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
)
66 MacPreControlCreate( parent
, id
, "" , wxPoint( x
, y
) , wxSize( width
, height
) ,style
, *((wxValidator
*)NULL
) , name
, &bounds
, title
) ;
68 m_macControl
= UMANewControl( parent
->GetMacRootWindow() , &bounds
, "\p" , true , 0 , 0 , 1,
69 kControlPlacardProc
, (long) this ) ;
70 MacPostControlCreate() ;
75 wxToolBar::~wxToolBar()
80 PicHandle
MakePict(GWorldPtr wp
)
85 PicHandle pict
; // this is the Picture we give back
87 RGBColor gray
= { 0xCCCC ,0xCCCC , 0xCCCC } ;
89 GetGWorld( &origPort
, &origDev
) ;
90 SetGWorld( wp
, NULL
) ;
92 pict
= OpenPicture(&wp
->portRect
); // open a picture, this disables drawing
96 RGBBackColor( &gray
) ;
97 EraseRect(&wp
->portRect
) ;
98 CopyBits((BitMap
*)*wp
->portPixMap
, // src PixMap - we copy image over itself -
99 (BitMap
*)*wp
->portPixMap
, // dst PixMap - no drawing occurs -
100 &wp
->portRect
, // srcRect - it will be recorded and compressed -
101 &wp
->portRect
, // dstRect - into the picture that is open -
102 srcCopy
,NULL
); // copyMode and no clip region
104 ClosePicture(); // We are done recording the picture
105 SetGWorld( origPort
, origDev
) ;
106 return pict
; // return our groovy pict handle
109 PicHandle
MakePictWhite(GWorldPtr wp
)
114 PicHandle pict
; // this is the Picture we give back
116 RGBColor white
= { 0xFFFF ,0xFFFF , 0xFFFF } ;
118 GetGWorld( &origPort
, &origDev
) ;
119 SetGWorld( wp
, NULL
) ;
121 pict
= OpenPicture(&wp
->portRect
); // open a picture, this disables drawing
125 RGBBackColor( &white
) ;
126 EraseRect(&wp
->portRect
) ;
127 CopyBits((BitMap
*)*wp
->portPixMap
, // src PixMap - we copy image over itself -
128 (BitMap
*)*wp
->portPixMap
, // dst PixMap - no drawing occurs -
129 &wp
->portRect
, // srcRect - it will be recorded and compressed -
130 &wp
->portRect
, // dstRect - into the picture that is open -
131 srcCopy
,NULL
); // copyMode and no clip region
133 ClosePicture(); // We are done recording the picture
134 SetGWorld( origPort
, origDev
) ;
135 return pict
; // return our groovy pict handle
138 const short kwxMacToolBarTopMargin
= 2 ;
139 const short kwxMacToolBarLeftMargin
= 2 ;
141 bool wxToolBar::CreateTools()
143 if (m_tools
.Number() == 0)
146 Rect toolbarrect
= { m_y
, m_x
, m_y
+ m_height
, m_x
+ m_width
} ;
147 ControlFontStyleRec controlstyle
;
148 WindowPtr window
= GetMacRootWindow() ;
149 controlstyle
.flags
= kControlUseFontMask
;
150 controlstyle
.font
= kControlFontSmallSystemFont
;
152 wxNode
*node
= m_tools
.First();
158 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
159 wxBitmapRefData
* bmap
= (wxBitmapRefData
*) ( tool
->m_bitmap1
.GetRefData()) ;
161 if( tool
->m_toolStyle
!= wxTOOL_STYLE_SEPARATOR
)
163 Rect toolrect
= { toolbarrect
.top
+ kwxMacToolBarTopMargin
, toolbarrect
.left
+ x
+ kwxMacToolBarLeftMargin
, 0 , 0 } ;
164 toolrect
.right
= toolrect
.left
+ m_defaultWidth
;
165 toolrect
.bottom
= toolrect
.top
+ m_defaultHeight
;
167 PicHandle icon
= NULL
;
170 if ( bmap
->m_bitmapType
== kMacBitmapTypePict
)
171 icon
= bmap
->m_hPict
;
172 else if ( bmap
->m_bitmapType
== kMacBitmapTypeGrafWorld
)
174 icon
= MakePict( bmap
->m_hBitmap
) ;
178 ControlHandle m_macToolHandle
;
182 m_macToolHandle
= UMANewControl( window
, &toolrect
, "\p" , true , 0 ,
183 kControlBehaviorOffsetContents
+ kControlContentPictHandle
, 0 , kControlBevelButtonNormalBevelProc
, (long) this ) ;
184 ControlButtonContentInfo info
;
186 info
.contentType
= kControlContentPictHandle
;
187 info
.u
.picture
= icon
;
189 UMASetControlData( m_macToolHandle
, kControlButtonPart
, kControlBevelButtonContentTag
, sizeof(info
) , (char*) &info
) ;
193 m_macToolHandle
= UMANewControl( window
, &toolrect
, "\p" , true , 0 ,
194 kControlBehaviorOffsetContents
, 0 , kControlBevelButtonNormalBevelProc
, (long) this ) ;
196 m_macToolHandles
.Add( m_macToolHandle
) ;
197 UMASetControlFontStyle( m_macToolHandle
, &controlstyle
) ;
198 UMAEmbedControl( m_macToolHandle
, m_macControl
) ;
200 x
+= (int)m_defaultWidth
;
205 m_macToolHandles
.Add( NULL
) ;
206 x
+= (int)m_defaultWidth
/ 4;
214 void wxToolBar::SetToolBitmapSize(const wxSize
& size
)
216 m_defaultWidth
= size
.x
; m_defaultHeight
= size
.y
;
219 wxSize
wxToolBar::GetMaxSize() const
225 // The button size is bigger than the bitmap size
226 wxSize
wxToolBar::GetToolSize() const
228 return wxSize(m_defaultWidth
+ 8, m_defaultHeight
+ 7);
231 void wxToolBar::MacHandleControlClick( ControlHandle control
, SInt16 controlpart
)
234 for ( index
= 0 ; index
< m_macToolHandles
.Count() ; ++index
)
236 if ( m_macToolHandles
[index
] == (void*) control
)
238 OnLeftClick( ( (wxToolBarTool
*) (m_tools
.Nth( index
)->Data() ) ) ->m_index
, ( (wxToolBarTool
*) (m_tools
.Nth( index
)->Data() ) ) ->m_toggleState
) ;
243 void wxToolBar::EnableTool(int toolIndex
, bool enable
)
245 wxNode
*node
= m_tools
.Find((long)toolIndex
);
248 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
249 tool
->m_enabled
= enable
;
250 // TODO enable button
254 void wxToolBar::ToggleTool(int toolIndex
, bool toggle
)
256 wxNode
*node
= m_tools
.Find((long)toolIndex
);
259 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
260 if (tool
->m_isToggle
)
262 tool
->m_toggleState
= toggle
;
263 // TODO: set toggle state
268 void wxToolBar::ClearTools()
271 wxToolBarBase::ClearTools();
274 // If pushedBitmap is NULL, a reversed version of bitmap is
275 // created and used as the pushed/toggled image.
276 // If toggle is TRUE, the button toggles between the two states.
278 wxToolBarTool
*wxToolBar::AddTool(int index
, const wxBitmap
& bitmap
, const wxBitmap
& pushedBitmap
,
279 bool toggle
, long xPos
, long yPos
, wxObject
*clientData
, const wxString
& helpString1
, const wxString
& helpString2
)
281 wxToolBarTool
*tool
= new wxToolBarTool(index
, bitmap
, wxNullBitmap
, toggle
, xPos
, yPos
, helpString1
, helpString2
);
282 tool
->m_clientData
= clientData
;
287 tool
->m_x
= m_xMargin
;
292 tool
->m_y
= m_yMargin
;
294 tool
->SetSize(m_defaultWidth
, m_defaultHeight
);
296 m_tools
.Append((long)index
, tool
);
300 #endif // wxUSE_TOOLBAR