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