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