Пример #1
0
        //---------------------------------------------------------------------------

        /*protected override void OnKeyPress(KeyPressEventArgs e)
         * //protected override void OnKeyDown(KeyEventArgs e)
         * {
         *  // Suche ab dem aktuellen Eintrag + 1 bis zum aktuellen Eintrag,
         *  // ob ein Eintrag mit dem getippten Anfangsbuchstaben auftaucht
         *  //	bool bFound = false;
         *  for (int i = 0; i < Items.Count; i++)
         *  {
         *      if ((Strings[(i + SelectedIndex + 1) % Items.Count][0] | 0x20) == (e.KeyChar | 0x20))
         *      {	// gefunden, also selektieren
         *          SelectedIndex = (i + SelectedIndex + 1) % Items.Count;
         *          base.OnChange(EventArgs.Empty);
         *          //			bFound = true;
         *          break;
         *      }
         *  }
         *  // Kein Ton, der nervt nur
         *  //	if (!bFound) Beep();
         *  e.KeyChar = '\0';
         *  //base.OnKeyPress(e);
         * }*/

        //---------------------------------------------------------------------------
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            int Left;

            if (ImageList == null)
            {   // Gibt keine Imagelist, drum ganz normal zeichnen
                Left = e.Bounds.Left + 1;
            }
            else
            {
                Left = e.Bounds.Left + ImageList.ImageSize.Width + 2;
            }
            e.DrawBackground(); e.DrawFocusRectangle();
            if (e.Index < 0)
            {
                return;
            }
            ImageComboItem item = (ImageComboItem)this.Items[e.Index];

            if (ImageList != null && item.ImageIndex != -1)
            {
                this.ImageList.Draw(e.Graphics, e.Bounds.Left + 1, e.Bounds.Top, item.ImageIndex); //(State.Contains(odSelected)) ? Imglist::dsSelected : Imglist::dsNormal, itImage
            }
            Color color = e.ForeColor;

            if ((e.State & DrawItemState.Disabled) != 0)
            {
                color = SystemColors.GrayText;
            }
            using (Brush brush = new SolidBrush(color))
                e.Graphics.DrawString(Strings[e.Index], e.Font, brush, Left, e.Bounds.Top + 1);

            base.OnDrawItem(e);
        }
Пример #2
0
        void PopulateColourCombo()
        {
            int index = 0;

            cmbColour.Items.Clear();
            cmbColour.ImageList.Images.Clear();
            cmbColour.ImageList.ColorDepth = ColorDepth.Depth32Bit;
            foreach (Task t in Todomoo.Tasks)
            {
                cmbColour.ImageList.Images.Add(IconColoured.GetSquared(t.Colour));
                ImageComboItem item = new ImageComboItem(Lang.Get("colour_as") + " " + t.Name, index);
                item.Tag = t.Colour;
                cmbColour.Items.Add(item);
                index++;
            }
            if (cmbColour.Items.Count == 0)
            {
                cmbColour.ImageList.Images.Add(IconColoured.GetSquared(Color.Gray));
                ImageComboItem item = new ImageComboItem(Lang.Get("default"), index);
                item.Tag = Color.Gray;
                cmbColour.Items.Add(item);
                index++;
            }
            cmbColour.SelectedIndex = 0;
        }
Пример #3
0
        void PopulateCategoryCombo(int select_category)
        {
            int index = 0;

            cmbCategory.Items.Clear();
            cmbCategory.ImageList.Images.Clear();
            cmbCategory.ImageList.ColorDepth = ColorDepth.Depth32Bit;
            foreach (Category c in Todomoo.Categories)
            {
                cmbCategory.ImageList.Images.Add(IconColoured.GetSquared(c.Colour));
                ImageComboItem item = new ImageComboItem(c.Name, index);
                item.Tag = c.Id;
                cmbCategory.Items.Add(item);
                index++;
            }
            if (cmbCategory.Items.Count == 0)
            {
                cmbCategory.Enabled = false;
                cmbCategory.Items.Add(new ImageComboItem(Lang.Get("category_must_create")));
            }
            cmbCategory.SelectedIndex = 0;
            if (select_category != 0)
            {
                foreach (ImageComboItem item in cmbCategory.Items)
                {
                    if ((int)item.Tag == select_category)
                    {
                        cmbCategory.SelectedItem = item;
                    }
                }
            }
        }
