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