Antares Simulator
Power System Simulator
mapnotebook.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_MAPNOTEBOOK_H__
22 #define __ANTARES_TOOLBOX_COMPONENT_MAPNOTEBOOK_H__
23 
24 #include "notebook.h"
25 #include <wx/textctrl.h>
26 #include <antares/logs/logs.h>
27 namespace Antares::Component
28 {
32 class MapNotebook: public Notebook, public Yuni::IEventObserver<MapNotebook>
33 {
34  friend class MapTabs;
35 
36 public:
38 
39 
43  MapNotebook(wxWindow* parent, Notebook::Orientation orientation = orLeft);
44 
45  ~MapNotebook()
46  {
47  destroyBoundEvents();
48  }
49 
53  void onMapLayerChanged(const wxString* text);
54  bool remove(Page* page);
55 
56 public:
57  class TabTextCtrl: public wxTextCtrl
58  {
59  public:
60  TabTextCtrl(Tabs* parent, wxWindowID id, Page* pageToRename):
61  wxTextCtrl((wxWindow*)parent,
62  id,
63  pageToRename->caption(),
64  wxPoint(pageToRename->pBoundingBox.x, pageToRename->pBoundingBox.y),
65  pageToRename->pBoundingBox.GetSize(),
66  wxTE_PROCESS_ENTER),
67  pPage(pageToRename),
68  pNotebook(&(parent->pNotebook))
69  {
70  SelectAll();
71  }
72 
73  ~TabTextCtrl() = default;
74  void OnTextEnter(wxCommandEvent& evt);
75 
76  void SetPage(Page* p)
77  {
78  if (p != nullptr)
79  {
80  pPage = p;
81  SetValue(pPage->caption());
82  Move(pPage->pBoundingBox.x, pPage->pBoundingBox.y);
83  SetSize(pPage->pBoundingBox.GetSize());
84  SelectAll();
85  Show();
86  }
87  else
88  {
89  Hide();
90  }
91  }
92 
93  private:
94  Page* pPage;
95  Notebook* pNotebook;
96  };
97 
98 public:
99  class MapTabs: public Notebook::Tabs
100  {
101  friend class MapNotebook;
102 
103  private:
104  class tabButton
105  {
106  public:
107  enum BtnType
108  {
109  btnLeft,
110  btnRight,
111  btnNone
112  };
113 
114  tabButton(std::string imagePath,
115  MapTabs* parentFrame,
116  BtnType t = btnNone,
117  const char* hoverImagePath = nullptr);
118  ~tabButton();
119  void drawButton(wxDC& dc, int x, int y);
120  void onMouseUp(wxMouseEvent&);
121  void onMouseEnter();
122  void onMouseLeave();
123  void onClick(wxMouseEvent&, BtnType t);
124 
125  BtnType type;
126  wxPoint coords;
127  wxBitmap* buttonImage = nullptr;
128  wxBitmap* hoverImage = nullptr;
129  wxRect* pBoundingBox = nullptr;
130  MapTabs* parentTabFrame = nullptr;
131  bool isVisible;
132  bool drawHover = false;
133  };
134 
135  int sizingOffset;
136  int undrawnLeftTabs;
137  int remainingRightTabs;
138  tabButton* rightTabScroll;
139  tabButton* leftTabScroll;
140  tabButton* addPageButton;
141  TabTextCtrl* pTabNameCtrl;
142 
143  public:
144  MapTabs(wxWindow* parent, Notebook& notebook);
145 
146  ~MapTabs()
147  {
148  delete rightTabScroll;
149  delete leftTabScroll;
150  delete addPageButton;
151  }
152 
153  void onDraw(wxPaintEvent&);
154  void drawOrientationTop(wxDC& dc);
156 
157 
161  void doSizing(wxDC& dc);
162 
163  void drawItemTop(wxDC& dc, Page* page, int& pos, Notebook::Alignment align);
164  void onMouseUp(wxMouseEvent&);
165  void onMouseMove(wxMouseEvent&);
166  void onMouseLeave(wxMouseEvent&);
167 
171  Yuni::Event<void(int&, int&)> onMouseMotion;
172 
173  DECLARE_EVENT_TABLE()
174  };
175 
176 private:
177  wxRect closePageBoundingBox;
178 
179 public:
183  Yuni::Event<> onAddPage;
192  Yuni::Event<void(Page&)> onPageDelete;
193 
194 }; // class MapNotebook
195 
196 } // namespace Antares::Component
197 #endif
Definition: mapnotebook.h:100
void onMouseUp(wxMouseEvent &)
Click up.
Definition: mapnotebook.cpp:476
Yuni::Event< void(int &, int &)> onMouseMotion
Event: adding a page.
Definition: mapnotebook.h:171
void doSizing(wxDC &dc)
compute the offset and draw tab scrolling button if tabs don't fit in the window \
Definition: mapnotebook.cpp:324
MapNotebook.
Definition: mapnotebook.h:33
Yuni::Event< void(Page &)> onPageDelete
Event: Page deletion.
Definition: mapnotebook.h:192
void onMapLayerChanged(const wxString *text)
remove a page by its name
Definition: mapnotebook.cpp:88
Yuni::Event onAddPage
Event: adding a page.
Definition: mapnotebook.h:183
MapNotebook(wxWindow *parent, Notebook::Orientation orientation=orLeft)
Default constructor.
Definition: mapnotebook.cpp:47
Definition: notebook.h:61
const wxString & caption() const
Get the caption of the page.
Definition: notebook.hxx:36
Definition: notebook.h:348
Notebook.
Definition: notebook.h:36
Orientation orientation() const
Get the orientation of the notebook.
Definition: notebook.hxx:111
virtual void onMouseEnter()
The mouse has entered.
Definition: panel.h:69
virtual void onMouseLeave()
The mouse has leaved.
Definition: panel.h:74