public ComboBoxListViewDesktop(ComboBox cmbBox)
            : base(DesktopManager.ScreenWidth - 50, DesktopManager.ScreenHeight - 50)
        {
            _suspended = true;

            ComboBoxList _itemsList = new ComboBoxList(5, 5, _mWidth - 10, _mHeight - 40);
            foreach (object item in cmbBox.Items)
                _itemsList.AddItem(item);

            object initialSelectedItem = _itemsList.SelectedItem = cmbBox.SelectedItem;
            _itemsList.BringItemIntoView(cmbBox.SelectedIndex);
            _itemsList.SelectedItemChanged += (s) =>
                {
                    cmbBox.SelectedItem = _itemsList.SelectedItem;
                };

            base.AddChild(_itemsList);

            TextButton cancelBut = new TextButton("Cancel", _mWidth - 105, _mHeight - 30, 100, 25);
            cancelBut.ButtonPressed += (s) => { cmbBox.SelectedItem = initialSelectedItem; Close(); };
            base.AddChild(cancelBut);

            TextButton okBut = new TextButton("Ok", cancelBut.X - 105, _mHeight - 30, 100, 25);
            okBut.ButtonPressed += (s) => Close();
            base.AddChild(okBut);

            _suspended = false;
        }
        private void AddButtons(MessageBoxButtons buttons)
        {
            int aux = (int)buttons;
            int noButtons = 0;
            while (aux != 0)
            {
                if ((aux % 2) == 1) noButtons++;
                aux = aux / 2;
            }

            int butWidth = (_mWidth - margin * (noButtons + 1)) / noButtons;

            int x = margin, y = _mHeight - butHeight - margin;

            if ((buttons & MessageBoxButtons.Ok) != 0)
            {
                TextButton butOk = new TextButton("Ok", x, y, butWidth, butHeight) { Tag = MessageBoxResult.Ok };
                butOk.ButtonPressed += but_ButtonPressed;
                base.AddChild(butOk);
                x += butWidth + margin;
            }
            if ((buttons & MessageBoxButtons.Yes) != 0)
            {
                TextButton butYes = new TextButton("Yes", x, y, butWidth, butHeight) { Tag = MessageBoxResult.Yes };
                butYes.ButtonPressed += but_ButtonPressed;
                base.AddChild(butYes);
                x += butWidth + margin;
            }
            if ((buttons & MessageBoxButtons.No) != 0)
            {
                TextButton butNo = new TextButton("No", x, y, butWidth, butHeight) { Tag = MessageBoxResult.No };
                butNo.ButtonPressed += but_ButtonPressed;
                base.AddChild(butNo);
                x += butWidth + margin;
            }
            if ((buttons & MessageBoxButtons.Retry) != 0)
            {
                TextButton butRetry = new TextButton("Retry", x, y, butWidth, butHeight) { Tag = MessageBoxResult.Retry };
                butRetry.ButtonPressed += but_ButtonPressed;
                base.AddChild(butRetry);
                x += butWidth + margin;
            }
            if ((buttons & MessageBoxButtons.Cancel) != 0)
            {
                TextButton butCancel = new TextButton("Cancel", x, y, butWidth, butHeight) { Tag = MessageBoxResult.Cancel };
                butCancel.ButtonPressed += but_ButtonPressed;
                base.AddChild(butCancel);
                x += butWidth + margin;
            }
        }
        public CalibrationDesktop(TouchCalibrationPoints calPoints)
        {
            DrawBackground += CalibrationDesktop_DrawBackground;
            _calibrationPoints = calPoints;
            _currentCalibrationPoint = 0;
            _isCalibrating = false;

            _doneButton = new TextButton("Done", _width / 2 - 50, _height - 40, 100, 35);
            _doneButton.Visible = false;
            _doneButton.ButtonPressed += (s) =>
            {
                _calDoneTimer.Dispose();
                if (CalibrationComplete != null) CalibrationComplete(this);
            };
            base.AddChild(_doneButton);

            _timerLabel = new Label(string.Empty, 10, 10, _width - 20, 0);
            _timerLabel.CenterText = true;
            _timerLabel.AutoHeight = true;
            _timerLabel.Visible = false;
            base.AddChild(_timerLabel);
        }
        private void CreateNumericLayout(Container p)
        {
            string keyLine = NumericKeys[0];

            int keyWidth = (p._width - 20 - (keyLine.Length + 2) * _uiMargin) / (keyLine.Length + 1);
            int keyHeight = (p._height - (NumericKeys.Length + 1) * _uiMargin) / NumericKeys.Length;

            int widthRemaining = p._width - ((keyLine.Length + 2) * _uiMargin + (keyLine.Length + 1) * keyWidth);

            int x, y;

            x = _uiMargin;
            y = 0;
            for (int i = 0; i < NumericKeys.Length; i++)
            {
                x = _uiMargin + widthRemaining / 2;
                string line = NumericKeys[i];
                for (int j = 0; j < line.Length; j++)
                {
                    TextButton numBut = new TextButton(line[j].ToString(), x, y, keyWidth, keyHeight) { Tag = (int)KeyFlags.NormalKey | ((int)line[j] & (int)KeyFlags.KeyMask) }; ;
                    numBut.ButtonPressed += _key_ButtonPressed;
                    p.AddChild(numBut);
                    x += _uiMargin + keyWidth;
                }
                y += keyHeight + _uiMargin;
            }

            y = 0;
            ImageButton backBut = new ImageButton(_bmpBackspace, x, y, keyWidth, keyHeight) { Tag = (int)KeyFlags.BackSpace };
            backBut.RepeatKeyPress = true;
            backBut.ButtonPressed += _key_ButtonPressed;
            p.AddChild(backBut);
            y += backBut._height + _uiMargin;

            TextButton modeSwitch = new TextButton("Mode", x, y, keyWidth, keyHeight) { Tag = (int)KeyFlags.ModeSwitch };
            modeSwitch.ButtonPressed += _keyModeSwitch_ButtonPressed;
            p.AddChild(modeSwitch);
            y += modeSwitch._height + _uiMargin;
        }
        private void CreateQwertyLayout(Container p)
        {
            string keyLine = Keys[0][_charSetUsed];

            int keyWidth = (p._width - (keyLine.Length + 1) * _uiMargin) / keyLine.Length;
            int keyHeight = (p._height - 5 * _uiMargin) / 4;

            int widthRemaining = p._width - ((keyLine.Length + 1) * _uiMargin + keyLine.Length * keyWidth);

            int x, y;

            #region 1st row keys
            x = _uiMargin + widthRemaining / 2;
            y = 0;
            for (int i = 0; i < keyLine.Length; i++)
            {
                TextButton keyBut = new TextButton(keyLine[i].ToString(), x, y, keyWidth, keyHeight) { Tag = (int)KeyFlags.NormalKey | ((int)keyLine[i] & (int)KeyFlags.KeyMask) };
                keyBut.ButtonPressed += _key_ButtonPressed;
                p.AddChild(keyBut);
                x += _uiMargin + keyWidth;
            }
            #endregion

            #region 2nd row keys
            x = _uiMargin + keyWidth / 2 + widthRemaining / 2;
            y += _uiMargin + keyHeight;
            keyLine = Keys[1][_charSetUsed];
            for (int i = 0; i < keyLine.Length; i++)
            {
                TextButton keyBut = new TextButton(keyLine[i].ToString(), x, y, keyWidth, keyHeight) { Tag = (int)KeyFlags.NormalKey | ((int)keyLine[i] & (int)KeyFlags.KeyMask) };
                keyBut.ButtonPressed += _key_ButtonPressed;
                p.AddChild(keyBut);
                x += _uiMargin + keyWidth;
            }
            #endregion

            #region 3rd row keys
            x = _uiMargin + widthRemaining / 2;
            y += _uiMargin + keyHeight;

            _capsButton = new TextButton("abc", x, y, keyWidth + keyWidth / 2, keyHeight) { Tag = (int)KeyFlags.CapsLock };
            _capsButton.ButtonPressed += _key_ButtonPressed;
            p.AddChild(_capsButton);
            x += _uiMargin + _capsButton._width;

            keyLine = Keys[2][_charSetUsed];
            for (int i = 0; i < keyLine.Length; i++)
            {
                TextButton keyBut = new TextButton(keyLine[i].ToString(), x, y, keyWidth, keyHeight) { Tag = (int)KeyFlags.NormalKey | ((int)keyLine[i] & (int)KeyFlags.KeyMask) };
                keyBut.ButtonPressed += _key_ButtonPressed;
                p.AddChild(keyBut);
                x += _uiMargin + keyWidth;
            }

            ImageButton backBut = new ImageButton(_bmpBackspace, x, y, keyWidth + keyWidth / 2, keyHeight) { Tag = (int)KeyFlags.BackSpace };
            backBut.RepeatKeyPress = true;
            backBut.ButtonPressed += _key_ButtonPressed;
            p.AddChild(backBut);
            #endregion

            #region 4th row keys
            x = _uiMargin + widthRemaining / 2;
            y += _uiMargin + keyHeight;

            TextButton modeSwitch = new TextButton("123?", x, y, keyWidth + keyWidth / 2, keyHeight) { Tag = (int)KeyFlags.ModeSwitch };
            modeSwitch.ButtonPressed += _key_ButtonPressed;
            modeSwitch.ButtonLongPressed += _keyModeSwitch_ButtonPressed;

            p.AddChild(modeSwitch);
            x += modeSwitch._width + _uiMargin;

            TextButton slashButton = new TextButton(",", x, y, keyWidth, keyHeight) { Tag = (int)KeyFlags.NormalKey | ((int)',' & (int)KeyFlags.KeyMask) };
            slashButton.ButtonPressed += _key_ButtonPressed;
            p.AddChild(slashButton);
            x += slashButton._width + _uiMargin;

            TextButton spaceButton = new TextButton("________", x, y, keyWidth * 4 + _uiMargin * 4 + keyWidth / 2, keyHeight) { Tag = (int)KeyFlags.NormalKey | ((int)' ' & (int)KeyFlags.KeyMask) };
            spaceButton.ButtonPressed += _key_ButtonPressed;
            p.AddChild(spaceButton);
            x += spaceButton._width + _uiMargin;

            TextButton pointButton = new TextButton(".", x, y, keyWidth, keyHeight) { Tag = (int)KeyFlags.NormalKey | ((int)'.' & (int)KeyFlags.KeyMask) };
            pointButton.ButtonPressed += _key_ButtonPressed;
            p.AddChild(pointButton);
            x += pointButton._width + _uiMargin;

            _enterButton = new ImageButton(_bmpEnter, x, y, keyWidth * 2, keyHeight) { Tag = (int)KeyFlags.Enter };
            _enterButton.ButtonPressed += _key_ButtonPressed;
            p.AddChild(_enterButton);
            #endregion
        }
        private void CreateCommonLayout()
        {
            string keyLine = Keys[0][_charSetUsed];
            int keyWidth = (_width - (keyLine.Length + 1) * _uiMargin) / keyLine.Length;
            int keyHeight = (_height / 2 - 5 * _uiMargin) / 4;

            int widthRemaining = _width - ((keyLine.Length + 1) * _uiMargin + keyLine.Length * keyWidth);

            int x = _uiMargin + widthRemaining / 2,
                y = _uiMargin;

            _editLabel = new Label(string.Empty, x, y, _width - 2 * _uiMargin - widthRemaining, StyleManager.CurrentStyle.LabelFont.Height);
            base.AddChild(_editLabel);

            _editTextbox = new EditableTextBox(string.Empty, x, y, _editLabel._width, _height / 4 - 2 * _uiMargin);
            base.AddChild(_editTextbox);

            #region done/cancel buttons
            x = _editTextbox.ScreenRight - 2 * keyWidth - _uiMargin;
            y = _editTextbox.ScreenBottom + _uiMargin;

            _doneButton = new TextButton("Done", x, y, 2 * keyWidth + _uiMargin, keyHeight);
            _doneButton.ButtonPressed += (sender) => { Close(); };
            base.AddChild(_doneButton);

            x -= keyWidth * 2 + _uiMargin * 2;
            TextButton _cancelButton = new TextButton("Cancel", x, y, keyWidth * 2 + _uiMargin, keyHeight);
            _cancelButton.ButtonPressed += (sender) =>
            {
                _editTextbox.Text = _initialText;
                if (_allowCloseOnlyWhenValid)
                {
                    if (_editTextbox.Valid)
                        Close();
                }
                else Close();
            };
            base.AddChild(_cancelButton);
            #endregion

            #region left/right/clear buttons
            Color transparentColor = ColorUtility.ColorFromRGB(255, 0, 255);
            Bitmap leftImg = Resources.Images.GetBitmap(Resources.Images.BitmapResources.arrowLeft);

            x = _uiMargin + widthRemaining / 2;
            y = _editTextbox.Height + 2 * _uiMargin;

            leftImg.MakeTransparent(transparentColor);
            _leftBut = new ImageButton(leftImg, x, y, keyHeight, keyHeight);
            _leftBut.RepeatKeyPress = true;
            _leftBut.ButtonPressed += (sender) =>
            {
                if (_editTextbox.CarretPosition != 0)
                {
                    _editTextbox.CarretPosition--;
                    RemakeButtonsEnabled();
                }
            };
            _leftBut.Enabled = false;
            x += _leftBut.Width + _uiMargin;
            base.AddChild(_leftBut);

            Bitmap rightImg = Resources.Images.GetBitmap(Resources.Images.BitmapResources.arrowRight);
            rightImg.MakeTransparent(transparentColor);
            _rightBut = new ImageButton(rightImg, x, y, keyHeight, keyHeight);
            _rightBut.RepeatKeyPress = true;
            _rightBut.ButtonPressed += (sender) =>
            {
                if (_editTextbox.CarretPosition != _editTextbox.Text.Length)
                {
                    _editTextbox.CarretPosition++;
                    RemakeButtonsEnabled();
                }
            };
            _rightBut.Enabled = false;
            x += _rightBut.Width + _uiMargin;
            base.AddChild(_rightBut);

            Bitmap clearImg = Resources.Images.GetBitmap(Resources.Images.BitmapResources.clear);
            clearImg.MakeTransparent(transparentColor);
            _clearBut = new ImageButton(clearImg, x, y, keyHeight, keyHeight);
            _clearBut.ButtonPressed += (sender) =>
            {
                if (_editTextbox.Text.Length != 0)
                {
                    _editTextbox.Text = string.Empty;
                    RemakeButtonsEnabled();
                }
            };
            _clearBut.Enabled = false;
            base.AddChild(_clearBut);
            #endregion
        }
