// Author: Stefan Csomor
// Modified by:
// Created: 04/01/98
-// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
{
// separator size
curSize = GetToolBar()->GetToolSize();
- if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
+ if ( GetToolBar()->GetWindowStyleFlag() & (wxTB_LEFT|wxTB_RIGHT) )
curSize.y /= 4;
else
curSize.x /= 4;
{
if ( wxToolBarToolBase::Toggle( toggle ) == false )
return false;
-
+
UpdateToggleImage(toggle);
return true;
}
-
+
void UpdateHelpStrings()
{
-#if wxOSX_USE_NATIVE_TOOLBAR
+#if wxOSX_USE_NATIVE_TOOLBAR
if ( m_toolbarItemRef )
{
wxFontEncoding enc = GetToolBarFontEncoding();
}
#endif
}
-
+
virtual bool SetShortHelp(const wxString& help)
{
if ( wxToolBarToolBase::SetShortHelp( help ) == false )
return false;
-
- UpdateHelpStrings();
+
+ UpdateHelpStrings();
return true;
}
-
+
virtual bool SetLongHelp(const wxString& help)
{
if ( wxToolBarToolBase::SetLongHelp( help ) == false )
return true;
}
- virtual void SetNormalBitmap(const wxBitmap& bmp)
+ virtual void SetNormalBitmap(const wxBitmap& bmp)
{
wxToolBarToolBase::SetNormalBitmap(bmp);
UpdateToggleImage(CanBeToggled() && IsToggled());
}
-
+
virtual void SetLabel(const wxString& label)
{
wxToolBarToolBase::SetLabel(label);
{
if ( wxToolBarToolBase::Enable( enable ) == false )
return false;
-
+
if ( IsControl() )
{
GetControl()->Enable( enable );
wxToolBar::~wxToolBar()
{
#if wxOSX_USE_NATIVE_TOOLBAR
- if (m_macToolbar != NULL)
+ // We could be not using a native tool bar at all, this happens when we're
+ // created with something other than the frame as parent for example.
+ if ( !m_macToolbar )
+ return;
+
+ // it might already have been uninstalled due to a previous call to Destroy, but in case
+ // wasn't, do so now, otherwise redraw events may occur for deleted objects
+ bool ownToolbarInstalled = false;
+ MacTopLevelHasNativeToolbar( &ownToolbarInstalled );
+ if (ownToolbarInstalled)
{
- // if this is the installed toolbar, then deinstall it
- if (m_macUsesNativeToolbar)
- MacInstallNativeToolbar( false );
+ MacUninstallNativeToolbar();
+ }
- CFIndex count = CFGetRetainCount( m_macToolbar ) ;
- // Leopard seems to have one refcount more, so we cannot check reliably at the moment
- if ( UMAGetSystemVersion() < 0x1050 )
+ CFIndex count = CFGetRetainCount( m_macToolbar ) ;
+ // Leopard seems to have one refcount more, so we cannot check reliably at the moment
+ if ( UMAGetSystemVersion() < 0x1050 )
+ {
+ if ( count != 1 )
{
- if ( count != 1 )
- {
- wxFAIL_MSG("Reference count of native control was not 1 in wxToolBar destructor");
- }
+ wxFAIL_MSG("Reference count of native control was not 1 in wxToolBar destructor");
}
- CFRelease( (HIToolbarRef)m_macToolbar );
- m_macToolbar = NULL;
}
-#endif
+ CFRelease( (HIToolbarRef)m_macToolbar );
+ m_macToolbar = NULL;
+#endif // wxOSX_USE_NATIVE_TOOLBAR
}
bool wxToolBar::Show( bool show )
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;
WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef());
bResult = true;
SetWindowToolbar( tlw, (HIToolbarRef) m_macToolbar );
+
+ // ShowHideWindowToolbar will make the wxFrame grow
+ // which we don't want in this case
+ wxSize sz = GetParent()->GetSize();
ShowHideWindowToolbar( tlw, true, false );
+ // Restore the original size
+ GetParent()->SetSize( sz );
+
ChangeWindowAttributes( tlw, kWindowToolbarButtonAttribute, 0 );
+
SetAutomaticControlDragTrackingEnabledForWindow( tlw, true );
- m_peer->Move(0,0,0,0 );
+ GetPeer()->Move(0,0,0,0 );
SetSize( wxSIZE_AUTO_WIDTH, 0 );
- m_peer->SetVisibility( false );
+ GetPeer()->SetVisibility( false );
wxToolBarBase::Show( false );
}
}
ShowHideWindowToolbar( tlw, false, false );
ChangeWindowAttributes( tlw, 0, kWindowToolbarButtonAttribute );
- SetWindowToolbar( tlw, NULL );
+ MacUninstallNativeToolbar();
- m_peer->SetVisibility( true );
+ GetPeer()->SetVisibility( true );
}
}
// wxLogDebug( wxT(" --> [%lx] - result [%s]"), (long)this, bResult ? wxT("T") : wxT("F") );
return bResult;
}
+
+void wxToolBar::MacUninstallNativeToolbar()
+{
+ if (!m_macToolbar)
+ return;
+
+ WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef());
+ if (tlw)
+ SetWindowToolbar( tlw, NULL );
+}
#endif
bool wxToolBar::Realize()
{
- if (m_tools.GetCount() == 0)
+ if ( !wxToolBarBase::Realize() )
return false;
+ wxSize tlw_sz = GetParent()->GetSize();
+
int maxWidth = 0;
int maxHeight = 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;
wxFAIL_MSG("Reference count of native tool was illegal before removal");
}
wxASSERT( IsValidControlHandle(tool->GetControl()->GetPeer()->GetControlRef() )) ;
+
+ wxString label = tool->GetLabel();
+ if ( !label.empty() )
+ HIToolbarItemSetLabel( hiItemRef, wxCFStringRef(label, GetFont().GetEncoding()) );
}
}
node = node->GetNext();
}
- if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
+ if (m_macUsesNativeToolbar)
+ GetParent()->SetSize( tlw_sz );
+
+ 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 += m_yMargin + kwxMacToolBarTopMargin;
m_minHeight = m_maxHeight = maxHeight;
}
SetRows( GetToolsCount() );
m_minHeight = maxHeight;
- maxHeight = th;
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)
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)
{
m_defaultWidth = size.x + kwxMacToolBorder;
node = node->GetNext();
}
- return (wxToolBarToolBase*)NULL;
+ return NULL;
}
wxString wxToolBar::MacGetToolTipString( wxPoint &pt )
// everything already done in the tool's implementation
}
-void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle)
+void wxToolBar::DoToggleTool(wxToolBarToolBase *WXUNUSED(t), bool WXUNUSED(toggle))
{
// everything already done in the tool's implementation
}
wxASSERT( tool->GetControlHandle() == NULL );
toolSize.x /= 4;
toolSize.y /= 4;
- if ( GetWindowStyleFlag() & wxTB_VERTICAL )
+ if ( GetWindowStyleFlag() & (wxTB_LEFT|wxTB_RIGHT) )
toolrect.bottom = toolSize.y;
else
toolrect.right = toolSize.x;
#if wxOSX_USE_NATIVE_TOOLBAR
if (m_macToolbar != NULL)
{
- wxCHECK_MSG( tool->GetControl(), false, _T("control must be non-NULL") );
+ wxCHECK_MSG( tool->GetControl(), false, wxT("control must be non-NULL") );
HIToolbarItemRef item;
HIViewRef viewRef = (HIViewRef) tool->GetControl()->GetHandle() ;
CFDataRef data = CFDataCreate( kCFAllocatorDefault , (UInt8*) &viewRef , sizeof(viewRef) ) ;
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;