From 4d5c10a6905942f93eaa3104673925e551eb132e Mon Sep 17 00:00:00 2001 From: "james.k.crook" Date: Sat, 6 Feb 2010 16:12:56 +0000 Subject: [PATCH] Patch from Ed Musgrove to allow narrower meter bar, plus also actions from code-review. --- src/toolbars/ToolBar.cpp | 52 +++++++++++++++++++--------------------- src/toolbars/ToolBar.h | 2 +- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/toolbars/ToolBar.cpp b/src/toolbars/ToolBar.cpp index 8a5622d64..69cc862fe 100644 --- a/src/toolbars/ToolBar.cpp +++ b/src/toolbars/ToolBar.cpp @@ -259,13 +259,17 @@ void ToolBar::ReCreateButtons() Layout(); // Recalculate the height to be a multiple of toolbarSingle -#define tbs ( toolbarSingle + toolbarGap ) + const int tbs = toolbarSingle + toolbarGap; wxSize sz = GetSize(); sz.y = ( ( ( sz.y + tbs ) / tbs ) * tbs ) - 1; -#undef tbs // Set the true AND minimum sizes and do final layout SetInitialSize(sz); + if(IsResizable()) + {// EM: allows narrow Meter Toolbar + sz.SetWidth(160); + SetMinSize(sz); + } Layout(); } @@ -585,6 +589,18 @@ void ToolBar::OnPaint( wxPaintEvent & event ) } } +/// @return true iff pos is in resize grabber. +bool ToolBar::IsResizeGrabberHit( wxPoint & pos ) +{ + wxRect rect = GetRect(); + + // Adjust to size of resize grabber + rect.x = rect.width - RWIDTH; + rect.y = 0; + rect.width = RWIDTH; + return rect.Contains( pos ); +} + // // Handle toolbar resizing // @@ -603,19 +619,11 @@ void ToolBar::OnLeftDown( wxMouseEvent & event ) if( IsResizable() ) { wxPoint pos = event.GetPosition(); - wxRect rect = GetRect(); - - // Adjust to size of resize grabber - rect.x = rect.width - RWIDTH; - rect.y = 0; - rect.width = RWIDTH; - // Is left click within resize grabber? - if( rect.Contains( pos ) ) + if( IsResizeGrabberHit( pos ) ) { // Retrieve the mouse position mResizeStart = ClientToScreen( pos ); - // We want all of the mouse events CaptureMouse(); } @@ -647,29 +655,17 @@ void ToolBar::OnMotion( wxMouseEvent & event ) } // Retrieve the mouse position - wxPoint pos = ClientToScreen( event.GetPosition() ); + wxPoint raw_pos = event.GetPosition(); + wxPoint pos = ClientToScreen( raw_pos ); if( !HasCapture() ) { + // JKC: Wrong place for this? Surely the cursor should change on + // mouse-down and capture-lost rather than with mouse movement? if( IsResizable() ) { - wxPoint pos = event.GetPosition(); - wxRect rect = GetRect(); - - // Adjust to size of resize grabber - rect.x = rect.width - RWIDTH; - rect.y = 0; - rect.width = RWIDTH; - // Is left click within resize grabber? - if( rect.Contains( pos ) ) - { - SetCursor( wxCURSOR_SIZEWE ); - } - else - { - SetCursor( wxCURSOR_ARROW ); - } + SetCursor( IsResizeGrabberHit( raw_pos ) ? wxCURSOR_SIZEWE : wxCURSOR_ARROW); } } else if( event.Dragging() ) diff --git a/src/toolbars/ToolBar.h b/src/toolbars/ToolBar.h index e7d943a4f..5451aed1b 100644 --- a/src/toolbars/ToolBar.h +++ b/src/toolbars/ToolBar.h @@ -159,7 +159,7 @@ class ToolBar:public wxPanel void OnCaptureLost(wxMouseCaptureLostEvent & event); private: - + bool IsResizeGrabberHit( wxPoint & pos ); void Init(wxWindow *parent, int type, const wxString & title, const wxString & label); wxWindow *mParent;