+ if (m_tools.Number() == 0)
+ return FALSE;
+
+ Rect toolbarrect = { m_y , m_x , m_y + m_height , m_x + m_width } ;
+ ControlFontStyleRec controlstyle ;
+ WindowPtr window = GetMacRootWindow() ;
+ controlstyle.flags = kControlUseFontMask ;
+ controlstyle.font = kControlFontSmallSystemFont ;
+
+ wxNode *node = m_tools.First();
+ int noButtons = 0;
+ int x = 0 ;
+ wxSize toolSize = GetToolSize() ;
+ int tw, th;
+ GetSize(& tw, & th);
+ while (node)
+ {
+ wxToolBarTool *tool = (wxToolBarTool *)node->Data();
+ wxBitmapRefData * bmap = (wxBitmapRefData*) ( tool->GetBitmap1().GetRefData()) ;
+
+ if( !tool->IsSeparator() )
+ {
+ Rect toolrect = { toolbarrect.top + kwxMacToolBarTopMargin , toolbarrect.left + x + kwxMacToolBarLeftMargin , 0 , 0 } ;
+ toolrect.right = toolrect.left + toolSize.x ;
+ toolrect.bottom = toolrect.top + toolSize.y ;
+
+ PicHandle icon = NULL ;
+ if ( bmap )
+ {
+ if ( bmap->m_bitmapType == kMacBitmapTypePict )
+ icon = bmap->m_hPict ;
+ else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
+ {
+ if ( tool->GetBitmap1().GetMask() )
+ {
+ icon = MakePict( bmap->m_hBitmap , tool->GetBitmap1().GetMask()->GetMaskBitmap() ) ;
+ }
+ else
+ {
+ icon = MakePict( bmap->m_hBitmap , NULL ) ;
+ }
+ }
+ }
+
+ ControlHandle m_macToolHandle ;
+
+ SInt16 behaviour = kControlBehaviorOffsetContents ;
+ if ( tool->CanBeToggled() )
+ behaviour += kControlBehaviorToggles ;
+
+ if ( icon )
+ {
+ m_macToolHandle = UMANewControl( window , &toolrect , "\p" , true , 0 ,
+ behaviour + kControlContentPictHandle , 0 , kControlBevelButtonNormalBevelProc , (long) this ) ;
+ ControlButtonContentInfo info ;
+
+ info.contentType = kControlContentPictHandle ;
+ info.u.picture = icon ;
+
+ UMASetControlData( m_macToolHandle , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
+ }
+ else
+ {
+ m_macToolHandle = UMANewControl( window , &toolrect , "\p" , true , 0 ,
+ behaviour , 0 , kControlBevelButtonNormalBevelProc , (long) this ) ;
+ }
+ m_macToolHandles.Add( m_macToolHandle ) ;
+ tool->m_index = m_macToolHandles.Count() -1 ;
+ if ( !tool->IsEnabled() )
+ {
+ UMADeactivateControl( m_macToolHandle ) ;
+ }
+ if ( tool->CanBeToggled() && tool->IsToggled() )
+ {
+ ::SetControlValue( m_macToolHandle , 1 ) ;
+ }
+ UMASetControlFontStyle( m_macToolHandle , &controlstyle ) ;
+ ControlHandle container = GetParent()->MacGetContainerForEmbedding() ;
+ wxASSERT_MSG( container != NULL , "No valid mac container control" ) ;
+ UMAEmbedControl( m_macToolHandle , container ) ;
+
+ x += (int)toolSize.x;
+ noButtons ++;
+ }
+ else
+ {
+ m_macToolHandles.Add( NULL ) ;
+ x += (int)toolSize.x / 4;
+ }
+ if ( toolbarrect.left + x + kwxMacToolBarLeftMargin > m_maxWidth)
+ m_maxWidth = toolbarrect.left + x + kwxMacToolBarLeftMargin;
+ if (toolbarrect.top + kwxMacToolBarTopMargin + toolSize.y > m_maxHeight)
+ m_maxHeight = toolbarrect.top + kwxMacToolBarTopMargin ;
+
+ node = node->Next();
+ }
+
+ if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )
+ {
+ m_maxWidth = tw ; // +=toolSize.x;
+ m_maxHeight += toolSize.y;
+ m_maxHeight += m_yMargin;
+ }
+ else
+ {
+ m_maxHeight = th ;// += toolSize.y;
+ m_maxWidth += toolSize.x;
+ m_maxWidth += m_xMargin;
+ }
+
+ SetSize(m_maxWidth, m_maxHeight);
+
+ return TRUE;