diff --git a/OnTopReplica/CommonControls.cs b/OnTopReplica/CommonControls.cs new file mode 100644 index 0000000..fa2af71 --- /dev/null +++ b/OnTopReplica/CommonControls.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; + +namespace OnTopReplica { + public static class CommonControls { + + [DllImport("comctl32.dll", EntryPoint = "InitCommonControlsEx", CallingConvention = CallingConvention.StdCall)] + static extern bool InitCommonControlsEx(ref INITCOMMONCONTROLSEX iccex); + + const int ICC_STANDARD_CLASSES = 0x00004000; + const int ICC_WIN95_CLASSES = 0x000000FF; + + public static bool InitStandard() { + INITCOMMONCONTROLSEX ex = new INITCOMMONCONTROLSEX(); + ex.dwSize = 8; + ex.dwICC = ICC_STANDARD_CLASSES | ICC_WIN95_CLASSES; + + return InitCommonControlsEx(ref ex); + } + + } + + struct INITCOMMONCONTROLSEX { + public int dwSize; + public int dwICC; + } + +} diff --git a/OnTopReplica/MainForm.Designer.cs b/OnTopReplica/MainForm.Designer.cs index 0887e22..3ee672d 100644 --- a/OnTopReplica/MainForm.Designer.cs +++ b/OnTopReplica/MainForm.Designer.cs @@ -388,14 +388,15 @@ this.danskToolStripMenuItem1, this.italianoToolStripMenuItem}); this.menuLanguages.Name = "menuLanguages"; - this.menuLanguages.Size = new System.Drawing.Size(153, 114); + this.menuLanguages.OwnerItem = this.languageToolStripMenuItem; + this.menuLanguages.Size = new System.Drawing.Size(114, 92); this.menuLanguages.Text = "Dansk"; // // englishToolStripMenuItem // this.englishToolStripMenuItem.Image = global::OnTopReplica.Properties.Resources.flag_usa; this.englishToolStripMenuItem.Name = "englishToolStripMenuItem"; - this.englishToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.englishToolStripMenuItem.Size = new System.Drawing.Size(113, 22); this.englishToolStripMenuItem.Tag = "en-US"; this.englishToolStripMenuItem.Text = "English"; this.englishToolStripMenuItem.Click += new System.EventHandler(this.Menu_Language_click); @@ -404,7 +405,7 @@ // this.cestinaToolStripMenuItem.Image = global::OnTopReplica.Properties.Resources.flag_czech; this.cestinaToolStripMenuItem.Name = "cestinaToolStripMenuItem"; - this.cestinaToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.cestinaToolStripMenuItem.Size = new System.Drawing.Size(113, 22); this.cestinaToolStripMenuItem.Tag = "cs-CZ"; this.cestinaToolStripMenuItem.Text = "Čeština"; this.cestinaToolStripMenuItem.Click += new System.EventHandler(this.Menu_Language_click); @@ -413,7 +414,7 @@ // this.danskToolStripMenuItem1.Image = global::OnTopReplica.Properties.Resources.flag_danish; this.danskToolStripMenuItem1.Name = "danskToolStripMenuItem1"; - this.danskToolStripMenuItem1.Size = new System.Drawing.Size(152, 22); + this.danskToolStripMenuItem1.Size = new System.Drawing.Size(113, 22); this.danskToolStripMenuItem1.Tag = "da-DK"; this.danskToolStripMenuItem1.Text = "Dansk"; this.danskToolStripMenuItem1.Click += new System.EventHandler(this.Menu_Language_click); @@ -422,7 +423,7 @@ // this.italianoToolStripMenuItem.Image = global::OnTopReplica.Properties.Resources.flag_ita; this.italianoToolStripMenuItem.Name = "italianoToolStripMenuItem"; - this.italianoToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.italianoToolStripMenuItem.Size = new System.Drawing.Size(113, 22); this.italianoToolStripMenuItem.Tag = "it-IT"; this.italianoToolStripMenuItem.Text = "Italiano"; this.italianoToolStripMenuItem.Click += new System.EventHandler(this.Menu_Language_click); @@ -500,7 +501,6 @@ this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MinimumSize = new System.Drawing.Size(200, 210); this.Name = "MainForm"; - this.ShowInTaskbar = false; this.TopMost = true; this.DoubleClick += new System.EventHandler(this.Form_doubleclick); this.menuContext.ResumeLayout(false); diff --git a/OnTopReplica/MainForm.cs b/OnTopReplica/MainForm.cs index c7ef7f8..fa943a6 100644 --- a/OnTopReplica/MainForm.cs +++ b/OnTopReplica/MainForm.cs @@ -70,7 +70,7 @@ namespace OnTopReplica { _fullscreenForm = new FullscreenForm(); _fullscreenForm.CloseRequest += new EventHandler(FullscreenForm_CloseRequest); - //Set native renderer on context menues + //Set native renderer on context menus Asztal.Szótár.NativeToolStripRenderer.SetToolStripRenderer(new Control[] { menuContext, menuWindows, menuOpacity, menuIconContext, menuResize, menuLanguages }); @@ -209,7 +209,7 @@ namespace OnTopReplica { manager.Dispose(); } - //Store settings + //Store position settings if (Settings.Default.StoreWindowPosition) { Settings.Default.WindowPositionStored = true; Settings.Default.LastLocation = Location; @@ -235,14 +235,17 @@ namespace OnTopReplica { //Get a window manager _windowManager = new WindowManager(); - //Install NotifyIcon - taskIcon = new NotifyIcon { - Text = Strings.ApplicationName, - Icon = Properties.Resources.main_icon, - Visible = true, - ContextMenuStrip = menuIconContext - }; - taskIcon.DoubleClick += new EventHandler(TaskIcon_doubleclick); + //Platform specific tray/taskbar + this.ShowInTaskbar = Program.Platform.ShowsInTaskBar; + if (Program.Platform.InstallTrayIcon) { + taskIcon = new NotifyIcon { + Text = Strings.ApplicationName, + Icon = Properties.Resources.main_icon, + Visible = true, + ContextMenuStrip = menuIconContext + }; + taskIcon.DoubleClick += new EventHandler(TaskIcon_doubleclick); + } //Reload position settings if needed if (_startOverride) { diff --git a/OnTopReplica/OnTopReplica.csproj b/OnTopReplica/OnTopReplica.csproj index 2f091a5..de5953d 100644 --- a/OnTopReplica/OnTopReplica.csproj +++ b/OnTopReplica/OnTopReplica.csproj @@ -116,6 +116,11 @@ + + + + + True True diff --git a/OnTopReplica/PlatformSupport.cs b/OnTopReplica/PlatformSupport.cs new file mode 100644 index 0000000..c6539bc --- /dev/null +++ b/OnTopReplica/PlatformSupport.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Text; +using OnTopReplica.Platforms; + +namespace OnTopReplica { + abstract class PlatformSupport { + + public static PlatformSupport Create() { + var os = Environment.OSVersion; + + if (os.Platform != PlatformID.Win32NT) + return new Other(); + + if (os.Version.Major == 6) { + if (os.Version.Minor >= 1) + return new WindowsSeven(); + else + return new WindowsVista(); + } + else { + //Generic NT + return new WindowsXp(); + } + } + + /// + /// Checks whether OnTopReplica is compatible with the platform. + /// + /// Returns false if OnTopReplica cannot run. + public abstract bool CheckCompatibility(); + + /// + /// Gets whether OnTopReplica should be displayed in the task bar. + /// + public virtual bool ShowsInTaskBar { + get { + return false; + } + } + + /// + /// Gets whether OnTopReplica should install a tray icon. + /// + public virtual bool InstallTrayIcon { + get { + return true; + } + } + + } +} diff --git a/OnTopReplica/Platforms/Other.cs b/OnTopReplica/Platforms/Other.cs new file mode 100644 index 0000000..e874026 --- /dev/null +++ b/OnTopReplica/Platforms/Other.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OnTopReplica.Platforms { + class Other : PlatformSupport { + + public override bool CheckCompatibility() { + //TODO: Err MSG + return false; + } + + } +} diff --git a/OnTopReplica/Platforms/WindowsSeven.cs b/OnTopReplica/Platforms/WindowsSeven.cs new file mode 100644 index 0000000..8fc63a5 --- /dev/null +++ b/OnTopReplica/Platforms/WindowsSeven.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OnTopReplica.Platforms { + class WindowsSeven : WindowsVista { + + public override bool InstallTrayIcon { + get { + return false; + } + } + + public override bool ShowsInTaskBar { + get { + return true; + } + } + + } +} diff --git a/OnTopReplica/Platforms/WindowsVista.cs b/OnTopReplica/Platforms/WindowsVista.cs new file mode 100644 index 0000000..1d79669 --- /dev/null +++ b/OnTopReplica/Platforms/WindowsVista.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows.Forms; + +namespace OnTopReplica.Platforms { + class WindowsVista : PlatformSupport { + + public override bool CheckCompatibility() { + if (!VistaControls.OsSupport.IsCompositionEnabled) { + MessageBox.Show(Strings.ErrorDwmOffContent, Strings.ErrorDwmOff, MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + return true; + } + + } +} diff --git a/OnTopReplica/Platforms/WindowsXp.cs b/OnTopReplica/Platforms/WindowsXp.cs new file mode 100644 index 0000000..88d3895 --- /dev/null +++ b/OnTopReplica/Platforms/WindowsXp.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows.Forms; + +namespace OnTopReplica.Platforms { + class WindowsXp : PlatformSupport { + + public override bool CheckCompatibility() { + MessageBox.Show(Strings.ErrorNoDwm, Strings.ErrorNoDwmTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + + } +} diff --git a/OnTopReplica/Program.cs b/OnTopReplica/Program.cs index 872215c..9c8ea4f 100644 --- a/OnTopReplica/Program.cs +++ b/OnTopReplica/Program.cs @@ -8,9 +8,12 @@ using System.Drawing; using System.IO; using VistaControls.TaskDialog; -namespace OnTopReplica -{ +namespace OnTopReplica { + static class Program { + + public static PlatformSupport Platform { get; private set; } + /// /// The main entry point for the application. /// @@ -22,25 +25,26 @@ namespace OnTopReplica Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - //Check for DWM - if (!CanStart) + //Initialize and check for platform support + Platform = PlatformSupport.Create(); + if (!Platform.CheckCompatibility()) return; - //Update settings if needed - if (Settings.Default.MustUpdate) { - Settings.Default.Upgrade(); - Settings.Default.MustUpdate = false; - } + //Update settings if needed + if (Settings.Default.MustUpdate) { + Settings.Default.Upgrade(); + Settings.Default.MustUpdate = false; + } bool reloadSettings = false; Point reloadLocation = new Point(); Size reloadSize = new Size(); - do { - //Update language settings - Thread.CurrentThread.CurrentUICulture = _languageChangeCode; - Settings.Default.Language = _languageChangeCode; - _languageChangeCode = null; + do { + //Update language settings + Thread.CurrentThread.CurrentUICulture = _languageChangeCode; + Settings.Default.Language = _languageChangeCode; + _languageChangeCode = null; Form form; if (reloadSettings) @@ -48,66 +52,38 @@ namespace OnTopReplica else form = new MainForm(); - Application.Run(form); + Application.Run(form); reloadSettings = true; reloadLocation = form.Location; reloadSize = form.Size; - } - while(_languageChangeCode != null); + } + while (_languageChangeCode != null); - //Persist settings - Settings.Default.Save(); + //Persist settings + Settings.Default.Save(); } + static CultureInfo _languageChangeCode = Settings.Default.Language; + /// - /// Checks whether OnTopReplica can start or not. + /// Forces a global language change. As soon as the main form is closed, the change is performed + /// and the form is reopened using the new language. /// - private static bool CanStart { - get { - //Do some checks in order to verify the presence of desktop composition - if (!VistaControls.OsSupport.IsVistaOrBetter) { - MessageBox.Show(Strings.ErrorNoDwm, Strings.ErrorNoDwmTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); - return false; - } + public static bool ForceGlobalLanguageChange(string languageCode) { + if (string.IsNullOrEmpty(languageCode)) + return false; - if (!VistaControls.OsSupport.IsCompositionEnabled) { - MessageBox.Show(Strings.ErrorDwmOffContent, Strings.ErrorDwmOff, MessageBoxButtons.OK, MessageBoxIcon.Error); - /*var dlg = new TaskDialog(Strings.ErrorDwmOff, Strings.ErrorGenericTitle, Strings.ErrorDwmOffContent) { - ExpandedControlText = Strings.ErrorDetailsAero, - ExpandedInformation = Strings.ErrorDetailsAeroInfo, - CommonButtons = TaskDialogButton.Close, - CommonIcon = VistaControls.TaskDialog.TaskDialogIcon.Stop - }; - dlg.Show();*/ - - return false; - } - - return true; + try { + _languageChangeCode = new CultureInfo(languageCode); } + catch { + return false; + } + + return true; } - static CultureInfo _languageChangeCode = Settings.Default.Language; - - /// - /// Forces a global language change. As soon as the main form is closed, the change is performed - /// and the form is reopened using the new language. - /// - public static bool ForceGlobalLanguageChange(string languageCode){ - if (string.IsNullOrEmpty(languageCode)) - return false; - - try { - _languageChangeCode = new CultureInfo(languageCode); - } - catch { - return false; - } - - return true; - } - static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { string dump = string.Format("OnTopReplica-dump-{0}{1}{2}{3}{4}.txt", DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day,