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 void wxWindow::Init()
116 m_macEraseOnRedraw
= true ;
119 m_doubleClickAllowed
= 0;
120 m_winCaptured
= FALSE
;
122 m_isBeingDeleted
= FALSE
;
125 m_mouseInWindow
= FALSE
;
129 m_backgroundTransparent
= FALSE
;
131 // as all windows are created with WS_VISIBLE style...
134 m_macWindowData
= NULL
;
135 m_macEraseOnRedraw
= true ;
142 m_hScrollBar
= NULL
;
143 m_vScrollBar
= NULL
;
145 #if wxUSE_DRAG_AND_DROP
146 m_pDropTarget
= NULL
;
151 wxWindow::~wxWindow()
153 m_isBeingDeleted
= TRUE
;
155 if ( s_lastMouseWindow
== this )
157 s_lastMouseWindow
= NULL
;
160 if ( gFocusWindow
== this )
162 gFocusWindow
= NULL
;
166 m_parent
->RemoveChild(this);
170 if ( m_macWindowData
)
172 wxToolTip::NotifyWindowDelete(m_macWindowData
->m_macWindow
) ;
173 UMADisposeWindow( m_macWindowData
->m_macWindow
) ;
174 delete m_macWindowData
;
175 wxRemoveMacWindowAssociation( this ) ;
180 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
184 const wxString
& name
)
186 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindow without parent") );
188 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
191 parent
->AddChild(this);
195 AdjustForParentClientOrigin(m_x
, m_y
, wxSIZE_USE_EXISTING
);
196 m_width
= WidthDefault( size
.x
);
197 m_height
= HeightDefault( size
.y
) ;
199 if ( ! IsKindOf( CLASSINFO ( wxControl
) ) && ! IsKindOf( CLASSINFO( wxStatusBar
) ) )
201 MacCreateScrollBars( style
) ;
207 void wxWindow::SetFocus()
209 if ( gFocusWindow
== this )
212 if ( AcceptsFocus() )
218 if ( gFocusWindow
->m_caret
)
220 gFocusWindow
->m_caret
->OnKillFocus();
222 #endif // wxUSE_CARET
223 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
224 if ( control
&& control
->GetMacControl() )
226 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlFocusNoPart
) ;
227 control
->MacRedrawControl() ;
229 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
230 event
.SetEventObject(gFocusWindow
);
231 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
233 gFocusWindow
= this ;
239 m_caret
->OnSetFocus();
241 #endif // wxUSE_CARET
242 // panel wants to track the window which was the last to have focus in it
243 wxPanel
*panel
= wxDynamicCast(GetParent(), wxPanel
);
246 panel
->SetLastFocus(this);
248 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
249 if ( control
&& control
->GetMacControl() )
251 UMASetKeyboardFocus( gFocusWindow
->GetMacRootWindow() , control
->GetMacControl() , kControlEditTextPart
) ;
254 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
255 event
.SetEventObject(this);
256 GetEventHandler()->ProcessEvent(event
) ;
261 bool wxWindow::Enable(bool enable
)
263 if ( !wxWindowBase::Enable(enable
) )
266 wxWindowList::Node
*node
= GetChildren().GetFirst();
269 wxWindow
*child
= node
->GetData();
270 child
->Enable(enable
);
272 node
= node
->GetNext();
278 void wxWindow::CaptureMouse()
280 wxTheApp
->s_captureWindow
= this ;
283 void wxWindow::ReleaseMouse()
285 wxTheApp
->s_captureWindow
= NULL
;
288 #if wxUSE_DRAG_AND_DROP
290 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
292 if ( m_pDropTarget
!= 0 ) {
293 delete m_pDropTarget
;
296 m_pDropTarget
= pDropTarget
;
297 if ( m_pDropTarget
!= 0 )
305 // Old style file-manager drag&drop
306 void wxWindow::DragAcceptFiles(bool accept
)
312 void wxWindow::DoGetSize(int *x
, int *y
) const
318 void wxWindow::DoGetPosition(int *x
, int *y
) const
324 wxPoint
pt(GetParent()->GetClientAreaOrigin());
331 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
333 menu
->SetInvokingWindow(this);
335 ClientToScreen( &x
, &y
) ;
337 ::InsertMenu( menu
->GetHMenu() , -1 ) ;
338 long menuResult
= ::PopUpMenuSelect(menu
->GetHMenu() ,y
,x
, 0) ;
339 menu
->MacMenuSelect( this , TickCount() , HiWord(menuResult
) , LoWord(menuResult
) ) ;
340 ::DeleteMenu( menu
->MacGetMenuId() ) ;
341 menu
->SetInvokingWindow(NULL
);
346 void wxWindow::DoScreenToClient(int *x
, int *y
) const
348 WindowRef window
= GetMacRootWindow() ;
356 ::SetPort( UMAGetWindowPort( window
) ) ;
357 ::GlobalToLocal( &localwhere
) ;
363 MacRootWindowToClient( x
, y
) ;
366 void wxWindow::DoClientToScreen(int *x
, int *y
) const
368 WindowRef window
= GetMacRootWindow() ;
370 MacClientToRootWindow( x
, y
) ;
378 ::SetPort( UMAGetWindowPort( window
) ) ;
379 ::SetOrigin( 0 , 0 ) ;
380 ::LocalToGlobal( &localwhere
) ;
386 void wxWindow::MacClientToRootWindow( int *x
, int *y
) const
388 if ( m_macWindowData
)
395 GetParent()->MacClientToRootWindow( x
, y
) ;
399 void wxWindow::MacRootWindowToClient( int *x
, int *y
) const
401 if ( m_macWindowData
)
408 GetParent()->MacRootWindowToClient( x
, y
) ;
412 bool wxWindow::SetCursor(const wxCursor
& cursor
)
414 if ( !wxWindowBase::SetCursor(cursor
) )
420 wxASSERT_MSG( m_cursor
.Ok(),
421 wxT("cursor must be valid after call to the base version"));
427 // Change the cursor NOW if we're within the correct window
429 if ( MacGetWindowFromPoint( wxPoint( pt
.h
, pt
.v
) , &mouseWin
) )
431 if ( mouseWin
== this && !wxIsBusy() )
433 cursor
.MacInstall() ;
441 // Get size *available for subwindows* i.e. excluding menu bar etc.
442 void wxWindow::DoGetClientSize(int *x
, int *y
) const
447 *x
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
448 *y
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
450 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
457 MacClientToRootWindow( &x1
, &y1
) ;
458 MacClientToRootWindow( &w
, &h
) ;
460 WindowRef window
= NULL
;
461 wxWindow
*iter
= (wxWindow
*)this ;
463 int totW
= 10000 , totH
= 10000;
466 if ( iter
->m_macWindowData
)
468 totW
= iter
->m_width
;
469 totH
= iter
->m_height
;
473 iter
= iter
->GetParent() ;
476 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
478 (*y
) -= MAC_SCROLLBAR_SIZE
;
484 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
486 (*x
) -= MAC_SCROLLBAR_SIZE
;
496 // ----------------------------------------------------------------------------
498 // ----------------------------------------------------------------------------
502 void wxWindow::DoSetToolTip(wxToolTip
*tooltip
)
504 wxWindowBase::DoSetToolTip(tooltip
);
507 m_tooltip
->SetWindow(this);
510 #endif // wxUSE_TOOLTIPS
512 void wxWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
514 DoSetSize( x
,y
, width
, height
) ;
517 // set the size of the window: if the dimensions are positive, just use them,
518 // but if any of them is equal to -1, it means that we must find the value for
519 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
520 // which case -1 is a valid value for x and y)
522 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
523 // the width/height to best suit our contents, otherwise we reuse the current
525 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
530 int former_w
= m_width
;
531 int former_h
= m_height
;
533 int currentX
, currentY
;
534 GetPosition(¤tX
, ¤tY
);
535 int currentW
,currentH
;
536 GetSize(¤tW
, ¤tH
);
538 int actualWidth
= width
;
539 int actualHeight
= height
;
542 if (x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
544 if (y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
547 wxSize
size( -1 , -1 ) ;
549 if (width
== -1 || height
== -1 )
551 size
= DoGetBestSize() ;
556 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
558 actualWidth
= size
.x
;
559 if ( actualWidth
== -1 )
564 actualWidth
= currentW
;
569 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
571 actualHeight
= size
.y
;
572 if ( actualHeight
== -1 )
577 actualHeight
= currentH
;
581 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
582 actualWidth
= m_minWidth
;
583 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
584 actualHeight
= m_minHeight
;
585 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
586 actualWidth
= m_maxWidth
;
587 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
588 actualHeight
= m_maxHeight
;
589 if ( actualX
== currentX
&& actualY
== currentY
&& actualWidth
== currentW
&& actualHeight
== currentH
)
591 MacRepositionScrollBars() ; // we might have a real position shift
595 AdjustForParentClientOrigin(actualX
, actualY
, sizeFlags
);
598 bool doMove
= false ;
599 bool doResize
= false ;
601 if ( actualX
!= former_x
|| actualY
!= former_y
)
605 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
610 if ( doMove
|| doResize
)
612 if ( m_macWindowData
)
617 // erase former position
618 wxMacDrawingHelper
focus( this ) ;
621 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
622 ClipRect( &clientrect
) ;
623 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
628 m_width
= actualWidth
;
629 m_height
= actualHeight
;
630 if ( m_macWindowData
)
633 ::MoveWindow(m_macWindowData
->m_macWindow
, m_x
, m_y
, false); // don't make frontmost
636 ::SizeWindow(m_macWindowData
->m_macWindow
, m_width
, m_height
, true);
638 // the OS takes care of invalidating and erasing the new area
639 // we have erased the old one
641 if ( IsKindOf( CLASSINFO( wxFrame
) ) )
643 wxFrame
* frame
= (wxFrame
*) this ;
644 frame
->PositionStatusBar();
645 frame
->PositionToolBar();
650 // erase new position
653 wxMacDrawingHelper
focus( this ) ;
656 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
657 ClipRect( &clientrect
) ;
658 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
663 wxWindow::MacSuperChangedPosition() ; // like this only children will be notified
665 MacRepositionScrollBars() ;
668 wxMoveEvent
event(wxPoint(m_x
, m_y
), m_windowId
);
669 event
.SetEventObject(this);
670 GetEventHandler()->ProcessEvent(event
) ;
674 MacRepositionScrollBars() ;
675 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
676 event
.SetEventObject(this);
677 GetEventHandler()->ProcessEvent(event
);
681 // For implementation purposes - sometimes decorations make the client area
684 wxPoint
wxWindow::GetClientAreaOrigin() const
686 return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
689 // Makes an adjustment to the window position (for example, a frame that has
690 // a toolbar that it manages itself).
691 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
693 if( !m_macWindowData
)
695 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
697 wxPoint
pt(GetParent()->GetClientAreaOrigin());
698 x
+= pt
.x
; y
+= pt
.y
;
703 void wxWindow::SetTitle(const wxString
& title
)
709 if( wxApp::s_macDefaultEncodingIsPC
)
710 label
= wxMacMakeMacStringFromPC( title
) ;
714 if ( m_macWindowData
)
715 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
718 wxString
wxWindow::GetTitle() const
723 bool wxWindow::Show(bool show
)
725 if ( !wxWindowBase::Show(show
) )
728 if ( m_macWindowData
)
732 UMAShowWindow( m_macWindowData
->m_macWindow
) ;
733 UMASelectWindow( m_macWindowData
->m_macWindow
) ;
734 // no need to generate events here, they will get them triggered by macos
735 // actually they should be , but apparently they are not
736 wxSizeEvent
event(wxSize(m_width
, m_height
), m_windowId
);
737 event
.SetEventObject(this);
738 GetEventHandler()->ProcessEvent(event
);
742 UMAHideWindow( m_macWindowData
->m_macWindow
) ;
745 MacSuperShown( show
) ;
748 MacUpdateImmediately() ;
753 void wxWindow::MacSuperShown( bool show
)
755 wxNode
*node
= GetChildren().First();
758 wxWindow
*child
= (wxWindow
*)node
->Data();
759 if ( child
->m_isShown
)
760 child
->MacSuperShown( show
) ;
765 bool wxWindow::MacIsReallyShown() const
767 if ( m_isShown
&& (m_parent
!= NULL
) ) {
768 return m_parent
->MacIsReallyShown();
772 bool status = m_isShown ;
773 wxWindow * win = this ;
774 while ( status && win->m_parent != NULL )
776 win = win->m_parent ;
777 status = win->m_isShown ;
783 int wxWindow::GetCharHeight() const
785 wxClientDC
dc ( (wxWindow
*)this ) ;
786 return dc
.GetCharHeight() ;
789 int wxWindow::GetCharWidth() const
791 wxClientDC
dc ( (wxWindow
*)this ) ;
792 return dc
.GetCharWidth() ;
795 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
796 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
798 const wxFont
*fontToUse
= theFont
;
802 wxClientDC
dc( (wxWindow
*) this ) ;
804 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
805 if ( externalLeading
)
806 *externalLeading
= le
;
815 void wxWindow::MacEraseBackground( Rect
*rect
)
818 WindowRef window = GetMacRootWindow() ;
819 if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
821 UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ;
823 else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
825 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
826 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
827 // either a non gray background color or a non control window
829 wxWindow* parent = GetParent() ;
832 if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
834 // if we have any other colours in the hierarchy
835 RGBBackColor( &parent->m_backgroundColour.GetPixel()) ;
838 if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() )
840 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
841 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
843 UMAApplyThemeBackground(kThemeBackgroundTabPane, rect, kThemeStateActive,8,true);
849 // we have arrived at a non control item
853 parent = parent->GetParent() ;
857 // if there is nothing special -> use default
858 UMASetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ;
863 RGBBackColor( &m_backgroundColour.GetPixel()) ;
868 for (wxNode *node = GetChildren().First(); node; node = node->Next())
870 wxWindow *child = (wxWindow*)node->Data();
872 Rect clientrect = { child->m_x , child->m_y , child->m_x +child->m_width , child->m_y + child->m_height } ;
873 SectRect( &clientrect , rect , &clientrect ) ;
875 OffsetRect( &clientrect , -child->m_x , -child->m_y ) ;
876 if ( child->GetMacRootWindow() == window && child->IsShown() )
878 wxMacDrawingClientHelper focus( this ) ;
881 child->MacEraseBackground( &clientrect ) ;
888 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
890 wxMacDrawingHelper
focus( this ) ;
893 Rect clientrect
= { 0 , 0 , m_height
, m_width
} ;
894 ClipRect( &clientrect
) ;
898 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
899 SectRect( &clientrect
, &r
, &clientrect
) ;
901 InvalWindowRect( GetMacRootWindow() , &clientrect
) ;
905 // Responds to colour changes: passes event on to children.
906 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
908 wxNode
*node
= GetChildren().First();
911 // Only propagate to non-top-level windows
912 wxWindow
*win
= (wxWindow
*)node
->Data();
913 if ( win
->GetParent() )
915 wxSysColourChangedEvent event2
;
916 event
.m_eventObject
= win
;
917 win
->GetEventHandler()->ProcessEvent(event2
);
924 #if wxUSE_CARET && WXWIN_COMPATIBILITY
925 // ---------------------------------------------------------------------------
926 // Caret manipulation
927 // ---------------------------------------------------------------------------
929 void wxWindow::CreateCaret(int w
, int h
)
931 SetCaret(new wxCaret(this, w
, h
));
934 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
936 wxFAIL_MSG("not implemented");
939 void wxWindow::ShowCaret(bool show
)
941 wxCHECK_RET( m_caret
, "no caret to show" );
946 void wxWindow::DestroyCaret()
951 void wxWindow::SetCaretPos(int x
, int y
)
953 wxCHECK_RET( m_caret
, "no caret to move" );
958 void wxWindow::GetCaretPos(int *x
, int *y
) const
960 wxCHECK_RET( m_caret
, "no caret to get position of" );
962 m_caret
->GetPosition(x
, y
);
964 #endif // wxUSE_CARET
966 wxWindow
*wxGetActiveWindow()
968 // actually this is a windows-only concept
972 // Coordinates relative to the window
973 void wxWindow::WarpPointer (int x_pos
, int y_pos
)
975 // We really dont move the mouse programmatically under mac
978 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
980 // TODO : probably we would adopt the EraseEvent structure
983 int wxWindow::GetScrollPos(int orient
) const
985 if ( orient
== wxHORIZONTAL
)
988 return m_hScrollBar
->GetThumbPosition() ;
993 return m_vScrollBar
->GetThumbPosition() ;
998 // This now returns the whole range, not just the number
999 // of positions that we can scroll.
1000 int wxWindow::GetScrollRange(int orient
) const
1002 if ( orient
== wxHORIZONTAL
)
1005 return m_hScrollBar
->GetRange() ;
1010 return m_vScrollBar
->GetRange() ;
1015 int wxWindow::GetScrollThumb(int orient
) const
1017 if ( orient
== wxHORIZONTAL
)
1020 return m_hScrollBar
->GetThumbSize() ;
1025 return m_vScrollBar
->GetThumbSize() ;
1030 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
1032 if ( orient
== wxHORIZONTAL
)
1035 m_hScrollBar
->SetThumbPosition( pos
) ;
1040 m_vScrollBar
->SetThumbPosition( pos
) ;
1044 void wxWindow::MacCreateRealWindow( const wxString
& title
,
1048 const wxString
& name
)
1051 m_windowStyle
= style
;
1072 m_macWindowData
= new MacWindowData() ;
1074 ::SetRect(&theBoundsRect
, m_x
, m_y
, m_x
+ m_width
, m_y
+ m_height
);
1076 // translate the window attributes in the appropriate window class and attributes
1078 WindowClass wclass
= 0;
1079 WindowAttributes attr
= kWindowNoAttributes
;
1081 if ( HasFlag(wxTINY_CAPTION_HORIZ
) || HasFlag(wxTINY_CAPTION_VERT
) )
1083 wclass
= kFloatingWindowClass
;
1084 if ( HasFlag(wxTINY_CAPTION_VERT
) )
1086 attr
|= kWindowSideTitlebarAttribute
;
1089 else if ( HasFlag( wxCAPTION
) )
1091 if ( HasFlag( wxDIALOG_MODAL
) )
1093 wclass
= kMovableModalWindowClass
;
1097 wclass
= kDocumentWindowClass
;
1102 wclass
= kModalWindowClass
;
1105 if ( HasFlag( wxMINIMIZE_BOX
) || HasFlag( wxMAXIMIZE_BOX
) )
1107 attr
|= kWindowFullZoomAttribute
;
1108 attr
|= kWindowCollapseBoxAttribute
;
1110 if ( HasFlag( wxRESIZE_BORDER
) )
1112 attr
|= kWindowResizableAttribute
;
1114 if ( HasFlag( wxSYSTEM_MENU
) )
1116 attr
|= kWindowCloseBoxAttribute
;
1119 UMACreateNewWindow( wclass
, attr
, &theBoundsRect
, &m_macWindowData
->m_macWindow
) ;
1120 wxAssociateWinWithMacWindow( m_macWindowData
->m_macWindow
, this ) ;
1122 if( wxApp::s_macDefaultEncodingIsPC
)
1123 label
= wxMacMakeMacStringFromPC( title
) ;
1126 UMASetWTitleC( m_macWindowData
->m_macWindow
, label
) ;
1127 UMACreateRootControl( m_macWindowData
->m_macWindow
, &m_macWindowData
->m_macRootControl
) ;
1129 m_macWindowData
->m_macFocus
= NULL
;
1132 void wxWindow::MacPaint( wxPaintEvent
&event
)
1136 void wxWindow::MacPaintBorders( )
1138 if( m_macWindowData
)
1141 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1142 RGBColor black
= { 0x0000, 0x0000 , 0x0000 } ;
1143 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1144 RGBColor shadow
= { 0x4444, 0x4444 , 0x4444 } ;
1147 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1149 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1150 RGBColor pen1
= sunken
? white
: black
;
1151 RGBColor pen2
= sunken
? shadow
: face
;
1152 RGBColor pen3
= sunken
? face
: shadow
;
1153 RGBColor pen4
= sunken
? black
: white
;
1155 RGBForeColor( &pen1
) ;
1157 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1158 FrameRect( &rect
) ;
1160 RGBForeColor( &pen2
) ;
1162 Rect rect
= { 1 , 1 , m_height
-1 , m_width
-1} ;
1163 FrameRect( &rect
) ;
1165 RGBForeColor( &pen3
) ;
1167 Rect rect
= { 0 , 0 , m_height
-2 , m_width
-2} ;
1168 FrameRect( &rect
) ;
1170 RGBForeColor( &pen4
) ;
1173 LineTo( m_width
- 3 , 0 ) ;
1175 LineTo( 0 , m_height
- 3 ) ;
1178 else if (HasFlag(wxSIMPLE_BORDER
))
1180 Rect rect
= { 0 , 0 , m_height
, m_width
} ;
1181 RGBForeColor( &black
) ;
1182 FrameRect( &rect
) ;
1185 if ( this->GetParent() )
1187 wxPaintDC dc(GetParent());
1188 GetParent()->PrepareDC(dc);
1190 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) )
1192 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1194 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1195 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1197 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1198 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1199 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1200 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1203 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1206 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1209 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1212 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1213 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1215 else if (HasFlag(wxDOUBLE_BORDER))
1217 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
1219 wxPen m_penButton3DShadow( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DSHADOW ), 1, wxSOLID ) ;
1220 wxPen m_penButton3DFace( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_3DFACE ), 1, wxSOLID ) ;
1222 wxPen wxPen1 = sunken ? *wxWHITE_PEN : *wxBLACK_PEN;
1223 wxPen wxPen2 = sunken ? m_penButton3DShadow : m_penButton3DShadow;
1224 wxPen wxPen3 = sunken ? m_penButton3DFace : m_penButton3DShadow;
1225 wxPen wxPen4 = sunken ? *wxBLACK_PEN : *wxWHITE_PEN;
1228 dc.DrawRectangle(m_x, m_y, m_width, m_height); // outer - right and button
1231 dc.DrawRectangle(m_x+1, m_y+1, m_width-1, m_height-1); // outer - left and top
1234 dc.DrawRectangle(m_x, m_y, m_width-2, m_height-2); // inner - right and button
1237 dc.DrawLine(m_x, m_y, m_x + m_width-3, m_y); // inner - left and top
1238 dc.DrawLine(m_x, m_y, m_x, m_y + m_height-3);
1240 else if (HasFlag(wxSIMPLE_BORDER))
1242 dc.SetPen(*wxBLACK_PEN);
1243 dc.DrawRectangle(m_x, m_y, m_width, m_height);
1249 // New function that will replace some of the above.
1250 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1251 int range
, bool refresh
)
1253 if ( orient
== wxHORIZONTAL
)
1257 if ( range
== 0 || thumbVisible
>= range
)
1259 if ( m_hScrollBar
->IsShown() )
1260 m_hScrollBar
->Show(false) ;
1264 if ( !m_hScrollBar
->IsShown() )
1265 m_hScrollBar
->Show(true) ;
1266 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, refresh
) ;
1274 if ( range
== 0 || thumbVisible
>= range
)
1276 if ( m_vScrollBar
->IsShown() )
1277 m_vScrollBar
->Show(false) ;
1281 if ( !m_vScrollBar
->IsShown() )
1282 m_vScrollBar
->Show(true) ;
1283 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, refresh
) ;
1287 MacRepositionScrollBars() ;
1290 // Does a physical scroll
1291 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1293 wxMacDrawingClientHelper
focus( this ) ;
1296 int width
, height
;
1297 GetClientSize( &width
, &height
) ;
1299 Rect scrollrect
= { 0 , 0 , height
, width
} ;
1301 RgnHandle updateRgn
= NewRgn() ;
1302 ClipRect( &scrollrect
) ;
1305 Rect r
= { rect
->y
, rect
->x
, rect
->y
+ rect
->height
, rect
->x
+ rect
->width
} ;
1306 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1308 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1309 InvalWindowRgn( GetMacRootWindow() , updateRgn
) ;
1310 DisposeRgn( updateRgn
) ;
1313 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1315 wxWindow
*child
= (wxWindow
*)node
->Data();
1316 if (child
== m_vScrollBar
) continue;
1317 if (child
== m_hScrollBar
) continue;
1318 if (child
->IsTopLevel()) continue;
1320 child
->GetPosition( &x
, &y
);
1322 child
->GetSize( &w
, &h
);
1323 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
1328 void wxWindow::MacOnScroll(wxScrollEvent
&event
)
1330 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
1332 wxScrollWinEvent wevent
;
1333 wevent
.SetPosition(event
.GetPosition());
1334 wevent
.SetOrientation(event
.GetOrientation());
1335 wevent
.m_eventObject
= this;
1337 if (event
.m_eventType
== wxEVT_SCROLL_TOP
) {
1338 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
1340 if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
) {
1341 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1343 if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
) {
1344 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
1346 if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
) {
1347 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1349 if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
) {
1350 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1352 if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
) {
1353 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1355 if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
) {
1356 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1359 GetEventHandler()->ProcessEvent(wevent
);
1363 bool wxWindow::SetFont(const wxFont
& font
)
1365 if ( !wxWindowBase::SetFont(font
) )
1374 // Get the window with the focus
1375 wxWindow
*wxWindowBase::FindFocus()
1377 return gFocusWindow
;
1380 #if WXWIN_COMPATIBILITY
1381 // If nothing defined for this, try the parent.
1382 // E.g. we may be a button loaded from a resource, with no callback function
1384 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1386 if ( GetEventHandler()->ProcessEvent(event
) )
1389 m_parent
->GetEventHandler()->OnCommand(win
, event
);
1391 #endif // WXWIN_COMPATIBILITY_2
1393 #if WXWIN_COMPATIBILITY
1394 wxObject
* wxWindow::GetChild(int number
) const
1396 // Return a pointer to the Nth object in the Panel
1397 wxNode
*node
= GetChildren().First();
1400 node
= node
->Next();
1403 wxObject
*obj
= (wxObject
*)node
->Data();
1409 #endif // WXWIN_COMPATIBILITY
1411 void wxWindow::OnSetFocus(wxFocusEvent
& event
)
1413 // panel wants to track the window which was the last to have focus in it,
1414 // so we want to set ourselves as the window which last had focus
1416 // notice that it's also important to do it upwards the tree becaus
1417 // otherwise when the top level panel gets focus, it won't set it back to
1418 // us, but to some other sibling
1419 wxWindow
*win
= this;
1422 wxWindow
*parent
= win
->GetParent();
1423 wxPanel
*panel
= wxDynamicCast(parent
, wxPanel
);
1426 panel
->SetLastFocus(win
);
1435 void wxWindow::Clear()
1437 if ( m_macWindowData
)
1439 wxMacDrawingClientHelper
helper ( this ) ;
1441 wxPoint origin
= GetClientAreaOrigin() ;
1442 GetClientSize( &w
, &h
) ;
1443 UMASetThemeWindowBackground( m_macWindowData
->m_macWindow
, m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
1444 Rect r
= { origin
.y
, origin
.x
, origin
.y
+h
, origin
.x
+w
} ;
1449 wxClientDC
dc(this);
1450 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1451 dc
.SetBackground(brush
);
1456 // Setup background and foreground colours correctly
1457 void wxWindow::SetupColours()
1460 SetBackgroundColour(GetParent()->GetBackgroundColour());
1463 void wxWindow::OnIdle(wxIdleEvent
& event
)
1466 // Check if we need to send a LEAVE event
1467 if (m_mouseInWindow)
1470 ::GetCursorPos(&pt);
1471 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1473 // Generate a LEAVE event
1474 m_mouseInWindow = FALSE;
1475 MSWOnMouseLeave(pt.x, pt.y, 0);
1480 // This calls the UI-update mechanism (querying windows for
1481 // menu/toolbar/control state information)
1485 // Raise the window to the top of the Z order
1486 void wxWindow::Raise()
1491 // Lower the window to the bottom of the Z order
1492 void wxWindow::Lower()
1497 void wxWindow::DoSetClientSize(int width
, int height
)
1499 if ( width
!= -1 || height
!= -1 )
1502 if ( width
!= -1 && m_vScrollBar
)
1503 width
+= MAC_SCROLLBAR_SIZE
;
1504 if ( height
!= -1 && m_vScrollBar
)
1505 height
+= MAC_SCROLLBAR_SIZE
;
1507 width
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1508 height
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1510 DoSetSize( -1 , -1 , width
, height
) ;
1515 wxWindow
* wxWindow::s_lastMouseWindow
= NULL
;
1517 bool wxWindow::MacGetWindowFromPointSub( const wxPoint
&point
, wxWindow
** outWin
)
1519 if ((point
.x
< m_x
) || (point
.y
< m_y
) ||
1520 (point
.x
> (m_x
+ m_width
)) || (point
.y
> (m_y
+ m_height
)))
1523 WindowRef window
= GetMacRootWindow() ;
1525 wxPoint
newPoint( point
) ;
1530 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1532 wxWindow
*child
= (wxWindow
*)node
->Data();
1533 // added the m_isShown test --dmazzoni
1534 if ( child
->GetMacRootWindow() == window
&& child
->m_isShown
)
1536 if (child
->MacGetWindowFromPointSub(newPoint
, outWin
))
1545 bool wxWindow::MacGetWindowFromPoint( const wxPoint
&screenpoint
, wxWindow
** outWin
)
1548 Point pt
= { screenpoint
.y
, screenpoint
.x
} ;
1549 if ( ::FindWindow( pt
, &window
) == 3 )
1551 wxPoint
point( screenpoint
) ;
1552 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1555 win
->ScreenToClient( point
) ;
1556 return win
->MacGetWindowFromPointSub( point
, outWin
) ;
1562 extern int wxBusyCursorCount
;
1564 bool wxWindow::MacDispatchMouseEvent(wxMouseEvent
& event
)
1566 if ((event
.m_x
< m_x
) || (event
.m_y
< m_y
) ||
1567 (event
.m_x
> (m_x
+ m_width
)) || (event
.m_y
> (m_y
+ m_height
)))
1571 if ( IsKindOf( CLASSINFO ( wxStaticBox
) ) )
1574 WindowRef window
= GetMacRootWindow() ;
1582 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1584 wxWindow
*child
= (wxWindow
*)node
->Data();
1585 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && child
->IsEnabled() )
1587 if (child
->MacDispatchMouseEvent(event
))
1595 if ( wxBusyCursorCount
== 0 )
1597 m_cursor
.MacInstall() ;
1600 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
1602 // set focus to this window
1603 if (AcceptsFocus() && FindFocus()!=this)
1608 if ( event
.GetEventType() == wxEVT_MOTION
1609 || event
.GetEventType() == wxEVT_ENTER_WINDOW
1610 || event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
1611 wxToolTip::RelayEvent( this , event
);
1612 #endif // wxUSE_TOOLTIPS
1613 GetEventHandler()->ProcessEvent( event
) ;
1620 wxString
wxWindow::MacGetToolTipString( wxPoint
&pt
)
1624 return m_tooltip
->GetTip() ;
1628 void wxWindow::MacFireMouseEvent( EventRecord
*ev
)
1630 wxMouseEvent
event(wxEVT_LEFT_DOWN
);
1631 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1632 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1634 event
.m_leftDown
= isDown
&& !controlDown
;
1635 event
.m_middleDown
= FALSE
;
1636 event
.m_rightDown
= isDown
&& controlDown
;
1638 if ( ev
->what
== mouseDown
)
1641 event
.SetEventType(wxEVT_RIGHT_DOWN
) ;
1643 event
.SetEventType(wxEVT_LEFT_DOWN
) ;
1645 else if ( ev
->what
== mouseUp
)
1648 event
.SetEventType(wxEVT_RIGHT_UP
) ;
1650 event
.SetEventType(wxEVT_LEFT_UP
) ;
1654 event
.SetEventType(wxEVT_MOTION
) ;
1657 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1658 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1659 event
.m_altDown
= ev
->modifiers
& optionKey
;
1660 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1662 Point localwhere
= ev
->where
;
1665 ::GetPort( &port
) ;
1666 ::SetPort( UMAGetWindowPort( m_macWindowData
->m_macWindow
) ) ;
1667 ::GlobalToLocal( &localwhere
) ;
1670 if ( ev
->what
== mouseDown
)
1672 if ( ev
->when
- lastWhen
<= GetDblTime() )
1674 if ( abs( localwhere
.h
- lastWhere
.h
) < 3 || abs( localwhere
.v
- lastWhere
.v
) < 3 )
1677 event
.SetEventType(wxEVT_RIGHT_DCLICK
) ;
1679 event
.SetEventType(wxEVT_LEFT_DCLICK
) ;
1682 lastWhen
= ev
->when
;
1683 lastWhere
= localwhere
;
1686 event
.m_x
= localwhere
.h
;
1687 event
.m_y
= localwhere
.v
;
1692 wxPoint origin = GetClientAreaOrigin() ;
1694 event.m_x += origin.x ;
1695 event.m_y += origin.y ;
1698 event
.m_timeStamp
= ev
->when
;
1699 event
.SetEventObject(this);
1700 if ( wxTheApp
->s_captureWindow
)
1704 wxTheApp
->s_captureWindow
->ScreenToClient( &x
, &y
) ;
1707 wxTheApp
->s_captureWindow
->GetEventHandler()->ProcessEvent( event
) ;
1708 if ( ev
->what
== mouseUp
)
1710 wxTheApp
->s_captureWindow
= NULL
;
1711 if ( wxBusyCursorCount
== 0 )
1713 m_cursor
.MacInstall() ;
1719 MacDispatchMouseEvent( event
) ;
1723 void wxWindow::MacMouseDown( EventRecord
*ev
, short part
)
1725 MacFireMouseEvent( ev
) ;
1728 void wxWindow::MacMouseUp( EventRecord
*ev
, short part
)
1730 WindowPtr frontWindow
;
1735 MacFireMouseEvent( ev
) ;
1741 void wxWindow::MacMouseMoved( EventRecord
*ev
, short part
)
1743 WindowPtr frontWindow
;
1748 MacFireMouseEvent( ev
) ;
1753 void wxWindow::MacActivate( EventRecord
*ev
, bool inIsActivating
)
1755 wxActivateEvent
event(wxEVT_ACTIVATE
, inIsActivating
, m_windowId
);
1756 event
.m_timeStamp
= ev
->when
;
1757 event
.SetEventObject(this);
1759 GetEventHandler()->ProcessEvent(event
);
1761 UMAHighlightAndActivateWindow( m_macWindowData
->m_macWindow
, inIsActivating
) ;
1764 void wxWindow::MacRedraw( RgnHandle updatergn
, long time
)
1766 // updatergn is always already clipped to our boundaries
1767 WindowRef window
= GetMacRootWindow() ;
1768 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1770 wxMacDrawingHelper
focus( this ) ; // was client
1773 WindowRef window
= GetMacRootWindow() ;
1774 bool eraseBackground
= false ;
1775 if ( m_macWindowData
)
1776 eraseBackground
= true ;
1777 if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
) )
1779 UMASetThemeWindowBackground( window
, kThemeBrushDocumentWindowBackground
, false ) ;
1781 else if ( m_backgroundColour
== wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1783 // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
1784 // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
1785 // either a non gray background color or a non control window
1788 wxWindow
* parent
= GetParent() ;
1791 if ( parent
->GetMacRootWindow() != window
)
1793 // we are in a different window on the mac system
1798 if( parent
->IsKindOf( CLASSINFO( wxControl
) ) && ((wxControl
*)parent
)->GetMacControl() )
1800 if ( parent
->m_backgroundColour
!= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) )
1802 // if we have any other colours in the hierarchy
1803 RGBBackColor( &parent
->m_backgroundColour
.GetPixel()) ;
1806 // if we have the normal colours in the hierarchy but another control etc. -> use it's background
1807 if ( parent
->IsKindOf( CLASSINFO( wxNotebook
) ) || parent
->IsKindOf( CLASSINFO( wxTabCtrl
) ))
1810 GetRegionBounds( updatergn
, &box
) ;
1811 UMAApplyThemeBackground(kThemeBackgroundTabPane
, &box
, kThemeStateActive
,8,true);
1820 parent
= parent
->GetParent() ;
1824 // if there is nothing special -> use default
1825 UMASetThemeWindowBackground( window
, kThemeBrushDialogBackgroundActive
, false ) ;
1830 RGBBackColor( &m_backgroundColour
.GetPixel()) ;
1832 if ( GetParent() && m_backgroundColour
!= GetParent()->GetBackgroundColour() )
1833 eraseBackground
= true ;
1834 SetClip( updatergn
) ;
1835 if ( eraseBackground
&& m_macEraseOnRedraw
)
1837 // todo : find a clever algorithm, which only will do this
1838 // if really necessary
1839 EraseRgn( updatergn
) ;
1843 m_macUpdateRgn
= updatergn
;
1845 RgnHandle newupdate
= NewRgn() ;
1846 wxSize point
= GetClientSize() ;
1847 wxPoint origin
= GetClientAreaOrigin() ;
1849 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
1850 SectRgn( newupdate
, m_macUpdateRgn
, newupdate
) ;
1851 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1852 m_updateRegion
= newupdate
;
1853 DisposeRgn( newupdate
) ;
1858 event
.m_timeStamp
= time
;
1859 event
.SetEventObject(this);
1860 GetEventHandler()->ProcessEvent(event
);
1864 RgnHandle childupdate
= NewRgn() ;
1866 for (wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
1868 wxWindow
*child
= (wxWindow
*)node
->Data();
1869 SetRectRgn( childupdate
, child
->m_x
, child
->m_y
, child
->m_x
+ child
->m_width
, child
->m_y
+ child
->m_height
) ;
1870 SectRgn( childupdate
, m_macUpdateRgn
, childupdate
) ;
1871 OffsetRgn( childupdate
, -child
->m_x
, -child
->m_y
) ;
1872 if ( child
->GetMacRootWindow() == window
&& child
->IsShown() && !EmptyRgn( childupdate
) )
1874 // because dialogs may also be children
1875 child
->MacRedraw( childupdate
, time
) ;
1878 DisposeRgn( childupdate
) ;
1879 // eventually a draw grow box here
1882 void wxWindow::MacUpdateImmediately()
1884 WindowRef window
= GetMacRootWindow() ;
1887 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1889 AGAPortHelper
help( GetWindowPort(window
) ) ;
1891 AGAPortHelper
help( (window
) ) ;
1893 SetOrigin( 0 , 0 ) ;
1894 BeginUpdate( window
) ;
1897 RgnHandle region
= NewRgn();
1901 GetPortVisibleRegion( GetWindowPort( window
), region
);
1903 // if windowshade gives incompatibility , take the follwing out
1904 if ( !EmptyRgn( region
) )
1906 win
->MacRedraw( region
, wxTheApp
->sm_lastMessageTime
) ;
1908 DisposeRgn( region
);
1911 EndUpdate( window
) ;
1915 void wxWindow::MacUpdate( EventRecord
*ev
)
1917 WindowRef window
= (WindowRef
) ev
->message
;
1918 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1920 AGAPortHelper
help( GetWindowPort(window
) ) ;
1922 AGAPortHelper
help( (window
) ) ;
1924 SetOrigin( 0 , 0 ) ;
1925 BeginUpdate( window
) ;
1928 RgnHandle region
= NewRgn();
1932 GetPortVisibleRegion( GetWindowPort( window
), region
);
1934 // if windowshade gives incompatibility , take the follwing out
1935 if ( !EmptyRgn( region
) )
1937 MacRedraw( region
, ev
->when
) ;
1939 DisposeRgn( region
);
1942 EndUpdate( window
) ;
1945 WindowRef
wxWindow::GetMacRootWindow() const
1947 WindowRef window
= NULL
;
1948 wxWindow
*iter
= (wxWindow
*)this ;
1952 if ( iter
->m_macWindowData
)
1953 return iter
->m_macWindowData
->m_macWindow
;
1955 iter
= iter
->GetParent() ;
1957 wxASSERT_MSG( 1 , "No valid mac root window" ) ;
1961 void wxWindow::MacCreateScrollBars( long style
)
1963 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, "attempt to create window twice" ) ;
1965 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
1966 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
1968 GetClientSize( &width
, &height
) ;
1970 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
1971 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
1972 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
1973 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
1975 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
1976 vSize
, wxVERTICAL
);
1978 if ( style
& wxVSCROLL
)
1984 m_vScrollBar
->Show(false) ;
1986 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
1987 hSize
, wxHORIZONTAL
);
1988 if ( style
& wxHSCROLL
)
1993 m_hScrollBar
->Show(false) ;
1996 // because the create does not take into account the client area origin
1997 MacRepositionScrollBars() ; // we might have a real position shift
2000 void wxWindow::MacRepositionScrollBars()
2002 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2003 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2005 // get real client area
2007 int width
= m_width
;
2008 int height
= m_height
;
2010 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2011 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2013 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2014 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2015 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2016 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2023 MacClientToRootWindow( &x
, &y
) ;
2024 MacClientToRootWindow( &w
, &h
) ;
2026 WindowRef window
= NULL
;
2027 wxWindow
*iter
= (wxWindow
*)this ;
2029 int totW
= 10000 , totH
= 10000;
2032 if ( iter
->m_macWindowData
)
2034 totW
= iter
->m_width
;
2035 totH
= iter
->m_height
;
2039 iter
= iter
->GetParent() ;
2067 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2071 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2075 void wxWindow::MacKeyDown( EventRecord
*ev
)
2081 bool wxWindow::AcceptsFocus() const
2083 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2086 ControlHandle
wxWindow::MacGetContainerForEmbedding()
2088 if ( m_macWindowData
)
2089 return m_macWindowData
->m_macRootControl
;
2091 return GetParent()->MacGetContainerForEmbedding() ;
2094 void wxWindow::MacSuperChangedPosition()
2096 // only window-absolute structures have to be moved i.e. controls
2098 wxNode
*node
= GetChildren().First();
2101 wxWindow
*child
= (wxWindow
*)node
->Data();
2102 child
->MacSuperChangedPosition() ;
2103 node
= node
->Next();
2107 bool wxWindow::MacSetPortFocusParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
2109 if ( window
== NULL
)
2115 ::GetPort(&currPort
);
2116 port
= UMAGetWindowPort( window
) ;
2117 if (currPort
!= port
)
2120 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2121 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2125 bool wxWindow::MacSetPortDrawingParams( const Point
& localOrigin
, const Rect
& clipRect
, WindowRef window
, wxWindow
* win
)
2127 if ( window
== NULL
)
2132 ::GetPort(&currPort
);
2133 port
= UMAGetWindowPort( window
) ;
2134 if (currPort
!= port
)
2136 // wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
2137 ::SetOrigin(-localOrigin
.h
, -localOrigin
.v
);
2138 ::ClipRect(&clipRect
);
2141 ::RGBBackColor(& win
->GetBackgroundColour().GetPixel() ) ;
2142 ::RGBForeColor(& win
->GetForegroundColour().GetPixel() ) ;
2143 Pattern whiteColor
;
2145 ::BackPat( GetQDGlobalsWhite( &whiteColor
) ) ;
2146 ::UMASetThemeWindowBackground( win
->m_macWindowData
->m_macWindow
, win
->m_macWindowData
->m_macWindowBackgroundTheme
, false ) ;
2150 void wxWindow::MacGetPortParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2152 if ( m_macWindowData
)
2158 clipRect
->right
= m_width
;
2159 clipRect
->bottom
= m_height
;
2160 *window
= m_macWindowData
->m_macWindow
;
2165 wxASSERT( GetParent() != NULL
) ;
2166 GetParent()->MacGetPortParams( localOrigin
, clipRect
, window
, rootwin
) ;
2167 localOrigin
->h
+= m_x
;
2168 localOrigin
->v
+= m_y
;
2169 OffsetRect(clipRect
, -m_x
, -m_y
);
2174 myClip
.right
= m_width
;
2175 myClip
.bottom
= m_height
;
2176 SectRect(clipRect
, &myClip
, clipRect
);
2180 void wxWindow::MacDoGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2182 // int width , height ;
2183 // GetClientSize( &width , &height ) ;
2185 if ( m_macWindowData
)
2191 clipRect
->right
= m_width
;//width;
2192 clipRect
->bottom
= m_height
;// height;
2193 *window
= m_macWindowData
->m_macWindow
;
2198 wxASSERT( GetParent() != NULL
) ;
2200 GetParent()->MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2202 localOrigin
->h
+= m_x
;
2203 localOrigin
->v
+= m_y
;
2204 OffsetRect(clipRect
, -m_x
, -m_y
);
2209 myClip
.right
= m_width
;//width;
2210 myClip
.bottom
= m_height
;// height;
2211 SectRect(clipRect
, &myClip
, clipRect
);
2215 void wxWindow::MacGetPortClientParams(Point
* localOrigin
, Rect
* clipRect
, WindowRef
*window
, wxWindow
** rootwin
)
2217 MacDoGetPortClientParams( localOrigin
, clipRect
, window
, rootwin
) ;
2219 int width
, height
;
2220 GetClientSize( &width
, &height
) ;
2222 client
= GetClientAreaOrigin( ) ;
2224 localOrigin
->h
+= client
.x
;
2225 localOrigin
->v
+= client
.y
;
2226 OffsetRect(clipRect
, -client
.x
, -client
.y
);
2231 myClip
.right
= width
;
2232 myClip
.bottom
= height
;
2233 SectRect(clipRect
, &myClip
, clipRect
);
2236 long wxWindow::MacGetLeftBorderSize( ) const
2238 if( m_macWindowData
)
2241 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2245 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2249 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2256 long wxWindow::MacGetRightBorderSize( ) const
2258 if( m_macWindowData
)
2261 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2265 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2269 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2276 long wxWindow::MacGetTopBorderSize( ) const
2278 if( m_macWindowData
)
2281 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2285 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2289 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2296 long wxWindow::MacGetBottomBorderSize( ) const
2298 if( m_macWindowData
)
2301 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2305 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2309 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2316 long wxWindow::MacRemoveBordersFromStyle( long style
)
2318 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2322 wxMacDrawingHelper::wxMacDrawingHelper( wxWindow
* theWindow
)
2329 m_currentPort
= NULL
;
2331 GetPort( &m_formerPort
) ;
2334 theWindow
->MacGetPortParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2335 m_currentPort
= UMAGetWindowPort( window
) ;
2336 if ( m_formerPort
!= m_currentPort
)
2337 SetPort( m_currentPort
) ;
2338 GetPenState( &m_savedPenState
) ;
2339 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2344 wxMacDrawingHelper::~wxMacDrawingHelper()
2348 SetPort( m_currentPort
) ;
2349 SetPenState( &m_savedPenState
) ;
2350 SetOrigin( 0 , 0 ) ;
2352 GetPortBounds( m_currentPort
, &portRect
) ;
2353 ClipRect( &portRect
) ;
2354 wxDC::MacInvalidateSetup() ;
2357 if ( m_formerPort
!= m_currentPort
)
2358 SetPort( m_formerPort
) ;
2361 wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindow
* theWindow
)
2368 m_currentPort
= NULL
;
2370 GetPort( &m_formerPort
) ;
2374 theWindow
->MacGetPortClientParams( &localOrigin
, &clipRect
, &window
, &rootwin
) ;
2375 m_currentPort
= UMAGetWindowPort( window
) ;
2376 if ( m_formerPort
!= m_currentPort
)
2377 SetPort( m_currentPort
) ;
2378 GetPenState( &m_savedPenState
) ;
2379 theWindow
->MacSetPortDrawingParams( localOrigin
, clipRect
, window
, rootwin
) ;
2384 wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
2388 SetPort( m_currentPort
) ;
2389 SetPenState( &m_savedPenState
) ;
2390 SetOrigin( 0 , 0 ) ;
2392 GetPortBounds( m_currentPort
, &portRect
) ;
2393 ClipRect( &portRect
) ;
2396 if ( m_formerPort
!= m_currentPort
)
2397 SetPort( m_formerPort
) ;
2400 // Find the wxWindow at the current mouse position, returning the mouse
2402 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
2404 pt
= wxGetMousePosition();
2405 wxWindow
* found
= wxFindWindowAtPoint(pt
);
2409 // Get the current mouse position.
2410 wxPoint
wxGetMousePosition()
2413 wxGetMousePosition(& x
, & y
);
2414 return wxPoint(x
, y
);