/////////////////////////////////////////////////////////////////////////////
-// Name: src/mac/carbon/toolbar.cpp
+// Name: src/osx/carbon/toolbar.cpp
// Purpose: wxToolBar
// Author: Stefan Csomor
// Modified by:
#endif
#include "wx/app.h"
-#include "wx/mac/uma.h"
+#include "wx/osx/private.h"
#include "wx/geometry.h"
#include "wx/sysopt.h"
const short kwxMacToolBorder = 0;
const short kwxMacToolSpacing = 6;
-
-IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
-
BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase)
EVT_PAINT( wxToolBar::OnPaint )
END_EVENT_TABLE()
#pragma mark -
#pragma mark Tool Implementation
-
// ----------------------------------------------------------------------------
// private classes
// ----------------------------------------------------------------------------
m_controlHandle = NULL ;
}
-#if wxMAC_USE_NATIVE_TOOLBAR
+#if wxOSX_USE_NATIVE_TOOLBAR
if ( m_toolbarItemRef )
{
CFIndex count = CFGetRetainCount( m_toolbarItemRef ) ;
CFRelease(m_toolbarItemRef);
m_toolbarItemRef = NULL;
}
-#endif // wxMAC_USE_NATIVE_TOOLBAR
+#endif // wxOSX_USE_NATIVE_TOOLBAR
}
wxSize GetSize() const
return wxPoint( m_x, m_y );
}
- bool DoEnable( bool enable );
+ virtual bool Enable( bool enable );
void UpdateToggleImage( bool toggle );
-#if wxMAC_USE_NATIVE_TOOLBAR
- void SetToolbarItemRef( HIToolbarItemRef ref )
+ virtual bool Toggle(bool toggle)
{
- if ( m_controlHandle )
- HideControl( m_controlHandle );
- if ( m_toolbarItemRef )
- CFRelease( m_toolbarItemRef );
-
- m_toolbarItemRef = ref;
+ if ( wxToolBarToolBase::Toggle( toggle ) == false )
+ return false;
+
+ UpdateToggleImage(toggle);
+ return true;
+ }
+
+ void UpdateHelpStrings()
+ {
+#if wxOSX_USE_NATIVE_TOOLBAR
if ( m_toolbarItemRef )
{
- wxFont f;
- wxFontEncoding enc;
- if ( GetToolBar() )
- f = GetToolBar()->GetFont();
- if ( f.IsOk() )
- enc = f.GetEncoding();
- else
- enc = wxFont::GetDefaultEncoding();
+ wxFontEncoding enc = GetToolBarFontEncoding();
HIToolbarItemSetHelpText(
m_toolbarItemRef,
wxCFStringRef( GetShortHelp(), enc ),
wxCFStringRef( GetLongHelp(), enc ) );
}
+#endif
+ }
+
+ virtual bool SetShortHelp(const wxString& help)
+ {
+ if ( wxToolBarToolBase::SetShortHelp( help ) == false )
+ return false;
+
+ UpdateHelpStrings();
+ return true;
+ }
+
+ virtual bool SetLongHelp(const wxString& help)
+ {
+ if ( wxToolBarToolBase::SetLongHelp( help ) == false )
+ return false;
+
+ UpdateHelpStrings();
+ return true;
+ }
+
+ virtual void SetNormalBitmap(const wxBitmap& bmp)
+ {
+ wxToolBarToolBase::SetNormalBitmap(bmp);
+ UpdateToggleImage(CanBeToggled() && IsToggled());
+ }
+
+ virtual void SetLabel(const wxString& label)
+ {
+ wxToolBarToolBase::SetLabel(label);
+#if wxOSX_USE_NATIVE_TOOLBAR
+ if ( m_toolbarItemRef )
+ {
+ // strip mnemonics from the label for compatibility with the usual
+ // labels in wxStaticText sense
+ wxString labelStr = wxStripMenuCodes(label);
+
+ HIToolbarItemSetLabel(
+ m_toolbarItemRef,
+ wxCFStringRef(labelStr, GetToolBarFontEncoding()) );
+ }
+#endif
+ }
+
+#if wxOSX_USE_NATIVE_TOOLBAR
+ void SetToolbarItemRef( HIToolbarItemRef ref )
+ {
+ if ( m_controlHandle )
+ HideControl( m_controlHandle );
+ if ( m_toolbarItemRef )
+ CFRelease( m_toolbarItemRef );
+
+ m_toolbarItemRef = ref;
+ UpdateHelpStrings();
}
HIToolbarItemRef GetToolbarItemRef() const
{
return m_index;
}
-#endif
+#endif // wxOSX_USE_NATIVE_TOOLBAR
private:
+#if wxOSX_USE_NATIVE_TOOLBAR
+ wxFontEncoding GetToolBarFontEncoding() const
+ {
+ wxFont f;
+ if ( GetToolBar() )
+ f = GetToolBar()->GetFont();
+ return f.IsOk() ? f.GetEncoding() : wxFont::GetDefaultEncoding();
+ }
+#endif // wxOSX_USE_NATIVE_TOOLBAR
+
void Init()
{
m_controlHandle = NULL;
-#if wxMAC_USE_NATIVE_TOOLBAR
+#if wxOSX_USE_NATIVE_TOOLBAR
m_toolbarItemRef = NULL;
m_index = -1;
#endif
wxCoord m_x;
wxCoord m_y;
-#if wxMAC_USE_NATIVE_TOOLBAR
+#if wxOSX_USE_NATIVE_TOOLBAR
HIToolbarItemRef m_toolbarItemRef;
// position in its toolbar, -1 means not inserted
CFIndex m_index;
DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarToolEventHandler )
-#if wxMAC_USE_NATIVE_TOOLBAR
+#if wxOSX_USE_NATIVE_TOOLBAR
static const EventTypeSpec toolBarEventList[] =
{
#endif
-bool wxToolBarTool::DoEnable( bool enable )
+bool wxToolBarTool::Enable( bool enable )
{
+ if ( wxToolBarToolBase::Enable( enable ) == false )
+ return false;
+
if ( IsControl() )
{
GetControl()->Enable( enable );
}
else if ( IsButton() )
{
-#if wxMAC_USE_NATIVE_TOOLBAR
+#if wxOSX_USE_NATIVE_TOOLBAR
if ( m_toolbarItemRef != NULL )
HIToolbarItemSetEnabled( m_toolbarItemRef, enable );
#endif
else if ( IsControl() )
{
// embedded native controls are moved by the OS
-#if wxMAC_USE_NATIVE_TOOLBAR
+#if wxOSX_USE_NATIVE_TOOLBAR
if ( ((wxToolBar*)GetToolBar())->MacWantsNativeToolbar() == false )
#endif
{
ControlButtonContentInfo info;
wxMacCreateBitmapButton( &info, bmp );
SetControlData( m_controlHandle, 0, kControlIconContentTag, sizeof(info), (Ptr)&info );
-#if wxMAC_USE_NATIVE_TOOLBAR
+#if wxOSX_USE_NATIVE_TOOLBAR
if (m_toolbarItemRef != NULL)
{
ControlButtonContentInfo info2;
ControlButtonContentInfo info;
wxMacCreateBitmapButton( &info, m_bmpNormal );
SetControlData( m_controlHandle, 0, kControlIconContentTag, sizeof(info), (Ptr)&info );
-#if wxMAC_USE_NATIVE_TOOLBAR
+#if wxOSX_USE_NATIVE_TOOLBAR
if (m_toolbarItemRef != NULL)
{
ControlButtonContentInfo info2;
m_defaultWidth = kwxMacToolBarToolDefaultWidth;
m_defaultHeight = kwxMacToolBarToolDefaultHeight;
-#if wxMAC_USE_NATIVE_TOOLBAR
- m_macHIToolbarRef = NULL;
+#if wxOSX_USE_NATIVE_TOOLBAR
+ m_macToolbar = NULL;
m_macUsesNativeToolbar = false;
#endif
}
CFIndex count = CFGetRetainCount( viewRef ) ;
if ( count >= 1 )
{
- wxFAIL_MSG("Reference count of native tool was illegal before removal");
-
CFRelease( viewRef ) ;
}
}
{
case kEventControlGetSizeConstraints:
{
- wxWindow* wxwindow = wxFindControlFromMacControl(object->viewRef ) ;
+ wxWindow* wxwindow = wxFindWindowFromWXWidget( (WXWidget) object->viewRef ) ;
if ( wxwindow )
{
// during toolbar layout the native window sometimes gets negative sizes,
return result ;
}
-#if wxMAC_USE_NATIVE_TOOLBAR
+#if wxOSX_USE_NATIVE_TOOLBAR
static const EventTypeSpec kToolbarEvents[] =
{
{ kEventClassToolbar, kEventToolbarGetDefaultIdentifiers },
}
return result ;
}
-#endif // wxMAC_USE_NATIVE_TOOLBAR
+#endif // wxOSX_USE_NATIVE_TOOLBAR
// also for the toolbar we have the dual implementation:
// only when MacInstallNativeToolbar is called is the native toolbar set as the window toolbar
OSStatus err = noErr;
-#if wxMAC_USE_NATIVE_TOOLBAR
+#if wxOSX_USE_NATIVE_TOOLBAR
if (parent->IsKindOf(CLASSINFO(wxFrame)) && wxSystemOptions::GetOptionInt(wxT("mac.toolbar.no-native")) != 1)
{
wxString labelStr = wxString::Format( wxT("%p"), this );
err = HIToolbarCreate(
wxCFStringRef( labelStr, wxFont::GetDefaultEncoding() ), 0,
- (HIToolbarRef*) &m_macHIToolbarRef );
+ (HIToolbarRef*) &m_macToolbar );
- if (m_macHIToolbarRef != NULL)
+ if (m_macToolbar != NULL)
{
- InstallEventHandler( HIObjectGetEventTarget((HIToolbarRef)m_macHIToolbarRef ), ToolbarDelegateHandler,
+ InstallEventHandler( HIObjectGetEventTarget((HIToolbarRef)m_macToolbar ), ToolbarDelegateHandler,
GetEventTypeCount( kToolbarEvents ), kToolbarEvents, this, NULL );
HIToolbarDisplayMode mode = kHIToolbarDisplayModeDefault;
else
mode = kHIToolbarDisplayModeIconOnly;
- HIToolbarSetDisplayMode( (HIToolbarRef) m_macHIToolbarRef, mode );
- HIToolbarSetDisplaySize( (HIToolbarRef) m_macHIToolbarRef, displaySize );
+ HIToolbarSetDisplayMode( (HIToolbarRef) m_macToolbar, mode );
+ HIToolbarSetDisplaySize( (HIToolbarRef) m_macToolbar, displaySize );
}
}
-#endif // wxMAC_USE_NATIVE_TOOLBAR
+#endif // wxOSX_USE_NATIVE_TOOLBAR
return (err == noErr);
}
wxToolBar::~wxToolBar()
{
-#if wxMAC_USE_NATIVE_TOOLBAR
- if (m_macHIToolbarRef != NULL)
+#if wxOSX_USE_NATIVE_TOOLBAR
+ if (m_macToolbar != NULL)
{
// if this is the installed toolbar, then deinstall it
if (m_macUsesNativeToolbar)
MacInstallNativeToolbar( false );
- CFIndex count = CFGetRetainCount( m_macHIToolbarRef ) ;
+ CFIndex count = CFGetRetainCount( m_macToolbar ) ;
// Leopard seems to have one refcount more, so we cannot check reliably at the moment
if ( UMAGetSystemVersion() < 0x1050 )
{
wxFAIL_MSG("Reference count of native control was not 1 in wxToolBar destructor");
}
}
- CFRelease( (HIToolbarRef)m_macHIToolbarRef );
- m_macHIToolbarRef = NULL;
+ CFRelease( (HIToolbarRef)m_macToolbar );
+ m_macToolbar = NULL;
}
#endif
}
if (bResult)
{
-#if wxMAC_USE_NATIVE_TOOLBAR
+#if wxOSX_USE_NATIVE_TOOLBAR
bool ownToolbarInstalled = false;
MacTopLevelHasNativeToolbar( &ownToolbarInstalled );
if (ownToolbarInstalled)
{
bool bResult;
-#if wxMAC_USE_NATIVE_TOOLBAR
+#if wxOSX_USE_NATIVE_TOOLBAR
bool ownToolbarInstalled;
MacTopLevelHasNativeToolbar( &ownToolbarInstalled );
void wxToolBar::DoGetSize( int *width, int *height ) const
{
-#if wxMAC_USE_NATIVE_TOOLBAR
+#if wxOSX_USE_NATIVE_TOOLBAR
Rect boundsR;
bool ownToolbarInstalled;
if ( ownToolbarInstalled )
{
// TODO: is this really a control ?
- GetControlBounds( (ControlRef) m_macHIToolbarRef, &boundsR );
+ GetControlBounds( (ControlRef) m_macToolbar, &boundsR );
if ( width != NULL )
*width = boundsR.right - boundsR.left;
if ( height != NULL )
{
wxToolBarBase::SetWindowStyleFlag( style );
-#if wxMAC_USE_NATIVE_TOOLBAR
- if (m_macHIToolbarRef != NULL)
+#if wxOSX_USE_NATIVE_TOOLBAR
+ if (m_macToolbar != NULL)
{
HIToolbarDisplayMode mode = kHIToolbarDisplayModeDefault;
else
mode = kHIToolbarDisplayModeIconOnly;
- HIToolbarSetDisplayMode( (HIToolbarRef) m_macHIToolbarRef, mode );
+ HIToolbarSetDisplayMode( (HIToolbarRef) m_macToolbar, mode );
}
#endif
}
-#if wxMAC_USE_NATIVE_TOOLBAR
+#if wxOSX_USE_NATIVE_TOOLBAR
bool wxToolBar::MacWantsNativeToolbar()
{
return m_macUsesNativeToolbar;
OSStatus err = GetWindowToolbar( tlw, &curToolbarRef );
bResultV = ((err == noErr) && (curToolbarRef != NULL));
if (bResultV && (ownToolbarInstalled != NULL))
- *ownToolbarInstalled = (curToolbarRef == m_macHIToolbarRef);
+ *ownToolbarInstalled = (curToolbarRef == m_macToolbar);
}
return bResultV;
{
bool bResult = false;
- if (usesNative && (m_macHIToolbarRef == NULL))
+ if (usesNative && (m_macToolbar == NULL))
return bResult;
if (usesNative && ((GetWindowStyleFlag() & wxTB_VERTICAL) != 0))
{
bResult = true;
- SetWindowToolbar( tlw, (HIToolbarRef) m_macHIToolbarRef );
+ SetWindowToolbar( tlw, (HIToolbarRef) m_macToolbar );
ShowHideWindowToolbar( tlw, true, false );
ChangeWindowAttributes( tlw, kWindowToolbarButtonAttribute, 0 );
SetAutomaticControlDragTrackingEnabledForWindow( tlw, true );
- Rect r = { 0, 0, 0, 0 };
- m_peer->SetRect( &r );
+ m_peer->Move(0,0,0,0 );
SetSize( wxSIZE_AUTO_WIDTH, 0 );
- m_peer->SetVisibility( false, true );
+ m_peer->SetVisibility( false );
wxToolBarBase::Show( false );
}
}
else
{
// only deinstall toolbar if this is the installed one
- if (m_macHIToolbarRef == curToolbarRef)
+ if (m_macToolbar == curToolbarRef)
{
bResult = true;
ChangeWindowAttributes( tlw, 0, kWindowToolbarButtonAttribute );
SetWindowToolbar( tlw, NULL );
- m_peer->SetVisibility( true, true );
+ m_peer->SetVisibility( true );
}
}
bool lastIsRadio = false;
bool curIsRadio = false;
-#if wxMAC_USE_NATIVE_TOOLBAR
+#if wxOSX_USE_NATIVE_TOOLBAR
CFIndex currentPosition = 0;
bool insertAll = false;
- HIToolbarRef refTB = (HIToolbarRef)m_macHIToolbarRef;
+ HIToolbarRef refTB = (HIToolbarRef)m_macToolbar;
+ wxFont f;
+ wxFontEncoding enc;
+ f = GetFont();
+ if ( f.IsOk() )
+ enc = f.GetEncoding();
+ else
+ enc = wxFont::GetDefaultEncoding();
#endif
node = m_tools.GetFirst();
else
x += cursize.x + kwxMacToolSpacing;
-#if wxMAC_USE_NATIVE_TOOLBAR
+#if wxOSX_USE_NATIVE_TOOLBAR
// install in native HIToolbar
if ( refTB )
{
HIToolbarItemRef hiItemRef = tool->GetToolbarItemRef();
if ( hiItemRef != NULL )
{
+ // since setting the help texts is non-virtual we have to update
+ // the strings now
if ( insertAll || (tool->GetIndex() != currentPosition) )
{
OSStatus err = noErr;
m_defaultWidth = size.x + kwxMacToolBorder;
m_defaultHeight = size.y + kwxMacToolBorder;
-#if wxMAC_USE_NATIVE_TOOLBAR
- if (m_macHIToolbarRef != NULL)
+#if wxOSX_USE_NATIVE_TOOLBAR
+ if (m_macToolbar != NULL)
{
int maxs = wxMax( size.x, size.y );
HIToolbarDisplaySize sizeSpec;
else
sizeSpec = kHIToolbarDisplaySizeSmall;
- HIToolbarSetDisplaySize( (HIToolbarRef) m_macHIToolbarRef, sizeSpec );
+ HIToolbarSetDisplaySize( (HIToolbarRef) m_macToolbar, sizeSpec );
}
#endif
}
{
wxWindow::MacSuperChangedPosition();
-#if wxMAC_USE_NATIVE_TOOLBAR
+#if wxOSX_USE_NATIVE_TOOLBAR
if (! m_macUsesNativeToolbar )
Realize();
#else
return wxEmptyString;
}
-void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable)
+void wxToolBar::DoEnableTool(wxToolBarToolBase *WXUNUSED(t), bool WXUNUSED(enable))
{
- if ( t != NULL )
- ((wxToolBarTool*)t)->DoEnable( enable );
+ // everything already done in the tool's implementation
}
void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle)
{
- wxToolBarTool *tool = (wxToolBarTool *)t;
- if ( ( tool != NULL ) && tool->IsButton() )
- tool->UpdateToggleImage( toggle );
+ // everything already done in the tool's implementation
}
bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase)
ControlRef controlHandle = NULL;
OSStatus err = 0;
-#if wxMAC_USE_NATIVE_TOOLBAR
+#if wxOSX_USE_NATIVE_TOOLBAR
wxString label = tool->GetLabel();
- if (m_macHIToolbarRef && !label.empty() )
+ if (m_macToolbar && !label.empty() )
{
// strip mnemonics from the label for compatibility
// with the usual labels in wxStaticText sense
label = wxStripMenuCodes(label);
}
-#endif // wxMAC_USE_NATIVE_TOOLBAR
+#endif // wxOSX_USE_NATIVE_TOOLBAR
switch (tool->GetStyle())
{
toolrect.right = toolSize.x;
// in flat style we need a visual separator
-#if wxMAC_USE_NATIVE_TOOLBAR
- if (m_macHIToolbarRef != NULL)
+#if wxOSX_USE_NATIVE_TOOLBAR
+ if (m_macToolbar != NULL)
{
HIToolbarItemRef item;
err = HIToolbarItemCreate(
}
else
err = noErr;
-#endif // wxMAC_USE_NATIVE_TOOLBAR
+#endif // wxOSX_USE_NATIVE_TOOLBAR
CreateSeparatorControl( window, &toolrect, &controlHandle );
tool->SetControlHandle( controlHandle );
behaviour, &info, 0, 0, 0, &controlHandle );
}
-#if wxMAC_USE_NATIVE_TOOLBAR
- if (m_macHIToolbarRef != NULL)
+#if wxOSX_USE_NATIVE_TOOLBAR
+ if (m_macToolbar != NULL)
{
HIToolbarItemRef item;
wxString labelStr = wxString::Format(wxT("%p"), tool);
}
else
err = noErr;
-#endif // wxMAC_USE_NATIVE_TOOLBAR
+#endif // wxOSX_USE_NATIVE_TOOLBAR
wxMacReleaseBitmapButton( &info );
case wxTOOL_STYLE_CONTROL:
-#if wxMAC_USE_NATIVE_TOOLBAR
- if (m_macHIToolbarRef != NULL)
+#if wxOSX_USE_NATIVE_TOOLBAR
+ if (m_macToolbar != NULL)
{
wxCHECK_MSG( tool->GetControl(), false, _T("control must be non-NULL") );
HIToolbarItemRef item;
HIViewRef viewRef = (HIViewRef) tool->GetControl()->GetHandle() ;
CFDataRef data = CFDataCreate( kCFAllocatorDefault , (UInt8*) &viewRef , sizeof(viewRef) ) ;
- err = HIToolbarCreateItemWithIdentifier((HIToolbarRef) m_macHIToolbarRef,kControlToolbarItemClassID,
+ err = HIToolbarCreateItemWithIdentifier((HIToolbarRef) m_macToolbar,kControlToolbarItemClassID,
data , &item ) ;
if (err == noErr)
void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle))
{
- wxFAIL_MSG( wxT("not implemented") );
+ // nothing to do
}
bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolbase)
wxSize sz = ((wxToolBarTool*)tool)->GetSize();
-#if wxMAC_USE_NATIVE_TOOLBAR
+#if wxOSX_USE_NATIVE_TOOLBAR
CFIndex removeIndex = tool->GetIndex();
#endif
-#if wxMAC_USE_NATIVE_TOOLBAR
- if (m_macHIToolbarRef != NULL)
+#if wxOSX_USE_NATIVE_TOOLBAR
+ if (m_macToolbar != NULL)
{
- if ( removeIndex != -1 && m_macHIToolbarRef )
+ if ( removeIndex != -1 && m_macToolbar )
{
- HIToolbarRemoveItemAtIndex( (HIToolbarRef) m_macHIToolbarRef, removeIndex );
+ HIToolbarRemoveItemAtIndex( (HIToolbarRef) m_macToolbar, removeIndex );
tool->SetIndex( -1 );
}
}
tool2->SetPosition( pt );
-#if wxMAC_USE_NATIVE_TOOLBAR
- if (m_macHIToolbarRef != NULL)
+#if wxOSX_USE_NATIVE_TOOLBAR
+ if (m_macToolbar != NULL)
{
if ( removeIndex != -1 && tool2->GetIndex() > removeIndex )
tool2->SetIndex( tool2->GetIndex() - 1 );
void wxToolBar::OnPaint(wxPaintEvent& event)
{
-#if wxMAC_USE_NATIVE_TOOLBAR
+#if wxOSX_USE_NATIVE_TOOLBAR
if ( m_macUsesNativeToolbar )
{
event.Skip(true);
int w, h;
GetSize( &w, &h );
- bool drawMetalTheme = MacGetTopLevelWindow()->MacGetMetalAppearance();
+ bool drawMetalTheme = MacGetTopLevelWindow()->GetExtraStyle() & wxFRAME_EX_METAL;
if ( !drawMetalTheme )
{