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