-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathInterlinVc.cs
More file actions
2772 lines (2598 loc) · 96.3 KB
/
InterlinVc.cs
File metadata and controls
2772 lines (2598 loc) · 96.3 KB
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
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2015-2018 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using SIL.LCModel.Core.Cellar;
using SIL.LCModel.Core.Text;
using SIL.LCModel.Core.WritingSystems;
using SIL.LCModel.Core.KernelInterfaces;
using SIL.FieldWorks.Common.ViewsInterfaces;
using SIL.FieldWorks.Common.RootSites;
using SIL.FieldWorks.FdoUi;
using SIL.LCModel;
using SIL.LCModel.DomainServices;
using SIL.LCModel.Infrastructure;
using Gecko.WebIDL;
namespace SIL.FieldWorks.IText
{
/// <summary>
/// View constructor for InterlinView. Just to get something working, currently
/// it is just a literal.
/// </summary>
public class InterlinVc : FwBaseVc, IDisposable
{
#region Constants and other similar ints.
internal int krgbNoteLabel = 100 + (100 << 8) + (100 << 16); // equal amounts of three colors produces a gray.
internal const int kfragInterlinPara = 100000;
protected internal const int kfragBundle = 100001;
internal const int kfragMorphBundle = 100002;
internal const int kfragAnalysis = 100003;
internal const int kfragPostfix = 100004;
internal const int kfragMorphForm = 100005;
internal const int kfragPrefix = 100006;
internal const int kfragCategory = 100007;
internal const int kfragAnalysisSummary = 100009;
internal const int kfragAnalysisMorphs = 100010;
//internal const int kfragSummary = 100011;
internal const int kfragSenseName = 100012;
internal const int kfragSingleInterlinearAnalysisWithLabels = 100013; // Recycle int for: internal const int kfragMissingGloss = 100013;
internal const int kfragDefaultSense = 100014; // Recycle int for: internal const int kfragMissingSenseobj = 100014;
internal const int kfragBundleMissingSense = 100015;
internal const int kfragAnalysisMissingPos = 100016;
internal const int kfragMsa = 100017;
//internal const int kfragMorphs = 100018;
internal const int kfragMissingWholeAnalysis = 100019;
internal const int kfragAnalysisMissingGloss = 100021;
internal const int kfragWordformForm = 100022;
internal const int kfragWordGlossGuess = 100023;
//internal const int kfragText = 100024;
internal const int kfragTxtSection = 100025;
internal const int kfragStText = 100026;
internal const int kfragParaSegment = 100027;
internal const int kfragSegFf = 100028;
internal const int kfragWordGloss = 100029;
internal const int kfragIsolatedAnalysis = 100030;
internal const int kfragMorphType = 100031;
internal const int kfragPossibiltyAnalysisName = 100032;
//internal const int kfragEmptyFreeTransPrompt = 100033;
public const int kfragSingleInterlinearAnalysisWithLabelsLeftAlign = 100034;
/// <summary>
/// Bundle of all the freeform annotations, displayed as a fake property of 'this' to reduce
/// what we have to regenerate when doing special prompts (Press Enter to ...).
/// </summary>
private const int kfragFreeformBundle = 100035;
// These ones are special: we select one ws by adding its index in to this constant.
// So a good-sized range of kfrags after this must be unused for each one.
// This one is used for isolated wordforms (e.g., in Words area) using the current list of
// analysis writing systems.
internal const int kfragWordGlossWs = 1001000;
// For this ones the flid and ws are determined by figuring the index and applying it to the line choice array
internal const int kfragLineChoices = 1002000;
// For this we follow kflidWfiAnalysis_Category and then use the ws and StringFlid indicated
// by the offset.
internal const int kfragAnalysisCategoryChoices = 1003000;
// Display a morph form (including prefix/suffix info) in the WS indicated by the line choices.
internal const int kfragMorphFormChoices = 1004000;
// Display a group of Wss for the same Freeform annotation, starting with the ws indicated by the
// index obtained from the offset from kfragSegFfchoices, and continuing for as many adjacent
// specs as have the same flid.
internal const int kfragSegFfChoices = 1005000;
// Constants used to identify 'fake' properties to DisplayVariant.
internal const int ktagGlossAppend = -50;
internal const int ktagGlossPrepend = -49;
//internal const int ktagAnalysisMissing = -51;
//internal const int ktagSummary = -52;
internal const int ktagBundleMissingSense = -53;
//internal const int ktagMissingGloss = -54;
internal const int ktagAnalysisMissingPos = -55;
internal const int ktagMissingWholeAnalysis = -56;
internal const int ktagAnalysisMissingGloss = -57;
// And constants used for the 'fake' properties that break paras into
// segments and provide defaults for wordforms
// These two used to be constants but were made variables with dummy virtual handlers so that
// ClearInfoAbout can clear them out.
internal const int ktagSegmentFree = -61;
internal const int ktagSegmentLit = -62;
internal const int ktagSegmentNote = -63;
internal const int ktagAnalysisStatus = -64;
// flids for paragraph annotation sequences.
internal int ktagSegmentForms;
bool m_fIsAddingRealFormToView; // indicates we are in the context of adding real form string to the vwEnv.
#endregion Constants and other similar ints.
#region Data members
protected bool m_fShowDefaultSense; // Use false to preserve prior behavior.
protected bool m_fHaveOpenedParagraph; // Use false to preserve prior behavior.
protected WritingSystemManager m_wsManager;
protected ISegmentRepository m_segRepository;
protected ICmObjectRepository m_coRepository;
protected IWfiMorphBundleRepository m_wmbRepository;
protected IWfiAnalysisRepository m_analRepository;
protected int m_wsVernForDisplay;
private int m_icurLine; // Keeps track of current interlinear line (see MaxStringWidthForChartColumn)
protected int m_wsAnalysis;
protected int m_wsUi;
internal WsListManager m_WsList;
private ITsString m_tssMissingVernacular; // A string in a Vernacular WS is missing
private ITsString m_tssMissingAnalysis; // A string in an Analysis WS is missing
private ITsString m_tssMissingGlossAppend;
private ITsString m_tssMissingGlossPrepend;
private ITsString m_tssEmptyAnalysis; // Shown on analysis language lines when we want nothing at all to appear.
private ITsString m_tssEmptyVern;
private ITsString m_tssEmptyPara;
private ITsString m_tssSpace;
private ITsString m_tssCommaSpace;
private ITsString m_tssPendingGlossAffix; // LexGloss line GlossAppend or GlossPrepend
private int m_mpBundleHeight; // millipoint height of interlinear bundle.
private bool m_fRtl;
private readonly IDictionary<ILgWritingSystem, ITsString> m_mapWsDirTss = new Dictionary<ILgWritingSystem, ITsString>();
// AnnotationDefns we need
private int m_hvoAnnDefNote;
private MoMorphSynAnalysisUi.MsaVc m_msaVc;
private InterlinLineChoices m_lineChoices;
protected IVwStylesheet m_stylesheet;
private IParaDataLoader m_loader;
private readonly int m_selfFlid;
private int m_leftPadding;
#endregion Data members
/// ------------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="InterlinVc"/> class.
/// </summary>
/// <remarks>We use the default analysis writing system as the default, even though
/// this view displays data in multiple writing systems. It's pretty arbitrary in this
/// case, but we need a valid WS because if we get an ORC, we have to create a Ts String
/// using some writing system.</remarks>
/// <param name="cache">The cache.</param>
/// ------------------------------------------------------------------------------------
public InterlinVc(LcmCache cache) : base(cache.DefaultAnalWs)
{
Cache = cache;
m_wsManager = m_cache.ServiceLocator.WritingSystemManager;
m_segRepository = m_cache.ServiceLocator.GetInstance<ISegmentRepository>();
m_coRepository = m_cache.ServiceLocator.GetInstance<ICmObjectRepository>();
m_wmbRepository = m_cache.ServiceLocator.GetInstance<IWfiMorphBundleRepository>();
m_analRepository = m_cache.ServiceLocator.GetInstance<IWfiAnalysisRepository>();
StTxtParaRepository = m_cache.ServiceLocator.GetInstance<IStTxtParaRepository>();
m_wsAnalysis = cache.DefaultAnalWs;
m_wsUi = cache.LanguageWritingSystemFactoryAccessor.UserWs;
GuessCache = new InterlinViewDataCache(m_cache);
PreferredVernWs = cache.DefaultVernWs;
m_selfFlid = m_cache.MetaDataCacheAccessor.GetFieldId2(CmObjectTags.kClassId, "Self", false);
m_tssMissingAnalysis = TsStringUtils.MakeString(ITextStrings.ksStars, m_wsAnalysis);
m_tssMissingGlossAppend = TsStringUtils.MakeString(MorphServices.kDefaultSeparatorLexEntryInflTypeGlossAffix + ITextStrings.ksStars, m_wsAnalysis);
m_tssMissingGlossPrepend = TsStringUtils.MakeString("", m_wsAnalysis);
m_tssEmptyAnalysis = TsStringUtils.EmptyString(m_wsAnalysis);
m_tssMissingVernacular = TsStringUtils.MakeString(ITextStrings.ksStars, cache.DefaultVernWs);
m_WsList = new WsListManager(m_cache);
m_tssEmptyPara = TsStringUtils.MakeString(ITextStrings.ksEmptyPara, m_wsAnalysis);
m_tssSpace = TsStringUtils.MakeString(" ", m_wsAnalysis);
m_msaVc = new MoMorphSynAnalysisUi.MsaVc(m_cache);
// This usually gets overridden, but ensures default behavior if not.
m_lineChoices = InterlinLineChoices.DefaultChoices(m_cache.LangProject,
WritingSystemServices.kwsVernInParagraph, WritingSystemServices.kwsAnal);
// This used to be a constant but was made variables with dummy virtual handlers so that
// ClearInfoAbout can clear them out.
// load guesses
ktagSegmentForms = SegmentTags.kflidAnalyses;
GetSegmentLevelTags(cache);
LangProjectHvo = m_cache.LangProject.Hvo;
}
internal InterlinViewDataCache GuessCache { get; set; }
private IStTxtParaRepository StTxtParaRepository { get; set; }
/// <summary>
/// Keeps track of the current interlinear line in a bundle being displayed.
/// </summary>
public int CurrentLine
{
get { return m_icurLine; }
}
/// <summary>
/// Normally gets some virtual property tags we need for stuff above the bundle level.
/// Code that is only using fragments at or below bundle may override this to do nothing,
/// and then need not set up the virtual property handlers. See ConstChartVc.
/// </summary>
/// <param name="cache"></param>
protected virtual void GetSegmentLevelTags(LcmCache cache)
{
}
/// <summary>
/// Answer true if the specified word can be analyzed. This is a further check after
/// ensuring it has an InstanceOf. It is equivalent to the check made in case kfragBundle of
/// Display(), but that already has access to the writing system of the Wordform.
/// GJM - Jan 19,'10 Added check to see if this occurrence is Punctuation: Punctuation cannot be analyzed.
/// </summary>
internal bool CanBeAnalyzed(AnalysisOccurrence occurrence)
{
return !(occurrence.Analysis is IPunctuationForm) &&
WritingSystemServices.GetAllWritingSystems(m_cache, "all vernacular", null, 0, 0).Contains(occurrence.BaselineWs);
}
internal IVwStylesheet StyleSheet
{
get
{
CheckDisposed();
return m_stylesheet;
}
set
{
CheckDisposed();
m_stylesheet = value;
}
}
#region Disposable stuff
#if DEBUG
/// <summary/>
~InterlinVc()
{
Dispose(false);
}
#endif
/// <summary>
/// Throw if the IsDisposed property is true
/// </summary>
public void CheckDisposed()
{
if (IsDisposed)
throw new ObjectDisposedException(GetType().ToString(), "This object is being used after it has been disposed: this is an Error.");
}
/// <summary/>
public bool IsDisposed { get; private set; }
/// <inheritdoc />
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary/>
protected virtual void Dispose(bool fDisposing)
{
Debug.WriteLineIf(!fDisposing, "****** Missing Dispose() call for " + GetType() + " *******");
if (fDisposing && !IsDisposed)
{
// dispose managed and unmanaged objects
// Dispose managed resources here.
m_WsList?.Dispose();
}
// Dispose unmanaged resources here, whether disposing is true or false.
m_msaVc = null;
m_cache = null;
m_tssMissingVernacular = null;
m_tssMissingAnalysis = null;
m_tssMissingGlossAppend = null;
m_tssMissingGlossPrepend = null;
m_tssEmptyAnalysis = null;
m_tssEmptyVern = null;
m_tssEmptyPara = null;
m_tssSpace = null;
m_tssCommaSpace = null;
m_WsList = null;
IsDisposed = true;
}
#endregion
public InterlinLineChoices LineChoices
{
get
{
CheckDisposed();
return m_lineChoices;
}
set
{
CheckDisposed();
m_lineChoices = value;
} // Note: caller responsible to Reconstruct if needed!
}
/// <summary>
/// The direction of the paragraph.
/// </summary>
public bool RightToLeft
{
get
{
CheckDisposed();
return m_fRtl;
}
}
/// <summary>
/// Gets or sets the left padding for a single interlin analysis that is always left-aligned.
/// </summary>
/// <value>The left padding.</value>
public int LeftPadding
{
get
{
CheckDisposed();
return m_leftPadding;
}
set
{
CheckDisposed();
m_leftPadding = value;
}
}
/// <summary>
/// Indicates we are in the context of adding real form string to the vwEnv
/// Made public for DiscourseExporter
/// </summary>
public bool IsDoingRealWordForm
{
get
{
CheckDisposed();
return m_fIsAddingRealFormToView;
}
set
{
CheckDisposed();
m_fIsAddingRealFormToView = value;
}
}
/// <summary>
/// Call this to clear the temporary cache of analyses. Minimally do this when
/// data changes. Ideally no more often than necessary.
/// </summary>
public void ResetAnalysisCache()
{
if (m_loader != null)
{
CheckDisposed();
m_loader.ResetGuessCache(IsParsingDevMode());
}
}
internal bool IsParsingDevMode()
{
if (RootSite?.GetMaster() == null)
return false;
return RootSite.GetMaster().IsParsingDevMode();
}
internal AnalysisGuessServices GuessServices
{
get
{
if (m_loader != null && m_loader.GuessServices != null)
return m_loader.GuessServices;
return new AnalysisGuessServices(m_cache, IsParsingDevMode());
}
}
public bool UpdatingOccurrence(IAnalysis oldAnalysis, IAnalysis newAnalysis)
{
if (m_loader != null)
{
CheckDisposed();
return m_loader.UpdatingOccurrence(oldAnalysis, newAnalysis);
}
return false;
}
private ITsString CommaSpaceString
{
get
{
if (m_tssCommaSpace == null)
m_tssCommaSpace = TsStringUtils.MakeString(", ", m_wsAnalysis);
return m_tssCommaSpace;
}
}
public WsListManager ListManager
{
get
{
CheckDisposed();
return m_WsList;
}
}
/// <summary>
/// Background color indicating a guess that has been approved by a human for use somewhere.
/// </summary>
public static int ApprovedGuessColor
{
get { return (int)CmObjectUi.RGB(150, 255, 255); }
}
/// <summary>
/// Background color indicating there are multiple possible human approved guesses
/// </summary>
public static int MultipleApprovedGuessColor
{
get { return (int)CmObjectUi.RGB(255, 255, 50); }
}
/// <summary>
/// Background color for a guess that no human has ever endorsed directly.
/// </summary>
public static int MachineGuessColor
{
get { return (int)CmObjectUi.RGB(234, 220, 186); }
}
/// <summary/>
internal InterlinDocRootSiteBase RootSite { get; set; }
/// <summary>
/// Clients, can supply a real vernacular alternative ws to be used for this display
/// for lines where we can't find an appropriate one. If none is provide, we'll use cache.DefaultVernWs.
/// </summary>
public int PreferredVernWs
{
get
{
CheckDisposed();
return m_wsVernForDisplay;
}
private set
{
if (value <= 0)
throw new ArgumentException($"Expected a real vernacular ws (got {value}).");
if (m_wsVernForDisplay == value)
return; // already set up
m_wsVernForDisplay = value;
m_tssEmptyVern = TsStringUtils.EmptyString(value);
m_fRtl = m_wsManager.Get(value).RightToLeftScript;
m_tssMissingVernacular = TsStringUtils.MakeString(ITextStrings.ksStars, value);
}
}
// Controls whether to display the default sense (true), or the normal '***' row.
public bool ShowDefaultSense
{
get
{
CheckDisposed();
return m_fShowDefaultSense;
}
set
{
CheckDisposed();
m_fShowDefaultSense = value;
}
}
virtual protected int LabelRGBFor(int choiceIndex)
{
return LabelRGBFor(m_lineChoices.EnabledLineSpecs[choiceIndex]);
}
virtual protected int LabelRGBFor(InterlinLineSpec spec)
{
return m_lineChoices.LabelRGBFor(spec);
}
/// <summary>
/// Called right before adding a string or opening a flow object, sets its color.
/// </summary>
/// <param name="vwenv"></param>
/// <param name="color"></param>
protected virtual void SetColor(IVwEnv vwenv, int color)
{
vwenv.set_IntProperty((int)FwTextPropType.ktptForeColor,
(int)FwTextPropVar.ktpvDefault, color);
}
/// <summary>
/// Add the specified string in the specified color to the display, using the UI Writing system.
/// </summary>
/// <param name="vwenv"></param>
/// <param name="color"></param>
/// <param name="str"></param>
protected void AddColoredString(IVwEnv vwenv, int color, string str)
{
SetColor(vwenv, color);
vwenv.AddString(TsStringUtils.MakeString(str, m_wsUi));
}
/// <summary>
/// Set the background color that we use to indicate a guess.
/// </summary>
private void SetGuessing(IVwEnv vwenv, int bgColor)
{
vwenv.set_IntProperty((int)FwTextPropType.ktptBackColor,
(int)FwTextPropVar.ktpvDefault,
bgColor);
UsingGuess = true;
}
private int GetGuessColor(ICmObject obj)
{
IWfiAnalysis wa;
if (IsParsingDevMode())
{
// Parser approval takes precedence over User approval.
wa = (obj is IWfiGloss) ? ((IWfiGloss)obj).Analysis : obj as IWfiAnalysis;
if (wa != null)
{
Opinions opinion = wa.GetAgentOpinion(wa.Cache.LangProject.DefaultParserAgent);
if (opinion == Opinions.approves)
return MachineGuessColor;
}
return ApprovedGuessColor;
}
// User approval takes precedence over Parser approval.
if (obj is IWfiGloss)
return ApprovedGuessColor;
wa = obj as IWfiAnalysis;
if (wa != null)
{
Opinions opinion = wa.GetAgentOpinion(wa.Cache.LangProject.DefaultUserAgent);
if (opinion == Opinions.approves)
return ApprovedGuessColor;
}
return MachineGuessColor;
}
public bool UsingGuess { get; set; }
/// <summary>
/// Get a guess for the given word or analysis.
/// </summary>
/// <param name="analysis"></param>
/// <returns></returns>
internal int GetGuess(IAnalysis analysis, AnalysisOccurrence occurrence)
{
if (GuessCache.get_IsPropInCache(occurrence, InterlinViewDataCache.AnalysisMostApprovedFlid,
(int)CellarPropertyType.ReferenceAtomic, 0))
{
var hvoResult = GuessCache.get_ObjectProp(occurrence, InterlinViewDataCache.AnalysisMostApprovedFlid);
if(hvoResult != 0 && Cache.ServiceLocator.IsValidObjectId(hvoResult))
return hvoResult; // may have been cleared by setting to zero, or the Decorator could have stale data
}
return analysis.Hvo;
}
// Set the properties that make the labels like "Note" 'in a fainter font" than the main text.
private void SetNoteLabelProps(IVwEnv vwenv)
{
SetColor(vwenv, krgbNoteLabel);
}
public override void Display(IVwEnv vwenv, int hvo, int frag)
{
CheckDisposed();
if (hvo == 0)
return; // Can't do anything without an hvo (except crash -- see LT-9348).
#if DEBUG
//TimeRecorder.Begin("Display");
#endif
switch (frag)
{
case kfragStText: // new root object for InterlinDocChild.
PreferredVernWs = WritingSystemServices.ActualWs(m_cache, WritingSystemServices.kwsVernInParagraph, hvo, StTextTags.kflidParagraphs);
vwenv.AddLazyVecItems(StTextTags.kflidParagraphs, this, kfragInterlinPara);
break;
case kfragInterlinPara: // Whole StTxtPara. This can be the root fragment in DE view.
if (vwenv.DataAccess.get_VecSize(hvo, StTxtParaTags.kflidSegments) == 0)
{
vwenv.NoteDependency(new[] { hvo }, new[] { StTxtParaTags.kflidSegments }, 1);
vwenv.AddString(m_tssEmptyPara);
}
else
{
// no need to calculate wsVernInParagraph at the paragraph level; we must recalculate for each word.
vwenv.AddLazyVecItems(StTxtParaTags.kflidSegments, this, kfragParaSegment);
}
break;
case kfragParaSegment:
// Don't put anything in this segment if it is a 'label' segment (typically containing a verse
// number for TE).
var seg = m_segRepository.GetObject(hvo);
if (seg.IsLabel)
break;
// This puts ten points between segments. There's always 5 points below each line of interlinear;
// if there are no freeform annotations another 5 points makes 10 between segments.
// If there are freeforms, we need the full 10 points after the last of them.
var haveFreeform = seg.FreeTranslation != null || seg.LiteralTranslation != null || seg.NotesOS.Count > 0;
vwenv.set_IntProperty((int)FwTextPropType.ktptMarginBottom,
(int)FwTextPropVar.ktpvMilliPoint, !haveFreeform ? 5000 : 10000);
vwenv.OpenDiv();
// Enhance JohnT: determine what the overall direction of the paragraph should
// be and set it.
if (m_mpBundleHeight == 0)
{
// First time...figure it out.
int dmpx, dmpyAnal, dmpyVern;
vwenv.get_StringWidth(m_tssEmptyAnalysis, null, out dmpx, out dmpyAnal);
vwenv.get_StringWidth(m_tssEmptyVern, null, out dmpx, out dmpyVern);
m_mpBundleHeight = dmpyAnal * 4 + dmpyVern * 3;
}
// The interlinear bundles are not editable.
vwenv.set_IntProperty((int)FwTextPropType.ktptEditable,
(int)FwTextPropVar.ktpvEnum, (int)TptEditable.ktptNotEditable);
if (RightToLeft)
{
vwenv.set_IntProperty((int)FwTextPropType.ktptRightToLeft,
(int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn);
vwenv.set_IntProperty((int)FwTextPropType.ktptAlign,
(int)FwTextPropVar.ktpvEnum, (int) FwTextAlign.ktalRight);
}
vwenv.set_IntProperty((int)FwTextPropType.ktptSpellCheck, (int)FwTextPropVar.ktpvEnum,
(int)SpellingModes.ksmDoNotCheck);
vwenv.OpenParagraph();
AddSegmentReference(vwenv, hvo); // Calculate and display the segment reference.
AddLabelPile(vwenv, m_cache);
vwenv.AddObjVecItems(SegmentTags.kflidAnalyses, this, kfragBundle);
// JohnT, 1 Feb 2008. Took this out as I can see no reason for it; AddObjVecItems handles
// the dependency already. Adding it just means that any change to the forms list
// regenerates a higher level than needed, which contributes to a great deal of scrolling
// and flashing (LT-7470).
// Originally added by Eric in revision 72 on the trunk as part of handling phrases.
// Eric can't see any reason we need it now, either. If you find a need to re-insert it,
// please document carefully the reasons it is needed and what bad consequences follow
// from removing it.
//vwenv.NoteDependency(new int[] { hvo }, new int[] { ktagSegmentForms }, 1);
vwenv.CloseParagraph();
// We'd get the same visual effect from just calling AddFreeformAnnotations here. But then a regenerate
// such as happens when hiding or showing a prompt has to redisplay the whole segment. This initially
// makes it lazy, then the lazy stuff gets expanded. In the process we may get undesired scrolling (LT-12248).
// So we insert another layer of object, allowing just the freeforms to be regenerated.
var flidSelf = Cache.MetaDataCacheAccessor.GetFieldId2(CmObjectTags.kClassId, "Self", false);
vwenv.AddObjProp(flidSelf, this, kfragFreeformBundle);
vwenv.CloseDiv();
break;
case kfragFreeformBundle:
AddFreeformAnnotations(vwenv, hvo);
break;
case kfragBundle: // One annotated word bundle; hvo is the IAnalysis object.
// checking AllowLayout (especially in context of Undo/Redo make/break phrase)
// helps prevent us from rebuilding the display until we've finished
// reconstructing the data and cache. Otherwise we can crash.
if (RootSite != null && !RootSite.AllowLayout)
return;
AddWordBundleInternal(hvo, vwenv);
break;
case kfragIsolatedAnalysis: // This one is used for an isolated HVO that is surely an analysis.
{
var wa = m_analRepository.GetObject(hvo);
vwenv.AddObj(wa.Owner.Hvo, this, kfragWordformForm);
vwenv.AddObj(hvo, this, kfragAnalysisMorphs);
int chvoGlosses = wa.MeaningsOC.Count;
for (int i = 0; i < m_WsList.AnalysisWsIds.Length; ++i)
{
SetColor(vwenv, LabelRGBFor(m_lineChoices.IndexInEnabled(InterlinLineChoices.kflidWordGloss,
m_WsList.AnalysisWsIds[i])));
if (chvoGlosses == 0)
{
// There are no glosses, display something indicating it is missing.
vwenv.AddProp(ktagAnalysisMissingGloss, this, kfragAnalysisMissingGloss);
}
else
{
vwenv.AddObjVec(WfiAnalysisTags.kflidMeanings, this, kfragWordGlossWs + i);
}
}
AddAnalysisPos(vwenv, hvo, hvo, -1);
}
break;
case kfragAnalysisMorphs:
int cmorphs = 0;
ICmObject co = m_coRepository.GetObject(hvo);
if (co is IWfiAnalysis)
cmorphs = (co as IWfiAnalysis).MorphBundlesOS.Count;
// We really want a variable for this...there have been pathological cases where
// m_fHaveOpenedParagraph changed during the construction of the paragraph, and we want to be
// sure to close the paragraph if we opened it.
var openedParagraph = !m_fHaveOpenedParagraph;
if (openedParagraph)
vwenv.OpenParagraph();
if (cmorphs == 0)
{
DisplayMorphBundle(vwenv, 0);
}
else
{
vwenv.AddObjVecItems(WfiAnalysisTags.kflidMorphBundles, this, kfragMorphBundle);
}
if (openedParagraph)
vwenv.CloseParagraph();
break;
case kfragMorphType: // for export only at present, display the
vwenv.AddObjProp(MoFormTags.kflidMorphType, this, kfragPossibiltyAnalysisName);
break;
case kfragPossibiltyAnalysisName:
vwenv.AddStringAltMember(CmPossibilityTags.kflidName, m_cache.DefaultAnalWs, this);
break;
case kfragMorphBundle: // the lines of morpheme information (hvo is a WfiMorphBundle)
// Make an 'inner pile' to contain the bundle of morph information.
// Give it 10 points of separation from whatever follows.
DisplayMorphBundle(vwenv, hvo);
break;
case kfragSingleInterlinearAnalysisWithLabels:
/*
// This puts ten points between segments. There's always 5 points below each line of interlinear;
// if there are no freeform annotations another 5 points makes 10 between segments.
// If there are freeforms, we need the full 10 points after the last of them.
int cfreeform = vwenv.get_DataAccess().get_VecSize(hvo, ktagSegFF);
vwenv.set_IntProperty((int)FwTextPropType.ktptMarginBottom,
(int)FwTextPropVar.ktpvMilliPoint, cfreeform == 0 ? 5000 : 10000);
*/
vwenv.OpenDiv();
DisplaySingleInterlinearAnalysisWithLabels(vwenv, hvo);
vwenv.CloseDiv();
break;
// This frag is used to display a single interlin analysis that is always left-aligned, even for RTL languages
case kfragSingleInterlinearAnalysisWithLabelsLeftAlign:
vwenv.OpenDiv();
vwenv.set_IntProperty((int)FwTextPropType.ktptPadLeading, (int)FwTextPropVar.ktpvMilliPoint, m_leftPadding);
vwenv.OpenParagraph();
vwenv.OpenInnerPile();
DisplaySingleInterlinearAnalysisWithLabels(vwenv, hvo);
vwenv.CloseInnerPile();
vwenv.CloseParagraph();
vwenv.CloseDiv();
break;
case kfragWordformForm: // The form of a WfiWordform.
vwenv.AddStringAltMember(WfiWordformTags.kflidForm, PreferredVernWs, this);
break;
case kfragPrefix:
vwenv.AddUnicodeProp(MoMorphTypeTags.kflidPrefix, PreferredVernWs, this);
break;
case kfragPostfix:
vwenv.AddUnicodeProp(MoMorphTypeTags.kflidPostfix, PreferredVernWs, this);
break;
case kfragSenseName: // The name (gloss) of a LexSense.
foreach (int wsId in m_WsList.AnalysisWsIds)
vwenv.AddStringAltMember(LexSenseTags.kflidGloss,
wsId, this);
break;
case kfragCategory: // the category of a WfiAnalysis, a part of speech;
// display the Abbreviation property inherited from CmPossibility.
foreach(var wsId in m_WsList.AnalysisWsIds)
{
vwenv.AddStringAltMember(CmPossibilityTags.kflidAbbreviation, wsId, this);
}
break;
default:
if (frag >= kfragWordGlossWs && frag < kfragWordGlossWs + m_WsList.AnalysisWsIds.Length)
{
// Displaying one ws of the form of a WfiGloss.
int ws = m_WsList.AnalysisWsIds[frag - kfragWordGlossWs];
vwenv.AddStringAltMember(WfiGlossTags.kflidForm, ws, this);
}
else if (frag >= kfragLineChoices && frag < kfragLineChoices + m_lineChoices.EnabledCount)
{
var spec = m_lineChoices.EnabledLineSpecs[frag - kfragLineChoices];
var ws = GetRealWsOrBestWsForContext(hvo, spec); // can be vernacular or analysis
if (ws > 0)
vwenv.AddStringAltMember(spec.StringFlid, ws, this);
}
else if (frag >= kfragAnalysisCategoryChoices && frag < kfragAnalysisCategoryChoices + m_lineChoices.EnabledCount)
{
AddAnalysisPos(vwenv, hvo, hvo, frag - kfragAnalysisCategoryChoices);
}
else if (frag >= kfragMorphFormChoices && frag < kfragMorphFormChoices + m_lineChoices.EnabledCount)
{
var spec = m_lineChoices.EnabledLineSpecs[frag - kfragMorphFormChoices];
var ws = GetRealWsOrBestWsForContext(hvo, spec);
DisplayMorphForm(vwenv, hvo, ws);
}
else if (frag >= kfragSegFfChoices && frag < kfragSegFfChoices + m_lineChoices.EnabledCount)
{
AddFreeformComment(vwenv, hvo, frag - kfragSegFfChoices);
}
else
{
throw new Exception("Bad fragment ID in InterlinVc.Display");
}
break;
}
#if DEBUG
//TimeRecorder.End("Display");
#endif
}
private void JoinGlossAffixesOfInflVariantTypes(ILexEntryRef entryRef1, int wsPreferred, out ITsIncStrBldr sbPrepend1, out ITsIncStrBldr sbAppend1)
{
var glossWs1 = Cache.ServiceLocator.WritingSystemManager.Get(wsPreferred);
MorphServices.JoinGlossAffixesOfInflVariantTypes(entryRef1.VariantEntryTypesRS, glossWs1,
out sbPrepend1, out sbAppend1);
}
/// <summary>
///
/// </summary>
/// <param name="hvo">the IAnalysis object</param>
/// <param name="vwenv"></param>
protected virtual void AddWordBundleInternal(int hvo, IVwEnv vwenv)
{
// we assume we're in the context of a segment with analyses here.
// we'll need this info down in DisplayAnalysisAndCloseInnerPile()
int hvoSeg;
int tagDummy;
int index;
vwenv.GetOuterObject(vwenv.EmbeddingLevel - 1, out hvoSeg, out tagDummy, out index);
var analysisOccurrence = new AnalysisOccurrence(m_segRepository.GetObject(hvoSeg), index);
SetBorderColor(vwenv, analysisOccurrence);
SetupAndOpenInnerPile(vwenv);
DisplayAnalysisAndCloseInnerPile(vwenv, analysisOccurrence, true);
}
private void SetBorderColor(IVwEnv vwenv, AnalysisOccurrence analysisOccurrence)
{
var coRepository = m_cache.ServiceLocator.GetInstance<ICmObjectRepository>();
var wag = (IAnalysis)coRepository.GetObject(analysisOccurrence.Analysis.Hvo);
int width = 0;
int color = (int)ColorUtil.ConvertColorToBGR(Color.Black);
if (IsParsingDevMode() && wag.ClassID != WfiWordformTags.kClassId && !(wag is IPunctuationForm))
{
// Show how the analysis was approved by setting the border color.
width = 3000;
color = GetGuessColor(wag.Analysis);
}
vwenv.set_IntProperty((int)FwTextPropType.ktptBorderTop, (int)FwTextPropVar.ktpvMilliPoint, width);
vwenv.set_IntProperty((int)FwTextPropType.ktptBorderBottom, (int)FwTextPropVar.ktpvMilliPoint, width);
vwenv.set_IntProperty((int)FwTextPropType.ktptBorderLeading, (int)FwTextPropVar.ktpvMilliPoint, width);
vwenv.set_IntProperty((int)FwTextPropType.ktptBorderTrailing, (int)FwTextPropVar.ktpvMilliPoint, width);
vwenv.set_IntProperty((int)FwTextPropType.ktptBorderColor, (int)FwTextPropVar.ktpvDefault, color);
}
/// <summary>
/// Displays Analysis using DisplayWordBundleMethod and closes the views Inner Pile.
/// </summary>
/// <param name="vwenv"></param>
/// <param name="analysisOccurrence"></param>
/// <param name="showMultipleAnalyses">Tells DisplayWordBundleMethod whether or not to show
/// the colored highlighting if a word has multiple analyses</param>
protected void DisplayAnalysisAndCloseInnerPile(IVwEnv vwenv, AnalysisOccurrence analysisOccurrence,
bool showMultipleAnalyses)
{
// if it is just a punctuation annotation, we just insert the form.
var analysis = analysisOccurrence.Analysis;
if (analysis is IPunctuationForm)
{
vwenv.AddStringProp(PunctuationFormTags.kflidForm, this);
}
else
{
// It's a full wordform-possessing annotation, display the full bundle.
new DisplayWordBundleMethod(vwenv, analysisOccurrence, this).Run(showMultipleAnalyses);
}
AddExtraBundleRows(vwenv, analysisOccurrence);
vwenv.CloseInnerPile();
}
/// <summary>
/// Setup a box with 10 points behind and 5 under and open the inner pile
/// </summary>
/// <param name="vwenv"></param>
protected virtual void SetupAndOpenInnerPile(IVwEnv vwenv)
{
// Make an 'inner pile' to contain the wordform and annotations.
// Give whatever box we make 10 points of separation from whatever follows.
vwenv.set_IntProperty((int)FwTextPropType.ktptMarginTrailing,
(int)FwTextPropVar.ktpvMilliPoint, 10000);
// 5 points below also helps space out the paragraph.
vwenv.set_IntProperty((int)FwTextPropType.ktptMarginBottom,
(int)FwTextPropVar.ktpvMilliPoint, 5000);
vwenv.OpenInnerPile();
}
protected virtual void AddFreeformComment(IVwEnv vwenv, int hvoSeg, int lineChoiceIndex)
{
int[] wssAnalysis = m_lineChoices.AdjacentEnabledWssAtIndex(lineChoiceIndex, hvoSeg);
if (wssAnalysis.Length == 0)
return;
vwenv.OpenDiv();
SetParaDirectionAndAlignment(vwenv, wssAnalysis[0]);
vwenv.OpenMappedPara();
string label;
int flid;
InterlinearExporter exporter = vwenv as InterlinearExporter;
int dummyFlid = m_lineChoices.EnabledLineSpecs[lineChoiceIndex].Flid;
switch (dummyFlid)
{
case InterlinLineChoices.kflidFreeTrans:
label = ITextStrings.ksFree_;
flid = SegmentTags.kflidFreeTranslation;
if (exporter != null)
exporter.FreeAnnotationType = "gls";
break;
case InterlinLineChoices.kflidLitTrans:
label = ITextStrings.ksLit_;
flid = SegmentTags.kflidLiteralTranslation;
if (exporter != null)
exporter.FreeAnnotationType = "lit";
break;
case InterlinLineChoices.kflidNote:
label = ITextStrings.ksNote_;
flid = NoteTags.kflidContent;
if (exporter != null)
exporter.FreeAnnotationType = "note";
break;
default:
throw new Exception("Unexpected FF annotation type");
}
SetNoteLabelProps(vwenv);
// REVIEW: Should we set the label to a special color as well?
var tssLabel = MakeUiElementString(label, m_cache.DefaultUserWs,
propsBldr => propsBldr.SetIntPropValues((int)FwTextPropType.ktptBold,
(int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn));
var labelBldr = tssLabel.GetBldr();
AddLineIndexProperty(labelBldr, lineChoiceIndex);
tssLabel = labelBldr.GetString();
var labelWidth = 0;
int labelHeight; // unused
if (wssAnalysis.Length > 1)
vwenv.get_StringWidth(tssLabel, null, out labelWidth, out labelHeight);
var wsVernPara = GetWsForSeg(hvoSeg);
if (IsWsRtl(wssAnalysis[0]) != IsWsRtl(wsVernPara))
{
ITsStrBldr bldr = tssLabel.GetBldr();
bldr.Replace(bldr.Length - 1, bldr.Length, null, null);
ITsString tssLabelNoSpace = bldr.GetString();
// (First) analysis language is upstream; insert label at end.
AddTssDirForWs(vwenv, wssAnalysis[0]);
AddFreeformComment(vwenv, hvoSeg, wssAnalysis[0], flid);
AddTssDirForWs(vwenv, wssAnalysis[0]);
if (wssAnalysis.Length != 1)
{
// Insert WS label for first line
AddTssDirForWs(vwenv, wsVernPara);
vwenv.AddString(m_tssSpace);
AddTssDirForWs(vwenv, wsVernPara);
SetNoteLabelProps(vwenv);
var abbrevLabel = WsListManager.WsLabel(m_cache, wssAnalysis[0]);
var abbrevBldr = abbrevLabel.GetBldr();
AddLineIndexProperty(abbrevBldr, lineChoiceIndex);
vwenv.AddString(abbrevBldr.GetString());
}
AddTssDirForWs(vwenv, wsVernPara);
vwenv.AddString(m_tssSpace);
AddTssDirForWs(vwenv, wsVernPara);
vwenv.AddString(tssLabelNoSpace);
AddTssDirForWs(vwenv, wsVernPara);
}
else
{
AddTssDirForWs(vwenv, wsVernPara);
vwenv.AddString(tssLabel);
AddTssDirForWs(vwenv, wsVernPara);
if (wssAnalysis.Length == 1)
{
AddTssDirForWs(vwenv, wssAnalysis[0]);
AddFreeformComment(vwenv, hvoSeg, wssAnalysis[0], flid);
}
else
{
SetNoteLabelProps(vwenv);
var abbrevLabel = WsListManager.WsLabel(m_cache, wssAnalysis[0]);
var abbrevBldr = abbrevLabel.GetBldr();