cxWidgets 1.0
cxComboBox.h
Go to the documentation of this file.
1// Copyright (c) 2026 E. Oulashin
2#ifndef __CXCOMBOBOX_H__
3#define __CXCOMBOBOX_H__
4
5#include "cxMultiLineInput.h"
6#include "cxMenu.h"
7#include <string>
8
39#include <set>
40
41namespace cx {
42
43using std::set;
44
50{
51 public:
83 explicit cxComboBox(cxWindow *pParentWindow = nullptr,
84 int pRow = 0, int pCol = 0,
85 int pHeight = DEFAULT_HEIGHT,
86 int pWidth = DEFAULT_WIDTH,
87 const std::string& pLabel = "",
88 eBorderStyle pBorderStyle = eBS_NOBORDER,
89 eInputOptions pInputOption = eINPUT_EDITABLE,
90 eInputTypes pInputType = eINPUT_TYPE_TEXT,
91 std::string *pExtValue = nullptr, bool pMenuEnabled = true,
92 int pRightLabelOffset = 0,
93 int pRightLabelHeight = 1,
94 int pRightLabelWidth = 5,
95 bool pShowRightLabel = false);
96
97 // Copy constructor
98 cxComboBox(const cxComboBox& pThatComboBox);
99
100 virtual ~cxComboBox();
101
115 virtual long showModal(bool pShowSelf = true, bool pBringToTop = true,
116 bool pShowSubwindows = true) override;
117
129 virtual void resize(int pNewHeight, int pNewWidth, bool pRefresh = true) override;
130
140 virtual bool move(int pNewRow, int pNewCol, bool pRefresh = true) override;
141
147 virtual void erase(bool pEraseSubwindows = true) override;
148
154 virtual void hide(bool pHideSubwindows = true) override;
155
161 virtual void unhide(bool pUnhideSubwindows = true) override;
162
173 virtual void appendToMenu(const std::string& pDisplayText,
174 const std::string& pItemText = "",
175 bool pRefresh = false, bool pBringToTop = false);
176
185 virtual bool removeFromMenu(unsigned pItemIndex, bool pRefresh = false);
186
198 virtual bool removeFromMenu(const std::string& pItemText,
199 bool pDisplayText = true,
200 bool pRefresh = false);
201
205 virtual void removeAllItemsFromMenu();
206
213 virtual void showMenu(bool pBringToTop = false);
214
218 virtual void hideMenu();
219
225 virtual unsigned numMenuItems() const;
226
232 virtual std::string getItemText(int pIndex) const;
233
240 virtual int height() const override;
241
247 virtual int width() const override;
248
255 virtual int inputHeight() const;
256
263 virtual int inputWidth() const;
264
271 virtual int menuHeight() const;
272
279 virtual int menuWidth() const;
280
288 virtual void setMenuHeight(int pNewHeight, bool pRefresh = false);
289
298 virtual void toggleMenu(bool pEnableMenu, bool pRefresh = true);
299
305 virtual bool menuIsEnabled() const;
306
314 virtual std::string cxTypeStr() const override;
315
321 cxMenu* getMenu();
322
328 virtual void setDropDownKey(int pKey);
329
335 virtual void addDropDownKey(int pKey);
336
342 virtual void setDropDownKeys(const set<int>& pKeys);
343
350 virtual void removeDropDownKey(int pKey);
351
360 virtual bool hasDropDownKey(int pKey) const;
361
368 virtual void toggleValidatorFunction(bool pRunValidatorFunction) override;
369
375 virtual bool getUseValidatorFunction() const override;
376
386 virtual void setUseAltMenuItemText(bool pUseAltMenuItemText);
387
395 virtual bool getUseAltMenuItemText() const;
396
397 protected:
415 long doInputLoop(bool pShowSelf, bool& pRunOnLeaveFunction);
416
422 void copyCxComboBoxStuff(const cxComboBox* pThatComboBox);
423
429 bool menuIsModal() const;
430
431 private:
432 cxMenu mMenu; // The drop-down menu
433 bool mUseAltMenuItemText = false; // Whether or not to use the alternate text for menu items
434 set<int> mDropDownKeys; // Keys that show the drop-down menu
435 // mRunValidatorFunction controls whether or not the validator function
436 // should run. Note that cxMultiLineInput has this same bool too;
437 // however, cxComboBox will disable that one because cxComboBox will
438 // run the validator.
439 bool mRunValidatorFunction = true;
440
441 // This is a helper for doInputLoop(). This shows the drop-down menu if
442 // it's enabled. This will return a return code to be used for the
443 // input loop and also set whether or not the input loop should
444 // continue.
445 //
446 // Parameters:
447 // pShowMenu: Whether or not to have the menu show its window when
448 // showModal() is called for it (for a screen optimization)
449 // pContinueOn (OUT): This will contain whether or not the input loop
450 // should continue.
451 //
452 // Return: The return code for use with the input loop & showModal()
453 long showMenuModal(bool pShowMenu, bool& pContinueOn);
454};
455
456} // namespace cx
457
458#endif
A text box that also has a drop-down box with a list of items that the user can choose from.
Definition cxComboBox.h:50
void copyCxComboBoxStuff(const cxComboBox *pThatComboBox)
Makes a copy of a cxComboBox's member variables.
Definition cxComboBox.cpp:643
virtual bool removeFromMenu(const std::string &pItemText, bool pDisplayText=true, bool pRefresh=false)
Removes a menu item from the menu.
virtual void addDropDownKey(int pKey)
Adds a key that will show the drop-down menu.
Definition cxComboBox.cpp:499
virtual void showMenu(bool pBringToTop=false)
Shows the drop-down menu.
Definition cxComboBox.cpp:362
virtual int menuWidth() const
Returns the width of the menu portion of.
Definition cxComboBox.cpp:426
virtual void resize(int pNewHeight, int pNewWidth, bool pRefresh=true) override
Changes window's width and height. The window's upper-left.
Definition cxComboBox.cpp:232
virtual int inputWidth() const
Returns the width of the input portion of.
Definition cxComboBox.cpp:416
virtual bool getUseValidatorFunction() const override
Returns whether or not the validator function should be used.
Definition cxComboBox.cpp:524
virtual void unhide(bool pUnhideSubwindows=true) override
Un-hides the window.
Definition cxComboBox.cpp:321
virtual void removeAllItemsFromMenu()
Removes all items from the menu.
Definition cxComboBox.cpp:355
virtual void appendToMenu(const std::string &pDisplayText, const std::string &pItemText="", bool pRefresh=false, bool pBringToTop=false)
Adds a string item to the end of the menu.
Definition cxComboBox.cpp:330
virtual int menuHeight() const
Returns the height of the menu portion of.
Definition cxComboBox.cpp:421
virtual bool hasDropDownKey(int pKey) const
Returns whether or not a key is in the list of drop-down keys.
Definition cxComboBox.cpp:514
long doInputLoop(bool pShowSelf, bool &pRunOnLeaveFunction)
Handles the input loop. Returns cxID_QUIT or cxID_EXIT,.
Definition cxComboBox.cpp:543
virtual bool getUseAltMenuItemText() const
Returns whether or not the alternate text of the drop-down menu.
Definition cxComboBox.cpp:534
virtual bool move(int pNewRow, int pNewCol, bool pRefresh=true) override
Changes the window's position, based on a new upper-left corner.
Definition cxComboBox.cpp:272
virtual void setDropDownKey(int pKey)
Sets a single key that will show the drop-down menu.
Definition cxComboBox.cpp:493
virtual void setMenuHeight(int pNewHeight, bool pRefresh=false)
Allows the height of the menu portion to be changed.
Definition cxComboBox.cpp:431
virtual void erase(bool pEraseSubwindows=true) override
Erases the window.
Definition cxComboBox.cpp:309
bool menuIsModal() const
Returns whether or not the drop-down menu is modal.
Definition cxComboBox.cpp:666
virtual bool menuIsEnabled() const
Returns whether or not the menu is enabled.
Definition cxComboBox.cpp:478
virtual unsigned numMenuItems() const
Returns the number of items on the menu.
Definition cxComboBox.cpp:372
virtual void setUseAltMenuItemText(bool pUseAltMenuItemText)
Sets whether or not to use the alternate text for all items on.
Definition cxComboBox.cpp:529
virtual void hideMenu()
Hides the drop-down menu.
Definition cxComboBox.cpp:367
virtual void toggleMenu(bool pEnableMenu, bool pRefresh=true)
Enables or disables the menu.
Definition cxComboBox.cpp:436
virtual bool removeFromMenu(unsigned pItemIndex, bool pRefresh=false)
Removes a menu item from the menu.
Definition cxComboBox.cpp:344
virtual void removeDropDownKey(int pKey)
Removes a key from the list of keys that will show the.
Definition cxComboBox.cpp:509
virtual int height() const override
Returns the total height of the combo box, including.
Definition cxComboBox.cpp:382
virtual void setDropDownKeys(const set< int > &pKeys)
Sets the keys that will show the drop-down menu.
Definition cxComboBox.cpp:504
virtual int width() const override
Returns the width of the combo box.
Definition cxComboBox.cpp:404
virtual void toggleValidatorFunction(bool pRunValidatorFunction) override
Sets whether or not the validator function should be used.
Definition cxComboBox.cpp:519
cxMenu * getMenu()
Returns a pointer to the drop-down menu.
Definition cxComboBox.cpp:488
virtual ~cxComboBox()
Definition cxComboBox.cpp:85
virtual long showModal(bool pShowSelf=true, bool pBringToTop=true, bool pShowSubwindows=true) override
Shows the window and waits for input.
Definition cxComboBox.cpp:89
virtual std::string cxTypeStr() const override
Returns the name of the cxWidgets class. This can be used to.
Definition cxComboBox.cpp:483
virtual void hide(bool pHideSubwindows=true) override
Hides the window.
Definition cxComboBox.cpp:315
cxComboBox(cxWindow *pParentWindow=nullptr, int pRow=0, int pCol=0, int pHeight=DEFAULT_HEIGHT, int pWidth=DEFAULT_WIDTH, const std::string &pLabel="", eBorderStyle pBorderStyle=eBS_NOBORDER, eInputOptions pInputOption=eINPUT_EDITABLE, eInputTypes pInputType=eINPUT_TYPE_TEXT, std::string *pExtValue=nullptr, bool pMenuEnabled=true, int pRightLabelOffset=0, int pRightLabelHeight=1, int pRightLabelWidth=5, bool pShowRightLabel=false)
Default constructor.
virtual int inputHeight() const
Returns the height of the input portion of.
Definition cxComboBox.cpp:411
virtual std::string getItemText(int pIndex) const
Definition cxComboBox.cpp:377
Represents a list of items, one of which may be selected.
Definition cxMenu.h:62
This class represents an input box that can have a height.
Definition cxMultiLineInput.h:149
Represents a text-based window on the screen. Can contain a title, status, and a message to appear wi...
Definition cxWindow.h:195
#define DEFAULT_HEIGHT
Definition cxWindow.h:68
#define DEFAULT_WIDTH
Definition cxWindow.h:69
cxBorderChars.h - Defines border characters to be used in drawing a box (i.e., in cxWindow and all it...
Definition cxApp.cpp:5
eInputTypes
Definition cxInputTypes.h:20
@ eINPUT_TYPE_TEXT
Definition cxInputTypes.h:21
eInputOptions
Definition cxInputOptions.h:20
@ eINPUT_EDITABLE
Definition cxInputOptions.h:21
eBorderStyle
Definition cxBorderStyles.h:26
@ eBS_NOBORDER
Definition cxBorderStyles.h:27