cxWidgets 1.0
cxPanel.h
Go to the documentation of this file.
1// Copyright (c) 2026 E. Oulashin
2#ifndef __CXPANEL_H__
3#define __CXPANEL_H__
4
5// Copyright (c) 2006-2007 Michael H. Kinney
6
7#include "cxWindow.h"
8#include <string>
9#include <vector>
10#include <memory>
11
12namespace cx {
13
45class cxPanel : public cxWindow
46{
47 public:
70 explicit cxPanel(cxWindow *pParentWindow = nullptr,
71 int pRow = 0, int pCol = 0,
72 int pHeight = DEFAULT_HEIGHT,
73 int pWidth = DEFAULT_WIDTH,
74 const std::string& pTitle = "",
75 const std::string& pMessage = "",
76 const std::string& pStatus = "",
77 eBorderStyle pBorderStyle = eBS_NOBORDER,
78 cxWindow *pExtTitleWindow = nullptr,
79 cxWindow *pExtStatusWindow = nullptr,
80 bool pMessageUnderlines = false);
81
82 virtual ~cxPanel();
83
100 virtual long showModal(bool pShowSelf = true, bool pBringToTop = true,
101 bool pShowSubwindows = true) override;
102
110 virtual bool getExitOnLeaveLast() const;
111
120 virtual void setExitOnLeaveLast(bool pExitOnLeaveLast);
121
133 virtual bool getExitOnLeaveFirst() const;
134
146 virtual void setExitOnLeaveFirst(bool pExitOnLeaveFirst);
147
154 virtual unsigned int numWindows() const;
155
167 virtual std::shared_ptr<cxWindow> getWindow(unsigned pIndex) const;
168
182 virtual bool append(const std::shared_ptr<cxWindow>& pWindow);
183
205 virtual bool append(const std::shared_ptr<cxWindow>& pWindow, int pRow, int pCol, bool pRefresh = false);
206
215 virtual void delWindow(unsigned pIndex);
216
225 virtual void delWindow(const std::shared_ptr<cxWindow>& pWindow);
226
233 virtual void delAllWindows();
234
246 virtual std::shared_ptr<cxWindow> removeWindow(unsigned int pIndex);
247
256 virtual void removeWindow(const std::shared_ptr<cxWindow>& pWindow);
257 virtual void removeWindow(cxWindow *pWindow);
258
268 virtual bool windowIsInPanel(const std::shared_ptr<cxWindow>& pWindow) const;
269 virtual bool windowIsInPanel(cxWindow *pWindow) const;
270
281 virtual bool move(int pNewRow, int pNewCol, bool pRefresh = true) override;
282
291 virtual bool setCurrentWindow(unsigned pIndex);
292
304 virtual bool setCurrentWindow(const std::string& pID, bool pIsTitle = true);
305
316 virtual bool setCurrentWindowByPtr(const std::shared_ptr<cxWindow>& pWindow);
317 virtual bool setCurrentWindowByPtr(cxWindow *pWindow);
318
328 virtual bool setKeyFunction(int pKey, const std::shared_ptr<cxFunction>& pFunction) override;
329
336 virtual void clearKeyFunction(int pKey) override;
337
365 virtual bool setKeyFunction(int pKey, funcPtr4 pFunction,
366 void *p1, void *p2, void *p3, void *p4,
367 bool pUseReturnVal = false,
368 bool pExitAfterRun = false,
369 bool pRunOnLeaveFunction = true) override;
370
396 virtual bool setKeyFunction(int pKey, funcPtr2 pFunction,
397 void *p1, void *p2,
398 bool pUseReturnVal = false,
399 bool pExitAfterRun = false,
400 bool pRunOnLeaveFunction = true) override;
401
427 virtual bool setKeyFunction(int pKey, funcPtr0 pFunction,
428 bool pUseReturnVal = false,
429 bool pExitAfterRun = false,
430 bool pRunOnLeaveFunction = true) override;
431
439 virtual int getCurrentWindowIndex() const;
440
451 virtual int getWindowIndex(const std::shared_ptr<cxWindow>& pWindow) const;
452 virtual int getWindowIndex(cxWindow *pWindow) const;
453
461 virtual const std::shared_ptr<cxWindow>& getCurrentWindowPtr() const;
462
476 virtual long show(bool pBringToTop = false, bool pShowSubwindows = true) override;
477
484 virtual void hide(bool pHideSubwindows = true) override;
485
492 virtual void unhide(bool pUnhideSubwindows = true) override;
493
501 virtual bool getShowPanelWindow() const;
502
511 virtual void setShowPanelWindow(bool pShowPanelWindow);
512
519 virtual bool getAllowExit() const;
520
528 virtual void setAllowExit(bool pAllowExit);
529
536 virtual bool getAllowQuit() const;
537
545 virtual void setAllowQuit(bool pAllowQuit);
546
555 virtual bool windowIsEnabled(unsigned pIndex) const;
556
564 virtual void enableWindow(unsigned pIndex, bool pEnabled = true);
565
572 virtual void clear(bool pRefresh = false) override;
573
590 virtual bool addQuitKey(int pKey, bool pRunOnLeaveFunction = true,
591 bool pOverride = false) override;
592
598 virtual void removeQuitKey(int pKey) override;
599
616 virtual bool addExitKey(int pKey, bool pRunOnLeaveFunction = true,
617 bool pOverride = false) override;
618
624 virtual void removeExitKey(int pKey) override;
625
632 virtual void setEnabled(bool pEnabled) override;
633
641 virtual void setEnabled(unsigned pIndex, bool pEnabled);
642
653 virtual void setEnabled(const std::string& pID, bool pEnabled, bool pIsTitle = true);
654
665 virtual bool swap(int pWindow1Index, int pWindow2Index);
666
677 virtual bool swap(cxWindow *pWindow1, cxWindow *pWindow2);
678 virtual bool swap(const std::shared_ptr<cxWindow>& pWindow1, const std::shared_ptr<cxWindow>& pWindow2);
679
688 virtual void setColor(e_WidgetItems pItem, e_cxColors pColor) override;
689
697 virtual std::string cxTypeStr() const override;
698
703 virtual void quitNow() override;
704
709 virtual void exitNow() override;
710
723 const std::shared_ptr<cxWindow>& getLastWindow() const;
724
731 virtual void setName(unsigned pIndex, const std::string& pName);
732
742 virtual void setName(const std::string& pID, const std::string& pName, bool pIsTitle = true);
743
751 virtual void setName(const std::string& pName) override;
752
757 virtual int top() const override;
758
763 virtual int bottom() const override;
764
765 protected:
766 typedef std::vector<std::shared_ptr<cxWindow> > cxWindowPtrCollection;
767 cxWindowPtrCollection mWindows; // The windows in the panel to cycle between
768 bool mCycleWin = true; // Whether or not to cycle to the next/previous
769 // window in the input loop (this is set false
770 // in setCurrentWindow()).
771 std::shared_ptr<cxWindow> mLastWindow; // The last window visited during the input loop
772
780 bool anyEnabledWindows() const;
781
792 bool lastEnabledWindow(int pIndex) const;
793
804 bool firstEnabledWindow(int pIndex) const;
805
806 private:
807 friend class cxWindow;
808
809 cxWindowPtrCollection::iterator mWindowIter; // To keep track of current window
810 bool mExitOnLeaveLast = false; // Exit the input loop when leaving last window?
811 bool mExitOnLeaveFirst = false; // Exit the input loop when leaving first window?
812 bool mAllowExit = true; // Whether or not the user is allowed to exit
813 bool mAllowQuit = true; // Whether or not the user is allowed to quit
814 // If mShowPanelWindow is true (default), the panel window
815 // will be shown (in addition to the subwindows and the windows
816 // in the panel). If it is false, only the windows in the
817 // panel will be shown.
818 bool mShowPanelWindow = true;
819
820 // Adds a cxWindow pointer to mWindows. Also checks to see
821 // if the cxWindow already has a cxPanel parent, and if so,
822 // will remove the window from the other cxPanel.
823 //
824 // Parameters:
825 // pWindow: A cxWindow pointer to be added to mWindows.
826 //
827 // Return: true if the window was added, or false if not.
828 bool addWindowPtr(const std::shared_ptr<cxWindow>& pWindow);
829
830 // Does the input loop. Returns the return code
831 // according to the user's input.
832 // Parameters:
833 // pSubwinShow: Whether or not to have the subwindows show
834 // themselves before doing their input loops.
835 // pRunOnLeaveFunction (OUT): This will store whether or not the onLeave
836 // function should run.
837 long doInputLoop(bool pSubwinShow, bool& pRunOnLeaveFunction);
838
839 // This adds an exit key to one of the windows in the panel. If the
840 // window is a cxMenu and if the key is one of the menu's up/down
841 // navigational keys, however, the exit key will not be added to the
842 // menu.
843 //
844 // Parameters:
845 // pWindow: A pointer to the cxWindow to add the exit key to
846 // pKey: The key to add as the exit key
847 // pRunOnLeaveFunction: Whether or not the window should run its
848 // onLeave function before leaving focus
849 // pOverride: Whether or not the key should override a function call
850 // for the key, if there is one set up
851 //
852 // Note: This is inline for speed (this function will get called
853 // inside of a loop).
854 inline void addExitKeyToWindow(std::shared_ptr<cxWindow>& pWindow, int pKey,
855 bool pRunOnLeaveFunction, bool pOverride);
856
857 // This adds a quit key to one of the windows in the panel. If the
858 // window is a cxMenu and if the key is one of the menu's up/down
859 // navigational keys, however, the quit key will not be added to the
860 // menu.
861 //
862 // Parameters:
863 // pWindow: A pointer to the cxWindow to add the quit key to
864 // pKey: The key to add as the quit key
865 // pRunOnLeaveFunction: Whether or not the window should run its
866 // onLeave function before leaving focus
867 // pOverride: Whether or not the key should override a function call
868 // for the key, if there is one set up
869 //
870 // Note: This is inline for speed (this function will get called
871 // inside of a loop).
872 inline void addQuitKeyToWindow(std::shared_ptr<cxWindow>& pWindow, int pKey,
873 bool pRunOnLeaveFunction, bool pOverride);
874
875 // Don't allow copy construction or assignment
876 cxPanel(const cxPanel& pThatPanel);
877 cxPanel& operator =(const cxPanel& pThatPanel);
878};
879
880} // namespace cx
881
882#endif
cxPanel is a window that contains other windows. When showModal()
Definition cxPanel.h:46
virtual ~cxPanel()
Definition cxPanel.cpp:41
virtual int bottom() const override
Returns the bottom row of the window.
Definition cxPanel.cpp:1024
virtual std::shared_ptr< cxWindow > getWindow(unsigned pIndex) const
Gets a pointer to one of the subwindows (by index).
Definition cxPanel.cpp:126
virtual bool append(const std::shared_ptr< cxWindow > &pWindow)
Adds a window to the panel. Note: The cxWindow.
virtual void setEnabled(unsigned pIndex, bool pEnabled)
Enables or disables a window in the panel (by index).
virtual bool getAllowQuit() const
Returns whether the user is allowed to quit out.
Definition cxPanel.cpp:657
std::vector< std::shared_ptr< cxWindow > > cxWindowPtrCollection
Definition cxPanel.h:766
virtual void setAllowQuit(bool pAllowQuit)
Sets whether the user is allowed to quit out of.
Definition cxPanel.cpp:662
const std::shared_ptr< cxWindow > & getLastWindow() const
Returns a pointer to the last window in the panel that was.
Definition cxPanel.cpp:974
virtual void setExitOnLeaveLast(bool pExitOnLeaveLast)
Sets whether the panel should exit focus.
Definition cxPanel.cpp:106
virtual void delAllWindows()
Removes all windows from the panel. Also frees the memory used.
Definition cxPanel.cpp:195
virtual long show(bool pBringToTop=false, bool pShowSubwindows=true) override
Shows the panel. If setShowPanelWindow(false) has been.
Definition cxPanel.cpp:568
virtual void setColor(e_WidgetItems pItem, e_cxColors pColor) override
Sets the color of one of the window items.
Definition cxPanel.cpp:881
virtual std::shared_ptr< cxWindow > removeWindow(unsigned int pIndex)
Removes a window from the panel, without freeing its memory.
Definition cxPanel.cpp:206
virtual int top() const override
Returns the top row of the window.
Definition cxPanel.cpp:1019
virtual bool append(const std::shared_ptr< cxWindow > &pWindow, int pRow, int pCol, bool pRefresh=false)
Adds a window to the panel with relative coordinates.
virtual bool windowIsInPanel(const std::shared_ptr< cxWindow > &pWindow) const
Returns whether a cxWindow object is contained.
virtual bool getExitOnLeaveLast() const
Returns whether or not the panel will exit focus.
Definition cxPanel.cpp:101
cxWindowPtrCollection mWindows
Definition cxPanel.h:767
virtual void setAllowExit(bool pAllowExit)
Sets whether the user is allowed to exit out of.
Definition cxPanel.cpp:652
virtual void quitNow() override
This causes the panel to stop its input loop with a code of.
Definition cxPanel.cpp:896
bool anyEnabledWindows() const
Returns whether any of the windows contained in mWindows are.
Definition cxPanel.cpp:1029
virtual bool getShowPanelWindow() const
Returns whether or not the panel window will be.
Definition cxPanel.cpp:637
virtual void clearKeyFunction(int pKey) override
Removes a function pointer for a keypress for the panel so that it will no.
Definition cxPanel.cpp:431
virtual bool getAllowExit() const
Returns whether the user is allowed to exit out.
Definition cxPanel.cpp:647
virtual bool swap(int pWindow1Index, int pWindow2Index)
Swaps the order of 2 subwindows (by index). If both indexes.
Definition cxPanel.cpp:818
virtual void removeQuitKey(int pKey) override
Removes a quit key.
Definition cxPanel.cpp:715
virtual unsigned int numWindows() const
Returns the number of windows that are contained.
Definition cxPanel.cpp:121
cxPanel(cxWindow *pParentWindow=nullptr, int pRow=0, int pCol=0, int pHeight=DEFAULT_HEIGHT, int pWidth=DEFAULT_WIDTH, const std::string &pTitle="", const std::string &pMessage="", const std::string &pStatus="", eBorderStyle pBorderStyle=eBS_NOBORDER, cxWindow *pExtTitleWindow=nullptr, cxWindow *pExtStatusWindow=nullptr, bool pMessageUnderlines=false)
Default constructor.
virtual bool setCurrentWindow(unsigned pIndex)
Sets which window will get focus in the next.
virtual long showModal(bool pShowSelf=true, bool pBringToTop=true, bool pShowSubwindows=true) override
Shows the panel and all of its subwindows and.
Definition cxPanel.cpp:45
virtual void removeExitKey(int pKey) override
Removes an exit key.
Definition cxPanel.cpp:747
virtual void setEnabled(const std::string &pID, bool pEnabled, bool pIsTitle=true)
Enables or disables a window in the panel (by title/name).
virtual void setShowPanelWindow(bool pShowPanelWindow)
Sets whether or not the panel window should be shown.
Definition cxPanel.cpp:642
std::shared_ptr< cxWindow > mLastWindow
Definition cxPanel.h:771
virtual bool setCurrentWindow(const std::string &pID, bool pIsTitle=true)
Sets which window will get focus in the next.
virtual std::string cxTypeStr() const override
Returns the name of the cxWidgets class. This can be used to.
Definition cxPanel.cpp:891
virtual void setName(const std::string &pName) override
Sets the name of the panel. The name is an alternative means.
bool lastEnabledWindow(int pIndex) const
Returns whether or not a window in the panel with a given index.
Definition cxPanel.cpp:1052
virtual void unhide(bool pUnhideSubwindows=true) override
Un-hides the panel, along with the windows in the panel.
Definition cxPanel.cpp:622
virtual void delWindow(const std::shared_ptr< cxWindow > &pWindow)
Removes a window from the panel (by pointer), and frees the.
virtual void setEnabled(bool pEnabled) override
Enables or disables the panel. Disabling/enabling a cxPanel.
Definition cxPanel.cpp:759
virtual bool setCurrentWindowByPtr(const std::shared_ptr< cxWindow > &pWindow)
Sets which window will get focus in the next.
virtual bool windowIsEnabled(unsigned pIndex) const
Returns whether or not one of the windows in the panel.
Definition cxPanel.cpp:667
virtual bool setKeyFunction(int pKey, const std::shared_ptr< cxFunction > &pFunction) override
Sets a function to be called when a key is pressed.
virtual bool getExitOnLeaveFirst() const
Returns whether the panel will exit focus.
Definition cxPanel.cpp:111
virtual void hide(bool pHideSubwindows=true) override
Hides the panel, along with the windows in the panel.
Definition cxPanel.cpp:607
bool mCycleWin
Definition cxPanel.h:768
virtual void clear(bool pRefresh=false) override
Clears all the window in the panel.
Definition cxPanel.cpp:687
virtual void setName(const std::string &pID, const std::string &pName, bool pIsTitle=true)
Sets the name of one of the windows in the panel (by title/name).
virtual void removeWindow(const std::shared_ptr< cxWindow > &pWindow)
Removes a window from the panel, without freeing its memory.
virtual bool addQuitKey(int pKey, bool pRunOnLeaveFunction=true, bool pOverride=false) override
Adds a key that will cause the window to quit its input loop.
Definition cxPanel.cpp:695
virtual int getWindowIndex(const std::shared_ptr< cxWindow > &pWindow) const
Given a cxWindow pointer, this function will return the index.
bool firstEnabledWindow(int pIndex) const
Returns whether or not a window in the panel with a given index.
Definition cxPanel.cpp:1078
virtual bool move(int pNewRow, int pNewCol, bool pRefresh=true) override
Changes the panel's position, based on a new upper-left corner.
Definition cxPanel.cpp:286
virtual const std::shared_ptr< cxWindow > & getCurrentWindowPtr() const
Returns a pointer to the current window.
Definition cxPanel.cpp:555
virtual void enableWindow(unsigned pIndex, bool pEnabled=true)
Enables/disables one of the windows in the panel (by index).
Definition cxPanel.cpp:679
virtual void setName(unsigned pIndex, const std::string &pName)
Sets the name of one of the windows in the panel (by index).
virtual void setExitOnLeaveFirst(bool pExitOnLeaveFirst)
Sets whether the panel should exit focus.
Definition cxPanel.cpp:116
virtual void delWindow(unsigned pIndex)
Removes a window from the panel (by index) and frees the memory.
virtual bool addExitKey(int pKey, bool pRunOnLeaveFunction=true, bool pOverride=false) override
Adds a key that will cause the window to quit its input loop.
Definition cxPanel.cpp:727
virtual void exitNow() override
This causes the panel to stop its input loop with a code of.
Definition cxPanel.cpp:935
virtual int getCurrentWindowIndex() const
Returns the index of the current window.
Definition cxPanel.cpp:498
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
std::string(* funcPtr4)(void *p1, void *p2, void *p3, void *p4)
Definition cxFunction.h:21
e_WidgetItems
Definition cxWidgetItems.h:42
std::string(* funcPtr0)()
Definition cxFunction.h:19
std::string(* funcPtr2)(void *p1, void *p2)
Definition cxFunction.h:20
eBorderStyle
Definition cxBorderStyles.h:26
@ eBS_NOBORDER
Definition cxBorderStyles.h:27
e_cxColors
Definition cxColors.h:46