sl@0
|
1 |
using System;
|
sl@0
|
2 |
using System.Collections.Generic;
|
sl@0
|
3 |
using System.ComponentModel;
|
sl@0
|
4 |
using System.Data;
|
sl@0
|
5 |
using System.Drawing;
|
sl@0
|
6 |
using System.Linq;
|
sl@0
|
7 |
using System.Text;
|
sl@0
|
8 |
using System.Threading.Tasks;
|
sl@0
|
9 |
using System.Windows.Forms;
|
sl@14
|
10 |
using System.IO;
|
sl@0
|
11 |
using CodeProject.Dialog;
|
sl@14
|
12 |
using System.Drawing.Imaging;
|
sl@17
|
13 |
using System.ServiceModel;
|
sl@25
|
14 |
using System.Threading;
|
sl@31
|
15 |
using System.Diagnostics;
|
sl@88
|
16 |
using System.Deployment.Application;
|
sl@94
|
17 |
using System.Reflection;
|
StephaneLenclud@112
|
18 |
//NAudio
|
StephaneLenclud@112
|
19 |
using NAudio.CoreAudioApi;
|
StephaneLenclud@112
|
20 |
using NAudio.CoreAudioApi.Interfaces;
|
StephaneLenclud@112
|
21 |
using System.Runtime.InteropServices;
|
StephaneLenclud@117
|
22 |
//Network
|
StephaneLenclud@117
|
23 |
using NETWORKLIST;
|
sl@25
|
24 |
//
|
sl@25
|
25 |
using SharpDisplayClient;
|
sl@55
|
26 |
using SharpDisplay;
|
sl@0
|
27 |
|
sl@0
|
28 |
namespace SharpDisplayManager
|
sl@0
|
29 |
{
|
sl@58
|
30 |
//Types declarations
|
sl@58
|
31 |
public delegate uint ColorProcessingDelegate(int aX, int aY, uint aPixel);
|
sl@58
|
32 |
public delegate int CoordinateTranslationDelegate(System.Drawing.Bitmap aBmp, int aInt);
|
sl@62
|
33 |
//Delegates are used for our thread safe method
|
sl@62
|
34 |
public delegate void AddClientDelegate(string aSessionId, ICallback aCallback);
|
sl@62
|
35 |
public delegate void RemoveClientDelegate(string aSessionId);
|
sl@79
|
36 |
public delegate void SetFieldDelegate(string SessionId, DataField aField);
|
sl@79
|
37 |
public delegate void SetFieldsDelegate(string SessionId, System.Collections.Generic.IList<DataField> aFields);
|
sl@62
|
38 |
public delegate void SetLayoutDelegate(string SessionId, TableLayout aLayout);
|
sl@62
|
39 |
public delegate void SetClientNameDelegate(string aSessionId, string aName);
|
StephaneLenclud@112
|
40 |
public delegate void PlainUpdateDelegate();
|
sl@62
|
41 |
|
sl@58
|
42 |
|
sl@58
|
43 |
/// <summary>
|
sl@58
|
44 |
/// Our Display manager main form
|
sl@58
|
45 |
/// </summary>
|
StephaneLenclud@112
|
46 |
public partial class MainForm : Form, IMMNotificationClient
|
sl@0
|
47 |
{
|
sl@2
|
48 |
DateTime LastTickTime;
|
sl@3
|
49 |
Display iDisplay;
|
sl@14
|
50 |
System.Drawing.Bitmap iBmp;
|
sl@14
|
51 |
bool iCreateBitmap; //Workaround render to bitmap issues when minimized
|
sl@17
|
52 |
ServiceHost iServiceHost;
|
sl@65
|
53 |
// Our collection of clients sorted by session id.
|
sl@33
|
54 |
public Dictionary<string, ClientData> iClients;
|
sl@65
|
55 |
// The name of the client which informations are currently displayed.
|
sl@65
|
56 |
public string iCurrentClientSessionId;
|
sl@65
|
57 |
ClientData iCurrentClientData;
|
sl@65
|
58 |
//
|
sl@29
|
59 |
public bool iClosing;
|
sl@65
|
60 |
//Function pointer for pixel color filtering
|
sl@58
|
61 |
ColorProcessingDelegate iColorFx;
|
sl@65
|
62 |
//Function pointer for pixel X coordinate intercept
|
sl@58
|
63 |
CoordinateTranslationDelegate iScreenX;
|
sl@65
|
64 |
//Function pointer for pixel Y coordinate intercept
|
sl@58
|
65 |
CoordinateTranslationDelegate iScreenY;
|
StephaneLenclud@112
|
66 |
//NAudio
|
StephaneLenclud@112
|
67 |
private MMDeviceEnumerator iMultiMediaDeviceEnumerator;
|
StephaneLenclud@112
|
68 |
private MMDevice iMultiMediaDevice;
|
StephaneLenclud@117
|
69 |
//Network
|
StephaneLenclud@117
|
70 |
private NetworkManager iNetworkManager;
|
StephaneLenclud@112
|
71 |
|
sl@2
|
72 |
|
sl@94
|
73 |
/// <summary>
|
sl@94
|
74 |
/// Manage run when Windows startup option
|
sl@94
|
75 |
/// </summary>
|
sl@92
|
76 |
private StartupManager iStartupManager;
|
sl@92
|
77 |
|
sl@94
|
78 |
/// <summary>
|
sl@94
|
79 |
/// System tray icon.
|
sl@94
|
80 |
/// </summary>
|
sl@94
|
81 |
private NotifyIconAdv iNotifyIcon;
|
sl@94
|
82 |
|
sl@0
|
83 |
public MainForm()
|
sl@0
|
84 |
{
|
sl@65
|
85 |
iCurrentClientSessionId = "";
|
sl@65
|
86 |
iCurrentClientData = null;
|
sl@2
|
87 |
LastTickTime = DateTime.Now;
|
StephaneLenclud@104
|
88 |
//Instantiate our display and register for events notifications
|
sl@3
|
89 |
iDisplay = new Display();
|
StephaneLenclud@104
|
90 |
iDisplay.OnOpened += OnDisplayOpened;
|
StephaneLenclud@104
|
91 |
iDisplay.OnClosed += OnDisplayClosed;
|
StephaneLenclud@104
|
92 |
//
|
StephaneLenclud@104
|
93 |
iClients = new Dictionary<string, ClientData>();
|
sl@92
|
94 |
iStartupManager = new StartupManager();
|
sl@94
|
95 |
iNotifyIcon = new NotifyIconAdv();
|
sl@2
|
96 |
|
StephaneLenclud@104
|
97 |
//Have our designer initialize its controls
|
sl@0
|
98 |
InitializeComponent();
|
StephaneLenclud@104
|
99 |
|
StephaneLenclud@104
|
100 |
//Populate device types
|
StephaneLenclud@104
|
101 |
PopulateDeviceTypes();
|
StephaneLenclud@104
|
102 |
|
StephaneLenclud@104
|
103 |
//Initial status update
|
sl@7
|
104 |
UpdateStatus();
|
StephaneLenclud@104
|
105 |
|
sl@14
|
106 |
//We have a bug when drawing minimized and reusing our bitmap
|
sl@14
|
107 |
iBmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height, PixelFormat.Format32bppArgb);
|
sl@14
|
108 |
iCreateBitmap = false;
|
sl@94
|
109 |
|
StephaneLenclud@104
|
110 |
//Minimize our window if desired
|
sl@94
|
111 |
if (Properties.Settings.Default.StartMinimized)
|
sl@94
|
112 |
{
|
sl@94
|
113 |
WindowState = FormWindowState.Minimized;
|
sl@94
|
114 |
}
|
sl@94
|
115 |
|
sl@0
|
116 |
}
|
sl@0
|
117 |
|
sl@94
|
118 |
/// <summary>
|
StephaneLenclud@106
|
119 |
///
|
StephaneLenclud@106
|
120 |
/// </summary>
|
StephaneLenclud@106
|
121 |
/// <param name="sender"></param>
|
StephaneLenclud@106
|
122 |
/// <param name="e"></param>
|
StephaneLenclud@106
|
123 |
private void MainForm_Load(object sender, EventArgs e)
|
StephaneLenclud@106
|
124 |
{
|
StephaneLenclud@106
|
125 |
//Check if we are running a Click Once deployed application
|
StephaneLenclud@106
|
126 |
if (ApplicationDeployment.IsNetworkDeployed)
|
StephaneLenclud@106
|
127 |
{
|
StephaneLenclud@106
|
128 |
//This is a proper Click Once installation, fetch and show our version number
|
StephaneLenclud@106
|
129 |
this.Text += " - v" + ApplicationDeployment.CurrentDeployment.CurrentVersion;
|
StephaneLenclud@106
|
130 |
}
|
StephaneLenclud@106
|
131 |
else
|
StephaneLenclud@106
|
132 |
{
|
StephaneLenclud@106
|
133 |
//Not a proper Click Once installation, assuming development build then
|
StephaneLenclud@106
|
134 |
this.Text += " - development";
|
StephaneLenclud@106
|
135 |
}
|
StephaneLenclud@106
|
136 |
|
StephaneLenclud@112
|
137 |
//NAudio
|
StephaneLenclud@112
|
138 |
iMultiMediaDeviceEnumerator = new MMDeviceEnumerator();
|
StephaneLenclud@117
|
139 |
iMultiMediaDeviceEnumerator.RegisterEndpointNotificationCallback(this);
|
StephaneLenclud@112
|
140 |
UpdateAudioDeviceAndMasterVolumeThreadSafe();
|
StephaneLenclud@112
|
141 |
|
StephaneLenclud@117
|
142 |
//Network
|
StephaneLenclud@117
|
143 |
iNetworkManager = new NetworkManager();
|
StephaneLenclud@117
|
144 |
iNetworkManager.OnConnectivityChanged += OnConnectivityChanged;
|
StephaneLenclud@117
|
145 |
UpdateNetworkStatus();
|
StephaneLenclud@117
|
146 |
|
StephaneLenclud@106
|
147 |
//Setup notification icon
|
StephaneLenclud@106
|
148 |
SetupTrayIcon();
|
StephaneLenclud@106
|
149 |
|
StephaneLenclud@106
|
150 |
// To make sure start up with minimize to tray works
|
StephaneLenclud@106
|
151 |
if (WindowState == FormWindowState.Minimized && Properties.Settings.Default.MinimizeToTray)
|
StephaneLenclud@106
|
152 |
{
|
StephaneLenclud@106
|
153 |
Visible = false;
|
StephaneLenclud@106
|
154 |
}
|
StephaneLenclud@106
|
155 |
|
StephaneLenclud@106
|
156 |
#if !DEBUG
|
StephaneLenclud@106
|
157 |
//When not debugging we want the screen to be empty until a client takes over
|
StephaneLenclud@106
|
158 |
ClearLayout();
|
StephaneLenclud@106
|
159 |
#else
|
StephaneLenclud@106
|
160 |
//When developing we want at least one client for testing
|
StephaneLenclud@106
|
161 |
StartNewClient("abcdefghijklmnopqrst-0123456789","ABCDEFGHIJKLMNOPQRST-0123456789");
|
StephaneLenclud@106
|
162 |
#endif
|
StephaneLenclud@106
|
163 |
|
StephaneLenclud@106
|
164 |
//Open display connection on start-up if needed
|
StephaneLenclud@106
|
165 |
if (Properties.Settings.Default.DisplayConnectOnStartup)
|
StephaneLenclud@106
|
166 |
{
|
StephaneLenclud@106
|
167 |
OpenDisplayConnection();
|
StephaneLenclud@106
|
168 |
}
|
StephaneLenclud@106
|
169 |
|
StephaneLenclud@106
|
170 |
//Start our server so that we can get client requests
|
StephaneLenclud@106
|
171 |
StartServer();
|
StephaneLenclud@106
|
172 |
}
|
StephaneLenclud@106
|
173 |
|
StephaneLenclud@106
|
174 |
/// <summary>
|
StephaneLenclud@104
|
175 |
/// Called when our display is opened.
|
StephaneLenclud@104
|
176 |
/// </summary>
|
StephaneLenclud@104
|
177 |
/// <param name="aDisplay"></param>
|
StephaneLenclud@104
|
178 |
private void OnDisplayOpened(Display aDisplay)
|
StephaneLenclud@104
|
179 |
{
|
StephaneLenclud@105
|
180 |
//Set our screen size now that our display is connected
|
StephaneLenclud@105
|
181 |
//Our panelDisplay is the container of our tableLayoutPanel
|
StephaneLenclud@105
|
182 |
//tableLayoutPanel will resize itself to fit the client size of our panelDisplay
|
StephaneLenclud@105
|
183 |
//panelDisplay needs an extra 2 pixels for borders on each sides
|
StephaneLenclud@105
|
184 |
//tableLayoutPanel will eventually be the exact size of our display
|
StephaneLenclud@105
|
185 |
Size size = new Size(iDisplay.WidthInPixels() + 2, iDisplay.HeightInPixels() + 2);
|
StephaneLenclud@105
|
186 |
panelDisplay.Size = size;
|
StephaneLenclud@105
|
187 |
|
StephaneLenclud@104
|
188 |
//Our display was just opened, update our UI
|
StephaneLenclud@104
|
189 |
UpdateStatus();
|
StephaneLenclud@104
|
190 |
//Initiate asynchronous request
|
StephaneLenclud@104
|
191 |
iDisplay.RequestFirmwareRevision();
|
StephaneLenclud@108
|
192 |
|
StephaneLenclud@117
|
193 |
//Audio
|
StephaneLenclud@112
|
194 |
UpdateMasterVolumeThreadSafe();
|
StephaneLenclud@117
|
195 |
//Network
|
StephaneLenclud@117
|
196 |
UpdateNetworkStatus();
|
StephaneLenclud@112
|
197 |
|
StephaneLenclud@108
|
198 |
#if DEBUG
|
StephaneLenclud@108
|
199 |
//Testing icon in debug, no arm done if icon not supported
|
StephaneLenclud@109
|
200 |
//iDisplay.SetIconStatus(Display.TMiniDisplayIconType.EMiniDisplayIconRecording, 0, 1);
|
StephaneLenclud@112
|
201 |
//iDisplay.SetAllIconsStatus(2);
|
StephaneLenclud@108
|
202 |
#endif
|
StephaneLenclud@108
|
203 |
|
StephaneLenclud@104
|
204 |
}
|
StephaneLenclud@104
|
205 |
|
StephaneLenclud@104
|
206 |
/// <summary>
|
StephaneLenclud@104
|
207 |
/// Called when our display is closed.
|
StephaneLenclud@104
|
208 |
/// </summary>
|
StephaneLenclud@104
|
209 |
/// <param name="aDisplay"></param>
|
StephaneLenclud@104
|
210 |
private void OnDisplayClosed(Display aDisplay)
|
StephaneLenclud@104
|
211 |
{
|
StephaneLenclud@104
|
212 |
//Our display was just closed, update our UI consequently
|
StephaneLenclud@104
|
213 |
UpdateStatus();
|
StephaneLenclud@104
|
214 |
}
|
StephaneLenclud@117
|
215 |
|
StephaneLenclud@117
|
216 |
public void OnConnectivityChanged(NetworkManager aNetwork, NLM_CONNECTIVITY newConnectivity)
|
StephaneLenclud@117
|
217 |
{
|
StephaneLenclud@117
|
218 |
//Update network status
|
StephaneLenclud@117
|
219 |
UpdateNetworkStatus();
|
StephaneLenclud@117
|
220 |
}
|
StephaneLenclud@117
|
221 |
|
StephaneLenclud@117
|
222 |
/// <summary>
|
StephaneLenclud@117
|
223 |
/// Update our Network Status
|
StephaneLenclud@117
|
224 |
/// </summary>
|
StephaneLenclud@117
|
225 |
private void UpdateNetworkStatus()
|
StephaneLenclud@117
|
226 |
{
|
StephaneLenclud@117
|
227 |
if (iDisplay.IsOpen())
|
StephaneLenclud@117
|
228 |
{
|
StephaneLenclud@117
|
229 |
iDisplay.SetIconOnOff(Display.TMiniDisplayIconType.EMiniDisplayIconNetwork, iNetworkManager.NetworkListManager.IsConnectedToInternet);
|
StephaneLenclud@117
|
230 |
}
|
StephaneLenclud@117
|
231 |
}
|
StephaneLenclud@117
|
232 |
|
StephaneLenclud@117
|
233 |
|
StephaneLenclud@112
|
234 |
/// <summary>
|
StephaneLenclud@112
|
235 |
/// Receive volume change notification and reflect changes on our slider.
|
StephaneLenclud@112
|
236 |
/// </summary>
|
StephaneLenclud@112
|
237 |
/// <param name="data"></param>
|
StephaneLenclud@112
|
238 |
public void OnVolumeNotificationThreadSafe(AudioVolumeNotificationData data)
|
StephaneLenclud@112
|
239 |
{
|
StephaneLenclud@112
|
240 |
UpdateMasterVolumeThreadSafe();
|
StephaneLenclud@112
|
241 |
}
|
StephaneLenclud@112
|
242 |
|
StephaneLenclud@112
|
243 |
/// <summary>
|
StephaneLenclud@112
|
244 |
/// Update master volume when user moves our slider.
|
StephaneLenclud@112
|
245 |
/// </summary>
|
StephaneLenclud@112
|
246 |
/// <param name="sender"></param>
|
StephaneLenclud@112
|
247 |
/// <param name="e"></param>
|
StephaneLenclud@112
|
248 |
private void trackBarMasterVolume_Scroll(object sender, EventArgs e)
|
StephaneLenclud@112
|
249 |
{
|
StephaneLenclud@116
|
250 |
//Just like Windows Volume Mixer we unmute if the volume is adjusted
|
StephaneLenclud@116
|
251 |
iMultiMediaDevice.AudioEndpointVolume.Mute = false;
|
StephaneLenclud@116
|
252 |
//Set volume level according to our volume slider new position
|
StephaneLenclud@112
|
253 |
iMultiMediaDevice.AudioEndpointVolume.MasterVolumeLevelScalar = trackBarMasterVolume.Value / 100.0f;
|
StephaneLenclud@112
|
254 |
}
|
StephaneLenclud@112
|
255 |
|
StephaneLenclud@113
|
256 |
|
StephaneLenclud@113
|
257 |
/// <summary>
|
StephaneLenclud@113
|
258 |
/// Mute check box changed.
|
StephaneLenclud@113
|
259 |
/// </summary>
|
StephaneLenclud@113
|
260 |
/// <param name="sender"></param>
|
StephaneLenclud@113
|
261 |
/// <param name="e"></param>
|
StephaneLenclud@113
|
262 |
private void checkBoxMute_CheckedChanged(object sender, EventArgs e)
|
StephaneLenclud@113
|
263 |
{
|
StephaneLenclud@113
|
264 |
iMultiMediaDevice.AudioEndpointVolume.Mute = checkBoxMute.Checked;
|
StephaneLenclud@113
|
265 |
}
|
StephaneLenclud@113
|
266 |
|
StephaneLenclud@112
|
267 |
/// <summary>
|
StephaneLenclud@112
|
268 |
/// Device State Changed
|
StephaneLenclud@112
|
269 |
/// </summary>
|
StephaneLenclud@112
|
270 |
public void OnDeviceStateChanged([MarshalAs(UnmanagedType.LPWStr)] string deviceId, [MarshalAs(UnmanagedType.I4)] DeviceState newState){}
|
StephaneLenclud@112
|
271 |
|
StephaneLenclud@112
|
272 |
/// <summary>
|
StephaneLenclud@112
|
273 |
/// Device Added
|
StephaneLenclud@112
|
274 |
/// </summary>
|
StephaneLenclud@112
|
275 |
public void OnDeviceAdded([MarshalAs(UnmanagedType.LPWStr)] string pwstrDeviceId) { }
|
StephaneLenclud@112
|
276 |
|
StephaneLenclud@112
|
277 |
/// <summary>
|
StephaneLenclud@112
|
278 |
/// Device Removed
|
StephaneLenclud@112
|
279 |
/// </summary>
|
StephaneLenclud@112
|
280 |
public void OnDeviceRemoved([MarshalAs(UnmanagedType.LPWStr)] string deviceId) { }
|
StephaneLenclud@112
|
281 |
|
StephaneLenclud@112
|
282 |
/// <summary>
|
StephaneLenclud@112
|
283 |
/// Default Device Changed
|
StephaneLenclud@112
|
284 |
/// </summary>
|
StephaneLenclud@112
|
285 |
public void OnDefaultDeviceChanged(DataFlow flow, Role role, [MarshalAs(UnmanagedType.LPWStr)] string defaultDeviceId)
|
StephaneLenclud@112
|
286 |
{
|
StephaneLenclud@112
|
287 |
if (role == Role.Multimedia && flow == DataFlow.Render)
|
StephaneLenclud@112
|
288 |
{
|
StephaneLenclud@112
|
289 |
UpdateAudioDeviceAndMasterVolumeThreadSafe();
|
StephaneLenclud@112
|
290 |
}
|
StephaneLenclud@112
|
291 |
}
|
StephaneLenclud@112
|
292 |
|
StephaneLenclud@112
|
293 |
/// <summary>
|
StephaneLenclud@112
|
294 |
/// Property Value Changed
|
StephaneLenclud@112
|
295 |
/// </summary>
|
StephaneLenclud@112
|
296 |
/// <param name="pwstrDeviceId"></param>
|
StephaneLenclud@112
|
297 |
/// <param name="key"></param>
|
StephaneLenclud@112
|
298 |
public void OnPropertyValueChanged([MarshalAs(UnmanagedType.LPWStr)] string pwstrDeviceId, PropertyKey key){}
|
StephaneLenclud@112
|
299 |
|
StephaneLenclud@112
|
300 |
|
StephaneLenclud@112
|
301 |
|
StephaneLenclud@112
|
302 |
|
StephaneLenclud@112
|
303 |
/// <summary>
|
StephaneLenclud@116
|
304 |
/// Update master volume indicators based our current system states.
|
StephaneLenclud@116
|
305 |
/// This typically includes volume levels and mute status.
|
StephaneLenclud@112
|
306 |
/// </summary>
|
StephaneLenclud@112
|
307 |
private void UpdateMasterVolumeThreadSafe()
|
StephaneLenclud@112
|
308 |
{
|
StephaneLenclud@112
|
309 |
if (this.InvokeRequired)
|
StephaneLenclud@112
|
310 |
{
|
StephaneLenclud@112
|
311 |
//Not in the proper thread, invoke ourselves
|
StephaneLenclud@112
|
312 |
PlainUpdateDelegate d = new PlainUpdateDelegate(UpdateMasterVolumeThreadSafe);
|
StephaneLenclud@112
|
313 |
this.Invoke(d, new object[] { });
|
StephaneLenclud@112
|
314 |
return;
|
StephaneLenclud@112
|
315 |
}
|
StephaneLenclud@112
|
316 |
|
StephaneLenclud@113
|
317 |
//Update volume slider
|
StephaneLenclud@112
|
318 |
float volumeLevelScalar = iMultiMediaDevice.AudioEndpointVolume.MasterVolumeLevelScalar;
|
StephaneLenclud@112
|
319 |
trackBarMasterVolume.Value = Convert.ToInt32(volumeLevelScalar * 100);
|
StephaneLenclud@113
|
320 |
//Update mute checkbox
|
StephaneLenclud@113
|
321 |
checkBoxMute.Checked = iMultiMediaDevice.AudioEndpointVolume.Mute;
|
StephaneLenclud@112
|
322 |
|
StephaneLenclud@116
|
323 |
//If our display connection is open we need to update its icons
|
StephaneLenclud@112
|
324 |
if (iDisplay.IsOpen())
|
StephaneLenclud@112
|
325 |
{
|
StephaneLenclud@116
|
326 |
//First take care our our volume level icons
|
StephaneLenclud@112
|
327 |
int volumeIconCount = iDisplay.IconCount(Display.TMiniDisplayIconType.EMiniDisplayIconVolume);
|
StephaneLenclud@112
|
328 |
if (volumeIconCount > 0)
|
StephaneLenclud@114
|
329 |
{
|
StephaneLenclud@116
|
330 |
//Compute current volume level from system level and the number of segments in our display volume bar.
|
StephaneLenclud@116
|
331 |
//That tells us how many segments in our volume bar needs to be turned on.
|
StephaneLenclud@116
|
332 |
float currentVolume = volumeLevelScalar * volumeIconCount;
|
StephaneLenclud@116
|
333 |
int segmentOnCount = Convert.ToInt32(currentVolume);
|
StephaneLenclud@116
|
334 |
//Check if our segment count was rounded up, this will later be used for half brightness segment
|
StephaneLenclud@116
|
335 |
bool roundedUp = segmentOnCount > currentVolume;
|
StephaneLenclud@114
|
336 |
|
StephaneLenclud@112
|
337 |
for (int i = 0; i < volumeIconCount; i++)
|
StephaneLenclud@112
|
338 |
{
|
StephaneLenclud@116
|
339 |
if (i < segmentOnCount)
|
StephaneLenclud@112
|
340 |
{
|
StephaneLenclud@116
|
341 |
//If we are dealing with our last segment and our segment count was rounded up then we will use half brightness.
|
StephaneLenclud@116
|
342 |
if (i == segmentOnCount - 1 && roundedUp)
|
StephaneLenclud@114
|
343 |
{
|
StephaneLenclud@114
|
344 |
//Half brightness
|
StephaneLenclud@114
|
345 |
iDisplay.SetIconStatus(Display.TMiniDisplayIconType.EMiniDisplayIconVolume, i, (iDisplay.IconStatusCount(Display.TMiniDisplayIconType.EMiniDisplayIconVolume) - 1)/2);
|
StephaneLenclud@114
|
346 |
}
|
StephaneLenclud@114
|
347 |
else
|
StephaneLenclud@114
|
348 |
{
|
StephaneLenclud@114
|
349 |
//Full brightness
|
StephaneLenclud@114
|
350 |
iDisplay.SetIconStatus(Display.TMiniDisplayIconType.EMiniDisplayIconVolume, i, iDisplay.IconStatusCount(Display.TMiniDisplayIconType.EMiniDisplayIconVolume) - 1);
|
StephaneLenclud@114
|
351 |
}
|
StephaneLenclud@112
|
352 |
}
|
StephaneLenclud@112
|
353 |
else
|
StephaneLenclud@112
|
354 |
{
|
StephaneLenclud@112
|
355 |
iDisplay.SetIconStatus(Display.TMiniDisplayIconType.EMiniDisplayIconVolume, i, 0);
|
StephaneLenclud@112
|
356 |
}
|
StephaneLenclud@112
|
357 |
}
|
StephaneLenclud@112
|
358 |
}
|
StephaneLenclud@113
|
359 |
|
StephaneLenclud@116
|
360 |
//Take care our our mute icon
|
StephaneLenclud@116
|
361 |
iDisplay.SetIconOnOff(Display.TMiniDisplayIconType.EMiniDisplayIconMute, iMultiMediaDevice.AudioEndpointVolume.Mute);
|
StephaneLenclud@112
|
362 |
}
|
StephaneLenclud@112
|
363 |
|
StephaneLenclud@112
|
364 |
}
|
StephaneLenclud@112
|
365 |
|
StephaneLenclud@112
|
366 |
/// <summary>
|
StephaneLenclud@112
|
367 |
///
|
StephaneLenclud@112
|
368 |
/// </summary>
|
StephaneLenclud@112
|
369 |
private void UpdateAudioDeviceAndMasterVolumeThreadSafe()
|
StephaneLenclud@112
|
370 |
{
|
StephaneLenclud@112
|
371 |
if (this.InvokeRequired)
|
StephaneLenclud@112
|
372 |
{
|
StephaneLenclud@112
|
373 |
//Not in the proper thread, invoke ourselves
|
StephaneLenclud@112
|
374 |
PlainUpdateDelegate d = new PlainUpdateDelegate(UpdateAudioDeviceAndMasterVolumeThreadSafe);
|
StephaneLenclud@112
|
375 |
this.Invoke(d, new object[] { });
|
StephaneLenclud@112
|
376 |
return;
|
StephaneLenclud@112
|
377 |
}
|
StephaneLenclud@112
|
378 |
|
StephaneLenclud@112
|
379 |
//We are in the correct thread just go ahead.
|
StephaneLenclud@112
|
380 |
try
|
StephaneLenclud@112
|
381 |
{
|
StephaneLenclud@112
|
382 |
//Get our master volume
|
StephaneLenclud@112
|
383 |
iMultiMediaDevice = iMultiMediaDeviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
|
StephaneLenclud@116
|
384 |
//Update our label
|
StephaneLenclud@116
|
385 |
labelDefaultAudioDevice.Text = iMultiMediaDevice.FriendlyName;
|
StephaneLenclud@116
|
386 |
|
StephaneLenclud@112
|
387 |
//Show our volume in our track bar
|
StephaneLenclud@112
|
388 |
UpdateMasterVolumeThreadSafe();
|
StephaneLenclud@112
|
389 |
|
StephaneLenclud@112
|
390 |
//Register to get volume modifications
|
StephaneLenclud@112
|
391 |
iMultiMediaDevice.AudioEndpointVolume.OnVolumeNotification += OnVolumeNotificationThreadSafe;
|
StephaneLenclud@112
|
392 |
//
|
StephaneLenclud@112
|
393 |
trackBarMasterVolume.Enabled = true;
|
StephaneLenclud@112
|
394 |
}
|
StephaneLenclud@112
|
395 |
catch (Exception ex)
|
StephaneLenclud@112
|
396 |
{
|
StephaneLenclud@112
|
397 |
Debug.WriteLine("Exception thrown in UpdateAudioDeviceAndMasterVolume");
|
StephaneLenclud@112
|
398 |
Debug.WriteLine(ex.ToString());
|
StephaneLenclud@112
|
399 |
//Something went wrong S/PDIF device ca throw exception I guess
|
StephaneLenclud@112
|
400 |
trackBarMasterVolume.Enabled = false;
|
StephaneLenclud@112
|
401 |
}
|
StephaneLenclud@112
|
402 |
}
|
StephaneLenclud@104
|
403 |
|
StephaneLenclud@104
|
404 |
/// <summary>
|
StephaneLenclud@104
|
405 |
///
|
StephaneLenclud@104
|
406 |
/// </summary>
|
StephaneLenclud@104
|
407 |
private void PopulateDeviceTypes()
|
StephaneLenclud@104
|
408 |
{
|
StephaneLenclud@104
|
409 |
int count = Display.TypeCount();
|
StephaneLenclud@104
|
410 |
|
StephaneLenclud@106
|
411 |
for (int i = 0; i < count; i++)
|
StephaneLenclud@104
|
412 |
{
|
StephaneLenclud@104
|
413 |
comboBoxDisplayType.Items.Add(Display.TypeName((Display.TMiniDisplayType)i));
|
StephaneLenclud@106
|
414 |
}
|
StephaneLenclud@104
|
415 |
}
|
StephaneLenclud@104
|
416 |
|
StephaneLenclud@104
|
417 |
/// <summary>
|
sl@99
|
418 |
///
|
sl@94
|
419 |
/// </summary>
|
sl@95
|
420 |
private void SetupTrayIcon()
|
sl@95
|
421 |
{
|
sl@95
|
422 |
iNotifyIcon.Icon = GetIcon("vfd.ico");
|
sl@95
|
423 |
iNotifyIcon.Text = "Sharp Display Manager";
|
sl@95
|
424 |
iNotifyIcon.Visible = true;
|
sl@95
|
425 |
|
sl@95
|
426 |
//Double click toggles visibility - typically brings up the application
|
sl@95
|
427 |
iNotifyIcon.DoubleClick += delegate(object obj, EventArgs args)
|
sl@95
|
428 |
{
|
sl@95
|
429 |
SysTrayHideShow();
|
sl@95
|
430 |
};
|
sl@95
|
431 |
|
sl@95
|
432 |
//Adding a context menu, useful to be able to exit the application
|
sl@95
|
433 |
ContextMenu contextMenu = new ContextMenu();
|
sl@95
|
434 |
//Context menu item to toggle visibility
|
sl@95
|
435 |
MenuItem hideShowItem = new MenuItem("Hide/Show");
|
sl@95
|
436 |
hideShowItem.Click += delegate(object obj, EventArgs args)
|
sl@95
|
437 |
{
|
sl@95
|
438 |
SysTrayHideShow();
|
sl@95
|
439 |
};
|
sl@95
|
440 |
contextMenu.MenuItems.Add(hideShowItem);
|
sl@95
|
441 |
|
sl@95
|
442 |
//Context menu item separator
|
sl@95
|
443 |
contextMenu.MenuItems.Add(new MenuItem("-"));
|
sl@95
|
444 |
|
sl@95
|
445 |
//Context menu exit item
|
sl@95
|
446 |
MenuItem exitItem = new MenuItem("Exit");
|
sl@95
|
447 |
exitItem.Click += delegate(object obj, EventArgs args)
|
sl@95
|
448 |
{
|
sl@95
|
449 |
Application.Exit();
|
sl@95
|
450 |
};
|
sl@95
|
451 |
contextMenu.MenuItems.Add(exitItem);
|
sl@95
|
452 |
|
sl@95
|
453 |
iNotifyIcon.ContextMenu = contextMenu;
|
sl@95
|
454 |
}
|
sl@95
|
455 |
|
sl@95
|
456 |
/// <summary>
|
sl@94
|
457 |
/// Access icons from embedded resources.
|
sl@94
|
458 |
/// </summary>
|
sl@94
|
459 |
/// <param name="name"></param>
|
sl@94
|
460 |
/// <returns></returns>
|
sl@94
|
461 |
public static Icon GetIcon(string name)
|
sl@94
|
462 |
{
|
sl@94
|
463 |
name = "SharpDisplayManager.Resources." + name;
|
sl@94
|
464 |
|
sl@94
|
465 |
string[] names =
|
sl@94
|
466 |
Assembly.GetExecutingAssembly().GetManifestResourceNames();
|
sl@94
|
467 |
for (int i = 0; i < names.Length; i++)
|
sl@94
|
468 |
{
|
sl@94
|
469 |
if (names[i].Replace('\\', '.') == name)
|
sl@94
|
470 |
{
|
sl@94
|
471 |
using (Stream stream = Assembly.GetExecutingAssembly().
|
sl@94
|
472 |
GetManifestResourceStream(names[i]))
|
sl@94
|
473 |
{
|
sl@94
|
474 |
return new Icon(stream);
|
sl@94
|
475 |
}
|
sl@94
|
476 |
}
|
sl@94
|
477 |
}
|
sl@94
|
478 |
|
sl@94
|
479 |
return null;
|
sl@94
|
480 |
}
|
sl@94
|
481 |
|
sl@94
|
482 |
|
sl@65
|
483 |
/// <summary>
|
sl@65
|
484 |
/// Set our current client.
|
sl@65
|
485 |
/// This will take care of applying our client layout and set data fields.
|
sl@65
|
486 |
/// </summary>
|
sl@65
|
487 |
/// <param name="aSessionId"></param>
|
sl@65
|
488 |
void SetCurrentClient(string aSessionId)
|
sl@57
|
489 |
{
|
sl@65
|
490 |
if (aSessionId == iCurrentClientSessionId)
|
sl@57
|
491 |
{
|
sl@65
|
492 |
//Given client is already the current one.
|
sl@65
|
493 |
//Don't bother changing anything then.
|
sl@65
|
494 |
return;
|
sl@65
|
495 |
}
|
sl@57
|
496 |
|
sl@65
|
497 |
//Set current client ID.
|
sl@65
|
498 |
iCurrentClientSessionId = aSessionId;
|
sl@65
|
499 |
//Fetch and set current client data.
|
sl@65
|
500 |
iCurrentClientData = iClients[aSessionId];
|
sl@65
|
501 |
//Apply layout and set data fields.
|
sl@65
|
502 |
UpdateTableLayoutPanel(iCurrentClientData);
|
sl@57
|
503 |
}
|
sl@57
|
504 |
|
sl@0
|
505 |
private void buttonFont_Click(object sender, EventArgs e)
|
sl@0
|
506 |
{
|
sl@0
|
507 |
//fontDialog.ShowColor = true;
|
sl@0
|
508 |
//fontDialog.ShowApply = true;
|
sl@0
|
509 |
fontDialog.ShowEffects = true;
|
sl@99
|
510 |
fontDialog.Font = cds.Font;
|
sl@28
|
511 |
|
sl@28
|
512 |
fontDialog.FixedPitchOnly = checkBoxFixedPitchFontOnly.Checked;
|
sl@28
|
513 |
|
sl@0
|
514 |
//fontDialog.ShowHelp = true;
|
sl@0
|
515 |
|
sl@0
|
516 |
//fontDlg.MaxSize = 40;
|
sl@0
|
517 |
//fontDlg.MinSize = 22;
|
sl@0
|
518 |
|
sl@0
|
519 |
//fontDialog.Parent = this;
|
sl@0
|
520 |
//fontDialog.StartPosition = FormStartPosition.CenterParent;
|
sl@0
|
521 |
|
sl@0
|
522 |
//DlgBox.ShowDialog(fontDialog);
|
sl@0
|
523 |
|
sl@0
|
524 |
//if (fontDialog.ShowDialog(this) != DialogResult.Cancel)
|
sl@0
|
525 |
if (DlgBox.ShowDialog(fontDialog) != DialogResult.Cancel)
|
sl@0
|
526 |
{
|
sl@99
|
527 |
//Set the fonts to all our labels in our layout
|
sl@99
|
528 |
foreach (Control ctrl in tableLayoutPanel.Controls)
|
sl@99
|
529 |
{
|
sl@99
|
530 |
if (ctrl is MarqueeLabel)
|
sl@99
|
531 |
{
|
sl@99
|
532 |
((MarqueeLabel)ctrl).Font = fontDialog.Font;
|
sl@99
|
533 |
}
|
sl@99
|
534 |
}
|
sl@0
|
535 |
|
sl@99
|
536 |
//Save font settings
|
sl@48
|
537 |
cds.Font = fontDialog.Font;
|
sl@8
|
538 |
Properties.Settings.Default.Save();
|
sl@36
|
539 |
//
|
sl@37
|
540 |
CheckFontHeight();
|
sl@37
|
541 |
}
|
sl@37
|
542 |
}
|
sl@36
|
543 |
|
sl@37
|
544 |
/// <summary>
|
sl@38
|
545 |
///
|
sl@37
|
546 |
/// </summary>
|
sl@37
|
547 |
void CheckFontHeight()
|
sl@37
|
548 |
{
|
sl@54
|
549 |
//Show font height and width
|
sl@54
|
550 |
labelFontHeight.Text = "Font height: " + cds.Font.Height;
|
sl@54
|
551 |
float charWidth = IsFixedWidth(cds.Font);
|
sl@54
|
552 |
if (charWidth == 0.0f)
|
sl@54
|
553 |
{
|
sl@54
|
554 |
labelFontWidth.Visible = false;
|
sl@54
|
555 |
}
|
sl@54
|
556 |
else
|
sl@54
|
557 |
{
|
sl@54
|
558 |
labelFontWidth.Visible = true;
|
sl@54
|
559 |
labelFontWidth.Text = "Font width: " + charWidth;
|
sl@54
|
560 |
}
|
sl@54
|
561 |
|
sl@70
|
562 |
MarqueeLabel label = null;
|
sl@68
|
563 |
//Get the first label control we can find
|
sl@68
|
564 |
foreach (Control ctrl in tableLayoutPanel.Controls)
|
sl@68
|
565 |
{
|
sl@68
|
566 |
if (ctrl is MarqueeLabel)
|
sl@68
|
567 |
{
|
sl@68
|
568 |
label = (MarqueeLabel)ctrl;
|
sl@68
|
569 |
break;
|
sl@68
|
570 |
}
|
sl@68
|
571 |
}
|
sl@68
|
572 |
|
sl@54
|
573 |
//Now check font height and show a warning if needed.
|
sl@68
|
574 |
if (label != null && label.Font.Height > label.Height)
|
sl@37
|
575 |
{
|
sl@60
|
576 |
labelWarning.Text = "WARNING: Selected font is too height by " + (label.Font.Height - label.Height) + " pixels!";
|
sl@37
|
577 |
labelWarning.Visible = true;
|
sl@0
|
578 |
}
|
sl@37
|
579 |
else
|
sl@37
|
580 |
{
|
sl@37
|
581 |
labelWarning.Visible = false;
|
sl@37
|
582 |
}
|
sl@37
|
583 |
|
sl@0
|
584 |
}
|
sl@0
|
585 |
|
sl@0
|
586 |
private void buttonCapture_Click(object sender, EventArgs e)
|
sl@0
|
587 |
{
|
sl@0
|
588 |
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height);
|
sl@0
|
589 |
tableLayoutPanel.DrawToBitmap(bmp, tableLayoutPanel.ClientRectangle);
|
sl@14
|
590 |
//Bitmap bmpToSave = new Bitmap(bmp);
|
sl@14
|
591 |
bmp.Save("D:\\capture.png");
|
sl@14
|
592 |
|
sl@60
|
593 |
((MarqueeLabel)tableLayoutPanel.Controls[0]).Text = "Captured";
|
sl@17
|
594 |
|
sl@14
|
595 |
/*
|
sl@14
|
596 |
string outputFileName = "d:\\capture.png";
|
sl@14
|
597 |
using (MemoryStream memory = new MemoryStream())
|
sl@14
|
598 |
{
|
sl@14
|
599 |
using (FileStream fs = new FileStream(outputFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite))
|
sl@14
|
600 |
{
|
sl@14
|
601 |
bmp.Save(memory, System.Drawing.Imaging.ImageFormat.Png);
|
sl@14
|
602 |
byte[] bytes = memory.ToArray();
|
sl@14
|
603 |
fs.Write(bytes, 0, bytes.Length);
|
sl@14
|
604 |
}
|
sl@14
|
605 |
}
|
sl@14
|
606 |
*/
|
sl@14
|
607 |
|
sl@0
|
608 |
}
|
sl@2
|
609 |
|
sl@12
|
610 |
private void CheckForRequestResults()
|
sl@12
|
611 |
{
|
sl@12
|
612 |
if (iDisplay.IsRequestPending())
|
sl@12
|
613 |
{
|
sl@12
|
614 |
switch (iDisplay.AttemptRequestCompletion())
|
sl@12
|
615 |
{
|
sl@51
|
616 |
case Display.TMiniDisplayRequest.EMiniDisplayRequestFirmwareRevision:
|
sl@51
|
617 |
toolStripStatusLabelConnect.Text += " v" + iDisplay.FirmwareRevision();
|
sl@51
|
618 |
//Issue next request then
|
sl@51
|
619 |
iDisplay.RequestPowerSupplyStatus();
|
sl@51
|
620 |
break;
|
sl@51
|
621 |
|
sl@12
|
622 |
case Display.TMiniDisplayRequest.EMiniDisplayRequestPowerSupplyStatus:
|
sl@12
|
623 |
if (iDisplay.PowerSupplyStatus())
|
sl@12
|
624 |
{
|
sl@12
|
625 |
toolStripStatusLabelPower.Text = "ON";
|
sl@12
|
626 |
}
|
sl@12
|
627 |
else
|
sl@12
|
628 |
{
|
sl@12
|
629 |
toolStripStatusLabelPower.Text = "OFF";
|
sl@12
|
630 |
}
|
sl@12
|
631 |
//Issue next request then
|
sl@12
|
632 |
iDisplay.RequestDeviceId();
|
sl@12
|
633 |
break;
|
sl@12
|
634 |
|
sl@12
|
635 |
case Display.TMiniDisplayRequest.EMiniDisplayRequestDeviceId:
|
sl@12
|
636 |
toolStripStatusLabelConnect.Text += " - " + iDisplay.DeviceId();
|
sl@12
|
637 |
//No more request to issue
|
sl@12
|
638 |
break;
|
sl@12
|
639 |
}
|
sl@12
|
640 |
}
|
sl@12
|
641 |
}
|
sl@12
|
642 |
|
sl@58
|
643 |
public static uint ColorWhiteIsOn(int aX, int aY, uint aPixel)
|
sl@58
|
644 |
{
|
sl@58
|
645 |
if ((aPixel & 0x00FFFFFF) == 0x00FFFFFF)
|
sl@58
|
646 |
{
|
sl@58
|
647 |
return 0xFFFFFFFF;
|
sl@58
|
648 |
}
|
sl@58
|
649 |
return 0x00000000;
|
sl@58
|
650 |
}
|
sl@16
|
651 |
|
sl@58
|
652 |
public static uint ColorUntouched(int aX, int aY, uint aPixel)
|
sl@57
|
653 |
{
|
sl@57
|
654 |
return aPixel;
|
sl@57
|
655 |
}
|
sl@57
|
656 |
|
sl@58
|
657 |
public static uint ColorInversed(int aX, int aY, uint aPixel)
|
sl@57
|
658 |
{
|
sl@57
|
659 |
return ~aPixel;
|
sl@57
|
660 |
}
|
sl@57
|
661 |
|
sl@58
|
662 |
public static uint ColorChessboard(int aX, int aY, uint aPixel)
|
sl@58
|
663 |
{
|
sl@58
|
664 |
if ((aX % 2 == 0) && (aY % 2 == 0))
|
sl@58
|
665 |
{
|
sl@58
|
666 |
return ~aPixel;
|
sl@58
|
667 |
}
|
sl@58
|
668 |
else if ((aX % 2 != 0) && (aY % 2 != 0))
|
sl@58
|
669 |
{
|
sl@58
|
670 |
return ~aPixel;
|
sl@58
|
671 |
}
|
sl@58
|
672 |
return 0x00000000;
|
sl@58
|
673 |
}
|
sl@58
|
674 |
|
sl@16
|
675 |
|
sl@16
|
676 |
public static int ScreenReversedX(System.Drawing.Bitmap aBmp, int aX)
|
sl@16
|
677 |
{
|
sl@16
|
678 |
return aBmp.Width - aX - 1;
|
sl@16
|
679 |
}
|
sl@16
|
680 |
|
sl@16
|
681 |
public int ScreenReversedY(System.Drawing.Bitmap aBmp, int aY)
|
sl@16
|
682 |
{
|
sl@16
|
683 |
return iBmp.Height - aY - 1;
|
sl@16
|
684 |
}
|
sl@16
|
685 |
|
sl@16
|
686 |
public int ScreenX(System.Drawing.Bitmap aBmp, int aX)
|
sl@16
|
687 |
{
|
sl@16
|
688 |
return aX;
|
sl@16
|
689 |
}
|
sl@16
|
690 |
|
sl@16
|
691 |
public int ScreenY(System.Drawing.Bitmap aBmp, int aY)
|
sl@16
|
692 |
{
|
sl@16
|
693 |
return aY;
|
sl@16
|
694 |
}
|
sl@16
|
695 |
|
sl@58
|
696 |
/// <summary>
|
sl@58
|
697 |
/// Select proper pixel delegates according to our current settings.
|
sl@58
|
698 |
/// </summary>
|
sl@58
|
699 |
private void SetupPixelDelegates()
|
sl@58
|
700 |
{
|
sl@59
|
701 |
//Select our pixel processing routine
|
sl@58
|
702 |
if (cds.InverseColors)
|
sl@58
|
703 |
{
|
sl@58
|
704 |
//iColorFx = ColorChessboard;
|
sl@58
|
705 |
iColorFx = ColorInversed;
|
sl@58
|
706 |
}
|
sl@58
|
707 |
else
|
sl@58
|
708 |
{
|
sl@58
|
709 |
iColorFx = ColorWhiteIsOn;
|
sl@58
|
710 |
}
|
sl@58
|
711 |
|
sl@58
|
712 |
//Select proper coordinate translation functions
|
sl@58
|
713 |
//We used delegate/function pointer to support reverse screen without doing an extra test on each pixels
|
sl@58
|
714 |
if (cds.ReverseScreen)
|
sl@58
|
715 |
{
|
sl@58
|
716 |
iScreenX = ScreenReversedX;
|
sl@58
|
717 |
iScreenY = ScreenReversedY;
|
sl@58
|
718 |
}
|
sl@58
|
719 |
else
|
sl@58
|
720 |
{
|
sl@58
|
721 |
iScreenX = ScreenX;
|
sl@58
|
722 |
iScreenY = ScreenY;
|
sl@58
|
723 |
}
|
sl@58
|
724 |
|
sl@58
|
725 |
}
|
sl@16
|
726 |
|
sl@16
|
727 |
//This is our timer tick responsible to perform our render
|
sl@2
|
728 |
private void timer_Tick(object sender, EventArgs e)
|
sl@14
|
729 |
{
|
sl@2
|
730 |
//Update our animations
|
sl@2
|
731 |
DateTime NewTickTime = DateTime.Now;
|
sl@2
|
732 |
|
sl@60
|
733 |
//Update animation for all our marquees
|
sl@68
|
734 |
foreach (Control ctrl in tableLayoutPanel.Controls)
|
sl@60
|
735 |
{
|
sl@68
|
736 |
if (ctrl is MarqueeLabel)
|
sl@68
|
737 |
{
|
sl@68
|
738 |
((MarqueeLabel)ctrl).UpdateAnimation(LastTickTime, NewTickTime);
|
sl@68
|
739 |
}
|
sl@60
|
740 |
}
|
sl@60
|
741 |
|
sl@2
|
742 |
|
sl@4
|
743 |
//Update our display
|
sl@4
|
744 |
if (iDisplay.IsOpen())
|
sl@4
|
745 |
{
|
sl@12
|
746 |
CheckForRequestResults();
|
sl@12
|
747 |
|
sl@22
|
748 |
//Draw to bitmap
|
sl@14
|
749 |
if (iCreateBitmap)
|
sl@14
|
750 |
{
|
sl@14
|
751 |
iBmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height, PixelFormat.Format32bppArgb);
|
sl@14
|
752 |
}
|
sl@14
|
753 |
tableLayoutPanel.DrawToBitmap(iBmp, tableLayoutPanel.ClientRectangle);
|
sl@14
|
754 |
//iBmp.Save("D:\\capture.png");
|
sl@16
|
755 |
|
sl@7
|
756 |
//Send it to our display
|
sl@14
|
757 |
for (int i = 0; i < iBmp.Width; i++)
|
sl@4
|
758 |
{
|
sl@14
|
759 |
for (int j = 0; j < iBmp.Height; j++)
|
sl@4
|
760 |
{
|
sl@4
|
761 |
unchecked
|
sl@4
|
762 |
{
|
sl@58
|
763 |
//Get our processed pixel coordinates
|
sl@58
|
764 |
int x = iScreenX(iBmp, i);
|
sl@58
|
765 |
int y = iScreenY(iBmp, j);
|
sl@58
|
766 |
//Get pixel color
|
sl@14
|
767 |
uint color = (uint)iBmp.GetPixel(i, j).ToArgb();
|
sl@57
|
768 |
//Apply color effects
|
sl@58
|
769 |
color = iColorFx(x,y,color);
|
sl@58
|
770 |
//Now set our pixel
|
sl@58
|
771 |
iDisplay.SetPixel(x, y, color);
|
sl@4
|
772 |
}
|
sl@4
|
773 |
}
|
sl@4
|
774 |
}
|
sl@4
|
775 |
|
sl@4
|
776 |
iDisplay.SwapBuffers();
|
sl@4
|
777 |
|
sl@4
|
778 |
}
|
sl@8
|
779 |
|
sl@8
|
780 |
//Compute instant FPS
|
sl@47
|
781 |
toolStripStatusLabelFps.Text = (1.0/NewTickTime.Subtract(LastTickTime).TotalSeconds).ToString("F0") + " / " + (1000/timer.Interval).ToString() + " FPS";
|
sl@8
|
782 |
|
sl@8
|
783 |
LastTickTime = NewTickTime;
|
sl@8
|
784 |
|
sl@2
|
785 |
}
|
sl@3
|
786 |
|
StephaneLenclud@103
|
787 |
/// <summary>
|
StephaneLenclud@103
|
788 |
/// Attempt to establish connection with our display hardware.
|
StephaneLenclud@103
|
789 |
/// </summary>
|
sl@46
|
790 |
private void OpenDisplayConnection()
|
sl@3
|
791 |
{
|
sl@46
|
792 |
CloseDisplayConnection();
|
sl@46
|
793 |
|
StephaneLenclud@104
|
794 |
if (!iDisplay.Open((Display.TMiniDisplayType)cds.DisplayType))
|
StephaneLenclud@104
|
795 |
{
|
StephaneLenclud@104
|
796 |
UpdateStatus();
|
StephaneLenclud@104
|
797 |
toolStripStatusLabelConnect.Text = "Connection error";
|
sl@7
|
798 |
}
|
sl@46
|
799 |
}
|
sl@7
|
800 |
|
sl@46
|
801 |
private void CloseDisplayConnection()
|
sl@46
|
802 |
{
|
StephaneLenclud@104
|
803 |
//Status will be updated upon receiving the closed event
|
sl@46
|
804 |
iDisplay.Close();
|
sl@46
|
805 |
}
|
sl@46
|
806 |
|
sl@46
|
807 |
private void buttonOpen_Click(object sender, EventArgs e)
|
sl@46
|
808 |
{
|
sl@46
|
809 |
OpenDisplayConnection();
|
sl@3
|
810 |
}
|
sl@3
|
811 |
|
sl@3
|
812 |
private void buttonClose_Click(object sender, EventArgs e)
|
sl@3
|
813 |
{
|
sl@46
|
814 |
CloseDisplayConnection();
|
sl@3
|
815 |
}
|
sl@3
|
816 |
|
sl@3
|
817 |
private void buttonClear_Click(object sender, EventArgs e)
|
sl@3
|
818 |
{
|
sl@3
|
819 |
iDisplay.Clear();
|
sl@3
|
820 |
iDisplay.SwapBuffers();
|
sl@3
|
821 |
}
|
sl@3
|
822 |
|
sl@3
|
823 |
private void buttonFill_Click(object sender, EventArgs e)
|
sl@3
|
824 |
{
|
sl@3
|
825 |
iDisplay.Fill();
|
sl@3
|
826 |
iDisplay.SwapBuffers();
|
sl@3
|
827 |
}
|
sl@3
|
828 |
|
sl@3
|
829 |
private void trackBarBrightness_Scroll(object sender, EventArgs e)
|
sl@3
|
830 |
{
|
sl@48
|
831 |
cds.Brightness = trackBarBrightness.Value;
|
sl@9
|
832 |
Properties.Settings.Default.Save();
|
sl@3
|
833 |
iDisplay.SetBrightness(trackBarBrightness.Value);
|
sl@9
|
834 |
|
sl@3
|
835 |
}
|
sl@7
|
836 |
|
sl@48
|
837 |
|
sl@48
|
838 |
/// <summary>
|
sl@48
|
839 |
/// CDS stands for Current Display Settings
|
sl@48
|
840 |
/// </summary>
|
sl@50
|
841 |
private DisplaySettings cds
|
sl@48
|
842 |
{
|
sl@48
|
843 |
get
|
sl@48
|
844 |
{
|
sl@65
|
845 |
DisplaysSettings settings = Properties.Settings.Default.DisplaysSettings;
|
sl@51
|
846 |
if (settings == null)
|
sl@51
|
847 |
{
|
sl@51
|
848 |
settings = new DisplaysSettings();
|
sl@51
|
849 |
settings.Init();
|
sl@65
|
850 |
Properties.Settings.Default.DisplaysSettings = settings;
|
sl@51
|
851 |
}
|
sl@48
|
852 |
|
sl@48
|
853 |
//Make sure all our settings have been created
|
sl@48
|
854 |
while (settings.Displays.Count <= Properties.Settings.Default.CurrentDisplayIndex)
|
sl@48
|
855 |
{
|
sl@50
|
856 |
settings.Displays.Add(new DisplaySettings());
|
sl@48
|
857 |
}
|
sl@48
|
858 |
|
sl@50
|
859 |
DisplaySettings displaySettings = settings.Displays[Properties.Settings.Default.CurrentDisplayIndex];
|
sl@48
|
860 |
return displaySettings;
|
sl@48
|
861 |
}
|
sl@48
|
862 |
}
|
sl@48
|
863 |
|
sl@54
|
864 |
/// <summary>
|
sl@54
|
865 |
/// Check if the given font has a fixed character pitch.
|
sl@54
|
866 |
/// </summary>
|
sl@54
|
867 |
/// <param name="ft"></param>
|
sl@54
|
868 |
/// <returns>0.0f if this is not a monospace font, otherwise returns the character width.</returns>
|
sl@54
|
869 |
public float IsFixedWidth(Font ft)
|
sl@54
|
870 |
{
|
sl@54
|
871 |
Graphics g = CreateGraphics();
|
sl@54
|
872 |
char[] charSizes = new char[] { 'i', 'a', 'Z', '%', '#', 'a', 'B', 'l', 'm', ',', '.' };
|
sl@54
|
873 |
float charWidth = g.MeasureString("I", ft, Int32.MaxValue, StringFormat.GenericTypographic).Width;
|
sl@54
|
874 |
|
sl@54
|
875 |
bool fixedWidth = true;
|
sl@54
|
876 |
|
sl@54
|
877 |
foreach (char c in charSizes)
|
sl@54
|
878 |
if (g.MeasureString(c.ToString(), ft, Int32.MaxValue, StringFormat.GenericTypographic).Width != charWidth)
|
sl@54
|
879 |
fixedWidth = false;
|
sl@54
|
880 |
|
sl@54
|
881 |
if (fixedWidth)
|
sl@54
|
882 |
{
|
sl@54
|
883 |
return charWidth;
|
sl@54
|
884 |
}
|
sl@54
|
885 |
|
sl@54
|
886 |
return 0.0f;
|
sl@54
|
887 |
}
|
sl@54
|
888 |
|
StephaneLenclud@103
|
889 |
/// <summary>
|
StephaneLenclud@103
|
890 |
/// Synchronize UI with settings
|
StephaneLenclud@103
|
891 |
/// </summary>
|
sl@7
|
892 |
private void UpdateStatus()
|
StephaneLenclud@103
|
893 |
{
|
sl@48
|
894 |
//Load settings
|
sl@54
|
895 |
checkBoxShowBorders.Checked = cds.ShowBorders;
|
sl@54
|
896 |
tableLayoutPanel.CellBorderStyle = (cds.ShowBorders ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None);
|
sl@60
|
897 |
|
sl@60
|
898 |
//Set the proper font to each of our labels
|
sl@60
|
899 |
foreach (MarqueeLabel ctrl in tableLayoutPanel.Controls)
|
sl@60
|
900 |
{
|
sl@60
|
901 |
ctrl.Font = cds.Font;
|
sl@60
|
902 |
}
|
sl@60
|
903 |
|
sl@54
|
904 |
CheckFontHeight();
|
sl@96
|
905 |
//Check if "run on Windows startup" is enabled
|
sl@96
|
906 |
checkBoxAutoStart.Checked = iStartupManager.Startup;
|
sl@96
|
907 |
//
|
sl@48
|
908 |
checkBoxConnectOnStartup.Checked = Properties.Settings.Default.DisplayConnectOnStartup;
|
sl@94
|
909 |
checkBoxMinimizeToTray.Checked = Properties.Settings.Default.MinimizeToTray;
|
sl@94
|
910 |
checkBoxStartMinimized.Checked = Properties.Settings.Default.StartMinimized;
|
sl@48
|
911 |
checkBoxReverseScreen.Checked = cds.ReverseScreen;
|
sl@57
|
912 |
checkBoxInverseColors.Checked = cds.InverseColors;
|
StephaneLenclud@115
|
913 |
checkBoxShowVolumeLabel.Checked = cds.ShowVolumeLabel;
|
sl@100
|
914 |
checkBoxScaleToFit.Checked = cds.ScaleToFit;
|
sl@100
|
915 |
maskedTextBoxMinFontSize.Enabled = cds.ScaleToFit;
|
sl@100
|
916 |
labelMinFontSize.Enabled = cds.ScaleToFit;
|
sl@100
|
917 |
maskedTextBoxMinFontSize.Text = cds.MinFontSize.ToString();
|
StephaneLenclud@106
|
918 |
maskedTextBoxScrollingSpeed.Text = cds.ScrollingSpeedInPixelsPerSecond.ToString();
|
sl@48
|
919 |
comboBoxDisplayType.SelectedIndex = cds.DisplayType;
|
sl@48
|
920 |
timer.Interval = cds.TimerInterval;
|
sl@48
|
921 |
maskedTextBoxTimerInterval.Text = cds.TimerInterval.ToString();
|
sl@100
|
922 |
textBoxScrollLoopSeparator.Text = cds.Separator;
|
sl@58
|
923 |
//
|
sl@58
|
924 |
SetupPixelDelegates();
|
sl@48
|
925 |
|
sl@7
|
926 |
if (iDisplay.IsOpen())
|
sl@7
|
927 |
{
|
StephaneLenclud@103
|
928 |
//We have a display connection
|
StephaneLenclud@103
|
929 |
//Reflect that in our UI
|
StephaneLenclud@103
|
930 |
|
StephaneLenclud@103
|
931 |
tableLayoutPanel.Enabled = true;
|
StephaneLenclud@105
|
932 |
panelDisplay.Enabled = true;
|
StephaneLenclud@103
|
933 |
|
sl@48
|
934 |
//Only setup brightness if display is open
|
sl@48
|
935 |
trackBarBrightness.Minimum = iDisplay.MinBrightness();
|
sl@48
|
936 |
trackBarBrightness.Maximum = iDisplay.MaxBrightness();
|
StephaneLenclud@105
|
937 |
if (cds.Brightness < iDisplay.MinBrightness() || cds.Brightness > iDisplay.MaxBrightness())
|
StephaneLenclud@105
|
938 |
{
|
StephaneLenclud@105
|
939 |
//Brightness out of range, this can occur when using auto-detect
|
StephaneLenclud@105
|
940 |
//Use max brightness instead
|
StephaneLenclud@105
|
941 |
trackBarBrightness.Value = iDisplay.MaxBrightness();
|
StephaneLenclud@105
|
942 |
iDisplay.SetBrightness(iDisplay.MaxBrightness());
|
StephaneLenclud@105
|
943 |
}
|
StephaneLenclud@105
|
944 |
else
|
StephaneLenclud@105
|
945 |
{
|
StephaneLenclud@105
|
946 |
trackBarBrightness.Value = cds.Brightness;
|
StephaneLenclud@105
|
947 |
iDisplay.SetBrightness(cds.Brightness);
|
StephaneLenclud@105
|
948 |
}
|
StephaneLenclud@105
|
949 |
|
StephaneLenclud@105
|
950 |
//Try compute the steps to something that makes sense
|
sl@48
|
951 |
trackBarBrightness.LargeChange = Math.Max(1, (iDisplay.MaxBrightness() - iDisplay.MinBrightness()) / 5);
|
sl@48
|
952 |
trackBarBrightness.SmallChange = 1;
|
StephaneLenclud@105
|
953 |
|
sl@48
|
954 |
//
|
sl@7
|
955 |
buttonFill.Enabled = true;
|
sl@7
|
956 |
buttonClear.Enabled = true;
|
sl@7
|
957 |
buttonOpen.Enabled = false;
|
sl@7
|
958 |
buttonClose.Enabled = true;
|
sl@7
|
959 |
trackBarBrightness.Enabled = true;
|
sl@10
|
960 |
toolStripStatusLabelConnect.Text = "Connected - " + iDisplay.Vendor() + " - " + iDisplay.Product();
|
sl@10
|
961 |
//+ " - " + iDisplay.SerialNumber();
|
sl@52
|
962 |
|
sl@52
|
963 |
if (iDisplay.SupportPowerOnOff())
|
sl@52
|
964 |
{
|
sl@52
|
965 |
buttonPowerOn.Enabled = true;
|
sl@52
|
966 |
buttonPowerOff.Enabled = true;
|
sl@52
|
967 |
}
|
sl@52
|
968 |
else
|
sl@52
|
969 |
{
|
sl@52
|
970 |
buttonPowerOn.Enabled = false;
|
sl@52
|
971 |
buttonPowerOff.Enabled = false;
|
sl@52
|
972 |
}
|
sl@53
|
973 |
|
sl@53
|
974 |
if (iDisplay.SupportClock())
|
sl@53
|
975 |
{
|
sl@53
|
976 |
buttonShowClock.Enabled = true;
|
sl@53
|
977 |
buttonHideClock.Enabled = true;
|
sl@53
|
978 |
}
|
sl@53
|
979 |
else
|
sl@53
|
980 |
{
|
sl@53
|
981 |
buttonShowClock.Enabled = false;
|
sl@53
|
982 |
buttonHideClock.Enabled = false;
|
sl@53
|
983 |
}
|
StephaneLenclud@115
|
984 |
|
StephaneLenclud@115
|
985 |
|
StephaneLenclud@115
|
986 |
//Check if Volume Label is supported. To date only MDM166AA supports that crap :)
|
StephaneLenclud@115
|
987 |
checkBoxShowVolumeLabel.Enabled = iDisplay.IconCount(Display.TMiniDisplayIconType.EMiniDisplayIconVolumeLabel)>0;
|
StephaneLenclud@115
|
988 |
|
StephaneLenclud@115
|
989 |
if (cds.ShowVolumeLabel)
|
StephaneLenclud@115
|
990 |
{
|
StephaneLenclud@115
|
991 |
iDisplay.SetIconOn(Display.TMiniDisplayIconType.EMiniDisplayIconVolumeLabel);
|
StephaneLenclud@115
|
992 |
}
|
StephaneLenclud@115
|
993 |
else
|
StephaneLenclud@115
|
994 |
{
|
StephaneLenclud@115
|
995 |
iDisplay.SetIconOff(Display.TMiniDisplayIconType.EMiniDisplayIconVolumeLabel);
|
StephaneLenclud@115
|
996 |
}
|
sl@7
|
997 |
}
|
sl@7
|
998 |
else
|
sl@7
|
999 |
{
|
StephaneLenclud@103
|
1000 |
//Display is connection not available
|
StephaneLenclud@103
|
1001 |
//Reflect that in our UI
|
StephaneLenclud@115
|
1002 |
checkBoxShowVolumeLabel.Enabled = false;
|
StephaneLenclud@103
|
1003 |
tableLayoutPanel.Enabled = false;
|
StephaneLenclud@105
|
1004 |
panelDisplay.Enabled = false;
|
sl@7
|
1005 |
buttonFill.Enabled = false;
|
sl@7
|
1006 |
buttonClear.Enabled = false;
|
sl@7
|
1007 |
buttonOpen.Enabled = true;
|
sl@7
|
1008 |
buttonClose.Enabled = false;
|
sl@7
|
1009 |
trackBarBrightness.Enabled = false;
|
sl@52
|
1010 |
buttonPowerOn.Enabled = false;
|
sl@52
|
1011 |
buttonPowerOff.Enabled = false;
|
sl@53
|
1012 |
buttonShowClock.Enabled = false;
|
sl@53
|
1013 |
buttonHideClock.Enabled = false;
|
sl@9
|
1014 |
toolStripStatusLabelConnect.Text = "Disconnected";
|
sl@48
|
1015 |
toolStripStatusLabelPower.Text = "N/A";
|
sl@7
|
1016 |
}
|
StephaneLenclud@106
|
1017 |
|
sl@7
|
1018 |
}
|
sl@9
|
1019 |
|
sl@13
|
1020 |
|
StephaneLenclud@115
|
1021 |
/// <summary>
|
StephaneLenclud@115
|
1022 |
///
|
StephaneLenclud@115
|
1023 |
/// </summary>
|
StephaneLenclud@115
|
1024 |
/// <param name="sender"></param>
|
StephaneLenclud@115
|
1025 |
/// <param name="e"></param>
|
StephaneLenclud@115
|
1026 |
private void checkBoxShowVolumeLabel_CheckedChanged(object sender, EventArgs e)
|
StephaneLenclud@115
|
1027 |
{
|
StephaneLenclud@115
|
1028 |
cds.ShowVolumeLabel = checkBoxShowVolumeLabel.Checked;
|
StephaneLenclud@115
|
1029 |
Properties.Settings.Default.Save();
|
StephaneLenclud@115
|
1030 |
UpdateStatus();
|
StephaneLenclud@115
|
1031 |
}
|
sl@13
|
1032 |
|
sl@9
|
1033 |
private void checkBoxShowBorders_CheckedChanged(object sender, EventArgs e)
|
sl@9
|
1034 |
{
|
sl@16
|
1035 |
//Save our show borders setting
|
sl@13
|
1036 |
tableLayoutPanel.CellBorderStyle = (checkBoxShowBorders.Checked ? TableLayoutPanelCellBorderStyle.Single : TableLayoutPanelCellBorderStyle.None);
|
sl@48
|
1037 |
cds.ShowBorders = checkBoxShowBorders.Checked;
|
sl@9
|
1038 |
Properties.Settings.Default.Save();
|
sl@57
|
1039 |
CheckFontHeight();
|
sl@9
|
1040 |
}
|
sl@13
|
1041 |
|
sl@13
|
1042 |
private void checkBoxConnectOnStartup_CheckedChanged(object sender, EventArgs e)
|
sl@13
|
1043 |
{
|
sl@16
|
1044 |
//Save our connect on startup setting
|
sl@13
|
1045 |
Properties.Settings.Default.DisplayConnectOnStartup = checkBoxConnectOnStartup.Checked;
|
sl@13
|
1046 |
Properties.Settings.Default.Save();
|
sl@13
|
1047 |
}
|
sl@13
|
1048 |
|
sl@94
|
1049 |
private void checkBoxMinimizeToTray_CheckedChanged(object sender, EventArgs e)
|
sl@94
|
1050 |
{
|
sl@94
|
1051 |
//Save our "Minimize to tray" setting
|
sl@94
|
1052 |
Properties.Settings.Default.MinimizeToTray = checkBoxMinimizeToTray.Checked;
|
sl@94
|
1053 |
Properties.Settings.Default.Save();
|
sl@94
|
1054 |
|
sl@94
|
1055 |
}
|
sl@94
|
1056 |
|
sl@94
|
1057 |
private void checkBoxStartMinimized_CheckedChanged(object sender, EventArgs e)
|
sl@94
|
1058 |
{
|
sl@94
|
1059 |
//Save our "Start minimized" setting
|
sl@94
|
1060 |
Properties.Settings.Default.StartMinimized = checkBoxStartMinimized.Checked;
|
sl@94
|
1061 |
Properties.Settings.Default.Save();
|
sl@94
|
1062 |
}
|
sl@94
|
1063 |
|
sl@94
|
1064 |
private void checkBoxAutoStart_CheckedChanged(object sender, EventArgs e)
|
sl@94
|
1065 |
{
|
sl@94
|
1066 |
iStartupManager.Startup = checkBoxAutoStart.Checked;
|
sl@94
|
1067 |
}
|
sl@94
|
1068 |
|
sl@94
|
1069 |
|
sl@16
|
1070 |
private void checkBoxReverseScreen_CheckedChanged(object sender, EventArgs e)
|
sl@16
|
1071 |
{
|
sl@16
|
1072 |
//Save our reverse screen setting
|
sl@48
|
1073 |
cds.ReverseScreen = checkBoxReverseScreen.Checked;
|
sl@16
|
1074 |
Properties.Settings.Default.Save();
|
sl@58
|
1075 |
SetupPixelDelegates();
|
sl@16
|
1076 |
}
|
sl@16
|
1077 |
|
sl@57
|
1078 |
private void checkBoxInverseColors_CheckedChanged(object sender, EventArgs e)
|
sl@57
|
1079 |
{
|
sl@57
|
1080 |
//Save our inverse colors setting
|
sl@57
|
1081 |
cds.InverseColors = checkBoxInverseColors.Checked;
|
sl@57
|
1082 |
Properties.Settings.Default.Save();
|
sl@58
|
1083 |
SetupPixelDelegates();
|
sl@57
|
1084 |
}
|
sl@57
|
1085 |
|
sl@100
|
1086 |
private void checkBoxScaleToFit_CheckedChanged(object sender, EventArgs e)
|
sl@100
|
1087 |
{
|
sl@100
|
1088 |
//Save our scale to fit setting
|
sl@100
|
1089 |
cds.ScaleToFit = checkBoxScaleToFit.Checked;
|
sl@100
|
1090 |
Properties.Settings.Default.Save();
|
sl@100
|
1091 |
//
|
sl@100
|
1092 |
labelMinFontSize.Enabled = cds.ScaleToFit;
|
sl@100
|
1093 |
maskedTextBoxMinFontSize.Enabled = cds.ScaleToFit;
|
sl@100
|
1094 |
}
|
sl@100
|
1095 |
|
sl@14
|
1096 |
private void MainForm_Resize(object sender, EventArgs e)
|
sl@14
|
1097 |
{
|
sl@14
|
1098 |
if (WindowState == FormWindowState.Minimized)
|
sl@14
|
1099 |
{
|
sl@14
|
1100 |
// Do some stuff
|
sl@14
|
1101 |
//iBmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height, PixelFormat.Format32bppArgb);
|
sl@14
|
1102 |
iCreateBitmap = true;
|
sl@14
|
1103 |
}
|
sl@14
|
1104 |
}
|
sl@14
|
1105 |
|
sl@17
|
1106 |
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
|
sl@17
|
1107 |
{
|
StephaneLenclud@117
|
1108 |
iNetworkManager.Dispose();
|
StephaneLenclud@105
|
1109 |
CloseDisplayConnection();
|
sl@17
|
1110 |
StopServer();
|
sl@32
|
1111 |
e.Cancel = iClosing;
|
sl@17
|
1112 |
}
|
sl@17
|
1113 |
|
sl@17
|
1114 |
public void StartServer()
|
sl@17
|
1115 |
{
|
sl@17
|
1116 |
iServiceHost = new ServiceHost
|
sl@17
|
1117 |
(
|
sl@55
|
1118 |
typeof(Session),
|
sl@20
|
1119 |
new Uri[] { new Uri("net.tcp://localhost:8001/") }
|
sl@17
|
1120 |
);
|
sl@17
|
1121 |
|
sl@55
|
1122 |
iServiceHost.AddServiceEndpoint(typeof(IService), new NetTcpBinding(SecurityMode.None, true), "DisplayService");
|
sl@17
|
1123 |
iServiceHost.Open();
|
sl@17
|
1124 |
}
|
sl@17
|
1125 |
|
sl@17
|
1126 |
public void StopServer()
|
sl@17
|
1127 |
{
|
sl@32
|
1128 |
if (iClients.Count > 0 && !iClosing)
|
sl@29
|
1129 |
{
|
sl@29
|
1130 |
//Tell our clients
|
sl@32
|
1131 |
iClosing = true;
|
sl@29
|
1132 |
BroadcastCloseEvent();
|
sl@29
|
1133 |
}
|
sl@32
|
1134 |
else if (iClosing)
|
sl@32
|
1135 |
{
|
sl@32
|
1136 |
if (MessageBox.Show("Force exit?", "Waiting for clients...", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
|
sl@32
|
1137 |
{
|
sl@32
|
1138 |
iClosing = false; //We make sure we force close if asked twice
|
sl@32
|
1139 |
}
|
sl@32
|
1140 |
}
|
sl@32
|
1141 |
else
|
sl@36
|
1142 |
{
|
sl@32
|
1143 |
//We removed that as it often lags for some reason
|
sl@32
|
1144 |
//iServiceHost.Close();
|
sl@32
|
1145 |
}
|
sl@17
|
1146 |
}
|
sl@17
|
1147 |
|
sl@21
|
1148 |
public void BroadcastCloseEvent()
|
sl@21
|
1149 |
{
|
sl@31
|
1150 |
Trace.TraceInformation("BroadcastCloseEvent - start");
|
sl@31
|
1151 |
|
sl@21
|
1152 |
var inactiveClients = new List<string>();
|
sl@21
|
1153 |
foreach (var client in iClients)
|
sl@21
|
1154 |
{
|
sl@21
|
1155 |
//if (client.Key != eventData.ClientName)
|
sl@21
|
1156 |
{
|
sl@21
|
1157 |
try
|
sl@21
|
1158 |
{
|
sl@31
|
1159 |
Trace.TraceInformation("BroadcastCloseEvent - " + client.Key);
|
sl@33
|
1160 |
client.Value.Callback.OnCloseOrder(/*eventData*/);
|
sl@21
|
1161 |
}
|
sl@21
|
1162 |
catch (Exception ex)
|
sl@21
|
1163 |
{
|
sl@21
|
1164 |
inactiveClients.Add(client.Key);
|
sl@21
|
1165 |
}
|
sl@21
|
1166 |
}
|
sl@21
|
1167 |
}
|
sl@21
|
1168 |
|
sl@21
|
1169 |
if (inactiveClients.Count > 0)
|
sl@21
|
1170 |
{
|
sl@21
|
1171 |
foreach (var client in inactiveClients)
|
sl@21
|
1172 |
{
|
sl@21
|
1173 |
iClients.Remove(client);
|
sl@30
|
1174 |
Program.iMainForm.treeViewClients.Nodes.Remove(Program.iMainForm.treeViewClients.Nodes.Find(client, false)[0]);
|
sl@21
|
1175 |
}
|
sl@21
|
1176 |
}
|
sl@97
|
1177 |
|
sl@97
|
1178 |
if (iClients.Count==0)
|
sl@97
|
1179 |
{
|
sl@97
|
1180 |
ClearLayout();
|
sl@97
|
1181 |
}
|
sl@21
|
1182 |
}
|
sl@21
|
1183 |
|
sl@97
|
1184 |
/// <summary>
|
sl@97
|
1185 |
/// Just remove all our fields.
|
sl@97
|
1186 |
/// </summary>
|
sl@97
|
1187 |
private void ClearLayout()
|
sl@97
|
1188 |
{
|
sl@97
|
1189 |
tableLayoutPanel.Controls.Clear();
|
sl@97
|
1190 |
tableLayoutPanel.RowStyles.Clear();
|
sl@97
|
1191 |
tableLayoutPanel.ColumnStyles.Clear();
|
sl@97
|
1192 |
}
|
sl@97
|
1193 |
|
StephaneLenclud@106
|
1194 |
/// <summary>
|
StephaneLenclud@106
|
1195 |
/// Just launch a demo client.
|
StephaneLenclud@106
|
1196 |
/// </summary>
|
StephaneLenclud@106
|
1197 |
private void StartNewClient(string aTopText = "", string aBottomText = "")
|
StephaneLenclud@106
|
1198 |
{
|
StephaneLenclud@106
|
1199 |
Thread clientThread = new Thread(SharpDisplayClient.Program.MainWithParams);
|
StephaneLenclud@106
|
1200 |
SharpDisplayClient.StartParams myParams = new SharpDisplayClient.StartParams(new Point(this.Right, this.Top),aTopText,aBottomText);
|
StephaneLenclud@106
|
1201 |
clientThread.Start(myParams);
|
StephaneLenclud@106
|
1202 |
BringToFront();
|
StephaneLenclud@106
|
1203 |
}
|
StephaneLenclud@106
|
1204 |
|
sl@25
|
1205 |
private void buttonStartClient_Click(object sender, EventArgs e)
|
sl@25
|
1206 |
{
|
StephaneLenclud@106
|
1207 |
StartNewClient();
|
sl@25
|
1208 |
}
|
sl@25
|
1209 |
|
sl@27
|
1210 |
private void buttonSuspend_Click(object sender, EventArgs e)
|
sl@27
|
1211 |
{
|
sl@52
|
1212 |
LastTickTime = DateTime.Now; //Reset timer to prevent jump
|
sl@27
|
1213 |
timer.Enabled = !timer.Enabled;
|
sl@27
|
1214 |
if (!timer.Enabled)
|
sl@27
|
1215 |
{
|
sl@52
|
1216 |
buttonSuspend.Text = "Run";
|
sl@27
|
1217 |
}
|
sl@27
|
1218 |
else
|
sl@27
|
1219 |
{
|
sl@27
|
1220 |
buttonSuspend.Text = "Pause";
|
sl@27
|
1221 |
}
|
sl@27
|
1222 |
}
|
sl@27
|
1223 |
|
sl@29
|
1224 |
private void buttonCloseClients_Click(object sender, EventArgs e)
|
sl@29
|
1225 |
{
|
sl@29
|
1226 |
BroadcastCloseEvent();
|
sl@29
|
1227 |
}
|
sl@29
|
1228 |
|
sl@30
|
1229 |
private void treeViewClients_AfterSelect(object sender, TreeViewEventArgs e)
|
sl@30
|
1230 |
{
|
sl@21
|
1231 |
|
sl@30
|
1232 |
}
|
sl@30
|
1233 |
|
sl@36
|
1234 |
|
sl@30
|
1235 |
/// <summary>
|
sl@36
|
1236 |
///
|
sl@30
|
1237 |
/// </summary>
|
sl@30
|
1238 |
/// <param name="aSessionId"></param>
|
sl@30
|
1239 |
/// <param name="aCallback"></param>
|
sl@55
|
1240 |
public void AddClientThreadSafe(string aSessionId, ICallback aCallback)
|
sl@30
|
1241 |
{
|
sl@33
|
1242 |
if (this.InvokeRequired)
|
sl@30
|
1243 |
{
|
sl@30
|
1244 |
//Not in the proper thread, invoke ourselves
|
sl@30
|
1245 |
AddClientDelegate d = new AddClientDelegate(AddClientThreadSafe);
|
sl@30
|
1246 |
this.Invoke(d, new object[] { aSessionId, aCallback });
|
sl@30
|
1247 |
}
|
sl@30
|
1248 |
else
|
sl@30
|
1249 |
{
|
sl@30
|
1250 |
//We are in the proper thread
|
sl@30
|
1251 |
//Add this session to our collection of clients
|
sl@33
|
1252 |
ClientData newClient = new ClientData(aSessionId, aCallback);
|
sl@33
|
1253 |
Program.iMainForm.iClients.Add(aSessionId, newClient);
|
sl@30
|
1254 |
//Add this session to our UI
|
sl@33
|
1255 |
UpdateClientTreeViewNode(newClient);
|
sl@30
|
1256 |
}
|
sl@30
|
1257 |
}
|
sl@30
|
1258 |
|
sl@30
|
1259 |
/// <summary>
|
sl@36
|
1260 |
///
|
sl@30
|
1261 |
/// </summary>
|
sl@30
|
1262 |
/// <param name="aSessionId"></param>
|
sl@30
|
1263 |
public void RemoveClientThreadSafe(string aSessionId)
|
sl@30
|
1264 |
{
|
sl@33
|
1265 |
if (this.InvokeRequired)
|
sl@30
|
1266 |
{
|
sl@30
|
1267 |
//Not in the proper thread, invoke ourselves
|
sl@30
|
1268 |
RemoveClientDelegate d = new RemoveClientDelegate(RemoveClientThreadSafe);
|
sl@30
|
1269 |
this.Invoke(d, new object[] { aSessionId });
|
sl@30
|
1270 |
}
|
sl@30
|
1271 |
else
|
sl@30
|
1272 |
{
|
sl@30
|
1273 |
//We are in the proper thread
|
sl@33
|
1274 |
//Remove this session from both client collection and UI tree view
|
sl@30
|
1275 |
if (Program.iMainForm.iClients.Keys.Contains(aSessionId))
|
sl@30
|
1276 |
{
|
sl@30
|
1277 |
Program.iMainForm.iClients.Remove(aSessionId);
|
sl@30
|
1278 |
Program.iMainForm.treeViewClients.Nodes.Remove(Program.iMainForm.treeViewClients.Nodes.Find(aSessionId, false)[0]);
|
sl@32
|
1279 |
}
|
sl@32
|
1280 |
|
sl@97
|
1281 |
if (iClients.Count == 0)
|
sl@97
|
1282 |
{
|
sl@97
|
1283 |
//Clear our screen when last client disconnects
|
sl@97
|
1284 |
ClearLayout();
|
sl@97
|
1285 |
|
sl@97
|
1286 |
if (iClosing)
|
sl@97
|
1287 |
{
|
sl@97
|
1288 |
//We were closing our form
|
sl@97
|
1289 |
//All clients are now closed
|
sl@97
|
1290 |
//Just resume our close operation
|
sl@97
|
1291 |
iClosing = false;
|
sl@97
|
1292 |
Close();
|
sl@97
|
1293 |
}
|
sl@97
|
1294 |
}
|
sl@30
|
1295 |
}
|
sl@30
|
1296 |
}
|
sl@30
|
1297 |
|
sl@30
|
1298 |
/// <summary>
|
sl@36
|
1299 |
///
|
sl@30
|
1300 |
/// </summary>
|
sl@62
|
1301 |
/// <param name="aSessionId"></param>
|
sl@72
|
1302 |
/// <param name="aLayout"></param>
|
sl@62
|
1303 |
public void SetClientLayoutThreadSafe(string aSessionId, TableLayout aLayout)
|
sl@62
|
1304 |
{
|
sl@62
|
1305 |
if (this.InvokeRequired)
|
sl@62
|
1306 |
{
|
sl@62
|
1307 |
//Not in the proper thread, invoke ourselves
|
sl@62
|
1308 |
SetLayoutDelegate d = new SetLayoutDelegate(SetClientLayoutThreadSafe);
|
sl@62
|
1309 |
this.Invoke(d, new object[] { aSessionId, aLayout });
|
sl@62
|
1310 |
}
|
sl@62
|
1311 |
else
|
sl@62
|
1312 |
{
|
sl@62
|
1313 |
ClientData client = iClients[aSessionId];
|
sl@62
|
1314 |
if (client != null)
|
sl@62
|
1315 |
{
|
sl@62
|
1316 |
client.Layout = aLayout;
|
sl@65
|
1317 |
UpdateTableLayoutPanel(client);
|
sl@62
|
1318 |
//
|
sl@62
|
1319 |
UpdateClientTreeViewNode(client);
|
sl@62
|
1320 |
}
|
sl@62
|
1321 |
}
|
sl@62
|
1322 |
}
|
sl@62
|
1323 |
|
sl@62
|
1324 |
/// <summary>
|
sl@62
|
1325 |
///
|
sl@62
|
1326 |
/// </summary>
|
sl@67
|
1327 |
/// <param name="aSessionId"></param>
|
sl@72
|
1328 |
/// <param name="aField"></param>
|
sl@75
|
1329 |
public void SetClientFieldThreadSafe(string aSessionId, DataField aField)
|
sl@30
|
1330 |
{
|
sl@33
|
1331 |
if (this.InvokeRequired)
|
sl@30
|
1332 |
{
|
sl@30
|
1333 |
//Not in the proper thread, invoke ourselves
|
sl@79
|
1334 |
SetFieldDelegate d = new SetFieldDelegate(SetClientFieldThreadSafe);
|
sl@72
|
1335 |
this.Invoke(d, new object[] { aSessionId, aField });
|
sl@30
|
1336 |
}
|
sl@30
|
1337 |
else
|
sl@30
|
1338 |
{
|
sl@75
|
1339 |
//We are in the proper thread
|
sl@75
|
1340 |
//Call the non-thread-safe variant
|
sl@75
|
1341 |
SetClientField(aSessionId, aField);
|
sl@75
|
1342 |
}
|
sl@75
|
1343 |
}
|
sl@75
|
1344 |
|
sl@75
|
1345 |
/// <summary>
|
sl@79
|
1346 |
///
|
sl@75
|
1347 |
/// </summary>
|
sl@75
|
1348 |
/// <param name="aSessionId"></param>
|
sl@75
|
1349 |
/// <param name="aField"></param>
|
sl@75
|
1350 |
private void SetClientField(string aSessionId, DataField aField)
|
sl@79
|
1351 |
{
|
sl@75
|
1352 |
SetCurrentClient(aSessionId);
|
sl@75
|
1353 |
ClientData client = iClients[aSessionId];
|
sl@75
|
1354 |
if (client != null)
|
sl@75
|
1355 |
{
|
sl@76
|
1356 |
bool somethingChanged = false;
|
sl@76
|
1357 |
|
sl@75
|
1358 |
//Make sure all our fields are in place
|
sl@75
|
1359 |
while (client.Fields.Count < (aField.Index + 1))
|
sl@30
|
1360 |
{
|
sl@75
|
1361 |
//Add a text field with proper index
|
sl@75
|
1362 |
client.Fields.Add(new DataField(client.Fields.Count));
|
sl@76
|
1363 |
somethingChanged = true;
|
sl@75
|
1364 |
}
|
sl@75
|
1365 |
|
sl@75
|
1366 |
if (client.Fields[aField.Index].IsSameLayout(aField))
|
sl@75
|
1367 |
{
|
sl@75
|
1368 |
//Same layout just update our field
|
sl@75
|
1369 |
client.Fields[aField.Index] = aField;
|
sl@75
|
1370 |
//
|
sl@75
|
1371 |
if (aField.IsText && tableLayoutPanel.Controls[aField.Index] is MarqueeLabel)
|
sl@79
|
1372 |
{
|
sl@75
|
1373 |
//Text field control already in place, just change the text
|
sl@72
|
1374 |
MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[aField.Index];
|
sl@76
|
1375 |
somethingChanged = (label.Text != aField.Text || label.TextAlign != aField.Alignment);
|
sl@72
|
1376 |
label.Text = aField.Text;
|
sl@72
|
1377 |
label.TextAlign = aField.Alignment;
|
sl@68
|
1378 |
}
|
sl@75
|
1379 |
else if (aField.IsBitmap && tableLayoutPanel.Controls[aField.Index] is PictureBox)
|
sl@75
|
1380 |
{
|
sl@76
|
1381 |
somethingChanged = true; //TODO: Bitmap comp or should we leave that to clients?
|
sl@75
|
1382 |
//Bitmap field control already in place just change the bitmap
|
sl@75
|
1383 |
PictureBox pictureBox = (PictureBox)tableLayoutPanel.Controls[aField.Index];
|
sl@75
|
1384 |
pictureBox.Image = aField.Bitmap;
|
sl@75
|
1385 |
}
|
sl@68
|
1386 |
else
|
sl@68
|
1387 |
{
|
sl@76
|
1388 |
somethingChanged = true;
|
sl@75
|
1389 |
//The requested control in our layout it not of the correct type
|
sl@68
|
1390 |
//Wrong control type, re-create them all
|
sl@68
|
1391 |
UpdateTableLayoutPanel(iCurrentClientData);
|
sl@68
|
1392 |
}
|
sl@30
|
1393 |
}
|
sl@75
|
1394 |
else
|
sl@75
|
1395 |
{
|
sl@76
|
1396 |
somethingChanged = true;
|
sl@75
|
1397 |
//Different layout, need to rebuild it
|
sl@75
|
1398 |
client.Fields[aField.Index] = aField;
|
sl@75
|
1399 |
UpdateTableLayoutPanel(iCurrentClientData);
|
sl@75
|
1400 |
}
|
sl@75
|
1401 |
|
sl@75
|
1402 |
//
|
sl@76
|
1403 |
if (somethingChanged)
|
sl@76
|
1404 |
{
|
sl@76
|
1405 |
UpdateClientTreeViewNode(client);
|
sl@76
|
1406 |
}
|
sl@30
|
1407 |
}
|
sl@30
|
1408 |
}
|
sl@30
|
1409 |
|
sl@30
|
1410 |
/// <summary>
|
sl@36
|
1411 |
///
|
sl@30
|
1412 |
/// </summary>
|
sl@30
|
1413 |
/// <param name="aTexts"></param>
|
sl@75
|
1414 |
public void SetClientFieldsThreadSafe(string aSessionId, System.Collections.Generic.IList<DataField> aFields)
|
sl@30
|
1415 |
{
|
sl@33
|
1416 |
if (this.InvokeRequired)
|
sl@30
|
1417 |
{
|
sl@30
|
1418 |
//Not in the proper thread, invoke ourselves
|
sl@75
|
1419 |
SetFieldsDelegate d = new SetFieldsDelegate(SetClientFieldsThreadSafe);
|
sl@72
|
1420 |
this.Invoke(d, new object[] { aSessionId, aFields });
|
sl@30
|
1421 |
}
|
sl@30
|
1422 |
else
|
sl@30
|
1423 |
{
|
sl@75
|
1424 |
//Put each our text fields in a label control
|
sl@75
|
1425 |
foreach (DataField field in aFields)
|
sl@30
|
1426 |
{
|
sl@75
|
1427 |
SetClientField(aSessionId, field);
|
sl@30
|
1428 |
}
|
sl@30
|
1429 |
}
|
sl@32
|
1430 |
}
|
sl@30
|
1431 |
|
sl@67
|
1432 |
/// <summary>
|
sl@67
|
1433 |
///
|
sl@67
|
1434 |
/// </summary>
|
sl@67
|
1435 |
/// <param name="aSessionId"></param>
|
sl@32
|
1436 |
/// <param name="aName"></param>
|
sl@32
|
1437 |
public void SetClientNameThreadSafe(string aSessionId, string aName)
|
sl@32
|
1438 |
{
|
sl@32
|
1439 |
if (this.InvokeRequired)
|
sl@32
|
1440 |
{
|
sl@32
|
1441 |
//Not in the proper thread, invoke ourselves
|
sl@32
|
1442 |
SetClientNameDelegate d = new SetClientNameDelegate(SetClientNameThreadSafe);
|
sl@32
|
1443 |
this.Invoke(d, new object[] { aSessionId, aName });
|
sl@32
|
1444 |
}
|
sl@32
|
1445 |
else
|
sl@32
|
1446 |
{
|
sl@32
|
1447 |
//We are in the proper thread
|
sl@33
|
1448 |
//Get our client
|
sl@33
|
1449 |
ClientData client = iClients[aSessionId];
|
sl@33
|
1450 |
if (client != null)
|
sl@32
|
1451 |
{
|
sl@33
|
1452 |
//Set its name
|
sl@33
|
1453 |
client.Name = aName;
|
sl@33
|
1454 |
//Update our tree-view
|
sl@33
|
1455 |
UpdateClientTreeViewNode(client);
|
sl@33
|
1456 |
}
|
sl@33
|
1457 |
}
|
sl@33
|
1458 |
}
|
sl@33
|
1459 |
|
sl@33
|
1460 |
/// <summary>
|
sl@36
|
1461 |
///
|
sl@33
|
1462 |
/// </summary>
|
sl@33
|
1463 |
/// <param name="aClient"></param>
|
sl@33
|
1464 |
private void UpdateClientTreeViewNode(ClientData aClient)
|
sl@33
|
1465 |
{
|
sl@33
|
1466 |
if (aClient == null)
|
sl@33
|
1467 |
{
|
sl@33
|
1468 |
return;
|
sl@33
|
1469 |
}
|
sl@33
|
1470 |
|
sl@33
|
1471 |
TreeNode node = null;
|
sl@33
|
1472 |
//Check that our client node already exists
|
sl@33
|
1473 |
//Get our client root node using its key which is our session ID
|
sl@33
|
1474 |
TreeNode[] nodes = treeViewClients.Nodes.Find(aClient.SessionId, false);
|
sl@33
|
1475 |
if (nodes.Count()>0)
|
sl@33
|
1476 |
{
|
sl@33
|
1477 |
//We already have a node for that client
|
sl@33
|
1478 |
node = nodes[0];
|
sl@33
|
1479 |
//Clear children as we are going to recreate them below
|
sl@33
|
1480 |
node.Nodes.Clear();
|
sl@33
|
1481 |
}
|
sl@33
|
1482 |
else
|
sl@33
|
1483 |
{
|
sl@33
|
1484 |
//Client node does not exists create a new one
|
sl@33
|
1485 |
treeViewClients.Nodes.Add(aClient.SessionId, aClient.SessionId);
|
sl@33
|
1486 |
node = treeViewClients.Nodes.Find(aClient.SessionId, false)[0];
|
sl@33
|
1487 |
}
|
sl@33
|
1488 |
|
sl@33
|
1489 |
if (node != null)
|
sl@33
|
1490 |
{
|
sl@33
|
1491 |
//Change its name
|
sl@33
|
1492 |
if (aClient.Name != "")
|
sl@33
|
1493 |
{
|
sl@33
|
1494 |
//We have a name, us it as text for our root node
|
sl@33
|
1495 |
node.Text = aClient.Name;
|
sl@32
|
1496 |
//Add a child with SessionId
|
sl@33
|
1497 |
node.Nodes.Add(new TreeNode(aClient.SessionId));
|
sl@33
|
1498 |
}
|
sl@33
|
1499 |
else
|
sl@33
|
1500 |
{
|
sl@33
|
1501 |
//No name, use session ID instead
|
sl@33
|
1502 |
node.Text = aClient.SessionId;
|
sl@33
|
1503 |
}
|
sl@36
|
1504 |
|
sl@67
|
1505 |
if (aClient.Fields.Count > 0)
|
sl@33
|
1506 |
{
|
sl@33
|
1507 |
//Create root node for our texts
|
sl@70
|
1508 |
TreeNode textsRoot = new TreeNode("Fields");
|
sl@33
|
1509 |
node.Nodes.Add(textsRoot);
|
sl@33
|
1510 |
//For each text add a new entry
|
sl@67
|
1511 |
foreach (DataField field in aClient.Fields)
|
sl@33
|
1512 |
{
|
sl@75
|
1513 |
if (!field.IsBitmap)
|
sl@67
|
1514 |
{
|
sl@72
|
1515 |
DataField textField = (DataField)field;
|
sl@70
|
1516 |
textsRoot.Nodes.Add(new TreeNode("[Text]" + textField.Text));
|
sl@67
|
1517 |
}
|
sl@67
|
1518 |
else
|
sl@67
|
1519 |
{
|
sl@72
|
1520 |
textsRoot.Nodes.Add(new TreeNode("[Bitmap]"));
|
sl@70
|
1521 |
}
|
sl@33
|
1522 |
}
|
sl@32
|
1523 |
}
|
sl@34
|
1524 |
|
sl@34
|
1525 |
node.ExpandAll();
|
sl@32
|
1526 |
}
|
sl@30
|
1527 |
}
|
sl@17
|
1528 |
|
sl@60
|
1529 |
/// <summary>
|
sl@60
|
1530 |
/// Update our table layout row styles to make sure each rows have similar height
|
sl@60
|
1531 |
/// </summary>
|
sl@60
|
1532 |
private void UpdateTableLayoutRowStyles()
|
sl@60
|
1533 |
{
|
sl@60
|
1534 |
foreach (RowStyle rowStyle in tableLayoutPanel.RowStyles)
|
sl@60
|
1535 |
{
|
sl@60
|
1536 |
rowStyle.SizeType = SizeType.Percent;
|
sl@60
|
1537 |
rowStyle.Height = 100 / tableLayoutPanel.RowCount;
|
sl@60
|
1538 |
}
|
sl@60
|
1539 |
}
|
sl@60
|
1540 |
|
sl@70
|
1541 |
/// DEPRECATED
|
sl@60
|
1542 |
/// <summary>
|
sl@61
|
1543 |
/// Empty and recreate our table layout with the given number of columns and rows.
|
sl@61
|
1544 |
/// Sizes of rows and columns are uniform.
|
sl@60
|
1545 |
/// </summary>
|
sl@60
|
1546 |
/// <param name="aColumn"></param>
|
sl@60
|
1547 |
/// <param name="aRow"></param>
|
sl@62
|
1548 |
private void UpdateTableLayoutPanel(int aColumn, int aRow)
|
sl@60
|
1549 |
{
|
sl@61
|
1550 |
tableLayoutPanel.Controls.Clear();
|
sl@61
|
1551 |
tableLayoutPanel.RowStyles.Clear();
|
sl@61
|
1552 |
tableLayoutPanel.ColumnStyles.Clear();
|
sl@61
|
1553 |
tableLayoutPanel.RowCount = 0;
|
sl@61
|
1554 |
tableLayoutPanel.ColumnCount = 0;
|
sl@60
|
1555 |
|
sl@61
|
1556 |
while (tableLayoutPanel.RowCount < aRow)
|
sl@61
|
1557 |
{
|
sl@61
|
1558 |
tableLayoutPanel.RowCount++;
|
sl@61
|
1559 |
}
|
sl@60
|
1560 |
|
sl@61
|
1561 |
while (tableLayoutPanel.ColumnCount < aColumn)
|
sl@61
|
1562 |
{
|
sl@61
|
1563 |
tableLayoutPanel.ColumnCount++;
|
sl@61
|
1564 |
}
|
sl@61
|
1565 |
|
sl@61
|
1566 |
for (int i = 0; i < tableLayoutPanel.ColumnCount; i++)
|
sl@61
|
1567 |
{
|
sl@61
|
1568 |
//Create our column styles
|
sl@61
|
1569 |
this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100 / tableLayoutPanel.ColumnCount));
|
sl@61
|
1570 |
|
sl@61
|
1571 |
for (int j = 0; j < tableLayoutPanel.RowCount; j++)
|
sl@61
|
1572 |
{
|
sl@61
|
1573 |
if (i == 0)
|
sl@61
|
1574 |
{
|
sl@61
|
1575 |
//Create our row styles
|
sl@61
|
1576 |
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100 / tableLayoutPanel.RowCount));
|
sl@61
|
1577 |
}
|
sl@61
|
1578 |
|
sl@61
|
1579 |
MarqueeLabel control = new SharpDisplayManager.MarqueeLabel();
|
sl@61
|
1580 |
control.AutoEllipsis = true;
|
sl@61
|
1581 |
control.AutoSize = true;
|
sl@61
|
1582 |
control.BackColor = System.Drawing.Color.Transparent;
|
sl@61
|
1583 |
control.Dock = System.Windows.Forms.DockStyle.Fill;
|
sl@61
|
1584 |
control.Location = new System.Drawing.Point(1, 1);
|
sl@61
|
1585 |
control.Margin = new System.Windows.Forms.Padding(0);
|
sl@61
|
1586 |
control.Name = "marqueeLabelCol" + aColumn + "Row" + aRow;
|
sl@61
|
1587 |
control.OwnTimer = false;
|
sl@61
|
1588 |
control.PixelsPerSecond = 64;
|
sl@100
|
1589 |
control.Separator = cds.Separator;
|
sl@100
|
1590 |
control.MinFontSize = cds.MinFontSize;
|
sl@100
|
1591 |
control.ScaleToFit = cds.ScaleToFit;
|
sl@61
|
1592 |
//control.Size = new System.Drawing.Size(254, 30);
|
sl@61
|
1593 |
//control.TabIndex = 2;
|
sl@61
|
1594 |
control.Font = cds.Font;
|
sl@61
|
1595 |
control.Text = "ABCDEFGHIJKLMNOPQRST-0123456789";
|
sl@61
|
1596 |
control.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
sl@61
|
1597 |
control.UseCompatibleTextRendering = true;
|
sl@61
|
1598 |
//
|
sl@61
|
1599 |
tableLayoutPanel.Controls.Add(control, i, j);
|
sl@61
|
1600 |
}
|
sl@61
|
1601 |
}
|
sl@38
|
1602 |
|
sl@62
|
1603 |
CheckFontHeight();
|
sl@38
|
1604 |
}
|
sl@38
|
1605 |
|
sl@63
|
1606 |
|
sl@63
|
1607 |
/// <summary>
|
sl@63
|
1608 |
/// Update our display table layout.
|
sl@63
|
1609 |
/// </summary>
|
sl@63
|
1610 |
/// <param name="aLayout"></param>
|
sl@65
|
1611 |
private void UpdateTableLayoutPanel(ClientData aClient)
|
sl@63
|
1612 |
{
|
StephaneLenclud@106
|
1613 |
if (aClient == null)
|
StephaneLenclud@106
|
1614 |
{
|
StephaneLenclud@106
|
1615 |
//Just drop it
|
StephaneLenclud@106
|
1616 |
return;
|
StephaneLenclud@106
|
1617 |
}
|
StephaneLenclud@106
|
1618 |
|
StephaneLenclud@106
|
1619 |
|
sl@65
|
1620 |
TableLayout layout = aClient.Layout;
|
sl@70
|
1621 |
int fieldCount = 0;
|
sl@70
|
1622 |
|
sl@63
|
1623 |
tableLayoutPanel.Controls.Clear();
|
sl@63
|
1624 |
tableLayoutPanel.RowStyles.Clear();
|
sl@63
|
1625 |
tableLayoutPanel.ColumnStyles.Clear();
|
sl@63
|
1626 |
tableLayoutPanel.RowCount = 0;
|
sl@63
|
1627 |
tableLayoutPanel.ColumnCount = 0;
|
sl@63
|
1628 |
|
sl@65
|
1629 |
while (tableLayoutPanel.RowCount < layout.Rows.Count)
|
sl@63
|
1630 |
{
|
sl@63
|
1631 |
tableLayoutPanel.RowCount++;
|
sl@63
|
1632 |
}
|
sl@63
|
1633 |
|
sl@65
|
1634 |
while (tableLayoutPanel.ColumnCount < layout.Columns.Count)
|
sl@63
|
1635 |
{
|
sl@63
|
1636 |
tableLayoutPanel.ColumnCount++;
|
sl@63
|
1637 |
}
|
sl@63
|
1638 |
|
sl@63
|
1639 |
for (int i = 0; i < tableLayoutPanel.ColumnCount; i++)
|
sl@63
|
1640 |
{
|
sl@63
|
1641 |
//Create our column styles
|
sl@65
|
1642 |
this.tableLayoutPanel.ColumnStyles.Add(layout.Columns[i]);
|
sl@63
|
1643 |
|
sl@63
|
1644 |
for (int j = 0; j < tableLayoutPanel.RowCount; j++)
|
sl@63
|
1645 |
{
|
sl@63
|
1646 |
if (i == 0)
|
sl@63
|
1647 |
{
|
sl@63
|
1648 |
//Create our row styles
|
sl@65
|
1649 |
this.tableLayoutPanel.RowStyles.Add(layout.Rows[j]);
|
sl@63
|
1650 |
}
|
sl@63
|
1651 |
|
sl@70
|
1652 |
//Check if we already have a control
|
sl@70
|
1653 |
Control existingControl = tableLayoutPanel.GetControlFromPosition(i,j);
|
sl@70
|
1654 |
if (existingControl!=null)
|
sl@70
|
1655 |
{
|
sl@70
|
1656 |
//We already have a control in that cell as a results of row/col spanning
|
sl@70
|
1657 |
//Move on to next cell then
|
sl@70
|
1658 |
continue;
|
sl@70
|
1659 |
}
|
sl@70
|
1660 |
|
sl@70
|
1661 |
fieldCount++;
|
sl@70
|
1662 |
|
sl@69
|
1663 |
//Check if a client field already exists for that cell
|
sl@69
|
1664 |
if (aClient.Fields.Count <= tableLayoutPanel.Controls.Count)
|
sl@65
|
1665 |
{
|
sl@69
|
1666 |
//No client field specified, create a text field by default
|
sl@72
|
1667 |
aClient.Fields.Add(new DataField(aClient.Fields.Count));
|
sl@65
|
1668 |
}
|
sl@68
|
1669 |
|
sl@69
|
1670 |
//Create a control corresponding to the field specified for that cell
|
sl@70
|
1671 |
DataField field = aClient.Fields[tableLayoutPanel.Controls.Count];
|
sl@70
|
1672 |
Control control = CreateControlForDataField(field);
|
sl@70
|
1673 |
|
sl@69
|
1674 |
//Add newly created control to our table layout at the specified row and column
|
sl@63
|
1675 |
tableLayoutPanel.Controls.Add(control, i, j);
|
sl@70
|
1676 |
//Make sure we specify row and column span for that new control
|
sl@70
|
1677 |
tableLayoutPanel.SetRowSpan(control,field.RowSpan);
|
sl@70
|
1678 |
tableLayoutPanel.SetColumnSpan(control, field.ColumnSpan);
|
sl@63
|
1679 |
}
|
sl@63
|
1680 |
}
|
sl@63
|
1681 |
|
sl@70
|
1682 |
//
|
sl@70
|
1683 |
while (aClient.Fields.Count > fieldCount)
|
sl@70
|
1684 |
{
|
sl@70
|
1685 |
//We have too much fields for this layout
|
sl@70
|
1686 |
//Just discard them until we get there
|
sl@70
|
1687 |
aClient.Fields.RemoveAt(aClient.Fields.Count-1);
|
sl@70
|
1688 |
}
|
sl@70
|
1689 |
|
sl@63
|
1690 |
CheckFontHeight();
|
sl@63
|
1691 |
}
|
sl@63
|
1692 |
|
sl@68
|
1693 |
/// <summary>
|
sl@70
|
1694 |
/// Check our type of data field and create corresponding control
|
sl@68
|
1695 |
/// </summary>
|
sl@68
|
1696 |
/// <param name="aField"></param>
|
sl@69
|
1697 |
private Control CreateControlForDataField(DataField aField)
|
sl@68
|
1698 |
{
|
sl@68
|
1699 |
Control control=null;
|
sl@75
|
1700 |
if (!aField.IsBitmap)
|
sl@68
|
1701 |
{
|
sl@68
|
1702 |
MarqueeLabel label = new SharpDisplayManager.MarqueeLabel();
|
sl@68
|
1703 |
label.AutoEllipsis = true;
|
sl@68
|
1704 |
label.AutoSize = true;
|
sl@68
|
1705 |
label.BackColor = System.Drawing.Color.Transparent;
|
sl@68
|
1706 |
label.Dock = System.Windows.Forms.DockStyle.Fill;
|
sl@68
|
1707 |
label.Location = new System.Drawing.Point(1, 1);
|
sl@68
|
1708 |
label.Margin = new System.Windows.Forms.Padding(0);
|
sl@68
|
1709 |
label.Name = "marqueeLabel" + aField.Index;
|
sl@68
|
1710 |
label.OwnTimer = false;
|
StephaneLenclud@106
|
1711 |
label.PixelsPerSecond = cds.ScrollingSpeedInPixelsPerSecond;
|
sl@100
|
1712 |
label.Separator = cds.Separator;
|
sl@100
|
1713 |
label.MinFontSize = cds.MinFontSize;
|
sl@100
|
1714 |
label.ScaleToFit = cds.ScaleToFit;
|
sl@68
|
1715 |
//control.Size = new System.Drawing.Size(254, 30);
|
sl@68
|
1716 |
//control.TabIndex = 2;
|
sl@68
|
1717 |
label.Font = cds.Font;
|
sl@68
|
1718 |
|
StephaneLenclud@106
|
1719 |
label.TextAlign = aField.Alignment;
|
sl@68
|
1720 |
label.UseCompatibleTextRendering = true;
|
sl@72
|
1721 |
label.Text = aField.Text;
|
sl@68
|
1722 |
//
|
sl@68
|
1723 |
control = label;
|
sl@68
|
1724 |
}
|
sl@72
|
1725 |
else
|
sl@68
|
1726 |
{
|
sl@68
|
1727 |
//Create picture box
|
sl@68
|
1728 |
PictureBox picture = new PictureBox();
|
sl@68
|
1729 |
picture.AutoSize = true;
|
sl@68
|
1730 |
picture.BackColor = System.Drawing.Color.Transparent;
|
sl@68
|
1731 |
picture.Dock = System.Windows.Forms.DockStyle.Fill;
|
sl@68
|
1732 |
picture.Location = new System.Drawing.Point(1, 1);
|
sl@68
|
1733 |
picture.Margin = new System.Windows.Forms.Padding(0);
|
sl@68
|
1734 |
picture.Name = "pictureBox" + aField;
|
sl@68
|
1735 |
//Set our image
|
sl@72
|
1736 |
picture.Image = aField.Bitmap;
|
sl@68
|
1737 |
//
|
sl@68
|
1738 |
control = picture;
|
sl@68
|
1739 |
}
|
sl@68
|
1740 |
|
sl@69
|
1741 |
return control;
|
sl@68
|
1742 |
}
|
sl@68
|
1743 |
|
StephaneLenclud@103
|
1744 |
/// <summary>
|
StephaneLenclud@103
|
1745 |
/// Called when the user selected a new display type.
|
StephaneLenclud@103
|
1746 |
/// </summary>
|
StephaneLenclud@103
|
1747 |
/// <param name="sender"></param>
|
StephaneLenclud@103
|
1748 |
/// <param name="e"></param>
|
sl@46
|
1749 |
private void comboBoxDisplayType_SelectedIndexChanged(object sender, EventArgs e)
|
sl@46
|
1750 |
{
|
StephaneLenclud@103
|
1751 |
//Store the selected display type in our settings
|
sl@48
|
1752 |
Properties.Settings.Default.CurrentDisplayIndex = comboBoxDisplayType.SelectedIndex;
|
sl@48
|
1753 |
cds.DisplayType = comboBoxDisplayType.SelectedIndex;
|
sl@46
|
1754 |
Properties.Settings.Default.Save();
|
StephaneLenclud@103
|
1755 |
|
StephaneLenclud@103
|
1756 |
//Try re-opening the display connection if we were already connected.
|
StephaneLenclud@103
|
1757 |
//Otherwise just update our status to reflect display type change.
|
sl@51
|
1758 |
if (iDisplay.IsOpen())
|
sl@51
|
1759 |
{
|
sl@51
|
1760 |
OpenDisplayConnection();
|
sl@51
|
1761 |
}
|
sl@51
|
1762 |
else
|
sl@51
|
1763 |
{
|
sl@51
|
1764 |
UpdateStatus();
|
sl@51
|
1765 |
}
|
sl@46
|
1766 |
}
|
sl@46
|
1767 |
|
sl@47
|
1768 |
private void maskedTextBoxTimerInterval_TextChanged(object sender, EventArgs e)
|
sl@47
|
1769 |
{
|
sl@47
|
1770 |
if (maskedTextBoxTimerInterval.Text != "")
|
sl@47
|
1771 |
{
|
sl@51
|
1772 |
int interval = Convert.ToInt32(maskedTextBoxTimerInterval.Text);
|
sl@51
|
1773 |
|
sl@51
|
1774 |
if (interval > 0)
|
sl@51
|
1775 |
{
|
sl@51
|
1776 |
timer.Interval = interval;
|
sl@51
|
1777 |
cds.TimerInterval = timer.Interval;
|
sl@51
|
1778 |
Properties.Settings.Default.Save();
|
sl@51
|
1779 |
}
|
sl@47
|
1780 |
}
|
sl@47
|
1781 |
}
|
sl@47
|
1782 |
|
sl@100
|
1783 |
private void maskedTextBoxMinFontSize_TextChanged(object sender, EventArgs e)
|
sl@100
|
1784 |
{
|
sl@100
|
1785 |
if (maskedTextBoxMinFontSize.Text != "")
|
sl@100
|
1786 |
{
|
sl@100
|
1787 |
int minFontSize = Convert.ToInt32(maskedTextBoxMinFontSize.Text);
|
sl@100
|
1788 |
|
sl@100
|
1789 |
if (minFontSize > 0)
|
sl@100
|
1790 |
{
|
sl@100
|
1791 |
cds.MinFontSize = minFontSize;
|
sl@100
|
1792 |
Properties.Settings.Default.Save();
|
StephaneLenclud@106
|
1793 |
//We need to recreate our layout for that change to take effect
|
StephaneLenclud@106
|
1794 |
UpdateTableLayoutPanel(iCurrentClientData);
|
sl@100
|
1795 |
}
|
sl@100
|
1796 |
}
|
sl@100
|
1797 |
}
|
sl@100
|
1798 |
|
StephaneLenclud@106
|
1799 |
|
StephaneLenclud@106
|
1800 |
private void maskedTextBoxScrollingSpeed_TextChanged(object sender, EventArgs e)
|
StephaneLenclud@106
|
1801 |
{
|
StephaneLenclud@106
|
1802 |
if (maskedTextBoxScrollingSpeed.Text != "")
|
StephaneLenclud@106
|
1803 |
{
|
StephaneLenclud@106
|
1804 |
int scrollingSpeed = Convert.ToInt32(maskedTextBoxScrollingSpeed.Text);
|
StephaneLenclud@106
|
1805 |
|
StephaneLenclud@106
|
1806 |
if (scrollingSpeed > 0)
|
StephaneLenclud@106
|
1807 |
{
|
StephaneLenclud@106
|
1808 |
cds.ScrollingSpeedInPixelsPerSecond = scrollingSpeed;
|
StephaneLenclud@106
|
1809 |
Properties.Settings.Default.Save();
|
StephaneLenclud@106
|
1810 |
//We need to recreate our layout for that change to take effect
|
StephaneLenclud@106
|
1811 |
UpdateTableLayoutPanel(iCurrentClientData);
|
StephaneLenclud@106
|
1812 |
}
|
StephaneLenclud@106
|
1813 |
}
|
StephaneLenclud@106
|
1814 |
}
|
StephaneLenclud@106
|
1815 |
|
sl@100
|
1816 |
private void textBoxScrollLoopSeparator_TextChanged(object sender, EventArgs e)
|
sl@100
|
1817 |
{
|
sl@100
|
1818 |
cds.Separator = textBoxScrollLoopSeparator.Text;
|
sl@100
|
1819 |
Properties.Settings.Default.Save();
|
StephaneLenclud@110
|
1820 |
|
StephaneLenclud@110
|
1821 |
//Update our text fields
|
StephaneLenclud@110
|
1822 |
foreach (MarqueeLabel ctrl in tableLayoutPanel.Controls)
|
StephaneLenclud@110
|
1823 |
{
|
StephaneLenclud@110
|
1824 |
ctrl.Separator = cds.Separator;
|
StephaneLenclud@110
|
1825 |
}
|
StephaneLenclud@110
|
1826 |
|
sl@100
|
1827 |
}
|
sl@100
|
1828 |
|
sl@52
|
1829 |
private void buttonPowerOn_Click(object sender, EventArgs e)
|
sl@52
|
1830 |
{
|
sl@52
|
1831 |
iDisplay.PowerOn();
|
sl@52
|
1832 |
}
|
sl@52
|
1833 |
|
sl@52
|
1834 |
private void buttonPowerOff_Click(object sender, EventArgs e)
|
sl@52
|
1835 |
{
|
sl@52
|
1836 |
iDisplay.PowerOff();
|
sl@52
|
1837 |
}
|
sl@52
|
1838 |
|
sl@53
|
1839 |
private void buttonShowClock_Click(object sender, EventArgs e)
|
sl@53
|
1840 |
{
|
sl@53
|
1841 |
iDisplay.ShowClock();
|
sl@53
|
1842 |
}
|
sl@53
|
1843 |
|
sl@53
|
1844 |
private void buttonHideClock_Click(object sender, EventArgs e)
|
sl@53
|
1845 |
{
|
sl@53
|
1846 |
iDisplay.HideClock();
|
sl@53
|
1847 |
}
|
sl@88
|
1848 |
|
sl@88
|
1849 |
private void buttonUpdate_Click(object sender, EventArgs e)
|
sl@88
|
1850 |
{
|
sl@88
|
1851 |
InstallUpdateSyncWithInfo();
|
sl@88
|
1852 |
}
|
sl@88
|
1853 |
|
sl@88
|
1854 |
|
sl@88
|
1855 |
private void InstallUpdateSyncWithInfo()
|
sl@88
|
1856 |
{
|
sl@88
|
1857 |
UpdateCheckInfo info = null;
|
sl@88
|
1858 |
|
sl@88
|
1859 |
if (ApplicationDeployment.IsNetworkDeployed)
|
sl@88
|
1860 |
{
|
sl@88
|
1861 |
ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
|
sl@88
|
1862 |
|
sl@88
|
1863 |
try
|
sl@88
|
1864 |
{
|
sl@88
|
1865 |
info = ad.CheckForDetailedUpdate();
|
sl@88
|
1866 |
|
sl@88
|
1867 |
}
|
sl@88
|
1868 |
catch (DeploymentDownloadException dde)
|
sl@88
|
1869 |
{
|
sl@88
|
1870 |
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);
|
sl@88
|
1871 |
return;
|
sl@88
|
1872 |
}
|
sl@88
|
1873 |
catch (InvalidDeploymentException ide)
|
sl@88
|
1874 |
{
|
sl@88
|
1875 |
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);
|
sl@88
|
1876 |
return;
|
sl@88
|
1877 |
}
|
sl@88
|
1878 |
catch (InvalidOperationException ioe)
|
sl@88
|
1879 |
{
|
sl@88
|
1880 |
MessageBox.Show("This application cannot be updated. It is likely not a ClickOnce application. Error: " + ioe.Message);
|
sl@88
|
1881 |
return;
|
sl@88
|
1882 |
}
|
sl@88
|
1883 |
|
sl@90
|
1884 |
if (info.UpdateAvailable)
|
sl@90
|
1885 |
{
|
sl@90
|
1886 |
Boolean doUpdate = true;
|
sl@88
|
1887 |
|
sl@90
|
1888 |
if (!info.IsUpdateRequired)
|
sl@90
|
1889 |
{
|
sl@90
|
1890 |
DialogResult dr = MessageBox.Show("An update is available. Would you like to update the application now?", "Update Available", MessageBoxButtons.OKCancel);
|
sl@90
|
1891 |
if (!(DialogResult.OK == dr))
|
sl@90
|
1892 |
{
|
sl@90
|
1893 |
doUpdate = false;
|
sl@90
|
1894 |
}
|
sl@90
|
1895 |
}
|
sl@90
|
1896 |
else
|
sl@90
|
1897 |
{
|
sl@90
|
1898 |
// Display a message that the app MUST reboot. Display the minimum required version.
|
sl@90
|
1899 |
MessageBox.Show("This application has detected a mandatory update from your current " +
|
sl@90
|
1900 |
"version to version " + info.MinimumRequiredVersion.ToString() +
|
sl@90
|
1901 |
". The application will now install the update and restart.",
|
sl@90
|
1902 |
"Update Available", MessageBoxButtons.OK,
|
sl@90
|
1903 |
MessageBoxIcon.Information);
|
sl@90
|
1904 |
}
|
sl@88
|
1905 |
|
sl@90
|
1906 |
if (doUpdate)
|
sl@90
|
1907 |
{
|
sl@90
|
1908 |
try
|
sl@90
|
1909 |
{
|
sl@90
|
1910 |
ad.Update();
|
sl@90
|
1911 |
MessageBox.Show("The application has been upgraded, and will now restart.");
|
sl@90
|
1912 |
Application.Restart();
|
sl@90
|
1913 |
}
|
sl@90
|
1914 |
catch (DeploymentDownloadException dde)
|
sl@90
|
1915 |
{
|
sl@90
|
1916 |
MessageBox.Show("Cannot install the latest version of the application. \n\nPlease check your network connection, or try again later. Error: " + dde);
|
sl@90
|
1917 |
return;
|
sl@90
|
1918 |
}
|
sl@90
|
1919 |
}
|
sl@90
|
1920 |
}
|
sl@90
|
1921 |
else
|
sl@90
|
1922 |
{
|
sl@90
|
1923 |
MessageBox.Show("You are already running the latest version.", "Application up-to-date");
|
sl@90
|
1924 |
}
|
sl@88
|
1925 |
}
|
sl@88
|
1926 |
}
|
sl@92
|
1927 |
|
sl@94
|
1928 |
|
sl@94
|
1929 |
/// <summary>
|
sl@99
|
1930 |
/// Used to
|
sl@94
|
1931 |
/// </summary>
|
sl@94
|
1932 |
private void SysTrayHideShow()
|
sl@92
|
1933 |
{
|
sl@94
|
1934 |
Visible = !Visible;
|
sl@94
|
1935 |
if (Visible)
|
sl@94
|
1936 |
{
|
sl@94
|
1937 |
Activate();
|
sl@94
|
1938 |
WindowState = FormWindowState.Normal;
|
sl@94
|
1939 |
}
|
sl@92
|
1940 |
}
|
sl@94
|
1941 |
|
sl@94
|
1942 |
/// <summary>
|
sl@94
|
1943 |
/// Use to handle minimize events.
|
sl@94
|
1944 |
/// </summary>
|
sl@94
|
1945 |
/// <param name="sender"></param>
|
sl@94
|
1946 |
/// <param name="e"></param>
|
sl@94
|
1947 |
private void MainForm_SizeChanged(object sender, EventArgs e)
|
sl@94
|
1948 |
{
|
sl@94
|
1949 |
if (WindowState == FormWindowState.Minimized && Properties.Settings.Default.MinimizeToTray)
|
sl@94
|
1950 |
{
|
sl@94
|
1951 |
if (Visible)
|
sl@94
|
1952 |
{
|
sl@94
|
1953 |
SysTrayHideShow();
|
sl@94
|
1954 |
}
|
sl@94
|
1955 |
}
|
sl@99
|
1956 |
|
sl@94
|
1957 |
}
|
sl@94
|
1958 |
|
StephaneLenclud@105
|
1959 |
/// <summary>
|
StephaneLenclud@105
|
1960 |
///
|
StephaneLenclud@105
|
1961 |
/// </summary>
|
StephaneLenclud@105
|
1962 |
/// <param name="sender"></param>
|
StephaneLenclud@105
|
1963 |
/// <param name="e"></param>
|
StephaneLenclud@105
|
1964 |
private void tableLayoutPanel_SizeChanged(object sender, EventArgs e)
|
StephaneLenclud@105
|
1965 |
{
|
StephaneLenclud@105
|
1966 |
//Our table layout size has changed which means our display size has changed.
|
StephaneLenclud@105
|
1967 |
//We need to re-create our bitmap.
|
StephaneLenclud@105
|
1968 |
iCreateBitmap = true;
|
StephaneLenclud@105
|
1969 |
}
|
sl@0
|
1970 |
}
|
sl@34
|
1971 |
|
sl@34
|
1972 |
/// <summary>
|
sl@34
|
1973 |
/// A UI thread copy of a client relevant data.
|
sl@34
|
1974 |
/// Keeping this copy in the UI thread helps us deal with threading issues.
|
sl@34
|
1975 |
/// </summary>
|
sl@34
|
1976 |
public class ClientData
|
sl@34
|
1977 |
{
|
sl@55
|
1978 |
public ClientData(string aSessionId, ICallback aCallback)
|
sl@34
|
1979 |
{
|
sl@34
|
1980 |
SessionId = aSessionId;
|
sl@34
|
1981 |
Name = "";
|
sl@67
|
1982 |
Fields = new List<DataField>();
|
sl@62
|
1983 |
Layout = new TableLayout(1, 2); //Default to one column and two rows
|
sl@34
|
1984 |
Callback = aCallback;
|
sl@34
|
1985 |
}
|
sl@34
|
1986 |
|
sl@34
|
1987 |
public string SessionId { get; set; }
|
sl@34
|
1988 |
public string Name { get; set; }
|
sl@67
|
1989 |
public List<DataField> Fields { get; set; }
|
sl@62
|
1990 |
public TableLayout Layout { get; set; }
|
sl@55
|
1991 |
public ICallback Callback { get; set; }
|
sl@34
|
1992 |
}
|
sl@0
|
1993 |
}
|