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 licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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 long actualStyle
= style
;
126 // FIXME: may need this on other platforms
128 actualStyle
&= ~wxVSCROLL
;
129 actualStyle
&= ~wxHSCROLL
;
132 // we add wxCLIP_CHILDREN to get the same ("natural") behaviour under MSW
133 // as under the other platforms
134 if ( !wxWindowNative::Create(parent
, id
, pos
, size
,
135 actualStyle
| wxCLIP_CHILDREN
,
141 // Set full style again, including those we didn't want present
142 // when calling the base window Create().
143 wxWindowBase::SetWindowStyleFlag(style
);
145 // if we should always have a vertical scrollbar, do show it
146 if ( style
& wxALWAYS_SHOW_SB
)
148 #if wxUSE_TWO_WINDOWS
149 SetInsertIntoMain( TRUE
);
151 m_scrollbarVert
= new wxScrollBar(this, -1,
152 wxDefaultPosition
, wxDefaultSize
,
154 #if wxUSE_TWO_WINDOWS
155 SetInsertIntoMain( FALSE
);
159 // if we should always have a horizontal scrollbar, do show it
160 if ( style
& wxHSCROLL
)
162 #if wxUSE_TWO_WINDOWS
163 SetInsertIntoMain( TRUE
);
165 m_scrollbarHorz
= new wxScrollBar(this, -1,
166 wxDefaultPosition
, wxDefaultSize
,
168 #if wxUSE_TWO_WINDOWS
169 SetInsertIntoMain( FALSE
);
173 if (m_scrollbarHorz
|| m_scrollbarVert
)
176 PositionScrollbars();
182 // ----------------------------------------------------------------------------
184 // ----------------------------------------------------------------------------
186 void wxWindow::SetBackground(const wxBitmap
& bitmap
,
191 m_alignBgBitmap
= alignment
;
192 m_stretchBgBitmap
= stretch
;
195 const wxBitmap
& wxWindow::GetBackgroundBitmap(int *alignment
,
196 wxStretch
*stretch
) const
198 if ( m_bitmapBg
.Ok() )
201 *alignment
= m_alignBgBitmap
;
203 *stretch
= m_stretchBgBitmap
;
209 // ----------------------------------------------------------------------------
211 // ----------------------------------------------------------------------------
213 // the event handlers executed when the window must be repainted
214 void wxWindow::OnNcPaint(wxNcPaintEvent
& WXUNUSED(event
))
218 // get the window rect
220 wxSize size
= GetSize();
224 rect
.height
= size
.y
;
226 // if the scrollbars are outside the border, we must adjust the rect to
228 if ( !m_renderer
->AreScrollbarsInsideBorder() )
230 wxScrollBar
*scrollbar
= GetScrollbar(wxVERTICAL
);
232 rect
.width
-= scrollbar
->GetSize().x
;
234 scrollbar
= GetScrollbar(wxHORIZONTAL
);
236 rect
.height
-= scrollbar
->GetSize().y
;
239 // get the DC and draw the border on it
241 DoDrawBorder(dc
, rect
);
245 void wxWindow::OnPaint(wxPaintEvent
& event
)
249 // it is a native control which paints itself
254 // get the DC to use and create renderer on it
256 wxControlRenderer
renderer(this, dc
, m_renderer
);
263 // the event handler executed when the window background must be painted
264 void wxWindow::OnErase(wxEraseEvent
& event
)
273 DoDrawBackground(*event
.GetDC());
275 // if we have both scrollbars, we also have a square in the corner between
276 // them which we must paint
277 if ( m_scrollbarVert
&& m_scrollbarHorz
)
279 wxSize size
= GetSize();
280 wxRect rectClient
= GetClientRect(),
281 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
284 rectCorner
.x
= rectClient
.GetRight() + 1;
285 rectCorner
.y
= rectClient
.GetBottom() + 1;
286 rectCorner
.SetRight(size
.x
- rectBorder
.width
);
287 rectCorner
.SetBottom(size
.y
- rectBorder
.height
);
289 if ( GetUpdateRegion().Contains(rectCorner
) )
291 m_renderer
->DrawScrollCorner(*event
.GetDC(), rectCorner
);
296 bool wxWindow::DoDrawBackground(wxDC
& dc
)
300 wxSize size
= GetSize(); // Why not GetClientSize() ?
304 rect
.height
= size
.y
;
306 wxWindow
* const parent
= GetParent();
307 if ( HasTransparentBackground() && parent
&& parent
->ProvidesBackground() )
309 wxASSERT( !IsTopLevel() );
311 wxPoint pos
= GetPosition();
313 AdjustForParentClientOrigin( pos
.x
, pos
.y
, 0 );
315 // Adjust DC logical origin
316 wxCoord org_x
, org_y
, x
, y
;
317 dc
.GetLogicalOrigin( &org_x
, &org_y
);
320 dc
.SetLogicalOrigin( x
, y
);
326 // Let parent draw the background
327 parent
->EraseBackground( dc
, rect
);
329 // Restore DC logical origin
330 dc
.SetLogicalOrigin( org_x
, org_y
);
334 // Draw background ouselves
335 EraseBackground( dc
, rect
);
341 void wxWindow::EraseBackground(wxDC
& dc
, const wxRect
& rect
)
343 if ( GetBackgroundBitmap().Ok() )
345 // Get the bitmap and the flags
348 wxBitmap bmp
= GetBackgroundBitmap(&alignment
, &stretch
);
349 wxControlRenderer::DrawBitmap(dc
, bmp
, rect
, alignment
, stretch
);
353 // Just fill it with bg colour if no bitmap
355 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this),
356 rect
, GetStateFlags());
360 void wxWindow::DoDrawBorder(wxDC
& dc
, const wxRect
& rect
)
362 // draw outline unless the update region is enitrely inside it in which
363 // case we don't need to do it
364 #if 0 // doesn't seem to work, why?
365 if ( wxRegion(rect
).Contains(GetUpdateRegion().GetBox()) != wxInRegion
)
368 m_renderer
->DrawBorder(dc
, GetBorder(), rect
, GetStateFlags());
372 void wxWindow::DoDraw(wxControlRenderer
* WXUNUSED(renderer
))
376 void wxWindow::Refresh(bool eraseBackground
, const wxRect
*rectClient
)
379 wxPoint pt
= GetClientAreaOrigin();
381 wxSize size
= GetClientSize();
385 rectWin
= *rectClient
;
387 // don't refresh anything beyond the client area (scrollbars for
389 if ( rectWin
.GetRight() > size
.x
)
390 rectWin
.SetRight(size
.x
);
391 if ( rectWin
.GetBottom() > size
.y
)
392 rectWin
.SetBottom(size
.y
);
396 else // refresh the entire client area
400 rectWin
.width
= size
.x
;
401 rectWin
.height
= size
.y
;
405 #ifdef WXDEBUG_REFRESH
406 static bool s_refreshDebug
= FALSE
;
407 if ( s_refreshDebug
)
410 dc
.SetBrush(*wxCYAN_BRUSH
);
411 dc
.SetPen(*wxTRANSPARENT_PEN
);
412 dc
.DrawRectangle(rectWin
);
414 // under Unix we use "--sync" X option for this
415 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
420 #endif // WXDEBUG_REFRESH
422 wxWindowNative::Refresh(eraseBackground
, &rectWin
);
424 // Refresh all sub controls if any.
425 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
428 wxWindow
*win
= node
->GetData();
429 // Only refresh sub controls when it is visible
430 // and when it is in the update region.
431 if(!win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)) && win
->IsShown() && wxRegion(rectWin
).Contains(win
->GetRect()) != wxOutRegion
)
432 win
->Refresh(eraseBackground
, &rectWin
);
434 node
= node
->GetNext();
438 // ----------------------------------------------------------------------------
440 // ----------------------------------------------------------------------------
442 bool wxWindow::Enable(bool enable
)
444 if ( !wxWindowNative::Enable(enable
) )
447 // disabled window can't keep focus
448 if ( FindFocus() == this && GetParent() != NULL
)
450 GetParent()->SetFocus();
455 // a window with renderer is drawn by ourselves and it has to be
456 // refreshed to reflect its new status
463 bool wxWindow::IsFocused() const
465 wxWindow
*self
= wxConstCast(this, wxWindow
);
466 return self
->FindFocus() == self
;
469 bool wxWindow::IsPressed() const
474 bool wxWindow::IsDefault() const
479 bool wxWindow::IsCurrent() const
484 bool wxWindow::SetCurrent(bool doit
)
486 if ( doit
== m_isCurrent
)
491 if ( CanBeHighlighted() )
497 int wxWindow::GetStateFlags() const
501 flags
|= wxCONTROL_DISABLED
;
503 // the following states are only possible if our application is active - if
504 // it is not, even our default/focused controls shouldn't appear as such
505 if ( wxTheApp
->IsActive() )
508 flags
|= wxCONTROL_CURRENT
;
510 flags
|= wxCONTROL_FOCUSED
;
512 flags
|= wxCONTROL_PRESSED
;
514 flags
|= wxCONTROL_ISDEFAULT
;
520 // ----------------------------------------------------------------------------
522 // ----------------------------------------------------------------------------
524 void wxWindow::OnSize(wxSizeEvent
& event
)
528 if ( m_scrollbarVert
|| m_scrollbarHorz
)
530 PositionScrollbars();
533 #if 0 // ndef __WXMSW__
534 // Refresh the area (strip) previously occupied by the border
536 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) && IsShown() )
538 // This code assumes that wxSizeEvent.GetSize() returns
539 // the area of the entire window, not just the client
541 wxSize newSize
= event
.GetSize();
543 if (m_oldSize
.x
== -1 && m_oldSize
.y
== -1)
549 if (HasFlag( wxSIMPLE_BORDER
))
551 if (newSize
.y
> m_oldSize
.y
)
555 rect
.width
= m_oldSize
.x
;
556 rect
.y
= m_oldSize
.y
-2;
558 Refresh( TRUE
, &rect
);
560 else if (newSize
.y
< m_oldSize
.y
)
566 rect
.width
= newSize
.x
;
567 wxWindowNative::Refresh( TRUE
, &rect
);
570 if (newSize
.x
> m_oldSize
.x
)
574 rect
.height
= m_oldSize
.y
;
575 rect
.x
= m_oldSize
.x
-2;
577 Refresh( TRUE
, &rect
);
579 else if (newSize
.x
< m_oldSize
.x
)
585 rect
.height
= newSize
.y
;
586 wxWindowNative::Refresh( TRUE
, &rect
);
590 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
592 if (newSize
.y
> m_oldSize
.y
)
596 rect
.width
= m_oldSize
.x
;
597 rect
.y
= m_oldSize
.y
-4;
599 Refresh( TRUE
, &rect
);
601 else if (newSize
.y
< m_oldSize
.y
)
607 rect
.width
= newSize
.x
;
608 wxWindowNative::Refresh( TRUE
, &rect
);
611 if (newSize
.x
> m_oldSize
.x
)
615 rect
.height
= m_oldSize
.y
;
616 rect
.x
= m_oldSize
.x
-4;
618 Refresh( TRUE
, &rect
);
620 else if (newSize
.x
< m_oldSize
.x
)
626 rect
.height
= newSize
.y
;
627 wxWindowNative::Refresh( TRUE
, &rect
);
636 wxSize
wxWindow::DoGetBestSize() const
638 return AdjustSize(DoGetBestClientSize());
641 wxSize
wxWindow::DoGetBestClientSize() const
643 return wxWindowNative::DoGetBestSize();
646 wxSize
wxWindow::AdjustSize(const wxSize
& size
) const
650 m_renderer
->AdjustSize(&sz
, this);
654 wxPoint
wxWindow::GetClientAreaOrigin() const
656 wxPoint pt
= wxWindowBase::GetClientAreaOrigin();
658 #if wxUSE_TWO_WINDOWS
661 pt
+= m_renderer
->GetBorderDimensions(GetBorder()).GetPosition();
667 void wxWindow::DoGetClientSize(int *width
, int *height
) const
669 // if it is a native window, we assume it handles the scrollbars itself
670 // too - and if it doesn't, there is not much we can do
673 wxWindowNative::DoGetClientSize(width
, height
);
679 wxWindowNative::DoGetClientSize(&w
, &h
);
681 // we assume that the scrollbars are positioned correctly (by a previous
682 // call to PositionScrollbars()) here
686 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
688 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
692 // in any case, take account of the scrollbar
693 if ( m_scrollbarVert
)
694 w
-= m_scrollbarVert
->GetSize().x
;
696 // if we don't have scrollbar or if it is outside the border (and not
697 // blended into it), take account of the right border as well
698 if ( !m_scrollbarVert
|| inside
)
699 w
-= rectBorder
.width
;
701 // and always account for the left border
702 *width
= w
- rectBorder
.x
;
704 // we shouldn't return invalid width
711 if ( m_scrollbarHorz
)
712 h
-= m_scrollbarHorz
->GetSize().y
;
714 if ( !m_scrollbarHorz
|| inside
)
715 h
-= rectBorder
.height
;
717 *height
= h
- rectBorder
.y
;
719 // we shouldn't return invalid height
725 void wxWindow::DoSetClientSize(int width
, int height
)
727 // take into account the borders
728 wxRect rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
729 width
+= rectBorder
.x
;
730 height
+= rectBorder
.y
;
732 // and the scrollbars (as they may be offset into the border, use the
733 // scrollbar position, not size - this supposes that PositionScrollbars()
734 // had been called before)
735 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
736 wxSize size
= GetSize();
737 if ( m_scrollbarVert
)
738 width
+= size
.x
- m_scrollbarVert
->GetPosition().x
;
739 if ( !m_scrollbarVert
|| inside
)
740 width
+= rectBorder
.width
;
742 if ( m_scrollbarHorz
)
743 height
+= size
.y
- m_scrollbarHorz
->GetPosition().y
;
744 if ( !m_scrollbarHorz
|| inside
)
745 height
+= rectBorder
.height
;
747 wxWindowNative::DoSetClientSize(width
, height
);
750 wxHitTest
wxWindow::DoHitTest(wxCoord x
, wxCoord y
) const
752 wxHitTest ht
= wxWindowNative::DoHitTest(x
, y
);
753 if ( ht
== wxHT_WINDOW_INSIDE
)
755 if ( m_scrollbarVert
&& x
>= m_scrollbarVert
->GetPosition().x
)
757 // it can still be changed below because it may also be the corner
758 ht
= wxHT_WINDOW_VERT_SCROLLBAR
;
761 if ( m_scrollbarHorz
&& y
>= m_scrollbarHorz
->GetPosition().y
)
763 ht
= ht
== wxHT_WINDOW_VERT_SCROLLBAR
? wxHT_WINDOW_CORNER
764 : wxHT_WINDOW_HORZ_SCROLLBAR
;
771 // ----------------------------------------------------------------------------
772 // scrolling: we implement it entirely ourselves except for ScrollWindow()
773 // function which is supposed to be (efficiently) implemented by the native
775 // ----------------------------------------------------------------------------
777 void wxWindow::RefreshScrollbars()
779 if ( m_scrollbarHorz
)
780 m_scrollbarHorz
->Refresh();
782 if ( m_scrollbarVert
)
783 m_scrollbarVert
->Refresh();
786 void wxWindow::PositionScrollbars()
788 // do not use GetClientSize/Rect as it relies on the scrollbars being
789 // correctly positioned
791 wxSize size
= GetSize();
792 wxBorder border
= GetBorder();
793 wxRect rectBorder
= m_renderer
->GetBorderDimensions(border
);
794 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
796 int height
= m_scrollbarHorz
? m_scrollbarHorz
->GetSize().y
: 0;
797 int width
= m_scrollbarVert
? m_scrollbarVert
->GetSize().x
: 0;
800 if ( m_scrollbarVert
)
802 rectBar
.x
= size
.x
- width
;
804 rectBar
.x
-= rectBorder
.width
;
805 rectBar
.width
= width
;
808 rectBar
.y
+= rectBorder
.y
;
809 rectBar
.height
= size
.y
- height
;
811 rectBar
.height
-= rectBorder
.y
+ rectBorder
.height
;
813 m_scrollbarVert
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
816 if ( m_scrollbarHorz
)
818 rectBar
.y
= size
.y
- height
;
820 rectBar
.y
-= rectBorder
.height
;
821 rectBar
.height
= height
;
824 rectBar
.x
+= rectBorder
.x
;
825 rectBar
.width
= size
.x
- width
;
827 rectBar
.width
-= rectBorder
.x
+ rectBorder
.width
;
829 m_scrollbarHorz
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
835 void wxWindow::SetScrollbar(int orient
,
841 wxASSERT_MSG( pageSize
<= range
,
842 _T("page size can't be greater than range") );
844 bool hasClientSizeChanged
= FALSE
;
845 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
846 if ( range
&& (pageSize
< range
) )
851 #if wxUSE_TWO_WINDOWS
852 SetInsertIntoMain( TRUE
);
854 scrollbar
= new wxScrollBar(this, -1,
855 wxDefaultPosition
, wxDefaultSize
,
856 orient
& wxVERTICAL
? wxSB_VERTICAL
858 #if wxUSE_TWO_WINDOWS
859 SetInsertIntoMain( FALSE
);
861 if ( orient
& wxVERTICAL
)
862 m_scrollbarVert
= scrollbar
;
864 m_scrollbarHorz
= scrollbar
;
866 // the client area diminished as we created a scrollbar
867 hasClientSizeChanged
= TRUE
;
869 PositionScrollbars();
871 else if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
873 // we might have disabled it before
877 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
879 else // no range means no scrollbar
883 // wxALWAYS_SHOW_SB only applies to the vertical scrollbar
884 if ( (orient
& wxVERTICAL
) && (GetWindowStyle() & wxALWAYS_SHOW_SB
) )
886 // just disable the scrollbar
887 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
888 scrollbar
->Disable();
890 else // really remove the scrollbar
894 if ( orient
& wxVERTICAL
)
895 m_scrollbarVert
= NULL
;
897 m_scrollbarHorz
= NULL
;
899 // the client area increased as we removed a scrollbar
900 hasClientSizeChanged
= TRUE
;
902 // the size of the remaining scrollbar must be adjusted
903 if ( m_scrollbarHorz
|| m_scrollbarVert
)
905 PositionScrollbars();
911 // give the window a chance to relayout
912 if ( hasClientSizeChanged
)
914 #if wxUSE_TWO_WINDOWS
915 wxWindowNative::SetSize( GetSize() );
917 wxSizeEvent
event(GetSize());
918 (void)GetEventHandler()->ProcessEvent(event
);
923 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
925 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
926 wxCHECK_RET( scrollbar
, _T("no scrollbar to set position for") );
928 scrollbar
->SetThumbPosition(pos
);
930 // VZ: I think we can safely ignore this as we always refresh it
931 // automatically whenever the value chanegs
938 int wxWindow::GetScrollPos(int orient
) const
940 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
941 return scrollbar
? scrollbar
->GetThumbPosition() : 0;
944 int wxWindow::GetScrollThumb(int orient
) const
946 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
947 return scrollbar
? scrollbar
->GetThumbSize() : 0;
950 int wxWindow::GetScrollRange(int orient
) const
952 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
953 return scrollbar
? scrollbar
->GetRange() : 0;
956 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
958 // use native scrolling when available and do it in generic way
962 wxWindowNative::ScrollWindow(dx
, dy
, rect
);
966 // before scrolling it, ensure that we don't have any unpainted areas
973 r
= ScrollNoRefresh(dx
, 0, rect
);
974 Refresh(TRUE
/* erase bkgnd */, &r
);
979 r
= ScrollNoRefresh(0, dy
, rect
);
980 Refresh(TRUE
/* erase bkgnd */, &r
);
983 // scroll children accordingly:
984 wxPoint
offset(dx
, dy
);
986 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
987 node
; node
= node
->GetNext())
989 wxWindow
*child
= node
->GetData();
990 if ( child
== m_scrollbarVert
|| child
== m_scrollbarHorz
)
993 // VS: Scrolling children has non-trivial semantics. If rect=NULL then
994 // it is easy: we scroll all children. Otherwise it gets
996 // 1. if scrolling in one direction only, scroll only
997 // those children that intersect shaft defined by the rectangle
998 // and scrolling direction
999 // 2. if scrolling in both axes, scroll all children
1001 if ( rect
&& (dx
* dy
== 0 /* moving in only one of x, y axis */) )
1003 wxRect childRect
= child
->GetRect();
1004 if ( dx
== 0 && (childRect
.GetLeft() <= rect
->GetRight() ||
1005 childRect
.GetRight() >= rect
->GetLeft()) )
1007 child
->Move(child
->GetPosition() + offset
);
1009 else if ( dy
== 0 && (childRect
.GetTop() <= rect
->GetBottom() ||
1010 childRect
.GetBottom() >= rect
->GetTop()) )
1012 child
->Move(child
->GetPosition() + offset
);
1017 child
->Move(child
->GetPosition() + offset
);
1020 #endif // wxX11/!wxX11
1023 wxRect
wxWindow::ScrollNoRefresh(int dx
, int dy
, const wxRect
*rectTotal
)
1025 wxASSERT_MSG( !dx
|| !dy
, _T("can't be used for diag scrolling") );
1027 // the rect to refresh (which we will calculate)
1036 // calculate the part of the window which we can just redraw in the new
1038 wxSize sizeTotal
= rectTotal
? rectTotal
->GetSize() : GetClientSize();
1040 wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
1041 sizeTotal
.x
, sizeTotal
.y
, dx
, dy
);
1043 // the initial and end point of the region we move in client coords
1044 wxPoint ptSource
, ptDest
;
1047 ptSource
= rectTotal
->GetPosition();
1048 ptDest
= rectTotal
->GetPosition();
1051 // the size of this region
1053 size
.x
= sizeTotal
.x
- abs(dx
);
1054 size
.y
= sizeTotal
.y
- abs(dy
);
1055 if ( size
.x
<= 0 || size
.y
<= 0 )
1057 // just redraw everything as nothing of the displayed image will stay
1058 wxLogTrace(_T("scroll"), _T("refreshing everything"));
1060 rect
= rectTotal
? *rectTotal
: wxRect(0, 0, sizeTotal
.x
, sizeTotal
.y
);
1062 else // move the part which doesn't change to the new location
1064 // note that when we scroll the canvas in some direction we move the
1065 // block which doesn't need to be refreshed in the opposite direction
1069 // scroll to the right, move to the left
1074 // scroll to the left, move to the right
1080 // scroll down, move up
1085 // scroll up, move down
1090 // we need to hide the caret before moving or it will erase itself at
1091 // the wrong (old) location
1092 wxCaret
*caret
= GetCaret();
1095 #endif // wxUSE_CARET
1098 wxClientDC
dc(this);
1099 wxBitmap
bmp(size
.x
, size
.y
);
1101 dcMem
.SelectObject(bmp
);
1103 dcMem
.Blit(wxPoint(0, 0), size
, &dc
, ptSource
1104 #if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
1105 + GetClientAreaOrigin()
1106 #endif // broken wxGTK wxDC::Blit
1108 dc
.Blit(ptDest
, size
, &dcMem
, wxPoint(0, 0));
1110 wxLogTrace(_T("scroll"),
1111 _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
1112 ptSource
.x
, ptSource
.y
,
1114 ptDest
.x
, ptDest
.y
);
1116 // and now repaint the uncovered area
1118 // FIXME: We repaint the intersection of these rectangles twice - is
1119 // it bad? I don't think so as it is rare to scroll the window
1120 // diagonally anyhow and so adding extra logic to compute
1121 // rectangle intersection is probably not worth the effort
1123 rect
.x
= ptSource
.x
;
1124 rect
.y
= ptSource
.y
;
1130 // refresh the area along the right border
1131 rect
.x
+= size
.x
+ dx
;
1136 // refresh the area along the left border
1140 rect
.height
= sizeTotal
.y
;
1142 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1144 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1151 // refresh the area along the bottom border
1152 rect
.y
+= size
.y
+ dy
;
1157 // refresh the area along the top border
1161 rect
.width
= sizeTotal
.x
;
1163 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1165 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1171 #endif // wxUSE_CARET
1177 // ----------------------------------------------------------------------------
1178 // accelerators and menu hot keys
1179 // ----------------------------------------------------------------------------
1182 // the last window over which Alt was pressed (used by OnKeyUp)
1183 wxWindow
*wxWindow::ms_winLastAltPress
= NULL
;
1184 #endif // wxUSE_MENUS
1186 #if wxUSE_ACCEL || wxUSE_MENUS
1188 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1191 int key
= event
.GetKeyCode();
1192 if ( !event
.ControlDown() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1194 ms_winLastAltPress
= this;
1196 // it can't be an accel anyhow
1200 ms_winLastAltPress
= NULL
;
1201 #endif // wxUSE_MENUS
1204 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
1206 int command
= win
->GetAcceleratorTable()->GetCommand(event
);
1207 if ( command
!= -1 )
1209 wxCommandEvent
eventCmd(wxEVT_COMMAND_MENU_SELECTED
, command
);
1210 if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) )
1212 // skip "event.Skip()" below
1217 if ( win
->IsTopLevel() )
1219 // try the frame menu bar
1221 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1224 wxMenuBar
*menubar
= frame
->GetMenuBar();
1225 if ( menubar
&& menubar
->ProcessAccelEvent(event
) )
1227 // skip "event.Skip()" below
1231 #endif // wxUSE_MENUS
1233 // if it wasn't in a menu, try to find a button
1234 if ( command
!= -1 )
1236 wxWindow
* child
= win
->FindWindow(command
);
1237 if ( child
&& wxDynamicCast(child
, wxButton
) )
1239 wxCommandEvent
eventCmd(wxEVT_COMMAND_BUTTON_CLICKED
, command
);
1240 eventCmd
.SetEventObject(child
);
1241 if ( child
->GetEventHandler()->ProcessEvent(eventCmd
) )
1243 // skip "event.Skip()" below
1249 // don't propagate accels from the child frame to the parent one
1253 #endif // wxUSE_ACCEL
1258 #endif // wxUSE_ACCEL
1262 wxMenuBar
*wxWindow::GetParentFrameMenuBar() const
1264 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
1266 if ( win
->IsTopLevel() )
1268 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1271 return frame
->GetMenuBar();
1274 // don't look further - we don't want to return the menubar of the
1283 void wxWindow::OnChar(wxKeyEvent
& event
)
1285 if ( event
.AltDown() && !event
.ControlDown() )
1287 int key
= event
.GetKeyCode();
1289 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1292 int item
= menubar
->FindNextItemForAccel(-1, key
);
1295 menubar
->PopupMenu((size_t)item
);
1297 // skip "event.Skip()" below
1306 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1308 int key
= event
.GetKeyCode();
1309 if ( !event
.HasModifiers() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1311 // only process Alt release specially if there were no other key
1312 // presses since Alt had been pressed and if both events happened in
1314 if ( ms_winLastAltPress
== this )
1316 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1317 if ( menubar
&& this != menubar
)
1319 menubar
->SelectMenu(0);
1328 // in any case reset it
1329 ms_winLastAltPress
= NULL
;
1332 #endif // wxUSE_MENUS
1334 // ----------------------------------------------------------------------------
1335 // MSW-specific section
1336 // ----------------------------------------------------------------------------
1340 #include "wx/msw/private.h"
1342 long wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1344 if ( message
== WM_NCHITTEST
)
1346 // the windows which contain the other windows should let the mouse
1347 // events through, otherwise a window inside a static box would
1348 // never get any events at all
1349 if ( IsStaticBox() )
1351 return HTTRANSPARENT
;
1355 return wxWindowNative::MSWWindowProc(message
, wParam
, lParam
);