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