예제 #1
0
        public static void SaveBootMappingsVista()
        {
            // Well, we need to write to HKLM under Vista or later.
            // Create a registry file and run it, user will have to allow regedit to run.

            if (!AppController.ConfirmWriteToProtectedSectionOfRegistryOnVistaOrLater("the changes to your boot mappings"))
            {
                return;
            }

            string tempfile = ExportMappingsAsRegistryFile(true);

            AppController.WriteRegistryFileVista(tempfile);
        }
예제 #2
0
        private static Bitmap DrawCaptionLine(Bitmap bmp, string caption, float fontsize, TextPosition where, bool localizable, Color fontColour)
        {
            // The upper 10/64 and lower 14/64 of the button are not considered drawing area
            // so discount them when calculating the row position. This also knocks the centre down by 4/64.

            using (Font font = AppController.GetButtonFont(fontsize, localizable))
                using (Graphics g = Graphics.FromImage(bmp))
                {
                    g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

                    // Use width of actual string for left placement:
                    // This only takes tiny amount of time - 14ms for 10000 iterations..
                    SizeF stringSize = g.MeasureString(caption, font);

                    int left = (bmp.Width / 2) - (int)(stringSize.Width / 2);
                    int top  = 0;

                    // Vertical centre justify within button and row:
                    switch (@where)
                    {
                    case TextPosition.Middle:
                        // Remove cast to int, get 'possible loss of fraction'. Oh well..
                        top = (int)(((bmp.Height - stringSize.Height) / 2) + (int)(bmp.Height / 28));
                        break;

                    case TextPosition.TextTop:
                        top = (int)(bmp.Height * 14F / 64F);
                        break;

                    case TextPosition.Bottom:
                        top = bmp.Height / 2;
                        break;

                    case TextPosition.SymbolTop:
                        top = (int)(bmp.Height * 8F / 64F);
                        break;
                    }

                    using (SolidBrush b = new SolidBrush(fontColour))
                    {
                        g.DrawString(caption, font, b, new Point(left, top));
                    }
                }

            return(bmp);
        }
예제 #3
0
        public Dictionary <string, int> GetGroupMembers(string groupname, int threshold)
        {
            // Enumerate group.
            string queryExpression;

            if (groupname == AllKeysGroupName)
            {
                queryExpression = @"/KeycodeData/keycodes[group!='Unmappable Keys']";
            }
            else if (groupname == _commonlyUsedKeysGroupName)
            {
                queryExpression = @"/KeycodeData/keycodes[useful>='2'" + "]";
            }
            else
            {
                queryExpression = @"/KeycodeData/keycodes[group='" + groupname + "' and useful>='" + threshold.ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat) + "']";
            }

            XPathNodeIterator iterator;

            iterator = (XPathNodeIterator)_navigator.Select(queryExpression);

            // Gives us a bunch of keycode nodes.
            // Given the scancode / extended from each node, ask for the name from the current layout.
            int scancode, extended;

            Dictionary <string, int> dir = new Dictionary <string, int>(iterator.Count);

            foreach (XPathNavigator node in iterator)
            {
                scancode = Int32.Parse(GetElementValue("sc", node), CultureInfo.InvariantCulture.NumberFormat);
                extended = Int32.Parse(GetElementValue("ex", node), CultureInfo.InvariantCulture.NumberFormat);
                string name = AppController.GetKeyName(scancode, extended);
                if (dir.ContainsKey(name)) // ArgumentException results when trying to add duplicate key..
                {
                    Console.WriteLine("Duplicate name error: Name {0} Existing Scancode : {1} Scancode: {2}", name, dir[name], scancode);
                }
                else
                {
                    dir.Add(name, KeyHasher.GetHashFromKeyData(scancode, extended));
                }
            }

            return(dir);
        }
