protected override void OnMouseUp(MouseEventArgs e) { // Detect which column was clicked and handle accordingly const int LVM_FIRST = 0x1000; const int LVM_SUBITEMHITTEST = LVM_FIRST + 57; NativeMethods.LVHITTESTINFO hitInfo = new NativeMethods.LVHITTESTINFO(); hitInfo.pt = new Point(e.X, e.Y); IntPtr pointer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(NativeMethods.LVHITTESTINFO))); Marshal.StructureToPtr(hitInfo, pointer, true); Message message = Message.Create(Handle, LVM_SUBITEMHITTEST, IntPtr.Zero, pointer); DefWndProc(ref message); hitInfo = (NativeMethods.LVHITTESTINFO)Marshal.PtrToStructure( pointer, typeof(NativeMethods.LVHITTESTINFO)); Marshal.FreeHGlobal(pointer); if (hitInfo.iItem >= 0 && hitInfo.iSubItem == 1) { // Flip the load on startup flag PluginListItem item = (PluginListItem)Items[hitInfo.iItem]; item.PluginInfo.IsLoadedAtStartup = !item.PluginInfo.IsLoadedAtStartup; Invalidate(); return; } base.OnMouseUp(e); }
/// <summary> /// Owner drawing listview item. /// </summary> protected void OnDrawItem(DrawItemEventArgs e, PluginListItem item) { e.DrawBackground(); // IsRunnning bitmap const int imageWidth = 16 + 3; if (imageList == null) { imageList = ((PluginDialog)Parent).ImageList; } if (imageList != null) { int imageIndex = item.PluginInfo.IsCurrentlyLoaded ? 0 : 1; imageList.Draw(e.Graphics, e.Bounds.Left + 2, e.Bounds.Top + 1, imageIndex); } // Name Rectangle bounds = Rectangle.FromLTRB(e.Bounds.Left + imageWidth, e.Bounds.Top, e.Bounds.Left + Columns[0].Width, e.Bounds.Bottom); using (Brush brush = new SolidBrush(e.ForeColor)) e.Graphics.DrawString(item.Name, e.Font, brush, bounds); // Check box (Load at startup) bounds = Rectangle.FromLTRB(bounds.Right + 1, bounds.Top, bounds.Right + Columns[1].Width + 1, bounds.Bottom - 1); ButtonState state = item.PluginInfo.IsLoadedAtStartup ? ButtonState.Checked : ButtonState.Normal; ControlPaint.DrawCheckBox(e.Graphics, bounds, state); }
/// <summary> /// Owner drawing listview item. /// </summary> protected void OnDrawItem( DrawItemEventArgs e, PluginListItem item ) { e.DrawBackground(); // IsRunnning bitmap const int imageWidth = 16+3; if(imageList==null) imageList = ((PluginDialog)Parent).ImageList; if(imageList!=null) { int imageIndex = item.PluginInfo.IsCurrentlyLoaded ? 0 : 1; imageList.Draw(e.Graphics, e.Bounds.Left+2, e.Bounds.Top+1, imageIndex); } // Name Rectangle bounds = Rectangle.FromLTRB(e.Bounds.Left+imageWidth, e.Bounds.Top, e.Bounds.Left+Columns[0].Width, e.Bounds.Bottom); using(Brush brush = new SolidBrush(e.ForeColor)) e.Graphics.DrawString(item.Name, e.Font, brush, bounds); // Check box (Load at startup) bounds = Rectangle.FromLTRB(bounds.Right+1, bounds.Top, bounds.Right+Columns[1].Width+1, bounds.Bottom-1); ButtonState state = item.PluginInfo.IsLoadedAtStartup ? ButtonState.Checked : ButtonState.Normal; ControlPaint.DrawCheckBox(e.Graphics, bounds, state); }
/// <summary> /// Fill the list view with currently installed plugins. /// </summary> void AddPluginList() { this.listView.Items.Clear(); foreach (PluginInfo pi in this.compiler.Plugins) { PluginListItem li = new PluginListItem(pi); this.listView.Items.Add(li); } }
/// <summary> /// Unload plugin and display message on failure. /// </summary> internal void PluginUnload(PluginListItem pi) { try { compiler.Unload(pi.PluginInfo); } catch(Exception caught) { MessageBox.Show("The error was:\n\n" + caught.Message, pi.Name + " failed to unload.", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Unload plugin and display message on failure. /// </summary> public void PluginUnload(PluginListItem pi) { try { this.compiler.Unload(pi.PluginInfo); } catch (Exception caught) { MessageBox.Show("The error was:\n\n" + caught.Message, pi.Name + " failed to unload.", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Load plugin and display message on failure. /// </summary> private void PluginLoad(PluginListItem pi) { try { compiler.Load(pi.PluginInfo); } catch (Exception caught) { MessageBox.Show("The error was:\n\n" + caught.Message, pi.Name + " plugin failed to load.", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Updates enabled states of controls to reflect selection. /// </summary> void UpdateUIStates() { bool isItemSelected = this.listView.SelectedItems.Count > 0; this.buttonUninstall.Enabled = isItemSelected; if (!isItemSelected) { this.buttonLoad.Enabled = false; this.buttonUnload.Enabled = false; return; } PluginListItem item = (PluginListItem)this.listView.SelectedItems[0]; this.buttonLoad.Enabled = !item.PluginInfo.IsCurrentlyLoaded; this.buttonUnload.Enabled = item.PluginInfo.IsCurrentlyLoaded; }
private void listView_SelectedIndexChanged(object sender, EventArgs e) { this.description.Text = ""; this.developer.Text = ""; this.webSite.Text = ""; this.UpdateUIStates(); if (this.listView.SelectedItems.Count != 1) { return; } PluginListItem item = (PluginListItem)this.listView.SelectedItems[0]; this.description.Text = item.PluginInfo.Description; this.developer.Text = item.PluginInfo.Developer; this.webSite.Text = item.PluginInfo.WebSite; }
private void listView_SelectedIndexChanged(object sender, System.EventArgs e) { description.Text = ""; developer.Text = ""; webSite.Text = ""; UpdateUIStates(); if (listView.SelectedItems.Count != 1) { return; } PluginListItem item = (PluginListItem)listView.SelectedItems[0]; description.Text = item.PluginInfo.Description; developer.Text = item.PluginInfo.Developer; webSite.Text = item.PluginInfo.WebSite; }
protected override void WndProc(ref Message m) { const int WM_DRAWITEM = 0x002B; const int WM_REFLECT = 0x2000; const int ODS_SELECTED = 0x0001; switch (m.Msg) { case WM_REFLECT | WM_DRAWITEM: { // Get the DRAWITEMSTRUCT from the LParam of the message NativeMethods.DRAWITEMSTRUCT dis = (NativeMethods.DRAWITEMSTRUCT)Marshal.PtrToStructure( m.LParam, typeof(NativeMethods.DRAWITEMSTRUCT)); // Create a rectangle from the RECT struct Rectangle r = new Rectangle(dis.rcItem.left, dis.rcItem.top, dis.rcItem.right - dis.rcItem.left, dis.rcItem.bottom - dis.rcItem.top); // Get the graphics from the hdc field of the DRAWITEMSTRUCT using (Graphics g = Graphics.FromHdc(dis.hdc)) { // Create new DrawItemState in its default state DrawItemState d = DrawItemState.Default; // Set the correct state for drawing if ((dis.itemState & ODS_SELECTED) > 0) { d = DrawItemState.Selected; } // Create the DrawItemEventArgs object PluginListItem item = (PluginListItem)Items[dis.itemID]; DrawItemEventArgs e = new DrawItemEventArgs(g, this.Font, r, dis.itemID, d); OnDrawItem(e, item); // We processed the message m.Result = (IntPtr)1; } break; } default: base.WndProc(ref m); break; } }
/// <summary> /// Fill the list view with currently installed plugins. /// </summary> void AddPluginList() { listView.Items.Clear(); foreach (PluginInfo pi in compiler.Plugins) { PluginListItem li = new PluginListItem(pi); listView.Items.Add(li); } }