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