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