src/FingersDance.Views/TimelineView.xaml.cs
author cavaliet
Wed, 07 Oct 2009 17:16:46 +0200
changeset 135 84b3bf5ee3d2
parent 130 192da585bee5
child 136 8b513df1b446
permissions -rw-r--r--
First step of drag and drop annotation from a timeline to an other player
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55
1ec0ef228158 data, viewmodel and view added
cavaliet
parents:
diff changeset
     1
using System;
1ec0ef228158 data, viewmodel and view added
cavaliet
parents:
diff changeset
     2
using System.Collections.Generic;
1ec0ef228158 data, viewmodel and view added
cavaliet
parents:
diff changeset
     3
using System.Linq;
1ec0ef228158 data, viewmodel and view added
cavaliet
parents:
diff changeset
     4
using System.Text;
1ec0ef228158 data, viewmodel and view added
cavaliet
parents:
diff changeset
     5
using System.Windows;
1ec0ef228158 data, viewmodel and view added
cavaliet
parents:
diff changeset
     6
using System.Windows.Controls;
1ec0ef228158 data, viewmodel and view added
cavaliet
parents:
diff changeset
     7
using System.Windows.Data;
1ec0ef228158 data, viewmodel and view added
cavaliet
parents:
diff changeset
     8
using System.Windows.Documents;
1ec0ef228158 data, viewmodel and view added
cavaliet
parents:
diff changeset
     9
using System.Windows.Input;
1ec0ef228158 data, viewmodel and view added
cavaliet
parents:
diff changeset
    10
using System.Windows.Media;
1ec0ef228158 data, viewmodel and view added
cavaliet
parents:
diff changeset
    11
using System.Windows.Media.Imaging;
1ec0ef228158 data, viewmodel and view added
cavaliet
parents:
diff changeset
    12
using System.Windows.Navigation;
1ec0ef228158 data, viewmodel and view added
cavaliet
parents:
diff changeset
    13
using System.Windows.Shapes;
128
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    14
using Microsoft.Surface.Presentation.Controls;
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    15
using Microsoft.Surface.Presentation;
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    16
135
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
    17
using FingersDance.Data;
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
    18
using FingersDance.ViewModels;
128
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    19
using FingersDance.Views;
55
1ec0ef228158 data, viewmodel and view added
cavaliet
parents:
diff changeset
    20
1ec0ef228158 data, viewmodel and view added
cavaliet
parents:
diff changeset
    21
namespace FingersDance.Views
1ec0ef228158 data, viewmodel and view added
cavaliet
parents:
diff changeset
    22
{
1ec0ef228158 data, viewmodel and view added
cavaliet
parents:
diff changeset
    23
    /// <summary>
1ec0ef228158 data, viewmodel and view added
cavaliet
parents:
diff changeset
    24
    /// Interaction logic for TimelineView.xaml
1ec0ef228158 data, viewmodel and view added
cavaliet
parents:
diff changeset
    25
    /// </summary>
1ec0ef228158 data, viewmodel and view added
cavaliet
parents:
diff changeset
    26
    public partial class TimelineView : UserControl
1ec0ef228158 data, viewmodel and view added
cavaliet
parents:
diff changeset
    27
    {
1ec0ef228158 data, viewmodel and view added
cavaliet
parents:
diff changeset
    28
        public TimelineView()
1ec0ef228158 data, viewmodel and view added
cavaliet
parents:
diff changeset
    29
        {
1ec0ef228158 data, viewmodel and view added
cavaliet
parents:
diff changeset
    30
            InitializeComponent();
1ec0ef228158 data, viewmodel and view added
cavaliet
parents:
diff changeset
    31
        }
128
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    32
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    33
        private void listview_PreviewContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    34
        {
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    35
            FrameworkElement findSource = e.OriginalSource as FrameworkElement;
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    36
            SurfaceListBoxItem draggedElement = null;
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    37
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    38
            // Find the touched SurfaceListBoxItem object.
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    39
            while (draggedElement == null && findSource != null)
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    40
            {
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    41
                if ((draggedElement = findSource as SurfaceListBoxItem) == null)
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    42
                {
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    43
                    findSource = VisualTreeHelper.GetParent(findSource) as FrameworkElement;
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    44
                }
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    45
            }
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    46
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    47
            if (draggedElement == null)
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    48
            {
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    49
                return;
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    50
            }
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    51
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    52
            // Create the cursor visual.
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    53
            ContentControl cursorVisual = new ContentControl()
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    54
            {
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    55
                Content = new TimelineAnnotationView()
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    56
                {
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    57
                    DataContext = findSource.DataContext
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    58
                }
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    59
            };
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    60
130
192da585bee5 debug for adding annotations on timeline. Data AnnotationViewModel and TimelineAnnotationView changed to keep annotation TcBegin from visual margin.
cavaliet
parents: 128
diff changeset
    61
            // We apply the current scale to the dragged annotation
192da585bee5 debug for adding annotations on timeline. Data AnnotationViewModel and TimelineAnnotationView changed to keep annotation TcBegin from visual margin.
cavaliet
parents: 128
diff changeset
    62
            ((TimelineAnnotationView)cursorVisual.Content).RenderTransform = this.RenderTransform;
128
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    63
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    64
            // Add a handler. This will enable the application to change the visual cues.
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    65
            //SurfaceDragDrop.AddTargetChangedHandler(cursorVisual, OnTargetChanged);
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    66
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    67
            // Create a list of input devices. Add the contacts that
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    68
            // are currently captured within the dragged element and
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    69
            // the current contact (if it isn't already in the list).
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    70
            List<InputDevice> devices = new List<InputDevice>();
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    71
            devices.Add(e.Contact);
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    72
            foreach (Contact contact in draggedElement.ContactsCapturedWithin)
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    73
            {
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    74
                if (contact != e.Contact)
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    75
                {
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    76
                    devices.Add(contact);
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    77
                }
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    78
            }
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    79
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    80
            // Get the drag source object
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    81
            ItemsControl dragSource = ItemsControl.ItemsControlFromItemContainer(draggedElement);
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    82
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    83
            bool startDragOkay =
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    84
                SurfaceDragDrop.BeginDragDrop(
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    85
                  dragSource,                 // The SurfaceListBox object that the cursor is dragged out from.
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    86
                  draggedElement,             // The SurfaceListBoxItem object that is dragged from the drag source.
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    87
                  cursorVisual,               // The visual element of the cursor.
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    88
                  draggedElement.DataContext, // The data associated with the cursor.
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    89
                  devices,                    // The input devices that start dragging the cursor.
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    90
                  DragDropEffects.Move);      // The allowed drag-and-drop effects of the operation.
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    91
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    92
            // If the drag began successfully, set e.Handled to true. 
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    93
            // Otherwise SurfaceListBoxItem captures the contact 
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    94
            // and causes the drag operation to fail.
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    95
            e.Handled = startDragOkay;
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    96
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    97
        }
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 55
diff changeset
    98
55
1ec0ef228158 data, viewmodel and view added
cavaliet
parents:
diff changeset
    99
    }
1ec0ef228158 data, viewmodel and view added
cavaliet
parents:
diff changeset
   100
}