Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions WindowsAPICodePack/Shell/Shell.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@
<Compile Include="Taskbar\JumpListLink.cs" />
<Compile Include="Taskbar\JumpListSeparator.cs" />
<Compile Include="Taskbar\TabbedThumbnailClosedEventArgs.cs" />
<Compile Include="Taskbar\TabbedThumbnailClosingEventArgs.cs" />
<Compile Include="Taskbar\TabbedThumbnailScreenCapture.cs" />
<Compile Include="Taskbar\TabbedThumbnailManager.cs" />
<Compile Include="Taskbar\TabbedThumbnailBitmapRequestedEventArgs.cs" />
Expand Down
81 changes: 63 additions & 18 deletions WindowsAPICodePack/Shell/Taskbar/TabbedThumbnail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ public string Title
if (_title != value)
{
_title = value;
if (TitleChanged != null) { TitleChanged(this, EventArgs.Empty); }
if (TitleChanged != null)
{
TitleChanged(this, EventArgs.Empty);
}
}
}
}
Expand All @@ -180,7 +183,10 @@ public string Tooltip
if (_tooltip != value)
{
_tooltip = value;
if (TooltipChanged != null) { TooltipChanged(this, EventArgs.Empty); }
if (TooltipChanged != null)
{
TooltipChanged(this, EventArgs.Empty);
}
}
}
}
Expand All @@ -207,7 +213,9 @@ public void SetWindowIcon(Icon icon)
/// <remarks>This method will not release the icon handle. It is the caller's responsibility to release the icon handle.</remarks>
public void SetWindowIcon(IntPtr iconHandle)
{
Icon = iconHandle != IntPtr.Zero ? System.Drawing.Icon.FromHandle(iconHandle) : null;
Icon = iconHandle != IntPtr.Zero
? System.Drawing.Icon.FromHandle(iconHandle)
: null;

if (TaskbarWindow != null && TaskbarWindow.TabbedThumbnailProxyWindow != null)
{
Expand Down Expand Up @@ -319,11 +327,11 @@ internal void SetImage(IntPtr hBitmap)
{
ShellNativeMethods.DeleteObject(CurrentHBitmap);
}

// Set the new bitmap
CurrentHBitmap = hBitmap;

// Let DWM know to invalidate its cached thumbnail/preview and ask us for a new one
// Let DWM know to invalidate its cached thumbnail/preview and ask us for a new one
TaskbarWindowManager.InvalidatePreview(TaskbarWindow);
}

Expand Down Expand Up @@ -355,8 +363,6 @@ public void InvalidatePreview()

#endregion



#region Events

/// <summary>
Expand All @@ -369,6 +375,11 @@ public void InvalidatePreview()
/// </summary>
public event EventHandler TooltipChanged;

/// <summary>
/// The event that occurs when a tab is closing on the taskbar thumbnail preview.
/// </summary>
public event EventHandler<TabbedThumbnailClosingEventArgs> TabbedThumbnailClosing;

/// <summary>
/// The event that occurs when a tab is closed on the taskbar thumbnail preview.
/// </summary>
Expand Down Expand Up @@ -425,19 +436,35 @@ internal void OnTabbedThumbnailMinimized()
}

/// <summary>
/// Returns true if the thumbnail was removed from the taskbar; false if it was not.
/// Returns true if the thumbnail should be removed from the taskbar; false if it should not.
/// </summary>
/// <returns>Returns true if the thumbnail was removed from the taskbar; false if it was not.</returns>
internal bool OnTabbedThumbnailClosed()
/// <returns>Returns true if the thumbnail should be removed from the taskbar; false if it should not.</returns>
internal bool OnTabbedThumbnailClosing()
{
var closingHandler = TabbedThumbnailClosing;
if (closingHandler != null)
{
var eventArgs = GetTabbedThumbnailClosingEventArgs();

closingHandler(this, eventArgs);

if (eventArgs.Cancel)
{
return false;
}
}

return true;
}

internal void OnTabbedThumbnailClosed()
{
var closedHandler = TabbedThumbnailClosed;
if (closedHandler != null)
{
var closingEvent = GetTabbedThumbnailClosingEventArgs();
var eventArgs = GetTabbedThumbnailClosedEventArgs();

closedHandler(this, closingEvent);

if (closingEvent.Cancel) { return false; }
closedHandler(this, eventArgs);
}
else
{
Expand All @@ -447,7 +474,6 @@ internal bool OnTabbedThumbnailClosed()

// Remove it from the internal list as well as the taskbar
TaskbarManager.Instance.TabbedThumbnail.RemoveThumbnailPreview(this);
return true;
}

internal void OnTabbedThumbnailActivated()
Expand Down Expand Up @@ -483,7 +509,23 @@ internal void OnTabbedThumbnailBitmapRequested()
}
}

private TabbedThumbnailClosedEventArgs GetTabbedThumbnailClosingEventArgs()
private TabbedThumbnailClosingEventArgs GetTabbedThumbnailClosingEventArgs()
{
TabbedThumbnailClosingEventArgs eventArgs = null;

if (this.WindowHandle != IntPtr.Zero)
{
eventArgs = new TabbedThumbnailClosingEventArgs(this.WindowHandle);
}
else if (this.WindowsControl != null)
{
eventArgs = new TabbedThumbnailClosingEventArgs(this.WindowsControl);
}

return eventArgs;
}

private TabbedThumbnailClosedEventArgs GetTabbedThumbnailClosedEventArgs()
{
TabbedThumbnailClosedEventArgs eventArgs = null;

Expand All @@ -495,7 +537,7 @@ private TabbedThumbnailClosedEventArgs GetTabbedThumbnailClosingEventArgs()
{
eventArgs = new TabbedThumbnailClosedEventArgs(this.WindowsControl);
}

return eventArgs;
}

Expand Down Expand Up @@ -546,7 +588,10 @@ protected virtual void Dispose(bool disposing)
{
_taskbarWindow = null;

if (Icon != null) { Icon.Dispose(); }
if (Icon != null)
{
Icon.Dispose();
}
Icon = null;

_title = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,5 @@ public TabbedThumbnailClosedEventArgs(IntPtr windowHandle) : base(windowHandle)
/// </summary>
/// <param name="windowsControl">WPF Control (UIElement) related to the event</param>
public TabbedThumbnailClosedEventArgs(UIElement windowsControl) : base(windowsControl) { }

/// <summary>
/// If set to true, the proxy window will not be removed from the taskbar.
/// </summary>
public bool Cancel { get; set; }

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Windows;

namespace Microsoft.WindowsAPICodePack.Taskbar
{
/// <summary>
/// Event args for the TabbedThumbnailClosing event. The application should set
/// the Cancel property to true if the thumbnail should not be removed.
/// </summary>
public class TabbedThumbnailClosingEventArgs : TabbedThumbnailEventArgs
{
/// <summary>
/// Creates a Event Args for a TabbedThumbnailClosing event.
/// </summary>
/// <param name="windowHandle">Window handle for the control/window related to the event</param>
public TabbedThumbnailClosingEventArgs(IntPtr windowHandle)
: base(windowHandle)
{
}

/// <summary>
/// Creates a Event Args for a TabbedThumbnailClosing event.
/// </summary>
/// <param name="windowsControl">WPF Control (UIElement) related to the event</param>
public TabbedThumbnailClosingEventArgs(UIElement windowsControl)
: base(windowsControl)
{
}

/// <summary>
/// Gets or sets a value indicating whether the thumbnail should not be removed.
/// </summary>
public bool Cancel
{
get;
set;
}
}
}
Loading