Audacity 3.2.0
Public Member Functions | Private Attributes | List of all members
ToolFrame Class Referencefinal

class ToolFrame More...

#include <ToolManager.h>

Inheritance diagram for ToolFrame:
[legend]
Collaboration diagram for ToolFrame:
[legend]

Public Member Functions

 ToolFrame (AudacityProject *parent, ToolManager *manager, ToolBar *bar, wxPoint pos)
 
 ~ToolFrame ()
 
ToolBarGetBar ()
 
void ClearBar ()
 
void LockInMinSize (ToolBar *pBar)
 
void OnGrabber (GrabberEvent &event)
 
void OnToolBarUpdate (wxCommandEvent &event)
 
void OnPaint (wxPaintEvent &WXUNUSED(event))
 
void OnMotion (wxMouseEvent &event)
 
void OnCaptureLost (wxMouseCaptureLostEvent &WXUNUSED(event))
 
void OnClose (wxCloseEvent &event)
 
void OnKeyDown (wxKeyEvent &event)
 
void Resize (const wxSize &size)
 

Private Attributes

AudacityProject *const mParent
 
ToolManagermManager
 
ToolBarmBar
 
wxSize mMinSize
 
wxSize mOrigSize
 

Detailed Description

class ToolFrame

Definition at line 167 of file ToolManager.h.

Constructor & Destructor Documentation

◆ ToolFrame()

ToolFrame::ToolFrame ( AudacityProject parent,
ToolManager manager,
ToolBar bar,
wxPoint  pos 
)

Definition at line 74 of file ToolManager.cpp.

76 : wxFrame( FindProjectFrame( parent ),
77 bar->GetId(),
78 wxEmptyString,
79 pos,
80 wxDefaultSize,
81 wxNO_BORDER |
82 wxFRAME_NO_TASKBAR |
83#if !defined(__WXMAC__) // bug1358
84 wxFRAME_TOOL_WINDOW |
85#endif
86 wxFRAME_FLOAT_ON_PARENT )
87 , mParent{ parent }
88{
89 int width = bar->GetSize().x;
90 int border = 1;
91
92 // Save parameters
94 mBar = bar;
95
96 // Transfer the bar to the ferry
97 bar->Reparent(this);
98
99 // Bug 2120 (comment 6 residual): No need to set a minimum size
100 // if the toolbar is not resizable. On GTK, setting a minimum
101 // size will prevent the frame from shrinking if the toolbar gets
102 // reconfigured and needs to resize smaller.
103 if (bar->IsResizable())
104 {
105 SetMinSize(bar->GetDockedSize());
106 }
107
108 {
109 // We use a sizer to maintain proper spacing
110 auto s = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
111
112 // Add the bar to the sizer
113 s->Add(bar, 1, wxEXPAND | wxALL, border);
114
115 // Add space for the resize grabber
116 if (bar->IsResizable())
117 {
118 s->Add(sizerW, 1);
119 width += sizerW;
120 }
121
122 SetSize(width + 2 * ToolBarFloatMargin,
123 bar->GetDockedSize().y + 2 * ToolBarFloatMargin);
124
125 // Attach the sizer and resize the window to fit
126 SetSizer(s.release());
127 }
128
129 Layout();
130
131 // Inform toolbar of change
132 bar->SetDocked( NULL, true );
133
134 // Make sure resizable floaters don't get any smaller than initial size
135 if( bar->IsResizable() )
136 {
137 // Calc the minimum size of the frame
138 mMinSize = bar->GetMinSize() + ( GetSize() - bar->GetSize() );
139 }
140}
wxFrame * FindProjectFrame(AudacityProject *project)
Get a pointer to the window associated with a project, or null if the given pointer is null,...
static const AttachedProjectObjects::RegisteredFactory manager
@ ToolBarFloatMargin
Definition: ToolBar.h:94
#define sizerW
Methods for ToolFrame.
Definition: ToolManager.cpp:69
virtual void SetDocked(ToolDock *dock, bool pushed)
Definition: ToolBar.cpp:647
bool IsResizable() const
Definition: ToolBar.cpp:424
virtual wxSize GetDockedSize()
Definition: ToolBar.h:149
ToolBar * mBar
Definition: ToolManager.h:212
wxSize mMinSize
Definition: ToolManager.h:213
ToolManager * mManager
Definition: ToolManager.h:211
AudacityProject *const mParent
Definition: ToolManager.h:210

References ToolBar::GetDockedSize(), ToolBar::IsResizable(), manager, mBar, mManager, mMinSize, ToolBar::SetDocked(), sizerW, and ToolBarFloatMargin.

Here is the call graph for this function:

◆ ~ToolFrame()

ToolFrame::~ToolFrame ( )

Definition at line 142 of file ToolManager.cpp.

143{
144 if(HasCapture())
145 ReleaseMouse();
146}

Member Function Documentation

◆ ClearBar()

void ToolFrame::ClearBar ( )
inline

Definition at line 176 of file ToolManager.h.

176{ mBar = nullptr; }

References mBar.

Referenced by ToolManager::HandleEscapeKey(), and ToolManager::OnMouse().

Here is the caller graph for this function:

◆ GetBar()

ToolBar * ToolFrame::GetBar ( )
inline

Definition at line 175 of file ToolManager.h.

175{ return mBar; }

References mBar.

◆ LockInMinSize()

void ToolFrame::LockInMinSize ( ToolBar pBar)

Definition at line 156 of file ToolManager.cpp.

157{
158 mBar = pBar;
159
160 wxSize sz = mBar->GetSize();
161 SetClientSize( sz );
162 int yDesiredMin = 26;
163 int y = sz.GetHeight();
164 if (y > yDesiredMin) {
165 sz.SetWidth((sz.GetWidth() * yDesiredMin) / y);
166 sz.SetHeight( yDesiredMin );
167 }
168 mMinSize = sz -wxSize( 10, 0);
169}

References mBar, and mMinSize.

◆ OnCaptureLost()

void ToolFrame::OnCaptureLost ( wxMouseCaptureLostEvent &  WXUNUSEDevent)

Definition at line 283 of file ToolManager.cpp.

284{
285 if( HasCapture() )
286 {
287 ReleaseMouse();
288 }
289}

◆ OnClose()

void ToolFrame::OnClose ( wxCloseEvent &  event)

Definition at line 291 of file ToolManager.cpp.

292{
293 event.Veto();
294}

◆ OnGrabber()

void ToolFrame::OnGrabber ( GrabberEvent event)

Definition at line 148 of file ToolManager.cpp.

149{
150 // Pass it on to the manager since it isn't in the handling hierarchy
151 mManager->ProcessEvent( event );
152}

References mManager.

◆ OnKeyDown()

void ToolFrame::OnKeyDown ( wxKeyEvent &  event)

Definition at line 296 of file ToolManager.cpp.

297{
298 event.Skip();
299 if( HasCapture() && event.GetKeyCode() == WXK_ESCAPE ) {
300 Resize( mOrigSize );
301 ReleaseMouse();
302 }
303}
wxSize mOrigSize
Definition: ToolManager.h:214
void Resize(const wxSize &size)

References mOrigSize, and Resize().

Here is the call graph for this function:

◆ OnMotion()

void ToolFrame::OnMotion ( wxMouseEvent &  event)

Definition at line 209 of file ToolManager.cpp.

210{
211 // Don't do anything if we're docked or not resizeable
212 if( !mBar || mBar->IsDocked() || !mBar->IsResizable() )
213 {
214 return;
215 }
216
217 // Retrieve the mouse position
218 wxPoint pos = ClientToScreen( event.GetPosition() );
219 if( HasCapture() && event.Dragging() )
220 {
221 wxRect rect = GetRect();
222
223 rect.SetBottomRight( pos );
224
225 // Keep it within max size, if specified
226 wxSize maxsz = mBar->GetMaxSize();
227 if (maxsz != wxDefaultSize)
228 {
229 if (maxsz.x != wxDefaultCoord && rect.width > maxsz.x)
230 {
231 rect.width = maxsz.x;
232 }
233 if (maxsz.y != wxDefaultCoord && rect.height > maxsz.y)
234 {
235 rect.height = maxsz.y;
236 }
237 }
238
239 if( rect.width < mMinSize.x )
240 {
241 rect.width = mMinSize.x;
242 }
243
244 if( rect.height < mMinSize.y )
245 {
246 rect.height = mMinSize.y;
247 }
248
249 Resize( rect.GetSize() );
250 }
251 else if( HasCapture() && event.LeftUp() )
252 {
253 ReleaseMouse();
254 }
255 else if( !HasCapture() )
256 {
257 wxRect rect = GetRect();
258 wxRect r;
259
260 r.x = rect.GetRight() - sizerW - 2,
261 r.y = rect.GetBottom() - sizerW - 2;
262 r.width = sizerW + 2;
263 r.height = sizerW + 2;
264
265 // Is left click within resize grabber?
266 if( r.Contains( pos ) && !event.Leaving() )
267 {
268 mOrigSize = GetSize();
269
270 SetCursor( wxCURSOR_SIZENWSE );
271 if( event.LeftDown() )
272 {
273 CaptureMouse();
274 }
275 }
276 else
277 {
278 SetCursor( wxCURSOR_ARROW );
279 }
280 }
281}
bool IsDocked() const
Definition: ToolBar.cpp:432

References ToolBar::IsDocked(), ToolBar::IsResizable(), mBar, mMinSize, mOrigSize, Resize(), and sizerW.

Here is the call graph for this function:

◆ OnPaint()

void ToolFrame::OnPaint ( wxPaintEvent &  WXUNUSEDevent)

Definition at line 182 of file ToolManager.cpp.

183{
184 wxPaintDC dc( this );
185 wxSize sz = GetSize();
186 wxRect r;
187
188 dc.SetPen( theTheme.Colour( clrTrackPanelText ) );
189 dc.SetBackground( wxBrush( theTheme.Colour( clrMedium ) ) );
190 dc.Clear();
191 dc.SetBrush( *wxTRANSPARENT_BRUSH );
192 dc.DrawRectangle( 0, 0, sz.GetWidth(), sz.GetHeight() );
193
194 if( mBar && mBar->IsResizable() )
195 {
196 r.x = sz.x - sizerW - 2,
197 r.y = sz.y - sizerW - 2;
198 r.width = sizerW + 2;
199 r.height = sizerW + 2;
200
201 AColor::Line(dc, r.GetLeft(), r.GetBottom(), r.GetRight(), r.GetTop() );
202 AColor::Line(dc, r.GetLeft() + 3, r.GetBottom(), r.GetRight(), r.GetTop() + 3 );
203 AColor::Line(dc, r.GetLeft() + 6, r.GetBottom(), r.GetRight(), r.GetTop() + 6 );
204 AColor::Line(dc, r.GetLeft() + 9, r.GetBottom(), r.GetRight(), r.GetTop() + 9 );
205 }
206
207}
THEME_API Theme theTheme
Definition: Theme.cpp:82
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:187
wxColour & Colour(int iIndex)

References ThemeBase::Colour(), ToolBar::IsResizable(), AColor::Line(), mBar, sizerW, and theTheme.

Here is the call graph for this function:

◆ OnToolBarUpdate()

void ToolFrame::OnToolBarUpdate ( wxCommandEvent &  event)

Definition at line 171 of file ToolManager.cpp.

172{
173 // Resize floater window to exactly contain toolbar
174 // use actual size rather than minimum size.
175 if (mBar)
176 mBar->GetParent()->SetClientSize( mBar->GetSize() );// ->GetMinSize() );
177
178 // Allow it to propagate to our parent
179 event.Skip();
180}

References mBar.

◆ Resize()

void ToolFrame::Resize ( const wxSize &  size)

Definition at line 305 of file ToolManager.cpp.

306{
307 SetMinSize( size );
308 SetSize( size );
309 Layout();
310 Refresh( false );
311}

References size.

Referenced by OnKeyDown(), and OnMotion().

Here is the caller graph for this function:

Member Data Documentation

◆ mBar

ToolBar* ToolFrame::mBar
private

◆ mManager

ToolManager* ToolFrame::mManager
private

Definition at line 211 of file ToolManager.h.

Referenced by OnGrabber(), and ToolFrame().

◆ mMinSize

wxSize ToolFrame::mMinSize
private

Definition at line 213 of file ToolManager.h.

Referenced by LockInMinSize(), OnMotion(), and ToolFrame().

◆ mOrigSize

wxSize ToolFrame::mOrigSize
private

Definition at line 214 of file ToolManager.h.

Referenced by OnKeyDown(), and OnMotion().

◆ mParent

AudacityProject* const ToolFrame::mParent
private

Definition at line 210 of file ToolManager.h.


The documentation for this class was generated from the following files: