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 // Get default border
149 wxBorder border
= GetBorder(style
);
150 style
&= ~wxBORDER_MASK
;
153 long actualStyle
= style
;
155 // we add wxCLIP_CHILDREN to get the same ("natural") behaviour under MSW
156 // as under the other platforms
157 actualStyle
|= wxCLIP_CHILDREN
;
159 actualStyle
&= ~wxVSCROLL
;
160 actualStyle
&= ~wxHSCROLL
;
163 // without this, borders (non-client areas in general) are not repainted
164 // correctly when resizing; apparently, native NC areas are fully repainted
165 // even without this style by MSW, but wxUniv implements client area
166 // itself, so it doesn't work correctly for us
168 // FIXME: this is very expensive, we need to fix the (commented-out) code
169 // in OnSize() instead
170 actualStyle
|= wxFULL_REPAINT_ON_RESIZE
;
173 if ( !wxWindowNative::Create(parent
, id
, pos
, size
, actualStyle
, name
) )
176 // Set full style again, including those we didn't want present
177 // when calling the base window Create().
178 wxWindowBase::SetWindowStyleFlag(style
);
180 // if we allow or should always have a vertical scrollbar, make it
181 if ( style
& wxVSCROLL
|| style
& wxALWAYS_SHOW_SB
)
183 #if wxUSE_TWO_WINDOWS
184 SetInsertIntoMain( true );
187 m_scrollbarVert
= new wxWindowScrollBar(this, wxID_ANY
,
188 wxDefaultPosition
, wxDefaultSize
,
190 #endif // wxUSE_SCROLLBAR
191 #if wxUSE_TWO_WINDOWS
192 SetInsertIntoMain( false );
196 // if we should allow a horizontal scrollbar, make it
197 if ( style
& wxHSCROLL
)
199 #if wxUSE_TWO_WINDOWS
200 SetInsertIntoMain( true );
203 m_scrollbarHorz
= new wxWindowScrollBar(this, wxID_ANY
,
204 wxDefaultPosition
, wxDefaultSize
,
206 #endif // wxUSE_SCROLLBAR
207 #if wxUSE_TWO_WINDOWS
208 SetInsertIntoMain( false );
213 if (m_scrollbarHorz
|| m_scrollbarVert
)
216 PositionScrollbars();
218 #endif // wxUSE_SCROLLBAR
223 wxWindow::~wxWindow()
225 m_isBeingDeleted
= true;
228 // clear pointers to scrollbar before deleting the children: they are
229 // children and so will be deleted by DestroyChildren() call below and if
230 // any code using the scrollbars would be called in the process or from
231 // ~wxWindowBase, the app would crash:
232 m_scrollbarVert
= m_scrollbarHorz
= NULL
;
235 // we have to destroy our children before we're destroyed because our
236 // children suppose that we're of type wxWindow, not just wxWindowNative,
237 // and so bad things may happen if they're deleted from the base class dtor
238 // as by then we're not a wxWindow any longer and wxUniv-specific virtual
239 // functions can't be called
243 // ----------------------------------------------------------------------------
245 // ----------------------------------------------------------------------------
247 void wxWindow::SetBackground(const wxBitmap
& bitmap
,
252 m_alignBgBitmap
= alignment
;
253 m_stretchBgBitmap
= stretch
;
256 const wxBitmap
& wxWindow::GetBackgroundBitmap(int *alignment
,
257 wxStretch
*stretch
) const
259 if ( m_bitmapBg
.Ok() )
262 *alignment
= m_alignBgBitmap
;
264 *stretch
= m_stretchBgBitmap
;
270 // ----------------------------------------------------------------------------
272 // ----------------------------------------------------------------------------
274 // the event handlers executed when the window must be repainted
275 void wxWindow::OnNcPaint(wxNcPaintEvent
& WXUNUSED(event
))
279 // get the window rect
280 wxRect
rect(GetSize());
283 // if the scrollbars are outside the border, we must adjust the rect to
285 if ( !m_renderer
->AreScrollbarsInsideBorder() )
287 wxScrollBar
*scrollbar
= GetScrollbar(wxVERTICAL
);
289 rect
.width
-= scrollbar
->GetSize().x
;
291 scrollbar
= GetScrollbar(wxHORIZONTAL
);
293 rect
.height
-= scrollbar
->GetSize().y
;
295 #endif // wxUSE_SCROLLBAR
297 // get the DC and draw the border on it
299 DoDrawBorder(dc
, rect
);
303 void wxWindow::OnPaint(wxPaintEvent
& event
)
307 // it is a native control which paints itself
312 // get the DC to use and create renderer on it
314 wxControlRenderer
renderer(this, dc
, m_renderer
);
321 // the event handler executed when the window background must be painted
322 void wxWindow::OnErase(wxEraseEvent
& event
)
331 DoDrawBackground(*event
.GetDC());
334 // if we have both scrollbars, we also have a square in the corner between
335 // them which we must paint
336 if ( m_scrollbarVert
&& m_scrollbarHorz
)
338 wxSize size
= GetSize();
339 wxRect rectClient
= GetClientRect(),
340 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
343 rectCorner
.x
= rectClient
.GetRight() + 1;
344 rectCorner
.y
= rectClient
.GetBottom() + 1;
345 rectCorner
.SetRight(size
.x
- rectBorder
.width
);
346 rectCorner
.SetBottom(size
.y
- rectBorder
.height
);
348 if ( GetUpdateRegion().Contains(rectCorner
) )
350 m_renderer
->DrawScrollCorner(*event
.GetDC(), rectCorner
);
353 #endif // wxUSE_SCROLLBAR
356 bool wxWindow::DoDrawBackground(wxDC
& dc
)
360 wxSize size
= GetSize(); // Why not GetClientSize() ?
364 rect
.height
= size
.y
;
366 wxWindow
* const parent
= GetParent();
367 if ( HasTransparentBackground() && !UseBgCol() && parent
)
369 // DirectFB paints the parent first, then its child windows, so by
370 // the time this code is called, parent's background was already
371 // drawn and there's no point in (imperfectly!) duplicating the work
374 wxASSERT( !IsTopLevel() );
376 wxPoint pos
= GetPosition();
378 AdjustForParentClientOrigin( pos
.x
, pos
.y
, 0 );
380 // Adjust DC logical origin
381 wxCoord org_x
, org_y
, x
, y
;
382 dc
.GetLogicalOrigin( &org_x
, &org_y
);
385 dc
.SetLogicalOrigin( x
, y
);
391 // Let parent draw the background
392 parent
->EraseBackground( dc
, rect
);
394 // Restore DC logical origin
395 dc
.SetLogicalOrigin( org_x
, org_y
);
400 // Draw background ourselves
401 EraseBackground( dc
, rect
);
407 void wxWindow::EraseBackground(wxDC
& dc
, const wxRect
& rect
)
409 if ( GetBackgroundBitmap().Ok() )
411 // Get the bitmap and the flags
414 wxBitmap bmp
= GetBackgroundBitmap(&alignment
, &stretch
);
415 wxControlRenderer::DrawBitmap(dc
, bmp
, rect
, alignment
, stretch
);
419 // Just fill it with bg colour if no bitmap
421 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this),
422 rect
, GetStateFlags());
426 void wxWindow::DoDrawBorder(wxDC
& dc
, const wxRect
& rect
)
428 // draw outline unless the update region is enitrely inside it in which
429 // case we don't need to do it
430 #if 0 // doesn't seem to work, why?
431 if ( wxRegion(rect
).Contains(GetUpdateRegion().GetBox()) != wxInRegion
)
434 m_renderer
->DrawBorder(dc
, GetBorder(), rect
, GetStateFlags());
438 void wxWindow::DoDraw(wxControlRenderer
* WXUNUSED(renderer
))
442 void wxWindow::Refresh(bool eraseBackground
, const wxRect
*rect
)
444 wxRect rectClient
; // the same rectangle in client coordinates
445 wxPoint origin
= GetClientAreaOrigin();
447 wxSize size
= GetClientSize();
451 // the rectangle passed as argument is in client coordinates
454 // don't refresh anything beyond the client area (scrollbars for
456 if ( rectClient
.GetRight() > size
.x
)
457 rectClient
.SetRight(size
.x
);
458 if ( rectClient
.GetBottom() > size
.y
)
459 rectClient
.SetBottom(size
.y
);
462 else // refresh the entire client area
464 // x,y is already set to 0 by default
465 rectClient
.SetSize(size
);
468 // convert refresh rectangle to window coordinates:
469 wxRect
rectWin(rectClient
);
470 rectWin
.Offset(origin
);
473 #ifdef WXDEBUG_REFRESH
474 static bool s_refreshDebug
= false;
475 if ( s_refreshDebug
)
478 dc
.SetBrush(*wxCYAN_BRUSH
);
479 dc
.SetPen(*wxTRANSPARENT_PEN
);
480 dc
.DrawRectangle(rectWin
);
482 // under Unix we use "--sync" X option for this
483 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
488 #endif // WXDEBUG_REFRESH
490 wxWindowNative::Refresh(eraseBackground
, &rectWin
);
492 // Refresh all sub controls if any.
493 wxWindowList
& children
= GetChildren();
494 for ( wxWindowList::iterator i
= children
.begin(); i
!= children
.end(); ++i
)
496 wxWindow
*child
= *i
;
497 // only refresh subcontrols if they are visible:
498 if ( child
->IsTopLevel() || !child
->IsShown() || child
->IsFrozen() )
501 // ...and when the subcontrols are in the update region:
502 wxRect
childrect(child
->GetRect());
503 childrect
.Intersect(rectClient
);
504 if ( childrect
.IsEmpty() )
507 // refresh the subcontrol now:
508 childrect
.Offset(-child
->GetPosition());
509 // NB: We must call wxWindowNative version because we need to refresh
510 // the entire control, not just its client area, and this is why we
511 // don't account for child client area origin here neither. Also
512 // note that we don't pass eraseBackground to the child, but use
513 // true instead: this is because we can't be sure that
514 // eraseBackground=false is safe for children as well and not only
516 child
->wxWindowNative::Refresh(eraseBackground
, &childrect
);
520 // ----------------------------------------------------------------------------
522 // ----------------------------------------------------------------------------
524 bool wxWindow::Enable(bool enable
)
526 if ( !wxWindowNative::Enable(enable
) )
529 // disabled window can't keep focus
530 if ( FindFocus() == this && GetParent() != NULL
)
532 GetParent()->SetFocus();
537 // a window with renderer is drawn by ourselves and it has to be
538 // refreshed to reflect its new status
545 bool wxWindow::IsFocused() const
547 return FindFocus() == this;
550 bool wxWindow::IsPressed() const
555 bool wxWindow::IsDefault() const
560 bool wxWindow::IsCurrent() const
565 bool wxWindow::SetCurrent(bool doit
)
567 if ( doit
== m_isCurrent
)
572 if ( CanBeHighlighted() )
578 int wxWindow::GetStateFlags() const
582 flags
|= wxCONTROL_DISABLED
;
584 // the following states are only possible if our application is active - if
585 // it is not, even our default/focused controls shouldn't appear as such
586 if ( wxTheApp
->IsActive() )
589 flags
|= wxCONTROL_CURRENT
;
591 flags
|= wxCONTROL_FOCUSED
;
593 flags
|= wxCONTROL_PRESSED
;
595 flags
|= wxCONTROL_ISDEFAULT
;
601 // ----------------------------------------------------------------------------
603 // ----------------------------------------------------------------------------
605 void wxWindow::OnSize(wxSizeEvent
& event
)
610 if ( m_scrollbarVert
|| m_scrollbarHorz
)
612 PositionScrollbars();
614 #endif // wxUSE_SCROLLBAR
616 #if 0 // ndef __WXMSW__
617 // Refresh the area (strip) previously occupied by the border
619 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) && IsShown() )
621 // This code assumes that wxSizeEvent.GetSize() returns
622 // the area of the entire window, not just the client
624 wxSize newSize
= event
.GetSize();
626 if (m_oldSize
.x
== wxDefaultCoord
&& m_oldSize
.y
== wxDefaultCoord
)
632 if (HasFlag( wxSIMPLE_BORDER
))
634 if (newSize
.y
> m_oldSize
.y
)
638 rect
.width
= m_oldSize
.x
;
639 rect
.y
= m_oldSize
.y
-2;
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
-2;
660 Refresh( true, &rect
);
662 else if (newSize
.x
< m_oldSize
.x
)
668 rect
.height
= newSize
.y
;
669 wxWindowNative::Refresh( true, &rect
);
673 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
) || HasFlag( wxBORDER_THEME
))
675 if (newSize
.y
> m_oldSize
.y
)
679 rect
.width
= m_oldSize
.x
;
680 rect
.y
= m_oldSize
.y
-4;
682 Refresh( true, &rect
);
684 else if (newSize
.y
< m_oldSize
.y
)
690 rect
.width
= newSize
.x
;
691 wxWindowNative::Refresh( true, &rect
);
694 if (newSize
.x
> m_oldSize
.x
)
698 rect
.height
= m_oldSize
.y
;
699 rect
.x
= m_oldSize
.x
-4;
701 Refresh( true, &rect
);
703 else if (newSize
.x
< m_oldSize
.x
)
709 rect
.height
= newSize
.y
;
710 wxWindowNative::Refresh( true, &rect
);
719 wxSize
wxWindow::DoGetBestSize() const
721 return AdjustSize(DoGetBestClientSize());
724 wxSize
wxWindow::DoGetBestClientSize() const
726 return wxWindowNative::DoGetBestSize();
729 wxSize
wxWindow::AdjustSize(const wxSize
& size
) const
733 m_renderer
->AdjustSize(&sz
, this);
737 wxPoint
wxWindow::GetClientAreaOrigin() const
739 wxPoint pt
= wxWindowBase::GetClientAreaOrigin();
741 #if wxUSE_TWO_WINDOWS
744 pt
+= m_renderer
->GetBorderDimensions(GetBorder()).GetPosition();
750 void wxWindow::DoGetClientSize(int *width
, int *height
) const
752 // if it is a native window, we assume it handles the scrollbars itself
753 // too - and if it doesn't, there is not much we can do
756 wxWindowNative::DoGetClientSize(width
, height
);
762 wxWindowNative::DoGetClientSize(&w
, &h
);
764 // we assume that the scrollbars are positioned correctly (by a previous
765 // call to PositionScrollbars()) here
769 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
774 // in any case, take account of the scrollbar
775 if ( m_scrollbarVert
)
776 w
-= m_scrollbarVert
->GetSize().x
;
777 #endif // wxUSE_SCROLLBAR
779 // account for the left and right borders
780 *width
= w
- rectBorder
.x
- rectBorder
.width
;
782 // we shouldn't return invalid width
790 if ( m_scrollbarHorz
)
791 h
-= m_scrollbarHorz
->GetSize().y
;
792 #endif // wxUSE_SCROLLBAR
794 *height
= h
- rectBorder
.y
- rectBorder
.height
;
796 // we shouldn't return invalid height
802 void wxWindow::DoSetClientSize(int width
, int height
)
804 // take into account the borders
805 wxRect rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
806 width
+= rectBorder
.x
;
807 height
+= rectBorder
.y
;
809 // and the scrollbars (as they may be offset into the border, use the
810 // scrollbar position, not size - this supposes that PositionScrollbars()
811 // had been called before)
812 wxSize size
= GetSize();
814 if ( m_scrollbarVert
)
815 width
+= size
.x
- m_scrollbarVert
->GetPosition().x
;
816 #endif // wxUSE_SCROLLBAR
817 width
+= rectBorder
.width
;
820 if ( m_scrollbarHorz
)
821 height
+= size
.y
- m_scrollbarHorz
->GetPosition().y
;
822 #endif // wxUSE_SCROLLBAR
823 height
+= rectBorder
.height
;
825 wxWindowNative::DoSetClientSize(width
, height
);
828 wxHitTest
wxWindow::DoHitTest(wxCoord x
, wxCoord y
) const
830 wxHitTest ht
= wxWindowNative::DoHitTest(x
, y
);
833 if ( ht
== wxHT_WINDOW_INSIDE
)
835 if ( m_scrollbarVert
&& x
>= m_scrollbarVert
->GetPosition().x
)
837 // it can still be changed below because it may also be the corner
838 ht
= wxHT_WINDOW_VERT_SCROLLBAR
;
841 if ( m_scrollbarHorz
&& y
>= m_scrollbarHorz
->GetPosition().y
)
843 ht
= ht
== wxHT_WINDOW_VERT_SCROLLBAR
? wxHT_WINDOW_CORNER
844 : wxHT_WINDOW_HORZ_SCROLLBAR
;
847 #endif // wxUSE_SCROLLBAR
852 // ----------------------------------------------------------------------------
853 // scrolling: we implement it entirely ourselves except for ScrollWindow()
854 // function which is supposed to be (efficiently) implemented by the native
856 // ----------------------------------------------------------------------------
858 void wxWindow::RefreshScrollbars()
861 if ( m_scrollbarHorz
)
862 m_scrollbarHorz
->Refresh();
864 if ( m_scrollbarVert
)
865 m_scrollbarVert
->Refresh();
866 #endif // wxUSE_SCROLLBAR
869 void wxWindow::PositionScrollbars()
872 // do not use GetClientSize/Rect as it relies on the scrollbars being
873 // correctly positioned
875 wxSize size
= GetSize();
876 wxBorder border
= GetBorder();
877 wxRect rectBorder
= m_renderer
->GetBorderDimensions(border
);
878 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
880 int height
= m_scrollbarHorz
? m_scrollbarHorz
->GetSize().y
: 0;
881 int width
= m_scrollbarVert
? m_scrollbarVert
->GetSize().x
: 0;
884 if ( m_scrollbarVert
)
886 rectBar
.x
= size
.x
- width
;
888 rectBar
.x
-= rectBorder
.width
;
889 rectBar
.width
= width
;
892 rectBar
.y
+= rectBorder
.y
;
893 rectBar
.height
= size
.y
- height
;
895 rectBar
.height
-= rectBorder
.y
+ rectBorder
.height
;
897 m_scrollbarVert
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
900 if ( m_scrollbarHorz
)
902 rectBar
.y
= size
.y
- height
;
904 rectBar
.y
-= rectBorder
.height
;
905 rectBar
.height
= height
;
908 rectBar
.x
+= rectBorder
.x
;
909 rectBar
.width
= size
.x
- width
;
911 rectBar
.width
-= rectBorder
.x
+ rectBorder
.width
;
913 m_scrollbarHorz
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
917 #endif // wxUSE_SCROLLBAR
920 void wxWindow::SetScrollbar(int orient
,
927 wxASSERT_MSG( pageSize
<= range
,
928 _T("page size can't be greater than range") );
930 bool hasClientSizeChanged
= false;
931 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
932 if ( range
&& (pageSize
< range
) )
937 #if wxUSE_TWO_WINDOWS
938 SetInsertIntoMain( true );
940 scrollbar
= new wxWindowScrollBar(this, wxID_ANY
,
941 wxDefaultPosition
, wxDefaultSize
,
942 orient
& wxVERTICAL
? wxSB_VERTICAL
944 #if wxUSE_TWO_WINDOWS
945 SetInsertIntoMain( false );
947 if ( orient
& wxVERTICAL
)
948 m_scrollbarVert
= scrollbar
;
950 m_scrollbarHorz
= scrollbar
;
952 // the client area diminished as we created a scrollbar
953 hasClientSizeChanged
= true;
955 PositionScrollbars();
957 else if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
959 // we might have disabled it before
963 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
965 else // no range means no scrollbar
969 // wxALWAYS_SHOW_SB only applies to the vertical scrollbar
970 if ( (orient
& wxVERTICAL
) && (GetWindowStyle() & wxALWAYS_SHOW_SB
) )
972 // just disable the scrollbar
973 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
974 scrollbar
->Disable();
976 else // really remove the scrollbar
980 if ( orient
& wxVERTICAL
)
981 m_scrollbarVert
= NULL
;
983 m_scrollbarHorz
= NULL
;
985 // the client area increased as we removed a scrollbar
986 hasClientSizeChanged
= true;
988 // the size of the remaining scrollbar must be adjusted
989 if ( m_scrollbarHorz
|| m_scrollbarVert
)
991 PositionScrollbars();
997 // give the window a chance to relayout
998 if ( hasClientSizeChanged
)
1000 #if wxUSE_TWO_WINDOWS
1001 wxWindowNative::SetSize( GetSize() );
1003 wxSizeEvent
event(GetSize());
1004 (void)GetEventHandler()->ProcessEvent(event
);
1008 wxUnusedVar(orient
);
1010 wxUnusedVar(pageSize
);
1012 wxUnusedVar(refresh
);
1013 #endif // wxUSE_SCROLLBAR
1016 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1019 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
1022 scrollbar
->SetThumbPosition(pos
);
1024 // VZ: I think we can safely ignore this as we always refresh it
1025 // automatically whenever the value chanegs
1031 wxUnusedVar(orient
);
1033 #endif // wxUSE_SCROLLBAR
1036 int wxWindow::GetScrollPos(int orient
) const
1039 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
1040 return scrollbar
? scrollbar
->GetThumbPosition() : 0;
1042 wxUnusedVar(orient
);
1044 #endif // wxUSE_SCROLLBAR
1047 int wxWindow::GetScrollThumb(int orient
) const
1050 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
1051 return scrollbar
? scrollbar
->GetThumbSize() : 0;
1053 wxUnusedVar(orient
);
1055 #endif // wxUSE_SCROLLBAR
1058 int wxWindow::GetScrollRange(int orient
) const
1061 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
1062 return scrollbar
? scrollbar
->GetRange() : 0;
1064 wxUnusedVar(orient
);
1066 #endif // wxUSE_SCROLLBAR
1069 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1071 // use native scrolling when available and do it in generic way
1075 wxWindowNative::ScrollWindow(dx
, dy
, rect
);
1079 // before scrolling it, ensure that we don't have any unpainted areas
1086 r
= ScrollNoRefresh(dx
, 0, rect
);
1087 Refresh(true /* erase bkgnd */, &r
);
1092 r
= ScrollNoRefresh(0, dy
, rect
);
1093 Refresh(true /* erase bkgnd */, &r
);
1096 // scroll children accordingly:
1097 wxPoint
offset(dx
, dy
);
1099 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1100 node
; node
= node
->GetNext())
1102 wxWindow
*child
= node
->GetData();
1104 if ( child
== m_scrollbarVert
|| child
== m_scrollbarHorz
)
1106 #endif // wxUSE_SCROLLBAR
1108 // VS: Scrolling children has non-trivial semantics. If rect=NULL then
1109 // it is easy: we scroll all children. Otherwise it gets
1111 // 1. if scrolling in one direction only, scroll only
1112 // those children that intersect shaft defined by the rectangle
1113 // and scrolling direction
1114 // 2. if scrolling in both axes, scroll all children
1116 bool shouldMove
= false;
1118 if ( rect
&& (dx
* dy
== 0 /* moving in only one of x, y axis */) )
1120 wxRect childRect
= child
->GetRect();
1121 if ( dx
== 0 && (childRect
.GetLeft() <= rect
->GetRight() ||
1122 childRect
.GetRight() >= rect
->GetLeft()) )
1126 else if ( dy
== 0 && (childRect
.GetTop() <= rect
->GetBottom() ||
1127 childRect
.GetBottom() >= rect
->GetTop()) )
1131 // else: child outside of scrolling shaft, don't move
1133 else // scrolling in both axes or rect=NULL
1139 child
->Move(child
->GetPosition() + offset
, wxSIZE_ALLOW_MINUS_ONE
);
1141 #endif // wxX11/!wxX11
1144 wxRect
wxWindow::ScrollNoRefresh(int dx
, int dy
, const wxRect
*rectTotal
)
1146 wxASSERT_MSG( !dx
|| !dy
, _T("can't be used for diag scrolling") );
1148 // the rect to refresh (which we will calculate)
1157 // calculate the part of the window which we can just redraw in the new
1159 wxSize sizeTotal
= rectTotal
? rectTotal
->GetSize() : GetClientSize();
1161 wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
1162 sizeTotal
.x
, sizeTotal
.y
, dx
, dy
);
1164 // the initial and end point of the region we move in client coords
1165 wxPoint ptSource
, ptDest
;
1168 ptSource
= rectTotal
->GetPosition();
1169 ptDest
= rectTotal
->GetPosition();
1172 // the size of this region
1174 size
.x
= sizeTotal
.x
- abs(dx
);
1175 size
.y
= sizeTotal
.y
- abs(dy
);
1176 if ( size
.x
<= 0 || size
.y
<= 0 )
1178 // just redraw everything as nothing of the displayed image will stay
1179 wxLogTrace(_T("scroll"), _T("refreshing everything"));
1181 rect
= rectTotal
? *rectTotal
: wxRect(0, 0, sizeTotal
.x
, sizeTotal
.y
);
1183 else // move the part which doesn't change to the new location
1185 // note that when we scroll the canvas in some direction we move the
1186 // block which doesn't need to be refreshed in the opposite direction
1190 // scroll to the right, move to the left
1195 // scroll to the left, move to the right
1201 // scroll down, move up
1206 // scroll up, move down
1211 // we need to hide the caret before moving or it will erase itself at
1212 // the wrong (old) location
1213 wxCaret
*caret
= GetCaret();
1216 #endif // wxUSE_CARET
1219 wxClientDC
dc(this);
1220 wxBitmap
bmp(size
.x
, size
.y
);
1222 dcMem
.SelectObject(bmp
);
1224 dcMem
.Blit(wxPoint(0,0), size
, &dc
, ptSource
1225 #if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
1226 + GetClientAreaOrigin()
1227 #endif // broken wxGTK wxDC::Blit
1229 dc
.Blit(ptDest
, size
, &dcMem
, wxPoint(0,0));
1231 wxLogTrace(_T("scroll"),
1232 _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
1233 ptSource
.x
, ptSource
.y
,
1235 ptDest
.x
, ptDest
.y
);
1237 // and now repaint the uncovered area
1239 // FIXME: We repaint the intersection of these rectangles twice - is
1240 // it bad? I don't think so as it is rare to scroll the window
1241 // diagonally anyhow and so adding extra logic to compute
1242 // rectangle intersection is probably not worth the effort
1244 rect
.x
= ptSource
.x
;
1245 rect
.y
= ptSource
.y
;
1251 // refresh the area along the right border
1252 rect
.x
+= size
.x
+ dx
;
1257 // refresh the area along the left border
1261 rect
.height
= sizeTotal
.y
;
1263 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1265 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1272 // refresh the area along the bottom border
1273 rect
.y
+= size
.y
+ dy
;
1278 // refresh the area along the top border
1282 rect
.width
= sizeTotal
.x
;
1284 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1286 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1292 #endif // wxUSE_CARET
1298 // ----------------------------------------------------------------------------
1299 // accelerators and menu hot keys
1300 // ----------------------------------------------------------------------------
1303 // the last window over which Alt was pressed (used by OnKeyUp)
1304 wxWindow
*wxWindow::ms_winLastAltPress
= NULL
;
1305 #endif // wxUSE_MENUS
1307 #if wxUSE_ACCEL || wxUSE_MENUS
1309 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1312 int key
= event
.GetKeyCode();
1313 if ( !event
.ControlDown() && (key
== WXK_ALT
|| key
== WXK_F10
) )
1315 ms_winLastAltPress
= this;
1317 // it can't be an accel anyhow
1321 ms_winLastAltPress
= NULL
;
1322 #endif // wxUSE_MENUS
1325 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
1327 int command
= win
->GetAcceleratorTable()->GetCommand(event
);
1328 if ( command
!= -1 )
1330 wxCommandEvent
eventCmd(wxEVT_COMMAND_MENU_SELECTED
, command
);
1331 if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) )
1333 // skip "event.Skip()" below
1338 if ( win
->IsTopLevel() )
1340 // try the frame menu bar
1342 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1345 wxMenuBar
*menubar
= frame
->GetMenuBar();
1346 if ( menubar
&& menubar
->ProcessAccelEvent(event
) )
1348 // skip "event.Skip()" below
1352 #endif // wxUSE_MENUS
1355 // if it wasn't in a menu, try to find a button
1356 if ( command
!= -1 )
1358 wxWindow
* child
= win
->FindWindow(command
);
1359 if ( child
&& wxDynamicCast(child
, wxButton
) )
1361 wxCommandEvent
eventCmd(wxEVT_COMMAND_BUTTON_CLICKED
, command
);
1362 eventCmd
.SetEventObject(child
);
1363 if ( child
->GetEventHandler()->ProcessEvent(eventCmd
) )
1365 // skip "event.Skip()" below
1370 #endif // wxUSE_BUTTON
1372 // don't propagate accels from the child frame to the parent one
1376 #endif // wxUSE_ACCEL
1381 #endif // wxUSE_ACCEL
1385 wxMenuBar
*wxWindow::GetParentFrameMenuBar() const
1387 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
1389 if ( win
->IsTopLevel() )
1391 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1394 return frame
->GetMenuBar();
1397 // don't look further - we don't want to return the menubar of the
1406 void wxWindow::OnChar(wxKeyEvent
& event
)
1408 if ( event
.AltDown() && !event
.ControlDown() )
1410 int key
= event
.GetKeyCode();
1412 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1415 int item
= menubar
->FindNextItemForAccel(-1, key
);
1418 menubar
->PopupMenu((size_t)item
);
1420 // skip "event.Skip()" below
1426 // if Return was pressed, see if there's a default button to activate
1427 if ( !event
.HasModifiers() && event
.GetKeyCode() == WXK_RETURN
)
1430 tlw
= wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow
);
1433 wxButton
*btn
= wxDynamicCast(tlw
->GetDefaultItem(), wxButton
);
1436 wxCommandEvent
evt(wxEVT_COMMAND_BUTTON_CLICKED
, btn
->GetId());
1437 evt
.SetEventObject(btn
);
1448 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1450 int key
= event
.GetKeyCode();
1451 if ( !event
.HasModifiers() && (key
== WXK_ALT
|| key
== WXK_F10
) )
1453 // only process Alt release specially if there were no other key
1454 // presses since Alt had been pressed and if both events happened in
1456 if ( ms_winLastAltPress
== this )
1458 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1459 if ( menubar
&& this != menubar
)
1461 menubar
->SelectMenu(0);
1470 // in any case reset it
1471 ms_winLastAltPress
= NULL
;
1474 #endif // wxUSE_MENUS
1476 // ----------------------------------------------------------------------------
1477 // MSW-specific section
1478 // ----------------------------------------------------------------------------
1482 #include "wx/msw/private.h"
1484 WXLRESULT
wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1486 if ( message
== WM_NCHITTEST
)
1488 // the windows which contain the other windows should let the mouse
1489 // events through, otherwise a window inside a static box would
1490 // never get any events at all
1491 if ( IsStaticBox() )
1493 return HTTRANSPARENT
;
1497 return wxWindowNative::MSWWindowProc(message
, wParam
, lParam
);