Represents a tabbed thumbnail on the taskbar for a given window or a control.
Inheritance: IDisposable
        /// <summary>
        /// Adds a new tabbed thumbnail to the taskbar.
        /// </summary>
        /// <param name="preview">Thumbnail preview for a specific window handle or control. The preview
        /// object can be initialized with specific properties for the title, bitmap, and tooltip.</param>
        /// <exception cref="System.ArgumentException">If the tabbed thumbnail has already been added</exception>
        public void AddThumbnailPreview(TabbedThumbnail preview)
        {
            if (preview == null) { throw new ArgumentNullException("preview"); }

            // UI Element has a windowHandle of zero.
            if (preview.WindowHandle == IntPtr.Zero)
            {
                if (_tabbedThumbnailCacheWPF.ContainsKey(preview.WindowsControl))
                {
                    throw new ArgumentException(LocalizedMessages.ThumbnailManagerPreviewAdded, "preview");
                }
                _tabbedThumbnailCacheWPF.Add(preview.WindowsControl, preview);
            }
            else
            {
                // Regular control with a valid handle
                if (_tabbedThumbnailCache.ContainsKey(preview.WindowHandle))
                {
                    throw new ArgumentException(LocalizedMessages.ThumbnailManagerPreviewAdded, "preview");
                }
                _tabbedThumbnailCache.Add(preview.WindowHandle, preview);
            }

            TaskbarWindowManager.AddTabbedThumbnail(preview);

            preview.InvalidatePreview(); // Note: Why this here?
        }
Example #2
0
        public void Dispose(bool disposing)
        {
            if (disposing)
            {
                // Dispose managed resources
                if (_tabbedThumbnailPreview != null)
                {
                    _tabbedThumbnailPreview.Dispose();
                }
                _tabbedThumbnailPreview = null;

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

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

                // Don't dispose the thumbnail buttons as they might be used in another window.
                // Setting them to null will indicate we don't need use anymore.
                _thumbnailButtons = null;
            }
        }
