Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
button.hxx
1/*
2** Copyright 2007-2024, RTE (https://www.rte-france.com)
3** See AUTHORS.txt
4** SPDX-License-Identifier: MPL-2.0
5** This file is part of Antares-Simulator,
6** Adequacy and Performance assessment for interconnected energy networks.
7**
8** Antares_Simulator is free software: you can redistribute it and/or modify
9** it under the terms of the Mozilla Public Licence 2.0 as published by
10** the Mozilla Foundation, either version 2 of the License, or
11** (at your option) any later version.
12**
13** Antares_Simulator is distributed in the hope that it will be useful,
14** but WITHOUT ANY WARRANTY; without even the implied warranty of
15** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16** Mozilla Public Licence 2.0 for more details.
17**
18** You should have received a copy of the Mozilla Public Licence 2.0
19** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20*/
21#ifndef __ANTARES_TOOLBOX_COMPONENTS_BUTTON_BUTTON_HXX__
22#define __ANTARES_TOOLBOX_COMPONENTS_BUTTON_BUTTON_HXX__
23
24namespace Antares
25{
26namespace Component
27{
28template<class T>
29Button::Button(wxWindow* parent,
30 const wxString& caption,
31 const char* bitmap,
32 T* object,
33 void (T::*method)(void*)) :
34 Panel(parent),
35 pCaption(caption),
36 pUserData(NULL),
37 pIcon(NULL),
38 pClickBehavior(clkDefault),
39 pRecommendedWidth(0),
40 pMiddleWidth(0),
41 pSelected(false),
42 pPushed(false),
43 pAutoToggle(false),
44 pBold(false),
45 pHover(true)
46{
47 // callback
48 using MethodType = void (T::*)(void*);
49 if (object)
50 pOnClick.bind(const_cast<T*>(object), reinterpret_cast<MethodType>(method));
51
52 SetBackgroundStyle(wxBG_STYLE_CUSTOM); // Required by both GTK and Windows
53 SetBackgroundColour(parent->GetBackgroundColour());
56}
57
58template<class T>
59inline void Button::onPopupMenu(const T* object, void (T::*method)(Button&, wxMenu&, void*))
60{
61 if (object)
62 {
63 using MethodType = void (T::*)(Button&, wxMenu&, void*);
64 pOnPopup.bind(const_cast<T*>(object), reinterpret_cast<MethodType>(method));
65 }
66 else
67 pOnPopup.clear();
68}
69
70inline void Button::onPopupMenu(const OnPopupMenu& popup)
71{
72 pOnPopup = popup;
73}
74
75template<class T>
76inline void Button::onClick(const T* object, void (T::*method)(void*))
77{
78 if (object)
79 {
80 using MethodType = void (T::*)(void*);
81 pOnClick.bind(const_cast<T*>(object), reinterpret_cast<MethodType>(method));
82 }
83 else
84 pOnClick.clear();
85}
86
88{
89 pOnClick.clear();
90}
91
92inline const wxString& Button::caption() const
93{
94 return pCaption;
95}
96
97inline void* Button::userdata() const
98{
99 return pUserData;
100}
101
102inline void Button::userdata(void* v)
103{
104 pUserData = v;
105}
106
107inline bool Button::dropDown() const
108{
109 return (pClickBehavior == clkDropdown);
110}
111
112inline void Button::dropDown(bool rhs)
113{
114 pClickBehavior = (rhs) ? clkDropdown : clkDefault;
116 Refresh();
117}
118
119inline bool Button::menu() const
120{
121 return (pClickBehavior == clkDropdown);
122}
123
124inline void Button::menu(bool rhs)
125{
126 pClickBehavior = (rhs) ? clkMenu : clkDefault;
128 Refresh();
129}
130
131inline bool Button::pushed() const
132{
133 return pPushed;
134}
135
136inline void Button::pushed(bool v)
137{
138 if (v != pPushed)
139 {
140 pPushed = v;
141 Refresh();
142 }
143}
144
145inline bool Button::autoToggle() const
146{
147 return pAutoToggle;
148}
149
150inline void Button::autoToggle(bool v)
151{
152 pAutoToggle = v;
153}
154
155inline void Button::image(const char* filename)
156{
157 loadIconFromResource(filename);
159}
160
161inline void Button::pushedColor(uint r, uint g, uint b)
162{
163 pColorOverridePushed.Set((unsigned char)r, (unsigned char)g, (unsigned char)b);
164}
165
166inline void Button::pushedColor(const wxColour& color)
167{
168 pColorOverridePushed = color;
169}
170
171inline void Button::pushedColor(const wxWindow* wnd)
172{
173 assert(wnd && "invalid window");
174 if (wnd)
175 pColorOverridePushed = wnd->GetBackgroundColour();
176}
177
178inline bool Button::bold() const
179{
180 return pBold;
181}
182
183inline void Button::bold(bool value)
184{
185 pBold = value;
186}
187
188inline bool Button::enabled() const
189{
190 return IsEnabled();
191}
192
193inline void Button::enabled(bool value)
194{
195 Enable(value);
196}
197
198inline bool Button::hover() const
199{
200 return pHover;
201}
202
203inline void Button::hover(bool value)
204{
205 pHover = value;
206}
207
208} // namespace Component
209} // namespace Antares
210
211#endif // __ANTARES_TOOLBOX_COMPONENTS_BUTTON_BUTTON_HXX__
Definition button.h:34
bool pushed() const
Get if the button is pushed.
Definition button.hxx:131
void disconnectClickEvent()
Disconnect the onClick event.
Definition button.hxx:87
bool menu() const
Get if a click on the button will produce a menu.
Definition button.hxx:119
bool bold() const
Get if the font should be bold.
Definition button.hxx:178
bool autoToggle() const
Get if the button is in auto-toggle mode.
Definition button.hxx:145
Button(wxWindow *parent, const wxString &caption)
Constructor.
Definition button.cpp:65
void onClick(const T *object, void(T::*method)(void *))
Set the onClick event.
Definition button.hxx:76
void precalculateCoordinates()
Pre-calculate all coordinates.
Definition button.cpp:158
bool dropDown() const
Get if the button has a drop down menu.
Definition button.hxx:107
bool enabled() const
Get if the button is enabled.
Definition button.hxx:188
void onPopupMenu(const T *object, void(T::*method)(Button &, wxMenu &, void *))
Set the handler for creating the popup menu.
Definition button.hxx:59
const wxString & caption() const
Get the caption of the button.
Definition button.hxx:92
Yuni::Bind< void(Button &, wxMenu &, void *)> OnPopupMenu
Event: Popup menu.
Definition button.h:39
void loadIconFromResource(const char *filename)
Preload the Icon.
Definition button.cpp:142
void image(const char *filename)
Set the image filename.
Definition button.hxx:155
void pushedColor(uint r, uint g, uint b)
Set the pushed color.
Definition button.hxx:161
void * userdata() const
Get the user-data.
Definition button.hxx:97
Panel implementation.
Definition panel.h:36