1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "toolbar.h"
20 #include "wx/toolbar.h"
22 IMPLEMENT_DYNAMIC_CLASS(wxToolBar
, wxToolBarBase
)
24 BEGIN_EVENT_TABLE(wxToolBar
, wxToolBarBase
)
27 #include <wx/mac/uma.h>
29 wxToolBar::wxToolBar()
38 bool wxToolBar::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
39 long style
, const wxString
& name
)
41 m_maxWidth
= m_maxHeight
= 0;
63 MacPreControlCreate( parent
, id
, "" , wxPoint( x
, y
) , wxSize( width
, height
) ,style
, *((wxValidator
*)NULL
) , name
, &bounds
, title
) ;
65 m_macControl
= UMANewControl( parent
->GetMacRootWindow() , &bounds
, "\p" , true , 0 , 0 , 1,
66 kControlPlacardProc
, (long) this ) ;
67 MacPostControlCreate() ;
72 wxToolBar::~wxToolBar()
77 PicHandle
MakePict(GWorldPtr wp
)
82 PicHandle pict
; // this is the Picture we give back
84 RGBColor gray
= { 0xCCCC ,0xCCCC , 0xCCCC } ;
86 GetGWorld( &origPort
, &origDev
) ;
87 SetGWorld( wp
, NULL
) ;
89 pict
= OpenPicture(&wp
->portRect
); // open a picture, this disables drawing
93 RGBBackColor( &gray
) ;
94 EraseRect(&wp
->portRect
) ;
95 CopyBits((BitMap
*)*wp
->portPixMap
, // src PixMap - we copy image over itself -
96 (BitMap
*)*wp
->portPixMap
, // dst PixMap - no drawing occurs -
97 &wp
->portRect
, // srcRect - it will be recorded and compressed -
98 &wp
->portRect
, // dstRect - into the picture that is open -
99 srcCopy
,NULL
); // copyMode and no clip region
101 ClosePicture(); // We are done recording the picture
102 SetGWorld( origPort
, origDev
) ;
103 return pict
; // return our groovy pict handle
106 PicHandle
MakePictWhite(GWorldPtr wp
)
111 PicHandle pict
; // this is the Picture we give back
113 RGBColor white
= { 0xFFFF ,0xFFFF , 0xFFFF } ;
115 GetGWorld( &origPort
, &origDev
) ;
116 SetGWorld( wp
, NULL
) ;
118 pict
= OpenPicture(&wp
->portRect
); // open a picture, this disables drawing
122 RGBBackColor( &white
) ;
123 EraseRect(&wp
->portRect
) ;
124 CopyBits((BitMap
*)*wp
->portPixMap
, // src PixMap - we copy image over itself -
125 (BitMap
*)*wp
->portPixMap
, // dst PixMap - no drawing occurs -
126 &wp
->portRect
, // srcRect - it will be recorded and compressed -
127 &wp
->portRect
, // dstRect - into the picture that is open -
128 srcCopy
,NULL
); // copyMode and no clip region
130 ClosePicture(); // We are done recording the picture
131 SetGWorld( origPort
, origDev
) ;
132 return pict
; // return our groovy pict handle
135 const short kwxMacToolBarTopMargin
= 2 ;
136 const short kwxMacToolBarLeftMargin
= 2 ;
138 bool wxToolBar::CreateTools()
140 if (m_tools
.Number() == 0)
143 Rect toolbarrect
= { m_y
, m_x
, m_y
+ m_height
, m_x
+ m_width
} ;
144 ControlFontStyleRec controlstyle
;
145 WindowPtr window
= GetMacRootWindow() ;
146 controlstyle
.flags
= kControlUseFontMask
;
147 controlstyle
.font
= kControlFontSmallSystemFont
;
149 wxNode
*node
= m_tools
.First();
152 wxSize toolSize
= GetToolSize() ;
157 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
158 wxBitmapRefData
* bmap
= (wxBitmapRefData
*) ( tool
->m_bitmap1
.GetRefData()) ;
160 if( tool
->m_toolStyle
!= wxTOOL_STYLE_SEPARATOR
)
162 Rect toolrect
= { toolbarrect
.top
+ kwxMacToolBarTopMargin
, toolbarrect
.left
+ x
+ kwxMacToolBarLeftMargin
, 0 , 0 } ;
163 toolrect
.right
= toolrect
.left
+ toolSize
.x
;
164 toolrect
.bottom
= toolrect
.top
+ toolSize
.y
;
166 PicHandle icon
= NULL
;
169 if ( bmap
->m_bitmapType
== kMacBitmapTypePict
)
170 icon
= bmap
->m_hPict
;
171 else if ( bmap
->m_bitmapType
== kMacBitmapTypeGrafWorld
)
173 icon
= MakePict( bmap
->m_hBitmap
) ;
177 ControlHandle m_macToolHandle
;
181 m_macToolHandle
= UMANewControl( window
, &toolrect
, "\p" , true , 0 ,
182 kControlBehaviorOffsetContents
+ kControlContentPictHandle
, 0 , kControlBevelButtonNormalBevelProc
, (long) this ) ;
183 ControlButtonContentInfo info
;
185 info
.contentType
= kControlContentPictHandle
;
186 info
.u
.picture
= icon
;
188 UMASetControlData( m_macToolHandle
, kControlButtonPart
, kControlBevelButtonContentTag
, sizeof(info
) , (char*) &info
) ;
192 m_macToolHandle
= UMANewControl( window
, &toolrect
, "\p" , true , 0 ,
193 kControlBehaviorOffsetContents
, 0 , kControlBevelButtonNormalBevelProc
, (long) this ) ;
195 m_macToolHandles
.Add( m_macToolHandle
) ;
196 UMASetControlFontStyle( m_macToolHandle
, &controlstyle
) ;
197 UMAEmbedControl( m_macToolHandle
, m_macControl
) ;
199 x
+= (int)toolSize
.x
;
204 m_macToolHandles
.Add( NULL
) ;
205 x
+= (int)toolSize
.x
/ 4;
207 if ( toolbarrect
.left
+ x
+ kwxMacToolBarLeftMargin
> m_maxWidth
)
208 m_maxWidth
= toolbarrect
.left
+ x
+ kwxMacToolBarLeftMargin
;
209 if (toolbarrect
.top
+ kwxMacToolBarTopMargin
+ toolSize
.y
> m_maxHeight
)
210 m_maxHeight
= toolbarrect
.top
+ kwxMacToolBarTopMargin
;
215 if ( GetWindowStyleFlag() & wxTB_HORIZONTAL
)
217 m_maxWidth
= tw
; // +=toolSize.x;
218 m_maxHeight
+= toolSize
.y
;
219 m_maxHeight
+= m_yMargin
;
223 m_maxHeight
= th
;// += toolSize.y;
224 m_maxWidth
+= toolSize
.x
;
225 m_maxWidth
+= m_xMargin
;
228 SetSize(m_maxWidth
, m_maxHeight
);
233 void wxToolBar::SetToolBitmapSize(const wxSize
& size
)
235 m_defaultWidth
= size
.x
; m_defaultHeight
= size
.y
;
238 wxSize
wxToolBar::GetMaxSize() const
240 return wxSize(m_maxWidth
, m_maxHeight
);
243 // The button size is bigger than the bitmap size
244 wxSize
wxToolBar::GetToolSize() const
246 return wxSize(m_defaultWidth
+ 8, m_defaultHeight
+ 7);
249 void wxToolBar::MacHandleControlClick( ControlHandle control
, SInt16 controlpart
)
252 for ( index
= 0 ; index
< m_macToolHandles
.Count() ; ++index
)
254 if ( m_macToolHandles
[index
] == (void*) control
)
256 OnLeftClick( ( (wxToolBarTool
*) (m_tools
.Nth( index
)->Data() ) ) ->m_index
, ( (wxToolBarTool
*) (m_tools
.Nth( index
)->Data() ) ) ->m_toggleState
) ;
261 void wxToolBar::EnableTool(int toolIndex
, bool enable
)
263 wxNode
*node
= m_tools
.Find((long)toolIndex
);
266 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
267 tool
->m_enabled
= enable
;
268 // TODO enable button
272 void wxToolBar::ToggleTool(int toolIndex
, bool toggle
)
274 wxNode
*node
= m_tools
.Find((long)toolIndex
);
277 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
278 if (tool
->m_isToggle
)
280 tool
->m_toggleState
= toggle
;
281 // TODO: set toggle state
286 void wxToolBar::ClearTools()
289 wxToolBarBase::ClearTools();
292 // If pushedBitmap is NULL, a reversed version of bitmap is
293 // created and used as the pushed/toggled image.
294 // If toggle is TRUE, the button toggles between the two states.
296 wxToolBarTool
*wxToolBar::AddTool(int index
, const wxBitmap
& bitmap
, const wxBitmap
& pushedBitmap
,
297 bool toggle
, long xPos
, long yPos
, wxObject
*clientData
, const wxString
& helpString1
, const wxString
& helpString2
)
299 wxToolBarTool
*tool
= new wxToolBarTool(index
, bitmap
, wxNullBitmap
, toggle
, xPos
, yPos
, helpString1
, helpString2
);
300 tool
->m_clientData
= clientData
;
305 tool
->m_x
= m_xMargin
;
310 tool
->m_y
= m_yMargin
;
312 tool
->SetSize(GetToolSize().x
, GetToolSize().y
);
314 if ((tool
->m_x
+ bitmap
.GetWidth() + m_xMargin
) > m_maxWidth
)
315 m_maxWidth
= (tool
->m_x
+ tool
->GetWidth() + m_xMargin
);
317 if ((tool
->m_y
+ bitmap
.GetHeight() + m_yMargin
) > m_maxHeight
)
318 m_maxHeight
= (tool
->m_y
+ tool
->GetHeight() + m_yMargin
);
320 m_tools
.Append((long)index
, tool
);
324 #endif // wxUSE_TOOLBAR