Пример #4
0
        private string CompileLapis()
        {
            string chunk = "";

            for (int i = 1; i < cmbQuality.Items.Count; i++)
            {
                LapiImageComboBox cmb  = Controls["cmbSockel" + i] as LapiImageComboBox;
                ImageComboItem    item = (cmb.Items[cmb.SelectedIndex] as ImageComboItem);
                if (item == null)
                {
                    chunk += "-1:-1;";
                    continue;
                }

                Lapi lapi = item.Tag as Lapi;
                if (lapi != null)
                {
                    chunk += lapi.ToImageIndex() + ":" + lapi.Level + ";";
                }
                else                 // empty slot = type -1
                {
                    chunk += "-1:0;";
                }
            }

            return(chunk);
        }
Пример #5
0
        void cbLanguage_SelectedValueChanged(object sender, EventArgs e)
        {
            ImageComboItem itm  = (ImageComboItem)this.cbLanguage.SelectedItem;
            LocaleItem     lang = (LocaleItem)itm.Tag;

            optset.Language          = lang.LocaleValue;
            this.localizator.Culture = optset.Language;
            this.localizator.Localize(this);
        }
Пример #6
0
 private void InitLoginCmb()
 {
     LocalLoginUserList = LocalLoginManager.GetLocalUsers();
     ImgCmbUserName.Items.Clear();
     foreach (LocalLoginUser pUser in LocalLoginUserList)
     {
         ImageComboItem pItem = new ImageComboItem(pUser.UserName, 0);
         ImgCmbUserName.Items.Add(pItem);
     }
 }
Пример #7
0
 void BtnChooseColourClick(object sender, EventArgs e)
 {
     if (colorDialog.ShowDialog() == DialogResult.OK)
     {
         Color col = colorDialog.Color;
         cmbColour.ImageList.Images.Add(IconColoured.GetSquared(col));
         ImageComboItem item = new ImageComboItem("RGB [" + col.R + ", " + col.G + ", " + col.B + "]", cmbColour.Items.Count);
         item.Tag = col;
         cmbColour.Items.Add(item);
         cmbColour.SelectedIndex = cmbColour.Items.Count - 1;
     }
 }
