libgeetk r13 - in trunk: . geetk geetk/gridview geetk/samples



Author: fzipp
Date: Sun Oct 26 19:58:11 2008
New Revision: 13
URL: http://svn.gnome.org/viewvc/libgeetk?rev=13&view=rev

Log:
Added CPaned widget


Added:
   trunk/geetk/gridview/cpaned.vala
   trunk/geetk/samples/cpaneddemo.vala
Modified:
   trunk/README
   trunk/geetk/Makefile.am
   trunk/geetk/samples/Makefile

Modified: trunk/README
==============================================================================
--- trunk/README	(original)
+++ trunk/README	Sun Oct 26 19:58:11 2008
@@ -28,6 +28,12 @@
 * GridView
 
 This is a Vala port of Medsphere's Gtk# GridView widget [6].
+Based on revision 1.
+
+* CPaned
+
+This is a Vala port of Medsphere's Gtk# CPaned widget [7].
+Based on revision 1.
 
 Some issues
 -----------
@@ -43,7 +49,7 @@
 from an overridden signal default handler. So I had to duplicate the actions of
 the base class as a workaround.
 
-Warning messages on the console: This is a known Vala Bug [7].
+Warning messages on the console: This is a known Vala Bug [8].
 
 ApplicationMenuItem is not yet ported.
 
@@ -58,5 +64,6 @@
 [3] http://tirania.org/blog/archive/2007/Aug-30-1.html
 [4] http://anonsvn.mono-project.com/viewcvs/trunk/gtk-sharp-ribbon/
 [5] http://debackerl.wordpress.com/
-[6] http://www.medsphere.org/projects/widgets/wiki/GridView
-[7] http://bugzilla.gnome.org/show_bug.cgi?id=534756#c10
+[6] http://medsphere.org/projects/widgets/wiki/GridView
+[7] http://medsphere.org/projects/widgets/wiki/CPaned
+[8] http://bugzilla.gnome.org/show_bug.cgi?id=534756#c10

Modified: trunk/geetk/Makefile.am
==============================================================================
--- trunk/geetk/Makefile.am	(original)
+++ trunk/geetk/Makefile.am	Sun Oct 26 19:58:11 2008
@@ -16,6 +16,7 @@
 lib_LTLIBRARIES = libgeetk.la
 
 libgeetk_la_VALASOURCES = 						\
+				gridview/cpaned.vala			\
 				gridview/gridview.vala			\
 				ribbon/application-button.vala		\
 				ribbon/application-menu-item.vala	\

