]> git.saurik.com Git - wxWidgets.git/blame - src/mac/control.cpp
Ok tests pixmap and bitmap now
[wxWidgets.git] / src / mac / 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 {
76a5e5d2 199 ::DisposeControl( (ControlHandle) m_macControl ) ;
89ebf1c9 200 m_macControl = NULL ;
519cb848 201 }
e9576ca5
SC
202}
203
e7549107 204void wxControl::SetLabel(const wxString& title)
e9576ca5 205{
28c98a77 206 m_label = wxStripMenuCodes(title) ;
89ebf1c9 207
427ff662 208 if ( m_macControl )
89ebf1c9 209 {
a9412f8f 210 UMASetControlTitle( (ControlHandle) m_macControl , m_label , m_font.GetEncoding() ) ;
89ebf1c9
RR
211 }
212 Refresh() ;
e9576ca5
SC
213}
214
37e2cb08 215wxSize wxControl::DoGetBestSize() const
e9576ca5 216{
439ddeba
SC
217 if ( (ControlHandle) m_macControl == NULL )
218 return wxWindow::DoGetBestSize() ;
219
89ebf1c9
RR
220 Rect bestsize = { 0 , 0 , 0 , 0 } ;
221 short baselineoffset ;
222 int bestWidth, bestHeight ;
76a5e5d2 223 ::GetBestControlRect( (ControlHandle) m_macControl , &bestsize , &baselineoffset ) ;
89ebf1c9
RR
224
225 if ( EmptyRect( &bestsize ) )
226 {
227 baselineoffset = 0;
228 bestsize.left = bestsize.top = 0 ;
229 bestsize.right = 16 ;
230 bestsize.bottom = 16 ;
231 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
232 {
233 bestsize.bottom = 16 ;
234 }
235 else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
236 {
237 bestsize.bottom = 24 ;
238 }
239 }
240
439ddeba 241 bestWidth = bestsize.right - bestsize.left ;
89ebf1c9
RR
242
243 bestWidth += 2 * m_macHorizontalBorder ;
244
245 bestHeight = bestsize.bottom - bestsize.top ;
246 if ( bestHeight < 10 )
247 bestHeight = 13 ;
248
249 bestHeight += 2 * m_macVerticalBorder;
250
251
9453cf2b 252 return wxSize(bestWidth, bestHeight);
e9576ca5
SC
253}
254
e7549107 255bool wxControl::ProcessCommand (wxCommandEvent & event)
e9576ca5 256{
a3bf7524
VS
257 // Tries:
258 // 1) OnCommand, starting at this window and working up parent hierarchy
259 // 2) OnCommand then calls ProcessEvent to search the event tables.
260 return GetEventHandler()->ProcessEvent(event);
e9576ca5
SC
261}
262
519cb848
SC
263// ------------------------
264wxList *wxWinMacControlList = NULL;
265wxControl *wxFindControlFromMacControl(ControlHandle inControl )
266{
267 wxNode *node = wxWinMacControlList->Find((long)inControl);
268 if (!node)
269 return NULL;
eb22f2a6 270 return (wxControl *)node->GetData();
519cb848
SC
271}
272
273void wxAssociateControlWithMacControl(ControlHandle inControl, wxControl *control)
274{
275 // adding NULL WindowRef is (first) surely a result of an error and
276 // (secondly) breaks menu command processing
427ff662 277 wxCHECK_RET( inControl != (ControlHandle) NULL, wxT("attempt to add a NULL WindowRef to window list") );
519cb848
SC
278
279 if ( !wxWinMacControlList->Find((long)inControl) )
280 wxWinMacControlList->Append((long)inControl, control);
281}
282
283void wxRemoveMacControlAssociation(wxControl *control)
284{
de923e4f
SC
285 if ( wxWinMacControlList )
286 wxWinMacControlList->DeleteObject(control);
519cb848
SC
287}
288
289void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString label ,
89ebf1c9
RR
290 const wxPoint& pos,
291 const wxSize& size, long style,
292 const wxValidator& validator,
76a5e5d2 293 const wxString& name , WXRECTPTR outBounds , unsigned char* maclabel )
519cb848 294{
89ebf1c9 295 m_label = label ;
9453cf2b 296
b45ed7a2 297 // These sizes will be adjusted in MacPostControlCreate
89ebf1c9
RR
298 m_width = size.x ;
299 m_height = size.y ;
300 m_x = pos.x ;
301 m_y = pos.y ;
302
76a5e5d2
SC
303 ((Rect*)outBounds)->top = -10;
304 ((Rect*)outBounds)->left = -10;
305 ((Rect*)outBounds)->bottom = 0;
306 ((Rect*)outBounds)->right = 0;
89ebf1c9 307
c5c9378c 308 wxMacStringToPascal( wxStripMenuCodes(label) , maclabel ) ;
519cb848
SC
309}
310
311void wxControl::MacPostControlCreate()
312{
427ff662 313 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
89ebf1c9
RR
314
315 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
316 {
317 // no font
318 }
2d9d0118 319 else if ( !UMAHasAquaLayout() && (IsKindOf( CLASSINFO( wxStaticBox ) ) || IsKindOf( CLASSINFO( wxRadioBox ) ) || IsKindOf( CLASSINFO( wxButton ) ) ) )
89ebf1c9
RR
320 {
321 ControlFontStyleRec controlstyle ;
322 controlstyle.flags = kControlUseFontMask ;
323 controlstyle.font = kControlFontSmallBoldSystemFont ;
324
76a5e5d2 325 ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ;
89ebf1c9
RR
326 }
327 else
328 {
329 ControlFontStyleRec controlstyle ;
330 controlstyle.flags = kControlUseFontMask ;
4b26b60f
SC
331
332 if (IsKindOf( CLASSINFO( wxButton ) ) )
a9412f8f 333 controlstyle.font = kControlFontBigSystemFont ; // eventually kControlFontBigSystemFont ;
4b26b60f
SC
334 else
335 controlstyle.font = kControlFontSmallSystemFont ;
89ebf1c9 336
76a5e5d2 337 ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ;
89ebf1c9 338 }
76a5e5d2 339 ControlHandle container = (ControlHandle) GetParent()->MacGetContainerForEmbedding() ;
89ebf1c9 340 wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
76a5e5d2 341 ::EmbedControl( (ControlHandle) m_macControl , container ) ;
de923e4f 342 m_macControlIsShown = MacIsReallyShown() ;
89ebf1c9 343
76a5e5d2 344 wxAssociateControlWithMacControl( (ControlHandle) m_macControl , this ) ;
e40298d5
JS
345 if ( wxMacSetupControlBackgroundUPP == NULL )
346 {
347 wxMacSetupControlBackgroundUPP = NewControlColorUPP( wxMacSetupControlBackground ) ;
348 }
349 if ( wxMacControlActionUPP == NULL )
350 {
351 wxMacControlActionUPP = NewControlDefUPP( wxMacControlDefinition ) ;
352 }
111c1e2c
JS
353 // The following block of code is responsible for crashes when switching
354 // back to windows, which can be seen in the dialogs sample.
355 // It is disabled until a proper solution can be found.
356#if 0
17a2c5a1 357#if TARGET_CARBON
b6f5f27a
SC
358/*
359 only working under classic carbon
17a2c5a1
SC
360 m_macControlAction = *(**(ControlHandle)m_macControl).contrlDefProc ;
361 (**(ControlHandle)m_macControl).contrlDefProc = (Handle) &wxMacControlActionUPP ;
b6f5f27a 362*/
17a2c5a1
SC
363#else
364 m_macControlAction = *(**(ControlHandle)m_macControl).contrlDefProc ;
365
366 cdefHandle cdef ;
367 cdef = (cdefHandle) NewHandle( sizeof(cdefRec) ) ;
368 if ( (**(ControlHandle)m_macControl).contrlDefProc != NULL )
369 {
e40298d5
JS
370 (**cdef).instruction = 0x4EF9; /* JMP instruction */
371 (**cdef).function = (void(*)()) wxMacControlActionUPP;
372 (**(ControlHandle)m_macControl).contrlDefProc = (Handle) cdef ;
17a2c5a1 373 }
111c1e2c 374#endif
17a2c5a1 375#endif
e40298d5
JS
376 SetControlColorProc( (ControlHandle) m_macControl , wxMacSetupControlBackgroundUPP ) ;
377
378 // Adjust the controls size and position
379 wxPoint pos(m_x, m_y);
380 wxSize best_size( DoGetBestSize() );
381 wxSize new_size( m_width, m_height );
382
383 m_x = m_y = m_width = m_height = -1; // Forces SetSize to move/size the control
384
385 if (new_size.x == -1) {
9453cf2b 386 new_size.x = best_size.x;
e40298d5
JS
387 }
388 if (new_size.y == -1) {
389 new_size.y = best_size.y;
390 }
391
392 SetSize(pos.x, pos.y, new_size.x, new_size.y);
393
427ff662 394#if wxUSE_UNICODE
a9412f8f 395 UMASetControlTitle( (ControlHandle) m_macControl , wxStripMenuCodes(m_label) , m_font.GetEncoding() ) ;
427ff662
SC
396#endif
397
de923e4f
SC
398 if ( m_macControlIsShown )
399 UMAShowControl( (ControlHandle) m_macControl ) ;
e40298d5
JS
400
401 SetCursor( *wxSTANDARD_CURSOR ) ;
402
403 Refresh() ;
519cb848
SC
404}
405
406void wxControl::MacAdjustControlRect()
407{
76a5e5d2 408 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
89ebf1c9
RR
409 if ( m_width == -1 || m_height == -1 )
410 {
411 Rect bestsize = { 0 , 0 , 0 , 0 } ;
412 short baselineoffset ;
413
76a5e5d2 414 ::GetBestControlRect( (ControlHandle) m_macControl , &bestsize , &baselineoffset ) ;
89ebf1c9
RR
415
416 if ( EmptyRect( &bestsize ) )
417 {
418 baselineoffset = 0;
419 bestsize.left = bestsize.top = 0 ;
420 bestsize.right = 16 ;
421 bestsize.bottom = 16 ;
422 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
423 {
424 bestsize.bottom = 16 ;
425 }
426 else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
427 {
428 bestsize.bottom = 24 ;
429 }
430 }
431
432 if ( m_width == -1 )
433 {
434 if ( IsKindOf( CLASSINFO( wxButton ) ) )
435 {
436 m_width = m_label.Length() * 8 + 12 ;
437 if ( m_width < 70 )
438 m_width = 70 ;
439 }
440 else if ( IsKindOf( CLASSINFO( wxStaticText ) ) )
441 {
442 m_width = m_label.Length() * 8 ;
443 }
444 else
445 m_width = bestsize.right - bestsize.left ;
446
327788ac 447 m_width += 2 * m_macHorizontalBorder + MacGetLeftBorderSize() + MacGetRightBorderSize() ;
89ebf1c9
RR
448 }
449 if ( m_height == -1 )
450 {
451 m_height = bestsize.bottom - bestsize.top ;
452 if ( m_height < 10 )
453 m_height = 13 ;
454
327788ac 455 m_height += 2 * m_macVerticalBorder + MacGetTopBorderSize() + MacGetBottomBorderSize() ;
89ebf1c9 456 }
439ddeba 457 MacUpdateDimensions() ;
89ebf1c9 458 }
519cb848 459}
76a5e5d2
SC
460
461WXWidget wxControl::MacGetContainerForEmbedding()
519cb848 462{
89ebf1c9
RR
463 if ( m_macControl )
464 return m_macControl ;
519cb848 465
89ebf1c9 466 return wxWindow::MacGetContainerForEmbedding() ;
519cb848
SC
467}
468
327788ac 469void wxControl::MacUpdateDimensions()
519cb848 470{
e40298d5
JS
471 // actually in the current systems this should never be possible, but later reparenting
472 // may become a reality
473
474 if ( (ControlHandle) m_macControl == NULL )
475 return ;
476
477 if ( GetParent() == NULL )
478 return ;
479
327788ac
SC
480 WindowRef rootwindow = (WindowRef) MacGetRootWindow() ;
481 if ( rootwindow == NULL )
e40298d5
JS
482 return ;
483
327788ac
SC
484 Rect oldBounds ;
485 GetControlBounds( (ControlHandle) m_macControl , &oldBounds ) ;
486
487 int new_x = m_x + MacGetLeftBorderSize() + m_macHorizontalBorder ;
488 int new_y = m_y + MacGetTopBorderSize() + m_macVerticalBorder ;
489 int new_width = m_width - MacGetLeftBorderSize() - MacGetRightBorderSize() - 2 * m_macHorizontalBorder ;
490 int new_height = m_height - MacGetTopBorderSize() - MacGetBottomBorderSize() - 2 * m_macVerticalBorder ;
491
492 GetParent()->MacWindowToRootWindow( & new_x , & new_y ) ;
493 bool doMove = new_x != oldBounds.left || new_y != oldBounds.top ;
494 bool doResize = ( oldBounds.right - oldBounds.left ) != new_width || (oldBounds.bottom - oldBounds.top ) != new_height ;
e40298d5
JS
495 if ( doMove || doResize )
496 {
497 InvalWindowRect( rootwindow, &oldBounds ) ;
498 if ( doMove )
499 {
500 UMAMoveControl( (ControlHandle) m_macControl , new_x , new_y ) ;
501 }
502 if ( doResize )
503 {
504 UMASizeControl( (ControlHandle) m_macControl , new_width , new_height ) ;
505 }
506 }
327788ac 507}
89ebf1c9 508
327788ac
SC
509void wxControl::MacSuperChangedPosition()
510{
e40298d5 511 MacUpdateDimensions() ;
89ebf1c9 512 wxWindow::MacSuperChangedPosition() ;
519cb848
SC
513}
514
515void wxControl::MacSuperEnabled( bool enabled )
516{
1c469f7f 517 Refresh(FALSE) ;
1c310985 518 wxWindow::MacSuperEnabled( enabled ) ;
519cb848
SC
519}
520
e40298d5 521void wxControl::MacSuperShown( bool show )
519cb848 522{
76a5e5d2 523 if ( (ControlHandle) m_macControl )
89ebf1c9
RR
524 {
525 if ( !show )
526 {
527 if ( m_macControlIsShown )
528 {
76a5e5d2 529 ::UMAHideControl( (ControlHandle) m_macControl ) ;
89ebf1c9
RR
530 m_macControlIsShown = false ;
531 }
532 }
533 else
534 {
535 if ( MacIsReallyShown() && !m_macControlIsShown )
536 {
76a5e5d2 537 ::UMAShowControl( (ControlHandle) m_macControl ) ;
89ebf1c9
RR
538 m_macControlIsShown = true ;
539 }
540 }
541 }
542
543 wxWindow::MacSuperShown( show ) ;
519cb848
SC
544}
545
546void wxControl::DoSetSize(int x, int y,
547 int width, int height,
548 int sizeFlags )
549{
327788ac 550 wxWindow::DoSetSize( x , y ,width , height ,sizeFlags ) ;
64820d33
SC
551#if 0
552 {
e40298d5
JS
553 Rect meta , control ;
554 GetControlBounds( (ControlHandle) m_macControl , &control ) ;
555 RgnHandle rgn = NewRgn() ;
556 GetControlRegion( (ControlHandle) m_macControl , kControlStructureMetaPart , rgn ) ;
557 GetRegionBounds( rgn , &meta ) ;
558 if ( !EmptyRect( &meta ) )
559 {
560 wxASSERT( meta.left >= control.left - m_macHorizontalBorder ) ;
561 wxASSERT( meta.right <= control.right + m_macHorizontalBorder ) ;
562 wxASSERT( meta.top >= control.top - m_macVerticalBorder ) ;
563 wxASSERT( meta.bottom <= control.bottom + m_macVerticalBorder ) ;
564 }
565 DisposeRgn( rgn ) ;
64820d33
SC
566 }
567#endif
327788ac 568 return ;
519cb848
SC
569}
570
519cb848
SC
571bool wxControl::Show(bool show)
572{
89ebf1c9
RR
573 if ( !wxWindow::Show( show ) )
574 return FALSE ;
575
76a5e5d2 576 if ( (ControlHandle) m_macControl )
89ebf1c9
RR
577 {
578 if ( !show )
579 {
580 if ( m_macControlIsShown )
581 {
76a5e5d2 582 ::UMAHideControl( (ControlHandle) m_macControl ) ;
89ebf1c9
RR
583 m_macControlIsShown = false ;
584 }
585 }
586 else
587 {
588 if ( MacIsReallyShown() && !m_macControlIsShown )
589 {
76a5e5d2 590 ::UMAShowControl( (ControlHandle) m_macControl ) ;
89ebf1c9
RR
591 m_macControlIsShown = true ;
592 }
593 }
594 }
595 return TRUE ;
519cb848
SC
596}
597
e7549107 598bool wxControl::Enable(bool enable)
519cb848 599{
e7549107
SC
600 if ( !wxWindow::Enable(enable) )
601 return FALSE;
519cb848 602
76a5e5d2 603 if ( (ControlHandle) m_macControl )
89ebf1c9
RR
604 {
605 if ( enable )
76a5e5d2 606 UMAActivateControl( (ControlHandle) m_macControl ) ;
89ebf1c9 607 else
76a5e5d2 608 UMADeactivateControl( (ControlHandle) m_macControl ) ;
89ebf1c9
RR
609 }
610 return TRUE ;
519cb848
SC
611}
612
613void wxControl::Refresh(bool eraseBack, const wxRect *rect)
614{
89ebf1c9 615 wxWindow::Refresh( eraseBack , rect ) ;
519cb848
SC
616}
617
2f1ae414
SC
618void wxControl::MacRedrawControl()
619{
404dfcae 620 if ( (ControlHandle) m_macControl && MacGetRootWindow() && m_macControlIsShown )
89ebf1c9 621 {
de043984
SC
622 wxClientDC dc(this) ;
623 wxMacPortSetter helper(&dc) ;
17a2c5a1 624 wxMacWindowClipper clipper(this) ;
de043984 625 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
76a5e5d2 626 UMADrawControl( (ControlHandle) m_macControl ) ;
89ebf1c9 627 }
2f1ae414
SC
628}
629
519cb848
SC
630void wxControl::OnPaint(wxPaintEvent& event)
631{
76a5e5d2 632 if ( (ControlHandle) m_macControl )
89ebf1c9 633 {
de043984
SC
634 wxPaintDC dc(this) ;
635 wxMacPortSetter helper(&dc) ;
17a2c5a1 636 wxMacWindowClipper clipper(this) ;
de043984 637 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
76a5e5d2 638 UMADrawControl( (ControlHandle) m_macControl ) ;
89ebf1c9
RR
639 }
640 else
641 {
a5a8ff8a 642 event.Skip() ;
89ebf1c9 643 }
519cb848 644}
51abe921
SC
645void wxControl::OnEraseBackground(wxEraseEvent& event)
646{
1c310985 647 wxWindow::OnEraseBackground( event ) ;
51abe921
SC
648}
649
519cb848
SC
650void wxControl::OnKeyDown( wxKeyEvent &event )
651{
76a5e5d2 652 if ( (ControlHandle) m_macControl == NULL )
89ebf1c9
RR
653 return ;
654
c5c9378c
SC
655#if TARGET_CARBON
656
e40298d5
JS
657 char charCode ;
658 UInt32 keyCode ;
c5c9378c
SC
659 UInt32 modifiers ;
660
e40298d5
JS
661 GetEventParameter( (EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode );
662 GetEventParameter( (EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode );
663 GetEventParameter((EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers);
c5c9378c
SC
664
665 ::HandleControlKey( (ControlHandle) m_macControl , keyCode , charCode , modifiers ) ;
e40298d5 666
c5c9378c 667#else
76a5e5d2 668 EventRecord *ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ;
89ebf1c9
RR
669 short keycode ;
670 short keychar ;
671 keychar = short(ev->message & charCodeMask);
672 keycode = short(ev->message & keyCodeMask) >> 8 ;
673
76a5e5d2 674 ::HandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers ) ;
c5c9378c 675#endif
519cb848
SC
676}
677
678void wxControl::OnMouseEvent( wxMouseEvent &event )
679{
76a5e5d2 680 if ( (ControlHandle) m_macControl == NULL )
89ebf1c9
RR
681 {
682 event.Skip() ;
683 return ;
684 }
685
686 if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK )
687 {
688
689 int x = event.m_x ;
690 int y = event.m_y ;
691
692 MacClientToRootWindow( &x , &y ) ;
693
694 ControlHandle control ;
695 Point localwhere ;
696 SInt16 controlpart ;
89ebf1c9
RR
697
698 localwhere.h = x ;
699 localwhere.v = y ;
700
701 short modifiers = 0;
702
703 if ( !event.m_leftDown && !event.m_rightDown )
704 modifiers |= btnState ;
705
706 if ( event.m_shiftDown )
707 modifiers |= shiftKey ;
708
709 if ( event.m_controlDown )
710 modifiers |= controlKey ;
711
712 if ( event.m_altDown )
713 modifiers |= optionKey ;
714
715 if ( event.m_metaDown )
716 modifiers |= cmdKey ;
89ebf1c9 717 {
76a5e5d2 718 control = (ControlHandle) m_macControl ;
89ebf1c9
RR
719 if ( control && ::IsControlActive( control ) )
720 {
721 {
722 controlpart = ::HandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ;
723 wxTheApp->s_lastMouseDown = 0 ;
4b26b60f 724 if ( control && controlpart != kControlNoPart )
89ebf1c9 725 {
4b26b60f 726 MacHandleControlClick( control , controlpart , false /* mouse not down anymore */ ) ;
89ebf1c9
RR
727 }
728 }
729 }
730 }
731 }
63d1f74f
SC
732 else
733 {
734 event.Skip() ;
735 }
519cb848
SC
736}
737
738bool wxControl::MacCanFocus() const
739{
e40298d5
JS
740 if ( (ControlHandle) m_macControl == NULL )
741 return true ;
742 else
743 return false ;
519cb848
SC
744}
745
4b26b60f 746void wxControl::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) )
519cb848 747{
427ff662 748 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
519cb848
SC
749}
750