1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
19 #include "wx/dcclient.h"
23 #include "wx/layout.h"
24 #include "wx/dialog.h"
25 #include "wx/listbox.h"
26 #include "wx/button.h"
27 #include "wx/settings.h"
28 #include "wx/msgdlg.h"
30 #include "wx/notebook.h"
31 #include "wx/tabctrl.h"
32 // TODO remove the line below, just for lookup-up convenience CS
33 #include "wx/mac/window.h"
35 #include "wx/menuitem.h"
38 #define wxWINDOW_HSCROLL 5998
39 #define wxWINDOW_VSCROLL 5997
40 #define MAC_SCROLLBAR_SIZE 16
42 #include <wx/mac/uma.h>
44 #if wxUSE_DRAG_AND_DROP
50 extern wxList wxPendingDelete
;
51 wxWindow
* gFocusWindow
= NULL
;
53 #if !USE_SHARED_LIBRARY
54 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxEvtHandler
)
56 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
57 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground
)
58 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
59 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
60 EVT_IDLE(wxWindow::OnIdle
)
67 // ===========================================================================
69 // ===========================================================================
71 // ---------------------------------------------------------------------------
72 // wxWindow utility functions
73 // ---------------------------------------------------------------------------
75 // Find an item given the Macintosh Window Reference
77 wxList
*wxWinMacWindowList
= NULL
;
78 wxWindow
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
80 wxNode
*node
= wxWinMacWindowList
->Find((long)inWindowRef
);
83 return (wxWindow
*)node
->Data();
86 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxWindow
*win
)
88 // adding NULL WindowRef is (first) surely a result of an error and
89 // (secondly) breaks menu command processing
90 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, "attempt to add a NULL WindowRef to window list" );
92 if ( !wxWinMacWindowList
->Find((long)inWindowRef
) )
93 wxWinMacWindowList
->Append((long)inWindowRef
, win
);
96 void wxRemoveMacWindowAssociation(wxWindow
*win
)
98 wxWinMacWindowList
->DeleteObject(win
);
101 // ----------------------------------------------------------------------------
102 // constructors and such
103 // ----------------------------------------------------------------------------
105 void wxWindow::Init()
111 m_doubleClickAllowed
= 0;
112 m_winCaptured
= FALSE
;
114 m_isBeingDeleted
= FALSE
;
117 m_mouseInWindow
= FALSE
;
121 m_backgroundTransparent
= FALSE
;
123 // as all windows are created with WS_VISIBLE style...
126 m_macWindowData
= NULL
;
133 m_hScrollBar
= NULL
;
134 m_vScrollBar
= NULL
;
136 #if wxUSE_DRAG_AND_DROP
137 m_pDropTarget
= NULL
;
142 wxWindow::~wxWindow()
144 m_isBeingDeleted
= TRUE
;
146 if ( s_lastMouseWindow
== this )
148 s_lastMouseWindow
= NULL
;
151 if ( gFocusWindow
== this )
153 gFocusWindow
= NULL
;
157 m_parent
->RemoveChild(this);
161 if ( m_macWindowData
)
163 UMADisposeWindow( m_macWindowData
->m_macWindow
) ;
164 delete m_macWindowData
;
165 wxRemoveMacWindowAssociation( this ) ;
170 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
174 const wxString
& name
)
176 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindow without parent") );
178 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
181 parent
->AddChild(this);
185 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
186 m_width
= WidthDefault( size
.x
);
187 m_height
= HeightDefault( size
.y
) ;
189 MacCreateScrollBars( style
) ;
194 void wxWindow::SetFocus()
196 if ( AcceptsFocus() )
200 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
201 if ( control
&& control
->GetMacControl() )
203 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlFocusNoPart
) ;
205 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
206 event
.SetEventObject(gFocusWindow
);
207 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
209 gFocusWindow
= this ;
211 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
212 if ( control
&& control
->GetMacControl() )
214 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlEditTextPart
) ;
217 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
218 event
.SetEventObject(this);
219 GetEventHandler()->ProcessEvent(event
) ;
224 bool wxWindow::Enable(bool enable
)
226 if ( !wxWindowBase::Enable(enable
) )
229 HWND hWnd = GetHwnd();
231 ::EnableWindow(hWnd, (BOOL)enable);
234 wxWindowList::Node
*node
= GetChildren().GetFirst();
237 wxWindow
*child
= node
->GetData();
238 child
->Enable(enable
);
240 node
= node
->GetNext();
246 void wxWindow::CaptureMouse()
248 wxTheApp
->s_captureWindow
= this ;
251 void wxWindow::ReleaseMouse()
253 wxTheApp
->s_captureWindow
= NULL
;
256 #if wxUSE_DRAG_AND_DROP
258 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
260 if ( m_pDropTarget
!= 0 ) {
261 delete m_pDropTarget
;
264 m_pDropTarget
= pDropTarget
;
265 if ( m_pDropTarget
!= 0 )
273 // Old style file-manager drag&drop
274 void wxWindow::DragAcceptFiles(bool accept
)
280 void wxWindow::DoGetSize(int *x
, int *y
) const
286 void wxWindow::DoGetPosition(int *x
, int *y
) const
292 wxPoint
pt(GetParent()->GetClientAreaOrigin());
298 wxSize
wxWindow::DoGetBestSize()
300 return wxSize( 0 , 0 ) ;
303 bool wxWindow::Reparent(wxWindow
*parent
)
305 if ( !wxWindowBase::Reparent(parent
) )
311 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
313 menu
->SetInvokingWindow(this);
315 ClientToScreen( &x
, &y
) ;
317 ::InsertMenu( menu
->GetHMenu() , -1 ) ;
318 long menuResult
= ::PopUpMenuSelect(menu
->GetHMenu() ,y
,x
, 0) ;
319 menu
->MacMenuSelect( this , TickCount() , HiWord(menuResult
) , LoWord(menuResult
) ) ;
320 ::DeleteMenu( menu
->MacGetMenuId() ) ;
321 menu
->SetInvokingWindow(NULL
);
326 void wxWindow::DoScreenToClient(int *x
, int *y
) const
328 WindowRef window
= GetMacRootWindow() ;
336 ::SetPort( UMAGetWindowPort( window
) ) ;
337 ::GlobalToLocal( &localwhere
) ;
343 MacRootWindowToClient( x
, y
) ;
346 void wxWindow::DoClientToScreen(int *x
, int *y
) const
348 WindowRef window
= GetMacRootWindow() ;
350 MacClientToRootWindow( x
, y
) ;
358 ::SetPort( UMAGetWindowPort( window
) ) ;
359 ::LocalToGlobal( &localwhere
) ;
365 void wxWindow::MacClientToRootWindow( int *x
, int *y
) const
367 if ( m_macWindowData
)
374 GetParent()->MacClientToRootWindow( x
, y
) ;
378 void wxWindow::MacRootWindowToClient( int *x
, int *y
) const
380 if ( m_macWindowData
)
387 GetParent()->MacRootWindowToClient( x
, y
) ;
391 bool wxWindow::SetCursor(const wxCursor
& cursor
)
393 if ( !wxWindowBase::SetCursor(cursor
) )
399 wxASSERT_MSG( m_cursor
.Ok(),
400 wxT("cursor must be valid after call to the base version"));
406 // Change the cursor NOW if we're within the correct window
408 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
410 if ( mouseWin
== this && !wxIsBusy() )
412 cursor
.MacInstall() ;
420 // Get size *available for subwindows* i.e. excluding menu bar etc.
421 void wxWindow::DoGetClientSize(int *x
, int *y
) const
426 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
427 (*x
) -= MAC_SCROLLBAR_SIZE
;
428 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
429 (*y
) -= MAC_SCROLLBAR_SIZE
;
433 // ----------------------------------------------------------------------------
435 // ----------------------------------------------------------------------------
439 void wxWindow::DoSetToolTip(wxToolTip
*tooltip
)
441 wxWindowBase::DoSetToolTip(tooltip
);
444 // m_tooltip->SetWindow(this);
447 #endif // wxUSE_TOOLTIPS
449 void wxWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
451 DoSetSize( x
,y
, width
, height
) ;
454 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
458 int former_w
= m_width
;
459 int former_h
= m_height
;
461 int currentX
, currentY
;
462 GetPosition(¤tX
, ¤tY
);
463 int currentW
,currentH
;
464 GetSize(¤tW
, ¤tH
);
466 int actualWidth
= width
;
467 int actualHeight
= height
;
470 if (x
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
472 if (y
== -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
475 actualWidth
= currentW
;
477 actualHeight
= currentH
;
479 if ( actualX
== currentX
&& actualY
== currentY
&& actualWidth
== currentW
&& actualHeight
== currentH
)
481 MacRepositionScrollBars() ; // we might have a real position shift
485 AdjustForParentClientOrigin(actualX
, actualY
, sizeFlags
);
488 bool doMove
= false ;
489 bool doResize
= false ;
491 if ( actualX
!= former_x
|| actualY
!= former_y
)
495 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
500 if ( doMove
|| doResize
)
502 if ( m_macWindowData
)
507 // erase former position
509 wxMacDrawingClientHelper
focus( this ) ;
512 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
513 InvalRect( &clientrect
) ;
519 m_width
= actualWidth
;
520 m_height
= actualHeight
;
521 if ( m_macWindowData
)
524 ::MoveWindow(m_macWindowData
->m_macWindow
, m_x
, m_y
, false); // don't make frontmost
527 ::SizeWindow(m_macWindowData
->m_macWindow
, m_width
, m_height
, true);
529 // the OS takes care of invalidating and erasing
531 if ( IsKindOf( CLASSINFO( wxFrame
) ) )
533 wxFrame
* frame
= (wxFrame
*) this ;
534 frame
->PositionStatusBar();
535 frame
->PositionToolBar();
540 // erase new position
542 wxMacDrawingClientHelper
focus( this ) ;
545 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
546 InvalRect( &clientrect
) ;
550 wxWindow::MacSuperChangedPosition() ; // like this only children will be notified
552 MacRepositionScrollBars() ;
555 wxMoveEvent
event(wxPoint(m_x
, m_y
), m_windowId
);
556 event
.SetEventObject(this);
557 GetEventHandler()->ProcessEvent(event
) ;
561 MacRepositionScrollBars() ;
562 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
563 event
.SetEventObject(this);
564 GetEventHandler()->ProcessEvent(event
);
568 // For implementation purposes - sometimes decorations make the client area
571 wxPoint
wxWindow::GetClientAreaOrigin() const
573 return wxPoint(0, 0);
576 // Makes an adjustment to the window position (for example, a frame that has
577 // a toolbar that it manages itself).
578 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
580 if( !m_macWindowData
)
582 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
584 wxPoint
pt(GetParent()->GetClientAreaOrigin());
585 x
+= pt
.x
; y
+= pt
.y
;
590 void wxWindow::SetTitle(const wxString
& title
)
596 if( wxApp::s_macDefaultEncodingIsPC
)
597 label
= wxMacMakeMacStringFromPC( title
) ;
601 if ( m_macWindowData
)
602 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
605 wxString
wxWindow::GetTitle() const
610 bool wxWindow::Show(bool show
)
612 if ( !wxWindowBase::Show(show
) )
615 if ( m_macWindowData
)
619 UMAShowWindow( m_macWindowData
->m_macWindow
) ;
620 UMASelectWindow( m_macWindowData
->m_macWindow
) ;
621 // no need to generate events here, they will get them triggered by macos
622 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
623 event
.SetEventObject(this);
624 GetEventHandler()->ProcessEvent(event
);
628 UMAHideWindow( m_macWindowData
->m_macWindow
) ;
636 int wxWindow::GetCharHeight() const
638 wxClientDC
dc ( (wxWindow
*)this ) ;
639 return dc
.GetCharHeight() ;
642 int wxWindow::GetCharWidth() const
644 wxClientDC
dc ( (wxWindow
*)this ) ;
645 return dc
.GetCharWidth() ;
648 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
649 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
651 const wxFont
*fontToUse
= theFont
;
660 *descent = tm.tmDescent;
661 if ( externalLeading )
662 *externalLeading = tm.tmExternalLeading;
667 void wxWindow::MacEraseBackground( Rect
*rect
)
669 WindowRef window
= GetMacRootWindow() ;
670 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
672 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
674 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
676 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
677 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
678 // either a non gray background color or a non control window
680 wxWindow
* parent
= GetParent() ;
683 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
685 // if we have any other colours in the hierarchy
686 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
689 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
691 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
692 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
694 ApplyThemeBackground (kThemeBackgroundTabPane
, rect
, kThemeStateActive
,8,true);
700 // we have arrived at a non control item
704 parent
= parent
->GetParent() ;
708 // if there is nothing special -> use default
709 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
714 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
719 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
721 wxWindow
*child
= (wxWindow
*)node
->Data();
725 // child->GetClientSize( &width , &height ) ;
727 Rect clientrect
= { child
->m_x
, child
->m_y
, child
->m_x
+child
->m_width
, child
->m_y
+ child
->m_height
} ;
728 SectRect( &clientrect
, rect
, &clientrect
) ;
730 OffsetRect( &clientrect
, -child
->m_x
, -child
->m_y
) ;
731 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() )
733 wxMacDrawingClientHelper
focus( this ) ;
736 child
->MacEraseBackground( &clientrect
) ;
742 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
744 wxMacDrawingClientHelper
focus( this ) ;
748 GetClientSize( &width
, &height
) ;
749 Rect clientrect
= { 0 , 0 , height
, width
} ;
750 ClipRect( &clientrect
) ;
754 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
755 SectRect( &clientrect
, &r
, &clientrect
) ;
757 InvalRect( &clientrect
) ;
761 MacEraseBackground( &clientrect ) ;
767 // Responds to colour changes: passes event on to children.
768 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
770 wxNode
*node
= GetChildren().First();
773 // Only propagate to non-top-level windows
774 wxWindow
*win
= (wxWindow
*)node
->Data();
775 if ( win
->GetParent() )
777 wxSysColourChangedEvent event2
;
778 event
.m_eventObject
= win
;
779 win
->GetEventHandler()->ProcessEvent(event2
);
786 #if wxUSE_CARET && WXWIN_COMPATIBILITY
787 // ---------------------------------------------------------------------------
788 // Caret manipulation
789 // ---------------------------------------------------------------------------
791 void wxWindow::CreateCaret(int w
, int h
)
793 SetCaret(new wxCaret(this, w
, h
));
796 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
798 wxFAIL_MSG("not implemented");
801 void wxWindow::ShowCaret(bool show
)
803 wxCHECK_RET( m_caret
, "no caret to show" );
808 void wxWindow::DestroyCaret()
813 void wxWindow::SetCaretPos(int x
, int y
)
815 wxCHECK_RET( m_caret
, "no caret to move" );
820 void wxWindow::GetCaretPos(int *x
, int *y
) const
822 wxCHECK_RET( m_caret
, "no caret to get position of" );
824 m_caret
->GetPosition(x
, y
);
826 #endif // wxUSE_CARET
828 wxWindow
*wxGetActiveWindow()
830 // actually this is a windows-only concept
834 // Coordinates relative to the window
835 void wxWindow::WarpPointer (int x_pos
, int y_pos
)
837 // We really dont move the mouse programmatically under mac
840 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
842 // TODO : probably we would adopt the EraseEvent structure
846 int wxWindow::GetScrollPos(int orient
) const
848 if ( orient
== wxHORIZONTAL
)
851 return m_hScrollBar
->GetThumbPosition() ;
856 return m_vScrollBar
->GetThumbPosition() ;
861 // This now returns the whole range, not just the number
862 // of positions that we can scroll.
863 int wxWindow::GetScrollRange(int orient
) const
865 if ( orient
== wxHORIZONTAL
)
868 return m_hScrollBar
->GetRange() ;
873 return m_vScrollBar
->GetRange() ;
878 int wxWindow::GetScrollThumb(int orient
) const
880 if ( orient
== wxHORIZONTAL
)
883 return m_hScrollBar
->GetThumbSize() ;
888 return m_vScrollBar
->GetThumbSize() ;
893 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
895 if ( orient
== wxHORIZONTAL
)
898 m_hScrollBar
->SetThumbPosition( pos
) ;
903 m_vScrollBar
->SetThumbPosition( pos
) ;
907 // New function that will replace some of the above.
908 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
909 int range
, bool refresh
)
911 if ( orient
== wxHORIZONTAL
)
915 if ( range
== 0 || thumbVisible
>= range
)
917 if ( m_hScrollBar
->IsShown() )
918 m_hScrollBar
->Show(false) ;
922 if ( !m_hScrollBar
->IsShown() )
923 m_hScrollBar
->Show(true) ;
924 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, refresh
) ;
932 if ( range
== 0 || thumbVisible
>= range
)
934 if ( m_vScrollBar
->IsShown() )
935 m_vScrollBar
->Show(false) ;
939 if ( !m_vScrollBar
->IsShown() )
940 m_vScrollBar
->Show(true) ;
941 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, refresh
) ;
945 MacRepositionScrollBars() ;
948 // Does a physical scroll
949 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
951 wxMacDrawingClientHelper
focus( this ) ;
955 GetClientSize( &width
, &height
) ;
956 Rect scrollrect
= { 0 , 0 , height
, width
} ;
958 RgnHandle updateRgn
= NewRgn() ;
959 ClipRect( &scrollrect
) ;
962 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
963 SectRect( &scrollrect
, &r
, &scrollrect
) ;
965 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
966 InvalRgn( updateRgn
) ;
967 DisposeRgn( updateRgn
) ;
971 bool wxWindow::SetFont(const wxFont
& font
)
973 if ( !wxWindowBase::SetFont(font
) )
982 // Get the window with the focus
983 wxWindow
*wxWindowBase::FindFocus()
985 return gFocusWindow
;
988 #if WXWIN_COMPATIBILITY
989 // If nothing defined for this, try the parent.
990 // E.g. we may be a button loaded from a resource, with no callback function
992 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
994 if ( GetEventHandler()->ProcessEvent(event
) )
997 m_parent
->GetEventHandler()->OnCommand(win
, event
);
999 #endif // WXWIN_COMPATIBILITY_2
1001 #if WXWIN_COMPATIBILITY
1002 wxObject
* wxWindow::GetChild(int number
) const
1004 // Return a pointer to the Nth object in the Panel
1005 wxNode
*node
= GetChildren().First();
1008 node
= node
->Next();
1011 wxObject
*obj
= (wxObject
*)node
->Data();
1017 #endif // WXWIN_COMPATIBILITY
1019 void wxWindow::Clear()
1021 if ( m_macWindowData
)
1023 wxMacDrawingClientHelper
helper ( this ) ;
1025 wxPoint origin
= GetClientAreaOrigin() ;
1026 GetClientSize( &w
, &h
) ;
1027 UMASetThemeWindowBackground( m_macWindowData
->m_macWindow
, m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
1028 Rect r
= { origin
.y
, origin
.x
, origin
.y
+h
, origin
.x
+w
} ;
1033 wxClientDC
dc(this);
1034 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1035 dc
.SetBackground(brush
);
1040 // Setup background and foreground colours correctly
1041 void wxWindow::SetupColours()
1044 SetBackgroundColour(GetParent()->GetBackgroundColour());
1047 void wxWindow::OnIdle(wxIdleEvent
& event
)
1050 // Check if we need to send a LEAVE event
1051 if (m_mouseInWindow)
1054 ::GetCursorPos(&pt);
1055 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1057 // Generate a LEAVE event
1058 m_mouseInWindow = FALSE;
1059 MSWOnMouseLeave(pt.x, pt.y, 0);
1064 // This calls the UI-update mechanism (querying windows for
1065 // menu/toolbar/control state information)
1069 // Raise the window to the top of the Z order
1070 void wxWindow::Raise()
1075 // Lower the window to the bottom of the Z order
1076 void wxWindow::Lower()
1081 void wxWindow::DoSetClientSize(int width
, int height
)
1083 if ( width
!= -1 || height
!= -1 )
1086 if ( width
!= -1 && m_vScrollBar
)
1087 width
+= MAC_SCROLLBAR_SIZE
;
1088 if ( height
!= -1 && m_vScrollBar
)
1089 height
+= MAC_SCROLLBAR_SIZE
;
1091 DoSetSize( -1 , -1 , width
, height
) ;
1096 wxWindow
* wxWindow::s_lastMouseWindow
= NULL
;
1098 bool wxWindow::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindow
** outWin
)
1100 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1101 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1104 WindowRef window
= GetMacRootWindow() ;
1106 wxPoint
newPoint( point
) ;
1111 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1113 wxWindow
*child
= (wxWindow
*)node
->Data();
1114 if ( child
->GetMacRootWindow() == window
)
1116 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1125 bool wxWindow::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindow
** outWin
)
1128 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1129 if ( ::FindWindow( pt
, &window
) == 3 )
1131 wxPoint
point( screenpoint
) ;
1132 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1133 win
->ScreenToClient( point
) ;
1134 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1139 extern int wxBusyCursorCount
;
1141 bool wxWindow::MacDispatchMouseEvent(wxMouseEvent
& event
)
1143 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1144 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1147 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) )
1150 WindowRef window
= GetMacRootWindow() ;
1158 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1160 wxWindow
*child
= (wxWindow
*)node
->Data();
1161 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1163 if (child
->MacDispatchMouseEvent(event
))
1171 if ( wxBusyCursorCount
== 0 )
1173 m_cursor
.MacInstall() ;
1175 GetEventHandler()->ProcessEvent( event
) ;
1179 void wxWindow::MacFireMouseEvent( EventRecord
*ev
)
1181 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
1182 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1183 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1185 event
.m_leftDown
= isDown
&& !controlDown
;
1186 event
.m_middleDown
= FALSE
;
1187 event
.m_rightDown
= isDown
&& controlDown
;
1189 if ( ev
->what
== mouseDown
)
1192 event
.SetEventType(wxEVT_RIGHT_DOWN
) ;
1194 event
.SetEventType(wxEVT_LEFT_DOWN
) ;
1196 else if ( ev
->what
== mouseUp
)
1199 event
.SetEventType(wxEVT_RIGHT_UP
) ;
1201 event
.SetEventType(wxEVT_LEFT_UP
) ;
1205 event
.SetEventType(wxEVT_MOTION
) ;
1208 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1209 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1210 event
.m_altDown
= ev
->modifiers
& optionKey
;
1211 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1213 Point localwhere
= ev
->where
;
1216 ::GetPort( &port
) ;
1217 ::SetPort( UMAGetWindowPort( m_macWindowData
->m_macWindow
) ) ;
1218 ::GlobalToLocal( &localwhere
) ;
1221 event
.m_x
= localwhere
.h
;
1222 event
.m_y
= localwhere
.v
;
1227 wxPoint origin = GetClientAreaOrigin() ;
1229 event.m_x += origin.x ;
1230 event.m_y += origin.y ;
1233 event
.m_timeStamp
= ev
->when
;
1234 event
.SetEventObject(this);
1235 if ( wxTheApp
->s_captureWindow
)
1239 wxTheApp
->s_captureWindow
->ScreenToClient( &x
, &y
) ;
1242 wxTheApp
->s_captureWindow
->GetEventHandler()->ProcessEvent( event
) ;
1243 if ( ev
->what
== mouseUp
)
1245 wxTheApp
->s_captureWindow
= NULL
;
1246 if ( wxBusyCursorCount
== 0 )
1248 m_cursor
.MacInstall() ;
1254 MacDispatchMouseEvent( event
) ;
1258 void wxWindow::MacMouseDown( EventRecord
*ev
, short part
)
1260 MacFireMouseEvent( ev
) ;
1263 void wxWindow::MacMouseUp( EventRecord
*ev
, short part
)
1265 WindowPtr frontWindow
;
1270 MacFireMouseEvent( ev
) ;
1276 void wxWindow::MacMouseMoved( EventRecord
*ev
, short part
)
1278 WindowPtr frontWindow
;
1283 MacFireMouseEvent( ev
) ;
1288 void wxWindow::MacActivate( EventRecord
*ev
, bool inIsActivating
)
1290 wxActivateEvent
event(wxEVT_ACTIVATE
, inIsActivating
);
1291 event
.m_timeStamp
= ev
->when
;
1292 event
.SetEventObject(this);
1294 GetEventHandler()->ProcessEvent(event
);
1296 UMAHighlightAndActivateWindow( m_macWindowData
->m_macWindow
, inIsActivating
) ;
1299 void wxWindow::MacRedraw( RgnHandle updatergn
, long time
)
1301 // updatergn is always already clipped to our boundaries
1302 WindowRef window
= GetMacRootWindow() ;
1303 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1305 wxMacDrawingClientHelper
focus( this ) ;
1308 WindowRef window
= GetMacRootWindow() ;
1309 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
1311 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
1313 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1315 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1316 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1317 // either a non gray background color or a non control window
1320 wxWindow
* parent
= GetParent() ;
1323 if ( parent
->GetMacRootWindow() != window
)
1325 // we are in a different window on the mac system
1330 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
1332 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1334 // if we have any other colours in the hierarchy
1335 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
1338 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1339 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
1341 ApplyThemeBackground (kThemeBackgroundTabPane
, &(**updatergn
).rgnBBox
, kThemeStateActive
,8,true);
1350 parent
= parent
->GetParent() ;
1354 // if there is nothing special -> use default
1355 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
1360 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
1362 SetClip( updatergn
) ;
1363 EraseRgn( updatergn
) ;
1368 m_updateRegion
= updatergn
;
1370 event
.m_timeStamp
= time
;
1371 event
.SetEventObject(this);
1373 GetEventHandler()->ProcessEvent(event
);
1375 RgnHandle childupdate
= NewRgn() ;
1377 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1379 wxWindow
*child
= (wxWindow
*)node
->Data();
1383 child
->GetClientSize( &width
, &height
) ;
1385 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+width
, child
->m_y
+ height
) ;
1386 SectRgn( childupdate
, m_updateRegion
.GetWXHRGN() , childupdate
) ;
1387 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1388 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() )
1390 // because dialogs may also be children
1391 child
->MacRedraw( childupdate
, time
) ;
1394 DisposeRgn( childupdate
) ;
1395 // eventually a draw grow box here
1398 void wxWindow::MacUpdateImmediately()
1400 WindowRef window
= GetMacRootWindow() ;
1403 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1404 BeginUpdate( window
) ;
1408 if ( !EmptyRgn( window
->visRgn
) )
1411 win
->MacRedraw( window
->visRgn
, wxTheApp
->sm_lastMessageTime
) ;
1414 wxMacDrawingHelper help( win ) ;
1415 SetOrigin( 0 , 0 ) ;
1416 UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
1417 UMAUpdateControls( window , window->visRgn ) ;
1418 UMASetThemeWindowBackground( win->m_macWindowData->m_macWindow , win->m_macWindowData->m_macWindowBackgroundTheme , false ) ;
1423 EndUpdate( window
) ;
1427 void wxWindow::MacUpdate( EventRecord
*ev
)
1429 WindowRef window
= (WindowRef
) ev
->message
;
1430 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1432 BeginUpdate( window
) ;
1435 // if windowshade gives incompatibility , take the follwing out
1437 if ( !EmptyRgn( window
->visRgn
) )
1440 MacRedraw( window
->visRgn
, ev
->when
) ;
1443 wxMacDrawingHelper help( this ) ;
1444 SetOrigin( 0 , 0 ) ;
1445 UMASetThemeWindowBackground( m_macWindowData->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
1446 UMAUpdateControls( window , window->visRgn ) ;
1447 UMASetThemeWindowBackground( m_macWindowData->m_macWindow , m_macWindowData->m_macWindowBackgroundTheme , false ) ;
1452 EndUpdate( window
) ;
1455 WindowRef
wxWindow::GetMacRootWindow() const
1457 WindowRef window
= NULL
;
1458 wxWindow
*iter
= (wxWindow
*)this ;
1462 if ( iter
->m_macWindowData
)
1463 return iter
->m_macWindowData
->m_macWindow
;
1465 iter
= iter
->GetParent() ;
1467 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1471 void wxWindow::MacCreateScrollBars( long style
)
1473 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
1474 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1475 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1477 if ( style
& wxVSCROLL
)
1479 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, wxPoint(m_width
-MAC_SCROLLBAR_SIZE
, 0),
1480 wxSize(MAC_SCROLLBAR_SIZE
, m_height
- adjust
), wxVERTICAL
);
1482 if ( style
& wxHSCROLL
)
1484 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, wxPoint(0 , m_height
-MAC_SCROLLBAR_SIZE
),
1485 wxSize( m_width
- adjust
, MAC_SCROLLBAR_SIZE
), wxHORIZONTAL
);
1487 // because the create does not take into account the client area origin
1488 MacRepositionScrollBars() ; // we might have a real position shift
1491 void wxWindow::MacRepositionScrollBars()
1493 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
1494 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
1498 m_vScrollBar
->SetSize( m_width
-MAC_SCROLLBAR_SIZE
, 0, MAC_SCROLLBAR_SIZE
, m_height
- adjust
, wxSIZE_USE_EXISTING
);
1502 m_hScrollBar
->SetSize( 0 , m_height
-MAC_SCROLLBAR_SIZE
,m_width
- adjust
, MAC_SCROLLBAR_SIZE
, wxSIZE_USE_EXISTING
);
1506 void wxWindow::MacKeyDown( EventRecord
*ev
)
1513 ControlHandle
wxWindow::MacGetContainerForEmbedding()
1515 if ( m_macWindowData
)
1516 return m_macWindowData
->m_macRootControl
;
1518 return GetParent()->MacGetContainerForEmbedding() ;
1521 void wxWindow::MacSuperChangedPosition()
1523 // only window-absolute structures have to be moved i.e. controls
1525 wxNode
*node
= GetChildren().First();
1528 wxWindow
*child
= (wxWindow
*)node
->Data();
1529 child
->MacSuperChangedPosition() ;
1530 node
= node
->Next();
1534 bool wxWindow::MacSetupFocusPort( )
1542 MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1543 return MacSetPortFocusParams( localOrigin
, clipRect
, window
, rootwin
) ;
1546 bool wxWindow::MacSetupFocusClientPort( )
1554 MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1555 return MacSetPortFocusParams( localOrigin
, clipRect
, window
, rootwin
) ;
1558 bool wxWindow::MacSetupDrawingPort( )
1566 MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1567 return MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
1570 bool wxWindow::MacSetupDrawingClientPort( )
1578 MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1579 return MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
1583 bool wxWindow::MacSetPortFocusParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
1585 if ( window
== NULL
)
1591 ::GetPort(&currPort
);
1592 port
= UMAGetWindowPort( window
) ;
1593 if (currPort
!= port
)
1596 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
1600 bool wxWindow::MacSetPortDrawingParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
1602 if ( window
== NULL
)
1607 ::GetPort(&currPort
);
1608 port
= UMAGetWindowPort( window
) ;
1609 if (currPort
!= port
)
1612 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
1613 ::ClipRect(&clipRect
);
1616 ::RGBBackColor(& win
->GetBackgroundColour().GetPixel() ) ;
1617 ::RGBForeColor(& win
->GetForegroundColour().GetPixel() ) ;
1618 ::BackPat( &qd
.white
) ;
1619 ::UMASetThemeWindowBackground( win
->m_macWindowData
->m_macWindow
, win
->m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
1623 void wxWindow::MacGetPortParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
1625 if ( m_macWindowData
)
1631 clipRect
->right
= m_width
;
1632 clipRect
->bottom
= m_height
;
1633 *window
= m_macWindowData
->m_macWindow
;
1638 wxASSERT( GetParent() != NULL
) ;
1639 GetParent()->MacGetPortParams( localOrigin
, clipRect
, window
, rootwin
) ;
1640 localOrigin
->h
+= m_x
;
1641 localOrigin
->v
+= m_y
;
1642 OffsetRect(clipRect
, -m_x
, -m_y
);
1647 myClip
.right
= m_width
;
1648 myClip
.bottom
= m_height
;
1649 SectRect(clipRect
, &myClip
, clipRect
);
1653 void wxWindow::MacGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
1655 int width
, height
;
1656 GetClientSize( &width
, &height
) ;
1658 if ( m_macWindowData
)
1664 clipRect
->right
= m_width
;//width;
1665 clipRect
->bottom
= m_height
;// height;
1666 *window
= m_macWindowData
->m_macWindow
;
1671 wxASSERT( GetParent() != NULL
) ;
1673 GetParent()->MacGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
1675 localOrigin
->h
+= m_x
;
1676 localOrigin
->v
+= m_y
;
1677 OffsetRect(clipRect
, -m_x
, -m_y
);
1682 myClip
.right
= width
;
1683 myClip
.bottom
= height
;
1684 SectRect(clipRect
, &myClip
, clipRect
);
1688 wxMacFocusHelper::wxMacFocusHelper( wxWindow
* theWindow
)
1695 m_currentPort
= NULL
;
1696 GetPort( &m_formerPort
) ;
1700 theWindow
->MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1701 m_currentPort
= UMAGetWindowPort( window
) ;
1702 theWindow
->MacSetPortFocusParams( localOrigin
, clipRect
, window
, rootwin
) ;
1707 wxMacFocusHelper::~wxMacFocusHelper()
1711 SetOrigin( 0 , 0 ) ;
1713 if ( m_formerPort
!= m_currentPort
)
1714 SetPort( m_formerPort
) ;
1717 wxMacDrawingHelper::wxMacDrawingHelper( wxWindow
* theWindow
)
1724 m_currentPort
= NULL
;
1726 GetPort( &m_formerPort
) ;
1729 theWindow
->MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1730 m_currentPort
= UMAGetWindowPort( window
) ;
1731 if ( m_formerPort
!= m_currentPort
)
1732 SetPort( m_currentPort
) ;
1733 GetPenState( &m_savedPenState
) ;
1734 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
1739 wxMacDrawingHelper::~wxMacDrawingHelper()
1743 SetPenState( &m_savedPenState
) ;
1744 SetOrigin( 0 , 0 ) ;
1745 ClipRect( &m_currentPort
->portRect
) ;
1748 if ( m_formerPort
!= m_currentPort
)
1749 SetPort( m_formerPort
) ;
1752 wxMacFocusClientHelper::wxMacFocusClientHelper( wxWindow
* theWindow
)
1759 m_currentPort
= NULL
;
1761 GetPort( &m_formerPort
) ;
1765 theWindow
->MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1766 m_currentPort
= UMAGetWindowPort( window
) ;
1767 theWindow
->MacSetPortFocusParams( localOrigin
, clipRect
, window
, rootwin
) ;
1772 wxMacFocusClientHelper::~wxMacFocusClientHelper()
1776 SetOrigin( 0 , 0 ) ;
1778 if ( m_formerPort
!= m_currentPort
)
1779 SetPort( m_formerPort
) ;
1782 wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindow
* theWindow
)
1789 m_currentPort
= NULL
;
1791 GetPort( &m_formerPort
) ;
1795 theWindow
->MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
1796 m_currentPort
= UMAGetWindowPort( window
) ;
1797 if ( m_formerPort
!= m_currentPort
)
1798 SetPort( m_currentPort
) ;
1799 GetPenState( &m_savedPenState
) ;
1800 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
1805 wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
1809 SetPenState( &m_savedPenState
) ;
1810 SetOrigin( 0 , 0 ) ;
1811 ClipRect( &m_currentPort
->portRect
) ;
1814 if ( m_formerPort
!= m_currentPort
)
1815 SetPort( m_formerPort
) ;