📄 tbarbase.h
字号:
/////////////////////////////////////////////////////////////////////////////
// Name: wx/tbarbase.h
// Purpose: Base class for toolbar classes
// Author: Julian Smart
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id: tbarbase.h,v 1.1 2005/03/16 06:49:27 kehc Exp $
// Copyright: (c) Julian Smart and Markus Holzem
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_TBARBASE_H_
#define _WX_TBARBASE_H_
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#if defined(__GNUG__) && !defined(__APPLE__)
#pragma interface "tbarbase.h"
#endif
#include "wx/defs.h"
#if wxUSE_TOOLBAR
#include "wx/bitmap.h"
#include "wx/list.h"
#include "wx/control.h"
class WXDLLEXPORT wxToolBarBase;
class WXDLLEXPORT wxToolBarToolBase;
class WXDLLEXPORT wxImage;
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
WXDLLEXPORT_DATA(extern const wxChar*) wxToolBarNameStr;
WXDLLEXPORT_DATA(extern const wxSize) wxDefaultSize;
WXDLLEXPORT_DATA(extern const wxPoint) wxDefaultPosition;
enum wxToolBarToolStyle
{
wxTOOL_STYLE_BUTTON = 1,
wxTOOL_STYLE_SEPARATOR = 2,
wxTOOL_STYLE_CONTROL
};
// ----------------------------------------------------------------------------
// 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 wxToolBarToolBase : public wxObject
{
public:
// ctors & dtor
// ------------
wxToolBarToolBase(wxToolBarBase *tbar = (wxToolBarBase *)NULL,
int id = wxID_SEPARATOR,
const wxString& label = wxEmptyString,
const wxBitmap& bmpNormal = wxNullBitmap,
const wxBitmap& bmpDisabled = wxNullBitmap,
wxItemKind kind = wxITEM_NORMAL,
wxObject *clientData = (wxObject *) NULL,
const wxString& shortHelpString = wxEmptyString,
const wxString& longHelpString = wxEmptyString)
: m_label(label),
m_shortHelpString(shortHelpString),
m_longHelpString(longHelpString)
{
m_tbar = tbar;
m_id = id;
m_clientData = clientData;
m_bmpNormal = bmpNormal;
m_bmpDisabled = bmpDisabled;
m_kind = kind;
m_enabled = TRUE;
m_toggled = FALSE;
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_kind = wxITEM_MAX; // invalid value
m_enabled = TRUE;
m_toggled = FALSE;
m_toolStyle = wxTOOL_STYLE_CONTROL;
}
~wxToolBarToolBase();
// accessors
// ---------
// general
int GetId() const { return m_id; }
wxControl *GetControl() const
{
wxASSERT_MSG( IsControl(), _T("this toolbar tool is not a control") );
return m_control;
}
wxToolBarBase *GetToolBar() const { return m_tbar; }
// style
bool IsButton() const { return m_toolStyle == wxTOOL_STYLE_BUTTON; }
bool IsControl() const { return m_toolStyle == wxTOOL_STYLE_CONTROL; }
bool IsSeparator() const { return m_toolStyle == wxTOOL_STYLE_SEPARATOR; }
int GetStyle() const { return m_toolStyle; }
wxItemKind GetKind() const
{
wxASSERT_MSG( IsButton(), _T("only makes sense for buttons") );
return m_kind;
}
// state
bool IsEnabled() const { return m_enabled; }
bool IsToggled() const { return m_toggled; }
bool CanBeToggled() const
{ return m_kind == wxITEM_CHECK || m_kind == wxITEM_RADIO; }
// attributes
const wxBitmap& GetNormalBitmap() const { return m_bmpNormal; }
const wxBitmap& GetDisabledBitmap() const { return m_bmpDisabled; }
const wxBitmap& GetBitmap() const
{ return IsEnabled() ? GetNormalBitmap() : GetDisabledBitmap(); }
wxString GetLabel() const { return m_label; }
wxString GetShortHelp() const { return m_shortHelpString; }
wxString GetLongHelp() const { return m_longHelpString; }
wxObject *GetClientData() const
{
if ( m_toolStyle == wxTOOL_STYLE_CONTROL )
{
return (wxObject*)m_control->GetClientData();
}
else
{
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 SetNormalBitmap(const wxBitmap& bmp) { m_bmpNormal = bmp; }
void SetDisabledBitmap(const wxBitmap& bmp) { m_bmpDisabled = bmp; }
virtual void SetLabel(const wxString& label) { m_label = label; }
void SetClientData(wxObject *clientData)
{
if ( m_toolStyle == wxTOOL_STYLE_CONTROL )
{
m_control->SetClientData(clientData);
}
else
{
m_clientData = clientData;
}
}
// add tool to/remove it from a toolbar
virtual void Detach() { m_tbar = (wxToolBarBase *)NULL; }
virtual void Attach(wxToolBarBase *tbar) { m_tbar = tbar; }
// compatibility only, don't use
#if WXWIN_COMPATIBILITY_2_2
const wxBitmap& GetBitmap1() const { return GetNormalBitmap(); }
const wxBitmap& GetBitmap2() const { return GetDisabledBitmap(); }
void SetBitmap1(const wxBitmap& bmp) { SetNormalBitmap(bmp); }
void SetBitmap2(const wxBitmap& bmp) { SetDisabledBitmap(bmp); }
#endif // WXWIN_COMPATIBILITY_2_2
protected:
wxToolBarBase *m_tbar; // the toolbar to which we belong (may be NULL)
// tool parameters
int m_toolStyle; // see enum wxToolBarToolStyle
int m_id; // the tool id, wxID_SEPARATOR for separator
wxItemKind m_kind; // for normal buttons may be wxITEM_NORMAL/CHECK/RADIO
// as controls have their own client data, no need to waste memory
union
{
wxObject *m_clientData;
wxControl *m_control;
};
// tool state
bool m_toggled;
bool m_enabled;
// normal and disabled bitmaps for the tool, both can be invalid
wxBitmap m_bmpNormal;
wxBitmap m_bmpDisabled;
// the button label
wxString m_label;
// short and long help strings
wxString m_shortHelpString;
wxString m_longHelpString;
};
// a list of toolbar tools
WX_DECLARE_EXPORTED_LIST(wxToolBarToolBase, wxToolBarToolsList);
// ----------------------------------------------------------------------------
// the base class for all toolbars
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxToolBarBase : public wxControl
{
public:
wxToolBarBase();
virtual ~wxToolBarBase();
// toolbar construction
// --------------------
// the full AddTool() function
//
// If bmpDisabled is wxNullBitmap, a shadowed version of the normal bitmap
// is created and used as the disabled image.
wxToolBarToolBase *AddTool(int id,
const wxString& label,
const wxBitmap& bitmap,
const wxBitmap& bmpDisabled,
wxItemKind kind = wxITEM_NORMAL,
const wxString& shortHelp = wxEmptyString,
const wxString& longHelp = wxEmptyString,
wxObject *data = NULL)
{
return DoAddTool(id, label, bitmap, bmpDisabled, kind,
shortHelp, longHelp, data);
}
// the most common AddTool() version
wxToolBarToolBase *AddTool(int id,
const wxString& label,
const wxBitmap& bitmap,
const wxString& shortHelp = wxEmptyString,
wxItemKind kind = wxITEM_NORMAL)
{
return AddTool(id, label, bitmap, wxNullBitmap, kind, shortHelp);
}
// add a check tool, i.e. a tool which can be toggled
wxToolBarToolBase *AddCheckTool(int id,
const wxString& label,
const wxBitmap& bitmap,
const wxBitmap& bmpDisabled = wxNullBitmap,
const wxString& shortHelp = wxEmptyString,
const wxString& longHelp = wxEmptyString,
wxObject *data = NULL)
{
return AddTool(id, label, bitmap, bmpDisabled, wxITEM_CHECK,
shortHelp, longHelp, data);
}
// add a radio tool, i.e. a tool which can be toggled and releases any
// other toggled radio tools in the same group when it happens
wxToolBarToolBase *AddRadioTool(int id,
const wxString& label,
const wxBitmap& bitmap,
const wxBitmap& bmpDisabled = wxNullBitmap,
const wxString& shortHelp = wxEmptyString,
const wxString& longHelp = wxEmptyString,
wxObject *data = NULL)
{
return AddTool(id, label, bitmap, bmpDisabled, wxITEM_RADIO,
shortHelp, longHelp, data);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -