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