merging in the toolbar changes

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4977 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 1999-12-15 19:47:54 +00:00
parent 56f5d962ad
commit 8a0681f933
17 changed files with 4144 additions and 3737 deletions

View File

@ -4,139 +4,92 @@
// Author: Robert Roebling
// RCS-ID: $Id$
// Copyright: (c) Robert Roebling
// Licence: wxWindows licence
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __TBARGTKH__
#define __TBARGTKH__
#ifndef _WX_GTK_TBARGTK_H_
#define _WX_GTK_TBARGTK_H_
#ifdef __GNUG__
#pragma interface
#pragma interface "tbargtk.h"
#endif
#include "wx/defs.h"
#if wxUSE_TOOLBAR
#include "wx/control.h"
#include "wx/bitmap.h"
#include "wx/tbarbase.h"
//-----------------------------------------------------------------------------
// classes
//-----------------------------------------------------------------------------
class wxToolBarTool;
class wxToolBar;
//-----------------------------------------------------------------------------
// constants
//-----------------------------------------------------------------------------
#define wxTOOL_STYLE_BUTTON 1
#define wxTOOL_STYLE_SEPARATOR 2
//-----------------------------------------------------------------------------
// global data
//-----------------------------------------------------------------------------
extern const wxChar *wxToolBarNameStr;
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// wxToolBar
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
class wxToolBar: public wxControl
class wxToolBar : public wxToolBarBase
{
public:
wxToolBar();
wxToolBar( wxWindow *parent, wxWindowID id,
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
long style = 0, const wxString& name = wxToolBarNameStr );
~wxToolBar();
// construction/destruction
wxToolBar() { Init(); }
wxToolBar( wxWindow *parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxToolBarNameStr )
{
Init();
bool Create( wxWindow *parent, wxWindowID id,
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
long style = 0, const wxString& name = wxToolBarNameStr);
Create(parent, id, pos, size, style, name);
}
// Only allow toggle if returns TRUE. Call when left button up.
virtual bool OnLeftClick(int toolIndex, bool toggleDown);
bool Create( wxWindow *parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxToolBarNameStr );
// Call when right button down.
virtual void OnRightClick(int toolIndex, float x, float y);
// Called when the mouse cursor enters a tool bitmap.
// Argument is -1 if mouse is exiting the toolbar.
virtual void OnMouseEnter(int toolIndex);
// If pushedBitmap is NULL, a reversed version of bitmap is
// created and used as the pushed/toggled image.
// If toggle is TRUE, the button toggles between the two states.
virtual wxToolBarTool *AddTool( int toolIndex, const wxBitmap& bitmap,
const wxBitmap& pushedBitmap = wxNullBitmap, bool toggle = FALSE,
wxCoord xPos = -1, wxCoord yPos = -1, wxObject *clientData = (wxObject *)NULL,
const wxString& helpString1 = "", const wxString& helpString2 = "");
// Add arbitrary control
virtual bool AddControl(wxControl *control);
// Add space
virtual void AddSeparator();
// Delete tool by index (=id)
virtual bool DeleteTool(int toolIndex);
// Delete all tools
virtual void ClearTools();
// Has to be called after adding tools or changing something
virtual bool Realize();
virtual void EnableTool(int toolIndex, bool enable);
virtual void ToggleTool(int toolIndex, bool toggle); // toggle is TRUE if toggled on
virtual wxObject *GetToolClientData(int index) const;
virtual bool GetToolState(int toolIndex) const;
virtual bool GetToolEnabled(int toolIndex) const;
virtual ~wxToolBar();
// override base class virtuals
virtual void SetMargins(int x, int y);
void SetMargins(const wxSize& size) { SetMargins(size.x, size.y); };
virtual wxSize GetToolMargins(void) { return wxSize(m_xMargin, m_yMargin); }
virtual void SetToolPacking(int packing);
virtual void SetToolSeparation(int separation);
virtual int GetToolPacking();
virtual int GetToolSeparation();
virtual wxString GetToolLongHelp(int toolIndex);
virtual wxString GetToolShortHelp(int toolIndex);
virtual void SetToolLongHelp(int toolIndex, const wxString& helpString);
virtual void SetToolShortHelp(int toolIndex, const wxString& helpString);
void OnIdle( wxIdleEvent &ievent );
// implementation
virtual wxToolBarToolBase *FindToolForPosition(wxCoord x, wxCoord y) const;
// implementation from now on
// --------------------------
GtkToolbar *m_toolbar;
int m_separation;
wxList m_tools;
GdkColor *m_fg;
GdkColor *m_bg;
int m_xMargin;
int m_yMargin;
bool m_hasToolAlready;
GdkColor *m_fg;
GdkColor *m_bg;
bool m_blockNextEvent;
void OnInternalIdle();
protected:
// common part of all ctors
void Init();
// implement base class pure virtuals
virtual bool DoInsertTool(size_t pos, wxToolBarToolBase *tool);
virtual bool DoDeleteTool(size_t pos, wxToolBarToolBase *tool);
virtual void DoEnableTool(wxToolBarToolBase *tool, bool enable);
virtual void DoToggleTool(wxToolBarToolBase *tool, bool toggle);
virtual void DoSetToggle(wxToolBarToolBase *tool, bool toggle);
virtual wxToolBarToolBase *CreateTool(int id,
const wxBitmap& bitmap1,
const wxBitmap& bitmap2,
bool toggle,
wxObject *clientData,
const wxString& shortHelpString,
const wxString& longHelpString);
virtual wxToolBarToolBase *CreateTool(wxControl *control);
private:
DECLARE_EVENT_TABLE()
DECLARE_DYNAMIC_CLASS(wxToolBar)
};
#endif
#endif // wxUSE_TOOLBAR
#endif
// __TBARGTKH__
// _WX_GTK_TBARGTK_H_

View File

@ -4,139 +4,92 @@
// Author: Robert Roebling
// RCS-ID: $Id$
// Copyright: (c) Robert Roebling
// Licence: wxWindows licence
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef __TBARGTKH__
#define __TBARGTKH__
#ifndef _WX_GTK_TBARGTK_H_
#define _WX_GTK_TBARGTK_H_
#ifdef __GNUG__
#pragma interface
#pragma interface "tbargtk.h"
#endif
#include "wx/defs.h"
#if wxUSE_TOOLBAR
#include "wx/control.h"
#include "wx/bitmap.h"
#include "wx/tbarbase.h"
//-----------------------------------------------------------------------------
// classes
//-----------------------------------------------------------------------------
class wxToolBarTool;
class wxToolBar;
//-----------------------------------------------------------------------------
// constants
//-----------------------------------------------------------------------------
#define wxTOOL_STYLE_BUTTON 1
#define wxTOOL_STYLE_SEPARATOR 2
//-----------------------------------------------------------------------------
// global data
//-----------------------------------------------------------------------------
extern const wxChar *wxToolBarNameStr;
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// wxToolBar
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
class wxToolBar: public wxControl
class wxToolBar : public wxToolBarBase
{
public:
wxToolBar();
wxToolBar( wxWindow *parent, wxWindowID id,
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
long style = 0, const wxString& name = wxToolBarNameStr );
~wxToolBar();
// construction/destruction
wxToolBar() { Init(); }
wxToolBar( wxWindow *parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxToolBarNameStr )
{
Init();
bool Create( wxWindow *parent, wxWindowID id,
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
long style = 0, const wxString& name = wxToolBarNameStr);
Create(parent, id, pos, size, style, name);
}
// Only allow toggle if returns TRUE. Call when left button up.
virtual bool OnLeftClick(int toolIndex, bool toggleDown);
bool Create( wxWindow *parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxToolBarNameStr );
// Call when right button down.
virtual void OnRightClick(int toolIndex, float x, float y);
// Called when the mouse cursor enters a tool bitmap.
// Argument is -1 if mouse is exiting the toolbar.
virtual void OnMouseEnter(int toolIndex);
// If pushedBitmap is NULL, a reversed version of bitmap is
// created and used as the pushed/toggled image.
// If toggle is TRUE, the button toggles between the two states.
virtual wxToolBarTool *AddTool( int toolIndex, const wxBitmap& bitmap,
const wxBitmap& pushedBitmap = wxNullBitmap, bool toggle = FALSE,
wxCoord xPos = -1, wxCoord yPos = -1, wxObject *clientData = (wxObject *)NULL,
const wxString& helpString1 = "", const wxString& helpString2 = "");
// Add arbitrary control
virtual bool AddControl(wxControl *control);
// Add space
virtual void AddSeparator();
// Delete tool by index (=id)
virtual bool DeleteTool(int toolIndex);
// Delete all tools
virtual void ClearTools();
// Has to be called after adding tools or changing something
virtual bool Realize();
virtual void EnableTool(int toolIndex, bool enable);
virtual void ToggleTool(int toolIndex, bool toggle); // toggle is TRUE if toggled on
virtual wxObject *GetToolClientData(int index) const;
virtual bool GetToolState(int toolIndex) const;
virtual bool GetToolEnabled(int toolIndex) const;
virtual ~wxToolBar();
// override base class virtuals
virtual void SetMargins(int x, int y);
void SetMargins(const wxSize& size) { SetMargins(size.x, size.y); };
virtual wxSize GetToolMargins(void) { return wxSize(m_xMargin, m_yMargin); }
virtual void SetToolPacking(int packing);
virtual void SetToolSeparation(int separation);
virtual int GetToolPacking();
virtual int GetToolSeparation();
virtual wxString GetToolLongHelp(int toolIndex);
virtual wxString GetToolShortHelp(int toolIndex);
virtual void SetToolLongHelp(int toolIndex, const wxString& helpString);
virtual void SetToolShortHelp(int toolIndex, const wxString& helpString);
void OnIdle( wxIdleEvent &ievent );
// implementation
virtual wxToolBarToolBase *FindToolForPosition(wxCoord x, wxCoord y) const;
// implementation from now on
// --------------------------
GtkToolbar *m_toolbar;
int m_separation;
wxList m_tools;
GdkColor *m_fg;
GdkColor *m_bg;
int m_xMargin;
int m_yMargin;
bool m_hasToolAlready;
GdkColor *m_fg;
GdkColor *m_bg;
bool m_blockNextEvent;
void OnInternalIdle();
protected:
// common part of all ctors
void Init();
// implement base class pure virtuals
virtual bool DoInsertTool(size_t pos, wxToolBarToolBase *tool);
virtual bool DoDeleteTool(size_t pos, wxToolBarToolBase *tool);
virtual void DoEnableTool(wxToolBarToolBase *tool, bool enable);
virtual void DoToggleTool(wxToolBarToolBase *tool, bool toggle);
virtual void DoSetToggle(wxToolBarToolBase *tool, bool toggle);
virtual wxToolBarToolBase *CreateTool(int id,
const wxBitmap& bitmap1,
const wxBitmap& bitmap2,
bool toggle,
wxObject *clientData,
const wxString& shortHelpString,
const wxString& longHelpString);
virtual wxToolBarToolBase *CreateTool(wxControl *control);
private:
DECLARE_EVENT_TABLE()
DECLARE_DYNAMIC_CLASS(wxToolBar)
};
#endif
#endif // wxUSE_TOOLBAR
#endif
// __TBARGTKH__
// _WX_GTK_TBARGTK_H_

View File

@ -1,8 +1,8 @@
/////////////////////////////////////////////////////////////////////////////
// Name: toolbar.h
// Name: wx/motif/toolbar.h
// Purpose: wxToolBar class
// Author: Julian Smart
// Modified by:
// Modified by: 13.12.99 by VZ during toolbar classes reorganization
// Created: 17/09/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
@ -13,81 +13,60 @@
#define _WX_TOOLBAR_H_
#ifdef __GNUG__
#pragma interface "toolbar.h"
#pragma interface "toolbar.h"
#endif
#include "wx/tbarbase.h"
WXDLLEXPORT_DATA(extern const char*) wxToolBarNameStr;
class WXDLLEXPORT wxToolBar: public wxToolBarBase
class WXDLLEXPORT wxToolBar : public wxToolBarBase
{
DECLARE_DYNAMIC_CLASS(wxToolBar)
public:
/*
* Public interface
*/
public:
// ctors and dtor
wxToolBar() { Init(); }
wxToolBar();
wxToolBar(wxWindow *parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxNO_BORDER | wxTB_HORIZONTAL,
const wxString& name = wxToolBarNameStr)
{
Init();
inline wxToolBar(wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
long style = wxNO_BORDER|wxTB_HORIZONTAL,
const wxString& name = wxToolBarNameStr):
m_widgets(wxKEY_INTEGER)
Create(parent, id, pos, size, style, name);
}
{
Create(parent, id, pos, size, style, name);
}
~wxToolBar();
bool Create(wxWindow *parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxNO_BORDER | wxTB_HORIZONTAL,
const wxString& name = wxToolBarNameStr);
bool Create(wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
long style = wxNO_BORDER|wxTB_HORIZONTAL,
const wxString& name = wxToolBarNameStr);
virtual ~wxToolBar();
// If pushedBitmap is NULL, a reversed version of bitmap is
// created and used as the pushed/toggled image.
// If toggle is TRUE, the button toggles between the two states.
wxToolBarTool *AddTool(int toolIndex, const wxBitmap& bitmap, const wxBitmap& pushedBitmap = wxNullBitmap,
bool toggle = FALSE, wxCoord xPos = -1, wxCoord yPos = -1, wxObject *clientData = NULL,
const wxString& helpString1 = "", const wxString& helpString2 = "");
// override/implement base class virtuals
virtual wxToolBarTool *FindToolForPosition(wxCoord x, wxCoord y) const;
// Set default bitmap size
void SetToolBitmapSize(const wxSize& size);
void EnableTool(int toolIndex, bool enable); // additional drawing on enabling
void ToggleTool(int toolIndex, bool toggle); // toggle is TRUE if toggled on
void ClearTools();
virtual bool Realize();
// The button size is bigger than the bitmap size
wxSize GetToolSize() const;
// implementation from now on
wxSize GetMaxSize() const;
// Add all the buttons
virtual bool CreateTools();
virtual void LayoutTools() {}
// The post-tool-addition call. TODO: do here whatever's
// necessary for completing the toolbar construction.
bool Realize() { return CreateTools(); };
// Implementation
void DestroyPixmaps();
int FindIndexForWidget(WXWidget w);
WXWidget FindWidgetForIndex(int index);
WXWidget GetTopWidget() const;
WXWidget GetClientWidget() const;
WXWidget GetMainWidget() const;
// find tool by widget
wxToolBarTool *FindToolByWidget(WXWidget w) const;
protected:
// List of widgets in the toolbar, indexed by tool index
wxList m_widgets;
// common part of all ctors
void Init();
// List of pixmaps to destroy when tools are recreated or
// or toolbar is destroyed.
wxList m_pixmaps;
// implement base class pure virtuals
virtual bool DoInsertTool(size_t pos, wxToolBarTool *tool);
virtual bool DoDeleteTool(size_t pos, wxToolBarTool *tool);
DECLARE_EVENT_TABLE()
virtual void DoEnableTool(wxToolBarTool *tool, bool enable);
virtual void DoToggleTool(wxToolBarTool *tool, bool toggle);
virtual void DoSetToggle(wxToolBarTool *tool, bool toggle);
private:
DECLARE_DYNAMIC_CLASS(wxToolBar)
};
#endif

View File

@ -1,6 +1,6 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/msw/tbar95.h
// Purpose: wxToolBar95 (Windows 95 toolbar) class
// Purpose: wxToolBar (Windows 95 toolbar) class
// Author: Julian Smart
// Modified by:
// Created: 01/02/97
@ -13,21 +13,20 @@
#define _WX_TBAR95_H_
#ifdef __GNUG__
#pragma interface "tbar95.h"
#pragma interface "tbar95.h"
#endif
#if wxUSE_TOOLBAR
#include "wx/dynarray.h"
#include "wx/tbarbase.h"
class WXDLLEXPORT wxToolBar95 : public wxToolBarBase
class WXDLLEXPORT wxToolBar : public wxToolBarBase
{
public:
wxToolBar95() { Init(); }
// ctors and dtor
wxToolBar() { Init(); }
wxToolBar95(wxWindow *parent,
wxToolBar(wxWindow *parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
@ -39,8 +38,6 @@ public:
Create(parent, id, pos, size, style, name);
}
~wxToolBar95();
bool Create(wxWindow *parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
@ -48,36 +45,21 @@ public:
long style = wxNO_BORDER | wxTB_HORIZONTAL,
const wxString& name = wxToolBarNameStr);
// override base class virtuals
virtual ~wxToolBar();
virtual wxToolBarTool *AddTool(int toolIndex,
const wxBitmap& bitmap,
const wxBitmap& pushedBitmap = wxNullBitmap,
bool toggle = FALSE,
long xPos = -1, long yPos = -1,
wxObject *clientData = NULL,
const wxString& helpString1 = wxEmptyString,
const wxString& helpString2 = wxEmptyString);
virtual bool AddControl(wxControl *control);
// override/implement base class virtuals
virtual wxToolBarToolBase *FindToolForPosition(wxCoord x, wxCoord y) const;
virtual bool DeleteTool(int toolIndex);
virtual void ClearTools();
virtual bool Realize() { return CreateTools(); };
virtual void EnableTool(int toolIndex, bool enable);
virtual void ToggleTool(int toolIndex, bool toggle);
virtual bool Realize();
virtual void SetToolBitmapSize(const wxSize& size);
virtual wxSize GetToolSize() const;
virtual wxSize GetMaxSize() const;
virtual bool GetToolState(int toolIndex) const;
virtual bool CreateTools();
virtual void SetRows(int nRows);
// IMPLEMENTATION
// implementation only from now on
// -------------------------------
virtual bool MSWCommand(WXUINT param, WXWORD id);
virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
@ -88,34 +70,37 @@ protected:
// common part of all ctors
void Init();
// the array storing the id for each index
wxArrayInt m_ids;
// implement base class pure virtuals
virtual bool DoInsertTool(size_t pos, wxToolBarToolBase *tool);
virtual bool DoDeleteTool(size_t pos, wxToolBarToolBase *tool);
// get index from id (returns wxNOT_FOUND if no such button)
int GetIndexFromId(int id) const;
virtual void DoEnableTool(wxToolBarToolBase *tool, bool enable);
virtual void DoToggleTool(wxToolBarToolBase *tool, bool toggle);
virtual void DoSetToggle(wxToolBarToolBase *tool, bool toggle);
virtual wxToolBarToolBase *CreateTool(int id,
const wxBitmap& bitmap1,
const wxBitmap& bitmap2,
bool toggle,
wxObject *clientData,
const wxString& shortHelpString,
const wxString& longHelpString);
virtual wxToolBarToolBase *CreateTool(wxControl *control);
// should be called whenever the toolbar size changes
void UpdateSize();
// override WndProc to process WM_SIZE
virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
// the big bitmap containing all bitmaps of the toolbar buttons
WXHBITMAP m_hBitmap;
DECLARE_EVENT_TABLE()
};
class WXDLLEXPORT wxToolBar : public wxToolBar95
{
public:
wxToolBar() { }
wxToolBar(wxWindow *parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxNO_BORDER | wxTB_HORIZONTAL,
const wxString& name = wxToolBarNameStr)
: wxToolBar95(parent, id, pos, size, style, name)
{
}
// the total number of toolbar elements
size_t m_nButtons;
private:
DECLARE_EVENT_TABLE()
DECLARE_DYNAMIC_CLASS(wxToolBar)
};

View File

@ -1,8 +1,8 @@
/////////////////////////////////////////////////////////////////////////////
// Name: tbarmsw.h
// Purpose: wxToolBarMSW class
// Name: wx/msw/tbarmsw.h
// Purpose: wxToolBar for Win16
// Author: Julian Smart
// Modified by:
// Modified by: 13.12.99 by VZ during toolbar classes reorganization
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
@ -24,117 +24,123 @@ WXDLLEXPORT_DATA(extern const wxChar*) wxButtonBarNameStr;
class WXDLLEXPORT wxMemoryDC;
// Non-Win95 (WIN32, WIN16, UNIX) version
// ----------------------------------------------------------------------------
// wxToolBar for Win16
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxToolBarMSW: public wxToolBarBase
{
DECLARE_DYNAMIC_CLASS(wxToolBarMSW)
public:
/*
* Public interface
*/
wxToolBarMSW(void);
inline wxToolBarMSW(wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
long style = wxNO_BORDER|wxTB_HORIZONTAL, const wxString& name = wxButtonBarNameStr)
{
Create(parent, id, pos, size, style, name);
}
bool Create(wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
long style = wxNO_BORDER|wxTB_HORIZONTAL, const wxString& name = wxButtonBarNameStr);
~wxToolBarMSW(void);
// Handle wxWindows events
void OnPaint(wxPaintEvent& event);
void OnSize(wxSizeEvent& event);
void OnMouseEvent(wxMouseEvent& event);
// If pushedBitmap is NULL, a reversed version of bitmap is
// created and used as the pushed/toggled image.
// If toggle is TRUE, the button toggles between the two states.
wxToolBarTool *AddTool(int toolIndex, const wxBitmap& bitmap, const wxBitmap& pushedBitmap = wxNullBitmap,
bool toggle = FALSE, long xPos = -1, long yPos = -1, wxObject *clientData = NULL,
const wxString& helpString1 = wxEmptyString, const wxString& helpString2 = wxEmptyString);
void DrawTool(wxDC& dc, wxMemoryDC& memDc, wxToolBarTool *tool);
// Set default bitmap size
virtual void SetToolBitmapSize(const wxSize& size);
void EnableTool(int toolIndex, bool enable); // additional drawing on enabling
// The button size is bigger than the bitmap size
wxSize GetToolSize(void) const;
void LayoutTools();
// The post-tool-addition call
bool Realize() { Layout(); return TRUE; };
protected:
void DrawTool(wxDC& dc, wxToolBarTool *tool, int state);
void GetSysColors(void);
bool InitGlobalObjects(void);
void FreeGlobalObjects(void);
void PatB(WXHDC hdc,int x,int y,int dx,int dy, long rgb);
void CreateMask(WXHDC hDC, int xoffset, int yoffset, int dx, int dy);
void DrawBlankButton(WXHDC hdc, int x, int y, int dx, int dy, int state);
void DrawButton(WXHDC hdc, int x, int y, int dx, int dy, wxToolBarTool *tool, int state);
WXHBITMAP CreateDitherBitmap();
bool CreateDitherBrush(void);
bool FreeDitherBrush(void);
WXHBITMAP CreateMappedBitmap(WXHINSTANCE hInstance, void *lpBitmapInfo);
WXHBITMAP CreateMappedBitmap(WXHINSTANCE hInstance, WXHBITMAP hBitmap);
protected:
int m_currentRowsOrColumns;
long m_lastX, m_lastY;
WXHBRUSH m_hbrDither;
WXDWORD m_rgbFace;
WXDWORD m_rgbShadow;
WXDWORD m_rgbHilight;
WXDWORD m_rgbFrame;
//
// m_hdcMono is the DC that holds a mono bitmap, m_hbmMono
// that is used to create highlights
// of button faces.
// m_hbmDefault hold the default bitmap if there is one.
//
WXHDC m_hdcMono;
WXHBITMAP m_hbmMono;
WXHBITMAP m_hbmDefault;
DECLARE_EVENT_TABLE()
};
//
// States (not all of them currently used)
//
#define wxTBSTATE_CHECKED 0x01 // radio button is checked
#define wxTBSTATE_PRESSED 0x02 // button is being depressed (any style)
#define wxTBSTATE_ENABLED 0x04 // button is enabled
#define wxTBSTATE_HIDDEN 0x08 // button is hidden
#define wxTBSTATE_INDETERMINATE 0x10 // button is indeterminate
class WXDLLEXPORT wxToolBar : public wxToolBarMSW
class WXDLLEXPORT wxToolBar : public wxToolBarBase
{
public:
wxToolBar() { }
// construction
wxToolBar() { Init(); }
wxToolBar(wxWindow *parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxNO_BORDER | wxTB_HORIZONTAL,
const wxString& name = wxToolBarNameStr)
: wxToolBarMSW(parent, id, pos, size, style, name)
long style = wxNO_BORDER|wxTB_HORIZONTAL,
const wxString& name = wxButtonBarNameStr)
{
Init();
Create(parent, id, pos, size, style, name);
}
bool Create(wxWindow *parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxNO_BORDER|wxTB_HORIZONTAL,
const wxString& name = wxButtonBarNameStr);
~wxToolBar();
// implement/override base class (pure) virtuals
virtual wxToolBarToolBase *AddTool(int id,
const wxBitmap& bitmap,
const wxBitmap& pushedBitmap,
bool toggle,
wxCoord xPos,
wxCoord yPos = -1,
wxObject *clientData = NULL,
const wxString& helpString1 = wxEmptyString,
const wxString& helpString2 = wxEmptyString);
virtual wxToolBarToolBase *FindToolForPosition(wxCoord x, wxCoord y) const;
virtual void SetToolBitmapSize(const wxSize& size);
virtual wxSize GetToolSize() const;
virtual bool Realize();
// implementation only from now on
// -------------------------------
// Handle wxWindows events
void OnPaint(wxPaintEvent& event);
void OnMouseEvent(wxMouseEvent& event);
protected:
void Init();
virtual bool DoInsertTool(size_t pos, wxToolBarToolBase *tool);
virtual bool DoDeleteTool(size_t pos, wxToolBarToolBase *tool);
virtual void DoEnableTool(wxToolBarToolBase *tool, bool enable);
virtual void DoToggleTool(wxToolBarToolBase *tool, bool toggle);
virtual void DoSetToggle(wxToolBarToolBase *tool, bool toggle);
virtual wxToolBarToolBase *CreateTool(int id,
const wxBitmap& bitmap1,
const wxBitmap& bitmap2,
bool toggle,
wxObject *clientData,
const wxString& shortHelpString,
const wxString& longHelpString);
virtual wxToolBarToolBase *CreateTool(wxControl *control);
void DoRedrawTool(wxToolBarToolBase *tool);
void DrawTool(wxDC& dc, wxToolBarToolBase *tool);
void DrawTool(wxDC& dc, wxToolBarToolBase *tool, int state);
void GetSysColors();
bool InitGlobalObjects();
void FreeGlobalObjects();
void PatB(WXHDC hdc,int x,int y,int dx,int dy, long rgb);
void CreateMask(WXHDC hDC, int xoffset, int yoffset, int dx, int dy);
void DrawBlankButton(WXHDC hdc, int x, int y, int dx, int dy, int state);
void DrawButton(WXHDC hdc, int x, int y, int dx, int dy,
wxToolBarTool *tool, int state);
WXHBITMAP CreateDitherBitmap();
bool CreateDitherBrush();
bool FreeDitherBrush();
WXHBITMAP CreateMappedBitmap(WXHINSTANCE hInstance, void *lpBitmapInfo);
WXHBITMAP CreateMappedBitmap(WXHINSTANCE hInstance, WXHBITMAP hBitmap);
int m_currentRowsOrColumns;
int m_pressedTool, m_currentTool;
wxCoord m_xPos, m_yPos;
wxCoord m_lastX, m_lastY;
WXHBRUSH m_hbrDither;
WXDWORD m_rgbFace;
WXDWORD m_rgbShadow;
WXDWORD m_rgbHilight;
WXDWORD m_rgbFrame;
//
// m_hdcMono is the DC that holds a mono bitmap, m_hbmMono
// that is used to create highlights
// of button faces.
// m_hbmDefault hold the default bitmap if there is one.
//
WXHDC m_hdcMono;
WXHBITMAP m_hbmMono;
WXHBITMAP m_hbmDefault;
private:
DECLARE_EVENT_TABLE()
DECLARE_DYNAMIC_CLASS(wxToolBar)
};

