]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/window.cpp
9d09716b24c224415daa51c920e8ccb208493f5b
[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 bool wxWindowMac::Show(bool show)
1507 {
1508 if ( !wxWindowBase::Show(show) )
1509 return FALSE;
1510
1511 // TODO use visibilityChanged Carbon Event for OSX
1512 bool former = MacIsReallyShown() ;
1513
1514 SetControlVisibility( (ControlRef) m_macControl , show , true ) ;
1515 if ( former != MacIsReallyShown() )
1516 MacPropagateVisibilityChanged() ;
1517 return TRUE;
1518 }
1519
1520 bool wxWindowMac::Enable(bool enable)
1521 {
1522 wxASSERT( m_macControl != NULL ) ;
1523 if ( !wxWindowBase::Enable(enable) )
1524 return FALSE;
1525
1526 bool former = MacIsReallyEnabled() ;
1527 if ( enable )
1528 EnableControl( (ControlRef) m_macControl ) ;
1529 else
1530 DisableControl( (ControlRef) m_macControl ) ;
1531
1532 if ( former != MacIsReallyEnabled() )
1533 MacPropagateEnabledStateChanged() ;
1534 return TRUE;
1535 }
1536
1537 //
1538 // status change propagations (will be not necessary for OSX later )
1539 //
1540
1541 void wxWindowMac::MacPropagateVisibilityChanged()
1542 {
1543 MacVisibilityChanged() ;
1544
1545 wxWindowListNode *node = GetChildren().GetFirst();
1546 while ( node )
1547 {
1548 wxWindowMac *child = node->GetData();
1549 if ( child->IsShown() )
1550 child->MacPropagateVisibilityChanged( ) ;
1551 node = node->GetNext();
1552 }
1553 }
1554
1555 void wxWindowMac::MacPropagateEnabledStateChanged( )
1556 {
1557 MacEnabledStateChanged() ;
1558
1559 wxWindowListNode *node = GetChildren().GetFirst();
1560 while ( node )
1561 {
1562 wxWindowMac *child = node->GetData();
1563 if ( child->IsEnabled() )
1564 child->MacPropagateEnabledStateChanged() ;
1565 node = node->GetNext();
1566 }
1567 }
1568
1569 void wxWindowMac::MacPropagateHiliteChanged( )
1570 {
1571 MacHiliteChanged() ;
1572
1573 wxWindowListNode *node = GetChildren().GetFirst();
1574 while ( node )
1575 {
1576 wxWindowMac *child = node->GetData();
1577 // if ( child->IsEnabled() )
1578 child->MacPropagateHiliteChanged() ;
1579 node = node->GetNext();
1580 }
1581 }
1582
1583 //
1584 // status change notifications
1585 //
1586
1587 void wxWindowMac::MacVisibilityChanged()
1588 {
1589 }
1590
1591 void wxWindowMac::MacHiliteChanged()
1592 {
1593 }
1594
1595 void wxWindowMac::MacEnabledStateChanged()
1596 {
1597 }
1598
1599 //
1600 // status queries on the inherited window's state
1601 //
1602
1603 bool wxWindowMac::MacIsReallyShown()
1604 {
1605 // only under OSX the visibility of the TLW is taken into account
1606 #if TARGET_API_MAC_OSX
1607 return IsControlVisible( (ControlRef) m_macControl ) ;
1608 #else
1609 wxWindow* win = this ;
1610 while( win->IsShown() )
1611 {
1612 if ( win->IsTopLevel() )
1613 return true ;
1614
1615 win = win->GetParent() ;
1616 if ( win == NULL )
1617 return true ;
1618
1619 } ;
1620 return false ;
1621 #endif
1622 }
1623
1624 bool wxWindowMac::MacIsReallyEnabled()
1625 {
1626 return IsControlEnabled( (ControlRef) m_macControl ) ;
1627 }
1628
1629 bool wxWindowMac::MacIsReallyHilited()
1630 {
1631 return IsControlActive( (ControlRef) m_macControl ) ;
1632 }
1633
1634 //
1635 //
1636 //
1637
1638 int wxWindowMac::GetCharHeight() const
1639 {
1640 wxClientDC dc ( (wxWindowMac*)this ) ;
1641 return dc.GetCharHeight() ;
1642 }
1643
1644 int wxWindowMac::GetCharWidth() const
1645 {
1646 wxClientDC dc ( (wxWindowMac*)this ) ;
1647 return dc.GetCharWidth() ;
1648 }
1649
1650 void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y,
1651 int *descent, int *externalLeading, const wxFont *theFont ) const
1652 {
1653 const wxFont *fontToUse = theFont;
1654 if ( !fontToUse )
1655 fontToUse = &m_font;
1656
1657 wxClientDC dc( (wxWindowMac*) this ) ;
1658 long lx,ly,ld,le ;
1659 dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ;
1660 if ( externalLeading )
1661 *externalLeading = le ;
1662 if ( descent )
1663 *descent = ld ;
1664 if ( x )
1665 *x = lx ;
1666 if ( y )
1667 *y = ly ;
1668 }
1669
1670 /*
1671 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1672 * we always intersect with the entire window, not only with the client area
1673 */
1674
1675 void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect)
1676 {
1677 #if TARGET_API_MAC_OSX
1678 HIViewSetNeedsDisplay( (ControlRef) m_macControl , true ) ;
1679 #else
1680 if ( IsControlVisible( (ControlRef) m_macControl ) )
1681 {
1682 SetControlVisibility( (ControlRef) m_macControl , false , false ) ;
1683 SetControlVisibility( (ControlRef) m_macControl , true , true ) ;
1684 }
1685 /*
1686 if ( MacGetTopLevelWindow() == NULL )
1687 return ;
1688
1689 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1690 return ;
1691
1692 wxPoint client = GetClientAreaOrigin();
1693 int x1 = -client.x;
1694 int y1 = -client.y;
1695 int x2 = m_width - client.x;
1696 int y2 = m_height - client.y;
1697
1698 if (IsKindOf( CLASSINFO(wxButton)))
1699 {
1700 // buttons have an "aura"
1701 y1 -= 5;
1702 x1 -= 5;
1703 y2 += 5;
1704 x2 += 5;
1705 }
1706
1707 Rect clientrect = { y1, x1, y2, x2 };
1708
1709 if ( rect )
1710 {
1711 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1712 SectRect( &clientrect , &r , &clientrect ) ;
1713 }
1714
1715 if ( !EmptyRect( &clientrect ) )
1716 {
1717 int top = 0 , left = 0 ;
1718
1719 MacClientToRootWindow( &left , &top ) ;
1720 OffsetRect( &clientrect , left , top ) ;
1721
1722 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1723 }
1724 */
1725 #endif
1726 }
1727
1728 void wxWindowMac::MacRedrawControl()
1729 {
1730 /*
1731 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
1732 {
1733 #if TARGET_API_MAC_CARBON
1734 Update() ;
1735 #else
1736 wxClientDC dc(this) ;
1737 wxMacPortSetter helper(&dc) ;
1738 wxMacWindowClipper clipper(this) ;
1739 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
1740 UMADrawControl( (ControlRef) m_macControl ) ;
1741 #endif
1742 }
1743 */
1744 }
1745
1746 /* TODO
1747 void wxWindowMac::OnPaint(wxPaintEvent& event)
1748 {
1749 // why don't we skip that here ?
1750 }
1751 */
1752
1753 wxWindowMac *wxGetActiveWindow()
1754 {
1755 // actually this is a windows-only concept
1756 return NULL;
1757 }
1758
1759 // Coordinates relative to the window
1760 void wxWindowMac::WarpPointer (int x_pos, int y_pos)
1761 {
1762 // We really don't move the mouse programmatically under Mac.
1763 }
1764
1765 void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
1766 {
1767 if ( m_macBackgroundBrush.Ok() == false || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT )
1768 {
1769 event.Skip() ;
1770 }
1771 else
1772 event.GetDC()->Clear() ;
1773 }
1774
1775 void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
1776 {
1777 wxWindowDC dc(this) ;
1778 wxMacPortSetter helper(&dc) ;
1779
1780 MacPaintBorders( dc.m_macLocalOrigin.x , dc.m_macLocalOrigin.y) ;
1781 }
1782
1783 int wxWindowMac::GetScrollPos(int orient) const
1784 {
1785 if ( orient == wxHORIZONTAL )
1786 {
1787 if ( m_hScrollBar )
1788 return m_hScrollBar->GetThumbPosition() ;
1789 }
1790 else
1791 {
1792 if ( m_vScrollBar )
1793 return m_vScrollBar->GetThumbPosition() ;
1794 }
1795 return 0;
1796 }
1797
1798 // This now returns the whole range, not just the number
1799 // of positions that we can scroll.
1800 int wxWindowMac::GetScrollRange(int orient) const
1801 {
1802 if ( orient == wxHORIZONTAL )
1803 {
1804 if ( m_hScrollBar )
1805 return m_hScrollBar->GetRange() ;
1806 }
1807 else
1808 {
1809 if ( m_vScrollBar )
1810 return m_vScrollBar->GetRange() ;
1811 }
1812 return 0;
1813 }
1814
1815 int wxWindowMac::GetScrollThumb(int orient) const
1816 {
1817 if ( orient == wxHORIZONTAL )
1818 {
1819 if ( m_hScrollBar )
1820 return m_hScrollBar->GetThumbSize() ;
1821 }
1822 else
1823 {
1824 if ( m_vScrollBar )
1825 return m_vScrollBar->GetThumbSize() ;
1826 }
1827 return 0;
1828 }
1829
1830 void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh)
1831 {
1832 if ( orient == wxHORIZONTAL )
1833 {
1834 if ( m_hScrollBar )
1835 m_hScrollBar->SetThumbPosition( pos ) ;
1836 }
1837 else
1838 {
1839 if ( m_vScrollBar )
1840 m_vScrollBar->SetThumbPosition( pos ) ;
1841 }
1842 }
1843
1844 void wxWindowMac::MacPaintBorders( int left , int top )
1845 {
1846 if( IsTopLevel() )
1847 return ;
1848
1849 int major,minor;
1850 wxGetOsVersion( &major, &minor );
1851
1852 RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ;
1853 RGBColor face = { 0xDDDD, 0xDDDD , 0xDDDD } ;
1854
1855 RGBColor darkShadow = { 0x0000, 0x0000 , 0x0000 } ;
1856 RGBColor lightShadow = { 0x4444, 0x4444 , 0x4444 } ;
1857 // OS X has lighter border edges than classic:
1858 if (major >= 10)
1859 {
1860 darkShadow.red = 0x8E8E;
1861 darkShadow.green = 0x8E8E;
1862 darkShadow.blue = 0x8E8E;
1863 lightShadow.red = 0xBDBD;
1864 lightShadow.green = 0xBDBD;
1865 lightShadow.blue = 0xBDBD;
1866 }
1867
1868 PenNormal() ;
1869
1870 int w , h ;
1871 GetSize( &w , &h ) ;
1872 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
1873 {
1874 #if wxMAC_USE_THEME_BORDER
1875 Rect rect = { top , left , m_height + top , m_width + left } ;
1876 SInt32 border = 0 ;
1877 /*
1878 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1879 InsetRect( &rect , border , border );
1880 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1881 */
1882
1883 DrawThemePrimaryGroup(&rect ,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1884 #else
1885 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1886 RGBForeColor( &face );
1887 MoveTo( left + 0 , top + h - 2 );
1888 LineTo( left + 0 , top + 0 );
1889 LineTo( left + w - 2 , top + 0 );
1890
1891 MoveTo( left + 2 , top + h - 3 );
1892 LineTo( left + w - 3 , top + h - 3 );
1893 LineTo( left + w - 3 , top + 2 );
1894
1895 RGBForeColor( sunken ? &face : &darkShadow );
1896 MoveTo( left + 0 , top + h - 1 );
1897 LineTo( left + w - 1 , top + h - 1 );
1898 LineTo( left + w - 1 , top + 0 );
1899
1900 RGBForeColor( sunken ? &lightShadow : &white );
1901 MoveTo( left + 1 , top + h - 3 );
1902 LineTo( left + 1, top + 1 );
1903 LineTo( left + w - 3 , top + 1 );
1904
1905 RGBForeColor( sunken ? &white : &lightShadow );
1906 MoveTo( left + 1 , top + h - 2 );
1907 LineTo( left + w - 2 , top + h - 2 );
1908 LineTo( left + w - 2 , top + 1 );
1909
1910 RGBForeColor( sunken ? &darkShadow : &face );
1911 MoveTo( left + 2 , top + h - 4 );
1912 LineTo( left + 2 , top + 2 );
1913 LineTo( left + w - 4 , top + 2 );
1914 #endif
1915 }
1916 else if (HasFlag(wxSIMPLE_BORDER))
1917 {
1918 Rect rect = { top , left , h + top , w + left } ;
1919 RGBForeColor( &darkShadow ) ;
1920 FrameRect( &rect ) ;
1921 }
1922 }
1923
1924 void wxWindowMac::RemoveChild( wxWindowBase *child )
1925 {
1926 if ( child == m_hScrollBar )
1927 m_hScrollBar = NULL ;
1928 if ( child == m_vScrollBar )
1929 m_vScrollBar = NULL ;
1930
1931 wxWindowBase::RemoveChild( child ) ;
1932 }
1933
1934 // New function that will replace some of the above.
1935 void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible,
1936 int range, bool refresh)
1937 {
1938 if ( orient == wxHORIZONTAL )
1939 {
1940 if ( m_hScrollBar )
1941 {
1942 if ( range == 0 || thumbVisible >= range )
1943 {
1944 if ( m_hScrollBar->IsShown() )
1945 m_hScrollBar->Show(false) ;
1946 }
1947 else
1948 {
1949 if ( !m_hScrollBar->IsShown() )
1950 m_hScrollBar->Show(true) ;
1951 m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
1952 }
1953 }
1954 }
1955 else
1956 {
1957 if ( m_vScrollBar )
1958 {
1959 if ( range == 0 || thumbVisible >= range )
1960 {
1961 if ( m_vScrollBar->IsShown() )
1962 m_vScrollBar->Show(false) ;
1963 }
1964 else
1965 {
1966 if ( !m_vScrollBar->IsShown() )
1967 m_vScrollBar->Show(true) ;
1968 m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
1969 }
1970 }
1971 }
1972 MacRepositionScrollBars() ;
1973 }
1974
1975 // Does a physical scroll
1976 void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
1977 {
1978 if( dx == 0 && dy ==0 )
1979 return ;
1980
1981
1982 {
1983 wxClientDC dc(this) ;
1984 wxMacPortSetter helper(&dc) ;
1985
1986 int width , height ;
1987 GetClientSize( &width , &height ) ;
1988
1989
1990 wxPoint pos;
1991 pos.x = pos.y = 0;
1992
1993 Rect scrollrect;
1994 // TODO take out the boundaries
1995 GetControlBounds( (ControlRef) m_macControl, &scrollrect);
1996
1997 RgnHandle updateRgn = NewRgn() ;
1998 if ( rect )
1999 {
2000 Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) ,
2001 dc.XLOG2DEVMAC(rect->x + rect->width) } ;
2002 SectRect( &scrollrect , &r , &scrollrect ) ;
2003 }
2004 ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
2005 #if TARGET_CARBON
2006 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
2007 // but it seems the update only refreshes the background of the control, rather than calling
2008 // kEventControlDraw, so we need to force a proper update here. There has to be a better
2009 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
2010 Update();
2011 #endif
2012 // we also have to scroll the update rgn in this rectangle
2013 // in order not to loose updates
2014 #if !TARGET_CARBON
2015 WindowRef rootWindow = (WindowRef) MacGetTopLevelWindowRef() ;
2016 RgnHandle formerUpdateRgn = NewRgn() ;
2017 RgnHandle scrollRgn = NewRgn() ;
2018 RectRgn( scrollRgn , &scrollrect ) ;
2019 GetWindowUpdateRgn( rootWindow , formerUpdateRgn ) ;
2020 Point pt = {0,0} ;
2021 LocalToGlobal( &pt ) ;
2022 OffsetRgn( formerUpdateRgn , -pt.h , -pt.v ) ;
2023 SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
2024 if ( !EmptyRgn( formerUpdateRgn ) )
2025 {
2026 MacOffsetRgn( formerUpdateRgn , dx , dy ) ;
2027 SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
2028 InvalWindowRgn(rootWindow , formerUpdateRgn ) ;
2029 }
2030 InvalWindowRgn(rootWindow , updateRgn ) ;
2031 DisposeRgn( updateRgn ) ;
2032 DisposeRgn( formerUpdateRgn ) ;
2033 DisposeRgn( scrollRgn ) ;
2034 #endif
2035 }
2036
2037 for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())
2038 {
2039 wxWindowMac *child = node->GetData();
2040 if (child == m_vScrollBar) continue;
2041 if (child == m_hScrollBar) continue;
2042 if (child->IsTopLevel()) continue;
2043
2044 int x,y;
2045 child->GetPosition( &x, &y );
2046 int w,h;
2047 child->GetSize( &w, &h );
2048 if (rect)
2049 {
2050 wxRect rc(x,y,w,h);
2051 if (rect->Intersects(rc))
2052 child->SetSize( x+dx, y+dy, w, h );
2053 }
2054 else
2055 {
2056 child->SetSize( x+dx, y+dy, w, h );
2057 }
2058 }
2059
2060 // TODO remove, was moved higher up Update() ;
2061
2062 }
2063
2064 void wxWindowMac::MacOnScroll(wxScrollEvent &event )
2065 {
2066 if ( event.m_eventObject == m_vScrollBar || event.m_eventObject == m_hScrollBar )
2067 {
2068 wxScrollWinEvent wevent;
2069 wevent.SetPosition(event.GetPosition());
2070 wevent.SetOrientation(event.GetOrientation());
2071 wevent.m_eventObject = this;
2072
2073 if (event.m_eventType == wxEVT_SCROLL_TOP)
2074 wevent.m_eventType = wxEVT_SCROLLWIN_TOP;
2075 else if (event.m_eventType == wxEVT_SCROLL_BOTTOM)
2076 wevent.m_eventType = wxEVT_SCROLLWIN_BOTTOM;
2077 else if (event.m_eventType == wxEVT_SCROLL_LINEUP)
2078 wevent.m_eventType = wxEVT_SCROLLWIN_LINEUP;
2079 else if (event.m_eventType == wxEVT_SCROLL_LINEDOWN)
2080 wevent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
2081 else if (event.m_eventType == wxEVT_SCROLL_PAGEUP)
2082 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEUP;
2083 else if (event.m_eventType == wxEVT_SCROLL_PAGEDOWN)
2084 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
2085 else if (event.m_eventType == wxEVT_SCROLL_THUMBTRACK)
2086 wevent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
2087 else if (event.m_eventType == wxEVT_SCROLL_THUMBRELEASE)
2088 wevent.m_eventType = wxEVT_SCROLLWIN_THUMBRELEASE;
2089
2090 GetEventHandler()->ProcessEvent(wevent);
2091 }
2092 }
2093
2094 // Get the window with the focus
2095 wxWindowMac *wxWindowBase::FindFocus()
2096 {
2097 return gFocusWindow ;
2098 }
2099
2100 void wxWindowMac::OnSetFocus(wxFocusEvent& event)
2101 {
2102 // panel wants to track the window which was the last to have focus in it,
2103 // so we want to set ourselves as the window which last had focus
2104 //
2105 // notice that it's also important to do it upwards the tree becaus
2106 // otherwise when the top level panel gets focus, it won't set it back to
2107 // us, but to some other sibling
2108
2109 // CS:don't know if this is still needed:
2110 //wxChildFocusEvent eventFocus(this);
2111 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2112
2113 event.Skip();
2114 }
2115
2116 void wxWindowMac::OnInternalIdle()
2117 {
2118 // This calls the UI-update mechanism (querying windows for
2119 // menu/toolbar/control state information)
2120 if (wxUpdateUIEvent::CanUpdate(this))
2121 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
2122 }
2123
2124 // Raise the window to the top of the Z order
2125 void wxWindowMac::Raise()
2126 {
2127 }
2128
2129 // Lower the window to the bottom of the Z order
2130 void wxWindowMac::Lower()
2131 {
2132 }
2133
2134
2135 // static wxWindow *gs_lastWhich = NULL;
2136
2137 bool wxWindowMac::MacSetupCursor( const wxPoint& pt)
2138 {
2139 // first trigger a set cursor event
2140
2141 wxPoint clientorigin = GetClientAreaOrigin() ;
2142 wxSize clientsize = GetClientSize() ;
2143 wxCursor cursor ;
2144 if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) )
2145 {
2146 wxSetCursorEvent event( pt.x , pt.y );
2147
2148 bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event);
2149 if ( processedEvtSetCursor && event.HasCursor() )
2150 {
2151 cursor = event.GetCursor() ;
2152 }
2153 else
2154 {
2155
2156 // the test for processedEvtSetCursor is here to prevent using m_cursor
2157 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2158 // it - this is a way to say that our cursor shouldn't be used for this
2159 // point
2160 if ( !processedEvtSetCursor && m_cursor.Ok() )
2161 {
2162 cursor = m_cursor ;
2163 }
2164 if ( wxIsBusy() )
2165 {
2166 }
2167 else
2168 {
2169 if ( !GetParent() )
2170 cursor = *wxSTANDARD_CURSOR ;
2171 }
2172 }
2173 if ( cursor.Ok() )
2174 cursor.MacInstall() ;
2175 }
2176 return cursor.Ok() ;
2177 }
2178
2179 wxString wxWindowMac::MacGetToolTipString( wxPoint &pt )
2180 {
2181 if ( m_tooltip )
2182 {
2183 return m_tooltip->GetTip() ;
2184 }
2185 return wxEmptyString ;
2186 }
2187
2188 void wxWindowMac::Update()
2189 {
2190 #if TARGET_API_MAC_OSX
2191 HIViewSetNeedsDisplay( (ControlRef) m_macControl , true ) ;
2192 #else
2193 ::Draw1Control( (ControlRef) m_macControl ) ;
2194 #endif
2195 }
2196
2197 wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const
2198 {
2199 wxTopLevelWindowMac* win = NULL ;
2200 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
2201 if ( window )
2202 {
2203 win = wxFindWinFromMacWindow( window ) ;
2204 }
2205 return win ;
2206 }
2207 wxRegion wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures )
2208 {
2209
2210 Rect r ;
2211 RgnHandle visRgn = NewRgn() ;
2212 RgnHandle tempRgn = NewRgn() ;
2213 if ( IsControlVisible( (ControlRef) m_macControl ) )
2214 {
2215 GetControlBounds( (ControlRef) m_macControl , &r ) ;
2216 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2217 {
2218 MacRootWindowToWindow( &r.left , & r.top ) ;
2219 MacRootWindowToWindow( &r.right , & r.bottom ) ;
2220 }
2221 else
2222 {
2223 r.right -= r.left ;
2224 r.bottom -= r.top ;
2225 r.left = 0 ;
2226 r.top = 0 ;
2227 }
2228 if ( includeOuterStructures )
2229 InsetRect( &r , -3 , -3 ) ;
2230 RectRgn( visRgn , &r ) ;
2231 if ( !IsTopLevel() )
2232 {
2233 wxWindow* child = this ;
2234 wxWindow* parent = child->GetParent() ;
2235 while( parent )
2236 {
2237 int x , y ;
2238 wxSize size ;
2239 // we have to find a better clipping algorithm here, in order not to clip things
2240 // positioned like status and toolbar
2241 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2242 {
2243 size = parent->GetSize() ;
2244 x = y = 0 ;
2245 }
2246 else
2247 {
2248 size = parent->GetClientSize() ;
2249 wxPoint origin = parent->GetClientAreaOrigin() ;
2250 x = origin.x ;
2251 y = origin.y ;
2252 }
2253 parent->MacWindowToRootWindow( &x, &y ) ;
2254 MacRootWindowToWindow( &x , &y ) ;
2255
2256 SetRectRgn( tempRgn ,
2257 x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() ,
2258 x + size.x - parent->MacGetRightBorderSize(),
2259 y + size.y - parent->MacGetBottomBorderSize()) ;
2260
2261 SectRgn( visRgn , tempRgn , visRgn ) ;
2262 if ( parent->IsTopLevel() )
2263 break ;
2264 child = parent ;
2265 parent = child->GetParent() ;
2266 }
2267 }
2268 }
2269
2270 wxRegion vis = visRgn ;
2271 DisposeRgn( visRgn ) ;
2272 DisposeRgn( tempRgn ) ;
2273 return vis ;
2274 }
2275
2276 /*
2277 This function must not change the updatergn !
2278 */
2279 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time )
2280 {
2281 RgnHandle updatergn = (RgnHandle) updatergnr ;
2282 bool handled = false ;
2283
2284 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2285 {
2286 RgnHandle newupdate = NewRgn() ;
2287 wxSize point = GetClientSize() ;
2288 wxPoint origin = GetClientAreaOrigin() ;
2289 SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ;
2290 SectRgn( newupdate , updatergn , newupdate ) ;
2291 OffsetRgn( newupdate , -origin.x , -origin.y ) ;
2292 m_updateRegion = newupdate ;
2293 DisposeRgn( newupdate ) ;
2294 }
2295
2296 if ( !EmptyRgn(updatergn) )
2297 {
2298 wxWindowDC dc(this);
2299 if (!EmptyRgn(updatergn))
2300 dc.SetClippingRegion(wxRegion(updatergn));
2301
2302 wxEraseEvent eevent( GetId(), &dc );
2303 eevent.SetEventObject( this );
2304 GetEventHandler()->ProcessEvent( eevent );
2305
2306 if ( !m_updateRegion.Empty() )
2307 {
2308 // paint the window itself
2309 wxPaintEvent event;
2310 event.m_timeStamp = time ;
2311 event.SetEventObject(this);
2312 handled = GetEventHandler()->ProcessEvent(event);
2313
2314 // paint custom borders
2315 wxNcPaintEvent eventNc( GetId() );
2316 eventNc.SetEventObject( this );
2317 GetEventHandler()->ProcessEvent( eventNc );
2318 }
2319 }
2320 return handled ;
2321 }
2322
2323 void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase)
2324 {
2325 RgnHandle updatergn = (RgnHandle) updatergnr ;
2326 // updatergn is always already clipped to our boundaries
2327 // if we are in compositing mode then it is in relative to the upper left of the control
2328 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2329 // of the toplevel window
2330 // it is in window coordinates, not in client coordinates
2331
2332 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2333 RgnHandle ownUpdateRgn = NewRgn() ;
2334 CopyRgn( updatergn , ownUpdateRgn ) ;
2335
2336 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2337 {
2338 Rect bounds;
2339 UMAGetControlBoundsInWindowCoords( (ControlRef)m_macControl, &bounds );
2340 RgnHandle controlRgn = NewRgn();
2341 RectRgn( controlRgn, &bounds );
2342 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2343 // the window update region
2344 SectRgn( ownUpdateRgn, controlRgn, ownUpdateRgn );
2345 DisposeRgn( controlRgn );
2346
2347 //KO: convert ownUpdateRgn to local coordinates
2348 OffsetRgn( ownUpdateRgn, -bounds.left, -bounds.top );
2349 }
2350
2351 MacDoRedraw( ownUpdateRgn , time ) ;
2352 DisposeRgn( ownUpdateRgn ) ;
2353
2354 }
2355
2356 WXWindow wxWindowMac::MacGetTopLevelWindowRef() const
2357 {
2358 wxWindowMac *iter = (wxWindowMac*)this ;
2359
2360 while( iter )
2361 {
2362 if ( iter->IsTopLevel() )
2363 return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ;
2364
2365 iter = iter->GetParent() ;
2366 }
2367 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2368 return NULL ;
2369 }
2370
2371 void wxWindowMac::MacCreateScrollBars( long style )
2372 {
2373 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ;
2374
2375 bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
2376 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ;
2377 int width, height ;
2378 GetClientSize( &width , &height ) ;
2379
2380 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
2381 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
2382 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
2383 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
2384
2385 m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint,
2386 vSize , wxVERTICAL);
2387
2388 if ( style & wxVSCROLL )
2389 {
2390
2391 }
2392 else
2393 {
2394 m_vScrollBar->Show(false) ;
2395 }
2396 m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint,
2397 hSize , wxHORIZONTAL);
2398 if ( style & wxHSCROLL )
2399 {
2400 }
2401 else
2402 {
2403 m_hScrollBar->Show(false) ;
2404 }
2405
2406 // because the create does not take into account the client area origin
2407 MacRepositionScrollBars() ; // we might have a real position shift
2408 }
2409
2410 void wxWindowMac::MacRepositionScrollBars()
2411 {
2412 bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
2413 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ;
2414
2415 // get real client area
2416
2417 int width ;
2418 int height ;
2419 GetSize( &width , &height ) ;
2420
2421 width -= MacGetLeftBorderSize() + MacGetRightBorderSize();
2422 height -= MacGetTopBorderSize() + MacGetBottomBorderSize();
2423
2424 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
2425 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
2426 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
2427 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
2428
2429 int x = 0 ;
2430 int y = 0 ;
2431 int w ;
2432 int h ;
2433 GetSize( &w , &h ) ;
2434
2435 MacClientToRootWindow( &x , &y ) ;
2436 MacClientToRootWindow( &w , &h ) ;
2437
2438 wxWindowMac *iter = (wxWindowMac*)this ;
2439
2440 int totW = 10000 , totH = 10000;
2441 while( iter )
2442 {
2443 if ( iter->IsTopLevel() )
2444 {
2445 iter->GetSize( &totW , &totH ) ;
2446 break ;
2447 }
2448
2449 iter = iter->GetParent() ;
2450 }
2451
2452 if ( x == 0 )
2453 {
2454 hPoint.x = -1 ;
2455 hSize.x += 1 ;
2456 }
2457 if ( y == 0 )
2458 {
2459 vPoint.y = -1 ;
2460 vSize.y += 1 ;
2461 }
2462
2463 if ( w-x >= totW )
2464 {
2465 hSize.x += 1 ;
2466 vPoint.x += 1 ;
2467 }
2468
2469 if ( h-y >= totH )
2470 {
2471 vSize.y += 1 ;
2472 hPoint.y += 1 ;
2473 }
2474
2475 if ( m_vScrollBar )
2476 {
2477 m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE);
2478 }
2479 if ( m_hScrollBar )
2480 {
2481 m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE);
2482 }
2483 }
2484
2485 bool wxWindowMac::AcceptsFocus() const
2486 {
2487 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2488 }
2489
2490 void wxWindowMac::MacSuperChangedPosition()
2491 {
2492 // only window-absolute structures have to be moved i.e. controls
2493
2494 wxWindowListNode *node = GetChildren().GetFirst();
2495 while ( node )
2496 {
2497 wxWindowMac *child = node->GetData();
2498 child->MacSuperChangedPosition() ;
2499 node = node->GetNext();
2500 }
2501 }
2502
2503 void wxWindowMac::MacTopLevelWindowChangedPosition()
2504 {
2505 // only screen-absolute structures have to be moved i.e. glcanvas
2506
2507 wxWindowListNode *node = GetChildren().GetFirst();
2508 while ( node )
2509 {
2510 wxWindowMac *child = node->GetData();
2511 child->MacTopLevelWindowChangedPosition() ;
2512 node = node->GetNext();
2513 }
2514 }
2515
2516 long wxWindowMac::MacGetLeftBorderSize( ) const
2517 {
2518 if( IsTopLevel() )
2519 return 0 ;
2520
2521 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
2522 {
2523 SInt32 border = 3 ;
2524 #if wxMAC_USE_THEME_BORDER
2525 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2526 #endif
2527 return border ;
2528 }
2529 else if ( m_windowStyle &wxDOUBLE_BORDER)
2530 {
2531 SInt32 border = 3 ;
2532 #if wxMAC_USE_THEME_BORDER
2533 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2534 #endif
2535 return border ;
2536 }
2537 else if (m_windowStyle &wxSIMPLE_BORDER)
2538 {
2539 return 1 ;
2540 }
2541 return 0 ;
2542 }
2543
2544 long wxWindowMac::MacGetRightBorderSize( ) const
2545 {
2546 // they are all symmetric in mac themes
2547 return MacGetLeftBorderSize() ;
2548 }
2549
2550 long wxWindowMac::MacGetTopBorderSize( ) const
2551 {
2552 // they are all symmetric in mac themes
2553 return MacGetLeftBorderSize() ;
2554 }
2555
2556 long wxWindowMac::MacGetBottomBorderSize( ) const
2557 {
2558 // they are all symmetric in mac themes
2559 return MacGetLeftBorderSize() ;
2560 }
2561
2562 long wxWindowMac::MacRemoveBordersFromStyle( long style )
2563 {
2564 return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ;
2565 }
2566
2567 // Find the wxWindowMac at the current mouse position, returning the mouse
2568 // position.
2569 wxWindowMac* wxFindWindowAtPointer(wxPoint& pt)
2570 {
2571 pt = wxGetMousePosition();
2572 wxWindowMac* found = wxFindWindowAtPoint(pt);
2573 return found;
2574 }
2575
2576 // Get the current mouse position.
2577 wxPoint wxGetMousePosition()
2578 {
2579 int x, y;
2580 wxGetMousePosition(& x, & y);
2581 return wxPoint(x, y);
2582 }
2583
2584 void wxWindowMac::OnMouseEvent( wxMouseEvent &event )
2585 {
2586 if ( event.GetEventType() == wxEVT_RIGHT_DOWN )
2587 {
2588 // copied from wxGTK : CS
2589 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2590 // except that:
2591 //
2592 // (a) it's a command event and so is propagated to the parent
2593 // (b) under MSW it can be generated from kbd too
2594 // (c) it uses screen coords (because of (a))
2595 wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU,
2596 this->GetId(),
2597 this->ClientToScreen(event.GetPosition()));
2598 if ( ! GetEventHandler()->ProcessEvent(evtCtx) )
2599 event.Skip() ;
2600 }
2601 else if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK )
2602 {
2603
2604 int x = event.m_x ;
2605 int y = event.m_y ;
2606
2607 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2608 {
2609 // OS Needs it in tlw content area coordinates
2610 MacClientToRootWindow( &x , &y ) ;
2611 }
2612 else
2613 {
2614 // OS Needs it in window not client coordinates
2615 wxPoint origin = GetClientAreaOrigin() ;
2616 x += origin.x ;
2617 y += origin.y ;
2618 }
2619 Point localwhere ;
2620 SInt16 controlpart ;
2621
2622 localwhere.h = x ;
2623 localwhere.v = y ;
2624
2625 short modifiers = 0;
2626
2627 if ( !event.m_leftDown && !event.m_rightDown )
2628 modifiers |= btnState ;
2629
2630 if ( event.m_shiftDown )
2631 modifiers |= shiftKey ;
2632
2633 if ( event.m_controlDown )
2634 modifiers |= controlKey ;
2635
2636 if ( event.m_altDown )
2637 modifiers |= optionKey ;
2638
2639 if ( event.m_metaDown )
2640 modifiers |= cmdKey ;
2641
2642 bool handled = false ;
2643
2644 if ( ::IsControlActive( (ControlRef) m_macControl ) )
2645 {
2646 controlpart = ::HandleControlClick( (ControlRef) m_macControl , localwhere , modifiers , (ControlActionUPP) -1 ) ;
2647 wxTheApp->s_lastMouseDown = 0 ;
2648 if ( controlpart != kControlNoPart )
2649 {
2650 MacHandleControlClick((WXWidget) (ControlRef) m_macControl , controlpart , false /* mouse not down anymore */ ) ;
2651 handled = true ;
2652 }
2653 }
2654 if ( !handled )
2655 event.Skip() ;
2656 }
2657 else
2658 {
2659 event.Skip() ;
2660 }
2661 }
2662
2663 void wxWindowMac::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) )
2664 {
2665 wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ;
2666 }
2667
2668 Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size )
2669 {
2670 int x ,y , w ,h ;
2671
2672 window->MacGetBoundsForControl( pos , size , x , y, w, h ) ;
2673 Rect bounds = { y , x , y+h , x+w };
2674 return bounds ;
2675 }
2676
2677