summaryrefslogtreecommitdiff
path: root/src/core/DataView.vala
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2014-07-23 09:06:59 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2014-07-23 09:06:59 +0200
commit4ea2cc3bd4a7d9b1c54a9d33e6a1cf82e7c8c21d (patch)
treed2e54377d14d604356c86862a326f64ae64dadd6 /src/core/DataView.vala
Imported Upstream version 0.18.1upstream/0.18.1
Diffstat (limited to 'src/core/DataView.vala')
-rw-r--r--src/core/DataView.vala132
1 files changed, 132 insertions, 0 deletions
diff --git a/src/core/DataView.vala b/src/core/DataView.vala
new file mode 100644
index 0000000..07cd4fc
--- /dev/null
+++ b/src/core/DataView.vala
@@ -0,0 +1,132 @@
+/* Copyright 2011-2014 Yorba Foundation
+ *
+ * This software is licensed under the GNU Lesser General Public License
+ * (version 2.1 or later). See the COPYING file in this distribution.
+ */
+
+public class DataView : DataObject {
+ private DataSource source;
+ private bool selected = false;
+ private bool visible = true;
+
+ // Indicates that the selection state has changed.
+ public virtual signal void state_changed(bool selected) {
+ }
+
+ // Indicates the visible state has changed.
+ public virtual signal void visibility_changed(bool visible) {
+ }
+
+ // Indicates that the display (what is seen by the user) of the DataView has changed.
+ public virtual signal void view_altered() {
+ }
+
+ // Indicates that the geometry of the DataView has changed (which implies the view has altered,
+ // but only in that the same elements have changed size).
+ public virtual signal void geometry_altered() {
+ }
+
+ public virtual signal void unsubscribed(DataSource source) {
+ }
+
+ public DataView(DataSource source) {
+ this.source = source;
+
+ // subscribe to the DataSource, which sets up signal reflection and gives the DataView
+ // first notification of destruction.
+ source.internal_subscribe(this);
+ }
+
+ ~DataView() {
+#if TRACE_DTORS
+ debug("DTOR: DataView %s", dbg_to_string);
+#endif
+ source.internal_unsubscribe(this);
+ }
+
+ public override string get_name() {
+ return "View of %s".printf(source.get_name());
+ }
+
+ public override string to_string() {
+ return "DataView %s [DataSource %s]".printf(get_name(), source.to_string());
+ }
+
+ public DataSource get_source() {
+ return source;
+ }
+
+ public bool is_selected() {
+ return selected;
+ }
+
+ // This method is only called by ViewCollection.
+ public void internal_set_selected(bool selected) {
+ if (this.selected == selected)
+ return;
+
+ this.selected = selected;
+ state_changed(selected);
+ }
+
+ // This method is only called by ViewCollection. Returns the toggled state.
+ public bool internal_toggle() {
+ selected = !selected;
+ state_changed(selected);
+
+ return selected;
+ }
+
+ public bool is_visible() {
+ return visible;
+ }
+
+ // This method is only called by ViewCollection.
+ public void internal_set_visible(bool visible) {
+ if (this.visible == visible)
+ return;
+
+ this.visible = visible;
+ visibility_changed(visible);
+ }
+
+ protected virtual void notify_view_altered() {
+ // impossible when not visible
+ if (!visible)
+ return;
+
+ ViewCollection vc = get_membership() as ViewCollection;
+ if (vc != null) {
+ if (!vc.are_notifications_frozen())
+ view_altered();
+
+ // notify ViewCollection in any event
+ vc.internal_notify_view_altered(this);
+ } else {
+ view_altered();
+ }
+ }
+
+ protected virtual void notify_geometry_altered() {
+ // impossible when not visible
+ if (!visible)
+ return;
+
+ ViewCollection vc = get_membership() as ViewCollection;
+ if (vc != null) {
+ if (!vc.are_notifications_frozen())
+ geometry_altered();
+
+ // notify ViewCollection in any event
+ vc.internal_notify_geometry_altered(this);
+ } else {
+ geometry_altered();
+ }
+ }
+
+ // This is only called by DataSource
+ public virtual void notify_unsubscribed(DataSource source) {
+ unsubscribed(source);
+ }
+}
+