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