Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
button.h
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_H__
22#define __ANTARES_TOOLBOX_COMPONENTS_BUTTON_BUTTON_H__
23
24#include <yuni/yuni.h>
25#include <wx/bitmap.h>
26#include <ui/common/component/panel.h>
27#include <vector>
28
29namespace Antares
30{
31namespace Component
32{
33class Button final : public Panel
34{
35public:
37 using OnClick = Yuni::Bind<void(void*)>;
39 using OnPopupMenu = Yuni::Bind<void(Button&, wxMenu&, void*)>;
41 using Vector = std::vector<Button*>;
42
43 enum ClickBehavior
44 {
45 clkDefault,
46 clkDropdown,
47 clkMenu,
48 };
49
50public:
52
53
56 Button(wxWindow* parent, const wxString& caption);
60 Button(wxWindow* parent, const wxString& caption, const char* bitmap);
64 Button(wxWindow* parent, const wxString& caption, const char* bitmap, const OnClick& onclick);
65
69 template<class T>
70 Button(wxWindow* parent,
71 const wxString& caption,
72 const char* bitmap,
73 T* object,
74 void (T::*method)(void*));
75
77 virtual ~Button();
79
81
82
83 const wxString& caption() const;
85 void caption(const wxString& rhs);
86 void caption(const wxChar* rhs);
88
90
91
92 void image(const char* filename);
94
96
97
98 bool enabled() const;
100 void enabled(bool value);
102
104
105
106 void* userdata() const;
108 void userdata(void* v);
110
112
113
114 bool dropDown() const;
116 void dropDown(bool rhs);
118
120
121
122 bool menu() const;
124 void menu(bool rhs);
126
128
129
130 bool pushed() const;
132 void pushed(bool v);
133
135 bool autoToggle() const;
137 void autoToggle(bool v);
138
140 void pushedColor(uint r, uint g, uint b);
141 void pushedColor(const wxColour& color);
142 void pushedColor(const wxWindow* wnd);
144
146
147
148 bool bold() const;
150 void bold(bool value);
152
154
155
156 void hover(bool value);
157 bool hover() const;
159
163 template<class T>
164 void onPopupMenu(const T* object, void (T::*method)(Button&, wxMenu&, void*));
168 void onPopupMenu(const OnPopupMenu& popup);
169
173 template<class T>
174 void onClick(const T* object, void (T::*method)(void*));
175
178
180 virtual void onMouseClick() override;
181
183 virtual void onMouseEnter() override;
185 virtual void onMouseLeave() override;
186
188 virtual void onMouseUp(wxMouseEvent& evt) override;
189
190protected:
192 void loadIconFromResource(const char* filename);
196 void internalClick();
197
199 void onDraw(wxPaintEvent& evt);
201 void onEraseBackground(wxEraseEvent&)
202 {
203 }
204
206 // (may lead to SegV otherwise)
207 virtual bool triggerMouseClickEvent() const override
208 {
209 return false;
210 }
211
212private:
214 wxString pCaption;
216 OnClick pOnClick;
218 OnPopupMenu pOnPopup;
220 void* pUserData;
222 wxBitmap* pIcon;
224 ClickBehavior pClickBehavior;
225
227 int pRecommendedWidth;
228 int pMiddleWidth;
229 bool pSelected;
230 bool pPushed;
231 bool pAutoToggle;
232 bool pBold;
233 bool pHover;
234
236 wxColour pColorOverridePushed;
237
239 wxSize pCaptionExtent;
240 // Event table
241 DECLARE_EVENT_TABLE()
242
243}; // class Button
244
245} // namespace Component
246} // namespace Antares
247
248#include "button.hxx"
249
250#endif // __ANTARES_TOOLBOX_COMPONENTS_BUTTON_BUTTON_H__
Definition button.h:34
bool pushed() const
Get if the button is pushed.
Definition button.hxx:131
virtual bool triggerMouseClickEvent() const override
Tells to Component::Panel to not trigger its own mouse click event.
Definition button.h:207
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
void onDraw(wxPaintEvent &evt)
Event: draw the panel.
Definition button.cpp:219
virtual void onMouseEnter() override
The mouse has entered.
Definition button.cpp:377
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
virtual void onMouseClick() override
The panel has been clicked (delayed)
Definition button.cpp:372
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
void onEraseBackground(wxEraseEvent &)
UI: Erase background, empty to avoid flickering.
Definition button.h:201
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 internalClick()
internal click
Definition button.cpp:396
Yuni::Bind< void(void *)> OnClick
Event: User click.
Definition button.h:37
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
std::vector< Button * > Vector
Vector.
Definition button.h:41
virtual ~Button()
Destructor.
Definition button.cpp:131
virtual void onMouseLeave() override
The mouse has leaved.
Definition button.cpp:387
virtual void onMouseUp(wxMouseEvent &evt) override
Click up.
Definition button.cpp:404
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