I'm recently migrated to Gtk+-4 & Gtkmm-4.0, dued mainly to the height-for-width trouble mentioned one week ago.
The problem is that I don't see the way to verify that height-for-width feature is back again in a treeview cell rows.
If so, I need help to find out the changes that should be implemented in the code attached below to see how the text fits above, in the same cell, when the column size is been reduced.
---- code -----
#include <gtkmm.h>
#include <map>
class MyWindow
:
public Gtk::Window
{
public:
MyWindow();
virtual ~MyWindow();
private:
void fill_treeview();
void wrap_col (Gtk::TreeViewColumn *, Gtk::CellRendererText *);
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");
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))
{
cl_message->connect_property_changed ("width",
sigc::bind (sigc::mem_fun (*this, &MyWindow::wrap_col), cl_message,
dynamic_cast<Gtk::CellRendererText *>(treeview.get_column_cell_renderer (m_col))));
}
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;
}
}
void
MyWindow::wrap_col (
Gtk::TreeViewColumn * _column, Gtk::CellRendererText * _cell_renderer)
{
_cell_renderer->property_wrap_mode() = Pango::WrapMode::WORD;
gint width = _column->get_width();
_cell_renderer->property_wrap_width() = width;
}
MyWindow::~MyWindow()
{
}
int main (int argc, char* argv[])
{
auto app = Gtk::Application::create ("org.gtkmm");
return app->make_window_and_run<MyWindow>(argc, argv);
}
--
David Gasa i Castell
Linux User #488832