Ejemplo n.º 1
0
        private void PlaylistView_DragOver(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(List <ListViewItem>)))
            {
                e.Effect = DragDropEffects.Move;
            }

            int N = PlaylistView.Items.Count;

            if (N == 0)
            {
                DropIndex = 0;
                Application.DoEvents();
                return;
            }

            Point mLoc = PlaylistView.PointToClient(Cursor.Position);

            Rectangle r0 = PlaylistView.Items[0].Bounds;
            Rectangle r1 = PlaylistView.Items[N - 1].Bounds;

            var hitt = PlaylistView.HitTest(mLoc);

            if (hitt.Item == null)
            {
                if (mLoc.Y < r0.Y)
                {
                    PlaylistView.InsertionMark.AppearsAfterItem = false;
                    PlaylistView.InsertionMark.Index            = 0;
                    DropIndex = 0;
                }
                else if (mLoc.Y > r1.Y)
                {
                    PlaylistView.InsertionMark.AppearsAfterItem = true;
                    PlaylistView.InsertionMark.Index            = N - 1;
                    DropIndex = N;
                }
            }
            else
            {
                int idx = hitt.Item.Index;
                PlaylistView.InsertionMark.Index = idx;

                if (mLoc.Y < r0.Y)
                {
                    PlaylistView.InsertionMark.AppearsAfterItem = false;
                    DropIndex = 0;
                }
                else
                {
                    PlaylistView.InsertionMark.AppearsAfterItem = true;
                    DropIndex = idx + 1;
                }
                if (idx == prevItem)
                {
                    return;
                }
            }
            Application.DoEvents();
        }
Ejemplo n.º 2
0
 private void BmpMidiEntryList_MouseDown(object sender, MouseEventArgs e)
 {
     rowIndex = PlaylistView.HitTest(e.X, e.Y).RowIndex;
     if (rowIndex != -1)
     {
         Size dragSize = SystemInformation.DragSize;
         dragBox = new Rectangle(new Point(e.X - (dragSize.Width / 2), e.Y - (dragSize.Height / 2)), dragSize);
     }
     else
     {
         dragBox = Rectangle.Empty;
     }
 }
Ejemplo n.º 3
0
        private void BmpMidiEntryList_DragDrop(object sender, DragEventArgs e)
        {
            Point clientPoint = this.PointToClient(new Point(e.X, e.Y));

            DataGridView.HitTestInfo hit = PlaylistView.HitTest(clientPoint.X, clientPoint.Y);

            // for internal drag-and-drop
            if (actuallyMoving)
            {
                int targetRowIndex = hit.RowIndex - 1;
                if (hit.Type == DataGridViewHitTestType.None)
                {
                    // user has dnd onto empty space, simply move midi to the end of the playlist
                    targetRowIndex = PlaylistView.RowCount - 1;
                }

                BmpMidiEntry oldData = PlaylistView.Rows[initialRowIndexForMovement].DataBoundItem as BmpMidiEntry;
                RemovePlaylistEntry(initialRowIndexForMovement);
                AddPlaylistEntry(oldData.FilePath.FilePath, oldData.Track.Track, targetRowIndex);
                actuallyMoving = false;

                return;
            }

            int dropIndex = 0;

            if (hit.Type == DataGridViewHitTestType.Cell)
            {
                // user has dnd onto an existing cell, move above the hovered midi
                dropIndex = hit.RowIndex - 1;
            }
            else if (hit.Type == DataGridViewHitTestType.None)
            {
                // user has dnd onto empty space, simply add midi to the end of the playlist
                dropIndex = playlistEntries.Count;
            }

            if (e.Effect == DragDropEffects.Move)
            {
                // just in case the user gets fancy with it and dnd's multiple midis
                string[] midiList = (string[])e.Data.GetData(DataFormats.FileDrop, false);
                foreach (string midiFilePath in midiList)
                {
                    string filename = Path.GetFileName(midiFilePath);
                    BmpPlaylistRequestAddEvent addEvent = new BmpPlaylistRequestAddEvent(filename, 0, dropIndex);
                    OnPlaylistManualRequestAdd?.Invoke(this, addEvent);
                }
            }
        }
Ejemplo n.º 4
0
        private void BmpMidiEntryList_DragDrop(object sender, DragEventArgs e)
        {
            Point clientPoint = this.PointToClient(new Point(e.X, e.Y));

            dropIndex = PlaylistView.HitTest(clientPoint.X, clientPoint.Y).RowIndex;

            if (dropIndex >= playlistEntries.Count || dropIndex == -1)
            {
                dropIndex = playlistEntries.Count - 1;
            }

            if (e.Effect == DragDropEffects.Move)
            {
                //DataGridViewRow data = e.Data.GetData(typeof(DataGridViewRow)) as DataGridViewRow;
                var data = e.Data.GetData(typeof(BmpMidiEntry)) as BmpMidiEntry;
                playlistEntries.RemoveAt(rowIndex);
                playlistEntries.Insert(dropIndex, new BmpMidiEntry(data.FilePath.FilePath, data.Track.Track));
                Select(dropIndex);
            }
            playlistBinding         = new BindingList <BmpMidiEntry>(playlistEntries);
            PlaylistView.DataSource = playlistBinding;

            this.SaveSettings();
        }