using FastReport.Design; using FastReport.DevComponents.DotNetBar; using FastReport.Utils; using System; using System.Drawing; using System.Windows.Forms; namespace FastReport.Controls { internal class StyleComboBoxItem : ComboBoxItem { private bool updating; private Report report; public event EventHandler StyleSelected; public new string Style { get { if (ComboBoxEx.Text == Res.Get("Designer,Toolbar,Style,NoStyle")) return ""; return ComboBoxEx.Text; } set { updating = true; if (value == null) value = ""; int i = Items.IndexOf(value); if (i != -1) SelectedIndex = i; else { if (String.IsNullOrEmpty(value)) value = Res.Get("Designer,Toolbar,Style,SelectStyle"); ComboBoxEx.Text = value; } updating = false; } } public Report Report { get { return report; } set { report = value; if (value != null) UpdateItems(); } } private void ComboBox_MeasureItem(object sender, MeasureItemEventArgs e) { e.ItemHeight = ComboBoxEx.LogicalToDevice(32); } private void ComboBox_DrawItem(object sender, DrawItemEventArgs e) { e.DrawBackground(); Graphics g = e.Graphics; if ((e.State & DrawItemState.ComboBoxEdit) > 0) { TextRenderer.DrawText(g, ComboBoxEx.Text, e.Font, e.Bounds.Location, e.ForeColor, e.BackColor); } else if (e.Index >= 0) { string name = (string)Items[e.Index]; float scale = ComboBoxEx.DpiMultiplier(); using (TextObject sample = new TextObject()) { sample.Bounds = new RectangleF((int)(e.Bounds.Left / scale) + 2, (int)(e.Bounds.Top / scale) + 2, (int)(e.Bounds.Width / scale) - 4, (int)(e.Bounds.Height / scale) - 4); sample.Text = name; sample.HorzAlign = HorzAlign.Center; sample.VertAlign = VertAlign.Center; if (report != null) { int index = report.Styles.IndexOf(name); if (index != -1) sample.ApplyStyle(report.Styles[index]); } using (var cache = new GraphicCache()) { sample.Draw(new FRPaintEventArgs(g, scale, scale, cache)); } } } } private void ComboBox_SelectedIndexChanged(object sender, EventArgs e) { if (updating) return; if (StyleSelected != null) StyleSelected(this, EventArgs.Empty); } private void UpdateItems() { Items.Clear(); Items.Add(Res.Get("Designer,Toolbar,Style,NoStyle")); foreach (Style s in report.Styles) { Items.Add(s.Name); } } public void UpdateDpiDependencies(Designer designer) { ComboWidth = designer.LogicalToDevice(110); ItemHeight = designer.LogicalToDevice(14); DropDownWidth = designer.LogicalToDevice(150); DropDownHeight = designer.LogicalToDevice(300); } public StyleComboBoxItem() { ComboBoxEx.DisableInternalDrawing = true; ComboBoxEx.DropDownStyle = ComboBoxStyle.DropDown; ComboBoxEx.DrawMode = DrawMode.OwnerDrawVariable; ItemHeight = 14; ComboWidth = 110; DropDownWidth = 150; DropDownHeight = 300; ComboBoxEx.DrawItem += new DrawItemEventHandler(ComboBox_DrawItem); ComboBoxEx.MeasureItem += new MeasureItemEventHandler(ComboBox_MeasureItem); ComboBoxEx.SelectedIndexChanged += new EventHandler(ComboBox_SelectedIndexChanged); } } }