]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/control.cpp
cast correction Profiler
[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;
e7549107
SC
150#if WXWIN_COMPATIBILITY
151 m_callback = 0;
152#endif // WXWIN_COMPATIBILITY
519cb848 153
89ebf1c9
RR
154 if ( wxMacLiveScrollbarActionUPP == NULL )
155 {
4114d0af 156#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
03e11df5
GD
157 wxMacLiveScrollbarActionUPP = NewControlActionUPP( wxMacLiveScrollbarActionProc );
158#else
89ebf1c9 159 wxMacLiveScrollbarActionUPP = NewControlActionProc( wxMacLiveScrollbarActionProc ) ;
03e11df5 160#endif
89ebf1c9 161 }
e9576ca5
SC
162}
163
2f1ae414
SC
164bool wxControl::Create(wxWindow *parent, wxWindowID id,
165 const wxPoint& pos,
166 const wxSize& size, long style,
167 const wxValidator& validator,
168 const wxString& name)
169{
89ebf1c9
RR
170 m_macControl = NULL ;
171 m_macHorizontalBorder = 0 ; // additional pixels around the real control
172 m_macVerticalBorder = 0 ;
327788ac 173
2f1ae414 174 bool rval = wxWindow::Create(parent, id, pos, size, style, name);
327788ac
SC
175 if ( parent )
176 {
177 m_backgroundColour = parent->GetBackgroundColour() ;
178 m_foregroundColour = parent->GetForegroundColour() ;
179 }
2f1ae414
SC
180 if (rval) {
181#if wxUSE_VALIDATORS
182 SetValidator(validator);
183#endif
184 }
185 return rval;
186}
187
e9576ca5
SC
188wxControl::~wxControl()
189{
e7549107 190 m_isBeingDeleted = TRUE;
17a2c5a1 191 wxRemoveMacControlAssociation( this ) ;
e9576ca5
SC
192 // If we delete an item, we should initialize the parent panel,
193 // because it could now be invalid.
9c641c05
SC
194 wxWindow *parent = GetParent() ;
195 if ( parent )
e9576ca5 196 {
9c641c05
SC
197 if (parent->GetDefaultItem() == (wxButton*) this)
198 parent->SetDefaultItem(NULL);
e9576ca5 199 }
76a5e5d2 200 if ( (ControlHandle) m_macControl )
519cb848 201 {
76a5e5d2 202 ::DisposeControl( (ControlHandle) m_macControl ) ;
89ebf1c9 203 m_macControl = NULL ;
519cb848 204 }
e9576ca5
SC
205}
206
e7549107 207void wxControl::SetLabel(const wxString& title)
e9576ca5 208{
28c98a77 209 m_label = wxStripMenuCodes(title) ;
89ebf1c9 210
427ff662 211 if ( m_macControl )
89ebf1c9 212 {
427ff662 213 UMASetControlTitle( (ControlHandle) m_macControl , m_label ) ;
89ebf1c9
RR
214 }
215 Refresh() ;
e9576ca5
SC
216}
217
37e2cb08 218wxSize wxControl::DoGetBestSize() const
e9576ca5 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
241 if ( IsKindOf( CLASSINFO( wxButton ) ) )
242 {
243 bestWidth = m_label.Length() * 8 + 12 ;
244 if ( bestWidth < 70 )
245 bestWidth = 70 ;
246 }
247 else if ( IsKindOf( CLASSINFO( wxStaticText ) ) )
248 {
249 bestWidth = m_label.Length() * 8 ;
250 }
251 else
252 bestWidth = bestsize.right - bestsize.left ;
253
254 bestWidth += 2 * m_macHorizontalBorder ;
255
256 bestHeight = bestsize.bottom - bestsize.top ;
257 if ( bestHeight < 10 )
258 bestHeight = 13 ;
259
260 bestHeight += 2 * m_macVerticalBorder;
261
262
9453cf2b 263 return wxSize(bestWidth, bestHeight);
e9576ca5
SC
264}
265
e7549107 266bool wxControl::ProcessCommand (wxCommandEvent & event)
e9576ca5
SC
267{
268 // Tries:
269 // 1) A callback function (to become obsolete)
270 // 2) OnCommand, starting at this window and working up parent hierarchy
271 // 3) OnCommand then calls ProcessEvent to search the event tables.
e7549107
SC
272#if WXWIN_COMPATIBILITY
273 if ( m_callback )
e9576ca5 274 {
e7549107
SC
275 (void)(*m_callback)(this, event);
276
277 return TRUE;
e9576ca5
SC
278 }
279 else
e7549107 280#endif // WXWIN_COMPATIBILITY
e9576ca5 281 {
e7549107 282 return GetEventHandler()->ProcessEvent(event);
e9576ca5
SC
283 }
284}
285
519cb848
SC
286// ------------------------
287wxList *wxWinMacControlList = NULL;
288wxControl *wxFindControlFromMacControl(ControlHandle inControl )
289{
290 wxNode *node = wxWinMacControlList->Find((long)inControl);
291 if (!node)
292 return NULL;
eb22f2a6 293 return (wxControl *)node->GetData();
519cb848
SC
294}
295
296void wxAssociateControlWithMacControl(ControlHandle inControl, wxControl *control)
297{
298 // adding NULL WindowRef is (first) surely a result of an error and
299 // (secondly) breaks menu command processing
427ff662 300 wxCHECK_RET( inControl != (ControlHandle) NULL, wxT("attempt to add a NULL WindowRef to window list") );
519cb848
SC
301
302 if ( !wxWinMacControlList->Find((long)inControl) )
303 wxWinMacControlList->Append((long)inControl, control);
304}
305
306void wxRemoveMacControlAssociation(wxControl *control)
307{
308 wxWinMacControlList->DeleteObject(control);
309}
310
311void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString label ,
89ebf1c9
RR
312 const wxPoint& pos,
313 const wxSize& size, long style,
314 const wxValidator& validator,
76a5e5d2 315 const wxString& name , WXRECTPTR outBounds , unsigned char* maclabel )
519cb848 316{
89ebf1c9 317 m_label = label ;
519cb848
SC
318 SetName(name);
319 if ( &validator )
89ebf1c9 320 SetValidator(validator);
519cb848
SC
321
322 m_windowStyle = style;
9453cf2b 323 parent->AddChild(this);
519cb848
SC
324
325 m_backgroundColour = parent->GetBackgroundColour() ;
326 m_foregroundColour = parent->GetForegroundColour() ;
327
328 if (id == -1)
329 m_windowId = NewControlId();
330 else
331 m_windowId = id;
332
9453cf2b
SC
333 // These sizes will be adjusted in MacPostControlCreate
334
89ebf1c9
RR
335 m_width = size.x ;
336 m_height = size.y ;
337 m_x = pos.x ;
338 m_y = pos.y ;
339
76a5e5d2
SC
340 ((Rect*)outBounds)->top = -10;
341 ((Rect*)outBounds)->left = -10;
342 ((Rect*)outBounds)->bottom = 0;
343 ((Rect*)outBounds)->right = 0;
89ebf1c9 344
c5c9378c 345 wxMacStringToPascal( wxStripMenuCodes(label) , maclabel ) ;
519cb848
SC
346}
347
348void wxControl::MacPostControlCreate()
349{
427ff662 350 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
89ebf1c9
RR
351
352 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
353 {
354 // no font
355 }
2d9d0118 356 else if ( !UMAHasAquaLayout() && (IsKindOf( CLASSINFO( wxStaticBox ) ) || IsKindOf( CLASSINFO( wxRadioBox ) ) || IsKindOf( CLASSINFO( wxButton ) ) ) )
89ebf1c9
RR
357 {
358 ControlFontStyleRec controlstyle ;
359 controlstyle.flags = kControlUseFontMask ;
360 controlstyle.font = kControlFontSmallBoldSystemFont ;
361
76a5e5d2 362 ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ;
89ebf1c9
RR
363 }
364 else
365 {
366 ControlFontStyleRec controlstyle ;
367 controlstyle.flags = kControlUseFontMask ;
4b26b60f
SC
368
369 if (IsKindOf( CLASSINFO( wxButton ) ) )
370 controlstyle.font = kControlFontSmallSystemFont ; // eventually kControlFontBigSystemFont ;
371 else
372 controlstyle.font = kControlFontSmallSystemFont ;
89ebf1c9 373
76a5e5d2 374 ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ;
89ebf1c9 375 }
76a5e5d2 376 ControlHandle container = (ControlHandle) GetParent()->MacGetContainerForEmbedding() ;
89ebf1c9 377 wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
76a5e5d2 378 ::EmbedControl( (ControlHandle) m_macControl , container ) ;
89ebf1c9
RR
379 m_macControlIsShown = true ;
380
76a5e5d2 381 wxAssociateControlWithMacControl( (ControlHandle) m_macControl , this ) ;
e40298d5
JS
382 if ( wxMacSetupControlBackgroundUPP == NULL )
383 {
384 wxMacSetupControlBackgroundUPP = NewControlColorUPP( wxMacSetupControlBackground ) ;
385 }
386 if ( wxMacControlActionUPP == NULL )
387 {
388 wxMacControlActionUPP = NewControlDefUPP( wxMacControlDefinition ) ;
389 }
111c1e2c
JS
390 // The following block of code is responsible for crashes when switching
391 // back to windows, which can be seen in the dialogs sample.
392 // It is disabled until a proper solution can be found.
393#if 0
17a2c5a1 394#if TARGET_CARBON
b6f5f27a
SC
395/*
396 only working under classic carbon
17a2c5a1
SC
397 m_macControlAction = *(**(ControlHandle)m_macControl).contrlDefProc ;
398 (**(ControlHandle)m_macControl).contrlDefProc = (Handle) &wxMacControlActionUPP ;
b6f5f27a 399*/
17a2c5a1
SC
400#else
401 m_macControlAction = *(**(ControlHandle)m_macControl).contrlDefProc ;
402
403 cdefHandle cdef ;
404 cdef = (cdefHandle) NewHandle( sizeof(cdefRec) ) ;
405 if ( (**(ControlHandle)m_macControl).contrlDefProc != NULL )
406 {
e40298d5
JS
407 (**cdef).instruction = 0x4EF9; /* JMP instruction */
408 (**cdef).function = (void(*)()) wxMacControlActionUPP;
409 (**(ControlHandle)m_macControl).contrlDefProc = (Handle) cdef ;
17a2c5a1 410 }
111c1e2c 411#endif
17a2c5a1 412#endif
e40298d5
JS
413 SetControlColorProc( (ControlHandle) m_macControl , wxMacSetupControlBackgroundUPP ) ;
414
415 // Adjust the controls size and position
416 wxPoint pos(m_x, m_y);
417 wxSize best_size( DoGetBestSize() );
418 wxSize new_size( m_width, m_height );
419
420 m_x = m_y = m_width = m_height = -1; // Forces SetSize to move/size the control
421
422 if (new_size.x == -1) {
9453cf2b 423 new_size.x = best_size.x;
e40298d5
JS
424 }
425 if (new_size.y == -1) {
426 new_size.y = best_size.y;
427 }
428
429 SetSize(pos.x, pos.y, new_size.x, new_size.y);
430
427ff662
SC
431#if wxUSE_UNICODE
432 UMASetControlTitle( (ControlHandle) m_macControl , wxStripMenuCodes(m_label) ) ;
433#endif
434
e40298d5
JS
435 UMAShowControl( (ControlHandle) m_macControl ) ;
436
437 SetCursor( *wxSTANDARD_CURSOR ) ;
438
439 Refresh() ;
519cb848
SC
440}
441
442void wxControl::MacAdjustControlRect()
443{
76a5e5d2 444 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
89ebf1c9
RR
445 if ( m_width == -1 || m_height == -1 )
446 {
447 Rect bestsize = { 0 , 0 , 0 , 0 } ;
448 short baselineoffset ;
449
76a5e5d2 450 ::GetBestControlRect( (ControlHandle) m_macControl , &bestsize , &baselineoffset ) ;
89ebf1c9
RR
451
452 if ( EmptyRect( &bestsize ) )
453 {
454 baselineoffset = 0;
455 bestsize.left = bestsize.top = 0 ;
456 bestsize.right = 16 ;
457 bestsize.bottom = 16 ;
458 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
459 {
460 bestsize.bottom = 16 ;
461 }
462 else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
463 {
464 bestsize.bottom = 24 ;
465 }
466 }
467
468 if ( m_width == -1 )
469 {
470 if ( IsKindOf( CLASSINFO( wxButton ) ) )
471 {
472 m_width = m_label.Length() * 8 + 12 ;
473 if ( m_width < 70 )
474 m_width = 70 ;
475 }
476 else if ( IsKindOf( CLASSINFO( wxStaticText ) ) )
477 {
478 m_width = m_label.Length() * 8 ;
479 }
480 else
481 m_width = bestsize.right - bestsize.left ;
482
327788ac 483 m_width += 2 * m_macHorizontalBorder + MacGetLeftBorderSize() + MacGetRightBorderSize() ;
89ebf1c9
RR
484 }
485 if ( m_height == -1 )
486 {
487 m_height = bestsize.bottom - bestsize.top ;
488 if ( m_height < 10 )
489 m_height = 13 ;
490
327788ac 491 m_height += 2 * m_macVerticalBorder + MacGetTopBorderSize() + MacGetBottomBorderSize() ;
89ebf1c9 492 }
e40298d5 493 MacUpdateDimensions() ;
327788ac 494// UMASizeControl( (ControlHandle) m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ;
89ebf1c9 495 }
519cb848 496}
76a5e5d2
SC
497
498WXWidget wxControl::MacGetContainerForEmbedding()
519cb848 499{
89ebf1c9
RR
500 if ( m_macControl )
501 return m_macControl ;
519cb848 502
89ebf1c9 503 return wxWindow::MacGetContainerForEmbedding() ;
519cb848
SC
504}
505
327788ac 506void wxControl::MacUpdateDimensions()
519cb848 507{
e40298d5
JS
508 // actually in the current systems this should never be possible, but later reparenting
509 // may become a reality
510
511 if ( (ControlHandle) m_macControl == NULL )
512 return ;
513
514 if ( GetParent() == NULL )
515 return ;
516
327788ac
SC
517 WindowRef rootwindow = (WindowRef) MacGetRootWindow() ;
518 if ( rootwindow == NULL )
e40298d5
JS
519 return ;
520
327788ac
SC
521 Rect oldBounds ;
522 GetControlBounds( (ControlHandle) m_macControl , &oldBounds ) ;
523
524 int new_x = m_x + MacGetLeftBorderSize() + m_macHorizontalBorder ;
525 int new_y = m_y + MacGetTopBorderSize() + m_macVerticalBorder ;
526 int new_width = m_width - MacGetLeftBorderSize() - MacGetRightBorderSize() - 2 * m_macHorizontalBorder ;
527 int new_height = m_height - MacGetTopBorderSize() - MacGetBottomBorderSize() - 2 * m_macVerticalBorder ;
528
529 GetParent()->MacWindowToRootWindow( & new_x , & new_y ) ;
530 bool doMove = new_x != oldBounds.left || new_y != oldBounds.top ;
531 bool doResize = ( oldBounds.right - oldBounds.left ) != new_width || (oldBounds.bottom - oldBounds.top ) != new_height ;
e40298d5
JS
532 if ( doMove || doResize )
533 {
534 InvalWindowRect( rootwindow, &oldBounds ) ;
535 if ( doMove )
536 {
537 UMAMoveControl( (ControlHandle) m_macControl , new_x , new_y ) ;
538 }
539 if ( doResize )
540 {
541 UMASizeControl( (ControlHandle) m_macControl , new_width , new_height ) ;
542 }
543 }
327788ac 544}
89ebf1c9 545
327788ac
SC
546void wxControl::MacSuperChangedPosition()
547{
e40298d5 548 MacUpdateDimensions() ;
89ebf1c9 549 wxWindow::MacSuperChangedPosition() ;
519cb848
SC
550}
551
552void wxControl::MacSuperEnabled( bool enabled )
553{
1c469f7f 554 Refresh(FALSE) ;
1c310985 555 wxWindow::MacSuperEnabled( enabled ) ;
519cb848
SC
556}
557
e40298d5 558void wxControl::MacSuperShown( bool show )
519cb848 559{
76a5e5d2 560 if ( (ControlHandle) m_macControl )
89ebf1c9
RR
561 {
562 if ( !show )
563 {
564 if ( m_macControlIsShown )
565 {
76a5e5d2 566 ::UMAHideControl( (ControlHandle) m_macControl ) ;
89ebf1c9
RR
567 m_macControlIsShown = false ;
568 }
569 }
570 else
571 {
572 if ( MacIsReallyShown() && !m_macControlIsShown )
573 {
76a5e5d2 574 ::UMAShowControl( (ControlHandle) m_macControl ) ;
89ebf1c9
RR
575 m_macControlIsShown = true ;
576 }
577 }
578 }
579
580 wxWindow::MacSuperShown( show ) ;
519cb848
SC
581}
582
583void wxControl::DoSetSize(int x, int y,
584 int width, int height,
585 int sizeFlags )
586{
327788ac 587 wxWindow::DoSetSize( x , y ,width , height ,sizeFlags ) ;
64820d33
SC
588#if 0
589 {
e40298d5
JS
590 Rect meta , control ;
591 GetControlBounds( (ControlHandle) m_macControl , &control ) ;
592 RgnHandle rgn = NewRgn() ;
593 GetControlRegion( (ControlHandle) m_macControl , kControlStructureMetaPart , rgn ) ;
594 GetRegionBounds( rgn , &meta ) ;
595 if ( !EmptyRect( &meta ) )
596 {
597 wxASSERT( meta.left >= control.left - m_macHorizontalBorder ) ;
598 wxASSERT( meta.right <= control.right + m_macHorizontalBorder ) ;
599 wxASSERT( meta.top >= control.top - m_macVerticalBorder ) ;
600 wxASSERT( meta.bottom <= control.bottom + m_macVerticalBorder ) ;
601 }
602 DisposeRgn( rgn ) ;
64820d33
SC
603 }
604#endif
327788ac
SC
605 return ;
606/*
607
76a5e5d2 608 if ( (ControlHandle) m_macControl == NULL )
89ebf1c9
RR
609 {
610 wxWindow::DoSetSize( x , y ,width , height ,sizeFlags ) ;
611 return ;
612 }
519cb848 613
0cd51b2d 614 Rect oldbounds;
9453cf2b
SC
615 int new_x, new_y, new_width, new_height;
616 int mac_x, mac_y;
617
618 new_x = m_x;
619 new_y = m_y;
620 new_width = m_width;
621 new_height = m_height;
622
623 if (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)
624 {
625 new_x = x;
626 new_y = y;
627 new_width = width;
628 new_height = height;
629 }
630 else
631 {
632 if (x != -1) new_x = x;
633 if (y != -1) new_y = y;
634 if (width != -1) new_width = width;
635 if (height != -1) new_height = height;
636 }
637
638 if(sizeFlags & wxSIZE_AUTO)
639 {
640 wxSize size = GetBestSize();
641 if (sizeFlags & wxSIZE_AUTO_WIDTH)
642 {
643 if (width == -1) new_width = size.x;
644 }
645 if (sizeFlags & wxSIZE_AUTO_HEIGHT)
646 {
647 if (height == -1) new_height = size.y;
648 }
649 }
1c310985 650 AdjustForParentClientOrigin(new_x, new_y, sizeFlags);
9453cf2b
SC
651
652 mac_x = new_x;
653 mac_y = new_y;
654 if(GetParent()) {
1c310985 655 GetParent()->MacWindowToRootWindow(&mac_x, &mac_y);
9453cf2b 656 }
76a5e5d2 657 GetControlBounds( (ControlHandle) m_macControl, &oldbounds);
9453cf2b
SC
658 oldbounds.right = oldbounds.left + m_width;
659 oldbounds.bottom = oldbounds.top + m_height;
660
661 bool doMove = false;
662 bool doResize = false;
663
664 if ( mac_x != (oldbounds.left - m_macHorizontalBorder) ||
665 mac_y != (oldbounds.top - m_macVerticalBorder) )
666 {
667 doMove = true ;
668 }
669 if ( new_width != oldbounds.right - oldbounds.left - 2 * m_macHorizontalBorder ||
670 new_height != oldbounds.bottom - oldbounds.top - 2 * m_macVerticalBorder)
671 {
672 doResize = true ;
673 }
674
675 if ( doMove || doResize )
676 {
1c310985
SC
677 Refresh() ;
678
9453cf2b
SC
679 // Ensure resize is within constraints
680 if ((m_minWidth != -1) && (new_width < m_minWidth)) {
681 new_width = m_minWidth;
682 }
683 if ((m_minHeight != -1) && (new_height < m_minHeight)) {
684 new_height = m_minHeight;
685 }
686 if ((m_maxWidth != -1) && (new_width > m_maxWidth)) {
687 new_width = m_maxWidth;
688 }
689 if ((m_maxHeight != -1) && (new_height > m_maxHeight)) {
690 new_height = m_maxHeight;
691 }
692
693 if ( doMove )
694 {
695 m_x = new_x;
696 m_y = new_y;
697
76a5e5d2 698 UMAMoveControl( (ControlHandle) m_macControl,
9453cf2b 699 mac_x + m_macHorizontalBorder, mac_y + m_macVerticalBorder);
1c310985 700
9453cf2b
SC
701 wxMoveEvent event(wxPoint(m_x, m_y), m_windowId);
702 event.SetEventObject(this);
703 GetEventHandler()->ProcessEvent(event) ;
704 }
705 if ( doResize )
706 {
707 m_width = new_width;
708 m_height = new_height;
709
76a5e5d2 710 UMASizeControl( (ControlHandle) m_macControl,
9453cf2b
SC
711 m_width - 2 * m_macHorizontalBorder,
712 m_height - 2 * m_macVerticalBorder ) ;
713
abfe4a84 714
9453cf2b
SC
715 wxSizeEvent event(wxSize(m_width, m_height), m_windowId);
716 event.SetEventObject(this);
717 GetEventHandler()->ProcessEvent(event);
718 }
719
1c310985 720 Refresh() ;
9453cf2b 721 }
327788ac 722*/
519cb848
SC
723}
724
519cb848
SC
725bool wxControl::Show(bool show)
726{
89ebf1c9
RR
727 if ( !wxWindow::Show( show ) )
728 return FALSE ;
729
76a5e5d2 730 if ( (ControlHandle) m_macControl )
89ebf1c9
RR
731 {
732 if ( !show )
733 {
734 if ( m_macControlIsShown )
735 {
76a5e5d2 736 ::UMAHideControl( (ControlHandle) m_macControl ) ;
89ebf1c9
RR
737 m_macControlIsShown = false ;
738 }
739 }
740 else
741 {
742 if ( MacIsReallyShown() && !m_macControlIsShown )
743 {
76a5e5d2 744 ::UMAShowControl( (ControlHandle) m_macControl ) ;
89ebf1c9
RR
745 m_macControlIsShown = true ;
746 }
747 }
748 }
749 return TRUE ;
519cb848
SC
750}
751
e7549107 752bool wxControl::Enable(bool enable)
519cb848 753{
e7549107
SC
754 if ( !wxWindow::Enable(enable) )
755 return FALSE;
519cb848 756
76a5e5d2 757 if ( (ControlHandle) m_macControl )
89ebf1c9
RR
758 {
759 if ( enable )
76a5e5d2 760 UMAActivateControl( (ControlHandle) m_macControl ) ;
89ebf1c9 761 else
76a5e5d2 762 UMADeactivateControl( (ControlHandle) m_macControl ) ;
89ebf1c9
RR
763 }
764 return TRUE ;
519cb848
SC
765}
766
767void wxControl::Refresh(bool eraseBack, const wxRect *rect)
768{
89ebf1c9 769 wxWindow::Refresh( eraseBack , rect ) ;
519cb848
SC
770}
771
2f1ae414
SC
772void wxControl::MacRedrawControl()
773{
404dfcae 774 if ( (ControlHandle) m_macControl && MacGetRootWindow() && m_macControlIsShown )
89ebf1c9 775 {
de043984
SC
776 wxClientDC dc(this) ;
777 wxMacPortSetter helper(&dc) ;
17a2c5a1 778 wxMacWindowClipper clipper(this) ;
de043984 779 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
76a5e5d2 780 UMADrawControl( (ControlHandle) m_macControl ) ;
89ebf1c9 781 }
2f1ae414
SC
782}
783
519cb848
SC
784void wxControl::OnPaint(wxPaintEvent& event)
785{
76a5e5d2 786 if ( (ControlHandle) m_macControl )
89ebf1c9 787 {
de043984
SC
788 wxPaintDC dc(this) ;
789 wxMacPortSetter helper(&dc) ;
17a2c5a1 790 wxMacWindowClipper clipper(this) ;
de043984 791 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
76a5e5d2 792 UMADrawControl( (ControlHandle) m_macControl ) ;
89ebf1c9
RR
793 }
794 else
795 {
a5a8ff8a 796 event.Skip() ;
89ebf1c9 797 }
519cb848 798}
51abe921
SC
799void wxControl::OnEraseBackground(wxEraseEvent& event)
800{
1c310985 801 wxWindow::OnEraseBackground( event ) ;
51abe921
SC
802}
803
519cb848
SC
804void wxControl::OnKeyDown( wxKeyEvent &event )
805{
76a5e5d2 806 if ( (ControlHandle) m_macControl == NULL )
89ebf1c9
RR
807 return ;
808
c5c9378c
SC
809#if TARGET_CARBON
810
e40298d5
JS
811 char charCode ;
812 UInt32 keyCode ;
c5c9378c
SC
813 UInt32 modifiers ;
814
e40298d5
JS
815 GetEventParameter( (EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode );
816 GetEventParameter( (EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode );
817 GetEventParameter((EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers);
c5c9378c
SC
818
819 ::HandleControlKey( (ControlHandle) m_macControl , keyCode , charCode , modifiers ) ;
e40298d5 820
c5c9378c 821#else
76a5e5d2 822 EventRecord *ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ;
89ebf1c9
RR
823 short keycode ;
824 short keychar ;
825 keychar = short(ev->message & charCodeMask);
826 keycode = short(ev->message & keyCodeMask) >> 8 ;
827
76a5e5d2 828 ::HandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers ) ;
c5c9378c 829#endif
519cb848
SC
830}
831
832void wxControl::OnMouseEvent( wxMouseEvent &event )
833{
76a5e5d2 834 if ( (ControlHandle) m_macControl == NULL )
89ebf1c9
RR
835 {
836 event.Skip() ;
837 return ;
838 }
839
840 if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK )
841 {
842
843 int x = event.m_x ;
844 int y = event.m_y ;
845
846 MacClientToRootWindow( &x , &y ) ;
847
848 ControlHandle control ;
849 Point localwhere ;
850 SInt16 controlpart ;
89ebf1c9
RR
851
852 localwhere.h = x ;
853 localwhere.v = y ;
854
855 short modifiers = 0;
856
857 if ( !event.m_leftDown && !event.m_rightDown )
858 modifiers |= btnState ;
859
860 if ( event.m_shiftDown )
861 modifiers |= shiftKey ;
862
863 if ( event.m_controlDown )
864 modifiers |= controlKey ;
865
866 if ( event.m_altDown )
867 modifiers |= optionKey ;
868
869 if ( event.m_metaDown )
870 modifiers |= cmdKey ;
89ebf1c9 871 {
76a5e5d2 872 control = (ControlHandle) m_macControl ;
89ebf1c9
RR
873 if ( control && ::IsControlActive( control ) )
874 {
875 {
876 controlpart = ::HandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ;
877 wxTheApp->s_lastMouseDown = 0 ;
4b26b60f 878 if ( control && controlpart != kControlNoPart )
89ebf1c9 879 {
4b26b60f 880 MacHandleControlClick( control , controlpart , false /* mouse not down anymore */ ) ;
89ebf1c9
RR
881 }
882 }
883 }
884 }
885 }
63d1f74f
SC
886 else
887 {
888 event.Skip() ;
889 }
519cb848
SC
890}
891
892bool wxControl::MacCanFocus() const
893{
e40298d5
JS
894 if ( (ControlHandle) m_macControl == NULL )
895 return true ;
896 else
897 return false ;
519cb848
SC
898}
899
4b26b60f 900void wxControl::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) )
519cb848 901{
427ff662 902 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
519cb848
SC
903}
904