wxgrid scroll events do not work on ubuntu?

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
james28909
Knows some wx things
Knows some wx things
Posts: 39
Joined: Mon Jul 01, 2019 8:27 pm

wxgrid scroll events do not work on ubuntu?

Post by james28909 » Wed Jul 31, 2019 2:48 am

same grid and events work fine on win10 64bit. and the gui itself works fine on ubuntu, but it cannot process EVT_SCROLLWIN_LINEUP and EVT_SCROLLWIN_LINEDOWN. is this possible on anything other than win32?

EDIT: i just realized i had a typo in my original question. changed EVT_SCROLL to EVT_SCROLLWIN
Last edited by james28909 on Sat Aug 03, 2019 12:03 pm, edited 1 time in total.

User avatar
doublemax
Moderator
Moderator
Posts: 13872
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxgrid scroll events do not work on ubuntu?

Post by doublemax » Wed Jul 31, 2019 5:04 am

Can you show how you connect the event handlers? And, are you really using EVT_SCROLL_LINEUP and EVT_SCROLL_LINEDOWN? That should probably be EVT_SCROLLWIN_LINEUP and EVT_SCROLLWIN_LINEDOWN.
Use the source, Luke!

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2007
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxgrid scroll events do not work on ubuntu?

Post by PB » Wed Jul 31, 2019 7:29 am

I have just tested with recentish wxWidgets master: as doublemax said only wxEVT_SCROLLWIN_* events are sent even on MSW. This makes perfect sense as wxGrid is derived from wxScrolled and wxEVT_SCROLL_* is only for wxScrollBar and wxSlider.

Using this code confirms it:

Code: Select all

#include <wx/wx.h>
#include <wx/grid.h>

class MyFrame: public wxFrame
{
public:   
    MyFrame() : wxFrame (NULL, wxID_ANY, "Test", wxDefaultPosition, wxSize(800, 800))
    {        
        wxPanel* mainPanel = new wxPanel(this);
        
         wxTextCtrl* logCtrl = new wxTextCtrl(mainPanel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 
            wxTE_MULTILINE | wxTE_READONLY | wxTE_RICH2);     
        wxLog::SetActiveTarget(new wxLogTextCtrl(logCtrl)); 

        wxGrid* grid = new wxGrid(mainPanel, wxID_ANY);
        grid->CreateGrid(200, 50);
                        
        wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
        
        mainSizer->Add(logCtrl, wxSizerFlags().Expand().DoubleBorder().Proportion(1));
        mainSizer->Add(grid, wxSizerFlags().Expand().DoubleBorder().Proportion(1));        
        mainPanel->SetSizer(mainSizer);

        grid->Bind(wxEVT_SCROLL_TOP, &MyFrame::OnScroll, this);        
        grid->Bind(wxEVT_SCROLL_BOTTOM, &MyFrame::OnScroll, this);
        grid->Bind(wxEVT_SCROLL_LINEUP, &MyFrame::OnScroll, this);
        grid->Bind(wxEVT_SCROLL_LINEDOWN, &MyFrame::OnScroll, this);
        grid->Bind(wxEVT_SCROLL_PAGEUP, &MyFrame::OnScroll, this);
        grid->Bind(wxEVT_SCROLL_PAGEDOWN, &MyFrame::OnScroll, this);
        grid->Bind(wxEVT_SCROLL_THUMBTRACK, &MyFrame::OnScroll, this);
        grid->Bind(wxEVT_SCROLL_THUMBRELEASE, &MyFrame::OnScroll, this);
        grid->Bind(wxEVT_SCROLL_CHANGED, &MyFrame::OnScroll, this);

        grid->Bind(wxEVT_SCROLLWIN_TOP, &MyFrame::OnScrollWin, this);        
        grid->Bind(wxEVT_SCROLLWIN_BOTTOM, &MyFrame::OnScrollWin, this);
        grid->Bind(wxEVT_SCROLLWIN_LINEUP, &MyFrame::OnScrollWin, this);
        grid->Bind(wxEVT_SCROLLWIN_LINEDOWN, &MyFrame::OnScrollWin, this);
        grid->Bind(wxEVT_SCROLLWIN_PAGEUP, &MyFrame::OnScrollWin, this);
        grid->Bind(wxEVT_SCROLLWIN_PAGEDOWN, &MyFrame::OnScrollWin, this);
        grid->Bind(wxEVT_SCROLLWIN_THUMBTRACK, &MyFrame::OnScrollWin, this);
        grid->Bind(wxEVT_SCROLLWIN_THUMBRELEASE, &MyFrame::OnScrollWin, this);        
    }

