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 // ----------------------------------------------------------------------------
109 wxWindow::wxWindow(wxWindow
*parent
,
114 const wxString
& name
)
115 : wxWindowNative(parent
, id
, pos
, size
, style
| wxCLIP_CHILDREN
, name
)
120 void wxWindow::Init()
123 m_scrollbarHorz
= (wxScrollBar
*)NULL
;
127 m_renderer
= wxTheme::Get()->GetRenderer();
133 bool wxWindow::Create(wxWindow
*parent
,
138 const wxString
& name
)
140 long actualStyle
= style
;
142 // FIXME: may need this on other platforms
144 actualStyle
&= ~wxVSCROLL
;
145 actualStyle
&= ~wxHSCROLL
;
148 // we add wxCLIP_CHILDREN to get the same ("natural") behaviour under MSW
149 // as under the other platforms
150 if ( !wxWindowNative::Create(parent
, id
, pos
, size
,
151 actualStyle
| wxCLIP_CHILDREN
,
157 // Set full style again, including those we didn't want present
158 // when calling the base window Create().
159 wxWindowBase::SetWindowStyleFlag(style
);
161 // if we should always have a vertical scrollbar, do show it
162 if ( style
& wxALWAYS_SHOW_SB
)
164 #if wxUSE_TWO_WINDOWS
165 SetInsertIntoMain( TRUE
);
167 m_scrollbarVert
= new wxScrollBar(this, -1,
168 wxDefaultPosition
, wxDefaultSize
,
170 #if wxUSE_TWO_WINDOWS
171 SetInsertIntoMain( FALSE
);
175 // if we should always have a horizontal scrollbar, do show it
176 if ( style
& wxHSCROLL
)
178 #if wxUSE_TWO_WINDOWS
179 SetInsertIntoMain( TRUE
);
181 m_scrollbarHorz
= new wxScrollBar(this, -1,
182 wxDefaultPosition
, wxDefaultSize
,
184 #if wxUSE_TWO_WINDOWS
185 SetInsertIntoMain( FALSE
);
189 if (m_scrollbarHorz
|| m_scrollbarVert
)
192 PositionScrollbars();
198 // ----------------------------------------------------------------------------
200 // ----------------------------------------------------------------------------
202 void wxWindow::SetBackground(const wxBitmap
& bitmap
,
207 m_alignBgBitmap
= alignment
;
208 m_stretchBgBitmap
= stretch
;
211 const wxBitmap
& wxWindow::GetBackgroundBitmap(int *alignment
,
212 wxStretch
*stretch
) const
214 if ( m_bitmapBg
.Ok() )
217 *alignment
= m_alignBgBitmap
;
219 *stretch
= m_stretchBgBitmap
;
225 // ----------------------------------------------------------------------------
227 // ----------------------------------------------------------------------------
229 // the event handlers executed when the window must be repainted
230 void wxWindow::OnNcPaint(wxPaintEvent
& WXUNUSED(event
))
234 // get the window rect
236 wxSize size
= GetSize();
240 rect
.height
= size
.y
;
242 // if the scrollbars are outside the border, we must adjust the rect to
244 if ( !m_renderer
->AreScrollbarsInsideBorder() )
246 wxScrollBar
*scrollbar
= GetScrollbar(wxVERTICAL
);
248 rect
.width
-= scrollbar
->GetSize().x
;
250 scrollbar
= GetScrollbar(wxHORIZONTAL
);
252 rect
.height
-= scrollbar
->GetSize().y
;
255 // get the DC and draw the border on it
257 DoDrawBorder(dc
, rect
);
261 void wxWindow::OnPaint(wxPaintEvent
& event
)
265 // it is a native control which paints itself
270 // get the DC to use and create renderer on it
272 wxControlRenderer
renderer(this, dc
, m_renderer
);
279 // the event handler executed when the window background must be painted
280 void wxWindow::OnErase(wxEraseEvent
& event
)
289 DoDrawBackground(*event
.GetDC());
291 // if we have both scrollbars, we also have a square in the corner between
292 // them which we must paint
293 if ( m_scrollbarVert
&& m_scrollbarHorz
)
295 wxSize size
= GetSize();
296 wxRect rectClient
= GetClientRect(),
297 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
300 rectCorner
.x
= rectClient
.GetRight() + 1;
301 rectCorner
.y
= rectClient
.GetBottom() + 1;
302 rectCorner
.SetRight(size
.x
- rectBorder
.width
);
303 rectCorner
.SetBottom(size
.y
- rectBorder
.height
);
305 if ( GetUpdateRegion().Contains(rectCorner
) )
307 m_renderer
->DrawScrollCorner(*event
.GetDC(), rectCorner
);
312 bool wxWindow::DoDrawBackground(wxDC
& dc
)
316 wxSize size
= GetSize(); // Why not GetClientSize() ?
320 rect
.height
= size
.y
;
322 wxWindow
* const parent
= GetParent();
323 if ( HasTransparentBackground() && parent
&& parent
->ProvidesBackground() )
325 wxASSERT( !IsTopLevel() );
327 wxPoint pos
= GetPosition();
329 AdjustForParentClientOrigin( pos
.x
, pos
.y
, 0 );
331 // Adjust DC logical origin
332 wxCoord org_x
, org_y
, x
, y
;
333 dc
.GetLogicalOrigin( &org_x
, &org_y
);
336 dc
.SetLogicalOrigin( x
, y
);
342 // Let parent draw the background
343 parent
->EraseBackground( dc
, rect
);
345 // Restore DC logical origin
346 dc
.SetLogicalOrigin( org_x
, org_y
);
350 // Draw background ouselves
351 EraseBackground( dc
, rect
);
357 void wxWindow::EraseBackground(wxDC
& dc
, const wxRect
& rect
)
359 if ( GetBackgroundBitmap().Ok() )
361 // Get the bitmap and the flags
364 wxBitmap bmp
= GetBackgroundBitmap(&alignment
, &stretch
);
365 wxControlRenderer::DrawBitmap(dc
, bmp
, rect
, alignment
, stretch
);
369 // Just fill it with bg colour if no bitmap
371 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this),
372 rect
, GetStateFlags());
376 void wxWindow::DoDrawBorder(wxDC
& dc
, const wxRect
& rect
)
378 // draw outline unless the update region is enitrely inside it in which
379 // case we don't need to do it
380 #if 0 // doesn't seem to work, why?
381 if ( wxRegion(rect
).Contains(GetUpdateRegion().GetBox()) != wxInRegion
)
384 m_renderer
->DrawBorder(dc
, GetBorder(), rect
, GetStateFlags());
388 void wxWindow::DoDraw(wxControlRenderer
* WXUNUSED(renderer
))
392 void wxWindow::Refresh(bool eraseBackground
, const wxRect
*rectClient
)
395 wxPoint pt
= GetClientAreaOrigin();
397 wxSize size
= GetClientSize();
401 rectWin
= *rectClient
;
403 // don't refresh anything beyond the client area (scrollbars for
405 if ( rectWin
.GetRight() > size
.x
)
406 rectWin
.SetRight(size
.x
);
407 if ( rectWin
.GetBottom() > size
.y
)
408 rectWin
.SetBottom(size
.y
);
412 else // refresh the entire client area
416 rectWin
.width
= size
.x
;
417 rectWin
.height
= size
.y
;
421 #ifdef WXDEBUG_REFRESH
422 static bool s_refreshDebug
= FALSE
;
423 if ( s_refreshDebug
)
426 dc
.SetBrush(*wxCYAN_BRUSH
);
427 dc
.SetPen(*wxTRANSPARENT_PEN
);
428 dc
.DrawRectangle(rectWin
);
430 // under Unix we use "--sync" X option for this
431 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
436 #endif // WXDEBUG_REFRESH
438 wxWindowNative::Refresh(eraseBackground
, &rectWin
);
440 // Refresh all sub controls if any.
441 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
444 wxWindow
*win
= node
->GetData();
445 // Only refresh sub controls when it is visible
446 // and when it is in the update region.
447 if(!win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)) && win
->IsShown() && wxRegion(rectWin
).Contains(win
->GetRect()) != wxOutRegion
)
448 win
->Refresh(eraseBackground
, &rectWin
);
450 node
= node
->GetNext();
454 // ----------------------------------------------------------------------------
456 // ----------------------------------------------------------------------------
458 bool wxWindow::Enable(bool enable
)
460 if ( !wxWindowNative::Enable(enable
) )
463 // disabled window can't keep focus
464 if ( FindFocus() == this && GetParent() != NULL
)
466 GetParent()->SetFocus();
471 // a window with renderer is drawn by ourselves and it has to be
472 // refreshed to reflect its new status
479 bool wxWindow::IsFocused() const
481 wxWindow
*self
= wxConstCast(this, wxWindow
);
482 return self
->FindFocus() == self
;
485 bool wxWindow::IsPressed() const
490 bool wxWindow::IsDefault() const
495 bool wxWindow::IsCurrent() const
500 bool wxWindow::SetCurrent(bool doit
)
502 if ( doit
== m_isCurrent
)
507 if ( CanBeHighlighted() )
513 int wxWindow::GetStateFlags() const
517 flags
|= wxCONTROL_DISABLED
;
519 // the following states are only possible if our application is active - if
520 // it is not, even our default/focused controls shouldn't appear as such
521 if ( wxTheApp
->IsActive() )
524 flags
|= wxCONTROL_CURRENT
;
526 flags
|= wxCONTROL_FOCUSED
;
528 flags
|= wxCONTROL_PRESSED
;
530 flags
|= wxCONTROL_ISDEFAULT
;
536 // ----------------------------------------------------------------------------
538 // ----------------------------------------------------------------------------
540 void wxWindow::OnSize(wxSizeEvent
& event
)
544 if ( m_scrollbarVert
|| m_scrollbarHorz
)
546 PositionScrollbars();
549 #if 0 // ndef __WXMSW__
550 // Refresh the area (strip) previously occupied by the border
552 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) && IsShown() )
554 // This code assumes that wxSizeEvent.GetSize() returns
555 // the area of the entire window, not just the client
557 wxSize newSize
= event
.GetSize();
559 if (m_oldSize
.x
== -1 && m_oldSize
.y
== -1)
565 if (HasFlag( wxSIMPLE_BORDER
))
567 if (newSize
.y
> m_oldSize
.y
)
571 rect
.width
= m_oldSize
.x
;
572 rect
.y
= m_oldSize
.y
-2;
574 Refresh( TRUE
, &rect
);
576 else if (newSize
.y
< m_oldSize
.y
)
582 rect
.width
= newSize
.x
;
583 wxWindowNative::Refresh( TRUE
, &rect
);
586 if (newSize
.x
> m_oldSize
.x
)
590 rect
.height
= m_oldSize
.y
;
591 rect
.x
= m_oldSize
.x
-2;
593 Refresh( TRUE
, &rect
);
595 else if (newSize
.x
< m_oldSize
.x
)
601 rect
.height
= newSize
.y
;
602 wxWindowNative::Refresh( TRUE
, &rect
);
606 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
608 if (newSize
.y
> m_oldSize
.y
)
612 rect
.width
= m_oldSize
.x
;
613 rect
.y
= m_oldSize
.y
-4;
615 Refresh( TRUE
, &rect
);
617 else if (newSize
.y
< m_oldSize
.y
)
623 rect
.width
= newSize
.x
;
624 wxWindowNative::Refresh( TRUE
, &rect
);
627 if (newSize
.x
> m_oldSize
.x
)
631 rect
.height
= m_oldSize
.y
;
632 rect
.x
= m_oldSize
.x
-4;
634 Refresh( TRUE
, &rect
);
636 else if (newSize
.x
< m_oldSize
.x
)
642 rect
.height
= newSize
.y
;
643 wxWindowNative::Refresh( TRUE
, &rect
);
652 wxSize
wxWindow::DoGetBestSize() const
654 return AdjustSize(DoGetBestClientSize());
657 wxSize
wxWindow::DoGetBestClientSize() const
659 return wxWindowNative::DoGetBestSize();
662 wxSize
wxWindow::AdjustSize(const wxSize
& size
) const
666 m_renderer
->AdjustSize(&sz
, this);
670 wxPoint
wxWindow::GetClientAreaOrigin() const
672 wxPoint pt
= wxWindowBase::GetClientAreaOrigin();
674 #if wxUSE_TWO_WINDOWS
677 pt
+= m_renderer
->GetBorderDimensions(GetBorder()).GetPosition();
683 void wxWindow::DoGetClientSize(int *width
, int *height
) const
685 // if it is a native window, we assume it handles the scrollbars itself
686 // too - and if it doesn't, there is not much we can do
689 wxWindowNative::DoGetClientSize(width
, height
);
695 wxWindowNative::DoGetClientSize(&w
, &h
);
697 // we assume that the scrollbars are positioned correctly (by a previous
698 // call to PositionScrollbars()) here
702 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
704 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
708 // in any case, take account of the scrollbar
709 if ( m_scrollbarVert
)
710 w
-= m_scrollbarVert
->GetSize().x
;
712 // if we don't have scrollbar or if it is outside the border (and not
713 // blended into it), take account of the right border as well
714 if ( !m_scrollbarVert
|| inside
)
715 w
-= rectBorder
.width
;
717 // and always account for the left border
718 *width
= w
- rectBorder
.x
;
720 // we shouldn't return invalid width
727 if ( m_scrollbarHorz
)
728 h
-= m_scrollbarHorz
->GetSize().y
;
730 if ( !m_scrollbarHorz
|| inside
)
731 h
-= rectBorder
.height
;
733 *height
= h
- rectBorder
.y
;
735 // we shouldn't return invalid height
741 void wxWindow::DoSetClientSize(int width
, int height
)
743 // take into account the borders
744 wxRect rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
745 width
+= rectBorder
.x
;
746 height
+= rectBorder
.y
;
748 // and the scrollbars (as they may be offset into the border, use the
749 // scrollbar position, not size - this supposes that PositionScrollbars()
750 // had been called before)
751 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
752 wxSize size
= GetSize();
753 if ( m_scrollbarVert
)
754 width
+= size
.x
- m_scrollbarVert
->GetPosition().x
;
755 if ( !m_scrollbarVert
|| inside
)
756 width
+= rectBorder
.width
;
758 if ( m_scrollbarHorz
)
759 height
+= size
.y
- m_scrollbarHorz
->GetPosition().y
;
760 if ( !m_scrollbarHorz
|| inside
)
761 height
+= rectBorder
.height
;
763 wxWindowNative::DoSetClientSize(width
, height
);
766 wxHitTest
wxWindow::DoHitTest(wxCoord x
, wxCoord y
) const
768 wxHitTest ht
= wxWindowNative::DoHitTest(x
, y
);
769 if ( ht
== wxHT_WINDOW_INSIDE
)
771 if ( m_scrollbarVert
&& x
>= m_scrollbarVert
->GetPosition().x
)
773 // it can still be changed below because it may also be the corner
774 ht
= wxHT_WINDOW_VERT_SCROLLBAR
;
777 if ( m_scrollbarHorz
&& y
>= m_scrollbarHorz
->GetPosition().y
)
779 ht
= ht
== wxHT_WINDOW_VERT_SCROLLBAR
? wxHT_WINDOW_CORNER
780 : wxHT_WINDOW_HORZ_SCROLLBAR
;
787 // ----------------------------------------------------------------------------
788 // scrolling: we implement it entirely ourselves except for ScrollWindow()
789 // function which is supposed to be (efficiently) implemented by the native
791 // ----------------------------------------------------------------------------
793 void wxWindow::RefreshScrollbars()
795 if ( m_scrollbarHorz
)
796 m_scrollbarHorz
->Refresh();
798 if ( m_scrollbarVert
)
799 m_scrollbarVert
->Refresh();
802 void wxWindow::PositionScrollbars()
804 // do not use GetClientSize/Rect as it relies on the scrollbars being
805 // correctly positioned
807 wxSize size
= GetSize();
808 wxBorder border
= GetBorder();
809 wxRect rectBorder
= m_renderer
->GetBorderDimensions(border
);
810 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
812 int height
= m_scrollbarHorz
? m_scrollbarHorz
->GetSize().y
: 0;
813 int width
= m_scrollbarVert
? m_scrollbarVert
->GetSize().x
: 0;
816 if ( m_scrollbarVert
)
818 rectBar
.x
= size
.x
- width
;
820 rectBar
.x
-= rectBorder
.width
;
821 rectBar
.width
= width
;
824 rectBar
.y
+= rectBorder
.y
;
825 rectBar
.height
= size
.y
- height
;
827 rectBar
.height
-= rectBorder
.y
+ rectBorder
.height
;
829 m_scrollbarVert
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
832 if ( m_scrollbarHorz
)
834 rectBar
.y
= size
.y
- height
;
836 rectBar
.y
-= rectBorder
.height
;
837 rectBar
.height
= height
;
840 rectBar
.x
+= rectBorder
.x
;
841 rectBar
.width
= size
.x
- width
;
843 rectBar
.width
-= rectBorder
.x
+ rectBorder
.width
;
845 m_scrollbarHorz
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
851 void wxWindow::SetScrollbar(int orient
,
857 wxASSERT_MSG( pageSize
<= range
,
858 _T("page size can't be greater than range") );
860 bool hasClientSizeChanged
= FALSE
;
861 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
862 if ( range
&& (pageSize
< range
) )
867 #if wxUSE_TWO_WINDOWS
868 SetInsertIntoMain( TRUE
);
870 scrollbar
= new wxScrollBar(this, -1,
871 wxDefaultPosition
, wxDefaultSize
,
872 orient
& wxVERTICAL
? wxSB_VERTICAL
874 #if wxUSE_TWO_WINDOWS
875 SetInsertIntoMain( FALSE
);
877 if ( orient
& wxVERTICAL
)
878 m_scrollbarVert
= scrollbar
;
880 m_scrollbarHorz
= scrollbar
;
882 // the client area diminished as we created a scrollbar
883 hasClientSizeChanged
= TRUE
;
885 PositionScrollbars();
887 else if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
889 // we might have disabled it before
893 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
895 else // no range means no scrollbar
899 // wxALWAYS_SHOW_SB only applies to the vertical scrollbar
900 if ( (orient
& wxVERTICAL
) && (GetWindowStyle() & wxALWAYS_SHOW_SB
) )
902 // just disable the scrollbar
903 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
904 scrollbar
->Disable();
906 else // really remove the scrollbar
910 if ( orient
& wxVERTICAL
)
911 m_scrollbarVert
= NULL
;
913 m_scrollbarHorz
= NULL
;
915 // the client area increased as we removed a scrollbar
916 hasClientSizeChanged
= TRUE
;
918 // the size of the remaining scrollbar must be adjusted
919 if ( m_scrollbarHorz
|| m_scrollbarVert
)
921 PositionScrollbars();
927 // give the window a chance to relayout
928 if ( hasClientSizeChanged
)
930 #if wxUSE_TWO_WINDOWS
931 wxWindowNative::SetSize( GetSize() );
933 wxSizeEvent
event(GetSize());
934 (void)GetEventHandler()->ProcessEvent(event
);
939 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
941 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
942 wxCHECK_RET( scrollbar
, _T("no scrollbar to set position for") );
944 scrollbar
->SetThumbPosition(pos
);
946 // VZ: I think we can safely ignore this as we always refresh it
947 // automatically whenever the value chanegs
954 int wxWindow::GetScrollPos(int orient
) const
956 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
957 return scrollbar
? scrollbar
->GetThumbPosition() : 0;
960 int wxWindow::GetScrollThumb(int orient
) const
962 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
963 return scrollbar
? scrollbar
->GetThumbSize() : 0;
966 int wxWindow::GetScrollRange(int orient
) const
968 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
969 return scrollbar
? scrollbar
->GetRange() : 0;
972 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
974 // use native scrolling when available and do it in generic way
978 wxWindowNative::ScrollWindow(dx
, dy
, rect
);
982 // before scrolling it, ensure that we don't have any unpainted areas
989 r
= ScrollNoRefresh(dx
, 0, rect
);
990 Refresh(TRUE
/* erase bkgnd */, &r
);
995 r
= ScrollNoRefresh(0, dy
, rect
);
996 Refresh(TRUE
/* erase bkgnd */, &r
);
999 // scroll children accordingly:
1000 wxPoint
offset(dx
, dy
);
1002 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1003 node
; node
= node
->GetNext())
1005 wxWindow
*child
= node
->GetData();
1006 if ( child
== m_scrollbarVert
|| child
== m_scrollbarHorz
)
1009 // VS: Scrolling children has non-trivial semantics. If rect=NULL then
1010 // it is easy: we scroll all children. Otherwise it gets
1012 // 1. if scrolling in one direction only, scroll only
1013 // those children that intersect shaft defined by the rectangle
1014 // and scrolling direction
1015 // 2. if scrolling in both axes, scroll all children
1017 if ( rect
&& (dx
* dy
== 0 /* moving in only one of x, y axis */) )
1019 wxRect childRect
= child
->GetRect();
1020 if ( dx
== 0 && (childRect
.GetLeft() <= rect
->GetRight() ||
1021 childRect
.GetRight() >= rect
->GetLeft()) )
1023 child
->Move(child
->GetPosition() + offset
);
1025 else if ( dy
== 0 && (childRect
.GetTop() <= rect
->GetBottom() ||
1026 childRect
.GetBottom() >= rect
->GetTop()) )
1028 child
->Move(child
->GetPosition() + offset
);
1033 child
->Move(child
->GetPosition() + offset
);
1036 #endif // wxX11/!wxX11
1039 wxRect
wxWindow::ScrollNoRefresh(int dx
, int dy
, const wxRect
*rectTotal
)
1041 wxASSERT_MSG( !dx
|| !dy
, _T("can't be used for diag scrolling") );
1043 // the rect to refresh (which we will calculate)
1052 // calculate the part of the window which we can just redraw in the new
1054 wxSize sizeTotal
= rectTotal
? rectTotal
->GetSize() : GetClientSize();
1056 wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
1057 sizeTotal
.x
, sizeTotal
.y
, dx
, dy
);
1059 // the initial and end point of the region we move in client coords
1060 wxPoint ptSource
, ptDest
;
1063 ptSource
= rectTotal
->GetPosition();
1064 ptDest
= rectTotal
->GetPosition();
1067 // the size of this region
1069 size
.x
= sizeTotal
.x
- abs(dx
);
1070 size
.y
= sizeTotal
.y
- abs(dy
);
1071 if ( size
.x
<= 0 || size
.y
<= 0 )
1073 // just redraw everything as nothing of the displayed image will stay
1074 wxLogTrace(_T("scroll"), _T("refreshing everything"));
1076 rect
= rectTotal
? *rectTotal
: wxRect(0, 0, sizeTotal
.x
, sizeTotal
.y
);
1078 else // move the part which doesn't change to the new location
1080 // note that when we scroll the canvas in some direction we move the
1081 // block which doesn't need to be refreshed in the opposite direction
1085 // scroll to the right, move to the left
1090 // scroll to the left, move to the right
1096 // scroll down, move up
1101 // scroll up, move down
1106 // we need to hide the caret before moving or it will erase itself at
1107 // the wrong (old) location
1108 wxCaret
*caret
= GetCaret();
1111 #endif // wxUSE_CARET
1114 wxClientDC
dc(this);
1115 wxBitmap
bmp(size
.x
, size
.y
);
1117 dcMem
.SelectObject(bmp
);
1119 dcMem
.Blit(wxPoint(0, 0), size
, &dc
, ptSource
1120 #if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
1121 + GetClientAreaOrigin()
1122 #endif // broken wxGTK wxDC::Blit
1124 dc
.Blit(ptDest
, size
, &dcMem
, wxPoint(0, 0));
1126 wxLogTrace(_T("scroll"),
1127 _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
1128 ptSource
.x
, ptSource
.y
,
1130 ptDest
.x
, ptDest
.y
);
1132 // and now repaint the uncovered area
1134 // FIXME: We repaint the intersection of these rectangles twice - is
1135 // it bad? I don't think so as it is rare to scroll the window
1136 // diagonally anyhow and so adding extra logic to compute
1137 // rectangle intersection is probably not worth the effort
1139 rect
.x
= ptSource
.x
;
1140 rect
.y
= ptSource
.y
;
1146 // refresh the area along the right border
1147 rect
.x
+= size
.x
+ dx
;
1152 // refresh the area along the left border
1156 rect
.height
= sizeTotal
.y
;
1158 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1160 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1167 // refresh the area along the bottom border
1168 rect
.y
+= size
.y
+ dy
;
1173 // refresh the area along the top border
1177 rect
.width
= sizeTotal
.x
;
1179 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1181 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1187 #endif // wxUSE_CARET
1193 // ----------------------------------------------------------------------------
1194 // accelerators and menu hot keys
1195 // ----------------------------------------------------------------------------
1198 // the last window over which Alt was pressed (used by OnKeyUp)
1199 wxWindow
*wxWindow::ms_winLastAltPress
= NULL
;
1200 #endif // wxUSE_MENUS
1202 #if wxUSE_ACCEL || wxUSE_MENUS
1204 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1207 int key
= event
.GetKeyCode();
1208 if ( !event
.ControlDown() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1210 ms_winLastAltPress
= this;
1212 // it can't be an accel anyhow
1216 ms_winLastAltPress
= NULL
;
1217 #endif // wxUSE_MENUS
1220 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
1222 int command
= win
->GetAcceleratorTable()->GetCommand(event
);
1223 if ( command
!= -1 )
1225 wxCommandEvent
eventCmd(wxEVT_COMMAND_MENU_SELECTED
, command
);
1226 if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) )
1228 // skip "event.Skip()" below
1233 if ( win
->IsTopLevel() )
1235 // try the frame menu bar
1237 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1240 wxMenuBar
*menubar
= frame
->GetMenuBar();
1241 if ( menubar
&& menubar
->ProcessAccelEvent(event
) )
1243 // skip "event.Skip()" below
1247 #endif // wxUSE_MENUS
1249 // if it wasn't in a menu, try to find a button
1250 if ( command
!= -1 )
1252 wxWindow
* child
= win
->FindWindow(command
);
1253 if ( child
&& wxDynamicCast(child
, wxButton
) )
1255 wxCommandEvent
eventCmd(wxEVT_COMMAND_BUTTON_CLICKED
, command
);
1256 eventCmd
.SetEventObject(child
);
1257 if ( child
->GetEventHandler()->ProcessEvent(eventCmd
) )
1259 // skip "event.Skip()" below
1265 // don't propagate accels from the child frame to the parent one
1269 #endif // wxUSE_ACCEL
1274 #endif // wxUSE_ACCEL
1278 wxMenuBar
*wxWindow::GetParentFrameMenuBar() const
1280 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
1282 if ( win
->IsTopLevel() )
1284 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1287 return frame
->GetMenuBar();
1290 // don't look further - we don't want to return the menubar of the
1299 void wxWindow::OnChar(wxKeyEvent
& event
)
1301 if ( event
.AltDown() && !event
.ControlDown() )
1303 int key
= event
.GetKeyCode();
1305 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1308 int item
= menubar
->FindNextItemForAccel(-1, key
);
1311 menubar
->PopupMenu((size_t)item
);
1313 // skip "event.Skip()" below
1322 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1324 int key
= event
.GetKeyCode();
1325 if ( !event
.HasModifiers() && (key
== WXK_MENU
|| key
== WXK_F10
) )
1327 // only process Alt release specially if there were no other key
1328 // presses since Alt had been pressed and if both events happened in
1330 if ( ms_winLastAltPress
== this )
1332 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1333 if ( menubar
&& this != menubar
)
1335 menubar
->SelectMenu(0);
1344 // in any case reset it
1345 ms_winLastAltPress
= NULL
;
1348 #endif // wxUSE_MENUS
1350 // ----------------------------------------------------------------------------
1351 // MSW-specific section
1352 // ----------------------------------------------------------------------------
1356 #include "wx/msw/private.h"
1358 long wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1360 if ( message
== WM_NCHITTEST
)
1362 // the windows which contain the other windows should let the mouse
1363 // events through, otherwise a window inside a static box would
1364 // never get any events at all
1365 if ( IsStaticBox() )
1367 return HTTRANSPARENT
;
1371 return wxWindowNative::MSWWindowProc(message
, wParam
, lParam
);