Exemplo n.º 1
0
        private static RawIcon?DoGetStockIcon(StockIcon id)
        {
            if (id < 0 || !OSUtils.IsVistaOrLater)
            {
                return(null);
            }

            IntPtr largeHandle = Shell32.GetStockIconHandle(id, SystemIconSize.Large);

            if (largeHandle == IntPtr.Zero)
            {
                return(null);
            }

            var result = new RawIcon(Icon.FromHandle(largeHandle));

            User32.DestroyIcon(largeHandle);

            IntPtr smallHandle = Shell32.GetStockIconHandle(id, SystemIconSize.Small);

            if (largeHandle == IntPtr.Zero)
            {
                return(result);
            }

            result.Add(Icon.FromHandle(smallHandle));
            User32.DestroyIcon(smallHandle);
            return(result);
        }
        public AdvancedSearch()
        {
            stockIcons = new StockIcons();

            documentsStockIcon = stockIcons.DocumentAssociated;
            videosStockIcon    = stockIcons.VideoFiles;
            musicStockIcon     = stockIcons.AudioFiles;
            picturesStockIcon  = stockIcons.ImageFiles;

            InitializeComponent();

            // Set our default
            DocumentsRadioButton.IsChecked = true;

            //
            prop1prop2OperationComboBox.SelectedIndex = 0;

            // Because the search can take some time, using a background thread.
            // This timer will check if that thread is still alive and accordingly update
            // the cursor
            DispatcherTimer timer = new DispatcherTimer();

            timer.Interval  = new TimeSpan(0, 0, 1);
            timer.IsEnabled = true;
            timer.Tick     += new EventHandler(timer_Tick);
        }
        public void StockIconsContainedInAllCollection()
        {
            // TODO: Redesign test, this is a pretty redundant test with the way the class is designed.

            var icons = new StockIcons();

            PropertyInfo[] infos = typeof(StockIcons).GetType().GetProperties(BindingFlags.Public);

            foreach (var info in infos)
            {
                if (info.PropertyType != typeof(StockIcon))
                {
                    continue;
                }

                StockIcon icon = null;

                try
                {
                    //this will throw an exception if the icon does not exist on the system
                    icon = (StockIcon)info.GetValue(icons, null);
                }

                catch { continue; }

                Assert.Contains(icon, icons.AllStockIcons);
            }
        }
Exemplo n.º 4
0
        public void StockIconsTest(StockIcon stockIcon)
        {
            var icon = Icons.GetStockIcon(stockIcon);

            Assert.IsTrue(!OSUtils.IsWindows || icon != null);
            SaveIcon(stockIcon.ToString(), icon);
        }
Exemplo n.º 5
0
        internal static IntPtr GetStockIconHandle(StockIcon id, SystemIconSize size)
        {
            var iconInfo = new SHSTOCKICONINFO {
                cbSize = (uint)Marshal.SizeOf(typeof(SHSTOCKICONINFO))
            };

            return(NativeMethods.SHGetStockIconInfo(id, SHGSI.ICON | (SHGSI)size, ref iconInfo) == 0 ? iconInfo.hIcon : IntPtr.Zero);
        }
Exemplo n.º 6
0
        private static RawIcon?GetStockIconOrDefault(StockIcon id, Func <Icon>?getLegacyIcon)
        {
            RawIcon?result = DoGetStockIcon(id);

            if (result == null && getLegacyIcon != null)
            {
                result = ToCombinedIcon(getLegacyIcon.Invoke());
            }
            return(result);
        }
Exemplo n.º 7
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            image40.Source = StockIcons.MobilePC;
            image41.Source = StockIcons.Printer;
            StockIcon b42 = new StockIcon(StockIconIdentifier.AutoList);

            image42.Source = b42.Bitmap;
            StockIcon b43 = new StockIcon(StockIconIdentifier.ServerShare, StockIconOptions.Selected);

            image43.Source = b43.Bitmap;
        }
