File size: 20,181 Bytes
10b2298
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
'  ========================================================================
'  Plantuml : a free UML diagram generator
'  ========================================================================
'
'  (C) Copyright 2009, Arnaud Roques
'
'  Project Info:  http://plantuml.sourceforge.net
'
'  This file is part of Plantuml.
'
'  Plantuml is free software; you can redistribute it and/or modify it
'  under the terms of the GNU General Public License as published by
'  the Free Software Foundation, either version 3 of the License, or
'  (at your option) any later version.
'
'  Plantuml distributed in the hope that it will be useful, but
'  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
'  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
'  License for more details.
'
'  You should have received a copy of the GNU General Public
'  License along with this library; if not, write to the Free Software
'  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
'  USA.
'
'  [Java is a trademark or registered trademark of Sun Microsystems, Inc.
'  in the United States and other countries.]
'
'  Original Author:  Arnaud Roques
'  Word Macro: Alain Bertucat
'
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub Macro_UML_all()
    Macro_UML ("all")
End Sub
Sub Macro_UML_parg()
    Macro_UML ("parg")
End Sub
Sub Macro_Masquer()
    Gestion_Masquer
End Sub
Function Macro_UML(l_scope)
'
' Macro_UML : generation de diagramme dans un document a partir de la description
'             "textuelle" de ces diagrammes dans le document
' Macro creee le 31/03/2009 par bertucat_a
'
' - Initialisations
'
    Gestion_Barre
    Set w_but = CommandBars("UML").Controls(4)
    
    Gestion_Style ("")
'
' --- Reperage debut et fin de description de schema
'
    w_Diag_d = "@startuml"
    w_Diag_f = "@enduml"
    
    w_Diag_idr = False
    w_Diag_no = 0

    Set f_Doc = ActiveDocument
    Set w_Crs = Selection.Range
    w_Hid = ActiveDocument.ActiveWindow.View.ShowHiddenText
    If w_Hid = False Then
        ActiveDocument.ActiveWindow.View.ShowHiddenText = True
    End If
    
    ' MSR - verif du cas particulier : un paragraphe
    Call controlParagraphe("@startuml", "@enduml")
    
    w_Crs.Select
'
' --- Identifiant fichier sans extension et repertoire courant
'
    w_Fdoc_id = f_Doc.Name
    w_Fdoc_id = Left(w_Fdoc_id, Len(w_Fdoc_id) - 4)
    w_Fdoc_dir = f_Doc.Path
    
    ' MSR - Gestion de l existance du module java
    ' Verification du fichier plantuml.jar
    
    Dim iRetVal As Integer
    
    'w_Fdoc_dir_Install = Environ("PLANTUML_INSTALL ")
    'If w_Fdoc_dir_Install <> "" Then
    '    w_Fdoc_dir = w_Fdoc_dir_Install
    'End If
    'str_test = "test -> " + w_Fdoc_dir
    'MsgBox (str_test)
    Dim nbTemplates As Integer
    
    nbTemplates = ActiveDocument.Parent.Templates.Count
    If nbTemplates > 1 Then
        For i = 1 To nbTemplates
            'MsgBox (ActiveDocument.Parent.Templates.Item(i).Name)
            If ActiveDocument.Parent.Templates.Item(i).Name = "PlantUML.dot" Then
                w_Fdoc_dir = ActiveDocument.Parent.Templates.Item(i).Path
            End If
        Next i
    End If
    
    
    
    'ActiveDocument.AttachedTemplate
    
    ' chercher si "plantuml.jar" existe !
    Set fs = CreateObject("Scripting.FileSystemObject")
    filespec = w_Fdoc_dir + "\plantuml.jar"
    If Not (fs.FileExists(filespec)) Then
        MsgBox ("Warning : not find plantuml.jar !")
        GoTo Macro_UML_exit
    End If
    
