using PaintDotNet.Base.SettingModel; using PaintDotNet.SystemLayer; using System; using System.Drawing; using System.Windows.Forms; namespace PaintDotNet { internal class ToolsControl : UserControl { private ToolStripEx toolStripEx; private ImageList imageList; private const int tbWidth = 2; private int ignoreToolClicked = 0; private Control onePxSpacingLeft; private ShortcutbarModel shortcutbarModel = Startup.instance.shortcutbarModel; private System.ComponentModel.Container components = null; private AppWorkspace appWorkspace; public ToolsControl(AppWorkspace appWorkspace) { this.appWorkspace = appWorkspace; InitializeComponent(); SetTools(); } public void SetTools() { if (this.toolStripEx != null) { this.toolStripEx.Items.Clear(); } this.imageList = new ImageList(); this.imageList.ColorDepth = ColorDepth.Depth32Bit; this.imageList.TransparentColor = Utility.TransparentKey; this.toolStripEx.ImageList = this.imageList; /** ToolStripItem[] buttons = new ToolStripItem[toolInfos.Length]; string toolTipFormat = PdnResources.GetString("ToolsControl.ToolToolTip.Format"); for (int i = 0; i < toolInfos.Length; ++i) { ToolInfo toolInfo = toolInfos[i]; ToolStripButton button = new ToolStripButton(); int imageIndex = imageList.Images.Add( toolInfo.Image.Reference, imageList.TransparentColor); button.ImageIndex = imageIndex; button.Tag = toolInfo.ToolType; button.ToolTipText = string.Format(toolTipFormat, toolInfo.Name, char.ToUpperInvariant(toolInfo.HotKey).ToString()); buttons[i] = button; } this.toolStripEx.Items.AddRange(buttons); **/ SetCustomizeTools(); } public void RefreshTools() { int numold = 0; if (this.toolStripEx != null) { numold = this.toolStripEx.Items.Count; } SetCustomizeTools(); for (int i = 0; i < numold; i++) { this.toolStripEx.Items.RemoveAt(0); } //this.toolStripEx.Enabled = (!this.appWorkspace.ScriptRunning); } public void SetCustomizeTools() { if (shortcutbarModel != null) { if (shortcutbarModel.Menus.Count > 0) { ToolStripItem[] buttons = new ToolStripItem[shortcutbarModel.Menus.Count]; for (int i = 0; i < shortcutbarModel.Menus.Count; i++) { ToolStripButton button = new ToolStripButton(); int imageIndex = -1; ToolStripItem[] items = this.appWorkspace.ToolBar.MainMenu.Items.Find(shortcutbarModel.Menus[i].Description, true); if (items != null && items.Length > 0) { if (((PdnMenuItem)(items[0])).Image != null) { imageIndex = this.imageList.Images.Add(((PdnMenuItem)(items[0])).Image, imageList.TransparentColor); button.ToolTipText = ((PdnMenuItem)(items[0])).Text; } else { imageIndex = this.imageList.Images.Add(PdnResources.GetImageResource("Icons.MenuImageRotate90CWIcon.png").Reference, imageList.TransparentColor); //imageIndex = this.imageList.Images.Add(new Bitmap(16, 16), imageList.TransparentColor); button.ToolTipText = shortcutbarModel.Menus[i].Name;// getShowName(Startup.instance.configModel.Language); } } else { imageIndex = this.imageList.Images.Add(PdnResources.GetImageResource("Icons.MenuImageRotate90CWIcon.png").Reference, imageList.TransparentColor); //imageIndex = this.imageList.Images.Add(new Bitmap(16, 16), imageList.TransparentColor); button.ToolTipText = shortcutbarModel.Menus[i].Name;// getShowName(Startup.instance.configModel.Language); } button.Enabled = Startup.getMenuIdVisible(shortcutbarModel.Menus[i].Id); button.ImageIndex = imageIndex; button.Tag = shortcutbarModel.Menus[i].Description; buttons[i] = button; if (this.appWorkspace.ActiveDocumentWorkspace != null) { if (button.Tag.ToString().Equals(this.type)) button.Checked = this.check; } } this.toolStripEx.Items.AddRange(buttons); appWorkspace.SetTopLeftCheckState(); } } } public void SelectTool(Type toolType) { SelectTool(toolType, true); } public void SelectTool(Type toolType, bool raiseEvent) { if (!raiseEvent) { ++this.ignoreToolClicked; } try { foreach (ToolStripButton button in this.toolStripEx.Items) { if ((Type)button.Tag == toolType) { this.ToolStripEx_ItemClicked(this, new ToolStripItemClickedEventArgs(button)); return; } } throw new ArgumentException("Tool type not found"); } finally { if (!raiseEvent) { --this.ignoreToolClicked; } } } protected override void OnLayout(LayoutEventArgs e) { int buttonWidth; if (this.toolStripEx.Items.Count > 0) { buttonWidth = this.toolStripEx.Items[0].Width; } else { buttonWidth = 0; } this.toolStripEx.Width = this.toolStripEx.Padding.Left + (buttonWidth * tbWidth) + (this.toolStripEx.Margin.Horizontal * tbWidth) + this.toolStripEx.Padding.Right; this.toolStripEx.Height = this.toolStripEx.GetPreferredSize(this.toolStripEx.Size).Height; this.Width = this.toolStripEx.Width + this.onePxSpacingLeft.Width; this.Height = this.toolStripEx.Height; base.OnLayout(e); } /// /// Clean up any resources being used. /// protected override void Dispose(bool disposing) { if (disposing) { if (components != null) { components.Dispose(); components = null; } } base.Dispose(disposing); } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.toolStripEx = new ToolStripEx(); this.onePxSpacingLeft = new Control(); this.SuspendLayout(); // // toolStripEx // this.toolStripEx.Dock = System.Windows.Forms.DockStyle.Top; this.toolStripEx.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden; this.toolStripEx.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.Flow; this.toolStripEx.ItemClicked += new ToolStripItemClickedEventHandler(ToolStripEx_ItemClicked); this.toolStripEx.Name = "toolStripEx"; this.toolStripEx.AutoSize = true; this.toolStripEx.RelinquishFocus += new EventHandler(ToolStripEx_RelinquishFocus); // // onePxSpacingLeft // this.onePxSpacingLeft.Dock = System.Windows.Forms.DockStyle.Left; this.onePxSpacingLeft.Width = 1; this.onePxSpacingLeft.Name = "onePxSpacingLeft"; // // MainToolBar // this.Controls.Add(this.toolStripEx); this.Controls.Add(this.onePxSpacingLeft); this.AutoScaleDimensions = new SizeF(96F, 96F); this.AutoScaleMode = AutoScaleMode.Dpi; this.Name = "MainToolBar"; this.Size = new System.Drawing.Size(48, 328); this.ResumeLayout(false); } public event EventHandler RelinquishFocus; private void OnRelinquishFocus() { if (RelinquishFocus != null) { RelinquishFocus(this, EventArgs.Empty); } } private void ToolStripEx_RelinquishFocus(object sender, EventArgs e) { OnRelinquishFocus(); } private void ToolStripEx_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { if (e.ClickedItem.GetType() != typeof(ToolStripButton)) { return; } ToolStripItem[] menu = this.appWorkspace.ToolBar.MainMenu.Items.Find(e.ClickedItem.Tag.ToString(), true); if (menu != null && menu.Length > 0) { if (menu != null && menu.Length > 0) { if (((PdnMenuItem)menu[0]).canChecked) ((ToolStripButton)e.ClickedItem).Checked = !((ToolStripButton)e.ClickedItem).Checked; ((PdnMenuItem)menu[0]).PerformClick(); appWorkspace.UpdateBottomButtonSelectionStatus(); } } } private string type; private bool check; public void RefreshBtnSelect(bool check, string type) { this.type = type; this.check = check; if (toolStripEx == null) return; for (int j = 0; j < this.toolStripEx.Items.Count; j++) { if (this.toolStripEx.Items[j] is ToolStripButton && ((ToolStripButton)this.toolStripEx.Items[j]).Tag.ToString().Equals(type)) ((ToolStripButton)this.toolStripEx.Items[j]).Checked = check; } this.Refresh(); } } }