예제 #4
0
        private static void Main()
        {
            if (AppController.IsOnlyAppInstance() == false)
            {
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            Application.ThreadException += ApplicationThreadException;
            AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;

            AppController.CreateAppDirectory();

#if DEBUG
#else
            Console.Write("Redirecting console output");
            LogProvider.RedirectConsoleOutput();
#endif

            ConfigFileProvider.ValidateUserConfigFile();

            Properties.Settings userSettings = new Properties.Settings();
            if (userSettings.UpgradeRequired)
            {
                Console.WriteLine("Upgrading settings to new version");
                userSettings.Upgrade();
                userSettings.UpgradeRequired = false;
                userSettings.Save();
            }

            AppController.Start();

            Application.Run(new KeyboardForm());

            AppController.Close();
            // Release static events or else leak.
            Application.ThreadException -= ApplicationThreadException;
            AppDomain.CurrentDomain.UnhandledException -= UnhandledExceptionHandler;
        }
예제 #5
0
        public static void SetFontSizes(float scale)
        {
            // See what font size fits the scaled-down button
            float baseFontSize = 36F;

            // Not using ButtonImages.GetButtonImage as that is where we were called from..
            using (var font = AppController.GetButtonFont(baseFontSize, false))
                using (var bmp = ButtonImages.ResizeBitmap(ButtonImages.GetBitmap(BlankButton.Blank), scale, false))
                    using (var g = Graphics.FromImage(bmp))
                    {
                        // Helps MeasureString. Can also pass StringFormat.GenericTypographic apparently ??

                        g.TextRenderingHint = TextRenderingHint.AntiAlias;
                        var characterWidth = (int)g.MeasureString(((char)77).ToString(CultureInfo.InvariantCulture), font).Width;

                        // Only use 90% of the bitmap's size to allow for the edges (especially at small sizes)
                        float ratio = (((0.9F * bmp.Height) / 2)) / characterWidth;
                        baseFontSize = (baseFontSize * ratio);
                    }

            BaseFontSize = baseFontSize;
        }
예제 #6
0
        public static void ShowKeyboardList()
        {
            var kblist    = GetInstalledKeyboardListInNameOrder();
            var keyboards = new StringBuilder();

            foreach (string keyboard in kblist)
            {
                keyboards.Append(keyboard + (char)13 + (char)10);
            }

            string keyboardListFile = Path.Combine(Path.GetTempPath(), "installed keyboards.txt");

            AppController.RegisterTempFile(keyboardListFile); // Reluctantly register for deletion

            using (var fs = new FileStream(keyboardListFile, FileMode.Create))
                using (var sw = new StreamWriter(fs))
                {
                    sw.Write(keyboards.ToString());
                    sw.Flush();
                }
            System.Diagnostics.Process.Start(keyboardListFile);
        }
예제 #7
0
        private static Bitmap StretchButtonVertical(Bitmap bmp, int verticalstretch)
        {
            // Same as horizontal more-or-less

            int halfheight  = bmp.Height / 2;
            int sliceheight = AppController.GetHighestCommonDenominator(verticalstretch, halfheight);

            Bitmap newbitmap = new Bitmap(bmp.Width, bmp.Height + verticalstretch);

            using (Graphics g = Graphics.FromImage(newbitmap))
            {
                g.DrawImage(bmp, 0, 0, new Rectangle(0, 0, bmp.Width, halfheight), GraphicsUnit.Pixel);
                for (int i = 0; i < verticalstretch; i += sliceheight)
                {
                    g.DrawImage(bmp, 0, halfheight + i, new Rectangle(0, halfheight, bmp.Width, sliceheight), GraphicsUnit.Pixel);
                }
                g.DrawImage(bmp, 0, halfheight + verticalstretch - 1,
                            new Rectangle(0, halfheight, bmp.Width, halfheight), GraphicsUnit.Pixel);
            }

            bmp.Dispose();
            return(newbitmap);
        }
예제 #8
0
        private static float GetMultiLineFontSize(Bitmap bmp, string caption, bool localizable, float fontsize)
        {
            string[] words = caption.Split();

            // Ignore words in brackets as they won't be displayed.
            string longestWord = words[0];

            for (int i = 1; i < words.GetLength(0); i++)
            {
                string word = words[i];
                if (word.StartsWith("(", StringComparison.Ordinal) && word.EndsWith(")", StringComparison.Ordinal))
                {
                    continue;
                }

                if (word.Length > longestWord.Length)
                {
                    longestWord = word;
                }
            }

            using (Graphics g = Graphics.FromImage(bmp))
                using (Font font = AppController.GetButtonFont(fontsize, localizable))
                {
                    g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

                    SizeF stringSize;
                    stringSize = g.MeasureString(longestWord, font);

                    if (stringSize.Width > (bmp.Width * 0.8F))
                    {
                        fontsize *= ((bmp.Width * 0.8F) / stringSize.Width);
                    }
                }

            return(fontsize);
        }