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