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 #include "wx/tooltip.h"
33 // TODO remove the line below, just for lookup-up convenience CS
34 #include "wx/mac/window.h"
36 #include "wx/menuitem.h"
43 #define wxWINDOW_HSCROLL 5998
44 #define wxWINDOW_VSCROLL 5997
45 #define MAC_SCROLLBAR_SIZE 16
47 #include <wx/mac/uma.h>
49 #if wxUSE_DRAG_AND_DROP
55 extern wxList wxPendingDelete
;
56 wxWindow
* gFocusWindow
= NULL
;
58 #if !USE_SHARED_LIBRARY
59 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxEvtHandler
)
60 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
61 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground
)
62 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
63 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
64 EVT_IDLE(wxWindow::OnIdle
)
65 // EVT_SCROLL(wxWindow::OnScroll)
72 // ===========================================================================
74 // ===========================================================================
76 // ---------------------------------------------------------------------------
77 // wxWindow utility functions
78 // ---------------------------------------------------------------------------
80 // Find an item given the Macintosh Window Reference
82 wxList
*wxWinMacWindowList
= NULL
;
83 wxWindow
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
85 wxNode
*node
= wxWinMacWindowList
->Find((long)inWindowRef
);
88 return (wxWindow
*)node
->Data();
91 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxWindow
*win
)
93 // adding NULL WindowRef is (first) surely a result of an error and
94 // (secondly) breaks menu command processing
95 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, "attempt to add a NULL WindowRef to window list" );
97 if ( !wxWinMacWindowList
->Find((long)inWindowRef
) )
98 wxWinMacWindowList
->Append((long)inWindowRef
, win
);
101 void wxRemoveMacWindowAssociation(wxWindow
*win
)
103 wxWinMacWindowList
->DeleteObject(win
);
106 // ----------------------------------------------------------------------------
107 // constructors and such
108 // ----------------------------------------------------------------------------
110 void wxWindow::Init()
116 m_doubleClickAllowed
= 0;
117 m_winCaptured
= FALSE
;
119 m_isBeingDeleted
= FALSE
;
122 m_mouseInWindow
= FALSE
;
126 m_backgroundTransparent
= FALSE
;
128 // as all windows are created with WS_VISIBLE style...
131 m_macWindowData
= NULL
;
138 m_hScrollBar
= NULL
;
139 m_vScrollBar
= NULL
;
141 #if wxUSE_DRAG_AND_DROP
142 m_pDropTarget
= NULL
;
147 wxWindow::~wxWindow()
149 m_isBeingDeleted
= TRUE
;
151 if ( s_lastMouseWindow
== this )
153 s_lastMouseWindow
= NULL
;
156 if ( gFocusWindow
== this )
158 gFocusWindow
= NULL
;
162 m_parent
->RemoveChild(this);
166 if ( m_macWindowData
)
168 wxToolTip::NotifyWindowDelete(m_macWindowData
->m_macWindow
) ;
169 UMADisposeWindow( m_macWindowData
->m_macWindow
) ;
170 delete m_macWindowData
;
171 wxRemoveMacWindowAssociation( this ) ;
176 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
180 const wxString
& name
)
182 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindow without parent") );
184 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
187 parent
->AddChild(this);
191 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
192 m_width
= WidthDefault( size
.x
);
193 m_height
= HeightDefault( size
.y
) ;
195 if ( ! IsKindOf( CLASSINFO ( wxControl
) ) )
197 MacCreateScrollBars( style
) ;
203 void wxWindow::SetFocus()
205 if ( AcceptsFocus() )
211 if ( gFocusWindow
->m_caret
)
213 gFocusWindow
->m_caret
->OnKillFocus();
215 #endif // wxUSE_CARET
216 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
217 if ( control
&& control
->GetMacControl() )
219 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlFocusNoPart
) ;
220 control
->MacRedrawControl() ;
222 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
223 event
.SetEventObject(gFocusWindow
);
224 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
226 gFocusWindow
= this ;
232 m_caret
->OnSetFocus();
234 #endif // wxUSE_CARET
235 // panel wants to track the window which was the last to have focus in it
236 wxPanel
*panel
= wxDynamicCast(GetParent(), wxPanel
);
239 panel
->SetLastFocus(this);
241 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
242 if ( control
&& control
->GetMacControl() )
244 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlEditTextPart
) ;
247 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
248 event
.SetEventObject(this);
249 GetEventHandler()->ProcessEvent(event
) ;
254 bool wxWindow::Enable(bool enable
)
256 if ( !wxWindowBase::Enable(enable
) )
259 wxWindowList::Node
*node
= GetChildren().GetFirst();
262 wxWindow
*child
= node
->GetData();
263 child
->Enable(enable
);
265 node
= node
->GetNext();
271 void wxWindow::CaptureMouse()
273 wxTheApp
->s_captureWindow
= this ;
276 void wxWindow::ReleaseMouse()
278 wxTheApp
->s_captureWindow
= NULL
;
281 #if wxUSE_DRAG_AND_DROP
283 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
285 if ( m_pDropTarget
!= 0 ) {
286 delete m_pDropTarget
;
289 m_pDropTarget
= pDropTarget
;
290 if ( m_pDropTarget
!= 0 )
298 // Old style file-manager drag&drop
299 void wxWindow::DragAcceptFiles(bool accept
)
305 void wxWindow::DoGetSize(int *x
, int *y
) const
311 void wxWindow::DoGetPosition(int *x
, int *y
) const
317 wxPoint
pt(GetParent()->GetClientAreaOrigin());
324 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
326 menu
->SetInvokingWindow(this);
328 ClientToScreen( &x
, &y
) ;
330 ::InsertMenu( menu
->GetHMenu() , -1 ) ;
331 long menuResult
= ::PopUpMenuSelect(menu
->GetHMenu() ,y
,x
, 0) ;
332 menu
->MacMenuSelect( this , TickCount() , HiWord(menuResult
) , LoWord(menuResult
) ) ;
333 ::DeleteMenu( menu
->MacGetMenuId() ) ;
334 menu
->SetInvokingWindow(NULL
);
339 void wxWindow::DoScreenToClient(int *x
, int *y
) const
341 WindowRef window
= GetMacRootWindow() ;
349 ::SetPort( UMAGetWindowPort( window
) ) ;
350 ::GlobalToLocal( &localwhere
) ;
356 MacRootWindowToClient( x
, y
) ;
359 void wxWindow::DoClientToScreen(int *x
, int *y
) const
361 WindowRef window
= GetMacRootWindow() ;
363 MacClientToRootWindow( x
, y
) ;
371 ::SetPort( UMAGetWindowPort( window
) ) ;
372 ::SetOrigin( 0 , 0 ) ;
373 ::LocalToGlobal( &localwhere
) ;
379 void wxWindow::MacClientToRootWindow( int *x
, int *y
) const
381 if ( m_macWindowData
)
388 GetParent()->MacClientToRootWindow( x
, y
) ;
392 void wxWindow::MacRootWindowToClient( int *x
, int *y
) const
394 if ( m_macWindowData
)
401 GetParent()->MacRootWindowToClient( x
, y
) ;
405 bool wxWindow::SetCursor(const wxCursor
& cursor
)
407 if ( !wxWindowBase::SetCursor(cursor
) )
413 wxASSERT_MSG( m_cursor
.Ok(),
414 wxT("cursor must be valid after call to the base version"));
420 // Change the cursor NOW if we're within the correct window
422 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
424 if ( mouseWin
== this && !wxIsBusy() )
426 cursor
.MacInstall() ;
434 // Get size *available for subwindows* i.e. excluding menu bar etc.
435 void wxWindow::DoGetClientSize(int *x
, int *y
) const
440 *x
-= 2 * MacGetBorderSize( ) ;
441 *y
-= 2 * MacGetBorderSize( ) ;
443 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
450 MacClientToRootWindow( &x1
, &y1
) ;
451 MacClientToRootWindow( &w
, &h
) ;
453 WindowRef window
= NULL
;
454 wxWindow
*iter
= (wxWindow
*)this ;
456 int totW
= 10000 , totH
= 10000;
459 if ( iter
->m_macWindowData
)
461 totW
= iter
->m_width
;
462 totH
= iter
->m_height
;
466 iter
= iter
->GetParent() ;
469 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
471 (*y
) -= MAC_SCROLLBAR_SIZE
;
477 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
479 (*x
) -= MAC_SCROLLBAR_SIZE
;
489 // ----------------------------------------------------------------------------
491 // ----------------------------------------------------------------------------
495 void wxWindow::DoSetToolTip(wxToolTip
*tooltip
)
497 wxWindowBase::DoSetToolTip(tooltip
);
500 m_tooltip
->SetWindow(this);
503 #endif // wxUSE_TOOLTIPS
505 void wxWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
507 DoSetSize( x
,y
, width
, height
) ;
510 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
515 int former_w
= m_width
;
516 int former_h
= m_height
;
518 int currentX
, currentY
;
519 GetPosition(¤tX
, ¤tY
);
520 int currentW
,currentH
;
521 GetSize(¤tW
, ¤tH
);
523 int actualWidth
= width
;
524 int actualHeight
= height
;
527 if (x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
529 if (y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
532 actualWidth
= currentW
;
534 actualHeight
= currentH
;
536 if ( actualX
== currentX
&& actualY
== currentY
&& actualWidth
== currentW
&& actualHeight
== currentH
)
538 MacRepositionScrollBars() ; // we might have a real position shift
542 AdjustForParentClientOrigin(actualX
, actualY
, sizeFlags
);
545 bool doMove
= false ;
546 bool doResize
= false ;
548 if ( actualX
!= former_x
|| actualY
!= former_y
)
552 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
557 if ( doMove
|| doResize
)
559 if ( m_macWindowData
)
564 // erase former position
566 wxMacDrawingClientHelper
focus( this ) ;
569 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
570 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
576 m_width
= actualWidth
;
577 m_height
= actualHeight
;
578 if ( m_macWindowData
)
581 ::MoveWindow(m_macWindowData
->m_macWindow
, m_x
, m_y
, false); // don't make frontmost
584 ::SizeWindow(m_macWindowData
->m_macWindow
, m_width
, m_height
, true);
586 // the OS takes care of invalidating and erasing
588 if ( IsKindOf( CLASSINFO( wxFrame
) ) )
590 wxFrame
* frame
= (wxFrame
*) this ;
591 frame
->PositionStatusBar();
592 frame
->PositionToolBar();
597 // erase new position
599 wxMacDrawingClientHelper
focus( this ) ;
602 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
603 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
607 wxWindow::MacSuperChangedPosition() ; // like this only children will be notified
609 MacRepositionScrollBars() ;
612 wxMoveEvent
event(wxPoint(m_x
, m_y
), m_windowId
);
613 event
.SetEventObject(this);
614 GetEventHandler()->ProcessEvent(event
) ;
618 MacRepositionScrollBars() ;
619 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
620 event
.SetEventObject(this);
621 GetEventHandler()->ProcessEvent(event
);
625 // For implementation purposes - sometimes decorations make the client area
628 wxPoint
wxWindow::GetClientAreaOrigin() const
630 return wxPoint(MacGetBorderSize( ) , MacGetBorderSize( ) );
633 // Makes an adjustment to the window position (for example, a frame that has
634 // a toolbar that it manages itself).
635 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
637 if( !m_macWindowData
)
639 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
641 wxPoint
pt(GetParent()->GetClientAreaOrigin());
642 x
+= pt
.x
; y
+= pt
.y
;
647 void wxWindow::SetTitle(const wxString
& title
)
653 if( wxApp::s_macDefaultEncodingIsPC
)
654 label
= wxMacMakeMacStringFromPC( title
) ;
658 if ( m_macWindowData
)
659 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
662 wxString
wxWindow::GetTitle() const
667 bool wxWindow::Show(bool show
)
669 if ( !wxWindowBase::Show(show
) )
672 if ( m_macWindowData
)
676 UMAShowWindow( m_macWindowData
->m_macWindow
) ;
677 UMASelectWindow( m_macWindowData
->m_macWindow
) ;
678 // no need to generate events here, they will get them triggered by macos
679 // actually they should be , but apparently they are not
680 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
681 event
.SetEventObject(this);
682 GetEventHandler()->ProcessEvent(event
);
686 UMAHideWindow( m_macWindowData
->m_macWindow
) ;
689 MacSuperShown( show
) ;
692 MacUpdateImmediately() ;
697 void wxWindow::MacSuperShown( bool show
)
699 wxNode
*node
= GetChildren().First();
702 wxWindow
*child
= (wxWindow
*)node
->Data();
703 if ( child
->m_isShown
)
704 child
->MacSuperShown( show
) ;
709 int wxWindow::GetCharHeight() const
711 wxClientDC
dc ( (wxWindow
*)this ) ;
712 return dc
.GetCharHeight() ;
715 int wxWindow::GetCharWidth() const
717 wxClientDC
dc ( (wxWindow
*)this ) ;
718 return dc
.GetCharWidth() ;
721 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
722 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
724 const wxFont
*fontToUse
= theFont
;
728 wxClientDC
dc( this ) ;
730 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, fontToUse
) ;
731 if ( externalLeading
)
732 *externalLeading
= le
;
741 void wxWindow::MacEraseBackground( Rect
*rect
)
743 WindowRef window
= GetMacRootWindow() ;
744 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
746 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
748 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
750 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
751 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
752 // either a non gray background color or a non control window
754 wxWindow
* parent
= GetParent() ;
757 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
759 // if we have any other colours in the hierarchy
760 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
763 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
765 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
766 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
768 UMAApplyThemeBackground(kThemeBackgroundTabPane
, rect
, kThemeStateActive
,8,true);
774 // we have arrived at a non control item
778 parent
= parent
->GetParent() ;
782 // if there is nothing special -> use default
783 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
788 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
793 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
795 wxWindow
*child
= (wxWindow
*)node
->Data();
797 Rect clientrect
= { child
->m_x
, child
->m_y
, child
->m_x
+child
->m_width
, child
->m_y
+ child
->m_height
} ;
798 SectRect( &clientrect
, rect
, &clientrect
) ;
800 OffsetRect( &clientrect
, -child
->m_x
, -child
->m_y
) ;
801 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() )
803 wxMacDrawingClientHelper
focus( this ) ;
806 child
->MacEraseBackground( &clientrect
) ;
812 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
814 wxMacDrawingHelper
focus( this ) ;
817 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
818 ClipRect( &clientrect
) ;
822 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
823 SectRect( &clientrect
, &r
, &clientrect
) ;
825 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
829 // Responds to colour changes: passes event on to children.
830 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
832 wxNode
*node
= GetChildren().First();
835 // Only propagate to non-top-level windows
836 wxWindow
*win
= (wxWindow
*)node
->Data();
837 if ( win
->GetParent() )
839 wxSysColourChangedEvent event2
;
840 event
.m_eventObject
= win
;
841 win
->GetEventHandler()->ProcessEvent(event2
);
848 #if wxUSE_CARET && WXWIN_COMPATIBILITY
849 // ---------------------------------------------------------------------------
850 // Caret manipulation
851 // ---------------------------------------------------------------------------
853 void wxWindow::CreateCaret(int w
, int h
)
855 SetCaret(new wxCaret(this, w
, h
));
858 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
860 wxFAIL_MSG("not implemented");
863 void wxWindow::ShowCaret(bool show
)
865 wxCHECK_RET( m_caret
, "no caret to show" );
870 void wxWindow::DestroyCaret()
875 void wxWindow::SetCaretPos(int x
, int y
)
877 wxCHECK_RET( m_caret
, "no caret to move" );
882 void wxWindow::GetCaretPos(int *x
, int *y
) const
884 wxCHECK_RET( m_caret
, "no caret to get position of" );
886 m_caret
->GetPosition(x
, y
);
888 #endif // wxUSE_CARET
890 wxWindow
*wxGetActiveWindow()
892 // actually this is a windows-only concept
896 // Coordinates relative to the window
897 void wxWindow::WarpPointer (int x_pos
, int y_pos
)
899 // We really dont move the mouse programmatically under mac
902 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
904 // TODO : probably we would adopt the EraseEvent structure
907 int wxWindow::GetScrollPos(int orient
) const
909 if ( orient
== wxHORIZONTAL
)
912 return m_hScrollBar
->GetThumbPosition() ;
917 return m_vScrollBar
->GetThumbPosition() ;
922 // This now returns the whole range, not just the number
923 // of positions that we can scroll.
924 int wxWindow::GetScrollRange(int orient
) const
926 if ( orient
== wxHORIZONTAL
)
929 return m_hScrollBar
->GetRange() ;
934 return m_vScrollBar
->GetRange() ;
939 int wxWindow::GetScrollThumb(int orient
) const
941 if ( orient
== wxHORIZONTAL
)
944 return m_hScrollBar
->GetThumbSize() ;
949 return m_vScrollBar
->GetThumbSize() ;
954 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
956 if ( orient
== wxHORIZONTAL
)
959 m_hScrollBar
->SetThumbPosition( pos
) ;
964 m_vScrollBar
->SetThumbPosition( pos
) ;
968 void wxWindow::MacCreateRealWindow( const wxString
& title
,
972 const wxString
& name
)
975 m_windowStyle
= style
;
996 m_macWindowData
= new MacWindowData() ;
998 ::SetRect(&theBoundsRect
, m_x
, m_y
, m_x
+ m_width
, m_y
+ m_height
);
1000 // translate the window attributes in the appropriate window class and attributes
1002 WindowClass wclass
;
1003 WindowAttributes attr
;
1005 if ( HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
) )
1007 wclass
= kFloatingWindowClass
;
1008 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1010 attr
|= kWindowSideTitlebarAttribute
;
1013 else if ( HasFlag( wxTHICK_FRAME
) )
1015 if ( HasFlag( wxDIALOG_MODAL
) )
1017 wclass
= kMovableModalWindowClass
;
1019 else if ( HasFlag( wxDIALOG_MODELESS
) )
1021 wclass
= kDocumentWindowClass
;
1025 if ( HasFlag( wxCAPTION
) )
1027 wclass
= kDocumentWindowClass
;
1031 wclass
= kModalWindowClass
;
1037 wclass
= kModalWindowClass
;
1040 attr
= kWindowNoAttributes
;
1042 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) )
1044 attr
|= kWindowFullZoomAttribute
;
1045 attr
|= kWindowCollapseBoxAttribute
;
1047 if ( HasFlag( wxRESIZE_BORDER
) )
1049 attr
|= kWindowResizableAttribute
;
1051 if ( HasFlag( wxSYSTEM_MENU
) )
1053 attr
|= kWindowCloseBoxAttribute
;
1056 UMACreateNewWindow( wclass
, attr
, &theBoundsRect
, &m_macWindowData
->m_macWindow
) ;
1057 wxAssociateWinWithMacWindow( m_macWindowData
->m_macWindow
, this ) ;
1059 if( wxApp::s_macDefaultEncodingIsPC
)
1060 label
= wxMacMakeMacStringFromPC( title
) ;
1063 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
1064 UMACreateRootControl( m_macWindowData
->m_macWindow
, &m_macWindowData
->m_macRootControl
) ;
1066 m_macWindowData
->m_macFocus
= NULL
;
1069 void wxWindow::MacPaint( wxPaintEvent
&event
)
1073 void wxWindow::MacPaintBorders( )
1075 if( m_macWindowData
)
1078 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1079 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1080 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1081 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1084 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1086 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1087 RGBColor pen1
= sunken
? white
: black
;
1088 RGBColor pen2
= sunken
? shadow
: face
;
1089 RGBColor pen3
= sunken
? face
: shadow
;
1090 RGBColor pen4
= sunken
? black
: white
;
1092 RGBForeColor( &pen1
) ;
1094 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1095 FrameRect( &rect
) ;
1097 RGBForeColor( &pen2
) ;
1099 Rect rect
= { 1 , 1 , m_height
-1 , m_width
-1} ;
1100 FrameRect( &rect
) ;
1102 RGBForeColor( &pen3
) ;
1104 Rect rect
= { 0 , 0 , m_height
-2 , m_width
-2} ;
1105 FrameRect( &rect
) ;
1107 RGBForeColor( &pen4
) ;
1110 LineTo( m_width
- 3 , 0 ) ;
1112 LineTo( 0 , m_height
- 3 ) ;
1115 else if (HasFlag(wxSIMPLE_BORDER
))
1117 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1118 RGBForeColor( &black
) ;
1119 FrameRect( &rect
) ;
1122 if ( this->GetParent() )
1124 wxPaintDC dc(GetParent());
1125 GetParent()->PrepareDC(dc);
1127 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) )
1129 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1131 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1132 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1134 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1135 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1136 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1137 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1140 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1143 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1146 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1149 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1150 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1152 else if (HasFlag(wxDOUBLE_BORDER))
1154 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1156 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1157 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1159 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1160 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1161 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1162 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1165 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1168 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1171 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1174 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1175 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1177 else if (HasFlag(wxSIMPLE_BORDER))
1179 dc.SetPen(*wxBLACK_PEN);
1180 dc.DrawRectangle(m_x, m_y, m_width, m_height);
1186 // New function that will replace some of the above.
1187 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1188 int range
, bool refresh
)
1190 if ( orient
== wxHORIZONTAL
)
1194 if ( range
== 0 || thumbVisible
>= range
)
1196 if ( m_hScrollBar
->IsShown() )
1197 m_hScrollBar
->Show(false) ;
1201 if ( !m_hScrollBar
->IsShown() )
1202 m_hScrollBar
->Show(true) ;
1203 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, refresh
) ;
1211 if ( range
== 0 || thumbVisible
>= range
)
1213 if ( m_vScrollBar
->IsShown() )
1214 m_vScrollBar
->Show(false) ;
1218 if ( !m_vScrollBar
->IsShown() )
1219 m_vScrollBar
->Show(true) ;
1220 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, refresh
) ;
1224 MacRepositionScrollBars() ;
1227 // Does a physical scroll
1228 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1230 wxMacDrawingClientHelper
focus( this ) ;
1233 int width
, height
;
1234 GetClientSize( &width
, &height
) ;
1236 Rect scrollrect
= { 0 , 0 , height
, width
} ;
1238 RgnHandle updateRgn
= NewRgn() ;
1239 ClipRect( &scrollrect
) ;
1242 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
1243 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1245 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1246 InvalWindowRgn( GetMacRootWindow() , updateRgn
) ;
1247 DisposeRgn( updateRgn
) ;
1250 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1252 wxWindow
*child
= (wxWindow
*)node
->Data();
1253 if (child
== m_vScrollBar
) continue;
1254 if (child
== m_hScrollBar
) continue;
1255 if (child
->IsTopLevel()) continue;
1257 child
->GetPosition( &x
, &y
);
1259 child
->GetSize( &w
, &h
);
1260 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1265 void wxWindow::MacOnScroll(wxScrollEvent
&event
)
1267 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1269 wxScrollWinEvent wevent
;
1270 wevent
.SetPosition(event
.GetPosition());
1271 wevent
.SetOrientation(event
.GetOrientation());
1272 wevent
.m_eventObject
= this;
1274 switch ( event
.m_eventType
)
1276 case wxEVT_SCROLL_TOP
:
1277 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1280 case wxEVT_SCROLL_BOTTOM
:
1281 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1284 case wxEVT_SCROLL_LINEUP
:
1285 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1288 case wxEVT_SCROLL_LINEDOWN
:
1289 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1292 case wxEVT_SCROLL_PAGEUP
:
1293 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1296 case wxEVT_SCROLL_PAGEDOWN
:
1297 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1300 case wxEVT_SCROLL_THUMBTRACK
:
1301 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1306 GetEventHandler()->ProcessEvent(wevent
);
1310 bool wxWindow::SetFont(const wxFont
& font
)
1312 if ( !wxWindowBase::SetFont(font
) )
1321 // Get the window with the focus
1322 wxWindow
*wxWindowBase::FindFocus()
1324 return gFocusWindow
;
1327 #if WXWIN_COMPATIBILITY
1328 // If nothing defined for this, try the parent.
1329 // E.g. we may be a button loaded from a resource, with no callback function
1331 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1333 if ( GetEventHandler()->ProcessEvent(event
) )
1336 m_parent
->GetEventHandler()->OnCommand(win
, event
);
1338 #endif // WXWIN_COMPATIBILITY_2
1340 #if WXWIN_COMPATIBILITY
1341 wxObject
* wxWindow::GetChild(int number
) const
1343 // Return a pointer to the Nth object in the Panel
1344 wxNode
*node
= GetChildren().First();
1347 node
= node
->Next();
1350 wxObject
*obj
= (wxObject
*)node
->Data();
1356 #endif // WXWIN_COMPATIBILITY
1358 void wxWindow::Clear()
1360 if ( m_macWindowData
)
1362 wxMacDrawingClientHelper
helper ( this ) ;
1364 wxPoint origin
= GetClientAreaOrigin() ;
1365 GetClientSize( &w
, &h
) ;
1366 UMASetThemeWindowBackground( m_macWindowData
->m_macWindow
, m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
1367 Rect r
= { origin
.y
, origin
.x
, origin
.y
+h
, origin
.x
+w
} ;
1372 wxClientDC
dc(this);
1373 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1374 dc
.SetBackground(brush
);
1379 // Setup background and foreground colours correctly
1380 void wxWindow::SetupColours()
1383 SetBackgroundColour(GetParent()->GetBackgroundColour());
1386 void wxWindow::OnIdle(wxIdleEvent
& event
)
1389 // Check if we need to send a LEAVE event
1390 if (m_mouseInWindow)
1393 ::GetCursorPos(&pt);
1394 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1396 // Generate a LEAVE event
1397 m_mouseInWindow = FALSE;
1398 MSWOnMouseLeave(pt.x, pt.y, 0);
1403 // This calls the UI-update mechanism (querying windows for
1404 // menu/toolbar/control state information)
1408 // Raise the window to the top of the Z order
1409 void wxWindow::Raise()
1414 // Lower the window to the bottom of the Z order
1415 void wxWindow::Lower()
1420 void wxWindow::DoSetClientSize(int width
, int height
)
1422 if ( width
!= -1 || height
!= -1 )
1425 if ( width
!= -1 && m_vScrollBar
)
1426 width
+= MAC_SCROLLBAR_SIZE
;
1427 if ( height
!= -1 && m_vScrollBar
)
1428 height
+= MAC_SCROLLBAR_SIZE
;
1430 width
+= 2 * MacGetBorderSize( ) ;
1431 height
+= 2 * MacGetBorderSize( ) ;
1433 DoSetSize( -1 , -1 , width
, height
) ;
1438 wxWindow
* wxWindow::s_lastMouseWindow
= NULL
;
1440 bool wxWindow::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindow
** outWin
)
1442 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1443 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1446 WindowRef window
= GetMacRootWindow() ;
1448 wxPoint
newPoint( point
) ;
1453 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1455 wxWindow
*child
= (wxWindow
*)node
->Data();
1456 if ( child
->GetMacRootWindow() == window
)
1458 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1467 bool wxWindow::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindow
** outWin
)
1470 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1471 if ( ::FindWindow( pt
, &window
) == 3 )
1473 wxPoint
point( screenpoint
) ;
1474 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1475 win
->ScreenToClient( point
) ;
1476 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1481 extern int wxBusyCursorCount
;
1483 bool wxWindow::MacDispatchMouseEvent(wxMouseEvent
& event
)
1485 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1486 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1490 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) )
1493 WindowRef window
= GetMacRootWindow() ;
1501 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1503 wxWindow
*child
= (wxWindow
*)node
->Data();
1504 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1506 if (child
->MacDispatchMouseEvent(event
))
1514 if ( wxBusyCursorCount
== 0 )
1516 m_cursor
.MacInstall() ;
1520 if ( event
.GetEventType() == wxEVT_MOTION
1521 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1522 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1523 wxToolTip::RelayEvent( this , event
);
1524 #endif // wxUSE_TOOLTIPS
1525 GetEventHandler()->ProcessEvent( event
) ;
1532 wxString
wxWindow::MacGetToolTipString( wxPoint
&pt
)
1536 return m_tooltip
->GetTip() ;
1540 void wxWindow::MacFireMouseEvent( EventRecord
*ev
)
1542 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
1543 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1544 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1546 event
.m_leftDown
= isDown
&& !controlDown
;
1547 event
.m_middleDown
= FALSE
;
1548 event
.m_rightDown
= isDown
&& controlDown
;
1550 if ( ev
->what
== mouseDown
)
1553 event
.SetEventType(wxEVT_RIGHT_DOWN
) ;
1555 event
.SetEventType(wxEVT_LEFT_DOWN
) ;
1557 else if ( ev
->what
== mouseUp
)
1560 event
.SetEventType(wxEVT_RIGHT_UP
) ;
1562 event
.SetEventType(wxEVT_LEFT_UP
) ;
1566 event
.SetEventType(wxEVT_MOTION
) ;
1569 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1570 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1571 event
.m_altDown
= ev
->modifiers
& optionKey
;
1572 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1574 Point localwhere
= ev
->where
;
1577 ::GetPort( &port
) ;
1578 ::SetPort( UMAGetWindowPort( m_macWindowData
->m_macWindow
) ) ;
1579 ::GlobalToLocal( &localwhere
) ;
1582 if ( ev
->what
== mouseDown
)
1584 if ( ev
->when
- lastWhen
<= GetDblTime() )
1586 if ( abs( localwhere
.h
- lastWhere
.h
) < 3 || abs( localwhere
.v
- lastWhere
.v
) < 3 )
1589 event
.SetEventType(wxEVT_RIGHT_DCLICK
) ;
1591 event
.SetEventType(wxEVT_LEFT_DCLICK
) ;
1594 lastWhen
= ev
->when
;
1595 lastWhere
= localwhere
;
1598 event
.m_x
= localwhere
.h
;
1599 event
.m_y
= localwhere
.v
;
1604 wxPoint origin = GetClientAreaOrigin() ;
1606 event.m_x += origin.x ;
1607 event.m_y += origin.y ;
1610 event
.m_timeStamp
= ev
->when
;
1611 event
.SetEventObject(this);
1612 if ( wxTheApp
->s_captureWindow
)
1616 wxTheApp
->s_captureWindow
->ScreenToClient( &x
, &y
) ;
1619 wxTheApp
->s_captureWindow
->GetEventHandler()->ProcessEvent( event
) ;
1620 if ( ev
->what
== mouseUp
)
1622 wxTheApp
->s_captureWindow
= NULL
;
1623 if ( wxBusyCursorCount
== 0 )
1625 m_cursor
.MacInstall() ;
1631 MacDispatchMouseEvent( event
) ;
1635 void wxWindow::MacMouseDown( EventRecord
*ev
, short part
)
1637 MacFireMouseEvent( ev
) ;
1640 void wxWindow::MacMouseUp( EventRecord
*ev
, short part
)
1642 WindowPtr frontWindow
;
1647 MacFireMouseEvent( ev
) ;
1653 void wxWindow::MacMouseMoved( EventRecord
*ev
, short part
)
1655 WindowPtr frontWindow
;
1660 MacFireMouseEvent( ev
) ;
1665 void wxWindow::MacActivate( EventRecord
*ev
, bool inIsActivating
)
1667 wxActivateEvent
event(wxEVT_ACTIVATE
, inIsActivating
);
1668 event
.m_timeStamp
= ev
->when
;
1669 event
.SetEventObject(this);
1671 GetEventHandler()->ProcessEvent(event
);
1673 UMAHighlightAndActivateWindow( m_macWindowData
->m_macWindow
, inIsActivating
) ;
1676 void wxWindow::MacRedraw( RgnHandle updatergn
, long time
)
1678 // updatergn is always already clipped to our boundaries
1679 WindowRef window
= GetMacRootWindow() ;
1680 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1682 wxMacDrawingHelper
focus( this ) ; // was client
1685 WindowRef window
= GetMacRootWindow() ;
1686 bool eraseBackground
= false ;
1687 if ( m_macWindowData
)
1688 eraseBackground
= true ;
1689 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
1691 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
1693 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1695 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1696 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1697 // either a non gray background color or a non control window
1700 wxWindow
* parent
= GetParent() ;
1703 if ( parent
->GetMacRootWindow() != window
)
1705 // we are in a different window on the mac system
1710 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
1712 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1714 // if we have any other colours in the hierarchy
1715 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
1718 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1719 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
1722 GetRegionBounds( updatergn
, &box
) ;
1723 UMAApplyThemeBackground(kThemeBackgroundTabPane
, &box
, kThemeStateActive
,8,true);
1732 parent
= parent
->GetParent() ;
1736 // if there is nothing special -> use default
1737 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
1742 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
1744 if ( GetParent() && m_backgroundColour
!= GetParent()->GetBackgroundColour() )
1745 eraseBackground
= true ;
1746 SetClip( updatergn
) ;
1747 if ( eraseBackground
)
1749 EraseRgn( updatergn
) ;
1753 m_macUpdateRgn
= updatergn
;
1755 RgnHandle newupdate
= NewRgn() ;
1756 wxSize point
= GetClientSize() ;
1757 wxPoint origin
= GetClientAreaOrigin() ;
1759 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1760 SectRgn( newupdate
, m_macUpdateRgn
, newupdate
) ;
1761 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1762 m_updateRegion
= newupdate
;
1763 DisposeRgn( newupdate
) ;
1768 event
.m_timeStamp
= time
;
1769 event
.SetEventObject(this);
1770 GetEventHandler()->ProcessEvent(event
);
1774 RgnHandle childupdate
= NewRgn() ;
1776 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1778 wxWindow
*child
= (wxWindow
*)node
->Data();
1779 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1780 SectRgn( childupdate
, m_macUpdateRgn
, childupdate
) ;
1781 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1782 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1784 // because dialogs may also be children
1785 child
->MacRedraw( childupdate
, time
) ;
1788 DisposeRgn( childupdate
) ;
1789 // eventually a draw grow box here
1792 void wxWindow::MacUpdateImmediately()
1794 WindowRef window
= GetMacRootWindow() ;
1797 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1799 AGAPortHelper
help( GetWindowPort(window
) ) ;
1801 AGAPortHelper
help( (window
) ) ;
1803 SetOrigin( 0 , 0 ) ;
1804 BeginUpdate( window
) ;
1807 RgnHandle region
= NewRgn();
1811 GetPortVisibleRegion( GetWindowPort( window
), region
);
1813 // if windowshade gives incompatibility , take the follwing out
1814 if ( !EmptyRgn( region
) )
1816 win
->MacRedraw( region
, wxTheApp
->sm_lastMessageTime
) ;
1818 DisposeRgn( region
);
1821 EndUpdate( window
) ;
1825 void wxWindow::MacUpdate( EventRecord
*ev
)
1827 WindowRef window
= (WindowRef
) ev
->message
;
1828 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1830 AGAPortHelper
help( GetWindowPort(window
) ) ;
1832 AGAPortHelper
help( (window
) ) ;
1834 SetOrigin( 0 , 0 ) ;
1835 BeginUpdate( window
) ;
1838 RgnHandle region
= NewRgn();
1842 GetPortVisibleRegion( GetWindowPort( window
), region
);
1844 // if windowshade gives incompatibility , take the follwing out
1845 if ( !EmptyRgn( region
) )
1847 MacRedraw( region
, ev
->when
) ;
1849 DisposeRgn( region
);
1852 EndUpdate( window
) ;
1855 WindowRef
wxWindow::GetMacRootWindow() const
1857 WindowRef window
= NULL
;
1858 wxWindow
*iter
= (wxWindow
*)this ;
1862 if ( iter
->m_macWindowData
)
1863 return iter
->m_macWindowData
->m_macWindow
;
1865 iter
= iter
->GetParent() ;
1867 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1871 void wxWindow::MacCreateScrollBars( long style
)
1873 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
1875 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1876 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1878 GetClientSize( &width
, &height
) ;
1880 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1881 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1882 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1883 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1885 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
1886 vSize
, wxVERTICAL
);
1888 if ( style
& wxVSCROLL
)
1894 m_vScrollBar
->Show(false) ;
1896 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
1897 hSize
, wxHORIZONTAL
);
1898 if ( style
& wxHSCROLL
)
1903 m_hScrollBar
->Show(false) ;
1906 // because the create does not take into account the client area origin
1907 MacRepositionScrollBars() ; // we might have a real position shift
1910 void wxWindow::MacRepositionScrollBars()
1912 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
1913 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
1915 // get real client area
1917 int width
= m_width
;
1918 int height
= m_height
;
1920 width
-= 2 * MacGetBorderSize() ;
1921 height
-= 2 * MacGetBorderSize() ;
1923 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1924 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1925 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1926 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1933 MacClientToRootWindow( &x
, &y
) ;
1934 MacClientToRootWindow( &w
, &h
) ;
1936 WindowRef window
= NULL
;
1937 wxWindow
*iter
= (wxWindow
*)this ;
1939 int totW
= 10000 , totH
= 10000;
1942 if ( iter
->m_macWindowData
)
1944 totW
= iter
->m_width
;
1945 totH
= iter
->m_height
;
1949 iter
= iter
->GetParent() ;
1977 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1981 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1985 void wxWindow::MacKeyDown( EventRecord
*ev
)
1991 bool wxWindow::AcceptsFocus() const
1993 return MacCanFocus() && wxWindowBase::AcceptsFocus();
1996 ControlHandle
wxWindow::MacGetContainerForEmbedding()
1998 if ( m_macWindowData
)
1999 return m_macWindowData
->m_macRootControl
;
2001 return GetParent()->MacGetContainerForEmbedding() ;
2004 void wxWindow::MacSuperChangedPosition()
2006 // only window-absolute structures have to be moved i.e. controls
2008 wxNode
*node
= GetChildren().First();
2011 wxWindow
*child
= (wxWindow
*)node
->Data();
2012 child
->MacSuperChangedPosition() ;
2013 node
= node
->Next();
2018 bool wxWindow::MacSetupFocusPort( )
2026 MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
2027 return MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
2030 bool wxWindow::MacSetupFocusClientPort( )
2038 MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
2039 return MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
2042 bool wxWindow::MacSetupDrawingPort( )
2050 MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
2051 return MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
2054 bool wxWindow::MacSetupDrawingClientPort( )
2062 MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
2063 return MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
2067 bool wxWindow::MacSetPortFocusParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
2069 if ( window
== NULL
)
2075 ::GetPort(&currPort
);
2076 port
= UMAGetWindowPort( window
) ;
2077 if (currPort
!= port
)
2080 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2081 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2085 bool wxWindow::MacSetPortDrawingParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
2087 if ( window
== NULL
)
2092 ::GetPort(&currPort
);
2093 port
= UMAGetWindowPort( window
) ;
2094 if (currPort
!= port
)
2096 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2097 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2098 ::ClipRect(&clipRect
);
2101 ::RGBBackColor(& win
->GetBackgroundColour().GetPixel() ) ;
2102 ::RGBForeColor(& win
->GetForegroundColour().GetPixel() ) ;
2103 Pattern whiteColor
;
2105 ::BackPat( GetQDGlobalsWhite( &whiteColor
) ) ;
2106 ::UMASetThemeWindowBackground( win
->m_macWindowData
->m_macWindow
, win
->m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
2110 void wxWindow::MacGetPortParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2112 if ( m_macWindowData
)
2118 clipRect
->right
= m_width
;
2119 clipRect
->bottom
= m_height
;
2120 *window
= m_macWindowData
->m_macWindow
;
2125 wxASSERT( GetParent() != NULL
) ;
2126 GetParent()->MacGetPortParams( localOrigin
, clipRect
, window
, rootwin
) ;
2127 localOrigin
->h
+= m_x
;
2128 localOrigin
->v
+= m_y
;
2129 OffsetRect(clipRect
, -m_x
, -m_y
);
2134 myClip
.right
= m_width
;
2135 myClip
.bottom
= m_height
;
2136 SectRect(clipRect
, &myClip
, clipRect
);
2140 void wxWindow::MacDoGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2142 // int width , height ;
2143 // GetClientSize( &width , &height ) ;
2145 if ( m_macWindowData
)
2151 clipRect
->right
= m_width
;//width;
2152 clipRect
->bottom
= m_height
;// height;
2153 *window
= m_macWindowData
->m_macWindow
;
2158 wxASSERT( GetParent() != NULL
) ;
2160 GetParent()->MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2162 localOrigin
->h
+= m_x
;
2163 localOrigin
->v
+= m_y
;
2164 OffsetRect(clipRect
, -m_x
, -m_y
);
2169 myClip
.right
= m_width
;//width;
2170 myClip
.bottom
= m_height
;// height;
2171 SectRect(clipRect
, &myClip
, clipRect
);
2175 void wxWindow::MacGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2177 MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2179 int width
, height
;
2180 GetClientSize( &width
, &height
) ;
2182 client
= GetClientAreaOrigin( ) ;
2184 localOrigin
->h
+= client
.x
;
2185 localOrigin
->v
+= client
.y
;
2186 OffsetRect(clipRect
, -client
.x
, -client
.y
);
2191 myClip
.right
= width
;
2192 myClip
.bottom
= height
;
2193 SectRect(clipRect
, &myClip
, clipRect
);
2196 long wxWindow::MacGetBorderSize( ) const
2198 if( m_macWindowData
)
2201 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2205 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2209 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2216 long wxWindow::MacRemoveBordersFromStyle( long style
)
2218 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2221 wxMacFocusHelper::wxMacFocusHelper( wxWindow * theWindow )
2228 m_currentPort = NULL ;
2229 GetPort( &m_formerPort ) ;
2233 theWindow->MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
2234 m_currentPort = UMAGetWindowPort( window ) ;
2235 theWindow->MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
2240 wxMacFocusHelper::~wxMacFocusHelper()
2244 SetPort( m_currentPort ) ;
2245 SetOrigin( 0 , 0 ) ;
2247 if ( m_formerPort != m_currentPort )
2248 SetPort( m_formerPort ) ;
2251 wxMacDrawingHelper::wxMacDrawingHelper( wxWindow
* theWindow
)
2258 m_currentPort
= NULL
;
2260 GetPort( &m_formerPort
) ;
2263 theWindow
->MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2264 m_currentPort
= UMAGetWindowPort( window
) ;
2265 if ( m_formerPort
!= m_currentPort
)
2266 SetPort( m_currentPort
) ;
2267 GetPenState( &m_savedPenState
) ;
2268 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2273 wxMacDrawingHelper::~wxMacDrawingHelper()
2277 SetPort( m_currentPort
) ;
2278 SetPenState( &m_savedPenState
) ;
2279 SetOrigin( 0 , 0 ) ;
2281 GetPortBounds( m_currentPort
, &portRect
) ;
2282 ClipRect( &portRect
) ;
2285 if ( m_formerPort
!= m_currentPort
)
2286 SetPort( m_formerPort
) ;
2289 wxMacFocusClientHelper::wxMacFocusClientHelper( wxWindow * theWindow )
2296 m_currentPort = NULL ;
2298 GetPort( &m_formerPort ) ;
2302 theWindow->MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
2303 m_currentPort = UMAGetWindowPort( window ) ;
2304 theWindow->MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
2309 wxMacFocusClientHelper::~wxMacFocusClientHelper()
2313 SetPort( m_currentPort ) ;
2314 SetOrigin( 0 , 0 ) ;
2316 if ( m_formerPort != m_currentPort )
2317 SetPort( m_formerPort ) ;
2321 wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindow
* theWindow
)
2328 m_currentPort
= NULL
;
2330 GetPort( &m_formerPort
) ;
2334 theWindow
->MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2335 m_currentPort
= UMAGetWindowPort( window
) ;
2336 if ( m_formerPort
!= m_currentPort
)
2337 SetPort( m_currentPort
) ;
2338 GetPenState( &m_savedPenState
) ;
2339 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2344 wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
2348 SetPort( m_currentPort
) ;
2349 SetPenState( &m_savedPenState
) ;
2350 SetOrigin( 0 , 0 ) ;
2352 GetPortBounds( m_currentPort
, &portRect
) ;
2353 ClipRect( &portRect
) ;
2356 if ( m_formerPort
!= m_currentPort
)
2357 SetPort( m_formerPort
) ;
2360 // Find the wxWindow at the current mouse position, returning the mouse
2362 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
2364 pt
= wxGetMousePosition();
2365 wxWindow
* found
= wxFindWindowAtPoint(pt
);
2369 // Get the current mouse position.
2370 wxPoint
wxGetMousePosition()
2373 wxGetMousePosition(& x
, & y
);
2374 return wxPoint(x
, y
);