View File

@ -26,7 +26,8 @@
#include "wx/list.h"
#include "wx/control.h"
class WXDLLEXPORT wxToolBar;
class WXDLLEXPORT wxToolBarBase;
class WXDLLEXPORT wxToolBarToolBase;
// ----------------------------------------------------------------------------
// constants
@ -36,7 +37,7 @@ WXDLLEXPORT_DATA(extern const wxChar*) wxToolBarNameStr;
WXDLLEXPORT_DATA(extern const wxSize) wxDefaultSize;
WXDLLEXPORT_DATA(extern const wxPoint) wxDefaultPosition;
enum
enum wxToolBarToolStyle
{
wxTOOL_STYLE_BUTTON = 1,
wxTOOL_STYLE_SEPARATOR = 2,
@ -44,60 +45,128 @@ enum
};
// ----------------------------------------------------------------------------
// wxToolBarTool is one button/separator/whatever in the toolbar
// wxToolBarTool is a toolbar element.
//
// It has a unique id (except for the separators which always have id -1), the
// style (telling whether it is a normal button, separator or a control), the
// state (toggled or not, enabled or not) and short and long help strings. The
// default implementations use the short help string for the tooltip text which
// is popped up when the mouse pointer enters the tool and the long help string
// for the applications status bar.
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxToolBarTool : public wxObject
class WXDLLEXPORT wxToolBarToolBase : public wxObject
{
public:
// ctors & dtor
// ------------
wxToolBarTool() { }
wxToolBarToolBase(wxToolBarBase *tbar = (wxToolBarBase *)NULL,
int id = wxID_SEPARATOR,
const wxBitmap& bitmap1 = wxNullBitmap,
const wxBitmap& bitmap2 = wxNullBitmap,
bool toggle = FALSE,
wxObject *clientData = (wxObject *) NULL,
const wxString& shortHelpString = wxEmptyString,
const wxString& longHelpString = wxEmptyString)
: m_shortHelpString(shortHelpString),
m_longHelpString(longHelpString)
{
m_tbar = tbar;
m_id = id;
m_clientData = clientData;
#ifdef __WXGTK__
wxToolBarTool(wxToolBar *owner,
int theIndex = 0,
const wxBitmap& bitmap1 = wxNullBitmap,
const wxBitmap& bitmap2 = wxNullBitmap,
bool toggle = FALSE,
wxObject *clientData = (wxObject *) NULL,
const wxString& shortHelpString = wxEmptyString,
const wxString& longHelpString = wxEmptyString,
GtkWidget *pixmap = (GtkWidget *) NULL );
#else // !GTK
wxToolBarTool(int theIndex,
const wxBitmap& bitmap1 = wxNullBitmap,
const wxBitmap& bitmap2 = wxNullBitmap,
bool toggle = FALSE,
long xPos = -1,
long yPos = -1,
const wxString& shortHelpString = wxEmptyString,
const wxString& longHelpString = wxEmptyString);
#endif // GTK/!GTK
m_bitmap1 = bitmap1;
m_bitmap2 = bitmap2;
wxToolBarTool(wxControl *control);
m_isToggle = toggle;
m_enabled = TRUE;
m_toggled = FALSE;
~wxToolBarTool();
m_toolStyle = id == wxID_SEPARATOR ? wxTOOL_STYLE_SEPARATOR
: wxTOOL_STYLE_BUTTON;
}
wxToolBarToolBase(wxToolBarBase *tbar, wxControl *control)
{
m_tbar = tbar;
m_control = control;
m_id = control->GetId();
m_isToggle = FALSE;
m_enabled = TRUE;
m_toggled = FALSE;
m_toolStyle = wxTOOL_STYLE_CONTROL;
}
~wxToolBarToolBase();
// accessors
// ---------
void SetSize( long w, long h ) { m_width = w; m_height = h; }
long GetWidth() const { return m_width; }
long GetHeight() const { return m_height; }
// general
int GetId() const { return m_id; }
wxControl *GetControl() const
{
wxASSERT_MSG( m_toolStyle == wxTOOL_STYLE_CONTROL,
_T("this toolbar tool is not a control") );
wxASSERT_MSG( IsControl(), _T("this toolbar tool is not a control") );
return m_control;
}
public:
int m_toolStyle;
int m_index;
wxToolBarBase *GetToolBar() const { return m_tbar; }
// style
int IsButton() const { return m_toolStyle == wxTOOL_STYLE_BUTTON; }
int IsControl() const { return m_toolStyle == wxTOOL_STYLE_CONTROL; }
int IsSeparator() const { return m_toolStyle == wxTOOL_STYLE_SEPARATOR; }
int GetStyle() const { return m_toolStyle; }
// state
bool IsEnabled() const { return m_enabled; }
bool IsToggled() const { return m_toggled; }
bool CanBeToggled() const { return m_isToggle; }
// attributes
const wxBitmap& GetBitmap1() const { return m_bitmap1; }
const wxBitmap& GetBitmap2() const { return m_bitmap2; }
const wxBitmap& GetBitmap() const
{ return IsToggled() ? m_bitmap2 : m_bitmap1; }
wxString GetShortHelp() const { return m_shortHelpString; }
wxString GetLongHelp() const { return m_longHelpString; }
wxObject *GetClientData() const
{
wxASSERT_MSG( m_toolStyle != wxTOOL_STYLE_CONTROL,
_T("this toolbar tool doesn't have client data") );
return m_clientData;
}
// modifiers: return TRUE if the state really changed
bool Enable(bool enable);
bool Toggle(bool toggle);
bool SetToggle(bool toggle);
bool SetShortHelp(const wxString& help);
bool SetLongHelp(const wxString& help);
void Toggle() { Toggle(!IsToggled()); }
void SetBitmap1(const wxBitmap& bmp) { m_bitmap1 = bmp; }
void SetBitmap2(const wxBitmap& bmp) { m_bitmap2 = bmp; }
// add tool to/remove it from a toolbar
virtual void Detach() { m_tbar = (wxToolBarBase *)NULL; }
virtual void Attach(wxToolBarBase *tbar) { m_tbar = tbar; }
protected:
wxToolBarBase *m_tbar; // the toolbar to which we belong (may be NULL)
int m_toolStyle; // see enum wxToolBarToolStyle
int m_id; // the tool id, wxID_SEPARATOR for separator
// as controls have their own client data, no need to waste memory
union
@ -106,33 +175,23 @@ public:
wxControl *m_control;
};
wxCoord m_x;
wxCoord m_y;
wxCoord m_width;
wxCoord m_height;
// tool state
bool m_toggled;
bool m_isToggle;
bool m_enabled;
bool m_toggleState;
bool m_isToggle;
bool m_enabled;
bool m_isMenuCommand;
// normal and toggles bitmaps
wxBitmap m_bitmap1;
wxBitmap m_bitmap2;
bool m_deleteSecondBitmap;
wxBitmap m_bitmap1;
wxBitmap m_bitmap2;
wxString m_shortHelpString;
wxString m_longHelpString;
#ifdef __WXGTK__
wxToolBar *m_owner;
GtkWidget *m_item;
GtkWidget *m_pixmap;
#endif // GTK
private:
DECLARE_DYNAMIC_CLASS(wxToolBarTool)
// short and long help strings
wxString m_shortHelpString;
wxString m_longHelpString;
};
// a list of toolbar tools
WX_DECLARE_LIST(wxToolBarToolBase, wxToolBarToolsList);
// ----------------------------------------------------------------------------
// the base class for all toolbars
// ----------------------------------------------------------------------------
@ -141,7 +200,7 @@ class WXDLLEXPORT wxToolBarBase : public wxControl
{
public:
wxToolBarBase();
~wxToolBarBase();
virtual ~wxToolBarBase();
// toolbar construction
// --------------------
@ -149,50 +208,93 @@ public:
// If pushedBitmap is NULL, a reversed version of bitmap is created and
// used as the pushed/toggled image. If toggle is TRUE, the button toggles
// between the two states.
virtual wxToolBarTool *AddTool(int toolIndex,
wxToolBarToolBase *AddTool(int id,
const wxBitmap& bitmap,
const wxBitmap& pushedBitmap = wxNullBitmap,
bool toggle = FALSE,
wxObject *clientData = NULL,
const wxString& shortHelpString = wxEmptyString,
const wxString& longHelpString = wxEmptyString)
{
return AddTool(id, bitmap, pushedBitmap, toggle,
-1, -1, clientData, shortHelpString, longHelpString);
}
// the old version of AddTool() kept for compatibility
virtual wxToolBarToolBase *AddTool
(
int id,
const wxBitmap& bitmap,
const wxBitmap& pushedBitmap = wxNullBitmap,
bool toggle = FALSE,
wxCoord xPos = -1,
const wxBitmap& pushedBitmap,
bool toggle,
wxCoord xPos,
wxCoord yPos = -1,
wxObject *clientData = NULL,
const wxString& helpString1 = wxEmptyString,
const wxString& helpString2 = wxEmptyString);
const wxString& helpString2 = wxEmptyString
);
// add an arbitrary control to the toolbar at given index, return TRUE if
// ok (notice that the control will be deleted by the toolbar and that it
// will also adjust its position/size)
// insert the new tool at the given position, if pos == GetToolsCount(), it
// is equivalent to AddTool()
virtual wxToolBarToolBase *InsertTool
(
size_t pos,
int id,
const wxBitmap& bitmap,
const wxBitmap& pushedBitmap = wxNullBitmap,
bool toggle = FALSE,
wxObject *clientData = NULL,
const wxString& help1 = wxEmptyString,
const wxString& help2 = wxEmptyString
);
// add an arbitrary control to the toolbar, return TRUE if ok (notice that
// the control will be deleted by the toolbar and that it will also adjust
// its position/size)
//
// NB: the control should have toolbar as its parent
virtual bool AddControl(wxControl * WXUNUSED(control)) { return FALSE; }
virtual wxToolBarToolBase *AddControl(wxControl *control);
virtual wxToolBarToolBase *InsertControl(size_t pos, wxControl *control);
virtual void AddSeparator();
// add a separator to the toolbar
virtual wxToolBarToolBase *AddSeparator();
virtual wxToolBarToolBase *InsertSeparator(size_t pos);
// remove the tool from the toolbar: the caller is responsible for actually
// deleting the pointer
virtual wxToolBarToolBase *RemoveTool(int id);
// delete tool either by index or by position
virtual bool DeleteToolByPos(size_t pos);
virtual bool DeleteTool(int id);
// delete all tools
virtual void ClearTools();
// must be called after all buttons have been created to finish toolbar
// initialisation
virtual bool Realize() = 0;
virtual bool Realize();
// tools state
// -----------
virtual void EnableTool(int toolIndex, bool enable);
// toggle is TRUE if toggled on
virtual void ToggleTool(int toolIndex, bool toggle);
virtual void EnableTool(int id, bool enable);
virtual void ToggleTool(int id, bool toggle);
// Set this to be togglable (or not)
virtual void SetToggle(int toolIndex, bool toggle);
virtual void SetToggle(int id, bool toggle);
virtual wxObject *GetToolClientData(int index) const;
virtual bool GetToolState(int toolIndex) const;
virtual bool GetToolEnabled(int toolIndex) const;
virtual wxToolBarTool *FindToolForPosition(long x, long y) const;
// return TRUE if the tool is toggled
virtual bool GetToolState(int id) const;
virtual void SetToolShortHelp(int toolIndex, const wxString& helpString);
virtual wxString GetToolShortHelp(int toolIndex) const;
virtual void SetToolLongHelp(int toolIndex, const wxString& helpString);
virtual wxString GetToolLongHelp(int toolIndex) const;
virtual bool GetToolEnabled(int id) const;
virtual void SetToolShortHelp(int id, const wxString& helpString);
virtual wxString GetToolShortHelp(int id) const;
virtual void SetToolLongHelp(int id, const wxString& helpString);
virtual wxString GetToolLongHelp(int id) const;
// margins/packing/separation
// --------------------------
@ -200,48 +302,58 @@ public:
virtual void SetMargins(int x, int y);
void SetMargins(const wxSize& size)
{ SetMargins((int) size.x, (int) size.y); }
virtual void SetToolPacking(int packing);
virtual void SetToolSeparation(int separation);
virtual void SetToolPacking(int packing)
{ m_toolPacking = packing; }
virtual void SetToolSeparation(int separation)
{ m_toolSeparation = separation; }
virtual wxSize GetToolMargins() { return wxSize(m_xMargin, m_yMargin); }
virtual int GetToolPacking() { return m_toolPacking; }
virtual int GetToolSeparation() { return m_toolSeparation; }
// toolbar geometry
// ----------------
// set the number of toolbar rows
virtual void SetRows(int nRows);
// the toolbar can wrap - limit the number of columns or rows it may take
void SetMaxRowsCols(int rows, int cols)
{ m_maxRows = rows; m_maxCols = cols; }
int GetMaxRows() const { return m_maxRows; }
int GetMaxCols() const { return m_maxCols; }
// tool(bar) size
// -------------
// get/set the size of the bitmaps used by the toolbar: should be called
// before adding any tools to the toolbar
virtual void SetToolBitmapSize(const wxSize& size)
{ m_defaultWidth = size.x; m_defaultHeight = size.y; };
virtual wxSize GetToolBitmapSize() const
{ return wxSize(m_defaultWidth, m_defaultHeight); }
// After the toolbar has initialized, this is the size the tools take up
virtual wxSize GetMaxSize() const;
// The button size (in some implementations) is bigger than the bitmap size: this returns
// the total button size.
// the button size in some implementations is bigger than the bitmap size:
// get the total button size (by default the same as bitmap size)
virtual wxSize GetToolSize() const
{ return wxSize(m_defaultWidth, m_defaultHeight); } ;
{ return GetToolBitmapSize(); } ;
// Handle wxToolBar events
// -----------------------
// returns a (non separator) tool containing the point (x, y) or NULL if
// there is no tool at this point (corrdinates are client)
virtual wxToolBarToolBase *FindToolForPosition(wxCoord x,
wxCoord y) const = 0;
// event handlers
// --------------
// NB: these functions are deprecated, use EVT_TOOL_XXX() instead!
// Only allow toggle if returns TRUE. Call when left button up.
virtual bool OnLeftClick(int toolIndex, bool toggleDown);
virtual bool OnLeftClick(int id, bool toggleDown);
// Call when right button down.
virtual void OnRightClick(int toolIndex, long x, long y);
virtual void OnRightClick(int id, long x, long y);
// Called when the mouse cursor enters a tool bitmap.
// Argument is -1 if mouse is exiting the toolbar.
virtual void OnMouseEnter(int toolIndex);
virtual void OnMouseEnter(int id);
// more deprecated functions
// -------------------------
@ -255,103 +367,75 @@ public:
virtual void SetDefaultSize(const wxSize& size) { SetToolBitmapSize(size); }
virtual wxSize GetDefaultSize() const { return GetToolBitmapSize(); }
virtual wxSize GetDefaultButtonSize() const { return GetToolSize(); }
void GetMaxSize ( long * width, long * height ) const
{ wxSize maxSize(GetMaxSize()); *width = maxSize.x; *height = maxSize.y; }
#endif // WXWIN_COMPATIBILITY
// implementation only from now on
// -------------------------------
wxList& GetTools() const { return (wxList&) m_tools; }
size_t GetToolsCount() const { return m_tools.GetCount(); }
// Lay the tools out
virtual void LayoutTools();
// Add all the buttons: required for Win95.
virtual bool CreateTools() { return TRUE; }
void Command(wxCommandEvent& event);
// SCROLLING: this has to be copied from wxScrolledWindow since wxToolBarBase
// inherits from wxControl. This could have been put into wxToolBarSimple,
// but we might want any derived toolbar class to be scrollable.
// Number of pixels per user unit (0 or -1 for no scrollbar)
// Length of virtual canvas in user units
virtual void SetScrollbars(int horizontal, int vertical,
int x_length, int y_length,
int x_pos = 0, int y_pos = 0);
// Physically scroll the window
virtual void Scroll(int x_pos, int y_pos);
virtual void GetScrollPixelsPerUnit(int *x_unit, int *y_unit) const;
virtual void EnableScrolling(bool x_scrolling, bool y_scrolling);
virtual void AdjustScrollbars();
// Prepare the DC by translating it according to the current scroll position
virtual void PrepareDC(wxDC& dc);
int GetScrollPageSize(int orient) const ;
void SetScrollPageSize(int orient, int pageSize);
// Get the view start
virtual void ViewStart(int *x, int *y) const;
// Actual size in pixels when scrolling is taken into account
virtual void GetVirtualSize(int *x, int *y) const;
void OnIdle(wxIdleEvent& event);
// Do the toolbar button updates (check for EVT_UPDATE_UI handlers)
virtual void DoToolbarUpdates();
// event handlers
void OnScroll(wxScrollEvent& event);
void OnSize(wxSizeEvent& event);
void OnIdle(wxIdleEvent& event);
protected:
wxList m_tools;
// to implement in derived classes
// -------------------------------
int m_maxRows;
int m_maxCols;
long m_maxWidth,
m_maxHeight;
// the tool is not yet inserted into m_tools list when this function is
// called and will only be added to it if this function succeeds
virtual bool DoInsertTool(size_t pos, wxToolBarToolBase *tool) = 0;
int m_currentTool; // Tool where mouse currently is
int m_pressedTool; // Tool where mouse pressed
// the tool is still in m_tools list when this function is called, it will
// only be deleted from it if it succeeds
virtual bool DoDeleteTool(size_t pos, wxToolBarToolBase *tool) = 0;
int m_xMargin;
int m_yMargin;
int m_toolPacking;
int m_toolSeparation;
// called when the tools enabled flag changes
virtual void DoEnableTool(wxToolBarToolBase *tool, bool enable) = 0;
wxCoord m_defaultWidth;
wxCoord m_defaultHeight;
// called when the tool is toggled
virtual void DoToggleTool(wxToolBarToolBase *tool, bool toggle) = 0;
public:
////////////////////////////////////////////////////////////////////////
//// IMPLEMENTATION
// called when the tools "can be toggled" flag changes
virtual void DoSetToggle(wxToolBarToolBase *tool, bool toggle) = 0;
// Calculate scroll increment
virtual int CalcScrollInc(wxScrollEvent& event);
// the functions to create toolbar tools
virtual wxToolBarToolBase *CreateTool(int id,
const wxBitmap& bitmap1,
const wxBitmap& bitmap2,
bool toggle,
wxObject *clientData,
const wxString& shortHelpString,
const wxString& longHelpString) = 0;
virtual wxToolBarToolBase *CreateTool(wxControl *control) = 0;
////////////////////////////////////////////////////////////////////////
//// PROTECTED DATA
protected:
int m_xScrollPixelsPerLine;
int m_yScrollPixelsPerLine;
bool m_xScrollingEnabled;
bool m_yScrollingEnabled;
int m_xScrollPosition;
int m_yScrollPosition;
bool m_calcScrolledOffset; // If TRUE, wxCanvasDC uses scrolled offsets
int m_xScrollLines;
int m_yScrollLines;
int m_xScrollLinesPerPage;
int m_yScrollLinesPerPage;
// helper functions
// ----------------
// find the tool by id
wxToolBarToolBase *FindById(int id) const;
// the list of all our tools
wxToolBarToolsList m_tools;
// the offset of the first tool
int m_xMargin;
int m_yMargin;
// the maximum number of toolbar rows/columns
int m_maxRows;
int m_maxCols;
// the tool packing and separation
int m_toolPacking,
m_toolSeparation;
// the size of the toolbar bitmaps
wxCoord m_defaultWidth, m_defaultHeight;
private:
DECLARE_EVENT_TABLE()
DECLARE_ABSTRACT_CLASS(wxToolBarBase)
};
#endif

View File

@ -1,13 +0,0 @@
#ifndef _WX_TBARMSW_H_BASE_
#define _WX_TBARMSW_H_BASE_
#if defined(__WXMSW__)
#include "wx/msw/tbarmsw.h"
#elif defined(__WXMOTIF__)
#include "wx/motif/tbarmsw.h"
#elif defined(__WXGTK__)
#include "wx/gtk/tbarmsw.h"
#endif
#endif
// _WX_TBARMSW_H_BASE_

View File

@ -1,81 +1,173 @@
/////////////////////////////////////////////////////////////////////////////
// Name: tbarsmpl.h
// Name: wx/tbarsmpl.h
// Purpose: wxToolBarSimple class
// Author: Julian Smart
// Modified by:
// Modified by: VZ on 14.12.99 during wxToolBar classes reorganization
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows licence
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_TBARSMPLH__
#define _WX_TBARSMPLH__
#ifdef __GNUG__
#pragma interface "tbarsmpl.h"
#pragma interface "tbarsmpl.h"
#endif
#include "wx/defs.h"
#if wxUSE_TOOLBAR
#include "wx/bitmap.h"
#include "wx/list.h"
#include "wx/tbarbase.h"
#if wxUSE_TOOLBAR_SIMPLE
class WXDLLEXPORT wxMemoryDC;
WXDLLEXPORT_DATA(extern const wxChar*) wxToolBarNameStr;
WXDLLEXPORT_DATA(extern const wxSize) wxDefaultSize;
WXDLLEXPORT_DATA(extern const wxPoint) wxDefaultPosition;
// ----------------------------------------------------------------------------
// wxToolBarSimple is a generic toolbar implementation in pure wxWindows
// ----------------------------------------------------------------------------
// XView can't cope properly with panels that behave like canvases
// (e.g. no scrollbars in panels)
class WXDLLEXPORT wxToolBarSimple : public wxToolBarBase
{
DECLARE_DYNAMIC_CLASS(wxToolBarSimple)
public:
// ctors and dtor
wxToolBarSimple() { Init(); }
public:
wxToolBarSimple(wxWindow *parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxNO_BORDER | wxTB_HORIZONTAL,
const wxString& name = wxToolBarNameStr)
{
Init();
wxToolBarSimple(void);
inline wxToolBarSimple(wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
long style = wxNO_BORDER|wxTB_HORIZONTAL,
const wxString& name = wxToolBarNameStr)
{
Create(parent, id, pos, size, style, name);
}
~wxToolBarSimple(void);
Create(parent, id, pos, size, style, name);
}
bool Create(wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
long style = wxNO_BORDER|wxTB_HORIZONTAL, const wxString& name = wxToolBarNameStr);
bool Create(wxWindow *parent,
wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxNO_BORDER | wxTB_HORIZONTAL,
const wxString& name = wxToolBarNameStr);
void OnPaint(wxPaintEvent& event);
void OnSize(wxSizeEvent& event);
void OnMouseEvent(wxMouseEvent& event);
void OnKillFocus(wxFocusEvent& event);
virtual ~wxToolBarSimple();
// Handle wxToolBar events
// override/implement base class virtuals
virtual wxToolBarToolBase *AddTool
(
int id,
const wxBitmap& bitmap,
const wxBitmap& pushedBitmap,
bool toggle,
wxCoord xPos,
wxCoord yPos = -1,
wxObject *clientData = NULL,
const wxString& helpString1 = wxEmptyString,
const wxString& helpString2 = wxEmptyString
);
virtual void DrawTool(wxDC& dc, wxMemoryDC& memDC, wxToolBarTool *tool);
virtual void ToggleTool(int toolIndex, bool toggle); // toggle is TRUE if toggled on
virtual wxToolBarToolBase *FindToolForPosition(wxCoord x, wxCoord y) const;
virtual void SpringUpButton(int index);
virtual bool Realize();
virtual void LayoutTools();
virtual void SetRows(int nRows);
// The post-tool-addition call
virtual bool Realize() { LayoutTools(); return TRUE; };
// implementation from now on
// --------------------------
// SCROLLING: this has to be copied from wxScrolledWindow since
// wxToolBarBase inherits from wxControl. This could have been put into
// wxToolBarSimple, but we might want any derived toolbar class to be
// scrollable.
// Number of pixels per user unit (0 or -1 for no scrollbar)
// Length of virtual canvas in user units
virtual void SetScrollbars(int horizontal, int vertical,
int x_length, int y_length,
int x_pos = 0, int y_pos = 0);
// Physically scroll the window
virtual void Scroll(int x_pos, int y_pos);
virtual void GetScrollPixelsPerUnit(int *x_unit, int *y_unit) const;
virtual void EnableScrolling(bool x_scrolling, bool y_scrolling);
virtual void AdjustScrollbars();
// Prepare the DC by translating it according to the current scroll position
virtual void PrepareDC(wxDC& dc);
int GetScrollPageSize(int orient) const ;
void SetScrollPageSize(int orient, int pageSize);
// Get the view start
virtual void ViewStart(int *x, int *y) const;
// Actual size in pixels when scrolling is taken into account
virtual void GetVirtualSize(int *x, int *y) const;
int CalcScrollInc(wxScrollEvent& event);
// event handlers
void OnPaint(wxPaintEvent& event);
void OnSize(wxSizeEvent& event);
void OnMouseEvent(wxMouseEvent& event);
void OnKillFocus(wxFocusEvent& event);
void OnScroll(wxScrollEvent& event);
protected:
int m_currentRowsOrColumns;
long m_lastX, m_lastY;
// common part of all ctors
void Init();
DECLARE_EVENT_TABLE()
// implement base class pure virtuals
virtual bool DoInsertTool(size_t pos, wxToolBarToolBase *tool);
virtual bool DoDeleteTool(size_t pos, wxToolBarToolBase *tool);
virtual void DoEnableTool(wxToolBarToolBase *tool, bool enable);
virtual void DoToggleTool(wxToolBarToolBase *tool, bool toggle);
virtual void DoSetToggle(wxToolBarToolBase *tool, bool toggle);
virtual wxToolBarToolBase *CreateTool(int id,
const wxBitmap& bitmap1,
const wxBitmap& bitmap2,
bool toggle,
wxObject *clientData,
const wxString& shortHelpString,
const wxString& longHelpString);
virtual wxToolBarToolBase *CreateTool(wxControl *control);
// helpers
void DrawTool(wxToolBarToolBase *tool);
virtual void DrawTool(wxDC& dc, wxToolBarToolBase *tool);
virtual void SpringUpButton(int index);
int m_currentRowsOrColumns;
int m_pressedTool, m_currentTool;
wxCoord m_lastX, m_lastY;
wxCoord m_maxWidth, m_maxHeight;
wxCoord m_xPos, m_yPos;
// scrolling data
int m_xScrollPixelsPerLine;
int m_yScrollPixelsPerLine;
bool m_xScrollingEnabled;
bool m_yScrollingEnabled;
int m_xScrollPosition;
int m_yScrollPosition;
bool m_calcScrolledOffset; // If TRUE, wxCanvasDC uses scrolled offsets
int m_xScrollLines;
int m_yScrollLines;
int m_xScrollLinesPerPage;
int m_yScrollLinesPerPage;
private:
DECLARE_EVENT_TABLE()
DECLARE_DYNAMIC_CLASS(wxToolBarSimple)
};
#endif // wxUSE_TOOLBAR
#endif // wxUSE_TOOLBAR_SIMPLE
#endif
// _WX_TBARSMPLH__

