PdnToolBar.cs 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786
  1. using PaintDotNet.Base.SettingModel;
  2. using PaintDotNet.Base.CommTool;
  3. using PaintDotNet.DbOpreate.DbBll;
  4. using PaintDotNet.DbOpreate.DbModel;
  5. using PaintDotNet.Menus;
  6. using PaintDotNet.SystemLayer;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Drawing;
  10. using System.Drawing.Drawing2D;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Windows.Forms;
  14. using System.Windows.Forms.Layout;
  15. using static PaintDotNet.Base.SettingModel.ToolbarModel;
  16. using PaintDotNet.Data.Param;
  17. using PaintDotNet.Annotation;
  18. using PaintDotNet.Annotation.Label;
  19. using PaintDotNet.Annotation.Enum;
  20. namespace PaintDotNet
  21. {
  22. internal class PdnToolBar : Control, IPaintBackground
  23. {
  24. private AppWorkspace appWorkspace;
  25. /// <summary>
  26. /// 主菜单
  27. /// </summary>
  28. private PdnMainMenu mainMenu;
  29. /// <summary>
  30. /// 自定义工具栏
  31. /// </summary>
  32. private ToolStripContainer toolStripContainer1;
  33. /// <summary>
  34. /// 自定义工具栏上的右键菜单
  35. /// </summary>
  36. private ContextMenuStrip contextMenuStrip;
  37. public ToolStrip[] toolStrips;
  38. private List<ToolStripComboBox> rulersComboBox = new List<ToolStripComboBox>();
  39. /// <summary>
  40. /// 工具栏
  41. /// </summary>
  42. private ToolbarModel toolbarModel = Startup.instance.toolbarModel;
  43. private int toolStripInitLayout = 10;
  44. /// <summary>
  45. /// 目前被改成tab的菜单了
  46. /// </summary>
  47. private OurDocumentStrip documentStrip;
  48. private OurToolStripRenderer otsr = new OurToolStripRenderer();
  49. private Bitmap copyedBitmap;//复制的图片
  50. private int nameNum = 0;//命名使用
  51. private class OurToolStripRenderer :
  52. ToolStripProfessionalRenderer
  53. {
  54. public OurToolStripRenderer()
  55. {
  56. RoundedEdges = false;
  57. }
  58. private void PaintBackground(Graphics g, Control control, Rectangle clipRect)
  59. {
  60. Control parent = control;
  61. IPaintBackground asIpb = null;
  62. while (true)
  63. {
  64. parent = parent.Parent;
  65. if (parent == null)
  66. {
  67. break;
  68. }
  69. asIpb = parent as IPaintBackground;
  70. if (asIpb != null)
  71. {
  72. break;
  73. }
  74. }
  75. if (asIpb != null)
  76. {
  77. Rectangle screenRect = control.RectangleToScreen(clipRect);
  78. Rectangle parentRect = parent.RectangleToClient(screenRect);
  79. int dx = parentRect.Left - clipRect.Left;
  80. int dy = parentRect.Top - clipRect.Top;
  81. g.TranslateTransform(-dx, -dy, MatrixOrder.Append);
  82. asIpb.PaintBackground(g, parentRect);
  83. g.TranslateTransform(dx, dy, MatrixOrder.Append);
  84. }
  85. }
  86. protected override void OnRenderToolStripPanelBackground(ToolStripPanelRenderEventArgs e)
  87. {
  88. PaintBackground(e.Graphics, e.ToolStripPanel, new Rectangle(new Point(0, 0), e.ToolStripPanel.Size));
  89. e.Handled = true;
  90. }
  91. protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
  92. {
  93. if (e.ToolStrip.GetType() != typeof(ToolStrip) &&
  94. e.ToolStrip.GetType() != typeof(ToolStripEx) &&
  95. e.ToolStrip.GetType() != typeof(PdnMainMenu))
  96. {
  97. base.OnRenderToolStripBackground(e);
  98. }
  99. else
  100. {
  101. PaintBackground(e.Graphics, e.ToolStrip, e.AffectedBounds);
  102. }
  103. }
  104. }
  105. private class OurDocumentStrip : DocumentStrip, IPaintBackground
  106. {
  107. public OurDocumentStrip(AppWorkspace appWorkspace) : base(appWorkspace)
  108. {
  109. }
  110. protected override void DrawItemBackground(Graphics g, Item item, Rectangle itemRect)
  111. {
  112. PaintBackground(g, itemRect);
  113. /**
  114. if (item.Image != null)
  115. {
  116. g.DrawImage(item.Image, new Point(0, 0));
  117. }
  118. else
  119. {
  120. PaintBackground(g, itemRect);
  121. }**/
  122. }
  123. public void PaintBackground(Graphics g, Rectangle clipRect)
  124. {
  125. IPaintBackground asIpb = this.Parent as IPaintBackground;
  126. if (asIpb != null)
  127. {
  128. Rectangle newClipRect = new Rectangle(
  129. clipRect.Left + Left, clipRect.Top + Top,
  130. clipRect.Width, clipRect.Height);
  131. g.TranslateTransform(-Left, -Top, MatrixOrder.Append);
  132. asIpb.PaintBackground(g, newClipRect);
  133. g.TranslateTransform(Left, Top, MatrixOrder.Append);
  134. }
  135. }
  136. }
  137. public void PaintBackground(Graphics g, Rectangle clipRect)
  138. {
  139. if (clipRect.Width > 0 && clipRect.Height > 0)
  140. {
  141. Color backColor = ProfessionalColors.MenuStripGradientEnd;
  142. using (SolidBrush brush = new SolidBrush(backColor))
  143. {
  144. g.FillRectangle(brush, clipRect.X, clipRect.Y, clipRect.Width, clipRect.Height);
  145. }
  146. }
  147. }
  148. public AppWorkspace AppWorkspace
  149. {
  150. get
  151. {
  152. return this.appWorkspace;
  153. }
  154. set
  155. {
  156. this.appWorkspace = value;
  157. this.mainMenu.AppWorkspace = value;
  158. }
  159. }
  160. public PdnMainMenu MainMenu
  161. {
  162. get
  163. {
  164. return this.mainMenu;
  165. }
  166. }
  167. public DocumentStrip DocumentStrip
  168. {
  169. get
  170. {
  171. return this.documentStrip;
  172. }
  173. }
  174. public PdnToolBar(AppWorkspace appWorkspace)
  175. {
  176. this.appWorkspace = appWorkspace;
  177. SuspendLayout();
  178. InitializeComponent();
  179. InitializeContextMenuStrip();
  180. this.otsr = new OurToolStripRenderer();
  181. this.mainMenu.Renderer = otsr;
  182. ResumeLayout(true);
  183. }
  184. public void InitializeContextMenuStrip()
  185. {
  186. this.contextMenuStrip.Items.Clear();
  187. foreach (Flow flow in Startup.instance.toolbarModel.Flows)
  188. {
  189. ToolStripMenuItem toolStripMenuItem = new ToolStripMenuItem();
  190. toolStripMenuItem.Text = flow.Name;
  191. toolStripMenuItem.Checked = flow.Show;
  192. this.contextMenuStrip.Items.Add(toolStripMenuItem);
  193. }
  194. }
  195. private void contextMenuStripItem_Click(object sender, ToolStripItemClickedEventArgs e)
  196. {
  197. bool ShowFlag = !((ToolStripMenuItem)e.ClickedItem).Checked;
  198. ((ToolStripMenuItem)e.ClickedItem).Checked = ShowFlag;
  199. Flow flow = Startup.instance.toolbarModel.Flows.Find(a => a.Name.Equals(e.ClickedItem.Text));
  200. if(flow!=null)
  201. {
  202. flow.Show = ShowFlag;
  203. string userInfoXml = XmlSerializeHelper.XmlSerialize<ToolbarModel>(Startup.instance.toolbarModel);
  204. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Toolbar.xml";
  205. FileOperationHelper.WriteStringToFile(userInfoXml, filePath, FileMode.Create);
  206. Control[] control = this.toolStripContainer1.TopToolStripPanel.Controls.Find(flow.Key, true);
  207. if (control != null && control.Length > 0)
  208. {
  209. control[0].Visible = ShowFlag;
  210. }
  211. }
  212. }
  213. /// <summary>
  214. /// 刷新自定义工具栏的列表内容-标尺标定
  215. /// </summary>
  216. public void refreshRulersComboBoxList()//###2
  217. {
  218. List<mic_rulers> list = Startup.instance.mic_rulersAll;
  219. string rulerName = "";
  220. if (list != null)
  221. {
  222. for (int ruleI = 0; ruleI < list.Count; ruleI++)
  223. {
  224. mic_rulers rule = list[ruleI];
  225. int rulid = rule.id;
  226. if (rulid == Startup.instance.configModel.RulerId)
  227. {
  228. rulerName = rule.ruler_name;
  229. break;
  230. }
  231. }
  232. }
  233. foreach (ToolStripComboBox comboBox in rulersComboBox)
  234. {
  235. comboBox.Items.Clear();
  236. if (list != null)
  237. {
  238. for (int ruleI = 0; ruleI < list.Count; ruleI++)
  239. {
  240. mic_rulers rule = list[ruleI];
  241. comboBox.Items.Add(rule.ruler_name);
  242. //if (Startup.instance.configModel != null)
  243. //{
  244. // if (Startup.instance.configModel.RulerId == rule.id)
  245. // {
  246. // zoomComboBox.Text = rule.ruler_name;// "newText";
  247. // }
  248. //}
  249. }
  250. }
  251. else
  252. continue;
  253. for (int i = 0; i < comboBox.Items.Count; i++)
  254. {
  255. if (rulerName.Equals(comboBox.Items[i].ToString()))
  256. {
  257. comboBox.SelectedIndex = i;
  258. }
  259. }
  260. }
  261. }
  262. /// <summary>
  263. /// 刷新自定义工具栏的激活标尺-标尺标定
  264. /// </summary>
  265. public void refreshRulersComboBoxActive()//###1
  266. {
  267. foreach (ToolStripComboBox comboBox in rulersComboBox)
  268. {
  269. string rulerName = "";
  270. List<mic_rulers> list = Startup.instance.mic_rulersAll;
  271. if (list != null)
  272. {
  273. for (int ruleI = 0; ruleI < list.Count; ruleI++)
  274. {
  275. mic_rulers rule = list[ruleI];
  276. int rulid = rule.id;
  277. if (rulid == Startup.instance.configModel.RulerId)
  278. {
  279. rulerName = rule.ruler_name;
  280. break;
  281. }
  282. }
  283. }
  284. for (int i = 0; i < comboBox.Items.Count; i++)
  285. {
  286. if (rulerName.Equals(comboBox.Items[i].ToString()))
  287. {
  288. comboBox.SelectedIndex = i;
  289. }
  290. }
  291. }
  292. }
  293. /// <summary>
  294. /// 布局自定义工具栏
  295. /// </summary>
  296. /// <param name="toReset"></param>
  297. /// <param name="refreshFlag">1 添加 2删除 3移出 4向上移动 5向下移动 6添加分割线【 7添加新的节点】</param>
  298. public void test1(bool toReset, int refreshFlag = 0, string toolStripContrainerName = null, int toolStripItemIndex = 0, string nodeName = null, string nodeText = null, int nodeTag = 0)
  299. {
  300. if (toReset && refreshFlag > 0 && refreshFlag < 7)
  301. {
  302. this.toolbarModel = Startup.instance.toolbarModel;
  303. if (toolbarModel == null || toolbarModel.Flows.Count == 0)
  304. {
  305. this.toolStripContainer1.TopToolStripPanel.Controls.Clear();
  306. return;
  307. }
  308. int toolCount = toolbarModel.Flows.Count;
  309. for (int j = toolbarModel.Flows.Count - 1; j >= 0; j--)
  310. {
  311. Flow flowJ = toolbarModel.Flows[j];
  312. if (flowJ.Menus.Count == 0)
  313. {
  314. toolCount -= 1;
  315. }
  316. }
  317. if (toolCount == 0)
  318. {
  319. this.toolStripContainer1.TopToolStripPanel.Controls.Clear();
  320. return;
  321. }
  322. bool addSuccess = false;
  323. foreach (ToolStrip toolStripContrainer in this.toolStripContainer1.TopToolStripPanel.Controls)
  324. {
  325. if (toolStripContrainer.Name.Equals(toolStripContrainerName))
  326. {
  327. if (refreshFlag == 6)// 6添加分割线
  328. {
  329. ToolStripItem[] buttons = new ToolStripItem[toolStripContrainer.Items.Count + 1];
  330. for (int itemIndex = 0; itemIndex < toolStripContrainer.Items.Count; itemIndex++)
  331. {
  332. if (itemIndex < toolStripItemIndex)
  333. buttons[itemIndex] = toolStripContrainer.Items[itemIndex];
  334. else if (itemIndex == toolStripItemIndex)
  335. {
  336. buttons[itemIndex] = new ToolStripSeparator();
  337. buttons[itemIndex + 1] = toolStripContrainer.Items[itemIndex];
  338. }
  339. else
  340. buttons[itemIndex + 1] = toolStripContrainer.Items[itemIndex];
  341. }
  342. toolStripContrainer.Items.Clear();
  343. toolStripContrainer.Items.AddRange(buttons);
  344. }
  345. else if (refreshFlag == 1)// 1 添加
  346. {
  347. addSuccess = true;
  348. //this.toolStripContainer1.TopToolStripPanel.Controls.Remove(toolStripContrainer);
  349. int toAddCount = 1;
  350. if (nodeName.Equals("Script"))//脚本列表
  351. {
  352. List<mic_script> list = mic_script_BLL.FindAll();
  353. toAddCount += (list.Count - 1);
  354. }
  355. else if (nodeName.Equals("SubRulerCalibration"))
  356. {
  357. toAddCount += 1;
  358. }
  359. ToolStripItem[] buttons = new ToolStripItem[toolStripContrainer.Items.Count + toAddCount];
  360. for (int itemIndex = 0; itemIndex < toolStripContrainer.Items.Count; itemIndex++)
  361. {
  362. buttons[itemIndex] = toolStripContrainer.Items[itemIndex];
  363. }
  364. int i = toolStripContrainer.Items.Count;
  365. int index = toolStripContrainer.Items.Count;// 0;
  366. {
  367. ToolStripButton button = new ToolStripButton();
  368. int imageIndex = -1;
  369. //if (flowJ.Menus[i].Description.Equals("SeparateLine"))
  370. //{
  371. // ToolStripSeparator separator0 = new ToolStripSeparator();
  372. // buttons[index] = separator0;
  373. // continue;
  374. //}
  375. ToolStripItem[] items = this.MainMenu.Items.Find(nodeName, true);
  376. if (items != null && items.Length > 0)
  377. {
  378. if (((PdnMenuItem)(items[0])).Image != null)
  379. imageIndex = toolStripContrainer.ImageList.Images.Add(((PdnMenuItem)(items[0])).Image, toolStripContrainer.ImageList.TransparentColor);
  380. else
  381. imageIndex = toolStripContrainer.ImageList.Images.Add(new Bitmap(16, 16), toolStripContrainer.ImageList.TransparentColor);
  382. }
  383. else
  384. {
  385. imageIndex = toolStripContrainer.ImageList.Images.Add(new Bitmap(16, 16), toolStripContrainer.ImageList.TransparentColor);
  386. }
  387. button.ImageIndex = imageIndex;
  388. button.Tag = nodeName;// flowJ.Menus[i].Description;
  389. button.ToolTipText = nodeText;// flowJ.Menus[i].Name;
  390. button.Text = nodeText;// flowJ.Menus[i].Name;
  391. button.TextImageRelation = TextImageRelation.ImageAboveText;
  392. //..Script
  393. if (nodeName.Equals("Script"))//脚本列表
  394. {
  395. List<mic_script> list = mic_script_BLL.FindAll();
  396. for (int itemI = 0; itemI < list.Count - 1; itemI++)
  397. {
  398. var itemSS = list[itemI];
  399. ToolStripButton unitLabel = new ToolStripButton();
  400. unitLabel.Text = itemSS.name;
  401. unitLabel.TextImageRelation = TextImageRelation.ImageBeforeText;
  402. unitLabel.Padding = new Padding(2, 20 - unitLabel.Height / 2, 0, 20 - unitLabel.Height / 2);
  403. //unitLabel.Tag = "Script_" + itemSS.id;
  404. unitLabel.Name = "" + itemSS.id;
  405. buttons[index] = unitLabel;
  406. index++;
  407. }
  408. //unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
  409. var item = list[list.Count - 1];
  410. ToolStripButton unitsLabel = new ToolStripButton();
  411. unitsLabel.Text = item.name;
  412. unitsLabel.TextImageRelation = TextImageRelation.ImageBeforeText;
  413. unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
  414. unitsLabel.Name = "" + item.id;
  415. buttons[index] = unitsLabel;
  416. }
  417. else if (nodeName.Equals("SubRulerCalibration"))
  418. {
  419. ToolStripLabel unitsLabel = new ToolStripLabel();
  420. unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
  421. unitsLabel.Text = "标尺:";
  422. buttons[index] = unitsLabel;
  423. index++;
  424. ToolStripComboBox zoomComboBox = new ToolStripComboBox();
  425. zoomComboBox.Tag = i;
  426. zoomComboBox.Size = new Size(100/*75*/, zoomComboBox.Height);
  427. zoomComboBox.Padding = new Padding(0, 20 - zoomComboBox.Height / 2, 2, 20 - zoomComboBox.Height / 2);
  428. zoomComboBox.MaxDropDownItems = 99;
  429. zoomComboBox.SelectedIndexChanged += ZoomComboBox_SelectedIndexChanged;
  430. List<mic_rulers> list = mic_rulers_BLL.FindAll();
  431. if (list != null)
  432. {
  433. for (int ruleI = 0; ruleI < list.Count; ruleI++)
  434. {
  435. mic_rulers rule = list[ruleI];
  436. zoomComboBox.Items.Add(rule.ruler_name);
  437. if (Startup.instance.configModel != null)
  438. {
  439. if (Startup.instance.configModel.RulerId == rule.id)
  440. {
  441. zoomComboBox.Text = rule.ruler_name;// "newText";
  442. }
  443. }
  444. }
  445. }
  446. //if (zoomComboBox.Text == null || zoomComboBox.Text.Equals(""))
  447. //{
  448. // zoomComboBox.Text = "请选择";
  449. //}
  450. rulersComboBox.Add(zoomComboBox);
  451. buttons[index] = zoomComboBox;
  452. zoomComboBox.ComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
  453. zoomComboBox.BackColor = SystemColors.Window;
  454. }
  455. else
  456. {
  457. buttons[index] = button;
  458. }
  459. }
  460. //toolStripEx.ItemClicked += new ToolStripItemClickedEventHandler(ToolStripEx_ItemClicked);
  461. //toolStripEx.ItemRemoved += ToolStripEx_ItemRemoved;
  462. //toolStripEx.EndDrag += ToolStripEx_DragDrop1;
  463. //toolStripEx.AllowDrop = false;
  464. //toolStripEx.AllowMerge = false;
  465. //toolStripEx.Height = 40;
  466. //toolStripEx.Items.AddRange(buttons);
  467. toolStripContrainer.Items.Clear();
  468. toolStripContrainer.Items.AddRange(buttons);
  469. appWorkspace.SetTopLeftCheckState();
  470. }
  471. else if (refreshFlag == 2)// 2删除
  472. {
  473. this.toolStripContainer1.TopToolStripPanel.Controls.Remove(toolStripContrainer);
  474. }
  475. else if (refreshFlag == 3)// 3移出
  476. {
  477. if (toolStripItemIndex > 0 && toolStripContrainer.Items.Count > toolStripItemIndex)
  478. {
  479. for (int itemIndex = 0; itemIndex < toolStripItemIndex/*toolStripContrainer.Items.Count*/; itemIndex++)
  480. {
  481. //#######################################
  482. }
  483. }
  484. //int toAddCount = 1;
  485. //if (nodeName.Equals("Script"))//脚本列表
  486. //{
  487. // List<mic_script> list = mic_script_BLL.FindAll();
  488. // toAddCount += (list.Count - 1);
  489. //}
  490. //else if (nodeName.Equals("SubRulerCalibration"))
  491. //{
  492. // toAddCount += 1;
  493. //}
  494. //ToolStripItem[] buttons = new ToolStripItem[toolStripContrainer.Items.Count + toAddCount];
  495. if (toolStripContrainer.Items.Count > toolStripItemIndex)
  496. toolStripContrainer.Items.RemoveAt(toolStripItemIndex);
  497. if (toolStripContrainer.Items.Count == 0)
  498. this.toolStripContainer1.TopToolStripPanel.Controls.Remove(toolStripContrainer);
  499. }
  500. else if (refreshFlag == 4)// 4向上移动
  501. {
  502. //if (toolStripContrainer.Items.Count > toolStripItemIndex)
  503. // toolStripContrainer.Items.RemoveAt(toolStripItemIndex);
  504. if (toolStripItemIndex > 0 && toolStripContrainer.Items.Count > toolStripItemIndex)
  505. {
  506. ToolStripItem[] buttons = new ToolStripItem[toolStripContrainer.Items.Count];
  507. for (int itemIndex = 0; itemIndex < toolStripContrainer.Items.Count; itemIndex++)
  508. {
  509. if (itemIndex == toolStripItemIndex)
  510. {
  511. buttons[toolStripItemIndex] = toolStripContrainer.Items[toolStripItemIndex - 1];
  512. }
  513. else if (itemIndex == toolStripItemIndex - 1)
  514. {
  515. buttons[toolStripItemIndex - 1] = toolStripContrainer.Items[toolStripItemIndex];
  516. }
  517. else
  518. {
  519. buttons[itemIndex] = toolStripContrainer.Items[itemIndex];
  520. }
  521. }
  522. //ToolStripItem preStripItem = toolStripContrainer.Items[toolStripItemIndex - 1];
  523. //toolStripContrainer.Items.Insert(toolStripItemIndex + 1, preStripItem);
  524. //toolStripContrainer.Items.RemoveAt(toolStripItemIndex - 1);
  525. toolStripContrainer.Items.Clear();
  526. toolStripContrainer.Items.AddRange(buttons);
  527. }
  528. //int index = this.treeViewLeft.SelectedNode.Parent.Nodes.IndexOf(this.treeViewLeft.SelectedNode);
  529. //if (index > 0)
  530. //{
  531. // TreeNode prenode = (TreeNode)this.treeViewLeft.SelectedNode.PrevNode.Clone();
  532. // this.treeViewLeft.SelectedNode.Parent.Nodes.Insert(index + 1, prenode);
  533. // this.treeViewLeft.Nodes.Remove(this.treeViewLeft.SelectedNode.PrevNode);
  534. //}
  535. }
  536. else if (refreshFlag == 5)// 5向下移动
  537. {
  538. if (toolStripItemIndex < toolStripContrainer.Items.Count - 1 && toolStripContrainer.Items.Count > toolStripItemIndex)
  539. {
  540. ToolStripItem[] buttons = new ToolStripItem[toolStripContrainer.Items.Count];
  541. for (int itemIndex = 0; itemIndex < toolStripContrainer.Items.Count; itemIndex++)
  542. {
  543. if (itemIndex == toolStripItemIndex)
  544. {
  545. buttons[toolStripItemIndex] = toolStripContrainer.Items[toolStripItemIndex + 1];
  546. }
  547. else if (itemIndex == toolStripItemIndex + 1)
  548. {
  549. buttons[toolStripItemIndex + 1] = toolStripContrainer.Items[toolStripItemIndex];
  550. }
  551. else
  552. {
  553. buttons[itemIndex] = toolStripContrainer.Items[itemIndex];
  554. }
  555. }
  556. toolStripContrainer.Items.Clear();
  557. toolStripContrainer.Items.AddRange(buttons);
  558. }
  559. }
  560. break;
  561. }
  562. }
  563. if (!addSuccess && refreshFlag == 1)// 1 添加
  564. {
  565. addSuccess = true;
  566. }
  567. else
  568. return;
  569. }
  570. if (toReset)
  571. {
  572. this.toolStripContainer1.TopToolStripPanel.ControlRemoved -= TopToolStripPanel_ControlRemoved;
  573. this.toolStripContainer1.TopToolStripPanel.DragDrop -= TopToolStripPanel_DragDrop;
  574. this.toolStripContainer1.TopToolStripPanel.DragLeave -= TopToolStripPanel_DragLeave;
  575. toolbarModel = Startup.instance.toolbarModel;
  576. }
  577. this.toolStripContainer1.TopToolStripPanel.Controls.Clear();
  578. this.toolStripContainer1.SuspendLayout();
  579. this.toolStripContainer1.TopToolStripPanel.SuspendLayout();
  580. this.toolStripContainer1.LeftToolStripPanel.SuspendLayout();
  581. this.toolStripContainer1.RightToolStripPanel.SuspendLayout();
  582. this.toolStripContainer1.BottomToolStripPanel.SuspendLayout();
  583. if (this.toolStripContainer1.TopToolStripPanel.Controls.Count == 0)
  584. SetCustomizeTools();
  585. //先将location值不为-100的菜单显示出来(初始值设置-100)
  586. int heightRow = 0;// -1;// 0;
  587. int widthRow1 = 0;// -1;// 0;
  588. //for (int j = 0; j < Startup.instance.toolbarLocationModel.Flows.Count; j++)
  589. for (int j = 0; j < Startup.instance.toolbarModel.Flows.Count; j++)
  590. {
  591. //ToolbarLocationModel.Flow flowJ = Startup.instance.toolbarLocationModel.Flows[j];
  592. ToolbarModel.Flow flowJ = Startup.instance.toolbarModel.Flows[j];
  593. if (flowJ.X > -100 && flowJ.Y > -100)
  594. {
  595. if (flowJ.Y > heightRow || (flowJ.Y == heightRow && flowJ.X >= widthRow1))
  596. {
  597. Control[] toolStripTemp = /*(ToolStrip[])*/this.toolStripContainer1.TopToolStripPanel.Controls.Find(flowJ.Key, true);
  598. //ToolStrip toolStripEx = (ToolStrip)this.toolStripContainer1.TopToolStripPanel.Controls.Find(flowJ.Key, true)[0];
  599. if (toolStripTemp != null && toolStripTemp.Length > 0/*toolStripEx == null*/)
  600. {
  601. ToolStrip toolStripEx = (ToolStrip)toolStripTemp[0];
  602. heightRow = flowJ.Y;
  603. widthRow1 = flowJ.X + toolStripEx.PreferredSize.Width + toolStripEx.Margin.Horizontal + 1;
  604. }
  605. else
  606. {
  607. if (toolStrips != null && toolStrips.Length > 0)
  608. {
  609. ToolStrip toolStripEx = new List<ToolStrip>(toolStrips).Find(a => a.Name.Equals(flowJ.Key));// toolStrips.Find(a => a.Key.Equals(toolStripEx.Name));
  610. if (toolStripEx != null)
  611. {
  612. heightRow = flowJ.Y;
  613. widthRow1 = flowJ.X + toolStripEx.PreferredSize.Width + toolStripEx.Margin.Horizontal + 1;
  614. continue;
  615. }
  616. }
  617. heightRow = flowJ.Y;
  618. widthRow1 = flowJ.X + 1;
  619. }
  620. }
  621. }
  622. }
  623. if (toolStrips != null && toolStrips.Length > 0)
  624. {
  625. for (int j = 0; j < toolStrips.Length; j++)
  626. {
  627. //Base.SettingModel.ToolbarLocationModel.Flow flowJ = toolbarLocationModel.Flows.Find(a => a.Key.Equals(toolStrips[j].Name));
  628. Base.SettingModel.ToolbarModel.Flow flowJ = toolbarModel.Flows.Find(a => a.Key.Equals(toolStrips[j].Name));
  629. if (flowJ.X == -100 || flowJ.Y == -100)
  630. {
  631. if (widthRow1 < ClientSize.Width || ClientSize.Width == 0)
  632. {
  633. toolStrips[j].Location = new Point(widthRow1/*lastToolStripEx.Right + 1*/, heightRow/*lastToolStripEx.Top*/);
  634. widthRow1 = widthRow1 + toolStrips[j].PreferredSize.Width + toolStrips[j].Margin.Horizontal + 1;
  635. }
  636. else
  637. {
  638. heightRow += 40;// 38;// 39;
  639. toolStrips[j].Location = new Point(0, heightRow/*lastToolStripEx.Bottom*/);
  640. widthRow1 = 0/*toolStripEx.Left*/ + toolStrips[j].PreferredSize.Width + toolStrips[j].Margin.Horizontal;
  641. }
  642. }
  643. else
  644. {
  645. toolStrips[j].Location = new Point(flowJ.X, flowJ.Y);
  646. }
  647. }
  648. }
  649. if(this.toolStripContainer1.TopToolStripPanel.Controls.Count ==0 && toolStrips != null)//数组的判定条件为后添加,不确定是否正确8.12
  650. this.toolStripContainer1.TopToolStripPanel.Controls.AddRange(toolStrips);
  651. this.toolStripContainer1.TopToolStripPanel.ResumeLayout();
  652. this.toolStripContainer1.LeftToolStripPanel.ResumeLayout();
  653. this.toolStripContainer1.RightToolStripPanel.ResumeLayout();
  654. this.toolStripContainer1.BottomToolStripPanel.ResumeLayout();
  655. this.toolStripContainer1.ResumeLayout();
  656. }
  657. protected override void OnLayout(LayoutEventArgs e)
  658. {
  659. bool plentyWidthBefore = (this.mainMenu.Width >= this.mainMenu.PreferredSize.Width);
  660. if (!plentyWidthBefore)
  661. {
  662. UI.SuspendControlPainting(this);
  663. }
  664. else
  665. {
  666. UI.SuspendControlPainting(this.documentStrip);
  667. }
  668. this.mainMenu.Location = new Point(0, 0);
  669. this.mainMenu.Height = this.mainMenu.PreferredSize.Height;
  670. this.toolStripContainer1.Location = new Point(0, this.mainMenu.Bottom);
  671. this.toolStripContainer1.Margin = new Padding(-5);
  672. this.toolStripContainer1.TopToolStripPanel.Margin = new Padding(-5);
  673. this.toolStripContainer1.TopToolStripPanel.RowMargin = new Padding(0/*-1*/);
  674. this.mainMenu.Padding = new Padding(0, this.mainMenu.Padding.Top, 0, this.mainMenu.Padding.Bottom);
  675. this.documentStrip.Width = ClientSize.Width;
  676. this.documentStrip.Anchor = AnchorStyles.Left | AnchorStyles.Right;
  677. this.documentStrip.Location = new Point(0, this.toolStripContainer1.Bottom);
  678. // Finish setting up widths and heights
  679. int oldDsHeight = this.documentStrip.Height;
  680. this.documentStrip.Height = 25;
  681. int tsWidth = ClientSize.Width;
  682. this.mainMenu.Width = tsWidth;
  683. if(tsWidth>0)
  684. {
  685. this.toolStripContainer1.TopToolStripPanel.Width = tsWidth;
  686. this.toolStripContainer1.Width = tsWidth;
  687. }
  688. this.Height = this.documentStrip.Bottom;
  689. this.documentStrip.PerformLayout();
  690. if (!plentyWidthBefore)
  691. {
  692. UI.ResumeControlPainting(this);
  693. Invalidate(true);
  694. }
  695. else
  696. {
  697. UI.ResumeControlPainting(this.documentStrip);
  698. this.documentStrip.Invalidate(true);
  699. }
  700. if (this.documentStrip.Width == 0)
  701. {
  702. this.mainMenu.Invalidate();
  703. }
  704. if (oldDsHeight != this.documentStrip.Height)
  705. {
  706. this.documentStrip.RefreshAllThumbnails();
  707. }
  708. base.OnLayout(e);
  709. }
  710. protected override void OnResize(EventArgs e)
  711. {
  712. PerformLayout();
  713. base.OnResize(e);
  714. }
  715. private void InitializeComponent()
  716. {
  717. this.SuspendLayout();
  718. this.mainMenu = new PdnMainMenu();
  719. this.toolStripContainer1 = new ToolStripContainer();
  720. this.documentStrip = new OurDocumentStrip(this.appWorkspace);
  721. this.toolStripContainer1.SuspendLayout();
  722. this.toolStripContainer1.TopToolStripPanel.SuspendLayout();
  723. //
  724. // mainMenu
  725. //
  726. this.mainMenu.Name = "mainMenu";
  727. this.mainMenu.ContextMenuStrip = this.contextMenuStrip;
  728. this.mainMenu.MouseClick += new System.Windows.Forms.MouseEventHandler(this.frmContextmenu_MouseClick);
  729. //
  730. // 右键菜单
  731. //
  732. this.contextMenuStrip = new ContextMenuStrip();
  733. this.contextMenuStrip.ItemClicked += new ToolStripItemClickedEventHandler(this.contextMenuStripItem_Click);
  734. //
  735. // toolStripContainer1.TopToolStripPanel
  736. //
  737. this.toolStripContainer1.AllowDrop = true;
  738. this.toolStripContainer1.BottomToolStripPanelVisible = false;
  739. this.toolStripContainer1.LeftToolStripPanelVisible = false;
  740. this.toolStripContainer1.RightToolStripPanelVisible = false;
  741. this.toolStripContainer1.TopToolStripPanel.Padding = new Padding(0, -20/*Top*/, 0, -2/*Bottom*/);
  742. this.toolStripContainer1.TopToolStripPanel.AllowDrop = true;
  743. this.toolStripContainer1.Name = "toolStripContainer1";
  744. this.toolStripContainer1.TabIndex = 13;
  745. this.toolStripContainer1.Text = "toolStripContainer1";
  746. this.toolStripContainer1.TopToolStripPanel.SizeChanged += new System.EventHandler(this.panel1_SizeChanged);
  747. this.toolStripContainer1.ContextMenuStrip = this.contextMenuStrip;
  748. this.toolStripContainer1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.frmContextmenu_MouseClick);
  749. //
  750. // documentStrip
  751. //
  752. this.documentStrip.AutoSize = false;
  753. this.documentStrip.Name = "documentStrip";
  754. this.documentStrip.TabIndex = 5;
  755. this.documentStrip.ShowScrollButtons = true;
  756. this.documentStrip.DocumentListChanged += new EventHandler(DocumentStrip_DocumentListChanged);
  757. this.documentStrip.DocumentClicked += DocumentStrip_DocumentClicked;
  758. this.documentStrip.ManagedFocus = true;
  759. //
  760. // PdnToolBar
  761. //
  762. this.Controls.Add(this.documentStrip);
  763. //this.Controls.Add(this.toolStripPanel);
  764. this.Controls.Add(this.toolStripContainer1);
  765. this.Controls.Add(this.mainMenu);
  766. this.toolStripContainer1.TopToolStripPanel.ResumeLayout(false);
  767. this.toolStripContainer1.TopToolStripPanel.PerformLayout();
  768. this.toolStripContainer1.ResumeLayout(false);
  769. this.toolStripContainer1.PerformLayout();
  770. this.ResumeLayout(false);
  771. }
  772. private void frmContextmenu_MouseClick(object sender, MouseEventArgs e)
  773. {
  774. if (e.Button == MouseButtons.Right)
  775. {
  776. this.contextMenuStrip.Show(MousePosition.X, MousePosition.Y);
  777. }
  778. }
  779. public void SetCustomizeTools()
  780. {
  781. if (toolbarModel == null || toolbarModel.Flows.Count == 0)
  782. {
  783. return;
  784. }
  785. int toolCount = toolbarModel.Flows.Count;
  786. for (int j = toolbarModel.Flows.Count - 1; j >= 0; j--)
  787. {
  788. Flow flowJ = toolbarModel.Flows[j];
  789. if (flowJ.Menus.Count == 0)// || !flowJ.Show
  790. {
  791. toolCount -= 1;
  792. }
  793. }
  794. if (toolCount == 0)
  795. {
  796. return;
  797. }
  798. toolStrips = new ToolStrip[toolCount];
  799. int t = 0;
  800. for (int j = toolbarModel.Flows.Count - 1; j >= 0; j--)
  801. {
  802. Flow flowJ = toolbarModel.Flows[j];
  803. /*if(!flowJ.Show)
  804. {
  805. continue;
  806. }*/
  807. if (flowJ.Menus.Count == 0)
  808. {
  809. continue;
  810. }
  811. ToolStrip toolStripEx = new ToolStrip();//Ex
  812. ImageList imageList = new ImageList();
  813. imageList.ColorDepth = ColorDepth.Depth32Bit;
  814. imageList.TransparentColor = Utility.TransparentKey;
  815. toolStripEx.ImageList = imageList;
  816. toolStripEx.Name = flowJ.Key;// "key_" + j;
  817. //Base.SettingModel.ToolbarLocationModel.Flow flow = toolbarLocationModel.Flows.Find(a => a.Key.Equals(flowJ.Key/*"targetProcess"*/));
  818. ////ToolbarLocationModel.Flows.Find();
  819. //int locationX = flow.X;
  820. //int locationY = flow.Y;
  821. int buttonsCount = flowJ.Menus.Count;
  822. foreach (Flow.Item item in flowJ.Menus)
  823. {
  824. //..Script
  825. if (item.Description.Equals("Script"))//脚本列表
  826. {
  827. List<mic_script> list = mic_script_BLL.FindAll();
  828. //foreach (var item in list)
  829. //{
  830. // this.listBox1.Items.Add(item.name);
  831. //}
  832. buttonsCount += (list.Count - 1);
  833. }
  834. if (item.Description.Equals("SubRulerCalibration"))//标尺标定,标尺列表
  835. {
  836. buttonsCount += 1;
  837. }
  838. }
  839. ToolStripItem[] buttons = new ToolStripItem[buttonsCount/*flowJ.Menus.Count*/];
  840. int index = 0;
  841. for (int i = 0; i < flowJ.Menus.Count; i++, index++)
  842. {
  843. ToolStripButton button = new ToolStripButton();
  844. int imageIndex = -1;
  845. if (flowJ.Menus[i].Description.Equals("SeparateLine"))
  846. {
  847. ToolStripSeparator separator0 = new ToolStripSeparator();
  848. buttons[index] = separator0;
  849. continue;
  850. }
  851. ToolStripItem[] items = this.MainMenu.Items.Find(flowJ.Menus[i].Description, true);
  852. if (items != null && items.Length > 0)
  853. {
  854. if (((PdnMenuItem)(items[0])).Image != null)
  855. imageIndex = imageList.Images.Add(((PdnMenuItem)(items[0])).Image, imageList.TransparentColor);
  856. else
  857. imageIndex = imageList.Images.Add(new Bitmap(16, 16), imageList.TransparentColor);
  858. button.ToolTipText = ((PdnMenuItem)(items[0])).Text;
  859. button.Text = ((PdnMenuItem)(items[0])).Text;
  860. }
  861. else
  862. {
  863. imageIndex = imageList.Images.Add(new Bitmap(16, 16), imageList.TransparentColor);
  864. button.ToolTipText = flowJ.Menus[i].Name;// getShowName(Startup.instance.configModel.Language);
  865. button.Text = flowJ.Menus[i].Name;// getShowName(Startup.instance.configModel.Language);
  866. }
  867. button.ImageIndex = imageIndex;
  868. button.Tag = flowJ.Menus[i].Description;
  869. button.TextImageRelation = TextImageRelation.ImageAboveText;
  870. //..Script
  871. if (flowJ.Menus[i].Description.Equals("Script"))//脚本列表
  872. {
  873. List<mic_script> list = mic_script_BLL.FindAll();
  874. for (int itemI = 0; itemI < list.Count - 1; itemI++)
  875. {
  876. var itemSS = list[itemI];
  877. ToolStripButton unitLabel = new ToolStripButton();
  878. unitLabel.Text = itemSS.name;
  879. unitLabel.TextImageRelation = TextImageRelation.ImageBeforeText;
  880. unitLabel.Padding = new Padding(2, 20 - unitLabel.Height / 2, 0, 20 - unitLabel.Height / 2);
  881. //unitLabel.Tag = "Script_" + itemSS.id;
  882. unitLabel.Name = "" + itemSS.id;
  883. unitLabel.Enabled = Startup.getMenuIdVisible(flowJ.Menus[i].Id);
  884. buttons[index] = unitLabel;
  885. index++;
  886. }
  887. //unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
  888. var item = list[list.Count - 1];
  889. ToolStripButton unitsLabel = new ToolStripButton();
  890. unitsLabel.Text = item.name;
  891. unitsLabel.TextImageRelation = TextImageRelation.ImageBeforeText;
  892. unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
  893. unitsLabel.Name = "" + item.id;
  894. unitsLabel.Enabled = Startup.getMenuIdVisible(flowJ.Menus[i].Id);
  895. buttons[index] = unitsLabel;
  896. }
  897. else if (flowJ.Menus[i].Description.Equals("SubRulerCalibration"))
  898. {
  899. ToolStripLabel unitsLabel = new ToolStripLabel();
  900. unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
  901. unitsLabel.Text = "标尺:";
  902. unitsLabel.Enabled = Startup.getMenuIdVisible(flowJ.Menus[i].Id);
  903. buttons[index] = unitsLabel;
  904. index++;
  905. ToolStripComboBox zoomComboBox = new ToolStripComboBox();
  906. zoomComboBox.Tag = i;
  907. zoomComboBox.Size = new Size(100/*75*/, zoomComboBox.Height);
  908. zoomComboBox.Padding = new Padding(0, 20 - zoomComboBox.Height / 2, 2, 20 - zoomComboBox.Height / 2);
  909. zoomComboBox.MaxDropDownItems = 99;
  910. zoomComboBox.SelectedIndexChanged += ZoomComboBox_SelectedIndexChanged;
  911. List<mic_rulers> list = mic_rulers_BLL.FindAll();
  912. if (list != null)
  913. {
  914. for (int ruleI = 0; ruleI < list.Count; ruleI++)
  915. {
  916. mic_rulers rule = list[ruleI];
  917. zoomComboBox.Items.Add(rule.ruler_name);
  918. if (Startup.instance.configModel != null)
  919. {
  920. if (Startup.instance.configModel.RulerId == rule.id)
  921. {
  922. zoomComboBox.Text = rule.ruler_name;// "newText";
  923. }
  924. }
  925. }
  926. }
  927. //if (zoomComboBox.Text == null || zoomComboBox.Text.Equals(""))
  928. //{
  929. // zoomComboBox.Text = "请选择";
  930. //}
  931. rulersComboBox.Add(zoomComboBox);
  932. zoomComboBox.Enabled = Startup.getMenuIdVisible(flowJ.Menus[i].Id);
  933. buttons[index] = zoomComboBox;
  934. zoomComboBox.ComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
  935. zoomComboBox.BackColor = SystemColors.Window;
  936. }
  937. else
  938. {
  939. button.Enabled = Startup.getMenuIdVisible(flowJ.Menus[i].Id);
  940. buttons[index] = button;
  941. }
  942. }
  943. toolStripEx.ItemClicked += new ToolStripItemClickedEventHandler(ToolStripEx_ItemClicked);
  944. toolStripEx.ItemRemoved += ToolStripEx_ItemRemoved;
  945. toolStripEx.EndDrag += ToolStripEx_DragDrop1;
  946. toolStripEx.AllowDrop = false;
  947. toolStripEx.AllowMerge = false;
  948. toolStripEx.Height = 40;
  949. toolStripEx.Items.AddRange(buttons);
  950. toolStrips[t] = toolStripEx;
  951. toolStripEx.Visible = flowJ.Show;
  952. t++;
  953. }
  954. this.toolStripContainer1.TopToolStripPanel.ControlRemoved += TopToolStripPanel_ControlRemoved;
  955. this.toolStripContainer1.TopToolStripPanel.DragDrop += TopToolStripPanel_DragDrop;
  956. this.toolStripContainer1.TopToolStripPanel.DragLeave += TopToolStripPanel_DragLeave;
  957. }
  958. private void ZoomComboBox_SelectedIndexChanged(object sender, EventArgs e)
  959. {
  960. if (((ToolStripComboBox)sender).SelectedItem != null)
  961. {
  962. List<mic_rulers> list = Startup.instance.mic_rulersAll;
  963. if (list != null)
  964. {
  965. for (int ruleI = 0; ruleI < list.Count; ruleI++)
  966. {
  967. mic_rulers rule = list[ruleI];
  968. if (rule.ruler_name.Equals(((ToolStripComboBox)sender).SelectedItem.ToString()))
  969. {
  970. int rulid = rule.id;
  971. string rulerName2 = rule.ruler_name;
  972. if (rulid != Startup.instance.configModel.RulerId)
  973. {
  974. //设置当前选中标尺
  975. this.appWorkspace.SetActiveRulerIndex(((ToolStripComboBox)sender).SelectedIndex);
  976. //应用到当前
  977. this.appWorkspace.Widgets.RuleListForm.MenuSubApplyCurrent();
  978. //int oldId = Startup.instance.configModel.RulerId;
  979. ////激活当前标尺到configModel
  980. //Startup.instance.configModel.RulerId = rulid;
  981. ////保存xml文件
  982. //string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(Startup.instance.configModel);
  983. //string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml";
  984. //if (FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
  985. //{
  986. // //调用startup的方法
  987. // Startup.instance.InitRulerInfo();
  988. // Startup.instance.InitUnitInfo();
  989. // foreach (ToolStripComboBox comboBox in rulersComboBox)
  990. // {
  991. // if (((ToolStripComboBox)sender) == comboBox)
  992. // {
  993. // continue;
  994. // }
  995. // for (int i = 0; i < comboBox.Items.Count; i++)
  996. // {
  997. // if (rulerName2.Equals(comboBox.Items[i].ToString()))
  998. // {
  999. // comboBox.SelectedIndex = i;
  1000. // }
  1001. // }
  1002. // }
  1003. // //this.appWorkspace.RefreshActiveRuler();
  1004. //}
  1005. //else
  1006. //{
  1007. // Startup.instance.configModel.RulerId = oldId;
  1008. // MessageBox.Show("标尺激活失败");
  1009. //}
  1010. }
  1011. break;
  1012. }
  1013. }
  1014. }
  1015. }
  1016. }
  1017. private void ToolStripEx_DragDrop1(object sender, EventArgs e)
  1018. {
  1019. if (toolStripInitLayout < 3)//to 完善
  1020. {
  1021. return;
  1022. }
  1023. for (int i = 0; i < this.toolStripContainer1.TopToolStripPanel.Controls.Count; i++)
  1024. {
  1025. ToolStrip toolStripEx = (ToolStrip)this.toolStripContainer1.TopToolStripPanel.Controls[i];
  1026. Point point = toolStripEx.Location;
  1027. //Base.SettingModel.ToolbarLocationModel.Flow flowJ = toolbarLocationModel.Flows.Find(a => a.Key.Equals(toolStripEx.Name));
  1028. Base.SettingModel.ToolbarModel.Flow flowJ = toolbarModel.Flows.Find(a => a.Key.Equals(toolStripEx.Name));
  1029. flowJ.X = point.X;
  1030. flowJ.Y = point.Y;
  1031. }
  1032. //string userInfoXml = XmlSerializeHelper.XmlSerialize(toolbarLocationModel);
  1033. string userInfoXml = XmlSerializeHelper.XmlSerialize(toolbarModel);
  1034. //string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\ToolbarLocation.xml";
  1035. string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Toolbar.xml";
  1036. if (FileOperationHelper.WriteStringToFile(userInfoXml, filePath, System.IO.FileMode.Create))
  1037. {
  1038. //Startup.instance.toolbarLocationModel = toolbarLocationModel;
  1039. Startup.instance.toolbarModel = toolbarModel;
  1040. }
  1041. else
  1042. {
  1043. MessageBox.Show("工具栏坐标保存失败");
  1044. }
  1045. }
  1046. ToolStrip toolStripEx = new ToolStrip();
  1047. /// <summary>
  1048. /// 重置工具栏
  1049. /// </summary>
  1050. public void ResetCustomizeTools()
  1051. {
  1052. this.toolbarModel = Startup.instance.toolbarModel;
  1053. if (toolbarModel == null || toolbarModel.Flows.Count == 0)
  1054. {
  1055. this.toolStripContainer1.TopToolStripPanel.Controls.Clear();
  1056. return;
  1057. }
  1058. int toolCount = toolbarModel.Flows.Count;
  1059. for (int j = toolbarModel.Flows.Count - 1; j >= 0; j--)
  1060. {
  1061. Flow flowJ = toolbarModel.Flows[j];
  1062. if (flowJ.Menus.Count == 0)
  1063. {
  1064. toolCount -= 1;
  1065. }
  1066. }
  1067. if (toolCount == 0)
  1068. {
  1069. this.toolStripContainer1.TopToolStripPanel.Controls.Clear();
  1070. return;
  1071. }
  1072. toolStrips = new ToolStrip[toolCount];
  1073. int t = 0;
  1074. for (int j = toolbarModel.Flows.Count - 1; j >= 0; j--)
  1075. {
  1076. Flow flowJ = toolbarModel.Flows[j];
  1077. if (flowJ.Menus.Count == 0)
  1078. {
  1079. continue;
  1080. }
  1081. ToolStrip toolStripEx = new ToolStrip();
  1082. ImageList imageList = new ImageList();
  1083. imageList.ColorDepth = ColorDepth.Depth32Bit;
  1084. imageList.TransparentColor = Utility.TransparentKey;
  1085. toolStripEx.ImageList = imageList;
  1086. toolStripEx.Name = flowJ.Key;
  1087. int buttonsCount = flowJ.Menus.Count;
  1088. foreach (Flow.Item item in flowJ.Menus)
  1089. {
  1090. if (item.Description.Equals("Script"))//脚本列表
  1091. {
  1092. List<mic_script> list = mic_script_BLL.FindAll();
  1093. buttonsCount += (list.Count - 1);
  1094. }
  1095. if (item.Description.Equals("SubRulerCalibration"))//标尺标定,标尺列表
  1096. {
  1097. buttonsCount += 1;
  1098. }
  1099. }
  1100. ToolStripItem[] buttons = new ToolStripItem[buttonsCount/*flowJ.Menus.Count*/];
  1101. int index = 0;
  1102. for (int i = 0; i < flowJ.Menus.Count; i++, index++)
  1103. {
  1104. ToolStripButton button = new ToolStripButton();
  1105. int imageIndex = -1;
  1106. if (flowJ.Menus[i].Description.Equals("SeparateLine"))
  1107. {
  1108. ToolStripSeparator separator0 = new ToolStripSeparator();
  1109. buttons[index] = separator0;
  1110. continue;
  1111. }
  1112. ToolStripItem[] items = this.MainMenu.Items.Find(flowJ.Menus[i].Description, true);
  1113. if (items != null && items.Length > 0)
  1114. {
  1115. if (((PdnMenuItem)(items[0])).Image != null)
  1116. imageIndex = imageList.Images.Add(((PdnMenuItem)(items[0])).Image, imageList.TransparentColor);
  1117. else
  1118. imageIndex = imageList.Images.Add(new Bitmap(16, 16), imageList.TransparentColor);
  1119. button.ToolTipText = ((PdnMenuItem)(items[0])).Text;
  1120. button.Text = ((PdnMenuItem)(items[0])).Text;
  1121. }
  1122. else
  1123. {
  1124. imageIndex = imageList.Images.Add(new Bitmap(16, 16), imageList.TransparentColor);
  1125. button.ToolTipText = flowJ.Menus[i].Name;// .getShowName(Startup.instance.configModel.Language);
  1126. button.Text = flowJ.Menus[i].Name;// .getShowName(Startup.instance.configModel.Language);
  1127. }
  1128. button.ImageIndex = imageIndex;
  1129. button.Tag = flowJ.Menus[i].Description;
  1130. button.TextImageRelation = TextImageRelation.ImageAboveText;
  1131. if (this.appWorkspace.ActiveDocumentWorkspace != null)
  1132. {
  1133. if (button.Tag.ToString().Equals(this.type))
  1134. button.Checked = this.check;
  1135. }
  1136. //..Script
  1137. if (flowJ.Menus[i].Description.Equals("Script"))//脚本列表
  1138. {
  1139. List<mic_script> list = mic_script_BLL.FindAll();
  1140. for (int itemI = 0; itemI < list.Count - 1; itemI++)
  1141. {
  1142. var itemSS = list[itemI];
  1143. ToolStripButton unitLabel = new ToolStripButton();
  1144. unitLabel.Text = itemSS.name;
  1145. unitLabel.TextImageRelation = TextImageRelation.ImageBeforeText;
  1146. unitLabel.Padding = new Padding(2, 20 - unitLabel.Height / 2, 0, 20 - unitLabel.Height / 2);
  1147. //unitLabel.Tag = "Script_" + itemSS.id;
  1148. unitLabel.Name = "" + itemSS.id;
  1149. buttons[index] = unitLabel;
  1150. index++;
  1151. }
  1152. //unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
  1153. var item = list[list.Count - 1];
  1154. ToolStripButton unitsLabel = new ToolStripButton();
  1155. unitsLabel.Text = item.name;
  1156. unitsLabel.TextImageRelation = TextImageRelation.ImageBeforeText;
  1157. unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
  1158. unitsLabel.Name = "" + item.id;
  1159. buttons[index] = unitsLabel;
  1160. }
  1161. else if (flowJ.Menus[i].Description.Equals("SubRulerCalibration"))
  1162. {
  1163. ToolStripLabel unitsLabel = new ToolStripLabel();
  1164. unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
  1165. unitsLabel.Text = "标尺:";
  1166. buttons[index] = unitsLabel;
  1167. index++;
  1168. ToolStripComboBox zoomComboBox = new ToolStripComboBox();
  1169. zoomComboBox.Tag = i;
  1170. zoomComboBox.Size = new Size(100/*75*/, zoomComboBox.Height);
  1171. zoomComboBox.Padding = new Padding(0, 20 - zoomComboBox.Height / 2, 2, 20 - zoomComboBox.Height / 2);
  1172. zoomComboBox.MaxDropDownItems = 99;
  1173. zoomComboBox.SelectedIndexChanged += ZoomComboBox_SelectedIndexChanged;
  1174. List<mic_rulers> list = mic_rulers_BLL.FindAll();
  1175. if (list != null)
  1176. {
  1177. for (int ruleI = 0; ruleI < list.Count; ruleI++)
  1178. {
  1179. mic_rulers rule = list[ruleI];
  1180. zoomComboBox.Items.Add(rule.ruler_name);
  1181. if (Startup.instance.configModel != null)
  1182. {
  1183. if (Startup.instance.configModel.RulerId == rule.id)
  1184. {
  1185. zoomComboBox.Text = rule.ruler_name;// "newText";
  1186. }
  1187. }
  1188. }
  1189. }
  1190. rulersComboBox.Add(zoomComboBox);
  1191. buttons[index] = zoomComboBox;
  1192. zoomComboBox.ComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
  1193. zoomComboBox.BackColor = SystemColors.Window;
  1194. }
  1195. else
  1196. {
  1197. buttons[index] = button;
  1198. }
  1199. }
  1200. toolStripEx.ItemClicked += new ToolStripItemClickedEventHandler(ToolStripEx_ItemClicked);
  1201. toolStripEx.ItemRemoved += ToolStripEx_ItemRemoved;
  1202. toolStripEx.EndDrag += ToolStripEx_DragDrop1;
  1203. toolStripEx.AllowDrop = false;
  1204. toolStripEx.AllowMerge = false;
  1205. toolStripEx.Height = 40;
  1206. toolStripEx.Items.AddRange(buttons);
  1207. toolStrips[t] = toolStripEx;
  1208. toolStripEx.Visible = flowJ.Show;
  1209. t++;
  1210. }
  1211. this.toolStripContainer1.TopToolStripPanel.Controls.Clear();
  1212. this.toolStripContainer1.TopToolStripPanel.Controls.AddRange(toolStrips);
  1213. //this.toolStripContainer1.TopToolStripPanel.Refresh();
  1214. //this.toolStripInitLayout = -100;// 10;
  1215. //this.toolbarModel = Startup.instance.toolbarModel;
  1216. //this.toolStripContainer1.TopToolStripPanel.Controls.Clear();
  1217. //SetCustomizeTools(true);
  1218. //int toolCount = this.toolbarModel.Flows.Count;
  1219. //for (int j = this.toolbarModel.Flows.Count - 1; j >= 0; j--)
  1220. //{
  1221. // Flow flowJ = this.toolbarModel.Flows[j];
  1222. // if (flowJ.Menus.Count == 0)
  1223. // {
  1224. // toolCount -= 1;
  1225. // }
  1226. //}
  1227. //if (toolCount == 0)
  1228. //{
  1229. // this.toolStripContainer1.TopToolStripPanel.Controls.Clear();
  1230. // return;
  1231. //}
  1232. //toolStrips = new ToolStrip[toolCount];
  1233. //rulersComboBox.Clear();
  1234. //int indexJ = 0;
  1235. ////先将location值不为-100的菜单显示出来(初始值设置-100)
  1236. //int heightRow = 0;// -1;// 0;
  1237. //int widthRow1 = 0;// -1;// 0;
  1238. ////for (int j = 0; j < Startup.instance.toolbarLocationModel.Flows.Count; j++)
  1239. //for (int j = 0; j < Startup.instance.toolbarModel.Flows.Count; j++)
  1240. //{
  1241. // //ToolbarLocationModel.Flow flowJ = Startup.instance.toolbarLocationModel.Flows[j];
  1242. // ToolbarModel.Flow flowJ = Startup.instance.toolbarModel.Flows[j];
  1243. // if (flowJ.X > -100 && flowJ.Y > -100)
  1244. // {
  1245. // if (flowJ.Y > heightRow || (flowJ.Y == heightRow && flowJ.X >= widthRow1))
  1246. // {
  1247. // Control[] temp = this.toolStripContainer1.TopToolStripPanel.Controls.Find(flowJ.Key, true);
  1248. // if (temp!=null && temp.Length>0)
  1249. // {
  1250. // ToolStrip toolStripEx = (ToolStrip)(temp[0]);
  1251. // if (toolStripEx == null)
  1252. // {
  1253. // heightRow = flowJ.Y;
  1254. // widthRow1 = flowJ.X + 1;
  1255. // }
  1256. // else
  1257. // {
  1258. // heightRow = flowJ.Y;
  1259. // widthRow1 = flowJ.X + toolStripEx.PreferredSize.Width + toolStripEx.Margin.Horizontal + 1;
  1260. // }
  1261. // }
  1262. // }
  1263. // }
  1264. //}
  1265. //for (int i = 0; i < this.toolStripContainer1.TopToolStripPanel.Controls.Count; i++)
  1266. //{
  1267. // ToolStrip toolStripEx = (ToolStrip)this.toolStripContainer1.TopToolStripPanel.Controls[i];
  1268. // Flow flowJ = toolbarModel.Flows.Find(a => a.Key.Equals(toolStripEx.Name));
  1269. // if (flowJ == null)
  1270. // {
  1271. // this.toolStripContainer1.TopToolStripPanel.Controls.Remove(toolStripEx);
  1272. // i--;
  1273. // }
  1274. // else
  1275. // {
  1276. // toolStrips[indexJ++] = toolStripEx;
  1277. // }
  1278. //}
  1279. //if (toolbarModel == null || toolbarModel.Flows.Count == 0)
  1280. //{
  1281. // return;
  1282. //}
  1283. ////int toolStripWidth = 0;
  1284. //for (int j = toolbarModel.Flows.Count - 1; j >= 0; j--)
  1285. //{
  1286. // Flow flowJ = toolbarModel.Flows[j];
  1287. // if (flowJ.Menus.Count == 0)
  1288. // {
  1289. // continue;
  1290. // }
  1291. // ToolStrip toolStripEx = new ToolStrip();//Ex
  1292. // ImageList imageList = new ImageList();
  1293. // imageList.ColorDepth = ColorDepth.Depth32Bit;
  1294. // imageList.TransparentColor = Utility.TransparentKey;
  1295. // toolStripEx.ImageList = imageList;
  1296. // toolStripEx.Name = flowJ.Key;// "key_" + j;
  1297. // //Base.SettingModel.ToolbarLocationModel.Flow flow = toolbarLocationModel.Flows.Find(a => a.Key.Equals(flowJ.Key/*"targetProcess"*/));
  1298. // ////ToolbarLocationModel.Flows.Find();
  1299. // //int locationX = flow.X;
  1300. // //int locationY = flow.Y;
  1301. // int buttonsCount = flowJ.Menus.Count;
  1302. // foreach (Flow.Item item in flowJ.Menus)
  1303. // {
  1304. // //..Script
  1305. // if (item.Description.Equals("Script"))//脚本列表
  1306. // {
  1307. // List<mic_script> list = mic_script_BLL.FindAll();
  1308. // buttonsCount += (list.Count - 1);
  1309. // }
  1310. // if (item.Description.Equals("SubRulerCalibration"))
  1311. // {
  1312. // buttonsCount += 1;
  1313. // }
  1314. // }
  1315. // ToolStripItem[] buttons = new ToolStripItem[buttonsCount/*flowJ.Menus.Count*/];
  1316. // int index = 0;
  1317. // for (int i = 0; i < flowJ.Menus.Count; i++, index++)
  1318. // {
  1319. // ToolStripButton button = new ToolStripButton();
  1320. // int imageIndex = -1;
  1321. // if (flowJ.Menus[i].Description.Equals("SeparateLine"))
  1322. // {
  1323. // ToolStripSeparator separator0 = new ToolStripSeparator();
  1324. // buttons[index] = separator0;
  1325. // continue;
  1326. // }
  1327. // //this.Items.Add(this.separator0);
  1328. // ToolStripItem[] items = this/*.appWorkspace.ToolBar*/.MainMenu.Items.Find(flowJ.Menus[i].Description, true);
  1329. // //ToolbarLocationModel.Flows;
  1330. // if (items != null && items.Length > 0)
  1331. // {
  1332. // if (((PdnMenuItem)(items[0])).Image != null)
  1333. // imageIndex = imageList.Images.Add(((PdnMenuItem)(items[0])).Image, imageList.TransparentColor);
  1334. // else
  1335. // imageIndex = imageList.Images.Add(new Bitmap(16, 16), imageList.TransparentColor);
  1336. // }
  1337. // else
  1338. // {
  1339. // imageIndex = imageList.Images.Add(new Bitmap(16, 16), imageList.TransparentColor);
  1340. // }
  1341. // button.ImageIndex = imageIndex;
  1342. // button.Tag = flowJ.Menus[i].Description;
  1343. // button.ToolTipText = flowJ.Menus[i].Name;
  1344. // button.Text = flowJ.Menus[i].Name;
  1345. // button.TextImageRelation = TextImageRelation.ImageAboveText;
  1346. // //..Script
  1347. // if (flowJ.Menus[i].Description.Equals("Script"))//脚本列表
  1348. // {
  1349. // List<mic_script> list = mic_script_BLL.FindAll();
  1350. // for (int itemI = 0; itemI < list.Count - 1; itemI++)
  1351. // {
  1352. // var itemSS = list[itemI];
  1353. // ToolStripButton unitLabel = new ToolStripButton();
  1354. // unitLabel.Text = itemSS.name;
  1355. // unitLabel.TextImageRelation = TextImageRelation.ImageBeforeText;
  1356. // unitLabel.Padding = new Padding(2, 20 - unitLabel.Height / 2, 0, 20 - unitLabel.Height / 2);
  1357. // unitLabel.Name = "" + itemSS.id;
  1358. // buttons[index] = unitLabel;
  1359. // index++;
  1360. // }
  1361. // //unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
  1362. // var item = list[list.Count - 1];
  1363. // ToolStripButton unitsLabel = new ToolStripButton();
  1364. // unitsLabel.Text = item.name;
  1365. // unitsLabel.TextImageRelation = TextImageRelation.ImageBeforeText;
  1366. // unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
  1367. // unitsLabel.Name = "" + item.id;
  1368. // buttons[index] = unitsLabel;
  1369. // }
  1370. // else if (flowJ.Menus[i].Description.Equals("SubRulerCalibration"))
  1371. // {
  1372. // ToolStripLabel unitsLabel = new ToolStripLabel();
  1373. // unitsLabel.Padding = new Padding(2, 20 - unitsLabel.Height / 2, 0, 20 - unitsLabel.Height / 2);
  1374. // unitsLabel.Text = "标尺:";
  1375. // buttons[index] = unitsLabel;
  1376. // index++;
  1377. // ToolStripComboBox zoomComboBox = new ToolStripComboBox();
  1378. // zoomComboBox.Tag = i;
  1379. // zoomComboBox.Size = new Size(100/*75*/, zoomComboBox.Height);
  1380. // zoomComboBox.Padding = new Padding(0, 20 - zoomComboBox.Height / 2, 2, 20 - zoomComboBox.Height / 2);
  1381. // zoomComboBox.MaxDropDownItems = 99;
  1382. // zoomComboBox.SelectedIndexChanged += ZoomComboBox_SelectedIndexChanged;
  1383. // List<mic_rulers> list = mic_rulers_BLL.FindAll();
  1384. // if (list != null)
  1385. // {
  1386. // for (int ruleI = 0; ruleI < list.Count; ruleI++)
  1387. // {
  1388. // mic_rulers rule = list[ruleI];
  1389. // zoomComboBox.Items.Add(rule.ruler_name);
  1390. // if (Startup.instance.configModel != null)
  1391. // {
  1392. // if (Startup.instance.configModel.RulerId == rule.id)
  1393. // {
  1394. // zoomComboBox.Text = rule.ruler_name;// "newText";
  1395. // }
  1396. // }
  1397. // }
  1398. // }
  1399. // //if (zoomComboBox.Text == null || zoomComboBox.Text.Equals(""))
  1400. // //{
  1401. // // zoomComboBox.Text = "请选择";
  1402. // //}
  1403. // rulersComboBox.Add(zoomComboBox);
  1404. // buttons[index] = zoomComboBox;
  1405. // zoomComboBox.ComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
  1406. // zoomComboBox.BackColor = SystemColors.Window;
  1407. // }
  1408. // else
  1409. // {
  1410. // buttons[index] = button;
  1411. // }
  1412. // }
  1413. // toolStripEx.ItemClicked += new ToolStripItemClickedEventHandler(ToolStripEx_ItemClicked);
  1414. // toolStripEx.ItemRemoved += ToolStripEx_ItemRemoved;
  1415. // toolStripEx.EndDrag += ToolStripEx_DragDrop1;
  1416. // toolStripEx.AllowDrop = false;
  1417. // toolStripEx.AllowMerge = false;
  1418. // toolStripEx.Height = 40;
  1419. // toolStripEx.Items.AddRange(buttons);
  1420. // //Base.SettingModel.ToolbarLocationModel.Flow flowLocJ = toolbarLocationModel.Flows.Find(a => a.Key.Equals(toolStripEx.Name));
  1421. // Base.SettingModel.ToolbarModel.Flow flowLocJ = toolbarModel.Flows.Find(a => a.Key.Equals(toolStripEx.Name));
  1422. // if (flowLocJ.X == -100 || flowLocJ.Y == -100)
  1423. // {
  1424. // Control[] toolStripTemp = /*(ToolStrip[])*/this.toolStripContainer1.TopToolStripPanel.Controls.Find(flowJ.Key, true);
  1425. // //ToolStrip toolStripEx = (ToolStrip)this.toolStripContainer1.TopToolStripPanel.Controls.Find(flowJ.Key, true)[0];
  1426. // if (toolStripTemp != null && toolStripTemp.Length > 0/*toolStripEx == null*/)
  1427. // {
  1428. // continue;
  1429. // }
  1430. // if (widthRow1 < ClientSize.Width || ClientSize.Width == 0)
  1431. // {
  1432. // toolStripEx.Location = new Point(widthRow1/*lastToolStripEx.Right + 1*/, heightRow/*lastToolStripEx.Top*/);
  1433. // widthRow1 = widthRow1 + toolStripEx.PreferredSize.Width + toolStripEx.Margin.Horizontal + 1;
  1434. // }
  1435. // else
  1436. // {
  1437. // heightRow += 40;// 38;// 39;
  1438. // toolStripEx.Location = new Point(0, heightRow/*lastToolStripEx.Bottom*/);
  1439. // widthRow1 = 0/*toolStripEx.Left*/ + toolStripEx.PreferredSize.Width + toolStripEx.Margin.Horizontal;
  1440. // }
  1441. // this.toolStripContainer1.TopToolStripPanel.Controls.Add(toolStripEx);
  1442. // toolStrips[indexJ++] = toolStripEx;
  1443. // }
  1444. //}
  1445. //this.toolStripContainer1.TopToolStripPanel.ControlRemoved += TopToolStripPanel_ControlRemoved;
  1446. //this.toolStripContainer1.TopToolStripPanel.DragDrop += TopToolStripPanel_DragDrop;
  1447. //this.toolStripContainer1.TopToolStripPanel.DragLeave += TopToolStripPanel_DragLeave;
  1448. //toolStripInitLayout = 3;// 0;
  1449. //this.toolStripContainer1.Enabled = (!this.appWorkspace.ScriptRunning);
  1450. ////this.mainMenu.Enabled = (!this.appWorkspace.ScriptRunning);
  1451. }
  1452. private string type;
  1453. private bool check;
  1454. /// <summary>
  1455. /// 连续绘制联动
  1456. /// </summary>
  1457. /// <param name="check">是否选择</param>
  1458. /// <param name="type">0:标注 1:测量</param>
  1459. public void RefreshBtnSelect(bool check, string type)
  1460. {
  1461. this.type = type;
  1462. this.check = check;
  1463. if (toolStrips == null)
  1464. return;
  1465. for (int i = 0; i < toolStrips.Length; i++)
  1466. {
  1467. for (int j = 0; j < toolStrips[i].Items.Count; j++)
  1468. {
  1469. if (toolStrips[i].Items[j] is ToolStripButton && ((ToolStripButton)toolStrips[i].Items[j]).Tag != null && ((ToolStripButton)toolStrips[i].Items[j]).Tag.ToString().Equals(type))
  1470. ((ToolStripButton)toolStrips[i].Items[j]).Checked = check;
  1471. }
  1472. }
  1473. this.Refresh();
  1474. }
  1475. private void TopToolStripPanel_DragLeave(object sender, EventArgs e)
  1476. {
  1477. //throw new NotImplementedException();
  1478. }
  1479. private void TopToolStripPanel_DragDrop(object sender, DragEventArgs e)
  1480. {
  1481. //throw new NotImplementedException();
  1482. }
  1483. private void TopToolStripPanel_ControlRemoved(object sender, ControlEventArgs e)
  1484. {
  1485. //throw new NotImplementedException();
  1486. }
  1487. private void ToolStripEx_ItemRemoved(object sender, ToolStripItemEventArgs e)
  1488. {
  1489. //throw new NotImplementedException();
  1490. }
  1491. /// <summary>
  1492. /// 递归查找菜单,暂时不用,改成直接用name查找
  1493. /// </summary>
  1494. /// <param name="collection"></param>
  1495. /// <param name="step"></param>
  1496. private void RecursiveData(ToolStripItemCollection collection, mic_script_step step)
  1497. {
  1498. for (int i = 0; i < collection.Count; i++)
  1499. {
  1500. if (!collection[i].Name.Equals("OpenRecent") && !collection[i].Name.Equals("CameraSelection"))
  1501. {
  1502. if (collection[i] is PdnMenuItem)
  1503. {
  1504. if (step.menu_id == ((PdnMenuItem)collection[i]).MenuId)
  1505. {
  1506. ((PdnMenuItem)collection[i]).PerformClick();
  1507. }
  1508. RecursiveData(((PdnMenuItem)collection[i]).DropDownItems, step);
  1509. }
  1510. }
  1511. }
  1512. }
  1513. /// <summary>
  1514. /// 脚本按钮点击方法
  1515. /// </summary>
  1516. /// <param name="sender"></param>
  1517. /// <param name="e"></param>
  1518. private void ToolStripEx_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  1519. {
  1520. if (e.ClickedItem.GetType() != typeof(ToolStripButton))
  1521. {
  1522. return;
  1523. }
  1524. if (e.ClickedItem.Tag == null)
  1525. {
  1526. //获取当前选中的脚本步骤
  1527. List<mic_script_step> steps = mic_script_step_BLL.FindAllByScripId(int.Parse(e.ClickedItem.Name)/*list[this.listBox1.SelectedIndex].id*/);
  1528. //this.WindowState = FormWindowState.Minimized;
  1529. //循环脚本步骤
  1530. foreach (mic_script_step step in steps)
  1531. {
  1532. //递归的方式
  1533. this.RecursiveData(this.appWorkspace.ToolBar.MainMenu.Items/*this.collection*/, step);
  1534. }
  1535. return;
  1536. }
  1537. //e.ClickedItem.Visible = false;
  1538. ToolStripItem[] menu = this.appWorkspace.ToolBar.MainMenu.Items.Find(e.ClickedItem.Tag.ToString(), true);
  1539. if (menu != null && menu.Length > 0)
  1540. {
  1541. if(((PdnMenuItem)menu[0]).canChecked)
  1542. ((ToolStripButton)e.ClickedItem).Checked = !((ToolStripButton)e.ClickedItem).Checked;
  1543. ((PdnMenuItem)menu[0]).PerformClick();
  1544. appWorkspace.UpdateBottomButtonSelectionStatus();
  1545. }
  1546. }
  1547. private void panel1_SizeChanged(object sender, EventArgs e)
  1548. {
  1549. this.toolStripContainer1.Height = this.toolStripContainer1.TopToolStripPanel.Height + 1;
  1550. }
  1551. private void DocumentStrip_DocumentClicked(object sender, EventArgs<Pair<DocumentWorkspace, DocumentClickAction>> e)
  1552. {
  1553. if (e.Data.Second == DocumentClickAction.Select)
  1554. {
  1555. PerformLayout();
  1556. }
  1557. }
  1558. private void DocumentStrip_DocumentListChanged(object sender, EventArgs e)
  1559. {
  1560. PerformLayout();
  1561. if (this.documentStrip.DocumentCount == 0)
  1562. {
  1563. //this.viewConfigStrip.Enabled = false;
  1564. //this.toolChooserStrip.Enabled = false;
  1565. }
  1566. else
  1567. {
  1568. //this.viewConfigStrip.Enabled = true;
  1569. //this.toolChooserStrip.Enabled = true;
  1570. }
  1571. }
  1572. /// <summary>
  1573. /// 用于ctrl+双击复制
  1574. /// </summary>
  1575. public void CopyAndPasteByControlAndDoubleClick()
  1576. {
  1577. //ToolStripItem[] menu = this.MainMenu.Items.Find(PdnMenuItem.GetDescription(ActionType.Copy), true);
  1578. //ToolStripItem[] menu1 = this.MainMenu.Items.Find(PdnMenuItem.GetDescription(ActionType.Paste), true);
  1579. //if (menu != null && menu1 != null && menu.Length > 0 && menu1.Length > 0)
  1580. //{
  1581. // ((PdnMenuItem)menu[0]).PerformClick();
  1582. // ((PdnMenuItem)menu1[0]).PerformClick();
  1583. //}
  1584. ControlAnd(CopyAndPasteBy());
  1585. }
  1586. /// <summary>
  1587. /// 复制剪裁图片
  1588. /// </summary>
  1589. /// <returns></returns>
  1590. public Bitmap CopyAndPasteBy()
  1591. {
  1592. if (AppWorkspace.ActiveDocumentWorkspace != null && AppWorkspace.ActiveDocumentWorkspace.CompositionSurface != null)
  1593. {
  1594. Bitmap temp = AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap();
  1595. copyedBitmap = new Bitmap(temp.Width, temp.Height);
  1596. Graphics graphics = Graphics.FromImage(copyedBitmap);
  1597. graphics.DrawImage(temp, 0, 0, temp.Width, temp.Height);
  1598. if (AppWorkspace.ActiveDocumentWorkspace.GraphicsList.IsExsitSpecificObject(DrawToolType.ImageCut))
  1599. {
  1600. //获取裁剪的矩形区域
  1601. List<DrawObject> objList = AppWorkspace.ActiveDocumentWorkspace.GraphicsList.GetDrawToolTypeList(DrawToolType.ImageCut);
  1602. ImageCutDraw imageCutDraw = (ImageCutDraw)objList[0];
  1603. RectangleF cutRectangle = imageCutDraw.Rectangle;
  1604. copyedBitmap = DrawRulerHelper.KiCut(copyedBitmap, (int)cutRectangle.X, (int)cutRectangle.Y, (int)cutRectangle.Width, (int)cutRectangle.Height);
  1605. }
  1606. }
  1607. return copyedBitmap;
  1608. }
  1609. /// <summary>
  1610. /// 粘贴剪裁图片
  1611. /// </summary>
  1612. /// <param name="copyedBitmap"></param>
  1613. public void ControlAnd(Bitmap copyedBitmap)
  1614. {
  1615. if (copyedBitmap != null)
  1616. {
  1617. DocumentWorkspace dw = AppWorkspace.AddNewDocumentWorkspace();
  1618. Document document = Document.FromImageMat(Camera.Tools.ToMat(copyedBitmap));
  1619. dw.Document = document;
  1620. dw.xmlSaveModel = AppWorkspace.ActiveDocumentWorkspace.xmlSaveModel;
  1621. dw.rules = AppWorkspace.ActiveDocumentWorkspace.rules;
  1622. //图片命名
  1623. nameNum++;
  1624. int numLength = nameNum.ToString().Length;
  1625. string joinName = "";
  1626. switch (numLength)
  1627. {
  1628. case 1:
  1629. joinName = "00" + nameNum;
  1630. break;
  1631. case 2:
  1632. joinName = "0" + nameNum;
  1633. break;
  1634. default:
  1635. joinName = nameNum.ToString();
  1636. break;
  1637. }
  1638. dw.fileText = PdnResources.GetString("Menu.Copythepicture.Text") + "-" + joinName;
  1639. AppWorkspace.ActiveDocumentWorkspace = dw;
  1640. }
  1641. }
  1642. }
  1643. }