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
568 wxMacDrawingClientHelper
focus( this ) ;
571 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
572 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
590 if ( IsKindOf( CLASSINFO( wxFrame
) ) )
592 wxFrame
* frame
= (wxFrame
*) this ;
593 frame
->PositionStatusBar();
594 frame
->PositionToolBar();
599 // erase new position
601 wxMacDrawingClientHelper
focus( this ) ;
604 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
605 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
609 wxWindow::MacSuperChangedPosition() ; // like this only children will be notified
611 MacRepositionScrollBars() ;
614 wxMoveEvent
event(wxPoint(m_x
, m_y
), m_windowId
);
615 event
.SetEventObject(this);
616 GetEventHandler()->ProcessEvent(event
) ;
620 MacRepositionScrollBars() ;
621 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
622 event
.SetEventObject(this);
623 GetEventHandler()->ProcessEvent(event
);
627 // For implementation purposes - sometimes decorations make the client area
630 wxPoint
wxWindow::GetClientAreaOrigin() const
632 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
635 // Makes an adjustment to the window position (for example, a frame that has
636 // a toolbar that it manages itself).
637 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
639 if( !m_macWindowData
)
641 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
643 wxPoint
pt(GetParent()->GetClientAreaOrigin());
644 x
+= pt
.x
; y
+= pt
.y
;
649 void wxWindow::SetTitle(const wxString
& title
)
655 if( wxApp::s_macDefaultEncodingIsPC
)
656 label
= wxMacMakeMacStringFromPC( title
) ;
660 if ( m_macWindowData
)
661 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
664 wxString
wxWindow::GetTitle() const
669 bool wxWindow::Show(bool show
)
671 if ( !wxWindowBase::Show(show
) )
674 if ( m_macWindowData
)
678 UMAShowWindow( m_macWindowData
->m_macWindow
) ;
679 UMASelectWindow( m_macWindowData
->m_macWindow
) ;
680 // no need to generate events here, they will get them triggered by macos
681 // actually they should be , but apparently they are not
682 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
683 event
.SetEventObject(this);
684 GetEventHandler()->ProcessEvent(event
);
688 UMAHideWindow( m_macWindowData
->m_macWindow
) ;
691 MacSuperShown( show
) ;
694 MacUpdateImmediately() ;
699 void wxWindow::MacSuperShown( bool show
)
701 wxNode
*node
= GetChildren().First();
704 wxWindow
*child
= (wxWindow
*)node
->Data();
705 if ( child
->m_isShown
)
706 child
->MacSuperShown( show
) ;
711 int wxWindow::GetCharHeight() const
713 wxClientDC
dc ( (wxWindow
*)this ) ;
714 return dc
.GetCharHeight() ;
717 int wxWindow::GetCharWidth() const
719 wxClientDC
dc ( (wxWindow
*)this ) ;
720 return dc
.GetCharWidth() ;
723 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
724 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
726 const wxFont
*fontToUse
= theFont
;
730 wxClientDC
dc( (wxWindow
*) this ) ;
732 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, fontToUse
) ;
733 if ( externalLeading
)
734 *externalLeading
= le
;
743 void wxWindow::MacEraseBackground( Rect
*rect
)
745 WindowRef window
= GetMacRootWindow() ;
746 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
748 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
750 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
752 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
753 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
754 // either a non gray background color or a non control window
756 wxWindow
* parent
= GetParent() ;
759 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
761 // if we have any other colours in the hierarchy
762 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
765 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
767 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
768 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
770 UMAApplyThemeBackground(kThemeBackgroundTabPane
, rect
, kThemeStateActive
,8,true);
776 // we have arrived at a non control item
780 parent
= parent
->GetParent() ;
784 // if there is nothing special -> use default
785 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
790 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
795 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
797 wxWindow
*child
= (wxWindow
*)node
->Data();
799 Rect clientrect
= { child
->m_x
, child
->m_y
, child
->m_x
+child
->m_width
, child
->m_y
+ child
->m_height
} ;
800 SectRect( &clientrect
, rect
, &clientrect
) ;
802 OffsetRect( &clientrect
, -child
->m_x
, -child
->m_y
) ;
803 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() )
805 wxMacDrawingClientHelper
focus( this ) ;
808 child
->MacEraseBackground( &clientrect
) ;
814 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
816 wxMacDrawingHelper
focus( this ) ;
819 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
820 ClipRect( &clientrect
) ;
824 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
825 SectRect( &clientrect
, &r
, &clientrect
) ;
827 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
831 // Responds to colour changes: passes event on to children.
832 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
834 wxNode
*node
= GetChildren().First();
837 // Only propagate to non-top-level windows
838 wxWindow
*win
= (wxWindow
*)node
->Data();
839 if ( win
->GetParent() )
841 wxSysColourChangedEvent event2
;
842 event
.m_eventObject
= win
;
843 win
->GetEventHandler()->ProcessEvent(event2
);
850 #if wxUSE_CARET && WXWIN_COMPATIBILITY
851 // ---------------------------------------------------------------------------
852 // Caret manipulation
853 // ---------------------------------------------------------------------------
855 void wxWindow::CreateCaret(int w
, int h
)
857 SetCaret(new wxCaret(this, w
, h
));
860 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
862 wxFAIL_MSG("not implemented");
865 void wxWindow::ShowCaret(bool show
)
867 wxCHECK_RET( m_caret
, "no caret to show" );
872 void wxWindow::DestroyCaret()
877 void wxWindow::SetCaretPos(int x
, int y
)
879 wxCHECK_RET( m_caret
, "no caret to move" );
884 void wxWindow::GetCaretPos(int *x
, int *y
) const
886 wxCHECK_RET( m_caret
, "no caret to get position of" );
888 m_caret
->GetPosition(x
, y
);
890 #endif // wxUSE_CARET
892 wxWindow
*wxGetActiveWindow()
894 // actually this is a windows-only concept
898 // Coordinates relative to the window
899 void wxWindow::WarpPointer (int x_pos
, int y_pos
)
901 // We really dont move the mouse programmatically under mac
904 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
906 // TODO : probably we would adopt the EraseEvent structure
909 int wxWindow::GetScrollPos(int orient
) const
911 if ( orient
== wxHORIZONTAL
)
914 return m_hScrollBar
->GetThumbPosition() ;
919 return m_vScrollBar
->GetThumbPosition() ;
924 // This now returns the whole range, not just the number
925 // of positions that we can scroll.
926 int wxWindow::GetScrollRange(int orient
) const
928 if ( orient
== wxHORIZONTAL
)
931 return m_hScrollBar
->GetRange() ;
936 return m_vScrollBar
->GetRange() ;
941 int wxWindow::GetScrollThumb(int orient
) const
943 if ( orient
== wxHORIZONTAL
)
946 return m_hScrollBar
->GetThumbSize() ;
951 return m_vScrollBar
->GetThumbSize() ;
956 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
958 if ( orient
== wxHORIZONTAL
)
961 m_hScrollBar
->SetThumbPosition( pos
) ;
966 m_vScrollBar
->SetThumbPosition( pos
) ;
970 void wxWindow::MacCreateRealWindow( const wxString
& title
,
974 const wxString
& name
)
977 m_windowStyle
= style
;
998 m_macWindowData
= new MacWindowData() ;
1000 ::SetRect(&theBoundsRect
, m_x
, m_y
, m_x
+ m_width
, m_y
+ m_height
);
1002 // translate the window attributes in the appropriate window class and attributes
1004 WindowClass wclass
= 0;
1005 WindowAttributes attr
= kWindowNoAttributes
;
1007 if ( HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
) )
1009 wclass
= kFloatingWindowClass
;
1010 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1012 attr
|= kWindowSideTitlebarAttribute
;
1015 else if ( HasFlag( wxTHICK_FRAME
) )
1017 if ( HasFlag( wxDIALOG_MODAL
) )
1019 wclass
= kMovableModalWindowClass
;
1021 else if ( HasFlag( wxDIALOG_MODELESS
) )
1023 wclass
= kDocumentWindowClass
;
1027 if ( HasFlag( wxCAPTION
) )
1029 wclass
= kDocumentWindowClass
;
1033 wclass
= kModalWindowClass
;
1039 wclass
= kModalWindowClass
;
1042 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) )
1044 attr
|= kWindowFullZoomAttribute
;
1045 attr
|= kWindowCollapseBoxAttribute
;
1047 if ( HasFlag( wxRESIZE_BORDER
) )
1049 attr
|= kWindowResizableAttribute
;
1051 if ( HasFlag( wxSYSTEM_MENU
) )
1053 attr
|= kWindowCloseBoxAttribute
;
1056 UMACreateNewWindow( wclass
, attr
, &theBoundsRect
, &m_macWindowData
->m_macWindow
) ;
1057 wxAssociateWinWithMacWindow( m_macWindowData
->m_macWindow
, this ) ;
1059 if( wxApp::s_macDefaultEncodingIsPC
)
1060 label
= wxMacMakeMacStringFromPC( title
) ;
1063 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
1064 UMACreateRootControl( m_macWindowData
->m_macWindow
, &m_macWindowData
->m_macRootControl
) ;
1066 m_macWindowData
->m_macFocus
= NULL
;
1069 void wxWindow::MacPaint( wxPaintEvent
&event
)
1073 void wxWindow::MacPaintBorders( )
1075 if( m_macWindowData
)
1078 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1079 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1080 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1081 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1084 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1086 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1087 RGBColor pen1
= sunken
? white
: black
;
1088 RGBColor pen2
= sunken
? shadow
: face
;
1089 RGBColor pen3
= sunken
? face
: shadow
;
1090 RGBColor pen4
= sunken
? black
: white
;
1092 RGBForeColor( &pen1
) ;
1094 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1095 FrameRect( &rect
) ;
1097 RGBForeColor( &pen2
) ;
1099 Rect rect
= { 1 , 1 , m_height
-1 , m_width
-1} ;
1100 FrameRect( &rect
) ;
1102 RGBForeColor( &pen3
) ;
1104 Rect rect
= { 0 , 0 , m_height
-2 , m_width
-2} ;
1105 FrameRect( &rect
) ;
1107 RGBForeColor( &pen4
) ;
1110 LineTo( m_width
- 3 , 0 ) ;
1112 LineTo( 0 , m_height
- 3 ) ;
1115 else if (HasFlag(wxSIMPLE_BORDER
))
1117 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1118 RGBForeColor( &black
) ;
1119 FrameRect( &rect
) ;
1122 if ( this->GetParent() )
1124 wxPaintDC dc(GetParent());
1125 GetParent()->PrepareDC(dc);
1127 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) )
1129 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1131 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1132 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1134 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1135 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1136 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1137 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1140 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1143 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1146 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1149 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1150 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1152 else if (HasFlag(wxDOUBLE_BORDER))
1154 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1156 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1157 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1159 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1160 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1161 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1162 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1165 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1168 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1171 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1174 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1175 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1177 else if (HasFlag(wxSIMPLE_BORDER))
1179 dc.SetPen(*wxBLACK_PEN);
1180 dc.DrawRectangle(m_x, m_y, m_width, m_height);
1186 // New function that will replace some of the above.
1187 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1188 int range
, bool refresh
)
1190 if ( orient
== wxHORIZONTAL
)
1194 if ( range
== 0 || thumbVisible
>= range
)
1196 if ( m_hScrollBar
->IsShown() )
1197 m_hScrollBar
->Show(false) ;
1201 if ( !m_hScrollBar
->IsShown() )
1202 m_hScrollBar
->Show(true) ;
1203 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, refresh
) ;
1211 if ( range
== 0 || thumbVisible
>= range
)
1213 if ( m_vScrollBar
->IsShown() )
1214 m_vScrollBar
->Show(false) ;
1218 if ( !m_vScrollBar
->IsShown() )
1219 m_vScrollBar
->Show(true) ;
1220 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, refresh
) ;
1224 MacRepositionScrollBars() ;
1227 // Does a physical scroll
1228 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1230 wxMacDrawingClientHelper
focus( this ) ;
1233 int width
, height
;
1234 GetClientSize( &width
, &height
) ;
1236 Rect scrollrect
= { 0 , 0 , height
, width
} ;
1238 RgnHandle updateRgn
= NewRgn() ;
1239 ClipRect( &scrollrect
) ;
1242 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
1243 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1245 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1246 InvalWindowRgn( GetMacRootWindow() , updateRgn
) ;
1247 DisposeRgn( updateRgn
) ;
1250 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1252 wxWindow
*child
= (wxWindow
*)node
->Data();
1253 if (child
== m_vScrollBar
) continue;
1254 if (child
== m_hScrollBar
) continue;
1255 if (child
->IsTopLevel()) continue;
1257 child
->GetPosition( &x
, &y
);
1259 child
->GetSize( &w
, &h
);
1260 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1265 void wxWindow::MacOnScroll(wxScrollEvent
&event
)
1267 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1269 wxScrollWinEvent wevent
;
1270 wevent
.SetPosition(event
.GetPosition());
1271 wevent
.SetOrientation(event
.GetOrientation());
1272 wevent
.m_eventObject
= this;
1274 if (event
.m_eventType
== wxEVT_SCROLL_TOP
) {
1275 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1277 if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
) {
1278 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1280 if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
) {
1281 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1283 if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
) {
1284 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1286 if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
) {
1287 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1289 if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
) {
1290 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1292 if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
) {
1293 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1296 GetEventHandler()->ProcessEvent(wevent
);
1300 bool wxWindow::SetFont(const wxFont
& font
)
1302 if ( !wxWindowBase::SetFont(font
) )
1311 // Get the window with the focus
1312 wxWindow
*wxWindowBase::FindFocus()
1314 return gFocusWindow
;
1317 #if WXWIN_COMPATIBILITY
1318 // If nothing defined for this, try the parent.
1319 // E.g. we may be a button loaded from a resource, with no callback function
1321 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1323 if ( GetEventHandler()->ProcessEvent(event
) )
1326 m_parent
->GetEventHandler()->OnCommand(win
, event
);
1328 #endif // WXWIN_COMPATIBILITY_2
1330 #if WXWIN_COMPATIBILITY
1331 wxObject
* wxWindow::GetChild(int number
) const
1333 // Return a pointer to the Nth object in the Panel
1334 wxNode
*node
= GetChildren().First();
1337 node
= node
->Next();
1340 wxObject
*obj
= (wxObject
*)node
->Data();
1346 #endif // WXWIN_COMPATIBILITY
1348 void wxWindow::Clear()
1350 if ( m_macWindowData
)
1352 wxMacDrawingClientHelper
helper ( this ) ;
1354 wxPoint origin
= GetClientAreaOrigin() ;
1355 GetClientSize( &w
, &h
) ;
1356 UMASetThemeWindowBackground( m_macWindowData
->m_macWindow
, m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
1357 Rect r
= { origin
.y
, origin
.x
, origin
.y
+h
, origin
.x
+w
} ;
1362 wxClientDC
dc(this);
1363 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1364 dc
.SetBackground(brush
);
1369 // Setup background and foreground colours correctly
1370 void wxWindow::SetupColours()
1373 SetBackgroundColour(GetParent()->GetBackgroundColour());
1376 void wxWindow::OnIdle(wxIdleEvent
& event
)
1379 // Check if we need to send a LEAVE event
1380 if (m_mouseInWindow)
1383 ::GetCursorPos(&pt);
1384 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1386 // Generate a LEAVE event
1387 m_mouseInWindow = FALSE;
1388 MSWOnMouseLeave(pt.x, pt.y, 0);
1393 // This calls the UI-update mechanism (querying windows for
1394 // menu/toolbar/control state information)
1398 // Raise the window to the top of the Z order
1399 void wxWindow::Raise()
1404 // Lower the window to the bottom of the Z order
1405 void wxWindow::Lower()
1410 void wxWindow::DoSetClientSize(int width
, int height
)
1412 if ( width
!= -1 || height
!= -1 )
1415 if ( width
!= -1 && m_vScrollBar
)
1416 width
+= MAC_SCROLLBAR_SIZE
;
1417 if ( height
!= -1 && m_vScrollBar
)
1418 height
+= MAC_SCROLLBAR_SIZE
;
1420 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1421 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1423 DoSetSize( -1 , -1 , width
, height
) ;
1428 wxWindow
* wxWindow::s_lastMouseWindow
= NULL
;
1430 bool wxWindow::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindow
** outWin
)
1432 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1433 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1436 WindowRef window
= GetMacRootWindow() ;
1438 wxPoint
newPoint( point
) ;
1443 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1445 wxWindow
*child
= (wxWindow
*)node
->Data();
1446 // added the m_isShown test --dmazzoni
1447 if ( child
->GetMacRootWindow() == window
&& child
->m_isShown
)
1449 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1458 bool wxWindow::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindow
** outWin
)
1461 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1462 if ( ::FindWindow( pt
, &window
) == 3 )
1464 wxPoint
point( screenpoint
) ;
1465 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1468 win
->ScreenToClient( point
) ;
1469 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1475 extern int wxBusyCursorCount
;
1477 bool wxWindow::MacDispatchMouseEvent(wxMouseEvent
& event
)
1479 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1480 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1484 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) )
1487 WindowRef window
= GetMacRootWindow() ;
1495 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1497 wxWindow
*child
= (wxWindow
*)node
->Data();
1498 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1500 if (child
->MacDispatchMouseEvent(event
))
1508 if ( wxBusyCursorCount
== 0 )
1510 m_cursor
.MacInstall() ;
1514 if ( event
.GetEventType() == wxEVT_MOTION
1515 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1516 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1517 wxToolTip::RelayEvent( this , event
);
1518 #endif // wxUSE_TOOLTIPS
1519 GetEventHandler()->ProcessEvent( event
) ;
1526 wxString
wxWindow::MacGetToolTipString( wxPoint
&pt
)
1530 return m_tooltip
->GetTip() ;
1534 void wxWindow::MacFireMouseEvent( EventRecord
*ev
)
1536 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
1537 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1538 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1540 event
.m_leftDown
= isDown
&& !controlDown
;
1541 event
.m_middleDown
= FALSE
;
1542 event
.m_rightDown
= isDown
&& controlDown
;
1544 if ( ev
->what
== mouseDown
)
1547 event
.SetEventType(wxEVT_RIGHT_DOWN
) ;
1549 event
.SetEventType(wxEVT_LEFT_DOWN
) ;
1551 else if ( ev
->what
== mouseUp
)
1554 event
.SetEventType(wxEVT_RIGHT_UP
) ;
1556 event
.SetEventType(wxEVT_LEFT_UP
) ;
1560 event
.SetEventType(wxEVT_MOTION
) ;
1563 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1564 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1565 event
.m_altDown
= ev
->modifiers
& optionKey
;
1566 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1568 Point localwhere
= ev
->where
;
1571 ::GetPort( &port
) ;
1572 ::SetPort( UMAGetWindowPort( m_macWindowData
->m_macWindow
) ) ;
1573 ::GlobalToLocal( &localwhere
) ;
1576 if ( ev
->what
== mouseDown
)
1578 if ( ev
->when
- lastWhen
<= GetDblTime() )
1580 if ( abs( localwhere
.h
- lastWhere
.h
) < 3 || abs( localwhere
.v
- lastWhere
.v
) < 3 )
1583 event
.SetEventType(wxEVT_RIGHT_DCLICK
) ;
1585 event
.SetEventType(wxEVT_LEFT_DCLICK
) ;
1588 lastWhen
= ev
->when
;
1589 lastWhere
= localwhere
;
1592 event
.m_x
= localwhere
.h
;
1593 event
.m_y
= localwhere
.v
;
1598 wxPoint origin = GetClientAreaOrigin() ;
1600 event.m_x += origin.x ;
1601 event.m_y += origin.y ;
1604 event
.m_timeStamp
= ev
->when
;
1605 event
.SetEventObject(this);
1606 if ( wxTheApp
->s_captureWindow
)
1610 wxTheApp
->s_captureWindow
->ScreenToClient( &x
, &y
) ;
1613 wxTheApp
->s_captureWindow
->GetEventHandler()->ProcessEvent( event
) ;
1614 if ( ev
->what
== mouseUp
)
1616 wxTheApp
->s_captureWindow
= NULL
;
1617 if ( wxBusyCursorCount
== 0 )
1619 m_cursor
.MacInstall() ;
1625 MacDispatchMouseEvent( event
) ;
1629 void wxWindow::MacMouseDown( EventRecord
*ev
, short part
)
1631 MacFireMouseEvent( ev
) ;
1634 void wxWindow::MacMouseUp( EventRecord
*ev
, short part
)
1636 WindowPtr frontWindow
;
1641 MacFireMouseEvent( ev
) ;
1647 void wxWindow::MacMouseMoved( EventRecord
*ev
, short part
)
1649 WindowPtr frontWindow
;
1654 MacFireMouseEvent( ev
) ;
1659 void wxWindow::MacActivate( EventRecord
*ev
, bool inIsActivating
)
1661 wxActivateEvent
event(wxEVT_ACTIVATE
, inIsActivating
);
1662 event
.m_timeStamp
= ev
->when
;
1663 event
.SetEventObject(this);
1665 GetEventHandler()->ProcessEvent(event
);
1667 UMAHighlightAndActivateWindow( m_macWindowData
->m_macWindow
, inIsActivating
) ;
1670 void wxWindow::MacRedraw( RgnHandle updatergn
, long time
)
1672 // updatergn is always already clipped to our boundaries
1673 WindowRef window
= GetMacRootWindow() ;
1674 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1676 wxMacDrawingHelper
focus( this ) ; // was client
1679 WindowRef window
= GetMacRootWindow() ;
1680 bool eraseBackground
= false ;
1681 if ( m_macWindowData
)
1682 eraseBackground
= true ;
1683 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
1685 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
1687 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1689 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1690 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1691 // either a non gray background color or a non control window
1694 wxWindow
* parent
= GetParent() ;
1697 if ( parent
->GetMacRootWindow() != window
)
1699 // we are in a different window on the mac system
1704 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
1706 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1708 // if we have any other colours in the hierarchy
1709 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
1712 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1713 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
1716 GetRegionBounds( updatergn
, &box
) ;
1717 UMAApplyThemeBackground(kThemeBackgroundTabPane
, &box
, kThemeStateActive
,8,true);
1726 parent
= parent
->GetParent() ;
1730 // if there is nothing special -> use default
1731 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
1736 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
1738 if ( GetParent() && m_backgroundColour
!= GetParent()->GetBackgroundColour() )
1739 eraseBackground
= true ;
1740 SetClip( updatergn
) ;
1741 if ( eraseBackground
)
1743 EraseRgn( updatergn
) ;
1747 m_macUpdateRgn
= updatergn
;
1749 RgnHandle newupdate
= NewRgn() ;
1750 wxSize point
= GetClientSize() ;
1751 wxPoint origin
= GetClientAreaOrigin() ;
1753 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1754 SectRgn( newupdate
, m_macUpdateRgn
, newupdate
) ;
1755 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1756 m_updateRegion
= newupdate
;
1757 DisposeRgn( newupdate
) ;
1762 event
.m_timeStamp
= time
;
1763 event
.SetEventObject(this);
1764 GetEventHandler()->ProcessEvent(event
);
1768 RgnHandle childupdate
= NewRgn() ;
1770 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1772 wxWindow
*child
= (wxWindow
*)node
->Data();
1773 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1774 SectRgn( childupdate
, m_macUpdateRgn
, childupdate
) ;
1775 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1776 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1778 // because dialogs may also be children
1779 child
->MacRedraw( childupdate
, time
) ;
1782 DisposeRgn( childupdate
) ;
1783 // eventually a draw grow box here
1786 void wxWindow::MacUpdateImmediately()
1788 WindowRef window
= GetMacRootWindow() ;
1791 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1793 AGAPortHelper
help( GetWindowPort(window
) ) ;
1795 AGAPortHelper
help( (window
) ) ;
1797 SetOrigin( 0 , 0 ) ;
1798 BeginUpdate( window
) ;
1801 RgnHandle region
= NewRgn();
1805 GetPortVisibleRegion( GetWindowPort( window
), region
);
1807 // if windowshade gives incompatibility , take the follwing out
1808 if ( !EmptyRgn( region
) )
1810 win
->MacRedraw( region
, wxTheApp
->sm_lastMessageTime
) ;
1812 DisposeRgn( region
);
1815 EndUpdate( window
) ;
1819 void wxWindow::MacUpdate( EventRecord
*ev
)
1821 WindowRef window
= (WindowRef
) ev
->message
;
1822 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1824 AGAPortHelper
help( GetWindowPort(window
) ) ;
1826 AGAPortHelper
help( (window
) ) ;
1828 SetOrigin( 0 , 0 ) ;
1829 BeginUpdate( window
) ;
1832 RgnHandle region
= NewRgn();
1836 GetPortVisibleRegion( GetWindowPort( window
), region
);
1838 // if windowshade gives incompatibility , take the follwing out
1839 if ( !EmptyRgn( region
) )
1841 MacRedraw( region
, ev
->when
) ;
1843 DisposeRgn( region
);
1846 EndUpdate( window
) ;
1849 WindowRef
wxWindow::GetMacRootWindow() const
1851 WindowRef window
= NULL
;
1852 wxWindow
*iter
= (wxWindow
*)this ;
1856 if ( iter
->m_macWindowData
)
1857 return iter
->m_macWindowData
->m_macWindow
;
1859 iter
= iter
->GetParent() ;
1861 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1865 void wxWindow::MacCreateScrollBars( long style
)
1867 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
1869 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1870 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1872 GetClientSize( &width
, &height
) ;
1874 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1875 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1876 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1877 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1879 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
1880 vSize
, wxVERTICAL
);
1882 if ( style
& wxVSCROLL
)
1888 m_vScrollBar
->Show(false) ;
1890 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
1891 hSize
, wxHORIZONTAL
);
1892 if ( style
& wxHSCROLL
)
1897 m_hScrollBar
->Show(false) ;
1900 // because the create does not take into account the client area origin
1901 MacRepositionScrollBars() ; // we might have a real position shift
1904 void wxWindow::MacRepositionScrollBars()
1906 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
1907 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
1909 // get real client area
1911 int width
= m_width
;
1912 int height
= m_height
;
1914 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
1915 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
1917 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1918 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1919 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1920 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1927 MacClientToRootWindow( &x
, &y
) ;
1928 MacClientToRootWindow( &w
, &h
) ;
1930 WindowRef window
= NULL
;
1931 wxWindow
*iter
= (wxWindow
*)this ;
1933 int totW
= 10000 , totH
= 10000;
1936 if ( iter
->m_macWindowData
)
1938 totW
= iter
->m_width
;
1939 totH
= iter
->m_height
;
1943 iter
= iter
->GetParent() ;
1971 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1975 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
1979 void wxWindow::MacKeyDown( EventRecord
*ev
)
1985 bool wxWindow::AcceptsFocus() const
1987 return MacCanFocus() && wxWindowBase::AcceptsFocus();
1990 ControlHandle
wxWindow::MacGetContainerForEmbedding()
1992 if ( m_macWindowData
)
1993 return m_macWindowData
->m_macRootControl
;
1995 return GetParent()->MacGetContainerForEmbedding() ;
1998 void wxWindow::MacSuperChangedPosition()
2000 // only window-absolute structures have to be moved i.e. controls
2002 wxNode
*node
= GetChildren().First();
2005 wxWindow
*child
= (wxWindow
*)node
->Data();
2006 child
->MacSuperChangedPosition() ;
2007 node
= node
->Next();
2012 bool wxWindow::MacSetupFocusPort( )
2020 MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
2021 return MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
2024 bool wxWindow::MacSetupFocusClientPort( )
2032 MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
2033 return MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
2036 bool wxWindow::MacSetupDrawingPort( )
2044 MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
2045 return MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
2048 bool wxWindow::MacSetupDrawingClientPort( )
2056 MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
2057 return MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
2061 bool wxWindow::MacSetPortFocusParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
2063 if ( window
== NULL
)
2069 ::GetPort(&currPort
);
2070 port
= UMAGetWindowPort( window
) ;
2071 if (currPort
!= port
)
2074 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2075 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2079 bool wxWindow::MacSetPortDrawingParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
2081 if ( window
== NULL
)
2086 ::GetPort(&currPort
);
2087 port
= UMAGetWindowPort( window
) ;
2088 if (currPort
!= port
)
2090 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2091 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2092 ::ClipRect(&clipRect
);
2095 ::RGBBackColor(& win
->GetBackgroundColour().GetPixel() ) ;
2096 ::RGBForeColor(& win
->GetForegroundColour().GetPixel() ) ;
2097 Pattern whiteColor
;
2099 ::BackPat( GetQDGlobalsWhite( &whiteColor
) ) ;
2100 ::UMASetThemeWindowBackground( win
->m_macWindowData
->m_macWindow
, win
->m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
2104 void wxWindow::MacGetPortParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2106 if ( m_macWindowData
)
2112 clipRect
->right
= m_width
;
2113 clipRect
->bottom
= m_height
;
2114 *window
= m_macWindowData
->m_macWindow
;
2119 wxASSERT( GetParent() != NULL
) ;
2120 GetParent()->MacGetPortParams( localOrigin
, clipRect
, window
, rootwin
) ;
2121 localOrigin
->h
+= m_x
;
2122 localOrigin
->v
+= m_y
;
2123 OffsetRect(clipRect
, -m_x
, -m_y
);
2128 myClip
.right
= m_width
;
2129 myClip
.bottom
= m_height
;
2130 SectRect(clipRect
, &myClip
, clipRect
);
2134 void wxWindow::MacDoGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2136 // int width , height ;
2137 // GetClientSize( &width , &height ) ;
2139 if ( m_macWindowData
)
2145 clipRect
->right
= m_width
;//width;
2146 clipRect
->bottom
= m_height
;// height;
2147 *window
= m_macWindowData
->m_macWindow
;
2152 wxASSERT( GetParent() != NULL
) ;
2154 GetParent()->MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2156 localOrigin
->h
+= m_x
;
2157 localOrigin
->v
+= m_y
;
2158 OffsetRect(clipRect
, -m_x
, -m_y
);
2163 myClip
.right
= m_width
;//width;
2164 myClip
.bottom
= m_height
;// height;
2165 SectRect(clipRect
, &myClip
, clipRect
);
2169 void wxWindow::MacGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2171 MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2173 int width
, height
;
2174 GetClientSize( &width
, &height
) ;
2176 client
= GetClientAreaOrigin( ) ;
2178 localOrigin
->h
+= client
.x
;
2179 localOrigin
->v
+= client
.y
;
2180 OffsetRect(clipRect
, -client
.x
, -client
.y
);
2185 myClip
.right
= width
;
2186 myClip
.bottom
= height
;
2187 SectRect(clipRect
, &myClip
, clipRect
);
2190 long wxWindow::MacGetLeftBorderSize( ) const
2192 if( m_macWindowData
)
2195 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2199 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2203 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2210 long wxWindow::MacGetRightBorderSize( ) const
2212 if( m_macWindowData
)
2215 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2219 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2223 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2230 long wxWindow::MacGetTopBorderSize( ) const
2232 if( m_macWindowData
)
2235 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2239 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2243 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2250 long wxWindow::MacGetBottomBorderSize( ) const
2252 if( m_macWindowData
)
2255 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2259 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2263 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2270 long wxWindow::MacRemoveBordersFromStyle( long style
)
2272 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2275 wxMacFocusHelper::wxMacFocusHelper( wxWindow * theWindow )
2282 m_currentPort = NULL ;
2283 GetPort( &m_formerPort ) ;
2287 theWindow->MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
2288 m_currentPort = UMAGetWindowPort( window ) ;
2289 theWindow->MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
2294 wxMacFocusHelper::~wxMacFocusHelper()
2298 SetPort( m_currentPort ) ;
2299 SetOrigin( 0 , 0 ) ;
2301 if ( m_formerPort != m_currentPort )
2302 SetPort( m_formerPort ) ;
2305 wxMacDrawingHelper::wxMacDrawingHelper( wxWindow
* theWindow
)
2312 m_currentPort
= NULL
;
2314 GetPort( &m_formerPort
) ;
2317 theWindow
->MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2318 m_currentPort
= UMAGetWindowPort( window
) ;
2319 if ( m_formerPort
!= m_currentPort
)
2320 SetPort( m_currentPort
) ;
2321 GetPenState( &m_savedPenState
) ;
2322 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2327 wxMacDrawingHelper::~wxMacDrawingHelper()
2331 SetPort( m_currentPort
) ;
2332 SetPenState( &m_savedPenState
) ;
2333 SetOrigin( 0 , 0 ) ;
2335 GetPortBounds( m_currentPort
, &portRect
) ;
2336 ClipRect( &portRect
) ;
2339 if ( m_formerPort
!= m_currentPort
)
2340 SetPort( m_formerPort
) ;
2343 wxMacFocusClientHelper::wxMacFocusClientHelper( wxWindow * theWindow )
2350 m_currentPort = NULL ;
2352 GetPort( &m_formerPort ) ;
2356 theWindow->MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
2357 m_currentPort = UMAGetWindowPort( window ) ;
2358 theWindow->MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ;
2363 wxMacFocusClientHelper::~wxMacFocusClientHelper()
2367 SetPort( m_currentPort ) ;
2368 SetOrigin( 0 , 0 ) ;
2370 if ( m_formerPort != m_currentPort )
2371 SetPort( m_formerPort ) ;
2375 wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindow
* theWindow
)
2382 m_currentPort
= NULL
;
2384 GetPort( &m_formerPort
) ;
2388 theWindow
->MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2389 m_currentPort
= UMAGetWindowPort( window
) ;
2390 if ( m_formerPort
!= m_currentPort
)
2391 SetPort( m_currentPort
) ;
2392 GetPenState( &m_savedPenState
) ;
2393 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2398 wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
2402 SetPort( m_currentPort
) ;
2403 SetPenState( &m_savedPenState
) ;
2404 SetOrigin( 0 , 0 ) ;
2406 GetPortBounds( m_currentPort
, &portRect
) ;
2407 ClipRect( &portRect
) ;
2410 if ( m_formerPort
!= m_currentPort
)
2411 SetPort( m_formerPort
) ;
2414 // Find the wxWindow at the current mouse position, returning the mouse
2416 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
2418 pt
= wxGetMousePosition();
2419 wxWindow
* found
= wxFindWindowAtPoint(pt
);
2423 // Get the current mouse position.
2424 wxPoint
wxGetMousePosition()
2427 wxGetMousePosition(& x
, & y
);
2428 return wxPoint(x
, y
);