Antares Simulator
Power System Simulator
spotlight.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_UI_COMMON_COMPONENT_SPOTLIGHT_SPOTLIGHT_H__
22 #define __ANTARES_UI_COMMON_COMPONENT_SPOTLIGHT_SPOTLIGHT_H__
23 
24 #include <yuni/yuni.h>
25 #include "../panel.h"
26 #include <vector>
27 #include <yuni/core/event.h>
28 #include <wx/bitmap.h>
29 #include <wx/textctrl.h>
30 #include <wx/combobox.h>
31 #include <yuni/core/color/rgb.h>
32 
33 #include <memory>
34 
35 namespace Antares::Component
36 {
37 class Spotlight final: public Antares::Component::Panel, public Yuni::IEventObserver<Spotlight>
38 {
39 public:
40  enum Options
41  {
42  optNone = 0,
43  optResultsInAPopup = 1,
45  optGroups = 2,
52  };
53 
54  enum
55  {
57  defaultFlags = optResultsInAPopup | optGroups,
58  };
59 
60 // class SearchToken
61 #include "searchtoken.h"
62 
63 // class IItem / Separator
64 #include "iitem.h"
65 #include "separator.h"
66 #include "text.h"
67 
68 // class IProvider
69 #include "provider.h"
70 
71 // class NullProvider
72 #include "null-provider.h"
73 
74 public:
78  static void FrameShow(wxWindow* parent,
80  uint flags = optGroups,
81  uint width = 340);
82 
86  static void FrameClose();
87 
88 public:
90 
91 
97  Spotlight(wxWindow* parent, uint flags = defaultFlags);
99  virtual ~Spotlight();
101 
103 
104 
107  void search(const Yuni::String& text);
108 
113  void search(const wxString& text);
114 
118  void redoResearch();
119 
125  void resetSearchInput();
127 
133  void onMapLayerChanged(const wxString* text);
135 
136  void onMapLayerAdded(const wxString* text);
137 
138  void onMapLayerRemoved(const wxString* text);
139 
140  void onMapLayerRenamed(const wxString* text);
141 
143 
144  IProvider::Ptr provider() const;
149 
151 
152  uint itemHeight() const;
155  void itemHeight(uint h);
157 
158 public:
160  Yuni::Event<void(const IItem::VectorPtr&, const SearchToken::VectorPtr&)> onUpdateItems;
161 
165  void updateResults();
166 
167 protected:
171  void convertRawTextIntoSearchTokenVector(SearchToken::Vector& out, const Yuni::String& text);
172 
173  void createComponents(Spotlight* parent, bool input, bool results);
174 
176  void onInputUpdated(wxCommandEvent& evt);
177 
178  void onComboUpdated(wxCommandEvent& evt);
179 
181  void resizeParentWindow();
182 
183 protected:
185  uint pFlags;
187  IProvider::Ptr pDataProvider;
191  SearchToken::VectorPtr pTokens;
193  Yuni::String pLastResearch;
195  Yuni::Event<void(IProvider::Ptr)> pResetProvider;
197  wxComboBox* pLayerFilter;
199  wxTextCtrl* pEdit;
201  wxWindow* pListbox;
204 
205  // data related to frame
209  wxWindow* pLayoutParent;
211  // When the mini frame is above the parent control, it should not be resized
212  // the frame can be resized if this variable is zero
214 
215  // keeping the sizers for some hide/show Magic depending on the number of layers
216  wxBoxSizer* vz;
217  wxBoxSizer* hzCombo;
218 
219 }; // class Spotlight
220 
221 } // namespace Antares::Component
222 
223 #include "iitem.hxx"
224 #include "spotlight.hxx"
225 
226 #endif // __ANTARES_UI_COMMON_COMPONENT_SPOTLIGHT_SPOTLIGHT_H__
Panel implementation.
Definition: panel.h:34
Definition: spotlight.h:38
void convertRawTextIntoSearchTokenVector(SearchToken::Vector &out, const Yuni::String &text)
Convert a raw text into a vector of tokens.
Definition: spotlight.cpp:306
int pDisplayHandle
Display monitor handle.
Definition: spotlight.h:207
@ defaultFlags
Default flags used by the constructor.
Definition: spotlight.h:57
wxWindow * pLayoutParent
Parent to consider for layout positioning when used from a frame.
Definition: spotlight.h:209
void updateResults()
Update the GUI with the new results.
Definition: spotlight.cpp:366
void onInputUpdated(wxCommandEvent &evt)
Event: the text input has been changed.
Definition: spotlight.cpp:559
static void FrameClose()
Close any opened window.
Definition: spotlight.cpp:728
IItem::VectorPtr pResults
Result set.
Definition: spotlight.h:189
virtual ~Spotlight()
Destructor.
Definition: spotlight.cpp:65
static void FrameShow(wxWindow *parent, IProvider::Ptr provider, uint flags=optGroups, uint width=340)
Display the spotlight in a frame.
Definition: spotlight.cpp:608
Options
Definition: spotlight.h:41
@ optBkgWhite
Use a white background instead of the default one.
Definition: spotlight.h:51
@ optGroups
Display groups as well.
Definition: spotlight.h:45
@ optAutoResizeParent
Try to automatically resize the parent window when according to the list.
Definition: spotlight.h:47
@ optNoSearchInput
The search input will not be shown.
Definition: spotlight.h:49
wxComboBox * pLayerFilter
ComboBox Filter.
Definition: spotlight.h:197
Yuni::String pLastResearch
The last research.
Definition: spotlight.h:193
uint pFlags
Flags.
Definition: spotlight.h:185
uint pItemHeight
Item height.
Definition: spotlight.h:203
IProvider::Ptr provider() const
Get the provider.
Definition: spotlight.hxx:36
Spotlight(wxWindow *parent, uint flags=defaultFlags)
Default constructor.
Definition: spotlight.cpp:51
wxTextCtrl * pEdit
Text edit.
Definition: spotlight.h:199
Yuni::Event< void(const IItem::VectorPtr &, const SearchToken::VectorPtr &)> onUpdateItems
Event: update items.
Definition: spotlight.h:160
void resetSearchInput()
Reset the search input.
Definition: spotlight.cpp:483
uint itemHeight() const
Get the item height.
Definition: spotlight.hxx:61
Yuni::Event< void(IProvider::Ptr)> pResetProvider
Internal updater for the provider.
Definition: spotlight.h:195
void redoResearch()
Redo the last search.
Definition: spotlight.cpp:254
bool pAllowFrameResize
Previous height.
Definition: spotlight.h:213
void resizeParentWindow()
Resize the parent window.
Definition: spotlight.cpp:384
void search(const Yuni::String &text)
Update the component with a given search string.
void onMapLayerChanged(const wxString *text)
set the value of the search input
Definition: spotlight.cpp:533
wxWindow * pListbox
The listbox.
Definition: spotlight.h:201
std::shared_ptr< Vector > VectorPtr
Vector Ptr.
Definition: iitem.h:34
std::shared_ptr< IProvider > Ptr
ptr
Definition: provider.h:33
std::shared_ptr< Vector > VectorPtr
Vector ptr.
Definition: searchtoken.h:35
std::vector< Ptr > Vector
Vector of search tokens.
Definition: searchtoken.h:33