Subversion Repositories DevTools

Rev

Rev 2104 | Rev 2116 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2104 Rev 2106
Line 8... Line 8...
8
	/// <summary>
8
	/// <summary>
9
	/// Summary description for StyleContent.
9
	/// Summary description for StyleContent.
10
	/// </summary>
10
	/// </summary>
11
	public class StyleContent
11
	public class StyleContent
12
	{
12
	{
13
      private Word.Application WordApp = null;
13
		public static void initialise()
14
      private Word.Document WordDocument = null;
-
 
15
 
-
 
16
		public StyleContent(Word.Application wordApp, Word.Document wordDocument)
-
 
17
		{
14
		{
18
         WordApp = wordApp;
-
 
19
         WordDocument = wordDocument;
-
 
20
		}
15
		}
21
 
16
 
22
      public void AcceptWordAppAndDoc(Word.Application wordApp, Word.Document wordDocument)
-
 
23
      {
-
 
24
         WordApp = wordApp;
-
 
25
         WordDocument = wordDocument;
-
 
26
      }
-
 
27
 
17
 
28
      /// <summary>
18
      /// <summary>
29
      /// Creates a wdStyleTypeParagraph based style
19
      /// Creates a wdStyleTypeParagraph based style
30
      /// </summary>
20
      /// </summary>
31
      /// <param name="newStyleName"></param>
21
      /// <param name="newStyleName"></param>
32
      /// <param name="followingStyleName"></param>
22
      /// <param name="followingStyleName"></param>
33
      /// <param name="baseStyle"></param>
23
      /// <param name="baseStyle"></param>
34
      /// <returns></returns>
24
      /// <returns></returns>
35
      private Word.Style createParagrapghStyle(string newStyleName, 
25
      private static Word.Style createParagrapghStyle(string newStyleName, string followingStyleName, Word.Style baseStyle)
36
         string followingStyleName, 
-
 
37
         Word.Style baseStyle)
-
 
38
      {
26
      {
39
         Word.Style s = getStyle(newStyleName);
27
         Word.Style s = getStyle(newStyleName);
40
         if (s == null)
28
         if (s == null)
41
         {
29
         {
42
            object o_styleType = Word.WdStyleType.wdStyleTypeParagraph;
30
            object o_styleType = Word.WdStyleType.wdStyleTypeParagraph;
43
            s = WordDocument.Styles.Add(newStyleName, ref o_styleType);
31
            s = createWordDoc.WordDocument.Styles.Add(newStyleName, ref o_styleType);
44
 
32
 
45
            object o_baseStyle = baseStyle.NameLocal;
33
            object o_baseStyle = baseStyle.NameLocal;
46
            object o_followingStyle = followingStyleName;
34
            object o_followingStyle = followingStyleName;
47
            s.set_BaseStyle(ref o_baseStyle);
35
            s.set_BaseStyle(ref o_baseStyle);
48
            s.set_NextParagraphStyle(ref o_followingStyle);
36
            s.set_NextParagraphStyle(ref o_followingStyle);
Line 62... Line 50...
62
      /// Creates a wdStyleTypeCharacter based style
50
      /// Creates a wdStyleTypeCharacter based style
63
      /// </summary>
51
      /// </summary>
64
      /// <param name="newStyleName"></param>
52
      /// <param name="newStyleName"></param>
65
      /// <param name="baseStyle"></param>
53
      /// <param name="baseStyle"></param>
66
      /// <returns></returns>
54
      /// <returns></returns>
67
      private Word.Style createCharacterStyle(string newStyleName, Word.Style baseStyle)
55
      private static Word.Style createCharacterStyle(string newStyleName, Word.Style baseStyle)
68
      {
56
      {
69
         Word.Style s = getStyle(newStyleName);
57
         Word.Style s = getStyle(newStyleName);
70
         if (s == null)
58
         if (s == null)
71
         {
59
         {
72
            object o_styleType = Word.WdStyleType.wdStyleTypeCharacter;
60
            object o_styleType = Word.WdStyleType.wdStyleTypeCharacter;
73
            s = WordDocument.Styles.Add(newStyleName, ref o_styleType);
61
            s = createWordDoc.WordDocument.Styles.Add(newStyleName, ref o_styleType);
74
            object o_baseStyle = baseStyle.NameLocal;
62
            object o_baseStyle = baseStyle.NameLocal;
75
            s.set_BaseStyle(ref o_baseStyle);
63
            s.set_BaseStyle(ref o_baseStyle);
76
            s.Font = baseStyle.Font;
64
            s.Font = baseStyle.Font;
77
            s.LanguageID = Word.WdLanguageID.wdEnglishAUS;
65
            s.LanguageID = Word.WdLanguageID.wdEnglishAUS;
78
            s.NoProofing = 0;
66
            s.NoProofing = 0;
Line 84... Line 72...
84
      /// This method is designed to correct problems that have been reported in the styles
72
      /// This method is designed to correct problems that have been reported in the styles
85
      /// contained in the input templates being used. These can be corrected programmatically
73
      /// contained in the input templates being used. These can be corrected programmatically
86
      /// much quicker than waiting for a fix to be done to the templates and having them re-deployed
74
      /// much quicker than waiting for a fix to be done to the templates and having them re-deployed
87
      /// to the shared drive where MS-Word templates are retrieved from by most users.
75
      /// to the shared drive where MS-Word templates are retrieved from by most users.
88
      /// </summary>
76
      /// </summary>
89
      public void correctErrorsInTemplateStyles()
77
      public static void correctErrorsInTemplateStyles()
90
      {
78
      {
91
         // Go through the document's list levels and make sure any faults are fixed up
79
         // Go through the document's list levels and make sure any faults are fixed up
92
         int i = 0;
80
         int i = 0;
93
         int j = 0;
81
         int j = 0;
94
         foreach (Word.ListTemplate lt in WordDocument.ListTemplates)
82
         foreach (Word.ListTemplate lt in createWordDoc.WordDocument.ListTemplates)
95
         {
83
         {
96
            j = 0;
84
            j = 0;
97
            foreach (Word.ListLevel lv in lt.ListLevels)
85
            foreach (Word.ListLevel lv in lt.ListLevels)
98
            {
86
            {
99
               // An old ERG template had a flaw where the list numbering restarts were not 
87
               // An old ERG template had a flaw where the list numbering restarts were not 
Line 126... Line 114...
126
      /// <summary>
114
      /// <summary>
127
      /// This method creates a heading level style for heading levels 10 or above. Although MS-Word 
115
      /// This method creates a heading level style for heading levels 10 or above. Although MS-Word 
128
      /// does not support level numbering above 9, EA_DocGen can fake the heading number and use the
116
      /// does not support level numbering above 9, EA_DocGen can fake the heading number and use the
129
      /// styles created in this method for the fake headings.
117
      /// styles created in this method for the fake headings.
130
      /// </summary>
118
      /// </summary>
131
      public void createAdditionalHeadingLevelStyles()
119
      public static void createAdditionalHeadingLevelStyles()
132
      {
120
      {
133
         Word.Style s_Body1 = getStyle(EA_Constants.styleName_Body1);
121
         Word.Style s_Body1 = getStyle(EA_Constants.styleName_Body1);
134
         if (s_Body1 != null)
122
         if (s_Body1 != null)
135
         {
123
         {
136
            Word.Style h10 = createParagrapghStyle(EA_Constants.styleName_Heading10OrAbove, EA_Constants.styleName_Body1, s_Body1);
124
            Word.Style h10 = createParagrapghStyle(EA_Constants.styleName_Heading10OrAbove, EA_Constants.styleName_Body1, s_Body1);
137
            h10.Font.Size = 10;
125
            h10.Font.Size = 10;
138
            h10.Font.Bold = 1;
126
            h10.Font.Bold = 1;
139
            h10.ParagraphFormat.LeftIndent  = WordApp.CentimetersToPoints((float)0.0);
127
            h10.ParagraphFormat.LeftIndent  = createWordDoc.WordApp.CentimetersToPoints((float)0.0);
140
            h10.ParagraphFormat.SpaceAfter  = 6;
128
            h10.ParagraphFormat.SpaceAfter  = 6;
141
            h10.ParagraphFormat.SpaceBefore = 12;
129
            h10.ParagraphFormat.SpaceBefore = 12;
142
         }
130
         }
143
      }
131
      }
144
 
132
 
145
      /// <summary>
133
      /// <summary>
146
      /// Create the styles used to display class element details
134
      /// Create the styles used to display class element details
147
      /// </summary>
135
      /// </summary>
148
      public void createElementDetailsStyles()
136
      public static void createElementDetailsStyles()
149
      {
137
      {
150
         Word.Style s_Body1 = getStyle(EA_Constants.styleName_Body1);
138
         Word.Style s_Body1 = getStyle(EA_Constants.styleName_Body1);
151
         if (s_Body1 != null)
139
         if (s_Body1 != null)
152
         {
140
         {
153
            // A couple of indented body 1 styles
141
            // A couple of indented body 1 styles
154
            Word.Style s_B1_3_5 = createParagrapghStyle(EA_Constants.styleName_Body1_Left_3_5cm, EA_Constants.styleName_Body1_Left_3_5cm, s_Body1);
142
            Word.Style s_B1_3_5 = createParagrapghStyle(EA_Constants.styleName_Body1_Left_3_5cm, EA_Constants.styleName_Body1_Left_3_5cm, s_Body1);
155
            s_B1_3_5.ParagraphFormat.LeftIndent = WordApp.CentimetersToPoints((float)3.5);
143
            s_B1_3_5.ParagraphFormat.LeftIndent = createWordDoc.WordApp.CentimetersToPoints((float)3.5);
156
 
144
 
157
            Word.Style s_B1_4_5 = createParagrapghStyle(EA_Constants.styleName_Body1_Left_4_5cm, EA_Constants.styleName_Body1_Left_4_5cm, s_Body1);
145
            Word.Style s_B1_4_5 = createParagrapghStyle(EA_Constants.styleName_Body1_Left_4_5cm, EA_Constants.styleName_Body1_Left_4_5cm, s_Body1);
158
            s_B1_4_5.ParagraphFormat.LeftIndent = WordApp.CentimetersToPoints((float)4.5);
146
            s_B1_4_5.ParagraphFormat.LeftIndent = createWordDoc.WordApp.CentimetersToPoints((float)4.5);
159
 
147
 
160
            // A couple of pseudo-heading styles
148
            // A couple of pseudo-heading styles
161
            Word.Style s_B1_2_5_Italic = createParagrapghStyle(EA_Constants.styleName_Body1_Left_2_5cm_Italic, EA_Constants.styleName_Body1_Left_3_5cm, s_Body1);
149
            Word.Style s_B1_2_5_Italic = createParagrapghStyle(EA_Constants.styleName_Body1_Left_2_5cm_Italic, EA_Constants.styleName_Body1_Left_3_5cm, s_Body1);
162
            s_B1_2_5_Italic.ParagraphFormat.LeftIndent = WordApp.CentimetersToPoints((float)2.5);
150
            s_B1_2_5_Italic.ParagraphFormat.LeftIndent = createWordDoc.WordApp.CentimetersToPoints((float)2.5);
163
            s_B1_2_5_Italic.Font.Italic = 1;
151
            s_B1_2_5_Italic.Font.Italic = 1;
164
            s_B1_2_5_Italic.Font.Bold = 1;
152
            s_B1_2_5_Italic.Font.Bold = 1;
165
 
153
 
166
            Word.Style s_B1_3_5_Italic = createParagrapghStyle(EA_Constants.styleName_Body1_Left_3_5cm_Italic, EA_Constants.styleName_Body1_Left_4_5cm, s_Body1);
154
            Word.Style s_B1_3_5_Italic = createParagrapghStyle(EA_Constants.styleName_Body1_Left_3_5cm_Italic, EA_Constants.styleName_Body1_Left_4_5cm, s_Body1);
167
            s_B1_3_5_Italic.ParagraphFormat.LeftIndent = WordApp.CentimetersToPoints((float)3.5);
155
            s_B1_3_5_Italic.ParagraphFormat.LeftIndent = createWordDoc.WordApp.CentimetersToPoints((float)3.5);
168
            s_B1_3_5_Italic.Font.Italic = 1;
156
            s_B1_3_5_Italic.Font.Italic = 1;
169
            s_B1_3_5_Italic.Font.Bold = 1;
157
            s_B1_3_5_Italic.Font.Bold = 1;
170
 
158
 
171
            // Style for use when detailing parameter descriptions
159
            // Style for use when detailing parameter descriptions
172
            Word.Style s_ParamDesc = createParagrapghStyle(EA_Constants.stylename_Parameter_Description, EA_Constants.styleName_Body1, s_Body1);
160
            Word.Style s_ParamDesc = createParagrapghStyle(EA_Constants.stylename_Parameter_Description, EA_Constants.styleName_Body1, s_Body1);
173
            s_ParamDesc.ParagraphFormat.TabStops.ClearAll();
161
            s_ParamDesc.ParagraphFormat.TabStops.ClearAll();
174
            object alignment = Word.WdTabAlignment.wdAlignTabLeft;
162
            object alignment = Word.WdTabAlignment.wdAlignTabLeft;
175
            object leader = Word.WdTabLeader.wdTabLeaderSpaces;
163
            object leader = Word.WdTabLeader.wdTabLeaderSpaces;
176
            s_ParamDesc.ParagraphFormat.LeftIndent = WordApp.CentimetersToPoints((float)9.0);
164
            s_ParamDesc.ParagraphFormat.LeftIndent = createWordDoc.WordApp.CentimetersToPoints((float)9.0);
177
            s_ParamDesc.ParagraphFormat.TabStops.Add( WordApp.CentimetersToPoints((float)9.0), ref alignment, ref leader );
165
            s_ParamDesc.ParagraphFormat.TabStops.Add( createWordDoc.WordApp.CentimetersToPoints((float)9.0), ref alignment, ref leader );
178
            s_ParamDesc.ParagraphFormat.FirstLineIndent = WordApp.CentimetersToPoints((float)-5.5);
166
            s_ParamDesc.ParagraphFormat.FirstLineIndent = createWordDoc.WordApp.CentimetersToPoints((float)-5.5);
179
         }
167
         }
180
      }
168
      }
181
 
169
 
182
      /// <summary>
170
      /// <summary>
183
      /// Creates the styles needed for generating requirement documentation, if they do not
171
      /// Creates the styles needed for generating requirement documentation, if they do not
184
      /// already exist.
172
      /// already exist.
185
      /// </summary>
173
      /// </summary>
186
      public void createRequirementStyles()
174
      public static void createRequirementStyles()
187
      {
175
      {
188
         Word.Style s_Body1 = getStyle(EA_Constants.styleName_Body1);
176
         Word.Style s_Body1 = getStyle(EA_Constants.styleName_Body1);
189
         if (s_Body1 != null)
177
         if (s_Body1 != null)
190
         {
178
         {
191
            // APPROVED ///////////////////////////////////////////////////////////////////////////////////////////////
179
            // APPROVED ///////////////////////////////////////////////////////////////////////////////////////////////
Line 200... Line 188...
200
            {
188
            {
201
               s_ReqAppHdr = createParagrapghStyle(EA_Constants.styleName_ReqAppHdr, EA_Constants.styleName_ReqAppBody, s_Body1);
189
               s_ReqAppHdr = createParagrapghStyle(EA_Constants.styleName_ReqAppHdr, EA_Constants.styleName_ReqAppBody, s_Body1);
202
               if (s_ReqAppHdr != null)
190
               if (s_ReqAppHdr != null)
203
               {
191
               {
204
                  // Indent:Hanging: 2.5cm, Space After: 3pt, Keep with next, Tabs: 16.5cm, Right
192
                  // Indent:Hanging: 2.5cm, Space After: 3pt, Keep with next, Tabs: 16.5cm, Right
205
                  s_ReqAppHdr.ParagraphFormat.FirstLineIndent = WordApp.CentimetersToPoints((float)-2.5);
193
                  s_ReqAppHdr.ParagraphFormat.FirstLineIndent = createWordDoc.WordApp.CentimetersToPoints((float)-2.5);
206
                  s_ReqAppHdr.ParagraphFormat.SpaceAfter = 3;
194
                  s_ReqAppHdr.ParagraphFormat.SpaceAfter = 3;
207
                  s_ReqAppHdr.ParagraphFormat.KeepWithNext = (int)MsoTriState.msoTrue;
195
                  s_ReqAppHdr.ParagraphFormat.KeepWithNext = (int)MsoTriState.msoTrue;
208
                  s_ReqAppHdr.ParagraphFormat.TabStops.ClearAll();
196
                  s_ReqAppHdr.ParagraphFormat.TabStops.ClearAll();
209
                  object alignment = Word.WdTabAlignment.wdAlignTabRight;
197
                  object alignment = Word.WdTabAlignment.wdAlignTabRight;
210
                  object leader = Word.WdTabLeader.wdTabLeaderSpaces;
198
                  object leader = Word.WdTabLeader.wdTabLeaderSpaces;
211
                  s_ReqAppHdr.ParagraphFormat.TabStops.Add( WordApp.CentimetersToPoints((float)16.5), ref alignment, ref leader );
199
                  s_ReqAppHdr.ParagraphFormat.TabStops.Add( createWordDoc.WordApp.CentimetersToPoints((float)16.5), ref alignment, ref leader );
212
               }
200
               }
213
            }
201
            }
214
 
202
 
215
            // PROPOSED ///////////////////////////////////////////////////////////////////////////////////////////////
203
            // PROPOSED ///////////////////////////////////////////////////////////////////////////////////////////////
216
            Word.Style s_ReqPropBody = null;
204
            Word.Style s_ReqPropBody = null;
Line 274... Line 262...
274
      /// the style name given. Everything else I tried, didn't work, even code from Visual Basic
262
      /// the style name given. Everything else I tried, didn't work, even code from Visual Basic
275
      /// examples failed to work or even compile (once converted) in C#.
263
      /// examples failed to work or even compile (once converted) in C#.
276
      /// </summary>
264
      /// </summary>
277
      /// <param name="styleText"></param>
265
      /// <param name="styleText"></param>
278
      /// <returns></returns>
266
      /// <returns></returns>
279
      public Word.Style getStyle(string styleText)
267
      public static Word.Style getStyle(string styleText)
280
      {
268
      {
281
         foreach(Word.Style aStyle in WordDocument.Styles)
269
         foreach(Word.Style aStyle in createWordDoc.WordDocument.Styles)
282
         {
270
         {
283
            //MessageBox.Show( aStyle.NameLocal );
271
            //MessageBox.Show( aStyle.NameLocal );
284
            if (aStyle.NameLocal.Equals(styleText))
272
            if (aStyle.NameLocal.Equals(styleText))
285
            {
273
            {
286
               return aStyle;
274
               return aStyle;