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 sometimes under
272 rect
= GetUpdateRegion().GetBox();
273 if ( !rect
.width
&& !rect
.height
)
276 wxSize size
= GetSize();
278 rect
.height
= size
.y
;
281 if ( GetBackgroundBitmap().Ok() )
283 // get the bitmap and the flags
286 wxBitmap bmp
= GetBackgroundBitmap(&alignment
, &stretch
);
287 wxControlRenderer::DrawBitmap(dc
, bmp
, rect
, alignment
, stretch
);
289 else // just fill it with bg colour if no bitmap
291 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this),
292 rect
, GetStateFlags());
298 void wxWindow::EraseBackground(wxDC
& dc
, const wxRect
& rect
)
300 // TODO: handle bg bitmaps here!
302 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this), rect
, GetStateFlags());
305 void wxWindow::DoDrawBorder(wxDC
& dc
, const wxRect
& rect
)
307 // draw outline unless the update region is enitrely inside it in which
308 // case we don't need to do it
309 #if 0 // doesn't seem to work, why?
310 if ( wxRegion(rect
).Contains(GetUpdateRegion().GetBox()) != wxInRegion
)
313 m_renderer
->DrawBorder(dc
, GetBorder(), rect
, GetStateFlags());
317 void wxWindow::DoDraw(wxControlRenderer
*renderer
)
321 void wxWindow::Refresh(bool eraseBackground
, const wxRect
*rectClient
)
324 wxPoint pt
= GetClientAreaOrigin();
326 wxSize size
= GetClientSize();
330 rectWin
= *rectClient
;
332 // don't refresh anything beyond the client area (scrollbars for
334 if ( rectWin
.GetRight() > size
.x
)
335 rectWin
.SetRight(size
.x
);
336 if ( rectWin
.GetBottom() > size
.y
)
337 rectWin
.SetBottom(size
.y
);
341 else // refresh the entire client area
345 rectWin
.width
= size
.x
;
346 rectWin
.height
= size
.y
;
350 #ifdef WXDEBUG_REFRESH
351 static bool s_refreshDebug
= FALSE
;
352 if ( s_refreshDebug
)
355 dc
.SetBrush(*wxCYAN_BRUSH
);
356 dc
.SetPen(*wxTRANSPARENT_PEN
);
357 dc
.DrawRectangle(rectWin
);
359 // under Unix we use "--sync" X option for this
360 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
365 #endif // WXDEBUG_REFRESH
367 wxWindowNative::Refresh(eraseBackground
, &rectWin
);
370 // ----------------------------------------------------------------------------
372 // ----------------------------------------------------------------------------
374 bool wxWindow::Enable(bool enable
)
376 if ( !wxWindowNative::Enable(enable
) )
379 // disabled window can't keep focus
380 if ( FindFocus() == this && GetParent() != NULL
)
382 GetParent()->SetFocus();
387 // a window with renderer is drawn by ourselves and it has to be
388 // refreshed to reflect its new status
395 bool wxWindow::IsFocused() const
397 wxWindow
*self
= wxConstCast(this, wxWindow
);
398 return self
->FindFocus() == self
;
401 bool wxWindow::IsPressed() const
406 bool wxWindow::IsDefault() const
411 bool wxWindow::IsCurrent() const
416 bool wxWindow::SetCurrent(bool doit
)
418 if ( doit
== m_isCurrent
)
423 if ( CanBeHighlighted() )
429 int wxWindow::GetStateFlags() const
433 flags
|= wxCONTROL_DISABLED
;
435 // the following states are only possible if our application is active - if
436 // it is not, even our default/focused controls shouldn't appear as such
437 if ( wxTheApp
->IsActive() )
440 flags
|= wxCONTROL_CURRENT
;
442 flags
|= wxCONTROL_FOCUSED
;
444 flags
|= wxCONTROL_PRESSED
;
446 flags
|= wxCONTROL_ISDEFAULT
;
452 // ----------------------------------------------------------------------------
454 // ----------------------------------------------------------------------------
456 void wxWindow::OnSize(wxSizeEvent
& event
)
460 if ( m_scrollbarVert
|| m_scrollbarHorz
)
462 PositionScrollbars();
465 #if 0 // ndef __WXMSW__
466 // Refresh the area (strip) previously occupied by the border
468 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE
) && IsShown())
470 // This code assumes that wxSizeEvent.GetSize() returns
471 // the area of the entire window, not just the client
473 wxSize newSize
= event
.GetSize();
475 if (m_oldSize
.x
== -1 && m_oldSize
.y
== -1)
481 if (HasFlag( wxSIMPLE_BORDER
))
483 if (newSize
.y
> m_oldSize
.y
)
487 rect
.width
= m_oldSize
.x
;
488 rect
.y
= m_oldSize
.y
-2;
490 Refresh( TRUE
, &rect
);
492 else if (newSize
.y
< m_oldSize
.y
)
498 rect
.width
= newSize
.x
;
499 wxWindowNative::Refresh( TRUE
, &rect
);
502 if (newSize
.x
> m_oldSize
.x
)
506 rect
.height
= m_oldSize
.y
;
507 rect
.x
= m_oldSize
.x
-2;
509 Refresh( TRUE
, &rect
);
511 else if (newSize
.x
< m_oldSize
.x
)
517 rect
.height
= newSize
.y
;
518 wxWindowNative::Refresh( TRUE
, &rect
);
522 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
524 if (newSize
.y
> m_oldSize
.y
)
528 rect
.width
= m_oldSize
.x
;
529 rect
.y
= m_oldSize
.y
-4;
531 Refresh( TRUE
, &rect
);
533 else if (newSize
.y
< m_oldSize
.y
)
539 rect
.width
= newSize
.x
;
540 wxWindowNative::Refresh( TRUE
, &rect
);
543 if (newSize
.x
> m_oldSize
.x
)
547 rect
.height
= m_oldSize
.y
;
548 rect
.x
= m_oldSize
.x
-4;
550 Refresh( TRUE
, &rect
);
552 else if (newSize
.x
< m_oldSize
.x
)
558 rect
.height
= newSize
.y
;
559 wxWindowNative::Refresh( TRUE
, &rect
);
568 wxSize
wxWindow::DoGetBestSize() const
570 return AdjustSize(DoGetBestClientSize());
573 wxSize
wxWindow::DoGetBestClientSize() const
575 return wxWindowNative::DoGetBestSize();
578 wxSize
wxWindow::AdjustSize(const wxSize
& size
) const
582 m_renderer
->AdjustSize(&sz
, this);
586 wxPoint
wxWindow::GetClientAreaOrigin() const
588 wxPoint pt
= wxWindowBase::GetClientAreaOrigin();
590 #if wxUSE_TWO_WINDOWS
593 pt
+= m_renderer
->GetBorderDimensions(GetBorder()).GetPosition();
599 void wxWindow::DoGetClientSize(int *width
, int *height
) const
601 // if it is a native window, we assume it handles the scrollbars itself
602 // too - and if it doesn't, there is not much we can do
605 wxWindowNative::DoGetClientSize(width
, height
);
611 wxWindowNative::DoGetClientSize(&w
, &h
);
613 // we assume that the scrollbars are positioned correctly (by a previous
614 // call to PositionScrollbars()) here
618 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
620 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
624 // in any case, take account of the scrollbar
625 if ( m_scrollbarVert
)
626 w
-= m_scrollbarVert
->GetSize().x
;
628 // if we don't have scrollbar or if it is outside the border (and not
629 // blended into it), take account of the right border as well
630 if ( !m_scrollbarVert
|| inside
)
631 w
-= rectBorder
.width
;
633 // and always account for the left border
634 *width
= w
- rectBorder
.x
;
636 // we shouldn't return invalid width
643 if ( m_scrollbarHorz
)
644 h
-= m_scrollbarHorz
->GetSize().y
;
646 if ( !m_scrollbarHorz
|| inside
)
647 h
-= rectBorder
.height
;
649 *height
= h
- rectBorder
.y
;
651 // we shouldn't return invalid height
657 void wxWindow::DoSetClientSize(int width
, int height
)
659 // take into account the borders
660 wxRect rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
661 width
+= rectBorder
.x
;
662 height
+= rectBorder
.y
;
664 // and the scrollbars (as they may be offset into the border, use the
665 // scrollbar position, not size - this supposes that PositionScrollbars()
666 // had been called before)
667 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
668 wxSize size
= GetSize();
669 if ( m_scrollbarVert
)
670 width
+= size
.x
- m_scrollbarVert
->GetPosition().x
;
671 if ( !m_scrollbarVert
|| inside
)
672 width
+= rectBorder
.width
;
674 if ( m_scrollbarHorz
)
675 height
+= size
.y
- m_scrollbarHorz
->GetPosition().y
;
676 if ( !m_scrollbarHorz
|| inside
)
677 height
+= rectBorder
.height
;
679 wxWindowNative::DoSetClientSize(width
, height
);
682 wxHitTest
wxWindow::DoHitTest(wxCoord x
, wxCoord y
) const
684 wxHitTest ht
= wxWindowNative::DoHitTest(x
, y
);
685 if ( ht
== wxHT_WINDOW_INSIDE
)
687 if ( m_scrollbarVert
&& x
>= m_scrollbarVert
->GetPosition().x
)
689 // it can still be changed below because it may also be the corner
690 ht
= wxHT_WINDOW_VERT_SCROLLBAR
;
693 if ( m_scrollbarHorz
&& y
>= m_scrollbarHorz
->GetPosition().y
)
695 ht
= ht
== wxHT_WINDOW_VERT_SCROLLBAR
? wxHT_WINDOW_CORNER
696 : wxHT_WINDOW_HORZ_SCROLLBAR
;
703 // ----------------------------------------------------------------------------
704 // scrolling: we implement it entirely ourselves except for ScrollWindow()
705 // function which is supposed to be (efficiently) implemented by the native
707 // ----------------------------------------------------------------------------
709 void wxWindow::RefreshScrollbars()
711 if ( m_scrollbarHorz
)
712 m_scrollbarHorz
->Refresh();
714 if ( m_scrollbarVert
)
715 m_scrollbarVert
->Refresh();
718 void wxWindow::PositionScrollbars()
720 // do not use GetClientSize/Rect as it relies on the scrollbars being
721 // correctly positioned
723 wxSize size
= GetSize();
724 wxBorder border
= GetBorder();
725 wxRect rectBorder
= m_renderer
->GetBorderDimensions(border
);
726 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
728 int height
= m_scrollbarHorz
? m_scrollbarHorz
->GetSize().y
: 0;
729 int width
= m_scrollbarVert
? m_scrollbarVert
->GetSize().x
: 0;
732 if ( m_scrollbarVert
)
734 rectBar
.x
= size
.x
- width
;
736 rectBar
.x
-= rectBorder
.width
;
737 rectBar
.width
= width
;
740 rectBar
.y
+= rectBorder
.y
;
741 rectBar
.height
= size
.y
- height
;
743 rectBar
.height
-= rectBorder
.y
+ rectBorder
.height
;
745 m_scrollbarVert
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
748 if ( m_scrollbarHorz
)
750 rectBar
.y
= size
.y
- height
;
752 rectBar
.y
-= rectBorder
.height
;
753 rectBar
.height
= height
;
756 rectBar
.x
+= rectBorder
.x
;
757 rectBar
.width
= size
.x
- width
;
759 rectBar
.width
-= rectBorder
.x
+ rectBorder
.width
;
761 m_scrollbarHorz
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
767 void wxWindow::SetScrollbar(int orient
,
773 wxASSERT_MSG( pageSize
<= range
,
774 _T("page size can't be greater than range") );
776 bool hasClientSizeChanged
= FALSE
;
777 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
778 if ( range
&& (pageSize
< range
) )
783 #if wxUSE_TWO_WINDOWS
784 SetInsertIntoMain( TRUE
);
786 scrollbar
= new wxScrollBar(this, -1,
787 wxDefaultPosition
, wxDefaultSize
,
788 orient
& wxVERTICAL
? wxSB_VERTICAL
790 #if wxUSE_TWO_WINDOWS
791 SetInsertIntoMain( FALSE
);
793 if ( orient
& wxVERTICAL
)
794 m_scrollbarVert
= scrollbar
;
796 m_scrollbarHorz
= scrollbar
;
798 // the client area diminished as we created a scrollbar
799 hasClientSizeChanged
= TRUE
;
801 PositionScrollbars();
803 else if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
805 // we might have disabled it before
809 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
811 else // no range means no scrollbar
815 // wxALWAYS_SHOW_SB only applies to the vertical scrollbar
816 if ( (orient
& wxVERTICAL
) && (GetWindowStyle() & wxALWAYS_SHOW_SB
) )
818 // just disable the scrollbar
819 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
820 scrollbar
->Disable();
822 else // really remove the scrollbar
826 if ( orient
& wxVERTICAL
)
827 m_scrollbarVert
= NULL
;
829 m_scrollbarHorz
= NULL
;
831 // the client area increased as we removed a scrollbar
832 hasClientSizeChanged
= TRUE
;
834 // the size of the remaining scrollbar must be adjusted
835 if ( m_scrollbarHorz
|| m_scrollbarVert
)
837 PositionScrollbars();
843 // give the window a chance to relayout
844 if ( hasClientSizeChanged
)
846 wxSizeEvent
event(GetSize());
847 (void)GetEventHandler()->ProcessEvent(event
);
851 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
853 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
854 wxCHECK_RET( scrollbar
, _T("no scrollbar to set position for") );
856 scrollbar
->SetThumbPosition(pos
);
858 // VZ: I think we can safely ignore this as we always refresh it
859 // automatically whenever the value chanegs
866 int wxWindow::GetScrollPos(int orient
) const
868 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
869 return scrollbar
? scrollbar
->GetThumbPosition() : 0;
872 int wxWindow::GetScrollThumb(int orient
) const
874 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
875 return scrollbar
? scrollbar
->GetThumbSize() : 0;
878 int wxWindow::GetScrollRange(int orient
) const
880 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
881 return scrollbar
? scrollbar
->GetRange() : 0;
884 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
886 // use native scrolling when available and do it in generic way
890 wxWindowNative::ScrollWindow(dx
, dy
, rect
);
894 // before scrolling it, ensure that we don't have any unpainted areas
901 r
= ScrollNoRefresh(dx
, 0, rect
);
902 Refresh(TRUE
/* erase bkgnd */, &r
);
907 r
= ScrollNoRefresh(0, dy
, rect
);
908 Refresh(TRUE
/* erase bkgnd */, &r
);
911 // scroll children accordingly:
912 wxPoint
offset(dx
, dy
);
914 for (wxWindowList::Node
*node
= GetChildren().GetFirst();
915 node
; node
= node
->GetNext())
917 wxWindow
*child
= node
->GetData();
918 if ( child
== m_scrollbarVert
|| child
== m_scrollbarHorz
)
921 // VS: Scrolling children has non-trivial semantics. If rect=NULL then
922 // it is easy: we scroll all children. Otherwise it gets
924 // 1. if scrolling in one direction only, scroll only
925 // those children that intersect shaft defined by the rectangle
926 // and scrolling direction
927 // 2. if scrolling in both axes, scroll all children
929 if ( rect
&& (dx
* dy
== 0 /* moving in only one of x, y axis */) )
931 wxRect childRect
= child
->GetRect();
932 if ( dx
== 0 && (childRect
.GetLeft() <= rect
->GetRight() ||
933 childRect
.GetRight() >= rect
->GetLeft()) )
935 child
->Move(child
->GetPosition() + offset
);
937 else if ( dy
== 0 && (childRect
.GetTop() <= rect
->GetBottom() ||
938 childRect
.GetBottom() >= rect
->GetTop()) )
940 child
->Move(child
->GetPosition() + offset
);
945 child
->Move(child
->GetPosition() + offset
);
951 wxRect
wxWindow::ScrollNoRefresh(int dx
, int dy
, const wxRect
*rectTotal
)
953 wxASSERT_MSG( !dx
|| !dy
, _T("can't be used for diag scrolling") );
955 // the rect to refresh (which we will calculate)
964 // calculate the part of the window which we can just redraw in the new
966 wxSize sizeTotal
= rectTotal
? rectTotal
->GetSize() : GetClientSize();
968 wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
969 sizeTotal
.x
, sizeTotal
.y
, dx
, dy
);
971 // the initial and end point of the region we move in client coords
972 wxPoint ptSource
, ptDest
;
975 ptSource
= rectTotal
->GetPosition();
976 ptDest
= rectTotal
->GetPosition();
979 // the size of this region
981 size
.x
= sizeTotal
.x
- abs(dx
);
982 size
.y
= sizeTotal
.y
- abs(dy
);
983 if ( size
.x
<= 0 || size
.y
<= 0 )
985 // just redraw everything as nothing of the displayed image will stay
986 wxLogTrace(_T("scroll"), _T("refreshing everything"));
988 rect
= rectTotal
? *rectTotal
: wxRect(0, 0, sizeTotal
.x
, sizeTotal
.y
);
990 else // move the part which doesn't change to the new location
992 // note that when we scroll the canvas in some direction we move the
993 // block which doesn't need to be refreshed in the opposite direction
997 // scroll to the right, move to the left
1002 // scroll to the left, move to the right
1008 // scroll down, move up
1013 // scroll up, move down
1018 // we need to hide the caret before moving or it will erase itself at
1019 // the wrong (old) location
1020 wxCaret
*caret
= GetCaret();
1023 #endif // wxUSE_CARET
1026 wxClientDC
dc(this);
1027 wxBitmap
bmp(size
.x
, size
.y
);
1029 dcMem
.SelectObject(bmp
);
1031 dcMem
.Blit(wxPoint(0, 0), size
, &dc
, ptSource
1032 #if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
1033 + GetClientAreaOrigin()
1034 #endif // broken wxGTK wxDC::Blit
1036 dc
.Blit(ptDest
, size
, &dcMem
, wxPoint(0, 0));
1038 wxLogTrace(_T("scroll"),
1039 _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
1040 ptSource
.x
, ptSource
.y
,
1042 ptDest
.x
, ptDest
.y
);
1044 // and now repaint the uncovered area
1046 // FIXME: We repaint the intersection of these rectangles twice - is
1047 // it bad? I don't think so as it is rare to scroll the window
1048 // diagonally anyhow and so adding extra logic to compute
1049 // rectangle intersection is probably not worth the effort
1051 rect
.x
= ptSource
.x
;
1052 rect
.y
= ptSource
.y
;
1058 // refresh the area along the right border
1059 rect
.x
+= size
.x
+ dx
;
1064 // refresh the area along the left border
1068 rect
.height
= sizeTotal
.y
;
1070 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1072 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1079 // refresh the area along the bottom border
1080 rect
.y
+= size
.y
+ dy
;
1085 // refresh the area along the top border
1089 rect
.width
= sizeTotal
.x
;
1091 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1093 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1099 #endif // wxUSE_CARET
1105 // ----------------------------------------------------------------------------
1106 // accelerators and menu hot keys
1107 // ----------------------------------------------------------------------------
1110 // the last window over which Alt was pressed (used by OnKeyUp)
1111 wxWindow
*wxWindow::ms_winLastAltPress
= NULL
;
1112 #endif // wxUSE_MENUS
1114 #if wxUSE_ACCEL || wxUSE_MENUS
1116 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1119 int key
= event
.GetKeyCode();
1120 if ( !event
.ControlDown() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1122 ms_winLastAltPress
= this;
1124 // it can't be an accel anyhow
1128 ms_winLastAltPress
= NULL
;
1129 #endif // wxUSE_MENUS
1132 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
1134 int command
= win
->GetAcceleratorTable()->GetCommand(event
);
1135 if ( command
!= -1 )
1137 wxCommandEvent
eventCmd(wxEVT_COMMAND_MENU_SELECTED
, command
);
1138 if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) )
1140 // skip "event.Skip()" below
1145 if ( win
->IsTopLevel() )
1147 // try the frame menu bar
1149 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1152 wxMenuBar
*menubar
= frame
->GetMenuBar();
1153 if ( menubar
&& menubar
->ProcessAccelEvent(event
) )
1155 // skip "event.Skip()" below
1159 #endif // wxUSE_MENUS
1161 // if it wasn't in a menu, try to find a button
1162 if ( command
!= -1 )
1164 wxWindow
* child
= win
->FindWindow(command
);
1165 if ( child
&& wxDynamicCast(child
, wxButton
) )
1167 wxCommandEvent
eventCmd(wxEVT_COMMAND_BUTTON_CLICKED
, command
);
1168 eventCmd
.SetEventObject(child
);
1169 if ( child
->GetEventHandler()->ProcessEvent(eventCmd
) )
1171 // skip "event.Skip()" below
1177 // don't propagate accels from the child frame to the parent one
1181 #endif // wxUSE_ACCEL
1186 #endif // wxUSE_ACCEL
1190 wxMenuBar
*wxWindow::GetParentFrameMenuBar() const
1192 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
1194 if ( win
->IsTopLevel() )
1196 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1199 return frame
->GetMenuBar();
1202 // don't look further - we don't want to return the menubar of the
1211 void wxWindow::OnChar(wxKeyEvent
& event
)
1213 if ( event
.AltDown() && !event
.ControlDown() )
1215 int key
= event
.GetKeyCode();
1217 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1220 int item
= menubar
->FindNextItemForAccel(-1, key
);
1223 menubar
->PopupMenu((size_t)item
);
1225 // skip "event.Skip()" below
1234 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1236 int key
= event
.GetKeyCode();
1237 if ( !event
.HasModifiers() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1239 // only process Alt release specially if there were no other key
1240 // presses since Alt had been pressed and if both events happened in
1242 if ( ms_winLastAltPress
== this )
1244 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1245 if ( menubar
&& this != menubar
)
1247 menubar
->SelectMenu(0);
1256 // in any case reset it
1257 ms_winLastAltPress
= NULL
;
1260 #endif // wxUSE_MENUS
1262 // ----------------------------------------------------------------------------
1263 // MSW-specific section
1264 // ----------------------------------------------------------------------------
1268 #include "wx/msw/private.h"
1270 long wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1272 if ( message
== WM_NCHITTEST
)
1274 // the windows which contain the other windows should let the mouse
1275 // events through, otherwise a window inside a static box would
1276 // never get any events at all
1277 if ( IsStaticBox() )
1279 return HTTRANSPARENT
;
1283 return wxWindowNative::MSWWindowProc(message
, wParam
, lParam
);