]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/window.cpp
added adjustOrigin parameter to bounds calculation, added Freeze and Thaw implementation
[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 InstallControlEventHandler( (ControlRef) m_macControl, GetwxMacWindowEventHandlerUPP(),
544 GetEventTypeCount(eventList), eventList, this,
545 (EventHandlerRef *)&m_macControlEventHandler);
546
547 }
548
549 // Constructor
550 bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id,
551 const wxPoint& pos,
552 const wxSize& size,
553 long style,
554 const wxString& name)
555 {
556 wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindowMac without parent") );
557
558 if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
559 return FALSE;
560
561 parent->AddChild(this);
562
563 m_windowVariant = parent->GetWindowVariant() ;
564
565 if ( m_macIsUserPane )
566 {
567 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
568
569 UInt32 features = kControlSupportsEmbedding | kControlSupportsLiveFeedback | kControlHasSpecialBackground |
570 kControlSupportsCalcBestRect | kControlHandlesTracking | kControlSupportsFocus | kControlWantsActivate | kControlWantsIdle;
571
572 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds, kControlSupportsEmbedding , (ControlRef*) &m_macControl);
573
574 MacPostControlCreate(pos,size) ;
575 #if !TARGET_API_MAC_OSX
576 SetControlData((ControlRef) m_macControl,kControlEntireControl,kControlUserPaneDrawProcTag,
577 sizeof(gControlUserPaneDrawUPP),(Ptr) &gControlUserPaneDrawUPP);
578 SetControlData((ControlRef) m_macControl,kControlEntireControl,kControlUserPaneHitTestProcTag,
579 sizeof(gControlUserPaneHitTestUPP),(Ptr) &gControlUserPaneHitTestUPP);
580 SetControlData((ControlRef) m_macControl,kControlEntireControl,kControlUserPaneTrackingProcTag,
581 sizeof(gControlUserPaneTrackingUPP),(Ptr) &gControlUserPaneTrackingUPP);
582 SetControlData((ControlRef) m_macControl,kControlEntireControl,kControlUserPaneIdleProcTag,
583 sizeof(gControlUserPaneIdleUPP),(Ptr) &gControlUserPaneIdleUPP);
584 SetControlData((ControlRef) m_macControl,kControlEntireControl,kControlUserPaneKeyDownProcTag,
585 sizeof(gControlUserPaneKeyDownUPP),(Ptr) &gControlUserPaneKeyDownUPP);
586 SetControlData((ControlRef) m_macControl,kControlEntireControl,kControlUserPaneActivateProcTag,
587 sizeof(gControlUserPaneActivateUPP),(Ptr) &gControlUserPaneActivateUPP);
588 SetControlData((ControlRef) m_macControl,kControlEntireControl,kControlUserPaneFocusProcTag,
589 sizeof(gControlUserPaneFocusUPP),(Ptr) &gControlUserPaneFocusUPP);
590 SetControlData((ControlRef) m_macControl,kControlEntireControl,kControlUserPaneBackgroundProcTag,
591 sizeof(gControlUserPaneBackgroundUPP),(Ptr) &gControlUserPaneBackgroundUPP);
592 #endif
593 }
594 #ifndef __WXUNIVERSAL__
595 // Don't give scrollbars to wxControls unless they ask for them
596 if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar))) ||
597 (IsKindOf(CLASSINFO(wxControl)) && ( style & wxHSCROLL || style & wxVSCROLL)))
598 {
599 MacCreateScrollBars( style ) ;
600 }
601 #endif
602
603 wxWindowCreateEvent event(this);
604 GetEventHandler()->AddPendingEvent(event);
605
606 return TRUE;
607 }
608
609 void wxWindowMac::MacPostControlCreate(const wxPoint& pos, const wxSize& size)
610 {
611 wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ;
612
613 wxAssociateControlWithMacControl( (ControlRef) m_macControl , this ) ;
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 HIViewConvertPoint( &pt , (ControlRef) m_macControl , (ControlRef) MacGetTopLevelWindow()->GetHandle() ) ;
1072
1073 if ( x ) *x = (int) pt.x ;
1074 if ( y ) *y = (int) pt.y ;
1075 #else
1076 if ( !IsTopLevel() )
1077 {
1078 Rect bounds ;
1079 GetControlBounds( (ControlRef) m_macControl , &bounds ) ;
1080 if(x) *x += bounds.left ;
1081 if(y) *y += bounds.top ;
1082 }
1083 #endif
1084 }
1085
1086 void wxWindowMac::MacWindowToRootWindow( short *x , short *y ) const
1087 {
1088 int x1 , y1 ;
1089 if ( x ) x1 = *x ;
1090 if ( y ) y1 = *y ;
1091 MacWindowToRootWindow( &x1 , &y1 ) ;
1092 if ( x ) *x = x1 ;
1093 if ( y ) *y = y1 ;
1094 }
1095
1096 void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const
1097 {
1098 #if TARGET_API_MAC_OSX
1099 HIPoint pt ;
1100 if ( x ) pt.x = *x ;
1101 if ( y ) pt.y = *y ;
1102
1103 HIViewConvertPoint( &pt , (ControlRef) MacGetTopLevelWindow()->GetHandle() , (ControlRef) m_macControl ) ;
1104
1105 if ( x ) *x = (int) pt.x ;
1106 if ( y ) *y = (int) pt.y ;
1107 #else
1108 if ( !IsTopLevel() )
1109 {
1110 Rect bounds ;
1111 GetControlBounds( (ControlRef) m_macControl , &bounds ) ;
1112 if(x) *x -= bounds.left ;
1113 if(y) *y -= bounds.top ;
1114 }
1115 #endif
1116 }
1117
1118 void wxWindowMac::MacRootWindowToWindow( short *x , short *y ) const
1119 {
1120 int x1 , y1 ;
1121 if ( x ) x1 = *x ;
1122 if ( y ) y1 = *y ;
1123 MacRootWindowToWindow( &x1 , &y1 ) ;
1124 if ( x ) *x = x1 ;
1125 if ( y ) *y = y1 ;
1126 }
1127
1128 wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const
1129 {
1130 wxSize sizeTotal = size;
1131
1132 RgnHandle rgn = NewRgn() ;
1133
1134 Rect content ;
1135
1136 if ( GetControlRegion( (ControlRef) m_macControl , kControlContentMetaPart , rgn ) == noErr )
1137 {
1138 GetRegionBounds( rgn , &content ) ;
1139 DisposeRgn( rgn ) ;
1140 }
1141 else
1142 {
1143 GetControlBounds( (ControlRef) m_macControl , &content ) ;
1144 }
1145 Rect structure ;
1146 GetControlBounds( (ControlRef) m_macControl , &structure ) ;
1147 #if !TARGET_API_MAC_OSX
1148 OffsetRect( &content , -structure.left , -structure.top ) ;
1149 #endif
1150
1151 sizeTotal.x += (structure.right - structure.left) - (content.right - content.left) ;
1152 sizeTotal.y += (structure.bottom - structure.top) - (content.bottom - content.top ) ;
1153
1154 sizeTotal.x += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1155 sizeTotal.y += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1156
1157 return sizeTotal;
1158 }
1159
1160
1161 // Get size *available for subwindows* i.e. excluding menu bar etc.
1162 void wxWindowMac::DoGetClientSize(int *x, int *y) const
1163 {
1164 int ww, hh;
1165
1166 RgnHandle rgn = NewRgn() ;
1167 Rect content ;
1168 if ( GetControlRegion( (ControlRef) m_macControl , kControlContentMetaPart , rgn ) == noErr )
1169 {
1170 GetRegionBounds( rgn , &content ) ;
1171 DisposeRgn( rgn ) ;
1172 }
1173 else
1174 {
1175 GetControlBounds( (ControlRef) m_macControl , &content ) ;
1176 }
1177 #if !TARGET_API_MAC_OSX
1178 Rect structure ;
1179 GetControlBounds( (ControlRef) m_macControl , &structure ) ;
1180 OffsetRect( &content , -structure.left , -structure.top ) ;
1181 #endif
1182 ww = content.right - content.left ;
1183 hh = content.bottom - content.top ;
1184
1185 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1186 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1187
1188 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
1189 {
1190 int x1 = 0 ;
1191 int y1 = 0 ;
1192 int w ;
1193 int h ;
1194 GetSize( &w , &h ) ;
1195
1196 MacClientToRootWindow( &x1 , &y1 ) ;
1197 MacClientToRootWindow( &w , &h ) ;
1198
1199 wxWindowMac *iter = (wxWindowMac*)this ;
1200
1201 int totW = 10000 , totH = 10000;
1202 while( iter )
1203 {
1204 if ( iter->IsTopLevel() )
1205 {
1206 iter->GetSize( &totW , &totH ) ;
1207 break ;
1208 }
1209
1210 iter = iter->GetParent() ;
1211 }
1212
1213 if (m_hScrollBar && m_hScrollBar->IsShown() )
1214 {
1215 hh -= MAC_SCROLLBAR_SIZE;
1216 if ( h-y1 >= totH )
1217 {
1218 hh += 1 ;
1219 }
1220 }
1221 if (m_vScrollBar && m_vScrollBar->IsShown() )
1222 {
1223 ww -= MAC_SCROLLBAR_SIZE;
1224 if ( w-x1 >= totW )
1225 {
1226 ww += 1 ;
1227 }
1228 }
1229 }
1230 if(x) *x = ww;
1231 if(y) *y = hh;
1232
1233 }
1234
1235 bool wxWindowMac::SetCursor(const wxCursor& cursor)
1236 {
1237 if (m_cursor == cursor)
1238 return FALSE;
1239
1240 if (wxNullCursor == cursor)
1241 {
1242 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) )
1243 return FALSE ;
1244 }
1245 else
1246 {
1247 if ( ! wxWindowBase::SetCursor( cursor ) )
1248 return FALSE ;
1249 }
1250
1251 wxASSERT_MSG( m_cursor.Ok(),
1252 wxT("cursor must be valid after call to the base version"));
1253
1254 /*
1255
1256 TODO why do we have to use current coordinates ?
1257
1258 Point pt ;
1259 wxWindowMac *mouseWin ;
1260 GetMouse( &pt ) ;
1261
1262 // Change the cursor NOW if we're within the correct window
1263
1264
1265 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1266 {
1267 if ( mouseWin == this && !wxIsBusy() )
1268 {
1269 m_cursor.MacInstall() ;
1270 }
1271 }
1272 */
1273 if ( !wxIsBusy() )
1274 {
1275 m_cursor.MacInstall() ;
1276 }
1277
1278 return TRUE ;
1279 }
1280
1281 #if wxUSE_MENUS
1282 bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y)
1283 {
1284 menu->SetInvokingWindow(this);
1285 menu->UpdateUI();
1286 ClientToScreen( &x , &y ) ;
1287
1288 menu->MacBeforeDisplay( true ) ;
1289 long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ;
1290 if ( HiWord(menuResult) != 0 )
1291 {
1292 MenuCommand id ;
1293 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &id ) ;
1294 wxMenuItem* item = NULL ;
1295 wxMenu* realmenu ;
1296 item = menu->FindItem(id, &realmenu) ;
1297 if (item->IsCheckable())
1298 {
1299 item->Check( !item->IsChecked() ) ;
1300 }
1301 menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ;
1302 }
1303 menu->MacAfterDisplay( true ) ;
1304
1305 menu->SetInvokingWindow(NULL);
1306
1307 return TRUE;
1308 }
1309 #endif
1310
1311 // ----------------------------------------------------------------------------
1312 // tooltips
1313 // ----------------------------------------------------------------------------
1314
1315 #if wxUSE_TOOLTIPS
1316
1317 void wxWindowMac::DoSetToolTip(wxToolTip *tooltip)
1318 {
1319 wxWindowBase::DoSetToolTip(tooltip);
1320
1321 if ( m_tooltip )
1322 m_tooltip->SetWindow(this);
1323 }
1324
1325 #endif // wxUSE_TOOLTIPS
1326
1327 void wxWindowMac::DoMoveWindow(int x, int y, int width, int height)
1328 {
1329 int former_x , former_y , former_w, former_h ;
1330 #if !TARGET_API_MAC_OSX
1331 DoGetPosition( &former_x , &former_y ) ;
1332 DoGetSize( &former_w , &former_h ) ;
1333 #else
1334 MacGetPositionAndSizeFromControl( former_x , former_y , former_w , former_h ) ;
1335 #endif
1336
1337 int actualWidth = width;
1338 int actualHeight = height;
1339 int actualX = x;
1340 int actualY = y;
1341
1342 if ((m_minWidth != -1) && (actualWidth < m_minWidth))
1343 actualWidth = m_minWidth;
1344 if ((m_minHeight != -1) && (actualHeight < m_minHeight))
1345 actualHeight = m_minHeight;
1346 if ((m_maxWidth != -1) && (actualWidth > m_maxWidth))
1347 actualWidth = m_maxWidth;
1348 if ((m_maxHeight != -1) && (actualHeight > m_maxHeight))
1349 actualHeight = m_maxHeight;
1350
1351 bool doMove = false ;
1352 bool doResize = false ;
1353
1354 if ( actualX != former_x || actualY != former_y )
1355 {
1356 doMove = true ;
1357 }
1358 if ( actualWidth != former_w || actualHeight != former_h )
1359 {
1360 doResize = true ;
1361 }
1362
1363 if ( doMove || doResize )
1364 {
1365 // we don't adjust twice for the origin
1366 Rect r = wxMacGetBoundsForControl(this , wxPoint( actualX,actualY), wxSize( actualWidth, actualHeight ) , false ) ;
1367 bool vis = IsControlVisible( (ControlRef) m_macControl ) ;
1368 #if TARGET_API_MAC_OSX
1369 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1370 if ( vis )
1371 SetControlVisibility( (ControlRef)m_macControl , false , true ) ;
1372 HIRect hir = { r.left , r.top , r.right - r.left , r.bottom - r.top } ;
1373 HIViewSetFrame ( (ControlRef) m_macControl , &hir ) ;
1374 if ( vis )
1375 SetControlVisibility( (ControlRef)m_macControl , true , true ) ;
1376 #else
1377 // TODO TEST SetControlBounds( (ControlRef) m_macControl , &r ) ;
1378 if ( vis )
1379 SetControlVisibility( (ControlRef)m_macControl , false , true ) ;
1380 if ( doMove )
1381 MoveControl( (ControlRef) m_macControl , r.left , r.top ) ;
1382 if ( doSize )
1383 SizeControl( (ControlRef) m_macControl , r.right-r.left , r.bottom-r.top ) ;
1384 if ( vis )
1385 SetControlVisibility( (ControlRef)m_macControl , true , true ) ;
1386 #endif
1387 MacRepositionScrollBars() ;
1388 if ( doMove )
1389 {
1390 wxPoint point(actualX,actualY);
1391 wxMoveEvent event(point, m_windowId);
1392 event.SetEventObject(this);
1393 GetEventHandler()->ProcessEvent(event) ;
1394 }
1395 if ( doResize )
1396 {
1397 MacRepositionScrollBars() ;
1398 wxSize size(actualWidth, actualHeight);
1399 wxSizeEvent event(size, m_windowId);
1400 event.SetEventObject(this);
1401 GetEventHandler()->ProcessEvent(event);
1402 }
1403 }
1404
1405 }
1406
1407 wxSize wxWindowMac::DoGetBestSize() const
1408 {
1409 if ( m_macIsUserPane || IsTopLevel() )
1410 return wxWindowBase::DoGetBestSize() ;
1411
1412 Rect bestsize = { 0 , 0 , 0 , 0 } ;
1413 short baselineoffset ;
1414 int bestWidth, bestHeight ;
1415 ::GetBestControlRect( (ControlRef) m_macControl , &bestsize , &baselineoffset ) ;
1416
1417 if ( EmptyRect( &bestsize ) )
1418 {
1419 baselineoffset = 0;
1420 bestsize.left = bestsize.top = 0 ;
1421 bestsize.right = 16 ;
1422 bestsize.bottom = 16 ;
1423 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
1424 {
1425 bestsize.bottom = 16 ;
1426 }
1427 else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
1428 {
1429 bestsize.bottom = 24 ;
1430 }
1431 else
1432 {
1433 // return wxWindowBase::DoGetBestSize() ;
1434 }
1435 }
1436
1437 bestWidth = bestsize.right - bestsize.left ;
1438 bestHeight = bestsize.bottom - bestsize.top ;
1439 if ( bestHeight < 10 )
1440 bestHeight = 13 ;
1441
1442 return wxSize(bestWidth, bestHeight);
1443 // return wxWindowBase::DoGetBestSize() ;
1444 }
1445
1446
1447 // set the size of the window: if the dimensions are positive, just use them,
1448 // but if any of them is equal to -1, it means that we must find the value for
1449 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1450 // which case -1 is a valid value for x and y)
1451 //
1452 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1453 // the width/height to best suit our contents, otherwise we reuse the current
1454 // width/height
1455 void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags)
1456 {
1457 // get the current size and position...
1458 int currentX, currentY;
1459 GetPosition(&currentX, &currentY);
1460
1461 int currentW,currentH;
1462 GetSize(&currentW, &currentH);
1463
1464 // ... and don't do anything (avoiding flicker) if it's already ok
1465 if ( x == currentX && y == currentY &&
1466 width == currentW && height == currentH && ( height != -1 && width != -1 ) )
1467 {
1468 // TODO REMOVE
1469 MacRepositionScrollBars() ; // we might have a real position shift
1470 return;
1471 }
1472
1473 if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
1474 x = currentX;
1475 if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
1476 y = currentY;
1477
1478 AdjustForParentClientOrigin(x, y, sizeFlags);
1479
1480 wxSize size(-1, -1);
1481 if ( width == -1 )
1482 {
1483 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
1484 {
1485 size = DoGetBestSize();
1486 width = size.x;
1487 }
1488 else
1489 {
1490 // just take the current one
1491 width = currentW;
1492 }
1493 }
1494
1495 if ( height == -1 )
1496 {
1497 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
1498 {
1499 if ( size.x == -1 )
1500 {
1501 size = DoGetBestSize();
1502 }
1503 //else: already called DoGetBestSize() above
1504
1505 height = size.y;
1506 }
1507 else
1508 {
1509 // just take the current one
1510 height = currentH;
1511 }
1512 }
1513
1514 DoMoveWindow(x, y, width, height);
1515
1516 }
1517
1518 wxPoint wxWindowMac::GetClientAreaOrigin() const
1519 {
1520 RgnHandle rgn = NewRgn() ;
1521 Rect content ;
1522 GetControlRegion( (ControlRef) m_macControl , kControlContentMetaPart , rgn ) ;
1523 GetRegionBounds( rgn , &content ) ;
1524 DisposeRgn( rgn ) ;
1525 #if !TARGET_API_MAC_OSX
1526 Rect structure ;
1527 GetControlBounds( (ControlRef) m_macControl , &structure ) ;
1528 OffsetRect( &content , -structure.left , -structure.top ) ;
1529 #endif
1530
1531 return wxPoint( content.left + MacGetLeftBorderSize( ) , content.top + MacGetTopBorderSize( ) );
1532 }
1533
1534 void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight)
1535 {
1536 if ( clientheight != -1 || clientheight != -1 )
1537 {
1538 int currentclientwidth , currentclientheight ;
1539 int currentwidth , currentheight ;
1540
1541 GetClientSize( &currentclientwidth , &currentclientheight ) ;
1542 GetSize( &currentwidth , &currentheight ) ;
1543
1544 DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth ,
1545 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
1546 }
1547 }
1548
1549 void wxWindowMac::SetTitle(const wxString& title)
1550 {
1551 m_label = wxStripMenuCodes(title) ;
1552
1553 if ( m_macControl )
1554 {
1555 UMASetControlTitle( (ControlRef) m_macControl , m_label , m_font.GetEncoding() ) ;
1556 }
1557 Refresh() ;
1558 }
1559
1560 wxString wxWindowMac::GetTitle() const
1561 {
1562 return m_label ;
1563 }
1564
1565 bool wxWindowMac::Show(bool show)
1566 {
1567 if ( !wxWindowBase::Show(show) )
1568 return FALSE;
1569
1570 // TODO use visibilityChanged Carbon Event for OSX
1571 bool former = MacIsReallyShown() ;
1572
1573 SetControlVisibility( (ControlRef) m_macControl , show , true ) ;
1574 if ( former != MacIsReallyShown() )
1575 MacPropagateVisibilityChanged() ;
1576 return TRUE;
1577 }
1578
1579 bool wxWindowMac::Enable(bool enable)
1580 {
1581 wxASSERT( m_macControl != NULL ) ;
1582 if ( !wxWindowBase::Enable(enable) )
1583 return FALSE;
1584
1585 bool former = MacIsReallyEnabled() ;
1586 if ( enable )
1587 EnableControl( (ControlRef) m_macControl ) ;
1588 else
1589 DisableControl( (ControlRef) m_macControl ) ;
1590
1591 if ( former != MacIsReallyEnabled() )
1592 MacPropagateEnabledStateChanged() ;
1593 return TRUE;
1594 }
1595
1596 //
1597 // status change propagations (will be not necessary for OSX later )
1598 //
1599
1600 void wxWindowMac::MacPropagateVisibilityChanged()
1601 {
1602 #if !TARGET_API_MAC_OSX
1603 MacVisibilityChanged() ;
1604
1605 wxWindowListNode *node = GetChildren().GetFirst();
1606 while ( node )
1607 {
1608 wxWindowMac *child = node->GetData();
1609 if ( child->IsShown() )
1610 child->MacPropagateVisibilityChanged( ) ;
1611 node = node->GetNext();
1612 }
1613 #endif
1614 }
1615
1616 void wxWindowMac::MacPropagateEnabledStateChanged( )
1617 {
1618 #if !TARGET_API_MAC_OSX
1619 MacEnabledStateChanged() ;
1620
1621 wxWindowListNode *node = GetChildren().GetFirst();
1622 while ( node )
1623 {
1624 wxWindowMac *child = node->GetData();
1625 if ( child->IsEnabled() )
1626 child->MacPropagateEnabledStateChanged() ;
1627 node = node->GetNext();
1628 }
1629 #endif
1630 }
1631
1632 void wxWindowMac::MacPropagateHiliteChanged( )
1633 {
1634 #if !TARGET_API_MAC_OSX
1635 MacHiliteChanged() ;
1636
1637 wxWindowListNode *node = GetChildren().GetFirst();
1638 while ( node )
1639 {
1640 wxWindowMac *child = node->GetData();
1641 // if ( child->IsEnabled() )
1642 child->MacPropagateHiliteChanged() ;
1643 node = node->GetNext();
1644 }
1645 #endif
1646 }
1647
1648 //
1649 // status change notifications
1650 //
1651
1652 void wxWindowMac::MacVisibilityChanged()
1653 {
1654 }
1655
1656 void wxWindowMac::MacHiliteChanged()
1657 {
1658 }
1659
1660 void wxWindowMac::MacEnabledStateChanged()
1661 {
1662 }
1663
1664 //
1665 // status queries on the inherited window's state
1666 //
1667
1668 bool wxWindowMac::MacIsReallyShown()
1669 {
1670 // only under OSX the visibility of the TLW is taken into account
1671 #if TARGET_API_MAC_OSX
1672 return IsControlVisible( (ControlRef) m_macControl ) ;
1673 #else
1674 wxWindow* win = this ;
1675 while( win->IsShown() )
1676 {
1677 if ( win->IsTopLevel() )
1678 return true ;
1679
1680 win = win->GetParent() ;
1681 if ( win == NULL )
1682 return true ;
1683
1684 } ;
1685 return false ;
1686 #endif
1687 }
1688
1689 bool wxWindowMac::MacIsReallyEnabled()
1690 {
1691 return IsControlEnabled( (ControlRef) m_macControl ) ;
1692 }
1693
1694 bool wxWindowMac::MacIsReallyHilited()
1695 {
1696 return IsControlActive( (ControlRef) m_macControl ) ;
1697 }
1698
1699 //
1700 //
1701 //
1702
1703 int wxWindowMac::GetCharHeight() const
1704 {
1705 wxClientDC dc ( (wxWindowMac*)this ) ;
1706 return dc.GetCharHeight() ;
1707 }
1708
1709 int wxWindowMac::GetCharWidth() const
1710 {
1711 wxClientDC dc ( (wxWindowMac*)this ) ;
1712 return dc.GetCharWidth() ;
1713 }
1714
1715 void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y,
1716 int *descent, int *externalLeading, const wxFont *theFont ) const
1717 {
1718 const wxFont *fontToUse = theFont;
1719 if ( !fontToUse )
1720 fontToUse = &m_font;
1721
1722 wxClientDC dc( (wxWindowMac*) this ) ;
1723 long lx,ly,ld,le ;
1724 dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ;
1725 if ( externalLeading )
1726 *externalLeading = le ;
1727 if ( descent )
1728 *descent = ld ;
1729 if ( x )
1730 *x = lx ;
1731 if ( y )
1732 *y = ly ;
1733 }
1734
1735 /*
1736 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1737 * we always intersect with the entire window, not only with the client area
1738 */
1739
1740 void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect)
1741 {
1742 #if TARGET_API_MAC_OSX
1743 if ( rect == NULL )
1744 HIViewSetNeedsDisplay( (ControlRef) m_macControl , true ) ;
1745 else
1746 {
1747 RgnHandle update = NewRgn() ;
1748 SetRectRgn( update , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1749 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , update , update ) ;
1750 wxPoint origin = GetClientAreaOrigin() ;
1751 OffsetRgn( update, origin.x , origin.y ) ;
1752 HIViewSetNeedsDisplayInRegion( (ControlRef) m_macControl , update , true ) ;
1753 }
1754 #else
1755 /*
1756 RgnHandle updateRgn = NewRgn() ;
1757 if ( rect == NULL )
1758 {
1759 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1760 }
1761 else
1762 {
1763 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1764 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1765 }
1766 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1767 DisposeRgn(updateRgn) ;
1768 */
1769 if ( IsControlVisible( (ControlRef) m_macControl ) )
1770 {
1771 SetControlVisibility( (ControlRef) m_macControl , false , false ) ;
1772 SetControlVisibility( (ControlRef) m_macControl , true , true ) ;
1773 }
1774 /*
1775 if ( MacGetTopLevelWindow() == NULL )
1776 return ;
1777
1778 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1779 return ;
1780
1781 wxPoint client = GetClientAreaOrigin();
1782 int x1 = -client.x;
1783 int y1 = -client.y;
1784 int x2 = m_width - client.x;
1785 int y2 = m_height - client.y;
1786
1787 if (IsKindOf( CLASSINFO(wxButton)))
1788 {
1789 // buttons have an "aura"
1790 y1 -= 5;
1791 x1 -= 5;
1792 y2 += 5;
1793 x2 += 5;
1794 }
1795
1796 Rect clientrect = { y1, x1, y2, x2 };
1797
1798 if ( rect )
1799 {
1800 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1801 SectRect( &clientrect , &r , &clientrect ) ;
1802 }
1803
1804 if ( !EmptyRect( &clientrect ) )
1805 {
1806 int top = 0 , left = 0 ;
1807
1808 MacClientToRootWindow( &left , &top ) ;
1809 OffsetRect( &clientrect , left , top ) ;
1810
1811 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1812 }
1813 */
1814 #endif
1815 }
1816
1817 void wxWindowMac::Freeze()
1818 {
1819 #if TARGET_API_MAC_OSX
1820 if ( !m_frozenness++ )
1821 {
1822 HIViewSetDrawingEnabled( (HIViewRef) m_macControl , false ) ;
1823 }
1824 #endif
1825 }
1826
1827 void wxWindowMac::Thaw()
1828 {
1829 #if TARGET_API_MAC_OSX
1830 wxASSERT_MSG( m_frozenness > 0, _T("Thaw() without matching Freeze()") );
1831
1832 if ( !--m_frozenness )
1833 {
1834 HIViewSetDrawingEnabled( (HIViewRef) m_macControl , true ) ;
1835 HIViewSetNeedsDisplay( (HIViewRef) m_macControl , true ) ;
1836 }
1837 #endif
1838 }
1839
1840 void wxWindowMac::MacRedrawControl()
1841 {
1842 /*
1843 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
1844 {
1845 #if TARGET_API_MAC_CARBON
1846 Update() ;
1847 #else
1848 wxClientDC dc(this) ;
1849 wxMacPortSetter helper(&dc) ;
1850 wxMacWindowClipper clipper(this) ;
1851 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
1852 UMADrawControl( (ControlRef) m_macControl ) ;
1853 #endif
1854 }
1855 */
1856 }
1857
1858 /* TODO
1859 void wxWindowMac::OnPaint(wxPaintEvent& event)
1860 {
1861 // why don't we skip that here ?
1862 }
1863 */
1864
1865 wxWindowMac *wxGetActiveWindow()
1866 {
1867 // actually this is a windows-only concept
1868 return NULL;
1869 }
1870
1871 // Coordinates relative to the window
1872 void wxWindowMac::WarpPointer (int x_pos, int y_pos)
1873 {
1874 // We really don't move the mouse programmatically under Mac.
1875 }
1876
1877 void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
1878 {
1879 if ( m_macBackgroundBrush.Ok() == false || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT )
1880 {
1881 event.Skip() ;
1882 }
1883 else
1884 event.GetDC()->Clear() ;
1885 }
1886
1887 void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
1888 {
1889 wxWindowDC dc(this) ;
1890 wxMacPortSetter helper(&dc) ;
1891
1892 MacPaintBorders( dc.m_macLocalOrigin.x , dc.m_macLocalOrigin.y) ;
1893 }
1894
1895 int wxWindowMac::GetScrollPos(int orient) const
1896 {
1897 if ( orient == wxHORIZONTAL )
1898 {
1899 if ( m_hScrollBar )
1900 return m_hScrollBar->GetThumbPosition() ;
1901 }
1902 else
1903 {
1904 if ( m_vScrollBar )
1905 return m_vScrollBar->GetThumbPosition() ;
1906 }
1907 return 0;
1908 }
1909
1910 // This now returns the whole range, not just the number
1911 // of positions that we can scroll.
1912 int wxWindowMac::GetScrollRange(int orient) const
1913 {
1914 if ( orient == wxHORIZONTAL )
1915 {
1916 if ( m_hScrollBar )
1917 return m_hScrollBar->GetRange() ;
1918 }
1919 else
1920 {
1921 if ( m_vScrollBar )
1922 return m_vScrollBar->GetRange() ;
1923 }
1924 return 0;
1925 }
1926
1927 int wxWindowMac::GetScrollThumb(int orient) const
1928 {
1929 if ( orient == wxHORIZONTAL )
1930 {
1931 if ( m_hScrollBar )
1932 return m_hScrollBar->GetThumbSize() ;
1933 }
1934 else
1935 {
1936 if ( m_vScrollBar )
1937 return m_vScrollBar->GetThumbSize() ;
1938 }
1939 return 0;
1940 }
1941
1942 void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh)
1943 {
1944 if ( orient == wxHORIZONTAL )
1945 {
1946 if ( m_hScrollBar )
1947 m_hScrollBar->SetThumbPosition( pos ) ;
1948 }
1949 else
1950 {
1951 if ( m_vScrollBar )
1952 m_vScrollBar->SetThumbPosition( pos ) ;
1953 }
1954 }
1955
1956 void wxWindowMac::MacPaintBorders( int left , int top )
1957 {
1958 if( IsTopLevel() )
1959 return ;
1960
1961 int major,minor;
1962 wxGetOsVersion( &major, &minor );
1963
1964 RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ;
1965 RGBColor face = { 0xDDDD, 0xDDDD , 0xDDDD } ;
1966
1967 RGBColor darkShadow = { 0x0000, 0x0000 , 0x0000 } ;
1968 RGBColor lightShadow = { 0x4444, 0x4444 , 0x4444 } ;
1969 // OS X has lighter border edges than classic:
1970 if (major >= 10)
1971 {
1972 darkShadow.red = 0x8E8E;
1973 darkShadow.green = 0x8E8E;
1974 darkShadow.blue = 0x8E8E;
1975 lightShadow.red = 0xBDBD;
1976 lightShadow.green = 0xBDBD;
1977 lightShadow.blue = 0xBDBD;
1978 }
1979
1980 PenNormal() ;
1981
1982 int w , h ;
1983 GetSize( &w , &h ) ;
1984 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
1985 {
1986 #if wxMAC_USE_THEME_BORDER
1987 Rect rect = { top , left , m_height + top , m_width + left } ;
1988 SInt32 border = 0 ;
1989 /*
1990 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1991 InsetRect( &rect , border , border );
1992 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1993 */
1994
1995 DrawThemePrimaryGroup(&rect ,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1996 #else
1997 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1998 RGBForeColor( &face );
1999 MoveTo( left + 0 , top + h - 2 );
2000 LineTo( left + 0 , top + 0 );
2001 LineTo( left + w - 2 , top + 0 );
2002
2003 MoveTo( left + 2 , top + h - 3 );
2004 LineTo( left + w - 3 , top + h - 3 );
2005 LineTo( left + w - 3 , top + 2 );
2006
2007 RGBForeColor( sunken ? &face : &darkShadow );
2008 MoveTo( left + 0 , top + h - 1 );
2009 LineTo( left + w - 1 , top + h - 1 );
2010 LineTo( left + w - 1 , top + 0 );
2011
2012 RGBForeColor( sunken ? &lightShadow : &white );
2013 MoveTo( left + 1 , top + h - 3 );
2014 LineTo( left + 1, top + 1 );
2015 LineTo( left + w - 3 , top + 1 );
2016
2017 RGBForeColor( sunken ? &white : &lightShadow );
2018 MoveTo( left + 1 , top + h - 2 );
2019 LineTo( left + w - 2 , top + h - 2 );
2020 LineTo( left + w - 2 , top + 1 );
2021
2022 RGBForeColor( sunken ? &darkShadow : &face );
2023 MoveTo( left + 2 , top + h - 4 );
2024 LineTo( left + 2 , top + 2 );
2025 LineTo( left + w - 4 , top + 2 );
2026 #endif
2027 }
2028 else if (HasFlag(wxSIMPLE_BORDER))
2029 {
2030 Rect rect = { top , left , h + top , w + left } ;
2031 RGBForeColor( &darkShadow ) ;
2032 FrameRect( &rect ) ;
2033 }
2034 }
2035
2036 void wxWindowMac::RemoveChild( wxWindowBase *child )
2037 {
2038 if ( child == m_hScrollBar )
2039 m_hScrollBar = NULL ;
2040 if ( child == m_vScrollBar )
2041 m_vScrollBar = NULL ;
2042
2043 wxWindowBase::RemoveChild( child ) ;
2044 }
2045
2046 // New function that will replace some of the above.
2047 void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible,
2048 int range, bool refresh)
2049 {
2050 if ( orient == wxHORIZONTAL )
2051 {
2052 if ( m_hScrollBar )
2053 {
2054 if ( range == 0 || thumbVisible >= range )
2055 {
2056 if ( m_hScrollBar->IsShown() )
2057 m_hScrollBar->Show(false) ;
2058 }
2059 else
2060 {
2061 if ( !m_hScrollBar->IsShown() )
2062 m_hScrollBar->Show(true) ;
2063 m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
2064 }
2065 }
2066 }
2067 else
2068 {
2069 if ( m_vScrollBar )
2070 {
2071 if ( range == 0 || thumbVisible >= range )
2072 {
2073 if ( m_vScrollBar->IsShown() )
2074 m_vScrollBar->Show(false) ;
2075 }
2076 else
2077 {
2078 if ( !m_vScrollBar->IsShown() )
2079 m_vScrollBar->Show(true) ;
2080 m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
2081 }
2082 }
2083 }
2084 MacRepositionScrollBars() ;
2085 }
2086
2087 // Does a physical scroll
2088 void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
2089 {
2090 if( dx == 0 && dy ==0 )
2091 return ;
2092
2093
2094 {
2095 wxClientDC dc(this) ;
2096 wxMacPortSetter helper(&dc) ;
2097
2098 int width , height ;
2099 GetClientSize( &width , &height ) ;
2100
2101
2102 wxPoint pos;
2103 pos.x = pos.y = 0;
2104
2105 Rect scrollrect;
2106 // TODO take out the boundaries
2107 GetControlBounds( (ControlRef) m_macControl, &scrollrect);
2108
2109 RgnHandle updateRgn = NewRgn() ;
2110 if ( rect )
2111 {
2112 Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) ,
2113 dc.XLOG2DEVMAC(rect->x + rect->width) } ;
2114 SectRect( &scrollrect , &r , &scrollrect ) ;
2115 }
2116 ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
2117 #if TARGET_CARBON
2118 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
2119 // but it seems the update only refreshes the background of the control, rather than calling
2120 // kEventControlDraw, so we need to force a proper update here. There has to be a better
2121 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
2122 Update();
2123 #endif
2124 // we also have to scroll the update rgn in this rectangle
2125 // in order not to loose updates
2126 #if !TARGET_CARBON
2127 WindowRef rootWindow = (WindowRef) MacGetTopLevelWindowRef() ;
2128 RgnHandle formerUpdateRgn = NewRgn() ;
2129 RgnHandle scrollRgn = NewRgn() ;
2130 RectRgn( scrollRgn , &scrollrect ) ;
2131 GetWindowUpdateRgn( rootWindow , formerUpdateRgn ) ;
2132 Point pt = {0,0} ;
2133 LocalToGlobal( &pt ) ;
2134 OffsetRgn( formerUpdateRgn , -pt.h , -pt.v ) ;
2135 SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
2136 if ( !EmptyRgn( formerUpdateRgn ) )
2137 {
2138 MacOffsetRgn( formerUpdateRgn , dx , dy ) ;
2139 SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
2140 InvalWindowRgn(rootWindow , formerUpdateRgn ) ;
2141 }
2142 InvalWindowRgn(rootWindow , updateRgn ) ;
2143 DisposeRgn( updateRgn ) ;
2144 DisposeRgn( formerUpdateRgn ) ;
2145 DisposeRgn( scrollRgn ) ;
2146 #endif
2147 }
2148
2149 for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())
2150 {
2151 wxWindowMac *child = node->GetData();
2152 if (child == m_vScrollBar) continue;
2153 if (child == m_hScrollBar) continue;
2154 if (child->IsTopLevel()) continue;
2155
2156 int x,y;
2157 child->GetPosition( &x, &y );
2158 int w,h;
2159 child->GetSize( &w, &h );
2160 if (rect)
2161 {
2162 wxRect rc(x,y,w,h);
2163 if (rect->Intersects(rc))
2164 child->SetSize( x+dx, y+dy, w, h );
2165 }
2166 else
2167 {
2168 child->SetSize( x+dx, y+dy, w, h );
2169 }
2170 }
2171
2172 // TODO remove, was moved higher up Update() ;
2173
2174 }
2175
2176 void wxWindowMac::MacOnScroll(wxScrollEvent &event )
2177 {
2178 if ( event.m_eventObject == m_vScrollBar || event.m_eventObject == m_hScrollBar )
2179 {
2180 wxScrollWinEvent wevent;
2181 wevent.SetPosition(event.GetPosition());
2182 wevent.SetOrientation(event.GetOrientation());
2183 wevent.m_eventObject = this;
2184
2185 if (event.m_eventType == wxEVT_SCROLL_TOP)
2186 wevent.m_eventType = wxEVT_SCROLLWIN_TOP;
2187 else if (event.m_eventType == wxEVT_SCROLL_BOTTOM)
2188 wevent.m_eventType = wxEVT_SCROLLWIN_BOTTOM;
2189 else if (event.m_eventType == wxEVT_SCROLL_LINEUP)
2190 wevent.m_eventType = wxEVT_SCROLLWIN_LINEUP;
2191 else if (event.m_eventType == wxEVT_SCROLL_LINEDOWN)
2192 wevent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
2193 else if (event.m_eventType == wxEVT_SCROLL_PAGEUP)
2194 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEUP;
2195 else if (event.m_eventType == wxEVT_SCROLL_PAGEDOWN)
2196 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
2197 else if (event.m_eventType == wxEVT_SCROLL_THUMBTRACK)
2198 wevent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
2199 else if (event.m_eventType == wxEVT_SCROLL_THUMBRELEASE)
2200 wevent.m_eventType = wxEVT_SCROLLWIN_THUMBRELEASE;
2201
2202 GetEventHandler()->ProcessEvent(wevent);
2203 }
2204 }
2205
2206 // Get the window with the focus
2207 wxWindowMac *wxWindowBase::FindFocus()
2208 {
2209 return gFocusWindow ;
2210 }
2211
2212 void wxWindowMac::OnSetFocus(wxFocusEvent& event)
2213 {
2214 // panel wants to track the window which was the last to have focus in it,
2215 // so we want to set ourselves as the window which last had focus
2216 //
2217 // notice that it's also important to do it upwards the tree becaus
2218 // otherwise when the top level panel gets focus, it won't set it back to
2219 // us, but to some other sibling
2220
2221 // CS:don't know if this is still needed:
2222 //wxChildFocusEvent eventFocus(this);
2223 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2224
2225 event.Skip();
2226 }
2227
2228 void wxWindowMac::OnInternalIdle()
2229 {
2230 // This calls the UI-update mechanism (querying windows for
2231 // menu/toolbar/control state information)
2232 if (wxUpdateUIEvent::CanUpdate(this))
2233 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
2234 }
2235
2236 // Raise the window to the top of the Z order
2237 void wxWindowMac::Raise()
2238 {
2239 }
2240
2241 // Lower the window to the bottom of the Z order
2242 void wxWindowMac::Lower()
2243 {
2244 }
2245
2246
2247 // static wxWindow *gs_lastWhich = NULL;
2248
2249 bool wxWindowMac::MacSetupCursor( const wxPoint& pt)
2250 {
2251 // first trigger a set cursor event
2252
2253 wxPoint clientorigin = GetClientAreaOrigin() ;
2254 wxSize clientsize = GetClientSize() ;
2255 wxCursor cursor ;
2256 if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) )
2257 {
2258 wxSetCursorEvent event( pt.x , pt.y );
2259
2260 bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event);
2261 if ( processedEvtSetCursor && event.HasCursor() )
2262 {
2263 cursor = event.GetCursor() ;
2264 }
2265 else
2266 {
2267
2268 // the test for processedEvtSetCursor is here to prevent using m_cursor
2269 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2270 // it - this is a way to say that our cursor shouldn't be used for this
2271 // point
2272 if ( !processedEvtSetCursor && m_cursor.Ok() )
2273 {
2274 cursor = m_cursor ;
2275 }
2276 if ( wxIsBusy() )
2277 {
2278 }
2279 else
2280 {
2281 if ( !GetParent() )
2282 cursor = *wxSTANDARD_CURSOR ;
2283 }
2284 }
2285 if ( cursor.Ok() )
2286 cursor.MacInstall() ;
2287 }
2288 return cursor.Ok() ;
2289 }
2290
2291 wxString wxWindowMac::MacGetToolTipString( wxPoint &pt )
2292 {
2293 if ( m_tooltip )
2294 {
2295 return m_tooltip->GetTip() ;
2296 }
2297 return wxEmptyString ;
2298 }
2299
2300 void wxWindowMac::Update()
2301 {
2302 #if TARGET_API_MAC_OSX
2303 HIViewSetNeedsDisplay( (ControlRef) m_macControl , true ) ;
2304 #else
2305 ::Draw1Control( (ControlRef) m_macControl ) ;
2306 #endif
2307 }
2308
2309 wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const
2310 {
2311 wxTopLevelWindowMac* win = NULL ;
2312 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
2313 if ( window )
2314 {
2315 win = wxFindWinFromMacWindow( window ) ;
2316 }
2317 return win ;
2318 }
2319 wxRegion wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures )
2320 {
2321
2322 Rect r ;
2323 RgnHandle visRgn = NewRgn() ;
2324 RgnHandle tempRgn = NewRgn() ;
2325 if ( IsControlVisible( (ControlRef) m_macControl ) )
2326 {
2327 GetControlBounds( (ControlRef) m_macControl , &r ) ;
2328 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2329 {
2330 MacRootWindowToWindow( &r.left , & r.top ) ;
2331 MacRootWindowToWindow( &r.right , & r.bottom ) ;
2332 }
2333 else
2334 {
2335 r.right -= r.left ;
2336 r.bottom -= r.top ;
2337 r.left = 0 ;
2338 r.top = 0 ;
2339 }
2340 if ( includeOuterStructures )
2341 InsetRect( &r , -3 , -3 ) ;
2342 RectRgn( visRgn , &r ) ;
2343 if ( !IsTopLevel() )
2344 {
2345 wxWindow* child = this ;
2346 wxWindow* parent = child->GetParent() ;
2347 while( parent )
2348 {
2349 int x , y ;
2350 wxSize size ;
2351 // we have to find a better clipping algorithm here, in order not to clip things
2352 // positioned like status and toolbar
2353 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2354 {
2355 size = parent->GetSize() ;
2356 x = y = 0 ;
2357 }
2358 else
2359 {
2360 size = parent->GetClientSize() ;
2361 wxPoint origin = parent->GetClientAreaOrigin() ;
2362 x = origin.x ;
2363 y = origin.y ;
2364 }
2365 parent->MacWindowToRootWindow( &x, &y ) ;
2366 MacRootWindowToWindow( &x , &y ) ;
2367
2368 SetRectRgn( tempRgn ,
2369 x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() ,
2370 x + size.x - parent->MacGetRightBorderSize(),
2371 y + size.y - parent->MacGetBottomBorderSize()) ;
2372
2373 SectRgn( visRgn , tempRgn , visRgn ) ;
2374 if ( parent->IsTopLevel() )
2375 break ;
2376 child = parent ;
2377 parent = child->GetParent() ;
2378 }
2379 }
2380 }
2381
2382 wxRegion vis = visRgn ;
2383 DisposeRgn( visRgn ) ;
2384 DisposeRgn( tempRgn ) ;
2385 return vis ;
2386 }
2387
2388 /*
2389 This function must not change the updatergn !
2390 */
2391 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time )
2392 {
2393 // we let the OS handle root control redraws
2394 if ( m_macControl == MacGetTopLevelWindow()->GetHandle() )
2395 return false ;
2396
2397 RgnHandle updatergn = (RgnHandle) updatergnr ;
2398 bool handled = false ;
2399
2400 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2401 {
2402 RgnHandle newupdate = NewRgn() ;
2403 wxSize point = GetClientSize() ;
2404 wxPoint origin = GetClientAreaOrigin() ;
2405 SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ;
2406 SectRgn( newupdate , updatergn , newupdate ) ;
2407 OffsetRgn( newupdate , -origin.x , -origin.y ) ;
2408 m_updateRegion = newupdate ;
2409 DisposeRgn( newupdate ) ;
2410 }
2411
2412 if ( !EmptyRgn(updatergn) )
2413 {
2414 wxWindowDC dc(this);
2415 if (!EmptyRgn(updatergn))
2416 dc.SetClippingRegion(wxRegion(updatergn));
2417
2418 wxEraseEvent eevent( GetId(), &dc );
2419 eevent.SetEventObject( this );
2420 GetEventHandler()->ProcessEvent( eevent );
2421
2422 if ( !m_updateRegion.Empty() )
2423 {
2424 // paint the window itself
2425 wxPaintEvent event;
2426 event.m_timeStamp = time ;
2427 event.SetEventObject(this);
2428 handled = GetEventHandler()->ProcessEvent(event);
2429
2430 // paint custom borders
2431 wxNcPaintEvent eventNc( GetId() );
2432 eventNc.SetEventObject( this );
2433 GetEventHandler()->ProcessEvent( eventNc );
2434 }
2435 }
2436 return handled ;
2437 }
2438
2439 void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase)
2440 {
2441 RgnHandle updatergn = (RgnHandle) updatergnr ;
2442 // updatergn is always already clipped to our boundaries
2443 // if we are in compositing mode then it is in relative to the upper left of the control
2444 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2445 // of the toplevel window
2446 // it is in window coordinates, not in client coordinates
2447
2448 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2449 RgnHandle ownUpdateRgn = NewRgn() ;
2450 CopyRgn( updatergn , ownUpdateRgn ) ;
2451
2452 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2453 {
2454 Rect bounds;
2455 UMAGetControlBoundsInWindowCoords( (ControlRef)m_macControl, &bounds );
2456 RgnHandle controlRgn = NewRgn();
2457 RectRgn( controlRgn, &bounds );
2458 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2459 // the window update region
2460 SectRgn( ownUpdateRgn, controlRgn, ownUpdateRgn );
2461 DisposeRgn( controlRgn );
2462
2463 //KO: convert ownUpdateRgn to local coordinates
2464 OffsetRgn( ownUpdateRgn, -bounds.left, -bounds.top );
2465 }
2466
2467 MacDoRedraw( ownUpdateRgn , time ) ;
2468 DisposeRgn( ownUpdateRgn ) ;
2469
2470 }
2471
2472 WXWindow wxWindowMac::MacGetTopLevelWindowRef() const
2473 {
2474 wxWindowMac *iter = (wxWindowMac*)this ;
2475
2476 while( iter )
2477 {
2478 if ( iter->IsTopLevel() )
2479 return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ;
2480
2481 iter = iter->GetParent() ;
2482 }
2483 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2484 return NULL ;
2485 }
2486
2487 void wxWindowMac::MacCreateScrollBars( long style )
2488 {
2489 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ;
2490
2491 bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
2492 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ;
2493 int width, height ;
2494 GetClientSize( &width , &height ) ;
2495
2496 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
2497 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
2498 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
2499 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
2500
2501 m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint,
2502 vSize , wxVERTICAL);
2503
2504 if ( style & wxVSCROLL )
2505 {
2506
2507 }
2508 else
2509 {
2510 m_vScrollBar->Show(false) ;
2511 }
2512 m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint,
2513 hSize , wxHORIZONTAL);
2514 if ( style & wxHSCROLL )
2515 {
2516 }
2517 else
2518 {
2519 m_hScrollBar->Show(false) ;
2520 }
2521
2522 // because the create does not take into account the client area origin
2523 MacRepositionScrollBars() ; // we might have a real position shift
2524 }
2525
2526 void wxWindowMac::MacRepositionScrollBars()
2527 {
2528 bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
2529 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ;
2530
2531 // get real client area
2532
2533 int width ;
2534 int height ;
2535 GetSize( &width , &height ) ;
2536
2537 width -= MacGetLeftBorderSize() + MacGetRightBorderSize();
2538 height -= MacGetTopBorderSize() + MacGetBottomBorderSize();
2539
2540 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
2541 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
2542 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
2543 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
2544
2545 int x = 0 ;
2546 int y = 0 ;
2547 int w ;
2548 int h ;
2549 GetSize( &w , &h ) ;
2550
2551 MacClientToRootWindow( &x , &y ) ;
2552 MacClientToRootWindow( &w , &h ) ;
2553
2554 wxWindowMac *iter = (wxWindowMac*)this ;
2555
2556 int totW = 10000 , totH = 10000;
2557 while( iter )
2558 {
2559 if ( iter->IsTopLevel() )
2560 {
2561 iter->GetSize( &totW , &totH ) ;
2562 break ;
2563 }
2564
2565 iter = iter->GetParent() ;
2566 }
2567
2568 if ( x == 0 )
2569 {
2570 hPoint.x = -1 ;
2571 hSize.x += 1 ;
2572 }
2573 if ( y == 0 )
2574 {
2575 vPoint.y = -1 ;
2576 vSize.y += 1 ;
2577 }
2578
2579 if ( w-x >= totW )
2580 {
2581 hSize.x += 1 ;
2582 vPoint.x += 1 ;
2583 }
2584
2585 if ( h-y >= totH )
2586 {
2587 vSize.y += 1 ;
2588 hPoint.y += 1 ;
2589 }
2590
2591 if ( m_vScrollBar )
2592 {
2593 m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE);
2594 }
2595 if ( m_hScrollBar )
2596 {
2597 m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE);
2598 }
2599 }
2600
2601 bool wxWindowMac::AcceptsFocus() const
2602 {
2603 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2604 }
2605
2606 void wxWindowMac::MacSuperChangedPosition()
2607 {
2608 // only window-absolute structures have to be moved i.e. controls
2609
2610 wxWindowListNode *node = GetChildren().GetFirst();
2611 while ( node )
2612 {
2613 wxWindowMac *child = node->GetData();
2614 child->MacSuperChangedPosition() ;
2615 node = node->GetNext();
2616 }
2617 }
2618
2619 void wxWindowMac::MacTopLevelWindowChangedPosition()
2620 {
2621 // only screen-absolute structures have to be moved i.e. glcanvas
2622
2623 wxWindowListNode *node = GetChildren().GetFirst();
2624 while ( node )
2625 {
2626 wxWindowMac *child = node->GetData();
2627 child->MacTopLevelWindowChangedPosition() ;
2628 node = node->GetNext();
2629 }
2630 }
2631
2632 long wxWindowMac::MacGetLeftBorderSize( ) const
2633 {
2634 if( IsTopLevel() )
2635 return 0 ;
2636
2637 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
2638 {
2639 SInt32 border = 3 ;
2640 #if wxMAC_USE_THEME_BORDER
2641 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2642 #endif
2643 return border ;
2644 }
2645 else if ( m_windowStyle &wxDOUBLE_BORDER)
2646 {
2647 SInt32 border = 3 ;
2648 #if wxMAC_USE_THEME_BORDER
2649 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2650 #endif
2651 return border ;
2652 }
2653 else if (m_windowStyle &wxSIMPLE_BORDER)
2654 {
2655 return 1 ;
2656 }
2657 return 0 ;
2658 }
2659
2660 long wxWindowMac::MacGetRightBorderSize( ) const
2661 {
2662 // they are all symmetric in mac themes
2663 return MacGetLeftBorderSize() ;
2664 }
2665
2666 long wxWindowMac::MacGetTopBorderSize( ) const
2667 {
2668 // they are all symmetric in mac themes
2669 return MacGetLeftBorderSize() ;
2670 }
2671
2672 long wxWindowMac::MacGetBottomBorderSize( ) const
2673 {
2674 // they are all symmetric in mac themes
2675 return MacGetLeftBorderSize() ;
2676 }
2677
2678 long wxWindowMac::MacRemoveBordersFromStyle( long style )
2679 {
2680 return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ;
2681 }
2682
2683 // Find the wxWindowMac at the current mouse position, returning the mouse
2684 // position.
2685 wxWindowMac* wxFindWindowAtPointer(wxPoint& pt)
2686 {
2687 pt = wxGetMousePosition();
2688 wxWindowMac* found = wxFindWindowAtPoint(pt);
2689 return found;
2690 }
2691
2692 // Get the current mouse position.
2693 wxPoint wxGetMousePosition()
2694 {
2695 int x, y;
2696 wxGetMousePosition(& x, & y);
2697 return wxPoint(x, y);
2698 }
2699
2700 void wxWindowMac::OnMouseEvent( wxMouseEvent &event )
2701 {
2702 if ( event.GetEventType() == wxEVT_RIGHT_DOWN )
2703 {
2704 // copied from wxGTK : CS
2705 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2706 // except that:
2707 //
2708 // (a) it's a command event and so is propagated to the parent
2709 // (b) under MSW it can be generated from kbd too
2710 // (c) it uses screen coords (because of (a))
2711 wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU,
2712 this->GetId(),
2713 this->ClientToScreen(event.GetPosition()));
2714 if ( ! GetEventHandler()->ProcessEvent(evtCtx) )
2715 event.Skip() ;
2716 }
2717 else if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK )
2718 {
2719
2720 int x = event.m_x ;
2721 int y = event.m_y ;
2722
2723 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2724 {
2725 // OS Needs it in tlw content area coordinates
2726 MacClientToRootWindow( &x , &y ) ;
2727 }
2728 else
2729 {
2730 // OS Needs it in window not client coordinates
2731 wxPoint origin = GetClientAreaOrigin() ;
2732 x += origin.x ;
2733 y += origin.y ;
2734 }
2735 Point localwhere ;
2736 SInt16 controlpart ;
2737
2738 localwhere.h = x ;
2739 localwhere.v = y ;
2740
2741 short modifiers = 0;
2742
2743 if ( !event.m_leftDown && !event.m_rightDown )
2744 modifiers |= btnState ;
2745
2746 if ( event.m_shiftDown )
2747 modifiers |= shiftKey ;
2748
2749 if ( event.m_controlDown )
2750 modifiers |= controlKey ;
2751
2752 if ( event.m_altDown )
2753 modifiers |= optionKey ;
2754
2755 if ( event.m_metaDown )
2756 modifiers |= cmdKey ;
2757
2758 bool handled = false ;
2759
2760 if ( ::IsControlActive( (ControlRef) m_macControl ) )
2761 {
2762 controlpart = ::HandleControlClick( (ControlRef) m_macControl , localwhere , modifiers , (ControlActionUPP) -1 ) ;
2763 wxTheApp->s_lastMouseDown = 0 ;
2764 if ( controlpart != kControlNoPart )
2765 {
2766 MacHandleControlClick((WXWidget) (ControlRef) m_macControl , controlpart , false /* mouse not down anymore */ ) ;
2767 handled = true ;
2768 }
2769 }
2770 if ( !handled )
2771 event.Skip() ;
2772 }
2773 else
2774 {
2775 event.Skip() ;
2776 }
2777 }
2778
2779 void wxWindowMac::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) )
2780 {
2781 wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ;
2782 }
2783
2784 Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin )
2785 {
2786 int x ,y , w ,h ;
2787
2788 window->MacGetBoundsForControl( pos , size , x , y, w, h , adjustForOrigin) ;
2789 Rect bounds = { y , x , y+h , x+w };
2790 return bounds ;
2791 }
2792
2793