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