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 // we add wxCLIP_CHILDREN to get the same ("natural") behaviour under MSW
128 // as under the other platforms
129 actualStyle
|= wxCLIP_CHILDREN
;
132 // FIXME: may need this on other platforms
133 actualStyle
&= ~wxVSCROLL
;
134 actualStyle
&= ~wxHSCROLL
;
136 // without this, borders (non-client areas in general) are not repainted
137 // correctly when resizing; apparently, native NC areas are fully repainted
138 // even without this style by MSW, but wxUniv implements client area
139 // itself, so it doesn't work correctly for us
141 // FIXME: this is very expensive, we need to fix the (commented-out) code
142 // in OnSize() instead
143 actualStyle
|= wxFULL_REPAINT_ON_RESIZE
;
146 if ( !wxWindowNative::Create(parent
, id
, pos
, size
, actualStyle
, name
) )
149 // Set full style again, including those we didn't want present
150 // when calling the base window Create().
151 wxWindowBase::SetWindowStyleFlag(style
);
153 // if we allow or should always have a vertical scrollbar, make it
154 if ( style
& wxVSCROLL
|| style
& wxALWAYS_SHOW_SB
)
156 #if wxUSE_TWO_WINDOWS
157 SetInsertIntoMain( true );
160 m_scrollbarVert
= new wxScrollBar(this, wxID_ANY
,
161 wxDefaultPosition
, wxDefaultSize
,
163 #endif // wxUSE_SCROLLBAR
164 #if wxUSE_TWO_WINDOWS
165 SetInsertIntoMain( false );
169 // if we should allow a horizontal scrollbar, make it
170 if ( style
& wxHSCROLL
)
172 #if wxUSE_TWO_WINDOWS
173 SetInsertIntoMain( true );
176 m_scrollbarHorz
= new wxScrollBar(this, wxID_ANY
,
177 wxDefaultPosition
, wxDefaultSize
,
179 #endif // wxUSE_SCROLLBAR
180 #if wxUSE_TWO_WINDOWS
181 SetInsertIntoMain( false );
186 if (m_scrollbarHorz
|| m_scrollbarVert
)
189 PositionScrollbars();
191 #endif // wxUSE_SCROLLBAR
196 wxWindow::~wxWindow()
198 m_isBeingDeleted
= true;
200 // we have to destroy our children before we're destroyed because our
201 // children suppose that we're of type wxWindow, not just wxWindowNative,
202 // and so bad things may happen if they're deleted from the base class dtor
203 // as by then we're not a wxWindow any longer and wxUniv-specific virtual
204 // functions can't be called
208 // ----------------------------------------------------------------------------
210 // ----------------------------------------------------------------------------
212 void wxWindow::SetBackground(const wxBitmap
& bitmap
,
217 m_alignBgBitmap
= alignment
;
218 m_stretchBgBitmap
= stretch
;
221 const wxBitmap
& wxWindow::GetBackgroundBitmap(int *alignment
,
222 wxStretch
*stretch
) const
224 if ( m_bitmapBg
.Ok() )
227 *alignment
= m_alignBgBitmap
;
229 *stretch
= m_stretchBgBitmap
;
235 // ----------------------------------------------------------------------------
237 // ----------------------------------------------------------------------------
239 // the event handlers executed when the window must be repainted
240 void wxWindow::OnNcPaint(wxNcPaintEvent
& WXUNUSED(event
))
244 // get the window rect
245 wxRect
rect(GetSize());
248 // if the scrollbars are outside the border, we must adjust the rect to
250 if ( !m_renderer
->AreScrollbarsInsideBorder() )
252 wxScrollBar
*scrollbar
= GetScrollbar(wxVERTICAL
);
254 rect
.width
-= scrollbar
->GetSize().x
;
256 scrollbar
= GetScrollbar(wxHORIZONTAL
);
258 rect
.height
-= scrollbar
->GetSize().y
;
260 #endif // wxUSE_SCROLLBAR
262 // get the DC and draw the border on it
264 DoDrawBorder(dc
, rect
);
268 void wxWindow::OnPaint(wxPaintEvent
& event
)
272 // it is a native control which paints itself
277 // get the DC to use and create renderer on it
279 wxControlRenderer
renderer(this, dc
, m_renderer
);
286 // the event handler executed when the window background must be painted
287 void wxWindow::OnErase(wxEraseEvent
& event
)
296 DoDrawBackground(*event
.GetDC());
299 // if we have both scrollbars, we also have a square in the corner between
300 // them which we must paint
301 if ( m_scrollbarVert
&& m_scrollbarHorz
)
303 wxSize size
= GetSize();
304 wxRect rectClient
= GetClientRect(),
305 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
308 rectCorner
.x
= rectClient
.GetRight() + 1;
309 rectCorner
.y
= rectClient
.GetBottom() + 1;
310 rectCorner
.SetRight(size
.x
- rectBorder
.width
);
311 rectCorner
.SetBottom(size
.y
- rectBorder
.height
);
313 if ( GetUpdateRegion().Contains(rectCorner
) )
315 m_renderer
->DrawScrollCorner(*event
.GetDC(), rectCorner
);
318 #endif // wxUSE_SCROLLBAR
321 bool wxWindow::DoDrawBackground(wxDC
& dc
)
325 wxSize size
= GetSize(); // Why not GetClientSize() ?
329 rect
.height
= size
.y
;
331 wxWindow
* const parent
= GetParent();
332 if ( HasTransparentBackground() && parent
)
334 wxASSERT( !IsTopLevel() );
336 wxPoint pos
= GetPosition();
338 AdjustForParentClientOrigin( pos
.x
, pos
.y
, 0 );
340 // Adjust DC logical origin
341 wxCoord org_x
, org_y
, x
, y
;
342 dc
.GetLogicalOrigin( &org_x
, &org_y
);
345 dc
.SetLogicalOrigin( x
, y
);
351 // Let parent draw the background
352 parent
->EraseBackground( dc
, rect
);
354 // Restore DC logical origin
355 dc
.SetLogicalOrigin( org_x
, org_y
);
359 // Draw background ourselves
360 EraseBackground( dc
, rect
);
366 void wxWindow::EraseBackground(wxDC
& dc
, const wxRect
& rect
)
368 if ( GetBackgroundBitmap().Ok() )
370 // Get the bitmap and the flags
373 wxBitmap bmp
= GetBackgroundBitmap(&alignment
, &stretch
);
374 wxControlRenderer::DrawBitmap(dc
, bmp
, rect
, alignment
, stretch
);
378 // Just fill it with bg colour if no bitmap
380 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this),
381 rect
, GetStateFlags());
385 void wxWindow::DoDrawBorder(wxDC
& dc
, const wxRect
& rect
)
387 // draw outline unless the update region is enitrely inside it in which
388 // case we don't need to do it
389 #if 0 // doesn't seem to work, why?
390 if ( wxRegion(rect
).Contains(GetUpdateRegion().GetBox()) != wxInRegion
)
393 m_renderer
->DrawBorder(dc
, GetBorder(), rect
, GetStateFlags());
397 void wxWindow::DoDraw(wxControlRenderer
* WXUNUSED(renderer
))
401 void wxWindow::Refresh(bool eraseBackground
, const wxRect
*rect
)
403 wxRect rectClient
; // the same rectangle in client coordinates
404 wxPoint origin
= GetClientAreaOrigin();
406 wxSize size
= GetClientSize();
410 // the rectangle passed as argument is in client coordinates
413 // don't refresh anything beyond the client area (scrollbars for
415 if ( rectClient
.GetRight() > size
.x
)
416 rectClient
.SetRight(size
.x
);
417 if ( rectClient
.GetBottom() > size
.y
)
418 rectClient
.SetBottom(size
.y
);
421 else // refresh the entire client area
423 // x,y is already set to 0 by default
424 rectClient
.SetSize(size
);
427 // convert refresh rectangle to window coordinates:
428 wxRect
rectWin(rectClient
);
429 rectWin
.Offset(origin
);
432 #ifdef WXDEBUG_REFRESH
433 static bool s_refreshDebug
= false;
434 if ( s_refreshDebug
)
437 dc
.SetBrush(*wxCYAN_BRUSH
);
438 dc
.SetPen(*wxTRANSPARENT_PEN
);
439 dc
.DrawRectangle(rectWin
);
441 // under Unix we use "--sync" X option for this
442 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
447 #endif // WXDEBUG_REFRESH
449 wxWindowNative::Refresh(eraseBackground
, &rectWin
);
451 // Refresh all sub controls if any.
452 wxWindowList
& children
= GetChildren();
453 for ( wxWindowList::iterator i
= children
.begin(); i
!= children
.end(); ++i
)
455 wxWindow
*child
= *i
;
456 // only refresh subcontrols if they are visible:
457 if ( child
->IsTopLevel() || !child
->IsShown() || child
->IsFrozen() )
460 // ...and when the subcontrols are in the update region:
461 wxRect
childrect(child
->GetRect());
462 childrect
.Intersect(rectClient
);
463 if ( childrect
.IsEmpty() )
466 // refresh the subcontrol now:
467 childrect
.Offset(-child
->GetPosition());
468 // NB: We must call wxWindowNative version because we need to refresh
469 // the entire control, not just its client area, and this is why we
470 // don't account for child client area origin here neither. Also
471 // note that we don't pass eraseBackground to the child, but use
472 // true instead: this is because we can't be sure that
473 // eraseBackground=false is safe for children as well and not only
475 child
->wxWindowNative::Refresh(eraseBackground
, &childrect
);
479 // ----------------------------------------------------------------------------
481 // ----------------------------------------------------------------------------
483 bool wxWindow::Enable(bool enable
)
485 if ( !wxWindowNative::Enable(enable
) )
488 // disabled window can't keep focus
489 if ( FindFocus() == this && GetParent() != NULL
)
491 GetParent()->SetFocus();
496 // a window with renderer is drawn by ourselves and it has to be
497 // refreshed to reflect its new status
504 bool wxWindow::IsFocused() const
506 return FindFocus() == this;
509 bool wxWindow::IsPressed() const
514 bool wxWindow::IsDefault() const
519 bool wxWindow::IsCurrent() const
524 bool wxWindow::SetCurrent(bool doit
)
526 if ( doit
== m_isCurrent
)
531 if ( CanBeHighlighted() )
537 int wxWindow::GetStateFlags() const
541 flags
|= wxCONTROL_DISABLED
;
543 // the following states are only possible if our application is active - if
544 // it is not, even our default/focused controls shouldn't appear as such
545 if ( wxTheApp
->IsActive() )
548 flags
|= wxCONTROL_CURRENT
;
550 flags
|= wxCONTROL_FOCUSED
;
552 flags
|= wxCONTROL_PRESSED
;
554 flags
|= wxCONTROL_ISDEFAULT
;
560 // ----------------------------------------------------------------------------
562 // ----------------------------------------------------------------------------
564 void wxWindow::OnSize(wxSizeEvent
& event
)
569 if ( m_scrollbarVert
|| m_scrollbarHorz
)
571 PositionScrollbars();
573 #endif // wxUSE_SCROLLBAR
575 #if 0 // ndef __WXMSW__
576 // Refresh the area (strip) previously occupied by the border
578 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) && IsShown() )
580 // This code assumes that wxSizeEvent.GetSize() returns
581 // the area of the entire window, not just the client
583 wxSize newSize
= event
.GetSize();
585 if (m_oldSize
.x
== wxDefaultCoord
&& m_oldSize
.y
== wxDefaultCoord
)
591 if (HasFlag( wxSIMPLE_BORDER
))
593 if (newSize
.y
> m_oldSize
.y
)
597 rect
.width
= m_oldSize
.x
;
598 rect
.y
= m_oldSize
.y
-2;
600 Refresh( true, &rect
);
602 else if (newSize
.y
< m_oldSize
.y
)
608 rect
.width
= newSize
.x
;
609 wxWindowNative::Refresh( true, &rect
);
612 if (newSize
.x
> m_oldSize
.x
)
616 rect
.height
= m_oldSize
.y
;
617 rect
.x
= m_oldSize
.x
-2;
619 Refresh( true, &rect
);
621 else if (newSize
.x
< m_oldSize
.x
)
627 rect
.height
= newSize
.y
;
628 wxWindowNative::Refresh( true, &rect
);
632 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
634 if (newSize
.y
> m_oldSize
.y
)
638 rect
.width
= m_oldSize
.x
;
639 rect
.y
= m_oldSize
.y
-4;
641 Refresh( true, &rect
);
643 else if (newSize
.y
< m_oldSize
.y
)
649 rect
.width
= newSize
.x
;
650 wxWindowNative::Refresh( true, &rect
);
653 if (newSize
.x
> m_oldSize
.x
)
657 rect
.height
= m_oldSize
.y
;
658 rect
.x
= m_oldSize
.x
-4;
660 Refresh( true, &rect
);
662 else if (newSize
.x
< m_oldSize
.x
)
668 rect
.height
= newSize
.y
;
669 wxWindowNative::Refresh( true, &rect
);
678 wxSize
wxWindow::DoGetBestSize() const
680 return AdjustSize(DoGetBestClientSize());
683 wxSize
wxWindow::DoGetBestClientSize() const
685 return wxWindowNative::DoGetBestSize();
688 wxSize
wxWindow::AdjustSize(const wxSize
& size
) const
692 m_renderer
->AdjustSize(&sz
, this);
696 wxPoint
wxWindow::GetClientAreaOrigin() const
698 wxPoint pt
= wxWindowBase::GetClientAreaOrigin();
700 #if wxUSE_TWO_WINDOWS
703 pt
+= m_renderer
->GetBorderDimensions(GetBorder()).GetPosition();
709 void wxWindow::DoGetClientSize(int *width
, int *height
) const
711 // if it is a native window, we assume it handles the scrollbars itself
712 // too - and if it doesn't, there is not much we can do
715 wxWindowNative::DoGetClientSize(width
, height
);
721 wxWindowNative::DoGetClientSize(&w
, &h
);
723 // we assume that the scrollbars are positioned correctly (by a previous
724 // call to PositionScrollbars()) here
728 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
733 // in any case, take account of the scrollbar
734 if ( m_scrollbarVert
)
735 w
-= m_scrollbarVert
->GetSize().x
;
736 #endif // wxUSE_SCROLLBAR
738 // account for the left and right borders
739 *width
= w
- rectBorder
.x
- rectBorder
.width
;
741 // we shouldn't return invalid width
749 if ( m_scrollbarHorz
)
750 h
-= m_scrollbarHorz
->GetSize().y
;
751 #endif // wxUSE_SCROLLBAR
753 *height
= h
- rectBorder
.y
- rectBorder
.height
;
755 // we shouldn't return invalid height
761 void wxWindow::DoSetClientSize(int width
, int height
)
763 // take into account the borders
764 wxRect rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
765 width
+= rectBorder
.x
;
766 height
+= rectBorder
.y
;
768 // and the scrollbars (as they may be offset into the border, use the
769 // scrollbar position, not size - this supposes that PositionScrollbars()
770 // had been called before)
771 wxSize size
= GetSize();
773 if ( m_scrollbarVert
)
774 width
+= size
.x
- m_scrollbarVert
->GetPosition().x
;
775 #endif // wxUSE_SCROLLBAR
776 width
+= rectBorder
.width
;
779 if ( m_scrollbarHorz
)
780 height
+= size
.y
- m_scrollbarHorz
->GetPosition().y
;
781 #endif // wxUSE_SCROLLBAR
782 height
+= rectBorder
.height
;
784 wxWindowNative::DoSetClientSize(width
, height
);
787 wxHitTest
wxWindow::DoHitTest(wxCoord x
, wxCoord y
) const
789 wxHitTest ht
= wxWindowNative::DoHitTest(x
, y
);
792 if ( ht
== wxHT_WINDOW_INSIDE
)
794 if ( m_scrollbarVert
&& x
>= m_scrollbarVert
->GetPosition().x
)
796 // it can still be changed below because it may also be the corner
797 ht
= wxHT_WINDOW_VERT_SCROLLBAR
;
800 if ( m_scrollbarHorz
&& y
>= m_scrollbarHorz
->GetPosition().y
)
802 ht
= ht
== wxHT_WINDOW_VERT_SCROLLBAR
? wxHT_WINDOW_CORNER
803 : wxHT_WINDOW_HORZ_SCROLLBAR
;
806 #endif // wxUSE_SCROLLBAR
811 // ----------------------------------------------------------------------------
812 // scrolling: we implement it entirely ourselves except for ScrollWindow()
813 // function which is supposed to be (efficiently) implemented by the native
815 // ----------------------------------------------------------------------------
817 void wxWindow::RefreshScrollbars()
820 if ( m_scrollbarHorz
)
821 m_scrollbarHorz
->Refresh();
823 if ( m_scrollbarVert
)
824 m_scrollbarVert
->Refresh();
825 #endif // wxUSE_SCROLLBAR
828 void wxWindow::PositionScrollbars()
831 // do not use GetClientSize/Rect as it relies on the scrollbars being
832 // correctly positioned
834 wxSize size
= GetSize();
835 wxBorder border
= GetBorder();
836 wxRect rectBorder
= m_renderer
->GetBorderDimensions(border
);
837 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
839 int height
= m_scrollbarHorz
? m_scrollbarHorz
->GetSize().y
: 0;
840 int width
= m_scrollbarVert
? m_scrollbarVert
->GetSize().x
: 0;
843 if ( m_scrollbarVert
)
845 rectBar
.x
= size
.x
- width
;
847 rectBar
.x
-= rectBorder
.width
;
848 rectBar
.width
= width
;
851 rectBar
.y
+= rectBorder
.y
;
852 rectBar
.height
= size
.y
- height
;
854 rectBar
.height
-= rectBorder
.y
+ rectBorder
.height
;
856 m_scrollbarVert
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
859 if ( m_scrollbarHorz
)
861 rectBar
.y
= size
.y
- height
;
863 rectBar
.y
-= rectBorder
.height
;
864 rectBar
.height
= height
;
867 rectBar
.x
+= rectBorder
.x
;
868 rectBar
.width
= size
.x
- width
;
870 rectBar
.width
-= rectBorder
.x
+ rectBorder
.width
;
872 m_scrollbarHorz
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
876 #endif // wxUSE_SCROLLBAR
879 void wxWindow::SetScrollbar(int orient
,
886 wxASSERT_MSG( pageSize
<= range
,
887 _T("page size can't be greater than range") );
889 bool hasClientSizeChanged
= false;
890 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
891 if ( range
&& (pageSize
< range
) )
896 #if wxUSE_TWO_WINDOWS
897 SetInsertIntoMain( true );
899 scrollbar
= new wxScrollBar(this, wxID_ANY
,
900 wxDefaultPosition
, wxDefaultSize
,
901 orient
& wxVERTICAL
? wxSB_VERTICAL
903 #if wxUSE_TWO_WINDOWS
904 SetInsertIntoMain( false );
906 if ( orient
& wxVERTICAL
)
907 m_scrollbarVert
= scrollbar
;
909 m_scrollbarHorz
= scrollbar
;
911 // the client area diminished as we created a scrollbar
912 hasClientSizeChanged
= true;
914 PositionScrollbars();
916 else if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
918 // we might have disabled it before
922 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
924 else // no range means no scrollbar
928 // wxALWAYS_SHOW_SB only applies to the vertical scrollbar
929 if ( (orient
& wxVERTICAL
) && (GetWindowStyle() & wxALWAYS_SHOW_SB
) )
931 // just disable the scrollbar
932 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
933 scrollbar
->Disable();
935 else // really remove the scrollbar
939 if ( orient
& wxVERTICAL
)
940 m_scrollbarVert
= NULL
;
942 m_scrollbarHorz
= NULL
;
944 // the client area increased as we removed a scrollbar
945 hasClientSizeChanged
= true;
947 // the size of the remaining scrollbar must be adjusted
948 if ( m_scrollbarHorz
|| m_scrollbarVert
)
950 PositionScrollbars();
956 // give the window a chance to relayout
957 if ( hasClientSizeChanged
)
959 #if wxUSE_TWO_WINDOWS
960 wxWindowNative::SetSize( GetSize() );
962 wxSizeEvent
event(GetSize());
963 (void)GetEventHandler()->ProcessEvent(event
);
969 wxUnusedVar(pageSize
);
971 wxUnusedVar(refresh
);
972 #endif // wxUSE_SCROLLBAR
975 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
978 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
981 scrollbar
->SetThumbPosition(pos
);
983 // VZ: I think we can safely ignore this as we always refresh it
984 // automatically whenever the value chanegs
992 #endif // wxUSE_SCROLLBAR
995 int wxWindow::GetScrollPos(int orient
) const
998 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
999 return scrollbar
? scrollbar
->GetThumbPosition() : 0;
1001 wxUnusedVar(orient
);
1003 #endif // wxUSE_SCROLLBAR
1006 int wxWindow::GetScrollThumb(int orient
) const
1009 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
1010 return scrollbar
? scrollbar
->GetThumbSize() : 0;
1012 wxUnusedVar(orient
);
1014 #endif // wxUSE_SCROLLBAR
1017 int wxWindow::GetScrollRange(int orient
) const
1020 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
1021 return scrollbar
? scrollbar
->GetRange() : 0;
1023 wxUnusedVar(orient
);
1025 #endif // wxUSE_SCROLLBAR
1028 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1030 // use native scrolling when available and do it in generic way
1034 wxWindowNative::ScrollWindow(dx
, dy
, rect
);
1038 // before scrolling it, ensure that we don't have any unpainted areas
1045 r
= ScrollNoRefresh(dx
, 0, rect
);
1046 Refresh(true /* erase bkgnd */, &r
);
1051 r
= ScrollNoRefresh(0, dy
, rect
);
1052 Refresh(true /* erase bkgnd */, &r
);
1055 // scroll children accordingly:
1056 wxPoint
offset(dx
, dy
);
1058 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1059 node
; node
= node
->GetNext())
1061 wxWindow
*child
= node
->GetData();
1063 if ( child
== m_scrollbarVert
|| child
== m_scrollbarHorz
)
1065 #endif // wxUSE_SCROLLBAR
1067 // VS: Scrolling children has non-trivial semantics. If rect=NULL then
1068 // it is easy: we scroll all children. Otherwise it gets
1070 // 1. if scrolling in one direction only, scroll only
1071 // those children that intersect shaft defined by the rectangle
1072 // and scrolling direction
1073 // 2. if scrolling in both axes, scroll all children
1075 if ( rect
&& (dx
* dy
== 0 /* moving in only one of x, y axis */) )
1077 wxRect childRect
= child
->GetRect();
1078 if ( dx
== 0 && (childRect
.GetLeft() <= rect
->GetRight() ||
1079 childRect
.GetRight() >= rect
->GetLeft()) )
1081 child
->Move(child
->GetPosition() + offset
);
1083 else if ( dy
== 0 && (childRect
.GetTop() <= rect
->GetBottom() ||
1084 childRect
.GetBottom() >= rect
->GetTop()) )
1086 child
->Move(child
->GetPosition() + offset
);
1091 child
->Move(child
->GetPosition() + offset
);
1094 #endif // wxX11/!wxX11
1097 wxRect
wxWindow::ScrollNoRefresh(int dx
, int dy
, const wxRect
*rectTotal
)
1099 wxASSERT_MSG( !dx
|| !dy
, _T("can't be used for diag scrolling") );
1101 // the rect to refresh (which we will calculate)
1110 // calculate the part of the window which we can just redraw in the new
1112 wxSize sizeTotal
= rectTotal
? rectTotal
->GetSize() : GetClientSize();
1114 wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
1115 sizeTotal
.x
, sizeTotal
.y
, dx
, dy
);
1117 // the initial and end point of the region we move in client coords
1118 wxPoint ptSource
, ptDest
;
1121 ptSource
= rectTotal
->GetPosition();
1122 ptDest
= rectTotal
->GetPosition();
1125 // the size of this region
1127 size
.x
= sizeTotal
.x
- abs(dx
);
1128 size
.y
= sizeTotal
.y
- abs(dy
);
1129 if ( size
.x
<= 0 || size
.y
<= 0 )
1131 // just redraw everything as nothing of the displayed image will stay
1132 wxLogTrace(_T("scroll"), _T("refreshing everything"));
1134 rect
= rectTotal
? *rectTotal
: wxRect(0, 0, sizeTotal
.x
, sizeTotal
.y
);
1136 else // move the part which doesn't change to the new location
1138 // note that when we scroll the canvas in some direction we move the
1139 // block which doesn't need to be refreshed in the opposite direction
1143 // scroll to the right, move to the left
1148 // scroll to the left, move to the right
1154 // scroll down, move up
1159 // scroll up, move down
1164 // we need to hide the caret before moving or it will erase itself at
1165 // the wrong (old) location
1166 wxCaret
*caret
= GetCaret();
1169 #endif // wxUSE_CARET
1172 wxClientDC
dc(this);
1173 wxBitmap
bmp(size
.x
, size
.y
);
1175 dcMem
.SelectObject(bmp
);
1177 dcMem
.Blit(wxPoint(0,0), size
, &dc
, ptSource
1178 #if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
1179 + GetClientAreaOrigin()
1180 #endif // broken wxGTK wxDC::Blit
1182 dc
.Blit(ptDest
, size
, &dcMem
, wxPoint(0,0));
1184 wxLogTrace(_T("scroll"),
1185 _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
1186 ptSource
.x
, ptSource
.y
,
1188 ptDest
.x
, ptDest
.y
);
1190 // and now repaint the uncovered area
1192 // FIXME: We repaint the intersection of these rectangles twice - is
1193 // it bad? I don't think so as it is rare to scroll the window
1194 // diagonally anyhow and so adding extra logic to compute
1195 // rectangle intersection is probably not worth the effort
1197 rect
.x
= ptSource
.x
;
1198 rect
.y
= ptSource
.y
;
1204 // refresh the area along the right border
1205 rect
.x
+= size
.x
+ dx
;
1210 // refresh the area along the left border
1214 rect
.height
= sizeTotal
.y
;
1216 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1218 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1225 // refresh the area along the bottom border
1226 rect
.y
+= size
.y
+ dy
;
1231 // refresh the area along the top border
1235 rect
.width
= sizeTotal
.x
;
1237 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1239 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1245 #endif // wxUSE_CARET
1251 // ----------------------------------------------------------------------------
1252 // accelerators and menu hot keys
1253 // ----------------------------------------------------------------------------
1256 // the last window over which Alt was pressed (used by OnKeyUp)
1257 wxWindow
*wxWindow::ms_winLastAltPress
= NULL
;
1258 #endif // wxUSE_MENUS
1260 #if wxUSE_ACCEL || wxUSE_MENUS
1262 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1265 int key
= event
.GetKeyCode();
1266 if ( !event
.ControlDown() && (key
== WXK_ALT
|| key
== WXK_F10
) )
1268 ms_winLastAltPress
= this;
1270 // it can't be an accel anyhow
1274 ms_winLastAltPress
= NULL
;
1275 #endif // wxUSE_MENUS
1278 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
1280 int command
= win
->GetAcceleratorTable()->GetCommand(event
);
1281 if ( command
!= -1 )
1283 wxCommandEvent
eventCmd(wxEVT_COMMAND_MENU_SELECTED
, command
);
1284 if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) )
1286 // skip "event.Skip()" below
1291 if ( win
->IsTopLevel() )
1293 // try the frame menu bar
1295 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1298 wxMenuBar
*menubar
= frame
->GetMenuBar();
1299 if ( menubar
&& menubar
->ProcessAccelEvent(event
) )
1301 // skip "event.Skip()" below
1305 #endif // wxUSE_MENUS
1307 // if it wasn't in a menu, try to find a button
1308 if ( command
!= -1 )
1310 wxWindow
* child
= win
->FindWindow(command
);
1311 if ( child
&& wxDynamicCast(child
, wxButton
) )
1313 wxCommandEvent
eventCmd(wxEVT_COMMAND_BUTTON_CLICKED
, command
);
1314 eventCmd
.SetEventObject(child
);
1315 if ( child
->GetEventHandler()->ProcessEvent(eventCmd
) )
1317 // skip "event.Skip()" below
1323 // don't propagate accels from the child frame to the parent one
1327 #endif // wxUSE_ACCEL
1332 #endif // wxUSE_ACCEL
1336 wxMenuBar
*wxWindow::GetParentFrameMenuBar() const
1338 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
1340 if ( win
->IsTopLevel() )
1342 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1345 return frame
->GetMenuBar();
1348 // don't look further - we don't want to return the menubar of the
1357 void wxWindow::OnChar(wxKeyEvent
& event
)
1359 if ( event
.AltDown() && !event
.ControlDown() )
1361 int key
= event
.GetKeyCode();
1363 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1366 int item
= menubar
->FindNextItemForAccel(-1, key
);
1369 menubar
->PopupMenu((size_t)item
);
1371 // skip "event.Skip()" below
1380 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1382 int key
= event
.GetKeyCode();
1383 if ( !event
.HasModifiers() && (key
== WXK_ALT
|| key
== WXK_F10
) )
1385 // only process Alt release specially if there were no other key
1386 // presses since Alt had been pressed and if both events happened in
1388 if ( ms_winLastAltPress
== this )
1390 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1391 if ( menubar
&& this != menubar
)
1393 menubar
->SelectMenu(0);
1402 // in any case reset it
1403 ms_winLastAltPress
= NULL
;
1406 #endif // wxUSE_MENUS
1408 // ----------------------------------------------------------------------------
1409 // MSW-specific section
1410 // ----------------------------------------------------------------------------
1414 #include "wx/msw/private.h"
1416 WXLRESULT
wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1418 if ( message
== WM_NCHITTEST
)
1420 // the windows which contain the other windows should let the mouse
1421 // events through, otherwise a window inside a static box would
1422 // never get any events at all
1423 if ( IsStaticBox() )
1425 return HTTRANSPARENT
;
1429 return wxWindowNative::MSWWindowProc(message
, wParam
, lParam
);