Ejemplo n.º 1
0
        private void OnFieldFormatLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            CsvFieldType t = GetCsvFieldType();

            string strUrl = null;

            if (IsTimeField(t))
            {
                strUrl = "https://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx";
            }
            // else if(t == CsvFieldType.Group)
            // {
            //	AppHelp.ShowHelp(AppDefs.HelpTopics.ImportExport,
            //		AppDefs.HelpTopics.ImportExportGenericCsv);
            //	return;
            // }
            else
            {
                Debug.Assert(false); return;
            }

            WinUtil.OpenUrl(strUrl, null);
        }
Ejemplo n.º 2
0
        private void OpenUrl(string strUrl)
        {
            /* if(!KeePassLib.Native.NativeLib.IsUnix())
            *  {
            *       // Process.Start has a considerable delay when opening URLs
            *       // here (different thread, etc.), therefore try the native
            *       // ShellExecute first (which doesn't have any delay)
            *       try
            *       {
            *               IntPtr h = NativeMethods.ShellExecute(this.Handle,
            *                       null, strUrl, null, null, NativeMethods.SW_SHOW);
            *               long l = h.ToInt64();
            *               if((l < 0) || (l > 32)) return;
            *               else { Debug.Assert(false); }
            *       }
            *       catch(Exception) { Debug.Assert(false); }
            *  }
            *
            *  try { NativeLib.StartProcess(strUrl); }
            *  catch(Exception) { Debug.Assert(false); } */

            WinUtil.OpenUrl(strUrl, null);             // Thread-safe
        }
Ejemplo n.º 3
0
        private void OnRichTextBoxLinkClicked(object sender, LinkClickedEventArgs e)
        {
            try
            {
                string strLink = e.LinkText;
                if (string.IsNullOrEmpty(strLink))
                {
                    Debug.Assert(false); return;
                }

                if ((strLink == m_strDataExpand) && (m_tscViewers.Text == m_strViewerHex))
                {
                    m_bDataExpanded = true;
                    UpdateHexView();
                    m_rtbText.Select(m_rtbText.TextLength, 0);
                    m_rtbText.ScrollToCaret();
                }
                else
                {
                    WinUtil.OpenUrl(strLink, null);
                }
            }
            catch (Exception) { }            // ScrollToCaret might throw (but still works)
        }
Ejemplo n.º 4
0
 private void OnLinkDonate(object sender, LinkLabelLinkClickedEventArgs e)
 {
     WinUtil.OpenUrl(PwDefs.DonationsUrl, null);
     this.Close();
 }
Ejemplo n.º 5
0
 private void OnLinkHomepage(object sender, LinkLabelLinkClickedEventArgs e)
 {
     WinUtil.OpenUrl(PwDefs.HomepageUrl, null);
     this.Close();
 }
Ejemplo n.º 6
0
 private void OnBtnGetMore(object sender, EventArgs e)
 {
     WinUtil.OpenUrl(PwDefs.PluginsUrl, null);
 }
Ejemplo n.º 7
0
 private void OnTextLinkClicked(object sender, LinkClickedEventArgs e)
 {
     WinUtil.OpenUrl(e.LinkText, null);
 }
Ejemplo n.º 8
0
 private void OnBtnGetMore(object sender, EventArgs e)
 {
     WinUtil.OpenUrl(PwDefs.TranslationsUrl, null);
     this.DialogResult = DialogResult.Cancel;
 }
