]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: control.cpp | |
3 | // Purpose: wxControl class | |
4 | // Author: AUTHOR | |
5 | // Modified by: | |
6 | // Created: ??/??/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) AUTHOR | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "control.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/control.h" | |
17 | #include "wx/panel.h" | |
18 | #include "wx/app.h" | |
19 | #include "wx/notebook.h" | |
20 | #include "wx/tabctrl.h" | |
21 | #include "wx/radiobox.h" | |
22 | #include "wx/spinbutt.h" | |
23 | #include "wx/scrolbar.h" | |
24 | #include "wx/button.h" | |
25 | #include "wx/dialog.h" | |
26 | #include "wx/statbox.h" | |
27 | #include "wx/sizer.h" | |
28 | #include "wx/stattext.h" | |
29 | ||
30 | #if !USE_SHARED_LIBRARY | |
31 | IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow) | |
32 | ||
33 | BEGIN_EVENT_TABLE(wxControl, wxWindow) | |
34 | EVT_MOUSE_EVENTS( wxControl::OnMouseEvent ) | |
35 | EVT_CHAR( wxControl::OnKeyDown ) | |
36 | EVT_PAINT( wxControl::OnPaint ) | |
37 | END_EVENT_TABLE() | |
38 | #endif | |
39 | ||
40 | #include <wx/mac/uma.h> | |
41 | ||
42 | // Item members | |
43 | ||
44 | ControlActionUPP wxMacLiveScrollbarActionUPP = NULL ; | |
45 | ||
46 | pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode ) ; | |
47 | pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode ) | |
48 | { | |
49 | if ( partCode != 0) | |
50 | { | |
51 | wxControl* wx = (wxControl*) GetControlReference( control ) ; | |
52 | if ( wx ) | |
53 | { | |
54 | wx->MacHandleControlClick( control , partCode ) ; | |
55 | } | |
56 | } | |
57 | } | |
58 | ||
59 | wxControl::wxControl() | |
60 | { | |
61 | m_macControl = NULL ; | |
62 | m_macHorizontalBorder = 0 ; // additional pixels around the real control | |
63 | m_macVerticalBorder = 0 ; | |
64 | m_backgroundColour = *wxWHITE; | |
65 | m_foregroundColour = *wxBLACK; | |
66 | #if WXWIN_COMPATIBILITY | |
67 | m_callback = 0; | |
68 | #endif // WXWIN_COMPATIBILITY | |
69 | ||
70 | if ( wxMacLiveScrollbarActionUPP == NULL ) | |
71 | { | |
72 | #ifdef __UNIX__ | |
73 | wxMacLiveScrollbarActionUPP = NewControlActionUPP( wxMacLiveScrollbarActionProc ); | |
74 | #else | |
75 | wxMacLiveScrollbarActionUPP = NewControlActionProc( wxMacLiveScrollbarActionProc ) ; | |
76 | #endif | |
77 | } | |
78 | } | |
79 | ||
80 | bool wxControl::Create(wxWindow *parent, wxWindowID id, | |
81 | const wxPoint& pos, | |
82 | const wxSize& size, long style, | |
83 | const wxValidator& validator, | |
84 | const wxString& name) | |
85 | { | |
86 | m_macControl = NULL ; | |
87 | m_macHorizontalBorder = 0 ; // additional pixels around the real control | |
88 | m_macVerticalBorder = 0 ; | |
89 | bool rval = wxWindow::Create(parent, id, pos, size, style, name); | |
90 | if (rval) { | |
91 | #if wxUSE_VALIDATORS | |
92 | SetValidator(validator); | |
93 | #endif | |
94 | } | |
95 | return rval; | |
96 | } | |
97 | ||
98 | wxControl::~wxControl() | |
99 | { | |
100 | m_isBeingDeleted = TRUE; | |
101 | // If we delete an item, we should initialize the parent panel, | |
102 | // because it could now be invalid. | |
103 | wxPanel *panel = wxDynamicCast(GetParent(), wxPanel); | |
104 | if ( panel ) | |
105 | { | |
106 | if (panel->GetDefaultItem() == (wxButton*) this) | |
107 | panel->SetDefaultItem(NULL); | |
108 | } | |
109 | if ( m_macControl ) | |
110 | { | |
111 | UMADisposeControl( m_macControl ) ; | |
112 | m_macControl = NULL ; | |
113 | } | |
114 | } | |
115 | ||
116 | void wxControl::SetLabel(const wxString& title) | |
117 | { | |
118 | m_label = title ; | |
119 | ||
120 | if ( m_macControl ) | |
121 | { | |
122 | Str255 maclabel ; | |
123 | wxString label ; | |
124 | ||
125 | if( wxApp::s_macDefaultEncodingIsPC ) | |
126 | label = wxMacMakeMacStringFromPC( title ) ; | |
127 | else | |
128 | label = title ; | |
129 | ||
130 | #if TARGET_CARBON | |
131 | c2pstrcpy( (StringPtr) maclabel , label ) ; | |
132 | #else | |
133 | strcpy( (char *) maclabel , label ) ; | |
134 | c2pstr( (char *) maclabel ) ; | |
135 | #endif | |
136 | ::SetControlTitle( m_macControl , maclabel ) ; | |
137 | } | |
138 | } | |
139 | ||
140 | wxSize wxControl::DoGetBestSize() const | |
141 | { | |
142 | return wxSize(20, 20); | |
143 | } | |
144 | ||
145 | bool wxControl::ProcessCommand (wxCommandEvent & event) | |
146 | { | |
147 | // Tries: | |
148 | // 1) A callback function (to become obsolete) | |
149 | // 2) OnCommand, starting at this window and working up parent hierarchy | |
150 | // 3) OnCommand then calls ProcessEvent to search the event tables. | |
151 | #if WXWIN_COMPATIBILITY | |
152 | if ( m_callback ) | |
153 | { | |
154 | (void)(*m_callback)(this, event); | |
155 | ||
156 | return TRUE; | |
157 | } | |
158 | else | |
159 | #endif // WXWIN_COMPATIBILITY | |
160 | { | |
161 | return GetEventHandler()->ProcessEvent(event); | |
162 | } | |
163 | } | |
164 | ||
165 | // ------------------------ | |
166 | wxList *wxWinMacControlList = NULL; | |
167 | wxControl *wxFindControlFromMacControl(ControlHandle inControl ) | |
168 | { | |
169 | wxNode *node = wxWinMacControlList->Find((long)inControl); | |
170 | if (!node) | |
171 | return NULL; | |
172 | return (wxControl *)node->Data(); | |
173 | } | |
174 | ||
175 | void wxAssociateControlWithMacControl(ControlHandle inControl, wxControl *control) | |
176 | { | |
177 | // adding NULL WindowRef is (first) surely a result of an error and | |
178 | // (secondly) breaks menu command processing | |
179 | wxCHECK_RET( inControl != (ControlHandle) NULL, "attempt to add a NULL WindowRef to window list" ); | |
180 | ||
181 | if ( !wxWinMacControlList->Find((long)inControl) ) | |
182 | wxWinMacControlList->Append((long)inControl, control); | |
183 | } | |
184 | ||
185 | void wxRemoveMacControlAssociation(wxControl *control) | |
186 | { | |
187 | wxWinMacControlList->DeleteObject(control); | |
188 | } | |
189 | ||
190 | void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString label , | |
191 | const wxPoint& pos, | |
192 | const wxSize& size, long style, | |
193 | const wxValidator& validator, | |
194 | const wxString& name , Rect *outBounds , StringPtr maclabel ) | |
195 | { | |
196 | m_label = label ; | |
197 | SetName(name); | |
198 | if ( &validator ) | |
199 | SetValidator(validator); | |
200 | ||
201 | m_windowStyle = style; | |
202 | parent->AddChild((wxButton *)this); | |
203 | ||
204 | m_backgroundColour = parent->GetBackgroundColour() ; | |
205 | m_foregroundColour = parent->GetForegroundColour() ; | |
206 | ||
207 | if (id == -1) | |
208 | m_windowId = NewControlId(); | |
209 | else | |
210 | m_windowId = id; | |
211 | ||
212 | m_width = size.x ; | |
213 | m_height = size.y ; | |
214 | int x = pos.x ; | |
215 | int y = pos.y ; | |
216 | AdjustForParentClientOrigin(x, y, wxSIZE_USE_EXISTING); | |
217 | m_x = x ; | |
218 | m_y = y ; | |
219 | ||
220 | ||
221 | parent->MacClientToRootWindow( &x , &y ) ; | |
222 | outBounds->top = y + m_macVerticalBorder ; | |
223 | outBounds->left = x + m_macHorizontalBorder ; | |
224 | outBounds->bottom = outBounds->top + m_height - 2 * m_macVerticalBorder; | |
225 | outBounds->right = outBounds->left + m_width - 2 * m_macHorizontalBorder ; | |
226 | ||
227 | char c_text[255]; | |
228 | strcpy( c_text , label ) ; | |
229 | if( wxApp::s_macDefaultEncodingIsPC ) | |
230 | { | |
231 | wxMacConvertFromPCForControls( c_text ) ; | |
232 | } | |
233 | ||
234 | #if TARGET_CARBON | |
235 | c2pstrcpy( (StringPtr) maclabel , c_text ) ; | |
236 | #else | |
237 | strcpy( (char *) maclabel , c_text ) ; | |
238 | c2pstr( (char *) maclabel ) ; | |
239 | #endif | |
240 | } | |
241 | ||
242 | void wxControl::MacPostControlCreate() | |
243 | { | |
244 | wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ; | |
245 | ||
246 | if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) | |
247 | { | |
248 | // no font | |
249 | } | |
250 | else if ( IsKindOf( CLASSINFO( wxStaticBox ) ) || IsKindOf( CLASSINFO( wxRadioBox ) ) || IsKindOf( CLASSINFO( wxButton ) ) ) | |
251 | { | |
252 | ControlFontStyleRec controlstyle ; | |
253 | controlstyle.flags = kControlUseFontMask ; | |
254 | controlstyle.font = kControlFontSmallBoldSystemFont ; | |
255 | ||
256 | ::UMASetControlFontStyle( m_macControl , &controlstyle ) ; | |
257 | } | |
258 | else | |
259 | { | |
260 | ControlFontStyleRec controlstyle ; | |
261 | controlstyle.flags = kControlUseFontMask ; | |
262 | controlstyle.font = kControlFontSmallSystemFont ; | |
263 | ||
264 | ::UMASetControlFontStyle( m_macControl , &controlstyle ) ; | |
265 | } | |
266 | ControlHandle container = GetParent()->MacGetContainerForEmbedding() ; | |
267 | wxASSERT_MSG( container != NULL , "No valid mac container control" ) ; | |
268 | ::UMAEmbedControl( m_macControl , container ) ; | |
269 | MacAdjustControlRect() ; | |
270 | wxAssociateControlWithMacControl( m_macControl , this ) ; | |
271 | } | |
272 | ||
273 | void wxControl::MacAdjustControlRect() | |
274 | { | |
275 | wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ; | |
276 | if ( m_width == -1 || m_height == -1 ) | |
277 | { | |
278 | Rect bestsize = { 0 , 0 , 0 , 0 } ; | |
279 | short baselineoffset ; | |
280 | ||
281 | UMAGetBestControlRect( m_macControl , &bestsize , &baselineoffset ) ; | |
282 | ||
283 | if ( EmptyRect( &bestsize ) ) | |
284 | { | |
285 | baselineoffset = 0; | |
286 | bestsize.left = bestsize.top = 0 ; | |
287 | bestsize.right = 16 ; | |
288 | bestsize.bottom = 16 ; | |
289 | if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) | |
290 | { | |
291 | bestsize.bottom = 16 ; | |
292 | } | |
293 | else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) | |
294 | { | |
295 | bestsize.bottom = 24 ; | |
296 | } | |
297 | } | |
298 | ||
299 | if ( m_width == -1 ) | |
300 | { | |
301 | if ( IsKindOf( CLASSINFO( wxButton ) ) ) | |
302 | { | |
303 | m_width = m_label.Length() * 8 + 12 ; | |
304 | } | |
305 | else if ( IsKindOf( CLASSINFO( wxStaticText ) ) ) | |
306 | { | |
307 | m_width = m_label.Length() * 8 ; | |
308 | } | |
309 | else | |
310 | m_width = bestsize.right - bestsize.left ; | |
311 | ||
312 | m_width += 2 * m_macHorizontalBorder ; | |
313 | } | |
314 | if ( m_height == -1 ) | |
315 | { | |
316 | m_height = bestsize.bottom - bestsize.top ; | |
317 | if ( m_height < 10 ) | |
318 | m_height = 13 ; | |
319 | ||
320 | m_height += 2 * m_macVerticalBorder; | |
321 | } | |
322 | ||
323 | wxMacDrawingHelper helper ( wxFindWinFromMacWindow( GetMacRootWindow() ) ) ; | |
324 | if ( helper.Ok() ) | |
325 | { | |
326 | UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ; | |
327 | } | |
328 | } | |
329 | } | |
330 | ControlHandle wxControl::MacGetContainerForEmbedding() | |
331 | { | |
332 | if ( m_macControl ) | |
333 | return m_macControl ; | |
334 | ||
335 | return wxWindow::MacGetContainerForEmbedding() ; | |
336 | } | |
337 | ||
338 | void wxControl::MacSuperChangedPosition() | |
339 | { | |
340 | if ( m_macControl ) | |
341 | { | |
342 | Rect contrlRect ; | |
343 | GetControlBounds( m_macControl , &contrlRect ) ; | |
344 | int former_mac_x = contrlRect.left ; | |
345 | int former_mac_y = contrlRect.top ; | |
346 | int mac_x = m_x ; | |
347 | int mac_y = m_y ; | |
348 | GetParent()->MacClientToRootWindow( & mac_x , & mac_y ) ; | |
349 | ||
350 | WindowRef rootwindow = GetMacRootWindow() ; | |
351 | wxWindow* wxrootwindow = wxFindWinFromMacWindow( rootwindow ) ; | |
352 | UMASetThemeWindowBackground( rootwindow , kThemeBrushDialogBackgroundActive , false ) ; | |
353 | wxMacDrawingHelper focus( wxrootwindow ) ; | |
354 | ||
355 | if ( mac_x != former_mac_x || mac_y != former_mac_y ) | |
356 | { | |
357 | { | |
358 | Rect inval = { former_mac_y , former_mac_x , former_mac_y + m_height , former_mac_x + m_width } ; | |
359 | InvalWindowRect( rootwindow , &inval ) ; | |
360 | } | |
361 | UMAMoveControl( m_macControl , mac_x + m_macHorizontalBorder , mac_y + m_macVerticalBorder ) ; | |
362 | { | |
363 | Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ; | |
364 | InvalWindowRect( rootwindow , &inval ) ; | |
365 | } | |
366 | } | |
367 | if ( wxrootwindow->IsKindOf( CLASSINFO( wxDialog ) ) ) | |
368 | { | |
369 | } | |
370 | else | |
371 | { | |
372 | UMASetThemeWindowBackground( rootwindow , kThemeBrushDocumentWindowBackground , false ) ; | |
373 | } | |
374 | } | |
375 | ||
376 | wxWindow::MacSuperChangedPosition() ; | |
377 | } | |
378 | ||
379 | void wxControl::MacSuperEnabled( bool enabled ) | |
380 | { | |
381 | /* | |
382 | if ( m_macControl ) | |
383 | { | |
384 | if ( UMAHasAppearance() ) | |
385 | { | |
386 | if ( !enabled ) | |
387 | { | |
388 | ::DeactivateControl( m_macControl ) ; | |
389 | } | |
390 | else | |
391 | { | |
392 | if ( m_macEnabled ) | |
393 | ::ActivateControl( m_macControl ) ; | |
394 | } | |
395 | } | |
396 | else | |
397 | { | |
398 | if ( !enabled ) | |
399 | { | |
400 | ::HiliteControl( m_macControl , 255 ) ; | |
401 | } | |
402 | else | |
403 | { | |
404 | if ( m_macEnabled ) | |
405 | ::HiliteControl( m_macControl , 0 ) ; | |
406 | } | |
407 | } | |
408 | } | |
409 | wxWindow::MacSuperEnabled( enabled ) ; | |
410 | */ | |
411 | } | |
412 | ||
413 | void wxControl::MacSuperShown( bool show ) | |
414 | { | |
415 | if ( m_macControl ) | |
416 | { | |
417 | if ( !show ) | |
418 | { | |
419 | ::UMAHideControl( m_macControl ) ; | |
420 | } | |
421 | else | |
422 | { | |
423 | if ( m_isShown ) | |
424 | ::UMAShowControl( m_macControl ) ; | |
425 | } | |
426 | } | |
427 | ||
428 | wxWindow::MacSuperShown( show ) ; | |
429 | } | |
430 | ||
431 | void wxControl::DoSetSize(int x, int y, | |
432 | int width, int height, | |
433 | int sizeFlags ) | |
434 | { | |
435 | if ( m_macControl == NULL ) | |
436 | { | |
437 | wxWindow::DoSetSize( x , y ,width , height ,sizeFlags ) ; | |
438 | return ; | |
439 | } | |
440 | ||
441 | WindowRef rootwindow = GetMacRootWindow() ; | |
442 | wxWindow* wxrootwindow = wxFindWinFromMacWindow( rootwindow ) ; | |
443 | UMASetThemeWindowBackground( rootwindow , kThemeBrushDialogBackgroundActive , false ) ; | |
444 | ||
445 | int former_x = m_x ; | |
446 | int former_y = m_y ; | |
447 | int former_w = m_width ; | |
448 | int former_h = m_height ; | |
449 | ||
450 | Rect contrlRect ; | |
451 | GetControlBounds( m_macControl , &contrlRect ) ; | |
452 | int former_mac_x = contrlRect.left ; | |
453 | int former_mac_y = contrlRect.top ; | |
454 | ||
455 | int currentX, currentY; | |
456 | GetPosition(¤tX, ¤tY); | |
457 | int currentW,currentH; | |
458 | GetSize(¤tW, ¤tH); | |
459 | ||
460 | int actualWidth = width; | |
461 | int actualHeight = height; | |
462 | int actualX = x; | |
463 | int actualY = y; | |
464 | if (x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
465 | actualX = currentX; | |
466 | if (y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
467 | actualY = currentY; | |
468 | if (width == -1) | |
469 | actualWidth = currentW ; | |
470 | if (height == -1) | |
471 | actualHeight = currentH ; | |
472 | ||
473 | if ( actualX == currentX && actualY == currentY && actualWidth == currentW && actualHeight == currentH) | |
474 | return ; | |
475 | ||
476 | AdjustForParentClientOrigin(actualX, actualY, sizeFlags); | |
477 | WindowRef macrootwindow = GetMacRootWindow() ; | |
478 | wxMacDrawingHelper focus( wxFindWinFromMacWindow( macrootwindow ) ) ; | |
479 | ||
480 | int mac_x = actualX ; | |
481 | int mac_y = actualY ; | |
482 | GetParent()->MacClientToRootWindow( & mac_x , & mac_y ) ; | |
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 + m_height , former_mac_x + m_width } ; | |
488 | InvalWindowRect( macrootwindow, &inval ) ; | |
489 | } | |
490 | UMAMoveControl( m_macControl , mac_x + m_macHorizontalBorder , mac_y + m_macVerticalBorder ) ; | |
491 | { | |
492 | Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ; | |
493 | InvalWindowRect(macrootwindow, &inval ) ; | |
494 | } | |
495 | } | |
496 | ||
497 | if ( actualX != former_x || actualY != former_y ) | |
498 | { | |
499 | m_x = actualX ; | |
500 | m_y = actualY ; | |
501 | ||
502 | MacRepositionScrollBars() ; | |
503 | // To consider -> should the parameters be the effective or the virtual coordinates (AdjustForParent..) | |
504 | wxMoveEvent event(wxPoint(m_x, m_y), m_windowId); | |
505 | event.SetEventObject(this); | |
506 | GetEventHandler()->ProcessEvent(event); | |
507 | } | |
508 | if ( actualWidth != former_w || actualHeight != former_h ) | |
509 | { | |
510 | { | |
511 | Rect inval = { mac_y , mac_x , mac_y + former_h , mac_x + former_w } ; | |
512 | InvalWindowRect( macrootwindow, &inval ) ; | |
513 | } | |
514 | m_width = actualWidth ; | |
515 | m_height = actualHeight ; | |
516 | ||
517 | UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ; | |
518 | { | |
519 | Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ; | |
520 | InvalWindowRect( macrootwindow , &inval ) ; | |
521 | } | |
522 | ||
523 | MacRepositionScrollBars() ; | |
524 | wxSizeEvent event(wxSize(m_width, m_height), m_windowId); | |
525 | event.SetEventObject(this); | |
526 | GetEventHandler()->ProcessEvent(event); | |
527 | } | |
528 | if ( wxrootwindow->IsKindOf( CLASSINFO( wxDialog ) ) ) | |
529 | { | |
530 | } | |
531 | else | |
532 | { | |
533 | UMASetThemeWindowBackground( rootwindow , kThemeBrushDocumentWindowBackground , false ) ; | |
534 | } | |
535 | } | |
536 | ||
537 | bool wxControl::Show(bool show) | |
538 | { | |
539 | if ( !wxWindow::Show( show ) ) | |
540 | return FALSE ; | |
541 | ||
542 | if ( m_macControl ) | |
543 | { | |
544 | if ( show ) | |
545 | ::UMAShowControl( m_macControl ) ; | |
546 | else | |
547 | ::UMAHideControl( m_macControl ) ; | |
548 | } | |
549 | return TRUE ; | |
550 | } | |
551 | ||
552 | bool wxControl::Enable(bool enable) | |
553 | { | |
554 | if ( !wxWindow::Enable(enable) ) | |
555 | return FALSE; | |
556 | ||
557 | if ( m_macControl ) | |
558 | { | |
559 | ||
560 | if ( UMAHasAppearance() ) | |
561 | { | |
562 | if ( enable ) | |
563 | ::ActivateControl( m_macControl ) ; | |
564 | else | |
565 | ::DeactivateControl( m_macControl ) ; | |
566 | } | |
567 | else | |
568 | { | |
569 | if ( enable ) | |
570 | ::HiliteControl( m_macControl , 0 ) ; | |
571 | else | |
572 | ::HiliteControl( m_macControl , 255 ) ; | |
573 | } | |
574 | } | |
575 | return TRUE ; | |
576 | } | |
577 | ||
578 | void wxControl::Refresh(bool eraseBack, const wxRect *rect) | |
579 | { | |
580 | if ( m_macControl ) | |
581 | { | |
582 | wxWindow::Refresh( eraseBack , rect ) ; | |
583 | } | |
584 | else | |
585 | { | |
586 | wxWindow::Refresh( eraseBack , rect ) ; | |
587 | } | |
588 | } | |
589 | ||
590 | void wxControl::MacRedrawControl() | |
591 | { | |
592 | if ( m_macControl ) | |
593 | { | |
594 | WindowRef window = GetMacRootWindow() ; | |
595 | if ( window ) | |
596 | { | |
597 | wxWindow* win = wxFindWinFromMacWindow( window ) ; | |
598 | if ( win ) | |
599 | { | |
600 | wxMacDrawingHelper help( win ) ; | |
601 | // the mac control manager always assumes to have the origin at 0,0 | |
602 | SetOrigin( 0 , 0 ) ; | |
603 | ||
604 | bool hasTabBehind = false ; | |
605 | wxWindow* parent = GetParent() ; | |
606 | while ( parent ) | |
607 | { | |
608 | if( parent->MacGetWindowData() ) | |
609 | { | |
610 | UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ; | |
611 | break ; | |
612 | } | |
613 | ||
614 | if( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) | |
615 | { | |
616 | if ( ((wxControl*)parent)->m_macControl ) | |
617 | SetUpControlBackground( ((wxControl*)parent)->m_macControl , -1 , true ) ; | |
618 | break ; | |
619 | } | |
620 | ||
621 | parent = parent->GetParent() ; | |
622 | } | |
623 | ||
624 | UMADrawControl( m_macControl ) ; | |
625 | UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ; | |
626 | } | |
627 | } | |
628 | } | |
629 | } | |
630 | ||
631 | void wxControl::OnPaint(wxPaintEvent& event) | |
632 | { | |
633 | if ( m_macControl ) | |
634 | { | |
635 | WindowRef window = GetMacRootWindow() ; | |
636 | if ( window ) | |
637 | { | |
638 | wxWindow* win = wxFindWinFromMacWindow( window ) ; | |
639 | if ( win ) | |
640 | { | |
641 | wxMacDrawingHelper help( win ) ; | |
642 | // the mac control manager always assumes to have the origin at 0,0 | |
643 | SetOrigin( 0 , 0 ) ; | |
644 | ||
645 | bool hasTabBehind = false ; | |
646 | wxWindow* parent = GetParent() ; | |
647 | while ( parent ) | |
648 | { | |
649 | if( parent->MacGetWindowData() ) | |
650 | { | |
651 | UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ; | |
652 | break ; | |
653 | } | |
654 | ||
655 | if( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) )) | |
656 | { | |
657 | if ( ((wxControl*)parent)->m_macControl ) | |
658 | SetUpControlBackground( ((wxControl*)parent)->m_macControl , -1 , true ) ; | |
659 | break ; | |
660 | } | |
661 | ||
662 | parent = parent->GetParent() ; | |
663 | } | |
664 | ||
665 | UMADrawControl( m_macControl ) ; | |
666 | UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ; | |
667 | } | |
668 | } | |
669 | } | |
670 | else | |
671 | { | |
672 | // wxWindow::OnPaint( event ) ; | |
673 | } | |
674 | } | |
675 | void wxControl::OnEraseBackground(wxEraseEvent& event) | |
676 | { | |
677 | // In general, you don't want to erase the background of a control, | |
678 | // or you'll get a flicker. | |
679 | // TODO: move this 'null' function into each control that | |
680 | // might flicker. | |
681 | } | |
682 | ||
683 | ||
684 | void wxControl::OnKeyDown( wxKeyEvent &event ) | |
685 | { | |
686 | if ( m_macControl == NULL ) | |
687 | return ; | |
688 | ||
689 | EventRecord *ev = wxTheApp->MacGetCurrentEvent() ; | |
690 | short keycode ; | |
691 | short keychar ; | |
692 | keychar = short(ev->message & charCodeMask); | |
693 | keycode = short(ev->message & keyCodeMask) >> 8 ; | |
694 | ||
695 | UMAHandleControlKey( m_macControl , keycode , keychar , ev->modifiers ) ; | |
696 | } | |
697 | ||
698 | void wxControl::OnMouseEvent( wxMouseEvent &event ) | |
699 | { | |
700 | if ( m_macControl == NULL ) | |
701 | { | |
702 | event.Skip() ; | |
703 | return ; | |
704 | } | |
705 | ||
706 | if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK ) | |
707 | { | |
708 | ||
709 | int x = event.m_x ; | |
710 | int y = event.m_y ; | |
711 | ||
712 | MacClientToRootWindow( &x , &y ) ; | |
713 | ||
714 | ControlHandle control ; | |
715 | Point localwhere ; | |
716 | GrafPtr port ; | |
717 | SInt16 controlpart ; | |
718 | WindowRef window = GetMacRootWindow() ; | |
719 | ||
720 | localwhere.h = x ; | |
721 | localwhere.v = y ; | |
722 | ||
723 | short modifiers = 0; | |
724 | ||
725 | if ( !event.m_leftDown && !event.m_rightDown ) | |
726 | modifiers |= btnState ; | |
727 | ||
728 | if ( event.m_shiftDown ) | |
729 | modifiers |= shiftKey ; | |
730 | ||
731 | if ( event.m_controlDown ) | |
732 | modifiers |= controlKey ; | |
733 | ||
734 | if ( event.m_altDown ) | |
735 | modifiers |= optionKey ; | |
736 | ||
737 | if ( event.m_metaDown ) | |
738 | modifiers |= cmdKey ; | |
739 | ||
740 | controlpart = FindControl( localwhere , window , &control ) ; | |
741 | { | |
742 | if ( AcceptsFocus() && FindFocus() != this ) | |
743 | { | |
744 | SetFocus() ; | |
745 | } | |
746 | if ( control && UMAIsControlActive( control ) ) | |
747 | { | |
748 | { | |
749 | if ( controlpart == kControlIndicatorPart && !UMAHasAppearance() ) | |
750 | controlpart = UMAHandleControlClick( control , localwhere , modifiers , (ControlActionUPP) NULL ) ; | |
751 | else | |
752 | controlpart = UMAHandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ; | |
753 | wxTheApp->s_lastMouseDown = 0 ; | |
754 | if ( controlpart && ! ( ( UMAHasAppearance() || (controlpart != kControlIndicatorPart) ) | |
755 | && (IsKindOf( CLASSINFO( wxScrollBar ) ) ) ) ) // otherwise we will get the event twice | |
756 | { | |
757 | MacHandleControlClick( control , controlpart ) ; | |
758 | } | |
759 | } | |
760 | } | |
761 | } | |
762 | } | |
763 | } | |
764 | ||
765 | bool wxControl::MacCanFocus() const | |
766 | { | |
767 | { if ( m_macControl == NULL ) | |
768 | return true ; | |
769 | else | |
770 | return false ; | |
771 | } | |
772 | } | |
773 | ||
774 | void wxControl::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) | |
775 | { | |
776 | wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ; | |
777 | } | |
778 |