Added: trunk/geetk/gridview/cpaned.vala
==============================================================================
--- (empty file)
+++ trunk/geetk/gridview/cpaned.vala	Sun Oct 26 19:58:11 2008
@@ -0,0 +1,170 @@
+/* 
+ * Medsphere.Widgets
+ * Copyright (C) 2007 Medsphere Systems Corporation
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This library 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 Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * CollapsePaned
+ *
+ * CPaned is a helper class for vpaneds with an _expander child
+ **/
+
+/**
+ * XXX: _snap_lock is not being correctly set when the paned is moved using the
+ *      keyboard.
+ * XXX: this code only works when the_expander is paned.Child2. it could be made
+ *      to work for either Child1/Child2 with some added logic to decide whether
+ *      to add/subtract, use min/max, etc.
+ **/
+
+using Gtk;
+using Gdk;
+
+namespace Geetk {
+
+	public class CPaned : GLib.Object {
+
+		public Paned paned { get; construct; }
+
+		private Expander _expander;
+
+		private bool _size_alloc_lock = false;
+		private bool _snap_lock = false;
+
+		protected double stored_pos { private get; private set; default = 0.5; }
+
+		public CPaned (Paned paned) {
+			this.paned = paned;
+		}
+
+		public CPaned.with_position (Paned paned, double initial_pos) {
+			this.paned = paned;
+			this.stored_pos = initial_pos;
+		}
+
+		construct {
+			if (!(this.paned is VPaned) || !(this.paned.child2 is Expander)) {
+				warning ("CPaned: this ain't gonna fly");
+//				return;
+			}
+
+			_expander = this.paned.child2 as Expander;
+
+			paned.size_allocate += on_paned_size_allocated;
+			paned.accept_position += on_paned_accept_position;
+			paned.button_press_event += on_paned_button_press_event;
+			paned.button_release_event += on_paned_button_release_event;
+
+			paned.notify += (s, p) => {
+				switch (p.name) {
+				case "position":
+					on_paned_position_changed (s);
+					break;
+				case "expanded":
+					on_expanded_changed (s);
+					break;
+				}
+			};
+		}
+
+		private void on_paned_size_allocated (Paned p, Rectangle a) {
+			if (_expander.expanded) {
+				_stored_pos =
+					(double) paned.position / (double) paned.allocation.height;
+			}
+
+			if (_size_alloc_lock) {
+				_size_alloc_lock = false;;
+				return;
+			}
+
+			snap ();
+		}
+
+		private bool on_paned_accept_position (Paned p) {
+			snap ();
+			return false;
+		}
+
+//		[ConnectBefore]
+		private bool on_paned_button_press_event (Paned p, EventButton e) {
+			_snap_lock = true;
+			return false;
+		}
+
+//		[ConnectBefore]
+		private bool on_paned_button_release_event (Paned p, EventButton e) {
+			_snap_lock = false;
+			snap ();
+			return false;
+		}
+
+		private void on_paned_position_changed (Paned p) {
+			if (!_snap_lock) {
+				return;
+			}
+
+			_size_alloc_lock = true;
+
+			Requisition req;
+			_expander.child.size_request (req);
+			bool e = paned.position + req.height <
+			         paned.max_position + (_expander.expanded ? req.height : 0);
+
+			if (_expander.expanded != e) {
+				_expander.expanded = e;
+			}
+
+			if (e) {
+				this.stored_pos =
+					(double) paned.position / (double) paned.allocation.height;
+			}
+		}
+
+		private void on_expanded_changed (Paned p) {
+			if (_expander.expanded) {
+				_size_alloc_lock = true;
+				paned.position = (int) (paned.allocation.height * this.stored_pos);
+			} else {
+				Requisition e_req;
+				_expander.size_request (e_req);
+				Requisition ec_req;
+				_expander.child.size_request (ec_req);
+
+				int height = (e_req.height - ec_req.height);
+
+				_expander.set_size_request (-1, (height >= -1) ? height : -1);
+				snap ();
+				_expander.set_size_request (-1, -1);
+			}
+		}
+
+		/**
+		 * OH SNAP
+		 * http://baz.medsphere.com/~brad/Pelican%20Oh%20snap.JPG
+		 **/
+		private void snap () {
+			if (_expander.expanded || _snap_lock) {
+				return;
+			}
+
+			_size_alloc_lock = true;
+			this.paned.position = this.paned.allocation.height;
+		}
+	}
+}
+

Modified: trunk/geetk/samples/Makefile
==============================================================================
--- trunk/geetk/samples/Makefile	(original)
+++ trunk/geetk/samples/Makefile	Sun Oct 26 19:58:11 2008
@@ -1,4 +1,7 @@
-all: gridviewdemo ribbondemo
+all: cpaneddemo gridviewdemo ribbondemo
+
+cpaneddemo:
+	# valac --pkg gtk+-2.0 --pkg geetk-1.0 --pkg gee-1.0 --disable-non-null cpaneddemo.vala -o cpaneddemo
 
 gridviewdemo: gridviewdemo.c
 	gcc gridviewdemo.c `pkg-config gtk+-2.0 --cflags --libs` `pkg-config geetk-1.0 --cflags --libs` -o gridviewdemo
@@ -7,5 +10,6 @@
 	valac --pkg gtk+-2.0 --pkg geetk-1.0 --pkg gee-1.0 --disable-non-null ribbondemo.vala -o ribbondemo
 
 clean:
+	rm -f cpaneddemo
 	rm -f gridviewdemo
 	rm -f ribbondemo

