class wxToolBarTool : public wxToolBarToolBase
{
public:
- wxToolBarTool( wxToolBar *tbar,
- int id,
- const wxString& label,
- const wxBitmap& bmpNormal,
- const wxBitmap& bmpDisabled,
- wxItemKind kind,
- wxObject *clientData,
- const wxString& shortHelp,
- const wxString& longHelp );
+ wxToolBarTool(
+ wxToolBar *tbar,
+ int id,
+ const wxString& label,
+ const wxBitmap& bmpNormal,
+ const wxBitmap& bmpDisabled,
+ wxItemKind kind,
+ wxObject *clientData,
+ const wxString& shortHelp,
+ const wxString& longHelp );
wxToolBarTool(wxToolBar *tbar, wxControl *control)
: wxToolBarToolBase(tbar, control)
~wxToolBarTool()
{
ClearControl();
- if ( m_controlHandle )
- DisposeControl( m_controlHandle );
#if wxMAC_USE_NATIVE_TOOLBAR
if ( m_toolbarItemRef )
void ClearControl()
{
m_control = NULL;
+ if ( m_controlHandle )
+ {
+ DisposeControl( m_controlHandle );
+ m_controlHandle = NULL ;
+ }
#if wxMAC_USE_NATIVE_TOOLBAR
m_toolbarItemRef = NULL;
wxSize GetSize() const
{
+ wxSize curSize;
+
if ( IsControl() )
{
- return GetControl()->GetSize();
+ curSize = GetControl()->GetSize();
}
else if ( IsButton() )
{
- return GetToolBar()->GetToolSize();
+ curSize = GetToolBar()->GetToolSize();
}
else
{
// separator size
- wxSize sz = GetToolBar()->GetToolSize();
+ curSize = GetToolBar()->GetToolSize();
if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
- sz.y /= 4;
+ curSize.y /= 4;
else
- sz.x /= 4;
-
- return sz;
+ curSize.x /= 4;
}
+
+ return curSize;
}
wxPoint GetPosition() const
#ifdef __WXMAC_OSX__
shouldToggle = !tbartool->IsToggled();
#else
- shouldToggle = ( GetControl32BitValue((ControlRef) tbartool->GetControlHandle()) != 0 );
+ shouldToggle = (GetControl32BitValue( (ControlRef)(tbartool->GetControlHandle()) ) != 0);
#endif
tbar->ToggleTool( tbartool->GetId(), shouldToggle );
#if wxMAC_USE_NATIVE_TOOLBAR
-//
-// native toolbar
-//
-
static const EventTypeSpec toolBarEventList[] =
{
{ kEventClassToolbarItem, kEventToolbarItemPerformAction },
if ( tbartool->CanBeToggled() )
{
- if ( tbar )
+ if ( tbar != NULL )
tbar->ToggleTool(toolID, !tbartool->IsToggled() );
}
- if ( tbar )
+ if ( tbar != NULL )
tbar->OnLeftClick( toolID, tbartool->IsToggled() );
result = noErr;
}
#endif
-// ============================================================================
-// implementation
-// ============================================================================
-
-// ----------------------------------------------------------------------------
-// wxToolBarTool
-// ----------------------------------------------------------------------------
-
bool wxToolBarTool::DoEnable( bool enable )
{
if ( IsControl() )
else if ( IsButton() )
{
#if wxMAC_USE_NATIVE_TOOLBAR
- if ( m_toolbarItemRef )
+ if ( m_toolbarItemRef != NULL )
HIToolbarItemSetEnabled( m_toolbarItemRef, enable );
#endif
- if ( m_controlHandle )
+ if ( m_controlHandle != NULL )
{
#if TARGET_API_MAC_OSX
if ( enable )
#if wxMAC_USE_NATIVE_TOOLBAR
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4
-#define kHIToolbarItemSelected (1 << 7)
+#define kHIToolbarItemSelected (1 << 7)
#endif
// FIXME: this should be a OSX v10.4 runtime check
{
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 );
+ sizeof(transform), (Ptr)&transform );
HIViewSetNeedsDisplay( m_controlHandle, true );
#else
wxToolBarToolBase * wxToolBar::CreateTool( wxControl *control )
{
- return new wxToolBarTool(this, control);
+ return new wxToolBarTool( this, control );
}
void wxToolBar::Init()
wxToolBar::~wxToolBar()
{
#if wxMAC_USE_NATIVE_TOOLBAR
- if ( m_macHIToolbarRef )
+ if (m_macHIToolbarRef != NULL)
{
// if this is the installed toolbar, then deinstall it
if (m_macUsesNativeToolbar)
MacInstallNativeToolbar( false );
- CFRelease( (HIToolbarRef) m_macHIToolbarRef );
+ CFRelease( (HIToolbarRef)m_macHIToolbarRef );
m_macHIToolbarRef = NULL;
}
#endif
bool wxToolBar::Show( bool show )
{
- bool bResult;
WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef());
+ bool bResult = (tlw != NULL);
- bResult = (tlw != NULL);
if (bResult)
{
#if wxMAC_USE_NATIVE_TOOLBAR
MacTopLevelHasNativeToolbar( &ownToolbarInstalled );
if (ownToolbarInstalled)
{
- bResult = ( IsWindowToolbarVisible( tlw ) != show);
+ bResult = (IsWindowToolbarVisible( tlw ) != show);
if ( bResult )
ShowHideWindowToolbar( tlw, show, false );
}
else
-#endif
-
bResult = wxToolBarBase::Show( show );
+#else
+
+ bResult = wxToolBarBase::Show( show );
+#endif
}
return bResult;
#if wxMAC_USE_NATIVE_TOOLBAR
bool ownToolbarInstalled;
+
MacTopLevelHasNativeToolbar( &ownToolbarInstalled );
if (ownToolbarInstalled)
{
bResult = IsWindowToolbarVisible( tlw );
}
else
-#endif
bResult = wxToolBarBase::IsShown();
+#else
+
+ bResult = wxToolBarBase::IsShown();
+#endif
return bResult;
}
*height = boundsR.bottom - boundsR.top;
}
else
-#endif
wxToolBarBase::DoGetSize( width, height );
+
+#else
+ wxToolBarBase::DoGetSize( width, height );
+#endif
}
wxSize wxToolBar::DoGetBestSize() const
{
HIToolbarRef curToolbarRef = NULL;
OSStatus err = GetWindowToolbar( tlw, &curToolbarRef );
- bResultV = ((err == 0) && (curToolbarRef != NULL));
+ bResultV = ((err == noErr) && (curToolbarRef != NULL));
if (bResultV && (ownToolbarInstalled != NULL))
*ownToolbarInstalled = (curToolbarRef == m_macHIToolbarRef);
}
{
bool bResult = false;
- WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef());
- if (tlw == NULL)
- return bResult;
-
if (usesNative && (m_macHIToolbarRef == NULL))
return bResult;
if (usesNative && ((GetWindowStyleFlag() & wxTB_VERTICAL) != 0))
return bResult;
+ WindowRef tlw = MAC_WXHWND(MacGetTopLevelWindowRef());
+ if (tlw == NULL)
+ return bResult;
+
// check the existing toolbar
HIToolbarRef curToolbarRef = NULL;
OSStatus err = GetWindowToolbar( tlw, &curToolbarRef );
GetSize( &tw, &th );
// find the maximum tool width and height
- wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
+ wxToolBarTool *tool;
+ wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
while ( node != NULL )
{
- wxToolBarTool *tool = (wxToolBarTool *) node->GetData();
-
+ tool = (wxToolBarTool *) node->GetData();
if ( tool != NULL )
{
wxSize sz = tool->GetSize();
node = m_tools.GetFirst();
while ( node != NULL )
{
- wxToolBarTool *tool = (wxToolBarTool *) node->GetData();
-
+ tool = (wxToolBarTool*) node->GetData();
if ( tool == NULL )
{
node = node->GetNext();
if (err != noErr)
{
wxString errMsg = wxString::Format( wxT("HIToolbarRemoveItemAtIndex failed [%ld]"), (long)err );
- wxASSERT_MSG( 0, errMsg.c_str() );
+ wxFAIL_MSG( errMsg.c_str() );
}
}
if (err != noErr)
{
wxString errMsg = wxString::Format( wxT("HIToolbarInsertItemAtIndex failed [%ld]"), (long)err );
- wxASSERT_MSG( 0, errMsg.c_str() );
+ wxFAIL_MSG( errMsg.c_str() );
}
tool->SetIndex( currentPosition );
if (! m_macUsesNativeToolbar )
Realize();
#else
+
Realize();
#endif
}
wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const
{
+ wxToolBarTool *tool;
wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
while ( node != NULL )
{
- wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
-
+ tool = (wxToolBarTool *)node->GetData();
if (tool != NULL)
{
wxRect2DInt r( tool->GetPosition(), tool->GetSize() );
node = node->GetNext();
}
- return (wxToolBarToolBase *)NULL;
+ return (wxToolBarToolBase*)NULL;
}
wxString wxToolBar::MacGetToolTipString( wxPoint &pt )
kHIToolbarItemCantBeRemoved | kHIToolbarItemAnchoredLeft | kHIToolbarItemAllowDuplicates, &item );
if (err == noErr)
{
- InstallEventHandler( HIObjectGetEventTarget(item), GetwxMacToolBarEventHandlerUPP(),
- GetEventTypeCount(toolBarEventList), toolBarEventList, tool, NULL );
+ InstallEventHandler(
+ HIObjectGetEventTarget(item), GetwxMacToolBarEventHandlerUPP(),
+ GetEventTypeCount(toolBarEventList), toolBarEventList, tool, NULL );
HIToolbarItemSetLabel( item, wxMacCFStringHolder(tool->GetLabel(), m_font.GetEncoding()) );
HIToolbarItemSetIconRef( item, info.u.iconRef );
HIToolbarItemSetCommandID( item, kHIToolbarCommandPressAction );
#endif
wxMacReleaseBitmapButton( &info );
+
#if 0
SetBevelButtonTextPlacement( m_controlHandle, kControlBevelButtonPlaceBelowGraphic );
UMASetControlTitle( m_controlHandle, label, wxFont::GetDefaultEncoding() );
else
{
wxString errMsg = wxString::Format( wxT("wxToolBar::DoInsertTool - failure [%ld]"), (long)err );
- wxASSERT_MSG( false, errMsg.c_str() );
+ wxFAIL_MSG( errMsg.c_str() );
}
return (err == noErr);
case wxTOOL_STYLE_SEPARATOR:
if ( tool->GetControlHandle() )
{
- DisposeControl( (ControlRef) tool->GetControlHandle() );
-
#if wxMAC_USE_NATIVE_TOOLBAR
if ( removeIndex != -1 && m_macHIToolbarRef )
{