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