I probably meant a static cast but I've had a play around with it and I don't think you need one:
This is really crude, but I think it's the basic idea, i.e. create a widget (in this case a Hbox subclass) that combines the label and close button., then add that as the tab label.
notebook.cc
Code:
#include <gtkmm.h>
#include "closelabel.h"
int main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
Gtk::Window window;
window.set_title("Notebook");
window.set_default_size(600, 400);
Gtk::VBox vbox;
window.add(vbox);
Gtk::Notebook notebook;
Gtk::Label label0("Content Alpha");
CloseLabel tabLabel0("Alpha");
notebook.append_page(label0, tabLabel0);
Gtk::Label label1("Content Beta");
CloseLabel tabLabel1("Beta");
notebook.append_page(label1, tabLabel1);
vbox.pack_start(notebook);
window.show_all();
Gtk::Main::run(window);
}
closelabel.h
Code:
#ifndef CLOSELABEL_H
#define CLOSELABEL_H
#include <gtkmm.h>
class CloseLabel : public Gtk::HBox
{
public:
CloseLabel(const char *text);
protected:
void on_close_button_clicked();
Gtk::Label tab_label;
Gtk::Button close_button;
};
#endif
closelabel.cc
Code:
#include "closelabel.h"
#include <iostream>
CloseLabel::CloseLabel(const char *text)
: tab_label(text), close_button("close")
{
close_button.signal_clicked().connect(
sigc::mem_fun(*this, &CloseLabel::on_close_button_clicked)
);
pack_start(tab_label);
pack_start(close_button);
show_all();
}
void CloseLabel::on_close_button_clicked()
{
std::cout << "on_close_button_clicked" << std::endl;
}
It needs some work. You'd need to keep track of the notebook page in the CloseLabel class so that you know which one to close in the handler. And, obviously, you'd use a nice little little "X" icon as an image rather than the ugly close button.
As you know, my C++ is not brilliant, but I think this is the way forward with these closeable tabs in GTK3.
Bookmarks