1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/univ/winuniv.cpp
3 // Purpose: implementation of extra wxWindow methods for wxUniv port
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ===========================================================================
13 // ===========================================================================
15 // ---------------------------------------------------------------------------
17 // ---------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
26 #include "wx/window.h"
30 #include "wx/dcclient.h"
31 #include "wx/dcmemory.h"
33 #include "wx/scrolbar.h"
37 #include "wx/button.h"
40 #include "wx/univ/colschem.h"
41 #include "wx/univ/renderer.h"
42 #include "wx/univ/theme.h"
49 #if wxDEBUG_LEVEL >= 2
50 // turn Refresh() debugging on/off
51 #define WXDEBUG_REFRESH
54 #if defined(WXDEBUG_REFRESH) && defined(__WXMSW__) && !defined(__WXMICROWIN__)
55 #include "wx/msw/private.h"
58 // ============================================================================
60 // ============================================================================
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 // This is scrollbar class used to implement wxWindow's "built-in" scrollbars;
67 // unlike the standard wxScrollBar class, this one is positioned outside of its
68 // parent's client area
69 class wxWindowScrollBar
: public wxScrollBar
72 wxWindowScrollBar(wxWindow
*parent
,
74 const wxPoint
& pos
= wxDefaultPosition
,
75 const wxSize
& size
= wxDefaultSize
,
76 long style
= wxSB_HORIZONTAL
)
77 : wxScrollBar(parent
, id
, pos
, size
, style
)
81 virtual bool CanBeOutsideClientArea() const { return true; }
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
89 // we can't use wxWindowNative here as it won't be expanded inside the macro
90 #if defined(__WXMSW__)
91 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowMSW
)
92 #elif defined(__WXGTK__)
93 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowGTK
)
94 #elif defined(__WXOSX_OR_COCOA__)
95 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowMac
)
96 #elif defined(__WXDFB__)
97 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowDFB
)
98 #elif defined(__WXX11__)
99 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowX11
)
100 #elif defined(__WXPM__)
101 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowOS2
)
104 BEGIN_EVENT_TABLE(wxWindow
, wxWindowNative
)
105 EVT_SIZE(wxWindow::OnSize
)
107 #if wxUSE_ACCEL || wxUSE_MENUS
108 EVT_KEY_DOWN(wxWindow::OnKeyDown
)
109 #endif // wxUSE_ACCEL
112 EVT_CHAR(wxWindow::OnChar
)
113 EVT_KEY_UP(wxWindow::OnKeyUp
)
114 #endif // wxUSE_MENUS
116 EVT_PAINT(wxWindow::OnPaint
)
117 EVT_NC_PAINT(wxWindow::OnNcPaint
)
118 EVT_ERASE_BACKGROUND(wxWindow::OnErase
)
121 // ----------------------------------------------------------------------------
123 // ----------------------------------------------------------------------------
125 void wxWindow::Init()
129 m_scrollbarHorz
= NULL
;
130 #endif // wxUSE_SCROLLBAR
134 m_renderer
= wxTheme::Get()->GetRenderer();
136 m_oldSize
.x
= wxDefaultCoord
;
137 m_oldSize
.y
= wxDefaultCoord
;
140 bool wxWindow::Create(wxWindow
*parent
,
145 const wxString
& name
)
147 // Get default border
148 wxBorder border
= GetBorder(style
);
149 style
&= ~wxBORDER_MASK
;
152 long actualStyle
= style
;
154 // we add wxCLIP_CHILDREN to get the same ("natural") behaviour under MSW
155 // as under the other platforms
156 actualStyle
|= wxCLIP_CHILDREN
;
158 actualStyle
&= ~wxVSCROLL
;
159 actualStyle
&= ~wxHSCROLL
;
162 // without this, borders (non-client areas in general) are not repainted
163 // correctly when resizing; apparently, native NC areas are fully repainted
164 // even without this style by MSW, but wxUniv implements client area
165 // itself, so it doesn't work correctly for us
167 // FIXME: this is very expensive, we need to fix the (commented-out) code
168 // in OnSize() instead
169 actualStyle
|= wxFULL_REPAINT_ON_RESIZE
;
172 if ( !wxWindowNative::Create(parent
, id
, pos
, size
, actualStyle
, name
) )
175 // Set full style again, including those we didn't want present
176 // when calling the base window Create().
177 wxWindowBase::SetWindowStyleFlag(style
);
179 // if we allow or should always have a vertical scrollbar, make it
180 if ( style
& wxVSCROLL
|| style
& wxALWAYS_SHOW_SB
)
182 #if wxUSE_TWO_WINDOWS
183 SetInsertIntoMain( true );
186 m_scrollbarVert
= new wxWindowScrollBar(this, wxID_ANY
,
187 wxDefaultPosition
, wxDefaultSize
,
189 #endif // wxUSE_SCROLLBAR
190 #if wxUSE_TWO_WINDOWS
191 SetInsertIntoMain( false );
195 // if we should allow a horizontal scrollbar, make it
196 if ( style
& wxHSCROLL
)
198 #if wxUSE_TWO_WINDOWS
199 SetInsertIntoMain( true );
202 m_scrollbarHorz
= new wxWindowScrollBar(this, wxID_ANY
,
203 wxDefaultPosition
, wxDefaultSize
,
205 #endif // wxUSE_SCROLLBAR
206 #if wxUSE_TWO_WINDOWS
207 SetInsertIntoMain( false );
212 if (m_scrollbarHorz
|| m_scrollbarVert
)
215 PositionScrollbars();
217 #endif // wxUSE_SCROLLBAR
222 wxWindow::~wxWindow()
227 // clear pointers to scrollbar before deleting the children: they are
228 // children and so will be deleted by DestroyChildren() call below and if
229 // any code using the scrollbars would be called in the process or from
230 // ~wxWindowBase, the app would crash:
231 m_scrollbarVert
= m_scrollbarHorz
= NULL
;
234 // we have to destroy our children before we're destroyed because our
235 // children suppose that we're of type wxWindow, not just wxWindowNative,
236 // and so bad things may happen if they're deleted from the base class dtor
237 // as by then we're not a wxWindow any longer and wxUniv-specific virtual
238 // functions can't be called
242 // ----------------------------------------------------------------------------
244 // ----------------------------------------------------------------------------
246 void wxWindow::SetBackground(const wxBitmap
& bitmap
,
251 m_alignBgBitmap
= alignment
;
252 m_stretchBgBitmap
= stretch
;
255 const wxBitmap
& wxWindow::GetBackgroundBitmap(int *alignment
,
256 wxStretch
*stretch
) const
258 if ( m_bitmapBg
.IsOk() )
261 *alignment
= m_alignBgBitmap
;
263 *stretch
= m_stretchBgBitmap
;
269 // ----------------------------------------------------------------------------
271 // ----------------------------------------------------------------------------
273 // the event handlers executed when the window must be repainted
274 void wxWindow::OnNcPaint(wxNcPaintEvent
& WXUNUSED(event
))
278 // get the window rect
279 wxRect
rect(GetSize());
282 // if the scrollbars are outside the border, we must adjust the rect to
284 if ( !m_renderer
->AreScrollbarsInsideBorder() )
286 wxScrollBar
*scrollbar
= GetScrollbar(wxVERTICAL
);
288 rect
.width
-= scrollbar
->GetSize().x
;
290 scrollbar
= GetScrollbar(wxHORIZONTAL
);
292 rect
.height
-= scrollbar
->GetSize().y
;
294 #endif // wxUSE_SCROLLBAR
296 // get the DC and draw the border on it
298 DoDrawBorder(dc
, rect
);
302 void wxWindow::OnPaint(wxPaintEvent
& event
)
306 // it is a native control which paints itself
311 // get the DC to use and create renderer on it
313 wxControlRenderer
renderer(this, dc
, m_renderer
);
320 // the event handler executed when the window background must be painted
321 void wxWindow::OnErase(wxEraseEvent
& event
)
330 DoDrawBackground(*event
.GetDC());
333 // if we have both scrollbars, we also have a square in the corner between
334 // them which we must paint
335 if ( m_scrollbarVert
&& m_scrollbarHorz
)
337 wxSize size
= GetSize();
338 wxRect rectClient
= GetClientRect(),
339 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
342 rectCorner
.x
= rectClient
.GetRight() + 1;
343 rectCorner
.y
= rectClient
.GetBottom() + 1;
344 rectCorner
.SetRight(size
.x
- rectBorder
.width
);
345 rectCorner
.SetBottom(size
.y
- rectBorder
.height
);
347 if ( GetUpdateRegion().Contains(rectCorner
) )
349 m_renderer
->DrawScrollCorner(*event
.GetDC(), rectCorner
);
352 #endif // wxUSE_SCROLLBAR
355 bool wxWindow::DoDrawBackground(wxDC
& dc
)
359 wxSize size
= GetSize(); // Why not GetClientSize() ?
363 rect
.height
= size
.y
;
365 wxWindow
* const parent
= GetParent();
366 if ( HasTransparentBackground() && !UseBgCol() && parent
)
368 // DirectFB paints the parent first, then its child windows, so by
369 // the time this code is called, parent's background was already
370 // drawn and there's no point in (imperfectly!) duplicating the work
373 wxASSERT( !IsTopLevel() );
375 wxPoint pos
= GetPosition();
377 AdjustForParentClientOrigin( pos
.x
, pos
.y
, 0 );
379 // Adjust DC logical origin
380 wxCoord org_x
, org_y
, x
, y
;
381 dc
.GetLogicalOrigin( &org_x
, &org_y
);
384 dc
.SetLogicalOrigin( x
, y
);
390 // Let parent draw the background
391 parent
->EraseBackground( dc
, rect
);
393 // Restore DC logical origin
394 dc
.SetLogicalOrigin( org_x
, org_y
);
399 // Draw background ourselves
400 EraseBackground( dc
, rect
);
406 void wxWindow::EraseBackground(wxDC
& dc
, const wxRect
& rect
)
408 if ( GetBackgroundBitmap().IsOk() )
410 // Get the bitmap and the flags
413 wxBitmap bmp
= GetBackgroundBitmap(&alignment
, &stretch
);
414 wxControlRenderer::DrawBitmap(dc
, bmp
, rect
, alignment
, stretch
);
418 // Just fill it with bg colour if no bitmap
420 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this),
421 rect
, GetStateFlags());
425 void wxWindow::DoDrawBorder(wxDC
& dc
, const wxRect
& rect
)
427 // draw outline unless the update region is enitrely inside it in which
428 // case we don't need to do it
429 #if 0 // doesn't seem to work, why?
430 if ( wxRegion(rect
).Contains(GetUpdateRegion().GetBox()) != wxInRegion
)
433 m_renderer
->DrawBorder(dc
, GetBorder(), rect
, GetStateFlags());
437 void wxWindow::DoDraw(wxControlRenderer
* WXUNUSED(renderer
))
441 void wxWindow::Refresh(bool eraseBackground
, const wxRect
*rect
)
443 wxRect rectClient
; // the same rectangle in client coordinates
444 wxPoint origin
= GetClientAreaOrigin();
446 wxSize size
= GetClientSize();
450 // the rectangle passed as argument is in client coordinates
453 // don't refresh anything beyond the client area (scrollbars for
455 if ( rectClient
.GetRight() > size
.x
)
456 rectClient
.SetRight(size
.x
);
457 if ( rectClient
.GetBottom() > size
.y
)
458 rectClient
.SetBottom(size
.y
);
461 else // refresh the entire client area
463 // x,y is already set to 0 by default
464 rectClient
.SetSize(size
);
467 // convert refresh rectangle to window coordinates:
468 wxRect
rectWin(rectClient
);
469 rectWin
.Offset(origin
);
472 #ifdef WXDEBUG_REFRESH
473 static bool s_refreshDebug
= false;
474 if ( s_refreshDebug
)
477 dc
.SetBrush(*wxCYAN_BRUSH
);
478 dc
.SetPen(*wxTRANSPARENT_PEN
);
479 dc
.DrawRectangle(rectWin
);
481 // under Unix we use "--sync" X option for this
482 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
487 #endif // WXDEBUG_REFRESH
489 wxWindowNative::Refresh(eraseBackground
, &rectWin
);
491 // Refresh all sub controls if any.
492 wxWindowList
& children
= GetChildren();
493 for ( wxWindowList::iterator i
= children
.begin(); i
!= children
.end(); ++i
)
495 wxWindow
*child
= *i
;
496 // only refresh subcontrols if they are visible:
497 if ( child
->IsTopLevel() || !child
->IsShown() || child
->IsFrozen() )
500 // ...and when the subcontrols are in the update region:
501 wxRect
childrect(child
->GetRect());
502 childrect
.Intersect(rectClient
);
503 if ( childrect
.IsEmpty() )
506 // refresh the subcontrol now:
507 childrect
.Offset(-child
->GetPosition());
508 // NB: We must call wxWindowNative version because we need to refresh
509 // the entire control, not just its client area, and this is why we
510 // don't account for child client area origin here neither. Also
511 // note that we don't pass eraseBackground to the child, but use
512 // true instead: this is because we can't be sure that
513 // eraseBackground=false is safe for children as well and not only
515 child
->wxWindowNative::Refresh(eraseBackground
, &childrect
);
519 // ----------------------------------------------------------------------------
521 // ----------------------------------------------------------------------------
523 bool wxWindow::Enable(bool enable
)
525 if ( !wxWindowNative::Enable(enable
) )
528 // disabled window can't keep focus
529 if ( FindFocus() == this && GetParent() != NULL
)
531 GetParent()->SetFocus();
536 // a window with renderer is drawn by ourselves and it has to be
537 // refreshed to reflect its new status
544 bool wxWindow::IsFocused() const
546 return FindFocus() == this;
549 bool wxWindow::IsPressed() const
554 bool wxWindow::IsDefault() const
559 bool wxWindow::IsCurrent() const
564 bool wxWindow::SetCurrent(bool doit
)
566 if ( doit
== m_isCurrent
)
571 if ( CanBeHighlighted() )
577 int wxWindow::GetStateFlags() const
581 flags
|= wxCONTROL_DISABLED
;
583 // the following states are only possible if our application is active - if
584 // it is not, even our default/focused controls shouldn't appear as such
585 if ( wxTheApp
->IsActive() )
588 flags
|= wxCONTROL_CURRENT
;
590 flags
|= wxCONTROL_FOCUSED
;
592 flags
|= wxCONTROL_PRESSED
;
594 flags
|= wxCONTROL_ISDEFAULT
;
600 // ----------------------------------------------------------------------------
602 // ----------------------------------------------------------------------------
604 void wxWindow::OnSize(wxSizeEvent
& event
)
609 if ( m_scrollbarVert
|| m_scrollbarHorz
)
611 PositionScrollbars();
613 #endif // wxUSE_SCROLLBAR
615 #if 0 // ndef __WXMSW__
616 // Refresh the area (strip) previously occupied by the border
618 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) && IsShown() )
620 // This code assumes that wxSizeEvent.GetSize() returns
621 // the area of the entire window, not just the client
623 wxSize newSize
= event
.GetSize();
625 if (m_oldSize
.x
== wxDefaultCoord
&& m_oldSize
.y
== wxDefaultCoord
)
631 if (HasFlag( wxSIMPLE_BORDER
))
633 if (newSize
.y
> m_oldSize
.y
)
637 rect
.width
= m_oldSize
.x
;
638 rect
.y
= m_oldSize
.y
-2;
640 Refresh( true, &rect
);
642 else if (newSize
.y
< m_oldSize
.y
)
648 rect
.width
= newSize
.x
;
649 wxWindowNative::Refresh( true, &rect
);
652 if (newSize
.x
> m_oldSize
.x
)
656 rect
.height
= m_oldSize
.y
;
657 rect
.x
= m_oldSize
.x
-2;
659 Refresh( true, &rect
);
661 else if (newSize
.x
< m_oldSize
.x
)
667 rect
.height
= newSize
.y
;
668 wxWindowNative::Refresh( true, &rect
);
672 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
) || HasFlag( wxBORDER_THEME
))
674 if (newSize
.y
> m_oldSize
.y
)
678 rect
.width
= m_oldSize
.x
;
679 rect
.y
= m_oldSize
.y
-4;
681 Refresh( true, &rect
);
683 else if (newSize
.y
< m_oldSize
.y
)
689 rect
.width
= newSize
.x
;
690 wxWindowNative::Refresh( true, &rect
);
693 if (newSize
.x
> m_oldSize
.x
)
697 rect
.height
= m_oldSize
.y
;
698 rect
.x
= m_oldSize
.x
-4;
700 Refresh( true, &rect
);
702 else if (newSize
.x
< m_oldSize
.x
)
708 rect
.height
= newSize
.y
;
709 wxWindowNative::Refresh( true, &rect
);
718 wxSize
wxWindow::DoGetBorderSize() const
720 return AdjustSize(wxSize(0, 0));
723 wxSize
wxWindow::AdjustSize(const wxSize
& size
) const
727 m_renderer
->AdjustSize(&sz
, this);
731 wxPoint
wxWindow::GetClientAreaOrigin() const
733 wxPoint pt
= wxWindowBase::GetClientAreaOrigin();
735 #if wxUSE_TWO_WINDOWS
738 pt
+= m_renderer
->GetBorderDimensions(GetBorder()).GetPosition();
744 void wxWindow::DoGetClientSize(int *width
, int *height
) const
746 // if it is a native window, we assume it handles the scrollbars itself
747 // too - and if it doesn't, there is not much we can do
750 wxWindowNative::DoGetClientSize(width
, height
);
756 wxWindowNative::DoGetClientSize(&w
, &h
);
758 // we assume that the scrollbars are positioned correctly (by a previous
759 // call to PositionScrollbars()) here
763 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
768 // in any case, take account of the scrollbar
769 if ( m_scrollbarVert
)
770 w
-= m_scrollbarVert
->GetSize().x
;
771 #endif // wxUSE_SCROLLBAR
773 // account for the left and right borders
774 *width
= w
- rectBorder
.x
- rectBorder
.width
;
776 // we shouldn't return invalid width
784 if ( m_scrollbarHorz
)
785 h
-= m_scrollbarHorz
->GetSize().y
;
786 #endif // wxUSE_SCROLLBAR
788 *height
= h
- rectBorder
.y
- rectBorder
.height
;
790 // we shouldn't return invalid height
796 void wxWindow::DoSetClientSize(int width
, int height
)
798 // take into account the borders
799 wxRect rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
800 width
+= rectBorder
.x
;
801 height
+= rectBorder
.y
;
803 // and the scrollbars (as they may be offset into the border, use the
804 // scrollbar position, not size - this supposes that PositionScrollbars()
805 // had been called before)
806 wxSize size
= GetSize();
808 if ( m_scrollbarVert
)
809 width
+= size
.x
- m_scrollbarVert
->GetPosition().x
;
810 #endif // wxUSE_SCROLLBAR
811 width
+= rectBorder
.width
;
814 if ( m_scrollbarHorz
)
815 height
+= size
.y
- m_scrollbarHorz
->GetPosition().y
;
816 #endif // wxUSE_SCROLLBAR
817 height
+= rectBorder
.height
;
819 wxWindowNative::DoSetClientSize(width
, height
);
822 wxHitTest
wxWindow::DoHitTest(wxCoord x
, wxCoord y
) const
824 wxHitTest ht
= wxWindowNative::DoHitTest(x
, y
);
827 if ( ht
== wxHT_WINDOW_INSIDE
)
829 if ( m_scrollbarVert
&& x
>= m_scrollbarVert
->GetPosition().x
)
831 // it can still be changed below because it may also be the corner
832 ht
= wxHT_WINDOW_VERT_SCROLLBAR
;
835 if ( m_scrollbarHorz
&& y
>= m_scrollbarHorz
->GetPosition().y
)
837 ht
= ht
== wxHT_WINDOW_VERT_SCROLLBAR
? wxHT_WINDOW_CORNER
838 : wxHT_WINDOW_HORZ_SCROLLBAR
;
841 #endif // wxUSE_SCROLLBAR
846 // ----------------------------------------------------------------------------
847 // scrolling: we implement it entirely ourselves except for ScrollWindow()
848 // function which is supposed to be (efficiently) implemented by the native
850 // ----------------------------------------------------------------------------
852 void wxWindow::RefreshScrollbars()
855 if ( m_scrollbarHorz
)
856 m_scrollbarHorz
->Refresh();
858 if ( m_scrollbarVert
)
859 m_scrollbarVert
->Refresh();
860 #endif // wxUSE_SCROLLBAR
863 void wxWindow::PositionScrollbars()
866 // do not use GetClientSize/Rect as it relies on the scrollbars being
867 // correctly positioned
869 wxSize size
= GetSize();
870 wxBorder border
= GetBorder();
871 wxRect rectBorder
= m_renderer
->GetBorderDimensions(border
);
872 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
874 int height
= m_scrollbarHorz
? m_scrollbarHorz
->GetSize().y
: 0;
875 int width
= m_scrollbarVert
? m_scrollbarVert
->GetSize().x
: 0;
878 if ( m_scrollbarVert
)
880 rectBar
.x
= size
.x
- width
;
882 rectBar
.x
-= rectBorder
.width
;
883 rectBar
.width
= width
;
886 rectBar
.y
+= rectBorder
.y
;
887 rectBar
.height
= size
.y
- height
;
889 rectBar
.height
-= rectBorder
.y
+ rectBorder
.height
;
891 m_scrollbarVert
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
894 if ( m_scrollbarHorz
)
896 rectBar
.y
= size
.y
- height
;
898 rectBar
.y
-= rectBorder
.height
;
899 rectBar
.height
= height
;
902 rectBar
.x
+= rectBorder
.x
;
903 rectBar
.width
= size
.x
- width
;
905 rectBar
.width
-= rectBorder
.x
+ rectBorder
.width
;
907 m_scrollbarHorz
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
911 #endif // wxUSE_SCROLLBAR
914 void wxWindow::SetScrollbar(int orient
,
921 wxASSERT_MSG( pageSize
<= range
,
922 wxT("page size can't be greater than range") );
924 bool hasClientSizeChanged
= false;
925 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
926 if ( range
&& (pageSize
< range
) )
931 #if wxUSE_TWO_WINDOWS
932 SetInsertIntoMain( true );
934 scrollbar
= new wxWindowScrollBar(this, wxID_ANY
,
935 wxDefaultPosition
, wxDefaultSize
,
936 orient
& wxVERTICAL
? wxSB_VERTICAL
938 #if wxUSE_TWO_WINDOWS
939 SetInsertIntoMain( false );
941 if ( orient
& wxVERTICAL
)
942 m_scrollbarVert
= scrollbar
;
944 m_scrollbarHorz
= scrollbar
;
946 // the client area diminished as we created a scrollbar
947 hasClientSizeChanged
= true;
949 PositionScrollbars();
951 else if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
953 // we might have disabled it before
957 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
959 else // no range means no scrollbar
963 // wxALWAYS_SHOW_SB only applies to the vertical scrollbar
964 if ( (orient
& wxVERTICAL
) && (GetWindowStyle() & wxALWAYS_SHOW_SB
) )
966 // just disable the scrollbar
967 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
968 scrollbar
->Disable();
970 else // really remove the scrollbar
974 if ( orient
& wxVERTICAL
)
975 m_scrollbarVert
= NULL
;
977 m_scrollbarHorz
= NULL
;
979 // the client area increased as we removed a scrollbar
980 hasClientSizeChanged
= true;
982 // the size of the remaining scrollbar must be adjusted
983 if ( m_scrollbarHorz
|| m_scrollbarVert
)
985 PositionScrollbars();
991 // give the window a chance to relayout
992 if ( hasClientSizeChanged
)
994 #if wxUSE_TWO_WINDOWS
995 wxWindowNative::SetSize( GetSize() );
997 wxSizeEvent
event(GetSize());
998 (void)GetEventHandler()->ProcessEvent(event
);
1002 wxUnusedVar(orient
);
1004 wxUnusedVar(pageSize
);
1006 wxUnusedVar(refresh
);
1007 #endif // wxUSE_SCROLLBAR
1010 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1013 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
1016 scrollbar
->SetThumbPosition(pos
);
1018 // VZ: I think we can safely ignore this as we always refresh it
1019 // automatically whenever the value chanegs
1025 wxUnusedVar(orient
);
1027 #endif // wxUSE_SCROLLBAR
1030 int wxWindow::GetScrollPos(int orient
) const
1033 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
1034 return scrollbar
? scrollbar
->GetThumbPosition() : 0;
1036 wxUnusedVar(orient
);
1038 #endif // wxUSE_SCROLLBAR
1041 int wxWindow::GetScrollThumb(int orient
) const
1044 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
1045 return scrollbar
? scrollbar
->GetThumbSize() : 0;
1047 wxUnusedVar(orient
);
1049 #endif // wxUSE_SCROLLBAR
1052 int wxWindow::GetScrollRange(int orient
) const
1055 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
1056 return scrollbar
? scrollbar
->GetRange() : 0;
1058 wxUnusedVar(orient
);
1060 #endif // wxUSE_SCROLLBAR
1063 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1065 // use native scrolling when available and do it in generic way
1069 wxWindowNative::ScrollWindow(dx
, dy
, rect
);
1073 // before scrolling it, ensure that we don't have any unpainted areas
1080 r
= ScrollNoRefresh(dx
, 0, rect
);
1081 Refresh(true /* erase bkgnd */, &r
);
1086 r
= ScrollNoRefresh(0, dy
, rect
);
1087 Refresh(true /* erase bkgnd */, &r
);
1090 // scroll children accordingly:
1091 wxPoint
offset(dx
, dy
);
1093 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1094 node
; node
= node
->GetNext())
1096 wxWindow
*child
= node
->GetData();
1098 if ( child
== m_scrollbarVert
|| child
== m_scrollbarHorz
)
1100 #endif // wxUSE_SCROLLBAR
1102 // VS: Scrolling children has non-trivial semantics. If rect=NULL then
1103 // it is easy: we scroll all children. Otherwise it gets
1105 // 1. if scrolling in one direction only, scroll only
1106 // those children that intersect shaft defined by the rectangle
1107 // and scrolling direction
1108 // 2. if scrolling in both axes, scroll all children
1110 bool shouldMove
= false;
1112 if ( rect
&& (dx
* dy
== 0 /* moving in only one of x, y axis */) )
1114 wxRect childRect
= child
->GetRect();
1115 if ( dx
== 0 && (childRect
.GetLeft() <= rect
->GetRight() ||
1116 childRect
.GetRight() >= rect
->GetLeft()) )
1120 else if ( dy
== 0 && (childRect
.GetTop() <= rect
->GetBottom() ||
1121 childRect
.GetBottom() >= rect
->GetTop()) )
1125 // else: child outside of scrolling shaft, don't move
1127 else // scrolling in both axes or rect=NULL
1133 child
->Move(child
->GetPosition() + offset
, wxSIZE_ALLOW_MINUS_ONE
);
1135 #endif // wxX11/!wxX11
1138 wxRect
wxWindow::ScrollNoRefresh(int dx
, int dy
, const wxRect
*rectTotal
)
1140 wxASSERT_MSG( !dx
|| !dy
, wxT("can't be used for diag scrolling") );
1142 // the rect to refresh (which we will calculate)
1151 // calculate the part of the window which we can just redraw in the new
1153 wxSize sizeTotal
= rectTotal
? rectTotal
->GetSize() : GetClientSize();
1155 wxLogTrace(wxT("scroll"), wxT("rect is %dx%d, scroll by %d, %d"),
1156 sizeTotal
.x
, sizeTotal
.y
, dx
, dy
);
1158 // the initial and end point of the region we move in client coords
1159 wxPoint ptSource
, ptDest
;
1162 ptSource
= rectTotal
->GetPosition();
1163 ptDest
= rectTotal
->GetPosition();
1166 // the size of this region
1168 size
.x
= sizeTotal
.x
- abs(dx
);
1169 size
.y
= sizeTotal
.y
- abs(dy
);
1170 if ( size
.x
<= 0 || size
.y
<= 0 )
1172 // just redraw everything as nothing of the displayed image will stay
1173 wxLogTrace(wxT("scroll"), wxT("refreshing everything"));
1175 rect
= rectTotal
? *rectTotal
: wxRect(0, 0, sizeTotal
.x
, sizeTotal
.y
);
1177 else // move the part which doesn't change to the new location
1179 // note that when we scroll the canvas in some direction we move the
1180 // block which doesn't need to be refreshed in the opposite direction
1184 // scroll to the right, move to the left
1189 // scroll to the left, move to the right
1195 // scroll down, move up
1200 // scroll up, move down
1205 // we need to hide the caret before moving or it will erase itself at
1206 // the wrong (old) location
1207 wxCaret
*caret
= GetCaret();
1210 #endif // wxUSE_CARET
1213 wxClientDC
dc(this);
1214 wxBitmap
bmp(size
.x
, size
.y
);
1216 dcMem
.SelectObject(bmp
);
1218 dcMem
.Blit(wxPoint(0,0), size
, &dc
, ptSource
1219 #if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
1220 + GetClientAreaOrigin()
1221 #endif // broken wxGTK wxDC::Blit
1223 dc
.Blit(ptDest
, size
, &dcMem
, wxPoint(0,0));
1225 wxLogTrace(wxT("scroll"),
1226 wxT("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
1227 ptSource
.x
, ptSource
.y
,
1229 ptDest
.x
, ptDest
.y
);
1231 // and now repaint the uncovered area
1233 // FIXME: We repaint the intersection of these rectangles twice - is
1234 // it bad? I don't think so as it is rare to scroll the window
1235 // diagonally anyhow and so adding extra logic to compute
1236 // rectangle intersection is probably not worth the effort
1238 rect
.x
= ptSource
.x
;
1239 rect
.y
= ptSource
.y
;
1245 // refresh the area along the right border
1246 rect
.x
+= size
.x
+ dx
;
1251 // refresh the area along the left border
1255 rect
.height
= sizeTotal
.y
;
1257 wxLogTrace(wxT("scroll"), wxT("refreshing (%d, %d)-(%d, %d)"),
1259 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1266 // refresh the area along the bottom border
1267 rect
.y
+= size
.y
+ dy
;
1272 // refresh the area along the top border
1276 rect
.width
= sizeTotal
.x
;
1278 wxLogTrace(wxT("scroll"), wxT("refreshing (%d, %d)-(%d, %d)"),
1280 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1286 #endif // wxUSE_CARET
1292 // ----------------------------------------------------------------------------
1293 // accelerators and menu hot keys
1294 // ----------------------------------------------------------------------------
1297 // the last window over which Alt was pressed (used by OnKeyUp)
1298 wxWindow
*wxWindow::ms_winLastAltPress
= NULL
;
1299 #endif // wxUSE_MENUS
1301 #if wxUSE_ACCEL || wxUSE_MENUS
1303 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1306 int key
= event
.GetKeyCode();
1307 if ( !event
.ControlDown() && (key
== WXK_ALT
|| key
== WXK_F10
) )
1309 ms_winLastAltPress
= this;
1311 // it can't be an accel anyhow
1315 ms_winLastAltPress
= NULL
;
1316 #endif // wxUSE_MENUS
1319 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
1321 int command
= win
->GetAcceleratorTable()->GetCommand(event
);
1322 if ( command
!= -1 )
1324 wxCommandEvent
eventCmd(wxEVT_MENU
, command
);
1325 if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) )
1327 // skip "event.Skip()" below
1332 if ( win
->IsTopLevel() )
1334 // try the frame menu bar
1336 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1339 wxMenuBar
*menubar
= frame
->GetMenuBar();
1340 if ( menubar
&& menubar
->ProcessAccelEvent(event
) )
1342 // skip "event.Skip()" below
1346 #endif // wxUSE_MENUS
1349 // if it wasn't in a menu, try to find a button
1350 if ( command
!= -1 )
1352 wxWindow
* child
= win
->FindWindow(command
);
1353 if ( child
&& wxDynamicCast(child
, wxButton
) )
1355 wxCommandEvent
eventCmd(wxEVT_BUTTON
, command
);
1356 eventCmd
.SetEventObject(child
);
1357 if ( child
->GetEventHandler()->ProcessEvent(eventCmd
) )
1359 // skip "event.Skip()" below
1364 #endif // wxUSE_BUTTON
1366 // don't propagate accels from the child frame to the parent one
1370 #endif // wxUSE_ACCEL
1375 #endif // wxUSE_ACCEL
1379 wxMenuBar
*wxWindow::GetParentFrameMenuBar() const
1381 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
1383 if ( win
->IsTopLevel() )
1385 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1388 return frame
->GetMenuBar();
1391 // don't look further - we don't want to return the menubar of the
1400 void wxWindow::OnChar(wxKeyEvent
& event
)
1402 if ( event
.AltDown() && !event
.ControlDown() )
1404 int key
= event
.GetKeyCode();
1406 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1409 int item
= menubar
->FindNextItemForAccel(-1, key
);
1412 menubar
->PopupMenu((size_t)item
);
1414 // skip "event.Skip()" below
1420 // if Return was pressed, see if there's a default button to activate
1421 if ( !event
.HasModifiers() && event
.GetKeyCode() == WXK_RETURN
)
1424 tlw
= wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow
);
1427 wxButton
*btn
= wxDynamicCast(tlw
->GetDefaultItem(), wxButton
);
1430 wxCommandEvent
evt(wxEVT_BUTTON
, btn
->GetId());
1431 evt
.SetEventObject(btn
);
1442 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1444 int key
= event
.GetKeyCode();
1445 if ( !event
.HasModifiers() && (key
== WXK_ALT
|| key
== WXK_F10
) )
1447 // only process Alt release specially if there were no other key
1448 // presses since Alt had been pressed and if both events happened in
1450 if ( ms_winLastAltPress
== this )
1452 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1453 if ( menubar
&& this != menubar
)
1455 menubar
->SelectMenu(0);
1464 // in any case reset it
1465 ms_winLastAltPress
= NULL
;
1468 #endif // wxUSE_MENUS
1470 // ----------------------------------------------------------------------------
1471 // MSW-specific section
1472 // ----------------------------------------------------------------------------
1476 #include "wx/msw/private.h"
1478 WXLRESULT
wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1480 if ( message
== WM_NCHITTEST
)
1482 // the windows which contain the other windows should let the mouse
1483 // events through, otherwise a window inside a static box would
1484 // never get any events at all
1485 if ( IsStaticBox() )
1487 return HTTRANSPARENT
;
1491 return wxWindowNative::MSWWindowProc(message
, wParam
, lParam
);