    void OnScroll(wxScrollEvent& evt)
    {
         static const wxString eventNames[] =
        {
            "wxEVT_SCROLL_TOP", "wxEVT_SCROLL_BOTTOM",
            "wxEVT_SCROLL_LINEUP", "wxEVT_SCROLL_LINEDOWN",
            "wxEVT_SCROLL_PAGEUP", "wxEVT_SCROLL_PAGEDOWN",
            "wxEVT_SCROLL_THUMBTRACK", "wxEVT_SCROLL_THUMBRELEASE",
            "wxEVT_SCROLL_CHANGED"
        };

        wxLogMessage("OnScroll(): %s,  pos = %d", eventNames[evt.GetEventType() - wxEVT_SCROLL_TOP],
            evt.GetPosition());
        evt.Skip();
    }

     void OnScrollWin(wxScrollWinEvent& evt)
    {
        static const wxString eventNames[] =
        {
            "wxEVT_SCROLLWIN_TOP", "wxEVT_SCROLLWIN_BOTTOM",
            "wxEVT_SCROLLWIN_LINEUP", "wxEVT_SCROLLWIN_LINEDOWN",
            "wxEVT_SCROLLWIN_PAGEUP", "wxEVT_SCROLLWIN_PAGEDOWN",
            "wxEVT_SCROLLWIN_THUMBTRACK", "wxEVT_SCROLLWIN_THUMBRELEASE"            
        };

        wxLogMessage("OnScrollWin(): %s,  pos = %d", eventNames[evt.GetEventType() - wxEVT_SCROLLWIN_TOP],
            evt.GetPosition());
        evt.Skip();
    }
};

class MyApp : public wxApp
{
public:         
    bool OnInit()
    {
        (new MyFrame())->Show();               
        return true;
    }   
}; wxIMPLEMENT_APP(MyApp);
However, wxScrollWinEvent does not seem that useful here though, as it appears it gets generated only when the mouse was used for scrolling, not for scrolling caused by the keyboard (arrows, PgDn/PgUp...).

james28909
Knows some wx things
Knows some wx things
Posts: 39
Joined: Mon Jul 01, 2019 8:27 pm

Re: wxgrid scroll events do not work on ubuntu?

Post by james28909 » Wed Jul 31, 2019 1:54 pm

the scroll events work fine on win32. but in ubuntu/linux the scroll events are not firing. here is how i have set it up, and like i said it works fine on windows, but i am testing for cross compatibility. should i be using connect or bind for linux/ubuntu?

Code: Select all


#thought this was ubuntu/linux events but does not work

   EVT_SCROLL_LINEUP( $grid, sub { log_scroll_event( $_[1], 'is grid 1 up', $grid, $grid2, $grid3 ) } );
   EVT_SCROLL_LINEDOWN( $grid, sub { log_scroll_event( $_[1], 'is grid 1 down', $grid, $grid2, $grid3 ) } );
   EVT_SCROLL_LINEUP( $grid2, sub { log_scroll_event( $_[1], 'is grid 2 up', $grid, $grid2, $grid3 ) } );
   EVT_SCROLL_LINEDOWN( $grid2, sub { log_scroll_event( $_[1], 'is grid 2 down', $grid, $grid2, $grid3 ) } );
 
   
   
#works in win32 but not in ubuntu/linux

   EVT_SCROLLWIN_LINEUP( $grid, sub { log_scroll_event( $_[1], 'is grid 1 up', $grid, $grid2, $grid3 ) } );
   EVT_SCROLLWIN_LINEDOWN( $grid, sub { log_scroll_event( $_[1], 'is grid 1 down', $grid, $grid2, $grid3 ) } );
   EVT_SCROLLWIN_LINEUP( $grid2, sub { log_scroll_event( $_[1], 'is grid 2 up', $grid, $grid2, $grid3 ) } );
   EVT_SCROLLWIN_LINEDOWN( $grid2, sub { log_scroll_event( $_[1], 'is grid 2 down', $grid, $grid,2 $grid3 ) } );
 
  
