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