(completely failed so far) attempt to make wxScrolledWindow work
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/wxUNIVERSAL@8204 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -80,10 +80,12 @@ public:
|
|||||||
int page,
|
int page,
|
||||||
int range,
|
int range,
|
||||||
bool refresh = TRUE );
|
bool refresh = TRUE );
|
||||||
virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE );
|
virtual void SetScrollPos(int orient, int pos, bool refresh = TRUE);
|
||||||
virtual int GetScrollPos( int orient ) const;
|
virtual int GetScrollPos(int orient) const;
|
||||||
virtual int GetScrollThumb( int orient ) const;
|
virtual int GetScrollThumb(int orient) const;
|
||||||
virtual int GetScrollRange( int orient ) const;
|
virtual int GetScrollRange(int orient) const;
|
||||||
|
virtual void ScrollWindow(int dx, int dy,
|
||||||
|
const wxRect* rect = (wxRect *) NULL);
|
||||||
|
|
||||||
// miscellaneous other methods
|
// miscellaneous other methods
|
||||||
// ---------------------------
|
// ---------------------------
|
||||||
|
@@ -110,6 +110,23 @@ private:
|
|||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Define a new canvas class: we will use it for drawing
|
||||||
|
class MyUnivCanvas : public wxScrolledWindow
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MyUnivCanvas(wxWindow *parent,
|
||||||
|
const wxPoint& pos,
|
||||||
|
const wxSize& size,
|
||||||
|
long style = 0)
|
||||||
|
: wxScrolledWindow(parent, -1, pos, size, style) { }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void OnPaint(wxPaintEvent& event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
DECLARE_EVENT_TABLE()
|
||||||
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// event tables
|
// event tables
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -122,6 +139,10 @@ BEGIN_EVENT_TABLE(MyUnivFrame, wxFrame)
|
|||||||
EVT_LEFT_UP(MyUnivFrame::OnLeftUp)
|
EVT_LEFT_UP(MyUnivFrame::OnLeftUp)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
BEGIN_EVENT_TABLE(MyUnivCanvas, wxScrolledWindow)
|
||||||
|
EVT_PAINT(MyUnivCanvas::OnPaint)
|
||||||
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// implementation
|
// implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -243,7 +264,7 @@ MyUnivFrame::MyUnivFrame(const wxString& title)
|
|||||||
sb->SetScrollbar(0, 10, 100, 10);
|
sb->SetScrollbar(0, 10, 100, 10);
|
||||||
sb = new wxScrollBar(this, -1, wxPoint(200, 330), wxSize(-1, 150), wxSB_VERTICAL);
|
sb = new wxScrollBar(this, -1, wxPoint(200, 330), wxSize(-1, 150), wxSB_VERTICAL);
|
||||||
sb->SetScrollbar(50, 50, 100, 10);
|
sb->SetScrollbar(50, 50, 100, 10);
|
||||||
#elif 1
|
#elif 0
|
||||||
wxWindow *win = new wxWindow(this, -1,
|
wxWindow *win = new wxWindow(this, -1,
|
||||||
wxPoint(200, 300),
|
wxPoint(200, 300),
|
||||||
wxSize(300, 150),
|
wxSize(300, 150),
|
||||||
@@ -251,11 +272,12 @@ MyUnivFrame::MyUnivFrame(const wxString& title)
|
|||||||
win->SetScrollbar(wxHORIZONTAL, 0, 10, 30);
|
win->SetScrollbar(wxHORIZONTAL, 0, 10, 30);
|
||||||
win->SetScrollbar(wxVERTICAL, 0, 5, 30);
|
win->SetScrollbar(wxVERTICAL, 0, 5, 30);
|
||||||
#else
|
#else
|
||||||
wxScrolledWindow *win = new wxScrolledWindow(this, -1,
|
wxScrolledWindow *win = new MyUnivCanvas(this,
|
||||||
wxPoint(200, 300),
|
wxPoint(200, 300),
|
||||||
wxSize(300, 150),
|
wxSize(300, 150),
|
||||||
wxSUNKEN_BORDER);
|
wxSUNKEN_BORDER);
|
||||||
win->SetScrollbars(10, 5, 30, 30, 15, 15);
|
win->SetScrollbars(10, 10, 100, 100, 0, 0);
|
||||||
|
win->ScrollWindow(100, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
new wxButton(this, -1, wxBITMAP(open), _T("&Open..."), wxPoint(10, 420));
|
new wxButton(this, -1, wxBITMAP(open), _T("&Open..."), wxPoint(10, 420));
|
||||||
@@ -293,3 +315,16 @@ void MyUnivFrame::OnLeftUp(wxMouseEvent& event)
|
|||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// MyUnivCanvas
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void MyUnivCanvas::OnPaint(wxPaintEvent& event)
|
||||||
|
{
|
||||||
|
wxPaintDC dc(this);
|
||||||
|
dc.SetPen(*wxRED_PEN);
|
||||||
|
dc.DrawLine(0, 0, 1000, 1000);
|
||||||
|
dc.DrawText(_T("This is a canvas"), 10, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -312,3 +312,82 @@ int wxWindow::GetScrollRange(int orient) const
|
|||||||
wxScrollBar *scrollbar = GetScrollbar(orient);
|
wxScrollBar *scrollbar = GetScrollbar(orient);
|
||||||
return scrollbar ? scrollbar->GetRange() : 0;
|
return scrollbar ? scrollbar->GetRange() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect)
|
||||||
|
{
|
||||||
|
wxASSERT_MSG( !rect, _T("scrolling only part of window not implemented") );
|
||||||
|
|
||||||
|
if ( !dx && !dy )
|
||||||
|
{
|
||||||
|
// nothing to do
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculate the part of the window which we can just redraw in the new
|
||||||
|
// location
|
||||||
|
wxSize sizeTotal = GetClientSize();
|
||||||
|
wxPoint ptSource, ptDest;
|
||||||
|
wxSize size;
|
||||||
|
size.x = sizeTotal.x - dx;
|
||||||
|
size.y = sizeTotal.y - dy;
|
||||||
|
if ( size.x < 0 || size.y < 0 )
|
||||||
|
{
|
||||||
|
// just redraw everything as nothing of the displayed image will stay
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
|
else // move the part which doesn't change to the new location
|
||||||
|
{
|
||||||
|
// positive values mean to scroll to thr right/down
|
||||||
|
if ( dx > 0 )
|
||||||
|
{
|
||||||
|
ptSource.x = 0;
|
||||||
|
ptDest.x = dx;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ptSource.x = dx;
|
||||||
|
ptDest.x = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( dy > 0 )
|
||||||
|
{
|
||||||
|
ptSource.y = 0;
|
||||||
|
ptDest.y = dy;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ptSource.y = dy;
|
||||||
|
ptDest.y = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// do move
|
||||||
|
wxClientDC dc(this);
|
||||||
|
dc.Blit(ptDest, size, &dc, ptSource);
|
||||||
|
|
||||||
|
// and now repaint the uncovered area
|
||||||
|
|
||||||
|
// FIXME: we repaint the intersection of these rectangles twice - is
|
||||||
|
// it bad?
|
||||||
|
|
||||||
|
wxRect rect;
|
||||||
|
rect.x = ptSource.x;
|
||||||
|
rect.y = ptSource.y;
|
||||||
|
|
||||||
|
if ( dx )
|
||||||
|
{
|
||||||
|
rect.width = abs(ptDest.x - ptSource.x);
|
||||||
|
rect.height = sizeTotal.y;
|
||||||
|
|
||||||
|
Refresh(TRUE /* erase bkgnd */, &rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( dy )
|
||||||
|
{
|
||||||
|
rect.width = sizeTotal.x;
|
||||||
|
rect.height = abs(ptDest.y - ptSource.y);
|
||||||
|
|
||||||
|
Refresh(TRUE /* erase bkgnd */, &rect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user