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