My question recalls: https://gitlab.gnome.org/GNOME/gtk/-/issues/12
I wrote a little Gtkmm-4.0 code
#include <gtkmm.h>
#include <map>
class MyWindow
:
public Gtk::Window
{
public:
MyWindow();
virtual ~MyWindow();
private:
void fill_treeview();
std::map<gint, Glib::ustring> messages;
// Gtkmm widgets
Gtk::Box box;
Gtk::TreeView treeview;
Gtk::Separator separator;
Gtk::Button button;
class ModelColumns
:
public Gtk::TreeModel::ColumnRecord
{
public:
ModelColumns()
{
add (id);
add (message);
}
Gtk::TreeModelColumn<gint> id;
Gtk::TreeModelColumn<Glib::ustring> message;
}
model_cols;
Glib::RefPtr<Gtk::ListStore> refListStore;
Gtk::TreeRow row;
};
MyWindow::MyWindow()
:
box (Gtk::Orientation::VERTICAL, 5),
button ("Close"),
messages ({
{1, "Message: one"},
{2, "Message: one two"},
{3, "Message: one two three"},
{4, "Message: one two three four"}
}),
refListStore (Gtk::ListStore::create (model_cols))
{
set_title ("MyWindow");
set_default_size (500, -1);
treeview.set_model (refListStore);
treeview.append_column ("Id.", model_cols.id);
gint m_col =
treeview.append_column ("Message", model_cols.message)-1;
if (Gtk::TreeViewColumn * cl_message = treeview.get_column (m_col))
{
Gtk::CellRendererText * c_message =
dynamic_cast<Gtk::CellRendererText *>(treeview.get_column_cell_renderer (m_col));
c_message->property_wrap_mode() = Pango::WrapMode::WORD;
c_message->property_wrap_width() = cl_message->get_width();
}
treeview.set_vexpand();
treeview.set_margin (10);
button.set_margin (10);
box.append (treeview);
box.append (separator);
box.append (button);
button.signal_clicked().connect (
sigc::mem_fun (*this, &Gtk::Widget::hide));
set_child (box);
fill_treeview();
}
void
MyWindow::fill_treeview()
{
if (!refListStore->children().empty())
refListStore->clear();
for (auto & it : messages)
{
row = *(refListStore->append());
row[model_cols.id] = it.first;
row[model_cols.message] = it.second;
}
}
MyWindow::~MyWindow()
{
}
int main (int argc, char* argv[])
{
auto app = Gtk::Application::create ("org.gtkmm");
return app->make_window_and_run<MyWindow>(argc, argv);
}
getting the following result
My questions is:
Gtk4 has already solved the problem about the trailing extra blank space at the beginning and at the end of cells (when word wrapping)… and therefore, the code is somewhat incomplete ? Or to the contrary, Gtk4 is still working on this…