1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/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 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/window.h"
31 #include "wx/dcclient.h"
32 #include "wx/dcmemory.h"
34 #include "wx/scrolbar.h"
40 #include "wx/univ/colschem.h"
41 #include "wx/univ/renderer.h"
42 #include "wx/univ/theme.h"
48 // turn Refresh() debugging on/off
49 #define WXDEBUG_REFRESH
52 #undef WXDEBUG_REFRESH
55 #if defined(WXDEBUG_REFRESH) && defined(__WXMSW__) && !defined(__WXMICROWIN__)
56 #include "wx/msw/private.h"
59 // ============================================================================
61 // ============================================================================
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 // we can't use wxWindowNative here as it won't be expanded inside the macro
68 #if defined(__WXMSW__)
69 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowMSW
)
70 #elif defined(__WXGTK__)
71 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowGTK
)
72 #elif defined(__WXMGL__)
73 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowMGL
)
74 #elif defined(__WXX11__)
75 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowX11
)
76 #elif defined(__WXPM__)
77 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowOS2
)
80 BEGIN_EVENT_TABLE(wxWindow
, wxWindowNative
)
81 EVT_SIZE(wxWindow::OnSize
)
83 #if wxUSE_ACCEL || wxUSE_MENUS
84 EVT_KEY_DOWN(wxWindow::OnKeyDown
)
88 EVT_CHAR(wxWindow::OnChar
)
89 EVT_KEY_UP(wxWindow::OnKeyUp
)
92 EVT_PAINT(wxWindow::OnPaint
)
93 EVT_NC_PAINT(wxWindow::OnNcPaint
)
94 EVT_ERASE_BACKGROUND(wxWindow::OnErase
)
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 void wxWindow::Init()
104 m_scrollbarHorz
= (wxScrollBar
*)NULL
;
108 m_renderer
= wxTheme::Get()->GetRenderer();
110 m_oldSize
.x
= wxDefaultCoord
;
111 m_oldSize
.y
= wxDefaultCoord
;
114 bool wxWindow::Create(wxWindow
*parent
,
119 const wxString
& name
)
121 long actualStyle
= style
;
123 // FIXME: may need this on other platforms
125 actualStyle
&= ~wxVSCROLL
;
126 actualStyle
&= ~wxHSCROLL
;
129 // we add wxCLIP_CHILDREN to get the same ("natural") behaviour under MSW
130 // as under the other platforms
131 if ( !wxWindowNative::Create(parent
, id
, pos
, size
,
132 actualStyle
| wxCLIP_CHILDREN
,
138 // Set full style again, including those we didn't want present
139 // when calling the base window Create().
140 wxWindowBase::SetWindowStyleFlag(style
);
142 // if we allow or should always have a vertical scrollbar, make it
143 if ( style
& wxVSCROLL
|| style
& wxALWAYS_SHOW_SB
)
145 #if wxUSE_TWO_WINDOWS
146 SetInsertIntoMain( true );
148 m_scrollbarVert
= new wxScrollBar(this, wxID_ANY
,
149 wxDefaultPosition
, wxDefaultSize
,
151 #if wxUSE_TWO_WINDOWS
152 SetInsertIntoMain( false );
156 // if we should allow a horizontal scrollbar, make it
157 if ( style
& wxHSCROLL
)
159 #if wxUSE_TWO_WINDOWS
160 SetInsertIntoMain( true );
162 m_scrollbarHorz
= new wxScrollBar(this, wxID_ANY
,
163 wxDefaultPosition
, wxDefaultSize
,
165 #if wxUSE_TWO_WINDOWS
166 SetInsertIntoMain( false );
170 if (m_scrollbarHorz
|| m_scrollbarVert
)
173 PositionScrollbars();
179 wxWindow::~wxWindow()
181 m_isBeingDeleted
= true;
183 // we have to destroy our children before we're destroyed because our
184 // children suppose that we're of type wxWindow, not just wxWindowNative,
185 // and so bad things may happen if they're deleted from the base class dtor
186 // as by then we're not a wxWindow any longer and wxUniv-specific virtual
187 // functions can't be called
191 // ----------------------------------------------------------------------------
193 // ----------------------------------------------------------------------------
195 void wxWindow::SetBackground(const wxBitmap
& bitmap
,
200 m_alignBgBitmap
= alignment
;
201 m_stretchBgBitmap
= stretch
;
204 const wxBitmap
& wxWindow::GetBackgroundBitmap(int *alignment
,
205 wxStretch
*stretch
) const
207 if ( m_bitmapBg
.Ok() )
210 *alignment
= m_alignBgBitmap
;
212 *stretch
= m_stretchBgBitmap
;
218 // ----------------------------------------------------------------------------
220 // ----------------------------------------------------------------------------
222 // the event handlers executed when the window must be repainted
223 void wxWindow::OnNcPaint(wxNcPaintEvent
& WXUNUSED(event
))
227 // get the window rect
229 wxSize size
= GetSize();
233 rect
.height
= size
.y
;
235 // if the scrollbars are outside the border, we must adjust the rect to
237 if ( !m_renderer
->AreScrollbarsInsideBorder() )
239 wxScrollBar
*scrollbar
= GetScrollbar(wxVERTICAL
);
241 rect
.width
-= scrollbar
->GetSize().x
;
243 scrollbar
= GetScrollbar(wxHORIZONTAL
);
245 rect
.height
-= scrollbar
->GetSize().y
;
248 // get the DC and draw the border on it
250 DoDrawBorder(dc
, rect
);
254 void wxWindow::OnPaint(wxPaintEvent
& event
)
258 // it is a native control which paints itself
263 // get the DC to use and create renderer on it
265 wxControlRenderer
renderer(this, dc
, m_renderer
);
272 // the event handler executed when the window background must be painted
273 void wxWindow::OnErase(wxEraseEvent
& event
)
282 DoDrawBackground(*event
.GetDC());
284 // if we have both scrollbars, we also have a square in the corner between
285 // them which we must paint
286 if ( m_scrollbarVert
&& m_scrollbarHorz
)
288 wxSize size
= GetSize();
289 wxRect rectClient
= GetClientRect(),
290 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
293 rectCorner
.x
= rectClient
.GetRight() + 1;
294 rectCorner
.y
= rectClient
.GetBottom() + 1;
295 rectCorner
.SetRight(size
.x
- rectBorder
.width
);
296 rectCorner
.SetBottom(size
.y
- rectBorder
.height
);
298 if ( GetUpdateRegion().Contains(rectCorner
) )
300 m_renderer
->DrawScrollCorner(*event
.GetDC(), rectCorner
);
305 bool wxWindow::DoDrawBackground(wxDC
& dc
)
309 wxSize size
= GetSize(); // Why not GetClientSize() ?
313 rect
.height
= size
.y
;
315 wxWindow
* const parent
= GetParent();
316 if ( HasTransparentBackground() && parent
)
318 wxASSERT( !IsTopLevel() );
320 wxPoint pos
= GetPosition();
322 AdjustForParentClientOrigin( pos
.x
, pos
.y
, 0 );
324 // Adjust DC logical origin
325 wxCoord org_x
, org_y
, x
, y
;
326 dc
.GetLogicalOrigin( &org_x
, &org_y
);
329 dc
.SetLogicalOrigin( x
, y
);
335 // Let parent draw the background
336 parent
->EraseBackground( dc
, rect
);
338 // Restore DC logical origin
339 dc
.SetLogicalOrigin( org_x
, org_y
);
343 // Draw background ourselves
344 EraseBackground( dc
, rect
);
350 void wxWindow::EraseBackground(wxDC
& dc
, const wxRect
& rect
)
352 if ( GetBackgroundBitmap().Ok() )
354 // Get the bitmap and the flags
357 wxBitmap bmp
= GetBackgroundBitmap(&alignment
, &stretch
);
358 wxControlRenderer::DrawBitmap(dc
, bmp
, rect
, alignment
, stretch
);
362 // Just fill it with bg colour if no bitmap
364 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this),
365 rect
, GetStateFlags());
369 void wxWindow::DoDrawBorder(wxDC
& dc
, const wxRect
& rect
)
371 // draw outline unless the update region is enitrely inside it in which
372 // case we don't need to do it
373 #if 0 // doesn't seem to work, why?
374 if ( wxRegion(rect
).Contains(GetUpdateRegion().GetBox()) != wxInRegion
)
377 m_renderer
->DrawBorder(dc
, GetBorder(), rect
, GetStateFlags());
381 void wxWindow::DoDraw(wxControlRenderer
* WXUNUSED(renderer
))
385 void wxWindow::Refresh(bool eraseBackground
, const wxRect
*rectClient
)
388 wxPoint pt
= GetClientAreaOrigin();
390 wxSize size
= GetClientSize();
394 rectWin
= *rectClient
;
396 // don't refresh anything beyond the client area (scrollbars for
398 if ( rectWin
.GetRight() > size
.x
)
399 rectWin
.SetRight(size
.x
);
400 if ( rectWin
.GetBottom() > size
.y
)
401 rectWin
.SetBottom(size
.y
);
405 else // refresh the entire client area
409 rectWin
.width
= size
.x
;
410 rectWin
.height
= size
.y
;
414 #ifdef WXDEBUG_REFRESH
415 static bool s_refreshDebug
= false;
416 if ( s_refreshDebug
)
419 dc
.SetBrush(*wxCYAN_BRUSH
);
420 dc
.SetPen(*wxTRANSPARENT_PEN
);
421 dc
.DrawRectangle(rectWin
);
423 // under Unix we use "--sync" X option for this
424 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
429 #endif // WXDEBUG_REFRESH
431 wxWindowNative::Refresh(eraseBackground
, &rectWin
);
433 // Refresh all sub controls if any.
434 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
437 wxWindow
*win
= node
->GetData();
438 // Only refresh sub controls when it is visible
439 // and when it is in the update region.
440 if(!win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)) && win
->IsShown() && wxRegion(rectWin
).Contains(win
->GetRect()) != wxOutRegion
)
441 win
->Refresh(eraseBackground
, &rectWin
);
443 node
= node
->GetNext();
447 // ----------------------------------------------------------------------------
449 // ----------------------------------------------------------------------------
451 bool wxWindow::Enable(bool enable
)
453 if ( !wxWindowNative::Enable(enable
) )
456 // disabled window can't keep focus
457 if ( FindFocus() == this && GetParent() != NULL
)
459 GetParent()->SetFocus();
464 // a window with renderer is drawn by ourselves and it has to be
465 // refreshed to reflect its new status
472 bool wxWindow::IsFocused() const
474 wxWindow
*self
= wxConstCast(this, wxWindow
);
475 return self
->FindFocus() == self
;
478 bool wxWindow::IsPressed() const
483 bool wxWindow::IsDefault() const
488 bool wxWindow::IsCurrent() const
493 bool wxWindow::SetCurrent(bool doit
)
495 if ( doit
== m_isCurrent
)
500 if ( CanBeHighlighted() )
506 int wxWindow::GetStateFlags() const
510 flags
|= wxCONTROL_DISABLED
;
512 // the following states are only possible if our application is active - if
513 // it is not, even our default/focused controls shouldn't appear as such
514 if ( wxTheApp
->IsActive() )
517 flags
|= wxCONTROL_CURRENT
;
519 flags
|= wxCONTROL_FOCUSED
;
521 flags
|= wxCONTROL_PRESSED
;
523 flags
|= wxCONTROL_ISDEFAULT
;
529 // ----------------------------------------------------------------------------
531 // ----------------------------------------------------------------------------
533 void wxWindow::OnSize(wxSizeEvent
& event
)
537 if ( m_scrollbarVert
|| m_scrollbarHorz
)
539 PositionScrollbars();
542 #if 0 // ndef __WXMSW__
543 // Refresh the area (strip) previously occupied by the border
545 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) && IsShown() )
547 // This code assumes that wxSizeEvent.GetSize() returns
548 // the area of the entire window, not just the client
550 wxSize newSize
= event
.GetSize();
552 if (m_oldSize
.x
== wxDefaultCoord
&& m_oldSize
.y
== wxDefaultCoord
)
558 if (HasFlag( wxSIMPLE_BORDER
))
560 if (newSize
.y
> m_oldSize
.y
)
564 rect
.width
= m_oldSize
.x
;
565 rect
.y
= m_oldSize
.y
-2;
567 Refresh( true, &rect
);
569 else if (newSize
.y
< m_oldSize
.y
)
575 rect
.width
= newSize
.x
;
576 wxWindowNative::Refresh( true, &rect
);
579 if (newSize
.x
> m_oldSize
.x
)
583 rect
.height
= m_oldSize
.y
;
584 rect
.x
= m_oldSize
.x
-2;
586 Refresh( true, &rect
);
588 else if (newSize
.x
< m_oldSize
.x
)
594 rect
.height
= newSize
.y
;
595 wxWindowNative::Refresh( true, &rect
);
599 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
601 if (newSize
.y
> m_oldSize
.y
)
605 rect
.width
= m_oldSize
.x
;
606 rect
.y
= m_oldSize
.y
-4;
608 Refresh( true, &rect
);
610 else if (newSize
.y
< m_oldSize
.y
)
616 rect
.width
= newSize
.x
;
617 wxWindowNative::Refresh( true, &rect
);
620 if (newSize
.x
> m_oldSize
.x
)
624 rect
.height
= m_oldSize
.y
;
625 rect
.x
= m_oldSize
.x
-4;
627 Refresh( true, &rect
);
629 else if (newSize
.x
< m_oldSize
.x
)
635 rect
.height
= newSize
.y
;
636 wxWindowNative::Refresh( true, &rect
);
645 wxSize
wxWindow::DoGetBestSize() const
647 return AdjustSize(DoGetBestClientSize());
650 wxSize
wxWindow::DoGetBestClientSize() const
652 return wxWindowNative::DoGetBestSize();
655 wxSize
wxWindow::AdjustSize(const wxSize
& size
) const
659 m_renderer
->AdjustSize(&sz
, this);
663 wxPoint
wxWindow::GetClientAreaOrigin() const
665 wxPoint pt
= wxWindowBase::GetClientAreaOrigin();
667 #if wxUSE_TWO_WINDOWS
670 pt
+= m_renderer
->GetBorderDimensions(GetBorder()).GetPosition();
676 void wxWindow::DoGetClientSize(int *width
, int *height
) const
678 // if it is a native window, we assume it handles the scrollbars itself
679 // too - and if it doesn't, there is not much we can do
682 wxWindowNative::DoGetClientSize(width
, height
);
688 wxWindowNative::DoGetClientSize(&w
, &h
);
690 // we assume that the scrollbars are positioned correctly (by a previous
691 // call to PositionScrollbars()) here
695 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
697 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
701 // in any case, take account of the scrollbar
702 if ( m_scrollbarVert
)
703 w
-= m_scrollbarVert
->GetSize().x
;
705 // if we don't have scrollbar or if it is outside the border (and not
706 // blended into it), take account of the right border as well
707 if ( !m_scrollbarVert
|| inside
)
708 w
-= rectBorder
.width
;
710 // and always account for the left border
711 *width
= w
- rectBorder
.x
;
713 // we shouldn't return invalid width
720 if ( m_scrollbarHorz
)
721 h
-= m_scrollbarHorz
->GetSize().y
;
723 if ( !m_scrollbarHorz
|| inside
)
724 h
-= rectBorder
.height
;
726 *height
= h
- rectBorder
.y
;
728 // we shouldn't return invalid height
734 void wxWindow::DoSetClientSize(int width
, int height
)
736 // take into account the borders
737 wxRect rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
738 width
+= rectBorder
.x
;
739 height
+= rectBorder
.y
;
741 // and the scrollbars (as they may be offset into the border, use the
742 // scrollbar position, not size - this supposes that PositionScrollbars()
743 // had been called before)
744 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
745 wxSize size
= GetSize();
746 if ( m_scrollbarVert
)
747 width
+= size
.x
- m_scrollbarVert
->GetPosition().x
;
748 if ( !m_scrollbarVert
|| inside
)
749 width
+= rectBorder
.width
;
751 if ( m_scrollbarHorz
)
752 height
+= size
.y
- m_scrollbarHorz
->GetPosition().y
;
753 if ( !m_scrollbarHorz
|| inside
)
754 height
+= rectBorder
.height
;
756 wxWindowNative::DoSetClientSize(width
, height
);
759 wxHitTest
wxWindow::DoHitTest(wxCoord x
, wxCoord y
) const
761 wxHitTest ht
= wxWindowNative::DoHitTest(x
, y
);
762 if ( ht
== wxHT_WINDOW_INSIDE
)
764 if ( m_scrollbarVert
&& x
>= m_scrollbarVert
->GetPosition().x
)
766 // it can still be changed below because it may also be the corner
767 ht
= wxHT_WINDOW_VERT_SCROLLBAR
;
770 if ( m_scrollbarHorz
&& y
>= m_scrollbarHorz
->GetPosition().y
)
772 ht
= ht
== wxHT_WINDOW_VERT_SCROLLBAR
? wxHT_WINDOW_CORNER
773 : wxHT_WINDOW_HORZ_SCROLLBAR
;
780 // ----------------------------------------------------------------------------
781 // scrolling: we implement it entirely ourselves except for ScrollWindow()
782 // function which is supposed to be (efficiently) implemented by the native
784 // ----------------------------------------------------------------------------
786 void wxWindow::RefreshScrollbars()
788 if ( m_scrollbarHorz
)
789 m_scrollbarHorz
->Refresh();
791 if ( m_scrollbarVert
)
792 m_scrollbarVert
->Refresh();
795 void wxWindow::PositionScrollbars()
797 // do not use GetClientSize/Rect as it relies on the scrollbars being
798 // correctly positioned
800 wxSize size
= GetSize();
801 wxBorder border
= GetBorder();
802 wxRect rectBorder
= m_renderer
->GetBorderDimensions(border
);
803 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
805 int height
= m_scrollbarHorz
? m_scrollbarHorz
->GetSize().y
: 0;
806 int width
= m_scrollbarVert
? m_scrollbarVert
->GetSize().x
: 0;
809 if ( m_scrollbarVert
)
811 rectBar
.x
= size
.x
- width
;
813 rectBar
.x
-= rectBorder
.width
;
814 rectBar
.width
= width
;
817 rectBar
.y
+= rectBorder
.y
;
818 rectBar
.height
= size
.y
- height
;
820 rectBar
.height
-= rectBorder
.y
+ rectBorder
.height
;
822 m_scrollbarVert
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
825 if ( m_scrollbarHorz
)
827 rectBar
.y
= size
.y
- height
;
829 rectBar
.y
-= rectBorder
.height
;
830 rectBar
.height
= height
;
833 rectBar
.x
+= rectBorder
.x
;
834 rectBar
.width
= size
.x
- width
;
836 rectBar
.width
-= rectBorder
.x
+ rectBorder
.width
;
838 m_scrollbarHorz
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
844 void wxWindow::SetScrollbar(int orient
,
850 wxASSERT_MSG( pageSize
<= range
,
851 _T("page size can't be greater than range") );
853 bool hasClientSizeChanged
= false;
854 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
855 if ( range
&& (pageSize
< range
) )
860 #if wxUSE_TWO_WINDOWS
861 SetInsertIntoMain( true );
863 scrollbar
= new wxScrollBar(this, wxID_ANY
,
864 wxDefaultPosition
, wxDefaultSize
,
865 orient
& wxVERTICAL
? wxSB_VERTICAL
867 #if wxUSE_TWO_WINDOWS
868 SetInsertIntoMain( false );
870 if ( orient
& wxVERTICAL
)
871 m_scrollbarVert
= scrollbar
;
873 m_scrollbarHorz
= scrollbar
;
875 // the client area diminished as we created a scrollbar
876 hasClientSizeChanged
= true;
878 PositionScrollbars();
880 else if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
882 // we might have disabled it before
886 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
888 else // no range means no scrollbar
892 // wxALWAYS_SHOW_SB only applies to the vertical scrollbar
893 if ( (orient
& wxVERTICAL
) && (GetWindowStyle() & wxALWAYS_SHOW_SB
) )
895 // just disable the scrollbar
896 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
897 scrollbar
->Disable();
899 else // really remove the scrollbar
903 if ( orient
& wxVERTICAL
)
904 m_scrollbarVert
= NULL
;
906 m_scrollbarHorz
= NULL
;
908 // the client area increased as we removed a scrollbar
909 hasClientSizeChanged
= true;
911 // the size of the remaining scrollbar must be adjusted
912 if ( m_scrollbarHorz
|| m_scrollbarVert
)
914 PositionScrollbars();
920 // give the window a chance to relayout
921 if ( hasClientSizeChanged
)
923 #if wxUSE_TWO_WINDOWS
924 wxWindowNative::SetSize( GetSize() );
926 wxSizeEvent
event(GetSize());
927 (void)GetEventHandler()->ProcessEvent(event
);
932 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
934 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
935 wxCHECK_RET( scrollbar
, _T("no scrollbar to set position for") );
937 scrollbar
->SetThumbPosition(pos
);
939 // VZ: I think we can safely ignore this as we always refresh it
940 // automatically whenever the value chanegs
947 int wxWindow::GetScrollPos(int orient
) const
949 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
950 return scrollbar
? scrollbar
->GetThumbPosition() : 0;
953 int wxWindow::GetScrollThumb(int orient
) const
955 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
956 return scrollbar
? scrollbar
->GetThumbSize() : 0;
959 int wxWindow::GetScrollRange(int orient
) const
961 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
962 return scrollbar
? scrollbar
->GetRange() : 0;
965 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
967 // use native scrolling when available and do it in generic way
971 wxWindowNative::ScrollWindow(dx
, dy
, rect
);
975 // before scrolling it, ensure that we don't have any unpainted areas
982 r
= ScrollNoRefresh(dx
, 0, rect
);
983 Refresh(true /* erase bkgnd */, &r
);
988 r
= ScrollNoRefresh(0, dy
, rect
);
989 Refresh(true /* erase bkgnd */, &r
);
992 // scroll children accordingly:
993 wxPoint
offset(dx
, dy
);
995 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
996 node
; node
= node
->GetNext())
998 wxWindow
*child
= node
->GetData();
999 if ( child
== m_scrollbarVert
|| child
== m_scrollbarHorz
)
1002 // VS: Scrolling children has non-trivial semantics. If rect=NULL then
1003 // it is easy: we scroll all children. Otherwise it gets
1005 // 1. if scrolling in one direction only, scroll only
1006 // those children that intersect shaft defined by the rectangle
1007 // and scrolling direction
1008 // 2. if scrolling in both axes, scroll all children
1010 if ( rect
&& (dx
* dy
== 0 /* moving in only one of x, y axis */) )
1012 wxRect childRect
= child
->GetRect();
1013 if ( dx
== 0 && (childRect
.GetLeft() <= rect
->GetRight() ||
1014 childRect
.GetRight() >= rect
->GetLeft()) )
1016 child
->Move(child
->GetPosition() + offset
);
1018 else if ( dy
== 0 && (childRect
.GetTop() <= rect
->GetBottom() ||
1019 childRect
.GetBottom() >= rect
->GetTop()) )
1021 child
->Move(child
->GetPosition() + offset
);
1026 child
->Move(child
->GetPosition() + offset
);
1029 #endif // wxX11/!wxX11
1032 wxRect
wxWindow::ScrollNoRefresh(int dx
, int dy
, const wxRect
*rectTotal
)
1034 wxASSERT_MSG( !dx
|| !dy
, _T("can't be used for diag scrolling") );
1036 // the rect to refresh (which we will calculate)
1045 // calculate the part of the window which we can just redraw in the new
1047 wxSize sizeTotal
= rectTotal
? rectTotal
->GetSize() : GetClientSize();
1049 wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
1050 sizeTotal
.x
, sizeTotal
.y
, dx
, dy
);
1052 // the initial and end point of the region we move in client coords
1053 wxPoint ptSource
, ptDest
;
1056 ptSource
= rectTotal
->GetPosition();
1057 ptDest
= rectTotal
->GetPosition();
1060 // the size of this region
1062 size
.x
= sizeTotal
.x
- abs(dx
);
1063 size
.y
= sizeTotal
.y
- abs(dy
);
1064 if ( size
.x
<= 0 || size
.y
<= 0 )
1066 // just redraw everything as nothing of the displayed image will stay
1067 wxLogTrace(_T("scroll"), _T("refreshing everything"));
1069 rect
= rectTotal
? *rectTotal
: wxRect(0, 0, sizeTotal
.x
, sizeTotal
.y
);
1071 else // move the part which doesn't change to the new location
1073 // note that when we scroll the canvas in some direction we move the
1074 // block which doesn't need to be refreshed in the opposite direction
1078 // scroll to the right, move to the left
1083 // scroll to the left, move to the right
1089 // scroll down, move up
1094 // scroll up, move down
1099 // we need to hide the caret before moving or it will erase itself at
1100 // the wrong (old) location
1101 wxCaret
*caret
= GetCaret();
1104 #endif // wxUSE_CARET
1107 wxClientDC
dc(this);
1108 wxBitmap
bmp(size
.x
, size
.y
);
1110 dcMem
.SelectObject(bmp
);
1112 dcMem
.Blit(wxPoint(0,0), size
, &dc
, ptSource
1113 #if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
1114 + GetClientAreaOrigin()
1115 #endif // broken wxGTK wxDC::Blit
1117 dc
.Blit(ptDest
, size
, &dcMem
, wxPoint(0,0));
1119 wxLogTrace(_T("scroll"),
1120 _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
1121 ptSource
.x
, ptSource
.y
,
1123 ptDest
.x
, ptDest
.y
);
1125 // and now repaint the uncovered area
1127 // FIXME: We repaint the intersection of these rectangles twice - is
1128 // it bad? I don't think so as it is rare to scroll the window
1129 // diagonally anyhow and so adding extra logic to compute
1130 // rectangle intersection is probably not worth the effort
1132 rect
.x
= ptSource
.x
;
1133 rect
.y
= ptSource
.y
;
1139 // refresh the area along the right border
1140 rect
.x
+= size
.x
+ dx
;
1145 // refresh the area along the left border
1149 rect
.height
= sizeTotal
.y
;
1151 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1153 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1160 // refresh the area along the bottom border
1161 rect
.y
+= size
.y
+ dy
;
1166 // refresh the area along the top border
1170 rect
.width
= sizeTotal
.x
;
1172 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1174 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1180 #endif // wxUSE_CARET
1186 // ----------------------------------------------------------------------------
1187 // accelerators and menu hot keys
1188 // ----------------------------------------------------------------------------
1191 // the last window over which Alt was pressed (used by OnKeyUp)
1192 wxWindow
*wxWindow::ms_winLastAltPress
= NULL
;
1193 #endif // wxUSE_MENUS
1195 #if wxUSE_ACCEL || wxUSE_MENUS
1197 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1200 int key
= event
.GetKeyCode();
1201 if ( !event
.ControlDown() && (key
== WXK_ALT
|| key
== WXK_F10
) )
1203 ms_winLastAltPress
= this;
1205 // it can't be an accel anyhow
1209 ms_winLastAltPress
= NULL
;
1210 #endif // wxUSE_MENUS
1213 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
1215 int command
= win
->GetAcceleratorTable()->GetCommand(event
);
1216 if ( command
!= -1 )
1218 wxCommandEvent
eventCmd(wxEVT_COMMAND_MENU_SELECTED
, command
);
1219 if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) )
1221 // skip "event.Skip()" below
1226 if ( win
->IsTopLevel() )
1228 // try the frame menu bar
1230 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1233 wxMenuBar
*menubar
= frame
->GetMenuBar();
1234 if ( menubar
&& menubar
->ProcessAccelEvent(event
) )
1236 // skip "event.Skip()" below
1240 #endif // wxUSE_MENUS
1242 // if it wasn't in a menu, try to find a button
1243 if ( command
!= -1 )
1245 wxWindow
* child
= win
->FindWindow(command
);
1246 if ( child
&& wxDynamicCast(child
, wxButton
) )
1248 wxCommandEvent
eventCmd(wxEVT_COMMAND_BUTTON_CLICKED
, command
);
1249 eventCmd
.SetEventObject(child
);
1250 if ( child
->GetEventHandler()->ProcessEvent(eventCmd
) )
1252 // skip "event.Skip()" below
1258 // don't propagate accels from the child frame to the parent one
1262 #endif // wxUSE_ACCEL
1267 #endif // wxUSE_ACCEL
1271 wxMenuBar
*wxWindow::GetParentFrameMenuBar() const
1273 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
1275 if ( win
->IsTopLevel() )
1277 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1280 return frame
->GetMenuBar();
1283 // don't look further - we don't want to return the menubar of the
1292 void wxWindow::OnChar(wxKeyEvent
& event
)
1294 if ( event
.AltDown() && !event
.ControlDown() )
1296 int key
= event
.GetKeyCode();
1298 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1301 int item
= menubar
->FindNextItemForAccel(-1, key
);
1304 menubar
->PopupMenu((size_t)item
);
1306 // skip "event.Skip()" below
1315 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1317 int key
= event
.GetKeyCode();
1318 if ( !event
.HasModifiers() && (key
== WXK_ALT
|| key
== WXK_F10
) )
1320 // only process Alt release specially if there were no other key
1321 // presses since Alt had been pressed and if both events happened in
1323 if ( ms_winLastAltPress
== this )
1325 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1326 if ( menubar
&& this != menubar
)
1328 menubar
->SelectMenu(0);
1337 // in any case reset it
1338 ms_winLastAltPress
= NULL
;
1341 #endif // wxUSE_MENUS
1343 // ----------------------------------------------------------------------------
1344 // MSW-specific section
1345 // ----------------------------------------------------------------------------
1349 #include "wx/msw/private.h"
1351 WXLRESULT
wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1353 if ( message
== WM_NCHITTEST
)
1355 // the windows which contain the other windows should let the mouse
1356 // events through, otherwise a window inside a static box would
1357 // never get any events at all
1358 if ( IsStaticBox() )
1360 return HTTRANSPARENT
;
1364 return wxWindowNative::MSWWindowProc(message
, wParam
, lParam
);