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
);
396 // ----------------------------------------------------------------------------
398 // ----------------------------------------------------------------------------
400 bool wxWindow::Enable(bool enable
)
402 if ( !wxWindowNative::Enable(enable
) )
405 // disabled window can't keep focus
406 if ( FindFocus() == this && GetParent() != NULL
)
408 GetParent()->SetFocus();
413 // a window with renderer is drawn by ourselves and it has to be
414 // refreshed to reflect its new status
421 bool wxWindow::IsFocused() const
423 wxWindow
*self
= wxConstCast(this, wxWindow
);
424 return self
->FindFocus() == self
;
427 bool wxWindow::IsPressed() const
432 bool wxWindow::IsDefault() const
437 bool wxWindow::IsCurrent() const
442 bool wxWindow::SetCurrent(bool doit
)
444 if ( doit
== m_isCurrent
)
449 if ( CanBeHighlighted() )
455 int wxWindow::GetStateFlags() const
459 flags
|= wxCONTROL_DISABLED
;
461 // the following states are only possible if our application is active - if
462 // it is not, even our default/focused controls shouldn't appear as such
463 if ( wxTheApp
->IsActive() )
466 flags
|= wxCONTROL_CURRENT
;
468 flags
|= wxCONTROL_FOCUSED
;
470 flags
|= wxCONTROL_PRESSED
;
472 flags
|= wxCONTROL_ISDEFAULT
;
478 // ----------------------------------------------------------------------------
480 // ----------------------------------------------------------------------------
482 void wxWindow::OnSize(wxSizeEvent
& event
)
486 if ( m_scrollbarVert
|| m_scrollbarHorz
)
488 PositionScrollbars();
491 #if 0 // ndef __WXMSW__
492 // Refresh the area (strip) previously occupied by the border
494 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE
) && IsShown())
496 // This code assumes that wxSizeEvent.GetSize() returns
497 // the area of the entire window, not just the client
499 wxSize newSize
= event
.GetSize();
501 if (m_oldSize
.x
== -1 && m_oldSize
.y
== -1)
507 if (HasFlag( wxSIMPLE_BORDER
))
509 if (newSize
.y
> m_oldSize
.y
)
513 rect
.width
= m_oldSize
.x
;
514 rect
.y
= m_oldSize
.y
-2;
516 Refresh( TRUE
, &rect
);
518 else if (newSize
.y
< m_oldSize
.y
)
524 rect
.width
= newSize
.x
;
525 wxWindowNative::Refresh( TRUE
, &rect
);
528 if (newSize
.x
> m_oldSize
.x
)
532 rect
.height
= m_oldSize
.y
;
533 rect
.x
= m_oldSize
.x
-2;
535 Refresh( TRUE
, &rect
);
537 else if (newSize
.x
< m_oldSize
.x
)
543 rect
.height
= newSize
.y
;
544 wxWindowNative::Refresh( TRUE
, &rect
);
548 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
550 if (newSize
.y
> m_oldSize
.y
)
554 rect
.width
= m_oldSize
.x
;
555 rect
.y
= m_oldSize
.y
-4;
557 Refresh( TRUE
, &rect
);
559 else if (newSize
.y
< m_oldSize
.y
)
565 rect
.width
= newSize
.x
;
566 wxWindowNative::Refresh( TRUE
, &rect
);
569 if (newSize
.x
> m_oldSize
.x
)
573 rect
.height
= m_oldSize
.y
;
574 rect
.x
= m_oldSize
.x
-4;
576 Refresh( TRUE
, &rect
);
578 else if (newSize
.x
< m_oldSize
.x
)
584 rect
.height
= newSize
.y
;
585 wxWindowNative::Refresh( TRUE
, &rect
);
594 wxSize
wxWindow::DoGetBestSize() const
596 return AdjustSize(DoGetBestClientSize());
599 wxSize
wxWindow::DoGetBestClientSize() const
601 return wxWindowNative::DoGetBestSize();
604 wxSize
wxWindow::AdjustSize(const wxSize
& size
) const
608 m_renderer
->AdjustSize(&sz
, this);
612 wxPoint
wxWindow::GetClientAreaOrigin() const
614 wxPoint pt
= wxWindowBase::GetClientAreaOrigin();
616 #if wxUSE_TWO_WINDOWS
619 pt
+= m_renderer
->GetBorderDimensions(GetBorder()).GetPosition();
625 void wxWindow::DoGetClientSize(int *width
, int *height
) const
627 // if it is a native window, we assume it handles the scrollbars itself
628 // too - and if it doesn't, there is not much we can do
631 wxWindowNative::DoGetClientSize(width
, height
);
637 wxWindowNative::DoGetClientSize(&w
, &h
);
639 // we assume that the scrollbars are positioned correctly (by a previous
640 // call to PositionScrollbars()) here
644 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
646 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
650 // in any case, take account of the scrollbar
651 if ( m_scrollbarVert
)
652 w
-= m_scrollbarVert
->GetSize().x
;
654 // if we don't have scrollbar or if it is outside the border (and not
655 // blended into it), take account of the right border as well
656 if ( !m_scrollbarVert
|| inside
)
657 w
-= rectBorder
.width
;
659 // and always account for the left border
660 *width
= w
- rectBorder
.x
;
662 // we shouldn't return invalid width
669 if ( m_scrollbarHorz
)
670 h
-= m_scrollbarHorz
->GetSize().y
;
672 if ( !m_scrollbarHorz
|| inside
)
673 h
-= rectBorder
.height
;
675 *height
= h
- rectBorder
.y
;
677 // we shouldn't return invalid height
683 void wxWindow::DoSetClientSize(int width
, int height
)
685 // take into account the borders
686 wxRect rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
687 width
+= rectBorder
.x
;
688 height
+= rectBorder
.y
;
690 // and the scrollbars (as they may be offset into the border, use the
691 // scrollbar position, not size - this supposes that PositionScrollbars()
692 // had been called before)
693 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
694 wxSize size
= GetSize();
695 if ( m_scrollbarVert
)
696 width
+= size
.x
- m_scrollbarVert
->GetPosition().x
;
697 if ( !m_scrollbarVert
|| inside
)
698 width
+= rectBorder
.width
;
700 if ( m_scrollbarHorz
)
701 height
+= size
.y
- m_scrollbarHorz
->GetPosition().y
;
702 if ( !m_scrollbarHorz
|| inside
)
703 height
+= rectBorder
.height
;
705 wxWindowNative::DoSetClientSize(width
, height
);
708 wxHitTest
wxWindow::DoHitTest(wxCoord x
, wxCoord y
) const
710 wxHitTest ht
= wxWindowNative::DoHitTest(x
, y
);
711 if ( ht
== wxHT_WINDOW_INSIDE
)
713 if ( m_scrollbarVert
&& x
>= m_scrollbarVert
->GetPosition().x
)
715 // it can still be changed below because it may also be the corner
716 ht
= wxHT_WINDOW_VERT_SCROLLBAR
;
719 if ( m_scrollbarHorz
&& y
>= m_scrollbarHorz
->GetPosition().y
)
721 ht
= ht
== wxHT_WINDOW_VERT_SCROLLBAR
? wxHT_WINDOW_CORNER
722 : wxHT_WINDOW_HORZ_SCROLLBAR
;
729 // ----------------------------------------------------------------------------
730 // scrolling: we implement it entirely ourselves except for ScrollWindow()
731 // function which is supposed to be (efficiently) implemented by the native
733 // ----------------------------------------------------------------------------
735 void wxWindow::RefreshScrollbars()
737 if ( m_scrollbarHorz
)
738 m_scrollbarHorz
->Refresh();
740 if ( m_scrollbarVert
)
741 m_scrollbarVert
->Refresh();
744 void wxWindow::PositionScrollbars()
746 // do not use GetClientSize/Rect as it relies on the scrollbars being
747 // correctly positioned
749 wxSize size
= GetSize();
750 wxBorder border
= GetBorder();
751 wxRect rectBorder
= m_renderer
->GetBorderDimensions(border
);
752 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
754 int height
= m_scrollbarHorz
? m_scrollbarHorz
->GetSize().y
: 0;
755 int width
= m_scrollbarVert
? m_scrollbarVert
->GetSize().x
: 0;
758 if ( m_scrollbarVert
)
760 rectBar
.x
= size
.x
- width
;
762 rectBar
.x
-= rectBorder
.width
;
763 rectBar
.width
= width
;
766 rectBar
.y
+= rectBorder
.y
;
767 rectBar
.height
= size
.y
- height
;
769 rectBar
.height
-= rectBorder
.y
+ rectBorder
.height
;
771 m_scrollbarVert
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
774 if ( m_scrollbarHorz
)
776 rectBar
.y
= size
.y
- height
;
778 rectBar
.y
-= rectBorder
.height
;
779 rectBar
.height
= height
;
782 rectBar
.x
+= rectBorder
.x
;
783 rectBar
.width
= size
.x
- width
;
785 rectBar
.width
-= rectBorder
.x
+ rectBorder
.width
;
787 m_scrollbarHorz
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
793 void wxWindow::SetScrollbar(int orient
,
799 wxASSERT_MSG( pageSize
<= range
,
800 _T("page size can't be greater than range") );
802 bool hasClientSizeChanged
= FALSE
;
803 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
804 if ( range
&& (pageSize
< range
) )
809 #if wxUSE_TWO_WINDOWS
810 SetInsertIntoMain( TRUE
);
812 scrollbar
= new wxScrollBar(this, -1,
813 wxDefaultPosition
, wxDefaultSize
,
814 orient
& wxVERTICAL
? wxSB_VERTICAL
816 #if wxUSE_TWO_WINDOWS
817 SetInsertIntoMain( FALSE
);
819 if ( orient
& wxVERTICAL
)
820 m_scrollbarVert
= scrollbar
;
822 m_scrollbarHorz
= scrollbar
;
824 // the client area diminished as we created a scrollbar
825 hasClientSizeChanged
= TRUE
;
827 PositionScrollbars();
829 else if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
831 // we might have disabled it before
835 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
837 else // no range means no scrollbar
841 // wxALWAYS_SHOW_SB only applies to the vertical scrollbar
842 if ( (orient
& wxVERTICAL
) && (GetWindowStyle() & wxALWAYS_SHOW_SB
) )
844 // just disable the scrollbar
845 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
846 scrollbar
->Disable();
848 else // really remove the scrollbar
852 if ( orient
& wxVERTICAL
)
853 m_scrollbarVert
= NULL
;
855 m_scrollbarHorz
= NULL
;
857 // the client area increased as we removed a scrollbar
858 hasClientSizeChanged
= TRUE
;
860 // the size of the remaining scrollbar must be adjusted
861 if ( m_scrollbarHorz
|| m_scrollbarVert
)
863 PositionScrollbars();
869 // give the window a chance to relayout
870 if ( hasClientSizeChanged
)
872 #if wxUSE_TWO_WINDOWS
873 wxWindowNative::SetSize( GetSize() );
875 wxSizeEvent
event(GetSize());
876 (void)GetEventHandler()->ProcessEvent(event
);
881 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
883 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
884 wxCHECK_RET( scrollbar
, _T("no scrollbar to set position for") );
886 scrollbar
->SetThumbPosition(pos
);
888 // VZ: I think we can safely ignore this as we always refresh it
889 // automatically whenever the value chanegs
896 int wxWindow::GetScrollPos(int orient
) const
898 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
899 return scrollbar
? scrollbar
->GetThumbPosition() : 0;
902 int wxWindow::GetScrollThumb(int orient
) const
904 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
905 return scrollbar
? scrollbar
->GetThumbSize() : 0;
908 int wxWindow::GetScrollRange(int orient
) const
910 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
911 return scrollbar
? scrollbar
->GetRange() : 0;
914 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
916 // use native scrolling when available and do it in generic way
920 wxWindowNative::ScrollWindow(dx
, dy
, rect
);
924 // before scrolling it, ensure that we don't have any unpainted areas
931 r
= ScrollNoRefresh(dx
, 0, rect
);
932 Refresh(TRUE
/* erase bkgnd */, &r
);
937 r
= ScrollNoRefresh(0, dy
, rect
);
938 Refresh(TRUE
/* erase bkgnd */, &r
);
941 // scroll children accordingly:
942 wxPoint
offset(dx
, dy
);
944 for (wxWindowList::Node
*node
= GetChildren().GetFirst();
945 node
; node
= node
->GetNext())
947 wxWindow
*child
= node
->GetData();
948 if ( child
== m_scrollbarVert
|| child
== m_scrollbarHorz
)
951 // VS: Scrolling children has non-trivial semantics. If rect=NULL then
952 // it is easy: we scroll all children. Otherwise it gets
954 // 1. if scrolling in one direction only, scroll only
955 // those children that intersect shaft defined by the rectangle
956 // and scrolling direction
957 // 2. if scrolling in both axes, scroll all children
959 if ( rect
&& (dx
* dy
== 0 /* moving in only one of x, y axis */) )
961 wxRect childRect
= child
->GetRect();
962 if ( dx
== 0 && (childRect
.GetLeft() <= rect
->GetRight() ||
963 childRect
.GetRight() >= rect
->GetLeft()) )
965 child
->Move(child
->GetPosition() + offset
);
967 else if ( dy
== 0 && (childRect
.GetTop() <= rect
->GetBottom() ||
968 childRect
.GetBottom() >= rect
->GetTop()) )
970 child
->Move(child
->GetPosition() + offset
);
975 child
->Move(child
->GetPosition() + offset
);
978 #endif // wxX11/!wxX11
981 wxRect
wxWindow::ScrollNoRefresh(int dx
, int dy
, const wxRect
*rectTotal
)
983 wxASSERT_MSG( !dx
|| !dy
, _T("can't be used for diag scrolling") );
985 // the rect to refresh (which we will calculate)
994 // calculate the part of the window which we can just redraw in the new
996 wxSize sizeTotal
= rectTotal
? rectTotal
->GetSize() : GetClientSize();
998 wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
999 sizeTotal
.x
, sizeTotal
.y
, dx
, dy
);
1001 // the initial and end point of the region we move in client coords
1002 wxPoint ptSource
, ptDest
;
1005 ptSource
= rectTotal
->GetPosition();
1006 ptDest
= rectTotal
->GetPosition();
1009 // the size of this region
1011 size
.x
= sizeTotal
.x
- abs(dx
);
1012 size
.y
= sizeTotal
.y
- abs(dy
);
1013 if ( size
.x
<= 0 || size
.y
<= 0 )
1015 // just redraw everything as nothing of the displayed image will stay
1016 wxLogTrace(_T("scroll"), _T("refreshing everything"));
1018 rect
= rectTotal
? *rectTotal
: wxRect(0, 0, sizeTotal
.x
, sizeTotal
.y
);
1020 else // move the part which doesn't change to the new location
1022 // note that when we scroll the canvas in some direction we move the
1023 // block which doesn't need to be refreshed in the opposite direction
1027 // scroll to the right, move to the left
1032 // scroll to the left, move to the right
1038 // scroll down, move up
1043 // scroll up, move down
1048 // we need to hide the caret before moving or it will erase itself at
1049 // the wrong (old) location
1050 wxCaret
*caret
= GetCaret();
1053 #endif // wxUSE_CARET
1056 wxClientDC
dc(this);
1057 wxBitmap
bmp(size
.x
, size
.y
);
1059 dcMem
.SelectObject(bmp
);
1061 dcMem
.Blit(wxPoint(0, 0), size
, &dc
, ptSource
1062 #if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
1063 + GetClientAreaOrigin()
1064 #endif // broken wxGTK wxDC::Blit
1066 dc
.Blit(ptDest
, size
, &dcMem
, wxPoint(0, 0));
1068 wxLogTrace(_T("scroll"),
1069 _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
1070 ptSource
.x
, ptSource
.y
,
1072 ptDest
.x
, ptDest
.y
);
1074 // and now repaint the uncovered area
1076 // FIXME: We repaint the intersection of these rectangles twice - is
1077 // it bad? I don't think so as it is rare to scroll the window
1078 // diagonally anyhow and so adding extra logic to compute
1079 // rectangle intersection is probably not worth the effort
1081 rect
.x
= ptSource
.x
;
1082 rect
.y
= ptSource
.y
;
1088 // refresh the area along the right border
1089 rect
.x
+= size
.x
+ dx
;
1094 // refresh the area along the left border
1098 rect
.height
= sizeTotal
.y
;
1100 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1102 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1109 // refresh the area along the bottom border
1110 rect
.y
+= size
.y
+ dy
;
1115 // refresh the area along the top border
1119 rect
.width
= sizeTotal
.x
;
1121 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1123 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1129 #endif // wxUSE_CARET
1135 // ----------------------------------------------------------------------------
1136 // accelerators and menu hot keys
1137 // ----------------------------------------------------------------------------
1140 // the last window over which Alt was pressed (used by OnKeyUp)
1141 wxWindow
*wxWindow::ms_winLastAltPress
= NULL
;
1142 #endif // wxUSE_MENUS
1144 #if wxUSE_ACCEL || wxUSE_MENUS
1146 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1149 int key
= event
.GetKeyCode();
1150 if ( !event
.ControlDown() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1152 ms_winLastAltPress
= this;
1154 // it can't be an accel anyhow
1158 ms_winLastAltPress
= NULL
;
1159 #endif // wxUSE_MENUS
1162 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
1164 int command
= win
->GetAcceleratorTable()->GetCommand(event
);
1165 if ( command
!= -1 )
1167 wxCommandEvent
eventCmd(wxEVT_COMMAND_MENU_SELECTED
, command
);
1168 if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) )
1170 // skip "event.Skip()" below
1175 if ( win
->IsTopLevel() )
1177 // try the frame menu bar
1179 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1182 wxMenuBar
*menubar
= frame
->GetMenuBar();
1183 if ( menubar
&& menubar
->ProcessAccelEvent(event
) )
1185 // skip "event.Skip()" below
1189 #endif // wxUSE_MENUS
1191 // if it wasn't in a menu, try to find a button
1192 if ( command
!= -1 )
1194 wxWindow
* child
= win
->FindWindow(command
);
1195 if ( child
&& wxDynamicCast(child
, wxButton
) )
1197 wxCommandEvent
eventCmd(wxEVT_COMMAND_BUTTON_CLICKED
, command
);
1198 eventCmd
.SetEventObject(child
);
1199 if ( child
->GetEventHandler()->ProcessEvent(eventCmd
) )
1201 // skip "event.Skip()" below
1207 // don't propagate accels from the child frame to the parent one
1211 #endif // wxUSE_ACCEL
1216 #endif // wxUSE_ACCEL
1220 wxMenuBar
*wxWindow::GetParentFrameMenuBar() const
1222 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
1224 if ( win
->IsTopLevel() )
1226 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1229 return frame
->GetMenuBar();
1232 // don't look further - we don't want to return the menubar of the
1241 void wxWindow::OnChar(wxKeyEvent
& event
)
1243 if ( event
.AltDown() && !event
.ControlDown() )
1245 int key
= event
.GetKeyCode();
1247 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1250 int item
= menubar
->FindNextItemForAccel(-1, key
);
1253 menubar
->PopupMenu((size_t)item
);
1255 // skip "event.Skip()" below
1264 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1266 int key
= event
.GetKeyCode();
1267 if ( !event
.HasModifiers() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1269 // only process Alt release specially if there were no other key
1270 // presses since Alt had been pressed and if both events happened in
1272 if ( ms_winLastAltPress
== this )
1274 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1275 if ( menubar
&& this != menubar
)
1277 menubar
->SelectMenu(0);
1286 // in any case reset it
1287 ms_winLastAltPress
= NULL
;
1290 #endif // wxUSE_MENUS
1292 // ----------------------------------------------------------------------------
1293 // MSW-specific section
1294 // ----------------------------------------------------------------------------
1298 #include "wx/msw/private.h"
1300 long wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1302 if ( message
== WM_NCHITTEST
)
1304 // the windows which contain the other windows should let the mouse
1305 // events through, otherwise a window inside a static box would
1306 // never get any events at all
1307 if ( IsStaticBox() )
1309 return HTTRANSPARENT
;
1313 return wxWindowNative::MSWWindowProc(message
, wParam
, lParam
);