Пример #1
0
        private void LanguageFormAdded(object sender, EventArgs e)
        {
            LanguageForm fLang = sender as LanguageForm;

            if (fLang == null)
            {
                return;
            }
            ListView m_lvLanguages = Tools.GetControl("m_lvLanguages", fLang) as ListView;

            if (m_lvLanguages == null)
            {
                return;
            }
            m_lvLanguages.BeginUpdate();
            int[] aWidths = StrUtil.DeserializeIntArray(UIUtil.GetColumnWidths(m_lvLanguages) + " " + DpiUtil.ScaleIntX(60).ToString());
            int   iCol    = m_lvLanguages.Columns.Add("L-ID").Index;

            foreach (ListViewItem i in m_lvLanguages.Items)
            {
                try
                {
                    XmlSerializerEx xs = new XmlSerializerEx(typeof(KPTranslation));
                    KPTranslation   t  = KPTranslation.Load(i.Tag as string, xs);
                    i.SubItems.Add(t.Properties.Iso6391Code);
                }
                catch { if (string.IsNullOrEmpty(i.Tag as string))
                        {
                            i.SubItems.Add("en");
                        }
                }
            }
            UIUtil.ResizeColumns(m_lvLanguages, aWidths, true);
            m_lvLanguages.EndUpdate();
        }
Пример #2
0
        private static ColorDialog CreateColorDialog(Color clrDefault)
        {
            ColorDialog dlg = new ColorDialog();

            dlg.AllowFullOpen = true;
            dlg.AnyColor      = true;
            if (!clrDefault.IsEmpty)
            {
                dlg.Color = clrDefault;
            }
            dlg.FullOpen = true;
            dlg.ShowHelp = false;
            // dlg.SolidColorOnly = false;

            try
            {
                string strColors = Program.Config.Defaults.CustomColors;
                if (!string.IsNullOrEmpty(strColors))
                {
                    int[] vColors = StrUtil.DeserializeIntArray(strColors);
                    if ((vColors != null) && (vColors.Length > 0))
                    {
                        dlg.CustomColors = vColors;
                    }
                }
            }
            catch (Exception) { Debug.Assert(false); }

            return(dlg);
        }
Пример #3
0
        private static string ComputeNewDisplayOrder(List <AceColumn> lNew,
                                                     List <AceColumn> lOld, string strOldOrder)
        {
            if ((lNew == null) || (lOld == null))
            {
                Debug.Assert(false); return(string.Empty);
            }
            if (string.IsNullOrEmpty(strOldOrder))
            {
                return(string.Empty);
            }

            List <AceColumnWithTag> lOldS = new List <AceColumnWithTag>();

            try
            {
                int[] vOld = StrUtil.DeserializeIntArray(strOldOrder);
                if ((vOld == null) || (vOld.Length != lOld.Count))
                {
                    Debug.Assert(false);
                    return(string.Empty);
                }

                for (int i = 0; i < vOld.Length; ++i)
                {
                    if (lOld[i] == null)
                    {
                        Debug.Assert(false); return(string.Empty);
                    }
                    lOldS.Add(new AceColumnWithTag(lOld[i], vOld[i]));
                }

                lOldS.Sort(AceColumnWithTag.CompareByTags);
            }
            catch (Exception) { Debug.Assert(false); return(string.Empty); }

            List <AceColumnWithTag> l = new List <AceColumnWithTag>();

            foreach (AceColumn c in lNew)
            {
                if (c != null)
                {
                    l.Add(new AceColumnWithTag(c, 0));
                }
                else
                {
                    Debug.Assert(false); return(string.Empty);
                }
            }

            long m = Math.Max(lNew.Count, lOld.Count);

            // Preserve order of previous columns
            for (int i = 0; i < lOldS.Count; ++i)
            {
                string strOldName = lOldS[i].TypeNameEx;

                foreach (AceColumnWithTag ct in l)
                {
                    if (ct.TypeNameEx == strOldName)
                    {
                        ct.Tag = m * i;
                        break;
                    }
                }
            }

            // Insert new columns based on their default position
            for (int i = 1; i < l.Count; ++i)
            {
                if (l[i].Tag == 0)
                {
                    l[i].Tag = l[i - 1].Tag + 1;
                }
            }

            l.Sort(AceColumnWithTag.CompareByTags);

            int[] v = new int[lNew.Count];
            for (int i = 0; i < v.Length; ++i)
            {
                for (int j = 0; j < l.Count; ++j)
                {
                    if (object.ReferenceEquals(l[j].Column, lNew[i]))
                    {
                        v[i] = j;
                        break;
                    }
                }
            }
            Debug.Assert(Array.IndexOf(v, 0) == Array.LastIndexOf(v, 0));

            return(StrUtil.SerializeIntArray(v));
        }