View File

@ -14,29 +14,32 @@
#include "wx/tbarbase.h" // the base class for all toolbars
#if 0
class WXDLLEXPORT wxToolBar : public wxControl
{
};
#endif // 0
#if defined(__WXMSW__) && defined(__WIN95__)
# include "wx/msw/tbar95.h"
#elif defined(__WXMSW__)
# include "wx/msw/tbarmsw.h"
#elif defined(__WXMOTIF__)
# include "wx/motif/toolbar.h"
#elif defined(__WXGTK__)
# include "wx/gtk/tbargtk.h"
#elif defined(__WXQT__)
# include "wx/qt/tbarqt.h"
#elif defined(__WXMAC__)
# include "wx/mac/toolbar.h"
#elif defined(__WXPM__)
# include "wx/os2/toolbar.h"
#elif defined(__WXSTUBS__)
# include "wx/stubs/toolbar.h"
#endif
#if wxUSE_TOOLBAR
#if !wxUSE_TOOLBAR_NATIVE
// the wxToolBarSimple is *the* toolbar class in this case
#define wxToolBarSimple wxToolBar
#include "wx/tbarsmpl.h"
#else // wxUSE_TOOLBAR_NATIVE
#if defined(__WXMSW__) && defined(__WIN95__)
#include "wx/msw/tbar95.h"
#elif defined(__WXMSW__)
#include "wx/msw/tbarmsw.h"
#elif defined(__WXMOTIF__)
#include "wx/motif/toolbar.h"
#elif defined(__WXGTK__)
#include "wx/gtk/tbargtk.h"
#elif defined(__WXQT__)
#include "wx/qt/tbarqt.h"
#elif defined(__WXMAC__)
#include "wx/mac/toolbar.h"
#elif defined(__WXPM__)
#include "wx/os2/toolbar.h"
#elif defined(__WXSTUBS__)
#include "wx/stubs/toolbar.h"
#endif
#endif // !wxUSE_TOOLBAR_NATIVE/wxUSE_TOOLBAR_NATIVE
#endif // wxUSE_TOOLBAR
#endif
// _WX_TOOLBAR_H_BASE_

File diff suppressed because it is too large Load Diff

View File

@ -1,461 +0,0 @@
/////////////////////////////////////////////////////////////////////////////
// Name: tbarsmpl.cpp
// Purpose: wxToolBarSimple
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "tbarsmpl.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/settings.h"
#include "wx/window.h"
#include "wx/dcclient.h"
#include "wx/dcmemory.h"
#endif
#if wxUSE_TOOLBAR
#include "wx/tbarsmpl.h"
IMPLEMENT_DYNAMIC_CLASS(wxToolBarSimple, wxToolBarBase)
BEGIN_EVENT_TABLE(wxToolBarSimple, wxToolBarBase)
EVT_SIZE(wxToolBarSimple::OnSize)
EVT_PAINT(wxToolBarSimple::OnPaint)
EVT_KILL_FOCUS(wxToolBarSimple::OnKillFocus)
EVT_MOUSE_EVENTS(wxToolBarSimple::OnMouseEvent)
END_EVENT_TABLE()
wxToolBarSimple::wxToolBarSimple(void)
{
m_currentRowsOrColumns = 0;
m_lastX = 0;
m_lastY = 0;
}
bool wxToolBarSimple::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style,
const wxString& name )
{
if ( ! wxWindow::Create(parent, id, pos, size, style, name) )
return FALSE;
// Set it to grey (or other 3D face colour)
wxSystemSettings settings;
SetBackgroundColour(settings.GetSystemColour(wxSYS_COLOUR_3DFACE));
if ( GetWindowStyleFlag() & wxTB_VERTICAL )
{ m_lastX = 7; m_lastY = 3; }
else
{ m_lastX = 3; m_lastY = 7; }
m_maxWidth = m_maxHeight = 0;
m_pressedTool = m_currentTool = -1;
m_xMargin = 0;
m_yMargin = 0;
m_toolPacking = 1;
m_toolSeparation = 5;
SetCursor(*wxSTANDARD_CURSOR);
return TRUE;
}
wxToolBarSimple::~wxToolBarSimple ()
{
}
void wxToolBarSimple::OnPaint (wxPaintEvent& WXUNUSED(event))
{
wxPaintDC dc(this);
PrepareDC(dc);
static int count = 0;
// Prevent reentry of OnPaint which would cause wxMemoryDC errors.
if ( count > 0 )
return;
count++;
wxMemoryDC mem_dc;
for ( wxNode *node = m_tools.First(); node; node = node->Next() )
{
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
if (tool->m_toolStyle == wxTOOL_STYLE_BUTTON)
DrawTool(dc, mem_dc, tool);
}
count--;
}
void wxToolBarSimple::OnSize ( wxSizeEvent& event )
{
wxToolBarBase::OnSize(event);
}
void wxToolBarSimple::OnKillFocus (wxFocusEvent& WXUNUSED(event))
{
OnMouseEnter(m_pressedTool = m_currentTool = -1);
}
void wxToolBarSimple::OnMouseEvent ( wxMouseEvent & event )
{
wxCoord x, y;
event.GetPosition(&x, &y);
wxToolBarTool *tool = FindToolForPosition(x, y);
if (event.LeftDown())
{
CaptureMouse();
}
if (event.LeftUp())
{
ReleaseMouse();
}
if (!tool)
{
if (m_currentTool > -1)
{
if (event.LeftIsDown())
SpringUpButton(m_currentTool);
m_currentTool = -1;
OnMouseEnter(-1);
}
return;
}
if (!event.IsButton())
{
if (tool->m_index != m_currentTool)
{
// If the left button is kept down and moved over buttons,
// press those buttons.
if (event.LeftIsDown() && tool->m_enabled)
{
SpringUpButton(m_currentTool);
tool->m_toggleState = !tool->m_toggleState;
wxMemoryDC *dc2 = new wxMemoryDC;
wxClientDC dc(this);
DrawTool(dc, *dc2, tool);
delete dc2;
}
m_currentTool = tool->m_index;
OnMouseEnter(tool->m_index);
}
return;
}
// Left button pressed.
if (event.LeftDown() && tool->m_enabled)
{
if (tool->m_isToggle)
{
tool->m_toggleState = !tool->m_toggleState;
}
wxMemoryDC *dc2 = new wxMemoryDC;
wxClientDC dc(this);
DrawTool(dc, *dc2, tool);
delete dc2;
}
else if (event.RightDown())
{
OnRightClick(tool->m_index, x, y);
}
// Left Button Released. Only this action confirms selection.
// If the button is enabled and it is not a toggle tool and it is
// in the pressed state, then raise the button and call OnLeftClick.
//
if (event.LeftUp() && tool->m_enabled &&
(tool->m_toggleState || tool->m_isToggle))
{
if (!tool->m_isToggle)
tool->m_toggleState = FALSE;
// Pass the OnLeftClick event to tool
if (!OnLeftClick(tool->m_index, tool->m_toggleState) && tool->m_isToggle)
{
// If it was a toggle, and OnLeftClick says No Toggle allowed,
// then change it back
tool->m_toggleState = !tool->m_toggleState;
}
wxClientDC dc(this);
wxMemoryDC *dc2 = new wxMemoryDC;
DrawTool(dc, *dc2, tool);
delete dc2;
}
}
void wxToolBarSimple::DrawTool(wxDC& dc, wxMemoryDC& memDC, wxToolBarTool *tool)
{
PrepareDC(dc);
wxPen dark_grey_pen(wxColour( 85,85,85 ), 1, wxSOLID);
wxPen white_pen("WHITE", 1, wxSOLID);
wxPen black_pen("BLACK", 1, wxSOLID);
wxBitmap *bitmap = tool->m_toggleState ? (& tool->m_bitmap2) : (& tool->m_bitmap1);
if (bitmap && bitmap->Ok())
{
#ifndef __WXGTK__
if (bitmap->GetPalette())
memDC.SetPalette(*bitmap->GetPalette());
#endif
int ax = (int)tool->m_x,
ay = (int)tool->m_y,
bx = (int)(tool->m_x+tool->GetWidth()),
by = (int)(tool->m_y+tool->GetHeight());
memDC.SelectObject(*bitmap);
if (m_windowStyle & wxTB_3DBUTTONS)
{
dc.SetClippingRegion(ax, ay, (bx-ax+1), (by-ay+1));
dc.Blit((ax+1), (ay+1), (bx-ax-2), (by-ay-2), &memDC, 0, 0);
wxPen * old_pen = & dc.GetPen();
dc.SetPen( white_pen );
dc.DrawLine(ax,(by-1),ax,ay);
dc.DrawLine(ax,ay,(bx-1),ay);
dc.SetPen( dark_grey_pen );
dc.DrawLine((bx-1),(ay+1),(bx-1),(by-1));
dc.DrawLine((bx-1),(by-1),(ax+1),(by-1));
dc.SetPen( black_pen );
dc.DrawLine(bx,ay,bx,by);
dc.DrawLine(bx,by,ax,by);
dc.SetPen( *old_pen );
dc.DestroyClippingRegion();
// Select bitmap out of the DC
}
else
{
dc.Blit(tool->m_x, tool->m_y,
bitmap->GetWidth(), bitmap->GetHeight(),
&memDC, 0, 0);
}
memDC.SelectObject(wxNullBitmap);
#ifndef __WXGTK__
memDC.SetPalette(wxNullPalette);
#endif
}
// No second bitmap, so draw a thick line around bitmap, or invert if mono
else if (tool->m_toggleState)
{
bool drawBorder = FALSE;
#ifdef __X__ // X doesn't invert properly on colour
drawBorder = wxColourDisplay();
#else // Inversion works fine under Windows
drawBorder = FALSE;
#endif
if (!drawBorder)
{
memDC.SelectObject(tool->m_bitmap1);
dc.Blit(tool->m_x, tool->m_y, tool->GetWidth(), tool->GetHeight(),
&memDC, 0, 0, wxSRC_INVERT);
memDC.SelectObject(wxNullBitmap);
}
else
{
if (m_windowStyle & wxTB_3DBUTTONS)
{
int ax = (int)tool->m_x,
ay = (int)tool->m_y,
bx = (int)(tool->m_x+tool->GetWidth()),
by = (int)(tool->m_y+tool->GetHeight());
memDC.SelectObject(tool->m_bitmap1);
dc.SetClippingRegion(ax, ay, (bx-ax+1), (by-ay+1));
dc.Blit((ax+2), (ay+2), (bx-ax-2), (by-ay-2), &memDC, 0, 0);
wxPen * old_pen = & dc.GetPen();
dc.SetPen( black_pen );
dc.DrawLine(ax,(by-1),ax,ay);
dc.DrawLine(ax,ay,(bx-1),ay);
dc.SetPen( dark_grey_pen );
dc.DrawLine((ax+1),(by-2),(ax+1),(ay+1));
dc.DrawLine((ax+1),(ay+1),(bx-2),(ay+1));
dc.SetPen( white_pen );
dc.DrawLine(bx,ay,bx,by);
dc.DrawLine(bx,by,ax,by);
dc.SetPen( *old_pen );
dc.DestroyClippingRegion();
memDC.SelectObject(wxNullBitmap);
}
else
{
long x = tool->m_x;
long y = tool->m_y;
long w = tool->m_bitmap1.GetWidth();
long h = tool->m_bitmap1.GetHeight();
wxPen thick_black_pen("BLACK", 3, wxSOLID);
memDC.SelectObject(tool->m_bitmap1);
dc.SetClippingRegion(tool->m_x, tool->m_y, w, h);
dc.Blit(tool->m_x, tool->m_y, w, h,
&memDC, 0, 0);
dc.SetPen(thick_black_pen);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(x, y, w-1, h-1);
dc.DestroyClippingRegion();
memDC.SelectObject(wxNullBitmap);
}
}
}
}
void wxToolBarSimple::ToggleTool(int index, bool toggle)
{
wxNode *node = (wxNode*) NULL;
node = m_tools.Find((long)index);
if (node)
{
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
if (tool && tool->m_isToggle)
{
bool oldState = tool->m_toggleState;
tool->m_toggleState = toggle;
if (oldState != toggle)
{
wxMemoryDC memDC;
wxClientDC dc(this);
DrawTool(dc, memDC, tool);
}
}
}
}
// Okay, so we've left the tool we're in ... we must check if
// the tool we're leaving was a 'sprung push button' and if so,
// spring it back to the up state.
//
void wxToolBarSimple::SpringUpButton(int index)
{
wxNode *node = (wxNode*) NULL;
node=m_tools.Find((long)index);
if (node) {
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
if (tool && !tool->m_isToggle && tool->m_toggleState){
tool->m_toggleState = FALSE;
wxMemoryDC memDC;
wxClientDC dc(this);
DrawTool(dc, memDC, tool);
}
else if (tool && tool->m_isToggle){
tool->m_toggleState = !tool->m_toggleState;
wxMemoryDC memDC;
wxClientDC dc(this);
DrawTool(dc, memDC, tool);
}
}
}
void wxToolBarSimple::LayoutTools(void)
{
m_currentRowsOrColumns = 0;
m_lastX = m_xMargin;
m_lastY = m_yMargin;
int maxToolWidth = 0;
int maxToolHeight = 0;
m_maxWidth = 0;
m_maxHeight = 0;
// Find the maximum tool width and height
wxNode *node = m_tools.First();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
if (tool->GetWidth() > maxToolWidth)
maxToolWidth = (int)tool->GetWidth();
if (tool->GetHeight() > maxToolHeight)
maxToolHeight = (int)tool->GetHeight();
node = node->Next();
}
int separatorSize = m_toolSeparation;
node = m_tools.First();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
if (tool->m_toolStyle == wxTOOL_STYLE_SEPARATOR)
{
if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
{
if (m_currentRowsOrColumns >= m_maxCols)
m_lastY += separatorSize;
else
m_lastX += separatorSize;
}
else
{
if (m_currentRowsOrColumns >= m_maxRows)
m_lastX += separatorSize;
else
m_lastY += separatorSize;
}
}
else if (tool->m_toolStyle == wxTOOL_STYLE_BUTTON)
{
if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
{
if (m_currentRowsOrColumns >= m_maxCols)
{
m_currentRowsOrColumns = 0;
m_lastX = m_xMargin;
m_lastY += maxToolHeight + m_toolPacking;
}
tool->m_x = (long) (m_lastX + (maxToolWidth - tool->GetWidth())/2.0);
tool->m_y = (long) (m_lastY + (maxToolHeight - tool->GetHeight())/2.0);
m_lastX += maxToolWidth + m_toolPacking;
}
else
{
if (m_currentRowsOrColumns >= m_maxRows)
{
m_currentRowsOrColumns = 0;
m_lastX += (maxToolWidth + m_toolPacking);
m_lastY = m_yMargin;
}
tool->m_x = (long) (m_lastX + (maxToolWidth - tool->GetWidth())/2.0);
tool->m_y = (long) (m_lastY + (maxToolHeight - tool->GetHeight())/2.0);
m_lastY += maxToolHeight + m_toolPacking;
}
m_currentRowsOrColumns ++;
}
if (m_lastX > m_maxWidth)
m_maxWidth = m_lastX;
if (m_lastY > m_maxHeight)
m_maxHeight = m_lastY;
node = node->Next();
}
if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
m_maxWidth += maxToolWidth;
else
m_maxHeight += maxToolHeight;
m_maxWidth += m_xMargin;
m_maxHeight += m_yMargin;
}
#endif

992
src/generic/tbarsmpl.cpp Normal file
View File

