mirror of
https://github.com/greenshot/greenshot
synced 2025-08-14 02:37:03 -07:00
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:
parent
7918109284
commit
e274a08a1e
7 changed files with 143 additions and 100 deletions
33
GreenshotPlugin/Controls/FormWithoutActivation.cs
Normal file
33
GreenshotPlugin/Controls/FormWithoutActivation.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
* For more information see: http://getgreenshot.org/
|
||||
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace GreenshotPlugin.Controls {
|
||||
/// <summary>
|
||||
/// FormWithoutActivation is exactly like a normal form, but doesn't activate (steal focus)
|
||||
/// </summary>
|
||||
public class FormWithoutActivation : Form {
|
||||
protected override bool ShowWithoutActivation {
|
||||
get { return true; }
|
||||
}
|
||||
}
|
||||
}
|
90
GreenshotPlugin/Controls/ThumbnailForm.cs
Normal file
90
GreenshotPlugin/Controls/ThumbnailForm.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue