Subversion Repositories DevTools

Rev

Rev 2132 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2094 ghuddy 1
using System;
2136 brianf 2
using Microsoft.Office.Interop.Word;
2094 ghuddy 3
using Microsoft.Office.Core;
4
 
5
 
6
namespace EA_DocGen
7
{
8
	/// <summary>
9
	/// Summary description for StyleContent.
10
	/// </summary>
11
	public class StyleContent
12
	{
2106 ghuddy 13
		public static void initialise()
2094 ghuddy 14
		{
15
		}
16
 
17
 
18
      /// <summary>
19
      /// Creates a wdStyleTypeParagraph based style
20
      /// </summary>
21
      /// <param name="newStyleName"></param>
22
      /// <param name="followingStyleName"></param>
23
      /// <param name="baseStyle"></param>
24
      /// <returns></returns>
2136 brianf 25
      private static Style createParagrapghStyle(string newStyleName, string followingStyleName, Style baseStyle)
2094 ghuddy 26
      {
2136 brianf 27
         Style s = getStyle(newStyleName);
2094 ghuddy 28
         if (s == null)
29
         {
2136 brianf 30
            object o_styleType = WdStyleType.wdStyleTypeParagraph;
2106 ghuddy 31
            s = createWordDoc.WordDocument.Styles.Add(newStyleName, ref o_styleType);
2094 ghuddy 32
 
33
            object o_baseStyle = baseStyle.NameLocal;
34
            object o_followingStyle = followingStyleName;
35
            s.set_BaseStyle(ref o_baseStyle);
36
            s.set_NextParagraphStyle(ref o_followingStyle);
37
 
38
            s.Font = baseStyle.Font;
39
            s.ParagraphFormat = baseStyle.ParagraphFormat;
2136 brianf 40
            s.LanguageID = WdLanguageID.wdEnglishAUS;
2094 ghuddy 41
            s.NoProofing = 0;
42
            s.Frame.Delete();
43
            s.NoSpaceBetweenParagraphsOfSameStyle = false;
44
 
45
         }
46
         return s;
47
      }
48
 
49
      /// <summary>
50
      /// Creates a wdStyleTypeCharacter based style
51
      /// </summary>
52
      /// <param name="newStyleName"></param>
53
      /// <param name="baseStyle"></param>
54
      /// <returns></returns>
2136 brianf 55
        private static Style createCharacterStyle(string newStyleName, Style baseStyle)
2094 ghuddy 56
      {
2136 brianf 57
         Style s = getStyle(newStyleName);
2094 ghuddy 58
         if (s == null)
59
         {
2136 brianf 60
            object o_styleType = WdStyleType.wdStyleTypeCharacter;
2106 ghuddy 61
            s = createWordDoc.WordDocument.Styles.Add(newStyleName, ref o_styleType);
2094 ghuddy 62
            object o_baseStyle = baseStyle.NameLocal;
63
            s.set_BaseStyle(ref o_baseStyle);
64
            s.Font = baseStyle.Font;
2136 brianf 65
            s.LanguageID = WdLanguageID.wdEnglishAUS;
2094 ghuddy 66
            s.NoProofing = 0;
67
         }
68
         return s;
69
      }
70
 
2116 ghuddy 71
      public static void fixupNumParaStyles()
72
      {
73
         // Remove all NumPara styles, some of which are known to be faulty.
2136 brianf 74
         Style np = getStyle(EA_Constants.styleName_NumPara1);
2116 ghuddy 75
         if (np != null) np.Delete();
76
         np = getStyle(EA_Constants.styleName_NumPara2);
77
         if (np != null) np.Delete();
78
         np = getStyle(EA_Constants.styleName_NumPara3);
79
         if (np != null) np.Delete();
80
         np = getStyle(EA_Constants.styleName_NumPara4);
81
         if (np != null) np.Delete();
82
         np = getStyle(EA_Constants.styleName_NumPara5);
83
         if (np != null) np.Delete();
84
         np = getStyle(EA_Constants.styleName_NumPara6);
85
         if (np != null) np.Delete();
86
         np = getStyle(EA_Constants.styleName_NumPara7);
87
         if (np != null) np.Delete();
88
         np = getStyle(EA_Constants.styleName_NumPara8);
89
         if (np != null) np.Delete();
90
         np = getStyle(EA_Constants.styleName_NumPara9);
91
         if (np != null) np.Delete();
92
         np = getStyle("Numpara 6");   // ERG template has this one too - Note the lower case p
93
         if (np != null) np.Delete();
94
 
95
         // Re-Create Good Num Para styles based on the now good Heading styles
2136 brianf 96
         Style baseStyle;
2116 ghuddy 97
         baseStyle = getStyle(EA_Constants.styleName_Heading1);
98
         if (baseStyle != null)
99
         {
100
            np = createParagrapghStyle(EA_Constants.styleName_NumPara1, EA_Constants.styleName_Body1, baseStyle);
101
            np.Font.Size = 10;
102
            np.Font.Bold = 0;
103
         }
104
         baseStyle = getStyle(EA_Constants.styleName_Heading2);
105
         if (baseStyle != null)
106
         {
107
            np = createParagrapghStyle(EA_Constants.styleName_NumPara2, EA_Constants.styleName_Body1, baseStyle);
108
            np.Font.Size = 10;
109
            np.Font.Bold = 0;
110
         }
111
         baseStyle = getStyle(EA_Constants.styleName_Heading3);
112
         if (baseStyle != null)
113
         {
114
            np = createParagrapghStyle(EA_Constants.styleName_NumPara3, EA_Constants.styleName_Body1, baseStyle);
115
            np.Font.Size = 10;
116
            np.Font.Bold = 0;
117
         }
118
         baseStyle = getStyle(EA_Constants.styleName_Heading4);
119
         if (baseStyle != null)
120
         {
121
            np = createParagrapghStyle(EA_Constants.styleName_NumPara4, EA_Constants.styleName_Body1, baseStyle);
122
            np.Font.Size = 10;
123
            np.Font.Bold = 0;
124
         }
125
         baseStyle = getStyle(EA_Constants.styleName_Heading5);
126
         if (baseStyle != null)
127
         {
128
            np = createParagrapghStyle(EA_Constants.styleName_NumPara5, EA_Constants.styleName_Body1, baseStyle);
129
            np.Font.Size = 10;
130
            np.Font.Bold = 0;
131
         }
132
         baseStyle = getStyle(EA_Constants.styleName_Heading6);
133
         if (baseStyle != null)
134
         {
135
            np = createParagrapghStyle(EA_Constants.styleName_NumPara6, EA_Constants.styleName_Body1, baseStyle);
136
            np.Font.Size = 10;
137
            np.Font.Bold = 0;
138
         }
139
         baseStyle = getStyle(EA_Constants.styleName_Heading7);
140
         if (baseStyle != null)
141
         {
142
            np = createParagrapghStyle(EA_Constants.styleName_NumPara7, EA_Constants.styleName_Body1, baseStyle);
143
            np.Font.Size = 10;
144
            np.Font.Bold = 0;
145
         }
146
         baseStyle = getStyle(EA_Constants.styleName_Heading8);
147
         if (baseStyle != null)
148
         {
149
            np = createParagrapghStyle(EA_Constants.styleName_NumPara8, EA_Constants.styleName_Body1, baseStyle);
150
            np.Font.Size = 10;
151
            np.Font.Bold = 0;
152
         }
153
         baseStyle = getStyle(EA_Constants.styleName_Heading9);
154
         if (baseStyle != null)
155
         {
156
            np = createParagrapghStyle(EA_Constants.styleName_NumPara9, EA_Constants.styleName_Body1, baseStyle);
157
            np.Font.Size = 10;
158
            np.Font.Bold = 0;
159
         }
160
      }
161
 
2132 ghuddy 162
      public static void forceHeadingsToUse2_5cmTabStops()
163
      {
2136 brianf 164
         object alignment = WdTabAlignment.wdAlignTabLeft;
165
         object leader = WdTabLeader.wdTabLeaderSpaces;
166
         Style h = getStyle(EA_Constants.styleName_Heading6);
2132 ghuddy 167
         if (h != null)
168
         {
169
            h.ParagraphFormat.TabStops.ClearAll();
170
            h.ParagraphFormat.TabStops.Add((float)2.5, ref alignment, ref leader);
171
         }
172
         h = getStyle(EA_Constants.styleName_Heading7);
173
         if (h != null)
174
         {
175
            h.ParagraphFormat.TabStops.ClearAll();
176
            h.ParagraphFormat.TabStops.Add((float)2.5, ref alignment, ref leader);
177
         }
178
         h = getStyle(EA_Constants.styleName_Heading8);
179
         if (h != null)
180
         {
181
            h.ParagraphFormat.TabStops.ClearAll();
182
            h.ParagraphFormat.TabStops.Add((float)2.5, ref alignment, ref leader);
183
         }
184
         h = getStyle(EA_Constants.styleName_Heading9);
185
         if (h != null)
186
         {
187
            h.ParagraphFormat.TabStops.ClearAll();
188
            h.ParagraphFormat.TabStops.Add((float)2.5, ref alignment, ref leader);
189
         }
190
      }
191
 
2104 ghuddy 192
      /// <summary>
193
      /// This method is designed to correct problems that have been reported in the styles
194
      /// contained in the input templates being used. These can be corrected programmatically
195
      /// much quicker than waiting for a fix to be done to the templates and having them re-deployed
196
      /// to the shared drive where MS-Word templates are retrieved from by most users.
197
      /// </summary>
2106 ghuddy 198
      public static void correctErrorsInTemplateStyles()
2104 ghuddy 199
      {
200
         // Go through the document's list levels and make sure any faults are fixed up
201
         int i = 0;
202
         int j = 0;
2136 brianf 203
         foreach (ListTemplate lt in createWordDoc.WordDocument.ListTemplates)
2104 ghuddy 204
         {
205
            j = 0;
2136 brianf 206
            foreach (ListLevel lv in lt.ListLevels)
2104 ghuddy 207
            {
208
               // An old ERG template had a flaw where the list numbering restarts were not 
209
               // configured correctly, so fix up if needed.
210
               if (lv.ResetOnHigher != j)
211
                  lv.ResetOnHigher = j;
212
               j++;
213
            }
214
            i++;
215
         }
2094 ghuddy 216
 
2104 ghuddy 217
         // Ensure heading levels 7 to 9 are bold
2136 brianf 218
         Style h7 = getStyle(EA_Constants.styleName_Heading7);
2104 ghuddy 219
         if (h7 != null)
220
         {
221
            h7.Font.Bold = 1;
222
         }
2136 brianf 223
         Style h8 = getStyle(EA_Constants.styleName_Heading8);
2104 ghuddy 224
         if (h8 != null)
225
         {
226
            h8.Font.Bold = 1;
227
         }
2136 brianf 228
         Style h9 = getStyle(EA_Constants.styleName_Heading9);
2104 ghuddy 229
         if (h9 != null)
230
         {
231
            h9.Font.Bold = 1;
232
         }
2116 ghuddy 233
 
234
         fixupNumParaStyles();
2104 ghuddy 235
      }
236
 
237
      /// <summary>
238
      /// This method creates a heading level style for heading levels 10 or above. Although MS-Word 
239
      /// does not support level numbering above 9, EA_DocGen can fake the heading number and use the
240
      /// styles created in this method for the fake headings.
241
      /// </summary>
2106 ghuddy 242
      public static void createAdditionalHeadingLevelStyles()
2104 ghuddy 243
      {
2136 brianf 244
         Style s_Body1 = getStyle(EA_Constants.styleName_Body1);
2104 ghuddy 245
         if (s_Body1 != null)
246
         {
2116 ghuddy 247
            // Heading 10 or above
2136 brianf 248
            Style h10 = createParagrapghStyle(EA_Constants.styleName_Heading10OrAbove, EA_Constants.styleName_Body1, s_Body1);
2104 ghuddy 249
            h10.Font.Size = 10;
250
            h10.Font.Bold = 1;
2106 ghuddy 251
            h10.ParagraphFormat.LeftIndent  = createWordDoc.WordApp.CentimetersToPoints((float)0.0);
2104 ghuddy 252
            h10.ParagraphFormat.SpaceAfter  = 6;
253
            h10.ParagraphFormat.SpaceBefore = 12;
2116 ghuddy 254
 
255
            // NumPara 10 or above
2136 brianf 256
            Style np10 = createParagrapghStyle(EA_Constants.styleName_NumPara10OrAbove, EA_Constants.styleName_Body1, s_Body1);
2116 ghuddy 257
            h10.Font.Size = 10;
258
            h10.Font.Bold = 0;
259
            h10.ParagraphFormat.LeftIndent  = createWordDoc.WordApp.CentimetersToPoints((float)0.0);
260
            h10.ParagraphFormat.SpaceAfter  = 6;
261
            h10.ParagraphFormat.SpaceBefore = 12;
2104 ghuddy 262
         }
263
      }
264
 
265
      /// <summary>
266
      /// Create the styles used to display class element details
267
      /// </summary>
2106 ghuddy 268
      public static void createElementDetailsStyles()
2098 ghuddy 269
      {
2136 brianf 270
         Style s_Body1 = getStyle(EA_Constants.styleName_Body1);
2098 ghuddy 271
         if (s_Body1 != null)
272
         {
273
            // A couple of indented body 1 styles
2136 brianf 274
            Style s_B1_3_5 = createParagrapghStyle(EA_Constants.styleName_Body1_Left_3_5cm, EA_Constants.styleName_Body1_Left_3_5cm, s_Body1);
2106 ghuddy 275
            s_B1_3_5.ParagraphFormat.LeftIndent = createWordDoc.WordApp.CentimetersToPoints((float)3.5);
2098 ghuddy 276
 
2136 brianf 277
            Style s_B1_4_5 = createParagrapghStyle(EA_Constants.styleName_Body1_Left_4_5cm, EA_Constants.styleName_Body1_Left_4_5cm, s_Body1);
2106 ghuddy 278
            s_B1_4_5.ParagraphFormat.LeftIndent = createWordDoc.WordApp.CentimetersToPoints((float)4.5);
2098 ghuddy 279
 
280
            // A couple of pseudo-heading styles
2136 brianf 281
            Style s_B1_2_5_Italic = createParagrapghStyle(EA_Constants.styleName_Body1_Left_2_5cm_Italic, EA_Constants.styleName_Body1_Left_3_5cm, s_Body1);
2106 ghuddy 282
            s_B1_2_5_Italic.ParagraphFormat.LeftIndent = createWordDoc.WordApp.CentimetersToPoints((float)2.5);
2098 ghuddy 283
            s_B1_2_5_Italic.Font.Italic = 1;
284
            s_B1_2_5_Italic.Font.Bold = 1;
285
 
2136 brianf 286
            Style s_B1_3_5_Italic = createParagrapghStyle(EA_Constants.styleName_Body1_Left_3_5cm_Italic, EA_Constants.styleName_Body1_Left_4_5cm, s_Body1);
2106 ghuddy 287
            s_B1_3_5_Italic.ParagraphFormat.LeftIndent = createWordDoc.WordApp.CentimetersToPoints((float)3.5);
2098 ghuddy 288
            s_B1_3_5_Italic.Font.Italic = 1;
289
            s_B1_3_5_Italic.Font.Bold = 1;
290
 
291
            // Style for use when detailing parameter descriptions
2136 brianf 292
            Style s_ParamDesc = createParagrapghStyle(EA_Constants.stylename_Parameter_Description, EA_Constants.styleName_Body1, s_Body1);
2098 ghuddy 293
            s_ParamDesc.ParagraphFormat.TabStops.ClearAll();
2136 brianf 294
            object alignment = WdTabAlignment.wdAlignTabLeft;
295
            object leader = WdTabLeader.wdTabLeaderSpaces;
2106 ghuddy 296
            s_ParamDesc.ParagraphFormat.LeftIndent = createWordDoc.WordApp.CentimetersToPoints((float)9.0);
297
            s_ParamDesc.ParagraphFormat.TabStops.Add( createWordDoc.WordApp.CentimetersToPoints((float)9.0), ref alignment, ref leader );
298
            s_ParamDesc.ParagraphFormat.FirstLineIndent = createWordDoc.WordApp.CentimetersToPoints((float)-5.5);
2098 ghuddy 299
         }
300
      }
301
 
2094 ghuddy 302
      /// <summary>
303
      /// Creates the styles needed for generating requirement documentation, if they do not
304
      /// already exist.
305
      /// </summary>
2106 ghuddy 306
      public static void createRequirementStyles()
2094 ghuddy 307
      {
2136 brianf 308
         Style s_Body1 = getStyle(EA_Constants.styleName_Body1);
2094 ghuddy 309
         if (s_Body1 != null)
310
         {
311
            // APPROVED ///////////////////////////////////////////////////////////////////////////////////////////////
2136 brianf 312
            Style s_ReqAppBody = createParagrapghStyle(EA_Constants.styleName_ReqAppBody, EA_Constants.styleName_ReqAppBody, s_Body1);
2094 ghuddy 313
            if (s_ReqAppBody != null)
314
            {
315
               // No changes needed - this is just a copy of Body 1
316
            }
317
 
2136 brianf 318
            Style s_ReqAppHdr = null;
2094 ghuddy 319
            if (s_ReqAppBody != null)
320
            {
321
               s_ReqAppHdr = createParagrapghStyle(EA_Constants.styleName_ReqAppHdr, EA_Constants.styleName_ReqAppBody, s_Body1);
322
               if (s_ReqAppHdr != null)
323
               {
324
                  // Indent:Hanging: 2.5cm, Space After: 3pt, Keep with next, Tabs: 16.5cm, Right
2106 ghuddy 325
                  s_ReqAppHdr.ParagraphFormat.FirstLineIndent = createWordDoc.WordApp.CentimetersToPoints((float)-2.5);
2094 ghuddy 326
                  s_ReqAppHdr.ParagraphFormat.SpaceAfter = 3;
327
                  s_ReqAppHdr.ParagraphFormat.KeepWithNext = (int)MsoTriState.msoTrue;
328
                  s_ReqAppHdr.ParagraphFormat.TabStops.ClearAll();
2136 brianf 329
                  object alignment = WdTabAlignment.wdAlignTabRight;
330
                  object leader = WdTabLeader.wdTabLeaderSpaces;
2106 ghuddy 331
                  s_ReqAppHdr.ParagraphFormat.TabStops.Add( createWordDoc.WordApp.CentimetersToPoints((float)16.5), ref alignment, ref leader );
2094 ghuddy 332
               }
333
            }
334
 
335
            // PROPOSED ///////////////////////////////////////////////////////////////////////////////////////////////
2136 brianf 336
            Style s_ReqPropBody = null;
2094 ghuddy 337
            if (s_ReqAppBody != null)
338
            {
339
               s_ReqPropBody = createParagrapghStyle(EA_Constants.styleName_ReqPropBody, EA_Constants.styleName_ReqPropBody, s_ReqAppBody );
340
               if (s_ReqPropBody != null)
341
               {
342
                  // Font: Italic
343
                  s_ReqPropBody.Font.Italic = (int)MsoTriState.msoTrue;
344
               }
345
            }
346
 
347
            if (s_ReqAppHdr != null && s_ReqPropBody != null)
348
            {
2136 brianf 349
               Style s_ReqPropHdr = createParagrapghStyle(EA_Constants.styleName_ReqPropHdr, EA_Constants.styleName_ReqPropBody, s_ReqAppHdr );
2094 ghuddy 350
               if (s_ReqPropHdr != null)
351
               {
352
                  // Font: Italic
353
                  s_ReqPropHdr.Font.Italic = (int)MsoTriState.msoTrue;
354
               }
355
            }
356
 
357
            // REJECTED ///////////////////////////////////////////////////////////////////////////////////////////////
2136 brianf 358
            Style s_ReqRejBody = null;
2094 ghuddy 359
            if (s_ReqAppBody != null)
360
            {
361
               s_ReqRejBody = createParagrapghStyle(EA_Constants.styleName_ReqRejBody, EA_Constants.styleName_ReqRejBody, s_ReqAppBody );
362
               if (s_ReqRejBody != null)
363
               {
364
                  // Font: Italic
365
                  s_ReqRejBody.Font.StrikeThrough = (int)MsoTriState.msoTrue;
366
               }
367
            }
368
 
369
            if (s_ReqAppHdr != null && s_ReqRejBody != null)
370
            {
2136 brianf 371
               Style s_ReqRejHdr = createParagrapghStyle(EA_Constants.styleName_ReqRejHdr, EA_Constants.styleName_ReqRejBody, s_ReqAppHdr );
2094 ghuddy 372
               if (s_ReqRejHdr != null)
373
               {
374
                  // Font: Italic
375
                  s_ReqRejHdr.Font.StrikeThrough = (int)MsoTriState.msoTrue;
376
               }
377
            }
378
 
379
            // REQUIREMENT NAME ///////////////////////////////////////////////////////////////////////////////////////////////
2136 brianf 380
            Style s_DefParaFont = getStyle("Default Paragraph Font");
2094 ghuddy 381
            if (s_DefParaFont != null)
382
            {
2136 brianf 383
               Style s_ReqName = createCharacterStyle(EA_Constants.styleName_ReqName, s_DefParaFont );
2094 ghuddy 384
               if (s_ReqName != null)
385
               {
386
                  s_ReqName.Font.Bold = (int)MsoTriState.msoTrue;
387
               }
388
            }
389
         }
390
      }
391
 
392
      /// <summary>
393
      /// This function was the only way I could figure out how to obtain a style object for
394
      /// the style name given. Everything else I tried, didn't work, even code from Visual Basic
395
      /// examples failed to work or even compile (once converted) in C#.
396
      /// </summary>
397
      /// <param name="styleText"></param>
398
      /// <returns></returns>
2136 brianf 399
      public static Style getStyle(string styleText)
2094 ghuddy 400
      {
2136 brianf 401
         foreach(Style aStyle in createWordDoc.WordDocument.Styles)
2094 ghuddy 402
         {
403
            //MessageBox.Show( aStyle.NameLocal );
2104 ghuddy 404
            if (aStyle.NameLocal.Equals(styleText))
2094 ghuddy 405
            {
406
               return aStyle;
407
            }
408
         }
409
         return null;
410
      }
411
 
412
 
413
 
414
	}
415
}