@ -0,0 +1,992 @@
/////////////////////////////////////////////////////////////////////////////
// Name: generic/tbarsmpl.cpp
// Purpose: wxToolBarSimple
// Author: Julian Smart
// Modified by: VZ on 14.12.99 during wxToolBarSimple reorganization
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__
#pragma implementation "tbarsmpl.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#if wxUSE_TOOLBAR_SIMPLE
#ifndef WX_PRECOMP
#include "wx/settings.h"
#include "wx/window.h"
#include "wx/dcclient.h"
#include "wx/dcmemory.h"
#endif
#include "wx/tbarsmpl.h"
// ----------------------------------------------------------------------------
// private classes
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxToolBarToolSimple : public wxToolBarToolBase
{
public:
wxToolBarToolSimple(wxToolBarSimple *tbar,
int id,
const wxBitmap& bitmap1,
const wxBitmap& bitmap2,
bool toggle,
wxObject *clientData,
const wxString& shortHelpString,
const wxString& longHelpString)
: wxToolBarToolBase(tbar, id, bitmap1, bitmap2, toggle,
clientData, shortHelpString, longHelpString)
{
}
wxToolBarToolSimple(wxToolBarSimple *tbar, wxControl *control)
: wxToolBarToolBase(tbar, control)
{
}
void SetSize(const wxSize& size)
{
m_width = size.x;
m_height = size.y;
}
long GetWidth() const { return m_width; }
long GetHeight() const { return m_height; }
wxCoord m_x;
wxCoord m_y;
wxCoord m_width;
wxCoord m_height;
};
// ----------------------------------------------------------------------------
// wxWin macros
// ----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxToolBarSimple, wxControl)
BEGIN_EVENT_TABLE(wxToolBarSimple, wxToolBarBase)
EVT_SIZE(wxToolBarSimple::OnSize)
EVT_SCROLL(wxToolBarSimple::OnScroll)
EVT_PAINT(wxToolBarSimple::OnPaint)
EVT_KILL_FOCUS(wxToolBarSimple::OnKillFocus)
EVT_MOUSE_EVENTS(wxToolBarSimple::OnMouseEvent)
END_EVENT_TABLE()
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// tool bar tools creation
// ----------------------------------------------------------------------------
wxToolBarToolBase *wxToolBarSimple::CreateTool(int id,
const wxBitmap& bitmap1,
const wxBitmap& bitmap2,
bool toggle,
wxObject *clientData,
const wxString& shortHelpString,
const wxString& longHelpString)
{
return new wxToolBarToolSimple(this, id, bitmap1, bitmap2, toggle,
clientData, shortHelpString, longHelpString);
}
wxToolBarToolBase *wxToolBarSimple::CreateTool(wxControl *control)
{
return new wxToolBarToolSimple(this, control);
}
// ----------------------------------------------------------------------------
// wxToolBarSimple creation
// ----------------------------------------------------------------------------
void wxToolBarSimple::Init()
{
m_currentRowsOrColumns = 0;
m_lastX =
m_lastY = 0;
m_maxWidth =
m_maxHeight = 0;
m_pressedTool =
m_currentTool = -1;
m_xPos =
m_yPos = -1;
m_toolPacking = 1;
m_toolSeparation = 5;
m_defaultWidth = 16;
m_defaultHeight = 15;
}
wxToolBarToolBase *wxToolBarSimple::AddTool(int id,
const wxBitmap& bitmap,
const wxBitmap& pushedBitmap,
bool toggle,
wxCoord xPos,
wxCoord yPos,
wxObject *clientData,
const wxString& helpString1,
const wxString& helpString2)
{
// rememeber the position for DoInsertTool()
m_xPos = xPos;
m_yPos = yPos;
return wxToolBarBase::AddTool(id, bitmap, pushedBitmap, toggle,
xPos, yPos, clientData,
helpString1, helpString2);
}
bool wxToolBarSimple::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
{
wxToolBarToolSimple *tool = (wxToolBarToolSimple *)toolBase;
wxCHECK_MSG( !tool->IsControl(), FALSE,
_T("generic wxToolBarSimple doesn't support controls") );
tool->m_x = m_xPos;
if ( tool->m_x == -1 )
tool->m_x = m_xMargin;
tool->m_y = m_yPos;
if ( tool->m_y == -1 )
tool->m_y = m_yMargin;
tool->SetSize(GetToolSize());
if ( tool->IsButton() )
{
// Calculate reasonable max size in case Layout() not called
if ((tool->m_x + tool->GetBitmap1().GetWidth() + m_xMargin) > m_maxWidth)
m_maxWidth = (tool->m_x + tool->GetWidth() + m_xMargin);
if ((tool->m_y + tool->GetBitmap1().GetHeight() + m_yMargin) > m_maxHeight)
m_maxHeight = (tool->m_y + tool->GetHeight() + m_yMargin);
}
return TRUE;
}
bool wxToolBarSimple::DoDeleteTool(size_t WXUNUSED(pos),
wxToolBarToolBase *tool)
{
// VZ: didn't test whether it works, but why not...
tool->Detach();
Refresh();
return TRUE;
}
bool wxToolBarSimple::Create(wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{
if ( !wxWindow::Create(parent, id, pos, size, style, name) )
return FALSE;
// Set it to grey (or other 3D face colour)
wxSystemSettings settings;
SetBackgroundColour(settings.GetSystemColour(wxSYS_COLOUR_3DFACE));
if ( GetWindowStyleFlag() & wxTB_VERTICAL )
{
m_lastX = 7;
m_lastY = 3;
m_maxRows = 32000; // a lot
m_maxCols = 1;
}
else
{
m_lastX = 3;
m_lastY = 7;
m_maxRows = 1;
m_maxCols = 32000; // a lot
}
SetCursor(*wxSTANDARD_CURSOR);
return TRUE;
}
wxToolBarSimple::~wxToolBarSimple()
{
}
bool wxToolBarSimple::Realize()
{
m_currentRowsOrColumns = 0;
m_lastX = m_xMargin;
m_lastY = m_yMargin;
m_maxWidth = 0;
m_maxHeight = 0;
int maxToolWidth = 0;
int maxToolHeight = 0;
// Find the maximum tool width and height
wxToolBarToolsList::Node *node = m_tools.GetFirst();
while ( node )
{
wxToolBarToolSimple *tool = (wxToolBarToolSimple *)node->GetData();
if ( tool->GetWidth() > maxToolWidth )
maxToolWidth = tool->GetWidth();
if (tool->GetHeight() > maxToolHeight)
maxToolHeight = tool->GetHeight();
node = node->GetNext();
}
int separatorSize = m_toolSeparation;
node = m_tools.GetFirst();
while ( node )
{
wxToolBarToolSimple *tool = (wxToolBarToolSimple *)node->GetData();
if ( tool->IsSeparator() )
{
if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
{
if (m_currentRowsOrColumns >= m_maxCols)
m_lastY += separatorSize;
else
m_lastX += separatorSize;
}
else
{
if (m_currentRowsOrColumns >= m_maxRows)
m_lastX += separatorSize;
else
m_lastY += separatorSize;
}
}
else if ( tool->IsButton() )
{
if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
{
if (m_currentRowsOrColumns >= m_maxCols)
{
m_currentRowsOrColumns = 0;
m_lastX = m_xMargin;
m_lastY += maxToolHeight + m_toolPacking;
}
tool->m_x = (long) (m_lastX + (maxToolWidth - tool->GetWidth())/2.0);
tool->m_y = (long) (m_lastY + (maxToolHeight - tool->GetHeight())/2.0);
m_lastX += maxToolWidth + m_toolPacking;
}
else
{
if (m_currentRowsOrColumns >= m_maxRows)
{
m_currentRowsOrColumns = 0;
m_lastX += (maxToolWidth + m_toolPacking);
m_lastY = m_yMargin;
}
tool->m_x = (long) (m_lastX + (maxToolWidth - tool->GetWidth())/2.0);
tool->m_y = (long) (m_lastY + (maxToolHeight - tool->GetHeight())/2.0);
m_lastY += maxToolHeight + m_toolPacking;
}
m_currentRowsOrColumns ++;
}
else
{
// TODO: support the controls
}
if (m_lastX > m_maxWidth)
m_maxWidth = m_lastX;
if (m_lastY > m_maxHeight)
m_maxHeight = m_lastY;
node = node->GetNext();
}
if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
m_maxWidth += maxToolWidth;
else
m_maxHeight += maxToolHeight;
m_maxWidth += m_xMargin;
m_maxHeight += m_yMargin;
return TRUE;
}
// ----------------------------------------------------------------------------
// event handlers
// ----------------------------------------------------------------------------
void wxToolBarSimple::OnPaint (wxPaintEvent& WXUNUSED(event))
{
wxPaintDC dc(this);
PrepareDC(dc);
static int count = 0;
// Prevent reentry of OnPaint which would cause wxMemoryDC errors.
if ( count > 0 )
return;
count++;
for ( wxToolBarToolsList::Node *node = m_tools.GetFirst();
node;
node = node->GetNext() )
{
wxToolBarToolBase *tool = node->GetData();
if ( tool->IsButton() )
DrawTool(dc, tool);
}
count--;
}
void wxToolBarSimple::OnSize (wxSizeEvent& WXUNUSED(event))
{
#if wxUSE_CONSTRAINTS
if (GetAutoLayout())
Layout();
#endif
AdjustScrollbars();
}
void wxToolBarSimple::OnKillFocus(wxFocusEvent& WXUNUSED(event))
{
OnMouseEnter(m_pressedTool = m_currentTool = -1);
}
void wxToolBarSimple::OnMouseEvent(wxMouseEvent & event)
{
wxCoord x, y;
event.GetPosition(&x, &y);
wxToolBarToolSimple *tool = (wxToolBarToolSimple *)FindToolForPosition(x, y);
if (event.LeftDown())
{
CaptureMouse();
}
if (event.LeftUp())
{
ReleaseMouse();
}
if (!tool)
{
if (m_currentTool > -1)
{
if (event.LeftIsDown())
SpringUpButton(m_currentTool);
m_currentTool = -1;
OnMouseEnter(-1);
}
return;
}
if (!event.IsButton())
{
if ( tool->GetId() != m_currentTool )
{
// If the left button is kept down and moved over buttons,
// press those buttons.
if ( event.LeftIsDown() && tool->IsEnabled() )
{
SpringUpButton(m_currentTool);
if ( tool->CanBeToggled() )
{
tool->Toggle();
}
DrawTool(tool);
}
m_currentTool = tool->GetId();
OnMouseEnter(m_currentTool);
}
return;
}
// Left button pressed.
if ( event.LeftDown() && tool->IsEnabled() )
{
if ( tool->CanBeToggled() )
{
tool->Toggle();
}
DrawTool(tool);
}
else if (event.RightDown())
{
OnRightClick(tool->GetId(), x, y);
}
// Left Button Released. Only this action confirms selection.
// If the button is enabled and it is not a toggle tool and it is
// in the pressed state, then raise the button and call OnLeftClick.
//
if ( event.LeftUp() && tool->IsEnabled() )
{
// Pass the OnLeftClick event to tool
if ( !OnLeftClick(tool->GetId(), tool->IsToggled()) &&
tool->CanBeToggled() )
{
// If it was a toggle, and OnLeftClick says No Toggle allowed,
// then change it back
tool->Toggle();
}
DrawTool(tool);
}
}
// ----------------------------------------------------------------------------
// drawing
// ----------------------------------------------------------------------------
void wxToolBarSimple::DrawTool(wxToolBarToolBase *tool)
{
wxClientDC dc(this);
DrawTool(dc, tool);
}
void wxToolBarSimple::DrawTool(wxDC& dc, wxToolBarToolBase *toolBase)
{
wxToolBarToolSimple *tool = (wxToolBarToolSimple *)toolBase;
wxMemoryDC memDC;
PrepareDC(dc);
wxPen dark_grey_pen(wxColour( 85,85,85 ), 1, wxSOLID);
wxPen white_pen("WHITE", 1, wxSOLID);
wxPen black_pen("BLACK", 1, wxSOLID);
wxBitmap bitmap = tool->GetBitmap();
if ( bitmap.Ok() )
{
#ifndef __WXGTK__
if (bitmap.GetPalette())
memDC.SetPalette(*bitmap.GetPalette());
#endif
int ax = (int)tool->m_x,
ay = (int)tool->m_y,
bx = (int)(tool->m_x+tool->GetWidth()),
by = (int)(tool->m_y+tool->GetHeight());
memDC.SelectObject(bitmap);
if (m_windowStyle & wxTB_3DBUTTONS)
{
dc.SetClippingRegion(ax, ay, (bx-ax+1), (by-ay+1));
dc.Blit((ax+1), (ay+1), (bx-ax-2), (by-ay-2), &memDC, 0, 0);
wxPen * old_pen = & dc.GetPen();
dc.SetPen( white_pen );
dc.DrawLine(ax,(by-1),ax,ay);
dc.DrawLine(ax,ay,(bx-1),ay);
dc.SetPen( dark_grey_pen );
dc.DrawLine((bx-1),(ay+1),(bx-1),(by-1));
dc.DrawLine((bx-1),(by-1),(ax+1),(by-1));
dc.SetPen( black_pen );
dc.DrawLine(bx,ay,bx,by);
dc.DrawLine(bx,by,ax,by);
dc.SetPen( *old_pen );
dc.DestroyClippingRegion();
// Select bitmap out of the DC
}
else
{
dc.Blit(tool->m_x, tool->m_y,
bitmap.GetWidth(), bitmap.GetHeight(),
&memDC, 0, 0);
}
memDC.SelectObject(wxNullBitmap);
#ifndef __WXGTK__
memDC.SetPalette(wxNullPalette);
#endif
}
// No second bitmap, so draw a thick line around bitmap, or invert if mono
else if ( tool->IsToggled() )
{
bool drawBorder = FALSE;
#ifdef __X__ // X doesn't invert properly on colour
drawBorder = wxColourDisplay();
#else // Inversion works fine under Windows
drawBorder = FALSE;
#endif
if (!drawBorder)
{
memDC.SelectObject(tool->GetBitmap1());
dc.Blit(tool->m_x, tool->m_y, tool->GetWidth(), tool->GetHeight(),
&memDC, 0, 0, wxSRC_INVERT);
memDC.SelectObject(wxNullBitmap);
}
else
{
bitmap = tool->GetBitmap1();
if (m_windowStyle & wxTB_3DBUTTONS)
{
int ax = (int)tool->m_x,
ay = (int)tool->m_y,
bx = (int)(tool->m_x+tool->GetWidth()),
by = (int)(tool->m_y+tool->GetHeight());
memDC.SelectObject(bitmap);
dc.SetClippingRegion(ax, ay, (bx-ax+1), (by-ay+1));
dc.Blit((ax+2), (ay+2), (bx-ax-2), (by-ay-2), &memDC, 0, 0);
wxPen * old_pen = & dc.GetPen();
dc.SetPen( black_pen );
dc.DrawLine(ax,(by-1),ax,ay);
dc.DrawLine(ax,ay,(bx-1),ay);
dc.SetPen( dark_grey_pen );
dc.DrawLine((ax+1),(by-2),(ax+1),(ay+1));
dc.DrawLine((ax+1),(ay+1),(bx-2),(ay+1));
dc.SetPen( white_pen );
dc.DrawLine(bx,ay,bx,by);
dc.DrawLine(bx,by,ax,by);
dc.SetPen( *old_pen );
dc.DestroyClippingRegion();
memDC.SelectObject(wxNullBitmap);
}
else
{
long x = tool->m_x;
long y = tool->m_y;
long w = bitmap.GetWidth();
long h = bitmap.GetHeight();
wxPen thick_black_pen("BLACK", 3, wxSOLID);
memDC.SelectObject(bitmap);
dc.SetClippingRegion(tool->m_x, tool->m_y, w, h);
dc.Blit(tool->m_x, tool->m_y, w, h,
&memDC, 0, 0);
dc.SetPen(thick_black_pen);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(x, y, w-1, h-1);
dc.DestroyClippingRegion();
memDC.SelectObject(wxNullBitmap);
}
}
}
}
// ----------------------------------------------------------------------------
// toolbar geometry
// ----------------------------------------------------------------------------
void wxToolBarSimple::SetRows(int nRows)
{
wxCHECK_RET( nRows != 0, _T("max number of rows must be > 0") );
m_maxCols = (GetToolsCount() + nRows - 1) / nRows;
AdjustScrollbars();
Refresh();
}
wxToolBarToolBase *wxToolBarSimple::FindToolForPosition(wxCoord x,
wxCoord y) const
{
wxToolBarToolsList::Node *node = m_tools.GetFirst();
while (node)
{
wxToolBarToolSimple *tool = (wxToolBarToolSimple *)node->GetData();
if ((x >= tool->m_x) && (y >= tool->m_y) &&
(x <= (tool->m_x + tool->GetWidth())) &&
(y <= (tool->m_y + tool->GetHeight())))
{
return tool;
}
node = node->GetNext();
}
return (wxToolBarToolBase *)NULL;
}
// ----------------------------------------------------------------------------
// tool state change handlers
// ----------------------------------------------------------------------------
void wxToolBarSimple::DoEnableTool(wxToolBarToolBase *tool,
bool WXUNUSED(enable))
{
DrawTool(tool);
}
void wxToolBarSimple::DoToggleTool(wxToolBarToolBase *tool,
bool WXUNUSED(toggle))
{
DrawTool(tool);
}
void wxToolBarSimple::DoSetToggle(wxToolBarToolBase * WXUNUSED(tool),
bool WXUNUSED(toggle))
{
// nothing to do
}
// Okay, so we've left the tool we're in ... we must check if the tool we're
// leaving was a 'sprung push button' and if so, spring it back to the up
// state.
void wxToolBarSimple::SpringUpButton(int id)
{
wxToolBarToolBase *tool = FindById(id);
if ( tool && tool->CanBeToggled() )
{
tool->Toggle();
DrawTool(tool);
}
}
// ----------------------------------------------------------------------------
// scrolling implementation
// ----------------------------------------------------------------------------
/*
* pixelsPerUnitX/pixelsPerUnitY: number of pixels per unit (e.g. pixels per text line)
* noUnitsX/noUnitsY: : no. units per scrollbar
*/
void wxToolBarSimple::SetScrollbars (int pixelsPerUnitX, int pixelsPerUnitY,
int noUnitsX, int noUnitsY,
int xPos, int yPos)
{
m_xScrollPixelsPerLine = pixelsPerUnitX;
m_yScrollPixelsPerLine = pixelsPerUnitY;
m_xScrollLines = noUnitsX;
m_yScrollLines = noUnitsY;
int w, h;
GetSize(&w, &h);
// Recalculate scroll bar range and position
if (m_xScrollLines > 0)
{
m_xScrollPosition = xPos;
SetScrollPos (wxHORIZONTAL, m_xScrollPosition, TRUE);
}
else
{
SetScrollbar(wxHORIZONTAL, 0, 0, 0, FALSE);
m_xScrollPosition = 0;
}
if (m_yScrollLines > 0)
{
m_yScrollPosition = yPos;
SetScrollPos (wxVERTICAL, m_yScrollPosition, TRUE);
}
else
{
SetScrollbar(wxVERTICAL, 0, 0, 0, FALSE);
m_yScrollPosition = 0;
}
AdjustScrollbars();
Refresh();
#if 0 //def __WXMSW__
::UpdateWindow ((HWND) GetHWND());
#endif
}
void wxToolBarSimple::OnScroll(wxScrollEvent& event)
{
int orient = event.GetOrientation();
int nScrollInc = CalcScrollInc(event);
if (nScrollInc == 0)
return;
if (orient == wxHORIZONTAL)
{
int newPos = m_xScrollPosition + nScrollInc;
SetScrollPos(wxHORIZONTAL, newPos, TRUE );
}
else
{
int newPos = m_yScrollPosition + nScrollInc;
SetScrollPos(wxVERTICAL, newPos, TRUE );
}
if (orient == wxHORIZONTAL)
{
if (m_xScrollingEnabled)
ScrollWindow(-m_xScrollPixelsPerLine * nScrollInc, 0, NULL);
else
Refresh();
}
else
{
if (m_yScrollingEnabled)
ScrollWindow(0, -m_yScrollPixelsPerLine * nScrollInc, NULL);
else
Refresh();
}
if (orient == wxHORIZONTAL)
{
m_xScrollPosition += nScrollInc;
}
else
{
m_yScrollPosition += nScrollInc;
}
}
int wxToolBarSimple::CalcScrollInc(wxScrollEvent& event)
{
int pos = event.GetPosition();
int orient = event.GetOrientation();
int nScrollInc = 0;
switch (event.GetEventType())
{
case wxEVT_SCROLL_TOP:
{
if (orient == wxHORIZONTAL)
nScrollInc = - m_xScrollPosition;
else
nScrollInc = - m_yScrollPosition;
break;
}
case wxEVT_SCROLL_BOTTOM:
{
if (orient == wxHORIZONTAL)
nScrollInc = m_xScrollLines - m_xScrollPosition;
else
nScrollInc = m_yScrollLines - m_yScrollPosition;
break;
}
case wxEVT_SCROLL_LINEUP:
{
nScrollInc = -1;
break;
}
case wxEVT_SCROLL_LINEDOWN:
{
nScrollInc = 1;
break;
}
case wxEVT_SCROLL_PAGEUP:
{
if (orient == wxHORIZONTAL)
nScrollInc = -GetScrollPageSize(wxHORIZONTAL);
else
nScrollInc = -GetScrollPageSize(wxVERTICAL);
break;
}
case wxEVT_SCROLL_PAGEDOWN:
{
if (orient == wxHORIZONTAL)
nScrollInc = GetScrollPageSize(wxHORIZONTAL);
else
nScrollInc = GetScrollPageSize(wxVERTICAL);
break;
}
case wxEVT_SCROLL_THUMBTRACK:
{
if (orient == wxHORIZONTAL)
nScrollInc = pos - m_xScrollPosition;
else
nScrollInc = pos - m_yScrollPosition;
break;
}
default:
{
break;
}
}
if (orient == wxHORIZONTAL)
{
int w, h;
GetClientSize(&w, &h);
int nMaxWidth = m_xScrollLines*m_xScrollPixelsPerLine;
int noPositions = (int) ( ((nMaxWidth - w)/(float)m_xScrollPixelsPerLine) + 0.5 );
if (noPositions < 0)
noPositions = 0;
if ( (m_xScrollPosition + nScrollInc) < 0 )
nScrollInc = -m_xScrollPosition; // As -ve as we can go
else if ( (m_xScrollPosition + nScrollInc) > noPositions )
nScrollInc = noPositions - m_xScrollPosition; // As +ve as we can go
return nScrollInc;
}
else
{
int w, h;
GetClientSize(&w, &h);
int nMaxHeight = m_yScrollLines*m_yScrollPixelsPerLine;
int noPositions = (int) ( ((nMaxHeight - h)/(float)m_yScrollPixelsPerLine) + 0.5 );
if (noPositions < 0)
noPositions = 0;
if ( (m_yScrollPosition + nScrollInc) < 0 )
nScrollInc = -m_yScrollPosition; // As -ve as we can go
else if ( (m_yScrollPosition + nScrollInc) > noPositions )
nScrollInc = noPositions - m_yScrollPosition; // As +ve as we can go
return nScrollInc;
}
}
// Adjust the scrollbars - new version.
void wxToolBarSimple::AdjustScrollbars()
{
int w, h;
GetClientSize(&w, &h);
// Recalculate scroll bar range and position
if (m_xScrollLines > 0)
{
int nMaxWidth = m_xScrollLines*m_xScrollPixelsPerLine;
int newRange = (int) ( ((nMaxWidth)/(float)m_xScrollPixelsPerLine) + 0.5 );
if (newRange < 0)
newRange = 0;
m_xScrollPosition = wxMin(newRange, m_xScrollPosition);
// Calculate page size i.e. number of scroll units you get on the
// current client window
int noPagePositions = (int) ( (w/(float)m_xScrollPixelsPerLine) + 0.5 );
if (noPagePositions < 1)
noPagePositions = 1;
SetScrollbar(wxHORIZONTAL, m_xScrollPosition, noPagePositions, newRange);
SetScrollPageSize(wxHORIZONTAL, noPagePositions);
}
if (m_yScrollLines > 0)
{
int nMaxHeight = m_yScrollLines*m_yScrollPixelsPerLine;
int newRange = (int) ( ((nMaxHeight)/(float)m_yScrollPixelsPerLine) + 0.5 );
if (newRange < 0)
newRange = 0;
m_yScrollPosition = wxMin(newRange, m_yScrollPosition);
// Calculate page size i.e. number of scroll units you get on the
// current client window
int noPagePositions = (int) ( (h/(float)m_yScrollPixelsPerLine) + 0.5 );
if (noPagePositions < 1)
noPagePositions = 1;
SetScrollbar(wxVERTICAL, m_yScrollPosition, noPagePositions, newRange);
SetScrollPageSize(wxVERTICAL, noPagePositions);
}
}
// Prepare the DC by translating it according to the current scroll position
void wxToolBarSimple::PrepareDC(wxDC& dc)
{
dc.SetDeviceOrigin(- m_xScrollPosition * m_xScrollPixelsPerLine, - m_yScrollPosition * m_yScrollPixelsPerLine);
}
void wxToolBarSimple::GetScrollPixelsPerUnit (int *x_unit, int *y_unit) const
{
*x_unit = m_xScrollPixelsPerLine;
*y_unit = m_yScrollPixelsPerLine;
}
int wxToolBarSimple::GetScrollPageSize(int orient) const
{
if ( orient == wxHORIZONTAL )
return m_xScrollLinesPerPage;
else
return m_yScrollLinesPerPage;
}
void wxToolBarSimple::SetScrollPageSize(int orient, int pageSize)
{
if ( orient == wxHORIZONTAL )
m_xScrollLinesPerPage = pageSize;
else
m_yScrollLinesPerPage = pageSize;
}
/*
* Scroll to given position (scroll position, not pixel position)
*/
void wxToolBarSimple::Scroll (int x_pos, int y_pos)
{
int old_x, old_y;
ViewStart (&old_x, &old_y);
if (((x_pos == -1) || (x_pos == old_x)) && ((y_pos == -1) || (y_pos == old_y)))
return;
if (x_pos > -1)
{
m_xScrollPosition = x_pos;
SetScrollPos (wxHORIZONTAL, x_pos, TRUE);
}
if (y_pos > -1)
{
m_yScrollPosition = y_pos;
SetScrollPos (wxVERTICAL, y_pos, TRUE);
}
Refresh();
#if 0 //def __WXMSW__
UpdateWindow ((HWND) GetHWND());
#endif
}
void wxToolBarSimple::EnableScrolling (bool x_scroll, bool y_scroll)
{
m_xScrollingEnabled = x_scroll;
m_yScrollingEnabled = y_scroll;
}
void wxToolBarSimple::GetVirtualSize (int *x, int *y) const
{
*x = m_xScrollPixelsPerLine * m_xScrollLines;
*y = m_yScrollPixelsPerLine * m_yScrollLines;
}
// Where the current view starts from
void wxToolBarSimple::ViewStart (int *x, int *y) const
{
*x = m_xScrollPosition;
*y = m_yScrollPosition;
}
#endif // wxUSE_TOOLBAR_SIMPLE

View File

@ -2,18 +2,27 @@
// Name: tbargtk.cpp
// Purpose: GTK toolbar
// Author: Robert Roebling
// Modified: 13.12.99 by VZ to derive from wxToolBarBase
// RCS-ID: $Id$
// Copyright: (c) Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__
#pragma implementation "tbargtk.h"
#pragma implementation "tbargtk.h"
#endif
#include "wx/toolbar.h"
#if wxUSE_TOOLBAR
#if wxUSE_TOOLBAR_NATIVE
#include "wx/frame.h"
@ -21,57 +30,99 @@
#include "gdk/gdk.h"
#include "gtk/gtk.h"
//-----------------------------------------------------------------------------
// idle system
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// globals
// ----------------------------------------------------------------------------
// idle system
extern void wxapp_install_idle_handler();
extern bool g_isIdle;
//-----------------------------------------------------------------------------
// data
//-----------------------------------------------------------------------------
extern bool g_blockEventsOnDrag;
extern wxCursor g_globalCursor;
// ----------------------------------------------------------------------------
// wxToolBarTool
// ----------------------------------------------------------------------------
class wxToolBarTool : public wxToolBarToolBase
{
public:
wxToolBarTool(wxToolBar *tbar,
int id,
const wxBitmap& bitmap1,
const wxBitmap& bitmap2,
bool toggle,
wxObject *clientData,
const wxString& shortHelpString,
const wxString& longHelpString)
: wxToolBarToolBase(tbar, id, bitmap1, bitmap2, toggle,
clientData, shortHelpString, longHelpString)
{
Init();
}
wxToolBarTool(wxToolBar *tbar, wxControl *control)
: wxToolBarToolBase(tbar, control)
{
Init();
}
GtkWidget *m_item;
GtkWidget *m_pixmap;
protected:
void Init();
};
// ----------------------------------------------------------------------------
// wxWin macros
// ----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
// ============================================================================
// implementation
// ============================================================================
//-----------------------------------------------------------------------------
// "clicked" (internal from gtk_toolbar)
//-----------------------------------------------------------------------------
static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget), wxToolBarTool *tool )
static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget),
wxToolBarTool *tool )
{
if (g_isIdle)
wxapp_install_idle_handler();
if (tool->m_owner->m_blockNextEvent)
wxToolBar *tbar = (wxToolBar *)tool->GetToolBar();
if ( tbar->m_blockNextEvent )
{
tool->m_owner->m_blockNextEvent = FALSE;
tbar->m_blockNextEvent = FALSE;
return;
}
if (g_blockEventsOnDrag) return;
if (!tool->m_enabled) return;
if (!tool->IsEnabled()) return;
if (tool->m_isToggle)
if (tool->CanBeToggled())
{
tool->m_toggleState = !tool->m_toggleState;
if (tool->m_bitmap2.Ok())
{
wxBitmap bitmap = tool->m_bitmap1;
if (tool->m_toggleState) bitmap = tool->m_bitmap2;
tool->Toggle();
wxBitmap bitmap = tool->GetBitmap();
if ( bitmap.Ok() )
{
GtkPixmap *pixmap = GTK_PIXMAP( tool->m_pixmap );
GdkBitmap *mask = (GdkBitmap *) NULL;
if (bitmap.GetMask()) mask = bitmap.GetMask()->GetBitmap();
GdkBitmap *mask = bitmap.GetMask() ? bitmap.GetMask()->GetBitmap()
: (GdkBitmap *)NULL;
gtk_pixmap_set( pixmap, bitmap.GetPixmap(), mask );
}
}
}
tool->m_owner->OnLeftClick( tool->m_index, tool->m_toggleState );
tbar->OnLeftClick( tool->GetId(), tool->IsToggled() );
}
//-----------------------------------------------------------------------------
@ -79,18 +130,18 @@ static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget), wxToolBarTool *to
//-----------------------------------------------------------------------------
static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget),
GdkEventCrossing *WXUNUSED(gdk_event), wxToolBarTool *tool )
GdkEventCrossing *WXUNUSED(gdk_event),
wxToolBarTool *tool )
{
if (g_isIdle) wxapp_install_idle_handler();
if (g_blockEventsOnDrag) return TRUE;
wxToolBar *tb = tool->m_owner;
wxToolBar *tb = (wxToolBar *)tool->GetToolBar();
#if (GTK_MINOR_VERSION == 0)
/* we grey-out the tip text of disabled tool in GTK 1.0 */
if (tool->m_enabled)
if (tool->IsEnabled())
{
if (tb->m_fg->red != 0)
{
@ -117,7 +168,7 @@ static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget),
/* emit the event */
tb->OnMouseEnter( tool->m_index );
tb->OnMouseEnter( tool->GetId() );
return FALSE;
}
@ -126,30 +177,51 @@ static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget),
// InsertChild callback for wxToolBar
//-----------------------------------------------------------------------------
static void wxInsertChildInToolBar( wxToolBar* WXUNUSED(parent), wxWindow* WXUNUSED(child) )
static void wxInsertChildInToolBar( wxToolBar* WXUNUSED(parent),
wxWindow* WXUNUSED(child) )
{
/* we don't do anything here but pray */
}
//-----------------------------------------------------------------------------
// wxToolBar
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// wxToolBarTool
// ----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxToolBar,wxControl)
BEGIN_EVENT_TABLE(wxToolBar, wxControl)
EVT_IDLE(wxToolBar::OnIdle)
END_EVENT_TABLE()
wxToolBar::wxToolBar()
void wxToolBarTool::Init()
{
m_item =
m_pixmap = (GtkWidget *)NULL;
}
wxToolBar::wxToolBar( wxWindow *parent, wxWindowID id,
const wxPoint& pos, const wxSize& size,
long style, const wxString& name )
wxToolBarToolBase *wxToolBar::CreateTool(int id,
const wxBitmap& bitmap1,
const wxBitmap& bitmap2,
bool toggle,
wxObject *clientData,
const wxString& shortHelpString,
const wxString& longHelpString)
{
Create( parent, id, pos, size, style, name );
return new wxToolBarTool(this, id, bitmap1, bitmap2, toggle,
clientData, shortHelpString, longHelpString);
}
wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control)
{
return new wxToolBarTool(this, control);
}
//-----------------------------------------------------------------------------
// wxToolBar construction
//-----------------------------------------------------------------------------
void wxToolBar::Init()
{
m_fg =
m_bg = (GdkColor *)NULL;
m_toolbar = (GtkToolbar *)NULL;
m_blockNextEvent = FALSE;
}
wxToolBar::~wxToolBar()
@ -158,36 +230,36 @@ wxToolBar::~wxToolBar()
delete m_bg;
}
bool wxToolBar::Create( wxWindow *parent, wxWindowID id,
const wxPoint& pos, const wxSize& size,
long style, const wxString& name )
bool wxToolBar::Create( wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name )
{
m_needParent = TRUE;
m_blockNextEvent = FALSE;
m_insertCallback = (wxInsertChildFunction)wxInsertChildInToolBar;
if (!PreCreation( parent, pos, size ) ||
!CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
if ( !PreCreation( parent, pos, size ) ||
!CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
{
wxFAIL_MSG( wxT("wxToolBar creation failed") );
return FALSE;
return FALSE;
}
m_tools.DeleteContents( TRUE );
GtkOrientation orient = style & wxTB_VERTICAL ? GTK_ORIENTATION_VERTICAL
: GTK_ORIENTATION_HORIZONTAL;
m_toolbar = GTK_TOOLBAR( gtk_toolbar_new( orient, GTK_TOOLBAR_ICONS ) );
m_toolbar = GTK_TOOLBAR( gtk_toolbar_new( GTK_ORIENTATION_HORIZONTAL,
GTK_TOOLBAR_ICONS ) );
m_separation = 7;
gtk_toolbar_set_space_size( m_toolbar, m_separation );
m_hasToolAlready = FALSE;
SetToolSeparation(7);
if (style & wxTB_DOCKABLE)
{
m_widget = gtk_handle_box_new();
gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) );
gtk_widget_show( GTK_WIDGET(m_toolbar) );
#if (GTK_MINOR_VERSION > 0)
if (style & wxTB_FLAT)
gtk_handle_box_set_shadow_type( GTK_HANDLE_BOX(m_widget), GTK_SHADOW_NONE );
@ -197,9 +269,9 @@ bool wxToolBar::Create( wxWindow *parent, wxWindowID id,
{
m_widget = GTK_WIDGET(m_toolbar);
}
gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), TRUE );
#if (GTK_MINOR_VERSION > 0)
if (style & wxTB_FLAT)
gtk_toolbar_set_button_relief( GTK_TOOLBAR(m_toolbar), GTK_RELIEF_NONE );
@ -210,32 +282,29 @@ bool wxToolBar::Create( wxWindow *parent, wxWindowID id,
m_fg->green = 0;
m_fg->blue = 0;
gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ), m_fg );
m_bg = new GdkColor;
m_bg->red = 65535;
m_bg->green = 65535;
m_bg->blue = 50000;
gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ), m_bg );
#if (GTK_MINOR_VERSION > 0)
gtk_tooltips_force_window( GTK_TOOLBAR(m_toolbar)->tooltips );
GtkStyle *g_style =
gtk_style_copy(
gtk_widget_get_style(
GTK_TOOLBAR(m_toolbar)->tooltips->tip_window ) );
gtk_style_copy(
gtk_widget_get_style(
GTK_TOOLBAR(m_toolbar)->tooltips->tip_window ) );
g_style->bg[GTK_STATE_NORMAL] = *m_bg;
gtk_widget_set_style( GTK_TOOLBAR(m_toolbar)->tooltips->tip_window, g_style );
#else
gtk_tooltips_set_colors( GTK_TOOLBAR(m_toolbar)->tooltips, m_bg, m_fg );
#endif
m_xMargin = 0;
m_yMargin = 0;
m_parent->DoAddChild( this );
PostCreation();
Show( TRUE );
@ -243,277 +312,182 @@ bool wxToolBar::Create( wxWindow *parent, wxWindowID id,
return TRUE;
}
bool wxToolBar::OnLeftClick( int toolIndex, bool toggleDown )
bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
{
wxCommandEvent event( wxEVT_COMMAND_TOOL_CLICKED, toolIndex );
event.SetEventObject(this);
event.SetInt( toolIndex );
event.SetExtraLong((long) toggleDown);
wxToolBarTool *tool = (wxToolBarTool *)toolBase;
GetEventHandler()->ProcessEvent(event);
return TRUE;
}
void wxToolBar::OnRightClick( int toolIndex, float WXUNUSED(x), float WXUNUSED(y) )
{
wxCommandEvent event( wxEVT_COMMAND_TOOL_RCLICKED, toolIndex );
event.SetEventObject( this );
event.SetInt( toolIndex );
GetEventHandler()->ProcessEvent(event);
}
void wxToolBar::OnMouseEnter( int toolIndex )
{
wxCommandEvent event( wxEVT_COMMAND_TOOL_ENTER, GetId() );
event.SetEventObject(this);
event.SetInt( toolIndex );
GetEventHandler()->ProcessEvent(event);
}
wxToolBarTool *wxToolBar::AddTool( int toolIndex, const wxBitmap& bitmap,
const wxBitmap& pushedBitmap, bool toggle,
wxCoord WXUNUSED(xPos), wxCoord WXUNUSED(yPos), wxObject *clientData,
const wxString& helpString1, const wxString& helpString2 )
{
m_hasToolAlready = TRUE;
wxCHECK_MSG( bitmap.Ok(), (wxToolBarTool *)NULL,
wxT("invalid bitmap for wxToolBar icon") );
wxCHECK_MSG( bitmap.GetBitmap() == NULL, (wxToolBarTool *)NULL,
wxT("wxToolBar doesn't support GdkBitmap") );
wxCHECK_MSG( bitmap.GetPixmap() != NULL, (wxToolBarTool *)NULL,
wxT("wxToolBar::Add needs a wxBitmap") );
GtkWidget *tool_pixmap = (GtkWidget *)NULL;
GdkPixmap *pixmap = bitmap.GetPixmap();
GdkBitmap *mask = (GdkBitmap *)NULL;
if ( bitmap.GetMask() )
mask = bitmap.GetMask()->GetBitmap();
tool_pixmap = gtk_pixmap_new( pixmap, mask );
#if (GTK_MINOR_VERSION > 0)
gtk_pixmap_set_build_insensitive( GTK_PIXMAP(tool_pixmap), TRUE );
#endif
gtk_misc_set_alignment( GTK_MISC(tool_pixmap), 0.5, 0.5 );
wxToolBarTool *tool = new wxToolBarTool( this, toolIndex, bitmap, pushedBitmap,
toggle, clientData,
helpString1, helpString2,
tool_pixmap );
GtkToolbarChildType ctype = toggle ? GTK_TOOLBAR_CHILD_TOGGLEBUTTON
: GTK_TOOLBAR_CHILD_BUTTON;
GtkWidget *item = gtk_toolbar_append_element
(
m_toolbar,
ctype,
(GtkWidget *)NULL,
(const char *)NULL,
helpString1.mbc_str(),
"",
tool_pixmap,
(GtkSignalFunc)gtk_toolbar_callback,
(gpointer)tool
);
tool->m_item = item;
GtkRequisition req;
(* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request ) (m_widget, &req );
m_width = req.width + m_xMargin;
m_height = req.height + 2*m_yMargin + 4;
gtk_signal_connect( GTK_OBJECT(tool->m_item),
"enter_notify_event",
GTK_SIGNAL_FUNC(gtk_toolbar_enter_callback),
(gpointer)tool );
m_tools.Append( tool );
return tool;
}
bool wxToolBar::AddControl(wxControl *control)
{
wxCHECK_MSG( control, FALSE, wxT("toolbar: can't insert NULL control") );
wxCHECK_MSG( control->GetParent() == this, FALSE,
wxT("control must have toolbar as parent") );
m_hasToolAlready = TRUE;
wxToolBarTool *tool = new wxToolBarTool(control);
tool -> m_item = NULL;
gtk_toolbar_append_widget( m_toolbar, control->m_widget, (const char *) NULL, (const char *) NULL );
GtkRequisition req;
(* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request ) (m_widget, &req );
m_width = req.width + m_xMargin;
m_height = req.height + 2*m_yMargin + 4;
m_tools.Append( tool );
return TRUE;
}
void wxToolBar::AddSeparator()
{
gtk_toolbar_append_space( m_toolbar );
}
bool wxToolBar::DeleteTool(int toolIndex)
{
wxNode *node = m_tools.First();
while (node)
if ( tool->IsButton() )
{
wxToolBarTool *tool = (wxToolBarTool*)node->Data();
if (tool->m_index == toolIndex)
{
if (tool->m_control)
tool->m_control->Destroy();
else
gtk_widget_destroy( tool->m_item );
m_tools.DeleteNode( node );
wxBitmap bitmap = tool->GetBitmap1();
wxCHECK_MSG( bitmap.Ok(), FALSE,
wxT("invalid bitmap for wxToolBar icon") );
wxCHECK_MSG( bitmap.GetBitmap() == NULL, FALSE,
wxT("wxToolBar doesn't support GdkBitmap") );
wxCHECK_MSG( bitmap.GetPixmap() != NULL, FALSE,
wxT("wxToolBar::Add needs a wxBitmap") );
GtkWidget *tool_pixmap = (GtkWidget *)NULL;
GdkPixmap *pixmap = bitmap.GetPixmap();
GdkBitmap *mask = (GdkBitmap *)NULL;
if ( bitmap.GetMask() )
mask = bitmap.GetMask()->GetBitmap();
tool_pixmap = gtk_pixmap_new( pixmap, mask );
#if (GTK_MINOR_VERSION > 0)
gtk_pixmap_set_build_insensitive( GTK_PIXMAP(tool_pixmap), TRUE );
#endif
gtk_misc_set_alignment( GTK_MISC(tool_pixmap), 0.5, 0.5 );
tool->m_pixmap = tool_pixmap;
}
switch ( tool->GetStyle() )
{
case wxTOOL_STYLE_BUTTON:
tool->m_item = gtk_toolbar_insert_element
(
m_toolbar,
tool->CanBeToggled()
? GTK_TOOLBAR_CHILD_TOGGLEBUTTON
: GTK_TOOLBAR_CHILD_BUTTON,
(GtkWidget *)NULL,
(const char *)NULL,
tool->GetShortHelp().mbc_str(),
"", // tooltip_private_text (?)
tool->m_pixmap,
(GtkSignalFunc)gtk_toolbar_callback,
(gpointer)tool,
pos
);
if ( !tool->m_item )
{
wxFAIL_MSG( _T("gtk_toolbar_insert_element() failed") );
return FALSE;
}
gtk_signal_connect( GTK_OBJECT(tool->m_item),
"enter_notify_event",
GTK_SIGNAL_FUNC(gtk_toolbar_enter_callback),
(gpointer)tool );
break;
case wxTOOL_STYLE_SEPARATOR:
gtk_toolbar_append_space( m_toolbar );
// skip the rest
return TRUE;
}
node = node->Next();
case wxTOOL_STYLE_CONTROL:
gtk_toolbar_insert_widget(
m_toolbar,
tool->GetControl()->m_widget,
(const char *) NULL,
(const char *) NULL,
pos
);
break;
}
return FALSE;
}
GtkRequisition req;
(* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request ) (m_widget, &req );
m_width = req.width + m_xMargin;
m_height = req.height + 2*m_yMargin + 4;
void wxToolBar::ClearTools()
{
wxFAIL_MSG( wxT("wxToolBar::ClearTools not implemented") );
}
bool wxToolBar::Realize()
{
return TRUE;
}
void wxToolBar::EnableTool(int toolIndex, bool enable)
bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *toolBase)
{
wxNode *node = m_tools.First();
while (node)
wxToolBarTool *tool = (wxToolBarTool *)toolBase;
switch ( tool->GetStyle() )
{
wxToolBarTool *tool = (wxToolBarTool*)node->Data();
if (tool->m_index == toolIndex)
{
tool->m_enabled = enable;
case wxTOOL_STYLE_CONTROL:
tool->GetControl()->Destroy();
break;
case wxTOOL_STYLE_BUTTON:
gtk_widget_destroy( tool->m_item );
break;
//case wxTOOL_STYLE_SEPARATOR: -- nothing to do
}
return TRUE;
}
// ----------------------------------------------------------------------------
// wxToolBar tools state
// ----------------------------------------------------------------------------
void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable)
{
#if (GTK_MINOR_VERSION > 0)
/* we don't disable the tools for GTK 1.0 as the bitmaps don't get
greyed anyway and this also disables tooltips */
if (tool->m_item)
gtk_widget_set_sensitive( tool->m_item, enable );
wxToolBarTool *tool = (wxToolBarTool *)toolBase;
/* we don't disable the tools for GTK 1.0 as the bitmaps don't get
greyed anyway and this also disables tooltips */
if (tool->m_item)
gtk_widget_set_sensitive( tool->m_item, enable );
#endif
return;
}
void wxToolBar::DoToggleTool( wxToolBarToolBase *toolBase, bool toggle )
{
wxToolBarTool *tool = (wxToolBarTool *)toolBase;
GtkWidget *item = tool->m_item;
if ( item && GTK_IS_TOGGLE_BUTTON(item) )
{
wxBitmap bitmap = tool->GetBitmap();
if ( bitmap.Ok() )
{
GtkPixmap *pixmap = GTK_PIXMAP( tool->m_pixmap );
GdkBitmap *mask = bitmap.GetMask() ? bitmap.GetMask()->GetBitmap()
: (GdkBitmap *)NULL;
gtk_pixmap_set( pixmap, bitmap.GetPixmap(), mask );
}
node = node->Next();
m_blockNextEvent = TRUE; // we cannot use gtk_signal_disconnect here
gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(item), toggle );
}
wxFAIL_MSG( wxT("wrong toolbar index") );
}
void wxToolBar::ToggleTool( int toolIndex, bool toggle )
void wxToolBar::DoSetToggle(wxToolBarToolBase * WXUNUSED(tool),
bool WXUNUSED(toggle))
{
wxNode *node = m_tools.First();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool*)node->Data();
if (tool->m_index == toolIndex)
{
if ((tool->m_item) && (GTK_IS_TOGGLE_BUTTON(tool->m_item)))
{
tool->m_toggleState = toggle;
if (tool->m_bitmap2.Ok())
{
wxBitmap bitmap = tool->m_bitmap1;
if (tool->m_toggleState) bitmap = tool->m_bitmap2;
GtkPixmap *pixmap = GTK_PIXMAP( tool->m_pixmap );
GdkBitmap *mask = (GdkBitmap *) NULL;
if (bitmap.GetMask()) mask = bitmap.GetMask()->GetBitmap();
gtk_pixmap_set( pixmap, bitmap.GetPixmap(), mask );
}
m_blockNextEvent = TRUE; // we cannot use gtk_signal_disconnect here
gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(tool->m_item), toggle );
}
return;
}
node = node->Next();
}
wxFAIL_MSG( wxT("wrong toolbar index") );
// VZ: absolutely no idea about how to do it
wxFAIL_MSG( _T("not implemented") );
}
wxObject *wxToolBar::GetToolClientData( int index ) const
{
wxNode *node = m_tools.First();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool*)node->Data();
if (tool->m_index == index) return tool->m_clientData;;
node = node->Next();
}
wxFAIL_MSG( wxT("wrong toolbar index") );
return (wxObject*)NULL;
}
// ----------------------------------------------------------------------------
// wxToolBar geometry
// ----------------------------------------------------------------------------
bool wxToolBar::GetToolState(int toolIndex) const
wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x),
wxCoord WXUNUSED(y)) const
{
wxNode *node = m_tools.First();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool*)node->Data();
if (tool->m_index == toolIndex) return tool->m_toggleState;
node = node->Next();
}
wxFAIL_MSG( wxT("wrong toolbar index") );
return FALSE;
}
// VZ: GTK+ doesn't seem to have such thing
wxFAIL_MSG( _T("wxToolBar::FindToolForPosition() not implemented") );
bool wxToolBar::GetToolEnabled(int toolIndex) const
{
wxNode *node = m_tools.First();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool*)node->Data();
if (tool->m_index == toolIndex) return tool->m_enabled;
node = node->Next();
}
wxFAIL_MSG( wxT("wrong toolbar index") );
return FALSE;
return (wxToolBarToolBase *)NULL;
}
void wxToolBar::SetMargins( int x, int y )
{
wxCHECK_RET( !m_hasToolAlready, wxT("wxToolBar::SetMargins must be called before adding tool.") );
wxCHECK_RET( GetToolsCount() == 0,
wxT("wxToolBar::SetMargins must be called before adding tools.") );
if (x > 1) gtk_toolbar_append_space( m_toolbar ); // oh well
@ -521,128 +495,15 @@ void wxToolBar::SetMargins( int x, int y )
m_yMargin = y;
}
void wxToolBar::SetToolPacking( int WXUNUSED(packing) )
{
wxFAIL_MSG( wxT("wxToolBar::SetToolPacking not implemented") );
}
void wxToolBar::SetToolSeparation( int separation )
{
gtk_toolbar_set_space_size( m_toolbar, separation );
m_separation = separation;
m_toolSeparation = separation;
}
int wxToolBar::GetToolPacking()
{
return 0;
}
int wxToolBar::GetToolSeparation()
{
return m_separation;
}
wxString wxToolBar::GetToolLongHelp(int toolIndex)
{
wxNode *node = m_tools.First();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool*)node->Data();
if (tool->m_index == toolIndex)
{
return tool->m_longHelpString;
}
node = node->Next();
}
wxFAIL_MSG( wxT("wrong toolbar index") );
return wxT("");
}
wxString wxToolBar::GetToolShortHelp(int toolIndex)
{
wxNode *node = m_tools.First();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool*)node->Data();
if (tool->m_index == toolIndex)
{
return tool->m_shortHelpString;
}
node = node->Next();
}
wxFAIL_MSG( wxT("wrong toolbar index") );
return wxT("");
}
void wxToolBar::SetToolLongHelp(int toolIndex, const wxString& helpString)
{
wxNode *node = m_tools.First();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool*)node->Data();
if (tool->m_index == toolIndex)
{
tool->m_longHelpString = helpString;
return;
}
node = node->Next();
}
wxFAIL_MSG( wxT("wrong toolbar index") );
return;
}
void wxToolBar::SetToolShortHelp(int toolIndex, const wxString& helpString)
{
wxNode *node = m_tools.First();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool*)node->Data();
if (tool->m_index == toolIndex)
{
tool->m_shortHelpString = helpString;
return;
}
node = node->Next();
}
wxFAIL_MSG( wxT("wrong toolbar index") );
return;
}
void wxToolBar::OnIdle( wxIdleEvent &WXUNUSED(ievent) )
{
wxEvtHandler* evtHandler = GetEventHandler();
wxNode* node = m_tools.First();
while (node)
{
wxToolBarTool* tool = (wxToolBarTool*) node->Data();
wxUpdateUIEvent event( tool->m_index );
event.SetEventObject(this);
if (evtHandler->ProcessEvent( event ))
{
if (event.GetSetEnabled())
EnableTool(tool->m_index, event.GetEnabled());
if (event.GetSetChecked())
ToggleTool(tool->m_index, event.GetChecked());
/*
if (event.GetSetText())
// Set tooltip?
*/
}
node = node->Next();
}
}
// ----------------------------------------------------------------------------
// wxToolBar idle handling
// ----------------------------------------------------------------------------
void wxToolBar::OnInternalIdle()
{
@ -652,31 +513,37 @@ void wxToolBar::OnInternalIdle()
if (cursor.Ok())
{
/* I now set the cursor the anew in every OnInternalIdle call
as setting the cursor in a parent window also effects the
windows above so that checking for the current cursor is
not possible. */
as setting the cursor in a parent window also effects the
windows above so that checking for the current cursor is
not possible. */
if (HasFlag(wxTB_DOCKABLE) && (m_widget->window))
{
/* if the toolbar is dockable, then m_widget stands for the
GtkHandleBox widget, which uses its own window so that we
can set the cursor for it. if the toolbar is not dockable,
m_widget comes from m_toolbar which uses its parent's
window ("windowless windows") and thus we cannot set the
cursor. */
gdk_window_set_cursor( m_widget->window, cursor.GetCursor() );
}
wxNode *node = m_tools.First();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool*)node->Data();
node = node->Next();
if (!tool->m_item || !tool->m_item->window)
continue;
else
gdk_window_set_cursor( tool->m_item->window, cursor.GetCursor() );
/* if the toolbar is dockable, then m_widget stands for the
GtkHandleBox widget, which uses its own window so that we
can set the cursor for it. if the toolbar is not dockable,
m_widget comes from m_toolbar which uses its parent's
window ("windowless windows") and thus we cannot set the
cursor. */
gdk_window_set_cursor( m_widget->window, cursor.GetCursor() );
}
wxToolBarToolsList::Node *node = m_tools.GetFirst();
while ( node )
{
wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
node = node->GetNext();
GtkWidget *item = tool->m_item;
if ( item )
{
GdkWindow *window = item->window;
if ( window )
{
gdk_window_set_cursor( window, cursor.GetCursor() );
}
}
}
}

