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 wxWindow
* wxWindowBase::GetCapture()
301 return wxTheApp
->s_captureWindow
;
304 void wxWindow::ReleaseMouse()
306 wxTheApp
->s_captureWindow
= NULL
;
309 #if wxUSE_DRAG_AND_DROP
311 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
313 if ( m_pDropTarget
!= 0 ) {
314 delete m_pDropTarget
;
317 m_pDropTarget
= pDropTarget
;
318 if ( m_pDropTarget
!= 0 )
326 // Old style file-manager drag&drop
327 void wxWindow::DragAcceptFiles(bool accept
)
333 void wxWindow::DoGetSize(int *x
, int *y
) const
339 void wxWindow::DoGetPosition(int *x
, int *y
) const
345 wxPoint
pt(GetParent()->GetClientAreaOrigin());
352 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
354 menu
->SetInvokingWindow(this);
356 ClientToScreen( &x
, &y
) ;
358 ::InsertMenu( menu
->GetHMenu() , -1 ) ;
359 long menuResult
= ::PopUpMenuSelect(menu
->GetHMenu() ,y
,x
, 0) ;
360 menu
->MacMenuSelect( this , TickCount() , HiWord(menuResult
) , LoWord(menuResult
) ) ;
361 ::DeleteMenu( menu
->MacGetMenuId() ) ;
362 menu
->SetInvokingWindow(NULL
);
367 void wxWindow::DoScreenToClient(int *x
, int *y
) const
369 WindowRef window
= GetMacRootWindow() ;
377 ::SetPort( UMAGetWindowPort( window
) ) ;
378 ::GlobalToLocal( &localwhere
) ;
384 MacRootWindowToClient( x
, y
) ;
387 void wxWindow::DoClientToScreen(int *x
, int *y
) const
389 WindowRef window
= GetMacRootWindow() ;
391 MacClientToRootWindow( x
, y
) ;
399 ::SetPort( UMAGetWindowPort( window
) ) ;
400 ::SetOrigin( 0 , 0 ) ;
401 ::LocalToGlobal( &localwhere
) ;
407 void wxWindow::MacClientToRootWindow( int *x
, int *y
) const
409 if ( m_macWindowData
)
416 GetParent()->MacClientToRootWindow( x
, y
) ;
420 void wxWindow::MacRootWindowToClient( int *x
, int *y
) const
422 if ( m_macWindowData
)
429 GetParent()->MacRootWindowToClient( x
, y
) ;
433 bool wxWindow::SetCursor(const wxCursor
& cursor
)
435 if (m_cursor
== cursor
)
438 if (wxNullCursor
== cursor
)
440 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
445 if ( ! wxWindowBase::SetCursor( cursor
) )
449 wxASSERT_MSG( m_cursor
.Ok(),
450 wxT("cursor must be valid after call to the base version"));
456 // Change the cursor NOW if we're within the correct window
458 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
460 if ( mouseWin
== this && !wxIsBusy() )
462 m_cursor
.MacInstall() ;
470 // Get size *available for subwindows* i.e. excluding menu bar etc.
471 void wxWindow::DoGetClientSize(int *x
, int *y
) const
476 *x
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
477 *y
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
479 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
486 MacClientToRootWindow( &x1
, &y1
) ;
487 MacClientToRootWindow( &w
, &h
) ;
489 WindowRef window
= NULL
;
490 wxWindow
*iter
= (wxWindow
*)this ;
492 int totW
= 10000 , totH
= 10000;
495 if ( iter
->m_macWindowData
)
497 totW
= iter
->m_width
;
498 totH
= iter
->m_height
;
502 iter
= iter
->GetParent() ;
505 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
507 (*y
) -= MAC_SCROLLBAR_SIZE
;
513 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
515 (*x
) -= MAC_SCROLLBAR_SIZE
;
525 // ----------------------------------------------------------------------------
527 // ----------------------------------------------------------------------------
531 void wxWindow::DoSetToolTip(wxToolTip
*tooltip
)
533 wxWindowBase::DoSetToolTip(tooltip
);
536 m_tooltip
->SetWindow(this);
539 #endif // wxUSE_TOOLTIPS
541 void wxWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
543 DoSetSize( x
,y
, width
, height
) ;
546 // set the size of the window: if the dimensions are positive, just use them,
547 // but if any of them is equal to -1, it means that we must find the value for
548 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
549 // which case -1 is a valid value for x and y)
551 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
552 // the width/height to best suit our contents, otherwise we reuse the current
554 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
559 int former_w
= m_width
;
560 int former_h
= m_height
;
562 int currentX
, currentY
;
563 GetPosition(¤tX
, ¤tY
);
564 int currentW
,currentH
;
565 GetSize(¤tW
, ¤tH
);
567 int actualWidth
= width
;
568 int actualHeight
= height
;
571 if (x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
573 if (y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
576 wxSize
size( -1 , -1 ) ;
578 if (width
== -1 || height
== -1 )
580 size
= DoGetBestSize() ;
585 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
587 actualWidth
= size
.x
;
588 if ( actualWidth
== -1 )
593 actualWidth
= currentW
;
598 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
600 actualHeight
= size
.y
;
601 if ( actualHeight
== -1 )
606 actualHeight
= currentH
;
610 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
611 actualWidth
= m_minWidth
;
612 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
613 actualHeight
= m_minHeight
;
614 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
615 actualWidth
= m_maxWidth
;
616 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
617 actualHeight
= m_maxHeight
;
618 if ( actualX
== currentX
&& actualY
== currentY
&& actualWidth
== currentW
&& actualHeight
== currentH
)
620 MacRepositionScrollBars() ; // we might have a real position shift
624 AdjustForParentClientOrigin(actualX
, actualY
, sizeFlags
);
627 bool doMove
= false ;
628 bool doResize
= false ;
630 if ( actualX
!= former_x
|| actualY
!= former_y
)
634 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
639 if ( doMove
|| doResize
)
641 if ( m_macWindowData
)
646 // erase former position
647 wxMacDrawingHelper
focus( this ) ;
650 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
651 // ClipRect( &clientrect ) ;
652 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
657 m_width
= actualWidth
;
658 m_height
= actualHeight
;
659 if ( m_macWindowData
)
662 ::MoveWindow(m_macWindowData
->m_macWindow
, m_x
, m_y
, false); // don't make frontmost
665 ::SizeWindow(m_macWindowData
->m_macWindow
, m_width
, m_height
, true);
667 // the OS takes care of invalidating and erasing the new area
668 // we have erased the old one
670 if ( IsKindOf( CLASSINFO( wxFrame
) ) )
672 wxFrame
* frame
= (wxFrame
*) this ;
673 frame
->PositionStatusBar();
674 frame
->PositionToolBar();
679 // erase new position
682 wxMacDrawingHelper
focus( this ) ;
685 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
686 // ClipRect( &clientrect ) ;
687 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
692 wxWindow::MacSuperChangedPosition() ; // like this only children will be notified
694 MacRepositionScrollBars() ;
697 wxPoint
point(m_x
, m_y
);
698 wxMoveEvent
event(point
, m_windowId
);
699 event
.SetEventObject(this);
700 GetEventHandler()->ProcessEvent(event
) ;
704 MacRepositionScrollBars() ;
705 wxSize
size(m_width
, m_height
);
706 wxSizeEvent
event(size
, m_windowId
);
707 event
.SetEventObject(this);
708 GetEventHandler()->ProcessEvent(event
);
712 // For implementation purposes - sometimes decorations make the client area
715 wxPoint
wxWindow::GetClientAreaOrigin() const
717 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
720 // Makes an adjustment to the window position (for example, a frame that has
721 // a toolbar that it manages itself).
722 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
724 if( !m_macWindowData
)
726 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
728 wxPoint
pt(GetParent()->GetClientAreaOrigin());
729 x
+= pt
.x
; y
+= pt
.y
;
734 void wxWindow::SetTitle(const wxString
& title
)
740 if( wxApp::s_macDefaultEncodingIsPC
)
741 label
= wxMacMakeMacStringFromPC( title
) ;
745 if ( m_macWindowData
)
746 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
749 wxString
wxWindow::GetTitle() const
754 bool wxWindow::Show(bool show
)
756 if ( !wxWindowBase::Show(show
) )
759 if ( m_macWindowData
)
763 UMAShowWindow( m_macWindowData
->m_macWindow
) ;
764 UMASelectWindow( m_macWindowData
->m_macWindow
) ;
765 // no need to generate events here, they will get them triggered by macos
766 // actually they should be , but apparently they are not
767 wxSize
size(m_width
, m_height
);
768 wxSizeEvent
event(size
, m_windowId
);
769 event
.SetEventObject(this);
770 GetEventHandler()->ProcessEvent(event
);
774 UMAHideWindow( m_macWindowData
->m_macWindow
) ;
777 MacSuperShown( show
) ;
780 WindowRef window
= GetMacRootWindow() ;
781 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
782 if ( !win
->m_isBeingDeleted
)
793 void wxWindow::MacSuperShown( bool show
)
795 wxNode
*node
= GetChildren().First();
798 wxWindow
*child
= (wxWindow
*)node
->Data();
799 if ( child
->m_isShown
)
800 child
->MacSuperShown( show
) ;
805 bool wxWindow::MacIsReallyShown() const
807 if ( m_isShown
&& (m_parent
!= NULL
) ) {
808 return m_parent
->MacIsReallyShown();
812 bool status = m_isShown ;
813 wxWindow * win = this ;
814 while ( status && win->m_parent != NULL )
816 win = win->m_parent ;
817 status = win->m_isShown ;
823 int wxWindow::GetCharHeight() const
825 wxClientDC
dc ( (wxWindow
*)this ) ;
826 return dc
.GetCharHeight() ;
829 int wxWindow::GetCharWidth() const
831 wxClientDC
dc ( (wxWindow
*)this ) ;
832 return dc
.GetCharWidth() ;
835 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
836 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
838 const wxFont
*fontToUse
= theFont
;
842 wxClientDC
dc( (wxWindow
*) this ) ;
844 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
845 if ( externalLeading
)
846 *externalLeading
= le
;
855 void wxWindow::MacEraseBackground( Rect
*rect
)
858 WindowRef window = GetMacRootWindow() ;
859 if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
861 UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ;
863 else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
865 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
866 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
867 // either a non gray background color or a non control window
869 wxWindow* parent = GetParent() ;
872 if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
874 // if we have any other colours in the hierarchy
875 RGBBackColor( &parent->m_backgroundColour.GetPixel()) ;
878 if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() )
880 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
881 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
883 UMAApplyThemeBackground(kThemeBackgroundTabPane, rect, kThemeStateActive,8,true);
889 // we have arrived at a non control item
893 parent = parent->GetParent() ;
897 // if there is nothing special -> use default
898 UMASetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ;
903 RGBBackColor( &m_backgroundColour.GetPixel()) ;
908 for (wxNode *node = GetChildren().First(); node; node = node->Next())
910 wxWindow *child = (wxWindow*)node->Data();
912 Rect clientrect = { child->m_x , child->m_y , child->m_x +child->m_width , child->m_y + child->m_height } ;
913 SectRect( &clientrect , rect , &clientrect ) ;
915 OffsetRect( &clientrect , -child->m_x , -child->m_y ) ;
916 if ( child->GetMacRootWindow() == window && child->IsShown() )
918 wxMacDrawingClientHelper focus( this ) ;
921 child->MacEraseBackground( &clientrect ) ;
928 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
933 wxMacDrawingClientHelper
focus( this ) ;
937 client
= GetClientAreaOrigin( ) ;
938 Rect clientrect
= { -client
.y
, -client
.x
, m_height
- client
.y
, m_width
- client
.x
} ;
939 // ClipRect( &clientrect ) ;
943 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
944 SectRect( &clientrect
, &r
, &clientrect
) ;
946 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
949 m_macEraseOnRedraw
= false ;
951 m_macEraseOnRedraw
= true ;
954 // Responds to colour changes: passes event on to children.
955 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
957 wxNode
*node
= GetChildren().First();
960 // Only propagate to non-top-level windows
961 wxWindow
*win
= (wxWindow
*)node
->Data();
962 if ( win
->GetParent() )
964 wxSysColourChangedEvent event2
;
965 event
.m_eventObject
= win
;
966 win
->GetEventHandler()->ProcessEvent(event2
);
973 #if wxUSE_CARET && WXWIN_COMPATIBILITY
974 // ---------------------------------------------------------------------------
975 // Caret manipulation
976 // ---------------------------------------------------------------------------
978 void wxWindow::CreateCaret(int w
, int h
)
980 SetCaret(new wxCaret(this, w
, h
));
983 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
985 wxFAIL_MSG("not implemented");
988 void wxWindow::ShowCaret(bool show
)
990 wxCHECK_RET( m_caret
, "no caret to show" );
995 void wxWindow::DestroyCaret()
1000 void wxWindow::SetCaretPos(int x
, int y
)
1002 wxCHECK_RET( m_caret
, "no caret to move" );
1004 m_caret
->Move(x
, y
);
1007 void wxWindow::GetCaretPos(int *x
, int *y
) const
1009 wxCHECK_RET( m_caret
, "no caret to get position of" );
1011 m_caret
->GetPosition(x
, y
);
1013 #endif // wxUSE_CARET
1015 wxWindow
*wxGetActiveWindow()
1017 // actually this is a windows-only concept
1021 // Coordinates relative to the window
1022 void wxWindow::WarpPointer (int x_pos
, int y_pos
)
1024 // We really dont move the mouse programmatically under mac
1027 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
1029 // TODO : probably we would adopt the EraseEvent structure
1032 int wxWindow::GetScrollPos(int orient
) const
1034 if ( orient
== wxHORIZONTAL
)
1037 return m_hScrollBar
->GetThumbPosition() ;
1042 return m_vScrollBar
->GetThumbPosition() ;
1047 // This now returns the whole range, not just the number
1048 // of positions that we can scroll.
1049 int wxWindow::GetScrollRange(int orient
) const
1051 if ( orient
== wxHORIZONTAL
)
1054 return m_hScrollBar
->GetRange() ;
1059 return m_vScrollBar
->GetRange() ;
1064 int wxWindow::GetScrollThumb(int orient
) const
1066 if ( orient
== wxHORIZONTAL
)
1069 return m_hScrollBar
->GetThumbSize() ;
1074 return m_vScrollBar
->GetThumbSize() ;
1079 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
1081 if ( orient
== wxHORIZONTAL
)
1084 m_hScrollBar
->SetThumbPosition( pos
) ;
1089 m_vScrollBar
->SetThumbPosition( pos
) ;
1093 void wxWindow::MacCreateRealWindow( const wxString
& title
,
1097 const wxString
& name
)
1100 m_windowStyle
= style
;
1121 m_macWindowData
= new MacWindowData() ;
1123 ::SetRect(&theBoundsRect
, m_x
, m_y
, m_x
+ m_width
, m_y
+ m_height
);
1125 // translate the window attributes in the appropriate window class and attributes
1127 WindowClass wclass
= 0;
1128 WindowAttributes attr
= kWindowNoAttributes
;
1130 if ( HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
) )
1132 wclass
= kFloatingWindowClass
;
1133 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1135 attr
|= kWindowSideTitlebarAttribute
;
1138 else if ( HasFlag( wxCAPTION
) )
1140 if ( HasFlag( wxDIALOG_MODAL
) )
1142 wclass
= kMovableModalWindowClass
;
1146 wclass
= kDocumentWindowClass
;
1151 wclass
= kModalWindowClass
;
1154 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) )
1156 attr
|= kWindowFullZoomAttribute
;
1157 attr
|= kWindowCollapseBoxAttribute
;
1159 if ( HasFlag( wxRESIZE_BORDER
) )
1161 attr
|= kWindowResizableAttribute
;
1163 if ( HasFlag( wxSYSTEM_MENU
) )
1165 attr
|= kWindowCloseBoxAttribute
;
1168 UMACreateNewWindow( wclass
, attr
, &theBoundsRect
, &m_macWindowData
->m_macWindow
) ;
1169 wxAssociateWinWithMacWindow( m_macWindowData
->m_macWindow
, this ) ;
1171 if( wxApp::s_macDefaultEncodingIsPC
)
1172 label
= wxMacMakeMacStringFromPC( title
) ;
1175 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
1176 UMACreateRootControl( m_macWindowData
->m_macWindow
, &m_macWindowData
->m_macRootControl
) ;
1178 m_macWindowData
->m_macFocus
= NULL
;
1179 m_macWindowData
->m_macHasReceivedFirstActivate
= true ;
1182 void wxWindow::MacPaint( wxPaintEvent
&event
)
1186 void wxWindow::MacPaintBorders( )
1188 if( m_macWindowData
)
1191 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1192 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1193 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1194 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1197 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1199 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1200 RGBColor pen1
= sunken
? white
: black
;
1201 RGBColor pen2
= sunken
? shadow
: face
;
1202 RGBColor pen3
= sunken
? face
: shadow
;
1203 RGBColor pen4
= sunken
? black
: white
;
1205 RGBForeColor( &pen1
) ;
1207 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1208 FrameRect( &rect
) ;
1210 RGBForeColor( &pen2
) ;
1212 Rect rect
= { 1 , 1 , m_height
-1 , m_width
-1} ;
1213 FrameRect( &rect
) ;
1215 RGBForeColor( &pen3
) ;
1217 Rect rect
= { 0 , 0 , m_height
-2 , m_width
-2} ;
1218 FrameRect( &rect
) ;
1220 RGBForeColor( &pen4
) ;
1223 LineTo( m_width
- 3 , 0 ) ;
1225 LineTo( 0 , m_height
- 3 ) ;
1228 else if (HasFlag(wxSIMPLE_BORDER
))
1230 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1231 RGBForeColor( &black
) ;
1232 FrameRect( &rect
) ;
1235 if ( this->GetParent() )
1237 wxPaintDC dc(GetParent());
1238 GetParent()->PrepareDC(dc);
1240 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) )
1242 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1244 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1245 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1247 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1248 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1249 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1250 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1253 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1256 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1259 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1262 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1263 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1265 else if (HasFlag(wxDOUBLE_BORDER))
1267 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1269 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1270 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1272 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1273 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1274 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1275 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1278 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1281 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1284 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1287 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1288 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1290 else if (HasFlag(wxSIMPLE_BORDER))
1292 dc.SetPen(*wxBLACK_PEN);
1293 dc.DrawRectangle(m_x, m_y, m_width, m_height);
1299 // New function that will replace some of the above.
1300 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1301 int range
, bool refresh
)
1303 if ( orient
== wxHORIZONTAL
)
1307 if ( range
== 0 || thumbVisible
>= range
)
1309 if ( m_hScrollBar
->IsShown() )
1310 m_hScrollBar
->Show(false) ;
1314 if ( !m_hScrollBar
->IsShown() )
1315 m_hScrollBar
->Show(true) ;
1316 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1324 if ( range
== 0 || thumbVisible
>= range
)
1326 if ( m_vScrollBar
->IsShown() )
1327 m_vScrollBar
->Show(false) ;
1331 if ( !m_vScrollBar
->IsShown() )
1332 m_vScrollBar
->Show(true) ;
1333 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1337 MacRepositionScrollBars() ;
1340 // Does a physical scroll
1341 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1343 wxMacDrawingClientHelper
focus( this ) ;
1346 int width
, height
;
1347 GetClientSize( &width
, &height
) ;
1349 Rect scrollrect
= { 0 , 0 , height
, width
} ;
1351 RgnHandle updateRgn
= NewRgn() ;
1352 ClipRect( &scrollrect
) ;
1355 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
1356 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1358 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1359 InvalWindowRgn( GetMacRootWindow() , updateRgn
) ;
1360 DisposeRgn( updateRgn
) ;
1363 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1365 wxWindow
*child
= (wxWindow
*)node
->Data();
1366 if (child
== m_vScrollBar
) continue;
1367 if (child
== m_hScrollBar
) continue;
1368 if (child
->IsTopLevel()) continue;
1370 child
->GetPosition( &x
, &y
);
1372 child
->GetSize( &w
, &h
);
1373 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1378 void wxWindow::MacOnScroll(wxScrollEvent
&event
)
1380 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1382 wxScrollWinEvent wevent
;
1383 wevent
.SetPosition(event
.GetPosition());
1384 wevent
.SetOrientation(event
.GetOrientation());
1385 wevent
.m_eventObject
= this;
1387 if (event
.m_eventType
== wxEVT_SCROLL_TOP
) {
1388 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1390 if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
) {
1391 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1393 if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
) {
1394 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1396 if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
) {
1397 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1399 if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
) {
1400 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1402 if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
) {
1403 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1405 if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
) {
1406 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1409 GetEventHandler()->ProcessEvent(wevent
);
1413 bool wxWindow::SetFont(const wxFont
& font
)
1415 if ( !wxWindowBase::SetFont(font
) )
1424 // Get the window with the focus
1425 wxWindow
*wxWindowBase::FindFocus()
1427 return gFocusWindow
;
1430 #if WXWIN_COMPATIBILITY
1431 // If nothing defined for this, try the parent.
1432 // E.g. we may be a button loaded from a resource, with no callback function
1434 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1436 if ( GetEventHandler()->ProcessEvent(event
) )
1439 m_parent
->GetEventHandler()->OnCommand(win
, event
);
1441 #endif // WXWIN_COMPATIBILITY_2
1443 #if WXWIN_COMPATIBILITY
1444 wxObject
* wxWindow::GetChild(int number
) const
1446 // Return a pointer to the Nth object in the Panel
1447 wxNode
*node
= GetChildren().First();
1450 node
= node
->Next();
1453 wxObject
*obj
= (wxObject
*)node
->Data();
1459 #endif // WXWIN_COMPATIBILITY
1461 void wxWindow::OnSetFocus(wxFocusEvent
& event
)
1463 // panel wants to track the window which was the last to have focus in it,
1464 // so we want to set ourselves as the window which last had focus
1466 // notice that it's also important to do it upwards the tree becaus
1467 // otherwise when the top level panel gets focus, it won't set it back to
1468 // us, but to some other sibling
1469 wxWindow
*win
= this;
1472 wxWindow
*parent
= win
->GetParent();
1473 wxPanel
*panel
= wxDynamicCast(parent
, wxPanel
);
1476 panel
->SetLastFocus(win
);
1485 void wxWindow::Clear()
1487 if ( m_macWindowData
)
1489 wxMacDrawingClientHelper
helper ( this ) ;
1491 wxPoint origin
= GetClientAreaOrigin() ;
1492 GetClientSize( &w
, &h
) ;
1493 UMASetThemeWindowBackground( m_macWindowData
->m_macWindow
, m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
1494 Rect r
= { origin
.y
, origin
.x
, origin
.y
+h
, origin
.x
+w
} ;
1499 wxClientDC
dc(this);
1500 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1501 dc
.SetBackground(brush
);
1506 // Setup background and foreground colours correctly
1507 void wxWindow::SetupColours()
1510 SetBackgroundColour(GetParent()->GetBackgroundColour());
1513 void wxWindow::OnIdle(wxIdleEvent
& event
)
1516 // Check if we need to send a LEAVE event
1517 if (m_mouseInWindow)
1520 ::GetCursorPos(&pt);
1521 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1523 // Generate a LEAVE event
1524 m_mouseInWindow = FALSE;
1525 MSWOnMouseLeave(pt.x, pt.y, 0);
1530 // This calls the UI-update mechanism (querying windows for
1531 // menu/toolbar/control state information)
1535 // Raise the window to the top of the Z order
1536 void wxWindow::Raise()
1538 if ( m_macWindowData
)
1540 UMABringToFront( m_macWindowData
->m_macWindow
) ;
1544 // Lower the window to the bottom of the Z order
1545 void wxWindow::Lower()
1547 if ( m_macWindowData
)
1549 UMASendBehind( m_macWindowData
->m_macWindow
, NULL
) ;
1553 void wxWindow::DoSetClientSize(int width
, int height
)
1555 if ( width
!= -1 || height
!= -1 )
1558 if ( width
!= -1 && m_vScrollBar
)
1559 width
+= MAC_SCROLLBAR_SIZE
;
1560 if ( height
!= -1 && m_vScrollBar
)
1561 height
+= MAC_SCROLLBAR_SIZE
;
1563 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1564 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1566 DoSetSize( -1 , -1 , width
, height
) ;
1571 wxWindow
* wxWindow::s_lastMouseWindow
= NULL
;
1573 bool wxWindow::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindow
** outWin
)
1575 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1576 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1579 WindowRef window
= GetMacRootWindow() ;
1581 wxPoint
newPoint( point
) ;
1586 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1588 wxWindow
*child
= (wxWindow
*)node
->Data();
1589 // added the m_isShown test --dmazzoni
1590 if ( child
->GetMacRootWindow() == window
&& child
->m_isShown
)
1592 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1601 bool wxWindow::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindow
** outWin
)
1604 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1605 if ( ::FindWindow( pt
, &window
) == 3 )
1607 wxPoint
point( screenpoint
) ;
1608 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1611 win
->ScreenToClient( point
) ;
1612 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1618 extern int wxBusyCursorCount
;
1620 bool wxWindow::MacDispatchMouseEvent(wxMouseEvent
& event
)
1622 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1623 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1627 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) )
1630 WindowRef window
= GetMacRootWindow() ;
1638 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1640 wxWindow
*child
= (wxWindow
*)node
->Data();
1641 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1643 if (child
->MacDispatchMouseEvent(event
))
1651 if ( wxBusyCursorCount
== 0 )
1653 m_cursor
.MacInstall() ;
1656 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1658 // set focus to this window
1659 if (AcceptsFocus() && FindFocus()!=this)
1664 if ( event
.GetEventType() == wxEVT_MOTION
1665 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1666 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1667 wxToolTip::RelayEvent( this , event
);
1668 #endif // wxUSE_TOOLTIPS
1669 GetEventHandler()->ProcessEvent( event
) ;
1676 wxString
wxWindow::MacGetToolTipString( wxPoint
&pt
)
1680 return m_tooltip
->GetTip() ;
1684 void wxWindow::MacFireMouseEvent( EventRecord
*ev
)
1686 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
1687 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1688 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1690 event
.m_leftDown
= isDown
&& !controlDown
;
1691 event
.m_middleDown
= FALSE
;
1692 event
.m_rightDown
= isDown
&& controlDown
;
1694 if ( ev
->what
== mouseDown
)
1697 event
.SetEventType(wxEVT_RIGHT_DOWN
) ;
1699 event
.SetEventType(wxEVT_LEFT_DOWN
) ;
1701 else if ( ev
->what
== mouseUp
)
1704 event
.SetEventType(wxEVT_RIGHT_UP
) ;
1706 event
.SetEventType(wxEVT_LEFT_UP
) ;
1710 event
.SetEventType(wxEVT_MOTION
) ;
1713 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1714 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1715 event
.m_altDown
= ev
->modifiers
& optionKey
;
1716 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1718 Point localwhere
= ev
->where
;
1721 ::GetPort( &port
) ;
1722 ::SetPort( UMAGetWindowPort( m_macWindowData
->m_macWindow
) ) ;
1723 ::GlobalToLocal( &localwhere
) ;
1726 if ( ev
->what
== mouseDown
)
1728 if ( ev
->when
- lastWhen
<= GetDblTime() )
1730 if ( abs( localwhere
.h
- lastWhere
.h
) < 3 || abs( localwhere
.v
- lastWhere
.v
) < 3 )
1733 event
.SetEventType(wxEVT_RIGHT_DCLICK
) ;
1735 event
.SetEventType(wxEVT_LEFT_DCLICK
) ;
1741 lastWhen
= ev
->when
;
1743 lastWhere
= localwhere
;
1746 event
.m_x
= localwhere
.h
;
1747 event
.m_y
= localwhere
.v
;
1752 wxPoint origin = GetClientAreaOrigin() ;
1754 event.m_x += origin.x ;
1755 event.m_y += origin.y ;
1758 event
.m_timeStamp
= ev
->when
;
1759 event
.SetEventObject(this);
1760 if ( wxTheApp
->s_captureWindow
)
1764 wxTheApp
->s_captureWindow
->ScreenToClient( &x
, &y
) ;
1767 wxTheApp
->s_captureWindow
->GetEventHandler()->ProcessEvent( event
) ;
1768 if ( ev
->what
== mouseUp
)
1770 wxTheApp
->s_captureWindow
= NULL
;
1771 if ( wxBusyCursorCount
== 0 )
1773 m_cursor
.MacInstall() ;
1779 MacDispatchMouseEvent( event
) ;
1783 void wxWindow::MacMouseDown( EventRecord
*ev
, short part
)
1785 MacFireMouseEvent( ev
) ;
1788 void wxWindow::MacMouseUp( EventRecord
*ev
, short part
)
1790 WindowPtr frontWindow
;
1795 MacFireMouseEvent( ev
) ;
1801 void wxWindow::MacMouseMoved( EventRecord
*ev
, short part
)
1803 WindowPtr frontWindow
;
1808 MacFireMouseEvent( ev
) ;
1813 void wxWindow::MacActivate( EventRecord
*ev
, bool inIsActivating
)
1815 if ( !m_macWindowData
->m_macHasReceivedFirstActivate
)
1816 m_macWindowData
->m_macHasReceivedFirstActivate
= true ;
1818 wxActivateEvent
event(wxEVT_ACTIVATE
, inIsActivating
, m_windowId
);
1819 event
.m_timeStamp
= ev
->when
;
1820 event
.SetEventObject(this);
1822 GetEventHandler()->ProcessEvent(event
);
1825 UMAHighlightAndActivateWindow( m_macWindowData
->m_macWindow
, inIsActivating
) ;
1826 // MacUpdateImmediately() ;
1829 void wxWindow::MacRedraw( RgnHandle updatergn
, long time
)
1831 // updatergn is always already clipped to our boundaries
1832 WindowRef window
= GetMacRootWindow() ;
1833 // ownUpdateRgn is the area that this window has to invalidate i.e. its own area without its children
1834 RgnHandle ownUpdateRgn
= NewRgn() ;
1835 CopyRgn( updatergn
, ownUpdateRgn
) ;
1836 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1838 wxMacDrawingHelper
focus( this ) ; // was client
1841 WindowRef window
= GetMacRootWindow() ;
1842 bool eraseBackground
= false ;
1843 if ( m_macWindowData
)
1844 eraseBackground
= true ;
1845 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
1847 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
1849 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1851 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1852 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1853 // either a non gray background color or a non control window
1856 wxWindow
* parent
= GetParent() ;
1859 if ( parent
->GetMacRootWindow() != window
)
1861 // we are in a different window on the mac system
1866 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
1868 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1870 // if we have any other colours in the hierarchy
1871 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
1874 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1875 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
1878 GetRegionBounds( updatergn
, &box
) ;
1879 UMAApplyThemeBackground(kThemeBackgroundTabPane
, &box
, kThemeStateActive
,8,true);
1888 parent
= parent
->GetParent() ;
1892 // if there is nothing special -> use default
1893 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
1898 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
1900 // subtract all non transparent children from updatergn
1902 RgnHandle childarea
= NewRgn() ;
1903 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1905 wxWindow
*child
= (wxWindow
*)node
->Data();
1906 // eventually test for transparent windows
1907 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() )
1909 if ( child
->GetBackgroundColour() != m_backgroundColour
&& !child
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)child
)->GetMacControl() )
1911 SetRectRgn( childarea
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1912 DiffRgn( ownUpdateRgn
, childarea
, ownUpdateRgn
) ;
1916 DisposeRgn( childarea
) ;
1918 if ( GetParent() && m_backgroundColour
!= GetParent()->GetBackgroundColour() )
1919 eraseBackground
= true ;
1920 SetClip( ownUpdateRgn
) ;
1921 if ( m_macEraseOnRedraw
) {
1922 if ( eraseBackground
)
1924 EraseRgn( ownUpdateRgn
) ;
1928 m_macEraseOnRedraw
= true ;
1933 RgnHandle newupdate
= NewRgn() ;
1934 wxSize point
= GetClientSize() ;
1935 wxPoint origin
= GetClientAreaOrigin() ;
1937 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1938 SectRgn( newupdate
, ownUpdateRgn
, newupdate
) ;
1939 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1940 m_updateRegion
= newupdate
;
1941 DisposeRgn( newupdate
) ;
1946 event
.m_timeStamp
= time
;
1947 event
.SetEventObject(this);
1948 GetEventHandler()->ProcessEvent(event
);
1952 RgnHandle childupdate
= NewRgn() ;
1954 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1956 wxWindow
*child
= (wxWindow
*)node
->Data();
1957 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1958 SectRgn( childupdate
, updatergn
, childupdate
) ;
1959 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1960 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1962 // because dialogs may also be children
1963 child
->MacRedraw( childupdate
, time
) ;
1966 DisposeRgn( childupdate
) ;
1967 // eventually a draw grow box here
1970 void wxWindow::MacUpdateImmediately()
1972 WindowRef window
= GetMacRootWindow() ;
1975 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1977 AGAPortHelper
help( GetWindowPort(window
) ) ;
1979 AGAPortHelper
help( (window
) ) ;
1981 SetOrigin( 0 , 0 ) ;
1982 BeginUpdate( window
) ;
1985 RgnHandle region
= NewRgn();
1989 GetPortVisibleRegion( GetWindowPort( window
), region
);
1991 // if windowshade gives incompatibility , take the follwing out
1992 if ( !EmptyRgn( region
) && win
->m_macWindowData
->m_macHasReceivedFirstActivate
)
1994 win
->MacRedraw( region
, wxTheApp
->sm_lastMessageTime
) ;
1996 DisposeRgn( region
);
1999 EndUpdate( window
) ;
2003 void wxWindow::MacUpdate( EventRecord
*ev
)
2005 WindowRef window
= (WindowRef
) ev
->message
;
2006 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
2008 AGAPortHelper
help( GetWindowPort(window
) ) ;
2010 AGAPortHelper
help( (window
) ) ;
2012 SetOrigin( 0 , 0 ) ;
2013 BeginUpdate( window
) ;
2016 RgnHandle region
= NewRgn();
2020 GetPortVisibleRegion( GetWindowPort( window
), region
);
2022 // if windowshade gives incompatibility , take the follwing out
2023 if ( !EmptyRgn( region
) && win
->m_macWindowData
->m_macHasReceivedFirstActivate
)
2025 MacRedraw( region
, ev
->when
) ;
2027 DisposeRgn( region
);
2030 EndUpdate( window
) ;
2033 WindowRef
wxWindow::GetMacRootWindow() const
2035 WindowRef window
= NULL
;
2036 wxWindow
*iter
= (wxWindow
*)this ;
2040 if ( iter
->m_macWindowData
)
2041 return iter
->m_macWindowData
->m_macWindow
;
2043 iter
= iter
->GetParent() ;
2045 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
2049 void wxWindow::MacCreateScrollBars( long style
)
2051 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
2053 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2054 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2056 GetClientSize( &width
, &height
) ;
2058 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2059 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2060 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2061 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2063 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2064 vSize
, wxVERTICAL
);
2066 if ( style
& wxVSCROLL
)
2072 m_vScrollBar
->Show(false) ;
2074 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2075 hSize
, wxHORIZONTAL
);
2076 if ( style
& wxHSCROLL
)
2081 m_hScrollBar
->Show(false) ;
2084 // because the create does not take into account the client area origin
2085 MacRepositionScrollBars() ; // we might have a real position shift
2088 void wxWindow::MacRepositionScrollBars()
2090 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2091 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2093 // get real client area
2095 int width
= m_width
;
2096 int height
= m_height
;
2098 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2099 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2101 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2102 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2103 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2104 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2111 MacClientToRootWindow( &x
, &y
) ;
2112 MacClientToRootWindow( &w
, &h
) ;
2114 WindowRef window
= NULL
;
2115 wxWindow
*iter
= (wxWindow
*)this ;
2117 int totW
= 10000 , totH
= 10000;
2120 if ( iter
->m_macWindowData
)
2122 totW
= iter
->m_width
;
2123 totH
= iter
->m_height
;
2127 iter
= iter
->GetParent() ;
2155 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2159 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2163 void wxWindow::MacKeyDown( EventRecord
*ev
)
2169 bool wxWindow::AcceptsFocus() const
2171 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2174 ControlHandle
wxWindow::MacGetContainerForEmbedding()
2176 if ( m_macWindowData
)
2177 return m_macWindowData
->m_macRootControl
;
2179 return GetParent()->MacGetContainerForEmbedding() ;
2182 void wxWindow::MacSuperChangedPosition()
2184 // only window-absolute structures have to be moved i.e. controls
2186 wxNode
*node
= GetChildren().First();
2189 wxWindow
*child
= (wxWindow
*)node
->Data();
2190 child
->MacSuperChangedPosition() ;
2191 node
= node
->Next();
2195 bool wxWindow::MacSetPortFocusParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
2197 if ( window
== NULL
)
2203 ::GetPort(&currPort
);
2204 port
= UMAGetWindowPort( window
) ;
2205 if (currPort
!= port
)
2208 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2209 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2213 bool wxWindow::MacSetPortDrawingParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
2215 if ( window
== NULL
)
2220 ::GetPort(&currPort
);
2221 port
= UMAGetWindowPort( window
) ;
2222 if (currPort
!= port
)
2224 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2225 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2226 ::ClipRect(&clipRect
);
2229 ::RGBBackColor(& win
->GetBackgroundColour().GetPixel() ) ;
2230 ::RGBForeColor(& win
->GetForegroundColour().GetPixel() ) ;
2231 Pattern whiteColor
;
2233 ::BackPat( GetQDGlobalsWhite( &whiteColor
) ) ;
2234 ::UMASetThemeWindowBackground( win
->m_macWindowData
->m_macWindow
, win
->m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
2238 void wxWindow::MacGetPortParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2240 if ( m_macWindowData
)
2246 clipRect
->right
= m_width
;
2247 clipRect
->bottom
= m_height
;
2248 *window
= m_macWindowData
->m_macWindow
;
2253 wxASSERT( GetParent() != NULL
) ;
2254 GetParent()->MacGetPortParams( localOrigin
, clipRect
, window
, rootwin
) ;
2255 localOrigin
->h
+= m_x
;
2256 localOrigin
->v
+= m_y
;
2257 OffsetRect(clipRect
, -m_x
, -m_y
);
2262 myClip
.right
= m_width
;
2263 myClip
.bottom
= m_height
;
2264 SectRect(clipRect
, &myClip
, clipRect
);
2268 void wxWindow::MacDoGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2270 // int width , height ;
2271 // GetClientSize( &width , &height ) ;
2273 if ( m_macWindowData
)
2279 clipRect
->right
= m_width
;//width;
2280 clipRect
->bottom
= m_height
;// height;
2281 *window
= m_macWindowData
->m_macWindow
;
2286 wxASSERT( GetParent() != NULL
) ;
2288 GetParent()->MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2290 localOrigin
->h
+= m_x
;
2291 localOrigin
->v
+= m_y
;
2292 OffsetRect(clipRect
, -m_x
, -m_y
);
2297 myClip
.right
= m_width
;//width;
2298 myClip
.bottom
= m_height
;// height;
2299 SectRect(clipRect
, &myClip
, clipRect
);
2303 void wxWindow::MacGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2305 MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2307 int width
, height
;
2308 GetClientSize( &width
, &height
) ;
2310 client
= GetClientAreaOrigin( ) ;
2312 localOrigin
->h
+= client
.x
;
2313 localOrigin
->v
+= client
.y
;
2314 OffsetRect(clipRect
, -client
.x
, -client
.y
);
2319 myClip
.right
= width
;
2320 myClip
.bottom
= height
;
2321 SectRect(clipRect
, &myClip
, clipRect
);
2324 long wxWindow::MacGetLeftBorderSize( ) const
2326 if( m_macWindowData
)
2329 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2333 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2337 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2344 long wxWindow::MacGetRightBorderSize( ) const
2346 if( m_macWindowData
)
2349 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2353 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2357 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2364 long wxWindow::MacGetTopBorderSize( ) const
2366 if( m_macWindowData
)
2369 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2373 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2377 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2384 long wxWindow::MacGetBottomBorderSize( ) const
2386 if( m_macWindowData
)
2389 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2393 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2397 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2404 long wxWindow::MacRemoveBordersFromStyle( long style
)
2406 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2410 wxMacDrawingHelper::wxMacDrawingHelper( wxWindow
* theWindow
)
2417 m_currentPort
= NULL
;
2419 GetPort( &m_formerPort
) ;
2422 theWindow
->MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2423 m_currentPort
= UMAGetWindowPort( window
) ;
2424 if ( m_formerPort
!= m_currentPort
)
2425 SetPort( m_currentPort
) ;
2426 GetPenState( &m_savedPenState
) ;
2427 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2432 wxMacDrawingHelper::~wxMacDrawingHelper()
2436 SetPort( m_currentPort
) ;
2437 SetPenState( &m_savedPenState
) ;
2438 SetOrigin( 0 , 0 ) ;
2440 GetPortBounds( m_currentPort
, &portRect
) ;
2441 ClipRect( &portRect
) ;
2444 if ( m_formerPort
!= m_currentPort
)
2445 SetPort( m_formerPort
) ;
2448 wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindow
* theWindow
)
2455 m_currentPort
= NULL
;
2457 GetPort( &m_formerPort
) ;
2461 theWindow
->MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2462 m_currentPort
= UMAGetWindowPort( window
) ;
2463 if ( m_formerPort
!= m_currentPort
)
2464 SetPort( m_currentPort
) ;
2465 GetPenState( &m_savedPenState
) ;
2466 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2471 wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
2475 SetPort( m_currentPort
) ;
2476 SetPenState( &m_savedPenState
) ;
2477 SetOrigin( 0 , 0 ) ;
2479 GetPortBounds( m_currentPort
, &portRect
) ;
2480 ClipRect( &portRect
) ;
2483 if ( m_formerPort
!= m_currentPort
)
2484 SetPort( m_formerPort
) ;
2487 // Find the wxWindow at the current mouse position, returning the mouse
2489 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
2491 pt
= wxGetMousePosition();
2492 wxWindow
* found
= wxFindWindowAtPoint(pt
);
2496 // Get the current mouse position.
2497 wxPoint
wxGetMousePosition()
2500 wxGetMousePosition(& x
, & y
);
2501 return wxPoint(x
, y
);