Пример #8
0
        /// <summary>
        /// Edit a Category object.
        /// </summary>
        /// <param name="category">Category to edit</param>
        public CategoryForm(Languages.Language language, Category category)
        {
            // Windows Forms designer support.
            InitializeComponent();

            // Setup task
            this.category = category;

            // Create form icon
            this.Icon = IconColoured.GetSquaredIcon(category.Colour);

            // Setup language
            Lang                 = language;
            Text                 = Lang.Get((category.Id == 0) ? "category_add" : "category_edit");
            btnOk.Text           = " " + Lang.Get((category.Id == 0) ? "add" : "edit");
            btnCancel.Text       = Lang.Get("cancel");
            btnChooseColour.Text = " " + Lang.Get("colour_choose");
            lblName.Text         = Lang.Get("name") + ":";
            lblColour.Text       = Lang.Get("colour") + ":";

            // Populate colours combo
            int index = 0;

            cmbColour.ImageList.ColorDepth = ColorDepth.Depth32Bit;
            foreach (Category cat in Todomoo.Categories)
            {
                cmbColour.ImageList.Images.Add(IconColoured.GetSquared(cat.Colour));
                ImageComboItem item = new ImageComboItem(Lang.Get("colour_as") + " " + cat.Name, index);
                item.Tag = cat.Colour;
                cmbColour.Items.Add(item);
                index++;
            }
            if (cmbColour.Items.Count == 0)
            {
                cmbColour.ImageList.Images.Add(IconColoured.GetSquared(Color.Gray));
                ImageComboItem item = new ImageComboItem(Lang.Get("default"), index);
                item.Tag = Color.Gray;
                cmbColour.Items.Add(item);
            }
            cmbColour.SelectedIndex = 0;

            // Fill in GUI fields
            txtName.Text = category.Name;
            foreach (ImageComboItem item in cmbColour.Items)
            {
                if (item.Text == Lang.Get("colour_as") + " " + category.Name)
                {
                    cmbColour.SelectedItem = item;
                }
            }
        }
        public void BuildDriveList()
        {
            base.Items.Clear();

            ShellAPI.SHFILEINFO shFInfo = new ShellAPI.SHFILEINFO();

            ShellAPI.SHGFI dwAttribs = ShellAPI.SHGFI.SHGFI_ICON | ShellAPI.SHGFI.SHGFI_SMALLICON | ShellAPI.SHGFI.SHGFI_SYSICONINDEX | ShellAPI.SHGFI.SHGFI_DISPLAYNAME;

            ListDictionary _iconDict = new ListDictionary();

            foreach (string drive in Directory.GetLogicalDrives())
            {
                IntPtr m_pHandle = ShellAPI.SHGetFileInfo(drive, ShellAPI.FILE_ATTRIBUTE_NORMAL, ref shFInfo, (uint)Marshal.SizeOf(shFInfo), dwAttribs);

                if (m_pHandle.Equals(IntPtr.Zero) == false)
                {
                    int idxIcon = 0;

                    if (_iconDict.Contains(shFInfo.iIcon) == false)
                    {
                        base.ImageList.Images.Add(Icon.FromHandle(shFInfo.hIcon).Clone() as Icon);

                        User32API.DestroyIcon(shFInfo.hIcon);

                        _iconDict.Add(shFInfo.iIcon, _iconDict.Count);

                        idxIcon = _iconDict.Count - 1;
                    }
                    else
                    {
                        idxIcon = Convert.ToInt32(_iconDict[shFInfo.iIcon]);
                    }

                    ImageComboItem item = new ImageComboItem(shFInfo.szDisplayName, idxIcon, false);

                    item.ItemValue = drive;

                    base.Items.Add(item);
                }
            }

            if (base.Items.Count != 0)
            {
                base.SelectedIndex = 0;
            }
        }
Пример #10
0
        private void LoadLanguageDirectory(string path)
        {
            int i;

            cbLanguage.Items.Clear();

            if (!Directory.Exists(path))
            {
                return;
            }

            string[] langFiles = Directory.GetFiles(path, "*.resources");
            if (langFiles.Length <= 0)
            {
                return;
            }

            for (i = 0; i < langFiles.Length; i++)
            {
                FileInfo finfo = new FileInfo(langFiles[i]);
                string   args  = finfo.Name.Replace(finfo.Extension, "");
                args = args.Replace("lang.", "");

                string         locale_name = (string)locales[args];
                LocaleItem     itm         = new LocaleItem(locale_name, args);
                ImageComboItem cbitm       = new ImageComboItem(itm.LocaleName, LocaleImageIndex(args));
                cbitm.Tag = itm;
                int pos = cbLanguage.Items.Add(cbitm);
            }

            for (i = 0; i < cbLanguage.Items.Count; i++)
            {
                ImageComboItem itm  = (ImageComboItem)cbLanguage.Items[i];
                LocaleItem     litm = (LocaleItem)itm.Tag;
                if (litm.LocaleValue == optset.Language)
                {
                    cbLanguage.SelectedIndex = i;
                    startupLanguageIdx       = i;
                    break;
                }
            }
        }
		public void BuildDriveList()
		{
			base.Items.Clear();

			ShellAPI.SHFILEINFO shInfo = new ShellAPI.SHFILEINFO();
			ShellAPI.SHGFI dwAttribs = 
				ShellAPI.SHGFI.SHGFI_ICON |
				ShellAPI.SHGFI.SHGFI_SMALLICON |
				ShellAPI.SHGFI.SHGFI_SYSICONINDEX |
				ShellAPI.SHGFI.SHGFI_DISPLAYNAME;

			ListDictionary _iconDict = new ListDictionary();			
			foreach( string drive in System.IO.Directory.GetLogicalDrives() )
			{
				IntPtr m_pHandle = ShellAPI.SHGetFileInfo(drive, ShellAPI.FILE_ATTRIBUTE_NORMAL, ref shInfo, (uint)System.Runtime.InteropServices.Marshal.SizeOf(shInfo), dwAttribs);

				if( m_pHandle.Equals(IntPtr.Zero)==false )					
				{
					int idxIcon = 0;
					if( _iconDict.Contains(shInfo.iIcon)==false )
					{
						base.ImageList.Images.Add( System.Drawing.Icon.FromHandle(shInfo.hIcon).Clone() as System.Drawing.Icon );

						User32API.DestroyIcon(shInfo.hIcon);

						_iconDict.Add( shInfo.iIcon, _iconDict.Count );
						idxIcon = _iconDict.Count-1;
					}
					else
						idxIcon = Convert.ToInt32( _iconDict[shInfo.iIcon] );


					ImageComboItem item = new ImageComboItem(shInfo.szDisplayName, idxIcon, false);
					item.ItemValue = drive;
					base.Items.Add( item );
				}
			}

			if( base.Items.Count!=0 )
				base.SelectedIndex = 0;
		}
