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 // deleting a window while it is shown invalidates the region
157 wxWindow
* iter
= this ;
159 if ( iter
->m_macWindowData
)
164 iter
= iter
->GetParent() ;
169 m_isBeingDeleted
= TRUE
;
171 if ( s_lastMouseWindow
== this )
173 s_lastMouseWindow
= NULL
;
176 if ( gFocusWindow
== this )
178 gFocusWindow
= NULL
;
182 m_parent
->RemoveChild(this);
186 if ( m_macWindowData
)
188 wxToolTip::NotifyWindowDelete(m_macWindowData
->m_macWindow
) ;
189 UMADisposeWindow( m_macWindowData
->m_macWindow
) ;
190 delete m_macWindowData
;
191 wxRemoveMacWindowAssociation( this ) ;
196 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
200 const wxString
& name
)
202 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindow without parent") );
204 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
207 parent
->AddChild(this);
211 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
212 m_width
= WidthDefault( size
.x
);
213 m_height
= HeightDefault( size
.y
) ;
215 if ( ! IsKindOf( CLASSINFO ( wxControl
) ) && ! IsKindOf( CLASSINFO( wxStatusBar
) ) )
217 MacCreateScrollBars( style
) ;
223 void wxWindow::SetFocus()
225 if ( gFocusWindow
== this )
228 if ( AcceptsFocus() )
234 if ( gFocusWindow
->m_caret
)
236 gFocusWindow
->m_caret
->OnKillFocus();
238 #endif // wxUSE_CARET
239 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
240 if ( control
&& control
->GetMacControl() )
242 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlFocusNoPart
) ;
243 control
->MacRedrawControl() ;
245 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
246 event
.SetEventObject(gFocusWindow
);
247 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
249 gFocusWindow
= this ;
255 m_caret
->OnSetFocus();
257 #endif // wxUSE_CARET
258 // panel wants to track the window which was the last to have focus in it
259 wxPanel
*panel
= wxDynamicCast(GetParent(), wxPanel
);
262 panel
->SetLastFocus(this);
264 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
265 if ( control
&& control
->GetMacControl() )
267 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlEditTextPart
) ;
270 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
271 event
.SetEventObject(this);
272 GetEventHandler()->ProcessEvent(event
) ;
277 bool wxWindow::Enable(bool enable
)
279 if ( !wxWindowBase::Enable(enable
) )
282 wxWindowList::Node
*node
= GetChildren().GetFirst();
285 wxWindow
*child
= node
->GetData();
286 child
->Enable(enable
);
288 node
= node
->GetNext();
294 void wxWindow::CaptureMouse()
296 wxTheApp
->s_captureWindow
= this ;
299 void wxWindow::ReleaseMouse()
301 wxTheApp
->s_captureWindow
= NULL
;
304 #if wxUSE_DRAG_AND_DROP
306 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
308 if ( m_pDropTarget
!= 0 ) {
309 delete m_pDropTarget
;
312 m_pDropTarget
= pDropTarget
;
313 if ( m_pDropTarget
!= 0 )
321 // Old style file-manager drag&drop
322 void wxWindow::DragAcceptFiles(bool accept
)
328 void wxWindow::DoGetSize(int *x
, int *y
) const
334 void wxWindow::DoGetPosition(int *x
, int *y
) const
340 wxPoint
pt(GetParent()->GetClientAreaOrigin());
347 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
349 menu
->SetInvokingWindow(this);
351 ClientToScreen( &x
, &y
) ;
353 ::InsertMenu( menu
->GetHMenu() , -1 ) ;
354 long menuResult
= ::PopUpMenuSelect(menu
->GetHMenu() ,y
,x
, 0) ;
355 menu
->MacMenuSelect( this , TickCount() , HiWord(menuResult
) , LoWord(menuResult
) ) ;
356 ::DeleteMenu( menu
->MacGetMenuId() ) ;
357 menu
->SetInvokingWindow(NULL
);
362 void wxWindow::DoScreenToClient(int *x
, int *y
) const
364 WindowRef window
= GetMacRootWindow() ;
372 ::SetPort( UMAGetWindowPort( window
) ) ;
373 ::GlobalToLocal( &localwhere
) ;
379 MacRootWindowToClient( x
, y
) ;
382 void wxWindow::DoClientToScreen(int *x
, int *y
) const
384 WindowRef window
= GetMacRootWindow() ;
386 MacClientToRootWindow( x
, y
) ;
394 ::SetPort( UMAGetWindowPort( window
) ) ;
395 ::SetOrigin( 0 , 0 ) ;
396 ::LocalToGlobal( &localwhere
) ;
402 void wxWindow::MacClientToRootWindow( int *x
, int *y
) const
404 if ( m_macWindowData
)
411 GetParent()->MacClientToRootWindow( x
, y
) ;
415 void wxWindow::MacRootWindowToClient( int *x
, int *y
) const
417 if ( m_macWindowData
)
424 GetParent()->MacRootWindowToClient( x
, y
) ;
428 bool wxWindow::SetCursor(const wxCursor
& cursor
)
430 if (m_cursor
== cursor
)
433 if (wxNullCursor
== cursor
)
435 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
440 if ( ! wxWindowBase::SetCursor( cursor
) )
444 wxASSERT_MSG( m_cursor
.Ok(),
445 wxT("cursor must be valid after call to the base version"));
451 // Change the cursor NOW if we're within the correct window
453 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
455 if ( mouseWin
== this && !wxIsBusy() )
457 m_cursor
.MacInstall() ;
465 // Get size *available for subwindows* i.e. excluding menu bar etc.
466 void wxWindow::DoGetClientSize(int *x
, int *y
) const
471 *x
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
472 *y
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
474 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
481 MacClientToRootWindow( &x1
, &y1
) ;
482 MacClientToRootWindow( &w
, &h
) ;
484 WindowRef window
= NULL
;
485 wxWindow
*iter
= (wxWindow
*)this ;
487 int totW
= 10000 , totH
= 10000;
490 if ( iter
->m_macWindowData
)
492 totW
= iter
->m_width
;
493 totH
= iter
->m_height
;
497 iter
= iter
->GetParent() ;
500 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
502 (*y
) -= MAC_SCROLLBAR_SIZE
;
508 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
510 (*x
) -= MAC_SCROLLBAR_SIZE
;
520 // ----------------------------------------------------------------------------
522 // ----------------------------------------------------------------------------
526 void wxWindow::DoSetToolTip(wxToolTip
*tooltip
)
528 wxWindowBase::DoSetToolTip(tooltip
);
531 m_tooltip
->SetWindow(this);
534 #endif // wxUSE_TOOLTIPS
536 void wxWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
538 DoSetSize( x
,y
, width
, height
) ;
541 // set the size of the window: if the dimensions are positive, just use them,
542 // but if any of them is equal to -1, it means that we must find the value for
543 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
544 // which case -1 is a valid value for x and y)
546 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
547 // the width/height to best suit our contents, otherwise we reuse the current
549 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
554 int former_w
= m_width
;
555 int former_h
= m_height
;
557 int currentX
, currentY
;
558 GetPosition(¤tX
, ¤tY
);
559 int currentW
,currentH
;
560 GetSize(¤tW
, ¤tH
);
562 int actualWidth
= width
;
563 int actualHeight
= height
;
566 if (x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
568 if (y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
571 wxSize
size( -1 , -1 ) ;
573 if (width
== -1 || height
== -1 )
575 size
= DoGetBestSize() ;
580 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
582 actualWidth
= size
.x
;
583 if ( actualWidth
== -1 )
588 actualWidth
= currentW
;
593 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
595 actualHeight
= size
.y
;
596 if ( actualHeight
== -1 )
601 actualHeight
= currentH
;
605 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
606 actualWidth
= m_minWidth
;
607 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
608 actualHeight
= m_minHeight
;
609 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
610 actualWidth
= m_maxWidth
;
611 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
612 actualHeight
= m_maxHeight
;
613 if ( actualX
== currentX
&& actualY
== currentY
&& actualWidth
== currentW
&& actualHeight
== currentH
)
615 MacRepositionScrollBars() ; // we might have a real position shift
619 AdjustForParentClientOrigin(actualX
, actualY
, sizeFlags
);
622 bool doMove
= false ;
623 bool doResize
= false ;
625 if ( actualX
!= former_x
|| actualY
!= former_y
)
629 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
634 if ( doMove
|| doResize
)
636 if ( m_macWindowData
)
641 // erase former position
642 wxMacDrawingHelper
focus( this ) ;
645 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
646 // ClipRect( &clientrect ) ;
647 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
652 m_width
= actualWidth
;
653 m_height
= actualHeight
;
654 if ( m_macWindowData
)
657 ::MoveWindow(m_macWindowData
->m_macWindow
, m_x
, m_y
, false); // don't make frontmost
660 ::SizeWindow(m_macWindowData
->m_macWindow
, m_width
, m_height
, true);
662 // the OS takes care of invalidating and erasing the new area
663 // we have erased the old one
665 if ( IsKindOf( CLASSINFO( wxFrame
) ) )
667 wxFrame
* frame
= (wxFrame
*) this ;
668 frame
->PositionStatusBar();
669 frame
->PositionToolBar();
674 // erase new position
677 wxMacDrawingHelper
focus( this ) ;
680 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
681 // ClipRect( &clientrect ) ;
682 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
687 wxWindow::MacSuperChangedPosition() ; // like this only children will be notified
689 MacRepositionScrollBars() ;
692 wxMoveEvent
event(wxPoint(m_x
, m_y
), m_windowId
);
693 event
.SetEventObject(this);
694 GetEventHandler()->ProcessEvent(event
) ;
698 MacRepositionScrollBars() ;
699 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
700 event
.SetEventObject(this);
701 GetEventHandler()->ProcessEvent(event
);
705 // For implementation purposes - sometimes decorations make the client area
708 wxPoint
wxWindow::GetClientAreaOrigin() const
710 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
713 // Makes an adjustment to the window position (for example, a frame that has
714 // a toolbar that it manages itself).
715 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
717 if( !m_macWindowData
)
719 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
721 wxPoint
pt(GetParent()->GetClientAreaOrigin());
722 x
+= pt
.x
; y
+= pt
.y
;
727 void wxWindow::SetTitle(const wxString
& title
)
733 if( wxApp::s_macDefaultEncodingIsPC
)
734 label
= wxMacMakeMacStringFromPC( title
) ;
738 if ( m_macWindowData
)
739 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
742 wxString
wxWindow::GetTitle() const
747 bool wxWindow::Show(bool show
)
749 if ( !wxWindowBase::Show(show
) )
752 if ( m_macWindowData
)
756 UMAShowWindow( m_macWindowData
->m_macWindow
) ;
757 UMASelectWindow( m_macWindowData
->m_macWindow
) ;
758 // no need to generate events here, they will get them triggered by macos
759 // actually they should be , but apparently they are not
760 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
761 event
.SetEventObject(this);
762 GetEventHandler()->ProcessEvent(event
);
766 UMAHideWindow( m_macWindowData
->m_macWindow
) ;
769 MacSuperShown( show
) ;
775 void wxWindow::MacSuperShown( bool show
)
777 wxNode
*node
= GetChildren().First();
780 wxWindow
*child
= (wxWindow
*)node
->Data();
781 if ( child
->m_isShown
)
782 child
->MacSuperShown( show
) ;
787 bool wxWindow::MacIsReallyShown() const
789 if ( m_isShown
&& (m_parent
!= NULL
) ) {
790 return m_parent
->MacIsReallyShown();
794 bool status = m_isShown ;
795 wxWindow * win = this ;
796 while ( status && win->m_parent != NULL )
798 win = win->m_parent ;
799 status = win->m_isShown ;
805 int wxWindow::GetCharHeight() const
807 wxClientDC
dc ( (wxWindow
*)this ) ;
808 return dc
.GetCharHeight() ;
811 int wxWindow::GetCharWidth() const
813 wxClientDC
dc ( (wxWindow
*)this ) ;
814 return dc
.GetCharWidth() ;
817 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
818 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
820 const wxFont
*fontToUse
= theFont
;
824 wxClientDC
dc( (wxWindow
*) this ) ;
826 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
827 if ( externalLeading
)
828 *externalLeading
= le
;
837 void wxWindow::MacEraseBackground( Rect
*rect
)
840 WindowRef window = GetMacRootWindow() ;
841 if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
843 UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ;
845 else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
847 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
848 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
849 // either a non gray background color or a non control window
851 wxWindow* parent = GetParent() ;
854 if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
856 // if we have any other colours in the hierarchy
857 RGBBackColor( &parent->m_backgroundColour.GetPixel()) ;
860 if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() )
862 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
863 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
865 UMAApplyThemeBackground(kThemeBackgroundTabPane, rect, kThemeStateActive,8,true);
871 // we have arrived at a non control item
875 parent = parent->GetParent() ;
879 // if there is nothing special -> use default
880 UMASetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ;
885 RGBBackColor( &m_backgroundColour.GetPixel()) ;
890 for (wxNode *node = GetChildren().First(); node; node = node->Next())
892 wxWindow *child = (wxWindow*)node->Data();
894 Rect clientrect = { child->m_x , child->m_y , child->m_x +child->m_width , child->m_y + child->m_height } ;
895 SectRect( &clientrect , rect , &clientrect ) ;
897 OffsetRect( &clientrect , -child->m_x , -child->m_y ) ;
898 if ( child->GetMacRootWindow() == window && child->IsShown() )
900 wxMacDrawingClientHelper focus( this ) ;
903 child->MacEraseBackground( &clientrect ) ;
910 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
915 wxMacDrawingHelper
focus( this ) ;
918 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
919 // ClipRect( &clientrect ) ;
923 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
924 SectRect( &clientrect
, &r
, &clientrect
) ;
926 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
929 m_macEraseOnRedraw
= false ;
931 m_macEraseOnRedraw
= true ;
934 // Responds to colour changes: passes event on to children.
935 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
937 wxNode
*node
= GetChildren().First();
940 // Only propagate to non-top-level windows
941 wxWindow
*win
= (wxWindow
*)node
->Data();
942 if ( win
->GetParent() )
944 wxSysColourChangedEvent event2
;
945 event
.m_eventObject
= win
;
946 win
->GetEventHandler()->ProcessEvent(event2
);
953 #if wxUSE_CARET && WXWIN_COMPATIBILITY
954 // ---------------------------------------------------------------------------
955 // Caret manipulation
956 // ---------------------------------------------------------------------------
958 void wxWindow::CreateCaret(int w
, int h
)
960 SetCaret(new wxCaret(this, w
, h
));
963 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
965 wxFAIL_MSG("not implemented");
968 void wxWindow::ShowCaret(bool show
)
970 wxCHECK_RET( m_caret
, "no caret to show" );
975 void wxWindow::DestroyCaret()
980 void wxWindow::SetCaretPos(int x
, int y
)
982 wxCHECK_RET( m_caret
, "no caret to move" );
987 void wxWindow::GetCaretPos(int *x
, int *y
) const
989 wxCHECK_RET( m_caret
, "no caret to get position of" );
991 m_caret
->GetPosition(x
, y
);
993 #endif // wxUSE_CARET
995 wxWindow
*wxGetActiveWindow()
997 // actually this is a windows-only concept
1001 // Coordinates relative to the window
1002 void wxWindow::WarpPointer (int x_pos
, int y_pos
)
1004 // We really dont move the mouse programmatically under mac
1007 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
1009 // TODO : probably we would adopt the EraseEvent structure
1012 int wxWindow::GetScrollPos(int orient
) const
1014 if ( orient
== wxHORIZONTAL
)
1017 return m_hScrollBar
->GetThumbPosition() ;
1022 return m_vScrollBar
->GetThumbPosition() ;
1027 // This now returns the whole range, not just the number
1028 // of positions that we can scroll.
1029 int wxWindow::GetScrollRange(int orient
) const
1031 if ( orient
== wxHORIZONTAL
)
1034 return m_hScrollBar
->GetRange() ;
1039 return m_vScrollBar
->GetRange() ;
1044 int wxWindow::GetScrollThumb(int orient
) const
1046 if ( orient
== wxHORIZONTAL
)
1049 return m_hScrollBar
->GetThumbSize() ;
1054 return m_vScrollBar
->GetThumbSize() ;
1059 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
1061 if ( orient
== wxHORIZONTAL
)
1064 m_hScrollBar
->SetThumbPosition( pos
) ;
1069 m_vScrollBar
->SetThumbPosition( pos
) ;
1073 void wxWindow::MacCreateRealWindow( const wxString
& title
,
1077 const wxString
& name
)
1080 m_windowStyle
= style
;
1101 m_macWindowData
= new MacWindowData() ;
1103 ::SetRect(&theBoundsRect
, m_x
, m_y
, m_x
+ m_width
, m_y
+ m_height
);
1105 // translate the window attributes in the appropriate window class and attributes
1107 WindowClass wclass
= 0;
1108 WindowAttributes attr
= kWindowNoAttributes
;
1110 if ( HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
) )
1112 wclass
= kFloatingWindowClass
;
1113 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1115 attr
|= kWindowSideTitlebarAttribute
;
1118 else if ( HasFlag( wxCAPTION
) )
1120 if ( HasFlag( wxDIALOG_MODAL
) )
1122 wclass
= kMovableModalWindowClass
;
1126 wclass
= kDocumentWindowClass
;
1131 wclass
= kModalWindowClass
;
1134 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) )
1136 attr
|= kWindowFullZoomAttribute
;
1137 attr
|= kWindowCollapseBoxAttribute
;
1139 if ( HasFlag( wxRESIZE_BORDER
) )
1141 attr
|= kWindowResizableAttribute
;
1143 if ( HasFlag( wxSYSTEM_MENU
) )
1145 attr
|= kWindowCloseBoxAttribute
;
1148 UMACreateNewWindow( wclass
, attr
, &theBoundsRect
, &m_macWindowData
->m_macWindow
) ;
1149 wxAssociateWinWithMacWindow( m_macWindowData
->m_macWindow
, this ) ;
1151 if( wxApp::s_macDefaultEncodingIsPC
)
1152 label
= wxMacMakeMacStringFromPC( title
) ;
1155 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
1156 UMACreateRootControl( m_macWindowData
->m_macWindow
, &m_macWindowData
->m_macRootControl
) ;
1158 m_macWindowData
->m_macFocus
= NULL
;
1159 m_macWindowData
->m_macHasReceivedFirstActivate
= true ;
1162 void wxWindow::MacPaint( wxPaintEvent
&event
)
1166 void wxWindow::MacPaintBorders( )
1168 if( m_macWindowData
)
1171 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1172 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1173 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1174 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1177 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1179 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1180 RGBColor pen1
= sunken
? white
: black
;
1181 RGBColor pen2
= sunken
? shadow
: face
;
1182 RGBColor pen3
= sunken
? face
: shadow
;
1183 RGBColor pen4
= sunken
? black
: white
;
1185 RGBForeColor( &pen1
) ;
1187 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1188 FrameRect( &rect
) ;
1190 RGBForeColor( &pen2
) ;
1192 Rect rect
= { 1 , 1 , m_height
-1 , m_width
-1} ;
1193 FrameRect( &rect
) ;
1195 RGBForeColor( &pen3
) ;
1197 Rect rect
= { 0 , 0 , m_height
-2 , m_width
-2} ;
1198 FrameRect( &rect
) ;
1200 RGBForeColor( &pen4
) ;
1203 LineTo( m_width
- 3 , 0 ) ;
1205 LineTo( 0 , m_height
- 3 ) ;
1208 else if (HasFlag(wxSIMPLE_BORDER
))
1210 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1211 RGBForeColor( &black
) ;
1212 FrameRect( &rect
) ;
1215 if ( this->GetParent() )
1217 wxPaintDC dc(GetParent());
1218 GetParent()->PrepareDC(dc);
1220 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) )
1222 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1224 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1225 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1227 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1228 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1229 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1230 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1233 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1236 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1239 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1242 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1243 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1245 else if (HasFlag(wxDOUBLE_BORDER))
1247 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1249 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1250 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1252 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1253 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1254 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1255 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1258 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1261 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1264 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1267 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1268 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1270 else if (HasFlag(wxSIMPLE_BORDER))
1272 dc.SetPen(*wxBLACK_PEN);
1273 dc.DrawRectangle(m_x, m_y, m_width, m_height);
1279 // New function that will replace some of the above.
1280 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1281 int range
, bool refresh
)
1283 if ( orient
== wxHORIZONTAL
)
1287 if ( range
== 0 || thumbVisible
>= range
)
1289 if ( m_hScrollBar
->IsShown() )
1290 m_hScrollBar
->Show(false) ;
1294 if ( !m_hScrollBar
->IsShown() )
1295 m_hScrollBar
->Show(true) ;
1296 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1304 if ( range
== 0 || thumbVisible
>= range
)
1306 if ( m_vScrollBar
->IsShown() )
1307 m_vScrollBar
->Show(false) ;
1311 if ( !m_vScrollBar
->IsShown() )
1312 m_vScrollBar
->Show(true) ;
1313 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1317 MacRepositionScrollBars() ;
1320 // Does a physical scroll
1321 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1323 wxMacDrawingClientHelper
focus( this ) ;
1326 int width
, height
;
1327 GetClientSize( &width
, &height
) ;
1329 Rect scrollrect
= { 0 , 0 , height
, width
} ;
1331 RgnHandle updateRgn
= NewRgn() ;
1332 ClipRect( &scrollrect
) ;
1335 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
1336 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1338 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1339 InvalWindowRgn( GetMacRootWindow() , updateRgn
) ;
1340 DisposeRgn( updateRgn
) ;
1343 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1345 wxWindow
*child
= (wxWindow
*)node
->Data();
1346 if (child
== m_vScrollBar
) continue;
1347 if (child
== m_hScrollBar
) continue;
1348 if (child
->IsTopLevel()) continue;
1350 child
->GetPosition( &x
, &y
);
1352 child
->GetSize( &w
, &h
);
1353 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1358 void wxWindow::MacOnScroll(wxScrollEvent
&event
)
1360 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1362 wxScrollWinEvent wevent
;
1363 wevent
.SetPosition(event
.GetPosition());
1364 wevent
.SetOrientation(event
.GetOrientation());
1365 wevent
.m_eventObject
= this;
1367 if (event
.m_eventType
== wxEVT_SCROLL_TOP
) {
1368 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1370 if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
) {
1371 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1373 if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
) {
1374 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1376 if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
) {
1377 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1379 if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
) {
1380 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1382 if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
) {
1383 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1385 if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
) {
1386 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1389 GetEventHandler()->ProcessEvent(wevent
);
1393 bool wxWindow::SetFont(const wxFont
& font
)
1395 if ( !wxWindowBase::SetFont(font
) )
1404 // Get the window with the focus
1405 wxWindow
*wxWindowBase::FindFocus()
1407 return gFocusWindow
;
1410 #if WXWIN_COMPATIBILITY
1411 // If nothing defined for this, try the parent.
1412 // E.g. we may be a button loaded from a resource, with no callback function
1414 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1416 if ( GetEventHandler()->ProcessEvent(event
) )
1419 m_parent
->GetEventHandler()->OnCommand(win
, event
);
1421 #endif // WXWIN_COMPATIBILITY_2
1423 #if WXWIN_COMPATIBILITY
1424 wxObject
* wxWindow::GetChild(int number
) const
1426 // Return a pointer to the Nth object in the Panel
1427 wxNode
*node
= GetChildren().First();
1430 node
= node
->Next();
1433 wxObject
*obj
= (wxObject
*)node
->Data();
1439 #endif // WXWIN_COMPATIBILITY
1441 void wxWindow::OnSetFocus(wxFocusEvent
& event
)
1443 // panel wants to track the window which was the last to have focus in it,
1444 // so we want to set ourselves as the window which last had focus
1446 // notice that it's also important to do it upwards the tree becaus
1447 // otherwise when the top level panel gets focus, it won't set it back to
1448 // us, but to some other sibling
1449 wxWindow
*win
= this;
1452 wxWindow
*parent
= win
->GetParent();
1453 wxPanel
*panel
= wxDynamicCast(parent
, wxPanel
);
1456 panel
->SetLastFocus(win
);
1465 void wxWindow::Clear()
1467 if ( m_macWindowData
)
1469 wxMacDrawingClientHelper
helper ( this ) ;
1471 wxPoint origin
= GetClientAreaOrigin() ;
1472 GetClientSize( &w
, &h
) ;
1473 UMASetThemeWindowBackground( m_macWindowData
->m_macWindow
, m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
1474 Rect r
= { origin
.y
, origin
.x
, origin
.y
+h
, origin
.x
+w
} ;
1479 wxClientDC
dc(this);
1480 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1481 dc
.SetBackground(brush
);
1486 // Setup background and foreground colours correctly
1487 void wxWindow::SetupColours()
1490 SetBackgroundColour(GetParent()->GetBackgroundColour());
1493 void wxWindow::OnIdle(wxIdleEvent
& event
)
1496 // Check if we need to send a LEAVE event
1497 if (m_mouseInWindow)
1500 ::GetCursorPos(&pt);
1501 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1503 // Generate a LEAVE event
1504 m_mouseInWindow = FALSE;
1505 MSWOnMouseLeave(pt.x, pt.y, 0);
1510 // This calls the UI-update mechanism (querying windows for
1511 // menu/toolbar/control state information)
1515 // Raise the window to the top of the Z order
1516 void wxWindow::Raise()
1521 // Lower the window to the bottom of the Z order
1522 void wxWindow::Lower()
1527 void wxWindow::DoSetClientSize(int width
, int height
)
1529 if ( width
!= -1 || height
!= -1 )
1532 if ( width
!= -1 && m_vScrollBar
)
1533 width
+= MAC_SCROLLBAR_SIZE
;
1534 if ( height
!= -1 && m_vScrollBar
)
1535 height
+= MAC_SCROLLBAR_SIZE
;
1537 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1538 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1540 DoSetSize( -1 , -1 , width
, height
) ;
1545 wxWindow
* wxWindow::s_lastMouseWindow
= NULL
;
1547 bool wxWindow::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindow
** outWin
)
1549 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1550 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1553 WindowRef window
= GetMacRootWindow() ;
1555 wxPoint
newPoint( point
) ;
1560 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1562 wxWindow
*child
= (wxWindow
*)node
->Data();
1563 // added the m_isShown test --dmazzoni
1564 if ( child
->GetMacRootWindow() == window
&& child
->m_isShown
)
1566 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1575 bool wxWindow::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindow
** outWin
)
1578 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1579 if ( ::FindWindow( pt
, &window
) == 3 )
1581 wxPoint
point( screenpoint
) ;
1582 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1585 win
->ScreenToClient( point
) ;
1586 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1592 extern int wxBusyCursorCount
;
1594 bool wxWindow::MacDispatchMouseEvent(wxMouseEvent
& event
)
1596 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1597 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1601 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) )
1604 WindowRef window
= GetMacRootWindow() ;
1612 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1614 wxWindow
*child
= (wxWindow
*)node
->Data();
1615 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1617 if (child
->MacDispatchMouseEvent(event
))
1625 if ( wxBusyCursorCount
== 0 )
1627 m_cursor
.MacInstall() ;
1630 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1632 // set focus to this window
1633 if (AcceptsFocus() && FindFocus()!=this)
1638 if ( event
.GetEventType() == wxEVT_MOTION
1639 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1640 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1641 wxToolTip::RelayEvent( this , event
);
1642 #endif // wxUSE_TOOLTIPS
1643 GetEventHandler()->ProcessEvent( event
) ;
1650 wxString
wxWindow::MacGetToolTipString( wxPoint
&pt
)
1654 return m_tooltip
->GetTip() ;
1658 void wxWindow::MacFireMouseEvent( EventRecord
*ev
)
1660 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
1661 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1662 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1664 event
.m_leftDown
= isDown
&& !controlDown
;
1665 event
.m_middleDown
= FALSE
;
1666 event
.m_rightDown
= isDown
&& controlDown
;
1668 if ( ev
->what
== mouseDown
)
1671 event
.SetEventType(wxEVT_RIGHT_DOWN
) ;
1673 event
.SetEventType(wxEVT_LEFT_DOWN
) ;
1675 else if ( ev
->what
== mouseUp
)
1678 event
.SetEventType(wxEVT_RIGHT_UP
) ;
1680 event
.SetEventType(wxEVT_LEFT_UP
) ;
1684 event
.SetEventType(wxEVT_MOTION
) ;
1687 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1688 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1689 event
.m_altDown
= ev
->modifiers
& optionKey
;
1690 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1692 Point localwhere
= ev
->where
;
1695 ::GetPort( &port
) ;
1696 ::SetPort( UMAGetWindowPort( m_macWindowData
->m_macWindow
) ) ;
1697 ::GlobalToLocal( &localwhere
) ;
1700 if ( ev
->what
== mouseDown
)
1702 if ( ev
->when
- lastWhen
<= GetDblTime() )
1704 if ( abs( localwhere
.h
- lastWhere
.h
) < 3 || abs( localwhere
.v
- lastWhere
.v
) < 3 )
1707 event
.SetEventType(wxEVT_RIGHT_DCLICK
) ;
1709 event
.SetEventType(wxEVT_LEFT_DCLICK
) ;
1715 lastWhen
= ev
->when
;
1717 lastWhere
= localwhere
;
1720 event
.m_x
= localwhere
.h
;
1721 event
.m_y
= localwhere
.v
;
1726 wxPoint origin = GetClientAreaOrigin() ;
1728 event.m_x += origin.x ;
1729 event.m_y += origin.y ;
1732 event
.m_timeStamp
= ev
->when
;
1733 event
.SetEventObject(this);
1734 if ( wxTheApp
->s_captureWindow
)
1738 wxTheApp
->s_captureWindow
->ScreenToClient( &x
, &y
) ;
1741 wxTheApp
->s_captureWindow
->GetEventHandler()->ProcessEvent( event
) ;
1742 if ( ev
->what
== mouseUp
)
1744 wxTheApp
->s_captureWindow
= NULL
;
1745 if ( wxBusyCursorCount
== 0 )
1747 m_cursor
.MacInstall() ;
1753 MacDispatchMouseEvent( event
) ;
1757 void wxWindow::MacMouseDown( EventRecord
*ev
, short part
)
1759 MacFireMouseEvent( ev
) ;
1762 void wxWindow::MacMouseUp( EventRecord
*ev
, short part
)
1764 WindowPtr frontWindow
;
1769 MacFireMouseEvent( ev
) ;
1775 void wxWindow::MacMouseMoved( EventRecord
*ev
, short part
)
1777 WindowPtr frontWindow
;
1782 MacFireMouseEvent( ev
) ;
1787 void wxWindow::MacActivate( EventRecord
*ev
, bool inIsActivating
)
1789 if ( !m_macWindowData
->m_macHasReceivedFirstActivate
)
1790 m_macWindowData
->m_macHasReceivedFirstActivate
= true ;
1792 wxActivateEvent
event(wxEVT_ACTIVATE
, inIsActivating
, m_windowId
);
1793 event
.m_timeStamp
= ev
->when
;
1794 event
.SetEventObject(this);
1796 GetEventHandler()->ProcessEvent(event
);
1799 UMAHighlightAndActivateWindow( m_macWindowData
->m_macWindow
, inIsActivating
) ;
1800 // MacUpdateImmediately() ;
1803 void wxWindow::MacRedraw( RgnHandle updatergn
, long time
)
1805 // updatergn is always already clipped to our boundaries
1806 WindowRef window
= GetMacRootWindow() ;
1807 // ownUpdateRgn is the area that this window has to invalidate i.e. its own area without its children
1808 RgnHandle ownUpdateRgn
= NewRgn() ;
1809 CopyRgn( updatergn
, ownUpdateRgn
) ;
1810 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1812 wxMacDrawingHelper
focus( this ) ; // was client
1815 WindowRef window
= GetMacRootWindow() ;
1816 bool eraseBackground
= false ;
1817 if ( m_macWindowData
)
1818 eraseBackground
= true ;
1819 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
1821 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
1823 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1825 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1826 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1827 // either a non gray background color or a non control window
1830 wxWindow
* parent
= GetParent() ;
1833 if ( parent
->GetMacRootWindow() != window
)
1835 // we are in a different window on the mac system
1840 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
1842 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1844 // if we have any other colours in the hierarchy
1845 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
1848 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1849 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
1852 GetRegionBounds( updatergn
, &box
) ;
1853 UMAApplyThemeBackground(kThemeBackgroundTabPane
, &box
, kThemeStateActive
,8,true);
1862 parent
= parent
->GetParent() ;
1866 // if there is nothing special -> use default
1867 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
1872 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
1874 // subtract all non transparent children from updatergn
1876 RgnHandle childarea
= NewRgn() ;
1877 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1879 wxWindow
*child
= (wxWindow
*)node
->Data();
1880 // eventually test for transparent windows
1881 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() )
1883 if ( child
->GetBackgroundColour() != m_backgroundColour
&& !child
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)child
)->GetMacControl() )
1885 SetRectRgn( childarea
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1886 DiffRgn( ownUpdateRgn
, childarea
, ownUpdateRgn
) ;
1890 DisposeRgn( childarea
) ;
1892 if ( GetParent() && m_backgroundColour
!= GetParent()->GetBackgroundColour() )
1893 eraseBackground
= true ;
1894 SetClip( ownUpdateRgn
) ;
1895 if ( m_macEraseOnRedraw
) {
1896 if ( eraseBackground
)
1898 EraseRgn( ownUpdateRgn
) ;
1902 m_macEraseOnRedraw
= true ;
1907 RgnHandle newupdate
= NewRgn() ;
1908 wxSize point
= GetClientSize() ;
1909 wxPoint origin
= GetClientAreaOrigin() ;
1911 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1912 SectRgn( newupdate
, ownUpdateRgn
, newupdate
) ;
1913 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1914 m_updateRegion
= newupdate
;
1915 DisposeRgn( newupdate
) ;
1920 event
.m_timeStamp
= time
;
1921 event
.SetEventObject(this);
1922 GetEventHandler()->ProcessEvent(event
);
1926 RgnHandle childupdate
= NewRgn() ;
1928 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1930 wxWindow
*child
= (wxWindow
*)node
->Data();
1931 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1932 SectRgn( childupdate
, updatergn
, childupdate
) ;
1933 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1934 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1936 // because dialogs may also be children
1937 child
->MacRedraw( childupdate
, time
) ;
1940 DisposeRgn( childupdate
) ;
1941 // eventually a draw grow box here
1944 void wxWindow::MacUpdateImmediately()
1946 WindowRef window
= GetMacRootWindow() ;
1949 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1951 AGAPortHelper
help( GetWindowPort(window
) ) ;
1953 AGAPortHelper
help( (window
) ) ;
1955 SetOrigin( 0 , 0 ) ;
1956 BeginUpdate( window
) ;
1959 RgnHandle region
= NewRgn();
1963 GetPortVisibleRegion( GetWindowPort( window
), region
);
1965 // if windowshade gives incompatibility , take the follwing out
1966 if ( !EmptyRgn( region
) && win
->m_macWindowData
->m_macHasReceivedFirstActivate
)
1968 win
->MacRedraw( region
, wxTheApp
->sm_lastMessageTime
) ;
1970 DisposeRgn( region
);
1973 EndUpdate( window
) ;
1977 void wxWindow::MacUpdate( EventRecord
*ev
)
1979 WindowRef window
= (WindowRef
) ev
->message
;
1980 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1982 AGAPortHelper
help( GetWindowPort(window
) ) ;
1984 AGAPortHelper
help( (window
) ) ;
1986 SetOrigin( 0 , 0 ) ;
1987 BeginUpdate( window
) ;
1990 RgnHandle region
= NewRgn();
1994 GetPortVisibleRegion( GetWindowPort( window
), region
);
1996 // if windowshade gives incompatibility , take the follwing out
1997 if ( !EmptyRgn( region
) && win
->m_macWindowData
->m_macHasReceivedFirstActivate
)
1999 MacRedraw( region
, ev
->when
) ;
2001 DisposeRgn( region
);
2004 EndUpdate( window
) ;
2007 WindowRef
wxWindow::GetMacRootWindow() const
2009 WindowRef window
= NULL
;
2010 wxWindow
*iter
= (wxWindow
*)this ;
2014 if ( iter
->m_macWindowData
)
2015 return iter
->m_macWindowData
->m_macWindow
;
2017 iter
= iter
->GetParent() ;
2019 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
2023 void wxWindow::MacCreateScrollBars( long style
)
2025 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
2027 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2028 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2030 GetClientSize( &width
, &height
) ;
2032 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2033 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2034 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2035 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2037 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2038 vSize
, wxVERTICAL
);
2040 if ( style
& wxVSCROLL
)
2046 m_vScrollBar
->Show(false) ;
2048 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2049 hSize
, wxHORIZONTAL
);
2050 if ( style
& wxHSCROLL
)
2055 m_hScrollBar
->Show(false) ;
2058 // because the create does not take into account the client area origin
2059 MacRepositionScrollBars() ; // we might have a real position shift
2062 void wxWindow::MacRepositionScrollBars()
2064 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2065 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2067 // get real client area
2069 int width
= m_width
;
2070 int height
= m_height
;
2072 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2073 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2075 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2076 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2077 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2078 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2085 MacClientToRootWindow( &x
, &y
) ;
2086 MacClientToRootWindow( &w
, &h
) ;
2088 WindowRef window
= NULL
;
2089 wxWindow
*iter
= (wxWindow
*)this ;
2091 int totW
= 10000 , totH
= 10000;
2094 if ( iter
->m_macWindowData
)
2096 totW
= iter
->m_width
;
2097 totH
= iter
->m_height
;
2101 iter
= iter
->GetParent() ;
2129 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2133 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2137 void wxWindow::MacKeyDown( EventRecord
*ev
)
2143 bool wxWindow::AcceptsFocus() const
2145 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2148 ControlHandle
wxWindow::MacGetContainerForEmbedding()
2150 if ( m_macWindowData
)
2151 return m_macWindowData
->m_macRootControl
;
2153 return GetParent()->MacGetContainerForEmbedding() ;
2156 void wxWindow::MacSuperChangedPosition()
2158 // only window-absolute structures have to be moved i.e. controls
2160 wxNode
*node
= GetChildren().First();
2163 wxWindow
*child
= (wxWindow
*)node
->Data();
2164 child
->MacSuperChangedPosition() ;
2165 node
= node
->Next();
2169 bool wxWindow::MacSetPortFocusParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
2171 if ( window
== NULL
)
2177 ::GetPort(&currPort
);
2178 port
= UMAGetWindowPort( window
) ;
2179 if (currPort
!= port
)
2182 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2183 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2187 bool wxWindow::MacSetPortDrawingParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
2189 if ( window
== NULL
)
2194 ::GetPort(&currPort
);
2195 port
= UMAGetWindowPort( window
) ;
2196 if (currPort
!= port
)
2198 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2199 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2200 ::ClipRect(&clipRect
);
2203 ::RGBBackColor(& win
->GetBackgroundColour().GetPixel() ) ;
2204 ::RGBForeColor(& win
->GetForegroundColour().GetPixel() ) ;
2205 Pattern whiteColor
;
2207 ::BackPat( GetQDGlobalsWhite( &whiteColor
) ) ;
2208 ::UMASetThemeWindowBackground( win
->m_macWindowData
->m_macWindow
, win
->m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
2212 void wxWindow::MacGetPortParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2214 if ( m_macWindowData
)
2220 clipRect
->right
= m_width
;
2221 clipRect
->bottom
= m_height
;
2222 *window
= m_macWindowData
->m_macWindow
;
2227 wxASSERT( GetParent() != NULL
) ;
2228 GetParent()->MacGetPortParams( localOrigin
, clipRect
, window
, rootwin
) ;
2229 localOrigin
->h
+= m_x
;
2230 localOrigin
->v
+= m_y
;
2231 OffsetRect(clipRect
, -m_x
, -m_y
);
2236 myClip
.right
= m_width
;
2237 myClip
.bottom
= m_height
;
2238 SectRect(clipRect
, &myClip
, clipRect
);
2242 void wxWindow::MacDoGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2244 // int width , height ;
2245 // GetClientSize( &width , &height ) ;
2247 if ( m_macWindowData
)
2253 clipRect
->right
= m_width
;//width;
2254 clipRect
->bottom
= m_height
;// height;
2255 *window
= m_macWindowData
->m_macWindow
;
2260 wxASSERT( GetParent() != NULL
) ;
2262 GetParent()->MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2264 localOrigin
->h
+= m_x
;
2265 localOrigin
->v
+= m_y
;
2266 OffsetRect(clipRect
, -m_x
, -m_y
);
2271 myClip
.right
= m_width
;//width;
2272 myClip
.bottom
= m_height
;// height;
2273 SectRect(clipRect
, &myClip
, clipRect
);
2277 void wxWindow::MacGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2279 MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2281 int width
, height
;
2282 GetClientSize( &width
, &height
) ;
2284 client
= GetClientAreaOrigin( ) ;
2286 localOrigin
->h
+= client
.x
;
2287 localOrigin
->v
+= client
.y
;
2288 OffsetRect(clipRect
, -client
.x
, -client
.y
);
2293 myClip
.right
= width
;
2294 myClip
.bottom
= height
;
2295 SectRect(clipRect
, &myClip
, clipRect
);
2298 long wxWindow::MacGetLeftBorderSize( ) const
2300 if( m_macWindowData
)
2303 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2307 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2311 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2318 long wxWindow::MacGetRightBorderSize( ) const
2320 if( m_macWindowData
)
2323 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2327 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2331 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2338 long wxWindow::MacGetTopBorderSize( ) const
2340 if( m_macWindowData
)
2343 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2347 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2351 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2358 long wxWindow::MacGetBottomBorderSize( ) const
2360 if( m_macWindowData
)
2363 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2367 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2371 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2378 long wxWindow::MacRemoveBordersFromStyle( long style
)
2380 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2384 wxMacDrawingHelper::wxMacDrawingHelper( wxWindow
* theWindow
)
2391 m_currentPort
= NULL
;
2393 GetPort( &m_formerPort
) ;
2396 theWindow
->MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2397 m_currentPort
= UMAGetWindowPort( window
) ;
2398 if ( m_formerPort
!= m_currentPort
)
2399 SetPort( m_currentPort
) ;
2400 GetPenState( &m_savedPenState
) ;
2401 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2406 wxMacDrawingHelper::~wxMacDrawingHelper()
2410 SetPort( m_currentPort
) ;
2411 SetPenState( &m_savedPenState
) ;
2412 SetOrigin( 0 , 0 ) ;
2414 GetPortBounds( m_currentPort
, &portRect
) ;
2415 ClipRect( &portRect
) ;
2418 if ( m_formerPort
!= m_currentPort
)
2419 SetPort( m_formerPort
) ;
2422 wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindow
* theWindow
)
2429 m_currentPort
= NULL
;
2431 GetPort( &m_formerPort
) ;
2435 theWindow
->MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2436 m_currentPort
= UMAGetWindowPort( window
) ;
2437 if ( m_formerPort
!= m_currentPort
)
2438 SetPort( m_currentPort
) ;
2439 GetPenState( &m_savedPenState
) ;
2440 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2445 wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
2449 SetPort( m_currentPort
) ;
2450 SetPenState( &m_savedPenState
) ;
2451 SetOrigin( 0 , 0 ) ;
2453 GetPortBounds( m_currentPort
, &portRect
) ;
2454 ClipRect( &portRect
) ;
2457 if ( m_formerPort
!= m_currentPort
)
2458 SetPort( m_formerPort
) ;
2461 // Find the wxWindow at the current mouse position, returning the mouse
2463 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
2465 pt
= wxGetMousePosition();
2466 wxWindow
* found
= wxFindWindowAtPoint(pt
);
2470 // Get the current mouse position.
2471 wxPoint
wxGetMousePosition()
2474 wxGetMousePosition(& x
, & y
);
2475 return wxPoint(x
, y
);