[Xfce4-commits] <design:master> Initial work on a button cell renderer.
Jannis Pohlmann
noreply at xfce.org
Mon May 30 02:40:01 CEST 2011
Updating branch refs/heads/master
to 41ab8f6d7ac13a6b6f09133fa990506cb1dddeab (commit)
from 207cc374d12b6f7918406aba59374d5f87c23864 (commit)
commit 41ab8f6d7ac13a6b6f09133fa990506cb1dddeab
Author: Jannis Pohlmann <jannis at xfce.org>
Date: Mon May 30 02:38:35 2011 +0200
Initial work on a button cell renderer.
.../treeview-mockup/vala/mockup.vala | 197 +++++++++++++++++--
1 files changed, 176 insertions(+), 21 deletions(-)
diff --git a/thunar/shortcuts-pane/treeview-mockup/vala/mockup.vala b/thunar/shortcuts-pane/treeview-mockup/vala/mockup.vala
index 3046859..201dc9d 100644
--- a/thunar/shortcuts-pane/treeview-mockup/vala/mockup.vala
+++ b/thunar/shortcuts-pane/treeview-mockup/vala/mockup.vala
@@ -25,17 +25,18 @@ using Gtk;
public class Shortcut : GLib.Object {
public string name { get; set; }
public Icon icon { get; set; }
+ public Icon action_icon { get; set; }
+ public bool connected { get; set; }
}
public class DeviceShortcut : Shortcut {
- public bool mounted { get; set; }
-
public DeviceShortcut (string name, string icon_name, bool mounted) {
this.name = name;
this.icon = new ThemedIcon (icon_name);
- this.mounted = mounted;
+ this.action_icon = new ThemedIcon ("media-eject");
+ this.connected = mounted;
}
}
@@ -45,17 +46,17 @@ public class SystemShortcut : Shortcut {
public SystemShortcut (string name, string icon_name) {
this.name = name;
this.icon = new ThemedIcon (icon_name);
+ this.connected = false;
}
}
public class RemoteShortcut : Shortcut {
- public bool connected { get; set; }
-
public RemoteShortcut (string name, string icon_name, bool connected) {
this.name = name;
this.icon = new ThemedIcon (icon_name);
+ this.action_icon = new ThemedIcon ("media-eject");
this.connected = connected;
}
}
@@ -90,7 +91,7 @@ public class ShortcutsModel : GLib.Object, TreeModel {
ICON,
NAME,
CATEGORY,
- ACTION_WIDGET,
+ ACTION_ICON,
SEPARATOR,
SENSITIVE,
HEIGHT,
@@ -101,7 +102,7 @@ public class ShortcutsModel : GLib.Object, TreeModel {
typeof (Icon),
typeof (string),
typeof (Category),
- typeof (Button),
+ typeof (Icon),
typeof (bool),
typeof (bool),
typeof (int),
@@ -115,13 +116,13 @@ public class ShortcutsModel : GLib.Object, TreeModel {
var devices = new Category ("DEVICES");
categories.add (devices);
- var disk = new DeviceShortcut ("File System", "harddrive", true);
+ var disk = new DeviceShortcut ("File System", "harddrive", false);
devices.items.add (disk);
var ipod = new DeviceShortcut ("iPod", "multimedia-player", true);
devices.items.add (ipod);
- var dvd = new DeviceShortcut ("Blank DVD+RW Disc", "media-optical-dvd", false);
+ var dvd = new DeviceShortcut ("Blank DVD+RW Disc", "media-optical-dvd", true);
devices.items.add (dvd);
var separator = new SeparatorCategory ();
@@ -228,6 +229,9 @@ public class ShortcutsModel : GLib.Object, TreeModel {
case Column.CATEGORY:
value = category;
break;
+ case Column.ACTION_ICON:
+ value = Value (ColumnTypes[column]);
+ break;
case Column.SEPARATOR:
bool is_separator = category is SeparatorCategory;
value = is_separator;
@@ -262,6 +266,13 @@ public class ShortcutsModel : GLib.Object, TreeModel {
case Column.CATEGORY:
value = Value (ColumnTypes[Column.CATEGORY]);
break;
+ case Column.ACTION_ICON:
+ if (item.connected) {
+ value = item.action_icon;
+ } else {
+ value = Value (ColumnTypes[column]);
+ }
+ break;
case Column.SEPARATOR:
value = false;
break;
@@ -579,7 +590,7 @@ public class ShortcutRenderer : CellRenderer {
/* compute icon area */
var icon_area = Gdk.Rectangle() {
x = cell_area.x + x,
- y = cell_area.y,
+ y = cell_area.y + (int) (yalign * (cell_area.height - icon_height)),
width = int.min (cell_area.width - x, icon_width),
height = int.min (cell_area.height, icon_height)
};
@@ -590,6 +601,11 @@ public class ShortcutRenderer : CellRenderer {
x += (int) spacing;
}
+ /* compute the text size */
+ int text_width;
+ int text_height;
+ compute_text_size (widget, null, out text_width, out text_height);
+
/* compute text area */
var text_area = Gdk.Rectangle() {
x = cell_area.x + x,
@@ -696,6 +712,135 @@ public class ShortcutRenderer : CellRenderer {
+public class ShortcutActionRenderer : CellRenderer {
+ public Icon icon { get; set; }
+ public int minimum_button_size { get; set; default = 17; }
+
+ public override void get_size (Widget widget,
+ Gdk.Rectangle? cell_area,
+ out int x_offset,
+ out int y_offset,
+ out int width,
+ out int height)
+ {
+ x_offset = 0;
+ y_offset = 0;
+
+ if (icon != null) {
+ width = 2 * (int) xpad + minimum_button_size;
+ height = 2 * (int) ypad + minimum_button_size;
+
+ if (cell_area != null) {
+ x_offset = int.max (0, (int) (xalign * (cell_area.width - width)));
+ y_offset = int.max (0, (int) (yalign * (cell_area.height - height)));
+ }
+ } else {
+ width = 0;
+ height = 0;
+ }
+ }
+
+ public override void render (Gdk.Window window,
+ Widget widget,
+ Gdk.Rectangle background_area,
+ Gdk.Rectangle cell_area,
+ Gdk.Rectangle expose_area,
+ CellRendererState flags)
+ {
+ if (icon != null) {
+ render_button (window, widget, background_area, cell_area, expose_area, flags);
+ render_icon (window, widget, background_area, cell_area, expose_area, flags);
+ }
+ }
+
+ public void render_button (Gdk.Window window,
+ Widget widget,
+ Gdk.Rectangle background_area,
+ Gdk.Rectangle cell_area,
+ Gdk.Rectangle expose_area,
+ CellRendererState flags)
+ {
+ int x, y, width, height;
+ get_size (widget, cell_area, out x, out y, out width, out height);
+
+ StateType state = StateType.NORMAL;
+ ShadowType shadow = ShadowType.NONE;
+
+ if ((flags & CellRendererState.PRELIT) != 0) {
+ state = StateType.PRELIGHT;
+ shadow = ShadowType.ETCHED_OUT;
+ }
+
+ if (shadow != ShadowType.NONE) {
+ Gtk.paint_box (widget.style, window, state, shadow, cell_area, widget, "button",
+ cell_area.x + x + (int) xpad,
+ cell_area.y + y + (int) ypad,
+ minimum_button_size,
+ minimum_button_size);
+ }
+ }
+
+ public void render_icon (Gdk.Window window,
+ Widget widget,
+ Gdk.Rectangle background_area,
+ Gdk.Rectangle cell_area,
+ Gdk.Rectangle expose_area,
+ CellRendererState flags)
+ {
+ Gdk.Pixbuf pixbuf = null;
+
+ /* load the icon */
+ if (icon is ThemedIcon) {
+ var icon_theme = IconTheme.get_default ();
+ var icon_info = icon_theme.lookup_by_gicon (icon, IconSize.MENU, IconLookupFlags.USE_BUILTIN);
+ if (icon_info != null) {
+ try {
+ pixbuf = icon_info.load_icon ();
+ } catch (Error e) {
+ }
+ }
+ } else if (icon is LoadableIcon) {
+ }
+
+ if (pixbuf == null)
+ return;
+
+ var icon_area = Gdk.Rectangle ();
+ var draw_area = Gdk.Rectangle ();
+
+ /* determine the real icon size */
+ icon_area.width = pixbuf.width;
+ icon_area.height = pixbuf.height;
+
+ /* scale down on demand */
+ if (icon_area.width > cell_area.width || icon_area.height > cell_area.height) {
+ pixbuf = pixbuf.scale_simple (cell_area.width, cell_area.height, Gdk.InterpType.BILINEAR);
+ icon_area.width = pixbuf.width;
+ icon_area.height = pixbuf.height;
+ }
+
+ icon_area.x = cell_area.x + (cell_area.width - icon_area.width) / 2;
+ icon_area.y = cell_area.y + (cell_area.height - icon_area.height) / 2;
+
+ icon_area.x += (int) xpad;
+ icon_area.y += (int) ypad;
+
+ if (expose_area.intersect (icon_area, out draw_area)) {
+ Gdk.draw_pixbuf (window, widget.style.black_gc, pixbuf,
+ draw_area.x - icon_area.x,
+ draw_area.y - icon_area.y,
+ draw_area.x,
+ draw_area.y,
+ draw_area.width,
+ draw_area.height,
+ Gdk.RgbDither.NORMAL,
+ 0, 0);
+ }
+ }
+}
+
+
+
public class ShortcutsView : Frame {
private ShortcutsModel model;
private TreeView view;
@@ -717,6 +862,8 @@ public class ShortcutsView : Frame {
view.set_headers_visible (false);
view.set_level_indentation (-14);
view.set_fixed_height_mode (false);
+ view.set_enable_tree_lines (false);
+ view.set_grid_lines (TreeViewGridLines.NONE);
scrollwin.add (view);
view.show ();
@@ -725,17 +872,25 @@ public class ShortcutsView : Frame {
var shortcut_renderer = new ShortcutRenderer ();
- var column = new TreeViewColumn ();
- column.set_clickable (true);
- column.set_title ("Shortcut");
- column.pack_start (shortcut_renderer, true);
- column.set_attributes (shortcut_renderer,
- "icon", ShortcutsModel.Column.ICON,
- "markup", ShortcutsModel.Column.NAME,
- "sensitive", ShortcutsModel.Column.SENSITIVE,
- "height", ShortcutsModel.Column.HEIGHT,
- "ypad", ShortcutsModel.Column.YPAD);
- view.append_column(column);
+ var action_renderer = new ShortcutActionRenderer ();
+ action_renderer.mode = CellRendererMode.ACTIVATABLE;
+ action_renderer.xpad = 1;
+
+ var shortcut_column = new TreeViewColumn ();
+ shortcut_column.pack_start (shortcut_renderer, true);
+ shortcut_column.set_expand (true);
+ shortcut_column.set_attributes (shortcut_renderer,
+ "icon", ShortcutsModel.Column.ICON,
+ "markup", ShortcutsModel.Column.NAME,
+ "sensitive", ShortcutsModel.Column.SENSITIVE,
+ "height", ShortcutsModel.Column.HEIGHT,
+ "ypad", ShortcutsModel.Column.YPAD);
+ shortcut_column.pack_start (action_renderer, false);
+ shortcut_column.set_attributes (action_renderer,
+ "icon", ShortcutsModel.Column.ACTION_ICON,
+ "sensitive", ShortcutsModel.Column.SENSITIVE,
+ "height", ShortcutsModel.Column.HEIGHT);
+ view.append_column(shortcut_column);
view.expand_all ();
}
More information about the Xfce4-commits
mailing list