Example #1
0
        private void OnFontComboSelectedIndexChanged(object sender, EventArgs e)
        {
            if ((m_uBlockEvents > 0) || (m_bdc != BinaryDataClass.RichText))
            {
                return;
            }

            try
            {
                string strName = m_tbFontCombo.Text;

                Font f = m_rtbText.SelectionFont;
                if (f != null)
                {
                    m_rtbText.SelectionFont = new Font(strName, f.Size,
                                                       f.Style, f.Unit, f.GdiCharSet, f.GdiVerticalFont);
                }
                else if (FontUtil.DefaultFont != null)
                {
                    m_rtbText.SelectionFont = FontUtil.CreateFont(strName,
                                                                  FontUtil.DefaultFont.SizeInPoints, FontStyle.Regular);
                }
                else
                {
                    m_rtbText.SelectionFont = FontUtil.CreateFont(strName,
                                                                  12.0f, FontStyle.Regular);
                }
            }
            catch (Exception ex) { MessageService.ShowWarning(ex); }

            UpdateUIState(true, true);
        }
Example #2
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            Debug.Assert(m_psWord != null);
            if (m_psWord == null)
            {
                throw new InvalidOperationException();
            }

            m_bFormLoaded = false;

            GlobalWindowManager.AddWindow(this);

            m_nFormHeight = this.Height;             // Before restoring the position/size

            string strRect = Program.Config.UI.CharPickerRect;

            if (strRect.Length > 0)
            {
                UIUtil.SetWindowScreenRect(this, strRect);
            }
            m_strInitialFormRect = UIUtil.GetWindowScreenRect(this);

            m_fontChars = FontUtil.CreateFont("Tahoma", 8.25f, FontStyle.Bold);

            this.Icon = Properties.Resources.KeePass;
            this.Text = KPRes.PickCharacters + " - " + PwDefs.ShortProductName;

            m_secWord.Attach(m_tbSelected, OnSelectedTextChangedEx, true);

            PwInputControlGroup.ConfigureHideButton(m_cbHideChars, null);

            AceColumn colPw = Program.Config.MainWindow.FindColumn(AceColumnType.Password);
            bool      bHide = ((colPw != null) ? colPw.HideWithAsterisks : true);

            if (m_bInitHide.HasValue)
            {
                bHide = m_bInitHide.Value;
            }
            bHide |= !AppPolicy.Current.UnhidePasswords;
            m_cbHideChars.Checked = bHide;

            RecreateResizableWindowControls();

            if (m_uCharCount > 0)
            {
                m_btnOK.Enabled = false;
                // m_btnOK.Visible = false;
            }

            if (m_bSetForeground)
            {
                this.BringToFront();
                this.Activate();
            }

            UIUtil.SetFocus(m_tbSelected, this);
            m_bFormLoaded = true;
        }
Example #3
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            if (m_psWord == null)
            {
                Debug.Assert(false); throw new InvalidOperationException();
            }

            // The password text box should not be focused by default
            // in order to avoid a Caps Lock warning tooltip bug;
            // https://sourceforge.net/p/keepass/bugs/1807/
            Debug.Assert((m_pnlBottom.TabIndex == 0) && !m_tbSelected.Focused);

            m_bFormLoaded = false;

            GlobalWindowManager.AddWindow(this);

            m_nFormHeight = this.Height;             // Before restoring the position/size

            m_strInitialFormRect = UIUtil.SetWindowScreenRectEx(this,
                                                                Program.Config.UI.CharPickerRect);

            m_fontChars = FontUtil.CreateFont("Tahoma", 8.25f, FontStyle.Bold);

            this.Icon = AppIcons.Default;
            this.Text = KPRes.PickCharacters + " - " + PwDefs.ShortProductName;

            // Must be set manually due to possible object override
            m_tbSelected.TextChanged += this.OnSelectedTextChangedEx;

            PwInputControlGroup.ConfigureHideButton(m_cbHideChars, null);

            AceColumn colPw = Program.Config.MainWindow.FindColumn(AceColumnType.Password);
            bool      bHide = ((colPw != null) ? colPw.HideWithAsterisks : true);

            if (m_bInitHide.HasValue)
            {
                bHide = m_bInitHide.Value;
            }
            bHide |= !AppPolicy.Current.UnhidePasswords;
            m_cbHideChars.Checked = bHide;

            RecreateResizableWindowControls();

            if (m_uCharCount > 0)
            {
                m_btnOK.Enabled = false;
                // m_btnOK.Visible = false;
            }

            if (m_bSetForeground)
            {
                this.BringToFront();
                this.Activate();
            }

            m_bFormLoaded = true;
        }
