/// <summary> /// Adds a new child control. /// </summary> /// <param name="ctrl">The child to add.</param> protected void AddChild(ZenControlBase ctrl) { // Make sure control is not already a child of me or someone else. if (zenChildren.Contains(ctrl)) { if (ctrl.Parent != this) { throw new InvalidOperationException("Control is already a child of a different parent."); } return; } // Make sure control was not a descendant of a different top-level form before. if (ctrl.parentForm != null && ctrl.parentForm != parentForm && parentForm != null) { throw new InvalidOperationException("Control cannot be added to the hierarchy of a different top-level form."); } // Set control's parent, add to my children ctrl.parent = this; if (parentForm != null) { ctrl.parentForm = parentForm; } zenChildren.Add(ctrl); // Own new control's WinForms controls. IEnumerable <Control> containedWinFormsControls = ctrl.GetWinFormsControlsRecursive(); foreach (Control c in containedWinFormsControls) { AddWinFormsControl(c); } }
/// <summary> /// Relays a control's request to start or stop capturing the mouse, up the chain to top form. /// </summary> /// <param name="ctrl">The control where the request come from.</param> /// <param name="capture">True to start capturing, false to stop.</param> internal virtual void SetControlMouseCapture(ZenControlBase ctrl, bool capture) { if (Parent != null) { Parent.SetControlMouseCapture(ctrl, capture); } }
/// <summary> /// Translates a location in the parent's coordinate system to a control's coordinate system. /// </summary> private Point parentToControl(ZenControlBase ctrl, Point pParent) { int x = pParent.X - ctrl.RelRect.X; int y = pParent.Y - ctrl.RelRect.Y; return(new Point(x, y)); }
public virtual bool DoMouseMove(Point p, MouseButtons button) { bool res = false; ZenControlBase ctrl = GetControl(p); if (ctrl != null) { if (ctrlWithMouse != ctrl) { if (ctrlWithMouse != null) { ctrlWithMouse.DoMouseLeave(); } ctrl.DoMouseEnter(); ctrlWithMouse = ctrl; } ctrl.DoMouseMove(parentToControl(ctrl, p), button); res = true; } else if (ctrlWithMouse != null) { ctrlWithMouse.DoMouseLeave(); ctrlWithMouse = null; } return(res); }
/// <summary> /// Ctor: take parent. /// </summary> /// <param name="parent"></param> internal ZenControlBase(ZenControlBase parent) { // Remember parent. this.parent = parent; // If there is a parent provided at this point... if (parent != null) { // Add myself to parent's children. parent.zenChildren.Add(this); // Find top-level parent, which is the form. ZenControlBase xpar = parent; while (xpar != null && !(xpar is ZenTabbedForm)) { xpar = xpar.Parent; } if (xpar != null) { parentForm = xpar as ZenTabbedForm; } else { parentForm = parent.parentForm; } } }
/// <summary> /// Registers a control for showing tooltips; or removes it if null is passed. /// </summary> internal override sealed void RegisterControlForTooltip(ZenControlBase ctrl, IZenTooltip tt) { lock (tooltipInfos) { // Removing existing tooltip? if (tt == null && tooltipInfos.ContainsKey(ctrl)) { // Tooltip will disappear when timer next hits. tooltipInfos[ctrl].AnimState = float.MinValue; // Make sure timer does hit. SubscribeToTimer(); } // Adding or resetting tooltip? else if (tt != null) { // Not there yet: add now if (!tooltipInfos.ContainsKey(ctrl)) { TooltipInfo tti = new TooltipInfo(tt); tooltipInfos[ctrl] = tti; } // There already: replace; keep animation state; make it repaint else { TooltipInfo ttiExisting = tooltipInfos[ctrl]; TooltipInfo tti = new TooltipInfo(tt); tti.AnimState = ttiExisting.AnimState; tti.Repaint = ttiExisting.AnimState != 0; tooltipInfos[ctrl] = tti; // If we need a repaint, make sure timer does hit. if (tti.Repaint) SubscribeToTimer(); } } } }
/// <summary> /// Adds new subscriber to timer callback. /// </summary> public void Subscribe(ZenControlBase ctrl) { lock (timerSubscribers) { if (!timerSubscribers.Contains(ctrl)) timerSubscribers.Add(ctrl); } }
/// <summary> /// Removes subscriber from timer callback. /// </summary> public void Unsubscribe(ZenControlBase ctrl) { lock (timerSubscribers) { if (timerSubscribers.Contains(ctrl)) timerSubscribers.Remove(ctrl); } }
public SettingsControl(ZenControlBase owner, ITextProvider tprov, ICedictEngineFactory dictFact) : base(owner) { ctrlWin = new SettingsControlWin(tprov, dictFact); ctrlWin.Size = Size; ctrlWin.Location = AbsLocation; RegisterWinFormsControl(ctrlWin); }
/// <summary> /// Signal mouse action to form, to start countdown/animation for showing or hiding tooltip. /// </summary> /// <param name="ctrl">The affected control.</param> /// <param name="enter"> /// <para>If true, countdown for showing begins. If false, animation to take down tooltip begins</para> /// <para>Can be called multiple times with false: hide animation will continue if already in progress.</para> /// <para>If called with false after tooltip has already expired and been hidden, has no effect.</para> /// </param> internal virtual void TooltipMouseAction(ZenControlBase ctrl, bool show) { ZenControlBase parent = Parent; if (parent != null) { parent.TooltipMouseAction(ctrl, show); } }
/// <summary> /// Initializes static members and starts system timer. /// </summary> internal ZenTimer(ZenControlBase parent) { this.parent = parent; timer = new System.Timers.Timer(40); timer.AutoReset = false; timer.Start(); timer.Elapsed += onTimerEvent; }
/// <summary> /// Register/unregister chain. Implemented and sealed by <see cref="ZenTabbedForm"/>. /// </summary> /// <param name="ctrl">Control to register for showing tooltips.</param> /// <param name="tt">Tooltip informatio provider. To show not tooltips, pass null.</param> internal virtual void RegisterControlForTooltip(ZenControlBase ctrl, IZenTooltip tt) { ZenControlBase parent = Parent; if (parent != null) { parent.RegisterControlForTooltip(ctrl, tt); } }
/// <summary> /// Adds new subscriber to timer callback. /// </summary> public void Subscribe(ZenControlBase ctrl) { lock (timerSubscribers) { if (!timerSubscribers.Contains(ctrl)) { timerSubscribers.Add(ctrl); } } }
/// <summary> /// Removes subscriber from timer callback. /// </summary> public void Unsubscribe(ZenControlBase ctrl) { lock (timerSubscribers) { if (timerSubscribers.Contains(ctrl)) { timerSubscribers.Remove(ctrl); } } }
public virtual bool DoMouseUp(Point p, MouseButtons button) { ZenControlBase ctrl = GetControl(p); if (ctrl != null) { return(ctrl.DoMouseUp(parentToControl(ctrl, p), button)); } return(false); }
/// <summary> /// Removes a child control. /// </summary> /// <param name="ctrl">The child to remove.</param> protected void RemoveChild(ZenControlBase ctrl) { IEnumerable <Control> containedWinFormsControls = ctrl.GetWinFormsControlsRecursive(); foreach (Control c in containedWinFormsControls) { RemoveWinFormsControl(c); } zenChildren.Remove(ctrl); ctrl.parent = null; }
public virtual void DoMouseLeave() { // Let parent form know so it can hide any visible tooltip. TooltipMouseAction(this, false); // Forward leave notifiation to any affected child control. if (ctrlWithMouse != null) { ctrlWithMouse.DoMouseLeave(); ctrlWithMouse = null; } }
/// <summary> /// Ctor: take parent. /// </summary> public ZenScrollBar(ZenControlBase parent, SubscribeScrollTimerDelegate subscribeScrollTimer) : base(parent) { this.subscribeScrollTimer = subscribeScrollTimer; Width = (int)(Scale * ((float)ZenParams.ScrollBarWidth)); pad = Width / 4; acceleration = acceleration * Scale; deceleration = deceleration * Scale; maxSpeed = maxSpeed * Scale; doInitAnimVals(); Application.AddMessageFilter(this); }
protected virtual void InvokeOnForm(Delegate method) { // Invoke comes from background thread. In the UI thread, parent may just have been removed. // If I have no parent, silently do not invoke. // Happens when an animation is in progress and user switches to different tab in top form ZenControlBase parent = Parent; if (parent != null) { parent.InvokeOnForm(method); } }
/// <summary> /// Handles UI changes (mouse enter, leave etc.) affecting tooltip visibility /// </summary> internal override sealed void TooltipMouseAction(ZenControlBase ctrl, bool show) { lock (tooltipInfos) { // Control does not have a tooltip - nothing to do if (!tooltipInfos.ContainsKey(ctrl)) return; TooltipInfo tti = tooltipInfos[ctrl]; // Mouse enter: fade in from 0, or fade back in if (show) { // Currently nowhere: start countdown to show if (tti.AnimState == 0) tti.AnimState = 0.01F; // Countdown already in progress or already fading in: nothing to do else if (tti.AnimState > 0 && tti.AnimState <= 100) { /* NOP */ } // Currently fading out: fade back in else if (tti.AnimState > 300) { // Already practically faded out: start fade-in all over again if (tti.AnimState > 399) tti.AnimState = 200.01F; // Otherwise, fade back in from same place else tti.AnimState = 100.01F + (400F - tti.AnimState); } // Countdown to hide is in progress: keep as is // float.MinValue to remove highlight: keep as is else { /* NOP */ } // For mouse enter, we always want to make sure timer is running SubscribeToTimer(); } // Mouse leave, or other reason to take down tooltip else { // Currently not shown: nothing to do; also not start timer b/c of this. if (tti.AnimState == 0) return; // Currently counting down to show: reset to not shown; do not request timer if (tti.AnimState > 0 && tti.AnimState <= 99.09F) { tti.AnimState = 0; return; } // All other state changes will require timer SubscribeToTimer(); // Not faded in much yet: just make it disappear if (tti.AnimState < 101F) { tti.AnimState = 0; tti.Repaint = true; } // Fading in: reverse else if (tti.AnimState > 100F && tti.AnimState < 199F) tti.AnimState = 300F + (200F - tti.AnimState); // Fully shown, not yet fading out: fade out else if (tti.AnimState < 301F) tti.AnimState = 300F; // Otherwise, it's request to remove (float.MinValue) or already fading out: no change else { /* NOP */ } } } }
/// <summary> /// Triggers a callback to control's <see cref="DoPaint"/>, then re-renders canvas. /// </summary> /// <param name="needBackground">If true, full canvas is repainted to control can render over stuff outside it's own rectangle.</param> /// <param name="rm">Determines when canvas is re-rendered after painting.</param> protected void MakeMePaint(bool needBackground, RenderMode rm) { // Request comes from background thread. In the UI thread, parent may just have been removed. // If I have no parent, silently do not invoke. // Happens when an animation is in progress and user switches to different tab in top form ZenControlBase parent = Parent; if (parent != null) { ControlToPaint[] ctrls = new ControlToPaint[1]; ctrls[0] = new ControlToPaint(this, needBackground, rm); parent.MakeControlsPaint(new ReadOnlyCollection <ControlToPaint>(ctrls)); } }
public virtual bool DoMouseClick(Point p, MouseButtons button) { ZenControlBase ctrl = GetControl(p); if (ctrl != null) { return(ctrl.DoMouseClick(parentToControl(ctrl, p), button)); } else if (MouseClick != null) { MouseClick(this); } return(true); }
/// <summary> /// Ctor: take parent. /// </summary> /// <param name="parent"></param> internal ZenControlBase(ZenControlBase parent) { // Remember parent. this.parent = parent; // If there is a parent provided at this point... if (parent != null) { // Add myself to parent's children. parent.zenChildren.Add(this); // Find top-level parent, which is the form. ZenControlBase xpar = parent; while (xpar != null && !(xpar is ZenTabbedForm)) xpar = xpar.Parent; if (xpar != null) parentForm = xpar as ZenTabbedForm; else parentForm = parent.parentForm; } }
/// <summary> /// Set or clears the control receiving the mouse capture. /// </summary> internal sealed override void SetControlMouseCapture(ZenControlBase ctrl, bool capture) { if (capture) { ctrlCapturingMouse = ctrl; form.Capture = true; } else if (ctrl == ctrlCapturingMouse) { ctrlCapturingMouse = null; } if (ctrlCapturingMouse == null) { form.Capture = false; } }
/// <summary> /// Handles UI changes (mouse enter, leave etc.) affecting tooltip visibility /// </summary> internal sealed override void TooltipMouseAction(ZenControlBase ctrl, bool show) { lock (tooltipInfos) { // Control does not have a tooltip - nothing to do if (!tooltipInfos.ContainsKey(ctrl)) { return; } TooltipInfo tti = tooltipInfos[ctrl]; // Mouse enter: fade in from 0, or fade back in if (show) { // Currently nowhere: start countdown to show if (tti.AnimState == 0) { tti.AnimState = 0.01F; } // Countdown already in progress or already fading in: nothing to do else if (tti.AnimState > 0 && tti.AnimState <= 100) /* NOP */ } {
public virtual void DoMouseEnter() { // Let parent form know so it can show tooltips if needed. TooltipMouseAction(this, true); // Forward leave/enter notifiations to any affected child controls. Point pAbs = MousePositionAbs; Point pRel = new Point(pAbs.X - AbsLeft, pAbs.Y - AbsTop); ZenControlBase ctrl = GetControl(pRel); if (ctrl != null) { if (ctrlWithMouse != ctrl) { if (ctrlWithMouse != null) { ctrlWithMouse.DoMouseLeave(); } ctrl.DoMouseEnter(); ctrlWithMouse = ctrl; } } }
/// <summary> /// Handles click on a tab header (to switch tabs). /// </summary> /// <param name="sender"></param> private void onTabCtrlClick(ZenControlBase sender) { ZenTabControl ztc = sender as ZenTabControl; // Click on active tab - nothing to do if (ztc.IsMain && activeTabIdx == -1) { return; } int idx = contentTabControls.IndexOf(ztc); if (idx == activeTabIdx) { return; } // Switching to main if (idx == -1) { contentTabControls[activeTabIdx].Selected = false; mainTabCtrl.Selected = true; RemoveChild(tabs[activeTabIdx].Ctrl); AddChild(mainTab.Ctrl); activeTabIdx = -1; } // Switching away to a content tab else { mainTabCtrl.Selected = false; contentTabControls[idx].Selected = true; RemoveChild(mainTab.Ctrl); AddChild(tabs[idx].Ctrl); activeTabIdx = idx; } // Newly active contol still has old size if window was resized arrangeControls(); // Refresh doRepaint(); form.Invalidate(); }
/// <summary> /// Registers a control for showing tooltips; or removes it if null is passed. /// </summary> internal sealed override void RegisterControlForTooltip(ZenControlBase ctrl, IZenTooltip tt) { lock (tooltipInfos) { // Removing existing tooltip? if (tt == null && tooltipInfos.ContainsKey(ctrl)) { // Tooltip will disappear when timer next hits. tooltipInfos[ctrl].AnimState = float.MinValue; // Make sure timer does hit. SubscribeToTimer(); } // Adding or resetting tooltip? else if (tt != null) { // Not there yet: add now if (!tooltipInfos.ContainsKey(ctrl)) { TooltipInfo tti = new TooltipInfo(tt); tooltipInfos[ctrl] = tti; } // There already: replace; keep animation state; make it repaint else { TooltipInfo ttiExisting = tooltipInfos[ctrl]; TooltipInfo tti = new TooltipInfo(tt); tti.AnimState = ttiExisting.AnimState; tti.Repaint = ttiExisting.AnimState != 0; tooltipInfos[ctrl] = tti; // If we need a repaint, make sure timer does hit. if (tti.Repaint) { SubscribeToTimer(); } } } } }
/// <summary> /// Ctor: takes parent. /// </summary> /// <param name="parent">The control's parent (owner).</param> public ZenControl(ZenControlBase parent) : base(parent) { }
/// <summary> /// Translates a location in the parent's coordinate system to a control's coordinate system. /// </summary> private Point parentToControl(ZenControlBase ctrl, Point pParent) { int x = pParent.X - ctrl.RelRect.X; int y = pParent.Y - ctrl.RelRect.Y; return new Point(x, y); }
/// <summary> /// Ctor: take parent. /// </summary> public ZenGradientButton(ZenControlBase parent) : base(parent) { font = SystemFontProvider.Instance.GetSystemFont(FontStyle.Regular, ZenParams.StandardFontSize); }
/// <summary> /// Signal mouse action to form, to start countdown/animation for showing or hiding tooltip. /// </summary> /// <param name="ctrl">The affected control.</param> /// <param name="enter"> /// <para>If true, countdown for showing begins. If false, animation to take down tooltip begins</para> /// <para>Can be called multiple times with false: hide animation will continue if already in progress.</para> /// <para>If called with false after tooltip has already expired and been hidden, has no effect.</para> /// </param> internal virtual void TooltipMouseAction(ZenControlBase ctrl, bool show) { ZenControlBase parent = Parent; if (parent != null) parent.TooltipMouseAction(ctrl, show); }
/// <summary> /// Ctor: init immutable instance. /// </summary> public ControlToPaint(ZenControlBase ctrl, bool needBackground, RenderMode renderMode) { Ctrl = ctrl; NeedBackground = needBackground; RenderMode = renderMode; }
/// <summary> /// Register/unregister chain. Implemented and sealed by <see cref="ZenTabbedForm"/>. /// </summary> /// <param name="ctrl">Control to register for showing tooltips.</param> /// <param name="tt">Tooltip informatio provider. To show not tooltips, pass null.</param> internal virtual void RegisterControlForTooltip(ZenControlBase ctrl, IZenTooltip tt) { ZenControlBase parent = Parent; if (parent != null) parent.RegisterControlForTooltip(ctrl, tt); }
/// <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> /// Event handler: "clear strokes" button clicked. /// </summary> void onClearWritingPad(ZenControlBase sender) { writingPad.Clear(); // Button states will be updated in "strokes changed" event handler. }
/// <summary> /// Set or clears the control receiving the mouse capture. /// </summary> internal override sealed void SetControlMouseCapture(ZenControlBase ctrl, bool capture) { if (capture) { ctrlCapturingMouse = ctrl; form.Capture = true; } else if (ctrl == ctrlCapturingMouse) ctrlCapturingMouse = null; if (ctrlCapturingMouse == null) form.Capture = false; }
/// <summary> /// Handles click on close button. /// </summary> private void onCloseClick(ZenControlBase sender) { form.Close(); }
/// <summary> /// Ctor: takes data to display. /// </summary> /// <param name="owner">Zen control that owns me.</param> /// <param name="tprov">Localized display text provider.</param> /// <param name="lookupThroughLink">Delegate to call when user initiates lookup by clicking on a link.</param> /// <param name="getEntry">Delegate to call when an entry must be retrieved (for "copy" context menu).</param> /// <param name="entryProvider">Dictionary entry provider.</param> /// <param name="cr">The lookup result this control will show.</param> /// <param name="maxHeadLength">Longest headword in full results list.</param> /// <param name="script">Scripts to show in headword.</param> /// <param name="odd">Odd/even position in list, for alternating BG color.</param> public OneResultControl(ZenControlBase owner, float scale, ITextProvider tprov, LookupThroughLinkDelegate lookupThroughLink, ParentPaintDelegate parentPaint, GetEntryDelegate getEntry, ICedictEntryProvider entryProvider, CedictResult cr, SearchScript script, bool last) : base(owner) { this.scale = scale; this.tprov = tprov; this.lookupThroughLink = lookupThroughLink; this.parentPaint = parentPaint; this.getEntry = getEntry; this.entry = entryProvider.GetEntry(cr.EntryId); this.res = cr; this.analyzedScript = script; this.last = last; padLeft = (int)(5.0F * scale); padTop = (int)(4.0F * scale); padBottom = (int)(8.0F * scale); padMid = (int)(20.0F * scale); padRight = (int)(10.0F * scale); }
/// <summary> /// Ctor: takes owner. /// </summary> public ZenImageButton(ZenControlBase parent) : base(parent) { }
/// <summary> /// Event handler: search language button clicked. /// </summary> private void onSearchLang(ZenControlBase sender) { // Toggle between English and Chinese if (searchLang == SearchLang.Chinese) searchLang = SearchLang.Target; else searchLang = SearchLang.Chinese; // Update button searchLangChanged(); }
public virtual void DoMouseEnter() { // Let parent form know so it can show tooltips if needed. TooltipMouseAction(this, true); // Forward leave/enter notifiations to any affected child controls. Point pAbs = MousePositionAbs; Point pRel = new Point(pAbs.X - AbsLeft, pAbs.Y - AbsTop); ZenControlBase ctrl = GetControl(pRel); if (ctrl != null) { if (ctrlWithMouse != ctrl) { if (ctrlWithMouse != null) ctrlWithMouse.DoMouseLeave(); ctrl.DoMouseEnter(); ctrlWithMouse = ctrl; } } }
/// <summary> /// Event handler: script selector button clicked. /// </summary> private void onSimpTrad(ZenControlBase sender) { // Next in row int scri = (int)searchScript; ++scri; if (scri > 2) scri = 0; searchScript = (SearchScript)scri; // Update button simpTradChanged(); // Change character picker's font // Only if it really changes - triggers calibration ctrlCharPicker.FontScript = searchScript == SearchScript.Traditional ? IdeoScript.Trad : IdeoScript.Simp; // Re-recognize strokes, if there are any startNewCharRecog(writingPad.Strokes); }
public virtual bool DoMouseMove(Point p, MouseButtons button) { bool res = false; ZenControlBase ctrl = GetControl(p); if (ctrl != null) { if (ctrlWithMouse != ctrl) { if (ctrlWithMouse != null) ctrlWithMouse.DoMouseLeave(); ctrl.DoMouseEnter(); ctrlWithMouse = ctrl; } ctrl.DoMouseMove(parentToControl(ctrl, p), button); res = true; } else if (ctrlWithMouse != null) { ctrlWithMouse.DoMouseLeave(); ctrlWithMouse = null; } return res; }
/// <summary> /// Event handler: "undo last stroke" button clicked. /// </summary> void onUndoStroke(ZenControlBase sender) { writingPad.UndoLast(); // Button states will be updated in "strokes changed" event handler. }
/// <summary> /// Relays a control's request to start or stop capturing the mouse, up the chain to top form. /// </summary> /// <param name="ctrl">The control where the request come from.</param> /// <param name="capture">True to start capturing, false to stop.</param> internal virtual void SetControlMouseCapture(ZenControlBase ctrl, bool capture) { if (Parent != null) Parent.SetControlMouseCapture(ctrl, capture); }
/// <summary> /// Adds a new child control. /// </summary> /// <param name="ctrl">The child to add.</param> protected void AddChild(ZenControlBase ctrl) { // Make sure control is not already a child of me or someone else. if (zenChildren.Contains(ctrl)) { if (ctrl.Parent != this) throw new InvalidOperationException("Control is already a child of a different parent."); return; } // Make sure control was not a descendant of a different top-level form before. if (ctrl.parentForm != null && ctrl.parentForm != parentForm && parentForm != null) throw new InvalidOperationException("Control cannot be added to the hierarchy of a different top-level form."); // Set control's parent, add to my children ctrl.parent = this; if (parentForm != null) ctrl.parentForm = parentForm; zenChildren.Add(ctrl); // Own new control's WinForms controls. IEnumerable<Control> containedWinFormsControls = ctrl.GetWinFormsControlsRecursive(); foreach (Control c in containedWinFormsControls) AddWinFormsControl(c); }
/// <summary> /// Handles click on minimize button. /// </summary> void onMinimizeClick(ZenControlBase sender) { form.WindowState = FormWindowState.Minimized; }
/// <summary> /// Removes a child control. /// </summary> /// <param name="ctrl">The child to remove.</param> protected void RemoveChild(ZenControlBase ctrl) { IEnumerable<Control> containedWinFormsControls = ctrl.GetWinFormsControlsRecursive(); foreach (Control c in containedWinFormsControls) RemoveWinFormsControl(c); zenChildren.Remove(ctrl); ctrl.parent = null; }
/// <summary> /// Handles click on a tab header (to switch tabs). /// </summary> /// <param name="sender"></param> private void onTabCtrlClick(ZenControlBase sender) { ZenTabControl ztc = sender as ZenTabControl; // Click on active tab - nothing to do if (ztc.IsMain && activeTabIdx == -1) return; int idx = contentTabControls.IndexOf(ztc); if (idx == activeTabIdx) return; // Switching to main if (idx == -1) { contentTabControls[activeTabIdx].Selected = false; mainTabCtrl.Selected = true; RemoveChild(tabs[activeTabIdx].Ctrl); AddChild(mainTab.Ctrl); activeTabIdx = -1; } // Switching away to a content tab else { mainTabCtrl.Selected = false; contentTabControls[idx].Selected = true; RemoveChild(mainTab.Ctrl); AddChild(tabs[idx].Ctrl); activeTabIdx = idx; } // Newly active contol still has old size if window was resized arrangeControls(); // Refresh doRepaint(); form.Invalidate(); }
/// <summary> /// Ctor: init immutable instance. /// </summary> public TooltipToPaint(ZenControlBase ctrl, TooltipInfo tti, float strength) { Ctrl = ctrl; TTI = tti; Strength = strength; }