PdnStatusBar.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. using PaintDotNet.SystemLayer;
  2. using System;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. namespace PaintDotNet
  6. {
  7. internal sealed class PdnStatusBar
  8. : StatusStrip,
  9. IStatusBarProgress
  10. {
  11. private System.Windows.Forms.ToolStripStatusLabel contextStatusLabel;
  12. private System.Windows.Forms.ToolStripSeparator progressStatusSeparator;
  13. private System.Windows.Forms.ToolStripProgressBar progressStatusBar;
  14. private System.Windows.Forms.ToolStripStatusLabel imageInfoStatusLabel;
  15. private System.Windows.Forms.ToolStripStatusLabel cursorInfoStatusLabel;
  16. private string progressTextFormat = PdnResources.GetString("StatusBar.Progress.Percentage.Format");
  17. private ImageResource contextStatusImage;
  18. public string ImageInfoStatusText
  19. {
  20. get
  21. {
  22. return this.imageInfoStatusLabel.Text;
  23. }
  24. set
  25. {
  26. this.imageInfoStatusLabel.Text = value;
  27. Update();
  28. }
  29. }
  30. public string ContextStatusText
  31. {
  32. get
  33. {
  34. return this.contextStatusLabel.Text;
  35. }
  36. set
  37. {
  38. this.contextStatusLabel.Text = value;
  39. Update();
  40. }
  41. }
  42. public ImageResource ContextStatusImage
  43. {
  44. get
  45. {
  46. return this.contextStatusImage;
  47. }
  48. set
  49. {
  50. this.contextStatusImage = value;
  51. if (this.contextStatusImage == null)
  52. {
  53. this.contextStatusLabel.Image = null;
  54. }
  55. else
  56. {
  57. this.contextStatusLabel.Image = this.contextStatusImage.Reference;
  58. }
  59. Update();
  60. }
  61. }
  62. public string CursorInfoText
  63. {
  64. get
  65. {
  66. return this.cursorInfoStatusLabel.Text;
  67. }
  68. set
  69. {
  70. this.cursorInfoStatusLabel.Text = value;
  71. Update();
  72. }
  73. }
  74. public void ResetProgressStatusBarAsync()
  75. {
  76. this.BeginInvoke(new Procedure(ResetProgressStatusBar));
  77. }
  78. public void EraseProgressStatusBar()
  79. {
  80. try
  81. {
  82. this.progressStatusSeparator.Visible = false;
  83. this.progressStatusBar.Visible = false;
  84. this.progressStatusBar.Value = 0;
  85. }
  86. catch (NullReferenceException)
  87. {
  88. // See bug #2212 -- appears to be a bug in the framework
  89. }
  90. }
  91. public void EraseProgressStatusBarAsync()
  92. {
  93. this.BeginInvoke(new Procedure(EraseProgressStatusBar));
  94. }
  95. public void ResetProgressStatusBar()
  96. {
  97. try
  98. {
  99. this.progressStatusBar.Value = 0;
  100. this.progressStatusSeparator.Visible = true;
  101. this.progressStatusBar.Visible = true;
  102. }
  103. catch (NullReferenceException nrex)
  104. {
  105. Tracing.Ping(nrex.ToString());
  106. }
  107. }
  108. public double GetProgressStatusBarValue()
  109. {
  110. lock (this.progressStatusBar)
  111. {
  112. return this.progressStatusBar.Value;
  113. }
  114. }
  115. public void SetProgressStatusBar(double percent)
  116. {
  117. lock (this.progressStatusBar)
  118. {
  119. this.progressStatusBar.Value = (int)percent;
  120. bool visible = (percent != 100);
  121. this.progressStatusBar.Visible = visible;
  122. this.progressStatusSeparator.Visible = visible;
  123. }
  124. }
  125. public PdnStatusBar()
  126. {
  127. InitializeComponent();
  128. this.cursorInfoStatusLabel.Image = PdnResources.GetImageResource("Icons.CursorXYIcon.png").Reference;
  129. this.cursorInfoStatusLabel.Text = string.Empty;
  130. // imageInfo (width,height info)
  131. this.imageInfoStatusLabel.Image = PdnResources.GetImageResource("Icons.ImageSizeIcon.png").Reference;
  132. // progress
  133. this.progressStatusBar.Visible = false;
  134. this.progressStatusSeparator.Visible = false;
  135. this.progressStatusBar.Height -= 4;
  136. this.progressStatusBar.ProgressBar.Style = ProgressBarStyle.Continuous;
  137. }
  138. private void InitializeComponent()
  139. {
  140. this.contextStatusLabel = new ToolStripStatusLabel();
  141. this.progressStatusSeparator = new ToolStripSeparator();
  142. this.progressStatusBar = new ToolStripProgressBar();
  143. this.imageInfoStatusLabel = new ToolStripStatusLabel();
  144. this.cursorInfoStatusLabel = new ToolStripStatusLabel();
  145. SuspendLayout();
  146. //
  147. // contextStatusLabel
  148. //
  149. this.contextStatusLabel.Name = "contextStatusLabel";
  150. this.contextStatusLabel.Width = UI.ScaleWidth(436);
  151. this.contextStatusLabel.Spring = true;
  152. this.contextStatusLabel.TextAlign = ContentAlignment.MiddleLeft;
  153. this.contextStatusLabel.ImageAlign = ContentAlignment.MiddleLeft;
  154. //
  155. // progressStatusBar
  156. //
  157. this.progressStatusBar.Name = "progressStatusBar";
  158. this.progressStatusBar.Width = 130;
  159. this.progressStatusBar.AutoSize = false;
  160. //
  161. // imageInfoStatusLabel
  162. //
  163. this.imageInfoStatusLabel.Name = "imageInfoStatusLabel";
  164. this.imageInfoStatusLabel.Width = UI.ScaleWidth(130);
  165. this.imageInfoStatusLabel.TextAlign = ContentAlignment.MiddleLeft;
  166. this.imageInfoStatusLabel.ImageAlign = ContentAlignment.MiddleLeft;
  167. this.imageInfoStatusLabel.AutoSize = false;
  168. //
  169. // cursorInfoStatusLabel
  170. //
  171. this.cursorInfoStatusLabel.Name = "cursorInfoStatusLabel";
  172. this.cursorInfoStatusLabel.Width = UI.ScaleWidth(230);
  173. this.cursorInfoStatusLabel.TextAlign = ContentAlignment.MiddleLeft;
  174. this.cursorInfoStatusLabel.ImageAlign = ContentAlignment.MiddleLeft;
  175. this.cursorInfoStatusLabel.AutoSize = false;
  176. //
  177. // PdnStatusBar
  178. //
  179. this.Name = "PdnStatusBar";
  180. this.Items.Add(this.contextStatusLabel);
  181. this.Items.Add(this.progressStatusSeparator);
  182. this.Items.Add(this.progressStatusBar);
  183. this.Items.Add(new ToolStripSeparator());
  184. this.Items.Add(this.imageInfoStatusLabel);
  185. this.Items.Add(new ToolStripSeparator());
  186. this.Items.Add(this.cursorInfoStatusLabel);
  187. ResumeLayout(false);
  188. }
  189. }
  190. }