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