Esempio n. 1
0
        public void CreateDragCursor(DragDropEffects aEffect)
        {
            if (iCursorInfo.Effect != aEffect)
            {
                if (iCursorInfo.Cursor != null)
                {
                    iCursorInfo.Cursor.Dispose();
                    iCursorInfo.Cursor = null;
                    iCursorInfo.Effect = DragDropEffects.None;
                }
            }

            if (SelectedIndices.Count > 0 && iCursorInfo.Cursor == null)
            {
                ListViewKinsky.Item item = iCursorInfo.Item;

                Bitmap image = new Bitmap(item.ListView.Width + 32, item.Bounds.Size.Height + 32, PixelFormat.Format32bppArgb);

                Graphics g = Graphics.FromImage(image);
                item.Draw(g, true);
                switch (aEffect)
                {
                case DragDropEffects.Copy:
                    kCursorCopy.Draw(g, new Rectangle(iCursorInfo.HotSpot.X, iCursorInfo.HotSpot.Y, kCursorCopy.Size.Width, kCursorCopy.Size.Height));
                    break;

                case DragDropEffects.Move:
                    kCursorMove.Draw(g, new Rectangle(iCursorInfo.HotSpot.X, iCursorInfo.HotSpot.Y, kCursorMove.Size.Width, kCursorMove.Size.Height));
                    break;

                default:
                    kCursorNone.Draw(g, new Rectangle(iCursorInfo.HotSpot.X, iCursorInfo.HotSpot.Y, kCursorNone.Size.Width, kCursorNone.Size.Height));
                    break;
                }
                g.Dispose();

                CursorApi.IconInfo iconInfo = new CursorApi.IconInfo();
                iconInfo.fIcon    = false;
                iconInfo.xHotspot = iCursorInfo.HotSpot.X;
                iconInfo.yHotspot = iCursorInfo.HotSpot.Y;
                iconInfo.hbmColor = image.GetHbitmap();
                iconInfo.hbmMask  = image.GetHbitmap();

                IntPtr pIconInfo = Marshal.AllocHGlobal(Marshal.SizeOf(iconInfo));
                Marshal.StructureToPtr(iconInfo, pIconInfo, true);
                IntPtr pIcon = CursorApi.CreateIconIndirect(pIconInfo);

                CursorApi.DestroyIcon(pIconInfo);
                CursorApi.DeleteObject(iconInfo.hbmMask);
                CursorApi.DeleteObject(iconInfo.hbmColor);

                iCursorInfo.Cursor = new Cursor(pIcon);

                iCursorInfo.Effect = aEffect;
            }
        }
Esempio n. 2
0
        private void EventListViewLibrary_ItemDrag(object sender, ItemDragEventArgs e)
        {
            if (SelectedIndices.Count > 0)
            {
                ListViewKinsky.Item item = Items[SelectedIndices[0]] as Item;
                Point mousePosition      = PointToClient(System.Windows.Forms.Control.MousePosition);

                if (iCursorInfo.Cursor != null)
                {
                    iCursorInfo.Cursor.Dispose();
                }
                iCursorInfo.Cursor  = null;
                iCursorInfo.Effect  = DragDropEffects.None;
                iCursorInfo.Item    = item;
                iCursorInfo.HotSpot = new Point(mousePosition.X - item.Bounds.X, mousePosition.Y - item.Bounds.Y);
            }
        }
Esempio n. 3
0
        private void DoSourceListChanged()
        {
            Trace.WriteLine(Trace.kKinskyDesktop, "SourceListChanged");

            IList <ModelSourceReceiver> sources = iSourceList.Sources;

            ListViewSelector.BeginUpdate();

            ListViewSelector.Items.Clear();

            foreach (ModelSourceReceiver s in sources)
            {
                if (iSender != null && s.Source.Device.Udn != iSender.Udn)
                {
                    Widgets.ListViewKinsky.Item  item    = new Widgets.ListViewKinsky.Item();
                    ListViewItem.ListViewSubItem subItem = new ListViewItem.ListViewSubItem();
                    subItem.Name = "Title";
                    subItem.Text = string.Format("{0}:{1}", s.Source.Room.Name, s.Source.FullName);
                    item.SubItems.Add(subItem);
                    //item.Icon = image;
                    //item.IconSelected = image;
                    item.Tag     = s;
                    item.Checked = s.IsPlayingSender(iSender);

                    int index = 0;
                    for (int i = 0; i < ListViewSelector.Items.Count; ++i, ++index)
                    {
                        ListViewItem        testItem = ListViewSelector.Items[i];
                        ModelSourceReceiver source   = testItem.Tag as ModelSourceReceiver;
                        string name = string.Format("{0}:{1}", source.Source.Room.Name, source.Source.FullName);
                        if (name.CompareTo(subItem.Text) > 0)
                        {
                            break;
                        }
                    }

                    ListViewSelector.Items.Insert(index, item);
                }
            }

            ListViewSelector.EndUpdate();
        }
