From df3407938694e8f591372c6e33361ce394d80c90 Mon Sep 17 00:00:00 2001 From: Rich Date: Fri, 18 Dec 2009 18:36:37 +0000 Subject: [PATCH] Added tables to movement logic Improved table layout --- PROMS/Volian.Controls.Library/StepPanel.cs | 6 +- PROMS/Volian.Controls.Library/StepRTB.cs | 102 ++++++++++++++------- 2 files changed, 71 insertions(+), 37 deletions(-) diff --git a/PROMS/Volian.Controls.Library/StepPanel.cs b/PROMS/Volian.Controls.Library/StepPanel.cs index df162771..f2859df2 100644 --- a/PROMS/Volian.Controls.Library/StepPanel.cs +++ b/PROMS/Volian.Controls.Library/StepPanel.cs @@ -18,9 +18,7 @@ namespace Volian.Controls.Library /// Procedure Item Info - Top ItemInfo /// private ItemInfo _MyProcedureItemInfo; - /// - /// This is not correct. There should be a dictionary of Section Layouts - /// + // TODO: This is not correct. There should be a dictionary of Section Layouts private StepSectionLayoutData _MyStepSectionLayoutData; /// /// Lookup Table to convert ItemInfo.ItemID to StepItem @@ -642,6 +640,7 @@ namespace Volian.Controls.Library if (ii.RNOs != null && ii.RNOLevel >= ii.ColumnMode) return BottomPart(ii.RNOs[0]); if (ii.Sections != null) return BottomPart(ii.Sections[0].LastSibling); if (ii.Steps != null) return BottomPart(ii.Steps[0].LastSibling); + if (ii.Tables != null) return BottomPart(ii.Tables[0].LastSibling); return ii; } /// @@ -721,6 +720,7 @@ namespace Volian.Controls.Library // Subitems - go to top part of subitem // (the lookAtSub prevented looping within a substep group at same level) if (lookAtSub && ii.Steps != null) return TopPart(ii.Steps[0]); + if (lookAtSub && ii.Tables != null) return TopPart(ii.Tables[0]); // RNOs: Use PMode (column) if (lookAtRNO && ii.RNOs != null && ii.RNOLevel >= ii.ColumnMode) return TopPart(ii.RNOs[0]); // Nextsibling - go to top part of sibling diff --git a/PROMS/Volian.Controls.Library/StepRTB.cs b/PROMS/Volian.Controls.Library/StepRTB.cs index ffcfcee3..778d143f 100644 --- a/PROMS/Volian.Controls.Library/StepRTB.cs +++ b/PROMS/Volian.Controls.Library/StepRTB.cs @@ -68,6 +68,12 @@ namespace Volian.Controls.Library } #endregion #region Properties and Variables + private static FontFamily _MyFontFamily = null; + public static FontFamily MyFontFamily + { + get { return StepRTB._MyFontFamily; } + set { StepRTB._MyFontFamily = value; } + } // use newer rich text box.... //[DllImport("kernel32.dll", CharSet = CharSet.Auto)] //static extern IntPtr LoadLibrary(string lpFileName); @@ -164,6 +170,17 @@ namespace Volian.Controls.Library private string _origRTF; public void RTBFillIn(bool edit) { + if (edit && _MyStepItem != null && (_MyItemInfo.IsTable || _MyItemInfo.IsFigure)) + { + // First get ColR + int colR = MyStepItem.MyStepPanel.ToDisplay(MyStepItem.MyStepSectionLayoutData.ColRTable, MyItemInfo.ColumnMode); + // Second get WidS + int widS = /* _WidthAdjust + borderWidth + */ MyStepItem.MyStepPanel.ToDisplay(MyStepItem.MyStepSectionLayoutData.WidSTableEdit, MyItemInfo.ColumnMode); + //int wNew = _MyStepItem.MyStepPanel.ToDisplay(_MyStepItem.MyStepSectionLayoutData.WidT); + int wNew = 70 + widS + colR * MyItemInfo.ColumnMode; + if(wNew > _MyStepItem.ItemWidth) + _MyStepItem.ItemWidth= wNew; + } _InitializingRTB = true; _SelectedRtfSB.Remove(0, _SelectedRtfSB.Length); DisplayText vlntxt = new DisplayText(_MyItemInfo, EpMode, VwMode, !edit, FieldToEdit); @@ -177,16 +194,25 @@ namespace Volian.Controls.Library #if(DEBUG) // Use Times New Roman for Debugging //Font = new Font("Times New Roman", 14, FontStyle.Regular); - Font = _origDisplayText.TextFont.WindowsFont; - //Font = new Font("Times New Roman", _origDisplayText.TextFont.WindowsFont.Size, _origDisplayText.TextFont.WindowsFont.Style); + //Font = _origDisplayText.TextFont.WindowsFont; + Font formatFont = _origDisplayText.TextFont.WindowsFont; + if (_MyItemInfo.IsTable || _MyItemInfo.IsFigure) + Font = formatFont; + else + Font = new Font(_MyFontFamily == null ? formatFont.FontFamily : _MyFontFamily, formatFont.Size, formatFont.Style); #elif(RELEASE) Font = _origDisplayText.TextFont.WindowsFont; // font defined in plant's format #else //DEMO // Comment this out for DEMO to customer // UN-Comment this for testing //Font = _origDisplayText.TextFont.WindowsFont; // font defined in plant's format + Font formatFont = _origDisplayText.TextFont.WindowsFont; + if (_MyItemInfo.IsTable || _MyItemInfo.IsFigure) + Font = formatFont; + else + Font = new Font("Bookman Old Style", formatFont.Size, formatFont.Style); #endif - Text = ""; // Initialize text before add text + Text = ""; // Initialize text before add text // IMPORTANT: SetLineSpacing must be set before Links, otherwise it // was confusing the 'handle' of the rtf box. RTBAPI.SetLineSpacing(this, RTBAPI.ParaSpacing.PFS_EXACT); @@ -221,18 +247,18 @@ namespace Volian.Controls.Library } AddEventHandlers(); } - else - { - if (_MyStepItem != null && (_MyItemInfo.IsTable || _MyItemInfo.IsFigure)) - { - //AdjustWidthForContent(); - _MyStepItem.ItemWidth = (int)_MyStepItem.TableWidth(Font, Text); - } - } + //else + //{ + // if (_MyStepItem != null && (_MyItemInfo.IsTable || _MyItemInfo.IsFigure)) + // { + // //_MyStepItem.ItemWidth = (int)_MyStepItem.TableWidth(Font, Text,false); + // _MyStepItem.ItemWidth = _MyStepItem.MyStepPanel.ToDisplay(_MyStepItem.MyStepSectionLayoutData.WidT); + // } + //} _origRTF = Rtf; _InitializingRTB = false; _MyItemInfo.MyConfig.PropertyChanged += new PropertyChangedEventHandler(MyConfig_PropertyChanged); - AdjustSizeForContents(); // TODO: this is not quite right yet. + AdjustSizeForContents(!edit); // TODO: this is not quite right yet. } private bool _ProcessKeystrokes = true; public bool ProcessKeystrokes @@ -276,7 +302,7 @@ namespace Volian.Controls.Library set { _ContentsRectangle = value; - AdjustSizeForContents(); + AdjustSizeForContents(false); } } public Size ContentsSize @@ -290,7 +316,7 @@ namespace Volian.Controls.Library set { _AdjustSize = value; - AdjustSizeForContents(); + AdjustSizeForContents(false); } } public System.Windows.Forms.AutoScaleMode AutoScaleMode; @@ -360,7 +386,6 @@ namespace Volian.Controls.Library this.MouseLeave += new EventHandler(StepRTB_MouseLeave); this.SelectionChanged +=new EventHandler(StepRTB_SelectionChanged); } - private void SetUp() { this.Height = 10; // initialize the height to 10, the default height was too big for the cells in grid tables @@ -776,16 +801,19 @@ namespace Volian.Controls.Library { if (HeightChanged != null) HeightChanged(sender, args); } - private void AdjustSizeForContents() + private void AdjustSizeForContents(bool adjustWidth) { - Size offset = Size - ClientSize; - int widthNew = ContentsSize.Width + offset.Width + AdjustSize.Width; - int heightNew = ContentsSize.Height + offset.Height + AdjustSize.Height; - Size szNew = new Size(widthNew,heightNew); - if (this.Size != szNew && !_InitializingRTB) + if (!_InitializingRTB) { - this.Size = szNew; - OnHeightChanged(this, new EventArgs()); + Size offset = Size - ClientSize; + int widthNew = ContentsSize.Width + offset.Width + AdjustSize.Width ; + int heightNew = ContentsSize.Height + offset.Height + AdjustSize.Height; + Size szNew = new Size((adjustWidth ? widthNew : (widthNew > Width ? widthNew : Width)), heightNew); + if (this.Size != szNew) + { + this.Size = szNew; + OnHeightChanged(this, new EventArgs()); + } } } private float GetStringWidth(string strMeasureString) @@ -1232,7 +1260,6 @@ namespace Volian.Controls.Library } #endregion #region KeyboardHandling - void StepRTB_KeyUp(object sender, KeyEventArgs e) { if (e.Control) @@ -1305,7 +1332,6 @@ namespace Volian.Controls.Library default: break; } - } private bool IsControlChar = false; private bool _SendBackSpace = false; @@ -2069,35 +2095,42 @@ namespace Volian.Controls.Library } public void OutlineTable(bool withBorder) { + if (_MyStepItem != null) // Set the width based upon the contents + _MyStepItem.ItemWidth = (int)_MyStepItem.TableWidth(Font, Text, true); // Determine the number of characters per line int w = MaxCharacterWidth(); + //Console.WriteLine("Before {0},{1}\n{2}\n{3}", Width, w, Rtf, Text); + Console.WriteLine("'Row','last','Start','w2','w','w3','offset1','offset2'"); string horzLine = Repeat(withBorder ? @"\u9472?" : " ", w); // Determine the number of lines int l = Lines.Length; for (int row = 0; row < Lines.Length; row++) { //int spaces = w - line.Length; - int offset = GetFirstCharIndexFromLine(row); - Select(offset, 0); + int offset1 = GetFirstCharIndexFromLine(row); + Select(offset1, 0); string cleanLine = RemoveLinkComments(Lines[row]); int w2 = Lines[row].Length; int w3 = cleanLine.Length; - offset = SelectionStart + w2 + (w - w3) + 1; + int offset2 = SelectionStart + w2 + (w - w3) + 1; + int selStart = SelectionStart; SelectedRtf = RtfPrefix + (withBorder ? @"\u9474?" : " ") + "}"; Select(SelectionStart + w2, 0); if (w3 < w) { SelectedText = "".PadRight(w - w3); - Select(offset, 0); + Select(offset2, 0); } SelectedRtf = RtfPrefix + (withBorder ? @"\u9474?" : " ") + "}"; + Console.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7}", row, selStart, SelectionStart, w2, w, w3, offset1, offset2); } // Add the top line - if (_MyStepItem != null) - { - //AdjustWidthForContent(); - _MyStepItem.ItemWidth = (int)_MyStepItem.TableWidth(Font, Text); - } + //if (_MyStepItem != null) + //{ + // Console.WriteLine("Char[0]={0:X}", (int)(Text[0])); + // _MyStepItem.ItemWidth = (int)_MyStepItem.TableWidth(Font, Text.Replace('\u2502','-'), false); + //} + //Console.WriteLine("After Edges\n{0}\n{1}", Rtf, Text); Select(0, 0); SelectedRtf = RtfPrefix + (withBorder ? @"\u9484?" : " ") + horzLine + (withBorder ? @"\u9488?\par " : @" \par ") + "}"; // Add the bottom line @@ -2105,6 +2138,7 @@ namespace Volian.Controls.Library ContentsResized += new ContentsResizedEventHandler(StepRTB_ContentsResized); SelectedRtf = RtfPrefix + (withBorder ? @"\par\u9492?" : @"\par ") + horzLine + (withBorder ? @"\u9496?" : @" ") + "}"; ContentsResized -= new ContentsResizedEventHandler(StepRTB_ContentsResized); + //Console.WriteLine("After Top and Bottom\n{0}\n{1}", Rtf, Text); ReplaceLinesInTable(withBorder); }