# HG changeset patch # User sl # Date 1411394666 -7200 # Node ID ac698f4e1b360d29258fad7eae1d58238d163a86 # Parent 5a24e79384be694232f0c156b0e3866b043a240b Adding the possibility for clients to define a basic layout. diff -r 5a24e79384be -r ac698f4e1b36 Client/Client.cs --- a/Client/Client.cs Mon Sep 22 13:21:00 2014 +0200 +++ b/Client/Client.cs Mon Sep 22 16:04:26 2014 +0200 @@ -70,6 +70,12 @@ Channel.SetName(aClientName); } + + public void SetLayout(TableLayout aLayout) + { + Channel.SetLayout(aLayout); + } + public void SetText(TextField aTextField) { Channel.SetText(aTextField); diff -r 5a24e79384be -r ac698f4e1b36 Client/MainForm.Designer.cs --- a/Client/MainForm.Designer.cs Mon Sep 22 13:21:00 2014 +0200 +++ b/Client/MainForm.Designer.cs Mon Sep 22 16:04:26 2014 +0200 @@ -35,6 +35,7 @@ this.buttonAlignCenter = new System.Windows.Forms.Button(); this.buttonAlignLeft = new System.Windows.Forms.Button(); this.buttonSetTopText = new System.Windows.Forms.Button(); + this.buttonLayoutUpdate = new System.Windows.Forms.Button(); this.SuspendLayout(); // // buttonSetText @@ -101,11 +102,22 @@ this.buttonSetTopText.UseVisualStyleBackColor = true; this.buttonSetTopText.Click += new System.EventHandler(this.buttonSetTopText_Click); // + // buttonLayoutUpdate + // + this.buttonLayoutUpdate.Location = new System.Drawing.Point(176, 131); + this.buttonLayoutUpdate.Name = "buttonLayoutUpdate"; + this.buttonLayoutUpdate.Size = new System.Drawing.Size(75, 23); + this.buttonLayoutUpdate.TabIndex = 25; + this.buttonLayoutUpdate.Text = "Layout 2x2"; + this.buttonLayoutUpdate.UseVisualStyleBackColor = true; + this.buttonLayoutUpdate.Click += new System.EventHandler(this.buttonLayoutUpdate_Click); + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(443, 252); + this.Controls.Add(this.buttonLayoutUpdate); this.Controls.Add(this.buttonSetTopText); this.Controls.Add(this.buttonAlignRight); this.Controls.Add(this.buttonAlignCenter); @@ -131,6 +143,7 @@ private System.Windows.Forms.Button buttonAlignCenter; private System.Windows.Forms.Button buttonAlignLeft; private System.Windows.Forms.Button buttonSetTopText; + private System.Windows.Forms.Button buttonLayoutUpdate; } } diff -r 5a24e79384be -r ac698f4e1b36 Client/MainForm.cs --- a/Client/MainForm.cs Mon Sep 22 13:21:00 2014 +0200 +++ b/Client/MainForm.cs Mon Sep 22 16:04:26 2014 +0200 @@ -149,5 +149,11 @@ new TextField(1, textBoxBottom.Text, Alignment) }); } + + private void buttonLayoutUpdate_Click(object sender, EventArgs e) + { + TableLayout layout = new TableLayout(2,2); + iClient.SetLayout(layout); + } } } diff -r 5a24e79384be -r ac698f4e1b36 Interface/Interface.cs --- a/Interface/Interface.cs Mon Sep 22 13:21:00 2014 +0200 +++ b/Interface/Interface.cs Mon Sep 22 16:04:26 2014 +0200 @@ -19,7 +19,57 @@ /// TextField can be send to our server to be displayed on the screen. /// [DataContract] - public class TextField + public class TableLayout + { + public TableLayout() + { + ColumnCount = 0; + RowCount = 0; + //Alignment = ContentAlignment.MiddleLeft; + } + + public TableLayout(int aColumnCount, int aRowCount) + { + ColumnCount = aColumnCount; + RowCount = aRowCount; + } + + [DataMember] + public int ColumnCount { get; set; } + + [DataMember] + public int RowCount { get; set; } + + [DataMember] + public List Cells { get; set; } + } + + /// + /// + /// + [DataContract] + public class DataField + { + [DataMember] + public int Column { get; set; } + + [DataMember] + public int Row { get; set; } + + [DataMember] + public int ColumnSpan { get; set; } + + [DataMember] + public int RowSpan { get; set; } + + } + + + /// + /// TextField can be send to our server to be displayed on the screen. + /// + [DataContract] + public class TextField : DataField { public TextField() { @@ -64,6 +114,13 @@ [OperationContract(IsOneWay = true)] void SetName(string aClientName); + + /// + /// + /// + [OperationContract(IsOneWay = true)] + void SetLayout(TableLayout aLayout); + /// /// Put the given text in the given field on your display. /// Fields are often just lines of text. diff -r 5a24e79384be -r ac698f4e1b36 Server/MainForm.cs --- a/Server/MainForm.cs Mon Sep 22 13:21:00 2014 +0200 +++ b/Server/MainForm.cs Mon Sep 22 16:04:26 2014 +0200 @@ -22,6 +22,14 @@ //Types declarations public delegate uint ColorProcessingDelegate(int aX, int aY, uint aPixel); public delegate int CoordinateTranslationDelegate(System.Drawing.Bitmap aBmp, int aInt); + //Delegates are used for our thread safe method + public delegate void AddClientDelegate(string aSessionId, ICallback aCallback); + public delegate void RemoveClientDelegate(string aSessionId); + public delegate void SetTextDelegate(string SessionId, TextField aTextField); + public delegate void SetLayoutDelegate(string SessionId, TableLayout aLayout); + public delegate void SetTextsDelegate(string SessionId, System.Collections.Generic.IList aTextFields); + public delegate void SetClientNameDelegate(string aSessionId, string aName); + /// /// Our Display manager main form @@ -691,13 +699,6 @@ } - //Delegates are used for our thread safe method - public delegate void AddClientDelegate(string aSessionId, ICallback aCallback); - public delegate void RemoveClientDelegate(string aSessionId); - public delegate void SetTextDelegate(string SessionId, TextField aTextField); - public delegate void SetTextsDelegate(string SessionId, System.Collections.Generic.IList aTextFields); - public delegate void SetClientNameDelegate(string aSessionId, string aName); - /// /// @@ -759,6 +760,32 @@ /// /// /// + /// + /// + public void SetClientLayoutThreadSafe(string aSessionId, TableLayout aLayout) + { + if (this.InvokeRequired) + { + //Not in the proper thread, invoke ourselves + SetLayoutDelegate d = new SetLayoutDelegate(SetClientLayoutThreadSafe); + this.Invoke(d, new object[] { aSessionId, aLayout }); + } + else + { + ClientData client = iClients[aSessionId]; + if (client != null) + { + client.Layout = aLayout; + UpdateTableLayoutPanel(client.Layout.ColumnCount, client.Layout.RowCount); + // + UpdateClientTreeViewNode(client); + } + } + } + + /// + /// + /// /// /// public void SetTextThreadSafe(string aSessionId, TextField aTextField) @@ -932,8 +959,7 @@ { if (tableLayoutPanel.RowCount < 6) { - RecreateTableLayoutPanel(tableLayoutPanel.ColumnCount, tableLayoutPanel.RowCount + 1); - CheckFontHeight(); + UpdateTableLayoutPanel(tableLayoutPanel.ColumnCount, tableLayoutPanel.RowCount + 1); } } @@ -941,13 +967,29 @@ { if (tableLayoutPanel.RowCount > 1) { - RecreateTableLayoutPanel(tableLayoutPanel.ColumnCount, tableLayoutPanel.RowCount - 1); - CheckFontHeight(); + UpdateTableLayoutPanel(tableLayoutPanel.ColumnCount, tableLayoutPanel.RowCount - 1); } UpdateTableLayoutRowStyles(); } + private void buttonAddColumn_Click(object sender, EventArgs e) + { + if (tableLayoutPanel.ColumnCount < 8) + { + UpdateTableLayoutPanel(tableLayoutPanel.ColumnCount + 1, tableLayoutPanel.RowCount); + } + } + + private void buttonRemoveColumn_Click(object sender, EventArgs e) + { + if (tableLayoutPanel.ColumnCount > 1) + { + UpdateTableLayoutPanel(tableLayoutPanel.ColumnCount - 1, tableLayoutPanel.RowCount); + } + } + + /// /// Update our table layout row styles to make sure each rows have similar height /// @@ -966,7 +1008,7 @@ /// /// /// - private void RecreateTableLayoutPanel(int aColumn, int aRow) + private void UpdateTableLayoutPanel(int aColumn, int aRow) { tableLayoutPanel.Controls.Clear(); tableLayoutPanel.RowStyles.Clear(); @@ -1018,24 +1060,8 @@ tableLayoutPanel.Controls.Add(control, i, j); } } - } - private void buttonAddColumn_Click(object sender, EventArgs e) - { - if (tableLayoutPanel.ColumnCount < 8) - { - RecreateTableLayoutPanel(tableLayoutPanel.ColumnCount + 1, tableLayoutPanel.RowCount); - //CheckFontHeight(); - } - } - - private void buttonRemoveColumn_Click(object sender, EventArgs e) - { - if (tableLayoutPanel.ColumnCount > 1) - { - RecreateTableLayoutPanel(tableLayoutPanel.ColumnCount - 1, tableLayoutPanel.RowCount); - //CheckFontHeight(); - } + CheckFontHeight(); } private void buttonAlignLeft_Click(object sender, EventArgs e) @@ -1125,12 +1151,14 @@ SessionId = aSessionId; Name = ""; Texts = new List(); + Layout = new TableLayout(1, 2); //Default to one column and two rows Callback = aCallback; } public string SessionId { get; set; } public string Name { get; set; } public List Texts { get; set; } + public TableLayout Layout { get; set; } public ICallback Callback { get; set; } } } diff -r 5a24e79384be -r ac698f4e1b36 Server/Session.cs --- a/Server/Session.cs Mon Sep 22 13:21:00 2014 +0200 +++ b/Server/Session.cs Mon Sep 22 16:04:26 2014 +0200 @@ -13,9 +13,9 @@ /// Implement our display services. /// Each client connection has such a session object server side. /// - [ServiceBehavior( + [ServiceBehavior( ConcurrencyMode = ConcurrencyMode.Multiple, - InstanceContextMode = InstanceContextMode.PerSession + InstanceContextMode = InstanceContextMode.PerSession )] class Session : IService, IDisposable { @@ -38,18 +38,6 @@ Trace.TraceInformation("Server session closing."); SharpDisplayManager.Program.iMainForm.RemoveClientThreadSafe(SessionId); } - - //From IDisplayService - public void SetTexts(System.Collections.Generic.IList aTextFields) - { - SharpDisplayManager.Program.iMainForm.SetTextsThreadSafe(SessionId, aTextFields); - } - - // - public void SetText(TextField aTextField) - { - SharpDisplayManager.Program.iMainForm.SetTextThreadSafe(SessionId, aTextField); - } // public void SetName(string aClientName) @@ -66,13 +54,31 @@ //callback.OnConnected(); } + public void SetLayout(TableLayout aLayout) + { + SharpDisplayManager.Program.iMainForm.SetClientLayoutThreadSafe(SessionId, aLayout); + } + + //From IDisplayService + public void SetTexts(System.Collections.Generic.IList aTextFields) + { + SharpDisplayManager.Program.iMainForm.SetTextsThreadSafe(SessionId, aTextFields); + } + + // + public void SetText(TextField aTextField) + { + SharpDisplayManager.Program.iMainForm.SetTextThreadSafe(SessionId, aTextField); + } + + /// public int ClientCount() { return SharpDisplayManager.Program.iMainForm.iClients.Count; } - + }