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