]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/window.cpp
applied patch 923858 (fixes crash in zlib streams)
[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 if ( m_macIsUserPane || IsTopLevel() )
1377 return wxWindowBase::DoGetBestSize() ;
1378
1379 Rect bestsize = { 0 , 0 , 0 , 0 } ;
1380 short baselineoffset ;
1381 int bestWidth, bestHeight ;
1382 ::GetBestControlRect( (ControlRef) m_macControl , &bestsize , &baselineoffset ) ;
1383
1384 if ( EmptyRect( &bestsize ) )
1385 {
1386 baselineoffset = 0;
1387 bestsize.left = bestsize.top = 0 ;
1388 bestsize.right = 16 ;
1389 bestsize.bottom = 16 ;
1390 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
1391 {
1392 bestsize.bottom = 16 ;
1393 }
1394 else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
1395 {
1396 bestsize.bottom = 24 ;
1397 }
1398 else
1399 {
1400 // return wxWindowBase::DoGetBestSize() ;
1401 }
1402 }
1403
1404 bestWidth = bestsize.right - bestsize.left ;
1405 bestHeight = bestsize.bottom - bestsize.top ;
1406 if ( bestHeight < 10 )
1407 bestHeight = 13 ;
1408
1409 return wxSize(bestWidth, bestHeight);
1410 // return wxWindowBase::DoGetBestSize() ;
1411 }
1412
1413
1414 // set the size of the window: if the dimensions are positive, just use them,
1415 // but if any of them is equal to -1, it means that we must find the value for
1416 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1417 // which case -1 is a valid value for x and y)
1418 //
1419 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1420 // the width/height to best suit our contents, otherwise we reuse the current
1421 // width/height
1422 void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags)
1423 {
1424 // get the current size and position...
1425 int currentX, currentY;
1426 GetPosition(&currentX, &currentY);
1427
1428 int currentW,currentH;
1429 GetSize(&currentW, &currentH);
1430
1431 // ... and don't do anything (avoiding flicker) if it's already ok
1432 if ( x == currentX && y == currentY &&
1433 width == currentW && height == currentH && ( height != -1 && width != -1 ) )
1434 {
1435 // TODO REMOVE
1436 MacRepositionScrollBars() ; // we might have a real position shift
1437 return;
1438 }
1439
1440 if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
1441 x = currentX;
1442 if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
1443 y = currentY;
1444
1445 AdjustForParentClientOrigin(x, y, sizeFlags);
1446
1447 wxSize size(-1, -1);
1448 if ( width == -1 )
1449 {
1450 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
1451 {
1452 size = DoGetBestSize();
1453 width = size.x;
1454 }
1455 else
1456 {
1457 // just take the current one
1458 width = currentW;
1459 }
1460 }
1461
1462 if ( height == -1 )
1463 {
1464 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
1465 {
1466 if ( size.x == -1 )
1467 {
1468 size = DoGetBestSize();
1469 }
1470 //else: already called DoGetBestSize() above
1471
1472 height = size.y;
1473 }
1474 else
1475 {
1476 // just take the current one
1477 height = currentH;
1478 }
1479 }
1480
1481 DoMoveWindow(x, y, width, height);
1482
1483 }
1484
1485 wxPoint wxWindowMac::GetClientAreaOrigin() const
1486 {
1487 RgnHandle rgn = NewRgn() ;
1488 Rect content ;
1489 GetControlRegion( (ControlRef) m_macControl , kControlContentMetaPart , rgn ) ;
1490 GetRegionBounds( rgn , &content ) ;
1491 DisposeRgn( rgn ) ;
1492 #if !TARGET_API_MAC_OSX
1493 Rect structure ;
1494 GetControlBounds( (ControlRef) m_macControl , &structure ) ;
1495 OffsetRect( &content , -structure.left , -structure.top ) ;
1496 #endif
1497
1498 return wxPoint( content.left + MacGetLeftBorderSize( ) , content.top + MacGetTopBorderSize( ) );
1499 }
1500
1501 void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight)
1502 {
1503 if ( clientheight != -1 || clientheight != -1 )
1504 {
1505 int currentclientwidth , currentclientheight ;
1506 int currentwidth , currentheight ;
1507
1508 GetClientSize( &currentclientwidth , &currentclientheight ) ;
1509 GetSize( &currentwidth , &currentheight ) ;
1510
1511 DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth ,
1512 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
1513 }
1514 }
1515
1516 void wxWindowMac::SetTitle(const wxString& title)
1517 {
1518 m_label = wxStripMenuCodes(title) ;
1519
1520 if ( m_macControl )
1521 {
1522 UMASetControlTitle( (ControlRef) m_macControl , m_label , m_font.GetEncoding() ) ;
1523 }
1524 Refresh() ;
1525 }
1526
1527 wxString wxWindowMac::GetTitle() const
1528 {
1529 return m_label ;
1530 }
1531
1532 bool wxWindowMac::Show(bool show)
1533 {
1534 if ( !wxWindowBase::Show(show) )
1535 return FALSE;
1536
1537 // TODO use visibilityChanged Carbon Event for OSX
1538 bool former = MacIsReallyShown() ;
1539
1540 SetControlVisibility( (ControlRef) m_macControl , show , true ) ;
1541 if ( former != MacIsReallyShown() )
1542 MacPropagateVisibilityChanged() ;
1543 return TRUE;
1544 }
1545
1546 bool wxWindowMac::Enable(bool enable)
1547 {
1548 wxASSERT( m_macControl != NULL ) ;
1549 if ( !wxWindowBase::Enable(enable) )
1550 return FALSE;
1551
1552 bool former = MacIsReallyEnabled() ;
1553 if ( enable )
1554 EnableControl( (ControlRef) m_macControl ) ;
1555 else
1556 DisableControl( (ControlRef) m_macControl ) ;
1557
1558 if ( former != MacIsReallyEnabled() )
1559 MacPropagateEnabledStateChanged() ;
1560 return TRUE;
1561 }
1562
1563 //
1564 // status change propagations (will be not necessary for OSX later )
1565 //
1566
1567 void wxWindowMac::MacPropagateVisibilityChanged()
1568 {
1569 #if !TARGET_API_MAC_OSX
1570 MacVisibilityChanged() ;
1571
1572 wxWindowListNode *node = GetChildren().GetFirst();
1573 while ( node )
1574 {
1575 wxWindowMac *child = node->GetData();
1576 if ( child->IsShown() )
1577 child->MacPropagateVisibilityChanged( ) ;
1578 node = node->GetNext();
1579 }
1580 #endif
1581 }
1582
1583 void wxWindowMac::MacPropagateEnabledStateChanged( )
1584 {
1585 #if !TARGET_API_MAC_OSX
1586 MacEnabledStateChanged() ;
1587
1588 wxWindowListNode *node = GetChildren().GetFirst();
1589 while ( node )
1590 {
1591 wxWindowMac *child = node->GetData();
1592 if ( child->IsEnabled() )
1593 child->MacPropagateEnabledStateChanged() ;
1594 node = node->GetNext();
1595 }
1596 #endif
1597 }
1598
1599 void wxWindowMac::MacPropagateHiliteChanged( )
1600 {
1601 #if !TARGET_API_MAC_OSX
1602 MacHiliteChanged() ;
1603
1604 wxWindowListNode *node = GetChildren().GetFirst();
1605 while ( node )
1606 {
1607 wxWindowMac *child = node->GetData();
1608 // if ( child->IsEnabled() )
1609 child->MacPropagateHiliteChanged() ;
1610 node = node->GetNext();
1611 }
1612 #endif
1613 }
1614
1615 //
1616 // status change notifications
1617 //
1618
1619 void wxWindowMac::MacVisibilityChanged()
1620 {
1621 }
1622
1623 void wxWindowMac::MacHiliteChanged()
1624 {
1625 }
1626
1627 void wxWindowMac::MacEnabledStateChanged()
1628 {
1629 }
1630
1631 //
1632 // status queries on the inherited window's state
1633 //
1634
1635 bool wxWindowMac::MacIsReallyShown()
1636 {
1637 // only under OSX the visibility of the TLW is taken into account
1638 #if TARGET_API_MAC_OSX
1639 return IsControlVisible( (ControlRef) m_macControl ) ;
1640 #else
1641 wxWindow* win = this ;
1642 while( win->IsShown() )
1643 {
1644 if ( win->IsTopLevel() )
1645 return true ;
1646
1647 win = win->GetParent() ;
1648 if ( win == NULL )
1649 return true ;
1650
1651 } ;
1652 return false ;
1653 #endif
1654 }
1655
1656 bool wxWindowMac::MacIsReallyEnabled()
1657 {
1658 return IsControlEnabled( (ControlRef) m_macControl ) ;
1659 }
1660
1661 bool wxWindowMac::MacIsReallyHilited()
1662 {
1663 return IsControlActive( (ControlRef) m_macControl ) ;
1664 }
1665
1666 //
1667 //
1668 //
1669
1670 int wxWindowMac::GetCharHeight() const
1671 {
1672 wxClientDC dc ( (wxWindowMac*)this ) ;
1673 return dc.GetCharHeight() ;
1674 }
1675
1676 int wxWindowMac::GetCharWidth() const
1677 {
1678 wxClientDC dc ( (wxWindowMac*)this ) ;
1679 return dc.GetCharWidth() ;
1680 }
1681
1682 void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y,
1683 int *descent, int *externalLeading, const wxFont *theFont ) const
1684 {
1685 const wxFont *fontToUse = theFont;
1686 if ( !fontToUse )
1687 fontToUse = &m_font;
1688
1689 wxClientDC dc( (wxWindowMac*) this ) ;
1690 long lx,ly,ld,le ;
1691 dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ;
1692 if ( externalLeading )
1693 *externalLeading = le ;
1694 if ( descent )
1695 *descent = ld ;
1696 if ( x )
1697 *x = lx ;
1698 if ( y )
1699 *y = ly ;
1700 }
1701
1702 /*
1703 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1704 * we always intersect with the entire window, not only with the client area
1705 */
1706
1707 void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect)
1708 {
1709 #if TARGET_API_MAC_OSX
1710 if ( rect == NULL )
1711 HIViewSetNeedsDisplay( (ControlRef) m_macControl , true ) ;
1712 else
1713 {
1714 RgnHandle update = NewRgn() ;
1715 SetRectRgn( update , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1716 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , update , update ) ;
1717 HIViewSetNeedsDisplayInRegion( (ControlRef) m_macControl , update , true ) ;
1718 }
1719 #else
1720 if ( IsControlVisible( (ControlRef) m_macControl ) )
1721 {
1722 SetControlVisibility( (ControlRef) m_macControl , false , false ) ;
1723 SetControlVisibility( (ControlRef) m_macControl , true , true ) ;
1724 }
1725 /*
1726 if ( MacGetTopLevelWindow() == NULL )
1727 return ;
1728
1729 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1730 return ;
1731
1732 wxPoint client = GetClientAreaOrigin();
1733 int x1 = -client.x;
1734 int y1 = -client.y;
1735 int x2 = m_width - client.x;
1736 int y2 = m_height - client.y;
1737
1738 if (IsKindOf( CLASSINFO(wxButton)))
1739 {
1740 // buttons have an "aura"
1741 y1 -= 5;
1742 x1 -= 5;
1743 y2 += 5;
1744 x2 += 5;
1745 }
1746
1747 Rect clientrect = { y1, x1, y2, x2 };
1748
1749 if ( rect )
1750 {
1751 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1752 SectRect( &clientrect , &r , &clientrect ) ;
1753 }
1754
1755 if ( !EmptyRect( &clientrect ) )
1756 {
1757 int top = 0 , left = 0 ;
1758
1759 MacClientToRootWindow( &left , &top ) ;
1760 OffsetRect( &clientrect , left , top ) ;
1761
1762 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1763 }
1764 */
1765 #endif
1766 }
1767
1768 void wxWindowMac::MacRedrawControl()
1769 {
1770 /*
1771 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
1772 {
1773 #if TARGET_API_MAC_CARBON
1774 Update() ;
1775 #else
1776 wxClientDC dc(this) ;
1777 wxMacPortSetter helper(&dc) ;
1778 wxMacWindowClipper clipper(this) ;
1779 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
1780 UMADrawControl( (ControlRef) m_macControl ) ;
1781 #endif
1782 }
1783 */
1784 }
1785
1786 /* TODO
1787 void wxWindowMac::OnPaint(wxPaintEvent& event)
1788 {
1789 // why don't we skip that here ?
1790 }
1791 */
1792
1793 wxWindowMac *wxGetActiveWindow()
1794 {
1795 // actually this is a windows-only concept
1796 return NULL;
1797 }
1798
1799 // Coordinates relative to the window
1800 void wxWindowMac::WarpPointer (int x_pos, int y_pos)
1801 {
1802 // We really don't move the mouse programmatically under Mac.
1803 }
1804
1805 void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
1806 {
1807 if ( m_macBackgroundBrush.Ok() == false || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT )
1808 {
1809 event.Skip() ;
1810 }
1811 else
1812 event.GetDC()->Clear() ;
1813 }
1814
1815 void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
1816 {
1817 wxWindowDC dc(this) ;
1818 wxMacPortSetter helper(&dc) ;
1819
1820 MacPaintBorders( dc.m_macLocalOrigin.x , dc.m_macLocalOrigin.y) ;
1821 }
1822
1823 int wxWindowMac::GetScrollPos(int orient) const
1824 {
1825 if ( orient == wxHORIZONTAL )
1826 {
1827 if ( m_hScrollBar )
1828 return m_hScrollBar->GetThumbPosition() ;
1829 }
1830 else
1831 {
1832 if ( m_vScrollBar )
1833 return m_vScrollBar->GetThumbPosition() ;
1834 }
1835 return 0;
1836 }
1837
1838 // This now returns the whole range, not just the number
1839 // of positions that we can scroll.
1840 int wxWindowMac::GetScrollRange(int orient) const
1841 {
1842 if ( orient == wxHORIZONTAL )
1843 {
1844 if ( m_hScrollBar )
1845 return m_hScrollBar->GetRange() ;
1846 }
1847 else
1848 {
1849 if ( m_vScrollBar )
1850 return m_vScrollBar->GetRange() ;
1851 }
1852 return 0;
1853 }
1854
1855 int wxWindowMac::GetScrollThumb(int orient) const
1856 {
1857 if ( orient == wxHORIZONTAL )
1858 {
1859 if ( m_hScrollBar )
1860 return m_hScrollBar->GetThumbSize() ;
1861 }
1862 else
1863 {
1864 if ( m_vScrollBar )
1865 return m_vScrollBar->GetThumbSize() ;
1866 }
1867 return 0;
1868 }
1869
1870 void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh)
1871 {
1872 if ( orient == wxHORIZONTAL )
1873 {
1874 if ( m_hScrollBar )
1875 m_hScrollBar->SetThumbPosition( pos ) ;
1876 }
1877 else
1878 {
1879 if ( m_vScrollBar )
1880 m_vScrollBar->SetThumbPosition( pos ) ;
1881 }
1882 }
1883
1884 void wxWindowMac::MacPaintBorders( int left , int top )
1885 {
1886 if( IsTopLevel() )
1887 return ;
1888
1889 int major,minor;
1890 wxGetOsVersion( &major, &minor );
1891
1892 RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ;
1893 RGBColor face = { 0xDDDD, 0xDDDD , 0xDDDD } ;
1894
1895 RGBColor darkShadow = { 0x0000, 0x0000 , 0x0000 } ;
1896 RGBColor lightShadow = { 0x4444, 0x4444 , 0x4444 } ;
1897 // OS X has lighter border edges than classic:
1898 if (major >= 10)
1899 {
1900 darkShadow.red = 0x8E8E;
1901 darkShadow.green = 0x8E8E;
1902 darkShadow.blue = 0x8E8E;
1903 lightShadow.red = 0xBDBD;
1904 lightShadow.green = 0xBDBD;
1905 lightShadow.blue = 0xBDBD;
1906 }
1907
1908 PenNormal() ;
1909
1910 int w , h ;
1911 GetSize( &w , &h ) ;
1912 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
1913 {
1914 #if wxMAC_USE_THEME_BORDER
1915 Rect rect = { top , left , m_height + top , m_width + left } ;
1916 SInt32 border = 0 ;
1917 /*
1918 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1919 InsetRect( &rect , border , border );
1920 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1921 */
1922
1923 DrawThemePrimaryGroup(&rect ,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1924 #else
1925 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1926 RGBForeColor( &face );
1927 MoveTo( left + 0 , top + h - 2 );
1928 LineTo( left + 0 , top + 0 );
1929 LineTo( left + w - 2 , top + 0 );
1930
1931 MoveTo( left + 2 , top + h - 3 );
1932 LineTo( left + w - 3 , top + h - 3 );
1933 LineTo( left + w - 3 , top + 2 );
1934
1935 RGBForeColor( sunken ? &face : &darkShadow );
1936 MoveTo( left + 0 , top + h - 1 );
1937 LineTo( left + w - 1 , top + h - 1 );
1938 LineTo( left + w - 1 , top + 0 );
1939
1940 RGBForeColor( sunken ? &lightShadow : &white );
1941 MoveTo( left + 1 , top + h - 3 );
1942 LineTo( left + 1, top + 1 );
1943 LineTo( left + w - 3 , top + 1 );
1944
1945 RGBForeColor( sunken ? &white : &lightShadow );
1946 MoveTo( left + 1 , top + h - 2 );
1947 LineTo( left + w - 2 , top + h - 2 );
1948 LineTo( left + w - 2 , top + 1 );
1949
1950 RGBForeColor( sunken ? &darkShadow : &face );
1951 MoveTo( left + 2 , top + h - 4 );
1952 LineTo( left + 2 , top + 2 );
1953 LineTo( left + w - 4 , top + 2 );
1954 #endif
1955 }
1956 else if (HasFlag(wxSIMPLE_BORDER))
1957 {
1958 Rect rect = { top , left , h + top , w + left } ;
1959 RGBForeColor( &darkShadow ) ;
1960 FrameRect( &rect ) ;
1961 }
1962 }
1963
1964 void wxWindowMac::RemoveChild( wxWindowBase *child )
1965 {
1966 if ( child == m_hScrollBar )
1967 m_hScrollBar = NULL ;
1968 if ( child == m_vScrollBar )
1969 m_vScrollBar = NULL ;
1970
1971 wxWindowBase::RemoveChild( child ) ;
1972 }
1973
1974 // New function that will replace some of the above.
1975 void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible,
1976 int range, bool refresh)
1977 {
1978 if ( orient == wxHORIZONTAL )
1979 {
1980 if ( m_hScrollBar )
1981 {
1982 if ( range == 0 || thumbVisible >= range )
1983 {
1984 if ( m_hScrollBar->IsShown() )
1985 m_hScrollBar->Show(false) ;
1986 }
1987 else
1988 {
1989 if ( !m_hScrollBar->IsShown() )
1990 m_hScrollBar->Show(true) ;
1991 m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
1992 }
1993 }
1994 }
1995 else
1996 {
1997 if ( m_vScrollBar )
1998 {
1999 if ( range == 0 || thumbVisible >= range )
2000 {
2001 if ( m_vScrollBar->IsShown() )
2002 m_vScrollBar->Show(false) ;
2003 }
2004 else
2005 {
2006 if ( !m_vScrollBar->IsShown() )
2007 m_vScrollBar->Show(true) ;
2008 m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
2009 }
2010 }
2011 }
2012 MacRepositionScrollBars() ;
2013 }
2014
2015 // Does a physical scroll
2016 void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
2017 {
2018 if( dx == 0 && dy ==0 )
2019 return ;
2020
2021
2022 {
2023 wxClientDC dc(this) ;
2024 wxMacPortSetter helper(&dc) ;
2025
2026 int width , height ;
2027 GetClientSize( &width , &height ) ;
2028
2029
2030 wxPoint pos;
2031 pos.x = pos.y = 0;
2032
2033 Rect scrollrect;
2034 // TODO take out the boundaries
2035 GetControlBounds( (ControlRef) m_macControl, &scrollrect);
2036
2037 RgnHandle updateRgn = NewRgn() ;
2038 if ( rect )
2039 {
2040 Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) ,
2041 dc.XLOG2DEVMAC(rect->x + rect->width) } ;
2042 SectRect( &scrollrect , &r , &scrollrect ) ;
2043 }
2044 ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
2045 #if TARGET_CARBON
2046 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
2047 // but it seems the update only refreshes the background of the control, rather than calling
2048 // kEventControlDraw, so we need to force a proper update here. There has to be a better
2049 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
2050 Update();
2051 #endif
2052 // we also have to scroll the update rgn in this rectangle
2053 // in order not to loose updates
2054 #if !TARGET_CARBON
2055 WindowRef rootWindow = (WindowRef) MacGetTopLevelWindowRef() ;
2056 RgnHandle formerUpdateRgn = NewRgn() ;
2057 RgnHandle scrollRgn = NewRgn() ;
2058 RectRgn( scrollRgn , &scrollrect ) ;
2059 GetWindowUpdateRgn( rootWindow , formerUpdateRgn ) ;
2060 Point pt = {0,0} ;
2061 LocalToGlobal( &pt ) ;
2062 OffsetRgn( formerUpdateRgn , -pt.h , -pt.v ) ;
2063 SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
2064 if ( !EmptyRgn( formerUpdateRgn ) )
2065 {
2066 MacOffsetRgn( formerUpdateRgn , dx , dy ) ;
2067 SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
2068 InvalWindowRgn(rootWindow , formerUpdateRgn ) ;
2069 }
2070 InvalWindowRgn(rootWindow , updateRgn ) ;
2071 DisposeRgn( updateRgn ) ;
2072 DisposeRgn( formerUpdateRgn ) ;
2073 DisposeRgn( scrollRgn ) ;
2074 #endif
2075 }
2076
2077 for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())
2078 {
2079 wxWindowMac *child = node->GetData();
2080 if (child == m_vScrollBar) continue;
2081 if (child == m_hScrollBar) continue;
2082 if (child->IsTopLevel()) continue;
2083
2084 int x,y;
2085 child->GetPosition( &x, &y );
2086 int w,h;
2087 child->GetSize( &w, &h );
2088 if (rect)
2089 {
2090 wxRect rc(x,y,w,h);
2091 if (rect->Intersects(rc))
2092 child->SetSize( x+dx, y+dy, w, h );
2093 }
2094 else
2095 {
2096 child->SetSize( x+dx, y+dy, w, h );
2097 }
2098 }
2099
2100 // TODO remove, was moved higher up Update() ;
2101
2102 }
2103
2104 void wxWindowMac::MacOnScroll(wxScrollEvent &event )
2105 {
2106 if ( event.m_eventObject == m_vScrollBar || event.m_eventObject == m_hScrollBar )
2107 {
2108 wxScrollWinEvent wevent;
2109 wevent.SetPosition(event.GetPosition());
2110 wevent.SetOrientation(event.GetOrientation());
2111 wevent.m_eventObject = this;
2112
2113 if (event.m_eventType == wxEVT_SCROLL_TOP)
2114 wevent.m_eventType = wxEVT_SCROLLWIN_TOP;
2115 else if (event.m_eventType == wxEVT_SCROLL_BOTTOM)
2116 wevent.m_eventType = wxEVT_SCROLLWIN_BOTTOM;
2117 else if (event.m_eventType == wxEVT_SCROLL_LINEUP)
2118 wevent.m_eventType = wxEVT_SCROLLWIN_LINEUP;
2119 else if (event.m_eventType == wxEVT_SCROLL_LINEDOWN)
2120 wevent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
2121 else if (event.m_eventType == wxEVT_SCROLL_PAGEUP)
2122 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEUP;
2123 else if (event.m_eventType == wxEVT_SCROLL_PAGEDOWN)
2124 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
2125 else if (event.m_eventType == wxEVT_SCROLL_THUMBTRACK)
2126 wevent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
2127 else if (event.m_eventType == wxEVT_SCROLL_THUMBRELEASE)
2128 wevent.m_eventType = wxEVT_SCROLLWIN_THUMBRELEASE;
2129
2130 GetEventHandler()->ProcessEvent(wevent);
2131 }
2132 }
2133
2134 // Get the window with the focus
2135 wxWindowMac *wxWindowBase::FindFocus()
2136 {
2137 return gFocusWindow ;
2138 }
2139
2140 void wxWindowMac::OnSetFocus(wxFocusEvent& event)
2141 {
2142 // panel wants to track the window which was the last to have focus in it,
2143 // so we want to set ourselves as the window which last had focus
2144 //
2145 // notice that it's also important to do it upwards the tree becaus
2146 // otherwise when the top level panel gets focus, it won't set it back to
2147 // us, but to some other sibling
2148
2149 // CS:don't know if this is still needed:
2150 //wxChildFocusEvent eventFocus(this);
2151 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2152
2153 event.Skip();
2154 }
2155
2156 void wxWindowMac::OnInternalIdle()
2157 {
2158 // This calls the UI-update mechanism (querying windows for
2159 // menu/toolbar/control state information)
2160 if (wxUpdateUIEvent::CanUpdate(this))
2161 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
2162 }
2163
2164 // Raise the window to the top of the Z order
2165 void wxWindowMac::Raise()
2166 {
2167 }
2168
2169 // Lower the window to the bottom of the Z order
2170 void wxWindowMac::Lower()
2171 {
2172 }
2173
2174
2175 // static wxWindow *gs_lastWhich = NULL;
2176
2177 bool wxWindowMac::MacSetupCursor( const wxPoint& pt)
2178 {
2179 // first trigger a set cursor event
2180
2181 wxPoint clientorigin = GetClientAreaOrigin() ;
2182 wxSize clientsize = GetClientSize() ;
2183 wxCursor cursor ;
2184 if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) )
2185 {
2186 wxSetCursorEvent event( pt.x , pt.y );
2187
2188 bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event);
2189 if ( processedEvtSetCursor && event.HasCursor() )
2190 {
2191 cursor = event.GetCursor() ;
2192 }
2193 else
2194 {
2195
2196 // the test for processedEvtSetCursor is here to prevent using m_cursor
2197 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2198 // it - this is a way to say that our cursor shouldn't be used for this
2199 // point
2200 if ( !processedEvtSetCursor && m_cursor.Ok() )
2201 {
2202 cursor = m_cursor ;
2203 }
2204 if ( wxIsBusy() )
2205 {
2206 }
2207 else
2208 {
2209 if ( !GetParent() )
2210 cursor = *wxSTANDARD_CURSOR ;
2211 }
2212 }
2213 if ( cursor.Ok() )
2214 cursor.MacInstall() ;
2215 }
2216 return cursor.Ok() ;
2217 }
2218
2219 wxString wxWindowMac::MacGetToolTipString( wxPoint &pt )
2220 {
2221 if ( m_tooltip )
2222 {
2223 return m_tooltip->GetTip() ;
2224 }
2225 return wxEmptyString ;
2226 }
2227
2228 void wxWindowMac::Update()
2229 {
2230 #if TARGET_API_MAC_OSX
2231 HIViewSetNeedsDisplay( (ControlRef) m_macControl , true ) ;
2232 #else
2233 ::Draw1Control( (ControlRef) m_macControl ) ;
2234 #endif
2235 }
2236
2237 wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const
2238 {
2239 wxTopLevelWindowMac* win = NULL ;
2240 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
2241 if ( window )
2242 {
2243 win = wxFindWinFromMacWindow( window ) ;
2244 }
2245 return win ;
2246 }
2247 wxRegion wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures )
2248 {
2249
2250 Rect r ;
2251 RgnHandle visRgn = NewRgn() ;
2252 RgnHandle tempRgn = NewRgn() ;
2253 if ( IsControlVisible( (ControlRef) m_macControl ) )
2254 {
2255 GetControlBounds( (ControlRef) m_macControl , &r ) ;
2256 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2257 {
2258 MacRootWindowToWindow( &r.left , & r.top ) ;
2259 MacRootWindowToWindow( &r.right , & r.bottom ) ;
2260 }
2261 else
2262 {
2263 r.right -= r.left ;
2264 r.bottom -= r.top ;
2265 r.left = 0 ;
2266 r.top = 0 ;
2267 }
2268 if ( includeOuterStructures )
2269 InsetRect( &r , -3 , -3 ) ;
2270 RectRgn( visRgn , &r ) ;
2271 if ( !IsTopLevel() )
2272 {
2273 wxWindow* child = this ;
2274 wxWindow* parent = child->GetParent() ;
2275 while( parent )
2276 {
2277 int x , y ;
2278 wxSize size ;
2279 // we have to find a better clipping algorithm here, in order not to clip things
2280 // positioned like status and toolbar
2281 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2282 {
2283 size = parent->GetSize() ;
2284 x = y = 0 ;
2285 }
2286 else
2287 {
2288 size = parent->GetClientSize() ;
2289 wxPoint origin = parent->GetClientAreaOrigin() ;
2290 x = origin.x ;
2291 y = origin.y ;
2292 }
2293 parent->MacWindowToRootWindow( &x, &y ) ;
2294 MacRootWindowToWindow( &x , &y ) ;
2295
2296 SetRectRgn( tempRgn ,
2297 x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() ,
2298 x + size.x - parent->MacGetRightBorderSize(),
2299 y + size.y - parent->MacGetBottomBorderSize()) ;
2300
2301 SectRgn( visRgn , tempRgn , visRgn ) ;
2302 if ( parent->IsTopLevel() )
2303 break ;
2304 child = parent ;
2305 parent = child->GetParent() ;
2306 }
2307 }
2308 }
2309
2310 wxRegion vis = visRgn ;
2311 DisposeRgn( visRgn ) ;
2312 DisposeRgn( tempRgn ) ;
2313 return vis ;
2314 }
2315
2316 /*
2317 This function must not change the updatergn !
2318 */
2319 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time )
2320 {
2321 // we let the OS handle root control redraws
2322 if ( m_macControl == MacGetTopLevelWindow()->GetHandle() )
2323 return false ;
2324
2325 RgnHandle updatergn = (RgnHandle) updatergnr ;
2326 bool handled = false ;
2327
2328 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2329 {
2330 RgnHandle newupdate = NewRgn() ;
2331 wxSize point = GetClientSize() ;
2332 wxPoint origin = GetClientAreaOrigin() ;
2333 SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ;
2334 SectRgn( newupdate , updatergn , newupdate ) ;
2335 OffsetRgn( newupdate , -origin.x , -origin.y ) ;
2336 m_updateRegion = newupdate ;
2337 DisposeRgn( newupdate ) ;
2338 }
2339
2340 if ( !EmptyRgn(updatergn) )
2341 {
2342 wxWindowDC dc(this);
2343 if (!EmptyRgn(updatergn))
2344 dc.SetClippingRegion(wxRegion(updatergn));
2345
2346 wxEraseEvent eevent( GetId(), &dc );
2347 eevent.SetEventObject( this );
2348 GetEventHandler()->ProcessEvent( eevent );
2349
2350 if ( !m_updateRegion.Empty() )
2351 {
2352 // paint the window itself
2353 wxPaintEvent event;
2354 event.m_timeStamp = time ;
2355 event.SetEventObject(this);
2356 handled = GetEventHandler()->ProcessEvent(event);
2357
2358 // paint custom borders
2359 wxNcPaintEvent eventNc( GetId() );
2360 eventNc.SetEventObject( this );
2361 GetEventHandler()->ProcessEvent( eventNc );
2362 }
2363 }
2364 return handled ;
2365 }
2366
2367 void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase)
2368 {
2369 RgnHandle updatergn = (RgnHandle) updatergnr ;
2370 // updatergn is always already clipped to our boundaries
2371 // if we are in compositing mode then it is in relative to the upper left of the control
2372 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2373 // of the toplevel window
2374 // it is in window coordinates, not in client coordinates
2375
2376 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2377 RgnHandle ownUpdateRgn = NewRgn() ;
2378 CopyRgn( updatergn , ownUpdateRgn ) ;
2379
2380 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2381 {
2382 Rect bounds;
2383 UMAGetControlBoundsInWindowCoords( (ControlRef)m_macControl, &bounds );
2384 RgnHandle controlRgn = NewRgn();
2385 RectRgn( controlRgn, &bounds );
2386 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2387 // the window update region
2388 SectRgn( ownUpdateRgn, controlRgn, ownUpdateRgn );
2389 DisposeRgn( controlRgn );
2390
2391 //KO: convert ownUpdateRgn to local coordinates
2392 OffsetRgn( ownUpdateRgn, -bounds.left, -bounds.top );
2393 }
2394
2395 MacDoRedraw( ownUpdateRgn , time ) ;
2396 DisposeRgn( ownUpdateRgn ) ;
2397
2398 }
2399
2400 WXWindow wxWindowMac::MacGetTopLevelWindowRef() const
2401 {
2402 wxWindowMac *iter = (wxWindowMac*)this ;
2403
2404 while( iter )
2405 {
2406 if ( iter->IsTopLevel() )
2407 return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ;
2408
2409 iter = iter->GetParent() ;
2410 }
2411 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2412 return NULL ;
2413 }
2414
2415 void wxWindowMac::MacCreateScrollBars( long style )
2416 {
2417 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ;
2418
2419 bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
2420 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ;
2421 int width, height ;
2422 GetClientSize( &width , &height ) ;
2423
2424 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
2425 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
2426 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
2427 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
2428
2429 m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint,
2430 vSize , wxVERTICAL);
2431
2432 if ( style & wxVSCROLL )
2433 {
2434
2435 }
2436 else
2437 {
2438 m_vScrollBar->Show(false) ;
2439 }
2440 m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint,
2441 hSize , wxHORIZONTAL);
2442 if ( style & wxHSCROLL )
2443 {
2444 }
2445 else
2446 {
2447 m_hScrollBar->Show(false) ;
2448 }
2449
2450 // because the create does not take into account the client area origin
2451 MacRepositionScrollBars() ; // we might have a real position shift
2452 }
2453
2454 void wxWindowMac::MacRepositionScrollBars()
2455 {
2456 bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
2457 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ;
2458
2459 // get real client area
2460
2461 int width ;
2462 int height ;
2463 GetSize( &width , &height ) ;
2464
2465 width -= MacGetLeftBorderSize() + MacGetRightBorderSize();
2466 height -= MacGetTopBorderSize() + MacGetBottomBorderSize();
2467
2468 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
2469 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
2470 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
2471 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
2472
2473 int x = 0 ;
2474 int y = 0 ;
2475 int w ;
2476 int h ;
2477 GetSize( &w , &h ) ;
2478
2479 MacClientToRootWindow( &x , &y ) ;
2480 MacClientToRootWindow( &w , &h ) ;
2481
2482 wxWindowMac *iter = (wxWindowMac*)this ;
2483
2484 int totW = 10000 , totH = 10000;
2485 while( iter )
2486 {
2487 if ( iter->IsTopLevel() )
2488 {
2489 iter->GetSize( &totW , &totH ) ;
2490 break ;
2491 }
2492
2493 iter = iter->GetParent() ;
2494 }
2495
2496 if ( x == 0 )
2497 {
2498 hPoint.x = -1 ;
2499 hSize.x += 1 ;
2500 }
2501 if ( y == 0 )
2502 {
2503 vPoint.y = -1 ;
2504 vSize.y += 1 ;
2505 }
2506
2507 if ( w-x >= totW )
2508 {
2509 hSize.x += 1 ;
2510 vPoint.x += 1 ;
2511 }
2512
2513 if ( h-y >= totH )
2514 {
2515 vSize.y += 1 ;
2516 hPoint.y += 1 ;
2517 }
2518
2519 if ( m_vScrollBar )
2520 {
2521 m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE);
2522 }
2523 if ( m_hScrollBar )
2524 {
2525 m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE);
2526 }
2527 }
2528
2529 bool wxWindowMac::AcceptsFocus() const
2530 {
2531 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2532 }
2533
2534 void wxWindowMac::MacSuperChangedPosition()
2535 {
2536 // only window-absolute structures have to be moved i.e. controls
2537
2538 wxWindowListNode *node = GetChildren().GetFirst();
2539 while ( node )
2540 {
2541 wxWindowMac *child = node->GetData();
2542 child->MacSuperChangedPosition() ;
2543 node = node->GetNext();
2544 }
2545 }
2546
2547 void wxWindowMac::MacTopLevelWindowChangedPosition()
2548 {
2549 // only screen-absolute structures have to be moved i.e. glcanvas
2550
2551 wxWindowListNode *node = GetChildren().GetFirst();
2552 while ( node )
2553 {
2554 wxWindowMac *child = node->GetData();
2555 child->MacTopLevelWindowChangedPosition() ;
2556 node = node->GetNext();
2557 }
2558 }
2559
2560 long wxWindowMac::MacGetLeftBorderSize( ) const
2561 {
2562 if( IsTopLevel() )
2563 return 0 ;
2564
2565 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
2566 {
2567 SInt32 border = 3 ;
2568 #if wxMAC_USE_THEME_BORDER
2569 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2570 #endif
2571 return border ;
2572 }
2573 else if ( m_windowStyle &wxDOUBLE_BORDER)
2574 {
2575 SInt32 border = 3 ;
2576 #if wxMAC_USE_THEME_BORDER
2577 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2578 #endif
2579 return border ;
2580 }
2581 else if (m_windowStyle &wxSIMPLE_BORDER)
2582 {
2583 return 1 ;
2584 }
2585 return 0 ;
2586 }
2587
2588 long wxWindowMac::MacGetRightBorderSize( ) const
2589 {
2590 // they are all symmetric in mac themes
2591 return MacGetLeftBorderSize() ;
2592 }
2593
2594 long wxWindowMac::MacGetTopBorderSize( ) const
2595 {
2596 // they are all symmetric in mac themes
2597 return MacGetLeftBorderSize() ;
2598 }
2599
2600 long wxWindowMac::MacGetBottomBorderSize( ) const
2601 {
2602 // they are all symmetric in mac themes
2603 return MacGetLeftBorderSize() ;
2604 }
2605
2606 long wxWindowMac::MacRemoveBordersFromStyle( long style )
2607 {
2608 return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ;
2609 }
2610
2611 // Find the wxWindowMac at the current mouse position, returning the mouse
2612 // position.
2613 wxWindowMac* wxFindWindowAtPointer(wxPoint& pt)
2614 {
2615 pt = wxGetMousePosition();
2616 wxWindowMac* found = wxFindWindowAtPoint(pt);
2617 return found;
2618 }
2619
2620 // Get the current mouse position.
2621 wxPoint wxGetMousePosition()
2622 {
2623 int x, y;
2624 wxGetMousePosition(& x, & y);
2625 return wxPoint(x, y);
2626 }
2627
2628 void wxWindowMac::OnMouseEvent( wxMouseEvent &event )
2629 {
2630 if ( event.GetEventType() == wxEVT_RIGHT_DOWN )
2631 {
2632 // copied from wxGTK : CS
2633 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2634 // except that:
2635 //
2636 // (a) it's a command event and so is propagated to the parent
2637 // (b) under MSW it can be generated from kbd too
2638 // (c) it uses screen coords (because of (a))
2639 wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU,
2640 this->GetId(),
2641 this->ClientToScreen(event.GetPosition()));
2642 if ( ! GetEventHandler()->ProcessEvent(evtCtx) )
2643 event.Skip() ;
2644 }
2645 else if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK )
2646 {
2647
2648 int x = event.m_x ;
2649 int y = event.m_y ;
2650
2651 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2652 {
2653 // OS Needs it in tlw content area coordinates
2654 MacClientToRootWindow( &x , &y ) ;
2655 }
2656 else
2657 {
2658 // OS Needs it in window not client coordinates
2659 wxPoint origin = GetClientAreaOrigin() ;
2660 x += origin.x ;
2661 y += origin.y ;
2662 }
2663 Point localwhere ;
2664 SInt16 controlpart ;
2665
2666 localwhere.h = x ;
2667 localwhere.v = y ;
2668
2669 short modifiers = 0;
2670
2671 if ( !event.m_leftDown && !event.m_rightDown )
2672 modifiers |= btnState ;
2673
2674 if ( event.m_shiftDown )
2675 modifiers |= shiftKey ;
2676
2677 if ( event.m_controlDown )
2678 modifiers |= controlKey ;
2679
2680 if ( event.m_altDown )
2681 modifiers |= optionKey ;
2682
2683 if ( event.m_metaDown )
2684 modifiers |= cmdKey ;
2685
2686 bool handled = false ;
2687
2688 if ( ::IsControlActive( (ControlRef) m_macControl ) )
2689 {
2690 controlpart = ::HandleControlClick( (ControlRef) m_macControl , localwhere , modifiers , (ControlActionUPP) -1 ) ;
2691 wxTheApp->s_lastMouseDown = 0 ;
2692 if ( controlpart != kControlNoPart )
2693 {
2694 MacHandleControlClick((WXWidget) (ControlRef) m_macControl , controlpart , false /* mouse not down anymore */ ) ;
2695 handled = true ;
2696 }
2697 }
2698 if ( !handled )
2699 event.Skip() ;
2700 }
2701 else
2702 {
2703 event.Skip() ;
2704 }
2705 }
2706
2707 void wxWindowMac::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) )
2708 {
2709 wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ;
2710 }
2711
2712 Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size )
2713 {
2714 int x ,y , w ,h ;
2715
2716 window->MacGetBoundsForControl( pos , size , x , y, w, h ) ;
2717 Rect bounds = { y , x , y+h , x+w };
2718 return bounds ;
2719 }
2720
2721