Statistics
| Branch: | Revision:

root / trunk / Pithos.Client.WPF / Shell / PithosBalloon.xaml.cs @ f2d88248

History | View | Annotate | Download (6.4 kB)

1
#region
2
/* -----------------------------------------------------------------------
3
 * <copyright file="PithosBalloon.xaml.cs" company="GRNet">
4
 * 
5
 * Copyright 2011-2012 GRNET S.A. All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or
8
 * without modification, are permitted provided that the following
9
 * conditions are met:
10
 *
11
 *   1. Redistributions of source code must retain the above
12
 *      copyright notice, this list of conditions and the following
13
 *      disclaimer.
14
 *
15
 *   2. Redistributions in binary form must reproduce the above
16
 *      copyright notice, this list of conditions and the following
17
 *      disclaimer in the documentation and/or other materials
18
 *      provided with the distribution.
19
 *
20
 *
21
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
22
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
25
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
28
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
 * POSSIBILITY OF SUCH DAMAGE.
33
 *
34
 * The views and conclusions contained in the software and
35
 * documentation are those of the authors and should not be
36
 * interpreted as representing official policies, either expressed
37
 * or implied, of GRNET S.A.
38
 * </copyright>
39
 * -----------------------------------------------------------------------
40
 */
41
#endregion
42
using System;
43
using System.Collections.Generic;
44
using System.Linq;
45
using System.Text;
46
using System.Windows;
47
using System.Windows.Controls;
48
using System.Windows.Controls.Primitives;
49
using System.Windows.Data;
50
using System.Windows.Documents;
51
using System.Windows.Input;
52
using System.Windows.Media;
53
using System.Windows.Media.Imaging;
54
using System.Windows.Navigation;
55
using System.Windows.Shapes;
56
using Hardcodet.Wpf.TaskbarNotification;
57

    
58
namespace Pithos.Client.WPF.Shell
59
{
60
    /// <summary>
61
    /// Interaction logic for PithosBalloon.xaml
62
    /// </summary>
63
    public partial class PithosBalloon : UserControl
64
    {
65
        private bool isClosing = false;
66
  
67
      #region Message dependency property
68
  
69
      public static readonly DependencyProperty MessageProperty =
70
          DependencyProperty.Register("Message",
71
                                      typeof (string),
72
                                      typeof (PithosBalloon),
73
                                      new FrameworkPropertyMetadata(""));
74
      public static readonly DependencyProperty TitleProperty =
75
          DependencyProperty.Register("Title",
76
                                      typeof (string),
77
                                      typeof (PithosBalloon),
78
                                      new FrameworkPropertyMetadata(""));
79
      public static readonly DependencyProperty IconProperty =
80
          DependencyProperty.Register("Icon",
81
                                      typeof (BalloonIcon),
82
                                      typeof (PithosBalloon),
83
                                      new FrameworkPropertyMetadata(BalloonIcon.None));
84
  
85
      public string Message
86
      {
87
        get { return (string) GetValue(MessageProperty); }
88
        set { SetValue(MessageProperty, value); }
89
      }
90

    
91
      public BalloonIcon Icon
92
      {
93
        get { return (BalloonIcon) GetValue(IconProperty); }
94
        set { 
95
            SetValue(IconProperty, value);            
96
        }
97
      }
98

    
99
        public string Title
100
      {
101
        get { return (string) GetValue(TitleProperty); }
102
        set { SetValue(TitleProperty, value); }
103
      }
104
  
105

    
106
       
107
      #endregion
108

    
109

    
110
      public PithosBalloon()
111
      {
112
        InitializeComponent();
113
          this.DataContext = this;
114
        TaskbarIcon.AddBalloonClosingHandler(this, OnBalloonClosing);
115
      }
116
  
117
  
118
      /// <summary>
119
      /// By subscribing to the <see cref="TaskbarIcon.BalloonClosingEvent"/>
120
      /// and setting the "Handled" property to true, we suppress the popup
121
      /// from being closed in order to display the fade-out animation.
122
      /// </summary>
123
      private void OnBalloonClosing(object sender, RoutedEventArgs e)
124
      {
125
        e.Handled = true;
126
        isClosing = true;
127
      }
128
  
129
  
130
      /// <summary>
131
      /// Resolves the <see cref="TaskbarIcon"/> that displayed
132
      /// the balloon and requests a close action.
133
      /// </summary>
134
      private void imgClose_MouseDown(object sender, MouseButtonEventArgs e)
135
      {
136
          //the tray icon assigned this attached property to simplify access
137
          CloseBalloon();
138
      }
139

    
140
        private void CloseBalloon()
141
        {
142
            TaskbarIcon taskbarIcon = TaskbarIcon.GetParentTaskbarIcon(this);
143
            taskbarIcon.CloseBalloon();
144
        }
145

    
146
        /// <summary>
147
      /// If the users hovers over the balloon, we don't close it.
148
      /// </summary>
149
      private void grid_MouseEnter(object sender, MouseEventArgs e)
150
      {
151
        //if we're already running the fade-out animation, do not interrupt anymore
152
        //(makes things too complicated for the sample)
153
        if (isClosing) return;
154
  
155
        //the tray icon assigned this attached property to simplify access
156
        TaskbarIcon taskbarIcon = TaskbarIcon.GetParentTaskbarIcon(this);
157
        taskbarIcon.ResetBalloonCloseTimer();
158
      }
159
  
160
  
161
      /// <summary>
162
      /// Closes the popup once the fade-out animation completed.
163
      /// The animation was triggered in XAML through the attached
164
      /// BalloonClosing event.
165
      /// </summary>
166
      private void OnFadeOutCompleted(object sender, EventArgs e)
167
      {
168
        Popup pp = (Popup)Parent;
169
        pp.IsOpen = false;
170
      }
171

    
172
      private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
173
      {
174
          CloseBalloon();
175
          if (ClickAction!= null)
176
          {
177
              ClickAction();
178
          }          
179
          
180
      }
181

    
182
      public Action ClickAction { get; set; }
183
   }
184
}