Loading [MathJax]/extensions/tex2jax.js
Antares Simulator
Power System Simulator
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Modules Pages Concepts
notebook.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_COMPONENT_NOTEBOOK_H__
22#define __ANTARES_TOOLBOX_COMPONENT_NOTEBOOK_H__
23
24#include <ui/common/component/panel.h>
25#include <vector>
26#include <wx/dc.h>
27#include "../../input/input.h"
28#include "../refresh.h"
29
30namespace Antares
31{
32namespace Component
33{
37class Notebook : public Panel
38{
39public:
40 enum Orientation
41 {
42 orLeft,
43 orTop,
44 };
45 enum Theme
46 {
47 themeDefault,
48 themeLight,
49 };
50
51 enum Alignment
52 {
53 alignRight,
54 alignLeft,
55 };
56
57public:
58 class Tabs;
59
60public:
61 class Page
62 {
63 friend class Tabs;
64 friend class Notebook;
65 friend class MapNotebook;
66
67 public:
69
71 Page(Notebook& notebook, wxWindow* ctrnl, const wxString& caption);
72 Page(Notebook& notebook, wxWindow* ctrnl, const wxString& name, const wxString& caption);
74 ~Page();
76
78
79
81 const Notebook& notebook() const;
83
85
86
87 const wxString& caption() const;
89 void caption(const wxString& s);
91
93
94
95 const wxString& name() const;
97 void name(const wxString& s);
99
101
102
103 bool selected() const
104 {
105 return pSelected;
106 }
108 Page* select(bool force = false);
110 void selectSubPage(Page* subPage);
112
114
115 bool visible() const
116 {
117 return pVisible;
118 }
119 void visible(const bool v);
121
123
124 bool displayExtraControls() const
125 {
126 return pDisplayExtraControls;
127 }
128 void displayExtraControls(bool v)
129 {
130 pDisplayExtraControls = v;
131 }
133 wxWindow* control() const
134 {
135 return pControl;
136 }
137
139 void refresh()
140 {
141 RefreshAllControls(pControl);
142 }
144
146
147
148 void removeSubPage(Page* p);
150 Page* addSubPage(Page* p);
152
153 private:
155 std::vector<Page*> subPages;
156
157 private:
159 void onSelectPage();
160
161 private:
163 Notebook& pNotebook;
165 wxWindow* pControl;
167 wxString pName;
169 wxString pCaption;
171 wxRect pBoundingBox;
173 bool pSelected;
175 bool pVisible;
177 bool pDisplayExtraControls;
178
179 }; // class Page
180
181 friend class Page;
182
183public:
185
186
190 Notebook(wxWindow* parent, Orientation orientation = orLeft);
192 virtual ~Notebook();
194
196
197
198 Orientation orientation() const;
200
204 void clear();
205
209 Page* add(wxWindow* ctnrl, const wxString& caption);
210
214 Page* add(wxWindow* ctnrl, const wxString& name, const wxString& caption);
215
219 void addSeparator();
220
222
223
224 bool tabsVisible() const;
226 void tabsVisible(bool v);
227
229 bool alwaysDisplayTabs() const;
231 void alwaysDisplayTabs(const bool v);
232
233 bool displayTitle() const;
234 void displayTitle(const bool v);
236
237 void addCommonControl(Toolbox::InputSelector::AInput* input, const int border = 0);
238 void addCommonControl(wxWindow* ctrnl,
239 const int border = 0,
240 const wxPoint& recommendedSize = wxPoint(20, 20));
241
242 void addCommonControlTop(Toolbox::InputSelector::AInput* input, const int border = 0);
243 void addCommonControlTop(wxWindow* ctrnl,
244 const int border = 0,
245 const wxPoint& recommendedSize = wxPoint(20, 20));
246
248
249
250 const wxString& caption() const;
252 void caption(const wxString& s);
254
258 bool select(const wxString& name, bool triggerEvents = true);
259
260 Page* selected()
261 {
262 return pLastSelected;
263 }
264 const Page* selected() const
265 {
266 return pLastSelected;
267 }
268
272 Page* find(const wxString& name);
273
274 void set_page_visibility(const wxString& name, bool visible);
275
277
278
281 void theme(Theme t)
282 {
283 pTheme = t;
284 }
285
286 Theme theme() const
287 {
288 return pTheme;
289 }
291
292 void alignment(Alignment a)
293 {
294 pAlignment = a;
295 }
296
300 wxWindow* titlePanelControl() const;
301
305 void enableRefreshForAllDatagrid(bool enabled);
306
307 // From wxWidgets standard API
308 virtual bool HasMultiplePages() const;
309
310 void forceRefresh();
311
312public:
323 Yuni::Event<void(Page&, bool&)> onPageAccept;
324
335 Yuni::Event<void(Page&)> onPageChanged;
336
337public:
338 class Tabs : public Panel
339 {
340 friend class Notebook;
341
342 public:
343 Tabs(wxWindow* parent, Notebook& notebook);
344 virtual ~Tabs();
345
346 virtual void onMouseUp(wxMouseEvent&);
347 void drawItem(wxDC& dc, Page* page, int& pos);
348 virtual void drawItemTop(wxDC& dc, Page* page, int& pos, Alignment align);
349 void drawItemOnCanvasNotSelected(Page* page,
350 wxDC& dc,
351 const int pos,
352 const int h,
353 const wxSize& textExtent);
354 void drawItemOnCanvasSelected(Page* page,
355 wxDC& dc,
356 const int pos,
357 const int h,
358 const wxSize& textExtent);
359
360 Notebook& pNotebook;
361
362 protected:
363 virtual void onDraw(wxPaintEvent& evt);
364 void onEraseBackground(wxEraseEvent& evt);
365 void drawOrientationLeft(wxDC& dc);
366 void drawOrientationTop(wxDC& dc);
367 void onForceRefresh();
368 wxPoint pCachedSize;
369
370 wxRect pRect;
371 int pMaxFound;
372 // A SegV occurs for an unknon reason when using a wxPoint on the stack
373 // when calling DrawPolygon.
374 // (MinGW TDM 4.4.1 - Windows XP - wxWidgets 2.8.10)
375 // It seems that the drawing context uses it later
376 wxPoint pPts[3];
377
378 DECLARE_EVENT_TABLE()
379 };
380
381private:
383 void onForceRefresh();
384
385public:
386 friend class Tabs;
388 const Orientation pOrientation;
390 using Pages = std::vector<Page*>;
396 wxString pCaption;
403
404 wxSizer* pSizerForPages;
405 wxSizer* pTopSizer;
406 wxSizer* pLeftSizer;
407
408 Page* pLastSelected;
409
411 std::vector<wxWindow*> pExtraControls;
412
413 Theme pTheme;
414 Alignment pAlignment;
415
416 wxString pCacheTitle;
417 wxColour pOriginalColor;
418 wxColour pOriginalColorDark;
419
420}; // class Notebook
421
422} // namespace Component
423} // namespace Antares
424
425#include "notebook.hxx"
426
427#endif // __ANTARES_TOOLBOX_COMPONENT_NOTEBOOK_H__
MapNotebook.
Definition mapnotebook.h:35
Definition notebook.h:62
void refresh()
Refresh.
Definition notebook.h:139
Notebook & notebook()
Get the attached notebook.
Definition notebook.hxx:28
const wxString & name() const
Get the name of the page.
Definition notebook.hxx:43
void selectSubPage(Page *subPage)
Select a subpage of this page.
Definition notebook.cpp:824
void removeSubPage(Page *p)
Remove a subpage.
Definition notebook.cpp:806
~Page()
Destructor.
Definition notebook.cpp:764
const wxString & caption() const
Get the caption of the page.
Definition notebook.hxx:38
wxWindow * control() const
Get the control of the page.
Definition notebook.h:133
bool selected() const
Get if the page is currently selected.
Definition notebook.h:103
Page * select(bool force=false)
Select the page.
Definition notebook.cpp:816
Page * addSubPage(Page *p)
Add a page as subpage.
Definition notebook.cpp:799
Definition notebook.h:339
virtual void onMouseUp(wxMouseEvent &)
Click up.
Definition notebook.cpp:909
Notebook.
Definition notebook.h:38
void enableRefreshForAllDatagrid(bool enabled)
Enable / Disable the refresh for all datagrid.
Definition notebook.cpp:903
Tabs * pTabs
The tab component.
Definition notebook.h:394
Orientation orientation() const
Get the orientation of the notebook.
Definition notebook.hxx:113
bool pTabsVisible
Can display tabs.
Definition notebook.h:398
bool pAlwaysDisplayTab
Always display tabs.
Definition notebook.h:400
const wxString & caption() const
Get the caption of the notebook.
Definition notebook.hxx:48
const Orientation pOrientation
Orientation.
Definition notebook.h:388
bool pDisplayTitle
Display the title.
Definition notebook.h:402
Page * add(wxWindow *ctnrl, const wxString &caption)
Add a new page.
Definition notebook.hxx:73
Pages pPages
All pages.
Definition notebook.h:392
wxWindow * titlePanelControl() const
Get the controls of the main bar.
Definition notebook.hxx:118
bool tabsVisible() const
Get if the tabs are visible.
Definition notebook.hxx:93
virtual ~Notebook()
Destructor.
Definition notebook.cpp:96
void addSeparator()
Add a separator.
Definition notebook.hxx:57
bool select(const wxString &name, bool triggerEvents=true)
Select a page by its name.
Definition notebook.cpp:958
std::vector< wxWindow * > pExtraControls
The complete list of extra controls.
Definition notebook.h:411
Yuni::Event< void(Page &, bool &)> onPageAccept
Event: Page changing.
Definition notebook.h:323
Yuni::Event< void(Page &)> onPageChanged
Event: Page changing.
Definition notebook.h:335
void theme(Theme t)
Set the current theme.
Definition notebook.h:281
Page * find(const wxString &name)
Find a page by its name.
Definition notebook.cpp:1000
std::vector< Page * > Pages
All pages.
Definition notebook.h:390
Notebook(wxWindow *parent, Orientation orientation=orLeft)
Default constructor.
Definition notebook.cpp:47
bool alwaysDisplayTabs() const
Get if the tabs must always be displayed, even if a single one is available.
Definition notebook.hxx:83
wxString pCaption
The caption of the notebook.
Definition notebook.h:396
void clear()
Delete all pages.
Definition notebook.cpp:665
Panel implementation.
Definition panel.h:36