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