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:
Vadim Zeitlin
2007-03-18 23:13:18 +00:00
parent 88c23b64c7
commit cdb11cb99e
13 changed files with 235 additions and 105 deletions

View File

@@ -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().

View File

@@ -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}

View File

@@ -6,7 +6,7 @@
// Created: 2006-04-13 // Created: 2006-04-13
// Id: $Id$ // Id: $Id$
// Copyright: (c) Julian Smart, Robert Roebling, Vadim Zeitlin, // Copyright: (c) Julian Smart, Robert Roebling, Vadim Zeitlin,
// SciTech Software, Inc. // SciTech Software, Inc.
// Licence: wxWindows licence // Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@@ -23,7 +23,7 @@ class WXDLLEXPORT wxButtonToolBarTool;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class WXDLLEXPORT wxButtonToolBar : public wxToolBarBase class WXDLLEXPORT wxButtonToolBar : public wxToolBarBase
{ {
public: public:
// construction/destruction // construction/destruction
wxButtonToolBar() { Init(); } wxButtonToolBar() { Init(); }
@@ -45,7 +45,7 @@ public:
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
long style = 0, long style = 0,
const wxString& name = wxToolBarNameStr ); const wxString& name = wxToolBarNameStr );
virtual ~wxButtonToolBar(); virtual ~wxButtonToolBar();
virtual bool Realize(); virtual bool Realize();
@@ -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;

View File

@@ -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

View File

@@ -56,7 +56,7 @@ public:
virtual void SetToolNormalBitmap(int id, const wxBitmap& bitmap); virtual void SetToolNormalBitmap(int id, const wxBitmap& bitmap);
virtual void SetToolDisabledBitmap(int id, const wxBitmap& bitmap); virtual void SetToolDisabledBitmap(int id, const wxBitmap& bitmap);
// implementation only from now on // implementation only from now on
// ------------------------------- // -------------------------------
@@ -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;

View File

@@ -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
// ---------------- // ----------------

View File

@@ -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,

View File

@@ -402,14 +402,14 @@ 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 );
wxTextCtrl *text = new wxTextCtrl( toolBar, -1, wxT("text"), wxDefaultPosition, wxSize(80,wxDefaultCoord) ); wxTextCtrl *text = new wxTextCtrl( toolBar, -1, wxT("text"), wxDefaultPosition, wxSize(80,wxDefaultCoord) );
toolBar->AddControl( text ); toolBar->AddControl( text );
wxSearchCtrl *srch = new wxSearchCtrl( toolBar, -1, wxT("xx"), wxDefaultPosition, wxSize(80,wxDefaultCoord), wxSUNKEN_BORDER ); wxSearchCtrl *srch = new wxSearchCtrl( toolBar, -1, wxT("xx"), wxDefaultPosition, wxSize(80,wxDefaultCoord), wxSUNKEN_BORDER );
toolBar->AddControl( srch ); toolBar->AddControl( srch );
} }

View File

