1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
18 #include "wx/window.h"
20 #include "wx/dcclient.h"
24 #include "wx/layout.h"
25 #include "wx/dialog.h"
26 #include "wx/listbox.h"
27 #include "wx/scrolbar.h"
28 #include "wx/statbox.h"
29 #include "wx/button.h"
30 #include "wx/settings.h"
31 #include "wx/msgdlg.h"
33 #include "wx/notebook.h"
34 #include "wx/tabctrl.h"
35 #include "wx/tooltip.h"
36 #include "wx/statusbr.h"
37 #include "wx/menuitem.h"
44 #define wxWINDOW_HSCROLL 5998
45 #define wxWINDOW_VSCROLL 5997
46 #define MAC_SCROLLBAR_SIZE 16
48 #include <wx/mac/uma.h>
50 #if wxUSE_DRAG_AND_DROP
56 extern wxList wxPendingDelete
;
57 wxWindow
* gFocusWindow
= NULL
;
59 #if !USE_SHARED_LIBRARY
60 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxEvtHandler
)
61 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
62 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground
)
63 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
64 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
65 EVT_IDLE(wxWindow::OnIdle
)
66 EVT_SET_FOCUS(wxWindow::OnSetFocus
)
73 // ===========================================================================
75 // ===========================================================================
77 // ---------------------------------------------------------------------------
78 // wxWindow utility functions
79 // ---------------------------------------------------------------------------
81 // Find an item given the Macintosh Window Reference
83 wxList
*wxWinMacWindowList
= NULL
;
84 wxWindow
*wxFindWinFromMacWindow(WindowRef inWindowRef
)
86 wxNode
*node
= wxWinMacWindowList
->Find((long)inWindowRef
);
89 return (wxWindow
*)node
->Data();
92 void wxAssociateWinWithMacWindow(WindowRef inWindowRef
, wxWindow
*win
)
94 // adding NULL WindowRef is (first) surely a result of an error and
95 // (secondly) breaks menu command processing
96 wxCHECK_RET( inWindowRef
!= (WindowRef
) NULL
, "attempt to add a NULL WindowRef to window list" );
98 if ( !wxWinMacWindowList
->Find((long)inWindowRef
) )
99 wxWinMacWindowList
->Append((long)inWindowRef
, win
);
102 void wxRemoveMacWindowAssociation(wxWindow
*win
)
104 wxWinMacWindowList
->DeleteObject(win
);
107 // ----------------------------------------------------------------------------
108 // constructors and such
109 // ----------------------------------------------------------------------------
111 WindowRef
wxWindow::s_macWindowInUpdate
= NULL
;
113 void wxWindow::Init()
118 m_macEraseOnRedraw
= true ;
121 m_doubleClickAllowed
= 0;
122 m_winCaptured
= FALSE
;
124 m_isBeingDeleted
= FALSE
;
127 m_mouseInWindow
= FALSE
;
131 m_backgroundTransparent
= FALSE
;
133 // as all windows are created with WS_VISIBLE style...
136 m_macWindowData
= NULL
;
137 m_macEraseOnRedraw
= true ;
144 m_hScrollBar
= NULL
;
145 m_vScrollBar
= NULL
;
147 #if wxUSE_DRAG_AND_DROP
148 m_pDropTarget
= NULL
;
153 wxWindow::~wxWindow()
155 m_isBeingDeleted
= TRUE
;
157 if ( s_lastMouseWindow
== this )
159 s_lastMouseWindow
= NULL
;
162 if ( gFocusWindow
== this )
164 gFocusWindow
= NULL
;
168 m_parent
->RemoveChild(this);
172 if ( m_macWindowData
)
174 wxToolTip::NotifyWindowDelete(m_macWindowData
->m_macWindow
) ;
175 UMADisposeWindow( m_macWindowData
->m_macWindow
) ;
176 delete m_macWindowData
;
177 wxRemoveMacWindowAssociation( this ) ;
182 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
186 const wxString
& name
)
188 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindow without parent") );
190 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
193 parent
->AddChild(this);
197 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
198 m_width
= WidthDefault( size
.x
);
199 m_height
= HeightDefault( size
.y
) ;
201 if ( ! IsKindOf( CLASSINFO ( wxControl
) ) && ! IsKindOf( CLASSINFO( wxStatusBar
) ) )
203 MacCreateScrollBars( style
) ;
209 void wxWindow::SetFocus()
211 if ( gFocusWindow
== this )
214 if ( AcceptsFocus() )
220 if ( gFocusWindow
->m_caret
)
222 gFocusWindow
->m_caret
->OnKillFocus();
224 #endif // wxUSE_CARET
225 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
226 if ( control
&& control
->GetMacControl() )
228 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlFocusNoPart
) ;
229 control
->MacRedrawControl() ;
231 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
232 event
.SetEventObject(gFocusWindow
);
233 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
235 gFocusWindow
= this ;
241 m_caret
->OnSetFocus();
243 #endif // wxUSE_CARET
244 // panel wants to track the window which was the last to have focus in it
245 wxPanel
*panel
= wxDynamicCast(GetParent(), wxPanel
);
248 panel
->SetLastFocus(this);
250 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
251 if ( control
&& control
->GetMacControl() )
253 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlEditTextPart
) ;
256 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
257 event
.SetEventObject(this);
258 GetEventHandler()->ProcessEvent(event
) ;
263 bool wxWindow::Enable(bool enable
)
265 if ( !wxWindowBase::Enable(enable
) )
268 wxWindowList::Node
*node
= GetChildren().GetFirst();
271 wxWindow
*child
= node
->GetData();
272 child
->Enable(enable
);
274 node
= node
->GetNext();
280 void wxWindow::CaptureMouse()
282 wxTheApp
->s_captureWindow
= this ;
285 void wxWindow::ReleaseMouse()
287 wxTheApp
->s_captureWindow
= NULL
;
290 #if wxUSE_DRAG_AND_DROP
292 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
294 if ( m_pDropTarget
!= 0 ) {
295 delete m_pDropTarget
;
298 m_pDropTarget
= pDropTarget
;
299 if ( m_pDropTarget
!= 0 )
307 // Old style file-manager drag&drop
308 void wxWindow::DragAcceptFiles(bool accept
)
314 void wxWindow::DoGetSize(int *x
, int *y
) const
320 void wxWindow::DoGetPosition(int *x
, int *y
) const
326 wxPoint
pt(GetParent()->GetClientAreaOrigin());
333 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
335 menu
->SetInvokingWindow(this);
337 ClientToScreen( &x
, &y
) ;
339 ::InsertMenu( menu
->GetHMenu() , -1 ) ;
340 long menuResult
= ::PopUpMenuSelect(menu
->GetHMenu() ,y
,x
, 0) ;
341 menu
->MacMenuSelect( this , TickCount() , HiWord(menuResult
) , LoWord(menuResult
) ) ;
342 ::DeleteMenu( menu
->MacGetMenuId() ) ;
343 menu
->SetInvokingWindow(NULL
);
348 void wxWindow::DoScreenToClient(int *x
, int *y
) const
350 WindowRef window
= GetMacRootWindow() ;
358 ::SetPort( UMAGetWindowPort( window
) ) ;
359 ::GlobalToLocal( &localwhere
) ;
365 MacRootWindowToClient( x
, y
) ;
368 void wxWindow::DoClientToScreen(int *x
, int *y
) const
370 WindowRef window
= GetMacRootWindow() ;
372 MacClientToRootWindow( x
, y
) ;
380 ::SetPort( UMAGetWindowPort( window
) ) ;
381 ::SetOrigin( 0 , 0 ) ;
382 ::LocalToGlobal( &localwhere
) ;
388 void wxWindow::MacClientToRootWindow( int *x
, int *y
) const
390 if ( m_macWindowData
)
397 GetParent()->MacClientToRootWindow( x
, y
) ;
401 void wxWindow::MacRootWindowToClient( int *x
, int *y
) const
403 if ( m_macWindowData
)
410 GetParent()->MacRootWindowToClient( x
, y
) ;
414 bool wxWindow::SetCursor(const wxCursor
& cursor
)
416 if ( !wxWindowBase::SetCursor(cursor
) )
422 wxASSERT_MSG( m_cursor
.Ok(),
423 wxT("cursor must be valid after call to the base version"));
429 // Change the cursor NOW if we're within the correct window
431 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
433 if ( mouseWin
== this && !wxIsBusy() )
435 cursor
.MacInstall() ;
443 // Get size *available for subwindows* i.e. excluding menu bar etc.
444 void wxWindow::DoGetClientSize(int *x
, int *y
) const
449 *x
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
450 *y
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
452 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
459 MacClientToRootWindow( &x1
, &y1
) ;
460 MacClientToRootWindow( &w
, &h
) ;
462 WindowRef window
= NULL
;
463 wxWindow
*iter
= (wxWindow
*)this ;
465 int totW
= 10000 , totH
= 10000;
468 if ( iter
->m_macWindowData
)
470 totW
= iter
->m_width
;
471 totH
= iter
->m_height
;
475 iter
= iter
->GetParent() ;
478 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
480 (*y
) -= MAC_SCROLLBAR_SIZE
;
486 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
488 (*x
) -= MAC_SCROLLBAR_SIZE
;
498 // ----------------------------------------------------------------------------
500 // ----------------------------------------------------------------------------
504 void wxWindow::DoSetToolTip(wxToolTip
*tooltip
)
506 wxWindowBase::DoSetToolTip(tooltip
);
509 m_tooltip
->SetWindow(this);
512 #endif // wxUSE_TOOLTIPS
514 void wxWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
516 DoSetSize( x
,y
, width
, height
) ;
519 // set the size of the window: if the dimensions are positive, just use them,
520 // but if any of them is equal to -1, it means that we must find the value for
521 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
522 // which case -1 is a valid value for x and y)
524 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
525 // the width/height to best suit our contents, otherwise we reuse the current
527 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
532 int former_w
= m_width
;
533 int former_h
= m_height
;
535 int currentX
, currentY
;
536 GetPosition(¤tX
, ¤tY
);
537 int currentW
,currentH
;
538 GetSize(¤tW
, ¤tH
);
540 int actualWidth
= width
;
541 int actualHeight
= height
;
544 if (x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
546 if (y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
549 wxSize
size( -1 , -1 ) ;
551 if (width
== -1 || height
== -1 )
553 size
= DoGetBestSize() ;
558 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
560 actualWidth
= size
.x
;
561 if ( actualWidth
== -1 )
566 actualWidth
= currentW
;
571 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
573 actualHeight
= size
.y
;
574 if ( actualHeight
== -1 )
579 actualHeight
= currentH
;
583 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
584 actualWidth
= m_minWidth
;
585 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
586 actualHeight
= m_minHeight
;
587 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
588 actualWidth
= m_maxWidth
;
589 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
590 actualHeight
= m_maxHeight
;
591 if ( actualX
== currentX
&& actualY
== currentY
&& actualWidth
== currentW
&& actualHeight
== currentH
)
593 MacRepositionScrollBars() ; // we might have a real position shift
597 AdjustForParentClientOrigin(actualX
, actualY
, sizeFlags
);
600 bool doMove
= false ;
601 bool doResize
= false ;
603 if ( actualX
!= former_x
|| actualY
!= former_y
)
607 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
612 if ( doMove
|| doResize
)
614 if ( m_macWindowData
)
619 // erase former position
620 wxMacDrawingHelper
focus( this ) ;
623 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
624 ClipRect( &clientrect
) ;
625 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
630 m_width
= actualWidth
;
631 m_height
= actualHeight
;
632 if ( m_macWindowData
)
635 ::MoveWindow(m_macWindowData
->m_macWindow
, m_x
, m_y
, false); // don't make frontmost
638 ::SizeWindow(m_macWindowData
->m_macWindow
, m_width
, m_height
, true);
640 // the OS takes care of invalidating and erasing the new area
641 // we have erased the old one
643 if ( IsKindOf( CLASSINFO( wxFrame
) ) )
645 wxFrame
* frame
= (wxFrame
*) this ;
646 frame
->PositionStatusBar();
647 frame
->PositionToolBar();
652 // erase new position
655 wxMacDrawingHelper
focus( this ) ;
658 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
659 ClipRect( &clientrect
) ;
660 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
665 wxWindow::MacSuperChangedPosition() ; // like this only children will be notified
667 MacRepositionScrollBars() ;
670 wxMoveEvent
event(wxPoint(m_x
, m_y
), m_windowId
);
671 event
.SetEventObject(this);
672 GetEventHandler()->ProcessEvent(event
) ;
676 MacRepositionScrollBars() ;
677 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
678 event
.SetEventObject(this);
679 GetEventHandler()->ProcessEvent(event
);
683 // For implementation purposes - sometimes decorations make the client area
686 wxPoint
wxWindow::GetClientAreaOrigin() const
688 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
691 // Makes an adjustment to the window position (for example, a frame that has
692 // a toolbar that it manages itself).
693 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
695 if( !m_macWindowData
)
697 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
699 wxPoint
pt(GetParent()->GetClientAreaOrigin());
700 x
+= pt
.x
; y
+= pt
.y
;
705 void wxWindow::SetTitle(const wxString
& title
)
711 if( wxApp::s_macDefaultEncodingIsPC
)
712 label
= wxMacMakeMacStringFromPC( title
) ;
716 if ( m_macWindowData
)
717 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
720 wxString
wxWindow::GetTitle() const
725 bool wxWindow::Show(bool show
)
727 if ( !wxWindowBase::Show(show
) )
730 if ( m_macWindowData
)
734 UMAShowWindow( m_macWindowData
->m_macWindow
) ;
735 UMASelectWindow( m_macWindowData
->m_macWindow
) ;
736 // no need to generate events here, they will get them triggered by macos
737 // actually they should be , but apparently they are not
738 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
739 event
.SetEventObject(this);
740 GetEventHandler()->ProcessEvent(event
);
744 UMAHideWindow( m_macWindowData
->m_macWindow
) ;
747 MacSuperShown( show
) ;
750 MacUpdateImmediately() ;
755 void wxWindow::MacSuperShown( bool show
)
757 wxNode
*node
= GetChildren().First();
760 wxWindow
*child
= (wxWindow
*)node
->Data();
761 if ( child
->m_isShown
)
762 child
->MacSuperShown( show
) ;
767 bool wxWindow::MacIsReallyShown() const
769 if ( m_isShown
&& (m_parent
!= NULL
) ) {
770 return m_parent
->MacIsReallyShown();
774 bool status = m_isShown ;
775 wxWindow * win = this ;
776 while ( status && win->m_parent != NULL )
778 win = win->m_parent ;
779 status = win->m_isShown ;
785 int wxWindow::GetCharHeight() const
787 wxClientDC
dc ( (wxWindow
*)this ) ;
788 return dc
.GetCharHeight() ;
791 int wxWindow::GetCharWidth() const
793 wxClientDC
dc ( (wxWindow
*)this ) ;
794 return dc
.GetCharWidth() ;
797 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
798 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
800 const wxFont
*fontToUse
= theFont
;
804 wxClientDC
dc( (wxWindow
*) this ) ;
806 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
807 if ( externalLeading
)
808 *externalLeading
= le
;
817 void wxWindow::MacEraseBackground( Rect
*rect
)
820 WindowRef window = GetMacRootWindow() ;
821 if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
823 UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ;
825 else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
827 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
828 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
829 // either a non gray background color or a non control window
831 wxWindow* parent = GetParent() ;
834 if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
836 // if we have any other colours in the hierarchy
837 RGBBackColor( &parent->m_backgroundColour.GetPixel()) ;
840 if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() )
842 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
843 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
845 UMAApplyThemeBackground(kThemeBackgroundTabPane, rect, kThemeStateActive,8,true);
851 // we have arrived at a non control item
855 parent = parent->GetParent() ;
859 // if there is nothing special -> use default
860 UMASetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ;
865 RGBBackColor( &m_backgroundColour.GetPixel()) ;
870 for (wxNode *node = GetChildren().First(); node; node = node->Next())
872 wxWindow *child = (wxWindow*)node->Data();
874 Rect clientrect = { child->m_x , child->m_y , child->m_x +child->m_width , child->m_y + child->m_height } ;
875 SectRect( &clientrect , rect , &clientrect ) ;
877 OffsetRect( &clientrect , -child->m_x , -child->m_y ) ;
878 if ( child->GetMacRootWindow() == window && child->IsShown() )
880 wxMacDrawingClientHelper focus( this ) ;
883 child->MacEraseBackground( &clientrect ) ;
890 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
892 wxMacDrawingHelper
focus( this ) ;
895 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
896 ClipRect( &clientrect
) ;
900 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
901 SectRect( &clientrect
, &r
, &clientrect
) ;
903 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
906 m_macEraseOnRedraw
= false ;
908 m_macEraseOnRedraw
= true ;
911 // Responds to colour changes: passes event on to children.
912 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
914 wxNode
*node
= GetChildren().First();
917 // Only propagate to non-top-level windows
918 wxWindow
*win
= (wxWindow
*)node
->Data();
919 if ( win
->GetParent() )
921 wxSysColourChangedEvent event2
;
922 event
.m_eventObject
= win
;
923 win
->GetEventHandler()->ProcessEvent(event2
);
930 #if wxUSE_CARET && WXWIN_COMPATIBILITY
931 // ---------------------------------------------------------------------------
932 // Caret manipulation
933 // ---------------------------------------------------------------------------
935 void wxWindow::CreateCaret(int w
, int h
)
937 SetCaret(new wxCaret(this, w
, h
));
940 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
942 wxFAIL_MSG("not implemented");
945 void wxWindow::ShowCaret(bool show
)
947 wxCHECK_RET( m_caret
, "no caret to show" );
952 void wxWindow::DestroyCaret()
957 void wxWindow::SetCaretPos(int x
, int y
)
959 wxCHECK_RET( m_caret
, "no caret to move" );
964 void wxWindow::GetCaretPos(int *x
, int *y
) const
966 wxCHECK_RET( m_caret
, "no caret to get position of" );
968 m_caret
->GetPosition(x
, y
);
970 #endif // wxUSE_CARET
972 wxWindow
*wxGetActiveWindow()
974 // actually this is a windows-only concept
978 // Coordinates relative to the window
979 void wxWindow::WarpPointer (int x_pos
, int y_pos
)
981 // We really dont move the mouse programmatically under mac
984 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
986 // TODO : probably we would adopt the EraseEvent structure
989 int wxWindow::GetScrollPos(int orient
) const
991 if ( orient
== wxHORIZONTAL
)
994 return m_hScrollBar
->GetThumbPosition() ;
999 return m_vScrollBar
->GetThumbPosition() ;
1004 // This now returns the whole range, not just the number
1005 // of positions that we can scroll.
1006 int wxWindow::GetScrollRange(int orient
) const
1008 if ( orient
== wxHORIZONTAL
)
1011 return m_hScrollBar
->GetRange() ;
1016 return m_vScrollBar
->GetRange() ;
1021 int wxWindow::GetScrollThumb(int orient
) const
1023 if ( orient
== wxHORIZONTAL
)
1026 return m_hScrollBar
->GetThumbSize() ;
1031 return m_vScrollBar
->GetThumbSize() ;
1036 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
1038 if ( orient
== wxHORIZONTAL
)
1041 m_hScrollBar
->SetThumbPosition( pos
) ;
1046 m_vScrollBar
->SetThumbPosition( pos
) ;
1050 void wxWindow::MacCreateRealWindow( const wxString
& title
,
1054 const wxString
& name
)
1057 m_windowStyle
= style
;
1078 m_macWindowData
= new MacWindowData() ;
1080 ::SetRect(&theBoundsRect
, m_x
, m_y
, m_x
+ m_width
, m_y
+ m_height
);
1082 // translate the window attributes in the appropriate window class and attributes
1084 WindowClass wclass
= 0;
1085 WindowAttributes attr
= kWindowNoAttributes
;
1087 if ( HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
) )
1089 wclass
= kFloatingWindowClass
;
1090 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1092 attr
|= kWindowSideTitlebarAttribute
;
1095 else if ( HasFlag( wxCAPTION
) )
1097 if ( HasFlag( wxDIALOG_MODAL
) )
1099 wclass
= kMovableModalWindowClass
;
1103 wclass
= kDocumentWindowClass
;
1108 wclass
= kModalWindowClass
;
1111 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) )
1113 attr
|= kWindowFullZoomAttribute
;
1114 attr
|= kWindowCollapseBoxAttribute
;
1116 if ( HasFlag( wxRESIZE_BORDER
) )
1118 attr
|= kWindowResizableAttribute
;
1120 if ( HasFlag( wxSYSTEM_MENU
) )
1122 attr
|= kWindowCloseBoxAttribute
;
1125 UMACreateNewWindow( wclass
, attr
, &theBoundsRect
, &m_macWindowData
->m_macWindow
) ;
1126 wxAssociateWinWithMacWindow( m_macWindowData
->m_macWindow
, this ) ;
1128 if( wxApp::s_macDefaultEncodingIsPC
)
1129 label
= wxMacMakeMacStringFromPC( title
) ;
1132 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
1133 UMACreateRootControl( m_macWindowData
->m_macWindow
, &m_macWindowData
->m_macRootControl
) ;
1135 m_macWindowData
->m_macFocus
= NULL
;
1138 void wxWindow::MacPaint( wxPaintEvent
&event
)
1142 void wxWindow::MacPaintBorders( )
1144 if( m_macWindowData
)
1147 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1148 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1149 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1150 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1153 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1155 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1156 RGBColor pen1
= sunken
? white
: black
;
1157 RGBColor pen2
= sunken
? shadow
: face
;
1158 RGBColor pen3
= sunken
? face
: shadow
;
1159 RGBColor pen4
= sunken
? black
: white
;
1161 RGBForeColor( &pen1
) ;
1163 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1164 FrameRect( &rect
) ;
1166 RGBForeColor( &pen2
) ;
1168 Rect rect
= { 1 , 1 , m_height
-1 , m_width
-1} ;
1169 FrameRect( &rect
) ;
1171 RGBForeColor( &pen3
) ;
1173 Rect rect
= { 0 , 0 , m_height
-2 , m_width
-2} ;
1174 FrameRect( &rect
) ;
1176 RGBForeColor( &pen4
) ;
1179 LineTo( m_width
- 3 , 0 ) ;
1181 LineTo( 0 , m_height
- 3 ) ;
1184 else if (HasFlag(wxSIMPLE_BORDER
))
1186 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1187 RGBForeColor( &black
) ;
1188 FrameRect( &rect
) ;
1191 if ( this->GetParent() )
1193 wxPaintDC dc(GetParent());
1194 GetParent()->PrepareDC(dc);
1196 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) )
1198 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1200 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1201 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1203 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1204 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1205 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1206 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1209 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1212 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1215 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1218 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1219 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1221 else if (HasFlag(wxDOUBLE_BORDER))
1223 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1225 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1226 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1228 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1229 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1230 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1231 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1234 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1237 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1240 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1243 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1244 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1246 else if (HasFlag(wxSIMPLE_BORDER))
1248 dc.SetPen(*wxBLACK_PEN);
1249 dc.DrawRectangle(m_x, m_y, m_width, m_height);
1255 // New function that will replace some of the above.
1256 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1257 int range
, bool refresh
)
1259 if ( orient
== wxHORIZONTAL
)
1263 if ( range
== 0 || thumbVisible
>= range
)
1265 if ( m_hScrollBar
->IsShown() )
1266 m_hScrollBar
->Show(false) ;
1270 if ( !m_hScrollBar
->IsShown() )
1271 m_hScrollBar
->Show(true) ;
1272 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, refresh
) ;
1280 if ( range
== 0 || thumbVisible
>= range
)
1282 if ( m_vScrollBar
->IsShown() )
1283 m_vScrollBar
->Show(false) ;
1287 if ( !m_vScrollBar
->IsShown() )
1288 m_vScrollBar
->Show(true) ;
1289 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, refresh
) ;
1293 MacRepositionScrollBars() ;
1296 // Does a physical scroll
1297 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1299 wxMacDrawingClientHelper
focus( this ) ;
1302 int width
, height
;
1303 GetClientSize( &width
, &height
) ;
1305 Rect scrollrect
= { 0 , 0 , height
, width
} ;
1307 RgnHandle updateRgn
= NewRgn() ;
1308 ClipRect( &scrollrect
) ;
1311 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
1312 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1314 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1315 InvalWindowRgn( GetMacRootWindow() , updateRgn
) ;
1316 DisposeRgn( updateRgn
) ;
1319 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1321 wxWindow
*child
= (wxWindow
*)node
->Data();
1322 if (child
== m_vScrollBar
) continue;
1323 if (child
== m_hScrollBar
) continue;
1324 if (child
->IsTopLevel()) continue;
1326 child
->GetPosition( &x
, &y
);
1328 child
->GetSize( &w
, &h
);
1329 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1334 void wxWindow::MacOnScroll(wxScrollEvent
&event
)
1336 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1338 wxScrollWinEvent wevent
;
1339 wevent
.SetPosition(event
.GetPosition());
1340 wevent
.SetOrientation(event
.GetOrientation());
1341 wevent
.m_eventObject
= this;
1343 if (event
.m_eventType
== wxEVT_SCROLL_TOP
) {
1344 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1346 if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
) {
1347 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1349 if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
) {
1350 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1352 if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
) {
1353 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1355 if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
) {
1356 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1358 if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
) {
1359 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1361 if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
) {
1362 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1365 GetEventHandler()->ProcessEvent(wevent
);
1369 bool wxWindow::SetFont(const wxFont
& font
)
1371 if ( !wxWindowBase::SetFont(font
) )
1380 // Get the window with the focus
1381 wxWindow
*wxWindowBase::FindFocus()
1383 return gFocusWindow
;
1386 #if WXWIN_COMPATIBILITY
1387 // If nothing defined for this, try the parent.
1388 // E.g. we may be a button loaded from a resource, with no callback function
1390 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1392 if ( GetEventHandler()->ProcessEvent(event
) )
1395 m_parent
->GetEventHandler()->OnCommand(win
, event
);
1397 #endif // WXWIN_COMPATIBILITY_2
1399 #if WXWIN_COMPATIBILITY
1400 wxObject
* wxWindow::GetChild(int number
) const
1402 // Return a pointer to the Nth object in the Panel
1403 wxNode
*node
= GetChildren().First();
1406 node
= node
->Next();
1409 wxObject
*obj
= (wxObject
*)node
->Data();
1415 #endif // WXWIN_COMPATIBILITY
1417 void wxWindow::OnSetFocus(wxFocusEvent
& event
)
1419 // panel wants to track the window which was the last to have focus in it,
1420 // so we want to set ourselves as the window which last had focus
1422 // notice that it's also important to do it upwards the tree becaus
1423 // otherwise when the top level panel gets focus, it won't set it back to
1424 // us, but to some other sibling
1425 wxWindow
*win
= this;
1428 wxWindow
*parent
= win
->GetParent();
1429 wxPanel
*panel
= wxDynamicCast(parent
, wxPanel
);
1432 panel
->SetLastFocus(win
);
1441 void wxWindow::Clear()
1443 if ( m_macWindowData
)
1445 wxMacDrawingClientHelper
helper ( this ) ;
1447 wxPoint origin
= GetClientAreaOrigin() ;
1448 GetClientSize( &w
, &h
) ;
1449 UMASetThemeWindowBackground( m_macWindowData
->m_macWindow
, m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
1450 Rect r
= { origin
.y
, origin
.x
, origin
.y
+h
, origin
.x
+w
} ;
1455 wxClientDC
dc(this);
1456 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1457 dc
.SetBackground(brush
);
1462 // Setup background and foreground colours correctly
1463 void wxWindow::SetupColours()
1466 SetBackgroundColour(GetParent()->GetBackgroundColour());
1469 void wxWindow::OnIdle(wxIdleEvent
& event
)
1472 // Check if we need to send a LEAVE event
1473 if (m_mouseInWindow)
1476 ::GetCursorPos(&pt);
1477 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1479 // Generate a LEAVE event
1480 m_mouseInWindow = FALSE;
1481 MSWOnMouseLeave(pt.x, pt.y, 0);
1486 // This calls the UI-update mechanism (querying windows for
1487 // menu/toolbar/control state information)
1491 // Raise the window to the top of the Z order
1492 void wxWindow::Raise()
1497 // Lower the window to the bottom of the Z order
1498 void wxWindow::Lower()
1503 void wxWindow::DoSetClientSize(int width
, int height
)
1505 if ( width
!= -1 || height
!= -1 )
1508 if ( width
!= -1 && m_vScrollBar
)
1509 width
+= MAC_SCROLLBAR_SIZE
;
1510 if ( height
!= -1 && m_vScrollBar
)
1511 height
+= MAC_SCROLLBAR_SIZE
;
1513 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1514 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1516 DoSetSize( -1 , -1 , width
, height
) ;
1521 wxWindow
* wxWindow::s_lastMouseWindow
= NULL
;
1523 bool wxWindow::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindow
** outWin
)
1525 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1526 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1529 WindowRef window
= GetMacRootWindow() ;
1531 wxPoint
newPoint( point
) ;
1536 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1538 wxWindow
*child
= (wxWindow
*)node
->Data();
1539 // added the m_isShown test --dmazzoni
1540 if ( child
->GetMacRootWindow() == window
&& child
->m_isShown
)
1542 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1551 bool wxWindow::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindow
** outWin
)
1554 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1555 if ( ::FindWindow( pt
, &window
) == 3 )
1557 wxPoint
point( screenpoint
) ;
1558 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1561 win
->ScreenToClient( point
) ;
1562 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1568 extern int wxBusyCursorCount
;
1570 bool wxWindow::MacDispatchMouseEvent(wxMouseEvent
& event
)
1572 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1573 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1577 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) )
1580 WindowRef window
= GetMacRootWindow() ;
1588 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1590 wxWindow
*child
= (wxWindow
*)node
->Data();
1591 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1593 if (child
->MacDispatchMouseEvent(event
))
1601 if ( wxBusyCursorCount
== 0 )
1603 m_cursor
.MacInstall() ;
1606 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1608 // set focus to this window
1609 if (AcceptsFocus() && FindFocus()!=this)
1614 if ( event
.GetEventType() == wxEVT_MOTION
1615 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1616 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1617 wxToolTip::RelayEvent( this , event
);
1618 #endif // wxUSE_TOOLTIPS
1619 GetEventHandler()->ProcessEvent( event
) ;
1626 wxString
wxWindow::MacGetToolTipString( wxPoint
&pt
)
1630 return m_tooltip
->GetTip() ;
1634 void wxWindow::MacFireMouseEvent( EventRecord
*ev
)
1636 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
1637 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1638 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1640 event
.m_leftDown
= isDown
&& !controlDown
;
1641 event
.m_middleDown
= FALSE
;
1642 event
.m_rightDown
= isDown
&& controlDown
;
1644 if ( ev
->what
== mouseDown
)
1647 event
.SetEventType(wxEVT_RIGHT_DOWN
) ;
1649 event
.SetEventType(wxEVT_LEFT_DOWN
) ;
1651 else if ( ev
->what
== mouseUp
)
1654 event
.SetEventType(wxEVT_RIGHT_UP
) ;
1656 event
.SetEventType(wxEVT_LEFT_UP
) ;
1660 event
.SetEventType(wxEVT_MOTION
) ;
1663 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1664 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1665 event
.m_altDown
= ev
->modifiers
& optionKey
;
1666 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1668 Point localwhere
= ev
->where
;
1671 ::GetPort( &port
) ;
1672 ::SetPort( UMAGetWindowPort( m_macWindowData
->m_macWindow
) ) ;
1673 ::GlobalToLocal( &localwhere
) ;
1676 if ( ev
->what
== mouseDown
)
1678 if ( ev
->when
- lastWhen
<= GetDblTime() )
1680 if ( abs( localwhere
.h
- lastWhere
.h
) < 3 || abs( localwhere
.v
- lastWhere
.v
) < 3 )
1683 event
.SetEventType(wxEVT_RIGHT_DCLICK
) ;
1685 event
.SetEventType(wxEVT_LEFT_DCLICK
) ;
1688 lastWhen
= ev
->when
;
1689 lastWhere
= localwhere
;
1692 event
.m_x
= localwhere
.h
;
1693 event
.m_y
= localwhere
.v
;
1698 wxPoint origin = GetClientAreaOrigin() ;
1700 event.m_x += origin.x ;
1701 event.m_y += origin.y ;
1704 event
.m_timeStamp
= ev
->when
;
1705 event
.SetEventObject(this);
1706 if ( wxTheApp
->s_captureWindow
)
1710 wxTheApp
->s_captureWindow
->ScreenToClient( &x
, &y
) ;
1713 wxTheApp
->s_captureWindow
->GetEventHandler()->ProcessEvent( event
) ;
1714 if ( ev
->what
== mouseUp
)
1716 wxTheApp
->s_captureWindow
= NULL
;
1717 if ( wxBusyCursorCount
== 0 )
1719 m_cursor
.MacInstall() ;
1725 MacDispatchMouseEvent( event
) ;
1729 void wxWindow::MacMouseDown( EventRecord
*ev
, short part
)
1731 MacFireMouseEvent( ev
) ;
1734 void wxWindow::MacMouseUp( EventRecord
*ev
, short part
)
1736 WindowPtr frontWindow
;
1741 MacFireMouseEvent( ev
) ;
1747 void wxWindow::MacMouseMoved( EventRecord
*ev
, short part
)
1749 WindowPtr frontWindow
;
1754 MacFireMouseEvent( ev
) ;
1759 void wxWindow::MacActivate( EventRecord
*ev
, bool inIsActivating
)
1761 wxActivateEvent
event(wxEVT_ACTIVATE
, inIsActivating
, m_windowId
);
1762 event
.m_timeStamp
= ev
->when
;
1763 event
.SetEventObject(this);
1765 GetEventHandler()->ProcessEvent(event
);
1767 UMAHighlightAndActivateWindow( m_macWindowData
->m_macWindow
, inIsActivating
) ;
1770 void wxWindow::MacRedraw( RgnHandle updatergn
, long time
)
1772 // updatergn is always already clipped to our boundaries
1773 WindowRef window
= GetMacRootWindow() ;
1774 // ownUpdateRgn is the area that this window has to invalidate i.e. its own area without its children
1775 RgnHandle ownUpdateRgn
= NewRgn() ;
1776 CopyRgn( updatergn
, ownUpdateRgn
) ;
1777 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1779 wxMacDrawingHelper
focus( this ) ; // was client
1782 WindowRef window
= GetMacRootWindow() ;
1783 bool eraseBackground
= false ;
1784 if ( m_macWindowData
)
1785 eraseBackground
= true ;
1786 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
1788 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
1790 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1792 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1793 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1794 // either a non gray background color or a non control window
1797 wxWindow
* parent
= GetParent() ;
1800 if ( parent
->GetMacRootWindow() != window
)
1802 // we are in a different window on the mac system
1807 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
1809 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1811 // if we have any other colours in the hierarchy
1812 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
1815 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1816 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
1819 GetRegionBounds( updatergn
, &box
) ;
1820 UMAApplyThemeBackground(kThemeBackgroundTabPane
, &box
, kThemeStateActive
,8,true);
1829 parent
= parent
->GetParent() ;
1833 // if there is nothing special -> use default
1834 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
1839 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
1841 // subtract all non transparent children from updatergn
1843 RgnHandle childarea
= NewRgn() ;
1844 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1846 wxWindow
*child
= (wxWindow
*)node
->Data();
1847 // eventually test for transparent windows
1848 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() )
1850 if ( !child
->IsKindOf( CLASSINFO( wxNotebook
) ) && !child
->IsKindOf( CLASSINFO( wxTabCtrl
) ) )
1852 SetRectRgn( childarea
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1853 DiffRgn( ownUpdateRgn
, childarea
, ownUpdateRgn
) ;
1857 DisposeRgn( childarea
) ;
1859 if ( GetParent() && m_backgroundColour
!= GetParent()->GetBackgroundColour() )
1860 eraseBackground
= true ;
1861 SetClip( updatergn
) ;
1862 if ( m_macEraseOnRedraw
) {
1863 if ( eraseBackground
)
1865 EraseRgn( ownUpdateRgn
) ;
1869 m_macEraseOnRedraw
= true ;
1874 RgnHandle newupdate
= NewRgn() ;
1875 wxSize point
= GetClientSize() ;
1876 wxPoint origin
= GetClientAreaOrigin() ;
1878 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1879 SectRgn( newupdate
, ownUpdateRgn
, newupdate
) ;
1880 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1881 m_updateRegion
= newupdate
;
1882 DisposeRgn( newupdate
) ;
1887 event
.m_timeStamp
= time
;
1888 event
.SetEventObject(this);
1889 GetEventHandler()->ProcessEvent(event
);
1893 RgnHandle childupdate
= NewRgn() ;
1895 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1897 wxWindow
*child
= (wxWindow
*)node
->Data();
1898 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1899 SectRgn( childupdate
, updatergn
, childupdate
) ;
1900 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1901 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1903 // because dialogs may also be children
1904 child
->MacRedraw( childupdate
, time
) ;
1907 DisposeRgn( childupdate
) ;
1908 // eventually a draw grow box here
1911 void wxWindow::MacUpdateImmediately()
1913 WindowRef window
= GetMacRootWindow() ;
1916 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1918 AGAPortHelper
help( GetWindowPort(window
) ) ;
1920 AGAPortHelper
help( (window
) ) ;
1922 SetOrigin( 0 , 0 ) ;
1923 BeginUpdate( window
) ;
1926 RgnHandle region
= NewRgn();
1930 GetPortVisibleRegion( GetWindowPort( window
), region
);
1932 // if windowshade gives incompatibility , take the follwing out
1933 if ( !EmptyRgn( region
) )
1935 win
->MacRedraw( region
, wxTheApp
->sm_lastMessageTime
) ;
1937 DisposeRgn( region
);
1940 EndUpdate( window
) ;
1944 void wxWindow::MacUpdate( EventRecord
*ev
)
1946 WindowRef window
= (WindowRef
) ev
->message
;
1947 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1949 AGAPortHelper
help( GetWindowPort(window
) ) ;
1951 AGAPortHelper
help( (window
) ) ;
1953 SetOrigin( 0 , 0 ) ;
1954 BeginUpdate( window
) ;
1957 RgnHandle region
= NewRgn();
1961 GetPortVisibleRegion( GetWindowPort( window
), region
);
1963 // if windowshade gives incompatibility , take the follwing out
1964 if ( !EmptyRgn( region
) )
1966 MacRedraw( region
, ev
->when
) ;
1968 DisposeRgn( region
);
1971 EndUpdate( window
) ;
1974 WindowRef
wxWindow::GetMacRootWindow() const
1976 WindowRef window
= NULL
;
1977 wxWindow
*iter
= (wxWindow
*)this ;
1981 if ( iter
->m_macWindowData
)
1982 return iter
->m_macWindowData
->m_macWindow
;
1984 iter
= iter
->GetParent() ;
1986 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1990 void wxWindow::MacCreateScrollBars( long style
)
1992 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
1994 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1995 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1997 GetClientSize( &width
, &height
) ;
1999 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2000 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2001 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2002 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2004 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2005 vSize
, wxVERTICAL
);
2007 if ( style
& wxVSCROLL
)
2013 m_vScrollBar
->Show(false) ;
2015 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2016 hSize
, wxHORIZONTAL
);
2017 if ( style
& wxHSCROLL
)
2022 m_hScrollBar
->Show(false) ;
2025 // because the create does not take into account the client area origin
2026 MacRepositionScrollBars() ; // we might have a real position shift
2029 void wxWindow::MacRepositionScrollBars()
2031 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2032 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2034 // get real client area
2036 int width
= m_width
;
2037 int height
= m_height
;
2039 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2040 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2042 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2043 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2044 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2045 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2052 MacClientToRootWindow( &x
, &y
) ;
2053 MacClientToRootWindow( &w
, &h
) ;
2055 WindowRef window
= NULL
;
2056 wxWindow
*iter
= (wxWindow
*)this ;
2058 int totW
= 10000 , totH
= 10000;
2061 if ( iter
->m_macWindowData
)
2063 totW
= iter
->m_width
;
2064 totH
= iter
->m_height
;
2068 iter
= iter
->GetParent() ;
2096 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2100 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2104 void wxWindow::MacKeyDown( EventRecord
*ev
)
2110 bool wxWindow::AcceptsFocus() const
2112 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2115 ControlHandle
wxWindow::MacGetContainerForEmbedding()
2117 if ( m_macWindowData
)
2118 return m_macWindowData
->m_macRootControl
;
2120 return GetParent()->MacGetContainerForEmbedding() ;
2123 void wxWindow::MacSuperChangedPosition()
2125 // only window-absolute structures have to be moved i.e. controls
2127 wxNode
*node
= GetChildren().First();
2130 wxWindow
*child
= (wxWindow
*)node
->Data();
2131 child
->MacSuperChangedPosition() ;
2132 node
= node
->Next();
2136 bool wxWindow::MacSetPortFocusParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
2138 if ( window
== NULL
)
2144 ::GetPort(&currPort
);
2145 port
= UMAGetWindowPort( window
) ;
2146 if (currPort
!= port
)
2149 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2150 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2154 bool wxWindow::MacSetPortDrawingParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
2156 if ( window
== NULL
)
2161 ::GetPort(&currPort
);
2162 port
= UMAGetWindowPort( window
) ;
2163 if (currPort
!= port
)
2165 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2166 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2167 ::ClipRect(&clipRect
);
2170 ::RGBBackColor(& win
->GetBackgroundColour().GetPixel() ) ;
2171 ::RGBForeColor(& win
->GetForegroundColour().GetPixel() ) ;
2172 Pattern whiteColor
;
2174 ::BackPat( GetQDGlobalsWhite( &whiteColor
) ) ;
2175 ::UMASetThemeWindowBackground( win
->m_macWindowData
->m_macWindow
, win
->m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
2179 void wxWindow::MacGetPortParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2181 if ( m_macWindowData
)
2187 clipRect
->right
= m_width
;
2188 clipRect
->bottom
= m_height
;
2189 *window
= m_macWindowData
->m_macWindow
;
2194 wxASSERT( GetParent() != NULL
) ;
2195 GetParent()->MacGetPortParams( localOrigin
, clipRect
, window
, rootwin
) ;
2196 localOrigin
->h
+= m_x
;
2197 localOrigin
->v
+= m_y
;
2198 OffsetRect(clipRect
, -m_x
, -m_y
);
2203 myClip
.right
= m_width
;
2204 myClip
.bottom
= m_height
;
2205 SectRect(clipRect
, &myClip
, clipRect
);
2209 void wxWindow::MacDoGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2211 // int width , height ;
2212 // GetClientSize( &width , &height ) ;
2214 if ( m_macWindowData
)
2220 clipRect
->right
= m_width
;//width;
2221 clipRect
->bottom
= m_height
;// height;
2222 *window
= m_macWindowData
->m_macWindow
;
2227 wxASSERT( GetParent() != NULL
) ;
2229 GetParent()->MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2231 localOrigin
->h
+= m_x
;
2232 localOrigin
->v
+= m_y
;
2233 OffsetRect(clipRect
, -m_x
, -m_y
);
2238 myClip
.right
= m_width
;//width;
2239 myClip
.bottom
= m_height
;// height;
2240 SectRect(clipRect
, &myClip
, clipRect
);
2244 void wxWindow::MacGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2246 MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2248 int width
, height
;
2249 GetClientSize( &width
, &height
) ;
2251 client
= GetClientAreaOrigin( ) ;
2253 localOrigin
->h
+= client
.x
;
2254 localOrigin
->v
+= client
.y
;
2255 OffsetRect(clipRect
, -client
.x
, -client
.y
);
2260 myClip
.right
= width
;
2261 myClip
.bottom
= height
;
2262 SectRect(clipRect
, &myClip
, clipRect
);
2265 long wxWindow::MacGetLeftBorderSize( ) const
2267 if( m_macWindowData
)
2270 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2274 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2278 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2285 long wxWindow::MacGetRightBorderSize( ) const
2287 if( m_macWindowData
)
2290 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2294 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2298 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2305 long wxWindow::MacGetTopBorderSize( ) const
2307 if( m_macWindowData
)
2310 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2314 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2318 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2325 long wxWindow::MacGetBottomBorderSize( ) const
2327 if( m_macWindowData
)
2330 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2334 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2338 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2345 long wxWindow::MacRemoveBordersFromStyle( long style
)
2347 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2351 wxMacDrawingHelper::wxMacDrawingHelper( wxWindow
* theWindow
)
2358 m_currentPort
= NULL
;
2360 GetPort( &m_formerPort
) ;
2363 theWindow
->MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2364 m_currentPort
= UMAGetWindowPort( window
) ;
2365 if ( m_formerPort
!= m_currentPort
)
2366 SetPort( m_currentPort
) ;
2367 GetPenState( &m_savedPenState
) ;
2368 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2373 wxMacDrawingHelper::~wxMacDrawingHelper()
2377 SetPort( m_currentPort
) ;
2378 SetPenState( &m_savedPenState
) ;
2379 SetOrigin( 0 , 0 ) ;
2381 GetPortBounds( m_currentPort
, &portRect
) ;
2382 ClipRect( &portRect
) ;
2385 if ( m_formerPort
!= m_currentPort
)
2386 SetPort( m_formerPort
) ;
2389 wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindow
* theWindow
)
2396 m_currentPort
= NULL
;
2398 GetPort( &m_formerPort
) ;
2402 theWindow
->MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2403 m_currentPort
= UMAGetWindowPort( window
) ;
2404 if ( m_formerPort
!= m_currentPort
)
2405 SetPort( m_currentPort
) ;
2406 GetPenState( &m_savedPenState
) ;
2407 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2412 wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
2416 SetPort( m_currentPort
) ;
2417 SetPenState( &m_savedPenState
) ;
2418 SetOrigin( 0 , 0 ) ;
2420 GetPortBounds( m_currentPort
, &portRect
) ;
2421 ClipRect( &portRect
) ;
2424 if ( m_formerPort
!= m_currentPort
)
2425 SetPort( m_formerPort
) ;
2428 // Find the wxWindow at the current mouse position, returning the mouse
2430 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
2432 pt
= wxGetMousePosition();
2433 wxWindow
* found
= wxFindWindowAtPoint(pt
);
2437 // Get the current mouse position.
2438 wxPoint
wxGetMousePosition()
2441 wxGetMousePosition(& x
, & y
);
2442 return wxPoint(x
, y
);