NSMenuItem CreateItem(object dataItem, int row) { var h = Handler; var item = new NSMenuItem(); var title = h.Widget.ItemTextBinding?.GetValue(dataItem) ?? string.Empty; item.Image = h.Widget.ItemImageBinding?.GetValue(dataItem).ToNS(); if (h.IsEventHandled(DropDown.FormatItemEvent)) { var args = new DropDownFormatEventArgs(dataItem, row, h.Font); h.Callback.OnFormatItem(h.Widget, args); if (args.IsFontSet && args.Font != null) { var attr = new NSMutableAttributedString(title); var font = args.Font.ToNS(); var range = new NSRange(0, attr.Length); attr.AddAttribute(NSStringAttributeKey.Font, font, range); item.AttributedTitle = attr; } else { item.Title = title; } } else { item.Title = title; } return(item); }
protected override void OnDrawItem(swf.DrawItemEventArgs e) { if (e.State.HasFlag(swf.DrawItemState.ComboBoxEdit)) { var bounds = e.Bounds; bounds.Inflate(2, 2); // only show the background color for the drop down, not for each item e.Graphics.FillRectangle(new sd.SolidBrush(BackColor), bounds); } else { e.DrawBackground(); } if (e.Index >= 0) { var item = Items[e.Index]; var bounds = e.Bounds; var etoitem = item as EtoComboBoxItem; var image = etoitem?.Image; if (image != null) { e.Graphics.DrawImage(image.ToSD(new Size(16, 16)), bounds.X, bounds.Y, 16, 16); bounds.X += 18; bounds.Width -= 18; } string text = item?.ToString(); var font = Font; if (FormatItem != null) { var args = new DropDownFormatEventArgs(etoitem.Value, e.Index, font.ToEto()); FormatItem.Invoke(this, args); font = args.Font.ToSD(); } // Determine the forecolor based on whether or not the item is selected swf.TextRenderer.DrawText(e.Graphics, text, font, bounds, ForeColor, swf.TextFormatFlags.Left); } e.DrawFocusRectangle(); }