what this code does is forwards scroll up, down, left, right events to other grids to keep them in sync. it works great on win32 but the events do not happen when on linux or ubuntu.

are there other methods i need to be using? ive read wxgrid doc page but could not find any relevant information, or atleast nothing caught my eye. any help would be very much appreciated

also, on a side note, when i try to use $grid->GetCellSize() i get an error:

Code: Select all

Can't locate object method "GetCellSize" via package "Wx::Grid"
do you think this means that GetCellSize is not built into the lib i am using for wxperl? on linux when i run wx-config --version it returns 3.0.4

what im trying to do is when a user left clicks a cell, it expands to a predefined size and adds some information to the cell. i want to be able to get the cell size before i change the cell though... that way i can set it back to its original size when a user clicks a different cell. i can keep track of cell sizes myself but would like to just be able to use a built in method if possible

EDIT: about the scroll events issue... am i going to have to manually calculate and show scrollbars to be able to keep track of them on ubuntu?

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2007
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxgrid scroll events do not work on ubuntu?

Post by PB » Wed Jul 31, 2019 2:49 pm

Did you read my previous post where the difference between wxEVT_SCROLLWIN and wxEVT_SCROLL was explained ?

Why you use in the code you posted different events on MSW (EVT_SCROLLWIN_*, is expected to work with wxGrid) and Linux (EVT_SCROLL_*, is not expected to work with wxGrid)...

james28909
Knows some wx things
Knows some wx things
Posts: 39
Joined: Mon Jul 01, 2019 8:27 pm

Re: wxgrid scroll events do not work on ubuntu?

Post by james28909 » Wed Jul 31, 2019 3:04 pm

no i did not see your post until now. i see that it is not intended to work on linux. thanks for telling me.

how would a person be able to capture scroll events on linux with wxgrid then? thats the problem in the end anyway, i need to be able to sync the grids scrolling on linux. what would be the best path to take to make this happen?

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2007
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxgrid scroll events do not work on ubuntu?

Post by PB » Wed Jul 31, 2019 3:08 pm

james28909 wrote:
Wed Jul 31, 2019 3:04 pm
i see that it is not intended to work on linux.
That is not what I wrote, I suggest reading both my posts again, and paying attention to parts highlighted in red.

james28909
Knows some wx things
Knows some wx things
Posts: 39
Joined: Mon Jul 01, 2019 8:27 pm

Re: wxgrid scroll events do not work on ubuntu?

Post by james28909 » Thu Aug 01, 2019 1:47 pm

@PB you have to excuse me when i say this, but i after reading your comments i am still not sure, because in your example you show me the difference in EVT_SCROLL and EVT_SCROLLWIN. i do appreciate this but the main cause for my concern is... EVT_SCROLLWIN is not working on linux/ubuntu. after reading your comment
"Why you use in the code you posted different events on MSW (EVT_SCROLLWIN_*, is expected to work with wxGrid) and Linux (EVT_SCROLL_*, is not expected to work with wxGrid)..."

if events on msw work with EVT_SCROLLWIN , are they also suppose to work on linux/ubuntu? if yes, then this is where my problem lies. the EVT_SCROLLWIN scroll events are not working for me on LINUX/UBUNTU.

also, since you asked why i was using EVT_SCROLL_ and EVT_SCROLLWIN_ i feel i need to clear the confusion, that should really have never been posted in my code. it was the last thing i tried before coming and posting here. in my code, the EVT_SCROLL_ did not even exist until about 5 mins before i posted this help thread. so do me a favor and lets pretend i did not have the EVT_SCROLL in my code and only have EVT_SCROLLWIN in my example because i fear that has caused a huge misunderstanding on what im trying to accomplish. so lets pretend that "EVT_SCROLL_ code was not even in there in my example, ok?

the problem i am having is EVT_SCROLLWIN_ events are not working under linux/ubuntu.

