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