LCOV - code coverage report
Current view: top level - src/utils/foxtools - MFXListIcon.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 50.0 % 6 3
Test Date: 2025-12-06 15:35:27 Functions: 0.0 % 1 0

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2006-2025 German Aerospace Center (DLR) and others.
       4              : // This program and the accompanying materials are made available under the
       5              : // terms of the Eclipse Public License 2.0 which is available at
       6              : // https://www.eclipse.org/legal/epl-2.0/
       7              : // This Source Code may also be made available under the following Secondary
       8              : // Licenses when the conditions for such availability set forth in the Eclipse
       9              : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10              : // or later which is available at
      11              : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12              : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13              : /****************************************************************************/
      14              : /// @file MFXListIcon.h
      15              : /// @author Pablo Alvarez Lopez
      16              : /// @date Feb 2023
      17              : ///
      18              : //
      19              : /****************************************************************************/
      20              : #pragma once
      21              : #include <config.h>
      22              : 
      23              : #include <vector>
      24              : 
      25              : #include "fxheader.h"
      26              : 
      27              : // ===========================================================================
      28              : // class declaration
      29              : // ===========================================================================
      30              : 
      31              : class MFXListIconItem;
      32              : 
      33              : // ===========================================================================
      34              : // class definitions
      35              : // ===========================================================================
      36              : 
      37              : /// @brief A list item which allows for custom coloring
      38              : class MFXListIcon : public FXScrollArea {
      39              :     /// @brief FOX declaration
      40            0 :     FXDECLARE(MFXListIcon)
      41              : 
      42              : public:
      43              :     enum {
      44              :         ID_LOOKUPTIMER = FXScrollArea::ID_LAST,
      45              :         ID_LAST
      46              :     };
      47              : 
      48              :     /// @brief Construct a list with initially no items in it
      49              :     MFXListIcon(FXComposite* p, FXObject* tgt = NULL, FXSelector sel = 0, FXuint opts = LIST_NORMAL, FXint x = 0, FXint y = 0, FXint w = 0, FXint h = 0);
      50              : 
      51              :     /// @brief Destructor
      52              :     ~MFXListIcon();
      53              : 
      54              :     /// @brief Create server-side resources
      55              :     void create();
      56              : 
      57              :     /// @brief Detach server-side resources
      58              :     void detach();
      59              : 
      60              :     /// @brief Perform layout
      61              :     void layout();
      62              : 
      63              :     /// @brief Return default width
      64              :     FXint getDefaultWidth();
      65              : 
      66              :     /// @brief Return default height
      67              :     FXint getDefaultHeight();
      68              : 
      69              :     /// @brief Compute and return content width
      70              :     FXint getContentWidth();
      71              : 
      72              :     /// @brief Return content height
      73              :     FXint getContentHeight();
      74              : 
      75              :     /// @brief Recalculate layout
      76              :     void recalc();
      77              : 
      78              :     /// @brief List widget can receive focus
      79              :     bool canFocus() const;
      80              : 
      81              :     /// @brief Move the focus to this window
      82              :     void setFocus();
      83              : 
      84              :     /// @brief Remove the focus from this window
      85              :     void killFocus();
      86              : 
      87              :     /// @brief Return the number of items in the list
      88              :     FXint getNumItems() const {
      89         7619 :         return (int)items.size();
      90              :     }
      91              : 
      92              :     /// @brief Return number of visible items
      93              :     FXint getNumVisible() const {
      94              :         return visible;
      95              :     }
      96              : 
      97              :     /// @brief Change the number of visible items
      98              :     void setNumVisible(FXint nvis);
      99              : 
     100              :     /// @brief Return the item at the given index
     101              :     MFXListIconItem* getItem(FXint index) const;
     102              : 
     103              :     /// @brief Replace the item with a [possibly subclassed] item
     104              :     FXint setItem(FXint index, MFXListIconItem* item, FXbool notify = FALSE);
     105              : 
     106              :     /// @brief Replace items text, icon, and user-data pointer
     107              :     FXint editItem(FXint index, const FXString& text, FXIcon* icon = NULL, void* ptr = NULL, FXbool notify = FALSE);
     108              : 
     109              :     /// @brief Insert a new [possibly subclassed] item at the give index
     110              :     FXint insertItem(FXint index, MFXListIconItem* item, FXbool notify = FALSE);
     111              : 
     112              :     /// @brief Insert item at index with given text,  icon,  and user-data pointer
     113              :     FXint insertItem(FXint index, const FXString& text, FXIcon* icon = NULL, void* ptr = NULL, FXbool notify = FALSE);
     114              : 
     115              :     /// @brief Append a [possibly subclassed] item to the list
     116              :     FXint appendItem(MFXListIconItem* item, FXbool notify = FALSE);
     117              : 
     118              :     /// @brief Append new item with given text and optional icon,  and user-data pointer
     119              :     FXint appendItem(const FXString& text, FXIcon* icon = NULL, void* ptr = NULL, FXbool notify = FALSE);
     120              : 
     121              :     /// @brief Remove node from list
     122              :     void removeItem(FXint index, FXbool notify = FALSE);
     123              : 
     124              :     /// @brief Remove all items from list
     125              :     void clearItems(FXbool notify = FALSE);
     126              : 
     127              :     /// @brief filter items in list
     128              :     void setFilter(const FXString& value, FXLabel* label);
     129              : 
     130              :     /// @brief Return item width
     131              :     FXint getItemWidth(FXint index) const;
     132              : 
     133              :     /// @brief Return item height
     134              :     FXint getItemHeight(FXint index) const;
     135              : 
     136              :     /// @brief Return index of item at y, if any
     137              :     MFXListIconItem* getItemAt(FXint y) const;
     138              : 
     139              :     /// @brief Search items by name (In all items)
     140              :     int findItem(const FXString& text) const;
     141              : 
     142              :     /// @brief Return item hit code: 0 no hit; 1 hit the icon; 2 hit the text
     143              :     FXint hitItem(MFXListIconItem* item, FXint x, FXint y) const;
     144              : 
     145              :     /// @brief Scroll to bring item into view
     146              :     void makeItemVisible(MFXListIconItem* item);
     147              : 
     148              :     /// @brief Scroll to bring item into view
     149              :     void makeItemVisible(FXint index);
     150              : 
     151              :     /// @brief Return TRUE if item is current
     152              :     FXbool isItemCurrent(FXint index) const;
     153              : 
     154              :     /// @brief Return TRUE if item is visible
     155              :     FXbool isItemVisible(MFXListIconItem* item) const;
     156              : 
     157              :     /// @brief Repaint item
     158              :     void updateItem(MFXListIconItem* item) const;
     159              : 
     160              :     /// @brief Select item by index
     161              :     FXbool selectItem(MFXListIconItem* item, FXbool notify = FALSE);
     162              : 
     163              :     /// @brief Deselect item
     164              :     FXbool deselectItem(MFXListIconItem* item, FXbool notify = FALSE);
     165              : 
     166              :     /// @brief Toggle item selection state
     167              :     FXbool toggleItem(MFXListIconItem* item, FXbool notify = FALSE);
     168              : 
     169              :     /// @brief Deselect all items
     170              :     FXbool killSelection(FXbool notify = FALSE);
     171              : 
     172              :     /// @brief Change current item
     173              :     void setCurrentItem(MFXListIconItem* item, FXbool notify = FALSE);
     174              : 
     175              :     /// @brief Return current item, if any
     176              :     FXint getCurrentItemIndex() const;
     177              : 
     178              :     /// @brief Return viewable item, if any
     179              :     FXint getViewableItem() const;
     180              : 
     181              :     /// @brief Change anchor item
     182              :     void setAnchorItem(MFXListIconItem* item);
     183              : 
     184              :     /// @brief Return anchor item,  if any
     185              :     FXint getAnchorItem() const;
     186              : 
     187              :     /// @brief Get item under the cursor, if any
     188              :     MFXListIconItem* getCursorItem() const;
     189              : 
     190              :     /// @brief Return text font
     191              :     FXFont* getFont() const {
     192       197215 :         return font;
     193              :     }
     194              : 
     195              :     /// @brief Return normal text color
     196              :     FXColor getTextColor() const {
     197        37740 :         return textColor;
     198              :     }
     199              : 
     200              :     /// @brief Change normal text color
     201              :     void setTextColor(FXColor clr);
     202              : 
     203              :     /// @brief Return selected text background
     204              :     FXColor getSelBackColor() const {
     205            0 :         return selbackColor;
     206              :     }
     207              : 
     208              :     /// @brief Return selected text color
     209              :     FXColor getSelTextColor() const {
     210            0 :         return seltextColor;
     211              :     }
     212              : 
     213              :     /// @brief Set the status line help text for this list
     214              :     void setHelpText(const FXString& text);
     215              : 
     216              :     /// @brief Get the status line help text for this list
     217              :     const FXString& getHelpText() const {
     218              :         return help;
     219              :     }
     220              : 
     221              :     /// @brief tolower string
     222              :     FXString tolowerString(const FXString& str) const;
     223              : 
     224              :     /// @name call functions
     225              :     /// @{
     226              :     long onPaint(FXObject*, FXSelector, void*);
     227              :     long onEnter(FXObject*, FXSelector, void*);
     228              :     long onLeave(FXObject*, FXSelector, void*);
     229              :     long onUngrabbed(FXObject*, FXSelector, void*);
     230              :     long onKeyPress(FXObject*, FXSelector, void*);
     231              :     long onKeyRelease(FXObject*, FXSelector, void*);
     232              :     long onLeftBtnPress(FXObject*, FXSelector, void*);
     233              :     long onLeftBtnRelease(FXObject*, FXSelector, void*);
     234              :     long onRightBtnPress(FXObject*, FXSelector, void*);
     235              :     long onRightBtnRelease(FXObject*, FXSelector, void*);
     236              :     long onMotion(FXObject*, FXSelector, void*);
     237              :     long onFocusIn(FXObject*, FXSelector, void*);
     238              :     long onFocusOut(FXObject*, FXSelector, void*);
     239              :     long onAutoScroll(FXObject*, FXSelector, void*);
     240              :     long onClicked(FXObject*, FXSelector, void*);
     241              :     long onDoubleClicked(FXObject*, FXSelector, void*);
     242              :     long onTripleClicked(FXObject*, FXSelector, void*);
     243              :     long onCommand(FXObject*, FXSelector, void*);
     244              :     long onQueryTip(FXObject*, FXSelector, void*);
     245              :     long onQueryHelp(FXObject*, FXSelector, void*);
     246              :     long onTipTimer(FXObject*, FXSelector, void*);
     247              :     long onLookupTimer(FXObject*, FXSelector, void*);
     248              :     /// @}
     249              : 
     250              : protected:
     251              :     /// @brief @brief FOX need this
     252              :     MFXListIcon();
     253              : 
     254              :     /// @brief @brief recompute list
     255              :     void recompute();
     256              : 
     257              :     /// @brief @brief create item
     258              :     MFXListIconItem* createItem(const FXString& text, FXIcon* icon, void* ptr);
     259              : 
     260              :     /// @brief Item list
     261              :     std::vector<MFXListIconItem*> items;
     262              : 
     263              :     /// @brief Selected item list
     264              :     std::vector<MFXListIconItem*> itemFiltered;
     265              : 
     266              :     /// @brief Anchor item
     267              :     FXint anchor = -1;
     268              : 
     269              :     /// @brief Current item
     270              :     MFXListIconItem* currentItem = nullptr;
     271              : 
     272              :     /// @brief Extent item
     273              :     FXint extent = -1;
     274              : 
     275              :     /// @brief Cursor item
     276              :     MFXListIconItem* cursor = nullptr;
     277              : 
     278              :     /// @brief Viewable item
     279              :     MFXListIconItem* viewable = nullptr;
     280              : 
     281              :     /// @brief Font
     282              :     FXFont* font = nullptr;
     283              : 
     284              :     /// @brief Text color
     285              :     FXColor textColor = 0;
     286              : 
     287              :     /// @brief Selected back color
     288              :     FXColor selbackColor = 0;
     289              : 
     290              :     /// @brief Selected text color
     291              :     FXColor seltextColor = 0;
     292              : 
     293              :     /// @brief List width
     294              :     FXint listWidth = 0;
     295              : 
     296              :     /// @brief List height
     297              :     FXint listHeight = 0;
     298              : 
     299              :     /// @brief Number of rows high
     300              :     FXint visible = 0;
     301              : 
     302              :     /// @brief Help text
     303              :     FXString help;
     304              : 
     305              :     /// @brief Grab point x
     306              :     FXint grabx = 0;
     307              : 
     308              :     /// @brief Grab point y
     309              :     FXint graby = 0;
     310              : 
     311              :     /// @brief Lookup string
     312              :     FXString lookup;
     313              : 
     314              :     /// @brief State of item
     315              :     FXbool state = FALSE;
     316              : 
     317              :     /// @brief filter
     318              :     FXString filter;
     319              : 
     320              : private:
     321              :     /// @brief typedef used for comparing elements
     322              :     typedef FXint(*FXCompareFunc)(const FXString&, const FXString&, FXint);
     323              : 
     324              :     /// @brief check if filter element
     325              :     bool showItem(const FXString& itemName) const;
     326              : 
     327              :     /// @brief @brief invalidate copy constructor
     328              :     MFXListIcon(const FXList&) = delete;
     329              : 
     330              :     /// @brief @brief invalidate assignement operator
     331              :     MFXListIcon&   operator = (const FXList&) = delete;
     332              : };
        

Generated by: LCOV version 2.0-1