]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/window.cpp
added tlw include
[wxWidgets.git] / src / mac / carbon / window.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: windows.cpp
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "window.h"
14 #endif
15
16 #include "wx/setup.h"
17 #include "wx/menu.h"
18 #include "wx/window.h"
19 #include "wx/dc.h"
20 #include "wx/dcclient.h"
21 #include "wx/utils.h"
22 #include "wx/app.h"
23 #include "wx/panel.h"
24 #include "wx/layout.h"
25 #include "wx/dialog.h"
26 #include "wx/scrolbar.h"
27 #include "wx/statbox.h"
28 #include "wx/button.h"
29 #include "wx/settings.h"
30 #include "wx/msgdlg.h"
31 #include "wx/frame.h"
32 #include "wx/tooltip.h"
33 #include "wx/statusbr.h"
34 #include "wx/menuitem.h"
35 #include "wx/spinctrl.h"
36 #include "wx/log.h"
37 #include "wx/geometry.h"
38
39 #include "wx/toolbar.h"
40 #include "wx/dc.h"
41
42 #if wxUSE_CARET
43 #include "wx/caret.h"
44 #endif // wxUSE_CARET
45
46 #define wxWINDOW_HSCROLL 5998
47 #define wxWINDOW_VSCROLL 5997
48 #define MAC_SCROLLBAR_SIZE 16
49
50 #include "wx/mac/uma.h"
51 #ifndef __DARWIN__
52 #include <Windows.h>
53 #include <ToolUtils.h>
54 #endif
55
56 #if TARGET_API_MAC_OSX
57 #ifndef __HIVIEW__
58 #include <HIToolbox/HIView.h>
59 #endif
60 #endif
61
62 #if wxUSE_DRAG_AND_DROP
63 #include "wx/dnd.h"
64 #endif
65
66 #include <string.h>
67
68 extern wxList wxPendingDelete;
69 wxWindowMac* gFocusWindow = NULL ;
70
71 #ifdef __WXUNIVERSAL__
72 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac, wxWindowBase)
73 #else // __WXMAC__
74 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
75 #endif // __WXUNIVERSAL__/__WXMAC__
76
77 #if !USE_SHARED_LIBRARY
78
79 BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase)
80 EVT_NC_PAINT(wxWindowMac::OnNcPaint)
81 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground)
82 // TODO EVT_PAINT(wxWindowMac::OnPaint)
83 EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged)
84 EVT_INIT_DIALOG(wxWindowMac::OnInitDialog)
85 EVT_SET_FOCUS(wxWindowMac::OnSetFocus)
86 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent)
87 END_EVENT_TABLE()
88
89 #endif
90
91 #define wxMAC_DEBUG_REDRAW 0
92 #ifndef wxMAC_DEBUG_REDRAW
93 #define wxMAC_DEBUG_REDRAW 0
94 #endif
95
96 #define wxMAC_USE_THEME_BORDER 0
97
98 // ---------------------------------------------------------------------------
99 // Carbon Events
100 // ---------------------------------------------------------------------------
101
102 extern long wxMacTranslateKey(unsigned char key, unsigned char code) ;
103 pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessage , SInt16 iDepth , Boolean iIsColor ) ;
104
105 static const EventTypeSpec eventList[] =
106 {
107 #if TARGET_API_MAC_OSX
108 { kEventClassControl , kEventControlDraw } ,
109 { kEventClassControl , kEventControlVisibilityChanged } ,
110 { kEventClassControl , kEventControlEnabledStateChanged } ,
111 { kEventClassControl , kEventControlHiliteChanged } ,
112 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
113 // { kEventClassControl , kEventControlBoundsChanged } ,
114
115 {}
116 #else
117 {}
118 #endif
119 } ;
120
121 static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
122 {
123 OSStatus result = eventNotHandledErr ;
124
125 wxMacCarbonEvent cEvent( event ) ;
126
127 ControlRef controlRef ;
128 wxWindowMac* thisWindow = (wxWindowMac*) data ;
129
130 cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ;
131
132 switch( GetEventKind( event ) )
133 {
134 case kEventControlDraw :
135 {
136 RgnHandle updateRgn = NULL ;
137
138 wxRegion visRegion = thisWindow->MacGetVisibleRegion() ;
139 if ( cEvent.GetParameter<RgnHandle>(kEventParamRgnHandle, &updateRgn) != noErr )
140 {
141 updateRgn = (RgnHandle) visRegion.GetWXHRGN() ;
142 }
143 else
144 {
145 // unfortunately this update region may be incorrect (tree ctrl sample )
146 // so we have to reset it
147 updateRgn = (RgnHandle) visRegion.GetWXHRGN() ;
148 }
149 // GrafPtr myport = cEvent.GetParameter<GrafPtr>(kEventParamGrafPort,typeGrafPtr) ;
150
151 #if 0 // in case we would need a coregraphics compliant background erase first
152 CGContextRef cgContext = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef) ;
153 if ( thisWindow->MacIsUserPane() )
154 {
155 HIRect bounds;
156 err = HIViewGetBounds( controlRef, &bounds );
157 CGContextSetRGBFillColor( cgContext, 1 , 1 , 1 , 1 );
158 // CGContextSetRGBFillColor( cgContext, .95, .95, .95, 1 );
159 CGContextFillRect( cgContext, bounds );
160 }
161 #endif
162 if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) )
163 result = noErr ;
164 else
165 result = eventNotHandledErr;
166 }
167 break ;
168 case kEventControlVisibilityChanged :
169 thisWindow->MacVisibilityChanged() ;
170 break ;
171 case kEventControlEnabledStateChanged :
172 thisWindow->MacEnabledStateChanged() ;
173 break ;
174 case kEventControlHiliteChanged :
175 thisWindow->MacHiliteChanged() ;
176 break ;
177 default :
178 break ;
179 }
180 return result ;
181 }
182
183 pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
184 {
185 OSStatus result = eventNotHandledErr ;
186
187 switch ( GetEventClass( event ) )
188 {
189 case kEventClassControl :
190 result = wxMacWindowControlEventHandler( handler, event, data ) ;
191 break ;
192 default :
193 break ;
194 }
195 return result ;
196 }
197
198 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler )
199
200 // ---------------------------------------------------------------------------
201 // UserPane events for non OSX builds
202 // ---------------------------------------------------------------------------
203
204 static pascal void wxMacControlUserPaneDrawProc(ControlRef control, SInt16 part)
205 {
206 wxWindow * win = wxFindControlFromMacControl(control) ;
207 wxCHECK_RET( win , wxT("Callback from unkown control") ) ;
208 win->MacControlUserPaneDrawProc(part) ;
209 }
210
211 static pascal ControlPartCode wxMacControlUserPaneHitTestProc(ControlRef control, Point where)
212 {
213 wxWindow * win = wxFindControlFromMacControl(control) ;
214 wxCHECK_MSG( win , kControlNoPart , wxT("Callback from unkown control") ) ;
215 return win->MacControlUserPaneHitTestProc(where.h , where.v) ;
216 }
217
218 static pascal ControlPartCode wxMacControlUserPaneTrackingProc(ControlRef control, Point startPt, ControlActionUPP actionProc)
219 {
220 wxWindow * win = wxFindControlFromMacControl(control) ;
221 wxCHECK_MSG( win , kControlNoPart , wxT("Callback from unkown control") ) ;
222 return win->MacControlUserPaneTrackingProc( startPt.h , startPt.v , (void*) actionProc) ;
223 }
224
225 static pascal void wxMacControlUserPaneIdleProc(ControlRef control)
226 {
227 wxWindow * win = wxFindControlFromMacControl(control) ;
228 wxCHECK_RET( win , wxT("Callback from unkown control") ) ;
229 win->MacControlUserPaneIdleProc() ;
230 }
231
232 static pascal ControlPartCode wxMacControlUserPaneKeyDownProc(ControlRef control, SInt16 keyCode, SInt16 charCode, SInt16 modifiers)
233 {
234 wxWindow * win = wxFindControlFromMacControl(control) ;
235 wxCHECK_MSG( win , kControlNoPart , wxT("Callback from unkown control") ) ;
236 return win->MacControlUserPaneKeyDownProc(keyCode,charCode,modifiers) ;
237 }
238
239 static pascal void wxMacControlUserPaneActivateProc(ControlRef control, Boolean activating)
240 {
241 wxWindow * win = wxFindControlFromMacControl(control) ;
242 wxCHECK_RET( win , wxT("Callback from unkown control") ) ;
243 win->MacControlUserPaneActivateProc(activating) ;
244 }
245
246 static pascal ControlPartCode wxMacControlUserPaneFocusProc(ControlRef control, ControlFocusPart action)
247 {
248 wxWindow * win = wxFindControlFromMacControl(control) ;
249 wxCHECK_MSG( win , kControlNoPart , wxT("Callback from unkown control") ) ;
250 return win->MacControlUserPaneFocusProc(action) ;
251 }
252
253 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info)
254 {
255 wxWindow * win = wxFindControlFromMacControl(control) ;
256 wxCHECK_RET( win , wxT("Callback from unkown control") ) ;
257 win->MacControlUserPaneBackgroundProc(info) ;
258 }
259
260 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part)
261 {
262 MacDoRedraw( MacGetVisibleRegion().GetWXHRGN() , 0 ) ;
263 }
264
265 wxInt16 wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y)
266 {
267 return kControlNoPart ;
268 }
269
270 wxInt16 wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc)
271 {
272 return kControlNoPart ;
273 }
274
275 void wxWindowMac::MacControlUserPaneIdleProc()
276 {
277 }
278
279 wxInt16 wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers)
280 {
281 return kControlNoPart ;
282 }
283
284 void wxWindowMac::MacControlUserPaneActivateProc(bool activating)
285 {
286 }
287
288 wxInt16 wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action)
289 {
290 return kControlNoPart ;
291 }
292
293 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info)
294 {
295 }
296
297 ControlUserPaneDrawUPP gControlUserPaneDrawUPP = NULL ;
298 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP = NULL ;
299 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP = NULL ;
300 ControlUserPaneIdleUPP gControlUserPaneIdleUPP = NULL ;
301 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP = NULL ;
302 ControlUserPaneActivateUPP gControlUserPaneActivateUPP = NULL ;
303 ControlUserPaneFocusUPP gControlUserPaneFocusUPP = NULL ;
304 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP = NULL ;
305
306 // ===========================================================================
307 // implementation
308 // ===========================================================================
309
310 wxList wxWinMacControlList(wxKEY_INTEGER);
311
312 wxWindow *wxFindControlFromMacControl(ControlRef inControl )
313 {
314 wxNode *node = wxWinMacControlList.Find((long)inControl);
315 if (!node)
316 return NULL;
317 return (wxControl *)node->GetData();
318 }
319
320 void wxAssociateControlWithMacControl(ControlRef inControl, wxWindow *control)
321 {
322 // adding NULL ControlRef is (first) surely a result of an error and
323 // (secondly) breaks native event processing
324 wxCHECK_RET( inControl != (ControlRef) NULL, wxT("attempt to add a NULL WindowRef to window list") );
325
326 if ( !wxWinMacControlList.Find((long)inControl) )
327 wxWinMacControlList.Append((long)inControl, control);
328 }
329
330 void wxRemoveMacControlAssociation(wxWindow *control)
331 {
332 wxWinMacControlList.DeleteObject(control);
333 }
334
335 // UPP functions
336 ControlActionUPP wxMacLiveScrollbarActionUPP = NULL ;
337
338 ControlColorUPP wxMacSetupControlBackgroundUPP = NULL ;
339
340 // we have to setup the brush in the current port and return noErr
341 // or return an error code so that the control manager walks further up the
342 // hierarchy to find a correct background
343
344 pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessage , SInt16 iDepth , Boolean iIsColor )
345 {
346 OSStatus status = paramErr ;
347 switch( iMessage )
348 {
349 case kControlMsgApplyTextColor :
350 break ;
351 case kControlMsgSetUpBackground :
352 {
353 wxWindow* wx = (wxWindow*) wxFindControlFromMacControl( iControl ) ;
354 if ( wx != NULL )
355 {
356 /*
357 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
358 if ( brush.Ok() )
359 {
360
361 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
362 */
363 // this clipping is only needed for non HIView
364
365 RgnHandle clip = NewRgn() ;
366 int x = 0 , y = 0;
367
368 wx->MacWindowToRootWindow( &x,&y ) ;
369 CopyRgn( (RgnHandle) wx->MacGetVisibleRegion().GetWXHRGN() , clip ) ;
370 OffsetRgn( clip , x , y ) ;
371 SetClip( clip ) ;
372 DisposeRgn( clip ) ;
373
374 status = noErr ;
375 /*
376 }
377 else if ( wx->MacIsUserPane() )
378 {
379 // if we don't have a valid brush for such a control, we have to call the
380 // setup of our parent ourselves
381 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
382 }
383 */
384 }
385 }
386 break ;
387 default :
388 break ;
389 }
390 return status ;
391 }
392
393
394 pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode partCode ) ;
395 pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode partCode )
396 {
397 if ( partCode != 0)
398 {
399 wxWindow* wx = wxFindControlFromMacControl( control ) ;
400 if ( wx )
401 {
402 wx->MacHandleControlClick( (WXWidget) control , partCode , true /* stillDown */ ) ;
403 }
404 }
405 }
406
407 // ----------------------------------------------------------------------------
408 // constructors and such
409 // ----------------------------------------------------------------------------
410
411 void wxWindowMac::Init()
412 {
413 m_backgroundTransparent = FALSE;
414
415 // as all windows are created with WS_VISIBLE style...
416 m_isShown = TRUE;
417
418 m_hScrollBar = NULL ;
419 m_vScrollBar = NULL ;
420 m_macBackgroundBrush = wxNullBrush ;
421
422 m_macControl = NULL ;
423
424 m_macIsUserPane = TRUE;
425
426 // make sure all proc ptrs are available
427
428 if ( gControlUserPaneDrawUPP == NULL )
429 {
430 gControlUserPaneDrawUPP = NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc ) ;
431 gControlUserPaneHitTestUPP = NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc ) ;
432 gControlUserPaneTrackingUPP = NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc ) ;
433 gControlUserPaneIdleUPP = NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc ) ;
434 gControlUserPaneKeyDownUPP = NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc ) ;
435 gControlUserPaneActivateUPP = NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc ) ;
436 gControlUserPaneFocusUPP = NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc ) ;
437 gControlUserPaneBackgroundUPP = NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc ) ;
438 }
439 if ( wxMacLiveScrollbarActionUPP == NULL )
440 {
441 wxMacLiveScrollbarActionUPP = NewControlActionUPP( wxMacLiveScrollbarActionProc );
442 }
443
444 if ( wxMacSetupControlBackgroundUPP == NULL )
445 {
446 wxMacSetupControlBackgroundUPP = NewControlColorUPP( wxMacSetupControlBackground ) ;
447 }
448
449 }
450
451 // Destructor
452 wxWindowMac::~wxWindowMac()
453 {
454 SendDestroyEvent();
455
456 m_isBeingDeleted = TRUE;
457
458 #ifndef __WXUNIVERSAL__
459 // VS: make sure there's no wxFrame with last focus set to us:
460 for ( wxWindow *win = GetParent(); win; win = win->GetParent() )
461 {
462 wxFrame *frame = wxDynamicCast(win, wxFrame);
463 if ( frame )
464 {
465 if ( frame->GetLastFocus() == this )
466 {
467 frame->SetLastFocus((wxWindow*)NULL);
468 }
469 break;
470 }
471 }
472 #endif // __WXUNIVERSAL__
473
474 // wxRemoveMacControlAssociation( this ) ;
475 // If we delete an item, we should initialize the parent panel,
476 // because it could now be invalid.
477 wxWindow *parent = GetParent() ;
478 if ( parent )
479 {
480 if (parent->GetDefaultItem() == (wxButton*) this)
481 parent->SetDefaultItem(NULL);
482 }
483 if ( (ControlRef) m_macControl )
484 {
485 // in case the callback might be called during destruction
486 wxRemoveMacControlAssociation( this) ;
487 ::SetControlColorProc( (ControlRef) m_macControl , NULL ) ;
488 ::DisposeControl( (ControlRef) m_macControl ) ;
489 m_macControl = NULL ;
490 }
491
492 if ( g_MacLastWindow == this )
493 {
494 g_MacLastWindow = NULL ;
495 }
496
497 wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame ) ;
498 if ( frame )
499 {
500 if ( frame->GetLastFocus() == this )
501 frame->SetLastFocus( NULL ) ;
502 }
503
504 if ( gFocusWindow == this )
505 {
506 gFocusWindow = NULL ;
507 }
508
509 DestroyChildren();
510
511 // delete our drop target if we've got one
512 #if wxUSE_DRAG_AND_DROP
513 if ( m_dropTarget != NULL )
514 {
515 delete m_dropTarget;
516 m_dropTarget = NULL;
517 }
518 #endif // wxUSE_DRAG_AND_DROP
519 }
520
521 //
522
523 void wxWindowMac::MacInstallEventHandler()
524 {
525 InstallControlEventHandler( (ControlRef) m_macControl, GetwxMacWindowEventHandlerUPP(),
526 GetEventTypeCount(eventList), eventList, this,
527 (EventHandlerRef *)&m_macControlEventHandler);
528
529 }
530
531 // Constructor
532 bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id,
533 const wxPoint& pos,
534 const wxSize& size,
535 long style,
536 const wxString& name)
537 {
538 wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindowMac without parent") );
539
540 if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
541 return FALSE;
542
543 parent->AddChild(this);
544
545 m_windowVariant = parent->GetWindowVariant() ;
546
547 if ( m_macIsUserPane )
548 {
549 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
550
551 UInt32 features = kControlSupportsEmbedding | kControlSupportsLiveFeedback /*| kControlHasSpecialBackground */ | kControlSupportsCalcBestRect | kControlHandlesTracking | kControlSupportsFocus | kControlWantsActivate | kControlWantsIdle;
552
553 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds, features, (ControlRef*) &m_macControl);
554
555 MacPostControlCreate(pos,size) ;
556 #if !TARGET_API_MAC_OSX
557 SetControlData((ControlRef) m_macControl,kControlEntireControl,kControlUserPaneDrawProcTag,
558 sizeof(gControlUserPaneDrawUPP),(Ptr) &gControlUserPaneDrawUPP);
559 SetControlData((ControlRef) m_macControl,kControlEntireControl,kControlUserPaneHitTestProcTag,
560 sizeof(gControlUserPaneHitTestUPP),(Ptr) &gControlUserPaneHitTestUPP);
561 SetControlData((ControlRef) m_macControl,kControlEntireControl,kControlUserPaneTrackingProcTag,
562 sizeof(gControlUserPaneTrackingUPP),(Ptr) &gControlUserPaneTrackingUPP);
563 SetControlData((ControlRef) m_macControl,kControlEntireControl,kControlUserPaneIdleProcTag,
564 sizeof(gControlUserPaneIdleUPP),(Ptr) &gControlUserPaneIdleUPP);
565 SetControlData((ControlRef) m_macControl,kControlEntireControl,kControlUserPaneKeyDownProcTag,
566 sizeof(gControlUserPaneKeyDownUPP),(Ptr) &gControlUserPaneKeyDownUPP);
567 SetControlData((ControlRef) m_macControl,kControlEntireControl,kControlUserPaneActivateProcTag,
568 sizeof(gControlUserPaneActivateUPP),(Ptr) &gControlUserPaneActivateUPP);
569 SetControlData((ControlRef) m_macControl,kControlEntireControl,kControlUserPaneFocusProcTag,
570 sizeof(gControlUserPaneFocusUPP),(Ptr) &gControlUserPaneFocusUPP);
571 SetControlData((ControlRef) m_macControl,kControlEntireControl,kControlUserPaneBackgroundProcTag,
572 sizeof(gControlUserPaneBackgroundUPP),(Ptr) &gControlUserPaneBackgroundUPP);
573 #endif
574 }
575 #ifndef __WXUNIVERSAL__
576 // Don't give scrollbars to wxControls unless they ask for them
577 if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar))) ||
578 (IsKindOf(CLASSINFO(wxControl)) && ( style & wxHSCROLL || style & wxVSCROLL)))
579 {
580 MacCreateScrollBars( style ) ;
581 }
582 #endif
583
584 wxWindowCreateEvent event(this);
585 GetEventHandler()->AddPendingEvent(event);
586
587 return TRUE;
588 }
589
590 void wxWindowMac::MacPostControlCreate(const wxPoint& pos, const wxSize& size)
591 {
592 wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ;
593
594 wxAssociateControlWithMacControl( (ControlRef) m_macControl , this ) ;
595 ::SetControlReference( (ControlRef) m_macControl , (long) this ) ;
596
597 MacInstallEventHandler();
598
599 ControlRef container = (ControlRef) GetParent()->GetHandle() ;
600 wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
601 ::EmbedControl( (ControlRef) m_macControl , container ) ;
602
603 // adjust font, controlsize etc
604 DoSetWindowVariant( m_windowVariant ) ;
605
606 #if !TARGET_API_MAC_OSX
607 // eventually we can fix some clipping issues be reactivating this hook
608 //if ( m_macIsUserPane )
609 // SetControlColorProc( (ControlRef) m_macControl , wxMacSetupControlBackgroundUPP ) ;
610 #endif
611
612 UMASetControlTitle( (ControlRef) m_macControl , wxStripMenuCodes(m_label) , m_font.GetEncoding() ) ;
613
614 wxSize new_size = size ;
615 if (!m_macIsUserPane)
616 {
617 wxSize best_size( DoGetBestSize() );
618
619 if (size.x == -1) {
620 new_size.x = best_size.x;
621 }
622 if (size.y == -1) {
623 new_size.y = best_size.y;
624 }
625 SetSize( pos.x, pos.y , new_size.x, new_size.y,wxSIZE_USE_EXISTING );
626 }
627
628 SetCursor( *wxSTANDARD_CURSOR ) ;
629
630 }
631
632 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant )
633 {
634 wxASSERT( m_macControl != NULL ) ;
635
636 m_windowVariant = variant ;
637
638 ControlSize size ;
639 ThemeFontID themeFont = kThemeSystemFont ;
640
641 // we will get that from the settings later
642 // and make this NORMAL later, but first
643 // we have a few calculations that we must fix
644
645 switch ( variant )
646 {
647 case wxWINDOW_VARIANT_NORMAL :
648 size = kControlSizeNormal;
649 themeFont = kThemeSystemFont ;
650 break ;
651 case wxWINDOW_VARIANT_SMALL :
652 size = kControlSizeSmall;
653 themeFont = kThemeSmallSystemFont ;
654 break ;
655 case wxWINDOW_VARIANT_MINI :
656 if (UMAGetSystemVersion() >= 0x1030 )
657 {
658 // not always defined in the headers
659 size = 3 ;
660 themeFont = 109 ;
661 }
662 else
663 {
664 size = kControlSizeSmall;
665 themeFont = kThemeSmallSystemFont ;
666 }
667 break ;
668 case wxWINDOW_VARIANT_LARGE :
669 size = kControlSizeLarge;
670 themeFont = kThemeSystemFont ;
671 break ;
672 default:
673 wxFAIL_MSG(_T("unexpected window variant"));
674 break ;
675 }
676 ::SetControlData( (ControlRef) m_macControl , kControlEntireControl, kControlSizeTag, sizeof( ControlSize ), &size );
677
678 wxFont font ;
679 font.MacCreateThemeFont( themeFont ) ;
680 SetFont( font ) ;
681 }
682
683 void wxWindowMac::MacUpdateControlFont()
684 {
685 ControlFontStyleRec fontStyle;
686 if ( m_font.MacGetThemeFontID() != kThemeCurrentPortFont )
687 {
688 switch( m_font.MacGetThemeFontID() )
689 {
690 case kThemeSmallSystemFont : fontStyle.font = kControlFontSmallSystemFont ; break ;
691 case 109 /*mini font */ : fontStyle.font = -5 ; break ;
692 case kThemeSystemFont : fontStyle.font = kControlFontBigSystemFont ; break ;
693 default : fontStyle.font = kControlFontBigSystemFont ; break ;
694 }
695 fontStyle.flags = kControlUseFontMask ;
696 }
697 else
698 {
699 fontStyle.font = m_font.MacGetFontNum() ;
700 fontStyle.style = m_font.MacGetFontStyle() ;
701 fontStyle.size = m_font.MacGetFontSize() ;
702 fontStyle.flags = kControlUseFontMask | kControlUseFaceMask | kControlUseSizeMask ;
703 }
704
705 fontStyle.just = teJustLeft ;
706 fontStyle.flags |= kControlUseJustMask ;
707 if ( ( GetWindowStyle() & wxALIGN_MASK ) & wxALIGN_CENTER_HORIZONTAL )
708 fontStyle.just = teJustCenter ;
709 else if ( ( GetWindowStyle() & wxALIGN_MASK ) & wxALIGN_RIGHT )
710 fontStyle.just = teJustRight ;
711
712
713 fontStyle.foreColor = MAC_WXCOLORREF(GetForegroundColour().GetPixel() ) ;
714 fontStyle.flags |= kControlUseForeColorMask ;
715
716 ::SetControlFontStyle( (ControlRef) m_macControl , &fontStyle );
717 Refresh() ;
718 }
719
720 bool wxWindowMac::SetFont(const wxFont& font)
721 {
722 bool retval = !wxWindowBase::SetFont( font ) ;
723
724 MacUpdateControlFont() ;
725
726 return retval;
727 }
728
729 bool wxWindowMac::SetForegroundColour(const wxColour& col )
730 {
731 if ( !wxWindowBase::SetForegroundColour(col) )
732 return false ;
733
734 MacUpdateControlFont() ;
735
736 return true ;
737 }
738
739 bool wxWindowMac::SetBackgroundColour(const wxColour& col )
740 {
741 if ( !wxWindowBase::SetBackgroundColour(col) && m_hasBgCol )
742 return false ;
743
744 wxBrush brush ;
745 if ( col == wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) )
746 {
747 brush.MacSetTheme( kThemeBrushDocumentWindowBackground ) ;
748 }
749 else if ( col == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) )
750 {
751 brush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ;
752 }
753 else
754 {
755 brush.SetColour( col ) ;
756 }
757 MacSetBackgroundBrush( brush ) ;
758
759 MacUpdateControlFont() ;
760
761 return true ;
762 }
763
764
765 bool wxWindowMac::MacCanFocus() const
766 {
767 wxASSERT( m_macControl != NULL ) ;
768
769 return true ;
770 }
771
772
773 void wxWindowMac::SetFocus()
774 {
775 if ( gFocusWindow == this )
776 return ;
777
778 if ( AcceptsFocus() )
779 {
780 if (gFocusWindow )
781 {
782 #if wxUSE_CARET
783 // Deal with caret
784 if ( gFocusWindow->m_caret )
785 {
786 gFocusWindow->m_caret->OnKillFocus();
787 }
788 #endif // wxUSE_CARET
789 #ifndef __WXUNIVERSAL__
790 wxWindow* control = wxDynamicCast( gFocusWindow , wxWindow ) ;
791 // TODO we must use the built-in focusing
792 if ( control && control->GetHandle() /* && control->MacIsReallyShown() */ )
793 {
794 UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetTopLevelWindowRef() , (ControlRef) control->GetHandle() , kControlFocusNoPart ) ;
795 control->MacRedrawControl() ;
796 }
797 #endif
798 // Without testing the window id, for some reason
799 // a kill focus event can still be sent to
800 // the control just being focussed.
801 int thisId = this->m_windowId;
802 int gFocusWindowId = gFocusWindow->m_windowId;
803 if (gFocusWindowId != thisId)
804 {
805 wxFocusEvent event(wxEVT_KILL_FOCUS, gFocusWindow->m_windowId);
806 event.SetEventObject(gFocusWindow);
807 gFocusWindow->GetEventHandler()->ProcessEvent(event) ;
808 }
809 }
810 gFocusWindow = this ;
811 {
812 #if wxUSE_CARET
813 // Deal with caret
814 if ( m_caret )
815 {
816 m_caret->OnSetFocus();
817 }
818 #endif // wxUSE_CARET
819 // panel wants to track the window which was the last to have focus in it
820 wxChildFocusEvent eventFocus(this);
821 GetEventHandler()->ProcessEvent(eventFocus);
822
823 #ifndef __WXUNIVERSAL__
824 wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ;
825 if ( control && control->GetHandle() )
826 {
827 UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetTopLevelWindowRef() , (ControlRef) control->GetHandle() , kControlFocusNextPart ) ;
828 }
829 #endif
830 wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId);
831 event.SetEventObject(this);
832 GetEventHandler()->ProcessEvent(event) ;
833 }
834 }
835 }
836
837
838 void wxWindowMac::DoCaptureMouse()
839 {
840 wxTheApp->s_captureWindow = this ;
841 }
842
843 wxWindow* wxWindowBase::GetCapture()
844 {
845 return wxTheApp->s_captureWindow ;
846 }
847
848 void wxWindowMac::DoReleaseMouse()
849 {
850 wxTheApp->s_captureWindow = NULL ;
851 }
852
853 #if wxUSE_DRAG_AND_DROP
854
855 void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget)
856 {
857 if ( m_dropTarget != 0 ) {
858 delete m_dropTarget;
859 }
860
861 m_dropTarget = pDropTarget;
862 if ( m_dropTarget != 0 )
863 {
864 // TODO
865 }
866 }
867
868 #endif
869
870 // Old style file-manager drag&drop
871 void wxWindowMac::DragAcceptFiles(bool accept)
872 {
873 // TODO
874 }
875
876 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x, int& y,
877 int& w, int& h) const
878 {
879 Rect bounds ;
880 GetControlBounds( (ControlRef) m_macControl , &bounds ) ;
881
882
883 x = bounds.left ;
884 y = bounds.top ;
885 w = bounds.right - bounds.left ;
886 h = bounds.bottom - bounds.top ;
887
888 wxTopLevelWindow* tlw = wxDynamicCast( this , wxTopLevelWindow ) ;
889 if ( tlw )
890 {
891 Point tlworigin = { 0 , 0 } ;
892 GrafPtr port ;
893 ::GetPort( &port ) ;
894 ::SetPort( UMAGetWindowPort( (WindowRef) tlw->MacGetWindowRef() ) ) ;
895 ::LocalToGlobal( &tlworigin ) ;
896 ::SetPort( port ) ;
897 x = tlworigin.h ;
898 y = tlworigin.v ;
899 }
900 }
901
902 bool wxWindowMac::MacGetBoundsForControl(const wxPoint& pos,
903 const wxSize& size,
904 int& x, int& y,
905 int& w, int& h) const
906 {
907 x = (int)pos.x;
908 y = (int)pos.y;
909 // todo the default calls may be used as soon as PostCreateControl Is moved here
910 w = size.x ; // WidthDefault( size.x );
911 h = size.y ; // HeightDefault( size.y ) ;
912 #if !TARGET_API_MAC_OSX
913 GetParent()->MacWindowToRootWindow( &x , &y ) ;
914 #endif
915
916 return true ;
917 }
918
919 // Get total size
920 void wxWindowMac::DoGetSize(int *x, int *y) const
921 {
922 #if TARGET_API_MAC_OSX
923 int x1 , y1 , w1 ,h1 ;
924 MacGetPositionAndSizeFromControl( x1 , y1, w1 ,h1 ) ;
925 if(x) *x = w1 ;
926 if(y) *y = h1 ;
927
928 #else
929 Rect bounds ;
930 GetControlBounds( (ControlRef) m_macControl , &bounds ) ;
931 if(x) *x = bounds.right - bounds.left ;
932 if(y) *y = bounds.bottom - bounds.top ;
933 #endif
934 }
935
936 void wxWindowMac::DoGetPosition(int *x, int *y) const
937 {
938 #if TARGET_API_MAC_OSX
939 int x1 , y1 , w1 ,h1 ;
940 MacGetPositionAndSizeFromControl( x1 , y1, w1 ,h1 ) ;
941 if ( !IsTopLevel() )
942 {
943 wxWindow *parent = GetParent();
944 if ( parent )
945 {
946 wxPoint pt(parent->GetClientAreaOrigin());
947 x1 -= pt.x ;
948 y1 -= pt.y ;
949 }
950 }
951 if(x) *x = x1 ;
952 if(y) *y = y1 ;
953 #else
954 Rect bounds ;
955 GetControlBounds( (ControlRef) m_macControl , &bounds ) ;
956 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
957
958 int xx = bounds.left ;
959 int yy = bounds.top ;
960
961 if ( !GetParent()->IsTopLevel() )
962 {
963 GetControlBounds( (ControlRef) GetParent()->GetHandle() , &bounds ) ;
964
965 xx -= bounds.left ;
966 yy -= bounds.top ;
967 }
968
969 wxPoint pt(GetParent()->GetClientAreaOrigin());
970 xx -= pt.x;
971 yy -= pt.y;
972
973 if(x) *x = xx;
974 if(y) *y = yy;
975 #endif
976 }
977
978 void wxWindowMac::DoScreenToClient(int *x, int *y) const
979 {
980 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
981
982 wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ;
983
984 {
985 Point localwhere = {0,0} ;
986
987 if(x) localwhere.h = * x ;
988 if(y) localwhere.v = * y ;
989
990 wxMacPortSaver s((GrafPtr)GetWindowPort( window )) ;
991 ::GlobalToLocal( &localwhere ) ;
992 if(x) *x = localwhere.h ;
993 if(y) *y = localwhere.v ;
994
995 }
996 MacRootWindowToWindow( x , y ) ;
997
998 wxPoint origin = GetClientAreaOrigin() ;
999 if(x) *x -= origin.x ;
1000 if(y) *y -= origin.y ;
1001 }
1002
1003 void wxWindowMac::DoClientToScreen(int *x, int *y) const
1004 {
1005 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
1006 wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ;
1007
1008 wxPoint origin = GetClientAreaOrigin() ;
1009 if(x) *x += origin.x ;
1010 if(y) *y += origin.y ;
1011
1012 MacWindowToRootWindow( x , y ) ;
1013
1014 {
1015 Point localwhere = { 0,0 };
1016 if(x) localwhere.h = * x ;
1017 if(y) localwhere.v = * y ;
1018
1019 wxMacPortSaver s((GrafPtr)GetWindowPort( window )) ;
1020 ::LocalToGlobal( &localwhere ) ;
1021 if(x) *x = localwhere.h ;
1022 if(y) *y = localwhere.v ;
1023 }
1024 }
1025
1026 void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const
1027 {
1028 wxPoint origin = GetClientAreaOrigin() ;
1029 if(x) *x += origin.x ;
1030 if(y) *y += origin.y ;
1031
1032 MacWindowToRootWindow( x , y ) ;
1033 }
1034
1035 void wxWindowMac::MacRootWindowToClient( int *x , int *y ) const
1036 {
1037 MacRootWindowToWindow( x , y ) ;
1038
1039 wxPoint origin = GetClientAreaOrigin() ;
1040 if(x) *x -= origin.x ;
1041 if(y) *y -= origin.y ;
1042 }
1043
1044 void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const
1045 {
1046 #if TARGET_API_MAC_OSX
1047 HIPoint pt ;
1048 if ( x ) pt.x = *x ;
1049 if ( y ) pt.y = *y ;
1050
1051 HIViewConvertPoint( &pt , (ControlRef) m_macControl , (ControlRef) MacGetTopLevelWindow()->GetHandle() ) ;
1052
1053 if ( x ) *x = (int) pt.x ;
1054 if ( y ) *y = (int) pt.y ;
1055 #else
1056 if ( !IsTopLevel() )
1057 {
1058 Rect bounds ;
1059 GetControlBounds( (ControlRef) m_macControl , &bounds ) ;
1060 if(x) *x += bounds.left ;
1061 if(y) *y += bounds.top ;
1062 }
1063 #endif
1064 }
1065
1066 void wxWindowMac::MacWindowToRootWindow( short *x , short *y ) const
1067 {
1068 int x1 , y1 ;
1069 if ( x ) x1 = *x ;
1070 if ( y ) y1 = *y ;
1071 MacWindowToRootWindow( &x1 , &y1 ) ;
1072 if ( x ) *x = x1 ;
1073 if ( y ) *y = y1 ;
1074 }
1075
1076 void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const
1077 {
1078 #if TARGET_API_MAC_OSX
1079 HIPoint pt ;
1080 if ( x ) pt.x = *x ;
1081 if ( y ) pt.y = *y ;
1082
1083 HIViewConvertPoint( &pt , (ControlRef) MacGetTopLevelWindow()->GetHandle() , (ControlRef) m_macControl ) ;
1084
1085 if ( x ) *x = (int) pt.x ;
1086 if ( y ) *y = (int) pt.y ;
1087 #else
1088 if ( !IsTopLevel() )
1089 {
1090 Rect bounds ;
1091 GetControlBounds( (ControlRef) m_macControl , &bounds ) ;
1092 if(x) *x -= bounds.left ;
1093 if(y) *y -= bounds.top ;
1094 }
1095 #endif
1096 }
1097
1098 void wxWindowMac::MacRootWindowToWindow( short *x , short *y ) const
1099 {
1100 int x1 , y1 ;
1101 if ( x ) x1 = *x ;
1102 if ( y ) y1 = *y ;
1103 MacRootWindowToWindow( &x1 , &y1 ) ;
1104 if ( x ) *x = x1 ;
1105 if ( y ) *y = y1 ;
1106 }
1107
1108 wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const
1109 {
1110 wxSize sizeTotal = size;
1111
1112 RgnHandle rgn = NewRgn() ;
1113
1114 Rect content ;
1115
1116 if ( GetControlRegion( (ControlRef) m_macControl , kControlContentMetaPart , rgn ) == noErr )
1117 {
1118 GetRegionBounds( rgn , &content ) ;
1119 DisposeRgn( rgn ) ;
1120 }
1121 else
1122 {
1123 GetControlBounds( (ControlRef) m_macControl , &content ) ;
1124 }
1125 Rect structure ;
1126 GetControlBounds( (ControlRef) m_macControl , &structure ) ;
1127 #if !TARGET_API_MAC_OSX
1128 OffsetRect( &content , -structure.left , -structure.top ) ;
1129 #endif
1130
1131 sizeTotal.x += (structure.right - structure.left) - (content.right - content.left) ;
1132 sizeTotal.y += (structure.bottom - structure.top) - (content.bottom - content.top ) ;
1133
1134 sizeTotal.x += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1135 sizeTotal.y += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1136
1137 return sizeTotal;
1138 }
1139
1140
1141 // Get size *available for subwindows* i.e. excluding menu bar etc.
1142 void wxWindowMac::DoGetClientSize(int *x, int *y) const
1143 {
1144 int ww, hh;
1145
1146 RgnHandle rgn = NewRgn() ;
1147 Rect content ;
1148 if ( GetControlRegion( (ControlRef) m_macControl , kControlContentMetaPart , rgn ) == noErr )
1149 {
1150 GetRegionBounds( rgn , &content ) ;
1151 DisposeRgn( rgn ) ;
1152 }
1153 else
1154 {
1155 GetControlBounds( (ControlRef) m_macControl , &content ) ;
1156 }
1157 #if !TARGET_API_MAC_OSX
1158 Rect structure ;
1159 GetControlBounds( (ControlRef) m_macControl , &structure ) ;
1160 OffsetRect( &content , -structure.left , -structure.top ) ;
1161 #endif
1162 ww = content.right - content.left ;
1163 hh = content.bottom - content.top ;
1164
1165 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1166 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1167
1168 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
1169 {
1170 int x1 = 0 ;
1171 int y1 = 0 ;
1172 int w ;
1173 int h ;
1174 GetSize( &w , &h ) ;
1175
1176 MacClientToRootWindow( &x1 , &y1 ) ;
1177 MacClientToRootWindow( &w , &h ) ;
1178
1179 wxWindowMac *iter = (wxWindowMac*)this ;
1180
1181 int totW = 10000 , totH = 10000;
1182 while( iter )
1183 {
1184 if ( iter->IsTopLevel() )
1185 {
1186 iter->GetSize( &totW , &totH ) ;
1187 break ;
1188 }
1189
1190 iter = iter->GetParent() ;
1191 }
1192
1193 if (m_hScrollBar && m_hScrollBar->IsShown() )
1194 {
1195 hh -= MAC_SCROLLBAR_SIZE;
1196 if ( h-y1 >= totH )
1197 {
1198 hh += 1 ;
1199 }
1200 }
1201 if (m_vScrollBar && m_vScrollBar->IsShown() )
1202 {
1203 ww -= MAC_SCROLLBAR_SIZE;
1204 if ( w-x1 >= totW )
1205 {
1206 ww += 1 ;
1207 }
1208 }
1209 }
1210 if(x) *x = ww;
1211 if(y) *y = hh;
1212
1213 }
1214
1215 bool wxWindowMac::SetCursor(const wxCursor& cursor)
1216 {
1217 if (m_cursor == cursor)
1218 return FALSE;
1219
1220 if (wxNullCursor == cursor)
1221 {
1222 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) )
1223 return FALSE ;
1224 }
1225 else
1226 {
1227 if ( ! wxWindowBase::SetCursor( cursor ) )
1228 return FALSE ;
1229 }
1230
1231 wxASSERT_MSG( m_cursor.Ok(),
1232 wxT("cursor must be valid after call to the base version"));
1233
1234 /*
1235
1236 TODO why do we have to use current coordinates ?
1237
1238 Point pt ;
1239 wxWindowMac *mouseWin ;
1240 GetMouse( &pt ) ;
1241
1242 // Change the cursor NOW if we're within the correct window
1243
1244
1245 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1246 {
1247 if ( mouseWin == this && !wxIsBusy() )
1248 {
1249 m_cursor.MacInstall() ;
1250 }
1251 }
1252 */
1253 if ( !wxIsBusy() )
1254 {
1255 m_cursor.MacInstall() ;
1256 }
1257
1258 return TRUE ;
1259 }
1260
1261 #if wxUSE_MENUS
1262 bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y)
1263 {
1264 menu->SetInvokingWindow(this);
1265 menu->UpdateUI();
1266 ClientToScreen( &x , &y ) ;
1267
1268 menu->MacBeforeDisplay( true ) ;
1269 long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ;
1270 if ( HiWord(menuResult) != 0 )
1271 {
1272 MenuCommand id ;
1273 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &id ) ;
1274 wxMenuItem* item = NULL ;
1275 wxMenu* realmenu ;
1276 item = menu->FindItem(id, &realmenu) ;
1277 if (item->IsCheckable())
1278 {
1279 item->Check( !item->IsChecked() ) ;
1280 }
1281 menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ;
1282 }
1283 menu->MacAfterDisplay( true ) ;
1284
1285 menu->SetInvokingWindow(NULL);
1286
1287 return TRUE;
1288 }
1289 #endif
1290
1291 // ----------------------------------------------------------------------------
1292 // tooltips
1293 // ----------------------------------------------------------------------------
1294
1295 #if wxUSE_TOOLTIPS
1296
1297 void wxWindowMac::DoSetToolTip(wxToolTip *tooltip)
1298 {
1299 wxWindowBase::DoSetToolTip(tooltip);
1300
1301 if ( m_tooltip )
1302 m_tooltip->SetWindow(this);
1303 }
1304
1305 #endif // wxUSE_TOOLTIPS
1306
1307 void wxWindowMac::DoMoveWindow(int x, int y, int width, int height)
1308 {
1309 int former_x , former_y , former_w, former_h ;
1310 #if !TARGET_API_MAC_OSX
1311 DoGetPosition( &former_x , &former_y ) ;
1312 DoGetSize( &former_w , &former_h ) ;
1313 #else
1314 MacGetPositionAndSizeFromControl( former_x , former_y , former_w , former_h ) ;
1315 #endif
1316
1317 int actualWidth = width;
1318 int actualHeight = height;
1319 int actualX = x;
1320 int actualY = y;
1321
1322 if ((m_minWidth != -1) && (actualWidth < m_minWidth))
1323 actualWidth = m_minWidth;
1324 if ((m_minHeight != -1) && (actualHeight < m_minHeight))
1325 actualHeight = m_minHeight;
1326 if ((m_maxWidth != -1) && (actualWidth > m_maxWidth))
1327 actualWidth = m_maxWidth;
1328 if ((m_maxHeight != -1) && (actualHeight > m_maxHeight))
1329 actualHeight = m_maxHeight;
1330
1331 bool doMove = false ;
1332 bool doResize = false ;
1333
1334 if ( actualX != former_x || actualY != former_y )
1335 {
1336 doMove = true ;
1337 }
1338 if ( actualWidth != former_w || actualHeight != former_h )
1339 {
1340 doResize = true ;
1341 }
1342
1343 if ( doMove || doResize )
1344 {
1345 Rect r = wxMacGetBoundsForControl(this , wxPoint( actualX,actualY), wxSize( actualWidth, actualHeight ) ) ;
1346 #if TARGET_API_MAC_OSX
1347 SetControlBounds( (ControlRef) m_macControl , &r ) ;
1348 #else
1349 if ( doMove )
1350 MoveControl( (ControlRef) m_macControl , r.left , r.top ) ;
1351 if ( doSize )
1352 SizeControl( (ControlRef) m_macControl , r.right-r.left , r.bottom-r.top ) ;
1353 #endif
1354 MacRepositionScrollBars() ;
1355 if ( doMove )
1356 {
1357 wxPoint point(actualX,actualY);
1358 wxMoveEvent event(point, m_windowId);
1359 event.SetEventObject(this);
1360 GetEventHandler()->ProcessEvent(event) ;
1361 }
1362 if ( doResize )
1363 {
1364 MacRepositionScrollBars() ;
1365 wxSize size(actualWidth, actualHeight);
1366 wxSizeEvent event(size, m_windowId);
1367 event.SetEventObject(this);
1368 GetEventHandler()->ProcessEvent(event);
1369 }
1370 }
1371
1372 }
1373
1374 wxSize wxWindowMac::DoGetBestSize() const
1375 {
1376 /*
1377 Rect bestsize = { 0 , 0 , 0 , 0 } ;
1378 short baselineoffset ;
1379 int bestWidth, bestHeight ;
1380 ::GetBestControlRect( (ControlRef) m_macControl , &bestsize , &baselineoffset ) ;
1381
1382 if ( EmptyRect( &bestsize ) )
1383 {
1384 baselineoffset = 0;
1385 bestsize.left = bestsize.top = 0 ;
1386 bestsize.right = 16 ;
1387 bestsize.bottom = 16 ;
1388 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
1389 {
1390 bestsize.bottom = 16 ;
1391 }
1392 else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
1393 {
1394 bestsize.bottom = 24 ;
1395 }
1396 else
1397 {
1398 // return wxWindowBase::DoGetBestSize() ;
1399 }
1400 }
1401
1402 bestWidth = bestsize.right - bestsize.left ;
1403 bestHeight = bestsize.bottom - bestsize.top ;
1404 if ( bestHeight < 10 )
1405 bestHeight = 13 ;
1406
1407 return wxSize(bestWidth, bestHeight);
1408 */
1409 return wxWindowBase::DoGetBestSize() ;
1410 }
1411
1412
1413 // set the size of the window: if the dimensions are positive, just use them,
1414 // but if any of them is equal to -1, it means that we must find the value for
1415 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1416 // which case -1 is a valid value for x and y)
1417 //
1418 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1419 // the width/height to best suit our contents, otherwise we reuse the current
1420 // width/height
1421 void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags)
1422 {
1423 // get the current size and position...
1424 int currentX, currentY;
1425 GetPosition(&currentX, &currentY);
1426
1427 int currentW,currentH;
1428 GetSize(&currentW, &currentH);
1429
1430 // ... and don't do anything (avoiding flicker) if it's already ok
1431 if ( x == currentX && y == currentY &&
1432 width == currentW && height == currentH && ( height != -1 && width != -1 ) )
1433 {
1434 // TODO REMOVE
1435 MacRepositionScrollBars() ; // we might have a real position shift
1436 return;
1437 }
1438
1439 if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
1440 x = currentX;
1441 if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
1442 y = currentY;
1443
1444 AdjustForParentClientOrigin(x, y, sizeFlags);
1445
1446 wxSize size(-1, -1);
1447 if ( width == -1 )
1448 {
1449 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
1450 {
1451 size = DoGetBestSize();
1452 width = size.x;
1453 }
1454 else
1455 {
1456 // just take the current one
1457 width = currentW;
1458 }
1459 }
1460
1461 if ( height == -1 )
1462 {
1463 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
1464 {
1465 if ( size.x == -1 )
1466 {
1467 size = DoGetBestSize();
1468 }
1469 //else: already called DoGetBestSize() above
1470
1471 height = size.y;
1472 }
1473 else
1474 {
1475 // just take the current one
1476 height = currentH;
1477 }
1478 }
1479
1480 DoMoveWindow(x, y, width, height);
1481
1482 }
1483
1484 wxPoint wxWindowMac::GetClientAreaOrigin() const
1485 {
1486 RgnHandle rgn = NewRgn() ;
1487 Rect content ;
1488 GetControlRegion( (ControlRef) m_macControl , kControlContentMetaPart , rgn ) ;
1489 GetRegionBounds( rgn , &content ) ;
1490 DisposeRgn( rgn ) ;
1491 #if !TARGET_API_MAC_OSX
1492 Rect structure ;
1493 GetControlBounds( (ControlRef) m_macControl , &structure ) ;
1494 OffsetRect( &content , -structure.left , -structure.top ) ;
1495 #endif
1496
1497 return wxPoint( content.left + MacGetLeftBorderSize( ) , content.top + MacGetTopBorderSize( ) );
1498 }
1499
1500 void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight)
1501 {
1502 if ( clientheight != -1 || clientheight != -1 )
1503 {
1504 int currentclientwidth , currentclientheight ;
1505 int currentwidth , currentheight ;
1506
1507 GetClientSize( &currentclientwidth , &currentclientheight ) ;
1508 GetSize( &currentwidth , &currentheight ) ;
1509
1510 DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth ,
1511 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
1512 }
1513 }
1514
1515 void wxWindowMac::SetTitle(const wxString& title)
1516 {
1517 m_label = wxStripMenuCodes(title) ;
1518
1519 if ( m_macControl )
1520 {
1521 UMASetControlTitle( (ControlRef) m_macControl , m_label , m_font.GetEncoding() ) ;
1522 }
1523 Refresh() ;
1524 }
1525
1526 wxString wxWindowMac::GetTitle() const
1527 {
1528 return m_label ;
1529 }
1530
1531 bool wxWindowMac::Show(bool show)
1532 {
1533 if ( !wxWindowBase::Show(show) )
1534 return FALSE;
1535
1536 // TODO use visibilityChanged Carbon Event for OSX
1537 bool former = MacIsReallyShown() ;
1538
1539 SetControlVisibility( (ControlRef) m_macControl , show , true ) ;
1540 if ( former != MacIsReallyShown() )
1541 MacPropagateVisibilityChanged() ;
1542 return TRUE;
1543 }
1544
1545 bool wxWindowMac::Enable(bool enable)
1546 {
1547 wxASSERT( m_macControl != NULL ) ;
1548 if ( !wxWindowBase::Enable(enable) )
1549 return FALSE;
1550
1551 bool former = MacIsReallyEnabled() ;
1552 if ( enable )
1553 EnableControl( (ControlRef) m_macControl ) ;
1554 else
1555 DisableControl( (ControlRef) m_macControl ) ;
1556
1557 if ( former != MacIsReallyEnabled() )
1558 MacPropagateEnabledStateChanged() ;
1559 return TRUE;
1560 }
1561
1562 //
1563 // status change propagations (will be not necessary for OSX later )
1564 //
1565
1566 void wxWindowMac::MacPropagateVisibilityChanged()
1567 {
1568 #if !TARGET_API_MAC_OSX
1569 MacVisibilityChanged() ;
1570
1571 wxWindowListNode *node = GetChildren().GetFirst();
1572 while ( node )
1573 {
1574 wxWindowMac *child = node->GetData();
1575 if ( child->IsShown() )
1576 child->MacPropagateVisibilityChanged( ) ;
1577 node = node->GetNext();
1578 }
1579 #endif
1580 }
1581
1582 void wxWindowMac::MacPropagateEnabledStateChanged( )
1583 {
1584 #if !TARGET_API_MAC_OSX
1585 MacEnabledStateChanged() ;
1586
1587 wxWindowListNode *node = GetChildren().GetFirst();
1588 while ( node )
1589 {
1590 wxWindowMac *child = node->GetData();
1591 if ( child->IsEnabled() )
1592 child->MacPropagateEnabledStateChanged() ;
1593 node = node->GetNext();
1594 }
1595 #endif
1596 }
1597
1598 void wxWindowMac::MacPropagateHiliteChanged( )
1599 {
1600 #if !TARGET_API_MAC_OSX
1601 MacHiliteChanged() ;
1602
1603 wxWindowListNode *node = GetChildren().GetFirst();
1604 while ( node )
1605 {
1606 wxWindowMac *child = node->GetData();
1607 // if ( child->IsEnabled() )
1608 child->MacPropagateHiliteChanged() ;
1609 node = node->GetNext();
1610 }
1611 #endif
1612 }
1613
1614 //
1615 // status change notifications
1616 //
1617
1618 void wxWindowMac::MacVisibilityChanged()
1619 {
1620 }
1621
1622 void wxWindowMac::MacHiliteChanged()
1623 {
1624 }
1625
1626 void wxWindowMac::MacEnabledStateChanged()
1627 {
1628 }
1629
1630 //
1631 // status queries on the inherited window's state
1632 //
1633
1634 bool wxWindowMac::MacIsReallyShown()
1635 {
1636 // only under OSX the visibility of the TLW is taken into account
1637 #if TARGET_API_MAC_OSX
1638 return IsControlVisible( (ControlRef) m_macControl ) ;
1639 #else
1640 wxWindow* win = this ;
1641 while( win->IsShown() )
1642 {
1643 if ( win->IsTopLevel() )
1644 return true ;
1645
1646 win = win->GetParent() ;
1647 if ( win == NULL )
1648 return true ;
1649
1650 } ;
1651 return false ;
1652 #endif
1653 }
1654
1655 bool wxWindowMac::MacIsReallyEnabled()
1656 {
1657 return IsControlEnabled( (ControlRef) m_macControl ) ;
1658 }
1659
1660 bool wxWindowMac::MacIsReallyHilited()
1661 {
1662 return IsControlActive( (ControlRef) m_macControl ) ;
1663 }
1664
1665 //
1666 //
1667 //
1668
1669 int wxWindowMac::GetCharHeight() const
1670 {
1671 wxClientDC dc ( (wxWindowMac*)this ) ;
1672 return dc.GetCharHeight() ;
1673 }
1674
1675 int wxWindowMac::GetCharWidth() const
1676 {
1677 wxClientDC dc ( (wxWindowMac*)this ) ;
1678 return dc.GetCharWidth() ;
1679 }
1680
1681 void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y,
1682 int *descent, int *externalLeading, const wxFont *theFont ) const
1683 {
1684 const wxFont *fontToUse = theFont;
1685 if ( !fontToUse )
1686 fontToUse = &m_font;
1687
1688 wxClientDC dc( (wxWindowMac*) this ) ;
1689 long lx,ly,ld,le ;
1690 dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ;
1691 if ( externalLeading )
1692 *externalLeading = le ;
1693 if ( descent )
1694 *descent = ld ;
1695 if ( x )
1696 *x = lx ;
1697 if ( y )
1698 *y = ly ;
1699 }
1700
1701 /*
1702 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1703 * we always intersect with the entire window, not only with the client area
1704 */
1705
1706 void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect)
1707 {
1708 #if TARGET_API_MAC_OSX
1709 if ( rect == NULL )
1710 HIViewSetNeedsDisplay( (ControlRef) m_macControl , true ) ;
1711 else
1712 {
1713 RgnHandle update = NewRgn() ;
1714 SetRectRgn( update , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1715 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , update , update ) ;
1716 HIViewSetNeedsDisplayInRegion( (ControlRef) m_macControl , update , true ) ;
1717 }
1718 #else
1719 if ( IsControlVisible( (ControlRef) m_macControl ) )
1720 {
1721 SetControlVisibility( (ControlRef) m_macControl , false , false ) ;
1722 SetControlVisibility( (ControlRef) m_macControl , true , true ) ;
1723 }
1724 /*
1725 if ( MacGetTopLevelWindow() == NULL )
1726 return ;
1727
1728 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1729 return ;
1730
1731 wxPoint client = GetClientAreaOrigin();
1732 int x1 = -client.x;
1733 int y1 = -client.y;
1734 int x2 = m_width - client.x;
1735 int y2 = m_height - client.y;
1736
1737 if (IsKindOf( CLASSINFO(wxButton)))
1738 {
1739 // buttons have an "aura"
1740 y1 -= 5;
1741 x1 -= 5;
1742 y2 += 5;
1743 x2 += 5;
1744 }
1745
1746 Rect clientrect = { y1, x1, y2, x2 };
1747
1748 if ( rect )
1749 {
1750 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1751 SectRect( &clientrect , &r , &clientrect ) ;
1752 }
1753
1754 if ( !EmptyRect( &clientrect ) )
1755 {
1756 int top = 0 , left = 0 ;
1757
1758 MacClientToRootWindow( &left , &top ) ;
1759 OffsetRect( &clientrect , left , top ) ;
1760
1761 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1762 }
1763 */
1764 #endif
1765 }
1766
1767 void wxWindowMac::MacRedrawControl()
1768 {
1769 /*
1770 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
1771 {
1772 #if TARGET_API_MAC_CARBON
1773 Update() ;
1774 #else
1775 wxClientDC dc(this) ;
1776 wxMacPortSetter helper(&dc) ;
1777 wxMacWindowClipper clipper(this) ;
1778 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
1779 UMADrawControl( (ControlRef) m_macControl ) ;
1780 #endif
1781 }
1782 */
1783 }
1784
1785 /* TODO
1786 void wxWindowMac::OnPaint(wxPaintEvent& event)
1787 {
1788 // why don't we skip that here ?
1789 }
1790 */
1791
1792 wxWindowMac *wxGetActiveWindow()
1793 {
1794 // actually this is a windows-only concept
1795 return NULL;
1796 }
1797
1798 // Coordinates relative to the window
1799 void wxWindowMac::WarpPointer (int x_pos, int y_pos)
1800 {
1801 // We really don't move the mouse programmatically under Mac.
1802 }
1803
1804 void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
1805 {
1806 if ( m_macBackgroundBrush.Ok() == false || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT )
1807 {
1808 event.Skip() ;
1809 }
1810 else
1811 event.GetDC()->Clear() ;
1812 }
1813
1814 void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
1815 {
1816 wxWindowDC dc(this) ;
1817 wxMacPortSetter helper(&dc) ;
1818
1819 MacPaintBorders( dc.m_macLocalOrigin.x , dc.m_macLocalOrigin.y) ;
1820 }
1821
1822 int wxWindowMac::GetScrollPos(int orient) const
1823 {
1824 if ( orient == wxHORIZONTAL )
1825 {
1826 if ( m_hScrollBar )
1827 return m_hScrollBar->GetThumbPosition() ;
1828 }
1829 else
1830 {
1831 if ( m_vScrollBar )
1832 return m_vScrollBar->GetThumbPosition() ;
1833 }
1834 return 0;
1835 }
1836
1837 // This now returns the whole range, not just the number
1838 // of positions that we can scroll.
1839 int wxWindowMac::GetScrollRange(int orient) const
1840 {
1841 if ( orient == wxHORIZONTAL )
1842 {
1843 if ( m_hScrollBar )
1844 return m_hScrollBar->GetRange() ;
1845 }
1846 else
1847 {
1848 if ( m_vScrollBar )
1849 return m_vScrollBar->GetRange() ;
1850 }
1851 return 0;
1852 }
1853
1854 int wxWindowMac::GetScrollThumb(int orient) const
1855 {
1856 if ( orient == wxHORIZONTAL )
1857 {
1858 if ( m_hScrollBar )
1859 return m_hScrollBar->GetThumbSize() ;
1860 }
1861 else
1862 {
1863 if ( m_vScrollBar )
1864 return m_vScrollBar->GetThumbSize() ;
1865 }
1866 return 0;
1867 }
1868
1869 void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh)
1870 {
1871 if ( orient == wxHORIZONTAL )
1872 {
1873 if ( m_hScrollBar )
1874 m_hScrollBar->SetThumbPosition( pos ) ;
1875 }
1876 else
1877 {
1878 if ( m_vScrollBar )
1879 m_vScrollBar->SetThumbPosition( pos ) ;
1880 }
1881 }
1882
1883 void wxWindowMac::MacPaintBorders( int left , int top )
1884 {
1885 if( IsTopLevel() )
1886 return ;
1887
1888 int major,minor;
1889 wxGetOsVersion( &major, &minor );
1890
1891 RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ;
1892 RGBColor face = { 0xDDDD, 0xDDDD , 0xDDDD } ;
1893
1894 RGBColor darkShadow = { 0x0000, 0x0000 , 0x0000 } ;
1895 RGBColor lightShadow = { 0x4444, 0x4444 , 0x4444 } ;
1896 // OS X has lighter border edges than classic:
1897 if (major >= 10)
1898 {
1899 darkShadow.red = 0x8E8E;
1900 darkShadow.green = 0x8E8E;
1901 darkShadow.blue = 0x8E8E;
1902 lightShadow.red = 0xBDBD;
1903 lightShadow.green = 0xBDBD;
1904 lightShadow.blue = 0xBDBD;
1905 }
1906
1907 PenNormal() ;
1908
1909 int w , h ;
1910 GetSize( &w , &h ) ;
1911 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
1912 {
1913 #if wxMAC_USE_THEME_BORDER
1914 Rect rect = { top , left , m_height + top , m_width + left } ;
1915 SInt32 border = 0 ;
1916 /*
1917 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1918 InsetRect( &rect , border , border );
1919 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1920 */
1921
1922 DrawThemePrimaryGroup(&rect ,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1923 #else
1924 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1925 RGBForeColor( &face );
1926 MoveTo( left + 0 , top + h - 2 );
1927 LineTo( left + 0 , top + 0 );
1928 LineTo( left + w - 2 , top + 0 );
1929
1930 MoveTo( left + 2 , top + h - 3 );
1931 LineTo( left + w - 3 , top + h - 3 );
1932 LineTo( left + w - 3 , top + 2 );
1933
1934 RGBForeColor( sunken ? &face : &darkShadow );
1935 MoveTo( left + 0 , top + h - 1 );
1936 LineTo( left + w - 1 , top + h - 1 );
1937 LineTo( left + w - 1 , top + 0 );
1938
1939 RGBForeColor( sunken ? &lightShadow : &white );
1940 MoveTo( left + 1 , top + h - 3 );
1941 LineTo( left + 1, top + 1 );
1942 LineTo( left + w - 3 , top + 1 );
1943
1944 RGBForeColor( sunken ? &white : &lightShadow );
1945 MoveTo( left + 1 , top + h - 2 );
1946 LineTo( left + w - 2 , top + h - 2 );
1947 LineTo( left + w - 2 , top + 1 );
1948
1949 RGBForeColor( sunken ? &darkShadow : &face );
1950 MoveTo( left + 2 , top + h - 4 );
1951 LineTo( left + 2 , top + 2 );
1952 LineTo( left + w - 4 , top + 2 );
1953 #endif
1954 }
1955 else if (HasFlag(wxSIMPLE_BORDER))
1956 {
1957 Rect rect = { top , left , h + top , w + left } ;
1958 RGBForeColor( &darkShadow ) ;
1959 FrameRect( &rect ) ;
1960 }
1961 }
1962
1963 void wxWindowMac::RemoveChild( wxWindowBase *child )
1964 {
1965 if ( child == m_hScrollBar )
1966 m_hScrollBar = NULL ;
1967 if ( child == m_vScrollBar )
1968 m_vScrollBar = NULL ;
1969
1970 wxWindowBase::RemoveChild( child ) ;
1971 }
1972
1973 // New function that will replace some of the above.
1974 void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible,
1975 int range, bool refresh)
1976 {
1977 if ( orient == wxHORIZONTAL )
1978 {
1979 if ( m_hScrollBar )
1980 {
1981 if ( range == 0 || thumbVisible >= range )
1982 {
1983 if ( m_hScrollBar->IsShown() )
1984 m_hScrollBar->Show(false) ;
1985 }
1986 else
1987 {
1988 if ( !m_hScrollBar->IsShown() )
1989 m_hScrollBar->Show(true) ;
1990 m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
1991 }
1992 }
1993 }
1994 else
1995 {
1996 if ( m_vScrollBar )
1997 {
1998 if ( range == 0 || thumbVisible >= range )
1999 {
2000 if ( m_vScrollBar->IsShown() )
2001 m_vScrollBar->Show(false) ;
2002 }
2003 else
2004 {
2005 if ( !m_vScrollBar->IsShown() )
2006 m_vScrollBar->Show(true) ;
2007 m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
2008 }
2009 }
2010 }
2011 MacRepositionScrollBars() ;
2012 }
2013
2014 // Does a physical scroll
2015 void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
2016 {
2017 if( dx == 0 && dy ==0 )
2018 return ;
2019
2020
2021 {
2022 wxClientDC dc(this) ;
2023 wxMacPortSetter helper(&dc) ;
2024
2025 int width , height ;
2026 GetClientSize( &width , &height ) ;
2027
2028
2029 wxPoint pos;
2030 pos.x = pos.y = 0;
2031
2032 Rect scrollrect;
2033 // TODO take out the boundaries
2034 GetControlBounds( (ControlRef) m_macControl, &scrollrect);
2035
2036 RgnHandle updateRgn = NewRgn() ;
2037 if ( rect )
2038 {
2039 Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) ,
2040 dc.XLOG2DEVMAC(rect->x + rect->width) } ;
2041 SectRect( &scrollrect , &r , &scrollrect ) ;
2042 }
2043 ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
2044 #if TARGET_CARBON
2045 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
2046 // but it seems the update only refreshes the background of the control, rather than calling
2047 // kEventControlDraw, so we need to force a proper update here. There has to be a better
2048 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
2049 Update();
2050 #endif
2051 // we also have to scroll the update rgn in this rectangle
2052 // in order not to loose updates
2053 #if !TARGET_CARBON
2054 WindowRef rootWindow = (WindowRef) MacGetTopLevelWindowRef() ;
2055 RgnHandle formerUpdateRgn = NewRgn() ;
2056 RgnHandle scrollRgn = NewRgn() ;
2057 RectRgn( scrollRgn , &scrollrect ) ;
2058 GetWindowUpdateRgn( rootWindow , formerUpdateRgn ) ;
2059 Point pt = {0,0} ;
2060 LocalToGlobal( &pt ) ;
2061 OffsetRgn( formerUpdateRgn , -pt.h , -pt.v ) ;
2062 SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
2063 if ( !EmptyRgn( formerUpdateRgn ) )
2064 {
2065 MacOffsetRgn( formerUpdateRgn , dx , dy ) ;
2066 SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
2067 InvalWindowRgn(rootWindow , formerUpdateRgn ) ;
2068 }
2069 InvalWindowRgn(rootWindow , updateRgn ) ;
2070 DisposeRgn( updateRgn ) ;
2071 DisposeRgn( formerUpdateRgn ) ;
2072 DisposeRgn( scrollRgn ) ;
2073 #endif
2074 }
2075
2076 for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())
2077 {
2078 wxWindowMac *child = node->GetData();
2079 if (child == m_vScrollBar) continue;
2080 if (child == m_hScrollBar) continue;
2081 if (child->IsTopLevel()) continue;
2082
2083 int x,y;
2084 child->GetPosition( &x, &y );
2085 int w,h;
2086 child->GetSize( &w, &h );
2087 if (rect)
2088 {
2089 wxRect rc(x,y,w,h);
2090 if (rect->Intersects(rc))
2091 child->SetSize( x+dx, y+dy, w, h );
2092 }
2093 else
2094 {
2095 child->SetSize( x+dx, y+dy, w, h );
2096 }
2097 }
2098
2099 // TODO remove, was moved higher up Update() ;
2100
2101 }
2102
2103 void wxWindowMac::MacOnScroll(wxScrollEvent &event )
2104 {
2105 if ( event.m_eventObject == m_vScrollBar || event.m_eventObject == m_hScrollBar )
2106 {
2107 wxScrollWinEvent wevent;
2108 wevent.SetPosition(event.GetPosition());
2109 wevent.SetOrientation(event.GetOrientation());
2110 wevent.m_eventObject = this;
2111
2112 if (event.m_eventType == wxEVT_SCROLL_TOP)
2113 wevent.m_eventType = wxEVT_SCROLLWIN_TOP;
2114 else if (event.m_eventType == wxEVT_SCROLL_BOTTOM)
2115 wevent.m_eventType = wxEVT_SCROLLWIN_BOTTOM;
2116 else if (event.m_eventType == wxEVT_SCROLL_LINEUP)
2117 wevent.m_eventType = wxEVT_SCROLLWIN_LINEUP;
2118 else if (event.m_eventType == wxEVT_SCROLL_LINEDOWN)
2119 wevent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
2120 else if (event.m_eventType == wxEVT_SCROLL_PAGEUP)
2121 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEUP;
2122 else if (event.m_eventType == wxEVT_SCROLL_PAGEDOWN)
2123 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
2124 else if (event.m_eventType == wxEVT_SCROLL_THUMBTRACK)
2125 wevent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
2126 else if (event.m_eventType == wxEVT_SCROLL_THUMBRELEASE)
2127 wevent.m_eventType = wxEVT_SCROLLWIN_THUMBRELEASE;
2128
2129 GetEventHandler()->ProcessEvent(wevent);
2130 }
2131 }
2132
2133 // Get the window with the focus
2134 wxWindowMac *wxWindowBase::FindFocus()
2135 {
2136 return gFocusWindow ;
2137 }
2138
2139 void wxWindowMac::OnSetFocus(wxFocusEvent& event)
2140 {
2141 // panel wants to track the window which was the last to have focus in it,
2142 // so we want to set ourselves as the window which last had focus
2143 //
2144 // notice that it's also important to do it upwards the tree becaus
2145 // otherwise when the top level panel gets focus, it won't set it back to
2146 // us, but to some other sibling
2147
2148 // CS:don't know if this is still needed:
2149 //wxChildFocusEvent eventFocus(this);
2150 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2151
2152 event.Skip();
2153 }
2154
2155 void wxWindowMac::OnInternalIdle()
2156 {
2157 // This calls the UI-update mechanism (querying windows for
2158 // menu/toolbar/control state information)
2159 if (wxUpdateUIEvent::CanUpdate(this))
2160 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
2161 }
2162
2163 // Raise the window to the top of the Z order
2164 void wxWindowMac::Raise()
2165 {
2166 }
2167
2168 // Lower the window to the bottom of the Z order
2169 void wxWindowMac::Lower()
2170 {
2171 }
2172
2173
2174 // static wxWindow *gs_lastWhich = NULL;
2175
2176 bool wxWindowMac::MacSetupCursor( const wxPoint& pt)
2177 {
2178 // first trigger a set cursor event
2179
2180 wxPoint clientorigin = GetClientAreaOrigin() ;
2181 wxSize clientsize = GetClientSize() ;
2182 wxCursor cursor ;
2183 if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) )
2184 {
2185 wxSetCursorEvent event( pt.x , pt.y );
2186
2187 bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event);
2188 if ( processedEvtSetCursor && event.HasCursor() )
2189 {
2190 cursor = event.GetCursor() ;
2191 }
2192 else
2193 {
2194
2195 // the test for processedEvtSetCursor is here to prevent using m_cursor
2196 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2197 // it - this is a way to say that our cursor shouldn't be used for this
2198 // point
2199 if ( !processedEvtSetCursor && m_cursor.Ok() )
2200 {
2201 cursor = m_cursor ;
2202 }
2203 if ( wxIsBusy() )
2204 {
2205 }
2206 else
2207 {
2208 if ( !GetParent() )
2209 cursor = *wxSTANDARD_CURSOR ;
2210 }
2211 }
2212 if ( cursor.Ok() )
2213 cursor.MacInstall() ;
2214 }
2215 return cursor.Ok() ;
2216 }
2217
2218 wxString wxWindowMac::MacGetToolTipString( wxPoint &pt )
2219 {
2220 if ( m_tooltip )
2221 {
2222 return m_tooltip->GetTip() ;
2223 }
2224 return wxEmptyString ;
2225 }
2226
2227 void wxWindowMac::Update()
2228 {
2229 #if TARGET_API_MAC_OSX
2230 HIViewSetNeedsDisplay( (ControlRef) m_macControl , true ) ;
2231 #else
2232 ::Draw1Control( (ControlRef) m_macControl ) ;
2233 #endif
2234 }
2235
2236 wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const
2237 {
2238 wxTopLevelWindowMac* win = NULL ;
2239 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
2240 if ( window )
2241 {
2242 win = wxFindWinFromMacWindow( window ) ;
2243 }
2244 return win ;
2245 }
2246 wxRegion wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures )
2247 {
2248
2249 Rect r ;
2250 RgnHandle visRgn = NewRgn() ;
2251 RgnHandle tempRgn = NewRgn() ;
2252 if ( IsControlVisible( (ControlRef) m_macControl ) )
2253 {
2254 GetControlBounds( (ControlRef) m_macControl , &r ) ;
2255 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2256 {
2257 MacRootWindowToWindow( &r.left , & r.top ) ;
2258 MacRootWindowToWindow( &r.right , & r.bottom ) ;
2259 }
2260 else
2261 {
2262 r.right -= r.left ;
2263 r.bottom -= r.top ;
2264 r.left = 0 ;
2265 r.top = 0 ;
2266 }
2267 if ( includeOuterStructures )
2268 InsetRect( &r , -3 , -3 ) ;
2269 RectRgn( visRgn , &r ) ;
2270 if ( !IsTopLevel() )
2271 {
2272 wxWindow* child = this ;
2273 wxWindow* parent = child->GetParent() ;
2274 while( parent )
2275 {
2276 int x , y ;
2277 wxSize size ;
2278 // we have to find a better clipping algorithm here, in order not to clip things
2279 // positioned like status and toolbar
2280 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2281 {
2282 size = parent->GetSize() ;
2283 x = y = 0 ;
2284 }
2285 else
2286 {
2287 size = parent->GetClientSize() ;
2288 wxPoint origin = parent->GetClientAreaOrigin() ;
2289 x = origin.x ;
2290 y = origin.y ;
2291 }
2292 parent->MacWindowToRootWindow( &x, &y ) ;
2293 MacRootWindowToWindow( &x , &y ) ;
2294
2295 SetRectRgn( tempRgn ,
2296 x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() ,
2297 x + size.x - parent->MacGetRightBorderSize(),
2298 y + size.y - parent->MacGetBottomBorderSize()) ;
2299
2300 SectRgn( visRgn , tempRgn , visRgn ) ;
2301 if ( parent->IsTopLevel() )
2302 break ;
2303 child = parent ;
2304 parent = child->GetParent() ;
2305 }
2306 }
2307 }
2308
2309 wxRegion vis = visRgn ;
2310 DisposeRgn( visRgn ) ;
2311 DisposeRgn( tempRgn ) ;
2312 return vis ;
2313 }
2314
2315 /*
2316 This function must not change the updatergn !
2317 */
2318 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time )
2319 {
2320 // we let the OS handle root control redraws
2321 if ( m_macControl == MacGetTopLevelWindow()->GetHandle() )
2322 return false ;
2323
2324 RgnHandle updatergn = (RgnHandle) updatergnr ;
2325 bool handled = false ;
2326
2327 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2328 {
2329 RgnHandle newupdate = NewRgn() ;
2330 wxSize point = GetClientSize() ;
2331 wxPoint origin = GetClientAreaOrigin() ;
2332 SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ;
2333 SectRgn( newupdate , updatergn , newupdate ) ;
2334 OffsetRgn( newupdate , -origin.x , -origin.y ) ;
2335 m_updateRegion = newupdate ;
2336 DisposeRgn( newupdate ) ;
2337 }
2338
2339 if ( !EmptyRgn(updatergn) )
2340 {
2341 wxWindowDC dc(this);
2342 if (!EmptyRgn(updatergn))
2343 dc.SetClippingRegion(wxRegion(updatergn));
2344
2345 wxEraseEvent eevent( GetId(), &dc );
2346 eevent.SetEventObject( this );
2347 GetEventHandler()->ProcessEvent( eevent );
2348
2349 if ( !m_updateRegion.Empty() )
2350 {
2351 // paint the window itself
2352 wxPaintEvent event;
2353 event.m_timeStamp = time ;
2354 event.SetEventObject(this);
2355 handled = GetEventHandler()->ProcessEvent(event);
2356
2357 // paint custom borders
2358 wxNcPaintEvent eventNc( GetId() );
2359 eventNc.SetEventObject( this );
2360 GetEventHandler()->ProcessEvent( eventNc );
2361 }
2362 }
2363 return handled ;
2364 }
2365
2366 void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase)
2367 {
2368 RgnHandle updatergn = (RgnHandle) updatergnr ;
2369 // updatergn is always already clipped to our boundaries
2370 // if we are in compositing mode then it is in relative to the upper left of the control
2371 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2372 // of the toplevel window
2373 // it is in window coordinates, not in client coordinates
2374
2375 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2376 RgnHandle ownUpdateRgn = NewRgn() ;
2377 CopyRgn( updatergn , ownUpdateRgn ) ;
2378
2379 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2380 {
2381 Rect bounds;
2382 UMAGetControlBoundsInWindowCoords( (ControlRef)m_macControl, &bounds );
2383 RgnHandle controlRgn = NewRgn();
2384 RectRgn( controlRgn, &bounds );
2385 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2386 // the window update region
2387 SectRgn( ownUpdateRgn, controlRgn, ownUpdateRgn );
2388 DisposeRgn( controlRgn );
2389
2390 //KO: convert ownUpdateRgn to local coordinates
2391 OffsetRgn( ownUpdateRgn, -bounds.left, -bounds.top );
2392 }
2393
2394 MacDoRedraw( ownUpdateRgn , time ) ;
2395 DisposeRgn( ownUpdateRgn ) ;
2396
2397 }
2398
2399 WXWindow wxWindowMac::MacGetTopLevelWindowRef() const
2400 {
2401 wxWindowMac *iter = (wxWindowMac*)this ;
2402
2403 while( iter )
2404 {
2405 if ( iter->IsTopLevel() )
2406 return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ;
2407
2408 iter = iter->GetParent() ;
2409 }
2410 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2411 return NULL ;
2412 }
2413
2414 void wxWindowMac::MacCreateScrollBars( long style )
2415 {
2416 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ;
2417
2418 bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
2419 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ;
2420 int width, height ;
2421 GetClientSize( &width , &height ) ;
2422
2423 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
2424 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
2425 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
2426 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
2427
2428 m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint,
2429 vSize , wxVERTICAL);
2430
2431 if ( style & wxVSCROLL )
2432 {
2433
2434 }
2435 else
2436 {
2437 m_vScrollBar->Show(false) ;
2438 }
2439 m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint,
2440 hSize , wxHORIZONTAL);
2441 if ( style & wxHSCROLL )
2442 {
2443 }
2444 else
2445 {
2446 m_hScrollBar->Show(false) ;
2447 }
2448
2449 // because the create does not take into account the client area origin
2450 MacRepositionScrollBars() ; // we might have a real position shift
2451 }
2452
2453 void wxWindowMac::MacRepositionScrollBars()
2454 {
2455 bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
2456 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ;
2457
2458 // get real client area
2459
2460 int width ;
2461 int height ;
2462 GetSize( &width , &height ) ;
2463
2464 width -= MacGetLeftBorderSize() + MacGetRightBorderSize();
2465 height -= MacGetTopBorderSize() + MacGetBottomBorderSize();
2466
2467 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
2468 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
2469 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
2470 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
2471
2472 int x = 0 ;
2473 int y = 0 ;
2474 int w ;
2475 int h ;
2476 GetSize( &w , &h ) ;
2477
2478 MacClientToRootWindow( &x , &y ) ;
2479 MacClientToRootWindow( &w , &h ) ;
2480
2481 wxWindowMac *iter = (wxWindowMac*)this ;
2482
2483 int totW = 10000 , totH = 10000;
2484 while( iter )
2485 {
2486 if ( iter->IsTopLevel() )
2487 {
2488 iter->GetSize( &totW , &totH ) ;
2489 break ;
2490 }
2491
2492 iter = iter->GetParent() ;
2493 }
2494
2495 if ( x == 0 )
2496 {
2497 hPoint.x = -1 ;
2498 hSize.x += 1 ;
2499 }
2500 if ( y == 0 )
2501 {
2502 vPoint.y = -1 ;
2503 vSize.y += 1 ;
2504 }
2505
2506 if ( w-x >= totW )
2507 {
2508 hSize.x += 1 ;
2509 vPoint.x += 1 ;
2510 }
2511
2512 if ( h-y >= totH )
2513 {
2514 vSize.y += 1 ;
2515 hPoint.y += 1 ;
2516 }
2517
2518 if ( m_vScrollBar )
2519 {
2520 m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE);
2521 }
2522 if ( m_hScrollBar )
2523 {
2524 m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE);
2525 }
2526 }
2527
2528 bool wxWindowMac::AcceptsFocus() const
2529 {
2530 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2531 }
2532
2533 void wxWindowMac::MacSuperChangedPosition()
2534 {
2535 // only window-absolute structures have to be moved i.e. controls
2536
2537 wxWindowListNode *node = GetChildren().GetFirst();
2538 while ( node )
2539 {
2540 wxWindowMac *child = node->GetData();
2541 child->MacSuperChangedPosition() ;
2542 node = node->GetNext();
2543 }
2544 }
2545
2546 void wxWindowMac::MacTopLevelWindowChangedPosition()
2547 {
2548 // only screen-absolute structures have to be moved i.e. glcanvas
2549
2550 wxWindowListNode *node = GetChildren().GetFirst();
2551 while ( node )
2552 {
2553 wxWindowMac *child = node->GetData();
2554 child->MacTopLevelWindowChangedPosition() ;
2555 node = node->GetNext();
2556 }
2557 }
2558
2559 long wxWindowMac::MacGetLeftBorderSize( ) const
2560 {
2561 if( IsTopLevel() )
2562 return 0 ;
2563
2564 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
2565 {
2566 SInt32 border = 3 ;
2567 #if wxMAC_USE_THEME_BORDER
2568 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2569 #endif
2570 return border ;
2571 }
2572 else if ( m_windowStyle &wxDOUBLE_BORDER)
2573 {
2574 SInt32 border = 3 ;
2575 #if wxMAC_USE_THEME_BORDER
2576 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2577 #endif
2578 return border ;
2579 }
2580 else if (m_windowStyle &wxSIMPLE_BORDER)
2581 {
2582 return 1 ;
2583 }
2584 return 0 ;
2585 }
2586
2587 long wxWindowMac::MacGetRightBorderSize( ) const
2588 {
2589 // they are all symmetric in mac themes
2590 return MacGetLeftBorderSize() ;
2591 }
2592
2593 long wxWindowMac::MacGetTopBorderSize( ) const
2594 {
2595 // they are all symmetric in mac themes
2596 return MacGetLeftBorderSize() ;
2597 }
2598
2599 long wxWindowMac::MacGetBottomBorderSize( ) const
2600 {
2601 // they are all symmetric in mac themes
2602 return MacGetLeftBorderSize() ;
2603 }
2604
2605 long wxWindowMac::MacRemoveBordersFromStyle( long style )
2606 {
2607 return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ;
2608 }
2609
2610 // Find the wxWindowMac at the current mouse position, returning the mouse
2611 // position.
2612 wxWindowMac* wxFindWindowAtPointer(wxPoint& pt)
2613 {
2614 pt = wxGetMousePosition();
2615 wxWindowMac* found = wxFindWindowAtPoint(pt);
2616 return found;
2617 }
2618
2619 // Get the current mouse position.
2620 wxPoint wxGetMousePosition()
2621 {
2622 int x, y;
2623 wxGetMousePosition(& x, & y);
2624 return wxPoint(x, y);
2625 }
2626
2627 void wxWindowMac::OnMouseEvent( wxMouseEvent &event )
2628 {
2629 if ( event.GetEventType() == wxEVT_RIGHT_DOWN )
2630 {
2631 // copied from wxGTK : CS
2632 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2633 // except that:
2634 //
2635 // (a) it's a command event and so is propagated to the parent
2636 // (b) under MSW it can be generated from kbd too
2637 // (c) it uses screen coords (because of (a))
2638 wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU,
2639 this->GetId(),
2640 this->ClientToScreen(event.GetPosition()));
2641 if ( ! GetEventHandler()->ProcessEvent(evtCtx) )
2642 event.Skip() ;
2643 }
2644 else if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK )
2645 {
2646
2647 int x = event.m_x ;
2648 int y = event.m_y ;
2649
2650 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2651 {
2652 // OS Needs it in tlw content area coordinates
2653 MacClientToRootWindow( &x , &y ) ;
2654 }
2655 else
2656 {
2657 // OS Needs it in window not client coordinates
2658 wxPoint origin = GetClientAreaOrigin() ;
2659 x += origin.x ;
2660 y += origin.y ;
2661 }
2662 Point localwhere ;
2663 SInt16 controlpart ;
2664
2665 localwhere.h = x ;
2666 localwhere.v = y ;
2667
2668 short modifiers = 0;
2669
2670 if ( !event.m_leftDown && !event.m_rightDown )
2671 modifiers |= btnState ;
2672
2673 if ( event.m_shiftDown )
2674 modifiers |= shiftKey ;
2675
2676 if ( event.m_controlDown )
2677 modifiers |= controlKey ;
2678
2679 if ( event.m_altDown )
2680 modifiers |= optionKey ;
2681
2682 if ( event.m_metaDown )
2683 modifiers |= cmdKey ;
2684
2685 bool handled = false ;
2686
2687 if ( ::IsControlActive( (ControlRef) m_macControl ) )
2688 {
2689 controlpart = ::HandleControlClick( (ControlRef) m_macControl , localwhere , modifiers , (ControlActionUPP) -1 ) ;
2690 wxTheApp->s_lastMouseDown = 0 ;
2691 if ( controlpart != kControlNoPart )
2692 {
2693 MacHandleControlClick((WXWidget) (ControlRef) m_macControl , controlpart , false /* mouse not down anymore */ ) ;
2694 handled = true ;
2695 }
2696 }
2697 if ( !handled )
2698 event.Skip() ;
2699 }
2700 else
2701 {
2702 event.Skip() ;
2703 }
2704 }
2705
2706 void wxWindowMac::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) )
2707 {
2708 wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ;
2709 }
2710
2711 Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size )
2712 {
2713 int x ,y , w ,h ;
2714
2715 window->MacGetBoundsForControl( pos , size , x , y, w, h ) ;
2716 Rect bounds = { y , x , y+h , x+w };
2717 return bounds ;
2718 }
2719
2720