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(__WXDFB__)
75 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowDFB
)
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()
107 m_scrollbarHorz
= (wxScrollBar
*)NULL
;
108 #endif // wxUSE_SCROLLBAR
112 m_renderer
= wxTheme::Get()->GetRenderer();
114 m_oldSize
.x
= wxDefaultCoord
;
115 m_oldSize
.y
= wxDefaultCoord
;
118 bool wxWindow::Create(wxWindow
*parent
,
123 const wxString
& name
)
125 long actualStyle
= style
;
127 // FIXME: may need this on other platforms
129 actualStyle
&= ~wxVSCROLL
;
130 actualStyle
&= ~wxHSCROLL
;
133 // we add wxCLIP_CHILDREN to get the same ("natural") behaviour under MSW
134 // as under the other platforms
135 if ( !wxWindowNative::Create(parent
, id
, pos
, size
,
136 actualStyle
| wxCLIP_CHILDREN
,
142 // Set full style again, including those we didn't want present
143 // when calling the base window Create().
144 wxWindowBase::SetWindowStyleFlag(style
);
146 // if we allow or should always have a vertical scrollbar, make it
147 if ( style
& wxVSCROLL
|| style
& wxALWAYS_SHOW_SB
)
149 #if wxUSE_TWO_WINDOWS
150 SetInsertIntoMain( true );
153 m_scrollbarVert
= new wxScrollBar(this, wxID_ANY
,
154 wxDefaultPosition
, wxDefaultSize
,
156 #endif // wxUSE_SCROLLBAR
157 #if wxUSE_TWO_WINDOWS
158 SetInsertIntoMain( false );
162 // if we should allow a horizontal scrollbar, make it
163 if ( style
& wxHSCROLL
)
165 #if wxUSE_TWO_WINDOWS
166 SetInsertIntoMain( true );
169 m_scrollbarHorz
= new wxScrollBar(this, wxID_ANY
,
170 wxDefaultPosition
, wxDefaultSize
,
172 #endif // wxUSE_SCROLLBAR
173 #if wxUSE_TWO_WINDOWS
174 SetInsertIntoMain( false );
179 if (m_scrollbarHorz
|| m_scrollbarVert
)
182 PositionScrollbars();
184 #endif // wxUSE_SCROLLBAR
189 wxWindow::~wxWindow()
191 m_isBeingDeleted
= true;
193 // we have to destroy our children before we're destroyed because our
194 // children suppose that we're of type wxWindow, not just wxWindowNative,
195 // and so bad things may happen if they're deleted from the base class dtor
196 // as by then we're not a wxWindow any longer and wxUniv-specific virtual
197 // functions can't be called
201 // ----------------------------------------------------------------------------
203 // ----------------------------------------------------------------------------
205 void wxWindow::SetBackground(const wxBitmap
& bitmap
,
210 m_alignBgBitmap
= alignment
;
211 m_stretchBgBitmap
= stretch
;
214 const wxBitmap
& wxWindow::GetBackgroundBitmap(int *alignment
,
215 wxStretch
*stretch
) const
217 if ( m_bitmapBg
.Ok() )
220 *alignment
= m_alignBgBitmap
;
222 *stretch
= m_stretchBgBitmap
;
228 // ----------------------------------------------------------------------------
230 // ----------------------------------------------------------------------------
232 // the event handlers executed when the window must be repainted
233 void wxWindow::OnNcPaint(wxNcPaintEvent
& WXUNUSED(event
))
237 // get the window rect
238 wxRect
rect(GetSize());
241 // if the scrollbars are outside the border, we must adjust the rect to
243 if ( !m_renderer
->AreScrollbarsInsideBorder() )
245 wxScrollBar
*scrollbar
= GetScrollbar(wxVERTICAL
);
247 rect
.width
-= scrollbar
->GetSize().x
;
249 scrollbar
= GetScrollbar(wxHORIZONTAL
);
251 rect
.height
-= scrollbar
->GetSize().y
;
253 #endif // wxUSE_SCROLLBAR
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());
292 // if we have both scrollbars, we also have a square in the corner between
293 // them which we must paint
294 if ( m_scrollbarVert
&& m_scrollbarHorz
)
296 wxSize size
= GetSize();
297 wxRect rectClient
= GetClientRect(),
298 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
301 rectCorner
.x
= rectClient
.GetRight() + 1;
302 rectCorner
.y
= rectClient
.GetBottom() + 1;
303 rectCorner
.SetRight(size
.x
- rectBorder
.width
);
304 rectCorner
.SetBottom(size
.y
- rectBorder
.height
);
306 if ( GetUpdateRegion().Contains(rectCorner
) )
308 m_renderer
->DrawScrollCorner(*event
.GetDC(), rectCorner
);
311 #endif // wxUSE_SCROLLBAR
314 bool wxWindow::DoDrawBackground(wxDC
& dc
)
318 wxSize size
= GetSize(); // Why not GetClientSize() ?
322 rect
.height
= size
.y
;
324 wxWindow
* const parent
= GetParent();
325 if ( HasTransparentBackground() && parent
)
327 wxASSERT( !IsTopLevel() );
329 wxPoint pos
= GetPosition();
331 AdjustForParentClientOrigin( pos
.x
, pos
.y
, 0 );
333 // Adjust DC logical origin
334 wxCoord org_x
, org_y
, x
, y
;
335 dc
.GetLogicalOrigin( &org_x
, &org_y
);
338 dc
.SetLogicalOrigin( x
, y
);
344 // Let parent draw the background
345 parent
->EraseBackground( dc
, rect
);
347 // Restore DC logical origin
348 dc
.SetLogicalOrigin( org_x
, org_y
);
352 // Draw background ourselves
353 EraseBackground( dc
, rect
);
359 void wxWindow::EraseBackground(wxDC
& dc
, const wxRect
& rect
)
361 if ( GetBackgroundBitmap().Ok() )
363 // Get the bitmap and the flags
366 wxBitmap bmp
= GetBackgroundBitmap(&alignment
, &stretch
);
367 wxControlRenderer::DrawBitmap(dc
, bmp
, rect
, alignment
, stretch
);
371 // Just fill it with bg colour if no bitmap
373 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this),
374 rect
, GetStateFlags());
378 void wxWindow::DoDrawBorder(wxDC
& dc
, const wxRect
& rect
)
380 // draw outline unless the update region is enitrely inside it in which
381 // case we don't need to do it
382 #if 0 // doesn't seem to work, why?
383 if ( wxRegion(rect
).Contains(GetUpdateRegion().GetBox()) != wxInRegion
)
386 m_renderer
->DrawBorder(dc
, GetBorder(), rect
, GetStateFlags());
390 void wxWindow::DoDraw(wxControlRenderer
* WXUNUSED(renderer
))
394 void wxWindow::Refresh(bool eraseBackground
, const wxRect
*rect
)
396 wxRect rectClient
; // the same rectangle in client coordinates
397 wxPoint origin
= GetClientAreaOrigin();
399 wxSize size
= GetClientSize();
403 // the rectangle passed as argument is in client coordinates
406 // don't refresh anything beyond the client area (scrollbars for
408 if ( rectClient
.GetRight() > size
.x
)
409 rectClient
.SetRight(size
.x
);
410 if ( rectClient
.GetBottom() > size
.y
)
411 rectClient
.SetBottom(size
.y
);
414 else // refresh the entire client area
416 // x,y is already set to 0 by default
417 rectClient
.SetSize(size
);
420 // convert refresh rectangle to window coordinates:
421 wxRect
rectWin(rectClient
);
422 rectWin
.Offset(origin
);
425 #ifdef WXDEBUG_REFRESH
426 static bool s_refreshDebug
= false;
427 if ( s_refreshDebug
)
430 dc
.SetBrush(*wxCYAN_BRUSH
);
431 dc
.SetPen(*wxTRANSPARENT_PEN
);
432 dc
.DrawRectangle(rectWin
);
434 // under Unix we use "--sync" X option for this
435 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
440 #endif // WXDEBUG_REFRESH
442 wxWindowNative::Refresh(eraseBackground
, &rectWin
);
444 // Refresh all sub controls if any.
445 wxWindowList
& children
= GetChildren();
446 for ( wxWindowList::iterator i
= children
.begin(); i
!= children
.end(); ++i
)
448 wxWindow
*child
= *i
;
449 // only refresh subcontrols if they are visible:
450 if ( child
->IsTopLevel() || !child
->IsShown() || child
->IsFrozen() )
453 // ...and when the subcontrols are in the update region:
454 wxRect
childrect(child
->GetRect());
455 childrect
.Intersect(rectClient
);
456 if ( childrect
.IsEmpty() )
459 // refresh the subcontrol now:
460 childrect
.Offset(-child
->GetPosition());
461 // NB: We must call wxWindowNative version because we need to refresh
462 // the entire control, not just its client area, and this is why we
463 // don't account for child client area origin here neither. Also
464 // note that we don't pass eraseBackground to the child, but use
465 // true instead: this is because we can't be sure that
466 // eraseBackground=false is safe for children as well and not only
468 child
->wxWindowNative::Refresh(eraseBackground
, &childrect
);
472 // ----------------------------------------------------------------------------
474 // ----------------------------------------------------------------------------
476 bool wxWindow::Enable(bool enable
)
478 if ( !wxWindowNative::Enable(enable
) )
481 // disabled window can't keep focus
482 if ( FindFocus() == this && GetParent() != NULL
)
484 GetParent()->SetFocus();
489 // a window with renderer is drawn by ourselves and it has to be
490 // refreshed to reflect its new status
497 bool wxWindow::IsFocused() const
499 return FindFocus() == this;
502 bool wxWindow::IsPressed() const
507 bool wxWindow::IsDefault() const
512 bool wxWindow::IsCurrent() const
517 bool wxWindow::SetCurrent(bool doit
)
519 if ( doit
== m_isCurrent
)
524 if ( CanBeHighlighted() )
530 int wxWindow::GetStateFlags() const
534 flags
|= wxCONTROL_DISABLED
;
536 // the following states are only possible if our application is active - if
537 // it is not, even our default/focused controls shouldn't appear as such
538 if ( wxTheApp
->IsActive() )
541 flags
|= wxCONTROL_CURRENT
;
543 flags
|= wxCONTROL_FOCUSED
;
545 flags
|= wxCONTROL_PRESSED
;
547 flags
|= wxCONTROL_ISDEFAULT
;
553 // ----------------------------------------------------------------------------
555 // ----------------------------------------------------------------------------
557 void wxWindow::OnSize(wxSizeEvent
& event
)
562 if ( m_scrollbarVert
|| m_scrollbarHorz
)
564 PositionScrollbars();
566 #endif // wxUSE_SCROLLBAR
568 #if 0 // ndef __WXMSW__
569 // Refresh the area (strip) previously occupied by the border
571 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) && IsShown() )
573 // This code assumes that wxSizeEvent.GetSize() returns
574 // the area of the entire window, not just the client
576 wxSize newSize
= event
.GetSize();
578 if (m_oldSize
.x
== wxDefaultCoord
&& m_oldSize
.y
== wxDefaultCoord
)
584 if (HasFlag( wxSIMPLE_BORDER
))
586 if (newSize
.y
> m_oldSize
.y
)
590 rect
.width
= m_oldSize
.x
;
591 rect
.y
= m_oldSize
.y
-2;
593 Refresh( true, &rect
);
595 else if (newSize
.y
< m_oldSize
.y
)
601 rect
.width
= newSize
.x
;
602 wxWindowNative::Refresh( true, &rect
);
605 if (newSize
.x
> m_oldSize
.x
)
609 rect
.height
= m_oldSize
.y
;
610 rect
.x
= m_oldSize
.x
-2;
612 Refresh( true, &rect
);
614 else if (newSize
.x
< m_oldSize
.x
)
620 rect
.height
= newSize
.y
;
621 wxWindowNative::Refresh( true, &rect
);
625 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
627 if (newSize
.y
> m_oldSize
.y
)
631 rect
.width
= m_oldSize
.x
;
632 rect
.y
= m_oldSize
.y
-4;
634 Refresh( true, &rect
);
636 else if (newSize
.y
< m_oldSize
.y
)
642 rect
.width
= newSize
.x
;
643 wxWindowNative::Refresh( true, &rect
);
646 if (newSize
.x
> m_oldSize
.x
)
650 rect
.height
= m_oldSize
.y
;
651 rect
.x
= m_oldSize
.x
-4;
653 Refresh( true, &rect
);
655 else if (newSize
.x
< m_oldSize
.x
)
661 rect
.height
= newSize
.y
;
662 wxWindowNative::Refresh( true, &rect
);
671 wxSize
wxWindow::DoGetBestSize() const
673 return AdjustSize(DoGetBestClientSize());
676 wxSize
wxWindow::DoGetBestClientSize() const
678 return wxWindowNative::DoGetBestSize();
681 wxSize
wxWindow::AdjustSize(const wxSize
& size
) const
685 m_renderer
->AdjustSize(&sz
, this);
689 wxPoint
wxWindow::GetClientAreaOrigin() const
691 wxPoint pt
= wxWindowBase::GetClientAreaOrigin();
693 #if wxUSE_TWO_WINDOWS
696 pt
+= m_renderer
->GetBorderDimensions(GetBorder()).GetPosition();
702 void wxWindow::DoGetClientSize(int *width
, int *height
) const
704 // if it is a native window, we assume it handles the scrollbars itself
705 // too - and if it doesn't, there is not much we can do
708 wxWindowNative::DoGetClientSize(width
, height
);
714 wxWindowNative::DoGetClientSize(&w
, &h
);
716 // we assume that the scrollbars are positioned correctly (by a previous
717 // call to PositionScrollbars()) here
721 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
726 // in any case, take account of the scrollbar
727 if ( m_scrollbarVert
)
728 w
-= m_scrollbarVert
->GetSize().x
;
729 #endif // wxUSE_SCROLLBAR
731 // account for the left and right borders
732 *width
= w
- rectBorder
.x
- rectBorder
.width
;
734 // we shouldn't return invalid width
742 if ( m_scrollbarHorz
)
743 h
-= m_scrollbarHorz
->GetSize().y
;
744 #endif // wxUSE_SCROLLBAR
746 *height
= h
- rectBorder
.y
- rectBorder
.height
;
748 // we shouldn't return invalid height
754 void wxWindow::DoSetClientSize(int width
, int height
)
756 // take into account the borders
757 wxRect rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
758 width
+= rectBorder
.x
;
759 height
+= rectBorder
.y
;
761 // and the scrollbars (as they may be offset into the border, use the
762 // scrollbar position, not size - this supposes that PositionScrollbars()
763 // had been called before)
764 wxSize size
= GetSize();
766 if ( m_scrollbarVert
)
767 width
+= size
.x
- m_scrollbarVert
->GetPosition().x
;
768 #endif // wxUSE_SCROLLBAR
769 width
+= rectBorder
.width
;
772 if ( m_scrollbarHorz
)
773 height
+= size
.y
- m_scrollbarHorz
->GetPosition().y
;
774 #endif // wxUSE_SCROLLBAR
775 height
+= rectBorder
.height
;
777 wxWindowNative::DoSetClientSize(width
, height
);
780 wxHitTest
wxWindow::DoHitTest(wxCoord x
, wxCoord y
) const
782 wxHitTest ht
= wxWindowNative::DoHitTest(x
, y
);
785 if ( ht
== wxHT_WINDOW_INSIDE
)
787 if ( m_scrollbarVert
&& x
>= m_scrollbarVert
->GetPosition().x
)
789 // it can still be changed below because it may also be the corner
790 ht
= wxHT_WINDOW_VERT_SCROLLBAR
;
793 if ( m_scrollbarHorz
&& y
>= m_scrollbarHorz
->GetPosition().y
)
795 ht
= ht
== wxHT_WINDOW_VERT_SCROLLBAR
? wxHT_WINDOW_CORNER
796 : wxHT_WINDOW_HORZ_SCROLLBAR
;
799 #endif // wxUSE_SCROLLBAR
804 // ----------------------------------------------------------------------------
805 // scrolling: we implement it entirely ourselves except for ScrollWindow()
806 // function which is supposed to be (efficiently) implemented by the native
808 // ----------------------------------------------------------------------------
810 void wxWindow::RefreshScrollbars()
813 if ( m_scrollbarHorz
)
814 m_scrollbarHorz
->Refresh();
816 if ( m_scrollbarVert
)
817 m_scrollbarVert
->Refresh();
818 #endif // wxUSE_SCROLLBAR
821 void wxWindow::PositionScrollbars()
824 // do not use GetClientSize/Rect as it relies on the scrollbars being
825 // correctly positioned
827 wxSize size
= GetSize();
828 wxBorder border
= GetBorder();
829 wxRect rectBorder
= m_renderer
->GetBorderDimensions(border
);
830 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
832 int height
= m_scrollbarHorz
? m_scrollbarHorz
->GetSize().y
: 0;
833 int width
= m_scrollbarVert
? m_scrollbarVert
->GetSize().x
: 0;
836 if ( m_scrollbarVert
)
838 rectBar
.x
= size
.x
- width
;
840 rectBar
.x
-= rectBorder
.width
;
841 rectBar
.width
= width
;
844 rectBar
.y
+= rectBorder
.y
;
845 rectBar
.height
= size
.y
- height
;
847 rectBar
.height
-= rectBorder
.y
+ rectBorder
.height
;
849 m_scrollbarVert
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
852 if ( m_scrollbarHorz
)
854 rectBar
.y
= size
.y
- height
;
856 rectBar
.y
-= rectBorder
.height
;
857 rectBar
.height
= height
;
860 rectBar
.x
+= rectBorder
.x
;
861 rectBar
.width
= size
.x
- width
;
863 rectBar
.width
-= rectBorder
.x
+ rectBorder
.width
;
865 m_scrollbarHorz
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
869 #endif // wxUSE_SCROLLBAR
872 void wxWindow::SetScrollbar(int orient
,
879 wxASSERT_MSG( pageSize
<= range
,
880 _T("page size can't be greater than range") );
882 bool hasClientSizeChanged
= false;
883 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
884 if ( range
&& (pageSize
< range
) )
889 #if wxUSE_TWO_WINDOWS
890 SetInsertIntoMain( true );
892 scrollbar
= new wxScrollBar(this, wxID_ANY
,
893 wxDefaultPosition
, wxDefaultSize
,
894 orient
& wxVERTICAL
? wxSB_VERTICAL
896 #if wxUSE_TWO_WINDOWS
897 SetInsertIntoMain( false );
899 if ( orient
& wxVERTICAL
)
900 m_scrollbarVert
= scrollbar
;
902 m_scrollbarHorz
= scrollbar
;
904 // the client area diminished as we created a scrollbar
905 hasClientSizeChanged
= true;
907 PositionScrollbars();
909 else if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
911 // we might have disabled it before
915 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
917 else // no range means no scrollbar
921 // wxALWAYS_SHOW_SB only applies to the vertical scrollbar
922 if ( (orient
& wxVERTICAL
) && (GetWindowStyle() & wxALWAYS_SHOW_SB
) )
924 // just disable the scrollbar
925 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
926 scrollbar
->Disable();
928 else // really remove the scrollbar
932 if ( orient
& wxVERTICAL
)
933 m_scrollbarVert
= NULL
;
935 m_scrollbarHorz
= NULL
;
937 // the client area increased as we removed a scrollbar
938 hasClientSizeChanged
= true;
940 // the size of the remaining scrollbar must be adjusted
941 if ( m_scrollbarHorz
|| m_scrollbarVert
)
943 PositionScrollbars();
949 // give the window a chance to relayout
950 if ( hasClientSizeChanged
)
952 #if wxUSE_TWO_WINDOWS
953 wxWindowNative::SetSize( GetSize() );
955 wxSizeEvent
event(GetSize());
956 (void)GetEventHandler()->ProcessEvent(event
);
962 wxUnusedVar(pageSize
);
964 wxUnusedVar(refresh
);
965 #endif // wxUSE_SCROLLBAR
968 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
971 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
974 scrollbar
->SetThumbPosition(pos
);
976 // VZ: I think we can safely ignore this as we always refresh it
977 // automatically whenever the value chanegs
985 #endif // wxUSE_SCROLLBAR
988 int wxWindow::GetScrollPos(int orient
) const
991 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
992 return scrollbar
? scrollbar
->GetThumbPosition() : 0;
996 #endif // wxUSE_SCROLLBAR
999 int wxWindow::GetScrollThumb(int orient
) const
1002 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
1003 return scrollbar
? scrollbar
->GetThumbSize() : 0;
1005 wxUnusedVar(orient
);
1007 #endif // wxUSE_SCROLLBAR
1010 int wxWindow::GetScrollRange(int orient
) const
1013 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
1014 return scrollbar
? scrollbar
->GetRange() : 0;
1016 wxUnusedVar(orient
);
1018 #endif // wxUSE_SCROLLBAR
1021 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1023 // use native scrolling when available and do it in generic way
1027 wxWindowNative::ScrollWindow(dx
, dy
, rect
);
1031 // before scrolling it, ensure that we don't have any unpainted areas
1038 r
= ScrollNoRefresh(dx
, 0, rect
);
1039 Refresh(true /* erase bkgnd */, &r
);
1044 r
= ScrollNoRefresh(0, dy
, rect
);
1045 Refresh(true /* erase bkgnd */, &r
);
1048 // scroll children accordingly:
1049 wxPoint
offset(dx
, dy
);
1051 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1052 node
; node
= node
->GetNext())
1054 wxWindow
*child
= node
->GetData();
1056 if ( child
== m_scrollbarVert
|| child
== m_scrollbarHorz
)
1058 #endif // wxUSE_SCROLLBAR
1060 // VS: Scrolling children has non-trivial semantics. If rect=NULL then
1061 // it is easy: we scroll all children. Otherwise it gets
1063 // 1. if scrolling in one direction only, scroll only
1064 // those children that intersect shaft defined by the rectangle
1065 // and scrolling direction
1066 // 2. if scrolling in both axes, scroll all children
1068 if ( rect
&& (dx
* dy
== 0 /* moving in only one of x, y axis */) )
1070 wxRect childRect
= child
->GetRect();
1071 if ( dx
== 0 && (childRect
.GetLeft() <= rect
->GetRight() ||
1072 childRect
.GetRight() >= rect
->GetLeft()) )
1074 child
->Move(child
->GetPosition() + offset
);
1076 else if ( dy
== 0 && (childRect
.GetTop() <= rect
->GetBottom() ||
1077 childRect
.GetBottom() >= rect
->GetTop()) )
1079 child
->Move(child
->GetPosition() + offset
);
1084 child
->Move(child
->GetPosition() + offset
);
1087 #endif // wxX11/!wxX11
1090 wxRect
wxWindow::ScrollNoRefresh(int dx
, int dy
, const wxRect
*rectTotal
)
1092 wxASSERT_MSG( !dx
|| !dy
, _T("can't be used for diag scrolling") );
1094 // the rect to refresh (which we will calculate)
1103 // calculate the part of the window which we can just redraw in the new
1105 wxSize sizeTotal
= rectTotal
? rectTotal
->GetSize() : GetClientSize();
1107 wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
1108 sizeTotal
.x
, sizeTotal
.y
, dx
, dy
);
1110 // the initial and end point of the region we move in client coords
1111 wxPoint ptSource
, ptDest
;
1114 ptSource
= rectTotal
->GetPosition();
1115 ptDest
= rectTotal
->GetPosition();
1118 // the size of this region
1120 size
.x
= sizeTotal
.x
- abs(dx
);
1121 size
.y
= sizeTotal
.y
- abs(dy
);
1122 if ( size
.x
<= 0 || size
.y
<= 0 )
1124 // just redraw everything as nothing of the displayed image will stay
1125 wxLogTrace(_T("scroll"), _T("refreshing everything"));
1127 rect
= rectTotal
? *rectTotal
: wxRect(0, 0, sizeTotal
.x
, sizeTotal
.y
);
1129 else // move the part which doesn't change to the new location
1131 // note that when we scroll the canvas in some direction we move the
1132 // block which doesn't need to be refreshed in the opposite direction
1136 // scroll to the right, move to the left
1141 // scroll to the left, move to the right
1147 // scroll down, move up
1152 // scroll up, move down
1157 // we need to hide the caret before moving or it will erase itself at
1158 // the wrong (old) location
1159 wxCaret
*caret
= GetCaret();
1162 #endif // wxUSE_CARET
1165 wxClientDC
dc(this);
1166 wxBitmap
bmp(size
.x
, size
.y
);
1168 dcMem
.SelectObject(bmp
);
1170 dcMem
.Blit(wxPoint(0,0), size
, &dc
, ptSource
1171 #if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
1172 + GetClientAreaOrigin()
1173 #endif // broken wxGTK wxDC::Blit
1175 dc
.Blit(ptDest
, size
, &dcMem
, wxPoint(0,0));
1177 wxLogTrace(_T("scroll"),
1178 _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
1179 ptSource
.x
, ptSource
.y
,
1181 ptDest
.x
, ptDest
.y
);
1183 // and now repaint the uncovered area
1185 // FIXME: We repaint the intersection of these rectangles twice - is
1186 // it bad? I don't think so as it is rare to scroll the window
1187 // diagonally anyhow and so adding extra logic to compute
1188 // rectangle intersection is probably not worth the effort
1190 rect
.x
= ptSource
.x
;
1191 rect
.y
= ptSource
.y
;
1197 // refresh the area along the right border
1198 rect
.x
+= size
.x
+ dx
;
1203 // refresh the area along the left border
1207 rect
.height
= sizeTotal
.y
;
1209 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1211 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1218 // refresh the area along the bottom border
1219 rect
.y
+= size
.y
+ dy
;
1224 // refresh the area along the top border
1228 rect
.width
= sizeTotal
.x
;
1230 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1232 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1238 #endif // wxUSE_CARET
1244 // ----------------------------------------------------------------------------
1245 // accelerators and menu hot keys
1246 // ----------------------------------------------------------------------------
1249 // the last window over which Alt was pressed (used by OnKeyUp)
1250 wxWindow
*wxWindow::ms_winLastAltPress
= NULL
;
1251 #endif // wxUSE_MENUS
1253 #if wxUSE_ACCEL || wxUSE_MENUS
1255 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1258 int key
= event
.GetKeyCode();
1259 if ( !event
.ControlDown() && (key
== WXK_ALT
|| key
== WXK_F10
) )
1261 ms_winLastAltPress
= this;
1263 // it can't be an accel anyhow
1267 ms_winLastAltPress
= NULL
;
1268 #endif // wxUSE_MENUS
1271 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
1273 int command
= win
->GetAcceleratorTable()->GetCommand(event
);
1274 if ( command
!= -1 )
1276 wxCommandEvent
eventCmd(wxEVT_COMMAND_MENU_SELECTED
, command
);
1277 if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) )
1279 // skip "event.Skip()" below
1284 if ( win
->IsTopLevel() )
1286 // try the frame menu bar
1288 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1291 wxMenuBar
*menubar
= frame
->GetMenuBar();
1292 if ( menubar
&& menubar
->ProcessAccelEvent(event
) )
1294 // skip "event.Skip()" below
1298 #endif // wxUSE_MENUS
1300 // if it wasn't in a menu, try to find a button
1301 if ( command
!= -1 )
1303 wxWindow
* child
= win
->FindWindow(command
);
1304 if ( child
&& wxDynamicCast(child
, wxButton
) )
1306 wxCommandEvent
eventCmd(wxEVT_COMMAND_BUTTON_CLICKED
, command
);
1307 eventCmd
.SetEventObject(child
);
1308 if ( child
->GetEventHandler()->ProcessEvent(eventCmd
) )
1310 // skip "event.Skip()" below
1316 // don't propagate accels from the child frame to the parent one
1320 #endif // wxUSE_ACCEL
1325 #endif // wxUSE_ACCEL
1329 wxMenuBar
*wxWindow::GetParentFrameMenuBar() const
1331 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
1333 if ( win
->IsTopLevel() )
1335 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1338 return frame
->GetMenuBar();
1341 // don't look further - we don't want to return the menubar of the
1350 void wxWindow::OnChar(wxKeyEvent
& event
)
1352 if ( event
.AltDown() && !event
.ControlDown() )
1354 int key
= event
.GetKeyCode();
1356 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1359 int item
= menubar
->FindNextItemForAccel(-1, key
);
1362 menubar
->PopupMenu((size_t)item
);
1364 // skip "event.Skip()" below
1373 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1375 int key
= event
.GetKeyCode();
1376 if ( !event
.HasModifiers() && (key
== WXK_ALT
|| key
== WXK_F10
) )
1378 // only process Alt release specially if there were no other key
1379 // presses since Alt had been pressed and if both events happened in
1381 if ( ms_winLastAltPress
== this )
1383 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1384 if ( menubar
&& this != menubar
)
1386 menubar
->SelectMenu(0);
1395 // in any case reset it
1396 ms_winLastAltPress
= NULL
;
1399 #endif // wxUSE_MENUS
1401 // ----------------------------------------------------------------------------
1402 // MSW-specific section
1403 // ----------------------------------------------------------------------------
1407 #include "wx/msw/private.h"
1409 WXLRESULT
wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1411 if ( message
== WM_NCHITTEST
)
1413 // the windows which contain the other windows should let the mouse
1414 // events through, otherwise a window inside a static box would
1415 // never get any events at all
1416 if ( IsStaticBox() )
1418 return HTTRANSPARENT
;
1422 return wxWindowNative::MSWWindowProc(message
, wParam
, lParam
);