#pragma mark -
#pragma mark Tool Implementation
-#if wxOSX_USE_COCOA
-#define wxOSX_USE_NATIVE_TOOLBAR 1
-#endif
-
// ----------------------------------------------------------------------------
// private classes
// ----------------------------------------------------------------------------
{
// separator size
curSize = GetToolBar()->GetToolSize();
- if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
+ if ( GetToolBar()->GetWindowStyleFlag() & (wxTB_LEFT|wxTB_RIGHT) )
curSize.y /= 4;
else
curSize.x /= 4;
bool DoEnable( bool enable );
void UpdateImages();
-
+
void UpdateToggleImage( bool toggle );
-
+
void UpdateLabel()
{
+#if wxOSX_USE_NATIVE_TOOLBAR
if ( m_toolbarItem )
{
// strip mnemonics from the label for compatibility with the usual
wxCFStringRef l(labelStr, GetToolBarFontEncoding());
[m_toolbarItem setLabel:l.AsNSString()];
-
+
wxCFStringRef sh( GetShortHelp(), GetToolBarFontEncoding() );
[m_toolbarItem setToolTip:sh.AsNSString()];
}
+#endif
}
void Action()
tbar->OnLeftClick( GetId(), IsToggled() );
}
-
+
#if wxOSX_USE_NATIVE_TOOLBAR
void SetToolbarItemRef( NSToolbarItem* ref )
{
#endif
};
+#if wxOSX_USE_NATIVE_TOOLBAR
+
@interface wxNSToolbarItem : NSToolbarItem
{
wxToolBarTool* impl;
@end
-@interface wxNSToolbarDelegate : NSObject
+@interface wxNSToolbarDelegate : NSObject wxOSX_10_6_AND_LATER(<NSToolbarDelegate>)
{
}
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag;
-
+
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar;
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar;
@end
+#endif
+
@interface wxNSToolBarButton : NSButton
{
@end
+#if wxOSX_USE_NATIVE_TOOLBAR
+
@implementation wxNSToolbarItem
- (id)initWithItemIdentifier: (NSString*) identifier
- (void) clickedAction: (id) sender
{
+ wxUnusedVar(sender);
if ( impl )
{
impl->Action();
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar
{
+ wxUnusedVar(toolbar);
return nil;
}
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar
{
+ wxUnusedVar(toolbar);
return nil;
}
- (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
{
+ wxUnusedVar(toolbar);
return nil;
}
- (NSToolbarItem*) toolbar:(NSToolbar*) toolbar itemForItemIdentifier:(NSString*) itemIdentifier willBeInsertedIntoToolbar:(BOOL) flag
{
+ wxUnusedVar(toolbar);
+#ifdef __LP64__
+ wxToolBarTool* tool = (wxToolBarTool*) [itemIdentifier longLongValue];
+#else
wxToolBarTool* tool = (wxToolBarTool*) [itemIdentifier intValue];
+#endif
if ( tool )
{
wxNSToolbarItem* item = (wxNSToolbarItem*) tool->GetToolbarItemRef();
@end
+#endif
+
@implementation wxNSToolBarButton
- (id)initWithFrame:(NSRect)frame
- (void) clickedAction: (id) sender
{
+ wxUnusedVar(sender);
if ( impl )
{
impl->Action();
frame.origin.y = mac_y;
[m_controlHandle setFrame:frame];
}
- }
+ }
}
void wxToolBarTool::UpdateImages()
dc.DrawRectangle( 0, 0, w, h );
dc.DrawBitmap( m_bmpNormal, 0, 0, true );
dc.SelectObject( wxNullBitmap );
-
+
[(NSButton*) m_controlHandle setAlternateImage:m_alternateBitmap.GetNSImage()];
}
UpdateToggleImage( CanBeToggled() && IsToggled() );
if (parent->IsKindOf(CLASSINFO(wxFrame)) && wxSystemOptions::GetOptionInt(wxT("mac.toolbar.no-native")) != 1)
{
static wxNSToolbarDelegate* controller = nil;
-
+
if ( controller == nil )
controller = [[wxNSToolbarDelegate alloc] init];
wxString identifier = wxString::Format( wxT("%p"), this );
wxCFStringRef cfidentifier(identifier);
NSToolbar* tb = [[NSToolbar alloc] initWithIdentifier:cfidentifier.AsNSString()];
-
+
m_macToolbar = tb ;
-
+
if (m_macToolbar != NULL)
{
[tb setDelegate:controller];
-
+
NSToolbarDisplayMode mode = NSToolbarDisplayModeDefault;
NSToolbarSizeMode displaySize = NSToolbarSizeModeSmall;
}
wxToolBar::~wxToolBar()
-{
-#if wxOSX_USE_NATIVE_TOOLBAR
- if (m_macToolbar != NULL)
- {
- // if this is the installed toolbar, then deinstall it
- if (m_macUsesNativeToolbar)
- MacInstallNativeToolbar( false );
-
- [(NSToolbar*)m_macToolbar release];
- m_macToolbar = NULL;
- }
-#endif
+{
+ [(NSToolbar*)m_macToolbar setDelegate:nil];
+ [(NSToolbar*)m_macToolbar release];
+ m_macToolbar = NULL;
}
bool wxToolBar::Show( bool show )
{
WXWindow tlw = MacGetTopLevelWindowRef();
float toolbarHeight = 0.0;
- NSRect windowFrame;
-
+ NSRect windowFrame = NSMakeRect(0, 0, 0, 0);
+
if(m_macToolbar && [(NSToolbar*)m_macToolbar isVisible])
{
windowFrame = [NSWindow contentRectForFrameRect:[tlw frame]
toolbarHeight = NSHeight(windowFrame)
- NSHeight([[tlw contentView] frame]);
}
-
+
if ( width != NULL )
- *width = windowFrame.size.width;
+ *width = (int)windowFrame.size.width;
if ( height != NULL )
- *height = toolbarHeight;
+ *height = (int)toolbarHeight;
}
else
wxToolBarBase::DoGetSize( width, height );
if (usesNative && (m_macToolbar == NULL))
return bResult;
- if (usesNative && ((GetWindowStyleFlag() & wxTB_VERTICAL) != 0))
+ if (usesNative && ((GetWindowStyleFlag() & (wxTB_LEFT|wxTB_RIGHT|wxTB_BOTTOM)) != 0))
return bResult;
WXWindow tlw = MacGetTopLevelWindowRef();
bResult = true;
[tlw setToolbar:(NSToolbar*) m_macToolbar];
[(NSToolbar*) m_macToolbar setVisible:YES];
-
+
m_peer->Move(0,0,0,0 );
SetSize( wxSIZE_AUTO_WIDTH, 0 );
m_peer->SetVisibility( false );
{
bResult = true;
[(NSToolbar*) m_macToolbar setVisible:NO];
- [tlw setToolbar:nil];
+ MacUninstallNativeToolbar();
m_peer->SetVisibility( true );
}
}
// wxLogDebug( wxT(" --> [%lx] - result [%s]"), (long)this, bResult ? wxT("T") : wxT("F") );
return bResult;
}
+
+void wxToolBar::MacUninstallNativeToolbar()
+{
+ if (!m_macToolbar)
+ return;
+
+ WXWindow tlw = MacGetTopLevelWindowRef();
+ if (tlw)
+ [tlw setToolbar:nil];
+}
#endif
bool wxToolBar::Realize()
{
- if (m_tools.GetCount() == 0)
+ if ( !wxToolBarBase::Realize() )
return false;
int maxWidth = 0;
if ( y + cursize.y > maxHeight )
maxHeight = y + cursize.y;
- if ( GetWindowStyleFlag() & wxTB_VERTICAL )
+ if ( GetWindowStyleFlag() & (wxTB_LEFT|wxTB_RIGHT) )
{
int x1 = x + ( maxToolWidth - cursize.x ) / 2;
tool->SetPosition( wxPoint(x1, y) );
}
// update the item positioning state
- if ( GetWindowStyleFlag() & wxTB_VERTICAL )
+ if ( GetWindowStyleFlag() & (wxTB_LEFT|wxTB_RIGHT) )
y += cursize.y + kwxMacToolSpacing;
else
x += cursize.x + kwxMacToolSpacing;
}
}
}
- wxString identifier = wxString::Format( wxT("%d"), (int) tool );
- wxCFStringRef cfidentifier(identifier);
- [refTB insertItemWithItemIdentifier:cfidentifier.AsNSString() atIndex:currentPosition];
+ wxCFStringRef cfidentifier;
+ const NSString *nsItemId;
+ if (tool->GetStyle() == wxTOOL_STYLE_SEPARATOR)
+ {
+ nsItemId = tool->IsStretchable() ? NSToolbarFlexibleSpaceItemIdentifier
+ : NSToolbarSeparatorItemIdentifier;
+ }
+ else
+ {
+ cfidentifier = wxCFStringRef(wxString::Format("%ld", (long)tool));
+ nsItemId = cfidentifier.AsNSString();
+ }
+
+ [refTB insertItemWithItemIdentifier:nsItemId atIndex:currentPosition];
tool->SetIndex( currentPosition );
}
node = node->GetNext();
}
- if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
+ if ( GetWindowStyleFlag() & (wxTB_TOP|wxTB_BOTTOM) )
{
// if not set yet, only one row
if ( m_maxRows <= 0 )
SetRows( 1 );
m_minWidth = maxWidth;
- maxWidth = tw;
+ // maxHeight = th;
maxHeight += m_yMargin + kwxMacToolBarTopMargin;
m_minHeight = m_maxHeight = maxHeight;
}
SetRows( GetToolsCount() );
m_minHeight = maxHeight;
- maxHeight = th;
+ // maxWidth = tw;
maxWidth += m_xMargin + kwxMacToolBarLeftMargin;
m_minWidth = m_maxWidth = maxWidth;
}
bool wantNativeToolbar, ownToolbarInstalled;
// attempt to install the native toolbar
- wantNativeToolbar = ((GetWindowStyleFlag() & wxTB_VERTICAL) == 0);
+ wantNativeToolbar = ((GetWindowStyleFlag() & (wxTB_LEFT|wxTB_BOTTOM|wxTB_RIGHT)) == 0);
MacInstallNativeToolbar( wantNativeToolbar );
(void)MacTopLevelHasNativeToolbar( &ownToolbarInstalled );
if (!ownToolbarInstalled)
void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap )
{
- wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
+ wxToolBarTool* tool = static_cast<wxToolBarTool*>(FindById(id));
if ( tool )
{
wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools."));
void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap )
{
- wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
+ wxToolBarTool* tool = static_cast<wxToolBarTool*>(FindById(id));
if ( tool )
{
wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools."));
node = node->GetNext();
}
- return (wxToolBarToolBase*)NULL;
+ return NULL;
}
wxString wxToolBar::MacGetToolTipString( wxPoint &pt )
bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase)
{
- wxToolBarTool *tool = wx_static_cast( wxToolBarTool*, toolBase );
+ wxToolBarTool *tool = static_cast< wxToolBarTool*>(toolBase );
if (tool == NULL)
return false;
wxASSERT( tool->GetControlHandle() == NULL );
toolSize.x /= 4;
toolSize.y /= 4;
- if ( GetWindowStyleFlag() & wxTB_VERTICAL )
+ if ( GetWindowStyleFlag() & (wxTB_LEFT|wxTB_RIGHT) )
toolrect.size.height = toolSize.y;
else
toolrect.size.width = toolSize.x;
#if wxOSX_USE_NATIVE_TOOLBAR
if (m_macToolbar != NULL)
{
- NSToolbarItem* item = [[NSToolbarItem alloc] initWithItemIdentifier:NSToolbarSeparatorItemIdentifier];
+ const NSString * const
+ nsItemId = tool->IsStretchable() ? NSToolbarFlexibleSpaceItemIdentifier
+ : NSToolbarSeparatorItemIdentifier;
+ NSToolbarItem* item = [[NSToolbarItem alloc] initWithItemIdentifier:nsItemId];
tool->SetToolbarItemRef( item );
}
#endif // wxOSX_USE_NATIVE_TOOLBAR
[v setBordered:NO];
[v setButtonType: ( tool->CanBeToggled() ? NSOnOffButton : NSMomentaryPushInButton )];
[v setImplementation:tool];
-
+
controlHandle = v;
-
+
#if wxOSX_USE_NATIVE_TOOLBAR
if (m_macToolbar != NULL)
{
- wxString identifier = wxString::Format(wxT("%d"), (int) tool);
+ wxString identifier = wxString::Format(wxT("%ld"), (long) tool);
wxCFStringRef cfidentifier( identifier, wxFont::GetDefaultEncoding() );
wxNSToolbarItem* item = [[wxNSToolbarItem alloc] initWithItemIdentifier:cfidentifier.AsNSString() ];
[item setImplementation:tool];
if (m_macToolbar != NULL)
{
WXWidget view = (WXWidget) tool->GetControl()->GetHandle() ;
- wxCHECK_MSG( view, false, _T("control must be non-NULL") );
+ wxCHECK_MSG( view, false, wxT("control must be non-NULL") );
- wxString identifier = wxString::Format(wxT("%d"), (int) tool);
+ wxString identifier = wxString::Format(wxT("%ld"), (long) tool);
wxCFStringRef cfidentifier( identifier, wxFont::GetDefaultEncoding() );
wxNSToolbarItem* item = [[wxNSToolbarItem alloc] initWithItemIdentifier:cfidentifier.AsNSString() ];
[item setImplementation:tool];
bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolbase)
{
- wxToolBarTool* tool = wx_static_cast( wxToolBarTool*, toolbase );
+ wxToolBarTool* tool = static_cast< wxToolBarTool*>(toolbase );
wxToolBarToolsList::compatibility_iterator node;
for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
{
wxToolBarTool *tool2 = (wxToolBarTool*) node->GetData();
wxPoint pt = tool2->GetPosition();
- if ( GetWindowStyleFlag() & wxTB_VERTICAL )
+ if ( GetWindowStyleFlag() & (wxTB_LEFT|wxTB_RIGHT) )
pt.y -= sz.y;
else
pt.x -= sz.x;