DesignerStatusBar.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. using System;
  2. using System.Windows.Forms;
  3. using System.ComponentModel;
  4. using FastReport.Forms;
  5. using FastReport.Utils;
  6. using FastReport.DevComponents.DotNetBar;
  7. using FastReport.Design.PageDesigners.Page;
  8. using System.Drawing;
  9. namespace FastReport.Design.StandardDesigner
  10. {
  11. /// <summary>
  12. /// Represents the designer's statusbar.
  13. /// </summary>
  14. [ToolboxItem(false)]
  15. public class DesignerStatusBar : Bar, IDesignerPlugin
  16. {
  17. #region Fields
  18. private Designer designer;
  19. private LabelItem lblLocation;
  20. private LabelItem lbllocationRightBot;
  21. private LabelItem lblSize;
  22. private LabelItem lblText;
  23. private ItemContainer pnZoom;
  24. private ItemContainer pnZoomButtons;
  25. private ButtonItem btnZoomPageWidth;
  26. private ButtonItem btnZoomWholePage;
  27. private ButtonItem btnZoom100;
  28. private SliderItem slZoom;
  29. private bool updatingZoom;
  30. private Timer zoomTimer;
  31. private float zoomToUpdate;
  32. #endregion
  33. #region Properties
  34. private Designer Designer
  35. {
  36. get { return designer; }
  37. }
  38. #endregion
  39. #region Private Methods
  40. private void UpdateZoom()
  41. {
  42. updatingZoom = true;
  43. int zoom = (int)(Designer.Zoom * 100);
  44. slZoom.Text = zoom.ToString() + "%";
  45. if (zoom < 100)
  46. zoom = (int)Math.Round((zoom - 25) / 0.75f);
  47. else if (zoom > 100)
  48. zoom = (zoom - 100) / 4 + 100;
  49. slZoom.Value = zoom;
  50. updatingZoom = false;
  51. }
  52. private void btnZoomPageWidth_Click(object sender, EventArgs e)
  53. {
  54. Designer.ZoomPageWidth();
  55. }
  56. private void btnZoomWholePage_Click(object sender, EventArgs e)
  57. {
  58. Designer.ZoomWholePage();
  59. }
  60. private void btnZoom100_Click(object sender, EventArgs e)
  61. {
  62. Designer.Zoom = 1;
  63. }
  64. private void slZoom_ValueChanged(object sender, EventArgs e)
  65. {
  66. if (updatingZoom)
  67. return;
  68. int val = slZoom.Value;
  69. if (val < 100)
  70. val = (int)Math.Round(val * 0.75f) + 25;
  71. else
  72. val = (val - 100) * 4 + 100;
  73. slZoom.Text = val.ToString() + "%";
  74. zoomToUpdate = val / 100f;
  75. zoomTimer.Start();
  76. }
  77. private void FZoomTimer_Tick(object sender, EventArgs e)
  78. {
  79. zoomTimer.Stop();
  80. Designer.Zoom = zoomToUpdate;
  81. }
  82. #endregion
  83. #region IDesignerPlugin
  84. /// <inheritdoc/>
  85. public string PluginName
  86. {
  87. get { return Name; }
  88. }
  89. /// <inheritdoc/>
  90. public void SaveState()
  91. {
  92. }
  93. /// <inheritdoc/>
  94. public void RestoreState()
  95. {
  96. }
  97. /// <inheritdoc/>
  98. public void SelectionChanged()
  99. {
  100. UpdateContent();
  101. }
  102. /// <inheritdoc/>
  103. public void UpdateContent()
  104. {
  105. UpdateZoom();
  106. }
  107. /// <inheritdoc/>
  108. public void Lock()
  109. {
  110. }
  111. /// <inheritdoc/>
  112. public void Unlock()
  113. {
  114. UpdateContent();
  115. }
  116. /// <inheritdoc/>
  117. public void Localize()
  118. {
  119. UpdateContent();
  120. }
  121. /// <inheritdoc/>
  122. public DesignerOptionsPage GetOptionsPage()
  123. {
  124. return null;
  125. }
  126. /// <inheritdoc/>
  127. public void UpdateUIStyle()
  128. {
  129. Style = UIStyleUtils.GetDotNetBarStyle(Designer.UIStyle);
  130. }
  131. /// <inheritdoc/>
  132. public new void UpdateDpiDependencies()
  133. {
  134. base.UpdateDpiDependencies();
  135. Font = Designer.Font;
  136. lblLocation.Image = Designer.GetImage(62);
  137. Image image = (Image)Designer.GetImage(62).Clone();
  138. image.RotateFlip(RotateFlipType.Rotate180FlipNone);
  139. lbllocationRightBot.Image = image;
  140. lblSize.Image = Designer.GetImage(63);
  141. btnZoomPageWidth.Image = Designer.GetImage(235);
  142. btnZoomWholePage.Image = Designer.GetImage(236);
  143. btnZoom100.Image = Designer.GetImage(237);
  144. lblLocation.Width = this.LogicalToDevice(120);
  145. lbllocationRightBot.Width = this.LogicalToDevice(120);
  146. lblSize.Width = this.LogicalToDevice(120);
  147. slZoom.UpdateDpiDependencies();
  148. }
  149. #endregion
  150. #region Public Methods
  151. /// <summary>
  152. /// Updates the information about location and size.
  153. /// </summary>
  154. /// <param name="location">The location.</param>
  155. /// <param name="size">The size.</param>
  156. public void UpdateLocationAndSize(string location, string size, string locationRightBot)
  157. {
  158. lblLocation.Visible = !String.IsNullOrEmpty(location);
  159. lblLocation.Text = location;
  160. lblSize.Visible = !String.IsNullOrEmpty(size);
  161. lblSize.Text = size;
  162. lbllocationRightBot.Visible = !String.IsNullOrEmpty(locationRightBot);
  163. lbllocationRightBot.Text = locationRightBot;
  164. }
  165. /// <summary>
  166. /// Updates the name and text information.
  167. /// </summary>
  168. /// <param name="s">The text.</param>
  169. public void UpdateText(string s)
  170. {
  171. SelectedObjectCollection selection = designer.SelectedObjects;
  172. string text = selection.Count == 0 ? "" : selection.Count > 1 ?
  173. String.Format(Res.Get("Designer,ToolWindow,Properties,NObjectsSelected"), selection.Count) :
  174. selection[0].Name;
  175. if (!String.IsNullOrEmpty(s))
  176. text += ": " + s.Replace('\r', ' ').Replace('\n', ' ');
  177. lblText.Text = text;
  178. }
  179. #endregion
  180. /// <summary>
  181. /// Initializes a new instance of the <see cref="DesignerStatusBar"/> class with default settings.
  182. /// </summary>
  183. /// <param name="designer">The report designer.</param>
  184. public DesignerStatusBar(Designer designer) : base()
  185. {
  186. Name = "StatusBar";
  187. this.designer = designer;
  188. BarType = eBarType.StatusBar;
  189. GrabHandleStyle = eGrabHandleStyle.ResizeHandle;
  190. PaddingBottom = 2;
  191. PaddingTop = 3;
  192. //Style = FastReport.DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
  193. lblLocation = new LabelItem();
  194. lblLocation.Width = 160;
  195. lblLocation.Height = 19;
  196. lbllocationRightBot = new LabelItem();
  197. lbllocationRightBot.Width = 160;
  198. lbllocationRightBot.Height = 19;
  199. lblSize = new LabelItem();
  200. lblSize.Width = 160;
  201. lblSize.Height = 19;
  202. lblText = new LabelItem();
  203. lblText.Height = 19;
  204. lblText.Stretch = true;
  205. lblText.EnableMarkup = false;
  206. pnZoom = new ItemContainer();
  207. pnZoom.BackgroundStyle.Class = "Office2007StatusBarBackground2";
  208. pnZoomButtons = new ItemContainer();
  209. pnZoomButtons.BeginGroup = true;
  210. pnZoomButtons.VerticalItemAlignment = eVerticalItemsAlignment.Middle;
  211. btnZoomPageWidth = new ButtonItem();
  212. btnZoomPageWidth.Click += btnZoomPageWidth_Click;
  213. btnZoomWholePage = new ButtonItem();
  214. btnZoomWholePage.Click += btnZoomWholePage_Click;
  215. btnZoom100 = new ButtonItem();
  216. btnZoom100.Click += btnZoom100_Click;
  217. pnZoomButtons.SubItems.AddRange(new BaseItem[] { btnZoomPageWidth, btnZoomWholePage, btnZoom100 });
  218. slZoom = new SliderItem();
  219. slZoom.Maximum = 200;
  220. slZoom.Step = 5;
  221. slZoom.Text = "100%";
  222. slZoom.Value = 100;
  223. slZoom.Width = 120;
  224. slZoom.ValueChanged += slZoom_ValueChanged;
  225. pnZoom.SubItems.AddRange(new BaseItem[] { pnZoomButtons, slZoom });
  226. Items.AddRange(new BaseItem[] { lblLocation, lbllocationRightBot, lblSize, lblText, pnZoom });
  227. Dock = DockStyle.Bottom;
  228. this.designer.Controls.Add(this);
  229. zoomTimer = new Timer();
  230. zoomTimer.Interval = 50;
  231. zoomTimer.Tick += FZoomTimer_Tick;
  232. }
  233. }
  234. }