]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/control.cpp
moved drawing to isvisible branch only
[wxWidgets.git] / src / mac / carbon / 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( 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 ::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 ) ;
211 }
212 Refresh() ;
213 }
214
215 wxSize wxControl::DoGetBestSize() const
216 {
217 Rect bestsize = { 0 , 0 , 0 , 0 } ;
218 short baselineoffset ;
219 int bestWidth, bestHeight ;
220 ::GetBestControlRect( (ControlHandle) m_macControl , &bestsize , &baselineoffset ) ;
221
222 if ( EmptyRect( &bestsize ) )
223 {
224 baselineoffset = 0;
225 bestsize.left = bestsize.top = 0 ;
226 bestsize.right = 16 ;
227 bestsize.bottom = 16 ;
228 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
229 {
230 bestsize.bottom = 16 ;
231 }
232 else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
233 {
234 bestsize.bottom = 24 ;
235 }
236 }
237
238 if ( IsKindOf( CLASSINFO( wxButton ) ) )
239 {
240 bestWidth = m_label.Length() * 8 + 12 ;
241 if ( bestWidth < 70 )
242 bestWidth = 70 ;
243 }
244 else if ( IsKindOf( CLASSINFO( wxStaticText ) ) )
245 {
246 bestWidth = m_label.Length() * 8 ;
247 }
248 else
249 bestWidth = bestsize.right - bestsize.left ;
250
251 bestWidth += 2 * m_macHorizontalBorder ;
252
253 bestHeight = bestsize.bottom - bestsize.top ;
254 if ( bestHeight < 10 )
255 bestHeight = 13 ;
256
257 bestHeight += 2 * m_macVerticalBorder;
258
259
260 return wxSize(bestWidth, bestHeight);
261 }
262
263 bool wxControl::ProcessCommand (wxCommandEvent & event)
264 {
265 // Tries:
266 // 1) OnCommand, starting at this window and working up parent hierarchy
267 // 2) OnCommand then calls ProcessEvent to search the event tables.
268 return GetEventHandler()->ProcessEvent(event);
269 }
270
271 // ------------------------
272 wxList *wxWinMacControlList = NULL;
273 wxControl *wxFindControlFromMacControl(ControlHandle inControl )
274 {
275 wxNode *node = wxWinMacControlList->Find((long)inControl);
276 if (!node)
277 return NULL;
278 return (wxControl *)node->GetData();
279 }
280
281 void wxAssociateControlWithMacControl(ControlHandle inControl, wxControl *control)
282 {
283 // adding NULL WindowRef is (first) surely a result of an error and
284 // (secondly) breaks menu command processing
285 wxCHECK_RET( inControl != (ControlHandle) NULL, wxT("attempt to add a NULL WindowRef to window list") );
286
287 if ( !wxWinMacControlList->Find((long)inControl) )
288 wxWinMacControlList->Append((long)inControl, control);
289 }
290
291 void wxRemoveMacControlAssociation(wxControl *control)
292 {
293 if ( wxWinMacControlList )
294 wxWinMacControlList->DeleteObject(control);
295 }
296
297 void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString label ,
298 const wxPoint& pos,
299 const wxSize& size, long style,
300 const wxValidator& validator,
301 const wxString& name , WXRECTPTR outBounds , unsigned char* maclabel )
302 {
303 m_label = label ;
304
305 // These sizes will be adjusted in MacPostControlCreate
306 m_width = size.x ;
307 m_height = size.y ;
308 m_x = pos.x ;
309 m_y = pos.y ;
310
311 ((Rect*)outBounds)->top = -10;
312 ((Rect*)outBounds)->left = -10;
313 ((Rect*)outBounds)->bottom = 0;
314 ((Rect*)outBounds)->right = 0;
315
316 wxMacStringToPascal( wxStripMenuCodes(label) , maclabel ) ;
317 }
318
319 void wxControl::MacPostControlCreate()
320 {
321 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
322
323 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
324 {
325 // no font
326 }
327 else if ( !UMAHasAquaLayout() && (IsKindOf( CLASSINFO( wxStaticBox ) ) || IsKindOf( CLASSINFO( wxRadioBox ) ) || IsKindOf( CLASSINFO( wxButton ) ) ) )
328 {
329 ControlFontStyleRec controlstyle ;
330 controlstyle.flags = kControlUseFontMask ;
331 controlstyle.font = kControlFontSmallBoldSystemFont ;
332
333 ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ;
334 }
335 else
336 {
337 ControlFontStyleRec controlstyle ;
338 controlstyle.flags = kControlUseFontMask ;
339
340 if (IsKindOf( CLASSINFO( wxButton ) ) )
341 controlstyle.font = kControlFontSmallSystemFont ; // eventually kControlFontBigSystemFont ;
342 else
343 controlstyle.font = kControlFontSmallSystemFont ;
344
345 ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ;
346 }
347 ControlHandle container = (ControlHandle) GetParent()->MacGetContainerForEmbedding() ;
348 wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
349 ::EmbedControl( (ControlHandle) m_macControl , container ) ;
350 m_macControlIsShown = MacIsReallyShown() ;
351
352 wxAssociateControlWithMacControl( (ControlHandle) m_macControl , this ) ;
353 if ( wxMacSetupControlBackgroundUPP == NULL )
354 {
355 wxMacSetupControlBackgroundUPP = NewControlColorUPP( wxMacSetupControlBackground ) ;
356 }
357 if ( wxMacControlActionUPP == NULL )
358 {
359 wxMacControlActionUPP = NewControlDefUPP( wxMacControlDefinition ) ;
360 }
361 // The following block of code is responsible for crashes when switching
362 // back to windows, which can be seen in the dialogs sample.
363 // It is disabled until a proper solution can be found.
364 #if 0
365 #if TARGET_CARBON
366 /*
367 only working under classic carbon
368 m_macControlAction = *(**(ControlHandle)m_macControl).contrlDefProc ;
369 (**(ControlHandle)m_macControl).contrlDefProc = (Handle) &wxMacControlActionUPP ;
370 */
371 #else
372 m_macControlAction = *(**(ControlHandle)m_macControl).contrlDefProc ;
373
374 cdefHandle cdef ;
375 cdef = (cdefHandle) NewHandle( sizeof(cdefRec) ) ;
376 if ( (**(ControlHandle)m_macControl).contrlDefProc != NULL )
377 {
378 (**cdef).instruction = 0x4EF9; /* JMP instruction */
379 (**cdef).function = (void(*)()) wxMacControlActionUPP;
380 (**(ControlHandle)m_macControl).contrlDefProc = (Handle) cdef ;
381 }
382 #endif
383 #endif
384 SetControlColorProc( (ControlHandle) m_macControl , wxMacSetupControlBackgroundUPP ) ;
385
386 // Adjust the controls size and position
387 wxPoint pos(m_x, m_y);
388 wxSize best_size( DoGetBestSize() );
389 wxSize new_size( m_width, m_height );
390
391 m_x = m_y = m_width = m_height = -1; // Forces SetSize to move/size the control
392
393 if (new_size.x == -1) {
394 new_size.x = best_size.x;
395 }
396 if (new_size.y == -1) {
397 new_size.y = best_size.y;
398 }
399
400 SetSize(pos.x, pos.y, new_size.x, new_size.y);
401
402 #if wxUSE_UNICODE
403 UMASetControlTitle( (ControlHandle) m_macControl , wxStripMenuCodes(m_label) ) ;
404 #endif
405
406 if ( m_macControlIsShown )
407 UMAShowControl( (ControlHandle) m_macControl ) ;
408
409 SetCursor( *wxSTANDARD_CURSOR ) ;
410
411 Refresh() ;
412 }
413
414 void wxControl::MacAdjustControlRect()
415 {
416 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
417 if ( m_width == -1 || m_height == -1 )
418 {
419 Rect bestsize = { 0 , 0 , 0 , 0 } ;
420 short baselineoffset ;
421
422 ::GetBestControlRect( (ControlHandle) m_macControl , &bestsize , &baselineoffset ) ;
423
424 if ( EmptyRect( &bestsize ) )
425 {
426 baselineoffset = 0;
427 bestsize.left = bestsize.top = 0 ;
428 bestsize.right = 16 ;
429 bestsize.bottom = 16 ;
430 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
431 {
432 bestsize.bottom = 16 ;
433 }
434 else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
435 {
436 bestsize.bottom = 24 ;
437 }
438 }
439
440 if ( m_width == -1 )
441 {
442 if ( IsKindOf( CLASSINFO( wxButton ) ) )
443 {
444 m_width = m_label.Length() * 8 + 12 ;
445 if ( m_width < 70 )
446 m_width = 70 ;
447 }
448 else if ( IsKindOf( CLASSINFO( wxStaticText ) ) )
449 {
450 m_width = m_label.Length() * 8 ;
451 }
452 else
453 m_width = bestsize.right - bestsize.left ;
454
455 m_width += 2 * m_macHorizontalBorder + MacGetLeftBorderSize() + MacGetRightBorderSize() ;
456 }
457 if ( m_height == -1 )
458 {
459 m_height = bestsize.bottom - bestsize.top ;
460 if ( m_height < 10 )
461 m_height = 13 ;
462
463 m_height += 2 * m_macVerticalBorder + MacGetTopBorderSize() + MacGetBottomBorderSize() ;
464 }
465 MacUpdateDimensions() ;
466 // UMASizeControl( (ControlHandle) m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ;
467 }
468 }
469
470 WXWidget wxControl::MacGetContainerForEmbedding()
471 {
472 if ( m_macControl )
473 return m_macControl ;
474
475 return wxWindow::MacGetContainerForEmbedding() ;
476 }
477
478 void wxControl::MacUpdateDimensions()
479 {
480 // actually in the current systems this should never be possible, but later reparenting
481 // may become a reality
482
483 if ( (ControlHandle) m_macControl == NULL )
484 return ;
485
486 if ( GetParent() == NULL )
487 return ;
488
489 WindowRef rootwindow = (WindowRef) MacGetRootWindow() ;
490 if ( rootwindow == NULL )
491 return ;
492
493 Rect oldBounds ;
494 GetControlBounds( (ControlHandle) m_macControl , &oldBounds ) ;
495
496 int new_x = m_x + MacGetLeftBorderSize() + m_macHorizontalBorder ;
497 int new_y = m_y + MacGetTopBorderSize() + m_macVerticalBorder ;
498 int new_width = m_width - MacGetLeftBorderSize() - MacGetRightBorderSize() - 2 * m_macHorizontalBorder ;
499 int new_height = m_height - MacGetTopBorderSize() - MacGetBottomBorderSize() - 2 * m_macVerticalBorder ;
500
501 GetParent()->MacWindowToRootWindow( & new_x , & new_y ) ;
502 bool doMove = new_x != oldBounds.left || new_y != oldBounds.top ;
503 bool doResize = ( oldBounds.right - oldBounds.left ) != new_width || (oldBounds.bottom - oldBounds.top ) != new_height ;
504 if ( doMove || doResize )
505 {
506 InvalWindowRect( rootwindow, &oldBounds ) ;
507 if ( doMove )
508 {
509 UMAMoveControl( (ControlHandle) m_macControl , new_x , new_y ) ;
510 }
511 if ( doResize )
512 {
513 UMASizeControl( (ControlHandle) m_macControl , new_width , new_height ) ;
514 }
515 }
516 }
517
518 void wxControl::MacSuperChangedPosition()
519 {
520 MacUpdateDimensions() ;
521 wxWindow::MacSuperChangedPosition() ;
522 }
523
524 void wxControl::MacSuperEnabled( bool enabled )
525 {
526 Refresh(FALSE) ;
527 wxWindow::MacSuperEnabled( enabled ) ;
528 }
529
530 void wxControl::MacSuperShown( bool show )
531 {
532 if ( (ControlHandle) m_macControl )
533 {
534 if ( !show )
535 {
536 if ( m_macControlIsShown )
537 {
538 ::UMAHideControl( (ControlHandle) m_macControl ) ;
539 m_macControlIsShown = false ;
540 }
541 }
542 else
543 {
544 if ( MacIsReallyShown() && !m_macControlIsShown )
545 {
546 ::UMAShowControl( (ControlHandle) m_macControl ) ;
547 m_macControlIsShown = true ;
548 }
549 }
550 }
551
552 wxWindow::MacSuperShown( show ) ;
553 }
554
555 void wxControl::DoSetSize(int x, int y,
556 int width, int height,
557 int sizeFlags )
558 {
559 wxWindow::DoSetSize( x , y ,width , height ,sizeFlags ) ;
560 #if 0
561 {
562 Rect meta , control ;
563 GetControlBounds( (ControlHandle) m_macControl , &control ) ;
564 RgnHandle rgn = NewRgn() ;
565 GetControlRegion( (ControlHandle) m_macControl , kControlStructureMetaPart , rgn ) ;
566 GetRegionBounds( rgn , &meta ) ;
567 if ( !EmptyRect( &meta ) )
568 {
569 wxASSERT( meta.left >= control.left - m_macHorizontalBorder ) ;
570 wxASSERT( meta.right <= control.right + m_macHorizontalBorder ) ;
571 wxASSERT( meta.top >= control.top - m_macVerticalBorder ) ;
572 wxASSERT( meta.bottom <= control.bottom + m_macVerticalBorder ) ;
573 }
574 DisposeRgn( rgn ) ;
575 }
576 #endif
577 return ;
578 }
579
580 bool wxControl::Show(bool show)
581 {
582 if ( !wxWindow::Show( show ) )
583 return FALSE ;
584
585 if ( (ControlHandle) m_macControl )
586 {
587 if ( !show )
588 {
589 if ( m_macControlIsShown )
590 {
591 ::UMAHideControl( (ControlHandle) m_macControl ) ;
592 m_macControlIsShown = false ;
593 }
594 }
595 else
596 {
597 if ( MacIsReallyShown() && !m_macControlIsShown )
598 {
599 ::UMAShowControl( (ControlHandle) m_macControl ) ;
600 m_macControlIsShown = true ;
601 }
602 }
603 }
604 return TRUE ;
605 }
606
607 bool wxControl::Enable(bool enable)
608 {
609 if ( !wxWindow::Enable(enable) )
610 return FALSE;
611
612 if ( (ControlHandle) m_macControl )
613 {
614 if ( enable )
615 UMAActivateControl( (ControlHandle) m_macControl ) ;
616 else
617 UMADeactivateControl( (ControlHandle) m_macControl ) ;
618 }
619 return TRUE ;
620 }
621
622 void wxControl::Refresh(bool eraseBack, const wxRect *rect)
623 {
624 wxWindow::Refresh( eraseBack , rect ) ;
625 }
626
627 void wxControl::MacRedrawControl()
628 {
629 if ( (ControlHandle) m_macControl && MacGetRootWindow() && m_macControlIsShown )
630 {
631 wxClientDC dc(this) ;
632 wxMacPortSetter helper(&dc) ;
633 wxMacWindowClipper clipper(this) ;
634 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
635 UMADrawControl( (ControlHandle) m_macControl ) ;
636 }
637 }
638
639 void wxControl::OnPaint(wxPaintEvent& event)
640 {
641 if ( (ControlHandle) m_macControl )
642 {
643 wxPaintDC dc(this) ;
644 wxMacPortSetter helper(&dc) ;
645 wxMacWindowClipper clipper(this) ;
646 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
647 UMADrawControl( (ControlHandle) m_macControl ) ;
648 }
649 else
650 {
651 event.Skip() ;
652 }
653 }
654 void wxControl::OnEraseBackground(wxEraseEvent& event)
655 {
656 wxWindow::OnEraseBackground( event ) ;
657 }
658
659 void wxControl::OnKeyDown( wxKeyEvent &event )
660 {
661 if ( (ControlHandle) m_macControl == NULL )
662 return ;
663
664 #if TARGET_CARBON
665
666 char charCode ;
667 UInt32 keyCode ;
668 UInt32 modifiers ;
669
670 GetEventParameter( (EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode );
671 GetEventParameter( (EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode );
672 GetEventParameter((EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers);
673
674 ::HandleControlKey( (ControlHandle) m_macControl , keyCode , charCode , modifiers ) ;
675
676 #else
677 EventRecord *ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ;
678 short keycode ;
679 short keychar ;
680 keychar = short(ev->message & charCodeMask);
681 keycode = short(ev->message & keyCodeMask) >> 8 ;
682
683 ::HandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers ) ;
684 #endif
685 }
686
687 void wxControl::OnMouseEvent( wxMouseEvent &event )
688 {
689 if ( (ControlHandle) m_macControl == NULL )
690 {
691 event.Skip() ;
692 return ;
693 }
694
695 if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK )
696 {
697
698 int x = event.m_x ;
699 int y = event.m_y ;
700
701 MacClientToRootWindow( &x , &y ) ;
702
703 ControlHandle control ;
704 Point localwhere ;
705 SInt16 controlpart ;
706
707 localwhere.h = x ;
708 localwhere.v = y ;
709
710 short modifiers = 0;
711
712 if ( !event.m_leftDown && !event.m_rightDown )
713 modifiers |= btnState ;
714
715 if ( event.m_shiftDown )
716 modifiers |= shiftKey ;
717
718 if ( event.m_controlDown )
719 modifiers |= controlKey ;
720
721 if ( event.m_altDown )
722 modifiers |= optionKey ;
723
724 if ( event.m_metaDown )
725 modifiers |= cmdKey ;
726 {
727 control = (ControlHandle) m_macControl ;
728 if ( control && ::IsControlActive( control ) )
729 {
730 {
731 controlpart = ::HandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ;
732 wxTheApp->s_lastMouseDown = 0 ;
733 if ( control && controlpart != kControlNoPart )
734 {
735 MacHandleControlClick( control , controlpart , false /* mouse not down anymore */ ) ;
736 }
737 }
738 }
739 }
740 }
741 else
742 {
743 event.Skip() ;
744 }
745 }
746
747 bool wxControl::MacCanFocus() const
748 {
749 if ( (ControlHandle) m_macControl == NULL )
750 return true ;
751 else
752 return false ;
753 }
754
755 void wxControl::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) )
756 {
757 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
758 }
759