Example #3
0
        /// <summary>
        /// Adds a new tabbed thumbnail to the taskbar.
        /// </summary>
        /// <param name="preview">Thumbnail preview for a specific window handle or control. The preview
        /// object can be initialized with specific properties for the title, bitmap, and tooltip.</param>
        /// <exception cref="System.ArgumentException">If the tabbed thumbnail has already been added</exception>
        public void AddThumbnailPreview(TabbedThumbnail preview)
        {
            if (preview == null)
            {
                throw new ArgumentNullException("preview");
            }

            // UI Element has a windowHandle of zero.
            if (preview.WindowHandle == IntPtr.Zero)
            {
                if (_tabbedThumbnailCacheWPF.ContainsKey(preview.WindowsControl))
                {
                    throw new ArgumentException(LocalizedMessages.ThumbnailManagerPreviewAdded, "preview");
                }
                _tabbedThumbnailCacheWPF.Add(preview.WindowsControl, preview);
            }
            else
            {
                // Regular control with a valid handle
                if (_tabbedThumbnailCache.ContainsKey(preview.WindowHandle))
                {
                    throw new ArgumentException(LocalizedMessages.ThumbnailManagerPreviewAdded, "preview");
                }
                _tabbedThumbnailCache.Add(preview.WindowHandle, preview);
            }

            TaskbarWindowManager.AddTabbedThumbnail(preview);

            preview.InvalidatePreview(); // Note: Why this here?
        }
        internal static void AddTabbedThumbnail(TabbedThumbnail preview)
        {
            // Create a TOP-LEVEL proxy window for the user's source window/control
            TaskbarWindow taskbarWindow = null;

            // get the TaskbarWindow for UIElement/WindowHandle respectfully.
            if (preview.WindowHandle == IntPtr.Zero)
            {
                taskbarWindow = GetTaskbarWindow(preview.WindowsControl, TaskbarProxyWindowType.TabbedThumbnail);
            }
            else
            {
                taskbarWindow = GetTaskbarWindow(preview.WindowHandle, TaskbarProxyWindowType.TabbedThumbnail);
            }

            //create taskbar, or set its TabbedThumbnail
            if (taskbarWindow == null)
            {
                taskbarWindow = new TaskbarWindow(preview);
                _taskbarWindowList.Add(taskbarWindow);
            }
            else if (taskbarWindow.TabbedThumbnail == null)
            {
                taskbarWindow.TabbedThumbnail = preview;
            }

            // Listen for Title changes
            preview.TitleChanged += new EventHandler(thumbnailPreview_TitleChanged);
            preview.TooltipChanged += new EventHandler(thumbnailPreview_TooltipChanged);

            // Get/Set properties for proxy window
            IntPtr windowHandle = taskbarWindow.WindowToTellTaskbarAbout;

            // Register this new tab and set it as being active.
            TaskbarList.Instance.RegisterTab(windowHandle, preview.ParentWindowHandle);
            TaskbarList.Instance.SetTabOrder(windowHandle, IntPtr.Zero);
            TaskbarList.Instance.SetTabActive(windowHandle, preview.ParentWindowHandle, 0);

            // We need to make sure we can set these properties even when running with admin 
            TabbedThumbnailNativeMethods.ChangeWindowMessageFilter(
                TabbedThumbnailNativeMethods.WmDwmSendIconicThumbnail,
                TabbedThumbnailNativeMethods.MsgfltAdd);

            TabbedThumbnailNativeMethods.ChangeWindowMessageFilter(
                TabbedThumbnailNativeMethods.WmDwmSendIconicLivePreviewBitmap,
                TabbedThumbnailNativeMethods.MsgfltAdd);

            // BUG: There should be somewhere to disable CustomWindowPreview. I didn't find it.
            TabbedThumbnailNativeMethods.EnableCustomWindowPreview(windowHandle, true);

            // Make sure we use the initial title set by the user
            // Trigger a "fake" title changed event, so the title is set on the taskbar thumbnail.
            // Empty/null title will be ignored.
            thumbnailPreview_TitleChanged(preview, EventArgs.Empty);
            thumbnailPreview_TooltipChanged(preview, EventArgs.Empty);

            // Indicate to the preview that we've added it on the taskbar
            preview.AddedToTaskbar = true;
        }
        internal static void AddTabbedThumbnail(TabbedThumbnail preview)
        {
            // Create a TOP-LEVEL proxy window for the user's source window/control
            TaskbarWindow taskbarWindow = null;

            // get the TaskbarWindow for UIElement/WindowHandle respectfully.
            if (preview.WindowHandle == IntPtr.Zero)
            {
                taskbarWindow = GetTaskbarWindow(preview.WindowsControl, TaskbarProxyWindowType.TabbedThumbnail);
            }
            else
            {
                taskbarWindow = GetTaskbarWindow(preview.WindowHandle, TaskbarProxyWindowType.TabbedThumbnail);
            }

            //create taskbar, or set its TabbedThumbnail
            if (taskbarWindow == null)
            {
                taskbarWindow = new TaskbarWindow(preview);
                _taskbarWindowList.Add(taskbarWindow);
            }
            else if (taskbarWindow.TabbedThumbnail == null)
            {
                taskbarWindow.TabbedThumbnail = preview;
            }

            // Listen for Title changes
            preview.TitleChanged   += new EventHandler(thumbnailPreview_TitleChanged);
            preview.TooltipChanged += new EventHandler(thumbnailPreview_TooltipChanged);

            // Get/Set properties for proxy window
            IntPtr windowHandle = taskbarWindow.WindowToTellTaskbarAbout;

            // Register this new tab and set it as being active.
            TaskbarList.Instance.RegisterTab(windowHandle, preview.ParentWindowHandle);
            TaskbarList.Instance.SetTabOrder(windowHandle, IntPtr.Zero);
            TaskbarList.Instance.SetTabActive(windowHandle, preview.ParentWindowHandle, 0);

            // We need to make sure we can set these properties even when running with admin
            TabbedThumbnailNativeMethods.ChangeWindowMessageFilter(
                TabbedThumbnailNativeMethods.WmDwmSendIconicThumbnail,
                TabbedThumbnailNativeMethods.MsgfltAdd);

            TabbedThumbnailNativeMethods.ChangeWindowMessageFilter(
                TabbedThumbnailNativeMethods.WmDwmSendIconicLivePreviewBitmap,
                TabbedThumbnailNativeMethods.MsgfltAdd);

            // BUG: There should be somewhere to disable CustomWindowPreview. I didn't find it.
            TabbedThumbnailNativeMethods.EnableCustomWindowPreview(windowHandle, true);

            // Make sure we use the initial title set by the user
            // Trigger a "fake" title changed event, so the title is set on the taskbar thumbnail.
            // Empty/null title will be ignored.
            thumbnailPreview_TitleChanged(preview, EventArgs.Empty);
            thumbnailPreview_TooltipChanged(preview, EventArgs.Empty);

            // Indicate to the preview that we've added it on the taskbar
            preview.AddedToTaskbar = true;
        }
        internal TabbedThumbnailProxyWindow(TabbedThumbnail preview)
        {
            TabbedThumbnail = preview;
            Size = new System.Drawing.Size(1, 1);

            if (!string.IsNullOrEmpty(preview.Title))
            {
                Text = preview.Title;
            }

            if (preview.WindowsControl != null)
            {                
                WindowsControl = preview.WindowsControl;            
            }
        }
        internal TabbedThumbnailProxyWindow(TabbedThumbnail preview)
        {
            TabbedThumbnail = preview;
            Size            = new System.Drawing.Size(1, 1);

            if (!string.IsNullOrEmpty(preview.Title))
            {
                Text = preview.Title;
            }

            if (preview.WindowsControl != null)
            {
                WindowsControl = preview.WindowsControl;
            }
        }
