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