1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "toolbar.h"
20 #include "wx/toolbar.h"
22 #if !USE_SHARED_LIBRARY
23 IMPLEMENT_DYNAMIC_CLASS(wxToolBar
, wxToolBarBase
)
25 BEGIN_EVENT_TABLE(wxToolBar
, wxToolBarBase
)
29 #include <wx/mac/uma.h>
31 wxToolBar::wxToolBar()
40 bool wxToolBar::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
41 long style
, const wxString
& name
)
43 m_maxWidth
= m_maxHeight
= 0;
65 MacPreControlCreate( parent
, id
, "" , wxPoint( x
, y
) , wxSize( width
, height
) ,style
, *((wxValidator
*)NULL
) , name
, &bounds
, title
) ;
67 m_macControl
= UMANewControl( parent
->GetMacRootWindow() , &bounds
, "\p" , true , 0 , 0 , 1,
68 kControlPlacardProc
, (long) this ) ;
69 MacPostControlCreate() ;
74 wxToolBar::~wxToolBar()
79 PicHandle
MakePict(GWorldPtr wp
)
84 PicHandle pict
; // this is the Picture we give back
86 RGBColor gray
= { 0xCCCC ,0xCCCC , 0xCCCC } ;
88 GetGWorld( &origPort
, &origDev
) ;
89 SetGWorld( wp
, NULL
) ;
91 pict
= OpenPicture(&wp
->portRect
); // open a picture, this disables drawing
95 RGBBackColor( &gray
) ;
96 EraseRect(&wp
->portRect
) ;
97 CopyBits((BitMap
*)*wp
->portPixMap
, // src PixMap - we copy image over itself -
98 (BitMap
*)*wp
->portPixMap
, // dst PixMap - no drawing occurs -
99 &wp
->portRect
, // srcRect - it will be recorded and compressed -
100 &wp
->portRect
, // dstRect - into the picture that is open -
101 srcCopy
,NULL
); // copyMode and no clip region
103 ClosePicture(); // We are done recording the picture
104 SetGWorld( origPort
, origDev
) ;
105 return pict
; // return our groovy pict handle
108 PicHandle
MakePictWhite(GWorldPtr wp
)
113 PicHandle pict
; // this is the Picture we give back
115 RGBColor white
= { 0xFFFF ,0xFFFF , 0xFFFF } ;
117 GetGWorld( &origPort
, &origDev
) ;
118 SetGWorld( wp
, NULL
) ;
120 pict
= OpenPicture(&wp
->portRect
); // open a picture, this disables drawing
124 RGBBackColor( &white
) ;
125 EraseRect(&wp
->portRect
) ;
126 CopyBits((BitMap
*)*wp
->portPixMap
, // src PixMap - we copy image over itself -
127 (BitMap
*)*wp
->portPixMap
, // dst PixMap - no drawing occurs -
128 &wp
->portRect
, // srcRect - it will be recorded and compressed -
129 &wp
->portRect
, // dstRect - into the picture that is open -
130 srcCopy
,NULL
); // copyMode and no clip region
132 ClosePicture(); // We are done recording the picture
133 SetGWorld( origPort
, origDev
) ;
134 return pict
; // return our groovy pict handle
137 const short kwxMacToolBarTopMargin
= 2 ;
138 const short kwxMacToolBarLeftMargin
= 2 ;
140 bool wxToolBar::CreateTools()
142 if (m_tools
.Number() == 0)
145 Rect toolbarrect
= { m_y
, m_x
, m_y
+ m_height
, m_x
+ m_width
} ;
146 ControlFontStyleRec controlstyle
;
147 WindowPtr window
= GetMacRootWindow() ;
148 controlstyle
.flags
= kControlUseFontMask
;
149 controlstyle
.font
= kControlFontSmallSystemFont
;
151 wxNode
*node
= m_tools
.First();
154 wxSize toolSize
= GetToolSize() ;
159 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
160 wxBitmapRefData
* bmap
= (wxBitmapRefData
*) ( tool
->m_bitmap1
.GetRefData()) ;
162 if( tool
->m_toolStyle
!= wxTOOL_STYLE_SEPARATOR
)
164 Rect toolrect
= { toolbarrect
.top
+ kwxMacToolBarTopMargin
, toolbarrect
.left
+ x
+ kwxMacToolBarLeftMargin
, 0 , 0 } ;
165 toolrect
.right
= toolrect
.left
+ toolSize
.x
;
166 toolrect
.bottom
= toolrect
.top
+ toolSize
.y
;
168 PicHandle icon
= NULL
;
171 if ( bmap
->m_bitmapType
== kMacBitmapTypePict
)
172 icon
= bmap
->m_hPict
;
173 else if ( bmap
->m_bitmapType
== kMacBitmapTypeGrafWorld
)
175 icon
= MakePict( bmap
->m_hBitmap
) ;
179 ControlHandle m_macToolHandle
;
183 m_macToolHandle
= UMANewControl( window
, &toolrect
, "\p" , true , 0 ,
184 kControlBehaviorOffsetContents
+ kControlContentPictHandle
, 0 , kControlBevelButtonNormalBevelProc
, (long) this ) ;
185 ControlButtonContentInfo info
;
187 info
.contentType
= kControlContentPictHandle
;
188 info
.u
.picture
= icon
;
190 UMASetControlData( m_macToolHandle
, kControlButtonPart
, kControlBevelButtonContentTag
, sizeof(info
) , (char*) &info
) ;
194 m_macToolHandle
= UMANewControl( window
, &toolrect
, "\p" , true , 0 ,
195 kControlBehaviorOffsetContents
, 0 , kControlBevelButtonNormalBevelProc
, (long) this ) ;
197 m_macToolHandles
.Add( m_macToolHandle
) ;
198 UMASetControlFontStyle( m_macToolHandle
, &controlstyle
) ;
199 UMAEmbedControl( m_macToolHandle
, m_macControl
) ;
201 x
+= (int)toolSize
.x
;
206 m_macToolHandles
.Add( NULL
) ;
207 x
+= (int)toolSize
.x
/ 4;
209 if ( toolbarrect
.left
+ x
+ kwxMacToolBarLeftMargin
> m_maxWidth
)
210 m_maxWidth
= toolbarrect
.left
+ x
+ kwxMacToolBarLeftMargin
;
211 if (toolbarrect
.top
+ kwxMacToolBarTopMargin
+ toolSize
.y
> m_maxHeight
)
212 m_maxHeight
= toolbarrect
.top
+ kwxMacToolBarTopMargin
;
217 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
219 m_maxWidth
= tw
; // +=toolSize.x;
220 m_maxHeight
+= toolSize
.y
;
221 m_maxHeight
+= m_yMargin
;
225 m_maxHeight
= th
;// += toolSize.y;
226 m_maxWidth
+= toolSize
.x
;
227 m_maxWidth
+= m_xMargin
;
230 SetSize(m_maxWidth
, m_maxHeight
);
235 void wxToolBar::SetToolBitmapSize(const wxSize
& size
)
237 m_defaultWidth
= size
.x
; m_defaultHeight
= size
.y
;
240 wxSize
wxToolBar::GetMaxSize() const
242 return wxSize(m_maxWidth
, m_maxHeight
);
245 // The button size is bigger than the bitmap size
246 wxSize
wxToolBar::GetToolSize() const
248 return wxSize(m_defaultWidth
+ 8, m_defaultHeight
+ 7);
251 void wxToolBar::MacHandleControlClick( ControlHandle control
, SInt16 controlpart
)
254 for ( index
= 0 ; index
< m_macToolHandles
.Count() ; ++index
)
256 if ( m_macToolHandles
[index
] == (void*) control
)
258 OnLeftClick( ( (wxToolBarTool
*) (m_tools
.Nth( index
)->Data() ) ) ->m_index
, ( (wxToolBarTool
*) (m_tools
.Nth( index
)->Data() ) ) ->m_toggleState
) ;
263 void wxToolBar::EnableTool(int toolIndex
, bool enable
)
265 wxNode
*node
= m_tools
.Find((long)toolIndex
);
268 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
269 tool
->m_enabled
= enable
;
270 // TODO enable button
274 void wxToolBar::ToggleTool(int toolIndex
, bool toggle
)
276 wxNode
*node
= m_tools
.Find((long)toolIndex
);
279 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
280 if (tool
->m_isToggle
)
282 tool
->m_toggleState
= toggle
;
283 // TODO: set toggle state
288 void wxToolBar::ClearTools()
291 wxToolBarBase::ClearTools();
294 // If pushedBitmap is NULL, a reversed version of bitmap is
295 // created and used as the pushed/toggled image.
296 // If toggle is TRUE, the button toggles between the two states.
298 wxToolBarTool
*wxToolBar::AddTool(int index
, const wxBitmap
& bitmap
, const wxBitmap
& pushedBitmap
,
299 bool toggle
, long xPos
, long yPos
, wxObject
*clientData
, const wxString
& helpString1
, const wxString
& helpString2
)
301 wxToolBarTool
*tool
= new wxToolBarTool(index
, bitmap
, wxNullBitmap
, toggle
, xPos
, yPos
, helpString1
, helpString2
);
302 tool
->m_clientData
= clientData
;
307 tool
->m_x
= m_xMargin
;
312 tool
->m_y
= m_yMargin
;
314 tool
->SetSize(GetToolSize().x
, GetToolSize().y
);
316 if ((tool
->m_x
+ bitmap
.GetWidth() + m_xMargin
) > m_maxWidth
)
317 m_maxWidth
= (tool
->m_x
+ tool
->GetWidth() + m_xMargin
);
319 if ((tool
->m_y
+ bitmap
.GetHeight() + m_yMargin
) > m_maxHeight
)
320 m_maxHeight
= (tool
->m_y
+ tool
->GetHeight() + m_yMargin
);
322 m_tools
.Append((long)index
, tool
);
326 #endif // wxUSE_TOOLBAR