Example #8
0
        /// <summary>
        /// Remove the tabbed thumbnail from the taskbar.
        /// </summary>
        /// <param name="preview">TabbedThumbnail associated with the control/window that
        /// is to be removed from the taskbar</param>
        public void RemoveThumbnailPreview(TabbedThumbnail preview)
        {
            if (preview == null)
            {
                throw new ArgumentNullException("preview");
            }

            if (_tabbedThumbnailCache.ContainsKey(preview.WindowHandle))
            {
                RemoveThumbnailPreview(preview.WindowHandle);
            }
            else if (_tabbedThumbnailCacheWPF.ContainsKey(preview.WindowsControl))
            {
                RemoveThumbnailPreview(preview.WindowsControl);
            }
        }
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                // Dispose managed resources
                if (TabbedThumbnail != null)
                {
                    TabbedThumbnail.Dispose();
                }

                TabbedThumbnail = null;

                WindowsControl = null;
            }

            base.Dispose(disposing);
        }
Example #10
0
        /// <summary>
        /// Determines whether the given preview has been added to the taskbar's tabbed thumbnail list.
        /// </summary>
        /// <param name="preview">The preview to locate on the taskbar's tabbed thumbnail list</param>
        /// <returns>true if the tab is already added on the taskbar; otherwise, false.</returns>
        public bool IsThumbnailPreviewAdded(TabbedThumbnail preview)
        {
            if (preview == null)
            {
                throw new ArgumentNullException("preview");
            }

            if (preview.WindowHandle != IntPtr.Zero && _tabbedThumbnailCache.ContainsKey(preview.WindowHandle))
            {
                return(true);
            }
            else if (preview.WindowsControl != null && _tabbedThumbnailCacheWPF.ContainsKey(preview.WindowsControl))
            {
                return(true);
            }

            return(false);
        }
