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