Added: trunk/geetk/samples/cpaneddemo.vala
==============================================================================
--- (empty file)
+++ trunk/geetk/samples/cpaneddemo.vala	Sun Oct 26 19:58:11 2008
@@ -0,0 +1,131 @@
+using Gtk;
+using Geetk;
+
+namespace DemoData {
+
+	public static const string TEXT = "OpenVista is a cost-effective, open, trusted and complete EHR which enhances patient safety, increases clinical and operational efficiency and provides an opportunity to improve quality of care delivery. Healthcare provider organizations are encouraged to access this software and see first hand how our commercialized version of the Veterans Affairs' FOIA VistA can be leveraged outside of the VA to support the goal of higher quality healthcare. We anticipate that an open source approach will assist in revolutionizing healthcare by enabling many more healthcare delivery organizations to successfully adopt such technology for the benefit of their patients and their businesses. Medsphere is focused on developing an open source community centered on Medsphere OpenVistaÂ. We welcome your participation in OpenVista projects. If you have an idea on how to improve quality, enhance functionality, or accelerate innovation in OpenVista we encourage a
 nd welcome your input -- please join our mailing lists.";
+}
+
+public class DemoWindow : Window {
+
+	public DemoWindow (string title) {
+		this.title = title;
+	}
+
+	construct {
+		this.destroy += Gtk.main_quit;
+		resize (640, 480);
+	}
+}
+
+public class CPanedDemo : DemoWindow {
+
+	private const int n_columns = 5;
+
+	private TreeView tree_view;
+
+	private Expander expander;
+	private TextView text_view;
+
+	private CPaned cpaned;
+
+	public CPanedDemo () {
+		base ("CPaned Demo");
+	}
+
+	construct {
+		var vpaned = new VPaned ();
+		add (vpaned);
+
+		var top_scrolled_window = new ScrolledWindow (null, null);
+		vpaned.pack1 (top_scrolled_window, true, false);
+
+		GLib.Type[] type_array = new GLib.Type[n_columns];
+		for (int x = 0; x < n_columns; x++) {
+			type_array[x] = typeof (string);
+		}
+
+		string[] words = DemoData.TEXT.split (" ");
+		var store = new ListStore.newv (n_columns, type_array);
+		TreeIter tree_iter;
+		store.append (out tree_iter);
+
+		for (int x = 0; words[x] != null; x++) {
+			int col = x % n_columns;
+			Value val = Value (typeof (string));
+			val.set_string (words[x]);
+			store.set_value (tree_iter, col, val);
+
+			if (col == n_columns - 1) {
+				store.append (out tree_iter);
+			}
+		}
+
+		tree_view = new TreeView ();
+		top_scrolled_window.add (tree_view);
+
+		for (int x = 0; x < n_columns; x++) {
+			tree_view.append_column (new TreeViewColumn.with_attributes (
+			                               "Column " + x.to_string (),
+			                               new CellRendererText (), "text", x));
+		}
+
+		tree_view.model = store;
+
+		expander = new Expander ("Details");
+		vpaned.pack2 (expander, true, false);
+
+		var align = new Alignment (0.0f, 0.0f, 1.0f, 1.0f);
+		align.left_padding = 12;
+		expander.add (align);
+
+		var bottom_scrolled_window = new ScrolledWindow (null, null);
+		bottom_scrolled_window.shadow_type = ShadowType.ETCHED_IN;
+		align.add (bottom_scrolled_window);
+
+		text_view = new TextView ();
+		text_view.editable = false;
+		bottom_scrolled_window.add (text_view);
+
+		tree_view.get_selection ().changed += on_tree_view_selection_changed;
+
+		cpaned = new CPaned (vpaned);
+	}
+
+	private void on_tree_view_selection_changed () {
+		TreeIter tree_iter;
+		TextBuffer buffer = text_view.buffer;
+
+		string t = "1\n2\n3\n4\n5\n6\n7\n";
+		buffer.set_text (t, (int) t.size ());
+
+//		if (tree_view.get_selection ().get_selected (out tree_iter)) {
+//			buffer.clear ();
+//			TextIter text_iter = buffer.start_iter;
+
+//			for (int x = 0; x < n_columns; x++) {
+//				string value =
+//					tree_view.model.get_value (tree_iter, x) as string;
+//				buffer.insert (ref text_iter,
+//				               "%d: %s\n".printf (x, value));
+//			}
+
+//			expander.expanded = true;
+//		} else {
+//			buffer.text = "";
+//			expander.expanded = false;
+//		}
+	}
+}
+
+static int main (string[] args) {
+	Gtk.init (ref args);
+
+	var demo = new CPanedDemo ();
+
+	demo.show_all ();
+	Gtk.main ();
+
+	return 0;
+}
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]