Esempio n. 7
0
        private static void CreateOtherSettingsPanel(Panel panel)
        {
            const int leftMargin = 10, topMargin = 10;
            int width = (panel.Width - leftMargin * 3) / 2;

            TextButton setTime, setDate, butCalibrate;
            panel.AddChild(setTime = new TextButton("Set Time", leftMargin, topMargin, width, 35));
            panel.AddChild(setDate = new TextButton("Set Date", leftMargin * 2 + width, topMargin, width, 35));
            panel.AddChild(butCalibrate = new TextButton("Calibrate", leftMargin, topMargin * 2 + setTime.Height + 5, width, 35));

            GetTimeDialog getTimeDiag = new GetTimeDialog();
            GetDateDialog getDateDiag = new GetDateDialog();

            setTime.ButtonPressed += (s) =>
            {
                new Thread(new ThreadStart(() =>
                {
                    if (getTimeDiag.Show("Select new Time", DateTime.Now.Hour, DateTime.Now.Minute))
                    {
                        DateTime current = DateTime.Now;
                        DateTime newDateTime = new DateTime(current.Year, current.Month, current.Day, getTimeDiag.SelectedHour, getTimeDiag.SelectedMinute, 0);
                        try
                        {
                            //TODO: emulator throws exception
                            Utility.SetLocalTime(newDateTime);
                            RealTimeClock.SetTime(newDateTime);
                        }
                        catch (Exception) { }
                    }
                })).Start();
            };

            setDate.ButtonPressed += (s) =>
            {
                new Thread(new ThreadStart(() =>
                {
                    if (getDateDiag.Show("Select new Date", DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year))
                    {
                        DateTime current = DateTime.Now;
                        DateTime newDateTime = new DateTime(getDateDiag.SelectedYear, getDateDiag.SelectedMonth, getDateDiag.SelectedDay, current.Hour, current.Minute, current.Second);
                        try
                        {
                            //TODO: emulator throws exception
                            Utility.SetLocalTime(newDateTime);
                            RealTimeClock.SetTime(newDateTime);
                        }
                        catch (Exception) { }
                    }
                })).Start();
            };

            butCalibrate.ButtonPressed += (s) => DesktopManager.Instance.StartCalibration();
        }