also, i am not worried about keyboard arrows or any keyboard events (yet) so lets not even worry about that. i want to catch the EVT_SCROLLWIN events in linux. i need to know if the mouse scrolled up or down in linux. in my app, this event updates the scroll position of another wxgrid and is detrimental to the usability of my app. the EVT_SCROLLWIN works fine in windows but EVT_SCROLLWIN is not working for me in linux .

User avatar
doublemax
Moderator
Moderator
Posts: 13872
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxgrid scroll events do not work on ubuntu?

Post by doublemax » Thu Aug 01, 2019 2:58 pm

The "WIN" in "EVT_SCROLLWIN" has nothing to do with Windows (the OS). It refers to the fact that these events are generated by a scrolled WINdow. The EVT_SCROLL events are generated by separate wxScrollBar controls.

EVT_SCROLLWIN events should work under Linux, too. Please show some code, especially event binding / event tables and event handlers.
Use the source, Luke!

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2007
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxgrid scroll events do not work on ubuntu?

Post by PB » Thu Aug 01, 2019 5:10 pm

In the original post, you wrote
james28909 wrote:
Wed Jul 31, 2019 2:48 am
same grid and events work fine on win10 64bit. and the gui itself works fine on ubuntu, but it cannot process EVT_SCROLL_LINEUP and EVT_SCROLL_LINEDOWN. is this possible on anything other than win32?
Writing nothing about wxEVT_SCROLLWIN_* events and you kept referring to the scrollbar events further on. Sorry I could not understand what you asked for....
james28909 wrote:
Thu Aug 01, 2019 1:47 pm
the problem i am having is EVT_SCROLLWIN_ events are not working under linux/ubuntu.
So you are saying that you tried compiling and running the code exactly as I posted it and it does not log any scrolling events on your system (assuming you are able to build a C++ program)? Are you sure there is not something wrong with the wrapper / wxWidgets you use - you also wrote that wxGrid::GetCellSize() was not available there...

I would expect that the same and correct code, particularly using a generic control such as wxGrid, works the same on both Windows and LInux and if not, it is probably a bug...

james28909
Knows some wx things
Knows some wx things
Posts: 39
Joined: Mon Jul 01, 2019 8:27 pm

Re: wxgrid scroll events do not work on ubuntu?

Post by james28909 » Thu Aug 01, 2019 10:29 pm

Code: Select all

EVT_SCROLLWIN_LINEUP( $grid, sub { scroll_event( $_[1], 'grid 1 up', $grid, $grid2 ) } );
EVT_SCROLLWIN_LINEDOWN( $grid, sub { scroll_event( $_[1], 'grid 1 down', $grid, $grid2 ) } );
EVT_SCROLLWIN_LINEUP( $grid2, sub { scroll_event( $_[1], 'grid 2 up', $grid, $grid2 ) } );
EVT_SCROLLWIN_LINEDOWN( $grid2, sub { scroll_event( $_[1], 'grid 2 down', $grid, $grid2 ) } );

sub scroll_event {
    my ( $event, $string, $grid, $grid2 ) = @_;

    if ( $event->GetOrientation == wxSB_VERTICAL and $string eq "grid 1 down" )
    {
        my ( $x, $y ) = $grid2->GetViewStart();
        my $num = $y + 1;
        $grid2->Scroll( 0, $num );
    }
    elsif ( $event->GetOrientation == wxSB_VERTICAL and $string eq "grid 1 up" )
    {
        my ( $x, $y ) = $grid2->GetViewStart();
        my $num = $y - 1;
        $grid2->Scroll( 0, $num );
    }

    $event->Skip;
}
this is a snippet of my code, hopefully it will be enough
this works fine under windows but it does not work for me in linux/ubuntu.

EDIT: please disregard my earlier comment about GetCellSize, i was able to get around this by using CellToRect( x, y );

james28909
Knows some wx things
Knows some wx things
Posts: 39
Joined: Mon Jul 01, 2019 8:27 pm

Re: wxgrid scroll events do not work on ubuntu?

Post by james28909 » Sat Aug 03, 2019 12:03 pm

updated my original post

Post Reply