1.1 --- a/Server/MainForm.cs Sat Oct 25 13:35:11 2014 +0200
1.2 +++ b/Server/MainForm.cs Sun Oct 26 16:16:57 2014 +0100
1.3 @@ -26,9 +26,8 @@
1.4 public delegate void AddClientDelegate(string aSessionId, ICallback aCallback);
1.5 public delegate void RemoveClientDelegate(string aSessionId);
1.6 public delegate void SetTextDelegate(string SessionId, DataField aField);
1.7 - public delegate void SetBitmapDelegate(string SessionId, DataField aField);
1.8 public delegate void SetLayoutDelegate(string SessionId, TableLayout aLayout);
1.9 - public delegate void SetTextsDelegate(string SessionId, System.Collections.Generic.IList<DataField> aFields);
1.10 + public delegate void SetFieldsDelegate(string SessionId, System.Collections.Generic.IList<DataField> aFields);
1.11 public delegate void SetClientNameDelegate(string aSessionId, string aName);
1.12
1.13
1.14 @@ -803,43 +802,74 @@
1.15 /// </summary>
1.16 /// <param name="aSessionId"></param>
1.17 /// <param name="aField"></param>
1.18 - public void SetClientTextThreadSafe(string aSessionId, DataField aField)
1.19 + public void SetClientFieldThreadSafe(string aSessionId, DataField aField)
1.20 {
1.21 if (this.InvokeRequired)
1.22 {
1.23 //Not in the proper thread, invoke ourselves
1.24 - SetTextDelegate d = new SetTextDelegate(SetClientTextThreadSafe);
1.25 + SetTextDelegate d = new SetTextDelegate(SetClientFieldThreadSafe);
1.26 this.Invoke(d, new object[] { aSessionId, aField });
1.27 }
1.28 else
1.29 {
1.30 - SetCurrentClient(aSessionId);
1.31 - ClientData client = iClients[aSessionId];
1.32 - if (client != null)
1.33 + //We are in the proper thread
1.34 + //Call the non-thread-safe variant
1.35 + SetClientField(aSessionId, aField);
1.36 + }
1.37 + }
1.38 +
1.39 + /// <summary>
1.40 + ///
1.41 + /// </summary>
1.42 + /// <param name="aSessionId"></param>
1.43 + /// <param name="aField"></param>
1.44 + private void SetClientField(string aSessionId, DataField aField)
1.45 + {
1.46 + SetCurrentClient(aSessionId);
1.47 + ClientData client = iClients[aSessionId];
1.48 + if (client != null)
1.49 + {
1.50 + //Make sure all our fields are in place
1.51 + while (client.Fields.Count < (aField.Index + 1))
1.52 {
1.53 - //Make sure all our texts are in place
1.54 - while (client.Fields.Count < (aField.Index + 1))
1.55 + //Add a text field with proper index
1.56 + client.Fields.Add(new DataField(client.Fields.Count));
1.57 + }
1.58 +
1.59 + if (client.Fields[aField.Index].IsSameLayout(aField))
1.60 + {
1.61 + //Same layout just update our field
1.62 + client.Fields[aField.Index] = aField;
1.63 + //
1.64 + if (aField.IsText && tableLayoutPanel.Controls[aField.Index] is MarqueeLabel)
1.65 {
1.66 - //Add a text field with proper index
1.67 - client.Fields.Add(new DataField(client.Fields.Count));
1.68 - }
1.69 - client.Fields[aField.Index] = aField;
1.70 -
1.71 - //We are in the proper thread
1.72 - if (tableLayoutPanel.Controls[aField.Index] is MarqueeLabel)
1.73 - {
1.74 + //Text field control already in place, just change the text
1.75 MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[aField.Index];
1.76 label.Text = aField.Text;
1.77 label.TextAlign = aField.Alignment;
1.78 }
1.79 + else if (aField.IsBitmap && tableLayoutPanel.Controls[aField.Index] is PictureBox)
1.80 + {
1.81 + //Bitmap field control already in place just change the bitmap
1.82 + PictureBox pictureBox = (PictureBox)tableLayoutPanel.Controls[aField.Index];
1.83 + pictureBox.Image = aField.Bitmap;
1.84 + }
1.85 else
1.86 {
1.87 + //The requested control in our layout it not of the correct type
1.88 //Wrong control type, re-create them all
1.89 UpdateTableLayoutPanel(iCurrentClientData);
1.90 }
1.91 - //
1.92 - UpdateClientTreeViewNode(client);
1.93 }
1.94 + else
1.95 + {
1.96 + //Different layout, need to rebuild it
1.97 + client.Fields[aField.Index] = aField;
1.98 + UpdateTableLayoutPanel(iCurrentClientData);
1.99 + }
1.100 +
1.101 + //
1.102 + UpdateClientTreeViewNode(client);
1.103 }
1.104 }
1.105
1.106 @@ -847,52 +877,20 @@
1.107 ///
1.108 /// </summary>
1.109 /// <param name="aTexts"></param>
1.110 - public void SetClientTextsThreadSafe(string aSessionId, System.Collections.Generic.IList<DataField> aFields)
1.111 + public void SetClientFieldsThreadSafe(string aSessionId, System.Collections.Generic.IList<DataField> aFields)
1.112 {
1.113 if (this.InvokeRequired)
1.114 {
1.115 //Not in the proper thread, invoke ourselves
1.116 - SetTextsDelegate d = new SetTextsDelegate(SetClientTextsThreadSafe);
1.117 + SetFieldsDelegate d = new SetFieldsDelegate(SetClientFieldsThreadSafe);
1.118 this.Invoke(d, new object[] { aSessionId, aFields });
1.119 }
1.120 else
1.121 {
1.122 - SetCurrentClient(aSessionId);
1.123 - //We are in the proper thread
1.124 - ClientData client = iClients[aSessionId];
1.125 - if (client != null)
1.126 + //Put each our text fields in a label control
1.127 + foreach (DataField field in aFields)
1.128 {
1.129 - //Populate our client with the given text fields
1.130 - foreach (DataField field in aFields)
1.131 - {
1.132 - //Make sure all our texts are in place
1.133 - while (client.Fields.Count < (field.Index + 1))
1.134 - {
1.135 - //Add a text field with proper index
1.136 - client.Fields.Add(new DataField(client.Fields.Count));
1.137 - }
1.138 - client.Fields[field.Index] = field;
1.139 - }
1.140 - //Put each our text fields in a label control
1.141 - foreach (DataField field in aFields)
1.142 - {
1.143 - if (tableLayoutPanel.Controls[field.Index] is MarqueeLabel)
1.144 - {
1.145 - //Proper control type just update the text
1.146 - MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[field.Index];
1.147 - label.Text = field.Text;
1.148 - label.TextAlign = field.Alignment;
1.149 - }
1.150 - else
1.151 - {
1.152 - //Wrong control for the given field
1.153 - //Update our layout thus re-creating our controls
1.154 - UpdateTableLayoutPanel(iCurrentClientData);
1.155 - break; //No need to keep on looping layout update will take care of everything
1.156 - }
1.157 - }
1.158 -
1.159 - UpdateClientTreeViewNode(client);
1.160 + SetClientField(aSessionId, field);
1.161 }
1.162 }
1.163 }
1.164 @@ -901,53 +899,6 @@
1.165 ///
1.166 /// </summary>
1.167 /// <param name="aSessionId"></param>
1.168 - /// <param name="aTextField"></param>
1.169 - public void SetClientBitmapThreadSafe(string aSessionId, DataField aField)
1.170 - {
1.171 - if (this.InvokeRequired)
1.172 - {
1.173 - //Not in the proper thread, invoke ourselves
1.174 - SetBitmapDelegate d = new SetBitmapDelegate(SetClientBitmapThreadSafe);
1.175 - this.Invoke(d, new object[] { aSessionId, aField });
1.176 - }
1.177 - else
1.178 - {
1.179 - SetCurrentClient(aSessionId);
1.180 - ClientData client = iClients[aSessionId];
1.181 - if (client != null)
1.182 - {
1.183 - //Make sure all our texts are in place
1.184 - while (client.Fields.Count < (aField.Index + 1))
1.185 - {
1.186 - //Add a text field with proper index
1.187 - client.Fields.Add(new DataField(client.Fields.Count));
1.188 - }
1.189 -
1.190 - client.Fields[aField.Index] = aField;
1.191 -
1.192 - //We are in the proper thread
1.193 - if (tableLayoutPanel.Controls[aField.Index] is PictureBox)
1.194 - {
1.195 - PictureBox pictureBox = (PictureBox)tableLayoutPanel.Controls[aField.Index];
1.196 - pictureBox.Image = aField.Bitmap;
1.197 - }
1.198 - else
1.199 - {
1.200 - //Wrong control type re-create them all
1.201 - UpdateTableLayoutPanel(iCurrentClientData);
1.202 - }
1.203 - //
1.204 - UpdateClientTreeViewNode(client);
1.205 - }
1.206 - }
1.207 - }
1.208 -
1.209 -
1.210 -
1.211 - /// <summary>
1.212 - ///
1.213 - /// </summary>
1.214 - /// <param name="aSessionId"></param>
1.215 /// <param name="aName"></param>
1.216 public void SetClientNameThreadSafe(string aSessionId, string aName)
1.217 {
1.218 @@ -1025,7 +976,7 @@
1.219 //For each text add a new entry
1.220 foreach (DataField field in aClient.Fields)
1.221 {
1.222 - if (!field.HasBitmap)
1.223 + if (!field.IsBitmap)
1.224 {
1.225 DataField textField = (DataField)field;
1.226 textsRoot.Nodes.Add(new TreeNode("[Text]" + textField.Text));
1.227 @@ -1238,7 +1189,7 @@
1.228 private Control CreateControlForDataField(DataField aField)
1.229 {
1.230 Control control=null;
1.231 - if (!aField.HasBitmap)
1.232 + if (!aField.IsBitmap)
1.233 {
1.234 MarqueeLabel label = new SharpDisplayManager.MarqueeLabel();
1.235 label.AutoEllipsis = true;