Renders a toolstrip using the UxTheme API via VisualStyleRenderer and a specific style.
Perhaps surprisingly, this does not need to be disposable.
Inheritance: ToolStripSystemRenderer
Ejemplo n.º 1
0
 static NativeStripInternals()
 {
     if (VisualStyleInformation.IsSupportedByOS && VisualStyleInformation.IsEnabledByUser)
     {
         Renderer = new ToolStripAeroRenderer(ToolbarTheme.Toolbar);
     }
 }
Ejemplo n.º 2
0
        public SysTrayApp()
        {
            toolStripRenderer = new ToolStripAeroRenderer();

            Directory.CreateDirectory(path + "\\images");

            if (!File.Exists(path + "\\bookmarks.xml"))
            {
                File.WriteAllText(path + "\\bookmarks.xml", WinRadioTray.Properties.Resources.bookmarks);
            }

            if (!File.Exists(path + "\\preferences.xml"))
            {
                File.WriteAllText(path + "\\preferences.xml", WinRadioTray.Properties.Resources.preferences);
            }

            if (!File.Exists(path + "\\WinRadioTray.log"))
            {
                File.WriteAllText(path + "\\WinRadioTray.log", WinRadioTray.Properties.Resources.logfile);
            }

            lf = new logForm();

            stations       = null;
            stations       = new ToolStripMenuItem("Stations");
            stations.Image = Properties.Resources.icons8_radio_2;
            XPathNavigator nav;
            XPathDocument  doc;

            doc = new XPathDocument(path + "\\bookmarks.xml");
            nav = doc.CreateNavigator();
            bookmarkList.Clear();
            urlList.Clear();
            groupList.Clear();
            resMan = new ResourceManager("WinRadioTray.Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly());
            XPathExpression exp = nav.Compile("bookmarks/group");

            exp.AddSort("@name", XmlSortOrder.Ascending, XmlCaseOrder.None, "", XmlDataType.Text);
            XPathNodeIterator nodeIterator = nav.Select(exp);

            while (nodeIterator.MoveNext())
            {
                ToolStripMenuItem tmp  = new ToolStripMenuItem(nodeIterator.Current.GetAttribute("name", ""));
                XPathExpression   exp2 = nav.Compile("bookmarks/group[@name='" + nodeIterator.Current.GetAttribute("name", "") + "']/bookmark");
                exp2.AddSort("@name", XmlSortOrder.Ascending, XmlCaseOrder.None, "", XmlDataType.Text);
                nav = doc.CreateNavigator();
                XPathNodeIterator nodeIterator2 = nav.Select(exp2);
                while (nodeIterator2.MoveNext())
                {
                    ToolStripMenuItem tmpStation = new ToolStripMenuItem(nodeIterator2.Current.GetAttribute("name", ""), null, new EventHandler(station_click));
                    tmpStation.Tag   = nodeIterator2.Current.GetAttribute("url", "");
                    tmpStation.Image = (nodeIterator2.Current.SelectSingleNode("@img") != null) ? thumb(nodeIterator2.Current.GetAttribute("name", ""), nodeIterator2.Current.GetAttribute("img", ""), "station") : Properties.Resources.icons8_speaker;
                    tmp.DropDownItems.Add(tmpStation);
                    tmp.DropDownDirection = ToolStripDropDownDirection.Left;
                    bookmarkList.Add(nodeIterator2.Current.GetAttribute("name", ""));
                    urlList.Add(nodeIterator2.Current.GetAttribute("url", ""));
                }
                tmp.Image = (nodeIterator.Current.SelectSingleNode("@img") != null) ? thumb(nodeIterator.Current.GetAttribute("name", ""), nodeIterator.Current.GetAttribute("img", ""), "group") : Properties.Resources.icons8_radio_station;
                stations.DropDownItems.Add(tmp);
                groupList.Add(nodeIterator.Current.GetAttribute("name", ""));
            }

            XmlDocument prefs = new XmlDocument();

            prefs.Load(path + "\\preferences.xml");
            XmlNode prefsRoot = prefs.FirstChild;

            lastStation       = prefsRoot["lastStation"].InnerText;
            preferences       = new ToolStripMenuItem("Preferences");
            preferences.Image = Properties.Resources.icons8_settings;

            audioSettings       = new ToolStripMenuItem("Audio Settings");
            audioSettings.Image = Properties.Resources.icons8_audio_wave;

            logging       = new ToolStripMenuItem("Log Actions");
            logging.Image = Properties.Resources.icons8_log;
            logging.DropDownItems.Add("Show Log", Properties.Resources.icons8_log_2, OnShowLog);
            logging.DropDownItems.Add("Clear Log", Properties.Resources.icons8_delete_document, OnClearLog);

            balanceTrackBar                        = new ToolStripLabeledTrackBar();
            balanceTrackBar.Label.Text             = prefsRoot.SelectSingleNode("balance") != null ? "Balance: " + prefsRoot["balance"].InnerText : "Balance: 0";
            balanceTrackBar.TrackBar.Minimum       = -100;
            balanceTrackBar.TrackBar.Maximum       = 100;
            balanceTrackBar.TrackBar.TickStyle     = TickStyle.BottomRight;
            balanceTrackBar.TrackBar.TickFrequency = 10;

            volumeTrackBar                        = new ToolStripLabeledTrackBar();
            volumeTrackBar.Label.Text             = prefsRoot.SelectSingleNode("volume") != null ? "Volume: " + prefsRoot["volume"].InnerText : "Volume: 50";
            volumeTrackBar.TrackBar.Minimum       = 0;
            volumeTrackBar.TrackBar.Maximum       = 100;
            volumeTrackBar.TrackBar.TickStyle     = TickStyle.BottomRight;
            volumeTrackBar.TrackBar.TickFrequency = 5;

            Color back = toolStripRenderer.ColorTable.ToolStripDropDownBackground;

            balanceTrackBar.BackColor          = back;
            balanceTrackBar.Label.BackColor    = back;
            balanceTrackBar.TrackBar.BackColor = back;
            balanceTrackBar.TrackBar.Value     = (prefsRoot["balance"].InnerText.Length > 0 || prefsRoot["balance"].InnerText == null) ? Int32.Parse(prefsRoot["balance"].InnerText) : 0;
            volumeTrackBar.BackColor           = back;
            volumeTrackBar.Label.BackColor     = back;
            volumeTrackBar.TrackBar.BackColor  = back;
            volumeTrackBar.TrackBar.Value      = (prefsRoot["volume"].InnerText.Length > 0 || prefsRoot["volume"].InnerText == null) ? Int32.Parse(prefsRoot["volume"].InnerText) : 50;

            resetBalance = new ToolStripMenuItem("Center Balance", null, recenterBalance);
            resetVolume  = new ToolStripMenuItem("Reset Volume", null, recenterVolume);

            audioSettings.DropDownItems.Add(volumeTrackBar);
            audioSettings.DropDownItems.Add(resetVolume);
            audioSettings.DropDownItems.Add("-");
            audioSettings.DropDownItems.Add(balanceTrackBar);
            audioSettings.DropDownItems.Add(resetBalance);

            trayMenu = new ContextMenuStrip();

            autoPlay = new ToolStripMenuItem("Auto play last station on startup", null, toggleAutoPlay);
            if (prefsRoot.SelectSingleNode("autoplay") != null)
            {
                autoPlay.Checked = prefsRoot["autoplay"].InnerText == "true" ? true : false;
            }
            else
            {
                autoPlay.Checked = false;
            }

            enableLogging = new ToolStripMenuItem("Enable activity logging", null, toggleLogging);
            if (prefsRoot.SelectSingleNode("logging") != null)
            {
                enableLogging.Checked = prefsRoot["logging"].InnerText == "true" ? true : false;
            }
            else
            {
                enableLogging.Checked = false;
            }

            enableMMKeys = new ToolStripMenuItem("Use multimedia keys", null, toggleMMKeys);
            if (prefsRoot.SelectSingleNode("mmkeys") != null)
            {
                enableMMKeys.Checked = prefsRoot["mmkeys"].InnerText == "true" ? true : false;
            }
            else
            {
                enableMMKeys.Checked = false;
            }

            stationSwitcher = new ToolStripMenuItem("Back/Foward Keys Switch Stations", null, toggleStationSwitcher);
            if (prefsRoot.SelectSingleNode("stationswitcher") != null)
            {
                stationSwitcher.Checked = prefsRoot["stationswitcher"].InnerText == "true" ? true : false;
            }
            else
            {
                stationSwitcher.Checked = false;
            }

            enableSleepTimer = new ToolStripMenuItem("Enable Sleep Timer", null, toggleSleepTimer);
            if (prefsRoot.SelectSingleNode("sleeptimer") != null)
            {
                enableSleepTimer.Checked = prefsRoot["sleeptimer"].InnerText == "true" ? true : false;
            }
            else
            {
                enableSleepTimer.Checked = false;
            }

            if (prefsRoot.SelectSingleNode("sleeptimerduration") != null)
            {
                sleepTimerDuration = Int32.Parse(prefsRoot["sleeptimerduration"].InnerText);
            }
            else
            {
                sleepTimerDuration = 60;
            }

            enableAutoRun         = new ToolStripMenuItem("Start with Windows", null, toggleAutoRun);
            enableAutoRun.Checked = registryValueExists("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\", "WinRadioTray");

            sleepTimerCtl                         = new ToolStripLabeledNumber();
            sleepTimerCtl.Label.Text              = "Timer Duration: ";
            sleepTimerCtl.NumericUpDown.Value     = sleepTimerDuration;
            sleepTimerCtl.BackColor               = back;
            sleepTimerCtl.Label.BackColor         = back;
            sleepTimerCtl.Label2.BackColor        = back;
            sleepTimerCtl.NumericUpDown.BackColor = back;

            preferences.DropDownItems.Add(autoPlay);
            preferences.DropDownItems.Add(enableLogging);
            preferences.DropDownItems.Add(enableMMKeys);
            preferences.DropDownItems.Add(stationSwitcher);
            preferences.DropDownItems.Add(enableAutoRun);
            preferences.DropDownItems.Add(enableSleepTimer);
            preferences.DropDownItems.Add(sleepTimerCtl);

            trayMenu.Items.Add(stations);
            trayMenu.Items.Add("-", null, null);
            trayMenu.Items.Add(preferences);
            trayMenu.Items.Add(audioSettings);
            trayMenu.Items.Add(logging);

            custom        = new ToolStripMenuItem();
            custom.Text   = "Play Custom URL";
            custom.Image  = Properties.Resources.icons8_add_link;
            custom.Click += OnCustom;
            trayMenu.Items.Add(custom);

            addCustom        = new ToolStripMenuItem();
            addCustom.Text   = "Add Custom URL to Station List";
            addCustom.Image  = Properties.Resources.icons8_plus_16;
            addCustom.Click += AddCustomToStations;
            trayMenu.Items.Add(addCustom);
            addCustom.Visible = false;

            manage        = new ToolStripMenuItem();
            manage.Text   = "Manage Stations";
            manage.Image  = Properties.Resources.icons8_maintenance;
            manage.Click += OnManage;
            trayMenu.Items.Add(manage);

            reload        = new ToolStripMenuItem();
            reload.Text   = "Reload Stations";
            reload.Image  = Properties.Resources.icons8_synchronize;
            reload.Click += OnReload;
            trayMenu.Items.Add(reload);

            trayMenu.Items.Add("-", null, null);

            play         = new ToolStripMenuItem();
            play.Text    = "Play";
            play.Image   = Properties.Resources.icons8_Play;
            play.Click  += OnPlay;
            play.Enabled = prefsRoot["lastURL"].InnerText.Length > 0 ? true : false;

            pause         = new ToolStripMenuItem();
            pause.Text    = "Pause";
            pause.Image   = Properties.Resources.icons8_Pause;
            pause.Click  += OnPause;
            pause.Visible = false;

            stop         = new ToolStripMenuItem();
            stop.Text    = "Stop";
            stop.Image   = Properties.Resources.icons8_Stop;
            stop.Click  += OnStop;
            stop.Enabled = false;

            previous         = new ToolStripMenuItem();
            previous.Text    = "Previous Station";
            previous.Image   = Properties.Resources.icons8_Rewind;
            previous.Click  += OnPrevious;
            previous.Enabled = false;

            next         = new ToolStripMenuItem();
            next.Text    = "Next Station";
            next.Image   = Properties.Resources.icons8_Fast_Forward;
            next.Click  += OnNext;
            next.Enabled = false;

            trayMenu.Items.Add(play);
            trayMenu.Items.Add(pause);
            trayMenu.Items.Add(stop);
            trayMenu.Items.Add(previous);
            trayMenu.Items.Add(next);
            trayMenu.Items.Add("-");

            about        = new ToolStripMenuItem();
            about.Text   = "About";
            about.Image  = Properties.Resources.icons8_info_point;
            about.Click += OnAbout;
            trayMenu.Items.Add(about);

            exit        = new ToolStripMenuItem();
            exit.Text   = "Exit";
            exit.Image  = Properties.Resources.icons8_cancel;
            exit.Click += OnExit;
            trayMenu.Items.Add(exit);

            trayIcon = new NotifyIcon();
            Fixes.Fixes.SetNotifyIconText(trayIcon, GetTooltipText("WinRadioTray"));
            trayIcon.Icon             = Properties.Resources.icons8_radio_tower_idle;
            trayIcon.ContextMenuStrip = trayMenu;
            trayIcon.Visible          = true;
            trayIcon.MouseUp         += trayIcon_MouseUp;

            volumeTrackBar.TrackBar.ValueChanged     += OnVolumeChange;
            balanceTrackBar.TrackBar.ValueChanged    += OnBalanceChange;
            sleepTimerCtl.NumericUpDown.ValueChanged += ChangeSleepTimerDuration;
            volumeTrackBar.TrackBar.ValueChanged     += OnVolumeChange;
            Bass.BASS_SetVolume((float)volumeTrackBar.TrackBar.Value / 100);
            Bass.BASS_ChannelSetAttribute(stream, BASSAttribute.BASS_ATTRIB_PAN, (float)balanceTrackBar.TrackBar.Value / 100);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// GaGa implementation.
        /// </summary>
        /// <param name="settingsFilepath">
        /// Path to the settings file to use.
        /// </param>
        /// <param name="streamsFilepath">
        /// Path to the streams file to use.
        /// </param>
        public GaGa(String settingsFilepath, String streamsFilepath)
        {
            // gui components:
            container         = new Container();
            toolStripRenderer = new ToolStripAeroRenderer();

            notifyIcon = new NotifyIcon(container);
            notifyIcon.ContextMenuStrip          = new ContextMenuStrip();
            notifyIcon.ContextMenuStrip.Renderer = toolStripRenderer;
            notifyIcon.Visible = true;

            // settings:
            this.settingsFilepath = settingsFilepath;
            settings = SettingsLoad();

            // streams:
            this.streamsFilepath = streamsFilepath;
            streamsFileLoader    = new StreamsFileLoader(streamsFilepath);

            // player:
            player = new Player(notifyIcon);

            // constant menu items:
            dynamicMenuMarker         = new ToolStripMenuItem();
            dynamicMenuMarker.Visible = false;

            errorOpenItem      = new ToolStripMenuItem();
            errorOpenItem.Text = "Error opening streams file (click for details)";

            errorReadItem      = new ToolStripMenuItem();
            errorReadItem.Text = "Error reading streams file (click for details)";

            editItem      = new ToolStripMenuItem();
            editItem.Text = "&Edit streams file";

            exitItem      = new ToolStripMenuItem();
            exitItem.Text = "E&xit";

            // audio submenu:
            audioMenuItem      = new ToolStripMenuItem();
            audioMenuItem.Text = "Audio";

            balanceTrackBar                  = new ToolStripLabeledTrackBar();
            balanceTrackBar.Label.Text       = "Balance";
            balanceTrackBar.TrackBar.Minimum = -10;
            balanceTrackBar.TrackBar.Maximum = 10;

            volumeTrackBar                  = new ToolStripLabeledTrackBar();
            volumeTrackBar.Label.Text       = "Volume";
            volumeTrackBar.TrackBar.Minimum = 0;
            volumeTrackBar.TrackBar.Maximum = 20;

            // adjust the backcolor to the renderer:
            Color back = toolStripRenderer.ColorTable.ToolStripDropDownBackground;

            balanceTrackBar.BackColor          = back;
            balanceTrackBar.Label.BackColor    = back;
            balanceTrackBar.TrackBar.BackColor = back;
            volumeTrackBar.BackColor           = back;
            volumeTrackBar.Label.BackColor     = back;
            volumeTrackBar.TrackBar.BackColor  = back;

            audioMenuItem.DropDownItems.Add(balanceTrackBar);
            audioMenuItem.DropDownItems.Add(volumeTrackBar);

            // options submenu:
            optionsMenuItem      = new ToolStripMenuItem();
            optionsMenuItem.Text = "Options";

            optionsEnableAutoPlayItem      = new ToolStripMenuItem();
            optionsEnableAutoPlayItem.Text = "Enable auto play on startup";

            optionsEnableMultimediaKeysItem      = new ToolStripMenuItem();
            optionsEnableMultimediaKeysItem.Text = "Enable multimedia keys";

            optionsMenuItem.DropDownItems.Add(optionsEnableAutoPlayItem);
            optionsMenuItem.DropDownItems.Add(optionsEnableMultimediaKeysItem);

            // add multimedia keys:
            KeyboardHook.Hooker.Add("Toggle Play", Keys.MediaPlayPause);
            KeyboardHook.Hooker.Add("Stop", Keys.MediaStop);
            KeyboardHook.Hooker.Add("Toggle Mute", Keys.VolumeMute);
            KeyboardHook.Hooker.Add("Volume Up", Keys.VolumeUp);
            KeyboardHook.Hooker.Add("Volume Down", Keys.VolumeDown);

            // apply settings before wiring events:
            balanceTrackBar.TrackBar.Value = settings.LastBalanceTrackBarValue;
            volumeTrackBar.TrackBar.Value  = settings.LastVolumeTrackBarValue;

            BalanceUpdate();
            VolumeUpdate();

            player.Select(settings.LastPlayerStream);

            optionsEnableAutoPlayItem.Checked       = settings.OptionsEnableAutoPlayChecked;
            optionsEnableMultimediaKeysItem.Checked = settings.OptionsEnableMultimediaKeysChecked;

            // wire events:
            notifyIcon.ContextMenuStrip.Opening += OnMenuOpening;
            notifyIcon.MouseClick += OnIconMouseClick;

            errorOpenItem.Click += OnErrorOpenItemClick;
            errorReadItem.Click += OnErrorReadItemClick;
            editItem.Click      += OnEditItemClick;
            exitItem.Click      += OnExitItemClick;

            balanceTrackBar.TrackBar.ValueChanged += OnBalanceTrackBarChanged;
            volumeTrackBar.TrackBar.ValueChanged  += OnVolumeTrackBarChanged;

            optionsEnableAutoPlayItem.CheckOnClick = true;
            optionsEnableMultimediaKeysItem.Click += OnEnableMultimediaKeysItemClicked;

            KeyboardHook.Hooker.HotkeyDown += OnHotkeyDown;

            // handle options:
            if (optionsEnableAutoPlayItem.Checked)
            {
                player.Play();
            }

            if (optionsEnableMultimediaKeysItem.Checked)
            {
                MultimediaKeysHook();
            }
        }