cxWidgets 1.0
cxNotebook.h
Go to the documentation of this file.
1// Copyright (c) 2026 E. Oulashin
2#ifndef __CXNOTEBOOK_H__
3#define __CXNOTEBOOK_H__
4
5// Copyright (c) 2007 Michael H. Kinney
6
7#include "cxPanel.h"
8#include <string>
9#include <vector>
10#include <map>
11#include <memory>
12
13namespace cx {
14
32class cxNotebook: public cxPanel
33{
34
35 public:
36
64 explicit cxNotebook(cxWindow *pParentWindow = nullptr,
65 int pRow = 0, int pCol = 0,
66 int pHeight = DEFAULT_HEIGHT,
67 int pWidth = DEFAULT_WIDTH,
68 bool pLabelsOnTop = true,
69 bool pLeftLabelSpace = true,
70 bool pRightLabelSpace = true,
71 int pTabSpacing = 0,
72 cxWindow *pExtTitleWindow = nullptr,
73 cxWindow *pExtStatusWindow = nullptr,
74 bool pTabNavWrap = true);
75
76 virtual ~cxNotebook();
77
86 void setLabelsOnTop(bool pLabelsOnTop, bool pRefresh = false);
87
94 bool getLabelsOnTop() const;
95
102 void setLeftLabelSpace(bool pLeftLabelSpace);
103
110 bool getLeftLabelSpace() const;
111
118 void setRightLabelSpace(bool pRightLabelSpace);
119
126 bool getRightLabelSpace() const;
127
144 bool setTabSpacing(int pTabSpacing, bool pRefresh = false);
145
152 int getTabSpacing() const;
153
162 void setTabNavWrap(bool pTabNavWrap);
163
171 bool getTabNavWrap() const;
172
184 virtual long show(bool pBringToTop = false, bool pShowSubwindows = true) override;
185
199 virtual long showModal(bool pShowSelf = true, bool pBringToTop = true,
200 bool pShowSubwindows = true) override;
201
208 virtual void hide(bool pHideSubwindows = true) override;
209
216 virtual void unhide(bool pUnhideSubwindows = true) override;
217
223 virtual std::string cxTypeStr() const override;
224
232 virtual bool windowIsInNotebook(cxWindow *pWindow) const;
233
249 virtual std::shared_ptr<cxPanel> append(const std::string& pLabel, const std::string& pPanelName = "");
250
260 virtual cxPanel* getPanel(unsigned int pIndex) const;
261
273 virtual cxPanel* getPanel(const std::string& pID, bool pIsLabel = true) const;
274
282 virtual cxPanel* getCurrentPanelPtr() const;
283
294 virtual bool move(int pNewRow, int pNewCol, bool pRefresh = true) override;
295
305 virtual void setShowPanelWindow(unsigned int pIndex, bool pShowPanelWindow);
306
318 virtual void setShowPanelWindow(const std::string& pID, bool pShowPanelWindow,
319 bool pIsLabel = true);
320
327 virtual bool getShowPanelWindow() const override;
328
338 virtual bool getShowPanelWindow(unsigned int pIndex) const;
339
353 virtual bool getShowPanelWindow(const std::string& pID, bool pIsLabel = true) const;
354
367 virtual void showSubwindows(bool pBringToTop = true, bool pShowSubwindows = true) override;
368
377 virtual std::string getLabel(unsigned int pIndex) const;
378
387 virtual std::string getLabel(const std::string& pName) const;
388
400 virtual bool setLabel(unsigned int pIndex, const std::string& pLabel, bool pRefresh = false);
401
415 virtual bool setLabel(const std::string& pID, const std::string& pLabel,
416 bool pIsLabel = true, bool pRefresh = false);
417
423 virtual void setEnabled(bool pEnabled) override;
424
434 virtual void setEnabled(unsigned int pIndex, bool pEnabled) override;
435
449 virtual void setEnabled(const std::string& pID, bool pEnabled, bool pIsTitle = true) override;
450
456 void setNextTabKey(int pKey);
457
463 int getNextTabKey() const;
464
470 void setPrevTabKey(int pKey);
471
477 int getPrevTabKey() const;
478
484 void setTabNavKey(int pKey);
485
492 int getTabNavKey() const;
493
500 void setAllDisabledMsg(const std::string& pAllDisabledMsg);
501
509 const std::string& getAllDisabledMsg() const;
510
517 void setNoWindowsMsg(const std::string& pNoWindowsMsg);
518
526 const std::string& getWindowDisabledMsg() const;
527
533 void setWindowDisabledMsg(const std::string& pMsg);
534
542 const std::string& getNoWindowsMsg() const;
543
551 virtual bool mouseEvtWasInTitle() const override;
552
563 virtual std::shared_ptr<cxWindow> removeWindow(unsigned int pIndex) override;
564
575 virtual void removeWindow(cxWindow *pWindow) override;
576
583 virtual void removeWindow(const std::shared_ptr<cxWindow>& pWindow) override;
584
593 virtual void delWindow(unsigned int pIndex) override;
594
602 virtual void delWindow(cxWindow *pWindow);
603
610 virtual void delWindow(const std::shared_ptr<cxWindow>& pWindow) override;
611
621 virtual bool setCurrentWindow(unsigned int pIndex) override;
622
632 virtual bool setCurrentWindow(const std::string& pTitle);
633
646 virtual bool setCurrentWindow(const std::string& pID, bool pIsLabel) override;
647
658 virtual bool setCurrentWindowByPtr(cxWindow *pWindow) override;
659
669 virtual bool setCurrentWindowByPtr(const std::shared_ptr<cxWindow>& pWindow) override;
670
679 virtual bool windowIsInPanel(const std::shared_ptr<cxWindow>& pWindow) const override;
680
689 virtual int lastClickTabIndex() const;
690
702 virtual bool swap(int pWindow1Index, int pWindow2Index) override;
703
715 virtual bool swap(const std::shared_ptr<cxWindow>& pWindow1, const std::shared_ptr<cxWindow>& pWindow2) override;
716 virtual bool swap(cxWindow *pWindow1, cxWindow *pWindow2) override;
717
725 bool selectNextWin();
726
734 bool selectPrevWin();
735
736 private:
737 typedef std::vector<std::shared_ptr<cxWindow> > labelWinContainer;
738 labelWinContainer mLabels; // These act as labels for the tabs
739 bool mLabelsOnTop; // Can determine if the labels are on top or bottom
740 bool mLeftLabelSpace; // Whether to have a space to the left of label text
741 bool mRightLabelSpace; // Whether to have a space to the right of label text
742 int mCurrentPanelIndex = 0; // Index of the current panel
743 int mNextTabKey = PAGE_DOWN; // The key to use to go to the next tab
744 int mPrevTabKey = PAGE_UP; // The key to use to go to the previous tab
745 int mTabNavKey; // The key to use to bring up a tab navigation menu
746 std::string mAllDisabledMsg; // Message to display when all windows are disabled
747 std::string mNoWindowsMsg; // Message to display when the notebook has no windows
748 std::string mWindowDisabledMsg; // Message to display when a window is disabled
749 int mTabSpacing; // # of spaces between the tabs
750 int mLastClickTabIndex = -1; // Index of the window that was clicked on
751 // mTabNavWrap controls whether "wrapping" occurs if user wants to
752 // navigate to the next/previous tab with the keyboard and they're
753 // on the last/first enabled tab.
754 bool mTabNavWrap;
755
756 // Runs the input loop
757 //
758 // Parameters:
759 // pRunOnLeaveFunction (OUT): This will store whether or not the onLeave
760 // function should run.
761 long doInputLoop(bool& pRunOnLeaveFunction);
762
763 // Shows the current panel, and hides the others
764 //
765 // Parameters:
766 // pApplylabelAttr: Whether or not to apply the label window attribute.
767 // Defaults to true.
768 // pBringToTop: Whether or not to bring the current panel to the top of
769 // the stack. Defaults to true.
770 void showCurrentWindow(bool pApplyLabelAttr = true, bool pBringToTop = true);
771
772 // Sets up the special border characters for a label window. This is a
773 // helper that is called when appending a panel and when the user
774 // changes one of the labels.
775 //
776 // Parameters:
777 // pIndex: The index of the label window. The label windows to the left
778 // and to the right of the window will also have their border characters
779 // set.
780 void setLabelWinSpecialChars(unsigned int pIndex);
781
782 // Sets the special border characters for all label windows
783 inline void setAllLabelWinSpecialChars();
784
785 // Makes sure that all the label windows are where they should be. Also
786 // makes sure they have the proper speical border characters.
787 //
788 // Parameters:
789 // pRefresh: Whether or not to refresh the screen. Defaults to false.
790 void alignLabelWindows(bool pRefresh = false);
791
792 // Dis-allow some of cxPanel's methods from being called by users of
793 // this class
794 bool getExitOnLeaveLast() const override;
795 void setExitOnLeaveLast(bool pExitOnLeaveLast) override;
796 bool getExitOnLeaveFirst() const override;
797 void setExitOnLeaveFirst(bool pExitOnLeaveFirst) override;
798 bool windowIsInPanel(cxWindow *pWindow) const override;
799 bool append(const std::shared_ptr<cxWindow>& pWindow) override;
800 bool append(const std::shared_ptr<cxWindow>& pWindow, int pRow, int pCol, bool pRefresh = false) override;
801 void setShowPanelWindow(bool pShowPanelWindow) override;
802
803 // Don't allow copy construction or assignment
804 cxNotebook(const cxNotebook& pNotebook);
805 cxNotebook& operator =(const cxNotebook& pNotebook);
806
817 void setupLabelBorder(int pIndex, bool pClear = false);
818
819 // This is a helper for setupLabelBorder(). It removes all strings from
820 // a title/status map that are all spaces.
821 static void removeSpaceStrings(std::map<int, std::string>& pStringMap);
822
823 // Shows a tab navigation menu, allowing the user to choose another tab
824 // to go to.
825 void showNavMenu();
826
827}; // end of class cxNotebook
828
829} // namespace cx
830
831#endif
This class represents a notebook control, which manages multiple.
Definition cxNotebook.h:33
virtual bool getShowPanelWindow() const override
Returns whether or not the panel window will be shown.
Definition cxNotebook.cpp:661
virtual std::shared_ptr< cxPanel > append(const std::string &pLabel, const std::string &pPanelName="")
Appends a new panel & tab to the notebook. Returns a pointer.
virtual void hide(bool pHideSubwindows=true) override
Hides the notebook.
Definition cxNotebook.cpp:313
virtual void showSubwindows(bool pBringToTop=true, bool pShowSubwindows=true) override
Shows the subwindows for the notebook. This is overidden here.
Definition cxNotebook.cpp:756
virtual std::string cxTypeStr() const override
Returns the class type as a string ("cxNotebook")
Definition cxNotebook.cpp:345
void setNoWindowsMsg(const std::string &pNoWindowsMsg)
Sets the message to be displayed when there are no panels in.
Definition cxNotebook.cpp:1064
virtual cxPanel * getPanel(const std::string &pID, bool pIsLabel=true) const
Returns a pointer to one of the panels in the notebook (by.
bool getLeftLabelSpace() const
Returns the currently-set option of having a space to the left.
Definition cxNotebook.cpp:126
virtual bool windowIsInPanel(const std::shared_ptr< cxWindow > &pWindow) const override
Returns whether a cxWindow object is contained in the notebook.
Definition cxNotebook.cpp:1967
void setWindowDisabledMsg(const std::string &pMsg)
Sets the message to be displayed when a window is disabled.
Definition cxNotebook.cpp:1074
void setTabNavKey(int pKey)
Sets the key that is used for bringing up a tab selection menu.
Definition cxNotebook.cpp:1029
virtual bool setCurrentWindow(const std::string &pID, bool pIsLabel) override
Sets which window will get focus in the next call to.
int getTabSpacing() const
Returns the number of spaces being used for horizontal tab.
Definition cxNotebook.cpp:192
int getTabNavKey() const
Returns the key currently used for bringing up the tab.
Definition cxNotebook.cpp:1049
virtual bool move(int pNewRow, int pNewCol, bool pRefresh=true) override
Changes the notebok's position, based on a new upper-left.
Definition cxNotebook.cpp:592
virtual bool windowIsInNotebook(cxWindow *pWindow) const
Returns whether a window exists in the notebook.
Definition cxNotebook.cpp:350
virtual bool setCurrentWindow(unsigned int pIndex) override
Sets which panel will get focus in the next call to.
Definition cxNotebook.cpp:1150
virtual void setEnabled(const std::string &pID, bool pEnabled, bool pIsTitle=true) override
Enables or disables a window in the panel (by title/name).
const std::string & getWindowDisabledMsg() const
Returns the message that is displayed when one of the panels in.
Definition cxNotebook.cpp:1069
virtual int lastClickTabIndex() const
Returns the index of the tab (label window) that was clicked.
Definition cxNotebook.cpp:1248
bool selectNextWin()
Selects the next available (enabled) window (moving forward),.
Definition cxNotebook.cpp:1277
bool selectPrevWin()
Selects the previous available (enabled) window (moving.
Definition cxNotebook.cpp:1330
virtual long showModal(bool pShowSelf=true, bool pBringToTop=true, bool pShowSubwindows=true) override
Shows the notebook and allows the user to interact with the.
Definition cxNotebook.cpp:262
virtual std::string getLabel(const std::string &pName) const
Returns the label forone of the panels (by panel name).
virtual cxPanel * getCurrentPanelPtr() const
Returns a pointer to the current panel, or nullptr if there is.
Definition cxNotebook.cpp:579
virtual bool getShowPanelWindow(const std::string &pID, bool pIsLabel=true) const
Returns whether or not one of the panels in the notebook will.
virtual std::string getLabel(unsigned int pIndex) const
Returns the label for one of the panels (by index).
Definition cxNotebook.cpp:784
virtual void delWindow(unsigned int pIndex) override
Removes a panel from the notebook (by index) and frees up its.
Definition cxNotebook.cpp:1130
const std::string & getNoWindowsMsg() const
Returns the message that is displayed when there are no panels.
Definition cxNotebook.cpp:1079
virtual cxPanel * getPanel(unsigned int pIndex) const
Returns a pointer to one of the panels in the notebook (by.
Definition cxNotebook.cpp:504
const std::string & getAllDisabledMsg() const
Returns the message that is displayed when all the panels in.
Definition cxNotebook.cpp:1059
virtual void setShowPanelWindow(const std::string &pID, bool pShowPanelWindow, bool pIsLabel=true)
Sets whether one of the panels in the notebook should show.
void setLeftLabelSpace(bool pLeftLabelSpace)
Toggles the option to have a space to the left of label text.
Definition cxNotebook.cpp:121
virtual bool mouseEvtWasInTitle() const override
Returns whether the current mouse information's coordinates.
Definition cxNotebook.cpp:1084
void setNextTabKey(int pKey)
Sets the key to be used for navigation to the next tab.
Definition cxNotebook.cpp:978
bool getRightLabelSpace() const
Returns the currently-set option of having a space to the right.
Definition cxNotebook.cpp:136
virtual bool setCurrentWindowByPtr(cxWindow *pWindow) override
Sets which window will get focus in the next.
Definition cxNotebook.cpp:1224
virtual bool swap(int pWindow1Index, int pWindow2Index) override
Swaps the order of 2 panels (by index). If both indexes are.
Definition cxNotebook.cpp:1253
virtual bool setLabel(const std::string &pID, const std::string &pLabel, bool pIsLabel=true, bool pRefresh=false)
Sets the label for one of the panels (by label/name). If the.
virtual long show(bool pBringToTop=false, bool pShowSubwindows=true) override
Shows the notebook.
Definition cxNotebook.cpp:207
void setPrevTabKey(int pKey)
Sets the key to be used for navigation to the previous tab.
Definition cxNotebook.cpp:1003
int getNextTabKey() const
Returns the key that is used for navigation to the next tab.
Definition cxNotebook.cpp:998
virtual bool setCurrentWindow(const std::string &pTitle)
Sets which panel will get focus in the next call to.
virtual void setEnabled(bool pEnabled) override
Enables or disables the notebook.
Definition cxNotebook.cpp:949
void setAllDisabledMsg(const std::string &pAllDisabledMsg)
Sets the message to be displayed when all the panels in the.
Definition cxNotebook.cpp:1054
void setRightLabelSpace(bool pRightLabelSpace)
Toggles the option to have a space to the right of label text.
Definition cxNotebook.cpp:131
virtual void setShowPanelWindow(unsigned int pIndex, bool pShowPanelWindow)
Sets whether one of the panels in the notebook should show.
Definition cxNotebook.cpp:600
void setTabNavWrap(bool pTabNavWrap)
Sets whether or not the user will be able to wrap from the.
Definition cxNotebook.cpp:197
bool getLabelsOnTop() const
Returns whether the labels are set to appear on top.
Definition cxNotebook.cpp:116
virtual void unhide(bool pUnhideSubwindows=true) override
Un-hides the notebook.
Definition cxNotebook.cpp:329
int getPrevTabKey() const
Returns the key that is used for navigation to the previous tab.
Definition cxNotebook.cpp:1024
virtual bool setLabel(unsigned int pIndex, const std::string &pLabel, bool pRefresh=false)
Sets the label for one of the panels (by index). If the new.
void setLabelsOnTop(bool pLabelsOnTop, bool pRefresh=false)
Toggles whether the labels should be on the top or bottom.
Definition cxNotebook.cpp:50
virtual std::shared_ptr< cxWindow > removeWindow(unsigned int pIndex) override
Removes a panel from the notebook. This returns a cxWindow.
Definition cxNotebook.cpp:1094
virtual ~cxNotebook()
Definition cxNotebook.cpp:46
bool getTabNavWrap() const
Returns whether or not wrapping is allowed between the first.
Definition cxNotebook.cpp:202
bool setTabSpacing(int pTabSpacing, bool pRefresh=false)
Sets the number of spaces to use for horizontal alignment of.
Definition cxNotebook.cpp:141
cxPanel is a window that contains other windows. When showModal()
Definition cxPanel.h:46
Represents a text-based window on the screen. Can contain a title, status, and a message to appear wi...
Definition cxWindow.h:195
#define PAGE_DOWN
Definition cxKeyDefines.h:23
#define PAGE_UP
Definition cxKeyDefines.h:22
#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