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