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