From 846e1424e2f563b699e7fcb81d10cf6f2246487f Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Thu, 20 Jan 2000 14:16:18 +0000 Subject: [PATCH 1/1] A no-change for scroll events. Added y-axis to wxPlot. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5548 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/generic/plot.h | 20 +++++++-- include/wx/gtk/scrolbar.h | 1 - include/wx/gtk/window.h | 1 + include/wx/gtk1/scrolbar.h | 1 - include/wx/gtk1/window.h | 1 + samples/controls/controls.cpp | 6 +++ samples/plot/plot.cpp | 21 +++++----- src/common/dynlib.cpp | 1 + src/generic/plot.cpp | 77 +++++++++++++++++++++++++++++------ src/gtk/listbox.cpp | 2 +- src/gtk/window.cpp | 7 +++- src/gtk1/listbox.cpp | 2 +- src/gtk1/window.cpp | 7 +++- 13 files changed, 112 insertions(+), 35 deletions(-) diff --git a/include/wx/generic/plot.h b/include/wx/generic/plot.h index dc6faebba3..da2436de3e 100644 --- a/include/wx/generic/plot.h +++ b/include/wx/generic/plot.h @@ -33,18 +33,30 @@ class wxPlotWindow; class WXDLLEXPORT wxPlotCurve: public wxObject { public: - wxPlotCurve( int offsetY ); + wxPlotCurve( int offsetY, double startY, double endY ); virtual wxInt32 GetStartX() = 0; virtual wxInt32 GetEndX() = 0; - + + virtual double GetY( wxInt32 x ) = 0; + + void SetStartY( double startY ) + { m_startY = startY; } + double GetStartY() + { return m_startY; } + void SetEndY( double endY ) + { m_endY = endY; } + double GetEndY() + { return m_endY; } + void SetOffsetY( int offsetY ) + { m_offsetY = offsetY; } int GetOffsetY() { return m_offsetY; } - virtual double GetY( wxInt32 x ) = 0; - private: int m_offsetY; + double m_startY; + double m_endY; DECLARE_ABSTRACT_CLASS(wxPlotCurve) }; diff --git a/include/wx/gtk/scrolbar.h b/include/wx/gtk/scrolbar.h index 0ebb6385e8..612c37afae 100644 --- a/include/wx/gtk/scrolbar.h +++ b/include/wx/gtk/scrolbar.h @@ -87,7 +87,6 @@ public: GtkAdjustment *m_adjust; float m_oldPos; - bool m_isScrolling; private: DECLARE_DYNAMIC_CLASS(wxScrollBar) diff --git a/include/wx/gtk/window.h b/include/wx/gtk/window.h index 0d7b776376..302d12e95f 100644 --- a/include/wx/gtk/window.h +++ b/include/wx/gtk/window.h @@ -185,6 +185,7 @@ public: bool m_isRadioButton:1; /* faster than IS_KIND_OF */ bool m_isFrame:1; /* faster than IS_KIND_OF */ bool m_acceptsFocus:1; /* not wxStaticBox, not wxStaticBitmap etc. */ + bool m_isScrolling; // these are true if the style were set before the widget was realized // (typcally in the constructor) but the actual GTK style must not be set diff --git a/include/wx/gtk1/scrolbar.h b/include/wx/gtk1/scrolbar.h index 0ebb6385e8..612c37afae 100644 --- a/include/wx/gtk1/scrolbar.h +++ b/include/wx/gtk1/scrolbar.h @@ -87,7 +87,6 @@ public: GtkAdjustment *m_adjust; float m_oldPos; - bool m_isScrolling; private: DECLARE_DYNAMIC_CLASS(wxScrollBar) diff --git a/include/wx/gtk1/window.h b/include/wx/gtk1/window.h index 0d7b776376..302d12e95f 100644 --- a/include/wx/gtk1/window.h +++ b/include/wx/gtk1/window.h @@ -185,6 +185,7 @@ public: bool m_isRadioButton:1; /* faster than IS_KIND_OF */ bool m_isFrame:1; /* faster than IS_KIND_OF */ bool m_acceptsFocus:1; /* not wxStaticBox, not wxStaticBitmap etc. */ + bool m_isScrolling; // these are true if the style were set before the widget was realized // (typcally in the constructor) but the actual GTK style must not be set diff --git a/samples/controls/controls.cpp b/samples/controls/controls.cpp index ac536f9b9c..8b5e042fa6 100644 --- a/samples/controls/controls.cpp +++ b/samples/controls/controls.cpp @@ -749,6 +749,12 @@ void MyPanel::OnListBox( wxCommandEvent &event ) { // GetParent()->Move(100, 100); + if (event.GetInt() == -1) + { + m_text->AppendText( "ListBox has no selections anymore\n" ); + return; + } + wxListBox *listbox = event.GetId() == ID_LISTBOX ? m_listbox : m_listboxSorted; diff --git a/samples/plot/plot.cpp b/samples/plot/plot.cpp index 760c941451..50a1932c39 100644 --- a/samples/plot/plot.cpp +++ b/samples/plot/plot.cpp @@ -39,8 +39,8 @@ class MyApp; class MyPlotCurve: public wxPlotCurve { public: - MyPlotCurve( int offsetY ) : - wxPlotCurve( offsetY ) {} + MyPlotCurve( int offsetY, double startY, double endY ) : + wxPlotCurve( offsetY, startY, endY ) {} virtual wxInt32 GetStartX() { return 0; } @@ -51,7 +51,7 @@ public: { double dx = x; dx /= 100; - return sin( dx )+1; + return sin( dx ); } }; @@ -98,7 +98,7 @@ BEGIN_EVENT_TABLE(MyFrame,wxFrame) END_EVENT_TABLE() MyFrame::MyFrame() - : wxFrame( (wxFrame *)NULL, -1, "wxScrolledWindow sample", + : wxFrame( (wxFrame *)NULL, -1, "wxPlotWindow sample", wxPoint(20,20), wxSize(470,500) ) { wxMenu *file_menu = new wxMenu(); @@ -116,10 +116,9 @@ MyFrame::MyFrame() m_plot = new wxPlotWindow( this, -1, wxPoint(0,0), wxSize(100,100), wxSUNKEN_BORDER ); m_plot->SetScrollbars( 10, 10, 500, 0 ); - - m_plot->Add( new MyPlotCurve(100) ); - m_plot->Add( new MyPlotCurve(40) ); - m_plot->Add( new MyPlotCurve(30) ); + + m_plot->Add( new MyPlotCurve( 0, -1.5, 1.5 ) ); + m_plot->Add( new MyPlotCurve( 50, -1.5, 1.5 ) ); m_log = new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,0), wxSize(100,100), wxTE_MULTILINE ); wxLog *old_log = wxLog::SetActiveTarget( new wxLogTextCtrl( m_log ) ); @@ -141,9 +140,9 @@ void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) ) void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) ) { - (void)wxMessageBox( "wxScroll demo II\n" - "Robert Roebling (c) 1998", - "About wxScroll II Demo", wxICON_INFORMATION | wxOK ); + (void)wxMessageBox( "wxPlotWindow Demo\n" + "Robert Roebling (c) 1999,2000", + "About wxPlotWindow Demo", wxICON_INFORMATION | wxOK ); } //----------------------------------------------------------------------------- diff --git a/src/common/dynlib.cpp b/src/common/dynlib.cpp index 1ab0a358f8..876f60c07d 100644 --- a/src/common/dynlib.cpp +++ b/src/common/dynlib.cpp @@ -48,6 +48,7 @@ #elif defined(HAVE_SHL_LOAD) # define wxDllOpen(lib) shl_load(lib.fn_str(), BIND_DEFERRED, 0) # define wxDllClose shl_unload + static inline void *wxDllGetSymbol(shl_t handle, const wxString& name) { void *sym; diff --git a/src/generic/plot.cpp b/src/generic/plot.cpp index ca02719c09..6cace8f2eb 100644 --- a/src/generic/plot.cpp +++ b/src/generic/plot.cpp @@ -33,15 +33,19 @@ #include "wx/generic/plot.h" +#include + //----------------------------------------------------------------------------- // wxPlotCurve //----------------------------------------------------------------------------- IMPLEMENT_ABSTRACT_CLASS(wxPlotCurve, wxObject) -wxPlotCurve::wxPlotCurve( int offsetY ) +wxPlotCurve::wxPlotCurve( int offsetY, double startY, double endY ) { m_offsetY = offsetY; + m_startY = startY; + m_endY = endY; } //----------------------------------------------------------------------------- @@ -84,10 +88,14 @@ void wxPlotArea::OnMouse( wxMouseEvent &event ) { wxPlotCurve *curve = (wxPlotCurve*)node->Data(); - wxCoord offset_y = client_height - curve->GetOffsetY(); - - double dy = curve->GetY( x ); - int curve_y = (wxCoord)(-dy * 100) + offset_y - 1; + double double_client_height = (double)client_height; + double range = curve->GetEndY() - curve->GetStartY(); + double end = curve->GetEndY(); + wxCoord offset_y = curve->GetOffsetY(); + + double dy = (end - curve->GetY( x )) / range; + wxCoord curve_y = (wxCoord)(dy * double_client_height) - offset_y - 1; + if ((y-curve_y < 4) && (y-curve_y > -4)) { m_owner->SetCurrent( curve ); @@ -123,12 +131,14 @@ void wxPlotArea::OnPaint( wxPaintEvent &WXUNUSED(event) ) update_x += view_x; update_y += view_y; +/* if (m_owner->m_current) { dc.SetPen( *wxLIGHT_GREY_PEN ); int base_line = client_height - m_owner->m_current->GetOffsetY(); dc.DrawLine( update_x-1, base_line-1, update_x+update_width+2, base_line-1 ); } +*/ wxNode *node = m_owner->m_curves.First(); while (node) @@ -139,16 +149,20 @@ void wxPlotArea::OnPaint( wxPaintEvent &WXUNUSED(event) ) dc.SetPen( *wxBLACK_PEN ); else dc.SetPen( *wxLIGHT_GREY_PEN ); - wxCoord offset_y = client_height - curve->GetOffsetY(); int start_x = wxMax( update_x-1, curve->GetStartX() ); int end_x = wxMin( update_x+update_width+2, curve->GetEndX() ); + double double_client_height = (double)client_height; + double range = curve->GetEndY() - curve->GetStartY(); + double end = curve->GetEndY(); + wxCoord offset_y = curve->GetOffsetY(); + wxCoord y=0,last_y=0; for (int x = start_x; x < end_x; x++) { - double dy = curve->GetY( x ); - y = (wxCoord)(-dy * 100) + offset_y - 1; + double dy = (end - curve->GetY( x )) / range; + y = (wxCoord)(dy * double_client_height) - offset_y - 1; if (x != start_x) dc.DrawLine( x-1, last_y, x, y ); @@ -238,14 +252,14 @@ wxPlotCurve *wxPlotWindow::GetAt( size_t n ) void wxPlotWindow::SetCurrent( wxPlotCurve* current ) { m_current = current; - m_area->Refresh( TRUE ); + m_area->Refresh( FALSE ); wxPoint pos( m_area->GetPosition() ); int client_width; int client_height; GetClientSize( &client_width, &client_height); - wxRect rect(pos.x-40,0,40,client_height); + wxRect rect(pos.x-45,0,45,client_height); Refresh(TRUE,&rect); } @@ -268,11 +282,50 @@ void wxPlotWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) wxPoint pos( m_area->GetPosition() ); + double range = m_current->GetEndY() - m_current->GetStartY(); + double offset = ((double) m_current->GetOffsetY() / (double)client_height ) * range; + double start = m_current->GetStartY() - offset; + double end = m_current->GetEndY() - offset; + int int_log_range = (int)floor( log10( range ) ); + double step = 1.0; + if (int_log_range > 0) + { + for (int i = 0; i < int_log_range; i++) + step *= 10; + } + if (int_log_range < 0) + { + for (int i = 0; i < -int_log_range; i++) + step /= 10; + } + double lower = ceil(start / step) * step; + double upper = floor(end / step) * step; + int steps = (int)ceil((upper-lower)/step); + if (steps < 3) + { + step /= 2; + if (lower-step > start) lower -= step; + } + + double current = lower; + while (current < upper+(step/2)) + { + int y = (int)((m_current->GetEndY()-current) / range * (double)client_height) - 1; + y -= m_current->GetOffsetY(); + if ((y > 10) && (y < client_height-7)) + { + dc.DrawLine( pos.x-15, y, pos.x-7, y ); + wxString label; + label.Printf( "%.1f", current ); + dc.DrawText( label, pos.x-45, y-7 ); + } + + current += step; + } + dc.DrawLine( pos.x-15, 5, pos.x-15, client_height-5 ); dc.DrawLine( pos.x-19, 9, pos.x-15, 5 ); dc.DrawLine( pos.x-10, 10, pos.x-15, 5 ); - int y = client_height - m_current->GetOffsetY() - 1; - dc.DrawLine( pos.x-15, y, pos.x-7, y ); } diff --git a/src/gtk/listbox.cpp b/src/gtk/listbox.cpp index e03436d1fa..cf6a80e27a 100644 --- a/src/gtk/listbox.cpp +++ b/src/gtk/listbox.cpp @@ -231,7 +231,7 @@ static void gtk_listitem_select_callback( GtkWidget *WXUNUSED(widget), wxListBox if (!listbox->m_hasVMT) return; if (g_blockEventsOnDrag) return; - + wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, listbox->GetId() ); event.SetEventObject( listbox ); diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 2d3fc4c7ab..a7cb687f54 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -1627,7 +1627,7 @@ static void gtk_window_hscroll_change_callback( GtkWidget *WXUNUSED(widget), wxW static gint gtk_scrollbar_button_press_callback( GtkRange *WXUNUSED(widget), GdkEventButton *WXUNUSED(gdk_event), - wxWindow *WXUNUSED(win)) + wxWindow *win) { DEBUG_MAIN_THREAD @@ -1640,6 +1640,7 @@ static gint gtk_scrollbar_button_press_callback( GtkRange *WXUNUSED(widget), // if (gdk_event->window != widget->slider) return FALSE; g_blockEventsOnScroll = TRUE; + win->m_isScrolling = TRUE; return FALSE; } @@ -1650,7 +1651,7 @@ static gint gtk_scrollbar_button_press_callback( GtkRange *WXUNUSED(widget), static gint gtk_scrollbar_button_release_callback( GtkRange *WXUNUSED(widget), GdkEventButton *WXUNUSED(gdk_event), - wxWindow *WXUNUSED(win)) + wxWindow *win) { DEBUG_MAIN_THREAD @@ -1661,6 +1662,7 @@ static gint gtk_scrollbar_button_release_callback( GtkRange *WXUNUSED(widget), // if (gdk_event->window != widget->slider) return FALSE; g_blockEventsOnScroll = FALSE; + win->m_isScrolling = FALSE; return FALSE; } @@ -1926,6 +1928,7 @@ void wxWindow::Init() m_nativeSizeEvent = FALSE; m_hasScrolling = FALSE; + m_isScrolling = FALSE; m_hAdjust = (GtkAdjustment*) NULL; m_vAdjust = (GtkAdjustment*) NULL; diff --git a/src/gtk1/listbox.cpp b/src/gtk1/listbox.cpp index e03436d1fa..cf6a80e27a 100644 --- a/src/gtk1/listbox.cpp +++ b/src/gtk1/listbox.cpp @@ -231,7 +231,7 @@ static void gtk_listitem_select_callback( GtkWidget *WXUNUSED(widget), wxListBox if (!listbox->m_hasVMT) return; if (g_blockEventsOnDrag) return; - + wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, listbox->GetId() ); event.SetEventObject( listbox ); diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index 2d3fc4c7ab..a7cb687f54 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -1627,7 +1627,7 @@ static void gtk_window_hscroll_change_callback( GtkWidget *WXUNUSED(widget), wxW static gint gtk_scrollbar_button_press_callback( GtkRange *WXUNUSED(widget), GdkEventButton *WXUNUSED(gdk_event), - wxWindow *WXUNUSED(win)) + wxWindow *win) { DEBUG_MAIN_THREAD @@ -1640,6 +1640,7 @@ static gint gtk_scrollbar_button_press_callback( GtkRange *WXUNUSED(widget), // if (gdk_event->window != widget->slider) return FALSE; g_blockEventsOnScroll = TRUE; + win->m_isScrolling = TRUE; return FALSE; } @@ -1650,7 +1651,7 @@ static gint gtk_scrollbar_button_press_callback( GtkRange *WXUNUSED(widget), static gint gtk_scrollbar_button_release_callback( GtkRange *WXUNUSED(widget), GdkEventButton *WXUNUSED(gdk_event), - wxWindow *WXUNUSED(win)) + wxWindow *win) { DEBUG_MAIN_THREAD @@ -1661,6 +1662,7 @@ static gint gtk_scrollbar_button_release_callback( GtkRange *WXUNUSED(widget), // if (gdk_event->window != widget->slider) return FALSE; g_blockEventsOnScroll = FALSE; + win->m_isScrolling = FALSE; return FALSE; } @@ -1926,6 +1928,7 @@ void wxWindow::Init() m_nativeSizeEvent = FALSE; m_hasScrolling = FALSE; + m_isScrolling = FALSE; m_hAdjust = (GtkAdjustment*) NULL; m_vAdjust = (GtkAdjustment*) NULL; -- 2.45.2