IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase)
- EVT_MOUSE_EVENTS( wxToolBar::OnMouse )
EVT_PAINT( wxToolBar::OnPaint )
END_EVENT_TABLE()
#endif
void SetSize(const wxSize& size) ;
void SetPosition( const wxPoint& position ) ;
+
wxSize GetSize() const
{
if ( IsControl() )
{
return wxPoint(m_x, m_y);
}
+ bool DoEnable( bool enable ) ;
private :
void Init()
{
wxToolBarTool* tbartool = (wxToolBarTool*)data ;
if ( tbartool->CanBeToggled() )
{
- tbartool->Toggle( GetControl32BitValue( (ControlRef) tbartool->GetControlHandle() ) ) ;
+ ((wxToolBar*)tbartool->GetToolBar())->ToggleTool(tbartool->GetId(), GetControl32BitValue((ControlRef)tbartool->GetControlHandle()));
}
((wxToolBar*)tbartool->GetToolBar())->OnLeftClick( tbartool->GetId() , tbartool -> IsToggled() ) ;
-
result = noErr;
}
break ;
// wxToolBarTool
// ----------------------------------------------------------------------------
+bool wxToolBarTool::DoEnable(bool enable)
+{
+ if ( IsControl() )
+ {
+ GetControl()->Enable( enable ) ;
+ }
+ else if ( IsButton() )
+ {
+#if TARGET_API_MAC_OSX
+ if ( enable )
+ EnableControl( m_controlHandle ) ;
+ else
+ DisableControl( m_controlHandle ) ;
+#else
+ if ( enable )
+ ActivateControl( m_controlHandle ) ;
+ else
+ DeactivateControl( m_controlHandle ) ;
+#endif
+ }
+ return true ;
+}
void wxToolBarTool::SetSize(const wxSize& size)
{
if ( IsControl() )
GetControlBounds( m_controlHandle , &contrlRect ) ;
int former_mac_x = contrlRect.left ;
int former_mac_y = contrlRect.top ;
- wxSize sz = GetToolBar()->GetToolSize() ;
+ GetToolBar()->GetToolSize() ;
if ( mac_x != former_mac_x || mac_y != former_mac_y )
{
SInt16 behaviour = kControlBehaviorOffsetContents ;
if ( CanBeToggled() )
behaviour += kControlBehaviorToggles ;
-
- if ( info.contentType != kControlNoContent )
- {
- m_controlHandle = ::NewControl( window , &toolrect , "\p" , true , 0 ,
- behaviour + info.contentType , 0 , kControlBevelButtonNormalBevelProc , (long) this ) ;
- ::SetControlData( m_controlHandle , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
- }
- else
- {
- m_controlHandle = ::NewControl( window , &toolrect , "\p" , true , 0 ,
- behaviour , 0 , kControlBevelButtonNormalBevelProc , (long) this ) ;
- }
+ CreateBevelButtonControl( window , &toolrect , CFSTR("") , kControlBevelButtonNormalBevel , behaviour , &info ,
+ 0 , 0 , 0 , &m_controlHandle ) ;
+
InstallControlEventHandler( (ControlRef) m_controlHandle, GetwxMacToolBarToolEventHandlerUPP(),
GetEventTypeCount(eventList), eventList, this,NULL);
+
UMAShowControl( m_controlHandle ) ;
- if ( !IsEnabled() )
- {
- UMADeactivateControl( m_controlHandle ) ;
- }
+
if ( CanBeToggled() && IsToggled() )
- {
::SetControl32BitValue( m_controlHandle , 1 ) ;
- }
else
- {
::SetControl32BitValue( m_controlHandle , 0 ) ;
- }
ControlRef container = (ControlRef) tbar->GetHandle() ;
wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
int maxToolHeight = 0;
// Find the maximum tool width and height
- wxToolBarToolsList::Node *node = m_tools.GetFirst();
+ wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
while ( node )
{
wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
node = node->GetNext();
}
+ bool lastWasRadio = FALSE;
node = m_tools.GetFirst();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
wxSize cursize = tool->GetSize() ;
+ bool isRadio = FALSE;
+
+ if ( tool->IsButton() && tool->GetKind() == wxITEM_RADIO )
+ {
+ if ( !lastWasRadio )
+ {
+ if (tool->Toggle(true))
+ {
+ DoToggleTool(tool, true);
+ }
+ }
+ isRadio = TRUE;
+ }
+ else
+ {
+ isRadio = FALSE;
+ }
+ lastWasRadio = isRadio;
+
// for the moment we just do a single row/column alignement
if ( x + cursize.x > maxWidth )
maxWidth = x + cursize.x ;
}
SetSize( maxWidth, maxHeight );
+ InvalidateBestSize();
return TRUE;
}
return wxSize(m_defaultWidth + 4, m_defaultHeight + 4);
}
-void wxToolBar::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) )
-{
- wxToolBarToolsList::Node *node;
- for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
- {
- wxToolBarTool* tool = (wxToolBarTool*) node->GetData() ;
- if ( tool->IsButton() )
- {
- if( tool->GetControlHandle() == control )
- {
- if ( tool->CanBeToggled() )
- {
- tool->Toggle( GetControl32BitValue( (ControlRef) control ) ) ;
- }
- OnLeftClick( tool->GetId() , tool -> IsToggled() ) ;
- break ;
- }
- }
- }
-}
-
void wxToolBar::SetRows(int nRows)
{
if ( nRows == m_maxRows )
wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const
{
- wxToolBarToolsList::Node *node = m_tools.GetFirst();
+ wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
while (node)
{
wxToolBarTool *tool = (wxToolBarTool *)node->GetData() ;
if (!IsShown())
return ;
- wxToolBarTool *tool = (wxToolBarTool *)t;
- if ( tool->IsControl() )
- {
- tool->GetControl()->Enable( enable ) ;
- }
- else if ( tool->IsButton() )
- {
- if ( enable )
- UMAActivateControl( (ControlRef) tool->GetControlHandle() ) ;
- else
- UMADeactivateControl( (ControlRef) tool->GetControlHandle() ) ;
- }
+ ((wxToolBarTool*)t)->DoEnable( enable ) ;
}
void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle)
{
// nothing special to do here - we relayout in Realize() later
tool->Attach(this);
+ InvalidateBestSize();
return TRUE;
}
bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool)
{
- wxToolBarToolsList::Node *node;
+ wxToolBarToolsList::compatibility_iterator node;
for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
{
wxToolBarToolBase *tool2 = node->GetData();
tool2->SetPosition( pt ) ;
}
+ InvalidateBestSize();
return TRUE ;
}
if ( toolbarrect.top < 0 )
toolbarrect.top = 0 ;
*/
- UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
-
- event.Skip() ;
-}
-
-void wxToolBar::OnMouse( wxMouseEvent &event )
-{
- if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK )
+ if ( !MacGetTopLevelWindow()->MacGetMetalAppearance() )
{
-
- int x = event.m_x ;
- int y = event.m_y ;
-
- MacClientToRootWindow( &x , &y ) ;
-
- ControlRef control ;
- Point localwhere ;
- SInt16 controlpart ;
- WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
-
- localwhere.h = x ;
- localwhere.v = y ;
-
- short modifiers = 0;
-
- if ( !event.m_leftDown && !event.m_rightDown )
- modifiers |= btnState ;
-
- if ( event.m_shiftDown )
- modifiers |= shiftKey ;
-
- if ( event.m_controlDown )
- modifiers |= controlKey ;
-
- if ( event.m_altDown )
- modifiers |= optionKey ;
-
- if ( event.m_metaDown )
- modifiers |= cmdKey ;
-
- controlpart = ::FindControl( localwhere , window , &control ) ;
+ UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
+ }
+ else
+ {
+#if TARGET_API_MAC_OSX
+#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
+ if ( UMAGetSystemVersion() >= 0x1030 )
+ {
+ HIRect hiToolbarrect = CGRectMake( dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) ,
+ dc.YLOG2DEVREL(h) , dc.XLOG2DEVREL(w) );
+ CGContextRef cgContext ;
+ Rect bounds ;
+ GetPortBounds( (CGrafPtr) dc.m_macPort , &bounds ) ;
+ QDBeginCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ;
+ CGContextTranslateCTM( cgContext , 0 , bounds.bottom - bounds.top ) ;
+ CGContextScaleCTM( cgContext , 1 , -1 ) ;
+
{
- if ( control && ::IsControlActive( control ) )
- {
- {
- controlpart = ::HandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ;
- wxTheApp->s_lastMouseDown = 0 ;
- if ( control && controlpart != kControlNoPart ) // otherwise we will get the event twice
- {
- MacHandleControlClick((WXWidget) control , controlpart , false /* not down anymore */ ) ;
- }
- }
- }
+ HIThemeBackgroundDrawInfo drawInfo ;
+ drawInfo.version = 0 ;
+ drawInfo.state = kThemeStateActive ;
+ drawInfo.kind = kThemeBackgroundMetal ;
+ HIThemeApplyBackground( &hiToolbarrect, &drawInfo , cgContext,kHIThemeOrientationNormal) ;
}
+ QDEndCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ;
}
+ else
+#endif
+ {
+ UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
+ }
+#endif
+ }
+ event.Skip() ;
}
#endif // wxUSE_TOOLBAR