Re: gtkmm 3.0.



I think it would be quite nice to add a function to Gtk::Builder which returns a Glib::RefPtr<> for top-level-widgets. Maybe thinking of returning a weak-pointer for derived widgets would also makes sense, so there is no need for C-Pointers (and ifs everywhere)

Gtk::RefPtr<Gtk::Window> main_window = builder->get_widget_toplevel("MainWindow"); Gtk::WeakPtr<Gtk::Button> close_button = builder->get_widget_derived("CloseButton");

Even better for Users would be an auto-ptr-approach like

Gtk::Ptr<Gtk::Window> main_window = builder->get_widget("MainWindow");
Gtk::Ptr<Gtk::Button> close_button = builder->get_widget("CloseButton");

This Pointer could check if the widget is managed by it's parent or if it needs to be destroyed after leaving scope.


These pointers would fit perfectly in other ideas in this thread before and are much easier to use than this mix of C-Ptrs, Members, Glib::RefPtr's and invisible childs...

For example think of this:

Gtk::Ptr<MyWindow> wnd = builder->get_widget("MainWindow"); //automatically call MyWindow-Ctor wnd->get_child("CloseButton")->set_text("New Text!"); //throw if pointer is invalid!

MyWindow::MyWindow()
{
  Gtk::Ptr<Gtk::Button> button = get_child("CloseButton");
  button->set_text("Close me");
}


Building Windows would work similar:

MyWindow::MyWindow()
{
  Gtk::Ptr<Gtk::Button> button = Gtk::Button:create("Text");
//or Gtk::Ptr button = Gtk::Button::create("Text"); ... Im not good at template-programming
    //maybe typedef Gtk::Button::Ptr ?

add(button); //button is now managed, so Gtk::Ptr does NOT destroy Gtk::Button
}


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