using System;
using System.Windows.Forms;
using System.ComponentModel;
using FastReport.Forms;
using FastReport.Utils;
using FastReport.DevComponents.DotNetBar;
using FastReport.Design.PageDesigners.Page;
using System.Drawing;
namespace FastReport.Design.StandardDesigner
{
///
/// Represents the designer's statusbar.
///
[ToolboxItem(false)]
public class DesignerStatusBar : Bar, IDesignerPlugin
{
#region Fields
private Designer designer;
private LabelItem lblLocation;
private LabelItem lbllocationRightBot;
private LabelItem lblSize;
private LabelItem lblText;
private ItemContainer pnZoom;
private ItemContainer pnZoomButtons;
private ButtonItem btnZoomPageWidth;
private ButtonItem btnZoomWholePage;
private ButtonItem btnZoom100;
private SliderItem slZoom;
private bool updatingZoom;
private Timer zoomTimer;
private float zoomToUpdate;
#endregion
#region Properties
private Designer Designer
{
get { return designer; }
}
#endregion
#region Private Methods
private void UpdateZoom()
{
updatingZoom = true;
int zoom = (int)(Designer.Zoom * 100);
slZoom.Text = zoom.ToString() + "%";
if (zoom < 100)
zoom = (int)Math.Round((zoom - 25) / 0.75f);
else if (zoom > 100)
zoom = (zoom - 100) / 4 + 100;
slZoom.Value = zoom;
updatingZoom = false;
}
private void btnZoomPageWidth_Click(object sender, EventArgs e)
{
Designer.ZoomPageWidth();
}
private void btnZoomWholePage_Click(object sender, EventArgs e)
{
Designer.ZoomWholePage();
}
private void btnZoom100_Click(object sender, EventArgs e)
{
Designer.Zoom = 1;
}
private void slZoom_ValueChanged(object sender, EventArgs e)
{
if (updatingZoom)
return;
int val = slZoom.Value;
if (val < 100)
val = (int)Math.Round(val * 0.75f) + 25;
else
val = (val - 100) * 4 + 100;
slZoom.Text = val.ToString() + "%";
zoomToUpdate = val / 100f;
zoomTimer.Start();
}
private void FZoomTimer_Tick(object sender, EventArgs e)
{
zoomTimer.Stop();
Designer.Zoom = zoomToUpdate;
}
#endregion
#region IDesignerPlugin
///
public string PluginName
{
get { return Name; }
}
///
public void SaveState()
{
}
///
public void RestoreState()
{
}
///
public void SelectionChanged()
{
UpdateContent();
}
///
public void UpdateContent()
{
UpdateZoom();
}
///
public void Lock()
{
}
///
public void Unlock()
{
UpdateContent();
}
///
public void Localize()
{
UpdateContent();
}
///
public DesignerOptionsPage GetOptionsPage()
{
return null;
}
///
public void UpdateUIStyle()
{
Style = UIStyleUtils.GetDotNetBarStyle(Designer.UIStyle);
}
///
public new void UpdateDpiDependencies()
{
base.UpdateDpiDependencies();
Font = Designer.Font;
lblLocation.Image = Designer.GetImage(62);
Image image = (Image)Designer.GetImage(62).Clone();
image.RotateFlip(RotateFlipType.Rotate180FlipNone);
lbllocationRightBot.Image = image;
lblSize.Image = Designer.GetImage(63);
btnZoomPageWidth.Image = Designer.GetImage(235);
btnZoomWholePage.Image = Designer.GetImage(236);
btnZoom100.Image = Designer.GetImage(237);
lblLocation.Width = this.LogicalToDevice(120);
lbllocationRightBot.Width = this.LogicalToDevice(120);
lblSize.Width = this.LogicalToDevice(120);
slZoom.UpdateDpiDependencies();
}
#endregion
#region Public Methods
///
/// Updates the information about location and size.
///
/// The location.
/// The size.
public void UpdateLocationAndSize(string location, string size, string locationRightBot)
{
lblLocation.Visible = !String.IsNullOrEmpty(location);
lblLocation.Text = location;
lblSize.Visible = !String.IsNullOrEmpty(size);
lblSize.Text = size;
lbllocationRightBot.Visible = !String.IsNullOrEmpty(locationRightBot);
lbllocationRightBot.Text = locationRightBot;
}
///
/// Updates the name and text information.
///
/// The text.
public void UpdateText(string s)
{
SelectedObjectCollection selection = designer.SelectedObjects;
string text = selection.Count == 0 ? "" : selection.Count > 1 ?
String.Format(Res.Get("Designer,ToolWindow,Properties,NObjectsSelected"), selection.Count) :
selection[0].Name;
if (!String.IsNullOrEmpty(s))
text += ": " + s.Replace('\r', ' ').Replace('\n', ' ');
lblText.Text = text;
}
#endregion
///
/// Initializes a new instance of the class with default settings.
///
/// The report designer.
public DesignerStatusBar(Designer designer) : base()
{
Name = "StatusBar";
this.designer = designer;
BarType = eBarType.StatusBar;
GrabHandleStyle = eGrabHandleStyle.ResizeHandle;
PaddingBottom = 2;
PaddingTop = 3;
//Style = FastReport.DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
lblLocation = new LabelItem();
lblLocation.Width = 160;
lblLocation.Height = 19;
lbllocationRightBot = new LabelItem();
lbllocationRightBot.Width = 160;
lbllocationRightBot.Height = 19;
lblSize = new LabelItem();
lblSize.Width = 160;
lblSize.Height = 19;
lblText = new LabelItem();
lblText.Height = 19;
lblText.Stretch = true;
lblText.EnableMarkup = false;
pnZoom = new ItemContainer();
pnZoom.BackgroundStyle.Class = "Office2007StatusBarBackground2";
pnZoomButtons = new ItemContainer();
pnZoomButtons.BeginGroup = true;
pnZoomButtons.VerticalItemAlignment = eVerticalItemsAlignment.Middle;
btnZoomPageWidth = new ButtonItem();
btnZoomPageWidth.Click += btnZoomPageWidth_Click;
btnZoomWholePage = new ButtonItem();
btnZoomWholePage.Click += btnZoomWholePage_Click;
btnZoom100 = new ButtonItem();
btnZoom100.Click += btnZoom100_Click;
pnZoomButtons.SubItems.AddRange(new BaseItem[] { btnZoomPageWidth, btnZoomWholePage, btnZoom100 });
slZoom = new SliderItem();
slZoom.Maximum = 200;
slZoom.Step = 5;
slZoom.Text = "100%";
slZoom.Value = 100;
slZoom.Width = 120;
slZoom.ValueChanged += slZoom_ValueChanged;
pnZoom.SubItems.AddRange(new BaseItem[] { pnZoomButtons, slZoom });
Items.AddRange(new BaseItem[] { lblLocation, lbllocationRightBot, lblSize, lblText, pnZoom });
Dock = DockStyle.Bottom;
this.designer.Controls.Add(this);
zoomTimer = new Timer();
zoomTimer.Interval = 50;
zoomTimer.Tick += FZoomTimer_Tick;
}
}
}