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