'
' - Phase 1 : Creation d'un fichier texte par bloc de description de schema
'             Recherche debut de bloc : "@startuml"
'             Fichier texte ouvert en "arriere-plan" (visible:=false)
'             Nom suffixe par numero d'ordre sur 4 digits
'             Chaque paragraphe d'un bloc est mis en style "UML"
'             puis le bloc est copie/colle dans le fichier texte
'
    w_but.Caption = "Extract"
    w_but.Visible = False
    w_but.Visible = True
    If l_scope = "all" Then
        Set w_Fnd_rng = ActiveDocument.Content
        w_Fwd = True
    Else
        Set w_Fnd_rng = w_Crs
        w_Fnd_rng.Collapse
        w_Fwd = False
    End If

    w_Fnd_rng.Find.Execute FindText:=w_Diag_d, Forward:=w_Fwd
    If w_Fnd_rng.Find.Found = True Then
        'MSR - on garde pour premiere ligne uniquement "w_Diag_d" avec le retour de ligne !
        'w_Fnd_rng.Paragraphs(1).Range.Text = w_Diag_d & Right(w_Fnd_rng.Paragraphs(1).Range, 1)
        
        Set w_Deb_rng = w_Fnd_rng.Paragraphs(1).Range
        w_Deb_rng.Collapse
    
    Else
        GoTo Macro_UML_exit
    End If
    Do While w_Fnd_rng.Find.Found = True And _
             (l_scope = "all" Or w_Diag_no < 1)
        w_but.Caption = "Extract." & w_Diag_no + 1
        w_but.Visible = False
        w_but.Visible = True
        Set w_Prgph = w_Fnd_rng.Paragraphs(1)
        Set w_Txt_rng = w_Prgph.Range
        w_Txt_rng.Collapse
        w_Diag_idr = True
        Do Until w_Diag_idr = False
            If Left(w_Prgph.Range.Text, Len(w_Diag_d)) = w_Diag_d Then
                'w_Prgph.Range.Text = w_Diag_d & vbCrLf
                Set w_Txt_rng = w_Prgph.Range
                w_Txt_rng.Collapse
               
            End If
            w_Txt_rng.MoveEnd Unit:=wdParagraph
            If Left(w_Prgph.Range.Text, Len(w_Diag_f)) = w_Diag_f Then
                'w_Prgph.Range.Text = w_Diag_f & vbCrLf
                w_Txt_rng.Style = "PlantUML"
                w_Txt_rng.Copy
                Set f_Txt = Documents.Add(Visible:=False)
                f_Txt.Content.Paste
                w_Diag_no = w_Diag_no + 1
                w_Ftxt_id = w_Fdoc_id & "_extr" & Right("000" & w_Diag_no, 4) & ".txt"
                f_Txt.SaveAs FileName:=w_Fdoc_dir & "\" & w_Ftxt_id, FileFormat:=wdFormatText
                f_Txt.Close
                w_Diag_idr = False
            End If
            
            Set w_Prgph = w_Prgph.Next
            
            If w_Prgph Is Nothing Then
                w_Diag_idr = False
            End If
        Loop
        w_Fnd_rng.Collapse Direction:=wdCollapseEnd
        If l_scope = "all" Then
            w_Fnd_rng.Find.Execute FindText:=w_Diag_d, Forward:=True
        End If
   Loop
'
' - Creation d'un fichier de reservation qui sera detruit a la fin de la procedure Java
'
    w_but.Caption = "Gener"
    w_but.Visible = False
    w_but.Visible = True
    Set f_Loc = Documents.Add(Visible:=False)
    f_Loc.SaveAs FileName:=w_Fdoc_dir & "\javaumllock.tmp", FileFormat:=wdFormatText
    f_Loc.Close

