private void RemoveEditFormUICustomisations(EditAutoTypeItemForm editForm) { var extraControls = editForm.Controls.Find(ExtraControlsName, false).FirstOrDefault(); var container = editForm.Controls.Find(ExistingControlsContainerName, false).FirstOrDefault(); if (extraControls == null || container == null) { Debug.Fail("Form not customised"); return; } editForm.SuspendLayout(); try { var acceptButton = editForm.AcceptButton; var cancelButton = editForm.CancelButton; var shiftAmount = extraControls.Height; editForm.Controls.Remove(container); editForm.Controls.Remove(extraControls); if (editForm.MinimumSize.Height != 0) { editForm.MinimumSize = new Size(editForm.MinimumSize.Width, editForm.MinimumSize.Height - shiftAmount); } editForm.Height -= shiftAmount; foreach (var control in container.Controls.Cast <Control>().ToArray()) { editForm.Controls.Add(control); } container.Dispose(); extraControls.Dispose(); editForm.AcceptButton = acceptButton; editForm.CancelButton = cancelButton; } finally { editForm.ResumeLayout(); } }
private void textBoxHotKeySequence_Click(object sender, EventArgs e) { AutoTypeConfig autoTypeConfig = new AutoTypeConfig(); if (textBoxHotKeySequence.Text != KeeOtp2Ext.BuiltInTotpPlaceHolder) { autoTypeConfig.DefaultSequence = textBoxHotKeySequence.Text; } EditAutoTypeItemForm eatf = new EditAutoTypeItemForm(); eatf.InitEx(autoTypeConfig, -1, true, KeeOtp2Ext.BuiltInTotpPlaceHolder, null); eatf.ShowDialog(); if (eatf.DialogResult == DialogResult.OK && autoTypeConfig.DefaultSequence != string.Empty) { textBoxHotKeySequence.Text = autoTypeConfig.DefaultSequence; } else { textBoxHotKeySequence.Text = KeeOtp2Ext.BuiltInTotpPlaceHolder; } }
private void bSequenceEdit_Click(object sender, EventArgs e) { EditAutoTypeItemForm dlg = new EditAutoTypeItemForm(); AutoTypeConfig atc = new AutoTypeConfig(); if (string.IsNullOrEmpty(rtbSequence.Text)) { atc.DefaultSequence = PasswordChangeAssistantExt.GetPCASequence(PasswordChangeAssistantExt.SelectedEntry, PluginTranslate.DefaultSequence01); } else { atc.DefaultSequence = rtbSequence.Text; } dlg.InitEx(atc, -1, true, rtbSequence.Text, m_pcadata.Strings); dlg.Text = KPRes.ConfigureKeystrokeSeq; Control cCustomSequence = Tools.GetControl("m_rbKeySeq", dlg); Control cFirst = Tools.GetControl("m_lblTargetWindow", dlg); if ((cCustomSequence != null) && (cFirst != null)) { int y = cCustomSequence.Top - cFirst.Top; HideControl("m_lblTargetWindow", dlg); HideControl("m_rbSeqDefault", dlg); HideControl("m_cmbWindow", dlg); HideControl("m_lblOpenHint", dlg); HideControl("m_lnkWildcardRegexHint", dlg); HideControl("m_rbSeqCustom", dlg); MoveControlUp("m_rbKeySeq", y, dlg); MoveControlUp("m_lblKeySeqInsertInfo", y, dlg); MoveControlUp("m_rtbPlaceholders", y, dlg); Tools.GetControl("m_rtbPlaceholders", dlg).Height += y; } if (UIUtil.ShowDialogAndDestroy(dlg) == DialogResult.OK) { rtbSequence.Text = atc.DefaultSequence; } }
private static void ApplyKeeResizeHack(EditAutoTypeItemForm editForm, int shiftAmount) { // KeeResize hack - KeeResize will automatically grow the items on the form when it resizes, which doesn't play nicely with having them moved from their original locations. // To fix this, intercept the resize event for KeeResize and lie about the size of the form. var eventsProperty = editForm.GetType().GetProperty("Events", BindingFlags.NonPublic | BindingFlags.Instance); if (eventsProperty != null) { var events = eventsProperty.GetValue(editForm, null) as EventHandlerList; var resizeEventKeyField = typeof(Control).GetField("EventResize", BindingFlags.NonPublic | BindingFlags.Static); if (resizeEventKeyField != null) { var resizeEventKey = resizeEventKeyField.GetValue(editForm); var resizeEvent = events[resizeEventKey]; if (resizeEvent != null) { var keeResizeEventHandler = resizeEvent.GetInvocationList().FirstOrDefault(eventHandler => eventHandler.Method.DeclaringType.FullName == "KeeResizeLib.FormResizer"); if (keeResizeEventHandler != null) { events.RemoveHandler(resizeEventKey, keeResizeEventHandler); var heightField = typeof(Control).GetField("height", BindingFlags.NonPublic | BindingFlags.Instance); if (heightField != null) { // Discover minimum height var controlInfoField = keeResizeEventHandler.Target.GetType().GetField("ControlInfo", BindingFlags.Public | BindingFlags.Instance); if (controlInfoField != null) { var controlInfo = controlInfoField.GetValue(keeResizeEventHandler.Target); if (controlInfo != null) { var orgHField = controlInfo.GetType().GetField("OrgH", BindingFlags.Public | BindingFlags.Instance); if (orgHField != null) { var orgH = orgHField.GetValue(controlInfo) as int?; if (orgH != null) { // Enforce this as a minimum size editForm.MinimumSize = new Size(Math.Max(editForm.MinimumSize.Height, orgH.Value), editForm.MinimumSize.Width); } } } } // Intercept all future resizes to lie about the height to KeeResize editForm.Resize += (o, e) => { var realHeight = (int)heightField.GetValue(editForm); heightField.SetValue(editForm, realHeight - shiftAmount); try { keeResizeEventHandler.DynamicInvoke(o, e); } finally { heightField.SetValue(editForm, realHeight); } }; } } } } } }
private void CustomiseEditFormUI(EditAutoTypeItemForm editForm) { if (editForm.Controls.Find(ExtraControlsName, false).Any()) { Debug.Fail("Form already customised"); return; } var editSequenceOnlyField = typeof(EditAutoTypeItemForm).GetField("m_bEditSequenceOnly", BindingFlags.Instance | BindingFlags.NonPublic); if (editSequenceOnlyField != null) { if (editSequenceOnlyField.GetValue(editForm) as bool? == true) { // This is a sequence-only edit window, so don't customise it. return; } } editForm.SuspendLayout(); try { var banner = editForm.Controls.Find("m_bannerImage", false).FirstOrDefault(); var placeholders = editForm.Controls.Find("m_rtbPlaceholders", false).FirstOrDefault(); // Add the new control, docked just below the banner var extraControls = new EditAutoTypeExtraControls(editForm) { Name = ExtraControlsName, Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right, AutoSizeMode = AutoSizeMode.GrowOnly, }; editForm.Controls.Add(extraControls); editForm.Controls.SetChildIndex(extraControls, 0); if (banner != null) { extraControls.Top = banner.Bottom; extraControls.MinimumSize = new Size(banner.Width, 0); } var shiftAmount = extraControls.Height; // Move all existing controls, except for the banner and the extra controls, into a container var container = new Panel { Name = ExistingControlsContainerName, Size = editForm.ClientSize, Location = Point.Empty, Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom, }; var acceptButton = editForm.AcceptButton; var cancelButton = editForm.CancelButton; foreach (var control in editForm.Controls.Cast <Control>().ToArray()) { if (control != banner && control != extraControls) { container.Controls.Add(control); } } editForm.AcceptButton = acceptButton; editForm.CancelButton = cancelButton; if (editForm.FormBorderStyle == FormBorderStyle.Sizable) { ApplyKeeResizeHack(editForm, shiftAmount); } // Resize the form editForm.Height += shiftAmount; if (editForm.MinimumSize.Height != 0) { editForm.MinimumSize = new Size(editForm.MinimumSize.Width, editForm.MinimumSize.Height + shiftAmount); } // Then put the container panel back on the form, shifted downwards container.Top = shiftAmount; editForm.Controls.Add(container); } finally { editForm.ResumeLayout(); } editForm.FormClosing += OnEditFormClosing; }
public EditAutoTypeExtraControls(EditAutoTypeItemForm parent) : this() { mParent = parent; mWindowTitleControls = (from controlName in new[] { "m_lblOpenHint", "m_lblOpenHint", "m_lblTargetWindow", "m_lnkWildcardRegexHint" } let control = FindControl(controlName) where control != null select control).ToList(); m_cmbWindow = FindControl("m_cmbWindow") as ImageComboBoxEx; if (m_cmbWindow == null) { System.Diagnostics.Debug.Fail("Could not find combo window"); m_cmbWindow = new ImageComboBoxEx(); // Create null stub to avoid crashing out } m_cmbWindow.TextChanged += m_cmbWindow_TextChanged; // Create an Imposter combo box over it mWindowTitleComboImposter = new ImageComboBoxEx { IntegralHeight = false, Name = "mWindowTitleComboImposter", TabIndex = m_cmbWindow.TabIndex, }; mWindowTitleComboImposter.TextChanged += mWindowTitleComboImposter_TextChanged; mWindowTitleComboImposter.DropDown += mWindowTitleComboImposter_DropDown; // Track changes to size and position and items m_cmbWindow.LocationChanged += SyncComboImposter; m_cmbWindow.SizeChanged += SyncComboImposter; // Ignore any direct changes itself mWindowTitleComboImposter.LocationChanged += SyncComboImposter; // Take initial values SyncComboImposter(null, EventArgs.Empty); // Replace the combo with its imposter m_cmbWindow.Parent.Controls.Add(mWindowTitleComboImposter); m_cmbWindow.Visible = false; mWindowTitleControls.Add(mWindowTitleComboImposter); // Add a separator between the two groups of radio buttons mSeparator = new Label { BorderStyle = BorderStyle.Fixed3D, Location = new Point(SeparatorIndent, mWindowTitleControls.Max(c => c.Bottom) + 7), Size = new Size(mParent.ClientSize.Width - SeparatorIndent * 2, 2), Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right, TabStop = false, }; m_cmbWindow.Parent.Controls.Add(mSeparator); }