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