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