@@ -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) )
{ {

View File

@@ -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);
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -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)
@@ -176,7 +176,7 @@ public:
enc = f.GetEncoding(); enc = f.GetEncoding();
else else
enc = wxFont::GetDefaultEncoding(); enc = wxFont::GetDefaultEncoding();
HIToolbarItemSetHelpText( HIToolbarItemSetHelpText(
m_toolbarItemRef, m_toolbarItemRef,
wxMacCFStringHolder( GetShortHelp(), enc ), wxMacCFStringHolder( GetShortHelp(), enc ),
@@ -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()
@@ -553,26 +554,26 @@ void wxToolBar::Init()
#define kControlToolbarItemClassID CFSTR( "org.wxwidgets.controltoolbaritem" ) #define kControlToolbarItemClassID CFSTR( "org.wxwidgets.controltoolbaritem" )
const EventTypeSpec kEvents[] = const EventTypeSpec kEvents[] =
{ {
{ kEventClassHIObject, kEventHIObjectConstruct }, { kEventClassHIObject, kEventHIObjectConstruct },
{ kEventClassHIObject, kEventHIObjectInitialize }, { kEventClassHIObject, kEventHIObjectInitialize },
{ kEventClassHIObject, kEventHIObjectDestruct }, { kEventClassHIObject, kEventHIObjectDestruct },
{ kEventClassToolbarItem, kEventToolbarItemCreateCustomView } { kEventClassToolbarItem, kEventToolbarItemCreateCustomView }
}; };
const EventTypeSpec kViewEvents[] = const EventTypeSpec kViewEvents[] =
{ {
{ kEventClassControl, kEventControlGetSizeConstraints } { kEventClassControl, kEventControlGetSizeConstraints }
}; };
struct ControlToolbarItem struct ControlToolbarItem
{ {
HIToolbarItemRef toolbarItem; HIToolbarItemRef toolbarItem;
HIViewRef viewRef; HIViewRef viewRef;
wxSize lastValidSize ; wxSize lastValidSize ;
}; };
static pascal OSStatus ControlToolbarItemHandler( EventHandlerCallRef inCallRef, EventRef inEvent, void* inUserData ) static pascal OSStatus ControlToolbarItemHandler( EventHandlerCallRef inCallRef, EventRef inEvent, void* inUserData )
{ {
@@ -588,20 +589,20 @@ static pascal OSStatus ControlToolbarItemHandler( EventHandlerCallRef inCallRef,
{ {
HIObjectRef toolbarItem; HIObjectRef toolbarItem;
ControlToolbarItem* item; ControlToolbarItem* item;
GetEventParameter( inEvent, kEventParamHIObjectInstance, typeHIObjectRef, NULL, GetEventParameter( inEvent, kEventParamHIObjectInstance, typeHIObjectRef, NULL,
sizeof( HIObjectRef ), NULL, &toolbarItem ); sizeof( HIObjectRef ), NULL, &toolbarItem );
item = (ControlToolbarItem*) malloc(sizeof(ControlToolbarItem)) ; item = (ControlToolbarItem*) malloc(sizeof(ControlToolbarItem)) ;
item->toolbarItem = toolbarItem ; item->toolbarItem = toolbarItem ;
item->viewRef = NULL ; item->viewRef = NULL ;
SetEventParameter( inEvent, kEventParamHIObjectInstance, typeVoidPtr, sizeof( void * ), &item ); SetEventParameter( inEvent, kEventParamHIObjectInstance, typeVoidPtr, sizeof( void * ), &item );
result = noErr ; result = noErr ;
} }
break; break;
case kEventHIObjectInitialize: case kEventHIObjectInitialize:
result = CallNextEventHandler( inCallRef, inEvent ); result = CallNextEventHandler( inCallRef, inEvent );
if ( result == noErr ) if ( result == noErr )
@@ -609,12 +610,12 @@ static pascal OSStatus ControlToolbarItemHandler( EventHandlerCallRef inCallRef,
CFDataRef data; CFDataRef data;
GetEventParameter( inEvent, kEventParamToolbarItemConfigData, typeCFTypeRef, NULL, GetEventParameter( inEvent, kEventParamToolbarItemConfigData, typeCFTypeRef, NULL,
sizeof( CFTypeRef ), NULL, &data ); sizeof( CFTypeRef ), NULL, &data );
HIViewRef viewRef ; HIViewRef viewRef ;
wxASSERT_MSG( CFDataGetLength( data ) == sizeof( viewRef ) , wxT("Illegal Data passed") ) ; wxASSERT_MSG( CFDataGetLength( data ) == sizeof( viewRef ) , wxT("Illegal Data passed") ) ;
memcpy( &viewRef , CFDataGetBytePtr( data ) , sizeof( viewRef ) ) ; memcpy( &viewRef , CFDataGetBytePtr( data ) , sizeof( viewRef ) ) ;
object->viewRef = (HIViewRef) viewRef ; object->viewRef = (HIViewRef) viewRef ;
result = noErr ; result = noErr ;
@@ -628,7 +629,7 @@ static pascal OSStatus ControlToolbarItemHandler( EventHandlerCallRef inCallRef,
HIViewRef viewRef = object->viewRef ; HIViewRef viewRef = object->viewRef ;
if( viewRef && IsValidControlHandle( viewRef) ) if( viewRef && IsValidControlHandle( viewRef) )
{ {
CFIndex count = CFGetRetainCount( viewRef ) ; CFIndex count = CFGetRetainCount( viewRef ) ;
if ( count >= 1 ) if ( count >= 1 )
CFRelease( viewRef ) ; CFRelease( viewRef ) ;
} }
@@ -638,10 +639,10 @@ static pascal OSStatus ControlToolbarItemHandler( EventHandlerCallRef inCallRef,
break; break;
} }
break; break;
case kEventClassToolbarItem: case kEventClassToolbarItem:
switch ( GetEventKind( inEvent ) ) switch ( GetEventKind( inEvent ) )
{ {
case kEventToolbarItemCreateCustomView: case kEventToolbarItemCreateCustomView:
{ {
HIViewRef viewRef = object->viewRef ; HIViewRef viewRef = object->viewRef ;
@@ -650,13 +651,13 @@ static pascal OSStatus ControlToolbarItemHandler( EventHandlerCallRef inCallRef,
HIViewSetVisible(viewRef, true) ; HIViewSetVisible(viewRef, true) ;
InstallEventHandler( GetControlEventTarget( viewRef ), ControlToolbarItemHandler, InstallEventHandler( GetControlEventTarget( viewRef ), ControlToolbarItemHandler,
GetEventTypeCount( kViewEvents ), kViewEvents, object, NULL ); GetEventTypeCount( kViewEvents ), kViewEvents, object, NULL );
result = SetEventParameter( inEvent, kEventParamControlRef, typeControlRef, sizeof( HIViewRef ), &viewRef ); result = SetEventParameter( inEvent, kEventParamControlRef, typeControlRef, sizeof( HIViewRef ), &viewRef );
} }
break; break;
} }
break; break;
case kEventClassControl: case kEventClassControl:
switch ( GetEventKind( inEvent ) ) switch ( GetEventKind( inEvent ) )
{ {
@@ -675,14 +676,14 @@ static pascal OSStatus ControlToolbarItemHandler( EventHandlerCallRef inCallRef,
object->lastValidSize = sz ; object->lastValidSize = sz ;
else else
sz = object->lastValidSize ; sz = object->lastValidSize ;
HISize min, max; HISize min, max;
min.width = max.width = sz.x ; min.width = max.width = sz.x ;
min.height = max.height = sz.y ; min.height = max.height = sz.y ;
result = SetEventParameter( inEvent, kEventParamMinimumSize, typeHISize, result = SetEventParameter( inEvent, kEventParamMinimumSize, typeHISize,
sizeof( HISize ), &min ); sizeof( HISize ), &min );
result = SetEventParameter( inEvent, kEventParamMaximumSize, typeHISize, result = SetEventParameter( inEvent, kEventParamMaximumSize, typeHISize,
sizeof( HISize ), &max ); sizeof( HISize ), &max );
result = noErr ; result = noErr ;
@@ -692,19 +693,19 @@ static pascal OSStatus ControlToolbarItemHandler( EventHandlerCallRef inCallRef,
} }
break; break;
} }
return result; return result;
} }
void RegisterControlToolbarItemClass() void RegisterControlToolbarItemClass()
{ {
static bool sRegistered; static bool sRegistered;
if ( !sRegistered ) if ( !sRegistered )
{ {
HIObjectRegisterSubclass( kControlToolbarItemClassID, kHIToolbarItemClassID, 0, HIObjectRegisterSubclass( kControlToolbarItemClassID, kHIToolbarItemClassID, 0,
ControlToolbarItemHandler, GetEventTypeCount( kEvents ), kEvents, 0, NULL ); ControlToolbarItemHandler, GetEventTypeCount( kEvents ), kEvents, 0, NULL );
sRegistered = true; sRegistered = true;
} }
} }
@@ -712,26 +713,26 @@ void RegisterControlToolbarItemClass()
HIToolbarItemRef CreateControlToolbarItem(CFStringRef inIdentifier, CFTypeRef inConfigData) HIToolbarItemRef CreateControlToolbarItem(CFStringRef inIdentifier, CFTypeRef inConfigData)
{ {
RegisterControlToolbarItemClass(); RegisterControlToolbarItemClass();
OSStatus err; OSStatus err;
EventRef event; EventRef event;
UInt32 options = kHIToolbarItemAllowDuplicates; UInt32 options = kHIToolbarItemAllowDuplicates;
HIToolbarItemRef result = NULL; HIToolbarItemRef result = NULL;
err = CreateEvent( NULL, kEventClassHIObject, kEventHIObjectInitialize, GetCurrentEventTime(), 0, &event ); err = CreateEvent( NULL, kEventClassHIObject, kEventHIObjectInitialize, GetCurrentEventTime(), 0, &event );
require_noerr( err, CantCreateEvent ); require_noerr( err, CantCreateEvent );
SetEventParameter( event, kEventParamAttributes, typeUInt32, sizeof( UInt32 ), &options ); SetEventParameter( event, kEventParamAttributes, typeUInt32, sizeof( UInt32 ), &options );
SetEventParameter( event, kEventParamToolbarItemIdentifier, typeCFStringRef, sizeof( CFStringRef ), &inIdentifier ); SetEventParameter( event, kEventParamToolbarItemIdentifier, typeCFStringRef, sizeof( CFStringRef ), &inIdentifier );
if ( inConfigData ) if ( inConfigData )
SetEventParameter( event, kEventParamToolbarItemConfigData, typeCFTypeRef, sizeof( CFTypeRef ), &inConfigData ); SetEventParameter( event, kEventParamToolbarItemConfigData, typeCFTypeRef, sizeof( CFTypeRef ), &inConfigData );
err = HIObjectCreate( kControlToolbarItemClassID, event, (HIObjectRef*)&result ); err = HIObjectCreate( kControlToolbarItemClassID, event, (HIObjectRef*)&result );
check_noerr( err ); check_noerr( err );
ReleaseEvent( event ); ReleaseEvent( event );
CantCreateEvent : CantCreateEvent :
return result ; return result ;
} }
@@ -761,7 +762,7 @@ static OSStatus ToolbarDelegateHandler( EventHandlerCallRef inCallRef, EventRef
result = noErr; result = noErr;
} }
break; break;
case kEventToolbarGetAllowedIdentifiers: case kEventToolbarGetAllowedIdentifiers:
{ {
GetEventParameter( inEvent, kEventParamMutableArray, typeCFMutableArrayRef, NULL, GetEventParameter( inEvent, kEventParamMutableArray, typeCFMutableArrayRef, NULL,
@@ -776,13 +777,13 @@ static OSStatus ToolbarDelegateHandler( EventHandlerCallRef inCallRef, EventRef
HIToolbarItemRef item = NULL; HIToolbarItemRef item = NULL;
CFTypeRef data = NULL; CFTypeRef data = NULL;
CFStringRef identifier = NULL ; CFStringRef identifier = NULL ;
GetEventParameter( inEvent, kEventParamToolbarItemIdentifier, typeCFStringRef, NULL, GetEventParameter( inEvent, kEventParamToolbarItemIdentifier, typeCFStringRef, NULL,
sizeof( CFStringRef ), NULL, &identifier ); sizeof( CFStringRef ), NULL, &identifier );
GetEventParameter( inEvent, kEventParamToolbarItemConfigData, typeCFTypeRef, NULL, GetEventParameter( inEvent, kEventParamToolbarItemConfigData, typeCFTypeRef, NULL,
sizeof( CFTypeRef ), NULL, &data ); sizeof( CFTypeRef ), NULL, &data );
if ( CFStringCompare( kControlToolbarItemClassID, identifier, kCFCompareBackwards ) == kCFCompareEqualTo ) if ( CFStringCompare( kControlToolbarItemClassID, identifier, kCFCompareBackwards ) == kCFCompareEqualTo )
{ {
item = CreateControlToolbarItem( kControlToolbarItemClassID, data ); item = CreateControlToolbarItem( kControlToolbarItemClassID, data );
@@ -793,7 +794,7 @@ static OSStatus ToolbarDelegateHandler( EventHandlerCallRef inCallRef, EventRef
result = noErr; result = noErr;
} }
} }
} }
break; break;
} }
@@ -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);
} }
@@ -1332,7 +1333,7 @@ void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap )
// a side-effect of the UpdateToggleImage function is that it always changes the bitmap used on the button. // a side-effect of the UpdateToggleImage function is that it always changes the bitmap used on the button.
tool->UpdateToggleImage( tool->CanBeToggled() && tool->IsToggled() ); tool->UpdateToggleImage( tool->CanBeToggled() && tool->IsToggled() );
} }
} }
void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap ) void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap )
@@ -1343,9 +1344,9 @@ void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap )
wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools.")); wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools."));
tool->SetDisabledBitmap(bitmap); tool->SetDisabledBitmap(bitmap);
// TODO: what to do for this one? // TODO: what to do for this one?
} }
} }
wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const
@@ -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 );
@@ -1497,8 +1498,8 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase)
// reference count to make sure we are not dealing with zombie controls after the native toolbar has released its views // reference count to make sure we are not dealing with zombie controls after the native toolbar has released its views
CFRetain( viewRef ) ; CFRetain( viewRef ) ;
CFDataRef data = CFDataCreate( kCFAllocatorDefault , (UInt8*) &viewRef , sizeof(viewRef) ) ; CFDataRef data = CFDataCreate( kCFAllocatorDefault , (UInt8*) &viewRef , sizeof(viewRef) ) ;
err = HIToolbarCreateItemWithIdentifier((HIToolbarRef) m_macHIToolbarRef,kControlToolbarItemClassID, err = HIToolbarCreateItemWithIdentifier((HIToolbarRef) m_macHIToolbarRef,kControlToolbarItemClassID,
data , &item ) ; data , &item ) ;
if (err == noErr) if (err == noErr)
{ {
@@ -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 )

View File

@@ -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,18 +1074,36 @@ 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 diff = height - size.y; int height = r.bottom - r.top - staticTextSize.y;
if ( diff < 0 )
{
// the control is too high, resize to fit
control->SetSize(wxDefaultCoord, height - 2);
diff = 2; 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 )
{
// the control is too high, resize to fit
control->SetSize(wxDefaultCoord, height - 2);
diff = 2;
}
}
else // enough space for both the control and the label
{
if ( staticText )
staticText->Show();
} }
int top; int top;
@@ -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);
}
} }
} }
} }

View File

@@ -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);
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------