1.1 --- a/Server/MainForm.cs Wed Jul 27 11:07:35 2016 +0200
1.2 +++ b/Server/MainForm.cs Wed Jul 27 15:05:58 2016 +0200
1.3 @@ -52,23 +52,33 @@
1.4 {
1.5 //Types declarations
1.6 public delegate uint ColorProcessingDelegate(int aX, int aY, uint aPixel);
1.7 +
1.8 public delegate int CoordinateTranslationDelegate(System.Drawing.Bitmap aBmp, int aInt);
1.9 +
1.10 //Delegates are used for our thread safe method
1.11 public delegate void AddClientDelegate(string aSessionId, ICallback aCallback);
1.12 +
1.13 public delegate void RemoveClientDelegate(string aSessionId);
1.14 +
1.15 public delegate void SetFieldDelegate(string SessionId, DataField aField);
1.16 +
1.17 public delegate void SetFieldsDelegate(string SessionId, System.Collections.Generic.IList<DataField> aFields);
1.18 +
1.19 public delegate void SetLayoutDelegate(string SessionId, TableLayout aLayout);
1.20 +
1.21 public delegate void SetClientNameDelegate(string aSessionId, string aName);
1.22 +
1.23 public delegate void SetClientPriorityDelegate(string aSessionId, uint aPriority);
1.24 +
1.25 public delegate void PlainUpdateDelegate();
1.26 +
1.27 public delegate void WndProcDelegate(ref Message aMessage);
1.28
1.29 /// <summary>
1.30 /// Our Display manager main form
1.31 /// </summary>
1.32 - [System.ComponentModel.DesignerCategory("Form")]
1.33 - public partial class MainForm : MainFormHid, IMMNotificationClient
1.34 + [System.ComponentModel.DesignerCategory("Form")]
1.35 + public partial class MainForm : MainFormHid, IMMNotificationClient
1.36 {
1.37 //public ManagerEventAction iManager = new ManagerEventAction();
1.38 DateTime LastTickTime;
1.39 @@ -83,35 +93,35 @@
1.40 ClientData iCurrentClientData;
1.41 //
1.42 public bool iClosing;
1.43 - //
1.44 - public bool iSkipFrameRendering;
1.45 + //
1.46 + public bool iSkipFrameRendering;
1.47 //Function pointer for pixel color filtering
1.48 ColorProcessingDelegate iColorFx;
1.49 //Function pointer for pixel X coordinate intercept
1.50 CoordinateTranslationDelegate iScreenX;
1.51 //Function pointer for pixel Y coordinate intercept
1.52 CoordinateTranslationDelegate iScreenY;
1.53 - //NAudio
1.54 - private MMDeviceEnumerator iMultiMediaDeviceEnumerator;
1.55 - private MMDevice iMultiMediaDevice;
1.56 - //Network
1.57 - private NetworkManager iNetworkManager;
1.58 + //NAudio
1.59 + private MMDeviceEnumerator iMultiMediaDeviceEnumerator;
1.60 + private MMDevice iMultiMediaDevice;
1.61 + //Network
1.62 + private NetworkManager iNetworkManager;
1.63
1.64 /// <summary>
1.65 /// CEC - Consumer Electronic Control.
1.66 /// Notably used to turn TV on and off as Windows broadcast monitor on and off notifications.
1.67 /// </summary>
1.68 private ConsumerElectronicControl iCecManager;
1.69 -
1.70 - /// <summary>
1.71 - /// Manage run when Windows startup option
1.72 - /// </summary>
1.73 - private StartupManager iStartupManager;
1.74 -
1.75 - /// <summary>
1.76 - /// System notification icon used to hide our application from the task bar.
1.77 - /// </summary>
1.78 - private SharpLib.Notification.Control iNotifyIcon;
1.79 +
1.80 + /// <summary>
1.81 + /// Manage run when Windows startup option
1.82 + /// </summary>
1.83 + private StartupManager iStartupManager;
1.84 +
1.85 + /// <summary>
1.86 + /// System notification icon used to hide our application from the task bar.
1.87 + /// </summary>
1.88 + private SharpLib.Notification.Control iNotifyIcon;
1.89
1.90 /// <summary>
1.91 /// System recording notification icon.
1.92 @@ -145,18 +155,18 @@
1.93 ManagerEventAction.Current.Init();
1.94 }
1.95 iSkipFrameRendering = false;
1.96 - iClosing = false;
1.97 + iClosing = false;
1.98 iCurrentClientSessionId = "";
1.99 iCurrentClientData = null;
1.100 LastTickTime = DateTime.Now;
1.101 - //Instantiate our display and register for events notifications
1.102 + //Instantiate our display and register for events notifications
1.103 iDisplay = new Display();
1.104 - iDisplay.OnOpened += OnDisplayOpened;
1.105 - iDisplay.OnClosed += OnDisplayClosed;
1.106 - //
1.107 - iClients = new Dictionary<string, ClientData>();
1.108 - iStartupManager = new StartupManager();
1.109 - iNotifyIcon = new SharpLib.Notification.Control();
1.110 + iDisplay.OnOpened += OnDisplayOpened;
1.111 + iDisplay.OnClosed += OnDisplayClosed;
1.112 + //
1.113 + iClients = new Dictionary<string, ClientData>();
1.114 + iStartupManager = new StartupManager();
1.115 + iNotifyIcon = new SharpLib.Notification.Control();
1.116 iRecordingNotification = new SharpLib.Notification.Control();
1.117
1.118 //Have our designer initialize its controls
1.119 @@ -172,50 +182,51 @@
1.120 //Populate optical drives
1.121 PopulateOpticalDrives();
1.122
1.123 - //Initial status update
1.124 + //Initial status update
1.125 UpdateStatus();
1.126
1.127 //We have a bug when drawing minimized and reusing our bitmap
1.128 //Though I could not reproduce it on Windows 10
1.129 - iBmp = new System.Drawing.Bitmap(iTableLayoutPanel.Width, iTableLayoutPanel.Height, PixelFormat.Format32bppArgb);
1.130 + iBmp = new System.Drawing.Bitmap(iTableLayoutPanel.Width, iTableLayoutPanel.Height,
1.131 + PixelFormat.Format32bppArgb);
1.132 iCreateBitmap = false;
1.133
1.134 - //Minimize our window if desired
1.135 - if (Properties.Settings.Default.StartMinimized)
1.136 - {
1.137 - WindowState = FormWindowState.Minimized;
1.138 - }
1.139 + //Minimize our window if desired
1.140 + if (Properties.Settings.Default.StartMinimized)
1.141 + {
1.142 + WindowState = FormWindowState.Minimized;
1.143 + }
1.144
1.145 }
1.146
1.147 - /// <summary>
1.148 - ///
1.149 - /// </summary>
1.150 - /// <param name="sender"></param>
1.151 - /// <param name="e"></param>
1.152 + /// <summary>
1.153 + ///
1.154 + /// </summary>
1.155 + /// <param name="sender"></param>
1.156 + /// <param name="e"></param>
1.157 private void MainForm_Load(object sender, EventArgs e)
1.158 {
1.159 - //Check if we are running a Click Once deployed application
1.160 - if (ApplicationDeployment.IsNetworkDeployed)
1.161 - {
1.162 - //This is a proper Click Once installation, fetch and show our version number
1.163 - this.Text += " - v" + ApplicationDeployment.CurrentDeployment.CurrentVersion;
1.164 - }
1.165 - else
1.166 - {
1.167 - //Not a proper Click Once installation, assuming development build then
1.168 - this.Text += " - development";
1.169 - }
1.170 -
1.171 - //NAudio
1.172 - iMultiMediaDeviceEnumerator = new MMDeviceEnumerator();
1.173 - iMultiMediaDeviceEnumerator.RegisterEndpointNotificationCallback(this);
1.174 - UpdateAudioDeviceAndMasterVolumeThreadSafe();
1.175 -
1.176 - //Network
1.177 - iNetworkManager = new NetworkManager();
1.178 - iNetworkManager.OnConnectivityChanged += OnConnectivityChanged;
1.179 - UpdateNetworkStatus();
1.180 + //Check if we are running a Click Once deployed application
1.181 + if (ApplicationDeployment.IsNetworkDeployed)
1.182 + {
1.183 + //This is a proper Click Once installation, fetch and show our version number
1.184 + this.Text += " - v" + ApplicationDeployment.CurrentDeployment.CurrentVersion;
1.185 + }
1.186 + else
1.187 + {
1.188 + //Not a proper Click Once installation, assuming development build then
1.189 + this.Text += " - development";
1.190 + }
1.191 +
1.192 + //NAudio
1.193 + iMultiMediaDeviceEnumerator = new MMDeviceEnumerator();
1.194 + iMultiMediaDeviceEnumerator.RegisterEndpointNotificationCallback(this);
1.195 + UpdateAudioDeviceAndMasterVolumeThreadSafe();
1.196 +
1.197 + //Network
1.198 + iNetworkManager = new NetworkManager();
1.199 + iNetworkManager.OnConnectivityChanged += OnConnectivityChanged;
1.200 + UpdateNetworkStatus();
1.201
1.202 //CEC
1.203 iCecManager = new ConsumerElectronicControl();
1.204 @@ -233,29 +244,29 @@
1.205
1.206 // To make sure start up with minimize to tray works
1.207 if (WindowState == FormWindowState.Minimized && Properties.Settings.Default.MinimizeToTray)
1.208 - {
1.209 - Visible = false;
1.210 - }
1.211 + {
1.212 + Visible = false;
1.213 + }
1.214
1.215 #if !DEBUG
1.216 - //When not debugging we want the screen to be empty until a client takes over
1.217 + //When not debugging we want the screen to be empty until a client takes over
1.218 ClearLayout();
1.219 #else
1.220 - //When developing we want at least one client for testing
1.221 - StartNewClient("abcdefghijklmnopqrst-0123456789","ABCDEFGHIJKLMNOPQRST-0123456789");
1.222 + //When developing we want at least one client for testing
1.223 + StartNewClient("abcdefghijklmnopqrst-0123456789", "ABCDEFGHIJKLMNOPQRST-0123456789");
1.224 #endif
1.225
1.226 - //Open display connection on start-up if needed
1.227 - if (Properties.Settings.Default.DisplayConnectOnStartup)
1.228 - {
1.229 - OpenDisplayConnection();
1.230 - }
1.231 -
1.232 - //Start our server so that we can get client requests
1.233 - StartServer();
1.234 -
1.235 - //Register for HID events
1.236 - RegisterHidDevices();
1.237 + //Open display connection on start-up if needed
1.238 + if (Properties.Settings.Default.DisplayConnectOnStartup)
1.239 + {
1.240 + OpenDisplayConnection();
1.241 + }
1.242 +
1.243 + //Start our server so that we can get client requests
1.244 + StartServer();
1.245 +
1.246 + //Register for HID events
1.247 + RegisterHidDevices();
1.248
1.249 //Start Idle client if needed
1.250 if (Properties.Settings.Default.StartIdleClient)
1.251 @@ -264,40 +275,40 @@
1.252 }
1.253 }
1.254
1.255 - /// <summary>
1.256 - /// Called when our display is opened.
1.257 - /// </summary>
1.258 - /// <param name="aDisplay"></param>
1.259 - private void OnDisplayOpened(Display aDisplay)
1.260 - {
1.261 + /// <summary>
1.262 + /// Called when our display is opened.
1.263 + /// </summary>
1.264 + /// <param name="aDisplay"></param>
1.265 + private void OnDisplayOpened(Display aDisplay)
1.266 + {
1.267 //Make sure we resume frame rendering
1.268 iSkipFrameRendering = false;
1.269
1.270 - //Set our screen size now that our display is connected
1.271 - //Our panelDisplay is the container of our tableLayoutPanel
1.272 - //tableLayoutPanel will resize itself to fit the client size of our panelDisplay
1.273 - //panelDisplay needs an extra 2 pixels for borders on each sides
1.274 - //tableLayoutPanel will eventually be the exact size of our display
1.275 - Size size = new Size(iDisplay.WidthInPixels() + 2, iDisplay.HeightInPixels() + 2);
1.276 - panelDisplay.Size = size;
1.277 -
1.278 - //Our display was just opened, update our UI
1.279 - UpdateStatus();
1.280 - //Initiate asynchronous request
1.281 - iDisplay.RequestFirmwareRevision();
1.282 -
1.283 - //Audio
1.284 - UpdateMasterVolumeThreadSafe();
1.285 - //Network
1.286 - UpdateNetworkStatus();
1.287 + //Set our screen size now that our display is connected
1.288 + //Our panelDisplay is the container of our tableLayoutPanel
1.289 + //tableLayoutPanel will resize itself to fit the client size of our panelDisplay
1.290 + //panelDisplay needs an extra 2 pixels for borders on each sides
1.291 + //tableLayoutPanel will eventually be the exact size of our display
1.292 + Size size = new Size(iDisplay.WidthInPixels() + 2, iDisplay.HeightInPixels() + 2);
1.293 + panelDisplay.Size = size;
1.294 +
1.295 + //Our display was just opened, update our UI
1.296 + UpdateStatus();
1.297 + //Initiate asynchronous request
1.298 + iDisplay.RequestFirmwareRevision();
1.299 +
1.300 + //Audio
1.301 + UpdateMasterVolumeThreadSafe();
1.302 + //Network
1.303 + UpdateNetworkStatus();
1.304
1.305 #if DEBUG
1.306 - //Testing icon in debug, no arm done if icon not supported
1.307 - //iDisplay.SetIconStatus(Display.TMiniDisplayIconType.EMiniDisplayIconRecording, 0, 1);
1.308 - //iDisplay.SetAllIconsStatus(2);
1.309 + //Testing icon in debug, no arm done if icon not supported
1.310 + //iDisplay.SetIconStatus(Display.TMiniDisplayIconType.EMiniDisplayIconRecording, 0, 1);
1.311 + //iDisplay.SetAllIconsStatus(2);
1.312 #endif
1.313
1.314 - }
1.315 + }
1.316
1.317 /// <summary>
1.318 /// Populate tree view with events and actions
1.319 @@ -309,6 +320,8 @@
1.320 buttonDeleteAction.Enabled = false;
1.321
1.322 Event currentEvent = CurrentEvent();
1.323 + SharpLib.Ear.Action currentAction = CurrentAction();
1.324 + TreeNode treeNodeToSelect = null;
1.325
1.326 //Reset our tree
1.327 iTreeViewEvents.Nodes.Clear();
1.328 @@ -316,7 +329,7 @@
1.329 foreach (string key in ManagerEventAction.Current.Events.Keys)
1.330 {
1.331 Event e = ManagerEventAction.Current.Events[key];
1.332 - TreeNode eventNode = iTreeViewEvents.Nodes.Add(key,e.Name);
1.333 + TreeNode eventNode = iTreeViewEvents.Nodes.Add(key, e.Name);
1.334 eventNode.Tag = e;
1.335 eventNode.Nodes.Add(key + ".Description", e.Description);
1.336 TreeNode actionsNodes = eventNode.Nodes.Add(key + ".Actions", "Actions");
1.337 @@ -326,82 +339,96 @@
1.338 {
1.339 TreeNode actionNode = actionsNodes.Nodes.Add(a.Brief());
1.340 actionNode.Tag = a;
1.341 + if (a == currentAction)
1.342 + {
1.343 + treeNodeToSelect = actionNode;
1.344 + }
1.345 }
1.346 }
1.347
1.348 iTreeViewEvents.ExpandAll();
1.349 SelectEvent(currentEvent);
1.350 - //Select the last action if any
1.351 - if (iTreeViewEvents.SelectedNode!= null && iTreeViewEvents.SelectedNode.Nodes[1].GetNodeCount(false) > 0)
1.352 +
1.353 + if (treeNodeToSelect != null)
1.354 {
1.355 - iTreeViewEvents.SelectedNode = iTreeViewEvents.SelectedNode.Nodes[1].Nodes[iTreeViewEvents.SelectedNode.Nodes[1].GetNodeCount(false)-1];
1.356 + iTreeViewEvents.SelectedNode = treeNodeToSelect;
1.357 }
1.358 + else if (iTreeViewEvents.SelectedNode != null && iTreeViewEvents.SelectedNode.Nodes[1].GetNodeCount(false) > 0)
1.359 + {
1.360 + //Select the last action if any
1.361 + iTreeViewEvents.SelectedNode =
1.362 + iTreeViewEvents.SelectedNode.Nodes[1].Nodes[
1.363 + iTreeViewEvents.SelectedNode.Nodes[1].GetNodeCount(false) - 1];
1.364 + }
1.365
1.366 }
1.367
1.368 - /// <summary>
1.369 - /// Called when our display is closed.
1.370 - /// </summary>
1.371 - /// <param name="aDisplay"></param>
1.372 - private void OnDisplayClosed(Display aDisplay)
1.373 - {
1.374 + /// <summary>
1.375 + /// Called when our display is closed.
1.376 + /// </summary>
1.377 + /// <param name="aDisplay"></param>
1.378 + private void OnDisplayClosed(Display aDisplay)
1.379 + {
1.380 //Our display was just closed, update our UI consequently
1.381 UpdateStatus();
1.382 - }
1.383 -
1.384 - public void OnConnectivityChanged(NetworkManager aNetwork, NLM_CONNECTIVITY newConnectivity)
1.385 - {
1.386 - //Update network status
1.387 - UpdateNetworkStatus();
1.388 - }
1.389 -
1.390 - /// <summary>
1.391 - /// Update our Network Status
1.392 - /// </summary>
1.393 - private void UpdateNetworkStatus()
1.394 - {
1.395 - if (iDisplay.IsOpen())
1.396 - {
1.397 - iDisplay.SetIconOnOff(MiniDisplay.IconType.Internet, iNetworkManager.NetworkListManager.IsConnectedToInternet);
1.398 + }
1.399 +
1.400 + public void OnConnectivityChanged(NetworkManager aNetwork, NLM_CONNECTIVITY newConnectivity)
1.401 + {
1.402 + //Update network status
1.403 + UpdateNetworkStatus();
1.404 + }
1.405 +
1.406 + /// <summary>
1.407 + /// Update our Network Status
1.408 + /// </summary>
1.409 + private void UpdateNetworkStatus()
1.410 + {
1.411 + if (iDisplay.IsOpen())
1.412 + {
1.413 + iDisplay.SetIconOnOff(MiniDisplay.IconType.Internet,
1.414 + iNetworkManager.NetworkListManager.IsConnectedToInternet);
1.415 iDisplay.SetIconOnOff(MiniDisplay.IconType.NetworkSignal, iNetworkManager.NetworkListManager.IsConnected);
1.416 - }
1.417 - }
1.418 -
1.419 -
1.420 - int iLastNetworkIconIndex = 0;
1.421 - int iUpdateCountSinceLastNetworkAnimation = 0;
1.422 -
1.423 - /// <summary>
1.424 - ///
1.425 - /// </summary>
1.426 - private void UpdateNetworkSignal(DateTime aLastTickTime, DateTime aNewTickTime)
1.427 - {
1.428 - iUpdateCountSinceLastNetworkAnimation++;
1.429 - iUpdateCountSinceLastNetworkAnimation = iUpdateCountSinceLastNetworkAnimation % 4;
1.430 -
1.431 - if (iDisplay.IsOpen() && iNetworkManager.NetworkListManager.IsConnected && iUpdateCountSinceLastNetworkAnimation==0)
1.432 - {
1.433 + }
1.434 + }
1.435 +
1.436 +
1.437 + int iLastNetworkIconIndex = 0;
1.438 + int iUpdateCountSinceLastNetworkAnimation = 0;
1.439 +
1.440 + /// <summary>
1.441 + ///
1.442 + /// </summary>
1.443 + private void UpdateNetworkSignal(DateTime aLastTickTime, DateTime aNewTickTime)
1.444 + {
1.445 + iUpdateCountSinceLastNetworkAnimation++;
1.446 + iUpdateCountSinceLastNetworkAnimation = iUpdateCountSinceLastNetworkAnimation%4;
1.447 +
1.448 + if (iDisplay.IsOpen() && iNetworkManager.NetworkListManager.IsConnected &&
1.449 + iUpdateCountSinceLastNetworkAnimation == 0)
1.450 + {
1.451 int iconCount = iDisplay.IconCount(MiniDisplay.IconType.NetworkSignal);
1.452 - if (iconCount <= 0)
1.453 - {
1.454 - //Prevents div by zero and other undefined behavior
1.455 - return;
1.456 - }
1.457 - iLastNetworkIconIndex++;
1.458 - iLastNetworkIconIndex = iLastNetworkIconIndex % (iconCount*2);
1.459 - for (int i=0;i<iconCount;i++)
1.460 - {
1.461 - if (i < iLastNetworkIconIndex && !(i == 0 && iLastNetworkIconIndex > 3) && !(i == 1 && iLastNetworkIconIndex > 4))
1.462 - {
1.463 + if (iconCount <= 0)
1.464 + {
1.465 + //Prevents div by zero and other undefined behavior
1.466 + return;
1.467 + }
1.468 + iLastNetworkIconIndex++;
1.469 + iLastNetworkIconIndex = iLastNetworkIconIndex%(iconCount*2);
1.470 + for (int i = 0; i < iconCount; i++)
1.471 + {
1.472 + if (i < iLastNetworkIconIndex && !(i == 0 && iLastNetworkIconIndex > 3) &&
1.473 + !(i == 1 && iLastNetworkIconIndex > 4))
1.474 + {
1.475 iDisplay.SetIconOn(MiniDisplay.IconType.NetworkSignal, i);
1.476 - }
1.477 - else
1.478 - {
1.479 + }
1.480 + else
1.481 + {
1.482 iDisplay.SetIconOff(MiniDisplay.IconType.NetworkSignal, i);
1.483 - }
1.484 - }
1.485 - }
1.486 - }
1.487 + }
1.488 + }
1.489 + }
1.490 + }
1.491
1.492
1.493
1.494 @@ -411,7 +438,7 @@
1.495 /// <param name="data"></param>
1.496 public void OnVolumeNotificationThreadSafe(AudioVolumeNotificationData data)
1.497 {
1.498 - UpdateMasterVolumeThreadSafe();
1.499 + UpdateMasterVolumeThreadSafe();
1.500 }
1.501
1.502 /// <summary>
1.503 @@ -421,42 +448,50 @@
1.504 /// <param name="e"></param>
1.505 private void trackBarMasterVolume_Scroll(object sender, EventArgs e)
1.506 {
1.507 - //Just like Windows Volume Mixer we unmute if the volume is adjusted
1.508 - iMultiMediaDevice.AudioEndpointVolume.Mute = false;
1.509 - //Set volume level according to our volume slider new position
1.510 - iMultiMediaDevice.AudioEndpointVolume.MasterVolumeLevelScalar = trackBarMasterVolume.Value / 100.0f;
1.511 + //Just like Windows Volume Mixer we unmute if the volume is adjusted
1.512 + iMultiMediaDevice.AudioEndpointVolume.Mute = false;
1.513 + //Set volume level according to our volume slider new position
1.514 + iMultiMediaDevice.AudioEndpointVolume.MasterVolumeLevelScalar = trackBarMasterVolume.Value/100.0f;
1.515 }
1.516
1.517
1.518 - /// <summary>
1.519 - /// Mute check box changed.
1.520 - /// </summary>
1.521 - /// <param name="sender"></param>
1.522 - /// <param name="e"></param>
1.523 - private void checkBoxMute_CheckedChanged(object sender, EventArgs e)
1.524 - {
1.525 - iMultiMediaDevice.AudioEndpointVolume.Mute = checkBoxMute.Checked;
1.526 - }
1.527 + /// <summary>
1.528 + /// Mute check box changed.
1.529 + /// </summary>
1.530 + /// <param name="sender"></param>
1.531 + /// <param name="e"></param>
1.532 + private void checkBoxMute_CheckedChanged(object sender, EventArgs e)
1.533 + {
1.534 + iMultiMediaDevice.AudioEndpointVolume.Mute = checkBoxMute.Checked;
1.535 + }
1.536
1.537 /// <summary>
1.538 /// Device State Changed
1.539 /// </summary>
1.540 - public void OnDeviceStateChanged([MarshalAs(UnmanagedType.LPWStr)] string deviceId, [MarshalAs(UnmanagedType.I4)] DeviceState newState){}
1.541 + public void OnDeviceStateChanged([MarshalAs(UnmanagedType.LPWStr)] string deviceId,
1.542 + [MarshalAs(UnmanagedType.I4)] DeviceState newState)
1.543 + {
1.544 + }
1.545
1.546 /// <summary>
1.547 /// Device Added
1.548 /// </summary>
1.549 - public void OnDeviceAdded([MarshalAs(UnmanagedType.LPWStr)] string pwstrDeviceId) { }
1.550 + public void OnDeviceAdded([MarshalAs(UnmanagedType.LPWStr)] string pwstrDeviceId)
1.551 + {
1.552 + }
1.553
1.554 /// <summary>
1.555 /// Device Removed
1.556 /// </summary>
1.557 - public void OnDeviceRemoved([MarshalAs(UnmanagedType.LPWStr)] string deviceId) { }
1.558 + public void OnDeviceRemoved([MarshalAs(UnmanagedType.LPWStr)] string deviceId)
1.559 + {
1.560 + }
1.561
1.562 /// <summary>
1.563 /// Default Device Changed
1.564 /// </summary>
1.565 - public void OnDefaultDeviceChanged(DataFlow flow, Role role, [MarshalAs(UnmanagedType.LPWStr)] string defaultDeviceId)
1.566 + public void OnDefaultDeviceChanged(DataFlow flow, Role role,
1.567 + [MarshalAs(UnmanagedType.LPWStr)] string defaultDeviceId)
1.568 {
1.569 if (role == Role.Multimedia && flow == DataFlow.Render)
1.570 {
1.571 @@ -469,73 +504,77 @@
1.572 /// </summary>
1.573 /// <param name="pwstrDeviceId"></param>
1.574 /// <param name="key"></param>
1.575 - public void OnPropertyValueChanged([MarshalAs(UnmanagedType.LPWStr)] string pwstrDeviceId, PropertyKey key){}
1.576 -
1.577 -
1.578 -
1.579 -
1.580 - /// <summary>
1.581 - /// Update master volume indicators based our current system states.
1.582 - /// This typically includes volume levels and mute status.
1.583 - /// </summary>
1.584 - private void UpdateMasterVolumeThreadSafe()
1.585 - {
1.586 - if (this.InvokeRequired)
1.587 - {
1.588 - //Not in the proper thread, invoke ourselves
1.589 - PlainUpdateDelegate d = new PlainUpdateDelegate(UpdateMasterVolumeThreadSafe);
1.590 - this.Invoke(d, new object[] { });
1.591 - return;
1.592 - }
1.593 -
1.594 - //Update volume slider
1.595 - float volumeLevelScalar = iMultiMediaDevice.AudioEndpointVolume.MasterVolumeLevelScalar;
1.596 - trackBarMasterVolume.Value = Convert.ToInt32(volumeLevelScalar * 100);
1.597 - //Update mute checkbox
1.598 - checkBoxMute.Checked = iMultiMediaDevice.AudioEndpointVolume.Mute;
1.599 -
1.600 - //If our display connection is open we need to update its icons
1.601 - if (iDisplay.IsOpen())
1.602 - {
1.603 - //First take care our our volume level icons
1.604 + public void OnPropertyValueChanged([MarshalAs(UnmanagedType.LPWStr)] string pwstrDeviceId, PropertyKey key)
1.605 + {
1.606 + }
1.607 +
1.608 +
1.609 +
1.610 +
1.611 + /// <summary>
1.612 + /// Update master volume indicators based our current system states.
1.613 + /// This typically includes volume levels and mute status.
1.614 + /// </summary>
1.615 + private void UpdateMasterVolumeThreadSafe()
1.616 + {
1.617 + if (this.InvokeRequired)
1.618 + {
1.619 + //Not in the proper thread, invoke ourselves
1.620 + PlainUpdateDelegate d = new PlainUpdateDelegate(UpdateMasterVolumeThreadSafe);
1.621 + this.Invoke(d, new object[] {});
1.622 + return;
1.623 + }
1.624 +
1.625 + //Update volume slider
1.626 + float volumeLevelScalar = iMultiMediaDevice.AudioEndpointVolume.MasterVolumeLevelScalar;
1.627 + trackBarMasterVolume.Value = Convert.ToInt32(volumeLevelScalar*100);
1.628 + //Update mute checkbox
1.629 + checkBoxMute.Checked = iMultiMediaDevice.AudioEndpointVolume.Mute;
1.630 +
1.631 + //If our display connection is open we need to update its icons
1.632 + if (iDisplay.IsOpen())
1.633 + {
1.634 + //First take care our our volume level icons
1.635 int volumeIconCount = iDisplay.IconCount(MiniDisplay.IconType.Volume);
1.636 - if (volumeIconCount > 0)
1.637 - {
1.638 - //Compute current volume level from system level and the number of segments in our display volume bar.
1.639 - //That tells us how many segments in our volume bar needs to be turned on.
1.640 - float currentVolume = volumeLevelScalar * volumeIconCount;
1.641 - int segmentOnCount = Convert.ToInt32(currentVolume);
1.642 - //Check if our segment count was rounded up, this will later be used for half brightness segment
1.643 - bool roundedUp = segmentOnCount > currentVolume;
1.644 -
1.645 - for (int i = 0; i < volumeIconCount; i++)
1.646 - {
1.647 - if (i < segmentOnCount)
1.648 - {
1.649 - //If we are dealing with our last segment and our segment count was rounded up then we will use half brightness.
1.650 - if (i == segmentOnCount - 1 && roundedUp)
1.651 - {
1.652 - //Half brightness
1.653 - iDisplay.SetIconStatus(MiniDisplay.IconType.Volume, i, (iDisplay.IconStatusCount(MiniDisplay.IconType.Volume) - 1) / 2);
1.654 - }
1.655 - else
1.656 - {
1.657 - //Full brightness
1.658 - iDisplay.SetIconStatus(MiniDisplay.IconType.Volume, i, iDisplay.IconStatusCount(MiniDisplay.IconType.Volume) - 1);
1.659 - }
1.660 - }
1.661 - else
1.662 - {
1.663 + if (volumeIconCount > 0)
1.664 + {
1.665 + //Compute current volume level from system level and the number of segments in our display volume bar.
1.666 + //That tells us how many segments in our volume bar needs to be turned on.
1.667 + float currentVolume = volumeLevelScalar*volumeIconCount;
1.668 + int segmentOnCount = Convert.ToInt32(currentVolume);
1.669 + //Check if our segment count was rounded up, this will later be used for half brightness segment
1.670 + bool roundedUp = segmentOnCount > currentVolume;
1.671 +
1.672 + for (int i = 0; i < volumeIconCount; i++)
1.673 + {
1.674 + if (i < segmentOnCount)
1.675 + {
1.676 + //If we are dealing with our last segment and our segment count was rounded up then we will use half brightness.
1.677 + if (i == segmentOnCount - 1 && roundedUp)
1.678 + {
1.679 + //Half brightness
1.680 + iDisplay.SetIconStatus(MiniDisplay.IconType.Volume, i,
1.681 + (iDisplay.IconStatusCount(MiniDisplay.IconType.Volume) - 1)/2);
1.682 + }
1.683 + else
1.684 + {
1.685 + //Full brightness
1.686 + iDisplay.SetIconStatus(MiniDisplay.IconType.Volume, i,
1.687 + iDisplay.IconStatusCount(MiniDisplay.IconType.Volume) - 1);
1.688 + }
1.689 + }
1.690 + else
1.691 + {
1.692 iDisplay.SetIconStatus(MiniDisplay.IconType.Volume, i, 0);
1.693 - }
1.694 - }
1.695 - }
1.696 -
1.697 - //Take care of our mute icon
1.698 + }
1.699 + }
1.700 + }
1.701 +
1.702 + //Take care of our mute icon
1.703 iDisplay.SetIconOnOff(MiniDisplay.IconType.Mute, iMultiMediaDevice.AudioEndpointVolume.Mute);
1.704 - }
1.705 -
1.706 - }
1.707 + }
1.708 +
1.709 + }
1.710
1.711 /// <summary>
1.712 ///
1.713 @@ -545,48 +584,48 @@
1.714 if (this.InvokeRequired)
1.715 {
1.716 //Not in the proper thread, invoke ourselves
1.717 - PlainUpdateDelegate d = new PlainUpdateDelegate(UpdateAudioDeviceAndMasterVolumeThreadSafe);
1.718 - this.Invoke(d, new object[] { });
1.719 + PlainUpdateDelegate d = new PlainUpdateDelegate(UpdateAudioDeviceAndMasterVolumeThreadSafe);
1.720 + this.Invoke(d, new object[] {});
1.721 return;
1.722 }
1.723 -
1.724 +
1.725 //We are in the correct thread just go ahead.
1.726 try
1.727 - {
1.728 + {
1.729 //Get our master volume
1.730 - iMultiMediaDevice = iMultiMediaDeviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
1.731 - //Update our label
1.732 - labelDefaultAudioDevice.Text = iMultiMediaDevice.FriendlyName;
1.733 + iMultiMediaDevice = iMultiMediaDeviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
1.734 + //Update our label
1.735 + labelDefaultAudioDevice.Text = iMultiMediaDevice.FriendlyName;
1.736
1.737 //Show our volume in our track bar
1.738 - UpdateMasterVolumeThreadSafe();
1.739 + UpdateMasterVolumeThreadSafe();
1.740
1.741 //Register to get volume modifications
1.742 - iMultiMediaDevice.AudioEndpointVolume.OnVolumeNotification += OnVolumeNotificationThreadSafe;
1.743 + iMultiMediaDevice.AudioEndpointVolume.OnVolumeNotification += OnVolumeNotificationThreadSafe;
1.744 //
1.745 - trackBarMasterVolume.Enabled = true;
1.746 + trackBarMasterVolume.Enabled = true;
1.747 }
1.748 catch (Exception ex)
1.749 {
1.750 Debug.WriteLine("Exception thrown in UpdateAudioDeviceAndMasterVolume");
1.751 Debug.WriteLine(ex.ToString());
1.752 //Something went wrong S/PDIF device ca throw exception I guess
1.753 - trackBarMasterVolume.Enabled = false;
1.754 + trackBarMasterVolume.Enabled = false;
1.755 }
1.756 }
1.757
1.758 - /// <summary>
1.759 - ///
1.760 - /// </summary>
1.761 - private void PopulateDeviceTypes()
1.762 - {
1.763 - int count = Display.TypeCount();
1.764 -
1.765 - for (int i = 0; i < count; i++)
1.766 - {
1.767 - comboBoxDisplayType.Items.Add(Display.TypeName((MiniDisplay.Type)i));
1.768 - }
1.769 - }
1.770 + /// <summary>
1.771 + ///
1.772 + /// </summary>
1.773 + private void PopulateDeviceTypes()
1.774 + {
1.775 + int count = Display.TypeCount();
1.776 +
1.777 + for (int i = 0; i < count; i++)
1.778 + {
1.779 + comboBoxDisplayType.Items.Add(Display.TypeName((MiniDisplay.Type) i));
1.780 + }
1.781 + }
1.782
1.783 /// <summary>
1.784 ///
1.785 @@ -604,12 +643,12 @@
1.786 Debug.WriteLine("Drive " + d.Name);
1.787 Debug.WriteLine(" Drive type: {0}", d.DriveType);
1.788
1.789 - if (d.DriveType==DriveType.CDRom)
1.790 + if (d.DriveType == DriveType.CDRom)
1.791 {
1.792 //This is an optical drive, add it now
1.793 - comboBoxOpticalDrives.Items.Add(d.Name.Substring(0,2));
1.794 - }
1.795 - }
1.796 + comboBoxOpticalDrives.Items.Add(d.Name.Substring(0, 2));
1.797 + }
1.798 + }
1.799 }
1.800
1.801 /// <summary>
1.802 @@ -623,44 +662,44 @@
1.803
1.804
1.805
1.806 - /// <summary>
1.807 - ///
1.808 - /// </summary>
1.809 - private void SetupTrayIcon()
1.810 - {
1.811 - iNotifyIcon.Icon = GetIcon("vfd.ico");
1.812 - iNotifyIcon.Text = "Sharp Display Manager";
1.813 - iNotifyIcon.Visible = true;
1.814 -
1.815 - //Double click toggles visibility - typically brings up the application
1.816 - iNotifyIcon.DoubleClick += delegate(object obj, EventArgs args)
1.817 - {
1.818 - SysTrayHideShow();
1.819 - };
1.820 -
1.821 - //Adding a context menu, useful to be able to exit the application
1.822 - ContextMenu contextMenu = new ContextMenu();
1.823 - //Context menu item to toggle visibility
1.824 - MenuItem hideShowItem = new MenuItem("Hide/Show");
1.825 - hideShowItem.Click += delegate(object obj, EventArgs args)
1.826 - {
1.827 - SysTrayHideShow();
1.828 - };
1.829 - contextMenu.MenuItems.Add(hideShowItem);
1.830 -
1.831 - //Context menu item separator
1.832 - contextMenu.MenuItems.Add(new MenuItem("-"));
1.833 -
1.834 - //Context menu exit item
1.835 - MenuItem exitItem = new MenuItem("Exit");
1.836 - exitItem.Click += delegate(object obj, EventArgs args)
1.837 - {
1.838 - Application.Exit();
1.839 - };
1.840 - contextMenu.MenuItems.Add(exitItem);
1.841 -
1.842 - iNotifyIcon.ContextMenu = contextMenu;
1.843 - }
1.844 + /// <summary>
1.845 + ///
1.846 + /// </summary>
1.847 + private void SetupTrayIcon()
1.848 + {
1.849 + iNotifyIcon.Icon = GetIcon("vfd.ico");
1.850 + iNotifyIcon.Text = "Sharp Display Manager";
1.851 + iNotifyIcon.Visible = true;
1.852 +
1.853 + //Double click toggles visibility - typically brings up the application
1.854 + iNotifyIcon.DoubleClick += delegate(object obj, EventArgs args)
1.855 + {
1.856 + SysTrayHideShow();
1.857 + };
1.858 +
1.859 + //Adding a context menu, useful to be able to exit the application
1.860 + ContextMenu contextMenu = new ContextMenu();
1.861 + //Context menu item to toggle visibility
1.862 + MenuItem hideShowItem = new MenuItem("Hide/Show");
1.863 + hideShowItem.Click += delegate(object obj, EventArgs args)
1.864 + {
1.865 + SysTrayHideShow();
1.866 + };
1.867 + contextMenu.MenuItems.Add(hideShowItem);
1.868 +
1.869 + //Context menu item separator
1.870 + contextMenu.MenuItems.Add(new MenuItem("-"));
1.871 +
1.872 + //Context menu exit item
1.873 + MenuItem exitItem = new MenuItem("Exit");
1.874 + exitItem.Click += delegate(object obj, EventArgs args)
1.875 + {
1.876 + Application.Exit();
1.877 + };
1.878 + contextMenu.MenuItems.Add(exitItem);
1.879 +
1.880 + iNotifyIcon.ContextMenu = contextMenu;
1.881 + }
1.882
1.883 /// <summary>
1.884 ///
1.885 @@ -678,22 +717,22 @@
1.886 /// <param name="aName"></param>
1.887 /// <returns></returns>
1.888 public static Icon GetIcon(string aName)
1.889 - {
1.890 - string[] names = Assembly.GetExecutingAssembly().GetManifestResourceNames();
1.891 - foreach (string name in names)
1.892 - {
1.893 + {
1.894 + string[] names = Assembly.GetExecutingAssembly().GetManifestResourceNames();
1.895 + foreach (string name in names)
1.896 + {
1.897 //Find a resource name that ends with the given name
1.898 - if (name.EndsWith(aName))
1.899 - {
1.900 - using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name))
1.901 - {
1.902 - return new Icon(stream);
1.903 - }
1.904 - }
1.905 - }
1.906 -
1.907 - return null;
1.908 - }
1.909 + if (name.EndsWith(aName))
1.910 + {
1.911 + using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name))
1.912 + {
1.913 + return new Icon(stream);
1.914 + }
1.915 + }
1.916 + }
1.917 +
1.918 + return null;
1.919 + }
1.920
1.921
1.922 /// <summary>
1.923 @@ -701,7 +740,7 @@
1.924 /// This will take care of applying our client layout and set data fields.
1.925 /// </summary>
1.926 /// <param name="aSessionId"></param>
1.927 - void SetCurrentClient(string aSessionId, bool aForce=false)
1.928 + void SetCurrentClient(string aSessionId, bool aForce = false)
1.929 {
1.930 if (aSessionId == iCurrentClientSessionId)
1.931 {
1.932 @@ -728,7 +767,8 @@
1.933 //Thus a background client can set this to zero allowing any other client to interrupt at any time
1.934 //We could also compute this delay by looking at the requests frequencies?
1.935 if (!aForce &&
1.936 - requestedClientData.Priority == iCurrentClientData.Priority && //Time sharing is only if clients have the same priority
1.937 + requestedClientData.Priority == iCurrentClientData.Priority &&
1.938 + //Time sharing is only if clients have the same priority
1.939 (lastSwitchToClientSecondsAgo < 30)) //Make sure a client is on for at least 30 seconds
1.940 {
1.941 //Don't switch clients too often
1.942 @@ -773,7 +813,7 @@
1.943 {
1.944 if (ctrl is MarqueeLabel)
1.945 {
1.946 - ((MarqueeLabel)ctrl).Font = fontDialog.Font;
1.947 + ((MarqueeLabel) ctrl).Font = fontDialog.Font;
1.948 }
1.949 }
1.950
1.951 @@ -809,7 +849,7 @@
1.952 {
1.953 if (ctrl is MarqueeLabel)
1.954 {
1.955 - label = (MarqueeLabel)ctrl;
1.956 + label = (MarqueeLabel) ctrl;
1.957 break;
1.958 }
1.959 }
1.960 @@ -817,7 +857,8 @@
1.961 //Now check font height and show a warning if needed.
1.962 if (label != null && label.Font.Height > label.Height)
1.963 {
1.964 - labelWarning.Text = "WARNING: Selected font is too height by " + (label.Font.Height - label.Height) + " pixels!";
1.965 + labelWarning.Text = "WARNING: Selected font is too height by " + (label.Font.Height - label.Height) +
1.966 + " pixels!";
1.967 labelWarning.Visible = true;
1.968 }
1.969 else
1.970 @@ -834,7 +875,7 @@
1.971 //Bitmap bmpToSave = new Bitmap(bmp);
1.972 bmp.Save("D:\\capture.png");
1.973
1.974 - ((MarqueeLabel)iTableLayoutPanel.Controls[0]).Text = "Captured";
1.975 + ((MarqueeLabel) iTableLayoutPanel.Controls[0]).Text = "Captured";
1.976
1.977 /*
1.978 string outputFileName = "d:\\capture.png";
1.979 @@ -905,11 +946,11 @@
1.980
1.981 public static uint ColorChessboard(int aX, int aY, uint aPixel)
1.982 {
1.983 - if ((aX % 2 == 0) && (aY % 2 == 0))
1.984 + if ((aX%2 == 0) && (aY%2 == 0))
1.985 {
1.986 return ~aPixel;
1.987 }
1.988 - else if ((aX % 2 != 0) && (aY % 2 != 0))
1.989 + else if ((aX%2 != 0) && (aY%2 != 0))
1.990 {
1.991 return ~aPixel;
1.992 }
1.993 @@ -977,14 +1018,14 @@
1.994 //Update our animations
1.995 DateTime NewTickTime = DateTime.Now;
1.996
1.997 - UpdateNetworkSignal(LastTickTime, NewTickTime);
1.998 + UpdateNetworkSignal(LastTickTime, NewTickTime);
1.999
1.1000 //Update animation for all our marquees
1.1001 foreach (Control ctrl in iTableLayoutPanel.Controls)
1.1002 {
1.1003 if (ctrl is MarqueeLabel)
1.1004 {
1.1005 - ((MarqueeLabel)ctrl).UpdateAnimation(LastTickTime, NewTickTime);
1.1006 + ((MarqueeLabel) ctrl).UpdateAnimation(LastTickTime, NewTickTime);
1.1007 }
1.1008 }
1.1009
1.1010 @@ -993,82 +1034,84 @@
1.1011 {
1.1012 CheckForRequestResults();
1.1013
1.1014 - //Check if frame rendering is needed
1.1015 - //Typically used when showing clock
1.1016 - if (!iSkipFrameRendering)
1.1017 - {
1.1018 - //Draw to bitmap
1.1019 - if (iCreateBitmap)
1.1020 - {
1.1021 - iBmp = new System.Drawing.Bitmap(iTableLayoutPanel.Width, iTableLayoutPanel.Height, PixelFormat.Format32bppArgb);
1.1022 + //Check if frame rendering is needed
1.1023 + //Typically used when showing clock
1.1024 + if (!iSkipFrameRendering)
1.1025 + {
1.1026 + //Draw to bitmap
1.1027 + if (iCreateBitmap)
1.1028 + {
1.1029 + iBmp = new System.Drawing.Bitmap(iTableLayoutPanel.Width, iTableLayoutPanel.Height,
1.1030 + PixelFormat.Format32bppArgb);
1.1031 iCreateBitmap = false;
1.1032 }
1.1033 - iTableLayoutPanel.DrawToBitmap(iBmp, iTableLayoutPanel.ClientRectangle);
1.1034 - //iBmp.Save("D:\\capture.png");
1.1035 -
1.1036 - //Send it to our display
1.1037 - for (int i = 0; i < iBmp.Width; i++)
1.1038 - {
1.1039 - for (int j = 0; j < iBmp.Height; j++)
1.1040 - {
1.1041 - unchecked
1.1042 - {
1.1043 - //Get our processed pixel coordinates
1.1044 - int x = iScreenX(iBmp, i);
1.1045 - int y = iScreenY(iBmp, j);
1.1046 - //Get pixel color
1.1047 - uint color = (uint)iBmp.GetPixel(i, j).ToArgb();
1.1048 - //Apply color effects
1.1049 - color = iColorFx(x, y, color);
1.1050 - //Now set our pixel
1.1051 - iDisplay.SetPixel(x, y, color);
1.1052 - }
1.1053 - }
1.1054 - }
1.1055 -
1.1056 - iDisplay.SwapBuffers();
1.1057 - }
1.1058 + iTableLayoutPanel.DrawToBitmap(iBmp, iTableLayoutPanel.ClientRectangle);
1.1059 + //iBmp.Save("D:\\capture.png");
1.1060 +
1.1061 + //Send it to our display
1.1062 + for (int i = 0; i < iBmp.Width; i++)
1.1063 + {
1.1064 + for (int j = 0; j < iBmp.Height; j++)
1.1065 + {
1.1066 + unchecked
1.1067 + {
1.1068 + //Get our processed pixel coordinates
1.1069 + int x = iScreenX(iBmp, i);
1.1070 + int y = iScreenY(iBmp, j);
1.1071 + //Get pixel color
1.1072 + uint color = (uint) iBmp.GetPixel(i, j).ToArgb();
1.1073 + //Apply color effects
1.1074 + color = iColorFx(x, y, color);
1.1075 + //Now set our pixel
1.1076 + iDisplay.SetPixel(x, y, color);
1.1077 + }
1.1078 + }
1.1079 + }
1.1080 +
1.1081 + iDisplay.SwapBuffers();
1.1082 + }
1.1083 }
1.1084
1.1085 //Compute instant FPS
1.1086 - toolStripStatusLabelFps.Text = (1.0/NewTickTime.Subtract(LastTickTime).TotalSeconds).ToString("F0") + " / " + (1000/timer.Interval).ToString() + " FPS";
1.1087 + toolStripStatusLabelFps.Text = (1.0/NewTickTime.Subtract(LastTickTime).TotalSeconds).ToString("F0") + " / " +
1.1088 + (1000/timer.Interval).ToString() + " FPS";
1.1089
1.1090 LastTickTime = NewTickTime;
1.1091
1.1092 }
1.1093
1.1094 - /// <summary>
1.1095 - /// Attempt to establish connection with our display hardware.
1.1096 - /// </summary>
1.1097 + /// <summary>
1.1098 + /// Attempt to establish connection with our display hardware.
1.1099 + /// </summary>
1.1100 private void OpenDisplayConnection()
1.1101 {
1.1102 CloseDisplayConnection();
1.1103
1.1104 - if (!iDisplay.Open((MiniDisplay.Type)cds.DisplayType))
1.1105 - {
1.1106 - UpdateStatus();
1.1107 - toolStripStatusLabelConnect.Text = "Connection error";
1.1108 + if (!iDisplay.Open((MiniDisplay.Type) cds.DisplayType))
1.1109 + {
1.1110 + UpdateStatus();
1.1111 + toolStripStatusLabelConnect.Text = "Connection error";
1.1112 }
1.1113 }
1.1114
1.1115 private void CloseDisplayConnection()
1.1116 {
1.1117 - //Status will be updated upon receiving the closed event
1.1118 -
1.1119 - if (iDisplay == null || !iDisplay.IsOpen())
1.1120 - {
1.1121 - return;
1.1122 - }
1.1123 -
1.1124 - //Do not clear if we gave up on rendering already.
1.1125 - //This means we will keep on displaying clock on MDM166AA for instance.
1.1126 - if (!iSkipFrameRendering)
1.1127 - {
1.1128 - iDisplay.Clear();
1.1129 - iDisplay.SwapBuffers();
1.1130 - }
1.1131 -
1.1132 - iDisplay.SetAllIconsStatus(0); //Turn off all icons
1.1133 + //Status will be updated upon receiving the closed event
1.1134 +
1.1135 + if (iDisplay == null || !iDisplay.IsOpen())
1.1136 + {
1.1137 + return;
1.1138 + }
1.1139 +
1.1140 + //Do not clear if we gave up on rendering already.
1.1141 + //This means we will keep on displaying clock on MDM166AA for instance.
1.1142 + if (!iSkipFrameRendering)
1.1143 + {
1.1144 + iDisplay.Clear();
1.1145 + iDisplay.SwapBuffers();
1.1146 + }
1.1147 +
1.1148 + iDisplay.SetAllIconsStatus(0); //Turn off all icons
1.1149 iDisplay.Close();
1.1150 }
1.1151
1.1152 @@ -1137,13 +1180,14 @@
1.1153 public float IsFixedWidth(Font ft)
1.1154 {
1.1155 Graphics g = CreateGraphics();
1.1156 - char[] charSizes = new char[] { 'i', 'a', 'Z', '%', '#', 'a', 'B', 'l', 'm', ',', '.' };
1.1157 + char[] charSizes = new char[] {'i', 'a', 'Z', '%', '#', 'a', 'B', 'l', 'm', ',', '.'};
1.1158 float charWidth = g.MeasureString("I", ft, Int32.MaxValue, StringFormat.GenericTypographic).Width;
1.1159
1.1160 bool fixedWidth = true;
1.1161
1.1162 foreach (char c in charSizes)
1.1163 - if (g.MeasureString(c.ToString(), ft, Int32.MaxValue, StringFormat.GenericTypographic).Width != charWidth)
1.1164 + if (g.MeasureString(c.ToString(), ft, Int32.MaxValue, StringFormat.GenericTypographic).Width !=
1.1165 + charWidth)
1.1166 fixedWidth = false;
1.1167
1.1168 if (fixedWidth)
1.1169 @@ -1154,14 +1198,16 @@
1.1170 return 0.0f;
1.1171 }
1.1172
1.1173 - /// <summary>
1.1174 - /// Synchronize UI with settings
1.1175 - /// </summary>
1.1176 + /// <summary>
1.1177 + /// Synchronize UI with settings
1.1178 + /// </summary>
1.1179 private void UpdateStatus()
1.1180 - {
1.1181 + {
1.1182 //Load settings
1.1183 checkBoxShowBorders.Checked = cds.ShowBorders;
1.1184 - iTableLayoutPanel.CellBorderStyle = (cds.ShowBorders ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None);
1.1185 + iTableLayoutPanel.CellBorderStyle = (cds.ShowBorders
1.1186 + ? TableLayoutPanelCellBorderStyle.Single
1.1187 + : TableLayoutPanelCellBorderStyle.None);
1.1188
1.1189 //Set the proper font to each of our labels
1.1190 foreach (MarqueeLabel ctrl in iTableLayoutPanel.Controls)
1.1191 @@ -1170,20 +1216,20 @@
1.1192 }
1.1193
1.1194 CheckFontHeight();
1.1195 - //Check if "run on Windows startup" is enabled
1.1196 - checkBoxAutoStart.Checked = iStartupManager.Startup;
1.1197 - //
1.1198 + //Check if "run on Windows startup" is enabled
1.1199 + checkBoxAutoStart.Checked = iStartupManager.Startup;
1.1200 + //
1.1201 checkBoxConnectOnStartup.Checked = Properties.Settings.Default.DisplayConnectOnStartup;
1.1202 - checkBoxMinimizeToTray.Checked = Properties.Settings.Default.MinimizeToTray;
1.1203 - checkBoxStartMinimized.Checked = Properties.Settings.Default.StartMinimized;
1.1204 + checkBoxMinimizeToTray.Checked = Properties.Settings.Default.MinimizeToTray;
1.1205 + checkBoxStartMinimized.Checked = Properties.Settings.Default.StartMinimized;
1.1206 iCheckBoxStartIdleClient.Checked = Properties.Settings.Default.StartIdleClient;
1.1207 labelStartFileName.Text = Properties.Settings.Default.StartFileName;
1.1208
1.1209
1.1210 //Try find our drive in our drive list
1.1211 - int opticalDriveItemIndex=0;
1.1212 + int opticalDriveItemIndex = 0;
1.1213 bool driveNotFound = true;
1.1214 - string opticalDriveToEject=Properties.Settings.Default.OpticalDriveToEject;
1.1215 + string opticalDriveToEject = Properties.Settings.Default.OpticalDriveToEject;
1.1216 foreach (object item in comboBoxOpticalDrives.Items)
1.1217 {
1.1218 if (opticalDriveToEject == item.ToString())
1.1219 @@ -1209,12 +1255,12 @@
1.1220 //Mini Display settings
1.1221 checkBoxReverseScreen.Checked = cds.ReverseScreen;
1.1222 checkBoxInverseColors.Checked = cds.InverseColors;
1.1223 - checkBoxShowVolumeLabel.Checked = cds.ShowVolumeLabel;
1.1224 + checkBoxShowVolumeLabel.Checked = cds.ShowVolumeLabel;
1.1225 checkBoxScaleToFit.Checked = cds.ScaleToFit;
1.1226 maskedTextBoxMinFontSize.Enabled = cds.ScaleToFit;
1.1227 labelMinFontSize.Enabled = cds.ScaleToFit;
1.1228 maskedTextBoxMinFontSize.Text = cds.MinFontSize.ToString();
1.1229 - maskedTextBoxScrollingSpeed.Text = cds.ScrollingSpeedInPixelsPerSecond.ToString();
1.1230 + maskedTextBoxScrollingSpeed.Text = cds.ScrollingSpeedInPixelsPerSecond.ToString();
1.1231 comboBoxDisplayType.SelectedIndex = cds.DisplayType;
1.1232 timer.Interval = cds.TimerInterval;
1.1233 maskedTextBoxTimerInterval.Text = cds.TimerInterval.ToString();
1.1234 @@ -1228,29 +1274,29 @@
1.1235 //Reflect that in our UI
1.1236 StartTimer();
1.1237
1.1238 - iTableLayoutPanel.Enabled = true;
1.1239 - panelDisplay.Enabled = true;
1.1240 + iTableLayoutPanel.Enabled = true;
1.1241 + panelDisplay.Enabled = true;
1.1242
1.1243 //Only setup brightness if display is open
1.1244 trackBarBrightness.Minimum = iDisplay.MinBrightness();
1.1245 trackBarBrightness.Maximum = iDisplay.MaxBrightness();
1.1246 - if (cds.Brightness < iDisplay.MinBrightness() || cds.Brightness > iDisplay.MaxBrightness())
1.1247 - {
1.1248 - //Brightness out of range, this can occur when using auto-detect
1.1249 - //Use max brightness instead
1.1250 - trackBarBrightness.Value = iDisplay.MaxBrightness();
1.1251 - iDisplay.SetBrightness(iDisplay.MaxBrightness());
1.1252 - }
1.1253 - else
1.1254 - {
1.1255 - trackBarBrightness.Value = cds.Brightness;
1.1256 - iDisplay.SetBrightness(cds.Brightness);
1.1257 - }
1.1258 -
1.1259 - //Try compute the steps to something that makes sense
1.1260 - trackBarBrightness.LargeChange = Math.Max(1, (iDisplay.MaxBrightness() - iDisplay.MinBrightness()) / 5);
1.1261 + if (cds.Brightness < iDisplay.MinBrightness() || cds.Brightness > iDisplay.MaxBrightness())
1.1262 + {
1.1263 + //Brightness out of range, this can occur when using auto-detect
1.1264 + //Use max brightness instead
1.1265 + trackBarBrightness.Value = iDisplay.MaxBrightness();
1.1266 + iDisplay.SetBrightness(iDisplay.MaxBrightness());
1.1267 + }
1.1268 + else
1.1269 + {
1.1270 + trackBarBrightness.Value = cds.Brightness;
1.1271 + iDisplay.SetBrightness(cds.Brightness);
1.1272 + }
1.1273 +
1.1274 + //Try compute the steps to something that makes sense
1.1275 + trackBarBrightness.LargeChange = Math.Max(1, (iDisplay.MaxBrightness() - iDisplay.MinBrightness())/5);
1.1276 trackBarBrightness.SmallChange = 1;
1.1277 -
1.1278 +
1.1279 //
1.1280 buttonFill.Enabled = true;
1.1281 buttonClear.Enabled = true;
1.1282 @@ -1282,18 +1328,18 @@
1.1283 buttonHideClock.Enabled = false;
1.1284 }
1.1285
1.1286 -
1.1287 - //Check if Volume Label is supported. To date only MDM166AA supports that crap :)
1.1288 - checkBoxShowVolumeLabel.Enabled = iDisplay.IconCount(MiniDisplay.IconType.VolumeLabel)>0;
1.1289 -
1.1290 - if (cds.ShowVolumeLabel)
1.1291 - {
1.1292 +
1.1293 + //Check if Volume Label is supported. To date only MDM166AA supports that crap :)
1.1294 + checkBoxShowVolumeLabel.Enabled = iDisplay.IconCount(MiniDisplay.IconType.VolumeLabel) > 0;
1.1295 +
1.1296 + if (cds.ShowVolumeLabel)
1.1297 + {
1.1298 iDisplay.SetIconOn(MiniDisplay.IconType.VolumeLabel);
1.1299 - }
1.1300 - else
1.1301 - {
1.1302 + }
1.1303 + else
1.1304 + {
1.1305 iDisplay.SetIconOff(MiniDisplay.IconType.VolumeLabel);
1.1306 - }
1.1307 + }
1.1308 }
1.1309 else
1.1310 {
1.1311 @@ -1303,12 +1349,12 @@
1.1312 //In debug start our timer even if we don't have a display connection
1.1313 StartTimer();
1.1314 #else
1.1315 - //In production environment we don't need our timer if no display connection
1.1316 + //In production environment we don't need our timer if no display connection
1.1317 StopTimer();
1.1318 #endif
1.1319 checkBoxShowVolumeLabel.Enabled = false;
1.1320 - iTableLayoutPanel.Enabled = false;
1.1321 - panelDisplay.Enabled = false;
1.1322 + iTableLayoutPanel.Enabled = false;
1.1323 + panelDisplay.Enabled = false;
1.1324 buttonFill.Enabled = false;
1.1325 buttonClear.Enabled = false;
1.1326 buttonOpen.Enabled = true;
1.1327 @@ -1325,22 +1371,24 @@
1.1328 }
1.1329
1.1330
1.1331 - /// <summary>
1.1332 - ///
1.1333 - /// </summary>
1.1334 - /// <param name="sender"></param>
1.1335 - /// <param name="e"></param>
1.1336 - private void checkBoxShowVolumeLabel_CheckedChanged(object sender, EventArgs e)
1.1337 - {
1.1338 - cds.ShowVolumeLabel = checkBoxShowVolumeLabel.Checked;
1.1339 - Properties.Settings.Default.Save();
1.1340 - UpdateStatus();
1.1341 - }
1.1342 + /// <summary>
1.1343 + ///
1.1344 + /// </summary>
1.1345 + /// <param name="sender"></param>
1.1346 + /// <param name="e"></param>
1.1347 + private void checkBoxShowVolumeLabel_CheckedChanged(object sender, EventArgs e)
1.1348 + {
1.1349 + cds.ShowVolumeLabel = checkBoxShowVolumeLabel.Checked;
1.1350 + Properties.Settings.Default.Save();
1.1351 + UpdateStatus();
1.1352 + }
1.1353
1.1354 private void checkBoxShowBorders_CheckedChanged(object sender, EventArgs e)
1.1355 {
1.1356 //Save our show borders setting
1.1357 - iTableLayoutPanel.CellBorderStyle = (checkBoxShowBorders.Checked ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None);
1.1358 + iTableLayoutPanel.CellBorderStyle = (checkBoxShowBorders.Checked
1.1359 + ? TableLayoutPanelCellBorderStyle.Single
1.1360 + : TableLayoutPanelCellBorderStyle.None);
1.1361 cds.ShowBorders = checkBoxShowBorders.Checked;
1.1362 Properties.Settings.Default.Save();
1.1363 CheckFontHeight();
1.1364 @@ -1353,20 +1401,20 @@
1.1365 Properties.Settings.Default.Save();
1.1366 }
1.1367
1.1368 - private void checkBoxMinimizeToTray_CheckedChanged(object sender, EventArgs e)
1.1369 - {
1.1370 - //Save our "Minimize to tray" setting
1.1371 - Properties.Settings.Default.MinimizeToTray = checkBoxMinimizeToTray.Checked;
1.1372 - Properties.Settings.Default.Save();
1.1373 -
1.1374 - }
1.1375 -
1.1376 - private void checkBoxStartMinimized_CheckedChanged(object sender, EventArgs e)
1.1377 - {
1.1378 - //Save our "Start minimized" setting
1.1379 - Properties.Settings.Default.StartMinimized = checkBoxStartMinimized.Checked;
1.1380 - Properties.Settings.Default.Save();
1.1381 - }
1.1382 + private void checkBoxMinimizeToTray_CheckedChanged(object sender, EventArgs e)
1.1383 + {
1.1384 + //Save our "Minimize to tray" setting
1.1385 + Properties.Settings.Default.MinimizeToTray = checkBoxMinimizeToTray.Checked;
1.1386 + Properties.Settings.Default.Save();
1.1387 +
1.1388 + }
1.1389 +
1.1390 + private void checkBoxStartMinimized_CheckedChanged(object sender, EventArgs e)
1.1391 + {
1.1392 + //Save our "Start minimized" setting
1.1393 + Properties.Settings.Default.StartMinimized = checkBoxStartMinimized.Checked;
1.1394 + Properties.Settings.Default.Save();
1.1395 + }
1.1396
1.1397 private void checkBoxStartIdleClient_CheckedChanged(object sender, EventArgs e)
1.1398 {
1.1399 @@ -1375,9 +1423,9 @@
1.1400 }
1.1401
1.1402 private void checkBoxAutoStart_CheckedChanged(object sender, EventArgs e)
1.1403 - {
1.1404 - iStartupManager.Startup = checkBoxAutoStart.Checked;
1.1405 - }
1.1406 + {
1.1407 + iStartupManager.Startup = checkBoxAutoStart.Checked;
1.1408 + }
1.1409
1.1410
1.1411 private void checkBoxReverseScreen_CheckedChanged(object sender, EventArgs e)
1.1412 @@ -1419,8 +1467,8 @@
1.1413 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
1.1414 {
1.1415 iCecManager.Stop();
1.1416 - iNetworkManager.Dispose();
1.1417 - CloseDisplayConnection();
1.1418 + iNetworkManager.Dispose();
1.1419 + CloseDisplayConnection();
1.1420 StopServer();
1.1421 e.Cancel = iClosing;
1.1422 }
1.1423 @@ -1429,11 +1477,12 @@
1.1424 {
1.1425 iServiceHost = new ServiceHost
1.1426 (
1.1427 - typeof(Session),
1.1428 - new Uri[] { new Uri("net.tcp://localhost:8001/") }
1.1429 + typeof(Session),
1.1430 + new Uri[] {new Uri("net.tcp://localhost:8001/")}
1.1431 );
1.1432
1.1433 - iServiceHost.AddServiceEndpoint(typeof(IService), new NetTcpBinding(SecurityMode.None, true), "DisplayService");
1.1434 + iServiceHost.AddServiceEndpoint(typeof(IService), new NetTcpBinding(SecurityMode.None, true),
1.1435 + "DisplayService");
1.1436 iServiceHost.Open();
1.1437 }
1.1438
1.1439 @@ -1447,7 +1496,9 @@
1.1440 }
1.1441 else if (iClosing)
1.1442 {
1.1443 - if (MessageBox.Show("Force exit?", "Waiting for clients...", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
1.1444 + if (
1.1445 + MessageBox.Show("Force exit?", "Waiting for clients...", MessageBoxButtons.YesNo,
1.1446 + MessageBoxIcon.Warning) == DialogResult.Yes)
1.1447 {
1.1448 iClosing = false; //We make sure we force close if asked twice
1.1449 }
1.1450 @@ -1471,7 +1522,7 @@
1.1451 try
1.1452 {
1.1453 Trace.TraceInformation("BroadcastCloseEvent - " + client.Key);
1.1454 - client.Value.Callback.OnCloseOrder(/*eventData*/);
1.1455 + client.Value.Callback.OnCloseOrder( /*eventData*/);
1.1456 }
1.1457 catch (Exception ex)
1.1458 {
1.1459 @@ -1485,37 +1536,39 @@
1.1460 foreach (var client in inactiveClients)
1.1461 {
1.1462 iClients.Remove(client);
1.1463 - Program.iMainForm.iTreeViewClients.Nodes.Remove(Program.iMainForm.iTreeViewClients.Nodes.Find(client, false)[0]);
1.1464 + Program.iMainForm.iTreeViewClients.Nodes.Remove(
1.1465 + Program.iMainForm.iTreeViewClients.Nodes.Find(client, false)[0]);
1.1466 }
1.1467 }
1.1468
1.1469 - if (iClients.Count==0)
1.1470 - {
1.1471 - ClearLayout();
1.1472 - }
1.1473 + if (iClients.Count == 0)
1.1474 + {
1.1475 + ClearLayout();
1.1476 + }
1.1477 }
1.1478
1.1479 - /// <summary>
1.1480 - /// Just remove all our fields.
1.1481 - /// </summary>
1.1482 - private void ClearLayout()
1.1483 - {
1.1484 - iTableLayoutPanel.Controls.Clear();
1.1485 - iTableLayoutPanel.RowStyles.Clear();
1.1486 - iTableLayoutPanel.ColumnStyles.Clear();
1.1487 - iCurrentClientData = null;
1.1488 - }
1.1489 -
1.1490 - /// <summary>
1.1491 - /// Just launch a demo client.
1.1492 - /// </summary>
1.1493 - private void StartNewClient(string aTopText = "", string aBottomText = "")
1.1494 - {
1.1495 - Thread clientThread = new Thread(SharpDisplayClient.Program.MainWithParams);
1.1496 - SharpDisplayClient.StartParams myParams = new SharpDisplayClient.StartParams(new Point(this.Right, this.Top),aTopText,aBottomText);
1.1497 - clientThread.Start(myParams);
1.1498 - BringToFront();
1.1499 - }
1.1500 + /// <summary>
1.1501 + /// Just remove all our fields.
1.1502 + /// </summary>
1.1503 + private void ClearLayout()
1.1504 + {
1.1505 + iTableLayoutPanel.Controls.Clear();
1.1506 + iTableLayoutPanel.RowStyles.Clear();
1.1507 + iTableLayoutPanel.ColumnStyles.Clear();
1.1508 + iCurrentClientData = null;
1.1509 + }
1.1510 +
1.1511 + /// <summary>
1.1512 + /// Just launch a demo client.
1.1513 + /// </summary>
1.1514 + private void StartNewClient(string aTopText = "", string aBottomText = "")
1.1515 + {
1.1516 + Thread clientThread = new Thread(SharpDisplayClient.Program.MainWithParams);
1.1517 + SharpDisplayClient.StartParams myParams = new SharpDisplayClient.StartParams(
1.1518 + new Point(this.Right, this.Top), aTopText, aBottomText);
1.1519 + clientThread.Start(myParams);
1.1520 + BringToFront();
1.1521 + }
1.1522
1.1523 /// <summary>
1.1524 /// Just launch our idle client.
1.1525 @@ -1523,7 +1576,8 @@
1.1526 private void StartIdleClient(string aTopText = "", string aBottomText = "")
1.1527 {
1.1528 Thread clientThread = new Thread(SharpDisplayIdleClient.Program.MainWithParams);
1.1529 - SharpDisplayIdleClient.StartParams myParams = new SharpDisplayIdleClient.StartParams(new Point(this.Right, this.Top), aTopText, aBottomText);
1.1530 + SharpDisplayIdleClient.StartParams myParams =
1.1531 + new SharpDisplayIdleClient.StartParams(new Point(this.Right, this.Top), aTopText, aBottomText);
1.1532 clientThread.Start(myParams);
1.1533 BringToFront();
1.1534 }
1.1535 @@ -1531,7 +1585,7 @@
1.1536
1.1537 private void buttonStartClient_Click(object sender, EventArgs e)
1.1538 {
1.1539 - StartNewClient();
1.1540 + StartNewClient();
1.1541 }
1.1542
1.1543 private void buttonSuspend_Click(object sender, EventArgs e)
1.1544 @@ -1587,13 +1641,13 @@
1.1545 }
1.1546
1.1547 //If the selected node is the root node of a client then switch to it
1.1548 - string sessionId=e.Node.Nodes[0].Text; //First child of a root node is the sessionId
1.1549 + string sessionId = e.Node.Nodes[0].Text; //First child of a root node is the sessionId
1.1550 if (iClients.ContainsKey(sessionId)) //Check that's actually what we are looking at
1.1551 {
1.1552 //We have a valid session just switch to that client
1.1553 - SetCurrentClient(sessionId,true);
1.1554 + SetCurrentClient(sessionId, true);
1.1555 }
1.1556 -
1.1557 +
1.1558 }
1.1559
1.1560
1.1561 @@ -1608,7 +1662,7 @@
1.1562 {
1.1563 //Not in the proper thread, invoke ourselves
1.1564 AddClientDelegate d = new AddClientDelegate(AddClientThreadSafe);
1.1565 - this.Invoke(d, new object[] { aSessionId, aCallback });
1.1566 + this.Invoke(d, new object[] {aSessionId, aCallback});
1.1567 }
1.1568 else
1.1569 {
1.1570 @@ -1650,7 +1704,7 @@
1.1571 {
1.1572 //Not in the proper thread, invoke ourselves
1.1573 RemoveClientDelegate d = new RemoveClientDelegate(RemoveClientThreadSafe);
1.1574 - this.Invoke(d, new object[] { aSessionId });
1.1575 + this.Invoke(d, new object[] {aSessionId});
1.1576 }
1.1577 else
1.1578 {
1.1579 @@ -1659,7 +1713,8 @@
1.1580 if (Program.iMainForm.iClients.Keys.Contains(aSessionId))
1.1581 {
1.1582 Program.iMainForm.iClients.Remove(aSessionId);
1.1583 - Program.iMainForm.iTreeViewClients.Nodes.Remove(Program.iMainForm.iTreeViewClients.Nodes.Find(aSessionId, false)[0]);
1.1584 + Program.iMainForm.iTreeViewClients.Nodes.Remove(
1.1585 + Program.iMainForm.iTreeViewClients.Nodes.Find(aSessionId, false)[0]);
1.1586 //Update recording status too whenever a client is removed
1.1587 UpdateRecordingNotification();
1.1588 }
1.1589 @@ -1670,26 +1725,26 @@
1.1590 iCurrentClientData = null;
1.1591 //Find the client with the highest priority and set it as current
1.1592 ClientData newCurrentClient = FindHighestPriorityClient();
1.1593 - if (newCurrentClient!=null)
1.1594 + if (newCurrentClient != null)
1.1595 {
1.1596 SetCurrentClient(newCurrentClient.SessionId, true);
1.1597 - }
1.1598 + }
1.1599 }
1.1600
1.1601 if (iClients.Count == 0)
1.1602 - {
1.1603 - //Clear our screen when last client disconnects
1.1604 - ClearLayout();
1.1605 -
1.1606 - if (iClosing)
1.1607 - {
1.1608 - //We were closing our form
1.1609 - //All clients are now closed
1.1610 - //Just resume our close operation
1.1611 - iClosing = false;
1.1612 - Close();
1.1613 - }
1.1614 - }
1.1615 + {
1.1616 + //Clear our screen when last client disconnects
1.1617 + ClearLayout();
1.1618 +
1.1619 + if (iClosing)
1.1620 + {
1.1621 + //We were closing our form
1.1622 + //All clients are now closed
1.1623 + //Just resume our close operation
1.1624 + iClosing = false;
1.1625 + Close();
1.1626 + }
1.1627 + }
1.1628 }
1.1629 }
1.1630
1.1631 @@ -1704,7 +1759,7 @@
1.1632 {
1.1633 //Not in the proper thread, invoke ourselves
1.1634 SetLayoutDelegate d = new SetLayoutDelegate(SetClientLayoutThreadSafe);
1.1635 - this.Invoke(d, new object[] { aSessionId, aLayout });
1.1636 + this.Invoke(d, new object[] {aSessionId, aLayout});
1.1637 }
1.1638 else
1.1639 {
1.1640 @@ -1743,7 +1798,7 @@
1.1641 {
1.1642 //Not in the proper thread, invoke ourselves
1.1643 SetFieldDelegate d = new SetFieldDelegate(SetClientFieldThreadSafe);
1.1644 - this.Invoke(d, new object[] { aSessionId, aField });
1.1645 + this.Invoke(d, new object[] {aSessionId, aField});
1.1646 }
1.1647 else
1.1648 {
1.1649 @@ -1762,7 +1817,7 @@
1.1650 /// <param name="aSessionId"></param>
1.1651 /// <param name="aField"></param>
1.1652 private void SetClientField(string aSessionId, DataField aField)
1.1653 - {
1.1654 + {
1.1655 //TODO: should check if the field actually changed?
1.1656
1.1657 ClientData client = iClients[aSessionId];
1.1658 @@ -1796,22 +1851,22 @@
1.1659 //If we are updating a field in our current client we need to update it in our panel
1.1660 if (aSessionId == iCurrentClientSessionId)
1.1661 {
1.1662 - Control ctrl=iTableLayoutPanel.GetControlFromPosition(tableField.Column, tableField.Row);
1.1663 + Control ctrl = iTableLayoutPanel.GetControlFromPosition(tableField.Column, tableField.Row);
1.1664 if (aField.IsTextField && ctrl is MarqueeLabel)
1.1665 {
1.1666 - TextField textField=(TextField)aField;
1.1667 + TextField textField = (TextField) aField;
1.1668 //Text field control already in place, just change the text
1.1669 - MarqueeLabel label = (MarqueeLabel)ctrl;
1.1670 + MarqueeLabel label = (MarqueeLabel) ctrl;
1.1671 contentChanged = (label.Text != textField.Text || label.TextAlign != textField.Alignment);
1.1672 label.Text = textField.Text;
1.1673 label.TextAlign = textField.Alignment;
1.1674 }
1.1675 else if (aField.IsBitmapField && ctrl is PictureBox)
1.1676 {
1.1677 - BitmapField bitmapField = (BitmapField)aField;
1.1678 + BitmapField bitmapField = (BitmapField) aField;
1.1679 contentChanged = true; //TODO: Bitmap comp or should we leave that to clients?
1.1680 //Bitmap field control already in place just change the bitmap
1.1681 - PictureBox pictureBox = (PictureBox)ctrl;
1.1682 + PictureBox pictureBox = (PictureBox) ctrl;
1.1683 pictureBox.Image = bitmapField.Bitmap;
1.1684 }
1.1685 else
1.1686 @@ -1821,7 +1876,7 @@
1.1687 }
1.1688 }
1.1689 else
1.1690 - {
1.1691 + {
1.1692 layoutChanged = true;
1.1693 }
1.1694
1.1695 @@ -1864,7 +1919,7 @@
1.1696 {
1.1697 //Not in the proper thread, invoke ourselves
1.1698 SetFieldsDelegate d = new SetFieldsDelegate(SetClientFieldsThreadSafe);
1.1699 - this.Invoke(d, new object[] { aSessionId, aFields });
1.1700 + this.Invoke(d, new object[] {aSessionId, aFields});
1.1701 }
1.1702 else
1.1703 {
1.1704 @@ -1912,7 +1967,7 @@
1.1705 {
1.1706 //Not in the proper thread, invoke ourselves
1.1707 SetClientNameDelegate d = new SetClientNameDelegate(SetClientNameThreadSafe);
1.1708 - this.Invoke(d, new object[] { aSessionId, aName });
1.1709 + this.Invoke(d, new object[] {aSessionId, aName});
1.1710 }
1.1711 else
1.1712 {
1.1713 @@ -1936,7 +1991,7 @@
1.1714 {
1.1715 //Not in the proper thread, invoke ourselves
1.1716 SetClientPriorityDelegate d = new SetClientPriorityDelegate(SetClientPriorityThreadSafe);
1.1717 - this.Invoke(d, new object[] { aSessionId, aPriority });
1.1718 + this.Invoke(d, new object[] {aSessionId, aPriority});
1.1719 }
1.1720 else
1.1721 {
1.1722 @@ -1951,7 +2006,7 @@
1.1723 UpdateClientTreeViewNode(client);
1.1724 //Change our current client as per new priority
1.1725 ClientData newCurrentClient = FindHighestPriorityClient();
1.1726 - if (newCurrentClient!=null)
1.1727 + if (newCurrentClient != null)
1.1728 {
1.1729 SetCurrentClient(newCurrentClient.SessionId);
1.1730 }
1.1731 @@ -1967,7 +2022,7 @@
1.1732 /// <returns></returns>
1.1733 public static string Truncate(string value, int maxChars)
1.1734 {
1.1735 - return value.Length <= maxChars ? value : value.Substring(0, maxChars-3) + "...";
1.1736 + return value.Length <= maxChars ? value : value.Substring(0, maxChars - 3) + "...";
1.1737 }
1.1738
1.1739 /// <summary>
1.1740 @@ -1977,12 +2032,12 @@
1.1741 {
1.1742 //Go through each
1.1743 bool activeRecording = false;
1.1744 - string text="";
1.1745 - RecordingField recField=new RecordingField();
1.1746 + string text = "";
1.1747 + RecordingField recField = new RecordingField();
1.1748 foreach (var client in iClients)
1.1749 {
1.1750 - RecordingField rec=(RecordingField)client.Value.FindSameFieldAs(recField);
1.1751 - if (rec!=null && rec.IsActive)
1.1752 + RecordingField rec = (RecordingField) client.Value.FindSameFieldAs(recField);
1.1753 + if (rec != null && rec.IsActive)
1.1754 {
1.1755 activeRecording = true;
1.1756 //Don't break cause we are collecting the names/texts.
1.1757 @@ -1995,23 +2050,23 @@
1.1758 //Not text for that recording, use client name instead
1.1759 text += client.Value.Name + " recording\n";
1.1760 }
1.1761 -
1.1762 +
1.1763 }
1.1764 }
1.1765
1.1766 //Update our text no matter what, can't have more than 63 characters otherwise it throws an exception.
1.1767 - iRecordingNotification.Text = Truncate(text,63);
1.1768 + iRecordingNotification.Text = Truncate(text, 63);
1.1769
1.1770 //Change visibility of notification if needed
1.1771 if (iRecordingNotification.Visible != activeRecording)
1.1772 - {
1.1773 + {
1.1774 iRecordingNotification.Visible = activeRecording;
1.1775 //Assuming the notification icon is in sync with our display icon
1.1776 //Take care of our REC icon
1.1777 if (iDisplay.IsOpen())
1.1778 {
1.1779 iDisplay.SetIconOnOff(MiniDisplay.IconType.Recording, activeRecording);
1.1780 - }
1.1781 + }
1.1782 }
1.1783 }
1.1784
1.1785 @@ -2035,7 +2090,7 @@
1.1786 //Check that our client node already exists
1.1787 //Get our client root node using its key which is our session ID
1.1788 TreeNode[] nodes = iTreeViewClients.Nodes.Find(aClient.SessionId, false);
1.1789 - if (nodes.Count()>0)
1.1790 + if (nodes.Count() > 0)
1.1791 {
1.1792 //We already have a node for that client
1.1793 node = nodes[0];
1.1794 @@ -2078,7 +2133,7 @@
1.1795 {
1.1796 if (field.IsTextField)
1.1797 {
1.1798 - TextField textField = (TextField)field;
1.1799 + TextField textField = (TextField) field;
1.1800 textsRoot.Nodes.Add(new TreeNode("[Text]" + textField.Text));
1.1801 }
1.1802 else if (field.IsBitmapField)
1.1803 @@ -2087,7 +2142,7 @@
1.1804 }
1.1805 else if (field.IsRecordingField)
1.1806 {
1.1807 - RecordingField recordingField = (RecordingField)field;
1.1808 + RecordingField recordingField = (RecordingField) field;
1.1809 textsRoot.Nodes.Add(new TreeNode("[Recording]" + recordingField.IsActive));
1.1810 }
1.1811 }
1.1812 @@ -2105,7 +2160,7 @@
1.1813 foreach (RowStyle rowStyle in iTableLayoutPanel.RowStyles)
1.1814 {
1.1815 rowStyle.SizeType = SizeType.Percent;
1.1816 - rowStyle.Height = 100 / iTableLayoutPanel.RowCount;
1.1817 + rowStyle.Height = 100/iTableLayoutPanel.RowCount;
1.1818 }
1.1819 }
1.1820
1.1821 @@ -2119,11 +2174,11 @@
1.1822 {
1.1823 Debug.Print("UpdateTableLayoutPanel");
1.1824
1.1825 - if (aClient == null)
1.1826 - {
1.1827 - //Just drop it
1.1828 - return;
1.1829 - }
1.1830 + if (aClient == null)
1.1831 + {
1.1832 + //Just drop it
1.1833 + return;
1.1834 + }
1.1835
1.1836
1.1837 TableLayout layout = aClient.Layout;
1.1838 @@ -2177,7 +2232,7 @@
1.1839 continue;
1.1840 }
1.1841
1.1842 - TableField tableField = (TableField)field;
1.1843 + TableField tableField = (TableField) field;
1.1844
1.1845 //Create a control corresponding to the field specified for that cell
1.1846 Control control = CreateControlForDataField(tableField);
1.1847 @@ -2199,7 +2254,7 @@
1.1848 /// <param name="aField"></param>
1.1849 private Control CreateControlForDataField(DataField aField)
1.1850 {
1.1851 - Control control=null;
1.1852 + Control control = null;
1.1853 if (aField.IsTextField)
1.1854 {
1.1855 MarqueeLabel label = new SharpDisplayManager.MarqueeLabel();
1.1856 @@ -2219,7 +2274,7 @@
1.1857 //control.TabIndex = 2;
1.1858 label.Font = cds.Font;
1.1859
1.1860 - TextField field = (TextField)aField;
1.1861 + TextField field = (TextField) aField;
1.1862 label.TextAlign = field.Alignment;
1.1863 label.UseCompatibleTextRendering = true;
1.1864 label.Text = field.Text;
1.1865 @@ -2237,7 +2292,7 @@
1.1866 picture.Margin = new System.Windows.Forms.Padding(0);
1.1867 picture.Name = "pictureBox" + aField;
1.1868 //Set our image
1.1869 - BitmapField field = (BitmapField)aField;
1.1870 + BitmapField field = (BitmapField) aField;
1.1871 picture.Image = field.Bitmap;
1.1872 //
1.1873 control = picture;
1.1874 @@ -2247,20 +2302,20 @@
1.1875 return control;
1.1876 }
1.1877
1.1878 - /// <summary>
1.1879 - /// Called when the user selected a new display type.
1.1880 - /// </summary>
1.1881 - /// <param name="sender"></param>
1.1882 - /// <param name="e"></param>
1.1883 + /// <summary>
1.1884 + /// Called when the user selected a new display type.
1.1885 + /// </summary>
1.1886 + /// <param name="sender"></param>
1.1887 + /// <param name="e"></param>
1.1888 private void comboBoxDisplayType_SelectedIndexChanged(object sender, EventArgs e)
1.1889 {
1.1890 - //Store the selected display type in our settings
1.1891 + //Store the selected display type in our settings
1.1892 Properties.Settings.Default.CurrentDisplayIndex = comboBoxDisplayType.SelectedIndex;
1.1893 cds.DisplayType = comboBoxDisplayType.SelectedIndex;
1.1894 Properties.Settings.Default.Save();
1.1895
1.1896 - //Try re-opening the display connection if we were already connected.
1.1897 - //Otherwise just update our status to reflect display type change.
1.1898 + //Try re-opening the display connection if we were already connected.
1.1899 + //Otherwise just update our status to reflect display type change.
1.1900 if (iDisplay.IsOpen())
1.1901 {
1.1902 OpenDisplayConnection();
1.1903 @@ -2296,39 +2351,39 @@
1.1904 {
1.1905 cds.MinFontSize = minFontSize;
1.1906 Properties.Settings.Default.Save();
1.1907 - //We need to recreate our layout for that change to take effect
1.1908 - UpdateTableLayoutPanel(iCurrentClientData);
1.1909 + //We need to recreate our layout for that change to take effect
1.1910 + UpdateTableLayoutPanel(iCurrentClientData);
1.1911 }
1.1912 }
1.1913 }
1.1914
1.1915
1.1916 - private void maskedTextBoxScrollingSpeed_TextChanged(object sender, EventArgs e)
1.1917 - {
1.1918 - if (maskedTextBoxScrollingSpeed.Text != "")
1.1919 - {
1.1920 - int scrollingSpeed = Convert.ToInt32(maskedTextBoxScrollingSpeed.Text);
1.1921 -
1.1922 - if (scrollingSpeed > 0)
1.1923 - {
1.1924 - cds.ScrollingSpeedInPixelsPerSecond = scrollingSpeed;
1.1925 - Properties.Settings.Default.Save();
1.1926 - //We need to recreate our layout for that change to take effect
1.1927 - UpdateTableLayoutPanel(iCurrentClientData);
1.1928 - }
1.1929 - }
1.1930 - }
1.1931 + private void maskedTextBoxScrollingSpeed_TextChanged(object sender, EventArgs e)
1.1932 + {
1.1933 + if (maskedTextBoxScrollingSpeed.Text != "")
1.1934 + {
1.1935 + int scrollingSpeed = Convert.ToInt32(maskedTextBoxScrollingSpeed.Text);
1.1936 +
1.1937 + if (scrollingSpeed > 0)
1.1938 + {
1.1939 + cds.ScrollingSpeedInPixelsPerSecond = scrollingSpeed;
1.1940 + Properties.Settings.Default.Save();
1.1941 + //We need to recreate our layout for that change to take effect
1.1942 + UpdateTableLayoutPanel(iCurrentClientData);
1.1943 + }
1.1944 + }
1.1945 + }
1.1946
1.1947 private void textBoxScrollLoopSeparator_TextChanged(object sender, EventArgs e)
1.1948 {
1.1949 cds.Separator = textBoxScrollLoopSeparator.Text;
1.1950 Properties.Settings.Default.Save();
1.1951
1.1952 - //Update our text fields
1.1953 - foreach (MarqueeLabel ctrl in iTableLayoutPanel.Controls)
1.1954 - {
1.1955 - ctrl.Separator = cds.Separator;
1.1956 - }
1.1957 + //Update our text fields
1.1958 + foreach (MarqueeLabel ctrl in iTableLayoutPanel.Controls)
1.1959 + {
1.1960 + ctrl.Separator = cds.Separator;
1.1961 + }
1.1962
1.1963 }
1.1964
1.1965 @@ -2344,12 +2399,12 @@
1.1966
1.1967 private void buttonShowClock_Click(object sender, EventArgs e)
1.1968 {
1.1969 - ShowClock();
1.1970 + ShowClock();
1.1971 }
1.1972
1.1973 private void buttonHideClock_Click(object sender, EventArgs e)
1.1974 {
1.1975 - HideClock();
1.1976 + HideClock();
1.1977 }
1.1978
1.1979 private void buttonUpdate_Click(object sender, EventArgs e)
1.1980 @@ -2357,39 +2412,39 @@
1.1981 InstallUpdateSyncWithInfo();
1.1982 }
1.1983
1.1984 - /// <summary>
1.1985 - ///
1.1986 - /// </summary>
1.1987 - void ShowClock()
1.1988 - {
1.1989 - if (!iDisplay.IsOpen())
1.1990 - {
1.1991 - return;
1.1992 - }
1.1993 -
1.1994 - //Devices like MDM166AA don't support windowing and frame rendering must be stopped while showing our clock
1.1995 - iSkipFrameRendering = true;
1.1996 - //Clear our screen
1.1997 - iDisplay.Clear();
1.1998 - iDisplay.SwapBuffers();
1.1999 - //Then show our clock
1.2000 - iDisplay.ShowClock();
1.2001 - }
1.2002 -
1.2003 - /// <summary>
1.2004 - ///
1.2005 - /// </summary>
1.2006 - void HideClock()
1.2007 - {
1.2008 - if (!iDisplay.IsOpen())
1.2009 - {
1.2010 - return;
1.2011 - }
1.2012 -
1.2013 - //Devices like MDM166AA don't support windowing and frame rendering must be stopped while showing our clock
1.2014 - iSkipFrameRendering = false;
1.2015 - iDisplay.HideClock();
1.2016 - }
1.2017 + /// <summary>
1.2018 + ///
1.2019 + /// </summary>
1.2020 + void ShowClock()
1.2021 + {
1.2022 + if (!iDisplay.IsOpen())
1.2023 + {
1.2024 + return;
1.2025 + }
1.2026 +
1.2027 + //Devices like MDM166AA don't support windowing and frame rendering must be stopped while showing our clock
1.2028 + iSkipFrameRendering = true;
1.2029 + //Clear our screen
1.2030 + iDisplay.Clear();
1.2031 + iDisplay.SwapBuffers();
1.2032 + //Then show our clock
1.2033 + iDisplay.ShowClock();
1.2034 + }
1.2035 +
1.2036 + /// <summary>
1.2037 + ///
1.2038 + /// </summary>
1.2039 + void HideClock()
1.2040 + {
1.2041 + if (!iDisplay.IsOpen())
1.2042 + {
1.2043 + return;
1.2044 + }
1.2045 +
1.2046 + //Devices like MDM166AA don't support windowing and frame rendering must be stopped while showing our clock
1.2047 + iSkipFrameRendering = false;
1.2048 + iDisplay.HideClock();
1.2049 + }
1.2050
1.2051 private void InstallUpdateSyncWithInfo()
1.2052 {
1.2053 @@ -2406,125 +2461,135 @@
1.2054 }
1.2055 catch (DeploymentDownloadException dde)
1.2056 {
1.2057 - MessageBox.Show("The new version of the application cannot be downloaded at this time. \n\nPlease check your network connection, or try again later. Error: " + dde.Message);
1.2058 + MessageBox.Show(
1.2059 + "The new version of the application cannot be downloaded at this time. \n\nPlease check your network connection, or try again later. Error: " +
1.2060 + dde.Message);
1.2061 return;
1.2062 }
1.2063 catch (InvalidDeploymentException ide)
1.2064 {
1.2065 - MessageBox.Show("Cannot check for a new version of the application. The ClickOnce deployment is corrupt. Please redeploy the application and try again. Error: " + ide.Message);
1.2066 + MessageBox.Show(
1.2067 + "Cannot check for a new version of the application. The ClickOnce deployment is corrupt. Please redeploy the application and try again. Error: " +
1.2068 + ide.Message);
1.2069 return;
1.2070 }
1.2071 catch (InvalidOperationException ioe)
1.2072 {
1.2073 - MessageBox.Show("This application cannot be updated. It is likely not a ClickOnce application. Error: " + ioe.Message);
1.2074 + MessageBox.Show(
1.2075 + "This application cannot be updated. It is likely not a ClickOnce application. Error: " +
1.2076 + ioe.Message);
1.2077 return;
1.2078 }
1.2079
1.2080 - if (info.UpdateAvailable)
1.2081 - {
1.2082 - Boolean doUpdate = true;
1.2083 -
1.2084 - if (!info.IsUpdateRequired)
1.2085 - {
1.2086 - DialogResult dr = MessageBox.Show("An update is available. Would you like to update the application now?", "Update Available", MessageBoxButtons.OKCancel);
1.2087 - if (!(DialogResult.OK == dr))
1.2088 - {
1.2089 - doUpdate = false;
1.2090 - }
1.2091 - }
1.2092 - else
1.2093 - {
1.2094 - // Display a message that the application MUST reboot. Display the minimum required version.
1.2095 - MessageBox.Show("This application has detected a mandatory update from your current " +
1.2096 - "version to version " + info.MinimumRequiredVersion.ToString() +
1.2097 - ". The application will now install the update and restart.",
1.2098 - "Update Available", MessageBoxButtons.OK,
1.2099 - MessageBoxIcon.Information);
1.2100 - }
1.2101 -
1.2102 - if (doUpdate)
1.2103 - {
1.2104 - try
1.2105 - {
1.2106 - ad.Update();
1.2107 - MessageBox.Show("The application has been upgraded, and will now restart.");
1.2108 - Application.Restart();
1.2109 - }
1.2110 - catch (DeploymentDownloadException dde)
1.2111 - {
1.2112 - MessageBox.Show("Cannot install the latest version of the application. \n\nPlease check your network connection, or try again later. Error: " + dde);
1.2113 - return;
1.2114 - }
1.2115 - }
1.2116 - }
1.2117 - else
1.2118 - {
1.2119 - MessageBox.Show("You are already running the latest version.", "Application up-to-date");
1.2120 - }
1.2121 + if (info.UpdateAvailable)
1.2122 + {
1.2123 + Boolean doUpdate = true;
1.2124 +
1.2125 + if (!info.IsUpdateRequired)
1.2126 + {
1.2127 + DialogResult dr =
1.2128 + MessageBox.Show("An update is available. Would you like to update the application now?",
1.2129 + "Update Available", MessageBoxButtons.OKCancel);
1.2130 + if (!(DialogResult.OK == dr))
1.2131 + {
1.2132 + doUpdate = false;
1.2133 + }
1.2134 + }
1.2135 + else
1.2136 + {
1.2137 + // Display a message that the application MUST reboot. Display the minimum required version.
1.2138 + MessageBox.Show("This application has detected a mandatory update from your current " +
1.2139 + "version to version " + info.MinimumRequiredVersion.ToString() +
1.2140 + ". The application will now install the update and restart.",
1.2141 + "Update Available", MessageBoxButtons.OK,
1.2142 + MessageBoxIcon.Information);
1.2143 + }
1.2144 +
1.2145 + if (doUpdate)
1.2146 + {
1.2147 + try
1.2148 + {
1.2149 + ad.Update();
1.2150 + MessageBox.Show("The application has been upgraded, and will now restart.");
1.2151 + Application.Restart();
1.2152 + }
1.2153 + catch (DeploymentDownloadException dde)
1.2154 + {
1.2155 + MessageBox.Show(
1.2156 + "Cannot install the latest version of the application. \n\nPlease check your network connection, or try again later. Error: " +
1.2157 + dde);
1.2158 + return;
1.2159 + }
1.2160 + }
1.2161 + }
1.2162 + else
1.2163 + {
1.2164 + MessageBox.Show("You are already running the latest version.", "Application up-to-date");
1.2165 + }
1.2166 }
1.2167 }
1.2168
1.2169
1.2170 - /// <summary>
1.2171 - /// Used to
1.2172 - /// </summary>
1.2173 - private void SysTrayHideShow()
1.2174 - {
1.2175 - Visible = !Visible;
1.2176 - if (Visible)
1.2177 - {
1.2178 - Activate();
1.2179 - WindowState = FormWindowState.Normal;
1.2180 - }
1.2181 - }
1.2182 -
1.2183 - /// <summary>
1.2184 - /// Use to handle minimize events.
1.2185 - /// </summary>
1.2186 - /// <param name="sender"></param>
1.2187 - /// <param name="e"></param>
1.2188 - private void MainForm_SizeChanged(object sender, EventArgs e)
1.2189 - {
1.2190 - if (WindowState == FormWindowState.Minimized && Properties.Settings.Default.MinimizeToTray)
1.2191 - {
1.2192 - if (Visible)
1.2193 - {
1.2194 - SysTrayHideShow();
1.2195 - }
1.2196 - }
1.2197 - }
1.2198 -
1.2199 - /// <summary>
1.2200 - ///
1.2201 - /// </summary>
1.2202 - /// <param name="sender"></param>
1.2203 - /// <param name="e"></param>
1.2204 - private void tableLayoutPanel_SizeChanged(object sender, EventArgs e)
1.2205 - {
1.2206 - //Our table layout size has changed which means our display size has changed.
1.2207 - //We need to re-create our bitmap.
1.2208 - iCreateBitmap = true;
1.2209 - }
1.2210 -
1.2211 - /// <summary>
1.2212 - ///
1.2213 - /// </summary>
1.2214 - /// <param name="sender"></param>
1.2215 - /// <param name="e"></param>
1.2216 - private void buttonSelectFile_Click(object sender, EventArgs e)
1.2217 - {
1.2218 - //openFileDialog1.InitialDirectory = "c:\\";
1.2219 - //openFileDialog.Filter = "EXE files (*.exe)|*.exe|All files (*.*)|*.*";
1.2220 - //openFileDialog.FilterIndex = 1;
1.2221 - openFileDialog.RestoreDirectory = true;
1.2222 -
1.2223 - if (DlgBox.ShowDialog(openFileDialog) == DialogResult.OK)
1.2224 - {
1.2225 - labelStartFileName.Text = openFileDialog.FileName;
1.2226 - Properties.Settings.Default.StartFileName = openFileDialog.FileName;
1.2227 - Properties.Settings.Default.Save();
1.2228 - }
1.2229 - }
1.2230 + /// <summary>
1.2231 + /// Used to
1.2232 + /// </summary>
1.2233 + private void SysTrayHideShow()
1.2234 + {
1.2235 + Visible = !Visible;
1.2236 + if (Visible)
1.2237 + {
1.2238 + Activate();
1.2239 + WindowState = FormWindowState.Normal;
1.2240 + }
1.2241 + }
1.2242 +
1.2243 + /// <summary>
1.2244 + /// Use to handle minimize events.
1.2245 + /// </summary>
1.2246 + /// <param name="sender"></param>
1.2247 + /// <param name="e"></param>
1.2248 + private void MainForm_SizeChanged(object sender, EventArgs e)
1.2249 + {
1.2250 + if (WindowState == FormWindowState.Minimized && Properties.Settings.Default.MinimizeToTray)
1.2251 + {
1.2252 + if (Visible)
1.2253 + {
1.2254 + SysTrayHideShow();
1.2255 + }
1.2256 + }
1.2257 + }
1.2258 +
1.2259 + /// <summary>
1.2260 + ///
1.2261 + /// </summary>
1.2262 + /// <param name="sender"></param>
1.2263 + /// <param name="e"></param>
1.2264 + private void tableLayoutPanel_SizeChanged(object sender, EventArgs e)
1.2265 + {
1.2266 + //Our table layout size has changed which means our display size has changed.
1.2267 + //We need to re-create our bitmap.
1.2268 + iCreateBitmap = true;
1.2269 + }
1.2270 +
1.2271 + /// <summary>
1.2272 + ///
1.2273 + /// </summary>
1.2274 + /// <param name="sender"></param>
1.2275 + /// <param name="e"></param>
1.2276 + private void buttonSelectFile_Click(object sender, EventArgs e)
1.2277 + {
1.2278 + //openFileDialog1.InitialDirectory = "c:\\";
1.2279 + //openFileDialog.Filter = "EXE files (*.exe)|*.exe|All files (*.*)|*.*";
1.2280 + //openFileDialog.FilterIndex = 1;
1.2281 + openFileDialog.RestoreDirectory = true;
1.2282 +
1.2283 + if (DlgBox.ShowDialog(openFileDialog) == DialogResult.OK)
1.2284 + {
1.2285 + labelStartFileName.Text = openFileDialog.FileName;
1.2286 + Properties.Settings.Default.StartFileName = openFileDialog.FileName;
1.2287 + Properties.Settings.Default.Save();
1.2288 + }
1.2289 + }
1.2290
1.2291 /// <summary>
1.2292 ///
1.2293 @@ -2559,11 +2624,11 @@
1.2294 {
1.2295 LogsUpdate();
1.2296
1.2297 - if (OnWndProc!=null)
1.2298 + if (OnWndProc != null)
1.2299 {
1.2300 OnWndProc(ref aMessage);
1.2301 }
1.2302 -
1.2303 +
1.2304 base.WndProc(ref aMessage);
1.2305 }
1.2306
1.2307 @@ -2591,7 +2656,7 @@
1.2308 /// </summary>
1.2309 private void ResetCec()
1.2310 {
1.2311 - if (iCecManager==null)
1.2312 + if (iCecManager == null)
1.2313 {
1.2314 //Thus skipping initial UI setup
1.2315 return;
1.2316 @@ -2602,7 +2667,7 @@
1.2317 if (Properties.Settings.Default.CecEnabled)
1.2318 {
1.2319 iCecManager.Start(Handle, "CEC",
1.2320 - Properties.Settings.Default.CecHdmiPort);
1.2321 + Properties.Settings.Default.CecHdmiPort);
1.2322
1.2323 SetupCecLogLevel();
1.2324 }
1.2325 @@ -2617,19 +2682,19 @@
1.2326 iCecManager.Client.LogLevel = 0;
1.2327
1.2328 if (checkBoxCecLogError.Checked)
1.2329 - iCecManager.Client.LogLevel |= (int)CecLogLevel.Error;
1.2330 + iCecManager.Client.LogLevel |= (int) CecLogLevel.Error;
1.2331
1.2332 if (checkBoxCecLogWarning.Checked)
1.2333 - iCecManager.Client.LogLevel |= (int)CecLogLevel.Warning;
1.2334 + iCecManager.Client.LogLevel |= (int) CecLogLevel.Warning;
1.2335
1.2336 if (checkBoxCecLogNotice.Checked)
1.2337 - iCecManager.Client.LogLevel |= (int)CecLogLevel.Notice;
1.2338 + iCecManager.Client.LogLevel |= (int) CecLogLevel.Notice;
1.2339
1.2340 if (checkBoxCecLogTraffic.Checked)
1.2341 - iCecManager.Client.LogLevel |= (int)CecLogLevel.Traffic;
1.2342 + iCecManager.Client.LogLevel |= (int) CecLogLevel.Traffic;
1.2343
1.2344 if (checkBoxCecLogDebug.Checked)
1.2345 - iCecManager.Client.LogLevel |= (int)CecLogLevel.Debug;
1.2346 + iCecManager.Client.LogLevel |= (int) CecLogLevel.Debug;
1.2347
1.2348 iCecManager.Client.FilterOutPollLogs = checkBoxCecLogNoPoll.Checked;
1.2349
1.2350 @@ -2650,7 +2715,7 @@
1.2351 SetupCecLogLevel();
1.2352 }
1.2353
1.2354 -
1.2355 +
1.2356 /// <summary>
1.2357 ///
1.2358 /// </summary>
1.2359 @@ -2663,9 +2728,9 @@
1.2360 }
1.2361
1.2362 string key = aEvent.GetType().Name;
1.2363 - TreeNode[] res=iTreeViewEvents.Nodes.Find(key, false);
1.2364 + TreeNode[] res = iTreeViewEvents.Nodes.Find(key, false);
1.2365 if (res.Length > 0)
1.2366 - {
1.2367 + {
1.2368 iTreeViewEvents.SelectedNode = res[0];
1.2369 iTreeViewEvents.Focus();
1.2370 }
1.2371 @@ -2686,7 +2751,7 @@
1.2372 {
1.2373 if (node.Tag is Event)
1.2374 {
1.2375 - selectedEvent = (Event)node.Tag;
1.2376 + selectedEvent = (Event) node.Tag;
1.2377 break;
1.2378 }
1.2379 node = node.Parent;
1.2380 @@ -2728,7 +2793,7 @@
1.2381 DialogResult res = CodeProject.Dialog.DlgBox.ShowDialog(ea);
1.2382 if (res == DialogResult.OK)
1.2383 {
1.2384 - selectedEvent.Actions.Add(ea.Action);
1.2385 + selectedEvent.Actions.Add(ea.Action);
1.2386 Properties.Settings.Default.Actions = ManagerEventAction.Current;
1.2387 Properties.Settings.Default.Save();
1.2388 PopulateEventsTreeView();
1.2389 @@ -2760,7 +2825,98 @@
1.2390 {
1.2391 //Enable buttons according to selected item
1.2392 buttonAddAction.Enabled = CurrentEvent() != null;
1.2393 - buttonDeleteAction.Enabled = CurrentAction() != null;
1.2394 +
1.2395 + SharpLib.Ear.Action currentAction = CurrentAction();
1.2396 + //If an action is selected enable the following buttons
1.2397 + buttonTestAction.Enabled =
1.2398 + buttonDeleteAction.Enabled =
1.2399 + buttonActionMoveUp.Enabled =
1.2400 + buttonActionMoveDown.Enabled =
1.2401 + currentAction != null;
1.2402 +
1.2403 + if (currentAction != null)
1.2404 + {
1.2405 + //If an action is selected enable move buttons if needed
1.2406 + buttonActionMoveUp.Enabled = iTreeViewEvents.SelectedNode.Index != 0;
1.2407 + buttonActionMoveDown.Enabled = iTreeViewEvents.SelectedNode.Index <
1.2408 + iTreeViewEvents.SelectedNode.Parent.Nodes.Count - 1;
1.2409 + }
1.2410 +
1.2411 + }
1.2412 +
1.2413 + /// <summary>
1.2414 + ///
1.2415 + /// </summary>
1.2416 + /// <param name="sender"></param>
1.2417 + /// <param name="e"></param>
1.2418 + private void buttonTestAction_Click(object sender, EventArgs e)
1.2419 + {
1.2420 + SharpLib.Ear.Action a = CurrentAction();
1.2421 + if (a != null)
1.2422 + {
1.2423 + Console.WriteLine("Action test run");
1.2424 + a.Execute();
1.2425 + }
1.2426 + iTreeViewEvents.Focus();
1.2427 + }
1.2428 +
1.2429 + /// <summary>
1.2430 + ///
1.2431 + /// </summary>
1.2432 + /// <param name="sender"></param>
1.2433 + /// <param name="e"></param>
1.2434 + private void buttonActionMoveUp_Click(object sender, EventArgs e)
1.2435 + {
1.2436 + SharpLib.Ear.Action a = CurrentAction();
1.2437 + if (a == null ||
1.2438 + //Action already at the top of the list
1.2439 + iTreeViewEvents.SelectedNode.Index == 0)
1.2440 + {
1.2441 + return;
1.2442 + }
1.2443 +
1.2444 + //Swap actions in event's action list
1.2445 + Event currentEvent = CurrentEvent();
1.2446 + int currentIndex = iTreeViewEvents.SelectedNode.Index;
1.2447 + SharpLib.Ear.Action movingUp = currentEvent.Actions[currentIndex];
1.2448 + SharpLib.Ear.Action movingDown = currentEvent.Actions[currentIndex-1];
1.2449 + currentEvent.Actions[currentIndex] = movingDown;
1.2450 + currentEvent.Actions[currentIndex-1] = movingUp;
1.2451 +
1.2452 + //Save and populate our tree again
1.2453 + Properties.Settings.Default.Actions = ManagerEventAction.Current;
1.2454 + Properties.Settings.Default.Save();
1.2455 + PopulateEventsTreeView();
1.2456 +
1.2457 + }
1.2458 +
1.2459 + /// <summary>
1.2460 + ///
1.2461 + /// </summary>
1.2462 + /// <param name="sender"></param>
1.2463 + /// <param name="e"></param>
1.2464 + private void buttonActionMoveDown_Click(object sender, EventArgs e)
1.2465 + {
1.2466 + SharpLib.Ear.Action a = CurrentAction();
1.2467 + if (a == null ||
1.2468 + //Action already at the bottom of the list
1.2469 + iTreeViewEvents.SelectedNode.Index == iTreeViewEvents.SelectedNode.Parent.Nodes.Count - 1)
1.2470 + {
1.2471 + return;
1.2472 + }
1.2473 +
1.2474 + //Swap actions in event's action list
1.2475 + Event currentEvent = CurrentEvent();
1.2476 + int currentIndex = iTreeViewEvents.SelectedNode.Index;
1.2477 + SharpLib.Ear.Action movingDown = currentEvent.Actions[currentIndex];
1.2478 + SharpLib.Ear.Action movingUp = currentEvent.Actions[currentIndex + 1];
1.2479 + currentEvent.Actions[currentIndex] = movingUp;
1.2480 + currentEvent.Actions[currentIndex + 1] = movingDown;
1.2481 +
1.2482 + //Save and populate our tree again
1.2483 + Properties.Settings.Default.Actions = ManagerEventAction.Current;
1.2484 + Properties.Settings.Default.Save();
1.2485 + PopulateEventsTreeView();
1.2486 }
1.2487 }
1.2488 }