using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
+using System.Drawing.Text;
namespace System.Windows.Forms {
[DefaultProperty("Text")]
private bool systray_active;
private ToolTip tooltip;
#if NET_2_0
+ private string balloon_text;
+ private string balloon_title;
+ private ToolTipIcon balloon_icon;
private ContextMenuStrip context_menu_strip;
private object tag;
#endif
owner.OnDoubleClick (EventArgs.Empty);
return;
}
+#if NET_2_0
+ case Msg.NIN_BALLOONUSERCLICK: {
+ owner.OnBalloonTipClicked (EventArgs.Empty);
+ return;
+ }
+
+ case Msg.NIN_BALLOONSHOW: {
+ owner.OnBalloonTipShown (EventArgs.Empty);
+ return;
+ }
+
+ case Msg.NIN_BALLOONHIDE:
+ case Msg.NIN_BALLOONTIMEOUT: {
+ owner.OnBalloonTipClosed (EventArgs.Empty);
+ return;
+ }
+#endif
}
return;
}
}
}
#endregion // NotifyIconWindow Class
+
+ #region NotifyIconBalloonWindow Class
+#if NET_2_0
+ internal class BalloonWindow : Form
+ {
+ private IntPtr owner;
+ private Timer timer;
+
+ private string title;
+ private string text;
+ private ToolTipIcon icon;
+
+ public BalloonWindow (IntPtr owner)
+ {
+ this.owner = owner;
+
+ StartPosition = FormStartPosition.Manual;
+ FormBorderStyle = FormBorderStyle.None;
+ TopMost = true;
+
+ MouseDown += new MouseEventHandler (HandleMouseDown);
+
+ timer = new Timer ();
+ timer.Enabled = false;
+ timer.Tick += new EventHandler (HandleTimer);
+ }
+
+ protected override void OnShown (EventArgs e)
+ {
+ base.OnShown (e);
+ timer.Start ();
+ }
+
+ protected override void OnPaint (PaintEventArgs e)
+ {
+ ThemeEngine.Current.DrawBalloonWindow (e.Graphics, ClientRectangle, this);
+ base.OnPaint (e);
+ }
+
+ private void Recalculate ()
+ {
+ Rectangle rect = ThemeEngine.Current.BalloonWindowRect (this);
+
+ Left = rect.Left;
+ Top = rect.Top;
+ Width = rect.Width;
+ Height = rect.Height;
+ }
+
+ // To be used when we have a "close button" inside balloon.
+ //private void HandleClick (object sender, EventArgs e)
+ //{
+ // XplatUI.SendMessage (owner, Msg.WM_USER, IntPtr.Zero, (IntPtr) Msg.NIN_BALLOONHIDE);
+ // Close ();
+ //}
+
+ private void HandleMouseDown (object sender, MouseEventArgs e)
+ {
+ XplatUI.SendMessage (owner, Msg.WM_USER, IntPtr.Zero, (IntPtr) Msg.NIN_BALLOONUSERCLICK);
+ Close ();
+ }
+
+ private void HandleTimer (object sender, EventArgs e)
+ {
+ timer.Stop ();
+ XplatUI.SendMessage (owner, Msg.WM_USER, IntPtr.Zero, (IntPtr) Msg.NIN_BALLOONTIMEOUT);
+ Close ();
+ }
+
+ internal StringFormat Format {
+ get {
+ StringFormat format = new StringFormat ();
+ format.Alignment = StringAlignment.Near;
+ format.HotkeyPrefix = HotkeyPrefix.Hide;
+
+ return format;
+ }
+ }
+
+ public string Title {
+ get { return this.title; }
+ set {
+ if (value == this.title)
+ return;
+
+ this.title = value;
+ Recalculate ();
+ }
+ }
+
+ public string Text {
+ get { return this.text; }
+ set {
+ if (value == this.text)
+ return;
+
+ this.text = value;
+ Recalculate ();
+ }
+ }
+
+ public int Timeout {
+ get { return timer.Interval; }
+ set {
+ // Some systems theres a limitiation in timeout, WinXP is between 10k and 30k.
+ if (value < 10000)
+ timer.Interval = 10000;
+ else if (value > 30000)
+ timer.Interval = 30000;
+ else
+ timer.Interval = value;
+ }
+ }
+ }
+#endif
+ #endregion // NotifyIconBalloonWindow Class
#region Public Constructors
public NotifyIcon() {
window = new NotifyIconWindow(this);
systray_active = false;
+
+#if NET_2_0
+ balloon_title = "";
+ balloon_text = "";
+#endif
}
public NotifyIcon(System.ComponentModel.IContainer container) : this() {
}
#endregion // Public Constructors
+ #region Public Methods
+#if NET_2_0
+ public void ShowBalloonTip (int timeout)
+ {
+ ShowBalloonTip(timeout, balloon_title, balloon_text, balloon_icon);
+ }
+
+ public void ShowBalloonTip(int timeout, string title, string text, ToolTipIcon icon)
+ {
+ XplatUI.SystrayBalloon(window.Handle, timeout, title, text, icon);
+ }
+#endif
+ #endregion Public Methods
+
#region Private Methods
+#if NET_2_0
+ private void OnBalloonTipClicked (EventArgs e)
+ {
+ EventHandler eh = (EventHandler)(Events [BalloonTipClickedEvent]);
+ if (eh != null)
+ eh (this, e);
+ }
+
+ private void OnBalloonTipClosed (EventArgs e)
+ {
+ EventHandler eh = (EventHandler)(Events [BalloonTipClosedEvent]);
+ if (eh != null)
+ eh (this, e);
+ }
+
+ private void OnBalloonTipShown (EventArgs e)
+ {
+ EventHandler eh = (EventHandler)(Events [BalloonTipShownEvent]);
+ if (eh != null)
+ eh (this, e);
+ }
+#endif
private void OnClick (EventArgs e)
{
EventHandler eh = (EventHandler)(Events [ClickEvent]);
#endregion // Private Methods
#region Public Instance Properties
+#if NET_2_0
+ public ToolTipIcon BalloonTipIcon {
+ get { return this.balloon_icon; }
+ set {
+ if (value == this.balloon_icon)
+ return;
+
+ this.balloon_icon = value;
+ }
+ }
+
+ [Localizable(true)]
+ public string BalloonTipText {
+ get { return this.balloon_text; }
+ set {
+ if (value == this.balloon_text)
+ return;
+
+ this.balloon_text = value;
+ }
+ }
+
+ [Localizable(true)]
+ public string BalloonTipTitle {
+ get { return this.balloon_title; }
+ set {
+ if (value == this.balloon_title)
+ return;
+
+ this.balloon_title = value;
+ }
+ }
+#endif
+
[DefaultValue(null)]
#if NET_2_0
[Browsable (false)]
#region Protected Instance Methods
protected override void Dispose(bool disposing) {
+ if (visible)
+ HideSystray();
+
if (icon_bitmap != null) {
icon_bitmap.Dispose();
}
static object MouseMoveEvent = new object ();
static object MouseUpEvent = new object ();
+#if NET_2_0
+ static object BalloonTipClickedEvent = new object ();
+ static object BalloonTipClosedEvent = new object ();
+ static object BalloonTipShownEvent = new object ();
+
+ [MWFCategory("Action")]
+ public event EventHandler BalloonTipClicked {
+ add { Events.AddHandler (BalloonTipClickedEvent, value); }
+ remove { Events.RemoveHandler (BalloonTipClickedEvent, value); }
+ }
+
+ [MWFCategory("Action")]
+ public event EventHandler BalloonTipClosed {
+ add { Events.AddHandler (BalloonTipClosedEvent, value); }
+ remove { Events.RemoveHandler (BalloonTipClosedEvent, value); }
+ }
+
+ [MWFCategory("Action")]
+ public event EventHandler BalloonTipShown {
+ add { Events.AddHandler (BalloonTipShownEvent, value); }
+ remove { Events.RemoveHandler (BalloonTipShownEvent, value); }
+ }
+#endif
+
#if NET_2_0
[MWFCategory("Action")]
#else