Refactored the "thumbnail" preview code to ThumbnailForm.cs, this removes some complexity from the MainForm. Also fixed an Imgur issue, which I noticed as they currently have maintenance. And I added a missing key to the language-en-US.xml

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1909 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-06-08 10:36:07 +00:00
parent 7918109284
commit e274a08a1e
7 changed files with 143 additions and 100 deletions

View file

@ -294,7 +294,7 @@ namespace Greenshot {
private CopyData copyData = null;
// Thumbnail preview
private FormWithoutActivation thumbnailForm = null;
private ThumbnailForm thumbnailForm = null;
private IntPtr thumbnailHandle = IntPtr.Zero;
private Rectangle parentMenuBounds = Rectangle.Empty;
// Make sure we have only one settings form
@ -743,72 +743,17 @@ namespace Greenshot {
private void ShowThumbnailOnEnter(object sender, EventArgs e) {
ToolStripMenuItem captureWindowItem = sender as ToolStripMenuItem;
WindowDetails window = captureWindowItem.Tag as WindowDetails;
parentMenuBounds = captureWindowItem.GetCurrentParent().TopLevelControl.Bounds;
if (thumbnailForm == null) {
thumbnailForm = new FormWithoutActivation();
thumbnailForm.ShowInTaskbar = false;
thumbnailForm.FormBorderStyle = FormBorderStyle.None;
thumbnailForm.TopMost = false;
thumbnailForm.Enabled = false;
if (conf.WindowCaptureMode == WindowCaptureMode.Auto || conf.WindowCaptureMode == WindowCaptureMode.Aero) {
thumbnailForm.BackColor = Color.FromArgb(255, conf.DWMBackgroundColor.R, conf.DWMBackgroundColor.G, conf.DWMBackgroundColor.B);
} else {
thumbnailForm.BackColor = Color.White;
}
}
if (thumbnailHandle != IntPtr.Zero) {
DWM.DwmUnregisterThumbnail(thumbnailHandle);
thumbnailHandle = IntPtr.Zero;
}
DWM.DwmRegisterThumbnail(thumbnailForm.Handle, window.Handle, out thumbnailHandle);
if (thumbnailHandle != IntPtr.Zero) {
Rectangle windowRectangle = window.WindowRectangle;
int thumbnailHeight = 200;
int thumbnailWidth = (int)(thumbnailHeight * ((float)windowRectangle.Width / (float)windowRectangle.Height));
if (thumbnailWidth > parentMenuBounds.Width) {
thumbnailWidth = parentMenuBounds.Width;
thumbnailHeight = (int)(thumbnailWidth * ((float)windowRectangle.Height / (float)windowRectangle.Width));
}
thumbnailForm.Width = thumbnailWidth;
thumbnailForm.Height = thumbnailHeight;
// Prepare the displaying of the Thumbnail
DWM_THUMBNAIL_PROPERTIES props = new DWM_THUMBNAIL_PROPERTIES();
props.Opacity = (byte)255;
props.Visible = true;
props.SourceClientAreaOnly = false;
props.Destination = new RECT(0, 0, thumbnailWidth, thumbnailHeight);
DWM.DwmUpdateThumbnailProperties(thumbnailHandle, ref props);
if (!thumbnailForm.Visible) {
thumbnailForm.Show();
}
// Make sure it's on "top"!
User32.SetWindowPos(thumbnailForm.Handle,captureWindowItem.GetCurrentParent().TopLevelControl.Handle, 0,0,0,0, WindowPos.SWP_NOMOVE | WindowPos.SWP_NOSIZE | WindowPos.SWP_NOACTIVATE);
// Align to menu
Rectangle screenBounds = WindowCapture.GetScreenBounds();
if (screenBounds.Contains(parentMenuBounds.Left, parentMenuBounds.Top - thumbnailHeight)) {
thumbnailForm.Location = new Point(parentMenuBounds.Left + (parentMenuBounds.Width/2) - (thumbnailWidth/2), parentMenuBounds.Top - thumbnailHeight);
} else {
thumbnailForm.Location = new Point(parentMenuBounds.Left + (parentMenuBounds.Width/2) - (thumbnailWidth/2), parentMenuBounds.Bottom);
}
thumbnailForm = new ThumbnailForm();
}
thumbnailForm.ShowThumbnail(window, captureWindowItem.GetCurrentParent().TopLevelControl);
}
private void HideThumbnailOnLeave(object sender, EventArgs e) {
hideThumbnail();
}
private void hideThumbnail() {
if (thumbnailHandle != IntPtr.Zero) {
DWM.DwmUnregisterThumbnail(thumbnailHandle);
thumbnailHandle = IntPtr.Zero;
thumbnailForm.Hide();
}
}
private void cleanupThumbnail() {
hideThumbnail();
if (thumbnailForm != null) {
thumbnailForm.Close();
thumbnailForm = null;

View file

@ -161,9 +161,6 @@
<Compile Include="Forms\CaptureForm.Designer.cs">
<DependentUpon>CaptureForm.cs</DependentUpon>
</Compile>
<Compile Include="Forms\FormWithoutActivation.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\ImageEditorForm.cs">
<SubType>Form</SubType>
</Compile>

View file

@ -51,6 +51,7 @@ Also, we would highly appreciate if you checked whether a tracker item already e
<resource name="contextmenu_openrecentcapture">Open last capture location</resource>
<resource name="contextmenu_quicksettings">Quick preferences</resource>
<resource name="contextmenu_settings">Preferences...</resource>
<resource name="destination_exportfailed">Error while exporting to {0}. Please try again.</resource>
<resource name="editor_arrange">Arrange</resource>
<resource name="editor_arrowheads">Arrow heads</resource>
<resource name="editor_arrowheads_both">Both</resource>

View file

@ -156,6 +156,10 @@ namespace GreenshotImgurPlugin {
}
public static void RetrieveImgurThumbnail(ImgurInfo imgurInfo) {
if (imgurInfo.SmallSquare == null) {
LOG.Warn("Imgur URL was null, not retrieving thumbnail.");
return;
}
LOG.InfoFormat("Retrieving Imgur image for {0} with url {1}", imgurInfo.Hash, imgurInfo);
HttpWebRequest webRequest = (HttpWebRequest)NetworkHelper.CreateWebRequest(imgurInfo.SmallSquare);
webRequest.Method = "GET";

View file

@ -21,7 +21,7 @@
using System;
using System.Windows.Forms;
namespace Greenshot.Forms {
namespace GreenshotPlugin.Controls {
/// <summary>
/// FormWithoutActivation is exactly like a normal form, but doesn't activate (steal focus)
/// </summary>

View file

@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using GreenshotPlugin.Core;
using Greenshot.IniFile;
using System.Drawing;
using GreenshotPlugin.UnmanagedHelpers;
namespace GreenshotPlugin.Controls {
public class ThumbnailForm : FormWithoutActivation {
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
private IntPtr thumbnailHandle = IntPtr.Zero;
private Rectangle parentMenuBounds = Rectangle.Empty;
public ThumbnailForm() {
ShowInTaskbar = false;
FormBorderStyle = FormBorderStyle.None;
TopMost = false;
Enabled = false;
if (conf.WindowCaptureMode == WindowCaptureMode.Auto || conf.WindowCaptureMode == WindowCaptureMode.Aero) {
BackColor = Color.FromArgb(255, conf.DWMBackgroundColor.R, conf.DWMBackgroundColor.G, conf.DWMBackgroundColor.B);
} else {
BackColor = Color.White;
}
// cleanup at close
this.FormClosing += delegate {
UnregisterThumbnail();
};
}
public new void Hide() {
UnregisterThumbnail();
base.Hide();
}
private void UnregisterThumbnail() {
if (thumbnailHandle != IntPtr.Zero) {
DWM.DwmUnregisterThumbnail(thumbnailHandle);
thumbnailHandle = IntPtr.Zero;
}
}
public void ShowThumbnail(WindowDetails window, Control parentControl) {
UnregisterThumbnail();
DWM.DwmRegisterThumbnail(Handle, window.Handle, out thumbnailHandle);
if (thumbnailHandle != IntPtr.Zero) {
Rectangle windowRectangle = window.WindowRectangle;
int thumbnailHeight = 200;
int thumbnailWidth = (int)(thumbnailHeight * ((float)windowRectangle.Width / (float)windowRectangle.Height));
if (parentControl != null && thumbnailWidth > parentControl.Width) {
thumbnailWidth = parentControl.Width;
thumbnailHeight = (int)(thumbnailWidth * ((float)windowRectangle.Height / (float)windowRectangle.Width));
}
Width = thumbnailWidth;
Height = thumbnailHeight;
// Prepare the displaying of the Thumbnail
DWM_THUMBNAIL_PROPERTIES props = new DWM_THUMBNAIL_PROPERTIES();
props.Opacity = (byte)255;
props.Visible = true;
props.SourceClientAreaOnly = false;
props.Destination = new RECT(0, 0, thumbnailWidth, thumbnailHeight);
DWM.DwmUpdateThumbnailProperties(thumbnailHandle, ref props);
if (parentControl != null) {
AlignToControl(parentControl);
}
if (!Visible) {
Show();
}
// Make sure it's on "top"!
if (parentControl != null) {
User32.SetWindowPos(Handle, parentControl.Handle, 0, 0, 0, 0, WindowPos.SWP_NOMOVE | WindowPos.SWP_NOSIZE | WindowPos.SWP_NOACTIVATE);
}
}
}
public void AlignToControl(Control alignTo) {
Rectangle screenBounds = WindowCapture.GetScreenBounds();
if (screenBounds.Contains(alignTo.Left, alignTo.Top - Height)) {
Location = new Point(alignTo.Left + (alignTo.Width / 2) - (Width / 2), alignTo.Top - Height);
} else {
Location = new Point(alignTo.Left + (alignTo.Width / 2) - (Width / 2), alignTo.Bottom);
}
}
}
}

View file

@ -175,6 +175,9 @@
<Compile Include="..\GreenshotInterop\OfficeInterop\WordInterop.cs">
<Link>Interop\WordInterop.cs</Link>
</Compile>
<Compile Include="Controls\FormWithoutActivation.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Controls\GreenshotButton.cs">
<SubType>Component</SubType>
</Compile>
@ -223,6 +226,9 @@
<Compile Include="Controls\GreenshotToolDropDownButton.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\ThumbnailForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Core\AbstractDestination.cs" />
<Compile Include="Core\AbstractProcessor.cs" />
<Compile Include="Core\AccessibleHelper.cs" />