]> git.saurik.com Git - wxWidgets.git/blame - src/generic/notifmsgg.cpp
Changed the procedure for writing a comment to a GIF image.
[wxWidgets.git] / src / generic / notifmsgg.cpp
CommitLineData
e36a1739
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: src/generic/notifmsgg.cpp
e2d5abbf 3// Purpose: generic implementation of wxGenericNotificationMessage
e36a1739
VZ
4// Author: Vadim Zeitlin
5// Created: 2007-11-24
6// RCS-ID: $Id$
7// Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
8// Licence: wxWindows licence
9///////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
19// for compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
e2d5abbf
VZ
26#ifndef wxUSE_LIBHILDON
27 #define wxUSE_LIBHILDON 0
28#endif
e36a1739 29
426d19f1
JS
30#ifndef wxUSE_LIBHILDON2
31 #define wxUSE_LIBHILDON2 0
32#endif
33
34#if wxUSE_NOTIFICATION_MESSAGE && (!wxUSE_LIBHILDON || !wxUSE_LIBHILDON2)
e36a1739
VZ
35
36#ifndef WX_PRECOMP
37 #include "wx/dialog.h"
38 #include "wx/timer.h"
aa71af91
PC
39 #include "wx/sizer.h"
40 #include "wx/statbmp.h"
e36a1739
VZ
41#endif //WX_PRECOMP
42
e5dbea49
VZ
43#include "wx/artprov.h"
44
e2d5abbf
VZ
45// even if the platform has the native implementation, we still normally want
46// to use the generic one (unless it's totally unsuitable for the target UI as
47// is the case of Hildon) because it may provide more features, so include
48// wx/generic/notifmsg.h to get wxGenericNotificationMessage declaration even
49// if wx/notifmsg.h only declares wxNotificationMessage itself (if it already
50// uses the generic version, the second inclusion will do no harm)
51#include "wx/notifmsg.h"
52#include "wx/generic/notifmsg.h"
53
e36a1739
VZ
54// ----------------------------------------------------------------------------
55// wxNotificationMessageDialog
56// ----------------------------------------------------------------------------
57
58class wxNotificationMessageDialog : public wxDialog
59{
60public:
61 wxNotificationMessageDialog(wxWindow *parent,
62 const wxString& text,
e5dbea49
VZ
63 int timeout,
64 int flags);
e36a1739
VZ
65
66 void Set(wxWindow *parent,
67 const wxString& text,
e5dbea49
VZ
68 int timeout,
69 int flags);
e36a1739
VZ
70
71 bool IsAutomatic() const { return m_timer.IsRunning(); }
72 void SetDeleteOnHide() { m_deleteOnHide = true; }
73
74private:
75 void OnClose(wxCloseEvent& event);
76 void OnTimer(wxTimerEvent& event);
77
78 // if true, delete the dialog when it should disappear, otherwise just hide
79 // it (initially false)
80 bool m_deleteOnHide;
81
82 // timer which will hide this dialog when it expires, if it's not running
83 // it means we were created without timeout
84 wxTimer m_timer;
85
86
87 DECLARE_EVENT_TABLE()
c0c133e1 88 wxDECLARE_NO_COPY_CLASS(wxNotificationMessageDialog);
e36a1739
VZ
89};
90
91// ============================================================================
92// wxNotificationMessageDialog implementation
93// ============================================================================
94
95BEGIN_EVENT_TABLE(wxNotificationMessageDialog, wxDialog)
96 EVT_CLOSE(wxNotificationMessageDialog::OnClose)
97
98 EVT_TIMER(wxID_ANY, wxNotificationMessageDialog::OnTimer)
99END_EVENT_TABLE()
100
101wxNotificationMessageDialog::wxNotificationMessageDialog(wxWindow *parent,
102 const wxString& text,
e5dbea49
VZ
103 int timeout,
104 int flags)
e36a1739
VZ
105 : wxDialog(parent, wxID_ANY, _("Notice"),
106 wxDefaultPosition, wxDefaultSize,
107 0 /* no caption, no border styles */),
108 m_timer(this)
109{
110 m_deleteOnHide = false;
111
e5dbea49 112 Set(parent, text, timeout, flags);
e36a1739
VZ
113}
114
115void
116wxNotificationMessageDialog::Set(wxWindow * WXUNUSED(parent),
117 const wxString& text,
e5dbea49
VZ
118 int timeout,
119 int flags)
e36a1739 120{
e5dbea49
VZ
121 wxSizer * const sizerTop = new wxBoxSizer(wxHORIZONTAL);
122 if ( flags & wxICON_MASK )
123 {
124 sizerTop->Add(new wxStaticBitmap
125 (
126 this,
127 wxID_ANY,
128 wxArtProvider::GetMessageBoxIcon(flags)
129 ),
130 wxSizerFlags().Centre().Border());
131 }
132
133 sizerTop->Add(CreateTextSizer(text), wxSizerFlags(1).Border());
134 SetSizerAndFit(sizerTop);
e36a1739 135
e2d5abbf 136 if ( timeout != wxGenericNotificationMessage::Timeout_Never )
e36a1739
VZ
137 {
138 // wxTimer uses ms, timeout is in seconds
139 m_timer.Start(timeout*1000, true /* one shot only */);
140 }
141 else if ( m_timer.IsRunning() )
142 {
143 m_timer.Stop();
144 }
145}
146
147void wxNotificationMessageDialog::OnClose(wxCloseEvent& event)
148{
149 if ( m_deleteOnHide )
150 {
151 // we don't need to keep this dialog alive any more
152 Destroy();
153 }
154 else // don't really close, just hide, as we can be shown again later
155 {
156 event.Veto();
157
158 Hide();
159 }
160}
161
162void wxNotificationMessageDialog::OnTimer(wxTimerEvent& WXUNUSED(event))
163{
164 if ( m_deleteOnHide )
165 Destroy();
166 else
167 Hide();
168}
169
170// ============================================================================
e2d5abbf 171// wxGenericNotificationMessage implementation
e36a1739
VZ
172// ============================================================================
173
e2d5abbf 174int wxGenericNotificationMessage::ms_timeout = 10;
e36a1739 175
e2d5abbf 176/* static */ void wxGenericNotificationMessage::SetDefaultTimeout(int timeout)
e36a1739
VZ
177{
178 wxASSERT_MSG( timeout > 0,
179 "negative or zero default timeout doesn't make sense" );
180
181 ms_timeout = timeout;
182}
183
e2d5abbf 184void wxGenericNotificationMessage::Init()
e36a1739
VZ
185{
186 m_dialog = NULL;
187}
188
e2d5abbf 189wxGenericNotificationMessage::~wxGenericNotificationMessage()
e36a1739
VZ
190{
191 if ( m_dialog->IsAutomatic() )
192 {
193 // we want to allow the user to create an automatically hidden
e2d5abbf 194 // notification just by creating a local wxGenericNotificationMessage object
e36a1739
VZ
195 // and so we shouldn't hide the notification when this object goes out
196 // of scope
197 m_dialog->SetDeleteOnHide();
198 }
199 else // manual dialog, hide it immediately
200 {
201 // OTOH for permanently shown dialogs only the code can hide them and
202 // if the object is deleted, we must do it now as it won't be
203 // accessible programmatically any more
204 delete m_dialog;
205 }
206}
207
e2d5abbf 208bool wxGenericNotificationMessage::Show(int timeout)
e36a1739
VZ
209{
210 if ( timeout == Timeout_Auto )
211 {
212 timeout = GetDefaultTimeout();
213 }
214
215 if ( !m_dialog )
216 {
217 m_dialog = new wxNotificationMessageDialog
218 (
219 GetParent(),
220 GetFullMessage(),
e5dbea49
VZ
221 timeout,
222 GetFlags()
e36a1739
VZ
223 );
224 }
225 else // update the existing dialog
226 {
e5dbea49 227 m_dialog->Set(GetParent(), GetFullMessage(), timeout, GetFlags());
e36a1739
VZ
228 }
229
230 m_dialog->Show();
231
232 return true;
233}
234
e2d5abbf 235bool wxGenericNotificationMessage::Close()
e36a1739
VZ
236{
237 if ( !m_dialog )
238 return false;
239
240 m_dialog->Hide();
241
242 return true;
243}
244
426d19f1 245#endif // wxUSE_NOTIFICATION_MESSAGE && (!wxUSE_LIBHILDON || !wxUSE_LIBHILDON2)