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 void wxWindow::Init()
117 m_doubleClickAllowed
= 0;
118 m_winCaptured
= FALSE
;
120 m_isBeingDeleted
= FALSE
;
123 m_mouseInWindow
= FALSE
;
127 m_backgroundTransparent
= FALSE
;
129 // as all windows are created with WS_VISIBLE style...
132 m_macWindowData
= NULL
;
139 m_hScrollBar
= NULL
;
140 m_vScrollBar
= NULL
;
142 #if wxUSE_DRAG_AND_DROP
143 m_pDropTarget
= NULL
;
148 wxWindow::~wxWindow()
150 m_isBeingDeleted
= TRUE
;
152 if ( s_lastMouseWindow
== this )
154 s_lastMouseWindow
= NULL
;
157 if ( gFocusWindow
== this )
159 gFocusWindow
= NULL
;
163 m_parent
->RemoveChild(this);
167 if ( m_macWindowData
)
169 wxToolTip::NotifyWindowDelete(m_macWindowData
->m_macWindow
) ;
170 UMADisposeWindow( m_macWindowData
->m_macWindow
) ;
171 delete m_macWindowData
;
172 wxRemoveMacWindowAssociation( this ) ;
177 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
181 const wxString
& name
)
183 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindow without parent") );
185 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
188 parent
->AddChild(this);
192 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
193 m_width
= WidthDefault( size
.x
);
194 m_height
= HeightDefault( size
.y
) ;
196 if ( ! IsKindOf( CLASSINFO ( wxControl
) ) && ! IsKindOf( CLASSINFO( wxStatusBar
) ) )
198 MacCreateScrollBars( style
) ;
204 void wxWindow::SetFocus()
206 if ( gFocusWindow
== this )
209 if ( AcceptsFocus() )
215 if ( gFocusWindow
->m_caret
)
217 gFocusWindow
->m_caret
->OnKillFocus();
219 #endif // wxUSE_CARET
220 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
221 if ( control
&& control
->GetMacControl() )
223 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlFocusNoPart
) ;
224 control
->MacRedrawControl() ;
226 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
227 event
.SetEventObject(gFocusWindow
);
228 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
230 gFocusWindow
= this ;
236 m_caret
->OnSetFocus();
238 #endif // wxUSE_CARET
239 // panel wants to track the window which was the last to have focus in it
240 wxPanel
*panel
= wxDynamicCast(GetParent(), wxPanel
);
243 panel
->SetLastFocus(this);
245 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
246 if ( control
&& control
->GetMacControl() )
248 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlEditTextPart
) ;
251 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
252 event
.SetEventObject(this);
253 GetEventHandler()->ProcessEvent(event
) ;
258 bool wxWindow::Enable(bool enable
)
260 if ( !wxWindowBase::Enable(enable
) )
263 wxWindowList::Node
*node
= GetChildren().GetFirst();
266 wxWindow
*child
= node
->GetData();
267 child
->Enable(enable
);
269 node
= node
->GetNext();
275 void wxWindow::CaptureMouse()
277 wxTheApp
->s_captureWindow
= this ;
280 void wxWindow::ReleaseMouse()
282 wxTheApp
->s_captureWindow
= NULL
;
285 #if wxUSE_DRAG_AND_DROP
287 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
289 if ( m_pDropTarget
!= 0 ) {
290 delete m_pDropTarget
;
293 m_pDropTarget
= pDropTarget
;
294 if ( m_pDropTarget
!= 0 )
302 // Old style file-manager drag&drop
303 void wxWindow::DragAcceptFiles(bool accept
)
309 void wxWindow::DoGetSize(int *x
, int *y
) const
315 void wxWindow::DoGetPosition(int *x
, int *y
) const
321 wxPoint
pt(GetParent()->GetClientAreaOrigin());
328 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
330 menu
->SetInvokingWindow(this);
332 ClientToScreen( &x
, &y
) ;
334 ::InsertMenu( menu
->GetHMenu() , -1 ) ;
335 long menuResult
= ::PopUpMenuSelect(menu
->GetHMenu() ,y
,x
, 0) ;
336 menu
->MacMenuSelect( this , TickCount() , HiWord(menuResult
) , LoWord(menuResult
) ) ;
337 ::DeleteMenu( menu
->MacGetMenuId() ) ;
338 menu
->SetInvokingWindow(NULL
);
343 void wxWindow::DoScreenToClient(int *x
, int *y
) const
345 WindowRef window
= GetMacRootWindow() ;
353 ::SetPort( UMAGetWindowPort( window
) ) ;
354 ::GlobalToLocal( &localwhere
) ;
360 MacRootWindowToClient( x
, y
) ;
363 void wxWindow::DoClientToScreen(int *x
, int *y
) const
365 WindowRef window
= GetMacRootWindow() ;
367 MacClientToRootWindow( x
, y
) ;
375 ::SetPort( UMAGetWindowPort( window
) ) ;
376 ::SetOrigin( 0 , 0 ) ;
377 ::LocalToGlobal( &localwhere
) ;
383 void wxWindow::MacClientToRootWindow( int *x
, int *y
) const
385 if ( m_macWindowData
)
392 GetParent()->MacClientToRootWindow( x
, y
) ;
396 void wxWindow::MacRootWindowToClient( int *x
, int *y
) const
398 if ( m_macWindowData
)
405 GetParent()->MacRootWindowToClient( x
, y
) ;
409 bool wxWindow::SetCursor(const wxCursor
& cursor
)
411 if ( !wxWindowBase::SetCursor(cursor
) )
417 wxASSERT_MSG( m_cursor
.Ok(),
418 wxT("cursor must be valid after call to the base version"));
424 // Change the cursor NOW if we're within the correct window
426 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
428 if ( mouseWin
== this && !wxIsBusy() )
430 cursor
.MacInstall() ;
438 // Get size *available for subwindows* i.e. excluding menu bar etc.
439 void wxWindow::DoGetClientSize(int *x
, int *y
) const
444 *x
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
445 *y
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
447 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
454 MacClientToRootWindow( &x1
, &y1
) ;
455 MacClientToRootWindow( &w
, &h
) ;
457 WindowRef window
= NULL
;
458 wxWindow
*iter
= (wxWindow
*)this ;
460 int totW
= 10000 , totH
= 10000;
463 if ( iter
->m_macWindowData
)
465 totW
= iter
->m_width
;
466 totH
= iter
->m_height
;
470 iter
= iter
->GetParent() ;
473 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
475 (*y
) -= MAC_SCROLLBAR_SIZE
;
481 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
483 (*x
) -= MAC_SCROLLBAR_SIZE
;
493 // ----------------------------------------------------------------------------
495 // ----------------------------------------------------------------------------
499 void wxWindow::DoSetToolTip(wxToolTip
*tooltip
)
501 wxWindowBase::DoSetToolTip(tooltip
);
504 m_tooltip
->SetWindow(this);
507 #endif // wxUSE_TOOLTIPS
509 void wxWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
511 DoSetSize( x
,y
, width
, height
) ;
514 // set the size of the window: if the dimensions are positive, just use them,
515 // but if any of them is equal to -1, it means that we must find the value for
516 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
517 // which case -1 is a valid value for x and y)
519 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
520 // the width/height to best suit our contents, otherwise we reuse the current
522 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
527 int former_w
= m_width
;
528 int former_h
= m_height
;
530 int currentX
, currentY
;
531 GetPosition(¤tX
, ¤tY
);
532 int currentW
,currentH
;
533 GetSize(¤tW
, ¤tH
);
535 int actualWidth
= width
;
536 int actualHeight
= height
;
539 if (x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
541 if (y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
544 wxSize
size( -1 , -1 ) ;
546 if (width
== -1 || height
== -1 )
548 size
= DoGetBestSize() ;
553 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
555 actualWidth
= size
.x
;
556 if ( actualWidth
== -1 )
561 actualWidth
= currentW
;
566 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
568 actualHeight
= size
.y
;
569 if ( actualHeight
== -1 )
574 actualHeight
= currentH
;
578 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
579 actualWidth
= m_minWidth
;
580 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
581 actualHeight
= m_minHeight
;
582 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
583 actualWidth
= m_maxWidth
;
584 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
585 actualHeight
= m_maxHeight
;
586 if ( actualX
== currentX
&& actualY
== currentY
&& actualWidth
== currentW
&& actualHeight
== currentH
)
588 MacRepositionScrollBars() ; // we might have a real position shift
592 AdjustForParentClientOrigin(actualX
, actualY
, sizeFlags
);
595 bool doMove
= false ;
596 bool doResize
= false ;
598 if ( actualX
!= former_x
|| actualY
!= former_y
)
602 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
607 if ( doMove
|| doResize
)
609 if ( m_macWindowData
)
614 // erase former position
615 wxMacDrawingHelper
focus( this ) ;
618 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
619 ClipRect( &clientrect
) ;
620 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
625 m_width
= actualWidth
;
626 m_height
= actualHeight
;
627 if ( m_macWindowData
)
630 ::MoveWindow(m_macWindowData
->m_macWindow
, m_x
, m_y
, false); // don't make frontmost
633 ::SizeWindow(m_macWindowData
->m_macWindow
, m_width
, m_height
, true);
635 // the OS takes care of invalidating and erasing the new area
636 // we have erased the old one
638 if ( IsKindOf( CLASSINFO( wxFrame
) ) )
640 wxFrame
* frame
= (wxFrame
*) this ;
641 frame
->PositionStatusBar();
642 frame
->PositionToolBar();
647 // erase new position
650 wxMacDrawingHelper
focus( this ) ;
653 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
654 ClipRect( &clientrect
) ;
655 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
660 wxWindow::MacSuperChangedPosition() ; // like this only children will be notified
662 MacRepositionScrollBars() ;
665 wxMoveEvent
event(wxPoint(m_x
, m_y
), m_windowId
);
666 event
.SetEventObject(this);
667 GetEventHandler()->ProcessEvent(event
) ;
671 MacRepositionScrollBars() ;
672 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
673 event
.SetEventObject(this);
674 GetEventHandler()->ProcessEvent(event
);
678 // For implementation purposes - sometimes decorations make the client area
681 wxPoint
wxWindow::GetClientAreaOrigin() const
683 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
686 // Makes an adjustment to the window position (for example, a frame that has
687 // a toolbar that it manages itself).
688 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
690 if( !m_macWindowData
)
692 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
694 wxPoint
pt(GetParent()->GetClientAreaOrigin());
695 x
+= pt
.x
; y
+= pt
.y
;
700 void wxWindow::SetTitle(const wxString
& title
)
706 if( wxApp::s_macDefaultEncodingIsPC
)
707 label
= wxMacMakeMacStringFromPC( title
) ;
711 if ( m_macWindowData
)
712 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
715 wxString
wxWindow::GetTitle() const
720 bool wxWindow::Show(bool show
)
722 if ( !wxWindowBase::Show(show
) )
725 if ( m_macWindowData
)
729 UMAShowWindow( m_macWindowData
->m_macWindow
) ;
730 UMASelectWindow( m_macWindowData
->m_macWindow
) ;
731 // no need to generate events here, they will get them triggered by macos
732 // actually they should be , but apparently they are not
733 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
734 event
.SetEventObject(this);
735 GetEventHandler()->ProcessEvent(event
);
739 UMAHideWindow( m_macWindowData
->m_macWindow
) ;
742 MacSuperShown( show
) ;
745 MacUpdateImmediately() ;
750 void wxWindow::MacSuperShown( bool show
)
752 wxNode
*node
= GetChildren().First();
755 wxWindow
*child
= (wxWindow
*)node
->Data();
756 if ( child
->m_isShown
)
757 child
->MacSuperShown( show
) ;
762 bool wxWindow::MacIsReallyShown() const
764 if ( m_isShown
&& (m_parent
!= NULL
) ) {
765 return m_parent
->MacIsReallyShown();
769 bool status = m_isShown ;
770 wxWindow * win = this ;
771 while ( status && win->m_parent != NULL )
773 win = win->m_parent ;
774 status = win->m_isShown ;
780 int wxWindow::GetCharHeight() const
782 wxClientDC
dc ( (wxWindow
*)this ) ;
783 return dc
.GetCharHeight() ;
786 int wxWindow::GetCharWidth() const
788 wxClientDC
dc ( (wxWindow
*)this ) ;
789 return dc
.GetCharWidth() ;
792 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
793 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
795 const wxFont
*fontToUse
= theFont
;
799 wxClientDC
dc( (wxWindow
*) this ) ;
801 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
802 if ( externalLeading
)
803 *externalLeading
= le
;
812 void wxWindow::MacEraseBackground( Rect
*rect
)
814 WindowRef window
= GetMacRootWindow() ;
815 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
817 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
819 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
821 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
822 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
823 // either a non gray background color or a non control window
825 wxWindow
* parent
= GetParent() ;
828 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
830 // if we have any other colours in the hierarchy
831 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
834 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
836 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
837 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
839 UMAApplyThemeBackground(kThemeBackgroundTabPane
, rect
, kThemeStateActive
,8,true);
845 // we have arrived at a non control item
849 parent
= parent
->GetParent() ;
853 // if there is nothing special -> use default
854 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
859 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
864 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
866 wxWindow
*child
= (wxWindow
*)node
->Data();
868 Rect clientrect
= { child
->m_x
, child
->m_y
, child
->m_x
+child
->m_width
, child
->m_y
+ child
->m_height
} ;
869 SectRect( &clientrect
, rect
, &clientrect
) ;
871 OffsetRect( &clientrect
, -child
->m_x
, -child
->m_y
) ;
872 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() )
874 wxMacDrawingClientHelper
focus( this ) ;
877 child
->MacEraseBackground( &clientrect
) ;
883 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
885 wxMacDrawingHelper
focus( this ) ;
888 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
889 ClipRect( &clientrect
) ;
893 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
894 SectRect( &clientrect
, &r
, &clientrect
) ;
896 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
900 // Responds to colour changes: passes event on to children.
901 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
903 wxNode
*node
= GetChildren().First();
906 // Only propagate to non-top-level windows
907 wxWindow
*win
= (wxWindow
*)node
->Data();
908 if ( win
->GetParent() )
910 wxSysColourChangedEvent event2
;
911 event
.m_eventObject
= win
;
912 win
->GetEventHandler()->ProcessEvent(event2
);
919 #if wxUSE_CARET && WXWIN_COMPATIBILITY
920 // ---------------------------------------------------------------------------
921 // Caret manipulation
922 // ---------------------------------------------------------------------------
924 void wxWindow::CreateCaret(int w
, int h
)
926 SetCaret(new wxCaret(this, w
, h
));
929 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
931 wxFAIL_MSG("not implemented");
934 void wxWindow::ShowCaret(bool show
)
936 wxCHECK_RET( m_caret
, "no caret to show" );
941 void wxWindow::DestroyCaret()
946 void wxWindow::SetCaretPos(int x
, int y
)
948 wxCHECK_RET( m_caret
, "no caret to move" );
953 void wxWindow::GetCaretPos(int *x
, int *y
) const
955 wxCHECK_RET( m_caret
, "no caret to get position of" );
957 m_caret
->GetPosition(x
, y
);
959 #endif // wxUSE_CARET
961 wxWindow
*wxGetActiveWindow()
963 // actually this is a windows-only concept
967 // Coordinates relative to the window
968 void wxWindow::WarpPointer (int x_pos
, int y_pos
)
970 // We really dont move the mouse programmatically under mac
973 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
975 // TODO : probably we would adopt the EraseEvent structure
978 int wxWindow::GetScrollPos(int orient
) const
980 if ( orient
== wxHORIZONTAL
)
983 return m_hScrollBar
->GetThumbPosition() ;
988 return m_vScrollBar
->GetThumbPosition() ;
993 // This now returns the whole range, not just the number
994 // of positions that we can scroll.
995 int wxWindow::GetScrollRange(int orient
) const
997 if ( orient
== wxHORIZONTAL
)
1000 return m_hScrollBar
->GetRange() ;
1005 return m_vScrollBar
->GetRange() ;
1010 int wxWindow::GetScrollThumb(int orient
) const
1012 if ( orient
== wxHORIZONTAL
)
1015 return m_hScrollBar
->GetThumbSize() ;
1020 return m_vScrollBar
->GetThumbSize() ;
1025 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
1027 if ( orient
== wxHORIZONTAL
)
1030 m_hScrollBar
->SetThumbPosition( pos
) ;
1035 m_vScrollBar
->SetThumbPosition( pos
) ;
1039 void wxWindow::MacCreateRealWindow( const wxString
& title
,
1043 const wxString
& name
)
1046 m_windowStyle
= style
;
1067 m_macWindowData
= new MacWindowData() ;
1069 ::SetRect(&theBoundsRect
, m_x
, m_y
, m_x
+ m_width
, m_y
+ m_height
);
1071 // translate the window attributes in the appropriate window class and attributes
1073 WindowClass wclass
= 0;
1074 WindowAttributes attr
= kWindowNoAttributes
;
1076 if ( HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
) )
1078 wclass
= kFloatingWindowClass
;
1079 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1081 attr
|= kWindowSideTitlebarAttribute
;
1084 else if ( HasFlag( wxCAPTION
) )
1086 if ( HasFlag( wxDIALOG_MODAL
) )
1088 wclass
= kMovableModalWindowClass
;
1092 wclass
= kDocumentWindowClass
;
1097 wclass
= kModalWindowClass
;
1100 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) )
1102 attr
|= kWindowFullZoomAttribute
;
1103 attr
|= kWindowCollapseBoxAttribute
;
1105 if ( HasFlag( wxRESIZE_BORDER
) )
1107 attr
|= kWindowResizableAttribute
;
1109 if ( HasFlag( wxSYSTEM_MENU
) )
1111 attr
|= kWindowCloseBoxAttribute
;
1114 UMACreateNewWindow( wclass
, attr
, &theBoundsRect
, &m_macWindowData
->m_macWindow
) ;
1115 wxAssociateWinWithMacWindow( m_macWindowData
->m_macWindow
, this ) ;
1117 if( wxApp::s_macDefaultEncodingIsPC
)
1118 label
= wxMacMakeMacStringFromPC( title
) ;
1121 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
1122 UMACreateRootControl( m_macWindowData
->m_macWindow
, &m_macWindowData
->m_macRootControl
) ;
1124 m_macWindowData
->m_macFocus
= NULL
;
1127 void wxWindow::MacPaint( wxPaintEvent
&event
)
1131 void wxWindow::MacPaintBorders( )
1133 if( m_macWindowData
)
1136 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1137 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1138 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1139 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1142 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1144 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1145 RGBColor pen1
= sunken
? white
: black
;
1146 RGBColor pen2
= sunken
? shadow
: face
;
1147 RGBColor pen3
= sunken
? face
: shadow
;
1148 RGBColor pen4
= sunken
? black
: white
;
1150 RGBForeColor( &pen1
) ;
1152 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1153 FrameRect( &rect
) ;
1155 RGBForeColor( &pen2
) ;
1157 Rect rect
= { 1 , 1 , m_height
-1 , m_width
-1} ;
1158 FrameRect( &rect
) ;
1160 RGBForeColor( &pen3
) ;
1162 Rect rect
= { 0 , 0 , m_height
-2 , m_width
-2} ;
1163 FrameRect( &rect
) ;
1165 RGBForeColor( &pen4
) ;
1168 LineTo( m_width
- 3 , 0 ) ;
1170 LineTo( 0 , m_height
- 3 ) ;
1173 else if (HasFlag(wxSIMPLE_BORDER
))
1175 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1176 RGBForeColor( &black
) ;
1177 FrameRect( &rect
) ;
1180 if ( this->GetParent() )
1182 wxPaintDC dc(GetParent());
1183 GetParent()->PrepareDC(dc);
1185 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) )
1187 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1189 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1190 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1192 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1193 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1194 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1195 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1198 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1201 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1204 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1207 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1208 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1210 else if (HasFlag(wxDOUBLE_BORDER))
1212 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1214 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1215 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1217 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1218 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1219 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1220 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1223 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1226 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1229 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1232 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1233 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1235 else if (HasFlag(wxSIMPLE_BORDER))
1237 dc.SetPen(*wxBLACK_PEN);
1238 dc.DrawRectangle(m_x, m_y, m_width, m_height);
1244 // New function that will replace some of the above.
1245 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1246 int range
, bool refresh
)
1248 if ( orient
== wxHORIZONTAL
)
1252 if ( range
== 0 || thumbVisible
>= range
)
1254 if ( m_hScrollBar
->IsShown() )
1255 m_hScrollBar
->Show(false) ;
1259 if ( !m_hScrollBar
->IsShown() )
1260 m_hScrollBar
->Show(true) ;
1261 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, refresh
) ;
1269 if ( range
== 0 || thumbVisible
>= range
)
1271 if ( m_vScrollBar
->IsShown() )
1272 m_vScrollBar
->Show(false) ;
1276 if ( !m_vScrollBar
->IsShown() )
1277 m_vScrollBar
->Show(true) ;
1278 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, refresh
) ;
1282 MacRepositionScrollBars() ;
1285 // Does a physical scroll
1286 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1288 wxMacDrawingClientHelper
focus( this ) ;
1291 int width
, height
;
1292 GetClientSize( &width
, &height
) ;
1294 Rect scrollrect
= { 0 , 0 , height
, width
} ;
1296 RgnHandle updateRgn
= NewRgn() ;
1297 ClipRect( &scrollrect
) ;
1300 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
1301 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1303 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1304 InvalWindowRgn( GetMacRootWindow() , updateRgn
) ;
1305 DisposeRgn( updateRgn
) ;
1308 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1310 wxWindow
*child
= (wxWindow
*)node
->Data();
1311 if (child
== m_vScrollBar
) continue;
1312 if (child
== m_hScrollBar
) continue;
1313 if (child
->IsTopLevel()) continue;
1315 child
->GetPosition( &x
, &y
);
1317 child
->GetSize( &w
, &h
);
1318 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1323 void wxWindow::MacOnScroll(wxScrollEvent
&event
)
1325 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1327 wxScrollWinEvent wevent
;
1328 wevent
.SetPosition(event
.GetPosition());
1329 wevent
.SetOrientation(event
.GetOrientation());
1330 wevent
.m_eventObject
= this;
1332 if (event
.m_eventType
== wxEVT_SCROLL_TOP
) {
1333 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1335 if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
) {
1336 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1338 if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
) {
1339 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1341 if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
) {
1342 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1344 if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
) {
1345 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1347 if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
) {
1348 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1350 if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
) {
1351 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1354 GetEventHandler()->ProcessEvent(wevent
);
1358 bool wxWindow::SetFont(const wxFont
& font
)
1360 if ( !wxWindowBase::SetFont(font
) )
1369 // Get the window with the focus
1370 wxWindow
*wxWindowBase::FindFocus()
1372 return gFocusWindow
;
1375 #if WXWIN_COMPATIBILITY
1376 // If nothing defined for this, try the parent.
1377 // E.g. we may be a button loaded from a resource, with no callback function
1379 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1381 if ( GetEventHandler()->ProcessEvent(event
) )
1384 m_parent
->GetEventHandler()->OnCommand(win
, event
);
1386 #endif // WXWIN_COMPATIBILITY_2
1388 #if WXWIN_COMPATIBILITY
1389 wxObject
* wxWindow::GetChild(int number
) const
1391 // Return a pointer to the Nth object in the Panel
1392 wxNode
*node
= GetChildren().First();
1395 node
= node
->Next();
1398 wxObject
*obj
= (wxObject
*)node
->Data();
1404 #endif // WXWIN_COMPATIBILITY
1406 void wxWindow::OnSetFocus(wxFocusEvent
& event
)
1408 // panel wants to track the window which was the last to have focus in it,
1409 // so we want to set ourselves as the window which last had focus
1411 // notice that it's also important to do it upwards the tree becaus
1412 // otherwise when the top level panel gets focus, it won't set it back to
1413 // us, but to some other sibling
1414 wxWindow
*win
= this;
1417 wxWindow
*parent
= win
->GetParent();
1418 wxPanel
*panel
= wxDynamicCast(parent
, wxPanel
);
1421 panel
->SetLastFocus(win
);
1430 void wxWindow::Clear()
1432 if ( m_macWindowData
)
1434 wxMacDrawingClientHelper
helper ( this ) ;
1436 wxPoint origin
= GetClientAreaOrigin() ;
1437 GetClientSize( &w
, &h
) ;
1438 UMASetThemeWindowBackground( m_macWindowData
->m_macWindow
, m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
1439 Rect r
= { origin
.y
, origin
.x
, origin
.y
+h
, origin
.x
+w
} ;
1444 wxClientDC
dc(this);
1445 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1446 dc
.SetBackground(brush
);
1451 // Setup background and foreground colours correctly
1452 void wxWindow::SetupColours()
1455 SetBackgroundColour(GetParent()->GetBackgroundColour());
1458 void wxWindow::OnIdle(wxIdleEvent
& event
)
1461 // Check if we need to send a LEAVE event
1462 if (m_mouseInWindow)
1465 ::GetCursorPos(&pt);
1466 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1468 // Generate a LEAVE event
1469 m_mouseInWindow = FALSE;
1470 MSWOnMouseLeave(pt.x, pt.y, 0);
1475 // This calls the UI-update mechanism (querying windows for
1476 // menu/toolbar/control state information)
1480 // Raise the window to the top of the Z order
1481 void wxWindow::Raise()
1486 // Lower the window to the bottom of the Z order
1487 void wxWindow::Lower()
1492 void wxWindow::DoSetClientSize(int width
, int height
)
1494 if ( width
!= -1 || height
!= -1 )
1497 if ( width
!= -1 && m_vScrollBar
)
1498 width
+= MAC_SCROLLBAR_SIZE
;
1499 if ( height
!= -1 && m_vScrollBar
)
1500 height
+= MAC_SCROLLBAR_SIZE
;
1502 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1503 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1505 DoSetSize( -1 , -1 , width
, height
) ;
1510 wxWindow
* wxWindow::s_lastMouseWindow
= NULL
;
1512 bool wxWindow::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindow
** outWin
)
1514 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1515 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1518 WindowRef window
= GetMacRootWindow() ;
1520 wxPoint
newPoint( point
) ;
1525 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1527 wxWindow
*child
= (wxWindow
*)node
->Data();
1528 // added the m_isShown test --dmazzoni
1529 if ( child
->GetMacRootWindow() == window
&& child
->m_isShown
)
1531 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1540 bool wxWindow::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindow
** outWin
)
1543 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1544 if ( ::FindWindow( pt
, &window
) == 3 )
1546 wxPoint
point( screenpoint
) ;
1547 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1550 win
->ScreenToClient( point
) ;
1551 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1557 extern int wxBusyCursorCount
;
1559 bool wxWindow::MacDispatchMouseEvent(wxMouseEvent
& event
)
1561 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1562 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1566 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) )
1569 WindowRef window
= GetMacRootWindow() ;
1577 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1579 wxWindow
*child
= (wxWindow
*)node
->Data();
1580 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1582 if (child
->MacDispatchMouseEvent(event
))
1590 if ( wxBusyCursorCount
== 0 )
1592 m_cursor
.MacInstall() ;
1595 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1597 // set focus to this window
1598 if (AcceptsFocus() && FindFocus()!=this)
1603 if ( event
.GetEventType() == wxEVT_MOTION
1604 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1605 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1606 wxToolTip::RelayEvent( this , event
);
1607 #endif // wxUSE_TOOLTIPS
1608 GetEventHandler()->ProcessEvent( event
) ;
1615 wxString
wxWindow::MacGetToolTipString( wxPoint
&pt
)
1619 return m_tooltip
->GetTip() ;
1623 void wxWindow::MacFireMouseEvent( EventRecord
*ev
)
1625 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
1626 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1627 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1629 event
.m_leftDown
= isDown
&& !controlDown
;
1630 event
.m_middleDown
= FALSE
;
1631 event
.m_rightDown
= isDown
&& controlDown
;
1633 if ( ev
->what
== mouseDown
)
1636 event
.SetEventType(wxEVT_RIGHT_DOWN
) ;
1638 event
.SetEventType(wxEVT_LEFT_DOWN
) ;
1640 else if ( ev
->what
== mouseUp
)
1643 event
.SetEventType(wxEVT_RIGHT_UP
) ;
1645 event
.SetEventType(wxEVT_LEFT_UP
) ;
1649 event
.SetEventType(wxEVT_MOTION
) ;
1652 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1653 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1654 event
.m_altDown
= ev
->modifiers
& optionKey
;
1655 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1657 Point localwhere
= ev
->where
;
1660 ::GetPort( &port
) ;
1661 ::SetPort( UMAGetWindowPort( m_macWindowData
->m_macWindow
) ) ;
1662 ::GlobalToLocal( &localwhere
) ;
1665 if ( ev
->what
== mouseDown
)
1667 if ( ev
->when
- lastWhen
<= GetDblTime() )
1669 if ( abs( localwhere
.h
- lastWhere
.h
) < 3 || abs( localwhere
.v
- lastWhere
.v
) < 3 )
1672 event
.SetEventType(wxEVT_RIGHT_DCLICK
) ;
1674 event
.SetEventType(wxEVT_LEFT_DCLICK
) ;
1677 lastWhen
= ev
->when
;
1678 lastWhere
= localwhere
;
1681 event
.m_x
= localwhere
.h
;
1682 event
.m_y
= localwhere
.v
;
1687 wxPoint origin = GetClientAreaOrigin() ;
1689 event.m_x += origin.x ;
1690 event.m_y += origin.y ;
1693 event
.m_timeStamp
= ev
->when
;
1694 event
.SetEventObject(this);
1695 if ( wxTheApp
->s_captureWindow
)
1699 wxTheApp
->s_captureWindow
->ScreenToClient( &x
, &y
) ;
1702 wxTheApp
->s_captureWindow
->GetEventHandler()->ProcessEvent( event
) ;
1703 if ( ev
->what
== mouseUp
)
1705 wxTheApp
->s_captureWindow
= NULL
;
1706 if ( wxBusyCursorCount
== 0 )
1708 m_cursor
.MacInstall() ;
1714 MacDispatchMouseEvent( event
) ;
1718 void wxWindow::MacMouseDown( EventRecord
*ev
, short part
)
1720 MacFireMouseEvent( ev
) ;
1723 void wxWindow::MacMouseUp( EventRecord
*ev
, short part
)
1725 WindowPtr frontWindow
;
1730 MacFireMouseEvent( ev
) ;
1736 void wxWindow::MacMouseMoved( EventRecord
*ev
, short part
)
1738 WindowPtr frontWindow
;
1743 MacFireMouseEvent( ev
) ;
1748 void wxWindow::MacActivate( EventRecord
*ev
, bool inIsActivating
)
1750 wxActivateEvent
event(wxEVT_ACTIVATE
, inIsActivating
, m_windowId
);
1751 event
.m_timeStamp
= ev
->when
;
1752 event
.SetEventObject(this);
1754 GetEventHandler()->ProcessEvent(event
);
1756 UMAHighlightAndActivateWindow( m_macWindowData
->m_macWindow
, inIsActivating
) ;
1759 void wxWindow::MacRedraw( RgnHandle updatergn
, long time
)
1761 // updatergn is always already clipped to our boundaries
1762 WindowRef window
= GetMacRootWindow() ;
1763 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1765 wxMacDrawingHelper
focus( this ) ; // was client
1768 WindowRef window
= GetMacRootWindow() ;
1769 bool eraseBackground
= false ;
1770 if ( m_macWindowData
)
1771 eraseBackground
= true ;
1772 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
1774 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
1776 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1778 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1779 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1780 // either a non gray background color or a non control window
1783 wxWindow
* parent
= GetParent() ;
1786 if ( parent
->GetMacRootWindow() != window
)
1788 // we are in a different window on the mac system
1793 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
1795 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1797 // if we have any other colours in the hierarchy
1798 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
1801 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1802 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
1805 GetRegionBounds( updatergn
, &box
) ;
1806 UMAApplyThemeBackground(kThemeBackgroundTabPane
, &box
, kThemeStateActive
,8,true);
1815 parent
= parent
->GetParent() ;
1819 // if there is nothing special -> use default
1820 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
1825 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
1827 if ( GetParent() && m_backgroundColour
!= GetParent()->GetBackgroundColour() )
1828 eraseBackground
= true ;
1829 SetClip( updatergn
) ;
1830 if ( eraseBackground
)
1832 EraseRgn( updatergn
) ;
1836 m_macUpdateRgn
= updatergn
;
1838 RgnHandle newupdate
= NewRgn() ;
1839 wxSize point
= GetClientSize() ;
1840 wxPoint origin
= GetClientAreaOrigin() ;
1842 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1843 SectRgn( newupdate
, m_macUpdateRgn
, newupdate
) ;
1844 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1845 m_updateRegion
= newupdate
;
1846 DisposeRgn( newupdate
) ;
1851 event
.m_timeStamp
= time
;
1852 event
.SetEventObject(this);
1853 GetEventHandler()->ProcessEvent(event
);
1857 RgnHandle childupdate
= NewRgn() ;
1859 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1861 wxWindow
*child
= (wxWindow
*)node
->Data();
1862 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1863 SectRgn( childupdate
, m_macUpdateRgn
, childupdate
) ;
1864 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1865 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1867 // because dialogs may also be children
1868 child
->MacRedraw( childupdate
, time
) ;
1871 DisposeRgn( childupdate
) ;
1872 // eventually a draw grow box here
1875 void wxWindow::MacUpdateImmediately()
1877 WindowRef window
= GetMacRootWindow() ;
1880 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1882 AGAPortHelper
help( GetWindowPort(window
) ) ;
1884 AGAPortHelper
help( (window
) ) ;
1886 SetOrigin( 0 , 0 ) ;
1887 BeginUpdate( window
) ;
1890 RgnHandle region
= NewRgn();
1894 GetPortVisibleRegion( GetWindowPort( window
), region
);
1896 // if windowshade gives incompatibility , take the follwing out
1897 if ( !EmptyRgn( region
) )
1899 win
->MacRedraw( region
, wxTheApp
->sm_lastMessageTime
) ;
1901 DisposeRgn( region
);
1904 EndUpdate( window
) ;
1908 void wxWindow::MacUpdate( EventRecord
*ev
)
1910 WindowRef window
= (WindowRef
) ev
->message
;
1911 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1913 AGAPortHelper
help( GetWindowPort(window
) ) ;
1915 AGAPortHelper
help( (window
) ) ;
1917 SetOrigin( 0 , 0 ) ;
1918 BeginUpdate( window
) ;
1921 RgnHandle region
= NewRgn();
1925 GetPortVisibleRegion( GetWindowPort( window
), region
);
1927 // if windowshade gives incompatibility , take the follwing out
1928 if ( !EmptyRgn( region
) )
1930 MacRedraw( region
, ev
->when
) ;
1932 DisposeRgn( region
);
1935 EndUpdate( window
) ;
1938 WindowRef
wxWindow::GetMacRootWindow() const
1940 WindowRef window
= NULL
;
1941 wxWindow
*iter
= (wxWindow
*)this ;
1945 if ( iter
->m_macWindowData
)
1946 return iter
->m_macWindowData
->m_macWindow
;
1948 iter
= iter
->GetParent() ;
1950 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1954 void wxWindow::MacCreateScrollBars( long style
)
1956 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
1958 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1959 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1961 GetClientSize( &width
, &height
) ;
1963 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1964 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1965 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1966 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1968 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
1969 vSize
, wxVERTICAL
);
1971 if ( style
& wxVSCROLL
)
1977 m_vScrollBar
->Show(false) ;
1979 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
1980 hSize
, wxHORIZONTAL
);
1981 if ( style
& wxHSCROLL
)
1986 m_hScrollBar
->Show(false) ;
1989 // because the create does not take into account the client area origin
1990 MacRepositionScrollBars() ; // we might have a real position shift
1993 void wxWindow::MacRepositionScrollBars()
1995 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
1996 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
1998 // get real client area
2000 int width
= m_width
;
2001 int height
= m_height
;
2003 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2004 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2006 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2007 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2008 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2009 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2016 MacClientToRootWindow( &x
, &y
) ;
2017 MacClientToRootWindow( &w
, &h
) ;
2019 WindowRef window
= NULL
;
2020 wxWindow
*iter
= (wxWindow
*)this ;
2022 int totW
= 10000 , totH
= 10000;
2025 if ( iter
->m_macWindowData
)
2027 totW
= iter
->m_width
;
2028 totH
= iter
->m_height
;
2032 iter
= iter
->GetParent() ;
2060 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2064 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2068 void wxWindow::MacKeyDown( EventRecord
*ev
)
2074 bool wxWindow::AcceptsFocus() const
2076 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2079 ControlHandle
wxWindow::MacGetContainerForEmbedding()
2081 if ( m_macWindowData
)
2082 return m_macWindowData
->m_macRootControl
;
2084 return GetParent()->MacGetContainerForEmbedding() ;
2087 void wxWindow::MacSuperChangedPosition()
2089 // only window-absolute structures have to be moved i.e. controls
2091 wxNode
*node
= GetChildren().First();
2094 wxWindow
*child
= (wxWindow
*)node
->Data();
2095 child
->MacSuperChangedPosition() ;
2096 node
= node
->Next();
2100 bool wxWindow::MacSetPortFocusParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
2102 if ( window
== NULL
)
2108 ::GetPort(&currPort
);
2109 port
= UMAGetWindowPort( window
) ;
2110 if (currPort
!= port
)
2113 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2114 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2118 bool wxWindow::MacSetPortDrawingParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
2120 if ( window
== NULL
)
2125 ::GetPort(&currPort
);
2126 port
= UMAGetWindowPort( window
) ;
2127 if (currPort
!= port
)
2129 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2130 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2131 ::ClipRect(&clipRect
);
2134 ::RGBBackColor(& win
->GetBackgroundColour().GetPixel() ) ;
2135 ::RGBForeColor(& win
->GetForegroundColour().GetPixel() ) ;
2136 Pattern whiteColor
;
2138 ::BackPat( GetQDGlobalsWhite( &whiteColor
) ) ;
2139 ::UMASetThemeWindowBackground( win
->m_macWindowData
->m_macWindow
, win
->m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
2143 void wxWindow::MacGetPortParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2145 if ( m_macWindowData
)
2151 clipRect
->right
= m_width
;
2152 clipRect
->bottom
= m_height
;
2153 *window
= m_macWindowData
->m_macWindow
;
2158 wxASSERT( GetParent() != NULL
) ;
2159 GetParent()->MacGetPortParams( localOrigin
, clipRect
, window
, rootwin
) ;
2160 localOrigin
->h
+= m_x
;
2161 localOrigin
->v
+= m_y
;
2162 OffsetRect(clipRect
, -m_x
, -m_y
);
2167 myClip
.right
= m_width
;
2168 myClip
.bottom
= m_height
;
2169 SectRect(clipRect
, &myClip
, clipRect
);
2173 void wxWindow::MacDoGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2175 // int width , height ;
2176 // GetClientSize( &width , &height ) ;
2178 if ( m_macWindowData
)
2184 clipRect
->right
= m_width
;//width;
2185 clipRect
->bottom
= m_height
;// height;
2186 *window
= m_macWindowData
->m_macWindow
;
2191 wxASSERT( GetParent() != NULL
) ;
2193 GetParent()->MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2195 localOrigin
->h
+= m_x
;
2196 localOrigin
->v
+= m_y
;
2197 OffsetRect(clipRect
, -m_x
, -m_y
);
2202 myClip
.right
= m_width
;//width;
2203 myClip
.bottom
= m_height
;// height;
2204 SectRect(clipRect
, &myClip
, clipRect
);
2208 void wxWindow::MacGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2210 MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2212 int width
, height
;
2213 GetClientSize( &width
, &height
) ;
2215 client
= GetClientAreaOrigin( ) ;
2217 localOrigin
->h
+= client
.x
;
2218 localOrigin
->v
+= client
.y
;
2219 OffsetRect(clipRect
, -client
.x
, -client
.y
);
2224 myClip
.right
= width
;
2225 myClip
.bottom
= height
;
2226 SectRect(clipRect
, &myClip
, clipRect
);
2229 long wxWindow::MacGetLeftBorderSize( ) const
2231 if( m_macWindowData
)
2234 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2238 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2242 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2249 long wxWindow::MacGetRightBorderSize( ) const
2251 if( m_macWindowData
)
2254 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2258 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2262 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2269 long wxWindow::MacGetTopBorderSize( ) const
2271 if( m_macWindowData
)
2274 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2278 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2282 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2289 long wxWindow::MacGetBottomBorderSize( ) const
2291 if( m_macWindowData
)
2294 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2298 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2302 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2309 long wxWindow::MacRemoveBordersFromStyle( long style
)
2311 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2314 wxMacFocusHelper::wxMacFocusHelper( wxWindow * theWindow )
2321 m_currentPort = NULL ;
2322 GetPort( &m_formerPort ) ;
2326 theWindow->MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
2327 m_currentPort = UMAGetWindowPort( window ) ;
2328 theWindow->MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
2333 wxMacFocusHelper::~wxMacFocusHelper()
2337 SetPort( m_currentPort ) ;
2338 SetOrigin( 0 , 0 ) ;
2340 if ( m_formerPort != m_currentPort )
2341 SetPort( m_formerPort ) ;
2345 wxMacDrawingHelper::wxMacDrawingHelper( wxWindow
* theWindow
)
2352 m_currentPort
= NULL
;
2354 GetPort( &m_formerPort
) ;
2357 theWindow
->MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2358 m_currentPort
= UMAGetWindowPort( window
) ;
2359 if ( m_formerPort
!= m_currentPort
)
2360 SetPort( m_currentPort
) ;
2361 GetPenState( &m_savedPenState
) ;
2362 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2367 wxMacDrawingHelper::~wxMacDrawingHelper()
2371 SetPort( m_currentPort
) ;
2372 SetPenState( &m_savedPenState
) ;
2373 SetOrigin( 0 , 0 ) ;
2375 GetPortBounds( m_currentPort
, &portRect
) ;
2376 ClipRect( &portRect
) ;
2377 wxDC::MacInvalidateSetup() ;
2380 if ( m_formerPort
!= m_currentPort
)
2381 SetPort( m_formerPort
) ;
2384 wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindow
* theWindow
)
2391 m_currentPort
= NULL
;
2393 GetPort( &m_formerPort
) ;
2397 theWindow
->MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2398 m_currentPort
= UMAGetWindowPort( window
) ;
2399 if ( m_formerPort
!= m_currentPort
)
2400 SetPort( m_currentPort
) ;
2401 GetPenState( &m_savedPenState
) ;
2402 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2407 wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
2411 SetPort( m_currentPort
) ;
2412 SetPenState( &m_savedPenState
) ;
2413 SetOrigin( 0 , 0 ) ;
2415 GetPortBounds( m_currentPort
, &portRect
) ;
2416 ClipRect( &portRect
) ;
2419 if ( m_formerPort
!= m_currentPort
)
2420 SetPort( m_formerPort
) ;
2423 // Find the wxWindow at the current mouse position, returning the mouse
2425 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
2427 pt
= wxGetMousePosition();
2428 wxWindow
* found
= wxFindWindowAtPoint(pt
);
2432 // Get the current mouse position.
2433 wxPoint
wxGetMousePosition()
2436 wxGetMousePosition(& x
, & y
);
2437 return wxPoint(x
, y
);