1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: univ/window.cpp
3 // Purpose: implementation of extra wxWindow methods for wxUniv port
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/window.h"
30 #include "wx/dcclient.h"
31 #include "wx/dcmemory.h"
33 #include "wx/scrolbar.h"
39 #include "wx/univ/colschem.h"
40 #include "wx/univ/renderer.h"
41 #include "wx/univ/theme.h"
47 // turn Refresh() debugging on/off
48 #define WXDEBUG_REFRESH
51 #undef WXDEBUG_REFRESH
54 #if defined(WXDEBUG_REFRESH) && defined(__WXMSW__) && !defined(__WXMICROWIN__)
55 #include "wx/msw/private.h"
58 // ============================================================================
60 // ============================================================================
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 // we can't use wxWindowNative here as it won't be expanded inside the macro
67 #if defined(__WXMSW__)
68 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowMSW
)
69 #elif defined(__WXGTK__)
70 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowGTK
)
71 #elif defined(__WXMGL__)
72 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowMGL
)
73 #elif defined(__WXX11__)
74 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowX11
)
75 #elif defined(__WXPM__)
76 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowOS2
)
79 BEGIN_EVENT_TABLE(wxWindow
, wxWindowNative
)
80 EVT_SIZE(wxWindow::OnSize
)
82 #if wxUSE_ACCEL || wxUSE_MENUS
83 EVT_KEY_DOWN(wxWindow::OnKeyDown
)
87 EVT_CHAR(wxWindow::OnChar
)
88 EVT_KEY_UP(wxWindow::OnKeyUp
)
91 EVT_PAINT(wxWindow::OnPaint
)
92 EVT_NC_PAINT(wxWindow::OnNcPaint
)
93 EVT_ERASE_BACKGROUND(wxWindow::OnErase
)
96 // ----------------------------------------------------------------------------
98 // ----------------------------------------------------------------------------
100 void wxWindow::Init()
103 m_scrollbarHorz
= (wxScrollBar
*)NULL
;
107 m_renderer
= wxTheme::Get()->GetRenderer();
109 m_oldSize
.x
= wxDefaultCoord
;
110 m_oldSize
.y
= wxDefaultCoord
;
113 bool wxWindow::Create(wxWindow
*parent
,
118 const wxString
& name
)
120 long actualStyle
= style
;
122 // FIXME: may need this on other platforms
124 actualStyle
&= ~wxVSCROLL
;
125 actualStyle
&= ~wxHSCROLL
;
128 // we add wxCLIP_CHILDREN to get the same ("natural") behaviour under MSW
129 // as under the other platforms
130 if ( !wxWindowNative::Create(parent
, id
, pos
, size
,
131 actualStyle
| wxCLIP_CHILDREN
,
137 // Set full style again, including those we didn't want present
138 // when calling the base window Create().
139 wxWindowBase::SetWindowStyleFlag(style
);
141 // if we allow or should always have a vertical scrollbar, make it
142 if ( style
& wxVSCROLL
|| style
& wxALWAYS_SHOW_SB
)
144 #if wxUSE_TWO_WINDOWS
145 SetInsertIntoMain( true );
147 m_scrollbarVert
= new wxScrollBar(this, wxID_ANY
,
148 wxDefaultPosition
, wxDefaultSize
,
150 #if wxUSE_TWO_WINDOWS
151 SetInsertIntoMain( false );
155 // if we should allow a horizontal scrollbar, make it
156 if ( style
& wxHSCROLL
)
158 #if wxUSE_TWO_WINDOWS
159 SetInsertIntoMain( true );
161 m_scrollbarHorz
= new wxScrollBar(this, wxID_ANY
,
162 wxDefaultPosition
, wxDefaultSize
,
164 #if wxUSE_TWO_WINDOWS
165 SetInsertIntoMain( false );
169 if (m_scrollbarHorz
|| m_scrollbarVert
)
172 PositionScrollbars();
178 wxWindow::~wxWindow()
180 m_isBeingDeleted
= true;
182 // we have to destroy our children before we're destroyed because our
183 // children suppose that we're of type wxWindow, not just wxWindowNative,
184 // and so bad things may happen if they're deleted from the base class dtor
185 // as by then we're not a wxWindow any longer and wxUniv-specific virtual
186 // functions can't be called
190 // ----------------------------------------------------------------------------
192 // ----------------------------------------------------------------------------
194 void wxWindow::SetBackground(const wxBitmap
& bitmap
,
199 m_alignBgBitmap
= alignment
;
200 m_stretchBgBitmap
= stretch
;
203 const wxBitmap
& wxWindow::GetBackgroundBitmap(int *alignment
,
204 wxStretch
*stretch
) const
206 if ( m_bitmapBg
.Ok() )
209 *alignment
= m_alignBgBitmap
;
211 *stretch
= m_stretchBgBitmap
;
217 // ----------------------------------------------------------------------------
219 // ----------------------------------------------------------------------------
221 // the event handlers executed when the window must be repainted
222 void wxWindow::OnNcPaint(wxNcPaintEvent
& WXUNUSED(event
))
226 // get the window rect
228 wxSize size
= GetSize();
232 rect
.height
= size
.y
;
234 // if the scrollbars are outside the border, we must adjust the rect to
236 if ( !m_renderer
->AreScrollbarsInsideBorder() )
238 wxScrollBar
*scrollbar
= GetScrollbar(wxVERTICAL
);
240 rect
.width
-= scrollbar
->GetSize().x
;
242 scrollbar
= GetScrollbar(wxHORIZONTAL
);
244 rect
.height
-= scrollbar
->GetSize().y
;
247 // get the DC and draw the border on it
249 DoDrawBorder(dc
, rect
);
253 void wxWindow::OnPaint(wxPaintEvent
& event
)
257 // it is a native control which paints itself
262 // get the DC to use and create renderer on it
264 wxControlRenderer
renderer(this, dc
, m_renderer
);
271 // the event handler executed when the window background must be painted
272 void wxWindow::OnErase(wxEraseEvent
& event
)
281 DoDrawBackground(*event
.GetDC());
283 // if we have both scrollbars, we also have a square in the corner between
284 // them which we must paint
285 if ( m_scrollbarVert
&& m_scrollbarHorz
)
287 wxSize size
= GetSize();
288 wxRect rectClient
= GetClientRect(),
289 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
292 rectCorner
.x
= rectClient
.GetRight() + 1;
293 rectCorner
.y
= rectClient
.GetBottom() + 1;
294 rectCorner
.SetRight(size
.x
- rectBorder
.width
);
295 rectCorner
.SetBottom(size
.y
- rectBorder
.height
);
297 if ( GetUpdateRegion().Contains(rectCorner
) )
299 m_renderer
->DrawScrollCorner(*event
.GetDC(), rectCorner
);
304 bool wxWindow::DoDrawBackground(wxDC
& dc
)
308 wxSize size
= GetSize(); // Why not GetClientSize() ?
312 rect
.height
= size
.y
;
314 wxWindow
* const parent
= GetParent();
315 if ( HasTransparentBackground() && parent
)
317 wxASSERT( !IsTopLevel() );
319 wxPoint pos
= GetPosition();
321 AdjustForParentClientOrigin( pos
.x
, pos
.y
, 0 );
323 // Adjust DC logical origin
324 wxCoord org_x
, org_y
, x
, y
;
325 dc
.GetLogicalOrigin( &org_x
, &org_y
);
328 dc
.SetLogicalOrigin( x
, y
);
334 // Let parent draw the background
335 parent
->EraseBackground( dc
, rect
);
337 // Restore DC logical origin
338 dc
.SetLogicalOrigin( org_x
, org_y
);
342 // Draw background ourselves
343 EraseBackground( dc
, rect
);
349 void wxWindow::EraseBackground(wxDC
& dc
, const wxRect
& rect
)
351 if ( GetBackgroundBitmap().Ok() )
353 // Get the bitmap and the flags
356 wxBitmap bmp
= GetBackgroundBitmap(&alignment
, &stretch
);
357 wxControlRenderer::DrawBitmap(dc
, bmp
, rect
, alignment
, stretch
);
361 // Just fill it with bg colour if no bitmap
363 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this),
364 rect
, GetStateFlags());
368 void wxWindow::DoDrawBorder(wxDC
& dc
, const wxRect
& rect
)
370 // draw outline unless the update region is enitrely inside it in which
371 // case we don't need to do it
372 #if 0 // doesn't seem to work, why?
373 if ( wxRegion(rect
).Contains(GetUpdateRegion().GetBox()) != wxInRegion
)
376 m_renderer
->DrawBorder(dc
, GetBorder(), rect
, GetStateFlags());
380 void wxWindow::DoDraw(wxControlRenderer
* WXUNUSED(renderer
))
384 void wxWindow::Refresh(bool eraseBackground
, const wxRect
*rectClient
)
387 wxPoint pt
= GetClientAreaOrigin();
389 wxSize size
= GetClientSize();
393 rectWin
= *rectClient
;
395 // don't refresh anything beyond the client area (scrollbars for
397 if ( rectWin
.GetRight() > size
.x
)
398 rectWin
.SetRight(size
.x
);
399 if ( rectWin
.GetBottom() > size
.y
)
400 rectWin
.SetBottom(size
.y
);
404 else // refresh the entire client area
408 rectWin
.width
= size
.x
;
409 rectWin
.height
= size
.y
;
413 #ifdef WXDEBUG_REFRESH
414 static bool s_refreshDebug
= false;
415 if ( s_refreshDebug
)
418 dc
.SetBrush(*wxCYAN_BRUSH
);
419 dc
.SetPen(*wxTRANSPARENT_PEN
);
420 dc
.DrawRectangle(rectWin
);
422 // under Unix we use "--sync" X option for this
423 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
428 #endif // WXDEBUG_REFRESH
430 wxWindowNative::Refresh(eraseBackground
, &rectWin
);
432 // Refresh all sub controls if any.
433 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
436 wxWindow
*win
= node
->GetData();
437 // Only refresh sub controls when it is visible
438 // and when it is in the update region.
439 if(!win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)) && win
->IsShown() && wxRegion(rectWin
).Contains(win
->GetRect()) != wxOutRegion
)
440 win
->Refresh(eraseBackground
, &rectWin
);
442 node
= node
->GetNext();
446 // ----------------------------------------------------------------------------
448 // ----------------------------------------------------------------------------
450 bool wxWindow::Enable(bool enable
)
452 if ( !wxWindowNative::Enable(enable
) )
455 // disabled window can't keep focus
456 if ( FindFocus() == this && GetParent() != NULL
)
458 GetParent()->SetFocus();
463 // a window with renderer is drawn by ourselves and it has to be
464 // refreshed to reflect its new status
471 bool wxWindow::IsFocused() const
473 wxWindow
*self
= wxConstCast(this, wxWindow
);
474 return self
->FindFocus() == self
;
477 bool wxWindow::IsPressed() const
482 bool wxWindow::IsDefault() const
487 bool wxWindow::IsCurrent() const
492 bool wxWindow::SetCurrent(bool doit
)
494 if ( doit
== m_isCurrent
)
499 if ( CanBeHighlighted() )
505 int wxWindow::GetStateFlags() const
509 flags
|= wxCONTROL_DISABLED
;
511 // the following states are only possible if our application is active - if
512 // it is not, even our default/focused controls shouldn't appear as such
513 if ( wxTheApp
->IsActive() )
516 flags
|= wxCONTROL_CURRENT
;
518 flags
|= wxCONTROL_FOCUSED
;
520 flags
|= wxCONTROL_PRESSED
;
522 flags
|= wxCONTROL_ISDEFAULT
;
528 // ----------------------------------------------------------------------------
530 // ----------------------------------------------------------------------------
532 void wxWindow::OnSize(wxSizeEvent
& event
)
536 if ( m_scrollbarVert
|| m_scrollbarHorz
)
538 PositionScrollbars();
541 #if 0 // ndef __WXMSW__
542 // Refresh the area (strip) previously occupied by the border
544 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) && IsShown() )
546 // This code assumes that wxSizeEvent.GetSize() returns
547 // the area of the entire window, not just the client
549 wxSize newSize
= event
.GetSize();
551 if (m_oldSize
.x
== wxDefaultCoord
&& m_oldSize
.y
== wxDefaultCoord
)
557 if (HasFlag( wxSIMPLE_BORDER
))
559 if (newSize
.y
> m_oldSize
.y
)
563 rect
.width
= m_oldSize
.x
;
564 rect
.y
= m_oldSize
.y
-2;
566 Refresh( true, &rect
);
568 else if (newSize
.y
< m_oldSize
.y
)
574 rect
.width
= newSize
.x
;
575 wxWindowNative::Refresh( true, &rect
);
578 if (newSize
.x
> m_oldSize
.x
)
582 rect
.height
= m_oldSize
.y
;
583 rect
.x
= m_oldSize
.x
-2;
585 Refresh( true, &rect
);
587 else if (newSize
.x
< m_oldSize
.x
)
593 rect
.height
= newSize
.y
;
594 wxWindowNative::Refresh( true, &rect
);
598 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
600 if (newSize
.y
> m_oldSize
.y
)
604 rect
.width
= m_oldSize
.x
;
605 rect
.y
= m_oldSize
.y
-4;
607 Refresh( true, &rect
);
609 else if (newSize
.y
< m_oldSize
.y
)
615 rect
.width
= newSize
.x
;
616 wxWindowNative::Refresh( true, &rect
);
619 if (newSize
.x
> m_oldSize
.x
)
623 rect
.height
= m_oldSize
.y
;
624 rect
.x
= m_oldSize
.x
-4;
626 Refresh( true, &rect
);
628 else if (newSize
.x
< m_oldSize
.x
)
634 rect
.height
= newSize
.y
;
635 wxWindowNative::Refresh( true, &rect
);
644 wxSize
wxWindow::DoGetBestSize() const
646 return AdjustSize(DoGetBestClientSize());
649 wxSize
wxWindow::DoGetBestClientSize() const
651 return wxWindowNative::DoGetBestSize();
654 wxSize
wxWindow::AdjustSize(const wxSize
& size
) const
658 m_renderer
->AdjustSize(&sz
, this);
662 wxPoint
wxWindow::GetClientAreaOrigin() const
664 wxPoint pt
= wxWindowBase::GetClientAreaOrigin();
666 #if wxUSE_TWO_WINDOWS
669 pt
+= m_renderer
->GetBorderDimensions(GetBorder()).GetPosition();
675 void wxWindow::DoGetClientSize(int *width
, int *height
) const
677 // if it is a native window, we assume it handles the scrollbars itself
678 // too - and if it doesn't, there is not much we can do
681 wxWindowNative::DoGetClientSize(width
, height
);
687 wxWindowNative::DoGetClientSize(&w
, &h
);
689 // we assume that the scrollbars are positioned correctly (by a previous
690 // call to PositionScrollbars()) here
694 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
696 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
700 // in any case, take account of the scrollbar
701 if ( m_scrollbarVert
)
702 w
-= m_scrollbarVert
->GetSize().x
;
704 // if we don't have scrollbar or if it is outside the border (and not
705 // blended into it), take account of the right border as well
706 if ( !m_scrollbarVert
|| inside
)
707 w
-= rectBorder
.width
;
709 // and always account for the left border
710 *width
= w
- rectBorder
.x
;
712 // we shouldn't return invalid width
719 if ( m_scrollbarHorz
)
720 h
-= m_scrollbarHorz
->GetSize().y
;
722 if ( !m_scrollbarHorz
|| inside
)
723 h
-= rectBorder
.height
;
725 *height
= h
- rectBorder
.y
;
727 // we shouldn't return invalid height
733 void wxWindow::DoSetClientSize(int width
, int height
)
735 // take into account the borders
736 wxRect rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
737 width
+= rectBorder
.x
;
738 height
+= rectBorder
.y
;
740 // and the scrollbars (as they may be offset into the border, use the
741 // scrollbar position, not size - this supposes that PositionScrollbars()
742 // had been called before)
743 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
744 wxSize size
= GetSize();
745 if ( m_scrollbarVert
)
746 width
+= size
.x
- m_scrollbarVert
->GetPosition().x
;
747 if ( !m_scrollbarVert
|| inside
)
748 width
+= rectBorder
.width
;
750 if ( m_scrollbarHorz
)
751 height
+= size
.y
- m_scrollbarHorz
->GetPosition().y
;
752 if ( !m_scrollbarHorz
|| inside
)
753 height
+= rectBorder
.height
;
755 wxWindowNative::DoSetClientSize(width
, height
);
758 wxHitTest
wxWindow::DoHitTest(wxCoord x
, wxCoord y
) const
760 wxHitTest ht
= wxWindowNative::DoHitTest(x
, y
);
761 if ( ht
== wxHT_WINDOW_INSIDE
)
763 if ( m_scrollbarVert
&& x
>= m_scrollbarVert
->GetPosition().x
)
765 // it can still be changed below because it may also be the corner
766 ht
= wxHT_WINDOW_VERT_SCROLLBAR
;
769 if ( m_scrollbarHorz
&& y
>= m_scrollbarHorz
->GetPosition().y
)
771 ht
= ht
== wxHT_WINDOW_VERT_SCROLLBAR
? wxHT_WINDOW_CORNER
772 : wxHT_WINDOW_HORZ_SCROLLBAR
;
779 // ----------------------------------------------------------------------------
780 // scrolling: we implement it entirely ourselves except for ScrollWindow()
781 // function which is supposed to be (efficiently) implemented by the native
783 // ----------------------------------------------------------------------------
785 void wxWindow::RefreshScrollbars()
787 if ( m_scrollbarHorz
)
788 m_scrollbarHorz
->Refresh();
790 if ( m_scrollbarVert
)
791 m_scrollbarVert
->Refresh();
794 void wxWindow::PositionScrollbars()
796 // do not use GetClientSize/Rect as it relies on the scrollbars being
797 // correctly positioned
799 wxSize size
= GetSize();
800 wxBorder border
= GetBorder();
801 wxRect rectBorder
= m_renderer
->GetBorderDimensions(border
);
802 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
804 int height
= m_scrollbarHorz
? m_scrollbarHorz
->GetSize().y
: 0;
805 int width
= m_scrollbarVert
? m_scrollbarVert
->GetSize().x
: 0;
808 if ( m_scrollbarVert
)
810 rectBar
.x
= size
.x
- width
;
812 rectBar
.x
-= rectBorder
.width
;
813 rectBar
.width
= width
;
816 rectBar
.y
+= rectBorder
.y
;
817 rectBar
.height
= size
.y
- height
;
819 rectBar
.height
-= rectBorder
.y
+ rectBorder
.height
;
821 m_scrollbarVert
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
824 if ( m_scrollbarHorz
)
826 rectBar
.y
= size
.y
- height
;
828 rectBar
.y
-= rectBorder
.height
;
829 rectBar
.height
= height
;
832 rectBar
.x
+= rectBorder
.x
;
833 rectBar
.width
= size
.x
- width
;
835 rectBar
.width
-= rectBorder
.x
+ rectBorder
.width
;
837 m_scrollbarHorz
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
843 void wxWindow::SetScrollbar(int orient
,
849 wxASSERT_MSG( pageSize
<= range
,
850 _T("page size can't be greater than range") );
852 bool hasClientSizeChanged
= false;
853 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
854 if ( range
&& (pageSize
< range
) )
859 #if wxUSE_TWO_WINDOWS
860 SetInsertIntoMain( true );
862 scrollbar
= new wxScrollBar(this, wxID_ANY
,
863 wxDefaultPosition
, wxDefaultSize
,
864 orient
& wxVERTICAL
? wxSB_VERTICAL
866 #if wxUSE_TWO_WINDOWS
867 SetInsertIntoMain( false );
869 if ( orient
& wxVERTICAL
)
870 m_scrollbarVert
= scrollbar
;
872 m_scrollbarHorz
= scrollbar
;
874 // the client area diminished as we created a scrollbar
875 hasClientSizeChanged
= true;
877 PositionScrollbars();
879 else if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
881 // we might have disabled it before
885 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
887 else // no range means no scrollbar
891 // wxALWAYS_SHOW_SB only applies to the vertical scrollbar
892 if ( (orient
& wxVERTICAL
) && (GetWindowStyle() & wxALWAYS_SHOW_SB
) )
894 // just disable the scrollbar
895 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
896 scrollbar
->Disable();
898 else // really remove the scrollbar
902 if ( orient
& wxVERTICAL
)
903 m_scrollbarVert
= NULL
;
905 m_scrollbarHorz
= NULL
;
907 // the client area increased as we removed a scrollbar
908 hasClientSizeChanged
= true;
910 // the size of the remaining scrollbar must be adjusted
911 if ( m_scrollbarHorz
|| m_scrollbarVert
)
913 PositionScrollbars();
919 // give the window a chance to relayout
920 if ( hasClientSizeChanged
)
922 #if wxUSE_TWO_WINDOWS
923 wxWindowNative::SetSize( GetSize() );
925 wxSizeEvent
event(GetSize());
926 (void)GetEventHandler()->ProcessEvent(event
);
931 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
933 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
934 wxCHECK_RET( scrollbar
, _T("no scrollbar to set position for") );
936 scrollbar
->SetThumbPosition(pos
);
938 // VZ: I think we can safely ignore this as we always refresh it
939 // automatically whenever the value chanegs
946 int wxWindow::GetScrollPos(int orient
) const
948 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
949 return scrollbar
? scrollbar
->GetThumbPosition() : 0;
952 int wxWindow::GetScrollThumb(int orient
) const
954 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
955 return scrollbar
? scrollbar
->GetThumbSize() : 0;
958 int wxWindow::GetScrollRange(int orient
) const
960 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
961 return scrollbar
? scrollbar
->GetRange() : 0;
964 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
966 // use native scrolling when available and do it in generic way
970 wxWindowNative::ScrollWindow(dx
, dy
, rect
);
974 // before scrolling it, ensure that we don't have any unpainted areas
981 r
= ScrollNoRefresh(dx
, 0, rect
);
982 Refresh(true /* erase bkgnd */, &r
);
987 r
= ScrollNoRefresh(0, dy
, rect
);
988 Refresh(true /* erase bkgnd */, &r
);
991 // scroll children accordingly:
992 wxPoint
offset(dx
, dy
);
994 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
995 node
; node
= node
->GetNext())
997 wxWindow
*child
= node
->GetData();
998 if ( child
== m_scrollbarVert
|| child
== m_scrollbarHorz
)
1001 // VS: Scrolling children has non-trivial semantics. If rect=NULL then
1002 // it is easy: we scroll all children. Otherwise it gets
1004 // 1. if scrolling in one direction only, scroll only
1005 // those children that intersect shaft defined by the rectangle
1006 // and scrolling direction
1007 // 2. if scrolling in both axes, scroll all children
1009 if ( rect
&& (dx
* dy
== 0 /* moving in only one of x, y axis */) )
1011 wxRect childRect
= child
->GetRect();
1012 if ( dx
== 0 && (childRect
.GetLeft() <= rect
->GetRight() ||
1013 childRect
.GetRight() >= rect
->GetLeft()) )
1015 child
->Move(child
->GetPosition() + offset
);
1017 else if ( dy
== 0 && (childRect
.GetTop() <= rect
->GetBottom() ||
1018 childRect
.GetBottom() >= rect
->GetTop()) )
1020 child
->Move(child
->GetPosition() + offset
);
1025 child
->Move(child
->GetPosition() + offset
);
1028 #endif // wxX11/!wxX11
1031 wxRect
wxWindow::ScrollNoRefresh(int dx
, int dy
, const wxRect
*rectTotal
)
1033 wxASSERT_MSG( !dx
|| !dy
, _T("can't be used for diag scrolling") );
1035 // the rect to refresh (which we will calculate)
1044 // calculate the part of the window which we can just redraw in the new
1046 wxSize sizeTotal
= rectTotal
? rectTotal
->GetSize() : GetClientSize();
1048 wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
1049 sizeTotal
.x
, sizeTotal
.y
, dx
, dy
);
1051 // the initial and end point of the region we move in client coords
1052 wxPoint ptSource
, ptDest
;
1055 ptSource
= rectTotal
->GetPosition();
1056 ptDest
= rectTotal
->GetPosition();
1059 // the size of this region
1061 size
.x
= sizeTotal
.x
- abs(dx
);
1062 size
.y
= sizeTotal
.y
- abs(dy
);
1063 if ( size
.x
<= 0 || size
.y
<= 0 )
1065 // just redraw everything as nothing of the displayed image will stay
1066 wxLogTrace(_T("scroll"), _T("refreshing everything"));
1068 rect
= rectTotal
? *rectTotal
: wxRect(0, 0, sizeTotal
.x
, sizeTotal
.y
);
1070 else // move the part which doesn't change to the new location
1072 // note that when we scroll the canvas in some direction we move the
1073 // block which doesn't need to be refreshed in the opposite direction
1077 // scroll to the right, move to the left
1082 // scroll to the left, move to the right
1088 // scroll down, move up
1093 // scroll up, move down
1098 // we need to hide the caret before moving or it will erase itself at
1099 // the wrong (old) location
1100 wxCaret
*caret
= GetCaret();
1103 #endif // wxUSE_CARET
1106 wxClientDC
dc(this);
1107 wxBitmap
bmp(size
.x
, size
.y
);
1109 dcMem
.SelectObject(bmp
);
1111 dcMem
.Blit(wxPoint(0,0), size
, &dc
, ptSource
1112 #if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
1113 + GetClientAreaOrigin()
1114 #endif // broken wxGTK wxDC::Blit
1116 dc
.Blit(ptDest
, size
, &dcMem
, wxPoint(0,0));
1118 wxLogTrace(_T("scroll"),
1119 _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
1120 ptSource
.x
, ptSource
.y
,
1122 ptDest
.x
, ptDest
.y
);
1124 // and now repaint the uncovered area
1126 // FIXME: We repaint the intersection of these rectangles twice - is
1127 // it bad? I don't think so as it is rare to scroll the window
1128 // diagonally anyhow and so adding extra logic to compute
1129 // rectangle intersection is probably not worth the effort
1131 rect
.x
= ptSource
.x
;
1132 rect
.y
= ptSource
.y
;
1138 // refresh the area along the right border
1139 rect
.x
+= size
.x
+ dx
;
1144 // refresh the area along the left border
1148 rect
.height
= sizeTotal
.y
;
1150 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1152 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1159 // refresh the area along the bottom border
1160 rect
.y
+= size
.y
+ dy
;
1165 // refresh the area along the top border
1169 rect
.width
= sizeTotal
.x
;
1171 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1173 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1179 #endif // wxUSE_CARET
1185 // ----------------------------------------------------------------------------
1186 // accelerators and menu hot keys
1187 // ----------------------------------------------------------------------------
1190 // the last window over which Alt was pressed (used by OnKeyUp)
1191 wxWindow
*wxWindow::ms_winLastAltPress
= NULL
;
1192 #endif // wxUSE_MENUS
1194 #if wxUSE_ACCEL || wxUSE_MENUS
1196 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1199 int key
= event
.GetKeyCode();
1200 if ( !event
.ControlDown() && (key
== WXK_ALT
|| key
== WXK_F10
) )
1202 ms_winLastAltPress
= this;
1204 // it can't be an accel anyhow
1208 ms_winLastAltPress
= NULL
;
1209 #endif // wxUSE_MENUS
1212 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
1214 int command
= win
->GetAcceleratorTable()->GetCommand(event
);
1215 if ( command
!= -1 )
1217 wxCommandEvent
eventCmd(wxEVT_COMMAND_MENU_SELECTED
, command
);
1218 if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) )
1220 // skip "event.Skip()" below
1225 if ( win
->IsTopLevel() )
1227 // try the frame menu bar
1229 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1232 wxMenuBar
*menubar
= frame
->GetMenuBar();
1233 if ( menubar
&& menubar
->ProcessAccelEvent(event
) )
1235 // skip "event.Skip()" below
1239 #endif // wxUSE_MENUS
1241 // if it wasn't in a menu, try to find a button
1242 if ( command
!= -1 )
1244 wxWindow
* child
= win
->FindWindow(command
);
1245 if ( child
&& wxDynamicCast(child
, wxButton
) )
1247 wxCommandEvent
eventCmd(wxEVT_COMMAND_BUTTON_CLICKED
, command
);
1248 eventCmd
.SetEventObject(child
);
1249 if ( child
->GetEventHandler()->ProcessEvent(eventCmd
) )
1251 // skip "event.Skip()" below
1257 // don't propagate accels from the child frame to the parent one
1261 #endif // wxUSE_ACCEL
1266 #endif // wxUSE_ACCEL
1270 wxMenuBar
*wxWindow::GetParentFrameMenuBar() const
1272 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
1274 if ( win
->IsTopLevel() )
1276 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1279 return frame
->GetMenuBar();
1282 // don't look further - we don't want to return the menubar of the
1291 void wxWindow::OnChar(wxKeyEvent
& event
)
1293 if ( event
.AltDown() && !event
.ControlDown() )
1295 int key
= event
.GetKeyCode();
1297 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1300 int item
= menubar
->FindNextItemForAccel(-1, key
);
1303 menubar
->PopupMenu((size_t)item
);
1305 // skip "event.Skip()" below
1314 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1316 int key
= event
.GetKeyCode();
1317 if ( !event
.HasModifiers() && (key
== WXK_ALT
|| key
== WXK_F10
) )
1319 // only process Alt release specially if there were no other key
1320 // presses since Alt had been pressed and if both events happened in
1322 if ( ms_winLastAltPress
== this )
1324 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1325 if ( menubar
&& this != menubar
)
1327 menubar
->SelectMenu(0);
1336 // in any case reset it
1337 ms_winLastAltPress
= NULL
;
1340 #endif // wxUSE_MENUS
1342 // ----------------------------------------------------------------------------
1343 // MSW-specific section
1344 // ----------------------------------------------------------------------------
1348 #include "wx/msw/private.h"
1350 WXLRESULT
wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1352 if ( message
== WM_NCHITTEST
)
1354 // the windows which contain the other windows should let the mouse
1355 // events through, otherwise a window inside a static box would
1356 // never get any events at all
1357 if ( IsStaticBox() )
1359 return HTTRANSPARENT
;
1363 return wxWindowNative::MSWWindowProc(message
, wParam
, lParam
);