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;
200 // clear pointers to scrollbar before deleting the children: they are
201 // children and so will be deleted by DestroyChildren() call below and if
202 // any code using the scrollbars would be called in the process or from
203 // ~wxWindowBase, the app would crash:
204 m_scrollbarVert
= m_scrollbarHorz
= NULL
;
207 // we have to destroy our children before we're destroyed because our
208 // children suppose that we're of type wxWindow, not just wxWindowNative,
209 // and so bad things may happen if they're deleted from the base class dtor
210 // as by then we're not a wxWindow any longer and wxUniv-specific virtual
211 // functions can't be called
215 // ----------------------------------------------------------------------------
217 // ----------------------------------------------------------------------------
219 void wxWindow::SetBackground(const wxBitmap
& bitmap
,
224 m_alignBgBitmap
= alignment
;
225 m_stretchBgBitmap
= stretch
;
228 const wxBitmap
& wxWindow::GetBackgroundBitmap(int *alignment
,
229 wxStretch
*stretch
) const
231 if ( m_bitmapBg
.Ok() )
234 *alignment
= m_alignBgBitmap
;
236 *stretch
= m_stretchBgBitmap
;
242 // ----------------------------------------------------------------------------
244 // ----------------------------------------------------------------------------
246 // the event handlers executed when the window must be repainted
247 void wxWindow::OnNcPaint(wxNcPaintEvent
& WXUNUSED(event
))
251 // get the window rect
252 wxRect
rect(GetSize());
255 // if the scrollbars are outside the border, we must adjust the rect to
257 if ( !m_renderer
->AreScrollbarsInsideBorder() )
259 wxScrollBar
*scrollbar
= GetScrollbar(wxVERTICAL
);
261 rect
.width
-= scrollbar
->GetSize().x
;
263 scrollbar
= GetScrollbar(wxHORIZONTAL
);
265 rect
.height
-= scrollbar
->GetSize().y
;
267 #endif // wxUSE_SCROLLBAR
269 // get the DC and draw the border on it
271 DoDrawBorder(dc
, rect
);
275 void wxWindow::OnPaint(wxPaintEvent
& event
)
279 // it is a native control which paints itself
284 // get the DC to use and create renderer on it
286 wxControlRenderer
renderer(this, dc
, m_renderer
);
293 // the event handler executed when the window background must be painted
294 void wxWindow::OnErase(wxEraseEvent
& event
)
303 DoDrawBackground(*event
.GetDC());
306 // if we have both scrollbars, we also have a square in the corner between
307 // them which we must paint
308 if ( m_scrollbarVert
&& m_scrollbarHorz
)
310 wxSize size
= GetSize();
311 wxRect rectClient
= GetClientRect(),
312 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
315 rectCorner
.x
= rectClient
.GetRight() + 1;
316 rectCorner
.y
= rectClient
.GetBottom() + 1;
317 rectCorner
.SetRight(size
.x
- rectBorder
.width
);
318 rectCorner
.SetBottom(size
.y
- rectBorder
.height
);
320 if ( GetUpdateRegion().Contains(rectCorner
) )
322 m_renderer
->DrawScrollCorner(*event
.GetDC(), rectCorner
);
325 #endif // wxUSE_SCROLLBAR
328 bool wxWindow::DoDrawBackground(wxDC
& dc
)
332 wxSize size
= GetSize(); // Why not GetClientSize() ?
336 rect
.height
= size
.y
;
338 wxWindow
* const parent
= GetParent();
339 if ( HasTransparentBackground() && parent
)
341 wxASSERT( !IsTopLevel() );
343 wxPoint pos
= GetPosition();
345 AdjustForParentClientOrigin( pos
.x
, pos
.y
, 0 );
347 // Adjust DC logical origin
348 wxCoord org_x
, org_y
, x
, y
;
349 dc
.GetLogicalOrigin( &org_x
, &org_y
);
352 dc
.SetLogicalOrigin( x
, y
);
358 // Let parent draw the background
359 parent
->EraseBackground( dc
, rect
);
361 // Restore DC logical origin
362 dc
.SetLogicalOrigin( org_x
, org_y
);
366 // Draw background ourselves
367 EraseBackground( dc
, rect
);
373 void wxWindow::EraseBackground(wxDC
& dc
, const wxRect
& rect
)
375 if ( GetBackgroundBitmap().Ok() )
377 // Get the bitmap and the flags
380 wxBitmap bmp
= GetBackgroundBitmap(&alignment
, &stretch
);
381 wxControlRenderer::DrawBitmap(dc
, bmp
, rect
, alignment
, stretch
);
385 // Just fill it with bg colour if no bitmap
387 m_renderer
->DrawBackground(dc
, wxTHEME_BG_COLOUR(this),
388 rect
, GetStateFlags());
392 void wxWindow::DoDrawBorder(wxDC
& dc
, const wxRect
& rect
)
394 // draw outline unless the update region is enitrely inside it in which
395 // case we don't need to do it
396 #if 0 // doesn't seem to work, why?
397 if ( wxRegion(rect
).Contains(GetUpdateRegion().GetBox()) != wxInRegion
)
400 m_renderer
->DrawBorder(dc
, GetBorder(), rect
, GetStateFlags());
404 void wxWindow::DoDraw(wxControlRenderer
* WXUNUSED(renderer
))
408 void wxWindow::Refresh(bool eraseBackground
, const wxRect
*rect
)
410 wxRect rectClient
; // the same rectangle in client coordinates
411 wxPoint origin
= GetClientAreaOrigin();
413 wxSize size
= GetClientSize();
417 // the rectangle passed as argument is in client coordinates
420 // don't refresh anything beyond the client area (scrollbars for
422 if ( rectClient
.GetRight() > size
.x
)
423 rectClient
.SetRight(size
.x
);
424 if ( rectClient
.GetBottom() > size
.y
)
425 rectClient
.SetBottom(size
.y
);
428 else // refresh the entire client area
430 // x,y is already set to 0 by default
431 rectClient
.SetSize(size
);
434 // convert refresh rectangle to window coordinates:
435 wxRect
rectWin(rectClient
);
436 rectWin
.Offset(origin
);
439 #ifdef WXDEBUG_REFRESH
440 static bool s_refreshDebug
= false;
441 if ( s_refreshDebug
)
444 dc
.SetBrush(*wxCYAN_BRUSH
);
445 dc
.SetPen(*wxTRANSPARENT_PEN
);
446 dc
.DrawRectangle(rectWin
);
448 // under Unix we use "--sync" X option for this
449 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
454 #endif // WXDEBUG_REFRESH
456 wxWindowNative::Refresh(eraseBackground
, &rectWin
);
458 // Refresh all sub controls if any.
459 wxWindowList
& children
= GetChildren();
460 for ( wxWindowList::iterator i
= children
.begin(); i
!= children
.end(); ++i
)
462 wxWindow
*child
= *i
;
463 // only refresh subcontrols if they are visible:
464 if ( child
->IsTopLevel() || !child
->IsShown() || child
->IsFrozen() )
467 // ...and when the subcontrols are in the update region:
468 wxRect
childrect(child
->GetRect());
469 childrect
.Intersect(rectClient
);
470 if ( childrect
.IsEmpty() )
473 // refresh the subcontrol now:
474 childrect
.Offset(-child
->GetPosition());
475 // NB: We must call wxWindowNative version because we need to refresh
476 // the entire control, not just its client area, and this is why we
477 // don't account for child client area origin here neither. Also
478 // note that we don't pass eraseBackground to the child, but use
479 // true instead: this is because we can't be sure that
480 // eraseBackground=false is safe for children as well and not only
482 child
->wxWindowNative::Refresh(eraseBackground
, &childrect
);
486 // ----------------------------------------------------------------------------
488 // ----------------------------------------------------------------------------
490 bool wxWindow::Enable(bool enable
)
492 if ( !wxWindowNative::Enable(enable
) )
495 // disabled window can't keep focus
496 if ( FindFocus() == this && GetParent() != NULL
)
498 GetParent()->SetFocus();
503 // a window with renderer is drawn by ourselves and it has to be
504 // refreshed to reflect its new status
511 bool wxWindow::IsFocused() const
513 return FindFocus() == this;
516 bool wxWindow::IsPressed() const
521 bool wxWindow::IsDefault() const
526 bool wxWindow::IsCurrent() const
531 bool wxWindow::SetCurrent(bool doit
)
533 if ( doit
== m_isCurrent
)
538 if ( CanBeHighlighted() )
544 int wxWindow::GetStateFlags() const
548 flags
|= wxCONTROL_DISABLED
;
550 // the following states are only possible if our application is active - if
551 // it is not, even our default/focused controls shouldn't appear as such
552 if ( wxTheApp
->IsActive() )
555 flags
|= wxCONTROL_CURRENT
;
557 flags
|= wxCONTROL_FOCUSED
;
559 flags
|= wxCONTROL_PRESSED
;
561 flags
|= wxCONTROL_ISDEFAULT
;
567 // ----------------------------------------------------------------------------
569 // ----------------------------------------------------------------------------
571 void wxWindow::OnSize(wxSizeEvent
& event
)
576 if ( m_scrollbarVert
|| m_scrollbarHorz
)
578 PositionScrollbars();
580 #endif // wxUSE_SCROLLBAR
582 #if 0 // ndef __WXMSW__
583 // Refresh the area (strip) previously occupied by the border
585 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) && IsShown() )
587 // This code assumes that wxSizeEvent.GetSize() returns
588 // the area of the entire window, not just the client
590 wxSize newSize
= event
.GetSize();
592 if (m_oldSize
.x
== wxDefaultCoord
&& m_oldSize
.y
== wxDefaultCoord
)
598 if (HasFlag( wxSIMPLE_BORDER
))
600 if (newSize
.y
> m_oldSize
.y
)
604 rect
.width
= m_oldSize
.x
;
605 rect
.y
= m_oldSize
.y
-2;
607 Refresh( true, &rect
);
609 else if (newSize
.y
< m_oldSize
.y
)
615 rect
.width
= newSize
.x
;
616 wxWindowNative::Refresh( true, &rect
);
619 if (newSize
.x
> m_oldSize
.x
)
623 rect
.height
= m_oldSize
.y
;
624 rect
.x
= m_oldSize
.x
-2;
626 Refresh( true, &rect
);
628 else if (newSize
.x
< m_oldSize
.x
)
634 rect
.height
= newSize
.y
;
635 wxWindowNative::Refresh( true, &rect
);
639 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
641 if (newSize
.y
> m_oldSize
.y
)
645 rect
.width
= m_oldSize
.x
;
646 rect
.y
= m_oldSize
.y
-4;
648 Refresh( true, &rect
);
650 else if (newSize
.y
< m_oldSize
.y
)
656 rect
.width
= newSize
.x
;
657 wxWindowNative::Refresh( true, &rect
);
660 if (newSize
.x
> m_oldSize
.x
)
664 rect
.height
= m_oldSize
.y
;
665 rect
.x
= m_oldSize
.x
-4;
667 Refresh( true, &rect
);
669 else if (newSize
.x
< m_oldSize
.x
)
675 rect
.height
= newSize
.y
;
676 wxWindowNative::Refresh( true, &rect
);
685 wxSize
wxWindow::DoGetBestSize() const
687 return AdjustSize(DoGetBestClientSize());
690 wxSize
wxWindow::DoGetBestClientSize() const
692 return wxWindowNative::DoGetBestSize();
695 wxSize
wxWindow::AdjustSize(const wxSize
& size
) const
699 m_renderer
->AdjustSize(&sz
, this);
703 wxPoint
wxWindow::GetClientAreaOrigin() const
705 wxPoint pt
= wxWindowBase::GetClientAreaOrigin();
707 #if wxUSE_TWO_WINDOWS
710 pt
+= m_renderer
->GetBorderDimensions(GetBorder()).GetPosition();
716 void wxWindow::DoGetClientSize(int *width
, int *height
) const
718 // if it is a native window, we assume it handles the scrollbars itself
719 // too - and if it doesn't, there is not much we can do
722 wxWindowNative::DoGetClientSize(width
, height
);
728 wxWindowNative::DoGetClientSize(&w
, &h
);
730 // we assume that the scrollbars are positioned correctly (by a previous
731 // call to PositionScrollbars()) here
735 rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
740 // in any case, take account of the scrollbar
741 if ( m_scrollbarVert
)
742 w
-= m_scrollbarVert
->GetSize().x
;
743 #endif // wxUSE_SCROLLBAR
745 // account for the left and right borders
746 *width
= w
- rectBorder
.x
- rectBorder
.width
;
748 // we shouldn't return invalid width
756 if ( m_scrollbarHorz
)
757 h
-= m_scrollbarHorz
->GetSize().y
;
758 #endif // wxUSE_SCROLLBAR
760 *height
= h
- rectBorder
.y
- rectBorder
.height
;
762 // we shouldn't return invalid height
768 void wxWindow::DoSetClientSize(int width
, int height
)
770 // take into account the borders
771 wxRect rectBorder
= m_renderer
->GetBorderDimensions(GetBorder());
772 width
+= rectBorder
.x
;
773 height
+= rectBorder
.y
;
775 // and the scrollbars (as they may be offset into the border, use the
776 // scrollbar position, not size - this supposes that PositionScrollbars()
777 // had been called before)
778 wxSize size
= GetSize();
780 if ( m_scrollbarVert
)
781 width
+= size
.x
- m_scrollbarVert
->GetPosition().x
;
782 #endif // wxUSE_SCROLLBAR
783 width
+= rectBorder
.width
;
786 if ( m_scrollbarHorz
)
787 height
+= size
.y
- m_scrollbarHorz
->GetPosition().y
;
788 #endif // wxUSE_SCROLLBAR
789 height
+= rectBorder
.height
;
791 wxWindowNative::DoSetClientSize(width
, height
);
794 wxHitTest
wxWindow::DoHitTest(wxCoord x
, wxCoord y
) const
796 wxHitTest ht
= wxWindowNative::DoHitTest(x
, y
);
799 if ( ht
== wxHT_WINDOW_INSIDE
)
801 if ( m_scrollbarVert
&& x
>= m_scrollbarVert
->GetPosition().x
)
803 // it can still be changed below because it may also be the corner
804 ht
= wxHT_WINDOW_VERT_SCROLLBAR
;
807 if ( m_scrollbarHorz
&& y
>= m_scrollbarHorz
->GetPosition().y
)
809 ht
= ht
== wxHT_WINDOW_VERT_SCROLLBAR
? wxHT_WINDOW_CORNER
810 : wxHT_WINDOW_HORZ_SCROLLBAR
;
813 #endif // wxUSE_SCROLLBAR
818 // ----------------------------------------------------------------------------
819 // scrolling: we implement it entirely ourselves except for ScrollWindow()
820 // function which is supposed to be (efficiently) implemented by the native
822 // ----------------------------------------------------------------------------
824 void wxWindow::RefreshScrollbars()
827 if ( m_scrollbarHorz
)
828 m_scrollbarHorz
->Refresh();
830 if ( m_scrollbarVert
)
831 m_scrollbarVert
->Refresh();
832 #endif // wxUSE_SCROLLBAR
835 void wxWindow::PositionScrollbars()
838 // do not use GetClientSize/Rect as it relies on the scrollbars being
839 // correctly positioned
841 wxSize size
= GetSize();
842 wxBorder border
= GetBorder();
843 wxRect rectBorder
= m_renderer
->GetBorderDimensions(border
);
844 bool inside
= m_renderer
->AreScrollbarsInsideBorder();
846 int height
= m_scrollbarHorz
? m_scrollbarHorz
->GetSize().y
: 0;
847 int width
= m_scrollbarVert
? m_scrollbarVert
->GetSize().x
: 0;
850 if ( m_scrollbarVert
)
852 rectBar
.x
= size
.x
- width
;
854 rectBar
.x
-= rectBorder
.width
;
855 rectBar
.width
= width
;
858 rectBar
.y
+= rectBorder
.y
;
859 rectBar
.height
= size
.y
- height
;
861 rectBar
.height
-= rectBorder
.y
+ rectBorder
.height
;
863 m_scrollbarVert
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
866 if ( m_scrollbarHorz
)
868 rectBar
.y
= size
.y
- height
;
870 rectBar
.y
-= rectBorder
.height
;
871 rectBar
.height
= height
;
874 rectBar
.x
+= rectBorder
.x
;
875 rectBar
.width
= size
.x
- width
;
877 rectBar
.width
-= rectBorder
.x
+ rectBorder
.width
;
879 m_scrollbarHorz
->SetSize(rectBar
, wxSIZE_NO_ADJUSTMENTS
);
883 #endif // wxUSE_SCROLLBAR
886 void wxWindow::SetScrollbar(int orient
,
893 wxASSERT_MSG( pageSize
<= range
,
894 _T("page size can't be greater than range") );
896 bool hasClientSizeChanged
= false;
897 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
898 if ( range
&& (pageSize
< range
) )
903 #if wxUSE_TWO_WINDOWS
904 SetInsertIntoMain( true );
906 scrollbar
= new wxScrollBar(this, wxID_ANY
,
907 wxDefaultPosition
, wxDefaultSize
,
908 orient
& wxVERTICAL
? wxSB_VERTICAL
910 #if wxUSE_TWO_WINDOWS
911 SetInsertIntoMain( false );
913 if ( orient
& wxVERTICAL
)
914 m_scrollbarVert
= scrollbar
;
916 m_scrollbarHorz
= scrollbar
;
918 // the client area diminished as we created a scrollbar
919 hasClientSizeChanged
= true;
921 PositionScrollbars();
923 else if ( GetWindowStyle() & wxALWAYS_SHOW_SB
)
925 // we might have disabled it before
929 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
931 else // no range means no scrollbar
935 // wxALWAYS_SHOW_SB only applies to the vertical scrollbar
936 if ( (orient
& wxVERTICAL
) && (GetWindowStyle() & wxALWAYS_SHOW_SB
) )
938 // just disable the scrollbar
939 scrollbar
->SetScrollbar(pos
, pageSize
, range
, pageSize
, refresh
);
940 scrollbar
->Disable();
942 else // really remove the scrollbar
946 if ( orient
& wxVERTICAL
)
947 m_scrollbarVert
= NULL
;
949 m_scrollbarHorz
= NULL
;
951 // the client area increased as we removed a scrollbar
952 hasClientSizeChanged
= true;
954 // the size of the remaining scrollbar must be adjusted
955 if ( m_scrollbarHorz
|| m_scrollbarVert
)
957 PositionScrollbars();
963 // give the window a chance to relayout
964 if ( hasClientSizeChanged
)
966 #if wxUSE_TWO_WINDOWS
967 wxWindowNative::SetSize( GetSize() );
969 wxSizeEvent
event(GetSize());
970 (void)GetEventHandler()->ProcessEvent(event
);
976 wxUnusedVar(pageSize
);
978 wxUnusedVar(refresh
);
979 #endif // wxUSE_SCROLLBAR
982 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
985 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
988 scrollbar
->SetThumbPosition(pos
);
990 // VZ: I think we can safely ignore this as we always refresh it
991 // automatically whenever the value chanegs
999 #endif // wxUSE_SCROLLBAR
1002 int wxWindow::GetScrollPos(int orient
) const
1005 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
1006 return scrollbar
? scrollbar
->GetThumbPosition() : 0;
1008 wxUnusedVar(orient
);
1010 #endif // wxUSE_SCROLLBAR
1013 int wxWindow::GetScrollThumb(int orient
) const
1016 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
1017 return scrollbar
? scrollbar
->GetThumbSize() : 0;
1019 wxUnusedVar(orient
);
1021 #endif // wxUSE_SCROLLBAR
1024 int wxWindow::GetScrollRange(int orient
) const
1027 wxScrollBar
*scrollbar
= GetScrollbar(orient
);
1028 return scrollbar
? scrollbar
->GetRange() : 0;
1030 wxUnusedVar(orient
);
1032 #endif // wxUSE_SCROLLBAR
1035 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1037 // use native scrolling when available and do it in generic way
1041 wxWindowNative::ScrollWindow(dx
, dy
, rect
);
1045 // before scrolling it, ensure that we don't have any unpainted areas
1052 r
= ScrollNoRefresh(dx
, 0, rect
);
1053 Refresh(true /* erase bkgnd */, &r
);
1058 r
= ScrollNoRefresh(0, dy
, rect
);
1059 Refresh(true /* erase bkgnd */, &r
);
1062 // scroll children accordingly:
1063 wxPoint
offset(dx
, dy
);
1065 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1066 node
; node
= node
->GetNext())
1068 wxWindow
*child
= node
->GetData();
1070 if ( child
== m_scrollbarVert
|| child
== m_scrollbarHorz
)
1072 #endif // wxUSE_SCROLLBAR
1074 // VS: Scrolling children has non-trivial semantics. If rect=NULL then
1075 // it is easy: we scroll all children. Otherwise it gets
1077 // 1. if scrolling in one direction only, scroll only
1078 // those children that intersect shaft defined by the rectangle
1079 // and scrolling direction
1080 // 2. if scrolling in both axes, scroll all children
1082 if ( rect
&& (dx
* dy
== 0 /* moving in only one of x, y axis */) )
1084 wxRect childRect
= child
->GetRect();
1085 if ( dx
== 0 && (childRect
.GetLeft() <= rect
->GetRight() ||
1086 childRect
.GetRight() >= rect
->GetLeft()) )
1088 child
->Move(child
->GetPosition() + offset
);
1090 else if ( dy
== 0 && (childRect
.GetTop() <= rect
->GetBottom() ||
1091 childRect
.GetBottom() >= rect
->GetTop()) )
1093 child
->Move(child
->GetPosition() + offset
);
1098 child
->Move(child
->GetPosition() + offset
);
1101 #endif // wxX11/!wxX11
1104 wxRect
wxWindow::ScrollNoRefresh(int dx
, int dy
, const wxRect
*rectTotal
)
1106 wxASSERT_MSG( !dx
|| !dy
, _T("can't be used for diag scrolling") );
1108 // the rect to refresh (which we will calculate)
1117 // calculate the part of the window which we can just redraw in the new
1119 wxSize sizeTotal
= rectTotal
? rectTotal
->GetSize() : GetClientSize();
1121 wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"),
1122 sizeTotal
.x
, sizeTotal
.y
, dx
, dy
);
1124 // the initial and end point of the region we move in client coords
1125 wxPoint ptSource
, ptDest
;
1128 ptSource
= rectTotal
->GetPosition();
1129 ptDest
= rectTotal
->GetPosition();
1132 // the size of this region
1134 size
.x
= sizeTotal
.x
- abs(dx
);
1135 size
.y
= sizeTotal
.y
- abs(dy
);
1136 if ( size
.x
<= 0 || size
.y
<= 0 )
1138 // just redraw everything as nothing of the displayed image will stay
1139 wxLogTrace(_T("scroll"), _T("refreshing everything"));
1141 rect
= rectTotal
? *rectTotal
: wxRect(0, 0, sizeTotal
.x
, sizeTotal
.y
);
1143 else // move the part which doesn't change to the new location
1145 // note that when we scroll the canvas in some direction we move the
1146 // block which doesn't need to be refreshed in the opposite direction
1150 // scroll to the right, move to the left
1155 // scroll to the left, move to the right
1161 // scroll down, move up
1166 // scroll up, move down
1171 // we need to hide the caret before moving or it will erase itself at
1172 // the wrong (old) location
1173 wxCaret
*caret
= GetCaret();
1176 #endif // wxUSE_CARET
1179 wxClientDC
dc(this);
1180 wxBitmap
bmp(size
.x
, size
.y
);
1182 dcMem
.SelectObject(bmp
);
1184 dcMem
.Blit(wxPoint(0,0), size
, &dc
, ptSource
1185 #if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT)
1186 + GetClientAreaOrigin()
1187 #endif // broken wxGTK wxDC::Blit
1189 dc
.Blit(ptDest
, size
, &dcMem
, wxPoint(0,0));
1191 wxLogTrace(_T("scroll"),
1192 _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"),
1193 ptSource
.x
, ptSource
.y
,
1195 ptDest
.x
, ptDest
.y
);
1197 // and now repaint the uncovered area
1199 // FIXME: We repaint the intersection of these rectangles twice - is
1200 // it bad? I don't think so as it is rare to scroll the window
1201 // diagonally anyhow and so adding extra logic to compute
1202 // rectangle intersection is probably not worth the effort
1204 rect
.x
= ptSource
.x
;
1205 rect
.y
= ptSource
.y
;
1211 // refresh the area along the right border
1212 rect
.x
+= size
.x
+ dx
;
1217 // refresh the area along the left border
1221 rect
.height
= sizeTotal
.y
;
1223 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1225 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1232 // refresh the area along the bottom border
1233 rect
.y
+= size
.y
+ dy
;
1238 // refresh the area along the top border
1242 rect
.width
= sizeTotal
.x
;
1244 wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"),
1246 rect
.GetRight() + 1, rect
.GetBottom() + 1);
1252 #endif // wxUSE_CARET
1258 // ----------------------------------------------------------------------------
1259 // accelerators and menu hot keys
1260 // ----------------------------------------------------------------------------
1263 // the last window over which Alt was pressed (used by OnKeyUp)
1264 wxWindow
*wxWindow::ms_winLastAltPress
= NULL
;
1265 #endif // wxUSE_MENUS
1267 #if wxUSE_ACCEL || wxUSE_MENUS
1269 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1272 int key
= event
.GetKeyCode();
1273 if ( !event
.ControlDown() && (key
== WXK_ALT
|| key
== WXK_F10
) )
1275 ms_winLastAltPress
= this;
1277 // it can't be an accel anyhow
1281 ms_winLastAltPress
= NULL
;
1282 #endif // wxUSE_MENUS
1285 for ( wxWindow
*win
= this; win
; win
= win
->GetParent() )
1287 int command
= win
->GetAcceleratorTable()->GetCommand(event
);
1288 if ( command
!= -1 )
1290 wxCommandEvent
eventCmd(wxEVT_COMMAND_MENU_SELECTED
, command
);
1291 if ( win
->GetEventHandler()->ProcessEvent(eventCmd
) )
1293 // skip "event.Skip()" below
1298 if ( win
->IsTopLevel() )
1300 // try the frame menu bar
1302 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1305 wxMenuBar
*menubar
= frame
->GetMenuBar();
1306 if ( menubar
&& menubar
->ProcessAccelEvent(event
) )
1308 // skip "event.Skip()" below
1312 #endif // wxUSE_MENUS
1314 // if it wasn't in a menu, try to find a button
1315 if ( command
!= -1 )
1317 wxWindow
* child
= win
->FindWindow(command
);
1318 if ( child
&& wxDynamicCast(child
, wxButton
) )
1320 wxCommandEvent
eventCmd(wxEVT_COMMAND_BUTTON_CLICKED
, command
);
1321 eventCmd
.SetEventObject(child
);
1322 if ( child
->GetEventHandler()->ProcessEvent(eventCmd
) )
1324 // skip "event.Skip()" below
1330 // don't propagate accels from the child frame to the parent one
1334 #endif // wxUSE_ACCEL
1339 #endif // wxUSE_ACCEL
1343 wxMenuBar
*wxWindow::GetParentFrameMenuBar() const
1345 for ( const wxWindow
*win
= this; win
; win
= win
->GetParent() )
1347 if ( win
->IsTopLevel() )
1349 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
1352 return frame
->GetMenuBar();
1355 // don't look further - we don't want to return the menubar of the
1364 void wxWindow::OnChar(wxKeyEvent
& event
)
1366 if ( event
.AltDown() && !event
.ControlDown() )
1368 int key
= event
.GetKeyCode();
1370 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1373 int item
= menubar
->FindNextItemForAccel(-1, key
);
1376 menubar
->PopupMenu((size_t)item
);
1378 // skip "event.Skip()" below
1387 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1389 int key
= event
.GetKeyCode();
1390 if ( !event
.HasModifiers() && (key
== WXK_ALT
|| key
== WXK_F10
) )
1392 // only process Alt release specially if there were no other key
1393 // presses since Alt had been pressed and if both events happened in
1395 if ( ms_winLastAltPress
== this )
1397 wxMenuBar
*menubar
= GetParentFrameMenuBar();
1398 if ( menubar
&& this != menubar
)
1400 menubar
->SelectMenu(0);
1409 // in any case reset it
1410 ms_winLastAltPress
= NULL
;
1413 #endif // wxUSE_MENUS
1415 // ----------------------------------------------------------------------------
1416 // MSW-specific section
1417 // ----------------------------------------------------------------------------
1421 #include "wx/msw/private.h"
1423 WXLRESULT
wxWindow::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1425 if ( message
== WM_NCHITTEST
)
1427 // the windows which contain the other windows should let the mouse
1428 // events through, otherwise a window inside a static box would
1429 // never get any events at all
1430 if ( IsStaticBox() )
1432 return HTTRANSPARENT
;
1436 return wxWindowNative::MSWWindowProc(message
, wParam
, lParam
);