cxWidgets 1.0
cxButton.h
Go to the documentation of this file.
1// Copyright (c) 2026 E. Oulashin
2#ifndef __CXBUTTON_H__
3#define __CXBUTTON_H__
4
20#include "cxWindow.h"
21#include "cxFunction.h"
22#include <string>
23#include <memory>
24
25namespace cx {
26
27class cxButton : public cxWindow
28{
29 public:
43 explicit cxButton(cxWindow *pParentWindowPtr = nullptr, int pRow = 0,
44 int pCol = 0, int pHeight = 3, int pWidth = 5,
45 const std::string& pLabel = "",
46 eBorderStyle pBorderStyle = eBS_SINGLE_LINE);
47
72 cxButton(cxWindow *pParentWindowPtr, int pRow, int pCol, int pHeight,
73 int pWidth, const std::string& pLabel, eBorderStyle pBorderStyle,
74 funcPtr4 pFunction, void *p1 = nullptr, void *p2 = nullptr,
75 void *p3 = nullptr, void *p4 = nullptr);
76
97 cxButton(cxWindow *pParentWindowPtr, int pRow, int pCol, int pHeight,
98 int pWidth, const std::string& pLabel, eBorderStyle pBorderStyle,
99 funcPtr2 pFunction, void *p1 = nullptr, void *p2 = nullptr);
100
106 cxButton(const cxButton& pButton);
107
111 virtual ~cxButton();
112
120 cxButton& operator =(const cxButton& pButton);
121
129 virtual std::string cxTypeStr() const override;
130
145 virtual long showModal(bool pShowSelf = true, bool pBringToTop = true,
146 bool pShowSubwindows = true) override;
147
160 virtual void setOnClickFunction(funcPtr4 pFunction, void *p1, void *p2,
161 void *p3, void *p4);
162
173 virtual void setOnClickFunction(funcPtr2 pFunction, void *p1, void *p2);
174
183 virtual void setOnClickFunction(funcPtr0 pFunction);
184
190 virtual std::string runOnClickFunction();
191
198 virtual void doMouseBehavior() override;
199
200 private:
201 // mOnClickFunction is a pointer to a function that should fire when
202 // the user presses the enter key (if the mouse was supported, this would
203 // also run when the user clicks the button).
204 std::shared_ptr<cxFunction> mOnClickFunction;
205
206 // Copies the onClick function from another cxButton. This is used by
207 // the copy constructor and the = operator.
208 void copyOnClickFunction(const cxButton& pButton);
209};
210
211} // namespace cx
212
213#endif
Definition cxButton.h:28
virtual std::string cxTypeStr() const override
Returns the name of the cxWidgets class. This can be used to.
Definition cxButton.cpp:62
cxButton(cxWindow *pParentWindowPtr, int pRow, int pCol, int pHeight, int pWidth, const std::string &pLabel, eBorderStyle pBorderStyle, funcPtr4 pFunction, void *p1=nullptr, void *p2=nullptr, void *p3=nullptr, void *p4=nullptr)
Constructor that sets up the button with a 4-parameter function.
virtual void doMouseBehavior() override
If the last mouse event occurred in the button, this will run.
Definition cxButton.cpp:201
virtual std::string runOnClickFunction()
Runs the onClick function, if it's set.
Definition cxButton.cpp:185
cxButton(cxWindow *pParentWindowPtr=nullptr, int pRow=0, int pCol=0, int pHeight=3, int pWidth=5, const std::string &pLabel="", eBorderStyle pBorderStyle=eBS_SINGLE_LINE)
Default constructor.
cxButton(cxWindow *pParentWindowPtr, int pRow, int pCol, int pHeight, int pWidth, const std::string &pLabel, eBorderStyle pBorderStyle, funcPtr2 pFunction, void *p1=nullptr, void *p2=nullptr)
Constructor that sets up the button with a 2-parameter function.
virtual long showModal(bool pShowSelf=true, bool pBringToTop=true, bool pShowSubwindows=true) override
Shows the button and waits for input. Fires the button's set.
Definition cxButton.cpp:67
cxButton & operator=(const cxButton &pButton)
Assignment operator.
Definition cxButton.cpp:52
virtual ~cxButton()
Definition cxButton.cpp:48
virtual void setOnClickFunction(funcPtr4 pFunction, void *p1, void *p2, void *p3, void *p4)
Sets the "on click" function pointer for the button. When.
Definition cxButton.cpp:165
Represents a text-based window on the screen. Can contain a title, status, and a message to appear wi...
Definition cxWindow.h:195
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