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