Ejemplo n.º 9
0
        private bool InitializeChildView(TabPage page, String uuid)
        {
            if (et_to_label != null)
            {
                add_child_items_to_tab(page);
                return(true);
            }
            SetBaseSizes(page);
            init_pwgen_button();

            et_to_label       = new Dictionary <EntryTemplate, Label>();
            et_to_control     = new Dictionary <EntryTemplate, Control>();
            et_to_secure_edit = new Dictionary <EntryTemplate, SecureTextBoxEx>();
            et_to_control2    = new Dictionary <EntryTemplate, Control>();
            SecureTextBoxEx entry_pass         = null;
            SecureTextBoxEx entry_pass_confirm = null;

            int     control_offset_y = DpiUtil.ScaleIntY(10);
            PwUuid  par_uuid         = new PwUuid(KeePassLib.Utility.MemUtil.HexStringToByteArray(uuid));
            PwEntry par_template     = m_host.Database.RootGroup.FindEntry(par_uuid, true);

            if (par_template == null)
            {
                return(false);
            }
            if (par_template.Strings.Get("_etm_template") == null)
            {
                return(false);
            }
            List <EntryTemplate> cur = parse_entry(par_template.Strings);


            foreach (EntryTemplate t in cur)
            {
                Label label = new Label();
                label.Text = t.title + ":";
                //label.AutoSize = false;
                label.Top      = control_offset_y;
                label.AutoSize = false;
                SetControlSizing(null, label);
                label.AutoEllipsis = true;
                label.TextAlign    = ContentAlignment.MiddleRight;
                FontUtil.AssignDefaultBold(label);

                et_to_label[t] = label;
                if (t.type == "Divider")
                {
                    label.Font       = new Font(label.Font.FontFamily, label.Font.Size * 1.1f, FontStyle.Bold | FontStyle.Underline);
                    label.TextAlign  = ContentAlignment.BottomLeft;
                    label.Text       = t.title;              //remove :
                    et_to_control[t] = null;
                }
                else if (t.type == "Checkbox")
                {
                    CheckBox checkbox = new CheckBox();
                    checkbox.Top     = control_offset_y;
                    et_to_control[t] = checkbox;
                }
                else if (t.type == "Listbox")
                {
                    ComboBox combobox = new ComboBox();
                    combobox.Top     = control_offset_y;
                    et_to_control[t] = combobox;
                    if (!String.IsNullOrEmpty(t.options))
                    {
                        String[] opts = t.options.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (String opt in opts)
                        {
                            combobox.Items.Add(opt.Trim());
                        }
                    }
                }
                else if (t.type == "Date" || t.type == "Time" || t.type == "Date Time")
                {
                    DateTimePicker picker = new DateTimePicker();
                    picker.Top          = control_offset_y;
                    picker.CustomFormat = "";
                    picker.Format       = DateTimePickerFormat.Custom;
                    if (t.type == "Date" || t.type == "Date Time")
                    {
                        picker.CustomFormat = System.Globalization.DateTimeFormatInfo.CurrentInfo.ShortDatePattern;
                    }
                    if (t.type == "Date Time")
                    {
                        picker.CustomFormat += " ";
                    }
                    if (t.type == "Time" || t.type == "Date Time")
                    {
                        picker.CustomFormat += System.Globalization.DateTimeFormatInfo.CurrentInfo.LongTimePattern;
                    }
                    if (t.fieldName == "@exp_date")
                    {
                        picker.ShowCheckBox = true;
                    }
                    et_to_control[t] = picker;
                }
                else if (t.type == "RichTextbox")
                {
                    var box = new CustomRichTextBoxEx();
                    box.Top = control_offset_y;
                    int lines = LinesFromOption(t.options);
                    box.Multiline        = lines > 1;
                    box.Height           = DpiUtil.ScaleIntY(13) * lines + DpiUtil.ScaleIntY(10);
                    box.CtrlEnterAccepts = true;
                    box.ScrollBars       = RichTextBoxScrollBars.Both;
                    control_offset_y    += DpiUtil.ScaleIntY(13) * (lines - 1);
                    UIUtil.PrepareStandardMultilineControl(box, true, lines > 1);

                    et_to_control[t] = box;
                }
                else if (t.type == "Inline" || t.type == "Protected Inline" || t.type == "Inline URL")
                {
                    var box   = new TextBox();
                    int lines = LinesFromOption(t.options);
                    if (t.type == "Inline URL")
                    {
                        lines = 1;
                    }
                    if (t.type == "Protected Inline")
                    {
                        box = new SecureTextBoxEx();
                    }
                    box.Top = control_offset_y;

                    if (lines > 1)
                    {
                        box.Multiline     = true;
                        box.AcceptsReturn = true;
                        box.Height        = DpiUtil.ScaleIntY(13) * lines + DpiUtil.ScaleIntY(10);
                        box.ScrollBars    = ScrollBars.Both;
                        control_offset_y += DpiUtil.ScaleIntY(13) * (lines - 1);
                    }
                    et_to_control[t] = box;
                    if (t.type == "Protected Inline")
                    {
                        et_to_secure_edit[t] = box as SecureTextBoxEx;
                        if (t.fieldName != "@confirm")
                        {
                            CheckBox chk = new CheckBox();
                            chk.Appearance = Appearance.Button;
                            chk.Image      = DpiUtil.ScaleImage(Resources.Resources.B17x05_3BlackDots, false);
                            chk.Size       = new Size(DpiUtil.ScaleIntX(32), DpiUtil.ScaleIntY(23));
                            chk.TextAlign  = ContentAlignment.MiddleCenter;
                            chk.UseVisualStyleBackColor = true;
                            chk.Top             = control_offset_y;
                            chk.Checked         = true;
                            chk.CheckedChanged += chk_CheckedChanged;
                            et_to_control2[t]   = chk;
                        }
                        else
                        {
                            et_to_control2[t]                  = m_btnGenPw;
                            et_to_control2[t].Top              = control_offset_y;
                            current_password_confirm_field     = box as SecureTextBoxEx;
                            current_password_confirm_field_txt = box;
                            entry_pass_confirm                 = box as SecureTextBoxEx;
                        }
                        if (t.fieldName == PwDefs.PasswordField)
                        {
                            entry_pass = current_password_field = box as SecureTextBoxEx;
                        }
                    }
                    else if (t.type == "Inline URL")
                    {
                        var link = new LinkLabel {
                            Text = "Open"
                        };
                        link.LinkClicked += (sender, args) => WinUtil.OpenUrl(box.Text ?? "", form.EntryRef);
                        link.Top          = control_offset_y;
                        link.Width        = DpiUtil.ScaleIntY(50);
                        et_to_control2[t] = link;
                    }
                }
                else if (t.type == "Popout" || t.type == "Protected Popout")
                {
                    Button btn = new Button();
                    btn.Text = "View/Edit";
                    if (t.type == "Protected Popout")
                    {
                        btn.Text = "View/Edit Secure";
                    }
                    btn.Height = BUTTON_HEIGHT;
                    btn.Top    = control_offset_y;

                    btn.Click       += btn_popout_Click;
                    et_to_control[t] = btn;
                }
                control_offset_y += DpiUtil.ScaleIntY(30);
                if (et_to_control[t] != null)                   //only the divider does not
                {
                    et_to_control[t].Tag = t;
                    SetControlSizing(t, et_to_control[t]);
                }
                if (et_to_control2.ContainsKey(t))
                {
                    et_to_control2[t].Tag = t;
                    SetControlSizing(t, et_to_control2[t]);
                }
            }
            client_remove_button        = new Button();
            client_remove_button.Text   = "Remove As Template Child";
            client_remove_button.Height = BUTTON_HEIGHT;
            SetControlSizing(null, client_remove_button);
            //client_remove_button.Height = 20;
            client_remove_button.Top    = control_offset_y;
            client_remove_button.Click += client_remove_button_Click;

            add_child_items_to_tab(page);
            return(true);
        }
