Esempio n. 1
0
 /// <summary>
 /// Loop the specified count and callback.
 /// </summary>
 /// <param name="count">Count.</param>
 /// <param name="callback">Callback.</param>
 public static void Loop(this int count, IndexCallback callback)
 {
     for (int i = 0; i < count; i++)
     {
         callback(i);
     }
 }
Esempio n. 2
0
        public frmIndex(FilterBar Parent, Point Anchor, IndexCallback Callback, FilterButton Button) : base(String.Empty, ButtonCreateType.None)
        {
            this.DoubleBuffered = true;

            callback = Callback;
            button   = Button;

            this.filterChar = '\0';

            this.FormBorderStyle = FormBorderStyle.None;
            this.StartPosition   = FormStartPosition.Manual;
            this.KeyPreview      = true;
            this.FilterTypeBasis = button.FilterType;

            setCaption();

            buttons = new List <QButton>();

            var aa = getChars(Parent, Button.FilterType).ToList();

            aa.RemoveAll(c => c <= ' ' || c == CLEAR_CHAR);

            if (aa.Count() == 0)
            {
                this.NoData = true;
                this.Close();
                this.callback(this);
                return;
            }

            this.NoData = false;

            aa.Sort();

            if (button.ValueType != FilterValueType.None)
            {
                aa.Add(CLEAR_CHAR);
            }

            aa = aa.Take(55).ToList();

            bool filterBadChars;

            switch (System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName)
            {
            case "en":
            case "de":
            case "it":
            case "cs":
            case "fr":
            case "pt":
                filterBadChars = true;
                break;

            default:
                filterBadChars = false;
                break;
            }

            foreach (char c in aa)
            {
                QButton b;
                if (Button.FilterType == FilterType.Year && c != CLEAR_CHAR)
                {
                    b = new QButton(c.ToString() + "0s", false, true);
                }
                else
                {
                    b = new QButton(c.ToString(), false, true);
                }

                if ((!filterBadChars) || (c < 0xFF))
                {
                    b.Tag = c;
                    buttons.Add(b);
                    b.BackColor      = this.BackColor;
                    b.ButtonPressed += new QButton.ButtonDelegate(click);
                    this.Controls.Add(b);
                }
            }

            this.MinimumSize = Size.Empty;

            buttons.Add(new QButton("~", false, true)); // placeholder for close button

            desiredWidth = arrangeButtons() + BORDER_WIDTH + 2;

            closeButtonRect = new Rectangle(buttons[buttons.Count - 1].Location, Properties.Resources.filter_index_close_hover.Size);

            buttons.RemoveAt(buttons.Count - 1);

            this.ClientSize = new System.Drawing.Size(desiredWidth,
                                                      rows * buttons[0].Height + BORDER_WIDTH * 2);


            Point p = Parent.PointToScreen(new Point(Math.Min(Anchor.X - this.Width / 2, Parent.Right - this.Width), Anchor.Y));

            p             = new Point(Math.Max(0, p.X), p.Y);
            this.Location = p;

            this.Owner = Lib.MainForm;

            this.Show(Lib.MainForm);

            QButton lastButton = buttons[buttons.Count - 1];

            if (lastButton.Text[0] == '_')
            {
                QToolTip clearToolTip = new QToolTip(lastButton, String.Empty);
                clearToolTip.SetToolTip(lastButton, Localization.Get(UI_Key.Filter_Index_Clear));
            }
            tooltip        = new QToolTip(this, Localization.Get(UI_Key.Filter_Index_Cancel));
            tooltip.Active = false;
        }