예제 #1
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;
            }
        }
예제 #2
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;
        }