]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/window.cpp
Applied patch for Intel compiler.
[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 HIViewSetNeedsDisplayInRegion( (ControlRef) m_macControl , update , true ) ;
1746 }
1747 #else
1748 /*
1749 RgnHandle updateRgn = NewRgn() ;
1750 if ( rect == NULL )
1751 {
1752 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1753 }
1754 else
1755 {
1756 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1757 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1758 }
1759 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1760 DisposeRgn(updateRgn) ;
1761 */
1762 if ( IsControlVisible( (ControlRef) m_macControl ) )
1763 {
1764 SetControlVisibility( (ControlRef) m_macControl , false , false ) ;
1765 SetControlVisibility( (ControlRef) m_macControl , true , true ) ;
1766 }
1767 /*
1768 if ( MacGetTopLevelWindow() == NULL )
1769 return ;
1770
1771 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1772 return ;
1773
1774 wxPoint client = GetClientAreaOrigin();
1775 int x1 = -client.x;
1776 int y1 = -client.y;
1777 int x2 = m_width - client.x;
1778 int y2 = m_height - client.y;
1779
1780 if (IsKindOf( CLASSINFO(wxButton)))
1781 {
1782 // buttons have an "aura"
1783 y1 -= 5;
1784 x1 -= 5;
1785 y2 += 5;
1786 x2 += 5;
1787 }
1788
1789 Rect clientrect = { y1, x1, y2, x2 };
1790
1791 if ( rect )
1792 {
1793 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1794 SectRect( &clientrect , &r , &clientrect ) ;
1795 }
1796
1797 if ( !EmptyRect( &clientrect ) )
1798 {
1799 int top = 0 , left = 0 ;
1800
1801 MacClientToRootWindow( &left , &top ) ;
1802 OffsetRect( &clientrect , left , top ) ;
1803
1804 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1805 }
1806 */
1807 #endif
1808 }
1809
1810 void wxWindowMac::MacRedrawControl()
1811 {
1812 /*
1813 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
1814 {
1815 #if TARGET_API_MAC_CARBON
1816 Update() ;
1817 #else
1818 wxClientDC dc(this) ;
1819 wxMacPortSetter helper(&dc) ;
1820 wxMacWindowClipper clipper(this) ;
1821 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
1822 UMADrawControl( (ControlRef) m_macControl ) ;
1823 #endif
1824 }
1825 */
1826 }
1827
1828 /* TODO
1829 void wxWindowMac::OnPaint(wxPaintEvent& event)
1830 {
1831 // why don't we skip that here ?
1832 }
1833 */
1834
1835 wxWindowMac *wxGetActiveWindow()
1836 {
1837 // actually this is a windows-only concept
1838 return NULL;
1839 }
1840
1841 // Coordinates relative to the window
1842 void wxWindowMac::WarpPointer (int x_pos, int y_pos)
1843 {
1844 // We really don't move the mouse programmatically under Mac.
1845 }
1846
1847 void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
1848 {
1849 if ( m_macBackgroundBrush.Ok() == false || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT )
1850 {
1851 event.Skip() ;
1852 }
1853 else
1854 event.GetDC()->Clear() ;
1855 }
1856
1857 void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
1858 {
1859 wxWindowDC dc(this) ;
1860 wxMacPortSetter helper(&dc) ;
1861
1862 MacPaintBorders( dc.m_macLocalOrigin.x , dc.m_macLocalOrigin.y) ;
1863 }
1864
1865 int wxWindowMac::GetScrollPos(int orient) const
1866 {
1867 if ( orient == wxHORIZONTAL )
1868 {
1869 if ( m_hScrollBar )
1870 return m_hScrollBar->GetThumbPosition() ;
1871 }
1872 else
1873 {
1874 if ( m_vScrollBar )
1875 return m_vScrollBar->GetThumbPosition() ;
1876 }
1877 return 0;
1878 }
1879
1880 // This now returns the whole range, not just the number
1881 // of positions that we can scroll.
1882 int wxWindowMac::GetScrollRange(int orient) const
1883 {
1884 if ( orient == wxHORIZONTAL )
1885 {
1886 if ( m_hScrollBar )
1887 return m_hScrollBar->GetRange() ;
1888 }
1889 else
1890 {
1891 if ( m_vScrollBar )
1892 return m_vScrollBar->GetRange() ;
1893 }
1894 return 0;
1895 }
1896
1897 int wxWindowMac::GetScrollThumb(int orient) const
1898 {
1899 if ( orient == wxHORIZONTAL )
1900 {
1901 if ( m_hScrollBar )
1902 return m_hScrollBar->GetThumbSize() ;
1903 }
1904 else
1905 {
1906 if ( m_vScrollBar )
1907 return m_vScrollBar->GetThumbSize() ;
1908 }
1909 return 0;
1910 }
1911
1912 void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh)
1913 {
1914 if ( orient == wxHORIZONTAL )
1915 {
1916 if ( m_hScrollBar )
1917 m_hScrollBar->SetThumbPosition( pos ) ;
1918 }
1919 else
1920 {
1921 if ( m_vScrollBar )
1922 m_vScrollBar->SetThumbPosition( pos ) ;
1923 }
1924 }
1925
1926 void wxWindowMac::MacPaintBorders( int left , int top )
1927 {
1928 if( IsTopLevel() )
1929 return ;
1930
1931 int major,minor;
1932 wxGetOsVersion( &major, &minor );
1933
1934 RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ;
1935 RGBColor face = { 0xDDDD, 0xDDDD , 0xDDDD } ;
1936
1937 RGBColor darkShadow = { 0x0000, 0x0000 , 0x0000 } ;
1938 RGBColor lightShadow = { 0x4444, 0x4444 , 0x4444 } ;
1939 // OS X has lighter border edges than classic:
1940 if (major >= 10)
1941 {
1942 darkShadow.red = 0x8E8E;
1943 darkShadow.green = 0x8E8E;
1944 darkShadow.blue = 0x8E8E;
1945 lightShadow.red = 0xBDBD;
1946 lightShadow.green = 0xBDBD;
1947 lightShadow.blue = 0xBDBD;
1948 }
1949
1950 PenNormal() ;
1951
1952 int w , h ;
1953 GetSize( &w , &h ) ;
1954 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
1955 {
1956 #if wxMAC_USE_THEME_BORDER
1957 Rect rect = { top , left , m_height + top , m_width + left } ;
1958 SInt32 border = 0 ;
1959 /*
1960 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1961 InsetRect( &rect , border , border );
1962 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1963 */
1964
1965 DrawThemePrimaryGroup(&rect ,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1966 #else
1967 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1968 RGBForeColor( &face );
1969 MoveTo( left + 0 , top + h - 2 );
1970 LineTo( left + 0 , top + 0 );
1971 LineTo( left + w - 2 , top + 0 );
1972
1973 MoveTo( left + 2 , top + h - 3 );
1974 LineTo( left + w - 3 , top + h - 3 );
1975 LineTo( left + w - 3 , top + 2 );
1976
1977 RGBForeColor( sunken ? &face : &darkShadow );
1978 MoveTo( left + 0 , top + h - 1 );
1979 LineTo( left + w - 1 , top + h - 1 );
1980 LineTo( left + w - 1 , top + 0 );
1981
1982 RGBForeColor( sunken ? &lightShadow : &white );
1983 MoveTo( left + 1 , top + h - 3 );
1984 LineTo( left + 1, top + 1 );
1985 LineTo( left + w - 3 , top + 1 );
1986
1987 RGBForeColor( sunken ? &white : &lightShadow );
1988 MoveTo( left + 1 , top + h - 2 );
1989 LineTo( left + w - 2 , top + h - 2 );
1990 LineTo( left + w - 2 , top + 1 );
1991
1992 RGBForeColor( sunken ? &darkShadow : &face );
1993 MoveTo( left + 2 , top + h - 4 );
1994 LineTo( left + 2 , top + 2 );
1995 LineTo( left + w - 4 , top + 2 );
1996 #endif
1997 }
1998 else if (HasFlag(wxSIMPLE_BORDER))
1999 {
2000 Rect rect = { top , left , h + top , w + left } ;
2001 RGBForeColor( &darkShadow ) ;
2002 FrameRect( &rect ) ;
2003 }
2004 }
2005
2006 void wxWindowMac::RemoveChild( wxWindowBase *child )
2007 {
2008 if ( child == m_hScrollBar )
2009 m_hScrollBar = NULL ;
2010 if ( child == m_vScrollBar )
2011 m_vScrollBar = NULL ;
2012
2013 wxWindowBase::RemoveChild( child ) ;
2014 }
2015
2016 // New function that will replace some of the above.
2017 void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible,
2018 int range, bool refresh)
2019 {
2020 if ( orient == wxHORIZONTAL )
2021 {
2022 if ( m_hScrollBar )
2023 {
2024 if ( range == 0 || thumbVisible >= range )
2025 {
2026 if ( m_hScrollBar->IsShown() )
2027 m_hScrollBar->Show(false) ;
2028 }
2029 else
2030 {
2031 if ( !m_hScrollBar->IsShown() )
2032 m_hScrollBar->Show(true) ;
2033 m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
2034 }
2035 }
2036 }
2037 else
2038 {
2039 if ( m_vScrollBar )
2040 {
2041 if ( range == 0 || thumbVisible >= range )
2042 {
2043 if ( m_vScrollBar->IsShown() )
2044 m_vScrollBar->Show(false) ;
2045 }
2046 else
2047 {
2048 if ( !m_vScrollBar->IsShown() )
2049 m_vScrollBar->Show(true) ;
2050 m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
2051 }
2052 }
2053 }
2054 MacRepositionScrollBars() ;
2055 }
2056
2057 // Does a physical scroll
2058 void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
2059 {
2060 if( dx == 0 && dy ==0 )
2061 return ;
2062
2063
2064 {
2065 wxClientDC dc(this) ;
2066 wxMacPortSetter helper(&dc) ;
2067
2068 int width , height ;
2069 GetClientSize( &width , &height ) ;
2070
2071
2072 wxPoint pos;
2073 pos.x = pos.y = 0;
2074
2075 Rect scrollrect;
2076 // TODO take out the boundaries
2077 GetControlBounds( (ControlRef) m_macControl, &scrollrect);
2078
2079 RgnHandle updateRgn = NewRgn() ;
2080 if ( rect )
2081 {
2082 Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) ,
2083 dc.XLOG2DEVMAC(rect->x + rect->width) } ;
2084 SectRect( &scrollrect , &r , &scrollrect ) ;
2085 }
2086 ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
2087 #if TARGET_CARBON
2088 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
2089 // but it seems the update only refreshes the background of the control, rather than calling
2090 // kEventControlDraw, so we need to force a proper update here. There has to be a better
2091 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
2092 Update();
2093 #endif
2094 // we also have to scroll the update rgn in this rectangle
2095 // in order not to loose updates
2096 #if !TARGET_CARBON
2097 WindowRef rootWindow = (WindowRef) MacGetTopLevelWindowRef() ;
2098 RgnHandle formerUpdateRgn = NewRgn() ;
2099 RgnHandle scrollRgn = NewRgn() ;
2100 RectRgn( scrollRgn , &scrollrect ) ;
2101 GetWindowUpdateRgn( rootWindow , formerUpdateRgn ) ;
2102 Point pt = {0,0} ;
2103 LocalToGlobal( &pt ) ;
2104 OffsetRgn( formerUpdateRgn , -pt.h , -pt.v ) ;
2105 SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
2106 if ( !EmptyRgn( formerUpdateRgn ) )
2107 {
2108 MacOffsetRgn( formerUpdateRgn , dx , dy ) ;
2109 SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
2110 InvalWindowRgn(rootWindow , formerUpdateRgn ) ;
2111 }
2112 InvalWindowRgn(rootWindow , updateRgn ) ;
2113 DisposeRgn( updateRgn ) ;
2114 DisposeRgn( formerUpdateRgn ) ;
2115 DisposeRgn( scrollRgn ) ;
2116 #endif
2117 }
2118
2119 for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())
2120 {
2121 wxWindowMac *child = node->GetData();
2122 if (child == m_vScrollBar) continue;
2123 if (child == m_hScrollBar) continue;
2124 if (child->IsTopLevel()) continue;
2125
2126 int x,y;
2127 child->GetPosition( &x, &y );
2128 int w,h;
2129 child->GetSize( &w, &h );
2130 if (rect)
2131 {
2132 wxRect rc(x,y,w,h);
2133 if (rect->Intersects(rc))
2134 child->SetSize( x+dx, y+dy, w, h );
2135 }
2136 else
2137 {
2138 child->SetSize( x+dx, y+dy, w, h );
2139 }
2140 }
2141
2142 // TODO remove, was moved higher up Update() ;
2143
2144 }
2145
2146 void wxWindowMac::MacOnScroll(wxScrollEvent &event )
2147 {
2148 if ( event.m_eventObject == m_vScrollBar || event.m_eventObject == m_hScrollBar )
2149 {
2150 wxScrollWinEvent wevent;
2151 wevent.SetPosition(event.GetPosition());
2152 wevent.SetOrientation(event.GetOrientation());
2153 wevent.m_eventObject = this;
2154
2155 if (event.m_eventType == wxEVT_SCROLL_TOP)
2156 wevent.m_eventType = wxEVT_SCROLLWIN_TOP;
2157 else if (event.m_eventType == wxEVT_SCROLL_BOTTOM)
2158 wevent.m_eventType = wxEVT_SCROLLWIN_BOTTOM;
2159 else if (event.m_eventType == wxEVT_SCROLL_LINEUP)
2160 wevent.m_eventType = wxEVT_SCROLLWIN_LINEUP;
2161 else if (event.m_eventType == wxEVT_SCROLL_LINEDOWN)
2162 wevent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
2163 else if (event.m_eventType == wxEVT_SCROLL_PAGEUP)
2164 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEUP;
2165 else if (event.m_eventType == wxEVT_SCROLL_PAGEDOWN)
2166 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
2167 else if (event.m_eventType == wxEVT_SCROLL_THUMBTRACK)
2168 wevent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
2169 else if (event.m_eventType == wxEVT_SCROLL_THUMBRELEASE)
2170 wevent.m_eventType = wxEVT_SCROLLWIN_THUMBRELEASE;
2171
2172 GetEventHandler()->ProcessEvent(wevent);
2173 }
2174 }
2175
2176 // Get the window with the focus
2177 wxWindowMac *wxWindowBase::FindFocus()
2178 {
2179 return gFocusWindow ;
2180 }
2181
2182 void wxWindowMac::OnSetFocus(wxFocusEvent& event)
2183 {
2184 // panel wants to track the window which was the last to have focus in it,
2185 // so we want to set ourselves as the window which last had focus
2186 //
2187 // notice that it's also important to do it upwards the tree becaus
2188 // otherwise when the top level panel gets focus, it won't set it back to
2189 // us, but to some other sibling
2190
2191 // CS:don't know if this is still needed:
2192 //wxChildFocusEvent eventFocus(this);
2193 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2194
2195 event.Skip();
2196 }
2197
2198 void wxWindowMac::OnInternalIdle()
2199 {
2200 // This calls the UI-update mechanism (querying windows for
2201 // menu/toolbar/control state information)
2202 if (wxUpdateUIEvent::CanUpdate(this))
2203 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
2204 }
2205
2206 // Raise the window to the top of the Z order
2207 void wxWindowMac::Raise()
2208 {
2209 }
2210
2211 // Lower the window to the bottom of the Z order
2212 void wxWindowMac::Lower()
2213 {
2214 }
2215
2216
2217 // static wxWindow *gs_lastWhich = NULL;
2218
2219 bool wxWindowMac::MacSetupCursor( const wxPoint& pt)
2220 {
2221 // first trigger a set cursor event
2222
2223 wxPoint clientorigin = GetClientAreaOrigin() ;
2224 wxSize clientsize = GetClientSize() ;
2225 wxCursor cursor ;
2226 if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) )
2227 {
2228 wxSetCursorEvent event( pt.x , pt.y );
2229
2230 bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event);
2231 if ( processedEvtSetCursor && event.HasCursor() )
2232 {
2233 cursor = event.GetCursor() ;
2234 }
2235 else
2236 {
2237
2238 // the test for processedEvtSetCursor is here to prevent using m_cursor
2239 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2240 // it - this is a way to say that our cursor shouldn't be used for this
2241 // point
2242 if ( !processedEvtSetCursor && m_cursor.Ok() )
2243 {
2244 cursor = m_cursor ;
2245 }
2246 if ( wxIsBusy() )
2247 {
2248 }
2249 else
2250 {
2251 if ( !GetParent() )
2252 cursor = *wxSTANDARD_CURSOR ;
2253 }
2254 }
2255 if ( cursor.Ok() )
2256 cursor.MacInstall() ;
2257 }
2258 return cursor.Ok() ;
2259 }
2260
2261 wxString wxWindowMac::MacGetToolTipString( wxPoint &pt )
2262 {
2263 if ( m_tooltip )
2264 {
2265 return m_tooltip->GetTip() ;
2266 }
2267 return wxEmptyString ;
2268 }
2269
2270 void wxWindowMac::Update()
2271 {
2272 #if TARGET_API_MAC_OSX
2273 HIViewSetNeedsDisplay( (ControlRef) m_macControl , true ) ;
2274 #else
2275 ::Draw1Control( (ControlRef) m_macControl ) ;
2276 #endif
2277 }
2278
2279 wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const
2280 {
2281 wxTopLevelWindowMac* win = NULL ;
2282 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
2283 if ( window )
2284 {
2285 win = wxFindWinFromMacWindow( window ) ;
2286 }
2287 return win ;
2288 }
2289 wxRegion wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures )
2290 {
2291
2292 Rect r ;
2293 RgnHandle visRgn = NewRgn() ;
2294 RgnHandle tempRgn = NewRgn() ;
2295 if ( IsControlVisible( (ControlRef) m_macControl ) )
2296 {
2297 GetControlBounds( (ControlRef) m_macControl , &r ) ;
2298 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2299 {
2300 MacRootWindowToWindow( &r.left , & r.top ) ;
2301 MacRootWindowToWindow( &r.right , & r.bottom ) ;
2302 }
2303 else
2304 {
2305 r.right -= r.left ;
2306 r.bottom -= r.top ;
2307 r.left = 0 ;
2308 r.top = 0 ;
2309 }
2310 if ( includeOuterStructures )
2311 InsetRect( &r , -3 , -3 ) ;
2312 RectRgn( visRgn , &r ) ;
2313 if ( !IsTopLevel() )
2314 {
2315 wxWindow* child = this ;
2316 wxWindow* parent = child->GetParent() ;
2317 while( parent )
2318 {
2319 int x , y ;
2320 wxSize size ;
2321 // we have to find a better clipping algorithm here, in order not to clip things
2322 // positioned like status and toolbar
2323 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2324 {
2325 size = parent->GetSize() ;
2326 x = y = 0 ;
2327 }
2328 else
2329 {
2330 size = parent->GetClientSize() ;
2331 wxPoint origin = parent->GetClientAreaOrigin() ;
2332 x = origin.x ;
2333 y = origin.y ;
2334 }
2335 parent->MacWindowToRootWindow( &x, &y ) ;
2336 MacRootWindowToWindow( &x , &y ) ;
2337
2338 SetRectRgn( tempRgn ,
2339 x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() ,
2340 x + size.x - parent->MacGetRightBorderSize(),
2341 y + size.y - parent->MacGetBottomBorderSize()) ;
2342
2343 SectRgn( visRgn , tempRgn , visRgn ) ;
2344 if ( parent->IsTopLevel() )
2345 break ;
2346 child = parent ;
2347 parent = child->GetParent() ;
2348 }
2349 }
2350 }
2351
2352 wxRegion vis = visRgn ;
2353 DisposeRgn( visRgn ) ;
2354 DisposeRgn( tempRgn ) ;
2355 return vis ;
2356 }
2357
2358 /*
2359 This function must not change the updatergn !
2360 */
2361 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time )
2362 {
2363 // we let the OS handle root control redraws
2364 if ( m_macControl == MacGetTopLevelWindow()->GetHandle() )
2365 return false ;
2366
2367 RgnHandle updatergn = (RgnHandle) updatergnr ;
2368 bool handled = false ;
2369
2370 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2371 {
2372 RgnHandle newupdate = NewRgn() ;
2373 wxSize point = GetClientSize() ;
2374 wxPoint origin = GetClientAreaOrigin() ;
2375 SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ;
2376 SectRgn( newupdate , updatergn , newupdate ) ;
2377 OffsetRgn( newupdate , -origin.x , -origin.y ) ;
2378 m_updateRegion = newupdate ;
2379 DisposeRgn( newupdate ) ;
2380 }
2381
2382 if ( !EmptyRgn(updatergn) )
2383 {
2384 wxWindowDC dc(this);
2385 if (!EmptyRgn(updatergn))
2386 dc.SetClippingRegion(wxRegion(updatergn));
2387
2388 wxEraseEvent eevent( GetId(), &dc );
2389 eevent.SetEventObject( this );
2390 GetEventHandler()->ProcessEvent( eevent );
2391
2392 if ( !m_updateRegion.Empty() )
2393 {
2394 // paint the window itself
2395 wxPaintEvent event;
2396 event.m_timeStamp = time ;
2397 event.SetEventObject(this);
2398 handled = GetEventHandler()->ProcessEvent(event);
2399
2400 // paint custom borders
2401 wxNcPaintEvent eventNc( GetId() );
2402 eventNc.SetEventObject( this );
2403 GetEventHandler()->ProcessEvent( eventNc );
2404 }
2405 }
2406 return handled ;
2407 }
2408
2409 void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase)
2410 {
2411 RgnHandle updatergn = (RgnHandle) updatergnr ;
2412 // updatergn is always already clipped to our boundaries
2413 // if we are in compositing mode then it is in relative to the upper left of the control
2414 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2415 // of the toplevel window
2416 // it is in window coordinates, not in client coordinates
2417
2418 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2419 RgnHandle ownUpdateRgn = NewRgn() ;
2420 CopyRgn( updatergn , ownUpdateRgn ) ;
2421
2422 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2423 {
2424 Rect bounds;
2425 UMAGetControlBoundsInWindowCoords( (ControlRef)m_macControl, &bounds );
2426 RgnHandle controlRgn = NewRgn();
2427 RectRgn( controlRgn, &bounds );
2428 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2429 // the window update region
2430 SectRgn( ownUpdateRgn, controlRgn, ownUpdateRgn );
2431 DisposeRgn( controlRgn );
2432
2433 //KO: convert ownUpdateRgn to local coordinates
2434 OffsetRgn( ownUpdateRgn, -bounds.left, -bounds.top );
2435 }
2436
2437 MacDoRedraw( ownUpdateRgn , time ) ;
2438 DisposeRgn( ownUpdateRgn ) ;
2439
2440 }
2441
2442 WXWindow wxWindowMac::MacGetTopLevelWindowRef() const
2443 {
2444 wxWindowMac *iter = (wxWindowMac*)this ;
2445
2446 while( iter )
2447 {
2448 if ( iter->IsTopLevel() )
2449 return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ;
2450
2451 iter = iter->GetParent() ;
2452 }
2453 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2454 return NULL ;
2455 }
2456
2457 void wxWindowMac::MacCreateScrollBars( long style )
2458 {
2459 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ;
2460
2461 bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
2462 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ;
2463 int width, height ;
2464 GetClientSize( &width , &height ) ;
2465
2466 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
2467 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
2468 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
2469 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
2470
2471 m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint,
2472 vSize , wxVERTICAL);
2473
2474 if ( style & wxVSCROLL )
2475 {
2476
2477 }
2478 else
2479 {
2480 m_vScrollBar->Show(false) ;
2481 }
2482 m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint,
2483 hSize , wxHORIZONTAL);
2484 if ( style & wxHSCROLL )
2485 {
2486 }
2487 else
2488 {
2489 m_hScrollBar->Show(false) ;
2490 }
2491
2492 // because the create does not take into account the client area origin
2493 MacRepositionScrollBars() ; // we might have a real position shift
2494 }
2495
2496 void wxWindowMac::MacRepositionScrollBars()
2497 {
2498 bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
2499 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ;
2500
2501 // get real client area
2502
2503 int width ;
2504 int height ;
2505 GetSize( &width , &height ) ;
2506
2507 width -= MacGetLeftBorderSize() + MacGetRightBorderSize();
2508 height -= MacGetTopBorderSize() + MacGetBottomBorderSize();
2509
2510 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
2511 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
2512 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
2513 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
2514
2515 int x = 0 ;
2516 int y = 0 ;
2517 int w ;
2518 int h ;
2519 GetSize( &w , &h ) ;
2520
2521 MacClientToRootWindow( &x , &y ) ;
2522 MacClientToRootWindow( &w , &h ) ;
2523
2524 wxWindowMac *iter = (wxWindowMac*)this ;
2525
2526 int totW = 10000 , totH = 10000;
2527 while( iter )
2528 {
2529 if ( iter->IsTopLevel() )
2530 {
2531 iter->GetSize( &totW , &totH ) ;
2532 break ;
2533 }
2534
2535 iter = iter->GetParent() ;
2536 }
2537
2538 if ( x == 0 )
2539 {
2540 hPoint.x = -1 ;
2541 hSize.x += 1 ;
2542 }
2543 if ( y == 0 )
2544 {
2545 vPoint.y = -1 ;
2546 vSize.y += 1 ;
2547 }
2548
2549 if ( w-x >= totW )
2550 {
2551 hSize.x += 1 ;
2552 vPoint.x += 1 ;
2553 }
2554
2555 if ( h-y >= totH )
2556 {
2557 vSize.y += 1 ;
2558 hPoint.y += 1 ;
2559 }
2560
2561 if ( m_vScrollBar )
2562 {
2563 m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE);
2564 }
2565 if ( m_hScrollBar )
2566 {
2567 m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE);
2568 }
2569 }
2570
2571 bool wxWindowMac::AcceptsFocus() const
2572 {
2573 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2574 }
2575
2576 void wxWindowMac::MacSuperChangedPosition()
2577 {
2578 // only window-absolute structures have to be moved i.e. controls
2579
2580 wxWindowListNode *node = GetChildren().GetFirst();
2581 while ( node )
2582 {
2583 wxWindowMac *child = node->GetData();
2584 child->MacSuperChangedPosition() ;
2585 node = node->GetNext();
2586 }
2587 }
2588
2589 void wxWindowMac::MacTopLevelWindowChangedPosition()
2590 {
2591 // only screen-absolute structures have to be moved i.e. glcanvas
2592
2593 wxWindowListNode *node = GetChildren().GetFirst();
2594 while ( node )
2595 {
2596 wxWindowMac *child = node->GetData();
2597 child->MacTopLevelWindowChangedPosition() ;
2598 node = node->GetNext();
2599 }
2600 }
2601
2602 long wxWindowMac::MacGetLeftBorderSize( ) const
2603 {
2604 if( IsTopLevel() )
2605 return 0 ;
2606
2607 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
2608 {
2609 SInt32 border = 3 ;
2610 #if wxMAC_USE_THEME_BORDER
2611 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2612 #endif
2613 return border ;
2614 }
2615 else if ( m_windowStyle &wxDOUBLE_BORDER)
2616 {
2617 SInt32 border = 3 ;
2618 #if wxMAC_USE_THEME_BORDER
2619 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2620 #endif
2621 return border ;
2622 }
2623 else if (m_windowStyle &wxSIMPLE_BORDER)
2624 {
2625 return 1 ;
2626 }
2627 return 0 ;
2628 }
2629
2630 long wxWindowMac::MacGetRightBorderSize( ) const
2631 {
2632 // they are all symmetric in mac themes
2633 return MacGetLeftBorderSize() ;
2634 }
2635
2636 long wxWindowMac::MacGetTopBorderSize( ) const
2637 {
2638 // they are all symmetric in mac themes
2639 return MacGetLeftBorderSize() ;
2640 }
2641
2642 long wxWindowMac::MacGetBottomBorderSize( ) const
2643 {
2644 // they are all symmetric in mac themes
2645 return MacGetLeftBorderSize() ;
2646 }
2647
2648 long wxWindowMac::MacRemoveBordersFromStyle( long style )
2649 {
2650 return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ;
2651 }
2652
2653 // Find the wxWindowMac at the current mouse position, returning the mouse
2654 // position.
2655 wxWindowMac* wxFindWindowAtPointer(wxPoint& pt)
2656 {
2657 pt = wxGetMousePosition();
2658 wxWindowMac* found = wxFindWindowAtPoint(pt);
2659 return found;
2660 }
2661
2662 // Get the current mouse position.
2663 wxPoint wxGetMousePosition()
2664 {
2665 int x, y;
2666 wxGetMousePosition(& x, & y);
2667 return wxPoint(x, y);
2668 }
2669
2670 void wxWindowMac::OnMouseEvent( wxMouseEvent &event )
2671 {
2672 if ( event.GetEventType() == wxEVT_RIGHT_DOWN )
2673 {
2674 // copied from wxGTK : CS
2675 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2676 // except that:
2677 //
2678 // (a) it's a command event and so is propagated to the parent
2679 // (b) under MSW it can be generated from kbd too
2680 // (c) it uses screen coords (because of (a))
2681 wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU,
2682 this->GetId(),
2683 this->ClientToScreen(event.GetPosition()));
2684 if ( ! GetEventHandler()->ProcessEvent(evtCtx) )
2685 event.Skip() ;
2686 }
2687 else if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK )
2688 {
2689
2690 int x = event.m_x ;
2691 int y = event.m_y ;
2692
2693 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2694 {
2695 // OS Needs it in tlw content area coordinates
2696 MacClientToRootWindow( &x , &y ) ;
2697 }
2698 else
2699 {
2700 // OS Needs it in window not client coordinates
2701 wxPoint origin = GetClientAreaOrigin() ;
2702 x += origin.x ;
2703 y += origin.y ;
2704 }
2705 Point localwhere ;
2706 SInt16 controlpart ;
2707
2708 localwhere.h = x ;
2709 localwhere.v = y ;
2710
2711 short modifiers = 0;
2712
2713 if ( !event.m_leftDown && !event.m_rightDown )
2714 modifiers |= btnState ;
2715
2716 if ( event.m_shiftDown )
2717 modifiers |= shiftKey ;
2718
2719 if ( event.m_controlDown )
2720 modifiers |= controlKey ;
2721
2722 if ( event.m_altDown )
2723 modifiers |= optionKey ;
2724
2725 if ( event.m_metaDown )
2726 modifiers |= cmdKey ;
2727
2728 bool handled = false ;
2729
2730 if ( ::IsControlActive( (ControlRef) m_macControl ) )
2731 {
2732 controlpart = ::HandleControlClick( (ControlRef) m_macControl , localwhere , modifiers , (ControlActionUPP) -1 ) ;
2733 wxTheApp->s_lastMouseDown = 0 ;
2734 if ( controlpart != kControlNoPart )
2735 {
2736 MacHandleControlClick((WXWidget) (ControlRef) m_macControl , controlpart , false /* mouse not down anymore */ ) ;
2737 handled = true ;
2738 }
2739 }
2740 if ( !handled )
2741 event.Skip() ;
2742 }
2743 else
2744 {
2745 event.Skip() ;
2746 }
2747 }
2748
2749 void wxWindowMac::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) )
2750 {
2751 wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ;
2752 }
2753
2754 Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size )
2755 {
2756 int x ,y , w ,h ;
2757
2758 window->MacGetBoundsForControl( pos , size , x , y, w, h ) ;
2759 Rect bounds = { y , x , y+h , x+w };
2760 return bounds ;
2761 }
2762
2763