toolbar support in all orientations

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66905 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2011-02-16 18:30:55 +00:00
parent ca9adee47f
commit baac715443
4 changed files with 307 additions and 168 deletions

View File

@@ -64,6 +64,7 @@ public:
// event handlers // event handlers
void OnActivate(wxActivateEvent& event); void OnActivate(wxActivateEvent& event);
void OnSysColourChanged(wxSysColourChangedEvent& event); void OnSysColourChanged(wxSysColourChangedEvent& event);
void OnSize(wxSizeEvent& event);
// Toolbar // Toolbar
#if wxUSE_TOOLBAR #if wxUSE_TOOLBAR
@@ -88,8 +89,6 @@ public:
void PositionBars(); void PositionBars();
// osx specific event handling common for all osx-ports
virtual void HandleResized( double timestampsec );
protected: protected:
// common part of all ctors // common part of all ctors

View File

@@ -29,6 +29,7 @@
BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
EVT_ACTIVATE(wxFrame::OnActivate) EVT_ACTIVATE(wxFrame::OnActivate)
EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
EVT_SIZE(wxFrame::OnSize)
END_EVENT_TABLE() END_EVENT_TABLE()
#define WX_MAC_STATUSBAR_HEIGHT 18 #define WX_MAC_STATUSBAR_HEIGHT 18
@@ -216,14 +217,12 @@ void wxFrame::OnActivate(wxActivateEvent& event)
} }
} }
void wxFrame::HandleResized( double timestampsec )
void wxFrame::OnSize(wxSizeEvent& event)
{ {
// according to the other ports we handle this within the OS level
// resize event, not within a wxSizeEvent
PositionBars(); PositionBars();
wxNonOwnedWindow::HandleResized( timestampsec ); event.Skip();
} }
#if wxUSE_MENUS #if wxUSE_MENUS
@@ -274,11 +273,16 @@ void wxFrame::DoGetClientSize(int *x, int *y) const
int w, h; int w, h;
toolbar->GetSize(&w, &h); toolbar->GetSize(&w, &h);
if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL ) if ( toolbar->IsVertical() )
{ {
if ( x ) if ( x )
*x -= w; *x -= w;
} }
else if ( toolbar->HasFlag( wxTB_BOTTOM ) )
{
if ( y )
*y -= h;
}
else else
{ {
#if !wxOSX_USE_NATIVE_TOOLBAR #if !wxOSX_USE_NATIVE_TOOLBAR
@@ -359,7 +363,7 @@ void wxFrame::PositionToolBar()
{ {
int cw, ch; int cw, ch;
GetSize( &cw , &ch ) ; wxTopLevelWindow::DoGetClientSize( &cw , &ch );
int statusX = 0 ; int statusX = 0 ;
int statusY = 0 ; int statusY = 0 ;
@@ -367,7 +371,7 @@ void wxFrame::PositionToolBar()
#if wxUSE_STATUSBAR #if wxUSE_STATUSBAR
if (GetStatusBar() && GetStatusBar()->IsShown()) if (GetStatusBar() && GetStatusBar()->IsShown())
{ {
GetStatusBar()->GetClientSize(&statusX, &statusY); GetStatusBar()->GetSize(&statusX, &statusY);
ch -= statusY; ch -= statusY;
} }
#endif #endif
@@ -384,20 +388,25 @@ void wxFrame::PositionToolBar()
tx = ty = 0 ; tx = ty = 0 ;
GetToolBar()->GetSize(&tw, &th); GetToolBar()->GetSize(&tw, &th);
if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) if (GetToolBar()->HasFlag(wxTB_LEFT))
{ {
// Use the 'real' position. wxSIZE_NO_ADJUSTMENTS // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
// means, pretend we don't have toolbar/status bar, so we // means, pretend we don't have toolbar/status bar, so we
// have the original client size. // have the original client size.
GetToolBar()->SetSize(tx , ty , tw, ch , wxSIZE_NO_ADJUSTMENTS ); GetToolBar()->SetSize(tx , ty , tw, ch , wxSIZE_NO_ADJUSTMENTS );
} }
else if (GetToolBar()->GetWindowStyleFlag() & wxTB_BOTTOM) else if (GetToolBar()->HasFlag(wxTB_RIGHT))
{
// Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
// means, pretend we don't have toolbar/status bar, so we
// have the original client size.
tx = cw - tw;
GetToolBar()->SetSize(tx , ty , tw, ch , wxSIZE_NO_ADJUSTMENTS );
}
else if (GetToolBar()->HasFlag(wxTB_BOTTOM))
{ {
//FIXME: this positions the tool bar almost correctly, but still it doesn't work right yet,
//as 1) the space for the 'old' top toolbar is still taken up, and 2) the toolbar
//doesn't extend it's width to the width of the frame.
tx = 0; tx = 0;
ty = ch - (th + statusY); ty = ch - th;
GetToolBar()->SetSize(tx, ty, cw, th, wxSIZE_NO_ADJUSTMENTS ); GetToolBar()->SetSize(tx, ty, cw, th, wxSIZE_NO_ADJUSTMENTS );
} }
else else

View File

@@ -1424,6 +1424,18 @@ bool wxToolBar::Realize()
return true; return true;
} }
void wxToolBar::DoLayout()
{
// TODO port back osx_cocoa layout solution
}
void wxToolBar::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{
wxToolBarBase::DoSetSize(x, y, width, height, sizeFlags);
DoLayout();
}
void wxToolBar::SetToolBitmapSize(const wxSize& size) void wxToolBar::SetToolBitmapSize(const wxSize& size)
{ {
m_defaultWidth = size.x + kwxMacToolBorder; m_defaultWidth = size.x + kwxMacToolBorder;

View File

@@ -43,6 +43,21 @@ END_EVENT_TABLE()
// private classes // private classes
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class wxToolBarTool;
@interface wxNSToolBarButton : NSButton
{
wxToolBarTool* impl;
}
- (id)initWithFrame:(NSRect)frame;
- (void) clickedAction: (id) sender;
- (void)setImplementation: (wxToolBarTool *) theImplementation;
- (wxToolBarTool*) implementation;
- (BOOL) isFlipped;
@end
// We have a dual implementation for each tool, WXWidget and NSToolbarItem* // We have a dual implementation for each tool, WXWidget and NSToolbarItem*
// when embedding native controls in the native toolbar we must make sure the // when embedding native controls in the native toolbar we must make sure the
@@ -130,13 +145,15 @@ public:
} }
else if ( IsButton() ) else if ( IsButton() )
{ {
curSize = GetToolBar()->GetToolSize(); // curSize = GetToolBar()->GetToolSize();
NSRect best = [(wxNSToolBarButton*)m_controlHandle frame];
curSize = wxSize(best.size.width, best.size.height);
} }
else else
{ {
// separator size // separator size
curSize = GetToolBar()->GetToolSize(); curSize = GetToolBar()->GetToolSize();
if ( GetToolBar()->GetWindowStyleFlag() & (wxTB_LEFT|wxTB_RIGHT) ) if ( GetToolBar()->IsVertical() )
curSize.y /= 4; curSize.y /= 4;
else else
curSize.x /= 4; curSize.x /= 4;
@@ -158,20 +175,23 @@ public:
void UpdateLabel() void UpdateLabel()
{ {
wxString labelStr = wxStripMenuCodes(m_label);
wxCFStringRef l(labelStr, GetToolBarFontEncoding());
wxCFStringRef sh( GetShortHelp(), GetToolBarFontEncoding() );
#if wxOSX_USE_NATIVE_TOOLBAR #if wxOSX_USE_NATIVE_TOOLBAR
if ( m_toolbarItem ) if ( m_toolbarItem )
{ {
// strip mnemonics from the label for compatibility with the usual // strip mnemonics from the label for compatibility with the usual
// labels in wxStaticText sense // labels in wxStaticText sense
wxString labelStr = wxStripMenuCodes(m_label);
wxCFStringRef l(labelStr, GetToolBarFontEncoding());
[m_toolbarItem setLabel:l.AsNSString()]; [m_toolbarItem setLabel:l.AsNSString()];
wxCFStringRef sh( GetShortHelp(), GetToolBarFontEncoding() );
[m_toolbarItem setToolTip:sh.AsNSString()]; [m_toolbarItem setToolTip:sh.AsNSString()];
} }
#endif #endif
if ( IsButton() )
[(NSButton*)m_controlHandle setTitle:l.AsNSString()];
} }
void Action() void Action()
@@ -298,19 +318,6 @@ private:
#endif #endif
@interface wxNSToolBarButton : NSButton
{
wxToolBarTool* impl;
}
- (id)initWithFrame:(NSRect)frame;
- (void) clickedAction: (id) sender;
- (void)setImplementation: (wxToolBarTool *) theImplementation;
- (wxToolBarTool*) implementation;
- (BOOL) isFlipped;
@end
#if wxOSX_USE_NATIVE_TOOLBAR #if wxOSX_USE_NATIVE_TOOLBAR
@implementation wxNSToolbarItem @implementation wxNSToolbarItem
@@ -540,7 +547,8 @@ void wxToolBarTool::UpdateToggleImage( bool toggle )
else else
#endif #endif
{ {
[(NSButton*)m_controlHandle setState:(toggle ? NSOnState : NSOffState)]; if ( IsButton() )
[(NSButton*)m_controlHandle setState:(toggle ? NSOnState : NSOffState)];
} }
} }
@@ -656,6 +664,13 @@ bool wxToolBar::Create(
wxToolBar::~wxToolBar() wxToolBar::~wxToolBar()
{ {
// removal only works while the toolbar is there
wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
if ( frame && frame->GetToolBar() == this )
{
frame->SetToolBar(NULL);
}
[(NSToolbar*)m_macToolbar setDelegate:nil]; [(NSToolbar*)m_macToolbar setDelegate:nil];
[(NSToolbar*)m_macToolbar release]; [(NSToolbar*)m_macToolbar release];
m_macToolbar = NULL; m_macToolbar = NULL;
@@ -745,11 +760,11 @@ void wxToolBar::DoGetSize( int *width, int *height ) const
wxSize wxToolBar::DoGetBestSize() const wxSize wxToolBar::DoGetBestSize() const
{ {
int width, height; // was updated in Realize()
wxSize size = GetMinSize();
DoGetSize( &width, &height ); return size;
return wxSize( width, height );
} }
void wxToolBar::SetWindowStyleFlag( long style ) void wxToolBar::SetWindowStyleFlag( long style )
@@ -805,7 +820,7 @@ bool wxToolBar::MacInstallNativeToolbar(bool usesNative)
if (usesNative && (m_macToolbar == NULL)) if (usesNative && (m_macToolbar == NULL))
return bResult; return bResult;
if (usesNative && ((GetWindowStyleFlag() & (wxTB_LEFT|wxTB_RIGHT|wxTB_BOTTOM)) != 0)) if (usesNative && HasFlag(wxTB_LEFT|wxTB_RIGHT|wxTB_BOTTOM) )
return bResult; return bResult;
WXWindow tlw = MacGetTopLevelWindowRef(); WXWindow tlw = MacGetTopLevelWindowRef();
@@ -862,24 +877,17 @@ void wxToolBar::MacUninstallNativeToolbar()
} }
#endif #endif
bool wxToolBar::Realize() void wxToolBar::DoLayout()
{ {
if ( !wxToolBarBase::Realize() )
return false;
int maxWidth = 0;
int maxHeight = 0;
int maxToolWidth = 0; int maxToolWidth = 0;
int maxToolHeight = 0; int maxToolHeight = 0;
int x = m_xMargin + kwxMacToolBarLeftMargin;
int y = m_yMargin + kwxMacToolBarTopMargin;
int tw, th; int tw, th;
GetSize( &tw, &th ); GetSize( &tw, &th );
// find the maximum tool width and height // find the maximum tool width and height
// and the number of stretchable items
unsigned numStretchableSpaces = 0;
wxToolBarTool *tool; wxToolBarTool *tool;
wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
while ( node ) while ( node )
@@ -888,18 +896,147 @@ bool wxToolBar::Realize()
if ( tool != NULL ) if ( tool != NULL )
{ {
wxSize sz = tool->GetSize(); wxSize sz = tool->GetSize();
if ( sz.x > maxToolWidth ) if ( sz.x > maxToolWidth )
maxToolWidth = sz.x; maxToolWidth = sz.x;
if ( sz.y > maxToolHeight ) if ( sz.y > maxToolHeight )
maxToolHeight = sz.y; maxToolHeight = sz.y;
if ( tool->IsStretchableSpace() )
numStretchableSpaces++;
} }
node = node->GetNext(); node = node->GetNext();
} }
bool lastIsRadio = false; // layout non-native toolbar
bool curIsRadio = false;
bool isHorizontal = !IsVertical();
int maxWidth = 0;
int maxHeight = 0;
int x = m_xMargin + kwxMacToolBarLeftMargin;
int y = m_yMargin + kwxMacToolBarTopMargin;
node = m_tools.GetFirst();
while ( node )
{
tool = (wxToolBarTool*) node->GetData();
if ( tool == NULL )
{
node = node->GetNext();
continue;
}
// set tool position:
// for the moment just perform a single row/column alignment
wxSize cursize = tool->GetSize();
if ( x + cursize.x > maxWidth )
maxWidth = x + cursize.x;
if ( y + cursize.y > maxHeight )
maxHeight = y + cursize.y;
// update the item positioning state
if ( !isHorizontal )
y += cursize.y + kwxMacToolSpacing;
else
x += cursize.x + kwxMacToolSpacing;
node = node->GetNext();
}
if ( isHorizontal )
{
// if not set yet, only one row
if ( m_maxRows <= 0 )
SetRows( 1 );
maxWidth += m_xMargin + kwxMacToolBarLeftMargin;
m_minWidth = maxWidth;
m_minHeight = m_maxHeight = maxToolHeight + 2 * (m_yMargin + kwxMacToolBarTopMargin);
}
else
{
// if not set yet, have one column
if ( (GetToolsCount() > 0) && (m_maxRows <= 0) )
SetRows( GetToolsCount() );
maxHeight += m_yMargin + kwxMacToolBarTopMargin;
m_minHeight = maxHeight;
m_minWidth = m_maxWidth = maxToolWidth + 2 * (m_yMargin + kwxMacToolBarTopMargin);
}
int totalStretchableSpace = 0;
int spacePerStretchable = 0;
if ( numStretchableSpaces > 0 )
{
if ( isHorizontal )
totalStretchableSpace = tw - maxWidth;
else
totalStretchableSpace = th - maxHeight;
if ( totalStretchableSpace > 0 )
spacePerStretchable = totalStretchableSpace / numStretchableSpaces;
}
// perform real positioning
x = m_xMargin + kwxMacToolBarLeftMargin;
y = m_yMargin + kwxMacToolBarTopMargin;
node = m_tools.GetFirst();
int currentStretchable = 0;
while ( node )
{
tool = (wxToolBarTool*) node->GetData();
if ( tool == NULL )
{
node = node->GetNext();
continue;
}
wxSize cursize = tool->GetSize();
if ( tool->IsStretchableSpace() )
{
++currentStretchable;
int thisSpace = currentStretchable == numStretchableSpaces ?
totalStretchableSpace - (currentStretchable-1)*spacePerStretchable :
spacePerStretchable;
if ( isHorizontal )
cursize.x += thisSpace;
else
cursize.y += thisSpace;
}
if ( !isHorizontal )
{
int x1 = x + ( maxToolWidth - cursize.x ) / 2;
tool->SetPosition( wxPoint(x1, y) );
}
else
{
int y1 = y + ( maxToolHeight - cursize.y ) / 2;
tool->SetPosition( wxPoint(x, y1) );
}
// update the item positioning state
if ( !isHorizontal )
y += cursize.y + kwxMacToolSpacing;
else
x += cursize.x + kwxMacToolSpacing;
node = node->GetNext();
}
}
bool wxToolBar::Realize()
{
if ( !wxToolBarBase::Realize() )
return false;
wxToolBarTool *tool;
wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
#if wxOSX_USE_NATIVE_TOOLBAR #if wxOSX_USE_NATIVE_TOOLBAR
CFIndex currentPosition = 0; CFIndex currentPosition = 0;
@@ -913,7 +1050,6 @@ bool wxToolBar::Realize()
enc = f.GetEncoding(); enc = f.GetEncoding();
else else
enc = wxFont::GetDefaultEncoding(); enc = wxFont::GetDefaultEncoding();
#endif
node = m_tools.GetFirst(); node = m_tools.GetFirst();
while ( node ) while ( node )
@@ -924,33 +1060,7 @@ bool wxToolBar::Realize()
node = node->GetNext(); node = node->GetNext();
continue; continue;
} }
// set tool position:
// for the moment just perform a single row/column alignment
wxSize cursize = tool->GetSize();
if ( x + cursize.x > maxWidth )
maxWidth = x + cursize.x;
if ( y + cursize.y > maxHeight )
maxHeight = y + cursize.y;
if ( GetWindowStyleFlag() & (wxTB_LEFT|wxTB_RIGHT) )
{
int x1 = x + ( maxToolWidth - cursize.x ) / 2;
tool->SetPosition( wxPoint(x1, y) );
}
else
{
int y1 = y + ( maxToolHeight - cursize.y ) / 2;
tool->SetPosition( wxPoint(x, y1) );
}
// update the item positioning state
if ( GetWindowStyleFlag() & (wxTB_LEFT|wxTB_RIGHT) )
y += cursize.y + kwxMacToolSpacing;
else
x += cursize.x + kwxMacToolSpacing;
#if wxOSX_USE_NATIVE_TOOLBAR
// install in native NSToolbar // install in native NSToolbar
if ( refTB ) if ( refTB )
{ {
@@ -961,22 +1071,22 @@ bool wxToolBar::Realize()
// the strings now // the strings now
wxCFStringRef sh( tool->GetShortHelp(), enc); wxCFStringRef sh( tool->GetShortHelp(), enc);
[hiItemRef setToolTip:sh.AsNSString()]; [hiItemRef setToolTip:sh.AsNSString()];
if ( insertAll || (tool->GetIndex() != currentPosition) ) if ( insertAll || (tool->GetIndex() != currentPosition) )
{ {
if ( !insertAll ) if ( !insertAll )
{ {
insertAll = true; insertAll = true;
// if this is the first tool that gets newly inserted or repositioned // 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 // first remove all 'old' tools from here to the right, because of this
// all following tools will have to be reinserted (insertAll). // all following tools will have to be reinserted (insertAll).
for ( wxToolBarToolsList::compatibility_iterator node2 = m_tools.GetLast(); for ( wxToolBarToolsList::compatibility_iterator node2 = m_tools.GetLast();
node2 != node; node2 != node;
node2 = node2->GetPrevious() ) node2 = node2->GetPrevious() )
{ {
wxToolBarTool *tool2 = (wxToolBarTool*) node2->GetData(); wxToolBarTool *tool2 = (wxToolBarTool*) node2->GetData();
const long idx = tool2->GetIndex(); const long idx = tool2->GetIndex();
if ( idx != -1 ) if ( idx != -1 )
{ {
@@ -985,29 +1095,49 @@ bool wxToolBar::Realize()
} }
} }
} }
wxCFStringRef cfidentifier; wxCFStringRef cfidentifier;
NSString *nsItemId; NSString *nsItemId;
if (tool->GetStyle() == wxTOOL_STYLE_SEPARATOR) if (tool->GetStyle() == wxTOOL_STYLE_SEPARATOR)
{ {
nsItemId = tool->IsStretchable() ? NSToolbarFlexibleSpaceItemIdentifier nsItemId = tool->IsStretchable() ? NSToolbarFlexibleSpaceItemIdentifier
: NSToolbarSeparatorItemIdentifier; : NSToolbarSeparatorItemIdentifier;
} }
else else
{ {
cfidentifier = wxCFStringRef(wxString::Format("%ld", (long)tool)); cfidentifier = wxCFStringRef(wxString::Format("%ld", (long)tool));
nsItemId = cfidentifier.AsNSString(); nsItemId = cfidentifier.AsNSString();
} }
[refTB insertItemWithItemIdentifier:nsItemId atIndex:currentPosition]; [refTB insertItemWithItemIdentifier:nsItemId atIndex:currentPosition];
tool->SetIndex( currentPosition ); tool->SetIndex( currentPosition );
} }
currentPosition++; currentPosition++;
} }
} }
node = node->GetNext();
}
#endif #endif
DoLayout();
// adjust radio items
bool lastIsRadio = false;
bool curIsRadio = false;
node = m_tools.GetFirst();
while ( node )
{
tool = (wxToolBarTool*) node->GetData();
if ( tool == NULL )
{
node = node->GetNext();
continue;
}
// update radio button (and group) state // update radio button (and group) state
lastIsRadio = curIsRadio; lastIsRadio = curIsRadio;
curIsRadio = ( tool->IsButton() && (tool->GetKind() == wxITEM_RADIO) ); curIsRadio = ( tool->IsButton() && (tool->GetKind() == wxITEM_RADIO) );
@@ -1049,54 +1179,21 @@ bool wxToolBar::Realize()
node = node->GetNext(); node = node->GetNext();
} }
if ( GetWindowStyleFlag() & (wxTB_TOP|wxTB_BOTTOM) )
{
// if not set yet, only one row
if ( m_maxRows <= 0 )
SetRows( 1 );
m_minWidth = maxWidth;
// maxHeight = th;
maxHeight += m_yMargin + kwxMacToolBarTopMargin;
m_minHeight = m_maxHeight = maxHeight;
}
else
{
// if not set yet, have one column
if ( (GetToolsCount() > 0) && (m_maxRows <= 0) )
SetRows( GetToolsCount() );
m_minHeight = maxHeight;
// maxWidth = tw;
maxWidth += m_xMargin + kwxMacToolBarLeftMargin;
m_minWidth = m_maxWidth = maxWidth;
}
#if 0
// FIXME: should this be OSX-only?
{
bool wantNativeToolbar, ownToolbarInstalled;
// attempt to install the native toolbar
wantNativeToolbar = ((GetWindowStyleFlag() & (wxTB_LEFT|wxTB_BOTTOM|wxTB_RIGHT)) == 0);
MacInstallNativeToolbar( wantNativeToolbar );
(void)MacTopLevelHasNativeToolbar( &ownToolbarInstalled );
if (!ownToolbarInstalled)
{
SetSize( maxWidth, maxHeight );
InvalidateBestSize();
}
}
#else
SetSize( maxWidth, maxHeight );
InvalidateBestSize(); InvalidateBestSize();
#endif SetInitialSize( wxSize(m_minWidth, m_minHeight));
SetInitialSize();
SendSizeEventToParent();
return true; return true;
} }
void wxToolBar::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{
wxToolBarBase::DoSetSize(x, y, width, height, sizeFlags);
DoLayout();
}
void wxToolBar::SetToolBitmapSize(const wxSize& size) void wxToolBar::SetToolBitmapSize(const wxSize& size)
{ {
m_defaultWidth = size.x + kwxMacToolBorder; m_defaultWidth = size.x + kwxMacToolBorder;
@@ -1136,6 +1233,7 @@ void wxToolBar::MacSuperChangedPosition()
{ {
wxWindow::MacSuperChangedPosition(); wxWindow::MacSuperChangedPosition();
/*
#if wxOSX_USE_NATIVE_TOOLBAR #if wxOSX_USE_NATIVE_TOOLBAR
if (! m_macUsesNativeToolbar ) if (! m_macUsesNativeToolbar )
Realize(); Realize();
@@ -1143,6 +1241,7 @@ void wxToolBar::MacSuperChangedPosition()
Realize(); Realize();
#endif #endif
*/
} }
void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap ) void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap )
@@ -1219,6 +1318,8 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase)
if (tool == NULL) if (tool == NULL)
return false; return false;
long style = GetWindowStyleFlag();
wxSize toolSize = GetToolSize(); wxSize toolSize = GetToolSize();
WXWidget controlHandle = NULL; WXWidget controlHandle = NULL;
NSRect toolrect = NSMakeRect(0, 0, toolSize.x, toolSize.y ); NSRect toolrect = NSMakeRect(0, 0, toolSize.x, toolSize.y );
@@ -1240,7 +1341,7 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase)
wxASSERT( tool->GetControlHandle() == NULL ); wxASSERT( tool->GetControlHandle() == NULL );
toolSize.x /= 4; toolSize.x /= 4;
toolSize.y /= 4; toolSize.y /= 4;
if ( GetWindowStyleFlag() & (wxTB_LEFT|wxTB_RIGHT) ) if ( IsVertical() )
toolrect.size.height = toolSize.y; toolrect.size.height = toolSize.y;
else else
toolrect.size.width = toolSize.x; toolrect.size.width = toolSize.x;
@@ -1273,6 +1374,14 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase)
[v setBordered:NO]; [v setBordered:NO];
[v setButtonType: ( tool->CanBeToggled() ? NSToggleButton : NSMomentaryPushInButton )]; [v setButtonType: ( tool->CanBeToggled() ? NSToggleButton : NSMomentaryPushInButton )];
[v setImplementation:tool]; [v setImplementation:tool];
if ( style & wxTB_NOICONS )
[v setImagePosition:NSNoImage];
else if ( style & wxTB_TEXT )
[v setImagePosition:NSImageAbove];
else
[v setImagePosition:NSImageOnly];
controlHandle = v; controlHandle = v;
@@ -1290,10 +1399,8 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase)
tool->SetControlHandle( controlHandle ); tool->SetControlHandle( controlHandle );
tool->UpdateImages(); tool->UpdateImages();
tool->UpdateLabel(); tool->UpdateLabel();
#if 0 [v sizeToFit];
SetBevelButtonTextPlacement( m_controlHandle, kControlBevelButtonPlaceBelowGraphic );
SetControlTitleWithCFString( m_controlHandle , wxCFStringRef( label, wxFont::GetDefaultEncoding() );
#endif
#if 0 #if 0
InstallControlEventHandler( InstallControlEventHandler(
(WXWidget) controlHandle, GetwxMacToolBarToolEventHandlerUPP(), (WXWidget) controlHandle, GetwxMacToolBarToolEventHandlerUPP(),
@@ -1389,7 +1496,7 @@ bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolbase)
wxToolBarTool *tool2 = (wxToolBarTool*) node->GetData(); wxToolBarTool *tool2 = (wxToolBarTool*) node->GetData();
wxPoint pt = tool2->GetPosition(); wxPoint pt = tool2->GetPosition();
if ( GetWindowStyleFlag() & (wxTB_LEFT|wxTB_RIGHT) ) if ( IsVertical() )
pt.y -= sz.y; pt.y -= sz.y;
else else
pt.x -= sz.x; pt.x -= sz.x;
@@ -1417,34 +1524,46 @@ void wxToolBar::OnPaint(wxPaintEvent& event)
#if wxOSX_USE_NATIVE_TOOLBAR #if wxOSX_USE_NATIVE_TOOLBAR
if ( m_macUsesNativeToolbar ) if ( m_macUsesNativeToolbar )
{ {
event.Skip(true); // nothing to do here
return;
}
#endif
wxPaintDC dc(this);
int w, h;
GetSize( &w, &h );
bool drawMetalTheme = MacGetTopLevelWindow()->GetExtraStyle() & wxFRAME_EX_METAL;
if ( !drawMetalTheme )
{
HIThemePlacardDrawInfo info;
memset( &info, 0, sizeof(info) );
info.version = 0;
info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive;
CGContextRef cgContext = (CGContextRef) MacGetCGContextRef();
HIRect rect = CGRectMake( 0, 0, w, h );
HIThemeDrawPlacard( &rect, &info, cgContext, kHIThemeOrientationNormal );
} }
else else
#endif
{ {
// leave the background as it is (striped or metal) int w, h;
} GetSize( &w, &h );
bool drawMetalTheme = MacGetTopLevelWindow()->GetExtraStyle() & wxFRAME_EX_METAL;
if ( UMAGetSystemVersion() < 0x1050 )
{
if ( !drawMetalTheme )
{
HIThemePlacardDrawInfo info;
memset( &info, 0, sizeof(info) );
info.version = 0;
info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive;
CGContextRef cgContext = (CGContextRef) MacGetCGContextRef();
HIRect rect = CGRectMake( 0, 0, w, h );
HIThemeDrawPlacard( &rect, &info, cgContext, kHIThemeOrientationNormal );
}
else
{
// leave the background as it is (striped or metal)
}
}
else
{
wxPaintDC dc(this);
wxRect rect(0,0,w,h);
dc.GradientFillLinear( rect , wxColour( 0xCC,0xCC,0xCC ), wxColour( 0xA8,0xA8,0xA8 ) , wxSOUTH );
dc.SetPen( wxPen( wxColour( 0x51,0x51,0x51 ) ) );
dc.DrawRectangle(rect);
}
}
event.Skip(); event.Skip();
} }