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