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

Generated by: LCOV version 2.0-1