Fixing field scroll reset issues whenever any field is updated.
Do not update layout when not needed anymore.
1.1 --- a/Interface/Interface.cs Sun Jun 21 14:15:11 2015 +0200
1.2 +++ b/Interface/Interface.cs Sat Jun 27 11:22:42 2015 +0200
1.3 @@ -50,6 +50,50 @@
1.4 }
1.5 }
1.6
1.7 + /// <summary>
1.8 + /// Compare two TableLayout object.
1.9 + /// </summary>
1.10 + /// <returns>Tells whether both layout are identical.</returns>
1.11 + public bool IsSameAs(TableLayout aTableLayout)
1.12 + {
1.13 + //Check rows and columns counts
1.14 + if (Columns.Count != aTableLayout.Columns.Count || Rows.Count != aTableLayout.Rows.Count)
1.15 + {
1.16 + return false;
1.17 + }
1.18 +
1.19 + //Compare each columns
1.20 + for (int i=0;i<Columns.Count;i++)
1.21 + {
1.22 + if (Columns[i].SizeType != aTableLayout.Columns[i].SizeType)
1.23 + {
1.24 + return false;
1.25 + }
1.26 +
1.27 + if (Columns[i].Width != aTableLayout.Columns[i].Width)
1.28 + {
1.29 + return false;
1.30 + }
1.31 + }
1.32 +
1.33 + //Compare each columns
1.34 + for (int i = 0; i < Rows.Count; i++)
1.35 + {
1.36 + if (Rows[i].SizeType != aTableLayout.Rows[i].SizeType)
1.37 + {
1.38 + return false;
1.39 + }
1.40 +
1.41 + if (Rows[i].Height != aTableLayout.Rows[i].Height)
1.42 + {
1.43 + return false;
1.44 + }
1.45 + }
1.46 +
1.47 + //Both rows and columns have the same content.
1.48 + return true;
1.49 + }
1.50 +
1.51 [DataMember]
1.52 public List<ColumnStyle> Columns { get; set; }
1.53
2.1 --- a/Server/MainForm.cs Sun Jun 21 14:15:11 2015 +0200
2.2 +++ b/Server/MainForm.cs Sat Jun 27 11:22:42 2015 +0200
2.3 @@ -1436,10 +1436,14 @@
2.4 ClientData client = iClients[aSessionId];
2.5 if (client != null)
2.6 {
2.7 - //Set our client layout then
2.8 - client.Layout = aLayout;
2.9 - //
2.10 - UpdateClientTreeViewNode(client);
2.11 + //Don't change a thing if the layout is the same
2.12 + if (!client.Layout.IsSameAs(aLayout))
2.13 + {
2.14 + //Set our client layout then
2.15 + client.Layout = aLayout;
2.16 + //
2.17 + UpdateClientTreeViewNode(client);
2.18 + }
2.19 }
2.20 }
2.21 }
2.22 @@ -1476,19 +1480,21 @@
2.23
2.24 ClientData client = iClients[aSessionId];
2.25 bool layoutChanged = false;
2.26 + bool contentChanged = true;
2.27
2.28 //Make sure all our fields are in place
2.29 while (client.Fields.Count < (aField.Index + 1))
2.30 {
2.31 - //Add a text field with proper index
2.32 + //Add a data field with proper index
2.33 client.Fields.Add(new DataField(client.Fields.Count));
2.34 layoutChanged = true;
2.35 }
2.36
2.37 + //Now that we know hour fields are in place just update that one
2.38 + client.Fields[aField.Index] = aField;
2.39 +
2.40 if (client.Fields[aField.Index].IsSameLayout(aField))
2.41 {
2.42 - //Same layout just update our field
2.43 - client.Fields[aField.Index] = aField;
2.44 //If we are updating a field in our current client we need to update it in our panel
2.45 if (aSessionId == iCurrentClientSessionId)
2.46 {
2.47 @@ -1496,13 +1502,13 @@
2.48 {
2.49 //Text field control already in place, just change the text
2.50 MarqueeLabel label = (MarqueeLabel)tableLayoutPanel.Controls[aField.Index];
2.51 - layoutChanged = (label.Text != aField.Text || label.TextAlign != aField.Alignment);
2.52 + contentChanged = (label.Text != aField.Text || label.TextAlign != aField.Alignment);
2.53 label.Text = aField.Text;
2.54 label.TextAlign = aField.Alignment;
2.55 }
2.56 else if (aField.IsBitmap && aField.Index < tableLayoutPanel.Controls.Count && tableLayoutPanel.Controls[aField.Index] is PictureBox)
2.57 {
2.58 - layoutChanged = true; //TODO: Bitmap comp or should we leave that to clients?
2.59 + contentChanged = true; //TODO: Bitmap comp or should we leave that to clients?
2.60 //Bitmap field control already in place just change the bitmap
2.61 PictureBox pictureBox = (PictureBox)tableLayoutPanel.Controls[aField.Index];
2.62 pictureBox.Image = aField.Bitmap;
2.63 @@ -1514,21 +1520,24 @@
2.64 }
2.65 }
2.66 else
2.67 - {
2.68 + {
2.69 layoutChanged = true;
2.70 - //Different layout, need to rebuild it
2.71 - client.Fields[aField.Index] = aField;
2.72 }
2.73
2.74 - //
2.75 - if (layoutChanged)
2.76 + //If either content or layout changed we need to update our tree view to reflect the changes
2.77 + if (contentChanged || layoutChanged)
2.78 {
2.79 UpdateClientTreeViewNode(client);
2.80 - //Our layout has changed, if we are already the current client we need to update our panel
2.81 - if (aSessionId == iCurrentClientSessionId)
2.82 + //
2.83 + if (layoutChanged)
2.84 {
2.85 - //Apply layout and set data fields.
2.86 - UpdateTableLayoutPanel(iCurrentClientData);
2.87 + Debug.Print("Layout changed");
2.88 + //Our layout has changed, if we are already the current client we need to update our panel
2.89 + if (aSessionId == iCurrentClientSessionId)
2.90 + {
2.91 + //Apply layout and set data fields.
2.92 + UpdateTableLayoutPanel(iCurrentClientData);
2.93 + }
2.94 }
2.95 }
2.96
2.97 @@ -1592,6 +1601,8 @@
2.98 /// <param name="aClient"></param>
2.99 private void UpdateClientTreeViewNode(ClientData aClient)
2.100 {
2.101 + Debug.Print("UpdateClientTreeViewNode");
2.102 +
2.103 if (aClient == null)
2.104 {
2.105 return;
2.106 @@ -1673,6 +1684,8 @@
2.107 /// <param name="aLayout"></param>
2.108 private void UpdateTableLayoutPanel(ClientData aClient)
2.109 {
2.110 + Debug.Print("UpdateClientTreeViewNode");
2.111 +
2.112 if (aClient == null)
2.113 {
2.114 //Just drop it
3.1 --- a/Server/SharpDisplayManager.csproj Sun Jun 21 14:15:11 2015 +0200
3.2 +++ b/Server/SharpDisplayManager.csproj Sat Jun 27 11:22:42 2015 +0200
3.3 @@ -32,7 +32,7 @@
3.4 <CreateWebPageOnPublish>true</CreateWebPageOnPublish>
3.5 <WebPage>index.htm</WebPage>
3.6 <OpenBrowserOnPublish>false</OpenBrowserOnPublish>
3.7 - <ApplicationRevision>1</ApplicationRevision>
3.8 + <ApplicationRevision>2</ApplicationRevision>
3.9 <ApplicationVersion>0.5.0.%2a</ApplicationVersion>
3.10 <UseApplicationTrust>false</UseApplicationTrust>
3.11 <CreateDesktopShortcut>true</CreateDesktopShortcut>