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