View File

@ -2,18 +2,27 @@
// Name: tbargtk.cpp
// Purpose: GTK toolbar
// Author: Robert Roebling
// Modified: 13.12.99 by VZ to derive from wxToolBarBase
// RCS-ID: $Id$
// Copyright: (c) Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__
#pragma implementation "tbargtk.h"
#pragma implementation "tbargtk.h"
#endif
#include "wx/toolbar.h"
#if wxUSE_TOOLBAR
#if wxUSE_TOOLBAR_NATIVE
#include "wx/frame.h"
@ -21,57 +30,99 @@
#include "gdk/gdk.h"
#include "gtk/gtk.h"
//-----------------------------------------------------------------------------
// idle system
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// globals
// ----------------------------------------------------------------------------
// idle system
extern void wxapp_install_idle_handler();
extern bool g_isIdle;
//-----------------------------------------------------------------------------
// data
//-----------------------------------------------------------------------------
extern bool g_blockEventsOnDrag;
extern wxCursor g_globalCursor;
// ----------------------------------------------------------------------------
// wxToolBarTool
// ----------------------------------------------------------------------------
class wxToolBarTool : public wxToolBarToolBase
{
public:
wxToolBarTool(wxToolBar *tbar,
int id,
const wxBitmap& bitmap1,
const wxBitmap& bitmap2,
bool toggle,
wxObject *clientData,
const wxString& shortHelpString,
const wxString& longHelpString)
: wxToolBarToolBase(tbar, id, bitmap1, bitmap2, toggle,
clientData, shortHelpString, longHelpString)
{
Init();
}
wxToolBarTool(wxToolBar *tbar, wxControl *control)
: wxToolBarToolBase(tbar, control)
{
Init();
}
GtkWidget *m_item;
GtkWidget *m_pixmap;
protected:
void Init();
};
// ----------------------------------------------------------------------------
// wxWin macros
// ----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
// ============================================================================
// implementation
// ============================================================================
//-----------------------------------------------------------------------------
// "clicked" (internal from gtk_toolbar)
//-----------------------------------------------------------------------------
static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget), wxToolBarTool *tool )
static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget),
wxToolBarTool *tool )
{
if (g_isIdle)
wxapp_install_idle_handler();
if (tool->m_owner->m_blockNextEvent)
wxToolBar *tbar = (wxToolBar *)tool->GetToolBar();
if ( tbar->m_blockNextEvent )
{
tool->m_owner->m_blockNextEvent = FALSE;
tbar->m_blockNextEvent = FALSE;
return;
}
if (g_blockEventsOnDrag) return;
if (!tool->m_enabled) return;
if (!tool->IsEnabled()) return;
if (tool->m_isToggle)
if (tool->CanBeToggled())
{
tool->m_toggleState = !tool->m_toggleState;
if (tool->m_bitmap2.Ok())
{
wxBitmap bitmap = tool->m_bitmap1;
if (tool->m_toggleState) bitmap = tool->m_bitmap2;
tool->Toggle();
wxBitmap bitmap = tool->GetBitmap();
if ( bitmap.Ok() )
{
GtkPixmap *pixmap = GTK_PIXMAP( tool->m_pixmap );
GdkBitmap *mask = (GdkBitmap *) NULL;
if (bitmap.GetMask()) mask = bitmap.GetMask()->GetBitmap();
GdkBitmap *mask = bitmap.GetMask() ? bitmap.GetMask()->GetBitmap()
: (GdkBitmap *)NULL;
gtk_pixmap_set( pixmap, bitmap.GetPixmap(), mask );
}
}
}
tool->m_owner->OnLeftClick( tool->m_index, tool->m_toggleState );
tbar->OnLeftClick( tool->GetId(), tool->IsToggled() );
}
//-----------------------------------------------------------------------------
@ -79,18 +130,18 @@ static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget), wxToolBarTool *to
//-----------------------------------------------------------------------------
static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget),
GdkEventCrossing *WXUNUSED(gdk_event), wxToolBarTool *tool )
GdkEventCrossing *WXUNUSED(gdk_event),
wxToolBarTool *tool )
{
if (g_isIdle) wxapp_install_idle_handler();
if (g_blockEventsOnDrag) return TRUE;
wxToolBar *tb = tool->m_owner;
wxToolBar *tb = (wxToolBar *)tool->GetToolBar();
#if (GTK_MINOR_VERSION == 0)
/* we grey-out the tip text of disabled tool in GTK 1.0 */
if (tool->m_enabled)
if (tool->IsEnabled())
{
if (tb->m_fg->red != 0)
{
@ -117,7 +168,7 @@ static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget),
/* emit the event */
tb->OnMouseEnter( tool->m_index );
tb->OnMouseEnter( tool->GetId() );
return FALSE;
}
@ -126,30 +177,51 @@ static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget),
// InsertChild callback for wxToolBar
//-----------------------------------------------------------------------------
static void wxInsertChildInToolBar( wxToolBar* WXUNUSED(parent), wxWindow* WXUNUSED(child) )
static void wxInsertChildInToolBar( wxToolBar* WXUNUSED(parent),
wxWindow* WXUNUSED(child) )
{
/* we don't do anything here but pray */
}
//-----------------------------------------------------------------------------
// wxToolBar
//-----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// wxToolBarTool
// ----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxToolBar,wxControl)
BEGIN_EVENT_TABLE(wxToolBar, wxControl)
EVT_IDLE(wxToolBar::OnIdle)
END_EVENT_TABLE()
wxToolBar::wxToolBar()
void wxToolBarTool::Init()
{
m_item =
m_pixmap = (GtkWidget *)NULL;
}
wxToolBar::wxToolBar( wxWindow *parent, wxWindowID id,
const wxPoint& pos, const wxSize& size,
long style, const wxString& name )
wxToolBarToolBase *wxToolBar::CreateTool(int id,
const wxBitmap& bitmap1,
const wxBitmap& bitmap2,
bool toggle,
wxObject *clientData,
const wxString& shortHelpString,
const wxString& longHelpString)
{
Create( parent, id, pos, size, style, name );
return new wxToolBarTool(this, id, bitmap1, bitmap2, toggle,
clientData, shortHelpString, longHelpString);
}
wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control)
{
return new wxToolBarTool(this, control);
}
//-----------------------------------------------------------------------------
// wxToolBar construction
//-----------------------------------------------------------------------------
void wxToolBar::Init()
{
m_fg =
m_bg = (GdkColor *)NULL;
m_toolbar = (GtkToolbar *)NULL;
m_blockNextEvent = FALSE;
}
wxToolBar::~wxToolBar()
@ -158,36 +230,36 @@ wxToolBar::~wxToolBar()
delete m_bg;
}
bool wxToolBar::Create( wxWindow *parent, wxWindowID id,
const wxPoint& pos, const wxSize& size,
long style, const wxString& name )
bool wxToolBar::Create( wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name )
{
m_needParent = TRUE;
m_blockNextEvent = FALSE;
m_insertCallback = (wxInsertChildFunction)wxInsertChildInToolBar;
if (!PreCreation( parent, pos, size ) ||
!CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
if ( !PreCreation( parent, pos, size ) ||
!CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
{
wxFAIL_MSG( wxT("wxToolBar creation failed") );
return FALSE;
return FALSE;
}
m_tools.DeleteContents( TRUE );
GtkOrientation orient = style & wxTB_VERTICAL ? GTK_ORIENTATION_VERTICAL
: GTK_ORIENTATION_HORIZONTAL;
m_toolbar = GTK_TOOLBAR( gtk_toolbar_new( orient, GTK_TOOLBAR_ICONS ) );
m_toolbar = GTK_TOOLBAR( gtk_toolbar_new( GTK_ORIENTATION_HORIZONTAL,
GTK_TOOLBAR_ICONS ) );
m_separation = 7;
gtk_toolbar_set_space_size( m_toolbar, m_separation );
m_hasToolAlready = FALSE;
SetToolSeparation(7);
if (style & wxTB_DOCKABLE)
{
m_widget = gtk_handle_box_new();
gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) );
gtk_widget_show( GTK_WIDGET(m_toolbar) );
#if (GTK_MINOR_VERSION > 0)
if (style & wxTB_FLAT)
gtk_handle_box_set_shadow_type( GTK_HANDLE_BOX(m_widget), GTK_SHADOW_NONE );
@ -197,9 +269,9 @@ bool wxToolBar::Create( wxWindow *parent, wxWindowID id,
{
m_widget = GTK_WIDGET(m_toolbar);
}
gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), TRUE );
#if (GTK_MINOR_VERSION > 0)
if (style & wxTB_FLAT)
gtk_toolbar_set_button_relief( GTK_TOOLBAR(m_toolbar), GTK_RELIEF_NONE );
@ -210,32 +282,29 @@ bool wxToolBar::Create( wxWindow *parent, wxWindowID id,
m_fg->green = 0;
m_fg->blue = 0;
gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ), m_fg );
m_bg = new GdkColor;
m_bg->red = 65535;
m_bg->green = 65535;
m_bg->blue = 50000;
gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ), m_bg );
#if (GTK_MINOR_VERSION > 0)
gtk_tooltips_force_window( GTK_TOOLBAR(m_toolbar)->tooltips );
GtkStyle *g_style =
gtk_style_copy(
gtk_widget_get_style(
GTK_TOOLBAR(m_toolbar)->tooltips->tip_window ) );
gtk_style_copy(
gtk_widget_get_style(
GTK_TOOLBAR(m_toolbar)->tooltips->tip_window ) );
g_style->bg[GTK_STATE_NORMAL] = *m_bg;
gtk_widget_set_style( GTK_TOOLBAR(m_toolbar)->tooltips->tip_window, g_style );
#else
gtk_tooltips_set_colors( GTK_TOOLBAR(m_toolbar)->tooltips, m_bg, m_fg );
#endif
m_xMargin = 0;
m_yMargin = 0;
m_parent->DoAddChild( this );
PostCreation();
Show( TRUE );
@ -243,277 +312,182 @@ bool wxToolBar::Create( wxWindow *parent, wxWindowID id,
return TRUE;
}
bool wxToolBar::OnLeftClick( int toolIndex, bool toggleDown )
bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
{
wxCommandEvent event( wxEVT_COMMAND_TOOL_CLICKED, toolIndex );
event.SetEventObject(this);
event.SetInt( toolIndex );
event.SetExtraLong((long) toggleDown);
wxToolBarTool *tool = (wxToolBarTool *)toolBase;
GetEventHandler()->ProcessEvent(event);
return TRUE;
}
void wxToolBar::OnRightClick( int toolIndex, float WXUNUSED(x), float WXUNUSED(y) )
{
wxCommandEvent event( wxEVT_COMMAND_TOOL_RCLICKED, toolIndex );
event.SetEventObject( this );
event.SetInt( toolIndex );
GetEventHandler()->ProcessEvent(event);
}
void wxToolBar::OnMouseEnter( int toolIndex )
{
wxCommandEvent event( wxEVT_COMMAND_TOOL_ENTER, GetId() );
event.SetEventObject(this);
event.SetInt( toolIndex );
GetEventHandler()->ProcessEvent(event);
}
wxToolBarTool *wxToolBar::AddTool( int toolIndex, const wxBitmap& bitmap,
const wxBitmap& pushedBitmap, bool toggle,
wxCoord WXUNUSED(xPos), wxCoord WXUNUSED(yPos), wxObject *clientData,
const wxString& helpString1, const wxString& helpString2 )
{
m_hasToolAlready = TRUE;
wxCHECK_MSG( bitmap.Ok(), (wxToolBarTool *)NULL,
wxT("invalid bitmap for wxToolBar icon") );
wxCHECK_MSG( bitmap.GetBitmap() == NULL, (wxToolBarTool *)NULL,
wxT("wxToolBar doesn't support GdkBitmap") );
wxCHECK_MSG( bitmap.GetPixmap() != NULL, (wxToolBarTool *)NULL,
wxT("wxToolBar::Add needs a wxBitmap") );
GtkWidget *tool_pixmap = (GtkWidget *)NULL;
GdkPixmap *pixmap = bitmap.GetPixmap();
GdkBitmap *mask = (GdkBitmap *)NULL;
if ( bitmap.GetMask() )
mask = bitmap.GetMask()->GetBitmap();
tool_pixmap = gtk_pixmap_new( pixmap, mask );
#if (GTK_MINOR_VERSION > 0)
gtk_pixmap_set_build_insensitive( GTK_PIXMAP(tool_pixmap), TRUE );
#endif
gtk_misc_set_alignment( GTK_MISC(tool_pixmap), 0.5, 0.5 );
wxToolBarTool *tool = new wxToolBarTool( this, toolIndex, bitmap, pushedBitmap,
toggle, clientData,
helpString1, helpString2,
tool_pixmap );
GtkToolbarChildType ctype = toggle ? GTK_TOOLBAR_CHILD_TOGGLEBUTTON
: GTK_TOOLBAR_CHILD_BUTTON;
GtkWidget *item = gtk_toolbar_append_element
(
m_toolbar,
ctype,
(GtkWidget *)NULL,
(const char *)NULL,
helpString1.mbc_str(),
"",
tool_pixmap,
(GtkSignalFunc)gtk_toolbar_callback,
(gpointer)tool
);
tool->m_item = item;
GtkRequisition req;
(* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request ) (m_widget, &req );
m_width = req.width + m_xMargin;
m_height = req.height + 2*m_yMargin + 4;
gtk_signal_connect( GTK_OBJECT(tool->m_item),
"enter_notify_event",
GTK_SIGNAL_FUNC(gtk_toolbar_enter_callback),
(gpointer)tool );
m_tools.Append( tool );
return tool;
}
bool wxToolBar::AddControl(wxControl *control)
{
wxCHECK_MSG( control, FALSE, wxT("toolbar: can't insert NULL control") );
wxCHECK_MSG( control->GetParent() == this, FALSE,
wxT("control must have toolbar as parent") );
m_hasToolAlready = TRUE;
wxToolBarTool *tool = new wxToolBarTool(control);
tool -> m_item = NULL;
gtk_toolbar_append_widget( m_toolbar, control->m_widget, (const char *) NULL, (const char *) NULL );
GtkRequisition req;
(* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request ) (m_widget, &req );
m_width = req.width + m_xMargin;
m_height = req.height + 2*m_yMargin + 4;
m_tools.Append( tool );
return TRUE;
}
void wxToolBar::AddSeparator()
{
gtk_toolbar_append_space( m_toolbar );
}
bool wxToolBar::DeleteTool(int toolIndex)
{
wxNode *node = m_tools.First();
while (node)
if ( tool->IsButton() )
{
wxToolBarTool *tool = (wxToolBarTool*)node->Data();
if (tool->m_index == toolIndex)
{
if (tool->m_control)
tool->m_control->Destroy();
else
gtk_widget_destroy( tool->m_item );
m_tools.DeleteNode( node );
wxBitmap bitmap = tool->GetBitmap1();
wxCHECK_MSG( bitmap.Ok(), FALSE,
wxT("invalid bitmap for wxToolBar icon") );
wxCHECK_MSG( bitmap.GetBitmap() == NULL, FALSE,
wxT("wxToolBar doesn't support GdkBitmap") );
wxCHECK_MSG( bitmap.GetPixmap() != NULL, FALSE,
wxT("wxToolBar::Add needs a wxBitmap") );
GtkWidget *tool_pixmap = (GtkWidget *)NULL;
GdkPixmap *pixmap = bitmap.GetPixmap();
GdkBitmap *mask = (GdkBitmap *)NULL;
if ( bitmap.GetMask() )
mask = bitmap.GetMask()->GetBitmap();
tool_pixmap = gtk_pixmap_new( pixmap, mask );
#if (GTK_MINOR_VERSION > 0)
gtk_pixmap_set_build_insensitive( GTK_PIXMAP(tool_pixmap), TRUE );
#endif
gtk_misc_set_alignment( GTK_MISC(tool_pixmap), 0.5, 0.5 );
tool->m_pixmap = tool_pixmap;
}
switch ( tool->GetStyle() )
{
case wxTOOL_STYLE_BUTTON:
tool->m_item = gtk_toolbar_insert_element
(
m_toolbar,
tool->CanBeToggled()
? GTK_TOOLBAR_CHILD_TOGGLEBUTTON
: GTK_TOOLBAR_CHILD_BUTTON,
(GtkWidget *)NULL,
(const char *)NULL,
tool->GetShortHelp().mbc_str(),
"", // tooltip_private_text (?)
tool->m_pixmap,
(GtkSignalFunc)gtk_toolbar_callback,
(gpointer)tool,
pos
);
if ( !tool->m_item )
{
wxFAIL_MSG( _T("gtk_toolbar_insert_element() failed") );
return FALSE;
}
gtk_signal_connect( GTK_OBJECT(tool->m_item),
"enter_notify_event",
GTK_SIGNAL_FUNC(gtk_toolbar_enter_callback),
(gpointer)tool );
break;
case wxTOOL_STYLE_SEPARATOR:
gtk_toolbar_append_space( m_toolbar );
// skip the rest
return TRUE;
}
node = node->Next();
case wxTOOL_STYLE_CONTROL:
gtk_toolbar_insert_widget(
m_toolbar,
tool->GetControl()->m_widget,
(const char *) NULL,
(const char *) NULL,
pos
);
break;
}
return FALSE;
}
GtkRequisition req;
(* GTK_WIDGET_CLASS( GTK_OBJECT(m_widget)->klass )->size_request ) (m_widget, &req );
m_width = req.width + m_xMargin;
m_height = req.height + 2*m_yMargin + 4;
void wxToolBar::ClearTools()
{
wxFAIL_MSG( wxT("wxToolBar::ClearTools not implemented") );
}
bool wxToolBar::Realize()
{
return TRUE;
}
void wxToolBar::EnableTool(int toolIndex, bool enable)
bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *toolBase)
{
wxNode *node = m_tools.First();
while (node)
wxToolBarTool *tool = (wxToolBarTool *)toolBase;
switch ( tool->GetStyle() )
{
wxToolBarTool *tool = (wxToolBarTool*)node->Data();
if (tool->m_index == toolIndex)
{
tool->m_enabled = enable;
case wxTOOL_STYLE_CONTROL:
tool->GetControl()->Destroy();
break;
case wxTOOL_STYLE_BUTTON:
gtk_widget_destroy( tool->m_item );
break;
//case wxTOOL_STYLE_SEPARATOR: -- nothing to do
}
return TRUE;
}
// ----------------------------------------------------------------------------
// wxToolBar tools state
// ----------------------------------------------------------------------------
void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable)
{
#if (GTK_MINOR_VERSION > 0)
/* we don't disable the tools for GTK 1.0 as the bitmaps don't get
greyed anyway and this also disables tooltips */
if (tool->m_item)
gtk_widget_set_sensitive( tool->m_item, enable );
wxToolBarTool *tool = (wxToolBarTool *)toolBase;
/* we don't disable the tools for GTK 1.0 as the bitmaps don't get
greyed anyway and this also disables tooltips */
if (tool->m_item)
gtk_widget_set_sensitive( tool->m_item, enable );
#endif
return;
}
void wxToolBar::DoToggleTool( wxToolBarToolBase *toolBase, bool toggle )
{
wxToolBarTool *tool = (wxToolBarTool *)toolBase;
GtkWidget *item = tool->m_item;
if ( item && GTK_IS_TOGGLE_BUTTON(item) )
{
wxBitmap bitmap = tool->GetBitmap();
if ( bitmap.Ok() )
{
GtkPixmap *pixmap = GTK_PIXMAP( tool->m_pixmap );
GdkBitmap *mask = bitmap.GetMask() ? bitmap.GetMask()->GetBitmap()
: (GdkBitmap *)NULL;
gtk_pixmap_set( pixmap, bitmap.GetPixmap(), mask );
}
node = node->Next();
m_blockNextEvent = TRUE; // we cannot use gtk_signal_disconnect here
gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(item), toggle );
}
wxFAIL_MSG( wxT("wrong toolbar index") );
}
void wxToolBar::ToggleTool( int toolIndex, bool toggle )
void wxToolBar::DoSetToggle(wxToolBarToolBase * WXUNUSED(tool),
bool WXUNUSED(toggle))
{
wxNode *node = m_tools.First();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool*)node->Data();
if (tool->m_index == toolIndex)
{
if ((tool->m_item) && (GTK_IS_TOGGLE_BUTTON(tool->m_item)))
{
tool->m_toggleState = toggle;
if (tool->m_bitmap2.Ok())
{
wxBitmap bitmap = tool->m_bitmap1;
if (tool->m_toggleState) bitmap = tool->m_bitmap2;
GtkPixmap *pixmap = GTK_PIXMAP( tool->m_pixmap );
GdkBitmap *mask = (GdkBitmap *) NULL;
if (bitmap.GetMask()) mask = bitmap.GetMask()->GetBitmap();
gtk_pixmap_set( pixmap, bitmap.GetPixmap(), mask );
}
m_blockNextEvent = TRUE; // we cannot use gtk_signal_disconnect here
gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(tool->m_item), toggle );
}
return;
}
node = node->Next();
}
wxFAIL_MSG( wxT("wrong toolbar index") );
// VZ: absolutely no idea about how to do it
wxFAIL_MSG( _T("not implemented") );
}
wxObject *wxToolBar::GetToolClientData( int index ) const
{
wxNode *node = m_tools.First();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool*)node->Data();
if (tool->m_index == index) return tool->m_clientData;;
node = node->Next();
}
wxFAIL_MSG( wxT("wrong toolbar index") );
return (wxObject*)NULL;
}
// ----------------------------------------------------------------------------
// wxToolBar geometry
// ----------------------------------------------------------------------------
bool wxToolBar::GetToolState(int toolIndex) const
wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x),
wxCoord WXUNUSED(y)) const
{
wxNode *node = m_tools.First();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool*)node->Data();
if (tool->m_index == toolIndex) return tool->m_toggleState;
node = node->Next();
}
wxFAIL_MSG( wxT("wrong toolbar index") );
return FALSE;
}
// VZ: GTK+ doesn't seem to have such thing
wxFAIL_MSG( _T("wxToolBar::FindToolForPosition() not implemented") );
bool wxToolBar::GetToolEnabled(int toolIndex) const
{
wxNode *node = m_tools.First();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool*)node->Data();
if (tool->m_index == toolIndex) return tool->m_enabled;
node = node->Next();
}
wxFAIL_MSG( wxT("wrong toolbar index") );
return FALSE;
return (wxToolBarToolBase *)NULL;
}
void wxToolBar::SetMargins( int x, int y )
{
wxCHECK_RET( !m_hasToolAlready, wxT("wxToolBar::SetMargins must be called before adding tool.") );
wxCHECK_RET( GetToolsCount() == 0,
wxT("wxToolBar::SetMargins must be called before adding tools.") );
if (x > 1) gtk_toolbar_append_space( m_toolbar ); // oh well
@ -521,128 +495,15 @@ void wxToolBar::SetMargins( int x, int y )
m_yMargin = y;
}
void wxToolBar::SetToolPacking( int WXUNUSED(packing) )
{
wxFAIL_MSG( wxT("wxToolBar::SetToolPacking not implemented") );
}
void wxToolBar::SetToolSeparation( int separation )
{
gtk_toolbar_set_space_size( m_toolbar, separation );
m_separation = separation;
m_toolSeparation = separation;
}
int wxToolBar::GetToolPacking()
{
return 0;
}
int wxToolBar::GetToolSeparation()
{
return m_separation;
}
wxString wxToolBar::GetToolLongHelp(int toolIndex)
{
wxNode *node = m_tools.First();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool*)node->Data();
if (tool->m_index == toolIndex)
{
return tool->m_longHelpString;
}
node = node->Next();
}
wxFAIL_MSG( wxT("wrong toolbar index") );
return wxT("");
}
wxString wxToolBar::GetToolShortHelp(int toolIndex)
{
wxNode *node = m_tools.First();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool*)node->Data();
if (tool->m_index == toolIndex)
{
return tool->m_shortHelpString;
}
node = node->Next();
}
wxFAIL_MSG( wxT("wrong toolbar index") );
return wxT("");
}
void wxToolBar::SetToolLongHelp(int toolIndex, const wxString& helpString)
{
wxNode *node = m_tools.First();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool*)node->Data();
if (tool->m_index == toolIndex)
{
tool->m_longHelpString = helpString;
return;
}
node = node->Next();
}
wxFAIL_MSG( wxT("wrong toolbar index") );
return;
}
void wxToolBar::SetToolShortHelp(int toolIndex, const wxString& helpString)
{
wxNode *node = m_tools.First();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool*)node->Data();
if (tool->m_index == toolIndex)
{
tool->m_shortHelpString = helpString;
return;
}
node = node->Next();
}
wxFAIL_MSG( wxT("wrong toolbar index") );
return;
}
void wxToolBar::OnIdle( wxIdleEvent &WXUNUSED(ievent) )
{
wxEvtHandler* evtHandler = GetEventHandler();
wxNode* node = m_tools.First();
while (node)
{
wxToolBarTool* tool = (wxToolBarTool*) node->Data();
wxUpdateUIEvent event( tool->m_index );
event.SetEventObject(this);
if (evtHandler->ProcessEvent( event ))
{
if (event.GetSetEnabled())
EnableTool(tool->m_index, event.GetEnabled());
if (event.GetSetChecked())
ToggleTool(tool->m_index, event.GetChecked());
/*
if (event.GetSetText())
// Set tooltip?
*/
}
node = node->Next();
}
}
// ----------------------------------------------------------------------------
// wxToolBar idle handling
// ----------------------------------------------------------------------------
void wxToolBar::OnInternalIdle()
{
@ -652,31 +513,37 @@ void wxToolBar::OnInternalIdle()
if (cursor.Ok())
{
/* I now set the cursor the anew in every OnInternalIdle call
as setting the cursor in a parent window also effects the
windows above so that checking for the current cursor is
not possible. */
as setting the cursor in a parent window also effects the
windows above so that checking for the current cursor is
not possible. */
if (HasFlag(wxTB_DOCKABLE) && (m_widget->window))
{
/* if the toolbar is dockable, then m_widget stands for the
GtkHandleBox widget, which uses its own window so that we
can set the cursor for it. if the toolbar is not dockable,
m_widget comes from m_toolbar which uses its parent's
window ("windowless windows") and thus we cannot set the
cursor. */
gdk_window_set_cursor( m_widget->window, cursor.GetCursor() );
}
wxNode *node = m_tools.First();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool*)node->Data();
node = node->Next();
if (!tool->m_item || !tool->m_item->window)
continue;
else
gdk_window_set_cursor( tool->m_item->window, cursor.GetCursor() );
/* if the toolbar is dockable, then m_widget stands for the
GtkHandleBox widget, which uses its own window so that we
can set the cursor for it. if the toolbar is not dockable,
m_widget comes from m_toolbar which uses its parent's
window ("windowless windows") and thus we cannot set the
cursor. */
gdk_window_set_cursor( m_widget->window, cursor.GetCursor() );
}
wxToolBarToolsList::Node *node = m_tools.GetFirst();
while ( node )
{
wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
node = node->GetNext();
GtkWidget *item = tool->m_item;
if ( item )
{
GdkWindow *window = item->window;
if ( window )
{
gdk_window_set_cursor( window, cursor.GetCursor() );
}
}
}
}

