1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
19 #include "wx/dcclient.h"
23 #include "wx/layout.h"
24 #include "wx/dialog.h"
25 #include "wx/listbox.h"
26 #include "wx/scrolbar.h"
27 #include "wx/statbox.h"
28 #include "wx/button.h"
29 #include "wx/settings.h"
30 #include "wx/msgdlg.h"
32 #include "wx/notebook.h"
33 #include "wx/tabctrl.h"
34 #include "wx/tooltip.h"
35 #include "wx/statusbr.h"
36 // TODO remove the line below, just for lookup-up convenience CS
37 #include "wx/window.h"
39 #include "wx/menuitem.h"
46 #define wxWINDOW_HSCROLL 5998
47 #define wxWINDOW_VSCROLL 5997
48 #define MAC_SCROLLBAR_SIZE 16
50 #include <wx/mac/uma.h>
52 #if wxUSE_DRAG_AND_DROP
58 extern wxList wxPendingDelete
;
59 wxWindow
* gFocusWindow
= NULL
;
61 #if !USE_SHARED_LIBRARY
62 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxEvtHandler
)
63 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
64 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground
)
65 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
66 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
67 EVT_IDLE(wxWindow::OnIdle
)
68 // EVT_SCROLL(wxWindow::OnScroll)
75 // ===========================================================================
77 // ===========================================================================
79 // ---------------------------------------------------------------------------
80 // wxWindow utility functions
81 // ---------------------------------------------------------------------------
83 // Find an item given the Macintosh Window Reference
85 wxList
*wxWinMacWindowList
= NULL
;
86 wxWindow
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
88 wxNode
*node
= wxWinMacWindowList
->Find((long)inWindowRef
);
91 return (wxWindow
*)node
->Data();
94 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxWindow
*win
)
96 // adding NULL WindowRef is (first) surely a result of an error and
97 // (secondly) breaks menu command processing
98 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, "attempt to add a NULL WindowRef to window list" );
100 if ( !wxWinMacWindowList
->Find((long)inWindowRef
) )
101 wxWinMacWindowList
->Append((long)inWindowRef
, win
);
104 void wxRemoveMacWindowAssociation(wxWindow
*win
)
106 wxWinMacWindowList
->DeleteObject(win
);
109 // ----------------------------------------------------------------------------
110 // constructors and such
111 // ----------------------------------------------------------------------------
113 void wxWindow::Init()
119 m_doubleClickAllowed
= 0;
120 m_winCaptured
= FALSE
;
122 m_isBeingDeleted
= FALSE
;
125 m_mouseInWindow
= FALSE
;
129 m_backgroundTransparent
= FALSE
;
131 // as all windows are created with WS_VISIBLE style...
134 m_macWindowData
= NULL
;
141 m_hScrollBar
= NULL
;
142 m_vScrollBar
= NULL
;
144 #if wxUSE_DRAG_AND_DROP
145 m_pDropTarget
= NULL
;
150 wxWindow::~wxWindow()
152 m_isBeingDeleted
= TRUE
;
154 if ( s_lastMouseWindow
== this )
156 s_lastMouseWindow
= NULL
;
159 if ( gFocusWindow
== this )
161 gFocusWindow
= NULL
;
165 m_parent
->RemoveChild(this);
169 if ( m_macWindowData
)
171 wxToolTip::NotifyWindowDelete(m_macWindowData
->m_macWindow
) ;
172 UMADisposeWindow( m_macWindowData
->m_macWindow
) ;
173 delete m_macWindowData
;
174 wxRemoveMacWindowAssociation( this ) ;
179 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
183 const wxString
& name
)
185 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindow without parent") );
187 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
190 parent
->AddChild(this);
194 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
195 m_width
= WidthDefault( size
.x
);
196 m_height
= HeightDefault( size
.y
) ;
198 if ( ! IsKindOf( CLASSINFO ( wxControl
) ) && ! IsKindOf( CLASSINFO( wxStatusBar
) ) )
200 MacCreateScrollBars( style
) ;
206 void wxWindow::SetFocus()
208 if ( AcceptsFocus() )
214 if ( gFocusWindow
->m_caret
)
216 gFocusWindow
->m_caret
->OnKillFocus();
218 #endif // wxUSE_CARET
219 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
220 if ( control
&& control
->GetMacControl() )
222 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlFocusNoPart
) ;
223 control
->MacRedrawControl() ;
225 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
226 event
.SetEventObject(gFocusWindow
);
227 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
229 gFocusWindow
= this ;
235 m_caret
->OnSetFocus();
237 #endif // wxUSE_CARET
238 // panel wants to track the window which was the last to have focus in it
239 wxPanel
*panel
= wxDynamicCast(GetParent(), wxPanel
);
242 panel
->SetLastFocus(this);
244 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
245 if ( control
&& control
->GetMacControl() )
247 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlEditTextPart
) ;
250 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
251 event
.SetEventObject(this);
252 GetEventHandler()->ProcessEvent(event
) ;
257 bool wxWindow::Enable(bool enable
)
259 if ( !wxWindowBase::Enable(enable
) )
262 wxWindowList::Node
*node
= GetChildren().GetFirst();
265 wxWindow
*child
= node
->GetData();
266 child
->Enable(enable
);
268 node
= node
->GetNext();
274 void wxWindow::CaptureMouse()
276 wxTheApp
->s_captureWindow
= this ;
279 void wxWindow::ReleaseMouse()
281 wxTheApp
->s_captureWindow
= NULL
;
284 #if wxUSE_DRAG_AND_DROP
286 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
288 if ( m_pDropTarget
!= 0 ) {
289 delete m_pDropTarget
;
292 m_pDropTarget
= pDropTarget
;
293 if ( m_pDropTarget
!= 0 )
301 // Old style file-manager drag&drop
302 void wxWindow::DragAcceptFiles(bool accept
)
308 void wxWindow::DoGetSize(int *x
, int *y
) const
314 void wxWindow::DoGetPosition(int *x
, int *y
) const
320 wxPoint
pt(GetParent()->GetClientAreaOrigin());
327 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
329 menu
->SetInvokingWindow(this);
331 ClientToScreen( &x
, &y
) ;
333 ::InsertMenu( menu
->GetHMenu() , -1 ) ;
334 long menuResult
= ::PopUpMenuSelect(menu
->GetHMenu() ,y
,x
, 0) ;
335 menu
->MacMenuSelect( this , TickCount() , HiWord(menuResult
) , LoWord(menuResult
) ) ;
336 ::DeleteMenu( menu
->MacGetMenuId() ) ;
337 menu
->SetInvokingWindow(NULL
);
342 void wxWindow::DoScreenToClient(int *x
, int *y
) const
344 WindowRef window
= GetMacRootWindow() ;
352 ::SetPort( UMAGetWindowPort( window
) ) ;
353 ::GlobalToLocal( &localwhere
) ;
359 MacRootWindowToClient( x
, y
) ;
362 void wxWindow::DoClientToScreen(int *x
, int *y
) const
364 WindowRef window
= GetMacRootWindow() ;
366 MacClientToRootWindow( x
, y
) ;
374 ::SetPort( UMAGetWindowPort( window
) ) ;
375 ::SetOrigin( 0 , 0 ) ;
376 ::LocalToGlobal( &localwhere
) ;
382 void wxWindow::MacClientToRootWindow( int *x
, int *y
) const
384 if ( m_macWindowData
)
391 GetParent()->MacClientToRootWindow( x
, y
) ;
395 void wxWindow::MacRootWindowToClient( int *x
, int *y
) const
397 if ( m_macWindowData
)
404 GetParent()->MacRootWindowToClient( x
, y
) ;
408 bool wxWindow::SetCursor(const wxCursor
& cursor
)
410 if ( !wxWindowBase::SetCursor(cursor
) )
416 wxASSERT_MSG( m_cursor
.Ok(),
417 wxT("cursor must be valid after call to the base version"));
423 // Change the cursor NOW if we're within the correct window
425 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
427 if ( mouseWin
== this && !wxIsBusy() )
429 cursor
.MacInstall() ;
437 // Get size *available for subwindows* i.e. excluding menu bar etc.
438 void wxWindow::DoGetClientSize(int *x
, int *y
) const
443 *x
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
444 *y
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
446 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
453 MacClientToRootWindow( &x1
, &y1
) ;
454 MacClientToRootWindow( &w
, &h
) ;
456 WindowRef window
= NULL
;
457 wxWindow
*iter
= (wxWindow
*)this ;
459 int totW
= 10000 , totH
= 10000;
462 if ( iter
->m_macWindowData
)
464 totW
= iter
->m_width
;
465 totH
= iter
->m_height
;
469 iter
= iter
->GetParent() ;
472 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
474 (*y
) -= MAC_SCROLLBAR_SIZE
;
480 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
482 (*x
) -= MAC_SCROLLBAR_SIZE
;
492 // ----------------------------------------------------------------------------
494 // ----------------------------------------------------------------------------
498 void wxWindow::DoSetToolTip(wxToolTip
*tooltip
)
500 wxWindowBase::DoSetToolTip(tooltip
);
503 m_tooltip
->SetWindow(this);
506 #endif // wxUSE_TOOLTIPS
508 void wxWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
510 DoSetSize( x
,y
, width
, height
) ;
513 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
518 int former_w
= m_width
;
519 int former_h
= m_height
;
521 int currentX
, currentY
;
522 GetPosition(¤tX
, ¤tY
);
523 int currentW
,currentH
;
524 GetSize(¤tW
, ¤tH
);
526 int actualWidth
= width
;
527 int actualHeight
= height
;
530 if (x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
532 if (y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
535 actualWidth
= currentW
;
537 actualHeight
= currentH
;
539 if ( actualX
== currentX
&& actualY
== currentY
&& actualWidth
== currentW
&& actualHeight
== currentH
)
541 MacRepositionScrollBars() ; // we might have a real position shift
545 AdjustForParentClientOrigin(actualX
, actualY
, sizeFlags
);
548 bool doMove
= false ;
549 bool doResize
= false ;
551 if ( actualX
!= former_x
|| actualY
!= former_y
)
555 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
560 if ( doMove
|| doResize
)
562 if ( m_macWindowData
)
567 // erase former position
568 wxMacDrawingHelper
focus( this ) ;
571 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
572 ClipRect( &clientrect
) ;
573 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
578 m_width
= actualWidth
;
579 m_height
= actualHeight
;
580 if ( m_macWindowData
)
583 ::MoveWindow(m_macWindowData
->m_macWindow
, m_x
, m_y
, false); // don't make frontmost
586 ::SizeWindow(m_macWindowData
->m_macWindow
, m_width
, m_height
, true);
588 // the OS takes care of invalidating and erasing the new area
589 // we have erased the old one
591 if ( IsKindOf( CLASSINFO( wxFrame
) ) )
593 wxFrame
* frame
= (wxFrame
*) this ;
594 frame
->PositionStatusBar();
595 frame
->PositionToolBar();
600 // erase new position
603 wxMacDrawingHelper
focus( this ) ;
606 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
607 ClipRect( &clientrect
) ;
608 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
613 wxWindow::MacSuperChangedPosition() ; // like this only children will be notified
615 MacRepositionScrollBars() ;
618 wxMoveEvent
event(wxPoint(m_x
, m_y
), m_windowId
);
619 event
.SetEventObject(this);
620 GetEventHandler()->ProcessEvent(event
) ;
624 MacRepositionScrollBars() ;
625 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
626 event
.SetEventObject(this);
627 GetEventHandler()->ProcessEvent(event
);
631 // For implementation purposes - sometimes decorations make the client area
634 wxPoint
wxWindow::GetClientAreaOrigin() const
636 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
639 // Makes an adjustment to the window position (for example, a frame that has
640 // a toolbar that it manages itself).
641 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
643 if( !m_macWindowData
)
645 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
647 wxPoint
pt(GetParent()->GetClientAreaOrigin());
648 x
+= pt
.x
; y
+= pt
.y
;
653 void wxWindow::SetTitle(const wxString
& title
)
659 if( wxApp::s_macDefaultEncodingIsPC
)
660 label
= wxMacMakeMacStringFromPC( title
) ;
664 if ( m_macWindowData
)
665 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
668 wxString
wxWindow::GetTitle() const
673 bool wxWindow::Show(bool show
)
675 if ( !wxWindowBase::Show(show
) )
678 if ( m_macWindowData
)
682 UMAShowWindow( m_macWindowData
->m_macWindow
) ;
683 UMASelectWindow( m_macWindowData
->m_macWindow
) ;
684 // no need to generate events here, they will get them triggered by macos
685 // actually they should be , but apparently they are not
686 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
687 event
.SetEventObject(this);
688 GetEventHandler()->ProcessEvent(event
);
692 UMAHideWindow( m_macWindowData
->m_macWindow
) ;
695 MacSuperShown( show
) ;
698 MacUpdateImmediately() ;
703 void wxWindow::MacSuperShown( bool show
)
705 wxNode
*node
= GetChildren().First();
708 wxWindow
*child
= (wxWindow
*)node
->Data();
709 if ( child
->m_isShown
)
710 child
->MacSuperShown( show
) ;
715 bool wxWindow::MacIsReallyShown() const
717 bool status
= m_isShown
;
718 wxWindow
* win
= this ;
719 while ( status
&& win
->m_parent
!= NULL
)
721 win
= win
->m_parent
;
722 status
= win
->m_isShown
;
727 int wxWindow::GetCharHeight() const
729 wxClientDC
dc ( (wxWindow
*)this ) ;
730 return dc
.GetCharHeight() ;
733 int wxWindow::GetCharWidth() const
735 wxClientDC
dc ( (wxWindow
*)this ) ;
736 return dc
.GetCharWidth() ;
739 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
740 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
742 const wxFont
*fontToUse
= theFont
;
746 wxClientDC
dc( (wxWindow
*) this ) ;
748 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, fontToUse
) ;
749 if ( externalLeading
)
750 *externalLeading
= le
;
759 void wxWindow::MacEraseBackground( Rect
*rect
)
761 WindowRef window
= GetMacRootWindow() ;
762 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
764 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
766 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
768 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
769 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
770 // either a non gray background color or a non control window
772 wxWindow
* parent
= GetParent() ;
775 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
777 // if we have any other colours in the hierarchy
778 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
781 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
783 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
784 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
786 UMAApplyThemeBackground(kThemeBackgroundTabPane
, rect
, kThemeStateActive
,8,true);
792 // we have arrived at a non control item
796 parent
= parent
->GetParent() ;
800 // if there is nothing special -> use default
801 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
806 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
811 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
813 wxWindow
*child
= (wxWindow
*)node
->Data();
815 Rect clientrect
= { child
->m_x
, child
->m_y
, child
->m_x
+child
->m_width
, child
->m_y
+ child
->m_height
} ;
816 SectRect( &clientrect
, rect
, &clientrect
) ;
818 OffsetRect( &clientrect
, -child
->m_x
, -child
->m_y
) ;
819 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() )
821 wxMacDrawingClientHelper
focus( this ) ;
824 child
->MacEraseBackground( &clientrect
) ;
830 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
832 wxMacDrawingHelper
focus( this ) ;
835 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
836 ClipRect( &clientrect
) ;
840 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
841 SectRect( &clientrect
, &r
, &clientrect
) ;
843 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
847 // Responds to colour changes: passes event on to children.
848 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
850 wxNode
*node
= GetChildren().First();
853 // Only propagate to non-top-level windows
854 wxWindow
*win
= (wxWindow
*)node
->Data();
855 if ( win
->GetParent() )
857 wxSysColourChangedEvent event2
;
858 event
.m_eventObject
= win
;
859 win
->GetEventHandler()->ProcessEvent(event2
);
866 #if wxUSE_CARET && WXWIN_COMPATIBILITY
867 // ---------------------------------------------------------------------------
868 // Caret manipulation
869 // ---------------------------------------------------------------------------
871 void wxWindow::CreateCaret(int w
, int h
)
873 SetCaret(new wxCaret(this, w
, h
));
876 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
878 wxFAIL_MSG("not implemented");
881 void wxWindow::ShowCaret(bool show
)
883 wxCHECK_RET( m_caret
, "no caret to show" );
888 void wxWindow::DestroyCaret()
893 void wxWindow::SetCaretPos(int x
, int y
)
895 wxCHECK_RET( m_caret
, "no caret to move" );
900 void wxWindow::GetCaretPos(int *x
, int *y
) const
902 wxCHECK_RET( m_caret
, "no caret to get position of" );
904 m_caret
->GetPosition(x
, y
);
906 #endif // wxUSE_CARET
908 wxWindow
*wxGetActiveWindow()
910 // actually this is a windows-only concept
914 // Coordinates relative to the window
915 void wxWindow::WarpPointer (int x_pos
, int y_pos
)
917 // We really dont move the mouse programmatically under mac
920 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
922 // TODO : probably we would adopt the EraseEvent structure
925 int wxWindow::GetScrollPos(int orient
) const
927 if ( orient
== wxHORIZONTAL
)
930 return m_hScrollBar
->GetThumbPosition() ;
935 return m_vScrollBar
->GetThumbPosition() ;
940 // This now returns the whole range, not just the number
941 // of positions that we can scroll.
942 int wxWindow::GetScrollRange(int orient
) const
944 if ( orient
== wxHORIZONTAL
)
947 return m_hScrollBar
->GetRange() ;
952 return m_vScrollBar
->GetRange() ;
957 int wxWindow::GetScrollThumb(int orient
) const
959 if ( orient
== wxHORIZONTAL
)
962 return m_hScrollBar
->GetThumbSize() ;
967 return m_vScrollBar
->GetThumbSize() ;
972 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
974 if ( orient
== wxHORIZONTAL
)
977 m_hScrollBar
->SetThumbPosition( pos
) ;
982 m_vScrollBar
->SetThumbPosition( pos
) ;
986 void wxWindow::MacCreateRealWindow( const wxString
& title
,
990 const wxString
& name
)
993 m_windowStyle
= style
;
1014 m_macWindowData
= new MacWindowData() ;
1016 ::SetRect(&theBoundsRect
, m_x
, m_y
, m_x
+ m_width
, m_y
+ m_height
);
1018 // translate the window attributes in the appropriate window class and attributes
1020 WindowClass wclass
= 0;
1021 WindowAttributes attr
= kWindowNoAttributes
;
1023 if ( HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
) )
1025 wclass
= kFloatingWindowClass
;
1026 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1028 attr
|= kWindowSideTitlebarAttribute
;
1031 else if ( HasFlag( wxCAPTION
) )
1033 if ( HasFlag( wxDIALOG_MODAL
) )
1035 wclass
= kMovableModalWindowClass
;
1037 else if ( HasFlag( wxDIALOG_MODELESS
) )
1039 wclass
= kDocumentWindowClass
;
1044 if ( HasFlag( wxCAPTION ) )
1046 wclass = kDocumentWindowClass ;
1050 wclass = kModalWindowClass ;
1057 wclass
= kModalWindowClass
;
1060 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) )
1062 attr
|= kWindowFullZoomAttribute
;
1063 attr
|= kWindowCollapseBoxAttribute
;
1065 if ( HasFlag( wxRESIZE_BORDER
) )
1067 attr
|= kWindowResizableAttribute
;
1069 if ( HasFlag( wxSYSTEM_MENU
) )
1071 attr
|= kWindowCloseBoxAttribute
;
1074 UMACreateNewWindow( wclass
, attr
, &theBoundsRect
, &m_macWindowData
->m_macWindow
) ;
1075 wxAssociateWinWithMacWindow( m_macWindowData
->m_macWindow
, this ) ;
1077 if( wxApp::s_macDefaultEncodingIsPC
)
1078 label
= wxMacMakeMacStringFromPC( title
) ;
1081 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
1082 UMACreateRootControl( m_macWindowData
->m_macWindow
, &m_macWindowData
->m_macRootControl
) ;
1084 m_macWindowData
->m_macFocus
= NULL
;
1087 void wxWindow::MacPaint( wxPaintEvent
&event
)
1091 void wxWindow::MacPaintBorders( )
1093 if( m_macWindowData
)
1096 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1097 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1098 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1099 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1102 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1104 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1105 RGBColor pen1
= sunken
? white
: black
;
1106 RGBColor pen2
= sunken
? shadow
: face
;
1107 RGBColor pen3
= sunken
? face
: shadow
;
1108 RGBColor pen4
= sunken
? black
: white
;
1110 RGBForeColor( &pen1
) ;
1112 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1113 FrameRect( &rect
) ;
1115 RGBForeColor( &pen2
) ;
1117 Rect rect
= { 1 , 1 , m_height
-1 , m_width
-1} ;
1118 FrameRect( &rect
) ;
1120 RGBForeColor( &pen3
) ;
1122 Rect rect
= { 0 , 0 , m_height
-2 , m_width
-2} ;
1123 FrameRect( &rect
) ;
1125 RGBForeColor( &pen4
) ;
1128 LineTo( m_width
- 3 , 0 ) ;
1130 LineTo( 0 , m_height
- 3 ) ;
1133 else if (HasFlag(wxSIMPLE_BORDER
))
1135 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1136 RGBForeColor( &black
) ;
1137 FrameRect( &rect
) ;
1140 if ( this->GetParent() )
1142 wxPaintDC dc(GetParent());
1143 GetParent()->PrepareDC(dc);
1145 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) )
1147 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1149 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1150 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1152 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1153 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1154 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1155 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1158 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1161 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1164 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1167 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1168 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1170 else if (HasFlag(wxDOUBLE_BORDER))
1172 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1174 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1175 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1177 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1178 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1179 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1180 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1183 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1186 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1189 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1192 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1193 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1195 else if (HasFlag(wxSIMPLE_BORDER))
1197 dc.SetPen(*wxBLACK_PEN);
1198 dc.DrawRectangle(m_x, m_y, m_width, m_height);
1204 // New function that will replace some of the above.
1205 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1206 int range
, bool refresh
)
1208 if ( orient
== wxHORIZONTAL
)
1212 if ( range
== 0 || thumbVisible
>= range
)
1214 if ( m_hScrollBar
->IsShown() )
1215 m_hScrollBar
->Show(false) ;
1219 if ( !m_hScrollBar
->IsShown() )
1220 m_hScrollBar
->Show(true) ;
1221 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, refresh
) ;
1229 if ( range
== 0 || thumbVisible
>= range
)
1231 if ( m_vScrollBar
->IsShown() )
1232 m_vScrollBar
->Show(false) ;
1236 if ( !m_vScrollBar
->IsShown() )
1237 m_vScrollBar
->Show(true) ;
1238 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, refresh
) ;
1242 MacRepositionScrollBars() ;
1245 // Does a physical scroll
1246 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1248 wxMacDrawingClientHelper
focus( this ) ;
1251 int width
, height
;
1252 GetClientSize( &width
, &height
) ;
1254 Rect scrollrect
= { 0 , 0 , height
, width
} ;
1256 RgnHandle updateRgn
= NewRgn() ;
1257 ClipRect( &scrollrect
) ;
1260 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
1261 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1263 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1264 InvalWindowRgn( GetMacRootWindow() , updateRgn
) ;
1265 DisposeRgn( updateRgn
) ;
1268 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1270 wxWindow
*child
= (wxWindow
*)node
->Data();
1271 if (child
== m_vScrollBar
) continue;
1272 if (child
== m_hScrollBar
) continue;
1273 if (child
->IsTopLevel()) continue;
1275 child
->GetPosition( &x
, &y
);
1277 child
->GetSize( &w
, &h
);
1278 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1283 void wxWindow::MacOnScroll(wxScrollEvent
&event
)
1285 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1287 wxScrollWinEvent wevent
;
1288 wevent
.SetPosition(event
.GetPosition());
1289 wevent
.SetOrientation(event
.GetOrientation());
1290 wevent
.m_eventObject
= this;
1292 if (event
.m_eventType
== wxEVT_SCROLL_TOP
) {
1293 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1295 if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
) {
1296 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1298 if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
) {
1299 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1301 if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
) {
1302 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1304 if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
) {
1305 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1307 if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
) {
1308 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1310 if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
) {
1311 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1314 GetEventHandler()->ProcessEvent(wevent
);
1318 bool wxWindow::SetFont(const wxFont
& font
)
1320 if ( !wxWindowBase::SetFont(font
) )
1329 // Get the window with the focus
1330 wxWindow
*wxWindowBase::FindFocus()
1332 return gFocusWindow
;
1335 #if WXWIN_COMPATIBILITY
1336 // If nothing defined for this, try the parent.
1337 // E.g. we may be a button loaded from a resource, with no callback function
1339 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1341 if ( GetEventHandler()->ProcessEvent(event
) )
1344 m_parent
->GetEventHandler()->OnCommand(win
, event
);
1346 #endif // WXWIN_COMPATIBILITY_2
1348 #if WXWIN_COMPATIBILITY
1349 wxObject
* wxWindow::GetChild(int number
) const
1351 // Return a pointer to the Nth object in the Panel
1352 wxNode
*node
= GetChildren().First();
1355 node
= node
->Next();
1358 wxObject
*obj
= (wxObject
*)node
->Data();
1364 #endif // WXWIN_COMPATIBILITY
1366 void wxWindow::Clear()
1368 if ( m_macWindowData
)
1370 wxMacDrawingClientHelper
helper ( this ) ;
1372 wxPoint origin
= GetClientAreaOrigin() ;
1373 GetClientSize( &w
, &h
) ;
1374 UMASetThemeWindowBackground( m_macWindowData
->m_macWindow
, m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
1375 Rect r
= { origin
.y
, origin
.x
, origin
.y
+h
, origin
.x
+w
} ;
1380 wxClientDC
dc(this);
1381 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1382 dc
.SetBackground(brush
);
1387 // Setup background and foreground colours correctly
1388 void wxWindow::SetupColours()
1391 SetBackgroundColour(GetParent()->GetBackgroundColour());
1394 void wxWindow::OnIdle(wxIdleEvent
& event
)
1397 // Check if we need to send a LEAVE event
1398 if (m_mouseInWindow)
1401 ::GetCursorPos(&pt);
1402 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1404 // Generate a LEAVE event
1405 m_mouseInWindow = FALSE;
1406 MSWOnMouseLeave(pt.x, pt.y, 0);
1411 // This calls the UI-update mechanism (querying windows for
1412 // menu/toolbar/control state information)
1416 // Raise the window to the top of the Z order
1417 void wxWindow::Raise()
1422 // Lower the window to the bottom of the Z order
1423 void wxWindow::Lower()
1428 void wxWindow::DoSetClientSize(int width
, int height
)
1430 if ( width
!= -1 || height
!= -1 )
1433 if ( width
!= -1 && m_vScrollBar
)
1434 width
+= MAC_SCROLLBAR_SIZE
;
1435 if ( height
!= -1 && m_vScrollBar
)
1436 height
+= MAC_SCROLLBAR_SIZE
;
1438 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1439 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1441 DoSetSize( -1 , -1 , width
, height
) ;
1446 wxWindow
* wxWindow::s_lastMouseWindow
= NULL
;
1448 bool wxWindow::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindow
** outWin
)
1450 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1451 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1454 WindowRef window
= GetMacRootWindow() ;
1456 wxPoint
newPoint( point
) ;
1461 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1463 wxWindow
*child
= (wxWindow
*)node
->Data();
1464 // added the m_isShown test --dmazzoni
1465 if ( child
->GetMacRootWindow() == window
&& child
->m_isShown
)
1467 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1476 bool wxWindow::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindow
** outWin
)
1479 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1480 if ( ::FindWindow( pt
, &window
) == 3 )
1482 wxPoint
point( screenpoint
) ;
1483 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1486 win
->ScreenToClient( point
) ;
1487 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1493 extern int wxBusyCursorCount
;
1495 bool wxWindow::MacDispatchMouseEvent(wxMouseEvent
& event
)
1497 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1498 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1502 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) )
1505 WindowRef window
= GetMacRootWindow() ;
1513 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1515 wxWindow
*child
= (wxWindow
*)node
->Data();
1516 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1518 if (child
->MacDispatchMouseEvent(event
))
1526 if ( wxBusyCursorCount
== 0 )
1528 m_cursor
.MacInstall() ;
1532 if ( event
.GetEventType() == wxEVT_MOTION
1533 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1534 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1535 wxToolTip::RelayEvent( this , event
);
1536 #endif // wxUSE_TOOLTIPS
1537 GetEventHandler()->ProcessEvent( event
) ;
1544 wxString
wxWindow::MacGetToolTipString( wxPoint
&pt
)
1548 return m_tooltip
->GetTip() ;
1552 void wxWindow::MacFireMouseEvent( EventRecord
*ev
)
1554 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
1555 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1556 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1558 event
.m_leftDown
= isDown
&& !controlDown
;
1559 event
.m_middleDown
= FALSE
;
1560 event
.m_rightDown
= isDown
&& controlDown
;
1562 if ( ev
->what
== mouseDown
)
1565 event
.SetEventType(wxEVT_RIGHT_DOWN
) ;
1567 event
.SetEventType(wxEVT_LEFT_DOWN
) ;
1569 else if ( ev
->what
== mouseUp
)
1572 event
.SetEventType(wxEVT_RIGHT_UP
) ;
1574 event
.SetEventType(wxEVT_LEFT_UP
) ;
1578 event
.SetEventType(wxEVT_MOTION
) ;
1581 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1582 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1583 event
.m_altDown
= ev
->modifiers
& optionKey
;
1584 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1586 Point localwhere
= ev
->where
;
1589 ::GetPort( &port
) ;
1590 ::SetPort( UMAGetWindowPort( m_macWindowData
->m_macWindow
) ) ;
1591 ::GlobalToLocal( &localwhere
) ;
1594 if ( ev
->what
== mouseDown
)
1596 if ( ev
->when
- lastWhen
<= GetDblTime() )
1598 if ( abs( localwhere
.h
- lastWhere
.h
) < 3 || abs( localwhere
.v
- lastWhere
.v
) < 3 )
1601 event
.SetEventType(wxEVT_RIGHT_DCLICK
) ;
1603 event
.SetEventType(wxEVT_LEFT_DCLICK
) ;
1606 lastWhen
= ev
->when
;
1607 lastWhere
= localwhere
;
1610 event
.m_x
= localwhere
.h
;
1611 event
.m_y
= localwhere
.v
;
1616 wxPoint origin = GetClientAreaOrigin() ;
1618 event.m_x += origin.x ;
1619 event.m_y += origin.y ;
1622 event
.m_timeStamp
= ev
->when
;
1623 event
.SetEventObject(this);
1624 if ( wxTheApp
->s_captureWindow
)
1628 wxTheApp
->s_captureWindow
->ScreenToClient( &x
, &y
) ;
1631 wxTheApp
->s_captureWindow
->GetEventHandler()->ProcessEvent( event
) ;
1632 if ( ev
->what
== mouseUp
)
1634 wxTheApp
->s_captureWindow
= NULL
;
1635 if ( wxBusyCursorCount
== 0 )
1637 m_cursor
.MacInstall() ;
1643 MacDispatchMouseEvent( event
) ;
1647 void wxWindow::MacMouseDown( EventRecord
*ev
, short part
)
1649 MacFireMouseEvent( ev
) ;
1652 void wxWindow::MacMouseUp( EventRecord
*ev
, short part
)
1654 WindowPtr frontWindow
;
1659 MacFireMouseEvent( ev
) ;
1665 void wxWindow::MacMouseMoved( EventRecord
*ev
, short part
)
1667 WindowPtr frontWindow
;
1672 MacFireMouseEvent( ev
) ;
1677 void wxWindow::MacActivate( EventRecord
*ev
, bool inIsActivating
)
1679 wxActivateEvent
event(wxEVT_ACTIVATE
, inIsActivating
);
1680 event
.m_timeStamp
= ev
->when
;
1681 event
.SetEventObject(this);
1683 GetEventHandler()->ProcessEvent(event
);
1685 UMAHighlightAndActivateWindow( m_macWindowData
->m_macWindow
, inIsActivating
) ;
1688 void wxWindow::MacRedraw( RgnHandle updatergn
, long time
)
1690 // updatergn is always already clipped to our boundaries
1691 WindowRef window
= GetMacRootWindow() ;
1692 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1694 wxMacDrawingHelper
focus( this ) ; // was client
1697 WindowRef window
= GetMacRootWindow() ;
1698 bool eraseBackground
= false ;
1699 if ( m_macWindowData
)
1700 eraseBackground
= true ;
1701 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
1703 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
1705 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1707 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1708 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1709 // either a non gray background color or a non control window
1712 wxWindow
* parent
= GetParent() ;
1715 if ( parent
->GetMacRootWindow() != window
)
1717 // we are in a different window on the mac system
1722 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
1724 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1726 // if we have any other colours in the hierarchy
1727 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
1730 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1731 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
1734 GetRegionBounds( updatergn
, &box
) ;
1735 UMAApplyThemeBackground(kThemeBackgroundTabPane
, &box
, kThemeStateActive
,8,true);
1744 parent
= parent
->GetParent() ;
1748 // if there is nothing special -> use default
1749 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
1754 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
1756 if ( GetParent() && m_backgroundColour
!= GetParent()->GetBackgroundColour() )
1757 eraseBackground
= true ;
1758 SetClip( updatergn
) ;
1759 if ( eraseBackground
)
1761 EraseRgn( updatergn
) ;
1765 m_macUpdateRgn
= updatergn
;
1767 RgnHandle newupdate
= NewRgn() ;
1768 wxSize point
= GetClientSize() ;
1769 wxPoint origin
= GetClientAreaOrigin() ;
1771 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1772 SectRgn( newupdate
, m_macUpdateRgn
, newupdate
) ;
1773 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1774 m_updateRegion
= newupdate
;
1775 DisposeRgn( newupdate
) ;
1780 event
.m_timeStamp
= time
;
1781 event
.SetEventObject(this);
1782 GetEventHandler()->ProcessEvent(event
);
1786 RgnHandle childupdate
= NewRgn() ;
1788 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1790 wxWindow
*child
= (wxWindow
*)node
->Data();
1791 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1792 SectRgn( childupdate
, m_macUpdateRgn
, childupdate
) ;
1793 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1794 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1796 // because dialogs may also be children
1797 child
->MacRedraw( childupdate
, time
) ;
1800 DisposeRgn( childupdate
) ;
1801 // eventually a draw grow box here
1804 void wxWindow::MacUpdateImmediately()
1806 WindowRef window
= GetMacRootWindow() ;
1809 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1811 AGAPortHelper
help( GetWindowPort(window
) ) ;
1813 AGAPortHelper
help( (window
) ) ;
1815 SetOrigin( 0 , 0 ) ;
1816 BeginUpdate( window
) ;
1819 RgnHandle region
= NewRgn();
1823 GetPortVisibleRegion( GetWindowPort( window
), region
);
1825 // if windowshade gives incompatibility , take the follwing out
1826 if ( !EmptyRgn( region
) )
1828 win
->MacRedraw( region
, wxTheApp
->sm_lastMessageTime
) ;
1830 DisposeRgn( region
);
1833 EndUpdate( window
) ;
1837 void wxWindow::MacUpdate( EventRecord
*ev
)
1839 WindowRef window
= (WindowRef
) ev
->message
;
1840 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1842 AGAPortHelper
help( GetWindowPort(window
) ) ;
1844 AGAPortHelper
help( (window
) ) ;
1846 SetOrigin( 0 , 0 ) ;
1847 BeginUpdate( window
) ;
1850 RgnHandle region
= NewRgn();
1854 GetPortVisibleRegion( GetWindowPort( window
), region
);
1856 // if windowshade gives incompatibility , take the follwing out
1857 if ( !EmptyRgn( region
) )
1859 MacRedraw( region
, ev
->when
) ;
1861 DisposeRgn( region
);
1864 EndUpdate( window
) ;
1867 WindowRef
wxWindow::GetMacRootWindow() const
1869 WindowRef window
= NULL
;
1870 wxWindow
*iter
= (wxWindow
*)this ;
1874 if ( iter
->m_macWindowData
)
1875 return iter
->m_macWindowData
->m_macWindow
;
1877 iter
= iter
->GetParent() ;
1879 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1883 void wxWindow::MacCreateScrollBars( long style
)
1885 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
1887 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1888 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1890 GetClientSize( &width
, &height
) ;
1892 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1893 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1894 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1895 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1897 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
1898 vSize
, wxVERTICAL
);
1900 if ( style
& wxVSCROLL
)
1906 m_vScrollBar
->Show(false) ;
1908 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
1909 hSize
, wxHORIZONTAL
);
1910 if ( style
& wxHSCROLL
)
1915 m_hScrollBar
->Show(false) ;
1918 // because the create does not take into account the client area origin
1919 MacRepositionScrollBars() ; // we might have a real position shift
1922 void wxWindow::MacRepositionScrollBars()
1924 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
1925 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
1927 // get real client area
1929 int width
= m_width
;
1930 int height
= m_height
;
1932 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
1933 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
1935 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1936 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1937 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1938 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1945 MacClientToRootWindow( &x
, &y
) ;
1946 MacClientToRootWindow( &w
, &h
) ;
1948 WindowRef window
= NULL
;
1949 wxWindow
*iter
= (wxWindow
*)this ;
1951 int totW
= 10000 , totH
= 10000;
1954 if ( iter
->m_macWindowData
)
1956 totW
= iter
->m_width
;
1957 totH
= iter
->m_height
;
1961 iter
= iter
->GetParent() ;
1989 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1993 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1997 void wxWindow::MacKeyDown( EventRecord
*ev
)
2003 bool wxWindow::AcceptsFocus() const
2005 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2008 ControlHandle
wxWindow::MacGetContainerForEmbedding()
2010 if ( m_macWindowData
)
2011 return m_macWindowData
->m_macRootControl
;
2013 return GetParent()->MacGetContainerForEmbedding() ;
2016 void wxWindow::MacSuperChangedPosition()
2018 // only window-absolute structures have to be moved i.e. controls
2020 wxNode
*node
= GetChildren().First();
2023 wxWindow
*child
= (wxWindow
*)node
->Data();
2024 child
->MacSuperChangedPosition() ;
2025 node
= node
->Next();
2029 bool wxWindow::MacSetPortFocusParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
2031 if ( window
== NULL
)
2037 ::GetPort(&currPort
);
2038 port
= UMAGetWindowPort( window
) ;
2039 if (currPort
!= port
)
2042 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2043 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2047 bool wxWindow::MacSetPortDrawingParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
2049 if ( window
== NULL
)
2054 ::GetPort(&currPort
);
2055 port
= UMAGetWindowPort( window
) ;
2056 if (currPort
!= port
)
2058 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2059 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2060 ::ClipRect(&clipRect
);
2063 ::RGBBackColor(& win
->GetBackgroundColour().GetPixel() ) ;
2064 ::RGBForeColor(& win
->GetForegroundColour().GetPixel() ) ;
2065 Pattern whiteColor
;
2067 ::BackPat( GetQDGlobalsWhite( &whiteColor
) ) ;
2068 ::UMASetThemeWindowBackground( win
->m_macWindowData
->m_macWindow
, win
->m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
2072 void wxWindow::MacGetPortParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2074 if ( m_macWindowData
)
2080 clipRect
->right
= m_width
;
2081 clipRect
->bottom
= m_height
;
2082 *window
= m_macWindowData
->m_macWindow
;
2087 wxASSERT( GetParent() != NULL
) ;
2088 GetParent()->MacGetPortParams( localOrigin
, clipRect
, window
, rootwin
) ;
2089 localOrigin
->h
+= m_x
;
2090 localOrigin
->v
+= m_y
;
2091 OffsetRect(clipRect
, -m_x
, -m_y
);
2096 myClip
.right
= m_width
;
2097 myClip
.bottom
= m_height
;
2098 SectRect(clipRect
, &myClip
, clipRect
);
2102 void wxWindow::MacDoGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2104 // int width , height ;
2105 // GetClientSize( &width , &height ) ;
2107 if ( m_macWindowData
)
2113 clipRect
->right
= m_width
;//width;
2114 clipRect
->bottom
= m_height
;// height;
2115 *window
= m_macWindowData
->m_macWindow
;
2120 wxASSERT( GetParent() != NULL
) ;
2122 GetParent()->MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2124 localOrigin
->h
+= m_x
;
2125 localOrigin
->v
+= m_y
;
2126 OffsetRect(clipRect
, -m_x
, -m_y
);
2131 myClip
.right
= m_width
;//width;
2132 myClip
.bottom
= m_height
;// height;
2133 SectRect(clipRect
, &myClip
, clipRect
);
2137 void wxWindow::MacGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2139 MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2141 int width
, height
;
2142 GetClientSize( &width
, &height
) ;
2144 client
= GetClientAreaOrigin( ) ;
2146 localOrigin
->h
+= client
.x
;
2147 localOrigin
->v
+= client
.y
;
2148 OffsetRect(clipRect
, -client
.x
, -client
.y
);
2153 myClip
.right
= width
;
2154 myClip
.bottom
= height
;
2155 SectRect(clipRect
, &myClip
, clipRect
);
2158 long wxWindow::MacGetLeftBorderSize( ) const
2160 if( m_macWindowData
)
2163 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2167 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2171 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2178 long wxWindow::MacGetRightBorderSize( ) const
2180 if( m_macWindowData
)
2183 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2187 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2191 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2198 long wxWindow::MacGetTopBorderSize( ) const
2200 if( m_macWindowData
)
2203 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2207 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2211 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2218 long wxWindow::MacGetBottomBorderSize( ) const
2220 if( m_macWindowData
)
2223 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2227 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2231 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2238 long wxWindow::MacRemoveBordersFromStyle( long style
)
2240 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2244 wxMacDrawingHelper::wxMacDrawingHelper( wxWindow
* theWindow
)
2251 m_currentPort
= NULL
;
2253 GetPort( &m_formerPort
) ;
2256 theWindow
->MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2257 m_currentPort
= UMAGetWindowPort( window
) ;
2258 if ( m_formerPort
!= m_currentPort
)
2259 SetPort( m_currentPort
) ;
2260 GetPenState( &m_savedPenState
) ;
2261 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2266 wxMacDrawingHelper::~wxMacDrawingHelper()
2270 SetPort( m_currentPort
) ;
2271 SetPenState( &m_savedPenState
) ;
2272 SetOrigin( 0 , 0 ) ;
2274 GetPortBounds( m_currentPort
, &portRect
) ;
2275 ClipRect( &portRect
) ;
2276 wxDC::MacInvalidateSetup() ;
2279 if ( m_formerPort
!= m_currentPort
)
2280 SetPort( m_formerPort
) ;
2283 wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindow
* theWindow
)
2290 m_currentPort
= NULL
;
2292 GetPort( &m_formerPort
) ;
2296 theWindow
->MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2297 m_currentPort
= UMAGetWindowPort( window
) ;
2298 if ( m_formerPort
!= m_currentPort
)
2299 SetPort( m_currentPort
) ;
2300 GetPenState( &m_savedPenState
) ;
2301 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2306 wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
2310 SetPort( m_currentPort
) ;
2311 SetPenState( &m_savedPenState
) ;
2312 SetOrigin( 0 , 0 ) ;
2314 GetPortBounds( m_currentPort
, &portRect
) ;
2315 ClipRect( &portRect
) ;
2318 if ( m_formerPort
!= m_currentPort
)
2319 SetPort( m_formerPort
) ;
2322 // Find the wxWindow at the current mouse position, returning the mouse
2324 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
2326 pt
= wxGetMousePosition();
2327 wxWindow
* found
= wxFindWindowAtPoint(pt
);
2331 // Get the current mouse position.
2332 wxPoint
wxGetMousePosition()
2335 wxGetMousePosition(& x
, & y
);
2336 return wxPoint(x
, y
);