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 license
10 ///////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
21 #pragma implementation "univwindow.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/window.h"
34 #include "wx/dcclient.h"
35 #include "wx/dcmemory.h"
37 #include "wx/scrolbar.h"
43 #include "wx/univ/colschem.h"
44 #include "wx/univ/renderer.h"
45 #include "wx/univ/theme.h"
51 // turn Refresh() debugging on/off
52 #define WXDEBUG_REFRESH
55 #undef WXDEBUG_REFRESH
58 #if defined(WXDEBUG_REFRESH) && defined(__WXMSW__) && !defined(__WXMICROWIN__)
59 #include "wx/msw/private.h"
62 // ============================================================================
64 // ============================================================================
66 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
70 // we can't use wxWindowNative here as it won't be expanded inside the macro
71 #if defined(__WXMSW__)
72 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowMSW
)
73 #elif defined(__WXGTK__)
74 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowGTK
)
75 #elif defined(__WXMGL__)
76 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowMGL
)
77 #elif defined(__WXX11__)
78 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowX11
)
79 #elif defined(__WXPM__)
80 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowOS2
)
83 BEGIN_EVENT_TABLE(wxWindow
, wxWindowNative
)
84 EVT_SIZE(wxWindow::OnSize
)
86 #if wxUSE_ACCEL || wxUSE_MENUS
87 EVT_KEY_DOWN(wxWindow::OnKeyDown
)
91 EVT_CHAR(wxWindow::OnChar
)
92 EVT_KEY_UP(wxWindow::OnKeyUp
)
95 EVT_PAINT(wxWindow::OnPaint
)
96 EVT_NC_PAINT(wxWindow::OnNcPaint
)
97 EVT_ERASE_BACKGROUND(wxWindow::OnErase
)
100 // ----------------------------------------------------------------------------
102 // ----------------------------------------------------------------------------
104 void wxWindow::Init()
107 m_scrollbarHorz
= (wxScrollBar
*)NULL
;
111 m_renderer
= wxTheme::Get()->GetRenderer();
117 bool wxWindow::Create(wxWindow
*parent
,
122 const wxString
& name
)
124 // we add wxCLIP_CHILDREN to get the same ("natural") behaviour under MSW
125 // as under the other platforms
126 if ( !wxWindowNative::Create(parent
, id
, pos
, size
,
127 style
| wxCLIP_CHILDREN
,
133 // if we should always have the scrollbar, do show it
134 if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
136 #if wxUSE_TWO_WINDOWS
137 SetInsertIntoMain( TRUE
);
139 m_scrollbarVert
= new wxScrollBar(this, -1,
140 wxDefaultPosition
, wxDefaultSize
,
142 #if wxUSE_TWO_WINDOWS
143 SetInsertIntoMain( FALSE
);
147 PositionScrollbars();
153 // ----------------------------------------------------------------------------
155 // ----------------------------------------------------------------------------
157 void wxWindow::SetBackground(const wxBitmap
& bitmap
,
162 m_alignBgBitmap
= alignment
;
163 m_stretchBgBitmap
= stretch
;
166 const wxBitmap
& wxWindow::GetBackgroundBitmap(int *alignment
,
167 wxStretch
*stretch
) const
169 if ( m_bitmapBg
.Ok() )
172 *alignment
= m_alignBgBitmap
;
174 *stretch
= m_stretchBgBitmap
;
180 // ----------------------------------------------------------------------------
182 // ----------------------------------------------------------------------------
184 // the event handlers executed when the window must be repainted
185 void wxWindow::OnNcPaint(wxPaintEvent
& event
)
189 // get the window rect
191 wxSize size
= GetSize();
195 rect
.height
= size
.y
;
197 // if the scrollbars are outside the border, we must adjust the rect to
199 if ( !m_renderer
->AreScrollbarsInsideBorder() )
201 wxScrollBar
*scrollbar
= GetScrollbar(wxVERTICAL
);
203 rect
.width
-= scrollbar
->GetSize().x
;
205 scrollbar
= GetScrollbar(wxHORIZONTAL
);
207 rect
.height
-= scrollbar
->GetSize().y
;
210 // get the DC and draw the border on it
212 DoDrawBorder(dc
, rect
);
216 void wxWindow::OnPaint(wxPaintEvent
& event
)
220 // it is a native control which paints itself
225 // get the DC to use and create renderer on it
227 wxControlRenderer
renderer(this, dc
, m_renderer
);
234 // the event handler executed when the window background must be painted
235 void wxWindow::OnErase(wxEraseEvent
& event
)
244 DoDrawBackground(*event
.GetDC());
246 // if we have both scrollbars, we also have a square in the corner between
247 // them which we must paint
248 if ( m_scrollbarVert
&& m_scrollbarHorz
)
250 wxSize size
= GetSize();
251 wxRect rectClient
= GetClientRect(),
252 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
255 rectCorner
.x
= rectClient
.GetRight() + 1;
256 rectCorner
.y
= rectClient
.GetBottom() + 1;
257 rectCorner
.SetRight(size
.x
- rectBorder
.width
);
258 rectCorner
.SetBottom(size
.y
- rectBorder
.height
);
260 if ( GetUpdateRegion().Contains(rectCorner
) )
262 m_renderer
->DrawScrollCorner(*event
.GetDC(), rectCorner
);
267 bool wxWindow::DoDrawBackground(wxDC
& dc
)
271 wxSize size
= GetSize(); // Why not GetClientSize() ?
275 rect
.height
= size
.y
;
277 if (HasTransparentBackground() && GetParent() && GetParent()->ProvidesBackground())
279 wxASSERT( !IsTopLevel() );
281 wxPoint pos
= GetPosition();
283 AdjustForParentClientOrigin( pos
.x
, pos
.y
, 0 );
285 // Adjust DC logical origin
287 dc
.GetLogicalOrigin( &x
, &y
);
290 dc
.SetLogicalOrigin( x
, y
);
296 // Let parent draw the background
297 GetParent()->EraseBackground( dc
, rect
);
301 // Draw background ouselves
302 EraseBackground( dc
, rect
);
308 void wxWindow::EraseBackground(wxDC
& dc
, const wxRect
& rect
)
310 if ( GetBackgroundBitmap().Ok() )
312 // Get the bitmap and the flags
315 wxBitmap bmp
= GetBackgroundBitmap(&alignment
, &stretch
);
316 wxControlRenderer::DrawBitmap(dc
, bmp
, rect
, alignment
, stretch
);
320 // Just fill it with bg colour if no bitmap
322 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this),
323 rect
, GetStateFlags());
327 void wxWindow::DoDrawBorder(wxDC
& dc
, const wxRect
& rect
)
329 // draw outline unless the update region is enitrely inside it in which
330 // case we don't need to do it
331 #if 0 // doesn't seem to work, why?
332 if ( wxRegion(rect
).Contains(GetUpdateRegion().GetBox()) != wxInRegion
)
335 m_renderer
->DrawBorder(dc
, GetBorder(), rect
, GetStateFlags());
339 void wxWindow::DoDraw(wxControlRenderer
*renderer
)
343 void wxWindow::Refresh(bool eraseBackground
, const wxRect
*rectClient
)
346 wxPoint pt
= GetClientAreaOrigin();
348 wxSize size
= GetClientSize();
352 rectWin
= *rectClient
;
354 // don't refresh anything beyond the client area (scrollbars for
356 if ( rectWin
.GetRight() > size
.x
)
357 rectWin
.SetRight(size
.x
);
358 if ( rectWin
.GetBottom() > size
.y
)
359 rectWin
.SetBottom(size
.y
);
363 else // refresh the entire client area
367 rectWin
.width
= size
.x
;
368 rectWin
.height
= size
.y
;
372 #ifdef WXDEBUG_REFRESH
373 static bool s_refreshDebug
= FALSE
;
374 if ( s_refreshDebug
)
377 dc
.SetBrush(*wxCYAN_BRUSH
);
378 dc
.SetPen(*wxTRANSPARENT_PEN
);
379 dc
.DrawRectangle(rectWin
);
381 // under Unix we use "--sync" X option for this
382 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
387 #endif // WXDEBUG_REFRESH
389 wxWindowNative::Refresh(eraseBackground
, &rectWin
);
392 // ----------------------------------------------------------------------------
394 // ----------------------------------------------------------------------------
396 bool wxWindow::Enable(bool enable
)
398 if ( !wxWindowNative::Enable(enable
) )
401 // disabled window can't keep focus
402 if ( FindFocus() == this && GetParent() != NULL
)
404 GetParent()->SetFocus();
409 // a window with renderer is drawn by ourselves and it has to be
410 // refreshed to reflect its new status
417 bool wxWindow::IsFocused() const
419 wxWindow
*self
= wxConstCast(this, wxWindow
);
420 return self
->FindFocus() == self
;
423 bool wxWindow::IsPressed() const
428 bool wxWindow::IsDefault() const
433 bool wxWindow::IsCurrent() const
438 bool wxWindow::SetCurrent(bool doit
)
440 if ( doit
== m_isCurrent
)
445 if ( CanBeHighlighted() )
451 int wxWindow::GetStateFlags() const
455 flags
|= wxCONTROL_DISABLED
;
457 // the following states are only possible if our application is active - if
458 // it is not, even our default/focused controls shouldn't appear as such
459 if ( wxTheApp
->IsActive() )
462 flags
|= wxCONTROL_CURRENT
;
464 flags
|= wxCONTROL_FOCUSED
;
466 flags
|= wxCONTROL_PRESSED
;
468 flags
|= wxCONTROL_ISDEFAULT
;
474 // ----------------------------------------------------------------------------
476 // ----------------------------------------------------------------------------
478 void wxWindow::OnSize(wxSizeEvent
& event
)
482 if ( m_scrollbarVert
|| m_scrollbarHorz
)
484 PositionScrollbars();
487 #if 0 // ndef __WXMSW__
488 // Refresh the area (strip) previously occupied by the border
490 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE
) && IsShown())
492 // This code assumes that wxSizeEvent.GetSize() returns
493 // the area of the entire window, not just the client
495 wxSize newSize
= event
.GetSize();
497 if (m_oldSize
.x
== -1 && m_oldSize
.y
== -1)
503 if (HasFlag( wxSIMPLE_BORDER
))
505 if (newSize
.y
> m_oldSize
.y
)
509 rect
.width
= m_oldSize
.x
;
510 rect
.y
= m_oldSize
.y
-2;
512 Refresh( TRUE
, &rect
);
514 else if (newSize
.y
< m_oldSize
.y
)
520 rect
.width
= newSize
.x
;
521 wxWindowNative::Refresh( TRUE
, &rect
);
524 if (newSize
.x
> m_oldSize
.x
)
528 rect
.height
= m_oldSize
.y
;
529 rect
.x
= m_oldSize
.x
-2;
531 Refresh( TRUE
, &rect
);
533 else if (newSize
.x
< m_oldSize
.x
)
539 rect
.height
= newSize
.y
;
540 wxWindowNative::Refresh( TRUE
, &rect
);
544 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
546 if (newSize
.y
> m_oldSize
.y
)
550 rect
.width
= m_oldSize
.x
;
551 rect
.y
= m_oldSize
.y
-4;
553 Refresh( TRUE
, &rect
);
555 else if (newSize
.y
< m_oldSize
.y
)
561 rect
.width
= newSize
.x
;
562 wxWindowNative::Refresh( TRUE
, &rect
);
565 if (newSize
.x
> m_oldSize
.x
)
569 rect
.height
= m_oldSize
.y
;
570 rect
.x
= m_oldSize
.x
-4;
572 Refresh( TRUE
, &rect
);
574 else if (newSize
.x
< m_oldSize
.x
)
580 rect
.height
= newSize
.y
;
581 wxWindowNative::Refresh( TRUE
, &rect
);
590 wxSize
wxWindow::DoGetBestSize() const
592 return AdjustSize(DoGetBestClientSize());
595 wxSize
wxWindow::DoGetBestClientSize() const
597 return wxWindowNative::DoGetBestSize();
600 wxSize
wxWindow::AdjustSize(const wxSize
& size
) const
604 m_renderer
->AdjustSize(&sz
, this);
608 wxPoint
wxWindow::GetClientAreaOrigin() const
610 wxPoint pt
= wxWindowBase::GetClientAreaOrigin();
612 #if wxUSE_TWO_WINDOWS
615 pt
+= m_renderer
->GetBorderDimensions(GetBorder()).GetPosition();
621 void wxWindow::DoGetClientSize(int *width
, int *height
) const
623 // if it is a native window, we assume it handles the scrollbars itself
624 // too - and if it doesn't, there is not much we can do
627 wxWindowNative::DoGetClientSize(width
, height
);
633 wxWindowNative::DoGetClientSize(&w
, &h
);
635 // we assume that the scrollbars are positioned correctly (by a previous
636 // call to PositionScrollbars()) here
640 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
642 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
646 // in any case, take account of the scrollbar
647 if ( m_scrollbarVert
)
648 w
-= m_scrollbarVert
->GetSize().x
;
650 // if we don't have scrollbar or if it is outside the border (and not
651 // blended into it), take account of the right border as well
652 if ( !m_scrollbarVert
|| inside
)
653 w
-= rectBorder
.width
;
655 // and always account for the left border
656 *width
= w
- rectBorder
.x
;
658 // we shouldn't return invalid width
665 if ( m_scrollbarHorz
)
666 h
-= m_scrollbarHorz
->GetSize().y
;
668 if ( !m_scrollbarHorz
|| inside
)
669 h
-= rectBorder
.height
;
671 *height
= h
- rectBorder
.y
;
673 // we shouldn't return invalid height
679 void wxWindow::DoSetClientSize(int width
, int height
)
681 // take into account the borders
682 wxRect rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
683 width
+= rectBorder
.x
;
684 height
+= rectBorder
.y
;
686 // and the scrollbars (as they may be offset into the border, use the
687 // scrollbar position, not size - this supposes that PositionScrollbars()
688 // had been called before)
689 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
690 wxSize size
= GetSize();
691 if ( m_scrollbarVert
)
692 width
+= size
.x
- m_scrollbarVert
->GetPosition().x
;
693 if ( !m_scrollbarVert
|| inside
)
694 width
+= rectBorder
.width
;
696 if ( m_scrollbarHorz
)
697 height
+= size
.y
- m_scrollbarHorz
->GetPosition().y
;
698 if ( !m_scrollbarHorz
|| inside
)
699 height
+= rectBorder
.height
;
701 wxWindowNative::DoSetClientSize(width
, height
);
704 wxHitTest
wxWindow::DoHitTest(wxCoord x
, wxCoord y
) const
706 wxHitTest ht
= wxWindowNative::DoHitTest(x
, y
);
707 if ( ht
== wxHT_WINDOW_INSIDE
)
709 if ( m_scrollbarVert
&& x
>= m_scrollbarVert
->GetPosition().x
)
711 // it can still be changed below because it may also be the corner
712 ht
= wxHT_WINDOW_VERT_SCROLLBAR
;
715 if ( m_scrollbarHorz
&& y
>= m_scrollbarHorz
->GetPosition().y
)
717 ht
= ht
== wxHT_WINDOW_VERT_SCROLLBAR
? wxHT_WINDOW_CORNER
718 : wxHT_WINDOW_HORZ_SCROLLBAR
;
725 // ----------------------------------------------------------------------------
726 // scrolling: we implement it entirely ourselves except for ScrollWindow()
727 // function which is supposed to be (efficiently) implemented by the native
729 // ----------------------------------------------------------------------------
731 void wxWindow::RefreshScrollbars()
733 if ( m_scrollbarHorz
)
734 m_scrollbarHorz
->Refresh();
736 if ( m_scrollbarVert
)
737 m_scrollbarVert
->Refresh();
740 void wxWindow::PositionScrollbars()
742 // do not use GetClientSize/Rect as it relies on the scrollbars being
743 // correctly positioned
745 wxSize size
= GetSize();
746 wxBorder border
= GetBorder();
747 wxRect rectBorder
= m_renderer
->GetBorderDimensions(border
);
748 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
750 int height
= m_scrollbarHorz
? m_scrollbarHorz
->GetSize().y
: 0;
751 int width
= m_scrollbarVert
? m_scrollbarVert
->GetSize().x
: 0;
754 if ( m_scrollbarVert
)
756 rectBar
.x
= size
.x
- width
;
758 rectBar
.x
-= rectBorder
.width
;
759 rectBar
.width
= width
;
762 rectBar
.y
+= rectBorder
.y
;
763 rectBar
.height
= size
.y
- height
;
765 rectBar
.height
-= rectBorder
.y
+ rectBorder
.height
;
767 m_scrollbarVert
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
770 if ( m_scrollbarHorz
)
772 rectBar
.y
= size
.y
- height
;
774 rectBar
.y
-= rectBorder
.height
;
775 rectBar
.height
= height
;
778 rectBar
.x
+= rectBorder
.x
;
779 rectBar
.width
= size
.x
- width
;
781 rectBar
.width
-= rectBorder
.x
+ rectBorder
.width
;
783 m_scrollbarHorz
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
789 void wxWindow::SetScrollbar(int orient
,
795 wxASSERT_MSG( pageSize
<= range
,
796 _T("page size can't be greater than range") );
798 bool hasClientSizeChanged
= FALSE
;
799 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
800 if ( range
&& (pageSize
< range
) )
805 #if wxUSE_TWO_WINDOWS
806 SetInsertIntoMain( TRUE
);
808 scrollbar
= new wxScrollBar(this, -1,
809 wxDefaultPosition
, wxDefaultSize
,
810 orient
& wxVERTICAL
? wxSB_VERTICAL
812 #if wxUSE_TWO_WINDOWS
813 SetInsertIntoMain( FALSE
);
815 if ( orient
& wxVERTICAL
)
816 m_scrollbarVert
= scrollbar
;
818 m_scrollbarHorz
= scrollbar
;
820 // the client area diminished as we created a scrollbar
821 hasClientSizeChanged
= TRUE
;
823 PositionScrollbars();
825 else if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
827 // we might have disabled it before
831 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
833 else // no range means no scrollbar
837 // wxALWAYS_SHOW_SB only applies to the vertical scrollbar
838 if ( (orient
& wxVERTICAL
) && (GetWindowStyle() & wxALWAYS_SHOW_SB
) )
840 // just disable the scrollbar
841 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
842 scrollbar
->Disable();
844 else // really remove the scrollbar
848 if ( orient
& wxVERTICAL
)
849 m_scrollbarVert
= NULL
;
851 m_scrollbarHorz
= NULL
;
853 // the client area increased as we removed a scrollbar
854 hasClientSizeChanged
= TRUE
;
856 // the size of the remaining scrollbar must be adjusted
857 if ( m_scrollbarHorz
|| m_scrollbarVert
)
859 PositionScrollbars();
865 // give the window a chance to relayout
866 if ( hasClientSizeChanged
)
868 #if wxUSE_TWO_WINDOWS
869 wxWindowNative::SetSize( GetSize() );
871 wxSizeEvent
event(GetSize());
872 (void)GetEventHandler()->ProcessEvent(event
);
877 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
879 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
880 wxCHECK_RET( scrollbar
, _T("no scrollbar to set position for") );
882 scrollbar
->SetThumbPosition(pos
);
884 // VZ: I think we can safely ignore this as we always refresh it
885 // automatically whenever the value chanegs
892 int wxWindow::GetScrollPos(int orient
) const
894 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
895 return scrollbar
? scrollbar
->GetThumbPosition() : 0;
898 int wxWindow::GetScrollThumb(int orient
) const
900 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
901 return scrollbar
? scrollbar
->GetThumbSize() : 0;
904 int wxWindow::GetScrollRange(int orient
) const
906 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
907 return scrollbar
? scrollbar
->GetRange() : 0;
910 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
912 // use native scrolling when available and do it in generic way
916 wxWindowNative::ScrollWindow(dx
, dy
, rect
);
920 // before scrolling it, ensure that we don't have any unpainted areas
927 r
= ScrollNoRefresh(dx
, 0, rect
);
928 Refresh(TRUE
/* erase bkgnd */, &r
);
933 r
= ScrollNoRefresh(0, dy
, rect
);
934 Refresh(TRUE
/* erase bkgnd */, &r
);
937 // scroll children accordingly:
938 wxPoint
offset(dx
, dy
);
940 for (wxWindowList::Node
*node
= GetChildren().GetFirst();
941 node
; node
= node
->GetNext())
943 wxWindow
*child
= node
->GetData();
944 if ( child
== m_scrollbarVert
|| child
== m_scrollbarHorz
)
947 // VS: Scrolling children has non-trivial semantics. If rect=NULL then
948 // it is easy: we scroll all children. Otherwise it gets
950 // 1. if scrolling in one direction only, scroll only
951 // those children that intersect shaft defined by the rectangle
952 // and scrolling direction
953 // 2. if scrolling in both axes, scroll all children
955 if ( rect
&& (dx
* dy
== 0 /* moving in only one of x, y axis */) )
957 wxRect childRect
= child
->GetRect();
958 if ( dx
== 0 && (childRect
.GetLeft() <= rect
->GetRight() ||
959 childRect
.GetRight() >= rect
->GetLeft()) )
961 child
->Move(child
->GetPosition() + offset
);
963 else if ( dy
== 0 && (childRect
.GetTop() <= rect
->GetBottom() ||
964 childRect
.GetBottom() >= rect
->GetTop()) )
966 child
->Move(child
->GetPosition() + offset
);
971 child
->Move(child
->GetPosition() + offset
);
977 wxRect
wxWindow::ScrollNoRefresh(int dx
, int dy
, const wxRect
*rectTotal
)
979 wxASSERT_MSG( !dx
|| !dy
, _T("can't be used for diag scrolling") );
981 // the rect to refresh (which we will calculate)
990 // calculate the part of the window which we can just redraw in the new
992 wxSize sizeTotal
= rectTotal
? rectTotal
->GetSize() : GetClientSize();
994 wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
995 sizeTotal
.x
, sizeTotal
.y
, dx
, dy
);
997 // the initial and end point of the region we move in client coords
998 wxPoint ptSource
, ptDest
;
1001 ptSource
= rectTotal
->GetPosition();
1002 ptDest
= rectTotal
->GetPosition();
1005 // the size of this region
1007 size
.x
= sizeTotal
.x
- abs(dx
);
1008 size
.y
= sizeTotal
.y
- abs(dy
);
1009 if ( size
.x
<= 0 || size
.y
<= 0 )
1011 // just redraw everything as nothing of the displayed image will stay
1012 wxLogTrace(_T("scroll"), _T("refreshing everything"));
1014 rect
= rectTotal
? *rectTotal
: wxRect(0, 0, sizeTotal
.x
, sizeTotal
.y
);
1016 else // move the part which doesn't change to the new location
1018 // note that when we scroll the canvas in some direction we move the
1019 // block which doesn't need to be refreshed in the opposite direction
1023 // scroll to the right, move to the left
1028 // scroll to the left, move to the right
1034 // scroll down, move up
1039 // scroll up, move down
1044 // we need to hide the caret before moving or it will erase itself at
1045 // the wrong (old) location
1046 wxCaret
*caret
= GetCaret();
1049 #endif // wxUSE_CARET
1052 wxClientDC
dc(this);
1053 wxBitmap
bmp(size
.x
, size
.y
);
1055 dcMem
.SelectObject(bmp
);
1057 dcMem
.Blit(wxPoint(0, 0), size
, &dc
, ptSource
1058 #if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
1059 + GetClientAreaOrigin()
1060 #endif // broken wxGTK wxDC::Blit
1062 dc
.Blit(ptDest
, size
, &dcMem
, wxPoint(0, 0));
1064 wxLogTrace(_T("scroll"),
1065 _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
1066 ptSource
.x
, ptSource
.y
,
1068 ptDest
.x
, ptDest
.y
);
1070 // and now repaint the uncovered area
1072 // FIXME: We repaint the intersection of these rectangles twice - is
1073 // it bad? I don't think so as it is rare to scroll the window
1074 // diagonally anyhow and so adding extra logic to compute
1075 // rectangle intersection is probably not worth the effort
1077 rect
.x
= ptSource
.x
;
1078 rect
.y
= ptSource
.y
;
1084 // refresh the area along the right border
1085 rect
.x
+= size
.x
+ dx
;
1090 // refresh the area along the left border
1094 rect
.height
= sizeTotal
.y
;
1096 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1098 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1105 // refresh the area along the bottom border
1106 rect
.y
+= size
.y
+ dy
;
1111 // refresh the area along the top border
1115 rect
.width
= sizeTotal
.x
;
1117 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1119 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1125 #endif // wxUSE_CARET
1131 // ----------------------------------------------------------------------------
1132 // accelerators and menu hot keys
1133 // ----------------------------------------------------------------------------
1136 // the last window over which Alt was pressed (used by OnKeyUp)
1137 wxWindow
*wxWindow::ms_winLastAltPress
= NULL
;
1138 #endif // wxUSE_MENUS
1140 #if wxUSE_ACCEL || wxUSE_MENUS
1142 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1145 int key
= event
.GetKeyCode();
1146 if ( !event
.ControlDown() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1148 ms_winLastAltPress
= this;
1150 // it can't be an accel anyhow
1154 ms_winLastAltPress
= NULL
;
1155 #endif // wxUSE_MENUS
1158 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
1160 int command
= win
->GetAcceleratorTable()->GetCommand(event
);
1161 if ( command
!= -1 )
1163 wxCommandEvent
eventCmd(wxEVT_COMMAND_MENU_SELECTED
, command
);
1164 if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) )
1166 // skip "event.Skip()" below
1171 if ( win
->IsTopLevel() )
1173 // try the frame menu bar
1175 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1178 wxMenuBar
*menubar
= frame
->GetMenuBar();
1179 if ( menubar
&& menubar
->ProcessAccelEvent(event
) )
1181 // skip "event.Skip()" below
1185 #endif // wxUSE_MENUS
1187 // if it wasn't in a menu, try to find a button
1188 if ( command
!= -1 )
1190 wxWindow
* child
= win
->FindWindow(command
);
1191 if ( child
&& wxDynamicCast(child
, wxButton
) )
1193 wxCommandEvent
eventCmd(wxEVT_COMMAND_BUTTON_CLICKED
, command
);
1194 eventCmd
.SetEventObject(child
);
1195 if ( child
->GetEventHandler()->ProcessEvent(eventCmd
) )
1197 // skip "event.Skip()" below
1203 // don't propagate accels from the child frame to the parent one
1207 #endif // wxUSE_ACCEL
1212 #endif // wxUSE_ACCEL
1216 wxMenuBar
*wxWindow::GetParentFrameMenuBar() const
1218 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
1220 if ( win
->IsTopLevel() )
1222 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1225 return frame
->GetMenuBar();
1228 // don't look further - we don't want to return the menubar of the
1237 void wxWindow::OnChar(wxKeyEvent
& event
)
1239 if ( event
.AltDown() && !event
.ControlDown() )
1241 int key
= event
.GetKeyCode();
1243 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1246 int item
= menubar
->FindNextItemForAccel(-1, key
);
1249 menubar
->PopupMenu((size_t)item
);
1251 // skip "event.Skip()" below
1260 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1262 int key
= event
.GetKeyCode();
1263 if ( !event
.HasModifiers() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1265 // only process Alt release specially if there were no other key
1266 // presses since Alt had been pressed and if both events happened in
1268 if ( ms_winLastAltPress
== this )
1270 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1271 if ( menubar
&& this != menubar
)
1273 menubar
->SelectMenu(0);
1282 // in any case reset it
1283 ms_winLastAltPress
= NULL
;
1286 #endif // wxUSE_MENUS
1288 // ----------------------------------------------------------------------------
1289 // MSW-specific section
1290 // ----------------------------------------------------------------------------
1294 #include "wx/msw/private.h"
1296 long wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1298 if ( message
== WM_NCHITTEST
)
1300 // the windows which contain the other windows should let the mouse
1301 // events through, otherwise a window inside a static box would
1302 // never get any events at all
1303 if ( IsStaticBox() )
1305 return HTTRANSPARENT
;
1309 return wxWindowNative::MSWWindowProc(message
, wParam
, lParam
);