// Licence: The wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-#pragma implementation "toolbar.h"
-#endif
-
#include "wx/wxprec.h"
#if wxUSE_TOOLBAR
~wxToolBarTool()
{
- ClearControl() ;
+ ClearControl() ;
if ( m_controlHandle )
DisposeControl( m_controlHandle ) ;
#if wxMAC_USE_NATIVE_TOOLBAR
void SetControlHandle( ControlRef handle )
{
- m_controlHandle = handle ;
+ m_controlHandle = handle ;
}
void SetPosition( const wxPoint& position ) ;
void ClearControl()
{
- m_control = NULL ;
+ m_control = NULL ;
#if wxMAC_USE_NATIVE_TOOLBAR
m_toolbarItemRef = NULL ;
#endif
{
return m_toolbarItemRef ;
}
+
+ void SetIndex( CFIndex idx )
+ {
+ m_index = idx ;
+ }
+
+ CFIndex GetIndex() const
+ {
+ return m_index ;
+ }
#endif
private :
m_controlHandle = NULL ;
#if wxMAC_USE_NATIVE_TOOLBAR
m_toolbarItemRef = NULL ;
+ m_index = -1 ;
#endif
}
ControlRef m_controlHandle ;
#if wxMAC_USE_NATIVE_TOOLBAR
HIToolbarItemRef m_toolbarItemRef ;
+ // position in its toolbar, -1 means not inserted
+ CFIndex m_index ;
#endif
wxCoord m_x;
wxCoord m_y;
static const EventTypeSpec eventList[] =
{
- { kEventClassControl , kEventControlHit } ,
+ { kEventClassControl , kEventControlHit } ,
#ifdef __WXMAC_OSX__
- { kEventClassControl , kEventControlHitTest } ,
+ { kEventClassControl , kEventControlHitTest } ,
#endif
} ;
static const EventTypeSpec toolBarEventList[] =
{
- { kEventClassToolbarItem , kEventToolbarItemPerformAction } ,
+ { kEventClassToolbarItem , kEventToolbarItemPerformAction } ,
} ;
static pascal OSStatus wxMacToolBarCommandEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
wxToolBar *tbar = ( wxToolBar * ) ( tbartool->GetToolBar() );
if ( tbartool->CanBeToggled() )
{
- tbar->ToggleTool(toolID, !tbartool->IsToggled() );
+ if ( tbar )
+ tbar->ToggleTool(toolID, !tbartool->IsToggled() );
}
- tbar->OnLeftClick( toolID , tbartool -> IsToggled() ) ;
+ if ( tbar )
+ tbar->OnLeftClick( toolID , tbartool -> IsToggled() ) ;
result = noErr;
}
}
dc.SelectObject( wxNullBitmap ) ;
ControlButtonContentInfo info ;
wxMacCreateBitmapButton( &info , bmp ) ;
- SetControlData( m_controlHandle , 0, kControlIconContentTag, sizeof( info ),
- (Ptr)&info );
+ SetControlData( m_controlHandle , 0, kControlIconContentTag,
+ sizeof( info ), (Ptr)&info );
wxMacReleaseBitmapButton( &info ) ;
}
else
{
ControlButtonContentInfo info ;
wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
- SetControlData( m_controlHandle , 0, kControlIconContentTag, sizeof( info ),
- (Ptr)&info );
+ SetControlData( m_controlHandle , 0, kControlIconContentTag,
+ sizeof( info ), (Ptr)&info );
wxMacReleaseBitmapButton( &info ) ;
}
IconTransformType transform = toggle ? kTransformSelected : kTransformNone ;
- SetControlData( m_controlHandle, 0, kControlIconTransformTag, sizeof( transform ),
- (Ptr)&transform );
+ SetControlData( m_controlHandle, 0, kControlIconTransformTag,
+ sizeof( transform ), (Ptr)&transform );
HIViewSetNeedsDisplay( m_controlHandle , true ) ;
#else
bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
long style, const wxString& name)
{
- if ( !wxToolBarBase::Create( parent , id , pos , size , style ) )
+ if ( !wxToolBarBase::Create( parent , id , pos , size , style, wxDefaultValidator, name ) )
return false ;
OSStatus err = 0;
#if wxMAC_USE_NATIVE_TOOLBAR
- wxString labelStr;
- labelStr.Format(wxT("%xd"), (int)this);
+ wxString labelStr = wxString::Format(wxT("%xd"), (int)this);
err = HIToolbarCreate( wxMacCFStringHolder(labelStr, wxFont::GetDefaultEncoding() ) , 0 ,
(HIToolbarRef*) &m_macHIToolbarRef );
MacTopLevelHasNativeToolbar( &ownToolbarInstalled );
if (ownToolbarInstalled)
{
- bResult = (HIViewIsVisible( (HIViewRef)m_macHIToolbarRef ) != show);
- ShowHideWindowToolbar( tlw, show, false );
+ bResult = ( IsWindowToolbarVisible(tlw) != show);
+ if ( bResult )
+ ShowHideWindowToolbar( tlw, show, false );
}
else
#endif
bool ownToolbarInstalled ;
MacTopLevelHasNativeToolbar( &ownToolbarInstalled );
if (ownToolbarInstalled)
- bResult = HIViewIsVisible( (HIViewRef)m_macHIToolbarRef );
+ {
+ WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef());
+ bResult = IsWindowToolbarVisible(tlw) ;
+ }
else
#endif
bResult = wxToolBarBase::IsShown();
wxToolBarBase::DoGetSize( width, height );
}
+wxSize wxToolBar::DoGetBestSize() const
+{
+ int width , height ;
+ DoGetSize( &width , &height ) ;
+ return wxSize( width , height ) ;
+}
+
void wxToolBar::SetWindowStyleFlag( long style )
{
wxToolBarBase::SetWindowStyleFlag( style );
bool wxToolBar::MacInstallNativeToolbar(bool usesNative)
{
- bool bResult = false;
+ bool bResult = false;
WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef());
if (tlw == NULL)
bool setChoiceInGroup = false;
node = m_tools.GetFirst();
+
+#if wxMAC_USE_NATIVE_TOOLBAR
+ CFIndex currentPosition = 0 ;
+ bool insertAll = false ;
+#endif // wxMAC_USE_NATIVE_TOOLBAR
+
while ( node != NULL )
{
wxToolBarTool *tool = (wxToolBarTool *) node->GetData();
HIToolbarItemRef hiItemRef = tool->GetToolbarItemRef();
if ( hiItemRef != NULL )
{
- OSStatus result = HIToolbarAppendItem( (HIToolbarRef) m_macHIToolbarRef, hiItemRef );
- if ( result == 0 )
+ if ( tool->GetIndex() != currentPosition || insertAll == true )
{
- InstallEventHandler( HIObjectGetEventTarget(hiItemRef), GetwxMacToolBarEventHandlerUPP(),
- GetEventTypeCount(toolBarEventList), toolBarEventList, tool, NULL );
+ OSStatus err = noErr ;
+ if ( !insertAll )
+ {
+ // if this is the first tool that gets newly inserted or repositioned
+ // first remove all 'old' tools from here to the right, because of this
+ // all following tools will have to be reinserted (insertAll). i = 100 because there's
+ // no way to determine how many there are in a toolbar, so just a high number :-(
+ for ( CFIndex i = 100 ; i >= currentPosition ; --i )
+ {
+ err = HIToolbarRemoveItemAtIndex( (HIToolbarRef) m_macHIToolbarRef , i ) ;
+ }
+ wxASSERT_MSG( err == noErr, _T("HIToolbarRemoveItemAtIndex failed") );
+ insertAll = true ;
+ }
+ err = HIToolbarInsertItemAtIndex( (HIToolbarRef) m_macHIToolbarRef, hiItemRef , currentPosition ) ;
+ wxASSERT_MSG( err == noErr, _T("HIToolbarInsertItemAtIndex failed") );
+ tool->SetIndex( currentPosition ) ;
}
+ currentPosition++ ;
}
}
-#endif
+#endif // wxMAC_USE_NATIVE_TOOLBAR
// update radio button (and group) state
lastIsRadio = curIsRadio;
SetSize( maxWidth, maxHeight );
InvalidateBestSize();
#endif
+
+ SetBestFittingSize();
+
return true;
}
#ifdef __WXMAC_OSX__
// in flat style we need a visual separator
- #if wxMAC_USE_NATIVE_TOOLBAR
+ #if wxMAC_USE_NATIVE_TOOLBAR
HIToolbarItemRef item;
err = HIToolbarItemCreate( kHIToolbarSeparatorIdentifier, kHIToolbarItemCantBeRemoved | kHIToolbarItemIsSeparator | kHIToolbarItemAllowDuplicates, &item );
if (err == noErr)
tool->SetToolbarItemRef( item );
- #endif
+ #endif // wxMAC_USE_NATIVE_TOOLBAR
CreateSeparatorControl( window, &toolrect, &controlHandle );
tool->SetControlHandle( controlHandle );
- #endif
+ #endif // __WXMAC_OSX__
}
break;
ControlButtonContentInfo info ;
wxMacCreateBitmapButton( &info , tool->GetNormalBitmap() , kControlContentIconRef ) ;
- if ( UMAGetSystemVersion() >= 0x1000)
- CreateIconControl( window , &toolrect , &info , false , &controlHandle ) ;
- else
- {
- SInt16 behaviour = kControlBehaviorOffsetContents ;
- if ( tool->CanBeToggled() )
- behaviour += kControlBehaviorToggles ;
- CreateBevelButtonControl( window , &toolrect , CFSTR("") , kControlBevelButtonNormalBevel , behaviour , &info ,
- 0 , 0 , 0 , &controlHandle ) ;
- }
+ if ( UMAGetSystemVersion() >= 0x1000)
+ CreateIconControl( window , &toolrect , &info , false , &controlHandle ) ;
+ else
+ {
+ SInt16 behaviour = kControlBehaviorOffsetContents ;
+ if ( tool->CanBeToggled() )
+ behaviour += kControlBehaviorToggles ;
+ CreateBevelButtonControl( window , &toolrect , CFSTR("") ,
+ kControlBevelButtonNormalBevel ,
+ behaviour , &info ,
+ 0 , 0 , 0 , &controlHandle ) ;
+ }
#if wxMAC_USE_NATIVE_TOOLBAR
HIToolbarItemRef item ;
- wxString labelStr;
- labelStr.Format(wxT("%xd"), (int)tool);
+ wxString labelStr = wxString::Format(wxT("%xd"), (int)tool);
err = HIToolbarItemCreate(
wxMacCFStringHolder(labelStr, wxFont::GetDefaultEncoding()),
kHIToolbarItemCantBeRemoved | kHIToolbarItemAnchoredLeft | kHIToolbarItemAllowDuplicates, &item );
if (err == noErr)
{
+ InstallEventHandler( HIObjectGetEventTarget(item), GetwxMacToolBarEventHandlerUPP(),
+ GetEventTypeCount(toolBarEventList), toolBarEventList, tool, NULL );
HIToolbarItemSetLabel( item, wxMacCFStringHolder(tool->GetLabel(), m_font.GetEncoding()) );
HIToolbarItemSetIconRef( item, info.u.iconRef );
- HIToolbarItemSetCommandID( item, tool->GetId() );
+ HIToolbarItemSetCommandID( item, kHIToolbarCommandPressAction );
tool->SetToolbarItemRef( item );
}
-#endif
+#endif // wxMAC_USE_NATIVE_TOOLBAR
wxMacReleaseBitmapButton( &info ) ;
/*
// FIXME: doesn't work yet...
{
HIToolbarItemRef item;
- wxString labelStr;
- labelStr.Format( wxT("%xd"), (int) tool );
+ wxString labelStr = wxString::Format( wxT("%xd"), (int) tool );
result = HIToolbarItemCreate( wxMacCFStringHolder(labelStr, wxFont::GetDefaultEncoding()),
kHIToolbarItemCantBeRemoved | kHIToolbarItemAnchoredLeft | kHIToolbarItemAllowDuplicates,
&item );
}
else
{
- wxString errMsg;
- errMsg.Format( wxT("wxToolBar::DoInsertTool - failure [%ld]"), (long) err );
+ wxString errMsg = wxString::Format( wxT("wxToolBar::DoInsertTool - failure [%ld]"), (long) err );
wxASSERT_MSG( false, errMsg.c_str() );
}
tool->Detach();
+#if wxMAC_USE_NATIVE_TOOLBAR
+ CFIndex removeIndex = tool->GetIndex();
+#endif // wxMAC_USE_NATIVE_TOOLBAR
+
switch ( tool->GetStyle() )
{
case wxTOOL_STYLE_CONTROL:
{
DisposeControl( (ControlRef) tool->GetControlHandle() ) ;
#if wxMAC_USE_NATIVE_TOOLBAR
- if ( tool->GetToolbarItemRef() )
- CFRelease( tool->GetToolbarItemRef() ) ;
-#endif
+ if ( removeIndex != -1 && m_macHIToolbarRef )
+ {
+ HIToolbarRemoveItemAtIndex( (HIToolbarRef) m_macHIToolbarRef , removeIndex ) ;
+ tool->SetIndex( -1 ) ;
+ }
+#endif // wxMAC_USE_NATIVE_TOOLBAR
tool->ClearControl() ;
}
break;
pt.x -= sz.x ;
tool2->SetPosition( pt ) ;
+
+#if wxMAC_USE_NATIVE_TOOLBAR
+ if ( removeIndex != -1 && tool2->GetIndex() > removeIndex )
+ tool2->SetIndex( tool2->GetIndex() - 1 ) ;
+#endif
+
}
InvalidateBestSize();