// file basilegsvanchorbut.cc
// by Basile Starynkevitch <basile@starynkevitch.net>
#include <gtkmm.h>
#include <gtksourceviewmm.h>
#include <iostream>
#include <fstream>

class App : public Gtk::Main 
{
  static const int _app_lin = __LINE__ +1;
  Glib::RefPtr<Gsv::LanguageManager> _app_langman;
  Gtk::Window _app_mainwin;
  Gtk::ScrolledWindow _app_scrwin;
  Gsv::View _app_view;
 public:
  App (int &argc, char**argv);
  virtual ~App () {};
};

App::App (int& argc, char**argv) 
  : Gtk::Main(argc, argv) {
  Gsv::init();
  _app_langman = Gsv::LanguageManager::get_default();
  _app_mainwin.add(_app_scrwin);
  _app_mainwin.set_default_size (500,350);
  _app_scrwin.add(_app_view);
  _app_scrwin.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
  Glib::RefPtr<Gsv::Buffer> buf = _app_view.get_source_buffer();
  _app_view.set_show_line_numbers(true);
  _app_view.set_editable(false);
  Glib::RefPtr<Gsv::Language> lang
    // guess our language, it's C++
    = _app_langman->guess_language(__FILE__,std::string());
  buf->set_language(lang);
  // read our own source code
  {
    std::ifstream infil(__FILE__);
    while (!infil.eof()) {
      std::string linestr;
      std::getline(infil,linestr);
      linestr += "\n";
      buf->insert(buf->end(),linestr);
    }
    infil.close();
  }
  Gtk::TextIter it = buf->get_iter_at_line(_app_lin);
  it.forward_chars(10);
  Gtk::Button* butt = new Gtk::Button("*");
  Glib::RefPtr<Gtk::TextChildAnchor> chanch = Gtk::TextChildAnchor::create ();
  buf->insert_child_anchor(it,chanch);
  _app_view.add_child_at_anchor(*butt,chanch);
  butt->show();
  _app_mainwin.show_all();
};


int main(int argc, char**argv)
{
  App myapp(argc, argv);
  myapp.run();
  return 0;
}

/**** for emacs
  ++ Local Variables: ++
  ++ compile-command: "g++ -Wall -O -g $(pkg-config --cflags --libs gtksourceviewmm-3.0  gtkmm-3.0  gtk+-3.0) -o basilegsvanchorbut basilegsvanchorbut.cc" ++
  ++ End: ++
***/
