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