1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: univ/window.cpp
3 // Purpose: implementation of extra wxWindow methods for wxUniv port
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
21 #pragma implementation "univwindow.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/window.h"
34 #include "wx/dcclient.h"
35 #include "wx/dcmemory.h"
37 #include "wx/scrolbar.h"
43 #include "wx/univ/colschem.h"
44 #include "wx/univ/renderer.h"
45 #include "wx/univ/theme.h"
51 // turn Refresh() debugging on/off
52 #define WXDEBUG_REFRESH
55 #undef WXDEBUG_REFRESH
58 #if defined(WXDEBUG_REFRESH) && defined(__WXMSW__) && !defined(__WXMICROWIN__)
59 #include "wx/msw/private.h"
62 // ============================================================================
64 // ============================================================================
66 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
70 // we can't use wxWindowNative here as it won't be expanded inside the macro
71 #if defined(__WXMSW__)
72 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowMSW
)
73 #elif defined(__WXGTK__)
74 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowGTK
)
75 #elif defined(__WXMGL__)
76 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowMGL
)
77 #elif defined(__WXX11__)
78 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowX11
)
79 #elif defined(__WXPM__)
80 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowOS2
)
83 BEGIN_EVENT_TABLE(wxWindow
, wxWindowNative
)
84 EVT_SIZE(wxWindow::OnSize
)
86 #if wxUSE_ACCEL || wxUSE_MENUS
87 EVT_KEY_DOWN(wxWindow::OnKeyDown
)
91 EVT_CHAR(wxWindow::OnChar
)
92 EVT_KEY_UP(wxWindow::OnKeyUp
)
95 EVT_PAINT(wxWindow::OnPaint
)
96 EVT_NC_PAINT(wxWindow::OnNcPaint
)
97 EVT_ERASE_BACKGROUND(wxWindow::OnErase
)
100 // ----------------------------------------------------------------------------
102 // ----------------------------------------------------------------------------
104 void wxWindow::Init()
107 m_scrollbarHorz
= (wxScrollBar
*)NULL
;
111 m_renderer
= wxTheme::Get()->GetRenderer();
117 bool wxWindow::Create(wxWindow
*parent
,
122 const wxString
& name
)
124 // we add wxCLIP_CHILDREN to get the same ("natural") behaviour under MSW
125 // as under the other platforms
126 if ( !wxWindowNative::Create(parent
, id
, pos
, size
,
127 style
| wxCLIP_CHILDREN
,
133 // if we should always have the scrollbar, do show it
134 if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
136 #if wxUSE_TWO_WINDOWS
137 SetInsertIntoMain( TRUE
);
139 m_scrollbarVert
= new wxScrollBar(this, -1,
140 wxDefaultPosition
, wxDefaultSize
,
142 #if wxUSE_TWO_WINDOWS
143 SetInsertIntoMain( FALSE
);
147 PositionScrollbars();
153 // ----------------------------------------------------------------------------
155 // ----------------------------------------------------------------------------
157 void wxWindow::SetBackground(const wxBitmap
& bitmap
,
162 m_alignBgBitmap
= alignment
;
163 m_stretchBgBitmap
= stretch
;
166 const wxBitmap
& wxWindow::GetBackgroundBitmap(int *alignment
,
167 wxStretch
*stretch
) const
169 if ( m_bitmapBg
.Ok() )
172 *alignment
= m_alignBgBitmap
;
174 *stretch
= m_stretchBgBitmap
;
180 // ----------------------------------------------------------------------------
182 // ----------------------------------------------------------------------------
184 // the event handlers executed when the window must be repainted
185 void wxWindow::OnNcPaint(wxPaintEvent
& event
)
189 // get the window rect
191 wxSize size
= GetSize();
195 rect
.height
= size
.y
;
197 // if the scrollbars are outside the border, we must adjust the rect to
199 if ( !m_renderer
->AreScrollbarsInsideBorder() )
201 wxScrollBar
*scrollbar
= GetScrollbar(wxVERTICAL
);
203 rect
.width
-= scrollbar
->GetSize().x
;
205 scrollbar
= GetScrollbar(wxHORIZONTAL
);
207 rect
.height
-= scrollbar
->GetSize().y
;
210 // get the DC and draw the border on it
212 DoDrawBorder(dc
, rect
);
216 void wxWindow::OnPaint(wxPaintEvent
& event
)
220 // it is a native control which paints itself
225 // get the DC to use and create renderer on it
227 wxControlRenderer
renderer(this, dc
, m_renderer
);
234 // the event handler executed when the window background must be painted
235 void wxWindow::OnErase(wxEraseEvent
& event
)
244 DoDrawBackground(*event
.GetDC());
246 // if we have both scrollbars, we also have a square in the corner between
247 // them which we must paint
248 if ( m_scrollbarVert
&& m_scrollbarHorz
)
250 wxSize size
= GetSize();
251 wxRect rectClient
= GetClientRect(),
252 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
255 rectCorner
.x
= rectClient
.GetRight() + 1;
256 rectCorner
.y
= rectClient
.GetBottom() + 1;
257 rectCorner
.SetRight(size
.x
- rectBorder
.width
);
258 rectCorner
.SetBottom(size
.y
- rectBorder
.height
);
260 if ( GetUpdateRegion().Contains(rectCorner
) )
262 m_renderer
->DrawScrollCorner(*event
.GetDC(), rectCorner
);
267 bool wxWindow::DoDrawBackground(wxDC
& dc
)
271 wxSize size
= GetSize(); // Why not GetClientSize() ?
275 rect
.height
= size
.y
;
277 wxWindow
* const parent
= GetParent();
278 if ( HasTransparentBackground() && parent
&& parent
->ProvidesBackground() )
280 wxASSERT( !IsTopLevel() );
282 wxPoint pos
= GetPosition();
284 AdjustForParentClientOrigin( pos
.x
, pos
.y
, 0 );
286 // Adjust DC logical origin
287 wxCoord org_x
, org_y
, x
, y
;
288 dc
.GetLogicalOrigin( &org_x
, &org_y
);
291 dc
.SetLogicalOrigin( x
, y
);
297 // Let parent draw the background
298 parent
->EraseBackground( dc
, rect
);
300 // Restore DC logical origin
301 dc
.SetLogicalOrigin( org_x
, org_y
);
305 // Draw background ouselves
306 EraseBackground( dc
, rect
);
312 void wxWindow::EraseBackground(wxDC
& dc
, const wxRect
& rect
)
314 if ( GetBackgroundBitmap().Ok() )
316 // Get the bitmap and the flags
319 wxBitmap bmp
= GetBackgroundBitmap(&alignment
, &stretch
);
320 wxControlRenderer::DrawBitmap(dc
, bmp
, rect
, alignment
, stretch
);
324 // Just fill it with bg colour if no bitmap
326 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this),
327 rect
, GetStateFlags());
331 void wxWindow::DoDrawBorder(wxDC
& dc
, const wxRect
& rect
)
333 // draw outline unless the update region is enitrely inside it in which
334 // case we don't need to do it
335 #if 0 // doesn't seem to work, why?
336 if ( wxRegion(rect
).Contains(GetUpdateRegion().GetBox()) != wxInRegion
)
339 m_renderer
->DrawBorder(dc
, GetBorder(), rect
, GetStateFlags());
343 void wxWindow::DoDraw(wxControlRenderer
*renderer
)
347 void wxWindow::Refresh(bool eraseBackground
, const wxRect
*rectClient
)
350 wxPoint pt
= GetClientAreaOrigin();
352 wxSize size
= GetClientSize();
356 rectWin
= *rectClient
;
358 // don't refresh anything beyond the client area (scrollbars for
360 if ( rectWin
.GetRight() > size
.x
)
361 rectWin
.SetRight(size
.x
);
362 if ( rectWin
.GetBottom() > size
.y
)
363 rectWin
.SetBottom(size
.y
);
367 else // refresh the entire client area
371 rectWin
.width
= size
.x
;
372 rectWin
.height
= size
.y
;
376 #ifdef WXDEBUG_REFRESH
377 static bool s_refreshDebug
= FALSE
;
378 if ( s_refreshDebug
)
381 dc
.SetBrush(*wxCYAN_BRUSH
);
382 dc
.SetPen(*wxTRANSPARENT_PEN
);
383 dc
.DrawRectangle(rectWin
);
385 // under Unix we use "--sync" X option for this
386 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
391 #endif // WXDEBUG_REFRESH
393 wxWindowNative::Refresh(eraseBackground
, &rectWin
);
395 // Refresh all sub controls if any.
396 wxWindowList::Node
*node
= GetChildren().GetFirst();
399 wxWindow
*win
= node
->GetData();
400 // Only refresh sub controls when it is visible
401 // and when it is in the update region.
402 if(win
->IsShown() && wxRegion(rectWin
).Contains(win
->GetRect()) != wxOutRegion
)
403 win
->Refresh(eraseBackground
, &rectWin
);
405 node
= node
->GetNext();
409 // ----------------------------------------------------------------------------
411 // ----------------------------------------------------------------------------
413 bool wxWindow::Enable(bool enable
)
415 if ( !wxWindowNative::Enable(enable
) )
418 // disabled window can't keep focus
419 if ( FindFocus() == this && GetParent() != NULL
)
421 GetParent()->SetFocus();
426 // a window with renderer is drawn by ourselves and it has to be
427 // refreshed to reflect its new status
434 bool wxWindow::IsFocused() const
436 wxWindow
*self
= wxConstCast(this, wxWindow
);
437 return self
->FindFocus() == self
;
440 bool wxWindow::IsPressed() const
445 bool wxWindow::IsDefault() const
450 bool wxWindow::IsCurrent() const
455 bool wxWindow::SetCurrent(bool doit
)
457 if ( doit
== m_isCurrent
)
462 if ( CanBeHighlighted() )
468 int wxWindow::GetStateFlags() const
472 flags
|= wxCONTROL_DISABLED
;
474 // the following states are only possible if our application is active - if
475 // it is not, even our default/focused controls shouldn't appear as such
476 if ( wxTheApp
->IsActive() )
479 flags
|= wxCONTROL_CURRENT
;
481 flags
|= wxCONTROL_FOCUSED
;
483 flags
|= wxCONTROL_PRESSED
;
485 flags
|= wxCONTROL_ISDEFAULT
;
491 // ----------------------------------------------------------------------------
493 // ----------------------------------------------------------------------------
495 void wxWindow::OnSize(wxSizeEvent
& event
)
499 if ( m_scrollbarVert
|| m_scrollbarHorz
)
501 PositionScrollbars();
504 #if 0 // ndef __WXMSW__
505 // Refresh the area (strip) previously occupied by the border
507 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE
) && IsShown())
509 // This code assumes that wxSizeEvent.GetSize() returns
510 // the area of the entire window, not just the client
512 wxSize newSize
= event
.GetSize();
514 if (m_oldSize
.x
== -1 && m_oldSize
.y
== -1)
520 if (HasFlag( wxSIMPLE_BORDER
))
522 if (newSize
.y
> m_oldSize
.y
)
526 rect
.width
= m_oldSize
.x
;
527 rect
.y
= m_oldSize
.y
-2;
529 Refresh( TRUE
, &rect
);
531 else if (newSize
.y
< m_oldSize
.y
)
537 rect
.width
= newSize
.x
;
538 wxWindowNative::Refresh( TRUE
, &rect
);
541 if (newSize
.x
> m_oldSize
.x
)
545 rect
.height
= m_oldSize
.y
;
546 rect
.x
= m_oldSize
.x
-2;
548 Refresh( TRUE
, &rect
);
550 else if (newSize
.x
< m_oldSize
.x
)
556 rect
.height
= newSize
.y
;
557 wxWindowNative::Refresh( TRUE
, &rect
);
561 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
563 if (newSize
.y
> m_oldSize
.y
)
567 rect
.width
= m_oldSize
.x
;
568 rect
.y
= m_oldSize
.y
-4;
570 Refresh( TRUE
, &rect
);
572 else if (newSize
.y
< m_oldSize
.y
)
578 rect
.width
= newSize
.x
;
579 wxWindowNative::Refresh( TRUE
, &rect
);
582 if (newSize
.x
> m_oldSize
.x
)
586 rect
.height
= m_oldSize
.y
;
587 rect
.x
= m_oldSize
.x
-4;
589 Refresh( TRUE
, &rect
);
591 else if (newSize
.x
< m_oldSize
.x
)
597 rect
.height
= newSize
.y
;
598 wxWindowNative::Refresh( TRUE
, &rect
);
607 wxSize
wxWindow::DoGetBestSize() const
609 return AdjustSize(DoGetBestClientSize());
612 wxSize
wxWindow::DoGetBestClientSize() const
614 return wxWindowNative::DoGetBestSize();
617 wxSize
wxWindow::AdjustSize(const wxSize
& size
) const
621 m_renderer
->AdjustSize(&sz
, this);
625 wxPoint
wxWindow::GetClientAreaOrigin() const
627 wxPoint pt
= wxWindowBase::GetClientAreaOrigin();
629 #if wxUSE_TWO_WINDOWS
632 pt
+= m_renderer
->GetBorderDimensions(GetBorder()).GetPosition();
638 void wxWindow::DoGetClientSize(int *width
, int *height
) const
640 // if it is a native window, we assume it handles the scrollbars itself
641 // too - and if it doesn't, there is not much we can do
644 wxWindowNative::DoGetClientSize(width
, height
);
650 wxWindowNative::DoGetClientSize(&w
, &h
);
652 // we assume that the scrollbars are positioned correctly (by a previous
653 // call to PositionScrollbars()) here
657 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
659 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
663 // in any case, take account of the scrollbar
664 if ( m_scrollbarVert
)
665 w
-= m_scrollbarVert
->GetSize().x
;
667 // if we don't have scrollbar or if it is outside the border (and not
668 // blended into it), take account of the right border as well
669 if ( !m_scrollbarVert
|| inside
)
670 w
-= rectBorder
.width
;
672 // and always account for the left border
673 *width
= w
- rectBorder
.x
;
675 // we shouldn't return invalid width
682 if ( m_scrollbarHorz
)
683 h
-= m_scrollbarHorz
->GetSize().y
;
685 if ( !m_scrollbarHorz
|| inside
)
686 h
-= rectBorder
.height
;
688 *height
= h
- rectBorder
.y
;
690 // we shouldn't return invalid height
696 void wxWindow::DoSetClientSize(int width
, int height
)
698 // take into account the borders
699 wxRect rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
700 width
+= rectBorder
.x
;
701 height
+= rectBorder
.y
;
703 // and the scrollbars (as they may be offset into the border, use the
704 // scrollbar position, not size - this supposes that PositionScrollbars()
705 // had been called before)
706 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
707 wxSize size
= GetSize();
708 if ( m_scrollbarVert
)
709 width
+= size
.x
- m_scrollbarVert
->GetPosition().x
;
710 if ( !m_scrollbarVert
|| inside
)
711 width
+= rectBorder
.width
;
713 if ( m_scrollbarHorz
)
714 height
+= size
.y
- m_scrollbarHorz
->GetPosition().y
;
715 if ( !m_scrollbarHorz
|| inside
)
716 height
+= rectBorder
.height
;
718 wxWindowNative::DoSetClientSize(width
, height
);
721 wxHitTest
wxWindow::DoHitTest(wxCoord x
, wxCoord y
) const
723 wxHitTest ht
= wxWindowNative::DoHitTest(x
, y
);
724 if ( ht
== wxHT_WINDOW_INSIDE
)
726 if ( m_scrollbarVert
&& x
>= m_scrollbarVert
->GetPosition().x
)
728 // it can still be changed below because it may also be the corner
729 ht
= wxHT_WINDOW_VERT_SCROLLBAR
;
732 if ( m_scrollbarHorz
&& y
>= m_scrollbarHorz
->GetPosition().y
)
734 ht
= ht
== wxHT_WINDOW_VERT_SCROLLBAR
? wxHT_WINDOW_CORNER
735 : wxHT_WINDOW_HORZ_SCROLLBAR
;
742 // ----------------------------------------------------------------------------
743 // scrolling: we implement it entirely ourselves except for ScrollWindow()
744 // function which is supposed to be (efficiently) implemented by the native
746 // ----------------------------------------------------------------------------
748 void wxWindow::RefreshScrollbars()
750 if ( m_scrollbarHorz
)
751 m_scrollbarHorz
->Refresh();
753 if ( m_scrollbarVert
)
754 m_scrollbarVert
->Refresh();
757 void wxWindow::PositionScrollbars()
759 // do not use GetClientSize/Rect as it relies on the scrollbars being
760 // correctly positioned
762 wxSize size
= GetSize();
763 wxBorder border
= GetBorder();
764 wxRect rectBorder
= m_renderer
->GetBorderDimensions(border
);
765 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
767 int height
= m_scrollbarHorz
? m_scrollbarHorz
->GetSize().y
: 0;
768 int width
= m_scrollbarVert
? m_scrollbarVert
->GetSize().x
: 0;
771 if ( m_scrollbarVert
)
773 rectBar
.x
= size
.x
- width
;
775 rectBar
.x
-= rectBorder
.width
;
776 rectBar
.width
= width
;
779 rectBar
.y
+= rectBorder
.y
;
780 rectBar
.height
= size
.y
- height
;
782 rectBar
.height
-= rectBorder
.y
+ rectBorder
.height
;
784 m_scrollbarVert
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
787 if ( m_scrollbarHorz
)
789 rectBar
.y
= size
.y
- height
;
791 rectBar
.y
-= rectBorder
.height
;
792 rectBar
.height
= height
;
795 rectBar
.x
+= rectBorder
.x
;
796 rectBar
.width
= size
.x
- width
;
798 rectBar
.width
-= rectBorder
.x
+ rectBorder
.width
;
800 m_scrollbarHorz
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
806 void wxWindow::SetScrollbar(int orient
,
812 wxASSERT_MSG( pageSize
<= range
,
813 _T("page size can't be greater than range") );
815 bool hasClientSizeChanged
= FALSE
;
816 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
817 if ( range
&& (pageSize
< range
) )
822 #if wxUSE_TWO_WINDOWS
823 SetInsertIntoMain( TRUE
);
825 scrollbar
= new wxScrollBar(this, -1,
826 wxDefaultPosition
, wxDefaultSize
,
827 orient
& wxVERTICAL
? wxSB_VERTICAL
829 #if wxUSE_TWO_WINDOWS
830 SetInsertIntoMain( FALSE
);
832 if ( orient
& wxVERTICAL
)
833 m_scrollbarVert
= scrollbar
;
835 m_scrollbarHorz
= scrollbar
;
837 // the client area diminished as we created a scrollbar
838 hasClientSizeChanged
= TRUE
;
840 PositionScrollbars();
842 else if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
844 // we might have disabled it before
848 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
850 else // no range means no scrollbar
854 // wxALWAYS_SHOW_SB only applies to the vertical scrollbar
855 if ( (orient
& wxVERTICAL
) && (GetWindowStyle() & wxALWAYS_SHOW_SB
) )
857 // just disable the scrollbar
858 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
859 scrollbar
->Disable();
861 else // really remove the scrollbar
865 if ( orient
& wxVERTICAL
)
866 m_scrollbarVert
= NULL
;
868 m_scrollbarHorz
= NULL
;
870 // the client area increased as we removed a scrollbar
871 hasClientSizeChanged
= TRUE
;
873 // the size of the remaining scrollbar must be adjusted
874 if ( m_scrollbarHorz
|| m_scrollbarVert
)
876 PositionScrollbars();
882 // give the window a chance to relayout
883 if ( hasClientSizeChanged
)
885 #if wxUSE_TWO_WINDOWS
886 wxWindowNative::SetSize( GetSize() );
888 wxSizeEvent
event(GetSize());
889 (void)GetEventHandler()->ProcessEvent(event
);
894 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
896 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
897 wxCHECK_RET( scrollbar
, _T("no scrollbar to set position for") );
899 scrollbar
->SetThumbPosition(pos
);
901 // VZ: I think we can safely ignore this as we always refresh it
902 // automatically whenever the value chanegs
909 int wxWindow::GetScrollPos(int orient
) const
911 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
912 return scrollbar
? scrollbar
->GetThumbPosition() : 0;
915 int wxWindow::GetScrollThumb(int orient
) const
917 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
918 return scrollbar
? scrollbar
->GetThumbSize() : 0;
921 int wxWindow::GetScrollRange(int orient
) const
923 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
924 return scrollbar
? scrollbar
->GetRange() : 0;
927 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
929 // use native scrolling when available and do it in generic way
933 wxWindowNative::ScrollWindow(dx
, dy
, rect
);
937 // before scrolling it, ensure that we don't have any unpainted areas
944 r
= ScrollNoRefresh(dx
, 0, rect
);
945 Refresh(TRUE
/* erase bkgnd */, &r
);
950 r
= ScrollNoRefresh(0, dy
, rect
);
951 Refresh(TRUE
/* erase bkgnd */, &r
);
954 // scroll children accordingly:
955 wxPoint
offset(dx
, dy
);
957 for (wxWindowList::Node
*node
= GetChildren().GetFirst();
958 node
; node
= node
->GetNext())
960 wxWindow
*child
= node
->GetData();
961 if ( child
== m_scrollbarVert
|| child
== m_scrollbarHorz
)
964 // VS: Scrolling children has non-trivial semantics. If rect=NULL then
965 // it is easy: we scroll all children. Otherwise it gets
967 // 1. if scrolling in one direction only, scroll only
968 // those children that intersect shaft defined by the rectangle
969 // and scrolling direction
970 // 2. if scrolling in both axes, scroll all children
972 if ( rect
&& (dx
* dy
== 0 /* moving in only one of x, y axis */) )
974 wxRect childRect
= child
->GetRect();
975 if ( dx
== 0 && (childRect
.GetLeft() <= rect
->GetRight() ||
976 childRect
.GetRight() >= rect
->GetLeft()) )
978 child
->Move(child
->GetPosition() + offset
);
980 else if ( dy
== 0 && (childRect
.GetTop() <= rect
->GetBottom() ||
981 childRect
.GetBottom() >= rect
->GetTop()) )
983 child
->Move(child
->GetPosition() + offset
);
988 child
->Move(child
->GetPosition() + offset
);
991 #endif // wxX11/!wxX11
994 wxRect
wxWindow::ScrollNoRefresh(int dx
, int dy
, const wxRect
*rectTotal
)
996 wxASSERT_MSG( !dx
|| !dy
, _T("can't be used for diag scrolling") );
998 // the rect to refresh (which we will calculate)
1007 // calculate the part of the window which we can just redraw in the new
1009 wxSize sizeTotal
= rectTotal
? rectTotal
->GetSize() : GetClientSize();
1011 wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
1012 sizeTotal
.x
, sizeTotal
.y
, dx
, dy
);
1014 // the initial and end point of the region we move in client coords
1015 wxPoint ptSource
, ptDest
;
1018 ptSource
= rectTotal
->GetPosition();
1019 ptDest
= rectTotal
->GetPosition();
1022 // the size of this region
1024 size
.x
= sizeTotal
.x
- abs(dx
);
1025 size
.y
= sizeTotal
.y
- abs(dy
);
1026 if ( size
.x
<= 0 || size
.y
<= 0 )
1028 // just redraw everything as nothing of the displayed image will stay
1029 wxLogTrace(_T("scroll"), _T("refreshing everything"));
1031 rect
= rectTotal
? *rectTotal
: wxRect(0, 0, sizeTotal
.x
, sizeTotal
.y
);
1033 else // move the part which doesn't change to the new location
1035 // note that when we scroll the canvas in some direction we move the
1036 // block which doesn't need to be refreshed in the opposite direction
1040 // scroll to the right, move to the left
1045 // scroll to the left, move to the right
1051 // scroll down, move up
1056 // scroll up, move down
1061 // we need to hide the caret before moving or it will erase itself at
1062 // the wrong (old) location
1063 wxCaret
*caret
= GetCaret();
1066 #endif // wxUSE_CARET
1069 wxClientDC
dc(this);
1070 wxBitmap
bmp(size
.x
, size
.y
);
1072 dcMem
.SelectObject(bmp
);
1074 dcMem
.Blit(wxPoint(0, 0), size
, &dc
, ptSource
1075 #if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
1076 + GetClientAreaOrigin()
1077 #endif // broken wxGTK wxDC::Blit
1079 dc
.Blit(ptDest
, size
, &dcMem
, wxPoint(0, 0));
1081 wxLogTrace(_T("scroll"),
1082 _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
1083 ptSource
.x
, ptSource
.y
,
1085 ptDest
.x
, ptDest
.y
);
1087 // and now repaint the uncovered area
1089 // FIXME: We repaint the intersection of these rectangles twice - is
1090 // it bad? I don't think so as it is rare to scroll the window
1091 // diagonally anyhow and so adding extra logic to compute
1092 // rectangle intersection is probably not worth the effort
1094 rect
.x
= ptSource
.x
;
1095 rect
.y
= ptSource
.y
;
1101 // refresh the area along the right border
1102 rect
.x
+= size
.x
+ dx
;
1107 // refresh the area along the left border
1111 rect
.height
= sizeTotal
.y
;
1113 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1115 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1122 // refresh the area along the bottom border
1123 rect
.y
+= size
.y
+ dy
;
1128 // refresh the area along the top border
1132 rect
.width
= sizeTotal
.x
;
1134 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1136 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1142 #endif // wxUSE_CARET
1148 // ----------------------------------------------------------------------------
1149 // accelerators and menu hot keys
1150 // ----------------------------------------------------------------------------
1153 // the last window over which Alt was pressed (used by OnKeyUp)
1154 wxWindow
*wxWindow::ms_winLastAltPress
= NULL
;
1155 #endif // wxUSE_MENUS
1157 #if wxUSE_ACCEL || wxUSE_MENUS
1159 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1162 int key
= event
.GetKeyCode();
1163 if ( !event
.ControlDown() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1165 ms_winLastAltPress
= this;
1167 // it can't be an accel anyhow
1171 ms_winLastAltPress
= NULL
;
1172 #endif // wxUSE_MENUS
1175 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
1177 int command
= win
->GetAcceleratorTable()->GetCommand(event
);
1178 if ( command
!= -1 )
1180 wxCommandEvent
eventCmd(wxEVT_COMMAND_MENU_SELECTED
, command
);
1181 if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) )
1183 // skip "event.Skip()" below
1188 if ( win
->IsTopLevel() )
1190 // try the frame menu bar
1192 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1195 wxMenuBar
*menubar
= frame
->GetMenuBar();
1196 if ( menubar
&& menubar
->ProcessAccelEvent(event
) )
1198 // skip "event.Skip()" below
1202 #endif // wxUSE_MENUS
1204 // if it wasn't in a menu, try to find a button
1205 if ( command
!= -1 )
1207 wxWindow
* child
= win
->FindWindow(command
);
1208 if ( child
&& wxDynamicCast(child
, wxButton
) )
1210 wxCommandEvent
eventCmd(wxEVT_COMMAND_BUTTON_CLICKED
, command
);
1211 eventCmd
.SetEventObject(child
);
1212 if ( child
->GetEventHandler()->ProcessEvent(eventCmd
) )
1214 // skip "event.Skip()" below
1220 // don't propagate accels from the child frame to the parent one
1224 #endif // wxUSE_ACCEL
1229 #endif // wxUSE_ACCEL
1233 wxMenuBar
*wxWindow::GetParentFrameMenuBar() const
1235 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
1237 if ( win
->IsTopLevel() )
1239 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1242 return frame
->GetMenuBar();
1245 // don't look further - we don't want to return the menubar of the
1254 void wxWindow::OnChar(wxKeyEvent
& event
)
1256 if ( event
.AltDown() && !event
.ControlDown() )
1258 int key
= event
.GetKeyCode();
1260 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1263 int item
= menubar
->FindNextItemForAccel(-1, key
);
1266 menubar
->PopupMenu((size_t)item
);
1268 // skip "event.Skip()" below
1277 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1279 int key
= event
.GetKeyCode();
1280 if ( !event
.HasModifiers() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1282 // only process Alt release specially if there were no other key
1283 // presses since Alt had been pressed and if both events happened in
1285 if ( ms_winLastAltPress
== this )
1287 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1288 if ( menubar
&& this != menubar
)
1290 menubar
->SelectMenu(0);
1299 // in any case reset it
1300 ms_winLastAltPress
= NULL
;
1303 #endif // wxUSE_MENUS
1305 // ----------------------------------------------------------------------------
1306 // MSW-specific section
1307 // ----------------------------------------------------------------------------
1311 #include "wx/msw/private.h"
1313 long wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1315 if ( message
== WM_NCHITTEST
)
1317 // the windows which contain the other windows should let the mouse
1318 // events through, otherwise a window inside a static box would
1319 // never get any events at all
1320 if ( IsStaticBox() )
1322 return HTTRANSPARENT
;
1326 return wxWindowNative::MSWWindowProc(message
, wParam
, lParam
);