/////////////////////////////////////////////////////////////////////////////
-// Name: No names yet.
-// Purpose: Contrib. demo
+// Name: toolwnd.h
+// Purpose: wxToolWindow, cbMiniButton, cbCloseBox, cbCollapseBox,
+// cbDockBox, cbFloatedBarWindow class declarations.
// Author: Aleksandras Gluchovas
// Modified by:
// Created: 06/09/98
// RCS-ID: $Id$
// Copyright: (c) Aleksandras Gluchovas
-// Licence: wxWindows license
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __TOOLWND_G__
WX_DEFINE_ARRAY( cbMinitButtonPtrT, cbMiniButtonArrayT );
+/*
+A tool window is a special kind of frame that paints its own title, and
+can be used to implement small floating windows.
+*/
+
class wxToolWindow : public wxFrame
{
- DECLARE_DYNAMIC_CLASS( wxToolWindow )
+ DECLARE_DYNAMIC_CLASS( wxToolWindow )
-public: /** protected really, accessed only by serializers **/
+public: /** protected really, accessed only by serializers **/
- cbMiniButtonArrayT mButtons;
- wxWindow* mpClientWnd;
+ cbMiniButtonArrayT mButtons;
+ wxWindow* mpClientWnd;
- wxFont mTitleFont;
+ wxFont mTitleFont;
- int mTitleHeight;
- int mClntHorizGap;
- int mClntVertGap;
- int mWndVertGap;
- int mWndHorizGap;
- int mButtonGap;
- int mInTitleMargin;
- int mHintBorder;
+ int mTitleHeight;
+ int mClntHorizGap;
+ int mClntVertGap;
+ int mWndVertGap;
+ int mWndHorizGap;
+ int mButtonGap;
+ int mInTitleMargin;
+ int mHintBorder;
- bool mResizeStarted;
- bool mRealTimeUpdatesOn;
+ bool mResizeStarted;
+ bool mRealTimeUpdatesOn;
- int mMTolerance;
+ int mMTolerance;
- int mCursorType;
- bool mMouseCaptured;
+ int mCursorType;
+ bool mMouseCaptured;
- // drag&drop state variables
+ // drag&drop state variables
- wxPoint mDragOrigin;
- wxRect mInitialRect;
- wxRect mPrevHintRect;
- wxScreenDC* mpScrDc;
+ wxPoint mDragOrigin;
+ wxRect mInitialRect;
+ wxRect mPrevHintRect;
+ wxScreenDC* mpScrDc;
protected:
- void GetScrWindowRect( wxRect& r );
- void GetScrMousePos ( wxMouseEvent& event, wxPoint& pos );
- void SetHintCursor ( int type );
+ // Maps client coordinates to screen coordinates.
+ void GetScrWindowRect( wxRect& r );
+
+ // Gets the mouse position in screen coordinates.
+ void GetScrMousePos ( wxMouseEvent& event, wxPoint& pos );
+
+ // Sets the hint cursor.
+ void SetHintCursor ( int type );
- void CalcResizedRect( wxRect& rect, wxPoint& delta, const wxSize& minDim );
- void AdjustRectPos( const wxRect& original, const wxSize& newDim, wxRect& newRect );
- wxSize GetMinimalWndDim();
+ // Calculate resized rectangle.
+ void CalcResizedRect( wxRect& rect, wxPoint& delta, const wxSize& minDim );
- void DrawHintRect( const wxRect& r );
+ // Helper function.
+ void AdjustRectPos( const wxRect& original, const wxSize& newDim, wxRect& newRect );
- int HitTestWindow( wxMouseEvent& event );
+ // Helper function.
+ wxSize GetMinimalWndDim();
- void LayoutMiniButtons();
+ // Draws the hint rectangle.
+ void DrawHintRect( const wxRect& r );
+
+ // Tests if the mouse position is in this window.
+ int HitTestWindow( wxMouseEvent& event );
+
+ // Lays out the buttons.
+ void LayoutMiniButtons();
public:
-
- wxToolWindow();
- ~wxToolWindow();
- void SetClient( wxWindow* pWnd );
- wxWindow* GetClient();
+ // Default constructor.
+ wxToolWindow();
+
+ // Destructor.
+ ~wxToolWindow();
+
+ // Sets the client for this tool window.
+ void SetClient( wxWindow* pWnd );
+
+ // Returns the client window.
+ wxWindow* GetClient();
+
+ // Sets the title font.
+ void SetTitleFont( wxFont& font );
+
+ // Adds a button. Buttons are added in right-to-left order.
+ void AddMiniButton( cbMiniButton* pBtn );
+
+ // Responds to a paint event.
+ void OnPaint( wxPaintEvent& event );
+
+ // Responds to a mouse move event.
+ void OnMotion( wxMouseEvent& event );
- void SetTitleFont( wxFont& font );
+ // Responds to a mouse left down event.
+ void OnLeftDown( wxMouseEvent& event );
- // buttons are added in right-to-left order
- void AddMiniButton( cbMiniButton* pBtn );
+ // Responds to a mouse left up event.
+ void OnLeftUp( wxMouseEvent& event );
- void OnPaint( wxPaintEvent& event );
+ // Responds to a size event.
+ void OnSize( wxSizeEvent& event );
- void OnMotion( wxMouseEvent& event );
- void OnLeftDown( wxMouseEvent& event );
- void OnLeftUp( wxMouseEvent& event );
- void OnSize( wxSizeEvent& event );
+ // Responds to an erase background event.
+ void OnEraseBackground( wxEraseEvent& event );
- void OnEraseBackground( wxEraseEvent& event );
+ // Returns the preferred size for the window.
+ virtual wxSize GetPreferredSize( const wxSize& given );
- // overridables:
+ // Called when a mini button is clicked.
+ // By default, does nothing.
+ virtual void OnMiniButtonClicked( int btnIdx ) {}
- virtual wxSize GetPreferredSize( const wxSize& given );
- virtual void OnMiniButtonClicked( int btnIdx ) {}
- virtual bool HandleTitleClick( wxMouseEvent& event ) { return FALSE; }
+ // Handles clicking on the title. By default, does nothing.
+ virtual bool HandleTitleClick( wxMouseEvent& event ) { return FALSE; }
- DECLARE_EVENT_TABLE()
+ DECLARE_EVENT_TABLE()
};
// FIXME:: the code below should be moved to a separate file
#include "wx/fl/controlbar.h"
+/*
+cbMiniButton is the base class for a small button that can be placed in a wxToolWindow
+titlebar.
+*/
+
class cbMiniButton : public wxObject
{
public:
- wxPoint mPos;
- wxSize mDim;
- bool mVisible;
- bool mEnabled;
+ wxPoint mPos;
+ wxSize mDim;
+ bool mVisible;
+ bool mEnabled;
- wxFrameLayout* mpLayout;
- cbDockPane* mpPane;
- cbPluginBase* mpPlugin;
+ wxFrameLayout* mpLayout;
+ cbDockPane* mpPane;
+ cbPluginBase* mpPlugin;
- wxWindow* mpWnd;
+ wxWindow* mpWnd;
- bool mWasClicked;
- bool mDragStarted;
+ bool mWasClicked;
+ bool mDragStarted;
- bool mPressed;
+ bool mPressed;
public:
- cbMiniButton();
+ // Default constructor.
+ cbMiniButton();
+
+ // Set the position of the button.
+ void SetPos( const wxPoint& pos );
+
+ // Returns TRUE if the given position was over the button.
+ bool HitTest( const wxPoint& pos );
+
+ // Responds to a left down event.
+ void OnLeftDown( const wxPoint& pos );
+
+ // Responds to a left up event.
+ void OnLeftUp( const wxPoint& pos );
+
+ // Responds to a mouse move event.
+ void OnMotion( const wxPoint& pos );
- void SetPos( const wxPoint& pos );
- bool HitTest( const wxPoint& pos );
+ // Refreshes the button.
+ void Refresh();
- void OnLeftDown( const wxPoint& pos );
- void OnLeftUp( const wxPoint& pos );
- void OnMotion( const wxPoint& pos );
+ // Draws the button. Override this to implement
+ // the desired appearance.
+ virtual void Draw( wxDC& dc );
- void Refresh();
- virtual void Draw( wxDC& dc );
+ // Returns TRUE if the button was clicked.
+ bool WasClicked();
- bool WasClicked();
- void Reset();
+ // Reset the button.
+ void Reset();
- void Enable( bool enable ) { mEnabled = enable; }
+ // Enable or disable the button.
+ void Enable( bool enable ) { mEnabled = enable; }
- bool IsPressed() { return mPressed; }
+ // Returns TRUE if this button is pressed.
+ bool IsPressed() { return mPressed; }
};
-// classes specific to wxFrameLayout engine (FOR NOW in here...)
+/*
+cbCloseBox is a window close button, used in a wxToolWindow titlebar.
+*/
class cbCloseBox : public cbMiniButton
{
public:
- virtual void Draw( wxDC& dc );
+ // Draws the close button appearance.
+ virtual void Draw( wxDC& dc );
};
+/*
+cbCollapseBox is a window collapse button, used in a wxToolWindow titlebar.
+*/
+
class cbCollapseBox : public cbMiniButton
{
public:
- bool mIsAtLeft;
+ bool mIsAtLeft;
- virtual void Draw( wxDC& dc );
+ // Draws the collapse button appearance.
+ virtual void Draw( wxDC& dc );
};
+/*
+cbDockBox is a window dock button, used in a wxToolWindow titlebar.
+*/
+
class cbDockBox : public cbMiniButton
{
public:
- virtual void Draw( wxDC& dc );
+ // Draws the dock button appearance.
+ virtual void Draw( wxDC& dc );
};
+/*
+cbFloatedBarWindow is a kind of wxToolWindow,
+implementing floating toolbars.
+*/
+
class cbFloatedBarWindow : public wxToolWindow
{
- DECLARE_DYNAMIC_CLASS( cbFloatedBarWindow )
+ DECLARE_DYNAMIC_CLASS( cbFloatedBarWindow )
protected:
- cbBarInfo* mpBar;
- wxFrameLayout* mpLayout;
+ cbBarInfo* mpBar;
+ wxFrameLayout* mpLayout;
- friend class cbFloatedBarWindowSerializer;
+ friend class cbFloatedBarWindowSerializer;
public:
- cbFloatedBarWindow();
+ // Default constructor.
+ cbFloatedBarWindow();
+
+ // Sets the bar information for this window.
+ void SetBar( cbBarInfo* pBar );
+
+ // Sets the layout for this window.
+ void SetLayout( wxFrameLayout* pLayout );
- void SetBar( cbBarInfo* pBar );
- void SetLayout( wxFrameLayout* pLayout );
- cbBarInfo* GetBar();
+ // Returns the bar information for this window.
+ cbBarInfo* GetBar();
- // given coordinates are those of the bar itself
- // floated container window's position and size
- // are ajusted accordingly
+ // Position the floating window. The given coordinates
+ // are those of the bar itself; the floated container window's
+ // position and size are ajusted accordingly.
+ void PositionFloatedWnd( int scrX, int scrY,
+ int width, int height );
- void PositionFloatedWnd( int scrX, int scrY,
- int width, int height );
+ // Overridden function returning the preferred size.
+ virtual wxSize GetPreferredSize( const wxSize& given );
- // overriden methods of wxToolWindow
+ // Overridden function responding to mouse clicks on mini-buttons.
+ virtual void OnMiniButtonClicked( int btnIdx );
- virtual wxSize GetPreferredSize( const wxSize& given );
- virtual void OnMiniButtonClicked( int btnIdx );
- virtual bool HandleTitleClick( wxMouseEvent& event );
+ // Overridden function responding to mouse button clicks on the titlebar.
+ virtual bool HandleTitleClick( wxMouseEvent& event );
- void OnDblClick( wxMouseEvent& event );
+ // Responds to double-click mouse events.
+ void OnDblClick( wxMouseEvent& event );
- DECLARE_EVENT_TABLE()
+ DECLARE_EVENT_TABLE()
};
#endif /* __TOOLWND_G__ */