# HG changeset patch # User sl # Date 1414336617 -3600 # Node ID 2549a8055bd11a9fe65e8a77c5c23f892bdf47e0 # Parent fd0bb39a7818195f4209e1ed57ec75648843e9e3 Removing specific functions for setting text and bitmap. Now having a generic functions for setting any kind of fields. Thus bitmaps can now be set together with text fields in a single server call. diff -r fd0bb39a7818 -r 2549a8055bd1 Client/Client.cs --- a/Client/Client.cs Sat Oct 25 13:35:11 2014 +0200 +++ b/Client/Client.cs Sun Oct 26 16:16:57 2014 +0100 @@ -76,19 +76,14 @@ Channel.SetLayout(aLayout); } - public void SetText(DataField aField) + public void SetField(DataField aField) { - Channel.SetText(aField); + Channel.SetField(aField); } - public void SetTexts(System.Collections.Generic.IList aFields) + public void SetFields(System.Collections.Generic.IList aFields) { - Channel.SetTexts(aFields); - } - - public void SetBitmap(DataField aField) - { - Channel.SetBitmap(aField); + Channel.SetFields(aFields); } public int ClientCount() diff -r fd0bb39a7818 -r 2549a8055bd1 Client/MainForm.cs --- a/Client/MainForm.cs Sat Oct 25 13:35:11 2014 +0200 +++ b/Client/MainForm.cs Sun Oct 26 16:16:57 2014 +0100 @@ -134,7 +134,7 @@ //TextField top = new TextField(0, textBoxTop.Text, ContentAlignment.MiddleLeft); iTextFieldTop.Text = textBoxTop.Text; iTextFieldTop.Alignment = Alignment; - iClient.SetText(iTextFieldTop); + iClient.SetField(iTextFieldTop); } private void buttonSetText_Click(object sender, EventArgs e) @@ -143,7 +143,7 @@ //iClient.SetText(1, "Bottom"); //TextField top = new TextField(0, textBoxTop.Text, ContentAlignment.MiddleLeft); - iClient.SetTexts(new DataField[] + iClient.SetFields(new DataField[] { new DataField(0, textBoxTop.Text, Alignment), new DataField(1, textBoxBottom.Text, Alignment) @@ -179,7 +179,7 @@ DataField field = new DataField(0, bitmap); field.ColumnSpan = 2; - iClient.SetBitmap(field); + iClient.SetField(field); } private void buttonBitmapLayout_Click(object sender, EventArgs e) @@ -221,12 +221,11 @@ DataField field = new DataField(0, bitmap); //We want our bitmap field to span across two rows field.RowSpan = 2; - //Send it to our server - iClient.SetBitmap(field); //Set texts - iClient.SetTexts(new DataField[] + iClient.SetFields(new DataField[] { + field, new DataField(1, textBoxTop.Text, Alignment), new DataField(2, textBoxBottom.Text, Alignment) }); diff -r fd0bb39a7818 -r 2549a8055bd1 Interface/Interface.cs --- a/Interface/Interface.cs Sat Oct 25 13:35:11 2014 +0200 +++ b/Interface/Interface.cs Sun Oct 26 16:16:57 2014 +0100 @@ -126,8 +126,14 @@ public Bitmap Bitmap { get; set; } // - public bool HasBitmap { get{ return Bitmap!=null;} } - + public bool IsBitmap { get{ return Bitmap!=null;} } + // + public bool IsText { get { return Bitmap == null; } } + // + public bool IsSameLayout(DataField aField) + { + return (aField.ColumnSpan == ColumnSpan && aField.RowSpan == RowSpan); + } } /// @@ -156,27 +162,19 @@ void SetLayout(TableLayout aLayout); /// - /// Put the given text in the given field on your display. - /// Fields are often just lines of text. + /// Set the given field on your display. + /// Fields are often just lines of text or bitmaps. /// /// [OperationContract(IsOneWay = true)] - void SetText(DataField aField); + void SetField(DataField aField); /// - /// Allows a client to set multiple text fields at once. + /// Allows a client to set multiple fields at once. /// - /// + /// [OperationContract(IsOneWay = true)] - void SetTexts(System.Collections.Generic.IList aFields); - - /// - /// Put the given bitmap in the given field on your display. - /// Fields are often just lines of text. - /// - /// - [OperationContract(IsOneWay = true)] - void SetBitmap(DataField aBitmapField); + void SetFields(System.Collections.Generic.IList aFields); /// /// Provides the number of clients currently connected diff -r fd0bb39a7818 -r 2549a8055bd1 Server/MainForm.cs --- a/Server/MainForm.cs Sat Oct 25 13:35:11 2014 +0200 +++ b/Server/MainForm.cs Sun Oct 26 16:16:57 2014 +0100 @@ -26,9 +26,8 @@ public delegate void AddClientDelegate(string aSessionId, ICallback aCallback); public delegate void RemoveClientDelegate(string aSessionId); public delegate void SetTextDelegate(string SessionId, DataField aField); - public delegate void SetBitmapDelegate(string SessionId, DataField aField); public delegate void SetLayoutDelegate(string SessionId, TableLayout aLayout); - public delegate void SetTextsDelegate(string SessionId, System.Collections.Generic.IList aFields); + public delegate void SetFieldsDelegate(string SessionId, System.Collections.Generic.IList aFields); public delegate void SetClientNameDelegate(string aSessionId, string aName); @@ -803,43 +802,74 @@ /// /// /// - public void SetClientTextThreadSafe(string aSessionId, DataField aField) + public void SetClientFieldThreadSafe(string aSessionId, DataField aField) { if (this.InvokeRequired) { //Not in the proper thread, invoke ourselves - SetTextDelegate d = new SetTextDelegate(SetClientTextThreadSafe); + SetTextDelegate d = new SetTextDelegate(SetClientFieldThreadSafe); this.Invoke(d, new object[] { aSessionId, aField }); } else { - SetCurrentClient(aSessionId); - ClientData client = iClients[aSessionId]; - if (client != null) + //We are in the proper thread + //Call the non-thread-safe variant + SetClientField(aSessionId, aField); + } + } + + /// + /// + /// + /// + /// + private void SetClientField(string aSessionId, DataField aField) + { + SetCurrentClient(aSessionId); + ClientData client = iClients[aSessionId]; + if (client != null) + { + //Make sure all our fields are in place + while (client.Fields.Count < (aField.Index + 1)) { - //Make sure all our texts are in place - while (client.Fields.Count < (aField.Index + 1)) + //Add a text field with proper index + client.Fields.Add(new DataField(client.Fields.Count)); + } + + if (client.Fields[aField.Index].IsSameLayout(aField)) + { + //Same layout just update our field + client.Fields[aField.Index] = aField; + // + if (aField.IsText && tableLayoutPanel.Controls[aField.Index] is MarqueeLabel) { - //Add a text field with proper index - client.Fields.Add(new DataField(client.Fields.Count)); - } - client.Fields[aField.Index] = aField; - - //We are in the proper thread - if (tableLayoutPanel.Controls[aField.Index] is MarqueeLabel) - { + //Text field control already in place, just change the text MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[aField.Index]; label.Text = aField.Text; label.TextAlign = aField.Alignment; } + else if (aField.IsBitmap && tableLayoutPanel.Controls[aField.Index] is PictureBox) + { + //Bitmap field control already in place just change the bitmap + PictureBox pictureBox = (PictureBox)tableLayoutPanel.Controls[aField.Index]; + pictureBox.Image = aField.Bitmap; + } else { + //The requested control in our layout it not of the correct type //Wrong control type, re-create them all UpdateTableLayoutPanel(iCurrentClientData); } - // - UpdateClientTreeViewNode(client); } + else + { + //Different layout, need to rebuild it + client.Fields[aField.Index] = aField; + UpdateTableLayoutPanel(iCurrentClientData); + } + + // + UpdateClientTreeViewNode(client); } } @@ -847,52 +877,20 @@ /// /// /// - public void SetClientTextsThreadSafe(string aSessionId, System.Collections.Generic.IList aFields) + public void SetClientFieldsThreadSafe(string aSessionId, System.Collections.Generic.IList aFields) { if (this.InvokeRequired) { //Not in the proper thread, invoke ourselves - SetTextsDelegate d = new SetTextsDelegate(SetClientTextsThreadSafe); + SetFieldsDelegate d = new SetFieldsDelegate(SetClientFieldsThreadSafe); this.Invoke(d, new object[] { aSessionId, aFields }); } else { - SetCurrentClient(aSessionId); - //We are in the proper thread - ClientData client = iClients[aSessionId]; - if (client != null) + //Put each our text fields in a label control + foreach (DataField field in aFields) { - //Populate our client with the given text fields - foreach (DataField field in aFields) - { - //Make sure all our texts are in place - while (client.Fields.Count < (field.Index + 1)) - { - //Add a text field with proper index - client.Fields.Add(new DataField(client.Fields.Count)); - } - client.Fields[field.Index] = field; - } - //Put each our text fields in a label control - foreach (DataField field in aFields) - { - if (tableLayoutPanel.Controls[field.Index] is MarqueeLabel) - { - //Proper control type just update the text - MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[field.Index]; - label.Text = field.Text; - label.TextAlign = field.Alignment; - } - else - { - //Wrong control for the given field - //Update our layout thus re-creating our controls - UpdateTableLayoutPanel(iCurrentClientData); - break; //No need to keep on looping layout update will take care of everything - } - } - - UpdateClientTreeViewNode(client); + SetClientField(aSessionId, field); } } } @@ -901,53 +899,6 @@ /// /// /// - /// - public void SetClientBitmapThreadSafe(string aSessionId, DataField aField) - { - if (this.InvokeRequired) - { - //Not in the proper thread, invoke ourselves - SetBitmapDelegate d = new SetBitmapDelegate(SetClientBitmapThreadSafe); - this.Invoke(d, new object[] { aSessionId, aField }); - } - else - { - SetCurrentClient(aSessionId); - ClientData client = iClients[aSessionId]; - if (client != null) - { - //Make sure all our texts are in place - while (client.Fields.Count < (aField.Index + 1)) - { - //Add a text field with proper index - client.Fields.Add(new DataField(client.Fields.Count)); - } - - client.Fields[aField.Index] = aField; - - //We are in the proper thread - if (tableLayoutPanel.Controls[aField.Index] is PictureBox) - { - PictureBox pictureBox = (PictureBox)tableLayoutPanel.Controls[aField.Index]; - pictureBox.Image = aField.Bitmap; - } - else - { - //Wrong control type re-create them all - UpdateTableLayoutPanel(iCurrentClientData); - } - // - UpdateClientTreeViewNode(client); - } - } - } - - - - /// - /// - /// - /// /// public void SetClientNameThreadSafe(string aSessionId, string aName) { @@ -1025,7 +976,7 @@ //For each text add a new entry foreach (DataField field in aClient.Fields) { - if (!field.HasBitmap) + if (!field.IsBitmap) { DataField textField = (DataField)field; textsRoot.Nodes.Add(new TreeNode("[Text]" + textField.Text)); @@ -1238,7 +1189,7 @@ private Control CreateControlForDataField(DataField aField) { Control control=null; - if (!aField.HasBitmap) + if (!aField.IsBitmap) { MarqueeLabel label = new SharpDisplayManager.MarqueeLabel(); label.AutoEllipsis = true; diff -r fd0bb39a7818 -r 2549a8055bd1 Server/Session.cs --- a/Server/Session.cs Sat Oct 25 13:35:11 2014 +0200 +++ b/Server/Session.cs Sun Oct 26 16:16:57 2014 +0100 @@ -59,22 +59,16 @@ SharpDisplayManager.Program.iMainForm.SetClientLayoutThreadSafe(SessionId, aLayout); } - //From IDisplayService - public void SetTexts(System.Collections.Generic.IList aFields) + // + public void SetField(DataField aField) { - SharpDisplayManager.Program.iMainForm.SetClientTextsThreadSafe(SessionId, aFields); + SharpDisplayManager.Program.iMainForm.SetClientFieldThreadSafe(SessionId, aField); } - // - public void SetText(DataField aField) + //From IDisplayService + public void SetFields(System.Collections.Generic.IList aFields) { - SharpDisplayManager.Program.iMainForm.SetClientTextThreadSafe(SessionId, aField); - } - - // - public void SetBitmap(DataField aField) - { - SharpDisplayManager.Program.iMainForm.SetClientBitmapThreadSafe(SessionId, aField); + SharpDisplayManager.Program.iMainForm.SetClientFieldsThreadSafe(SessionId, aFields); } ///