RE: [gtkmm] textbuffer's signal_erase



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> I think you've got the right
> idea though, once we know how to execute it.
> 

Well, I played around with it and the attached program seems to 
work correctly. 

cheers,
- --
joey yandle                             ___====-_  _-====___
www.divisionbyzero.com            _--~~~#####//      \\#####~~~--_
/jwy/pubkey.asc                _-~##########// (    ) \\##########~-_
                              -############//  :\^^/:  \\############-
                            _~############//   (@::@)   \\############~_
                           ~#############((     \\//     ))#############~
                          -###############\\    (^^)    //###############-
                         -#################\\  / "" \  //#################-
                        -###################\\/      \//###################-
                       _#/:##########/\######(   /\   )######/\##########:\#_
                       :/ :#/\#/\#/\/  \#/\##\  :  :  /##/\#/  \/\#/\#/\#: \:
                       "  :/  V  V  "   V  \#\: :  : :/#/  V   "  V  V  \:  "
                          "   "  "      "   \ : :  : : /   "      "  "   "
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/OyBAdkrvuJEnEGoRAjt3AJ9l59XVQmOl2MZ323vpkubT/tijcgCgqmug
GFOf00bWxzHtgmetlnAGDEs=
=GZcq
-----END PGP SIGNATURE-----
/* -*- mode: C++ c-basic-offset: 4  -*-
 */

#include <gtkmm/main.h>
#include <gtkmm/window.h>
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/textview.h>
#include <gtkmm/box.h>
#include <gtkmm/separator.h>

#include <iostream>

class TBuffer : public Gtk::TextBuffer {
public:
    static Glib::RefPtr<Gtk::TextBuffer> create() {
        return Glib::RefPtr<Gtk::TextBuffer>(new TBuffer());
    }

protected:
    TBuffer() : TextBuffer() {}

    virtual void on_erase(const Gtk::TextBuffer::iterator& i, const Gtk::TextBuffer::iterator& j) {
        std::cout << "on_erase: " << this->get_text(i, j) << std::endl;
        TextBuffer::on_erase(i, j);
    }
};

void on_erase(const Gtk::TextBuffer::iterator& i, const Gtk::TextBuffer::iterator& j, Glib::RefPtr<Gtk::TextBuffer> buf);

int main(int argc, char** argv) {
    Gtk::Main main(&argc, &argv);

    Gtk::Window* window = new Gtk::Window(Gtk::WINDOW_TOPLEVEL);
    Gtk::ScrolledWindow* scrollwindow = Gtk::manage(new Gtk::ScrolledWindow());
    Gtk::TextView* view = Gtk::manage(new Gtk::TextView());

    if(argc > 1) {
        view->set_buffer(TBuffer::create());
    } 
    else {
        view->get_buffer()->signal_erase().connect(SigC::bind(SigC::slot(&on_erase), view->get_buffer()), true);
    }

    scrollwindow->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);

    scrollwindow->add(*view);

    window->add(*scrollwindow);
    window->set_default_size(300, 300);

    window->show_all();

    //view->get_buffer()->signal_erase().connect(SigC::bind(SigC::slot(&on_erase), view->get_buffer()));

    main.run(*window);
    
    return 0;
}
                                             
void on_erase(const Gtk::TextBuffer::iterator& i, 
              const Gtk::TextBuffer::iterator& j, 
              Glib::RefPtr<Gtk::TextBuffer> buf) {
    std::cout << "on_erase: " << buf->get_text(i, j) << std::endl;
}


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