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