[Xfce4-commits] <design:master> Play around with events and a different background a bit.

Jannis Pohlmann noreply at xfce.org
Tue May 31 01:04:01 CEST 2011


Updating branch refs/heads/master
         to fc40bdd7d8d5876946024ab44d526f430b64cfc3 (commit)
       from e78c056a3aece2003848e0312853dd77be3e8e9e (commit)

commit fc40bdd7d8d5876946024ab44d526f430b64cfc3
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Tue May 31 01:02:17 2011 +0200

    Play around with events and a different background a bit.

 .../shortcuts-pane/demo-code/custom-view/Makefile  |    2 +-
 .../demo-code/custom-view/shortcut-row.vala        |  120 ++++++++++++++++++++
 .../demo-code/custom-view/shortcuts-view.vala      |   32 ++----
 3 files changed, 133 insertions(+), 21 deletions(-)

diff --git a/thunar/shortcuts-pane/demo-code/custom-view/Makefile b/thunar/shortcuts-pane/demo-code/custom-view/Makefile
index 95cf8b2..f5640cb 100644
--- a/thunar/shortcuts-pane/demo-code/custom-view/Makefile
+++ b/thunar/shortcuts-pane/demo-code/custom-view/Makefile
@@ -1,7 +1,7 @@
 VALA_FLAGS  = 
 VALA_FLAGS += --pkg gtk+-2.0
 
-VALA_FILES  = mockup.vala shortcuts-view.vala
+VALA_FILES  = mockup.vala shortcuts-view.vala shortcut-row.vala
 
 default:
 	valac $(VALA_FLAGS) $(VALA_FILES) && ./mockup
diff --git a/thunar/shortcuts-pane/demo-code/custom-view/shortcut-row.vala b/thunar/shortcuts-pane/demo-code/custom-view/shortcut-row.vala
new file mode 100644
index 0000000..0592155
--- /dev/null
+++ b/thunar/shortcuts-pane/demo-code/custom-view/shortcut-row.vala
@@ -0,0 +1,120 @@
+/* vi:set et ai sw=2 sts=2 ts=2: */
+/*-
+ * Copyright (c) 2011 Jannis Pohlmann <jannis at xfce.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+using Gtk;
+
+
+
+public class ShortcutRow : EventBox {
+  public string title { get; set; }
+  public string icon_name { get; set; }
+  public bool connected { get; set; }
+
+  public ShortcutRow (string title, string icon_name, bool connected) {
+    this.title = title;
+    this.icon_name = icon_name;
+    this.connected = connected;
+
+    set_can_focus (true);
+    set_sensitive (true);
+
+    var align = new Alignment (0.0f, 0.0f, 1.0f, 1.0f);
+    align.set_padding (0, 0, 14, 0);
+    add (align);
+    align.show ();
+
+    var box = new HBox (false, 2);
+    align.add (box);
+    box.show ();
+
+    var icon = new Image.from_icon_name (icon_name, IconSize.MENU);
+    box.pack_start (icon, false, true, 0);
+    icon.show ();
+
+    var label = new Label (title);
+    label.set_alignment (0.0f, 0.5f);
+    box.add (label);
+    label.show ();
+
+    if (connected) {
+      var button_icon = new Image.from_icon_name ("media-eject", IconSize.MENU);
+      button_icon.set_pixel_size (16);
+
+      var button = new Button ();
+      button.set_relief (ReliefStyle.NONE);
+      button.set_image (button_icon);
+      box.pack_start (button, false, true, 0);
+      button.show ();
+    }
+  }
+
+  public override bool expose_event (Gdk.EventExpose event) {
+    Cairo.Context cairo = Gdk.cairo_create (window);
+
+    cairo.rectangle (event.area.x, event.area.y, event.area.width, event.area.height);
+    cairo.clip ();
+
+    StateType state = get_state ();
+
+    cairo.rectangle (event.area.x, event.area.y, event.area.width, event.area.height);
+
+    if (state == StateType.PRELIGHT) {
+      cairo.set_source_rgb (0.9, 0.9, 0.9);
+      cairo.fill_preserve ();
+    }
+
+    if (state == StateType.SELECTED) {
+      cairo.set_source_rgb (0.5, 0.5, 0.5);
+      cairo.fill_preserve ();
+    }
+
+    forall ((child) => {
+      child.expose_event (event);
+    });
+
+    return false;
+  }
+
+  public override bool focus_in_event (Gdk.EventFocus event) {
+    set_state (StateType.SELECTED);
+    return true;
+  }
+
+  public override bool focus_out_event (Gdk.EventFocus event) {
+    set_state (StateType.NORMAL);
+    return true;
+  }
+
+  public override bool button_press_event (Gdk.EventButton event) {
+    return true;
+  }
+
+  public override bool enter_notify_event (Gdk.EventCrossing event) {
+    set_state (StateType.PRELIGHT);
+    return false;
+  }
+
+  public override bool leave_notify_event (Gdk.EventCrossing event) {
+    if (get_state () == StateType.PRELIGHT) {
+      set_state (StateType.NORMAL);
+    }
+    return false;
+  }
+}
diff --git a/thunar/shortcuts-pane/demo-code/custom-view/shortcuts-view.vala b/thunar/shortcuts-pane/demo-code/custom-view/shortcuts-view.vala
index 275dc99..547fe82 100644
--- a/thunar/shortcuts-pane/demo-code/custom-view/shortcuts-view.vala
+++ b/thunar/shortcuts-pane/demo-code/custom-view/shortcuts-view.vala
@@ -37,29 +37,21 @@ public class ShortcutsView : EventBox {
     devices_expander.set_spacing (0);
     box.pack_start(devices_expander, false, true, 0);
 
-    var filesys_align = new Alignment (0.0f, 0.0f, 1.0f, 1.0f);
-    filesys_align.set_padding (0, 0, 14, 0);
-    devices_expander.add (filesys_align);
-    filesys_align.show ();
+    var devices_box = new VBox (false, 0);
+    devices_expander.add (devices_box);
+    devices_box.show ();
 
-    var filesys_box = new HBox (false, 2);
-    filesys_align.add (filesys_box);
-    filesys_box.show ();
+    var filesys = new ShortcutRow ("File System", "harddrive", false);
+    devices_box.pack_start (filesys, false, true, 0);
+    filesys.show ();
 
-    var filesys_icon = new Image.from_icon_name ("harddrive", IconSize.MENU);
-    filesys_box.pack_start (filesys_icon, false, true, 0);
-    filesys_icon.show ();
+    var ipod = new ShortcutRow ("iPod", "multimedia-player", true);
+    devices_box.pack_start (ipod, false, true, 0);
+    ipod.show ();
 
-    var filesys_label = new Label ("File System");
-    filesys_label.set_alignment (0.0f, 0.5f);
-    filesys_box.add (filesys_label);
-    filesys_label.show ();
-
-    var filesys_button = new Button ();
-    filesys_button.set_relief (ReliefStyle.NONE);
-    filesys_button.set_image (new Image.from_icon_name ("media-eject", IconSize.MENU));
-    filesys_box.pack_start (filesys_button, false, true, 0);
-    filesys_button.show ();
+    var dvdrw = new ShortcutRow ("Blank DVD+RW Disc", "media-optical-dvd", true);
+    devices_box.pack_start (dvdrw, false, true, 0);
+    dvdrw.show ();
 
     var places_expander = new Expander ("<span size='medium' weight='bold' color='#353535'>PLACES</span>");
     places_expander.set_use_markup (true);



More information about the Xfce4-commits mailing list