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 // TODO remove the line below, just for lookup-up convenience CS
36 #include "wx/window.h"
38 #include "wx/menuitem.h"
45 #define wxWINDOW_HSCROLL 5998
46 #define wxWINDOW_VSCROLL 5997
47 #define MAC_SCROLLBAR_SIZE 16
49 #include <wx/mac/uma.h>
51 #if wxUSE_DRAG_AND_DROP
57 extern wxList wxPendingDelete
;
58 wxWindow
* gFocusWindow
= NULL
;
60 #if !USE_SHARED_LIBRARY
61 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxEvtHandler
)
62 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
63 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground
)
64 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
65 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
66 EVT_IDLE(wxWindow::OnIdle
)
67 // EVT_SCROLL(wxWindow::OnScroll)
74 // ===========================================================================
76 // ===========================================================================
78 // ---------------------------------------------------------------------------
79 // wxWindow utility functions
80 // ---------------------------------------------------------------------------
82 // Find an item given the Macintosh Window Reference
84 wxList
*wxWinMacWindowList
= NULL
;
85 wxWindow
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
87 wxNode
*node
= wxWinMacWindowList
->Find((long)inWindowRef
);
90 return (wxWindow
*)node
->Data();
93 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxWindow
*win
)
95 // adding NULL WindowRef is (first) surely a result of an error and
96 // (secondly) breaks menu command processing
97 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, "attempt to add a NULL WindowRef to window list" );
99 if ( !wxWinMacWindowList
->Find((long)inWindowRef
) )
100 wxWinMacWindowList
->Append((long)inWindowRef
, win
);
103 void wxRemoveMacWindowAssociation(wxWindow
*win
)
105 wxWinMacWindowList
->DeleteObject(win
);
108 // ----------------------------------------------------------------------------
109 // constructors and such
110 // ----------------------------------------------------------------------------
112 void wxWindow::Init()
118 m_doubleClickAllowed
= 0;
119 m_winCaptured
= FALSE
;
121 m_isBeingDeleted
= FALSE
;
124 m_mouseInWindow
= FALSE
;
128 m_backgroundTransparent
= FALSE
;
130 // as all windows are created with WS_VISIBLE style...
133 m_macWindowData
= NULL
;
140 m_hScrollBar
= NULL
;
141 m_vScrollBar
= NULL
;
143 #if wxUSE_DRAG_AND_DROP
144 m_pDropTarget
= NULL
;
149 wxWindow::~wxWindow()
151 m_isBeingDeleted
= TRUE
;
153 if ( s_lastMouseWindow
== this )
155 s_lastMouseWindow
= NULL
;
158 if ( gFocusWindow
== this )
160 gFocusWindow
= NULL
;
164 m_parent
->RemoveChild(this);
168 if ( m_macWindowData
)
170 wxToolTip::NotifyWindowDelete(m_macWindowData
->m_macWindow
) ;
171 UMADisposeWindow( m_macWindowData
->m_macWindow
) ;
172 delete m_macWindowData
;
173 wxRemoveMacWindowAssociation( this ) ;
178 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
182 const wxString
& name
)
184 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindow without parent") );
186 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
189 parent
->AddChild(this);
193 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
194 m_width
= WidthDefault( size
.x
);
195 m_height
= HeightDefault( size
.y
) ;
197 if ( ! IsKindOf( CLASSINFO ( wxControl
) ) )
199 MacCreateScrollBars( style
) ;
205 void wxWindow::SetFocus()
207 if ( AcceptsFocus() )
213 if ( gFocusWindow
->m_caret
)
215 gFocusWindow
->m_caret
->OnKillFocus();
217 #endif // wxUSE_CARET
218 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
219 if ( control
&& control
->GetMacControl() )
221 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlFocusNoPart
) ;
222 control
->MacRedrawControl() ;
224 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
225 event
.SetEventObject(gFocusWindow
);
226 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
228 gFocusWindow
= this ;
234 m_caret
->OnSetFocus();
236 #endif // wxUSE_CARET
237 // panel wants to track the window which was the last to have focus in it
238 wxPanel
*panel
= wxDynamicCast(GetParent(), wxPanel
);
241 panel
->SetLastFocus(this);
243 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
244 if ( control
&& control
->GetMacControl() )
246 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlEditTextPart
) ;
249 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
250 event
.SetEventObject(this);
251 GetEventHandler()->ProcessEvent(event
) ;
256 bool wxWindow::Enable(bool enable
)
258 if ( !wxWindowBase::Enable(enable
) )
261 wxWindowList::Node
*node
= GetChildren().GetFirst();
264 wxWindow
*child
= node
->GetData();
265 child
->Enable(enable
);
267 node
= node
->GetNext();
273 void wxWindow::CaptureMouse()
275 wxTheApp
->s_captureWindow
= this ;
278 void wxWindow::ReleaseMouse()
280 wxTheApp
->s_captureWindow
= NULL
;
283 #if wxUSE_DRAG_AND_DROP
285 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
287 if ( m_pDropTarget
!= 0 ) {
288 delete m_pDropTarget
;
291 m_pDropTarget
= pDropTarget
;
292 if ( m_pDropTarget
!= 0 )
300 // Old style file-manager drag&drop
301 void wxWindow::DragAcceptFiles(bool accept
)
307 void wxWindow::DoGetSize(int *x
, int *y
) const
313 void wxWindow::DoGetPosition(int *x
, int *y
) const
319 wxPoint
pt(GetParent()->GetClientAreaOrigin());
326 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
328 menu
->SetInvokingWindow(this);
330 ClientToScreen( &x
, &y
) ;
332 ::InsertMenu( menu
->GetHMenu() , -1 ) ;
333 long menuResult
= ::PopUpMenuSelect(menu
->GetHMenu() ,y
,x
, 0) ;
334 menu
->MacMenuSelect( this , TickCount() , HiWord(menuResult
) , LoWord(menuResult
) ) ;
335 ::DeleteMenu( menu
->MacGetMenuId() ) ;
336 menu
->SetInvokingWindow(NULL
);
341 void wxWindow::DoScreenToClient(int *x
, int *y
) const
343 WindowRef window
= GetMacRootWindow() ;
351 ::SetPort( UMAGetWindowPort( window
) ) ;
352 ::GlobalToLocal( &localwhere
) ;
358 MacRootWindowToClient( x
, y
) ;
361 void wxWindow::DoClientToScreen(int *x
, int *y
) const
363 WindowRef window
= GetMacRootWindow() ;
365 MacClientToRootWindow( x
, y
) ;
373 ::SetPort( UMAGetWindowPort( window
) ) ;
374 ::SetOrigin( 0 , 0 ) ;
375 ::LocalToGlobal( &localwhere
) ;
381 void wxWindow::MacClientToRootWindow( int *x
, int *y
) const
383 if ( m_macWindowData
)
390 GetParent()->MacClientToRootWindow( x
, y
) ;
394 void wxWindow::MacRootWindowToClient( int *x
, int *y
) const
396 if ( m_macWindowData
)
403 GetParent()->MacRootWindowToClient( x
, y
) ;
407 bool wxWindow::SetCursor(const wxCursor
& cursor
)
409 if ( !wxWindowBase::SetCursor(cursor
) )
415 wxASSERT_MSG( m_cursor
.Ok(),
416 wxT("cursor must be valid after call to the base version"));
422 // Change the cursor NOW if we're within the correct window
424 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
426 if ( mouseWin
== this && !wxIsBusy() )
428 cursor
.MacInstall() ;
436 // Get size *available for subwindows* i.e. excluding menu bar etc.
437 void wxWindow::DoGetClientSize(int *x
, int *y
) const
442 *x
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
443 *y
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
445 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
452 MacClientToRootWindow( &x1
, &y1
) ;
453 MacClientToRootWindow( &w
, &h
) ;
455 WindowRef window
= NULL
;
456 wxWindow
*iter
= (wxWindow
*)this ;
458 int totW
= 10000 , totH
= 10000;
461 if ( iter
->m_macWindowData
)
463 totW
= iter
->m_width
;
464 totH
= iter
->m_height
;
468 iter
= iter
->GetParent() ;
471 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
473 (*y
) -= MAC_SCROLLBAR_SIZE
;
479 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
481 (*x
) -= MAC_SCROLLBAR_SIZE
;
491 // ----------------------------------------------------------------------------
493 // ----------------------------------------------------------------------------
497 void wxWindow::DoSetToolTip(wxToolTip
*tooltip
)
499 wxWindowBase::DoSetToolTip(tooltip
);
502 m_tooltip
->SetWindow(this);
505 #endif // wxUSE_TOOLTIPS
507 void wxWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
509 DoSetSize( x
,y
, width
, height
) ;
512 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
517 int former_w
= m_width
;
518 int former_h
= m_height
;
520 int currentX
, currentY
;
521 GetPosition(¤tX
, ¤tY
);
522 int currentW
,currentH
;
523 GetSize(¤tW
, ¤tH
);
525 int actualWidth
= width
;
526 int actualHeight
= height
;
529 if (x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
531 if (y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
534 actualWidth
= currentW
;
536 actualHeight
= currentH
;
538 if ( actualX
== currentX
&& actualY
== currentY
&& actualWidth
== currentW
&& actualHeight
== currentH
)
540 MacRepositionScrollBars() ; // we might have a real position shift
544 AdjustForParentClientOrigin(actualX
, actualY
, sizeFlags
);
547 bool doMove
= false ;
548 bool doResize
= false ;
550 if ( actualX
!= former_x
|| actualY
!= former_y
)
554 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
559 if ( doMove
|| doResize
)
561 if ( m_macWindowData
)
566 // erase former position
567 wxMacDrawingHelper
focus( this ) ;
570 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
571 ClipRect( &clientrect
) ;
572 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
577 m_width
= actualWidth
;
578 m_height
= actualHeight
;
579 if ( m_macWindowData
)
582 ::MoveWindow(m_macWindowData
->m_macWindow
, m_x
, m_y
, false); // don't make frontmost
585 ::SizeWindow(m_macWindowData
->m_macWindow
, m_width
, m_height
, true);
587 // the OS takes care of invalidating and erasing
589 if ( IsKindOf( CLASSINFO( wxFrame
) ) )
591 wxFrame
* frame
= (wxFrame
*) this ;
592 frame
->PositionStatusBar();
593 frame
->PositionToolBar();
598 // erase new position
601 wxMacDrawingHelper
focus( this ) ;
604 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
605 ClipRect( &clientrect
) ;
606 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
611 wxWindow::MacSuperChangedPosition() ; // like this only children will be notified
613 MacRepositionScrollBars() ;
616 wxMoveEvent
event(wxPoint(m_x
, m_y
), m_windowId
);
617 event
.SetEventObject(this);
618 GetEventHandler()->ProcessEvent(event
) ;
622 MacRepositionScrollBars() ;
623 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
624 event
.SetEventObject(this);
625 GetEventHandler()->ProcessEvent(event
);
629 // For implementation purposes - sometimes decorations make the client area
632 wxPoint
wxWindow::GetClientAreaOrigin() const
634 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
637 // Makes an adjustment to the window position (for example, a frame that has
638 // a toolbar that it manages itself).
639 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
641 if( !m_macWindowData
)
643 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
645 wxPoint
pt(GetParent()->GetClientAreaOrigin());
646 x
+= pt
.x
; y
+= pt
.y
;
651 void wxWindow::SetTitle(const wxString
& title
)
657 if( wxApp::s_macDefaultEncodingIsPC
)
658 label
= wxMacMakeMacStringFromPC( title
) ;
662 if ( m_macWindowData
)
663 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
666 wxString
wxWindow::GetTitle() const
671 bool wxWindow::Show(bool show
)
673 if ( !wxWindowBase::Show(show
) )
676 if ( m_macWindowData
)
680 UMAShowWindow( m_macWindowData
->m_macWindow
) ;
681 UMASelectWindow( m_macWindowData
->m_macWindow
) ;
682 // no need to generate events here, they will get them triggered by macos
683 // actually they should be , but apparently they are not
684 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
685 event
.SetEventObject(this);
686 GetEventHandler()->ProcessEvent(event
);
690 UMAHideWindow( m_macWindowData
->m_macWindow
) ;
693 MacSuperShown( show
) ;
696 MacUpdateImmediately() ;
701 void wxWindow::MacSuperShown( bool show
)
703 wxNode
*node
= GetChildren().First();
706 wxWindow
*child
= (wxWindow
*)node
->Data();
707 if ( child
->m_isShown
)
708 child
->MacSuperShown( show
) ;
713 int wxWindow::GetCharHeight() const
715 wxClientDC
dc ( (wxWindow
*)this ) ;
716 return dc
.GetCharHeight() ;
719 int wxWindow::GetCharWidth() const
721 wxClientDC
dc ( (wxWindow
*)this ) ;
722 return dc
.GetCharWidth() ;
725 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
726 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
728 const wxFont
*fontToUse
= theFont
;
732 wxClientDC
dc( (wxWindow
*) this ) ;
734 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, fontToUse
) ;
735 if ( externalLeading
)
736 *externalLeading
= le
;
745 void wxWindow::MacEraseBackground( Rect
*rect
)
747 WindowRef window
= GetMacRootWindow() ;
748 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
750 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
752 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
754 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
755 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
756 // either a non gray background color or a non control window
758 wxWindow
* parent
= GetParent() ;
761 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
763 // if we have any other colours in the hierarchy
764 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
767 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
769 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
770 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
772 UMAApplyThemeBackground(kThemeBackgroundTabPane
, rect
, kThemeStateActive
,8,true);
778 // we have arrived at a non control item
782 parent
= parent
->GetParent() ;
786 // if there is nothing special -> use default
787 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
792 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
797 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
799 wxWindow
*child
= (wxWindow
*)node
->Data();
801 Rect clientrect
= { child
->m_x
, child
->m_y
, child
->m_x
+child
->m_width
, child
->m_y
+ child
->m_height
} ;
802 SectRect( &clientrect
, rect
, &clientrect
) ;
804 OffsetRect( &clientrect
, -child
->m_x
, -child
->m_y
) ;
805 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() )
807 wxMacDrawingClientHelper
focus( this ) ;
810 child
->MacEraseBackground( &clientrect
) ;
816 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
818 wxMacDrawingHelper
focus( this ) ;
821 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
822 ClipRect( &clientrect
) ;
826 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
827 SectRect( &clientrect
, &r
, &clientrect
) ;
829 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
833 // Responds to colour changes: passes event on to children.
834 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
836 wxNode
*node
= GetChildren().First();
839 // Only propagate to non-top-level windows
840 wxWindow
*win
= (wxWindow
*)node
->Data();
841 if ( win
->GetParent() )
843 wxSysColourChangedEvent event2
;
844 event
.m_eventObject
= win
;
845 win
->GetEventHandler()->ProcessEvent(event2
);
852 #if wxUSE_CARET && WXWIN_COMPATIBILITY
853 // ---------------------------------------------------------------------------
854 // Caret manipulation
855 // ---------------------------------------------------------------------------
857 void wxWindow::CreateCaret(int w
, int h
)
859 SetCaret(new wxCaret(this, w
, h
));
862 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
864 wxFAIL_MSG("not implemented");
867 void wxWindow::ShowCaret(bool show
)
869 wxCHECK_RET( m_caret
, "no caret to show" );
874 void wxWindow::DestroyCaret()
879 void wxWindow::SetCaretPos(int x
, int y
)
881 wxCHECK_RET( m_caret
, "no caret to move" );
886 void wxWindow::GetCaretPos(int *x
, int *y
) const
888 wxCHECK_RET( m_caret
, "no caret to get position of" );
890 m_caret
->GetPosition(x
, y
);
892 #endif // wxUSE_CARET
894 wxWindow
*wxGetActiveWindow()
896 // actually this is a windows-only concept
900 // Coordinates relative to the window
901 void wxWindow::WarpPointer (int x_pos
, int y_pos
)
903 // We really dont move the mouse programmatically under mac
906 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
908 // TODO : probably we would adopt the EraseEvent structure
911 int wxWindow::GetScrollPos(int orient
) const
913 if ( orient
== wxHORIZONTAL
)
916 return m_hScrollBar
->GetThumbPosition() ;
921 return m_vScrollBar
->GetThumbPosition() ;
926 // This now returns the whole range, not just the number
927 // of positions that we can scroll.
928 int wxWindow::GetScrollRange(int orient
) const
930 if ( orient
== wxHORIZONTAL
)
933 return m_hScrollBar
->GetRange() ;
938 return m_vScrollBar
->GetRange() ;
943 int wxWindow::GetScrollThumb(int orient
) const
945 if ( orient
== wxHORIZONTAL
)
948 return m_hScrollBar
->GetThumbSize() ;
953 return m_vScrollBar
->GetThumbSize() ;
958 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
960 if ( orient
== wxHORIZONTAL
)
963 m_hScrollBar
->SetThumbPosition( pos
) ;
968 m_vScrollBar
->SetThumbPosition( pos
) ;
972 void wxWindow::MacCreateRealWindow( const wxString
& title
,
976 const wxString
& name
)
979 m_windowStyle
= style
;
1000 m_macWindowData
= new MacWindowData() ;
1002 ::SetRect(&theBoundsRect
, m_x
, m_y
, m_x
+ m_width
, m_y
+ m_height
);
1004 // translate the window attributes in the appropriate window class and attributes
1006 WindowClass wclass
= 0;
1007 WindowAttributes attr
= kWindowNoAttributes
;
1009 if ( HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
) )
1011 wclass
= kFloatingWindowClass
;
1012 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1014 attr
|= kWindowSideTitlebarAttribute
;
1017 else if ( HasFlag( wxTHICK_FRAME
) )
1019 if ( HasFlag( wxDIALOG_MODAL
) )
1021 wclass
= kMovableModalWindowClass
;
1023 else if ( HasFlag( wxDIALOG_MODELESS
) )
1025 wclass
= kDocumentWindowClass
;
1029 if ( HasFlag( wxCAPTION
) )
1031 wclass
= kDocumentWindowClass
;
1035 wclass
= kModalWindowClass
;
1041 wclass
= kModalWindowClass
;
1044 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) )
1046 attr
|= kWindowFullZoomAttribute
;
1047 attr
|= kWindowCollapseBoxAttribute
;
1049 if ( HasFlag( wxRESIZE_BORDER
) )
1051 attr
|= kWindowResizableAttribute
;
1053 if ( HasFlag( wxSYSTEM_MENU
) )
1055 attr
|= kWindowCloseBoxAttribute
;
1058 UMACreateNewWindow( wclass
, attr
, &theBoundsRect
, &m_macWindowData
->m_macWindow
) ;
1059 wxAssociateWinWithMacWindow( m_macWindowData
->m_macWindow
, this ) ;
1061 if( wxApp::s_macDefaultEncodingIsPC
)
1062 label
= wxMacMakeMacStringFromPC( title
) ;
1065 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
1066 UMACreateRootControl( m_macWindowData
->m_macWindow
, &m_macWindowData
->m_macRootControl
) ;
1068 m_macWindowData
->m_macFocus
= NULL
;
1071 void wxWindow::MacPaint( wxPaintEvent
&event
)
1075 void wxWindow::MacPaintBorders( )
1077 if( m_macWindowData
)
1080 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1081 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1082 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1083 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1086 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1088 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1089 RGBColor pen1
= sunken
? white
: black
;
1090 RGBColor pen2
= sunken
? shadow
: face
;
1091 RGBColor pen3
= sunken
? face
: shadow
;
1092 RGBColor pen4
= sunken
? black
: white
;
1094 RGBForeColor( &pen1
) ;
1096 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1097 FrameRect( &rect
) ;
1099 RGBForeColor( &pen2
) ;
1101 Rect rect
= { 1 , 1 , m_height
-1 , m_width
-1} ;
1102 FrameRect( &rect
) ;
1104 RGBForeColor( &pen3
) ;
1106 Rect rect
= { 0 , 0 , m_height
-2 , m_width
-2} ;
1107 FrameRect( &rect
) ;
1109 RGBForeColor( &pen4
) ;
1112 LineTo( m_width
- 3 , 0 ) ;
1114 LineTo( 0 , m_height
- 3 ) ;
1117 else if (HasFlag(wxSIMPLE_BORDER
))
1119 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1120 RGBForeColor( &black
) ;
1121 FrameRect( &rect
) ;
1124 if ( this->GetParent() )
1126 wxPaintDC dc(GetParent());
1127 GetParent()->PrepareDC(dc);
1129 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) )
1131 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1133 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1134 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1136 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1137 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1138 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1139 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1142 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1145 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1148 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1151 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1152 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1154 else if (HasFlag(wxDOUBLE_BORDER))
1156 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1158 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1159 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1161 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1162 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1163 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1164 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1167 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1170 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1173 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1176 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1177 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1179 else if (HasFlag(wxSIMPLE_BORDER))
1181 dc.SetPen(*wxBLACK_PEN);
1182 dc.DrawRectangle(m_x, m_y, m_width, m_height);
1188 // New function that will replace some of the above.
1189 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1190 int range
, bool refresh
)
1192 if ( orient
== wxHORIZONTAL
)
1196 if ( range
== 0 || thumbVisible
>= range
)
1198 if ( m_hScrollBar
->IsShown() )
1199 m_hScrollBar
->Show(false) ;
1203 if ( !m_hScrollBar
->IsShown() )
1204 m_hScrollBar
->Show(true) ;
1205 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, refresh
) ;
1213 if ( range
== 0 || thumbVisible
>= range
)
1215 if ( m_vScrollBar
->IsShown() )
1216 m_vScrollBar
->Show(false) ;
1220 if ( !m_vScrollBar
->IsShown() )
1221 m_vScrollBar
->Show(true) ;
1222 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, refresh
) ;
1226 MacRepositionScrollBars() ;
1229 // Does a physical scroll
1230 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1232 wxMacDrawingClientHelper
focus( this ) ;
1235 int width
, height
;
1236 GetClientSize( &width
, &height
) ;
1238 Rect scrollrect
= { 0 , 0 , height
, width
} ;
1240 RgnHandle updateRgn
= NewRgn() ;
1241 ClipRect( &scrollrect
) ;
1244 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
1245 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1247 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1248 InvalWindowRgn( GetMacRootWindow() , updateRgn
) ;
1249 DisposeRgn( updateRgn
) ;
1252 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1254 wxWindow
*child
= (wxWindow
*)node
->Data();
1255 if (child
== m_vScrollBar
) continue;
1256 if (child
== m_hScrollBar
) continue;
1257 if (child
->IsTopLevel()) continue;
1259 child
->GetPosition( &x
, &y
);
1261 child
->GetSize( &w
, &h
);
1262 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1267 void wxWindow::MacOnScroll(wxScrollEvent
&event
)
1269 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1271 wxScrollWinEvent wevent
;
1272 wevent
.SetPosition(event
.GetPosition());
1273 wevent
.SetOrientation(event
.GetOrientation());
1274 wevent
.m_eventObject
= this;
1276 if (event
.m_eventType
== wxEVT_SCROLL_TOP
) {
1277 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1279 if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
) {
1280 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1282 if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
) {
1283 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1285 if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
) {
1286 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1288 if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
) {
1289 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1291 if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
) {
1292 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1294 if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
) {
1295 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1298 GetEventHandler()->ProcessEvent(wevent
);
1302 bool wxWindow::SetFont(const wxFont
& font
)
1304 if ( !wxWindowBase::SetFont(font
) )
1313 // Get the window with the focus
1314 wxWindow
*wxWindowBase::FindFocus()
1316 return gFocusWindow
;
1319 #if WXWIN_COMPATIBILITY
1320 // If nothing defined for this, try the parent.
1321 // E.g. we may be a button loaded from a resource, with no callback function
1323 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1325 if ( GetEventHandler()->ProcessEvent(event
) )
1328 m_parent
->GetEventHandler()->OnCommand(win
, event
);
1330 #endif // WXWIN_COMPATIBILITY_2
1332 #if WXWIN_COMPATIBILITY
1333 wxObject
* wxWindow::GetChild(int number
) const
1335 // Return a pointer to the Nth object in the Panel
1336 wxNode
*node
= GetChildren().First();
1339 node
= node
->Next();
1342 wxObject
*obj
= (wxObject
*)node
->Data();
1348 #endif // WXWIN_COMPATIBILITY
1350 void wxWindow::Clear()
1352 if ( m_macWindowData
)
1354 wxMacDrawingClientHelper
helper ( this ) ;
1356 wxPoint origin
= GetClientAreaOrigin() ;
1357 GetClientSize( &w
, &h
) ;
1358 UMASetThemeWindowBackground( m_macWindowData
->m_macWindow
, m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
1359 Rect r
= { origin
.y
, origin
.x
, origin
.y
+h
, origin
.x
+w
} ;
1364 wxClientDC
dc(this);
1365 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1366 dc
.SetBackground(brush
);
1371 // Setup background and foreground colours correctly
1372 void wxWindow::SetupColours()
1375 SetBackgroundColour(GetParent()->GetBackgroundColour());
1378 void wxWindow::OnIdle(wxIdleEvent
& event
)
1381 // Check if we need to send a LEAVE event
1382 if (m_mouseInWindow)
1385 ::GetCursorPos(&pt);
1386 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1388 // Generate a LEAVE event
1389 m_mouseInWindow = FALSE;
1390 MSWOnMouseLeave(pt.x, pt.y, 0);
1395 // This calls the UI-update mechanism (querying windows for
1396 // menu/toolbar/control state information)
1400 // Raise the window to the top of the Z order
1401 void wxWindow::Raise()
1406 // Lower the window to the bottom of the Z order
1407 void wxWindow::Lower()
1412 void wxWindow::DoSetClientSize(int width
, int height
)
1414 if ( width
!= -1 || height
!= -1 )
1417 if ( width
!= -1 && m_vScrollBar
)
1418 width
+= MAC_SCROLLBAR_SIZE
;
1419 if ( height
!= -1 && m_vScrollBar
)
1420 height
+= MAC_SCROLLBAR_SIZE
;
1422 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1423 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1425 DoSetSize( -1 , -1 , width
, height
) ;
1430 wxWindow
* wxWindow::s_lastMouseWindow
= NULL
;
1432 bool wxWindow::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindow
** outWin
)
1434 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1435 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1438 WindowRef window
= GetMacRootWindow() ;
1440 wxPoint
newPoint( point
) ;
1445 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1447 wxWindow
*child
= (wxWindow
*)node
->Data();
1448 // added the m_isShown test --dmazzoni
1449 if ( child
->GetMacRootWindow() == window
&& child
->m_isShown
)
1451 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1460 bool wxWindow::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindow
** outWin
)
1463 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1464 if ( ::FindWindow( pt
, &window
) == 3 )
1466 wxPoint
point( screenpoint
) ;
1467 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1470 win
->ScreenToClient( point
) ;
1471 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1477 extern int wxBusyCursorCount
;
1479 bool wxWindow::MacDispatchMouseEvent(wxMouseEvent
& event
)
1481 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1482 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1486 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) )
1489 WindowRef window
= GetMacRootWindow() ;
1497 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1499 wxWindow
*child
= (wxWindow
*)node
->Data();
1500 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1502 if (child
->MacDispatchMouseEvent(event
))
1510 if ( wxBusyCursorCount
== 0 )
1512 m_cursor
.MacInstall() ;
1516 if ( event
.GetEventType() == wxEVT_MOTION
1517 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1518 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1519 wxToolTip::RelayEvent( this , event
);
1520 #endif // wxUSE_TOOLTIPS
1521 GetEventHandler()->ProcessEvent( event
) ;
1528 wxString
wxWindow::MacGetToolTipString( wxPoint
&pt
)
1532 return m_tooltip
->GetTip() ;
1536 void wxWindow::MacFireMouseEvent( EventRecord
*ev
)
1538 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
1539 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1540 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1542 event
.m_leftDown
= isDown
&& !controlDown
;
1543 event
.m_middleDown
= FALSE
;
1544 event
.m_rightDown
= isDown
&& controlDown
;
1546 if ( ev
->what
== mouseDown
)
1549 event
.SetEventType(wxEVT_RIGHT_DOWN
) ;
1551 event
.SetEventType(wxEVT_LEFT_DOWN
) ;
1553 else if ( ev
->what
== mouseUp
)
1556 event
.SetEventType(wxEVT_RIGHT_UP
) ;
1558 event
.SetEventType(wxEVT_LEFT_UP
) ;
1562 event
.SetEventType(wxEVT_MOTION
) ;
1565 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1566 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1567 event
.m_altDown
= ev
->modifiers
& optionKey
;
1568 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1570 Point localwhere
= ev
->where
;
1573 ::GetPort( &port
) ;
1574 ::SetPort( UMAGetWindowPort( m_macWindowData
->m_macWindow
) ) ;
1575 ::GlobalToLocal( &localwhere
) ;
1578 if ( ev
->what
== mouseDown
)
1580 if ( ev
->when
- lastWhen
<= GetDblTime() )
1582 if ( abs( localwhere
.h
- lastWhere
.h
) < 3 || abs( localwhere
.v
- lastWhere
.v
) < 3 )
1585 event
.SetEventType(wxEVT_RIGHT_DCLICK
) ;
1587 event
.SetEventType(wxEVT_LEFT_DCLICK
) ;
1590 lastWhen
= ev
->when
;
1591 lastWhere
= localwhere
;
1594 event
.m_x
= localwhere
.h
;
1595 event
.m_y
= localwhere
.v
;
1600 wxPoint origin = GetClientAreaOrigin() ;
1602 event.m_x += origin.x ;
1603 event.m_y += origin.y ;
1606 event
.m_timeStamp
= ev
->when
;
1607 event
.SetEventObject(this);
1608 if ( wxTheApp
->s_captureWindow
)
1612 wxTheApp
->s_captureWindow
->ScreenToClient( &x
, &y
) ;
1615 wxTheApp
->s_captureWindow
->GetEventHandler()->ProcessEvent( event
) ;
1616 if ( ev
->what
== mouseUp
)
1618 wxTheApp
->s_captureWindow
= NULL
;
1619 if ( wxBusyCursorCount
== 0 )
1621 m_cursor
.MacInstall() ;
1627 MacDispatchMouseEvent( event
) ;
1631 void wxWindow::MacMouseDown( EventRecord
*ev
, short part
)
1633 MacFireMouseEvent( ev
) ;
1636 void wxWindow::MacMouseUp( EventRecord
*ev
, short part
)
1638 WindowPtr frontWindow
;
1643 MacFireMouseEvent( ev
) ;
1649 void wxWindow::MacMouseMoved( EventRecord
*ev
, short part
)
1651 WindowPtr frontWindow
;
1656 MacFireMouseEvent( ev
) ;
1661 void wxWindow::MacActivate( EventRecord
*ev
, bool inIsActivating
)
1663 wxActivateEvent
event(wxEVT_ACTIVATE
, inIsActivating
);
1664 event
.m_timeStamp
= ev
->when
;
1665 event
.SetEventObject(this);
1667 GetEventHandler()->ProcessEvent(event
);
1669 UMAHighlightAndActivateWindow( m_macWindowData
->m_macWindow
, inIsActivating
) ;
1672 void wxWindow::MacRedraw( RgnHandle updatergn
, long time
)
1674 // updatergn is always already clipped to our boundaries
1675 WindowRef window
= GetMacRootWindow() ;
1676 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1678 wxMacDrawingHelper
focus( this ) ; // was client
1681 WindowRef window
= GetMacRootWindow() ;
1682 bool eraseBackground
= false ;
1683 if ( m_macWindowData
)
1684 eraseBackground
= true ;
1685 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
1687 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
1689 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1691 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1692 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1693 // either a non gray background color or a non control window
1696 wxWindow
* parent
= GetParent() ;
1699 if ( parent
->GetMacRootWindow() != window
)
1701 // we are in a different window on the mac system
1706 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
1708 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1710 // if we have any other colours in the hierarchy
1711 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
1714 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1715 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
1718 GetRegionBounds( updatergn
, &box
) ;
1719 UMAApplyThemeBackground(kThemeBackgroundTabPane
, &box
, kThemeStateActive
,8,true);
1728 parent
= parent
->GetParent() ;
1732 // if there is nothing special -> use default
1733 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
1738 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
1740 if ( GetParent() && m_backgroundColour
!= GetParent()->GetBackgroundColour() )
1741 eraseBackground
= true ;
1742 SetClip( updatergn
) ;
1743 if ( eraseBackground
)
1745 EraseRgn( updatergn
) ;
1749 m_macUpdateRgn
= updatergn
;
1751 RgnHandle newupdate
= NewRgn() ;
1752 wxSize point
= GetClientSize() ;
1753 wxPoint origin
= GetClientAreaOrigin() ;
1755 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1756 SectRgn( newupdate
, m_macUpdateRgn
, newupdate
) ;
1757 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1758 m_updateRegion
= newupdate
;
1759 DisposeRgn( newupdate
) ;
1764 event
.m_timeStamp
= time
;
1765 event
.SetEventObject(this);
1766 GetEventHandler()->ProcessEvent(event
);
1770 RgnHandle childupdate
= NewRgn() ;
1772 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1774 wxWindow
*child
= (wxWindow
*)node
->Data();
1775 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1776 SectRgn( childupdate
, m_macUpdateRgn
, childupdate
) ;
1777 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1778 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1780 // because dialogs may also be children
1781 child
->MacRedraw( childupdate
, time
) ;
1784 DisposeRgn( childupdate
) ;
1785 // eventually a draw grow box here
1788 void wxWindow::MacUpdateImmediately()
1790 WindowRef window
= GetMacRootWindow() ;
1793 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1795 AGAPortHelper
help( GetWindowPort(window
) ) ;
1797 AGAPortHelper
help( (window
) ) ;
1799 SetOrigin( 0 , 0 ) ;
1800 BeginUpdate( window
) ;
1803 RgnHandle region
= NewRgn();
1807 GetPortVisibleRegion( GetWindowPort( window
), region
);
1809 // if windowshade gives incompatibility , take the follwing out
1810 if ( !EmptyRgn( region
) )
1812 win
->MacRedraw( region
, wxTheApp
->sm_lastMessageTime
) ;
1814 DisposeRgn( region
);
1817 EndUpdate( window
) ;
1821 void wxWindow::MacUpdate( EventRecord
*ev
)
1823 WindowRef window
= (WindowRef
) ev
->message
;
1824 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1826 AGAPortHelper
help( GetWindowPort(window
) ) ;
1828 AGAPortHelper
help( (window
) ) ;
1830 SetOrigin( 0 , 0 ) ;
1831 BeginUpdate( window
) ;
1834 RgnHandle region
= NewRgn();
1838 GetPortVisibleRegion( GetWindowPort( window
), region
);
1840 // if windowshade gives incompatibility , take the follwing out
1841 if ( !EmptyRgn( region
) )
1843 MacRedraw( region
, ev
->when
) ;
1845 DisposeRgn( region
);
1848 EndUpdate( window
) ;
1851 WindowRef
wxWindow::GetMacRootWindow() const
1853 WindowRef window
= NULL
;
1854 wxWindow
*iter
= (wxWindow
*)this ;
1858 if ( iter
->m_macWindowData
)
1859 return iter
->m_macWindowData
->m_macWindow
;
1861 iter
= iter
->GetParent() ;
1863 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1867 void wxWindow::MacCreateScrollBars( long style
)
1869 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
1871 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1872 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1874 GetClientSize( &width
, &height
) ;
1876 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1877 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1878 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1879 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1881 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
1882 vSize
, wxVERTICAL
);
1884 if ( style
& wxVSCROLL
)
1890 m_vScrollBar
->Show(false) ;
1892 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
1893 hSize
, wxHORIZONTAL
);
1894 if ( style
& wxHSCROLL
)
1899 m_hScrollBar
->Show(false) ;
1902 // because the create does not take into account the client area origin
1903 MacRepositionScrollBars() ; // we might have a real position shift
1906 void wxWindow::MacRepositionScrollBars()
1908 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
1909 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
1911 // get real client area
1913 int width
= m_width
;
1914 int height
= m_height
;
1916 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
1917 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
1919 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1920 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1921 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1922 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1929 MacClientToRootWindow( &x
, &y
) ;
1930 MacClientToRootWindow( &w
, &h
) ;
1932 WindowRef window
= NULL
;
1933 wxWindow
*iter
= (wxWindow
*)this ;
1935 int totW
= 10000 , totH
= 10000;
1938 if ( iter
->m_macWindowData
)
1940 totW
= iter
->m_width
;
1941 totH
= iter
->m_height
;
1945 iter
= iter
->GetParent() ;
1973 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1977 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1981 void wxWindow::MacKeyDown( EventRecord
*ev
)
1987 bool wxWindow::AcceptsFocus() const
1989 return MacCanFocus() && wxWindowBase::AcceptsFocus();
1992 ControlHandle
wxWindow::MacGetContainerForEmbedding()
1994 if ( m_macWindowData
)
1995 return m_macWindowData
->m_macRootControl
;
1997 return GetParent()->MacGetContainerForEmbedding() ;
2000 void wxWindow::MacSuperChangedPosition()
2002 // only window-absolute structures have to be moved i.e. controls
2004 wxNode
*node
= GetChildren().First();
2007 wxWindow
*child
= (wxWindow
*)node
->Data();
2008 child
->MacSuperChangedPosition() ;
2009 node
= node
->Next();
2014 bool wxWindow::MacSetupFocusPort( )
2022 MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
2023 return MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
2026 bool wxWindow::MacSetupFocusClientPort( )
2034 MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
2035 return MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
2038 bool wxWindow::MacSetupDrawingPort( )
2046 MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
2047 return MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
2050 bool wxWindow::MacSetupDrawingClientPort( )
2058 MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
2059 return MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
2063 bool wxWindow::MacSetPortFocusParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
2065 if ( window
== NULL
)
2071 ::GetPort(&currPort
);
2072 port
= UMAGetWindowPort( window
) ;
2073 if (currPort
!= port
)
2076 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2077 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2081 bool wxWindow::MacSetPortDrawingParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
2083 if ( window
== NULL
)
2088 ::GetPort(&currPort
);
2089 port
= UMAGetWindowPort( window
) ;
2090 if (currPort
!= port
)
2092 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2093 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2094 ::ClipRect(&clipRect
);
2097 ::RGBBackColor(& win
->GetBackgroundColour().GetPixel() ) ;
2098 ::RGBForeColor(& win
->GetForegroundColour().GetPixel() ) ;
2099 Pattern whiteColor
;
2101 ::BackPat( GetQDGlobalsWhite( &whiteColor
) ) ;
2102 ::UMASetThemeWindowBackground( win
->m_macWindowData
->m_macWindow
, win
->m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
2106 void wxWindow::MacGetPortParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2108 if ( m_macWindowData
)
2114 clipRect
->right
= m_width
;
2115 clipRect
->bottom
= m_height
;
2116 *window
= m_macWindowData
->m_macWindow
;
2121 wxASSERT( GetParent() != NULL
) ;
2122 GetParent()->MacGetPortParams( localOrigin
, clipRect
, window
, rootwin
) ;
2123 localOrigin
->h
+= m_x
;
2124 localOrigin
->v
+= m_y
;
2125 OffsetRect(clipRect
, -m_x
, -m_y
);
2130 myClip
.right
= m_width
;
2131 myClip
.bottom
= m_height
;
2132 SectRect(clipRect
, &myClip
, clipRect
);
2136 void wxWindow::MacDoGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2138 // int width , height ;
2139 // GetClientSize( &width , &height ) ;
2141 if ( m_macWindowData
)
2147 clipRect
->right
= m_width
;//width;
2148 clipRect
->bottom
= m_height
;// height;
2149 *window
= m_macWindowData
->m_macWindow
;
2154 wxASSERT( GetParent() != NULL
) ;
2156 GetParent()->MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2158 localOrigin
->h
+= m_x
;
2159 localOrigin
->v
+= m_y
;
2160 OffsetRect(clipRect
, -m_x
, -m_y
);
2165 myClip
.right
= m_width
;//width;
2166 myClip
.bottom
= m_height
;// height;
2167 SectRect(clipRect
, &myClip
, clipRect
);
2171 void wxWindow::MacGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2173 MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2175 int width
, height
;
2176 GetClientSize( &width
, &height
) ;
2178 client
= GetClientAreaOrigin( ) ;
2180 localOrigin
->h
+= client
.x
;
2181 localOrigin
->v
+= client
.y
;
2182 OffsetRect(clipRect
, -client
.x
, -client
.y
);
2187 myClip
.right
= width
;
2188 myClip
.bottom
= height
;
2189 SectRect(clipRect
, &myClip
, clipRect
);
2192 long wxWindow::MacGetLeftBorderSize( ) const
2194 if( m_macWindowData
)
2197 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2201 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2205 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2212 long wxWindow::MacGetRightBorderSize( ) const
2214 if( m_macWindowData
)
2217 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2221 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2225 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2232 long wxWindow::MacGetTopBorderSize( ) const
2234 if( m_macWindowData
)
2237 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2241 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2245 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2252 long wxWindow::MacGetBottomBorderSize( ) const
2254 if( m_macWindowData
)
2257 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2261 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2265 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2272 long wxWindow::MacRemoveBordersFromStyle( long style
)
2274 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2278 wxMacDrawingHelper::wxMacDrawingHelper( wxWindow
* theWindow
)
2285 m_currentPort
= NULL
;
2287 GetPort( &m_formerPort
) ;
2290 theWindow
->MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2291 m_currentPort
= UMAGetWindowPort( window
) ;
2292 if ( m_formerPort
!= m_currentPort
)
2293 SetPort( m_currentPort
) ;
2294 GetPenState( &m_savedPenState
) ;
2295 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2300 wxMacDrawingHelper::~wxMacDrawingHelper()
2304 SetPort( m_currentPort
) ;
2305 SetPenState( &m_savedPenState
) ;
2306 SetOrigin( 0 , 0 ) ;
2308 GetPortBounds( m_currentPort
, &portRect
) ;
2309 ClipRect( &portRect
) ;
2310 wxDC::MacInvalidateSetup() ;
2313 if ( m_formerPort
!= m_currentPort
)
2314 SetPort( m_formerPort
) ;
2317 wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindow
* theWindow
)
2324 m_currentPort
= NULL
;
2326 GetPort( &m_formerPort
) ;
2330 theWindow
->MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2331 m_currentPort
= UMAGetWindowPort( window
) ;
2332 if ( m_formerPort
!= m_currentPort
)
2333 SetPort( m_currentPort
) ;
2334 GetPenState( &m_savedPenState
) ;
2335 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2340 wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
2344 SetPort( m_currentPort
) ;
2345 SetPenState( &m_savedPenState
) ;
2346 SetOrigin( 0 , 0 ) ;
2348 GetPortBounds( m_currentPort
, &portRect
) ;
2349 ClipRect( &portRect
) ;
2352 if ( m_formerPort
!= m_currentPort
)
2353 SetPort( m_formerPort
) ;
2356 // Find the wxWindow at the current mouse position, returning the mouse
2358 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
2360 pt
= wxGetMousePosition();
2361 wxWindow
* found
= wxFindWindowAtPoint(pt
);
2365 // Get the current mouse position.
2366 wxPoint
wxGetMousePosition()
2369 wxGetMousePosition(& x
, & y
);
2370 return wxPoint(x
, y
);