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();
115 m_hasDialogBackground
= FALSE
;
118 bool wxWindow::Create(wxWindow
*parent
,
123 const wxString
& name
)
125 // we add wxCLIP_CHILDREN to get the same ("natural") behaviour under MSW
126 // as under the other platforms
127 if ( !wxWindowNative::Create(parent
, id
, pos
, size
,
128 style
| wxCLIP_CHILDREN
,
134 // if we should always have the scrollbar, do show it
135 if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
137 #if wxUSE_TWO_WINDOWS
138 SetInsertIntoMain( TRUE
);
140 m_scrollbarVert
= new wxScrollBar(this, -1,
141 wxDefaultPosition
, wxDefaultSize
,
143 #if wxUSE_TWO_WINDOWS
144 SetInsertIntoMain( FALSE
);
148 PositionScrollbars();
154 // ----------------------------------------------------------------------------
156 // ----------------------------------------------------------------------------
158 void wxWindow::SetBackground(const wxBitmap
& bitmap
,
163 m_alignBgBitmap
= alignment
;
164 m_stretchBgBitmap
= stretch
;
167 const wxBitmap
& wxWindow::GetBackgroundBitmap(int *alignment
,
168 wxStretch
*stretch
) const
170 if ( m_bitmapBg
.Ok() )
173 *alignment
= m_alignBgBitmap
;
175 *stretch
= m_stretchBgBitmap
;
181 // ----------------------------------------------------------------------------
183 // ----------------------------------------------------------------------------
185 // the event handler executed when the window background must be painted
186 void wxWindow::OnErase(wxEraseEvent
& event
)
195 DoDrawBackground(*event
.GetDC());
197 // if we have both scrollbars, we also have a square in the corner between
198 // them which we must paint
199 if ( m_scrollbarVert
&& m_scrollbarHorz
)
201 wxSize size
= GetSize();
202 wxRect rectClient
= GetClientRect(),
203 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
206 rectCorner
.x
= rectClient
.GetRight() + 1;
207 rectCorner
.y
= rectClient
.GetBottom() + 1;
208 rectCorner
.SetRight(size
.x
- rectBorder
.width
);
209 rectCorner
.SetBottom(size
.y
- rectBorder
.height
);
211 if ( GetUpdateRegion().Contains(rectCorner
) )
213 m_renderer
->DrawScrollCorner(*event
.GetDC(), rectCorner
);
218 // the event handlers executed when the window must be repainted
219 void wxWindow::OnNcPaint(wxPaintEvent
& event
)
223 // get the window rect
225 wxSize size
= GetSize();
229 rect
.height
= size
.y
;
231 // if the scrollbars are outside the border, we must adjust the rect to
233 if ( !m_renderer
->AreScrollbarsInsideBorder() )
235 wxScrollBar
*scrollbar
= GetScrollbar(wxVERTICAL
);
237 rect
.width
-= scrollbar
->GetSize().x
;
239 scrollbar
= GetScrollbar(wxHORIZONTAL
);
241 rect
.height
-= scrollbar
->GetSize().y
;
244 // get the DC and draw the border on it
246 DoDrawBorder(dc
, rect
);
250 void wxWindow::OnPaint(wxPaintEvent
& event
)
254 // it is a native control which paints itself
259 // get the DC to use and create renderer on it
261 wxControlRenderer
renderer(this, dc
, m_renderer
);
268 bool wxWindow::DoDrawBackground(wxDC
& dc
)
270 // FIXME: Leaving this code in leads to partial bg redraws
271 // sometimes under MSW.
272 // The same happens under X11 because it has a clear
273 // region and an update region and these are sometimes
278 rect
= GetUpdateRegion().GetBox();
279 if ( !rect
.width
&& !rect
.height
)
282 wxSize size
= GetSize();
284 rect
.height
= size
.y
;
287 if ( GetBackgroundBitmap().Ok() )
289 // get the bitmap and the flags
292 wxBitmap bmp
= GetBackgroundBitmap(&alignment
, &stretch
);
293 wxControlRenderer::DrawBitmap(dc
, bmp
, rect
, alignment
, stretch
);
295 else // just fill it with bg colour if no bitmap
297 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this),
298 rect
, GetStateFlags());
304 void wxWindow::EraseBackground(wxDC
& dc
, const wxRect
& rect
)
306 // TODO: handle bg bitmaps here!
308 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this), rect
, GetStateFlags());
311 void wxWindow::DoDrawBorder(wxDC
& dc
, const wxRect
& rect
)
313 // draw outline unless the update region is enitrely inside it in which
314 // case we don't need to do it
315 #if 0 // doesn't seem to work, why?
316 if ( wxRegion(rect
).Contains(GetUpdateRegion().GetBox()) != wxInRegion
)
319 m_renderer
->DrawBorder(dc
, GetBorder(), rect
, GetStateFlags());
323 void wxWindow::DoDraw(wxControlRenderer
*renderer
)
327 void wxWindow::Refresh(bool eraseBackground
, const wxRect
*rectClient
)
330 wxPoint pt
= GetClientAreaOrigin();
332 wxSize size
= GetClientSize();
336 rectWin
= *rectClient
;
338 // don't refresh anything beyond the client area (scrollbars for
340 if ( rectWin
.GetRight() > size
.x
)
341 rectWin
.SetRight(size
.x
);
342 if ( rectWin
.GetBottom() > size
.y
)
343 rectWin
.SetBottom(size
.y
);
347 else // refresh the entire client area
351 rectWin
.width
= size
.x
;
352 rectWin
.height
= size
.y
;
356 #ifdef WXDEBUG_REFRESH
357 static bool s_refreshDebug
= FALSE
;
358 if ( s_refreshDebug
)
361 dc
.SetBrush(*wxCYAN_BRUSH
);
362 dc
.SetPen(*wxTRANSPARENT_PEN
);
363 dc
.DrawRectangle(rectWin
);
365 // under Unix we use "--sync" X option for this
366 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
371 #endif // WXDEBUG_REFRESH
373 wxWindowNative::Refresh(eraseBackground
, &rectWin
);
376 // ----------------------------------------------------------------------------
378 // ----------------------------------------------------------------------------
380 bool wxWindow::Enable(bool enable
)
382 if ( !wxWindowNative::Enable(enable
) )
385 // disabled window can't keep focus
386 if ( FindFocus() == this && GetParent() != NULL
)
388 GetParent()->SetFocus();
393 // a window with renderer is drawn by ourselves and it has to be
394 // refreshed to reflect its new status
401 bool wxWindow::IsFocused() const
403 wxWindow
*self
= wxConstCast(this, wxWindow
);
404 return self
->FindFocus() == self
;
407 bool wxWindow::IsPressed() const
412 bool wxWindow::IsDefault() const
417 bool wxWindow::IsCurrent() const
422 bool wxWindow::SetCurrent(bool doit
)
424 if ( doit
== m_isCurrent
)
429 if ( CanBeHighlighted() )
435 int wxWindow::GetStateFlags() const
439 flags
|= wxCONTROL_DISABLED
;
441 // the following states are only possible if our application is active - if
442 // it is not, even our default/focused controls shouldn't appear as such
443 if ( wxTheApp
->IsActive() )
446 flags
|= wxCONTROL_CURRENT
;
448 flags
|= wxCONTROL_FOCUSED
;
450 flags
|= wxCONTROL_PRESSED
;
452 flags
|= wxCONTROL_ISDEFAULT
;
458 // ----------------------------------------------------------------------------
460 // ----------------------------------------------------------------------------
462 void wxWindow::OnSize(wxSizeEvent
& event
)
466 if ( m_scrollbarVert
|| m_scrollbarHorz
)
468 PositionScrollbars();
471 #if 0 // ndef __WXMSW__
472 // Refresh the area (strip) previously occupied by the border
474 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE
) && IsShown())
476 // This code assumes that wxSizeEvent.GetSize() returns
477 // the area of the entire window, not just the client
479 wxSize newSize
= event
.GetSize();
481 if (m_oldSize
.x
== -1 && m_oldSize
.y
== -1)
487 if (HasFlag( wxSIMPLE_BORDER
))
489 if (newSize
.y
> m_oldSize
.y
)
493 rect
.width
= m_oldSize
.x
;
494 rect
.y
= m_oldSize
.y
-2;
496 Refresh( TRUE
, &rect
);
498 else if (newSize
.y
< m_oldSize
.y
)
504 rect
.width
= newSize
.x
;
505 wxWindowNative::Refresh( TRUE
, &rect
);
508 if (newSize
.x
> m_oldSize
.x
)
512 rect
.height
= m_oldSize
.y
;
513 rect
.x
= m_oldSize
.x
-2;
515 Refresh( TRUE
, &rect
);
517 else if (newSize
.x
< m_oldSize
.x
)
523 rect
.height
= newSize
.y
;
524 wxWindowNative::Refresh( TRUE
, &rect
);
528 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
530 if (newSize
.y
> m_oldSize
.y
)
534 rect
.width
= m_oldSize
.x
;
535 rect
.y
= m_oldSize
.y
-4;
537 Refresh( TRUE
, &rect
);
539 else if (newSize
.y
< m_oldSize
.y
)
545 rect
.width
= newSize
.x
;
546 wxWindowNative::Refresh( TRUE
, &rect
);
549 if (newSize
.x
> m_oldSize
.x
)
553 rect
.height
= m_oldSize
.y
;
554 rect
.x
= m_oldSize
.x
-4;
556 Refresh( TRUE
, &rect
);
558 else if (newSize
.x
< m_oldSize
.x
)
564 rect
.height
= newSize
.y
;
565 wxWindowNative::Refresh( TRUE
, &rect
);
574 wxSize
wxWindow::DoGetBestSize() const
576 return AdjustSize(DoGetBestClientSize());
579 wxSize
wxWindow::DoGetBestClientSize() const
581 return wxWindowNative::DoGetBestSize();
584 wxSize
wxWindow::AdjustSize(const wxSize
& size
) const
588 m_renderer
->AdjustSize(&sz
, this);
592 wxPoint
wxWindow::GetClientAreaOrigin() const
594 wxPoint pt
= wxWindowBase::GetClientAreaOrigin();
596 #if wxUSE_TWO_WINDOWS
599 pt
+= m_renderer
->GetBorderDimensions(GetBorder()).GetPosition();
605 void wxWindow::DoGetClientSize(int *width
, int *height
) const
607 // if it is a native window, we assume it handles the scrollbars itself
608 // too - and if it doesn't, there is not much we can do
611 wxWindowNative::DoGetClientSize(width
, height
);
617 wxWindowNative::DoGetClientSize(&w
, &h
);
619 // we assume that the scrollbars are positioned correctly (by a previous
620 // call to PositionScrollbars()) here
624 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
626 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
630 // in any case, take account of the scrollbar
631 if ( m_scrollbarVert
)
632 w
-= m_scrollbarVert
->GetSize().x
;
634 // if we don't have scrollbar or if it is outside the border (and not
635 // blended into it), take account of the right border as well
636 if ( !m_scrollbarVert
|| inside
)
637 w
-= rectBorder
.width
;
639 // and always account for the left border
640 *width
= w
- rectBorder
.x
;
642 // we shouldn't return invalid width
649 if ( m_scrollbarHorz
)
650 h
-= m_scrollbarHorz
->GetSize().y
;
652 if ( !m_scrollbarHorz
|| inside
)
653 h
-= rectBorder
.height
;
655 *height
= h
- rectBorder
.y
;
657 // we shouldn't return invalid height
663 void wxWindow::DoSetClientSize(int width
, int height
)
665 // take into account the borders
666 wxRect rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
667 width
+= rectBorder
.x
;
668 height
+= rectBorder
.y
;
670 // and the scrollbars (as they may be offset into the border, use the
671 // scrollbar position, not size - this supposes that PositionScrollbars()
672 // had been called before)
673 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
674 wxSize size
= GetSize();
675 if ( m_scrollbarVert
)
676 width
+= size
.x
- m_scrollbarVert
->GetPosition().x
;
677 if ( !m_scrollbarVert
|| inside
)
678 width
+= rectBorder
.width
;
680 if ( m_scrollbarHorz
)
681 height
+= size
.y
- m_scrollbarHorz
->GetPosition().y
;
682 if ( !m_scrollbarHorz
|| inside
)
683 height
+= rectBorder
.height
;
685 wxWindowNative::DoSetClientSize(width
, height
);
688 wxHitTest
wxWindow::DoHitTest(wxCoord x
, wxCoord y
) const
690 wxHitTest ht
= wxWindowNative::DoHitTest(x
, y
);
691 if ( ht
== wxHT_WINDOW_INSIDE
)
693 if ( m_scrollbarVert
&& x
>= m_scrollbarVert
->GetPosition().x
)
695 // it can still be changed below because it may also be the corner
696 ht
= wxHT_WINDOW_VERT_SCROLLBAR
;
699 if ( m_scrollbarHorz
&& y
>= m_scrollbarHorz
->GetPosition().y
)
701 ht
= ht
== wxHT_WINDOW_VERT_SCROLLBAR
? wxHT_WINDOW_CORNER
702 : wxHT_WINDOW_HORZ_SCROLLBAR
;
709 // ----------------------------------------------------------------------------
710 // scrolling: we implement it entirely ourselves except for ScrollWindow()
711 // function which is supposed to be (efficiently) implemented by the native
713 // ----------------------------------------------------------------------------
715 void wxWindow::RefreshScrollbars()
717 if ( m_scrollbarHorz
)
718 m_scrollbarHorz
->Refresh();
720 if ( m_scrollbarVert
)
721 m_scrollbarVert
->Refresh();
724 void wxWindow::PositionScrollbars()
726 // do not use GetClientSize/Rect as it relies on the scrollbars being
727 // correctly positioned
729 wxSize size
= GetSize();
730 wxBorder border
= GetBorder();
731 wxRect rectBorder
= m_renderer
->GetBorderDimensions(border
);
732 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
734 int height
= m_scrollbarHorz
? m_scrollbarHorz
->GetSize().y
: 0;
735 int width
= m_scrollbarVert
? m_scrollbarVert
->GetSize().x
: 0;
738 if ( m_scrollbarVert
)
740 rectBar
.x
= size
.x
- width
;
742 rectBar
.x
-= rectBorder
.width
;
743 rectBar
.width
= width
;
746 rectBar
.y
+= rectBorder
.y
;
747 rectBar
.height
= size
.y
- height
;
749 rectBar
.height
-= rectBorder
.y
+ rectBorder
.height
;
751 m_scrollbarVert
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
754 if ( m_scrollbarHorz
)
756 rectBar
.y
= size
.y
- height
;
758 rectBar
.y
-= rectBorder
.height
;
759 rectBar
.height
= height
;
762 rectBar
.x
+= rectBorder
.x
;
763 rectBar
.width
= size
.x
- width
;
765 rectBar
.width
-= rectBorder
.x
+ rectBorder
.width
;
767 m_scrollbarHorz
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
773 void wxWindow::SetScrollbar(int orient
,
779 wxASSERT_MSG( pageSize
<= range
,
780 _T("page size can't be greater than range") );
782 bool hasClientSizeChanged
= FALSE
;
783 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
784 if ( range
&& (pageSize
< range
) )
789 #if wxUSE_TWO_WINDOWS
790 SetInsertIntoMain( TRUE
);
792 scrollbar
= new wxScrollBar(this, -1,
793 wxDefaultPosition
, wxDefaultSize
,
794 orient
& wxVERTICAL
? wxSB_VERTICAL
796 #if wxUSE_TWO_WINDOWS
797 SetInsertIntoMain( FALSE
);
799 if ( orient
& wxVERTICAL
)
800 m_scrollbarVert
= scrollbar
;
802 m_scrollbarHorz
= scrollbar
;
804 // the client area diminished as we created a scrollbar
805 hasClientSizeChanged
= TRUE
;
807 PositionScrollbars();
809 else if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
811 // we might have disabled it before
815 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
817 else // no range means no scrollbar
821 // wxALWAYS_SHOW_SB only applies to the vertical scrollbar
822 if ( (orient
& wxVERTICAL
) && (GetWindowStyle() & wxALWAYS_SHOW_SB
) )
824 // just disable the scrollbar
825 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
826 scrollbar
->Disable();
828 else // really remove the scrollbar
832 if ( orient
& wxVERTICAL
)
833 m_scrollbarVert
= NULL
;
835 m_scrollbarHorz
= NULL
;
837 // the client area increased as we removed a scrollbar
838 hasClientSizeChanged
= TRUE
;
840 // the size of the remaining scrollbar must be adjusted
841 if ( m_scrollbarHorz
|| m_scrollbarVert
)
843 PositionScrollbars();
849 // give the window a chance to relayout
850 if ( hasClientSizeChanged
)
852 #if wxUSE_TWO_WINDOWS
853 wxWindowNative::SetSize( GetSize() );
855 wxSizeEvent
event(GetSize());
856 (void)GetEventHandler()->ProcessEvent(event
);
861 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
863 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
864 wxCHECK_RET( scrollbar
, _T("no scrollbar to set position for") );
866 scrollbar
->SetThumbPosition(pos
);
868 // VZ: I think we can safely ignore this as we always refresh it
869 // automatically whenever the value chanegs
876 int wxWindow::GetScrollPos(int orient
) const
878 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
879 return scrollbar
? scrollbar
->GetThumbPosition() : 0;
882 int wxWindow::GetScrollThumb(int orient
) const
884 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
885 return scrollbar
? scrollbar
->GetThumbSize() : 0;
888 int wxWindow::GetScrollRange(int orient
) const
890 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
891 return scrollbar
? scrollbar
->GetRange() : 0;
894 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
896 // use native scrolling when available and do it in generic way
900 wxWindowNative::ScrollWindow(dx
, dy
, rect
);
904 // before scrolling it, ensure that we don't have any unpainted areas
911 r
= ScrollNoRefresh(dx
, 0, rect
);
912 Refresh(TRUE
/* erase bkgnd */, &r
);
917 r
= ScrollNoRefresh(0, dy
, rect
);
918 Refresh(TRUE
/* erase bkgnd */, &r
);
921 // scroll children accordingly:
922 wxPoint
offset(dx
, dy
);
924 for (wxWindowList::Node
*node
= GetChildren().GetFirst();
925 node
; node
= node
->GetNext())
927 wxWindow
*child
= node
->GetData();
928 if ( child
== m_scrollbarVert
|| child
== m_scrollbarHorz
)
931 // VS: Scrolling children has non-trivial semantics. If rect=NULL then
932 // it is easy: we scroll all children. Otherwise it gets
934 // 1. if scrolling in one direction only, scroll only
935 // those children that intersect shaft defined by the rectangle
936 // and scrolling direction
937 // 2. if scrolling in both axes, scroll all children
939 if ( rect
&& (dx
* dy
== 0 /* moving in only one of x, y axis */) )
941 wxRect childRect
= child
->GetRect();
942 if ( dx
== 0 && (childRect
.GetLeft() <= rect
->GetRight() ||
943 childRect
.GetRight() >= rect
->GetLeft()) )
945 child
->Move(child
->GetPosition() + offset
);
947 else if ( dy
== 0 && (childRect
.GetTop() <= rect
->GetBottom() ||
948 childRect
.GetBottom() >= rect
->GetTop()) )
950 child
->Move(child
->GetPosition() + offset
);
955 child
->Move(child
->GetPosition() + offset
);
961 wxRect
wxWindow::ScrollNoRefresh(int dx
, int dy
, const wxRect
*rectTotal
)
963 wxASSERT_MSG( !dx
|| !dy
, _T("can't be used for diag scrolling") );
965 // the rect to refresh (which we will calculate)
974 // calculate the part of the window which we can just redraw in the new
976 wxSize sizeTotal
= rectTotal
? rectTotal
->GetSize() : GetClientSize();
978 wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
979 sizeTotal
.x
, sizeTotal
.y
, dx
, dy
);
981 // the initial and end point of the region we move in client coords
982 wxPoint ptSource
, ptDest
;
985 ptSource
= rectTotal
->GetPosition();
986 ptDest
= rectTotal
->GetPosition();
989 // the size of this region
991 size
.x
= sizeTotal
.x
- abs(dx
);
992 size
.y
= sizeTotal
.y
- abs(dy
);
993 if ( size
.x
<= 0 || size
.y
<= 0 )
995 // just redraw everything as nothing of the displayed image will stay
996 wxLogTrace(_T("scroll"), _T("refreshing everything"));
998 rect
= rectTotal
? *rectTotal
: wxRect(0, 0, sizeTotal
.x
, sizeTotal
.y
);
1000 else // move the part which doesn't change to the new location
1002 // note that when we scroll the canvas in some direction we move the
1003 // block which doesn't need to be refreshed in the opposite direction
1007 // scroll to the right, move to the left
1012 // scroll to the left, move to the right
1018 // scroll down, move up
1023 // scroll up, move down
1028 // we need to hide the caret before moving or it will erase itself at
1029 // the wrong (old) location
1030 wxCaret
*caret
= GetCaret();
1033 #endif // wxUSE_CARET
1036 wxClientDC
dc(this);
1037 wxBitmap
bmp(size
.x
, size
.y
);
1039 dcMem
.SelectObject(bmp
);
1041 dcMem
.Blit(wxPoint(0, 0), size
, &dc
, ptSource
1042 #if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
1043 + GetClientAreaOrigin()
1044 #endif // broken wxGTK wxDC::Blit
1046 dc
.Blit(ptDest
, size
, &dcMem
, wxPoint(0, 0));
1048 wxLogTrace(_T("scroll"),
1049 _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
1050 ptSource
.x
, ptSource
.y
,
1052 ptDest
.x
, ptDest
.y
);
1054 // and now repaint the uncovered area
1056 // FIXME: We repaint the intersection of these rectangles twice - is
1057 // it bad? I don't think so as it is rare to scroll the window
1058 // diagonally anyhow and so adding extra logic to compute
1059 // rectangle intersection is probably not worth the effort
1061 rect
.x
= ptSource
.x
;
1062 rect
.y
= ptSource
.y
;
1068 // refresh the area along the right border
1069 rect
.x
+= size
.x
+ dx
;
1074 // refresh the area along the left border
1078 rect
.height
= sizeTotal
.y
;
1080 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1082 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1089 // refresh the area along the bottom border
1090 rect
.y
+= size
.y
+ dy
;
1095 // refresh the area along the top border
1099 rect
.width
= sizeTotal
.x
;
1101 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1103 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1109 #endif // wxUSE_CARET
1115 // ----------------------------------------------------------------------------
1116 // accelerators and menu hot keys
1117 // ----------------------------------------------------------------------------
1120 // the last window over which Alt was pressed (used by OnKeyUp)
1121 wxWindow
*wxWindow::ms_winLastAltPress
= NULL
;
1122 #endif // wxUSE_MENUS
1124 #if wxUSE_ACCEL || wxUSE_MENUS
1126 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1129 int key
= event
.GetKeyCode();
1130 if ( !event
.ControlDown() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1132 ms_winLastAltPress
= this;
1134 // it can't be an accel anyhow
1138 ms_winLastAltPress
= NULL
;
1139 #endif // wxUSE_MENUS
1142 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
1144 int command
= win
->GetAcceleratorTable()->GetCommand(event
);
1145 if ( command
!= -1 )
1147 wxCommandEvent
eventCmd(wxEVT_COMMAND_MENU_SELECTED
, command
);
1148 if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) )
1150 // skip "event.Skip()" below
1155 if ( win
->IsTopLevel() )
1157 // try the frame menu bar
1159 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1162 wxMenuBar
*menubar
= frame
->GetMenuBar();
1163 if ( menubar
&& menubar
->ProcessAccelEvent(event
) )
1165 // skip "event.Skip()" below
1169 #endif // wxUSE_MENUS
1171 // if it wasn't in a menu, try to find a button
1172 if ( command
!= -1 )
1174 wxWindow
* child
= win
->FindWindow(command
);
1175 if ( child
&& wxDynamicCast(child
, wxButton
) )
1177 wxCommandEvent
eventCmd(wxEVT_COMMAND_BUTTON_CLICKED
, command
);
1178 eventCmd
.SetEventObject(child
);
1179 if ( child
->GetEventHandler()->ProcessEvent(eventCmd
) )
1181 // skip "event.Skip()" below
1187 // don't propagate accels from the child frame to the parent one
1191 #endif // wxUSE_ACCEL
1196 #endif // wxUSE_ACCEL
1200 wxMenuBar
*wxWindow::GetParentFrameMenuBar() const
1202 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
1204 if ( win
->IsTopLevel() )
1206 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1209 return frame
->GetMenuBar();
1212 // don't look further - we don't want to return the menubar of the
1221 void wxWindow::OnChar(wxKeyEvent
& event
)
1223 if ( event
.AltDown() && !event
.ControlDown() )
1225 int key
= event
.GetKeyCode();
1227 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1230 int item
= menubar
->FindNextItemForAccel(-1, key
);
1233 menubar
->PopupMenu((size_t)item
);
1235 // skip "event.Skip()" below
1244 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1246 int key
= event
.GetKeyCode();
1247 if ( !event
.HasModifiers() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1249 // only process Alt release specially if there were no other key
1250 // presses since Alt had been pressed and if both events happened in
1252 if ( ms_winLastAltPress
== this )
1254 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1255 if ( menubar
&& this != menubar
)
1257 menubar
->SelectMenu(0);
1266 // in any case reset it
1267 ms_winLastAltPress
= NULL
;
1270 #endif // wxUSE_MENUS
1272 // ----------------------------------------------------------------------------
1273 // MSW-specific section
1274 // ----------------------------------------------------------------------------
1278 #include "wx/msw/private.h"
1280 long wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1282 if ( message
== WM_NCHITTEST
)
1284 // the windows which contain the other windows should let the mouse
1285 // events through, otherwise a window inside a static box would
1286 // never get any events at all
1287 if ( IsStaticBox() )
1289 return HTTRANSPARENT
;
1293 return wxWindowNative::MSWWindowProc(message
, wParam
, lParam
);