Example #4
0
        public Font ToFont()
        {
            if (m_bCacheValid)
            {
                return(m_fCached);
            }

            m_fCached     = FontUtil.CreateFont(m_strFamily, m_fSize, m_fStyle, m_gu);
            m_bCacheValid = true;
            return(m_fCached);
        }
Example #5
0
        private void OnFontSizeComboSelectedIndexChanged(object sender, EventArgs e)
        {
            if ((m_uBlockEvents > 0) || (m_bdc != BinaryDataClass.RichText))
            {
                return;
            }

            try
            {
                Font  f = m_rtbText.SelectionFont;
                float fSize;
                if (!float.TryParse(m_tbFontSizeCombo.Text, out fSize))
                {
                    if (f != null)
                    {
                        fSize = f.SizeInPoints;
                    }
                    else if (FontUtil.DefaultFont != null)
                    {
                        fSize = FontUtil.DefaultFont.SizeInPoints;
                    }
                    else
                    {
                        fSize = 12.0f;
                    }
                }

                if (f != null)
                {
                    m_rtbText.SelectionFont = new Font(f.Name, fSize, f.Style,
                                                       GraphicsUnit.Point, f.GdiCharSet, f.GdiVerticalFont);
                }
                else if (!NativeLib.IsUnix())
                {
                    UIUtil.RtfSetFontSize(m_rtbText, fSize);
                }
                else                 // Unix
                {
                    m_rtbText.SelectionFont = FontUtil.CreateFont(
                        FontFamily.GenericSansSerif, fSize, FontStyle.Regular);
                }
            }
            catch (Exception ex) { MessageService.ShowWarning(ex); }

            UpdateUIState(true, true);
        }
Example #6
0
        public EntryPickerDialog(KeeAgentExt ext, bool aShowConstraintControls)
        {
            this.ext = ext;
            InitializeComponent();
            if (!aShowConstraintControls)
            {
                Controls.Remove(mTableLayoutPanel);
                mCustomTreeViewEx.Height += mTableLayoutPanel.Height + 6;
            }
            if (Type.GetType("Mono.Runtime") == null)
            {
                Icon = Properties.Resources.KeeAgent_icon;
            }
            else
            {
                Icon = Properties.Resources.KeeAgent_icon_mono;

                mTableLayoutPanel.AutoSize = false;
                mTableLayoutPanel.Size     = new Size(mCustomTreeViewEx.Width,
                                                      mLifetimeConstraintControl.Height);

                // on windows, help button is displayed in the title bar
                // on mono, we need to add one in the window
                var helpButton = new Button();
                helpButton.Size     = new Size(25, 25);
                helpButton.Image    = Properties.Resources.Help_png;
                helpButton.Anchor   = AnchorStyles.Bottom | AnchorStyles.Left;
                helpButton.Location = new Point(mCustomTreeViewEx.Location.X,
                                                mOkButton.Location.Y);
                helpButton.Click += (sender, e) => OnHelpRequested();
                Controls.Add(helpButton);
            }

            if (ext.Options.AlwaysConfirm)
            {
                mConfirmConstraintControl.ReplaceWithGlobalConfirmMessage();
            }

            mExpiredFont = FontUtil.CreateFont(mCustomTreeViewEx.Font, FontStyle.Strikeout);
            mBoldFont    = FontUtil.CreateFont(mCustomTreeViewEx.Font, FontStyle.Bold);
            mItalicFont  = FontUtil.CreateFont(mCustomTreeViewEx.Font, FontStyle.Italic);
            InitalizeList(false);
        }
