using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Safedispatch_4_0; namespace Dispatcher.maptab { public partial class MenuControl : UserControl { public enum UITheme { Blue, Light, Teal }; [Description("Theme"), Category("Data")] private UITheme _theme; public UITheme Theme { get { return _theme; } set { _theme = value; ApplyThemeToUI(_theme); } } private int rowCount = 0; private Tabs previousTab; public MenuControl() { InitializeComponent(); previousTab = Tabs.LIVE; // create the toolTip that will be displayed toolTip = new ToolTip(); toolTip.AutoPopDelay = 500; toolTip.InitialDelay = 500; toolTip.ReshowDelay = 500; toolTip.IsBalloon = false; toolTip.ShowAlways = true; //this.SuspendLayout(); AddMenuButton(menuLive); AddMenuButton(menuGeofence); AddMenuButton(menuHistory); AddMenuButton(menuText); AddMenuButton(menuTicketing); AddMenuButton(menuReports); AddMenuButton(menuVoice); AddMenuButton(menuTelemetry); AddMenuButton(menuSystem); //this.ResumeLayout(); } /// /// Add a menu button to the table panel /// /// Button which needs to be added private void AddMenuButton(MenuButton button) { //rowCount = tablePanel.RowCount; RowStyle style = new RowStyle(SizeType.AutoSize); tablePanel.RowStyles.Add(style); //tablePanel.RowCount = tablePanel.RowStyles.Count; // add button to the panel tablePanel.Controls.Add(button, 0, rowCount++); } /// /// Event handler for when the button is clicked. This will change /// the UI for all others buttons /// /// The menu button which was clicked private void MenuButton_Click(object sender, EventArgs e) { // go through all the controls in order to get // the menu buttons foreach (Control ctr in tablePanel.Controls) { // check if current control is a Menu Button if (ctr is MenuButton) { // select or deselect it depending on it's state MenuButton bt = ctr as MenuButton; if ((MenuButton)sender == bt) { ChangeTab(bt, true); } else bt.IsSelected = false; } } } /// /// Event handler for when the button is clicked. This will change /// the UI for all others buttons /// /// The menu button which was double clicked private void MenuButton_DoubleClick(object sender, EventArgs e) { // trigger the menu button click in order to change the state of this button //MenuButton_Click(sender, e); // go through all the controls in order to get // the menu buttons foreach (Control ctr in tablePanel.Controls) { // check if current control is a Menu Button if (ctr is MenuButton) { // select or deselect it depending on it's state MenuButton bt = ctr as MenuButton; if ((MenuButton)sender == bt) { // raise the event for when the Live button is Double Clicked if (bt == menuLive) this.OnLiveDoubleClicked(new MenuClickEventArgs() { PreviousTab = previousTab }); // raise the event for when the Geofence button is Double Clicked else if (bt == menuGeofence) this.OnGeofenceDoubleClicked(new MenuClickEventArgs() { PreviousTab = previousTab }); // raise the event for when the History button is Double Clicked else if (bt == menuHistory) this.OnHistoryDoubleClicked(new MenuClickEventArgs() { PreviousTab = previousTab }); // raise the event for when the Text button is Double Clicked else if (bt == menuText) this.OnTextDoubleClicked(new MenuClickEventArgs() { PreviousTab = previousTab }); // raise the event for when the Ticketing button is Double Clicked else if (bt == menuTicketing) this.OnTicketingDoubleClicked(new MenuClickEventArgs() { PreviousTab = previousTab }); // raise the event for when the Reports button is Double Clicked else if (bt == menuReports) this.OnReportsDoubleClicked(new MenuClickEventArgs() { PreviousTab = previousTab }); // raise the event for when the Voice button is Double Clicked else if (bt == menuVoice) this.OnVoiceDoubleClicked(new MenuClickEventArgs() { PreviousTab = previousTab }); // raise the event for when the Telemetry button is Double Clicked else if (bt == menuTelemetry) this.OnTelemetryDoubleClicked(new MenuClickEventArgs() { PreviousTab = previousTab }); // raise the event for when the System button is Double Clicked else if (bt == menuSystem) this.OnSystemDoubleClicked(new MenuClickEventArgs() { PreviousTab = previousTab }); } } } } /// /// Handle the Alerts click /// private void pbAlerts_Click(object sender, EventArgs e) { // raise the event for when the Alerts are clicked this.OnAlertsClicked(new AlertsEventArgs() { Empty = "" }); } /// /// Change the UI style /// /// private void ApplyThemeToUI(UITheme theme) { if (theme == UITheme.Light) { pbAlerts.Image = Dispatcher.Properties.Resources.t_alert_b; pbSettings.Image = Dispatcher.Properties.Resources.t_settings_b; labelSettings.ForeColor = Color.FromArgb(0, 0, 0); labelAlert.ForeColor = Color.FromArgb(0, 0, 0); panelTop.BackColor = Color.FromArgb(255, 255, 255); } else if (theme == UITheme.Blue) { pbAlerts.Image = Dispatcher.Properties.Resources.t_alert; pbSettings.Image = Dispatcher.Properties.Resources.t_settings; labelSettings.ForeColor = Color.FromArgb(162, 229, 255); labelAlert.ForeColor = Color.FromArgb(162, 229, 255); panelTop.BackColor = Color.FromArgb(12, 121, 203); } menuLive.Theme = (theme == UITheme.Light ? MenuButton.ThemeStyle.Light : MenuButton.ThemeStyle.Blue); menuGeofence.Theme = (theme == UITheme.Light ? MenuButton.ThemeStyle.Light : MenuButton.ThemeStyle.Blue); menuHistory.Theme = (theme == UITheme.Light ? MenuButton.ThemeStyle.Light : MenuButton.ThemeStyle.Blue); menuText.Theme = (theme == UITheme.Light ? MenuButton.ThemeStyle.Light : MenuButton.ThemeStyle.Blue); menuTicketing.Theme = (theme == UITheme.Light ? MenuButton.ThemeStyle.Light : MenuButton.ThemeStyle.Blue); menuReports.Theme = (theme == UITheme.Light ? MenuButton.ThemeStyle.Light : MenuButton.ThemeStyle.Blue); menuVoice.Theme = (theme == UITheme.Light ? MenuButton.ThemeStyle.Light : MenuButton.ThemeStyle.Blue); menuTelemetry.Theme = (theme == UITheme.Light ? MenuButton.ThemeStyle.Light : MenuButton.ThemeStyle.Blue); menuSystem.Theme = (theme == UITheme.Light ? MenuButton.ThemeStyle.Light : MenuButton.ThemeStyle.Blue); } private void ChangeTab(MenuButton bt, bool raiseEvent) { // raise the event for when the Live button is clicked if (bt == menuLive) { if(raiseEvent) this.OnLiveClicked(new MenuClickEventArgs() { PreviousTab = previousTab }); previousTab = Tabs.LIVE; } // raise the event for when the Geofence button is clicked else if (bt == menuGeofence) { if (raiseEvent) this.OnGeofenceClicked(new MenuClickEventArgs() { PreviousTab = previousTab }); previousTab = Tabs.GEOFENCE; } // raise the event for when the History button is clicked else if (bt == menuHistory) { if (raiseEvent) this.OnHistoryClicked(new MenuClickEventArgs() { PreviousTab = previousTab }); previousTab = Tabs.HISTORY; } // raise the event for when the Text button is clicked else if (bt == menuText) { if (raiseEvent) this.OnTextClicked(new MenuClickEventArgs() { PreviousTab = previousTab }); previousTab = Tabs.TEXT; } // raise the event for when the Ticketing button is clicked else if (bt == menuTicketing) { if (raiseEvent) this.OnTicketingClicked(new MenuClickEventArgs() { PreviousTab = previousTab }); previousTab = Tabs.TICKETING; } // raise the event for when the Reports button is clicked else if (bt == menuReports) { if (raiseEvent) this.OnReportsClicked(new MenuClickEventArgs() { PreviousTab = previousTab }); previousTab = Tabs.REPORTS; } // raise the event for when the Voice button is clicked else if (bt == menuVoice) { if (raiseEvent) this.OnVoiceClicked(new MenuClickEventArgs() { PreviousTab = previousTab }); previousTab = Tabs.VOICE; } // raise the event for when the Telemetry button is clicked else if (bt == menuTelemetry) { if (raiseEvent) this.OnTelemetryClicked(new MenuClickEventArgs() { PreviousTab = previousTab }); previousTab = Tabs.TELEMETRY; } // raise the event for when the System button is clicked else if (bt == menuSystem) { if (raiseEvent) this.OnSystemClicked(new MenuClickEventArgs() { PreviousTab = previousTab }); previousTab = Tabs.SYSTEM; } bt.IsSelected = true; } /// /// Set the desired Tab as a consequence of a programmatically /// change of the tab /// /// Desired tab which needs to be activated public void SetTab(Tabs tab, bool raiseEvent) { if (tab == Tabs.LIVE) ChangeTab(menuLive, false); else if (tab == Tabs.GEOFENCE) ChangeTab(menuGeofence, false); else if (tab == Tabs.HISTORY) ChangeTab(menuHistory, false); else if (tab == Tabs.TEXT) ChangeTab(menuText, false); else if (tab == Tabs.TICKETING) ChangeTab(menuTicketing, false); else if (tab == Tabs.REPORTS) ChangeTab(menuReports, false); else if (tab == Tabs.VOICE) ChangeTab(menuVoice, false); else if (tab == Tabs.TELEMETRY) ChangeTab(menuTelemetry, false); else if (tab == Tabs.SYSTEM) ChangeTab(menuSystem, false); } /// /// Change the name of the dispatcher inside the menu control /// /// Name of the logged in dispatcher public void SetDispatcherName(String dispatcher) { labelDispatcher.Text = dispatcher.ToUpper(); } #region EVENTS public class AlertsEventArgs : EventArgs { public String Empty { get; set; } } public event EventHandler AlertsClicked; /// /// Event raise for when the alerts are clicked /// protected virtual void OnAlertsClicked(AlertsEventArgs e) { EventHandler handler = this.AlertsClicked; if (handler != null) handler(this, e); } public class MenuClickEventArgs : EventArgs { public Tabs PreviousTab { get; set; } //public Tabs SelectedTab { get; set; } } public event EventHandler MenuButtonClicked; /// /// Event raise for when a menu button is Clicked /// protected virtual void OnMenuButtonClicked(MenuClickEventArgs e) { EventHandler handler = this.MenuButtonClicked; if (handler != null) handler(this, e); } /// /// Event raise for when live button is Clicked & DoubleClicked /// public event EventHandler LiveClicked; public event EventHandler LiveDoubleClicked; protected virtual void OnLiveClicked(MenuClickEventArgs e) { EventHandler handler = this.LiveClicked; if (handler != null) handler(this, e); } protected virtual void OnLiveDoubleClicked(MenuClickEventArgs e) { EventHandler handler = this.LiveDoubleClicked; if (handler != null) handler(this, e); } /// /// Event raise for when geofence button is Clicked & DoubleClicked /// public event EventHandler GeofenceClicked; public event EventHandler GeofenceDoubleClicked; protected virtual void OnGeofenceClicked(MenuClickEventArgs e) { EventHandler handler = this.GeofenceClicked; if (handler != null) handler(this, e); } protected virtual void OnGeofenceDoubleClicked(MenuClickEventArgs e) { EventHandler handler = this.GeofenceDoubleClicked; if (handler != null) handler(this, e); } /// /// Event raise for when history button is Clicked & DoubleClicked /// public event EventHandler HistoryClicked; public event EventHandler HistoryDoubleClicked; protected virtual void OnHistoryClicked(MenuClickEventArgs e) { EventHandler handler = this.HistoryClicked; if (handler != null) handler(this, e); } protected virtual void OnHistoryDoubleClicked(MenuClickEventArgs e) { EventHandler handler = this.HistoryDoubleClicked; if (handler != null) handler(this, e); } /// /// Event raise for when text button is Clicked & DoubleClicked /// public event EventHandler TextClicked; public event EventHandler TextDoubleClicked; protected virtual void OnTextClicked(MenuClickEventArgs e) { EventHandler handler = this.TextClicked; if (handler != null) handler(this, e); } protected virtual void OnTextDoubleClicked(MenuClickEventArgs e) { EventHandler handler = this.TextDoubleClicked; if (handler != null) handler(this, e); } /// /// Event raise for when text button is Clicked & DoubleClicked /// public event EventHandler TicketingClicked; public event EventHandler TicketingDoubleClicked; protected virtual void OnTicketingClicked(MenuClickEventArgs e) { EventHandler handler = this.TicketingClicked; if (handler != null) handler(this, e); } protected virtual void OnTicketingDoubleClicked(MenuClickEventArgs e) { EventHandler handler = this.TicketingDoubleClicked; if (handler != null) handler(this, e); } /// /// Event raise for when reports button is Clicked & DoubleClicked /// public event EventHandler ReportsClicked; public event EventHandler ReportsDoubleClicked; protected virtual void OnReportsClicked(MenuClickEventArgs e) { EventHandler handler = this.ReportsClicked; if (handler != null) handler(this, e); } protected virtual void OnReportsDoubleClicked(MenuClickEventArgs e) { EventHandler handler = this.ReportsDoubleClicked; if (handler != null) handler(this, e); } /// /// Event raise for when voice button is Clicked & DoubleClicked /// public event EventHandler VoiceClicked; public event EventHandler VoiceDoubleClicked; protected virtual void OnVoiceClicked(MenuClickEventArgs e) { EventHandler handler = this.VoiceClicked; if (handler != null) handler(this, e); } protected virtual void OnVoiceDoubleClicked(MenuClickEventArgs e) { EventHandler handler = this.VoiceDoubleClicked; if (handler != null) handler(this, e); } /// /// Event raise for when Telemetry button is Clicked & DoubleClicked /// public event EventHandler TelemetryClicked; public event EventHandler TelemetryDoubleClicked; protected virtual void OnTelemetryClicked(MenuClickEventArgs e) { EventHandler handler = this.TelemetryClicked; if (handler != null) handler(this, e); } protected virtual void OnTelemetryDoubleClicked(MenuClickEventArgs e) { EventHandler handler = this.TelemetryDoubleClicked; if (handler != null) handler(this, e); } /// /// Event raise for when System button is Clicked & DoubleClicked /// public event EventHandler SystemClicked; public event EventHandler SystemDoubleClicked; protected virtual void OnSystemClicked(MenuClickEventArgs e) { EventHandler handler = this.SystemClicked; if (handler != null) handler(this, e); } protected virtual void OnSystemDoubleClicked(MenuClickEventArgs e) { EventHandler handler = this.SystemDoubleClicked; if (handler != null) handler(this, e); } #endregion private Size largeSize = new Size(242, 814); private Point pbMenuLocation = new Point(); private Point pbAlertsLocation = new Point(); private Point pbSettingsLocation = new Point(); /// /// Intercept the click on the menu picture box /// in order to enlrage or shrink the menu, move the pictureboxex /// and hide/show others ui elements /// private void pbMenu_Click(object sender, EventArgs e) { if(pbMenu.Tag.Equals("large")) { this.SuspendLayout(); // save the current size largeSize = this.Size; // save current locations for pbMenu and others pbSettingsLocation = pbSettings.Location; pbAlertsLocation = pbAlerts.Location; pbMenuLocation = pbMenu.Location; // shrink the size this.Size = new Size(55, largeSize.Height); this.ResumeLayout(); pbMenu.Tag = "small"; pbIcon.Visible = false; labelDispatcher.Visible = false; labelWelcome.Visible = false; labelAlert.Visible = false; labelSettings.Visible = false; pbMenu.Location = new Point(7, 13); pbAlerts.Location = new Point(7, 59); pbSettings.Location = new Point(7, 105); } else { this.SuspendLayout(); // restore the size this.Size = new Size(largeSize.Width + 9, largeSize.Height); this.ResumeLayout(); pbMenu.Tag = "large"; pbIcon.Visible = true; labelDispatcher.Visible = true; labelWelcome.Visible = true; labelAlert.Visible = true; labelSettings.Visible = true; pbMenu.Location = pbMenuLocation; pbAlerts.Location = pbAlertsLocation; pbSettings.Location = pbSettingsLocation; } } #region TOOLTIP private void PictureBox_MouseEnter(object sender, EventArgs e) { if (sender is PictureBox) { PictureBox box = (PictureBox)sender; DisplayToolTip(sender, (box == pbAlerts ? " " + "Alerts" + " " : (box == pbSettings ? " " + "Settings" + " " : " " + "Menu" + " "))); } } private void PictureBox_MouseHover(object sender, EventArgs e) { if (sender is PictureBox) { PictureBox box = (PictureBox)sender; DisplayToolTip(sender, (box == pbAlerts ? " " + "Alerts" + " " : (box == pbSettings ? " " + "Settings" + " " : " " + "Menu" + " "))); } } private void PictureBox_MouseLeave(object sender, EventArgs e) { if (sender is PictureBox) toolTip.Hide((PictureBox)sender); } /// /// Show a tooltip with the desired message to a specific control /// /// Control to which the tooltip is attached /// Message which is written inside the tooltip private void DisplayToolTip(object sender, string message) { toolTip.Show(" " + message + " ", (Control)sender, 15000); } #endregion } }