1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
18 #include "wx/window.h"
20 #include "wx/dcclient.h"
24 #include "wx/layout.h"
25 #include "wx/dialog.h"
26 #include "wx/listbox.h"
27 #include "wx/scrolbar.h"
28 #include "wx/statbox.h"
29 #include "wx/button.h"
30 #include "wx/settings.h"
31 #include "wx/msgdlg.h"
33 #include "wx/notebook.h"
34 #include "wx/tabctrl.h"
35 #include "wx/tooltip.h"
36 #include "wx/statusbr.h"
37 #include "wx/menuitem.h"
44 #define wxWINDOW_HSCROLL 5998
45 #define wxWINDOW_VSCROLL 5997
46 #define MAC_SCROLLBAR_SIZE 16
48 #include <wx/mac/uma.h>
50 #if wxUSE_DRAG_AND_DROP
56 extern wxList wxPendingDelete
;
57 wxWindow
* gFocusWindow
= NULL
;
59 #if !USE_SHARED_LIBRARY
60 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxEvtHandler
)
61 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
62 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground
)
63 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
64 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
65 EVT_IDLE(wxWindow::OnIdle
)
66 EVT_SET_FOCUS(wxWindow::OnSetFocus
)
73 // ===========================================================================
75 // ===========================================================================
77 // ---------------------------------------------------------------------------
78 // wxWindow utility functions
79 // ---------------------------------------------------------------------------
81 // Find an item given the Macintosh Window Reference
83 wxList
*wxWinMacWindowList
= NULL
;
84 wxWindow
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
86 wxNode
*node
= wxWinMacWindowList
->Find((long)inWindowRef
);
89 return (wxWindow
*)node
->Data();
92 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxWindow
*win
)
94 // adding NULL WindowRef is (first) surely a result of an error and
95 // (secondly) breaks menu command processing
96 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, "attempt to add a NULL WindowRef to window list" );
98 if ( !wxWinMacWindowList
->Find((long)inWindowRef
) )
99 wxWinMacWindowList
->Append((long)inWindowRef
, win
);
102 void wxRemoveMacWindowAssociation(wxWindow
*win
)
104 wxWinMacWindowList
->DeleteObject(win
);
107 // ----------------------------------------------------------------------------
108 // constructors and such
109 // ----------------------------------------------------------------------------
111 WindowRef
wxWindow::s_macWindowInUpdate
= NULL
;
113 void wxWindow::Init()
118 m_macEraseOnRedraw
= true ;
121 m_doubleClickAllowed
= 0;
122 m_winCaptured
= FALSE
;
124 m_isBeingDeleted
= FALSE
;
127 m_mouseInWindow
= FALSE
;
131 m_backgroundTransparent
= FALSE
;
133 // as all windows are created with WS_VISIBLE style...
136 m_macWindowData
= NULL
;
137 m_macEraseOnRedraw
= true ;
144 m_hScrollBar
= NULL
;
145 m_vScrollBar
= NULL
;
147 #if wxUSE_DRAG_AND_DROP
148 m_pDropTarget
= NULL
;
153 wxWindow::~wxWindow()
155 m_isBeingDeleted
= TRUE
;
157 if ( s_lastMouseWindow
== this )
159 s_lastMouseWindow
= NULL
;
162 if ( gFocusWindow
== this )
164 gFocusWindow
= NULL
;
168 m_parent
->RemoveChild(this);
172 if ( m_macWindowData
)
174 wxToolTip::NotifyWindowDelete(m_macWindowData
->m_macWindow
) ;
175 UMADisposeWindow( m_macWindowData
->m_macWindow
) ;
176 delete m_macWindowData
;
177 wxRemoveMacWindowAssociation( this ) ;
182 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
186 const wxString
& name
)
188 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindow without parent") );
190 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
193 parent
->AddChild(this);
197 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
198 m_width
= WidthDefault( size
.x
);
199 m_height
= HeightDefault( size
.y
) ;
201 if ( ! IsKindOf( CLASSINFO ( wxControl
) ) && ! IsKindOf( CLASSINFO( wxStatusBar
) ) )
203 MacCreateScrollBars( style
) ;
209 void wxWindow::SetFocus()
211 if ( gFocusWindow
== this )
214 if ( AcceptsFocus() )
220 if ( gFocusWindow
->m_caret
)
222 gFocusWindow
->m_caret
->OnKillFocus();
224 #endif // wxUSE_CARET
225 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
226 if ( control
&& control
->GetMacControl() )
228 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlFocusNoPart
) ;
229 control
->MacRedrawControl() ;
231 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
232 event
.SetEventObject(gFocusWindow
);
233 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
235 gFocusWindow
= this ;
241 m_caret
->OnSetFocus();
243 #endif // wxUSE_CARET
244 // panel wants to track the window which was the last to have focus in it
245 wxPanel
*panel
= wxDynamicCast(GetParent(), wxPanel
);
248 panel
->SetLastFocus(this);
250 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
251 if ( control
&& control
->GetMacControl() )
253 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlEditTextPart
) ;
256 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
257 event
.SetEventObject(this);
258 GetEventHandler()->ProcessEvent(event
) ;
263 bool wxWindow::Enable(bool enable
)
265 if ( !wxWindowBase::Enable(enable
) )
268 wxWindowList::Node
*node
= GetChildren().GetFirst();
271 wxWindow
*child
= node
->GetData();
272 child
->Enable(enable
);
274 node
= node
->GetNext();
280 void wxWindow::CaptureMouse()
282 wxTheApp
->s_captureWindow
= this ;
285 void wxWindow::ReleaseMouse()
287 wxTheApp
->s_captureWindow
= NULL
;
290 #if wxUSE_DRAG_AND_DROP
292 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
294 if ( m_pDropTarget
!= 0 ) {
295 delete m_pDropTarget
;
298 m_pDropTarget
= pDropTarget
;
299 if ( m_pDropTarget
!= 0 )
307 // Old style file-manager drag&drop
308 void wxWindow::DragAcceptFiles(bool accept
)
314 void wxWindow::DoGetSize(int *x
, int *y
) const
320 void wxWindow::DoGetPosition(int *x
, int *y
) const
326 wxPoint
pt(GetParent()->GetClientAreaOrigin());
333 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
335 menu
->SetInvokingWindow(this);
337 ClientToScreen( &x
, &y
) ;
339 ::InsertMenu( menu
->GetHMenu() , -1 ) ;
340 long menuResult
= ::PopUpMenuSelect(menu
->GetHMenu() ,y
,x
, 0) ;
341 menu
->MacMenuSelect( this , TickCount() , HiWord(menuResult
) , LoWord(menuResult
) ) ;
342 ::DeleteMenu( menu
->MacGetMenuId() ) ;
343 menu
->SetInvokingWindow(NULL
);
348 void wxWindow::DoScreenToClient(int *x
, int *y
) const
350 WindowRef window
= GetMacRootWindow() ;
358 ::SetPort( UMAGetWindowPort( window
) ) ;
359 ::GlobalToLocal( &localwhere
) ;
365 MacRootWindowToClient( x
, y
) ;
368 void wxWindow::DoClientToScreen(int *x
, int *y
) const
370 WindowRef window
= GetMacRootWindow() ;
372 MacClientToRootWindow( x
, y
) ;
380 ::SetPort( UMAGetWindowPort( window
) ) ;
381 ::SetOrigin( 0 , 0 ) ;
382 ::LocalToGlobal( &localwhere
) ;
388 void wxWindow::MacClientToRootWindow( int *x
, int *y
) const
390 if ( m_macWindowData
)
397 GetParent()->MacClientToRootWindow( x
, y
) ;
401 void wxWindow::MacRootWindowToClient( int *x
, int *y
) const
403 if ( m_macWindowData
)
410 GetParent()->MacRootWindowToClient( x
, y
) ;
414 bool wxWindow::SetCursor(const wxCursor
& cursor
)
416 if (m_cursor
== cursor
)
419 if (wxNullCursor
== cursor
)
421 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
426 if ( ! wxWindowBase::SetCursor( cursor
) )
430 wxASSERT_MSG( m_cursor
.Ok(),
431 wxT("cursor must be valid after call to the base version"));
437 // Change the cursor NOW if we're within the correct window
439 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
441 if ( mouseWin
== this && !wxIsBusy() )
443 m_cursor
.MacInstall() ;
451 // Get size *available for subwindows* i.e. excluding menu bar etc.
452 void wxWindow::DoGetClientSize(int *x
, int *y
) const
457 *x
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
458 *y
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
460 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
467 MacClientToRootWindow( &x1
, &y1
) ;
468 MacClientToRootWindow( &w
, &h
) ;
470 WindowRef window
= NULL
;
471 wxWindow
*iter
= (wxWindow
*)this ;
473 int totW
= 10000 , totH
= 10000;
476 if ( iter
->m_macWindowData
)
478 totW
= iter
->m_width
;
479 totH
= iter
->m_height
;
483 iter
= iter
->GetParent() ;
486 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
488 (*y
) -= MAC_SCROLLBAR_SIZE
;
494 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
496 (*x
) -= MAC_SCROLLBAR_SIZE
;
506 // ----------------------------------------------------------------------------
508 // ----------------------------------------------------------------------------
512 void wxWindow::DoSetToolTip(wxToolTip
*tooltip
)
514 wxWindowBase::DoSetToolTip(tooltip
);
517 m_tooltip
->SetWindow(this);
520 #endif // wxUSE_TOOLTIPS
522 void wxWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
524 DoSetSize( x
,y
, width
, height
) ;
527 // set the size of the window: if the dimensions are positive, just use them,
528 // but if any of them is equal to -1, it means that we must find the value for
529 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
530 // which case -1 is a valid value for x and y)
532 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
533 // the width/height to best suit our contents, otherwise we reuse the current
535 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
540 int former_w
= m_width
;
541 int former_h
= m_height
;
543 int currentX
, currentY
;
544 GetPosition(¤tX
, ¤tY
);
545 int currentW
,currentH
;
546 GetSize(¤tW
, ¤tH
);
548 int actualWidth
= width
;
549 int actualHeight
= height
;
552 if (x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
554 if (y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
557 wxSize
size( -1 , -1 ) ;
559 if (width
== -1 || height
== -1 )
561 size
= DoGetBestSize() ;
566 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
568 actualWidth
= size
.x
;
569 if ( actualWidth
== -1 )
574 actualWidth
= currentW
;
579 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
581 actualHeight
= size
.y
;
582 if ( actualHeight
== -1 )
587 actualHeight
= currentH
;
591 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
592 actualWidth
= m_minWidth
;
593 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
594 actualHeight
= m_minHeight
;
595 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
596 actualWidth
= m_maxWidth
;
597 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
598 actualHeight
= m_maxHeight
;
599 if ( actualX
== currentX
&& actualY
== currentY
&& actualWidth
== currentW
&& actualHeight
== currentH
)
601 MacRepositionScrollBars() ; // we might have a real position shift
605 AdjustForParentClientOrigin(actualX
, actualY
, sizeFlags
);
608 bool doMove
= false ;
609 bool doResize
= false ;
611 if ( actualX
!= former_x
|| actualY
!= former_y
)
615 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
620 if ( doMove
|| doResize
)
622 if ( m_macWindowData
)
627 // erase former position
628 wxMacDrawingHelper
focus( this ) ;
631 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
632 ClipRect( &clientrect
) ;
633 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
638 m_width
= actualWidth
;
639 m_height
= actualHeight
;
640 if ( m_macWindowData
)
643 ::MoveWindow(m_macWindowData
->m_macWindow
, m_x
, m_y
, false); // don't make frontmost
646 ::SizeWindow(m_macWindowData
->m_macWindow
, m_width
, m_height
, true);
648 // the OS takes care of invalidating and erasing the new area
649 // we have erased the old one
651 if ( IsKindOf( CLASSINFO( wxFrame
) ) )
653 wxFrame
* frame
= (wxFrame
*) this ;
654 frame
->PositionStatusBar();
655 frame
->PositionToolBar();
660 // erase new position
663 wxMacDrawingHelper
focus( this ) ;
666 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
667 ClipRect( &clientrect
) ;
668 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
673 wxWindow::MacSuperChangedPosition() ; // like this only children will be notified
675 MacRepositionScrollBars() ;
678 wxMoveEvent
event(wxPoint(m_x
, m_y
), m_windowId
);
679 event
.SetEventObject(this);
680 GetEventHandler()->ProcessEvent(event
) ;
684 MacRepositionScrollBars() ;
685 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
686 event
.SetEventObject(this);
687 GetEventHandler()->ProcessEvent(event
);
691 // For implementation purposes - sometimes decorations make the client area
694 wxPoint
wxWindow::GetClientAreaOrigin() const
696 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
699 // Makes an adjustment to the window position (for example, a frame that has
700 // a toolbar that it manages itself).
701 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
703 if( !m_macWindowData
)
705 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
707 wxPoint
pt(GetParent()->GetClientAreaOrigin());
708 x
+= pt
.x
; y
+= pt
.y
;
713 void wxWindow::SetTitle(const wxString
& title
)
719 if( wxApp::s_macDefaultEncodingIsPC
)
720 label
= wxMacMakeMacStringFromPC( title
) ;
724 if ( m_macWindowData
)
725 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
728 wxString
wxWindow::GetTitle() const
733 bool wxWindow::Show(bool show
)
735 if ( !wxWindowBase::Show(show
) )
738 if ( m_macWindowData
)
742 UMAShowWindow( m_macWindowData
->m_macWindow
) ;
743 UMASelectWindow( m_macWindowData
->m_macWindow
) ;
744 // no need to generate events here, they will get them triggered by macos
745 // actually they should be , but apparently they are not
746 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
747 event
.SetEventObject(this);
748 GetEventHandler()->ProcessEvent(event
);
752 UMAHideWindow( m_macWindowData
->m_macWindow
) ;
755 MacSuperShown( show
) ;
758 MacUpdateImmediately() ;
763 void wxWindow::MacSuperShown( bool show
)
765 wxNode
*node
= GetChildren().First();
768 wxWindow
*child
= (wxWindow
*)node
->Data();
769 if ( child
->m_isShown
)
770 child
->MacSuperShown( show
) ;
775 bool wxWindow::MacIsReallyShown() const
777 if ( m_isShown
&& (m_parent
!= NULL
) ) {
778 return m_parent
->MacIsReallyShown();
782 bool status = m_isShown ;
783 wxWindow * win = this ;
784 while ( status && win->m_parent != NULL )
786 win = win->m_parent ;
787 status = win->m_isShown ;
793 int wxWindow::GetCharHeight() const
795 wxClientDC
dc ( (wxWindow
*)this ) ;
796 return dc
.GetCharHeight() ;
799 int wxWindow::GetCharWidth() const
801 wxClientDC
dc ( (wxWindow
*)this ) ;
802 return dc
.GetCharWidth() ;
805 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
806 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
808 const wxFont
*fontToUse
= theFont
;
812 wxClientDC
dc( (wxWindow
*) this ) ;
814 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
815 if ( externalLeading
)
816 *externalLeading
= le
;
825 void wxWindow::MacEraseBackground( Rect
*rect
)
828 WindowRef window = GetMacRootWindow() ;
829 if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
831 UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ;
833 else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
835 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
836 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
837 // either a non gray background color or a non control window
839 wxWindow* parent = GetParent() ;
842 if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
844 // if we have any other colours in the hierarchy
845 RGBBackColor( &parent->m_backgroundColour.GetPixel()) ;
848 if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() )
850 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
851 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
853 UMAApplyThemeBackground(kThemeBackgroundTabPane, rect, kThemeStateActive,8,true);
859 // we have arrived at a non control item
863 parent = parent->GetParent() ;
867 // if there is nothing special -> use default
868 UMASetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ;
873 RGBBackColor( &m_backgroundColour.GetPixel()) ;
878 for (wxNode *node = GetChildren().First(); node; node = node->Next())
880 wxWindow *child = (wxWindow*)node->Data();
882 Rect clientrect = { child->m_x , child->m_y , child->m_x +child->m_width , child->m_y + child->m_height } ;
883 SectRect( &clientrect , rect , &clientrect ) ;
885 OffsetRect( &clientrect , -child->m_x , -child->m_y ) ;
886 if ( child->GetMacRootWindow() == window && child->IsShown() )
888 wxMacDrawingClientHelper focus( this ) ;
891 child->MacEraseBackground( &clientrect ) ;
898 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
900 wxMacDrawingHelper
focus( this ) ;
903 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
904 ClipRect( &clientrect
) ;
908 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
909 SectRect( &clientrect
, &r
, &clientrect
) ;
911 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
914 m_macEraseOnRedraw
= false ;
916 m_macEraseOnRedraw
= true ;
919 // Responds to colour changes: passes event on to children.
920 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
922 wxNode
*node
= GetChildren().First();
925 // Only propagate to non-top-level windows
926 wxWindow
*win
= (wxWindow
*)node
->Data();
927 if ( win
->GetParent() )
929 wxSysColourChangedEvent event2
;
930 event
.m_eventObject
= win
;
931 win
->GetEventHandler()->ProcessEvent(event2
);
938 #if wxUSE_CARET && WXWIN_COMPATIBILITY
939 // ---------------------------------------------------------------------------
940 // Caret manipulation
941 // ---------------------------------------------------------------------------
943 void wxWindow::CreateCaret(int w
, int h
)
945 SetCaret(new wxCaret(this, w
, h
));
948 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
950 wxFAIL_MSG("not implemented");
953 void wxWindow::ShowCaret(bool show
)
955 wxCHECK_RET( m_caret
, "no caret to show" );
960 void wxWindow::DestroyCaret()
965 void wxWindow::SetCaretPos(int x
, int y
)
967 wxCHECK_RET( m_caret
, "no caret to move" );
972 void wxWindow::GetCaretPos(int *x
, int *y
) const
974 wxCHECK_RET( m_caret
, "no caret to get position of" );
976 m_caret
->GetPosition(x
, y
);
978 #endif // wxUSE_CARET
980 wxWindow
*wxGetActiveWindow()
982 // actually this is a windows-only concept
986 // Coordinates relative to the window
987 void wxWindow::WarpPointer (int x_pos
, int y_pos
)
989 // We really dont move the mouse programmatically under mac
992 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
994 // TODO : probably we would adopt the EraseEvent structure
997 int wxWindow::GetScrollPos(int orient
) const
999 if ( orient
== wxHORIZONTAL
)
1002 return m_hScrollBar
->GetThumbPosition() ;
1007 return m_vScrollBar
->GetThumbPosition() ;
1012 // This now returns the whole range, not just the number
1013 // of positions that we can scroll.
1014 int wxWindow::GetScrollRange(int orient
) const
1016 if ( orient
== wxHORIZONTAL
)
1019 return m_hScrollBar
->GetRange() ;
1024 return m_vScrollBar
->GetRange() ;
1029 int wxWindow::GetScrollThumb(int orient
) const
1031 if ( orient
== wxHORIZONTAL
)
1034 return m_hScrollBar
->GetThumbSize() ;
1039 return m_vScrollBar
->GetThumbSize() ;
1044 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
1046 if ( orient
== wxHORIZONTAL
)
1049 m_hScrollBar
->SetThumbPosition( pos
) ;
1054 m_vScrollBar
->SetThumbPosition( pos
) ;
1058 void wxWindow::MacCreateRealWindow( const wxString
& title
,
1062 const wxString
& name
)
1065 m_windowStyle
= style
;
1086 m_macWindowData
= new MacWindowData() ;
1088 ::SetRect(&theBoundsRect
, m_x
, m_y
, m_x
+ m_width
, m_y
+ m_height
);
1090 // translate the window attributes in the appropriate window class and attributes
1092 WindowClass wclass
= 0;
1093 WindowAttributes attr
= kWindowNoAttributes
;
1095 if ( HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
) )
1097 wclass
= kFloatingWindowClass
;
1098 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1100 attr
|= kWindowSideTitlebarAttribute
;
1103 else if ( HasFlag( wxCAPTION
) )
1105 if ( HasFlag( wxDIALOG_MODAL
) )
1107 wclass
= kMovableModalWindowClass
;
1111 wclass
= kDocumentWindowClass
;
1116 wclass
= kModalWindowClass
;
1119 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) )
1121 attr
|= kWindowFullZoomAttribute
;
1122 attr
|= kWindowCollapseBoxAttribute
;
1124 if ( HasFlag( wxRESIZE_BORDER
) )
1126 attr
|= kWindowResizableAttribute
;
1128 if ( HasFlag( wxSYSTEM_MENU
) )
1130 attr
|= kWindowCloseBoxAttribute
;
1133 UMACreateNewWindow( wclass
, attr
, &theBoundsRect
, &m_macWindowData
->m_macWindow
) ;
1134 wxAssociateWinWithMacWindow( m_macWindowData
->m_macWindow
, this ) ;
1136 if( wxApp::s_macDefaultEncodingIsPC
)
1137 label
= wxMacMakeMacStringFromPC( title
) ;
1140 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
1141 UMACreateRootControl( m_macWindowData
->m_macWindow
, &m_macWindowData
->m_macRootControl
) ;
1143 m_macWindowData
->m_macFocus
= NULL
;
1146 void wxWindow::MacPaint( wxPaintEvent
&event
)
1150 void wxWindow::MacPaintBorders( )
1152 if( m_macWindowData
)
1155 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1156 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1157 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1158 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1161 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1163 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1164 RGBColor pen1
= sunken
? white
: black
;
1165 RGBColor pen2
= sunken
? shadow
: face
;
1166 RGBColor pen3
= sunken
? face
: shadow
;
1167 RGBColor pen4
= sunken
? black
: white
;
1169 RGBForeColor( &pen1
) ;
1171 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1172 FrameRect( &rect
) ;
1174 RGBForeColor( &pen2
) ;
1176 Rect rect
= { 1 , 1 , m_height
-1 , m_width
-1} ;
1177 FrameRect( &rect
) ;
1179 RGBForeColor( &pen3
) ;
1181 Rect rect
= { 0 , 0 , m_height
-2 , m_width
-2} ;
1182 FrameRect( &rect
) ;
1184 RGBForeColor( &pen4
) ;
1187 LineTo( m_width
- 3 , 0 ) ;
1189 LineTo( 0 , m_height
- 3 ) ;
1192 else if (HasFlag(wxSIMPLE_BORDER
))
1194 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1195 RGBForeColor( &black
) ;
1196 FrameRect( &rect
) ;
1199 if ( this->GetParent() )
1201 wxPaintDC dc(GetParent());
1202 GetParent()->PrepareDC(dc);
1204 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) )
1206 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1208 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1209 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1211 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1212 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1213 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1214 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1217 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1220 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1223 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1226 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1227 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1229 else if (HasFlag(wxDOUBLE_BORDER))
1231 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1233 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1234 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1236 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1237 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1238 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1239 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1242 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1245 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1248 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1251 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1252 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1254 else if (HasFlag(wxSIMPLE_BORDER))
1256 dc.SetPen(*wxBLACK_PEN);
1257 dc.DrawRectangle(m_x, m_y, m_width, m_height);
1263 // New function that will replace some of the above.
1264 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1265 int range
, bool refresh
)
1267 if ( orient
== wxHORIZONTAL
)
1271 if ( range
== 0 || thumbVisible
>= range
)
1273 if ( m_hScrollBar
->IsShown() )
1274 m_hScrollBar
->Show(false) ;
1278 if ( !m_hScrollBar
->IsShown() )
1279 m_hScrollBar
->Show(true) ;
1280 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1288 if ( range
== 0 || thumbVisible
>= range
)
1290 if ( m_vScrollBar
->IsShown() )
1291 m_vScrollBar
->Show(false) ;
1295 if ( !m_vScrollBar
->IsShown() )
1296 m_vScrollBar
->Show(true) ;
1297 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1301 MacRepositionScrollBars() ;
1304 // Does a physical scroll
1305 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1307 wxMacDrawingClientHelper
focus( this ) ;
1310 int width
, height
;
1311 GetClientSize( &width
, &height
) ;
1313 Rect scrollrect
= { 0 , 0 , height
, width
} ;
1315 RgnHandle updateRgn
= NewRgn() ;
1316 ClipRect( &scrollrect
) ;
1319 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
1320 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1322 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1323 InvalWindowRgn( GetMacRootWindow() , updateRgn
) ;
1324 DisposeRgn( updateRgn
) ;
1327 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1329 wxWindow
*child
= (wxWindow
*)node
->Data();
1330 if (child
== m_vScrollBar
) continue;
1331 if (child
== m_hScrollBar
) continue;
1332 if (child
->IsTopLevel()) continue;
1334 child
->GetPosition( &x
, &y
);
1336 child
->GetSize( &w
, &h
);
1337 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1342 void wxWindow::MacOnScroll(wxScrollEvent
&event
)
1344 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1346 wxScrollWinEvent wevent
;
1347 wevent
.SetPosition(event
.GetPosition());
1348 wevent
.SetOrientation(event
.GetOrientation());
1349 wevent
.m_eventObject
= this;
1351 if (event
.m_eventType
== wxEVT_SCROLL_TOP
) {
1352 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1354 if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
) {
1355 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1357 if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
) {
1358 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1360 if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
) {
1361 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1363 if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
) {
1364 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1366 if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
) {
1367 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1369 if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
) {
1370 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1373 GetEventHandler()->ProcessEvent(wevent
);
1377 bool wxWindow::SetFont(const wxFont
& font
)
1379 if ( !wxWindowBase::SetFont(font
) )
1388 // Get the window with the focus
1389 wxWindow
*wxWindowBase::FindFocus()
1391 return gFocusWindow
;
1394 #if WXWIN_COMPATIBILITY
1395 // If nothing defined for this, try the parent.
1396 // E.g. we may be a button loaded from a resource, with no callback function
1398 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1400 if ( GetEventHandler()->ProcessEvent(event
) )
1403 m_parent
->GetEventHandler()->OnCommand(win
, event
);
1405 #endif // WXWIN_COMPATIBILITY_2
1407 #if WXWIN_COMPATIBILITY
1408 wxObject
* wxWindow::GetChild(int number
) const
1410 // Return a pointer to the Nth object in the Panel
1411 wxNode
*node
= GetChildren().First();
1414 node
= node
->Next();
1417 wxObject
*obj
= (wxObject
*)node
->Data();
1423 #endif // WXWIN_COMPATIBILITY
1425 void wxWindow::OnSetFocus(wxFocusEvent
& event
)
1427 // panel wants to track the window which was the last to have focus in it,
1428 // so we want to set ourselves as the window which last had focus
1430 // notice that it's also important to do it upwards the tree becaus
1431 // otherwise when the top level panel gets focus, it won't set it back to
1432 // us, but to some other sibling
1433 wxWindow
*win
= this;
1436 wxWindow
*parent
= win
->GetParent();
1437 wxPanel
*panel
= wxDynamicCast(parent
, wxPanel
);
1440 panel
->SetLastFocus(win
);
1449 void wxWindow::Clear()
1451 if ( m_macWindowData
)
1453 wxMacDrawingClientHelper
helper ( this ) ;
1455 wxPoint origin
= GetClientAreaOrigin() ;
1456 GetClientSize( &w
, &h
) ;
1457 UMASetThemeWindowBackground( m_macWindowData
->m_macWindow
, m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
1458 Rect r
= { origin
.y
, origin
.x
, origin
.y
+h
, origin
.x
+w
} ;
1463 wxClientDC
dc(this);
1464 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1465 dc
.SetBackground(brush
);
1470 // Setup background and foreground colours correctly
1471 void wxWindow::SetupColours()
1474 SetBackgroundColour(GetParent()->GetBackgroundColour());
1477 void wxWindow::OnIdle(wxIdleEvent
& event
)
1480 // Check if we need to send a LEAVE event
1481 if (m_mouseInWindow)
1484 ::GetCursorPos(&pt);
1485 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1487 // Generate a LEAVE event
1488 m_mouseInWindow = FALSE;
1489 MSWOnMouseLeave(pt.x, pt.y, 0);
1494 // This calls the UI-update mechanism (querying windows for
1495 // menu/toolbar/control state information)
1499 // Raise the window to the top of the Z order
1500 void wxWindow::Raise()
1505 // Lower the window to the bottom of the Z order
1506 void wxWindow::Lower()
1511 void wxWindow::DoSetClientSize(int width
, int height
)
1513 if ( width
!= -1 || height
!= -1 )
1516 if ( width
!= -1 && m_vScrollBar
)
1517 width
+= MAC_SCROLLBAR_SIZE
;
1518 if ( height
!= -1 && m_vScrollBar
)
1519 height
+= MAC_SCROLLBAR_SIZE
;
1521 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1522 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1524 DoSetSize( -1 , -1 , width
, height
) ;
1529 wxWindow
* wxWindow::s_lastMouseWindow
= NULL
;
1531 bool wxWindow::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindow
** outWin
)
1533 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1534 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1537 WindowRef window
= GetMacRootWindow() ;
1539 wxPoint
newPoint( point
) ;
1544 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1546 wxWindow
*child
= (wxWindow
*)node
->Data();
1547 // added the m_isShown test --dmazzoni
1548 if ( child
->GetMacRootWindow() == window
&& child
->m_isShown
)
1550 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1559 bool wxWindow::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindow
** outWin
)
1562 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1563 if ( ::FindWindow( pt
, &window
) == 3 )
1565 wxPoint
point( screenpoint
) ;
1566 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1569 win
->ScreenToClient( point
) ;
1570 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1576 extern int wxBusyCursorCount
;
1578 bool wxWindow::MacDispatchMouseEvent(wxMouseEvent
& event
)
1580 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1581 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1585 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) )
1588 WindowRef window
= GetMacRootWindow() ;
1596 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1598 wxWindow
*child
= (wxWindow
*)node
->Data();
1599 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1601 if (child
->MacDispatchMouseEvent(event
))
1609 if ( wxBusyCursorCount
== 0 )
1611 m_cursor
.MacInstall() ;
1614 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1616 // set focus to this window
1617 if (AcceptsFocus() && FindFocus()!=this)
1622 if ( event
.GetEventType() == wxEVT_MOTION
1623 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1624 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1625 wxToolTip::RelayEvent( this , event
);
1626 #endif // wxUSE_TOOLTIPS
1627 GetEventHandler()->ProcessEvent( event
) ;
1634 wxString
wxWindow::MacGetToolTipString( wxPoint
&pt
)
1638 return m_tooltip
->GetTip() ;
1642 void wxWindow::MacFireMouseEvent( EventRecord
*ev
)
1644 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
1645 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1646 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1648 event
.m_leftDown
= isDown
&& !controlDown
;
1649 event
.m_middleDown
= FALSE
;
1650 event
.m_rightDown
= isDown
&& controlDown
;
1652 if ( ev
->what
== mouseDown
)
1655 event
.SetEventType(wxEVT_RIGHT_DOWN
) ;
1657 event
.SetEventType(wxEVT_LEFT_DOWN
) ;
1659 else if ( ev
->what
== mouseUp
)
1662 event
.SetEventType(wxEVT_RIGHT_UP
) ;
1664 event
.SetEventType(wxEVT_LEFT_UP
) ;
1668 event
.SetEventType(wxEVT_MOTION
) ;
1671 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1672 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1673 event
.m_altDown
= ev
->modifiers
& optionKey
;
1674 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1676 Point localwhere
= ev
->where
;
1679 ::GetPort( &port
) ;
1680 ::SetPort( UMAGetWindowPort( m_macWindowData
->m_macWindow
) ) ;
1681 ::GlobalToLocal( &localwhere
) ;
1684 if ( ev
->what
== mouseDown
)
1686 if ( ev
->when
- lastWhen
<= GetDblTime() )
1688 if ( abs( localwhere
.h
- lastWhere
.h
) < 3 || abs( localwhere
.v
- lastWhere
.v
) < 3 )
1691 event
.SetEventType(wxEVT_RIGHT_DCLICK
) ;
1693 event
.SetEventType(wxEVT_LEFT_DCLICK
) ;
1696 lastWhen
= ev
->when
;
1697 lastWhere
= localwhere
;
1700 event
.m_x
= localwhere
.h
;
1701 event
.m_y
= localwhere
.v
;
1706 wxPoint origin = GetClientAreaOrigin() ;
1708 event.m_x += origin.x ;
1709 event.m_y += origin.y ;
1712 event
.m_timeStamp
= ev
->when
;
1713 event
.SetEventObject(this);
1714 if ( wxTheApp
->s_captureWindow
)
1718 wxTheApp
->s_captureWindow
->ScreenToClient( &x
, &y
) ;
1721 wxTheApp
->s_captureWindow
->GetEventHandler()->ProcessEvent( event
) ;
1722 if ( ev
->what
== mouseUp
)
1724 wxTheApp
->s_captureWindow
= NULL
;
1725 if ( wxBusyCursorCount
== 0 )
1727 m_cursor
.MacInstall() ;
1733 MacDispatchMouseEvent( event
) ;
1737 void wxWindow::MacMouseDown( EventRecord
*ev
, short part
)
1739 MacFireMouseEvent( ev
) ;
1742 void wxWindow::MacMouseUp( EventRecord
*ev
, short part
)
1744 WindowPtr frontWindow
;
1749 MacFireMouseEvent( ev
) ;
1755 void wxWindow::MacMouseMoved( EventRecord
*ev
, short part
)
1757 WindowPtr frontWindow
;
1762 MacFireMouseEvent( ev
) ;
1767 void wxWindow::MacActivate( EventRecord
*ev
, bool inIsActivating
)
1769 wxActivateEvent
event(wxEVT_ACTIVATE
, inIsActivating
, m_windowId
);
1770 event
.m_timeStamp
= ev
->when
;
1771 event
.SetEventObject(this);
1773 GetEventHandler()->ProcessEvent(event
);
1775 UMAHighlightAndActivateWindow( m_macWindowData
->m_macWindow
, inIsActivating
) ;
1778 void wxWindow::MacRedraw( RgnHandle updatergn
, long time
)
1780 // updatergn is always already clipped to our boundaries
1781 WindowRef window
= GetMacRootWindow() ;
1782 // ownUpdateRgn is the area that this window has to invalidate i.e. its own area without its children
1783 RgnHandle ownUpdateRgn
= NewRgn() ;
1784 CopyRgn( updatergn
, ownUpdateRgn
) ;
1785 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1787 wxMacDrawingHelper
focus( this ) ; // was client
1790 WindowRef window
= GetMacRootWindow() ;
1791 bool eraseBackground
= false ;
1792 if ( m_macWindowData
)
1793 eraseBackground
= true ;
1794 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
1796 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
1798 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1800 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1801 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1802 // either a non gray background color or a non control window
1805 wxWindow
* parent
= GetParent() ;
1808 if ( parent
->GetMacRootWindow() != window
)
1810 // we are in a different window on the mac system
1815 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
1817 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1819 // if we have any other colours in the hierarchy
1820 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
1823 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1824 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
1827 GetRegionBounds( updatergn
, &box
) ;
1828 UMAApplyThemeBackground(kThemeBackgroundTabPane
, &box
, kThemeStateActive
,8,true);
1837 parent
= parent
->GetParent() ;
1841 // if there is nothing special -> use default
1842 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
1847 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
1849 // subtract all non transparent children from updatergn
1851 RgnHandle childarea
= NewRgn() ;
1852 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1854 wxWindow
*child
= (wxWindow
*)node
->Data();
1855 // eventually test for transparent windows
1856 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() )
1858 if ( !child
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)child
)->GetMacControl() )
1860 SetRectRgn( childarea
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1861 DiffRgn( ownUpdateRgn
, childarea
, ownUpdateRgn
) ;
1865 DisposeRgn( childarea
) ;
1867 if ( GetParent() && m_backgroundColour
!= GetParent()->GetBackgroundColour() )
1868 eraseBackground
= true ;
1869 SetClip( ownUpdateRgn
) ;
1870 if ( m_macEraseOnRedraw
) {
1871 if ( eraseBackground
)
1873 EraseRgn( ownUpdateRgn
) ;
1877 m_macEraseOnRedraw
= true ;
1882 RgnHandle newupdate
= NewRgn() ;
1883 wxSize point
= GetClientSize() ;
1884 wxPoint origin
= GetClientAreaOrigin() ;
1886 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1887 SectRgn( newupdate
, ownUpdateRgn
, newupdate
) ;
1888 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1889 m_updateRegion
= newupdate
;
1890 DisposeRgn( newupdate
) ;
1895 event
.m_timeStamp
= time
;
1896 event
.SetEventObject(this);
1897 GetEventHandler()->ProcessEvent(event
);
1901 RgnHandle childupdate
= NewRgn() ;
1903 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1905 wxWindow
*child
= (wxWindow
*)node
->Data();
1906 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1907 SectRgn( childupdate
, updatergn
, childupdate
) ;
1908 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1909 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1911 // because dialogs may also be children
1912 child
->MacRedraw( childupdate
, time
) ;
1915 DisposeRgn( childupdate
) ;
1916 // eventually a draw grow box here
1919 void wxWindow::MacUpdateImmediately()
1921 WindowRef window
= GetMacRootWindow() ;
1924 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1926 AGAPortHelper
help( GetWindowPort(window
) ) ;
1928 AGAPortHelper
help( (window
) ) ;
1930 SetOrigin( 0 , 0 ) ;
1931 BeginUpdate( window
) ;
1934 RgnHandle region
= NewRgn();
1938 GetPortVisibleRegion( GetWindowPort( window
), region
);
1940 // if windowshade gives incompatibility , take the follwing out
1941 if ( !EmptyRgn( region
) )
1943 win
->MacRedraw( region
, wxTheApp
->sm_lastMessageTime
) ;
1945 DisposeRgn( region
);
1948 EndUpdate( window
) ;
1952 void wxWindow::MacUpdate( EventRecord
*ev
)
1954 WindowRef window
= (WindowRef
) ev
->message
;
1955 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1957 AGAPortHelper
help( GetWindowPort(window
) ) ;
1959 AGAPortHelper
help( (window
) ) ;
1961 SetOrigin( 0 , 0 ) ;
1962 BeginUpdate( window
) ;
1965 RgnHandle region
= NewRgn();
1969 GetPortVisibleRegion( GetWindowPort( window
), region
);
1971 // if windowshade gives incompatibility , take the follwing out
1972 if ( !EmptyRgn( region
) )
1974 MacRedraw( region
, ev
->when
) ;
1976 DisposeRgn( region
);
1979 EndUpdate( window
) ;
1982 WindowRef
wxWindow::GetMacRootWindow() const
1984 WindowRef window
= NULL
;
1985 wxWindow
*iter
= (wxWindow
*)this ;
1989 if ( iter
->m_macWindowData
)
1990 return iter
->m_macWindowData
->m_macWindow
;
1992 iter
= iter
->GetParent() ;
1994 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1998 void wxWindow::MacCreateScrollBars( long style
)
2000 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
2002 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2003 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2005 GetClientSize( &width
, &height
) ;
2007 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2008 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2009 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2010 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2012 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2013 vSize
, wxVERTICAL
);
2015 if ( style
& wxVSCROLL
)
2021 m_vScrollBar
->Show(false) ;
2023 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2024 hSize
, wxHORIZONTAL
);
2025 if ( style
& wxHSCROLL
)
2030 m_hScrollBar
->Show(false) ;
2033 // because the create does not take into account the client area origin
2034 MacRepositionScrollBars() ; // we might have a real position shift
2037 void wxWindow::MacRepositionScrollBars()
2039 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2040 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2042 // get real client area
2044 int width
= m_width
;
2045 int height
= m_height
;
2047 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2048 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2050 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2051 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2052 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2053 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2060 MacClientToRootWindow( &x
, &y
) ;
2061 MacClientToRootWindow( &w
, &h
) ;
2063 WindowRef window
= NULL
;
2064 wxWindow
*iter
= (wxWindow
*)this ;
2066 int totW
= 10000 , totH
= 10000;
2069 if ( iter
->m_macWindowData
)
2071 totW
= iter
->m_width
;
2072 totH
= iter
->m_height
;
2076 iter
= iter
->GetParent() ;
2104 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2108 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2112 void wxWindow::MacKeyDown( EventRecord
*ev
)
2118 bool wxWindow::AcceptsFocus() const
2120 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2123 ControlHandle
wxWindow::MacGetContainerForEmbedding()
2125 if ( m_macWindowData
)
2126 return m_macWindowData
->m_macRootControl
;
2128 return GetParent()->MacGetContainerForEmbedding() ;
2131 void wxWindow::MacSuperChangedPosition()
2133 // only window-absolute structures have to be moved i.e. controls
2135 wxNode
*node
= GetChildren().First();
2138 wxWindow
*child
= (wxWindow
*)node
->Data();
2139 child
->MacSuperChangedPosition() ;
2140 node
= node
->Next();
2144 bool wxWindow::MacSetPortFocusParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
2146 if ( window
== NULL
)
2152 ::GetPort(&currPort
);
2153 port
= UMAGetWindowPort( window
) ;
2154 if (currPort
!= port
)
2157 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2158 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2162 bool wxWindow::MacSetPortDrawingParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
2164 if ( window
== NULL
)
2169 ::GetPort(&currPort
);
2170 port
= UMAGetWindowPort( window
) ;
2171 if (currPort
!= port
)
2173 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2174 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2175 ::ClipRect(&clipRect
);
2178 ::RGBBackColor(& win
->GetBackgroundColour().GetPixel() ) ;
2179 ::RGBForeColor(& win
->GetForegroundColour().GetPixel() ) ;
2180 Pattern whiteColor
;
2182 ::BackPat( GetQDGlobalsWhite( &whiteColor
) ) ;
2183 ::UMASetThemeWindowBackground( win
->m_macWindowData
->m_macWindow
, win
->m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
2187 void wxWindow::MacGetPortParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2189 if ( m_macWindowData
)
2195 clipRect
->right
= m_width
;
2196 clipRect
->bottom
= m_height
;
2197 *window
= m_macWindowData
->m_macWindow
;
2202 wxASSERT( GetParent() != NULL
) ;
2203 GetParent()->MacGetPortParams( localOrigin
, clipRect
, window
, rootwin
) ;
2204 localOrigin
->h
+= m_x
;
2205 localOrigin
->v
+= m_y
;
2206 OffsetRect(clipRect
, -m_x
, -m_y
);
2211 myClip
.right
= m_width
;
2212 myClip
.bottom
= m_height
;
2213 SectRect(clipRect
, &myClip
, clipRect
);
2217 void wxWindow::MacDoGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2219 // int width , height ;
2220 // GetClientSize( &width , &height ) ;
2222 if ( m_macWindowData
)
2228 clipRect
->right
= m_width
;//width;
2229 clipRect
->bottom
= m_height
;// height;
2230 *window
= m_macWindowData
->m_macWindow
;
2235 wxASSERT( GetParent() != NULL
) ;
2237 GetParent()->MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2239 localOrigin
->h
+= m_x
;
2240 localOrigin
->v
+= m_y
;
2241 OffsetRect(clipRect
, -m_x
, -m_y
);
2246 myClip
.right
= m_width
;//width;
2247 myClip
.bottom
= m_height
;// height;
2248 SectRect(clipRect
, &myClip
, clipRect
);
2252 void wxWindow::MacGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2254 MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2256 int width
, height
;
2257 GetClientSize( &width
, &height
) ;
2259 client
= GetClientAreaOrigin( ) ;
2261 localOrigin
->h
+= client
.x
;
2262 localOrigin
->v
+= client
.y
;
2263 OffsetRect(clipRect
, -client
.x
, -client
.y
);
2268 myClip
.right
= width
;
2269 myClip
.bottom
= height
;
2270 SectRect(clipRect
, &myClip
, clipRect
);
2273 long wxWindow::MacGetLeftBorderSize( ) const
2275 if( m_macWindowData
)
2278 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2282 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2286 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2293 long wxWindow::MacGetRightBorderSize( ) const
2295 if( m_macWindowData
)
2298 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2302 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2306 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2313 long wxWindow::MacGetTopBorderSize( ) const
2315 if( m_macWindowData
)
2318 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2322 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2326 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2333 long wxWindow::MacGetBottomBorderSize( ) const
2335 if( m_macWindowData
)
2338 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2342 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2346 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2353 long wxWindow::MacRemoveBordersFromStyle( long style
)
2355 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2359 wxMacDrawingHelper::wxMacDrawingHelper( wxWindow
* theWindow
)
2366 m_currentPort
= NULL
;
2368 GetPort( &m_formerPort
) ;
2371 theWindow
->MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2372 m_currentPort
= UMAGetWindowPort( window
) ;
2373 if ( m_formerPort
!= m_currentPort
)
2374 SetPort( m_currentPort
) ;
2375 GetPenState( &m_savedPenState
) ;
2376 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2381 wxMacDrawingHelper::~wxMacDrawingHelper()
2385 SetPort( m_currentPort
) ;
2386 SetPenState( &m_savedPenState
) ;
2387 SetOrigin( 0 , 0 ) ;
2389 GetPortBounds( m_currentPort
, &portRect
) ;
2390 ClipRect( &portRect
) ;
2393 if ( m_formerPort
!= m_currentPort
)
2394 SetPort( m_formerPort
) ;
2397 wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindow
* theWindow
)
2404 m_currentPort
= NULL
;
2406 GetPort( &m_formerPort
) ;
2410 theWindow
->MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2411 m_currentPort
= UMAGetWindowPort( window
) ;
2412 if ( m_formerPort
!= m_currentPort
)
2413 SetPort( m_currentPort
) ;
2414 GetPenState( &m_savedPenState
) ;
2415 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2420 wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
2424 SetPort( m_currentPort
) ;
2425 SetPenState( &m_savedPenState
) ;
2426 SetOrigin( 0 , 0 ) ;
2428 GetPortBounds( m_currentPort
, &portRect
) ;
2429 ClipRect( &portRect
) ;
2432 if ( m_formerPort
!= m_currentPort
)
2433 SetPort( m_formerPort
) ;
2436 // Find the wxWindow at the current mouse position, returning the mouse
2438 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
2440 pt
= wxGetMousePosition();
2441 wxWindow
* found
= wxFindWindowAtPoint(pt
);
2445 // Get the current mouse position.
2446 wxPoint
wxGetMousePosition()
2449 wxGetMousePosition(& x
, & y
);
2450 return wxPoint(x
, y
);