示例#1
0
 public SettingsControl(ZenControlBase owner, ITextProvider tprov, ICedictEngineFactory dictFact)
     : base(owner)
 {
     ctrlWin = new SettingsControlWin(tprov, dictFact);
     ctrlWin.Size = Size;
     ctrlWin.Location = AbsLocation;
     RegisterWinFormsControl(ctrlWin);
 }
示例#2
0
 public SettingsControl(ZenControlBase owner, ITextProvider tprov, ICedictEngineFactory dictFact)
     : base(owner)
 {
     ctrlWin          = new SettingsControlWin(tprov, dictFact);
     ctrlWin.Size     = Size;
     ctrlWin.Location = AbsLocation;
     RegisterWinFormsControl(ctrlWin);
 }
示例#3
0
        /// <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")));
        }
示例#4
0
        public SettingsControlWin(ITextProvider tprov, ICedictEngineFactory dictFact)
        {
            InitializeComponent();

            setTexts(tprov, dictFact);
            arrangeHeader();

            chkUpdates.Checked = AppSettings.NotifyOfUpdates;
            chkUpdates.CheckedChanged += onUpdatesCheckedChanged;
            lblWebVal.Click += onLinkLabelClick;
            lblSourceCodeVal.Click += onLinkLabelClick;
            lblLicenseVal.Click += onLinkLabelClick;

            setSystemFont();
        }
示例#5
0
        public SettingsControlWin(ITextProvider tprov, ICedictEngineFactory dictFact)
        {
            InitializeComponent();

            setTexts(tprov, dictFact);
            arrangeHeader();

            chkUpdates.Checked         = AppSettings.NotifyOfUpdates;
            chkUpdates.CheckedChanged += onUpdatesCheckedChanged;
            lblWebVal.Click           += onLinkLabelClick;
            lblSourceCodeVal.Click    += onLinkLabelClick;
            lblLicenseVal.Click       += onLinkLabelClick;

            setSystemFont();
        }
示例#6
0
文件: MainForm.cs 项目: sheeeng/Zydeo
        /// <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")));
        }
示例#7
0
        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();
        }
示例#8
0
        /// <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);
        }
示例#9
0
        /// <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);
        }
示例#10
0
        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();
        }