/// <summary> /// Shows the notification window. /// </summary> /// <param name="win">The <see cref="NotificationWindow"/> to show</param> /// <remarks> /// Classes inheriting from <see cref="VisualDisplay"/> should always use this /// method to show their notifications rather than calling <c>NotificationWindow.Show</c> /// directly because this method hooks up some necessary events to handle click callbacks, /// layout management, etc. /// </remarks> protected void Show(NotificationWindow win) { win.AfterLoad += new EventHandler(win_AfterLoad); win.FormClosed += new System.Windows.Forms.FormClosedEventHandler(win_FormClosed); win.NotificationClicked += new NotificationCallbackEventHandler(win_NotificationClicked); win.NotificationClosed += new NotificationCallbackEventHandler(win_NotificationClosed); win.Show(); }
/// <summary> /// Creates a new PopupAnimator using the preset default values. /// </summary> /// <param name="form">The <see cref="NotificationWindow"/> to animate</param> public PopupAnimator(NotificationWindow form) { this.form = form; form.BeforeShown += new EventHandler(form_BeforeShown); form.AutoClosing += new System.Windows.Forms.FormClosingEventHandler(form_AutoClosing); this.timer = new Timer(); this.timer.Interval = TIMER_INTERVAL; this.timer.Tick += new EventHandler(timer_Tick); }
/// <summary> /// Creates a new FadeAnimator using the preset default values. /// </summary> /// <param name="form">The <see cref="NotificationWindow"/> to animate</param> public FadeAnimator(NotificationWindow form) { this.form = form; form.Opacity = 0; form.BeforeShown += new EventHandler(form_BeforeShown); form.AutoClosing += new FormClosingEventHandler(form_AutoClosing); this.timer = new Timer(); this.timer.Interval = TIMER_INTERVAL; this.timer.Tick += new EventHandler(timer_Tick); }
/// <summary> /// Creates a new PopupAnimator specifying the pop behavior values /// </summary> /// <param name="form">The <see cref="NotificationWindow"/> to animate</param> /// <param name="popInDuration">The amount of time (in milliseconds) over which the pop-in should occur</param> /// <param name="popOutDuration">The amount of time (in milliseconds) over which the pop-out should occur</param> /// <param name="direction">The direction the window should pop</param> public PopupAnimator(NotificationWindow form, int popInDuration, int popOutDuration, PopupDirection direction) : this(form) { this.popInDuration = popInDuration; this.popOutDuration = popOutDuration; this.direction = direction; }
/// <summary> /// Creates a new FadeAnimator specifying the fade behavior values /// </summary> /// <param name="form">The <see cref="NotificationWindow"/> to animate</param> /// <param name="fadeInDuration">The amount of time (in milliseconds) over which the fade-in should occur</param> /// <param name="fadeOutDuration">The amount of time (in milliseconds) over which the fade-out should occur</param> /// <param name="finalOpacity">The final opacity of the form once faded in</param> public FadeAnimator(NotificationWindow form, int fadeInDuration, int fadeOutDuration, double finalOpacity) : this(form) { this.fadeInDuration = fadeInDuration; this.fadeOutDuration = fadeOutDuration; this.finalOpacity = finalOpacity; }
protected override LayoutManager GetLayoutManager( NotificationWindow win ) { switch ( ( (WindowsGrowlNotificationWindow)win ).DisplayLocation ) { case WindowsGrowlVisualDisplayLocation.TopLeft: return this.tllm; case WindowsGrowlVisualDisplayLocation.TopRight: return this.trlm; case WindowsGrowlVisualDisplayLocation.BottomLeft: return this.bllm; } return this.brlm; }
/// <summary> /// Makes a call to the associated LayoutManager when the notification is shown /// </summary> /// <param name="sender">The object that fired the event</param> /// <param name="e">Information about the event</param> void win_AfterLoad(object sender, EventArgs e) { NotificationWindow win = (NotificationWindow)sender; this.activeWindows.Insert(0, win); LayoutManager lm = GetLayoutManager(win); if (lm != null) { lm.Add(win); } }
protected override LayoutManager GetLayoutManager(NotificationWindow nw) { BlueFlowerWindow win = (BlueFlowerWindow)nw; switch (win.DisplayLocation) { case Location.TopLeft: return tllm; case Location.BottomLeft: return bllm; case Location.TopRight: return trlm; default: return brlm; } }
/// <summary> /// Makes a call to the associated LayoutManager when the notification is closed /// </summary> /// <param name="sender">The object that fired the event</param> /// <param name="e">Information about the event</param> void win_FormClosed(object sender, System.Windows.Forms.FormClosedEventArgs e) { NotificationWindow win = (NotificationWindow)sender; this.activeWindows.Remove(win); if (!this.suppressLayout) { LayoutManager lm = GetLayoutManager(win); if (lm != null) { lm.Remove(win); } } win.AfterLoad -= new EventHandler(win_AfterLoad); win.FormClosed -= new System.Windows.Forms.FormClosedEventHandler(win_FormClosed); win.NotificationClicked -= new NotificationCallbackEventHandler(win_NotificationClicked); win.NotificationClosed -= new NotificationCallbackEventHandler(win_NotificationClosed); }
/// <summary> /// Releases unmanaged and - optionally - managed resources /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected void Dispose(bool disposing) { if (disposing) { if (this.timer != null) { this.timer.Tick -= new EventHandler(timer_Tick); this.timer.Dispose(); this.timer = null; } if (this.form != null) { this.form.BeforeShown -= new EventHandler(form_BeforeShown); this.form.AutoClosing -= new FormClosingEventHandler(form_AutoClosing); this.form.Dispose(); this.form = null; } } }
/// <summary> /// Removes a notification from the list and repositions any other open notifications /// </summary> /// <param name="win">The notification window being closed</param> /// <remarks> /// This method does not call the window's <c>Close</c> method - you must close /// the window yourself. /// </remarks> public void Remove(NotificationWindow win) { RepositionWindows(win, true); this.activeWindows.Remove(win); }
protected override LayoutManager GetLayoutManager(NotificationWindow win) { return this.lm; }
/// <summary> /// Returns a reference to the <see cref="LayoutManager"/> used to control /// window layout. /// </summary> /// <param name="win">The current <see cref="NotificationWindow"/> being shown or hidden</param> /// <returns> /// <see cref="LayoutManager"/> if the display is using the built-in layout management; /// <c>null</c> if the display is handling its own layout management /// </returns> protected virtual LayoutManager GetLayoutManager(NotificationWindow win) { return null; }
/// <summary> /// Repositions any open windows /// </summary> /// <param name="currentWin">The new window being shown or the window being closed</param> /// <param name="closing">Indicates if the window is being closed (vs. being shown)</param> private void RepositionWindows(NotificationWindow currentWin, bool closing) { if (this.ActiveWindows.Count > 0) { System.Windows.Forms.Screen screen = System.Windows.Forms.Screen.FromControl(currentWin); lock (this.ActiveWindows) { if (closing) { int x = currentWin.Location.X; int y = (this.direction == AutoPositionDirection.UpLeft || this.direction == AutoPositionDirection.UpRight ? currentWin.Bottom : currentWin.Top); int index = this.ActiveWindows.IndexOf(currentWin); for (int i = index; i < this.ActiveWindows.Count; i++) { NotificationWindow aw = this.ActiveWindows[i]; if (aw != currentWin) { switch (this.direction) { case AutoPositionDirection.DownLeft: case AutoPositionDirection.DownRight: if (y + aw.Height > screen.Bounds.Bottom) { y = screen.WorkingArea.Top; x = aw.Location.X; } break; case AutoPositionDirection.UpLeft: case AutoPositionDirection.UpRight: y = y - aw.Height; if (y < screen.Bounds.Top) { y = screen.WorkingArea.Bottom - aw.Height; x = aw.Location.X; } break; } aw.Location = new System.Drawing.Point(x, y); x = aw.Location.X; y = (this.direction == AutoPositionDirection.UpLeft || this.direction == AutoPositionDirection.UpRight ? aw.Top - this.verticalPadding : aw.Bottom + this.verticalPadding); } } } else { int x = currentWin.Location.X; int y = currentWin.Location.Y; foreach (NotificationWindow aw in this.ActiveWindows) { if (aw != currentWin) { switch (this.direction) { case AutoPositionDirection.DownLeft: y = y + currentWin.Size.Height + this.verticalPadding; if (y + aw.Height > screen.WorkingArea.Bottom) { y = screen.WorkingArea.Top; x = x - currentWin.Size.Width - this.horizontalPadding; } break; case AutoPositionDirection.DownRight: y = y + currentWin.Size.Height + this.verticalPadding; if (y + aw.Height > screen.WorkingArea.Bottom) { y = screen.WorkingArea.Top; x = x + currentWin.Size.Width + this.horizontalPadding; } break; case AutoPositionDirection.UpLeft: y = y - this.verticalPadding - aw.Height; if (y < screen.WorkingArea.Top) { y = screen.WorkingArea.Bottom - aw.Height; x = x - currentWin.Size.Width - this.horizontalPadding; } break; case AutoPositionDirection.UpRight: y = y - this.verticalPadding - aw.Height; if (y < screen.WorkingArea.Top) { y = screen.WorkingArea.Bottom - aw.Height; x = x + currentWin.Size.Width + this.horizontalPadding; } break; } aw.Location = new System.Drawing.Point(x, y); x = aw.Location.X; currentWin = aw; } } } } } }
/// <summary> /// Adds a new notification to the list and repositions any other open notifications /// </summary> /// <param name="win">The new notification window being shown</param> /// <remarks> /// This method does not call the window's <c>Show</c> method - you must show /// the window yourself. /// </remarks> public void Add(NotificationWindow win) { RepositionWindows(win, false); this.activeWindows.Insert(0, win); }
protected override LayoutManager GetLayoutManager(NotificationWindow win) { SmokestackWindow sw = (SmokestackWindow)win; switch (sw.DisplayLocation) { case Location.TopLeft : return tllm; case Location.BottomLeft : return bllm; case Location.TopRight : return trlm; default : return brlm; } }
/// <summary> /// Returns a reference to the <see cref="LayoutManager"/> used to control /// window layout. /// </summary> /// <param name="win">The current <see cref="NotificationWindow"/> being shown or hidden</param> /// <returns> /// <see cref="LayoutManager"/> if the display is using the built-in layout management; /// <c>null</c> if the display is handling its own layout management /// </returns> protected virtual LayoutManager GetLayoutManager(NotificationWindow win) { return(null); }