Basic selective platform features.

This commit is contained in:
Lorenz Cuno Klopfenstein 2010-06-22 13:05:30 +02:00
parent 11edb1ed58
commit 964c2a000f
10 changed files with 211 additions and 77 deletions

View file

@ -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;
}
}

View file

@ -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);

View file

@ -70,7 +70,7 @@ namespace OnTopReplica {
_fullscreenForm = new FullscreenForm();
_fullscreenForm.CloseRequest += new EventHandler<CloseRequestEventArgs>(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) {

View file

@ -116,6 +116,11 @@
<Compile Include="EnumerationExtensions.cs" />
<Compile Include="FullscreenMode.cs" />
<Compile Include="HotKeyManager.cs" />
<Compile Include="PlatformSupport.cs" />
<Compile Include="Platforms\Other.cs" />
<Compile Include="Platforms\WindowsSeven.cs" />
<Compile Include="Platforms\WindowsVista.cs" />
<Compile Include="Platforms\WindowsXp.cs" />
<Compile Include="Strings.cs.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>

View file

@ -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();
}
}
/// <summary>
/// Checks whether OnTopReplica is compatible with the platform.
/// </summary>
/// <returns>Returns false if OnTopReplica cannot run.</returns>
public abstract bool CheckCompatibility();
/// <summary>
/// Gets whether OnTopReplica should be displayed in the task bar.
/// </summary>
public virtual bool ShowsInTaskBar {
get {
return false;
}
}
/// <summary>
/// Gets whether OnTopReplica should install a tray icon.
/// </summary>
public virtual bool InstallTrayIcon {
get {
return true;
}
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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; }
/// <summary>
/// The main entry point for the application.
/// </summary>
@ -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;
/// <summary>
/// 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.
/// </summary>
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;
/// <summary>
/// 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.
/// </summary>
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,