I found the bottleneck, please tell me how to fix it...



Hello again.


For http://segusoland.sourceforge.net , I have found the bottleneck in
my ListBox widget. I have a ListBox, implemented with


ScrolledWindow
  Viewport
     VBox
        EventBox
        ...


There are about 2000 EventBoxes in the VBox. Each time an EventBox is
clicked, it hides itself. The problem is that hiding the Nth EventBox
sends on_size_allocate messages to EventBoxes {N+1, ..., 2000}. Yes,
not to all of them: just to the EventBoxes that follow the hidden one!

So if I click the _last_ EventBox, the update is instantaneous. If I
click the _first_ one, it is slow as hell.

I need a way to avoid sending those on_size_allocate messages to the
EventBoxes at all. The messages are useless anyway, because no resize
is taking place! This must be possible... please help me!

I tried putting gtk_widget_freeze_child_notify in position (*) and
gtk_widget_thaw_child_notify in position (**), but it won't
work... (and I couldn't find good info about what these functions
really do).

A test program follows.


#include <gtkmm.h>
#include <iostream>
using namespace Gtk;
using namespace std;


class MyItem : public EventBox{
public:
        MyItem(int id){
                mMyIdentificationNumber = id;
                
                Label * l = new Label("hello");
                l->show();
                add(*l);

        }
        virtual void on_size_allocate(GtkAllocation* a){
                cout << "on_size_allocate for Item " <<mMyIdentificationNumber <<endl;
                EventBox::on_size_allocate(a);
        }
        
        virtual bool on_button_press_event(GdkEventButton* event){
                // (*)
                cout << "Button pressed. hiding myself." << endl;
                hide();
                EventBox::on_button_press_event(event);
                // (**)
        }

private:
        int mMyIdentificationNumber;
};



int main(int argc, char *argv[])
{
        Gtk::Main main(argc, argv);
        Window lWindow;

        VBox vbox;
        vbox.show();
        lWindow.add(vbox);

        
        ScrolledWindow s;
        s.show();
        vbox.pack_start(s, true, true);
        
        VBox lItemBox;
        lItemBox.show();
        s.add(lItemBox);

        for (int i = 0 ; i<2000 ; i++){
                MyItem * lNewItem = new MyItem(i);
                lNewItem->show();
                lItemBox.pack_start( *lNewItem, false, true);
        }

        main.run(lWindow);
    
        return 0;
}
 






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]