'
' - Appel de l'utilitaire de creation des schemas au format PNG a partir des fichiers texte
'

            
    w_Cmd = "java -classpath """ & w_Fdoc_dir & "\plantuml.jar;" & _
            w_Fdoc_dir & "\plantumlskins.jar"" net.sourceforge.plantuml.Run -word """ & w_Fdoc_dir & """"
    Shell (w_Cmd)
' This sleep is needed, but we don't know why...
    Sleep 500
'
' - Phase 2 : Insertion des schemas dans le documents apres validation de leur creation
'             (boite de dialogue : la fenetre de commandes DOS doit etre refermee ou bien
'             suppression par traitement Java du fichier javaumllock.temp)
'             Insertion apres chaque paragraphe de fin de bloc de description
'             (autant de fois que de blocs detectes en phase 1,
'             recherche de la chaine de reperage de fin de bloc)
'             Si une image est deja rattachee au paragraphe suivant et si ce paragraphe
'             est en style "PlantUML", le paragraphe est supprime
'             Un nouveau paragraphe (style "PlantUML", non cache) est cree pour recevoir l'image
'             Nom image idem fichier texte, avec extension .png (genere par utilitaire)
'             Gestion d'une boucle pour le cas o� plusieurs images sont generees pour un shema
'
    
    w_suite_idr = 0
    Set fso = CreateObject("Scripting.FileSystemObject")
    w_bctr = 0
    
    Do
        w_bctr = w_bctr + 1
        w_but.Caption = "Gener." & w_bctr
        w_but.Visible = False
        w_but.Visible = True
        DoEvents
        Sleep 1000
        If fso.FileExists(w_Fdoc_dir & "\javaumllock.tmp") = False Then
            w_suite_idr = 1
            Exit Do
        End If
        If w_bctr > 30 Then
            MsgBox ("Java Timeout. Aborted.")
            Exit Do
        End If
    Loop
    
    If w_suite_idr <> 1 Then
        End
    End If
    
    w_but.Caption = "Inser"
    w_but.Visible = False
    w_but.Visible = True
    
    If l_scope = "all" Then
        Set w_Fnd_rng = ActiveDocument.Content
        w_Fwd = True
    Else
        Set w_Fnd_rng = w_Deb_rng
        w_Fwd = True
    End If
    w_Fnd_rng.Find.Execute FindText:=w_Diag_f, Forward:=w_Fwd
    w_i1 = 0
    Do While w_Fnd_rng.Find.Found = True And _
             (l_scope = "all" Or w_i1 < 1)
        w_i1 = w_i1 + 1
        w_but.Caption = "Inser." & w_i1
        w_but.Visible = False
        w_but.Visible = True
        Set w_Prgph_rng = w_Fnd_rng.Paragraphs(1).Next.Range
        Do While w_Prgph_rng.InlineShapes.Count > 0 And w_Prgph_rng.Style = "PlantUML"
            w_Prgph_rng.Delete
            Set w_Prgph_rng = w_Fnd_rng.Paragraphs(1).Next.Range
        Loop
        Set w_Inser_rng = w_Prgph_rng
        w_Fpng_gen = w_Fdoc_dir & "\" & w_Fdoc_id & "_extr" & Right("000" & w_i1, 4) & "*.png"
        w_Fpng_id = Dir(w_Fpng_gen)
        While w_Fpng_id <> ""
            Set w_Prgph_rng = ActiveDocument.Paragraphs.Add(Range:=w_Inser_rng).Range
            Set w_Inser_rng = w_Prgph_rng.Paragraphs(1).Next.Range
            w_Prgph_rng.Style = "PlantUML"
            w_Prgph_rng.Font.Hidden = False
            w_Prgph_rng.Collapse
            Set w_Img = w_Prgph_rng.InlineShapes.AddPicture _
                (FileName:=w_Fdoc_dir & "\" & w_Fpng_id _
                , LinkToFile:=False, SaveWithDocument:=True)
            If w_Img.ScaleHeight > 100 Or w_Img.ScaleWidth > 100 Then
                w_Img.Reset
            End If
            w_Fpng_id = Dir()
        Wend
        w_Fnd_rng.Collapse Direction:=wdCollapseEnd
        w_Fnd_rng.Find.Execute FindText:=w_Diag_f, Forward:=True
   Loop
    
'
' - Phase 3 : suppression des fichiers de travail (texte et PNG)
'             variante en commentaire : Generation et execution d'un fichier .bat
'             pour suppression des fichiers de travail (texte et PNG)
'               A partir d'un fichier "squelette"
'               Fichiers de commandes ouverts en "arriere-plan" (visible:=false)
'               --> particularisation avec le repertoire courant et l'identifiant generique
'                   des fichiers a supprimer
'
    w_but.Caption = "Delete"
    w_but.Visible = False
    w_but.Visible = True
    On Error Resume Next
    Kill (w_Fdoc_dir & "\" & w_Fdoc_id & "_extr*.*")
    On Error GoTo 0

    'MSR - gestion du bouton afficher/masquer
    
Macro_UML_exit:

    w_but.Visible = False
    Set w_Bar = ActiveDocument.CommandBars("UML")
    Set w_but = w_Bar.Controls(1)
        
    w_but.Visible = False
    
    If w_Hid = False Then
        ActiveDocument.ActiveWindow.View.ShowHiddenText = False
        
        w_but.Caption = "Show PlantUML"
    Else
        w_but.Caption = "Hide PlantUML"
    End If
    w_but.Visible = True
    
'    w_Crs.Select
'    MsgBox ("Traitement UML termine")
    ' on affiche le text
    ActiveDocument.ActiveWindow.View.ShowAll = False
    ActiveDocument.ActiveWindow.View.ShowHiddenText = True
    
End Function
Sub Gestion_Barre()

    On Error GoTo Barre_Creat
    Set w_Bar = ActiveDocument.CommandBars("UML")
    On Error GoTo 0
    w_Bar.Visible = True
    
    On Error GoTo Bouton_Creat
    Set w_but = w_Bar.Controls(1)
    On Error GoTo 0
'    w_but.Type = msoControlButton
    w_but.OnAction = "Module1.Macro_Masquer"
    w_but.Style = msoButtonCaption
    w_but.Caption = "Hide PlantUML"
    w_but.Visible = True
    
    On Error GoTo Bouton_Creat
    Set w_but = w_Bar.Controls(2)
    On Error GoTo 0
'    w_but.Type = msoControlButton
    w_but.OnAction = "Module1.Macro_UML_all"
    w_but.Style = msoButtonCaption
    w_but.Caption = "UML.*"
    w_but.Visible = True
    
    On Error GoTo Bouton_Creat
    Set w_but = w_Bar.Controls(3)
    On Error GoTo 0
'    w_but.Type = msoControlButton
    w_but.OnAction = "Module1.Macro_UML_parg"
    w_but.Style = msoButtonCaption
    w_but.Caption = "UML.1"
    w_but.Visible = True
    
    On Error GoTo Bouton_Creat
    Set w_but = w_Bar.Controls(4)
    On Error GoTo 0
'    w_but.Type = msoControlButton
    w_but.OnAction = ""
    w_but.Style = msoButtonCaption
    w_but.Caption = "Trace"
    w_but.Visible = True


Barre_Exit:

    Exit Sub


Barre_Creat:
    
    Set w_Bar = ActiveDocument.CommandBars.Add(Name:="UML")
    
    Resume Next


Bouton_Creat:
    
    Set w_but = w_Bar.Controls.Add(Type:=msoControlButton, Before:=w_Bar.Controls.Count + 1)
    
    Resume Next


End Sub
Sub Gestion_Style(testModif As String)
'Cette fonction permet de gerer le style PlantUML
' - Creation du style avec testModif=""
' - Modification du style (masquer) avec testModif=Hide
' - Re-initialisaiton du style (re-afficher) avec testModif=Show
' - Existe deja avec testModif="" -> pas de modif

On Error GoTo Style_Creat
Set w_Stl = ActiveDocument.Styles("PlantUML")
On Error GoTo 0

' MSR ajout d'un test pour gestion de l'affichage
If testModif = "Hide PlantUML" Then
    GoTo Style_Modif
ElseIf testModif = "Show PlantUML" Then
    GoTo Style_Init
End If
    

Style_Exit:

    Exit Sub

Style_Creat:
    
        Set w_Stl = ActiveDocument.Styles.Add(Name:="PlantUML", Type:=wdStyleTypeParagraph)
        w_Stl.BaseStyle = "Normal"
        w_Stl.AutomaticallyUpdate = True

Style_Init:

    With w_Stl.Font
        .Name = "Courier New"
        .Size = 9
        .Hidden = True
        .Color = wdColorGreen
    End With
    With w_Stl.ParagraphFormat
        With .Shading
            .Texture = wdTextureNone
            .ForegroundPatternColor = wdColorAutomatic
            .BackgroundPatternColor = wdColorLightGreen
        End With
        
        .LeftIndent = CentimetersToPoints(0)
        With .Shading
            .Texture = wdTextureNone
            .ForegroundPatternColor = wdColorAutomatic
            .BackgroundPatternColor = 12254650
        End With
        With .Borders(wdBorderLeft)
            .LineStyle = wdLineStyleDashLargeGap
            .LineWidth = wdLineWidth050pt
            .Color = 3910491
        End With
        With .Borders(wdBorderRight)
            .LineStyle = wdLineStyleDashLargeGap
            .LineWidth = wdLineWidth050pt
            .Color = 3910491
        End With
        With .Borders(wdBorderTop)
            .LineStyle = wdLineStyleDashLargeGap
            .LineWidth = wdLineWidth050pt
            .Color = 3910491
        End With
        With .Borders(wdBorderBottom)
            .LineStyle = wdLineStyleDashLargeGap
            .LineWidth = wdLineWidth050pt
            .Color = 3910491
        End With
        With .Borders
            .DistanceFromTop = 1
            .DistanceFromLeft = 4
            .DistanceFromBottom = 1
            .DistanceFromRight = 4
            .Shadow = False
        End With
    End With
    
    ' ajout des tabulations
    w_Stl.NoSpaceBetweenParagraphsOfSameStyle = _
        False
    w_Stl.ParagraphFormat.TabStops.ClearAll
    w_Stl.ParagraphFormat.TabStops.Add Position:= _
        CentimetersToPoints(1), Alignment:=wdAlignTabLeft, Leader:= _
        wdTabLeaderSpaces
    w_Stl.ParagraphFormat.TabStops.Add Position:= _
        CentimetersToPoints(2), Alignment:=wdAlignTabLeft, Leader:= _
        wdTabLeaderSpaces
    w_Stl.ParagraphFormat.TabStops.Add Position:= _
        CentimetersToPoints(3), Alignment:=wdAlignTabLeft, Leader:= _
        wdTabLeaderSpaces
    w_Stl.ParagraphFormat.TabStops.Add Position:= _
        CentimetersToPoints(4), Alignment:=wdAlignTabLeft, Leader:= _
        wdTabLeaderSpaces
    Exit Sub

Style_Modif:
    
    ' Modification du style pour ne pas afficher le code plantUML, le cadre et le fond
    Set w_Stl = ActiveDocument.Styles("PlantUML")
    
    With w_Stl.Font
        .Name = "Courier New"
        .Size = 9
        .Hidden = True
        .Color = wdColorGreen
    End With
    'Cas particulier pour debuguer ! MSR ??
    If w_Stl.Font.Hidden <> -1 Then
        w_Stl.Font.Hidden = -1
    End If
    With w_Stl.ParagraphFormat
        With .Shading
            .Texture = wdTextureNone
            .ForegroundPatternColor = wdColorAutomatic
            .BackgroundPatternColor = wdColorAutomatic
        End With
        .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
        .Borders(wdBorderRight).LineStyle = wdLineStyleNone
        .Borders(wdBorderTop).LineStyle = wdLineStyleNone
        .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
   End With
    
End Sub

' MSR - gestion de l'option d'affichage des textes masques du style : "PlantUML"
Sub Gestion_Masquer()


' On positionne un repere pour y retourner apres traitement
ActiveDocument.Bookmarks.Add Name:="Position", Range:=Selection.Range

' Changement du nom du bouton
Set w_Bar = ActiveDocument.CommandBars("UML")
Set w_but = w_Bar.Controls(1)
'w_but.State = msoButtonDown
w_but.State = msoButtonUp
If w_but.Caption = "Hide PlantUML" Then
    w_but.Caption = "Show PlantUML"
    w_Bar.Controls(2).Visible = Flase
    w_Bar.Controls(3).Visible = Flase
    
Else
    w_but.Caption = "Hide PlantUML"
    w_Bar.Controls(2).Visible = True
    w_Bar.Controls(3).Visible = True
End If

On Error GoTo Gestion_Masquer_Exit
Set w_Stl = ActiveDocument.Styles("PlantUML")
On Error GoTo 0

' Gestion de l'option d'affiche des zones masquees de Word
w_Hid = ActiveDocument.ActiveWindow.View.ShowHiddenText

'Verifier l'etat reel !
If w_Bar.Controls(2).Visible = True And w_Hid = True Then
    w_Hid = False
End If
If w_Bar.Controls(2).Visible = False And w_Hid = False Then
    w_Hid = True
End If


If w_Hid = False Then
    ' on affiche le fond et la bordure
    Gestion_Style ("Show PlantUML")
    
    ' on affiche le text
    ActiveDocument.ActiveWindow.View.ShowAll = False
    ActiveDocument.ActiveWindow.View.ShowHiddenText = True
Else
    ' on n'affiche pas le fond et la bordure
    Gestion_Style ("Hide PlantUML")
    
    ' on n'affiche pas le text
    ActiveDocument.ActiveWindow.View.ShowAll = False
    ActiveDocument.ActiveWindow.View.ShowHiddenText = False
End If

'Gestion_Etat

Gestion_Masquer_Exit:
'On se repostionne sur le repere et on l'efface
Selection.GoTo What:=wdGoToBookmark, Name:="Position"
ActiveDocument.Bookmarks(Index:="Position").Delete

End Sub

' MSR ajout de cette fonction pour ajouter une ligne (paragraphe) avant et apres les bornes
' Cette fonction permet de gerer le cas particulier de la demo : pas d'autre texte que le code plantuml dans le document
Sub controlParagraphe(nameDeb As String, nameFin As String)
Dim test As Boolean

If Left(ActiveDocument.Paragraphs(1).Range.Text, Len(nameDeb)) = nameDeb Then
    ActiveDocument.Paragraphs(1).Range.Select
    Selection.InsertParagraphBefore
    ActiveDocument.Paragraphs(1).Range.Select
    Selection.ClearFormatting
End If

If Left(ActiveDocument.Paragraphs(ActiveDocument.Paragraphs.Count).Range.Text, Len(nameFin)) = nameFin Then
    ActiveDocument.Paragraphs.Add
    ActiveDocument.Paragraphs(ActiveDocument.Paragraphs.Count).Range.Select
    Selection.ClearFormatting
End If
If ActiveDocument.Paragraphs.Count > 1 Then
    If Left(ActiveDocument.Paragraphs(ActiveDocument.Paragraphs.Count - 1).Range.Text, Len(nameFin)) = nameFin Then
        ActiveDocument.Paragraphs.Add
        ActiveDocument.Paragraphs(ActiveDocument.Paragraphs.Count).Range.Select
        Selection.ClearFormatting
    End If
End If

End Sub

Sub Gestion_Etat()

' Gestion de l'option d'affiche des zones masquees de Word
w_Hid = ActiveDocument.ActiveWindow.View.ShowHiddenText
'If ActiveDocument.Styles("PlantUML2") Then
'
'End If


    ' on affiche le text
'    ActiveDocument.ActiveWindow.View.ShowAll = False
'    ActiveDocument.ActiveWindow.View.ShowHiddenText = True
'    Gestion_Style ("Show PlantUML")

End Sub