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