bsnes/hiro/gtk/widget/list-view-column.cpp

134 lines
4.8 KiB
C++
Raw Normal View History

Update to v094r09 release. byuu says: This will easily be the biggest diff in the history of higan. And not in a good way. * target-higan and target-loki have been blown away completely * nall and ruby massively updated * phoenix replaced with hiro (pretty near a total rewrite) * target-higan restarted using hiro (just a window for now) * all emulation cores updated to compile again * installation changed to not require root privileges (installs locally) For the foreseeable future (maybe even permanently?), the new higan UI will only build under Linux/BSD with GTK+ 2.20+. Probably the most likely route for Windows/OS X will be to try and figure out how to build hiro/GTK on those platforms, as awful as that would be. The other alternative would be to produce new UIs for those platforms ... which would actually be a good opportunity to make something much more user friendly. Being that I just started on this a few hours ago, that means that for at least a few weeks, don't expect to be able to actually play any games. Right now, you can pretty much just compile the binary and that's it. It's quite possible that some nall changes didn't produce compilation errors, but will produce runtime errors. So until the UI can actually load games, we won't know if anything is broken. But we should mostly be okay. It was mostly just trim<1> -> trim changes, moving to Hash::SHA256 (much cleaner), and patching some reckless memory copy functions enough to compile. Progress isn't going to be like it was before: I'm now dividing my time much thinner between studying and other hobbies. My aim this time is not to produce a binary for everyone to play games on. Rather, it's to keep the emulator alive. I want to be able to apply critical patches again. And I would also like the base of the emulator to live on, for use in other emulator frontends that utilize higan.
2015-02-26 10:10:46 +00:00
namespace hiro {
auto pListViewColumn::construct() -> void {
unsigned offset = self().offset();
gtkHeader = gtk_hbox_new(false, 0);
gtkHeaderIcon = gtk_image_new();
gtk_box_pack_start(GTK_BOX(gtkHeader), gtkHeaderIcon, false, false, 0);
gtkHeaderText = gtk_label_new(state().text);
gtk_box_pack_start(GTK_BOX(gtkHeader), gtkHeaderText, true, false, 2);
gtkColumn = gtk_tree_view_column_new();
gtk_tree_view_column_set_sizing(gtkColumn, GTK_TREE_VIEW_COLUMN_FIXED);
gtk_tree_view_column_set_title(gtkColumn, "");
gtk_tree_view_column_set_widget(gtkColumn, gtkHeader);
if(offset == 0) {
gtkCellToggle = gtk_cell_renderer_toggle_new();
gtk_tree_view_column_pack_start(gtkColumn, gtkCellToggle, false);
gtk_tree_view_column_set_attributes(gtkColumn, gtkCellToggle, "active", 0, nullptr);
}
gtkCellIcon = gtk_cell_renderer_pixbuf_new();
gtk_tree_view_column_pack_start(gtkColumn, gtkCellIcon, false);
gtk_tree_view_column_set_attributes(gtkColumn, gtkCellIcon, "pixbuf", 1 + offset * 2 + 0, nullptr);
gtkCellText = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(gtkColumn, gtkCellText, false);
gtk_tree_view_column_set_attributes(gtkColumn, gtkCellText, "text", 1 + offset * 2 + 1, nullptr);
g_signal_connect(G_OBJECT(gtkColumn), "clicked", G_CALLBACK(ListView_headerActivate), (gpointer)_parent());
g_signal_connect(G_OBJECT(gtkCellText), "edited", G_CALLBACK(ListView_edit), (gpointer)_parent());
if(gtkCellToggle) g_signal_connect(G_OBJECT(gtkCellToggle), "toggled", G_CALLBACK(ListView_toggle), (gpointer)_parent());
}
auto pListViewColumn::destruct() -> void {
}
auto pListViewColumn::setActive() -> void {
if(auto parent = _parent()) {
gtk_tree_view_set_search_column(parent->gtkTreeView, 1 + self().offset() * 2 + 1);
}
}
auto pListViewColumn::setBackgroundColor(Color color) -> void {
if(color) {
GdkColor gdkColor = CreateColor(color);
if(gtkCellToggle) g_object_set(G_OBJECT(gtkCellToggle), "cell-background-gdk", &gdkColor, nullptr);
g_object_set(G_OBJECT(gtkCellIcon), "cell-background-gdk", &gdkColor, nullptr);
g_object_set(G_OBJECT(gtkCellText), "cell-background-gdk", &gdkColor, nullptr);
} else {
if(gtkCellToggle) g_object_set(G_OBJECT(gtkCellToggle), "cell-background-set", FALSE, nullptr);
g_object_set(G_OBJECT(gtkCellIcon), "cell-background-set", FALSE, nullptr);
g_object_set(G_OBJECT(gtkCellText), "cell-background-set", FALSE, nullptr);
}
}
auto pListViewColumn::setEditable(bool editable) -> void {
g_object_set(G_OBJECT(gtkCellText), "editable", editable ? TRUE : FALSE, nullptr);
}
auto pListViewColumn::setFont(const string& font) -> void {
pFont::setFont(gtkHeaderText, font);
auto fontDescription = pFont::create(font);
g_object_set(G_OBJECT(gtkCellText), "font-desc", fontDescription, nullptr);
pango_font_description_free(fontDescription);
}
auto pListViewColumn::setForegroundColor(Color color) -> void {
if(color) {
GdkColor gdkColor = CreateColor(color);
g_object_set(G_OBJECT(gtkCellText), "foreground-gdk", &gdkColor, nullptr);
} else {
g_object_set(G_OBJECT(gtkCellText), "foreground-set", FALSE, nullptr);
}
}
auto pListViewColumn::setHorizontalAlignment(double alignment) -> void {
_setAlignment();
}
auto pListViewColumn::setIcon(const image& icon) -> void {
if(icon) {
gtk_image_set_from_pixbuf(GTK_IMAGE(gtkHeaderIcon), CreatePixbuf(icon));
} else {
gtk_image_clear(GTK_IMAGE(gtkHeaderIcon));
}
}
auto pListViewColumn::setResizable(bool resizable) -> void {
gtk_tree_view_column_set_resizable(gtkColumn, resizable);
}
auto pListViewColumn::setSortable(bool sortable) -> void {
gtk_tree_view_column_set_clickable(gtkColumn, sortable);
}
auto pListViewColumn::setText(const string& text) -> void {
gtk_label_set_text(GTK_LABEL(gtkHeaderText), text);
}
auto pListViewColumn::setVerticalAlignment(double alignment) -> void {
_setAlignment();
}
auto pListViewColumn::setVisible(bool visible) -> void {
gtk_tree_view_column_set_visible(gtkColumn, visible);
}
auto pListViewColumn::setWidth(signed width) -> void {
if(auto parent = _parent()) {
parent->resizeColumns();
}
}
auto pListViewColumn::_parent() -> pListView* {
if(auto parent = self().parentListView()) return parent->self();
return nullptr;
}
auto pListViewColumn::_setAlignment() -> void {
gtk_tree_view_column_set_alignment(gtkColumn, state().horizontalAlignment);
gtk_cell_renderer_set_alignment(GTK_CELL_RENDERER(gtkCellText), state().horizontalAlignment, state().verticalAlignment);
//set multi-line text alignment
auto pangoAlignment = PANGO_ALIGN_CENTER;
if(state().horizontalAlignment < 0.333) pangoAlignment = PANGO_ALIGN_LEFT;
if(state().horizontalAlignment > 0.666) pangoAlignment = PANGO_ALIGN_RIGHT;
g_object_set(G_OBJECT(gtkCellText), "alignment", pangoAlignment, nullptr);
}
}