Scrolling updates.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3917 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
1999-10-10 18:42:43 +00:00
parent fb9010ed40
commit bf0c00c6e8
5 changed files with 97 additions and 99 deletions

View File

@@ -74,7 +74,6 @@ public:
void OnQuit(wxCommandEvent& event); void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event); void OnAbout(wxCommandEvent& event);
void OnOption(wxCommandEvent &event); void OnOption(wxCommandEvent &event);
void OnMouseMove(wxMouseEvent &event);
wxColour SelectColour(); wxColour SelectColour();
void PrepareDC(wxDC& dc); void PrepareDC(wxDC& dc);
@@ -105,6 +104,7 @@ public:
void DrawTestLines( int x, int y, int width, wxDC &dc ); void DrawTestLines( int x, int y, int width, wxDC &dc );
void OnPaint(wxPaintEvent &event); void OnPaint(wxPaintEvent &event);
void OnMouseMove(wxMouseEvent &event);
protected: protected:
MyFrame *m_owner; MyFrame *m_owner;
@@ -199,6 +199,7 @@ bool MyApp::OnInit()
// handlers) which process them. // handlers) which process them.
BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
EVT_PAINT (MyCanvas::OnPaint) EVT_PAINT (MyCanvas::OnPaint)
EVT_MOTION (MyCanvas::OnMouseMove)
END_EVENT_TABLE() END_EVENT_TABLE()
MyCanvas::MyCanvas( MyFrame *parent ) MyCanvas::MyCanvas( MyFrame *parent )
@@ -307,6 +308,20 @@ void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event))
} }
void MyCanvas::OnMouseMove(wxMouseEvent &event)
{
wxClientDC dc(this);
PrepareDC(dc);
m_owner->PrepareDC(dc);
wxPoint pos = event.GetPosition();
long x = dc.DeviceToLogicalX( pos.x );
long y = dc.DeviceToLogicalY( pos.y );
wxString str;
str.Printf( "Current mouse position: %d,%d", (int)x, (int)y );
m_owner->SetStatusText( str );
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// MyFrame // MyFrame
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -315,7 +330,6 @@ void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event))
// handlers) which process them. It can be also done at run-time, but for the // handlers) which process them. It can be also done at run-time, but for the
// simple menu events like this the static method is much simpler. // simple menu events like this the static method is much simpler.
BEGIN_EVENT_TABLE(MyFrame, wxFrame) BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MOTION (MyFrame::OnMouseMove)
EVT_MENU (Minimal_Quit, MyFrame::OnQuit) EVT_MENU (Minimal_Quit, MyFrame::OnQuit)
EVT_MENU (Minimal_About, MyFrame::OnAbout) EVT_MENU (Minimal_About, MyFrame::OnAbout)
EVT_MENU_RANGE(MenuOption_First, MenuOption_Last, MyFrame::OnOption) EVT_MENU_RANGE(MenuOption_First, MenuOption_Last, MyFrame::OnOption)
@@ -504,19 +518,6 @@ void MyFrame::PrepareDC(wxDC& dc)
dc.SetAxisOrientation( !m_xAxisReversed, m_yAxisReversed ); dc.SetAxisOrientation( !m_xAxisReversed, m_yAxisReversed );
} }
void MyFrame::OnMouseMove(wxMouseEvent &event)
{
wxClientDC dc(this);
PrepareDC(dc);
wxPoint pos = event.GetPosition();
long x = dc.DeviceToLogicalX( pos.x );
long y = dc.DeviceToLogicalY( pos.y );
wxString str;
str.Printf( "Current mouse position: %d,%d", (int)x, (int)y );
SetStatusText( str );
}
wxColour MyFrame::SelectColour() wxColour MyFrame::SelectColour()
{ {
wxColour col; wxColour col;

View File

@@ -43,6 +43,7 @@ public:
void OnDeleteButton( wxCommandEvent &event ); void OnDeleteButton( wxCommandEvent &event );
void OnMoveButton( wxCommandEvent &event ); void OnMoveButton( wxCommandEvent &event );
void OnScrollWin( wxCommandEvent &event ); void OnScrollWin( wxCommandEvent &event );
void OnMouseDown( wxMouseEvent &event );
wxButton *m_button; wxButton *m_button;
@@ -95,6 +96,7 @@ IMPLEMENT_DYNAMIC_CLASS(MyCanvas, wxScrolledWindow)
BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
EVT_PAINT( MyCanvas::OnPaint) EVT_PAINT( MyCanvas::OnPaint)
EVT_LEFT_DOWN( MyCanvas::OnMouseDown)
EVT_BUTTON( ID_QUERYPOS, MyCanvas::OnQueryPosition) EVT_BUTTON( ID_QUERYPOS, MyCanvas::OnQueryPosition)
EVT_BUTTON( ID_ADDBUTTON, MyCanvas::OnAddButton) EVT_BUTTON( ID_ADDBUTTON, MyCanvas::OnAddButton)
EVT_BUTTON( ID_DELBUTTON, MyCanvas::OnDeleteButton) EVT_BUTTON( ID_DELBUTTON, MyCanvas::OnDeleteButton)
@@ -174,20 +176,40 @@ MyCanvas::~MyCanvas()
{ {
} }
void MyCanvas::OnMouseDown( wxMouseEvent &event )
{
wxPoint pt( event.GetPosition() );
int x,y;
CalcUnscrolledPosition( pt.x, pt.y, &x, &y );
wxLogMessage( "Mouse down event at: %d %d, scrolled: %d %d", pt.x, pt.y, x, y );
}
void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
{
wxPaintDC dc( this );
PrepareDC( dc );
dc.DrawText( "Press mouse button to test calculations!", 160, 50 );
dc.DrawText( "Some text", 140, 140 );
dc.DrawRectangle( 100, 160, 200, 200 );
}
void MyCanvas::OnQueryPosition( wxCommandEvent &WXUNUSED(event) ) void MyCanvas::OnQueryPosition( wxCommandEvent &WXUNUSED(event) )
{ {
wxPoint pt( m_button->GetPosition() ); wxPoint pt( m_button->GetPosition() );
wxLogMessage( """wxButton"" position %d %d", pt.x, pt.y ); wxLogMessage( "Position of ""Query position"" is %d %d", pt.x, pt.y );
if ((pt.x == 10) && (pt.y == 110)) pt = ClientToScreen( pt );
wxLogMessage( "-> Correct." ); wxLogMessage( "Position of ""Query position"" on screen is %d %d", pt.x, pt.y );
else
wxLogMessage( "-> Incorrect." );
} }
void MyCanvas::OnAddButton( wxCommandEvent &WXUNUSED(event) ) void MyCanvas::OnAddButton( wxCommandEvent &WXUNUSED(event) )
{ {
wxLogMessage( "Inserting button at position 10,70..." ); wxLogMessage( "Inserting button at position 10,70..." );
(void) new wxButton( this, ID_NEWBUTTON, "new button", wxPoint(10,70), wxSize(80,25) ); wxButton *button = new wxButton( this, ID_NEWBUTTON, "new button", wxPoint(10,70), wxSize(80,25) );
wxPoint pt( button->GetPosition() );
wxLogMessage( "-> Position after inserting %d %d", pt.x, pt.y );
} }
void MyCanvas::OnDeleteButton( wxCommandEvent &event ) void MyCanvas::OnDeleteButton( wxCommandEvent &event )
@@ -204,7 +226,11 @@ void MyCanvas::OnMoveButton( wxCommandEvent &event )
{ {
wxLogMessage( "Moving button 10 pixels downward.." ); wxLogMessage( "Moving button 10 pixels downward.." );
wxWindow *win = FindWindow( event.GetId() ); wxWindow *win = FindWindow( event.GetId() );
win->Move( -1, win->GetPosition().y + 10 ); wxPoint pt( win->GetPosition() );
wxLogMessage( "-> Position before move is %d %d", pt.x, pt.y );
win->Move( -1, pt.y + 10 );
pt = win->GetPosition();
wxLogMessage( "-> Position after move is %d %d", pt.x, pt.y );
} }
void MyCanvas::OnScrollWin( wxCommandEvent &WXUNUSED(event) ) void MyCanvas::OnScrollWin( wxCommandEvent &WXUNUSED(event) )
@@ -215,18 +241,6 @@ void MyCanvas::OnScrollWin( wxCommandEvent &WXUNUSED(event) )
Scroll( -1, y+2 ); Scroll( -1, y+2 );
} }
void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
{
wxPaintDC dc( this );
PrepareDC( dc );
dc.DrawText( "Some text", 140, 140 );
dc.DrawRectangle( 10, 70, 80, 25 );
dc.DrawRectangle( 100, 160, 200, 200 );
}
// MyFrame // MyFrame
const int ID_QUIT = 108; const int ID_QUIT = 108;

View File

@@ -1711,6 +1711,12 @@ gtk_window_realized_callback( GtkWidget * WXUNUSED(widget), wxWindow *win )
static void wxInsertChildInWindow( wxWindow* parent, wxWindow* child ) static void wxInsertChildInWindow( wxWindow* parent, wxWindow* child )
{ {
/* the window might have been scrolled already, do we
have to adapt the position */
GtkMyFixed *myfixed = GTK_MYFIXED(parent->m_wxwindow);
child->m_x += myfixed->xoffset;
child->m_y += myfixed->yoffset;
gtk_myfixed_put( GTK_MYFIXED(parent->m_wxwindow), gtk_myfixed_put( GTK_MYFIXED(parent->m_wxwindow),
GTK_WIDGET(child->m_widget), GTK_WIDGET(child->m_widget),
child->m_x, child->m_x,
@@ -2114,17 +2120,19 @@ void wxWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags )
} }
else else
{ {
GtkMyFixed *myfixed = GTK_MYFIXED(m_parent->m_wxwindow);
if ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0) if ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0)
{ {
if (x != -1) m_x = x; if (x != -1) m_x = x + myfixed->xoffset;
if (y != -1) m_y = y; if (y != -1) m_y = y + myfixed->yoffset;
if (width != -1) m_width = width; if (width != -1) m_width = width;
if (height != -1) m_height = height; if (height != -1) m_height = height;
} }
else else
{ {
m_x = x; m_x = x + myfixed->xoffset;
m_y = y; m_y = y + myfixed->yoffset;
m_width = width; m_width = width;
m_height = height; m_height = height;
} }
@@ -2154,27 +2162,6 @@ void wxWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags )
bottom_border = 5; bottom_border = 5;
} }
/* this is the result of hours of debugging: the following code
means that if we have a m_wxwindow and we set the size of
m_widget, m_widget (which is a GtkScrolledWindow) does NOT
automatically propagate its size down to its m_wxwindow,
which is its client area. therefore, we have to tell the
client area directly that it has to resize itself.
this will lead to that m_widget (GtkScrolledWindow) will
calculate how much size it needs for scrollbars etc and
it will then call XXX_size_allocate of its child, which
is m_wxwindow. m_wxwindow in turn will do the same with its
children and so on. problems can arise if this happens
before all the children have been realized as some widgets
stupidy need to be realized during XXX_size_allocate (e.g.
GtkNotebook) and they will segv if called otherwise. this
emergency is tested in gtk_myfixed_size_allocate. Normally
this shouldn't be needed and only gtk_widget_queue_resize()
should be enough to provoke a resize at the next appropriate
moment, but this seems to fail, e.g. when a wxNotebook contains
a wxSplitterWindow: the splitter window's children won't
show up properly resized then. */
gtk_myfixed_set_size( GTK_MYFIXED(m_parent->m_wxwindow), gtk_myfixed_set_size( GTK_MYFIXED(m_parent->m_wxwindow),
m_widget, m_widget,
m_x-border, m_x-border,
@@ -2203,7 +2190,7 @@ void wxWindow::OnInternalIdle()
as setting the cursor in a parent window also effects the as setting the cursor in a parent window also effects the
windows above so that checking for the current cursor is windows above so that checking for the current cursor is
not possible. */ not possible. */
if (m_wxwindow) if (m_wxwindow)
{ {
GdkWindow *window = GTK_MYFIXED(m_wxwindow)->bin_window; GdkWindow *window = GTK_MYFIXED(m_wxwindow)->bin_window;
@@ -2392,8 +2379,17 @@ void wxWindow::DoGetPosition( int *x, int *y ) const
{ {
wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); wxCHECK_RET( (m_widget != NULL), wxT("invalid window") );
if (x) (*x) = m_x; int dx = 0;
if (y) (*y) = m_y; int dy = 0;
if (m_parent && m_parent->m_wxwindow)
{
GtkMyFixed *myfixed = GTK_MYFIXED(m_parent->m_wxwindow);
dx = myfixed->xoffset;
dy = myfixed->yoffset;
}
if (x) (*x) = m_x - dx;
if (y) (*y) = m_y - dy;
} }
void wxWindow::DoClientToScreen( int *x, int *y ) const void wxWindow::DoClientToScreen( int *x, int *y ) const

View File

@@ -1711,6 +1711,12 @@ gtk_window_realized_callback( GtkWidget * WXUNUSED(widget), wxWindow *win )
static void wxInsertChildInWindow( wxWindow* parent, wxWindow* child ) static void wxInsertChildInWindow( wxWindow* parent, wxWindow* child )
{ {
/* the window might have been scrolled already, do we
have to adapt the position */
GtkMyFixed *myfixed = GTK_MYFIXED(parent->m_wxwindow);
child->m_x += myfixed->xoffset;
child->m_y += myfixed->yoffset;
gtk_myfixed_put( GTK_MYFIXED(parent->m_wxwindow), gtk_myfixed_put( GTK_MYFIXED(parent->m_wxwindow),
GTK_WIDGET(child->m_widget), GTK_WIDGET(child->m_widget),
child->m_x, child->m_x,
@@ -2114,17 +2120,19 @@ void wxWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags )
} }
else else
{ {
GtkMyFixed *myfixed = GTK_MYFIXED(m_parent->m_wxwindow);
if ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0) if ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0)
{ {
if (x != -1) m_x = x; if (x != -1) m_x = x + myfixed->xoffset;
if (y != -1) m_y = y; if (y != -1) m_y = y + myfixed->yoffset;
if (width != -1) m_width = width; if (width != -1) m_width = width;
if (height != -1) m_height = height; if (height != -1) m_height = height;
} }
else else
{ {
m_x = x; m_x = x + myfixed->xoffset;
m_y = y; m_y = y + myfixed->yoffset;
m_width = width; m_width = width;
m_height = height; m_height = height;
} }
@@ -2154,27 +2162,6 @@ void wxWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags )
bottom_border = 5; bottom_border = 5;
} }
/* this is the result of hours of debugging: the following code
means that if we have a m_wxwindow and we set the size of
m_widget, m_widget (which is a GtkScrolledWindow) does NOT
automatically propagate its size down to its m_wxwindow,
which is its client area. therefore, we have to tell the
client area directly that it has to resize itself.
this will lead to that m_widget (GtkScrolledWindow) will
calculate how much size it needs for scrollbars etc and
it will then call XXX_size_allocate of its child, which
is m_wxwindow. m_wxwindow in turn will do the same with its
children and so on. problems can arise if this happens
before all the children have been realized as some widgets
stupidy need to be realized during XXX_size_allocate (e.g.
GtkNotebook) and they will segv if called otherwise. this
emergency is tested in gtk_myfixed_size_allocate. Normally
this shouldn't be needed and only gtk_widget_queue_resize()
should be enough to provoke a resize at the next appropriate
moment, but this seems to fail, e.g. when a wxNotebook contains
a wxSplitterWindow: the splitter window's children won't
show up properly resized then. */
gtk_myfixed_set_size( GTK_MYFIXED(m_parent->m_wxwindow), gtk_myfixed_set_size( GTK_MYFIXED(m_parent->m_wxwindow),
m_widget, m_widget,
m_x-border, m_x-border,
@@ -2203,7 +2190,7 @@ void wxWindow::OnInternalIdle()
as setting the cursor in a parent window also effects the as setting the cursor in a parent window also effects the
windows above so that checking for the current cursor is windows above so that checking for the current cursor is
not possible. */ not possible. */
if (m_wxwindow) if (m_wxwindow)
{ {
GdkWindow *window = GTK_MYFIXED(m_wxwindow)->bin_window; GdkWindow *window = GTK_MYFIXED(m_wxwindow)->bin_window;
@@ -2392,8 +2379,17 @@ void wxWindow::DoGetPosition( int *x, int *y ) const
{ {
wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); wxCHECK_RET( (m_widget != NULL), wxT("invalid window") );
if (x) (*x) = m_x; int dx = 0;
if (y) (*y) = m_y; int dy = 0;
if (m_parent && m_parent->m_wxwindow)
{
GtkMyFixed *myfixed = GTK_MYFIXED(m_parent->m_wxwindow);
dx = myfixed->xoffset;
dy = myfixed->yoffset;
}
if (x) (*x) = m_x - dx;
if (y) (*y) = m_y - dy;
} }
void wxWindow::DoClientToScreen( int *x, int *y ) const void wxWindow::DoClientToScreen( int *x, int *y ) const

View File

@@ -463,13 +463,8 @@ void wxHtmlWidgetCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2)
c = c -> GetParent(); c = c -> GetParent();
} }
#ifdef __WXMSW__
((wxScrolledWindow*)(m_Wnd -> GetParent())) -> ViewStart(&stx, &sty); ((wxScrolledWindow*)(m_Wnd -> GetParent())) -> ViewStart(&stx, &sty);
m_Wnd -> SetSize(absx - HTML_SCROLL_STEP * stx, absy - HTML_SCROLL_STEP * sty, m_Width, m_Height); m_Wnd -> SetSize(absx - HTML_SCROLL_STEP * stx, absy - HTML_SCROLL_STEP * sty, m_Width, m_Height);
#else
m_Wnd -> SetSize(absx, absy, m_Width, m_Height);
#endif
wxHtmlCell::Draw(dc, x, y, view_y1, view_y2); wxHtmlCell::Draw(dc, x, y, view_y1, view_y2);
} }
@@ -487,13 +482,9 @@ void wxHtmlWidgetCell::DrawInvisible(wxDC& dc, int x, int y)
c = c -> GetParent(); c = c -> GetParent();
} }
#ifdef __WXMSW__
((wxScrolledWindow*)(m_Wnd -> GetParent())) -> ViewStart(&stx, &sty); ((wxScrolledWindow*)(m_Wnd -> GetParent())) -> ViewStart(&stx, &sty);
m_Wnd -> SetSize(absx - HTML_SCROLL_STEP * stx, absy - HTML_SCROLL_STEP * sty, m_Width, m_Height); m_Wnd -> SetSize(absx - HTML_SCROLL_STEP * stx, absy - HTML_SCROLL_STEP * sty, m_Width, m_Height);
#else
m_Wnd -> SetSize(absx, absy, m_Width, m_Height);
#endif
wxHtmlCell::DrawInvisible(dc, x, y); wxHtmlCell::DrawInvisible(dc, x, y);
} }