Ejemplo n.º 10
0
 private void OnPluginsLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     WinUtil.OpenUrl(PwDefs.PluginsUrl, null);
 }
Ejemplo n.º 11
0
        private static void ShowHelpOnline(string strTopic, string strSection)
        {
            string strUrl = GetOnlineUrl(strTopic, strSection);

            WinUtil.OpenUrl(strUrl, null);
        }
        private static void ShowMessageBox(EcasAction a, EcasContext ctx)
        {
            VistaTaskDialog vtd = new VistaTaskDialog();

            string strMain = EcasUtil.GetParamString(a.Parameters, 0, true);

            if (!string.IsNullOrEmpty(strMain))
            {
                vtd.MainInstruction = strMain;
            }

            string strText = EcasUtil.GetParamString(a.Parameters, 1, true);

            if (!string.IsNullOrEmpty(strText))
            {
                vtd.Content = strText;
            }

            uint uIcon = EcasUtil.GetParamUInt(a.Parameters, 2, 0);

            if (uIcon == (uint)MessageBoxIcon.Information)
            {
                vtd.SetIcon(VtdIcon.Information);
            }
            else if (uIcon == (uint)MessageBoxIcon.Question)
            {
                vtd.SetIcon(VtdCustomIcon.Question);
            }
            else if (uIcon == (uint)MessageBoxIcon.Warning)
            {
                vtd.SetIcon(VtdIcon.Warning);
            }
            else if (uIcon == (uint)MessageBoxIcon.Error)
            {
                vtd.SetIcon(VtdIcon.Error);
            }
            else
            {
                Debug.Assert(uIcon == (uint)MessageBoxIcon.None);
            }

            vtd.CommandLinks = false;

            uint uBtns      = EcasUtil.GetParamUInt(a.Parameters, 3, 0);
            bool bCanCancel = false;

            if (uBtns == (uint)MessageBoxButtons.OKCancel)
            {
                vtd.AddButton((int)DialogResult.OK, KPRes.Ok, null);
                vtd.AddButton((int)DialogResult.Cancel, KPRes.Cancel, null);
                bCanCancel = true;
            }
            else if (uBtns == (uint)MessageBoxButtons.YesNo)
            {
                vtd.AddButton((int)DialogResult.OK, KPRes.YesCmd, null);
                vtd.AddButton((int)DialogResult.Cancel, KPRes.NoCmd, null);
                bCanCancel = true;
            }
            else
            {
                vtd.AddButton((int)DialogResult.OK, KPRes.Ok, null);
            }

            uint uDef = EcasUtil.GetParamUInt(a.Parameters, 4, 0);
            ReadOnlyCollection <VtdButton> lButtons = vtd.Buttons;

            if (uDef < (uint)lButtons.Count)
            {
                vtd.DefaultButtonID = lButtons[(int)uDef].ID;
            }

            vtd.WindowTitle = PwDefs.ShortProductName;

            string strTrg = ctx.Trigger.Name;

            if (!string.IsNullOrEmpty(strTrg))
            {
                vtd.FooterText = KPRes.Trigger + @": '" + strTrg + @"'.";
                vtd.SetFooterIcon(VtdIcon.Information);
            }

            int dr;

            if (vtd.ShowDialog())
            {
                dr = vtd.Result;
            }
            else
            {
                string str = (strMain ?? string.Empty);
                if (!string.IsNullOrEmpty(strText))
                {
                    if (str.Length > 0)
                    {
                        str += MessageService.NewParagraph;
                    }
                    str += strText;
                }

                MessageBoxDefaultButton mbdb = MessageBoxDefaultButton.Button1;
                if (uDef == 1)
                {
                    mbdb = MessageBoxDefaultButton.Button2;
                }
                else if (uDef == 2)
                {
                    mbdb = MessageBoxDefaultButton.Button3;
                }

                MessageService.ExternalIncrementMessageCount();
                try
                {
                    dr = (int)MessageService.SafeShowMessageBox(str,
                                                                PwDefs.ShortProductName, (MessageBoxButtons)uBtns,
                                                                (MessageBoxIcon)uIcon, mbdb);
                }
                finally { MessageService.ExternalDecrementMessageCount(); }
            }

            uint uActCondID = EcasUtil.GetParamUInt(a.Parameters, 5, 0);

            bool bDrY = ((dr == (int)DialogResult.OK) ||
                         (dr == (int)DialogResult.Yes));
            bool bDrN = ((dr == (int)DialogResult.Cancel) ||
                         (dr == (int)DialogResult.No));

            bool bPerformAction = (((uActCondID == IdMbcY) && bDrY) ||
                                   ((uActCondID == IdMbcN) && bDrN));

            if (!bPerformAction)
            {
                return;
            }

            uint   uActID         = EcasUtil.GetParamUInt(a.Parameters, 6, 0);
            string strActionParam = EcasUtil.GetParamString(a.Parameters, 7, true);

            if (uActID == IdMbaNone)
            {
            }
            else if (uActID == IdMbaAbort)
            {
                if (bCanCancel)
                {
                    ctx.Cancel = true;
                }
            }
            else if (uActID == IdMbaCmd)
            {
                if (!string.IsNullOrEmpty(strActionParam))
                {
                    WinUtil.OpenUrl(strActionParam, null);
                }
            }
            else
            {
                Debug.Assert(false);
            }
        }
