Update of /cvsroot/audacity/audacity-src/src/toolbars
In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv16147

Modified Files:
        ToolManager.h ToolManager.cpp ToolBar.cpp MeterToolBar.cpp 
        ToolDock.cpp ToolBar.h 
Log Message:
Frameless toolbars...with many corrections to general handling.

Index: ToolManager.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/toolbars/ToolManager.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- ToolManager.cpp     17 Oct 2006 12:36:29 -0000      1.6
+++ ToolManager.cpp     22 Oct 2006 09:54:26 -0000      1.7
@@ -1,4 +1,4 @@
-/**********************************************************************
+ /**********************************************************************
 
   Audacity: A Digital Audio Editor
 
@@ -30,6 +30,7 @@
 #include <wx/wxprec.h>
 
 #ifndef WX_PRECOMP
+#include <wx/app.h>
 #include <wx/defs.h>
 #include <wx/event.h>
 #include <wx/frame.h>
@@ -45,6 +46,10 @@
 #include <wx/minifram.h>
 #include <wx/popupwin.h>
 
+#if defined(__WXMAC__)
+#include <wx/mac/uma.h>
+#endif
+
 #include "ToolManager.h"
 #include "ControlToolBar.h"
 #include "DeviceToolBar.h"
@@ -64,16 +69,228 @@
 #include "../widgets/AButton.h"
 #include "../widgets/Grabber.h"
 
+////////////////////////////////////////////////////////////
+/// Methods for ToolFrame
+////////////////////////////////////////////////////////////
+#define sizerW 11
+
+//
+// Constructor
+//
+class ToolFrame:public wxFrame
+{
+ public:
+
+   ToolFrame( wxWindow *parent, ToolManager *manager, ToolBar *bar, wxPoint 
pos )
+   : wxFrame( parent,
+              bar->GetId(),
+              wxEmptyString,
+              pos,
+              wxDefaultSize,
+              wxNO_BORDER |
+              wxFRAME_NO_TASKBAR |
+              wxFRAME_TOOL_WINDOW |
+              wxFRAME_FLOAT_ON_PARENT )
+   {
+      int width = bar->GetSize().x;
+      int border;
+
+      // OSX doesn't need a border, but Windows and Linux do
+      border = 1;
+#if defined(__WXMAC__)
+      border = 0;
+
+      // WXMAC doesn't support wxFRAME_FLOAT_ON_PARENT, so we do
+      SetWindowClass( (WindowRef) MacGetWindowRef(), kFloatingWindowClass );
+#endif
+
+      // Save parameters
+      mParent = parent;
+      mManager = manager;
+      mBar = bar;
+
+      // Transfer the bar to the ferry
+      bar->Reparent( this );
+
+      // We use a sizer to maintain proper spacing
+      wxBoxSizer *s = new wxBoxSizer( wxHORIZONTAL );
+
+      // Add the bar to the sizer
+      s->Add( bar, 1, wxEXPAND | wxALL, border );
+
+      // Add space for the resize grabber
+      if( bar->IsResizable() )
+      {
+         s->Add( sizerW, 1 );
+         width += sizerW;
+      }
+
+      SetSize( width + 2, bar->GetMinSize().y + 2 );
+
+      // Attach the sizer and resize the window to fit
+      SetSizer( s );
+      Layout();
+
+      // Inform toolbar of change
+      bar->SetDocked( false, true );
+
+      // Make sure resizable floaters don't get any smaller than initial size
+      if( bar->IsResizable() )
+      {
+         // Calc the minimum size of the frame
+         mMinSize = bar->GetBestFittingSize() + ( GetSize() - bar->GetSize() );
+      }
+   }
+
+   //
+   // Transition a toolbar from float to dragging
+   //
+   void OnGrabber( GrabberEvent & event )
+   {
+      // Pass it on to the manager since it isn't in the handling hierarchy
+      mManager->ProcessEvent( event );
+   }
+
+   //
+   // Handle frame paint events
+   //
+   void OnPaint( wxPaintEvent & event )
+   {
+      wxPaintDC dc( this );
+      wxSize sz = GetSize();
+      wxRect r;
+
+      dc.BeginDrawing();
+      dc.SetPen( wxColour( 90, 90, 90 ) );
+
+#if !defined(__WXMAC__)
+      
dc.SetBackground(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)));
+      dc.Clear();
+      dc.SetBrush( *wxTRANSPARENT_BRUSH );
+      dc.DrawRectangle( 0, 0, sz.GetWidth(), sz.GetHeight() );
+#endif
+
+      if( mBar->IsResizable() )
+      {
+         r.x = sz.x - sizerW - 2,
+         r.y = sz.y - sizerW - 2;
+         r.width = sizerW + 2;
+         r.height = sizerW + 2;
+
+         dc.DrawLine( r.GetLeft(), r.GetBottom(), r.GetRight(), r.GetTop() );
+         dc.DrawLine( r.GetLeft() + 3, r.GetBottom(), r.GetRight(), r.GetTop() 
+ 3 );
+         dc.DrawLine( r.GetLeft() + 6, r.GetBottom(), r.GetRight(), r.GetTop() 
+ 6 );
+         dc.DrawLine( r.GetLeft() + 9, r.GetBottom(), r.GetRight(), r.GetTop() 
+ 9 );
+      }
+
+      dc.EndDrawing();
+   }
+
+   void OnMotion( wxMouseEvent & event )
+   {
+      // Don't do anything if we're docked or not resizeable
+      if( mBar->IsDocked() || !mBar->IsResizable() )
+      {
+         return;
+      }
+
+      // Retrieve the mouse position
+      wxPoint pos = ClientToScreen( event.GetPosition() );
+      if( HasCapture() && event.Dragging() )
+      {
+         wxRect rect = GetRect();
+
+         rect.SetBottomRight( pos );
+         if( rect.width < mMinSize.x )
+         {
+            rect.width = mMinSize.x;
+         }
+
+         if( rect.height < mMinSize.y )
+         {
+            rect.height = mMinSize.y;
+         }        
+
+         SetMinSize( rect.GetSize() );
+         SetSize( rect.GetSize() );
+         Layout();
+         Refresh( false );
+      }
+      else if( event.LeftUp() )
+      {
+         ReleaseMouse();
+      }
+      else if( !HasCapture() )
+      {
+         wxRect rect = GetRect();
+         wxRect r;
+
+         r.x = rect.GetRight() - sizerW - 2,
+         r.y = rect.GetBottom() - sizerW - 2;
+         r.width = sizerW + 2;
+         r.height = sizerW + 2;
+
+         // Is left click within resize grabber?
+         if( r.Inside( pos ) && !event.Leaving() )
+         {
+            SetCursor( wxCURSOR_SIZENWSE );
+            if( event.LeftDown() )
+            {
+               CaptureMouse();
+            }
+         }
+         else
+         {
+            SetCursor( wxCURSOR_ARROW );
+         }
+      }
+   }
+
+   //
+   // Do not allow the window to close through keyboard accelerators
+   // (like ALT+F4 on Windows)
+   //
+   void OnClose( wxCloseEvent & event )
+   {
+      event.Veto();
+   }
+
+ private:
+
+   wxWindow *mParent;
+   ToolManager *mManager;
+   ToolBar *mBar;
+   wxSize mMinSize;
+
+ public:
+
+   DECLARE_CLASS( ToolFrame );
+   DECLARE_EVENT_TABLE();
+};
+
+IMPLEMENT_CLASS( ToolFrame, wxFrame );
+
+BEGIN_EVENT_TABLE( ToolFrame, wxFrame )
+   EVT_GRABBER( wxID_ANY, ToolFrame::OnGrabber )
+   EVT_PAINT( ToolFrame::OnPaint )
+   EVT_MOUSE_EVENTS( ToolFrame::OnMotion )
+   EVT_CLOSE( ToolFrame::OnClose )
+END_EVENT_TABLE()
+
 IMPLEMENT_CLASS( ToolManager, wxEvtHandler );
 
 ////////////////////////////////////////////////////////////
 /// Methods for ToolManager
 ////////////////////////////////////////////////////////////
 
+BEGIN_EVENT_TABLE( ToolManager, wxEvtHandler )
+   EVT_GRABBER( wxID_ANY, ToolManager::OnGrabber )
+END_EVENT_TABLE()
+
 //
 // Constructor
 //
-ToolManager::ToolManager( wxWindow *parent )
+ToolManager::ToolManager( AudacityProject *parent )
 : wxEvtHandler()
 {
    wxPoint pt[ 3 ];
@@ -90,7 +307,6 @@
    mDragWindow = NULL;
    mDragDock = NULL;
    mDragBar = NULL;
-   mWatchdog.SetOwner( this, wxID_ANY );
 
    // Create the down arrow
    pt[ 0 ].x = 0;
@@ -122,7 +338,7 @@
                              wxSize( 32, 32 ),
                              wxFRAME_TOOL_WINDOW |
                              wxFRAME_SHAPED |
-                             wxSIMPLE_BORDER |
+                             wxNO_BORDER |
                              wxFRAME_NO_TASKBAR |
                              wxSTAY_ON_TOP );
 
@@ -134,13 +350,24 @@
 
    // Hook the paint event...needed for all
    mIndicator->Connect( wxEVT_PAINT,
-                        wxPaintEventHandler( ToolManager::OnPaint ),
+                        wxPaintEventHandler( ToolManager::OnIndicatorPaint ),
                         NULL,
                         this );
 
    // It's a little shy
    mIndicator->Hide();
 
+   // Hook the parents mouse events...using the parent helps greatly
+   // under GTK
+   mParent->Connect( wxEVT_LEFT_UP,
+                     wxMouseEventHandler( ToolManager::OnMouse ),
+                     NULL,
+                     this );
+   mParent->Connect( wxEVT_MOTION,
+                     wxMouseEventHandler( ToolManager::OnMouse ),
+                     NULL,
+                     this );
+
    // Create the top and bottom docks
    mTopDock = new ToolDock( this, parent, TopDockID );
    mBotDock = new ToolDock( this, parent, BotDockID );
@@ -167,13 +394,23 @@
    // Save the toolbar states
    WriteConfig();
 
+   // Remove handlers from parent
+   mParent->Disconnect( wxEVT_LEFT_UP,
+                        wxMouseEventHandler( ToolManager::OnMouse ),
+                        NULL,
+                        this );
+   mParent->Disconnect( wxEVT_MOTION,
+                        wxMouseEventHandler( ToolManager::OnMouse ),
+                        NULL,
+                        this );
+
    // Remove our event handlers
    mIndicator->Disconnect( wxEVT_CREATE,
                            wxWindowCreateEventHandler( ToolManager::OnCreate ),
                            NULL,
                            this );
    mIndicator->Disconnect( wxEVT_PAINT,
-                           wxPaintEventHandler( ToolManager::OnPaint ),
+                           wxPaintEventHandler( ToolManager::OnIndicatorPaint 
),
                            NULL,
                            this );
 
@@ -183,11 +420,6 @@
    // Delete the indicator regions
    delete mLeft;
    delete mDown;
-
-   if( mDragWindow )
-   {
-      mDragWindow->Destroy();
-   }
 }
 
 //
@@ -199,8 +431,11 @@
    wxArrayInt unordered[ DockCount ];
    int order[ DockCount ][ ToolBarCount ];
    bool show[ ToolBarCount ];
+   int width[ ToolBarCount ];
+   int height[ ToolBarCount ];
    int x, y;
    int dock, ord, ndx;
+
 #if defined(__WXMAC__)
    // Disable window animation
    wxSystemOptions::SetOption( wxMAC_WINDOW_PLAIN_TRANSITION, 1 );
@@ -221,8 +456,10 @@
    // Load and apply settings for each bar
    for( ndx = 0; ndx < ToolBarCount; ndx++ )
    {
+      ToolBar *bar = mBars[ ndx ];
+
       // Change to the bar subkey
-      gPrefs->SetPath( mBars[ ndx ]->GetLabel() );
+      gPrefs->SetPath( bar->GetLabel() );
 
       // Read in all the settings
       gPrefs->Read( wxT("Dock"), &dock, ndx == SelectionBarID ? BotDockID : 
TopDockID );
@@ -230,6 +467,8 @@
       gPrefs->Read( wxT("Show"), &show[ ndx ], ndx == DeviceBarID ? false : 
true );
       gPrefs->Read( wxT("X"), &x, -1 );
       gPrefs->Read( wxT("Y"), &y, -1 );
+      gPrefs->Read( wxT("W"), &width[ ndx ], -1 );
+      gPrefs->Read( wxT("H"), &height[ ndx ], -1 );
 
       // Docked or floating?
       if( dock )
@@ -242,11 +481,19 @@
          // Create the bar with the correct parent
          if( dock == TopDockID )
          {
-            mBars[ ndx ]->Create( mTopDock );
+            bar->Create( mTopDock );
          }
          else
          {
-            mBars[ ndx ]->Create( mBotDock );
+            bar->Create( mBotDock );
+         }
+
+         // Set the width
+         if( width[ ndx ] )
+         {
+            wxSize sz( width[ ndx ], bar->GetSize().y );
+            bar->SetSize( sz );
+            bar->Layout();
          }
 
          // Is order within range and unoccupied?
@@ -266,13 +513,25 @@
       else
       {
          // Create the bar (with the top dock being temporary parent)
-         mBars[ ndx ]->Create( mTopDock );
+         bar->Create( mTopDock );
 
-         // Set window position (validate these somehow????)
-         wxPoint pos( x, y );
+         // Construct a new floater
+         ToolFrame *f = new ToolFrame( mParent, this, bar, wxPoint( x, y ) );
 
-         // Set the bar afloat and show/hide it
-         Float( mBars[ ndx ], pos )->Show( show[ ndx ] );
+         // Set the width and height
+         if( width[ ndx ] != -1 && height[ ndx ] != -1 )
+         {
+            wxSize sz( width[ ndx ], height[ ndx ] );
+            f->SetMinSize( sz );
+            f->SetSize( sz );
+            f->Layout();
+         }
+
+         // Show or hide it
+         bar->Expose( show[ ndx ] );
+
+         // Inform toolbar of change
+         bar->SetDocked( false, false );
       }
 
       // Change back to the bar root
@@ -323,6 +582,11 @@
 
    // Restore original config path
    gPrefs->SetPath( oldpath );
+
+#if defined(__WXMAC__)
+   // Reinstate original transition
+   wxSystemOptions::SetOption( wxMAC_WINDOW_PLAIN_TRANSITION, mTransition );
+#endif
 }
 
 //
@@ -357,29 +621,21 @@
       gPrefs->Write( wxT("Dock"), to ? TopDockID : bo ? BotDockID : NoDockID );
       gPrefs->Write( wxT("Order"), to + bo );
       gPrefs->Write( wxT("Show"), IsVisible( ndx ) );
-      if( bar->IsDocked() )
-      {
-         gPrefs->Write( wxT("X"), -1 );
-         gPrefs->Write( wxT("Y"), -1 );
 
-         // Kill the bar
-         bar->Destroy();
-      }
-      else
+      wxPoint pos( -1, -1 );
+      wxSize sz = bar->GetSize();
+      if( !bar->IsDocked() )
       {
-         wxPoint p = bar->GetParent()->GetPosition();
-         gPrefs->Write( wxT("X"), p.x );
-         gPrefs->Write( wxT("Y"), p.y );
-
-         // Disconnect the event handler
-         bar->GetParent()->Disconnect( EVT_GRABBER_CLICKED,
-                                       GrabberEventHandler( 
ToolManager::OnGrabber ),
-                                       NULL,
-                                       this );
-
-         // Kill the bar
-         bar->Destroy();
+         pos = bar->GetParent()->GetPosition();
+         sz = bar->GetParent()->GetSize();
       }
+      gPrefs->Write( wxT("X"), pos.x );
+      gPrefs->Write( wxT("Y"), pos.y );
+      gPrefs->Write( wxT("W"), sz.x );
+      gPrefs->Write( wxT("H"), sz.y );
+
+      // Kill the bar
+      bar->Destroy();
 
       // Change back to the bar root
       gPrefs->SetPath( wxT("..") );
@@ -414,78 +670,6 @@
 }
 
 //
-// Toggle the docked/floating state of the specified toolbar
-//
-wxWindow *ToolManager::Float( ToolBar *t, wxPoint & pos )
-{
-   wxWindow *parent;
-
-#if defined(__WXMAC__)
-   // Disable window animation
-   wxSystemOptions::SetOption( wxMAC_WINDOW_PLAIN_TRANSITION, 1 );
-#endif
-
-   // Create the floater window
-   int flags = wxCAPTION | wxFRAME_TOOL_WINDOW | wxFRAME_FLOAT_ON_PARENT;
-   if( t->IsResizeable() )
-   {
-      parent = new wxFrame( mParent,
-                            wxID_ANY,
-                            t->GetTitle(),
-                            pos,
-                            wxDefaultSize,
-                            flags | wxRESIZE_BORDER,
-                            t->GetLabel() );
-   }
-   else
-   {
-      parent = new wxMiniFrame( mParent,
-                                wxID_ANY,
-                                t->GetTitle(),
-                                pos,
-                                wxDefaultSize,
-                                flags,
-                                t->GetLabel() );
-   }
-
-   // Intercept the grabber events
-   parent->Connect( EVT_GRABBER_CLICKED,
-                    GrabberEventHandler( ToolManager::OnGrabber ),
-                    NULL,
-                    this );
-
-   // Move the toolbar from the toolbar dock to the floater window
-   t->Reparent( parent );
-
-   // Tell the toolbar about the change
-   t->SetDocked( false );
-
-   // Resize the floater client size to the toolbars minimum size
-   wxSize sz = t->GetSize();
-   parent->SetClientSize( sz.x + 1, sz.y + 1 );
-
-   // Make sure resizable floaters don't get any smaller than initial size
-   if( t->IsResizeable() )
-   {
-      // Adjust bar minimum size to account for frame decorations
-      wxSize msz = t->GetMinSize();
-      wxSize psz = parent->GetSize();
-      msz.x += ( psz.x - sz.x );
-      msz.y += ( psz.y - sz.y );
-
-      // Set the minimum size
-      parent->SetSizeHints( msz );
-   }
-
-#if defined(__WXMAC__)
-   // Reinstate original transition
-   wxSystemOptions::SetOption( wxMAC_WINDOW_PLAIN_TRANSITION, mTransition );
-#endif
-
-   return parent;
-}
-
-//
 // Queues an EVT_TOOLBAR_UPDATED command event to notify any
 // interest parties of an updated toolbar or dock layout
 //
@@ -511,6 +695,8 @@
 {
    ToolBar *t = mBars[ type ];
 
+   return t->IsVisible();
+
    // If toolbar is floating
    if( !t->IsDocked() )
    {
@@ -536,118 +722,11 @@
    }
    else
    {
-      t->GetParent()->Show( !t->GetParent()->IsShown() );
+      t->Expose( !t->IsVisible() );
    }
 }
 
 //
-// Transition a toolbar from docked to dragging
-//
-void ToolManager::UnDock( ToolBar *bar )
-{
-#if defined(__WXMAC__)
-   // Disable window animation
-   wxSystemOptions::SetOption( wxMAC_WINDOW_PLAIN_TRANSITION, 1 );
-#endif
-
-   // Remember which bar we're dragging
-   mDragBar = bar;
-
-   // Inform toolbar of change
-   mDragBar->SetDocked( false );
-
-   // Continue the drag 
-   StartDrag( wxGetMousePosition() );
-}
-
-//
-// Common handler for transitioning a bar to dragging
-//
-void ToolManager::StartDrag( const wxPoint & pos )
-{
-   wxSize sz;
-
-   // Get the current size and force the height to the minimum
-   sz = mDragBar->GetSize();
-   sz.y = mDragBar->GetMinSize().y;
-
-   // Sink the previous ferry
-   if( mDragWindow )
-   {
-      mDragWindow->Destroy();
-      mDragWindow = NULL;
-   }
-
-   // Construct a new ferry
-   //
-   // For GTK, we use a popup window since dragging a frame causes mouse 
capture
-   // problems and a wxWindow will not work as its position is restricted to 
the
-   // interior of the current project frame.  (We want to be able to drag 
toolbars
-   // outside the frame.)  The popup window (frame actually) doesn't have this
-   // constraint or capture problems.
-   //
-   // But, a standard frame should be used for Windows and OSX since a popup 
doesn't
-   // work quite right under Windows (for this purpose) and the latter doesn't 
yet
-   // support the wxPopupWindow class.
-#if defined(__WXGTK__)
-   mDragWindow = new wxPopupWindow( mParent,
-                                    wxNO_BORDER |
-                                    wxFRAME_NO_TASKBAR |
-                                    wxFRAME_FLOAT_ON_PARENT );
-   mDragWindow->SetSize( pos.x, pos.y, sz.GetWidth() + 2, sz.GetHeight() + 2 );
-#else
-   mDragWindow = new wxFrame( mParent,
-                              wxID_ANY,
-                              wxEmptyString,
-                              pos,
-                              wxSize( sz.GetWidth() + 2, sz.GetHeight() + 2 ),
-                              wxNO_BORDER |
-                              wxFRAME_NO_TASKBAR |
-                              wxFRAME_FLOAT_ON_PARENT );
-#endif
-
-   // Transfer the bar to the ferry
-   mDragBar->Reparent( mDragWindow );
-
-   // GTK needs a yield before we can reposition the bar within the ferry
-   wxYieldIfNeeded();
-
-   // Anchor it down
-   mDragBar->SetSize( 1,
-                      1,
-                      sz.GetWidth(),
-                      sz.GetHeight() );
-
-   // Intercept the mouse events
-   mDragWindow->Connect( wxEVT_MOTION,
-                         wxMouseEventHandler( ToolManager::OnMouse ),
-                         NULL,
-                         this );
-   mDragWindow->Connect( wxEVT_LEFT_UP,
-                         wxMouseEventHandler( ToolManager::OnMouse ),
-                         NULL,
-                         this );
-
-   // Draw a border
-#if defined(__WXGTK__)
-   mDragWindow->SetBackgroundColour( *wxBLACK );
-   mDragWindow->ClearBackground();
-#endif
-
-   // Make sure the ferry is visible
-   mDragWindow->Show();
-
-   // Notify parent of change
-   Updated();
-
-   // We want all mouse events from this point on
-   mDragWindow->CaptureMouse();
-
-   // Setup a watchdog in case we lose the capture
-//   mWatchdog.Start( 50, wxTIMER_CONTINUOUS );
-}
-
-//
 // Ask both docks to (re)layout their bars
 //
 void ToolManager::LayoutToolBars()
@@ -665,60 +744,62 @@
    // Go ahead and set the event to propagate
    event.Skip();
 
-   // Can't do anything if we're not dragging
-   if( !mDragBar )
+   // Can't do anything if we're not dragging.  This also prevents
+   // us from intercepting events that don't belong to us from the
+   // parent since we're Connect()ed to a couple.
+   if( !mDragWindow )
    {
       return;
    }
 
-   // Retrieve the mouse position
-   wxPoint pos = wxGetMousePosition();
+#if defined(__WXMAC__)
+   // Disable window animation
+   wxSystemOptions::SetOption( wxMAC_WINDOW_PLAIN_TRANSITION, 1 );
+#endif
+
+   // Retrieve the event position
+   wxPoint pos =
+      ( (wxWindow *)event.GetEventObject() )->ClientToScreen( 
event.GetPosition() );
 
    // Button was released...finish the drag
-   if( !event.LeftIsDown())
+   if( !event.LeftIsDown() )
    {
-      // Stop the watchdog
-//      mWatchdog.Stop();
-
-      // Release the mouse if we have it (we should, but sometimes...)
-      if( mDragWindow->HasCapture() )
+      // Release capture
+      if( mParent->HasCapture() )
       {
-         mDragWindow->ReleaseMouse();
+         mParent->ReleaseMouse();
       }
 
       // Hide the indicator
       mIndicator->Hide();
 
-      // Transition the bar to a dock or a floater
-      if( mDragDock )
+      // Transition the bar to a dock
+      if( mDragDock && !event.ShiftDown() )
       {
          // Trip over...everyone ashore that's going ashore...
          mDragDock->Dock( mDragBar, mDragBefore );
+
+         // Done with the floater
+         mDragWindow->Destroy();
+         mDragBar->Refresh(false);
       }
       else
       {
-         // Set the bar afloat
-         Float( mDragBar, pos )->Show();
+         // Calling SetDocked() to force the grabber button to popup
+         mDragBar->SetDocked( false, false );
       }
 
-      // Hide the ferry (gets deleted above)
-      mDragWindow->Hide();
-
       // Done dragging
+      mDragWindow = NULL;
       mDragDock = NULL;
       mDragBar = NULL;
       mLastPos.x = mBarPos.x = -1;
       mLastPos.y = mBarPos.y = -1;
-
-#if defined(__WXMAC__)
-      // Reinstate original transition
-      wxSystemOptions::SetOption( wxMAC_WINDOW_PLAIN_TRANSITION, mTransition );
-#endif
    }
    else if( event.Dragging() && pos != mLastPos )
    {
       // Make toolbar follow the mouse
-      mDragWindow->Move( pos );
+      mDragWindow->Move( pos - mDragOffset );
 
       // Remember to prevent excessive movement
       mLastPos = pos;
@@ -781,6 +862,7 @@
             mIndicator->SetShape( *mCurrent );
             mIndicator->Move( dock->GetParent()->ClientToScreen( p ) );
             mIndicator->Show();
+            mIndicator->Update();
 
             // Remember for next go round
             mBarPos = r;
@@ -801,25 +883,10 @@
       // Remember to which dock the drag bar belongs.
       mDragDock = dock;
    }
-}
 
-//
-// Protect against losing mouse capture
-//
-void ToolManager::OnTimer( wxTimerEvent & event )
-{
-#if 0
-   // If we've lost capture, simulate a button up event
-   if( !mDragWindow->HasCapture() )
-   {
-      wxMouseEvent e;
-      wxPoint p( ScreenToClient( wxGetMousePosition() ) );
-      e.m_x = p.x;
-      e.m_y = p.y;
-      e.SetEventType( wxEVT_LEFT_UP );
-      e.m_leftDown = false;
-      OnMouse( e );
-   }
+#if defined(__WXMAC__)
+   // Reinstate original transition
+   wxSystemOptions::SetOption( wxMAC_WINDOW_PLAIN_TRANSITION, mTransition );
 #endif
 }
 
@@ -829,10 +896,10 @@
 // Really only needed for the Mac since SetBackgroundColour()
 // doesn't seem to work with shaped frames.
 //
-void ToolManager::OnPaint( wxPaintEvent & event )
+void ToolManager::OnIndicatorPaint( wxPaintEvent & event )
 {
-   wxPaintDC dc( mIndicator );
-
+   wxWindow *w = (wxWindow *)event.GetEventObject();
+   wxPaintDC dc( w );
    dc.BeginDrawing();
    dc.SetBackground( *wxBLUE_BRUSH );
    dc.Clear();
@@ -858,30 +925,53 @@
 //
 void ToolManager::OnGrabber( GrabberEvent & event )
 {
-   wxWindow *parent;
+   // No need to propagate any further
+   event.Skip( false );
+
+   // Remember which bar we're dragging
+   mDragBar = mBars[ event.GetId() ];
 
+   // Calculate the drag offset
+   wxPoint mp = event.GetPosition();
+   mDragOffset = mp - 
+                 mDragBar->GetParent()->ClientToScreen( 
mDragBar->GetPosition() ) +
+                 wxPoint( 1, 1 );
+
+   // Must set the bar afloat if it's currently docked
+   if( mDragBar->IsDocked() )
+   {
 #if defined(__WXMAC__)
-   // Disable window animation
-   wxSystemOptions::SetOption( wxMAC_WINDOW_PLAIN_TRANSITION, 1 );
+      // Disable window animation
+      wxSystemOptions::SetOption( wxMAC_WINDOW_PLAIN_TRANSITION, 1 );
 #endif
 
-   // No need to propagate any further
-   event.Skip( true );
+      // Adjust the starting position
+      mp -= mDragOffset;
 
-   // Remember which bar we're dragging
-   mDragBar = mBars[ event.GetId() ];
+      // Inform toolbar of change
+      mDragBar->SetDocked( false, true );
 
-   // Get the parent
-   parent = mDragBar->GetParent();
+      // Construct a new floater
+      mDragWindow = new ToolFrame( mParent, this, mDragBar, mp );
 
-   // And make it disappear
-   parent->Hide();
+      // Make sure the ferry is visible
+      mDragWindow->Show();
+   
+      // Notify parent of change
+      Updated();
 
-   // Start the dragging
-   StartDrag( wxGetMousePosition() );
+#if defined(__WXMAC__)
+      // Reinstate original transition
+      wxSystemOptions::SetOption( wxMAC_WINDOW_PLAIN_TRANSITION, mTransition );
+#endif
+   }
+   else
+   {
+      mDragWindow = (ToolFrame *) mDragBar->GetParent();
+   }
 
-   // Kill the parent
-   parent->Destroy();
+   // We want all mouse events from this point on
+   mParent->CaptureMouse();
 }
 
 // Indentation settings for Vim and Emacs and unique identifier for Arch, a
@@ -893,5 +983,4 @@
 // End:
 //
 // vim: et sts=3 sw=3
-// arch-tag: 2f4ec75c-bdb7-4889-96d1-5d00abc41027
-
+// arch-tag: 2f4ec75c-bdb7-4889-96d-5d00abc41027

Index: ToolBar.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/toolbars/ToolBar.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- ToolBar.cpp 17 Oct 2006 12:36:29 -0000      1.4
+++ ToolBar.cpp 22 Oct 2006 09:54:26 -0000      1.5
@@ -73,7 +73,6 @@
 //
 BEGIN_EVENT_TABLE( ToolBar, wxPanel )
    EVT_PAINT( ToolBar::OnPaint )
-   EVT_SIZE( ToolBar::OnSize )
    EVT_ERASE_BACKGROUND( ToolBar::OnErase )
    EVT_LEFT_DOWN( ToolBar::OnLeftDown )
    EVT_LEFT_UP( ToolBar::OnLeftUp )
@@ -85,19 +84,21 @@
 //
 ToolBar::ToolBar( int type,
                   const wxString &label,
-                  bool resizeable )
+                  bool resizable )
 : wxPanel()
 {
    // Save parameters
    mType = type;
    mLabel = label;
    mTitle.Printf( _("Audacity %s ToolBar"), mLabel.c_str() );
-   mResizeable = resizeable;
+   mResizable = resizable;
 
    // Initialize everything
    mParent = NULL;
-   mDocked = true;
    mHSizer = NULL;
+   mSpacer = NULL;
+   mDocked = true;
+   mVisible = false;
 }
 
 //
@@ -132,11 +133,11 @@
 }
 
 //
-// Returns whether the toolbar is resizeable or not
+// Returns whether the toolbar is resizable or not
 //
-bool ToolBar::IsResizeable()
+bool ToolBar::IsResizable()
 {
-   return mResizeable;
+   return mResizable;
 }
 
 //
@@ -148,6 +149,35 @@
 }
 
 //
+// Returns the visibility of the toolbar
+//
+bool ToolBar::IsVisible()
+{
+   return mVisible;
+}
+
+//
+// Show or hide the toolbar
+//
+bool ToolBar::Expose( bool show )
+{
+   bool was = mVisible;
+
+   mVisible = show;
+
+   if( IsDocked() )
+   {
+      Show( show );
+   }
+   else
+   {
+      GetParent()->Show( show );
+   }
+
+   return was;
+}
+
+//
 // Initialize the toolbar
 //
 void ToolBar::Create( wxWindow *parent )
@@ -169,6 +199,7 @@
 
    // Let the user see it in all its glory
    Show();
+   mVisible = true;
 }
 
 void ToolBar::ReCreateButtons()
@@ -180,21 +211,31 @@
    // Get rid of any children we may have
    DestroyChildren();
 
-   // Use a box sizer for laying out controls
-   mHSizer = new wxBoxSizer( wxHORIZONTAL );
+   // Create the main sizer
+   wxBoxSizer *ms = new wxBoxSizer( wxHORIZONTAL );
 
-   // Create the grabber and add it to the sizer
+   // Create the grabber and add it to the main sizer
    mGrabber = new Grabber( this, mType );
-   Add( mGrabber, 0, wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP | wxRIGHT, 1 );
+   ms->Add( mGrabber, 0, wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP | wxRIGHT, 1 );
+
+   // Use a box sizer for laying out controls
+   mHSizer = new wxBoxSizer( wxHORIZONTAL );
+   ms->Add( mHSizer, 1, wxEXPAND );
 
    // (Re)Establish dock state
-   SetDocked( IsDocked() );
+   SetDocked( IsDocked(), false );
 
    // Go add all the rest of the gadgets
    Populate();
 
+   // Add some space for the resize border
+   if( IsResizable() )
+   {
+      mSpacer = ms->Add( RWIDTH, 1 );
+   }
+
    // Set the sizer and do initial layout
-   SetSizerAndFit( mHSizer );
+   SetSizerAndFit( ms );
    Layout();
 
    // Recalculate the height to be a multiple of toolbarSingle
@@ -216,29 +257,18 @@
 //
 // Toggle the docked/floating state
 //
-void ToolBar::SetDocked( bool dock )
+void ToolBar::SetDocked( bool dock, bool pushed )
 {
    // Remember it
    mDocked = dock;
 
    // Change the tooltip of the grabber
-   if( dock )
-   {
-      mGrabber->SetLabel( _("Float") );
 #if wxUSE_TOOLTIPS
-      mGrabber->SetToolTip( _("Float Toolbar") );
-#endif
-   }
-   else
-   {
-      mGrabber->SetLabel( _("Dock") );
-#if wxUSE_TOOLTIPS
-      mGrabber->SetToolTip( _("Dock Toolbar") );
+   mGrabber->SetToolTip( GetTitle() );
 #endif
-   }
 
-   // Raise the grabber button as it should be pushed
-   mGrabber->PushButton( false );
+   // Set the grabber button state
+   mGrabber->PushButton( pushed );
 }
 
 //
@@ -439,14 +469,6 @@
 }
 
 //
-// Handle sizing
-//
-void ToolBar::OnSize( wxSizeEvent & event )
-{
-   Refresh( false );
-}
-
-//
 // Handle background erasure
 //
 void ToolBar::OnErase( wxEraseEvent & event )
@@ -472,7 +494,7 @@
    // Go repaint the rest
    Repaint( &dc );
 
-   if( mResizeable && IsDocked() )
+   if( IsResizable() && IsDocked() )
    {
       wxSize sz = GetSize();
 
@@ -497,7 +519,7 @@
    }
 
    // Can we be resized?
-   if( IsResizeable() )
+   if( IsResizable() )
    {
       wxPoint pos = event.GetPosition();
       wxRect rect = GetRect();
@@ -521,10 +543,14 @@
 
 void ToolBar::OnLeftUp( wxMouseEvent & event )
 {
+   // Go ahead and set the event to propagate
+   event.Skip();
+
    if( HasCapture() )
    {
       ReleaseMouse();
    }
+
    SetCursor( wxCURSOR_ARROW );
 }
 
@@ -544,7 +570,7 @@
 
    if( !HasCapture() )
    {
-      if( IsResizeable() )
+      if( IsResizable() )
       {
          wxPoint pos = event.GetPosition();
          wxRect rect = GetRect();
@@ -599,7 +625,7 @@
       // Resize the bar
       SetSize( r.GetSize() );
 
-      // Tell everyone we'd changed sizes
+      // Tell everyone we've changed sizes
       Updated();
 
       // Refresh our world

Index: ToolBar.h
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/toolbars/ToolBar.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- ToolBar.h   24 Sep 2006 18:11:11 -0000      1.2
+++ ToolBar.h   22 Oct 2006 09:54:26 -0000      1.3
@@ -82,14 +82,16 @@
    virtual void EnableDisableButtons() = 0;
    virtual void ReCreateButtons();
 
-   void SetDocked(bool dock);
+   void SetDocked(bool dock, bool pushed);
 
    int GetType();
    wxString GetTitle();
    wxString GetLabel();
    ToolDock *GetDock();
 
-   bool IsResizeable();
+   bool Expose( bool show = true );
+
+   bool IsResizable();
    bool IsVisible();
    bool IsDocked();
 
@@ -144,17 +146,12 @@
    virtual void Populate() = 0;
    virtual void Repaint(wxDC *dc) = 0;
 
-   void OnSize(wxSizeEvent & event);
    void OnErase(wxEraseEvent & event);
    void OnPaint(wxPaintEvent & event);
    void OnLeftDown(wxMouseEvent & event);
    void OnLeftUp(wxMouseEvent & event);
    void OnMotion(wxMouseEvent & event);
 
-   bool mDocked;
-   bool mVisible;
-   bool mResizeable;
-
  private:
 
    void Init(wxWindow *parent, int type, const wxString & title, const 
wxString & label);
@@ -163,6 +160,7 @@
    
    Grabber *mGrabber;
    wxBoxSizer *mHSizer;
+   wxSizerItem *mSpacer;
 
    wxPoint mResizeStart;
 
@@ -170,6 +168,10 @@
    wxString mLabel;
    int mType;
 
+   bool mVisible;
+   bool mDocked;
+   bool mResizable;
+
  public:
 
    DECLARE_CLASS(ToolBar);

Index: ToolDock.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/toolbars/ToolDock.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ToolDock.cpp        15 Oct 2006 03:47:23 -0000      1.3
+++ ToolDock.cpp        22 Oct 2006 09:54:26 -0000      1.4
@@ -112,6 +112,9 @@
    bar->Reparent( this );
    mBars[ bar->GetId() ] = bar;
 
+   // Reset height
+   bar->SetSize( bar->GetSize().x, bar->GetMinSize().y );
+
    // Park the new bar in the correct berth
    if( before >= 0 && before < (int)mDockedBars.GetCount() )
    {
@@ -123,7 +126,7 @@
    }
 
    // Inform toolbar of change
-   bar->SetDocked( true );
+   bar->SetDocked( true, false );
 
    // Rearrange our world
    LayoutToolBars();
@@ -305,7 +308,7 @@
 
             // Get bar rect and make gap part of it
             r.SetPosition( b->GetParent()->ClientToScreen( b->GetPosition() ) 
);
-            r.SetSize( b->IsResizeable() ? b->GetSize() : b->GetSize() );
+            r.SetSize( b->IsResizable() ? b->GetSize() : b->GetSize() );
             r.width += toolbarGap;
             r.height += toolbarGap;
 
@@ -401,7 +404,7 @@
    ToolBar *t = mBars[ type ];
 
    // Maintain the docked array
-   if( t->IsShown() )
+   if( t->IsVisible() )
    {
       mDockedBars.Remove( t );
    }
@@ -411,7 +414,7 @@
    }
 
    // Make it (dis)appear
-   t->Show( !t->IsShown() );
+   t->Expose( !t->IsVisible() );
 
    // Update the layout
    LayoutToolBars();
@@ -435,16 +438,12 @@
 void ToolDock::OnGrabber( GrabberEvent & event )
 {
    ToolBar *t = mBars[ event.GetId() ];
-   wxSize sz = t->GetSize();
 
-   // Send "request" to start a drag operation
-   mManager->UnDock( t );
+   // Pass it on to the manager since it isn't in the handling hierarchy
+   mManager->ProcessEvent( event );
 
    // We no longer have control
    mDockedBars.Remove( t );
-
-   // No need to propagate any further
-   event.Skip( true );
 }
 
 // 
@@ -476,7 +475,7 @@
 }
 
 //
-// Handle sizing
+// Prevent flicker
 //
 void ToolDock::OnErase( wxEraseEvent & event )
 {

Index: ToolManager.h
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/toolbars/ToolManager.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- ToolManager.h       17 Oct 2006 12:36:29 -0000      1.4
+++ ToolManager.h       22 Oct 2006 09:54:26 -0000      1.5
@@ -23,6 +23,7 @@
 class wxArrayPtrVoid;
 class wxBitmap;
 class wxCommandEvent;
+class wxFrame;
 class wxMouseEvent;
 class wxPaintEvent;
 class wxPoint;
@@ -33,6 +34,9 @@
 class wxTimerEvent;
 class wxWindow;
 
+class AudacityProject;
+class ToolFrame;
+
 ////////////////////////////////////////////////////////////
 /// class ToolManager
 ////////////////////////////////////////////////////////////
@@ -42,7 +46,7 @@
 
  public:
 
-   ToolManager( wxWindow *parent );
+   ToolManager( AudacityProject *parent );
    ~ToolManager();
 
    void LayoutToolBars();
@@ -58,38 +62,36 @@
    ToolDock *GetTopDock();
    ToolDock *GetBotDock();
 
-   void UnDock( ToolBar *bar );
-
  private:
 
-   wxWindow *Float( ToolBar *t, wxPoint & pos );
+   ToolBar *Float( ToolBar *t, wxPoint & pos );
 
-   void OnTimer( wxTimerEvent & event );
    void OnMouse( wxMouseEvent & event );
    void OnGrabber( GrabberEvent & event );
-   void OnPaint( wxPaintEvent & event );
    void OnCreate( wxWindowCreateEvent & event );
-  
+
+   void OnIndicatorPaint( wxPaintEvent & event );
+
    void ReadConfig();
    void WriteConfig();
-   void StartDrag( const wxPoint & pos );
    void Updated();
 
-   wxWindow *mParent;
+   AudacityProject *mParent;
 
+   ToolFrame *mDragWindow;
    ToolDock *mDragDock;
    ToolBar *mDragBar;
+   wxPoint mDragOffset;
    int mDragBefore;
 
    wxPoint mLastPos;
    wxRect mBarPos;
+
    wxFrame *mIndicator;
    wxRegion *mLeft;
    wxRegion *mDown;
    wxRegion *mCurrent;
 
-   wxTimer mWatchdog;
-
 #if defined(__WXMAC__)
    bool mTransition;
 #endif
@@ -100,11 +102,10 @@
 
    ToolBar *mBars[ ToolBarCount ];
 
-   wxWindow *mDragWindow;
-
  public:
 
    DECLARE_CLASS( ToolManager );
+   DECLARE_EVENT_TABLE();
 };
 
 #endif

Index: MeterToolBar.cpp
===================================================================
RCS file: /cvsroot/audacity/audacity-src/src/toolbars/MeterToolBar.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- MeterToolBar.cpp    16 Sep 2006 05:54:36 -0000      1.1
+++ MeterToolBar.cpp    22 Oct 2006 09:54:26 -0000      1.2
@@ -105,9 +105,14 @@
       return;
    }
 
+   // Update the layout
+   Layout();
+
    // Get the usable area
-   GetClientSize( &width, &height );
-   width -= mSizer->GetPosition().x + 4;
+//   GetClientSize( &width, &height );
+//   width -= mSizer->GetPosition().x;
+   wxSize sz = GetSizer()->GetSize();
+   width = sz.x; height = sz.y;
 
    // Default location for record meter
    wxGBPosition pos( 0, 1 );
@@ -118,16 +123,16 @@
       if( height > 120 )
       {
          // Stacked
-         mPlayMeter->SetMinSize( wxSize( width - 2, ( height / 2 ) - 1 ) );
-         mRecordMeter->SetMinSize( wxSize( width - 2, ( height / 2 ) - 1 ) );
+         mPlayMeter->SetMinSize( wxSize( width, ( height / 2 ) ) );
+         mRecordMeter->SetMinSize( wxSize( width, ( height / 2 ) ) );
          pos.SetCol( 0 );
          pos.SetRow( 1 );
       }
       else
       {
          // Side-by-side
-         mPlayMeter->SetMinSize( wxSize( ( width / 2 ) - 3, height ) );
-         mRecordMeter->SetMinSize( wxSize( ( width / 2 ) - 6, height ) );
+         mPlayMeter->SetMinSize( wxSize( ( width / 2 ), height ) );
+         mRecordMeter->SetMinSize( wxSize( ( width / 2 ), height ) );
       }
 
       mPlayMeter->SetStyle(Meter::HorizontalStereo);
@@ -136,8 +141,8 @@
    else
    {
       // Two vertical, side-by-side
-      mPlayMeter->SetMinSize( wxSize( ( width / 2 ) - 2, height ) );
-      mRecordMeter->SetMinSize( wxSize( ( width / 2 ) - 2, height ) );
+      mPlayMeter->SetMinSize( wxSize( ( width / 2 ), height ) );
+      mRecordMeter->SetMinSize( wxSize( ( width / 2 ), height ) );
       mPlayMeter->SetStyle(Meter::VerticalStereo);
       mRecordMeter->SetStyle(Meter::VerticalStereo);
    }


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Audacity-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/audacity-cvs

Reply via email to