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"
42 #include "wx/univ/colschem.h"
43 #include "wx/univ/renderer.h"
44 #include "wx/univ/theme.h"
50 // turn Refresh() debugging on/off
51 #define WXDEBUG_REFRESH
54 #undef WXDEBUG_REFRESH
57 #if defined(WXDEBUG_REFRESH) && defined(__WXMSW__) && !defined(__WXMICROWIN__)
58 #include "wx/msw/private.h"
61 // ============================================================================
63 // ============================================================================
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 // we can't use wxWindowNative here as it won't be expanded inside the macro
70 #if defined(__WXMSW__)
71 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowMSW
)
72 #elif defined(__WXGTK__)
73 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowGTK
)
74 #elif defined(__WXMGL__)
75 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowMGL
)
76 #elif defined(__WXX11__)
77 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowX11
)
78 #elif defined(__WXPM__)
79 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowOS2
)
82 BEGIN_EVENT_TABLE(wxWindow
, wxWindowNative
)
83 EVT_SIZE(wxWindow::OnSize
)
85 #if wxUSE_ACCEL || wxUSE_MENUS
86 EVT_KEY_DOWN(wxWindow::OnKeyDown
)
90 EVT_CHAR(wxWindow::OnChar
)
91 EVT_KEY_UP(wxWindow::OnKeyUp
)
94 EVT_PAINT(wxWindow::OnPaint
)
95 EVT_NC_PAINT(wxWindow::OnNcPaint
)
96 EVT_ERASE_BACKGROUND(wxWindow::OnErase
)
99 // ----------------------------------------------------------------------------
101 // ----------------------------------------------------------------------------
103 void wxWindow::Init()
106 m_scrollbarHorz
= (wxScrollBar
*)NULL
;
110 m_renderer
= wxTheme::Get()->GetRenderer();
116 bool wxWindow::Create(wxWindow
*parent
,
121 const wxString
& name
)
123 // we add wxCLIP_CHILDREN to get the same ("natural") behaviour under MSW
124 // as under the other platforms
125 if ( !wxWindowNative::Create(parent
, id
, pos
, size
,
126 style
| wxCLIP_CHILDREN
,
132 // if we should always have the scrollbar, do show it
133 if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
135 #if wxUSE_TWO_WINDOWS
136 SetInsertIntoMain( TRUE
);
138 m_scrollbarVert
= new wxScrollBar(this, -1,
139 wxDefaultPosition
, wxDefaultSize
,
141 #if wxUSE_TWO_WINDOWS
142 SetInsertIntoMain( FALSE
);
146 PositionScrollbars();
152 // ----------------------------------------------------------------------------
154 // ----------------------------------------------------------------------------
156 void wxWindow::SetBackground(const wxBitmap
& bitmap
,
161 m_alignBgBitmap
= alignment
;
162 m_stretchBgBitmap
= stretch
;
165 const wxBitmap
& wxWindow::GetBackgroundBitmap(int *alignment
,
166 wxStretch
*stretch
) const
168 if ( m_bitmapBg
.Ok() )
171 *alignment
= m_alignBgBitmap
;
173 *stretch
= m_stretchBgBitmap
;
179 // ----------------------------------------------------------------------------
181 // ----------------------------------------------------------------------------
183 // the event handler executed when the window background must be painted
184 void wxWindow::OnErase(wxEraseEvent
& event
)
193 DoDrawBackground(*event
.GetDC());
195 // if we have both scrollbars, we also have a square in the corner between
196 // them which we must paint
197 if ( m_scrollbarVert
&& m_scrollbarHorz
)
199 wxSize size
= GetSize();
200 wxRect rectClient
= GetClientRect(),
201 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
204 rectCorner
.x
= rectClient
.GetRight() + 1;
205 rectCorner
.y
= rectClient
.GetBottom() + 1;
206 rectCorner
.SetRight(size
.x
- rectBorder
.width
);
207 rectCorner
.SetBottom(size
.y
- rectBorder
.height
);
209 if ( GetUpdateRegion().Contains(rectCorner
) )
211 m_renderer
->DrawScrollCorner(*event
.GetDC(), rectCorner
);
216 // the event handlers executed when the window must be repainted
217 void wxWindow::OnNcPaint(wxPaintEvent
& event
)
221 // get the window rect
223 wxSize size
= GetSize();
227 rect
.height
= size
.y
;
229 // if the scrollbars are outside the border, we must adjust the rect to
231 if ( !m_renderer
->AreScrollbarsInsideBorder() )
233 wxScrollBar
*scrollbar
= GetScrollbar(wxVERTICAL
);
235 rect
.width
-= scrollbar
->GetSize().x
;
237 scrollbar
= GetScrollbar(wxHORIZONTAL
);
239 rect
.height
-= scrollbar
->GetSize().y
;
242 // get the DC and draw the border on it
244 DoDrawBorder(dc
, rect
);
248 void wxWindow::OnPaint(wxPaintEvent
& event
)
252 // it is a native control which paints itself
257 // get the DC to use and create renderer on it
259 wxControlRenderer
renderer(this, dc
, m_renderer
);
266 bool wxWindow::DoDrawBackground(wxDC
& dc
)
268 // FIXME: Leaving this code in leads to partial bg redraws
269 // sometimes under MSW.
270 // The same happens under X11 because it has a clear
271 // region and an update region and these are sometimes
276 rect
= GetUpdateRegion().GetBox();
277 if ( !rect
.width
&& !rect
.height
)
280 wxSize size
= GetSize();
282 rect
.height
= size
.y
;
285 if ( GetBackgroundBitmap().Ok() )
287 // get the bitmap and the flags
290 wxBitmap bmp
= GetBackgroundBitmap(&alignment
, &stretch
);
291 wxControlRenderer::DrawBitmap(dc
, bmp
, rect
, alignment
, stretch
);
293 else // just fill it with bg colour if no bitmap
295 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this),
296 rect
, GetStateFlags());
302 void wxWindow::EraseBackground(wxDC
& dc
, const wxRect
& rect
)
304 // TODO: handle bg bitmaps here!
306 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this), rect
, GetStateFlags());
309 void wxWindow::DoDrawBorder(wxDC
& dc
, const wxRect
& rect
)
311 // draw outline unless the update region is enitrely inside it in which
312 // case we don't need to do it
313 #if 0 // doesn't seem to work, why?
314 if ( wxRegion(rect
).Contains(GetUpdateRegion().GetBox()) != wxInRegion
)
317 m_renderer
->DrawBorder(dc
, GetBorder(), rect
, GetStateFlags());
321 void wxWindow::DoDraw(wxControlRenderer
*renderer
)
325 void wxWindow::Refresh(bool eraseBackground
, const wxRect
*rectClient
)
328 wxPoint pt
= GetClientAreaOrigin();
330 wxSize size
= GetClientSize();
334 rectWin
= *rectClient
;
336 // don't refresh anything beyond the client area (scrollbars for
338 if ( rectWin
.GetRight() > size
.x
)
339 rectWin
.SetRight(size
.x
);
340 if ( rectWin
.GetBottom() > size
.y
)
341 rectWin
.SetBottom(size
.y
);
345 else // refresh the entire client area
349 rectWin
.width
= size
.x
;
350 rectWin
.height
= size
.y
;
354 #ifdef WXDEBUG_REFRESH
355 static bool s_refreshDebug
= FALSE
;
356 if ( s_refreshDebug
)
359 dc
.SetBrush(*wxCYAN_BRUSH
);
360 dc
.SetPen(*wxTRANSPARENT_PEN
);
361 dc
.DrawRectangle(rectWin
);
363 // under Unix we use "--sync" X option for this
364 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
369 #endif // WXDEBUG_REFRESH
371 wxWindowNative::Refresh(eraseBackground
, &rectWin
);
374 // ----------------------------------------------------------------------------
376 // ----------------------------------------------------------------------------
378 bool wxWindow::Enable(bool enable
)
380 if ( !wxWindowNative::Enable(enable
) )
383 // disabled window can't keep focus
384 if ( FindFocus() == this && GetParent() != NULL
)
386 GetParent()->SetFocus();
391 // a window with renderer is drawn by ourselves and it has to be
392 // refreshed to reflect its new status
399 bool wxWindow::IsFocused() const
401 wxWindow
*self
= wxConstCast(this, wxWindow
);
402 return self
->FindFocus() == self
;
405 bool wxWindow::IsPressed() const
410 bool wxWindow::IsDefault() const
415 bool wxWindow::IsCurrent() const
420 bool wxWindow::SetCurrent(bool doit
)
422 if ( doit
== m_isCurrent
)
427 if ( CanBeHighlighted() )
433 int wxWindow::GetStateFlags() const
437 flags
|= wxCONTROL_DISABLED
;
439 // the following states are only possible if our application is active - if
440 // it is not, even our default/focused controls shouldn't appear as such
441 if ( wxTheApp
->IsActive() )
444 flags
|= wxCONTROL_CURRENT
;
446 flags
|= wxCONTROL_FOCUSED
;
448 flags
|= wxCONTROL_PRESSED
;
450 flags
|= wxCONTROL_ISDEFAULT
;
456 // ----------------------------------------------------------------------------
458 // ----------------------------------------------------------------------------
460 void wxWindow::OnSize(wxSizeEvent
& event
)
464 if ( m_scrollbarVert
|| m_scrollbarHorz
)
466 PositionScrollbars();
469 #if 0 // ndef __WXMSW__
470 // Refresh the area (strip) previously occupied by the border
472 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE
) && IsShown())
474 // This code assumes that wxSizeEvent.GetSize() returns
475 // the area of the entire window, not just the client
477 wxSize newSize
= event
.GetSize();
479 if (m_oldSize
.x
== -1 && m_oldSize
.y
== -1)
485 if (HasFlag( wxSIMPLE_BORDER
))
487 if (newSize
.y
> m_oldSize
.y
)
491 rect
.width
= m_oldSize
.x
;
492 rect
.y
= m_oldSize
.y
-2;
494 Refresh( TRUE
, &rect
);
496 else if (newSize
.y
< m_oldSize
.y
)
502 rect
.width
= newSize
.x
;
503 wxWindowNative::Refresh( TRUE
, &rect
);
506 if (newSize
.x
> m_oldSize
.x
)
510 rect
.height
= m_oldSize
.y
;
511 rect
.x
= m_oldSize
.x
-2;
513 Refresh( TRUE
, &rect
);
515 else if (newSize
.x
< m_oldSize
.x
)
521 rect
.height
= newSize
.y
;
522 wxWindowNative::Refresh( TRUE
, &rect
);
526 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
528 if (newSize
.y
> m_oldSize
.y
)
532 rect
.width
= m_oldSize
.x
;
533 rect
.y
= m_oldSize
.y
-4;
535 Refresh( TRUE
, &rect
);
537 else if (newSize
.y
< m_oldSize
.y
)
543 rect
.width
= newSize
.x
;
544 wxWindowNative::Refresh( TRUE
, &rect
);
547 if (newSize
.x
> m_oldSize
.x
)
551 rect
.height
= m_oldSize
.y
;
552 rect
.x
= m_oldSize
.x
-4;
554 Refresh( TRUE
, &rect
);
556 else if (newSize
.x
< m_oldSize
.x
)
562 rect
.height
= newSize
.y
;
563 wxWindowNative::Refresh( TRUE
, &rect
);
572 wxSize
wxWindow::DoGetBestSize() const
574 return AdjustSize(DoGetBestClientSize());
577 wxSize
wxWindow::DoGetBestClientSize() const
579 return wxWindowNative::DoGetBestSize();
582 wxSize
wxWindow::AdjustSize(const wxSize
& size
) const
586 m_renderer
->AdjustSize(&sz
, this);
590 wxPoint
wxWindow::GetClientAreaOrigin() const
592 wxPoint pt
= wxWindowBase::GetClientAreaOrigin();
594 #if wxUSE_TWO_WINDOWS
597 pt
+= m_renderer
->GetBorderDimensions(GetBorder()).GetPosition();
603 void wxWindow::DoGetClientSize(int *width
, int *height
) const
605 // if it is a native window, we assume it handles the scrollbars itself
606 // too - and if it doesn't, there is not much we can do
609 wxWindowNative::DoGetClientSize(width
, height
);
615 wxWindowNative::DoGetClientSize(&w
, &h
);
617 // we assume that the scrollbars are positioned correctly (by a previous
618 // call to PositionScrollbars()) here
622 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
624 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
628 // in any case, take account of the scrollbar
629 if ( m_scrollbarVert
)
630 w
-= m_scrollbarVert
->GetSize().x
;
632 // if we don't have scrollbar or if it is outside the border (and not
633 // blended into it), take account of the right border as well
634 if ( !m_scrollbarVert
|| inside
)
635 w
-= rectBorder
.width
;
637 // and always account for the left border
638 *width
= w
- rectBorder
.x
;
640 // we shouldn't return invalid width
647 if ( m_scrollbarHorz
)
648 h
-= m_scrollbarHorz
->GetSize().y
;
650 if ( !m_scrollbarHorz
|| inside
)
651 h
-= rectBorder
.height
;
653 *height
= h
- rectBorder
.y
;
655 // we shouldn't return invalid height
661 void wxWindow::DoSetClientSize(int width
, int height
)
663 // take into account the borders
664 wxRect rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
665 width
+= rectBorder
.x
;
666 height
+= rectBorder
.y
;
668 // and the scrollbars (as they may be offset into the border, use the
669 // scrollbar position, not size - this supposes that PositionScrollbars()
670 // had been called before)
671 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
672 wxSize size
= GetSize();
673 if ( m_scrollbarVert
)
674 width
+= size
.x
- m_scrollbarVert
->GetPosition().x
;
675 if ( !m_scrollbarVert
|| inside
)
676 width
+= rectBorder
.width
;
678 if ( m_scrollbarHorz
)
679 height
+= size
.y
- m_scrollbarHorz
->GetPosition().y
;
680 if ( !m_scrollbarHorz
|| inside
)
681 height
+= rectBorder
.height
;
683 wxWindowNative::DoSetClientSize(width
, height
);
686 wxHitTest
wxWindow::DoHitTest(wxCoord x
, wxCoord y
) const
688 wxHitTest ht
= wxWindowNative::DoHitTest(x
, y
);
689 if ( ht
== wxHT_WINDOW_INSIDE
)
691 if ( m_scrollbarVert
&& x
>= m_scrollbarVert
->GetPosition().x
)
693 // it can still be changed below because it may also be the corner
694 ht
= wxHT_WINDOW_VERT_SCROLLBAR
;
697 if ( m_scrollbarHorz
&& y
>= m_scrollbarHorz
->GetPosition().y
)
699 ht
= ht
== wxHT_WINDOW_VERT_SCROLLBAR
? wxHT_WINDOW_CORNER
700 : wxHT_WINDOW_HORZ_SCROLLBAR
;
707 // ----------------------------------------------------------------------------
708 // scrolling: we implement it entirely ourselves except for ScrollWindow()
709 // function which is supposed to be (efficiently) implemented by the native
711 // ----------------------------------------------------------------------------
713 void wxWindow::RefreshScrollbars()
715 if ( m_scrollbarHorz
)
716 m_scrollbarHorz
->Refresh();
718 if ( m_scrollbarVert
)
719 m_scrollbarVert
->Refresh();
722 void wxWindow::PositionScrollbars()
724 // do not use GetClientSize/Rect as it relies on the scrollbars being
725 // correctly positioned
727 wxSize size
= GetSize();
728 wxBorder border
= GetBorder();
729 wxRect rectBorder
= m_renderer
->GetBorderDimensions(border
);
730 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
732 int height
= m_scrollbarHorz
? m_scrollbarHorz
->GetSize().y
: 0;
733 int width
= m_scrollbarVert
? m_scrollbarVert
->GetSize().x
: 0;
736 if ( m_scrollbarVert
)
738 rectBar
.x
= size
.x
- width
;
740 rectBar
.x
-= rectBorder
.width
;
741 rectBar
.width
= width
;
744 rectBar
.y
+= rectBorder
.y
;
745 rectBar
.height
= size
.y
- height
;
747 rectBar
.height
-= rectBorder
.y
+ rectBorder
.height
;
749 m_scrollbarVert
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
752 if ( m_scrollbarHorz
)
754 rectBar
.y
= size
.y
- height
;
756 rectBar
.y
-= rectBorder
.height
;
757 rectBar
.height
= height
;
760 rectBar
.x
+= rectBorder
.x
;
761 rectBar
.width
= size
.x
- width
;
763 rectBar
.width
-= rectBorder
.x
+ rectBorder
.width
;
765 m_scrollbarHorz
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
771 void wxWindow::SetScrollbar(int orient
,
777 wxASSERT_MSG( pageSize
<= range
,
778 _T("page size can't be greater than range") );
780 bool hasClientSizeChanged
= FALSE
;
781 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
782 if ( range
&& (pageSize
< range
) )
787 #if wxUSE_TWO_WINDOWS
788 SetInsertIntoMain( TRUE
);
790 scrollbar
= new wxScrollBar(this, -1,
791 wxDefaultPosition
, wxDefaultSize
,
792 orient
& wxVERTICAL
? wxSB_VERTICAL
794 #if wxUSE_TWO_WINDOWS
795 SetInsertIntoMain( FALSE
);
797 if ( orient
& wxVERTICAL
)
798 m_scrollbarVert
= scrollbar
;
800 m_scrollbarHorz
= scrollbar
;
802 // the client area diminished as we created a scrollbar
803 hasClientSizeChanged
= TRUE
;
805 PositionScrollbars();
807 else if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
809 // we might have disabled it before
813 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
815 else // no range means no scrollbar
819 // wxALWAYS_SHOW_SB only applies to the vertical scrollbar
820 if ( (orient
& wxVERTICAL
) && (GetWindowStyle() & wxALWAYS_SHOW_SB
) )
822 // just disable the scrollbar
823 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
824 scrollbar
->Disable();
826 else // really remove the scrollbar
830 if ( orient
& wxVERTICAL
)
831 m_scrollbarVert
= NULL
;
833 m_scrollbarHorz
= NULL
;
835 // the client area increased as we removed a scrollbar
836 hasClientSizeChanged
= TRUE
;
838 // the size of the remaining scrollbar must be adjusted
839 if ( m_scrollbarHorz
|| m_scrollbarVert
)
841 PositionScrollbars();
847 // give the window a chance to relayout
848 if ( hasClientSizeChanged
)
850 #if wxUSE_TWO_WINDOWS
851 wxWindowNative::SetSize( GetSize() );
853 wxSizeEvent
event(GetSize());
854 (void)GetEventHandler()->ProcessEvent(event
);
859 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
861 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
862 wxCHECK_RET( scrollbar
, _T("no scrollbar to set position for") );
864 scrollbar
->SetThumbPosition(pos
);
866 // VZ: I think we can safely ignore this as we always refresh it
867 // automatically whenever the value chanegs
874 int wxWindow::GetScrollPos(int orient
) const
876 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
877 return scrollbar
? scrollbar
->GetThumbPosition() : 0;
880 int wxWindow::GetScrollThumb(int orient
) const
882 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
883 return scrollbar
? scrollbar
->GetThumbSize() : 0;
886 int wxWindow::GetScrollRange(int orient
) const
888 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
889 return scrollbar
? scrollbar
->GetRange() : 0;
892 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
894 // use native scrolling when available and do it in generic way
898 wxWindowNative::ScrollWindow(dx
, dy
, rect
);
902 // before scrolling it, ensure that we don't have any unpainted areas
909 r
= ScrollNoRefresh(dx
, 0, rect
);
910 Refresh(TRUE
/* erase bkgnd */, &r
);
915 r
= ScrollNoRefresh(0, dy
, rect
);
916 Refresh(TRUE
/* erase bkgnd */, &r
);
919 // scroll children accordingly:
920 wxPoint
offset(dx
, dy
);
922 for (wxWindowList::Node
*node
= GetChildren().GetFirst();
923 node
; node
= node
->GetNext())
925 wxWindow
*child
= node
->GetData();
926 if ( child
== m_scrollbarVert
|| child
== m_scrollbarHorz
)
929 // VS: Scrolling children has non-trivial semantics. If rect=NULL then
930 // it is easy: we scroll all children. Otherwise it gets
932 // 1. if scrolling in one direction only, scroll only
933 // those children that intersect shaft defined by the rectangle
934 // and scrolling direction
935 // 2. if scrolling in both axes, scroll all children
937 if ( rect
&& (dx
* dy
== 0 /* moving in only one of x, y axis */) )
939 wxRect childRect
= child
->GetRect();
940 if ( dx
== 0 && (childRect
.GetLeft() <= rect
->GetRight() ||
941 childRect
.GetRight() >= rect
->GetLeft()) )
943 child
->Move(child
->GetPosition() + offset
);
945 else if ( dy
== 0 && (childRect
.GetTop() <= rect
->GetBottom() ||
946 childRect
.GetBottom() >= rect
->GetTop()) )
948 child
->Move(child
->GetPosition() + offset
);
953 child
->Move(child
->GetPosition() + offset
);
959 wxRect
wxWindow::ScrollNoRefresh(int dx
, int dy
, const wxRect
*rectTotal
)
961 wxASSERT_MSG( !dx
|| !dy
, _T("can't be used for diag scrolling") );
963 // the rect to refresh (which we will calculate)
972 // calculate the part of the window which we can just redraw in the new
974 wxSize sizeTotal
= rectTotal
? rectTotal
->GetSize() : GetClientSize();
976 wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
977 sizeTotal
.x
, sizeTotal
.y
, dx
, dy
);
979 // the initial and end point of the region we move in client coords
980 wxPoint ptSource
, ptDest
;
983 ptSource
= rectTotal
->GetPosition();
984 ptDest
= rectTotal
->GetPosition();
987 // the size of this region
989 size
.x
= sizeTotal
.x
- abs(dx
);
990 size
.y
= sizeTotal
.y
- abs(dy
);
991 if ( size
.x
<= 0 || size
.y
<= 0 )
993 // just redraw everything as nothing of the displayed image will stay
994 wxLogTrace(_T("scroll"), _T("refreshing everything"));
996 rect
= rectTotal
? *rectTotal
: wxRect(0, 0, sizeTotal
.x
, sizeTotal
.y
);
998 else // move the part which doesn't change to the new location
1000 // note that when we scroll the canvas in some direction we move the
1001 // block which doesn't need to be refreshed in the opposite direction
1005 // scroll to the right, move to the left
1010 // scroll to the left, move to the right
1016 // scroll down, move up
1021 // scroll up, move down
1026 // we need to hide the caret before moving or it will erase itself at
1027 // the wrong (old) location
1028 wxCaret
*caret
= GetCaret();
1031 #endif // wxUSE_CARET
1034 wxClientDC
dc(this);
1035 wxBitmap
bmp(size
.x
, size
.y
);
1037 dcMem
.SelectObject(bmp
);
1039 dcMem
.Blit(wxPoint(0, 0), size
, &dc
, ptSource
1040 #if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
1041 + GetClientAreaOrigin()
1042 #endif // broken wxGTK wxDC::Blit
1044 dc
.Blit(ptDest
, size
, &dcMem
, wxPoint(0, 0));
1046 wxLogTrace(_T("scroll"),
1047 _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
1048 ptSource
.x
, ptSource
.y
,
1050 ptDest
.x
, ptDest
.y
);
1052 // and now repaint the uncovered area
1054 // FIXME: We repaint the intersection of these rectangles twice - is
1055 // it bad? I don't think so as it is rare to scroll the window
1056 // diagonally anyhow and so adding extra logic to compute
1057 // rectangle intersection is probably not worth the effort
1059 rect
.x
= ptSource
.x
;
1060 rect
.y
= ptSource
.y
;
1066 // refresh the area along the right border
1067 rect
.x
+= size
.x
+ dx
;
1072 // refresh the area along the left border
1076 rect
.height
= sizeTotal
.y
;
1078 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1080 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1087 // refresh the area along the bottom border
1088 rect
.y
+= size
.y
+ dy
;
1093 // refresh the area along the top border
1097 rect
.width
= sizeTotal
.x
;
1099 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1101 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1107 #endif // wxUSE_CARET
1113 // ----------------------------------------------------------------------------
1114 // accelerators and menu hot keys
1115 // ----------------------------------------------------------------------------
1118 // the last window over which Alt was pressed (used by OnKeyUp)
1119 wxWindow
*wxWindow::ms_winLastAltPress
= NULL
;
1120 #endif // wxUSE_MENUS
1122 #if wxUSE_ACCEL || wxUSE_MENUS
1124 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1127 int key
= event
.GetKeyCode();
1128 if ( !event
.ControlDown() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1130 ms_winLastAltPress
= this;
1132 // it can't be an accel anyhow
1136 ms_winLastAltPress
= NULL
;
1137 #endif // wxUSE_MENUS
1140 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
1142 int command
= win
->GetAcceleratorTable()->GetCommand(event
);
1143 if ( command
!= -1 )
1145 wxCommandEvent
eventCmd(wxEVT_COMMAND_MENU_SELECTED
, command
);
1146 if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) )
1148 // skip "event.Skip()" below
1153 if ( win
->IsTopLevel() )
1155 // try the frame menu bar
1157 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1160 wxMenuBar
*menubar
= frame
->GetMenuBar();
1161 if ( menubar
&& menubar
->ProcessAccelEvent(event
) )
1163 // skip "event.Skip()" below
1167 #endif // wxUSE_MENUS
1169 // if it wasn't in a menu, try to find a button
1170 if ( command
!= -1 )
1172 wxWindow
* child
= win
->FindWindow(command
);
1173 if ( child
&& wxDynamicCast(child
, wxButton
) )
1175 wxCommandEvent
eventCmd(wxEVT_COMMAND_BUTTON_CLICKED
, command
);
1176 eventCmd
.SetEventObject(child
);
1177 if ( child
->GetEventHandler()->ProcessEvent(eventCmd
) )
1179 // skip "event.Skip()" below
1185 // don't propagate accels from the child frame to the parent one
1189 #endif // wxUSE_ACCEL
1194 #endif // wxUSE_ACCEL
1198 wxMenuBar
*wxWindow::GetParentFrameMenuBar() const
1200 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
1202 if ( win
->IsTopLevel() )
1204 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1207 return frame
->GetMenuBar();
1210 // don't look further - we don't want to return the menubar of the
1219 void wxWindow::OnChar(wxKeyEvent
& event
)
1221 if ( event
.AltDown() && !event
.ControlDown() )
1223 int key
= event
.GetKeyCode();
1225 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1228 int item
= menubar
->FindNextItemForAccel(-1, key
);
1231 menubar
->PopupMenu((size_t)item
);
1233 // skip "event.Skip()" below
1242 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1244 int key
= event
.GetKeyCode();
1245 if ( !event
.HasModifiers() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1247 // only process Alt release specially if there were no other key
1248 // presses since Alt had been pressed and if both events happened in
1250 if ( ms_winLastAltPress
== this )
1252 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1253 if ( menubar
&& this != menubar
)
1255 menubar
->SelectMenu(0);
1264 // in any case reset it
1265 ms_winLastAltPress
= NULL
;
1268 #endif // wxUSE_MENUS
1270 // ----------------------------------------------------------------------------
1271 // MSW-specific section
1272 // ----------------------------------------------------------------------------
1276 #include "wx/msw/private.h"
1278 long wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1280 if ( message
== WM_NCHITTEST
)
1282 // the windows which contain the other windows should let the mouse
1283 // events through, otherwise a window inside a static box would
1284 // never get any events at all
1285 if ( IsStaticBox() )
1287 return HTTRANSPARENT
;
1291 return wxWindowNative::MSWWindowProc(message
, wParam
, lParam
);