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 m_scrollbarVert
= new wxScrollBar(this, -1,
136 wxDefaultPosition
, wxDefaultSize
,
140 PositionScrollbars();
146 // ----------------------------------------------------------------------------
148 // ----------------------------------------------------------------------------
150 void wxWindow::SetBackground(const wxBitmap
& bitmap
,
155 m_alignBgBitmap
= alignment
;
156 m_stretchBgBitmap
= stretch
;
159 const wxBitmap
& wxWindow::GetBackgroundBitmap(int *alignment
,
160 wxStretch
*stretch
) const
162 if ( m_bitmapBg
.Ok() )
165 *alignment
= m_alignBgBitmap
;
167 *stretch
= m_stretchBgBitmap
;
173 // ----------------------------------------------------------------------------
175 // ----------------------------------------------------------------------------
177 // the event handler executed when the window background must be painted
178 void wxWindow::OnErase(wxEraseEvent
& event
)
187 DoDrawBackground(*event
.GetDC());
189 // if we have both scrollbars, we also have a square in the corner between
190 // them which we must paint
191 if ( m_scrollbarVert
&& m_scrollbarHorz
)
193 wxSize size
= GetSize();
194 wxRect rectClient
= GetClientRect(),
195 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
198 rectCorner
.x
= rectClient
.GetRight() + 1;
199 rectCorner
.y
= rectClient
.GetBottom() + 1;
200 rectCorner
.SetRight(size
.x
- rectBorder
.width
);
201 rectCorner
.SetBottom(size
.y
- rectBorder
.height
);
203 if ( GetUpdateRegion().Contains(rectCorner
) )
205 m_renderer
->DrawScrollCorner(*event
.GetDC(), rectCorner
);
210 // the event handlers executed when the window must be repainted
211 void wxWindow::OnNcPaint(wxPaintEvent
& event
)
215 // get the window rect
217 wxSize size
= GetSize();
221 rect
.height
= size
.y
;
223 // if the scrollbars are outside the border, we must adjust the rect to
225 if ( !m_renderer
->AreScrollbarsInsideBorder() )
227 wxScrollBar
*scrollbar
= GetScrollbar(wxVERTICAL
);
229 rect
.width
-= scrollbar
->GetSize().x
;
231 scrollbar
= GetScrollbar(wxHORIZONTAL
);
233 rect
.height
-= scrollbar
->GetSize().y
;
236 // get the DC and draw the border on it
238 DoDrawBorder(dc
, rect
);
242 void wxWindow::OnPaint(wxPaintEvent
& event
)
246 // it is a native control which paints itself
251 // get the DC to use and create renderer on it
253 wxControlRenderer
renderer(this, dc
, m_renderer
);
260 bool wxWindow::DoDrawBackground(wxDC
& dc
)
262 // FIXME: leaving this code in leads to partial bg redraws sometimes under
266 rect
= GetUpdateRegion().GetBox();
267 if ( !rect
.width
&& !rect
.height
)
270 wxSize size
= GetSize();
272 rect
.height
= size
.y
;
275 if ( GetBackgroundBitmap().Ok() )
277 // get the bitmap and the flags
280 wxBitmap bmp
= GetBackgroundBitmap(&alignment
, &stretch
);
281 wxControlRenderer::DrawBitmap(dc
, bmp
, rect
, alignment
, stretch
);
283 else // just fill it with bg colour if no bitmap
285 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this),
286 rect
, GetStateFlags());
292 void wxWindow::EraseBackground(wxDC
& dc
, const wxRect
& rect
)
294 // TODO: handle bg bitmaps here!
296 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this), rect
, GetStateFlags());
299 void wxWindow::DoDrawBorder(wxDC
& dc
, const wxRect
& rect
)
301 // draw outline unless the update region is enitrely inside it in which
302 // case we don't need to do it
303 #if 0 // doesn't seem to work, why?
304 if ( wxRegion(rect
).Contains(GetUpdateRegion().GetBox()) != wxInRegion
)
307 m_renderer
->DrawBorder(dc
, GetBorder(), rect
, GetStateFlags());
311 void wxWindow::DoDraw(wxControlRenderer
*renderer
)
315 void wxWindow::Refresh(bool eraseBackground
, const wxRect
*rectClient
)
318 wxPoint pt
= GetClientAreaOrigin();
320 wxSize size
= GetClientSize();
324 rectWin
= *rectClient
;
326 // don't refresh anything beyond the client area (scrollbars for
328 if ( rectWin
.GetRight() > size
.x
)
329 rectWin
.SetRight(size
.x
);
330 if ( rectWin
.GetBottom() > size
.y
)
331 rectWin
.SetBottom(size
.y
);
335 else // refresh the entire client area
339 rectWin
.width
= size
.x
;
340 rectWin
.height
= size
.y
;
344 #ifdef WXDEBUG_REFRESH
345 static bool s_refreshDebug
= FALSE
;
346 if ( s_refreshDebug
)
349 dc
.SetBrush(*wxCYAN_BRUSH
);
350 dc
.SetPen(*wxTRANSPARENT_PEN
);
351 dc
.DrawRectangle(rectWin
);
353 // under Unix we use "--sync" X option for this
354 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
359 #endif // WXDEBUG_REFRESH
361 wxWindowNative::Refresh(eraseBackground
, &rectWin
);
364 // ----------------------------------------------------------------------------
366 // ----------------------------------------------------------------------------
368 bool wxWindow::Enable(bool enable
)
370 if ( !wxWindowNative::Enable(enable
) )
373 // disabled window can't keep focus
374 if ( FindFocus() == this && GetParent() != NULL
)
376 GetParent()->SetFocus();
381 // a window with renderer is drawn by ourselves and it has to be
382 // refreshed to reflect its new status
389 bool wxWindow::IsFocused() const
391 wxWindow
*self
= wxConstCast(this, wxWindow
);
392 return self
->FindFocus() == self
;
395 bool wxWindow::IsPressed() const
400 bool wxWindow::IsDefault() const
405 bool wxWindow::IsCurrent() const
410 bool wxWindow::SetCurrent(bool doit
)
412 if ( doit
== m_isCurrent
)
417 if ( CanBeHighlighted() )
423 int wxWindow::GetStateFlags() const
427 flags
|= wxCONTROL_DISABLED
;
429 // the following states are only possible if our application is active - if
430 // it is not, even our default/focused controls shouldn't appear as such
431 if ( wxTheApp
->IsActive() )
434 flags
|= wxCONTROL_CURRENT
;
436 flags
|= wxCONTROL_FOCUSED
;
438 flags
|= wxCONTROL_PRESSED
;
440 flags
|= wxCONTROL_ISDEFAULT
;
446 // ----------------------------------------------------------------------------
448 // ----------------------------------------------------------------------------
450 void wxWindow::OnSize(wxSizeEvent
& event
)
454 if ( m_scrollbarVert
|| m_scrollbarHorz
)
456 PositionScrollbars();
460 // Refresh the area (strip) previously occupied by the border
462 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE
) && IsShown())
464 // This code assumes that wxSizeEvent.GetSize() returns
465 // the area of the entire window, not just the client
467 wxSize newSize
= event
.GetSize();
469 if (m_oldSize
.x
== -1 && m_oldSize
.y
== -1)
475 if (HasFlag( wxSIMPLE_BORDER
))
477 if (newSize
.y
> m_oldSize
.y
)
481 rect
.width
= m_oldSize
.x
;
482 rect
.y
= m_oldSize
.y
-2;
484 Refresh( TRUE
, &rect
);
486 else if (newSize
.y
< m_oldSize
.y
)
492 rect
.width
= newSize
.x
;
493 wxWindowNative::Refresh( TRUE
, &rect
);
496 if (newSize
.x
> m_oldSize
.x
)
500 rect
.height
= m_oldSize
.y
;
501 rect
.x
= m_oldSize
.x
-2;
503 Refresh( TRUE
, &rect
);
505 else if (newSize
.x
< m_oldSize
.x
)
511 rect
.height
= newSize
.y
;
512 wxWindowNative::Refresh( TRUE
, &rect
);
516 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
518 if (newSize
.y
> m_oldSize
.y
)
522 rect
.width
= m_oldSize
.x
;
523 rect
.y
= m_oldSize
.y
-4;
525 Refresh( TRUE
, &rect
);
527 else if (newSize
.y
< m_oldSize
.y
)
533 rect
.width
= newSize
.x
;
534 wxWindowNative::Refresh( TRUE
, &rect
);
537 if (newSize
.x
> m_oldSize
.x
)
541 rect
.height
= m_oldSize
.y
;
542 rect
.x
= m_oldSize
.x
-4;
544 Refresh( TRUE
, &rect
);
546 else if (newSize
.x
< m_oldSize
.x
)
552 rect
.height
= newSize
.y
;
553 wxWindowNative::Refresh( TRUE
, &rect
);
562 wxSize
wxWindow::DoGetBestSize() const
564 return AdjustSize(DoGetBestClientSize());
567 wxSize
wxWindow::DoGetBestClientSize() const
569 return wxWindowNative::DoGetBestSize();
572 wxSize
wxWindow::AdjustSize(const wxSize
& size
) const
576 m_renderer
->AdjustSize(&sz
, this);
580 wxPoint
wxWindow::GetClientAreaOrigin() const
582 wxPoint pt
= wxWindowBase::GetClientAreaOrigin();
585 pt
+= m_renderer
->GetBorderDimensions(GetBorder()).GetPosition();
590 void wxWindow::DoGetClientSize(int *width
, int *height
) const
592 // if it is a native window, we assume it handles the scrollbars itself
593 // too - and if it doesn't, there is not much we can do
596 wxWindowNative::DoGetClientSize(width
, height
);
602 wxWindowNative::DoGetClientSize(&w
, &h
);
604 // we assume that the scrollbars are positioned correctly (by a previous
605 // call to PositionScrollbars()) here
609 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
611 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
615 // in any case, take account of the scrollbar
616 if ( m_scrollbarVert
)
617 w
-= m_scrollbarVert
->GetSize().x
;
619 // if we don't have scrollbar or if it is outside the border (and not
620 // blended into it), take account of the right border as well
621 if ( !m_scrollbarVert
|| inside
)
622 w
-= rectBorder
.width
;
624 // and always account for the left border
625 *width
= w
- rectBorder
.x
;
627 // we shouldn't return invalid width
634 if ( m_scrollbarHorz
)
635 h
-= m_scrollbarHorz
->GetSize().y
;
637 if ( !m_scrollbarHorz
|| inside
)
638 h
-= rectBorder
.height
;
640 *height
= h
- rectBorder
.y
;
642 // we shouldn't return invalid height
648 void wxWindow::DoSetClientSize(int width
, int height
)
650 // take into account the borders
651 wxRect rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
652 width
+= rectBorder
.x
;
653 height
+= rectBorder
.y
;
655 // and the scrollbars (as they may be offset into the border, use the
656 // scrollbar position, not size - this supposes that PositionScrollbars()
657 // had been called before)
658 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
659 wxSize size
= GetSize();
660 if ( m_scrollbarVert
)
661 width
+= size
.x
- m_scrollbarVert
->GetPosition().x
;
662 if ( !m_scrollbarVert
|| inside
)
663 width
+= rectBorder
.width
;
665 if ( m_scrollbarHorz
)
666 height
+= size
.y
- m_scrollbarHorz
->GetPosition().y
;
667 if ( !m_scrollbarHorz
|| inside
)
668 height
+= rectBorder
.height
;
670 wxWindowNative::DoSetClientSize(width
, height
);
673 wxHitTest
wxWindow::DoHitTest(wxCoord x
, wxCoord y
) const
675 wxHitTest ht
= wxWindowNative::DoHitTest(x
, y
);
676 if ( ht
== wxHT_WINDOW_INSIDE
)
678 if ( m_scrollbarVert
&& x
>= m_scrollbarVert
->GetPosition().x
)
680 // it can still be changed below because it may also be the corner
681 ht
= wxHT_WINDOW_VERT_SCROLLBAR
;
684 if ( m_scrollbarHorz
&& y
>= m_scrollbarHorz
->GetPosition().y
)
686 ht
= ht
== wxHT_WINDOW_VERT_SCROLLBAR
? wxHT_WINDOW_CORNER
687 : wxHT_WINDOW_HORZ_SCROLLBAR
;
694 // ----------------------------------------------------------------------------
695 // scrolling: we implement it entirely ourselves except for ScrollWindow()
696 // function which is supposed to be (efficiently) implemented by the native
698 // ----------------------------------------------------------------------------
700 void wxWindow::RefreshScrollbars()
702 if ( m_scrollbarHorz
)
703 m_scrollbarHorz
->Refresh();
705 if ( m_scrollbarVert
)
706 m_scrollbarVert
->Refresh();
709 void wxWindow::PositionScrollbars()
711 // do not use GetClientSize/Rect as it relies on the scrollbars being
712 // correctly positioned
714 wxSize size
= GetSize();
715 wxBorder border
= GetBorder();
716 wxRect rectBorder
= m_renderer
->GetBorderDimensions(border
);
717 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
719 int height
= m_scrollbarHorz
? m_scrollbarHorz
->GetSize().y
: 0;
720 int width
= m_scrollbarVert
? m_scrollbarVert
->GetSize().x
: 0;
723 if ( m_scrollbarVert
)
725 rectBar
.x
= size
.x
- width
;
727 rectBar
.x
-= rectBorder
.width
;
728 rectBar
.width
= width
;
731 rectBar
.y
+= rectBorder
.y
;
732 rectBar
.height
= size
.y
- height
;
734 rectBar
.height
-= rectBorder
.y
+ rectBorder
.height
;
736 m_scrollbarVert
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
739 if ( m_scrollbarHorz
)
741 rectBar
.y
= size
.y
- height
;
743 rectBar
.y
-= rectBorder
.height
;
744 rectBar
.height
= height
;
747 rectBar
.x
+= rectBorder
.x
;
748 rectBar
.width
= size
.x
- width
;
750 rectBar
.width
-= rectBorder
.x
+ rectBorder
.width
;
752 m_scrollbarHorz
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
758 void wxWindow::SetScrollbar(int orient
,
764 wxASSERT_MSG( pageSize
<= range
,
765 _T("page size can't be greater than range") );
767 bool hasClientSizeChanged
= FALSE
;
768 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
769 if ( range
&& (pageSize
< range
) )
774 scrollbar
= new wxScrollBar(this, -1,
775 wxDefaultPosition
, wxDefaultSize
,
776 orient
& wxVERTICAL
? wxSB_VERTICAL
778 if ( orient
& wxVERTICAL
)
779 m_scrollbarVert
= scrollbar
;
781 m_scrollbarHorz
= scrollbar
;
783 // the client area diminished as we created a scrollbar
784 hasClientSizeChanged
= TRUE
;
786 PositionScrollbars();
788 else if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
790 // we might have disabled it before
794 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
796 else // no range means no scrollbar
800 // wxALWAYS_SHOW_SB only applies to the vertical scrollbar
801 if ( (orient
& wxVERTICAL
) && (GetWindowStyle() & wxALWAYS_SHOW_SB
) )
803 // just disable the scrollbar
804 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
805 scrollbar
->Disable();
807 else // really remove the scrollbar
811 if ( orient
& wxVERTICAL
)
812 m_scrollbarVert
= NULL
;
814 m_scrollbarHorz
= NULL
;
816 // the client area increased as we removed a scrollbar
817 hasClientSizeChanged
= TRUE
;
819 // the size of the remaining scrollbar must be adjusted
820 if ( m_scrollbarHorz
|| m_scrollbarVert
)
822 PositionScrollbars();
828 // give the window a chance to relayout
829 if ( hasClientSizeChanged
)
831 wxSizeEvent
event(GetSize());
832 (void)GetEventHandler()->ProcessEvent(event
);
836 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
838 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
839 wxCHECK_RET( scrollbar
, _T("no scrollbar to set position for") );
841 scrollbar
->SetThumbPosition(pos
);
843 // VZ: I think we can safely ignore this as we always refresh it
844 // automatically whenever the value chanegs
851 int wxWindow::GetScrollPos(int orient
) const
853 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
854 return scrollbar
? scrollbar
->GetThumbPosition() : 0;
857 int wxWindow::GetScrollThumb(int orient
) const
859 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
860 return scrollbar
? scrollbar
->GetThumbSize() : 0;
863 int wxWindow::GetScrollRange(int orient
) const
865 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
866 return scrollbar
? scrollbar
->GetRange() : 0;
869 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
871 // use native scrolling when available and do it in generic way
875 wxWindowNative::ScrollWindow(dx
, dy
, rect
);
879 // before scrolling it, ensure that we don't have any unpainted areas
886 r
= ScrollNoRefresh(dx
, 0, rect
);
887 Refresh(TRUE
/* erase bkgnd */, &r
);
892 r
= ScrollNoRefresh(0, dy
, rect
);
893 Refresh(TRUE
/* erase bkgnd */, &r
);
896 // scroll children accordingly:
897 wxPoint
offset(dx
, dy
);
899 for (wxWindowList::Node
*node
= GetChildren().GetFirst();
900 node
; node
= node
->GetNext())
902 wxWindow
*child
= node
->GetData();
903 if ( child
== m_scrollbarVert
|| child
== m_scrollbarHorz
)
906 // VS: Scrolling children has non-trivial semantics. If rect=NULL then
907 // it is easy: we scroll all children. Otherwise it gets
909 // 1. if scrolling in one direction only, scroll only
910 // those children that intersect shaft defined by the rectangle
911 // and scrolling direction
912 // 2. if scrolling in both axes, scroll all children
914 if ( rect
&& (dx
* dy
== 0 /* moving in only one of x, y axis */) )
916 wxRect childRect
= child
->GetRect();
917 if ( dx
== 0 && (childRect
.GetLeft() <= rect
->GetRight() ||
918 childRect
.GetRight() >= rect
->GetLeft()) )
920 child
->Move(child
->GetPosition() + offset
);
922 else if ( dy
== 0 && (childRect
.GetTop() <= rect
->GetBottom() ||
923 childRect
.GetBottom() >= rect
->GetTop()) )
925 child
->Move(child
->GetPosition() + offset
);
930 child
->Move(child
->GetPosition() + offset
);
936 wxRect
wxWindow::ScrollNoRefresh(int dx
, int dy
, const wxRect
*rectTotal
)
938 wxASSERT_MSG( !dx
|| !dy
, _T("can't be used for diag scrolling") );
940 // the rect to refresh (which we will calculate)
949 // calculate the part of the window which we can just redraw in the new
951 wxSize sizeTotal
= rectTotal
? rectTotal
->GetSize() : GetClientSize();
953 wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
954 sizeTotal
.x
, sizeTotal
.y
, dx
, dy
);
956 // the initial and end point of the region we move in client coords
957 wxPoint ptSource
, ptDest
;
960 ptSource
= rectTotal
->GetPosition();
961 ptDest
= rectTotal
->GetPosition();
964 // the size of this region
966 size
.x
= sizeTotal
.x
- abs(dx
);
967 size
.y
= sizeTotal
.y
- abs(dy
);
968 if ( size
.x
<= 0 || size
.y
<= 0 )
970 // just redraw everything as nothing of the displayed image will stay
971 wxLogTrace(_T("scroll"), _T("refreshing everything"));
973 rect
= rectTotal
? *rectTotal
: wxRect(0, 0, sizeTotal
.x
, sizeTotal
.y
);
975 else // move the part which doesn't change to the new location
977 // note that when we scroll the canvas in some direction we move the
978 // block which doesn't need to be refreshed in the opposite direction
982 // scroll to the right, move to the left
987 // scroll to the left, move to the right
993 // scroll down, move up
998 // scroll up, move down
1003 // we need to hide the caret before moving or it will erase itself at
1004 // the wrong (old) location
1005 wxCaret
*caret
= GetCaret();
1008 #endif // wxUSE_CARET
1011 wxClientDC
dc(this);
1012 wxBitmap
bmp(size
.x
, size
.y
);
1014 dcMem
.SelectObject(bmp
);
1016 dcMem
.Blit(wxPoint(0, 0), size
, &dc
, ptSource
1017 #if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
1018 + GetClientAreaOrigin()
1019 #endif // broken wxGTK wxDC::Blit
1021 dc
.Blit(ptDest
, size
, &dcMem
, wxPoint(0, 0));
1023 wxLogTrace(_T("scroll"),
1024 _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
1025 ptSource
.x
, ptSource
.y
,
1027 ptDest
.x
, ptDest
.y
);
1029 // and now repaint the uncovered area
1031 // FIXME: We repaint the intersection of these rectangles twice - is
1032 // it bad? I don't think so as it is rare to scroll the window
1033 // diagonally anyhow and so adding extra logic to compute
1034 // rectangle intersection is probably not worth the effort
1036 rect
.x
= ptSource
.x
;
1037 rect
.y
= ptSource
.y
;
1043 // refresh the area along the right border
1044 rect
.x
+= size
.x
+ dx
;
1049 // refresh the area along the left border
1053 rect
.height
= sizeTotal
.y
;
1055 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1057 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1064 // refresh the area along the bottom border
1065 rect
.y
+= size
.y
+ dy
;
1070 // refresh the area along the top border
1074 rect
.width
= sizeTotal
.x
;
1076 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1078 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1084 #endif // wxUSE_CARET
1090 // ----------------------------------------------------------------------------
1091 // accelerators and menu hot keys
1092 // ----------------------------------------------------------------------------
1095 // the last window over which Alt was pressed (used by OnKeyUp)
1096 wxWindow
*wxWindow::ms_winLastAltPress
= NULL
;
1097 #endif // wxUSE_MENUS
1099 #if wxUSE_ACCEL || wxUSE_MENUS
1101 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1104 int key
= event
.GetKeyCode();
1105 if ( !event
.ControlDown() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1107 ms_winLastAltPress
= this;
1109 // it can't be an accel anyhow
1113 ms_winLastAltPress
= NULL
;
1114 #endif // wxUSE_MENUS
1117 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
1119 int command
= win
->GetAcceleratorTable()->GetCommand(event
);
1120 if ( command
!= -1 )
1122 wxCommandEvent
eventCmd(wxEVT_COMMAND_MENU_SELECTED
, command
);
1123 if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) )
1125 // skip "event.Skip()" below
1130 if ( win
->IsTopLevel() )
1132 // try the frame menu bar
1134 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1137 wxMenuBar
*menubar
= frame
->GetMenuBar();
1138 if ( menubar
&& menubar
->ProcessAccelEvent(event
) )
1140 // skip "event.Skip()" below
1144 #endif // wxUSE_MENUS
1146 // if it wasn't in a menu, try to find a button
1147 if ( command
!= -1 )
1149 wxWindow
* child
= win
->FindWindow(command
);
1150 if ( child
&& wxDynamicCast(child
, wxButton
) )
1152 wxCommandEvent
eventCmd(wxEVT_COMMAND_BUTTON_CLICKED
, command
);
1153 eventCmd
.SetEventObject(child
);
1154 if ( child
->GetEventHandler()->ProcessEvent(eventCmd
) )
1156 // skip "event.Skip()" below
1162 // don't propagate accels from the child frame to the parent one
1166 #endif // wxUSE_ACCEL
1171 #endif // wxUSE_ACCEL
1175 wxMenuBar
*wxWindow::GetParentFrameMenuBar() const
1177 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
1179 if ( win
->IsTopLevel() )
1181 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1184 return frame
->GetMenuBar();
1187 // don't look further - we don't want to return the menubar of the
1196 void wxWindow::OnChar(wxKeyEvent
& event
)
1198 if ( event
.AltDown() && !event
.ControlDown() )
1200 int key
= event
.GetKeyCode();
1202 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1205 int item
= menubar
->FindNextItemForAccel(-1, key
);
1208 menubar
->PopupMenu((size_t)item
);
1210 // skip "event.Skip()" below
1219 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1221 int key
= event
.GetKeyCode();
1222 if ( !event
.HasModifiers() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1224 // only process Alt release specially if there were no other key
1225 // presses since Alt had been pressed and if both events happened in
1227 if ( ms_winLastAltPress
== this )
1229 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1230 if ( menubar
&& this != menubar
)
1232 menubar
->SelectMenu(0);
1241 // in any case reset it
1242 ms_winLastAltPress
= NULL
;
1245 #endif // wxUSE_MENUS
1247 // ----------------------------------------------------------------------------
1248 // MSW-specific section
1249 // ----------------------------------------------------------------------------
1253 #include "wx/msw/private.h"
1255 long wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1257 if ( message
== WM_NCHITTEST
)
1259 // the windows which contain the other windows should let the mouse
1260 // events through, otherwise a window inside a static box would
1261 // never get any events at all
1262 if ( IsStaticBox() )
1264 return HTTRANSPARENT
;
1268 return wxWindowNative::MSWWindowProc(message
, wParam
, lParam
);