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