Example #11
0
        /// <summary>
        /// Moves an existing thumbnail to a new position in the application's group.
        /// </summary>
        /// <param name="previewToChange">Preview for the window whose order is being changed.
        /// This value is required, must already be added via AddThumbnailPreview method, and cannot be null.</param>
        /// <param name="insertBeforePreview">The preview of the tab window whose thumbnail that previewToChange is inserted to the left of.
        /// This preview must already be added via AddThumbnailPreview. If this value is null, the previewToChange tab is added to the end of the list.
        /// </param>
        public static void SetTabOrder(TabbedThumbnail previewToChange, TabbedThumbnail insertBeforePreview)
        {
            if (previewToChange == null)
            {
                throw new ArgumentNullException("previewToChange");
            }

            IntPtr handleToReorder = previewToChange.TaskbarWindow.WindowToTellTaskbarAbout;

            if (insertBeforePreview == null)
            {
                TaskbarList.Instance.SetTabOrder(handleToReorder, IntPtr.Zero);
            }
            else
            {
                IntPtr handleBefore = insertBeforePreview.TaskbarWindow.WindowToTellTaskbarAbout;
                TaskbarList.Instance.SetTabOrder(handleToReorder, handleBefore);
            }
        }
        private static void thumbnailPreview_TitleChanged(object sender, EventArgs e)
        {
            TabbedThumbnail preview = sender as TabbedThumbnail;

            TaskbarWindow taskbarWindow = null;

            if (preview.WindowHandle == IntPtr.Zero)
            {
                taskbarWindow = GetTaskbarWindow(preview.WindowsControl, TaskbarProxyWindowType.TabbedThumbnail);
            }
            else
            {
                taskbarWindow = GetTaskbarWindow(preview.WindowHandle, TaskbarProxyWindowType.TabbedThumbnail);
            }

            // Update the proxy window for the tabbed thumbnail
            if (taskbarWindow != null)
            {
                taskbarWindow.SetTitle(preview.Title);
            }
        }
        private static void thumbnailPreview_TooltipChanged(object sender, EventArgs e)
        {
            TabbedThumbnail preview = sender as TabbedThumbnail;

            TaskbarWindow taskbarWindow = null;

            if (preview.WindowHandle == IntPtr.Zero)
            {
                taskbarWindow = GetTaskbarWindow(preview.WindowsControl, TaskbarProxyWindowType.TabbedThumbnail);
            }
            else
            {
                taskbarWindow = GetTaskbarWindow(preview.WindowHandle, TaskbarProxyWindowType.TabbedThumbnail);
            }

            // Update the proxy window for the tabbed thumbnail
            if (taskbarWindow != null)
            {
                TaskbarList.Instance.SetThumbnailTooltip(taskbarWindow.WindowToTellTaskbarAbout, preview.Tooltip);
            }
        }
Example #14
0
        internal TaskbarWindow(TabbedThumbnail preview)
        {
            if (preview == null)
            {
                throw new ArgumentNullException("preview");
            }

            // Create our proxy window
            // Bug: This is only called in this constructor.  Which will cause the property
            // to fail if TaskbarWindow is initialized from a different constructor.
            TabbedThumbnailProxyWindow = new TabbedThumbnailProxyWindow(preview);

            // set our current state
            EnableThumbnailToolbars = false;
            EnableTabbedThumbnails  = true;

            // copy values
            UserWindowHandle = preview.WindowHandle;
            WindowsControl   = preview.WindowsControl;
            TabbedThumbnail  = preview;
        }
