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/scrolbar.h"
27 #include "wx/statbox.h"
28 #include "wx/button.h"
29 #include "wx/settings.h"
30 #include "wx/msgdlg.h"
32 #include "wx/notebook.h"
33 #include "wx/tabctrl.h"
34 #include "wx/tooltip.h"
35 #include "wx/statusbr.h"
36 // TODO remove the line below, just for lookup-up convenience CS
37 #include "wx/window.h"
39 #include "wx/menuitem.h"
46 #define wxWINDOW_HSCROLL 5998
47 #define wxWINDOW_VSCROLL 5997
48 #define MAC_SCROLLBAR_SIZE 16
50 #include <wx/mac/uma.h>
52 #if wxUSE_DRAG_AND_DROP
58 extern wxList wxPendingDelete
;
59 wxWindow
* gFocusWindow
= NULL
;
61 #if !USE_SHARED_LIBRARY
62 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxEvtHandler
)
63 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
64 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground
)
65 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
66 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
67 EVT_IDLE(wxWindow::OnIdle
)
68 // EVT_SCROLL(wxWindow::OnScroll)
75 // ===========================================================================
77 // ===========================================================================
79 // ---------------------------------------------------------------------------
80 // wxWindow utility functions
81 // ---------------------------------------------------------------------------
83 // Find an item given the Macintosh Window Reference
85 wxList
*wxWinMacWindowList
= NULL
;
86 wxWindow
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
88 wxNode
*node
= wxWinMacWindowList
->Find((long)inWindowRef
);
91 return (wxWindow
*)node
->Data();
94 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxWindow
*win
)
96 // adding NULL WindowRef is (first) surely a result of an error and
97 // (secondly) breaks menu command processing
98 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, "attempt to add a NULL WindowRef to window list" );
100 if ( !wxWinMacWindowList
->Find((long)inWindowRef
) )
101 wxWinMacWindowList
->Append((long)inWindowRef
, win
);
104 void wxRemoveMacWindowAssociation(wxWindow
*win
)
106 wxWinMacWindowList
->DeleteObject(win
);
109 // ----------------------------------------------------------------------------
110 // constructors and such
111 // ----------------------------------------------------------------------------
113 void wxWindow::Init()
119 m_doubleClickAllowed
= 0;
120 m_winCaptured
= FALSE
;
122 m_isBeingDeleted
= FALSE
;
125 m_mouseInWindow
= FALSE
;
129 m_backgroundTransparent
= FALSE
;
131 // as all windows are created with WS_VISIBLE style...
134 m_macWindowData
= NULL
;
141 m_hScrollBar
= NULL
;
142 m_vScrollBar
= NULL
;
144 #if wxUSE_DRAG_AND_DROP
145 m_pDropTarget
= NULL
;
150 wxWindow::~wxWindow()
152 m_isBeingDeleted
= TRUE
;
154 if ( s_lastMouseWindow
== this )
156 s_lastMouseWindow
= NULL
;
159 if ( gFocusWindow
== this )
161 gFocusWindow
= NULL
;
165 m_parent
->RemoveChild(this);
169 if ( m_macWindowData
)
171 wxToolTip::NotifyWindowDelete(m_macWindowData
->m_macWindow
) ;
172 UMADisposeWindow( m_macWindowData
->m_macWindow
) ;
173 delete m_macWindowData
;
174 wxRemoveMacWindowAssociation( this ) ;
179 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
183 const wxString
& name
)
185 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindow without parent") );
187 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
190 parent
->AddChild(this);
194 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
195 m_width
= WidthDefault( size
.x
);
196 m_height
= HeightDefault( size
.y
) ;
198 if ( ! IsKindOf( CLASSINFO ( wxControl
) ) && ! IsKindOf( CLASSINFO( wxStatusBar
) ) )
200 MacCreateScrollBars( style
) ;
206 void wxWindow::SetFocus()
208 if ( AcceptsFocus() )
214 if ( gFocusWindow
->m_caret
)
216 gFocusWindow
->m_caret
->OnKillFocus();
218 #endif // wxUSE_CARET
219 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
220 if ( control
&& control
->GetMacControl() )
222 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlFocusNoPart
) ;
223 control
->MacRedrawControl() ;
225 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
226 event
.SetEventObject(gFocusWindow
);
227 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
229 gFocusWindow
= this ;
235 m_caret
->OnSetFocus();
237 #endif // wxUSE_CARET
238 // panel wants to track the window which was the last to have focus in it
239 wxPanel
*panel
= wxDynamicCast(GetParent(), wxPanel
);
242 panel
->SetLastFocus(this);
244 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
245 if ( control
&& control
->GetMacControl() )
247 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlEditTextPart
) ;
250 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
251 event
.SetEventObject(this);
252 GetEventHandler()->ProcessEvent(event
) ;
257 bool wxWindow::Enable(bool enable
)
259 if ( !wxWindowBase::Enable(enable
) )
262 wxWindowList::Node
*node
= GetChildren().GetFirst();
265 wxWindow
*child
= node
->GetData();
266 child
->Enable(enable
);
268 node
= node
->GetNext();
274 void wxWindow::CaptureMouse()
276 wxTheApp
->s_captureWindow
= this ;
279 void wxWindow::ReleaseMouse()
281 wxTheApp
->s_captureWindow
= NULL
;
284 #if wxUSE_DRAG_AND_DROP
286 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
288 if ( m_pDropTarget
!= 0 ) {
289 delete m_pDropTarget
;
292 m_pDropTarget
= pDropTarget
;
293 if ( m_pDropTarget
!= 0 )
301 // Old style file-manager drag&drop
302 void wxWindow::DragAcceptFiles(bool accept
)
308 void wxWindow::DoGetSize(int *x
, int *y
) const
314 void wxWindow::DoGetPosition(int *x
, int *y
) const
320 wxPoint
pt(GetParent()->GetClientAreaOrigin());
327 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
329 menu
->SetInvokingWindow(this);
331 ClientToScreen( &x
, &y
) ;
333 ::InsertMenu( menu
->GetHMenu() , -1 ) ;
334 long menuResult
= ::PopUpMenuSelect(menu
->GetHMenu() ,y
,x
, 0) ;
335 menu
->MacMenuSelect( this , TickCount() , HiWord(menuResult
) , LoWord(menuResult
) ) ;
336 ::DeleteMenu( menu
->MacGetMenuId() ) ;
337 menu
->SetInvokingWindow(NULL
);
342 void wxWindow::DoScreenToClient(int *x
, int *y
) const
344 WindowRef window
= GetMacRootWindow() ;
352 ::SetPort( UMAGetWindowPort( window
) ) ;
353 ::GlobalToLocal( &localwhere
) ;
359 MacRootWindowToClient( x
, y
) ;
362 void wxWindow::DoClientToScreen(int *x
, int *y
) const
364 WindowRef window
= GetMacRootWindow() ;
366 MacClientToRootWindow( x
, y
) ;
374 ::SetPort( UMAGetWindowPort( window
) ) ;
375 ::SetOrigin( 0 , 0 ) ;
376 ::LocalToGlobal( &localwhere
) ;
382 void wxWindow::MacClientToRootWindow( int *x
, int *y
) const
384 if ( m_macWindowData
)
391 GetParent()->MacClientToRootWindow( x
, y
) ;
395 void wxWindow::MacRootWindowToClient( int *x
, int *y
) const
397 if ( m_macWindowData
)
404 GetParent()->MacRootWindowToClient( x
, y
) ;
408 bool wxWindow::SetCursor(const wxCursor
& cursor
)
410 if ( !wxWindowBase::SetCursor(cursor
) )
416 wxASSERT_MSG( m_cursor
.Ok(),
417 wxT("cursor must be valid after call to the base version"));
423 // Change the cursor NOW if we're within the correct window
425 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
427 if ( mouseWin
== this && !wxIsBusy() )
429 cursor
.MacInstall() ;
437 // Get size *available for subwindows* i.e. excluding menu bar etc.
438 void wxWindow::DoGetClientSize(int *x
, int *y
) const
443 *x
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
444 *y
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
446 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
453 MacClientToRootWindow( &x1
, &y1
) ;
454 MacClientToRootWindow( &w
, &h
) ;
456 WindowRef window
= NULL
;
457 wxWindow
*iter
= (wxWindow
*)this ;
459 int totW
= 10000 , totH
= 10000;
462 if ( iter
->m_macWindowData
)
464 totW
= iter
->m_width
;
465 totH
= iter
->m_height
;
469 iter
= iter
->GetParent() ;
472 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
474 (*y
) -= MAC_SCROLLBAR_SIZE
;
480 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
482 (*x
) -= MAC_SCROLLBAR_SIZE
;
492 // ----------------------------------------------------------------------------
494 // ----------------------------------------------------------------------------
498 void wxWindow::DoSetToolTip(wxToolTip
*tooltip
)
500 wxWindowBase::DoSetToolTip(tooltip
);
503 m_tooltip
->SetWindow(this);
506 #endif // wxUSE_TOOLTIPS
508 void wxWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
510 DoSetSize( x
,y
, width
, height
) ;
513 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
518 int former_w
= m_width
;
519 int former_h
= m_height
;
521 int currentX
, currentY
;
522 GetPosition(¤tX
, ¤tY
);
523 int currentW
,currentH
;
524 GetSize(¤tW
, ¤tH
);
526 int actualWidth
= width
;
527 int actualHeight
= height
;
530 if (x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
532 if (y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
535 actualWidth
= currentW
;
537 actualHeight
= currentH
;
539 if ( actualX
== currentX
&& actualY
== currentY
&& actualWidth
== currentW
&& actualHeight
== currentH
)
541 MacRepositionScrollBars() ; // we might have a real position shift
545 AdjustForParentClientOrigin(actualX
, actualY
, sizeFlags
);
548 bool doMove
= false ;
549 bool doResize
= false ;
551 if ( actualX
!= former_x
|| actualY
!= former_y
)
555 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
560 if ( doMove
|| doResize
)
562 if ( m_macWindowData
)
567 // erase former position
568 wxMacDrawingHelper
focus( this ) ;
571 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
572 ClipRect( &clientrect
) ;
573 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
578 m_width
= actualWidth
;
579 m_height
= actualHeight
;
580 if ( m_macWindowData
)
583 ::MoveWindow(m_macWindowData
->m_macWindow
, m_x
, m_y
, false); // don't make frontmost
586 ::SizeWindow(m_macWindowData
->m_macWindow
, m_width
, m_height
, true);
588 // the OS takes care of invalidating and erasing the new area
589 // we have erased the old one
591 if ( IsKindOf( CLASSINFO( wxFrame
) ) )
593 wxFrame
* frame
= (wxFrame
*) this ;
594 frame
->PositionStatusBar();
595 frame
->PositionToolBar();
600 // erase new position
603 wxMacDrawingHelper
focus( this ) ;
606 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
607 ClipRect( &clientrect
) ;
608 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
613 wxWindow::MacSuperChangedPosition() ; // like this only children will be notified
615 MacRepositionScrollBars() ;
618 wxMoveEvent
event(wxPoint(m_x
, m_y
), m_windowId
);
619 event
.SetEventObject(this);
620 GetEventHandler()->ProcessEvent(event
) ;
624 MacRepositionScrollBars() ;
625 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
626 event
.SetEventObject(this);
627 GetEventHandler()->ProcessEvent(event
);
631 // For implementation purposes - sometimes decorations make the client area
634 wxPoint
wxWindow::GetClientAreaOrigin() const
636 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
639 // Makes an adjustment to the window position (for example, a frame that has
640 // a toolbar that it manages itself).
641 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
643 if( !m_macWindowData
)
645 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
647 wxPoint
pt(GetParent()->GetClientAreaOrigin());
648 x
+= pt
.x
; y
+= pt
.y
;
653 void wxWindow::SetTitle(const wxString
& title
)
659 if( wxApp::s_macDefaultEncodingIsPC
)
660 label
= wxMacMakeMacStringFromPC( title
) ;
664 if ( m_macWindowData
)
665 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
668 wxString
wxWindow::GetTitle() const
673 bool wxWindow::Show(bool show
)
675 if ( !wxWindowBase::Show(show
) )
678 if ( m_macWindowData
)
682 UMAShowWindow( m_macWindowData
->m_macWindow
) ;
683 UMASelectWindow( m_macWindowData
->m_macWindow
) ;
684 // no need to generate events here, they will get them triggered by macos
685 // actually they should be , but apparently they are not
686 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
687 event
.SetEventObject(this);
688 GetEventHandler()->ProcessEvent(event
);
692 UMAHideWindow( m_macWindowData
->m_macWindow
) ;
695 MacSuperShown( show
) ;
698 MacUpdateImmediately() ;
703 void wxWindow::MacSuperShown( bool show
)
705 wxNode
*node
= GetChildren().First();
708 wxWindow
*child
= (wxWindow
*)node
->Data();
709 if ( child
->m_isShown
)
710 child
->MacSuperShown( show
) ;
715 bool wxWindow::MacIsReallyShown() const
717 bool status
= m_isShown
;
718 wxWindow
* win
= this ;
719 while ( status
&& win
->m_parent
!= NULL
)
721 win
= win
->m_parent
;
722 status
= win
->m_isShown
;
727 int wxWindow::GetCharHeight() const
729 wxClientDC
dc ( (wxWindow
*)this ) ;
730 return dc
.GetCharHeight() ;
733 int wxWindow::GetCharWidth() const
735 wxClientDC
dc ( (wxWindow
*)this ) ;
736 return dc
.GetCharWidth() ;
739 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
740 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
742 const wxFont
*fontToUse
= theFont
;
746 wxClientDC
dc( (wxWindow
*) this ) ;
748 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, fontToUse
) ;
749 if ( externalLeading
)
750 *externalLeading
= le
;
759 void wxWindow::MacEraseBackground( Rect
*rect
)
761 WindowRef window
= GetMacRootWindow() ;
762 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
764 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
766 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
768 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
769 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
770 // either a non gray background color or a non control window
772 wxWindow
* parent
= GetParent() ;
775 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
777 // if we have any other colours in the hierarchy
778 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
781 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
783 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
784 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
786 UMAApplyThemeBackground(kThemeBackgroundTabPane
, rect
, kThemeStateActive
,8,true);
792 // we have arrived at a non control item
796 parent
= parent
->GetParent() ;
800 // if there is nothing special -> use default
801 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
806 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
811 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
813 wxWindow
*child
= (wxWindow
*)node
->Data();
815 Rect clientrect
= { child
->m_x
, child
->m_y
, child
->m_x
+child
->m_width
, child
->m_y
+ child
->m_height
} ;
816 SectRect( &clientrect
, rect
, &clientrect
) ;
818 OffsetRect( &clientrect
, -child
->m_x
, -child
->m_y
) ;
819 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() )
821 wxMacDrawingClientHelper
focus( this ) ;
824 child
->MacEraseBackground( &clientrect
) ;
830 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
832 wxMacDrawingHelper
focus( this ) ;
835 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
836 ClipRect( &clientrect
) ;
840 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
841 SectRect( &clientrect
, &r
, &clientrect
) ;
843 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
847 // Responds to colour changes: passes event on to children.
848 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
850 wxNode
*node
= GetChildren().First();
853 // Only propagate to non-top-level windows
854 wxWindow
*win
= (wxWindow
*)node
->Data();
855 if ( win
->GetParent() )
857 wxSysColourChangedEvent event2
;
858 event
.m_eventObject
= win
;
859 win
->GetEventHandler()->ProcessEvent(event2
);
866 #if wxUSE_CARET && WXWIN_COMPATIBILITY
867 // ---------------------------------------------------------------------------
868 // Caret manipulation
869 // ---------------------------------------------------------------------------
871 void wxWindow::CreateCaret(int w
, int h
)
873 SetCaret(new wxCaret(this, w
, h
));
876 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
878 wxFAIL_MSG("not implemented");
881 void wxWindow::ShowCaret(bool show
)
883 wxCHECK_RET( m_caret
, "no caret to show" );
888 void wxWindow::DestroyCaret()
893 void wxWindow::SetCaretPos(int x
, int y
)
895 wxCHECK_RET( m_caret
, "no caret to move" );
900 void wxWindow::GetCaretPos(int *x
, int *y
) const
902 wxCHECK_RET( m_caret
, "no caret to get position of" );
904 m_caret
->GetPosition(x
, y
);
906 #endif // wxUSE_CARET
908 wxWindow
*wxGetActiveWindow()
910 // actually this is a windows-only concept
914 // Coordinates relative to the window
915 void wxWindow::WarpPointer (int x_pos
, int y_pos
)
917 // We really dont move the mouse programmatically under mac
920 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
922 // TODO : probably we would adopt the EraseEvent structure
925 int wxWindow::GetScrollPos(int orient
) const
927 if ( orient
== wxHORIZONTAL
)
930 return m_hScrollBar
->GetThumbPosition() ;
935 return m_vScrollBar
->GetThumbPosition() ;
940 // This now returns the whole range, not just the number
941 // of positions that we can scroll.
942 int wxWindow::GetScrollRange(int orient
) const
944 if ( orient
== wxHORIZONTAL
)
947 return m_hScrollBar
->GetRange() ;
952 return m_vScrollBar
->GetRange() ;
957 int wxWindow::GetScrollThumb(int orient
) const
959 if ( orient
== wxHORIZONTAL
)
962 return m_hScrollBar
->GetThumbSize() ;
967 return m_vScrollBar
->GetThumbSize() ;
972 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
974 if ( orient
== wxHORIZONTAL
)
977 m_hScrollBar
->SetThumbPosition( pos
) ;
982 m_vScrollBar
->SetThumbPosition( pos
) ;
986 void wxWindow::MacCreateRealWindow( const wxString
& title
,
990 const wxString
& name
)
993 m_windowStyle
= style
;
1014 m_macWindowData
= new MacWindowData() ;
1016 ::SetRect(&theBoundsRect
, m_x
, m_y
, m_x
+ m_width
, m_y
+ m_height
);
1018 // translate the window attributes in the appropriate window class and attributes
1020 WindowClass wclass
= 0;
1021 WindowAttributes attr
= kWindowNoAttributes
;
1023 if ( HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
) )
1025 wclass
= kFloatingWindowClass
;
1026 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1028 attr
|= kWindowSideTitlebarAttribute
;
1031 else if ( HasFlag( wxTHICK_FRAME
) )
1033 if ( HasFlag( wxDIALOG_MODAL
) )
1035 wclass
= kMovableModalWindowClass
;
1037 else if ( HasFlag( wxDIALOG_MODELESS
) )
1039 wclass
= kDocumentWindowClass
;
1043 if ( HasFlag( wxCAPTION
) )
1045 wclass
= kDocumentWindowClass
;
1049 wclass
= kModalWindowClass
;
1055 wclass
= kModalWindowClass
;
1058 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) )
1060 attr
|= kWindowFullZoomAttribute
;
1061 attr
|= kWindowCollapseBoxAttribute
;
1063 if ( HasFlag( wxRESIZE_BORDER
) )
1065 attr
|= kWindowResizableAttribute
;
1067 if ( HasFlag( wxSYSTEM_MENU
) )
1069 attr
|= kWindowCloseBoxAttribute
;
1072 UMACreateNewWindow( wclass
, attr
, &theBoundsRect
, &m_macWindowData
->m_macWindow
) ;
1073 wxAssociateWinWithMacWindow( m_macWindowData
->m_macWindow
, this ) ;
1075 if( wxApp::s_macDefaultEncodingIsPC
)
1076 label
= wxMacMakeMacStringFromPC( title
) ;
1079 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
1080 UMACreateRootControl( m_macWindowData
->m_macWindow
, &m_macWindowData
->m_macRootControl
) ;
1082 m_macWindowData
->m_macFocus
= NULL
;
1085 void wxWindow::MacPaint( wxPaintEvent
&event
)
1089 void wxWindow::MacPaintBorders( )
1091 if( m_macWindowData
)
1094 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1095 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1096 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1097 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1100 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1102 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1103 RGBColor pen1
= sunken
? white
: black
;
1104 RGBColor pen2
= sunken
? shadow
: face
;
1105 RGBColor pen3
= sunken
? face
: shadow
;
1106 RGBColor pen4
= sunken
? black
: white
;
1108 RGBForeColor( &pen1
) ;
1110 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1111 FrameRect( &rect
) ;
1113 RGBForeColor( &pen2
) ;
1115 Rect rect
= { 1 , 1 , m_height
-1 , m_width
-1} ;
1116 FrameRect( &rect
) ;
1118 RGBForeColor( &pen3
) ;
1120 Rect rect
= { 0 , 0 , m_height
-2 , m_width
-2} ;
1121 FrameRect( &rect
) ;
1123 RGBForeColor( &pen4
) ;
1126 LineTo( m_width
- 3 , 0 ) ;
1128 LineTo( 0 , m_height
- 3 ) ;
1131 else if (HasFlag(wxSIMPLE_BORDER
))
1133 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1134 RGBForeColor( &black
) ;
1135 FrameRect( &rect
) ;
1138 if ( this->GetParent() )
1140 wxPaintDC dc(GetParent());
1141 GetParent()->PrepareDC(dc);
1143 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) )
1145 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1147 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1148 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1150 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1151 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1152 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1153 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1156 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1159 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1162 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1165 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1166 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1168 else if (HasFlag(wxDOUBLE_BORDER))
1170 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1172 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1173 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1175 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1176 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1177 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1178 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1181 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1184 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1187 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1190 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1191 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1193 else if (HasFlag(wxSIMPLE_BORDER))
1195 dc.SetPen(*wxBLACK_PEN);
1196 dc.DrawRectangle(m_x, m_y, m_width, m_height);
1202 // New function that will replace some of the above.
1203 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1204 int range
, bool refresh
)
1206 if ( orient
== wxHORIZONTAL
)
1210 if ( range
== 0 || thumbVisible
>= range
)
1212 if ( m_hScrollBar
->IsShown() )
1213 m_hScrollBar
->Show(false) ;
1217 if ( !m_hScrollBar
->IsShown() )
1218 m_hScrollBar
->Show(true) ;
1219 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, refresh
) ;
1227 if ( range
== 0 || thumbVisible
>= range
)
1229 if ( m_vScrollBar
->IsShown() )
1230 m_vScrollBar
->Show(false) ;
1234 if ( !m_vScrollBar
->IsShown() )
1235 m_vScrollBar
->Show(true) ;
1236 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, refresh
) ;
1240 MacRepositionScrollBars() ;
1243 // Does a physical scroll
1244 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1246 wxMacDrawingClientHelper
focus( this ) ;
1249 int width
, height
;
1250 GetClientSize( &width
, &height
) ;
1252 Rect scrollrect
= { 0 , 0 , height
, width
} ;
1254 RgnHandle updateRgn
= NewRgn() ;
1255 ClipRect( &scrollrect
) ;
1258 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
1259 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1261 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1262 InvalWindowRgn( GetMacRootWindow() , updateRgn
) ;
1263 DisposeRgn( updateRgn
) ;
1266 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1268 wxWindow
*child
= (wxWindow
*)node
->Data();
1269 if (child
== m_vScrollBar
) continue;
1270 if (child
== m_hScrollBar
) continue;
1271 if (child
->IsTopLevel()) continue;
1273 child
->GetPosition( &x
, &y
);
1275 child
->GetSize( &w
, &h
);
1276 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1281 void wxWindow::MacOnScroll(wxScrollEvent
&event
)
1283 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1285 wxScrollWinEvent wevent
;
1286 wevent
.SetPosition(event
.GetPosition());
1287 wevent
.SetOrientation(event
.GetOrientation());
1288 wevent
.m_eventObject
= this;
1290 if (event
.m_eventType
== wxEVT_SCROLL_TOP
) {
1291 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1293 if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
) {
1294 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1296 if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
) {
1297 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1299 if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
) {
1300 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1302 if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
) {
1303 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1305 if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
) {
1306 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1308 if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
) {
1309 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1312 GetEventHandler()->ProcessEvent(wevent
);
1316 bool wxWindow::SetFont(const wxFont
& font
)
1318 if ( !wxWindowBase::SetFont(font
) )
1327 // Get the window with the focus
1328 wxWindow
*wxWindowBase::FindFocus()
1330 return gFocusWindow
;
1333 #if WXWIN_COMPATIBILITY
1334 // If nothing defined for this, try the parent.
1335 // E.g. we may be a button loaded from a resource, with no callback function
1337 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1339 if ( GetEventHandler()->ProcessEvent(event
) )
1342 m_parent
->GetEventHandler()->OnCommand(win
, event
);
1344 #endif // WXWIN_COMPATIBILITY_2
1346 #if WXWIN_COMPATIBILITY
1347 wxObject
* wxWindow::GetChild(int number
) const
1349 // Return a pointer to the Nth object in the Panel
1350 wxNode
*node
= GetChildren().First();
1353 node
= node
->Next();
1356 wxObject
*obj
= (wxObject
*)node
->Data();
1362 #endif // WXWIN_COMPATIBILITY
1364 void wxWindow::Clear()
1366 if ( m_macWindowData
)
1368 wxMacDrawingClientHelper
helper ( this ) ;
1370 wxPoint origin
= GetClientAreaOrigin() ;
1371 GetClientSize( &w
, &h
) ;
1372 UMASetThemeWindowBackground( m_macWindowData
->m_macWindow
, m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
1373 Rect r
= { origin
.y
, origin
.x
, origin
.y
+h
, origin
.x
+w
} ;
1378 wxClientDC
dc(this);
1379 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1380 dc
.SetBackground(brush
);
1385 // Setup background and foreground colours correctly
1386 void wxWindow::SetupColours()
1389 SetBackgroundColour(GetParent()->GetBackgroundColour());
1392 void wxWindow::OnIdle(wxIdleEvent
& event
)
1395 // Check if we need to send a LEAVE event
1396 if (m_mouseInWindow)
1399 ::GetCursorPos(&pt);
1400 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1402 // Generate a LEAVE event
1403 m_mouseInWindow = FALSE;
1404 MSWOnMouseLeave(pt.x, pt.y, 0);
1409 // This calls the UI-update mechanism (querying windows for
1410 // menu/toolbar/control state information)
1414 // Raise the window to the top of the Z order
1415 void wxWindow::Raise()
1420 // Lower the window to the bottom of the Z order
1421 void wxWindow::Lower()
1426 void wxWindow::DoSetClientSize(int width
, int height
)
1428 if ( width
!= -1 || height
!= -1 )
1431 if ( width
!= -1 && m_vScrollBar
)
1432 width
+= MAC_SCROLLBAR_SIZE
;
1433 if ( height
!= -1 && m_vScrollBar
)
1434 height
+= MAC_SCROLLBAR_SIZE
;
1436 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1437 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1439 DoSetSize( -1 , -1 , width
, height
) ;
1444 wxWindow
* wxWindow::s_lastMouseWindow
= NULL
;
1446 bool wxWindow::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindow
** outWin
)
1448 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1449 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1452 WindowRef window
= GetMacRootWindow() ;
1454 wxPoint
newPoint( point
) ;
1459 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1461 wxWindow
*child
= (wxWindow
*)node
->Data();
1462 // added the m_isShown test --dmazzoni
1463 if ( child
->GetMacRootWindow() == window
&& child
->m_isShown
)
1465 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1474 bool wxWindow::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindow
** outWin
)
1477 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1478 if ( ::FindWindow( pt
, &window
) == 3 )
1480 wxPoint
point( screenpoint
) ;
1481 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1484 win
->ScreenToClient( point
) ;
1485 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1491 extern int wxBusyCursorCount
;
1493 bool wxWindow::MacDispatchMouseEvent(wxMouseEvent
& event
)
1495 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1496 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1500 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) )
1503 WindowRef window
= GetMacRootWindow() ;
1511 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1513 wxWindow
*child
= (wxWindow
*)node
->Data();
1514 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1516 if (child
->MacDispatchMouseEvent(event
))
1524 if ( wxBusyCursorCount
== 0 )
1526 m_cursor
.MacInstall() ;
1530 if ( event
.GetEventType() == wxEVT_MOTION
1531 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1532 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1533 wxToolTip::RelayEvent( this , event
);
1534 #endif // wxUSE_TOOLTIPS
1535 GetEventHandler()->ProcessEvent( event
) ;
1542 wxString
wxWindow::MacGetToolTipString( wxPoint
&pt
)
1546 return m_tooltip
->GetTip() ;
1550 void wxWindow::MacFireMouseEvent( EventRecord
*ev
)
1552 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
1553 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1554 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1556 event
.m_leftDown
= isDown
&& !controlDown
;
1557 event
.m_middleDown
= FALSE
;
1558 event
.m_rightDown
= isDown
&& controlDown
;
1560 if ( ev
->what
== mouseDown
)
1563 event
.SetEventType(wxEVT_RIGHT_DOWN
) ;
1565 event
.SetEventType(wxEVT_LEFT_DOWN
) ;
1567 else if ( ev
->what
== mouseUp
)
1570 event
.SetEventType(wxEVT_RIGHT_UP
) ;
1572 event
.SetEventType(wxEVT_LEFT_UP
) ;
1576 event
.SetEventType(wxEVT_MOTION
) ;
1579 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1580 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1581 event
.m_altDown
= ev
->modifiers
& optionKey
;
1582 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1584 Point localwhere
= ev
->where
;
1587 ::GetPort( &port
) ;
1588 ::SetPort( UMAGetWindowPort( m_macWindowData
->m_macWindow
) ) ;
1589 ::GlobalToLocal( &localwhere
) ;
1592 if ( ev
->what
== mouseDown
)
1594 if ( ev
->when
- lastWhen
<= GetDblTime() )
1596 if ( abs( localwhere
.h
- lastWhere
.h
) < 3 || abs( localwhere
.v
- lastWhere
.v
) < 3 )
1599 event
.SetEventType(wxEVT_RIGHT_DCLICK
) ;
1601 event
.SetEventType(wxEVT_LEFT_DCLICK
) ;
1604 lastWhen
= ev
->when
;
1605 lastWhere
= localwhere
;
1608 event
.m_x
= localwhere
.h
;
1609 event
.m_y
= localwhere
.v
;
1614 wxPoint origin = GetClientAreaOrigin() ;
1616 event.m_x += origin.x ;
1617 event.m_y += origin.y ;
1620 event
.m_timeStamp
= ev
->when
;
1621 event
.SetEventObject(this);
1622 if ( wxTheApp
->s_captureWindow
)
1626 wxTheApp
->s_captureWindow
->ScreenToClient( &x
, &y
) ;
1629 wxTheApp
->s_captureWindow
->GetEventHandler()->ProcessEvent( event
) ;
1630 if ( ev
->what
== mouseUp
)
1632 wxTheApp
->s_captureWindow
= NULL
;
1633 if ( wxBusyCursorCount
== 0 )
1635 m_cursor
.MacInstall() ;
1641 MacDispatchMouseEvent( event
) ;
1645 void wxWindow::MacMouseDown( EventRecord
*ev
, short part
)
1647 MacFireMouseEvent( ev
) ;
1650 void wxWindow::MacMouseUp( EventRecord
*ev
, short part
)
1652 WindowPtr frontWindow
;
1657 MacFireMouseEvent( ev
) ;
1663 void wxWindow::MacMouseMoved( EventRecord
*ev
, short part
)
1665 WindowPtr frontWindow
;
1670 MacFireMouseEvent( ev
) ;
1675 void wxWindow::MacActivate( EventRecord
*ev
, bool inIsActivating
)
1677 wxActivateEvent
event(wxEVT_ACTIVATE
, inIsActivating
);
1678 event
.m_timeStamp
= ev
->when
;
1679 event
.SetEventObject(this);
1681 GetEventHandler()->ProcessEvent(event
);
1683 UMAHighlightAndActivateWindow( m_macWindowData
->m_macWindow
, inIsActivating
) ;
1686 void wxWindow::MacRedraw( RgnHandle updatergn
, long time
)
1688 // updatergn is always already clipped to our boundaries
1689 WindowRef window
= GetMacRootWindow() ;
1690 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1692 wxMacDrawingHelper
focus( this ) ; // was client
1695 WindowRef window
= GetMacRootWindow() ;
1696 bool eraseBackground
= false ;
1697 if ( m_macWindowData
)
1698 eraseBackground
= true ;
1699 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
1701 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
1703 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1705 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1706 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1707 // either a non gray background color or a non control window
1710 wxWindow
* parent
= GetParent() ;
1713 if ( parent
->GetMacRootWindow() != window
)
1715 // we are in a different window on the mac system
1720 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
1722 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1724 // if we have any other colours in the hierarchy
1725 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
1728 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1729 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
1732 GetRegionBounds( updatergn
, &box
) ;
1733 UMAApplyThemeBackground(kThemeBackgroundTabPane
, &box
, kThemeStateActive
,8,true);
1742 parent
= parent
->GetParent() ;
1746 // if there is nothing special -> use default
1747 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
1752 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
1754 if ( GetParent() && m_backgroundColour
!= GetParent()->GetBackgroundColour() )
1755 eraseBackground
= true ;
1756 SetClip( updatergn
) ;
1757 if ( eraseBackground
)
1759 EraseRgn( updatergn
) ;
1763 m_macUpdateRgn
= updatergn
;
1765 RgnHandle newupdate
= NewRgn() ;
1766 wxSize point
= GetClientSize() ;
1767 wxPoint origin
= GetClientAreaOrigin() ;
1769 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1770 SectRgn( newupdate
, m_macUpdateRgn
, newupdate
) ;
1771 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1772 m_updateRegion
= newupdate
;
1773 DisposeRgn( newupdate
) ;
1778 event
.m_timeStamp
= time
;
1779 event
.SetEventObject(this);
1780 GetEventHandler()->ProcessEvent(event
);
1784 RgnHandle childupdate
= NewRgn() ;
1786 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1788 wxWindow
*child
= (wxWindow
*)node
->Data();
1789 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1790 SectRgn( childupdate
, m_macUpdateRgn
, childupdate
) ;
1791 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1792 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1794 // because dialogs may also be children
1795 child
->MacRedraw( childupdate
, time
) ;
1798 DisposeRgn( childupdate
) ;
1799 // eventually a draw grow box here
1802 void wxWindow::MacUpdateImmediately()
1804 WindowRef window
= GetMacRootWindow() ;
1807 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1809 AGAPortHelper
help( GetWindowPort(window
) ) ;
1811 AGAPortHelper
help( (window
) ) ;
1813 SetOrigin( 0 , 0 ) ;
1814 BeginUpdate( window
) ;
1817 RgnHandle region
= NewRgn();
1821 GetPortVisibleRegion( GetWindowPort( window
), region
);
1823 // if windowshade gives incompatibility , take the follwing out
1824 if ( !EmptyRgn( region
) )
1826 win
->MacRedraw( region
, wxTheApp
->sm_lastMessageTime
) ;
1828 DisposeRgn( region
);
1831 EndUpdate( window
) ;
1835 void wxWindow::MacUpdate( EventRecord
*ev
)
1837 WindowRef window
= (WindowRef
) ev
->message
;
1838 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1840 AGAPortHelper
help( GetWindowPort(window
) ) ;
1842 AGAPortHelper
help( (window
) ) ;
1844 SetOrigin( 0 , 0 ) ;
1845 BeginUpdate( window
) ;
1848 RgnHandle region
= NewRgn();
1852 GetPortVisibleRegion( GetWindowPort( window
), region
);
1854 // if windowshade gives incompatibility , take the follwing out
1855 if ( !EmptyRgn( region
) )
1857 MacRedraw( region
, ev
->when
) ;
1859 DisposeRgn( region
);
1862 EndUpdate( window
) ;
1865 WindowRef
wxWindow::GetMacRootWindow() const
1867 WindowRef window
= NULL
;
1868 wxWindow
*iter
= (wxWindow
*)this ;
1872 if ( iter
->m_macWindowData
)
1873 return iter
->m_macWindowData
->m_macWindow
;
1875 iter
= iter
->GetParent() ;
1877 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1881 void wxWindow::MacCreateScrollBars( long style
)
1883 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
1885 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1886 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1888 GetClientSize( &width
, &height
) ;
1890 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1891 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1892 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1893 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1895 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
1896 vSize
, wxVERTICAL
);
1898 if ( style
& wxVSCROLL
)
1904 m_vScrollBar
->Show(false) ;
1906 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
1907 hSize
, wxHORIZONTAL
);
1908 if ( style
& wxHSCROLL
)
1913 m_hScrollBar
->Show(false) ;
1916 // because the create does not take into account the client area origin
1917 MacRepositionScrollBars() ; // we might have a real position shift
1920 void wxWindow::MacRepositionScrollBars()
1922 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
1923 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
1925 // get real client area
1927 int width
= m_width
;
1928 int height
= m_height
;
1930 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
1931 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
1933 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1934 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1935 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1936 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1943 MacClientToRootWindow( &x
, &y
) ;
1944 MacClientToRootWindow( &w
, &h
) ;
1946 WindowRef window
= NULL
;
1947 wxWindow
*iter
= (wxWindow
*)this ;
1949 int totW
= 10000 , totH
= 10000;
1952 if ( iter
->m_macWindowData
)
1954 totW
= iter
->m_width
;
1955 totH
= iter
->m_height
;
1959 iter
= iter
->GetParent() ;
1987 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1991 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1995 void wxWindow::MacKeyDown( EventRecord
*ev
)
2001 bool wxWindow::AcceptsFocus() const
2003 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2006 ControlHandle
wxWindow::MacGetContainerForEmbedding()
2008 if ( m_macWindowData
)
2009 return m_macWindowData
->m_macRootControl
;
2011 return GetParent()->MacGetContainerForEmbedding() ;
2014 void wxWindow::MacSuperChangedPosition()
2016 // only window-absolute structures have to be moved i.e. controls
2018 wxNode
*node
= GetChildren().First();
2021 wxWindow
*child
= (wxWindow
*)node
->Data();
2022 child
->MacSuperChangedPosition() ;
2023 node
= node
->Next();
2028 bool wxWindow::MacSetupFocusPort( )
2036 MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
2037 return MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
2040 bool wxWindow::MacSetupFocusClientPort( )
2048 MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
2049 return MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
2052 bool wxWindow::MacSetupDrawingPort( )
2060 MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
2061 return MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
2064 bool wxWindow::MacSetupDrawingClientPort( )
2072 MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
2073 return MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
2077 bool wxWindow::MacSetPortFocusParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
2079 if ( window
== NULL
)
2085 ::GetPort(&currPort
);
2086 port
= UMAGetWindowPort( window
) ;
2087 if (currPort
!= port
)
2090 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2091 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2095 bool wxWindow::MacSetPortDrawingParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
2097 if ( window
== NULL
)
2102 ::GetPort(&currPort
);
2103 port
= UMAGetWindowPort( window
) ;
2104 if (currPort
!= port
)
2106 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2107 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2108 ::ClipRect(&clipRect
);
2111 ::RGBBackColor(& win
->GetBackgroundColour().GetPixel() ) ;
2112 ::RGBForeColor(& win
->GetForegroundColour().GetPixel() ) ;
2113 Pattern whiteColor
;
2115 ::BackPat( GetQDGlobalsWhite( &whiteColor
) ) ;
2116 ::UMASetThemeWindowBackground( win
->m_macWindowData
->m_macWindow
, win
->m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
2120 void wxWindow::MacGetPortParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2122 if ( m_macWindowData
)
2128 clipRect
->right
= m_width
;
2129 clipRect
->bottom
= m_height
;
2130 *window
= m_macWindowData
->m_macWindow
;
2135 wxASSERT( GetParent() != NULL
) ;
2136 GetParent()->MacGetPortParams( localOrigin
, clipRect
, window
, rootwin
) ;
2137 localOrigin
->h
+= m_x
;
2138 localOrigin
->v
+= m_y
;
2139 OffsetRect(clipRect
, -m_x
, -m_y
);
2144 myClip
.right
= m_width
;
2145 myClip
.bottom
= m_height
;
2146 SectRect(clipRect
, &myClip
, clipRect
);
2150 void wxWindow::MacDoGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2152 // int width , height ;
2153 // GetClientSize( &width , &height ) ;
2155 if ( m_macWindowData
)
2161 clipRect
->right
= m_width
;//width;
2162 clipRect
->bottom
= m_height
;// height;
2163 *window
= m_macWindowData
->m_macWindow
;
2168 wxASSERT( GetParent() != NULL
) ;
2170 GetParent()->MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2172 localOrigin
->h
+= m_x
;
2173 localOrigin
->v
+= m_y
;
2174 OffsetRect(clipRect
, -m_x
, -m_y
);
2179 myClip
.right
= m_width
;//width;
2180 myClip
.bottom
= m_height
;// height;
2181 SectRect(clipRect
, &myClip
, clipRect
);
2185 void wxWindow::MacGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2187 MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2189 int width
, height
;
2190 GetClientSize( &width
, &height
) ;
2192 client
= GetClientAreaOrigin( ) ;
2194 localOrigin
->h
+= client
.x
;
2195 localOrigin
->v
+= client
.y
;
2196 OffsetRect(clipRect
, -client
.x
, -client
.y
);
2201 myClip
.right
= width
;
2202 myClip
.bottom
= height
;
2203 SectRect(clipRect
, &myClip
, clipRect
);
2206 long wxWindow::MacGetLeftBorderSize( ) const
2208 if( m_macWindowData
)
2211 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2215 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2219 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2226 long wxWindow::MacGetRightBorderSize( ) const
2228 if( m_macWindowData
)
2231 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2235 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2239 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2246 long wxWindow::MacGetTopBorderSize( ) const
2248 if( m_macWindowData
)
2251 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2255 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2259 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2266 long wxWindow::MacGetBottomBorderSize( ) const
2268 if( m_macWindowData
)
2271 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2275 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2279 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2286 long wxWindow::MacRemoveBordersFromStyle( long style
)
2288 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2292 wxMacDrawingHelper::wxMacDrawingHelper( wxWindow
* theWindow
)
2299 m_currentPort
= NULL
;
2301 GetPort( &m_formerPort
) ;
2304 theWindow
->MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2305 m_currentPort
= UMAGetWindowPort( window
) ;
2306 if ( m_formerPort
!= m_currentPort
)
2307 SetPort( m_currentPort
) ;
2308 GetPenState( &m_savedPenState
) ;
2309 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2314 wxMacDrawingHelper::~wxMacDrawingHelper()
2318 SetPort( m_currentPort
) ;
2319 SetPenState( &m_savedPenState
) ;
2320 SetOrigin( 0 , 0 ) ;
2322 GetPortBounds( m_currentPort
, &portRect
) ;
2323 ClipRect( &portRect
) ;
2324 wxDC::MacInvalidateSetup() ;
2327 if ( m_formerPort
!= m_currentPort
)
2328 SetPort( m_formerPort
) ;
2331 wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindow
* theWindow
)
2338 m_currentPort
= NULL
;
2340 GetPort( &m_formerPort
) ;
2344 theWindow
->MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2345 m_currentPort
= UMAGetWindowPort( window
) ;
2346 if ( m_formerPort
!= m_currentPort
)
2347 SetPort( m_currentPort
) ;
2348 GetPenState( &m_savedPenState
) ;
2349 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2354 wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
2358 SetPort( m_currentPort
) ;
2359 SetPenState( &m_savedPenState
) ;
2360 SetOrigin( 0 , 0 ) ;
2362 GetPortBounds( m_currentPort
, &portRect
) ;
2363 ClipRect( &portRect
) ;
2366 if ( m_formerPort
!= m_currentPort
)
2367 SetPort( m_formerPort
) ;
2370 // Find the wxWindow at the current mouse position, returning the mouse
2372 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
2374 pt
= wxGetMousePosition();
2375 wxWindow
* found
= wxFindWindowAtPoint(pt
);
2379 // Get the current mouse position.
2380 wxPoint
wxGetMousePosition()
2383 wxGetMousePosition(& x
, & y
);
2384 return wxPoint(x
, y
);