Exemplo n.º 8
0
        //// =====================================================================================

        /// <summary>
        /// Obtient l'icône correspondant au nom spécifié.
        /// </summary>
        /// <param name="name">Nom de l'icône.</param>
        /// <returns>Icône correspondant au nom spécifié.</returns>
        private static StockIcon GetStockIcon(string name)
        {
            if (!icons.ContainsKey(name))
            {
                icons[name] = new StockIcon((Icon)resources.GetObject(name))
                {
                    Name = name
                }
            }
            ;
            return(icons[name]);
        }
    }
Exemplo n.º 9
0
        public void CalculateIcons()
        {
            int x = DrawSurface.GlobalBounds.X;
            int y = DrawSurface.GlobalBounds.Y;
            int w = DrawSurface.GlobalBounds.Width;
            int h = DrawSurface.GlobalBounds.Height;

            MaxStock = 0;
            MinStock = 9999;

            foreach (float stock in FilteredCompanies.SelectMany(company => company.StockHistory))
            {
                MaxStock = Math.Max(stock, MaxStock);
                MinStock = Math.Min(stock, MinStock);
            }

            foreach (Company company in FilteredCompanies)
            {
                Icons.Add(new StockIcon()
                {
                    Company  = company,
                    DestRect = new Rectangle(x + w / 2, y + h / 2, 32, 32)
                });
            }

            for (int i = 1; i < Window; i++)
            {
                int tick     = (w / (Window + 1)) * (i + 1);
                int prevtick = (w / (Window + 1)) * (i);
                int j        = 0;
                foreach (Company company in FilteredCompanies)
                {
                    if (company.StockHistory.Count < i + 1)
                    {
                        continue;
                    }
                    float price0           = company.StockHistory[i];
                    float normalizedPrice0 = (price0 - MinStock) / (MaxStock - MinStock);

                    if (j % company.StockHistory.Count == (i - 1))
                    {
                        StockIcon icon = Icons[j];
                        icon.DestRect = new Rectangle((int)(x + tick), (int)(y + h - normalizedPrice0 * h) - 16, 32, 32);
                        Icons[j]      = icon;
                    }
                    j++;
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Retrieve a built-in icon
        /// </summary>
        /// <param name="StockIcon">Icon to be extracted</param>
        /// <param name="Large">32z32 or 16x16</param>
        /// <returns>The icon according to the arguments</returns>
        public static Icon GetStockIcon(StockIcon StockIcon, bool Large)
        {
            NativeMethods.SHSTOCKICONINFO info = new NativeMethods.SHSTOCKICONINFO();
            info.cbSize = Marshal.SizeOf(info);
            NativeMethods.SHGSI Flags = NativeMethods.SHGSI.SHGSI_ICON;
            if (!Large)
            {
                Flags |= NativeMethods.SHGSI.SHGSI_SMALLICON;
            }
            int Result = NativeMethods.SHGetStockIconInfo(StockIcon, Flags, ref info);

            if (NativeMethods.Failed(Result))
            {
                Marshal.ThrowExceptionForHR(Result);
            }
            return(Icon.FromHandle(info.hIcon));
        }
Exemplo n.º 11
0
        public void StockIconsNotNull()
        {
            PropertyInfo[] infos = typeof(StockIcons).GetType().GetProperties(BindingFlags.Public);

            // BUG: This (StockIcons) doesn't follow the same pattern as most of the other factory style patterned classes?
            StockIcons icons = new StockIcons();

            foreach (PropertyInfo info in infos)
            {
                if (info.PropertyType == typeof(StockIcon))
                {
                    Assert.DoesNotThrow(new Assert.ThrowsDelegate(() =>
                    {
                        StockIcon test = (StockIcon)info.GetValue(icons, null);
                    }));
                }
            }
        }
Exemplo n.º 12
0
        private static Icon GetSystemIcon(StockIcon id, Func <Icon> getLegacyIcon)
        {
            RawIcon result;

            lock (systemIconsCache)
            {
                if (!systemIconsCache.TryGetValue(id, out result))
                {
                    result = DoGetStockIcon(id);
                    if (result == null && getLegacyIcon != null)
                    {
                        result = ToCombinedIcon(getLegacyIcon.Invoke());
                    }
                    systemIconsCache[id] = result;
                }
            }

            return(result?.ToIcon(false));
        }
        public ErrorBox(Exception error, string errorDetails)
        {
            Error = error ?? throw new ArgumentNullException(nameof(error));

            InitializeComponent();

            Title = Assembly.GetEntryAssembly().GetName().Name + " Error";
            ErrorDetails.Visibility = Visibility.Collapsed;
            ErrorDetails.Text       = error.GetAllMessages();

            if (!string.IsNullOrWhiteSpace(errorDetails))
            {
                ErrorDetails.Text += Environment.NewLine + Environment.NewLine + "-- Details -- " + Environment.NewLine + Environment.NewLine + errorDetails;
            }

            ErrorDetails.Text += Environment.NewLine + Environment.NewLine + "-- Diagnostics -- " + Environment.NewLine + Environment.NewLine + GetDebugInformation();
            Image.Source       = StockIcon.GetStockBitmap(StockIconId.ERROR, StockIcon.SHGSI.SHGSI_LARGEICON);
            ErrorText.Text     = error.GetInterestingExceptionMessage();
        }
Exemplo n.º 14
0
        public static Icon GetStockIcon(StockIcon stockIcon, IconSize size = IconSize.Large, StockIconOptions options = 0)
        {
            var flags = ToStockIconFlags(size, options);
            var sii   = new UnsafeNativeMethods.SHSTOCKICONINFO();

            sii.cbSize = UnsafeNativeMethods.SHSTOCKICONINFO.Sizeof();

            int hr = UnsafeNativeMethods.SHGetStockIconInfo((int)stockIcon, flags, ref sii);

            if (hr != 0)
            {
                throw new COMException("SHGetStockIconInfo failed.", hr);
            }
            if (sii.hIcon == IntPtr.Zero)
            {
                throw new NotSupportedException("The stock icon is not supported by the running OS.");
            }

            return(HIconToIcon(sii.hIcon));
        }
Exemplo n.º 15
0
 internal static extern int SHGetStockIconInfo(StockIcon siid, SHGSI uFlags, ref SHSTOCKICONINFO psii);
Exemplo n.º 16
0
        // ###############################################################################
        // ### C O N S T R U C T I O N   A N D   I N I T I A L I Z A T I O N
        // ###############################################################################

        #region Construction

        /// <summary> Initializing constructor. </summary>
        /// <param name="display">The display pointer, that specifies the connection to the X server. <see cref="System.IntPtr"/> </param>
        /// <param name="screenNumber"> The appropriate screen number on the host server. <see cref="System.Int32"/> </param>
        /// <param name="icon"> The left bitmap to display. <see cref="XrwBitmap.Icon"/> </param>
        public X11Graphic(IntPtr display, TInt screenNumber, StockIcon icon)
        {
            // Check arguments.
            if (display == IntPtr.Zero)
            {
                throw new ArgumentNullException("display");
            }
            if (icon == X11Graphic.StockIcon.None)
            {
                throw new ArgumentNullException("icon");
            }

            _display      = display;
            _screenNumber = screenNumber;

            // Load bitmap.
            Bitmap bmp = null;

            try
            {
                System.IO.Stream bmpStream = null;

                if (icon == X11Graphic.StockIcon.Attention16TrueColor)
                {
                    bmpStream = new System.IO.MemoryStream(X11Resources.IMAGE_ATTENTION_16_TRUECOLOR, false);
                }
                else if (icon == X11Graphic.StockIcon.Attention32TrueColor)
                {
                    bmpStream = new System.IO.MemoryStream(X11Resources.IMAGE_ATTENTION_32_TRUECOLOR, false);
                }
                else if (icon == X11Graphic.StockIcon.Attention48TrueColor)
                {
                    bmpStream = new System.IO.MemoryStream(X11Resources.IMAGE_ATTENTION_48_TRUECOLOR, false);
                }

                else if (icon == X11Graphic.StockIcon.Cancel16TrueColor)
                {
                    bmpStream = new System.IO.MemoryStream(X11Resources.IMAGE_CANCEL_16_TRUECOLOR, false);
                }
                else if (icon == X11Graphic.StockIcon.Cancel32TrueColor)
                {
                    bmpStream = new System.IO.MemoryStream(X11Resources.IMAGE_CANCEL_32_TRUECOLOR, false);
                }
                else if (icon == X11Graphic.StockIcon.Cancel48TrueColor)
                {
                    bmpStream = new System.IO.MemoryStream(X11Resources.IMAGE_CANCEL_48_TRUECOLOR, false);
                }

                else if (icon == X11Graphic.StockIcon.Error16TrueColor)
                {
                    bmpStream = new System.IO.MemoryStream(X11Resources.IMAGE_ERROR_16_TRUECOLOR, false);
                }
                else if (icon == X11Graphic.StockIcon.Error32TrueColor)
                {
                    bmpStream = new System.IO.MemoryStream(X11Resources.IMAGE_ERROR_32_TRUECOLOR, false);
                }
                else if (icon == X11Graphic.StockIcon.Error48TrueColor)
                {
                    bmpStream = new System.IO.MemoryStream(X11Resources.IMAGE_ERROR_48_TRUECOLOR, false);
                }

                else if (icon == X11Graphic.StockIcon.Information16TrueColor)
                {
                    bmpStream = new System.IO.MemoryStream(X11Resources.IMAGE_INFO_16_TRUECOLOR, false);
                }
                else if (icon == X11Graphic.StockIcon.Information32TrueColor)
                {
                    bmpStream = new System.IO.MemoryStream(X11Resources.IMAGE_INFO_32_TRUECOLOR, false);
                }
                else if (icon == X11Graphic.StockIcon.Information48TrueColor)
                {
                    bmpStream = new System.IO.MemoryStream(X11Resources.IMAGE_INFO_48_TRUECOLOR, false);
                }

                else if (icon == X11Graphic.StockIcon.Ok16TrueColor)
                {
                    bmpStream = new System.IO.MemoryStream(X11Resources.IMAGE_OK_16_TRUECOLOR, false);
                }

                else if (icon == X11Graphic.StockIcon.Question16TrueColor)
                {
                    bmpStream = new System.IO.MemoryStream(X11Resources.IMAGE_QUESTION_16_TRUECOLOR, false);
                }
                else if (icon == X11Graphic.StockIcon.Question32TrueColor)
                {
                    bmpStream = new System.IO.MemoryStream(X11Resources.IMAGE_QUESTION_32_TRUECOLOR, false);
                }

                else if (icon == X11Graphic.StockIcon.Warning16TrueColor)
                {
                    bmpStream = new System.IO.MemoryStream(X11Resources.IMAGE_WARNING_16_TRUECOLOR, false);
                }
                else if (icon == X11Graphic.StockIcon.Warning32TrueColor)
                {
                    bmpStream = new System.IO.MemoryStream(X11Resources.IMAGE_WARNING_32_TRUECOLOR, false);
                }

                else if (icon == X11Graphic.StockIcon.ToggleOff16TrueColor)
                {
                    bmpStream = new System.IO.MemoryStream(X11Resources.IMAGE_TOGGLEOFF_16_TRUECOLOR, false);
                }
                else if (icon == X11Graphic.StockIcon.ToggleOn16TrueColor)
                {
                    bmpStream = new System.IO.MemoryStream(X11Resources.IMAGE_TOGGLEON_16_TRUECOLOR, false);
                }
                else if (icon == X11Graphic.StockIcon.RadioOff16TrueColor)
                {
                    bmpStream = new System.IO.MemoryStream(X11Resources.IMAGE_RADIOOFF_16_TRUECOLOR, false);
                }
                else if (icon == X11Graphic.StockIcon.RadioOn16TrueColor)
                {
                    bmpStream = new System.IO.MemoryStream(X11Resources.IMAGE_RADIOON_16_TRUECOLOR, false);
                }

                bmp = new Bitmap(bmpStream);
                bmpStream.Close();
            }
            catch (Exception e)
            {
                throw e;
            }
            if (bmp == null)
            {
                throw new OperationCanceledException("Failed to create bitmap from '" + icon.ToString() + "'.");
            }

            InitializeGraphicRessources(bmp);
        }
Exemplo n.º 17
0
        public static MessageBoxResult Show(this Window window, string text, string caption,
                                            MessageBoxButton button = MessageBoxButton.OK,
                                            MessageBoxImage image   = MessageBoxImage.None,
                                            ImageSource imageSource = null)
        {
            var dlg  = new MessageBoxWindow();
            var icon = (StockIconId)0;

            switch (image)
            {
            case MessageBoxImage.Error:
                icon = StockIconId.ERROR;
                break;

            case MessageBoxImage.Information:
                icon = StockIconId.INFO;
                break;

            case MessageBoxImage.Exclamation:
                icon = StockIconId.WARNING;
                break;

            case MessageBoxImage.Question:
                icon = StockIconId.HELP;
                break;
            }

            if (icon != 0 || imageSource != null)
            {
                var img = new Image();
                img.VerticalAlignment = VerticalAlignment.Top;
                img.Source            = imageSource ?? StockIcon.GetStockBitmap(icon, StockIcon.SHGSI.SHGSI_LARGEICON);
                img.Width             = 32;
                img.Margin            = new Thickness(0, 0, 10, 0);
                dlg.ContentPanel.Children.Add(img);
            }

            var tb = new TextBlock();

            tb.Text         = text;
            tb.MaxWidth     = System.Windows.Forms.Screen.FromHandle(new WindowInteropHelper(window).Handle).WorkingArea.Width / 3;
            tb.TextWrapping = TextWrapping.Wrap;
            dlg.ContentPanel.Children.Add(tb);
            dlg.Title = caption ?? UIUtilities.GetProduct();
            dlg.Owner = window ?? UIUtilities.GetActiveWindow();
            switch (button)
            {
            case MessageBoxButton.OK:
                dlg.Button1.Content  = "OK";
                dlg.ResultForButton1 = MessageBoxResult.OK;
                break;

            case MessageBoxButton.OKCancel:
                dlg.Button1.Content    = "OK";
                dlg.ResultForButton1   = MessageBoxResult.OK;
                dlg.Button2.Content    = "Cancel";
                dlg.Button1.IsDefault  = false;
                dlg.Button2.IsDefault  = true;
                dlg.ResultForButton1   = MessageBoxResult.Cancel;
                dlg.Button2.Visibility = Visibility.Visible;
                dlg.Sep1.Visibility    = Visibility.Visible;
                break;

            case MessageBoxButton.YesNo:
                dlg.Button1.Content    = "Yes";
                dlg.ResultForButton1   = MessageBoxResult.Yes;
                dlg.Button2.Content    = "No";
                dlg.Button1.IsDefault  = false;
                dlg.Button2.IsDefault  = true;
                dlg.ResultForButton2   = MessageBoxResult.No;
                dlg.Button2.Visibility = Visibility.Visible;
                dlg.Sep1.Visibility    = Visibility.Visible;
                break;

            case MessageBoxButton.YesNoCancel:
                dlg.Button1.Content    = "Yes";
                dlg.ResultForButton1   = MessageBoxResult.Yes;
                dlg.Button2.Content    = "No";
                dlg.ResultForButton2   = MessageBoxResult.No;
                dlg.Button3.Content    = "Cancel";
                dlg.Button1.IsDefault  = false;
                dlg.Button2.IsDefault  = false;
                dlg.Button3.IsDefault  = true;
                dlg.ResultForButton3   = MessageBoxResult.Cancel;
                dlg.Button2.Visibility = Visibility.Visible;
                dlg.Button3.Visibility = Visibility.Visible;
                dlg.Sep1.Visibility    = Visibility.Visible;
                dlg.Sep2.Visibility    = Visibility.Visible;
                break;
            }

            _ = dlg.ShowDialog();
            return(dlg.Result);
        }
Exemplo n.º 18
0
 [return : NotNullIfNotNull("getLegacyIcon")] private static Icon?GetSystemIcon(StockIcon id, Func <Icon>?getLegacyIcon)
 => SystemIconsCache.GetOrAdd(id, getSystemIconAddValueFactory, getLegacyIcon)?.ToIcon(false);
Exemplo n.º 19
0
 /// <summary>
 /// Tries to get a system stock icon. When there is no icon defined for provided <paramref name="id"/>,
 /// or Windows version is below Vista, this method returns <see langword="null"/>.
 /// In Windows XP use the predefined property members to retrieve system icons.
 /// </summary>
 /// <param name="id">Id of the icon to retrieve. For future compatibility reasons non-defined <see cref="StockIcon"/> values are also allowed.</param>
 /// <returns>An <see cref="Icon"/> instance containing a small and large icon when an icon belongs to <paramref name="id"/>, or <see langword="null"/>,
 /// when no icon found or Windows version is below Vista, or the method is called in a non-Windows environment.</returns>
 /// <remarks>
 /// <note>On non-Windows platforms this method always returns <see langword="null"/>.</note>
 /// </remarks>
 public static Icon?GetStockIcon(StockIcon id) => GetSystemIcon(id, null);
Exemplo n.º 20
0
        public WpfDialog(string title, string description, WpfDialogOptions options)
        {
            InitializeComponent();

            DialogTitle = title;
            Description = description;

            if (options != null)
            {
                if (options.CustomContent != null)
                {
                    UserContentArea.Children.Clear();
                    UserContentArea.Children.Add(options.CustomContent);
                }
                else
                {
                    UserContentArea.Visibility = Visibility.Collapsed;
                }

                if (options.PossibleResponses != null)
                {
                    buttonPanel.Children.Clear();

                    UserResponses responses = options.PossibleResponses;
                    for (int responseNum = 0; responseNum < responses.ResponseNames.Length; responseNum++)
                    {
                        Button btnResponse = new Button();
                        btnResponse.Content  = responses.ResponseNames[responseNum];
                        btnResponse.Height   = 23;
                        btnResponse.MinWidth = 70;
                        btnResponse.Click   += new RoutedEventHandler(btnResponse_Click);

                        if (responseNum == responses.DefaultResponseIndex)
                        {
                            btnResponse.IsDefault = true;
                        }

                        // Only set the margin on the
                        if (responseNum != responses.ResponseNames.Length)
                        {
                            btnResponse.Margin = new Thickness(0, 0, 5, 0);
                        }

                        buttonPanel.Children.Add(btnResponse);
                    }
                }

                if (options.TitleBarIcon != null)
                {
                    this.Icon = options.TitleBarIcon;
                }

                if (options.DialogIcon != null)
                {
                    iconImage.Source = options.DialogIcon;
                }
                else
                {
                    StockIcons icons = new StockIcons();
                    StockIcon  icon  = icons.Info;

                    if (options.DialogType == DialogType.Question)
                    {
                        icon = icons.Help;
                    }
                    else if (options.DialogType == DialogType.Error)
                    {
                        icon = icons.Error;
                    }
                    else if (options.DialogType == DialogType.Warning)
                    {
                        icon = icons.Warning;
                    }

                    // This is an example of how to load a bitmap using a pack formatted string.
                    //resourceImage = @"Helpers\UIHelpers\Images\question.png";
                    //BitmapImage bitmapImage = new BitmapImage(new Uri(String.Format("pack://application:,,,/{0}", resourceImage)));

                    iconImage.Source = icon.BitmapSource;
                }
            }

            this.DataContext = this;
        }