View File

@ -1,16 +1,24 @@
/////////////////////////////////////////////////////////////////////////////
// Name: toolbar.cpp
// Name: motif/toolbar.cpp
// Purpose: wxToolBar
// Author: Julian Smart
// Modified by:
// Modified by: 13.12.99 by VZ during toolbar classes reorganization
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__
#pragma implementation "toolbar.h"
#pragma implementation "toolbar.h"
#endif
#include "wx/wx.h"
@ -34,51 +42,147 @@
#include "wx/motif/private.h"
IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxToolBarBase)
// ----------------------------------------------------------------------------
// wxWin macros
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase)
END_EVENT_TABLE()
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
#endif
// ----------------------------------------------------------------------------
// private functions
// ----------------------------------------------------------------------------
static void wxToolButtonCallback (Widget w, XtPointer clientData,
XtPointer ptr);
static void wxToolButtonPopupCallback (Widget w, XtPointer client_data,
XEvent *event, Boolean *continue_to_dispatch);
class wxToolBarTimer: public wxTimer
// ----------------------------------------------------------------------------
// private classes
// ----------------------------------------------------------------------------
class wxToolBarTimer : public wxTimer
{
public:
wxToolBarTimer() { }
virtual void Notify();
virtual void Notify();
static Widget help_popup;
static Widget buttonWidget;
static wxString helpString;
static Widget help_popup;
static Widget buttonWidget;
static wxString helpString;
};
class wxToolBarTool : public wxToolBarToolBase
{
public:
wxToolBarTool(wxToolBar *tbar,
int id,
const wxBitmap& bitmap1,
const wxBitmap& bitmap2,
bool toggle,
wxObject *clientData,
const wxString& shortHelpString,
const wxString& longHelpString)
: wxToolBarToolBase(tbar, id, bitmap1, bitmap2, toggle,
clientData, shortHelpString, longHelpString)
{
Init();
}
wxToolBarTool(wxToolBar *tbar, wxControl *control)
: wxToolBarToolBase(tbar, control)
{
Init();
}
virtual ~wxToolBarTool();
// accessors
void SetWidget(Widget widget) { m_widget = widget; }
Widget GetButtonWidget() const { return m_widget; }
void SetPixmap(Pixmap pixmap) { m_pixmap = pixmap; }
Pixmap GetPixmap() const { return m_pixmap; }
protected:
void Init();
Widget m_widget;
Pixmap m_pixmap;
};
// ----------------------------------------------------------------------------
// globals
// ----------------------------------------------------------------------------
static wxToolBarTimer* wxTheToolBarTimer = (wxToolBarTimer*) NULL;
Widget wxToolBarTimer::help_popup = (Widget) 0;
Widget wxToolBarTimer::buttonWidget = (Widget) 0;
wxString wxToolBarTimer::helpString = "";
wxString wxToolBarTimer::helpString;
wxToolBar::wxToolBar():
m_widgets(wxKEY_INTEGER)
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// wxToolBarTool
// ----------------------------------------------------------------------------
wxToolBarToolBase *wxToolBarToolBase::New(wxToolBar *tbar,
int id,
const wxBitmap& bitmap1,
const wxBitmap& bitmap2,
bool toggle,
wxObject *clientData,
const wxString& shortHelpString,
const wxString& longHelpString)
{
m_maxWidth = -1;
m_maxHeight = -1;
m_defaultWidth = 24;
m_defaultHeight = 22;
return new wxToolBarTool(tbar, id, bitmap1, bitmap2, toggle,
clientData, shortHelpString, longHelpString);
}
bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
long style, const wxString& name)
wxToolBarToolBase *wxToolBarToolBase::New(wxToolBar *tbar, wxControl *control)
{
return new wxToolBarTool(tbar, control);
}
void wxToolBarTool::Init()
{
m_widget = (Widget)0;
m_pixmap = (Pixmap)0;
}
wxToolBarTool::~wxToolBarTool()
{
XtDestroyWidget(m_widget);
XmDestroyPixmap(DefaultScreenOfDisplay((Display*)wxGetDisplay()), m_pixmap);
}
// ----------------------------------------------------------------------------
// wxToolBar construction
// ----------------------------------------------------------------------------
void wxToolBar::Init()
{
m_windowId = id;
m_maxWidth = -1;
m_maxHeight = -1;
m_defaultWidth = 24;
m_defaultHeight = 22;
}
bool wxToolBar::Create(wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{
Init();
m_windowId = id;
SetName(name);
m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
m_foregroundColour = parent->GetForegroundColour();
@ -126,14 +230,15 @@ wxToolBar::~wxToolBar()
{
delete wxTheToolBarTimer;
wxTheToolBarTimer = NULL;
ClearTools();
DestroyPixmaps();
}
bool wxToolBar::CreateTools()
bool wxToolBar::Realize()
{
if (m_tools.Number() == 0)
return FALSE;
if ( m_tools.GetCount() == 0 )
{
// nothing to do
return TRUE;
}
// Separator spacing
const int separatorSize = GetToolSeparation(); // 8;
@ -148,178 +253,193 @@ bool wxToolBar::CreateTools()
int currentSpacing = 0;
m_widgets.Clear();
Widget prevButton = (Widget) 0;
wxNode* node = m_tools.First();
while (node)
Widget button;
Pixmap pixmap, insensPixmap;
wxBitmap bmp;
wxToolBarToolsList::Node *node = m_tools.GetFirst();
while ( node )
{
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
if (tool->m_toolStyle == wxTOOL_STYLE_SEPARATOR)
currentX += separatorSize;
else if (tool->m_bitmap1.Ok())
switch ( tool->GetStyle() )
{
Widget button = (Widget) 0;
case wxTOOL_STYLE_CONTROL:
wxFAIL_MSG( _T("not implemented") );
break;
if (tool->m_isToggle)
{
button = XtVaCreateWidget("toggleButton",
xmToggleButtonWidgetClass, (Widget) m_mainWidget,
XmNx, currentX, XmNy, currentY,
// XmNpushButtonEnabled, True,
XmNmultiClick, XmMULTICLICK_KEEP,
XmNlabelType, XmPIXMAP,
NULL);
XtAddCallback ((Widget) button, XmNvalueChangedCallback, (XtCallbackProc) wxToolButtonCallback,
(XtPointer) this);
case wxTOOL_STYLE_SEPARATOR:
currentX += separatorSize;
break;
XtVaSetValues ((Widget) button,
XmNselectColor, m_backgroundColour.AllocColour(XtDisplay((Widget) button)),
NULL);
}
else
{
button = XtVaCreateWidget("button",
xmPushButtonWidgetClass, (Widget) m_mainWidget,
XmNx, currentX, XmNy, currentY,
XmNpushButtonEnabled, True,
XmNmultiClick, XmMULTICLICK_KEEP,
XmNlabelType, XmPIXMAP,
NULL);
XtAddCallback (button,
XmNactivateCallback, (XtCallbackProc) wxToolButtonCallback,
(XtPointer) this);
}
case wxTOOL_STYLE_BUTTON:
button = (Widget) 0;
DoChangeBackgroundColour((WXWidget) button, m_backgroundColour, TRUE);
if ( tool->CanBeToggled() )
{
button = XtVaCreateWidget("toggleButton",
xmToggleButtonWidgetClass, (Widget) m_mainWidget,
XmNx, currentX, XmNy, currentY,
// XmNpushButtonEnabled, True,
XmNmultiClick, XmMULTICLICK_KEEP,
XmNlabelType, XmPIXMAP,
NULL);
XtAddCallback ((Widget) button, XmNvalueChangedCallback, (XtCallbackProc) wxToolButtonCallback,
(XtPointer) this);
// For each button, if there is a mask, we must create
// a new wxBitmap that has the correct background colour
// for the button. Otherwise the background will just be
// e.g. black if a transparent XPM has been loaded.
wxBitmap originalBitmap = tool->m_bitmap1;
XtVaSetValues ((Widget) button,
XmNselectColor, m_backgroundColour.AllocColour(XtDisplay((Widget) button)),
NULL);
}
else
{
button = XtVaCreateWidget("button",
xmPushButtonWidgetClass, (Widget) m_mainWidget,
XmNx, currentX, XmNy, currentY,
XmNpushButtonEnabled, True,
XmNmultiClick, XmMULTICLICK_KEEP,
XmNlabelType, XmPIXMAP,
NULL);
XtAddCallback (button,
XmNactivateCallback, (XtCallbackProc) wxToolButtonCallback,
(XtPointer) this);
}
if (tool->m_bitmap1.GetMask())
{
DoChangeBackgroundColour((WXWidget) button, m_backgroundColour, TRUE);
tool->SetWidget(button);
// For each button, if there is a mask, we must create
// a new wxBitmap that has the correct background colour
// for the button. Otherwise the background will just be
// e.g. black if a transparent XPM has been loaded.
bmp = tool->GetBitmap1();
if ( bmp.GetMask() )
{
int backgroundPixel;
XtVaGetValues(button, XmNbackground, &backgroundPixel,
NULL);
wxColour col;
col.SetPixel(backgroundPixel);
wxBitmap newBitmap = wxCreateMaskedBitmap(bmp, col);
tool->SetBitmap1(newBitmap);
}
// Create a selected/toggled bitmap. If there isn't a 2nd
// bitmap, we need to create it (with a darker, selected
// background)
int backgroundPixel;
XtVaGetValues(button, XmNbackground, &backgroundPixel,
NULL);
if ( tool->CanBeToggled() )
XtVaGetValues(button, XmNselectColor, &backgroundPixel,
NULL);
else
XtVaGetValues(button, XmNarmColor, &backgroundPixel,
NULL);
wxColour col;
col.SetPixel(backgroundPixel);
wxBitmap newBitmap = wxCreateMaskedBitmap(tool->m_bitmap1, col);
tool->m_bitmap1 = newBitmap;
}
// Create a selected/toggled bitmap. If there isn't a m_bitmap2,
// we need to create it (with a darker, selected background)
int backgroundPixel;
if (tool->m_isToggle)
XtVaGetValues(button, XmNselectColor, &backgroundPixel,
NULL);
else
XtVaGetValues(button, XmNarmColor, &backgroundPixel,
NULL);
wxColour col;
col.SetPixel(backgroundPixel);
if (tool->m_bitmap2.Ok() && tool->m_bitmap2.GetMask())
{
// Use what's there
wxBitmap newBitmap = wxCreateMaskedBitmap(tool->m_bitmap2, col);
tool->m_bitmap2 = newBitmap;
}
else
{
// Use unselected bitmap
if (originalBitmap.GetMask())
if (tool->GetBitmap2().Ok() && tool->GetBitmap2().GetMask())
{
wxBitmap newBitmap = wxCreateMaskedBitmap(originalBitmap, col);
tool->m_bitmap2 = newBitmap;
}
else
tool->m_bitmap2 = tool->m_bitmap1;
}
Pixmap pixmap = (Pixmap) tool->m_bitmap1.GetPixmap();
Pixmap insensPixmap = (Pixmap) tool->m_bitmap1.GetInsensPixmap();
if (tool->m_isToggle)
{
// Toggle button
Pixmap pixmap2 = (Pixmap) 0;
Pixmap insensPixmap2 = (Pixmap) 0;
// If there's a bitmap for the toggled state, use it,
// otherwise generate one.
if (tool->m_bitmap2.Ok())
{
pixmap2 = (Pixmap) tool->m_bitmap2.GetPixmap();
insensPixmap2 = (Pixmap) tool->m_bitmap2.GetInsensPixmap();
// Use what's there
wxBitmap newBitmap = wxCreateMaskedBitmap(tool->GetBitmap2(), col);
tool->SetBitmap2(newBitmap);
}
else
{
pixmap2 = (Pixmap) tool->m_bitmap1.GetArmPixmap(button);
insensPixmap2 = XCreateInsensitivePixmap((Display*) wxGetDisplay(), pixmap2);
m_pixmaps.Append((wxObject*) insensPixmap2); // Store for later deletion
// Use unselected bitmap
if ( bmp.GetMask() )
{
wxBitmap newBitmap = wxCreateMaskedBitmap(bmp, col);
tool->SetBitmap2(newBitmap);
}
else
tool->SetBitmap2(bmp);
}
XtVaSetValues (button,
XmNindicatorOn, False,
XmNshadowThickness, 2,
// XmNborderWidth, 0,
// XmNspacing, 0,
XmNmarginWidth, 0,
XmNmarginHeight, 0,
XmNfillOnSelect, True,
XmNlabelPixmap, pixmap,
XmNselectPixmap, pixmap2,
XmNlabelInsensitivePixmap, insensPixmap,
XmNselectInsensitivePixmap, insensPixmap2,
XmNlabelType, XmPIXMAP,
NULL);
}
else
{
Pixmap pixmap2 = (Pixmap) 0;
// If there's a bitmap for the armed state, use it,
// otherwise generate one.
if (tool->m_bitmap2.Ok())
pixmap = (Pixmap) bmp.GetPixmap();
insensPixmap = (Pixmap) bmp.GetInsensPixmap();
if (tool->CanBeToggled())
{
pixmap2 = (Pixmap) tool->m_bitmap2.GetPixmap();
// Toggle button
Pixmap pixmap2 = (Pixmap) 0;
Pixmap insensPixmap2 = (Pixmap) 0;
// If there's a bitmap for the toggled state, use it,
// otherwise generate one.
if (tool->GetBitmap2().Ok())
{
wxBitmap bmp2 = tool->GetBitmap2();
pixmap2 = (Pixmap) bmp2.GetPixmap();
insensPixmap2 = (Pixmap) bmp2.GetInsensPixmap();
}
else
{
pixmap2 = (Pixmap) bmp.GetArmPixmap(button);
insensPixmap2 = XCreateInsensitivePixmap((Display*) wxGetDisplay(), pixmap2);
}
XtVaSetValues (button,
XmNindicatorOn, False,
XmNshadowThickness, 2,
// XmNborderWidth, 0,
// XmNspacing, 0,
XmNmarginWidth, 0,
XmNmarginHeight, 0,
XmNfillOnSelect, True,
XmNlabelPixmap, pixmap,
XmNselectPixmap, pixmap2,
XmNlabelInsensitivePixmap, insensPixmap,
XmNselectInsensitivePixmap, insensPixmap2,
XmNlabelType, XmPIXMAP,
NULL);
}
else
{
pixmap2 = (Pixmap) tool->m_bitmap1.GetArmPixmap(button);
Pixmap pixmap2 = (Pixmap) 0;
// If there's a bitmap for the armed state, use it,
// otherwise generate one.
if (tool->GetBitmap2().Ok())
{
pixmap2 = (Pixmap) tool->GetBitmap2().GetPixmap();
}
else
{
pixmap2 = (Pixmap) bmp.GetArmPixmap(button);
}
// Normal button
XtVaSetValues(button,
XmNlabelPixmap, pixmap,
XmNlabelInsensitivePixmap, insensPixmap,
XmNarmPixmap, pixmap2,
NULL);
}
// Normal button
XtVaSetValues(button,
XmNlabelPixmap, pixmap,
XmNlabelInsensitivePixmap, insensPixmap,
XmNarmPixmap, pixmap2,
NULL);
}
XtManageChild(button);
XtManageChild(button);
Dimension width, height;
XtVaGetValues(button, XmNwidth, & width, XmNheight, & height,
NULL);
currentX += width + marginX;
buttonHeight = wxMax(buttonHeight, height);
{
Dimension width, height;
XtVaGetValues(button,
XmNwidth, &width,
XmNheight, & height,
NULL);
currentX += width + marginX;
buttonHeight = wxMax(buttonHeight, height);
}
XtAddEventHandler (button, EnterWindowMask | LeaveWindowMask,
False, wxToolButtonPopupCallback, (XtPointer) this);
m_widgets.Append(tool->m_index, (wxObject*) button);
XtAddEventHandler (button, EnterWindowMask | LeaveWindowMask,
False, wxToolButtonPopupCallback, (XtPointer) this);
prevButton = button;
currentSpacing = 0;
currentSpacing = 0;
break;
}
node = node->Next();
node = node->GetNext();
}
SetSize(-1, -1, currentX, buttonHeight + 2*marginY);
@ -327,199 +447,107 @@ bool wxToolBar::CreateTools()
return TRUE;
}
void wxToolBar::SetToolBitmapSize(const wxSize& size)
wxToolBarTool *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x),
wxCoord WXUNUSED(y)) const
{
// TODO not necessary?
m_defaultWidth = size.x; m_defaultHeight = size.y;
wxFAIL_MSG( _T("TODO") );
return (wxToolBarTool *)NULL;
}
wxSize wxToolBar::GetMaxSize() const
bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarTool *tool)
{
int w, h;
GetSize(& w, & h);
tool->Attach(this);
return wxSize(w, h);
return TRUE;
}
// The button size is bigger than the bitmap size
wxSize wxToolBar::GetToolSize() const
bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarTool *tool)
{
// TODO not necessary?
return wxSize(m_defaultWidth + 8, m_defaultHeight + 7);
tool->Detach();
return TRUE;
}
void wxToolBar::EnableTool(int toolIndex, bool enable)
void wxToolBar::DoEnableTool(wxToolBarTool *tool, bool enable)
{
wxNode *node = m_tools.Find((long)toolIndex);
if (node)
XtSetSensitive(tool->GetButtonWidget(), (Boolean) enable);
}
void wxToolBar::DoToggleTool(wxToolBarTool *tool, bool toggle)
{
XmToggleButtonSetState(tool->GetButtonWidget(), (Boolean) toggle, False);
}
void wxToolBar::DoSetToggle(wxToolBarTool *tool, bool toggle)
{
wxFAIL_MSG( _T("TODO") );
}
// ----------------------------------------------------------------------------
// Motif callbacks
// ----------------------------------------------------------------------------
wxToolBarTool *wxToolBar::FindToolByWidget(WXWidget w) const
{
wxToolBarToolsList::Node* node = m_tools.GetFirst();
while ( node )
{
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
tool->m_enabled = enable;
WXWidget widget = FindWidgetForIndex(tool->m_index);
if (widget == (WXWidget) 0)
return;
XtSetSensitive((Widget) widget, (Boolean) enable);
}
}
void wxToolBar::ToggleTool(int toolIndex, bool toggle)
{
wxNode *node = m_tools.Find((long)toolIndex);
if (node)
{
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
if (tool->m_isToggle)
wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
if ( tool->GetButtonWidget() == w)
{
tool->m_toggleState = toggle;
WXWidget widget = FindWidgetForIndex(tool->m_index);
if (widget == (WXWidget) 0)
return;
XmToggleButtonSetState((Widget) widget, (Boolean) toggle, False);
return tool;
}
node = node->GetNext();
}
return (wxToolBarTool *)NULL;
}
void wxToolBar::ClearTools()
{
wxNode* node = m_widgets.First();
while (node)
{
Widget button = (Widget) node->Data();
XtDestroyWidget(button);
node = node->Next();
}
m_widgets.Clear();
DestroyPixmaps();
wxToolBarBase::ClearTools();
}
void wxToolBar::DestroyPixmaps()
{
wxNode* node = m_pixmaps.First();
while (node)
{
Pixmap pixmap = (Pixmap) node->Data();
XmDestroyPixmap (DefaultScreenOfDisplay ((Display*) GetXDisplay()), pixmap);
node = node->Next();
}
m_pixmaps.Clear();
}
// If pushedBitmap is NULL, a reversed version of bitmap is
// created and used as the pushed/toggled image.
// If toggle is TRUE, the button toggles between the two states.
wxToolBarTool *wxToolBar::AddTool(int index, const wxBitmap& bitmap, const wxBitmap& WXUNUSED(pushedBitmap),
bool toggle, wxCoord xPos, wxCoord yPos, wxObject *clientData, const wxString& helpString1, const wxString& helpString2)
{
wxToolBarTool *tool = new wxToolBarTool(index, bitmap, wxNullBitmap, toggle, xPos, yPos, helpString1, helpString2);
tool->m_clientData = clientData;
if (xPos > -1)
tool->m_x = xPos;
else
tool->m_x = m_xMargin;
if (yPos > -1)
tool->m_y = yPos;
else
tool->m_y = m_yMargin;
wxSize size = GetToolSize();
tool->SetSize(size.x, size.y);
m_tools.Append((long)index, tool);
return tool;
}
int wxToolBar::FindIndexForWidget(WXWidget w)
{
wxNode* node = m_widgets.First();
while (node)
{
WXWidget widget = (WXWidget) node->Data();
if (widget == w)
return (int) node->GetKeyInteger();
node = node->Next();
}
return -1;
}
WXWidget wxToolBar::FindWidgetForIndex(int index)
{
wxNode* node = m_widgets.Find((long) index);
if (!node)
return (WXWidget) 0;
else
return (WXWidget) node->Data();
}
WXWidget wxToolBar::GetTopWidget() const
{
return m_mainWidget;
}
WXWidget wxToolBar::GetClientWidget() const
{
return m_mainWidget;
}
WXWidget wxToolBar::GetMainWidget() const
{
return m_mainWidget;
}
void wxToolButtonCallback (Widget w, XtPointer clientData,
XtPointer WXUNUSED(ptr))
static void wxToolButtonCallback(Widget w,
XtPointer clientData,
XtPointer WXUNUSED(ptr))
{
wxToolBar *toolBar = (wxToolBar *) clientData;
int index = toolBar->FindIndexForWidget((WXWidget) w);
wxToolBarTool *tool = toolBar->FindToolByWidget((WXWidget) w);
if ( !tool )
return;
if (index != -1)
if ( tool->CanBeToggled() )
tool->Toggle();
if ( !toolBar->OnLeftClick(tool->GetId(), tool->IsToggled()) )
{
wxNode *node = toolBar->GetTools().Find((long)index);
if (!node)
return;
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
if (tool->m_isToggle)
tool->m_toggleState = !tool->m_toggleState;
(void) toolBar->OnLeftClick(index, tool->m_toggleState);
// revert
tool->Toggle();
}
}
static void wxToolButtonPopupCallback (Widget w, XtPointer client_data,
XEvent *event, Boolean *WXUNUSED(continue_to_dispatch))
static void wxToolButtonPopupCallback(Widget w,
XtPointer client_data,
XEvent *event,
Boolean *WXUNUSED(continue_to_dispatch))
{
// TODO: retrieve delay before popping up tooltip from wxSystemSettings.
int delayMilli = 800;
static const int delayMilli = 800;
wxToolBar* toolBar = (wxToolBar*) client_data;
wxToolBarTool *tool = toolBar->FindToolByWidget((WXWidget) w);
int index = toolBar->FindIndexForWidget((WXWidget) w);
if ( !tool )
return;
if (index != -1)
{
wxNode *node = toolBar->GetTools().Find((long)index);
if (!node)
return;
wxString str(toolBar->GetToolShortHelp(index));
if (str.IsNull() || str == "")
return;
wxString tooltip = tool->GetShortHelp();
if ( !tooltip )
return;
if (!wxTheToolBarTimer)
wxTheToolBarTimer = new wxToolBarTimer;
wxToolBarTimer::buttonWidget = w;
wxToolBarTimer::helpString = str;
if (!wxTheToolBarTimer)
wxTheToolBarTimer = new wxToolBarTimer;
wxToolBarTimer::buttonWidget = w;
wxToolBarTimer::helpString = tooltip;
/************************************************************/
/* Popup help label */
@ -551,7 +579,6 @@ static void wxToolButtonPopupCallback (Widget w, XtPointer client_data,
}
wxToolBarTimer::help_popup = (Widget) 0;
}
}
}
void wxToolBarTimer::Notify()

