DesignerStatusBar.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Drawing;
  4. using System.ComponentModel;
  5. using FastReport.Forms;
  6. using FastReport.Utils;
  7. using FastReport.Controls;
  8. namespace FastReport.Design.StandardDesigner
  9. {
  10. /// <summary>
  11. /// Represents the designer's statusbar.
  12. /// </summary>
  13. [ToolboxItem(false)]
  14. public class DesignerStatusBar : StatusStrip, IDesignerPlugin
  15. {
  16. #region Fields
  17. private Designer FDesigner;
  18. private ToolStripStatusLabel lblLocationRightBot;
  19. private ToolStripStatusLabel lblLocation;
  20. private ToolStripStatusLabel lblSize;
  21. private ToolStripStatusLabel lblText;
  22. private ToolStripZoomControl zoomControl;
  23. private bool updatingZoom;
  24. #endregion
  25. #region Properties
  26. private Designer Designer
  27. {
  28. get { return FDesigner; }
  29. }
  30. #endregion
  31. #region IDesignerPlugin
  32. /// <inheritdoc/>
  33. public string PluginName
  34. {
  35. get { return Name; }
  36. }
  37. /// <inheritdoc/>
  38. public void SaveState()
  39. {
  40. }
  41. /// <inheritdoc/>
  42. public void ReinitDpiSize()
  43. {
  44. }
  45. /// <inheritdoc/>
  46. public void RestoreState()
  47. {
  48. }
  49. /// <inheritdoc/>
  50. public void SelectionChanged()
  51. {
  52. UpdateContent();
  53. }
  54. /// <inheritdoc/>
  55. public void UpdateContent()
  56. {
  57. UpdateZoom();
  58. }
  59. /// <inheritdoc/>
  60. public void Lock()
  61. {
  62. }
  63. /// <inheritdoc/>
  64. public void Unlock()
  65. {
  66. UpdateContent();
  67. }
  68. /// <inheritdoc/>
  69. public void Localize()
  70. {
  71. UpdateContent();
  72. }
  73. /// <inheritdoc/>
  74. public DesignerOptionsPage GetOptionsPage()
  75. {
  76. return null;
  77. }
  78. /// <inheritdoc/>
  79. public void UpdateUIStyle()
  80. {
  81. Renderer = UIStyleUtils.GetToolStripRenderer(Designer.UIStyle);
  82. zoomControl.UIStyle = Designer.UIStyle;
  83. }
  84. private Image Rotate180(Image original)
  85. {
  86. var bitmap = new Bitmap(original.Width, original.Height);
  87. using (var g = Graphics.FromImage(bitmap))
  88. {
  89. g.TranslateTransform(bitmap.Width / 2, bitmap.Height / 2);
  90. g.RotateTransform(180);
  91. g.DrawImage(original, -bitmap.Width / 2, -bitmap.Height / 2);
  92. }
  93. return bitmap;
  94. }
  95. /// <inheritdoc/>
  96. public void UpdateDpiDependencies()
  97. {
  98. Font = Designer.LogicalToDevice(DrawUtils.DefaultFont);
  99. Height = Designer.LogicalToDevice(26);
  100. Padding = new Padding(6, 0, 0, 0);
  101. lblLocation.Size = Designer.LogicalToDevice(new Size(140, 26));
  102. lblLocationRightBot.Size = lblLocation.Size;
  103. lblSize.Size = lblLocation.Size;
  104. lblLocation.Image = Designer.GetImage(62);
  105. lblLocationRightBot.Image = Rotate180(Designer.GetImage(62));
  106. lblSize.Image = Designer.GetImage(63);
  107. zoomControl.Size = Designer.LogicalToDevice(new Size(280, 26));
  108. }
  109. #endregion
  110. #region Private Methods
  111. private void UpdateZoom()
  112. {
  113. updatingZoom = true;
  114. zoomControl.ZoomValue = Designer.Zoom;
  115. updatingZoom = false;
  116. }
  117. private void btnZoomPageWidth_Click(object sender, EventArgs e)
  118. {
  119. Designer.ZoomPageWidth();
  120. }
  121. private void btnZoomWholePage_Click(object sender, EventArgs e)
  122. {
  123. Designer.ZoomWholePage();
  124. }
  125. private void btnZoom100_Click(object sender, EventArgs e)
  126. {
  127. Designer.Zoom = 1;
  128. }
  129. private void slider_ValueChanged(object sender, EventArgs e)
  130. {
  131. if (updatingZoom)
  132. return;
  133. Designer.Zoom = zoomControl.ZoomValue;
  134. }
  135. #endregion
  136. #region Public Methods
  137. /// <summary>
  138. /// Updates the information about location and size.
  139. /// </summary>
  140. /// <param name="location">The location.</param>
  141. /// <param name="size">The size.</param>
  142. /// <param name="locationRightBot">The location of right bottom angle.</param>
  143. public void UpdateLocationAndSize(string location, string size, string locationRightBot)
  144. {
  145. lblLocation.Visible = !String.IsNullOrEmpty(location);
  146. lblLocation.Text = location;
  147. lblSize.Visible = !String.IsNullOrEmpty(size);
  148. lblSize.Text = size;
  149. lblLocationRightBot.Visible = !String.IsNullOrEmpty(locationRightBot);
  150. lblLocationRightBot.Text = locationRightBot;
  151. }
  152. /// <summary>
  153. /// Updates the name and text information.
  154. /// </summary>
  155. /// <param name="s">The text.</param>
  156. public void UpdateText(string s)
  157. {
  158. SelectedObjectCollection selection = FDesigner.SelectedObjects;
  159. string text = selection.Count == 0 ? "" : selection.Count > 1 ?
  160. String.Format(Res.Get("Designer,ToolWindow,Properties,NObjectsSelected"), selection.Count) :
  161. selection[0].Name;
  162. if (!String.IsNullOrEmpty(s))
  163. text += ": " + s.Replace('\r', ' ').Replace('\n', ' ');
  164. lblText.Text = text;
  165. }
  166. #endregion
  167. /// <summary>
  168. /// Initializes a new instance of the <see cref="DesignerStatusBar"/> class with default settings.
  169. /// </summary>
  170. /// <param name="designer">The report designer.</param>
  171. public DesignerStatusBar(Designer designer) : base()
  172. {
  173. Name = "StatusBar";
  174. FDesigner = designer;
  175. AutoSize = false;
  176. SizingGrip = false;
  177. lblLocation = new ToolStripStatusLabel();
  178. lblLocation.AutoSize = false;
  179. lblLocation.TextAlign = ContentAlignment.MiddleLeft;
  180. lblLocation.ImageAlign = ContentAlignment.MiddleLeft;
  181. lblLocationRightBot = new ToolStripStatusLabel();
  182. lblLocationRightBot.AutoSize = false;
  183. lblLocationRightBot.TextAlign = ContentAlignment.MiddleLeft;
  184. lblLocationRightBot.ImageAlign = ContentAlignment.MiddleLeft;
  185. lblSize = new ToolStripStatusLabel();
  186. lblSize.AutoSize = false;
  187. lblSize.TextAlign = ContentAlignment.MiddleLeft;
  188. lblSize.ImageAlign = ContentAlignment.MiddleLeft;
  189. lblText = new ToolStripStatusLabel();
  190. lblText.Spring = true;
  191. lblText.TextAlign = ContentAlignment.MiddleLeft;
  192. zoomControl = new ToolStripZoomControl();
  193. zoomControl.ZoomPageWidthClick += btnZoomPageWidth_Click;
  194. zoomControl.ZoomWholePageClick += btnZoomWholePage_Click;
  195. zoomControl.Zoom100Click += btnZoom100_Click;
  196. zoomControl.ValueChanged += slider_ValueChanged;
  197. Items.AddRange(new ToolStripItem[] { lblLocation, lblLocationRightBot, lblSize, lblText, zoomControl });
  198. Dock = DockStyle.Bottom;
  199. FDesigner.Controls.Add(this);
  200. UpdateDpiDependencies();
  201. }
  202. }
  203. }