Esempio n. 8
0
        private static void CreateNetworkSettingsPanel(Panel panel)
        {
            const int leftMargin = 10;
            const int topMargin = 10;

            NetworkInterface net = NetworkInterface.GetAllNetworkInterfaces()[0];

            bool isDhcp = net.IsDhcpEnabled;
            int labelFontHeightDiv2 = StyleManager.CurrentStyle.LabelFont.Height / 2;

            RadioButton rdStatic, rdDynamic;
            panel.AddChild(new Label("Configuration", leftMargin, topMargin + 13 - labelFontHeightDiv2, 80, 25));
            panel.AddChild(rdStatic = new RadioButton("Static", 100, topMargin, 80, 26) { IsChecked = !isDhcp });
            panel.AddChild(rdDynamic = new RadioButton("Dynamic", rdStatic.X + rdStatic.Width + 10, topMargin, 80, 26) { IsChecked = isDhcp });

            TextBox txtIp, txtNetMask, txtGateway, txtDns;

            int y = rdStatic.Y + rdStatic.Height + 5;

            panel.AddChild(new Label("Address", leftMargin, y + 15 - labelFontHeightDiv2, 80, 25));
            panel.AddChild(txtIp = new TextBox(net.IPAddress.ToString(), 100, y, 175, 30)
            {
                EditTextLabel = "IP Address",
                Validator = NetValidators.IpValidator,
                AllowedChars = AllowedCharTypesEnum.Ip,
                Enabled = !isDhcp
            });
            y += 35;

            panel.AddChild(new Label("Netmask", leftMargin, y + 15 - labelFontHeightDiv2, 80, 25));
            panel.AddChild(txtNetMask = new TextBox(net.SubnetMask.ToString(), 100, y, 175, 30)
            {
                EditTextLabel = "Subnet Mask",
                Validator = NetValidators.NetMaskValidator,
                AllowedChars = AllowedCharTypesEnum.Ip,
                Enabled = !isDhcp
            });
            y += 35;

            panel.AddChild(new Label("Gateway", leftMargin, y + 15 - labelFontHeightDiv2, 80, 25));
            panel.AddChild(txtGateway = new TextBox(net.GatewayAddress.ToString(), 100, y, 175, 30)
            {
                EditTextLabel = "Gateway IP Address",
                Validator = NetValidators.IpValidator,
                AllowedChars = AllowedCharTypesEnum.Ip,
                Enabled = !isDhcp
            });
            y += 35;

            panel.AddChild(new Label("Dns", leftMargin, y + 15 - labelFontHeightDiv2, 80, 25));
            panel.AddChild(txtDns = new TextBox(net.DnsAddresses.Length >= 1 ? net.DnsAddresses[0] : string.Empty, 100, y, 175, 30)
            {
                EditTextLabel = "DNS Address",
                Validator = NetValidators.IpAllowEmptyValidator,
                AllowedChars = AllowedCharTypesEnum.Ip,
                Enabled = !isDhcp
            });
            y += 35;

            TextButton applyButton = null, proxyButton;

            UiEventHandler modeChangedHandler = (s) =>
            {
                bool dynamicSelected = rdDynamic.IsChecked;

                panel.Suspended = true;

                txtIp.Enabled = !dynamicSelected;
                txtNetMask.Enabled = !dynamicSelected;
                txtGateway.Enabled = !dynamicSelected;
                txtDns.Enabled = !dynamicSelected;

                if (!dynamicSelected)
                {
                    txtIp.Text = net.IPAddress.ToString();
                    txtNetMask.Text = net.SubnetMask.ToString();
                    txtGateway.Text = net.GatewayAddress.ToString();
                    txtDns.Text = net.DnsAddresses.Length >= 1 ? net.DnsAddresses[0].ToString() : string.Empty;
                }
                else applyButton.Enabled = true;

                panel.Suspended = false;
            };
            rdStatic.IsCheckedChanged += modeChangedHandler;

            int x = txtIp.X + txtIp.Width + 10;
            panel.AddChild(applyButton = new TextButton("Apply", x, txtIp.Y, panel.Width - x - 10, txtIp.Height * 2 + 5) { Enabled = false });
            panel.AddChild(proxyButton = new TextButton("Proxy", x, txtGateway.Y, panel.Width - x - 10, txtGateway.Height * 2 + 5));

            applyButton.ButtonPressed += (s) =>
            {
                applyButton.Enabled = false;

                AppSettings.Instance.Network.DhcpEnabled = rdDynamic.IsChecked;

                if (rdDynamic.IsChecked)
                {
                    net.EnableDhcp();
                }
                else
                {
                    net.EnableStaticIP(txtIp.Text, txtNetMask.Text, txtGateway.Text);

                    if (txtDns.Text.Length != 0)
                    {
                        AppSettings.Instance.Network.DnsAddresses = new string[] { txtDns.Text };
                        net.EnableStaticDns(AppSettings.Instance.Network.DnsAddresses);
                    }
                    AppSettings.Instance.Network.IpAddress = IPAddress.Parse(txtIp.Text).GetAddressBytes();
                    AppSettings.Instance.Network.NetMask = IPAddress.Parse(txtNetMask.Text).GetAddressBytes();
                    AppSettings.Instance.Network.Gateway = IPAddress.Parse(txtGateway.Text).GetAddressBytes();
                }

                AppSettings.Instance.Save();
            };

            ProxyDialog proxyDiag = new ProxyDialog();
            proxyButton.ButtonPressed += (s) =>
            {
                new Thread(new ThreadStart(() =>
                    {
                        if (proxyDiag.Show(AppSettings.Instance.Network.UseProxy, AppSettings.Instance.Network.Proxy.UseForRadio, AppSettings.Instance.Network.Proxy.Address))
                        {
                            AppSettings.Instance.Network.UseProxy = proxyDiag.UseProxy;
                            AppSettings.Instance.Network.Proxy.UseForRadio = proxyDiag.UseForRadio;
                            AppSettings.Instance.Network.Proxy.Address = proxyDiag.ProxyAddress;

                            proxyForWeather = AppSettings.Instance.Network.UseProxy && !AppSettings.Instance.Network.Proxy.UseForRadio ?
                                new WebProxy(AppSettings.Instance.Network.Proxy.Address) : null;

                            AppSettings.Instance.Save();
                        }
                    })).Start();
            };

            txtDns.TextChanged += (nt, valid) => applyButton.Enabled = valid;
            txtIp.TextChanged += (nt, valid) => applyButton.Enabled = valid;
            txtGateway.TextChanged += (nt, valid) => applyButton.Enabled = valid;
            txtNetMask.TextChanged += (nt, valid) => applyButton.Enabled = valid;
        }