Ejemplo n.º 13
0
 private void OnLinkLangCodeClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     WinUtil.OpenUrl("https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes", null);
 }
        //private int ScaleX(int i) {
        //	return DpiUtil.ScaleIntX(i);
        //}
        //private int ScaleY(int i) {
        //	return DpiUtil.ScaleIntY(i);
        //}

        private bool InitializeChildView(TabPage page, String uuid)
        {
            if (et_to_label != null)
            {
                add_child_items_to_tab(page);
                return(true);
            }

            init_pwgen_button();
            et_to_label       = new Dictionary <EntryTemplate, Label>();
            et_to_control     = new Dictionary <EntryTemplate, Control>();
            et_to_secure_edit = new Dictionary <EntryTemplate, SecureEdit>();
            et_to_control2    = new Dictionary <EntryTemplate, Control>();
            SecureEdit entry_pass         = null;
            SecureEdit entry_pass_confirm = null;

            int     control_offset_y = 10;
            PwUuid  par_uuid         = new PwUuid(KeePassLib.Utility.MemUtil.HexStringToByteArray(uuid));
            PwEntry par_template     = m_host.Database.RootGroup.FindEntry(par_uuid, true);

            if (par_template == null)
            {
                return(false);
            }
            if (par_template.Strings.Get("_etm_template") == null)
            {
                return(false);
            }
            List <EntryTemplate> cur                 = parse_entry(par_template.Strings);
            const int            LABEL_WIDTH         = 130;
            const int            LEFT_CONTROL_OFFSET = LABEL_WIDTH + 5;
            int CONTROL_WIDTH = TAB_WIDTH - LABEL_WIDTH - 55;

            foreach (EntryTemplate t in cur)
            {
                Label label = new Label();
                label.Text = t.title + ":";
                //label.AutoSize = false;
                label.Top      = control_offset_y;
                label.Left     = 0;
                label.AutoSize = false;
                label.Width    = LABEL_WIDTH;

                label.AutoEllipsis = true;
                label.TextAlign    = ContentAlignment.MiddleRight;
                FontUtil.AssignDefaultBold(label);

                et_to_label[t] = label;
                if (t.type == "Divider")
                {
                    label.Font       = new Font(label.Font.FontFamily, label.Font.Size * 1.1f, FontStyle.Bold | FontStyle.Underline);
                    label.TextAlign  = ContentAlignment.BottomLeft;
                    label.Width      = CONTROL_WIDTH + LABEL_WIDTH;
                    label.Text       = t.title;              //remove :
                    et_to_control[t] = null;
                }
                else if (t.type == "Checkbox")
                {
                    CheckBox checkbox = new CheckBox();
                    checkbox.Top     = control_offset_y;
                    checkbox.Left    = LEFT_CONTROL_OFFSET;
                    et_to_control[t] = checkbox;
                }
                else if (t.type == "Listbox")
                {
                    ComboBox combobox = new ComboBox();
                    combobox.Top     = control_offset_y;
                    combobox.Left    = LEFT_CONTROL_OFFSET;
                    combobox.Width   = CONTROL_WIDTH;
                    et_to_control[t] = combobox;
                    if (!String.IsNullOrEmpty(t.options))
                    {
                        String[] opts = t.options.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (String opt in opts)
                        {
                            combobox.Items.Add(opt.Trim());
                        }
                    }
                }
                else if (t.type == "Date" || t.type == "Time" || t.type == "Date Time")
                {
                    DateTimePicker picker = new DateTimePicker();
                    picker.Top          = control_offset_y;
                    picker.Left         = LEFT_CONTROL_OFFSET;
                    picker.CustomFormat = "";
                    picker.Width        = CONTROL_WIDTH;
                    picker.Format       = DateTimePickerFormat.Custom;
                    if (t.type == "Date" || t.type == "Date Time")
                    {
                        picker.CustomFormat = System.Globalization.DateTimeFormatInfo.CurrentInfo.ShortDatePattern;
                    }
                    if (t.type == "Date Time")
                    {
                        picker.CustomFormat += " ";
                    }
                    if (t.type == "Time" || t.type == "Date Time")
                    {
                        picker.CustomFormat += System.Globalization.DateTimeFormatInfo.CurrentInfo.LongTimePattern;
                    }
                    if (t.fieldName == "@exp_date")
                    {
                        picker.ShowCheckBox = true;
                    }
                    et_to_control[t] = picker;
                }
                else if (t.type == "Inline" || t.type == "Protected Inline" || t.type == "Inline URL")
                {
                    TextBox box = new TextBox();
                    box.Top   = control_offset_y;
                    box.Left  = LEFT_CONTROL_OFFSET;
                    box.Width = t.type == "Inline URL" ? CONTROL_WIDTH - 30 : CONTROL_WIDTH;
                    int lines = LinesFromOption(t.options);
                    if (t.type == "Inline URL")
                    {
                        lines = 1;
                    }
                    if (lines > 1)
                    {
                        box.Multiline     = true;
                        box.AcceptsReturn = true;
                        box.Height        = 13 * lines + 10;
                        box.ScrollBars    = ScrollBars.Both;
                        control_offset_y += 13 * (lines - 1);
                    }
                    et_to_control[t] = box;
                    if (t.type == "Protected Inline")
                    {
                        SecureEdit sedit = new SecureEdit();
                        sedit.Attach(box, null, true);
                        et_to_secure_edit[t] = sedit;
                        if (t.fieldName != "@confirm")
                        {
                            CheckBox chk = new CheckBox();
                            chk.Appearance = Appearance.Button;
                            chk.Image      = Resources.Resources.B17x05_3BlackDots;
                            chk.Location   = new Point(box.Left + box.Width + 10, control_offset_y);
                            chk.Size       = new Size(32, 23);
                            chk.TextAlign  = ContentAlignment.MiddleCenter;
                            chk.UseVisualStyleBackColor = true;
                            chk.Tag             = t;
                            chk.Checked         = true;
                            chk.CheckedChanged += chk_CheckedChanged;
                            et_to_control2[t]   = chk;
                        }
                        else
                        {
                            et_to_control2[t]                  = m_btnGenPw;
                            et_to_control2[t].Location         = new Point(box.Left + box.Width + 10, control_offset_y);
                            current_password_confirm_field     = sedit;
                            current_password_confirm_field_txt = box;
                            entry_pass_confirm                 = sedit;
                        }
                        if (t.fieldName == PwDefs.PasswordField)
                        {
                            entry_pass = current_password_field = sedit;
                        }
                    }
                    else if (t.type == "Inline URL")
                    {
                        var link = new LinkLabel {
                            Text = "Open"
                        };
                        link.LinkClicked += (sender, args) => WinUtil.OpenUrl(box.Text ?? "", form.EntryRef);
                        link.Location     = new Point(box.Left + box.Width + 10, control_offset_y);
                        link.Width        = 50;
                        et_to_control2[t] = link;
                    }
                }
                else if (t.type == "Popout" || t.type == "Protected Popout")
                {
                    Button btn = new Button();
                    btn.Text = "View/Edit";
                    if (t.type == "Protected Popout")
                    {
                        btn.Text = "View/Edit Secure";
                    }
                    btn.Tag   = t;
                    btn.Width = CONTROL_WIDTH;
                    btn.Left  = LEFT_CONTROL_OFFSET;
                    //btn.Height = 20;
                    btn.Top          = control_offset_y;
                    btn.Click       += btn_popout_Click;
                    et_to_control[t] = btn;
                }

                control_offset_y += 30;
            }
            client_remove_button       = new Button();
            client_remove_button.Text  = "Remove As Template Child";
            client_remove_button.Width = CONTROL_WIDTH;
            client_remove_button.Left  = LEFT_CONTROL_OFFSET;
            //client_remove_button.Height = 20;
            client_remove_button.Top    = control_offset_y;
            client_remove_button.Click += client_remove_button_Click;
            if (entry_pass_confirm != null && entry_pass != null)
            {
            }
            add_child_items_to_tab(page);
            return(true);
        }