1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/univ/window.cpp
3 // Purpose: implementation of extra wxWindow methods for wxUniv port
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/window.h"
31 #include "wx/dcclient.h"
32 #include "wx/dcmemory.h"
34 #include "wx/scrolbar.h"
40 #include "wx/univ/colschem.h"
41 #include "wx/univ/renderer.h"
42 #include "wx/univ/theme.h"
48 // turn Refresh() debugging on/off
49 #define WXDEBUG_REFRESH
52 #undef WXDEBUG_REFRESH
55 #if defined(WXDEBUG_REFRESH) && defined(__WXMSW__) && !defined(__WXMICROWIN__)
56 #include "wx/msw/private.h"
59 // ============================================================================
61 // ============================================================================
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 // we can't use wxWindowNative here as it won't be expanded inside the macro
68 #if defined(__WXMSW__)
69 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowMSW
)
70 #elif defined(__WXGTK__)
71 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowGTK
)
72 #elif defined(__WXMGL__)
73 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowMGL
)
74 #elif defined(__WXDFB__)
75 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowDFB
)
76 #elif defined(__WXX11__)
77 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowX11
)
78 #elif defined(__WXPM__)
79 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowOS2
)
82 BEGIN_EVENT_TABLE(wxWindow
, wxWindowNative
)
83 EVT_SIZE(wxWindow::OnSize
)
85 #if wxUSE_ACCEL || wxUSE_MENUS
86 EVT_KEY_DOWN(wxWindow::OnKeyDown
)
90 EVT_CHAR(wxWindow::OnChar
)
91 EVT_KEY_UP(wxWindow::OnKeyUp
)
94 EVT_PAINT(wxWindow::OnPaint
)
95 EVT_NC_PAINT(wxWindow::OnNcPaint
)
96 EVT_ERASE_BACKGROUND(wxWindow::OnErase
)
99 // ----------------------------------------------------------------------------
101 // ----------------------------------------------------------------------------
103 void wxWindow::Init()
107 m_scrollbarHorz
= (wxScrollBar
*)NULL
;
108 #endif // wxUSE_SCROLLBAR
112 m_renderer
= wxTheme::Get()->GetRenderer();
114 m_oldSize
.x
= wxDefaultCoord
;
115 m_oldSize
.y
= wxDefaultCoord
;
118 bool wxWindow::Create(wxWindow
*parent
,
123 const wxString
& name
)
125 long actualStyle
= style
;
127 // we add wxCLIP_CHILDREN to get the same ("natural") behaviour under MSW
128 // as under the other platforms
129 actualStyle
|= wxCLIP_CHILDREN
;
131 actualStyle
&= ~wxVSCROLL
;
132 actualStyle
&= ~wxHSCROLL
;
135 // without this, borders (non-client areas in general) are not repainted
136 // correctly when resizing; apparently, native NC areas are fully repainted
137 // even without this style by MSW, but wxUniv implements client area
138 // itself, so it doesn't work correctly for us
140 // FIXME: this is very expensive, we need to fix the (commented-out) code
141 // in OnSize() instead
142 actualStyle
|= wxFULL_REPAINT_ON_RESIZE
;
145 if ( !wxWindowNative::Create(parent
, id
, pos
, size
, actualStyle
, name
) )
148 // Set full style again, including those we didn't want present
149 // when calling the base window Create().
150 wxWindowBase::SetWindowStyleFlag(style
);
152 // if we allow or should always have a vertical scrollbar, make it
153 if ( style
& wxVSCROLL
|| style
& wxALWAYS_SHOW_SB
)
155 #if wxUSE_TWO_WINDOWS
156 SetInsertIntoMain( true );
159 m_scrollbarVert
= new wxScrollBar(this, wxID_ANY
,
160 wxDefaultPosition
, wxDefaultSize
,
162 #endif // wxUSE_SCROLLBAR
163 #if wxUSE_TWO_WINDOWS
164 SetInsertIntoMain( false );
168 // if we should allow a horizontal scrollbar, make it
169 if ( style
& wxHSCROLL
)
171 #if wxUSE_TWO_WINDOWS
172 SetInsertIntoMain( true );
175 m_scrollbarHorz
= new wxScrollBar(this, wxID_ANY
,
176 wxDefaultPosition
, wxDefaultSize
,
178 #endif // wxUSE_SCROLLBAR
179 #if wxUSE_TWO_WINDOWS
180 SetInsertIntoMain( false );
185 if (m_scrollbarHorz
|| m_scrollbarVert
)
188 PositionScrollbars();
190 #endif // wxUSE_SCROLLBAR
195 wxWindow::~wxWindow()
197 m_isBeingDeleted
= true;
199 // we have to destroy our children before we're destroyed because our
200 // children suppose that we're of type wxWindow, not just wxWindowNative,
201 // and so bad things may happen if they're deleted from the base class dtor
202 // as by then we're not a wxWindow any longer and wxUniv-specific virtual
203 // functions can't be called
207 // ----------------------------------------------------------------------------
209 // ----------------------------------------------------------------------------
211 void wxWindow::SetBackground(const wxBitmap
& bitmap
,
216 m_alignBgBitmap
= alignment
;
217 m_stretchBgBitmap
= stretch
;
220 const wxBitmap
& wxWindow::GetBackgroundBitmap(int *alignment
,
221 wxStretch
*stretch
) const
223 if ( m_bitmapBg
.Ok() )
226 *alignment
= m_alignBgBitmap
;
228 *stretch
= m_stretchBgBitmap
;
234 // ----------------------------------------------------------------------------
236 // ----------------------------------------------------------------------------
238 // the event handlers executed when the window must be repainted
239 void wxWindow::OnNcPaint(wxNcPaintEvent
& WXUNUSED(event
))
243 // get the window rect
244 wxRect
rect(GetSize());
247 // if the scrollbars are outside the border, we must adjust the rect to
249 if ( !m_renderer
->AreScrollbarsInsideBorder() )
251 wxScrollBar
*scrollbar
= GetScrollbar(wxVERTICAL
);
253 rect
.width
-= scrollbar
->GetSize().x
;
255 scrollbar
= GetScrollbar(wxHORIZONTAL
);
257 rect
.height
-= scrollbar
->GetSize().y
;
259 #endif // wxUSE_SCROLLBAR
261 // get the DC and draw the border on it
263 DoDrawBorder(dc
, rect
);
267 void wxWindow::OnPaint(wxPaintEvent
& event
)
271 // it is a native control which paints itself
276 // get the DC to use and create renderer on it
278 wxControlRenderer
renderer(this, dc
, m_renderer
);
285 // the event handler executed when the window background must be painted
286 void wxWindow::OnErase(wxEraseEvent
& event
)
295 DoDrawBackground(*event
.GetDC());
298 // if we have both scrollbars, we also have a square in the corner between
299 // them which we must paint
300 if ( m_scrollbarVert
&& m_scrollbarHorz
)
302 wxSize size
= GetSize();
303 wxRect rectClient
= GetClientRect(),
304 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
307 rectCorner
.x
= rectClient
.GetRight() + 1;
308 rectCorner
.y
= rectClient
.GetBottom() + 1;
309 rectCorner
.SetRight(size
.x
- rectBorder
.width
);
310 rectCorner
.SetBottom(size
.y
- rectBorder
.height
);
312 if ( GetUpdateRegion().Contains(rectCorner
) )
314 m_renderer
->DrawScrollCorner(*event
.GetDC(), rectCorner
);
317 #endif // wxUSE_SCROLLBAR
320 bool wxWindow::DoDrawBackground(wxDC
& dc
)
324 wxSize size
= GetSize(); // Why not GetClientSize() ?
328 rect
.height
= size
.y
;
330 wxWindow
* const parent
= GetParent();
331 if ( HasTransparentBackground() && parent
)
333 wxASSERT( !IsTopLevel() );
335 wxPoint pos
= GetPosition();
337 AdjustForParentClientOrigin( pos
.x
, pos
.y
, 0 );
339 // Adjust DC logical origin
340 wxCoord org_x
, org_y
, x
, y
;
341 dc
.GetLogicalOrigin( &org_x
, &org_y
);
344 dc
.SetLogicalOrigin( x
, y
);
350 // Let parent draw the background
351 parent
->EraseBackground( dc
, rect
);
353 // Restore DC logical origin
354 dc
.SetLogicalOrigin( org_x
, org_y
);
358 // Draw background ourselves
359 EraseBackground( dc
, rect
);
365 void wxWindow::EraseBackground(wxDC
& dc
, const wxRect
& rect
)
367 if ( GetBackgroundBitmap().Ok() )
369 // Get the bitmap and the flags
372 wxBitmap bmp
= GetBackgroundBitmap(&alignment
, &stretch
);
373 wxControlRenderer::DrawBitmap(dc
, bmp
, rect
, alignment
, stretch
);
377 // Just fill it with bg colour if no bitmap
379 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this),
380 rect
, GetStateFlags());
384 void wxWindow::DoDrawBorder(wxDC
& dc
, const wxRect
& rect
)
386 // draw outline unless the update region is enitrely inside it in which
387 // case we don't need to do it
388 #if 0 // doesn't seem to work, why?
389 if ( wxRegion(rect
).Contains(GetUpdateRegion().GetBox()) != wxInRegion
)
392 m_renderer
->DrawBorder(dc
, GetBorder(), rect
, GetStateFlags());
396 void wxWindow::DoDraw(wxControlRenderer
* WXUNUSED(renderer
))
400 void wxWindow::Refresh(bool eraseBackground
, const wxRect
*rect
)
402 wxRect rectClient
; // the same rectangle in client coordinates
403 wxPoint origin
= GetClientAreaOrigin();
405 wxSize size
= GetClientSize();
409 // the rectangle passed as argument is in client coordinates
412 // don't refresh anything beyond the client area (scrollbars for
414 if ( rectClient
.GetRight() > size
.x
)
415 rectClient
.SetRight(size
.x
);
416 if ( rectClient
.GetBottom() > size
.y
)
417 rectClient
.SetBottom(size
.y
);
420 else // refresh the entire client area
422 // x,y is already set to 0 by default
423 rectClient
.SetSize(size
);
426 // convert refresh rectangle to window coordinates:
427 wxRect
rectWin(rectClient
);
428 rectWin
.Offset(origin
);
431 #ifdef WXDEBUG_REFRESH
432 static bool s_refreshDebug
= false;
433 if ( s_refreshDebug
)
436 dc
.SetBrush(*wxCYAN_BRUSH
);
437 dc
.SetPen(*wxTRANSPARENT_PEN
);
438 dc
.DrawRectangle(rectWin
);
440 // under Unix we use "--sync" X option for this
441 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
446 #endif // WXDEBUG_REFRESH
448 wxWindowNative::Refresh(eraseBackground
, &rectWin
);
450 // Refresh all sub controls if any.
451 wxWindowList
& children
= GetChildren();
452 for ( wxWindowList::iterator i
= children
.begin(); i
!= children
.end(); ++i
)
454 wxWindow
*child
= *i
;
455 // only refresh subcontrols if they are visible:
456 if ( child
->IsTopLevel() || !child
->IsShown() || child
->IsFrozen() )
459 // ...and when the subcontrols are in the update region:
460 wxRect
childrect(child
->GetRect());
461 childrect
.Intersect(rectClient
);
462 if ( childrect
.IsEmpty() )
465 // refresh the subcontrol now:
466 childrect
.Offset(-child
->GetPosition());
467 // NB: We must call wxWindowNative version because we need to refresh
468 // the entire control, not just its client area, and this is why we
469 // don't account for child client area origin here neither. Also
470 // note that we don't pass eraseBackground to the child, but use
471 // true instead: this is because we can't be sure that
472 // eraseBackground=false is safe for children as well and not only
474 child
->wxWindowNative::Refresh(eraseBackground
, &childrect
);
478 // ----------------------------------------------------------------------------
480 // ----------------------------------------------------------------------------
482 bool wxWindow::Enable(bool enable
)
484 if ( !wxWindowNative::Enable(enable
) )
487 // disabled window can't keep focus
488 if ( FindFocus() == this && GetParent() != NULL
)
490 GetParent()->SetFocus();
495 // a window with renderer is drawn by ourselves and it has to be
496 // refreshed to reflect its new status
503 bool wxWindow::IsFocused() const
505 return FindFocus() == this;
508 bool wxWindow::IsPressed() const
513 bool wxWindow::IsDefault() const
518 bool wxWindow::IsCurrent() const
523 bool wxWindow::SetCurrent(bool doit
)
525 if ( doit
== m_isCurrent
)
530 if ( CanBeHighlighted() )
536 int wxWindow::GetStateFlags() const
540 flags
|= wxCONTROL_DISABLED
;
542 // the following states are only possible if our application is active - if
543 // it is not, even our default/focused controls shouldn't appear as such
544 if ( wxTheApp
->IsActive() )
547 flags
|= wxCONTROL_CURRENT
;
549 flags
|= wxCONTROL_FOCUSED
;
551 flags
|= wxCONTROL_PRESSED
;
553 flags
|= wxCONTROL_ISDEFAULT
;
559 // ----------------------------------------------------------------------------
561 // ----------------------------------------------------------------------------
563 void wxWindow::OnSize(wxSizeEvent
& event
)
568 if ( m_scrollbarVert
|| m_scrollbarHorz
)
570 PositionScrollbars();
572 #endif // wxUSE_SCROLLBAR
574 #if 0 // ndef __WXMSW__
575 // Refresh the area (strip) previously occupied by the border
577 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) && IsShown() )
579 // This code assumes that wxSizeEvent.GetSize() returns
580 // the area of the entire window, not just the client
582 wxSize newSize
= event
.GetSize();
584 if (m_oldSize
.x
== wxDefaultCoord
&& m_oldSize
.y
== wxDefaultCoord
)
590 if (HasFlag( wxSIMPLE_BORDER
))
592 if (newSize
.y
> m_oldSize
.y
)
596 rect
.width
= m_oldSize
.x
;
597 rect
.y
= m_oldSize
.y
-2;
599 Refresh( true, &rect
);
601 else if (newSize
.y
< m_oldSize
.y
)
607 rect
.width
= newSize
.x
;
608 wxWindowNative::Refresh( true, &rect
);
611 if (newSize
.x
> m_oldSize
.x
)
615 rect
.height
= m_oldSize
.y
;
616 rect
.x
= m_oldSize
.x
-2;
618 Refresh( true, &rect
);
620 else if (newSize
.x
< m_oldSize
.x
)
626 rect
.height
= newSize
.y
;
627 wxWindowNative::Refresh( true, &rect
);
631 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
633 if (newSize
.y
> m_oldSize
.y
)
637 rect
.width
= m_oldSize
.x
;
638 rect
.y
= m_oldSize
.y
-4;
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
-4;
659 Refresh( true, &rect
);
661 else if (newSize
.x
< m_oldSize
.x
)
667 rect
.height
= newSize
.y
;
668 wxWindowNative::Refresh( true, &rect
);
677 wxSize
wxWindow::DoGetBestSize() const
679 return AdjustSize(DoGetBestClientSize());
682 wxSize
wxWindow::DoGetBestClientSize() const
684 return wxWindowNative::DoGetBestSize();
687 wxSize
wxWindow::AdjustSize(const wxSize
& size
) const
691 m_renderer
->AdjustSize(&sz
, this);
695 wxPoint
wxWindow::GetClientAreaOrigin() const
697 wxPoint pt
= wxWindowBase::GetClientAreaOrigin();
699 #if wxUSE_TWO_WINDOWS
702 pt
+= m_renderer
->GetBorderDimensions(GetBorder()).GetPosition();
708 void wxWindow::DoGetClientSize(int *width
, int *height
) const
710 // if it is a native window, we assume it handles the scrollbars itself
711 // too - and if it doesn't, there is not much we can do
714 wxWindowNative::DoGetClientSize(width
, height
);
720 wxWindowNative::DoGetClientSize(&w
, &h
);
722 // we assume that the scrollbars are positioned correctly (by a previous
723 // call to PositionScrollbars()) here
727 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
732 // in any case, take account of the scrollbar
733 if ( m_scrollbarVert
)
734 w
-= m_scrollbarVert
->GetSize().x
;
735 #endif // wxUSE_SCROLLBAR
737 // account for the left and right borders
738 *width
= w
- rectBorder
.x
- rectBorder
.width
;
740 // we shouldn't return invalid width
748 if ( m_scrollbarHorz
)
749 h
-= m_scrollbarHorz
->GetSize().y
;
750 #endif // wxUSE_SCROLLBAR
752 *height
= h
- rectBorder
.y
- rectBorder
.height
;
754 // we shouldn't return invalid height
760 void wxWindow::DoSetClientSize(int width
, int height
)
762 // take into account the borders
763 wxRect rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
764 width
+= rectBorder
.x
;
765 height
+= rectBorder
.y
;
767 // and the scrollbars (as they may be offset into the border, use the
768 // scrollbar position, not size - this supposes that PositionScrollbars()
769 // had been called before)
770 wxSize size
= GetSize();
772 if ( m_scrollbarVert
)
773 width
+= size
.x
- m_scrollbarVert
->GetPosition().x
;
774 #endif // wxUSE_SCROLLBAR
775 width
+= rectBorder
.width
;
778 if ( m_scrollbarHorz
)
779 height
+= size
.y
- m_scrollbarHorz
->GetPosition().y
;
780 #endif // wxUSE_SCROLLBAR
781 height
+= rectBorder
.height
;
783 wxWindowNative::DoSetClientSize(width
, height
);
786 wxHitTest
wxWindow::DoHitTest(wxCoord x
, wxCoord y
) const
788 wxHitTest ht
= wxWindowNative::DoHitTest(x
, y
);
791 if ( ht
== wxHT_WINDOW_INSIDE
)
793 if ( m_scrollbarVert
&& x
>= m_scrollbarVert
->GetPosition().x
)
795 // it can still be changed below because it may also be the corner
796 ht
= wxHT_WINDOW_VERT_SCROLLBAR
;
799 if ( m_scrollbarHorz
&& y
>= m_scrollbarHorz
->GetPosition().y
)
801 ht
= ht
== wxHT_WINDOW_VERT_SCROLLBAR
? wxHT_WINDOW_CORNER
802 : wxHT_WINDOW_HORZ_SCROLLBAR
;
805 #endif // wxUSE_SCROLLBAR
810 // ----------------------------------------------------------------------------
811 // scrolling: we implement it entirely ourselves except for ScrollWindow()
812 // function which is supposed to be (efficiently) implemented by the native
814 // ----------------------------------------------------------------------------
816 void wxWindow::RefreshScrollbars()
819 if ( m_scrollbarHorz
)
820 m_scrollbarHorz
->Refresh();
822 if ( m_scrollbarVert
)
823 m_scrollbarVert
->Refresh();
824 #endif // wxUSE_SCROLLBAR
827 void wxWindow::PositionScrollbars()
830 // do not use GetClientSize/Rect as it relies on the scrollbars being
831 // correctly positioned
833 wxSize size
= GetSize();
834 wxBorder border
= GetBorder();
835 wxRect rectBorder
= m_renderer
->GetBorderDimensions(border
);
836 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
838 int height
= m_scrollbarHorz
? m_scrollbarHorz
->GetSize().y
: 0;
839 int width
= m_scrollbarVert
? m_scrollbarVert
->GetSize().x
: 0;
842 if ( m_scrollbarVert
)
844 rectBar
.x
= size
.x
- width
;
846 rectBar
.x
-= rectBorder
.width
;
847 rectBar
.width
= width
;
850 rectBar
.y
+= rectBorder
.y
;
851 rectBar
.height
= size
.y
- height
;
853 rectBar
.height
-= rectBorder
.y
+ rectBorder
.height
;
855 m_scrollbarVert
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
858 if ( m_scrollbarHorz
)
860 rectBar
.y
= size
.y
- height
;
862 rectBar
.y
-= rectBorder
.height
;
863 rectBar
.height
= height
;
866 rectBar
.x
+= rectBorder
.x
;
867 rectBar
.width
= size
.x
- width
;
869 rectBar
.width
-= rectBorder
.x
+ rectBorder
.width
;
871 m_scrollbarHorz
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
875 #endif // wxUSE_SCROLLBAR
878 void wxWindow::SetScrollbar(int orient
,
885 wxASSERT_MSG( pageSize
<= range
,
886 _T("page size can't be greater than range") );
888 bool hasClientSizeChanged
= false;
889 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
890 if ( range
&& (pageSize
< range
) )
895 #if wxUSE_TWO_WINDOWS
896 SetInsertIntoMain( true );
898 scrollbar
= new wxScrollBar(this, wxID_ANY
,
899 wxDefaultPosition
, wxDefaultSize
,
900 orient
& wxVERTICAL
? wxSB_VERTICAL
902 #if wxUSE_TWO_WINDOWS
903 SetInsertIntoMain( false );
905 if ( orient
& wxVERTICAL
)
906 m_scrollbarVert
= scrollbar
;
908 m_scrollbarHorz
= scrollbar
;
910 // the client area diminished as we created a scrollbar
911 hasClientSizeChanged
= true;
913 PositionScrollbars();
915 else if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
917 // we might have disabled it before
921 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
923 else // no range means no scrollbar
927 // wxALWAYS_SHOW_SB only applies to the vertical scrollbar
928 if ( (orient
& wxVERTICAL
) && (GetWindowStyle() & wxALWAYS_SHOW_SB
) )
930 // just disable the scrollbar
931 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
932 scrollbar
->Disable();
934 else // really remove the scrollbar
938 if ( orient
& wxVERTICAL
)
939 m_scrollbarVert
= NULL
;
941 m_scrollbarHorz
= NULL
;
943 // the client area increased as we removed a scrollbar
944 hasClientSizeChanged
= true;
946 // the size of the remaining scrollbar must be adjusted
947 if ( m_scrollbarHorz
|| m_scrollbarVert
)
949 PositionScrollbars();
955 // give the window a chance to relayout
956 if ( hasClientSizeChanged
)
958 #if wxUSE_TWO_WINDOWS
959 wxWindowNative::SetSize( GetSize() );
961 wxSizeEvent
event(GetSize());
962 (void)GetEventHandler()->ProcessEvent(event
);
968 wxUnusedVar(pageSize
);
970 wxUnusedVar(refresh
);
971 #endif // wxUSE_SCROLLBAR
974 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
977 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
980 scrollbar
->SetThumbPosition(pos
);
982 // VZ: I think we can safely ignore this as we always refresh it
983 // automatically whenever the value chanegs
991 #endif // wxUSE_SCROLLBAR
994 int wxWindow::GetScrollPos(int orient
) const
997 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
998 return scrollbar
? scrollbar
->GetThumbPosition() : 0;
1000 wxUnusedVar(orient
);
1002 #endif // wxUSE_SCROLLBAR
1005 int wxWindow::GetScrollThumb(int orient
) const
1008 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
1009 return scrollbar
? scrollbar
->GetThumbSize() : 0;
1011 wxUnusedVar(orient
);
1013 #endif // wxUSE_SCROLLBAR
1016 int wxWindow::GetScrollRange(int orient
) const
1019 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
1020 return scrollbar
? scrollbar
->GetRange() : 0;
1022 wxUnusedVar(orient
);
1024 #endif // wxUSE_SCROLLBAR
1027 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1029 // use native scrolling when available and do it in generic way
1033 wxWindowNative::ScrollWindow(dx
, dy
, rect
);
1037 // before scrolling it, ensure that we don't have any unpainted areas
1044 r
= ScrollNoRefresh(dx
, 0, rect
);
1045 Refresh(true /* erase bkgnd */, &r
);
1050 r
= ScrollNoRefresh(0, dy
, rect
);
1051 Refresh(true /* erase bkgnd */, &r
);
1054 // scroll children accordingly:
1055 wxPoint
offset(dx
, dy
);
1057 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1058 node
; node
= node
->GetNext())
1060 wxWindow
*child
= node
->GetData();
1062 if ( child
== m_scrollbarVert
|| child
== m_scrollbarHorz
)
1064 #endif // wxUSE_SCROLLBAR
1066 // VS: Scrolling children has non-trivial semantics. If rect=NULL then
1067 // it is easy: we scroll all children. Otherwise it gets
1069 // 1. if scrolling in one direction only, scroll only
1070 // those children that intersect shaft defined by the rectangle
1071 // and scrolling direction
1072 // 2. if scrolling in both axes, scroll all children
1074 if ( rect
&& (dx
* dy
== 0 /* moving in only one of x, y axis */) )
1076 wxRect childRect
= child
->GetRect();
1077 if ( dx
== 0 && (childRect
.GetLeft() <= rect
->GetRight() ||
1078 childRect
.GetRight() >= rect
->GetLeft()) )
1080 child
->Move(child
->GetPosition() + offset
);
1082 else if ( dy
== 0 && (childRect
.GetTop() <= rect
->GetBottom() ||
1083 childRect
.GetBottom() >= rect
->GetTop()) )
1085 child
->Move(child
->GetPosition() + offset
);
1090 child
->Move(child
->GetPosition() + offset
);
1093 #endif // wxX11/!wxX11
1096 wxRect
wxWindow::ScrollNoRefresh(int dx
, int dy
, const wxRect
*rectTotal
)
1098 wxASSERT_MSG( !dx
|| !dy
, _T("can't be used for diag scrolling") );
1100 // the rect to refresh (which we will calculate)
1109 // calculate the part of the window which we can just redraw in the new
1111 wxSize sizeTotal
= rectTotal
? rectTotal
->GetSize() : GetClientSize();
1113 wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
1114 sizeTotal
.x
, sizeTotal
.y
, dx
, dy
);
1116 // the initial and end point of the region we move in client coords
1117 wxPoint ptSource
, ptDest
;
1120 ptSource
= rectTotal
->GetPosition();
1121 ptDest
= rectTotal
->GetPosition();
1124 // the size of this region
1126 size
.x
= sizeTotal
.x
- abs(dx
);
1127 size
.y
= sizeTotal
.y
- abs(dy
);
1128 if ( size
.x
<= 0 || size
.y
<= 0 )
1130 // just redraw everything as nothing of the displayed image will stay
1131 wxLogTrace(_T("scroll"), _T("refreshing everything"));
1133 rect
= rectTotal
? *rectTotal
: wxRect(0, 0, sizeTotal
.x
, sizeTotal
.y
);
1135 else // move the part which doesn't change to the new location
1137 // note that when we scroll the canvas in some direction we move the
1138 // block which doesn't need to be refreshed in the opposite direction
1142 // scroll to the right, move to the left
1147 // scroll to the left, move to the right
1153 // scroll down, move up
1158 // scroll up, move down
1163 // we need to hide the caret before moving or it will erase itself at
1164 // the wrong (old) location
1165 wxCaret
*caret
= GetCaret();
1168 #endif // wxUSE_CARET
1171 wxClientDC
dc(this);
1172 wxBitmap
bmp(size
.x
, size
.y
);
1174 dcMem
.SelectObject(bmp
);
1176 dcMem
.Blit(wxPoint(0,0), size
, &dc
, ptSource
1177 #if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
1178 + GetClientAreaOrigin()
1179 #endif // broken wxGTK wxDC::Blit
1181 dc
.Blit(ptDest
, size
, &dcMem
, wxPoint(0,0));
1183 wxLogTrace(_T("scroll"),
1184 _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
1185 ptSource
.x
, ptSource
.y
,
1187 ptDest
.x
, ptDest
.y
);
1189 // and now repaint the uncovered area
1191 // FIXME: We repaint the intersection of these rectangles twice - is
1192 // it bad? I don't think so as it is rare to scroll the window
1193 // diagonally anyhow and so adding extra logic to compute
1194 // rectangle intersection is probably not worth the effort
1196 rect
.x
= ptSource
.x
;
1197 rect
.y
= ptSource
.y
;
1203 // refresh the area along the right border
1204 rect
.x
+= size
.x
+ dx
;
1209 // refresh the area along the left border
1213 rect
.height
= sizeTotal
.y
;
1215 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1217 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1224 // refresh the area along the bottom border
1225 rect
.y
+= size
.y
+ dy
;
1230 // refresh the area along the top border
1234 rect
.width
= sizeTotal
.x
;
1236 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1238 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1244 #endif // wxUSE_CARET
1250 // ----------------------------------------------------------------------------
1251 // accelerators and menu hot keys
1252 // ----------------------------------------------------------------------------
1255 // the last window over which Alt was pressed (used by OnKeyUp)
1256 wxWindow
*wxWindow::ms_winLastAltPress
= NULL
;
1257 #endif // wxUSE_MENUS
1259 #if wxUSE_ACCEL || wxUSE_MENUS
1261 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1264 int key
= event
.GetKeyCode();
1265 if ( !event
.ControlDown() && (key
== WXK_ALT
|| key
== WXK_F10
) )
1267 ms_winLastAltPress
= this;
1269 // it can't be an accel anyhow
1273 ms_winLastAltPress
= NULL
;
1274 #endif // wxUSE_MENUS
1277 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
1279 int command
= win
->GetAcceleratorTable()->GetCommand(event
);
1280 if ( command
!= -1 )
1282 wxCommandEvent
eventCmd(wxEVT_COMMAND_MENU_SELECTED
, command
);
1283 if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) )
1285 // skip "event.Skip()" below
1290 if ( win
->IsTopLevel() )
1292 // try the frame menu bar
1294 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1297 wxMenuBar
*menubar
= frame
->GetMenuBar();
1298 if ( menubar
&& menubar
->ProcessAccelEvent(event
) )
1300 // skip "event.Skip()" below
1304 #endif // wxUSE_MENUS
1306 // if it wasn't in a menu, try to find a button
1307 if ( command
!= -1 )
1309 wxWindow
* child
= win
->FindWindow(command
);
1310 if ( child
&& wxDynamicCast(child
, wxButton
) )
1312 wxCommandEvent
eventCmd(wxEVT_COMMAND_BUTTON_CLICKED
, command
);
1313 eventCmd
.SetEventObject(child
);
1314 if ( child
->GetEventHandler()->ProcessEvent(eventCmd
) )
1316 // skip "event.Skip()" below
1322 // don't propagate accels from the child frame to the parent one
1326 #endif // wxUSE_ACCEL
1331 #endif // wxUSE_ACCEL
1335 wxMenuBar
*wxWindow::GetParentFrameMenuBar() const
1337 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
1339 if ( win
->IsTopLevel() )
1341 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1344 return frame
->GetMenuBar();
1347 // don't look further - we don't want to return the menubar of the
1356 void wxWindow::OnChar(wxKeyEvent
& event
)
1358 if ( event
.AltDown() && !event
.ControlDown() )
1360 int key
= event
.GetKeyCode();
1362 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1365 int item
= menubar
->FindNextItemForAccel(-1, key
);
1368 menubar
->PopupMenu((size_t)item
);
1370 // skip "event.Skip()" below
1379 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1381 int key
= event
.GetKeyCode();
1382 if ( !event
.HasModifiers() && (key
== WXK_ALT
|| key
== WXK_F10
) )
1384 // only process Alt release specially if there were no other key
1385 // presses since Alt had been pressed and if both events happened in
1387 if ( ms_winLastAltPress
== this )
1389 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1390 if ( menubar
&& this != menubar
)
1392 menubar
->SelectMenu(0);
1401 // in any case reset it
1402 ms_winLastAltPress
= NULL
;
1405 #endif // wxUSE_MENUS
1407 // ----------------------------------------------------------------------------
1408 // MSW-specific section
1409 // ----------------------------------------------------------------------------
1413 #include "wx/msw/private.h"
1415 WXLRESULT
wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1417 if ( message
== WM_NCHITTEST
)
1419 // the windows which contain the other windows should let the mouse
1420 // events through, otherwise a window inside a static box would
1421 // never get any events at all
1422 if ( IsStaticBox() )
1424 return HTTRANSPARENT
;
1428 return wxWindowNative::MSWWindowProc(message
, wParam
, lParam
);