Antares Simulator
Power System Simulator
notebook.h
1 /*
2  * Copyright 2007-2025, 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 
30 namespace Antares::Component
31 {
35 class Notebook: public Panel
36 {
37 public:
38  enum Orientation
39  {
40  orLeft,
41  orTop,
42  };
43 
44  enum Theme
45  {
46  themeDefault,
47  themeLight,
48  };
49 
50  enum Alignment
51  {
52  alignRight,
53  alignLeft,
54  };
55 
56 public:
57  class Tabs;
58 
59 public:
60  class Page
61  {
62  friend class Tabs;
63  friend class Notebook;
64  friend class MapNotebook;
65 
66  public:
68 
70  Page(Notebook& notebook, wxWindow* ctrnl, const wxString& caption);
71  Page(Notebook& notebook, wxWindow* ctrnl, const wxString& name, const wxString& caption);
73  ~Page();
75 
77 
78  Notebook& notebook();
80  const Notebook& notebook() const;
82 
84 
85  const wxString& caption() const;
88  void caption(const wxString& s);
90 
92 
93  const wxString& name() const;
96  void name(const wxString& s);
97 
99 
101 
102  bool selected() const
104  {
105  return pSelected;
106  }
107 
109  Page* select(bool force = false);
111  void selectSubPage(Page* subPage);
112 
114 
116 
117  bool visible() const
118  {
119  return pVisible;
120  }
121 
122  void visible(const bool v);
123 
125 
127 
128  bool displayExtraControls() const
129  {
130  return pDisplayExtraControls;
131  }
132 
133  void displayExtraControls(bool v)
134  {
135  pDisplayExtraControls = v;
136  }
137 
139  wxWindow* control() const
140  {
141  return pControl;
142  }
143 
145  void refresh()
146  {
147  RefreshAllControls(pControl);
148  }
149 
151 
153 
154  void removeSubPage(Page* p);
157  Page* addSubPage(Page* p);
159 
160  private:
162  std::vector<Page*> subPages;
163 
164  private:
166  void onSelectPage();
167 
168  private:
170  Notebook& pNotebook;
172  wxWindow* pControl;
174  wxString pName;
176  wxString pCaption;
178  wxRect pBoundingBox;
180  bool pSelected;
182  bool pVisible;
184  bool pDisplayExtraControls;
185 
186  }; // class Page
187 
188  friend class Page;
189 
190 public:
192 
193 
197  Notebook(wxWindow* parent, Orientation orientation = orLeft);
199  virtual ~Notebook();
201 
203 
204  Orientation orientation() const;
207 
211  void clear();
212 
216  Page* add(wxWindow* ctnrl, const wxString& caption);
217 
221  Page* add(wxWindow* ctnrl, const wxString& name, const wxString& caption);
222 
226  void addSeparator();
227 
229 
230  bool tabsVisible() const;
233  void tabsVisible(bool v);
234 
236  bool alwaysDisplayTabs() const;
238  void alwaysDisplayTabs(const bool v);
239 
240  bool displayTitle() const;
241  void displayTitle(const bool v);
243 
244  void addCommonControl(Toolbox::InputSelector::AInput* input, const int border = 0);
245  void addCommonControl(wxWindow* ctrnl,
246  const int border = 0,
247  const wxPoint& recommendedSize = wxPoint(20, 20));
248 
249  void addCommonControlTop(Toolbox::InputSelector::AInput* input, const int border = 0);
250  void addCommonControlTop(wxWindow* ctrnl,
251  const int border = 0,
252  const wxPoint& recommendedSize = wxPoint(20, 20));
253 
255 
256  const wxString& caption() const;
259  void caption(const wxString& s);
261 
265  bool select(const wxString& name, bool triggerEvents = true);
266 
267  Page* selected()
268  {
269  return pLastSelected;
270  }
271 
272  const Page* selected() const
273  {
274  return pLastSelected;
275  }
276 
280  Page* find(const wxString& name);
281 
282  void set_page_visibility(const wxString& name, bool visible);
283 
285 
286 
289  void theme(Theme t)
290  {
291  pTheme = t;
292  }
293 
294  Theme theme() const
295  {
296  return pTheme;
297  }
298 
300 
301  void alignment(Alignment a)
302  {
303  pAlignment = a;
304  }
305 
309  wxWindow* titlePanelControl() const;
310 
314  void enableRefreshForAllDatagrid(bool enabled);
315 
316  // From wxWidgets standard API
317  virtual bool HasMultiplePages() const;
318 
319  void forceRefresh();
320 
321 public:
332  Yuni::Event<void(Page&, bool&)> onPageAccept;
333 
344  Yuni::Event<void(Page&)> onPageChanged;
345 
346 public:
347  class Tabs: public Panel
348  {
349  friend class Notebook;
350 
351  public:
352  Tabs(wxWindow* parent, Notebook& notebook);
353  virtual ~Tabs();
354 
355  virtual void onMouseUp(wxMouseEvent&);
356  void drawItem(wxDC& dc, Page* page, int& pos);
357  virtual void drawItemTop(wxDC& dc, Page* page, int& pos, Alignment align);
358  void drawItemOnCanvasNotSelected(Page* page,
359  wxDC& dc,
360  const int pos,
361  const int h,
362  const wxSize& textExtent);
363  void drawItemOnCanvasSelected(Page* page,
364  wxDC& dc,
365  const int pos,
366  const int h,
367  const wxSize& textExtent);
368 
369  Notebook& pNotebook;
370 
371  protected:
372  virtual void onDraw(wxPaintEvent& evt);
373  void onEraseBackground(wxEraseEvent& evt);
374  void drawOrientationLeft(wxDC& dc);
375  void drawOrientationTop(wxDC& dc);
376  void onForceRefresh();
377  wxPoint pCachedSize;
378 
379  wxRect pRect;
380  int pMaxFound;
381  // A SegV occurs for an unknon reason when using a wxPoint on the stack
382  // when calling DrawPolygon.
383  // (MinGW TDM 4.4.1 - Windows XP - wxWidgets 2.8.10)
384  // It seems that the drawing context uses it later
385  wxPoint pPts[3];
386 
387  DECLARE_EVENT_TABLE()
388  };
389 
390 private:
392  void onForceRefresh();
393 
394 public:
395  friend class Tabs;
397  const Orientation pOrientation;
399  using Pages = std::vector<Page*>;
405  wxString pCaption;
412 
413  wxSizer* pSizerForPages;
414  wxSizer* pTopSizer;
415  wxSizer* pLeftSizer;
416 
417  Page* pLastSelected;
418 
420  std::vector<wxWindow*> pExtraControls;
421 
422  Theme pTheme;
423  Alignment pAlignment;
424 
425  wxString pCacheTitle;
426  wxColour pOriginalColor;
427  wxColour pOriginalColorDark;
428 
429 }; // class Notebook
430 
431 } // namespace Antares::Component
432 
433 #include "notebook.hxx"
434 
435 #endif // __ANTARES_TOOLBOX_COMPONENT_NOTEBOOK_H__
MapNotebook.
Definition: mapnotebook.h:33
Definition: notebook.h:61
void refresh()
Refresh.
Definition: notebook.h:145
Notebook & notebook()
Get the attached notebook.
Definition: notebook.hxx:26
const wxString & name() const
Get the name of the page.
Definition: notebook.hxx:41
void selectSubPage(Page *subPage)
Select a subpage of this page.
Definition: notebook.cpp:878
wxWindow * control() const
Get the control of the page.
Definition: notebook.h:139
void removeSubPage(Page *p)
Remove a subpage.
Definition: notebook.cpp:856
~Page()
Destructor.
Definition: notebook.cpp:810
const wxString & caption() const
Get the caption of the page.
Definition: notebook.hxx:36
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:868
Page * addSubPage(Page *p)
Add a page as subpage.
Definition: notebook.cpp:849
Definition: notebook.h:348
virtual void onMouseUp(wxMouseEvent &)
Click up.
Definition: notebook.cpp:981
Notebook.
Definition: notebook.h:36
void enableRefreshForAllDatagrid(bool enabled)
Enable / Disable the refresh for all datagrid.
Definition: notebook.cpp:973
Tabs * pTabs
The tab component.
Definition: notebook.h:403
Orientation orientation() const
Get the orientation of the notebook.
Definition: notebook.hxx:111
bool pTabsVisible
Can display tabs.
Definition: notebook.h:407
bool pAlwaysDisplayTab
Always display tabs.
Definition: notebook.h:409
const wxString & caption() const
Get the caption of the notebook.
Definition: notebook.hxx:46
const Orientation pOrientation
Orientation.
Definition: notebook.h:397
bool pDisplayTitle
Display the title.
Definition: notebook.h:411
Page * add(wxWindow *ctnrl, const wxString &caption)
Add a new page.
Definition: notebook.hxx:71
Pages pPages
All pages.
Definition: notebook.h:401
wxWindow * titlePanelControl() const
Get the controls of the main bar.
Definition: notebook.hxx:116
bool tabsVisible() const
Get if the tabs are visible.
Definition: notebook.hxx:91
virtual ~Notebook()
Destructor.
Definition: notebook.cpp:94
void addSeparator()
Add a separator.
Definition: notebook.hxx:55
bool select(const wxString &name, bool triggerEvents=true)
Select a page by its name.
Definition: notebook.cpp:1030
std::vector< wxWindow * > pExtraControls
The complete list of extra controls.
Definition: notebook.h:420
Yuni::Event< void(Page &, bool &)> onPageAccept
Event: Page changing.
Definition: notebook.h:332
Yuni::Event< void(Page &)> onPageChanged
Event: Page changing.
Definition: notebook.h:344
void theme(Theme t)
Set the current theme.
Definition: notebook.h:289
Page * find(const wxString &name)
Find a page by its name.
Definition: notebook.cpp:1076
std::vector< Page * > Pages
All pages.
Definition: notebook.h:399
Notebook(wxWindow *parent, Orientation orientation=orLeft)
Default constructor.
Definition: notebook.cpp:45
bool alwaysDisplayTabs() const
Get if the tabs must always be displayed, even if a single one is available.
Definition: notebook.hxx:81
wxString pCaption
The caption of the notebook.
Definition: notebook.h:405
void clear()
Delete all pages.
Definition: notebook.cpp:707
Panel implementation.
Definition: panel.h:34