]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/carbon/window.cpp
ryan's QT implementation
[wxWidgets.git] / src / mac / carbon / window.cpp
... / ...
CommitLineData
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
71extern 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
81BEGIN_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)
90END_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
105extern long wxMacTranslateKey(unsigned char key, unsigned char code) ;
106pascal 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
111enum {
112 kEventControlVisibilityChanged = 157
113};
114#endif
115
116#endif
117
118static 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
137static 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
250static 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
328pascal 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
345DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler )
346
347// ---------------------------------------------------------------------------
348// UserPane events for non OSX builds
349// ---------------------------------------------------------------------------
350
351static 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
358static 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
365static 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
372static 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
379static 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
386static 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
393static 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
400static 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
407void 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
417wxInt16 wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y)
418{
419 return kControlNoPart ;
420}
421
422wxInt16 wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc)
423{
424 return kControlNoPart ;
425}
426
427void wxWindowMac::MacControlUserPaneIdleProc()
428{
429}
430
431wxInt16 wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers)
432{
433 return kControlNoPart ;
434}
435
436void wxWindowMac::MacControlUserPaneActivateProc(bool activating)
437{
438}
439
440wxInt16 wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action)
441{
442 return kControlNoPart ;
443}
444
445void wxWindowMac::MacControlUserPaneBackgroundProc(void* info)
446{
447}
448
449ControlUserPaneDrawUPP gControlUserPaneDrawUPP = NULL ;
450ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP = NULL ;
451ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP = NULL ;
452ControlUserPaneIdleUPP gControlUserPaneIdleUPP = NULL ;
453ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP = NULL ;
454ControlUserPaneActivateUPP gControlUserPaneActivateUPP = NULL ;
455ControlUserPaneFocusUPP gControlUserPaneFocusUPP = NULL ;
456ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP = NULL ;
457
458// ===========================================================================
459// implementation
460// ===========================================================================
461
462wxList wxWinMacControlList(wxKEY_INTEGER);
463
464wxWindow *wxFindControlFromMacControl(ControlRef inControl )
465{
466 wxNode *node = wxWinMacControlList.Find((long)inControl);
467 if (!node)
468 return NULL;
469 return (wxControl *)node->GetData();
470}
471
472void 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
482void wxRemoveMacControlAssociation(wxWindow *control)
483{
484 wxWinMacControlList.DeleteObject(control);
485}
486
487// UPP functions
488ControlActionUPP wxMacLiveScrollbarActionUPP = NULL ;
489
490ControlColorUPP 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
496pascal 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
540pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode partCode ) ;
541pascal 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
557wxWindowMac::wxWindowMac()
558{
559 Init();
560}
561
562wxWindowMac::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
573void 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
618wxWindowMac::~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
683WXWidget wxWindowMac::GetHandle() const
684{
685 return (WXWidget) m_peer->GetControlRef() ;
686}
687
688
689void 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
699bool 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
760void 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
790void 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
846void wxWindowMac::MacUpdateControlFont()
847{
848 m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
849 Refresh() ;
850}
851
852bool wxWindowMac::SetFont(const wxFont& font)
853{
854 bool retval = !wxWindowBase::SetFont( font ) ;
855
856 MacUpdateControlFont() ;
857
858 return retval;
859}
860
861bool wxWindowMac::SetForegroundColour(const wxColour& col )
862{
863 if ( !wxWindowBase::SetForegroundColour(col) )
864 return false ;
865
866 MacUpdateControlFont() ;
867
868 return true ;
869}
870
871bool 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 return true ;
893}
894
895void wxWindowMac::MacSetBackgroundBrush( const wxBrush &brush )
896{
897 m_macBackgroundBrush = brush ;
898 m_peer->SetBackground( brush ) ;
899}
900
901bool wxWindowMac::MacCanFocus() const
902{
903 // there is currently no way to determine whether the window is running in full keyboard
904 // access mode, therefore we cannot rely on these features, yet the only other way would be
905 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
906 // in event handlers...
907 UInt32 features = 0 ;
908 m_peer->GetFeatures( & features ) ;
909 return features & ( kControlSupportsFocus | kControlGetsFocusOnClick ) ;
910}
911
912
913void wxWindowMac::SetFocus()
914{
915 if ( AcceptsFocus() )
916 {
917#if !TARGET_API_MAC_OSX
918 wxWindow* former = FindFocus() ;
919#endif
920 OSStatus err = m_peer->SetFocus( kControlFocusNextPart ) ;
921 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
922 // leave in case of an error
923 if ( err == errCouldntSetFocus )
924 return ;
925
926#if !TARGET_API_MAC_OSX
927 // emulate carbon events when running under carbonlib where they are not natively available
928 if ( former )
929 {
930 EventRef evRef = NULL ;
931 verify_noerr( MacCreateEvent( NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , kEventAttributeUserEvent ,
932 &evRef ) );
933
934 wxMacCarbonEvent cEvent( evRef ) ;
935 cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) former->GetHandle() ) ;
936 cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNoPart ) ;
937
938 wxMacWindowEventHandler( NULL , evRef , former ) ;
939 ReleaseEvent(evRef) ;
940 }
941 // send new focus event
942 {
943 EventRef evRef = NULL ;
944 verify_noerr( MacCreateEvent( NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , kEventAttributeUserEvent ,
945 &evRef ) );
946
947 wxMacCarbonEvent cEvent( evRef ) ;
948 cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) GetHandle() ) ;
949 cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNextPart ) ;
950
951 wxMacWindowEventHandler( NULL , evRef , this ) ;
952 ReleaseEvent(evRef) ;
953 }
954#endif
955 }
956}
957
958
959void wxWindowMac::DoCaptureMouse()
960{
961 wxTheApp->s_captureWindow = this ;
962}
963
964wxWindow* wxWindowBase::GetCapture()
965{
966 return wxTheApp->s_captureWindow ;
967}
968
969void wxWindowMac::DoReleaseMouse()
970{
971 wxTheApp->s_captureWindow = NULL ;
972}
973
974#if wxUSE_DRAG_AND_DROP
975
976void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget)
977{
978 if ( m_dropTarget != 0 ) {
979 delete m_dropTarget;
980 }
981
982 m_dropTarget = pDropTarget;
983 if ( m_dropTarget != 0 )
984 {
985 // TODO
986 }
987}
988
989#endif
990
991// Old style file-manager drag&drop
992void wxWindowMac::DragAcceptFiles(bool accept)
993{
994 // TODO
995}
996
997void wxWindowMac::MacGetPositionAndSizeFromControl(int& x, int& y,
998 int& w, int& h) const
999{
1000 Rect bounds ;
1001 m_peer->GetRect( &bounds ) ;
1002
1003
1004 x = bounds.left ;
1005 y = bounds.top ;
1006 w = bounds.right - bounds.left ;
1007 h = bounds.bottom - bounds.top ;
1008
1009 wxTopLevelWindow* tlw = wxDynamicCast( this , wxTopLevelWindow ) ;
1010 if ( tlw )
1011 {
1012 Point tlworigin = { 0 , 0 } ;
1013 QDLocalToGlobalPoint( UMAGetWindowPort( (WindowRef) tlw->MacGetWindowRef() ) , &tlworigin ) ;
1014 x = tlworigin.h ;
1015 y = tlworigin.v ;
1016 }
1017}
1018
1019bool wxWindowMac::MacGetBoundsForControl(const wxPoint& pos,
1020 const wxSize& size,
1021 int& x, int& y,
1022 int& w, int& h , bool adjustOrigin ) const
1023{
1024 // the desired size, minus the border pixels gives the correct size of the control
1025
1026 x = (int)pos.x;
1027 y = (int)pos.y;
1028 // todo the default calls may be used as soon as PostCreateControl Is moved here
1029 w = size.x ; // WidthDefault( size.x );
1030 h = size.y ; // HeightDefault( size.y ) ;
1031#if !TARGET_API_MAC_OSX
1032 GetParent()->MacWindowToRootWindow( &x , &y ) ;
1033#endif
1034
1035 x += MacGetLeftBorderSize() ;
1036 y += MacGetTopBorderSize() ;
1037 w -= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1038 h -= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1039
1040 if ( adjustOrigin )
1041 AdjustForParentClientOrigin( x , y ) ;
1042 return true ;
1043}
1044
1045// Get total size
1046void wxWindowMac::DoGetSize(int *x, int *y) const
1047{
1048 // take the size of the control and add the borders that have to be drawn outside
1049 int x1 , y1 , w1 ,h1 ;
1050#if TARGET_API_MAC_OSX
1051 MacGetPositionAndSizeFromControl( x1 , y1, w1 ,h1 ) ;
1052
1053#else
1054 Rect bounds ;
1055 m_peer->GetRect( &bounds ) ;
1056 w1 = bounds.right - bounds.left ;
1057 h1 = bounds.bottom - bounds.top ;
1058#endif
1059 w1 += MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1060 h1 += MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1061
1062 if(x) *x = w1 ;
1063 if(y) *y = h1 ;
1064}
1065
1066void wxWindowMac::DoGetPosition(int *x, int *y) const
1067{
1068 #if TARGET_API_MAC_OSX
1069 int x1 , y1 , w1 ,h1 ;
1070 MacGetPositionAndSizeFromControl( x1 , y1, w1 ,h1 ) ;
1071 x1 -= MacGetLeftBorderSize() ;
1072 y1 -= MacGetTopBorderSize() ;
1073 if ( !IsTopLevel() )
1074 {
1075 wxWindow *parent = GetParent();
1076 if ( parent )
1077 {
1078 wxPoint pt(parent->GetClientAreaOrigin());
1079 x1 -= pt.x ;
1080 y1 -= pt.y ;
1081 }
1082 }
1083 if(x) *x = x1 ;
1084 if(y) *y = y1 ;
1085 #else
1086 Rect bounds ;
1087 m_peer->GetRect( &bounds ) ;
1088 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
1089
1090 int xx = bounds.left ;
1091 int yy = bounds.top ;
1092 xx -= MacGetLeftBorderSize() ;
1093 yy -= MacGetTopBorderSize() ;
1094
1095 if ( !GetParent()->IsTopLevel() )
1096 {
1097 GetControlBounds( (ControlRef) GetParent()->GetHandle() , &bounds ) ;
1098
1099 xx -= bounds.left ;
1100 yy -= bounds.top ;
1101 }
1102
1103 wxPoint pt(GetParent()->GetClientAreaOrigin());
1104 xx -= pt.x;
1105 yy -= pt.y;
1106
1107 if(x) *x = xx;
1108 if(y) *y = yy;
1109#endif
1110}
1111
1112void wxWindowMac::DoScreenToClient(int *x, int *y) const
1113{
1114 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
1115
1116 wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ;
1117
1118 {
1119 Point localwhere = {0,0} ;
1120
1121 if(x) localwhere.h = * x ;
1122 if(y) localwhere.v = * y ;
1123
1124 QDGlobalToLocalPoint( GetWindowPort( window ) , &localwhere ) ;
1125 if(x) *x = localwhere.h ;
1126 if(y) *y = localwhere.v ;
1127
1128 }
1129 MacRootWindowToWindow( x , y ) ;
1130
1131 wxPoint origin = GetClientAreaOrigin() ;
1132 if(x) *x -= origin.x ;
1133 if(y) *y -= origin.y ;
1134}
1135
1136void wxWindowMac::DoClientToScreen(int *x, int *y) const
1137{
1138 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
1139 wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ;
1140
1141 wxPoint origin = GetClientAreaOrigin() ;
1142 if(x) *x += origin.x ;
1143 if(y) *y += origin.y ;
1144
1145 MacWindowToRootWindow( x , y ) ;
1146
1147 {
1148 Point localwhere = { 0,0 };
1149 if(x) localwhere.h = * x ;
1150 if(y) localwhere.v = * y ;
1151 QDLocalToGlobalPoint( GetWindowPort( window ) , &localwhere ) ;
1152 if(x) *x = localwhere.h ;
1153 if(y) *y = localwhere.v ;
1154 }
1155}
1156
1157void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const
1158{
1159 wxPoint origin = GetClientAreaOrigin() ;
1160 if(x) *x += origin.x ;
1161 if(y) *y += origin.y ;
1162
1163 MacWindowToRootWindow( x , y ) ;
1164}
1165
1166void wxWindowMac::MacRootWindowToClient( int *x , int *y ) const
1167{
1168 MacRootWindowToWindow( x , y ) ;
1169
1170 wxPoint origin = GetClientAreaOrigin() ;
1171 if(x) *x -= origin.x ;
1172 if(y) *y -= origin.y ;
1173}
1174
1175void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const
1176{
1177 #if TARGET_API_MAC_OSX
1178 wxPoint pt ;
1179 if ( x ) pt.x = *x ;
1180 if ( y ) pt.y = *y ;
1181
1182 if ( !IsTopLevel() )
1183 {
1184 wxTopLevelWindowMac* top = MacGetTopLevelWindow();
1185 if (top)
1186 {
1187 pt.x -= MacGetLeftBorderSize() ;
1188 pt.y -= MacGetTopBorderSize() ;
1189 wxMacControl::Convert( &pt , m_peer , top->m_peer ) ;
1190 }
1191 }
1192
1193 if ( x ) *x = (int) pt.x ;
1194 if ( y ) *y = (int) pt.y ;
1195 #else
1196 if ( !IsTopLevel() )
1197 {
1198 Rect bounds ;
1199 m_peer->GetRect( &bounds ) ;
1200 if(x) *x += bounds.left ;
1201 if(y) *y += bounds.top ;
1202 }
1203#endif
1204}
1205
1206void wxWindowMac::MacWindowToRootWindow( short *x , short *y ) const
1207{
1208 int x1 , y1 ;
1209 if ( x ) x1 = *x ;
1210 if ( y ) y1 = *y ;
1211 MacWindowToRootWindow( &x1 , &y1 ) ;
1212 if ( x ) *x = x1 ;
1213 if ( y ) *y = y1 ;
1214}
1215
1216void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const
1217{
1218 #if TARGET_API_MAC_OSX
1219 wxPoint pt ;
1220 if ( x ) pt.x = *x ;
1221 if ( y ) pt.y = *y ;
1222
1223 if ( !IsTopLevel() )
1224 {
1225 wxMacControl::Convert( &pt , MacGetTopLevelWindow()->m_peer , m_peer ) ;
1226 pt.x += MacGetLeftBorderSize() ;
1227 pt.y += MacGetTopBorderSize() ;
1228 }
1229
1230 if ( x ) *x = (int) pt.x ;
1231 if ( y ) *y = (int) pt.y ;
1232 #else
1233 if ( !IsTopLevel() )
1234 {
1235 Rect bounds ;
1236 m_peer->GetRect( &bounds ) ;
1237 if(x) *x -= bounds.left ;
1238 if(y) *y -= bounds.top ;
1239 }
1240#endif
1241}
1242
1243void wxWindowMac::MacRootWindowToWindow( short *x , short *y ) const
1244{
1245 int x1 , y1 ;
1246 if ( x ) x1 = *x ;
1247 if ( y ) y1 = *y ;
1248 MacRootWindowToWindow( &x1 , &y1 ) ;
1249 if ( x ) *x = x1 ;
1250 if ( y ) *y = y1 ;
1251}
1252
1253void wxWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom )
1254{
1255 RgnHandle rgn = NewRgn() ;
1256 Rect content ;
1257 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
1258 {
1259 GetRegionBounds( rgn , &content ) ;
1260 DisposeRgn( rgn ) ;
1261 }
1262 else
1263 {
1264 m_peer->GetRect( &content ) ;
1265 }
1266 Rect structure ;
1267 m_peer->GetRect( &structure ) ;
1268#if !TARGET_API_MAC_OSX
1269 OffsetRect( &content , -structure.left , -structure.top ) ;
1270#endif
1271 left = content.left - structure.left ;
1272 top = content.top - structure.top ;
1273 right = structure.right - content.right ;
1274 bottom = structure.bottom - content.bottom ;
1275}
1276
1277wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const
1278{
1279 wxSize sizeTotal = size;
1280
1281 RgnHandle rgn = NewRgn() ;
1282
1283 Rect content ;
1284
1285 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
1286 {
1287 GetRegionBounds( rgn , &content ) ;
1288 DisposeRgn( rgn ) ;
1289 }
1290 else
1291 {
1292 m_peer->GetRect( &content ) ;
1293 }
1294 Rect structure ;
1295 m_peer->GetRect( &structure ) ;
1296#if !TARGET_API_MAC_OSX
1297 OffsetRect( &content , -structure.left , -structure.top ) ;
1298#endif
1299
1300 sizeTotal.x += (structure.right - structure.left) - (content.right - content.left) ;
1301 sizeTotal.y += (structure.bottom - structure.top) - (content.bottom - content.top ) ;
1302
1303 sizeTotal.x += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1304 sizeTotal.y += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1305
1306 return sizeTotal;
1307}
1308
1309
1310// Get size *available for subwindows* i.e. excluding menu bar etc.
1311void wxWindowMac::DoGetClientSize(int *x, int *y) const
1312{
1313 int ww, hh;
1314
1315 RgnHandle rgn = NewRgn() ;
1316 Rect content ;
1317 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
1318 {
1319 GetRegionBounds( rgn , &content ) ;
1320 DisposeRgn( rgn ) ;
1321 }
1322 else
1323 {
1324 m_peer->GetRect( &content ) ;
1325 }
1326#if !TARGET_API_MAC_OSX
1327 Rect structure ;
1328 m_peer->GetRect( &structure ) ;
1329 OffsetRect( &content , -structure.left , -structure.top ) ;
1330#endif
1331 ww = content.right - content.left ;
1332 hh = content.bottom - content.top ;
1333
1334 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1335 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1336
1337 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
1338 {
1339 int x1 = 0 ;
1340 int y1 = 0 ;
1341 int w ;
1342 int h ;
1343 GetSize( &w , &h ) ;
1344
1345 MacClientToRootWindow( &x1 , &y1 ) ;
1346 MacClientToRootWindow( &w , &h ) ;
1347
1348 wxWindowMac *iter = (wxWindowMac*)this ;
1349
1350 int totW = 10000 , totH = 10000;
1351 while( iter )
1352 {
1353 if ( iter->IsTopLevel() )
1354 {
1355 iter->GetSize( &totW , &totH ) ;
1356 break ;
1357 }
1358
1359 iter = iter->GetParent() ;
1360 }
1361
1362 if (m_hScrollBar && m_hScrollBar->IsShown() )
1363 {
1364 hh -= MAC_SCROLLBAR_SIZE;
1365 if ( h-y1 >= totH )
1366 {
1367 hh += 1 ;
1368 }
1369 }
1370 if (m_vScrollBar && m_vScrollBar->IsShown() )
1371 {
1372 ww -= MAC_SCROLLBAR_SIZE;
1373 if ( w-x1 >= totW )
1374 {
1375 ww += 1 ;
1376 }
1377 }
1378 }
1379 if(x) *x = ww;
1380 if(y) *y = hh;
1381
1382}
1383
1384bool wxWindowMac::SetCursor(const wxCursor& cursor)
1385{
1386 if (m_cursor == cursor)
1387 return FALSE;
1388
1389 if (wxNullCursor == cursor)
1390 {
1391 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) )
1392 return FALSE ;
1393 }
1394 else
1395 {
1396 if ( ! wxWindowBase::SetCursor( cursor ) )
1397 return FALSE ;
1398 }
1399
1400 wxASSERT_MSG( m_cursor.Ok(),
1401 wxT("cursor must be valid after call to the base version"));
1402
1403
1404 wxWindowMac *mouseWin = 0 ;
1405 {
1406 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
1407 CGrafPtr savePort ;
1408 Boolean swapped = QDSwapPort( GetWindowPort( window ) , &savePort ) ;
1409
1410 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1411 // position, use it...
1412
1413 Point pt ;
1414 GetMouse( &pt ) ;
1415 ControlPartCode part ;
1416 ControlRef control ;
1417 control = wxMacFindControlUnderMouse( pt , window , &part ) ;
1418 if ( control )
1419 mouseWin = wxFindControlFromMacControl( control ) ;
1420
1421 if ( swapped )
1422 QDSwapPort( savePort , NULL ) ;
1423 }
1424
1425 if ( mouseWin == this && !wxIsBusy() )
1426 {
1427 m_cursor.MacInstall() ;
1428 }
1429
1430 return TRUE ;
1431}
1432
1433#if wxUSE_MENUS
1434bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y)
1435{
1436 menu->SetInvokingWindow(this);
1437 menu->UpdateUI();
1438
1439 if ( x == -1 && y == -1 )
1440 {
1441 wxPoint mouse = wxGetMousePosition();
1442 x = mouse.x; y = mouse.y;
1443 }
1444 else
1445 {
1446 ClientToScreen( &x , &y ) ;
1447 }
1448
1449 menu->MacBeforeDisplay( true ) ;
1450 long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ;
1451 if ( HiWord(menuResult) != 0 )
1452 {
1453 MenuCommand id ;
1454 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &id ) ;
1455 wxMenuItem* item = NULL ;
1456 wxMenu* realmenu ;
1457 item = menu->FindItem(id, &realmenu) ;
1458 if (item->IsCheckable())
1459 {
1460 item->Check( !item->IsChecked() ) ;
1461 }
1462 menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ;
1463 }
1464 menu->MacAfterDisplay( true ) ;
1465
1466 menu->SetInvokingWindow(NULL);
1467
1468 return TRUE;
1469}
1470#endif
1471
1472// ----------------------------------------------------------------------------
1473// tooltips
1474// ----------------------------------------------------------------------------
1475
1476#if wxUSE_TOOLTIPS
1477
1478void wxWindowMac::DoSetToolTip(wxToolTip *tooltip)
1479{
1480 wxWindowBase::DoSetToolTip(tooltip);
1481
1482 if ( m_tooltip )
1483 m_tooltip->SetWindow(this);
1484}
1485
1486#endif // wxUSE_TOOLTIPS
1487
1488void wxWindowMac::DoMoveWindow(int x, int y, int width, int height)
1489{
1490 int former_x , former_y , former_w, former_h ;
1491#if !TARGET_API_MAC_OSX
1492 DoGetPosition( &former_x , &former_y ) ;
1493 DoGetSize( &former_w , &former_h ) ;
1494#else
1495 MacGetPositionAndSizeFromControl( former_x , former_y , former_w , former_h ) ;
1496 former_x -= MacGetLeftBorderSize() ;
1497 former_y -= MacGetTopBorderSize() ;
1498 former_w += MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1499 former_h += MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1500#endif
1501
1502 int actualWidth = width;
1503 int actualHeight = height;
1504 int actualX = x;
1505 int actualY = y;
1506
1507 if ((m_minWidth != -1) && (actualWidth < m_minWidth))
1508 actualWidth = m_minWidth;
1509 if ((m_minHeight != -1) && (actualHeight < m_minHeight))
1510 actualHeight = m_minHeight;
1511 if ((m_maxWidth != -1) && (actualWidth > m_maxWidth))
1512 actualWidth = m_maxWidth;
1513 if ((m_maxHeight != -1) && (actualHeight > m_maxHeight))
1514 actualHeight = m_maxHeight;
1515
1516 bool doMove = false ;
1517 bool doResize = false ;
1518
1519 if ( actualX != former_x || actualY != former_y )
1520 {
1521 doMove = true ;
1522 }
1523 if ( actualWidth != former_w || actualHeight != former_h )
1524 {
1525 doResize = true ;
1526 }
1527
1528 if ( doMove || doResize )
1529 {
1530 // we don't adjust twice for the origin
1531 Rect r = wxMacGetBoundsForControl(this , wxPoint( actualX,actualY), wxSize( actualWidth, actualHeight ) , false ) ;
1532 bool vis = m_peer->IsVisible();
1533
1534 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1535 if ( vis )
1536 m_peer->SetVisibility( false , true ) ;
1537 m_peer->SetRect( &r ) ;
1538 if ( vis )
1539 m_peer->SetVisibility( true , true ) ;
1540
1541 MacRepositionScrollBars() ;
1542 if ( doMove )
1543 {
1544 wxPoint point(actualX,actualY);
1545 wxMoveEvent event(point, m_windowId);
1546 event.SetEventObject(this);
1547 GetEventHandler()->ProcessEvent(event) ;
1548 }
1549 if ( doResize )
1550 {
1551 MacRepositionScrollBars() ;
1552 wxSize size(actualWidth, actualHeight);
1553 wxSizeEvent event(size, m_windowId);
1554 event.SetEventObject(this);
1555 GetEventHandler()->ProcessEvent(event);
1556 }
1557 }
1558
1559}
1560
1561wxSize wxWindowMac::DoGetBestSize() const
1562{
1563 if ( m_macIsUserPane || IsTopLevel() )
1564 return wxWindowBase::DoGetBestSize() ;
1565
1566 Rect bestsize = { 0 , 0 , 0 , 0 } ;
1567 int bestWidth, bestHeight ;
1568 m_peer->GetBestRect( &bestsize ) ;
1569
1570 if ( EmptyRect( &bestsize ) )
1571 {
1572 bestsize.left = bestsize.top = 0 ;
1573 bestsize.right = 16 ;
1574 bestsize.bottom = 16 ;
1575 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
1576 {
1577 bestsize.bottom = 16 ;
1578 }
1579 else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
1580 {
1581 bestsize.bottom = 24 ;
1582 }
1583 else
1584 {
1585 // return wxWindowBase::DoGetBestSize() ;
1586 }
1587 }
1588
1589 bestWidth = bestsize.right - bestsize.left ;
1590 bestHeight = bestsize.bottom - bestsize.top ;
1591 if ( bestHeight < 10 )
1592 bestHeight = 13 ;
1593
1594 return wxSize(bestWidth, bestHeight);
1595}
1596
1597
1598// set the size of the window: if the dimensions are positive, just use them,
1599// but if any of them is equal to -1, it means that we must find the value for
1600// it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1601// which case -1 is a valid value for x and y)
1602//
1603// If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1604// the width/height to best suit our contents, otherwise we reuse the current
1605// width/height
1606void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags)
1607{
1608 // get the current size and position...
1609 int currentX, currentY;
1610 GetPosition(&currentX, &currentY);
1611
1612 int currentW,currentH;
1613 GetSize(&currentW, &currentH);
1614
1615 // ... and don't do anything (avoiding flicker) if it's already ok
1616 if ( x == currentX && y == currentY &&
1617 width == currentW && height == currentH && ( height != -1 && width != -1 ) )
1618 {
1619 // TODO REMOVE
1620 MacRepositionScrollBars() ; // we might have a real position shift
1621 return;
1622 }
1623
1624 if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
1625 x = currentX;
1626 if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
1627 y = currentY;
1628
1629 AdjustForParentClientOrigin(x, y, sizeFlags);
1630
1631 wxSize size(-1, -1);
1632 if ( width == -1 )
1633 {
1634 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
1635 {
1636 size = DoGetBestSize();
1637 width = size.x;
1638 }
1639 else
1640 {
1641 // just take the current one
1642 width = currentW;
1643 }
1644 }
1645
1646 if ( height == -1 )
1647 {
1648 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
1649 {
1650 if ( size.x == -1 )
1651 {
1652 size = DoGetBestSize();
1653 }
1654 //else: already called DoGetBestSize() above
1655
1656 height = size.y;
1657 }
1658 else
1659 {
1660 // just take the current one
1661 height = currentH;
1662 }
1663 }
1664
1665 DoMoveWindow(x, y, width, height);
1666
1667}
1668
1669wxPoint wxWindowMac::GetClientAreaOrigin() const
1670{
1671 RgnHandle rgn = NewRgn() ;
1672 Rect content ;
1673 m_peer->GetRegion( kControlContentMetaPart , rgn ) ;
1674 GetRegionBounds( rgn , &content ) ;
1675 DisposeRgn( rgn ) ;
1676#if !TARGET_API_MAC_OSX
1677 // if the content rgn is empty / not supported
1678 // don't attempt to correct the coordinates to wxWindow relative ones
1679 if (!::EmptyRect( &content ) )
1680 {
1681 Rect structure ;
1682 m_peer->GetRect( &structure ) ;
1683 OffsetRect( &content , -structure.left , -structure.top ) ;
1684 }
1685#endif
1686
1687 return wxPoint( content.left + MacGetLeftBorderSize( ) , content.top + MacGetTopBorderSize( ) );
1688}
1689
1690void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight)
1691{
1692 if ( clientheight != -1 || clientheight != -1 )
1693 {
1694 int currentclientwidth , currentclientheight ;
1695 int currentwidth , currentheight ;
1696
1697 GetClientSize( &currentclientwidth , &currentclientheight ) ;
1698 GetSize( &currentwidth , &currentheight ) ;
1699
1700 DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth ,
1701 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
1702 }
1703}
1704
1705void wxWindowMac::SetTitle(const wxString& title)
1706{
1707 m_label = wxStripMenuCodes(title) ;
1708
1709 if ( m_peer && m_peer->Ok() )
1710 {
1711 m_peer->SetTitle( m_label ) ;
1712 }
1713 Refresh() ;
1714}
1715
1716wxString wxWindowMac::GetTitle() const
1717{
1718 return m_label ;
1719}
1720
1721bool wxWindowMac::Show(bool show)
1722{
1723 if ( !wxWindowBase::Show(show) )
1724 return FALSE;
1725
1726 // TODO use visibilityChanged Carbon Event for OSX
1727 bool former = MacIsReallyShown() ;
1728
1729 m_peer->SetVisibility( show , true ) ;
1730 if ( former != MacIsReallyShown() )
1731 MacPropagateVisibilityChanged() ;
1732 return TRUE;
1733}
1734
1735bool wxWindowMac::Enable(bool enable)
1736{
1737 wxASSERT( m_peer->Ok() ) ;
1738 if ( !wxWindowBase::Enable(enable) )
1739 return FALSE;
1740
1741 bool former = MacIsReallyEnabled() ;
1742 m_peer->Enable( enable ) ;
1743
1744 if ( former != MacIsReallyEnabled() )
1745 MacPropagateEnabledStateChanged() ;
1746 return TRUE;
1747}
1748
1749//
1750// status change propagations (will be not necessary for OSX later )
1751//
1752
1753void wxWindowMac::MacPropagateVisibilityChanged()
1754{
1755#if !TARGET_API_MAC_OSX
1756 MacVisibilityChanged() ;
1757
1758 wxWindowListNode *node = GetChildren().GetFirst();
1759 while ( node )
1760 {
1761 wxWindowMac *child = node->GetData();
1762 if ( child->IsShown() )
1763 child->MacPropagateVisibilityChanged( ) ;
1764 node = node->GetNext();
1765 }
1766#endif
1767}
1768
1769void wxWindowMac::MacPropagateEnabledStateChanged( )
1770{
1771#if !TARGET_API_MAC_OSX
1772 MacEnabledStateChanged() ;
1773
1774 wxWindowListNode *node = GetChildren().GetFirst();
1775 while ( node )
1776 {
1777 wxWindowMac *child = node->GetData();
1778 if ( child->IsEnabled() )
1779 child->MacPropagateEnabledStateChanged() ;
1780 node = node->GetNext();
1781 }
1782#endif
1783}
1784
1785void wxWindowMac::MacPropagateHiliteChanged( )
1786{
1787#if !TARGET_API_MAC_OSX
1788 MacHiliteChanged() ;
1789
1790 wxWindowListNode *node = GetChildren().GetFirst();
1791 while ( node )
1792 {
1793 wxWindowMac *child = node->GetData();
1794 // if ( child->IsEnabled() )
1795 child->MacPropagateHiliteChanged() ;
1796 node = node->GetNext();
1797 }
1798#endif
1799}
1800
1801//
1802// status change notifications
1803//
1804
1805void wxWindowMac::MacVisibilityChanged()
1806{
1807}
1808
1809void wxWindowMac::MacHiliteChanged()
1810{
1811}
1812
1813void wxWindowMac::MacEnabledStateChanged()
1814{
1815}
1816
1817//
1818// status queries on the inherited window's state
1819//
1820
1821bool wxWindowMac::MacIsReallyShown()
1822{
1823 // only under OSX the visibility of the TLW is taken into account
1824#if TARGET_API_MAC_OSX
1825 if ( m_peer && m_peer->Ok() )
1826 return m_peer->IsVisible();
1827#endif
1828 wxWindow* win = this ;
1829 while( win->IsShown() )
1830 {
1831 if ( win->IsTopLevel() )
1832 return true ;
1833
1834 win = win->GetParent() ;
1835 if ( win == NULL )
1836 return true ;
1837
1838 } ;
1839 return false ;
1840}
1841
1842bool wxWindowMac::MacIsReallyEnabled()
1843{
1844 return m_peer->IsEnabled() ;
1845}
1846
1847bool wxWindowMac::MacIsReallyHilited()
1848{
1849 return m_peer->IsActive();
1850}
1851
1852void wxWindowMac::MacFlashInvalidAreas()
1853{
1854#if TARGET_API_MAC_OSX
1855 HIViewFlashDirtyArea( (WindowRef) MacGetTopLevelWindowRef() ) ;
1856#endif
1857}
1858
1859//
1860//
1861//
1862
1863int wxWindowMac::GetCharHeight() const
1864{
1865 wxClientDC dc ( (wxWindowMac*)this ) ;
1866 return dc.GetCharHeight() ;
1867}
1868
1869int wxWindowMac::GetCharWidth() const
1870{
1871 wxClientDC dc ( (wxWindowMac*)this ) ;
1872 return dc.GetCharWidth() ;
1873}
1874
1875void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y,
1876 int *descent, int *externalLeading, const wxFont *theFont ) const
1877{
1878 const wxFont *fontToUse = theFont;
1879 if ( !fontToUse )
1880 fontToUse = &m_font;
1881
1882 wxClientDC dc( (wxWindowMac*) this ) ;
1883 long lx,ly,ld,le ;
1884 dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ;
1885 if ( externalLeading )
1886 *externalLeading = le ;
1887 if ( descent )
1888 *descent = ld ;
1889 if ( x )
1890 *x = lx ;
1891 if ( y )
1892 *y = ly ;
1893}
1894
1895/*
1896 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1897 * we always intersect with the entire window, not only with the client area
1898 */
1899
1900void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect)
1901{
1902 if ( m_peer == NULL )
1903 return ;
1904
1905#if TARGET_API_MAC_OSX
1906 if ( rect == NULL )
1907 m_peer->SetNeedsDisplay( true ) ;
1908 else
1909 {
1910 RgnHandle update = NewRgn() ;
1911 SetRectRgn( update , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1912 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , update , update ) ;
1913 wxPoint origin = GetClientAreaOrigin() ;
1914 OffsetRgn( update, origin.x , origin.y ) ;
1915 m_peer->SetNeedsDisplay( true , update) ;
1916 }
1917#else
1918/*
1919 RgnHandle updateRgn = NewRgn() ;
1920 if ( rect == NULL )
1921 {
1922 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1923 }
1924 else
1925 {
1926 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1927 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1928 }
1929 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1930 DisposeRgn(updateRgn) ;
1931*/
1932 if ( m_peer->IsVisible())
1933 {
1934 m_peer->SetVisibility( false , false ) ;
1935 m_peer->SetVisibility( true , true ) ;
1936 }
1937 /*
1938 if ( MacGetTopLevelWindow() == NULL )
1939 return ;
1940
1941 if ( !m_peer->IsVisible())
1942 return ;
1943
1944 wxPoint client = GetClientAreaOrigin();
1945 int x1 = -client.x;
1946 int y1 = -client.y;
1947 int x2 = m_width - client.x;
1948 int y2 = m_height - client.y;
1949
1950 if (IsKindOf( CLASSINFO(wxButton)))
1951 {
1952 // buttons have an "aura"
1953 y1 -= 5;
1954 x1 -= 5;
1955 y2 += 5;
1956 x2 += 5;
1957 }
1958
1959 Rect clientrect = { y1, x1, y2, x2 };
1960
1961 if ( rect )
1962 {
1963 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1964 SectRect( &clientrect , &r , &clientrect ) ;
1965 }
1966
1967 if ( !EmptyRect( &clientrect ) )
1968 {
1969 int top = 0 , left = 0 ;
1970
1971 MacClientToRootWindow( &left , &top ) ;
1972 OffsetRect( &clientrect , left , top ) ;
1973
1974 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1975 }
1976 */
1977#endif
1978}
1979
1980void wxWindowMac::Freeze()
1981{
1982#if TARGET_API_MAC_OSX
1983 if ( !m_frozenness++ )
1984 {
1985 m_peer->SetDrawingEnabled( false ) ;
1986 }
1987#endif
1988}
1989
1990
1991void wxWindowMac::Thaw()
1992{
1993#if TARGET_API_MAC_OSX
1994 wxASSERT_MSG( m_frozenness > 0, _T("Thaw() without matching Freeze()") );
1995
1996 if ( !--m_frozenness )
1997 {
1998 m_peer->SetDrawingEnabled( true ) ;
1999 m_peer->InvalidateWithChildren() ;
2000 }
2001#endif
2002}
2003
2004void wxWindowMac::MacRedrawControl()
2005{
2006/*
2007 if ( *m_peer && MacGetTopLevelWindowRef() && m_peer->IsVisible())
2008 {
2009#if TARGET_API_MAC_CARBON
2010 Update() ;
2011#else
2012 wxClientDC dc(this) ;
2013 wxMacPortSetter helper(&dc) ;
2014 wxMacWindowClipper clipper(this) ;
2015 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2016 UMADrawControl( *m_peer ) ;
2017#endif
2018 }
2019*/
2020}
2021
2022/* TODO
2023void wxWindowMac::OnPaint(wxPaintEvent& event)
2024{
2025 // why don't we skip that here ?
2026}
2027*/
2028
2029wxWindowMac *wxGetActiveWindow()
2030{
2031 // actually this is a windows-only concept
2032 return NULL;
2033}
2034
2035// Coordinates relative to the window
2036void wxWindowMac::WarpPointer (int x_pos, int y_pos)
2037{
2038 // We really don't move the mouse programmatically under Mac.
2039}
2040
2041void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
2042{
2043#if TARGET_API_MAC_OSX
2044 if ( m_macBackgroundBrush.Ok() == false || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT )
2045 {
2046 event.Skip() ;
2047 }
2048 else
2049#endif
2050 event.GetDC()->Clear() ;
2051}
2052
2053void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
2054{
2055 wxWindowDC dc(this) ;
2056 wxMacPortSetter helper(&dc) ;
2057
2058 MacPaintBorders( dc.m_macLocalOrigin.x , dc.m_macLocalOrigin.y) ;
2059}
2060
2061int wxWindowMac::GetScrollPos(int orient) const
2062{
2063 if ( orient == wxHORIZONTAL )
2064 {
2065 if ( m_hScrollBar )
2066 return m_hScrollBar->GetThumbPosition() ;
2067 }
2068 else
2069 {
2070 if ( m_vScrollBar )
2071 return m_vScrollBar->GetThumbPosition() ;
2072 }
2073 return 0;
2074}
2075
2076// This now returns the whole range, not just the number
2077// of positions that we can scroll.
2078int wxWindowMac::GetScrollRange(int orient) const
2079{
2080 if ( orient == wxHORIZONTAL )
2081 {
2082 if ( m_hScrollBar )
2083 return m_hScrollBar->GetRange() ;
2084 }
2085 else
2086 {
2087 if ( m_vScrollBar )
2088 return m_vScrollBar->GetRange() ;
2089 }
2090 return 0;
2091}
2092
2093int wxWindowMac::GetScrollThumb(int orient) const
2094{
2095 if ( orient == wxHORIZONTAL )
2096 {
2097 if ( m_hScrollBar )
2098 return m_hScrollBar->GetThumbSize() ;
2099 }
2100 else
2101 {
2102 if ( m_vScrollBar )
2103 return m_vScrollBar->GetThumbSize() ;
2104 }
2105 return 0;
2106}
2107
2108void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh)
2109{
2110 if ( orient == wxHORIZONTAL )
2111 {
2112 if ( m_hScrollBar )
2113 m_hScrollBar->SetThumbPosition( pos ) ;
2114 }
2115 else
2116 {
2117 if ( m_vScrollBar )
2118 m_vScrollBar->SetThumbPosition( pos ) ;
2119 }
2120}
2121
2122void wxWindowMac::MacPaintBorders( int left , int top )
2123{
2124 if( IsTopLevel() )
2125 return ;
2126
2127 int major,minor;
2128 wxGetOsVersion( &major, &minor );
2129
2130 RGBColor darkShadow = { 0x0000, 0x0000 , 0x0000 } ;
2131 RGBColor lightShadow = { 0x4444, 0x4444 , 0x4444 } ;
2132 // OS X has lighter border edges than classic:
2133 if (major >= 10)
2134 {
2135 darkShadow.red = 0x8E8E;
2136 darkShadow.green = 0x8E8E;
2137 darkShadow.blue = 0x8E8E;
2138 lightShadow.red = 0xBDBD;
2139 lightShadow.green = 0xBDBD;
2140 lightShadow.blue = 0xBDBD;
2141 }
2142
2143 PenNormal() ;
2144
2145 int w , h ;
2146 GetSize( &w , &h ) ;
2147 Rect rect = { top , left , h + top , w + left } ;
2148 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
2149 {
2150#if wxMAC_USE_THEME_BORDER
2151 SInt32 border = 0 ;
2152 GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ;
2153 InsetRect( &rect , border , border );
2154 DrawThemeEditTextFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2155#else
2156 RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ;
2157 RGBColor face = { 0xDDDD, 0xDDDD , 0xDDDD } ;
2158
2159 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
2160 RGBForeColor( &face );
2161 MoveTo( left + 0 , top + h - 2 );
2162 LineTo( left + 0 , top + 0 );
2163 LineTo( left + w - 2 , top + 0 );
2164
2165 MoveTo( left + 2 , top + h - 3 );
2166 LineTo( left + w - 3 , top + h - 3 );
2167 LineTo( left + w - 3 , top + 2 );
2168
2169 RGBForeColor( sunken ? &face : &darkShadow );
2170 MoveTo( left + 0 , top + h - 1 );
2171 LineTo( left + w - 1 , top + h - 1 );
2172 LineTo( left + w - 1 , top + 0 );
2173
2174 RGBForeColor( sunken ? &lightShadow : &white );
2175 MoveTo( left + 1 , top + h - 3 );
2176 LineTo( left + 1, top + 1 );
2177 LineTo( left + w - 3 , top + 1 );
2178
2179 RGBForeColor( sunken ? &white : &lightShadow );
2180 MoveTo( left + 1 , top + h - 2 );
2181 LineTo( left + w - 2 , top + h - 2 );
2182 LineTo( left + w - 2 , top + 1 );
2183
2184 RGBForeColor( sunken ? &darkShadow : &face );
2185 MoveTo( left + 2 , top + h - 4 );
2186 LineTo( left + 2 , top + 2 );
2187 LineTo( left + w - 4 , top + 2 );
2188#endif
2189 }
2190 else if (HasFlag(wxSIMPLE_BORDER))
2191 {
2192 Rect rect = { top , left , h + top , w + left } ;
2193 RGBForeColor( &darkShadow ) ;
2194 FrameRect( &rect ) ;
2195 }
2196}
2197
2198void wxWindowMac::RemoveChild( wxWindowBase *child )
2199{
2200 if ( child == m_hScrollBar )
2201 m_hScrollBar = NULL ;
2202 if ( child == m_vScrollBar )
2203 m_vScrollBar = NULL ;
2204
2205 wxWindowBase::RemoveChild( child ) ;
2206}
2207
2208// New function that will replace some of the above.
2209void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible,
2210 int range, bool refresh)
2211{
2212 if ( orient == wxHORIZONTAL )
2213 {
2214 if ( m_hScrollBar )
2215 {
2216 if ( range == 0 || thumbVisible >= range )
2217 {
2218 if ( m_hScrollBar->IsShown() )
2219 m_hScrollBar->Show(false) ;
2220 }
2221 else
2222 {
2223 if ( !m_hScrollBar->IsShown() )
2224 m_hScrollBar->Show(true) ;
2225 m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
2226 }
2227 }
2228 }
2229 else
2230 {
2231 if ( m_vScrollBar )
2232 {
2233 if ( range == 0 || thumbVisible >= range )
2234 {
2235 if ( m_vScrollBar->IsShown() )
2236 m_vScrollBar->Show(false) ;
2237 }
2238 else
2239 {
2240 if ( !m_vScrollBar->IsShown() )
2241 m_vScrollBar->Show(true) ;
2242 m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
2243 }
2244 }
2245 }
2246 MacRepositionScrollBars() ;
2247}
2248
2249// Does a physical scroll
2250void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
2251{
2252 if( dx == 0 && dy ==0 )
2253 return ;
2254
2255
2256 {
2257
2258 int width , height ;
2259 GetClientSize( &width , &height ) ;
2260#if TARGET_API_MAC_OSX
2261 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2262 // area is scrolled, this does not occur if width and height are 2 pixels less,
2263 // TODO write optimal workaround
2264 wxRect scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , MacGetLeftBorderSize() + width , MacGetTopBorderSize() + height ) ;
2265 if ( rect )
2266 {
2267 scrollrect.Intersect( *rect ) ;
2268 }
2269 if ( m_peer->GetNeedsDisplay() )
2270 {
2271 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2272 // either immediate redraw or full invalidate
2273#if 1
2274 // is the better overall solution, as it does not slow down scrolling
2275 m_peer->SetNeedsDisplay( true ) ;
2276#else
2277 // this would be the preferred version for fast drawing controls
2278 if( UMAGetSystemVersion() < 0x1030 )
2279 Update() ;
2280 else
2281 HIViewRender(*m_peer) ;
2282#endif
2283 }
2284 m_peer->ScrollRect( scrollrect , dx , dy ) ;
2285#else
2286
2287 wxPoint pos;
2288 pos.x = pos.y = 0;
2289
2290 Rect scrollrect;
2291 RgnHandle updateRgn = NewRgn() ;
2292
2293 {
2294 wxClientDC dc(this) ;
2295 wxMacPortSetter helper(&dc) ;
2296
2297 m_peer->GetRect( &scrollrect ) ;
2298 scrollrect.top += MacGetTopBorderSize() ;
2299 scrollrect.left += MacGetLeftBorderSize() ;
2300 scrollrect.bottom = scrollrect.top + height ;
2301 scrollrect.right = scrollrect.left + width ;
2302
2303 if ( rect )
2304 {
2305 Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) ,
2306 dc.XLOG2DEVMAC(rect->x + rect->width) } ;
2307 SectRect( &scrollrect , &r , &scrollrect ) ;
2308 }
2309 ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
2310 }
2311 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2312#endif
2313 }
2314
2315 for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())
2316 {
2317 wxWindowMac *child = node->GetData();
2318 if (child == m_vScrollBar) continue;
2319 if (child == m_hScrollBar) continue;
2320 if (child->IsTopLevel()) continue;
2321
2322 int x,y;
2323 child->GetPosition( &x, &y );
2324 int w,h;
2325 child->GetSize( &w, &h );
2326 if (rect)
2327 {
2328 wxRect rc(x,y,w,h);
2329 if (rect->Intersects(rc))
2330 child->SetSize( x+dx, y+dy, w, h );
2331 }
2332 else
2333 {
2334 child->SetSize( x+dx, y+dy, w, h );
2335 }
2336 }
2337}
2338
2339void wxWindowMac::MacOnScroll(wxScrollEvent &event )
2340{
2341 if ( event.m_eventObject == m_vScrollBar || event.m_eventObject == m_hScrollBar )
2342 {
2343 wxScrollWinEvent wevent;
2344 wevent.SetPosition(event.GetPosition());
2345 wevent.SetOrientation(event.GetOrientation());
2346 wevent.m_eventObject = this;
2347
2348 if (event.m_eventType == wxEVT_SCROLL_TOP)
2349 wevent.m_eventType = wxEVT_SCROLLWIN_TOP;
2350 else if (event.m_eventType == wxEVT_SCROLL_BOTTOM)
2351 wevent.m_eventType = wxEVT_SCROLLWIN_BOTTOM;
2352 else if (event.m_eventType == wxEVT_SCROLL_LINEUP)
2353 wevent.m_eventType = wxEVT_SCROLLWIN_LINEUP;
2354 else if (event.m_eventType == wxEVT_SCROLL_LINEDOWN)
2355 wevent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
2356 else if (event.m_eventType == wxEVT_SCROLL_PAGEUP)
2357 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEUP;
2358 else if (event.m_eventType == wxEVT_SCROLL_PAGEDOWN)
2359 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
2360 else if (event.m_eventType == wxEVT_SCROLL_THUMBTRACK)
2361 wevent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
2362 else if (event.m_eventType == wxEVT_SCROLL_THUMBRELEASE)
2363 wevent.m_eventType = wxEVT_SCROLLWIN_THUMBRELEASE;
2364
2365 GetEventHandler()->ProcessEvent(wevent);
2366 }
2367}
2368
2369// Get the window with the focus
2370wxWindowMac *wxWindowBase::FindFocus()
2371{
2372 ControlRef control ;
2373 GetKeyboardFocus( GetUserFocusWindow() , &control ) ;
2374 return wxFindControlFromMacControl( control ) ;
2375}
2376
2377void wxWindowMac::OnSetFocus(wxFocusEvent& event)
2378{
2379 // panel wants to track the window which was the last to have focus in it,
2380 // so we want to set ourselves as the window which last had focus
2381 //
2382 // notice that it's also important to do it upwards the tree becaus
2383 // otherwise when the top level panel gets focus, it won't set it back to
2384 // us, but to some other sibling
2385
2386 // CS:don't know if this is still needed:
2387 //wxChildFocusEvent eventFocus(this);
2388 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2389
2390 if ( MacGetTopLevelWindow() && m_peer->NeedsFocusRect() )
2391 {
2392 wxMacWindowStateSaver sv( this ) ;
2393// wxWindowDC dc(this) ;
2394// wxMacPortSetter helper(&dc) ;
2395
2396 int w , h ;
2397 int x , y ;
2398 x = y = 0 ;
2399 MacWindowToRootWindow( &x , &y ) ;
2400 GetSize( &w , &h ) ;
2401 Rect rect = {y , x , h + y , w + x } ;
2402
2403 if ( event.GetEventType() == wxEVT_SET_FOCUS )
2404 DrawThemeFocusRect( &rect , true ) ;
2405 else
2406 DrawThemeFocusRect( &rect , false ) ;
2407 }
2408
2409 event.Skip();
2410}
2411
2412void wxWindowMac::OnInternalIdle()
2413{
2414 // This calls the UI-update mechanism (querying windows for
2415 // menu/toolbar/control state information)
2416 if (wxUpdateUIEvent::CanUpdate(this))
2417 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
2418}
2419
2420// Raise the window to the top of the Z order
2421void wxWindowMac::Raise()
2422{
2423 m_peer->SetZOrder( true , NULL ) ;
2424}
2425
2426// Lower the window to the bottom of the Z order
2427void wxWindowMac::Lower()
2428{
2429 m_peer->SetZOrder( false , NULL ) ;
2430}
2431
2432
2433// static wxWindow *gs_lastWhich = NULL;
2434
2435bool wxWindowMac::MacSetupCursor( const wxPoint& pt)
2436{
2437 // first trigger a set cursor event
2438
2439 wxPoint clientorigin = GetClientAreaOrigin() ;
2440 wxSize clientsize = GetClientSize() ;
2441 wxCursor cursor ;
2442 if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) )
2443 {
2444 wxSetCursorEvent event( pt.x , pt.y );
2445
2446 bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event);
2447 if ( processedEvtSetCursor && event.HasCursor() )
2448 {
2449 cursor = event.GetCursor() ;
2450 }
2451 else
2452 {
2453
2454 // the test for processedEvtSetCursor is here to prevent using m_cursor
2455 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2456 // it - this is a way to say that our cursor shouldn't be used for this
2457 // point
2458 if ( !processedEvtSetCursor && m_cursor.Ok() )
2459 {
2460 cursor = m_cursor ;
2461 }
2462 if ( wxIsBusy() )
2463 {
2464 }
2465 else
2466 {
2467 if ( !GetParent() )
2468 cursor = *wxSTANDARD_CURSOR ;
2469 }
2470 }
2471 if ( cursor.Ok() )
2472 cursor.MacInstall() ;
2473 }
2474 return cursor.Ok() ;
2475}
2476
2477wxString wxWindowMac::MacGetToolTipString( wxPoint &pt )
2478{
2479 if ( m_tooltip )
2480 {
2481 return m_tooltip->GetTip() ;
2482 }
2483 return wxEmptyString ;
2484}
2485
2486void wxWindowMac::Update()
2487{
2488#if TARGET_API_MAC_OSX
2489 WindowRef window = (WindowRef)MacGetTopLevelWindowRef() ;
2490#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2491 // for composited windows this also triggers a redraw of all
2492 // invalid views in the window
2493 if( UMAGetSystemVersion() >= 0x1030 )
2494 HIWindowFlush(window) ;
2495 else
2496#endif
2497 {
2498 // the only way to trigger the redrawing on earlier systems is to call
2499 // ReceiveNextEvent
2500
2501 EventRef currentEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ;
2502 UInt32 currentEventClass = 0 ;
2503 UInt32 currentEventKind = 0 ;
2504 if ( currentEvent != NULL )
2505 {
2506 currentEventClass = ::GetEventClass( currentEvent ) ;
2507 currentEventKind = ::GetEventKind( currentEvent ) ;
2508 }
2509 if ( currentEventClass != kEventClassMenu )
2510 {
2511 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2512
2513 EventRef theEvent;
2514 OSStatus status = noErr ;
2515 status = ReceiveNextEvent( 0 , NULL , kEventDurationNoWait , false , &theEvent ) ;
2516 }
2517 else
2518 m_peer->SetNeedsDisplay( true ) ;
2519 }
2520#else
2521 ::Draw1Control( m_peer->GetControlRef() ) ;
2522#endif
2523}
2524
2525wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const
2526{
2527 wxTopLevelWindowMac* win = NULL ;
2528 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
2529 if ( window )
2530 {
2531 win = wxFindWinFromMacWindow( window ) ;
2532 }
2533 return win ;
2534}
2535wxRegion wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures )
2536{
2537
2538 Rect r ;
2539 RgnHandle visRgn = NewRgn() ;
2540 RgnHandle tempRgn = NewRgn() ;
2541 if ( m_peer->IsVisible())
2542 {
2543 m_peer->GetRect( &r ) ;
2544 r.left -= MacGetLeftBorderSize() ;
2545 r.top -= MacGetTopBorderSize() ;
2546 r.bottom += MacGetBottomBorderSize() ;
2547 r.right += MacGetRightBorderSize() ;
2548
2549 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2550 {
2551 MacRootWindowToWindow( &r.left , & r.top ) ;
2552 MacRootWindowToWindow( &r.right , & r.bottom ) ;
2553 }
2554 else
2555 {
2556 r.right -= r.left ;
2557 r.bottom -= r.top ;
2558 r.left = 0 ;
2559 r.top = 0 ;
2560 }
2561 if ( includeOuterStructures )
2562 InsetRect( &r , -3 , -3 ) ;
2563 RectRgn( visRgn , &r ) ;
2564 if ( !IsTopLevel() )
2565 {
2566 wxWindow* child = this ;
2567 wxWindow* parent = child->GetParent() ;
2568 while( parent )
2569 {
2570 int x , y ;
2571 wxSize size ;
2572 // we have to find a better clipping algorithm here, in order not to clip things
2573 // positioned like status and toolbar
2574 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2575 {
2576 size = parent->GetSize() ;
2577 x = y = 0 ;
2578 }
2579 else
2580 {
2581 size = parent->GetClientSize() ;
2582 wxPoint origin = parent->GetClientAreaOrigin() ;
2583 x = origin.x ;
2584 y = origin.y ;
2585 }
2586 parent->MacWindowToRootWindow( &x, &y ) ;
2587 MacRootWindowToWindow( &x , &y ) ;
2588
2589 SetRectRgn( tempRgn ,
2590 x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() ,
2591 x + size.x - parent->MacGetRightBorderSize(),
2592 y + size.y - parent->MacGetBottomBorderSize()) ;
2593
2594 SectRgn( visRgn , tempRgn , visRgn ) ;
2595 if ( parent->IsTopLevel() )
2596 break ;
2597 child = parent ;
2598 parent = child->GetParent() ;
2599 }
2600 }
2601 }
2602
2603 wxRegion vis = visRgn ;
2604 DisposeRgn( visRgn ) ;
2605 DisposeRgn( tempRgn ) ;
2606 return vis ;
2607}
2608
2609/*
2610 This function must not change the updatergn !
2611 */
2612bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time )
2613{
2614 RgnHandle updatergn = (RgnHandle) updatergnr ;
2615 bool handled = false ;
2616
2617 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2618 {
2619 RgnHandle newupdate = NewRgn() ;
2620 wxSize point = GetClientSize() ;
2621 wxPoint origin = GetClientAreaOrigin() ;
2622 SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ;
2623 SectRgn( newupdate , updatergn , newupdate ) ;
2624 OffsetRgn( newupdate , -origin.x , -origin.y ) ;
2625 m_updateRegion = newupdate ;
2626 DisposeRgn( newupdate ) ;
2627 }
2628
2629 if ( !EmptyRgn(updatergn) )
2630 {
2631 wxWindowDC dc(this);
2632 if (!EmptyRgn(updatergn))
2633 dc.SetClippingRegion(wxRegion(updatergn));
2634
2635 wxEraseEvent eevent( GetId(), &dc );
2636 eevent.SetEventObject( this );
2637 GetEventHandler()->ProcessEvent( eevent );
2638
2639 if ( !m_updateRegion.Empty() )
2640 {
2641 // paint the window itself
2642 wxPaintEvent event;
2643 event.m_timeStamp = time ;
2644 event.SetEventObject(this);
2645 handled = GetEventHandler()->ProcessEvent(event);
2646
2647 // paint custom borders
2648 wxNcPaintEvent eventNc( GetId() );
2649 eventNc.SetEventObject( this );
2650 GetEventHandler()->ProcessEvent( eventNc );
2651 }
2652 }
2653 return handled ;
2654}
2655
2656void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase)
2657{
2658 RgnHandle updatergn = (RgnHandle) updatergnr ;
2659 // updatergn is always already clipped to our boundaries
2660 // if we are in compositing mode then it is in relative to the upper left of the control
2661 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2662 // of the toplevel window
2663 // it is in window coordinates, not in client coordinates
2664
2665 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2666 RgnHandle ownUpdateRgn = NewRgn() ;
2667 CopyRgn( updatergn , ownUpdateRgn ) ;
2668
2669 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2670 {
2671 Rect bounds;
2672 m_peer->GetRectInWindowCoords( &bounds );
2673 RgnHandle controlRgn = NewRgn();
2674 RectRgn( controlRgn, &bounds );
2675 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2676 // the window update region
2677 SectRgn( ownUpdateRgn, controlRgn, ownUpdateRgn );
2678 DisposeRgn( controlRgn );
2679
2680 //KO: convert ownUpdateRgn to local coordinates
2681 OffsetRgn( ownUpdateRgn, -bounds.left, -bounds.top );
2682 }
2683
2684 MacDoRedraw( ownUpdateRgn , time ) ;
2685 DisposeRgn( ownUpdateRgn ) ;
2686
2687}
2688
2689WXWindow wxWindowMac::MacGetTopLevelWindowRef() const
2690{
2691 wxWindowMac *iter = (wxWindowMac*)this ;
2692
2693 while( iter )
2694 {
2695 if ( iter->IsTopLevel() )
2696 return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ;
2697
2698 iter = iter->GetParent() ;
2699 }
2700 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2701 return NULL ;
2702}
2703
2704void wxWindowMac::MacCreateScrollBars( long style )
2705{
2706 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ;
2707
2708#if 0
2709
2710 bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
2711 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ;
2712 int width, height ;
2713 GetClientSize( &width , &height ) ;
2714
2715 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
2716 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
2717 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
2718 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
2719
2720 m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint,
2721 vSize , wxVERTICAL);
2722
2723 if ( style & wxVSCROLL )
2724 {
2725
2726 }
2727 else
2728 {
2729 m_vScrollBar->Show(false) ;
2730 }
2731 m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint,
2732 hSize , wxHORIZONTAL);
2733 if ( style & wxHSCROLL )
2734 {
2735 }
2736 else
2737 {
2738 m_hScrollBar->Show(false) ;
2739 }
2740#else
2741 if ( style & ( wxVSCROLL | wxHSCROLL ) )
2742 {
2743 bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
2744 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ;
2745 int width, height ;
2746 GetClientSize( &width , &height ) ;
2747
2748 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
2749 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
2750 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
2751 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
2752
2753
2754 if ( style & wxVSCROLL )
2755 {
2756 m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint,
2757 vSize , wxVERTICAL);
2758 }
2759
2760 if ( style & wxHSCROLL )
2761 {
2762 m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint,
2763 hSize , wxHORIZONTAL);
2764 }
2765 }
2766#endif
2767
2768
2769 // because the create does not take into account the client area origin
2770 MacRepositionScrollBars() ; // we might have a real position shift
2771}
2772
2773void wxWindowMac::MacRepositionScrollBars()
2774{
2775 if ( !m_hScrollBar && !m_vScrollBar )
2776 return ;
2777
2778 bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
2779 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ;
2780
2781 // get real client area
2782
2783 int width ;
2784 int height ;
2785 GetSize( &width , &height ) ;
2786
2787 width -= MacGetLeftBorderSize() + MacGetRightBorderSize();
2788 height -= MacGetTopBorderSize() + MacGetBottomBorderSize();
2789
2790 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
2791 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
2792 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
2793 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
2794
2795 int x = 0 ;
2796 int y = 0 ;
2797 int w ;
2798 int h ;
2799 GetSize( &w , &h ) ;
2800
2801 MacClientToRootWindow( &x , &y ) ;
2802 MacClientToRootWindow( &w , &h ) ;
2803
2804 wxWindowMac *iter = (wxWindowMac*)this ;
2805
2806 int totW = 10000 , totH = 10000;
2807 while( iter )
2808 {
2809 if ( iter->IsTopLevel() )
2810 {
2811 iter->GetSize( &totW , &totH ) ;
2812 break ;
2813 }
2814
2815 iter = iter->GetParent() ;
2816 }
2817
2818 if ( x == 0 )
2819 {
2820 hPoint.x = -1 ;
2821 hSize.x += 1 ;
2822 }
2823 if ( y == 0 )
2824 {
2825 vPoint.y = -1 ;
2826 vSize.y += 1 ;
2827 }
2828
2829 if ( w-x >= totW )
2830 {
2831 hSize.x += 1 ;
2832 vPoint.x += 1 ;
2833 }
2834
2835 if ( h-y >= totH )
2836 {
2837 vSize.y += 1 ;
2838 hPoint.y += 1 ;
2839 }
2840
2841 if ( m_vScrollBar )
2842 {
2843 m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE);
2844 }
2845 if ( m_hScrollBar )
2846 {
2847 m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE);
2848 }
2849}
2850
2851bool wxWindowMac::AcceptsFocus() const
2852{
2853 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2854}
2855
2856void wxWindowMac::MacSuperChangedPosition()
2857{
2858 // only window-absolute structures have to be moved i.e. controls
2859
2860 wxWindowListNode *node = GetChildren().GetFirst();
2861 while ( node )
2862 {
2863 wxWindowMac *child = node->GetData();
2864 child->MacSuperChangedPosition() ;
2865 node = node->GetNext();
2866 }
2867}
2868
2869void wxWindowMac::MacTopLevelWindowChangedPosition()
2870{
2871 // only screen-absolute structures have to be moved i.e. glcanvas
2872
2873 wxWindowListNode *node = GetChildren().GetFirst();
2874 while ( node )
2875 {
2876 wxWindowMac *child = node->GetData();
2877 child->MacTopLevelWindowChangedPosition() ;
2878 node = node->GetNext();
2879 }
2880}
2881
2882long wxWindowMac::MacGetLeftBorderSize( ) const
2883{
2884 if( IsTopLevel() )
2885 return 0 ;
2886
2887 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
2888 {
2889 SInt32 border = 3 ;
2890#if 0 // wxMAC_USE_THEME_BORDER
2891 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2892#endif
2893 return border ;
2894 }
2895 else if ( m_windowStyle &wxDOUBLE_BORDER)
2896 {
2897 SInt32 border = 3 ;
2898#if 0 // wxMAC_USE_THEME_BORDER
2899 GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ;
2900#endif
2901 return border ;
2902 }
2903 else if (m_windowStyle &wxSIMPLE_BORDER)
2904 {
2905 return 1 ;
2906 }
2907 return 0 ;
2908}
2909
2910long wxWindowMac::MacGetRightBorderSize( ) const
2911{
2912 // they are all symmetric in mac themes
2913 return MacGetLeftBorderSize() ;
2914}
2915
2916long wxWindowMac::MacGetTopBorderSize( ) const
2917{
2918 // they are all symmetric in mac themes
2919 return MacGetLeftBorderSize() ;
2920}
2921
2922long wxWindowMac::MacGetBottomBorderSize( ) const
2923{
2924 // they are all symmetric in mac themes
2925 return MacGetLeftBorderSize() ;
2926}
2927
2928long wxWindowMac::MacRemoveBordersFromStyle( long style )
2929{
2930 return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ;
2931}
2932
2933// Find the wxWindowMac at the current mouse position, returning the mouse
2934// position.
2935wxWindowMac* wxFindWindowAtPointer(wxPoint& pt)
2936{
2937 pt = wxGetMousePosition();
2938 wxWindowMac* found = wxFindWindowAtPoint(pt);
2939 return found;
2940}
2941
2942// Get the current mouse position.
2943wxPoint wxGetMousePosition()
2944{
2945 int x, y;
2946 wxGetMousePosition(& x, & y);
2947 return wxPoint(x, y);
2948}
2949
2950void wxWindowMac::OnMouseEvent( wxMouseEvent &event )
2951{
2952 if ( event.GetEventType() == wxEVT_RIGHT_DOWN )
2953 {
2954 // copied from wxGTK : CS
2955 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2956 // except that:
2957 //
2958 // (a) it's a command event and so is propagated to the parent
2959 // (b) under MSW it can be generated from kbd too
2960 // (c) it uses screen coords (because of (a))
2961 wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU,
2962 this->GetId(),
2963 this->ClientToScreen(event.GetPosition()));
2964 if ( ! GetEventHandler()->ProcessEvent(evtCtx) )
2965 event.Skip() ;
2966 }
2967 else
2968 {
2969 event.Skip() ;
2970 }
2971}
2972
2973void wxWindowMac::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) )
2974{
2975}
2976
2977Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin )
2978{
2979 int x ,y , w ,h ;
2980
2981 window->MacGetBoundsForControl( pos , size , x , y, w, h , adjustForOrigin) ;
2982 Rect bounds = { y , x , y+h , x+w };
2983 return bounds ;
2984}
2985
2986wxInt32 wxWindowMac::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
2987{
2988 return eventNotHandledErr ;
2989}
2990
2991