ToolsControl.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. using SmartCoalApplication.Core;
  2. using SmartCoalApplication.SystemLayer;
  3. using System;
  4. using System.Drawing;
  5. using System.Windows.Forms;
  6. namespace SmartCoalApplication
  7. {
  8. internal class ToolsControl : UserControl
  9. {
  10. private ToolStripEx toolStripEx;
  11. private ImageList imageList;
  12. private const int tbWidth = 2;
  13. private Control onePxSpacingLeft;
  14. //private ShortcutbarModel shortcutbarModel = Startup.instance.shortcutbarModel;
  15. private System.ComponentModel.Container components = null;
  16. private AppWorkspace appWorkspace;
  17. public ToolsControl(AppWorkspace appWorkspace)
  18. {
  19. this.appWorkspace = appWorkspace;
  20. InitializeComponent();
  21. SetTools();
  22. }
  23. public void SetTools()
  24. {
  25. if (this.toolStripEx != null)
  26. {
  27. this.toolStripEx.Items.Clear();
  28. }
  29. this.imageList = new ImageList();
  30. this.imageList.ColorDepth = ColorDepth.Depth32Bit;
  31. this.imageList.TransparentColor = Utility.TransparentKey;
  32. this.toolStripEx.ImageList = this.imageList;
  33. SetCustomizeTools();
  34. }
  35. public void SetCustomizeTools()
  36. {
  37. /*if (shortcutbarModel != null)
  38. {
  39. if (shortcutbarModel.Menus.Count > 0)
  40. {
  41. ToolStripItem[] buttons = new ToolStripItem[shortcutbarModel.Menus.Count];
  42. for (int i = 0; i < shortcutbarModel.Menus.Count; i++)
  43. {
  44. ToolStripButton button = new ToolStripButton();
  45. int imageIndex = -1;
  46. ToolStripItem[] items = this.appWorkspace.ToolBar.MainMenu.Items.Find(shortcutbarModel.Menus[i].Description, true);
  47. if (items != null && items.Length > 0)
  48. {
  49. if (((PdnMenuItem)(items[0])).Image != null)
  50. {
  51. imageIndex = this.imageList.Images.Add(((PdnMenuItem)(items[0])).Image, imageList.TransparentColor);
  52. button.ToolTipText = ((PdnMenuItem)(items[0])).Text;
  53. }
  54. else
  55. {
  56. imageIndex = this.imageList.Images.Add(PdnResources.GetImageResource("Icons.MenuImageRotate90CWIcon.png").Reference, imageList.TransparentColor);
  57. //imageIndex = this.imageList.Images.Add(new Bitmap(16, 16), imageList.TransparentColor);
  58. button.ToolTipText = shortcutbarModel.Menus[i].Name;// getShowName(Startup.instance.configModel.Language);
  59. }
  60. }
  61. else
  62. {
  63. imageIndex = this.imageList.Images.Add(PdnResources.GetImageResource("Icons.MenuImageRotate90CWIcon.png").Reference, imageList.TransparentColor);
  64. //imageIndex = this.imageList.Images.Add(new Bitmap(16, 16), imageList.TransparentColor);
  65. button.ToolTipText = shortcutbarModel.Menus[i].Name;// getShowName(Startup.instance.configModel.Language);
  66. }
  67. button.Enabled = Startup.getMenuIdVisible(shortcutbarModel.Menus[i].Id);
  68. button.ImageIndex = imageIndex;
  69. button.Tag = shortcutbarModel.Menus[i].Description;
  70. buttons[i] = button;
  71. if (this.appWorkspace.ActiveDocumentWorkspace != null)
  72. {
  73. if (button.Tag.ToString().Equals(this.type))
  74. button.Checked = this.check;
  75. }
  76. }
  77. this.toolStripEx.Items.AddRange(buttons);
  78. appWorkspace.SetTopLeftCheckState();
  79. }
  80. }*/
  81. }
  82. protected override void OnLayout(LayoutEventArgs e)
  83. {
  84. int buttonWidth;
  85. if (this.toolStripEx.Items.Count > 0)
  86. {
  87. buttonWidth = this.toolStripEx.Items[0].Width;
  88. }
  89. else
  90. {
  91. buttonWidth = 0;
  92. }
  93. this.toolStripEx.Width =
  94. this.toolStripEx.Padding.Left +
  95. (buttonWidth * tbWidth) +
  96. (this.toolStripEx.Margin.Horizontal * tbWidth) +
  97. this.toolStripEx.Padding.Right;
  98. this.toolStripEx.Height = this.toolStripEx.GetPreferredSize(this.toolStripEx.Size).Height;
  99. this.Width = this.toolStripEx.Width + this.onePxSpacingLeft.Width;
  100. this.Height = this.toolStripEx.Height;
  101. base.OnLayout(e);
  102. }
  103. protected override void Dispose(bool disposing)
  104. {
  105. if (disposing)
  106. {
  107. if (components != null)
  108. {
  109. components.Dispose();
  110. components = null;
  111. }
  112. }
  113. base.Dispose(disposing);
  114. }
  115. private void InitializeComponent()
  116. {
  117. this.toolStripEx = new ToolStripEx();
  118. this.onePxSpacingLeft = new Control();
  119. this.SuspendLayout();
  120. //
  121. // toolStripEx
  122. //
  123. this.toolStripEx.Dock = System.Windows.Forms.DockStyle.Top;
  124. this.toolStripEx.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
  125. this.toolStripEx.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.Flow;
  126. this.toolStripEx.ItemClicked += new ToolStripItemClickedEventHandler(ToolStripEx_ItemClicked);
  127. this.toolStripEx.Name = "toolStripEx";
  128. this.toolStripEx.AutoSize = true;
  129. this.toolStripEx.RelinquishFocus += new EventHandler(ToolStripEx_RelinquishFocus);
  130. //
  131. // onePxSpacingLeft
  132. //
  133. this.onePxSpacingLeft.Dock = System.Windows.Forms.DockStyle.Left;
  134. this.onePxSpacingLeft.Width = 1;
  135. this.onePxSpacingLeft.Name = "onePxSpacingLeft";
  136. //
  137. // MainToolBar
  138. //
  139. this.Controls.Add(this.toolStripEx);
  140. this.Controls.Add(this.onePxSpacingLeft);
  141. this.AutoScaleDimensions = new SizeF(96F, 96F);
  142. this.AutoScaleMode = AutoScaleMode.Dpi;
  143. this.Name = "MainToolBar";
  144. this.Size = new System.Drawing.Size(48, 328);
  145. this.ResumeLayout(false);
  146. }
  147. public event EventHandler RelinquishFocus;
  148. private void OnRelinquishFocus()
  149. {
  150. if (RelinquishFocus != null)
  151. {
  152. RelinquishFocus(this, EventArgs.Empty);
  153. }
  154. }
  155. private void ToolStripEx_RelinquishFocus(object sender, EventArgs e)
  156. {
  157. OnRelinquishFocus();
  158. }
  159. private void ToolStripEx_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  160. {
  161. /*if (e.ClickedItem.GetType() != typeof(ToolStripButton))
  162. {
  163. return;
  164. }
  165. ToolStripItem[] menu = this.appWorkspace.ToolBar.MainMenu.Items.Find(e.ClickedItem.Tag.ToString(), true);
  166. if (menu != null && menu.Length > 0)
  167. {
  168. if (menu != null && menu.Length > 0)
  169. {
  170. if (((PdnMenuItem)menu[0]).canChecked)
  171. ((ToolStripButton)e.ClickedItem).Checked = !((ToolStripButton)e.ClickedItem).Checked;
  172. ((PdnMenuItem)menu[0]).PerformClick();
  173. appWorkspace.UpdateBottomButtonSelectionStatus();
  174. }
  175. }*/
  176. }
  177. private string type;
  178. private bool check;
  179. public void RefreshBtnSelect(bool check, string type)
  180. {
  181. this.type = type;
  182. this.check = check;
  183. if (toolStripEx == null)
  184. return;
  185. for (int j = 0; j < this.toolStripEx.Items.Count; j++)
  186. {
  187. if (this.toolStripEx.Items[j] is ToolStripButton && ((ToolStripButton)this.toolStripEx.Items[j]).Tag.ToString().Equals(type))
  188. ((ToolStripButton)this.toolStripEx.Items[j]).Checked = check;
  189. }
  190. this.Refresh();
  191. }
  192. }
  193. }