Example #15
0
        /// <summary>
        /// Sets the given tabbed thumbnail preview object as being active on the taskbar tabbed thumbnails list.
        /// Call this method to keep the application and the taskbar in sync as to which window/control
        /// is currently active (or selected, in the case of tabbed application).
        /// </summary>
        /// <param name="preview">TabbedThumbnail for the specific control/indow that is currently active in the application</param>
        /// <exception cref="System.ArgumentException">If the control/window is not yet added to the tabbed thumbnails list</exception>
        public void SetActiveTab(TabbedThumbnail preview)
        {
            if (preview == null)
            {
                throw new ArgumentNullException("preview");
            }

            if (preview.WindowHandle != IntPtr.Zero)
            {
                if (!_tabbedThumbnailCache.ContainsKey(preview.WindowHandle))
                {
                    throw new ArgumentException(LocalizedMessages.ThumbnailManagerPreviewNotAdded, "preview");
                }
                TaskbarWindowManager.SetActiveTab(_tabbedThumbnailCache[preview.WindowHandle].TaskbarWindow);
            }
            else if (preview.WindowsControl != null)
            {
                if (!_tabbedThumbnailCacheWPF.ContainsKey(preview.WindowsControl))
                {
                    throw new ArgumentException(LocalizedMessages.ThumbnailManagerPreviewNotAdded, "preview");
                }
                TaskbarWindowManager.SetActiveTab(_tabbedThumbnailCacheWPF[preview.WindowsControl].TaskbarWindow);
            }
        }
        /// <summary>
        /// Determines whether the given preview has been added to the taskbar's tabbed thumbnail list.
        /// </summary>
        /// <param name="preview">The preview to locate on the taskbar's tabbed thumbnail list</param>
        /// <returns>true if the tab is already added on the taskbar; otherwise, false.</returns>
        public bool IsThumbnailPreviewAdded(TabbedThumbnail preview)
        {
            if (preview == null)
            {
                throw new ArgumentNullException("preview");
            }

            if (preview.WindowHandle != IntPtr.Zero && _tabbedThumbnailCache.ContainsKey(preview.WindowHandle))
            {
                return true;
            }
            else if (preview.WindowsControl != null && _tabbedThumbnailCacheWPF.ContainsKey(preview.WindowsControl))
            {
                return true;
            }

            return false;
        }
        /// <summary>
        /// Remove the tabbed thumbnail from the taskbar.
        /// </summary>
        /// <param name="preview">TabbedThumbnail associated with the control/window that 
        /// is to be removed from the taskbar</param>
        public void RemoveThumbnailPreview(TabbedThumbnail preview)
        {
            if (preview == null)
            {
                throw new ArgumentNullException("preview");
            }

            if (_tabbedThumbnailCache.ContainsKey(preview.WindowHandle))
            {
                RemoveThumbnailPreview(preview.WindowHandle);
            }
            else if (_tabbedThumbnailCacheWPF.ContainsKey(preview.WindowsControl))
            {
                RemoveThumbnailPreview(preview.WindowsControl);
            }
        }
        /// <summary>
        /// Sets the given tabbed thumbnail preview object as being active on the taskbar tabbed thumbnails list.
        /// Call this method to keep the application and the taskbar in sync as to which window/control
        /// is currently active (or selected, in the case of tabbed application).
        /// </summary>
        /// <param name="preview">TabbedThumbnail for the specific control/indow that is currently active in the application</param>
        /// <exception cref="System.ArgumentException">If the control/window is not yet added to the tabbed thumbnails list</exception>
        public void SetActiveTab(TabbedThumbnail preview)
        {
            if (preview == null) { throw new ArgumentNullException("preview"); }

            if (preview.WindowHandle != IntPtr.Zero)
            {
                if (!_tabbedThumbnailCache.ContainsKey(preview.WindowHandle))
                {
                    throw new ArgumentException(LocalizedMessages.ThumbnailManagerPreviewNotAdded, "preview");
                }
                TaskbarWindowManager.SetActiveTab(_tabbedThumbnailCache[preview.WindowHandle].TaskbarWindow);
            }
            else if (preview.WindowsControl != null)
            {
                if (!_tabbedThumbnailCacheWPF.ContainsKey(preview.WindowsControl))
                {
                    throw new ArgumentException(LocalizedMessages.ThumbnailManagerPreviewNotAdded, "preview");
                }
                TaskbarWindowManager.SetActiveTab(_tabbedThumbnailCacheWPF[preview.WindowsControl].TaskbarWindow);
            }
        }
        internal TaskbarWindow(TabbedThumbnail preview)
        {
            if (preview == null) { throw new ArgumentNullException("preview"); }

            // Create our proxy window
            // Bug: This is only called in this constructor.  Which will cause the property 
            // to fail if TaskbarWindow is initialized from a different constructor.
            TabbedThumbnailProxyWindow = new TabbedThumbnailProxyWindow(preview);

            // set our current state
            EnableThumbnailToolbars = false;
            EnableTabbedThumbnails = true;

            // copy values
            UserWindowHandle = preview.WindowHandle;
            WindowsControl = preview.WindowsControl;
            TabbedThumbnail = preview;
        }
