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