123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430 |
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- using FastReport.Utils;
- using FastReport.Controls;
- namespace FastReport.Forms
- {
- internal partial class HighlightEditorForm : BaseDialogForm
- {
- private Report report;
- private ImageList images;
- private ConditionCollection conditions;
- private Timer refreshTimer;
- private bool updating;
- public ConditionCollection Conditions
- {
- get { return conditions; }
- set
- {
- conditions = new ConditionCollection();
- conditions.Assign(value);
- PopulateConditions();
- }
- }
- private HighlightCondition CurrentCondition
- {
- get
- {
- if (lvConditions.SelectedItems.Count == 0)
- return null;
- return lvConditions.SelectedItems[0].Tag as HighlightCondition;
- }
- }
- private Bitmap GetImage(HighlightCondition c)
- {
- Bitmap bmp = new Bitmap(16, 16);
- using (Graphics g = Graphics.FromImage(bmp))
- {
- g.FillRectangle(Brushes.White, new RectangleF(0, 0, 16, 16));
- using (TextObject sample = new TextObject())
- {
- sample.Bounds = new RectangleF(0, 0, 16, 16);
- sample.ApplyCondition(c);
- sample.Font = new Font("Times New Roman", 12);
- sample.Text = "A";
- sample.HorzAlign = HorzAlign.Center;
- sample.VertAlign = VertAlign.Center;
- using (GraphicCache cache = new GraphicCache())
- {
- sample.Draw(new FRPaintEventArgs(g, 1, 1, cache));
- }
- }
- }
- return bmp;
- }
- private int GetImageIndex(HighlightCondition c)
- {
- Bitmap bmp = GetImage(c);
- images.Images.Add(bmp);
- return images.Images.Count - 1;
- }
- private void RefreshSample()
- {
- pnSample.Refresh();
- }
- private void UpdateControls()
- {
- bool enabled = CurrentCondition != null;
- btnDelete.Enabled = enabled;
- btnEdit.Enabled = enabled;
- btnUp.Enabled = enabled;
- btnDown.Enabled = enabled;
- gbStyle.Enabled = enabled;
- if (enabled)
- {
- updating = true;
- cbApplyBorder.Checked = CurrentCondition.ApplyBorder;
- cbApplyFill.Checked = CurrentCondition.ApplyFill;
- cbApplyTextFill.Checked = CurrentCondition.ApplyTextFill;
- cbApplyFont.Checked = CurrentCondition.ApplyFont;
- cbVisible.Checked = CurrentCondition.Visible;
- btnBorder.Enabled = CurrentCondition.ApplyBorder;
- btnFill.Enabled = CurrentCondition.ApplyFill;
- btnTextColor.Enabled = CurrentCondition.ApplyTextFill;
- btnFont.Enabled = CurrentCondition.ApplyFont;
- updating = false;
- }
- }
- private void SetApply()
- {
- foreach (ListViewItem li in lvConditions.SelectedItems)
- {
- HighlightCondition c = li.Tag as HighlightCondition;
- c.ApplyBorder = cbApplyBorder.Checked;
- c.ApplyFill = cbApplyFill.Checked;
- c.ApplyTextFill = cbApplyTextFill.Checked;
- c.ApplyFont = cbApplyFont.Checked;
- c.Visible = cbVisible.Checked;
- li.ImageIndex = GetImageIndex(c);
- }
- RefreshSample();
- }
- private void PopulateConditions()
- {
- foreach (HighlightCondition c in conditions)
- {
- ListViewItem li = lvConditions.Items.Add(c.Expression, GetImageIndex(c));
- li.Tag = c;
- }
- if (lvConditions.Items.Count > 0)
- lvConditions.Items[0].Selected = true;
- UpdateControls();
- }
- private void pnSample_Paint(object sender, PaintEventArgs e)
- {
- if (CurrentCondition == null)
- return;
- #if AVALONIA
- e.Graphics.FontScale = 1;
- #endif
- using (TextObject sample = new TextObject())
- {
- sample.Text = Res.Get("Misc,Sample");
- sample.ApplyCondition(CurrentCondition);
- float scale = this.DpiMultiplier();
- sample.Bounds = new RectangleF(2, 2, pnSample.Width / scale - 4, pnSample.Height / scale - 4);
- sample.HorzAlign = HorzAlign.Center;
- sample.VertAlign = VertAlign.Center;
- using (GraphicCache cache = new GraphicCache())
- {
- sample.Draw(new FRPaintEventArgs(e.Graphics, scale, scale, cache));
- }
- }
- }
- private void FTimer_Tick(object sender, EventArgs e)
- {
- UpdateControls();
- RefreshSample();
- refreshTimer.Stop();
- }
- private void lvConditions_SelectedIndexChanged(object sender, EventArgs e)
- {
- refreshTimer.Start();
- }
- private void btnAdd_Click(object sender, EventArgs e)
- {
- using (ExpressionEditorForm form = new ExpressionEditorForm(report))
- {
- form.ExpressionText = report.ScriptLanguage == Language.CSharp ? "Value == 0" : "Value = 0";
- if (form.ShowDialog() == DialogResult.OK)
- {
- HighlightCondition c = new HighlightCondition();
- conditions.Add(c);
- c.Expression = form.ExpressionText;
- ListViewItem li = lvConditions.Items.Add(c.Expression, GetImageIndex(c));
- li.Tag = c;
- lvConditions.SelectedItems.Clear();
- li.Selected = true;
- }
- }
- }
- private void btnDelete_Click(object sender, EventArgs e)
- {
- while (lvConditions.SelectedItems.Count > 0)
- {
- HighlightCondition c = lvConditions.SelectedItems[0].Tag as HighlightCondition;
- conditions.Remove(c);
- lvConditions.Items.Remove(lvConditions.SelectedItems[0]);
- }
- }
- private void btnEdit_Click(object sender, EventArgs e)
- {
- if (lvConditions.SelectedItems.Count == 1)
- {
- using (ExpressionEditorForm form = new ExpressionEditorForm(report))
- {
- form.ExpressionText = CurrentCondition.Expression;
- if (form.ShowDialog() == DialogResult.OK)
- {
- CurrentCondition.Expression = form.ExpressionText;
- lvConditions.SelectedItems[0].Text = CurrentCondition.Expression;
- }
- }
- }
- }
- private void btnUp_Click(object sender, EventArgs e)
- {
- if (lvConditions.SelectedItems.Count != 1)
- return;
- int index = lvConditions.SelectedIndices[0];
- if (index > 0)
- {
- ListViewItem li = lvConditions.SelectedItems[0];
- lvConditions.Items.Remove(li);
- lvConditions.Items.Insert(index - 1, li);
- li.Selected = false;
- li.Selected = true;
- HighlightCondition c = li.Tag as HighlightCondition;
- conditions.Remove(c);
- conditions.Insert(index - 1, c);
- }
- }
- private void btnDown_Click(object sender, EventArgs e)
- {
- if (lvConditions.SelectedItems.Count != 1)
- return;
- int index = lvConditions.SelectedIndices[0];
- if (index < lvConditions.Items.Count - 1)
- {
- ListViewItem li = lvConditions.SelectedItems[0];
- lvConditions.Items.Remove(li);
- lvConditions.Items.Insert(index + 1, li);
- li.Selected = false;
- li.Selected = true;
- HighlightCondition c = li.Tag as HighlightCondition;
- conditions.Remove(c);
- conditions.Insert(index + 1, c);
- }
- }
- private void cbApplyBorder_CheckedChanged(object sender, EventArgs e)
- {
- if (updating || CurrentCondition == null)
- return;
- btnBorder.Enabled = cbApplyBorder.Checked;
- SetApply();
- }
- private void cbApplyFill_CheckedChanged(object sender, EventArgs e)
- {
- if (updating || CurrentCondition == null)
- return;
- btnFill.Enabled = cbApplyFill.Checked;
- SetApply();
- }
- private void cbApplyTextFill_CheckedChanged(object sender, EventArgs e)
- {
- if (updating || CurrentCondition == null)
- return;
- btnTextColor.Enabled = cbApplyTextFill.Checked;
- SetApply();
- }
- private void cbApplyFont_CheckedChanged(object sender, EventArgs e)
- {
- if (updating || CurrentCondition == null)
- return;
- btnFont.Enabled = cbApplyFont.Checked;
- SetApply();
- }
- private void btnBorder_Click(object sender, EventArgs e)
- {
- if (CurrentCondition == null)
- return;
- using (BorderEditorForm editor = new BorderEditorForm())
- {
- editor.Border = CurrentCondition.Border.Clone();
- if (editor.ShowDialog() == DialogResult.OK)
- {
- foreach (ListViewItem li in lvConditions.SelectedItems)
- {
- HighlightCondition c = li.Tag as HighlightCondition;
- c.Border = editor.Border.Clone();
- li.ImageIndex = GetImageIndex(c);
- }
- RefreshSample();
- }
- }
- }
- private void btnFill_Click(object sender, EventArgs e)
- {
- if (CurrentCondition == null)
- return;
- using (FillEditorForm editor = new FillEditorForm())
- {
- editor.Fill = CurrentCondition.Fill.Clone();
- if (editor.ShowDialog() == DialogResult.OK)
- {
- foreach (ListViewItem li in lvConditions.SelectedItems)
- {
- HighlightCondition c = li.Tag as HighlightCondition;
- c.Fill = editor.Fill.Clone();
- li.ImageIndex = GetImageIndex(c);
- }
- RefreshSample();
- }
- }
- }
- private void btnTextColor_Click(object sender, EventArgs e)
- {
- if (CurrentCondition == null)
- return;
- using (FillEditorForm editor = new FillEditorForm())
- {
- editor.Fill = CurrentCondition.TextFill.Clone();
- if (editor.ShowDialog() == DialogResult.OK)
- {
- foreach (ListViewItem li in lvConditions.SelectedItems)
- {
- HighlightCondition c = li.Tag as HighlightCondition;
- c.TextFill = editor.Fill.Clone();
- li.ImageIndex = GetImageIndex(c);
- }
- RefreshSample();
- }
- }
- }
- private void btnFont_Click(object sender, EventArgs e)
- {
- if (CurrentCondition == null)
- return;
- using (FontDialog dialog = new FontDialog())
- {
- dialog.Font = CurrentCondition.Font;
- if (dialog.ShowDialog() == DialogResult.OK)
- {
- foreach (ListViewItem li in lvConditions.SelectedItems)
- {
- HighlightCondition c = li.Tag as HighlightCondition;
- c.Font = dialog.Font;
- li.ImageIndex = GetImageIndex(c);
- }
- RefreshSample();
- }
- }
- }
- private void cbVisible_CheckedChanged(object sender, EventArgs e)
- {
- if (updating || CurrentCondition == null)
- return;
- SetApply();
- }
- private void HighlightEditorForm_FormClosed(object sender, FormClosedEventArgs e)
- {
- Done();
- }
- private void Init()
- {
- images = new ImageList();
- images.ImageSize = new Size(16, 16);
- images.ColorDepth = ColorDepth.Depth24Bit;
- lvConditions.SmallImageList = images;
- refreshTimer = new Timer();
- refreshTimer.Interval = 50;
- refreshTimer.Tick += FTimer_Tick;
- }
- private void Done()
- {
- images.Dispose();
- }
- public override void Localize()
- {
- base.Localize();
- MyRes res = new MyRes("Forms,HighlightEditor");
- Text = res.Get("");
- gbConditions.Text = res.Get("Conditions");
- btnAdd.Text = res.Get("Add");
- btnDelete.Text = res.Get("Delete");
- btnEdit.Text = res.Get("Edit");
- gbStyle.Text = res.Get("Style");
- btnBorder.Text = Res.Get("Forms,Style,Border");
- btnFill.Text = res.Get("Fill");
- btnTextColor.Text = res.Get("TextColor");
- btnFont.Text = res.Get("Font");
- cbVisible.Text = res.Get("Visible");
- }
- public override void UpdateDpiDependencies()
- {
- base.UpdateDpiDependencies();
- btnUp.Image = GetImage(208);
- btnDown.Image = GetImage(209);
- btnBorder.Image = GetImage(36);
- btnFill.Image = GetImage(38);
- btnTextColor.Image = GetImage(23);
- btnFont.Image = GetImage(59);
- MinimumSize = this.LogicalToDevice(new Size(480, 322));
- }
- public HighlightEditorForm(Report report)
- {
- this.report = report;
- CanSaveRestoreState = true;
- InitializeComponent();
- Init();
- Localize();
- UIUtils.CheckRTL(this);
- UpdateDpiDependencies();
- }
- }
- }
|