Example #7
0
            // Ported from KeePass Mainform_functions SetListEntry
            internal static ListViewItem InsertListEntryOLD(PwEntry pe, int iIndex)
            {
                // Adapted variables
                DateTime      m_dtCachedNow       = DateTime.Now;
                Font          m_fontExpired       = FontUtil.CreateFont(m_lvEntries.Font, FontStyle.Strikeout);
                bool          m_bEntryGrouping    = m_lvEntries.ShowGroups;
                bool          m_bShowTanIndices   = Program.Config.MainWindow.TanView.ShowIndices;
                bool          bSubEntries         = Program.Config.MainWindow.ShowEntriesOfSubGroups;
                ListViewGroup m_lvgLastEntryGroup = null;

                foreach (ListViewGroup lvg in m_lvEntries.Groups)
                {
                    if ((lvg.Tag as PwGroup) == pe.ParentGroup)
                    {
                        m_lvgLastEntryGroup = lvg;
                    }
                }
                PwGroup pg = (Program.MainForm.GetSelectedGroup());
                PwObjectList <PwEntry> pwlSource = ((pg != null) ? pg.GetEntries(bSubEntries) : new PwObjectList <PwEntry>());
                bool m_bOnlyTans = ListContainsOnlyTans(pwlSource);

                ListViewItem lviTarget = null;
                Color        m_clrAlternateItemBgColor = UIUtil.GetAlternateColor(m_lvEntries.BackColor);

                if (pe == null)
                {
                    Debug.Assert(false); return(null);
                }

                ListViewItem lvi = (lviTarget ?? new ListViewItem());
                PwListItem   pli = new PwListItem(pe);

                lvi.Tag = pli;

                //lvi.BeginUpdate();

                if (pe.Expires && (pe.ExpiryTime <= m_dtCachedNow))
                {
                    lvi.ImageIndex = (int)PwIcon.Expired;
                    if (m_fontExpired != null)
                    {
                        lvi.Font = m_fontExpired;
                    }
                }
                else // Not expired
                {
                    // Reset font, if item was expired previously (i.e. has expired font)
                    if ((lviTarget != null) && (lvi.ImageIndex == (int)PwIcon.Expired))
                    {
                        lvi.Font = m_lvEntries.Font;
                    }

                    if (pe.CustomIconUuid.EqualsValue(PwUuid.Zero))
                    {
                        lvi.ImageIndex = (int)pe.IconId;
                    }
                    else
                    {
                        lvi.ImageIndex = (int)PwIcon.Count +
                                         m_host.MainWindow.DocumentManager.ActiveDatabase.GetCustomIconIndex(pe.CustomIconUuid);
                    }
                }

                if (m_bEntryGrouping && (lviTarget == null))
                {
                    PwGroup pgContainer = pe.ParentGroup;
                    PwGroup pgLast      = ((m_lvgLastEntryGroup != null) ?
                                           (PwGroup)m_lvgLastEntryGroup.Tag : null);

                    Debug.Assert(pgContainer != null);
                    if (pgContainer != null)
                    {
                        if (pgContainer != pgLast)
                        {
                            m_lvgLastEntryGroup = new ListViewGroup(
                                pgContainer.GetFullPath());
                            m_lvgLastEntryGroup.Tag = pgContainer;

                            m_lvEntries.Groups.Add(m_lvgLastEntryGroup);
                        }

                        lvi.Group = m_lvgLastEntryGroup;
                    }
                }

                if (!pe.ForegroundColor.IsEmpty)
                {
                    lvi.ForeColor = pe.ForegroundColor;
                }
                else if (lviTarget != null)
                {
                    lvi.ForeColor = m_lvEntries.ForeColor;
                }
                else
                {
                    Debug.Assert(UIUtil.ColorsEqual(lvi.ForeColor, m_lvEntries.ForeColor));
                }

                if (!pe.BackgroundColor.IsEmpty)
                {
                    lvi.BackColor = pe.BackgroundColor;
                }
                // else if(Program.Config.MainWindow.EntryListAlternatingBgColors &&
                //	((m_lvEntries.Items.Count & 1) == 1))
                //	lvi.BackColor = m_clrAlternateItemBgColor;
                else if (lviTarget != null)
                {
                    lvi.BackColor = m_lvEntries.BackColor;
                }
                else
                {
                    Debug.Assert(UIUtil.ColorsEqual(lvi.BackColor, m_lvEntries.BackColor));
                }

                // m_bOnlyTans &= PwDefs.IsTanEntry(pe);
                if (m_bShowTanIndices && m_bOnlyTans)
                {
                    string strIndex = pe.Strings.ReadSafe(PwDefs.TanIndexField);

                    if (strIndex.Length > 0)
                    {
                        lvi.Text = strIndex;
                    }
                    else
                    {
                        lvi.Text = PwDefs.TanTitle;
                    }
                }
                else
                {
                    lvi.Text = GetEntryFieldEx(pe, 0, true);
                }

                int nColumns = m_lvEntries.Columns.Count;

                if (lviTarget == null)
                {
                    for (int iColumn = 1; iColumn < nColumns; ++iColumn)
                    {
                        lvi.SubItems.Add(GetEntryFieldEx(pe, iColumn, true));
                    }
                }
                else
                {
                    int nSubItems = lvi.SubItems.Count;
                    for (int iColumn = 1; iColumn < nColumns; ++iColumn)
                    {
                        string strSub = GetEntryFieldEx(pe, iColumn, true);
                        if (iColumn < nSubItems)
                        {
                            lvi.SubItems[iColumn].Text = strSub;
                        }
                        else
                        {
                            lvi.SubItems.Add(strSub);
                        }
                    }

                    Debug.Assert(lvi.SubItems.Count == nColumns);
                }

                //if (lviTarget == null) m_lvEntries.Items.Add(lvi);
                if (lviTarget == null)
                {
                    m_lvEntries.Items.Insert(iIndex, lvi);
                }

                UIUtil.SetAlternatingBgColors(m_lvEntries, m_clrAlternateItemBgColor,
                                              Program.Config.MainWindow.EntryListAlternatingBgColors);

                //lvi.EndUpdate();

                return(lvi);
            }