Example #20
0
		private void CreateInstances() {

			for(int i = 0; i < _config.Accounts.Count; i++) {

				Account account = _config.Accounts[i];

				if(_instances.ContainsKey(account.Guid)) {
					continue;
				}

				Notifier notifier = new Notifier(account);
				notifier.FormClosed += _Notifier_FormClosed;
				notifier.CheckMailFinished += _Notifier_CheckFinished;

				_instances.Add(account.Guid, notifier);

				notifier.Show(this);

				TabbedThumbnail preview = new TabbedThumbnail(base.Handle, notifier.Handle);
				preview.TabbedThumbnailClosed += _Preview_TabbedThumbnailClosed;
				preview.SetWindowIcon(Resources.Icons.Window);
				preview.Tooltip = String.Empty;
				preview.Title = account.FullAddress;

				notifier.PreviewThumbnail = preview;

				_taskbarManager.TabbedThumbnail.AddThumbnailPreview(preview);
			}

			if(_config.Accounts.Count > 0) {
				Account account = _config.Accounts[0];
				_taskbarManager.TabbedThumbnail.SetActiveTab(_instances[account.Guid].Handle);
			}
		}
        public void Dispose(bool disposing)
        {
            if (disposing)
            {
                // Dispose managed resources
                if (_tabbedThumbnailPreview != null)
                {
                    _tabbedThumbnailPreview.Dispose();
                }
                _tabbedThumbnailPreview = null;

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

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

                // Don't dispose the thumbnail buttons as they might be used in another window.
                // Setting them to null will indicate we don't need use anymore.
                _thumbnailButtons = null;
            }
        }
        /// <summary>
        /// Moves an existing thumbnail to a new position in the application's group.
        /// </summary>
        /// <param name="previewToChange">Preview for the window whose order is being changed. 
        /// This value is required, must already be added via AddThumbnailPreview method, and cannot be null.</param>
        /// <param name="insertBeforePreview">The preview of the tab window whose thumbnail that previewToChange is inserted to the left of. 
        /// This preview must already be added via AddThumbnailPreview. If this value is null, the previewToChange tab is added to the end of the list.
        /// </param>
        public static void SetTabOrder(TabbedThumbnail previewToChange, TabbedThumbnail insertBeforePreview)
        {
            if (previewToChange == null)
            {
                throw new ArgumentNullException("previewToChange");
            }

            IntPtr handleToReorder = previewToChange.TaskbarWindow.WindowToTellTaskbarAbout;

            if (insertBeforePreview == null)
            {
                TaskbarList.Instance.SetTabOrder(handleToReorder, IntPtr.Zero);
            }
            else
            {
                IntPtr handleBefore = insertBeforePreview.TaskbarWindow.WindowToTellTaskbarAbout;
                TaskbarList.Instance.SetTabOrder(handleToReorder, handleBefore);
            }
        }