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 handlers executed when the window must be repainted
184 void wxWindow::OnNcPaint(wxPaintEvent
& event
)
188 // get the window rect
190 wxSize size
= GetSize();
194 rect
.height
= size
.y
;
196 // if the scrollbars are outside the border, we must adjust the rect to
198 if ( !m_renderer
->AreScrollbarsInsideBorder() )
200 wxScrollBar
*scrollbar
= GetScrollbar(wxVERTICAL
);
202 rect
.width
-= scrollbar
->GetSize().x
;
204 scrollbar
= GetScrollbar(wxHORIZONTAL
);
206 rect
.height
-= scrollbar
->GetSize().y
;
209 // get the DC and draw the border on it
211 DoDrawBorder(dc
, rect
);
215 void wxWindow::OnPaint(wxPaintEvent
& event
)
219 // it is a native control which paints itself
224 // get the DC to use and create renderer on it
226 wxControlRenderer
renderer(this, dc
, m_renderer
);
233 // the event handler executed when the window background must be painted
234 void wxWindow::OnErase(wxEraseEvent
& event
)
243 DoDrawBackground(*event
.GetDC());
245 // if we have both scrollbars, we also have a square in the corner between
246 // them which we must paint
247 if ( m_scrollbarVert
&& m_scrollbarHorz
)
249 wxSize size
= GetSize();
250 wxRect rectClient
= GetClientRect(),
251 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
254 rectCorner
.x
= rectClient
.GetRight() + 1;
255 rectCorner
.y
= rectClient
.GetBottom() + 1;
256 rectCorner
.SetRight(size
.x
- rectBorder
.width
);
257 rectCorner
.SetBottom(size
.y
- rectBorder
.height
);
259 if ( GetUpdateRegion().Contains(rectCorner
) )
261 m_renderer
->DrawScrollCorner(*event
.GetDC(), rectCorner
);
266 bool wxWindow::DoDrawBackground(wxDC
& dc
)
270 wxSize size
= GetSize(); // Why not GetClientSize() ?
274 rect
.height
= size
.y
;
276 if (HasTransparentBackground() && GetParent() && GetParent()->ProvidesBackground())
278 wxASSERT( !IsTopLevel() );
280 wxPoint pos
= GetPosition();
282 AdjustForParentClientOrigin( pos
.x
, pos
.y
, 0 );
284 // Adjust DC logical origin
286 dc
.GetLogicalOrigin( &x
, &y
);
289 dc
.SetLogicalOrigin( x
, y
);
295 // Let parent draw the background
296 GetParent()->EraseBackground( dc
, rect
);
300 // Draw background ouselves
301 EraseBackground( dc
, rect
);
307 void wxWindow::EraseBackground(wxDC
& dc
, const wxRect
& rect
)
309 if ( GetBackgroundBitmap().Ok() )
311 // Get the bitmap and the flags
314 wxBitmap bmp
= GetBackgroundBitmap(&alignment
, &stretch
);
315 wxControlRenderer::DrawBitmap(dc
, bmp
, rect
, alignment
, stretch
);
319 // Just fill it with bg colour if no bitmap
321 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this),
322 rect
, GetStateFlags());
326 void wxWindow::DoDrawBorder(wxDC
& dc
, const wxRect
& rect
)
328 // draw outline unless the update region is enitrely inside it in which
329 // case we don't need to do it
330 #if 0 // doesn't seem to work, why?
331 if ( wxRegion(rect
).Contains(GetUpdateRegion().GetBox()) != wxInRegion
)
334 m_renderer
->DrawBorder(dc
, GetBorder(), rect
, GetStateFlags());
338 void wxWindow::DoDraw(wxControlRenderer
*renderer
)
342 void wxWindow::Refresh(bool eraseBackground
, const wxRect
*rectClient
)
345 wxPoint pt
= GetClientAreaOrigin();
347 wxSize size
= GetClientSize();
351 rectWin
= *rectClient
;
353 // don't refresh anything beyond the client area (scrollbars for
355 if ( rectWin
.GetRight() > size
.x
)
356 rectWin
.SetRight(size
.x
);
357 if ( rectWin
.GetBottom() > size
.y
)
358 rectWin
.SetBottom(size
.y
);
362 else // refresh the entire client area
366 rectWin
.width
= size
.x
;
367 rectWin
.height
= size
.y
;
371 #ifdef WXDEBUG_REFRESH
372 static bool s_refreshDebug
= FALSE
;
373 if ( s_refreshDebug
)
376 dc
.SetBrush(*wxCYAN_BRUSH
);
377 dc
.SetPen(*wxTRANSPARENT_PEN
);
378 dc
.DrawRectangle(rectWin
);
380 // under Unix we use "--sync" X option for this
381 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
386 #endif // WXDEBUG_REFRESH
388 wxWindowNative::Refresh(eraseBackground
, &rectWin
);
391 // ----------------------------------------------------------------------------
393 // ----------------------------------------------------------------------------
395 bool wxWindow::Enable(bool enable
)
397 if ( !wxWindowNative::Enable(enable
) )
400 // disabled window can't keep focus
401 if ( FindFocus() == this && GetParent() != NULL
)
403 GetParent()->SetFocus();
408 // a window with renderer is drawn by ourselves and it has to be
409 // refreshed to reflect its new status
416 bool wxWindow::IsFocused() const
418 wxWindow
*self
= wxConstCast(this, wxWindow
);
419 return self
->FindFocus() == self
;
422 bool wxWindow::IsPressed() const
427 bool wxWindow::IsDefault() const
432 bool wxWindow::IsCurrent() const
437 bool wxWindow::SetCurrent(bool doit
)
439 if ( doit
== m_isCurrent
)
444 if ( CanBeHighlighted() )
450 int wxWindow::GetStateFlags() const
454 flags
|= wxCONTROL_DISABLED
;
456 // the following states are only possible if our application is active - if
457 // it is not, even our default/focused controls shouldn't appear as such
458 if ( wxTheApp
->IsActive() )
461 flags
|= wxCONTROL_CURRENT
;
463 flags
|= wxCONTROL_FOCUSED
;
465 flags
|= wxCONTROL_PRESSED
;
467 flags
|= wxCONTROL_ISDEFAULT
;
473 // ----------------------------------------------------------------------------
475 // ----------------------------------------------------------------------------
477 void wxWindow::OnSize(wxSizeEvent
& event
)
481 if ( m_scrollbarVert
|| m_scrollbarHorz
)
483 PositionScrollbars();
486 #if 0 // ndef __WXMSW__
487 // Refresh the area (strip) previously occupied by the border
489 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE
) && IsShown())
491 // This code assumes that wxSizeEvent.GetSize() returns
492 // the area of the entire window, not just the client
494 wxSize newSize
= event
.GetSize();
496 if (m_oldSize
.x
== -1 && m_oldSize
.y
== -1)
502 if (HasFlag( wxSIMPLE_BORDER
))
504 if (newSize
.y
> m_oldSize
.y
)
508 rect
.width
= m_oldSize
.x
;
509 rect
.y
= m_oldSize
.y
-2;
511 Refresh( TRUE
, &rect
);
513 else if (newSize
.y
< m_oldSize
.y
)
519 rect
.width
= newSize
.x
;
520 wxWindowNative::Refresh( TRUE
, &rect
);
523 if (newSize
.x
> m_oldSize
.x
)
527 rect
.height
= m_oldSize
.y
;
528 rect
.x
= m_oldSize
.x
-2;
530 Refresh( TRUE
, &rect
);
532 else if (newSize
.x
< m_oldSize
.x
)
538 rect
.height
= newSize
.y
;
539 wxWindowNative::Refresh( TRUE
, &rect
);
543 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
545 if (newSize
.y
> m_oldSize
.y
)
549 rect
.width
= m_oldSize
.x
;
550 rect
.y
= m_oldSize
.y
-4;
552 Refresh( TRUE
, &rect
);
554 else if (newSize
.y
< m_oldSize
.y
)
560 rect
.width
= newSize
.x
;
561 wxWindowNative::Refresh( TRUE
, &rect
);
564 if (newSize
.x
> m_oldSize
.x
)
568 rect
.height
= m_oldSize
.y
;
569 rect
.x
= m_oldSize
.x
-4;
571 Refresh( TRUE
, &rect
);
573 else if (newSize
.x
< m_oldSize
.x
)
579 rect
.height
= newSize
.y
;
580 wxWindowNative::Refresh( TRUE
, &rect
);
589 wxSize
wxWindow::DoGetBestSize() const
591 return AdjustSize(DoGetBestClientSize());
594 wxSize
wxWindow::DoGetBestClientSize() const
596 return wxWindowNative::DoGetBestSize();
599 wxSize
wxWindow::AdjustSize(const wxSize
& size
) const
603 m_renderer
->AdjustSize(&sz
, this);
607 wxPoint
wxWindow::GetClientAreaOrigin() const
609 wxPoint pt
= wxWindowBase::GetClientAreaOrigin();
611 #if wxUSE_TWO_WINDOWS
614 pt
+= m_renderer
->GetBorderDimensions(GetBorder()).GetPosition();
620 void wxWindow::DoGetClientSize(int *width
, int *height
) const
622 // if it is a native window, we assume it handles the scrollbars itself
623 // too - and if it doesn't, there is not much we can do
626 wxWindowNative::DoGetClientSize(width
, height
);
632 wxWindowNative::DoGetClientSize(&w
, &h
);
634 // we assume that the scrollbars are positioned correctly (by a previous
635 // call to PositionScrollbars()) here
639 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
641 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
645 // in any case, take account of the scrollbar
646 if ( m_scrollbarVert
)
647 w
-= m_scrollbarVert
->GetSize().x
;
649 // if we don't have scrollbar or if it is outside the border (and not
650 // blended into it), take account of the right border as well
651 if ( !m_scrollbarVert
|| inside
)
652 w
-= rectBorder
.width
;
654 // and always account for the left border
655 *width
= w
- rectBorder
.x
;
657 // we shouldn't return invalid width
664 if ( m_scrollbarHorz
)
665 h
-= m_scrollbarHorz
->GetSize().y
;
667 if ( !m_scrollbarHorz
|| inside
)
668 h
-= rectBorder
.height
;
670 *height
= h
- rectBorder
.y
;
672 // we shouldn't return invalid height
678 void wxWindow::DoSetClientSize(int width
, int height
)
680 // take into account the borders
681 wxRect rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
682 width
+= rectBorder
.x
;
683 height
+= rectBorder
.y
;
685 // and the scrollbars (as they may be offset into the border, use the
686 // scrollbar position, not size - this supposes that PositionScrollbars()
687 // had been called before)
688 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
689 wxSize size
= GetSize();
690 if ( m_scrollbarVert
)
691 width
+= size
.x
- m_scrollbarVert
->GetPosition().x
;
692 if ( !m_scrollbarVert
|| inside
)
693 width
+= rectBorder
.width
;
695 if ( m_scrollbarHorz
)
696 height
+= size
.y
- m_scrollbarHorz
->GetPosition().y
;
697 if ( !m_scrollbarHorz
|| inside
)
698 height
+= rectBorder
.height
;
700 wxWindowNative::DoSetClientSize(width
, height
);
703 wxHitTest
wxWindow::DoHitTest(wxCoord x
, wxCoord y
) const
705 wxHitTest ht
= wxWindowNative::DoHitTest(x
, y
);
706 if ( ht
== wxHT_WINDOW_INSIDE
)
708 if ( m_scrollbarVert
&& x
>= m_scrollbarVert
->GetPosition().x
)
710 // it can still be changed below because it may also be the corner
711 ht
= wxHT_WINDOW_VERT_SCROLLBAR
;
714 if ( m_scrollbarHorz
&& y
>= m_scrollbarHorz
->GetPosition().y
)
716 ht
= ht
== wxHT_WINDOW_VERT_SCROLLBAR
? wxHT_WINDOW_CORNER
717 : wxHT_WINDOW_HORZ_SCROLLBAR
;
724 // ----------------------------------------------------------------------------
725 // scrolling: we implement it entirely ourselves except for ScrollWindow()
726 // function which is supposed to be (efficiently) implemented by the native
728 // ----------------------------------------------------------------------------
730 void wxWindow::RefreshScrollbars()
732 if ( m_scrollbarHorz
)
733 m_scrollbarHorz
->Refresh();
735 if ( m_scrollbarVert
)
736 m_scrollbarVert
->Refresh();
739 void wxWindow::PositionScrollbars()
741 // do not use GetClientSize/Rect as it relies on the scrollbars being
742 // correctly positioned
744 wxSize size
= GetSize();
745 wxBorder border
= GetBorder();
746 wxRect rectBorder
= m_renderer
->GetBorderDimensions(border
);
747 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
749 int height
= m_scrollbarHorz
? m_scrollbarHorz
->GetSize().y
: 0;
750 int width
= m_scrollbarVert
? m_scrollbarVert
->GetSize().x
: 0;
753 if ( m_scrollbarVert
)
755 rectBar
.x
= size
.x
- width
;
757 rectBar
.x
-= rectBorder
.width
;
758 rectBar
.width
= width
;
761 rectBar
.y
+= rectBorder
.y
;
762 rectBar
.height
= size
.y
- height
;
764 rectBar
.height
-= rectBorder
.y
+ rectBorder
.height
;
766 m_scrollbarVert
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
769 if ( m_scrollbarHorz
)
771 rectBar
.y
= size
.y
- height
;
773 rectBar
.y
-= rectBorder
.height
;
774 rectBar
.height
= height
;
777 rectBar
.x
+= rectBorder
.x
;
778 rectBar
.width
= size
.x
- width
;
780 rectBar
.width
-= rectBorder
.x
+ rectBorder
.width
;
782 m_scrollbarHorz
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
788 void wxWindow::SetScrollbar(int orient
,
794 wxASSERT_MSG( pageSize
<= range
,
795 _T("page size can't be greater than range") );
797 bool hasClientSizeChanged
= FALSE
;
798 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
799 if ( range
&& (pageSize
< range
) )
804 #if wxUSE_TWO_WINDOWS
805 SetInsertIntoMain( TRUE
);
807 scrollbar
= new wxScrollBar(this, -1,
808 wxDefaultPosition
, wxDefaultSize
,
809 orient
& wxVERTICAL
? wxSB_VERTICAL
811 #if wxUSE_TWO_WINDOWS
812 SetInsertIntoMain( FALSE
);
814 if ( orient
& wxVERTICAL
)
815 m_scrollbarVert
= scrollbar
;
817 m_scrollbarHorz
= scrollbar
;
819 // the client area diminished as we created a scrollbar
820 hasClientSizeChanged
= TRUE
;
822 PositionScrollbars();
824 else if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
826 // we might have disabled it before
830 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
832 else // no range means no scrollbar
836 // wxALWAYS_SHOW_SB only applies to the vertical scrollbar
837 if ( (orient
& wxVERTICAL
) && (GetWindowStyle() & wxALWAYS_SHOW_SB
) )
839 // just disable the scrollbar
840 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
841 scrollbar
->Disable();
843 else // really remove the scrollbar
847 if ( orient
& wxVERTICAL
)
848 m_scrollbarVert
= NULL
;
850 m_scrollbarHorz
= NULL
;
852 // the client area increased as we removed a scrollbar
853 hasClientSizeChanged
= TRUE
;
855 // the size of the remaining scrollbar must be adjusted
856 if ( m_scrollbarHorz
|| m_scrollbarVert
)
858 PositionScrollbars();
864 // give the window a chance to relayout
865 if ( hasClientSizeChanged
)
867 #if wxUSE_TWO_WINDOWS
868 wxWindowNative::SetSize( GetSize() );
870 wxSizeEvent
event(GetSize());
871 (void)GetEventHandler()->ProcessEvent(event
);
876 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
878 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
879 wxCHECK_RET( scrollbar
, _T("no scrollbar to set position for") );
881 scrollbar
->SetThumbPosition(pos
);
883 // VZ: I think we can safely ignore this as we always refresh it
884 // automatically whenever the value chanegs
891 int wxWindow::GetScrollPos(int orient
) const
893 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
894 return scrollbar
? scrollbar
->GetThumbPosition() : 0;
897 int wxWindow::GetScrollThumb(int orient
) const
899 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
900 return scrollbar
? scrollbar
->GetThumbSize() : 0;
903 int wxWindow::GetScrollRange(int orient
) const
905 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
906 return scrollbar
? scrollbar
->GetRange() : 0;
909 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
911 // use native scrolling when available and do it in generic way
915 wxWindowNative::ScrollWindow(dx
, dy
, rect
);
919 // before scrolling it, ensure that we don't have any unpainted areas
926 r
= ScrollNoRefresh(dx
, 0, rect
);
927 Refresh(TRUE
/* erase bkgnd */, &r
);
932 r
= ScrollNoRefresh(0, dy
, rect
);
933 Refresh(TRUE
/* erase bkgnd */, &r
);
936 // scroll children accordingly:
937 wxPoint
offset(dx
, dy
);
939 for (wxWindowList::Node
*node
= GetChildren().GetFirst();
940 node
; node
= node
->GetNext())
942 wxWindow
*child
= node
->GetData();
943 if ( child
== m_scrollbarVert
|| child
== m_scrollbarHorz
)
946 // VS: Scrolling children has non-trivial semantics. If rect=NULL then
947 // it is easy: we scroll all children. Otherwise it gets
949 // 1. if scrolling in one direction only, scroll only
950 // those children that intersect shaft defined by the rectangle
951 // and scrolling direction
952 // 2. if scrolling in both axes, scroll all children
954 if ( rect
&& (dx
* dy
== 0 /* moving in only one of x, y axis */) )
956 wxRect childRect
= child
->GetRect();
957 if ( dx
== 0 && (childRect
.GetLeft() <= rect
->GetRight() ||
958 childRect
.GetRight() >= rect
->GetLeft()) )
960 child
->Move(child
->GetPosition() + offset
);
962 else if ( dy
== 0 && (childRect
.GetTop() <= rect
->GetBottom() ||
963 childRect
.GetBottom() >= rect
->GetTop()) )
965 child
->Move(child
->GetPosition() + offset
);
970 child
->Move(child
->GetPosition() + offset
);
976 wxRect
wxWindow::ScrollNoRefresh(int dx
, int dy
, const wxRect
*rectTotal
)
978 wxASSERT_MSG( !dx
|| !dy
, _T("can't be used for diag scrolling") );
980 // the rect to refresh (which we will calculate)
989 // calculate the part of the window which we can just redraw in the new
991 wxSize sizeTotal
= rectTotal
? rectTotal
->GetSize() : GetClientSize();
993 wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
994 sizeTotal
.x
, sizeTotal
.y
, dx
, dy
);
996 // the initial and end point of the region we move in client coords
997 wxPoint ptSource
, ptDest
;
1000 ptSource
= rectTotal
->GetPosition();
1001 ptDest
= rectTotal
->GetPosition();
1004 // the size of this region
1006 size
.x
= sizeTotal
.x
- abs(dx
);
1007 size
.y
= sizeTotal
.y
- abs(dy
);
1008 if ( size
.x
<= 0 || size
.y
<= 0 )
1010 // just redraw everything as nothing of the displayed image will stay
1011 wxLogTrace(_T("scroll"), _T("refreshing everything"));
1013 rect
= rectTotal
? *rectTotal
: wxRect(0, 0, sizeTotal
.x
, sizeTotal
.y
);
1015 else // move the part which doesn't change to the new location
1017 // note that when we scroll the canvas in some direction we move the
1018 // block which doesn't need to be refreshed in the opposite direction
1022 // scroll to the right, move to the left
1027 // scroll to the left, move to the right
1033 // scroll down, move up
1038 // scroll up, move down
1043 // we need to hide the caret before moving or it will erase itself at
1044 // the wrong (old) location
1045 wxCaret
*caret
= GetCaret();
1048 #endif // wxUSE_CARET
1051 wxClientDC
dc(this);
1052 wxBitmap
bmp(size
.x
, size
.y
);
1054 dcMem
.SelectObject(bmp
);
1056 dcMem
.Blit(wxPoint(0, 0), size
, &dc
, ptSource
1057 #if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
1058 + GetClientAreaOrigin()
1059 #endif // broken wxGTK wxDC::Blit
1061 dc
.Blit(ptDest
, size
, &dcMem
, wxPoint(0, 0));
1063 wxLogTrace(_T("scroll"),
1064 _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
1065 ptSource
.x
, ptSource
.y
,
1067 ptDest
.x
, ptDest
.y
);
1069 // and now repaint the uncovered area
1071 // FIXME: We repaint the intersection of these rectangles twice - is
1072 // it bad? I don't think so as it is rare to scroll the window
1073 // diagonally anyhow and so adding extra logic to compute
1074 // rectangle intersection is probably not worth the effort
1076 rect
.x
= ptSource
.x
;
1077 rect
.y
= ptSource
.y
;
1083 // refresh the area along the right border
1084 rect
.x
+= size
.x
+ dx
;
1089 // refresh the area along the left border
1093 rect
.height
= sizeTotal
.y
;
1095 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1097 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1104 // refresh the area along the bottom border
1105 rect
.y
+= size
.y
+ dy
;
1110 // refresh the area along the top border
1114 rect
.width
= sizeTotal
.x
;
1116 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1118 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1124 #endif // wxUSE_CARET
1130 // ----------------------------------------------------------------------------
1131 // accelerators and menu hot keys
1132 // ----------------------------------------------------------------------------
1135 // the last window over which Alt was pressed (used by OnKeyUp)
1136 wxWindow
*wxWindow::ms_winLastAltPress
= NULL
;
1137 #endif // wxUSE_MENUS
1139 #if wxUSE_ACCEL || wxUSE_MENUS
1141 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1144 int key
= event
.GetKeyCode();
1145 if ( !event
.ControlDown() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1147 ms_winLastAltPress
= this;
1149 // it can't be an accel anyhow
1153 ms_winLastAltPress
= NULL
;
1154 #endif // wxUSE_MENUS
1157 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
1159 int command
= win
->GetAcceleratorTable()->GetCommand(event
);
1160 if ( command
!= -1 )
1162 wxCommandEvent
eventCmd(wxEVT_COMMAND_MENU_SELECTED
, command
);
1163 if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) )
1165 // skip "event.Skip()" below
1170 if ( win
->IsTopLevel() )
1172 // try the frame menu bar
1174 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1177 wxMenuBar
*menubar
= frame
->GetMenuBar();
1178 if ( menubar
&& menubar
->ProcessAccelEvent(event
) )
1180 // skip "event.Skip()" below
1184 #endif // wxUSE_MENUS
1186 // if it wasn't in a menu, try to find a button
1187 if ( command
!= -1 )
1189 wxWindow
* child
= win
->FindWindow(command
);
1190 if ( child
&& wxDynamicCast(child
, wxButton
) )
1192 wxCommandEvent
eventCmd(wxEVT_COMMAND_BUTTON_CLICKED
, command
);
1193 eventCmd
.SetEventObject(child
);
1194 if ( child
->GetEventHandler()->ProcessEvent(eventCmd
) )
1196 // skip "event.Skip()" below
1202 // don't propagate accels from the child frame to the parent one
1206 #endif // wxUSE_ACCEL
1211 #endif // wxUSE_ACCEL
1215 wxMenuBar
*wxWindow::GetParentFrameMenuBar() const
1217 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
1219 if ( win
->IsTopLevel() )
1221 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1224 return frame
->GetMenuBar();
1227 // don't look further - we don't want to return the menubar of the
1236 void wxWindow::OnChar(wxKeyEvent
& event
)
1238 if ( event
.AltDown() && !event
.ControlDown() )
1240 int key
= event
.GetKeyCode();
1242 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1245 int item
= menubar
->FindNextItemForAccel(-1, key
);
1248 menubar
->PopupMenu((size_t)item
);
1250 // skip "event.Skip()" below
1259 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1261 int key
= event
.GetKeyCode();
1262 if ( !event
.HasModifiers() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1264 // only process Alt release specially if there were no other key
1265 // presses since Alt had been pressed and if both events happened in
1267 if ( ms_winLastAltPress
== this )
1269 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1270 if ( menubar
&& this != menubar
)
1272 menubar
->SelectMenu(0);
1281 // in any case reset it
1282 ms_winLastAltPress
= NULL
;
1285 #endif // wxUSE_MENUS
1287 // ----------------------------------------------------------------------------
1288 // MSW-specific section
1289 // ----------------------------------------------------------------------------
1293 #include "wx/msw/private.h"
1295 long wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1297 if ( message
== WM_NCHITTEST
)
1299 // the windows which contain the other windows should let the mouse
1300 // events through, otherwise a window inside a static box would
1301 // never get any events at all
1302 if ( IsStaticBox() )
1304 return HTTRANSPARENT
;
1308 return wxWindowNative::MSWWindowProc(message
, wParam
, lParam
);