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