]> git.saurik.com Git - wxWidgets.git/blame - src/mac/control.cpp
Fixed bug that was giving the wrong size of wxCustomDataObjects to the receiver.
[wxWidgets.git] / src / mac / control.cpp
CommitLineData
e9576ca5
SC
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/control.h"
519cb848
SC
17#include "wx/notebook.h"
18#include "wx/tabctrl.h"
2f1ae414 19#include "wx/radiobox.h"
519cb848 20#include "wx/spinbutt.h"
e9576ca5 21
2f1ae414 22#if !USE_SHARED_LIBRARY
8208e181 23IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
e9576ca5 24
2f1ae414 25BEGIN_EVENT_TABLE(wxControl, wxWindow)
519cb848
SC
26 EVT_MOUSE_EVENTS( wxControl::OnMouseEvent )
27 EVT_CHAR( wxControl::OnKeyDown )
28 EVT_PAINT( wxControl::OnPaint )
e9576ca5 29END_EVENT_TABLE()
2f1ae414 30#endif
e9576ca5 31
519cb848
SC
32#include <wx/mac/uma.h>
33
e9576ca5 34// Item members
519cb848
SC
35
36ControlActionUPP wxMacLiveScrollbarActionUPP = NULL ;
37
2f1ae414 38pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode ) ;
519cb848
SC
39pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode )
40{
41 if ( partCode != 0)
42 {
43 wxControl* wx = (wxControl*) GetControlReference( control ) ;
44 if ( wx )
45 {
46 wx->MacHandleControlClick( control , partCode ) ;
47 }
48 }
49}
50
e9576ca5
SC
51wxControl::wxControl()
52{
2f1ae414
SC
53 m_macControl = NULL ;
54 m_macHorizontalBorder = 0 ; // additional pixels around the real control
55 m_macVerticalBorder = 0 ;
e9576ca5
SC
56 m_backgroundColour = *wxWHITE;
57 m_foregroundColour = *wxBLACK;
e7549107
SC
58#if WXWIN_COMPATIBILITY
59 m_callback = 0;
60#endif // WXWIN_COMPATIBILITY
519cb848
SC
61
62 if ( wxMacLiveScrollbarActionUPP == NULL )
63 {
64 wxMacLiveScrollbarActionUPP = NewControlActionProc( wxMacLiveScrollbarActionProc ) ;
65 }
e9576ca5
SC
66}
67
2f1ae414
SC
68bool wxControl::Create(wxWindow *parent, wxWindowID id,
69 const wxPoint& pos,
70 const wxSize& size, long style,
71 const wxValidator& validator,
72 const wxString& name)
73{
74 m_macControl = NULL ;
75 m_macHorizontalBorder = 0 ; // additional pixels around the real control
76 m_macVerticalBorder = 0 ;
77 bool rval = wxWindow::Create(parent, id, pos, size, style, name);
78 if (rval) {
79#if wxUSE_VALIDATORS
80 SetValidator(validator);
81#endif
82 }
83 return rval;
84}
85
e9576ca5
SC
86wxControl::~wxControl()
87{
e7549107 88 m_isBeingDeleted = TRUE;
e9576ca5
SC
89 // If we delete an item, we should initialize the parent panel,
90 // because it could now be invalid.
e7549107
SC
91 wxPanel *panel = wxDynamicCast(GetParent(), wxPanel);
92 if ( panel )
e9576ca5 93 {
e7549107
SC
94 if (panel->GetDefaultItem() == (wxButton*) this)
95 panel->SetDefaultItem(NULL);
e9576ca5 96 }
519cb848
SC
97 if ( m_macControl )
98 {
99 UMADisposeControl( m_macControl ) ;
100 m_macControl = NULL ;
101 }
e9576ca5
SC
102}
103
e7549107 104void wxControl::SetLabel(const wxString& title)
e9576ca5 105{
e7549107 106 m_label = title ;
519cb848
SC
107
108 if ( m_macControl )
109 {
110 Str255 maclabel ;
e7549107
SC
111 wxString label ;
112
113 if( wxApp::s_macDefaultEncodingIsPC )
114 label = wxMacMakeMacStringFromPC( title ) ;
115 else
116 label = title ;
519cb848
SC
117
118 strcpy( (char*) maclabel , label ) ;
119 c2pstr( (char*) maclabel ) ;
120
121 ::SetControlTitle( m_macControl , maclabel ) ;
122 }
e9576ca5
SC
123}
124
37e2cb08 125wxSize wxControl::DoGetBestSize() const
e9576ca5 126{
e7549107 127 return wxSize(20, 20);
e9576ca5
SC
128}
129
e7549107 130bool wxControl::ProcessCommand (wxCommandEvent & event)
e9576ca5
SC
131{
132 // Tries:
133 // 1) A callback function (to become obsolete)
134 // 2) OnCommand, starting at this window and working up parent hierarchy
135 // 3) OnCommand then calls ProcessEvent to search the event tables.
e7549107
SC
136#if WXWIN_COMPATIBILITY
137 if ( m_callback )
e9576ca5 138 {
e7549107
SC
139 (void)(*m_callback)(this, event);
140
141 return TRUE;
e9576ca5
SC
142 }
143 else
e7549107 144#endif // WXWIN_COMPATIBILITY
e9576ca5 145 {
e7549107 146 return GetEventHandler()->ProcessEvent(event);
e9576ca5
SC
147 }
148}
149
519cb848
SC
150// ------------------------
151wxList *wxWinMacControlList = NULL;
152wxControl *wxFindControlFromMacControl(ControlHandle inControl )
153{
154 wxNode *node = wxWinMacControlList->Find((long)inControl);
155 if (!node)
156 return NULL;
157 return (wxControl *)node->Data();
158}
159
160void wxAssociateControlWithMacControl(ControlHandle inControl, wxControl *control)
161{
162 // adding NULL WindowRef is (first) surely a result of an error and
163 // (secondly) breaks menu command processing
164 wxCHECK_RET( inControl != (ControlHandle) NULL, "attempt to add a NULL WindowRef to window list" );
165
166 if ( !wxWinMacControlList->Find((long)inControl) )
167 wxWinMacControlList->Append((long)inControl, control);
168}
169
170void wxRemoveMacControlAssociation(wxControl *control)
171{
172 wxWinMacControlList->DeleteObject(control);
173}
174
175void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString label ,
176 const wxPoint& pos,
177 const wxSize& size, long style,
178 const wxValidator& validator,
179 const wxString& name , Rect *outBounds , StringPtr maclabel )
180{
181 m_label = label ;
182 SetName(name);
183 if ( &validator )
184 SetValidator(validator);
185
186 m_windowStyle = style;
187 parent->AddChild((wxButton *)this);
188
189 m_backgroundColour = parent->GetBackgroundColour() ;
190 m_foregroundColour = parent->GetForegroundColour() ;
191
192 if (id == -1)
193 m_windowId = NewControlId();
194 else
195 m_windowId = id;
196
197 m_width = size.x ;
198 m_height = size.y ;
199 int x = pos.x ;
200 int y = pos.y ;
201 AdjustForParentClientOrigin(x, y, wxSIZE_USE_EXISTING);
202 m_x = x ;
203 m_y = y ;
204
205
519cb848
SC
206 parent->MacClientToRootWindow( &x , &y ) ;
207 outBounds->top = y + m_macVerticalBorder ;
208 outBounds->left = x + m_macHorizontalBorder ;
209 outBounds->bottom = outBounds->top + m_height - 2 * m_macVerticalBorder;
210 outBounds->right = outBounds->left + m_width - 2 * m_macHorizontalBorder ;
211
212 strcpy( (char*) maclabel , label ) ;
213 if( wxApp::s_macDefaultEncodingIsPC )
214 {
215 wxMacConvertFromPCForControls( (char*) maclabel ) ;
216 }
217
218 c2pstr( (char*) maclabel ) ;
219}
220
221void wxControl::MacPostControlCreate()
222{
223 wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
224
225 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
226 {
227 // no font
228 }
2f1ae414 229 else if ( IsKindOf( CLASSINFO( wxStaticBox ) ) || IsKindOf( CLASSINFO( wxRadioBox ) ) || IsKindOf( CLASSINFO( wxButton ) ) )
519cb848
SC
230 {
231 ControlFontStyleRec controlstyle ;
232 controlstyle.flags = kControlUseFontMask ;
233 controlstyle.font = kControlFontSmallBoldSystemFont ;
234
235 ::UMASetControlFontStyle( m_macControl , &controlstyle ) ;
236 }
237 else
238 {
239 ControlFontStyleRec controlstyle ;
240 controlstyle.flags = kControlUseFontMask ;
241 controlstyle.font = kControlFontSmallSystemFont ;
242
243 ::UMASetControlFontStyle( m_macControl , &controlstyle ) ;
244 }
245 ControlHandle container = GetParent()->MacGetContainerForEmbedding() ;
246 wxASSERT_MSG( container != NULL , "No valid mac container control" ) ;
247 ::UMAEmbedControl( m_macControl , container ) ;
248 MacAdjustControlRect() ;
249 wxAssociateControlWithMacControl( m_macControl , this ) ;
250}
251
252void wxControl::MacAdjustControlRect()
253{
254 wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
255 if ( m_width == -1 || m_height == -1 )
256 {
257 Rect bestsize = { 0 , 0 , 0 , 0 } ;
258 short baselineoffset ;
259
260 UMAGetBestControlRect( m_macControl , &bestsize , &baselineoffset ) ;
261
262 if ( EmptyRect( &bestsize ) )
263 {
264 baselineoffset = 0;
265 bestsize.left = bestsize.top = 0 ;
266 bestsize.right = 16 ;
267 bestsize.bottom = 16 ;
268 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
269 {
270 bestsize.bottom = 16 ;
271 }
272 else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
273 {
274 bestsize.bottom = 24 ;
275 }
276 }
277
278 if ( m_width == -1 )
279 {
280 if ( IsKindOf( CLASSINFO( wxButton ) ) )
281 {
2f1ae414 282 m_width = m_label.Length() * 8 + 12 ;
519cb848
SC
283 }
284 else if ( IsKindOf( CLASSINFO( wxStaticText ) ) )
285 {
286 m_width = m_label.Length() * 8 ;
287 }
288 else
2f1ae414
SC
289 m_width = bestsize.right - bestsize.left ;
290
291 m_width += 2 * m_macHorizontalBorder ;
519cb848
SC
292 }
293 if ( m_height == -1 )
294 {
295 m_height = bestsize.bottom - bestsize.top ;
296 if ( m_height < 10 )
297 m_height = 13 ;
298
299 m_height += 2 * m_macVerticalBorder;
300 }
301
302 wxMacDrawingHelper helper ( wxFindWinFromMacWindow( GetMacRootWindow() ) ) ;
303 if ( helper.Ok() )
304 {
2f1ae414 305 UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ;
519cb848
SC
306 }
307 }
308}
309ControlHandle wxControl::MacGetContainerForEmbedding()
310{
311 if ( m_macControl )
312 return m_macControl ;
313
314 return wxWindow::MacGetContainerForEmbedding() ;
315}
316
317void wxControl::MacSuperChangedPosition()
318{
319 if ( m_macControl )
320 {
2f1ae414
SC
321 Rect contrlRect ;
322 GetControlBounds( m_macControl , &contrlRect ) ;
323 int former_mac_x = contrlRect.left ;
324 int former_mac_y = contrlRect.top ;
519cb848
SC
325 int mac_x = m_x ;
326 int mac_y = m_y ;
327 GetParent()->MacClientToRootWindow( & mac_x , & mac_y ) ;
328
329 WindowRef rootwindow = GetMacRootWindow() ;
330 wxWindow* wxrootwindow = wxFindWinFromMacWindow( rootwindow ) ;
331 UMASetThemeWindowBackground( rootwindow , kThemeBrushDialogBackgroundActive , false ) ;
332 wxMacDrawingHelper focus( wxrootwindow ) ;
333
334 if ( mac_x != former_mac_x || mac_y != former_mac_y )
335 {
336 {
337 Rect inval = { former_mac_y , former_mac_x , former_mac_y + m_height , former_mac_x + m_width } ;
2f1ae414 338 InvalWindowRect( rootwindow , &inval ) ;
519cb848 339 }
2f1ae414 340 UMAMoveControl( m_macControl , mac_x + m_macHorizontalBorder , mac_y + m_macVerticalBorder ) ;
519cb848
SC
341 {
342 Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ;
2f1ae414 343 InvalWindowRect( rootwindow , &inval ) ;
519cb848
SC
344 }
345 }
346 if ( wxrootwindow->IsKindOf( CLASSINFO( wxDialog ) ) )
347 {
348 }
349 else
350 {
351 UMASetThemeWindowBackground( rootwindow , kThemeBrushDocumentWindowBackground , false ) ;
352 }
353 }
354
355 wxWindow::MacSuperChangedPosition() ;
356}
357
358void wxControl::MacSuperEnabled( bool enabled )
359{
e7549107 360/*
519cb848
SC
361 if ( m_macControl )
362 {
363 if ( UMAHasAppearance() )
364 {
365 if ( !enabled )
366 {
367 ::DeactivateControl( m_macControl ) ;
368 }
369 else
370 {
371 if ( m_macEnabled )
372 ::ActivateControl( m_macControl ) ;
373 }
374 }
375 else
376 {
377 if ( !enabled )
378 {
379 ::HiliteControl( m_macControl , 255 ) ;
380 }
381 else
382 {
383 if ( m_macEnabled )
384 ::HiliteControl( m_macControl , 0 ) ;
385 }
386 }
387 }
388 wxWindow::MacSuperEnabled( enabled ) ;
2f1ae414 389*/
519cb848
SC
390}
391
392void wxControl::MacSuperShown( bool show )
393{
394 if ( m_macControl )
395 {
396 if ( !show )
397 {
398 ::UMAHideControl( m_macControl ) ;
399 }
400 else
401 {
8208e181 402 if ( m_isShown )
519cb848
SC
403 ::UMAShowControl( m_macControl ) ;
404 }
405 }
406
407 wxWindow::MacSuperShown( show ) ;
408}
409
410void wxControl::DoSetSize(int x, int y,
411 int width, int height,
412 int sizeFlags )
413{
414 if ( m_macControl == NULL )
415 {
416 wxWindow::DoSetSize( x , y ,width , height ,sizeFlags ) ;
417 return ;
418 }
419
420 WindowRef rootwindow = GetMacRootWindow() ;
421 wxWindow* wxrootwindow = wxFindWinFromMacWindow( rootwindow ) ;
422 UMASetThemeWindowBackground( rootwindow , kThemeBrushDialogBackgroundActive , false ) ;
423
424 int former_x = m_x ;
425 int former_y = m_y ;
426 int former_w = m_width ;
427 int former_h = m_height ;
428
2f1ae414
SC
429 Rect contrlRect ;
430 GetControlBounds( m_macControl , &contrlRect ) ;
431 int former_mac_x = contrlRect.left ;
432 int former_mac_y = contrlRect.top ;
519cb848
SC
433
434 int currentX, currentY;
435 GetPosition(&currentX, &currentY);
436 int currentW,currentH;
437 GetSize(&currentW, &currentH);
438
439 int actualWidth = width;
440 int actualHeight = height;
441 int actualX = x;
442 int actualY = y;
2f1ae414 443 if (x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
519cb848 444 actualX = currentX;
2f1ae414 445 if (y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
519cb848
SC
446 actualY = currentY;
447 if (width == -1)
448 actualWidth = currentW ;
449 if (height == -1)
450 actualHeight = currentH ;
451
452 if ( actualX == currentX && actualY == currentY && actualWidth == currentW && actualHeight == currentH)
453 return ;
454
455 AdjustForParentClientOrigin(actualX, actualY, sizeFlags);
2f1ae414
SC
456 WindowRef macrootwindow = GetMacRootWindow() ;
457 wxMacDrawingHelper focus( wxFindWinFromMacWindow( macrootwindow ) ) ;
519cb848
SC
458
459 int mac_x = actualX ;
460 int mac_y = actualY ;
461 GetParent()->MacClientToRootWindow( & mac_x , & mac_y ) ;
462
463 if ( mac_x != former_mac_x || mac_y != former_mac_y )
464 {
465 {
466 Rect inval = { former_mac_y , former_mac_x , former_mac_y + m_height , former_mac_x + m_width } ;
2f1ae414 467 InvalWindowRect( macrootwindow, &inval ) ;
519cb848 468 }
2f1ae414 469 UMAMoveControl( m_macControl , mac_x + m_macHorizontalBorder , mac_y + m_macVerticalBorder ) ;
519cb848
SC
470 {
471 Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ;
2f1ae414 472 InvalWindowRect(macrootwindow, &inval ) ;
519cb848
SC
473 }
474 }
475
476 if ( actualX != former_x || actualY != former_y )
477 {
478 m_x = actualX ;
479 m_y = actualY ;
480
481 MacRepositionScrollBars() ;
482 // To consider -> should the parameters be the effective or the virtual coordinates (AdjustForParent..)
483 wxMoveEvent event(wxPoint(m_x, m_y), m_windowId);
484 event.SetEventObject(this);
485 GetEventHandler()->ProcessEvent(event);
486 }
487 if ( actualWidth != former_w || actualHeight != former_h )
488 {
489 {
490 Rect inval = { mac_y , mac_x , mac_y + former_h , mac_x + former_w } ;
2f1ae414 491 InvalWindowRect( macrootwindow, &inval ) ;
519cb848
SC
492 }
493 m_width = actualWidth ;
494 m_height = actualHeight ;
495
2f1ae414 496 UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ;
519cb848
SC
497 {
498 Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ;
2f1ae414 499 InvalWindowRect( macrootwindow , &inval ) ;
519cb848
SC
500 }
501
502 MacRepositionScrollBars() ;
503 wxSizeEvent event(wxSize(m_width, m_height), m_windowId);
504 event.SetEventObject(this);
505 GetEventHandler()->ProcessEvent(event);
506 }
507 if ( wxrootwindow->IsKindOf( CLASSINFO( wxDialog ) ) )
508 {
509 }
510 else
511 {
512 UMASetThemeWindowBackground( rootwindow , kThemeBrushDocumentWindowBackground , false ) ;
513 }
514}
515
519cb848
SC
516bool wxControl::Show(bool show)
517{
e7549107
SC
518 if ( !wxWindow::Show( show ) )
519 return FALSE ;
520
521 if ( m_macControl )
522 {
523 if ( show )
524 ::UMAShowControl( m_macControl ) ;
525 else
526 ::UMAHideControl( m_macControl ) ;
527 }
528 return TRUE ;
519cb848
SC
529}
530
e7549107 531bool wxControl::Enable(bool enable)
519cb848 532{
e7549107
SC
533 if ( !wxWindow::Enable(enable) )
534 return FALSE;
519cb848 535
e7549107 536 if ( m_macControl )
519cb848 537 {
e7549107
SC
538
539 if ( UMAHasAppearance() )
540 {
541 if ( enable )
542 ::ActivateControl( m_macControl ) ;
543 else
544 ::DeactivateControl( m_macControl ) ;
545 }
519cb848 546 else
e7549107
SC
547 {
548 if ( enable )
549 ::HiliteControl( m_macControl , 0 ) ;
550 else
551 ::HiliteControl( m_macControl , 255 ) ;
552 }
519cb848 553 }
e7549107 554 return TRUE ;
519cb848
SC
555}
556
557void wxControl::Refresh(bool eraseBack, const wxRect *rect)
558{
559 if ( m_macControl )
560 {
561 wxWindow::Refresh( eraseBack , rect ) ;
562 }
563 else
564 {
565 wxWindow::Refresh( eraseBack , rect ) ;
566 }
567}
568
2f1ae414
SC
569void wxControl::MacRedrawControl()
570{
571 if ( m_macControl )
572 {
573 WindowRef window = GetMacRootWindow() ;
574 if ( window )
575 {
576 wxWindow* win = wxFindWinFromMacWindow( window ) ;
577 if ( win )
578 {
579 wxMacDrawingHelper help( win ) ;
580 // the mac control manager always assumes to have the origin at 0,0
581 SetOrigin( 0 , 0 ) ;
582
583 bool hasTabBehind = false ;
584 wxWindow* parent = GetParent() ;
585 while ( parent )
586 {
587 if( parent->MacGetWindowData() )
588 {
589 UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
590 break ;
591 }
592
593 if( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
594 {
595 if ( ((wxControl*)parent)->m_macControl )
596 SetUpControlBackground( ((wxControl*)parent)->m_macControl , -1 , true ) ;
597 break ;
598 }
599
600 parent = parent->GetParent() ;
601 }
602
603 UMADrawControl( m_macControl ) ;
604 UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ;
605 }
606 }
607 }
608}
609
519cb848
SC
610void wxControl::OnPaint(wxPaintEvent& event)
611{
612 if ( m_macControl )
613 {
614 WindowRef window = GetMacRootWindow() ;
615 if ( window )
616 {
617 wxWindow* win = wxFindWinFromMacWindow( window ) ;
618 if ( win )
619 {
620 wxMacDrawingHelper help( win ) ;
2f1ae414 621 // the mac control manager always assumes to have the origin at 0,0
519cb848
SC
622 SetOrigin( 0 , 0 ) ;
623
624 bool hasTabBehind = false ;
625 wxWindow* parent = GetParent() ;
626 while ( parent )
627 {
e7549107 628 if( parent->MacGetWindowData() )
519cb848 629 {
e7549107 630 UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
519cb848
SC
631 break ;
632 }
633
634 if( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
635 {
636 if ( ((wxControl*)parent)->m_macControl )
637 SetUpControlBackground( ((wxControl*)parent)->m_macControl , -1 , true ) ;
638 break ;
639 }
640
641 parent = parent->GetParent() ;
642 }
643
644 UMADrawControl( m_macControl ) ;
e7549107 645 UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ;
519cb848
SC
646 }
647 }
648 }
649 else
650 {
e7549107 651 // wxWindow::OnPaint( event ) ;
519cb848
SC
652 }
653}
51abe921
SC
654void wxControl::OnEraseBackground(wxEraseEvent& event)
655{
656 // In general, you don't want to erase the background of a control,
657 // or you'll get a flicker.
658 // TODO: move this 'null' function into each control that
659 // might flicker.
660}
661
519cb848
SC
662
663void wxControl::OnKeyDown( wxKeyEvent &event )
664{
665 if ( m_macControl == NULL )
666 return ;
667
668 EventRecord *ev = wxTheApp->MacGetCurrentEvent() ;
669 short keycode ;
670 short keychar ;
671 keychar = short(ev->message & charCodeMask);
672 keycode = short(ev->message & keyCodeMask) >> 8 ;
673
674 UMAHandleControlKey( m_macControl , keycode , keychar , ev->modifiers ) ;
675}
676
677void wxControl::OnMouseEvent( wxMouseEvent &event )
678{
679 if ( m_macControl == NULL )
680 {
681 event.Skip() ;
682 return ;
683 }
684
2f1ae414 685 if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK )
519cb848
SC
686 {
687
688 int x = event.m_x ;
689 int y = event.m_y ;
690
691 MacClientToRootWindow( &x , &y ) ;
692
693 ControlHandle control ;
694 Point localwhere ;
695 GrafPtr port ;
696 SInt16 controlpart ;
697 WindowRef window = GetMacRootWindow() ;
698
699 localwhere.h = x ;
700 localwhere.v = y ;
701
702 short modifiers = 0;
703
704 if ( !event.m_leftDown && !event.m_rightDown )
705 modifiers |= btnState ;
706
707 if ( event.m_shiftDown )
708 modifiers |= shiftKey ;
709
710 if ( event.m_controlDown )
711 modifiers |= controlKey ;
712
713 if ( event.m_altDown )
714 modifiers |= optionKey ;
715
716 if ( event.m_metaDown )
717 modifiers |= cmdKey ;
718
719 controlpart = FindControl( localwhere , window , &control ) ;
720 {
721 if ( AcceptsFocus() && FindFocus() != this )
722 {
723 SetFocus() ;
724 }
725 if ( control && UMAIsControlActive( control ) )
726 {
727 {
728 if ( controlpart == kControlIndicatorPart && !UMAHasAppearance() )
729 controlpart = UMAHandleControlClick( control , localwhere , modifiers , (ControlActionUPP) NULL ) ;
730 else
731 controlpart = UMAHandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ;
732 wxTheApp->s_lastMouseDown = 0 ;
733 if ( controlpart && ! ( ( UMAHasAppearance() || (controlpart != kControlIndicatorPart) )
734 && (IsKindOf( CLASSINFO( wxScrollBar ) ) ) ) ) // otherwise we will get the event twice
735 {
736 MacHandleControlClick( control , controlpart ) ;
737 }
738 }
739 }
740 }
741 }
742}
743
744bool wxControl::MacCanFocus() const
745{
746 { if ( m_macControl == NULL )
747 return true ;
748 else
749 return false ;
750 }
751}
752
753void wxControl::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
754{
755 wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
756}
757