Пример #12
0
        private void LoadLanguages()
        {
            // Loads the languages found in the lang subfolder on the application's startup path.
            ImageComboItem comboItem;

            if (!Directory.Exists(Application.StartupPath + @"\lang\"))  // If lang directory is missing, disable language selection
            {
                Console.WriteLine("Error: The directory lang\\ does not exist.");
                LanguageIcons.Images.Add("error", Properties.Resources.errorLang);
                imageComboLanguage.ImageList  = LanguageIcons;
                LanguageText["errorLang"]     = "error";
                LanguageText["errorLangLong"] = "Lang. error";
                comboItem     = new ImageComboItem("Lang. error", 0);
                comboItem.Tag = "error";
                imageComboLanguage.Items.Add(comboItem);
                imageComboLanguage.SelectedIndex = 0;
                imageComboLanguage.Enabled       = false;
                AvailableLanguages.Clear();
                CurrentLanguage = "error";
                return;
            }

            bool noDefaultLangFile = false;

            string[] filePaths = Directory.GetFiles(Application.StartupPath + @"\lang\", "*.dat", SearchOption.TopDirectoryOnly);
            Console.WriteLine("Number of language files found: {0}", filePaths.Length);

            if (filePaths.Length == 0)  // If no language files exist, disable language selection
            {
                Console.WriteLine("Error: Could not locate any language files.");
                LanguageIcons.Images.Add("error", Properties.Resources.errorLang);
                imageComboLanguage.ImageList  = LanguageIcons;
                LanguageText["errorLang"]     = "error";
                LanguageText["errorLangLong"] = "Lang. error";
                comboItem     = new ImageComboItem("Lang. error", 0);
                comboItem.Tag = "error";
                imageComboLanguage.Items.Add(comboItem);
                imageComboLanguage.SelectedIndex = 0;
                imageComboLanguage.Enabled       = false;
                AvailableLanguages.Clear();
                CurrentLanguage = "error";
                return;
            }

            if (!filePaths.Contains(Application.StartupPath + @"\lang\" + DefaultLanguage + ".dat")) // If default language cannot be found, add it anyway
            {
                // The application's default language was not found in the lang folder, but it can still be added to the language list
                filePaths         = filePaths.Append(Application.StartupPath + @"\lang\" + DefaultLanguage + ".dat").ToArray();
                noDefaultLangFile = true;
                Console.WriteLine("The application's default language file, {0}, was not found. However, it can still be added to the language list.", DefaultLanguageLong);
            }
            filePaths = filePaths.OrderBy(s => s).ToArray(); // Sort alphabetically so that languages are displayed alphebetically in the dropdown list

            string langShort;

            string[] keyvalue = new string[2]; // keyvalue[0] = the key; keyvalue[1] = the value
            int      equalsIndex;
            int      i = 0;

            foreach (var file in filePaths)
            {
                langShort = Path.GetFileNameWithoutExtension(file);
                if (noDefaultLangFile && langShort.Equals(DefaultLanguage))
                {
                    // Add the default language, even though it previously failed to load its .dat file.
                    LanguageIcons.Images.Add(DefaultLanguage, Properties.Resources.defaultLangIcon);
                    LanguageText[DefaultLanguage + "Lang"]     = DefaultLanguage;
                    LanguageText[DefaultLanguage + "LangLong"] = DefaultLanguageLong;
                    comboItem     = new ImageComboItem(DefaultLanguageLong, i);
                    comboItem.Tag = DefaultLanguage;
                    imageComboLanguage.Items.Add(comboItem);
                    AvailableLanguages.Add(DefaultLanguage);
                    i++;
                    continue;
                }

                // Load language text
                foreach (string line in File.ReadAllLines(file, Encoding.Unicode))
                {
                    equalsIndex = line.IndexOf("=");
                    if (equalsIndex > 0)                                                               // If there is at least 1 "=" character and it isn't the first character
                    {
                        keyvalue[0] = line.Substring(0, equalsIndex);                                  // The key
                        keyvalue[1] = line.Substring(equalsIndex + 1, line.Count() - equalsIndex - 1); // The value

                        if (!LanguageText.ContainsKey(langShort + keyvalue[0]))
                        {
                            LanguageText.Add(langShort + keyvalue[0], keyvalue[1]);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Error: A line in the file {0} is not formatted properly.", file);
                    }
                }

                // Load language icon
                if (!LanguageIcons.Images.ContainsKey(langShort))
                {
                    if (LanguageText.ContainsKey(langShort + "Icon"))
                    {
                        if (File.Exists(Application.StartupPath + @"\lang\" + LanguageText[langShort + "Icon"]))
                        {
                            LanguageIcons.Images.Add(langShort, Image.FromFile(Application.StartupPath + @"\lang\" + LanguageText[langShort + "Icon"]));
                        }
                        else  // There was an error loading the language icon
                        {
                            LanguageIcons.Images.Add(langShort, Properties.Resources.errorLang);
                            Console.WriteLine("Error loading language icon for the language: {0}.", langShort);
                        }
                    }
                    else  // No language icon was specified
                    {
                        LanguageIcons.Images.Add(langShort, Properties.Resources.noLangIcon);
                    }

                    // Check if it's already in the list first?
                    comboItem     = new ImageComboItem(LanguageText[langShort + "LangLong"], i);
                    comboItem.Tag = langShort;
                    imageComboLanguage.Items.Add(comboItem);
                }

                AvailableLanguages.Add(langShort);
                i++;
            }

            imageComboLanguage.ImageList = LanguageIcons;

            if (CurrentLanguage == "")                                // If the CurrentLanguage has not been set, then set it
            {
                if (AvailableLanguages.Contains(UserDefaultLanguage)) // 1st priority is the user's chosen default language if it exists in the lang folder
                {
                    CurrentLanguage = UserDefaultLanguage;
                }
                else if (AvailableLanguages.Contains(DefaultLanguage)) // 2nd priority is the program's default language if it exists in the lang folder
                {
                    CurrentLanguage = DefaultLanguage;
                    // The default language should always be available
                }
                else if (AvailableLanguages.Count > 0) // 3rd priority is whatever other language exists in the lang folder
                {
                    // This case should never occur if everything is working correctly, because the default language should always be available
                    CurrentLanguage = AvailableLanguages.First();
                }
                else // Last is the error state where no languages exist.
                {
                    // This case should be caught previously by previous error checks and should never occur.
                    return;
                }

                // Select the current language in the ImageCombo drop-down list:
                foreach (ImageComboItem item in imageComboLanguage.Items)
                {
                    if (item.ItemText == LanguageText[CurrentLanguage + "LangLong"])
                    {
                        imageComboLanguage.SelectedIndex = item.ImageIndex;
                    }
                }
            }

            RefreshLanguage();
            imageComboLanguage.Refresh();
        }