e030863f2c82f94cd82309b2ef52c11f36ef264a
[pithos-ms-client] / trunk%2FPithos.Client.WPF%2FShell%2FPithosBalloon.xaml.cs
1 #region\r
2 /* -----------------------------------------------------------------------\r
3  * <copyright file="PithosBalloon.xaml.cs" company="GRNet">\r
4  * \r
5  * Copyright 2011-2012 GRNET S.A. All rights reserved.\r
6  *\r
7  * Redistribution and use in source and binary forms, with or\r
8  * without modification, are permitted provided that the following\r
9  * conditions are met:\r
10  *\r
11  *   1. Redistributions of source code must retain the above\r
12  *      copyright notice, this list of conditions and the following\r
13  *      disclaimer.\r
14  *\r
15  *   2. Redistributions in binary form must reproduce the above\r
16  *      copyright notice, this list of conditions and the following\r
17  *      disclaimer in the documentation and/or other materials\r
18  *      provided with the distribution.\r
19  *\r
20  *\r
21  * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS\r
22  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
23  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
24  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR\r
25  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
28  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED\r
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
32  * POSSIBILITY OF SUCH DAMAGE.\r
33  *\r
34  * The views and conclusions contained in the software and\r
35  * documentation are those of the authors and should not be\r
36  * interpreted as representing official policies, either expressed\r
37  * or implied, of GRNET S.A.\r
38  * </copyright>\r
39  * -----------------------------------------------------------------------\r
40  */\r
41 #endregion\r
42 using System;\r
43 using System.Collections.Generic;\r
44 using System.Linq;\r
45 using System.Text;\r
46 using System.Windows;\r
47 using System.Windows.Controls;\r
48 using System.Windows.Controls.Primitives;\r
49 using System.Windows.Data;\r
50 using System.Windows.Documents;\r
51 using System.Windows.Input;\r
52 using System.Windows.Media;\r
53 using System.Windows.Media.Imaging;\r
54 using System.Windows.Navigation;\r
55 using System.Windows.Shapes;\r
56 using Hardcodet.Wpf.TaskbarNotification;\r
57 \r
58 namespace Pithos.Client.WPF.Shell\r
59 {\r
60     /// <summary>\r
61     /// Interaction logic for PithosBalloon.xaml\r
62     /// </summary>\r
63     public partial class PithosBalloon : UserControl\r
64     {\r
65         private bool isClosing = false;\r
66   \r
67       #region Message dependency property\r
68   \r
69       public static readonly DependencyProperty MessageProperty =\r
70           DependencyProperty.Register("Message",\r
71                                       typeof (string),\r
72                                       typeof (PithosBalloon),\r
73                                       new FrameworkPropertyMetadata(""));\r
74       public static readonly DependencyProperty TitleProperty =\r
75           DependencyProperty.Register("Title",\r
76                                       typeof (string),\r
77                                       typeof (PithosBalloon),\r
78                                       new FrameworkPropertyMetadata(""));\r
79       public static readonly DependencyProperty IconProperty =\r
80           DependencyProperty.Register("Icon",\r
81                                       typeof (BalloonIcon),\r
82                                       typeof (PithosBalloon),\r
83                                       new FrameworkPropertyMetadata(BalloonIcon.None));\r
84   \r
85       public string Message\r
86       {\r
87         get { return (string) GetValue(MessageProperty); }\r
88         set { SetValue(MessageProperty, value); }\r
89       }\r
90 \r
91       public BalloonIcon Icon\r
92       {\r
93         get { return (BalloonIcon) GetValue(IconProperty); }\r
94         set { \r
95             SetValue(IconProperty, value);            \r
96         }\r
97       }\r
98 \r
99         public string Title\r
100       {\r
101         get { return (string) GetValue(TitleProperty); }\r
102         set { SetValue(TitleProperty, value); }\r
103       }\r
104   \r
105 \r
106        \r
107       #endregion\r
108 \r
109 \r
110       public PithosBalloon()\r
111       {\r
112         InitializeComponent();\r
113           this.DataContext = this;\r
114         TaskbarIcon.AddBalloonClosingHandler(this, OnBalloonClosing);\r
115       }\r
116   \r
117   \r
118       /// <summary>\r
119       /// By subscribing to the <see cref="TaskbarIcon.BalloonClosingEvent"/>\r
120       /// and setting the "Handled" property to true, we suppress the popup\r
121       /// from being closed in order to display the fade-out animation.\r
122       /// </summary>\r
123       private void OnBalloonClosing(object sender, RoutedEventArgs e)\r
124       {\r
125         e.Handled = true;\r
126         isClosing = true;\r
127       }\r
128   \r
129   \r
130       /// <summary>\r
131       /// Resolves the <see cref="TaskbarIcon"/> that displayed\r
132       /// the balloon and requests a close action.\r
133       /// </summary>\r
134       private void imgClose_MouseDown(object sender, MouseButtonEventArgs e)\r
135       {\r
136         //the tray icon assigned this attached property to simplify access\r
137         TaskbarIcon taskbarIcon = TaskbarIcon.GetParentTaskbarIcon(this);\r
138         taskbarIcon.CloseBalloon();\r
139       }\r
140   \r
141       /// <summary>\r
142       /// If the users hovers over the balloon, we don't close it.\r
143       /// </summary>\r
144       private void grid_MouseEnter(object sender, MouseEventArgs e)\r
145       {\r
146         //if we're already running the fade-out animation, do not interrupt anymore\r
147         //(makes things too complicated for the sample)\r
148         if (isClosing) return;\r
149   \r
150         //the tray icon assigned this attached property to simplify access\r
151         TaskbarIcon taskbarIcon = TaskbarIcon.GetParentTaskbarIcon(this);\r
152         taskbarIcon.ResetBalloonCloseTimer();\r
153       }\r
154   \r
155   \r
156       /// <summary>\r
157       /// Closes the popup once the fade-out animation completed.\r
158       /// The animation was triggered in XAML through the attached\r
159       /// BalloonClosing event.\r
160       /// </summary>\r
161       private void OnFadeOutCompleted(object sender, EventArgs e)\r
162       {\r
163         Popup pp = (Popup)Parent;\r
164         pp.IsOpen = false;\r
165       }\r
166    }\r
167 }\r