]> git.saurik.com Git - wxWidgets.git/blame - src/mac/control.cpp
Applied [ 590985 ] fix for radiobox under motif
[wxWidgets.git] / src / mac / control.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: control.cpp
3// Purpose: wxControl class
4// Author: AUTHOR
5// Modified by:
6// Created: ??/??/98
7// RCS-ID: $Id$
8// Copyright: (c) AUTHOR
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 )
ca453266 39// EVT_CHAR( wxControl::OnKeyDown )
89ebf1c9 40 EVT_PAINT( wxControl::OnPaint )
e9576ca5 41END_EVENT_TABLE()
2f1ae414 42#endif
e9576ca5 43
d497dca4 44#include "wx/mac/uma.h"
7372fd0a 45#include "wx/mac/private.h"
519cb848 46
e9576ca5 47// Item members
519cb848
SC
48
49ControlActionUPP wxMacLiveScrollbarActionUPP = NULL ;
50
2f1ae414 51pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode ) ;
519cb848
SC
52pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode )
53{
89ebf1c9
RR
54 if ( partCode != 0)
55 {
56 wxControl* wx = (wxControl*) GetControlReference( control ) ;
57 if ( wx )
58 {
59 wx->MacHandleControlClick( control , partCode ) ;
60 }
61 }
519cb848
SC
62}
63
692f921a
SC
64ControlColorUPP wxMacSetupControlBackgroundUPP = NULL ;
65
66pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessage , SInt16 iDepth , Boolean iIsColor )
67{
68 OSStatus status = noErr ;
69 switch( iMessage )
70 {
71 case kControlMsgSetUpBackground :
692f921a 72 {
f03c50fa
SC
73 wxControl* wx = (wxControl*) GetControlReference( iControl ) ;
74 if ( wx != NULL && wx->IsKindOf( CLASSINFO( wxControl ) ) )
75 {
76 wxDC::MacSetupBackgroundForCurrentPort( wx->MacGetBackgroundBrush() ) ;
77 // SetThemeBackground( iDepth , iIsColor ) ;
78 }
79 else
80 {
81 status = paramErr ;
82 }
692f921a
SC
83 }
84 break ;
85 default :
86 status = paramErr ;
87 break ;
88 }
89 return status ;
90}
91
e9576ca5
SC
92wxControl::wxControl()
93{
89ebf1c9
RR
94 m_macControl = NULL ;
95 m_macHorizontalBorder = 0 ; // additional pixels around the real control
96 m_macVerticalBorder = 0 ;
e9576ca5
SC
97 m_backgroundColour = *wxWHITE;
98 m_foregroundColour = *wxBLACK;
e7549107
SC
99#if WXWIN_COMPATIBILITY
100 m_callback = 0;
101#endif // WXWIN_COMPATIBILITY
519cb848 102
89ebf1c9
RR
103 if ( wxMacLiveScrollbarActionUPP == NULL )
104 {
4114d0af 105#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
03e11df5
GD
106 wxMacLiveScrollbarActionUPP = NewControlActionUPP( wxMacLiveScrollbarActionProc );
107#else
89ebf1c9 108 wxMacLiveScrollbarActionUPP = NewControlActionProc( wxMacLiveScrollbarActionProc ) ;
03e11df5 109#endif
89ebf1c9 110 }
e9576ca5
SC
111}
112
2f1ae414
SC
113bool wxControl::Create(wxWindow *parent, wxWindowID id,
114 const wxPoint& pos,
115 const wxSize& size, long style,
116 const wxValidator& validator,
117 const wxString& name)
118{
89ebf1c9
RR
119 m_macControl = NULL ;
120 m_macHorizontalBorder = 0 ; // additional pixels around the real control
121 m_macVerticalBorder = 0 ;
327788ac 122
2f1ae414 123 bool rval = wxWindow::Create(parent, id, pos, size, style, name);
327788ac
SC
124 if ( parent )
125 {
126 m_backgroundColour = parent->GetBackgroundColour() ;
127 m_foregroundColour = parent->GetForegroundColour() ;
128 }
2f1ae414
SC
129 if (rval) {
130#if wxUSE_VALIDATORS
131 SetValidator(validator);
132#endif
133 }
134 return rval;
135}
136
e9576ca5
SC
137wxControl::~wxControl()
138{
e7549107 139 m_isBeingDeleted = TRUE;
e9576ca5
SC
140 // If we delete an item, we should initialize the parent panel,
141 // because it could now be invalid.
9c641c05
SC
142 wxWindow *parent = GetParent() ;
143 if ( parent )
e9576ca5 144 {
9c641c05
SC
145 if (parent->GetDefaultItem() == (wxButton*) this)
146 parent->SetDefaultItem(NULL);
e9576ca5 147 }
76a5e5d2 148 if ( (ControlHandle) m_macControl )
519cb848 149 {
76a5e5d2 150 ::DisposeControl( (ControlHandle) m_macControl ) ;
89ebf1c9 151 m_macControl = NULL ;
519cb848 152 }
e9576ca5
SC
153}
154
e7549107 155void wxControl::SetLabel(const wxString& title)
e9576ca5 156{
28c98a77 157 m_label = wxStripMenuCodes(title) ;
89ebf1c9 158
76a5e5d2 159 if ( (ControlHandle) m_macControl )
89ebf1c9
RR
160 {
161 Str255 maclabel ;
162 wxString label ;
163
164 if( wxApp::s_macDefaultEncodingIsPC )
28c98a77 165 label = wxMacMakeMacStringFromPC( m_label ) ;
89ebf1c9 166 else
28c98a77 167 label = m_label ;
89ebf1c9 168
03e11df5 169#if TARGET_CARBON
89ebf1c9 170 c2pstrcpy( (StringPtr) maclabel , label ) ;
03e11df5 171#else
89ebf1c9
RR
172 strcpy( (char *) maclabel , label ) ;
173 c2pstr( (char *) maclabel ) ;
03e11df5 174#endif
76a5e5d2 175 ::SetControlTitle( (ControlHandle) m_macControl , maclabel ) ;
89ebf1c9
RR
176 }
177 Refresh() ;
e9576ca5
SC
178}
179
37e2cb08 180wxSize wxControl::DoGetBestSize() const
e9576ca5 181{
89ebf1c9
RR
182 Rect bestsize = { 0 , 0 , 0 , 0 } ;
183 short baselineoffset ;
184 int bestWidth, bestHeight ;
76a5e5d2 185 ::GetBestControlRect( (ControlHandle) m_macControl , &bestsize , &baselineoffset ) ;
89ebf1c9
RR
186
187 if ( EmptyRect( &bestsize ) )
188 {
189 baselineoffset = 0;
190 bestsize.left = bestsize.top = 0 ;
191 bestsize.right = 16 ;
192 bestsize.bottom = 16 ;
193 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
194 {
195 bestsize.bottom = 16 ;
196 }
197 else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
198 {
199 bestsize.bottom = 24 ;
200 }
201 }
202
203 if ( IsKindOf( CLASSINFO( wxButton ) ) )
204 {
205 bestWidth = m_label.Length() * 8 + 12 ;
206 if ( bestWidth < 70 )
207 bestWidth = 70 ;
208 }
209 else if ( IsKindOf( CLASSINFO( wxStaticText ) ) )
210 {
211 bestWidth = m_label.Length() * 8 ;
212 }
213 else
214 bestWidth = bestsize.right - bestsize.left ;
215
216 bestWidth += 2 * m_macHorizontalBorder ;
217
218 bestHeight = bestsize.bottom - bestsize.top ;
219 if ( bestHeight < 10 )
220 bestHeight = 13 ;
221
222 bestHeight += 2 * m_macVerticalBorder;
223
224
9453cf2b 225 return wxSize(bestWidth, bestHeight);
e9576ca5
SC
226}
227
e7549107 228bool wxControl::ProcessCommand (wxCommandEvent & event)
e9576ca5
SC
229{
230 // Tries:
231 // 1) A callback function (to become obsolete)
232 // 2) OnCommand, starting at this window and working up parent hierarchy
233 // 3) OnCommand then calls ProcessEvent to search the event tables.
e7549107
SC
234#if WXWIN_COMPATIBILITY
235 if ( m_callback )
e9576ca5 236 {
e7549107
SC
237 (void)(*m_callback)(this, event);
238
239 return TRUE;
e9576ca5
SC
240 }
241 else
e7549107 242#endif // WXWIN_COMPATIBILITY
e9576ca5 243 {
e7549107 244 return GetEventHandler()->ProcessEvent(event);
e9576ca5
SC
245 }
246}
247
519cb848
SC
248// ------------------------
249wxList *wxWinMacControlList = NULL;
250wxControl *wxFindControlFromMacControl(ControlHandle inControl )
251{
252 wxNode *node = wxWinMacControlList->Find((long)inControl);
253 if (!node)
254 return NULL;
255 return (wxControl *)node->Data();
256}
257
258void wxAssociateControlWithMacControl(ControlHandle inControl, wxControl *control)
259{
260 // adding NULL WindowRef is (first) surely a result of an error and
261 // (secondly) breaks menu command processing
262 wxCHECK_RET( inControl != (ControlHandle) NULL, "attempt to add a NULL WindowRef to window list" );
263
264 if ( !wxWinMacControlList->Find((long)inControl) )
265 wxWinMacControlList->Append((long)inControl, control);
266}
267
268void wxRemoveMacControlAssociation(wxControl *control)
269{
270 wxWinMacControlList->DeleteObject(control);
271}
272
273void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString label ,
89ebf1c9
RR
274 const wxPoint& pos,
275 const wxSize& size, long style,
276 const wxValidator& validator,
76a5e5d2 277 const wxString& name , WXRECTPTR outBounds , unsigned char* maclabel )
519cb848 278{
89ebf1c9 279 m_label = label ;
519cb848
SC
280 SetName(name);
281 if ( &validator )
89ebf1c9 282 SetValidator(validator);
519cb848
SC
283
284 m_windowStyle = style;
9453cf2b 285 parent->AddChild(this);
519cb848
SC
286
287 m_backgroundColour = parent->GetBackgroundColour() ;
288 m_foregroundColour = parent->GetForegroundColour() ;
289
290 if (id == -1)
291 m_windowId = NewControlId();
292 else
293 m_windowId = id;
294
9453cf2b
SC
295 // These sizes will be adjusted in MacPostControlCreate
296
89ebf1c9
RR
297 m_width = size.x ;
298 m_height = size.y ;
299 m_x = pos.x ;
300 m_y = pos.y ;
301
76a5e5d2
SC
302 ((Rect*)outBounds)->top = -10;
303 ((Rect*)outBounds)->left = -10;
304 ((Rect*)outBounds)->bottom = 0;
305 ((Rect*)outBounds)->right = 0;
89ebf1c9
RR
306
307 char c_text[255];
308 strcpy( c_text , label ) ;
309 if( wxApp::s_macDefaultEncodingIsPC )
310 {
311 wxMacConvertFromPCForControls( c_text ) ;
312 }
519cb848 313
03e11df5 314#if TARGET_CARBON
89ebf1c9 315 c2pstrcpy( (StringPtr) maclabel , c_text ) ;
03e11df5 316#else
89ebf1c9
RR
317 strcpy( (char *) maclabel , c_text ) ;
318 c2pstr( (char *) maclabel ) ;
03e11df5 319#endif
519cb848
SC
320}
321
322void wxControl::MacPostControlCreate()
323{
76a5e5d2 324 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , "No valid mac control" ) ;
89ebf1c9
RR
325
326 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
327 {
328 // no font
329 }
2d9d0118 330 else if ( !UMAHasAquaLayout() && (IsKindOf( CLASSINFO( wxStaticBox ) ) || IsKindOf( CLASSINFO( wxRadioBox ) ) || IsKindOf( CLASSINFO( wxButton ) ) ) )
89ebf1c9
RR
331 {
332 ControlFontStyleRec controlstyle ;
333 controlstyle.flags = kControlUseFontMask ;
334 controlstyle.font = kControlFontSmallBoldSystemFont ;
335
76a5e5d2 336 ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ;
89ebf1c9
RR
337 }
338 else
339 {
340 ControlFontStyleRec controlstyle ;
341 controlstyle.flags = kControlUseFontMask ;
342 controlstyle.font = kControlFontSmallSystemFont ;
343
76a5e5d2 344 ::SetControlFontStyle( (ControlHandle) m_macControl , &controlstyle ) ;
89ebf1c9 345 }
76a5e5d2 346 ControlHandle container = (ControlHandle) GetParent()->MacGetContainerForEmbedding() ;
89ebf1c9 347 wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
76a5e5d2 348 ::EmbedControl( (ControlHandle) m_macControl , container ) ;
89ebf1c9
RR
349 m_macControlIsShown = true ;
350
76a5e5d2 351 wxAssociateControlWithMacControl( (ControlHandle) m_macControl , this ) ;
9453cf2b 352
692f921a
SC
353 if ( wxMacSetupControlBackgroundUPP == NULL )
354 {
355 wxMacSetupControlBackgroundUPP = NewControlColorUPP( wxMacSetupControlBackground ) ;
356 }
357 SetControlColorProc( (ControlHandle) m_macControl , wxMacSetupControlBackgroundUPP ) ;
9453cf2b
SC
358
359 // Adjust the controls size and position
360 wxPoint pos(m_x, m_y);
361 wxSize best_size( DoGetBestSize() );
362 wxSize new_size( m_width, m_height );
363
364 m_x = m_y = m_width = m_height = -1; // Forces SetSize to move/size the control
365
366 if (new_size.x == -1) {
367 new_size.x = best_size.x;
368 }
369 if (new_size.y == -1) {
370 new_size.y = best_size.y;
371 }
372
373 SetSize(pos.x, pos.y, new_size.x, new_size.y);
374
76a5e5d2 375 UMAShowControl( (ControlHandle) m_macControl ) ;
a5a8ff8a 376 Refresh() ;
519cb848
SC
377}
378
379void wxControl::MacAdjustControlRect()
380{
76a5e5d2 381 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
89ebf1c9
RR
382 if ( m_width == -1 || m_height == -1 )
383 {
384 Rect bestsize = { 0 , 0 , 0 , 0 } ;
385 short baselineoffset ;
386
76a5e5d2 387 ::GetBestControlRect( (ControlHandle) m_macControl , &bestsize , &baselineoffset ) ;
89ebf1c9
RR
388
389 if ( EmptyRect( &bestsize ) )
390 {
391 baselineoffset = 0;
392 bestsize.left = bestsize.top = 0 ;
393 bestsize.right = 16 ;
394 bestsize.bottom = 16 ;
395 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
396 {
397 bestsize.bottom = 16 ;
398 }
399 else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
400 {
401 bestsize.bottom = 24 ;
402 }
403 }
404
405 if ( m_width == -1 )
406 {
407 if ( IsKindOf( CLASSINFO( wxButton ) ) )
408 {
409 m_width = m_label.Length() * 8 + 12 ;
410 if ( m_width < 70 )
411 m_width = 70 ;
412 }
413 else if ( IsKindOf( CLASSINFO( wxStaticText ) ) )
414 {
415 m_width = m_label.Length() * 8 ;
416 }
417 else
418 m_width = bestsize.right - bestsize.left ;
419
327788ac 420 m_width += 2 * m_macHorizontalBorder + MacGetLeftBorderSize() + MacGetRightBorderSize() ;
89ebf1c9
RR
421 }
422 if ( m_height == -1 )
423 {
424 m_height = bestsize.bottom - bestsize.top ;
425 if ( m_height < 10 )
426 m_height = 13 ;
427
327788ac 428 m_height += 2 * m_macVerticalBorder + MacGetTopBorderSize() + MacGetBottomBorderSize() ;
89ebf1c9 429 }
327788ac
SC
430 MacUpdateDimensions() ;
431// UMASizeControl( (ControlHandle) m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ;
89ebf1c9 432 }
519cb848 433}
76a5e5d2
SC
434
435WXWidget wxControl::MacGetContainerForEmbedding()
519cb848 436{
89ebf1c9
RR
437 if ( m_macControl )
438 return m_macControl ;
519cb848 439
89ebf1c9 440 return wxWindow::MacGetContainerForEmbedding() ;
519cb848
SC
441}
442
327788ac 443void wxControl::MacUpdateDimensions()
519cb848 444{
327788ac
SC
445 // actually in the current systems this should never be possible, but later reparenting
446 // may become a reality
447
448 if ( (ControlHandle) m_macControl == NULL )
449 return ;
450
451 if ( GetParent() == NULL )
452 return ;
453
454 WindowRef rootwindow = (WindowRef) MacGetRootWindow() ;
455 if ( rootwindow == NULL )
456 return ;
457
458 Rect oldBounds ;
459 GetControlBounds( (ControlHandle) m_macControl , &oldBounds ) ;
460
461 int new_x = m_x + MacGetLeftBorderSize() + m_macHorizontalBorder ;
462 int new_y = m_y + MacGetTopBorderSize() + m_macVerticalBorder ;
463 int new_width = m_width - MacGetLeftBorderSize() - MacGetRightBorderSize() - 2 * m_macHorizontalBorder ;
464 int new_height = m_height - MacGetTopBorderSize() - MacGetBottomBorderSize() - 2 * m_macVerticalBorder ;
465
466 GetParent()->MacWindowToRootWindow( & new_x , & new_y ) ;
467 bool doMove = new_x != oldBounds.left || new_y != oldBounds.top ;
468 bool doResize = ( oldBounds.right - oldBounds.left ) != new_width || (oldBounds.bottom - oldBounds.top ) != new_height ;
469 if ( doMove || doResize )
470 {
471 InvalWindowRect( rootwindow, &oldBounds ) ;
472 if ( doMove )
473 {
474 UMAMoveControl( (ControlHandle) m_macControl , new_x , new_y ) ;
475 }
476 if ( doResize )
477 {
478 UMASizeControl( (ControlHandle) m_macControl , new_width , new_height ) ;
479 }
480 }
481}
89ebf1c9 482
327788ac
SC
483void wxControl::MacSuperChangedPosition()
484{
485 MacUpdateDimensions() ;
89ebf1c9 486 wxWindow::MacSuperChangedPosition() ;
519cb848
SC
487}
488
489void wxControl::MacSuperEnabled( bool enabled )
490{
1c469f7f 491 Refresh(FALSE) ;
1c310985 492 wxWindow::MacSuperEnabled( enabled ) ;
519cb848
SC
493}
494
495void wxControl::MacSuperShown( bool show )
496{
76a5e5d2 497 if ( (ControlHandle) m_macControl )
89ebf1c9
RR
498 {
499 if ( !show )
500 {
501 if ( m_macControlIsShown )
502 {
76a5e5d2 503 ::UMAHideControl( (ControlHandle) m_macControl ) ;
89ebf1c9
RR
504 m_macControlIsShown = false ;
505 }
506 }
507 else
508 {
509 if ( MacIsReallyShown() && !m_macControlIsShown )
510 {
76a5e5d2 511 ::UMAShowControl( (ControlHandle) m_macControl ) ;
89ebf1c9
RR
512 m_macControlIsShown = true ;
513 }
514 }
515 }
516
517 wxWindow::MacSuperShown( show ) ;
519cb848
SC
518}
519
520void wxControl::DoSetSize(int x, int y,
521 int width, int height,
522 int sizeFlags )
523{
327788ac
SC
524 wxWindow::DoSetSize( x , y ,width , height ,sizeFlags ) ;
525 return ;
526/*
527
76a5e5d2 528 if ( (ControlHandle) m_macControl == NULL )
89ebf1c9
RR
529 {
530 wxWindow::DoSetSize( x , y ,width , height ,sizeFlags ) ;
531 return ;
532 }
519cb848 533
0cd51b2d 534 Rect oldbounds;
9453cf2b
SC
535 int new_x, new_y, new_width, new_height;
536 int mac_x, mac_y;
537
538 new_x = m_x;
539 new_y = m_y;
540 new_width = m_width;
541 new_height = m_height;
542
543 if (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)
544 {
545 new_x = x;
546 new_y = y;
547 new_width = width;
548 new_height = height;
549 }
550 else
551 {
552 if (x != -1) new_x = x;
553 if (y != -1) new_y = y;
554 if (width != -1) new_width = width;
555 if (height != -1) new_height = height;
556 }
557
558 if(sizeFlags & wxSIZE_AUTO)
559 {
560 wxSize size = GetBestSize();
561 if (sizeFlags & wxSIZE_AUTO_WIDTH)
562 {
563 if (width == -1) new_width = size.x;
564 }
565 if (sizeFlags & wxSIZE_AUTO_HEIGHT)
566 {
567 if (height == -1) new_height = size.y;
568 }
569 }
1c310985 570 AdjustForParentClientOrigin(new_x, new_y, sizeFlags);
9453cf2b
SC
571
572 mac_x = new_x;
573 mac_y = new_y;
574 if(GetParent()) {
1c310985 575 GetParent()->MacWindowToRootWindow(&mac_x, &mac_y);
9453cf2b 576 }
76a5e5d2 577 GetControlBounds( (ControlHandle) m_macControl, &oldbounds);
9453cf2b
SC
578 oldbounds.right = oldbounds.left + m_width;
579 oldbounds.bottom = oldbounds.top + m_height;
580
581 bool doMove = false;
582 bool doResize = false;
583
584 if ( mac_x != (oldbounds.left - m_macHorizontalBorder) ||
585 mac_y != (oldbounds.top - m_macVerticalBorder) )
586 {
587 doMove = true ;
588 }
589 if ( new_width != oldbounds.right - oldbounds.left - 2 * m_macHorizontalBorder ||
590 new_height != oldbounds.bottom - oldbounds.top - 2 * m_macVerticalBorder)
591 {
592 doResize = true ;
593 }
594
595 if ( doMove || doResize )
596 {
1c310985
SC
597 Refresh() ;
598
9453cf2b
SC
599 // Ensure resize is within constraints
600 if ((m_minWidth != -1) && (new_width < m_minWidth)) {
601 new_width = m_minWidth;
602 }
603 if ((m_minHeight != -1) && (new_height < m_minHeight)) {
604 new_height = m_minHeight;
605 }
606 if ((m_maxWidth != -1) && (new_width > m_maxWidth)) {
607 new_width = m_maxWidth;
608 }
609 if ((m_maxHeight != -1) && (new_height > m_maxHeight)) {
610 new_height = m_maxHeight;
611 }
612
613 if ( doMove )
614 {
615 m_x = new_x;
616 m_y = new_y;
617
76a5e5d2 618 UMAMoveControl( (ControlHandle) m_macControl,
9453cf2b 619 mac_x + m_macHorizontalBorder, mac_y + m_macVerticalBorder);
1c310985 620
9453cf2b
SC
621 wxMoveEvent event(wxPoint(m_x, m_y), m_windowId);
622 event.SetEventObject(this);
623 GetEventHandler()->ProcessEvent(event) ;
624 }
625 if ( doResize )
626 {
627 m_width = new_width;
628 m_height = new_height;
629
76a5e5d2 630 UMASizeControl( (ControlHandle) m_macControl,
9453cf2b
SC
631 m_width - 2 * m_macHorizontalBorder,
632 m_height - 2 * m_macVerticalBorder ) ;
633
abfe4a84 634
9453cf2b
SC
635 wxSizeEvent event(wxSize(m_width, m_height), m_windowId);
636 event.SetEventObject(this);
637 GetEventHandler()->ProcessEvent(event);
638 }
639
1c310985 640 Refresh() ;
9453cf2b 641 }
327788ac 642*/
519cb848
SC
643}
644
519cb848
SC
645bool wxControl::Show(bool show)
646{
89ebf1c9
RR
647 if ( !wxWindow::Show( show ) )
648 return FALSE ;
649
76a5e5d2 650 if ( (ControlHandle) m_macControl )
89ebf1c9
RR
651 {
652 if ( !show )
653 {
654 if ( m_macControlIsShown )
655 {
76a5e5d2 656 ::UMAHideControl( (ControlHandle) m_macControl ) ;
89ebf1c9
RR
657 m_macControlIsShown = false ;
658 }
659 }
660 else
661 {
662 if ( MacIsReallyShown() && !m_macControlIsShown )
663 {
76a5e5d2 664 ::UMAShowControl( (ControlHandle) m_macControl ) ;
89ebf1c9
RR
665 m_macControlIsShown = true ;
666 }
667 }
668 }
669 return TRUE ;
519cb848
SC
670}
671
e7549107 672bool wxControl::Enable(bool enable)
519cb848 673{
e7549107
SC
674 if ( !wxWindow::Enable(enable) )
675 return FALSE;
519cb848 676
76a5e5d2 677 if ( (ControlHandle) m_macControl )
89ebf1c9
RR
678 {
679 if ( enable )
76a5e5d2 680 UMAActivateControl( (ControlHandle) m_macControl ) ;
89ebf1c9 681 else
76a5e5d2 682 UMADeactivateControl( (ControlHandle) m_macControl ) ;
89ebf1c9
RR
683 }
684 return TRUE ;
519cb848
SC
685}
686
687void wxControl::Refresh(bool eraseBack, const wxRect *rect)
688{
89ebf1c9 689 wxWindow::Refresh( eraseBack , rect ) ;
519cb848
SC
690}
691
2f1ae414
SC
692void wxControl::MacRedrawControl()
693{
76a5e5d2 694 if ( (ControlHandle) m_macControl && MacGetRootWindow() )
89ebf1c9 695 {
de043984
SC
696 wxClientDC dc(this) ;
697 wxMacPortSetter helper(&dc) ;
b8f2db1f
SC
698/*
699 Rect r = { 0 , 0 , 32000 , 32000 } ;
700 ClipRect( &r ) ;
701*/
7372fd0a 702 int x = 0 , y = 0;
b8f2db1f
SC
703 wxWindow *parent = GetParent() ;
704 parent->MacWindowToRootWindow( &x,&y ) ;
7372fd0a 705 RgnHandle clrgn = NewRgn() ;
b8f2db1f
SC
706 RgnHandle insidergn = NewRgn() ;
707 wxSize size = parent->GetSize() ;
708 SetRectRgn( insidergn , parent->MacGetLeftBorderSize() , parent->MacGetTopBorderSize() ,
709 size.x - parent->MacGetLeftBorderSize() - parent->MacGetRightBorderSize(),
710 size.y - parent->MacGetTopBorderSize() - parent->MacGetBottomBorderSize()) ;
711
712 CopyRgn( (RgnHandle) parent->MacGetVisibleRegion(false).GetWXHRGN() , clrgn ) ;
713 SectRgn( clrgn , insidergn , clrgn ) ;
7372fd0a
SC
714 OffsetRgn( clrgn , x , y ) ;
715 SetClip( clrgn ) ;
b8f2db1f
SC
716 DisposeRgn( clrgn ) ;
717 DisposeRgn( insidergn ) ;
7372fd0a 718
de043984 719 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
76a5e5d2 720 UMADrawControl( (ControlHandle) m_macControl ) ;
89ebf1c9 721 }
2f1ae414
SC
722}
723
519cb848
SC
724void wxControl::OnPaint(wxPaintEvent& event)
725{
76a5e5d2 726 if ( (ControlHandle) m_macControl )
89ebf1c9 727 {
de043984
SC
728 wxPaintDC dc(this) ;
729 wxMacPortSetter helper(&dc) ;
b8f2db1f
SC
730/*
731 Rect r = { 0 , 0 , 32000 , 32000 } ;
732 ClipRect( &r ) ;
733*/
7372fd0a
SC
734
735 int x = 0 , y = 0;
b8f2db1f
SC
736 wxWindow *parent = GetParent() ;
737 parent->MacWindowToRootWindow( &x,&y ) ;
7372fd0a 738 RgnHandle clrgn = NewRgn() ;
b8f2db1f
SC
739 RgnHandle insidergn = NewRgn() ;
740 wxSize size = parent->GetSize() ;
741 SetRectRgn( insidergn , parent->MacGetLeftBorderSize() , parent->MacGetTopBorderSize() ,
742 size.x - parent->MacGetLeftBorderSize() - parent->MacGetRightBorderSize(),
743 size.y - parent->MacGetTopBorderSize() - parent->MacGetBottomBorderSize()) ;
744
745 CopyRgn( (RgnHandle) parent->MacGetVisibleRegion(false).GetWXHRGN() , clrgn ) ;
746 SectRgn( clrgn , insidergn , clrgn ) ;
7372fd0a
SC
747 OffsetRgn( clrgn , x , y ) ;
748 SetClip( clrgn ) ;
b8f2db1f
SC
749 DisposeRgn( clrgn ) ;
750 DisposeRgn( insidergn ) ;
de043984
SC
751
752 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
76a5e5d2 753 UMADrawControl( (ControlHandle) m_macControl ) ;
89ebf1c9
RR
754 }
755 else
756 {
a5a8ff8a 757 event.Skip() ;
89ebf1c9 758 }
519cb848 759}
51abe921
SC
760void wxControl::OnEraseBackground(wxEraseEvent& event)
761{
1c310985 762 wxWindow::OnEraseBackground( event ) ;
51abe921
SC
763}
764
519cb848
SC
765
766void wxControl::OnKeyDown( wxKeyEvent &event )
767{
76a5e5d2 768 if ( (ControlHandle) m_macControl == NULL )
89ebf1c9
RR
769 return ;
770
76a5e5d2 771 EventRecord *ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ;
89ebf1c9
RR
772 short keycode ;
773 short keychar ;
774 keychar = short(ev->message & charCodeMask);
775 keycode = short(ev->message & keyCodeMask) >> 8 ;
776
76a5e5d2 777 ::HandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers ) ;
519cb848
SC
778}
779
780void wxControl::OnMouseEvent( wxMouseEvent &event )
781{
76a5e5d2 782 if ( (ControlHandle) m_macControl == NULL )
89ebf1c9
RR
783 {
784 event.Skip() ;
785 return ;
786 }
787
788 if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK )
789 {
790
791 int x = event.m_x ;
792 int y = event.m_y ;
793
794 MacClientToRootWindow( &x , &y ) ;
795
796 ControlHandle control ;
797 Point localwhere ;
798 SInt16 controlpart ;
76a5e5d2 799 WindowRef window = (WindowRef) MacGetRootWindow() ;
89ebf1c9
RR
800
801 localwhere.h = x ;
802 localwhere.v = y ;
803
804 short modifiers = 0;
805
806 if ( !event.m_leftDown && !event.m_rightDown )
807 modifiers |= btnState ;
808
809 if ( event.m_shiftDown )
810 modifiers |= shiftKey ;
811
812 if ( event.m_controlDown )
813 modifiers |= controlKey ;
814
815 if ( event.m_altDown )
816 modifiers |= optionKey ;
817
818 if ( event.m_metaDown )
819 modifiers |= cmdKey ;
f78024a1 820/*
892e461e 821#if TARGET_CARBON
280df085 822 control = FindControlUnderMouse( localwhere , window , &controlpart ) ;
892e461e 823#else
89ebf1c9 824 controlpart = FindControl( localwhere , window , &control ) ;
892e461e 825#endif
f78024a1 826*/
89ebf1c9
RR
827 {
828 /*
829 if ( AcceptsFocus() && FindFocus() != this )
830 {
831 SetFocus() ;
832 }
833 */
76a5e5d2 834 control = (ControlHandle) m_macControl ;
89ebf1c9
RR
835 if ( control && ::IsControlActive( control ) )
836 {
837 {
838 controlpart = ::HandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ;
839 wxTheApp->s_lastMouseDown = 0 ;
840 if ( control && controlpart != kControlNoPart &&
841 ! IsKindOf( CLASSINFO( wxScrollBar ) )
842 ) // otherwise we will get the event twice for scrollbar
843 {
844 MacHandleControlClick( control , controlpart ) ;
845 }
846 }
847 }
848 }
849 }
519cb848
SC
850}
851
852bool wxControl::MacCanFocus() const
853{
76a5e5d2 854 { if ( (ControlHandle) m_macControl == NULL )
89ebf1c9
RR
855 return true ;
856 else
857 return false ;
858 }
519cb848
SC
859}
860
76a5e5d2 861void wxControl::MacHandleControlClick( WXWidget control , wxInt16 controlpart )
519cb848 862{
76a5e5d2 863 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , "No valid mac control" ) ;
519cb848
SC
864}
865