]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: toolbar.cpp | |
3 | // Purpose: wxToolBar | |
4 | // Author: AUTHOR | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
2f1ae414 | 8 | // Copyright: (c) AUTHORy |
e9576ca5 SC |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
11 | #ifdef __GNUG__ | |
12 | #pragma implementation "toolbar.h" | |
13 | #endif | |
14 | ||
15 | #include "wx/wx.h" | |
519cb848 SC |
16 | |
17 | #if wxUSE_TOOLBAR | |
18 | ||
e9576ca5 | 19 | #include "wx/toolbar.h" |
2f1ae414 SC |
20 | #include "wx/notebook.h" |
21 | #include "wx/tabctrl.h" | |
e9576ca5 | 22 | |
2f1ae414 | 23 | #if !USE_SHARED_LIBRARY |
12ed316d | 24 | IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxToolBarBase) |
e9576ca5 SC |
25 | |
26 | BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase) | |
2f1ae414 SC |
27 | EVT_MOUSE_EVENTS( wxToolBar::OnMouse ) |
28 | EVT_PAINT( wxToolBar::OnPaint ) | |
e9576ca5 | 29 | END_EVENT_TABLE() |
2f1ae414 | 30 | #endif |
e9576ca5 | 31 | |
519cb848 SC |
32 | #include <wx/mac/uma.h> |
33 | ||
37e2cb08 SC |
34 | // ---------------------------------------------------------------------------- |
35 | // private classes | |
36 | // ---------------------------------------------------------------------------- | |
37 | ||
38 | class wxToolBarTool : public wxToolBarToolBase | |
39 | { | |
40 | public: | |
41 | wxToolBarTool(wxToolBar *tbar, | |
42 | int id, | |
43 | const wxBitmap& bitmap1, | |
44 | const wxBitmap& bitmap2, | |
45 | bool toggle, | |
46 | wxObject *clientData, | |
47 | const wxString& shortHelpString, | |
48 | const wxString& longHelpString) | |
49 | : wxToolBarToolBase(tbar, id, bitmap1, bitmap2, toggle, | |
50 | clientData, shortHelpString, longHelpString) | |
51 | { | |
52 | m_nSepCount = 0; | |
2f1ae414 | 53 | m_index = -1 ; |
37e2cb08 SC |
54 | } |
55 | ||
56 | wxToolBarTool(wxToolBar *tbar, wxControl *control) | |
57 | : wxToolBarToolBase(tbar, control) | |
58 | { | |
59 | m_nSepCount = 1; | |
2f1ae414 | 60 | m_index = -1 ; |
37e2cb08 SC |
61 | } |
62 | ||
63 | // set/get the number of separators which we use to cover the space used by | |
64 | // a control in the toolbar | |
65 | void SetSeparatorsCount(size_t count) { m_nSepCount = count; } | |
66 | size_t GetSeparatorsCount() const { return m_nSepCount; } | |
67 | ||
68 | int m_index ; | |
69 | private: | |
70 | size_t m_nSepCount; | |
71 | }; | |
72 | ||
73 | ||
74 | // ============================================================================ | |
75 | // implementation | |
76 | // ============================================================================ | |
77 | ||
78 | // ---------------------------------------------------------------------------- | |
79 | // wxToolBarTool | |
80 | // ---------------------------------------------------------------------------- | |
81 | ||
895f5af7 SC |
82 | const short kwxMacToolBarToolDefaultWidth = 24 ; |
83 | const short kwxMacToolBarToolDefaultHeight = 22 ; | |
84 | const short kwxMacToolBarTopMargin = 2 ; | |
85 | const short kwxMacToolBarLeftMargin = 2 ; | |
86 | ||
2f1ae414 | 87 | |
37e2cb08 SC |
88 | wxToolBarToolBase *wxToolBar::CreateTool(int id, |
89 | const wxBitmap& bitmap1, | |
90 | const wxBitmap& bitmap2, | |
91 | bool toggle, | |
92 | wxObject *clientData, | |
93 | const wxString& shortHelpString, | |
94 | const wxString& longHelpString) | |
95 | { | |
96 | return new wxToolBarTool(this, id, bitmap1, bitmap2, toggle, | |
97 | clientData, shortHelpString, longHelpString); | |
98 | } | |
99 | ||
100 | wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control) | |
101 | { | |
102 | return new wxToolBarTool(this, control); | |
103 | } | |
104 | ||
37e2cb08 | 105 | void wxToolBar::Init() |
e9576ca5 SC |
106 | { |
107 | m_maxWidth = -1; | |
108 | m_maxHeight = -1; | |
895f5af7 SC |
109 | m_defaultWidth = kwxMacToolBarToolDefaultWidth; |
110 | m_defaultHeight = kwxMacToolBarToolDefaultHeight; | |
e9576ca5 SC |
111 | } |
112 | ||
113 | bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, | |
114 | long style, const wxString& name) | |
115 | { | |
e9576ca5 | 116 | |
519cb848 SC |
117 | int x = pos.x; |
118 | int y = pos.y; | |
119 | int width = size.x; | |
120 | int height = size.y; | |
e9576ca5 | 121 | |
519cb848 SC |
122 | if (width <= 0) |
123 | width = 100; | |
124 | if (height <= 0) | |
125 | height = 30; | |
126 | if (x < 0) | |
127 | x = 0; | |
128 | if (y < 0) | |
129 | y = 0; | |
e9576ca5 | 130 | |
895f5af7 SC |
131 | SetName(name); |
132 | ||
133 | m_windowStyle = style; | |
134 | parent->AddChild(this); | |
135 | ||
136 | m_backgroundColour = parent->GetBackgroundColour() ; | |
137 | m_foregroundColour = parent->GetForegroundColour() ; | |
138 | ||
139 | if (id == -1) | |
140 | m_windowId = NewControlId(); | |
141 | else | |
142 | m_windowId = id; | |
143 | ||
144 | { | |
145 | m_width = size.x ; | |
146 | m_height = size.y ; | |
147 | int x = pos.x ; | |
148 | int y = pos.y ; | |
149 | AdjustForParentClientOrigin(x, y, wxSIZE_USE_EXISTING); | |
150 | m_x = x ; | |
151 | m_y = y ; | |
152 | } | |
a90c95aa RR |
153 | |
154 | return TRUE; | |
e9576ca5 SC |
155 | } |
156 | ||
157 | wxToolBar::~wxToolBar() | |
158 | { | |
7810c95b SC |
159 | // we must refresh the frame size when the toolbar is deleted but the frame |
160 | // is not - otherwise toolbar leaves a hole in the place it used to occupy | |
e9576ca5 SC |
161 | } |
162 | ||
2f1ae414 SC |
163 | PicHandle MakePict(GWorldPtr wp, GWorldPtr mask ) ; |
164 | PicHandle MakePict(GWorldPtr wp, GWorldPtr mask ) | |
519cb848 SC |
165 | { |
166 | CGrafPtr origPort ; | |
167 | GDHandle origDev ; | |
168 | ||
169 | PicHandle pict; // this is the Picture we give back | |
170 | ||
171 | RGBColor gray = { 0xCCCC ,0xCCCC , 0xCCCC } ; | |
2f1ae414 SC |
172 | RGBColor white = { 0xffff ,0xffff , 0xffff } ; |
173 | RGBColor black = { 0x0000 ,0x0000 , 0x0000 } ; | |
519cb848 | 174 | |
2f1ae414 SC |
175 | unsigned char *maskimage = NULL ; |
176 | Rect portRect ; | |
177 | GetPortBounds( wp , &portRect ) ; | |
178 | int width = portRect.right - portRect.left ; | |
179 | int height = portRect.bottom - portRect.top ; | |
519cb848 | 180 | |
2f1ae414 SC |
181 | LockPixels( GetGWorldPixMap( wp ) ) ; |
182 | GetGWorld( &origPort , &origDev ) ; | |
519cb848 | 183 | |
2f1ae414 SC |
184 | if ( mask ) |
185 | { | |
186 | ||
187 | maskimage = (unsigned char*) malloc( width * height ) ; | |
188 | SetGWorld( mask , NULL ) ; | |
189 | LockPixels( GetGWorldPixMap( mask ) ) ; | |
190 | for ( int y = 0 ; y < height ; ++y ) | |
191 | { | |
192 | for( int x = 0 ; x < width ; ++x ) | |
193 | { | |
194 | RGBColor col ; | |
195 | ||
196 | GetCPixel( x + portRect.left , y + portRect.top , &col ) ; | |
197 | maskimage[y*width + x] = ( col.red == 0 ) ; // for monochrome masks | |
198 | } | |
199 | } | |
200 | UnlockPixels( GetGWorldPixMap( mask ) ) ; | |
201 | } | |
519cb848 | 202 | |
519cb848 SC |
203 | SetGWorld( wp , NULL ) ; |
204 | ||
2f1ae414 | 205 | pict = OpenPicture(&portRect); // open a picture, this disables drawing |
519cb848 SC |
206 | if(!pict) |
207 | return NULL; | |
2f1ae414 SC |
208 | |
209 | RGBBackColor( &gray ) ; | |
210 | RGBForeColor( &black ) ; | |
211 | EraseRect(&portRect) ; | |
519cb848 | 212 | RGBBackColor( &white ) ; |
2f1ae414 SC |
213 | |
214 | if ( maskimage ) | |
215 | { | |
216 | for ( int y = 0 ; y < height ; ++y ) | |
217 | { | |
218 | for( int x = 0 ; x < width ; ++x ) | |
219 | { | |
220 | if ( maskimage[y*width + x] ) | |
221 | { | |
222 | RGBColor col ; | |
223 | ||
224 | GetCPixel( x + portRect.left , y + portRect.top , &col ) ; | |
225 | SetCPixel( x + portRect.left , y + portRect.top , &col ) ; | |
226 | } | |
227 | } | |
228 | } | |
229 | free( maskimage ) ; | |
230 | maskimage = NULL ; | |
231 | } | |
232 | else | |
233 | { | |
234 | CopyBits(GetPortBitMapForCopyBits(wp), // src PixMap - we copy image over itself - | |
235 | GetPortBitMapForCopyBits(wp), // dst PixMap - no drawing occurs - | |
236 | &portRect, // srcRect - it will be recorded and compressed - | |
237 | &portRect, // dstRect - into the picture that is open - | |
519cb848 SC |
238 | srcCopy,NULL); // copyMode and no clip region |
239 | ||
2f1ae414 | 240 | } |
519cb848 | 241 | ClosePicture(); // We are done recording the picture |
2f1ae414 | 242 | UnlockPixels( GetGWorldPixMap( wp ) ) ; |
519cb848 SC |
243 | SetGWorld( origPort , origDev ) ; |
244 | return pict; // return our groovy pict handle | |
245 | } | |
246 | ||
37e2cb08 | 247 | bool wxToolBar::Realize() |
e9576ca5 | 248 | { |
519cb848 SC |
249 | if (m_tools.Number() == 0) |
250 | return FALSE; | |
e9576ca5 | 251 | |
80645074 SC |
252 | Point localOrigin ; |
253 | Rect clipRect ; | |
254 | WindowRef window ; | |
255 | wxWindow *win ; | |
256 | ||
7810c95b | 257 | GetParent()->MacGetPortParams( &localOrigin , &clipRect , &window , &win ) ; |
80645074 SC |
258 | |
259 | Rect toolbarrect = { m_y + localOrigin.v , m_x + localOrigin.h , | |
260 | m_y + m_height + localOrigin.v , m_x + m_width + localOrigin.h} ; | |
519cb848 | 261 | ControlFontStyleRec controlstyle ; |
80645074 | 262 | |
519cb848 SC |
263 | controlstyle.flags = kControlUseFontMask ; |
264 | controlstyle.font = kControlFontSmallSystemFont ; | |
265 | ||
266 | wxNode *node = m_tools.First(); | |
267 | int noButtons = 0; | |
268 | int x = 0 ; | |
7c551d95 SC |
269 | wxSize toolSize = GetToolSize() ; |
270 | int tw, th; | |
271 | GetSize(& tw, & th); | |
895f5af7 SC |
272 | |
273 | int maxWidth = 0 ; | |
274 | int maxHeight = 0 ; | |
275 | ||
519cb848 SC |
276 | while (node) |
277 | { | |
278 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
37e2cb08 | 279 | wxBitmapRefData * bmap = (wxBitmapRefData*) ( tool->GetBitmap1().GetRefData()) ; |
519cb848 | 280 | |
2f1ae414 | 281 | if( !tool->IsSeparator() ) |
519cb848 | 282 | { |
895f5af7 | 283 | Rect toolrect = { toolbarrect.top + m_yMargin + kwxMacToolBarTopMargin, toolbarrect.left + x + m_xMargin + kwxMacToolBarLeftMargin , 0 , 0 } ; |
7c551d95 SC |
284 | toolrect.right = toolrect.left + toolSize.x ; |
285 | toolrect.bottom = toolrect.top + toolSize.y ; | |
519cb848 SC |
286 | |
287 | PicHandle icon = NULL ; | |
288 | if ( bmap ) | |
289 | { | |
290 | if ( bmap->m_bitmapType == kMacBitmapTypePict ) | |
291 | icon = bmap->m_hPict ; | |
292 | else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld ) | |
293 | { | |
2f1ae414 SC |
294 | if ( tool->GetBitmap1().GetMask() ) |
295 | { | |
296 | icon = MakePict( bmap->m_hBitmap , tool->GetBitmap1().GetMask()->GetMaskBitmap() ) ; | |
297 | } | |
298 | else | |
299 | { | |
300 | icon = MakePict( bmap->m_hBitmap , NULL ) ; | |
301 | } | |
519cb848 SC |
302 | } |
303 | } | |
304 | ||
305 | ControlHandle m_macToolHandle ; | |
2f1ae414 | 306 | |
8208e181 SC |
307 | SInt16 behaviour = kControlBehaviorOffsetContents ; |
308 | if ( tool->CanBeToggled() ) | |
309 | behaviour += kControlBehaviorToggles ; | |
310 | ||
519cb848 SC |
311 | if ( icon ) |
312 | { | |
fdaf613a | 313 | m_macToolHandle = UMANewControl( window , &toolrect , "\p" , false , 0 , |
8208e181 | 314 | behaviour + kControlContentPictHandle , 0 , kControlBevelButtonNormalBevelProc , (long) this ) ; |
519cb848 SC |
315 | ControlButtonContentInfo info ; |
316 | ||
317 | info.contentType = kControlContentPictHandle ; | |
318 | info.u.picture = icon ; | |
319 | ||
320 | UMASetControlData( m_macToolHandle , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ; | |
321 | } | |
322 | else | |
323 | { | |
fdaf613a | 324 | m_macToolHandle = UMANewControl( window , &toolrect , "\p" , false , 0 , |
8208e181 | 325 | behaviour , 0 , kControlBevelButtonNormalBevelProc , (long) this ) ; |
519cb848 | 326 | } |
fdaf613a | 327 | UMAShowControl( m_macToolHandle ) ; |
519cb848 | 328 | m_macToolHandles.Add( m_macToolHandle ) ; |
2f1ae414 SC |
329 | tool->m_index = m_macToolHandles.Count() -1 ; |
330 | if ( !tool->IsEnabled() ) | |
331 | { | |
332 | UMADeactivateControl( m_macToolHandle ) ; | |
333 | } | |
334 | if ( tool->CanBeToggled() && tool->IsToggled() ) | |
335 | { | |
336 | ::SetControlValue( m_macToolHandle , 1 ) ; | |
337 | } | |
519cb848 | 338 | UMASetControlFontStyle( m_macToolHandle , &controlstyle ) ; |
2f1ae414 SC |
339 | ControlHandle container = GetParent()->MacGetContainerForEmbedding() ; |
340 | wxASSERT_MSG( container != NULL , "No valid mac container control" ) ; | |
341 | UMAEmbedControl( m_macToolHandle , container ) ; | |
519cb848 | 342 | |
7c551d95 | 343 | x += (int)toolSize.x; |
519cb848 SC |
344 | noButtons ++; |
345 | } | |
346 | else | |
347 | { | |
348 | m_macToolHandles.Add( NULL ) ; | |
7c551d95 | 349 | x += (int)toolSize.x / 4; |
519cb848 | 350 | } |
895f5af7 SC |
351 | if ( toolbarrect.left + x + m_xMargin + kwxMacToolBarLeftMargin- m_x - localOrigin.h > maxWidth) |
352 | maxWidth = toolbarrect.left + x + kwxMacToolBarLeftMargin+ m_xMargin - m_x - localOrigin.h; | |
353 | if (toolbarrect.top + m_yMargin + kwxMacToolBarTopMargin - m_y - localOrigin.v > maxHeight) | |
354 | maxHeight = toolbarrect.top + kwxMacToolBarTopMargin + m_yMargin - m_y - localOrigin.v ; | |
7c551d95 | 355 | |
519cb848 SC |
356 | node = node->Next(); |
357 | } | |
358 | ||
7c551d95 SC |
359 | if ( GetWindowStyleFlag() & wxTB_HORIZONTAL ) |
360 | { | |
7810c95b SC |
361 | if ( m_maxRows == 0 ) |
362 | { | |
363 | // if not set yet, only one row | |
364 | SetRows(1); | |
365 | } | |
895f5af7 SC |
366 | maxWidth = tw ; |
367 | maxHeight += toolSize.y; | |
368 | maxHeight += m_yMargin + kwxMacToolBarTopMargin; | |
369 | m_maxHeight = maxHeight ; | |
7c551d95 SC |
370 | } |
371 | else | |
372 | { | |
7810c95b SC |
373 | if ( noButtons > 0 && m_maxRows == 0 ) |
374 | { | |
375 | // if not set yet, have one column | |
376 | SetRows(noButtons); | |
377 | } | |
895f5af7 SC |
378 | maxHeight = th ; |
379 | maxWidth += toolSize.x; | |
380 | maxWidth += m_xMargin + kwxMacToolBarLeftMargin; | |
381 | m_maxWidth = maxWidth ; | |
7c551d95 SC |
382 | } |
383 | ||
895f5af7 | 384 | SetSize(maxWidth, maxHeight); |
7c551d95 | 385 | |
519cb848 | 386 | return TRUE; |
e9576ca5 SC |
387 | } |
388 | ||
389 | void wxToolBar::SetToolBitmapSize(const wxSize& size) | |
390 | { | |
9aad97fd | 391 | m_defaultWidth = size.x+4; m_defaultHeight = size.y+4; |
e9576ca5 SC |
392 | } |
393 | ||
e9576ca5 SC |
394 | // The button size is bigger than the bitmap size |
395 | wxSize wxToolBar::GetToolSize() const | |
396 | { | |
2f1ae414 | 397 | return wxSize(m_defaultWidth + 4, m_defaultHeight + 4); |
e9576ca5 SC |
398 | } |
399 | ||
519cb848 SC |
400 | void wxToolBar::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) |
401 | { | |
402 | int index = 0 ; | |
403 | for ( index = 0 ; index < m_macToolHandles.Count() ; ++index ) | |
404 | { | |
405 | if ( m_macToolHandles[index] == (void*) control ) | |
406 | { | |
2f1ae414 SC |
407 | wxToolBarTool *tool = (wxToolBarTool *)m_tools.Nth( index )->Data(); |
408 | if ( tool->CanBeToggled() ) | |
409 | { | |
410 | tool->Toggle( GetControlValue( control ) ) ; | |
411 | } | |
412 | OnLeftClick( tool->GetId() , tool -> IsToggled() ) ; | |
413 | break ; | |
519cb848 SC |
414 | } |
415 | } | |
416 | } | |
417 | ||
37e2cb08 | 418 | void wxToolBar::SetRows(int nRows) |
e9576ca5 | 419 | { |
37e2cb08 | 420 | if ( nRows == m_maxRows ) |
e9576ca5 | 421 | { |
37e2cb08 SC |
422 | // avoid resizing the frame uselessly |
423 | return; | |
e9576ca5 | 424 | } |
37e2cb08 SC |
425 | |
426 | m_maxRows = nRows; | |
e9576ca5 SC |
427 | } |
428 | ||
c257d44d SC |
429 | void wxToolBar::MacSuperChangedPosition() |
430 | { | |
431 | if (m_tools.Number() > 0) | |
432 | { | |
433 | ||
434 | Point localOrigin ; | |
435 | Rect clipRect ; | |
436 | WindowRef window ; | |
437 | wxWindow *win ; | |
438 | ||
439 | GetParent()->MacGetPortParams( &localOrigin , &clipRect , &window , &win ) ; | |
440 | ||
441 | Rect toolbarrect = { m_y + localOrigin.v , m_x + localOrigin.h , | |
442 | m_y + m_height + localOrigin.v , m_x + m_width + localOrigin.h} ; | |
443 | ControlFontStyleRec controlstyle ; | |
444 | ||
445 | controlstyle.flags = kControlUseFontMask ; | |
446 | controlstyle.font = kControlFontSmallSystemFont ; | |
447 | ||
448 | wxNode *node = m_tools.First(); | |
449 | int noButtons = 0; | |
450 | int x = 0 ; | |
451 | wxSize toolSize = GetToolSize() ; | |
452 | int tw, th; | |
453 | GetSize(& tw, & th); | |
454 | ||
455 | int maxWidth = 0 ; | |
456 | int maxHeight = 0 ; | |
457 | int toolcount = 0 ; | |
458 | { | |
459 | WindowRef rootwindow = GetMacRootWindow() ; | |
460 | wxWindow* wxrootwindow = wxFindWinFromMacWindow( rootwindow ) ; | |
461 | UMASetThemeWindowBackground( rootwindow , kThemeBrushDialogBackgroundActive , false ) ; | |
462 | wxMacDrawingHelper focus( wxrootwindow ) ; | |
463 | while (node) | |
464 | { | |
465 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
466 | wxBitmapRefData * bmap = (wxBitmapRefData*) ( tool->GetBitmap1().GetRefData()) ; | |
467 | ||
468 | if( !tool->IsSeparator() ) | |
469 | { | |
470 | Rect toolrect = { toolbarrect.top + m_yMargin + kwxMacToolBarTopMargin, toolbarrect.left + x + m_xMargin + kwxMacToolBarLeftMargin , 0 , 0 } ; | |
471 | toolrect.right = toolrect.left + toolSize.x ; | |
472 | toolrect.bottom = toolrect.top + toolSize.y ; | |
473 | ||
474 | ControlHandle m_macToolHandle = (ControlHandle) m_macToolHandles[toolcount++] ; | |
475 | ||
476 | { | |
477 | Rect contrlRect ; | |
478 | GetControlBounds( m_macToolHandle , &contrlRect ) ; | |
479 | int former_mac_x = contrlRect.left ; | |
480 | int former_mac_y = contrlRect.top ; | |
481 | int mac_x = toolrect.left ; | |
482 | int mac_y = toolrect.top ; | |
483 | ||
484 | if ( mac_x != former_mac_x || mac_y != former_mac_y ) | |
485 | { | |
486 | { | |
487 | Rect inval = { former_mac_y , former_mac_x , former_mac_y + toolSize.y , former_mac_x + toolSize.y } ; | |
488 | InvalWindowRect( rootwindow , &inval ) ; | |
489 | } | |
490 | UMAMoveControl( m_macToolHandle , mac_x , mac_y ) ; | |
491 | { | |
492 | Rect inval = { mac_y , mac_x , mac_y + toolSize.y , mac_x + toolSize.y } ; | |
493 | InvalWindowRect( rootwindow , &inval ) ; | |
494 | } | |
495 | } | |
496 | } | |
497 | ||
498 | x += (int)toolSize.x; | |
499 | noButtons ++; | |
500 | } | |
501 | else | |
502 | { | |
503 | toolcount++ ; | |
504 | x += (int)toolSize.x / 4; | |
505 | } | |
506 | if ( toolbarrect.left + x + m_xMargin + kwxMacToolBarLeftMargin- m_x - localOrigin.h > maxWidth) | |
507 | maxWidth = toolbarrect.left + x + kwxMacToolBarLeftMargin+ m_xMargin - m_x - localOrigin.h; | |
508 | if (toolbarrect.top + m_yMargin + kwxMacToolBarTopMargin - m_y - localOrigin.v > maxHeight) | |
509 | maxHeight = toolbarrect.top + kwxMacToolBarTopMargin + m_yMargin - m_y - localOrigin.v ; | |
510 | ||
511 | node = node->Next(); | |
512 | } | |
513 | if ( wxrootwindow->IsKindOf( CLASSINFO( wxDialog ) ) ) | |
514 | { | |
515 | } | |
516 | else | |
517 | { | |
518 | UMASetThemeWindowBackground( rootwindow , kThemeBrushDocumentWindowBackground , false ) ; | |
519 | } | |
520 | } | |
521 | ||
522 | if ( GetWindowStyleFlag() & wxTB_HORIZONTAL ) | |
523 | { | |
524 | if ( m_maxRows == 0 ) | |
525 | { | |
526 | // if not set yet, only one row | |
527 | SetRows(1); | |
528 | } | |
529 | maxWidth = tw ; | |
530 | maxHeight += toolSize.y; | |
531 | maxHeight += m_yMargin + kwxMacToolBarTopMargin; | |
532 | m_maxHeight = maxHeight ; | |
533 | } | |
534 | else | |
535 | { | |
536 | if ( noButtons > 0 && m_maxRows == 0 ) | |
537 | { | |
538 | // if not set yet, have one column | |
539 | SetRows(noButtons); | |
540 | } | |
541 | maxHeight = th ; | |
542 | maxWidth += toolSize.x; | |
543 | maxWidth += m_xMargin + kwxMacToolBarLeftMargin; | |
544 | m_maxWidth = maxWidth ; | |
545 | } | |
546 | ||
547 | SetSize(maxWidth, maxHeight); | |
548 | } | |
549 | ||
550 | wxWindow::MacSuperChangedPosition() ; | |
551 | } | |
552 | ||
37e2cb08 | 553 | wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const |
e9576ca5 | 554 | { |
37e2cb08 | 555 | MacClientToRootWindow( &x , &y ) ; |
2f1ae414 | 556 | Point pt = { y ,x } ; |
37e2cb08 SC |
557 | |
558 | int index = 0 ; | |
559 | for ( index = 0 ; index < m_macToolHandles.Count() ; ++index ) | |
560 | { | |
2f1ae414 | 561 | if ( m_macToolHandles[index] ) |
37e2cb08 | 562 | { |
2f1ae414 SC |
563 | Rect bounds ; |
564 | GetControlBounds((ControlHandle) m_macToolHandles[index], &bounds ) ; | |
565 | if ( PtInRect( pt , &bounds ) ) | |
566 | { | |
567 | return (wxToolBarTool*) (m_tools.Nth( index )->Data() ) ; | |
568 | } | |
37e2cb08 SC |
569 | } |
570 | } | |
571 | ||
572 | return (wxToolBarToolBase *)NULL; | |
e9576ca5 SC |
573 | } |
574 | ||
2f1ae414 SC |
575 | wxString wxToolBar::MacGetToolTipString( wxPoint &pt ) |
576 | { | |
577 | wxToolBarToolBase* tool = FindToolForPosition( pt.x , pt.y ) ; | |
578 | if ( tool ) | |
579 | { | |
580 | return tool->GetShortHelp() ; | |
581 | } | |
582 | return "" ; | |
583 | } | |
584 | ||
37e2cb08 | 585 | void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable) |
e9576ca5 | 586 | { |
37e2cb08 | 587 | wxToolBarTool *tool = (wxToolBarTool *)t; |
2f1ae414 SC |
588 | if ( tool->m_index < 0 ) |
589 | return ; | |
590 | ||
8208e181 | 591 | ControlHandle control = (ControlHandle) m_macToolHandles[ tool->m_index ] ; |
2f1ae414 SC |
592 | |
593 | if ( enable ) | |
594 | UMAActivateControl( control ) ; | |
8208e181 | 595 | else |
2f1ae414 | 596 | UMADeactivateControl( control ) ; |
e9576ca5 SC |
597 | } |
598 | ||
37e2cb08 | 599 | void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle) |
e9576ca5 | 600 | { |
37e2cb08 | 601 | wxToolBarTool *tool = (wxToolBarTool *)t; |
2f1ae414 SC |
602 | if ( tool->m_index < 0 ) |
603 | return ; | |
8208e181 SC |
604 | |
605 | ControlHandle control = (ControlHandle) m_macToolHandles[ tool->m_index ] ; | |
606 | ::SetControlValue( control , toggle ) ; | |
37e2cb08 | 607 | } |
7c551d95 | 608 | |
37e2cb08 SC |
609 | bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), |
610 | wxToolBarToolBase *tool) | |
611 | { | |
612 | // nothing special to do here - we really create the toolbar buttons in | |
613 | // Realize() later | |
614 | tool->Attach(this); | |
7c551d95 | 615 | |
37e2cb08 SC |
616 | return TRUE; |
617 | } | |
e9576ca5 | 618 | |
37e2cb08 SC |
619 | void wxToolBar::DoSetToggle(wxToolBarToolBase *t, bool toggle) |
620 | { | |
621 | wxToolBarTool *tool = (wxToolBarTool *)t; | |
622 | // TODO: set toggle state | |
e9576ca5 SC |
623 | } |
624 | ||
37e2cb08 SC |
625 | bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool) |
626 | { | |
627 | return TRUE ; | |
628 | } | |
2f1ae414 SC |
629 | |
630 | void wxToolBar::OnPaint(wxPaintEvent& event) | |
631 | { | |
80645074 SC |
632 | Point localOrigin ; |
633 | Rect clipRect ; | |
634 | WindowRef window ; | |
635 | wxWindow *win ; | |
636 | ||
7810c95b | 637 | GetParent()->MacGetPortParams( &localOrigin , &clipRect , &window , &win ) ; |
80645074 SC |
638 | if ( window && win ) |
639 | { | |
640 | wxMacDrawingHelper help( win ) ; | |
641 | // the mac control manager always assumes to have the origin at 0,0 | |
642 | SetOrigin( 0 , 0 ) ; | |
643 | ||
644 | bool hasTabBehind = false ; | |
645 | wxWindow* parent = GetParent() ; | |
646 | while ( parent ) | |
647 | { | |
648 | if( parent->MacGetWindowData() ) | |
649 | { | |
650 | UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ; | |
651 | break ; | |
652 | } | |
653 | ||
654 | if( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) | |
655 | { | |
656 | if ( ((wxControl*)parent)->GetMacControl() ) | |
657 | SetUpControlBackground( ((wxControl*)parent)->GetMacControl() , -1 , true ) ; | |
658 | break ; | |
659 | } | |
660 | ||
661 | parent = parent->GetParent() ; | |
662 | } | |
895f5af7 | 663 | |
80645074 | 664 | Rect toolbarrect = { m_y + localOrigin.v , m_x + localOrigin.h , |
895f5af7 | 665 | m_y + localOrigin.v + m_height , m_x + localOrigin.h + m_width } ; |
80645074 SC |
666 | |
667 | UMADrawThemePlacard( &toolbarrect , IsEnabled() ? kThemeStateActive : kThemeStateInactive) ; | |
668 | { | |
669 | int index = 0 ; | |
670 | for ( index = 0 ; index < m_macToolHandles.Count() ; ++index ) | |
671 | { | |
672 | if ( m_macToolHandles[index] ) | |
673 | { | |
674 | UMADrawControl( (ControlHandle) m_macToolHandles[index] ) ; | |
675 | } | |
676 | } | |
677 | } | |
678 | UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ; | |
80645074 | 679 | } |
2f1ae414 | 680 | } |
895f5af7 | 681 | |
2f1ae414 SC |
682 | void wxToolBar::OnMouse( wxMouseEvent &event ) |
683 | { | |
684 | ||
685 | if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK ) | |
686 | { | |
687 | ||
688 | int x = event.m_x ; | |
689 | int y = event.m_y ; | |
690 | ||
691 | MacClientToRootWindow( &x , &y ) ; | |
692 | ||
693 | ControlHandle control ; | |
694 | Point localwhere ; | |
695 | GrafPtr port ; | |
696 | SInt16 controlpart ; | |
697 | WindowRef window = GetMacRootWindow() ; | |
698 | ||
699 | localwhere.h = x ; | |
700 | localwhere.v = y ; | |
701 | ||
702 | short modifiers = 0; | |
703 | ||
704 | if ( !event.m_leftDown && !event.m_rightDown ) | |
705 | modifiers |= btnState ; | |
706 | ||
707 | if ( event.m_shiftDown ) | |
708 | modifiers |= shiftKey ; | |
709 | ||
710 | if ( event.m_controlDown ) | |
711 | modifiers |= controlKey ; | |
712 | ||
713 | if ( event.m_altDown ) | |
714 | modifiers |= optionKey ; | |
715 | ||
716 | if ( event.m_metaDown ) | |
717 | modifiers |= cmdKey ; | |
718 | ||
719 | controlpart = FindControl( localwhere , window , &control ) ; | |
720 | { | |
2f1ae414 SC |
721 | if ( control && UMAIsControlActive( control ) ) |
722 | { | |
723 | { | |
724 | if ( controlpart == kControlIndicatorPart && !UMAHasAppearance() ) | |
725 | controlpart = UMAHandleControlClick( control , localwhere , modifiers , (ControlActionUPP) NULL ) ; | |
726 | else | |
727 | controlpart = UMAHandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ; | |
728 | wxTheApp->s_lastMouseDown = 0 ; | |
729 | if ( controlpart && ! ( ( UMAHasAppearance() || (controlpart != kControlIndicatorPart) ) | |
730 | && (IsKindOf( CLASSINFO( wxScrollBar ) ) ) ) ) // otherwise we will get the event twice | |
731 | { | |
732 | MacHandleControlClick( control , controlpart ) ; | |
733 | } | |
734 | } | |
735 | } | |
736 | } | |
737 | } | |
738 | } | |
739 | ||
519cb848 SC |
740 | #endif // wxUSE_TOOLBAR |
741 |