1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/window.cpp
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/window.h"
23 #include "wx/dcclient.h"
24 #include "wx/button.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"
38 #include "wx/tooltip.h"
39 #include "wx/spinctrl.h"
40 #include "wx/geometry.h"
46 #if wxUSE_DRAG_AND_DROP
50 #include "wx/mac/uma.h"
52 #define MAC_SCROLLBAR_SIZE 15
53 #define MAC_SMALL_SCROLLBAR_SIZE 11
57 #include <ToolUtils.h>
59 #include <MacTextEditor.h>
62 #if TARGET_API_MAC_OSX
64 #include <HIToolbox/HIView.h>
70 #ifdef __WXUNIVERSAL__
71 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
73 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
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
)
82 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
83 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus
)
84 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
87 #define wxMAC_DEBUG_REDRAW 0
88 #ifndef wxMAC_DEBUG_REDRAW
89 #define wxMAC_DEBUG_REDRAW 0
92 #define wxMAC_USE_THEME_BORDER 1
94 // ---------------------------------------------------------------------------
95 // Utility Routines to move between different coordinate systems
96 // ---------------------------------------------------------------------------
99 * Right now we have the following setup :
100 * a border that is not part of the native control is always outside the
101 * control's border (otherwise we loose all native intelligence, future ways
102 * may be to have a second embedding control responsible for drawing borders
103 * and backgrounds eventually)
104 * so all this border calculations have to be taken into account when calling
105 * native methods or getting native oriented data
106 * so we have three coordinate systems here
107 * wx client coordinates
108 * wx window coordinates (including window frames)
113 // originating from native control
117 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
119 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
122 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
124 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
128 // directed towards native control
131 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
133 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
136 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
138 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
141 // ---------------------------------------------------------------------------
143 // ---------------------------------------------------------------------------
145 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
146 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
148 #if TARGET_API_MAC_OSX
150 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
153 kEventControlVisibilityChanged
= 157
159 static const EventTypeSpec eventList
[] =
161 { kEventClassCommand
, kEventProcessCommand
} ,
162 { kEventClassCommand
, kEventCommandUpdateStatus
} ,
164 { kEventClassControl
, kEventControlHit
} ,
166 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
167 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
169 { kEventClassControl
, kEventControlDraw
} ,
170 #if TARGET_API_MAC_OSX
171 { kEventClassControl
, kEventControlVisibilityChanged
} ,
172 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
173 { kEventClassControl
, kEventControlHiliteChanged
} ,
175 { kEventClassControl
, kEventControlSetFocusPart
} ,
177 { kEventClassService
, kEventServiceGetTypes
},
178 { kEventClassService
, kEventServiceCopy
},
179 { kEventClassService
, kEventServicePaste
},
181 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
182 // { kEventClassControl , kEventControlBoundsChanged } ,
185 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
187 OSStatus result
= eventNotHandledErr
;
189 wxMacCarbonEvent
cEvent( event
) ;
191 ControlRef controlRef
;
192 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
194 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
196 switch ( GetEventKind( event
) )
198 #if TARGET_API_MAC_OSX
199 case kEventControlDraw
:
201 RgnHandle updateRgn
= NULL
;
202 RgnHandle allocatedRgn
= NULL
;
203 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
206 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
208 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
212 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
214 // as this update region is in native window locals we must adapt it to wx window local
215 allocatedRgn
= NewRgn() ;
216 CopyRgn( updateRgn
, allocatedRgn
) ;
218 // hide the given region by the new region that must be shifted
219 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
220 updateRgn
= allocatedRgn
;
225 GetRegionBounds( updateRgn
, &rgnBounds
) ;
227 #if wxMAC_DEBUG_REDRAW
228 if ( thisWindow
->MacIsUserPane() )
230 static float color
= 0.5 ;
233 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
235 HIViewGetBounds( controlRef
, &bounds
);
236 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
237 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
238 CGContextFillRect( cgContext
, bounds
);
251 #if wxMAC_USE_CORE_GRAPHICS
252 bool created
= false ;
253 CGContextRef cgContext
= NULL
;
254 OSStatus err
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, &cgContext
) ;
255 wxASSERT_MSG( err
== noErr
, wxT("Unable to retrieve CGContextRef") ) ;
256 thisWindow
->MacSetCGContextRef( cgContext
) ;
259 wxMacCGContextStateSaver
sg( cgContext
) ;
262 wxWindow
* iter
= thisWindow
;
265 alpha
*= (float) iter
->GetTransparent()/255.0 ;
266 if ( iter
->IsTopLevel() )
269 iter
= iter
->GetParent() ;
272 CGContextSetAlpha( cgContext
, alpha
) ;
274 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
277 #if wxMAC_USE_CORE_GRAPHICS
278 thisWindow
->MacSetCGContextRef( NULL
) ;
282 CGContextRelease( cgContext
) ;
287 DisposeRgn( allocatedRgn
) ;
291 case kEventControlVisibilityChanged
:
292 thisWindow
->MacVisibilityChanged() ;
295 case kEventControlEnabledStateChanged
:
296 thisWindow
->MacEnabledStateChanged() ;
299 case kEventControlHiliteChanged
:
300 thisWindow
->MacHiliteChanged() ;
304 // we emulate this event under Carbon CFM
305 case kEventControlSetFocusPart
:
307 Boolean focusEverything
= false ;
308 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
311 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
316 if ( controlPart
== kControlFocusNoPart
)
319 if ( thisWindow
->GetCaret() )
320 thisWindow
->GetCaret()->OnKillFocus();
323 static bool inKillFocusEvent
= false ;
325 if ( !inKillFocusEvent
)
327 inKillFocusEvent
= true ;
328 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
329 event
.SetEventObject(thisWindow
);
330 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
331 inKillFocusEvent
= false ;
336 // panel wants to track the window which was the last to have focus in it
337 wxChildFocusEvent
eventFocus(thisWindow
);
338 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
341 if ( thisWindow
->GetCaret() )
342 thisWindow
->GetCaret()->OnSetFocus();
345 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
346 event
.SetEventObject(thisWindow
);
347 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
350 if ( thisWindow
->MacIsUserPane() )
355 case kEventControlHit
:
356 result
= thisWindow
->MacControlHit( handler
, event
) ;
366 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
368 OSStatus result
= eventNotHandledErr
;
370 wxMacCarbonEvent
cEvent( event
) ;
372 ControlRef controlRef
;
373 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
374 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
375 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
377 switch ( GetEventKind( event
) )
379 case kEventServiceGetTypes
:
383 textCtrl
->GetSelection( &from
, &to
) ;
385 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
387 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
388 if ( textCtrl
->IsEditable() )
389 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
391 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt', 'PICT', 'MooV', 'AIFF' */ };
392 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
394 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
398 CFArrayAppendValue(copyTypes
, typestring
) ;
400 CFArrayAppendValue(pasteTypes
, typestring
) ;
402 CFRelease( typestring
) ;
410 case kEventServiceCopy
:
415 textCtrl
->GetSelection( &from
, &to
) ;
416 wxString val
= textCtrl
->GetValue() ;
417 val
= val
.Mid( from
, to
- from
) ;
418 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
419 verify_noerr( ClearScrap( &scrapRef
) ) ;
420 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.length() , val
.c_str() ) ) ;
425 case kEventServicePaste
:
428 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
429 Size textSize
, pastedSize
;
430 verify_noerr( GetScrapFlavorSize(scrapRef
, kTXNTextData
, &textSize
) ) ;
432 char *content
= new char[textSize
] ;
433 GetScrapFlavorData(scrapRef
, kTXNTextData
, &pastedSize
, content
);
434 content
[textSize
- 1] = 0 ;
437 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
439 textCtrl
->WriteText( wxString( content
) ) ;
454 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
456 OSStatus result
= eventNotHandledErr
;
457 wxWindowMac
* focus
= (wxWindowMac
*) data
;
459 wchar_t* uniChars
= NULL
;
460 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
462 UniChar
* charBuf
= NULL
;
463 UInt32 dataSize
= 0 ;
466 if ( GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
468 numChars
= dataSize
/ sizeof( UniChar
) + 1;
471 if ( (size_t) numChars
* 2 > sizeof(buf
) )
472 charBuf
= new UniChar
[ numChars
] ;
476 uniChars
= new wchar_t[ numChars
] ;
477 GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
478 charBuf
[ numChars
- 1 ] = 0;
479 #if SIZEOF_WCHAR_T == 2
480 uniChars
= (wchar_t*) charBuf
;
481 memcpy( uniChars
, charBuf
, numChars
* 2 ) ;
483 // the resulting string will never have more chars than the utf16 version, so this is safe
484 wxMBConvUTF16 converter
;
485 numChars
= converter
.MB2WC( uniChars
, (const char*)charBuf
, numChars
) ;
489 switch ( GetEventKind( event
) )
491 case kEventTextInputUpdateActiveInputArea
:
493 // An IME input event may return several characters, but we need to send one char at a time to
495 for (int pos
=0 ; pos
< numChars
; pos
++)
497 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
498 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
499 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
501 UInt32 message
= (0 << 8) + ((char)uniChars
[pos
] );
502 if ( wxTheApp
->MacSendCharEvent(
503 focus
, message
, 0 , when
, 0 , 0 , uniChars
[pos
] ) )
508 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
512 case kEventTextInputUnicodeForKeyEvent
:
514 UInt32 keyCode
, modifiers
;
517 unsigned char charCode
;
519 GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
, typeEventRef
, NULL
, sizeof(rawEvent
), NULL
, &rawEvent
) ;
520 GetEventParameter( rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
521 GetEventParameter( rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
522 GetEventParameter( rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
523 GetEventParameter( rawEvent
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
525 UInt32 message
= (keyCode
<< 8) + charCode
;
527 // An IME input event may return several characters, but we need to send one char at a time to
529 for (int pos
=0 ; pos
< numChars
; pos
++)
531 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
532 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
533 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
535 if ( wxTheApp
->MacSendCharEvent(
536 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChars
[pos
] ) )
541 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
550 if ( charBuf
!= buf
)
556 static pascal OSStatus
wxMacWindowCommandEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
558 OSStatus result
= eventNotHandledErr
;
559 wxWindowMac
* focus
= (wxWindowMac
*) data
;
563 wxMacCarbonEvent
cEvent( event
) ;
564 cEvent
.GetParameter
<HICommand
>(kEventParamDirectObject
,typeHICommand
,&command
) ;
566 wxMenuItem
* item
= NULL
;
567 wxMenu
* itemMenu
= wxFindMenuFromMacCommand( command
, item
) ;
568 int id
= wxMacCommandToId( command
.commandID
) ;
572 wxASSERT( itemMenu
!= NULL
) ;
574 switch ( cEvent
.GetKind() )
576 case kEventProcessCommand
:
578 if (item
->IsCheckable())
579 item
->Check( !item
->IsChecked() ) ;
581 if ( itemMenu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) )
585 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, id
);
586 event
.SetEventObject(focus
);
587 event
.SetInt(item
->IsCheckable() ? item
->IsChecked() : -1);
589 if ( focus
->GetEventHandler()->ProcessEvent(event
) )
595 case kEventCommandUpdateStatus
:
597 wxUpdateUIEvent
event(id
);
598 event
.SetEventObject( itemMenu
);
600 bool processed
= false;
602 // Try the menu's event handler
604 wxEvtHandler
*handler
= itemMenu
->GetEventHandler();
606 processed
= handler
->ProcessEvent(event
);
609 // Try the window the menu was popped up from
610 // (and up through the hierarchy)
613 const wxMenuBase
*menu
= itemMenu
;
616 wxWindow
*win
= menu
->GetInvokingWindow();
619 processed
= win
->GetEventHandler()->ProcessEvent(event
);
623 menu
= menu
->GetParent();
629 processed
= focus
->GetEventHandler()->ProcessEvent(event
);
634 // if anything changed, update the changed attribute
635 if (event
.GetSetText())
636 itemMenu
->SetLabel(id
, event
.GetText());
637 if (event
.GetSetChecked())
638 itemMenu
->Check(id
, event
.GetChecked());
639 if (event
.GetSetEnabled())
640 itemMenu
->Enable(id
, event
.GetEnabled());
654 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
656 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
657 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
658 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
659 OSStatus result
= eventNotHandledErr
;
661 switch ( GetEventClass( event
) )
663 case kEventClassCommand
:
664 result
= wxMacWindowCommandEventHandler( handler
, event
, data
) ;
667 case kEventClassControl
:
668 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
671 case kEventClassService
:
672 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
675 case kEventClassTextInput
:
676 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
683 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
688 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
690 #if !TARGET_API_MAC_OSX
692 // ---------------------------------------------------------------------------
693 // UserPane events for non OSX builds
694 // ---------------------------------------------------------------------------
696 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
698 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
700 win
->MacControlUserPaneDrawProc(part
) ;
702 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP
, wxMacControlUserPaneDrawProc
) ;
704 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
706 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
708 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
710 return kControlNoPart
;
712 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP
, wxMacControlUserPaneHitTestProc
) ;
714 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
716 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
718 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
720 return kControlNoPart
;
722 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP
, wxMacControlUserPaneTrackingProc
) ;
724 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
726 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
728 win
->MacControlUserPaneIdleProc() ;
730 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP
, wxMacControlUserPaneIdleProc
) ;
732 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
734 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
736 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
738 return kControlNoPart
;
740 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP
, wxMacControlUserPaneKeyDownProc
) ;
742 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
744 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
746 win
->MacControlUserPaneActivateProc(activating
) ;
748 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP
, wxMacControlUserPaneActivateProc
) ;
750 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
752 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
754 return win
->MacControlUserPaneFocusProc(action
) ;
756 return kControlNoPart
;
758 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP
, wxMacControlUserPaneFocusProc
) ;
760 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
762 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
764 win
->MacControlUserPaneBackgroundProc(info
) ;
766 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP
, wxMacControlUserPaneBackgroundProc
) ;
768 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
771 RgnHandle rgn
= NewRgn() ;
773 MacWindowToRootWindow( &x
, &y
) ;
774 OffsetRgn( rgn
, -x
, -y
) ;
775 wxMacWindowStateSaver
sv( this ) ;
776 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
777 MacDoRedraw( rgn
, 0 ) ;
781 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
783 return kControlNoPart
;
786 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
788 return kControlNoPart
;
791 void wxWindowMac::MacControlUserPaneIdleProc()
795 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
797 return kControlNoPart
;
800 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
804 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
806 if ( AcceptsFocus() )
809 return kControlNoPart
;
812 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
818 // ---------------------------------------------------------------------------
819 // Scrollbar Tracking for all
820 // ---------------------------------------------------------------------------
822 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
823 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
827 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
829 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
832 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
834 // ===========================================================================
836 // ===========================================================================
838 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
840 static MacControlMap wxWinMacControlList
;
842 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
844 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
846 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
849 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
851 // adding NULL ControlRef is (first) surely a result of an error and
852 // (secondly) breaks native event processing
853 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
855 wxWinMacControlList
[inControl
] = control
;
858 void wxRemoveMacControlAssociation(wxWindow
*control
)
860 // iterate over all the elements in the class
861 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
862 // we should go on...
868 MacControlMap::iterator it
;
869 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
871 if ( it
->second
== control
)
873 wxWinMacControlList
.erase(it
);
881 // ----------------------------------------------------------------------------
882 // constructors and such
883 // ----------------------------------------------------------------------------
885 wxWindowMac::wxWindowMac()
890 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
895 const wxString
& name
)
898 Create(parent
, id
, pos
, size
, style
, name
);
901 void wxWindowMac::Init()
907 #if WXWIN_COMPATIBILITY_2_4
908 m_backgroundTransparent
= false;
911 #if wxMAC_USE_CORE_GRAPHICS
912 m_cgContextRef
= NULL
;
915 // as all windows are created with WS_VISIBLE style...
918 m_hScrollBar
= NULL
;
919 m_vScrollBar
= NULL
;
920 m_macBackgroundBrush
= wxNullBrush
;
922 m_macIsUserPane
= true;
923 m_clipChildren
= false ;
924 m_cachedClippedRectValid
= false ;
926 // we need a valid font for the encodings
927 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
930 wxWindowMac::~wxWindowMac()
934 m_isBeingDeleted
= true;
936 MacInvalidateBorders() ;
938 #ifndef __WXUNIVERSAL__
939 // VS: make sure there's no wxFrame with last focus set to us:
940 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
942 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
945 if ( frame
->GetLastFocus() == this )
946 frame
->SetLastFocus((wxWindow
*)NULL
);
952 // destroy children before destroying this window itself
955 // wxRemoveMacControlAssociation( this ) ;
956 // If we delete an item, we should initialize the parent panel,
957 // because it could now be invalid.
958 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow
);
961 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
962 tlw
->SetDefaultItem(NULL
);
965 if ( m_peer
&& m_peer
->Ok() )
967 // in case the callback might be called during destruction
968 wxRemoveMacControlAssociation( this) ;
969 ::RemoveEventHandler( (EventHandlerRef
) m_macControlEventHandler
) ;
970 // we currently are not using this hook
971 // ::SetControlColorProc( *m_peer , NULL ) ;
975 if ( g_MacLastWindow
== this )
976 g_MacLastWindow
= NULL
;
978 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
981 if ( frame
->GetLastFocus() == this )
982 frame
->SetLastFocus( NULL
) ;
985 // delete our drop target if we've got one
986 #if wxUSE_DRAG_AND_DROP
987 if ( m_dropTarget
!= NULL
)
997 WXWidget
wxWindowMac::GetHandle() const
999 return (WXWidget
) m_peer
->GetControlRef() ;
1002 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
1004 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
1005 InstallControlEventHandler( (ControlRef
)control
, GetwxMacWindowEventHandlerUPP(),
1006 GetEventTypeCount(eventList
), eventList
, this,
1007 (EventHandlerRef
*)&m_macControlEventHandler
);
1009 #if !TARGET_API_MAC_OSX
1010 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
1012 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
, kControlUserPaneDrawProcTag
, GetwxMacControlUserPaneDrawProc()) ;
1013 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
, kControlUserPaneHitTestProcTag
, GetwxMacControlUserPaneHitTestProc()) ;
1014 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
, kControlUserPaneTrackingProcTag
, GetwxMacControlUserPaneTrackingProc()) ;
1015 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
, kControlUserPaneIdleProcTag
, GetwxMacControlUserPaneIdleProc()) ;
1016 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
, kControlUserPaneKeyDownProcTag
, GetwxMacControlUserPaneKeyDownProc()) ;
1017 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
, kControlUserPaneActivateProcTag
, GetwxMacControlUserPaneActivateProc()) ;
1018 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
, kControlUserPaneFocusProcTag
, GetwxMacControlUserPaneFocusProc()) ;
1019 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
, kControlUserPaneBackgroundProcTag
, GetwxMacControlUserPaneBackgroundProc()) ;
1025 bool wxWindowMac::Create(wxWindowMac
*parent
,
1030 const wxString
& name
)
1032 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
1034 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
1037 m_windowVariant
= parent
->GetWindowVariant() ;
1039 if ( m_macIsUserPane
)
1041 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
1044 | kControlSupportsEmbedding
1045 | kControlSupportsLiveFeedback
1046 | kControlGetsFocusOnClick
1047 // | kControlHasSpecialBackground
1048 // | kControlSupportsCalcBestRect
1049 | kControlHandlesTracking
1050 | kControlSupportsFocus
1051 | kControlWantsActivate
1052 | kControlWantsIdle
;
1054 m_peer
= new wxMacControl(this) ;
1055 OSStatus err
=::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
1056 verify_noerr( err
);
1058 MacPostControlCreate(pos
, size
) ;
1061 #ifndef __WXUNIVERSAL__
1062 // Don't give scrollbars to wxControls unless they ask for them
1063 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
)))
1064 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
1066 MacCreateScrollBars( style
) ;
1070 wxWindowCreateEvent
event(this);
1071 GetEventHandler()->AddPendingEvent(event
);
1076 void wxWindowMac::MacChildAdded()
1079 m_vScrollBar
->Raise() ;
1081 m_hScrollBar
->Raise() ;
1084 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
1086 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
1088 m_peer
->SetReference( (long)this ) ;
1089 GetParent()->AddChild( this );
1091 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
1093 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
1094 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
1095 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
1096 GetParent()->MacChildAdded() ;
1098 // adjust font, controlsize etc
1099 DoSetWindowVariant( m_windowVariant
) ;
1101 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
) ) ;
1103 if (!m_macIsUserPane
)
1104 SetInitialBestSize(size
);
1106 SetCursor( *wxSTANDARD_CURSOR
) ;
1109 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
1111 // Don't assert, in case we set the window variant before
1112 // the window is created
1113 // wxASSERT( m_peer->Ok() ) ;
1115 m_windowVariant
= variant
;
1117 if (m_peer
== NULL
|| !m_peer
->Ok())
1121 ThemeFontID themeFont
= kThemeSystemFont
;
1123 // we will get that from the settings later
1124 // and make this NORMAL later, but first
1125 // we have a few calculations that we must fix
1129 case wxWINDOW_VARIANT_NORMAL
:
1130 size
= kControlSizeNormal
;
1131 themeFont
= kThemeSystemFont
;
1134 case wxWINDOW_VARIANT_SMALL
:
1135 size
= kControlSizeSmall
;
1136 themeFont
= kThemeSmallSystemFont
;
1139 case wxWINDOW_VARIANT_MINI
:
1140 if (UMAGetSystemVersion() >= 0x1030 )
1142 // not always defined in the headers
1148 size
= kControlSizeSmall
;
1149 themeFont
= kThemeSmallSystemFont
;
1153 case wxWINDOW_VARIANT_LARGE
:
1154 size
= kControlSizeLarge
;
1155 themeFont
= kThemeSystemFont
;
1159 wxFAIL_MSG(_T("unexpected window variant"));
1163 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
1166 font
.MacCreateThemeFont( themeFont
) ;
1170 void wxWindowMac::MacUpdateControlFont()
1172 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1176 bool wxWindowMac::SetFont(const wxFont
& font
)
1178 bool retval
= wxWindowBase::SetFont( font
);
1180 MacUpdateControlFont() ;
1185 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1187 bool retval
= wxWindowBase::SetForegroundColour( col
);
1190 MacUpdateControlFont();
1195 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1197 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1201 wxColour
newCol(GetBackgroundColour());
1203 if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_APPWORKSPACE
) )
1204 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1205 else if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE
) )
1206 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1208 brush
.SetColour( newCol
) ;
1210 MacSetBackgroundBrush( brush
) ;
1211 MacUpdateControlFont() ;
1216 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1218 m_macBackgroundBrush
= brush
;
1219 m_peer
->SetBackground( brush
) ;
1222 bool wxWindowMac::MacCanFocus() const
1224 // TODO : evaluate performance hits by looking up this value, eventually cache the results for a 1 sec or so
1225 // CAUTION : the value returned currently is 0 or 2, I've also found values of 1 having the same meaning,
1226 // but the value range is nowhere documented
1227 Boolean keyExistsAndHasValidFormat
;
1228 CFIndex fullKeyboardAccess
= CFPreferencesGetAppIntegerValue( CFSTR("AppleKeyboardUIMode" ) ,
1229 kCFPreferencesCurrentApplication
, &keyExistsAndHasValidFormat
);
1231 if ( keyExistsAndHasValidFormat
&& fullKeyboardAccess
> 0 )
1237 UInt32 features
= 0 ;
1238 m_peer
->GetFeatures( &features
) ;
1240 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1244 void wxWindowMac::SetFocus()
1246 if ( !AcceptsFocus() )
1249 wxWindow
* former
= FindFocus() ;
1250 if ( former
== this )
1253 // as we cannot rely on the control features to find out whether we are in full keyboard mode,
1254 // we can only leave in case of an error
1255 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1256 if ( err
== errCouldntSetFocus
)
1259 SetUserFocusWindow( (WindowRef
)MacGetTopLevelWindowRef() );
1261 #if !TARGET_API_MAC_OSX
1262 // emulate carbon events when running under CarbonLib where they are not natively available
1265 EventRef evRef
= NULL
;
1267 err
= MacCreateEvent(
1268 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1269 kEventAttributeUserEvent
, &evRef
);
1270 verify_noerr( err
);
1272 wxMacCarbonEvent
cEvent( evRef
) ;
1273 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1274 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1276 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1277 ReleaseEvent( evRef
) ;
1280 // send new focus event
1282 EventRef evRef
= NULL
;
1284 err
= MacCreateEvent(
1285 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1286 kEventAttributeUserEvent
, &evRef
);
1287 verify_noerr( err
);
1289 wxMacCarbonEvent
cEvent( evRef
) ;
1290 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1291 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1293 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1294 ReleaseEvent( evRef
) ;
1299 void wxWindowMac::DoCaptureMouse()
1301 wxApp::s_captureWindow
= this ;
1304 wxWindow
* wxWindowBase::GetCapture()
1306 return wxApp::s_captureWindow
;
1309 void wxWindowMac::DoReleaseMouse()
1311 wxApp::s_captureWindow
= NULL
;
1314 #if wxUSE_DRAG_AND_DROP
1316 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1318 if ( m_dropTarget
!= NULL
)
1319 delete m_dropTarget
;
1321 m_dropTarget
= pDropTarget
;
1322 if ( m_dropTarget
!= NULL
)
1330 // Old-style File Manager Drag & Drop
1331 void wxWindowMac::DragAcceptFiles(bool accept
)
1336 // Returns the size of the native control. In the case of the toplevel window
1337 // this is the content area root control
1339 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1340 int& w
, int& h
) const
1342 wxFAIL_MSG( wxT("Not currently supported") ) ;
1345 // From a wx position / size calculate the appropriate size of the native control
1347 bool wxWindowMac::MacGetBoundsForControl(
1351 int& w
, int& h
, bool adjustOrigin
) const
1353 // the desired size, minus the border pixels gives the correct size of the control
1357 // TODO: the default calls may be used as soon as PostCreateControl Is moved here
1358 w
= wxMax(size
.x
, 0) ; // WidthDefault( size.x );
1359 h
= wxMax(size
.y
, 0) ; // HeightDefault( size.y ) ;
1361 x
+= MacGetLeftBorderSize() ;
1362 y
+= MacGetTopBorderSize() ;
1363 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1364 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1367 AdjustForParentClientOrigin( x
, y
) ;
1369 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1370 if ( !GetParent()->IsTopLevel() )
1372 x
-= GetParent()->MacGetLeftBorderSize() ;
1373 y
-= GetParent()->MacGetTopBorderSize() ;
1379 // Get window size (not client size)
1380 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1383 m_peer
->GetRect( &bounds
) ;
1386 *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1388 *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1391 // get the position of the bounds of this window in client coordinates of its parent
1392 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1395 m_peer
->GetRect( &bounds
) ;
1397 int x1
= bounds
.left
;
1398 int y1
= bounds
.top
;
1400 // get the wx window position from the native one
1401 x1
-= MacGetLeftBorderSize() ;
1402 y1
-= MacGetTopBorderSize() ;
1404 if ( !IsTopLevel() )
1406 wxWindow
*parent
= GetParent();
1409 // we must first adjust it to be in window coordinates of the parent,
1410 // as otherwise it gets lost by the ClientAreaOrigin fix
1411 x1
+= parent
->MacGetLeftBorderSize() ;
1412 y1
+= parent
->MacGetTopBorderSize() ;
1414 // and now to client coordinates
1415 wxPoint
pt(parent
->GetClientAreaOrigin());
1427 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1429 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1430 wxCHECK_RET( window
, wxT("TopLevel Window missing") ) ;
1432 Point localwhere
= { 0, 0 } ;
1439 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1446 MacRootWindowToWindow( x
, y
) ;
1448 wxPoint origin
= GetClientAreaOrigin() ;
1455 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1457 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1458 wxCHECK_RET( window
, wxT("TopLevel window missing") ) ;
1460 wxPoint origin
= GetClientAreaOrigin() ;
1466 MacWindowToRootWindow( x
, y
) ;
1468 Point localwhere
= { 0, 0 };
1474 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1482 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1484 wxPoint origin
= GetClientAreaOrigin() ;
1490 MacWindowToRootWindow( x
, y
) ;
1493 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1495 MacRootWindowToWindow( x
, y
) ;
1497 wxPoint origin
= GetClientAreaOrigin() ;
1504 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1513 if ( !IsTopLevel() )
1515 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1518 pt
.x
-= MacGetLeftBorderSize() ;
1519 pt
.y
-= MacGetTopBorderSize() ;
1520 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1530 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1539 MacWindowToRootWindow( &x1
, &y1
) ;
1547 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1556 if ( !IsTopLevel() )
1558 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1561 wxMacControl::Convert( &pt
, top
->m_peer
, m_peer
) ;
1562 pt
.x
+= MacGetLeftBorderSize() ;
1563 pt
.y
+= MacGetTopBorderSize() ;
1573 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1582 MacRootWindowToWindow( &x1
, &y1
) ;
1590 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1592 RgnHandle rgn
= NewRgn() ;
1594 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1596 Rect structure
, content
;
1598 GetRegionBounds( rgn
, &content
) ;
1599 m_peer
->GetRect( &structure
) ;
1600 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1602 left
= content
.left
- structure
.left
;
1603 top
= content
.top
- structure
.top
;
1604 right
= structure
.right
- content
.right
;
1605 bottom
= structure
.bottom
- content
.bottom
;
1609 left
= top
= right
= bottom
= 0 ;
1615 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1617 wxSize sizeTotal
= size
;
1619 RgnHandle rgn
= NewRgn() ;
1620 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1622 Rect content
, structure
;
1623 GetRegionBounds( rgn
, &content
) ;
1624 m_peer
->GetRect( &structure
) ;
1626 // structure is in parent coordinates, but we only need width and height, so it's ok
1628 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1629 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1634 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1635 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1640 // Get size *available for subwindows* i.e. excluding menu bar etc.
1641 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
1645 RgnHandle rgn
= NewRgn() ;
1647 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1648 GetRegionBounds( rgn
, &content
) ;
1650 m_peer
->GetRect( &content
) ;
1653 ww
= content
.right
- content
.left
;
1654 hh
= content
.bottom
- content
.top
;
1656 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1657 hh
-= m_hScrollBar
->GetSize().y
;
1659 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1660 ww
-= m_vScrollBar
->GetSize().x
;
1668 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1670 if (m_cursor
== cursor
)
1673 if (wxNullCursor
== cursor
)
1675 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1680 if ( ! wxWindowBase::SetCursor( cursor
) )
1684 wxASSERT_MSG( m_cursor
.Ok(),
1685 wxT("cursor must be valid after call to the base version"));
1687 wxWindowMac
*mouseWin
= 0 ;
1689 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1690 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1692 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1694 // TODO: If we ever get a GetCurrentEvent... replacement
1695 // for the mouse position, use it...
1698 ControlPartCode part
;
1699 ControlRef control
;
1702 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1704 mouseWin
= wxFindControlFromMacControl( control
) ;
1707 QDSwapPort( savePort
, NULL
) ;
1710 if ( mouseWin
== this && !wxIsBusy() )
1711 m_cursor
.MacInstall() ;
1717 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1719 menu
->SetInvokingWindow(this);
1722 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
1724 wxPoint mouse
= wxGetMousePosition();
1730 ClientToScreen( &x
, &y
) ;
1733 menu
->MacBeforeDisplay( true ) ;
1734 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() , y
, x
, 0) ;
1735 if ( HiWord(menuResult
) != 0 )
1738 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &macid
);
1739 int id
= wxMacCommandToId( macid
);
1740 wxMenuItem
* item
= NULL
;
1742 item
= menu
->FindItem( id
, &realmenu
) ;
1745 if (item
->IsCheckable())
1746 item
->Check( !item
->IsChecked() ) ;
1748 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1752 menu
->MacAfterDisplay( true ) ;
1753 menu
->SetInvokingWindow( NULL
);
1759 // ----------------------------------------------------------------------------
1761 // ----------------------------------------------------------------------------
1765 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1767 wxWindowBase::DoSetToolTip(tooltip
);
1770 m_tooltip
->SetWindow(this);
1775 void wxWindowMac::MacInvalidateBorders()
1777 if ( m_peer
== NULL
)
1780 bool vis
= MacIsReallyShown() ;
1784 int outerBorder
= MacGetLeftBorderSize() ;
1785 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1788 if ( outerBorder
== 0 )
1791 // now we know that we have something to do at all
1793 // as the borders are drawn on the parent we have to properly invalidate all these areas
1794 RgnHandle updateInner
, updateOuter
;
1797 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1798 updateInner
= NewRgn() ;
1799 updateOuter
= NewRgn() ;
1801 m_peer
->GetRect( &rect
) ;
1802 RectRgn( updateInner
, &rect
) ;
1803 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1804 RectRgn( updateOuter
, &rect
) ;
1805 DiffRgn( updateOuter
, updateInner
, updateOuter
) ;
1807 #ifdef __WXMAC_OSX__
1808 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1810 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1812 InvalWindowRgn( tlw
, updateOuter
) ;
1815 DisposeRgn( updateOuter
) ;
1816 DisposeRgn( updateInner
) ;
1819 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1821 // this is never called for a toplevel window, so we know we have a parent
1822 int former_x
, former_y
, former_w
, former_h
;
1824 // Get true coordinates of former position
1825 DoGetPosition( &former_x
, &former_y
) ;
1826 DoGetSize( &former_w
, &former_h
) ;
1828 wxWindow
*parent
= GetParent();
1831 wxPoint
pt(parent
->GetClientAreaOrigin());
1836 int actualWidth
= width
;
1837 int actualHeight
= height
;
1841 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1842 actualWidth
= m_minWidth
;
1843 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1844 actualHeight
= m_minHeight
;
1845 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1846 actualWidth
= m_maxWidth
;
1847 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1848 actualHeight
= m_maxHeight
;
1850 bool doMove
= false, doResize
= false ;
1852 if ( actualX
!= former_x
|| actualY
!= former_y
)
1855 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1858 if ( doMove
|| doResize
)
1860 // as the borders are drawn outside the native control, we adjust now
1862 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1863 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1864 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1867 wxMacRectToNative( &bounds
, &r
) ;
1869 if ( !GetParent()->IsTopLevel() )
1870 wxMacWindowToNative( GetParent() , &r
) ;
1872 MacInvalidateBorders() ;
1874 m_cachedClippedRectValid
= false ;
1875 m_peer
->SetRect( &r
) ;
1877 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1879 MacInvalidateBorders() ;
1881 MacRepositionScrollBars() ;
1884 wxPoint
point(actualX
, actualY
);
1885 wxMoveEvent
event(point
, m_windowId
);
1886 event
.SetEventObject(this);
1887 GetEventHandler()->ProcessEvent(event
) ;
1892 MacRepositionScrollBars() ;
1893 wxSize
size(actualWidth
, actualHeight
);
1894 wxSizeEvent
event(size
, m_windowId
);
1895 event
.SetEventObject(this);
1896 GetEventHandler()->ProcessEvent(event
);
1901 wxSize
wxWindowMac::DoGetBestSize() const
1903 if ( m_macIsUserPane
|| IsTopLevel() )
1904 return wxWindowBase::DoGetBestSize() ;
1906 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1907 int bestWidth
, bestHeight
;
1909 m_peer
->GetBestRect( &bestsize
) ;
1910 if ( EmptyRect( &bestsize
) )
1915 bestsize
.bottom
= 16 ;
1917 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1919 bestsize
.bottom
= 16 ;
1922 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1924 bestsize
.bottom
= 24 ;
1929 // return wxWindowBase::DoGetBestSize() ;
1933 bestWidth
= bestsize
.right
- bestsize
.left
;
1934 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1935 if ( bestHeight
< 10 )
1938 return wxSize(bestWidth
, bestHeight
);
1941 // set the size of the window: if the dimensions are positive, just use them,
1942 // but if any of them is equal to -1, it means that we must find the value for
1943 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1944 // which case -1 is a valid value for x and y)
1946 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1947 // the width/height to best suit our contents, otherwise we reuse the current
1949 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1951 // get the current size and position...
1952 int currentX
, currentY
;
1953 int currentW
, currentH
;
1955 GetPosition(¤tX
, ¤tY
);
1956 GetSize(¤tW
, ¤tH
);
1958 // ... and don't do anything (avoiding flicker) if it's already ok
1959 if ( x
== currentX
&& y
== currentY
&&
1960 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1963 MacRepositionScrollBars() ; // we might have a real position shift
1968 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1970 if ( x
== wxDefaultCoord
)
1972 if ( y
== wxDefaultCoord
)
1976 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1978 wxSize size
= wxDefaultSize
;
1979 if ( width
== wxDefaultCoord
)
1981 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1983 size
= DoGetBestSize();
1988 // just take the current one
1993 if ( height
== wxDefaultCoord
)
1995 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1997 if ( size
.x
== wxDefaultCoord
)
1998 size
= DoGetBestSize();
1999 // else: already called DoGetBestSize() above
2005 // just take the current one
2010 DoMoveWindow( x
, y
, width
, height
);
2013 wxPoint
wxWindowMac::GetClientAreaOrigin() const
2015 RgnHandle rgn
= NewRgn() ;
2017 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
2019 GetRegionBounds( rgn
, &content
) ;
2029 return wxPoint( content
.left
+ MacGetLeftBorderSize() , content
.top
+ MacGetTopBorderSize() );
2032 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
2034 if ( clientheight
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
2036 int currentclientwidth
, currentclientheight
;
2037 int currentwidth
, currentheight
;
2039 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
2040 GetSize( ¤twidth
, ¤theight
) ;
2042 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
2043 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
2047 void wxWindowMac::SetLabel(const wxString
& title
)
2049 m_label
= wxStripMenuCodes(title
, wxStrip_Mnemonics
) ;
2051 if ( m_peer
&& m_peer
->Ok() )
2052 m_peer
->SetLabel( m_label
) ;
2057 wxString
wxWindowMac::GetLabel() const
2062 bool wxWindowMac::Show(bool show
)
2064 bool former
= MacIsReallyShown() ;
2065 if ( !wxWindowBase::Show(show
) )
2068 // TODO: use visibilityChanged Carbon Event for OSX
2070 m_peer
->SetVisibility( show
, true ) ;
2072 if ( former
!= MacIsReallyShown() )
2073 MacPropagateVisibilityChanged() ;
2078 bool wxWindowMac::Enable(bool enable
)
2080 wxASSERT( m_peer
->Ok() ) ;
2081 bool former
= MacIsReallyEnabled() ;
2082 if ( !wxWindowBase::Enable(enable
) )
2085 m_peer
->Enable( enable
) ;
2087 if ( former
!= MacIsReallyEnabled() )
2088 MacPropagateEnabledStateChanged() ;
2094 // status change propagations (will be not necessary for OSX later )
2097 void wxWindowMac::MacPropagateVisibilityChanged()
2099 #if !TARGET_API_MAC_OSX
2100 MacVisibilityChanged() ;
2103 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2106 child
= node
->GetData();
2107 if ( child
->IsShown() )
2108 child
->MacPropagateVisibilityChanged() ;
2110 node
= node
->GetNext();
2115 void wxWindowMac::MacPropagateEnabledStateChanged()
2117 #if !TARGET_API_MAC_OSX
2118 MacEnabledStateChanged() ;
2121 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2124 child
= node
->GetData();
2125 if ( child
->IsEnabled() )
2126 child
->MacPropagateEnabledStateChanged() ;
2128 node
= node
->GetNext();
2133 void wxWindowMac::MacPropagateHiliteChanged()
2135 #if !TARGET_API_MAC_OSX
2136 MacHiliteChanged() ;
2139 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2142 child
= node
->GetData();
2143 if (child
/* && child->IsEnabled() */)
2144 child
->MacPropagateHiliteChanged() ;
2146 node
= node
->GetNext();
2152 // status change notifications
2155 void wxWindowMac::MacVisibilityChanged()
2159 void wxWindowMac::MacHiliteChanged()
2163 void wxWindowMac::MacEnabledStateChanged()
2168 // status queries on the inherited window's state
2171 bool wxWindowMac::MacIsReallyShown()
2173 // only under OSX the visibility of the TLW is taken into account
2174 if ( m_isBeingDeleted
)
2177 #if TARGET_API_MAC_OSX
2178 if ( m_peer
&& m_peer
->Ok() )
2179 return m_peer
->IsVisible();
2182 wxWindow
* win
= this ;
2183 while ( win
->IsShown() )
2185 if ( win
->IsTopLevel() )
2188 win
= win
->GetParent() ;
2196 bool wxWindowMac::MacIsReallyEnabled()
2198 return m_peer
->IsEnabled() ;
2201 bool wxWindowMac::MacIsReallyHilited()
2203 return m_peer
->IsActive();
2206 void wxWindowMac::MacFlashInvalidAreas()
2208 #if TARGET_API_MAC_OSX
2209 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2213 int wxWindowMac::GetCharHeight() const
2215 wxClientDC
dc( (wxWindowMac
*)this ) ;
2217 return dc
.GetCharHeight() ;
2220 int wxWindowMac::GetCharWidth() const
2222 wxClientDC
dc( (wxWindowMac
*)this ) ;
2224 return dc
.GetCharWidth() ;
2227 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2228 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2230 const wxFont
*fontToUse
= theFont
;
2232 fontToUse
= &m_font
;
2234 wxClientDC
dc( (wxWindowMac
*) this ) ;
2236 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2237 if ( externalLeading
)
2238 *externalLeading
= le
;
2248 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2249 * we always intersect with the entire window, not only with the client area
2252 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2254 if ( m_peer
== NULL
)
2257 if ( !MacIsReallyShown() )
2264 wxMacRectToNative( rect
, &r
) ;
2265 m_peer
->SetNeedsDisplay( &r
) ;
2269 m_peer
->SetNeedsDisplay() ;
2273 void wxWindowMac::Freeze()
2275 #if TARGET_API_MAC_OSX
2276 if ( !m_frozenness
++ )
2278 if ( m_peer
&& m_peer
->Ok() )
2279 m_peer
->SetDrawingEnabled( false ) ;
2284 void wxWindowMac::Thaw()
2286 #if TARGET_API_MAC_OSX
2287 wxASSERT_MSG( m_frozenness
> 0, wxT("Thaw() without matching Freeze()") );
2289 if ( !--m_frozenness
)
2291 if ( m_peer
&& m_peer
->Ok() )
2293 m_peer
->SetDrawingEnabled( true ) ;
2294 m_peer
->InvalidateWithChildren() ;
2300 wxWindowMac
*wxGetActiveWindow()
2302 // actually this is a windows-only concept
2306 // Coordinates relative to the window
2307 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
2309 // We really don't move the mouse programmatically under Mac.
2312 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2314 if ( MacGetTopLevelWindow() == NULL
)
2317 #if TARGET_API_MAC_OSX
2318 if ( !m_macBackgroundBrush
.Ok() || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2325 event
.GetDC()->Clear() ;
2329 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2334 int wxWindowMac::GetScrollPos(int orient
) const
2336 if ( orient
== wxHORIZONTAL
)
2339 return m_hScrollBar
->GetThumbPosition() ;
2344 return m_vScrollBar
->GetThumbPosition() ;
2350 // This now returns the whole range, not just the number
2351 // of positions that we can scroll.
2352 int wxWindowMac::GetScrollRange(int orient
) const
2354 if ( orient
== wxHORIZONTAL
)
2357 return m_hScrollBar
->GetRange() ;
2362 return m_vScrollBar
->GetRange() ;
2368 int wxWindowMac::GetScrollThumb(int orient
) const
2370 if ( orient
== wxHORIZONTAL
)
2373 return m_hScrollBar
->GetThumbSize() ;
2378 return m_vScrollBar
->GetThumbSize() ;
2384 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2386 if ( orient
== wxHORIZONTAL
)
2389 m_hScrollBar
->SetThumbPosition( pos
) ;
2394 m_vScrollBar
->SetThumbPosition( pos
) ;
2399 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2400 // our own window origin is at leftOrigin/rightOrigin
2403 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2409 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2410 bool hasBothScrollbars
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && (m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2412 // back to the surrounding frame rectangle
2413 m_peer
->GetRect( &rect
) ;
2414 InsetRect( &rect
, -1 , -1 ) ;
2416 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2417 if ( UMAGetSystemVersion() >= 0x1030 )
2419 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2420 rect
.bottom
- rect
.top
) ;
2422 HIThemeFrameDrawInfo info
;
2423 memset( &info
, 0 , sizeof(info
) ) ;
2427 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2428 info
.isFocused
= hasFocus
;
2430 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2431 wxASSERT( cgContext
) ;
2433 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2435 info
.kind
= kHIThemeFrameTextFieldSquare
;
2436 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2438 else if ( HasFlag(wxSIMPLE_BORDER
) )
2440 info
.kind
= kHIThemeFrameListBox
;
2441 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2443 else if ( hasFocus
)
2445 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2448 m_peer
->GetRect( &rect
) ;
2449 if ( hasBothScrollbars
)
2451 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2452 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2453 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2454 HIThemeGrowBoxDrawInfo info
;
2455 memset( &info
, 0, sizeof(info
) ) ;
2457 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2458 info
.kind
= kHIThemeGrowBoxKindNone
;
2459 info
.size
= kHIThemeGrowBoxSizeNormal
;
2460 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2461 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2467 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2471 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2472 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2475 if ( HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2476 DrawThemeEditTextFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2477 else if ( HasFlag(wxSIMPLE_BORDER
) )
2478 DrawThemeListBoxFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2481 DrawThemeFocusRect( &rect
, true ) ;
2483 if ( hasBothScrollbars
)
2485 // GetThemeStandaloneGrowBoxBounds
2486 // DrawThemeStandaloneNoGrowBox
2491 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2493 if ( child
== m_hScrollBar
)
2494 m_hScrollBar
= NULL
;
2495 if ( child
== m_vScrollBar
)
2496 m_vScrollBar
= NULL
;
2498 wxWindowBase::RemoveChild( child
) ;
2501 // New function that will replace some of the above.
2502 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2503 int range
, bool refresh
)
2506 bool triggerSizeEvent
= false;
2508 if ( orient
== wxHORIZONTAL
)
2512 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2513 if ( m_hScrollBar
->IsShown() != showScroller
)
2515 m_hScrollBar
->Show( showScroller
);
2516 triggerSizeEvent
= true;
2519 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2526 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2527 if ( m_vScrollBar
->IsShown() != showScroller
)
2529 m_vScrollBar
->Show( showScroller
) ;
2530 triggerSizeEvent
= true;
2533 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2537 MacRepositionScrollBars() ;
2538 if ( triggerSizeEvent
)
2540 wxSizeEvent
event(GetSize(), m_windowId
);
2541 event
.SetEventObject(this);
2542 GetEventHandler()->ProcessEvent(event
);
2546 // Does a physical scroll
2547 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2549 if ( dx
== 0 && dy
== 0 )
2552 int width
, height
;
2553 GetClientSize( &width
, &height
) ;
2555 #if TARGET_API_MAC_OSX
2558 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2559 // area is scrolled, this does not occur if width and height are 2 pixels less,
2560 // TODO: write optimal workaround
2561 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2563 scrollrect
.Intersect( *rect
) ;
2565 if ( m_peer
->GetNeedsDisplay() )
2567 // because HIViewScrollRect does not scroll the already invalidated area we have two options:
2568 // either immediate redraw or full invalidate
2570 // is the better overall solution, as it does not slow down scrolling
2571 m_peer
->SetNeedsDisplay() ;
2573 // this would be the preferred version for fast drawing controls
2575 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2576 if ( UMAGetSystemVersion() >= 0x1030 )
2577 HIViewRender(m_peer
->GetControlRef()) ;
2584 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2585 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2586 m_peer
->ScrollRect( &scrollrect
, dx
, dy
) ;
2588 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2589 // either immediate redraw or full invalidate
2591 // is the better overall solution, as it does not slow down scrolling
2592 m_peer
->SetNeedsDisplay() ;
2594 // this would be the preferred version for fast drawing controls
2596 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2597 if ( UMAGetSystemVersion() >= 0x1030 )
2598 HIViewRender(m_peer
->GetControlRef()) ;
2612 RgnHandle updateRgn
= NewRgn() ;
2615 wxClientDC
dc(this) ;
2616 wxMacPortSetter
helper(&dc
) ;
2618 m_peer
->GetRectInWindowCoords( &scrollrect
) ;
2619 //scrollrect.top += MacGetTopBorderSize() ;
2620 //scrollrect.left += MacGetLeftBorderSize() ;
2621 scrollrect
.bottom
= scrollrect
.top
+ height
;
2622 scrollrect
.right
= scrollrect
.left
+ width
;
2626 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2627 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2628 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2631 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2633 // now scroll the former update region as well and add the new update region
2634 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2635 RgnHandle formerUpdateRgn
= NewRgn() ;
2636 RgnHandle scrollRgn
= NewRgn() ;
2637 RectRgn( scrollRgn
, &scrollrect
) ;
2638 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2640 LocalToGlobal( &pt
) ;
2641 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2642 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2644 if ( !EmptyRgn( formerUpdateRgn
) )
2646 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2647 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2648 InvalWindowRgn( rootWindow
, formerUpdateRgn
) ;
2651 InvalWindowRgn(rootWindow
, updateRgn
) ;
2652 DisposeRgn( updateRgn
) ;
2653 DisposeRgn( formerUpdateRgn
) ;
2654 DisposeRgn( scrollRgn
) ;
2662 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2664 child
= node
->GetData();
2667 if (child
== m_vScrollBar
)
2669 if (child
== m_hScrollBar
)
2671 if (child
->IsTopLevel())
2674 child
->GetPosition( &x
, &y
);
2675 child
->GetSize( &w
, &h
);
2678 wxRect
rc( x
, y
, w
, h
);
2679 if (rect
->Intersects( rc
))
2680 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2684 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2689 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
2691 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2693 wxScrollWinEvent wevent
;
2694 wevent
.SetPosition(event
.GetPosition());
2695 wevent
.SetOrientation(event
.GetOrientation());
2696 wevent
.SetEventObject(this);
2698 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2699 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2700 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2701 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2702 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2703 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2704 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2705 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2706 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2707 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2708 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2709 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2710 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2711 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2712 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2713 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2715 GetEventHandler()->ProcessEvent(wevent
);
2719 // Get the window with the focus
2720 wxWindowMac
*wxWindowBase::DoFindFocus()
2722 ControlRef control
;
2723 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2724 return wxFindControlFromMacControl( control
) ;
2727 void wxWindowMac::OnSetFocus( wxFocusEvent
& event
)
2729 // panel wants to track the window which was the last to have focus in it,
2730 // so we want to set ourselves as the window which last had focus
2732 // notice that it's also important to do it upwards the tree because
2733 // otherwise when the top level panel gets focus, it won't set it back to
2734 // us, but to some other sibling
2736 // CS: don't know if this is still needed:
2737 //wxChildFocusEvent eventFocus(this);
2738 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2740 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2742 #if wxMAC_USE_CORE_GRAPHICS
2743 GetParent()->Refresh() ;
2745 wxMacWindowStateSaver
sv( this ) ;
2748 m_peer
->GetRect( &rect
) ;
2749 // auf den umgebenden Rahmen zur\9fck
2750 InsetRect( &rect
, -1 , -1 ) ;
2752 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2756 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2758 rect
.right
+= pt
.x
;
2760 rect
.bottom
+= pt
.y
;
2763 bool bIsFocusEvent
= (event
.GetEventType() == wxEVT_SET_FOCUS
);
2764 DrawThemeFocusRect( &rect
, bIsFocusEvent
) ;
2765 if ( !bIsFocusEvent
)
2767 // as this erases part of the frame we have to redraw borders
2768 // and because our z-ordering is not always correct (staticboxes)
2769 // we have to invalidate things, we cannot simple redraw
2770 MacInvalidateBorders() ;
2778 void wxWindowMac::OnInternalIdle()
2780 // This calls the UI-update mechanism (querying windows for
2781 // menu/toolbar/control state information)
2782 if (wxUpdateUIEvent::CanUpdate(this))
2783 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2786 // Raise the window to the top of the Z order
2787 void wxWindowMac::Raise()
2789 m_peer
->SetZOrder( true , NULL
) ;
2792 // Lower the window to the bottom of the Z order
2793 void wxWindowMac::Lower()
2795 m_peer
->SetZOrder( false , NULL
) ;
2798 // static wxWindow *gs_lastWhich = NULL;
2800 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2802 // first trigger a set cursor event
2804 wxPoint clientorigin
= GetClientAreaOrigin() ;
2805 wxSize clientsize
= GetClientSize() ;
2807 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2809 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2811 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2812 if ( processedEvtSetCursor
&& event
.HasCursor() )
2814 cursor
= event
.GetCursor() ;
2818 // the test for processedEvtSetCursor is here to prevent using m_cursor
2819 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2820 // it - this is a way to say that our cursor shouldn't be used for this
2822 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2825 if ( !wxIsBusy() && !GetParent() )
2826 cursor
= *wxSTANDARD_CURSOR
;
2830 cursor
.MacInstall() ;
2833 return cursor
.Ok() ;
2836 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2840 return m_tooltip
->GetTip() ;
2843 return wxEmptyString
;
2846 void wxWindowMac::ClearBackground()
2852 void wxWindowMac::Update()
2854 #if TARGET_API_MAC_OSX
2855 MacGetTopLevelWindow()->MacPerformUpdates() ;
2857 ::Draw1Control( m_peer
->GetControlRef() ) ;
2861 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2863 wxTopLevelWindowMac
* win
= NULL
;
2864 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2866 win
= wxFindWinFromMacWindow( window
) ;
2871 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2873 MacUpdateClippedRects() ;
2875 return m_cachedClippedClientRect
;
2878 const wxRect
& wxWindowMac::MacGetClippedRect() const
2880 MacUpdateClippedRects() ;
2882 return m_cachedClippedRect
;
2885 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2887 MacUpdateClippedRects() ;
2889 return m_cachedClippedRectWithOuterStructure
;
2892 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2894 static wxRegion emptyrgn
;
2896 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2898 MacUpdateClippedRects() ;
2899 if ( includeOuterStructures
)
2900 return m_cachedClippedRegionWithOuterStructure
;
2902 return m_cachedClippedRegion
;
2910 void wxWindowMac::MacUpdateClippedRects() const
2912 if ( m_cachedClippedRectValid
)
2915 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2916 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2917 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2918 // to add focus borders everywhere
2920 Rect r
, rIncludingOuterStructures
;
2922 m_peer
->GetRect( &r
) ;
2923 r
.left
-= MacGetLeftBorderSize() ;
2924 r
.top
-= MacGetTopBorderSize() ;
2925 r
.bottom
+= MacGetBottomBorderSize() ;
2926 r
.right
+= MacGetRightBorderSize() ;
2933 rIncludingOuterStructures
= r
;
2934 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2936 wxRect cl
= GetClientRect() ;
2937 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2941 const wxWindow
* child
= this ;
2942 const wxWindow
* parent
= NULL
;
2944 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2946 if ( parent
->MacIsChildOfClientArea(child
) )
2948 size
= parent
->GetClientSize() ;
2949 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2955 // this will be true for scrollbars, toolbars etc.
2956 size
= parent
->GetSize() ;
2957 y
= parent
->MacGetTopBorderSize() ;
2958 x
= parent
->MacGetLeftBorderSize() ;
2959 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2960 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2963 parent
->MacWindowToRootWindow( &x
, &y
) ;
2964 MacRootWindowToWindow( &x
, &y
) ;
2966 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2968 // the wxwindow and client rects will always be clipped
2969 SectRect( &r
, &rparent
, &r
) ;
2970 SectRect( &rClient
, &rparent
, &rClient
) ;
2972 // the structure only at 'hard' borders
2973 if ( parent
->MacClipChildren() ||
2974 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2976 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2982 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2983 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2984 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2985 m_cachedClippedRectWithOuterStructure
= wxRect(
2986 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2987 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2988 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2990 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2991 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2992 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2994 m_cachedClippedRectValid
= true ;
2998 This function must not change the updatergn !
3000 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
3002 bool handled
= false ;
3004 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
3005 GetRegionBounds( updatergn
, &updatebounds
) ;
3007 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
3009 if ( !EmptyRgn(updatergn
) )
3011 RgnHandle newupdate
= NewRgn() ;
3012 wxSize point
= GetClientSize() ;
3013 wxPoint origin
= GetClientAreaOrigin() ;
3014 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
3015 SectRgn( newupdate
, updatergn
, newupdate
) ;
3017 // first send an erase event to the entire update area
3019 // for the toplevel window this really is the entire area
3020 // for all the others only their client area, otherwise they
3021 // might be drawing with full alpha and eg put blue into
3022 // the grow-box area of a scrolled window (scroll sample)
3023 wxDC
* dc
= new wxWindowDC(this);
3025 dc
->SetClippingRegion(wxRegion(updatergn
));
3027 dc
->SetClippingRegion(wxRegion(newupdate
));
3029 wxEraseEvent
eevent( GetId(), dc
);
3030 eevent
.SetEventObject( this );
3031 GetEventHandler()->ProcessEvent( eevent
);
3035 // calculate a client-origin version of the update rgn and set m_updateRegion to that
3036 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
3037 m_updateRegion
= newupdate
;
3038 DisposeRgn( newupdate
) ;
3040 if ( !m_updateRegion
.Empty() )
3042 // paint the window itself
3045 event
.SetTimestamp(time
);
3046 event
.SetEventObject(this);
3047 GetEventHandler()->ProcessEvent(event
);
3051 // now we cannot rely on having its borders drawn by a window itself, as it does not
3052 // get the updateRgn wide enough to always do so, so we do it from the parent
3053 // this would also be the place to draw any custom backgrounds for native controls
3054 // in Composited windowing
3055 wxPoint clientOrigin
= GetClientAreaOrigin() ;
3059 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
3061 child
= node
->GetData();
3064 if (child
== m_vScrollBar
)
3066 if (child
== m_hScrollBar
)
3068 if (child
->IsTopLevel())
3070 if (!child
->IsShown())
3073 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
3075 child
->GetPosition( &x
, &y
);
3076 child
->GetSize( &w
, &h
);
3077 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
3078 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
3079 InsetRect( &childRect
, -10 , -10) ;
3081 if ( RectInRgn( &childRect
, updatergn
) )
3083 // paint custom borders
3084 wxNcPaintEvent
eventNc( child
->GetId() );
3085 eventNc
.SetEventObject( child
);
3086 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
3088 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
3089 if ( UMAGetSystemVersion() >= 0x1030 )
3091 child
->MacPaintBorders(0, 0) ;
3096 wxWindowDC
dc(this) ;
3097 dc
.SetClippingRegion(wxRegion(updatergn
));
3098 wxMacPortSetter
helper(&dc
) ;
3099 child
->MacPaintBorders(0, 0) ;
3110 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
3112 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3116 if ( iter
->IsTopLevel() )
3117 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
3119 iter
= iter
->GetParent() ;
3122 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
3127 void wxWindowMac::MacCreateScrollBars( long style
)
3129 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
3131 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
3133 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
3134 int scrlsize
= MAC_SCROLLBAR_SIZE
;
3135 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
3136 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
3138 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
3139 variant
= wxWINDOW_VARIANT_SMALL
;
3142 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
3144 GetClientSize( &width
, &height
) ;
3146 wxPoint
vPoint(width
- scrlsize
, 0) ;
3147 wxSize
vSize(scrlsize
, height
- adjust
) ;
3148 wxPoint
hPoint(0, height
- scrlsize
) ;
3149 wxSize
hSize(width
- adjust
, scrlsize
) ;
3151 if ( style
& wxVSCROLL
)
3152 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
3154 if ( style
& wxHSCROLL
)
3155 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
3158 // because the create does not take into account the client area origin
3159 // we might have a real position shift
3160 MacRepositionScrollBars() ;
3163 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
3165 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
3170 void wxWindowMac::MacRepositionScrollBars()
3172 if ( !m_hScrollBar
&& !m_vScrollBar
)
3175 bool hasBoth
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3176 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3177 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3179 // get real client area
3181 GetSize( &width
, &height
);
3183 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3184 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3186 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
3187 wxSize
vSize( scrlsize
, height
- adjust
) ;
3188 wxPoint
hPoint( 0 , height
- scrlsize
) ;
3189 wxSize
hSize( width
- adjust
, scrlsize
) ;
3192 int x
= 0, y
= 0, w
, h
;
3193 GetSize( &w
, &h
) ;
3195 MacClientToRootWindow( &x
, &y
) ;
3196 MacClientToRootWindow( &w
, &h
) ;
3198 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3200 int totW
= 10000 , totH
= 10000;
3203 if ( iter
->IsTopLevel() )
3205 iter
->GetSize( &totW
, &totH
) ;
3209 iter
= iter
->GetParent() ;
3223 if ( w
- x
>= totW
)
3228 if ( h
- y
>= totH
)
3236 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3238 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3241 bool wxWindowMac::AcceptsFocus() const
3243 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3246 void wxWindowMac::MacSuperChangedPosition()
3248 // only window-absolute structures have to be moved i.e. controls
3250 m_cachedClippedRectValid
= false ;
3253 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3256 child
= node
->GetData();
3257 child
->MacSuperChangedPosition() ;
3259 node
= node
->GetNext();
3263 void wxWindowMac::MacTopLevelWindowChangedPosition()
3265 // only screen-absolute structures have to be moved i.e. glcanvas
3268 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3271 child
= node
->GetData();
3272 child
->MacTopLevelWindowChangedPosition() ;
3274 node
= node
->GetNext();
3278 long wxWindowMac::MacGetLeftBorderSize() const
3285 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
3287 // this metric is only the 'outset' outside the simple frame rect
3288 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3291 else if (HasFlag(wxSIMPLE_BORDER
))
3293 // this metric is only the 'outset' outside the simple frame rect
3294 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3301 long wxWindowMac::MacGetRightBorderSize() const
3303 // they are all symmetric in mac themes
3304 return MacGetLeftBorderSize() ;
3307 long wxWindowMac::MacGetTopBorderSize() const
3309 // they are all symmetric in mac themes
3310 return MacGetLeftBorderSize() ;
3313 long wxWindowMac::MacGetBottomBorderSize() const
3315 // they are all symmetric in mac themes
3316 return MacGetLeftBorderSize() ;
3319 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3321 return style
& ~wxBORDER_MASK
;
3324 // Find the wxWindowMac at the current mouse position, returning the mouse
3326 wxWindowMac
* wxFindWindowAtPointer( wxPoint
& pt
)
3328 pt
= wxGetMousePosition();
3329 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3334 // Get the current mouse position.
3335 wxPoint
wxGetMousePosition()
3339 wxGetMousePosition( &x
, &y
);
3341 return wxPoint(x
, y
);
3344 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3346 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3348 // copied from wxGTK : CS
3349 // VZ: shouldn't we move this to base class then?
3351 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3354 // (a) it's a command event and so is propagated to the parent
3355 // (b) under MSW it can be generated from kbd too
3356 // (c) it uses screen coords (because of (a))
3357 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3359 this->ClientToScreen(event
.GetPosition()));
3360 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3369 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3371 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3372 CallNextEventHandler(
3373 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
3374 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3377 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3381 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3385 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3386 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
3391 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3393 return eventNotHandledErr
;
3396 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
3398 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
3399 if ( !wxWindowBase::Reparent(newParent
) )
3402 // copied from MacPostControlCreate
3403 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
3405 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
3407 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
3412 bool wxWindowMac::SetTransparent(wxByte alpha
)
3414 #if wxMAC_USE_CORE_GRAPHICS
3415 if ( alpha
!= m_macAlpha
)
3417 m_macAlpha
= alpha
;
3427 bool wxWindowMac::CanSetTransparent()
3429 #if wxMAC_USE_CORE_GRAPHICS
3436 wxByte
wxWindowMac::GetTransparent() const