]> git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/control.cpp
Override GetPixelSize on OS X as the base impl creates a wxScreenDC each time, which...
[wxWidgets.git] / src / mac / classic / control.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/control.cpp
3 // Purpose: wxControl class
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #include "wx/control.h"
19
20 #ifndef WX_PRECOMP
21 #include "wx/app.h"
22 #include "wx/panel.h"
23 #include "wx/dc.h"
24 #include "wx/dcclient.h"
25 #include "wx/button.h"
26 #include "wx/dialog.h"
27 #include "wx/scrolbar.h"
28 #include "wx/stattext.h"
29 #include "wx/statbox.h"
30 #include "wx/radiobox.h"
31 #include "wx/sizer.h"
32 #endif // WX_PRECOMP
33
34 #include "wx/notebook.h"
35 #include "wx/tabctrl.h"
36 #include "wx/spinbutt.h"
37
38 IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
39
40 BEGIN_EVENT_TABLE(wxControl, wxWindow)
41 EVT_MOUSE_EVENTS( wxControl::OnMouseEvent )
42 EVT_PAINT( wxControl::OnPaint )
43 END_EVENT_TABLE()
44
45 #include "wx/mac/uma.h"
46 #include "wx/mac/private.h"
47
48 // Item members
49
50
51 #if PRAGMA_STRUCT_ALIGN
52 #pragma options align=mac68k
53 #elif PRAGMA_STRUCT_PACKPUSH
54 #pragma pack(push, 2)
55 #elif PRAGMA_STRUCT_PACK
56 #pragma pack(2)
57 #endif
58
59 typedef struct {
60 unsigned short instruction;
61 void (*function)();
62 } cdefRec, *cdefPtr, **cdefHandle;
63
64 #if PRAGMA_STRUCT_ALIGN
65 #pragma options align=reset
66 #elif PRAGMA_STRUCT_PACKPUSH
67 #pragma pack(pop)
68 #elif PRAGMA_STRUCT_PACK
69 #pragma pack()
70 #endif
71
72 ControlActionUPP wxMacLiveScrollbarActionUPP = NULL ;
73 wxControl *wxFindControlFromMacControl(ControlHandle inControl ) ;
74
75 pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode ) ;
76 pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode )
77 {
78 if ( partCode != 0)
79 {
80 wxControl* wx = (wxControl*) GetControlReference( control ) ;
81 if ( wx )
82 {
83 wx->MacHandleControlClick( (WXWidget) control , partCode , true /* stillDown */ ) ;
84 }
85 }
86 }
87
88 ControlColorUPP wxMacSetupControlBackgroundUPP = NULL ;
89 ControlDefUPP wxMacControlActionUPP = NULL ;
90
91 pascal SInt32 wxMacControlDefinition(SInt16 varCode, ControlRef theControl, ControlDefProcMessage message, SInt32 param)
92 {
93
94 wxControl* wx = (wxControl*) wxFindControlFromMacControl( theControl ) ;
95 if ( wx != NULL && wx->IsKindOf( CLASSINFO( wxControl ) ) )
96 {
97 if( message == drawCntl )
98 {
99 wxMacWindowClipper clip( wx ) ;
100 return InvokeControlDefUPP( varCode , theControl , message , param , (ControlDefUPP) wx->MacGetControlAction() ) ;
101 }
102 else
103 return InvokeControlDefUPP( varCode , theControl , message , param , (ControlDefUPP) wx->MacGetControlAction() ) ;
104 }
105 return NULL ;
106 }
107
108 pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessage , SInt16 iDepth , Boolean iIsColor )
109 {
110 OSStatus status = noErr ;
111 switch( iMessage )
112 {
113 case kControlMsgSetUpBackground :
114 {
115 wxControl* wx = (wxControl*) GetControlReference( iControl ) ;
116 if ( wx != NULL && wx->IsKindOf( CLASSINFO( wxControl ) ) )
117 {
118 wxDC::MacSetupBackgroundForCurrentPort( wx->MacGetBackgroundBrush() ) ;
119 #if TARGET_CARBON
120 // under classic this would lead to partial redraws
121 RgnHandle clip = NewRgn() ;
122 int x = 0 , y = 0;
123
124 wx->MacWindowToRootWindow( &x,&y ) ;
125 CopyRgn( (RgnHandle) wx->MacGetVisibleRegion(false).GetWXHRGN() , clip ) ;
126 OffsetRgn( clip , x , y ) ;
127 SetClip( clip ) ;
128 DisposeRgn( clip ) ;
129 #endif
130 }
131 else
132 {
133 status = paramErr ;
134 }
135 }
136 break ;
137 default :
138 status = paramErr ;
139 break ;
140 }
141 return status ;
142 }
143
144 wxControl::wxControl()
145 {
146 m_macControl = NULL ;
147 m_macControlAction = NULL ;
148 m_macHorizontalBorder = 0 ; // additional pixels around the real control
149 m_macVerticalBorder = 0 ;
150 m_backgroundColour = *wxWHITE;
151 m_foregroundColour = *wxBLACK;
152
153 if ( wxMacLiveScrollbarActionUPP == NULL )
154 {
155 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
156 wxMacLiveScrollbarActionUPP = NewControlActionUPP( wxMacLiveScrollbarActionProc );
157 #else
158 wxMacLiveScrollbarActionUPP = NewControlActionProc( wxMacLiveScrollbarActionProc ) ;
159 #endif
160 }
161 }
162
163 bool wxControl::Create(wxWindow *parent, wxWindowID id,
164 const wxPoint& pos,
165 const wxSize& size, long style,
166 const wxValidator& validator,
167 const wxString& name)
168 {
169 m_macControl = NULL ;
170 m_macHorizontalBorder = 0 ; // additional pixels around the real control
171 m_macVerticalBorder = 0 ;
172
173 bool rval = wxWindow::Create(parent, id, pos, size, style, name);
174 if ( parent )
175 {
176 m_backgroundColour = parent->GetBackgroundColour() ;
177 m_foregroundColour = parent->GetForegroundColour() ;
178 }
179 if (rval) {
180 #if wxUSE_VALIDATORS
181 SetValidator(validator);
182 #endif
183 }
184 return rval;
185 }
186
187 wxControl::~wxControl()
188 {
189 m_isBeingDeleted = true;
190 wxRemoveMacControlAssociation( this ) ;
191 // If we delete an item, we should initialize the parent panel,
192 // because it could now be invalid.
193 wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
194 if ( tlw )
195 {
196 if ( tlw->GetDefaultItem() == (wxButton*) this)
197 tlw->SetDefaultItem(NULL);
198 }
199 if ( (ControlHandle) m_macControl )
200 {
201 // in case the callback might be called during destruction
202 ::SetControlColorProc( (ControlHandle) m_macControl , NULL ) ;
203 ::DisposeControl( (ControlHandle) m_macControl ) ;
204 m_macControl = NULL ;
205 }
206 }
207
208 void wxControl::SetLabel(const wxString& title)
209 {
210 m_label = GetLabelText(title) ;
211
212 if ( m_macControl )
213 {
214 UMASetControlTitle( (ControlHandle) m_macControl , m_label , m_font.GetEncoding() ) ;
215 }
216 Refresh() ;
217 }
218
219 wxSize wxControl::DoGetBestSize() const
220 {
221 if ( (ControlHandle) m_macControl == NULL )
222 return wxWindow::DoGetBestSize() ;
223
224 Rect bestsize = { 0 , 0 , 0 , 0 } ;
225 short baselineoffset ;
226 int bestWidth, bestHeight ;
227 ::GetBestControlRect( (ControlHandle) m_macControl , &bestsize , &baselineoffset ) ;
228
229 if ( EmptyRect( &bestsize ) )
230 {
231 baselineoffset = 0;
232 bestsize.left = bestsize.top = 0 ;
233 bestsize.right = 16 ;
234 bestsize.bottom = 16 ;
235 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
236 {
237 bestsize.bottom = 16 ;
238 }
239 else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
240 {
241 bestsize.bottom = 24 ;
242 }
243 }
244
245 bestWidth = bestsize.right - bestsize.left ;
246
247 bestWidth += 2 * m_macHorizontalBorder ;
248
249 bestHeight = bestsize.bottom - bestsize.top ;
250 if ( bestHeight < 10 )
251 bestHeight = 13 ;
252
253 bestHeight += 2 * m_macVerticalBorder;
254
255
256 return wxSize(bestWidth, bestHeight);
257 }
258
259 bool wxControl::ProcessCommand (wxCommandEvent & event)
260 {
261 // Tries:
262 // 1) OnCommand, starting at this window and working up parent hierarchy
263 // 2) OnCommand then calls ProcessEvent to search the event tables.
264 return GetEventHandler()->ProcessEvent(event);
265 }
266
267 // ------------------------
268 wxList *wxWinMacControlList = NULL;
269 wxControl *wxFindControlFromMacControl(ControlHandle inControl )
270 {
271 wxNode *node = wxWinMacControlList->Find((long)inControl);
272 if (!node)
273 return NULL;
274 return (wxControl *)node->GetData();
275 }
276
277 void wxAssociateControlWithMacControl(ControlHandle inControl, wxControl *control)
278 {
279 // adding NULL WindowRef is (first) surely a result of an error and
280 // (secondly) breaks menu command processing
281 wxCHECK_RET( inControl != (ControlHandle) NULL, wxT("attempt to add a NULL WindowRef to window list") );
282
283 if ( !wxWinMacControlList->Find((long)inControl) )
284 wxWinMacControlList->Append((long)inControl, control);
285 }
286
287 void wxRemoveMacControlAssociation(wxControl *control)
288 {
289 if ( wxWinMacControlList )
290 wxWinMacControlList->DeleteObject(control);
291 }
292
293 void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString label ,
294 const wxPoint& pos,
295 const wxSize& size, long style,
296 const wxValidator& validator,
297 const wxString& name , WXRECTPTR outBounds , unsigned char* maclabel )
298 {
299 m_label = label ;
300
301 // These sizes will be adjusted in MacPostControlCreate
302 m_width = size.x ;
303 m_height = size.y ;
304 m_x = pos.x ;
305 m_y = pos.y ;
306
307 ((Rect*)outBounds)->top = -10;
308 ((Rect*)outBounds)->left = -10;
309 ((Rect*)outBounds)->bottom = 0;
310 ((Rect*)outBounds)->right = 0;
311
312 wxMacStringToPascal( GetLabelText(label) , maclabel ) ;
313 }
314
315 void wxControl::MacPostControlCreate()
316 {
317 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
318 DoSetWindowVariant( m_windowVariant ) ;
319 /*
320 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
321 {
322 // no font
323 }
324 else if ( !UMAHasAquaLayout() && (IsKindOf( CLASSINFO( wxStaticBox ) ) || IsKindOf( CLASSINFO( wxRadioBox ) ) || IsKindOf( CLASSINFO( wxButton ) ) ) )
325 {
326 ControlFontStyleRec controlstyle ;
327 controlstyle.flags = kControlUseFontMask ;
328 controlstyle.font = kControlFontSmallBoldSystemFont ;
329
330 ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ;
331 }
332 else
333 {
334 ControlFontStyleRec controlstyle ;
335 controlstyle.flags = kControlUseFontMask ;
336
337 if (IsKindOf( CLASSINFO( wxButton ) ) )
338 controlstyle.font = kControlFontBigSystemFont ; // eventually kControlFontBigSystemFont ;
339 else
340 controlstyle.font = kControlFontSmallSystemFont ;
341
342 ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ;
343 }
344 */
345 ControlHandle container = (ControlHandle) GetParent()->MacGetContainerForEmbedding() ;
346 wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
347 ::EmbedControl( (ControlHandle) m_macControl , container ) ;
348 m_macControlIsShown = MacIsReallyShown() ;
349
350 wxAssociateControlWithMacControl( (ControlHandle) m_macControl , this ) ;
351 if ( wxMacSetupControlBackgroundUPP == NULL )
352 {
353 wxMacSetupControlBackgroundUPP = NewControlColorUPP( wxMacSetupControlBackground ) ;
354 }
355 if ( wxMacControlActionUPP == NULL )
356 {
357 wxMacControlActionUPP = NewControlDefUPP( wxMacControlDefinition ) ;
358 }
359 // The following block of code is responsible for crashes when switching
360 // back to windows, which can be seen in the dialogs sample.
361 // It is disabled until a proper solution can be found.
362 #if 0
363 #if TARGET_CARBON
364 /*
365 only working under classic carbon
366 m_macControlAction = *(**(ControlHandle)m_macControl).contrlDefProc ;
367 (**(ControlHandle)m_macControl).contrlDefProc = (Handle) &wxMacControlActionUPP ;
368 */
369 #else
370 m_macControlAction = *(**(ControlHandle)m_macControl).contrlDefProc ;
371
372 cdefHandle cdef ;
373 cdef = (cdefHandle) NewHandle( sizeof(cdefRec) ) ;
374 if ( (**(ControlHandle)m_macControl).contrlDefProc != NULL )
375 {
376 (**cdef).instruction = 0x4EF9; /* JMP instruction */
377 (**cdef).function = (void(*)()) wxMacControlActionUPP;
378 (**(ControlHandle)m_macControl).contrlDefProc = (Handle) cdef ;
379 }
380 #endif
381 #endif
382 SetControlColorProc( (ControlHandle) m_macControl , wxMacSetupControlBackgroundUPP ) ;
383
384 // Adjust the controls size and position
385 wxPoint pos(m_x, m_y);
386 wxSize best_size( DoGetBestSize() );
387 wxSize new_size( m_width, m_height );
388
389 m_x = m_y = m_width = m_height = -1; // Forces SetSize to move/size the control
390
391 if (new_size.x == -1) {
392 new_size.x = best_size.x;
393 }
394 if (new_size.y == -1) {
395 new_size.y = best_size.y;
396 }
397
398 SetSize(pos.x, pos.y, new_size.x, new_size.y);
399
400 #if wxUSE_UNICODE
401 UMASetControlTitle( (ControlHandle) m_macControl , GetLabelText(m_label) , m_font.GetEncoding() ) ;
402 #endif
403
404 if ( m_macControlIsShown )
405 UMAShowControl( (ControlHandle) m_macControl ) ;
406
407 SetCursor( *wxSTANDARD_CURSOR ) ;
408
409 Refresh() ;
410 }
411
412 void wxControl::MacAdjustControlRect()
413 {
414 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
415 if ( m_width == -1 || m_height == -1 )
416 {
417 Rect bestsize = { 0 , 0 , 0 , 0 } ;
418 short baselineoffset ;
419
420 ::GetBestControlRect( (ControlHandle) m_macControl , &bestsize , &baselineoffset ) ;
421
422 if ( EmptyRect( &bestsize ) )
423 {
424 baselineoffset = 0;
425 bestsize.left = bestsize.top = 0 ;
426 bestsize.right = 16 ;
427 bestsize.bottom = 16 ;
428 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
429 {
430 bestsize.bottom = 16 ;
431 }
432 else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
433 {
434 bestsize.bottom = 24 ;
435 }
436 }
437
438 if ( m_width == -1 )
439 {
440 if ( IsKindOf( CLASSINFO( wxButton ) ) )
441 {
442 m_width = m_label.length() * 8 + 12 ;
443 if ( m_width < 70 )
444 m_width = 70 ;
445 }
446 else if ( IsKindOf( CLASSINFO( wxStaticText ) ) )
447 {
448 m_width = m_label.length() * 8 ;
449 }
450 else
451 m_width = bestsize.right - bestsize.left ;
452
453 m_width += 2 * m_macHorizontalBorder + MacGetLeftBorderSize() + MacGetRightBorderSize() ;
454 }
455 if ( m_height == -1 )
456 {
457 m_height = bestsize.bottom - bestsize.top ;
458 if ( m_height < 10 )
459 m_height = 13 ;
460
461 m_height += 2 * m_macVerticalBorder + MacGetTopBorderSize() + MacGetBottomBorderSize() ;
462 }
463 MacUpdateDimensions() ;
464 }
465 }
466
467 WXWidget wxControl::MacGetContainerForEmbedding()
468 {
469 if ( m_macControl )
470 return m_macControl ;
471
472 return wxWindow::MacGetContainerForEmbedding() ;
473 }
474
475 void wxControl::MacUpdateDimensions()
476 {
477 // actually in the current systems this should never be possible, but later reparenting
478 // may become a reality
479
480 if ( (ControlHandle) m_macControl == NULL )
481 return ;
482
483 if ( GetParent() == NULL )
484 return ;
485
486 WindowRef rootwindow = (WindowRef) MacGetRootWindow() ;
487 if ( rootwindow == NULL )
488 return ;
489
490 Rect oldBounds ;
491 GetControlBounds( (ControlHandle) m_macControl , &oldBounds ) ;
492
493 int new_x = m_x + MacGetLeftBorderSize() + m_macHorizontalBorder ;
494 int new_y = m_y + MacGetTopBorderSize() + m_macVerticalBorder ;
495 int new_width = m_width - MacGetLeftBorderSize() - MacGetRightBorderSize() - 2 * m_macHorizontalBorder ;
496 int new_height = m_height - MacGetTopBorderSize() - MacGetBottomBorderSize() - 2 * m_macVerticalBorder ;
497
498 GetParent()->MacWindowToRootWindow( & new_x , & new_y ) ;
499 bool doMove = new_x != oldBounds.left || new_y != oldBounds.top ;
500 bool doResize = ( oldBounds.right - oldBounds.left ) != new_width || (oldBounds.bottom - oldBounds.top ) != new_height ;
501 if ( doMove || doResize )
502 {
503 InvalWindowRect( rootwindow, &oldBounds ) ;
504 if ( doMove )
505 {
506 UMAMoveControl( (ControlHandle) m_macControl , new_x , new_y ) ;
507 }
508 if ( doResize )
509 {
510 UMASizeControl( (ControlHandle) m_macControl , new_width , new_height ) ;
511 }
512 }
513 }
514
515 void wxControl::MacSuperChangedPosition()
516 {
517 MacUpdateDimensions() ;
518 wxWindow::MacSuperChangedPosition() ;
519 }
520
521 void wxControl::MacSuperEnabled( bool enabled )
522 {
523 Refresh(false) ;
524 wxWindow::MacSuperEnabled( enabled ) ;
525 }
526
527 void wxControl::MacSuperShown( bool show )
528 {
529 if ( (ControlHandle) m_macControl )
530 {
531 if ( !show )
532 {
533 if ( m_macControlIsShown )
534 {
535 ::UMAHideControl( (ControlHandle) m_macControl ) ;
536 m_macControlIsShown = false ;
537 }
538 }
539 else
540 {
541 if ( MacIsReallyShown() && !m_macControlIsShown )
542 {
543 ::UMAShowControl( (ControlHandle) m_macControl ) ;
544 m_macControlIsShown = true ;
545 }
546 }
547 }
548
549 wxWindow::MacSuperShown( show ) ;
550 }
551
552 void wxControl::DoSetSize(int x, int y,
553 int width, int height,
554 int sizeFlags )
555 {
556 wxWindow::DoSetSize( x , y ,width , height ,sizeFlags ) ;
557 #if 0
558 {
559 Rect meta , control ;
560 GetControlBounds( (ControlHandle) m_macControl , &control ) ;
561 RgnHandle rgn = NewRgn() ;
562 GetControlRegion( (ControlHandle) m_macControl , kControlStructureMetaPart , rgn ) ;
563 GetRegionBounds( rgn , &meta ) ;
564 if ( !EmptyRect( &meta ) )
565 {
566 wxASSERT( meta.left >= control.left - m_macHorizontalBorder ) ;
567 wxASSERT( meta.right <= control.right + m_macHorizontalBorder ) ;
568 wxASSERT( meta.top >= control.top - m_macVerticalBorder ) ;
569 wxASSERT( meta.bottom <= control.bottom + m_macVerticalBorder ) ;
570 }
571 DisposeRgn( rgn ) ;
572 }
573 #endif
574 return ;
575 }
576
577 bool wxControl::Show(bool show)
578 {
579 if ( !wxWindow::Show( show ) )
580 return false ;
581
582 if ( (ControlHandle) m_macControl )
583 {
584 if ( !show )
585 {
586 if ( m_macControlIsShown )
587 {
588 ::UMAHideControl( (ControlHandle) m_macControl ) ;
589 m_macControlIsShown = false ;
590 }
591 }
592 else
593 {
594 if ( MacIsReallyShown() && !m_macControlIsShown )
595 {
596 ::UMAShowControl( (ControlHandle) m_macControl ) ;
597 m_macControlIsShown = true ;
598 }
599 }
600 }
601 return true ;
602 }
603
604 bool wxControl::Enable(bool enable)
605 {
606 if ( !wxWindow::Enable(enable) )
607 return false;
608
609 if ( (ControlHandle) m_macControl )
610 {
611 if ( enable )
612 UMAActivateControl( (ControlHandle) m_macControl ) ;
613 else
614 UMADeactivateControl( (ControlHandle) m_macControl ) ;
615 }
616 return true ;
617 }
618
619 void wxControl::Refresh(bool eraseBack, const wxRect *rect)
620 {
621 wxWindow::Refresh( eraseBack , rect ) ;
622 }
623
624 void wxControl::MacRedrawControl()
625 {
626 if ( (ControlHandle) m_macControl && MacGetRootWindow() && m_macControlIsShown )
627 {
628 wxClientDC dc(this) ;
629 wxMacPortSetter helper(&dc) ;
630 wxMacWindowClipper clipper(this) ;
631 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
632 UMADrawControl( (ControlHandle) m_macControl ) ;
633 }
634 }
635
636 void wxControl::OnPaint(wxPaintEvent& event)
637 {
638 if ( (ControlHandle) m_macControl )
639 {
640 wxPaintDC dc(this) ;
641 wxMacPortSetter helper(&dc) ;
642 wxMacWindowClipper clipper(this) ;
643 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
644 UMADrawControl( (ControlHandle) m_macControl ) ;
645 }
646 else
647 {
648 event.Skip() ;
649 }
650 }
651 void wxControl::OnEraseBackground(wxEraseEvent& event)
652 {
653 wxWindow::OnEraseBackground( event ) ;
654 }
655
656 void wxControl::OnKeyDown( wxKeyEvent &event )
657 {
658 if ( (ControlHandle) m_macControl == NULL )
659 return ;
660
661 #if TARGET_CARBON
662
663 char charCode ;
664 UInt32 keyCode ;
665 UInt32 modifiers ;
666
667 GetEventParameter( (EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode );
668 GetEventParameter( (EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode );
669 GetEventParameter((EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers);
670
671 ::HandleControlKey( (ControlHandle) m_macControl , keyCode , charCode , modifiers ) ;
672
673 #else
674 EventRecord *ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ;
675 short keycode ;
676 short keychar ;
677 keychar = short(ev->message & charCodeMask);
678 keycode = short(ev->message & keyCodeMask) >> 8 ;
679
680 ::HandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers ) ;
681 #endif
682 }
683
684 void wxControl::OnMouseEvent( wxMouseEvent &event )
685 {
686 if ( (ControlHandle) m_macControl == NULL )
687 {
688 event.Skip() ;
689 return ;
690 }
691
692 if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK )
693 {
694
695 int x = event.m_x ;
696 int y = event.m_y ;
697
698 MacClientToRootWindow( &x , &y ) ;
699
700 ControlHandle control ;
701 Point localwhere ;
702 SInt16 controlpart ;
703
704 localwhere.h = x ;
705 localwhere.v = y ;
706
707 short modifiers = 0;
708
709 if ( !event.m_leftDown && !event.m_rightDown )
710 modifiers |= btnState ;
711
712 if ( event.m_shiftDown )
713 modifiers |= shiftKey ;
714
715 if ( event.m_controlDown )
716 modifiers |= controlKey ;
717
718 if ( event.m_altDown )
719 modifiers |= optionKey ;
720
721 if ( event.m_metaDown )
722 modifiers |= cmdKey ;
723 {
724 control = (ControlHandle) m_macControl ;
725 if ( control && ::IsControlActive( control ) )
726 {
727 {
728 controlpart = ::HandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ;
729 wxTheApp->s_lastMouseDown = 0 ;
730 if ( control && controlpart != kControlNoPart )
731 {
732 MacHandleControlClick( (WXWidget) control , controlpart , false /* mouse not down anymore */ ) ;
733 }
734 }
735 }
736 }
737 }
738 else
739 {
740 event.Skip() ;
741 }
742 }
743
744 bool wxControl::MacCanFocus() const
745 {
746 if ( (ControlHandle) m_macControl == NULL )
747 return true ;
748 else
749 return false ;
750 }
751
752 void wxControl::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) )
753 {
754 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
755 }
756
757 void wxControl::DoSetWindowVariant( wxWindowVariant variant )
758 {
759 if ( m_macControl == NULL )
760 {
761 wxWindow::SetWindowVariant( variant ) ;
762 return ;
763
764 }
765 m_windowVariant = variant ;
766
767 ControlSize size ;
768 ControlFontStyleRec fontStyle;
769 fontStyle.flags = kControlUseFontMask ;
770
771 // we will get that from the settings later
772 // and make this NORMAL later, but first
773 // we have a few calculations that we must fix
774
775 if ( variant == wxWINDOW_VARIANT_NORMAL )
776 {
777 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
778 variant = wxWINDOW_VARIANT_NORMAL ;
779 else
780 variant = wxWINDOW_VARIANT_SMALL ;
781 }
782
783 switch ( variant )
784 {
785 case wxWINDOW_VARIANT_NORMAL :
786 size = kControlSizeNormal;
787 fontStyle.font = kControlFontBigSystemFont;
788 break ;
789 case wxWINDOW_VARIANT_SMALL :
790 size = kControlSizeSmall;
791 fontStyle.font = kControlFontSmallSystemFont;
792 break ;
793 case wxWINDOW_VARIANT_MINI :
794 if (UMAGetSystemVersion() >= 0x1030 )
795 {
796 size = 3 ; // not always defined in the header
797 fontStyle.font = -5 ; // not always defined in the header
798 }
799 else
800 {
801 size = kControlSizeSmall;
802 fontStyle.font = kControlFontSmallSystemFont;
803 }
804 break;
805 break ;
806 case wxWINDOW_VARIANT_LARGE :
807 size = kControlSizeLarge;
808 fontStyle.font = kControlFontBigSystemFont;
809 break ;
810 default:
811 wxFAIL_MSG(_T("unexpected window variant"));
812 break ;
813 }
814 ::SetControlData( (ControlHandle) m_macControl , kControlEntireControl, kControlSizeTag, sizeof( ControlSize ), &size );
815 ::SetControlFontStyle( (ControlHandle) m_macControl , &fontStyle );
816 }