private void setTexts(ITextProvider tprov) { Text = tprov.GetString("FatalErrorFormHeader"); lblHeader.Text = tprov.GetString("FatalErrorFormHeader"); lblSorry.Text = tprov.GetString("FatalErrorFormSorry"); lblWhy.Text = tprov.GetString("FatalErrorFormWhy"); }
/// <summary> /// Initializes tooltip provider for "search language" or "script" button. /// </summary> /// <param name="button">The actual button.</param> /// <param name="isLang">If true, this is tooltip for "search lang"; otherwise, for "script".</param> /// <param name="tprov">Localized UI strings provider.</param> /// <param name="script">Current search script.</param> /// <param name="lang">Current search language.</param> /// <param name="needleHeight">Needle's height at today's scaling.</param> public SearchOptionsTooltip(ZenGradientButton button, bool isLang, ITextProvider tprov, SearchScript script, SearchLang lang, int needleHeight, int boxRight) { this.button = button; this.needleHeight = needleHeight; this.topOrSide = -boxRight; if (isLang) { if (lang == SearchLang.Chinese) { text = tprov.GetString("LangZhoTooltip"); } else { text = tprov.GetString("LangTrgTooltip"); } } else { if (script == SearchScript.Simplified) { text = tprov.GetString("ScriptSimpTooltip"); } else if (script == SearchScript.Traditional) { text = tprov.GetString("ScriptTradTooltip"); } else { text = tprov.GetString("ScriptBothTooltip"); } } }
public ClearUndoTooltips(ZenGradientButton button, bool isClear, ITextProvider tprov, int needleHeight) { this.isClear = isClear; this.button = button; this.needleHeight = needleHeight; if (isClear) text = tprov.GetString("WritingPadClearTooltip"); else text = tprov.GetString("WritingPadUndoTooltip"); }
/// <summary> /// Ctor: initializes main form. /// </summary> public MainForm(ICedictEngineFactory dictFact, ITextProvider tprov) : base(tprov) { this.tprov = tprov; // Initialize hanzi renderer // -- Scale (DPI) // -- Available systems fonts HanziRenderer.Scale = Scale; if (HanziRenderer.IsWinKaiAvailable()) { Magic.SetZhoContentFontFamily(IdeoFamily.WinKai); } else { Magic.SetZhoContentFontFamily(IdeoFamily.ArphicKai); } // Initialize system font provider with our own if (SystemFontProvider.Instance as ZydeoSystemFontProvider == null) { SystemFontProvider.Instance = new ZydeoSystemFontProvider(); } // Find out last window size and location from settings Size size = AppSettings.WindowLogicalSize; Point loc = AppSettings.WindowLoc; ignoredSavedSizeAndLocation = !verifySizeAndLoc(size, loc); // If location+size do not make sense, let system position window, and go with default size. if (ignoredSavedSizeAndLocation) { WinForm.StartPosition = FormStartPosition.WindowsDefaultLocation; LogicalSize = Magic.WinDefaultLogicalSize; } // Otherwise, position at last location else { WinForm.StartPosition = FormStartPosition.Manual; Location = loc; LogicalSize = size; } // Set (logical) minimum size LogicalMinimumSize = Magic.WinMinimumLogicalSize; Header = tprov.GetString("WinHeader"); lc = new LookupControl(this, dictFact, tprov); stgs = new SettingsControl(this, tprov, dictFact); MainTab = new ZenTab(stgs, tprov.GetString("TabMain")); Tabs.Add(new ZenTab(lc, tprov.GetString("TabLookup"))); }
// ----------------------------------------- /// <summary> /// Ctor: take info about update. /// </summary> public WhiteUpdateControl(ZenControlBase owner, ITextProvider tprov, int vmaj, int vmin, DateTime rdate, string rnotes, UpdateNowDelegate updateNow) : base(owner) { this.tprov = tprov; scale = Scale; this.updateNow = updateNow; // Fonts. !! Dispose 'em. fntTitle = FontCollection.CreateFont(Magic.WhiteUpdFntTitle, Magic.WhiteUpFntTitleSz, FontStyle.Regular); fntNorm = SystemFontProvider.Instance.GetSystemFont(FontStyle.Regular, Magic.WhiteUpdFntNormSz); fntTblHead = SystemFontProvider.Instance.GetSystemFont(FontStyle.Bold, Magic.WhiteUpdFntNormSz); fntTblValues = SystemFontProvider.Instance.GetSystemFont(FontStyle.Italic, 10F); // Construct UI strings Version ver = Assembly.GetExecutingAssembly().GetName().Version; strVersionVal = tprov.GetString("WhiteUpdateTblVersionVal"); strVersionVal = string.Format(strVersionVal, ver.Major + "." + ver.Minor, vmaj + "." + vmin); string longDateFormat = getLongDateFormat(); strDateVal = rdate.ToString(longDateFormat); urlRelNotes = rnotes; strTitle = tprov.GetString("WhiteUpdateTitle"); strBody = tprov.GetString("WhiteUpdateBody"); strTblHead = tprov.GetString("WhiteUpdateTblHeader"); strTblVersion = tprov.GetString("WhiteUpdateTblVersion"); strTblDate = tprov.GetString("WhiteUpdateTblDate"); strTblNotes = tprov.GetString("WhiteUpdateTblNotes"); strTblNotesVal = tprov.GetString("WhiteUpdateTblNotesVal"); // Width update button is fixed btnUpdateWidth = (int)(scale * 200F); }
public ClearUndoTooltips(ZenGradientButton button, bool isClear, ITextProvider tprov, int needleHeight) { this.isClear = isClear; this.button = button; this.needleHeight = needleHeight; if (isClear) { text = tprov.GetString("WritingPadClearTooltip"); } else { text = tprov.GetString("WritingPadUndoTooltip"); } }
/// <summary> /// Creates "update now" button when it's time to show it in fade-in animation. /// </summary> private void doCreateBtnUpdate() { btnUpdate = new ZenGradientButton(this); btnUpdate.Height = (int)(scale * 24F); btnUpdate.Width = btnUpdateWidth; btnUpdate.RelLocation = btnUpdateRelLoc; btnUpdate.SetFont(SystemFontProvider.Instance.GetSystemFont(FontStyle.Regular, 10F)); btnUpdate.Text = tprov.GetString("WhiteUpdateButton"); btnUpdate.MouseClick += onBtnUpdateClick; }
/// <summary> /// Ctor: take parent etc. /// </summary> public SearchInputControl(ZenControl owner, ITextProvider tprov) : base(owner) { this.tprov = tprov; padding = (int)Math.Round(4.0F * Scale); // The hinted text input control. txtInput = new HintedTextBox(); txtInput.Name = "txtInput"; txtInput.TabIndex = 0; txtInput.BorderStyle = BorderStyle.None; RegisterWinFormsControl(txtInput); // My font family, and other properties to achieve a borderless inside input field. txtInput.Font = (SystemFontProvider.Instance as ZydeoSystemFontProvider).GetZhoButtonFont( FontStyle.Regular, 16F); txtInput.AutoSize = false; txtInput.Height = txtInput.PreferredHeight + padding; txtInput.HintText = tprov.GetString("SearchTextHint"); // My height depends on text box's height at current font settings. blockSizeChanged = true; Height = 2 + txtInput.Height; blockSizeChanged = false; txtInput.KeyPress += onTextBoxKeyPress; // Search button Assembly a = Assembly.GetExecutingAssembly(); var imgSearch = Image.FromStream(a.GetManifestResourceStream("ZD.Gui.Resources.search.png")); btnSearch = new ZenImageButton(this); btnSearch.RelLocation = new Point(padding, padding); btnSearch.Size = new Size(Height - 2 * padding, Height - 2 * padding); btnSearch.Image = imgSearch; btnSearch.MouseClick += onClickSearch; // Clear text button. var imgCancel = Image.FromStream(a.GetManifestResourceStream("ZD.Gui.Resources.cancel.png")); btnCancel = new ZenImageButton(this); btnCancel.Size = new Size(Height - 2 * padding, Height - 2 * padding); btnCancel.Padding = padding; // We want the X to be somewhat smaller btnCancel.RelLocation = new Point(Width - padding - btnCancel.Width, padding); btnCancel.Image = imgCancel; btnCancel.Visible = false; btnCancel.MouseClick += onClickCancel; txtInput.MouseEnter += onTxtMouseEnter; txtInput.MouseLeave += onTxtMouseLeave; txtInput.MouseMove += onTxtMouseMove; txtInput.TextChanged += onTxtTextChanged; }
/// <summary> /// Gets the HTML for a single sense, not including enclosing paragraph etc., only inline markup. /// </summary> /// <param name="tprov">Text provider if meta-labels (e.g. "Classifier") are to be included. If null, they are stripped.</param> private static string getSenseHtmlPure(ITextProvider tprov, CedictSense sense, SearchScript script) { StringBuilder sb = new StringBuilder(); string strDomain = HybridToHtml(sense.Domain, script); string strEquiv = HybridToHtml(sense.Equiv, script); string strNote = HybridToHtml(sense.Note, script); if (sense.Domain != HybridText.Empty) { if (sense.Domain.EqualsPlainText("CL:")) { if (tprov != null) { sb.Append(templateItalicsOpen); sb.Append(escape(tprov.GetString("ResultCtrlClassifier")) + " "); sb.Append(templateItalicsClose); } } else { sb.Append(templateItalicsOpen); sb.Append(strDomain); sb.Append(templateItalicsClose); } } if (sense.Domain != HybridText.Empty && !sense.Domain.EqualsPlainText("CL:")) { if (sense.Equiv != HybridText.Empty || sense.Note != HybridText.Empty) { sb.Append(' '); } } sb.Append(strEquiv); if (sense.Equiv != HybridText.Empty && sense.Note != HybridText.Empty) { sb.Append(' '); } if (sense.Note != HybridText.Empty) { sb.Append(templateItalicsOpen); sb.Append(strNote); sb.Append(templateItalicsClose); } // Done return(sb.ToString()); }
/// <summary> /// Gets display strings by combining entry, sense index, and localized strings. /// </summary> private void getDisplayStrings(ITextProvider tprov, int senseIx, out string fullFormatted, out string fullCedict, out string hanzi1, out string hanzi2, out string pinyin, out string sense) { fullFormatted = tprov.GetString("CtxtCopyEntryFormatted"); fullCedict = tprov.GetString("CtxtCopyEntryCedict"); pinyin = tprov.GetString("CtxtCopyPinyin"); string pinyinVal = CedictFormatter.GetPinyinString(entry.GetPinyinForDisplay(true), Magic.CtxtMenuMaxSyllableLength); pinyin = string.Format(pinyin, pinyinVal); sense = null; hanzi1 = null; hanzi2 = null; if (script == SearchScript.Simplified || script == SearchScript.Traditional || entry.ChSimpl == entry.ChTrad) { hanzi1 = tprov.GetString("CtxtCopyHanzi"); string hanzi1Val = script == SearchScript.Traditional ? entry.ChTrad : entry.ChSimpl; hanzi1Val = ellipse(hanzi1Val, Magic.CtxtMenuMaxSyllableLength); hanzi1 = string.Format(hanzi1, hanzi1Val); } else { hanzi1 = tprov.GetString("CtxtCopySimplified"); string hanzi1Val = ellipse(entry.ChSimpl, Magic.CtxtMenuMaxSyllableLength); hanzi1 = string.Format(hanzi1, hanzi1Val); hanzi2 = tprov.GetString("CtxtCopyTraditional"); string hanzi2Val = ellipse(entry.ChTrad, Magic.CtxtMenuMaxSyllableLength); hanzi2 = string.Format(hanzi2, hanzi2Val); } if (senseIx != -1) { sense = tprov.GetString("CtxtCopySense"); string senseVal = getSense(senseIx); senseVal = ellipse(senseVal, Magic.CtxtMenuMaxSenseLength); sense = string.Format(sense, senseVal); } }
/// <summary> /// Ctor. /// </summary> public LookupControl(ZenControlBase owner, ICedictEngineFactory dictFact, ITextProvider tprov) : base(owner) { this.dictFact = dictFact; this.tprov = tprov; padding = (int)Math.Round(5.0F * Scale); // Init search language and script from user settings searchLang = AppSettings.SearchLang; searchScript = AppSettings.SearchScript; // Init HanziLookup fsStrokes = new FileStream(Magic.StrokesFileName, FileMode.Open, FileAccess.Read); brStrokes = new BinaryReader(fsStrokes); strokesData = new StrokesDataSource(brStrokes); // Writing pad writingPad = new WritingPad(this, tprov); writingPad.RelLocation = new Point(padding, padding); writingPad.LogicalSize = new Size(200, 200); writingPad.StrokesChanged += writingPad_StrokesChanged; // Images for buttons under writing pad; will get owned by buttons, not that it matters. Assembly a = Assembly.GetExecutingAssembly(); var imgStrokesClear = Image.FromStream(a.GetManifestResourceStream("ZD.Gui.Resources.strokes-clear.png")); var imgStrokesUndo = Image.FromStream(a.GetManifestResourceStream("ZD.Gui.Resources.strokes-undo.png")); // Clear and undo buttons under writing pad. float leftBtnWidth = writingPad.Width / 2 + 1; float btnHeight = 22.0F * Scale; // -- btnClearWritingPad = new ZenGradientButton(this); btnClearWritingPad.RelLocation = new Point(writingPad.RelLeft, writingPad.RelBottom - 1); btnClearWritingPad.Size = new Size((int)leftBtnWidth, (int)btnHeight); btnClearWritingPad.Text = tprov.GetString("WritingPadClear"); btnClearWritingPad.SetFont(SystemFontProvider.Instance.GetSystemFont(FontStyle.Regular, 9.0F)); btnClearWritingPad.Padding = (int)(3.0F * Scale); btnClearWritingPad.ImageExtraPadding = (int)(3.0F * Scale); btnClearWritingPad.Image = imgStrokesClear; btnClearWritingPad.Enabled = false; btnClearWritingPad.MouseClick += onClearWritingPad; // -- btnUndoStroke = new ZenGradientButton(this); btnUndoStroke.RelLocation = new Point(btnClearWritingPad.RelRight - 1, writingPad.RelBottom - 1); btnUndoStroke.Size = new Size(writingPad.RelRight - btnUndoStroke.RelLeft, (int)btnHeight); btnUndoStroke.Text = tprov.GetString("WritingPadUndo"); btnUndoStroke.SetFont(SystemFontProvider.Instance.GetSystemFont(FontStyle.Regular, 9.0F)); btnUndoStroke.Padding = (int)(3.0F * Scale); btnUndoStroke.ImageExtraPadding = (int)(1.5F * Scale); btnUndoStroke.Image = imgStrokesUndo; btnUndoStroke.Enabled = false; btnUndoStroke.MouseClick += onUndoStroke; // -- btnClearWritingPad.Tooltip = new ClearUndoTooltips(btnClearWritingPad, true, tprov, padding); btnUndoStroke.Tooltip = new ClearUndoTooltips(btnUndoStroke, false, tprov, padding); // -- // Character picker control under writing pad. ctrlCharPicker = new CharPicker(this, tprov); ctrlCharPicker.FontFam = Magic.ZhoContentFontFamily; ctrlCharPicker.FontScript = searchScript == SearchScript.Traditional ? IdeoScript.Trad : IdeoScript.Simp; ctrlCharPicker.RelLocation = new Point(padding, btnClearWritingPad.RelBottom + padding); ctrlCharPicker.LogicalSize = new Size(200, 80); ctrlCharPicker.CharPicked += onCharPicked; // Search input control at top ctrlSearchInput = new SearchInputControl(this, tprov); ctrlSearchInput.RelLocation = new Point(writingPad.RelRight + padding, padding); ctrlSearchInput.StartSearch += onStartSearch; // Tweaks for Chinese text on UI buttons // This is specific to Segoe UI and Noto Sans S Chinese fonts. float ofsZho = 0; //if (!(SystemFontProvider.Instance as ZydeoSystemFontProvider).SegoeExists) // ofsZho = Magic.ZhoButtonFontSize * Scale / 3.7F; // Script selector button to the right of search input control btnSimpTrad = new ZenGradientButton(this); btnSimpTrad.RelTop = padding; btnSimpTrad.Height = ctrlSearchInput.Height; btnSimpTrad.SetFont((SystemFontProvider.Instance as ZydeoSystemFontProvider).GetZhoButtonFont( FontStyle.Regular, Magic.ZhoButtonFontSize)); btnSimpTrad.Width = getSimpTradWidth(); btnSimpTrad.ForcedCharVertOfs = ofsZho; btnSimpTrad.RelLeft = Width - padding - btnSimpTrad.Width; btnSimpTrad.Height = ctrlSearchInput.Height; btnSimpTrad.MouseClick += onSimpTrad; // Search language selector to the right of search input control btnSearchLang = new ZenGradientButton(this); btnSearchLang.RelTop = padding; btnSearchLang.Height = ctrlSearchInput.Height; btnSearchLang.SetFont((SystemFontProvider.Instance as ZydeoSystemFontProvider).GetZhoButtonFont( FontStyle.Regular, Magic.ZhoButtonFontSize)); btnSearchLang.Width = getSearchLangWidth(); btnSearchLang.ForcedCharVertOfs = ofsZho; btnSearchLang.RelLeft = btnSimpTrad.RelLeft - padding - btnSearchLang.Width; btnSearchLang.Height = ctrlSearchInput.Height; btnSearchLang.MouseClick += onSearchLang; // Update button texts; do it here so tooltip locations will be correct. simpTradChanged(); searchLangChanged(); // Lookup results control. ctrlResults = new ResultsControl(this, tprov, onLookupThroughLink, onGetEntry); ctrlResults.RelLocation = new Point(writingPad.RelRight + padding, ctrlSearchInput.RelBottom + padding); }
/// <summary> /// Ctor: initializes main form. /// </summary> public MainForm(ICedictEngineFactory dictFact, ITextProvider tprov) : base(tprov) { this.tprov = tprov; // Initialize hanzi renderer // -- Scale (DPI) // -- Available systems fonts HanziRenderer.Scale = Scale; if (HanziRenderer.IsWinKaiAvailable()) Magic.SetZhoContentFontFamily(IdeoFamily.WinKai); else Magic.SetZhoContentFontFamily(IdeoFamily.ArphicKai); // Initialize system font provider with our own if (SystemFontProvider.Instance as ZydeoSystemFontProvider == null) SystemFontProvider.Instance = new ZydeoSystemFontProvider(); // Find out last window size and location from settings Size size = AppSettings.WindowLogicalSize; Point loc = AppSettings.WindowLoc; ignoredSavedSizeAndLocation = !verifySizeAndLoc(size, loc); // If location+size do not make sense, let system position window, and go with default size. if (ignoredSavedSizeAndLocation) { WinForm.StartPosition = FormStartPosition.WindowsDefaultLocation; LogicalSize = Magic.WinDefaultLogicalSize; } // Otherwise, position at last location else { WinForm.StartPosition = FormStartPosition.Manual; Location = loc; LogicalSize = size; } // Set (logical) minimum size LogicalMinimumSize = Magic.WinMinimumLogicalSize; Header = tprov.GetString("WinHeader"); lc = new LookupControl(this, dictFact, tprov); stgs = new SettingsControl(this, tprov, dictFact); MainTab = new ZenTab(stgs, tprov.GetString("TabMain")); Tabs.Add(new ZenTab(lc, tprov.GetString("TabLookup"))); }
public SysBtnTooltips(ZenSystemButton button, ITextProvider tprov) { this.button = button; if (button.BtnType == SystemButtonType.Close) text = tprov.GetString("MainCloseTooltip"); else if (button.BtnType == SystemButtonType.Minimize) text = tprov.GetString("MainMinimizeTooltip"); }
/// <summary> /// Paints the control. /// </summary> public override void DoPaint(System.Drawing.Graphics g) { // Get character rectangles CharRect[] rects = getCharRects(); // Background using (Brush b = new SolidBrush(ZenParams.WindowColor)) { g.FillRectangle(b, 0, 0, Width, Height); } // Characters if (items != null) { StringFormat sf = StringFormat.GenericTypographic; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; using (Brush b = new SolidBrush(Color.Black)) { for (int i = 0; i != rects.Length; ++i) { RectangleF rect = rects[i].Rect; // Background using (Brush bgb = new SolidBrush(rects[i].BgColor)) { g.FillRectangle(bgb, rect); } // Draw character, if any if (i >= items.Length) { continue; } string str = ""; str += items[i]; HanziRenderer.DrawString(g, str, new PointF(rect.X + charOfsX, rect.Y + charOfsY), b, fontFam, fontScript, fontSize, FontStyle.Regular); } } } // Error message else { StringFormat sf = StringFormat.GenericDefault; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; string line1 = tprov.GetString("CharPickerError1"); string line2 = tprov.GetString("CharPickerError2"); float fontSize = Magic.CharPickerErrorFontSize; using (Font f1 = SystemFontProvider.Instance.GetSystemFont(FontStyle.Bold, fontSize)) using (Font f2 = SystemFontProvider.Instance.GetSystemFont(FontStyle.Regular, fontSize)) using (Brush b = new SolidBrush(Color.Black)) { float padL = 10F * Scale; float padR = 10F * Scale; SizeF sz1 = g.MeasureString(line1, f1, (int)(Width - padL - padR), sf); SizeF sz2 = g.MeasureString(line2, f2, (int)(Width - padL - padR), sf); float hblock = sz1.Height + sz2.Height; PointF pt1 = new PointF(padL, (((float)Height - 2) - hblock) / 2F); PointF pt2 = new PointF(pt1.X, pt1.Y + sz1.Height); g.DrawString(line1, f1, b, pt1); g.DrawString(line2, f2, b, new RectangleF(pt2.X, pt2.Y, Width - pt2.X - 1, Height - pt2.Y - 1)); } } // Border using (Pen p = new Pen(ZenParams.BorderColor)) { g.DrawLine(p, 0, 0, Width, 0); g.DrawLine(p, Width - 1, 0, Width - 1, Height); g.DrawLine(p, Width - 1, Height - 1, 0, Height - 1); g.DrawLine(p, 0, Height - 1, 0, 0); } }
/// <summary> /// Ctor: init. /// </summary> /// <param name="cmdTriggered">Delegate that will be called when a command is issued.</param> /// <param name="entry">Cedict entry to fetch clipboard data from.</param> /// <param name="senseIX">Index of sense over which user right-clicked, or -1.</param> /// <param name="script">Search script (so two Hanzi items are shown if needed).</param> public ResultsCtxtControl(CommandTriggeredDelegate cmdTriggered, ITextProvider tprov, CedictEntry entry, int senseIx, SearchScript script) { this.cmdTriggered = cmdTriggered; this.tprov = tprov; this.entry = entry; this.senseIx = senseIx; this.script = script; InitializeComponent(); BackColor = ZenParams.BorderColor; pnlTop.BackColor = ZenParams.WindowColor; tblFull.BackColor = ZenParams.WindowColor; tblZho.BackColor = ZenParams.WindowColor; tblSense.BackColor = ZenParams.WindowColor; // Display strings string title = tprov.GetString("CtxtCopyTitle"); string fullFormatted, fullCedict, hanzi1, hanzi2, pinyin, sense; getDisplayStrings(tprov, senseIx, out fullFormatted, out fullCedict, out hanzi1, out hanzi2, out pinyin, out sense); lblFullFormatted.Text = fullFormatted; lblFullCedict.Text = fullCedict; lblHanzi1.Text = hanzi1; lblHanzi2.Text = hanzi2; lblPinyin.Text = pinyin; lblSense.Text = sense; // Margin/border tweaks: 1px also at higher DPIs tblLayout.Location = new Point(1, 1); pnlTop.Margin = new Padding(0, 0, 0, 1); tblLayout.RowStyles[1].Height = pnlTop.Height + 1; tblFull.Margin = new Padding(0, 0, 0, 1); tblLayout.RowStyles[1].Height = tblFull.Height + 1; tblZho.Margin = new Padding(0, 0, 0, 1); tblLayout.RowStyles[2].Height = tblZho.Height + 1; tblSense.Margin = new Padding(0, 0, 0, 0); tblLayout.RowStyles[3].Height = tblSense.Height; tblLayout.Height = tblSense.Bottom; // Hide rows we don't need: second hanzi if (hanzi2 == null) { int hHanzi2 = lblHanzi2.Height; tblZho.Controls.Remove(lblHanzi2); lblPinyin.Top = lblHanzi2.Top; lblHanzi2.Dispose(); lblHanzi2 = null; tblZho.Controls.Remove(lblPinyin); tblZho.Controls.Add(lblPinyin, 0, 2); tblZho.RowCount -= 1; tblZho.RowStyles.RemoveAt(2); tblZho.Height -= hHanzi2; tblLayout.RowStyles[2].Height -= hHanzi2; tblLayout.Height -= hHanzi2; } // Sense if (sense == null) { int hSense = tblSense.Height; tblLayout.Controls.Remove(tblSense); tblSense.Dispose(); tblSense = null; tblLayout.RowStyles.RemoveAt(tblLayout.RowStyles.Count - 1); tblLayout.RowCount -= 1; tblLayout.Height -= hSense + 1; } // Label collection for hover int lblCount = 6; if (lblHanzi2 == null) { --lblCount; } if (lblSense == null) { --lblCount; } lblColl = new Label[lblCount]; lblColl[0] = lblFullFormatted; lblColl[1] = lblFullCedict; lblColl[2] = lblHanzi1; int ix = 3; if (lblHanzi2 != null) { lblColl[ix] = lblHanzi2; ++ix; } lblColl[ix] = lblPinyin; ++ix; if (lblSense != null) { lblColl[ix] = lblSense; ++ix; } // Event handling for hover tblFull.CellPaint += onTblLayoutCellPaint; tblZho.CellPaint += onTblLayoutCellPaint; if (tblSense != null) { tblSense.CellPaint += onTblLayoutCellPaint; } }
/// <summary> /// Ctor: init. /// </summary> /// <param name="cmdTriggered">Delegate that will be called when a command is issued.</param> /// <param name="entry">Cedict entry to fetch clipboard data from.</param> /// <param name="senseIX">Index of sense over which user right-clicked, or -1.</param> /// <param name="script">Search script (so two Hanzi items are shown if needed).</param> public ResultsCtxtControl(CommandTriggeredDelegate cmdTriggered, ITextProvider tprov, CedictEntry entry, int senseIx, SearchScript script) { this.cmdTriggered = cmdTriggered; this.tprov = tprov; this.entry = entry; this.senseIx = senseIx; this.script = script; InitializeComponent(); BackColor = ZenParams.BorderColor; pnlTop.BackColor = ZenParams.WindowColor; tblFull.BackColor = ZenParams.WindowColor; tblZho.BackColor = ZenParams.WindowColor; tblSense.BackColor = ZenParams.WindowColor; // Display strings string title = tprov.GetString("CtxtCopyTitle"); string fullFormatted, fullCedict, hanzi1, hanzi2, pinyin, sense; getDisplayStrings(tprov, senseIx, out fullFormatted, out fullCedict, out hanzi1, out hanzi2, out pinyin, out sense); lblFullFormatted.Text = fullFormatted; lblFullCedict.Text = fullCedict; lblHanzi1.Text = hanzi1; lblHanzi2.Text = hanzi2; lblPinyin.Text = pinyin; lblSense.Text = sense; // Margin/border tweaks: 1px also at higher DPIs tblLayout.Location = new Point(1, 1); pnlTop.Margin = new Padding(0, 0, 0, 1); tblLayout.RowStyles[1].Height = pnlTop.Height + 1; tblFull.Margin = new Padding(0, 0, 0, 1); tblLayout.RowStyles[1].Height = tblFull.Height + 1; tblZho.Margin = new Padding(0, 0, 0, 1); tblLayout.RowStyles[2].Height = tblZho.Height + 1; tblSense.Margin = new Padding(0, 0, 0, 0); tblLayout.RowStyles[3].Height = tblSense.Height; tblLayout.Height = tblSense.Bottom; // Hide rows we don't need: second hanzi if (hanzi2 == null) { int hHanzi2 = lblHanzi2.Height; tblZho.Controls.Remove(lblHanzi2); lblPinyin.Top = lblHanzi2.Top; lblHanzi2.Dispose(); lblHanzi2 = null; tblZho.Controls.Remove(lblPinyin); tblZho.Controls.Add(lblPinyin, 0, 2); tblZho.RowCount -= 1; tblZho.RowStyles.RemoveAt(2); tblZho.Height -= hHanzi2; tblLayout.RowStyles[2].Height -= hHanzi2; tblLayout.Height -= hHanzi2; } // Sense if (sense == null) { int hSense = tblSense.Height; tblLayout.Controls.Remove(tblSense); tblSense.Dispose(); tblSense = null; tblLayout.RowStyles.RemoveAt(tblLayout.RowStyles.Count - 1); tblLayout.RowCount -= 1; tblLayout.Height -= hSense + 1; } // Label collection for hover int lblCount = 6; if (lblHanzi2 == null) --lblCount; if (lblSense == null) --lblCount; lblColl = new Label[lblCount]; lblColl[0] = lblFullFormatted; lblColl[1] = lblFullCedict; lblColl[2] = lblHanzi1; int ix = 3; if (lblHanzi2 != null) { lblColl[ix] = lblHanzi2; ++ix; } lblColl[ix] = lblPinyin; ++ix; if (lblSense != null) { lblColl[ix] = lblSense; ++ix; } // Event handling for hover tblFull.CellPaint += onTblLayoutCellPaint; tblZho.CellPaint += onTblLayoutCellPaint; if (tblSense != null) tblSense.CellPaint += onTblLayoutCellPaint; }
/// <summary> /// See <see cref="SetResults"/>. /// </summary> private bool doSetResults(int lookupId, ICedictEntryProvider entryProvider, ReadOnlyCollection <CedictResult> results, SearchScript script) { lock (displayIdLO) { // If we're already too late, don't bother changing display. if (displayId > lookupId) { return(false); } displayId = lookupId; // Empty result set - special handling if (results.Count == 0) { lock (resCtrlsLO) { doDisposeResultControls(); txtResCount = tprov.GetString("ResultsCountNone"); setScrollbarVisibility(false); } // Render doFade(false); MakeMePaint(false, RenderMode.Invalidate); return(true); } } // Decide if we first try with scrollbar visible or not // This is a very rough heuristics (10 results or more), but doesn't matter // Recalc costs much if there are many results, and the number covers that safely bool sbarVisible = results.Count > 10; // Content rectangle height and width int cw, ch; getContentSize(sbarVisible, out cw, out ch); // Create new result controls. At this point, not overwriting old ones! // This is the cycle that takes *long*. List <OneResultControl> newCtrls = new List <OneResultControl>(results.Count); int y = 0; using (Bitmap bmp = new Bitmap(1, 1)) using (Graphics g = Graphics.FromImage(bmp)) { bool canceled = false; for (int rix = 0; rix != results.Count; ++rix) { CedictResult cr = results[rix]; OneResultControl orc = new OneResultControl(null, Scale, tprov, onLookupFromCtrl, onPaintFromCtrl, onGetEntry, entryProvider, cr, script, rix == results.Count - 1); orc.Analyze(g, cw); // Cannot use RelLocation b/c control has no parent yet orc.AbsLocation = new Point(AbsLeft + 1, AbsTop + y + 1); y += orc.Height; newCtrls.Add(orc); // At any point, if we realize lookup ID has changed, we stop // This can happen if a later, quick lookup completes and shows results before us // Checking integers is atomic, no locking if (displayId > lookupId) { canceled = true; break; } } if (canceled) { foreach (OneResultControl orc in newCtrls) { orc.Dispose(); } return(false); } } // OK, last chance to change our mind about showing results. // The rest is synchronized - but it's also fast lock (displayIdLO) { if (displayId > lookupId) { return(false); } displayId = lookupId; // Rest must be invoked on GUI. Otherwise, as we're adding children, // Collections are modified that are also accessed by paint in a resize event handler etc. InvokeOnForm((MethodInvoker) delegate { // Stop any scrolling that may be going on. Cannot scroll what's being replaced. if (sbar.Parent == this) { sbar.StopAnyScrolling(); } // Prevent any painting from worker threads - also accesses collection we're changing lock (resCtrlsLO) { // Get rid of old result controls, remember/own new ones doDisposeResultControls(); resCtrls = newCtrls; foreach (OneResultControl orc in resCtrls) { AddChild(orc); } // Actually show or hide scrollbar as per original decision setScrollbarVisibility(sbarVisible); // Now, by the time we're here, size may have changed // That is unlikely, but then we got to re-layout stuff int cwNew, chNew; getContentSize(sbarVisible, out cwNew, out chNew); if (cwNew != cw || chNew != ch) { reAnalyzeResultsDisplay(); } else { // Everything as big as it used to be... // Change our mind about scrollbar? cw = showOrHideScrollbar(); } } // Results count text if (resCtrls.Count == 1) { txtResCount = tprov.GetString("ResultsCountOne"); } else { txtResCount = tprov.GetString("ResultsCountN"); txtResCount = string.Format(txtResCount, resCtrls.Count); } // Update first visible control's index updateFirstVisibleIdx(); // Render doFade(false); MakeMePaint(false, RenderMode.Invalidate); }); // Done. return(true); } }
private void setTexts(ITextProvider tprov, ICedictEngineFactory dictFact) { // Localized labels lblAbout.Text = tprov.GetString("ZydeoAbout"); lblHeader1.Text = tprov.GetString("ZydeoHeader1"); lblHeader2.Text = tprov.GetString("ZydeoHeader2"); lblSourceCode.Text = tprov.GetString("ZydeoSourceCode"); lblLicense.Text = tprov.GetString("ZydeoLicense"); lblLicenseVal.Text = tprov.GetString("ZydeoLicenseVal"); lblCopyrightVal.Text = tprov.GetString("ZydeoCopyrightVal"); lblCopyright.Text = tprov.GetString("ZydeoCopyright"); lblCharRecogVal.Text = tprov.GetString("ZydeoCharRecogVal"); lblCharRecog.Text = tprov.GetString("ZydeoCharRecog"); lblDictionaryVal.Text = tprov.GetString("ZydeoDictionaryVal"); lblDictionary.Text = tprov.GetString("ZydeoDictionary"); lblVersion.Text = tprov.GetString("ZydeoVersion"); lblWeb.Text = tprov.GetString("ZydeoWeb"); lblUpdates.Text = tprov.GetString("ZydeoUpdates"); chkUpdates.Text = tprov.GetString("ZydeoNotifyUpdates"); // Magic labels: string hard-wired lblWebVal.Text = Magic.WebUrl; lblSourceCodeVal.Text = Magic.GithubUrl; // Runtime data ICedictInfo info = dictFact.GetInfo(Magic.DictFileName); string infoStr = tprov.GetString("ZydeoDictionaryVal"); // Formatting entry count with current locale's thousand separator string entryCountFmt = info.EntryCount.ToString("N0"); // Formatting date in current locale's "short" form string dateFmt = info.Date.ToShortDateString(); infoStr = string.Format(infoStr, dateFmt, entryCountFmt); lblDictionaryVal.Text = infoStr; Version ver = Assembly.GetExecutingAssembly().GetName().Version; lblVersionVal.Text = ver.Major.ToString() + "." + ver.Minor.ToString(); }
/// <summary> /// Gets the HTML for a single sense, not including enclosing paragraph etc., only inline markup. /// </summary> /// <param name="tprov">Text provider if meta-labels (e.g. "Classifier") are to be included. If null, they are stripped.</param> private static string getSenseHtmlPure(ITextProvider tprov, CedictSense sense, SearchScript script) { StringBuilder sb = new StringBuilder(); string strDomain = HybridToHtml(sense.Domain, script); string strEquiv = HybridToHtml(sense.Equiv, script); string strNote = HybridToHtml(sense.Note, script); if (sense.Domain != HybridText.Empty) { if (sense.Domain.EqualsPlainText("CL:")) { if (tprov != null) { sb.Append(templateItalicsOpen); sb.Append(escape(tprov.GetString("ResultCtrlClassifier")) + " "); sb.Append(templateItalicsClose); } } else { sb.Append(templateItalicsOpen); sb.Append(strDomain); sb.Append(templateItalicsClose); } } if (sense.Domain != HybridText.Empty && !sense.Domain.EqualsPlainText("CL:")) if (sense.Equiv != HybridText.Empty || sense.Note != HybridText.Empty) sb.Append(' '); sb.Append(strEquiv); if (sense.Equiv != HybridText.Empty && sense.Note != HybridText.Empty) sb.Append(' '); if (sense.Note != HybridText.Empty) { sb.Append(templateItalicsOpen); sb.Append(strNote); sb.Append(templateItalicsClose); } // Done return sb.ToString(); }
private void setTexts(ITextProvider tprov, ICedictEngineFactory dictFact) { // Localized labels lblAbout.Text =tprov.GetString("ZydeoAbout"); lblHeader1.Text = tprov.GetString("ZydeoHeader1"); lblHeader2.Text = tprov.GetString("ZydeoHeader2"); lblSourceCode.Text = tprov.GetString("ZydeoSourceCode"); lblLicense.Text = tprov.GetString("ZydeoLicense"); lblLicenseVal.Text = tprov.GetString("ZydeoLicenseVal"); lblCopyrightVal.Text = tprov.GetString("ZydeoCopyrightVal"); lblCopyright.Text = tprov.GetString("ZydeoCopyright"); lblCharRecogVal.Text = tprov.GetString("ZydeoCharRecogVal"); lblCharRecog.Text = tprov.GetString("ZydeoCharRecog"); lblDictionaryVal.Text = tprov.GetString("ZydeoDictionaryVal"); lblDictionary.Text = tprov.GetString("ZydeoDictionary"); lblVersion.Text = tprov.GetString("ZydeoVersion"); lblWeb.Text = tprov.GetString("ZydeoWeb"); lblUpdates.Text = tprov.GetString("ZydeoUpdates"); chkUpdates.Text = tprov.GetString("ZydeoNotifyUpdates"); // Magic labels: string hard-wired lblWebVal.Text = Magic.WebUrl; lblSourceCodeVal.Text = Magic.GithubUrl; // Runtime data ICedictInfo info = dictFact.GetInfo(Magic.DictFileName); string infoStr = tprov.GetString("ZydeoDictionaryVal"); // Formatting entry count with current locale's thousand separator string entryCountFmt = info.EntryCount.ToString("N0"); // Formatting date in current locale's "short" form string dateFmt = info.Date.ToShortDateString(); infoStr = string.Format(infoStr, dateFmt, entryCountFmt); lblDictionaryVal.Text = infoStr; Version ver = Assembly.GetExecutingAssembly().GetName().Version; lblVersionVal.Text = ver.Major.ToString() + "." + ver.Minor.ToString(); }
/// <summary> /// Initializes tooltip provider for "search language" or "script" button. /// </summary> /// <param name="button">The actual button.</param> /// <param name="isLang">If true, this is tooltip for "search lang"; otherwise, for "script".</param> /// <param name="tprov">Localized UI strings provider.</param> /// <param name="script">Current search script.</param> /// <param name="lang">Current search language.</param> /// <param name="needleHeight">Needle's height at today's scaling.</param> public SearchOptionsTooltip(ZenGradientButton button, bool isLang, ITextProvider tprov, SearchScript script, SearchLang lang, int needleHeight, int boxRight) { this.button = button; this.needleHeight = needleHeight; this.topOrSide = -boxRight; if (isLang) { if (lang == SearchLang.Chinese) text = tprov.GetString("LangZhoTooltip"); else text = tprov.GetString("LangTrgTooltip"); } else { if (script == SearchScript.Simplified) text = tprov.GetString("ScriptSimpTooltip"); else if (script == SearchScript.Traditional) text = tprov.GetString("ScriptTradTooltip"); else text = tprov.GetString("ScriptBothTooltip"); } }