|
| 1 | +using Avalonia.Controls; |
| 2 | +using CADability.UserInterface; |
| 3 | +using System; |
| 4 | +using System.Collections.Generic; |
| 5 | +using System.ComponentModel; |
| 6 | +using System.Diagnostics; |
| 7 | +using System.Text; |
| 8 | +using System.Xml; |
| 9 | + |
| 10 | + |
| 11 | +namespace CADability.Avalonia |
| 12 | +{ |
| 13 | + public partial class CadControl : UserControl, ICommandHandler |
| 14 | + { |
| 15 | + private CadFrame cadFrame; // the frame, which knows about the views, the ControlCenter (PropertiesExplorer), the menu |
| 16 | + // private ProgressForm progressForm; |
| 17 | + public CadControl() |
| 18 | + { |
| 19 | + InitializeComponent(); // makes the cadCanvas and the propertiesExplorer |
| 20 | + // KeyPreview = true; // used to filter the escape key (and maybe some more?) |
| 21 | + // cadFrame = new CadFrame(propertiesExplorer, cadCanvas, this); |
| 22 | + cadFrame = new CadFrame(cadCanvas, this); |
| 23 | + // cadFrame.ProgressAction = (show, percent, title) => { this.ProgressForm.ShowProgressBar(show, percent, title); }; |
| 24 | + cadCanvas.Frame = cadFrame; |
| 25 | + // propertiesExplorer.Frame = cadFrame; |
| 26 | + // show this menu in the MainForm |
| 27 | + // MenuWithHandler[] mainMenu = MenuResource.LoadMenuDefinition("SDI Menu", true, cadFrame); |
| 28 | + // MainMenuStrip = MenuManager.MakeMainMenu(mainMenu); |
| 29 | + // Controls.Add(MainMenuStrip); |
| 30 | + // cadFrame.FormMenu = MainMenuStrip; |
| 31 | + // open an existing Project or create a new one |
| 32 | + // ToolBars.CreateOrRestoreToolbars(topToolStripContainer, cadFrame); |
| 33 | + // Application.Idle += new EventHandler(OnIdle); // update the toolbars (menus are updated when they popup) |
| 34 | + } |
| 35 | + /// <summary> |
| 36 | + /// Resets the main menu of the form. After MenuResource.SetMenuResource has been loaded, the mainmenu in CADability |
| 37 | + /// is changed to the new resource. In order to set this menu in the form, call this method. |
| 38 | + /// </summary> |
| 39 | + /// <param name="debuggerPlaygroundClass">if not null, specifies an additional menue class, which will be created by reflection</param> |
| 40 | + // TODO |
| 41 | + // public void ResetMainMenu(string debuggerPlaygroundClass) |
| 42 | + // { |
| 43 | + // MenuWithHandler[] mainMenu = MenuResource.LoadMenuDefinition("SDI Menu", true, cadFrame); |
| 44 | + // if (!string.IsNullOrEmpty(debuggerPlaygroundClass)) |
| 45 | + // { |
| 46 | + // // in the following lines a "DebuggerPlayground" object is created via reflection. This class is a playground to write testcode |
| 47 | + // // which is not included in the sources. This is why it is constructed via reflection, there is no need to have this class in the project. |
| 48 | + // Type dbgplygnd = Type.GetType(debuggerPlaygroundClass, false); |
| 49 | + // if (dbgplygnd != null) |
| 50 | + // { |
| 51 | + // MethodInfo connect = dbgplygnd.GetMethod("Connect"); |
| 52 | + // if (connect != null) mainMenu = connect.Invoke(null, new object[] { cadFrame, mainMenu }) as MenuWithHandler[]; |
| 53 | + // } |
| 54 | + // } |
| 55 | + |
| 56 | + // if (this.MainMenuStrip != null) |
| 57 | + // { |
| 58 | + // this.Controls.Remove(this.MainMenuStrip); |
| 59 | + // this.MainMenuStrip.Dispose(); |
| 60 | + // } |
| 61 | + // MainMenuStrip = MenuManager.MakeMainMenu(mainMenu); |
| 62 | + // this.Controls.Add(MainMenuStrip); |
| 63 | + // cadFrame.FormMenu = MainMenuStrip; |
| 64 | + // } |
| 65 | + // Access the components of the MainForm from the CadFrame. |
| 66 | + // TODO |
| 67 | + // public void SetToolbar(XmlNode definition) |
| 68 | + // { |
| 69 | + // ToolBars.SetToolBar(topToolStripContainer, cadFrame, definition); |
| 70 | + // } |
| 71 | + // TODO |
| 72 | + // public ProgressForm ProgressForm |
| 73 | + // { |
| 74 | + // get |
| 75 | + // { |
| 76 | + // if (progressForm == null) |
| 77 | + // { |
| 78 | + // progressForm = new ProgressForm |
| 79 | + // { |
| 80 | + // TopLevel = true, |
| 81 | + // Owner = this, |
| 82 | + // Visible = false |
| 83 | + // }; |
| 84 | + // } |
| 85 | + // return progressForm; |
| 86 | + // } |
| 87 | + // } |
| 88 | + // public PropertiesExplorer PropertiesExplorer => propertiesExplorer; |
| 89 | + public CadCanvas CadCanvas => cadCanvas; |
| 90 | + public CadFrame CadFrame => cadFrame; |
| 91 | + |
| 92 | + // slowdown OnIdle polling: |
| 93 | + readonly Stopwatch _idleSw = Stopwatch.StartNew(); |
| 94 | + const int MinIdleCheckMs = 250; |
| 95 | + bool _idleBusy; |
| 96 | + // TODO Avalonia |
| 97 | + // private void OnIdle(object sender, EventArgs e) |
| 98 | + // { |
| 99 | + // if (_idleBusy) return; |
| 100 | + // if (_idleSw.ElapsedMilliseconds < MinIdleCheckMs) return; |
| 101 | + |
| 102 | + // _idleBusy = true; |
| 103 | + // _idleSw.Restart(); |
| 104 | + // try { ToolBars.UpdateCommandState(topToolStripContainer.TopToolStripPanel); } |
| 105 | + // finally { _idleBusy = false; } |
| 106 | + // } |
| 107 | + // TODO |
| 108 | + // protected override void OnClosing(CancelEventArgs e) |
| 109 | + // { // maybe we need to save the project |
| 110 | + // ToolBars.SaveToolbarPositions(topToolStripContainer); |
| 111 | + // Settings.SaveGlobalSettings(); |
| 112 | + // ToolStripManager.SaveSettings(this); // save the positions of the toolbars (doesn't work correctly) |
| 113 | + // base.OnClosing(e); |
| 114 | + // } |
| 115 | + // TODO |
| 116 | + // protected override void OnFormClosed(FormClosedEventArgs e) |
| 117 | + // { |
| 118 | + // cadFrame.Dispose(); |
| 119 | + // MainMenuStrip.Dispose(); |
| 120 | + // this.Dispose(); |
| 121 | + // cadCanvas.Dispose(); |
| 122 | + // propertiesExplorer.Dispose(); |
| 123 | + // topToolStripContainer.Dispose(); |
| 124 | + // splitContainer.Dispose(); |
| 125 | + // if (progressForm != null) progressForm.Dispose(); |
| 126 | + |
| 127 | + // MainMenuStrip = null; |
| 128 | + // cadFrame = null; |
| 129 | + // cadCanvas = null; |
| 130 | + // propertiesExplorer = null; |
| 131 | + // topToolStripContainer = null; |
| 132 | + // splitContainer = null; |
| 133 | + // progressForm = null; |
| 134 | + |
| 135 | + // base.OnFormClosed(e); |
| 136 | + // } |
| 137 | + // TODO |
| 138 | + // protected override bool ProcessCmdKey(ref Message msg, Keys keyData) |
| 139 | + // { |
| 140 | + // Keys nmKeyData = (Keys)((int)keyData & 0x0FFFF); |
| 141 | + // bool preProcess = nmKeyData >= Keys.F1 && nmKeyData <= Keys.F24; |
| 142 | + // preProcess = preProcess || (nmKeyData == Keys.Escape); |
| 143 | + // preProcess = preProcess || (nmKeyData == Keys.Up) || (nmKeyData == Keys.Down); |
| 144 | + // preProcess = preProcess || (nmKeyData == Keys.Tab) || (nmKeyData == Keys.Enter); |
| 145 | + // preProcess = preProcess || keyData.HasFlag(Keys.Control) || keyData.HasFlag(Keys.Alt); // menu shortcut |
| 146 | + // if (propertiesExplorer.EntryWithTextBox == null) preProcess |= (nmKeyData == Keys.Delete); // the delete key is preferred by the textbox, if there is one |
| 147 | + // Substitutes.KeyEventArgs e = new Substitutes.KeyEventArgs((Substitutes.Keys)keyData); |
| 148 | + // if (preProcess) |
| 149 | + // { |
| 150 | + // e.Handled = false; |
| 151 | + // cadFrame.PreProcessKeyDown(e); |
| 152 | + // if (e.Handled) return true; |
| 153 | + // } |
| 154 | + // CadFrame.PreProcessKeyDown(e); |
| 155 | + // if (e.Handled) return true; |
| 156 | + // //if (msg.Msg== 0x0101) // WM_KEYUP |
| 157 | + // //{ } |
| 158 | + // return base.ProcessCmdKey(ref msg, keyData); |
| 159 | + // } |
| 160 | + |
| 161 | + public virtual bool OnCommand(string MenuId) |
| 162 | + { |
| 163 | + return false; |
| 164 | + } |
| 165 | + |
| 166 | + public virtual bool OnUpdateCommand(string MenuId, CommandState CommandState) |
| 167 | + { |
| 168 | + return false; |
| 169 | + } |
| 170 | + |
| 171 | + public virtual void OnSelected(MenuWithHandler selectedMenuItem, bool selected) |
| 172 | + { |
| 173 | + |
| 174 | + } |
| 175 | + |
| 176 | + } |
| 177 | +} |
0 commit comments