[f-spot/icon-view-cleanup: 6/7] Introduce BrowseablePointerGridView



commit e7f430fb47c96c628ae4801687d37885cf19e627
Author: Mike Gemünde <mike gemuende de>
Date:   Tue Sep 7 18:39:34 2010 +0200

    Introduce BrowseablePointerGridView
    
    The BrowseablePointerGridView is a view for collections based
    on a BrowseablePointer which only allows to select one photo at once.

 .../FSpot.Widgets/BrowseablePointerGridView.cs     |  146 ++++++++++++++++++++
 src/Clients/MainApp/MainApp.csproj                 |    1 +
 src/Clients/MainApp/Makefile.am                    |    1 +
 3 files changed, 148 insertions(+), 0 deletions(-)
---
diff --git a/src/Clients/MainApp/FSpot.Widgets/BrowseablePointerGridView.cs b/src/Clients/MainApp/FSpot.Widgets/BrowseablePointerGridView.cs
new file mode 100644
index 0000000..0c33d22
--- /dev/null
+++ b/src/Clients/MainApp/FSpot.Widgets/BrowseablePointerGridView.cs
@@ -0,0 +1,146 @@
+/*
+ * BrowseablePointerGridView.cs
+ *
+ * Author(s)
+ *  Mike Gemuende <mike gemuende de>
+ *
+ * This is free software. See COPYING for details.
+ */
+
+using System;
+
+using Gdk;
+using Gtk;
+
+using FSpot.Core;
+
+
+namespace FSpot.Widgets
+{
+    /// <summary>
+    ///    This widget displays a photo collection based on an BrowseablePointer. That means, that
+    ///    only one photo can be selected at once.
+    /// </summary>
+    public class BrowseablePointerGridView : CollectionGridView
+    {
+
+#region Public Properties
+
+        public BrowsablePointer Pointer {
+            get; private set;
+        }
+
+#endregion
+
+#region Constructors
+
+        public BrowseablePointerGridView (IntPtr raw) : base (raw)
+        {
+        }
+
+        public BrowseablePointerGridView (BrowsablePointer pointer)
+            : base (pointer.Collection)
+        {
+            Pointer = pointer;
+
+            Pointer.Changed += (obj, args) => {
+                InvalidateCell (args.PreviousIndex);
+                InvalidateCell (Pointer.Index);
+            };
+
+            AddEvents ((int) EventMask.KeyPressMask
+                     | (int) EventMask.ButtonPressMask);
+
+            CanFocus = true;
+        }
+
+#endregion
+
+#region Drawing Methods
+
+        protected override void DrawPhoto (int cell_num, Rectangle cell_area, Rectangle expose_area, bool selected, bool focussed)
+        {
+            base.DrawPhoto (cell_num, cell_area, expose_area, (Pointer.Index == cell_num), false);
+        }
+
+#endregion
+
+#region Override Widget Events
+
+        protected override bool OnButtonPressEvent (EventButton evnt)
+        {
+            int cell_num = CellAtPosition ((int) evnt.X, (int) evnt.Y);
+
+            GrabFocus ();
+
+            if (cell_num >= 0)
+                Pointer.Index = cell_num;
+
+            return true;
+        }
+
+        protected override bool OnKeyPressEvent (EventKey evnt)
+        {
+            bool shift = ModifierType.ShiftMask == (evnt.State & ModifierType.ShiftMask);
+            bool control = ModifierType.ControlMask == (evnt.State & ModifierType.ControlMask);
+
+            switch (evnt.Key) {
+            case Gdk.Key.Down:
+            case Gdk.Key.J:
+            case Gdk.Key.j:
+                Pointer.Index += VisibleColums;
+                break;
+
+            case Gdk.Key.Left:
+            case Gdk.Key.H:
+            case Gdk.Key.h:
+                if (control && shift)
+                    Pointer.Index -= Pointer.Index % VisibleColums;
+                else
+                    Pointer.MovePrevious ();
+                break;
+
+            case Gdk.Key.Right:
+            case Gdk.Key.L:
+            case Gdk.Key.l:
+                if (control && shift)
+                    Pointer.Index += VisibleColums - (Pointer.Index % VisibleColums) - 1;
+                else
+                    Pointer.MoveNext ();
+                break;
+
+            case Gdk.Key.Up:
+            case Gdk.Key.K:
+            case Gdk.Key.k:
+                Pointer.Index -= VisibleColums;
+                break;
+
+            case Gdk.Key.Page_Up:
+                Pointer.Index -= VisibleColums * VisibleRows;
+                break;
+
+            case Gdk.Key.Page_Down:
+                Pointer.Index += VisibleColums * VisibleRows;
+                break;
+
+            case Gdk.Key.Home:
+                Pointer.MoveFirst ();
+                break;
+
+            case Gdk.Key.End:
+                Pointer.MoveLast ();
+                break;
+
+            default:
+                return false;
+            }
+
+            ScrollTo (Pointer.Index);
+            return true;
+        }
+
+#endregion
+
+    }
+}
+
diff --git a/src/Clients/MainApp/MainApp.csproj b/src/Clients/MainApp/MainApp.csproj
index 15703b7..9b8641b 100644
--- a/src/Clients/MainApp/MainApp.csproj
+++ b/src/Clients/MainApp/MainApp.csproj
@@ -206,6 +206,7 @@
     <Compile Include="FSpot.Widgets\ThumbnailTextCaptionRenderer.cs" />
     <Compile Include="FSpot.Widgets\SelectionCollectionGridView.cs" />
     <Compile Include="FSpot.Widgets\CollectionCellGridView.cs" />
+    <Compile Include="FSpot.Widgets\BrowseablePointerGridView.cs" />
   </ItemGroup>
   <ItemGroup>
     <EmbeddedResource Include="..\..\..\COPYING">
diff --git a/src/Clients/MainApp/Makefile.am b/src/Clients/MainApp/Makefile.am
index 46100fa..8a53311 100644
--- a/src/Clients/MainApp/Makefile.am
+++ b/src/Clients/MainApp/Makefile.am
@@ -87,6 +87,7 @@ SOURCES =  \
 	FSpot.UI.Dialog/SelectionRatioDialog.cs \
 	FSpot.UI.Dialog/TagSelectionDialog.cs \
 	FSpot.UI.Dialog/ThreadProgressDialog.cs \
+	FSpot.Widgets/BrowseablePointerGridView.cs \
 	FSpot.Widgets/CellRendererTextProgress.cs \
 	FSpot.Widgets/CollectionCellGridView.cs \
 	FSpot.Widgets/EditorPage.cs \



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