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