Esempio n. 4
0
        protected override void EventListViewLibrary_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
        {
            TextFormatFlags flags = TextFormatFlags.VerticalCenter | TextFormatFlags.NoPrefix | TextFormatFlags.EndEllipsis;

            // Because of a bug in the underlying Win32 control, the DrawItem event occurs without accompanying DrawSubItem events once per row in the
            // details view when the mouse pointer moves over the row, causing anything painted in a DrawSubItem event handler to be painted over by a
            // custom background drawn in a DrawItem event handler. See the example in the OwnerDraw reference topic for a workaround that invalidates
            // each row when the extra event occurs. An alternative workaround is to put all your custom drawing code in a DrawSubItem event handler
            // and paint the background for the entire item (including subitems) only when the DrawListViewSubItemEventArgs.ColumnIndex value is 0.
            if (e.ColumnIndex == 0)
            {
                e.Graphics.FillRectangle(iBackBrush, e.Bounds);

                if (iIsAlbum && Items.Count > 0)
                {
                    ListViewKinsky.Item item  = Items[0] as ListViewKinsky.Item;
                    musicTrack          track = item.Tag as musicTrack;

                    int iconHeight = (int)(Columns[0].Width * 0.5f);
                    int iconOffset = 5;// (int)((Columns[0].Width - iconHeight) * 0.5f);

                    Image albumArt = item.Icon;
                    if (albumArt != null)
                    {
                        e.Graphics.FillRectangle(iBackBrush, item.Bounds.Left + iconOffset, item.Bounds.Top + iconOffset, iconHeight, iconHeight);
                        try
                        {
                            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                            e.Graphics.DrawImage(albumArt, item.Bounds.Left + iconOffset, item.Bounds.Top + iconOffset, iconHeight, iconHeight);
                        }
                        catch (ArgumentException ex)
                        {
                            Trace.WriteLine(Trace.kKinsky, "ListViewLibrary.EventListViewLibrary_DrawSubItem: " + ex.Message);
                        }
                    }

                    if (track != null)
                    {
                        int x      = item.Bounds.Left + iconOffset + iconHeight + iconOffset;
                        int y      = item.Bounds.Top + iconOffset;
                        int width  = Columns[0].Width + item.Bounds.Left;
                        int height = iFont.Height;

                        e.Graphics.FillRectangle(iBackBrush, new Rectangle(x, y, width - x, height * 4));

                        string album = DidlLiteAdapter.Album(track);
                        if (!string.IsNullOrEmpty(album))
                        {
                            TextRenderer.DrawText(e.Graphics, album, iFont, new Rectangle(x, y, width - x, height), ForeColor, flags);
                            y += height;
                        }

                        string artist = DidlLiteAdapter.AlbumArtist(track);
                        if (!string.IsNullOrEmpty(artist))
                        {
                            TextRenderer.DrawText(e.Graphics, artist, iFont, new Rectangle(x, y, width - x, height), Color.DarkGray, flags);
                            y += height;
                        }

                        string genre = DidlLiteAdapter.Genre(track);
                        if (!string.IsNullOrEmpty(genre))
                        {
                            TextRenderer.DrawText(e.Graphics, genre, iFont, new Rectangle(x, y, width - x, height), Color.DarkGray, flags);
                            y += height;
                        }

                        TextRenderer.DrawText(e.Graphics, DidlLiteAdapter.ReleaseYear(track), iFont, new Rectangle(x, y, width - x, height), Color.DarkGray, flags);
                    }
                }
            }
            //Console.WriteLine("columIndex=" + e.ColumnIndex + ", header=" + e.Header + ", item=" + e.Item + ", itemIndex=" + e.ItemIndex + ", subItem=" + e.SubItem);
            //e.DrawDefault = true;
            //return;

            if (e.ColumnIndex > 0)
            {
                if (e.Item.Selected)
                {
                    e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
                    e.Graphics.FillRectangle(iHighlightBackBrush, e.Bounds);
                }
                else
                {
                    e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
                    e.Graphics.FillRectangle(iBackBrush, e.Bounds);
                }
            }

            ListViewItem.ListViewSubItem subItem = null;
            for (int i = 0; i < e.Item.SubItems.Count; ++i)
            {
                if (e.Item.SubItems[i].Name == e.Header.Name)
                {
                    subItem = e.Item.SubItems[i];
                    break;
                }
            }

            if (subItem != null)
            {
                if (e.Item.Selected)
                {
                    TextRenderer.DrawText(e.Graphics, subItem.Text, iFont, e.Bounds, HighlightForeColour, flags);
                }
                else
                {
                    if (e.Header.Name != "Title")
                    {
                        TextRenderer.DrawText(e.Graphics, subItem.Text, iFont, e.Bounds, ForeColorMuted, flags);
                    }
                    else
                    {
                        TextRenderer.DrawText(e.Graphics, subItem.Text, iFont, e.Bounds, ForeColor, flags);
                    }
                }
            }
        }