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