cxWidgets 1.0
cxMultiForm.h
Go to the documentation of this file.
1// Copyright (c) 2026 E. Oulashin
2#ifndef __CXMULTIFORM_H__
3#define __CXMULTIFORM_H__
4
5// Copyright (c) 2005-2007 Michael H. Kinney
6//
7// This class represents a form that can contain
8// subforms (forms within the form).
9//
10// TODO: When the user presses ESC on one of
11// the subforms, if the subforms have any
12// onLeave functions, it will still run them..
13// ESC should quit directly out of the whole
14// multiForm.
15//
16// TODO: Add a way of telling the multiForm to
17// do subforms first on the first pass through
18// the input loop. (Would have to add a private
19// boolean variable, mDoFormsFirst, and then
20// another boolean in doInputLoop(), firstPass,
21// and for each pass in the input loop, have it
22// do the inputs if firstPass is false or
23// mDoFormsFirst is false.)
24
25#include "cxForm.h"
26#include "cxFunction.h"
27#include <string>
28#include <vector>
29#include <memory>
30
31namespace cx {
32
48class cxMultiForm : public cxForm
49{
50 public:
72 explicit cxMultiForm(cxWindow *pParentWindow = nullptr, int pRow = 0,
73 int pCol = 0, int pHeight = DEFAULT_HEIGHT,
74 int pWidth = DEFAULT_WIDTH, const std::string& pTitle = "",
75 eBorderStyle pBorderStyle = eBS_SINGLE_LINE,
76 cxWindow *pExtTitleWindow = nullptr,
77 cxWindow *pExtStatusWindow = nullptr,
78 bool pAutoExit = false, bool pStacked = false);
79
84 cxMultiForm(const cxMultiForm& pThatMultiForm);
85
86 virtual ~cxMultiForm();
87
95 cxMultiForm& operator =(const cxMultiForm& pThatMultiForm);
96
113 virtual std::shared_ptr<cxForm> appendForm(int pRow, int pCol, int pHeight,
114 int pWidth, const std::string& pTitle = "",
115 eBorderStyle pBorderStyle = eBS_NOBORDER,
116 bool pStacked = false);
117
137 virtual bool appendForm(std::shared_ptr<cxForm>& pForm, int pRow, int pCol, bool* pMoved = nullptr);
138
151 virtual bool appendForm(std::shared_ptr<cxForm>& pForm);
152
163 virtual std::shared_ptr<cxForm> getForm(unsigned pIndex) const;
164
175 virtual std::shared_ptr<cxForm> getForm(const std::string& pTitle) const;
176
186 virtual long show(bool pBringToTop = false, bool pShowSubwindows = true) override;
187
202 virtual long showModal(bool pShowSelf = true, bool pBringToTop = false,
203 bool pShowSubwindows = true) override;
204
213 virtual void showAllSubforms(bool pBringToTop = true, bool pSkipCurrentForm = false) const;
214
223 virtual bool removeSubform(unsigned pIndex);
224
233 virtual bool removeSubform(const std::string& pTitle);
234
244 virtual std::string getValue(unsigned pFormIndex, int pInputIndex) const;
245
250 virtual std::string getValue(int pIndex) const override;
251
256 virtual std::string getValue(const std::string& pStr, bool pIsLabel = true) const override;
257
272 virtual std::string getValue(unsigned pFormIndex, const std::string& pLabel,
273 bool pIsLabel = true) const;
274
286 virtual std::string getValue(const std::string& pTitle, int pInputIndex) const;
287
301 virtual std::string getValue(const std::string& pTitle, const std::string& pLabel,
302 bool pIsLabel = true) const;
303
315 virtual bool setValue(unsigned pFormIndex, int pInputIndex, const std::string& pValue,
316 bool pRefresh = false);
317
318
331 virtual bool setValue(unsigned pFormIndex, const std::string& pLabel,
332 const std::string& pValue, bool pIsLabel = true,
333 bool pRefresh = false);
334
346 virtual bool setValue(const std::string& pTitle, int pInputIndex,
347 const std::string& pValue, bool pRefresh = false);
348
361 virtual bool setValue(const std::string& pTitle, const std::string& pLabel,
362 const std::string& pValue, bool pIsLabel = true,
363 bool pRefresh = false);
364
372 virtual bool setValue(int pIndex, const std::string& pValue, bool pRefresh = false) override;
373
383 virtual bool setValue(const std::string& pLabel, const std::string& pValue, bool pIsLabel = true, bool pRefresh = false) override;
384
390 size_t numSubforms() const;
391
397 virtual int getLastKey() const override;
398
406 bool hasEditableSubforms() const;
407
416 virtual bool move(int pNewRow, int pNewCol, bool pRefresh = true) override;
417
423 virtual void hide(bool pHideSubwindows = true) override;
424
430 virtual void unhide(bool pUnhideSubwindows = true) override;
431
454 virtual bool setKeyFunction(int pKey, funcPtr4 pFunction,
455 void *p1, void *p2, void *p3, void *p4,
456 bool pUseReturnVal = false,
457 bool pExitAfterRun = false,
458 bool pRunOnLeaveFunction = true) override;
459
480 virtual bool setKeyFunction(int pKey, funcPtr2 pFunction,
481 void *p1, void *p2,
482 bool pUseReturnVal = false,
483 bool pExitAfterRun = false,
484 bool pRunOnLeaveFunction = true) override;
485
506 virtual bool setKeyFunction(int pKey, funcPtr0 pFunction,
507 bool pUseReturnVal = false,
508 bool pExitAfterRun = false,
509 bool pRunOnLeaveFunction = true) override;
510
518 virtual bool setCurrentSubform(int pIndex);
519
527 virtual bool setCurrentSubform(const std::string& pTitle);
528
539 virtual bool setCurrentSubformByPtr(const std::shared_ptr<cxForm>& pForm);
540 virtual bool setCurrentSubformByPtr(cxForm *pForm);
541
547 virtual int getCurrentForm() const;
548
559 virtual int getSubformIndex(const std::shared_ptr<cxForm>& pForm) const;
560 virtual int getSubformIndex(cxForm *pForm) const;
561
570 virtual bool hasChanged() const override;
571
578 virtual void setChanged(bool pDataChanged) override;
579
586 virtual void setSubformEnabled(unsigned pIndex, bool pEnabled);
587
594 virtual void setSubformEnabled(const std::string& pTitle, bool pEnabled);
595
605 virtual bool subformIsEnabled(unsigned pIndex) const;
606
616 virtual bool subformIsEnabled(const std::string& pTitle) const;
617
634 virtual bool addQuitKey(int pKey, bool pRunOnLeaveFunction = true,
635 bool pOverride = false) override;
636
642 virtual void removeQuitKey(int pKey) override;
643
660 virtual bool addExitKey(int pKey, bool pRunOnLeaveFunction = true,
661 bool pOverride = false) override;
662
668 virtual void removeExitKey(int pKey) override;
669
677 virtual void setDisableCursorOnShow(bool pDisableCursorOnShow) override;
678
685 virtual void clear(bool pRefresh = false) override;
686
697 void setAssumeMovingBackwards(bool pAssumeMovingBackwards);
698
707 bool getAssumeMovingBackwards() const;
708
716 virtual void setEnabled(bool pEnabled) override;
717
725 virtual std::string cxTypeStr() const override;
726
727 protected:
733 void copyCxMultiFormStuff(const cxMultiForm* pThatMultiForm);
734
747 long doInputLoop(bool pShowSubforms);
748
759 int lowestSubformRow(unsigned pIndex = 0) const;
760
761 private:
762 typedef std::vector<std::shared_ptr<cxForm> > formPtrContainer;
763 formPtrContainer mForms; // Contains pointers to the subforms
764 int mCurrentForm = 0; // The index of the subform that currently has focus
765 bool mCycleForm = true; // Whether or not to cycle to the next or
766 // previous form in the input loop (this
767 // is set to false when setCurrentSubform()
768 // is called)
769 // If this is set true, then when focus is set to the multiForm and the
770 // cursor is on the last form, then the cursor on the last form will be
771 // set to the last input on that form (motion is assumed to be moving
772 // backwards).
773 bool mAssumeMovingBackwards = true;
774
775 // Frees the memory used by the subforms and clears
776 // mForms.
777 inline void freeSubforms();
778
779 // Runs an input loop for the inputs. Also sets a boolean for
780 // whether or not to continue the input loop.
781 long doInputs(bool& pContinueOn);
782
783 // Runs an input loop for the subforms.
784 // Parameters:
785 // pShowSubforms: Whether or not to have the subforms show themselves
786 // before running their input loops.
787 // pContinueOn: This will store a boolean for whether or not to
788 // continue the input loop.
789 // pClickedInput: This will store a boolean for whether or not the user
790 // clicked on an input in the multiForm. This is used by the input
791 // loop to determine whether to go back to looping through the inputs.
792 long doSubforms(bool pShowSubforms, bool& pContinueOn, bool& pClickedInput);
793
794 // Selects the next form with editable inputs.
795 // Returns whether or not the current form was
796 // the last form in mForms.
797 bool selectNextForm();
798
799 // Selects the previous form with editable inputs.
800 // Returns whether or not the current form was
801 // the first form in mForms.
802 bool selectPrevForm();
803
804 // Adds this multiForm's function keys to a subform.
805 void addFormFunctionKeysToSubform(std::shared_ptr<cxForm>& pForm);
806
807 // Adds this multiForm's quit keys and exit keys to a subform.
808 void addQuitAndExitKeysToSubform(std::shared_ptr<cxForm>& pForm);
809
810 // Returns whether a subform is enabled and editable (by index).
811 // Note that no bounds checking is done (for optimal
812 // efficiency).
813 inline bool subformIsEnabledAndEditable(unsigned int pIndex);
814};
815
816
817} // namespace cx
818
819#endif
Represents a form that contains text inputs. The user can move forward between the inputs on the form...
Definition cxForm.h:85
friend class cxMultiForm
Definition cxForm.h:3342
Represents a form that can.
Definition cxMultiForm.h:49
virtual bool appendForm(std::shared_ptr< cxForm > &pForm, int pRow, int pCol, bool *pMoved=nullptr)
Appends a subform to the form via a pointer.
virtual bool setValue(const std::string &pTitle, int pInputIndex, const std::string &pValue, bool pRefresh=false)
Sets a value of an input on one of the subforms.
cxMultiForm(cxWindow *pParentWindow=nullptr, int pRow=0, int pCol=0, int pHeight=DEFAULT_HEIGHT, int pWidth=DEFAULT_WIDTH, const std::string &pTitle="", eBorderStyle pBorderStyle=eBS_SINGLE_LINE, cxWindow *pExtTitleWindow=nullptr, cxWindow *pExtStatusWindow=nullptr, bool pAutoExit=false, bool pStacked=false)
size_t numSubforms() const
Returns the number of subforms on the form.
Definition cxMultiForm.cpp:481
virtual bool appendForm(std::shared_ptr< cxForm > &pForm)
Appends a subform to the form via a pointer (without.
virtual bool addQuitKey(int pKey, bool pRunOnLeaveFunction=true, bool pOverride=false) override
Adds a key that will cause the form to quit and.
Definition cxMultiForm.cpp:866
virtual std::string getValue(unsigned pFormIndex, const std::string &pLabel, bool pIsLabel=true) const
Gets the value of an input on one of the subforms (by.
int lowestSubformRow(unsigned pIndex=0) const
Returns the lowest row of any subform on the form, starting at.
Definition cxMultiForm.cpp:1188
virtual void setDisableCursorOnShow(bool pDisableCursorOnShow) override
Sets whether the window should disable the cursor.
Definition cxMultiForm.cpp:926
virtual bool addExitKey(int pKey, bool pRunOnLeaveFunction=true, bool pOverride=false) override
Adds a key that will cause the form to quit and.
Definition cxMultiForm.cpp:896
bool hasEditableSubforms() const
Returns whether any of the subforms contain.
Definition cxMultiForm.cpp:491
long doInputLoop(bool pShowSubforms)
Handles the input loop. Returns cxID_QUIT or cxID_EXIT,.
Definition cxMultiForm.cpp:1027
virtual bool setValue(unsigned pFormIndex, const std::string &pLabel, const std::string &pValue, bool pIsLabel=true, bool pRefresh=false)
Sets a value of an input on one of the subforms.
virtual bool setCurrentSubformByPtr(const std::shared_ptr< cxForm > &pForm)
Changes which subform is to have the focus (by pointer).
cxMultiForm & operator=(const cxMultiForm &pThatMultiForm)
Assignment operator.
Definition cxMultiForm.cpp:54
virtual void unhide(bool pUnhideSubwindows=true) override
Un-hides the form.
Definition cxMultiForm.cpp:586
virtual void setSubformEnabled(unsigned pIndex, bool pEnabled)
Enables or disables one of the subforms (by index).
Definition cxMultiForm.cpp:832
virtual void removeQuitKey(int pKey) override
Removes a quit key (but doesn't work for ESC)
Definition cxMultiForm.cpp:886
virtual long show(bool pBringToTop=false, bool pShowSubwindows=true) override
Definition cxMultiForm.cpp:238
virtual int getSubformIndex(const std::shared_ptr< cxForm > &pForm) const
Returns the index of a subform on the.
Definition cxMultiForm.cpp:775
virtual std::shared_ptr< cxForm > getForm(const std::string &pTitle) const
Returns a pointer to one of the subforms (by title), or.
virtual bool setValue(unsigned pFormIndex, int pInputIndex, const std::string &pValue, bool pRefresh=false)
Sets a value of an input on one of the subforms.
virtual std::shared_ptr< cxForm > appendForm(int pRow, int pCol, int pHeight, int pWidth, const std::string &pTitle="", eBorderStyle pBorderStyle=eBS_NOBORDER, bool pStacked=false)
Appends a subform to the form.
virtual bool setKeyFunction(int pKey, funcPtr4 pFunction, void *p1, void *p2, void *p3, void *p4, bool pUseReturnVal=false, bool pExitAfterRun=false, bool pRunOnLeaveFunction=true) override
Definition cxMultiForm.cpp:602
virtual bool setValue(const std::string &pLabel, const std::string &pValue, bool pIsLabel=true, bool pRefresh=false) override
virtual std::string getValue(const std::string &pTitle, int pInputIndex) const
Gets the value of an input on one of the subforms (by.
void copyCxMultiFormStuff(const cxMultiForm *pThatMultiForm)
Makes a copy of a cxMultiForm's member variables.
Definition cxMultiForm.cpp:993
void setAssumeMovingBackwards(bool pAssumeMovingBackwards)
Normally, if the cursor is on the last form when a cxMultiForm.
Definition cxMultiForm.cpp:948
virtual bool removeSubform(const std::string &pTitle)
Removes a subform (by title).
virtual std::shared_ptr< cxForm > getForm(unsigned pIndex) const
Returns a pointer to one of the subforms (by index), or.
Definition cxMultiForm.cpp:210
virtual void setSubformEnabled(const std::string &pTitle, bool pEnabled)
Enables or disables one of the subforms (by title).
virtual bool setValue(const std::string &pTitle, const std::string &pLabel, const std::string &pValue, bool pIsLabel=true, bool pRefresh=false)
Sets a value of an input on one of the subforms.
virtual bool subformIsEnabled(const std::string &pTitle) const
Returns whether one of the subforms is.
virtual bool setValue(int pIndex, const std::string &pValue, bool pRefresh=false) override
virtual long showModal(bool pShowSelf=true, bool pBringToTop=false, bool pShowSubwindows=true) override
Shows the form and waits for input.
Definition cxMultiForm.cpp:273
virtual void removeExitKey(int pKey) override
Removes an exit key.
Definition cxMultiForm.cpp:916
virtual std::string cxTypeStr() const override
Returns the name of the cxWidgets class. This can be used to.
Definition cxMultiForm.cpp:969
virtual std::string getValue(const std::string &pStr, bool pIsLabel=true) const override
Returns the value associated with a particular input (by label or name).
virtual bool move(int pNewRow, int pNewCol, bool pRefresh=true) override
Definition cxMultiForm.cpp:510
virtual int getLastKey() const override
Returns the last key typed by the user.
Definition cxMultiForm.cpp:486
virtual void hide(bool pHideSubwindows=true) override
Hides the form.
Definition cxMultiForm.cpp:574
virtual bool removeSubform(unsigned pIndex)
Removes a subform (by index).
Definition cxMultiForm.cpp:331
virtual std::string getValue(const std::string &pTitle, const std::string &pLabel, bool pIsLabel=true) const
Gets the value of an input on one of the subforms (by.
virtual bool subformIsEnabled(unsigned pIndex) const
Returns whether one of the subforms is.
Definition cxMultiForm.cpp:854
virtual bool hasChanged() const override
Returns whether or not any inputs on the form,.
Definition cxMultiForm.cpp:797
virtual void setEnabled(bool pEnabled) override
Enables or disables the multiForm. Enabling/disabling a.
Definition cxMultiForm.cpp:958
virtual void clear(bool pRefresh=false) override
Clears the multiForm and all the subforms.
Definition cxMultiForm.cpp:936
virtual void setChanged(bool pDataChanged) override
Setter for whether or not data should be considered changed.
Definition cxMultiForm.cpp:820
virtual bool setCurrentSubform(int pIndex)
Changes which subform is to have the focus (by index).
Definition cxMultiForm.cpp:696
virtual bool setCurrentSubform(const std::string &pTitle)
Changes which subform is to have the focus (by title).
virtual int getCurrentForm() const
Returns the index of the current form.
Definition cxMultiForm.cpp:770
virtual ~cxMultiForm()
Definition cxMultiForm.cpp:48
bool getAssumeMovingBackwards() const
Returns whether it will be assumed that the user is moving.
Definition cxMultiForm.cpp:953
virtual void showAllSubforms(bool pBringToTop=true, bool pSkipCurrentForm=false) const
Shows (refreshes) all inputs.
Definition cxMultiForm.cpp:305
virtual std::string getValue(unsigned pFormIndex, int pInputIndex) const
Gets the value of an input on one of the subforms (by indexes)
Definition cxMultiForm.cpp:354
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
std::string(* funcPtr0)()
Definition cxFunction.h:19
std::string(* funcPtr2)(void *p1, void *p2)
Definition cxFunction.h:20
eBorderStyle
Definition cxBorderStyles.h:26
@ eBS_SINGLE_LINE
Definition cxBorderStyles.h:28
@ eBS_NOBORDER
Definition cxBorderStyles.h:27