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:
parent
56f5d962ad
commit
8a0681f933
@ -4,139 +4,92 @@
|
|||||||
// Author: Robert Roebling
|
// Author: Robert Roebling
|
||||||
// RCS-ID: $Id$
|
// RCS-ID: $Id$
|
||||||
// Copyright: (c) Robert Roebling
|
// Copyright: (c) Robert Roebling
|
||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef __TBARGTKH__
|
#ifndef _WX_GTK_TBARGTK_H_
|
||||||
#define __TBARGTKH__
|
#define _WX_GTK_TBARGTK_H_
|
||||||
|
|
||||||
#ifdef __GNUG__
|
#ifdef __GNUG__
|
||||||
#pragma interface
|
#pragma interface "tbargtk.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/defs.h"
|
|
||||||
|
|
||||||
#if wxUSE_TOOLBAR
|
#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
|
// wxToolBar
|
||||||
//-----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
class wxToolBar: public wxControl
|
class wxToolBar : public wxToolBarBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxToolBar();
|
// construction/destruction
|
||||||
wxToolBar( wxWindow *parent, wxWindowID id,
|
wxToolBar() { Init(); }
|
||||||
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
|
wxToolBar( wxWindow *parent,
|
||||||
long style = 0, const wxString& name = wxToolBarNameStr );
|
wxWindowID id,
|
||||||
~wxToolBar();
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
|
const wxSize& size = wxDefaultSize,
|
||||||
|
long style = 0,
|
||||||
|
const wxString& name = wxToolBarNameStr )
|
||||||
|
{
|
||||||
|
Init();
|
||||||
|
|
||||||
bool Create( wxWindow *parent, wxWindowID id,
|
Create(parent, id, pos, size, style, name);
|
||||||
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
|
}
|
||||||
long style = 0, const wxString& name = wxToolBarNameStr);
|
|
||||||
|
|
||||||
// Only allow toggle if returns TRUE. Call when left button up.
|
bool Create( wxWindow *parent,
|
||||||
virtual bool OnLeftClick(int toolIndex, bool toggleDown);
|
wxWindowID id,
|
||||||
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
|
const wxSize& size = wxDefaultSize,
|
||||||
|
long style = 0,
|
||||||
|
const wxString& name = wxToolBarNameStr );
|
||||||
|
|
||||||
// Call when right button down.
|
virtual ~wxToolBar();
|
||||||
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;
|
|
||||||
|
|
||||||
|
// override base class virtuals
|
||||||
virtual void SetMargins(int x, int y);
|
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 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;
|
GtkToolbar *m_toolbar;
|
||||||
int m_separation;
|
|
||||||
wxList m_tools;
|
GdkColor *m_fg;
|
||||||
|
GdkColor *m_bg;
|
||||||
GdkColor *m_fg;
|
|
||||||
GdkColor *m_bg;
|
|
||||||
int m_xMargin;
|
|
||||||
int m_yMargin;
|
|
||||||
bool m_hasToolAlready;
|
|
||||||
bool m_blockNextEvent;
|
bool m_blockNextEvent;
|
||||||
|
|
||||||
void OnInternalIdle();
|
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:
|
private:
|
||||||
DECLARE_EVENT_TABLE()
|
|
||||||
DECLARE_DYNAMIC_CLASS(wxToolBar)
|
DECLARE_DYNAMIC_CLASS(wxToolBar)
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // wxUSE_TOOLBAR
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
// __TBARGTKH__
|
// _WX_GTK_TBARGTK_H_
|
||||||
|
@ -4,139 +4,92 @@
|
|||||||
// Author: Robert Roebling
|
// Author: Robert Roebling
|
||||||
// RCS-ID: $Id$
|
// RCS-ID: $Id$
|
||||||
// Copyright: (c) Robert Roebling
|
// Copyright: (c) Robert Roebling
|
||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef __TBARGTKH__
|
#ifndef _WX_GTK_TBARGTK_H_
|
||||||
#define __TBARGTKH__
|
#define _WX_GTK_TBARGTK_H_
|
||||||
|
|
||||||
#ifdef __GNUG__
|
#ifdef __GNUG__
|
||||||
#pragma interface
|
#pragma interface "tbargtk.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/defs.h"
|
|
||||||
|
|
||||||
#if wxUSE_TOOLBAR
|
#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
|
// wxToolBar
|
||||||
//-----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
class wxToolBar: public wxControl
|
class wxToolBar : public wxToolBarBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxToolBar();
|
// construction/destruction
|
||||||
wxToolBar( wxWindow *parent, wxWindowID id,
|
wxToolBar() { Init(); }
|
||||||
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
|
wxToolBar( wxWindow *parent,
|
||||||
long style = 0, const wxString& name = wxToolBarNameStr );
|
wxWindowID id,
|
||||||
~wxToolBar();
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
|
const wxSize& size = wxDefaultSize,
|
||||||
|
long style = 0,
|
||||||
|
const wxString& name = wxToolBarNameStr )
|
||||||
|
{
|
||||||
|
Init();
|
||||||
|
|
||||||
bool Create( wxWindow *parent, wxWindowID id,
|
Create(parent, id, pos, size, style, name);
|
||||||
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
|
}
|
||||||
long style = 0, const wxString& name = wxToolBarNameStr);
|
|
||||||
|
|
||||||
// Only allow toggle if returns TRUE. Call when left button up.
|
bool Create( wxWindow *parent,
|
||||||
virtual bool OnLeftClick(int toolIndex, bool toggleDown);
|
wxWindowID id,
|
||||||
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
|
const wxSize& size = wxDefaultSize,
|
||||||
|
long style = 0,
|
||||||
|
const wxString& name = wxToolBarNameStr );
|
||||||
|
|
||||||
// Call when right button down.
|
virtual ~wxToolBar();
|
||||||
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;
|
|
||||||
|
|
||||||
|
// override base class virtuals
|
||||||
virtual void SetMargins(int x, int y);
|
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 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;
|
GtkToolbar *m_toolbar;
|
||||||
int m_separation;
|
|
||||||
wxList m_tools;
|
GdkColor *m_fg;
|
||||||
|
GdkColor *m_bg;
|
||||||
GdkColor *m_fg;
|
|
||||||
GdkColor *m_bg;
|
|
||||||
int m_xMargin;
|
|
||||||
int m_yMargin;
|
|
||||||
bool m_hasToolAlready;
|
|
||||||
bool m_blockNextEvent;
|
bool m_blockNextEvent;
|
||||||
|
|
||||||
void OnInternalIdle();
|
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:
|
private:
|
||||||
DECLARE_EVENT_TABLE()
|
|
||||||
DECLARE_DYNAMIC_CLASS(wxToolBar)
|
DECLARE_DYNAMIC_CLASS(wxToolBar)
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // wxUSE_TOOLBAR
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
// __TBARGTKH__
|
// _WX_GTK_TBARGTK_H_
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: toolbar.h
|
// Name: wx/motif/toolbar.h
|
||||||
// Purpose: wxToolBar class
|
// Purpose: wxToolBar class
|
||||||
// Author: Julian Smart
|
// Author: Julian Smart
|
||||||
// Modified by:
|
// Modified by: 13.12.99 by VZ during toolbar classes reorganization
|
||||||
// Created: 17/09/98
|
// Created: 17/09/98
|
||||||
// RCS-ID: $Id$
|
// RCS-ID: $Id$
|
||||||
// Copyright: (c) Julian Smart
|
// Copyright: (c) Julian Smart
|
||||||
@ -13,81 +13,60 @@
|
|||||||
#define _WX_TOOLBAR_H_
|
#define _WX_TOOLBAR_H_
|
||||||
|
|
||||||
#ifdef __GNUG__
|
#ifdef __GNUG__
|
||||||
#pragma interface "toolbar.h"
|
#pragma interface "toolbar.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/tbarbase.h"
|
class WXDLLEXPORT wxToolBar : public wxToolBarBase
|
||||||
|
|
||||||
WXDLLEXPORT_DATA(extern const char*) wxToolBarNameStr;
|
|
||||||
|
|
||||||
class WXDLLEXPORT wxToolBar: public wxToolBarBase
|
|
||||||
{
|
{
|
||||||
DECLARE_DYNAMIC_CLASS(wxToolBar)
|
public:
|
||||||
public:
|
// ctors and dtor
|
||||||
/*
|
wxToolBar() { Init(); }
|
||||||
* Public interface
|
|
||||||
*/
|
|
||||||
|
|
||||||
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,
|
Create(parent, id, pos, size, style, name);
|
||||||
long style = wxNO_BORDER|wxTB_HORIZONTAL,
|
}
|
||||||
const wxString& name = wxToolBarNameStr):
|
|
||||||
m_widgets(wxKEY_INTEGER)
|
|
||||||
|
|
||||||
{
|
bool Create(wxWindow *parent,
|
||||||
Create(parent, id, pos, size, style, name);
|
wxWindowID id,
|
||||||
}
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
~wxToolBar();
|
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,
|
virtual ~wxToolBar();
|
||||||
long style = wxNO_BORDER|wxTB_HORIZONTAL,
|
|
||||||
const wxString& name = wxToolBarNameStr);
|
|
||||||
|
|
||||||
// If pushedBitmap is NULL, a reversed version of bitmap is
|
// override/implement base class virtuals
|
||||||
// created and used as the pushed/toggled image.
|
virtual wxToolBarTool *FindToolForPosition(wxCoord x, wxCoord y) const;
|
||||||
// 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 = "");
|
|
||||||
|
|
||||||
// Set default bitmap size
|
virtual bool Realize();
|
||||||
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();
|
|
||||||
|
|
||||||
// The button size is bigger than the bitmap size
|
// implementation from now on
|
||||||
wxSize GetToolSize() const;
|
|
||||||
|
|
||||||
wxSize GetMaxSize() const;
|
// find tool by widget
|
||||||
|
wxToolBarTool *FindToolByWidget(WXWidget w) 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;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// List of widgets in the toolbar, indexed by tool index
|
// common part of all ctors
|
||||||
wxList m_widgets;
|
void Init();
|
||||||
|
|
||||||
// List of pixmaps to destroy when tools are recreated or
|
// implement base class pure virtuals
|
||||||
// or toolbar is destroyed.
|
virtual bool DoInsertTool(size_t pos, wxToolBarTool *tool);
|
||||||
wxList m_pixmaps;
|
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
|
#endif
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: wx/msw/tbar95.h
|
// Name: wx/msw/tbar95.h
|
||||||
// Purpose: wxToolBar95 (Windows 95 toolbar) class
|
// Purpose: wxToolBar (Windows 95 toolbar) class
|
||||||
// Author: Julian Smart
|
// Author: Julian Smart
|
||||||
// Modified by:
|
// Modified by:
|
||||||
// Created: 01/02/97
|
// Created: 01/02/97
|
||||||
@ -13,21 +13,20 @@
|
|||||||
#define _WX_TBAR95_H_
|
#define _WX_TBAR95_H_
|
||||||
|
|
||||||
#ifdef __GNUG__
|
#ifdef __GNUG__
|
||||||
#pragma interface "tbar95.h"
|
#pragma interface "tbar95.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if wxUSE_TOOLBAR
|
#if wxUSE_TOOLBAR
|
||||||
|
|
||||||
#include "wx/dynarray.h"
|
#include "wx/dynarray.h"
|
||||||
|
|
||||||
#include "wx/tbarbase.h"
|
class WXDLLEXPORT wxToolBar : public wxToolBarBase
|
||||||
|
|
||||||
class WXDLLEXPORT wxToolBar95 : public wxToolBarBase
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxToolBar95() { Init(); }
|
// ctors and dtor
|
||||||
|
wxToolBar() { Init(); }
|
||||||
|
|
||||||
wxToolBar95(wxWindow *parent,
|
wxToolBar(wxWindow *parent,
|
||||||
wxWindowID id,
|
wxWindowID id,
|
||||||
const wxPoint& pos = wxDefaultPosition,
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
const wxSize& size = wxDefaultSize,
|
const wxSize& size = wxDefaultSize,
|
||||||
@ -39,8 +38,6 @@ public:
|
|||||||
Create(parent, id, pos, size, style, name);
|
Create(parent, id, pos, size, style, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
~wxToolBar95();
|
|
||||||
|
|
||||||
bool Create(wxWindow *parent,
|
bool Create(wxWindow *parent,
|
||||||
wxWindowID id,
|
wxWindowID id,
|
||||||
const wxPoint& pos = wxDefaultPosition,
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
@ -48,36 +45,21 @@ public:
|
|||||||
long style = wxNO_BORDER | wxTB_HORIZONTAL,
|
long style = wxNO_BORDER | wxTB_HORIZONTAL,
|
||||||
const wxString& name = wxToolBarNameStr);
|
const wxString& name = wxToolBarNameStr);
|
||||||
|
|
||||||
// override base class virtuals
|
virtual ~wxToolBar();
|
||||||
|
|
||||||
virtual wxToolBarTool *AddTool(int toolIndex,
|
// override/implement base class virtuals
|
||||||
const wxBitmap& bitmap,
|
virtual wxToolBarToolBase *FindToolForPosition(wxCoord x, wxCoord y) const;
|
||||||
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);
|
|
||||||
|
|
||||||
virtual bool DeleteTool(int toolIndex);
|
virtual bool Realize();
|
||||||
virtual void ClearTools();
|
|
||||||
|
|
||||||
virtual bool Realize() { return CreateTools(); };
|
|
||||||
|
|
||||||
virtual void EnableTool(int toolIndex, bool enable);
|
|
||||||
virtual void ToggleTool(int toolIndex, bool toggle);
|
|
||||||
|
|
||||||
virtual void SetToolBitmapSize(const wxSize& size);
|
virtual void SetToolBitmapSize(const wxSize& size);
|
||||||
virtual wxSize GetToolSize() const;
|
virtual wxSize GetToolSize() const;
|
||||||
virtual wxSize GetMaxSize() const;
|
|
||||||
|
|
||||||
virtual bool GetToolState(int toolIndex) const;
|
|
||||||
|
|
||||||
virtual bool CreateTools();
|
|
||||||
virtual void SetRows(int nRows);
|
virtual void SetRows(int nRows);
|
||||||
|
|
||||||
// IMPLEMENTATION
|
// implementation only from now on
|
||||||
|
// -------------------------------
|
||||||
|
|
||||||
virtual bool MSWCommand(WXUINT param, WXWORD id);
|
virtual bool MSWCommand(WXUINT param, WXWORD id);
|
||||||
virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
|
virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
|
||||||
|
|
||||||
@ -88,34 +70,37 @@ protected:
|
|||||||
// common part of all ctors
|
// common part of all ctors
|
||||||
void Init();
|
void Init();
|
||||||
|
|
||||||
// the array storing the id for each index
|
// implement base class pure virtuals
|
||||||
wxArrayInt m_ids;
|
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)
|
virtual void DoEnableTool(wxToolBarToolBase *tool, bool enable);
|
||||||
int GetIndexFromId(int id) const;
|
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
|
// the big bitmap containing all bitmaps of the toolbar buttons
|
||||||
WXHBITMAP m_hBitmap;
|
WXHBITMAP m_hBitmap;
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
// the total number of toolbar elements
|
||||||
};
|
size_t m_nButtons;
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
DECLARE_EVENT_TABLE()
|
||||||
DECLARE_DYNAMIC_CLASS(wxToolBar)
|
DECLARE_DYNAMIC_CLASS(wxToolBar)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: tbarmsw.h
|
// Name: wx/msw/tbarmsw.h
|
||||||
// Purpose: wxToolBarMSW class
|
// Purpose: wxToolBar for Win16
|
||||||
// Author: Julian Smart
|
// Author: Julian Smart
|
||||||
// Modified by:
|
// Modified by: 13.12.99 by VZ during toolbar classes reorganization
|
||||||
// Created: 01/02/97
|
// Created: 01/02/97
|
||||||
// RCS-ID: $Id$
|
// RCS-ID: $Id$
|
||||||
// Copyright: (c) Julian Smart
|
// Copyright: (c) Julian Smart
|
||||||
@ -24,117 +24,123 @@ WXDLLEXPORT_DATA(extern const wxChar*) wxButtonBarNameStr;
|
|||||||
|
|
||||||
class WXDLLEXPORT wxMemoryDC;
|
class WXDLLEXPORT wxMemoryDC;
|
||||||
|
|
||||||
// Non-Win95 (WIN32, WIN16, UNIX) version
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxToolBar for Win16
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
class WXDLLEXPORT wxToolBarMSW: public wxToolBarBase
|
class WXDLLEXPORT wxToolBar : 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
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxToolBar() { }
|
// construction
|
||||||
|
wxToolBar() { Init(); }
|
||||||
|
|
||||||
wxToolBar(wxWindow *parent,
|
wxToolBar(wxWindow *parent,
|
||||||
wxWindowID id,
|
wxWindowID id,
|
||||||
const wxPoint& pos = wxDefaultPosition,
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
const wxSize& size = wxDefaultSize,
|
const wxSize& size = wxDefaultSize,
|
||||||
long style = wxNO_BORDER | wxTB_HORIZONTAL,
|
long style = wxNO_BORDER|wxTB_HORIZONTAL,
|
||||||
const wxString& name = wxToolBarNameStr)
|
const wxString& name = wxButtonBarNameStr)
|
||||||
: wxToolBarMSW(parent, id, pos, size, style, name)
|
|
||||||
{
|
{
|
||||||
|
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:
|
private:
|
||||||
|
DECLARE_EVENT_TABLE()
|
||||||
DECLARE_DYNAMIC_CLASS(wxToolBar)
|
DECLARE_DYNAMIC_CLASS(wxToolBar)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -26,7 +26,8 @@
|
|||||||
#include "wx/list.h"
|
#include "wx/list.h"
|
||||||
#include "wx/control.h"
|
#include "wx/control.h"
|
||||||
|
|
||||||
class WXDLLEXPORT wxToolBar;
|
class WXDLLEXPORT wxToolBarBase;
|
||||||
|
class WXDLLEXPORT wxToolBarToolBase;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// constants
|
// constants
|
||||||
@ -36,7 +37,7 @@ WXDLLEXPORT_DATA(extern const wxChar*) wxToolBarNameStr;
|
|||||||
WXDLLEXPORT_DATA(extern const wxSize) wxDefaultSize;
|
WXDLLEXPORT_DATA(extern const wxSize) wxDefaultSize;
|
||||||
WXDLLEXPORT_DATA(extern const wxPoint) wxDefaultPosition;
|
WXDLLEXPORT_DATA(extern const wxPoint) wxDefaultPosition;
|
||||||
|
|
||||||
enum
|
enum wxToolBarToolStyle
|
||||||
{
|
{
|
||||||
wxTOOL_STYLE_BUTTON = 1,
|
wxTOOL_STYLE_BUTTON = 1,
|
||||||
wxTOOL_STYLE_SEPARATOR = 2,
|
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:
|
public:
|
||||||
// ctors & dtor
|
// 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__
|
m_bitmap1 = bitmap1;
|
||||||
wxToolBarTool(wxToolBar *owner,
|
m_bitmap2 = bitmap2;
|
||||||
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
|
|
||||||
|
|
||||||
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
|
// accessors
|
||||||
// ---------
|
// ---------
|
||||||
|
|
||||||
void SetSize( long w, long h ) { m_width = w; m_height = h; }
|
// general
|
||||||
long GetWidth() const { return m_width; }
|
int GetId() const { return m_id; }
|
||||||
long GetHeight() const { return m_height; }
|
|
||||||
|
|
||||||
wxControl *GetControl() const
|
wxControl *GetControl() const
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( m_toolStyle == wxTOOL_STYLE_CONTROL,
|
wxASSERT_MSG( IsControl(), _T("this toolbar tool is not a control") );
|
||||||
_T("this toolbar tool is not a control") );
|
|
||||||
|
|
||||||
return m_control;
|
return m_control;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
wxToolBarBase *GetToolBar() const { return m_tbar; }
|
||||||
int m_toolStyle;
|
|
||||||
int m_index;
|
// 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
|
// as controls have their own client data, no need to waste memory
|
||||||
union
|
union
|
||||||
@ -106,33 +175,23 @@ public:
|
|||||||
wxControl *m_control;
|
wxControl *m_control;
|
||||||
};
|
};
|
||||||
|
|
||||||
wxCoord m_x;
|
// tool state
|
||||||
wxCoord m_y;
|
bool m_toggled;
|
||||||
wxCoord m_width;
|
bool m_isToggle;
|
||||||
wxCoord m_height;
|
bool m_enabled;
|
||||||
|
|
||||||
bool m_toggleState;
|
// normal and toggles bitmaps
|
||||||
bool m_isToggle;
|
wxBitmap m_bitmap1;
|
||||||
bool m_enabled;
|
wxBitmap m_bitmap2;
|
||||||
bool m_isMenuCommand;
|
|
||||||
|
|
||||||
bool m_deleteSecondBitmap;
|
// short and long help strings
|
||||||
wxBitmap m_bitmap1;
|
wxString m_shortHelpString;
|
||||||
wxBitmap m_bitmap2;
|
wxString m_longHelpString;
|
||||||
|
|
||||||
wxString m_shortHelpString;
|
|
||||||
wxString m_longHelpString;
|
|
||||||
|
|
||||||
#ifdef __WXGTK__
|
|
||||||
wxToolBar *m_owner;
|
|
||||||
GtkWidget *m_item;
|
|
||||||
GtkWidget *m_pixmap;
|
|
||||||
#endif // GTK
|
|
||||||
|
|
||||||
private:
|
|
||||||
DECLARE_DYNAMIC_CLASS(wxToolBarTool)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// a list of toolbar tools
|
||||||
|
WX_DECLARE_LIST(wxToolBarToolBase, wxToolBarToolsList);
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// the base class for all toolbars
|
// the base class for all toolbars
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -141,7 +200,7 @@ class WXDLLEXPORT wxToolBarBase : public wxControl
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxToolBarBase();
|
wxToolBarBase();
|
||||||
~wxToolBarBase();
|
virtual ~wxToolBarBase();
|
||||||
|
|
||||||
// toolbar construction
|
// toolbar construction
|
||||||
// --------------------
|
// --------------------
|
||||||
@ -149,50 +208,93 @@ public:
|
|||||||
// If pushedBitmap is NULL, a reversed version of bitmap is created and
|
// 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
|
// used as the pushed/toggled image. If toggle is TRUE, the button toggles
|
||||||
// between the two states.
|
// 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& bitmap,
|
||||||
const wxBitmap& pushedBitmap = wxNullBitmap,
|
const wxBitmap& pushedBitmap,
|
||||||
bool toggle = FALSE,
|
bool toggle,
|
||||||
wxCoord xPos = -1,
|
wxCoord xPos,
|
||||||
wxCoord yPos = -1,
|
wxCoord yPos = -1,
|
||||||
wxObject *clientData = NULL,
|
wxObject *clientData = NULL,
|
||||||
const wxString& helpString1 = wxEmptyString,
|
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
|
// insert the new tool at the given position, if pos == GetToolsCount(), it
|
||||||
// ok (notice that the control will be deleted by the toolbar and that it
|
// is equivalent to AddTool()
|
||||||
// will also adjust its position/size)
|
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
|
// 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();
|
virtual void ClearTools();
|
||||||
|
|
||||||
// must be called after all buttons have been created to finish toolbar
|
// must be called after all buttons have been created to finish toolbar
|
||||||
// initialisation
|
// initialisation
|
||||||
virtual bool Realize() = 0;
|
virtual bool Realize();
|
||||||
|
|
||||||
// tools state
|
// tools state
|
||||||
// -----------
|
// -----------
|
||||||
|
|
||||||
virtual void EnableTool(int toolIndex, bool enable);
|
virtual void EnableTool(int id, bool enable);
|
||||||
|
virtual void ToggleTool(int id, bool toggle);
|
||||||
// toggle is TRUE if toggled on
|
|
||||||
virtual void ToggleTool(int toolIndex, bool toggle);
|
|
||||||
|
|
||||||
// Set this to be togglable (or not)
|
// 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 wxObject *GetToolClientData(int index) const;
|
||||||
|
|
||||||
virtual bool GetToolState(int toolIndex) const;
|
// return TRUE if the tool is toggled
|
||||||
virtual bool GetToolEnabled(int toolIndex) const;
|
virtual bool GetToolState(int id) const;
|
||||||
virtual wxToolBarTool *FindToolForPosition(long x, long y) const;
|
|
||||||
|
|
||||||
virtual void SetToolShortHelp(int toolIndex, const wxString& helpString);
|
virtual bool GetToolEnabled(int id) const;
|
||||||
virtual wxString GetToolShortHelp(int toolIndex) const;
|
|
||||||
virtual void SetToolLongHelp(int toolIndex, const wxString& helpString);
|
virtual void SetToolShortHelp(int id, const wxString& helpString);
|
||||||
virtual wxString GetToolLongHelp(int toolIndex) const;
|
virtual wxString GetToolShortHelp(int id) const;
|
||||||
|
virtual void SetToolLongHelp(int id, const wxString& helpString);
|
||||||
|
virtual wxString GetToolLongHelp(int id) const;
|
||||||
|
|
||||||
// margins/packing/separation
|
// margins/packing/separation
|
||||||
// --------------------------
|
// --------------------------
|
||||||
@ -200,48 +302,58 @@ public:
|
|||||||
virtual void SetMargins(int x, int y);
|
virtual void SetMargins(int x, int y);
|
||||||
void SetMargins(const wxSize& size)
|
void SetMargins(const wxSize& size)
|
||||||
{ SetMargins((int) size.x, (int) size.y); }
|
{ SetMargins((int) size.x, (int) size.y); }
|
||||||
virtual void SetToolPacking(int packing);
|
virtual void SetToolPacking(int packing)
|
||||||
virtual void SetToolSeparation(int separation);
|
{ m_toolPacking = packing; }
|
||||||
|
virtual void SetToolSeparation(int separation)
|
||||||
|
{ m_toolSeparation = separation; }
|
||||||
|
|
||||||
virtual wxSize GetToolMargins() { return wxSize(m_xMargin, m_yMargin); }
|
virtual wxSize GetToolMargins() { return wxSize(m_xMargin, m_yMargin); }
|
||||||
virtual int GetToolPacking() { return m_toolPacking; }
|
virtual int GetToolPacking() { return m_toolPacking; }
|
||||||
virtual int GetToolSeparation() { return m_toolSeparation; }
|
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)
|
void SetMaxRowsCols(int rows, int cols)
|
||||||
{ m_maxRows = rows; m_maxCols = cols; }
|
{ m_maxRows = rows; m_maxCols = cols; }
|
||||||
int GetMaxRows() const { return m_maxRows; }
|
int GetMaxRows() const { return m_maxRows; }
|
||||||
int GetMaxCols() const { return m_maxCols; }
|
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)
|
virtual void SetToolBitmapSize(const wxSize& size)
|
||||||
{ m_defaultWidth = size.x; m_defaultHeight = size.y; };
|
{ m_defaultWidth = size.x; m_defaultHeight = size.y; };
|
||||||
virtual wxSize GetToolBitmapSize() const
|
virtual wxSize GetToolBitmapSize() const
|
||||||
{ return wxSize(m_defaultWidth, m_defaultHeight); }
|
{ return wxSize(m_defaultWidth, m_defaultHeight); }
|
||||||
|
|
||||||
// After the toolbar has initialized, this is the size the tools take up
|
// the button size in some implementations is bigger than the bitmap size:
|
||||||
virtual wxSize GetMaxSize() const;
|
// get the total button size (by default the same as bitmap size)
|
||||||
|
|
||||||
// The button size (in some implementations) is bigger than the bitmap size: this returns
|
|
||||||
// the total button size.
|
|
||||||
virtual wxSize GetToolSize() const
|
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!
|
// NB: these functions are deprecated, use EVT_TOOL_XXX() instead!
|
||||||
|
|
||||||
// Only allow toggle if returns TRUE. Call when left button up.
|
// 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.
|
// 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.
|
// Called when the mouse cursor enters a tool bitmap.
|
||||||
// Argument is -1 if mouse is exiting the toolbar.
|
// Argument is -1 if mouse is exiting the toolbar.
|
||||||
virtual void OnMouseEnter(int toolIndex);
|
virtual void OnMouseEnter(int id);
|
||||||
|
|
||||||
// more deprecated functions
|
// more deprecated functions
|
||||||
// -------------------------
|
// -------------------------
|
||||||
@ -255,103 +367,75 @@ public:
|
|||||||
virtual void SetDefaultSize(const wxSize& size) { SetToolBitmapSize(size); }
|
virtual void SetDefaultSize(const wxSize& size) { SetToolBitmapSize(size); }
|
||||||
virtual wxSize GetDefaultSize() const { return GetToolBitmapSize(); }
|
virtual wxSize GetDefaultSize() const { return GetToolBitmapSize(); }
|
||||||
virtual wxSize GetDefaultButtonSize() const { return GetToolSize(); }
|
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
|
#endif // WXWIN_COMPATIBILITY
|
||||||
|
|
||||||
// implementation only from now on
|
// implementation only from now on
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
|
|
||||||
wxList& GetTools() const { return (wxList&) m_tools; }
|
size_t GetToolsCount() const { return m_tools.GetCount(); }
|
||||||
|
|
||||||
// Lay the tools out
|
void OnIdle(wxIdleEvent& event);
|
||||||
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;
|
|
||||||
|
|
||||||
// Do the toolbar button updates (check for EVT_UPDATE_UI handlers)
|
// Do the toolbar button updates (check for EVT_UPDATE_UI handlers)
|
||||||
virtual void DoToolbarUpdates();
|
virtual void DoToolbarUpdates();
|
||||||
|
|
||||||
// event handlers
|
|
||||||
void OnScroll(wxScrollEvent& event);
|
|
||||||
void OnSize(wxSizeEvent& event);
|
|
||||||
void OnIdle(wxIdleEvent& event);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
wxList m_tools;
|
// to implement in derived classes
|
||||||
|
// -------------------------------
|
||||||
|
|
||||||
int m_maxRows;
|
// the tool is not yet inserted into m_tools list when this function is
|
||||||
int m_maxCols;
|
// called and will only be added to it if this function succeeds
|
||||||
long m_maxWidth,
|
virtual bool DoInsertTool(size_t pos, wxToolBarToolBase *tool) = 0;
|
||||||
m_maxHeight;
|
|
||||||
|
|
||||||
int m_currentTool; // Tool where mouse currently is
|
// the tool is still in m_tools list when this function is called, it will
|
||||||
int m_pressedTool; // Tool where mouse pressed
|
// only be deleted from it if it succeeds
|
||||||
|
virtual bool DoDeleteTool(size_t pos, wxToolBarToolBase *tool) = 0;
|
||||||
|
|
||||||
int m_xMargin;
|
// called when the tools enabled flag changes
|
||||||
int m_yMargin;
|
virtual void DoEnableTool(wxToolBarToolBase *tool, bool enable) = 0;
|
||||||
int m_toolPacking;
|
|
||||||
int m_toolSeparation;
|
|
||||||
|
|
||||||
wxCoord m_defaultWidth;
|
// called when the tool is toggled
|
||||||
wxCoord m_defaultHeight;
|
virtual void DoToggleTool(wxToolBarToolBase *tool, bool toggle) = 0;
|
||||||
|
|
||||||
public:
|
// called when the tools "can be toggled" flag changes
|
||||||
////////////////////////////////////////////////////////////////////////
|
virtual void DoSetToggle(wxToolBarToolBase *tool, bool toggle) = 0;
|
||||||
//// IMPLEMENTATION
|
|
||||||
|
|
||||||
// Calculate scroll increment
|
// the functions to create toolbar tools
|
||||||
virtual int CalcScrollInc(wxScrollEvent& event);
|
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;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
// helper functions
|
||||||
//// PROTECTED DATA
|
// ----------------
|
||||||
protected:
|
|
||||||
int m_xScrollPixelsPerLine;
|
// find the tool by id
|
||||||
int m_yScrollPixelsPerLine;
|
wxToolBarToolBase *FindById(int id) const;
|
||||||
bool m_xScrollingEnabled;
|
|
||||||
bool m_yScrollingEnabled;
|
// the list of all our tools
|
||||||
int m_xScrollPosition;
|
wxToolBarToolsList m_tools;
|
||||||
int m_yScrollPosition;
|
|
||||||
bool m_calcScrolledOffset; // If TRUE, wxCanvasDC uses scrolled offsets
|
// the offset of the first tool
|
||||||
int m_xScrollLines;
|
int m_xMargin;
|
||||||
int m_yScrollLines;
|
int m_yMargin;
|
||||||
int m_xScrollLinesPerPage;
|
|
||||||
int m_yScrollLinesPerPage;
|
// 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:
|
private:
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
DECLARE_ABSTRACT_CLASS(wxToolBarBase)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -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_
|
|
@ -1,81 +1,173 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: tbarsmpl.h
|
// Name: wx/tbarsmpl.h
|
||||||
// Purpose: wxToolBarSimple class
|
// Purpose: wxToolBarSimple class
|
||||||
// Author: Julian Smart
|
// Author: Julian Smart
|
||||||
// Modified by:
|
// Modified by: VZ on 14.12.99 during wxToolBar classes reorganization
|
||||||
// Created: 01/02/97
|
// Created: 01/02/97
|
||||||
// RCS-ID: $Id$
|
// RCS-ID: $Id$
|
||||||
// Copyright: (c) Julian Smart and Markus Holzem
|
// Copyright: (c) Julian Smart and Markus Holzem
|
||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef _WX_TBARSMPLH__
|
#ifndef _WX_TBARSMPLH__
|
||||||
#define _WX_TBARSMPLH__
|
#define _WX_TBARSMPLH__
|
||||||
|
|
||||||
#ifdef __GNUG__
|
#ifdef __GNUG__
|
||||||
#pragma interface "tbarsmpl.h"
|
#pragma interface "tbarsmpl.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/defs.h"
|
|
||||||
|
|
||||||
#if wxUSE_TOOLBAR
|
|
||||||
|
|
||||||
#include "wx/bitmap.h"
|
|
||||||
#include "wx/list.h"
|
|
||||||
#include "wx/tbarbase.h"
|
#include "wx/tbarbase.h"
|
||||||
|
|
||||||
|
#if wxUSE_TOOLBAR_SIMPLE
|
||||||
|
|
||||||
class WXDLLEXPORT wxMemoryDC;
|
class WXDLLEXPORT wxMemoryDC;
|
||||||
|
|
||||||
WXDLLEXPORT_DATA(extern const wxChar*) wxToolBarNameStr;
|
// ----------------------------------------------------------------------------
|
||||||
WXDLLEXPORT_DATA(extern const wxSize) wxDefaultSize;
|
// wxToolBarSimple is a generic toolbar implementation in pure wxWindows
|
||||||
WXDLLEXPORT_DATA(extern const wxPoint) wxDefaultPosition;
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
// XView can't cope properly with panels that behave like canvases
|
|
||||||
// (e.g. no scrollbars in panels)
|
|
||||||
class WXDLLEXPORT wxToolBarSimple : public wxToolBarBase
|
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);
|
Create(parent, id, pos, size, style, name);
|
||||||
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);
|
|
||||||
|
|
||||||
bool Create(wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
|
bool Create(wxWindow *parent,
|
||||||
long style = wxNO_BORDER|wxTB_HORIZONTAL, const wxString& name = wxToolBarNameStr);
|
wxWindowID id,
|
||||||
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
|
const wxSize& size = wxDefaultSize,
|
||||||
|
long style = wxNO_BORDER | wxTB_HORIZONTAL,
|
||||||
|
const wxString& name = wxToolBarNameStr);
|
||||||
|
|
||||||
void OnPaint(wxPaintEvent& event);
|
virtual ~wxToolBarSimple();
|
||||||
void OnSize(wxSizeEvent& event);
|
|
||||||
void OnMouseEvent(wxMouseEvent& event);
|
|
||||||
void OnKillFocus(wxFocusEvent& event);
|
|
||||||
|
|
||||||
// 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 wxToolBarToolBase *FindToolForPosition(wxCoord x, wxCoord y) const;
|
||||||
virtual void ToggleTool(int toolIndex, bool toggle); // toggle is TRUE if toggled on
|
|
||||||
|
|
||||||
virtual void SpringUpButton(int index);
|
virtual bool Realize();
|
||||||
|
|
||||||
virtual void LayoutTools();
|
virtual void SetRows(int nRows);
|
||||||
|
|
||||||
// The post-tool-addition call
|
// implementation from now on
|
||||||
virtual bool Realize() { LayoutTools(); return TRUE; };
|
// --------------------------
|
||||||
|
|
||||||
|
// 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:
|
protected:
|
||||||
int m_currentRowsOrColumns;
|
// common part of all ctors
|
||||||
long m_lastX, m_lastY;
|
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
|
#endif
|
||||||
// _WX_TBARSMPLH__
|
// _WX_TBARSMPLH__
|
||||||
|
|
||||||
|
@ -14,29 +14,32 @@
|
|||||||
|
|
||||||
#include "wx/tbarbase.h" // the base class for all toolbars
|
#include "wx/tbarbase.h" // the base class for all toolbars
|
||||||
|
|
||||||
#if 0
|
#if wxUSE_TOOLBAR
|
||||||
class WXDLLEXPORT wxToolBar : public wxControl
|
#if !wxUSE_TOOLBAR_NATIVE
|
||||||
{
|
// the wxToolBarSimple is *the* toolbar class in this case
|
||||||
};
|
#define wxToolBarSimple wxToolBar
|
||||||
#endif // 0
|
|
||||||
|
#include "wx/tbarsmpl.h"
|
||||||
#if defined(__WXMSW__) && defined(__WIN95__)
|
#else // wxUSE_TOOLBAR_NATIVE
|
||||||
# include "wx/msw/tbar95.h"
|
#if defined(__WXMSW__) && defined(__WIN95__)
|
||||||
#elif defined(__WXMSW__)
|
#include "wx/msw/tbar95.h"
|
||||||
# include "wx/msw/tbarmsw.h"
|
#elif defined(__WXMSW__)
|
||||||
#elif defined(__WXMOTIF__)
|
#include "wx/msw/tbarmsw.h"
|
||||||
# include "wx/motif/toolbar.h"
|
#elif defined(__WXMOTIF__)
|
||||||
#elif defined(__WXGTK__)
|
#include "wx/motif/toolbar.h"
|
||||||
# include "wx/gtk/tbargtk.h"
|
#elif defined(__WXGTK__)
|
||||||
#elif defined(__WXQT__)
|
#include "wx/gtk/tbargtk.h"
|
||||||
# include "wx/qt/tbarqt.h"
|
#elif defined(__WXQT__)
|
||||||
#elif defined(__WXMAC__)
|
#include "wx/qt/tbarqt.h"
|
||||||
# include "wx/mac/toolbar.h"
|
#elif defined(__WXMAC__)
|
||||||
#elif defined(__WXPM__)
|
#include "wx/mac/toolbar.h"
|
||||||
# include "wx/os2/toolbar.h"
|
#elif defined(__WXPM__)
|
||||||
#elif defined(__WXSTUBS__)
|
#include "wx/os2/toolbar.h"
|
||||||
# include "wx/stubs/toolbar.h"
|
#elif defined(__WXSTUBS__)
|
||||||
#endif
|
#include "wx/stubs/toolbar.h"
|
||||||
|
#endif
|
||||||
|
#endif // !wxUSE_TOOLBAR_NATIVE/wxUSE_TOOLBAR_NATIVE
|
||||||
|
#endif // wxUSE_TOOLBAR
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
// _WX_TOOLBAR_H_BASE_
|
// _WX_TOOLBAR_H_BASE_
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -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
992
src/generic/tbarsmpl.cpp
Normal 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
|
@ -2,18 +2,27 @@
|
|||||||
// Name: tbargtk.cpp
|
// Name: tbargtk.cpp
|
||||||
// Purpose: GTK toolbar
|
// Purpose: GTK toolbar
|
||||||
// Author: Robert Roebling
|
// Author: Robert Roebling
|
||||||
|
// Modified: 13.12.99 by VZ to derive from wxToolBarBase
|
||||||
// RCS-ID: $Id$
|
// RCS-ID: $Id$
|
||||||
// Copyright: (c) Robert Roebling
|
// Copyright: (c) Robert Roebling
|
||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// declarations
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// headers
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifdef __GNUG__
|
#ifdef __GNUG__
|
||||||
#pragma implementation "tbargtk.h"
|
#pragma implementation "tbargtk.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/toolbar.h"
|
#include "wx/toolbar.h"
|
||||||
|
|
||||||
#if wxUSE_TOOLBAR
|
#if wxUSE_TOOLBAR_NATIVE
|
||||||
|
|
||||||
#include "wx/frame.h"
|
#include "wx/frame.h"
|
||||||
|
|
||||||
@ -21,57 +30,99 @@
|
|||||||
#include "gdk/gdk.h"
|
#include "gdk/gdk.h"
|
||||||
#include "gtk/gtk.h"
|
#include "gtk/gtk.h"
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// idle system
|
// globals
|
||||||
//-----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// idle system
|
||||||
extern void wxapp_install_idle_handler();
|
extern void wxapp_install_idle_handler();
|
||||||
extern bool g_isIdle;
|
extern bool g_isIdle;
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// data
|
// data
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
extern bool g_blockEventsOnDrag;
|
extern bool g_blockEventsOnDrag;
|
||||||
extern wxCursor g_globalCursor;
|
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)
|
// "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)
|
if (g_isIdle)
|
||||||
wxapp_install_idle_handler();
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_blockEventsOnDrag) 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;
|
tool->Toggle();
|
||||||
|
|
||||||
if (tool->m_bitmap2.Ok())
|
wxBitmap bitmap = tool->GetBitmap();
|
||||||
{
|
if ( bitmap.Ok() )
|
||||||
wxBitmap bitmap = tool->m_bitmap1;
|
{
|
||||||
if (tool->m_toggleState) bitmap = tool->m_bitmap2;
|
|
||||||
|
|
||||||
GtkPixmap *pixmap = GTK_PIXMAP( tool->m_pixmap );
|
GtkPixmap *pixmap = GTK_PIXMAP( tool->m_pixmap );
|
||||||
|
|
||||||
GdkBitmap *mask = (GdkBitmap *) NULL;
|
GdkBitmap *mask = bitmap.GetMask() ? bitmap.GetMask()->GetBitmap()
|
||||||
if (bitmap.GetMask()) mask = bitmap.GetMask()->GetBitmap();
|
: (GdkBitmap *)NULL;
|
||||||
|
|
||||||
gtk_pixmap_set( pixmap, bitmap.GetPixmap(), mask );
|
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),
|
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_isIdle) wxapp_install_idle_handler();
|
||||||
|
|
||||||
if (g_blockEventsOnDrag) return TRUE;
|
if (g_blockEventsOnDrag) return TRUE;
|
||||||
|
|
||||||
|
wxToolBar *tb = (wxToolBar *)tool->GetToolBar();
|
||||||
wxToolBar *tb = tool->m_owner;
|
|
||||||
|
|
||||||
#if (GTK_MINOR_VERSION == 0)
|
#if (GTK_MINOR_VERSION == 0)
|
||||||
/* we grey-out the tip text of disabled tool in GTK 1.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)
|
if (tb->m_fg->red != 0)
|
||||||
{
|
{
|
||||||
@ -117,7 +168,7 @@ static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget),
|
|||||||
|
|
||||||
/* emit the event */
|
/* emit the event */
|
||||||
|
|
||||||
tb->OnMouseEnter( tool->m_index );
|
tb->OnMouseEnter( tool->GetId() );
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -126,30 +177,51 @@ static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget),
|
|||||||
// InsertChild callback for wxToolBar
|
// 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 */
|
/* we don't do anything here but pray */
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxToolBar
|
// wxToolBarTool
|
||||||
//-----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxToolBar,wxControl)
|
void wxToolBarTool::Init()
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(wxToolBar, wxControl)
|
|
||||||
EVT_IDLE(wxToolBar::OnIdle)
|
|
||||||
END_EVENT_TABLE()
|
|
||||||
|
|
||||||
wxToolBar::wxToolBar()
|
|
||||||
{
|
{
|
||||||
|
m_item =
|
||||||
|
m_pixmap = (GtkWidget *)NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxToolBar::wxToolBar( wxWindow *parent, wxWindowID id,
|
wxToolBarToolBase *wxToolBar::CreateTool(int id,
|
||||||
const wxPoint& pos, const wxSize& size,
|
const wxBitmap& bitmap1,
|
||||||
long style, const wxString& name )
|
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()
|
wxToolBar::~wxToolBar()
|
||||||
@ -158,36 +230,36 @@ wxToolBar::~wxToolBar()
|
|||||||
delete m_bg;
|
delete m_bg;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxToolBar::Create( wxWindow *parent, wxWindowID id,
|
bool wxToolBar::Create( wxWindow *parent,
|
||||||
const wxPoint& pos, const wxSize& size,
|
wxWindowID id,
|
||||||
long style, const wxString& name )
|
const wxPoint& pos,
|
||||||
|
const wxSize& size,
|
||||||
|
long style,
|
||||||
|
const wxString& name )
|
||||||
{
|
{
|
||||||
m_needParent = TRUE;
|
m_needParent = TRUE;
|
||||||
m_blockNextEvent = FALSE;
|
|
||||||
m_insertCallback = (wxInsertChildFunction)wxInsertChildInToolBar;
|
m_insertCallback = (wxInsertChildFunction)wxInsertChildInToolBar;
|
||||||
|
|
||||||
if (!PreCreation( parent, pos, size ) ||
|
if ( !PreCreation( parent, pos, size ) ||
|
||||||
!CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
|
!CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
|
||||||
{
|
{
|
||||||
wxFAIL_MSG( wxT("wxToolBar creation failed") );
|
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,
|
SetToolSeparation(7);
|
||||||
GTK_TOOLBAR_ICONS ) );
|
|
||||||
|
|
||||||
m_separation = 7;
|
|
||||||
gtk_toolbar_set_space_size( m_toolbar, m_separation );
|
|
||||||
m_hasToolAlready = FALSE;
|
|
||||||
|
|
||||||
if (style & wxTB_DOCKABLE)
|
if (style & wxTB_DOCKABLE)
|
||||||
{
|
{
|
||||||
m_widget = gtk_handle_box_new();
|
m_widget = gtk_handle_box_new();
|
||||||
gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) );
|
gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) );
|
||||||
gtk_widget_show( GTK_WIDGET(m_toolbar) );
|
gtk_widget_show( GTK_WIDGET(m_toolbar) );
|
||||||
|
|
||||||
#if (GTK_MINOR_VERSION > 0)
|
#if (GTK_MINOR_VERSION > 0)
|
||||||
if (style & wxTB_FLAT)
|
if (style & wxTB_FLAT)
|
||||||
gtk_handle_box_set_shadow_type( GTK_HANDLE_BOX(m_widget), GTK_SHADOW_NONE );
|
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);
|
m_widget = GTK_WIDGET(m_toolbar);
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), TRUE );
|
gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), TRUE );
|
||||||
|
|
||||||
#if (GTK_MINOR_VERSION > 0)
|
#if (GTK_MINOR_VERSION > 0)
|
||||||
if (style & wxTB_FLAT)
|
if (style & wxTB_FLAT)
|
||||||
gtk_toolbar_set_button_relief( GTK_TOOLBAR(m_toolbar), GTK_RELIEF_NONE );
|
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->green = 0;
|
||||||
m_fg->blue = 0;
|
m_fg->blue = 0;
|
||||||
gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ), m_fg );
|
gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ), m_fg );
|
||||||
|
|
||||||
m_bg = new GdkColor;
|
m_bg = new GdkColor;
|
||||||
m_bg->red = 65535;
|
m_bg->red = 65535;
|
||||||
m_bg->green = 65535;
|
m_bg->green = 65535;
|
||||||
m_bg->blue = 50000;
|
m_bg->blue = 50000;
|
||||||
gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ), m_bg );
|
gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ), m_bg );
|
||||||
|
|
||||||
#if (GTK_MINOR_VERSION > 0)
|
#if (GTK_MINOR_VERSION > 0)
|
||||||
gtk_tooltips_force_window( GTK_TOOLBAR(m_toolbar)->tooltips );
|
gtk_tooltips_force_window( GTK_TOOLBAR(m_toolbar)->tooltips );
|
||||||
|
|
||||||
GtkStyle *g_style =
|
GtkStyle *g_style =
|
||||||
gtk_style_copy(
|
gtk_style_copy(
|
||||||
gtk_widget_get_style(
|
gtk_widget_get_style(
|
||||||
GTK_TOOLBAR(m_toolbar)->tooltips->tip_window ) );
|
GTK_TOOLBAR(m_toolbar)->tooltips->tip_window ) );
|
||||||
|
|
||||||
g_style->bg[GTK_STATE_NORMAL] = *m_bg;
|
g_style->bg[GTK_STATE_NORMAL] = *m_bg;
|
||||||
gtk_widget_set_style( GTK_TOOLBAR(m_toolbar)->tooltips->tip_window, g_style );
|
gtk_widget_set_style( GTK_TOOLBAR(m_toolbar)->tooltips->tip_window, g_style );
|
||||||
#else
|
#else
|
||||||
gtk_tooltips_set_colors( GTK_TOOLBAR(m_toolbar)->tooltips, m_bg, m_fg );
|
gtk_tooltips_set_colors( GTK_TOOLBAR(m_toolbar)->tooltips, m_bg, m_fg );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_xMargin = 0;
|
|
||||||
m_yMargin = 0;
|
|
||||||
|
|
||||||
m_parent->DoAddChild( this );
|
m_parent->DoAddChild( this );
|
||||||
|
|
||||||
PostCreation();
|
PostCreation();
|
||||||
|
|
||||||
Show( TRUE );
|
Show( TRUE );
|
||||||
@ -243,277 +312,182 @@ bool wxToolBar::Create( wxWindow *parent, wxWindowID id,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxToolBar::OnLeftClick( int toolIndex, bool toggleDown )
|
bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
|
||||||
{
|
{
|
||||||
wxCommandEvent event( wxEVT_COMMAND_TOOL_CLICKED, toolIndex );
|
wxToolBarTool *tool = (wxToolBarTool *)toolBase;
|
||||||
event.SetEventObject(this);
|
|
||||||
event.SetInt( toolIndex );
|
|
||||||
event.SetExtraLong((long) toggleDown);
|
|
||||||
|
|
||||||
GetEventHandler()->ProcessEvent(event);
|
if ( tool->IsButton() )
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
wxToolBarTool *tool = (wxToolBarTool*)node->Data();
|
wxBitmap bitmap = tool->GetBitmap1();
|
||||||
if (tool->m_index == toolIndex)
|
|
||||||
{
|
wxCHECK_MSG( bitmap.Ok(), FALSE,
|
||||||
if (tool->m_control)
|
wxT("invalid bitmap for wxToolBar icon") );
|
||||||
tool->m_control->Destroy();
|
|
||||||
else
|
wxCHECK_MSG( bitmap.GetBitmap() == NULL, FALSE,
|
||||||
gtk_widget_destroy( tool->m_item );
|
wxT("wxToolBar doesn't support GdkBitmap") );
|
||||||
m_tools.DeleteNode( node );
|
|
||||||
|
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;
|
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;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxToolBar::EnableTool(int toolIndex, bool enable)
|
bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *toolBase)
|
||||||
{
|
{
|
||||||
wxNode *node = m_tools.First();
|
wxToolBarTool *tool = (wxToolBarTool *)toolBase;
|
||||||
while (node)
|
|
||||||
|
switch ( tool->GetStyle() )
|
||||||
{
|
{
|
||||||
wxToolBarTool *tool = (wxToolBarTool*)node->Data();
|
case wxTOOL_STYLE_CONTROL:
|
||||||
if (tool->m_index == toolIndex)
|
tool->GetControl()->Destroy();
|
||||||
{
|
break;
|
||||||
tool->m_enabled = enable;
|
|
||||||
|
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)
|
#if (GTK_MINOR_VERSION > 0)
|
||||||
/* we don't disable the tools for GTK 1.0 as the bitmaps don't get
|
wxToolBarTool *tool = (wxToolBarTool *)toolBase;
|
||||||
greyed anyway and this also disables tooltips */
|
|
||||||
if (tool->m_item)
|
/* we don't disable the tools for GTK 1.0 as the bitmaps don't get
|
||||||
gtk_widget_set_sensitive( tool->m_item, enable );
|
greyed anyway and this also disables tooltips */
|
||||||
|
if (tool->m_item)
|
||||||
|
gtk_widget_set_sensitive( tool->m_item, enable );
|
||||||
#endif
|
#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();
|
// VZ: absolutely no idea about how to do it
|
||||||
while (node)
|
wxFAIL_MSG( _T("not implemented") );
|
||||||
{
|
|
||||||
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") );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxObject *wxToolBar::GetToolClientData( int index ) const
|
// ----------------------------------------------------------------------------
|
||||||
{
|
// wxToolBar geometry
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxToolBar::GetToolState(int toolIndex) const
|
wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x),
|
||||||
|
wxCoord WXUNUSED(y)) const
|
||||||
{
|
{
|
||||||
wxNode *node = m_tools.First();
|
// VZ: GTK+ doesn't seem to have such thing
|
||||||
while (node)
|
wxFAIL_MSG( _T("wxToolBar::FindToolForPosition() not implemented") );
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxToolBar::GetToolEnabled(int toolIndex) const
|
return (wxToolBarToolBase *)NULL;
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxToolBar::SetMargins( int x, int y )
|
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
|
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;
|
m_yMargin = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxToolBar::SetToolPacking( int WXUNUSED(packing) )
|
|
||||||
{
|
|
||||||
wxFAIL_MSG( wxT("wxToolBar::SetToolPacking not implemented") );
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxToolBar::SetToolSeparation( int separation )
|
void wxToolBar::SetToolSeparation( int separation )
|
||||||
{
|
{
|
||||||
gtk_toolbar_set_space_size( m_toolbar, separation );
|
gtk_toolbar_set_space_size( m_toolbar, separation );
|
||||||
m_separation = separation;
|
m_toolSeparation = separation;
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxToolBar::GetToolPacking()
|
// ----------------------------------------------------------------------------
|
||||||
{
|
// wxToolBar idle handling
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxToolBar::OnInternalIdle()
|
void wxToolBar::OnInternalIdle()
|
||||||
{
|
{
|
||||||
@ -652,31 +513,37 @@ void wxToolBar::OnInternalIdle()
|
|||||||
if (cursor.Ok())
|
if (cursor.Ok())
|
||||||
{
|
{
|
||||||
/* I now set the cursor the anew in every OnInternalIdle call
|
/* I now set the cursor the anew in every OnInternalIdle call
|
||||||
as setting the cursor in a parent window also effects the
|
as setting the cursor in a parent window also effects the
|
||||||
windows above so that checking for the current cursor is
|
windows above so that checking for the current cursor is
|
||||||
not possible. */
|
not possible. */
|
||||||
|
|
||||||
if (HasFlag(wxTB_DOCKABLE) && (m_widget->window))
|
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();
|
/* if the toolbar is dockable, then m_widget stands for the
|
||||||
node = node->Next();
|
GtkHandleBox widget, which uses its own window so that we
|
||||||
|
can set the cursor for it. if the toolbar is not dockable,
|
||||||
if (!tool->m_item || !tool->m_item->window)
|
m_widget comes from m_toolbar which uses its parent's
|
||||||
continue;
|
window ("windowless windows") and thus we cannot set the
|
||||||
else
|
cursor. */
|
||||||
gdk_window_set_cursor( tool->m_item->window, cursor.GetCursor() );
|
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() );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,18 +2,27 @@
|
|||||||
// Name: tbargtk.cpp
|
// Name: tbargtk.cpp
|
||||||
// Purpose: GTK toolbar
|
// Purpose: GTK toolbar
|
||||||
// Author: Robert Roebling
|
// Author: Robert Roebling
|
||||||
|
// Modified: 13.12.99 by VZ to derive from wxToolBarBase
|
||||||
// RCS-ID: $Id$
|
// RCS-ID: $Id$
|
||||||
// Copyright: (c) Robert Roebling
|
// Copyright: (c) Robert Roebling
|
||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// declarations
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// headers
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifdef __GNUG__
|
#ifdef __GNUG__
|
||||||
#pragma implementation "tbargtk.h"
|
#pragma implementation "tbargtk.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/toolbar.h"
|
#include "wx/toolbar.h"
|
||||||
|
|
||||||
#if wxUSE_TOOLBAR
|
#if wxUSE_TOOLBAR_NATIVE
|
||||||
|
|
||||||
#include "wx/frame.h"
|
#include "wx/frame.h"
|
||||||
|
|
||||||
@ -21,57 +30,99 @@
|
|||||||
#include "gdk/gdk.h"
|
#include "gdk/gdk.h"
|
||||||
#include "gtk/gtk.h"
|
#include "gtk/gtk.h"
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// idle system
|
// globals
|
||||||
//-----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// idle system
|
||||||
extern void wxapp_install_idle_handler();
|
extern void wxapp_install_idle_handler();
|
||||||
extern bool g_isIdle;
|
extern bool g_isIdle;
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// data
|
// data
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
extern bool g_blockEventsOnDrag;
|
extern bool g_blockEventsOnDrag;
|
||||||
extern wxCursor g_globalCursor;
|
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)
|
// "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)
|
if (g_isIdle)
|
||||||
wxapp_install_idle_handler();
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_blockEventsOnDrag) 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;
|
tool->Toggle();
|
||||||
|
|
||||||
if (tool->m_bitmap2.Ok())
|
wxBitmap bitmap = tool->GetBitmap();
|
||||||
{
|
if ( bitmap.Ok() )
|
||||||
wxBitmap bitmap = tool->m_bitmap1;
|
{
|
||||||
if (tool->m_toggleState) bitmap = tool->m_bitmap2;
|
|
||||||
|
|
||||||
GtkPixmap *pixmap = GTK_PIXMAP( tool->m_pixmap );
|
GtkPixmap *pixmap = GTK_PIXMAP( tool->m_pixmap );
|
||||||
|
|
||||||
GdkBitmap *mask = (GdkBitmap *) NULL;
|
GdkBitmap *mask = bitmap.GetMask() ? bitmap.GetMask()->GetBitmap()
|
||||||
if (bitmap.GetMask()) mask = bitmap.GetMask()->GetBitmap();
|
: (GdkBitmap *)NULL;
|
||||||
|
|
||||||
gtk_pixmap_set( pixmap, bitmap.GetPixmap(), mask );
|
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),
|
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_isIdle) wxapp_install_idle_handler();
|
||||||
|
|
||||||
if (g_blockEventsOnDrag) return TRUE;
|
if (g_blockEventsOnDrag) return TRUE;
|
||||||
|
|
||||||
|
wxToolBar *tb = (wxToolBar *)tool->GetToolBar();
|
||||||
wxToolBar *tb = tool->m_owner;
|
|
||||||
|
|
||||||
#if (GTK_MINOR_VERSION == 0)
|
#if (GTK_MINOR_VERSION == 0)
|
||||||
/* we grey-out the tip text of disabled tool in GTK 1.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)
|
if (tb->m_fg->red != 0)
|
||||||
{
|
{
|
||||||
@ -117,7 +168,7 @@ static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget),
|
|||||||
|
|
||||||
/* emit the event */
|
/* emit the event */
|
||||||
|
|
||||||
tb->OnMouseEnter( tool->m_index );
|
tb->OnMouseEnter( tool->GetId() );
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -126,30 +177,51 @@ static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget),
|
|||||||
// InsertChild callback for wxToolBar
|
// 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 */
|
/* we don't do anything here but pray */
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxToolBar
|
// wxToolBarTool
|
||||||
//-----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxToolBar,wxControl)
|
void wxToolBarTool::Init()
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(wxToolBar, wxControl)
|
|
||||||
EVT_IDLE(wxToolBar::OnIdle)
|
|
||||||
END_EVENT_TABLE()
|
|
||||||
|
|
||||||
wxToolBar::wxToolBar()
|
|
||||||
{
|
{
|
||||||
|
m_item =
|
||||||
|
m_pixmap = (GtkWidget *)NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxToolBar::wxToolBar( wxWindow *parent, wxWindowID id,
|
wxToolBarToolBase *wxToolBar::CreateTool(int id,
|
||||||
const wxPoint& pos, const wxSize& size,
|
const wxBitmap& bitmap1,
|
||||||
long style, const wxString& name )
|
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()
|
wxToolBar::~wxToolBar()
|
||||||
@ -158,36 +230,36 @@ wxToolBar::~wxToolBar()
|
|||||||
delete m_bg;
|
delete m_bg;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxToolBar::Create( wxWindow *parent, wxWindowID id,
|
bool wxToolBar::Create( wxWindow *parent,
|
||||||
const wxPoint& pos, const wxSize& size,
|
wxWindowID id,
|
||||||
long style, const wxString& name )
|
const wxPoint& pos,
|
||||||
|
const wxSize& size,
|
||||||
|
long style,
|
||||||
|
const wxString& name )
|
||||||
{
|
{
|
||||||
m_needParent = TRUE;
|
m_needParent = TRUE;
|
||||||
m_blockNextEvent = FALSE;
|
|
||||||
m_insertCallback = (wxInsertChildFunction)wxInsertChildInToolBar;
|
m_insertCallback = (wxInsertChildFunction)wxInsertChildInToolBar;
|
||||||
|
|
||||||
if (!PreCreation( parent, pos, size ) ||
|
if ( !PreCreation( parent, pos, size ) ||
|
||||||
!CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
|
!CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
|
||||||
{
|
{
|
||||||
wxFAIL_MSG( wxT("wxToolBar creation failed") );
|
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,
|
SetToolSeparation(7);
|
||||||
GTK_TOOLBAR_ICONS ) );
|
|
||||||
|
|
||||||
m_separation = 7;
|
|
||||||
gtk_toolbar_set_space_size( m_toolbar, m_separation );
|
|
||||||
m_hasToolAlready = FALSE;
|
|
||||||
|
|
||||||
if (style & wxTB_DOCKABLE)
|
if (style & wxTB_DOCKABLE)
|
||||||
{
|
{
|
||||||
m_widget = gtk_handle_box_new();
|
m_widget = gtk_handle_box_new();
|
||||||
gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) );
|
gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) );
|
||||||
gtk_widget_show( GTK_WIDGET(m_toolbar) );
|
gtk_widget_show( GTK_WIDGET(m_toolbar) );
|
||||||
|
|
||||||
#if (GTK_MINOR_VERSION > 0)
|
#if (GTK_MINOR_VERSION > 0)
|
||||||
if (style & wxTB_FLAT)
|
if (style & wxTB_FLAT)
|
||||||
gtk_handle_box_set_shadow_type( GTK_HANDLE_BOX(m_widget), GTK_SHADOW_NONE );
|
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);
|
m_widget = GTK_WIDGET(m_toolbar);
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), TRUE );
|
gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar), TRUE );
|
||||||
|
|
||||||
#if (GTK_MINOR_VERSION > 0)
|
#if (GTK_MINOR_VERSION > 0)
|
||||||
if (style & wxTB_FLAT)
|
if (style & wxTB_FLAT)
|
||||||
gtk_toolbar_set_button_relief( GTK_TOOLBAR(m_toolbar), GTK_RELIEF_NONE );
|
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->green = 0;
|
||||||
m_fg->blue = 0;
|
m_fg->blue = 0;
|
||||||
gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ), m_fg );
|
gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ), m_fg );
|
||||||
|
|
||||||
m_bg = new GdkColor;
|
m_bg = new GdkColor;
|
||||||
m_bg->red = 65535;
|
m_bg->red = 65535;
|
||||||
m_bg->green = 65535;
|
m_bg->green = 65535;
|
||||||
m_bg->blue = 50000;
|
m_bg->blue = 50000;
|
||||||
gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ), m_bg );
|
gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(m_toolbar) ), m_bg );
|
||||||
|
|
||||||
#if (GTK_MINOR_VERSION > 0)
|
#if (GTK_MINOR_VERSION > 0)
|
||||||
gtk_tooltips_force_window( GTK_TOOLBAR(m_toolbar)->tooltips );
|
gtk_tooltips_force_window( GTK_TOOLBAR(m_toolbar)->tooltips );
|
||||||
|
|
||||||
GtkStyle *g_style =
|
GtkStyle *g_style =
|
||||||
gtk_style_copy(
|
gtk_style_copy(
|
||||||
gtk_widget_get_style(
|
gtk_widget_get_style(
|
||||||
GTK_TOOLBAR(m_toolbar)->tooltips->tip_window ) );
|
GTK_TOOLBAR(m_toolbar)->tooltips->tip_window ) );
|
||||||
|
|
||||||
g_style->bg[GTK_STATE_NORMAL] = *m_bg;
|
g_style->bg[GTK_STATE_NORMAL] = *m_bg;
|
||||||
gtk_widget_set_style( GTK_TOOLBAR(m_toolbar)->tooltips->tip_window, g_style );
|
gtk_widget_set_style( GTK_TOOLBAR(m_toolbar)->tooltips->tip_window, g_style );
|
||||||
#else
|
#else
|
||||||
gtk_tooltips_set_colors( GTK_TOOLBAR(m_toolbar)->tooltips, m_bg, m_fg );
|
gtk_tooltips_set_colors( GTK_TOOLBAR(m_toolbar)->tooltips, m_bg, m_fg );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_xMargin = 0;
|
|
||||||
m_yMargin = 0;
|
|
||||||
|
|
||||||
m_parent->DoAddChild( this );
|
m_parent->DoAddChild( this );
|
||||||
|
|
||||||
PostCreation();
|
PostCreation();
|
||||||
|
|
||||||
Show( TRUE );
|
Show( TRUE );
|
||||||
@ -243,277 +312,182 @@ bool wxToolBar::Create( wxWindow *parent, wxWindowID id,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxToolBar::OnLeftClick( int toolIndex, bool toggleDown )
|
bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
|
||||||
{
|
{
|
||||||
wxCommandEvent event( wxEVT_COMMAND_TOOL_CLICKED, toolIndex );
|
wxToolBarTool *tool = (wxToolBarTool *)toolBase;
|
||||||
event.SetEventObject(this);
|
|
||||||
event.SetInt( toolIndex );
|
|
||||||
event.SetExtraLong((long) toggleDown);
|
|
||||||
|
|
||||||
GetEventHandler()->ProcessEvent(event);
|
if ( tool->IsButton() )
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
wxToolBarTool *tool = (wxToolBarTool*)node->Data();
|
wxBitmap bitmap = tool->GetBitmap1();
|
||||||
if (tool->m_index == toolIndex)
|
|
||||||
{
|
wxCHECK_MSG( bitmap.Ok(), FALSE,
|
||||||
if (tool->m_control)
|
wxT("invalid bitmap for wxToolBar icon") );
|
||||||
tool->m_control->Destroy();
|
|
||||||
else
|
wxCHECK_MSG( bitmap.GetBitmap() == NULL, FALSE,
|
||||||
gtk_widget_destroy( tool->m_item );
|
wxT("wxToolBar doesn't support GdkBitmap") );
|
||||||
m_tools.DeleteNode( node );
|
|
||||||
|
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;
|
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;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxToolBar::EnableTool(int toolIndex, bool enable)
|
bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *toolBase)
|
||||||
{
|
{
|
||||||
wxNode *node = m_tools.First();
|
wxToolBarTool *tool = (wxToolBarTool *)toolBase;
|
||||||
while (node)
|
|
||||||
|
switch ( tool->GetStyle() )
|
||||||
{
|
{
|
||||||
wxToolBarTool *tool = (wxToolBarTool*)node->Data();
|
case wxTOOL_STYLE_CONTROL:
|
||||||
if (tool->m_index == toolIndex)
|
tool->GetControl()->Destroy();
|
||||||
{
|
break;
|
||||||
tool->m_enabled = enable;
|
|
||||||
|
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)
|
#if (GTK_MINOR_VERSION > 0)
|
||||||
/* we don't disable the tools for GTK 1.0 as the bitmaps don't get
|
wxToolBarTool *tool = (wxToolBarTool *)toolBase;
|
||||||
greyed anyway and this also disables tooltips */
|
|
||||||
if (tool->m_item)
|
/* we don't disable the tools for GTK 1.0 as the bitmaps don't get
|
||||||
gtk_widget_set_sensitive( tool->m_item, enable );
|
greyed anyway and this also disables tooltips */
|
||||||
|
if (tool->m_item)
|
||||||
|
gtk_widget_set_sensitive( tool->m_item, enable );
|
||||||
#endif
|
#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();
|
// VZ: absolutely no idea about how to do it
|
||||||
while (node)
|
wxFAIL_MSG( _T("not implemented") );
|
||||||
{
|
|
||||||
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") );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxObject *wxToolBar::GetToolClientData( int index ) const
|
// ----------------------------------------------------------------------------
|
||||||
{
|
// wxToolBar geometry
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxToolBar::GetToolState(int toolIndex) const
|
wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x),
|
||||||
|
wxCoord WXUNUSED(y)) const
|
||||||
{
|
{
|
||||||
wxNode *node = m_tools.First();
|
// VZ: GTK+ doesn't seem to have such thing
|
||||||
while (node)
|
wxFAIL_MSG( _T("wxToolBar::FindToolForPosition() not implemented") );
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxToolBar::GetToolEnabled(int toolIndex) const
|
return (wxToolBarToolBase *)NULL;
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxToolBar::SetMargins( int x, int y )
|
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
|
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;
|
m_yMargin = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxToolBar::SetToolPacking( int WXUNUSED(packing) )
|
|
||||||
{
|
|
||||||
wxFAIL_MSG( wxT("wxToolBar::SetToolPacking not implemented") );
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxToolBar::SetToolSeparation( int separation )
|
void wxToolBar::SetToolSeparation( int separation )
|
||||||
{
|
{
|
||||||
gtk_toolbar_set_space_size( m_toolbar, separation );
|
gtk_toolbar_set_space_size( m_toolbar, separation );
|
||||||
m_separation = separation;
|
m_toolSeparation = separation;
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxToolBar::GetToolPacking()
|
// ----------------------------------------------------------------------------
|
||||||
{
|
// wxToolBar idle handling
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxToolBar::OnInternalIdle()
|
void wxToolBar::OnInternalIdle()
|
||||||
{
|
{
|
||||||
@ -652,31 +513,37 @@ void wxToolBar::OnInternalIdle()
|
|||||||
if (cursor.Ok())
|
if (cursor.Ok())
|
||||||
{
|
{
|
||||||
/* I now set the cursor the anew in every OnInternalIdle call
|
/* I now set the cursor the anew in every OnInternalIdle call
|
||||||
as setting the cursor in a parent window also effects the
|
as setting the cursor in a parent window also effects the
|
||||||
windows above so that checking for the current cursor is
|
windows above so that checking for the current cursor is
|
||||||
not possible. */
|
not possible. */
|
||||||
|
|
||||||
if (HasFlag(wxTB_DOCKABLE) && (m_widget->window))
|
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();
|
/* if the toolbar is dockable, then m_widget stands for the
|
||||||
node = node->Next();
|
GtkHandleBox widget, which uses its own window so that we
|
||||||
|
can set the cursor for it. if the toolbar is not dockable,
|
||||||
if (!tool->m_item || !tool->m_item->window)
|
m_widget comes from m_toolbar which uses its parent's
|
||||||
continue;
|
window ("windowless windows") and thus we cannot set the
|
||||||
else
|
cursor. */
|
||||||
gdk_window_set_cursor( tool->m_item->window, cursor.GetCursor() );
|
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() );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,16 +1,24 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: toolbar.cpp
|
// Name: motif/toolbar.cpp
|
||||||
// Purpose: wxToolBar
|
// Purpose: wxToolBar
|
||||||
// Author: Julian Smart
|
// Author: Julian Smart
|
||||||
// Modified by:
|
// Modified by: 13.12.99 by VZ during toolbar classes reorganization
|
||||||
// Created: 04/01/98
|
// Created: 04/01/98
|
||||||
// RCS-ID: $Id$
|
// RCS-ID: $Id$
|
||||||
// Copyright: (c) Julian Smart
|
// Copyright: (c) Julian Smart
|
||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// declarations
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// headers
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifdef __GNUG__
|
#ifdef __GNUG__
|
||||||
#pragma implementation "toolbar.h"
|
#pragma implementation "toolbar.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/wx.h"
|
#include "wx/wx.h"
|
||||||
@ -34,51 +42,147 @@
|
|||||||
|
|
||||||
#include "wx/motif/private.h"
|
#include "wx/motif/private.h"
|
||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxToolBarBase)
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxWin macros
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase)
|
#if !USE_SHARED_LIBRARY
|
||||||
END_EVENT_TABLE()
|
IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// private functions
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
static void wxToolButtonCallback (Widget w, XtPointer clientData,
|
static void wxToolButtonCallback (Widget w, XtPointer clientData,
|
||||||
XtPointer ptr);
|
XtPointer ptr);
|
||||||
static void wxToolButtonPopupCallback (Widget w, XtPointer client_data,
|
static void wxToolButtonPopupCallback (Widget w, XtPointer client_data,
|
||||||
XEvent *event, Boolean *continue_to_dispatch);
|
XEvent *event, Boolean *continue_to_dispatch);
|
||||||
|
|
||||||
class wxToolBarTimer: public wxTimer
|
// ----------------------------------------------------------------------------
|
||||||
|
// private classes
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class wxToolBarTimer : public wxTimer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxToolBarTimer() { }
|
virtual void Notify();
|
||||||
virtual void Notify();
|
|
||||||
|
|
||||||
static Widget help_popup;
|
static Widget help_popup;
|
||||||
static Widget buttonWidget;
|
static Widget buttonWidget;
|
||||||
static wxString helpString;
|
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;
|
static wxToolBarTimer* wxTheToolBarTimer = (wxToolBarTimer*) NULL;
|
||||||
|
|
||||||
Widget wxToolBarTimer::help_popup = (Widget) 0;
|
Widget wxToolBarTimer::help_popup = (Widget) 0;
|
||||||
Widget wxToolBarTimer::buttonWidget = (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;
|
return new wxToolBarTool(tbar, id, bitmap1, bitmap2, toggle,
|
||||||
m_maxHeight = -1;
|
clientData, shortHelpString, longHelpString);
|
||||||
m_defaultWidth = 24;
|
|
||||||
m_defaultHeight = 22;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
|
wxToolBarToolBase *wxToolBarToolBase::New(wxToolBar *tbar, wxControl *control)
|
||||||
long style, const wxString& name)
|
{
|
||||||
|
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_maxWidth = -1;
|
||||||
m_maxHeight = -1;
|
m_maxHeight = -1;
|
||||||
|
|
||||||
m_defaultWidth = 24;
|
m_defaultWidth = 24;
|
||||||
m_defaultHeight = 22;
|
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);
|
SetName(name);
|
||||||
m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
|
m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
|
||||||
m_foregroundColour = parent->GetForegroundColour();
|
m_foregroundColour = parent->GetForegroundColour();
|
||||||
@ -126,14 +230,15 @@ wxToolBar::~wxToolBar()
|
|||||||
{
|
{
|
||||||
delete wxTheToolBarTimer;
|
delete wxTheToolBarTimer;
|
||||||
wxTheToolBarTimer = NULL;
|
wxTheToolBarTimer = NULL;
|
||||||
ClearTools();
|
|
||||||
DestroyPixmaps();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxToolBar::CreateTools()
|
bool wxToolBar::Realize()
|
||||||
{
|
{
|
||||||
if (m_tools.Number() == 0)
|
if ( m_tools.GetCount() == 0 )
|
||||||
return FALSE;
|
{
|
||||||
|
// nothing to do
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
// Separator spacing
|
// Separator spacing
|
||||||
const int separatorSize = GetToolSeparation(); // 8;
|
const int separatorSize = GetToolSeparation(); // 8;
|
||||||
@ -148,178 +253,193 @@ bool wxToolBar::CreateTools()
|
|||||||
|
|
||||||
int currentSpacing = 0;
|
int currentSpacing = 0;
|
||||||
|
|
||||||
m_widgets.Clear();
|
Widget button;
|
||||||
Widget prevButton = (Widget) 0;
|
Pixmap pixmap, insensPixmap;
|
||||||
wxNode* node = m_tools.First();
|
wxBitmap bmp;
|
||||||
while (node)
|
|
||||||
|
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)
|
switch ( tool->GetStyle() )
|
||||||
currentX += separatorSize;
|
|
||||||
else if (tool->m_bitmap1.Ok())
|
|
||||||
{
|
{
|
||||||
Widget button = (Widget) 0;
|
case wxTOOL_STYLE_CONTROL:
|
||||||
|
wxFAIL_MSG( _T("not implemented") );
|
||||||
|
break;
|
||||||
|
|
||||||
if (tool->m_isToggle)
|
case wxTOOL_STYLE_SEPARATOR:
|
||||||
{
|
currentX += separatorSize;
|
||||||
button = XtVaCreateWidget("toggleButton",
|
break;
|
||||||
xmToggleButtonWidgetClass, (Widget) m_mainWidget,
|
|
||||||
XmNx, currentX, XmNy, currentY,
|
|
||||||
// XmNpushButtonEnabled, True,
|
|
||||||
XmNmultiClick, XmMULTICLICK_KEEP,
|
|
||||||
XmNlabelType, XmPIXMAP,
|
|
||||||
NULL);
|
|
||||||
XtAddCallback ((Widget) button, XmNvalueChangedCallback, (XtCallbackProc) wxToolButtonCallback,
|
|
||||||
(XtPointer) this);
|
|
||||||
|
|
||||||
XtVaSetValues ((Widget) button,
|
case wxTOOL_STYLE_BUTTON:
|
||||||
XmNselectColor, m_backgroundColour.AllocColour(XtDisplay((Widget) button)),
|
button = (Widget) 0;
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
XtVaSetValues ((Widget) button,
|
||||||
// a new wxBitmap that has the correct background colour
|
XmNselectColor, m_backgroundColour.AllocColour(XtDisplay((Widget) button)),
|
||||||
// for the button. Otherwise the background will just be
|
NULL);
|
||||||
// e.g. black if a transparent XPM has been loaded.
|
}
|
||||||
wxBitmap originalBitmap = tool->m_bitmap1;
|
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;
|
int backgroundPixel;
|
||||||
XtVaGetValues(button, XmNbackground, &backgroundPixel,
|
if ( tool->CanBeToggled() )
|
||||||
NULL);
|
XtVaGetValues(button, XmNselectColor, &backgroundPixel,
|
||||||
|
NULL);
|
||||||
|
else
|
||||||
|
XtVaGetValues(button, XmNarmColor, &backgroundPixel,
|
||||||
|
NULL);
|
||||||
|
|
||||||
wxColour col;
|
wxColour col;
|
||||||
col.SetPixel(backgroundPixel);
|
col.SetPixel(backgroundPixel);
|
||||||
|
|
||||||
wxBitmap newBitmap = wxCreateMaskedBitmap(tool->m_bitmap1, col);
|
if (tool->GetBitmap2().Ok() && tool->GetBitmap2().GetMask())
|
||||||
|
|
||||||
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())
|
|
||||||
{
|
{
|
||||||
wxBitmap newBitmap = wxCreateMaskedBitmap(originalBitmap, col);
|
// Use what's there
|
||||||
tool->m_bitmap2 = newBitmap;
|
wxBitmap newBitmap = wxCreateMaskedBitmap(tool->GetBitmap2(), col);
|
||||||
}
|
tool->SetBitmap2(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();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pixmap2 = (Pixmap) tool->m_bitmap1.GetArmPixmap(button);
|
// Use unselected bitmap
|
||||||
insensPixmap2 = XCreateInsensitivePixmap((Display*) wxGetDisplay(), pixmap2);
|
if ( bmp.GetMask() )
|
||||||
m_pixmaps.Append((wxObject*) insensPixmap2); // Store for later deletion
|
{
|
||||||
|
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,
|
pixmap = (Pixmap) bmp.GetPixmap();
|
||||||
// otherwise generate one.
|
insensPixmap = (Pixmap) bmp.GetInsensPixmap();
|
||||||
if (tool->m_bitmap2.Ok())
|
|
||||||
|
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
|
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
|
XtManageChild(button);
|
||||||
XtVaSetValues(button,
|
|
||||||
XmNlabelPixmap, pixmap,
|
|
||||||
XmNlabelInsensitivePixmap, insensPixmap,
|
|
||||||
XmNarmPixmap, pixmap2,
|
|
||||||
NULL);
|
|
||||||
}
|
|
||||||
XtManageChild(button);
|
|
||||||
|
|
||||||
Dimension width, height;
|
{
|
||||||
XtVaGetValues(button, XmNwidth, & width, XmNheight, & height,
|
Dimension width, height;
|
||||||
NULL);
|
XtVaGetValues(button,
|
||||||
currentX += width + marginX;
|
XmNwidth, &width,
|
||||||
buttonHeight = wxMax(buttonHeight, height);
|
XmNheight, & height,
|
||||||
|
NULL);
|
||||||
|
currentX += width + marginX;
|
||||||
|
buttonHeight = wxMax(buttonHeight, height);
|
||||||
|
}
|
||||||
|
|
||||||
XtAddEventHandler (button, EnterWindowMask | LeaveWindowMask,
|
XtAddEventHandler (button, EnterWindowMask | LeaveWindowMask,
|
||||||
False, wxToolButtonPopupCallback, (XtPointer) this);
|
False, wxToolButtonPopupCallback, (XtPointer) this);
|
||||||
m_widgets.Append(tool->m_index, (wxObject*) button);
|
|
||||||
|
|
||||||
prevButton = button;
|
currentSpacing = 0;
|
||||||
currentSpacing = 0;
|
break;
|
||||||
}
|
}
|
||||||
node = node->Next();
|
|
||||||
|
node = node->GetNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
SetSize(-1, -1, currentX, buttonHeight + 2*marginY);
|
SetSize(-1, -1, currentX, buttonHeight + 2*marginY);
|
||||||
@ -327,199 +447,107 @@ bool wxToolBar::CreateTools()
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxToolBar::SetToolBitmapSize(const wxSize& size)
|
wxToolBarTool *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x),
|
||||||
|
wxCoord WXUNUSED(y)) const
|
||||||
{
|
{
|
||||||
// TODO not necessary?
|
wxFAIL_MSG( _T("TODO") );
|
||||||
m_defaultWidth = size.x; m_defaultHeight = size.y;
|
|
||||||
|
return (wxToolBarTool *)NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxSize wxToolBar::GetMaxSize() const
|
bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarTool *tool)
|
||||||
{
|
{
|
||||||
int w, h;
|
tool->Attach(this);
|
||||||
GetSize(& w, & h);
|
|
||||||
|
|
||||||
return wxSize(w, h);
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The button size is bigger than the bitmap size
|
bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarTool *tool)
|
||||||
wxSize wxToolBar::GetToolSize() const
|
|
||||||
{
|
{
|
||||||
// TODO not necessary?
|
tool->Detach();
|
||||||
return wxSize(m_defaultWidth + 8, m_defaultHeight + 7);
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxToolBar::EnableTool(int toolIndex, bool enable)
|
void wxToolBar::DoEnableTool(wxToolBarTool *tool, bool enable)
|
||||||
{
|
{
|
||||||
wxNode *node = m_tools.Find((long)toolIndex);
|
XtSetSensitive(tool->GetButtonWidget(), (Boolean) enable);
|
||||||
if (node)
|
}
|
||||||
|
|
||||||
|
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();
|
wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
|
||||||
tool->m_enabled = enable;
|
if ( tool->GetButtonWidget() == w)
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
tool->m_toggleState = toggle;
|
return tool;
|
||||||
|
|
||||||
WXWidget widget = FindWidgetForIndex(tool->m_index);
|
|
||||||
if (widget == (WXWidget) 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
XmToggleButtonSetState((Widget) widget, (Boolean) toggle, False);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
node = node->GetNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (wxToolBarTool *)NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxToolBar::ClearTools()
|
static void wxToolButtonCallback(Widget w,
|
||||||
{
|
XtPointer clientData,
|
||||||
wxNode* node = m_widgets.First();
|
XtPointer WXUNUSED(ptr))
|
||||||
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))
|
|
||||||
{
|
{
|
||||||
wxToolBar *toolBar = (wxToolBar *) clientData;
|
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);
|
// revert
|
||||||
if (!node)
|
tool->Toggle();
|
||||||
return;
|
|
||||||
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
|
|
||||||
if (tool->m_isToggle)
|
|
||||||
tool->m_toggleState = !tool->m_toggleState;
|
|
||||||
|
|
||||||
(void) toolBar->OnLeftClick(index, tool->m_toggleState);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void wxToolButtonPopupCallback (Widget w, XtPointer client_data,
|
static void wxToolButtonPopupCallback(Widget w,
|
||||||
XEvent *event, Boolean *WXUNUSED(continue_to_dispatch))
|
XtPointer client_data,
|
||||||
|
XEvent *event,
|
||||||
|
Boolean *WXUNUSED(continue_to_dispatch))
|
||||||
{
|
{
|
||||||
// TODO: retrieve delay before popping up tooltip from wxSystemSettings.
|
// TODO: retrieve delay before popping up tooltip from wxSystemSettings.
|
||||||
int delayMilli = 800;
|
static const int delayMilli = 800;
|
||||||
|
|
||||||
wxToolBar* toolBar = (wxToolBar*) client_data;
|
wxToolBar* toolBar = (wxToolBar*) client_data;
|
||||||
|
wxToolBarTool *tool = toolBar->FindToolByWidget((WXWidget) w);
|
||||||
|
|
||||||
int index = toolBar->FindIndexForWidget((WXWidget) w);
|
if ( !tool )
|
||||||
|
return;
|
||||||
|
|
||||||
if (index != -1)
|
wxString tooltip = tool->GetShortHelp();
|
||||||
{
|
if ( !tooltip )
|
||||||
wxNode *node = toolBar->GetTools().Find((long)index);
|
return;
|
||||||
if (!node)
|
|
||||||
return;
|
|
||||||
wxString str(toolBar->GetToolShortHelp(index));
|
|
||||||
if (str.IsNull() || str == "")
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!wxTheToolBarTimer)
|
if (!wxTheToolBarTimer)
|
||||||
wxTheToolBarTimer = new wxToolBarTimer;
|
wxTheToolBarTimer = new wxToolBarTimer;
|
||||||
|
|
||||||
wxToolBarTimer::buttonWidget = w;
|
|
||||||
wxToolBarTimer::helpString = str;
|
|
||||||
|
|
||||||
|
wxToolBarTimer::buttonWidget = w;
|
||||||
|
wxToolBarTimer::helpString = tooltip;
|
||||||
|
|
||||||
/************************************************************/
|
/************************************************************/
|
||||||
/* Popup help label */
|
/* Popup help label */
|
||||||
@ -551,7 +579,6 @@ static void wxToolButtonPopupCallback (Widget w, XtPointer client_data,
|
|||||||
}
|
}
|
||||||
wxToolBarTimer::help_popup = (Widget) 0;
|
wxToolBarTimer::help_popup = (Widget) 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxToolBarTimer::Notify()
|
void wxToolBarTimer::Notify()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: msw/tbar95.cpp
|
// Name: msw/tbar95.cpp
|
||||||
// Purpose: wxToolBar95
|
// Purpose: wxToolBar
|
||||||
// Author: Julian Smart
|
// Author: Julian Smart
|
||||||
// Modified by:
|
// Modified by:
|
||||||
// Created: 04/01/98
|
// Created: 04/01/98
|
||||||
@ -29,6 +29,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef WX_PRECOMP
|
#ifndef WX_PRECOMP
|
||||||
|
#include "wx/frame.h"
|
||||||
#include "wx/log.h"
|
#include "wx/log.h"
|
||||||
#include "wx/intl.h"
|
#include "wx/intl.h"
|
||||||
#include "wx/dynarray.h"
|
#include "wx/dynarray.h"
|
||||||
@ -36,7 +37,9 @@
|
|||||||
#include "wx/bitmap.h"
|
#include "wx/bitmap.h"
|
||||||
#endif
|
#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__)
|
#if !defined(__GNUWIN32__) && !defined(__SALFORDC__)
|
||||||
#include "malloc.h"
|
#include "malloc.h"
|
||||||
@ -55,7 +58,6 @@
|
|||||||
#endif // __TWIN32__
|
#endif // __TWIN32__
|
||||||
|
|
||||||
#include "wx/msw/dib.h"
|
#include "wx/msw/dib.h"
|
||||||
#include "wx/msw/tbar95.h"
|
|
||||||
#include "wx/app.h" // for GetComCtl32Version
|
#include "wx/app.h" // for GetComCtl32Version
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -74,8 +76,12 @@
|
|||||||
|
|
||||||
// Messages
|
// Messages
|
||||||
#ifndef TB_GETSTYLE
|
#ifndef TB_GETSTYLE
|
||||||
#define TB_GETSTYLE (WM_USER + 57)
|
|
||||||
#define TB_SETSTYLE (WM_USER + 56)
|
#define TB_SETSTYLE (WM_USER + 56)
|
||||||
|
#define TB_GETSTYLE (WM_USER + 57)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef TB_HITTEST
|
||||||
|
#define TB_HITTEST (WM_USER + 69)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// these values correspond to those used by comctl32.dll
|
// these values correspond to those used by comctl32.dll
|
||||||
@ -86,7 +92,7 @@
|
|||||||
#define DEFAULTBARHEIGHT 27
|
#define DEFAULTBARHEIGHT 27
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// function prototypes
|
// private function prototypes
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
static void wxMapBitmap(HBITMAP hBitmap, int width, int height);
|
static void wxMapBitmap(HBITMAP hBitmap, int width, int height);
|
||||||
@ -95,41 +101,96 @@ static void wxMapBitmap(HBITMAP hBitmap, int width, int height);
|
|||||||
// wxWin macros
|
// wxWin macros
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxToolBarBase)
|
IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(wxToolBar95, wxToolBarBase)
|
BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase)
|
||||||
EVT_MOUSE_EVENTS(wxToolBar95::OnMouseEvent)
|
EVT_MOUSE_EVENTS(wxToolBar::OnMouseEvent)
|
||||||
EVT_SYS_COLOUR_CHANGED(wxToolBar95::OnSysColourChanged)
|
EVT_SYS_COLOUR_CHANGED(wxToolBar::OnSysColourChanged)
|
||||||
END_EVENT_TABLE()
|
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
|
// 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_hBitmap = 0;
|
||||||
|
|
||||||
|
m_nButtons = 0;
|
||||||
|
|
||||||
m_defaultWidth = DEFAULTBITMAPX;
|
m_defaultWidth = DEFAULTBITMAPX;
|
||||||
m_defaultHeight = DEFAULTBITMAPY;
|
m_defaultHeight = DEFAULTBITMAPY;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxToolBar95::Create(wxWindow *parent,
|
bool wxToolBar::Create(wxWindow *parent,
|
||||||
wxWindowID id,
|
wxWindowID id,
|
||||||
const wxPoint& pos,
|
const wxPoint& pos,
|
||||||
const wxSize& size,
|
const wxSize& size,
|
||||||
long style,
|
long style,
|
||||||
const wxString& name)
|
const wxString& name)
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( (style & wxTB_VERTICAL) == 0,
|
|
||||||
wxT("Sorry, wxToolBar95 under Windows 95 only "
|
|
||||||
"supports horizontal orientation.") );
|
|
||||||
|
|
||||||
// common initialisation
|
// common initialisation
|
||||||
if ( !CreateControl(parent, id, pos, size, style, name) )
|
if ( !CreateControl(parent, id, pos, size, style, name) )
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -179,10 +240,8 @@ bool wxToolBar95::Create(wxWindow *parent,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxToolBar95::~wxToolBar95()
|
wxToolBar::~wxToolBar()
|
||||||
{
|
{
|
||||||
UnsubclassWin();
|
|
||||||
|
|
||||||
if (m_hBitmap)
|
if (m_hBitmap)
|
||||||
{
|
{
|
||||||
::DeleteObject((HBITMAP) 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.
|
// nothing special to do here - we really create the toolbar buttons in
|
||||||
// But adding tools and calling CreateTools should probably
|
// Realize() later
|
||||||
// recreate a buttonbar OK.
|
tool->Attach(this);
|
||||||
wxToolBarBase::ClearTools();
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxToolBar95::DeleteTool(int id)
|
bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool)
|
||||||
{
|
{
|
||||||
int index = GetIndexFromId(id);
|
// normally, we only delete one button, but we use several separators to
|
||||||
wxASSERT_MSG( index != wxNOT_FOUND, _T("invalid toolbar button id") );
|
// 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");
|
wxLogLastError(_T("TB_GETITEMRECT"));
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxNode *node = m_tools.Nth(index);
|
int width = r.right - r.left;
|
||||||
delete (wxToolBarTool *)node->Data();
|
|
||||||
m_tools.DeleteNode(node);
|
|
||||||
|
|
||||||
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;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxToolBar95::AddControl(wxControl *control)
|
bool wxToolBar::Realize()
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( control, FALSE, _T("toolbar: can't insert NULL control") );
|
size_t nTools = GetToolsCount();
|
||||||
|
|
||||||
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();
|
|
||||||
if ( nTools == 0 )
|
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 totalBitmapWidth = (int)(m_defaultWidth * nTools);
|
||||||
int totalBitmapHeight = (int)m_defaultHeight;
|
int totalBitmapHeight = (int)m_defaultHeight;
|
||||||
|
|
||||||
// Create a bitmap for all the tool bitmaps
|
// Create a bitmap for all the tool bitmaps
|
||||||
HDC dc = ::GetDC(NULL);
|
HBITMAP hBitmap = ::CreateCompatibleBitmap(ScreenHDC(),
|
||||||
m_hBitmap = (WXHBITMAP) ::CreateCompatibleBitmap(dc,
|
totalBitmapWidth,
|
||||||
totalBitmapWidth,
|
totalBitmapHeight);
|
||||||
totalBitmapHeight);
|
if ( !hBitmap )
|
||||||
::ReleaseDC(NULL, dc);
|
{
|
||||||
|
wxLogLastError(_T("CreateCompatibleBitmap"));
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_hBitmap = (WXHBITMAP)hBitmap;
|
||||||
|
|
||||||
// Now blit all the tools onto this bitmap
|
// Now blit all the tools onto this bitmap
|
||||||
HDC memoryDC = ::CreateCompatibleDC(NULL);
|
HDC memoryDC = ::CreateCompatibleDC(NULL);
|
||||||
HBITMAP oldBitmap = (HBITMAP) ::SelectObject(memoryDC, (HBITMAP)m_hBitmap);
|
HBITMAP oldBitmap = (HBITMAP) ::SelectObject(memoryDC, hBitmap);
|
||||||
|
|
||||||
HDC memoryDC2 = ::CreateCompatibleDC(NULL);
|
HDC memoryDC2 = ::CreateCompatibleDC(NULL);
|
||||||
|
|
||||||
@ -297,15 +359,15 @@ bool wxToolBar95::CreateTools()
|
|||||||
wxCoord x = 0;
|
wxCoord x = 0;
|
||||||
|
|
||||||
// the number of buttons (not separators)
|
// the number of buttons (not separators)
|
||||||
int noButtons = 0;
|
int nButtons = 0;
|
||||||
|
|
||||||
wxNode *node = m_tools.First();
|
wxToolBarToolsList::Node *node = m_tools.GetFirst();
|
||||||
while (node)
|
while ( node )
|
||||||
{
|
{
|
||||||
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
|
wxToolBarToolBase *tool = node->GetData();
|
||||||
if ( tool->m_toolStyle == wxTOOL_STYLE_BUTTON && tool->m_bitmap1.Ok() )
|
if ( tool->IsButton() )
|
||||||
{
|
{
|
||||||
HBITMAP hbmp = GetHbitmapOf(tool->m_bitmap1);
|
HBITMAP hbmp = GetHbitmapOf(tool->GetBitmap1());
|
||||||
if ( hbmp )
|
if ( hbmp )
|
||||||
{
|
{
|
||||||
HBITMAP oldBitmap2 = (HBITMAP)::SelectObject(memoryDC2, hbmp);
|
HBITMAP oldBitmap2 = (HBITMAP)::SelectObject(memoryDC2, hbmp);
|
||||||
@ -316,12 +378,20 @@ bool wxToolBar95::CreateTools()
|
|||||||
}
|
}
|
||||||
|
|
||||||
::SelectObject(memoryDC2, oldBitmap2);
|
::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);
|
::SelectObject(memoryDC, oldBitmap);
|
||||||
@ -329,7 +399,7 @@ bool wxToolBar95::CreateTools()
|
|||||||
::DeleteDC(memoryDC2);
|
::DeleteDC(memoryDC2);
|
||||||
|
|
||||||
// Map to system colours
|
// Map to system colours
|
||||||
wxMapBitmap((HBITMAP) m_hBitmap, totalBitmapWidth, totalBitmapHeight);
|
wxMapBitmap(hBitmap, totalBitmapWidth, totalBitmapHeight);
|
||||||
|
|
||||||
if ( oldToolBarBitmap )
|
if ( oldToolBarBitmap )
|
||||||
{
|
{
|
||||||
@ -337,59 +407,64 @@ bool wxToolBar95::CreateTools()
|
|||||||
replaceBitmap.hInstOld = NULL;
|
replaceBitmap.hInstOld = NULL;
|
||||||
replaceBitmap.hInstNew = NULL;
|
replaceBitmap.hInstNew = NULL;
|
||||||
replaceBitmap.nIDOld = (UINT) oldToolBarBitmap;
|
replaceBitmap.nIDOld = (UINT) oldToolBarBitmap;
|
||||||
replaceBitmap.nIDNew = (UINT) (HBITMAP) m_hBitmap;
|
replaceBitmap.nIDNew = (UINT) hBitmap;
|
||||||
replaceBitmap.nButtons = noButtons;
|
replaceBitmap.nButtons = nButtons;
|
||||||
if ( ::SendMessage(GetHwnd(), TB_REPLACEBITMAP,
|
if ( !::SendMessage(GetHwnd(), TB_REPLACEBITMAP,
|
||||||
0, (LPARAM) &replaceBitmap) == -1 )
|
0, (LPARAM) &replaceBitmap) )
|
||||||
{
|
{
|
||||||
wxFAIL_MSG(wxT("Could not add bitmap to toolbar"));
|
wxFAIL_MSG(wxT("Could not add bitmap to toolbar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
::DeleteObject((HBITMAP) oldToolBarBitmap);
|
::DeleteObject(oldToolBarBitmap);
|
||||||
|
|
||||||
// Now delete all the buttons
|
// Now delete all the buttons
|
||||||
int i = 0;
|
for ( size_t pos = 0; pos < m_nButtons; pos++ )
|
||||||
while ( TRUE )
|
|
||||||
{
|
{
|
||||||
// TODO: What about separators???? They don't have an id!
|
if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON, 0, 0) )
|
||||||
if ( ! ::SendMessage( GetHwnd(), TB_DELETEBUTTON, i, 0 ) )
|
{
|
||||||
break;
|
wxLogLastError("TB_DELETEBUTTON");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else // no old bitmap
|
||||||
{
|
{
|
||||||
TBADDBITMAP addBitmap;
|
TBADDBITMAP addBitmap;
|
||||||
addBitmap.hInst = 0;
|
addBitmap.hInst = 0;
|
||||||
addBitmap.nID = (UINT)m_hBitmap;
|
addBitmap.nID = (UINT) hBitmap;
|
||||||
if ( ::SendMessage(GetHwnd(), TB_ADDBITMAP,
|
if ( ::SendMessage(GetHwnd(), TB_ADDBITMAP,
|
||||||
(WPARAM) noButtons, (LPARAM)&addBitmap) == -1 )
|
(WPARAM) nButtons, (LPARAM)&addBitmap) == -1 )
|
||||||
{
|
{
|
||||||
wxFAIL_MSG(wxT("Could not add bitmap to toolbar"));
|
wxFAIL_MSG(wxT("Could not add bitmap to toolbar"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now add the buttons.
|
// Next add the buttons and separators
|
||||||
|
// -----------------------------------
|
||||||
|
|
||||||
TBBUTTON *buttons = new TBBUTTON[nTools];
|
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;
|
wxArrayInt controlIds;
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int bitmapId = 0;
|
int bitmapId = 0;
|
||||||
|
|
||||||
node = m_tools.First();
|
for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
|
||||||
while (node)
|
|
||||||
{
|
{
|
||||||
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];
|
TBBUTTON& button = buttons[i];
|
||||||
|
|
||||||
wxZeroMemory(button);
|
wxZeroMemory(button);
|
||||||
|
|
||||||
switch ( tool->m_toolStyle )
|
switch ( tool->GetStyle() )
|
||||||
{
|
{
|
||||||
case wxTOOL_STYLE_CONTROL:
|
case wxTOOL_STYLE_CONTROL:
|
||||||
controlIds.Add(i);
|
button.idCommand = tool->GetId();
|
||||||
button.idCommand = tool->m_index;
|
|
||||||
// fall through: create just a separator too
|
// fall through: create just a separator too
|
||||||
|
|
||||||
case wxTOOL_STYLE_SEPARATOR:
|
case wxTOOL_STYLE_SEPARATOR:
|
||||||
@ -399,21 +474,21 @@ bool wxToolBar95::CreateTools()
|
|||||||
|
|
||||||
case wxTOOL_STYLE_BUTTON:
|
case wxTOOL_STYLE_BUTTON:
|
||||||
button.iBitmap = bitmapId;
|
button.iBitmap = bitmapId;
|
||||||
button.idCommand = tool->m_index;
|
button.idCommand = tool->GetId();
|
||||||
|
|
||||||
if (tool->m_enabled)
|
if ( tool->IsEnabled() )
|
||||||
button.fsState |= TBSTATE_ENABLED;
|
button.fsState |= TBSTATE_ENABLED;
|
||||||
if (tool->m_toggleState)
|
if ( tool->IsToggled() )
|
||||||
button.fsState |= TBSTATE_CHECKED;
|
button.fsState |= TBSTATE_CHECKED;
|
||||||
button.fsStyle = tool->m_isToggle ? TBSTYLE_CHECK
|
|
||||||
: TBSTYLE_BUTTON;
|
button.fsStyle = tool->CanBeToggled() ? TBSTYLE_CHECK
|
||||||
|
: TBSTYLE_BUTTON;
|
||||||
|
|
||||||
bitmapId++;
|
bitmapId++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
node = node->Next();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !::SendMessage(GetHwnd(), TB_ADDBUTTONS,
|
if ( !::SendMessage(GetHwnd(), TB_ADDBUTTONS,
|
||||||
@ -424,12 +499,17 @@ bool wxToolBar95::CreateTools()
|
|||||||
|
|
||||||
delete [] buttons;
|
delete [] buttons;
|
||||||
|
|
||||||
|
// Deal with the controls finally
|
||||||
|
// ------------------------------
|
||||||
|
|
||||||
// adjust the controls size to fit nicely in the toolbar
|
// adjust the controls size to fit nicely in the toolbar
|
||||||
size_t nControls = controlIds.GetCount();
|
size_t index = 0;
|
||||||
for ( size_t nCtrl = 0; nCtrl < nControls; nCtrl++ )
|
for ( node = m_tools.GetFirst(); node; node = node->GetNext(), index++ )
|
||||||
{
|
{
|
||||||
wxToolBarTool *tool = (wxToolBarTool *)
|
wxToolBarToolBase *tool = node->GetData();
|
||||||
m_tools.Nth(controlIds[nCtrl])->Data();
|
if ( !tool->IsControl() )
|
||||||
|
continue;
|
||||||
|
|
||||||
wxControl *control = tool->GetControl();
|
wxControl *control = tool->GetControl();
|
||||||
|
|
||||||
wxSize size = control->GetSize();
|
wxSize size = control->GetSize();
|
||||||
@ -437,6 +517,15 @@ bool wxToolBar95::CreateTools()
|
|||||||
// the position of the leftmost controls corner
|
// the position of the leftmost controls corner
|
||||||
int left = -1;
|
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+
|
// TB_SETBUTTONINFO message is only supported by comctl32.dll 4.71+
|
||||||
#if defined(_WIN32_IE) && (_WIN32_IE >= 0x400 )
|
#if defined(_WIN32_IE) && (_WIN32_IE >= 0x400 )
|
||||||
// available in headers, now check whether it is available now
|
// available in headers, now check whether it is available now
|
||||||
@ -450,9 +539,9 @@ bool wxToolBar95::CreateTools()
|
|||||||
tbbi.dwMask = TBIF_SIZE;
|
tbbi.dwMask = TBIF_SIZE;
|
||||||
tbbi.cx = size.x;
|
tbbi.cx = size.x;
|
||||||
if ( !SendMessage(GetHwnd(), TB_SETBUTTONINFO,
|
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");
|
wxLogLastError("TB_SETBUTTONINFO");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -461,18 +550,7 @@ bool wxToolBar95::CreateTools()
|
|||||||
#endif // comctl32.dll 4.71
|
#endif // comctl32.dll 4.71
|
||||||
// TB_SETBUTTONINFO unavailable
|
// 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
|
// 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;
|
int widthSep = r.right - r.left;
|
||||||
left = r.left;
|
left = r.left;
|
||||||
|
|
||||||
@ -485,27 +563,24 @@ bool wxToolBar95::CreateTools()
|
|||||||
size_t nSeparators = size.x / widthSep;
|
size_t nSeparators = size.x / widthSep;
|
||||||
for ( size_t nSep = 0; nSep < nSeparators; nSep++ )
|
for ( size_t nSep = 0; nSep < nSeparators; nSep++ )
|
||||||
{
|
{
|
||||||
m_ids.Insert(0, (size_t)index);
|
|
||||||
|
|
||||||
if ( !SendMessage(GetHwnd(), TB_INSERTBUTTON,
|
if ( !SendMessage(GetHwnd(), TB_INSERTBUTTON,
|
||||||
index, (LPARAM)&tbb) )
|
index, (LPARAM)&tbb) )
|
||||||
{
|
{
|
||||||
wxLogLastError("TB_INSERTBUTTON");
|
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
|
// adjust the controls width to exactly cover the separators
|
||||||
control->SetSize((nSeparators + 1)*widthSep, -1);
|
control->SetSize((nSeparators + 1)*widthSep, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// and position the control itself correctly vertically
|
// 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 height = r.bottom - r.top;
|
||||||
int diff = height - size.y;
|
int diff = height - size.y;
|
||||||
if ( diff < 0 )
|
if ( diff < 0 )
|
||||||
@ -516,12 +591,29 @@ bool wxToolBar95::CreateTools()
|
|||||||
diff = 2;
|
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;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -530,31 +622,35 @@ bool wxToolBar95::CreateTools()
|
|||||||
// message handlers
|
// message handlers
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool wxToolBar95::MSWCommand(WXUINT cmd, WXWORD id)
|
bool wxToolBar::MSWCommand(WXUINT cmd, WXWORD id)
|
||||||
{
|
{
|
||||||
wxNode *node = m_tools.Find((long)id);
|
wxToolBarToolBase *tool = FindById((int)id);
|
||||||
if (!node)
|
if ( !tool )
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
|
if ( tool->CanBeToggled() )
|
||||||
if (tool->m_isToggle)
|
|
||||||
{
|
{
|
||||||
LRESULT state = ::SendMessage(GetHwnd(), TB_GETSTATE, id, 0);
|
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);
|
bool toggled = tool->IsToggled();
|
||||||
if ( ret == FALSE && tool->m_isToggle )
|
|
||||||
|
// 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;
|
// revert back
|
||||||
::SendMessage(GetHwnd(), TB_CHECKBUTTON,
|
toggled = !toggled;
|
||||||
(WPARAM)id, (LPARAM)MAKELONG(tool->m_toggleState, 0));
|
tool->SetToggle(toggled);
|
||||||
|
|
||||||
|
::SendMessage(GetHwnd(), TB_CHECKBUTTON, id, MAKELONG(toggled, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxToolBar95::MSWOnNotify(int WXUNUSED(idCtrl),
|
bool wxToolBar::MSWOnNotify(int WXUNUSED(idCtrl),
|
||||||
WXLPARAM lParam,
|
WXLPARAM lParam,
|
||||||
WXLPARAM *result)
|
WXLPARAM *result)
|
||||||
{
|
{
|
||||||
@ -573,13 +669,12 @@ bool wxToolBar95::MSWOnNotify(int WXUNUSED(idCtrl),
|
|||||||
|
|
||||||
LPTOOLTIPTEXT ttText = (LPTOOLTIPTEXT)lParam;
|
LPTOOLTIPTEXT ttText = (LPTOOLTIPTEXT)lParam;
|
||||||
int id = (int)ttText->hdr.idFrom;
|
int id = (int)ttText->hdr.idFrom;
|
||||||
wxNode *node = m_tools.Find((long)id);
|
|
||||||
if (!node)
|
wxToolBarToolBase *tool = FindById(id);
|
||||||
|
if ( !tool )
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
|
const wxString& help = tool->GetShortHelp();
|
||||||
|
|
||||||
const wxString& help = tool->m_shortHelpString;
|
|
||||||
|
|
||||||
if ( !help.IsEmpty() )
|
if ( !help.IsEmpty() )
|
||||||
{
|
{
|
||||||
@ -617,91 +712,116 @@ bool wxToolBar95::MSWOnNotify(int WXUNUSED(idCtrl),
|
|||||||
}
|
}
|
||||||
|
|
||||||
// For backward compatibility...
|
// For backward compatibility...
|
||||||
OnMouseEnter(tool->m_index);
|
OnMouseEnter(tool->GetId());
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// sizing stuff
|
// toolbar geometry
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void wxToolBar95::SetToolBitmapSize(const wxSize& size)
|
void wxToolBar::SetToolBitmapSize(const wxSize& size)
|
||||||
{
|
{
|
||||||
wxToolBarBase::SetToolBitmapSize(size);
|
wxToolBarBase::SetToolBitmapSize(size);
|
||||||
|
|
||||||
::SendMessage(GetHwnd(), TB_SETBITMAPSIZE, 0, MAKELONG(size.x, size.y));
|
::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
|
if ( nRows == m_maxRows )
|
||||||
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) )
|
|
||||||
{
|
{
|
||||||
// it has a side effect of filling m_maxWidth/Height variables
|
// avoid resizing the frame uselessly
|
||||||
((wxToolBar95 *)this)->SetRows(m_maxRows); // const_cast
|
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
|
// The button size is bigger than the bitmap size
|
||||||
wxSize wxToolBar95::GetToolSize() const
|
wxSize wxToolBar::GetToolSize() const
|
||||||
{
|
{
|
||||||
// FIXME: this is completely bogus (VZ)
|
// TB_GETBUTTONSIZE is supported from version 4.70
|
||||||
return wxSize(m_defaultWidth + 8, m_defaultHeight + 7);
|
#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
|
// tool state
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void wxToolBar95::EnableTool(int toolIndex, bool enable)
|
void wxToolBar::DoEnableTool(wxToolBarToolBase *tool, bool enable)
|
||||||
{
|
{
|
||||||
wxNode *node = m_tools.Find((long)toolIndex);
|
::SendMessage(GetHwnd(), TB_ENABLEBUTTON,
|
||||||
if (node)
|
(WPARAM)tool->GetId(), (LPARAM)MAKELONG(enable, 0));
|
||||||
{
|
|
||||||
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
|
|
||||||
tool->m_enabled = enable;
|
|
||||||
::SendMessage(GetHwnd(), TB_ENABLEBUTTON,
|
|
||||||
(WPARAM)toolIndex, (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);
|
::SendMessage(GetHwnd(), TB_CHECKBUTTON,
|
||||||
if (node)
|
(WPARAM)tool->GetId(), (LPARAM)MAKELONG(toggle, 0));
|
||||||
{
|
|
||||||
wxToolBarTool *tool = (wxToolBarTool *)node->Data();
|
|
||||||
if (tool->m_isToggle)
|
|
||||||
{
|
|
||||||
tool->m_toggleState = toggle;
|
|
||||||
::SendMessage(GetHwnd(), TB_CHECKBUTTON,
|
|
||||||
(WPARAM)toolIndex, (LPARAM)MAKELONG(toggle, 0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxToolBar95::GetToolState(int toolIndex) const
|
void wxToolBar::DoSetToggle(wxToolBarToolBase *tool, bool toggle)
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( GetIndexFromId(toolIndex) != wxNOT_FOUND,
|
// VZ: AFAIK, the button has to be created either with TBSTYLE_CHECK or
|
||||||
_T("invalid toolbar button id") );
|
// without, so we really need to delete the button and recreate it here
|
||||||
|
wxFAIL_MSG( _T("not implemented") );
|
||||||
return ::SendMessage(GetHwnd(), TB_ISBUTTONCHECKED,
|
|
||||||
(WPARAM)toolIndex, (LPARAM)0) != 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -709,13 +829,13 @@ bool wxToolBar95::GetToolState(int toolIndex) const
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
// Responds to colour changes, and passes event on to children.
|
// 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)),
|
m_backgroundColour = wxColour(GetRValue(GetSysColor(COLOR_BTNFACE)),
|
||||||
GetGValue(GetSysColor(COLOR_BTNFACE)), GetBValue(GetSysColor(COLOR_BTNFACE)));
|
GetGValue(GetSysColor(COLOR_BTNFACE)), GetBValue(GetSysColor(COLOR_BTNFACE)));
|
||||||
|
|
||||||
// Remap the buttons
|
// Remap the buttons
|
||||||
CreateTools();
|
Realize();
|
||||||
|
|
||||||
Refresh();
|
Refresh();
|
||||||
|
|
||||||
@ -723,7 +843,7 @@ void wxToolBar95::OnSysColourChanged(wxSysColourChangedEvent& event)
|
|||||||
wxWindow::OnSysColourChanged(event);
|
wxWindow::OnSysColourChanged(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxToolBar95::OnMouseEvent(wxMouseEvent& event)
|
void wxToolBar::OnMouseEvent(wxMouseEvent& event)
|
||||||
{
|
{
|
||||||
if (event.RightDown())
|
if (event.RightDown())
|
||||||
{
|
{
|
||||||
@ -737,21 +857,50 @@ void wxToolBar95::OnMouseEvent(wxMouseEvent& event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long wxToolBar::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// helpers
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
int wxToolBar95::GetIndexFromId(int id) const
|
|
||||||
{
|
{
|
||||||
size_t count = m_ids.GetCount();
|
if ( nMsg == WM_SIZE )
|
||||||
for ( size_t n = 0; n < count; n++ )
|
|
||||||
{
|
{
|
||||||
if ( m_ids[n] == id )
|
// calculate our minor dimenstion ourselves - we're confusing the
|
||||||
return n;
|
// 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_BUTTONSHADOW (RGB(128,128,128)) // dark grey
|
||||||
#define BGR_BUTTONFACE (RGB(192,192,192)) // bright grey
|
#define BGR_BUTTONFACE (RGB(192,192,192)) // bright grey
|
||||||
#define BGR_BUTTONHILIGHT (RGB(255,255,255)) // white
|
#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
|
#define BGR_BACKGROUND (RGB(255,000,255)) // magenta
|
||||||
|
|
||||||
void wxMapBitmap(HBITMAP hBitmap, int width, int height)
|
void wxMapBitmap(HBITMAP hBitmap, int width, int height)
|
||||||
@ -856,4 +1005,4 @@ void wxMapBitmap(HBITMAP hBitmap, int width, int height)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif // !(wxUSE_TOOLBAR && Win95)
|
#endif // wxUSE_TOOLBAR && Win95
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user