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