View File

@ -1,6 +1,6 @@
/////////////////////////////////////////////////////////////////////////////
// Name: msw/tbar95.cpp
// Purpose: wxToolBar95
// Purpose: wxToolBar
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
@ -29,6 +29,7 @@
#endif
#ifndef WX_PRECOMP
#include "wx/frame.h"
#include "wx/log.h"
#include "wx/intl.h"
#include "wx/dynarray.h"
@ -36,7 +37,9 @@
#include "wx/bitmap.h"
#endif
#if wxUSE_BUTTONBAR && wxUSE_TOOLBAR && defined(__WIN95__)
#if wxUSE_TOOLBAR && defined(__WIN95__) && wxUSE_TOOLBAR_NATIVE
#include "wx/toolbar.h"
#if !defined(__GNUWIN32__) && !defined(__SALFORDC__)
#include "malloc.h"
@ -55,7 +58,6 @@
#endif // __TWIN32__
#include "wx/msw/dib.h"
#include "wx/msw/tbar95.h"
#include "wx/app.h" // for GetComCtl32Version
// ----------------------------------------------------------------------------
@ -74,8 +76,12 @@
// Messages
#ifndef TB_GETSTYLE
#define TB_GETSTYLE (WM_USER + 57)
#define TB_SETSTYLE (WM_USER + 56)
#define TB_GETSTYLE (WM_USER + 57)
#endif
#ifndef TB_HITTEST
#define TB_HITTEST (WM_USER + 69)
#endif
// these values correspond to those used by comctl32.dll
@ -86,7 +92,7 @@
#define DEFAULTBARHEIGHT 27
// ----------------------------------------------------------------------------
// function prototypes
// private function prototypes
// ----------------------------------------------------------------------------
static void wxMapBitmap(HBITMAP hBitmap, int width, int height);
@ -95,41 +101,96 @@ static void wxMapBitmap(HBITMAP hBitmap, int width, int height);
// wxWin macros
// ----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxToolBarBase)
IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
BEGIN_EVENT_TABLE(wxToolBar95, wxToolBarBase)
EVT_MOUSE_EVENTS(wxToolBar95::OnMouseEvent)
EVT_SYS_COLOUR_CHANGED(wxToolBar95::OnSysColourChanged)
BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase)
EVT_MOUSE_EVENTS(wxToolBar::OnMouseEvent)
EVT_SYS_COLOUR_CHANGED(wxToolBar::OnSysColourChanged)
END_EVENT_TABLE()
// ----------------------------------------------------------------------------
// private classes
// ----------------------------------------------------------------------------
class wxToolBarTool : public wxToolBarToolBase
{
public:
wxToolBarTool(wxToolBar *tbar,
int id,
const wxBitmap& bitmap1,
const wxBitmap& bitmap2,
bool toggle,
wxObject *clientData,
const wxString& shortHelpString,
const wxString& longHelpString)
: wxToolBarToolBase(tbar, id, bitmap1, bitmap2, toggle,
clientData, shortHelpString, longHelpString)
{
m_nSepCount = 0;
}
wxToolBarTool(wxToolBar *tbar, wxControl *control)
: wxToolBarToolBase(tbar, control)
{
m_nSepCount = 1;
}
// set/get the number of separators which we use to cover the space used by
// a control in the toolbar
void SetSeparatorsCount(size_t count) { m_nSepCount = count; }
size_t GetSeparatorsCount() const { return m_nSepCount; }
private:
size_t m_nSepCount;
};
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// wxToolBar95 construction
// wxToolBarTool
// ----------------------------------------------------------------------------
void wxToolBar95::Init()
wxToolBarToolBase *wxToolBar::CreateTool(int id,
const wxBitmap& bitmap1,
const wxBitmap& bitmap2,
bool toggle,
wxObject *clientData,
const wxString& shortHelpString,
const wxString& longHelpString)
{
return new wxToolBarTool(this, id, bitmap1, bitmap2, toggle,
clientData, shortHelpString, longHelpString);
}
wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control)
{
return new wxToolBarTool(this, control);
}
// ----------------------------------------------------------------------------
// wxToolBar construction
// ----------------------------------------------------------------------------
void wxToolBar::Init()
{
m_maxWidth = -1;
m_maxHeight = -1;
m_hBitmap = 0;
m_nButtons = 0;
m_defaultWidth = DEFAULTBITMAPX;
m_defaultHeight = DEFAULTBITMAPY;
}
bool wxToolBar95::Create(wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
bool wxToolBar::Create(wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{
wxASSERT_MSG( (style & wxTB_VERTICAL) == 0,
wxT("Sorry, wxToolBar95 under Windows 95 only "
"supports horizontal orientation.") );
// common initialisation
if ( !CreateControl(parent, id, pos, size, style, name) )
return FALSE;
@ -179,10 +240,8 @@ bool wxToolBar95::Create(wxWindow *parent,
return TRUE;
}
wxToolBar95::~wxToolBar95()
wxToolBar::~wxToolBar()
{
UnsubclassWin();
if (m_hBitmap)
{
::DeleteObject((HBITMAP) m_hBitmap);
@ -190,106 +249,109 @@ wxToolBar95::~wxToolBar95()
}
// ----------------------------------------------------------------------------
// adding/removing buttons
// adding/removing tools
// ----------------------------------------------------------------------------
void wxToolBar95::ClearTools()
bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos),
wxToolBarToolBase *tool)
{
// TODO: Don't know how to reset the toolbar bitmap, as yet.
// But adding tools and calling CreateTools should probably
// recreate a buttonbar OK.
wxToolBarBase::ClearTools();
// nothing special to do here - we really create the toolbar buttons in
// Realize() later
tool->Attach(this);
return TRUE;
}
bool wxToolBar95::DeleteTool(int id)
bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool)
{
int index = GetIndexFromId(id);
wxASSERT_MSG( index != wxNOT_FOUND, _T("invalid toolbar button id") );
// normally, we only delete one button, but we use several separators to
// cover the space used by one control sometimes (with old comctl32.dll)
size_t nButtonsToDelete = 1;
if ( !SendMessage(GetHwnd(), TB_DELETEBUTTON, index, 0) )
// get the size of the button we're going to delete
RECT r;
if ( !::SendMessage(GetHwnd(), TB_GETITEMRECT, pos, (LPARAM)&r) )
{
wxLogLastError("TB_DELETEBUTTON");
return FALSE;
wxLogLastError(_T("TB_GETITEMRECT"));
}
wxNode *node = m_tools.Nth(index);
delete (wxToolBarTool *)node->Data();
m_tools.DeleteNode(node);
int width = r.right - r.left;
m_ids.RemoveAt(index);
if ( tool->IsControl() )
{
nButtonsToDelete = ((wxToolBarTool *)tool)->GetSeparatorsCount();
width *= nButtonsToDelete;
}
while ( nButtonsToDelete-- > 0 )
{
if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON, pos, 0) )
{
wxLogLastError("TB_DELETEBUTTON");
return FALSE;
}
}
tool->Detach();
m_nButtons -= nButtonsToDelete;
// reposition all the controls after this button
wxToolBarToolsList::Node *node = m_tools.Item(pos);
for ( node = node->GetNext(); node; node = node->GetNext() )
{
wxToolBarToolBase *tool2 = node->GetData();
if ( tool2->IsControl() )
{
int x;
wxControl *control = tool2->GetControl();
control->GetPosition(&x, NULL);
control->Move(x - width, -1);
}
}
return TRUE;
}
bool wxToolBar95::AddControl(wxControl *control)
bool wxToolBar::Realize()
{
wxCHECK_MSG( control, FALSE, _T("toolbar: can't insert NULL control") );
wxCHECK_MSG( control->GetParent() == this, FALSE,
_T("control must have toolbar as parent") );
wxToolBarTool *tool = new wxToolBarTool(control);
m_tools.Append(control->GetId(), tool);
m_ids.Add(control->GetId());
return TRUE;
}
wxToolBarTool *wxToolBar95::AddTool(int index,
const wxBitmap& bitmap,
const wxBitmap& pushedBitmap,
bool toggle,
long xPos, long yPos,
wxObject *clientData,
const wxString& helpString1,
const wxString& helpString2)
{
wxToolBarTool *tool = new wxToolBarTool(index, bitmap, wxNullBitmap,
toggle, xPos, yPos,
helpString1, helpString2);
tool->m_clientData = clientData;
if (xPos > -1)
tool->m_x = xPos;
else
tool->m_x = m_xMargin;
if (yPos > -1)
tool->m_y = yPos;
else
tool->m_y = m_yMargin;
tool->SetSize(GetToolSize().x, GetToolSize().y);
m_tools.Append((long)index, tool);
m_ids.Add(index);
return tool;
}
bool wxToolBar95::CreateTools()
{
size_t nTools = m_tools.GetCount();
size_t nTools = GetToolsCount();
if ( nTools == 0 )
return FALSE;
{
// nothing to do
return TRUE;
}
HBITMAP oldToolBarBitmap = (HBITMAP) m_hBitmap;
bool isVertical = (GetWindowStyle() & wxTB_VERTICAL) != 0;
// First, add the bitmap: we use one bitmap for all toolbar buttons
// ----------------------------------------------------------------
// if we already have a bitmap, we'll replace the existing one - otherwise
// we'll install a new one
HBITMAP oldToolBarBitmap = (HBITMAP)m_hBitmap;
int totalBitmapWidth = (int)(m_defaultWidth * nTools);
int totalBitmapHeight = (int)m_defaultHeight;
// Create a bitmap for all the tool bitmaps
HDC dc = ::GetDC(NULL);
m_hBitmap = (WXHBITMAP) ::CreateCompatibleBitmap(dc,
totalBitmapWidth,
totalBitmapHeight);
::ReleaseDC(NULL, dc);
HBITMAP hBitmap = ::CreateCompatibleBitmap(ScreenHDC(),
totalBitmapWidth,
totalBitmapHeight);
if ( !hBitmap )
{
wxLogLastError(_T("CreateCompatibleBitmap"));
return FALSE;
}
m_hBitmap = (WXHBITMAP)hBitmap;
// Now blit all the tools onto this bitmap
HDC memoryDC = ::CreateCompatibleDC(NULL);
HBITMAP oldBitmap = (HBITMAP) ::SelectObject(memoryDC, (HBITMAP)m_hBitmap);
HBITMAP oldBitmap = (HBITMAP) ::SelectObject(memoryDC, hBitmap);
HDC memoryDC2 = ::CreateCompatibleDC(NULL);
@ -297,15 +359,15 @@ bool wxToolBar95::CreateTools()
wxCoord x = 0;
// the number of buttons (not separators)
int noButtons = 0;
int nButtons = 0;
wxNode *node = m_tools.First();
while (node)
wxToolBarToolsList::Node *node = m_tools.GetFirst();
while ( node )
{
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
if ( tool->m_toolStyle == wxTOOL_STYLE_BUTTON && tool->m_bitmap1.Ok() )
wxToolBarToolBase *tool = node->GetData();
if ( tool->IsButton() )
{
HBITMAP hbmp = GetHbitmapOf(tool->m_bitmap1);
HBITMAP hbmp = GetHbitmapOf(tool->GetBitmap1());
if ( hbmp )
{
HBITMAP oldBitmap2 = (HBITMAP)::SelectObject(memoryDC2, hbmp);
@ -316,12 +378,20 @@ bool wxToolBar95::CreateTools()
}
::SelectObject(memoryDC2, oldBitmap2);
x += m_defaultWidth;
noButtons++;
}
else
{
wxFAIL_MSG( _T("invalid tool button bitmap") );
}
// still inc width and number of buttons because otherwise the
// subsequent buttons will all be shifted which is rather confusing
// (and like this you'd see immediately which bitmap was bad)
x += m_defaultWidth;
nButtons++;
}
node = node->Next();
node = node->GetNext();
}
::SelectObject(memoryDC, oldBitmap);
@ -329,7 +399,7 @@ bool wxToolBar95::CreateTools()
::DeleteDC(memoryDC2);
// Map to system colours
wxMapBitmap((HBITMAP) m_hBitmap, totalBitmapWidth, totalBitmapHeight);
wxMapBitmap(hBitmap, totalBitmapWidth, totalBitmapHeight);
if ( oldToolBarBitmap )
{
@ -337,59 +407,64 @@ bool wxToolBar95::CreateTools()
replaceBitmap.hInstOld = NULL;
replaceBitmap.hInstNew = NULL;
replaceBitmap.nIDOld = (UINT) oldToolBarBitmap;
replaceBitmap.nIDNew = (UINT) (HBITMAP) m_hBitmap;
replaceBitmap.nButtons = noButtons;
if ( ::SendMessage(GetHwnd(), TB_REPLACEBITMAP,
0, (LPARAM) &replaceBitmap) == -1 )
replaceBitmap.nIDNew = (UINT) hBitmap;
replaceBitmap.nButtons = nButtons;
if ( !::SendMessage(GetHwnd(), TB_REPLACEBITMAP,
0, (LPARAM) &replaceBitmap) )
{
wxFAIL_MSG(wxT("Could not add bitmap to toolbar"));
}
::DeleteObject((HBITMAP) oldToolBarBitmap);
::DeleteObject(oldToolBarBitmap);
// Now delete all the buttons
int i = 0;
while ( TRUE )
for ( size_t pos = 0; pos < m_nButtons; pos++ )
{
// TODO: What about separators???? They don't have an id!
if ( ! ::SendMessage( GetHwnd(), TB_DELETEBUTTON, i, 0 ) )
break;
if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON, 0, 0) )
{
wxLogLastError("TB_DELETEBUTTON");
}
}
}
else
else // no old bitmap
{
TBADDBITMAP addBitmap;
addBitmap.hInst = 0;
addBitmap.nID = (UINT)m_hBitmap;
addBitmap.nID = (UINT) hBitmap;
if ( ::SendMessage(GetHwnd(), TB_ADDBITMAP,
(WPARAM) noButtons, (LPARAM)&addBitmap) == -1 )
(WPARAM) nButtons, (LPARAM)&addBitmap) == -1 )
{
wxFAIL_MSG(wxT("Could not add bitmap to toolbar"));
}
}
// Now add the buttons.
// Next add the buttons and separators
// -----------------------------------
TBBUTTON *buttons = new TBBUTTON[nTools];
// this array will holds the indices of all controls in the toolbar
// this array will hold the indices of all controls in the toolbar
wxArrayInt controlIds;
int i = 0;
int bitmapId = 0;
node = m_tools.First();
while (node)
for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
{
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
wxToolBarToolBase *tool = node->GetData();
// don't add separators to the vertical toolbar - looks ugly
if ( isVertical && tool->IsSeparator() )
continue;
TBBUTTON& button = buttons[i];
wxZeroMemory(button);
switch ( tool->m_toolStyle )
switch ( tool->GetStyle() )
{
case wxTOOL_STYLE_CONTROL:
controlIds.Add(i);
button.idCommand = tool->m_index;
button.idCommand = tool->GetId();
// fall through: create just a separator too
case wxTOOL_STYLE_SEPARATOR:
@ -399,21 +474,21 @@ bool wxToolBar95::CreateTools()
case wxTOOL_STYLE_BUTTON:
button.iBitmap = bitmapId;
button.idCommand = tool->m_index;
button.idCommand = tool->GetId();
if (tool->m_enabled)
if ( tool->IsEnabled() )
button.fsState |= TBSTATE_ENABLED;
if (tool->m_toggleState)
if ( tool->IsToggled() )
button.fsState |= TBSTATE_CHECKED;
button.fsStyle = tool->m_isToggle ? TBSTYLE_CHECK
: TBSTYLE_BUTTON;
button.fsStyle = tool->CanBeToggled() ? TBSTYLE_CHECK
: TBSTYLE_BUTTON;
bitmapId++;
break;
}
i++;
node = node->Next();
}
if ( !::SendMessage(GetHwnd(), TB_ADDBUTTONS,
@ -424,12 +499,17 @@ bool wxToolBar95::CreateTools()
delete [] buttons;
// Deal with the controls finally
// ------------------------------
// adjust the controls size to fit nicely in the toolbar
size_t nControls = controlIds.GetCount();
for ( size_t nCtrl = 0; nCtrl < nControls; nCtrl++ )
size_t index = 0;
for ( node = m_tools.GetFirst(); node; node = node->GetNext(), index++ )
{
wxToolBarTool *tool = (wxToolBarTool *)
m_tools.Nth(controlIds[nCtrl])->Data();
wxToolBarToolBase *tool = node->GetData();
if ( !tool->IsControl() )
continue;
wxControl *control = tool->GetControl();
wxSize size = control->GetSize();
@ -437,6 +517,15 @@ bool wxToolBar95::CreateTools()
// the position of the leftmost controls corner
int left = -1;
// note that we use TB_GETITEMRECT and not TB_GETRECT because the
// latter only appeared in v4.70 of comctl32.dll
RECT r;
if ( !SendMessage(GetHwnd(), TB_GETITEMRECT,
index, (LPARAM)(LPRECT)&r) )
{
wxLogLastError("TB_GETITEMRECT");
}
// TB_SETBUTTONINFO message is only supported by comctl32.dll 4.71+
#if defined(_WIN32_IE) && (_WIN32_IE >= 0x400 )
// available in headers, now check whether it is available now
@ -450,9 +539,9 @@ bool wxToolBar95::CreateTools()
tbbi.dwMask = TBIF_SIZE;
tbbi.cx = size.x;
if ( !SendMessage(GetHwnd(), TB_SETBUTTONINFO,
tool->m_index, (LPARAM)&tbbi) )
tool->GetId(), (LPARAM)&tbbi) )
{
// the index is probably invalid
// the id is probably invalid?
wxLogLastError("TB_SETBUTTONINFO");
}
@ -461,18 +550,7 @@ bool wxToolBar95::CreateTools()
#endif // comctl32.dll 4.71
// TB_SETBUTTONINFO unavailable
{
int index = GetIndexFromId(tool->m_index);
wxASSERT_MSG( index != wxNOT_FOUND,
_T("control wasn't added to the tbar?") );
// try adding several separators to fit the controls width
RECT r;
if ( !SendMessage(GetHwnd(), TB_GETRECT,
tool->m_index, (LPARAM)(LPRECT)&r) )
{
wxLogLastError("TB_GETITEMRECT");
}
int widthSep = r.right - r.left;
left = r.left;
@ -485,27 +563,24 @@ bool wxToolBar95::CreateTools()
size_t nSeparators = size.x / widthSep;
for ( size_t nSep = 0; nSep < nSeparators; nSep++ )
{
m_ids.Insert(0, (size_t)index);
if ( !SendMessage(GetHwnd(), TB_INSERTBUTTON,
index, (LPARAM)&tbb) )
{
wxLogLastError("TB_INSERTBUTTON");
}
index++;
}
// remember the number of separators we used - we'd have to
// delete all of them later
((wxToolBarTool *)tool)->SetSeparatorsCount(nSeparators);
// adjust the controls width to exactly cover the separators
control->SetSize((nSeparators + 1)*widthSep, -1);
}
// and position the control itself correctly vertically
RECT r;
if ( !SendMessage(GetHwnd(), TB_GETRECT,
tool->m_index, (LPARAM)(LPRECT)&r) )
{
wxLogLastError("TB_GETRECT");
}
int height = r.bottom - r.top;
int diff = height - size.y;
if ( diff < 0 )
@ -516,12 +591,29 @@ bool wxToolBar95::CreateTools()
diff = 2;
}
control->Move(left == -1 ? r.left : left, r.top + diff / 2);
control->Move(left == -1 ? r.left : left, r.top + (diff + 1) / 2);
}
(void)::SendMessage(GetHwnd(), TB_AUTOSIZE, (WPARAM)0, (LPARAM) 0);
// the max index is the "real" number of buttons - i.e. counting even the
// separators which we added just for aligning the controls
m_nButtons = index;
SetRows(m_maxRows);
if ( !isVertical )
{
if ( m_maxRows == 0 )
{
// if not set yet, only one row
SetRows(1);
}
}
else if ( m_nButtons > 0 ) // vertical non empty toolbar
{
if ( m_maxRows == 0 )
{
// if not set yet, have one column
SetRows(m_nButtons);
}
}
return TRUE;
}
@ -530,31 +622,35 @@ bool wxToolBar95::CreateTools()
// message handlers
// ----------------------------------------------------------------------------
bool wxToolBar95::MSWCommand(WXUINT cmd, WXWORD id)
bool wxToolBar::MSWCommand(WXUINT cmd, WXWORD id)
{
wxNode *node = m_tools.Find((long)id);
if (!node)
wxToolBarToolBase *tool = FindById((int)id);
if ( !tool )
return FALSE;
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
if (tool->m_isToggle)
if ( tool->CanBeToggled() )
{
LRESULT state = ::SendMessage(GetHwnd(), TB_GETSTATE, id, 0);
tool->m_toggleState = state & TBSTATE_CHECKED;
tool->SetToggle((state & TBSTATE_CHECKED) != 0);
}
BOOL ret = OnLeftClick((int)id, tool->m_toggleState);
if ( ret == FALSE && tool->m_isToggle )
bool toggled = tool->IsToggled();
// OnLeftClick() can veto the button state change - for buttons which may
// be toggled only, of couse
if ( !OnLeftClick((int)id, toggled) && tool->CanBeToggled() )
{
tool->m_toggleState = !tool->m_toggleState;
::SendMessage(GetHwnd(), TB_CHECKBUTTON,
(WPARAM)id, (LPARAM)MAKELONG(tool->m_toggleState, 0));
// revert back
toggled = !toggled;
tool->SetToggle(toggled);
::SendMessage(GetHwnd(), TB_CHECKBUTTON, id, MAKELONG(toggled, 0));
}
return TRUE;
}
bool wxToolBar95::MSWOnNotify(int WXUNUSED(idCtrl),
bool wxToolBar::MSWOnNotify(int WXUNUSED(idCtrl),
WXLPARAM lParam,
WXLPARAM *result)
{
@ -573,13 +669,12 @@ bool wxToolBar95::MSWOnNotify(int WXUNUSED(idCtrl),
LPTOOLTIPTEXT ttText = (LPTOOLTIPTEXT)lParam;
int id = (int)ttText->hdr.idFrom;
wxNode *node = m_tools.Find((long)id);
if (!node)
wxToolBarToolBase *tool = FindById(id);
if ( !tool )
return FALSE;
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
const wxString& help = tool->m_shortHelpString;
const wxString& help = tool->GetShortHelp();
if ( !help.IsEmpty() )
{
@ -617,91 +712,116 @@ bool wxToolBar95::MSWOnNotify(int WXUNUSED(idCtrl),
}
// For backward compatibility...
OnMouseEnter(tool->m_index);
OnMouseEnter(tool->GetId());
return TRUE;
}
// ----------------------------------------------------------------------------
// sizing stuff
// toolbar geometry
// ----------------------------------------------------------------------------
void wxToolBar95::SetToolBitmapSize(const wxSize& size)
void wxToolBar::SetToolBitmapSize(const wxSize& size)
{
wxToolBarBase::SetToolBitmapSize(size);
::SendMessage(GetHwnd(), TB_SETBITMAPSIZE, 0, MAKELONG(size.x, size.y));
}
void wxToolBar95::SetRows(int nRows)
void wxToolBar::SetRows(int nRows)
{
// TRUE in wParam means to create at least as many rows
RECT rect;
::SendMessage(GetHwnd(), TB_SETROWS,
MAKEWPARAM(nRows, TRUE), (LPARAM) &rect);
m_maxWidth = (rect.right - rect.left + 2);
m_maxHeight = (rect.bottom - rect.top + 2);
m_maxRows = nRows;
}
wxSize wxToolBar95::GetMaxSize() const
{
if ( (m_maxWidth == -1) || (m_maxHeight == -1) )
if ( nRows == m_maxRows )
{
// it has a side effect of filling m_maxWidth/Height variables
((wxToolBar95 *)this)->SetRows(m_maxRows); // const_cast
// avoid resizing the frame uselessly
return;
}
return wxSize(m_maxWidth, m_maxHeight);
// TRUE in wParam means to create at least as many rows, FALSE -
// at most as many
RECT rect;
::SendMessage(GetHwnd(), TB_SETROWS,
MAKEWPARAM(nRows, !(GetWindowStyle() & wxTB_VERTICAL)),
(LPARAM) &rect);
m_maxRows = nRows;
UpdateSize();
}
// The button size is bigger than the bitmap size
wxSize wxToolBar95::GetToolSize() const
wxSize wxToolBar::GetToolSize() const
{
// FIXME: this is completely bogus (VZ)
return wxSize(m_defaultWidth + 8, m_defaultHeight + 7);
// TB_GETBUTTONSIZE is supported from version 4.70
#if defined(_WIN32_IE) && (_WIN32_IE >= 0x300 )
if ( wxTheApp->GetComCtl32Version() >= 470 )
{
DWORD dw = ::SendMessage(GetHwnd(), TB_GETBUTTONSIZE, 0, 0);
return wxSize(LOWORD(dw), HIWORD(dw));
}
else
#endif // comctl32.dll 4.70+
{
// defaults
return wxSize(m_defaultWidth + 8, m_defaultHeight + 7);
}
}
wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const
{
POINT pt;
pt.x = x;
pt.y = y;
int index = (int)::SendMessage(GetHwnd(), TB_HITTEST, 0, (LPARAM)&pt);
if ( index < 0 )
{
// it's a separator or there is no tool at all there
return (wxToolBarToolBase *)NULL;
}
return m_tools.Item((size_t)index)->GetData();
}
void wxToolBar::UpdateSize()
{
// we must refresh the frame after the toolbar size (possibly) changed
wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
if ( frame )
{
// don't change the size, we just need to generate a WM_SIZE
RECT r;
if ( !GetWindowRect(GetHwndOf(frame), &r) )
{
wxLogLastError(_T("GetWindowRect"));
}
(void)::SendMessage(GetHwndOf(frame), WM_SIZE, SIZE_RESTORED,
MAKELPARAM(r.right - r.left, r.bottom - r.top));
}
}
// ----------------------------------------------------------------------------
// tool state
// ----------------------------------------------------------------------------
void wxToolBar95::EnableTool(int toolIndex, bool enable)
void wxToolBar::DoEnableTool(wxToolBarToolBase *tool, bool enable)
{
wxNode *node = m_tools.Find((long)toolIndex);
if (node)
{
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
tool->m_enabled = enable;
::SendMessage(GetHwnd(), TB_ENABLEBUTTON,
(WPARAM)toolIndex, (LPARAM)MAKELONG(enable, 0));
}
::SendMessage(GetHwnd(), TB_ENABLEBUTTON,
(WPARAM)tool->GetId(), (LPARAM)MAKELONG(enable, 0));
}
void wxToolBar95::ToggleTool(int toolIndex, bool toggle)
void wxToolBar::DoToggleTool(wxToolBarToolBase *tool, bool toggle)
{
wxNode *node = m_tools.Find((long)toolIndex);
if (node)
{
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
if (tool->m_isToggle)
{
tool->m_toggleState = toggle;
::SendMessage(GetHwnd(), TB_CHECKBUTTON,
(WPARAM)toolIndex, (LPARAM)MAKELONG(toggle, 0));
}
}
::SendMessage(GetHwnd(), TB_CHECKBUTTON,
(WPARAM)tool->GetId(), (LPARAM)MAKELONG(toggle, 0));
}
bool wxToolBar95::GetToolState(int toolIndex) const
void wxToolBar::DoSetToggle(wxToolBarToolBase *tool, bool toggle)
{
wxASSERT_MSG( GetIndexFromId(toolIndex) != wxNOT_FOUND,
_T("invalid toolbar button id") );
return ::SendMessage(GetHwnd(), TB_ISBUTTONCHECKED,
(WPARAM)toolIndex, (LPARAM)0) != 0;
// VZ: AFAIK, the button has to be created either with TBSTYLE_CHECK or
// without, so we really need to delete the button and recreate it here
wxFAIL_MSG( _T("not implemented") );
}
// ----------------------------------------------------------------------------
@ -709,13 +829,13 @@ bool wxToolBar95::GetToolState(int toolIndex) const
// ----------------------------------------------------------------------------
// Responds to colour changes, and passes event on to children.
void wxToolBar95::OnSysColourChanged(wxSysColourChangedEvent& event)
void wxToolBar::OnSysColourChanged(wxSysColourChangedEvent& event)
{
m_backgroundColour = wxColour(GetRValue(GetSysColor(COLOR_BTNFACE)),
GetGValue(GetSysColor(COLOR_BTNFACE)), GetBValue(GetSysColor(COLOR_BTNFACE)));
// Remap the buttons
CreateTools();
Realize();
Refresh();
@ -723,7 +843,7 @@ void wxToolBar95::OnSysColourChanged(wxSysColourChangedEvent& event)
wxWindow::OnSysColourChanged(event);
}
void wxToolBar95::OnMouseEvent(wxMouseEvent& event)
void wxToolBar::OnMouseEvent(wxMouseEvent& event)
{
if (event.RightDown())
{
@ -737,21 +857,50 @@ void wxToolBar95::OnMouseEvent(wxMouseEvent& event)
}
}
// ----------------------------------------------------------------------------
// helpers
// ----------------------------------------------------------------------------
int wxToolBar95::GetIndexFromId(int id) const
long wxToolBar::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
{
size_t count = m_ids.GetCount();
for ( size_t n = 0; n < count; n++ )
if ( nMsg == WM_SIZE )
{
if ( m_ids[n] == id )
return n;
// calculate our minor dimenstion ourselves - we're confusing the
// standard logic (TB_AUTOSIZE) with our horizontal toolbars and other
// hacks
RECT r;
if ( ::SendMessage(GetHwnd(), TB_GETITEMRECT, 0, (LPARAM)&r) )
{
int w, h;
if ( GetWindowStyle() & wxTB_VERTICAL )
{
w = r.right - r.left;
if ( m_maxRows )
{
w *= (m_nButtons + m_maxRows - 1)/m_maxRows;
}
h = HIWORD(lParam);
}
else
{
w = LOWORD(lParam);
h = r.bottom - r.top;
if ( m_maxRows )
{
h += 6; // FIXME: this is the separator line height...
h *= m_maxRows;
}
}
if ( MAKELPARAM(w, h) != lParam )
{
// size really changed
SetSize(w, h);
}
// message processed
return 0;
}
}
return wxNOT_FOUND;
return wxControl::MSWWindowProc(nMsg, wParam, lParam);
}
// ----------------------------------------------------------------------------
@ -766,7 +915,7 @@ int wxToolBar95::GetIndexFromId(int id) const
#define BGR_BUTTONSHADOW (RGB(128,128,128)) // dark grey
#define BGR_BUTTONFACE (RGB(192,192,192)) // bright grey
#define BGR_BUTTONHILIGHT (RGB(255,255,255)) // white
#define BGR_BACKGROUNDSEL (RGB(000,000,255)) // blue
#define BGR_BACKGROUNDSEL (RGB(255,000,000)) // blue
#define BGR_BACKGROUND (RGB(255,000,255)) // magenta
void wxMapBitmap(HBITMAP hBitmap, int width, int height)
@ -856,4 +1005,4 @@ void wxMapBitmap(HBITMAP hBitmap, int width, int height)
#endif
#endif // !(wxUSE_TOOLBAR && Win95)
#endif // wxUSE_TOOLBAR && Win95

File diff suppressed because it is too large Load Diff