123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- using System;
- using System.Windows.Forms;
- using System.Drawing;
- using FastReport.Utils;
- using FastReport.Design;
- namespace FastReport.Controls
- {
- internal class ToolStripStyleComboBox : ToolStripComboBox
- {
- private bool updating;
- private Report report;
- public event EventHandler StyleSelected;
- public string Style
- {
- get
- {
- if (ComboBox.Text == Res.Get("Designer,Toolbar,Style,NoStyle"))
- return "";
- return ComboBox.Text;
- }
- set
- {
- updating = true;
- if (value == null)
- value = "";
- int i = ComboBox.Items.IndexOf(value);
- if (i != -1)
- ComboBox.SelectedIndex = i;
- else
- {
- if (String.IsNullOrEmpty(value))
- value = Res.Get("Designer,Toolbar,Style,NoStyle");
- ComboBox.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 = ComboBox.LogicalToDevice(32);
- }
- private void ComboBox_DrawItem(object sender, DrawItemEventArgs e)
- {
- e.DrawBackground();
- Graphics g = e.Graphics;
- if (e.Index >= 0)
- {
- string name = (string)Items[e.Index];
- float scale = ComboBox.DpiMultiplier();
- using (TextObject sample = new TextObject())
- {
- sample.Bounds = new RectangleF(e.Bounds.Left + 2, e.Bounds.Top + 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 (GraphicCache cache = new GraphicCache())
- {
- sample.Draw(new FRPaintEventArgs(g, scale, scale, cache));
- }
- }
- }
- }
- private void ComboBox_TextChanged(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)
- {
- Width = designer.LogicalToDevice(100);
- ComboBox.ItemHeight = designer.LogicalToDevice(15);
- DropDownWidth = designer.LogicalToDevice(150);
- DropDownHeight = designer.LogicalToDevice(300);
- }
- public ToolStripStyleComboBox()
- {
- AutoSize = false;
- ComboBox.DrawMode = DrawMode.OwnerDrawVariable;
- ComboBox.ItemHeight = 15;
- ComboBox.DrawItem += ComboBox_DrawItem;
- ComboBox.MeasureItem += ComboBox_MeasureItem;
- ComboBox.TextChanged += ComboBox_TextChanged;
- Size = new Size(100, 25);
- DropDownWidth = 150;
- DropDownHeight = 300;
- }
- }
- }
|