]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/control.cpp
added generic color dialog to setup
[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
9// Licence: wxWindows licence
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"
519cb848
SC
22#include "wx/notebook.h"
23#include "wx/tabctrl.h"
2f1ae414 24#include "wx/radiobox.h"
519cb848 25#include "wx/spinbutt.h"
03e11df5
GD
26#include "wx/scrolbar.h"
27#include "wx/button.h"
28#include "wx/dialog.h"
29#include "wx/statbox.h"
30#include "wx/sizer.h"
31#include "wx/stattext.h"
e9576ca5 32
2f1ae414 33#if !USE_SHARED_LIBRARY
8208e181 34IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
e9576ca5 35
2f1ae414 36BEGIN_EVENT_TABLE(wxControl, wxWindow)
519cb848
SC
37 EVT_MOUSE_EVENTS( wxControl::OnMouseEvent )
38 EVT_CHAR( wxControl::OnKeyDown )
39 EVT_PAINT( wxControl::OnPaint )
e9576ca5 40END_EVENT_TABLE()
2f1ae414 41#endif
e9576ca5 42
519cb848
SC
43#include <wx/mac/uma.h>
44
e9576ca5 45// Item members
519cb848
SC
46
47ControlActionUPP wxMacLiveScrollbarActionUPP = NULL ;
48
2f1ae414 49pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode ) ;
519cb848
SC
50pascal void wxMacLiveScrollbarActionProc( ControlHandle control , ControlPartCode partCode )
51{
52 if ( partCode != 0)
53 {
54 wxControl* wx = (wxControl*) GetControlReference( control ) ;
55 if ( wx )
56 {
57 wx->MacHandleControlClick( control , partCode ) ;
58 }
59 }
60}
61
e9576ca5
SC
62wxControl::wxControl()
63{
2f1ae414
SC
64 m_macControl = NULL ;
65 m_macHorizontalBorder = 0 ; // additional pixels around the real control
66 m_macVerticalBorder = 0 ;
e9576ca5
SC
67 m_backgroundColour = *wxWHITE;
68 m_foregroundColour = *wxBLACK;
e7549107
SC
69#if WXWIN_COMPATIBILITY
70 m_callback = 0;
71#endif // WXWIN_COMPATIBILITY
519cb848
SC
72
73 if ( wxMacLiveScrollbarActionUPP == NULL )
74 {
4114d0af 75#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
03e11df5
GD
76 wxMacLiveScrollbarActionUPP = NewControlActionUPP( wxMacLiveScrollbarActionProc );
77#else
519cb848 78 wxMacLiveScrollbarActionUPP = NewControlActionProc( wxMacLiveScrollbarActionProc ) ;
03e11df5 79#endif
519cb848 80 }
e9576ca5
SC
81}
82
2f1ae414
SC
83bool wxControl::Create(wxWindow *parent, wxWindowID id,
84 const wxPoint& pos,
85 const wxSize& size, long style,
86 const wxValidator& validator,
87 const wxString& name)
88{
89 m_macControl = NULL ;
90 m_macHorizontalBorder = 0 ; // additional pixels around the real control
91 m_macVerticalBorder = 0 ;
92 bool rval = wxWindow::Create(parent, id, pos, size, style, name);
93 if (rval) {
94#if wxUSE_VALIDATORS
95 SetValidator(validator);
96#endif
97 }
98 return rval;
99}
100
e9576ca5
SC
101wxControl::~wxControl()
102{
e7549107 103 m_isBeingDeleted = TRUE;
e9576ca5
SC
104 // If we delete an item, we should initialize the parent panel,
105 // because it could now be invalid.
e7549107
SC
106 wxPanel *panel = wxDynamicCast(GetParent(), wxPanel);
107 if ( panel )
e9576ca5 108 {
e7549107
SC
109 if (panel->GetDefaultItem() == (wxButton*) this)
110 panel->SetDefaultItem(NULL);
e9576ca5 111 }
519cb848
SC
112 if ( m_macControl )
113 {
114 UMADisposeControl( m_macControl ) ;
115 m_macControl = NULL ;
116 }
e9576ca5
SC
117}
118
e7549107 119void wxControl::SetLabel(const wxString& title)
e9576ca5 120{
e7549107 121 m_label = title ;
519cb848
SC
122
123 if ( m_macControl )
124 {
125 Str255 maclabel ;
e7549107
SC
126 wxString label ;
127
128 if( wxApp::s_macDefaultEncodingIsPC )
129 label = wxMacMakeMacStringFromPC( title ) ;
130 else
131 label = title ;
519cb848 132
03e11df5
GD
133#if TARGET_CARBON
134 c2pstrcpy( (StringPtr) maclabel , label ) ;
135#else
136 strcpy( (char *) maclabel , label ) ;
137 c2pstr( (char *) maclabel ) ;
138#endif
519cb848
SC
139 ::SetControlTitle( m_macControl , maclabel ) ;
140 }
fdaf613a 141 Refresh() ;
e9576ca5
SC
142}
143
37e2cb08 144wxSize wxControl::DoGetBestSize() const
e9576ca5 145{
e7549107 146 return wxSize(20, 20);
e9576ca5
SC
147}
148
e7549107 149bool wxControl::ProcessCommand (wxCommandEvent & event)
e9576ca5
SC
150{
151 // Tries:
152 // 1) A callback function (to become obsolete)
153 // 2) OnCommand, starting at this window and working up parent hierarchy
154 // 3) OnCommand then calls ProcessEvent to search the event tables.
e7549107
SC
155#if WXWIN_COMPATIBILITY
156 if ( m_callback )
e9576ca5 157 {
e7549107
SC
158 (void)(*m_callback)(this, event);
159
160 return TRUE;
e9576ca5
SC
161 }
162 else
e7549107 163#endif // WXWIN_COMPATIBILITY
e9576ca5 164 {
e7549107 165 return GetEventHandler()->ProcessEvent(event);
e9576ca5
SC
166 }
167}
168
519cb848
SC
169// ------------------------
170wxList *wxWinMacControlList = NULL;
171wxControl *wxFindControlFromMacControl(ControlHandle inControl )
172{
173 wxNode *node = wxWinMacControlList->Find((long)inControl);
174 if (!node)
175 return NULL;
176 return (wxControl *)node->Data();
177}
178
179void wxAssociateControlWithMacControl(ControlHandle inControl, wxControl *control)
180{
181 // adding NULL WindowRef is (first) surely a result of an error and
182 // (secondly) breaks menu command processing
183 wxCHECK_RET( inControl != (ControlHandle) NULL, "attempt to add a NULL WindowRef to window list" );
184
185 if ( !wxWinMacControlList->Find((long)inControl) )
186 wxWinMacControlList->Append((long)inControl, control);
187}
188
189void wxRemoveMacControlAssociation(wxControl *control)
190{
191 wxWinMacControlList->DeleteObject(control);
192}
193
194void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString label ,
195 const wxPoint& pos,
196 const wxSize& size, long style,
197 const wxValidator& validator,
198 const wxString& name , Rect *outBounds , StringPtr maclabel )
199{
200 m_label = label ;
201 SetName(name);
202 if ( &validator )
203 SetValidator(validator);
204
205 m_windowStyle = style;
206 parent->AddChild((wxButton *)this);
207
208 m_backgroundColour = parent->GetBackgroundColour() ;
209 m_foregroundColour = parent->GetForegroundColour() ;
210
211 if (id == -1)
212 m_windowId = NewControlId();
213 else
214 m_windowId = id;
215
216 m_width = size.x ;
217 m_height = size.y ;
218 int x = pos.x ;
219 int y = pos.y ;
220 AdjustForParentClientOrigin(x, y, wxSIZE_USE_EXISTING);
221 m_x = x ;
222 m_y = y ;
223
224
519cb848
SC
225 parent->MacClientToRootWindow( &x , &y ) ;
226 outBounds->top = y + m_macVerticalBorder ;
227 outBounds->left = x + m_macHorizontalBorder ;
228 outBounds->bottom = outBounds->top + m_height - 2 * m_macVerticalBorder;
229 outBounds->right = outBounds->left + m_width - 2 * m_macHorizontalBorder ;
230
03e11df5
GD
231 char c_text[255];
232 strcpy( c_text , label ) ;
519cb848
SC
233 if( wxApp::s_macDefaultEncodingIsPC )
234 {
03e11df5 235 wxMacConvertFromPCForControls( c_text ) ;
519cb848
SC
236 }
237
03e11df5
GD
238#if TARGET_CARBON
239 c2pstrcpy( (StringPtr) maclabel , c_text ) ;
240#else
241 strcpy( (char *) maclabel , c_text ) ;
242 c2pstr( (char *) maclabel ) ;
243#endif
519cb848
SC
244}
245
246void wxControl::MacPostControlCreate()
247{
248 wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
249
250 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
251 {
252 // no font
253 }
2f1ae414 254 else if ( IsKindOf( CLASSINFO( wxStaticBox ) ) || IsKindOf( CLASSINFO( wxRadioBox ) ) || IsKindOf( CLASSINFO( wxButton ) ) )
519cb848
SC
255 {
256 ControlFontStyleRec controlstyle ;
257 controlstyle.flags = kControlUseFontMask ;
258 controlstyle.font = kControlFontSmallBoldSystemFont ;
259
260 ::UMASetControlFontStyle( m_macControl , &controlstyle ) ;
261 }
262 else
263 {
264 ControlFontStyleRec controlstyle ;
265 controlstyle.flags = kControlUseFontMask ;
266 controlstyle.font = kControlFontSmallSystemFont ;
267
268 ::UMASetControlFontStyle( m_macControl , &controlstyle ) ;
269 }
270 ControlHandle container = GetParent()->MacGetContainerForEmbedding() ;
271 wxASSERT_MSG( container != NULL , "No valid mac container control" ) ;
272 ::UMAEmbedControl( m_macControl , container ) ;
c809f3be 273 m_macControlIsShown = true ;
519cb848
SC
274 MacAdjustControlRect() ;
275 wxAssociateControlWithMacControl( m_macControl , this ) ;
fdaf613a 276 UMAShowControl( m_macControl ) ;
519cb848
SC
277}
278
279void wxControl::MacAdjustControlRect()
280{
281 wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
282 if ( m_width == -1 || m_height == -1 )
283 {
284 Rect bestsize = { 0 , 0 , 0 , 0 } ;
285 short baselineoffset ;
286
287 UMAGetBestControlRect( m_macControl , &bestsize , &baselineoffset ) ;
288
289 if ( EmptyRect( &bestsize ) )
290 {
291 baselineoffset = 0;
292 bestsize.left = bestsize.top = 0 ;
293 bestsize.right = 16 ;
294 bestsize.bottom = 16 ;
295 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
296 {
297 bestsize.bottom = 16 ;
298 }
299 else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
300 {
301 bestsize.bottom = 24 ;
302 }
303 }
304
305 if ( m_width == -1 )
306 {
307 if ( IsKindOf( CLASSINFO( wxButton ) ) )
308 {
2f1ae414 309 m_width = m_label.Length() * 8 + 12 ;
0a67a93b
SC
310 if ( m_width < 70 )
311 m_width = 70 ;
519cb848
SC
312 }
313 else if ( IsKindOf( CLASSINFO( wxStaticText ) ) )
314 {
315 m_width = m_label.Length() * 8 ;
316 }
317 else
2f1ae414
SC
318 m_width = bestsize.right - bestsize.left ;
319
320 m_width += 2 * m_macHorizontalBorder ;
519cb848
SC
321 }
322 if ( m_height == -1 )
323 {
324 m_height = bestsize.bottom - bestsize.top ;
325 if ( m_height < 10 )
326 m_height = 13 ;
327
328 m_height += 2 * m_macVerticalBorder;
329 }
330
331 wxMacDrawingHelper helper ( wxFindWinFromMacWindow( GetMacRootWindow() ) ) ;
332 if ( helper.Ok() )
333 {
2f1ae414 334 UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ;
519cb848
SC
335 }
336 }
337}
338ControlHandle wxControl::MacGetContainerForEmbedding()
339{
340 if ( m_macControl )
341 return m_macControl ;
342
343 return wxWindow::MacGetContainerForEmbedding() ;
344}
345
346void wxControl::MacSuperChangedPosition()
347{
348 if ( m_macControl )
349 {
2f1ae414
SC
350 Rect contrlRect ;
351 GetControlBounds( m_macControl , &contrlRect ) ;
352 int former_mac_x = contrlRect.left ;
353 int former_mac_y = contrlRect.top ;
519cb848
SC
354 int mac_x = m_x ;
355 int mac_y = m_y ;
356 GetParent()->MacClientToRootWindow( & mac_x , & mac_y ) ;
357
358 WindowRef rootwindow = GetMacRootWindow() ;
359 wxWindow* wxrootwindow = wxFindWinFromMacWindow( rootwindow ) ;
360 UMASetThemeWindowBackground( rootwindow , kThemeBrushDialogBackgroundActive , false ) ;
361 wxMacDrawingHelper focus( wxrootwindow ) ;
362
363 if ( mac_x != former_mac_x || mac_y != former_mac_y )
364 {
fd2e20ff
SC
365 {
366 Rect inval = { former_mac_y , former_mac_x , former_mac_y + m_height , former_mac_x + m_width } ;
367 InvalWindowRect( rootwindow , &inval ) ;
368 }
2f1ae414 369 UMAMoveControl( m_macControl , mac_x + m_macHorizontalBorder , mac_y + m_macVerticalBorder ) ;
fd2e20ff
SC
370 {
371 Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ;
372 InvalWindowRect( rootwindow , &inval ) ;
373 }
519cb848
SC
374 }
375 if ( wxrootwindow->IsKindOf( CLASSINFO( wxDialog ) ) )
376 {
377 }
378 else
379 {
380 UMASetThemeWindowBackground( rootwindow , kThemeBrushDocumentWindowBackground , false ) ;
381 }
382 }
383
384 wxWindow::MacSuperChangedPosition() ;
385}
386
387void wxControl::MacSuperEnabled( bool enabled )
388{
e7549107 389/*
519cb848
SC
390 if ( m_macControl )
391 {
392 if ( UMAHasAppearance() )
393 {
394 if ( !enabled )
395 {
396 ::DeactivateControl( m_macControl ) ;
397 }
398 else
399 {
400 if ( m_macEnabled )
401 ::ActivateControl( m_macControl ) ;
402 }
403 }
404 else
405 {
406 if ( !enabled )
407 {
408 ::HiliteControl( m_macControl , 255 ) ;
409 }
410 else
411 {
412 if ( m_macEnabled )
413 ::HiliteControl( m_macControl , 0 ) ;
414 }
415 }
416 }
417 wxWindow::MacSuperEnabled( enabled ) ;
2f1ae414 418*/
519cb848
SC
419}
420
421void wxControl::MacSuperShown( bool show )
422{
423 if ( m_macControl )
424 {
425 if ( !show )
426 {
c809f3be
SC
427 if ( m_macControlIsShown )
428 {
429 ::UMAHideControl( m_macControl ) ;
430 m_macControlIsShown = false ;
431 }
519cb848
SC
432 }
433 else
434 {
c809f3be
SC
435 if ( MacIsReallyShown() && !m_macControlIsShown )
436 {
519cb848 437 ::UMAShowControl( m_macControl ) ;
c809f3be
SC
438 m_macControlIsShown = true ;
439 }
519cb848
SC
440 }
441 }
442
443 wxWindow::MacSuperShown( show ) ;
444}
445
446void wxControl::DoSetSize(int x, int y,
447 int width, int height,
448 int sizeFlags )
449{
450 if ( m_macControl == NULL )
451 {
452 wxWindow::DoSetSize( x , y ,width , height ,sizeFlags ) ;
453 return ;
454 }
455
456 WindowRef rootwindow = GetMacRootWindow() ;
457 wxWindow* wxrootwindow = wxFindWinFromMacWindow( rootwindow ) ;
458 UMASetThemeWindowBackground( rootwindow , kThemeBrushDialogBackgroundActive , false ) ;
459
460 int former_x = m_x ;
461 int former_y = m_y ;
462 int former_w = m_width ;
463 int former_h = m_height ;
464
2f1ae414
SC
465 Rect contrlRect ;
466 GetControlBounds( m_macControl , &contrlRect ) ;
467 int former_mac_x = contrlRect.left ;
468 int former_mac_y = contrlRect.top ;
519cb848
SC
469
470 int currentX, currentY;
471 GetPosition(&currentX, &currentY);
472 int currentW,currentH;
473 GetSize(&currentW, &currentH);
474
475 int actualWidth = width;
476 int actualHeight = height;
477 int actualX = x;
478 int actualY = y;
2f1ae414 479 if (x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
519cb848 480 actualX = currentX;
2f1ae414 481 if (y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
519cb848
SC
482 actualY = currentY;
483 if (width == -1)
484 actualWidth = currentW ;
485 if (height == -1)
486 actualHeight = currentH ;
487
488 if ( actualX == currentX && actualY == currentY && actualWidth == currentW && actualHeight == currentH)
489 return ;
490
491 AdjustForParentClientOrigin(actualX, actualY, sizeFlags);
2f1ae414
SC
492 WindowRef macrootwindow = GetMacRootWindow() ;
493 wxMacDrawingHelper focus( wxFindWinFromMacWindow( macrootwindow ) ) ;
519cb848
SC
494
495 int mac_x = actualX ;
496 int mac_y = actualY ;
497 GetParent()->MacClientToRootWindow( & mac_x , & mac_y ) ;
498
499 if ( mac_x != former_mac_x || mac_y != former_mac_y )
500 {
fd2e20ff
SC
501 {
502 Rect inval = { former_mac_y , former_mac_x , former_mac_y + m_height , former_mac_x + m_width } ;
503 InvalWindowRect( macrootwindow, &inval ) ;
504 }
2f1ae414 505 UMAMoveControl( m_macControl , mac_x + m_macHorizontalBorder , mac_y + m_macVerticalBorder ) ;
fd2e20ff
SC
506 {
507 Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ;
508 InvalWindowRect(macrootwindow, &inval ) ;
509 }
519cb848
SC
510 }
511
512 if ( actualX != former_x || actualY != former_y )
513 {
514 m_x = actualX ;
515 m_y = actualY ;
516
517 MacRepositionScrollBars() ;
518 // To consider -> should the parameters be the effective or the virtual coordinates (AdjustForParent..)
6868c3eb
GD
519 wxPoint point(m_x, m_y);
520 wxMoveEvent event(point, m_windowId);
fd2e20ff
SC
521 event.SetEventObject(this);
522 GetEventHandler()->ProcessEvent(event);
519cb848
SC
523 }
524 if ( actualWidth != former_w || actualHeight != former_h )
525 {
526 {
527 Rect inval = { mac_y , mac_x , mac_y + former_h , mac_x + former_w } ;
2f1ae414 528 InvalWindowRect( macrootwindow, &inval ) ;
519cb848
SC
529 }
530 m_width = actualWidth ;
531 m_height = actualHeight ;
532
2f1ae414 533 UMASizeControl( m_macControl , m_width - 2 * m_macHorizontalBorder, m_height - 2 * m_macVerticalBorder ) ;
519cb848
SC
534 {
535 Rect inval = { mac_y , mac_x , mac_y + m_height , mac_x + m_width } ;
2f1ae414 536 InvalWindowRect( macrootwindow , &inval ) ;
519cb848
SC
537 }
538
539 MacRepositionScrollBars() ;
6868c3eb
GD
540 wxSize size(m_width, m_height);
541 wxSizeEvent event(size, m_windowId);
fd2e20ff
SC
542 event.SetEventObject(this);
543 GetEventHandler()->ProcessEvent(event);
519cb848
SC
544 }
545 if ( wxrootwindow->IsKindOf( CLASSINFO( wxDialog ) ) )
546 {
547 }
548 else
549 {
550 UMASetThemeWindowBackground( rootwindow , kThemeBrushDocumentWindowBackground , false ) ;
551 }
552}
553
519cb848
SC
554bool wxControl::Show(bool show)
555{
e7549107
SC
556 if ( !wxWindow::Show( show ) )
557 return FALSE ;
558
559 if ( m_macControl )
560 {
c809f3be
SC
561 if ( !show )
562 {
563 if ( m_macControlIsShown )
564 {
565 ::UMAHideControl( m_macControl ) ;
566 m_macControlIsShown = false ;
567 }
568 }
e7549107 569 else
c809f3be
SC
570 {
571 if ( MacIsReallyShown() && !m_macControlIsShown )
572 {
573 ::UMAShowControl( m_macControl ) ;
574 m_macControlIsShown = true ;
575 }
576 }
e7549107
SC
577 }
578 return TRUE ;
519cb848
SC
579}
580
e7549107 581bool wxControl::Enable(bool enable)
519cb848 582{
e7549107
SC
583 if ( !wxWindow::Enable(enable) )
584 return FALSE;
519cb848 585
e7549107 586 if ( m_macControl )
519cb848 587 {
fdaf613a
SC
588 if ( enable )
589 UMAActivateControl( m_macControl ) ;
519cb848 590 else
fdaf613a 591 UMADeactivateControl( m_macControl ) ;
519cb848 592 }
e7549107 593 return TRUE ;
519cb848
SC
594}
595
596void wxControl::Refresh(bool eraseBack, const wxRect *rect)
597{
598 if ( m_macControl )
599 {
600 wxWindow::Refresh( eraseBack , rect ) ;
601 }
602 else
603 {
604 wxWindow::Refresh( eraseBack , rect ) ;
605 }
606}
607
2f1ae414
SC
608void wxControl::MacRedrawControl()
609{
610 if ( m_macControl )
611 {
612 WindowRef window = GetMacRootWindow() ;
613 if ( window )
614 {
615 wxWindow* win = wxFindWinFromMacWindow( window ) ;
616 if ( win )
617 {
618 wxMacDrawingHelper help( win ) ;
619 // the mac control manager always assumes to have the origin at 0,0
620 SetOrigin( 0 , 0 ) ;
621
622 bool hasTabBehind = false ;
623 wxWindow* parent = GetParent() ;
624 while ( parent )
625 {
626 if( parent->MacGetWindowData() )
627 {
628 UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
629 break ;
630 }
631
632 if( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
633 {
634 if ( ((wxControl*)parent)->m_macControl )
635 SetUpControlBackground( ((wxControl*)parent)->m_macControl , -1 , true ) ;
636 break ;
637 }
638
639 parent = parent->GetParent() ;
640 }
641
642 UMADrawControl( m_macControl ) ;
643 UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ;
644 }
645 }
646 }
647}
648
519cb848
SC
649void wxControl::OnPaint(wxPaintEvent& event)
650{
651 if ( m_macControl )
652 {
653 WindowRef window = GetMacRootWindow() ;
654 if ( window )
655 {
656 wxWindow* win = wxFindWinFromMacWindow( window ) ;
657 if ( win )
658 {
659 wxMacDrawingHelper help( win ) ;
2f1ae414 660 // the mac control manager always assumes to have the origin at 0,0
519cb848 661 SetOrigin( 0 , 0 ) ;
27419164 662
519cb848 663
27419164 664 bool hasTabBehind = false ;
519cb848
SC
665 wxWindow* parent = GetParent() ;
666 while ( parent )
667 {
e7549107 668 if( parent->MacGetWindowData() )
519cb848 669 {
e7549107 670 UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
519cb848
SC
671 break ;
672 }
673
674 if( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
675 {
676 if ( ((wxControl*)parent)->m_macControl )
677 SetUpControlBackground( ((wxControl*)parent)->m_macControl , -1 , true ) ;
678 break ;
679 }
680
681 parent = parent->GetParent() ;
682 }
27419164 683
519cb848 684 UMADrawControl( m_macControl ) ;
e7549107 685 UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ;
519cb848
SC
686 }
687 }
688 }
689 else
690 {
e7549107 691 // wxWindow::OnPaint( event ) ;
519cb848
SC
692 }
693}
51abe921
SC
694void wxControl::OnEraseBackground(wxEraseEvent& event)
695{
696 // In general, you don't want to erase the background of a control,
697 // or you'll get a flicker.
698 // TODO: move this 'null' function into each control that
699 // might flicker.
700}
701
519cb848
SC
702
703void wxControl::OnKeyDown( wxKeyEvent &event )
704{
705 if ( m_macControl == NULL )
706 return ;
707
708 EventRecord *ev = wxTheApp->MacGetCurrentEvent() ;
709 short keycode ;
710 short keychar ;
711 keychar = short(ev->message & charCodeMask);
712 keycode = short(ev->message & keyCodeMask) >> 8 ;
713
714 UMAHandleControlKey( m_macControl , keycode , keychar , ev->modifiers ) ;
715}
716
717void wxControl::OnMouseEvent( wxMouseEvent &event )
718{
719 if ( m_macControl == NULL )
720 {
721 event.Skip() ;
722 return ;
723 }
724
2f1ae414 725 if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK )
519cb848
SC
726 {
727
728 int x = event.m_x ;
729 int y = event.m_y ;
730
731 MacClientToRootWindow( &x , &y ) ;
732
733 ControlHandle control ;
734 Point localwhere ;
735 GrafPtr port ;
736 SInt16 controlpart ;
737 WindowRef window = GetMacRootWindow() ;
738
739 localwhere.h = x ;
740 localwhere.v = y ;
741
742 short modifiers = 0;
743
744 if ( !event.m_leftDown && !event.m_rightDown )
745 modifiers |= btnState ;
746
747 if ( event.m_shiftDown )
748 modifiers |= shiftKey ;
749
750 if ( event.m_controlDown )
751 modifiers |= controlKey ;
752
753 if ( event.m_altDown )
754 modifiers |= optionKey ;
755
756 if ( event.m_metaDown )
757 modifiers |= cmdKey ;
758
759 controlpart = FindControl( localwhere , window , &control ) ;
760 {
7810c95b 761 /*
519cb848
SC
762 if ( AcceptsFocus() && FindFocus() != this )
763 {
764 SetFocus() ;
765 }
7810c95b 766 */
519cb848
SC
767 if ( control && UMAIsControlActive( control ) )
768 {
769 {
770 if ( controlpart == kControlIndicatorPart && !UMAHasAppearance() )
771 controlpart = UMAHandleControlClick( control , localwhere , modifiers , (ControlActionUPP) NULL ) ;
772 else
773 controlpart = UMAHandleControlClick( control , localwhere , modifiers , (ControlActionUPP) -1 ) ;
774 wxTheApp->s_lastMouseDown = 0 ;
775 if ( controlpart && ! ( ( UMAHasAppearance() || (controlpart != kControlIndicatorPart) )
776 && (IsKindOf( CLASSINFO( wxScrollBar ) ) ) ) ) // otherwise we will get the event twice
777 {
778 MacHandleControlClick( control , controlpart ) ;
779 }
780 }
781 }
782 }
783 }
784}
785
786bool wxControl::MacCanFocus() const
787{
788 { if ( m_macControl == NULL )
789 return true ;
790 else
791 return false ;
792 }
793}
794
795void wxControl::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
796{
797 wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
798}
799