using SAGY.RevitMenu; using SAGY.RevitMenu.Configuration; namespace TSZ.RevitMenu { using Autodesk.Revit.UI; using System; using System.CodeDom.Compiler; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.IO; using System.Windows; using System.Windows.Controls; using System.Windows.Forms; using System.Windows.Forms.Integration; using System.Windows.Markup; using TSZ.RevitBaseDll.Extends; using TSZ.RevitMenu.Configuration; public class ScreenMenu : Page, IDockablePaneProvider, IComponentConnector { private bool _contentLoaded; private TszButtonData _curCmd; private ExternalCommandData _extCmdData; private ExternalEvent _externalEvent; private RvtCmdExternalEventHandler _handler; private int m_bottom = 1; private int m_left = 1; private DockPosition m_position = DockPosition.Bottom; private int m_right = 1; private Guid m_targetGuid; private int m_top = 1; internal OutlookBar obMenu; public ScreenMenu() { this.InitializeComponent(); this._handler = new RvtCmdExternalEventHandler(this._extCmdData); this._externalEvent = ExternalEvent.Create(this._handler); } [GeneratedCode("PresentationBuildTasks", "4.0.0.0"), DebuggerNonUserCode] internal Delegate _CreateDelegate(System.Type delegateType, string handler) { return Delegate.CreateDelegate(delegateType, this, handler); } private void Host_SizeChanged(object sender, SizeChangedEventArgs e) { this.obMenu.UpdateSize(e.NewSize.Width, e.NewSize.Height); } [GeneratedCode("PresentationBuildTasks", "4.0.0.0"), DebuggerNonUserCode] public void InitializeComponent() { if (!this._contentLoaded) { this._contentLoaded = true; Uri resourceLocator = new Uri("/TSZ.RevitMenu;component/screenmenu.xaml", UriKind.Relative); System.Windows.Application.LoadComponent(this, resourceLocator); } } private void Page_FocusableChanged(object sender, DependencyPropertyChangedEventArgs e) { this.UpdateSize(); } public void PanelEvent(object sender, EventArgs e) { try { if (this._extCmdData != null) { System.Windows.Forms.Control control = (System.Windows.Forms.Control) sender; this._curCmd = control.Tag as TszButtonData; if (this._curCmd != null) { this._extCmdData.Application.ActiveViewFocus(); this._handler.CurBtnCmd = this._curCmd; this._externalEvent.Raise(); this.UpdateSize(); } } } catch (Exception exception) { MessageShow.Show(exception, false, ""); } } private void ScreenMenu_OnLoaded(object sender, RoutedEventArgs e) { if (this.obMenu.Controls.Count <= 0) { try { bool blnRevit = false; foreach (TszTabData data in MenuConfig.GetConfigTabs(Globals.UiApp.ControlledApplication.VersionNumber, out blnRevit)) { if (data.TabText != "MTSMENU") { CmdPanel panel = new CmdPanel(); this.obMenu.AddTabButton(data.TabName, panel); foreach (TszPanelData data2 in data.Panels) { foreach (TszButtonData data3 in data2.Buttons) { string path = data3.ImageName + "16.png"; if (File.Exists(path)) { string caption = data3.ButtonText.Replace(" ", "").Replace("\r\n", "").Replace("\n", ""); panel.AddCmdButton(caption, System.Drawing.Image.FromFile(path), data3, new EventHandler(this.PanelEvent)); } } } } } this.obMenu.SelectTabButton(0); } catch (Exception exception) { MessageShow.Show(exception, false, ""); } } } public void SetCmdData(ExternalCommandData cmdData) { this.ExtCmdData = cmdData; if (this._handler != null) { this._handler.ExtCmdData = cmdData; } } public void SetInitialDockingParameters(int left, int right, int top, int bottom, DockPosition position, Guid targetGuid) { this.m_position = position; this.m_left = left; this.m_right = right; this.m_top = top; this.m_bottom = bottom; this.m_targetGuid = targetGuid; } public void SetupDockablePane(DockablePaneProviderData data) { DockablePaneId id; data.FrameworkElement = this; data.InitialState = new DockablePaneState(); data.InitialState.DockPosition = this.m_position; if (this.m_targetGuid == Guid.Empty) { id = null; } else { id = new DockablePaneId(this.m_targetGuid); } if (this.m_position == DockPosition.Tabbed) { data.InitialState.TabBehind = id; } if (this.m_position == DockPosition.Floating) { data.InitialState.SetFloatingRectangle(new Autodesk.Revit.UI.Rectangle(this.m_left, this.m_top, this.m_right, this.m_bottom)); } } [GeneratedCode("PresentationBuildTasks", "4.0.0.0"), EditorBrowsable(EditorBrowsableState.Never), DebuggerNonUserCode] void IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: ((ScreenMenu) target).Loaded += new RoutedEventHandler(this.ScreenMenu_OnLoaded); ((ScreenMenu) target).SizeChanged += new SizeChangedEventHandler(this.Host_SizeChanged); ((ScreenMenu) target).FocusableChanged += new DependencyPropertyChangedEventHandler(this.Page_FocusableChanged); return; case 2: ((WindowsFormsHost) target).SizeChanged += new SizeChangedEventHandler(this.Host_SizeChanged); ((WindowsFormsHost) target).FocusableChanged += new DependencyPropertyChangedEventHandler(this.Page_FocusableChanged); return; case 3: ((Grid) target).SizeChanged += new SizeChangedEventHandler(this.Host_SizeChanged); return; case 4: ((WindowsFormsHost) target).SizeChanged += new SizeChangedEventHandler(this.Host_SizeChanged); return; case 5: this.obMenu = (OutlookBar) target; return; } this._contentLoaded = true; } private void UpdateSize() { this.obMenu.UpdateSize(base.RenderSize.Width, base.RenderSize.Height); } public ExternalCommandData ExtCmdData { set { this._extCmdData = value; } } } }