private unsafe void CustomDraw(ref Message m) { bool flag = false; bool drawDefault = false; try { int dwItemSpec; Rectangle itemRectOrEmpty; System.Windows.Forms.NativeMethods.NMLVCUSTOMDRAW* lParam = (System.Windows.Forms.NativeMethods.NMLVCUSTOMDRAW*) m.LParam; switch (lParam->nmcd.dwDrawStage) { case 1: if (this.OwnerDraw) { m.Result = (IntPtr) 0x20; } else { m.Result = (IntPtr) 0x22; this.odCacheBackColor = this.BackColor; this.odCacheForeColor = this.ForeColor; this.odCacheFont = this.Font; this.odCacheFontHandle = base.FontHandle; if (lParam->dwItemType == 1) { if (this.odCacheFontHandleWrapper != null) { this.odCacheFontHandleWrapper.Dispose(); } this.odCacheFont = new Font(this.odCacheFont, FontStyle.Bold); this.odCacheFontHandleWrapper = new Control.FontHandleWrapper(this.odCacheFont); this.odCacheFontHandle = this.odCacheFontHandleWrapper.Handle; System.Windows.Forms.SafeNativeMethods.SelectObject(new HandleRef(lParam->nmcd, lParam->nmcd.hdc), new HandleRef(this.odCacheFontHandleWrapper, this.odCacheFontHandleWrapper.Handle)); m.Result = (IntPtr) 2; } } return; case 0x10001: dwItemSpec = (int) lParam->nmcd.dwItemSpec; itemRectOrEmpty = this.GetItemRectOrEmpty(dwItemSpec); if (!base.ClientRectangle.IntersectsWith(itemRectOrEmpty)) { return; } if (this.OwnerDraw) { Graphics graphics = Graphics.FromHdcInternal(lParam->nmcd.hdc); DrawListViewItemEventArgs e = null; try { e = new DrawListViewItemEventArgs(graphics, this.Items[(int) lParam->nmcd.dwItemSpec], itemRectOrEmpty, (int) lParam->nmcd.dwItemSpec, (ListViewItemStates) lParam->nmcd.uItemState); this.OnDrawItem(e); } finally { graphics.Dispose(); } drawDefault = e.DrawDefault; if (this.viewStyle == System.Windows.Forms.View.Details) { m.Result = (IntPtr) 0x20; } else if (!e.DrawDefault) { m.Result = (IntPtr) 4; } if (!e.DrawDefault) { return; } } if ((this.viewStyle == System.Windows.Forms.View.Details) || (this.viewStyle == System.Windows.Forms.View.Tile)) { m.Result = (IntPtr) 0x22; flag = true; } break; case 0x30001: break; default: goto Label_06C1; } dwItemSpec = (int) lParam->nmcd.dwItemSpec; itemRectOrEmpty = this.GetItemRectOrEmpty(dwItemSpec); if (base.ClientRectangle.IntersectsWith(itemRectOrEmpty)) { if (this.OwnerDraw && !drawDefault) { Graphics graphics2 = Graphics.FromHdcInternal(lParam->nmcd.hdc); DrawListViewSubItemEventArgs args2 = null; bool flag3 = true; try { if (lParam->iSubItem < this.Items[dwItemSpec].SubItems.Count) { Rectangle subItemRect = this.GetSubItemRect(dwItemSpec, lParam->iSubItem); if ((lParam->iSubItem == 0) && (this.Items[dwItemSpec].SubItems.Count > 1)) { subItemRect.Width = this.columnHeaders[0].Width; } if (base.ClientRectangle.IntersectsWith(subItemRect)) { args2 = new DrawListViewSubItemEventArgs(graphics2, subItemRect, this.Items[dwItemSpec], this.Items[dwItemSpec].SubItems[lParam->iSubItem], dwItemSpec, lParam->iSubItem, this.columnHeaders[lParam->iSubItem], (ListViewItemStates) lParam->nmcd.uItemState); this.OnDrawSubItem(args2); flag3 = !args2.DrawDefault; } } } finally { graphics2.Dispose(); } if (flag3) { m.Result = (IntPtr) 4; return; } } ListViewItem item = this.Items[(int) lParam->nmcd.dwItemSpec]; if (flag && item.UseItemStyleForSubItems) { m.Result = (IntPtr) 2; } int uItemState = lParam->nmcd.uItemState; if (!this.HideSelection && ((this.GetItemState((int) lParam->nmcd.dwItemSpec) & 2) == 0)) { uItemState &= -2; } int num4 = ((lParam->nmcd.dwDrawStage & 0x20000) != 0) ? lParam->iSubItem : 0; Font font = null; Color empty = Color.Empty; Color backColor = Color.Empty; bool flag4 = false; bool flag5 = false; if ((item != null) && (num4 < item.SubItems.Count)) { flag4 = true; if (((num4 == 0) && ((uItemState & 0x40) != 0)) && this.HotTracking) { flag5 = true; font = new Font(item.SubItems[0].Font, FontStyle.Underline); } else { font = item.SubItems[num4].Font; } if ((num4 > 0) || ((uItemState & 0x47) == 0)) { empty = item.SubItems[num4].ForeColor; backColor = item.SubItems[num4].BackColor; } } Color c = Color.Empty; Color color4 = Color.Empty; if (flag4) { c = empty; color4 = backColor; } bool flag6 = true; if (!base.Enabled) { flag6 = false; } else if (((this.activation == ItemActivation.OneClick) || (this.activation == ItemActivation.TwoClick)) && ((uItemState & 0x47) != 0)) { flag6 = false; } if (flag6) { if (!flag4 || c.IsEmpty) { lParam->clrText = ColorTranslator.ToWin32(this.odCacheForeColor); } else { lParam->clrText = ColorTranslator.ToWin32(c); } if (lParam->clrText == ColorTranslator.ToWin32(SystemColors.HotTrack)) { int num5 = 0; bool flag7 = false; int num6 = 0xff0000; do { int num7 = lParam->clrText & num6; if ((num7 != 0) || (num6 == 0xff)) { int num8 = 0x10 - num5; if (num7 == num6) { num7 = ((num7 >> (num8 & 0x1f)) - 1) << num8; } else { num7 = ((num7 >> (num8 & 0x1f)) + 1) << num8; } lParam->clrText = (lParam->clrText & ~num6) | num7; flag7 = true; } else { num6 = num6 >> 8; num5 += 8; } } while (!flag7); } if (!flag4 || color4.IsEmpty) { lParam->clrTextBk = ColorTranslator.ToWin32(this.odCacheBackColor); } else { lParam->clrTextBk = ColorTranslator.ToWin32(color4); } } if (!flag4 || (font == null)) { if (this.odCacheFont != null) { System.Windows.Forms.SafeNativeMethods.SelectObject(new HandleRef(lParam->nmcd, lParam->nmcd.hdc), new HandleRef(null, this.odCacheFontHandle)); } } else { if (this.odCacheFontHandleWrapper != null) { this.odCacheFontHandleWrapper.Dispose(); } this.odCacheFontHandleWrapper = new Control.FontHandleWrapper(font); System.Windows.Forms.SafeNativeMethods.SelectObject(new HandleRef(lParam->nmcd, lParam->nmcd.hdc), new HandleRef(this.odCacheFontHandleWrapper, this.odCacheFontHandleWrapper.Handle)); } if (!flag) { m.Result = (IntPtr) 2; } if (flag5) { font.Dispose(); } } return; Label_06C1: m.Result = IntPtr.Zero; } catch (Exception) { m.Result = IntPtr.Zero; } }
protected override void Dispose(bool disposing) { if (disposing) { if (this.imageListSmall != null) { this.imageListSmall.Disposed -= new EventHandler(this.DetachImageList); this.imageListSmall = null; } if (this.imageListLarge != null) { this.imageListLarge.Disposed -= new EventHandler(this.DetachImageList); this.imageListLarge = null; } if (this.imageListState != null) { this.imageListState.Disposed -= new EventHandler(this.DetachImageList); this.imageListState = null; } if (this.columnHeaders != null) { for (int i = this.columnHeaders.Length - 1; i >= 0; i--) { this.columnHeaders[i].OwnerListview = null; this.columnHeaders[i].Dispose(); } this.columnHeaders = null; } this.Items.Clear(); if (this.odCacheFontHandleWrapper != null) { this.odCacheFontHandleWrapper.Dispose(); this.odCacheFontHandleWrapper = null; } if (!string.IsNullOrEmpty(this.backgroundImageFileName) || (this.bkImgFileNames != null)) { new FileIOPermission(PermissionState.Unrestricted).Assert(); try { FileInfo info; if (!string.IsNullOrEmpty(this.backgroundImageFileName)) { info = new FileInfo(this.backgroundImageFileName); try { info.Delete(); } catch (IOException) { } this.backgroundImageFileName = string.Empty; } for (int j = 0; j <= this.bkImgFileNamesCount; j++) { info = new FileInfo(this.bkImgFileNames[j]); try { info.Delete(); } catch (IOException) { } } this.bkImgFileNames = null; this.bkImgFileNamesCount = -1; } finally { PermissionSet.RevertAssert(); } } } base.Dispose(disposing); }
protected override void OnFontChanged(EventArgs e) { base.OnFontChanged(e); this.prefHeightCache = -1; base.Height = this.PreferredHeight; if (this.calendarFont == null) { this.calendarFontHandleWrapper = null; this.SetControlCalendarFont(); } }