-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathChooseAnalysisHandler.cs
More file actions
711 lines (643 loc) · 22.8 KB
/
Copy pathChooseAnalysisHandler.cs
File metadata and controls
711 lines (643 loc) · 22.8 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
// Copyright (c) 2015-2017 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.Windows.Forms;
using System.Drawing;
using SIL.LCModel;
using SIL.FieldWorks.Common.ViewsInterfaces;
using SIL.LCModel.DomainServices;
using SIL.FieldWorks.FdoUi;
using SIL.LCModel.Utils;
using SIL.FieldWorks.Common.Widgets;
using SIL.LCModel.Core.Text;
using SIL.LCModel.Core.KernelInterfaces;
namespace SIL.FieldWorks.IText
{
/// <summary>
/// This class handles the functions of the combo box that is used to choose a
/// different existing analysis.
/// </summary>
internal class ChooseAnalysisHandler : IComboHandler, IDisposable
{
int m_hvoAnalysis; // The current 'analysis', may be wordform, analysis, gloss.
int m_hvoSrc; // the object (CmAnnotation? or SbWordform) we're analyzing.
AnalysisOccurrence m_occurrence;
bool m_fInitializing = false; // true to suppress AnalysisChosen while setting up combo.
LcmCache m_cache;
IComboList m_combo;
SandboxBase m_owner;
const string ksMissingString = "---";
const string ksPartSeparator = " ";
/// <summary>
/// this is something of a hack until we convert to using a style sheet
/// </summary>
protected static int s_baseFontSize = 12;
/// <summary>
/// This fires when the user selects an item in the menu.
/// The client will typically read the Analysis of 'this' to find which object has been
/// selected as the current analysis.
/// As a special case, if Analysis is zero, the user has selected the special
/// 'Use default analysis' item, and the Sandbox should re-initialize as if no analysis
/// had been selected for this word.
/// Another special case is when the analysis is the ID of the WfiWordform itself.
/// In this case, we specifically want to create a new analysis (so show no defaults).
/// </summary>
public event EventHandler AnalysisChosen;
/// <summary>
/// The object that should be modified if the user selects an analysis
/// </summary>
public int Source
{
get
{
CheckDisposed();
return m_hvoSrc;
}
}
/// <summary>
/// Initially, the analysis we based the list on. After the user makes a selection,
/// the selection he made.
/// </summary>
public AnalysisTree GetAnalysisTree()
{
var analysisTree = new AnalysisTree();
if (m_hvoAnalysis != 0)
{
var analysisObj = (IAnalysis)m_cache.ServiceLocator.GetInstance<ICmObjectRepository>().GetObject(m_hvoAnalysis);
analysisTree.Analysis = analysisObj;
}
return analysisTree;
}
/// <summary>
/// The current selected item in the combo box.
/// </summary>
public HvoTssComboItem SelectedItem
{
get
{
CheckDisposed();
if (m_combo == null)
return null;
return m_combo.SelectedItem as HvoTssComboItem;
}
}
internal IVwStylesheet StyleSheet
{
get
{
CheckDisposed();
if (m_combo != null)
return m_combo.StyleSheet;
return null;
}
}
/// Create one, typically from the Sandbox, using an existing combo box or list. The caller is responsible
/// to display it; the Show method should not be called, especially if comboList is actually not a combo box.
/// </summary>
/// <param name="cache"></param>
/// <param name="hvoSrc"></param>
/// <param name="?"></param>
/// <param name="comboList"></param>
public ChooseAnalysisHandler(LcmCache cache, int hvoSrc, int hvoAnalysis, AnalysisOccurrence occurrence, IComboList comboList)
{
m_combo = comboList;
m_cache = cache;
m_hvoSrc = hvoSrc;
m_hvoAnalysis = hvoAnalysis;
m_occurrence = occurrence;
m_combo.SelectedIndexChanged += new EventHandler(m_combo_SelectedIndexChanged);
m_combo.WritingSystemFactory = cache.LanguageWritingSystemFactoryAccessor;
}
#region IDisposable & Co. implementation
// Region last reviewed: never
/// <summary>
/// Check to see if the object has been disposed.
/// All public Properties and Methods should call this
/// before doing anything else.
/// </summary>
public void CheckDisposed()
{
if (IsDisposed)
throw new ObjectDisposedException(String.Format("'{0}' in use after being disposed.", GetType().Name));
}
/// <summary>
/// True, if the object has been disposed.
/// </summary>
private bool m_isDisposed = false;
/// <summary>
/// See if the object has been disposed.
/// </summary>
public bool IsDisposed
{
get { return m_isDisposed; }
}
/// <summary>
/// Finalizer, in case client doesn't dispose it.
/// Force Dispose(false) if not already called (i.e. m_isDisposed is true)
/// </summary>
/// <remarks>
/// In case some clients forget to dispose it directly.
/// </remarks>
~ChooseAnalysisHandler()
{
Dispose(false);
// The base class finalizer is called automatically.
}
/// <summary>
///
/// </summary>
/// <remarks>Must not be virtual.</remarks>
public void Dispose()
{
Dispose(true);
// This object will be cleaned up by the Dispose method.
// Therefore, you should call GC.SupressFinalize to
// take this object off the finalization queue
// and prevent finalization code for this object
// from executing a second time.
GC.SuppressFinalize(this);
}
/// <summary>
/// Executes in two distinct scenarios.
///
/// 1. If disposing is true, the method has been called directly
/// or indirectly by a user's code via the Dispose method.
/// Both managed and unmanaged resources can be disposed.
///
/// 2. If disposing is false, the method has been called by the
/// runtime from inside the finalizer and you should not reference (access)
/// other managed objects, as they already have been garbage collected.
/// Only unmanaged resources can be disposed.
/// </summary>
/// <param name="disposing"></param>
/// <remarks>
/// If any exceptions are thrown, that is fine.
/// If the method is being done in a finalizer, it will be ignored.
/// If it is thrown by client code calling Dispose,
/// it needs to be handled by fixing the bug.
///
/// If subclasses override this method, they should call the base implementation.
/// </remarks>
protected virtual void Dispose(bool disposing)
{
System.Diagnostics.Debug.WriteLineIf(!disposing, "****************** Missing Dispose() call for " + GetType().Name + " ******************");
// Must not be run more than once.
if (m_isDisposed)
return;
if (disposing)
{
// Dispose managed resources here.
if (m_combo != null)
{
m_combo.SelectedIndexChanged -= new EventHandler(m_combo_SelectedIndexChanged);
FwComboBox combo = m_combo as FwComboBox;
if (combo != null && combo.Parent == null)
combo.Dispose();
else
{
ComboListBox clb = (m_combo as ComboListBox);
if (clb != null)
clb.Dispose();
}
}
}
// Dispose unmanaged resources here, whether disposing is true or false.
m_cache = null;
m_owner = null;
m_isDisposed = true;
}
#endregion IDisposable & Co. implementation
/// <summary>
/// Add an item to the combo box, but only if its text is non-empty.
/// </summary>
/// <param name="text"></param>
/// <param name="fPossibleCurrent">generally true; false for items like "new analysis" that
/// can't possibly be the current item, though hvoAnalysis might match.</param>
void AddItem(ICmObject co, ITsString text, bool fPossibleCurrent)
{
AddItem(co, text, fPossibleCurrent, 0);
}
/// <summary>
/// Add an item to the combo box, but only if its text is non-empty.
/// </summary>
/// <param name="fPossibleCurrent">generally true; false for items like "new analysis" that
/// can't possibly be the current item, though hvoAnalysis might match.</param>
/// <param name="tag">tag to specify an otherwise ambigious item.</param>
void AddItem(ICmObject co, ITsString text, bool fPossibleCurrent, int tag)
{
if (text.Length == 0)
return;
int hvoObj = co != null ? co.Hvo : 0;
HvoTssComboItem newItem = new HvoTssComboItem(hvoObj, text, tag);
m_combo.Items.Add(newItem);
if (fPossibleCurrent && hvoObj == m_hvoAnalysis)
m_combo.SelectedItem = newItem;
}
void AddSeparatorLine()
{
//review
ITsStrBldr builder = TsStringUtils.MakeStrBldr();
builder.Replace(0,0,"-------", null);
builder.SetIntPropValues(0, builder.Length, (int)FwTextPropType.ktptWs,
(int)FwTextPropVar.ktpvDefault, m_cache.DefaultUserWs);
HvoTssComboItem newItem = new HvoTssComboItem(-1, builder.GetString()); //hack todo
m_combo.Items.Add(newItem);
}
/// <summary>
/// Initialize the combo contents.
/// </summary>
public void SetupCombo()
{
CheckDisposed();
m_fInitializing = true;
var wordform = m_owner.GetWordformOfAnalysis();
// Add the analyses, and recursively the other items.
var guess_services = new AnalysisGuessServices(m_cache, IsParsingDevMode());
var sorted_analyses = guess_services.GetSortedAnalysisGuesses(wordform, m_occurrence, false);
foreach (var wa in sorted_analyses)
{
Opinions o = wa.GetAgentOpinion(
m_cache.LangProject.DefaultUserAgent);
// skip any analysis the user has disapproved.
if (o != Opinions.disapproves)
{
AddAnalysisItems(wa);
AddSeparatorLine();
}
}
// Add option to clear the analysis altogether.
AddItem(wordform, MakeSimpleString(ITextStrings.ksNewAnalysis), false, WfiWordformTags.kClassId);
// Add option to reset to the default
AddItem(null, MakeSimpleString(ITextStrings.ksUseDefaultAnalysis), false);
m_fInitializing = false;
}
/// <summary>
/// Add the items for this WfiAnalysis (itself and ones it owns).
/// </summary>
void AddAnalysisItems(IWfiAnalysis wa)
{
AddItem(wa,
MakeAnalysisStringRep(wa, m_cache, StyleSheet != null, (m_owner as SandboxBase).RawWordformWs), true);
var guess_services = new AnalysisGuessServices(m_cache, IsParsingDevMode());
var sorted_glosses = guess_services.GetSortedGlossGuesses(wa, m_occurrence);
foreach (var gloss in sorted_glosses)
{
AddItem(gloss, MakeGlossStringRep(gloss, m_cache, StyleSheet != null), true);
}
//add the "new word gloss" option
AddItem(wa, MakeSimpleString(ITextStrings.ksNewWordGloss), false, WfiGlossTags.kClassId);
}
private bool IsParsingDevMode()
{
if (Owner?.InterlinDoc?.GetMaster() == null)
return false;
return Owner.InterlinDoc.GetMaster().IsParsingDevMode();
}
protected ITsString MakeSimpleString(String str)
{
ITsStrBldr builder = TsStringUtils.MakeStrBldr();
ITsPropsBldr bldr = TsStringUtils.MakePropsBldr();
bldr.SetIntPropValues((int)FwTextPropType.ktptWs,
(int)FwTextPropVar.ktpvDefault, m_cache.DefaultUserWs);
bldr.SetIntPropValues((int)FwTextPropType.ktptFontSize,
(int)FwTextPropVar.ktpvMilliPoint, s_baseFontSize * 800);
bldr.SetStrPropValue((int)FwTextStringProp.kstpFontFamily, MiscUtils.StandardSansSerif);
builder.Replace(0,0,str , bldr.GetTextProps());
return builder.GetString();
}
// Generate a suitable string representation of a WfiGloss.
// Todo: finish implementing (add the gloss!)
internal static ITsString MakeGlossStringRep(IWfiGloss wg, LcmCache fdoCache, bool fUseStyleSheet)
{
ITsStrBldr tsb = TsStringUtils.MakeStrBldr();
var wa = wg.Owner as IWfiAnalysis;
var category = wa.CategoryRA;
if (category != null)
{
ITsString tssPos = category.Abbreviation.get_String( fdoCache.DefaultAnalWs);
tsb.Replace(0, 0, tssPos.Text,
PartOfSpeechTextProperties(fdoCache,false, fUseStyleSheet));
}
else
{
tsb.Replace(0, 0, ksMissingString,
PartOfSpeechTextProperties(fdoCache,false, fUseStyleSheet));
}
tsb.Replace(tsb.Length, tsb.Length, " ", null);
tsb.Replace(tsb.Length, tsb.Length,
wg.Form.get_String(fdoCache.DefaultAnalWs).Text,
GlossTextProperties(fdoCache, false, fUseStyleSheet));
//indent
tsb.Replace(0,0, " ", null);
return tsb.GetString();
}
// Make a string representing a WfiAnalysis, suitable for use in a combo box item.
internal static ITsString MakeAnalysisStringRep(IWfiAnalysis wa, LcmCache fdoCache, bool fUseStyleSheet, int wsVern)
{
// ITsTextProps boldItalicAnalysis = BoldItalicAnalysis(fdoCache);
// ITsTextProps italicAnalysis = ItalicAnalysis(fdoCache, Sandbox.SandboxVc.krgbRed);
ITsTextProps posTextProperties = PartOfSpeechTextProperties(fdoCache, true, fUseStyleSheet);
ITsTextProps formTextProperties = FormTextProperties(fdoCache, fUseStyleSheet, wsVern);
ITsTextProps glossTextProperties = GlossTextProperties(fdoCache, true, fUseStyleSheet);
ITsStrBldr tsb = TsStringUtils.MakeStrBldr();
int cmorph = wa.MorphBundlesOS.Count;
if (cmorph == 0)
return TsStringUtils.MakeString(ITextStrings.ksNoMorphemes, fdoCache.DefaultUserWs);
bool fRtl = fdoCache.ServiceLocator.WritingSystemManager.Get(wsVern).RightToLeftScript;
int start = 0;
int lim = cmorph;
int increment = 1;
if (fRtl)
{
start = cmorph - 1;
lim = -1;
increment = -1;
}
if (wa?.Cache?.LanguageProject != null)
{
Opinions uao = wa.GetAgentOpinion(wa.Cache.LangProject.DefaultUserAgent);
Opinions pao = wa.GetAgentOpinion(wa.Cache.LangProject.DefaultParserAgent);
AddOpinion(tsb, uao, InterlinVc.ApprovedGuessColor);
AddOpinion(tsb, pao, InterlinVc.MachineGuessColor);
tsb.Replace(tsb.Length, tsb.Length, " ", null);
tsb.SetProperties(tsb.Length - 1, tsb.Length, formTextProperties);
}
for (int i = start; i != lim; i += increment)
{
var mb = wa.MorphBundlesOS[i];
var mf = mb.MorphRA;
ITsString tssForm = null;
// Review: Appears to be similar to code in LexEntryVc.
if (mf != null)
{
var entry = mf.Owner as ILexEntry;
var lexemeForm = entry.LexemeFormOA;
if (lexemeForm != null)
{
tssForm = lexemeForm.Form.get_String(wsVern);
}
if (tssForm == null || tssForm.Length == 0)
{
tssForm = entry.CitationForm.get_String(wsVern);
}
if (tssForm.Length == 0)
{
// If there isn't a lexeme form OR citation form use the form of the morph.
tssForm = mf.Form.get_String(wsVern);
}
}
else // no MoForm linked to this bundle, use its own form.
{
tssForm = mb.Form.get_String(wsVern);
}
int ichForm = tsb.Length;
tsb.ReplaceTsString(ichForm, ichForm, tssForm);
tsb.SetProperties(ichForm, tsb.Length,formTextProperties);
// add category (part of speech)
var msa = mb.MsaRA;
tsb.Replace(tsb.Length, tsb.Length, " ", null);
int ichMinMsa = tsb.Length;
string interlinName = ksMissingString;
if (msa != null)
interlinName = msa.InterlinearAbbr;
tsb.Replace(ichMinMsa, ichMinMsa, interlinName, posTextProperties);
//add sense
var sense = mb.SenseRA ?? mb.DefaultSense;
tsb.Replace(tsb.Length, tsb.Length, " ", null);
int ichMinSense = tsb.Length;
if (sense != null)
{
ITsString tssGloss = sense.Gloss.get_String(fdoCache.DefaultAnalWs);
var inflType = mb.InflTypeRA;
var glossAccessor = sense.Gloss;
var wsAnalysis = fdoCache.ServiceLocator.WritingSystemManager.Get(fdoCache.DefaultAnalWs);
var tssSense = MorphServices.MakeGlossOptionWithInflVariantTypes(inflType, glossAccessor, wsAnalysis);
var displayText = tssSense?.Text ?? tssGloss.Text;
tsb.Replace(ichMinSense, ichMinSense, displayText, glossTextProperties);
}
else
tsb.Replace(ichMinSense, ichMinSense, ksMissingString, glossTextProperties);
// Enhance JohnT: use proper seps.
tsb.Replace(tsb.Length, tsb.Length, ksPartSeparator, null);
}
// Delete the final separator. (Enhance JohnT: this needs to get smarter when we do
// real seps.)
int ichFrom = tsb.Length - ksPartSeparator.Length;
if (ichFrom < 0)
ichFrom = 0;
tsb.Replace(ichFrom, tsb.Length, "", null);
return tsb.GetString();
}
private static void AddOpinion(ITsStrBldr tsb, Opinions opinion, int backColor)
{
int foreColor = (int)CmObjectUi.RGB(Color.Black);
if (opinion == Opinions.approves)
tsb.Replace(tsb.Length, tsb.Length, "\u2714", null); // bold check mark
else if (opinion == Opinions.noopinion)
{
// Use same foreground and background color to create a blank of the same width as a check mark.
tsb.Replace(tsb.Length, tsb.Length, "\u2714", null);
foreColor = backColor;
}
else if (opinion == Opinions.disapproves)
{
tsb.Replace(tsb.Length, tsb.Length, "X", null);
foreColor = (int)CmObjectUi.RGB(Color.Red);
}
tsb.SetStrPropValue(tsb.Length - 1, tsb.Length, (int)FwTextPropType.ktptFontFamily, "Segoe UI Symbol");
tsb.SetIntPropValues(tsb.Length - 1, tsb.Length, (int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault, foreColor);
tsb.SetIntPropValues(tsb.Length - 1, tsb.Length, (int)FwTextPropType.ktptBackColor, (int)FwTextPropVar.ktpvDefault, backColor);
}
/// <summary>
///
/// </summary>
/// <param name="fdoCache"></param>
/// <returns></returns>
public static ITsTextProps FormTextProperties(LcmCache fdoCache, bool fUseStyleSheet, int wsVern)
{
int color =(int) CmObjectUi.RGB(Color.DarkBlue);
ITsPropsBldr bldr = TsStringUtils.MakePropsBldr();
if (!fUseStyleSheet)
{
bldr.SetIntPropValues((int)FwTextPropType.ktptFontSize ,
(int)FwTextPropVar.ktpvMilliPoint, s_baseFontSize * 1000);
}
bldr.SetIntPropValues((int)FwTextPropType.ktptWs,
(int)FwTextPropVar.ktpvDefault, wsVern);
// bldr.SetIntPropValues((int)FwTextPropType.ktptBold,
// (int)FwTextPropVar.ktpvEnum,
// (int)FwTextToggleVal.kttvInvert);
// bldr.SetIntPropValues((int)FwTextPropType.ktptItalic,
// (int)FwTextPropVar.ktpvEnum,
// (int)FwTextToggleVal.kttvInvert);
bldr.SetIntPropValues((int)FwTextPropType.ktptForeColor,
(int)FwTextPropVar.ktpvDefault, color);
return bldr.GetTextProps();
}
public static ITsTextProps GlossTextProperties(LcmCache fdoCache, bool inAnalysisLine, bool fUseStyleSheet)
{
int color =(int) CmObjectUi.RGB(Color.DarkRed);
ITsPropsBldr bldr = TsStringUtils.MakePropsBldr();
if (!fUseStyleSheet)
{
bldr.SetIntPropValues((int)FwTextPropType.ktptFontSize ,
(int)FwTextPropVar.ktpvMilliPoint, s_baseFontSize * 1000);
}
bldr.SetIntPropValues((int)FwTextPropType.ktptWs,
(int)FwTextPropVar.ktpvDefault, fdoCache.DefaultAnalWs);
if (inAnalysisLine)
{
bldr.SetIntPropValues((int)FwTextPropType.ktptSuperscript,
(int)FwTextPropVar.ktpvEnum,
(int)FwSuperscriptVal.kssvSuper);
}
bldr.SetIntPropValues((int)FwTextPropType.ktptForeColor,
(int)FwTextPropVar.ktpvDefault, color);
return bldr.GetTextProps();
}
/// <summary>
///
/// </summary>
/// <param name="fdoCache"></param>
/// <returns></returns>
public static ITsTextProps PartOfSpeechTextProperties(LcmCache fdoCache, bool inAnalysisLine, bool fUseStyleSheet)
{
int color =(int) CmObjectUi.RGB(Color.Green);
ITsPropsBldr bldr = TsStringUtils.MakePropsBldr();
if (!fUseStyleSheet)
{
bldr.SetIntPropValues((int)FwTextPropType.ktptFontSize ,
(int)FwTextPropVar.ktpvMilliPoint, (int)( s_baseFontSize * 1000* .8));
}
bldr.SetIntPropValues((int)FwTextPropType.ktptWs,
(int)FwTextPropVar.ktpvDefault, fdoCache.DefaultAnalWs);
// bldr.SetIntPropValues((int)FwTextPropType.ktptItalic,
// (int)FwTextPropVar.ktpvEnum,
// (int)FwTextToggleVal.kttvInvert);
if (inAnalysisLine)
{
bldr.SetIntPropValues((int)FwTextPropType.ktptSuperscript,
(int)FwTextPropVar.ktpvEnum,
(int)FwSuperscriptVal.kssvSub);
}
bldr.SetIntPropValues((int)FwTextPropType.ktptForeColor,
(int)FwTextPropVar.ktpvDefault, color);
return bldr.GetTextProps();
}
/// <summary>
/// Get the site where the combo or combo list is displayed.
/// </summary>
public SandboxBase Owner
{
get
{
CheckDisposed();
return m_owner;
}
set
{
CheckDisposed();
m_owner = value;
}
}
/// <summary>
/// Display the combo box at the specified location, or the list box pulled down from the specified location.
/// </summary>
/// <param name="loc"></param>
public void Activate(Rect loc)
{
CheckDisposed();
FwComboBox combo = m_combo as FwComboBox;
if (combo != null)
{
combo.Location = new System.Drawing.Point(loc.left, loc.top);
// 21 is the default height of a combo, the smallest reasonable size.
combo.Size = new System.Drawing.Size(Math.Max(loc.right - loc.left + 30, 200), Math.Max( loc.bottom - loc.top, 50));
if (!m_owner.Controls.Contains(combo))
m_owner.Controls.Add(combo);
}
else
{
ComboListBox c = (m_combo as ComboListBox);
c.AdjustSize(500, 400); // these are maximums!
c.LaunchingForm = m_owner.ParentForm;
c.FormHidden += ComboListHidden;
c.Launch(m_owner.RectangleToScreen(loc), Screen.GetWorkingArea(m_owner));
}
}
/// <summary>
/// Required interface method. We don't have a particular morph selected so answer zero.
/// </summary>
public int SelectedMorphHvo
{
get
{
CheckDisposed();
return 0;
}
}
/// <summary>
/// Required interface method, not relevant for this class.
/// </summary>
public void HandleSelectIfActive()
{
CheckDisposed();
}
/// <summary>
/// Handle the user selecting something in the combo.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void m_combo_SelectedIndexChanged(object sender, EventArgs e)
{
if (m_fInitializing)
return;
int x = ((HvoTssComboItem)m_combo.SelectedItem).Hvo;
if(x >= 0) //could be a separator
m_hvoAnalysis = x;
Hide(); // Moved here from the end as the 'AnalysisChosen' method can
// cause the current object to be disposed of. Not very nice...
// if there are other calls yet to be invoked on the object.
// LT-5775: this is no real fix, as a real fix would understand
// why the RootBox.MakeTextSelection would cause this object to
// be disposed. This I don't know...
if (AnalysisChosen != null)
AnalysisChosen(this, new EventArgs());
}
/// <summary>
/// Implement required interface method; will never be called because editing not allowed.
/// </summary>
/// <returns></returns>
public virtual bool HandleReturnKey()
{
CheckDisposed();
return false;
}
/// <summary>
/// Get rid of the combo, typically when the user clicks outside it.
/// </summary>
public void Hide()
{
CheckDisposed();
FwComboBox combo = m_combo as FwComboBox;
if (combo != null && m_owner.Controls.Contains(combo))
m_owner.Controls.Remove(combo);
ComboListBox clb = m_combo as ComboListBox;
if (clb != null)
clb.HideForm();
}
public void ComboListHidden(object sender, EventArgs args)
{
if (!(sender is ComboListBox))
{
throw new ApplicationException("Unexpected origin of ComboListHidden event.");
}
((ComboListBox)sender).FormHidden -= ComboListHidden;
if (m_owner != null && !m_owner.IsDisposed)
{
m_owner.Focus();
}
}
}
}