[Xfce4-commits] <xfce4-notes-plugin:master> Update code to build with GTK+3

Mike Massonnet noreply at xfce.org
Sun Nov 11 16:34:02 CET 2012


Updating branch refs/heads/master
         to 2b666709e374d93e8ef6bd84577a1700aa3e60a0 (commit)
       from de5772612cb466ee1aebc8ff10777721f1f15881 (commit)

commit 2b666709e374d93e8ef6bd84577a1700aa3e60a0
Author: Mike Massonnet <mmassonnet at gmail.com>
Date:   Wed Oct 31 22:58:01 2012 +0100

    Update code to build with GTK+3

 data/vapi/gtk214/gtk+-2.0.vapi |    2 +-
 lib/application.vala           |   27 +++++++++----
 lib/hypertextview.vala         |    6 +-
 lib/icon-button.vala           |   15 ++++++-
 lib/note.vala                  |   28 +++++++++++++-
 lib/window.vala                |   81 +++++++++++++++++++++++++++-------------
 src/main-panel-plugin.vala     |    2 +
 src/main-status-icon.vala      |    8 +++-
 8 files changed, 124 insertions(+), 45 deletions(-)

diff --git a/data/vapi/gtk214/gtk+-2.0.vapi b/data/vapi/gtk214/gtk+-2.0.vapi
index 70034b7..db78073 100644
--- a/data/vapi/gtk214/gtk+-2.0.vapi
+++ b/data/vapi/gtk214/gtk+-2.0.vapi
@@ -5098,7 +5098,7 @@ namespace Gtk {
 		public class unowned GLib.ParamSpec find_style_property (string property_name);
 		public void freeze_child_notify ();
 		public virtual unowned Atk.Object get_accessible ();
-		public void get_allocation (Gtk.Allocation allocation);
+		public void get_allocation (out Gtk.Allocation allocation);
 		public unowned Gtk.Widget get_ancestor (GLib.Type widget_type);
 		public bool get_app_paintable ();
 		public bool get_can_default ();
diff --git a/lib/application.vala b/lib/application.vala
index 3872a6a..9a5e674 100644
--- a/lib/application.vala
+++ b/lib/application.vala
@@ -367,7 +367,7 @@ namespace Xnp {
 					string[] tabs_order = win.get_note_names ();
 					int last_page = win.get_current_page ();
 					int transparency = (int)((1 - win.opacity) * 100);
-					bool visible = (bool)(win.get_flags () & Gtk.WidgetFlags.VISIBLE);
+					bool visible = win.get_visible ();
 
 					keyfile.set_integer (win.name, "PosX", winx);
 					keyfile.set_integer (win.name, "PosY", winy);
@@ -426,19 +426,26 @@ namespace Xnp {
 		 */
 		private void rename_window (Xnp.Window window) {
 			var dialog = new Gtk.Dialog.with_buttons (_("Rename group"), window,
+#if ENABLE_GTK3
+					Gtk.DialogFlags.DESTROY_WITH_PARENT,
+#else
 					Gtk.DialogFlags.DESTROY_WITH_PARENT|Gtk.DialogFlags.NO_SEPARATOR,
+#endif
 					Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK);
+			Gtk.Box content_area = (Gtk.Box)dialog.get_content_area ();
 			dialog.set_default_response (Gtk.ResponseType.OK);
 			dialog.resizable = false;
 			dialog.icon_name = Gtk.STOCK_EDIT;
 			dialog.border_width = 4;
-			dialog.vbox.border_width = 6;
+#if !ENABLE_GTK3
+			content_area.border_width = 6;
+#endif
 
 			var entry = new Gtk.Entry ();
 			entry.text = window.name;
 			entry.activates_default = true;
-			dialog.vbox.add (entry);
-			dialog.vbox.show_all ();
+			content_area.add (entry);
+			content_area.show_all ();
 
 			int res = dialog.run ();
 			dialog.hide ();
@@ -666,7 +673,7 @@ namespace Xnp {
 				if (win.is_active) {
 					active_found = true;
 				}
-				if (!(bool)(win.get_flags () & Gtk.WidgetFlags.VISIBLE)) {
+				if (!win.get_visible ()) {
 					invisible_found = true;
 				}
 				else {
@@ -677,7 +684,7 @@ namespace Xnp {
 			foreach (var win in this.window_list) {
 				// Present visible windows
 				if (!active_found && visible_found) {
-					if ((bool)(win.get_flags () & Gtk.WidgetFlags.VISIBLE)) {
+					if (win.get_visible ()) {
 						win.present ();
 					}
 				}
@@ -699,7 +706,7 @@ namespace Xnp {
 		 */
 		public void open_settings_dialog () {
 			try {
-				Gdk.spawn_command_line_on_screen (Gdk.Screen.get_default (), "xfce4-notes-settings");
+				GLib.Process.spawn_command_line_async ("xfce4-notes-settings");
 			}
 			catch (GLib.Error e) {
 				var error_dialog = new Gtk.MessageDialog (null, Gtk.DialogFlags.DESTROY_WITH_PARENT,
@@ -716,21 +723,23 @@ namespace Xnp {
 		 * Open the about dialog.
 		 */
 		public void open_about_dialog () {
+#if !ENABLE_GTK3
 			Gtk.AboutDialog.set_url_hook ((dialog, uri) => {
 					string command;
 					try {
 						command = "exo-open %s".printf (uri);
-						Gdk.spawn_command_line_on_screen (Gdk.Screen.get_default (), command);
+						GLib.Process.spawn_command_line_async (command);
 						return;
 					} catch (GLib.Error e) {
 					}
 					try {
 						command = "firefox %s".printf (uri);
-						Gdk.spawn_command_line_on_screen (Gdk.Screen.get_default (), command);
+						GLib.Process.spawn_command_line_async (command);
 						return;
 					} catch (GLib.Error e) {
 					}
 				});
+#endif
 
 			string[] authors = {
 					"(c) 2006-2010 Mike Massonnet",
diff --git a/lib/hypertextview.vala b/lib/hypertextview.vala
index c6fb2cb..a1f3038 100644
--- a/lib/hypertextview.vala
+++ b/lib/hypertextview.vala
@@ -115,7 +115,7 @@ namespace Xnp {
 				link = start.get_text (end);
 
 				try {
-					Gdk.spawn_command_line_on_screen (Gdk.Screen.get_default (), "exo-open "+link);
+					GLib.Process.spawn_command_line_async ("exo-open "+link);
 					return false;
 				} catch (Error e) {
 				}
@@ -126,13 +126,13 @@ namespace Xnp {
 					message ("Unable to open link with default handler: %s", e.message);
 				}
 				try {
-					Gdk.spawn_command_line_on_screen (Gdk.Screen.get_default (), "xdg-open "+link);
+					GLib.Process.spawn_command_line_async ("xdg-open "+link);
 					return false;
 				}
 				catch (Error e) {
 				}
 				try {
-					Gdk.spawn_command_line_on_screen (Gdk.Screen.get_default (), "firefox "+link);
+					GLib.Process.spawn_command_line_async ("firefox "+link);
 					return false;
 				}
 				catch (Error e) {
diff --git a/lib/icon-button.vala b/lib/icon-button.vala
index dff687a..4396f11 100644
--- a/lib/icon-button.vala
+++ b/lib/icon-button.vala
@@ -53,13 +53,22 @@ namespace Xnp {
 			warning ("This object doesn't allow packing child widgets.");
 		}
 
+#if ENABLE_GTK3
+		public override bool draw (Cairo.Context cr) {
+#else
 		public override bool expose_event (Gdk.EventExpose event) {
+#endif
+			Gtk.Allocation allocation;
+			get_allocation (out allocation);
+
 			int width = allocation.width - (int)border_width * 2;
 			int height = allocation.height - (int)border_width * 2;
 			int x = allocation.width / 2 - width / 2 + allocation.x;
 			int y = allocation.height / 2 - height / 2 + allocation.y;
 
-			var cr = Gdk.cairo_create(window);
+#if !ENABLE_GTK3
+			var cr = Gdk.cairo_create (get_window ());
+#endif
 			cr.rectangle (x, y, width, height);
 			cr.clip ();
 
@@ -74,13 +83,13 @@ namespace Xnp {
 
 		private bool on_enter_notify_event (Gdk.EventCrossing event) {
 			active = true;
-			window.invalidate_rect (null, false);
+			get_window ().invalidate_rect (null, false);
 			return false;
 		}
 
 		private bool on_leave_notify_event (Gdk.EventCrossing event) {
 			active = false;
-			window.invalidate_rect (null, false);
+			get_window ().invalidate_rect (null, false);
 			return false;
 		}
 
diff --git a/lib/note.vala b/lib/note.vala
index 73fc659..fb6b798 100644
--- a/lib/note.vala
+++ b/lib/note.vala
@@ -77,9 +77,32 @@ namespace Xnp {
 			this.dirty = false;
 		}
 
+#if ENABLE_GTK3
+		public override void get_preferred_width (out int minimum_width, out int natural_width) {
+			var child = this.get_child ();
+			if (child != null && child.get_visible ()) {
+				child.get_preferred_width (out minimum_width, out natural_width);
+			}
+			else {
+				minimum_width = 0;
+				natural_width = 0;
+			}
+		}
+
+		public override void get_preferred_height (out int minimum_height, out int natural_height) {
+			var child = this.get_child ();
+			if (child != null && child.get_visible ()) {
+				child.get_preferred_height (out minimum_height, out natural_height);
+			}
+			else {
+				minimum_height = 0;
+				natural_height = 0;
+			}
+		}
+#else
 		public override void size_request (ref Gtk.Requisition requisition) {
 			Gtk.Requisition child_requisition;
-			if (this.child != null && (bool)(this.child.get_flags () & Gtk.WidgetFlags.VISIBLE)) {
+			if (this.child != null && (this.child.get_visible ())) {
 				this.child.size_request (out child_requisition);
 				requisition = child_requisition;
 			}
@@ -91,10 +114,11 @@ namespace Xnp {
 
 		public override void size_allocate (Gdk.Rectangle allocation) {
 			this.allocation = (Gtk.Allocation)allocation;
-			if (this.child != null && (bool)(this.child.get_flags () & Gtk.WidgetFlags.VISIBLE)) {
+			if (this.child != null && this.child.get_visible ()) {
 				this.child.size_allocate (allocation);
 			}
 		}
+#endif
 
 		/*
 		 * Signal callbacks
diff --git a/lib/window.vala b/lib/window.vala
index dfcd543..35dd08f 100644
--- a/lib/window.vala
+++ b/lib/window.vala
@@ -281,7 +281,9 @@ namespace Xnp {
 			this.notebook.show_border = true;
 			this.notebook.show_tabs = false;
 			this.notebook.tab_pos = Gtk.PositionType.TOP;
+#if !ENABLE_GTK3
 			this.notebook.tab_border = 4;
+#endif
 			this.notebook.scrollable = true;
 			this.notebook.show ();
 			this.content_box.pack_start (this.notebook, true, true, 0);
@@ -374,7 +376,7 @@ namespace Xnp {
 		 * Reset the mouse cursor.
 		 */
 		private bool window_leaved_cb () {
-			window.set_cursor (null);
+			get_window ().set_cursor (null);
 			return true;
 		}
 
@@ -384,10 +386,14 @@ namespace Xnp {
 		 * Update mouse cursor.
 		 */
 		private bool window_motion_cb (Gdk.EventMotion event) {
+			Gtk.Allocation allocation;
+
+			get_allocation (out allocation);
+
 			if (event.x > 4 && event.y > 4
 				&& event.x < allocation.width - 4
 				&& event.y < allocation.height - 4) {
-				window.set_cursor (null);
+				get_window ().set_cursor (null);
 				return false;
 			}
 
@@ -395,27 +401,27 @@ namespace Xnp {
 			if (event.x >= allocation.width - this.CORNER_MARGIN
 				&& event.y >= this.CORNER_MARGIN
 				&& event.y < allocation.height - this.CORNER_MARGIN)
-				window.set_cursor (this.CURSOR_RIGHT);
+				get_window ().set_cursor (this.CURSOR_RIGHT);
 			// Bottom right corner
 			else if (event.x >= allocation.width - this.CORNER_MARGIN
 				&& event.y >= allocation.height - this.CORNER_MARGIN)
-				window.set_cursor (this.CURSOR_BOTTOM_RC);
+				get_window ().set_cursor (this.CURSOR_BOTTOM_RC);
 			// Bottom
 			else if (event.x > this.CORNER_MARGIN
 				&& event.y > allocation.height - this.CORNER_MARGIN
 				&& event.x < allocation.width - this.CORNER_MARGIN)
-				window.set_cursor (this.CURSOR_BOTTOM);
+				get_window ().set_cursor (this.CURSOR_BOTTOM);
 			// Bottom left corner
 			else if (event.x <= this.CORNER_MARGIN
 				&& event.y >= allocation.height - this.CORNER_MARGIN)
-				window.set_cursor (this.CURSOR_BOTTOM_LC);
+				get_window ().set_cursor (this.CURSOR_BOTTOM_LC);
 			// Left
 			else if (event.x <= this.CORNER_MARGIN && event.y >= this.CORNER_MARGIN
 				&& event.y < allocation.height - this.CORNER_MARGIN)
-				window.set_cursor (this.CURSOR_LEFT);
+				get_window ().set_cursor (this.CURSOR_LEFT);
 			// Default
 			else
-				window.set_cursor (null);
+				get_window ().set_cursor (null);
 
 			return true;
 		}
@@ -427,6 +433,10 @@ namespace Xnp {
 		 */
 		private bool window_pressed_cb (Gdk.EventButton event) {
 			Gdk.WindowEdge edge;
+			Gtk.Allocation allocation;
+
+			get_allocation (out allocation);
+
 			if (event.x > 4 && event.y > 4
 				&& event.x < allocation.width - 4
 				&& event.y < allocation.height - 4)
@@ -475,8 +485,7 @@ namespace Xnp {
 				 * of xfwm4 switching the state */
 				this.mi_above.active = (bool)(event.new_window_state & Gdk.WindowState.ABOVE);
 			}
-			if ((bool)(event.changed_mask & Gdk.WindowState.STICKY) &&
-				(bool)(get_flags () & Gtk.WidgetFlags.VISIBLE)) {
+			if ((bool)(event.changed_mask & Gdk.WindowState.STICKY) && get_visible ()) {
 				this.sticky = (bool)((event.new_window_state & Gdk.WindowState.STICKY) != 0);
 			}
 			return false;
@@ -491,7 +500,7 @@ namespace Xnp {
 			if (event.type != Gdk.EventType.BUTTON_PRESS)
 				return false;
 			if (event.button == 1) {
-				this.window.show ();
+				get_window ().show ();
 				int winx, winy, curx, cury;
 				get_position (out winx, out winy);
 				get_pointer (out curx, out cury);
@@ -500,7 +509,7 @@ namespace Xnp {
 				begin_move_drag (1, winx, winy, Gtk.get_current_event_time ());
 			}
 			else if (event.button == 2) {
-				this.window.lower ();
+				get_window ().lower ();
 			}
 			else if (event.button == 3) {
 				this.menu.popup (null, null, null, 0, Gtk.get_current_event_time ());
@@ -615,24 +624,39 @@ namespace Xnp {
 		 * Menu position function for the window menu.
 		 */
 		private void menu_position (Gtk.Menu menu, out int x, out int y, out bool push_in) {
-			int winx, winy, width, height, depth;
+			int winx, winy, width, height;
 			Gtk.Requisition requisition;
-			window.get_geometry (out winx, out winy, out width, out height, out depth);
-			window.get_origin (out x, out y);
+			Gtk.Allocation allocation;
+
+#if ENABLE_GTK3
+			get_window ().get_geometry (out winx, out winy, out width, out height);
+			menu.get_preferred_size (out requisition, null);
+#else
+			get_window ().get_geometry (out winx, out winy, out width, out height, null);
 			menu.size_request (out requisition);
+#endif
+			get_window ().get_origin (out x, out y);
 			push_in = false;
 
-			if (y + content_box.allocation.y + requisition.height > Gdk.Screen.height ()) {
+			content_box.get_allocation (out allocation);
+
+			if (y + allocation.y + requisition.height > Gdk.Screen.height ()) {
 				/* Show menu above */
 				y -= requisition.height;
 			}
 			else {
 				/* Show menu below */
-				y += content_box.allocation.y;
+				y += allocation.y;
 			}
 			if (x + requisition.width > Gdk.Screen.width ()) {
 				/* Adjust menu left */
+#if ENABLE_GTK3
+				int menu_width;
+				menu.get_preferred_width (out menu_width, null);
+				x = x - menu_width + allocation.y;
+#else
 				x = x - menu.requisition.width + content_box.allocation.y;
+#endif
 			}
 		}
 
@@ -795,7 +819,7 @@ namespace Xnp {
 		 */
 		public void get_geometry (out int winx, out int winy, out int width, out int height) {
 			// Window is shaded
-			if (!(bool)(this.content_box.get_flags () & Gtk.WidgetFlags.VISIBLE)) {
+			if (!this.content_box.get_visible ()) {
 				get_size (out this.width, null);
 			}
 			else {
@@ -853,7 +877,7 @@ namespace Xnp {
 		 * Shade the window (roll up) to show only the title bar.
 		 */
 		private void shade () {
-			if ((bool)(this.content_box.get_flags () & Gtk.WidgetFlags.VISIBLE)) {
+			if (this.content_box.get_visible ()) {
 				this.content_box.hide ();
 				get_size (out this.width, out this.height);
 				resize (this.width, 1);
@@ -866,7 +890,7 @@ namespace Xnp {
 		 * Unshade the window (roll down).
 		 */
 		private void unshade () {
-			if (!(bool)(this.content_box.get_flags () & Gtk.WidgetFlags.VISIBLE)) {
+			if (!this.content_box.get_visible ()) {
 				this.content_box.show ();
 				get_size (out this.width, null);
 				resize (this.width, this.height);
@@ -1016,19 +1040,24 @@ namespace Xnp {
 			var note = (Xnp.Note)(this.notebook.get_nth_page (page));
 
 			var dialog = new Gtk.Dialog.with_buttons (_("Rename note"), (Gtk.Window)get_toplevel (),
+#if ENABLE_GTK3
+				Gtk.DialogFlags.MODAL|Gtk.DialogFlags.DESTROY_WITH_PARENT,
+#else
 				Gtk.DialogFlags.MODAL|Gtk.DialogFlags.DESTROY_WITH_PARENT|Gtk.DialogFlags.NO_SEPARATOR,
+#endif
 				Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK);
+			Gtk.Box content_area = (Gtk.Box)dialog.get_content_area ();
 			dialog.set_default_response (Gtk.ResponseType.OK);
 			dialog.resizable = false;
 			dialog.icon_name = Gtk.STOCK_EDIT;
 			dialog.border_width = 4;
-			dialog.vbox.border_width = 6;
+			content_area.border_width = 6;
 
 			var entry = new Gtk.Entry ();
 			entry.text = note.name;
 			entry.activates_default = true;
-			dialog.vbox.add (entry);
-			dialog.vbox.show_all ();
+			content_area.add (entry);
+			content_area.show_all ();
 
 			int res = dialog.run ();
 			dialog.hide ();
@@ -1124,15 +1153,15 @@ namespace Xnp {
 			}
 		}
 
-/*
+/* valac -X '-I..' -X '-DGETTEXT_PACKAGE="xfce4-notes-plugin"' -X '-DPKGDATADIR="../data"' -D ENABLE_GTK3 --pkg=gtk+-3.0 --pkg=libxfce4util-1.0 --pkg=libxfconf-0 --pkg=color --pkg=config --vapidir=.. --vapidir=. window.vala note.vala hypertextview.vala icon-button.vala
 		static int main (string[] args) {
 			Gtk.init (ref args);
-			var sample = new Xnp.Window ("Note");
+			var sample = new Xnp.Window ();
 			sample.show ();
 			Gtk.main ();
 			return 0;
 		}
-*/
+// */
 
 	}
 
diff --git a/src/main-panel-plugin.vala b/src/main-panel-plugin.vala
index a789eff..a4c8642 100644
--- a/src/main-panel-plugin.vala
+++ b/src/main-panel-plugin.vala
@@ -75,6 +75,7 @@ public class NotesPlugin : Xfce.PanelPlugin {
 	 * Set an X selection to listen to for the popup command.
 	 */
 	private bool set_x_selection () {
+#if !ENABLE_GTK3
 		invisible = new Gtk.Invisible ();
 		if (!Xnp.Popup.set_x_selection (invisible)) {
 			return false;
@@ -86,6 +87,7 @@ public class NotesPlugin : Xfce.PanelPlugin {
 			}
 			return false;
 		});
+#endif
 		return true;
 	}
 
diff --git a/src/main-status-icon.vala b/src/main-status-icon.vala
index c9edeb2..06bfd68 100644
--- a/src/main-status-icon.vala
+++ b/src/main-status-icon.vala
@@ -31,7 +31,7 @@ static void build_plugin () {
 	var save_location = Xfce.Resource.save_location (Xfce.ResourceType.CONFIG, "xfce4/xfce4-notes.rc", true);
 	application = new Xnp.Application (save_location);
 	status_icon = new Gtk.StatusIcon.from_icon_name ("xfce4-notes-plugin");
-	status_icon.set_tooltip (_("Notes"));
+	status_icon.set_tooltip_text (_("Notes"));
 	Timeout.add_seconds (60, () => {
 			if (!status_icon.is_embedded ()) {
 				warning ("Status Icon is not embedded");
@@ -83,6 +83,7 @@ static Gtk.Menu build_context_menu () {
 }
 
 static bool set_x_selection () {
+#if !ENABLE_GTK3
 	invisible = new Gtk.Invisible ();
 	if (!Xnp.Popup.set_x_selection (invisible)) {
 		return false;
@@ -94,11 +95,15 @@ static bool set_x_selection () {
 		}
 		return false;
 	});
+#endif
 	return true;
 }
 
 static int main (string[] args) {
 	Gtk.init (ref args);
+#if ENABLE_GTK3
+	// TODO: Gtk.Application
+#else
 	Unique.App app = new Unique.App ("org.xfce.Notes", null);
 	if (app.is_running) {
 		if (app.send_message (Unique.Command.ACTIVATE, null) == Unique.Response.OK) {
@@ -112,6 +117,7 @@ static int main (string[] args) {
 		}
 		return Unique.Response.OK;
 	});
+#endif
 	GLib.Environment.set_application_name (_("Notes"));
 	build_plugin ();
 	Xfce.Autostart. at set ("xfce4-notes-autostart", "xfce4-notes", false);


More information about the Xfce4-commits mailing list