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