]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/window.cpp
Commited slighly modified fix by David Parsons.
[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 void wxWindowMac::Thaw()
1859 {
1860 #if TARGET_API_MAC_OSX
1861 wxASSERT_MSG( m_frozenness > 0, _T("Thaw() without matching Freeze()") );
1862
1863 if ( !--m_frozenness )
1864 {
1865 HIViewSetDrawingEnabled( (HIViewRef) m_macControl , true ) ;
1866 HIViewSetNeedsDisplay( (HIViewRef) m_macControl , true ) ;
1867 }
1868 #endif
1869 }
1870
1871 void wxWindowMac::MacRedrawControl()
1872 {
1873 /*
1874 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
1875 {
1876 #if TARGET_API_MAC_CARBON
1877 Update() ;
1878 #else
1879 wxClientDC dc(this) ;
1880 wxMacPortSetter helper(&dc) ;
1881 wxMacWindowClipper clipper(this) ;
1882 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
1883 UMADrawControl( (ControlRef) m_macControl ) ;
1884 #endif
1885 }
1886 */
1887 }
1888
1889 /* TODO
1890 void wxWindowMac::OnPaint(wxPaintEvent& event)
1891 {
1892 // why don't we skip that here ?
1893 }
1894 */
1895
1896 wxWindowMac *wxGetActiveWindow()
1897 {
1898 // actually this is a windows-only concept
1899 return NULL;
1900 }
1901
1902 // Coordinates relative to the window
1903 void wxWindowMac::WarpPointer (int x_pos, int y_pos)
1904 {
1905 // We really don't move the mouse programmatically under Mac.
1906 }
1907
1908 void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
1909 {
1910 if ( m_macBackgroundBrush.Ok() == false || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT )
1911 {
1912 event.Skip() ;
1913 }
1914 else
1915 event.GetDC()->Clear() ;
1916 }
1917
1918 void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
1919 {
1920 wxWindowDC dc(this) ;
1921 wxMacPortSetter helper(&dc) ;
1922
1923 MacPaintBorders( dc.m_macLocalOrigin.x , dc.m_macLocalOrigin.y) ;
1924 }
1925
1926 int wxWindowMac::GetScrollPos(int orient) const
1927 {
1928 if ( orient == wxHORIZONTAL )
1929 {
1930 if ( m_hScrollBar )
1931 return m_hScrollBar->GetThumbPosition() ;
1932 }
1933 else
1934 {
1935 if ( m_vScrollBar )
1936 return m_vScrollBar->GetThumbPosition() ;
1937 }
1938 return 0;
1939 }
1940
1941 // This now returns the whole range, not just the number
1942 // of positions that we can scroll.
1943 int wxWindowMac::GetScrollRange(int orient) const
1944 {
1945 if ( orient == wxHORIZONTAL )
1946 {
1947 if ( m_hScrollBar )
1948 return m_hScrollBar->GetRange() ;
1949 }
1950 else
1951 {
1952 if ( m_vScrollBar )
1953 return m_vScrollBar->GetRange() ;
1954 }
1955 return 0;
1956 }
1957
1958 int wxWindowMac::GetScrollThumb(int orient) const
1959 {
1960 if ( orient == wxHORIZONTAL )
1961 {
1962 if ( m_hScrollBar )
1963 return m_hScrollBar->GetThumbSize() ;
1964 }
1965 else
1966 {
1967 if ( m_vScrollBar )
1968 return m_vScrollBar->GetThumbSize() ;
1969 }
1970 return 0;
1971 }
1972
1973 void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh)
1974 {
1975 if ( orient == wxHORIZONTAL )
1976 {
1977 if ( m_hScrollBar )
1978 m_hScrollBar->SetThumbPosition( pos ) ;
1979 }
1980 else
1981 {
1982 if ( m_vScrollBar )
1983 m_vScrollBar->SetThumbPosition( pos ) ;
1984 }
1985 }
1986
1987 void wxWindowMac::MacPaintBorders( int left , int top )
1988 {
1989 if( IsTopLevel() )
1990 return ;
1991
1992 int major,minor;
1993 wxGetOsVersion( &major, &minor );
1994
1995 RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ;
1996 RGBColor face = { 0xDDDD, 0xDDDD , 0xDDDD } ;
1997
1998 RGBColor darkShadow = { 0x0000, 0x0000 , 0x0000 } ;
1999 RGBColor lightShadow = { 0x4444, 0x4444 , 0x4444 } ;
2000 // OS X has lighter border edges than classic:
2001 if (major >= 10)
2002 {
2003 darkShadow.red = 0x8E8E;
2004 darkShadow.green = 0x8E8E;
2005 darkShadow.blue = 0x8E8E;
2006 lightShadow.red = 0xBDBD;
2007 lightShadow.green = 0xBDBD;
2008 lightShadow.blue = 0xBDBD;
2009 }
2010
2011 PenNormal() ;
2012
2013 int w , h ;
2014 GetSize( &w , &h ) ;
2015 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
2016 {
2017 #if wxMAC_USE_THEME_BORDER
2018 Rect rect = { top , left , m_height + top , m_width + left } ;
2019 SInt32 border = 0 ;
2020 /*
2021 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2022 InsetRect( &rect , border , border );
2023 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2024 */
2025
2026 DrawThemePrimaryGroup(&rect ,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2027 #else
2028 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
2029 RGBForeColor( &face );
2030 MoveTo( left + 0 , top + h - 2 );
2031 LineTo( left + 0 , top + 0 );
2032 LineTo( left + w - 2 , top + 0 );
2033
2034 MoveTo( left + 2 , top + h - 3 );
2035 LineTo( left + w - 3 , top + h - 3 );
2036 LineTo( left + w - 3 , top + 2 );
2037
2038 RGBForeColor( sunken ? &face : &darkShadow );
2039 MoveTo( left + 0 , top + h - 1 );
2040 LineTo( left + w - 1 , top + h - 1 );
2041 LineTo( left + w - 1 , top + 0 );
2042
2043 RGBForeColor( sunken ? &lightShadow : &white );
2044 MoveTo( left + 1 , top + h - 3 );
2045 LineTo( left + 1, top + 1 );
2046 LineTo( left + w - 3 , top + 1 );
2047
2048 RGBForeColor( sunken ? &white : &lightShadow );
2049 MoveTo( left + 1 , top + h - 2 );
2050 LineTo( left + w - 2 , top + h - 2 );
2051 LineTo( left + w - 2 , top + 1 );
2052
2053 RGBForeColor( sunken ? &darkShadow : &face );
2054 MoveTo( left + 2 , top + h - 4 );
2055 LineTo( left + 2 , top + 2 );
2056 LineTo( left + w - 4 , top + 2 );
2057 #endif
2058 }
2059 else if (HasFlag(wxSIMPLE_BORDER))
2060 {
2061 Rect rect = { top , left , h + top , w + left } ;
2062 RGBForeColor( &darkShadow ) ;
2063 FrameRect( &rect ) ;
2064 }
2065 }
2066
2067 void wxWindowMac::RemoveChild( wxWindowBase *child )
2068 {
2069 if ( child == m_hScrollBar )
2070 m_hScrollBar = NULL ;
2071 if ( child == m_vScrollBar )
2072 m_vScrollBar = NULL ;
2073
2074 wxWindowBase::RemoveChild( child ) ;
2075 }
2076
2077 // New function that will replace some of the above.
2078 void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible,
2079 int range, bool refresh)
2080 {
2081 if ( orient == wxHORIZONTAL )
2082 {
2083 if ( m_hScrollBar )
2084 {
2085 if ( range == 0 || thumbVisible >= range )
2086 {
2087 if ( m_hScrollBar->IsShown() )
2088 m_hScrollBar->Show(false) ;
2089 }
2090 else
2091 {
2092 if ( !m_hScrollBar->IsShown() )
2093 m_hScrollBar->Show(true) ;
2094 m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
2095 }
2096 }
2097 }
2098 else
2099 {
2100 if ( m_vScrollBar )
2101 {
2102 if ( range == 0 || thumbVisible >= range )
2103 {
2104 if ( m_vScrollBar->IsShown() )
2105 m_vScrollBar->Show(false) ;
2106 }
2107 else
2108 {
2109 if ( !m_vScrollBar->IsShown() )
2110 m_vScrollBar->Show(true) ;
2111 m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
2112 }
2113 }
2114 }
2115 MacRepositionScrollBars() ;
2116 }
2117
2118 // Does a physical scroll
2119 void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
2120 {
2121 if( dx == 0 && dy ==0 )
2122 return ;
2123
2124
2125 {
2126 wxClientDC dc(this) ;
2127 wxMacPortSetter helper(&dc) ;
2128
2129 int width , height ;
2130 GetClientSize( &width , &height ) ;
2131
2132
2133 wxPoint pos;
2134 pos.x = pos.y = 0;
2135
2136 Rect scrollrect;
2137 // TODO take out the boundaries
2138 GetControlBounds( (ControlRef) m_macControl, &scrollrect);
2139
2140 RgnHandle updateRgn = NewRgn() ;
2141 if ( rect )
2142 {
2143 Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) ,
2144 dc.XLOG2DEVMAC(rect->x + rect->width) } ;
2145 SectRect( &scrollrect , &r , &scrollrect ) ;
2146 }
2147 ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
2148 #if TARGET_CARBON
2149 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
2150 // but it seems the update only refreshes the background of the control, rather than calling
2151 // kEventControlDraw, so we need to force a proper update here. There has to be a better
2152 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
2153 Update();
2154 #endif
2155 // we also have to scroll the update rgn in this rectangle
2156 // in order not to loose updates
2157 #if !TARGET_CARBON
2158 WindowRef rootWindow = (WindowRef) MacGetTopLevelWindowRef() ;
2159 RgnHandle formerUpdateRgn = NewRgn() ;
2160 RgnHandle scrollRgn = NewRgn() ;
2161 RectRgn( scrollRgn , &scrollrect ) ;
2162 GetWindowUpdateRgn( rootWindow , formerUpdateRgn ) ;
2163 Point pt = {0,0} ;
2164 LocalToGlobal( &pt ) ;
2165 OffsetRgn( formerUpdateRgn , -pt.h , -pt.v ) ;
2166 SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
2167 if ( !EmptyRgn( formerUpdateRgn ) )
2168 {
2169 MacOffsetRgn( formerUpdateRgn , dx , dy ) ;
2170 SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
2171 InvalWindowRgn(rootWindow , formerUpdateRgn ) ;
2172 }
2173 InvalWindowRgn(rootWindow , updateRgn ) ;
2174 DisposeRgn( updateRgn ) ;
2175 DisposeRgn( formerUpdateRgn ) ;
2176 DisposeRgn( scrollRgn ) ;
2177 #endif
2178 }
2179
2180 for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())
2181 {
2182 wxWindowMac *child = node->GetData();
2183 if (child == m_vScrollBar) continue;
2184 if (child == m_hScrollBar) continue;
2185 if (child->IsTopLevel()) continue;
2186
2187 int x,y;
2188 child->GetPosition( &x, &y );
2189 int w,h;
2190 child->GetSize( &w, &h );
2191 if (rect)
2192 {
2193 wxRect rc(x,y,w,h);
2194 if (rect->Intersects(rc))
2195 child->SetSize( x+dx, y+dy, w, h );
2196 }
2197 else
2198 {
2199 child->SetSize( x+dx, y+dy, w, h );
2200 }
2201 }
2202
2203 // TODO remove, was moved higher up Update() ;
2204
2205 }
2206
2207 void wxWindowMac::MacOnScroll(wxScrollEvent &event )
2208 {
2209 if ( event.m_eventObject == m_vScrollBar || event.m_eventObject == m_hScrollBar )
2210 {
2211 wxScrollWinEvent wevent;
2212 wevent.SetPosition(event.GetPosition());
2213 wevent.SetOrientation(event.GetOrientation());
2214 wevent.m_eventObject = this;
2215
2216 if (event.m_eventType == wxEVT_SCROLL_TOP)
2217 wevent.m_eventType = wxEVT_SCROLLWIN_TOP;
2218 else if (event.m_eventType == wxEVT_SCROLL_BOTTOM)
2219 wevent.m_eventType = wxEVT_SCROLLWIN_BOTTOM;
2220 else if (event.m_eventType == wxEVT_SCROLL_LINEUP)
2221 wevent.m_eventType = wxEVT_SCROLLWIN_LINEUP;
2222 else if (event.m_eventType == wxEVT_SCROLL_LINEDOWN)
2223 wevent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
2224 else if (event.m_eventType == wxEVT_SCROLL_PAGEUP)
2225 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEUP;
2226 else if (event.m_eventType == wxEVT_SCROLL_PAGEDOWN)
2227 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
2228 else if (event.m_eventType == wxEVT_SCROLL_THUMBTRACK)
2229 wevent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
2230 else if (event.m_eventType == wxEVT_SCROLL_THUMBRELEASE)
2231 wevent.m_eventType = wxEVT_SCROLLWIN_THUMBRELEASE;
2232
2233 GetEventHandler()->ProcessEvent(wevent);
2234 }
2235 }
2236
2237 // Get the window with the focus
2238 wxWindowMac *wxWindowBase::FindFocus()
2239 {
2240 return gFocusWindow ;
2241 }
2242
2243 void wxWindowMac::OnSetFocus(wxFocusEvent& event)
2244 {
2245 // panel wants to track the window which was the last to have focus in it,
2246 // so we want to set ourselves as the window which last had focus
2247 //
2248 // notice that it's also important to do it upwards the tree becaus
2249 // otherwise when the top level panel gets focus, it won't set it back to
2250 // us, but to some other sibling
2251
2252 // CS:don't know if this is still needed:
2253 //wxChildFocusEvent eventFocus(this);
2254 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2255
2256 event.Skip();
2257 }
2258
2259 void wxWindowMac::OnInternalIdle()
2260 {
2261 // This calls the UI-update mechanism (querying windows for
2262 // menu/toolbar/control state information)
2263 if (wxUpdateUIEvent::CanUpdate(this))
2264 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
2265 }
2266
2267 // Raise the window to the top of the Z order
2268 void wxWindowMac::Raise()
2269 {
2270 }
2271
2272 // Lower the window to the bottom of the Z order
2273 void wxWindowMac::Lower()
2274 {
2275 }
2276
2277
2278 // static wxWindow *gs_lastWhich = NULL;
2279
2280 bool wxWindowMac::MacSetupCursor( const wxPoint& pt)
2281 {
2282 // first trigger a set cursor event
2283
2284 wxPoint clientorigin = GetClientAreaOrigin() ;
2285 wxSize clientsize = GetClientSize() ;
2286 wxCursor cursor ;
2287 if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) )
2288 {
2289 wxSetCursorEvent event( pt.x , pt.y );
2290
2291 bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event);
2292 if ( processedEvtSetCursor && event.HasCursor() )
2293 {
2294 cursor = event.GetCursor() ;
2295 }
2296 else
2297 {
2298
2299 // the test for processedEvtSetCursor is here to prevent using m_cursor
2300 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2301 // it - this is a way to say that our cursor shouldn't be used for this
2302 // point
2303 if ( !processedEvtSetCursor && m_cursor.Ok() )
2304 {
2305 cursor = m_cursor ;
2306 }
2307 if ( wxIsBusy() )
2308 {
2309 }
2310 else
2311 {
2312 if ( !GetParent() )
2313 cursor = *wxSTANDARD_CURSOR ;
2314 }
2315 }
2316 if ( cursor.Ok() )
2317 cursor.MacInstall() ;
2318 }
2319 return cursor.Ok() ;
2320 }
2321
2322 wxString wxWindowMac::MacGetToolTipString( wxPoint &pt )
2323 {
2324 if ( m_tooltip )
2325 {
2326 return m_tooltip->GetTip() ;
2327 }
2328 return wxEmptyString ;
2329 }
2330
2331 void wxWindowMac::Update()
2332 {
2333 #if TARGET_API_MAC_OSX
2334 HIViewSetNeedsDisplay( (ControlRef) m_macControl , true ) ;
2335 #else
2336 ::Draw1Control( (ControlRef) m_macControl ) ;
2337 #endif
2338 }
2339
2340 wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const
2341 {
2342 wxTopLevelWindowMac* win = NULL ;
2343 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
2344 if ( window )
2345 {
2346 win = wxFindWinFromMacWindow( window ) ;
2347 }
2348 return win ;
2349 }
2350 wxRegion wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures )
2351 {
2352
2353 Rect r ;
2354 RgnHandle visRgn = NewRgn() ;
2355 RgnHandle tempRgn = NewRgn() ;
2356 if ( IsControlVisible( (ControlRef) m_macControl ) )
2357 {
2358 GetControlBounds( (ControlRef) m_macControl , &r ) ;
2359 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2360 {
2361 MacRootWindowToWindow( &r.left , & r.top ) ;
2362 MacRootWindowToWindow( &r.right , & r.bottom ) ;
2363 }
2364 else
2365 {
2366 r.right -= r.left ;
2367 r.bottom -= r.top ;
2368 r.left = 0 ;
2369 r.top = 0 ;
2370 }
2371 if ( includeOuterStructures )
2372 InsetRect( &r , -3 , -3 ) ;
2373 RectRgn( visRgn , &r ) ;
2374 if ( !IsTopLevel() )
2375 {
2376 wxWindow* child = this ;
2377 wxWindow* parent = child->GetParent() ;
2378 while( parent )
2379 {
2380 int x , y ;
2381 wxSize size ;
2382 // we have to find a better clipping algorithm here, in order not to clip things
2383 // positioned like status and toolbar
2384 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2385 {
2386 size = parent->GetSize() ;
2387 x = y = 0 ;
2388 }
2389 else
2390 {
2391 size = parent->GetClientSize() ;
2392 wxPoint origin = parent->GetClientAreaOrigin() ;
2393 x = origin.x ;
2394 y = origin.y ;
2395 }
2396 parent->MacWindowToRootWindow( &x, &y ) ;
2397 MacRootWindowToWindow( &x , &y ) ;
2398
2399 SetRectRgn( tempRgn ,
2400 x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() ,
2401 x + size.x - parent->MacGetRightBorderSize(),
2402 y + size.y - parent->MacGetBottomBorderSize()) ;
2403
2404 SectRgn( visRgn , tempRgn , visRgn ) ;
2405 if ( parent->IsTopLevel() )
2406 break ;
2407 child = parent ;
2408 parent = child->GetParent() ;
2409 }
2410 }
2411 }
2412
2413 wxRegion vis = visRgn ;
2414 DisposeRgn( visRgn ) ;
2415 DisposeRgn( tempRgn ) ;
2416 return vis ;
2417 }
2418
2419 /*
2420 This function must not change the updatergn !
2421 */
2422 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time )
2423 {
2424 RgnHandle updatergn = (RgnHandle) updatergnr ;
2425 bool handled = false ;
2426
2427 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2428 {
2429 RgnHandle newupdate = NewRgn() ;
2430 wxSize point = GetClientSize() ;
2431 wxPoint origin = GetClientAreaOrigin() ;
2432 SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ;
2433 SectRgn( newupdate , updatergn , newupdate ) ;
2434 OffsetRgn( newupdate , -origin.x , -origin.y ) ;
2435 m_updateRegion = newupdate ;
2436 DisposeRgn( newupdate ) ;
2437 }
2438
2439 if ( !EmptyRgn(updatergn) )
2440 {
2441 wxWindowDC dc(this);
2442 if (!EmptyRgn(updatergn))
2443 dc.SetClippingRegion(wxRegion(updatergn));
2444
2445 wxEraseEvent eevent( GetId(), &dc );
2446 eevent.SetEventObject( this );
2447 GetEventHandler()->ProcessEvent( eevent );
2448
2449 if ( !m_updateRegion.Empty() )
2450 {
2451 // paint the window itself
2452 wxPaintEvent event;
2453 event.m_timeStamp = time ;
2454 event.SetEventObject(this);
2455 handled = GetEventHandler()->ProcessEvent(event);
2456
2457 // paint custom borders
2458 wxNcPaintEvent eventNc( GetId() );
2459 eventNc.SetEventObject( this );
2460 GetEventHandler()->ProcessEvent( eventNc );
2461 }
2462 }
2463 return handled ;
2464 }
2465
2466 void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase)
2467 {
2468 RgnHandle updatergn = (RgnHandle) updatergnr ;
2469 // updatergn is always already clipped to our boundaries
2470 // if we are in compositing mode then it is in relative to the upper left of the control
2471 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2472 // of the toplevel window
2473 // it is in window coordinates, not in client coordinates
2474
2475 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2476 RgnHandle ownUpdateRgn = NewRgn() ;
2477 CopyRgn( updatergn , ownUpdateRgn ) ;
2478
2479 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2480 {
2481 Rect bounds;
2482 UMAGetControlBoundsInWindowCoords( (ControlRef)m_macControl, &bounds );
2483 RgnHandle controlRgn = NewRgn();
2484 RectRgn( controlRgn, &bounds );
2485 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2486 // the window update region
2487 SectRgn( ownUpdateRgn, controlRgn, ownUpdateRgn );
2488 DisposeRgn( controlRgn );
2489
2490 //KO: convert ownUpdateRgn to local coordinates
2491 OffsetRgn( ownUpdateRgn, -bounds.left, -bounds.top );
2492 }
2493
2494 MacDoRedraw( ownUpdateRgn , time ) ;
2495 DisposeRgn( ownUpdateRgn ) ;
2496
2497 }
2498
2499 WXWindow wxWindowMac::MacGetTopLevelWindowRef() const
2500 {
2501 wxWindowMac *iter = (wxWindowMac*)this ;
2502
2503 while( iter )
2504 {
2505 if ( iter->IsTopLevel() )
2506 return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ;
2507
2508 iter = iter->GetParent() ;
2509 }
2510 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2511 return NULL ;
2512 }
2513
2514 void wxWindowMac::MacCreateScrollBars( long style )
2515 {
2516 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ;
2517
2518 bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
2519 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ;
2520 int width, height ;
2521 GetClientSize( &width , &height ) ;
2522
2523 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
2524 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
2525 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
2526 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
2527
2528 m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint,
2529 vSize , wxVERTICAL);
2530
2531 if ( style & wxVSCROLL )
2532 {
2533
2534 }
2535 else
2536 {
2537 m_vScrollBar->Show(false) ;
2538 }
2539 m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint,
2540 hSize , wxHORIZONTAL);
2541 if ( style & wxHSCROLL )
2542 {
2543 }
2544 else
2545 {
2546 m_hScrollBar->Show(false) ;
2547 }
2548
2549 // because the create does not take into account the client area origin
2550 MacRepositionScrollBars() ; // we might have a real position shift
2551 }
2552
2553 void wxWindowMac::MacRepositionScrollBars()
2554 {
2555 bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
2556 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ;
2557
2558 // get real client area
2559
2560 int width ;
2561 int height ;
2562 GetSize( &width , &height ) ;
2563
2564 width -= MacGetLeftBorderSize() + MacGetRightBorderSize();
2565 height -= MacGetTopBorderSize() + MacGetBottomBorderSize();
2566
2567 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
2568 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
2569 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
2570 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
2571
2572 int x = 0 ;
2573 int y = 0 ;
2574 int w ;
2575 int h ;
2576 GetSize( &w , &h ) ;
2577
2578 MacClientToRootWindow( &x , &y ) ;
2579 MacClientToRootWindow( &w , &h ) ;
2580
2581 wxWindowMac *iter = (wxWindowMac*)this ;
2582
2583 int totW = 10000 , totH = 10000;
2584 while( iter )
2585 {
2586 if ( iter->IsTopLevel() )
2587 {
2588 iter->GetSize( &totW , &totH ) ;
2589 break ;
2590 }
2591
2592 iter = iter->GetParent() ;
2593 }
2594
2595 if ( x == 0 )
2596 {
2597 hPoint.x = -1 ;
2598 hSize.x += 1 ;
2599 }
2600 if ( y == 0 )
2601 {
2602 vPoint.y = -1 ;
2603 vSize.y += 1 ;
2604 }
2605
2606 if ( w-x >= totW )
2607 {
2608 hSize.x += 1 ;
2609 vPoint.x += 1 ;
2610 }
2611
2612 if ( h-y >= totH )
2613 {
2614 vSize.y += 1 ;
2615 hPoint.y += 1 ;
2616 }
2617
2618 if ( m_vScrollBar )
2619 {
2620 m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE);
2621 }
2622 if ( m_hScrollBar )
2623 {
2624 m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE);
2625 }
2626 }
2627
2628 bool wxWindowMac::AcceptsFocus() const
2629 {
2630 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2631 }
2632
2633 void wxWindowMac::MacSuperChangedPosition()
2634 {
2635 // only window-absolute structures have to be moved i.e. controls
2636
2637 wxWindowListNode *node = GetChildren().GetFirst();
2638 while ( node )
2639 {
2640 wxWindowMac *child = node->GetData();
2641 child->MacSuperChangedPosition() ;
2642 node = node->GetNext();
2643 }
2644 }
2645
2646 void wxWindowMac::MacTopLevelWindowChangedPosition()
2647 {
2648 // only screen-absolute structures have to be moved i.e. glcanvas
2649
2650 wxWindowListNode *node = GetChildren().GetFirst();
2651 while ( node )
2652 {
2653 wxWindowMac *child = node->GetData();
2654 child->MacTopLevelWindowChangedPosition() ;
2655 node = node->GetNext();
2656 }
2657 }
2658
2659 long wxWindowMac::MacGetLeftBorderSize( ) const
2660 {
2661 if( IsTopLevel() )
2662 return 0 ;
2663
2664 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
2665 {
2666 SInt32 border = 3 ;
2667 #if wxMAC_USE_THEME_BORDER
2668 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2669 #endif
2670 return border ;
2671 }
2672 else if ( m_windowStyle &wxDOUBLE_BORDER)
2673 {
2674 SInt32 border = 3 ;
2675 #if wxMAC_USE_THEME_BORDER
2676 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2677 #endif
2678 return border ;
2679 }
2680 else if (m_windowStyle &wxSIMPLE_BORDER)
2681 {
2682 return 1 ;
2683 }
2684 return 0 ;
2685 }
2686
2687 long wxWindowMac::MacGetRightBorderSize( ) const
2688 {
2689 // they are all symmetric in mac themes
2690 return MacGetLeftBorderSize() ;
2691 }
2692
2693 long wxWindowMac::MacGetTopBorderSize( ) const
2694 {
2695 // they are all symmetric in mac themes
2696 return MacGetLeftBorderSize() ;
2697 }
2698
2699 long wxWindowMac::MacGetBottomBorderSize( ) const
2700 {
2701 // they are all symmetric in mac themes
2702 return MacGetLeftBorderSize() ;
2703 }
2704
2705 long wxWindowMac::MacRemoveBordersFromStyle( long style )
2706 {
2707 return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ;
2708 }
2709
2710 // Find the wxWindowMac at the current mouse position, returning the mouse
2711 // position.
2712 wxWindowMac* wxFindWindowAtPointer(wxPoint& pt)
2713 {
2714 pt = wxGetMousePosition();
2715 wxWindowMac* found = wxFindWindowAtPoint(pt);
2716 return found;
2717 }
2718
2719 // Get the current mouse position.
2720 wxPoint wxGetMousePosition()
2721 {
2722 int x, y;
2723 wxGetMousePosition(& x, & y);
2724 return wxPoint(x, y);
2725 }
2726
2727 void wxWindowMac::OnMouseEvent( wxMouseEvent &event )
2728 {
2729 if ( event.GetEventType() == wxEVT_RIGHT_DOWN )
2730 {
2731 // copied from wxGTK : CS
2732 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2733 // except that:
2734 //
2735 // (a) it's a command event and so is propagated to the parent
2736 // (b) under MSW it can be generated from kbd too
2737 // (c) it uses screen coords (because of (a))
2738 wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU,
2739 this->GetId(),
2740 this->ClientToScreen(event.GetPosition()));
2741 if ( ! GetEventHandler()->ProcessEvent(evtCtx) )
2742 event.Skip() ;
2743 }
2744 else if (event.GetEventType() == wxEVT_LEFT_DOWN || event.GetEventType() == wxEVT_LEFT_DCLICK )
2745 {
2746
2747 int x = event.m_x ;
2748 int y = event.m_y ;
2749
2750 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2751 {
2752 // OS Needs it in tlw content area coordinates
2753 MacClientToRootWindow( &x , &y ) ;
2754 }
2755 else
2756 {
2757 // OS Needs it in window not client coordinates
2758 wxPoint origin = GetClientAreaOrigin() ;
2759 x += origin.x ;
2760 y += origin.y ;
2761 }
2762 Point localwhere ;
2763 SInt16 controlpart ;
2764
2765 localwhere.h = x ;
2766 localwhere.v = y ;
2767
2768 short modifiers = 0;
2769
2770 if ( !event.m_leftDown && !event.m_rightDown )
2771 modifiers |= btnState ;
2772
2773 if ( event.m_shiftDown )
2774 modifiers |= shiftKey ;
2775
2776 if ( event.m_controlDown )
2777 modifiers |= controlKey ;
2778
2779 if ( event.m_altDown )
2780 modifiers |= optionKey ;
2781
2782 if ( event.m_metaDown )
2783 modifiers |= cmdKey ;
2784
2785 bool handled = false ;
2786
2787 if ( ::IsControlActive( (ControlRef) m_macControl ) )
2788 {
2789 controlpart = ::HandleControlClick( (ControlRef) m_macControl , localwhere , modifiers , (ControlActionUPP) -1 ) ;
2790 wxTheApp->s_lastMouseDown = 0 ;
2791 if ( controlpart != kControlNoPart )
2792 {
2793 MacHandleControlClick((WXWidget) (ControlRef) m_macControl , controlpart , false /* mouse not down anymore */ ) ;
2794 handled = true ;
2795 }
2796 }
2797 if ( !handled )
2798 event.Skip() ;
2799 }
2800 else
2801 {
2802 event.Skip() ;
2803 }
2804 }
2805
2806 void wxWindowMac::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) )
2807 {
2808 wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ;
2809 }
2810
2811 Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin )
2812 {
2813 int x ,y , w ,h ;
2814
2815 window->MacGetBoundsForControl( pos , size , x , y, w, h , adjustForOrigin) ;
2816 Rect bounds = { y , x , y+h , x+w };
2817 return bounds ;
2818 }
2819
2820