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 // ---------------------------------------------------------------------------
93 // Utility Routines to move between different coordinate systems
94 // ---------------------------------------------------------------------------
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)
111 // originating from native control
115 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
117 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
120 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
122 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
126 // directed towards native control
129 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
131 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
134 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
136 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
139 // ---------------------------------------------------------------------------
141 // ---------------------------------------------------------------------------
143 #if TARGET_API_MAC_OSX
145 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
148 kEventControlVisibilityChanged
= 157
154 static const EventTypeSpec eventList
[] =
156 { kEventClassCommand
, kEventProcessCommand
} ,
157 { kEventClassCommand
, kEventCommandUpdateStatus
} ,
159 { kEventClassControl
, kEventControlHit
} ,
161 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
162 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
164 { kEventClassControl
, kEventControlDraw
} ,
165 #if TARGET_API_MAC_OSX
166 { kEventClassControl
, kEventControlVisibilityChanged
} ,
167 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
168 { kEventClassControl
, kEventControlHiliteChanged
} ,
170 { kEventClassControl
, kEventControlSetFocusPart
} ,
172 { kEventClassService
, kEventServiceGetTypes
},
173 { kEventClassService
, kEventServiceCopy
},
174 { kEventClassService
, kEventServicePaste
},
176 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
177 // { kEventClassControl , kEventControlBoundsChanged } ,
180 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
182 OSStatus result
= eventNotHandledErr
;
184 wxMacCarbonEvent
cEvent( event
) ;
186 ControlRef controlRef
;
187 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
189 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
191 switch ( GetEventKind( event
) )
193 #if TARGET_API_MAC_OSX
194 case kEventControlDraw
:
196 RgnHandle updateRgn
= NULL
;
197 RgnHandle allocatedRgn
= NULL
;
198 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
200 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
202 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
206 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
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
) ;
212 // hide the given region by the new region that must be shifted
213 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
214 updateRgn
= allocatedRgn
;
219 GetRegionBounds( updateRgn
, &rgnBounds
) ;
221 #if wxMAC_DEBUG_REDRAW
222 if ( thisWindow
->MacIsUserPane() )
224 static float color
= 0.5 ;
227 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
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
);
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
) ;
253 wxMacCGContextStateSaver
sg( cgContext
) ;
256 wxWindow
* iter
= thisWindow
;
259 alpha
*= (float) iter
->GetTransparent()/255.0 ;
260 if ( iter
->IsTopLevel() )
263 iter
= iter
->GetParent() ;
266 CGContextSetAlpha( cgContext
, alpha
) ;
268 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
271 #if wxMAC_USE_CORE_GRAPHICS
272 thisWindow
->MacSetCGContextRef( NULL
) ;
276 CGContextRelease( cgContext
) ;
281 DisposeRgn( allocatedRgn
) ;
285 case kEventControlVisibilityChanged
:
286 thisWindow
->MacVisibilityChanged() ;
289 case kEventControlEnabledStateChanged
:
290 thisWindow
->MacEnabledStateChanged() ;
293 case kEventControlHiliteChanged
:
294 thisWindow
->MacHiliteChanged() ;
298 // we emulate this event under Carbon CFM
299 case kEventControlSetFocusPart
:
301 Boolean focusEverything
= false ;
302 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
305 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
310 if ( controlPart
== kControlFocusNoPart
)
313 if ( thisWindow
->GetCaret() )
314 thisWindow
->GetCaret()->OnKillFocus();
317 static bool inKillFocusEvent
= false ;
319 if ( !inKillFocusEvent
)
321 inKillFocusEvent
= true ;
322 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
323 event
.SetEventObject(thisWindow
);
324 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
325 inKillFocusEvent
= false ;
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
);
335 if ( thisWindow
->GetCaret() )
336 thisWindow
->GetCaret()->OnSetFocus();
339 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
340 event
.SetEventObject(thisWindow
);
341 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
344 if ( thisWindow
->MacIsUserPane() )
349 case kEventControlHit
:
350 result
= thisWindow
->MacControlHit( handler
, event
) ;
360 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
362 OSStatus result
= eventNotHandledErr
;
364 wxMacCarbonEvent
cEvent( event
) ;
366 ControlRef controlRef
;
367 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
368 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
369 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
371 switch ( GetEventKind( event
) )
373 case kEventServiceGetTypes
:
377 textCtrl
->GetSelection( &from
, &to
) ;
379 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
381 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
382 if ( textCtrl
->IsEditable() )
383 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
385 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt', 'PICT', 'MooV', 'AIFF' */ };
386 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
388 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
392 CFArrayAppendValue(copyTypes
, typestring
) ;
394 CFArrayAppendValue(pasteTypes
, typestring
) ;
396 CFRelease( typestring
) ;
404 case kEventServiceCopy
:
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() ) ) ;
419 case kEventServicePaste
:
422 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
423 Size textSize
, pastedSize
;
424 verify_noerr( GetScrapFlavorSize(scrapRef
, kTXNTextData
, &textSize
) ) ;
426 char *content
= new char[textSize
] ;
427 GetScrapFlavorData(scrapRef
, kTXNTextData
, &pastedSize
, content
);
428 content
[textSize
- 1] = 0 ;
431 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
433 textCtrl
->WriteText( wxString( content
) ) ;
448 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
450 OSStatus result
= eventNotHandledErr
;
451 wxWindowMac
* focus
= (wxWindowMac
*) data
;
453 wchar_t* uniChars
= NULL
;
454 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
456 UniChar
* charBuf
= NULL
;
457 UInt32 dataSize
= 0 ;
460 if ( GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
462 numChars
= dataSize
/ sizeof( UniChar
) + 1;
465 if ( (size_t) numChars
* 2 > sizeof(buf
) )
466 charBuf
= new UniChar
[ numChars
] ;
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 ) ;
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
) ;
483 switch ( GetEventKind( event
) )
485 case kEventTextInputUpdateActiveInputArea
:
487 // An IME input event may return several characters, but we need to send one char at a time to
489 for (int pos
=0 ; pos
< numChars
; pos
++)
491 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
492 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
493 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
495 UInt32 message
= (0 << 8) + ((char)uniChars
[pos
] );
496 if ( wxTheApp
->MacSendCharEvent(
497 focus
, message
, 0 , when
, 0 , 0 , uniChars
[pos
] ) )
502 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
506 case kEventTextInputUnicodeForKeyEvent
:
508 UInt32 keyCode
, modifiers
;
511 unsigned char charCode
;
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
);
519 UInt32 message
= (keyCode
<< 8) + charCode
;
521 // An IME input event may return several characters, but we need to send one char at a time to
523 for (int pos
=0 ; pos
< numChars
; pos
++)
525 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
526 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
527 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
529 if ( wxTheApp
->MacSendCharEvent(
530 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChars
[pos
] ) )
535 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
544 if ( charBuf
!= buf
)
550 static pascal OSStatus
wxMacWindowCommandEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
552 OSStatus result
= eventNotHandledErr
;
553 wxWindowMac
* focus
= (wxWindowMac
*) data
;
557 wxMacCarbonEvent
cEvent( event
) ;
558 cEvent
.GetParameter
<HICommand
>(kEventParamDirectObject
,typeHICommand
,&command
) ;
560 wxMenuItem
* item
= NULL
;
561 wxMenu
* itemMenu
= wxFindMenuFromMacCommand( command
, item
) ;
562 int id
= wxMacCommandToId( command
.commandID
) ;
566 wxASSERT( itemMenu
!= NULL
) ;
568 switch ( cEvent
.GetKind() )
570 case kEventProcessCommand
:
572 if (item
->IsCheckable())
573 item
->Check( !item
->IsChecked() ) ;
575 if ( itemMenu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) )
579 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, id
);
580 event
.SetEventObject(focus
);
581 event
.SetInt(item
->IsCheckable() ? item
->IsChecked() : -1);
583 if ( focus
->GetEventHandler()->ProcessEvent(event
) )
589 case kEventCommandUpdateStatus
:
591 wxUpdateUIEvent
event(id
);
592 event
.SetEventObject( itemMenu
);
594 bool processed
= false;
596 // Try the menu's event handler
598 wxEvtHandler
*handler
= itemMenu
->GetEventHandler();
600 processed
= handler
->ProcessEvent(event
);
603 // Try the window the menu was popped up from
604 // (and up through the hierarchy)
607 const wxMenuBase
*menu
= itemMenu
;
610 wxWindow
*win
= menu
->GetInvokingWindow();
613 processed
= win
->GetEventHandler()->ProcessEvent(event
);
617 menu
= menu
->GetParent();
623 processed
= focus
->GetEventHandler()->ProcessEvent(event
);
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());
648 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
650 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
651 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
652 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
653 OSStatus result
= eventNotHandledErr
;
655 switch ( GetEventClass( event
) )
657 case kEventClassCommand
:
658 result
= wxMacWindowCommandEventHandler( handler
, event
, data
) ;
661 case kEventClassControl
:
662 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
665 case kEventClassService
:
666 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
669 case kEventClassTextInput
:
670 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
677 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
682 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
684 #if !TARGET_API_MAC_OSX
686 // ---------------------------------------------------------------------------
687 // UserPane events for non OSX builds
688 // ---------------------------------------------------------------------------
690 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
692 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
694 win
->MacControlUserPaneDrawProc(part
) ;
696 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP
, wxMacControlUserPaneDrawProc
) ;
698 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
700 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
702 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
704 return kControlNoPart
;
706 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP
, wxMacControlUserPaneHitTestProc
) ;
708 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
710 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
712 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
714 return kControlNoPart
;
716 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP
, wxMacControlUserPaneTrackingProc
) ;
718 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
720 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
722 win
->MacControlUserPaneIdleProc() ;
724 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP
, wxMacControlUserPaneIdleProc
) ;
726 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
728 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
730 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
732 return kControlNoPart
;
734 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP
, wxMacControlUserPaneKeyDownProc
) ;
736 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
738 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
740 win
->MacControlUserPaneActivateProc(activating
) ;
742 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP
, wxMacControlUserPaneActivateProc
) ;
744 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
746 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
748 return win
->MacControlUserPaneFocusProc(action
) ;
750 return kControlNoPart
;
752 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP
, wxMacControlUserPaneFocusProc
) ;
754 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
756 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
758 win
->MacControlUserPaneBackgroundProc(info
) ;
760 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP
, wxMacControlUserPaneBackgroundProc
) ;
762 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
765 RgnHandle rgn
= NewRgn() ;
767 MacWindowToRootWindow( &x
, &y
) ;
768 OffsetRgn( rgn
, -x
, -y
) ;
769 wxMacWindowStateSaver
sv( this ) ;
770 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
771 MacDoRedraw( rgn
, 0 ) ;
775 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
777 return kControlNoPart
;
780 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
782 return kControlNoPart
;
785 void wxWindowMac::MacControlUserPaneIdleProc()
789 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
791 return kControlNoPart
;
794 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
798 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
800 if ( AcceptsFocus() )
803 return kControlNoPart
;
806 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
812 // ---------------------------------------------------------------------------
813 // Scrollbar Tracking for all
814 // ---------------------------------------------------------------------------
816 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
817 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
821 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
823 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
826 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
828 // ===========================================================================
830 // ===========================================================================
832 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
834 static MacControlMap wxWinMacControlList
;
836 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
838 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
840 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
843 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
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") );
849 wxWinMacControlList
[inControl
] = control
;
852 void wxRemoveMacControlAssociation(wxWindow
*control
)
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...
862 MacControlMap::iterator it
;
863 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
865 if ( it
->second
== control
)
867 wxWinMacControlList
.erase(it
);
875 // ----------------------------------------------------------------------------
876 // constructors and such
877 // ----------------------------------------------------------------------------
879 wxWindowMac::wxWindowMac()
884 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
889 const wxString
& name
)
892 Create(parent
, id
, pos
, size
, style
, name
);
895 void wxWindowMac::Init()
901 #if WXWIN_COMPATIBILITY_2_4
902 m_backgroundTransparent
= false;
905 #if wxMAC_USE_CORE_GRAPHICS
906 m_cgContextRef
= NULL
;
909 // as all windows are created with WS_VISIBLE style...
912 m_hScrollBar
= NULL
;
913 m_vScrollBar
= NULL
;
914 m_macBackgroundBrush
= wxNullBrush
;
916 m_macIsUserPane
= true;
917 m_clipChildren
= false ;
918 m_cachedClippedRectValid
= false ;
920 // we need a valid font for the encodings
921 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
924 wxWindowMac::~wxWindowMac()
928 m_isBeingDeleted
= true;
930 MacInvalidateBorders() ;
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() )
936 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
939 if ( frame
->GetLastFocus() == this )
940 frame
->SetLastFocus((wxWindow
*)NULL
);
946 // destroy children before destroying this window itself
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
);
955 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
956 tlw
->SetDefaultItem(NULL
);
959 if ( m_peer
&& m_peer
->Ok() )
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 ) ;
969 if ( g_MacLastWindow
== this )
970 g_MacLastWindow
= NULL
;
972 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
975 if ( frame
->GetLastFocus() == this )
976 frame
->SetLastFocus( NULL
) ;
979 // delete our drop target if we've got one
980 #if wxUSE_DRAG_AND_DROP
981 if ( m_dropTarget
!= NULL
)
991 WXWidget
wxWindowMac::GetHandle() const
993 return (WXWidget
) m_peer
->GetControlRef() ;
996 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
998 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
999 InstallControlEventHandler( (ControlRef
)control
, GetwxMacWindowEventHandlerUPP(),
1000 GetEventTypeCount(eventList
), eventList
, this,
1001 (EventHandlerRef
*)&m_macControlEventHandler
);
1003 #if !TARGET_API_MAC_OSX
1004 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
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()) ;
1019 bool wxWindowMac::Create(wxWindowMac
*parent
,
1024 const wxString
& name
)
1026 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
1028 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
1031 m_windowVariant
= parent
->GetWindowVariant() ;
1033 if ( m_macIsUserPane
)
1035 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
1038 | kControlSupportsEmbedding
1039 | kControlSupportsLiveFeedback
1040 | kControlGetsFocusOnClick
1041 // | kControlHasSpecialBackground
1042 // | kControlSupportsCalcBestRect
1043 | kControlHandlesTracking
1044 | kControlSupportsFocus
1045 | kControlWantsActivate
1046 | kControlWantsIdle
;
1048 m_peer
= new wxMacControl(this) ;
1049 OSStatus err
=::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
1050 verify_noerr( err
);
1052 MacPostControlCreate(pos
, size
) ;
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
))))
1060 MacCreateScrollBars( style
) ;
1064 wxWindowCreateEvent
event(this);
1065 GetEventHandler()->AddPendingEvent(event
);
1070 void wxWindowMac::MacChildAdded()
1073 m_vScrollBar
->Raise() ;
1075 m_hScrollBar
->Raise() ;
1078 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
1080 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
1082 m_peer
->SetReference( (long)this ) ;
1083 GetParent()->AddChild( this );
1085 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
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() ;
1092 // adjust font, controlsize etc
1093 DoSetWindowVariant( m_windowVariant
) ;
1095 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
) ) ;
1097 if (!m_macIsUserPane
)
1098 SetInitialBestSize(size
);
1100 SetCursor( *wxSTANDARD_CURSOR
) ;
1103 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
1105 // Don't assert, in case we set the window variant before
1106 // the window is created
1107 // wxASSERT( m_peer->Ok() ) ;
1109 m_windowVariant
= variant
;
1111 if (m_peer
== NULL
|| !m_peer
->Ok())
1115 ThemeFontID themeFont
= kThemeSystemFont
;
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
1123 case wxWINDOW_VARIANT_NORMAL
:
1124 size
= kControlSizeNormal
;
1125 themeFont
= kThemeSystemFont
;
1128 case wxWINDOW_VARIANT_SMALL
:
1129 size
= kControlSizeSmall
;
1130 themeFont
= kThemeSmallSystemFont
;
1133 case wxWINDOW_VARIANT_MINI
:
1134 if (UMAGetSystemVersion() >= 0x1030 )
1136 // not always defined in the headers
1142 size
= kControlSizeSmall
;
1143 themeFont
= kThemeSmallSystemFont
;
1147 case wxWINDOW_VARIANT_LARGE
:
1148 size
= kControlSizeLarge
;
1149 themeFont
= kThemeSystemFont
;
1153 wxFAIL_MSG(_T("unexpected window variant"));
1157 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
1160 font
.MacCreateThemeFont( themeFont
) ;
1164 void wxWindowMac::MacUpdateControlFont()
1166 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1170 bool wxWindowMac::SetFont(const wxFont
& font
)
1172 bool retval
= wxWindowBase::SetFont( font
);
1174 MacUpdateControlFont() ;
1179 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1181 bool retval
= wxWindowBase::SetForegroundColour( col
);
1184 MacUpdateControlFont();
1189 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1191 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1195 wxColour
newCol(GetBackgroundColour());
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
) ;
1202 brush
.SetColour( newCol
) ;
1204 MacSetBackgroundBrush( brush
) ;
1205 MacUpdateControlFont() ;
1210 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1212 m_macBackgroundBrush
= brush
;
1213 m_peer
->SetBackground( brush
) ;
1216 bool wxWindowMac::MacCanFocus() const
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
);
1225 if ( keyExistsAndHasValidFormat
&& fullKeyboardAccess
> 0 )
1231 UInt32 features
= 0 ;
1232 m_peer
->GetFeatures( &features
) ;
1234 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1238 void wxWindowMac::SetFocus()
1240 if ( !AcceptsFocus() )
1243 wxWindow
* former
= FindFocus() ;
1244 if ( former
== this )
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
)
1253 SetUserFocusWindow( (WindowRef
)MacGetTopLevelWindowRef() );
1255 #if !TARGET_API_MAC_OSX
1256 // emulate carbon events when running under CarbonLib where they are not natively available
1259 EventRef evRef
= NULL
;
1261 err
= MacCreateEvent(
1262 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1263 kEventAttributeUserEvent
, &evRef
);
1264 verify_noerr( err
);
1266 wxMacCarbonEvent
cEvent( evRef
) ;
1267 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1268 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1270 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1271 ReleaseEvent( evRef
) ;
1274 // send new focus event
1276 EventRef evRef
= NULL
;
1278 err
= MacCreateEvent(
1279 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1280 kEventAttributeUserEvent
, &evRef
);
1281 verify_noerr( err
);
1283 wxMacCarbonEvent
cEvent( evRef
) ;
1284 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1285 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1287 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1288 ReleaseEvent( evRef
) ;
1293 void wxWindowMac::DoCaptureMouse()
1295 wxApp::s_captureWindow
= this ;
1298 wxWindow
* wxWindowBase::GetCapture()
1300 return wxApp::s_captureWindow
;
1303 void wxWindowMac::DoReleaseMouse()
1305 wxApp::s_captureWindow
= NULL
;
1308 #if wxUSE_DRAG_AND_DROP
1310 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1312 if ( m_dropTarget
!= NULL
)
1313 delete m_dropTarget
;
1315 m_dropTarget
= pDropTarget
;
1316 if ( m_dropTarget
!= NULL
)
1324 // Old-style File Manager Drag & Drop
1325 void wxWindowMac::DragAcceptFiles(bool accept
)
1330 // Returns the size of the native control. In the case of the toplevel window
1331 // this is the content area root control
1333 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1334 int& w
, int& h
) const
1336 wxFAIL_MSG( wxT("Not currently supported") ) ;
1339 // From a wx position / size calculate the appropriate size of the native control
1341 bool wxWindowMac::MacGetBoundsForControl(
1345 int& w
, int& h
, bool adjustOrigin
) const
1347 // the desired size, minus the border pixels gives the correct size of the control
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 ) ;
1355 x
+= MacGetLeftBorderSize() ;
1356 y
+= MacGetTopBorderSize() ;
1357 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1358 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1361 AdjustForParentClientOrigin( x
, y
) ;
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() )
1366 x
-= GetParent()->MacGetLeftBorderSize() ;
1367 y
-= GetParent()->MacGetTopBorderSize() ;
1373 // Get window size (not client size)
1374 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1377 m_peer
->GetRect( &bounds
) ;
1380 *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1382 *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
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
1389 m_peer
->GetRect( &bounds
) ;
1391 int x1
= bounds
.left
;
1392 int y1
= bounds
.top
;
1394 // get the wx window position from the native one
1395 x1
-= MacGetLeftBorderSize() ;
1396 y1
-= MacGetTopBorderSize() ;
1398 if ( !IsTopLevel() )
1400 wxWindow
*parent
= GetParent();
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() ;
1408 // and now to client coordinates
1409 wxPoint
pt(parent
->GetClientAreaOrigin());
1421 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1423 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1424 wxCHECK_RET( window
, wxT("TopLevel Window missing") ) ;
1426 Point localwhere
= { 0, 0 } ;
1433 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1440 MacRootWindowToWindow( x
, y
) ;
1442 wxPoint origin
= GetClientAreaOrigin() ;
1449 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1451 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1452 wxCHECK_RET( window
, wxT("TopLevel window missing") ) ;
1454 wxPoint origin
= GetClientAreaOrigin() ;
1460 MacWindowToRootWindow( x
, y
) ;
1462 Point localwhere
= { 0, 0 };
1468 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1476 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1478 wxPoint origin
= GetClientAreaOrigin() ;
1484 MacWindowToRootWindow( x
, y
) ;
1487 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1489 MacRootWindowToWindow( x
, y
) ;
1491 wxPoint origin
= GetClientAreaOrigin() ;
1498 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1507 if ( !IsTopLevel() )
1509 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1512 pt
.x
-= MacGetLeftBorderSize() ;
1513 pt
.y
-= MacGetTopBorderSize() ;
1514 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1524 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1533 MacWindowToRootWindow( &x1
, &y1
) ;
1541 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1550 if ( !IsTopLevel() )
1552 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1555 wxMacControl::Convert( &pt
, top
->m_peer
, m_peer
) ;
1556 pt
.x
+= MacGetLeftBorderSize() ;
1557 pt
.y
+= MacGetTopBorderSize() ;
1567 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1576 MacRootWindowToWindow( &x1
, &y1
) ;
1584 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1586 RgnHandle rgn
= NewRgn() ;
1588 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1590 Rect structure
, content
;
1592 GetRegionBounds( rgn
, &content
) ;
1593 m_peer
->GetRect( &structure
) ;
1594 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1596 left
= content
.left
- structure
.left
;
1597 top
= content
.top
- structure
.top
;
1598 right
= structure
.right
- content
.right
;
1599 bottom
= structure
.bottom
- content
.bottom
;
1603 left
= top
= right
= bottom
= 0 ;
1609 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1611 wxSize sizeTotal
= size
;
1613 RgnHandle rgn
= NewRgn() ;
1614 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1616 Rect content
, structure
;
1617 GetRegionBounds( rgn
, &content
) ;
1618 m_peer
->GetRect( &structure
) ;
1620 // structure is in parent coordinates, but we only need width and height, so it's ok
1622 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1623 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1628 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1629 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1634 // Get size *available for subwindows* i.e. excluding menu bar etc.
1635 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
1639 RgnHandle rgn
= NewRgn() ;
1641 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1642 GetRegionBounds( rgn
, &content
) ;
1644 m_peer
->GetRect( &content
) ;
1647 ww
= content
.right
- content
.left
;
1648 hh
= content
.bottom
- content
.top
;
1650 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1651 hh
-= m_hScrollBar
->GetSize().y
;
1653 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1654 ww
-= m_vScrollBar
->GetSize().x
;
1662 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1664 if (m_cursor
== cursor
)
1667 if (wxNullCursor
== cursor
)
1669 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1674 if ( ! wxWindowBase::SetCursor( cursor
) )
1678 wxASSERT_MSG( m_cursor
.Ok(),
1679 wxT("cursor must be valid after call to the base version"));
1681 wxWindowMac
*mouseWin
= 0 ;
1683 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1684 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1686 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1688 // TODO: If we ever get a GetCurrentEvent... replacement
1689 // for the mouse position, use it...
1692 ControlPartCode part
;
1693 ControlRef control
;
1696 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1698 mouseWin
= wxFindControlFromMacControl( control
) ;
1701 QDSwapPort( savePort
, NULL
) ;
1704 if ( mouseWin
== this && !wxIsBusy() )
1705 m_cursor
.MacInstall() ;
1711 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1713 menu
->SetInvokingWindow(this);
1716 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
1718 wxPoint mouse
= wxGetMousePosition();
1724 ClientToScreen( &x
, &y
) ;
1727 menu
->MacBeforeDisplay( true ) ;
1728 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() , y
, x
, 0) ;
1729 if ( HiWord(menuResult
) != 0 )
1732 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &macid
);
1733 int id
= wxMacCommandToId( macid
);
1734 wxMenuItem
* item
= NULL
;
1736 item
= menu
->FindItem( id
, &realmenu
) ;
1739 if (item
->IsCheckable())
1740 item
->Check( !item
->IsChecked() ) ;
1742 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1746 menu
->MacAfterDisplay( true ) ;
1747 menu
->SetInvokingWindow( NULL
);
1753 // ----------------------------------------------------------------------------
1755 // ----------------------------------------------------------------------------
1759 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1761 wxWindowBase::DoSetToolTip(tooltip
);
1764 m_tooltip
->SetWindow(this);
1769 void wxWindowMac::MacInvalidateBorders()
1771 if ( m_peer
== NULL
)
1774 bool vis
= MacIsReallyShown() ;
1778 int outerBorder
= MacGetLeftBorderSize() ;
1779 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1782 if ( outerBorder
== 0 )
1785 // now we know that we have something to do at all
1787 // as the borders are drawn on the parent we have to properly invalidate all these areas
1788 RgnHandle updateInner
, updateOuter
;
1791 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1792 updateInner
= NewRgn() ;
1793 updateOuter
= NewRgn() ;
1795 m_peer
->GetRect( &rect
) ;
1796 RectRgn( updateInner
, &rect
) ;
1797 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1798 RectRgn( updateOuter
, &rect
) ;
1799 DiffRgn( updateOuter
, updateInner
, updateOuter
) ;
1801 #ifdef __WXMAC_OSX__
1802 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1804 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1806 InvalWindowRgn( tlw
, updateOuter
) ;
1809 DisposeRgn( updateOuter
) ;
1810 DisposeRgn( updateInner
) ;
1813 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1815 // this is never called for a toplevel window, so we know we have a parent
1816 int former_x
, former_y
, former_w
, former_h
;
1818 // Get true coordinates of former position
1819 DoGetPosition( &former_x
, &former_y
) ;
1820 DoGetSize( &former_w
, &former_h
) ;
1822 wxWindow
*parent
= GetParent();
1825 wxPoint
pt(parent
->GetClientAreaOrigin());
1830 int actualWidth
= width
;
1831 int actualHeight
= height
;
1835 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1836 actualWidth
= m_minWidth
;
1837 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1838 actualHeight
= m_minHeight
;
1839 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1840 actualWidth
= m_maxWidth
;
1841 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1842 actualHeight
= m_maxHeight
;
1844 bool doMove
= false, doResize
= false ;
1846 if ( actualX
!= former_x
|| actualY
!= former_y
)
1849 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1852 if ( doMove
|| doResize
)
1854 // as the borders are drawn outside the native control, we adjust now
1856 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1857 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1858 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1861 wxMacRectToNative( &bounds
, &r
) ;
1863 if ( !GetParent()->IsTopLevel() )
1864 wxMacWindowToNative( GetParent() , &r
) ;
1866 MacInvalidateBorders() ;
1868 m_cachedClippedRectValid
= false ;
1869 m_peer
->SetRect( &r
) ;
1871 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1873 MacInvalidateBorders() ;
1875 MacRepositionScrollBars() ;
1878 wxPoint
point(actualX
, actualY
);
1879 wxMoveEvent
event(point
, m_windowId
);
1880 event
.SetEventObject(this);
1881 GetEventHandler()->ProcessEvent(event
) ;
1886 MacRepositionScrollBars() ;
1887 wxSize
size(actualWidth
, actualHeight
);
1888 wxSizeEvent
event(size
, m_windowId
);
1889 event
.SetEventObject(this);
1890 GetEventHandler()->ProcessEvent(event
);
1895 wxSize
wxWindowMac::DoGetBestSize() const
1897 if ( m_macIsUserPane
|| IsTopLevel() )
1898 return wxWindowBase::DoGetBestSize() ;
1900 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1901 int bestWidth
, bestHeight
;
1903 m_peer
->GetBestRect( &bestsize
) ;
1904 if ( EmptyRect( &bestsize
) )
1909 bestsize
.bottom
= 16 ;
1911 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1913 bestsize
.bottom
= 16 ;
1916 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1918 bestsize
.bottom
= 24 ;
1923 // return wxWindowBase::DoGetBestSize() ;
1927 bestWidth
= bestsize
.right
- bestsize
.left
;
1928 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1929 if ( bestHeight
< 10 )
1932 return wxSize(bestWidth
, bestHeight
);
1935 // set the size of the window: if the dimensions are positive, just use them,
1936 // but if any of them is equal to -1, it means that we must find the value for
1937 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1938 // which case -1 is a valid value for x and y)
1940 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1941 // the width/height to best suit our contents, otherwise we reuse the current
1943 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1945 // get the current size and position...
1946 int currentX
, currentY
;
1947 int currentW
, currentH
;
1949 GetPosition(¤tX
, ¤tY
);
1950 GetSize(¤tW
, ¤tH
);
1952 // ... and don't do anything (avoiding flicker) if it's already ok
1953 if ( x
== currentX
&& y
== currentY
&&
1954 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1957 MacRepositionScrollBars() ; // we might have a real position shift
1962 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1964 if ( x
== wxDefaultCoord
)
1966 if ( y
== wxDefaultCoord
)
1970 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1972 wxSize size
= wxDefaultSize
;
1973 if ( width
== wxDefaultCoord
)
1975 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1977 size
= DoGetBestSize();
1982 // just take the current one
1987 if ( height
== wxDefaultCoord
)
1989 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1991 if ( size
.x
== wxDefaultCoord
)
1992 size
= DoGetBestSize();
1993 // else: already called DoGetBestSize() above
1999 // just take the current one
2004 DoMoveWindow( x
, y
, width
, height
);
2007 wxPoint
wxWindowMac::GetClientAreaOrigin() const
2009 RgnHandle rgn
= NewRgn() ;
2011 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
2013 GetRegionBounds( rgn
, &content
) ;
2023 return wxPoint( content
.left
+ MacGetLeftBorderSize() , content
.top
+ MacGetTopBorderSize() );
2026 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
2028 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
2030 int currentclientwidth
, currentclientheight
;
2031 int currentwidth
, currentheight
;
2033 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
2034 GetSize( ¤twidth
, ¤theight
) ;
2036 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
2037 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
2041 void wxWindowMac::SetLabel(const wxString
& title
)
2043 m_label
= wxStripMenuCodes(title
, wxStrip_Mnemonics
) ;
2045 if ( m_peer
&& m_peer
->Ok() )
2046 m_peer
->SetLabel( m_label
) ;
2051 wxString
wxWindowMac::GetLabel() const
2056 bool wxWindowMac::Show(bool show
)
2058 bool former
= MacIsReallyShown() ;
2059 if ( !wxWindowBase::Show(show
) )
2062 // TODO: use visibilityChanged Carbon Event for OSX
2064 m_peer
->SetVisibility( show
, true ) ;
2066 if ( former
!= MacIsReallyShown() )
2067 MacPropagateVisibilityChanged() ;
2072 bool wxWindowMac::Enable(bool enable
)
2074 wxASSERT( m_peer
->Ok() ) ;
2075 bool former
= MacIsReallyEnabled() ;
2076 if ( !wxWindowBase::Enable(enable
) )
2079 m_peer
->Enable( enable
) ;
2081 if ( former
!= MacIsReallyEnabled() )
2082 MacPropagateEnabledStateChanged() ;
2088 // status change propagations (will be not necessary for OSX later )
2091 void wxWindowMac::MacPropagateVisibilityChanged()
2093 #if !TARGET_API_MAC_OSX
2094 MacVisibilityChanged() ;
2097 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2100 child
= node
->GetData();
2101 if ( child
->IsShown() )
2102 child
->MacPropagateVisibilityChanged() ;
2104 node
= node
->GetNext();
2109 void wxWindowMac::MacPropagateEnabledStateChanged()
2111 #if !TARGET_API_MAC_OSX
2112 MacEnabledStateChanged() ;
2115 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2118 child
= node
->GetData();
2119 if ( child
->IsEnabled() )
2120 child
->MacPropagateEnabledStateChanged() ;
2122 node
= node
->GetNext();
2127 void wxWindowMac::MacPropagateHiliteChanged()
2129 #if !TARGET_API_MAC_OSX
2130 MacHiliteChanged() ;
2133 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2136 child
= node
->GetData();
2137 if (child
/* && child->IsEnabled() */)
2138 child
->MacPropagateHiliteChanged() ;
2140 node
= node
->GetNext();
2146 // status change notifications
2149 void wxWindowMac::MacVisibilityChanged()
2153 void wxWindowMac::MacHiliteChanged()
2157 void wxWindowMac::MacEnabledStateChanged()
2162 // status queries on the inherited window's state
2165 bool wxWindowMac::MacIsReallyShown()
2167 // only under OSX the visibility of the TLW is taken into account
2168 if ( m_isBeingDeleted
)
2171 #if TARGET_API_MAC_OSX
2172 if ( m_peer
&& m_peer
->Ok() )
2173 return m_peer
->IsVisible();
2176 wxWindow
* win
= this ;
2177 while ( win
->IsShown() )
2179 if ( win
->IsTopLevel() )
2182 win
= win
->GetParent() ;
2190 bool wxWindowMac::MacIsReallyEnabled()
2192 return m_peer
->IsEnabled() ;
2195 bool wxWindowMac::MacIsReallyHilited()
2197 return m_peer
->IsActive();
2200 void wxWindowMac::MacFlashInvalidAreas()
2202 #if TARGET_API_MAC_OSX
2203 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2207 int wxWindowMac::GetCharHeight() const
2209 wxClientDC
dc( (wxWindowMac
*)this ) ;
2211 return dc
.GetCharHeight() ;
2214 int wxWindowMac::GetCharWidth() const
2216 wxClientDC
dc( (wxWindowMac
*)this ) ;
2218 return dc
.GetCharWidth() ;
2221 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2222 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2224 const wxFont
*fontToUse
= theFont
;
2226 fontToUse
= &m_font
;
2228 wxClientDC
dc( (wxWindowMac
*) this ) ;
2230 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2231 if ( externalLeading
)
2232 *externalLeading
= le
;
2242 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2243 * we always intersect with the entire window, not only with the client area
2246 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2248 if ( m_peer
== NULL
)
2251 if ( !MacIsReallyShown() )
2258 wxMacRectToNative( rect
, &r
) ;
2259 m_peer
->SetNeedsDisplay( &r
) ;
2263 m_peer
->SetNeedsDisplay() ;
2267 void wxWindowMac::Freeze()
2269 #if TARGET_API_MAC_OSX
2270 if ( !m_frozenness
++ )
2272 if ( m_peer
&& m_peer
->Ok() )
2273 m_peer
->SetDrawingEnabled( false ) ;
2278 void wxWindowMac::Thaw()
2280 #if TARGET_API_MAC_OSX
2281 wxASSERT_MSG( m_frozenness
> 0, wxT("Thaw() without matching Freeze()") );
2283 if ( !--m_frozenness
)
2285 if ( m_peer
&& m_peer
->Ok() )
2287 m_peer
->SetDrawingEnabled( true ) ;
2288 m_peer
->InvalidateWithChildren() ;
2294 wxWindowMac
*wxGetActiveWindow()
2296 // actually this is a windows-only concept
2300 // Coordinates relative to the window
2301 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
2303 // We really don't move the mouse programmatically under Mac.
2306 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2308 if ( MacGetTopLevelWindow() == NULL
)
2311 #if TARGET_API_MAC_OSX
2312 if ( !m_macBackgroundBrush
.Ok() || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2319 event
.GetDC()->Clear() ;
2323 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2328 int wxWindowMac::GetScrollPos(int orient
) const
2330 if ( orient
== wxHORIZONTAL
)
2333 return m_hScrollBar
->GetThumbPosition() ;
2338 return m_vScrollBar
->GetThumbPosition() ;
2344 // This now returns the whole range, not just the number
2345 // of positions that we can scroll.
2346 int wxWindowMac::GetScrollRange(int orient
) const
2348 if ( orient
== wxHORIZONTAL
)
2351 return m_hScrollBar
->GetRange() ;
2356 return m_vScrollBar
->GetRange() ;
2362 int wxWindowMac::GetScrollThumb(int orient
) const
2364 if ( orient
== wxHORIZONTAL
)
2367 return m_hScrollBar
->GetThumbSize() ;
2372 return m_vScrollBar
->GetThumbSize() ;
2378 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2380 if ( orient
== wxHORIZONTAL
)
2383 m_hScrollBar
->SetThumbPosition( pos
) ;
2388 m_vScrollBar
->SetThumbPosition( pos
) ;
2393 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2394 // our own window origin is at leftOrigin/rightOrigin
2397 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2403 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2404 bool hasBothScrollbars
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && (m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2406 // back to the surrounding frame rectangle
2407 m_peer
->GetRect( &rect
) ;
2408 InsetRect( &rect
, -1 , -1 ) ;
2410 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2411 if ( UMAGetSystemVersion() >= 0x1030 )
2413 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2414 rect
.bottom
- rect
.top
) ;
2416 HIThemeFrameDrawInfo info
;
2417 memset( &info
, 0 , sizeof(info
) ) ;
2421 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2422 info
.isFocused
= hasFocus
;
2424 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2425 wxASSERT( cgContext
) ;
2427 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2429 info
.kind
= kHIThemeFrameTextFieldSquare
;
2430 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2432 else if ( HasFlag(wxSIMPLE_BORDER
) )
2434 info
.kind
= kHIThemeFrameListBox
;
2435 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2437 else if ( hasFocus
)
2439 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2442 m_peer
->GetRect( &rect
) ;
2443 if ( hasBothScrollbars
)
2445 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2446 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2447 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2448 HIThemeGrowBoxDrawInfo info
;
2449 memset( &info
, 0, sizeof(info
) ) ;
2451 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2452 info
.kind
= kHIThemeGrowBoxKindNone
;
2453 info
.size
= kHIThemeGrowBoxSizeNormal
;
2454 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2455 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2461 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2465 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2466 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2469 if ( HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2470 DrawThemeEditTextFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2471 else if ( HasFlag(wxSIMPLE_BORDER
) )
2472 DrawThemeListBoxFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2475 DrawThemeFocusRect( &rect
, true ) ;
2477 if ( hasBothScrollbars
)
2479 // GetThemeStandaloneGrowBoxBounds
2480 // DrawThemeStandaloneNoGrowBox
2485 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2487 if ( child
== m_hScrollBar
)
2488 m_hScrollBar
= NULL
;
2489 if ( child
== m_vScrollBar
)
2490 m_vScrollBar
= NULL
;
2492 wxWindowBase::RemoveChild( child
) ;
2495 // New function that will replace some of the above.
2496 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2497 int range
, bool refresh
)
2500 bool triggerSizeEvent
= false;
2502 if ( orient
== wxHORIZONTAL
)
2506 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2507 if ( m_hScrollBar
->IsShown() != showScroller
)
2509 m_hScrollBar
->Show( showScroller
);
2510 triggerSizeEvent
= true;
2513 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2520 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2521 if ( m_vScrollBar
->IsShown() != showScroller
)
2523 m_vScrollBar
->Show( showScroller
) ;
2524 triggerSizeEvent
= true;
2527 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2531 MacRepositionScrollBars() ;
2532 if ( triggerSizeEvent
)
2534 wxSizeEvent
event(GetSize(), m_windowId
);
2535 event
.SetEventObject(this);
2536 GetEventHandler()->ProcessEvent(event
);
2540 // Does a physical scroll
2541 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2543 if ( dx
== 0 && dy
== 0 )
2546 int width
, height
;
2547 GetClientSize( &width
, &height
) ;
2549 #if TARGET_API_MAC_OSX
2552 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2553 // area is scrolled, this does not occur if width and height are 2 pixels less,
2554 // TODO: write optimal workaround
2555 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2557 scrollrect
.Intersect( *rect
) ;
2559 if ( m_peer
->GetNeedsDisplay() )
2561 // because HIViewScrollRect does not scroll the already invalidated area we have two options:
2562 // either immediate redraw or full invalidate
2564 // is the better overall solution, as it does not slow down scrolling
2565 m_peer
->SetNeedsDisplay() ;
2567 // this would be the preferred version for fast drawing controls
2569 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2570 if ( UMAGetSystemVersion() >= 0x1030 )
2571 HIViewRender(m_peer
->GetControlRef()) ;
2578 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2579 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2580 m_peer
->ScrollRect( &scrollrect
, dx
, dy
) ;
2582 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2583 // either immediate redraw or full invalidate
2585 // is the better overall solution, as it does not slow down scrolling
2586 m_peer
->SetNeedsDisplay() ;
2588 // this would be the preferred version for fast drawing controls
2590 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2591 if ( UMAGetSystemVersion() >= 0x1030 )
2592 HIViewRender(m_peer
->GetControlRef()) ;
2606 RgnHandle updateRgn
= NewRgn() ;
2609 wxClientDC
dc(this) ;
2610 wxMacPortSetter
helper(&dc
) ;
2612 m_peer
->GetRectInWindowCoords( &scrollrect
) ;
2613 //scrollrect.top += MacGetTopBorderSize() ;
2614 //scrollrect.left += MacGetLeftBorderSize() ;
2615 scrollrect
.bottom
= scrollrect
.top
+ height
;
2616 scrollrect
.right
= scrollrect
.left
+ width
;
2620 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2621 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2622 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2625 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2627 // now scroll the former update region as well and add the new update region
2628 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2629 RgnHandle formerUpdateRgn
= NewRgn() ;
2630 RgnHandle scrollRgn
= NewRgn() ;
2631 RectRgn( scrollRgn
, &scrollrect
) ;
2632 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2634 LocalToGlobal( &pt
) ;
2635 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2636 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2638 if ( !EmptyRgn( formerUpdateRgn
) )
2640 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2641 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2642 InvalWindowRgn( rootWindow
, formerUpdateRgn
) ;
2645 InvalWindowRgn(rootWindow
, updateRgn
) ;
2646 DisposeRgn( updateRgn
) ;
2647 DisposeRgn( formerUpdateRgn
) ;
2648 DisposeRgn( scrollRgn
) ;
2656 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2658 child
= node
->GetData();
2661 if (child
== m_vScrollBar
)
2663 if (child
== m_hScrollBar
)
2665 if (child
->IsTopLevel())
2668 child
->GetPosition( &x
, &y
);
2669 child
->GetSize( &w
, &h
);
2672 wxRect
rc( x
, y
, w
, h
);
2673 if (rect
->Intersects( rc
))
2674 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2678 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2683 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
2685 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2687 wxScrollWinEvent wevent
;
2688 wevent
.SetPosition(event
.GetPosition());
2689 wevent
.SetOrientation(event
.GetOrientation());
2690 wevent
.SetEventObject(this);
2692 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2693 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2694 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2695 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2696 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2697 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2698 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2699 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2700 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2701 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2702 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2703 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2704 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2705 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2706 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2707 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2709 GetEventHandler()->ProcessEvent(wevent
);
2713 // Get the window with the focus
2714 wxWindowMac
*wxWindowBase::DoFindFocus()
2716 ControlRef control
;
2717 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2718 return wxFindControlFromMacControl( control
) ;
2721 void wxWindowMac::OnSetFocus( wxFocusEvent
& event
)
2723 // panel wants to track the window which was the last to have focus in it,
2724 // so we want to set ourselves as the window which last had focus
2726 // notice that it's also important to do it upwards the tree because
2727 // otherwise when the top level panel gets focus, it won't set it back to
2728 // us, but to some other sibling
2730 // CS: don't know if this is still needed:
2731 //wxChildFocusEvent eventFocus(this);
2732 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2734 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2736 #if wxMAC_USE_CORE_GRAPHICS
2737 GetParent()->Refresh() ;
2739 wxMacWindowStateSaver
sv( this ) ;
2742 m_peer
->GetRect( &rect
) ;
2743 // auf den umgebenden Rahmen zur\9fck
2744 InsetRect( &rect
, -1 , -1 ) ;
2746 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2750 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2752 rect
.right
+= pt
.x
;
2754 rect
.bottom
+= pt
.y
;
2757 bool bIsFocusEvent
= (event
.GetEventType() == wxEVT_SET_FOCUS
);
2758 DrawThemeFocusRect( &rect
, bIsFocusEvent
) ;
2759 if ( !bIsFocusEvent
)
2761 // as this erases part of the frame we have to redraw borders
2762 // and because our z-ordering is not always correct (staticboxes)
2763 // we have to invalidate things, we cannot simple redraw
2764 MacInvalidateBorders() ;
2772 void wxWindowMac::OnInternalIdle()
2774 // This calls the UI-update mechanism (querying windows for
2775 // menu/toolbar/control state information)
2776 if (wxUpdateUIEvent::CanUpdate(this))
2777 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2780 // Raise the window to the top of the Z order
2781 void wxWindowMac::Raise()
2783 m_peer
->SetZOrder( true , NULL
) ;
2786 // Lower the window to the bottom of the Z order
2787 void wxWindowMac::Lower()
2789 m_peer
->SetZOrder( false , NULL
) ;
2792 // static wxWindow *gs_lastWhich = NULL;
2794 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2796 // first trigger a set cursor event
2798 wxPoint clientorigin
= GetClientAreaOrigin() ;
2799 wxSize clientsize
= GetClientSize() ;
2801 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2803 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2805 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2806 if ( processedEvtSetCursor
&& event
.HasCursor() )
2808 cursor
= event
.GetCursor() ;
2812 // the test for processedEvtSetCursor is here to prevent using m_cursor
2813 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2814 // it - this is a way to say that our cursor shouldn't be used for this
2816 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2819 if ( !wxIsBusy() && !GetParent() )
2820 cursor
= *wxSTANDARD_CURSOR
;
2824 cursor
.MacInstall() ;
2827 return cursor
.Ok() ;
2830 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2834 return m_tooltip
->GetTip() ;
2837 return wxEmptyString
;
2840 void wxWindowMac::ClearBackground()
2846 void wxWindowMac::Update()
2848 #if TARGET_API_MAC_OSX
2849 MacGetTopLevelWindow()->MacPerformUpdates() ;
2851 ::Draw1Control( m_peer
->GetControlRef() ) ;
2855 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2857 wxTopLevelWindowMac
* win
= NULL
;
2858 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2860 win
= wxFindWinFromMacWindow( window
) ;
2865 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2867 MacUpdateClippedRects() ;
2869 return m_cachedClippedClientRect
;
2872 const wxRect
& wxWindowMac::MacGetClippedRect() const
2874 MacUpdateClippedRects() ;
2876 return m_cachedClippedRect
;
2879 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2881 MacUpdateClippedRects() ;
2883 return m_cachedClippedRectWithOuterStructure
;
2886 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2888 static wxRegion emptyrgn
;
2890 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2892 MacUpdateClippedRects() ;
2893 if ( includeOuterStructures
)
2894 return m_cachedClippedRegionWithOuterStructure
;
2896 return m_cachedClippedRegion
;
2904 void wxWindowMac::MacUpdateClippedRects() const
2906 if ( m_cachedClippedRectValid
)
2909 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2910 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2911 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2912 // to add focus borders everywhere
2914 Rect r
, rIncludingOuterStructures
;
2916 m_peer
->GetRect( &r
) ;
2917 r
.left
-= MacGetLeftBorderSize() ;
2918 r
.top
-= MacGetTopBorderSize() ;
2919 r
.bottom
+= MacGetBottomBorderSize() ;
2920 r
.right
+= MacGetRightBorderSize() ;
2927 rIncludingOuterStructures
= r
;
2928 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2930 wxRect cl
= GetClientRect() ;
2931 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2935 const wxWindow
* child
= this ;
2936 const wxWindow
* parent
= NULL
;
2938 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2940 if ( parent
->MacIsChildOfClientArea(child
) )
2942 size
= parent
->GetClientSize() ;
2943 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2949 // this will be true for scrollbars, toolbars etc.
2950 size
= parent
->GetSize() ;
2951 y
= parent
->MacGetTopBorderSize() ;
2952 x
= parent
->MacGetLeftBorderSize() ;
2953 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2954 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2957 parent
->MacWindowToRootWindow( &x
, &y
) ;
2958 MacRootWindowToWindow( &x
, &y
) ;
2960 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2962 // the wxwindow and client rects will always be clipped
2963 SectRect( &r
, &rparent
, &r
) ;
2964 SectRect( &rClient
, &rparent
, &rClient
) ;
2966 // the structure only at 'hard' borders
2967 if ( parent
->MacClipChildren() ||
2968 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2970 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2976 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2977 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2978 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2979 m_cachedClippedRectWithOuterStructure
= wxRect(
2980 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2981 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2982 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2984 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2985 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2986 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2988 m_cachedClippedRectValid
= true ;
2992 This function must not change the updatergn !
2994 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2996 bool handled
= false ;
2998 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2999 GetRegionBounds( updatergn
, &updatebounds
) ;
3001 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
3003 if ( !EmptyRgn(updatergn
) )
3005 RgnHandle newupdate
= NewRgn() ;
3006 wxSize point
= GetClientSize() ;
3007 wxPoint origin
= GetClientAreaOrigin() ;
3008 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
3009 SectRgn( newupdate
, updatergn
, newupdate
) ;
3011 // first send an erase event to the entire update area
3013 // for the toplevel window this really is the entire area
3014 // for all the others only their client area, otherwise they
3015 // might be drawing with full alpha and eg put blue into
3016 // the grow-box area of a scrolled window (scroll sample)
3017 wxDC
* dc
= new wxWindowDC(this);
3019 dc
->SetClippingRegion(wxRegion(updatergn
));
3021 dc
->SetClippingRegion(wxRegion(newupdate
));
3023 wxEraseEvent
eevent( GetId(), dc
);
3024 eevent
.SetEventObject( this );
3025 GetEventHandler()->ProcessEvent( eevent
);
3029 // calculate a client-origin version of the update rgn and set m_updateRegion to that
3030 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
3031 m_updateRegion
= newupdate
;
3032 DisposeRgn( newupdate
) ;
3034 if ( !m_updateRegion
.Empty() )
3036 // paint the window itself
3039 event
.SetTimestamp(time
);
3040 event
.SetEventObject(this);
3041 GetEventHandler()->ProcessEvent(event
);
3045 // now we cannot rely on having its borders drawn by a window itself, as it does not
3046 // get the updateRgn wide enough to always do so, so we do it from the parent
3047 // this would also be the place to draw any custom backgrounds for native controls
3048 // in Composited windowing
3049 wxPoint clientOrigin
= GetClientAreaOrigin() ;
3053 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
3055 child
= node
->GetData();
3058 if (child
== m_vScrollBar
)
3060 if (child
== m_hScrollBar
)
3062 if (child
->IsTopLevel())
3064 if (!child
->IsShown())
3067 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
3069 child
->GetPosition( &x
, &y
);
3070 child
->GetSize( &w
, &h
);
3071 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
3072 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
3073 InsetRect( &childRect
, -10 , -10) ;
3075 if ( RectInRgn( &childRect
, updatergn
) )
3077 // paint custom borders
3078 wxNcPaintEvent
eventNc( child
->GetId() );
3079 eventNc
.SetEventObject( child
);
3080 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
3082 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
3083 if ( UMAGetSystemVersion() >= 0x1030 )
3085 child
->MacPaintBorders(0, 0) ;
3090 wxWindowDC
dc(this) ;
3091 dc
.SetClippingRegion(wxRegion(updatergn
));
3092 wxMacPortSetter
helper(&dc
) ;
3093 child
->MacPaintBorders(0, 0) ;
3104 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
3106 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3110 if ( iter
->IsTopLevel() )
3111 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
3113 iter
= iter
->GetParent() ;
3119 void wxWindowMac::MacCreateScrollBars( long style
)
3121 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
3123 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
3125 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
3126 int scrlsize
= MAC_SCROLLBAR_SIZE
;
3127 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
3129 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
3132 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
3134 GetClientSize( &width
, &height
) ;
3136 wxPoint
vPoint(width
- scrlsize
, 0) ;
3137 wxSize
vSize(scrlsize
, height
- adjust
) ;
3138 wxPoint
hPoint(0, height
- scrlsize
) ;
3139 wxSize
hSize(width
- adjust
, scrlsize
) ;
3141 if ( style
& wxVSCROLL
)
3142 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
3144 if ( style
& wxHSCROLL
)
3145 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
3148 // because the create does not take into account the client area origin
3149 // we might have a real position shift
3150 MacRepositionScrollBars() ;
3153 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
3155 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
3160 void wxWindowMac::MacRepositionScrollBars()
3162 if ( !m_hScrollBar
&& !m_vScrollBar
)
3165 bool hasBoth
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3166 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3167 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3169 // get real client area
3171 GetSize( &width
, &height
);
3173 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3174 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3176 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
3177 wxSize
vSize( scrlsize
, height
- adjust
) ;
3178 wxPoint
hPoint( 0 , height
- scrlsize
) ;
3179 wxSize
hSize( width
- adjust
, scrlsize
) ;
3182 int x
= 0, y
= 0, w
, h
;
3183 GetSize( &w
, &h
) ;
3185 MacClientToRootWindow( &x
, &y
) ;
3186 MacClientToRootWindow( &w
, &h
) ;
3188 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3190 int totW
= 10000 , totH
= 10000;
3193 if ( iter
->IsTopLevel() )
3195 iter
->GetSize( &totW
, &totH
) ;
3199 iter
= iter
->GetParent() ;
3213 if ( w
- x
>= totW
)
3218 if ( h
- y
>= totH
)
3226 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3228 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3231 bool wxWindowMac::AcceptsFocus() const
3233 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3236 void wxWindowMac::MacSuperChangedPosition()
3238 // only window-absolute structures have to be moved i.e. controls
3240 m_cachedClippedRectValid
= false ;
3243 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3246 child
= node
->GetData();
3247 child
->MacSuperChangedPosition() ;
3249 node
= node
->GetNext();
3253 void wxWindowMac::MacTopLevelWindowChangedPosition()
3255 // only screen-absolute structures have to be moved i.e. glcanvas
3258 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3261 child
= node
->GetData();
3262 child
->MacTopLevelWindowChangedPosition() ;
3264 node
= node
->GetNext();
3268 long wxWindowMac::MacGetLeftBorderSize() const
3275 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
3277 // this metric is only the 'outset' outside the simple frame rect
3278 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3281 else if (HasFlag(wxSIMPLE_BORDER
))
3283 // this metric is only the 'outset' outside the simple frame rect
3284 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3291 long wxWindowMac::MacGetRightBorderSize() const
3293 // they are all symmetric in mac themes
3294 return MacGetLeftBorderSize() ;
3297 long wxWindowMac::MacGetTopBorderSize() const
3299 // they are all symmetric in mac themes
3300 return MacGetLeftBorderSize() ;
3303 long wxWindowMac::MacGetBottomBorderSize() const
3305 // they are all symmetric in mac themes
3306 return MacGetLeftBorderSize() ;
3309 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3311 return style
& ~wxBORDER_MASK
;
3314 // Find the wxWindowMac at the current mouse position, returning the mouse
3316 wxWindowMac
* wxFindWindowAtPointer( wxPoint
& pt
)
3318 pt
= wxGetMousePosition();
3319 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3324 // Get the current mouse position.
3325 wxPoint
wxGetMousePosition()
3329 wxGetMousePosition( &x
, &y
);
3331 return wxPoint(x
, y
);
3334 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3336 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3338 // copied from wxGTK : CS
3339 // VZ: shouldn't we move this to base class then?
3341 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3344 // (a) it's a command event and so is propagated to the parent
3345 // (b) under MSW it can be generated from kbd too
3346 // (c) it uses screen coords (because of (a))
3347 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3349 this->ClientToScreen(event
.GetPosition()));
3350 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3359 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3361 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3362 CallNextEventHandler(
3363 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
3364 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3367 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3371 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3375 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3376 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
3381 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3383 return eventNotHandledErr
;
3386 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
3388 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
3389 if ( !wxWindowBase::Reparent(newParent
) )
3392 // copied from MacPostControlCreate
3393 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
3395 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
3397 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
3402 bool wxWindowMac::SetTransparent(wxByte alpha
)
3404 #if wxMAC_USE_CORE_GRAPHICS
3405 if ( alpha
!= m_macAlpha
)
3407 m_macAlpha
= alpha
;
3417 bool wxWindowMac::CanSetTransparent()
3419 #if wxMAC_USE_CORE_GRAPHICS
3426 wxByte
wxWindowMac::GetTransparent() const