1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-11 02:34:08 +02:00

Rewrite CanMoveWindow and CanResizeWindow in notification classes

This commit is contained in:
chylex 2017-10-31 12:36:46 +01:00
parent d9da14b5dc
commit ca55119531
7 changed files with 35 additions and 36 deletions

View File

@ -62,14 +62,7 @@ public FormBrowser(UpdaterSettings updaterSettings){
this.plugins.Executed += plugins_Executed;
this.plugins.Reload();
this.notification = new FormNotificationTweet(this, plugins){
#if DEBUG
CanMoveWindow = () => (ModifierKeys & Keys.Alt) == Keys.Alt
#else
CanMoveWindow = () => false
#endif
};
this.notification = new FormNotificationTweet(this, plugins);
this.notification.Show();
this.browser = new TweetDeckBrowser(this, plugins, new TweetDeckBridge(this, notification));

View File

@ -1,8 +1,15 @@
using TweetDuck.Plugins;
using System.Windows.Forms;
using TweetDuck.Core.Utils;
using TweetDuck.Plugins;
using TweetDuck.Resources;
namespace TweetDuck.Core.Notification.Example{
sealed class FormNotificationExample : FormNotificationMain{
public override bool RequiresResize => true;
protected override bool CanDragWindow => Program.UserConfig.NotificationPosition == TweetNotification.Position.Custom;
private bool CanResizeWindow => Program.UserConfig.NotificationSize == TweetNotification.Size.Custom;
private readonly TweetNotification exampleNotification;
public FormNotificationExample(FormBrowser owner, PluginManager pluginManager) : base(owner, pluginManager, false){
@ -14,7 +21,7 @@ public FormNotificationExample(FormBrowser owner, PluginManager pluginManager) :
exampleNotification = TweetNotification.Example(exampleTweetHTML, 95);
}
public void ShowExampleNotification(bool reset){
if (reset){
LoadTweet(exampleNotification);
@ -25,5 +32,14 @@ public void ShowExampleNotification(bool reset){
UpdateTitle();
}
protected override FormBorderStyle GetBorderStyle(){
if (WindowsUtils.ShouldAvoidToolWindow && Visible){ // Visible = workaround for alt+tab
return CanResizeWindow ? FormBorderStyle.Sizable : FormBorderStyle.FixedSingle;
}
else{
return CanResizeWindow ? FormBorderStyle.SizableToolWindow : FormBorderStyle.FixedToolWindow;
}
}
}
}

View File

@ -66,22 +66,17 @@ protected Point PrimaryLocation{
}
public bool IsNotificationVisible => Location != ControlExtensions.InvisibleLocation;
protected virtual bool CanDragWindow => true;
public new Point Location{
get => base.Location;
set{
Visible = (base.Location = value) != ControlExtensions.InvisibleLocation;
FormBorderStyle = GetBorderStyle(CanResizeWindow);
FormBorderStyle = GetBorderStyle();
}
}
public bool CanResizeWindow{
get => FormBorderStyle == FormBorderStyle.Sizable || FormBorderStyle == FormBorderStyle.SizableToolWindow;
set => FormBorderStyle = GetBorderStyle(value);
}
public Func<bool> CanMoveWindow { get; set; } = () => true;
protected override bool ShowWithoutActivation => true;
protected double SizeScale => dpiScale*Program.UserConfig.ZoomMultiplier;
@ -120,7 +115,7 @@ protected FormNotificationBase(FormBrowser owner, bool enableContextMenu){
this.browser.Dock = DockStyle.None;
this.browser.ClientSize = ClientSize;
this.browser.IsBrowserInitializedChanged += Browser_IsBrowserInitializedChanged;
this.browser.IsBrowserInitializedChanged += browser_IsBrowserInitializedChanged;
#if DEBUG
this.browser.ConsoleMessage += BrowserUtils.HandleConsoleMessage;
@ -143,7 +138,7 @@ protected FormNotificationBase(FormBrowser owner, bool enableContextMenu){
}
protected override void WndProc(ref Message m){
if (m.Msg == 0x0112 && (m.WParam.ToInt32() & 0xFFF0) == 0xF010 && !CanMoveWindow()){ // WM_SYSCOMMAND, SC_MOVE
if (m.Msg == 0x0112 && (m.WParam.ToInt32() & 0xFFF0) == 0xF010 && !CanDragWindow){ // WM_SYSCOMMAND, SC_MOVE
return;
}
@ -156,7 +151,7 @@ private void owner_FormClosed(object sender, FormClosedEventArgs e){
Close();
}
private void Browser_IsBrowserInitializedChanged(object sender, IsBrowserInitializedChangedEventArgs e){
private void browser_IsBrowserInitializedChanged(object sender, IsBrowserInitializedChangedEventArgs e){
if (e.IsBrowserInitialized){
Initialized?.Invoke(this, EventArgs.Empty);
@ -231,12 +226,12 @@ public void DisplayTooltip(string text){
}
}
private FormBorderStyle GetBorderStyle(bool sizable){
protected virtual FormBorderStyle GetBorderStyle(){
if (WindowsUtils.ShouldAvoidToolWindow && Visible){ // Visible = workaround for alt+tab
return sizable ? FormBorderStyle.Sizable : FormBorderStyle.FixedSingle;
return FormBorderStyle.FixedSingle;
}
else{
return sizable ? FormBorderStyle.SizableToolWindow : FormBorderStyle.FixedToolWindow;
return FormBorderStyle.FixedToolWindow;
}
}
}

View File

@ -31,9 +31,9 @@ abstract partial class FormNotificationMain : FormNotificationBase{
private bool? prevDisplayTimer;
private int? prevFontSize;
public bool RequiresResize{
public virtual bool RequiresResize{
get{
return !prevDisplayTimer.HasValue || !prevFontSize.HasValue || prevDisplayTimer != Program.UserConfig.DisplayNotificationTimer || prevFontSize != FontSizeLevel || CanResizeWindow;
return !prevDisplayTimer.HasValue || !prevFontSize.HasValue || prevDisplayTimer != Program.UserConfig.DisplayNotificationTimer || prevFontSize != FontSizeLevel;
}
set{

View File

@ -12,6 +12,8 @@
namespace TweetDuck.Core.Notification.Screenshot{
sealed class FormNotificationScreenshotable : FormNotificationBase{
protected override bool CanDragWindow => false;
private readonly PluginManager plugins;
public FormNotificationScreenshotable(Action callback, FormBrowser owner, PluginManager pluginManager) : base(owner, false){

View File

@ -42,10 +42,7 @@ public void Trigger(string html, int width, int height){
return;
}
screenshot = new FormNotificationScreenshotable(Callback, owner, plugins){
CanMoveWindow = () => false
};
screenshot = new FormNotificationScreenshotable(Callback, owner, plugins);
screenshot.LoadNotificationForScreenshot(new TweetNotification(string.Empty, string.Empty, string.Empty, html, 0, string.Empty, string.Empty), width, height);
screenshot.Show();
timeout.Start();

View File

@ -74,9 +74,6 @@ public TabSettingsNotifications(FormNotificationExample notification){
trackBarEdgeDistance.SetValueSafe(Config.NotificationEdgeDistance);
labelEdgeDistanceValue.Text = trackBarEdgeDistance.Value+" px";
this.notification.CanMoveWindow = () => radioLocCustom.Checked;
this.notification.CanResizeWindow = radioSizeCustom.Checked;
Disposed += (sender, args) => this.notification.Dispose();
}
@ -168,10 +165,11 @@ private void radioLocCustom_Click(object sender, EventArgs e){
}
private void radioSize_CheckedChanged(object sender, EventArgs e){
if (radioSizeAuto.Checked)Config.NotificationSize = TweetNotification.Size.Auto;
if (radioSizeAuto.Checked){
Config.NotificationSize = TweetNotification.Size.Auto;
}
notification.ShowExampleNotification(false);
notification.CanResizeWindow = false; // must be after ShowNotificationForSettings
}
private void radioSizeCustom_Click(object sender, EventArgs e){
@ -180,8 +178,6 @@ private void radioSizeCustom_Click(object sender, EventArgs e){
}
Config.NotificationSize = TweetNotification.Size.Custom;
notification.CanResizeWindow = true;
notification.ShowExampleNotification(false);
}