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