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 #if wxUSE_TWO_WINDOWS
847 wxWindowNative::SetSize( GetSize() );
849 wxSizeEvent
event(GetSize());
850 (void)GetEventHandler()->ProcessEvent(event
);
855 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
857 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
858 wxCHECK_RET( scrollbar
, _T("no scrollbar to set position for") );
860 scrollbar
->SetThumbPosition(pos
);
862 // VZ: I think we can safely ignore this as we always refresh it
863 // automatically whenever the value chanegs
870 int wxWindow::GetScrollPos(int orient
) const
872 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
873 return scrollbar
? scrollbar
->GetThumbPosition() : 0;
876 int wxWindow::GetScrollThumb(int orient
) const
878 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
879 return scrollbar
? scrollbar
->GetThumbSize() : 0;
882 int wxWindow::GetScrollRange(int orient
) const
884 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
885 return scrollbar
? scrollbar
->GetRange() : 0;
888 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
890 // use native scrolling when available and do it in generic way
894 wxWindowNative::ScrollWindow(dx
, dy
, rect
);
898 // before scrolling it, ensure that we don't have any unpainted areas
905 r
= ScrollNoRefresh(dx
, 0, rect
);
906 Refresh(TRUE
/* erase bkgnd */, &r
);
911 r
= ScrollNoRefresh(0, dy
, rect
);
912 Refresh(TRUE
/* erase bkgnd */, &r
);
915 // scroll children accordingly:
916 wxPoint
offset(dx
, dy
);
918 for (wxWindowList::Node
*node
= GetChildren().GetFirst();
919 node
; node
= node
->GetNext())
921 wxWindow
*child
= node
->GetData();
922 if ( child
== m_scrollbarVert
|| child
== m_scrollbarHorz
)
925 // VS: Scrolling children has non-trivial semantics. If rect=NULL then
926 // it is easy: we scroll all children. Otherwise it gets
928 // 1. if scrolling in one direction only, scroll only
929 // those children that intersect shaft defined by the rectangle
930 // and scrolling direction
931 // 2. if scrolling in both axes, scroll all children
933 if ( rect
&& (dx
* dy
== 0 /* moving in only one of x, y axis */) )
935 wxRect childRect
= child
->GetRect();
936 if ( dx
== 0 && (childRect
.GetLeft() <= rect
->GetRight() ||
937 childRect
.GetRight() >= rect
->GetLeft()) )
939 child
->Move(child
->GetPosition() + offset
);
941 else if ( dy
== 0 && (childRect
.GetTop() <= rect
->GetBottom() ||
942 childRect
.GetBottom() >= rect
->GetTop()) )
944 child
->Move(child
->GetPosition() + offset
);
949 child
->Move(child
->GetPosition() + offset
);
955 wxRect
wxWindow::ScrollNoRefresh(int dx
, int dy
, const wxRect
*rectTotal
)
957 wxASSERT_MSG( !dx
|| !dy
, _T("can't be used for diag scrolling") );
959 // the rect to refresh (which we will calculate)
968 // calculate the part of the window which we can just redraw in the new
970 wxSize sizeTotal
= rectTotal
? rectTotal
->GetSize() : GetClientSize();
972 wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
973 sizeTotal
.x
, sizeTotal
.y
, dx
, dy
);
975 // the initial and end point of the region we move in client coords
976 wxPoint ptSource
, ptDest
;
979 ptSource
= rectTotal
->GetPosition();
980 ptDest
= rectTotal
->GetPosition();
983 // the size of this region
985 size
.x
= sizeTotal
.x
- abs(dx
);
986 size
.y
= sizeTotal
.y
- abs(dy
);
987 if ( size
.x
<= 0 || size
.y
<= 0 )
989 // just redraw everything as nothing of the displayed image will stay
990 wxLogTrace(_T("scroll"), _T("refreshing everything"));
992 rect
= rectTotal
? *rectTotal
: wxRect(0, 0, sizeTotal
.x
, sizeTotal
.y
);
994 else // move the part which doesn't change to the new location
996 // note that when we scroll the canvas in some direction we move the
997 // block which doesn't need to be refreshed in the opposite direction
1001 // scroll to the right, move to the left
1006 // scroll to the left, move to the right
1012 // scroll down, move up
1017 // scroll up, move down
1022 // we need to hide the caret before moving or it will erase itself at
1023 // the wrong (old) location
1024 wxCaret
*caret
= GetCaret();
1027 #endif // wxUSE_CARET
1030 wxClientDC
dc(this);
1031 wxBitmap
bmp(size
.x
, size
.y
);
1033 dcMem
.SelectObject(bmp
);
1035 dcMem
.Blit(wxPoint(0, 0), size
, &dc
, ptSource
1036 #if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
1037 + GetClientAreaOrigin()
1038 #endif // broken wxGTK wxDC::Blit
1040 dc
.Blit(ptDest
, size
, &dcMem
, wxPoint(0, 0));
1042 wxLogTrace(_T("scroll"),
1043 _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
1044 ptSource
.x
, ptSource
.y
,
1046 ptDest
.x
, ptDest
.y
);
1048 // and now repaint the uncovered area
1050 // FIXME: We repaint the intersection of these rectangles twice - is
1051 // it bad? I don't think so as it is rare to scroll the window
1052 // diagonally anyhow and so adding extra logic to compute
1053 // rectangle intersection is probably not worth the effort
1055 rect
.x
= ptSource
.x
;
1056 rect
.y
= ptSource
.y
;
1062 // refresh the area along the right border
1063 rect
.x
+= size
.x
+ dx
;
1068 // refresh the area along the left border
1072 rect
.height
= sizeTotal
.y
;
1074 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1076 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1083 // refresh the area along the bottom border
1084 rect
.y
+= size
.y
+ dy
;
1089 // refresh the area along the top border
1093 rect
.width
= sizeTotal
.x
;
1095 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1097 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1103 #endif // wxUSE_CARET
1109 // ----------------------------------------------------------------------------
1110 // accelerators and menu hot keys
1111 // ----------------------------------------------------------------------------
1114 // the last window over which Alt was pressed (used by OnKeyUp)
1115 wxWindow
*wxWindow::ms_winLastAltPress
= NULL
;
1116 #endif // wxUSE_MENUS
1118 #if wxUSE_ACCEL || wxUSE_MENUS
1120 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1123 int key
= event
.GetKeyCode();
1124 if ( !event
.ControlDown() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1126 ms_winLastAltPress
= this;
1128 // it can't be an accel anyhow
1132 ms_winLastAltPress
= NULL
;
1133 #endif // wxUSE_MENUS
1136 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
1138 int command
= win
->GetAcceleratorTable()->GetCommand(event
);
1139 if ( command
!= -1 )
1141 wxCommandEvent
eventCmd(wxEVT_COMMAND_MENU_SELECTED
, command
);
1142 if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) )
1144 // skip "event.Skip()" below
1149 if ( win
->IsTopLevel() )
1151 // try the frame menu bar
1153 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1156 wxMenuBar
*menubar
= frame
->GetMenuBar();
1157 if ( menubar
&& menubar
->ProcessAccelEvent(event
) )
1159 // skip "event.Skip()" below
1163 #endif // wxUSE_MENUS
1165 // if it wasn't in a menu, try to find a button
1166 if ( command
!= -1 )
1168 wxWindow
* child
= win
->FindWindow(command
);
1169 if ( child
&& wxDynamicCast(child
, wxButton
) )
1171 wxCommandEvent
eventCmd(wxEVT_COMMAND_BUTTON_CLICKED
, command
);
1172 eventCmd
.SetEventObject(child
);
1173 if ( child
->GetEventHandler()->ProcessEvent(eventCmd
) )
1175 // skip "event.Skip()" below
1181 // don't propagate accels from the child frame to the parent one
1185 #endif // wxUSE_ACCEL
1190 #endif // wxUSE_ACCEL
1194 wxMenuBar
*wxWindow::GetParentFrameMenuBar() const
1196 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
1198 if ( win
->IsTopLevel() )
1200 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1203 return frame
->GetMenuBar();
1206 // don't look further - we don't want to return the menubar of the
1215 void wxWindow::OnChar(wxKeyEvent
& event
)
1217 if ( event
.AltDown() && !event
.ControlDown() )
1219 int key
= event
.GetKeyCode();
1221 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1224 int item
= menubar
->FindNextItemForAccel(-1, key
);
1227 menubar
->PopupMenu((size_t)item
);
1229 // skip "event.Skip()" below
1238 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1240 int key
= event
.GetKeyCode();
1241 if ( !event
.HasModifiers() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1243 // only process Alt release specially if there were no other key
1244 // presses since Alt had been pressed and if both events happened in
1246 if ( ms_winLastAltPress
== this )
1248 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1249 if ( menubar
&& this != menubar
)
1251 menubar
->SelectMenu(0);
1260 // in any case reset it
1261 ms_winLastAltPress
= NULL
;
1264 #endif // wxUSE_MENUS
1266 // ----------------------------------------------------------------------------
1267 // MSW-specific section
1268 // ----------------------------------------------------------------------------
1272 #include "wx/msw/private.h"
1274 long wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1276 if ( message
== WM_NCHITTEST
)
1278 // the windows which contain the other windows should let the mouse
1279 // events through, otherwise a window inside a static box would
1280 // never get any events at all
1281 if ( IsStaticBox() )
1283 return HTTRANSPARENT
;
1287 return wxWindowNative::MSWWindowProc(message
, wParam
, lParam
);