Пример #4
0
        private void DpiScale()
        {
            AceMeta aceMeta = this.Meta;             // m_meta might be null
            double  dCfgX = aceMeta.DpiFactorX, dCfgY = aceMeta.DpiFactorY;
            double  dScrX = DpiUtil.FactorX, dScrY = DpiUtil.FactorY;

            if ((dScrX == dCfgX) && (dScrY == dCfgY))
            {
                return;
            }

            // When this method returns, all positions and sizes are in pixels
            // for the current screen DPI
            aceMeta.DpiFactorX = dScrX;
            aceMeta.DpiFactorY = dScrY;

            // Backward compatibility; configuration files created by KeePass
            // 2.37 and earlier do not contain DpiFactor* values, they default
            // to 0.0 and all positions and sizes are in pixels for the current
            // screen DPI; so, do not perform any DPI scaling in this case
            if ((dCfgX == 0.0) || (dCfgY == 0.0))
            {
                return;
            }

            double           sX = dScrX / dCfgX, sY = dScrY / dCfgY;
            GFunc <int, int> fX = delegate(int x)
            {
                return((int)Math.Round((double)x * sX));
            };
            GFunc <int, int> fY = delegate(int y)
            {
                return((int)Math.Round((double)y * sY));
            };
            GFunc <string, string> fWsr = delegate(string strRect)
            {
                return(UIUtil.ScaleWindowScreenRect(strRect, sX, sY));
            };
            GFunc <string, string> fVX = delegate(string strArray)
            {
                if (string.IsNullOrEmpty(strArray))
                {
                    return(strArray);
                }

                try
                {
                    int[] v = StrUtil.DeserializeIntArray(strArray);
                    if (v == null)
                    {
                        Debug.Assert(false); return(strArray);
                    }

                    for (int i = 0; i < v.Length; ++i)
                    {
                        v[i] = (int)Math.Round((double)v[i] * sX);
                    }

                    return(StrUtil.SerializeIntArray(v));
                }
                catch (Exception) { Debug.Assert(false); }

                return(strArray);
            };
            Action <AceFont> fFont = delegate(AceFont f)
            {
                if (f == null)
                {
                    Debug.Assert(false); return;
                }

                if (f.GraphicsUnit == GraphicsUnit.Pixel)
                {
                    f.Size = (float)(f.Size * sY);
                }
            };

            AceMainWindow mw = this.MainWindow;
            AceUI         ui = this.UI;

            if (mw.X != AppDefs.InvalidWindowValue)
            {
                mw.X = fX(mw.X);
            }
            if (mw.Y != AppDefs.InvalidWindowValue)
            {
                mw.Y = fY(mw.Y);
            }
            if (mw.Width != AppDefs.InvalidWindowValue)
            {
                mw.Width = fX(mw.Width);
            }
            if (mw.Height != AppDefs.InvalidWindowValue)
            {
                mw.Height = fY(mw.Height);
            }

            foreach (AceColumn c in mw.EntryListColumns)
            {
                if (c.Width >= 0)
                {
                    c.Width = fX(c.Width);
                }
            }

            ui.DataViewerRect          = fWsr(ui.DataViewerRect);
            ui.DataEditorRect          = fWsr(ui.DataEditorRect);
            ui.CharPickerRect          = fWsr(ui.CharPickerRect);
            ui.AutoTypeCtxRect         = fWsr(ui.AutoTypeCtxRect);
            ui.AutoTypeCtxColumnWidths = fVX(ui.AutoTypeCtxColumnWidths);

            fFont(ui.StandardFont);
            fFont(ui.PasswordFont);
            fFont(ui.DataEditorFont);
        }