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