1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/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"
27 #include "wx/window.h"
31 #include "wx/dcclient.h"
32 #include "wx/dcmemory.h"
34 #include "wx/scrolbar.h"
40 #include "wx/univ/colschem.h"
41 #include "wx/univ/renderer.h"
42 #include "wx/univ/theme.h"
48 // turn Refresh() debugging on/off
49 #define WXDEBUG_REFRESH
52 #undef WXDEBUG_REFRESH
55 #if defined(WXDEBUG_REFRESH) && defined(__WXMSW__) && !defined(__WXMICROWIN__)
56 #include "wx/msw/private.h"
59 // ============================================================================
61 // ============================================================================
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 // we can't use wxWindowNative here as it won't be expanded inside the macro
68 #if defined(__WXMSW__)
69 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowMSW
)
70 #elif defined(__WXGTK__)
71 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowGTK
)
72 #elif defined(__WXMGL__)
73 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowMGL
)
74 #elif defined(__WXX11__)
75 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowX11
)
76 #elif defined(__WXPM__)
77 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowOS2
)
80 BEGIN_EVENT_TABLE(wxWindow
, wxWindowNative
)
81 EVT_SIZE(wxWindow::OnSize
)
83 #if wxUSE_ACCEL || wxUSE_MENUS
84 EVT_KEY_DOWN(wxWindow::OnKeyDown
)
88 EVT_CHAR(wxWindow::OnChar
)
89 EVT_KEY_UP(wxWindow::OnKeyUp
)
92 EVT_PAINT(wxWindow::OnPaint
)
93 EVT_NC_PAINT(wxWindow::OnNcPaint
)
94 EVT_ERASE_BACKGROUND(wxWindow::OnErase
)
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 void wxWindow::Init()
104 m_scrollbarHorz
= (wxScrollBar
*)NULL
;
108 m_renderer
= wxTheme::Get()->GetRenderer();
110 m_oldSize
.x
= wxDefaultCoord
;
111 m_oldSize
.y
= wxDefaultCoord
;
114 bool wxWindow::Create(wxWindow
*parent
,
119 const wxString
& name
)
121 long actualStyle
= style
;
123 // FIXME: may need this on other platforms
125 actualStyle
&= ~wxVSCROLL
;
126 actualStyle
&= ~wxHSCROLL
;
129 // we add wxCLIP_CHILDREN to get the same ("natural") behaviour under MSW
130 // as under the other platforms
131 if ( !wxWindowNative::Create(parent
, id
, pos
, size
,
132 actualStyle
| wxCLIP_CHILDREN
,
138 // Set full style again, including those we didn't want present
139 // when calling the base window Create().
140 wxWindowBase::SetWindowStyleFlag(style
);
142 // if we allow or should always have a vertical scrollbar, make it
143 if ( style
& wxVSCROLL
|| style
& wxALWAYS_SHOW_SB
)
145 #if wxUSE_TWO_WINDOWS
146 SetInsertIntoMain( true );
148 m_scrollbarVert
= new wxScrollBar(this, wxID_ANY
,
149 wxDefaultPosition
, wxDefaultSize
,
151 #if wxUSE_TWO_WINDOWS
152 SetInsertIntoMain( false );
156 // if we should allow a horizontal scrollbar, make it
157 if ( style
& wxHSCROLL
)
159 #if wxUSE_TWO_WINDOWS
160 SetInsertIntoMain( true );
162 m_scrollbarHorz
= new wxScrollBar(this, wxID_ANY
,
163 wxDefaultPosition
, wxDefaultSize
,
165 #if wxUSE_TWO_WINDOWS
166 SetInsertIntoMain( false );
170 if (m_scrollbarHorz
|| m_scrollbarVert
)
173 PositionScrollbars();
179 wxWindow::~wxWindow()
181 m_isBeingDeleted
= true;
183 // we have to destroy our children before we're destroyed because our
184 // children suppose that we're of type wxWindow, not just wxWindowNative,
185 // and so bad things may happen if they're deleted from the base class dtor
186 // as by then we're not a wxWindow any longer and wxUniv-specific virtual
187 // functions can't be called
191 // ----------------------------------------------------------------------------
193 // ----------------------------------------------------------------------------
195 void wxWindow::SetBackground(const wxBitmap
& bitmap
,
200 m_alignBgBitmap
= alignment
;
201 m_stretchBgBitmap
= stretch
;
204 const wxBitmap
& wxWindow::GetBackgroundBitmap(int *alignment
,
205 wxStretch
*stretch
) const
207 if ( m_bitmapBg
.Ok() )
210 *alignment
= m_alignBgBitmap
;
212 *stretch
= m_stretchBgBitmap
;
218 // ----------------------------------------------------------------------------
220 // ----------------------------------------------------------------------------
222 // the event handlers executed when the window must be repainted
223 void wxWindow::OnNcPaint(wxNcPaintEvent
& WXUNUSED(event
))
227 // get the window rect
229 wxSize size
= GetSize();
233 rect
.height
= size
.y
;
235 // if the scrollbars are outside the border, we must adjust the rect to
237 if ( !m_renderer
->AreScrollbarsInsideBorder() )
239 wxScrollBar
*scrollbar
= GetScrollbar(wxVERTICAL
);
241 rect
.width
-= scrollbar
->GetSize().x
;
243 scrollbar
= GetScrollbar(wxHORIZONTAL
);
245 rect
.height
-= scrollbar
->GetSize().y
;
248 // get the DC and draw the border on it
250 DoDrawBorder(dc
, rect
);
254 void wxWindow::OnPaint(wxPaintEvent
& event
)
258 // it is a native control which paints itself
263 // get the DC to use and create renderer on it
265 wxControlRenderer
renderer(this, dc
, m_renderer
);
272 // the event handler executed when the window background must be painted
273 void wxWindow::OnErase(wxEraseEvent
& event
)
282 DoDrawBackground(*event
.GetDC());
284 // if we have both scrollbars, we also have a square in the corner between
285 // them which we must paint
286 if ( m_scrollbarVert
&& m_scrollbarHorz
)
288 wxSize size
= GetSize();
289 wxRect rectClient
= GetClientRect(),
290 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
293 rectCorner
.x
= rectClient
.GetRight() + 1;
294 rectCorner
.y
= rectClient
.GetBottom() + 1;
295 rectCorner
.SetRight(size
.x
- rectBorder
.width
);
296 rectCorner
.SetBottom(size
.y
- rectBorder
.height
);
298 if ( GetUpdateRegion().Contains(rectCorner
) )
300 m_renderer
->DrawScrollCorner(*event
.GetDC(), rectCorner
);
305 bool wxWindow::DoDrawBackground(wxDC
& dc
)
309 wxSize size
= GetSize(); // Why not GetClientSize() ?
313 rect
.height
= size
.y
;
315 wxWindow
* const parent
= GetParent();
316 if ( HasTransparentBackground() && parent
)
318 wxASSERT( !IsTopLevel() );
320 wxPoint pos
= GetPosition();
322 AdjustForParentClientOrigin( pos
.x
, pos
.y
, 0 );
324 // Adjust DC logical origin
325 wxCoord org_x
, org_y
, x
, y
;
326 dc
.GetLogicalOrigin( &org_x
, &org_y
);
329 dc
.SetLogicalOrigin( x
, y
);
335 // Let parent draw the background
336 parent
->EraseBackground( dc
, rect
);
338 // Restore DC logical origin
339 dc
.SetLogicalOrigin( org_x
, org_y
);
343 // Draw background ourselves
344 EraseBackground( dc
, rect
);
350 void wxWindow::EraseBackground(wxDC
& dc
, const wxRect
& rect
)
352 if ( GetBackgroundBitmap().Ok() )
354 // Get the bitmap and the flags
357 wxBitmap bmp
= GetBackgroundBitmap(&alignment
, &stretch
);
358 wxControlRenderer::DrawBitmap(dc
, bmp
, rect
, alignment
, stretch
);
362 // Just fill it with bg colour if no bitmap
364 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this),
365 rect
, GetStateFlags());
369 void wxWindow::DoDrawBorder(wxDC
& dc
, const wxRect
& rect
)
371 // draw outline unless the update region is enitrely inside it in which
372 // case we don't need to do it
373 #if 0 // doesn't seem to work, why?
374 if ( wxRegion(rect
).Contains(GetUpdateRegion().GetBox()) != wxInRegion
)
377 m_renderer
->DrawBorder(dc
, GetBorder(), rect
, GetStateFlags());
381 void wxWindow::DoDraw(wxControlRenderer
* WXUNUSED(renderer
))
385 void wxWindow::Refresh(bool eraseBackground
, const wxRect
*rectClient
)
388 wxPoint pt
= GetClientAreaOrigin();
390 wxSize size
= GetClientSize();
394 rectWin
= *rectClient
;
396 // don't refresh anything beyond the client area (scrollbars for
398 if ( rectWin
.GetRight() > size
.x
)
399 rectWin
.SetRight(size
.x
);
400 if ( rectWin
.GetBottom() > size
.y
)
401 rectWin
.SetBottom(size
.y
);
405 else // refresh the entire client area
409 rectWin
.width
= size
.x
;
410 rectWin
.height
= size
.y
;
414 #ifdef WXDEBUG_REFRESH
415 static bool s_refreshDebug
= false;
416 if ( s_refreshDebug
)
419 dc
.SetBrush(*wxCYAN_BRUSH
);
420 dc
.SetPen(*wxTRANSPARENT_PEN
);
421 dc
.DrawRectangle(rectWin
);
423 // under Unix we use "--sync" X option for this
424 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
429 #endif // WXDEBUG_REFRESH
431 wxWindowNative::Refresh(eraseBackground
, &rectWin
);
433 // Refresh all sub controls if any.
434 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
437 wxWindow
*win
= node
->GetData();
438 // Only refresh sub controls when it is visible
439 // and when it is in the update region.
440 if(!win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)) && win
->IsShown() && wxRegion(rectWin
).Contains(win
->GetRect()) != wxOutRegion
)
441 win
->Refresh(eraseBackground
, &rectWin
);
443 node
= node
->GetNext();
447 // ----------------------------------------------------------------------------
449 // ----------------------------------------------------------------------------
451 bool wxWindow::Enable(bool enable
)
453 if ( !wxWindowNative::Enable(enable
) )
456 // disabled window can't keep focus
457 if ( FindFocus() == this && GetParent() != NULL
)
459 GetParent()->SetFocus();
464 // a window with renderer is drawn by ourselves and it has to be
465 // refreshed to reflect its new status
472 bool wxWindow::IsFocused() const
474 return FindFocus() == this;
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
);