Audacity  2.2.2
ExpandingToolBar.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  ExpandingToolBar.h
6 
7  Dominic Mazzoni
8 
9 **********************************************************************/
10 
11 #ifndef __AUDACITY_EXPANDING_TOOL_BAR__
12 #define __AUDACITY_EXPANDING_TOOL_BAR__
13 
14 #include "../MemoryX.h"
15 #include <vector>
16 #include <wx/defs.h>
17 #include <wx/dialog.h>
18 #include <wx/panel.h>
19 #include <wx/hashmap.h>
20 #include <wx/timer.h>
21 #include <wx/minifram.h>
22 
23 #include "ImageRoll.h"
24 #include "wxPanelWrapper.h"
25 
26 #include <unordered_map>
27 
28 class wxDragImage;
29 
30 class AButton;
31 
32 class ExpandingToolBar;
33 class ToolBarFrame;
34 class ToolBarDialog;
35 class ToolBarArea;
36 class ToolBarGrabber;
37 
38 class ToolBarArrangement;
39 
40 using WindowHash = std::unordered_map<void*, int>;
41 
43 
44 //
45 // A smart ToolBar class that has a "MainPanel" which is always
46 // displayed, and an "ExtraPanel" that can be hidden to save space.
47 // Can be docked into a ToolBarArea or floated in an ToolBarFrame;
48 //
49 
50 class ExpandingToolBar final : public wxPanelWrapper
51 {
52  public:
53  DECLARE_DYNAMIC_CLASS(ExpandingToolBar)
54 
55  ExpandingToolBar(wxWindow* parent, wxWindowID id,
56  const wxPoint& pos = wxDefaultPosition,
57  const wxSize& size = wxDefaultSize);
58 
59  virtual ~ExpandingToolBar();
60 
61  wxPanel *GetMainPanel() { return mMainPanel; }
62  wxPanel *GetExtraPanel() { return mExtraPanel; }
63 
64  void SetAutoExpand(bool enabled) { mAutoExpand = enabled; }
65  bool GetAutoExpand() { return mAutoExpand; }
66 
67  void Expand();
68  void Collapse(bool now = false);
69 
70  bool IsExpanded() { return mIsExpanded; }
71 
72  void OnSize(wxSizeEvent &evt);
73  void OnToggle(wxCommandEvent &evt);
74  void OnTimer(wxTimerEvent &evt);
75 
76  void StartMoving();
77  void UpdateMoving();
78  void FinishMoving();
79 
80  bool Layout() override;
81  void Fit() override;
82 
83  protected:
84  void RecursivelyPushEventHandlers(wxWindow *win);
85  bool IsCursorInWindow();
86  void ReparentExtraPanel();
87  void MoveDrawer(wxSize prevSize);
88  wxBitmap GetToolbarBitmap();
89 
90  void TryAutoExpand();
91  void TryAutoCollapse();
92 
93  wxPanel *mMainPanel;
94  wxPanel *mExtraPanel;
102  wxSize mMainSize;
103  wxSize mExtraSize;
104  wxSize mButtonSize;
105  wxSize mGrabberSize;
110  wxTimer mTimer;
114  std::unique_ptr<ToolBarArrangement> mSavedArrangement;
116  std::unique_ptr<wxDragImage> mDragImage;
117  wxWindow *mTopLevelParent;
118  std::vector<wxRect> mDropTargets;
119  wxRect mDropTarget;
120 
122 
123  DECLARE_EVENT_TABLE()
124 
126  std::vector< std::unique_ptr< ExpandingToolBarEvtHandler > > mHandlers;
127 };
128 
129 class ToolBarGrabber final : public wxPanelWrapper
130 {
131  public:
132  DECLARE_DYNAMIC_CLASS(ToolBarGrabber)
133 
134  ToolBarGrabber(wxWindow *parent,
135  wxWindowID id,
136  ExpandingToolBar *ownerToolbar,
137  const wxPoint& pos = wxDefaultPosition,
138  const wxSize& size = wxDefaultSize);
139 
140  void OnPaint(wxPaintEvent &evt);
141  void OnSize(wxSizeEvent &evt);
142  void OnMouse(wxMouseEvent &evt);
143 
144  protected:
145  int mState;
146  //ImageRoll mImageRoll[2];
148 
149  DECLARE_EVENT_TABLE()
150 };
151 
152 class ToolBarDialog final : public wxDialogWrapper
153 {
154  public:
155  DECLARE_DYNAMIC_CLASS(ToolBarDialog)
156 
157  ToolBarDialog(wxWindow* parent,
158  wxWindowID id,
159  const wxString& name = wxEmptyString,
160  const wxPoint& pos = wxDefaultPosition);
161 
162  ~ToolBarDialog();
163 
164  void Fit() override;
165 
166  void SetChild(ExpandingToolBar *child);
167 
168  protected:
170 
171  DECLARE_EVENT_TABLE()
172 };
173 
174 class ToolBarFrame final : public wxMiniFrame
175 {
176  public:
177  DECLARE_DYNAMIC_CLASS(ToolBarFrame)
178 
179  ToolBarFrame(wxWindow* parent,
180  wxWindowID id,
181  const wxString& name = wxEmptyString,
182  const wxPoint& pos = wxDefaultPosition);
183 
184  ~ToolBarFrame();
185 
186  void Fit() override;
187 
188  void SetChild(ExpandingToolBar *child);
189 
190  protected:
192 
193  DECLARE_EVENT_TABLE()
194 };
195 
196 //
197 // Note: with a ToolBarArea, the parent sets the width, but the
198 // ToolBarArea sets the height dynamically based on the number of
199 // toolbars it contains.
200 //
201 class ToolBarArea final : public wxPanelWrapper
202 {
203  public:
204  DECLARE_DYNAMIC_CLASS(ToolBarArea)
205 
206  ToolBarArea(wxWindow* parent,
207  wxWindowID id,
208  const wxPoint& pos = wxDefaultPosition,
209  const wxSize& size = wxDefaultSize);
210  ~ToolBarArea();
211 
212  bool Layout() override;
213  void Fit() override;
214 
215  void OnSize(wxSizeEvent &evt);
216  void OnMouse(wxMouseEvent &evt);
217 
218  void CollapseAll(bool now = false);
219 
220  // Does not add or DELETE the window, just relates to layout...
221  void AddChild(ExpandingToolBar *child);
222  void RemoveChild(ExpandingToolBar *child);
223 
224  std::unique_ptr<ToolBarArrangement> SaveArrangement();
225  void RestoreArrangement(std::unique_ptr<ToolBarArrangement>&& arrangement);
226 
227  std::vector<wxRect> GetDropTargets();
228  void MoveChild(ExpandingToolBar *child, wxRect dropTarget);
229 
230  void SetCapturedChild(ExpandingToolBar *child);
231 
232  protected:
233  void ContractRow(int rowIndex);
234  bool ExpandRow(int rowIndex);
235  void LayoutOne(int childIndex);
236  void AdjustLayout();
237  void Fit(bool horizontal, bool vertical);
238 
239  std::vector<ExpandingToolBar*> mChildArray;
240  std::vector<int> mRowArray;
242  bool mInOnSize;
243 
245 
246  wxSize mMinSize;
247  wxSize mMaxSize;
248  wxSize mActualSize;
249 
250  std::vector<wxRect> mDropTargets;
251  std::vector<int> mDropTargetIndices;
252  std::vector<int> mDropTargetRows;
253 
254  DECLARE_EVENT_TABLE()
255 };
256 
257 #endif // __AUDACITY_EXPANDING_TOOL_BAR__
wxWindow * mTopLevelParent
std::unique_ptr< ToolBarArrangement > mSavedArrangement
bool Layout() override
void Fit() override
static int msNoAutoExpandStack
AButton * mToggleButton
ExpandingToolBar(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
ExpandingToolBar * mOwnerToolBar
void RecursivelyPushEventHandlers(wxWindow *win)
void MoveDrawer(wxSize prevSize)
ToolBarArea * mAreaParent
ToolBarDialog * mDialogParent
WindowHash mWindowHash
Draws the grabber for an ExpandingToolBar.
A custom event handler for ExpandingToolBar.
std::vector< int > mDropTargetIndices
ExpandingToolBar * mChild
void OnToggle(wxCommandEvent &evt)
A smart ToolBar class that has a "MainPanel" which is always displayed, and an "ExtraPanel" that can ...
ImageRollPanel * mTargetPanel
A miniframe based container for ExpandingToolBars providing modeless presentation.
std::vector< std::unique_ptr< ExpandingToolBarEvtHandler > > mHandlers
std::vector< wxRect > mDropTargets
wxPanel * GetMainPanel()
A dialog based container for ExpandingToolBars providing modal based operations.
void OnSize(wxSizeEvent &evt)
std::vector< ExpandingToolBar * > mChildArray
wxPanel * GetExtraPanel()
void SetAutoExpand(bool enabled)
Small class that holds some layout information for an ExpandingToolBar.
An alterantive to ToolBarFrame which can contain an ExpandingToolBar. ToolBarArea is used for a 'dock...
void Collapse(bool now=false)
wxSize mLastLayoutSize
A wxPanel which displays an ImageRoll.
Definition: ImageRoll.h:71
ToolBarFrame * mFrameParent
std::vector< int > mRowArray
ExpandingToolBar * mChild
ExpandingToolBar * mCapturedChild
void OnTimer(wxTimerEvent &evt)
const wxChar * name
Definition: Distortion.cpp:94
wxBitmap GetToolbarBitmap()
ToolBarGrabber * mGrabber
std::vector< wxRect > mDropTargets
std::unordered_map< void *, int > WindowHash
std::vector< int > mDropTargetRows
std::unique_ptr< wxDragImage > mDragImage
A wxButton with mouse-over behaviour.
Definition: AButton.h:28