Example #8
0
        public static void MakeTagsButton(Button btn, TextBox tb, ToolTip tt,
                                          PwGroup pgParent, PwGroup pgTagsSource)
        {
            if ((btn == null) || (tb == null))
            {
                Debug.Assert(false); return;
            }
            Debug.Assert(tt != null);

            Image img = UIUtil.CreateDropDownImage(Properties.Resources.B16x16_KNotes);

            UIUtil.SetButtonImage(btn, img, true);

            UIUtil.SetToolTip(tt, btn, KPRes.TagsAddRemove, true);

            CustomContextMenuStripEx ctx = null;
            Font fItalic = null;

            btn.Click += delegate(object sender, EventArgs e)
            {
                if (ctx == null)
                {
                    ctx     = new CustomContextMenuStripEx();
                    fItalic = FontUtil.CreateFont(ctx.Font, FontStyle.Italic);
                }

                List <string> lCur = StrUtil.StringToTags(tb.Text);

                Dictionary <string, bool> dCur = new Dictionary <string, bool>();
                foreach (string strTag in lCur)
                {
                    dCur[strTag] = true;
                }

                List <string> lParent = ((pgParent != null) ?
                                         pgParent.GetTagsInherited(true) : new List <string>());
                Dictionary <string, bool> dParent = new Dictionary <string, bool>();
                foreach (string strTag in lParent)
                {
                    dParent[strTag] = true;
                }

                List <string> lAll = new List <string>(lCur);
                if (pgTagsSource != null)
                {
                    lAll.AddRange(pgTagsSource.BuildEntryTagsList(false, true));
                    StrUtil.NormalizeTags(lAll);
                }

                List <ToolStripItem> lMenuItems = new List <ToolStripItem>();

                if (lAll.Count == 0)
                {
                    ToolStripMenuItem tsmi = new ToolStripMenuItem(
                        StrUtil.EncodeMenuText("(" + KPRes.TagsNotFound + ")"));
                    tsmi.Enabled = false;

                    lMenuItems.Add(tsmi);
                }
                else
                {
                    for (int i = 0; i < lAll.Count; ++i)
                    {
                        string strTag  = lAll[i];                        // Used in Click handler
                        bool   bHasTag = dCur.ContainsKey(strTag);
                        bool   bInh    = dParent.ContainsKey(strTag);

                        string strSuffix = string.Empty;
                        if (bInh)
                        {
                            strSuffix = " (" + KPRes.Inherited + ")";
                        }

                        ToolStripMenuItem tsmi = new ToolStripMenuItem(
                            StrUtil.EncodeMenuText(strTag + strSuffix));
                        UIUtil.SetChecked(tsmi, bHasTag);

                        if (bInh)
                        {
                            tsmi.Font = fItalic;
                        }

                        tsmi.Click += delegate(object senderT, EventArgs eT)
                        {
                            if (bHasTag)
                            {
                                lCur.Remove(strTag);
                            }
                            else
                            {
                                lCur.Add(strTag);
                                StrUtil.NormalizeTags(lCur);
                            }

                            tb.Text = StrUtil.TagsToString(lCur, true);
                        };

                        lMenuItems.Add(tsmi);
                    }
                }

                ctx.Items.Clear();
                ctx.Items.AddRange(lMenuItems.ToArray());

                ctx.ShowEx(btn);
            };
        }