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 // this will be done by the activate event
760 MacUpdateImmediately() ;
765 void wxWindow::MacSuperShown( bool show
)
767 wxNode
*node
= GetChildren().First();
770 wxWindow
*child
= (wxWindow
*)node
->Data();
771 if ( child
->m_isShown
)
772 child
->MacSuperShown( show
) ;
777 bool wxWindow::MacIsReallyShown() const
779 if ( m_isShown
&& (m_parent
!= NULL
) ) {
780 return m_parent
->MacIsReallyShown();
784 bool status = m_isShown ;
785 wxWindow * win = this ;
786 while ( status && win->m_parent != NULL )
788 win = win->m_parent ;
789 status = win->m_isShown ;
795 int wxWindow::GetCharHeight() const
797 wxClientDC
dc ( (wxWindow
*)this ) ;
798 return dc
.GetCharHeight() ;
801 int wxWindow::GetCharWidth() const
803 wxClientDC
dc ( (wxWindow
*)this ) ;
804 return dc
.GetCharWidth() ;
807 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
808 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
810 const wxFont
*fontToUse
= theFont
;
814 wxClientDC
dc( (wxWindow
*) this ) ;
816 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
817 if ( externalLeading
)
818 *externalLeading
= le
;
827 void wxWindow::MacEraseBackground( Rect
*rect
)
830 WindowRef window = GetMacRootWindow() ;
831 if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
833 UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ;
835 else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
837 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
838 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
839 // either a non gray background color or a non control window
841 wxWindow* parent = GetParent() ;
844 if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
846 // if we have any other colours in the hierarchy
847 RGBBackColor( &parent->m_backgroundColour.GetPixel()) ;
850 if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() )
852 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
853 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
855 UMAApplyThemeBackground(kThemeBackgroundTabPane, rect, kThemeStateActive,8,true);
861 // we have arrived at a non control item
865 parent = parent->GetParent() ;
869 // if there is nothing special -> use default
870 UMASetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ;
875 RGBBackColor( &m_backgroundColour.GetPixel()) ;
880 for (wxNode *node = GetChildren().First(); node; node = node->Next())
882 wxWindow *child = (wxWindow*)node->Data();
884 Rect clientrect = { child->m_x , child->m_y , child->m_x +child->m_width , child->m_y + child->m_height } ;
885 SectRect( &clientrect , rect , &clientrect ) ;
887 OffsetRect( &clientrect , -child->m_x , -child->m_y ) ;
888 if ( child->GetMacRootWindow() == window && child->IsShown() )
890 wxMacDrawingClientHelper focus( this ) ;
893 child->MacEraseBackground( &clientrect ) ;
900 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
902 wxMacDrawingHelper
focus( this ) ;
905 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
906 ClipRect( &clientrect
) ;
910 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
911 SectRect( &clientrect
, &r
, &clientrect
) ;
913 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
916 m_macEraseOnRedraw
= false ;
918 m_macEraseOnRedraw
= true ;
921 // Responds to colour changes: passes event on to children.
922 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
924 wxNode
*node
= GetChildren().First();
927 // Only propagate to non-top-level windows
928 wxWindow
*win
= (wxWindow
*)node
->Data();
929 if ( win
->GetParent() )
931 wxSysColourChangedEvent event2
;
932 event
.m_eventObject
= win
;
933 win
->GetEventHandler()->ProcessEvent(event2
);
940 #if wxUSE_CARET && WXWIN_COMPATIBILITY
941 // ---------------------------------------------------------------------------
942 // Caret manipulation
943 // ---------------------------------------------------------------------------
945 void wxWindow::CreateCaret(int w
, int h
)
947 SetCaret(new wxCaret(this, w
, h
));
950 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
952 wxFAIL_MSG("not implemented");
955 void wxWindow::ShowCaret(bool show
)
957 wxCHECK_RET( m_caret
, "no caret to show" );
962 void wxWindow::DestroyCaret()
967 void wxWindow::SetCaretPos(int x
, int y
)
969 wxCHECK_RET( m_caret
, "no caret to move" );
974 void wxWindow::GetCaretPos(int *x
, int *y
) const
976 wxCHECK_RET( m_caret
, "no caret to get position of" );
978 m_caret
->GetPosition(x
, y
);
980 #endif // wxUSE_CARET
982 wxWindow
*wxGetActiveWindow()
984 // actually this is a windows-only concept
988 // Coordinates relative to the window
989 void wxWindow::WarpPointer (int x_pos
, int y_pos
)
991 // We really dont move the mouse programmatically under mac
994 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
996 // TODO : probably we would adopt the EraseEvent structure
999 int wxWindow::GetScrollPos(int orient
) const
1001 if ( orient
== wxHORIZONTAL
)
1004 return m_hScrollBar
->GetThumbPosition() ;
1009 return m_vScrollBar
->GetThumbPosition() ;
1014 // This now returns the whole range, not just the number
1015 // of positions that we can scroll.
1016 int wxWindow::GetScrollRange(int orient
) const
1018 if ( orient
== wxHORIZONTAL
)
1021 return m_hScrollBar
->GetRange() ;
1026 return m_vScrollBar
->GetRange() ;
1031 int wxWindow::GetScrollThumb(int orient
) const
1033 if ( orient
== wxHORIZONTAL
)
1036 return m_hScrollBar
->GetThumbSize() ;
1041 return m_vScrollBar
->GetThumbSize() ;
1046 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
1048 if ( orient
== wxHORIZONTAL
)
1051 m_hScrollBar
->SetThumbPosition( pos
) ;
1056 m_vScrollBar
->SetThumbPosition( pos
) ;
1060 void wxWindow::MacCreateRealWindow( const wxString
& title
,
1064 const wxString
& name
)
1067 m_windowStyle
= style
;
1088 m_macWindowData
= new MacWindowData() ;
1090 ::SetRect(&theBoundsRect
, m_x
, m_y
, m_x
+ m_width
, m_y
+ m_height
);
1092 // translate the window attributes in the appropriate window class and attributes
1094 WindowClass wclass
= 0;
1095 WindowAttributes attr
= kWindowNoAttributes
;
1097 if ( HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
) )
1099 wclass
= kFloatingWindowClass
;
1100 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1102 attr
|= kWindowSideTitlebarAttribute
;
1105 else if ( HasFlag( wxCAPTION
) )
1107 if ( HasFlag( wxDIALOG_MODAL
) )
1109 wclass
= kMovableModalWindowClass
;
1113 wclass
= kDocumentWindowClass
;
1118 wclass
= kModalWindowClass
;
1121 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) )
1123 attr
|= kWindowFullZoomAttribute
;
1124 attr
|= kWindowCollapseBoxAttribute
;
1126 if ( HasFlag( wxRESIZE_BORDER
) )
1128 attr
|= kWindowResizableAttribute
;
1130 if ( HasFlag( wxSYSTEM_MENU
) )
1132 attr
|= kWindowCloseBoxAttribute
;
1135 UMACreateNewWindow( wclass
, attr
, &theBoundsRect
, &m_macWindowData
->m_macWindow
) ;
1136 wxAssociateWinWithMacWindow( m_macWindowData
->m_macWindow
, this ) ;
1138 if( wxApp::s_macDefaultEncodingIsPC
)
1139 label
= wxMacMakeMacStringFromPC( title
) ;
1142 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
1143 UMACreateRootControl( m_macWindowData
->m_macWindow
, &m_macWindowData
->m_macRootControl
) ;
1145 m_macWindowData
->m_macFocus
= NULL
;
1148 void wxWindow::MacPaint( wxPaintEvent
&event
)
1152 void wxWindow::MacPaintBorders( )
1154 if( m_macWindowData
)
1157 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1158 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1159 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1160 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1163 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1165 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1166 RGBColor pen1
= sunken
? white
: black
;
1167 RGBColor pen2
= sunken
? shadow
: face
;
1168 RGBColor pen3
= sunken
? face
: shadow
;
1169 RGBColor pen4
= sunken
? black
: white
;
1171 RGBForeColor( &pen1
) ;
1173 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1174 FrameRect( &rect
) ;
1176 RGBForeColor( &pen2
) ;
1178 Rect rect
= { 1 , 1 , m_height
-1 , m_width
-1} ;
1179 FrameRect( &rect
) ;
1181 RGBForeColor( &pen3
) ;
1183 Rect rect
= { 0 , 0 , m_height
-2 , m_width
-2} ;
1184 FrameRect( &rect
) ;
1186 RGBForeColor( &pen4
) ;
1189 LineTo( m_width
- 3 , 0 ) ;
1191 LineTo( 0 , m_height
- 3 ) ;
1194 else if (HasFlag(wxSIMPLE_BORDER
))
1196 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1197 RGBForeColor( &black
) ;
1198 FrameRect( &rect
) ;
1201 if ( this->GetParent() )
1203 wxPaintDC dc(GetParent());
1204 GetParent()->PrepareDC(dc);
1206 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) )
1208 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1210 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1211 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1213 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1214 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1215 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1216 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1219 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1222 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1225 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1228 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1229 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1231 else if (HasFlag(wxDOUBLE_BORDER))
1233 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1235 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1236 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1238 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1239 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1240 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1241 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1244 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1247 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1250 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1253 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1254 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1256 else if (HasFlag(wxSIMPLE_BORDER))
1258 dc.SetPen(*wxBLACK_PEN);
1259 dc.DrawRectangle(m_x, m_y, m_width, m_height);
1265 // New function that will replace some of the above.
1266 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1267 int range
, bool refresh
)
1269 if ( orient
== wxHORIZONTAL
)
1273 if ( range
== 0 || thumbVisible
>= range
)
1275 if ( m_hScrollBar
->IsShown() )
1276 m_hScrollBar
->Show(false) ;
1280 if ( !m_hScrollBar
->IsShown() )
1281 m_hScrollBar
->Show(true) ;
1282 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1290 if ( range
== 0 || thumbVisible
>= range
)
1292 if ( m_vScrollBar
->IsShown() )
1293 m_vScrollBar
->Show(false) ;
1297 if ( !m_vScrollBar
->IsShown() )
1298 m_vScrollBar
->Show(true) ;
1299 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1303 MacRepositionScrollBars() ;
1306 // Does a physical scroll
1307 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1309 wxMacDrawingClientHelper
focus( this ) ;
1312 int width
, height
;
1313 GetClientSize( &width
, &height
) ;
1315 Rect scrollrect
= { 0 , 0 , height
, width
} ;
1317 RgnHandle updateRgn
= NewRgn() ;
1318 ClipRect( &scrollrect
) ;
1321 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
1322 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1324 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1325 InvalWindowRgn( GetMacRootWindow() , updateRgn
) ;
1326 DisposeRgn( updateRgn
) ;
1329 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1331 wxWindow
*child
= (wxWindow
*)node
->Data();
1332 if (child
== m_vScrollBar
) continue;
1333 if (child
== m_hScrollBar
) continue;
1334 if (child
->IsTopLevel()) continue;
1336 child
->GetPosition( &x
, &y
);
1338 child
->GetSize( &w
, &h
);
1339 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1344 void wxWindow::MacOnScroll(wxScrollEvent
&event
)
1346 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1348 wxScrollWinEvent wevent
;
1349 wevent
.SetPosition(event
.GetPosition());
1350 wevent
.SetOrientation(event
.GetOrientation());
1351 wevent
.m_eventObject
= this;
1353 if (event
.m_eventType
== wxEVT_SCROLL_TOP
) {
1354 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1356 if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
) {
1357 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1359 if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
) {
1360 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1362 if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
) {
1363 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1365 if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
) {
1366 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1368 if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
) {
1369 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1371 if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
) {
1372 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1375 GetEventHandler()->ProcessEvent(wevent
);
1379 bool wxWindow::SetFont(const wxFont
& font
)
1381 if ( !wxWindowBase::SetFont(font
) )
1390 // Get the window with the focus
1391 wxWindow
*wxWindowBase::FindFocus()
1393 return gFocusWindow
;
1396 #if WXWIN_COMPATIBILITY
1397 // If nothing defined for this, try the parent.
1398 // E.g. we may be a button loaded from a resource, with no callback function
1400 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1402 if ( GetEventHandler()->ProcessEvent(event
) )
1405 m_parent
->GetEventHandler()->OnCommand(win
, event
);
1407 #endif // WXWIN_COMPATIBILITY_2
1409 #if WXWIN_COMPATIBILITY
1410 wxObject
* wxWindow::GetChild(int number
) const
1412 // Return a pointer to the Nth object in the Panel
1413 wxNode
*node
= GetChildren().First();
1416 node
= node
->Next();
1419 wxObject
*obj
= (wxObject
*)node
->Data();
1425 #endif // WXWIN_COMPATIBILITY
1427 void wxWindow::OnSetFocus(wxFocusEvent
& event
)
1429 // panel wants to track the window which was the last to have focus in it,
1430 // so we want to set ourselves as the window which last had focus
1432 // notice that it's also important to do it upwards the tree becaus
1433 // otherwise when the top level panel gets focus, it won't set it back to
1434 // us, but to some other sibling
1435 wxWindow
*win
= this;
1438 wxWindow
*parent
= win
->GetParent();
1439 wxPanel
*panel
= wxDynamicCast(parent
, wxPanel
);
1442 panel
->SetLastFocus(win
);
1451 void wxWindow::Clear()
1453 if ( m_macWindowData
)
1455 wxMacDrawingClientHelper
helper ( this ) ;
1457 wxPoint origin
= GetClientAreaOrigin() ;
1458 GetClientSize( &w
, &h
) ;
1459 UMASetThemeWindowBackground( m_macWindowData
->m_macWindow
, m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
1460 Rect r
= { origin
.y
, origin
.x
, origin
.y
+h
, origin
.x
+w
} ;
1465 wxClientDC
dc(this);
1466 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1467 dc
.SetBackground(brush
);
1472 // Setup background and foreground colours correctly
1473 void wxWindow::SetupColours()
1476 SetBackgroundColour(GetParent()->GetBackgroundColour());
1479 void wxWindow::OnIdle(wxIdleEvent
& event
)
1482 // Check if we need to send a LEAVE event
1483 if (m_mouseInWindow)
1486 ::GetCursorPos(&pt);
1487 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1489 // Generate a LEAVE event
1490 m_mouseInWindow = FALSE;
1491 MSWOnMouseLeave(pt.x, pt.y, 0);
1496 // This calls the UI-update mechanism (querying windows for
1497 // menu/toolbar/control state information)
1501 // Raise the window to the top of the Z order
1502 void wxWindow::Raise()
1507 // Lower the window to the bottom of the Z order
1508 void wxWindow::Lower()
1513 void wxWindow::DoSetClientSize(int width
, int height
)
1515 if ( width
!= -1 || height
!= -1 )
1518 if ( width
!= -1 && m_vScrollBar
)
1519 width
+= MAC_SCROLLBAR_SIZE
;
1520 if ( height
!= -1 && m_vScrollBar
)
1521 height
+= MAC_SCROLLBAR_SIZE
;
1523 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1524 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1526 DoSetSize( -1 , -1 , width
, height
) ;
1531 wxWindow
* wxWindow::s_lastMouseWindow
= NULL
;
1533 bool wxWindow::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindow
** outWin
)
1535 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1536 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1539 WindowRef window
= GetMacRootWindow() ;
1541 wxPoint
newPoint( point
) ;
1546 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1548 wxWindow
*child
= (wxWindow
*)node
->Data();
1549 // added the m_isShown test --dmazzoni
1550 if ( child
->GetMacRootWindow() == window
&& child
->m_isShown
)
1552 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1561 bool wxWindow::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindow
** outWin
)
1564 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1565 if ( ::FindWindow( pt
, &window
) == 3 )
1567 wxPoint
point( screenpoint
) ;
1568 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1571 win
->ScreenToClient( point
) ;
1572 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1578 extern int wxBusyCursorCount
;
1580 bool wxWindow::MacDispatchMouseEvent(wxMouseEvent
& event
)
1582 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1583 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1587 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) )
1590 WindowRef window
= GetMacRootWindow() ;
1598 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1600 wxWindow
*child
= (wxWindow
*)node
->Data();
1601 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1603 if (child
->MacDispatchMouseEvent(event
))
1611 if ( wxBusyCursorCount
== 0 )
1613 m_cursor
.MacInstall() ;
1616 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1618 // set focus to this window
1619 if (AcceptsFocus() && FindFocus()!=this)
1624 if ( event
.GetEventType() == wxEVT_MOTION
1625 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1626 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1627 wxToolTip::RelayEvent( this , event
);
1628 #endif // wxUSE_TOOLTIPS
1629 GetEventHandler()->ProcessEvent( event
) ;
1636 wxString
wxWindow::MacGetToolTipString( wxPoint
&pt
)
1640 return m_tooltip
->GetTip() ;
1644 void wxWindow::MacFireMouseEvent( EventRecord
*ev
)
1646 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
1647 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1648 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1650 event
.m_leftDown
= isDown
&& !controlDown
;
1651 event
.m_middleDown
= FALSE
;
1652 event
.m_rightDown
= isDown
&& controlDown
;
1654 if ( ev
->what
== mouseDown
)
1657 event
.SetEventType(wxEVT_RIGHT_DOWN
) ;
1659 event
.SetEventType(wxEVT_LEFT_DOWN
) ;
1661 else if ( ev
->what
== mouseUp
)
1664 event
.SetEventType(wxEVT_RIGHT_UP
) ;
1666 event
.SetEventType(wxEVT_LEFT_UP
) ;
1670 event
.SetEventType(wxEVT_MOTION
) ;
1673 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1674 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1675 event
.m_altDown
= ev
->modifiers
& optionKey
;
1676 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1678 Point localwhere
= ev
->where
;
1681 ::GetPort( &port
) ;
1682 ::SetPort( UMAGetWindowPort( m_macWindowData
->m_macWindow
) ) ;
1683 ::GlobalToLocal( &localwhere
) ;
1686 if ( ev
->what
== mouseDown
)
1688 if ( ev
->when
- lastWhen
<= GetDblTime() )
1690 if ( abs( localwhere
.h
- lastWhere
.h
) < 3 || abs( localwhere
.v
- lastWhere
.v
) < 3 )
1693 event
.SetEventType(wxEVT_RIGHT_DCLICK
) ;
1695 event
.SetEventType(wxEVT_LEFT_DCLICK
) ;
1698 lastWhen
= ev
->when
;
1699 lastWhere
= localwhere
;
1702 event
.m_x
= localwhere
.h
;
1703 event
.m_y
= localwhere
.v
;
1708 wxPoint origin = GetClientAreaOrigin() ;
1710 event.m_x += origin.x ;
1711 event.m_y += origin.y ;
1714 event
.m_timeStamp
= ev
->when
;
1715 event
.SetEventObject(this);
1716 if ( wxTheApp
->s_captureWindow
)
1720 wxTheApp
->s_captureWindow
->ScreenToClient( &x
, &y
) ;
1723 wxTheApp
->s_captureWindow
->GetEventHandler()->ProcessEvent( event
) ;
1724 if ( ev
->what
== mouseUp
)
1726 wxTheApp
->s_captureWindow
= NULL
;
1727 if ( wxBusyCursorCount
== 0 )
1729 m_cursor
.MacInstall() ;
1735 MacDispatchMouseEvent( event
) ;
1739 void wxWindow::MacMouseDown( EventRecord
*ev
, short part
)
1741 MacFireMouseEvent( ev
) ;
1744 void wxWindow::MacMouseUp( EventRecord
*ev
, short part
)
1746 WindowPtr frontWindow
;
1751 MacFireMouseEvent( ev
) ;
1757 void wxWindow::MacMouseMoved( EventRecord
*ev
, short part
)
1759 WindowPtr frontWindow
;
1764 MacFireMouseEvent( ev
) ;
1769 void wxWindow::MacActivate( EventRecord
*ev
, bool inIsActivating
)
1771 wxActivateEvent
event(wxEVT_ACTIVATE
, inIsActivating
, m_windowId
);
1772 event
.m_timeStamp
= ev
->when
;
1773 event
.SetEventObject(this);
1775 GetEventHandler()->ProcessEvent(event
);
1777 UMAHighlightAndActivateWindow( m_macWindowData
->m_macWindow
, inIsActivating
) ;
1779 MacUpdateImmediately() ;
1782 void wxWindow::MacRedraw( RgnHandle updatergn
, long time
)
1784 // updatergn is always already clipped to our boundaries
1785 WindowRef window
= GetMacRootWindow() ;
1786 // ownUpdateRgn is the area that this window has to invalidate i.e. its own area without its children
1787 RgnHandle ownUpdateRgn
= NewRgn() ;
1788 CopyRgn( updatergn
, ownUpdateRgn
) ;
1789 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1791 wxMacDrawingHelper
focus( this ) ; // was client
1794 WindowRef window
= GetMacRootWindow() ;
1795 bool eraseBackground
= false ;
1796 if ( m_macWindowData
)
1797 eraseBackground
= true ;
1798 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
1800 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
1802 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1804 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1805 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1806 // either a non gray background color or a non control window
1809 wxWindow
* parent
= GetParent() ;
1812 if ( parent
->GetMacRootWindow() != window
)
1814 // we are in a different window on the mac system
1819 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
1821 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1823 // if we have any other colours in the hierarchy
1824 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
1827 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1828 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
1831 GetRegionBounds( updatergn
, &box
) ;
1832 UMAApplyThemeBackground(kThemeBackgroundTabPane
, &box
, kThemeStateActive
,8,true);
1841 parent
= parent
->GetParent() ;
1845 // if there is nothing special -> use default
1846 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
1851 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
1853 // subtract all non transparent children from updatergn
1855 RgnHandle childarea
= NewRgn() ;
1856 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1858 wxWindow
*child
= (wxWindow
*)node
->Data();
1859 // eventually test for transparent windows
1860 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() )
1862 if ( !child
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)child
)->GetMacControl() )
1864 SetRectRgn( childarea
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1865 DiffRgn( ownUpdateRgn
, childarea
, ownUpdateRgn
) ;
1869 DisposeRgn( childarea
) ;
1871 if ( GetParent() && m_backgroundColour
!= GetParent()->GetBackgroundColour() )
1872 eraseBackground
= true ;
1873 SetClip( ownUpdateRgn
) ;
1874 if ( m_macEraseOnRedraw
) {
1875 if ( eraseBackground
)
1877 EraseRgn( ownUpdateRgn
) ;
1881 m_macEraseOnRedraw
= true ;
1886 RgnHandle newupdate
= NewRgn() ;
1887 wxSize point
= GetClientSize() ;
1888 wxPoint origin
= GetClientAreaOrigin() ;
1890 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1891 SectRgn( newupdate
, ownUpdateRgn
, newupdate
) ;
1892 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1893 m_updateRegion
= newupdate
;
1894 DisposeRgn( newupdate
) ;
1899 event
.m_timeStamp
= time
;
1900 event
.SetEventObject(this);
1901 GetEventHandler()->ProcessEvent(event
);
1905 RgnHandle childupdate
= NewRgn() ;
1907 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1909 wxWindow
*child
= (wxWindow
*)node
->Data();
1910 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1911 SectRgn( childupdate
, updatergn
, childupdate
) ;
1912 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1913 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1915 // because dialogs may also be children
1916 child
->MacRedraw( childupdate
, time
) ;
1919 DisposeRgn( childupdate
) ;
1920 // eventually a draw grow box here
1923 void wxWindow::MacUpdateImmediately()
1925 WindowRef window
= GetMacRootWindow() ;
1928 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1930 AGAPortHelper
help( GetWindowPort(window
) ) ;
1932 AGAPortHelper
help( (window
) ) ;
1934 SetOrigin( 0 , 0 ) ;
1935 BeginUpdate( window
) ;
1938 RgnHandle region
= NewRgn();
1942 GetPortVisibleRegion( GetWindowPort( window
), region
);
1944 // if windowshade gives incompatibility , take the follwing out
1945 if ( !EmptyRgn( region
) )
1947 win
->MacRedraw( region
, wxTheApp
->sm_lastMessageTime
) ;
1949 DisposeRgn( region
);
1952 EndUpdate( window
) ;
1956 void wxWindow::MacUpdate( EventRecord
*ev
)
1958 WindowRef window
= (WindowRef
) ev
->message
;
1959 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1961 AGAPortHelper
help( GetWindowPort(window
) ) ;
1963 AGAPortHelper
help( (window
) ) ;
1965 SetOrigin( 0 , 0 ) ;
1966 BeginUpdate( window
) ;
1969 RgnHandle region
= NewRgn();
1973 GetPortVisibleRegion( GetWindowPort( window
), region
);
1975 // if windowshade gives incompatibility , take the follwing out
1976 if ( !EmptyRgn( region
) )
1978 MacRedraw( region
, ev
->when
) ;
1980 DisposeRgn( region
);
1983 EndUpdate( window
) ;
1986 WindowRef
wxWindow::GetMacRootWindow() const
1988 WindowRef window
= NULL
;
1989 wxWindow
*iter
= (wxWindow
*)this ;
1993 if ( iter
->m_macWindowData
)
1994 return iter
->m_macWindowData
->m_macWindow
;
1996 iter
= iter
->GetParent() ;
1998 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
2002 void wxWindow::MacCreateScrollBars( long style
)
2004 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
2006 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2007 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2009 GetClientSize( &width
, &height
) ;
2011 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2012 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2013 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2014 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2016 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2017 vSize
, wxVERTICAL
);
2019 if ( style
& wxVSCROLL
)
2025 m_vScrollBar
->Show(false) ;
2027 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2028 hSize
, wxHORIZONTAL
);
2029 if ( style
& wxHSCROLL
)
2034 m_hScrollBar
->Show(false) ;
2037 // because the create does not take into account the client area origin
2038 MacRepositionScrollBars() ; // we might have a real position shift
2041 void wxWindow::MacRepositionScrollBars()
2043 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2044 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2046 // get real client area
2048 int width
= m_width
;
2049 int height
= m_height
;
2051 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2052 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2054 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2055 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2056 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2057 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2064 MacClientToRootWindow( &x
, &y
) ;
2065 MacClientToRootWindow( &w
, &h
) ;
2067 WindowRef window
= NULL
;
2068 wxWindow
*iter
= (wxWindow
*)this ;
2070 int totW
= 10000 , totH
= 10000;
2073 if ( iter
->m_macWindowData
)
2075 totW
= iter
->m_width
;
2076 totH
= iter
->m_height
;
2080 iter
= iter
->GetParent() ;
2108 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2112 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2116 void wxWindow::MacKeyDown( EventRecord
*ev
)
2122 bool wxWindow::AcceptsFocus() const
2124 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2127 ControlHandle
wxWindow::MacGetContainerForEmbedding()
2129 if ( m_macWindowData
)
2130 return m_macWindowData
->m_macRootControl
;
2132 return GetParent()->MacGetContainerForEmbedding() ;
2135 void wxWindow::MacSuperChangedPosition()
2137 // only window-absolute structures have to be moved i.e. controls
2139 wxNode
*node
= GetChildren().First();
2142 wxWindow
*child
= (wxWindow
*)node
->Data();
2143 child
->MacSuperChangedPosition() ;
2144 node
= node
->Next();
2148 bool wxWindow::MacSetPortFocusParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
2150 if ( window
== NULL
)
2156 ::GetPort(&currPort
);
2157 port
= UMAGetWindowPort( window
) ;
2158 if (currPort
!= port
)
2161 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2162 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2166 bool wxWindow::MacSetPortDrawingParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
2168 if ( window
== NULL
)
2173 ::GetPort(&currPort
);
2174 port
= UMAGetWindowPort( window
) ;
2175 if (currPort
!= port
)
2177 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2178 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2179 ::ClipRect(&clipRect
);
2182 ::RGBBackColor(& win
->GetBackgroundColour().GetPixel() ) ;
2183 ::RGBForeColor(& win
->GetForegroundColour().GetPixel() ) ;
2184 Pattern whiteColor
;
2186 ::BackPat( GetQDGlobalsWhite( &whiteColor
) ) ;
2187 ::UMASetThemeWindowBackground( win
->m_macWindowData
->m_macWindow
, win
->m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
2191 void wxWindow::MacGetPortParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2193 if ( m_macWindowData
)
2199 clipRect
->right
= m_width
;
2200 clipRect
->bottom
= m_height
;
2201 *window
= m_macWindowData
->m_macWindow
;
2206 wxASSERT( GetParent() != NULL
) ;
2207 GetParent()->MacGetPortParams( localOrigin
, clipRect
, window
, rootwin
) ;
2208 localOrigin
->h
+= m_x
;
2209 localOrigin
->v
+= m_y
;
2210 OffsetRect(clipRect
, -m_x
, -m_y
);
2215 myClip
.right
= m_width
;
2216 myClip
.bottom
= m_height
;
2217 SectRect(clipRect
, &myClip
, clipRect
);
2221 void wxWindow::MacDoGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2223 // int width , height ;
2224 // GetClientSize( &width , &height ) ;
2226 if ( m_macWindowData
)
2232 clipRect
->right
= m_width
;//width;
2233 clipRect
->bottom
= m_height
;// height;
2234 *window
= m_macWindowData
->m_macWindow
;
2239 wxASSERT( GetParent() != NULL
) ;
2241 GetParent()->MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2243 localOrigin
->h
+= m_x
;
2244 localOrigin
->v
+= m_y
;
2245 OffsetRect(clipRect
, -m_x
, -m_y
);
2250 myClip
.right
= m_width
;//width;
2251 myClip
.bottom
= m_height
;// height;
2252 SectRect(clipRect
, &myClip
, clipRect
);
2256 void wxWindow::MacGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2258 MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2260 int width
, height
;
2261 GetClientSize( &width
, &height
) ;
2263 client
= GetClientAreaOrigin( ) ;
2265 localOrigin
->h
+= client
.x
;
2266 localOrigin
->v
+= client
.y
;
2267 OffsetRect(clipRect
, -client
.x
, -client
.y
);
2272 myClip
.right
= width
;
2273 myClip
.bottom
= height
;
2274 SectRect(clipRect
, &myClip
, clipRect
);
2277 long wxWindow::MacGetLeftBorderSize( ) const
2279 if( m_macWindowData
)
2282 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2286 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2290 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2297 long wxWindow::MacGetRightBorderSize( ) const
2299 if( m_macWindowData
)
2302 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2306 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2310 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2317 long wxWindow::MacGetTopBorderSize( ) const
2319 if( m_macWindowData
)
2322 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2326 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2330 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2337 long wxWindow::MacGetBottomBorderSize( ) const
2339 if( m_macWindowData
)
2342 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2346 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2350 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2357 long wxWindow::MacRemoveBordersFromStyle( long style
)
2359 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2363 wxMacDrawingHelper::wxMacDrawingHelper( wxWindow
* theWindow
)
2370 m_currentPort
= NULL
;
2372 GetPort( &m_formerPort
) ;
2375 theWindow
->MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2376 m_currentPort
= UMAGetWindowPort( window
) ;
2377 if ( m_formerPort
!= m_currentPort
)
2378 SetPort( m_currentPort
) ;
2379 GetPenState( &m_savedPenState
) ;
2380 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2385 wxMacDrawingHelper::~wxMacDrawingHelper()
2389 SetPort( m_currentPort
) ;
2390 SetPenState( &m_savedPenState
) ;
2391 SetOrigin( 0 , 0 ) ;
2393 GetPortBounds( m_currentPort
, &portRect
) ;
2394 ClipRect( &portRect
) ;
2397 if ( m_formerPort
!= m_currentPort
)
2398 SetPort( m_formerPort
) ;
2401 wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindow
* theWindow
)
2408 m_currentPort
= NULL
;
2410 GetPort( &m_formerPort
) ;
2414 theWindow
->MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2415 m_currentPort
= UMAGetWindowPort( window
) ;
2416 if ( m_formerPort
!= m_currentPort
)
2417 SetPort( m_currentPort
) ;
2418 GetPenState( &m_savedPenState
) ;
2419 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2424 wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
2428 SetPort( m_currentPort
) ;
2429 SetPenState( &m_savedPenState
) ;
2430 SetOrigin( 0 , 0 ) ;
2432 GetPortBounds( m_currentPort
, &portRect
) ;
2433 ClipRect( &portRect
) ;
2436 if ( m_formerPort
!= m_currentPort
)
2437 SetPort( m_formerPort
) ;
2440 // Find the wxWindow at the current mouse position, returning the mouse
2442 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
2444 pt
= wxGetMousePosition();
2445 wxWindow
* found
= wxFindWindowAtPoint(pt
);
2449 // Get the current mouse position.
2450 wxPoint
wxGetMousePosition()
2453 wxGetMousePosition(& x
, & y
);
2454 return wxPoint(x
, y
);