+ // draw the item text
+ Rectangle text_rect = item.LabelRect;
+ // format for the item text
+ StringFormat format = new StringFormat ();
+ format.LineAlignment = StringAlignment.Center;
+ if (control.View == View.LargeIcon)
+ format.Alignment = StringAlignment.Center;
+ else
+ format.Alignment = StringAlignment.Near;
+
+ if (!control.LabelWrap)
+ format.FormatFlags = StringFormatFlags.NoWrap;
+
+ if (item.Selected) {
+ if (control.View == View.Details) {
+ if (control.FullRowSelect) {
+ // fill the entire rect excluding the checkbox
+ Rectangle full_rect = item.EntireRect;
+ full_rect.Location = item.LabelRect.Location;
+ dc.FillRectangle (this.ResPool.GetSolidBrush
+ (this.ColorHilight), full_rect);
+ }
+ else {
+ Size text_size = Size.Ceiling (dc.MeasureString (item.Text,
+ item.Font));
+ text_rect.Width = text_size.Width;
+ dc.FillRectangle (this.ResPool.GetSolidBrush
+ (this.ColorHilight), text_rect);
+ }
+ }
+ else {
+ /*Size text_size = Size.Ceiling (dc.MeasureString (item.Text,
+ item.Font));
+ Point loc = text_rect.Location;
+ loc.X += (text_rect.Width - text_size.Width) / 2;
+ text_rect.Width = text_size.Width;*/
+ dc.FillRectangle (this.ResPool.GetSolidBrush (this.ColorHilight),
+ text_rect);
+ }
+ }
+ else
+ dc.FillRectangle (ResPool.GetSolidBrush (item.BackColor), text_rect);
+
+ if (item.Text != null && item.Text.Length > 0) {
+ if (item.Selected)
+ dc.DrawString (item.Text, item.Font, this.ResPool.GetSolidBrush
+ (this.ColorHilightText), text_rect, format);
+ else
+ dc.DrawString (item.Text, item.Font, this.ResPool.GetSolidBrush
+ (item.ForeColor), text_rect, format);
+ }
+
+ if (control.View == View.Details && control.Columns.Count > 0) {
+ // draw subitems for details view
+ ListViewItem.ListViewSubItemCollection subItems = item.SubItems;
+ int count = (control.Columns.Count < subItems.Count ?
+ control.Columns.Count : subItems.Count);
+
+ if (count > 0) {
+ ColumnHeader col;
+ ListViewItem.ListViewSubItem subItem;
+ Rectangle sub_item_rect = item.LabelRect;
+
+ // set the format for subitems
+ format.FormatFlags = StringFormatFlags.NoWrap;
+ format.Alignment = StringAlignment.Near;
+
+ // 0th subitem is the item already drawn
+ for (int index = 1; index < count; index++) {
+ subItem = subItems [index];
+ col = control.Columns [index];
+ sub_item_rect.X = col.Rect.Left;
+ sub_item_rect.Width = col.Wd;
+
+ SolidBrush sub_item_back_br = null;
+ SolidBrush sub_item_fore_br = null;
+ Font sub_item_font = null;
+
+ if (item.UseItemStyleForSubItems) {
+ sub_item_back_br = this.ResPool.GetSolidBrush
+ (item.BackColor);
+ sub_item_fore_br = this.ResPool.GetSolidBrush
+ (item.ForeColor);
+ sub_item_font = item.Font;
+ }
+ else {
+ sub_item_back_br = this.ResPool.GetSolidBrush
+ (subItem.BackColor);
+ sub_item_fore_br = this.ResPool.GetSolidBrush
+ (subItem.ForeColor);
+ sub_item_font = subItem.Font;
+ }
+
+ // In case of fullrowselect, background is filled
+ // for the entire rect above
+ if (item.Selected && control.FullRowSelect) {
+ if (subItem.Text != null && subItem.Text.Length > 0)
+ dc.DrawString (subItem.Text, sub_item_font,
+ this.ResPool.GetSolidBrush
+ (this.ColorHilightText),
+ sub_item_rect, format);
+ }
+ else {
+ dc.FillRectangle (sub_item_back_br, sub_item_rect);
+ if (subItem.Text != null && subItem.Text.Length > 0)
+ dc.DrawString (subItem.Text, sub_item_font,
+ sub_item_fore_br,
+ sub_item_rect, format);
+ }
+ sub_item_rect.X += col.Wd;
+ }
+ }
+ }
+ }
+
+ // Sizing
+ public override Size ListViewCheckBoxSize {
+ get { return new Size (16, 16); }
+ }
+
+ public override int ListViewColumnHeaderHeight {
+ get { return 16; }
+ }
+
+ public override int ListViewDefaultColumnWidth {
+ get { return 60; }
+ }
+
+ public override int ListViewVerticalSpacing {
+ get { return 22; }
+ }
+
+ public override int ListViewEmptyColumnWidth {
+ get { return 10; }
+ }
+
+ public override int ListViewHorizontalSpacing {
+ get { return 10; }
+ }
+
+ public override Size ListViewDefaultSize {
+ get { return new Size (121, 97); }
+ }
+ #endregion // ListView
+
+ #region Menus
+ public override void CalcItemSize (Graphics dc, MenuAPI.MENUITEM item, int y, int x, bool menuBar)
+ {
+ item.rect.Y = y;
+ item.rect.X = x;
+
+ if (item.item.Visible == false)
+ return;
+
+ if (item.item.Separator == true) {
+ item.rect.Height = SEPARATOR_HEIGHT / 2;
+ item.rect.Width = -1;
+ return;
+ }
+
+ if (item.item.MeasureEventDefined) {
+ MeasureItemEventArgs mi = new MeasureItemEventArgs (dc, item.pos);
+ item.item.PerformMeasureItem (mi);
+ item.rect.Height = mi.ItemHeight;
+ item.rect.Width = mi.ItemWidth;
+ return;
+ } else {
+
+ SizeF size;
+ size = dc.MeasureString (item.item.Text, ThemeEngine.Current.MenuFont);
+ item.rect.Width = (int) size.Width;
+ item.rect.Height = (int) size.Height;
+
+ if (!menuBar) {
+
+ if (item.item.Shortcut != Shortcut.None && item.item.ShowShortcut) {
+ item.item.XTab = ThemeEngine.Current.MenuCheckSize.Width + MENU_TAB_SPACE + (int) size.Width;
+ size = dc.MeasureString (" " + item.item.GetShortCutText (), ThemeEngine.Current.MenuFont);
+ item.rect.Width += MENU_TAB_SPACE + (int) size.Width;
+ }
+
+ item.rect.Width += 4 + (ThemeEngine.Current.MenuCheckSize.Width * 2);
+ }
+ else {
+ item.rect.Width += MENU_BAR_ITEMS_SPACE;
+ x += item.rect.Width;
+ }
+
+ if (item.rect.Height < ThemeEngine.Current.MenuHeight)
+ item.rect.Height = ThemeEngine.Current.MenuHeight;
+ }
+ }
+
+ // Updates the menu rect and returns the height
+ public override int CalcMenuBarSize (Graphics dc, IntPtr hMenu, int width)
+ {
+ int x = 0;
+ int i = 0;
+ int y = 0;
+ MenuAPI.MENU menu = MenuAPI.GetMenuFromID (hMenu);
+ menu.Height = 0;
+ MenuAPI.MENUITEM item;
+
+ while (i < menu.items.Count) {
+
+ item = (MenuAPI.MENUITEM) menu.items[i];
+ CalcItemSize (dc, item, y, x, true);
+ i = i + 1;
+
+ if (x + item.rect.Width > width) {
+ item.rect.X = 0;
+ y += item.rect.Height;
+ item.rect.Y = y;
+ x = 0;
+ }
+
+ x += item.rect.Width;
+ item.item.MenuBar = true;
+
+ if (y + item.rect.Height > menu.Height)
+ menu.Height = item.rect.Height + y;
+ }
+
+ menu.Width = width;
+ return menu.Height;
+ }
+
+
+ public override void CalcPopupMenuSize (Graphics dc, IntPtr hMenu)
+ {
+ int x = 3;
+ int start = 0;
+ int i, n, y, max;
+
+ MenuAPI.MENU menu = MenuAPI.GetMenuFromID (hMenu);
+ menu.Height = 0;
+
+ while (start < menu.items.Count) {
+ y = 2;
+ max = 0;
+ for (i = start; i < menu.items.Count; i++) {
+ MenuAPI.MENUITEM item = (MenuAPI.MENUITEM) menu.items[i];
+
+ if ((i != start) && (item.item.Break || item.item.BarBreak))
+ break;
+
+ CalcItemSize (dc, item, y, x, false);
+ y += item.rect.Height;
+
+ if (item.rect.Width > max)
+ max = item.rect.Width;
+ }
+
+ // Reemplace the -1 by the menu width (separators)
+ for (n = start; n < i; n++, start++) {
+ MenuAPI.MENUITEM item = (MenuAPI.MENUITEM) menu.items[n];
+ item.rect.Width = max;
+ }
+
+ if (y > menu.Height)
+ menu.Height = y;
+
+ x+= max;
+ }
+
+ menu.Width = x;
+
+ //space for border
+ menu.Width += 2;
+ menu.Height += 2;
+
+ menu.Width += SM_CXBORDER;
+ menu.Height += SM_CYBORDER;
+ }
+
+ // Draws a menu bar in a window
+ public override void DrawMenuBar (Graphics dc, IntPtr hMenu, Rectangle rect)
+ {
+ MenuAPI.MENU menu = MenuAPI.GetMenuFromID (hMenu);
+ Rectangle item_rect;
+
+ if (menu.Height == 0)
+ ThemeEngine.Current.CalcMenuBarSize (dc, hMenu, rect.Width);
+
+ rect.Height = menu.Height;
+ dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (menu.Wnd.BackColor), rect);
+
+ for (int i = 0; i < menu.items.Count; i++) {
+ MenuAPI.MENUITEM it = (MenuAPI.MENUITEM) menu.items[i];
+ item_rect = it.rect;
+ item_rect.X += rect.X;
+ item_rect.Y += rect.Y;
+ it.item.MenuHeight = menu.Height;
+ it.item.PerformDrawItem (new DrawItemEventArgs (dc, ThemeEngine.Current.MenuFont,
+ item_rect, i, it.item.Status));
+
+ }
+ }
+
+ public override void DrawMenuItem (MenuItem item, DrawItemEventArgs e)
+ {
+ StringFormat string_format;
+ Rectangle rect_text = e.Bounds;
+
+ if (item.Visible == false)
+ return;
+
+ if (item.MenuBar) {
+ string_format = string_format_menu_menubar_text;
+ }
+ else {
+ string_format = string_format_menu_text;
+ }
+
+ if (item.Separator == true) {
+ e.Graphics.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonShadow),
+ e.Bounds.X, e.Bounds.Y, e.Bounds.X + e.Bounds.Width, e.Bounds.Y);
+
+ e.Graphics.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonHilight),
+ e.Bounds.X, e.Bounds.Y + 1, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + 1);
+
+ return;
+ }
+
+ if (!item.MenuBar)
+ rect_text.X += ThemeEngine.Current.MenuCheckSize.Width;
+
+ if (item.BarBreak) { /* Draw vertical break bar*/
+ Rectangle rect = e.Bounds;
+ rect.Y++;
+ rect.Width = 3;
+ rect.Height = item.MenuHeight - 6;
+
+ e.Graphics.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonShadow),
+ rect.X, rect.Y , rect.X, rect.Y + rect.Height);
+
+ e.Graphics.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonHilight),
+ rect.X + 1, rect.Y , rect.X +1, rect.Y + rect.Height);
+ }
+
+ Color color_text;
+ Color color_back;
+
+ if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
+ color_text = ThemeEngine.Current.ColorHilightText;
+ color_back = ThemeEngine.Current.ColorHilight;
+ }
+ else {
+ color_text = ThemeEngine.Current.ColorMenuText;
+ color_back = ThemeEngine.Current.ColorMenu;
+ }
+
+ /* Draw background */
+ Rectangle rect_back = e.Bounds;
+ rect_back.X++;
+ rect_back.Width -=2;
+ e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (color_back), rect_back);
+
+ if (item.Enabled) {
+ e.Graphics.DrawString (item.Text, e.Font,
+ ThemeEngine.Current.ResPool.GetSolidBrush (color_text),
+ rect_text, string_format);
+
+ if (!item.MenuBar && item.Shortcut != Shortcut.None && item.ShowShortcut) {
+ string str = item.GetShortCutText ();
+ Rectangle rect = rect_text;
+ rect.X = item.XTab;
+ rect.Width -= item.XTab;
+
+ e.Graphics.DrawString (str, e.Font, ThemeEngine.Current.ResPool.GetSolidBrush (color_text),
+ rect, string_format_menu_shortcut);
+ }
+ }
+ else {
+ ControlPaint.DrawStringDisabled (e.Graphics, item.Text, e.Font,
+ Color.Black, rect_text, string_format);
+ }
+
+ /* Draw arrow */
+ if (item.MenuBar == false && item.IsPopup) {
+
+ int cx = ThemeEngine.Current.MenuCheckSize.Width;
+ int cy = ThemeEngine.Current.MenuCheckSize.Height;
+ Bitmap bmp = new Bitmap (cx, cy);
+ Graphics gr = Graphics.FromImage (bmp);
+ Rectangle rect_arrow = new Rectangle (0, 0, cx, cy);
+ ControlPaint.DrawMenuGlyph (gr, rect_arrow, MenuGlyph.Arrow);
+ bmp.MakeTransparent ();
+
+ if (item.Enabled) {
+ e.Graphics.DrawImage (bmp, e.Bounds.X + e.Bounds.Width - cx,
+ e.Bounds.Y + ((e.Bounds.Height - cy) /2));
+ } else {
+ ControlPaint.DrawImageDisabled (e.Graphics, bmp, e.Bounds.X + e.Bounds.Width - cx,
+ e.Bounds.Y + ((e.Bounds.Height - cy) /2), color_back);
+ }
+
+ gr.Dispose ();
+ bmp.Dispose ();
+ }
+
+ /* Draw checked or radio */
+ if (item.MenuBar == false && item.Checked) {
+
+ Rectangle area = e.Bounds;
+ int cx = ThemeEngine.Current.MenuCheckSize.Width;
+ int cy = ThemeEngine.Current.MenuCheckSize.Height;
+ Bitmap bmp = new Bitmap (cx, cy);
+ Graphics gr = Graphics.FromImage (bmp);
+ Rectangle rect_arrow = new Rectangle (0, 0, cx, cy);
+
+ if (item.RadioCheck)
+ ControlPaint.DrawMenuGlyph (gr, rect_arrow, MenuGlyph.Bullet);
+ else
+ ControlPaint.DrawMenuGlyph (gr, rect_arrow, MenuGlyph.Checkmark);
+
+ bmp.MakeTransparent ();
+ e.Graphics.DrawImage (bmp, area.X, e.Bounds.Y + ((e.Bounds.Height - cy) / 2));
+
+ gr.Dispose ();
+ bmp.Dispose ();
+ }
+ }
+
+ public override void DrawPopupMenu (Graphics dc, IntPtr hMenu, Rectangle cliparea, Rectangle rect)
+ {
+ MenuAPI.MENU menu = MenuAPI.GetMenuFromID (hMenu);
+
+ dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush
+ (ThemeEngine.Current.ColorMenu), cliparea);
+
+ /* Draw menu borders */
+ dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorHilightText),
+ rect.X, rect.Y, rect.X + rect.Width, rect.Y);
+
+ dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorHilightText),
+ rect.X, rect.Y, rect.X, rect.Y + rect.Height);