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()
105 m_scrollbarHorz
= (wxScrollBar
*)NULL
;
106 #endif // wxUSE_SCROLLBAR
110 m_renderer
= wxTheme::Get()->GetRenderer();
112 m_oldSize
.x
= wxDefaultCoord
;
113 m_oldSize
.y
= wxDefaultCoord
;
116 bool wxWindow::Create(wxWindow
*parent
,
121 const wxString
& name
)
123 long actualStyle
= style
;
125 // FIXME: may need this on other platforms
127 actualStyle
&= ~wxVSCROLL
;
128 actualStyle
&= ~wxHSCROLL
;
131 // we add wxCLIP_CHILDREN to get the same ("natural") behaviour under MSW
132 // as under the other platforms
133 if ( !wxWindowNative::Create(parent
, id
, pos
, size
,
134 actualStyle
| wxCLIP_CHILDREN
,
140 // Set full style again, including those we didn't want present
141 // when calling the base window Create().
142 wxWindowBase::SetWindowStyleFlag(style
);
144 // if we allow or should always have a vertical scrollbar, make it
145 if ( style
& wxVSCROLL
|| style
& wxALWAYS_SHOW_SB
)
147 #if wxUSE_TWO_WINDOWS
148 SetInsertIntoMain( true );
151 m_scrollbarVert
= new wxScrollBar(this, wxID_ANY
,
152 wxDefaultPosition
, wxDefaultSize
,
154 #endif // wxUSE_SCROLLBAR
155 #if wxUSE_TWO_WINDOWS
156 SetInsertIntoMain( false );
160 // if we should allow a horizontal scrollbar, make it
161 if ( style
& wxHSCROLL
)
163 #if wxUSE_TWO_WINDOWS
164 SetInsertIntoMain( true );
167 m_scrollbarHorz
= new wxScrollBar(this, wxID_ANY
,
168 wxDefaultPosition
, wxDefaultSize
,
170 #endif // wxUSE_SCROLLBAR
171 #if wxUSE_TWO_WINDOWS
172 SetInsertIntoMain( false );
177 if (m_scrollbarHorz
|| m_scrollbarVert
)
180 PositionScrollbars();
182 #endif // wxUSE_SCROLLBAR
187 wxWindow::~wxWindow()
189 m_isBeingDeleted
= true;
191 // we have to destroy our children before we're destroyed because our
192 // children suppose that we're of type wxWindow, not just wxWindowNative,
193 // and so bad things may happen if they're deleted from the base class dtor
194 // as by then we're not a wxWindow any longer and wxUniv-specific virtual
195 // functions can't be called
199 // ----------------------------------------------------------------------------
201 // ----------------------------------------------------------------------------
203 void wxWindow::SetBackground(const wxBitmap
& bitmap
,
208 m_alignBgBitmap
= alignment
;
209 m_stretchBgBitmap
= stretch
;
212 const wxBitmap
& wxWindow::GetBackgroundBitmap(int *alignment
,
213 wxStretch
*stretch
) const
215 if ( m_bitmapBg
.Ok() )
218 *alignment
= m_alignBgBitmap
;
220 *stretch
= m_stretchBgBitmap
;
226 // ----------------------------------------------------------------------------
228 // ----------------------------------------------------------------------------
230 // the event handlers executed when the window must be repainted
231 void wxWindow::OnNcPaint(wxNcPaintEvent
& WXUNUSED(event
))
235 // get the window rect
236 wxRect
rect(GetSize());
239 // if the scrollbars are outside the border, we must adjust the rect to
241 if ( !m_renderer
->AreScrollbarsInsideBorder() )
243 wxScrollBar
*scrollbar
= GetScrollbar(wxVERTICAL
);
245 rect
.width
-= scrollbar
->GetSize().x
;
247 scrollbar
= GetScrollbar(wxHORIZONTAL
);
249 rect
.height
-= scrollbar
->GetSize().y
;
251 #endif // wxUSE_SCROLLBAR
253 // get the DC and draw the border on it
255 DoDrawBorder(dc
, rect
);
259 void wxWindow::OnPaint(wxPaintEvent
& event
)
263 // it is a native control which paints itself
268 // get the DC to use and create renderer on it
270 wxControlRenderer
renderer(this, dc
, m_renderer
);
277 // the event handler executed when the window background must be painted
278 void wxWindow::OnErase(wxEraseEvent
& event
)
287 DoDrawBackground(*event
.GetDC());
290 // if we have both scrollbars, we also have a square in the corner between
291 // them which we must paint
292 if ( m_scrollbarVert
&& m_scrollbarHorz
)
294 wxSize size
= GetSize();
295 wxRect rectClient
= GetClientRect(),
296 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
299 rectCorner
.x
= rectClient
.GetRight() + 1;
300 rectCorner
.y
= rectClient
.GetBottom() + 1;
301 rectCorner
.SetRight(size
.x
- rectBorder
.width
);
302 rectCorner
.SetBottom(size
.y
- rectBorder
.height
);
304 if ( GetUpdateRegion().Contains(rectCorner
) )
306 m_renderer
->DrawScrollCorner(*event
.GetDC(), rectCorner
);
309 #endif // wxUSE_SCROLLBAR
312 bool wxWindow::DoDrawBackground(wxDC
& dc
)
316 wxSize size
= GetSize(); // Why not GetClientSize() ?
320 rect
.height
= size
.y
;
322 wxWindow
* const parent
= GetParent();
323 if ( HasTransparentBackground() && parent
)
325 wxASSERT( !IsTopLevel() );
327 wxPoint pos
= GetPosition();
329 AdjustForParentClientOrigin( pos
.x
, pos
.y
, 0 );
331 // Adjust DC logical origin
332 wxCoord org_x
, org_y
, x
, y
;
333 dc
.GetLogicalOrigin( &org_x
, &org_y
);
336 dc
.SetLogicalOrigin( x
, y
);
342 // Let parent draw the background
343 parent
->EraseBackground( dc
, rect
);
345 // Restore DC logical origin
346 dc
.SetLogicalOrigin( org_x
, org_y
);
350 // Draw background ourselves
351 EraseBackground( dc
, rect
);
357 void wxWindow::EraseBackground(wxDC
& dc
, const wxRect
& rect
)
359 if ( GetBackgroundBitmap().Ok() )
361 // Get the bitmap and the flags
364 wxBitmap bmp
= GetBackgroundBitmap(&alignment
, &stretch
);
365 wxControlRenderer::DrawBitmap(dc
, bmp
, rect
, alignment
, stretch
);
369 // Just fill it with bg colour if no bitmap
371 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this),
372 rect
, GetStateFlags());
376 void wxWindow::DoDrawBorder(wxDC
& dc
, const wxRect
& rect
)
378 // draw outline unless the update region is enitrely inside it in which
379 // case we don't need to do it
380 #if 0 // doesn't seem to work, why?
381 if ( wxRegion(rect
).Contains(GetUpdateRegion().GetBox()) != wxInRegion
)
384 m_renderer
->DrawBorder(dc
, GetBorder(), rect
, GetStateFlags());
388 void wxWindow::DoDraw(wxControlRenderer
* WXUNUSED(renderer
))
392 void wxWindow::Refresh(bool eraseBackground
, const wxRect
*rectClient
)
395 wxPoint pt
= GetClientAreaOrigin();
397 wxSize size
= GetClientSize();
401 rectWin
= *rectClient
;
403 // don't refresh anything beyond the client area (scrollbars for
405 if ( rectWin
.GetRight() > size
.x
)
406 rectWin
.SetRight(size
.x
);
407 if ( rectWin
.GetBottom() > size
.y
)
408 rectWin
.SetBottom(size
.y
);
412 else // refresh the entire client area
416 rectWin
.width
= size
.x
;
417 rectWin
.height
= size
.y
;
421 #ifdef WXDEBUG_REFRESH
422 static bool s_refreshDebug
= false;
423 if ( s_refreshDebug
)
426 dc
.SetBrush(*wxCYAN_BRUSH
);
427 dc
.SetPen(*wxTRANSPARENT_PEN
);
428 dc
.DrawRectangle(rectWin
);
430 // under Unix we use "--sync" X option for this
431 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
436 #endif // WXDEBUG_REFRESH
438 wxWindowNative::Refresh(eraseBackground
, &rectWin
);
440 // Refresh all sub controls if any.
441 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
444 wxWindow
*win
= node
->GetData();
445 // Only refresh sub controls when it is visible
446 // and when it is in the update region.
447 if(!win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)) && win
->IsShown() && wxRegion(rectWin
).Contains(win
->GetRect()) != wxOutRegion
)
448 win
->Refresh(eraseBackground
, &rectWin
);
450 node
= node
->GetNext();
454 // ----------------------------------------------------------------------------
456 // ----------------------------------------------------------------------------
458 bool wxWindow::Enable(bool enable
)
460 if ( !wxWindowNative::Enable(enable
) )
463 // disabled window can't keep focus
464 if ( FindFocus() == this && GetParent() != NULL
)
466 GetParent()->SetFocus();
471 // a window with renderer is drawn by ourselves and it has to be
472 // refreshed to reflect its new status
479 bool wxWindow::IsFocused() const
481 return FindFocus() == this;
484 bool wxWindow::IsPressed() const
489 bool wxWindow::IsDefault() const
494 bool wxWindow::IsCurrent() const
499 bool wxWindow::SetCurrent(bool doit
)
501 if ( doit
== m_isCurrent
)
506 if ( CanBeHighlighted() )
512 int wxWindow::GetStateFlags() const
516 flags
|= wxCONTROL_DISABLED
;
518 // the following states are only possible if our application is active - if
519 // it is not, even our default/focused controls shouldn't appear as such
520 if ( wxTheApp
->IsActive() )
523 flags
|= wxCONTROL_CURRENT
;
525 flags
|= wxCONTROL_FOCUSED
;
527 flags
|= wxCONTROL_PRESSED
;
529 flags
|= wxCONTROL_ISDEFAULT
;
535 // ----------------------------------------------------------------------------
537 // ----------------------------------------------------------------------------
539 void wxWindow::OnSize(wxSizeEvent
& event
)
544 if ( m_scrollbarVert
|| m_scrollbarHorz
)
546 PositionScrollbars();
548 #endif // wxUSE_SCROLLBAR
550 #if 0 // ndef __WXMSW__
551 // Refresh the area (strip) previously occupied by the border
553 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) && IsShown() )
555 // This code assumes that wxSizeEvent.GetSize() returns
556 // the area of the entire window, not just the client
558 wxSize newSize
= event
.GetSize();
560 if (m_oldSize
.x
== wxDefaultCoord
&& m_oldSize
.y
== wxDefaultCoord
)
566 if (HasFlag( wxSIMPLE_BORDER
))
568 if (newSize
.y
> m_oldSize
.y
)
572 rect
.width
= m_oldSize
.x
;
573 rect
.y
= m_oldSize
.y
-2;
575 Refresh( true, &rect
);
577 else if (newSize
.y
< m_oldSize
.y
)
583 rect
.width
= newSize
.x
;
584 wxWindowNative::Refresh( true, &rect
);
587 if (newSize
.x
> m_oldSize
.x
)
591 rect
.height
= m_oldSize
.y
;
592 rect
.x
= m_oldSize
.x
-2;
594 Refresh( true, &rect
);
596 else if (newSize
.x
< m_oldSize
.x
)
602 rect
.height
= newSize
.y
;
603 wxWindowNative::Refresh( true, &rect
);
607 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
609 if (newSize
.y
> m_oldSize
.y
)
613 rect
.width
= m_oldSize
.x
;
614 rect
.y
= m_oldSize
.y
-4;
616 Refresh( true, &rect
);
618 else if (newSize
.y
< m_oldSize
.y
)
624 rect
.width
= newSize
.x
;
625 wxWindowNative::Refresh( true, &rect
);
628 if (newSize
.x
> m_oldSize
.x
)
632 rect
.height
= m_oldSize
.y
;
633 rect
.x
= m_oldSize
.x
-4;
635 Refresh( true, &rect
);
637 else if (newSize
.x
< m_oldSize
.x
)
643 rect
.height
= newSize
.y
;
644 wxWindowNative::Refresh( true, &rect
);
653 wxSize
wxWindow::DoGetBestSize() const
655 return AdjustSize(DoGetBestClientSize());
658 wxSize
wxWindow::DoGetBestClientSize() const
660 return wxWindowNative::DoGetBestSize();
663 wxSize
wxWindow::AdjustSize(const wxSize
& size
) const
667 m_renderer
->AdjustSize(&sz
, this);
671 wxPoint
wxWindow::GetClientAreaOrigin() const
673 wxPoint pt
= wxWindowBase::GetClientAreaOrigin();
675 #if wxUSE_TWO_WINDOWS
678 pt
+= m_renderer
->GetBorderDimensions(GetBorder()).GetPosition();
684 void wxWindow::DoGetClientSize(int *width
, int *height
) const
686 // if it is a native window, we assume it handles the scrollbars itself
687 // too - and if it doesn't, there is not much we can do
690 wxWindowNative::DoGetClientSize(width
, height
);
696 wxWindowNative::DoGetClientSize(&w
, &h
);
698 // we assume that the scrollbars are positioned correctly (by a previous
699 // call to PositionScrollbars()) here
703 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
705 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
710 // in any case, take account of the scrollbar
711 if ( m_scrollbarVert
)
712 w
-= m_scrollbarVert
->GetSize().x
;
713 #endif // wxUSE_SCROLLBAR
715 // if we don't have scrollbar or if it is outside the border (and not
716 // blended into it), take account of the right border as well
720 #endif // wxUSE_SCROLLBAR
722 w
-= rectBorder
.width
;
724 // and always account for the left border
725 *width
= w
- rectBorder
.x
;
727 // we shouldn't return invalid width
735 if ( m_scrollbarHorz
)
736 h
-= m_scrollbarHorz
->GetSize().y
;
737 #endif // wxUSE_SCROLLBAR
742 #endif // wxUSE_SCROLLBAR
744 h
-= rectBorder
.height
;
746 *height
= h
- rectBorder
.y
;
748 // we shouldn't return invalid height
754 void wxWindow::DoSetClientSize(int width
, int height
)
756 // take into account the borders
757 wxRect rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
758 width
+= rectBorder
.x
;
759 height
+= rectBorder
.y
;
761 // and the scrollbars (as they may be offset into the border, use the
762 // scrollbar position, not size - this supposes that PositionScrollbars()
763 // had been called before)
764 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
765 wxSize size
= GetSize();
767 if ( m_scrollbarVert
)
768 width
+= size
.x
- m_scrollbarVert
->GetPosition().x
;
769 #endif // wxUSE_SCROLLBAR
773 #endif // wxUSE_SCROLLBAR
775 width
+= rectBorder
.width
;
778 if ( m_scrollbarHorz
)
779 height
+= size
.y
- m_scrollbarHorz
->GetPosition().y
;
780 #endif // wxUSE_SCROLLBAR
784 #endif // wxUSE_SCROLLBAR
786 height
+= rectBorder
.height
;
788 wxWindowNative::DoSetClientSize(width
, height
);
791 wxHitTest
wxWindow::DoHitTest(wxCoord x
, wxCoord y
) const
793 wxHitTest ht
= wxWindowNative::DoHitTest(x
, y
);
796 if ( ht
== wxHT_WINDOW_INSIDE
)
798 if ( m_scrollbarVert
&& x
>= m_scrollbarVert
->GetPosition().x
)
800 // it can still be changed below because it may also be the corner
801 ht
= wxHT_WINDOW_VERT_SCROLLBAR
;
804 if ( m_scrollbarHorz
&& y
>= m_scrollbarHorz
->GetPosition().y
)
806 ht
= ht
== wxHT_WINDOW_VERT_SCROLLBAR
? wxHT_WINDOW_CORNER
807 : wxHT_WINDOW_HORZ_SCROLLBAR
;
810 #endif // wxUSE_SCROLLBAR
815 // ----------------------------------------------------------------------------
816 // scrolling: we implement it entirely ourselves except for ScrollWindow()
817 // function which is supposed to be (efficiently) implemented by the native
819 // ----------------------------------------------------------------------------
821 void wxWindow::RefreshScrollbars()
824 if ( m_scrollbarHorz
)
825 m_scrollbarHorz
->Refresh();
827 if ( m_scrollbarVert
)
828 m_scrollbarVert
->Refresh();
829 #endif // wxUSE_SCROLLBAR
832 void wxWindow::PositionScrollbars()
835 // do not use GetClientSize/Rect as it relies on the scrollbars being
836 // correctly positioned
838 wxSize size
= GetSize();
839 wxBorder border
= GetBorder();
840 wxRect rectBorder
= m_renderer
->GetBorderDimensions(border
);
841 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
843 int height
= m_scrollbarHorz
? m_scrollbarHorz
->GetSize().y
: 0;
844 int width
= m_scrollbarVert
? m_scrollbarVert
->GetSize().x
: 0;
847 if ( m_scrollbarVert
)
849 rectBar
.x
= size
.x
- width
;
851 rectBar
.x
-= rectBorder
.width
;
852 rectBar
.width
= width
;
855 rectBar
.y
+= rectBorder
.y
;
856 rectBar
.height
= size
.y
- height
;
858 rectBar
.height
-= rectBorder
.y
+ rectBorder
.height
;
860 m_scrollbarVert
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
863 if ( m_scrollbarHorz
)
865 rectBar
.y
= size
.y
- height
;
867 rectBar
.y
-= rectBorder
.height
;
868 rectBar
.height
= height
;
871 rectBar
.x
+= rectBorder
.x
;
872 rectBar
.width
= size
.x
- width
;
874 rectBar
.width
-= rectBorder
.x
+ rectBorder
.width
;
876 m_scrollbarHorz
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
880 #endif // wxUSE_SCROLLBAR
883 void wxWindow::SetScrollbar(int orient
,
890 wxASSERT_MSG( pageSize
<= range
,
891 _T("page size can't be greater than range") );
893 bool hasClientSizeChanged
= false;
894 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
895 if ( range
&& (pageSize
< range
) )
900 #if wxUSE_TWO_WINDOWS
901 SetInsertIntoMain( true );
903 scrollbar
= new wxScrollBar(this, wxID_ANY
,
904 wxDefaultPosition
, wxDefaultSize
,
905 orient
& wxVERTICAL
? wxSB_VERTICAL
907 #if wxUSE_TWO_WINDOWS
908 SetInsertIntoMain( false );
910 if ( orient
& wxVERTICAL
)
911 m_scrollbarVert
= scrollbar
;
913 m_scrollbarHorz
= scrollbar
;
915 // the client area diminished as we created a scrollbar
916 hasClientSizeChanged
= true;
918 PositionScrollbars();
920 else if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
922 // we might have disabled it before
926 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
928 else // no range means no scrollbar
932 // wxALWAYS_SHOW_SB only applies to the vertical scrollbar
933 if ( (orient
& wxVERTICAL
) && (GetWindowStyle() & wxALWAYS_SHOW_SB
) )
935 // just disable the scrollbar
936 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
937 scrollbar
->Disable();
939 else // really remove the scrollbar
943 if ( orient
& wxVERTICAL
)
944 m_scrollbarVert
= NULL
;
946 m_scrollbarHorz
= NULL
;
948 // the client area increased as we removed a scrollbar
949 hasClientSizeChanged
= true;
951 // the size of the remaining scrollbar must be adjusted
952 if ( m_scrollbarHorz
|| m_scrollbarVert
)
954 PositionScrollbars();
960 // give the window a chance to relayout
961 if ( hasClientSizeChanged
)
963 #if wxUSE_TWO_WINDOWS
964 wxWindowNative::SetSize( GetSize() );
966 wxSizeEvent
event(GetSize());
967 (void)GetEventHandler()->ProcessEvent(event
);
973 wxUnusedVar(pageSize
);
975 wxUnusedVar(refresh
);
976 #endif // wxUSE_SCROLLBAR
979 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
982 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
985 scrollbar
->SetThumbPosition(pos
);
987 // VZ: I think we can safely ignore this as we always refresh it
988 // automatically whenever the value chanegs
996 #endif // wxUSE_SCROLLBAR
999 int wxWindow::GetScrollPos(int orient
) const
1002 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
1003 return scrollbar
? scrollbar
->GetThumbPosition() : 0;
1005 wxUnusedVar(orient
);
1007 #endif // wxUSE_SCROLLBAR
1010 int wxWindow::GetScrollThumb(int orient
) const
1013 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
1014 return scrollbar
? scrollbar
->GetThumbSize() : 0;
1016 wxUnusedVar(orient
);
1018 #endif // wxUSE_SCROLLBAR
1021 int wxWindow::GetScrollRange(int orient
) const
1024 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
1025 return scrollbar
? scrollbar
->GetRange() : 0;
1027 wxUnusedVar(orient
);
1029 #endif // wxUSE_SCROLLBAR
1032 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1034 // use native scrolling when available and do it in generic way
1038 wxWindowNative::ScrollWindow(dx
, dy
, rect
);
1042 // before scrolling it, ensure that we don't have any unpainted areas
1049 r
= ScrollNoRefresh(dx
, 0, rect
);
1050 Refresh(true /* erase bkgnd */, &r
);
1055 r
= ScrollNoRefresh(0, dy
, rect
);
1056 Refresh(true /* erase bkgnd */, &r
);
1059 // scroll children accordingly:
1060 wxPoint
offset(dx
, dy
);
1062 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1063 node
; node
= node
->GetNext())
1065 wxWindow
*child
= node
->GetData();
1067 if ( child
== m_scrollbarVert
|| child
== m_scrollbarHorz
)
1069 #endif // wxUSE_SCROLLBAR
1071 // VS: Scrolling children has non-trivial semantics. If rect=NULL then
1072 // it is easy: we scroll all children. Otherwise it gets
1074 // 1. if scrolling in one direction only, scroll only
1075 // those children that intersect shaft defined by the rectangle
1076 // and scrolling direction
1077 // 2. if scrolling in both axes, scroll all children
1079 if ( rect
&& (dx
* dy
== 0 /* moving in only one of x, y axis */) )
1081 wxRect childRect
= child
->GetRect();
1082 if ( dx
== 0 && (childRect
.GetLeft() <= rect
->GetRight() ||
1083 childRect
.GetRight() >= rect
->GetLeft()) )
1085 child
->Move(child
->GetPosition() + offset
);
1087 else if ( dy
== 0 && (childRect
.GetTop() <= rect
->GetBottom() ||
1088 childRect
.GetBottom() >= rect
->GetTop()) )
1090 child
->Move(child
->GetPosition() + offset
);
1095 child
->Move(child
->GetPosition() + offset
);
1098 #endif // wxX11/!wxX11
1101 wxRect
wxWindow::ScrollNoRefresh(int dx
, int dy
, const wxRect
*rectTotal
)
1103 wxASSERT_MSG( !dx
|| !dy
, _T("can't be used for diag scrolling") );
1105 // the rect to refresh (which we will calculate)
1114 // calculate the part of the window which we can just redraw in the new
1116 wxSize sizeTotal
= rectTotal
? rectTotal
->GetSize() : GetClientSize();
1118 wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
1119 sizeTotal
.x
, sizeTotal
.y
, dx
, dy
);
1121 // the initial and end point of the region we move in client coords
1122 wxPoint ptSource
, ptDest
;
1125 ptSource
= rectTotal
->GetPosition();
1126 ptDest
= rectTotal
->GetPosition();
1129 // the size of this region
1131 size
.x
= sizeTotal
.x
- abs(dx
);
1132 size
.y
= sizeTotal
.y
- abs(dy
);
1133 if ( size
.x
<= 0 || size
.y
<= 0 )
1135 // just redraw everything as nothing of the displayed image will stay
1136 wxLogTrace(_T("scroll"), _T("refreshing everything"));
1138 rect
= rectTotal
? *rectTotal
: wxRect(0, 0, sizeTotal
.x
, sizeTotal
.y
);
1140 else // move the part which doesn't change to the new location
1142 // note that when we scroll the canvas in some direction we move the
1143 // block which doesn't need to be refreshed in the opposite direction
1147 // scroll to the right, move to the left
1152 // scroll to the left, move to the right
1158 // scroll down, move up
1163 // scroll up, move down
1168 // we need to hide the caret before moving or it will erase itself at
1169 // the wrong (old) location
1170 wxCaret
*caret
= GetCaret();
1173 #endif // wxUSE_CARET
1176 wxClientDC
dc(this);
1177 wxBitmap
bmp(size
.x
, size
.y
);
1179 dcMem
.SelectObject(bmp
);
1181 dcMem
.Blit(wxPoint(0,0), size
, &dc
, ptSource
1182 #if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
1183 + GetClientAreaOrigin()
1184 #endif // broken wxGTK wxDC::Blit
1186 dc
.Blit(ptDest
, size
, &dcMem
, wxPoint(0,0));
1188 wxLogTrace(_T("scroll"),
1189 _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
1190 ptSource
.x
, ptSource
.y
,
1192 ptDest
.x
, ptDest
.y
);
1194 // and now repaint the uncovered area
1196 // FIXME: We repaint the intersection of these rectangles twice - is
1197 // it bad? I don't think so as it is rare to scroll the window
1198 // diagonally anyhow and so adding extra logic to compute
1199 // rectangle intersection is probably not worth the effort
1201 rect
.x
= ptSource
.x
;
1202 rect
.y
= ptSource
.y
;
1208 // refresh the area along the right border
1209 rect
.x
+= size
.x
+ dx
;
1214 // refresh the area along the left border
1218 rect
.height
= sizeTotal
.y
;
1220 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1222 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1229 // refresh the area along the bottom border
1230 rect
.y
+= size
.y
+ dy
;
1235 // refresh the area along the top border
1239 rect
.width
= sizeTotal
.x
;
1241 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1243 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1249 #endif // wxUSE_CARET
1255 // ----------------------------------------------------------------------------
1256 // accelerators and menu hot keys
1257 // ----------------------------------------------------------------------------
1260 // the last window over which Alt was pressed (used by OnKeyUp)
1261 wxWindow
*wxWindow::ms_winLastAltPress
= NULL
;
1262 #endif // wxUSE_MENUS
1264 #if wxUSE_ACCEL || wxUSE_MENUS
1266 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1269 int key
= event
.GetKeyCode();
1270 if ( !event
.ControlDown() && (key
== WXK_ALT
|| key
== WXK_F10
) )
1272 ms_winLastAltPress
= this;
1274 // it can't be an accel anyhow
1278 ms_winLastAltPress
= NULL
;
1279 #endif // wxUSE_MENUS
1282 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
1284 int command
= win
->GetAcceleratorTable()->GetCommand(event
);
1285 if ( command
!= -1 )
1287 wxCommandEvent
eventCmd(wxEVT_COMMAND_MENU_SELECTED
, command
);
1288 if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) )
1290 // skip "event.Skip()" below
1295 if ( win
->IsTopLevel() )
1297 // try the frame menu bar
1299 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1302 wxMenuBar
*menubar
= frame
->GetMenuBar();
1303 if ( menubar
&& menubar
->ProcessAccelEvent(event
) )
1305 // skip "event.Skip()" below
1309 #endif // wxUSE_MENUS
1311 // if it wasn't in a menu, try to find a button
1312 if ( command
!= -1 )
1314 wxWindow
* child
= win
->FindWindow(command
);
1315 if ( child
&& wxDynamicCast(child
, wxButton
) )
1317 wxCommandEvent
eventCmd(wxEVT_COMMAND_BUTTON_CLICKED
, command
);
1318 eventCmd
.SetEventObject(child
);
1319 if ( child
->GetEventHandler()->ProcessEvent(eventCmd
) )
1321 // skip "event.Skip()" below
1327 // don't propagate accels from the child frame to the parent one
1331 #endif // wxUSE_ACCEL
1336 #endif // wxUSE_ACCEL
1340 wxMenuBar
*wxWindow::GetParentFrameMenuBar() const
1342 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
1344 if ( win
->IsTopLevel() )
1346 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1349 return frame
->GetMenuBar();
1352 // don't look further - we don't want to return the menubar of the
1361 void wxWindow::OnChar(wxKeyEvent
& event
)
1363 if ( event
.AltDown() && !event
.ControlDown() )
1365 int key
= event
.GetKeyCode();
1367 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1370 int item
= menubar
->FindNextItemForAccel(-1, key
);
1373 menubar
->PopupMenu((size_t)item
);
1375 // skip "event.Skip()" below
1384 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1386 int key
= event
.GetKeyCode();
1387 if ( !event
.HasModifiers() && (key
== WXK_ALT
|| key
== WXK_F10
) )
1389 // only process Alt release specially if there were no other key
1390 // presses since Alt had been pressed and if both events happened in
1392 if ( ms_winLastAltPress
== this )
1394 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1395 if ( menubar
&& this != menubar
)
1397 menubar
->SelectMenu(0);
1406 // in any case reset it
1407 ms_winLastAltPress
= NULL
;
1410 #endif // wxUSE_MENUS
1412 // ----------------------------------------------------------------------------
1413 // MSW-specific section
1414 // ----------------------------------------------------------------------------
1418 #include "wx/msw/private.h"
1420 WXLRESULT
wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1422 if ( message
== WM_NCHITTEST
)
1424 // the windows which contain the other windows should let the mouse
1425 // events through, otherwise a window inside a static box would
1426 // never get any events at all
1427 if ( IsStaticBox() )
1429 return HTTRANSPARENT
;
1433 return wxWindowNative::MSWWindowProc(message
, wParam
, lParam
);