예제 #1
0
        internal static void ConfigureText(Control c, bool bHandleTextChange)
        {
            if (c == null)
            {
                Debug.Assert(false); return;
            }

            Color clrNormal = c.ForeColor;
            Color clrMulti  = UIUtil.ColorTowards(clrNormal, (UIUtil.IsDarkColor(
                                                                  clrNormal) ? Color.White : Color.Black), 0.5);

            EventHandler eh = delegate(object sender, EventArgs e)
            {
                Control cEv = (sender as Control);
                if (cEv == null)
                {
                    Debug.Assert(false); return;
                }
                Debug.Assert(cEv == c);

                bool bCue = (cEv.Text == MultipleValuesEx.CueString);
                cEv.ForeColor = (bCue ? clrMulti : clrNormal);
            };

            eh(c, EventArgs.Empty);

            if (bHandleTextChange)
            {
                c.TextChanged += eh;
            }
        }
예제 #2
0
        internal static void ConfigureText(ListViewItem lvi, int iSubItem)
        {
            if (lvi == null)
            {
                Debug.Assert(false); return;
            }
            if ((iSubItem < 0) || (iSubItem >= lvi.SubItems.Count))
            {
                Debug.Assert(false); return;
            }

            ListViewItem.ListViewSubItem lvsi = lvi.SubItems[iSubItem];
            if (lvsi.Text == MultipleValuesEx.CueString)
            {
                Color clrNormal = lvi.ForeColor;
                Color clrMulti  = UIUtil.ColorTowards(clrNormal, (UIUtil.IsDarkColor(
                                                                      clrNormal) ? Color.White : Color.Black), 0.5);
                Debug.Assert(UIUtil.ColorsEqual(clrNormal, SystemColors.ControlText));

                Debug.Assert(lvi.UseItemStyleForSubItems);                 // Caller uses colors already?
                lvi.UseItemStyleForSubItems = false;
                lvsi.ForeColor = clrMulti;
            }
        }
예제 #3
0
        internal static Color GetQualityColor(float fQ, bool bToControlBack)
        {
            if (fQ < 0.0f)
            {
                Debug.Assert(false); fQ = 0.0f;
            }
            if (fQ > 1.0f)
            {
                Debug.Assert(false); fQ = 1.0f;
            }

            Color clrL = AppDefs.ColorQualityLow;
            Color clrH = AppDefs.ColorQualityHigh;
            Color clrM = AppDefs.ColorQualityMid;

            int iR, iG, iB;

            if (fQ <= 0.5f)
            {
                fQ *= 2.0f;
                iR  = clrL.R + (int)(fQ * ((int)clrM.R - (int)clrL.R));
                iG  = clrL.G + (int)(fQ * ((int)clrM.G - (int)clrL.G));
                iB  = clrL.B + (int)(fQ * ((int)clrM.B - (int)clrL.B));
            }
            else
            {
                fQ = (fQ - 0.5f) * 2.0f;
                iR = clrM.R + (int)(fQ * ((int)clrH.R - (int)clrM.R));
                iG = clrM.G + (int)(fQ * ((int)clrH.G - (int)clrM.G));
                iB = clrM.B + (int)(fQ * ((int)clrH.B - (int)clrM.B));
            }

            if (iR < 0)
            {
                Debug.Assert(false); iR = 0;
            }
            if (iR > 255)
            {
                Debug.Assert(false); iR = 255;
            }
            if (iG < 0)
            {
                Debug.Assert(false); iG = 0;
            }
            if (iG > 255)
            {
                Debug.Assert(false); iG = 255;
            }
            if (iB < 0)
            {
                Debug.Assert(false); iB = 0;
            }
            if (iB > 255)
            {
                Debug.Assert(false); iB = 255;
            }

            Color clrQ = Color.FromArgb(iR, iG, iB);

            if (bToControlBack)
            {
                return(UIUtil.ColorTowards(clrQ, AppDefs.ColorControlNormal, 0.5));
            }
            return(clrQ);
        }
예제 #4
0
        internal static List <object> CreatePwQualityList(PwDatabase pd,
                                                          IStatusLogger sl, out Action <ListView> fInit)
        {
            fInit = delegate(ListView lv)
            {
                int w  = lv.ClientSize.Width - UIUtil.GetVScrollBarWidth();
                int wf = (int)(((long)w * 5L) / 23L);
                int wq = w - (wf * 4);
                int di = Math.Min(UIUtil.GetSmallIconSize().Width, wf);

                lv.Columns.Add(KPRes.Title, wf + di);
                lv.Columns.Add(KPRes.UserName, wf);
                lv.Columns.Add(KPRes.Password, wf);
                lv.Columns.Add(KPRes.Group, wf - di);
                lv.Columns.Add(KPRes.Quality, wq, HorizontalAlignment.Right);

                UIUtil.SetDisplayIndices(lv, new int[] { 1, 2, 3, 0, 4 });
            };

            List <KeyValuePair <PwEntry, ulong> > l = CreatePwQualityListEx(pd, sl);

            if (l == null)
            {
                return(null);
            }

            List <object> lResults = new List <object>();
            DateTime      dtNow    = DateTime.UtcNow;

            Color clrL = UIUtil.ColorTowards(AppDefs.ColorQualityLow,
                                             AppDefs.ColorControlNormal, 0.5);
            Color clrH = UIUtil.ColorTowards(AppDefs.ColorQualityHigh,
                                             AppDefs.ColorControlNormal, 0.5);
            int   rL = clrL.R, gL = clrL.G, bL = clrL.B;
            float rSp = (int)clrH.R - rL;
            float gSp = (int)clrH.G - gL;
            float bSp = (int)clrH.B - bL;

            foreach (KeyValuePair <PwEntry, ulong> kvp in l)
            {
                PwEntry pe = kvp.Key;

                string strGroup = string.Empty;
                if (pe.ParentGroup != null)
                {
                    strGroup = pe.ParentGroup.GetFullPath(" - ", false);
                }

                ListViewItem lvi = new ListViewItem(pe.Strings.ReadSafe(
                                                        PwDefs.TitleField));
                lvi.UseItemStyleForSubItems = false;

                lvi.SubItems.Add(pe.Strings.ReadSafe(PwDefs.UserNameField));
                lvi.SubItems.Add(pe.Strings.ReadSafe(PwDefs.PasswordField));
                lvi.SubItems.Add(strGroup);

                ulong q = (kvp.Value >> 32);
                ListViewItem.ListViewSubItem lvsi = lvi.SubItems.Add(
                    q.ToString() + " " + KPRes.BitsStc);

                try
                {
                    float fQ = (float)Math.Min(q, 128UL) / 128.0f;
                    lvsi.BackColor = Color.FromArgb(rL + (int)(fQ * rSp),
                                                    gL + (int)(fQ * gSp), bL + (int)(fQ * bSp));
                }
                catch (Exception) { Debug.Assert(false); }

                lvi.ImageIndex = UIUtil.GetEntryIconIndex(pd, pe, dtNow);
                lvi.Tag        = pe;
                lResults.Add(lvi);
            }

            return(lResults);
        }