added labels support for toolbar controls for wxMac and wxMSW (modified patch 1613603)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44903 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -69,6 +69,7 @@ All:
|
|||||||
All (GUI):
|
All (GUI):
|
||||||
|
|
||||||
- Added wxDC::StretchBlit() for wxMac and wxMSW (Vince Harron)
|
- Added wxDC::StretchBlit() for wxMac and wxMSW (Vince Harron)
|
||||||
|
- Added support for labels for toolbar controls (Vince Harron)
|
||||||
- Added wxEventBlocker class (Francesco Montorsi).
|
- Added wxEventBlocker class (Francesco Montorsi).
|
||||||
- Added wxFile/DirPickerCtrl::Get/SetFile/DirName() (Francesco Montorsi).
|
- Added wxFile/DirPickerCtrl::Get/SetFile/DirName() (Francesco Montorsi).
|
||||||
- Added wxSizerFlags::Top() and Bottom().
|
- Added wxSizerFlags::Top() and Bottom().
|
||||||
|
@@ -165,12 +165,20 @@ Toolbar destructor.
|
|||||||
|
|
||||||
\membersection{wxToolBar::AddControl}\label{wxtoolbaraddcontrol}
|
\membersection{wxToolBar::AddControl}\label{wxtoolbaraddcontrol}
|
||||||
|
|
||||||
\func{bool}{AddControl}{\param{wxControl*}{ control}}
|
\func{bool}{AddControl}{\param{wxControl*}{ control}, \param{const wxString&}{ label = ""}}
|
||||||
|
|
||||||
Adds any control to the toolbar, typically e.g. a combobox.
|
Adds any control to the toolbar, typically e.g. a combobox.
|
||||||
|
|
||||||
\docparam{control}{The control to be added.}
|
\docparam{control}{The control to be added.}
|
||||||
|
|
||||||
|
\docparam{label}{Text to be displayed near the control.}
|
||||||
|
|
||||||
|
\wxheading{Remarks}
|
||||||
|
|
||||||
|
wxMSW: the label is only displayed if there is enough space available below the embedded control.
|
||||||
|
|
||||||
|
wxMac: labels are only displayed if wxWidgets is built with wxMAC_USE_NATIVE_TOOLBAR set to 1
|
||||||
|
|
||||||
|
|
||||||
\membersection{wxToolBar::AddSeparator}\label{wxtoolbaraddseparator}
|
\membersection{wxToolBar::AddSeparator}\label{wxtoolbaraddseparator}
|
||||||
|
|
||||||
|
@@ -73,7 +73,8 @@ protected:
|
|||||||
wxObject *clientData,
|
wxObject *clientData,
|
||||||
const wxString& shortHelp,
|
const wxString& shortHelp,
|
||||||
const wxString& longHelp);
|
const wxString& longHelp);
|
||||||
virtual wxToolBarToolBase *CreateTool(wxControl *control);
|
virtual wxToolBarToolBase *CreateTool(wxControl *control,
|
||||||
|
const wxString& label);
|
||||||
|
|
||||||
virtual wxSize DoGetBestClientSize() const;
|
virtual wxSize DoGetBestClientSize() const;
|
||||||
|
|
||||||
|
@@ -93,7 +93,8 @@ protected:
|
|||||||
wxObject *clientData,
|
wxObject *clientData,
|
||||||
const wxString& shortHelp,
|
const wxString& shortHelp,
|
||||||
const wxString& longHelp);
|
const wxString& longHelp);
|
||||||
virtual wxToolBarToolBase *CreateTool(wxControl *control);
|
virtual wxToolBarToolBase *CreateTool(wxControl *control,
|
||||||
|
const wxString& label);
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
#if wxMAC_USE_NATIVE_TOOLBAR
|
#if wxMAC_USE_NATIVE_TOOLBAR
|
||||||
|
@@ -104,7 +104,9 @@ protected:
|
|||||||
wxObject *clientData,
|
wxObject *clientData,
|
||||||
const wxString& shortHelp,
|
const wxString& shortHelp,
|
||||||
const wxString& longHelp);
|
const wxString& longHelp);
|
||||||
virtual wxToolBarToolBase *CreateTool(wxControl *control);
|
|
||||||
|
virtual wxToolBarToolBase *CreateTool(wxControl *control,
|
||||||
|
const wxString& label);
|
||||||
|
|
||||||
// return the appropriate size and flags for the toolbar control
|
// return the appropriate size and flags for the toolbar control
|
||||||
virtual wxSize DoGetBestSize() const;
|
virtual wxSize DoGetBestSize() const;
|
||||||
|
@@ -91,7 +91,10 @@ public:
|
|||||||
: wxTOOL_STYLE_BUTTON;
|
: wxTOOL_STYLE_BUTTON;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxToolBarToolBase(wxToolBarBase *tbar, wxControl *control)
|
wxToolBarToolBase(wxToolBarBase *tbar,
|
||||||
|
wxControl *control,
|
||||||
|
const wxString& label)
|
||||||
|
: m_label(label)
|
||||||
{
|
{
|
||||||
m_tbar = tbar;
|
m_tbar = tbar;
|
||||||
m_control = control;
|
m_control = control;
|
||||||
@@ -316,13 +319,17 @@ public:
|
|||||||
virtual wxToolBarToolBase *AddTool (wxToolBarToolBase *tool);
|
virtual wxToolBarToolBase *AddTool (wxToolBarToolBase *tool);
|
||||||
virtual wxToolBarToolBase *InsertTool (size_t pos, wxToolBarToolBase *tool);
|
virtual wxToolBarToolBase *InsertTool (size_t pos, wxToolBarToolBase *tool);
|
||||||
|
|
||||||
// add an arbitrary control to the toolbar (notice that
|
// add an arbitrary control to the toolbar (notice that the control will be
|
||||||
// the control will be deleted by the toolbar and that it will also adjust
|
// deleted by the toolbar and that it will also adjust its position/size)
|
||||||
// its position/size)
|
|
||||||
//
|
//
|
||||||
|
// the label is optional and, if specified, will be shown near the control
|
||||||
// NB: the control should have toolbar as its parent
|
// NB: the control should have toolbar as its parent
|
||||||
virtual wxToolBarToolBase *AddControl(wxControl *control);
|
virtual wxToolBarToolBase *
|
||||||
virtual wxToolBarToolBase *InsertControl(size_t pos, wxControl *control);
|
AddControl(wxControl *control, const wxString& label = wxEmptyString);
|
||||||
|
|
||||||
|
virtual wxToolBarToolBase *
|
||||||
|
InsertControl(size_t pos, wxControl *control,
|
||||||
|
const wxString& label = wxEmptyString);
|
||||||
|
|
||||||
// get the control with the given id or return NULL
|
// get the control with the given id or return NULL
|
||||||
virtual wxControl *FindControl( int toolid );
|
virtual wxControl *FindControl( int toolid );
|
||||||
@@ -565,7 +572,8 @@ protected:
|
|||||||
const wxString& shortHelp,
|
const wxString& shortHelp,
|
||||||
const wxString& longHelp) = 0;
|
const wxString& longHelp) = 0;
|
||||||
|
|
||||||
virtual wxToolBarToolBase *CreateTool(wxControl *control) = 0;
|
virtual wxToolBarToolBase *CreateTool(wxControl *control,
|
||||||
|
const wxString& label) = 0;
|
||||||
|
|
||||||
// helper functions
|
// helper functions
|
||||||
// ----------------
|
// ----------------
|
||||||
|
@@ -98,7 +98,8 @@ protected:
|
|||||||
wxObject *clientData,
|
wxObject *clientData,
|
||||||
const wxString& shortHelp,
|
const wxString& shortHelp,
|
||||||
const wxString& longHelp);
|
const wxString& longHelp);
|
||||||
virtual wxToolBarToolBase *CreateTool(wxControl *control);
|
virtual wxToolBarToolBase *CreateTool(wxControl *control,
|
||||||
|
const wxString& label);
|
||||||
|
|
||||||
virtual wxSize DoGetBestClientSize() const;
|
virtual wxSize DoGetBestClientSize() const;
|
||||||
virtual void DoSetSize(int x, int y,
|
virtual void DoSetSize(int x, int y,
|
||||||
|
@@ -402,7 +402,7 @@ void MyFrame::RecreateToolbar()
|
|||||||
combo->Append(_T("combobox"));
|
combo->Append(_T("combobox"));
|
||||||
combo->Append(_T("in a"));
|
combo->Append(_T("in a"));
|
||||||
combo->Append(_T("toolbar"));
|
combo->Append(_T("toolbar"));
|
||||||
toolBar->AddControl(combo);
|
toolBar->AddControl(combo, _T("Combo Label"));
|
||||||
|
|
||||||
wxSpinCtrl *spin = new wxSpinCtrl( toolBar, ID_SPIN, wxT("0"), wxDefaultPosition, wxSize(80,wxDefaultCoord), 0, 0, 100 );
|
wxSpinCtrl *spin = new wxSpinCtrl( toolBar, ID_SPIN, wxT("0"), wxDefaultPosition, wxSize(80,wxDefaultCoord), 0, 0, 100 );
|
||||||
toolBar->AddControl( spin );
|
toolBar->AddControl( spin );
|
||||||
|
@@ -197,12 +197,16 @@ wxToolBarBase::InsertTool(size_t pos, wxToolBarToolBase *tool)
|
|||||||
return tool;
|
return tool;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxToolBarToolBase *wxToolBarBase::AddControl(wxControl *control)
|
wxToolBarToolBase *
|
||||||
|
wxToolBarBase::AddControl(wxControl *control, const wxString& label)
|
||||||
{
|
{
|
||||||
return InsertControl(GetToolsCount(), control);
|
return InsertControl(GetToolsCount(), control, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxToolBarToolBase *wxToolBarBase::InsertControl(size_t pos, wxControl *control)
|
wxToolBarToolBase *
|
||||||
|
wxToolBarBase::InsertControl(size_t pos,
|
||||||
|
wxControl *control,
|
||||||
|
const wxString& label)
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( control, (wxToolBarToolBase *)NULL,
|
wxCHECK_MSG( control, (wxToolBarToolBase *)NULL,
|
||||||
_T("toolbar: can't insert NULL control") );
|
_T("toolbar: can't insert NULL control") );
|
||||||
@@ -213,7 +217,7 @@ wxToolBarToolBase *wxToolBarBase::InsertControl(size_t pos, wxControl *control)
|
|||||||
wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
|
wxCHECK_MSG( pos <= GetToolsCount(), (wxToolBarToolBase *)NULL,
|
||||||
_T("invalid position in wxToolBar::InsertControl()") );
|
_T("invalid position in wxToolBar::InsertControl()") );
|
||||||
|
|
||||||
wxToolBarToolBase *tool = CreateTool(control);
|
wxToolBarToolBase *tool = CreateTool(control, label);
|
||||||
|
|
||||||
if ( !InsertTool(pos, tool) )
|
if ( !InsertTool(pos, tool) )
|
||||||
{
|
{
|
||||||
|
@@ -66,8 +66,10 @@ public:
|
|||||||
m_button = NULL;
|
m_button = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxButtonToolBarTool(wxButtonToolBar *tbar, wxControl *control)
|
wxButtonToolBarTool(wxButtonToolBar *tbar,
|
||||||
: wxToolBarToolBase(tbar, control)
|
wxControl *control,
|
||||||
|
const wxString& label)
|
||||||
|
: wxToolBarToolBase(tbar, control, label)
|
||||||
{
|
{
|
||||||
m_x = m_y = wxDefaultCoord;
|
m_x = m_y = wxDefaultCoord;
|
||||||
m_width =
|
m_width =
|
||||||
@@ -271,9 +273,10 @@ wxToolBarToolBase *wxButtonToolBar::CreateTool(int id,
|
|||||||
clientData, shortHelp, longHelp);
|
clientData, shortHelp, longHelp);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxToolBarToolBase *wxButtonToolBar::CreateTool(wxControl *control)
|
wxToolBarToolBase *wxButtonToolBar::CreateTool(wxControl *control,
|
||||||
|
const wxString& label)
|
||||||
{
|
{
|
||||||
return new wxButtonToolBarTool(this, control);
|
return new wxButtonToolBarTool(this, control, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -72,8 +72,8 @@ public:
|
|||||||
const wxString& shortHelp,
|
const wxString& shortHelp,
|
||||||
const wxString& longHelp );
|
const wxString& longHelp );
|
||||||
|
|
||||||
wxToolBarTool(wxToolBar *tbar, wxControl *control)
|
wxToolBarTool(wxToolBar *tbar, wxControl *control, const wxString& label)
|
||||||
: wxToolBarToolBase(tbar, control)
|
: wxToolBarToolBase(tbar, control, label)
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
if (control != NULL)
|
if (control != NULL)
|
||||||
@@ -533,9 +533,10 @@ wxToolBarToolBase *wxToolBar::CreateTool(
|
|||||||
clientData, shortHelp, longHelp );
|
clientData, shortHelp, longHelp );
|
||||||
}
|
}
|
||||||
|
|
||||||
wxToolBarToolBase * wxToolBar::CreateTool( wxControl *control )
|
wxToolBarToolBase *
|
||||||
|
wxToolBar::CreateTool(wxControl *control, const wxString& label)
|
||||||
{
|
{
|
||||||
return new wxToolBarTool( this, control );
|
return new wxToolBarTool(this, control, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxToolBar::Init()
|
void wxToolBar::Init()
|
||||||
@@ -843,7 +844,7 @@ bool wxToolBar::Create(
|
|||||||
HIToolbarSetDisplayMode( (HIToolbarRef) m_macHIToolbarRef, mode );
|
HIToolbarSetDisplayMode( (HIToolbarRef) m_macHIToolbarRef, mode );
|
||||||
HIToolbarSetDisplaySize( (HIToolbarRef) m_macHIToolbarRef, displaySize );
|
HIToolbarSetDisplaySize( (HIToolbarRef) m_macHIToolbarRef, displaySize );
|
||||||
}
|
}
|
||||||
#endif
|
#endif // wxMAC_USE_NATIVE_TOOLBAR
|
||||||
|
|
||||||
return (err == noErr);
|
return (err == noErr);
|
||||||
}
|
}
|
||||||
@@ -1403,6 +1404,10 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase)
|
|||||||
OSStatus err = 0;
|
OSStatus err = 0;
|
||||||
tool->Attach( this );
|
tool->Attach( this );
|
||||||
|
|
||||||
|
#if wxMAC_USE_NATIVE_TOOLBAR
|
||||||
|
HIToolbarItemRef item;
|
||||||
|
#endif
|
||||||
|
|
||||||
switch (tool->GetStyle())
|
switch (tool->GetStyle())
|
||||||
{
|
{
|
||||||
case wxTOOL_STYLE_SEPARATOR:
|
case wxTOOL_STYLE_SEPARATOR:
|
||||||
@@ -1415,21 +1420,18 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase)
|
|||||||
else
|
else
|
||||||
toolrect.right = toolSize.x;
|
toolrect.right = toolSize.x;
|
||||||
|
|
||||||
#ifdef __WXMAC_OSX__
|
|
||||||
// in flat style we need a visual separator
|
// in flat style we need a visual separator
|
||||||
#if wxMAC_USE_NATIVE_TOOLBAR
|
#if wxMAC_USE_NATIVE_TOOLBAR
|
||||||
HIToolbarItemRef item;
|
|
||||||
err = HIToolbarItemCreate(
|
err = HIToolbarItemCreate(
|
||||||
kHIToolbarSeparatorIdentifier,
|
kHIToolbarSeparatorIdentifier,
|
||||||
kHIToolbarItemCantBeRemoved | kHIToolbarItemIsSeparator | kHIToolbarItemAllowDuplicates,
|
kHIToolbarItemCantBeRemoved | kHIToolbarItemIsSeparator | kHIToolbarItemAllowDuplicates,
|
||||||
&item );
|
&item );
|
||||||
if (err == noErr)
|
if (err == noErr)
|
||||||
tool->SetToolbarItemRef( item );
|
tool->SetToolbarItemRef( item );
|
||||||
#endif
|
#endif // wxMAC_USE_NATIVE_TOOLBAR
|
||||||
|
|
||||||
CreateSeparatorControl( window, &toolrect, &controlHandle );
|
CreateSeparatorControl( window, &toolrect, &controlHandle );
|
||||||
tool->SetControlHandle( controlHandle );
|
tool->SetControlHandle( controlHandle );
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -1454,7 +1456,6 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if wxMAC_USE_NATIVE_TOOLBAR
|
#if wxMAC_USE_NATIVE_TOOLBAR
|
||||||
HIToolbarItemRef item;
|
|
||||||
wxString labelStr = wxString::Format(wxT("%xd"), (int)tool);
|
wxString labelStr = wxString::Format(wxT("%xd"), (int)tool);
|
||||||
err = HIToolbarItemCreate(
|
err = HIToolbarItemCreate(
|
||||||
wxMacCFStringHolder(labelStr, wxFont::GetDefaultEncoding()),
|
wxMacCFStringHolder(labelStr, wxFont::GetDefaultEncoding()),
|
||||||
@@ -1464,12 +1465,12 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase)
|
|||||||
InstallEventHandler(
|
InstallEventHandler(
|
||||||
HIObjectGetEventTarget(item), GetwxMacToolBarEventHandlerUPP(),
|
HIObjectGetEventTarget(item), GetwxMacToolBarEventHandlerUPP(),
|
||||||
GetEventTypeCount(toolBarEventList), toolBarEventList, tool, NULL );
|
GetEventTypeCount(toolBarEventList), toolBarEventList, tool, NULL );
|
||||||
HIToolbarItemSetLabel( item, wxMacCFStringHolder(tool->GetLabel(), m_font.GetEncoding()) );
|
|
||||||
HIToolbarItemSetIconRef( item, info.u.iconRef );
|
HIToolbarItemSetIconRef( item, info.u.iconRef );
|
||||||
HIToolbarItemSetCommandID( item, kHIToolbarCommandPressAction );
|
HIToolbarItemSetCommandID( item, kHIToolbarCommandPressAction );
|
||||||
tool->SetToolbarItemRef( item );
|
tool->SetToolbarItemRef( item );
|
||||||
}
|
}
|
||||||
#endif
|
#endif // wxMAC_USE_NATIVE_TOOLBAR
|
||||||
|
|
||||||
wxMacReleaseBitmapButton( &info );
|
wxMacReleaseBitmapButton( &info );
|
||||||
|
|
||||||
@@ -1516,6 +1517,19 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if wxMAC_USE_NATIVE_TOOLBAR
|
||||||
|
wxString label = tool->GetLabel();
|
||||||
|
if ( !label.empty() )
|
||||||
|
{
|
||||||
|
// strip mnemonics from the label for compatibility
|
||||||
|
// with the usual labels in wxStaticText sense
|
||||||
|
label = wxStaticText(label);
|
||||||
|
|
||||||
|
HIToolbarItemSetLabel(item,
|
||||||
|
wxMacCFStringHolder(label, m_font.GetEncoding()));
|
||||||
|
}
|
||||||
|
#endif // wxMAC_USE_NATIVE_TOOLBAR
|
||||||
|
|
||||||
if ( err == noErr )
|
if ( err == noErr )
|
||||||
{
|
{
|
||||||
if ( controlHandle )
|
if ( controlHandle )
|
||||||
|
@@ -148,14 +148,38 @@ public:
|
|||||||
clientData, shortHelp, longHelp)
|
clientData, shortHelp, longHelp)
|
||||||
{
|
{
|
||||||
m_nSepCount = 0;
|
m_nSepCount = 0;
|
||||||
|
m_staticText = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxToolBarTool(wxToolBar *tbar, wxControl *control)
|
wxToolBarTool(wxToolBar *tbar, wxControl *control, const wxString& label)
|
||||||
: wxToolBarToolBase(tbar, control)
|
: wxToolBarToolBase(tbar, control, label)
|
||||||
{
|
{
|
||||||
|
if ( IsControl() && !m_label.empty() )
|
||||||
|
{
|
||||||
|
// create a control to render the control's label
|
||||||
|
m_staticText = new wxStaticText
|
||||||
|
(
|
||||||
|
m_tbar,
|
||||||
|
wxID_ANY,
|
||||||
|
m_label,
|
||||||
|
wxDefaultPosition,
|
||||||
|
wxDefaultSize,
|
||||||
|
wxALIGN_CENTRE | wxST_NO_AUTORESIZE
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else // no label
|
||||||
|
{
|
||||||
|
m_staticText = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
m_nSepCount = 1;
|
m_nSepCount = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual ~wxToolBarTool()
|
||||||
|
{
|
||||||
|
delete m_staticText;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void SetLabel(const wxString& label)
|
virtual void SetLabel(const wxString& label)
|
||||||
{
|
{
|
||||||
if ( label == m_label )
|
if ( label == m_label )
|
||||||
@@ -163,12 +187,23 @@ public:
|
|||||||
|
|
||||||
wxToolBarToolBase::SetLabel(label);
|
wxToolBarToolBase::SetLabel(label);
|
||||||
|
|
||||||
|
if ( m_staticText )
|
||||||
|
m_staticText->SetLabel(label);
|
||||||
|
|
||||||
// we need to update the label shown in the toolbar because it has a
|
// we need to update the label shown in the toolbar because it has a
|
||||||
// pointer to the internal buffer of the old label
|
// pointer to the internal buffer of the old label
|
||||||
//
|
//
|
||||||
// TODO: use TB_SETBUTTONINFO
|
// TODO: use TB_SETBUTTONINFO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxStaticText* GetStaticText()
|
||||||
|
{
|
||||||
|
wxASSERT_MSG( IsControl(),
|
||||||
|
_T("only makes sense for embedded control tools") );
|
||||||
|
|
||||||
|
return m_staticText;
|
||||||
|
}
|
||||||
|
|
||||||
// set/get the number of separators which we use to cover the space used by
|
// set/get the number of separators which we use to cover the space used by
|
||||||
// a control in the toolbar
|
// a control in the toolbar
|
||||||
void SetSeparatorsCount(size_t count) { m_nSepCount = count; }
|
void SetSeparatorsCount(size_t count) { m_nSepCount = count; }
|
||||||
@@ -176,6 +211,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
size_t m_nSepCount;
|
size_t m_nSepCount;
|
||||||
|
wxStaticText *m_staticText;
|
||||||
|
|
||||||
DECLARE_NO_COPY_CLASS(wxToolBarTool)
|
DECLARE_NO_COPY_CLASS(wxToolBarTool)
|
||||||
};
|
};
|
||||||
@@ -201,9 +237,10 @@ wxToolBarToolBase *wxToolBar::CreateTool(int id,
|
|||||||
clientData, shortHelp, longHelp);
|
clientData, shortHelp, longHelp);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control)
|
wxToolBarToolBase *
|
||||||
|
wxToolBar::CreateTool(wxControl *control, const wxString& label)
|
||||||
{
|
{
|
||||||
return new wxToolBarTool(this, control);
|
return new wxToolBarTool(this, control, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -489,13 +526,16 @@ bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool)
|
|||||||
// takes care of all normal items)
|
// takes care of all normal items)
|
||||||
for ( /* node -> first after deleted */ ; node; node = node->GetNext() )
|
for ( /* node -> first after deleted */ ; node; node = node->GetNext() )
|
||||||
{
|
{
|
||||||
wxToolBarToolBase *tool2 = node->GetData();
|
wxToolBarTool *tool2 = (wxToolBarTool*)node->GetData();
|
||||||
if ( tool2->IsControl() )
|
if ( tool2->IsControl() )
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
wxControl *control = tool2->GetControl();
|
wxControl *control = tool2->GetControl();
|
||||||
control->GetPosition(&x, NULL);
|
control->GetPosition(&x, NULL);
|
||||||
control->Move(x - width, wxDefaultCoord);
|
control->Move(x - width, wxDefaultCoord);
|
||||||
|
|
||||||
|
wxStaticText* staticText = tool2->GetStaticText();
|
||||||
|
staticText->Move(x - width, wxDefaultCoord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -944,7 +984,7 @@ bool wxToolBar::Realize()
|
|||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
for ( node = m_tools.GetFirst(); node; node = node->GetNext(), index++ )
|
for ( node = m_tools.GetFirst(); node; node = node->GetNext(), index++ )
|
||||||
{
|
{
|
||||||
wxToolBarToolBase *tool = node->GetData();
|
wxToolBarTool *tool = (wxToolBarTool*)node->GetData();
|
||||||
|
|
||||||
// we calculate the running y coord for vertical toolbars so we need to
|
// we calculate the running y coord for vertical toolbars so we need to
|
||||||
// get the items size for all items but for the horizontal ones we
|
// get the items size for all items but for the horizontal ones we
|
||||||
@@ -971,7 +1011,15 @@ bool wxToolBar::Realize()
|
|||||||
}
|
}
|
||||||
|
|
||||||
wxControl *control = tool->GetControl();
|
wxControl *control = tool->GetControl();
|
||||||
|
wxStaticText * const staticText = tool->GetStaticText();
|
||||||
|
|
||||||
wxSize size = control->GetSize();
|
wxSize size = control->GetSize();
|
||||||
|
wxSize staticTextSize;
|
||||||
|
if ( staticText )
|
||||||
|
{
|
||||||
|
staticTextSize = staticText->GetSize();
|
||||||
|
staticTextSize.y += 3; // margin between control and its label
|
||||||
|
}
|
||||||
|
|
||||||
// the position of the leftmost controls corner
|
// the position of the leftmost controls corner
|
||||||
int left = wxDefaultCoord;
|
int left = wxDefaultCoord;
|
||||||
@@ -1026,12 +1074,24 @@ bool wxToolBar::Realize()
|
|||||||
((wxToolBarTool *)tool)->SetSeparatorsCount(nSeparators);
|
((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, wxDefaultCoord);
|
size.x = (nSeparators + 1)*widthSep;
|
||||||
|
control->SetSize(size.x, wxDefaultCoord);
|
||||||
}
|
}
|
||||||
|
|
||||||
// position the control itself correctly vertically
|
// position the control itself correctly vertically centering it on the
|
||||||
int height = r.bottom - r.top;
|
// icon area of the toolbar
|
||||||
|
int height = r.bottom - r.top - staticTextSize.y;
|
||||||
|
|
||||||
int diff = height - size.y;
|
int diff = height - size.y;
|
||||||
|
if ( diff < 0 || !HasFlag(wxTB_TEXT) )
|
||||||
|
{
|
||||||
|
// not enough room for the static text
|
||||||
|
if ( staticText )
|
||||||
|
staticText->Hide();
|
||||||
|
|
||||||
|
// recalculate height & diff without the staticText control
|
||||||
|
height = r.bottom - r.top;
|
||||||
|
diff = height - size.y;
|
||||||
if ( diff < 0 )
|
if ( diff < 0 )
|
||||||
{
|
{
|
||||||
// the control is too high, resize to fit
|
// the control is too high, resize to fit
|
||||||
@@ -1039,6 +1099,12 @@ bool wxToolBar::Realize()
|
|||||||
|
|
||||||
diff = 2;
|
diff = 2;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else // enough space for both the control and the label
|
||||||
|
{
|
||||||
|
if ( staticText )
|
||||||
|
staticText->Show();
|
||||||
|
}
|
||||||
|
|
||||||
int top;
|
int top;
|
||||||
if ( IsVertical() )
|
if ( IsVertical() )
|
||||||
@@ -1057,6 +1123,11 @@ bool wxToolBar::Realize()
|
|||||||
}
|
}
|
||||||
|
|
||||||
control->Move(left, top + (diff + 1) / 2);
|
control->Move(left, top + (diff + 1) / 2);
|
||||||
|
if ( staticText )
|
||||||
|
{
|
||||||
|
staticText->Move(left + (size.x - staticTextSize.x)/2,
|
||||||
|
r.bottom - staticTextSize.y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// the max index is the "real" number of buttons - i.e. counting even the
|
// the max index is the "real" number of buttons - i.e. counting even the
|
||||||
@@ -1539,12 +1610,18 @@ bool wxToolBar::HandlePaint(WXWPARAM wParam, WXLPARAM lParam)
|
|||||||
// otherwise
|
// otherwise
|
||||||
for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
|
for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
|
||||||
{
|
{
|
||||||
wxToolBarToolBase *tool = node->GetData();
|
wxToolBarTool *tool = (wxToolBarTool*)node->GetData();
|
||||||
if ( tool->IsControl() )
|
if ( tool->IsControl() )
|
||||||
{
|
{
|
||||||
// get the control rect in our client coords
|
// get the control rect in our client coords
|
||||||
wxControl *control = tool->GetControl();
|
wxControl *control = tool->GetControl();
|
||||||
|
wxStaticText *staticText = tool->GetStaticText();
|
||||||
wxRect rectCtrl = control->GetRect();
|
wxRect rectCtrl = control->GetRect();
|
||||||
|
wxRect rectStaticText(0,0,0,0);
|
||||||
|
if ( staticText )
|
||||||
|
{
|
||||||
|
rectStaticText = staticText->GetRect();
|
||||||
|
}
|
||||||
|
|
||||||
// iterate over all buttons
|
// iterate over all buttons
|
||||||
TBBUTTON tbb;
|
TBBUTTON tbb;
|
||||||
@@ -1585,6 +1662,15 @@ bool wxToolBar::HandlePaint(WXWPARAM wParam, WXLPARAM lParam)
|
|||||||
// style in the parent: the controls can disappear
|
// style in the parent: the controls can disappear
|
||||||
control->Refresh(false);
|
control->Refresh(false);
|
||||||
}
|
}
|
||||||
|
if ( staticText && rectStaticText.Intersects(rectItem) )
|
||||||
|
{
|
||||||
|
// yes, do erase it!
|
||||||
|
dc.DrawRectangle(rectItem);
|
||||||
|
|
||||||
|
// Necessary in case we use a no-paint-on-size
|
||||||
|
// style in the parent: the controls can disappear
|
||||||
|
staticText->Refresh(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -104,8 +104,8 @@ public:
|
|||||||
m_underMouse = false;
|
m_underMouse = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxToolBarTool(wxToolBar *tbar, wxControl *control)
|
wxToolBarTool(wxToolBar *tbar, wxControl *control, const wxString& label)
|
||||||
: wxToolBarToolBase(tbar, control)
|
: wxToolBarToolBase(tbar, control, label)
|
||||||
{
|
{
|
||||||
// no position yet
|
// no position yet
|
||||||
m_x =
|
m_x =
|
||||||
@@ -328,9 +328,10 @@ wxToolBarToolBase *wxToolBar::CreateTool(int id,
|
|||||||
clientData, shortHelp, longHelp);
|
clientData, shortHelp, longHelp);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control)
|
wxToolBarToolBase *
|
||||||
|
wxToolBar::CreateTool(wxControl *control, const wxString& label)
|
||||||
{
|
{
|
||||||
return new wxToolBarTool(this, control);
|
return new wxToolBarTool(this, control, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user