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