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