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 // This is scrollbar class used to implement wxWindow's "built-in" scrollbars;
68 // unlike the standard wxScrollBar class, this one is positioned outside of its
69 // parent's client area
70 class wxWindowScrollBar
: public wxScrollBar
73 wxWindowScrollBar(wxWindow
*parent
,
75 const wxPoint
& pos
= wxDefaultPosition
,
76 const wxSize
& size
= wxDefaultSize
,
77 long style
= wxSB_HORIZONTAL
)
78 : wxScrollBar(parent
, id
, pos
, size
, style
)
82 virtual bool CanBeOutsideClientArea() const { return true; }
86 // ----------------------------------------------------------------------------
88 // ----------------------------------------------------------------------------
90 // we can't use wxWindowNative here as it won't be expanded inside the macro
91 #if defined(__WXMSW__)
92 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowMSW
)
93 #elif defined(__WXGTK__)
94 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowGTK
)
95 #elif defined(__WXMGL__)
96 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowMGL
)
97 #elif defined(__WXDFB__)
98 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowDFB
)
99 #elif defined(__WXX11__)
100 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowX11
)
101 #elif defined(__WXPM__)
102 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowOS2
)
105 BEGIN_EVENT_TABLE(wxWindow
, wxWindowNative
)
106 EVT_SIZE(wxWindow::OnSize
)
108 #if wxUSE_ACCEL || wxUSE_MENUS
109 EVT_KEY_DOWN(wxWindow::OnKeyDown
)
110 #endif // wxUSE_ACCEL
113 EVT_CHAR(wxWindow::OnChar
)
114 EVT_KEY_UP(wxWindow::OnKeyUp
)
115 #endif // wxUSE_MENUS
117 EVT_PAINT(wxWindow::OnPaint
)
118 EVT_NC_PAINT(wxWindow::OnNcPaint
)
119 EVT_ERASE_BACKGROUND(wxWindow::OnErase
)
122 // ----------------------------------------------------------------------------
124 // ----------------------------------------------------------------------------
126 void wxWindow::Init()
130 m_scrollbarHorz
= (wxScrollBar
*)NULL
;
131 #endif // wxUSE_SCROLLBAR
135 m_renderer
= wxTheme::Get()->GetRenderer();
137 m_oldSize
.x
= wxDefaultCoord
;
138 m_oldSize
.y
= wxDefaultCoord
;
141 bool wxWindow::Create(wxWindow
*parent
,
146 const wxString
& name
)
148 long actualStyle
= style
;
150 // we add wxCLIP_CHILDREN to get the same ("natural") behaviour under MSW
151 // as under the other platforms
152 actualStyle
|= wxCLIP_CHILDREN
;
154 actualStyle
&= ~wxVSCROLL
;
155 actualStyle
&= ~wxHSCROLL
;
158 // without this, borders (non-client areas in general) are not repainted
159 // correctly when resizing; apparently, native NC areas are fully repainted
160 // even without this style by MSW, but wxUniv implements client area
161 // itself, so it doesn't work correctly for us
163 // FIXME: this is very expensive, we need to fix the (commented-out) code
164 // in OnSize() instead
165 actualStyle
|= wxFULL_REPAINT_ON_RESIZE
;
168 if ( !wxWindowNative::Create(parent
, id
, pos
, size
, actualStyle
, name
) )
171 // Set full style again, including those we didn't want present
172 // when calling the base window Create().
173 wxWindowBase::SetWindowStyleFlag(style
);
175 // if we allow or should always have a vertical scrollbar, make it
176 if ( style
& wxVSCROLL
|| style
& wxALWAYS_SHOW_SB
)
178 #if wxUSE_TWO_WINDOWS
179 SetInsertIntoMain( true );
182 m_scrollbarVert
= new wxWindowScrollBar(this, wxID_ANY
,
183 wxDefaultPosition
, wxDefaultSize
,
185 #endif // wxUSE_SCROLLBAR
186 #if wxUSE_TWO_WINDOWS
187 SetInsertIntoMain( false );
191 // if we should allow a horizontal scrollbar, make it
192 if ( style
& wxHSCROLL
)
194 #if wxUSE_TWO_WINDOWS
195 SetInsertIntoMain( true );
198 m_scrollbarHorz
= new wxWindowScrollBar(this, wxID_ANY
,
199 wxDefaultPosition
, wxDefaultSize
,
201 #endif // wxUSE_SCROLLBAR
202 #if wxUSE_TWO_WINDOWS
203 SetInsertIntoMain( false );
208 if (m_scrollbarHorz
|| m_scrollbarVert
)
211 PositionScrollbars();
213 #endif // wxUSE_SCROLLBAR
218 wxWindow::~wxWindow()
220 m_isBeingDeleted
= true;
223 // clear pointers to scrollbar before deleting the children: they are
224 // children and so will be deleted by DestroyChildren() call below and if
225 // any code using the scrollbars would be called in the process or from
226 // ~wxWindowBase, the app would crash:
227 m_scrollbarVert
= m_scrollbarHorz
= NULL
;
230 // we have to destroy our children before we're destroyed because our
231 // children suppose that we're of type wxWindow, not just wxWindowNative,
232 // and so bad things may happen if they're deleted from the base class dtor
233 // as by then we're not a wxWindow any longer and wxUniv-specific virtual
234 // functions can't be called
238 // ----------------------------------------------------------------------------
240 // ----------------------------------------------------------------------------
242 void wxWindow::SetBackground(const wxBitmap
& bitmap
,
247 m_alignBgBitmap
= alignment
;
248 m_stretchBgBitmap
= stretch
;
251 const wxBitmap
& wxWindow::GetBackgroundBitmap(int *alignment
,
252 wxStretch
*stretch
) const
254 if ( m_bitmapBg
.Ok() )
257 *alignment
= m_alignBgBitmap
;
259 *stretch
= m_stretchBgBitmap
;
265 // ----------------------------------------------------------------------------
267 // ----------------------------------------------------------------------------
269 // the event handlers executed when the window must be repainted
270 void wxWindow::OnNcPaint(wxNcPaintEvent
& WXUNUSED(event
))
274 // get the window rect
275 wxRect
rect(GetSize());
278 // if the scrollbars are outside the border, we must adjust the rect to
280 if ( !m_renderer
->AreScrollbarsInsideBorder() )
282 wxScrollBar
*scrollbar
= GetScrollbar(wxVERTICAL
);
284 rect
.width
-= scrollbar
->GetSize().x
;
286 scrollbar
= GetScrollbar(wxHORIZONTAL
);
288 rect
.height
-= scrollbar
->GetSize().y
;
290 #endif // wxUSE_SCROLLBAR
292 // get the DC and draw the border on it
294 DoDrawBorder(dc
, rect
);
298 void wxWindow::OnPaint(wxPaintEvent
& event
)
302 // it is a native control which paints itself
307 // get the DC to use and create renderer on it
309 wxControlRenderer
renderer(this, dc
, m_renderer
);
316 // the event handler executed when the window background must be painted
317 void wxWindow::OnErase(wxEraseEvent
& event
)
326 DoDrawBackground(*event
.GetDC());
329 // if we have both scrollbars, we also have a square in the corner between
330 // them which we must paint
331 if ( m_scrollbarVert
&& m_scrollbarHorz
)
333 wxSize size
= GetSize();
334 wxRect rectClient
= GetClientRect(),
335 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
338 rectCorner
.x
= rectClient
.GetRight() + 1;
339 rectCorner
.y
= rectClient
.GetBottom() + 1;
340 rectCorner
.SetRight(size
.x
- rectBorder
.width
);
341 rectCorner
.SetBottom(size
.y
- rectBorder
.height
);
343 if ( GetUpdateRegion().Contains(rectCorner
) )
345 m_renderer
->DrawScrollCorner(*event
.GetDC(), rectCorner
);
348 #endif // wxUSE_SCROLLBAR
351 bool wxWindow::DoDrawBackground(wxDC
& dc
)
355 wxSize size
= GetSize(); // Why not GetClientSize() ?
359 rect
.height
= size
.y
;
361 wxWindow
* const parent
= GetParent();
362 if ( HasTransparentBackground() && parent
)
364 wxASSERT( !IsTopLevel() );
366 wxPoint pos
= GetPosition();
368 AdjustForParentClientOrigin( pos
.x
, pos
.y
, 0 );
370 // Adjust DC logical origin
371 wxCoord org_x
, org_y
, x
, y
;
372 dc
.GetLogicalOrigin( &org_x
, &org_y
);
375 dc
.SetLogicalOrigin( x
, y
);
381 // Let parent draw the background
382 parent
->EraseBackground( dc
, rect
);
384 // Restore DC logical origin
385 dc
.SetLogicalOrigin( org_x
, org_y
);
389 // Draw background ourselves
390 EraseBackground( dc
, rect
);
396 void wxWindow::EraseBackground(wxDC
& dc
, const wxRect
& rect
)
398 if ( GetBackgroundBitmap().Ok() )
400 // Get the bitmap and the flags
403 wxBitmap bmp
= GetBackgroundBitmap(&alignment
, &stretch
);
404 wxControlRenderer::DrawBitmap(dc
, bmp
, rect
, alignment
, stretch
);
408 // Just fill it with bg colour if no bitmap
410 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this),
411 rect
, GetStateFlags());
415 void wxWindow::DoDrawBorder(wxDC
& dc
, const wxRect
& rect
)
417 // draw outline unless the update region is enitrely inside it in which
418 // case we don't need to do it
419 #if 0 // doesn't seem to work, why?
420 if ( wxRegion(rect
).Contains(GetUpdateRegion().GetBox()) != wxInRegion
)
423 m_renderer
->DrawBorder(dc
, GetBorder(), rect
, GetStateFlags());
427 void wxWindow::DoDraw(wxControlRenderer
* WXUNUSED(renderer
))
431 void wxWindow::Refresh(bool eraseBackground
, const wxRect
*rect
)
433 wxRect rectClient
; // the same rectangle in client coordinates
434 wxPoint origin
= GetClientAreaOrigin();
436 wxSize size
= GetClientSize();
440 // the rectangle passed as argument is in client coordinates
443 // don't refresh anything beyond the client area (scrollbars for
445 if ( rectClient
.GetRight() > size
.x
)
446 rectClient
.SetRight(size
.x
);
447 if ( rectClient
.GetBottom() > size
.y
)
448 rectClient
.SetBottom(size
.y
);
451 else // refresh the entire client area
453 // x,y is already set to 0 by default
454 rectClient
.SetSize(size
);
457 // convert refresh rectangle to window coordinates:
458 wxRect
rectWin(rectClient
);
459 rectWin
.Offset(origin
);
462 #ifdef WXDEBUG_REFRESH
463 static bool s_refreshDebug
= false;
464 if ( s_refreshDebug
)
467 dc
.SetBrush(*wxCYAN_BRUSH
);
468 dc
.SetPen(*wxTRANSPARENT_PEN
);
469 dc
.DrawRectangle(rectWin
);
471 // under Unix we use "--sync" X option for this
472 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
477 #endif // WXDEBUG_REFRESH
479 wxWindowNative::Refresh(eraseBackground
, &rectWin
);
481 // Refresh all sub controls if any.
482 wxWindowList
& children
= GetChildren();
483 for ( wxWindowList::iterator i
= children
.begin(); i
!= children
.end(); ++i
)
485 wxWindow
*child
= *i
;
486 // only refresh subcontrols if they are visible:
487 if ( child
->IsTopLevel() || !child
->IsShown() || child
->IsFrozen() )
490 // ...and when the subcontrols are in the update region:
491 wxRect
childrect(child
->GetRect());
492 childrect
.Intersect(rectClient
);
493 if ( childrect
.IsEmpty() )
496 // refresh the subcontrol now:
497 childrect
.Offset(-child
->GetPosition());
498 // NB: We must call wxWindowNative version because we need to refresh
499 // the entire control, not just its client area, and this is why we
500 // don't account for child client area origin here neither. Also
501 // note that we don't pass eraseBackground to the child, but use
502 // true instead: this is because we can't be sure that
503 // eraseBackground=false is safe for children as well and not only
505 child
->wxWindowNative::Refresh(eraseBackground
, &childrect
);
509 // ----------------------------------------------------------------------------
511 // ----------------------------------------------------------------------------
513 bool wxWindow::Enable(bool enable
)
515 if ( !wxWindowNative::Enable(enable
) )
518 // disabled window can't keep focus
519 if ( FindFocus() == this && GetParent() != NULL
)
521 GetParent()->SetFocus();
526 // a window with renderer is drawn by ourselves and it has to be
527 // refreshed to reflect its new status
534 bool wxWindow::IsFocused() const
536 return FindFocus() == this;
539 bool wxWindow::IsPressed() const
544 bool wxWindow::IsDefault() const
549 bool wxWindow::IsCurrent() const
554 bool wxWindow::SetCurrent(bool doit
)
556 if ( doit
== m_isCurrent
)
561 if ( CanBeHighlighted() )
567 int wxWindow::GetStateFlags() const
571 flags
|= wxCONTROL_DISABLED
;
573 // the following states are only possible if our application is active - if
574 // it is not, even our default/focused controls shouldn't appear as such
575 if ( wxTheApp
->IsActive() )
578 flags
|= wxCONTROL_CURRENT
;
580 flags
|= wxCONTROL_FOCUSED
;
582 flags
|= wxCONTROL_PRESSED
;
584 flags
|= wxCONTROL_ISDEFAULT
;
590 // ----------------------------------------------------------------------------
592 // ----------------------------------------------------------------------------
594 void wxWindow::OnSize(wxSizeEvent
& event
)
599 if ( m_scrollbarVert
|| m_scrollbarHorz
)
601 PositionScrollbars();
603 #endif // wxUSE_SCROLLBAR
605 #if 0 // ndef __WXMSW__
606 // Refresh the area (strip) previously occupied by the border
608 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) && IsShown() )
610 // This code assumes that wxSizeEvent.GetSize() returns
611 // the area of the entire window, not just the client
613 wxSize newSize
= event
.GetSize();
615 if (m_oldSize
.x
== wxDefaultCoord
&& m_oldSize
.y
== wxDefaultCoord
)
621 if (HasFlag( wxSIMPLE_BORDER
))
623 if (newSize
.y
> m_oldSize
.y
)
627 rect
.width
= m_oldSize
.x
;
628 rect
.y
= m_oldSize
.y
-2;
630 Refresh( true, &rect
);
632 else if (newSize
.y
< m_oldSize
.y
)
638 rect
.width
= newSize
.x
;
639 wxWindowNative::Refresh( true, &rect
);
642 if (newSize
.x
> m_oldSize
.x
)
646 rect
.height
= m_oldSize
.y
;
647 rect
.x
= m_oldSize
.x
-2;
649 Refresh( true, &rect
);
651 else if (newSize
.x
< m_oldSize
.x
)
657 rect
.height
= newSize
.y
;
658 wxWindowNative::Refresh( true, &rect
);
662 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
664 if (newSize
.y
> m_oldSize
.y
)
668 rect
.width
= m_oldSize
.x
;
669 rect
.y
= m_oldSize
.y
-4;
671 Refresh( true, &rect
);
673 else if (newSize
.y
< m_oldSize
.y
)
679 rect
.width
= newSize
.x
;
680 wxWindowNative::Refresh( true, &rect
);
683 if (newSize
.x
> m_oldSize
.x
)
687 rect
.height
= m_oldSize
.y
;
688 rect
.x
= m_oldSize
.x
-4;
690 Refresh( true, &rect
);
692 else if (newSize
.x
< m_oldSize
.x
)
698 rect
.height
= newSize
.y
;
699 wxWindowNative::Refresh( true, &rect
);
708 wxSize
wxWindow::DoGetBestSize() const
710 return AdjustSize(DoGetBestClientSize());
713 wxSize
wxWindow::DoGetBestClientSize() const
715 return wxWindowNative::DoGetBestSize();
718 wxSize
wxWindow::AdjustSize(const wxSize
& size
) const
722 m_renderer
->AdjustSize(&sz
, this);
726 wxPoint
wxWindow::GetClientAreaOrigin() const
728 wxPoint pt
= wxWindowBase::GetClientAreaOrigin();
730 #if wxUSE_TWO_WINDOWS
733 pt
+= m_renderer
->GetBorderDimensions(GetBorder()).GetPosition();
739 void wxWindow::DoGetClientSize(int *width
, int *height
) const
741 // if it is a native window, we assume it handles the scrollbars itself
742 // too - and if it doesn't, there is not much we can do
745 wxWindowNative::DoGetClientSize(width
, height
);
751 wxWindowNative::DoGetClientSize(&w
, &h
);
753 // we assume that the scrollbars are positioned correctly (by a previous
754 // call to PositionScrollbars()) here
758 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
763 // in any case, take account of the scrollbar
764 if ( m_scrollbarVert
)
765 w
-= m_scrollbarVert
->GetSize().x
;
766 #endif // wxUSE_SCROLLBAR
768 // account for the left and right borders
769 *width
= w
- rectBorder
.x
- rectBorder
.width
;
771 // we shouldn't return invalid width
779 if ( m_scrollbarHorz
)
780 h
-= m_scrollbarHorz
->GetSize().y
;
781 #endif // wxUSE_SCROLLBAR
783 *height
= h
- rectBorder
.y
- rectBorder
.height
;
785 // we shouldn't return invalid height
791 void wxWindow::DoSetClientSize(int width
, int height
)
793 // take into account the borders
794 wxRect rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
795 width
+= rectBorder
.x
;
796 height
+= rectBorder
.y
;
798 // and the scrollbars (as they may be offset into the border, use the
799 // scrollbar position, not size - this supposes that PositionScrollbars()
800 // had been called before)
801 wxSize size
= GetSize();
803 if ( m_scrollbarVert
)
804 width
+= size
.x
- m_scrollbarVert
->GetPosition().x
;
805 #endif // wxUSE_SCROLLBAR
806 width
+= rectBorder
.width
;
809 if ( m_scrollbarHorz
)
810 height
+= size
.y
- m_scrollbarHorz
->GetPosition().y
;
811 #endif // wxUSE_SCROLLBAR
812 height
+= rectBorder
.height
;
814 wxWindowNative::DoSetClientSize(width
, height
);
817 wxHitTest
wxWindow::DoHitTest(wxCoord x
, wxCoord y
) const
819 wxHitTest ht
= wxWindowNative::DoHitTest(x
, y
);
822 if ( ht
== wxHT_WINDOW_INSIDE
)
824 if ( m_scrollbarVert
&& x
>= m_scrollbarVert
->GetPosition().x
)
826 // it can still be changed below because it may also be the corner
827 ht
= wxHT_WINDOW_VERT_SCROLLBAR
;
830 if ( m_scrollbarHorz
&& y
>= m_scrollbarHorz
->GetPosition().y
)
832 ht
= ht
== wxHT_WINDOW_VERT_SCROLLBAR
? wxHT_WINDOW_CORNER
833 : wxHT_WINDOW_HORZ_SCROLLBAR
;
836 #endif // wxUSE_SCROLLBAR
841 // ----------------------------------------------------------------------------
842 // scrolling: we implement it entirely ourselves except for ScrollWindow()
843 // function which is supposed to be (efficiently) implemented by the native
845 // ----------------------------------------------------------------------------
847 void wxWindow::RefreshScrollbars()
850 if ( m_scrollbarHorz
)
851 m_scrollbarHorz
->Refresh();
853 if ( m_scrollbarVert
)
854 m_scrollbarVert
->Refresh();
855 #endif // wxUSE_SCROLLBAR
858 void wxWindow::PositionScrollbars()
861 // do not use GetClientSize/Rect as it relies on the scrollbars being
862 // correctly positioned
864 wxSize size
= GetSize();
865 wxBorder border
= GetBorder();
866 wxRect rectBorder
= m_renderer
->GetBorderDimensions(border
);
867 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
869 int height
= m_scrollbarHorz
? m_scrollbarHorz
->GetSize().y
: 0;
870 int width
= m_scrollbarVert
? m_scrollbarVert
->GetSize().x
: 0;
873 if ( m_scrollbarVert
)
875 rectBar
.x
= size
.x
- width
;
877 rectBar
.x
-= rectBorder
.width
;
878 rectBar
.width
= width
;
881 rectBar
.y
+= rectBorder
.y
;
882 rectBar
.height
= size
.y
- height
;
884 rectBar
.height
-= rectBorder
.y
+ rectBorder
.height
;
886 m_scrollbarVert
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
889 if ( m_scrollbarHorz
)
891 rectBar
.y
= size
.y
- height
;
893 rectBar
.y
-= rectBorder
.height
;
894 rectBar
.height
= height
;
897 rectBar
.x
+= rectBorder
.x
;
898 rectBar
.width
= size
.x
- width
;
900 rectBar
.width
-= rectBorder
.x
+ rectBorder
.width
;
902 m_scrollbarHorz
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
906 #endif // wxUSE_SCROLLBAR
909 void wxWindow::SetScrollbar(int orient
,
916 wxASSERT_MSG( pageSize
<= range
,
917 _T("page size can't be greater than range") );
919 bool hasClientSizeChanged
= false;
920 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
921 if ( range
&& (pageSize
< range
) )
926 #if wxUSE_TWO_WINDOWS
927 SetInsertIntoMain( true );
929 scrollbar
= new wxWindowScrollBar(this, wxID_ANY
,
930 wxDefaultPosition
, wxDefaultSize
,
931 orient
& wxVERTICAL
? wxSB_VERTICAL
933 #if wxUSE_TWO_WINDOWS
934 SetInsertIntoMain( false );
936 if ( orient
& wxVERTICAL
)
937 m_scrollbarVert
= scrollbar
;
939 m_scrollbarHorz
= scrollbar
;
941 // the client area diminished as we created a scrollbar
942 hasClientSizeChanged
= true;
944 PositionScrollbars();
946 else if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
948 // we might have disabled it before
952 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
954 else // no range means no scrollbar
958 // wxALWAYS_SHOW_SB only applies to the vertical scrollbar
959 if ( (orient
& wxVERTICAL
) && (GetWindowStyle() & wxALWAYS_SHOW_SB
) )
961 // just disable the scrollbar
962 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
963 scrollbar
->Disable();
965 else // really remove the scrollbar
969 if ( orient
& wxVERTICAL
)
970 m_scrollbarVert
= NULL
;
972 m_scrollbarHorz
= NULL
;
974 // the client area increased as we removed a scrollbar
975 hasClientSizeChanged
= true;
977 // the size of the remaining scrollbar must be adjusted
978 if ( m_scrollbarHorz
|| m_scrollbarVert
)
980 PositionScrollbars();
986 // give the window a chance to relayout
987 if ( hasClientSizeChanged
)
989 #if wxUSE_TWO_WINDOWS
990 wxWindowNative::SetSize( GetSize() );
992 wxSizeEvent
event(GetSize());
993 (void)GetEventHandler()->ProcessEvent(event
);
999 wxUnusedVar(pageSize
);
1001 wxUnusedVar(refresh
);
1002 #endif // wxUSE_SCROLLBAR
1005 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1008 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
1011 scrollbar
->SetThumbPosition(pos
);
1013 // VZ: I think we can safely ignore this as we always refresh it
1014 // automatically whenever the value chanegs
1020 wxUnusedVar(orient
);
1022 #endif // wxUSE_SCROLLBAR
1025 int wxWindow::GetScrollPos(int orient
) const
1028 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
1029 return scrollbar
? scrollbar
->GetThumbPosition() : 0;
1031 wxUnusedVar(orient
);
1033 #endif // wxUSE_SCROLLBAR
1036 int wxWindow::GetScrollThumb(int orient
) const
1039 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
1040 return scrollbar
? scrollbar
->GetThumbSize() : 0;
1042 wxUnusedVar(orient
);
1044 #endif // wxUSE_SCROLLBAR
1047 int wxWindow::GetScrollRange(int orient
) const
1050 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
1051 return scrollbar
? scrollbar
->GetRange() : 0;
1053 wxUnusedVar(orient
);
1055 #endif // wxUSE_SCROLLBAR
1058 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1060 // use native scrolling when available and do it in generic way
1064 wxWindowNative::ScrollWindow(dx
, dy
, rect
);
1068 // before scrolling it, ensure that we don't have any unpainted areas
1075 r
= ScrollNoRefresh(dx
, 0, rect
);
1076 Refresh(true /* erase bkgnd */, &r
);
1081 r
= ScrollNoRefresh(0, dy
, rect
);
1082 Refresh(true /* erase bkgnd */, &r
);
1085 // scroll children accordingly:
1086 wxPoint
offset(dx
, dy
);
1088 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1089 node
; node
= node
->GetNext())
1091 wxWindow
*child
= node
->GetData();
1093 if ( child
== m_scrollbarVert
|| child
== m_scrollbarHorz
)
1095 #endif // wxUSE_SCROLLBAR
1097 // VS: Scrolling children has non-trivial semantics. If rect=NULL then
1098 // it is easy: we scroll all children. Otherwise it gets
1100 // 1. if scrolling in one direction only, scroll only
1101 // those children that intersect shaft defined by the rectangle
1102 // and scrolling direction
1103 // 2. if scrolling in both axes, scroll all children
1105 bool shouldMove
= false;
1107 if ( rect
&& (dx
* dy
== 0 /* moving in only one of x, y axis */) )
1109 wxRect childRect
= child
->GetRect();
1110 if ( dx
== 0 && (childRect
.GetLeft() <= rect
->GetRight() ||
1111 childRect
.GetRight() >= rect
->GetLeft()) )
1115 else if ( dy
== 0 && (childRect
.GetTop() <= rect
->GetBottom() ||
1116 childRect
.GetBottom() >= rect
->GetTop()) )
1120 // else: child outside of scrolling shaft, don't move
1122 else // scrolling in both axes or rect=NULL
1128 child
->Move(child
->GetPosition() + offset
, wxSIZE_ALLOW_MINUS_ONE
);
1130 #endif // wxX11/!wxX11
1133 wxRect
wxWindow::ScrollNoRefresh(int dx
, int dy
, const wxRect
*rectTotal
)
1135 wxASSERT_MSG( !dx
|| !dy
, _T("can't be used for diag scrolling") );
1137 // the rect to refresh (which we will calculate)
1146 // calculate the part of the window which we can just redraw in the new
1148 wxSize sizeTotal
= rectTotal
? rectTotal
->GetSize() : GetClientSize();
1150 wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
1151 sizeTotal
.x
, sizeTotal
.y
, dx
, dy
);
1153 // the initial and end point of the region we move in client coords
1154 wxPoint ptSource
, ptDest
;
1157 ptSource
= rectTotal
->GetPosition();
1158 ptDest
= rectTotal
->GetPosition();
1161 // the size of this region
1163 size
.x
= sizeTotal
.x
- abs(dx
);
1164 size
.y
= sizeTotal
.y
- abs(dy
);
1165 if ( size
.x
<= 0 || size
.y
<= 0 )
1167 // just redraw everything as nothing of the displayed image will stay
1168 wxLogTrace(_T("scroll"), _T("refreshing everything"));
1170 rect
= rectTotal
? *rectTotal
: wxRect(0, 0, sizeTotal
.x
, sizeTotal
.y
);
1172 else // move the part which doesn't change to the new location
1174 // note that when we scroll the canvas in some direction we move the
1175 // block which doesn't need to be refreshed in the opposite direction
1179 // scroll to the right, move to the left
1184 // scroll to the left, move to the right
1190 // scroll down, move up
1195 // scroll up, move down
1200 // we need to hide the caret before moving or it will erase itself at
1201 // the wrong (old) location
1202 wxCaret
*caret
= GetCaret();
1205 #endif // wxUSE_CARET
1208 wxClientDC
dc(this);
1209 wxBitmap
bmp(size
.x
, size
.y
);
1211 dcMem
.SelectObject(bmp
);
1213 dcMem
.Blit(wxPoint(0,0), size
, &dc
, ptSource
1214 #if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
1215 + GetClientAreaOrigin()
1216 #endif // broken wxGTK wxDC::Blit
1218 dc
.Blit(ptDest
, size
, &dcMem
, wxPoint(0,0));
1220 wxLogTrace(_T("scroll"),
1221 _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
1222 ptSource
.x
, ptSource
.y
,
1224 ptDest
.x
, ptDest
.y
);
1226 // and now repaint the uncovered area
1228 // FIXME: We repaint the intersection of these rectangles twice - is
1229 // it bad? I don't think so as it is rare to scroll the window
1230 // diagonally anyhow and so adding extra logic to compute
1231 // rectangle intersection is probably not worth the effort
1233 rect
.x
= ptSource
.x
;
1234 rect
.y
= ptSource
.y
;
1240 // refresh the area along the right border
1241 rect
.x
+= size
.x
+ dx
;
1246 // refresh the area along the left border
1250 rect
.height
= sizeTotal
.y
;
1252 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1254 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1261 // refresh the area along the bottom border
1262 rect
.y
+= size
.y
+ dy
;
1267 // refresh the area along the top border
1271 rect
.width
= sizeTotal
.x
;
1273 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1275 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1281 #endif // wxUSE_CARET
1287 // ----------------------------------------------------------------------------
1288 // accelerators and menu hot keys
1289 // ----------------------------------------------------------------------------
1292 // the last window over which Alt was pressed (used by OnKeyUp)
1293 wxWindow
*wxWindow::ms_winLastAltPress
= NULL
;
1294 #endif // wxUSE_MENUS
1296 #if wxUSE_ACCEL || wxUSE_MENUS
1298 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1301 int key
= event
.GetKeyCode();
1302 if ( !event
.ControlDown() && (key
== WXK_ALT
|| key
== WXK_F10
) )
1304 ms_winLastAltPress
= this;
1306 // it can't be an accel anyhow
1310 ms_winLastAltPress
= NULL
;
1311 #endif // wxUSE_MENUS
1314 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
1316 int command
= win
->GetAcceleratorTable()->GetCommand(event
);
1317 if ( command
!= -1 )
1319 wxCommandEvent
eventCmd(wxEVT_COMMAND_MENU_SELECTED
, command
);
1320 if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) )
1322 // skip "event.Skip()" below
1327 if ( win
->IsTopLevel() )
1329 // try the frame menu bar
1331 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1334 wxMenuBar
*menubar
= frame
->GetMenuBar();
1335 if ( menubar
&& menubar
->ProcessAccelEvent(event
) )
1337 // skip "event.Skip()" below
1341 #endif // wxUSE_MENUS
1344 // if it wasn't in a menu, try to find a button
1345 if ( command
!= -1 )
1347 wxWindow
* child
= win
->FindWindow(command
);
1348 if ( child
&& wxDynamicCast(child
, wxButton
) )
1350 wxCommandEvent
eventCmd(wxEVT_COMMAND_BUTTON_CLICKED
, command
);
1351 eventCmd
.SetEventObject(child
);
1352 if ( child
->GetEventHandler()->ProcessEvent(eventCmd
) )
1354 // skip "event.Skip()" below
1359 #endif // wxUSE_BUTTON
1361 // don't propagate accels from the child frame to the parent one
1365 #endif // wxUSE_ACCEL
1370 #endif // wxUSE_ACCEL
1374 wxMenuBar
*wxWindow::GetParentFrameMenuBar() const
1376 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
1378 if ( win
->IsTopLevel() )
1380 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1383 return frame
->GetMenuBar();
1386 // don't look further - we don't want to return the menubar of the
1395 void wxWindow::OnChar(wxKeyEvent
& event
)
1397 if ( event
.AltDown() && !event
.ControlDown() )
1399 int key
= event
.GetKeyCode();
1401 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1404 int item
= menubar
->FindNextItemForAccel(-1, key
);
1407 menubar
->PopupMenu((size_t)item
);
1409 // skip "event.Skip()" below
1415 // if Return was pressed, see if there's a default button to activate
1416 if ( !event
.HasModifiers() && event
.GetKeyCode() == WXK_RETURN
)
1419 tlw
= wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow
);
1422 wxButton
*btn
= wxDynamicCast(tlw
->GetDefaultItem(), wxButton
);
1425 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, btn
->GetId());
1426 evt
.SetEventObject(btn
);
1437 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1439 int key
= event
.GetKeyCode();
1440 if ( !event
.HasModifiers() && (key
== WXK_ALT
|| key
== WXK_F10
) )
1442 // only process Alt release specially if there were no other key
1443 // presses since Alt had been pressed and if both events happened in
1445 if ( ms_winLastAltPress
== this )
1447 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1448 if ( menubar
&& this != menubar
)
1450 menubar
->SelectMenu(0);
1459 // in any case reset it
1460 ms_winLastAltPress
= NULL
;
1463 #endif // wxUSE_MENUS
1465 // ----------------------------------------------------------------------------
1466 // MSW-specific section
1467 // ----------------------------------------------------------------------------
1471 #include "wx/msw/private.h"
1473 WXLRESULT
wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1475 if ( message
== WM_NCHITTEST
)
1477 // the windows which contain the other windows should let the mouse
1478 // events through, otherwise a window inside a static box would
1479 // never get any events at all
1480 if ( IsStaticBox() )
1482 return HTTRANSPARENT
;
1486 return wxWindowNative::MSWWindowProc(message
, wParam
, lParam
);