1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/notifmsgg.cpp
3 // Purpose: generic implementation of wxGenericNotificationMessage
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
26 #ifndef wxUSE_LIBHILDON
27 #define wxUSE_LIBHILDON 0
30 #if wxUSE_NOTIFICATION_MESSAGE && !wxUSE_LIBHILDON
33 #include "wx/dialog.h"
37 #include "wx/artprov.h"
39 // even if the platform has the native implementation, we still normally want
40 // to use the generic one (unless it's totally unsuitable for the target UI as
41 // is the case of Hildon) because it may provide more features, so include
42 // wx/generic/notifmsg.h to get wxGenericNotificationMessage declaration even
43 // if wx/notifmsg.h only declares wxNotificationMessage itself (if it already
44 // uses the generic version, the second inclusion will do no harm)
45 #include "wx/notifmsg.h"
46 #include "wx/generic/notifmsg.h"
48 // ----------------------------------------------------------------------------
49 // wxNotificationMessageDialog
50 // ----------------------------------------------------------------------------
52 class wxNotificationMessageDialog
: public wxDialog
55 wxNotificationMessageDialog(wxWindow
*parent
,
60 void Set(wxWindow
*parent
,
65 bool IsAutomatic() const { return m_timer
.IsRunning(); }
66 void SetDeleteOnHide() { m_deleteOnHide
= true; }
69 void OnClose(wxCloseEvent
& event
);
70 void OnTimer(wxTimerEvent
& event
);
72 // if true, delete the dialog when it should disappear, otherwise just hide
73 // it (initially false)
76 // timer which will hide this dialog when it expires, if it's not running
77 // it means we were created without timeout
82 DECLARE_NO_COPY_CLASS(wxNotificationMessageDialog
)
85 // ============================================================================
86 // wxNotificationMessageDialog implementation
87 // ============================================================================
89 BEGIN_EVENT_TABLE(wxNotificationMessageDialog
, wxDialog
)
90 EVT_CLOSE(wxNotificationMessageDialog::OnClose
)
92 EVT_TIMER(wxID_ANY
, wxNotificationMessageDialog::OnTimer
)
95 wxNotificationMessageDialog::wxNotificationMessageDialog(wxWindow
*parent
,
99 : wxDialog(parent
, wxID_ANY
, _("Notice"),
100 wxDefaultPosition
, wxDefaultSize
,
101 0 /* no caption, no border styles */),
104 m_deleteOnHide
= false;
106 Set(parent
, text
, timeout
, flags
);
110 wxNotificationMessageDialog::Set(wxWindow
* WXUNUSED(parent
),
111 const wxString
& text
,
115 wxSizer
* const sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
116 if ( flags
& wxICON_MASK
)
118 sizerTop
->Add(new wxStaticBitmap
122 wxArtProvider::GetMessageBoxIcon(flags
)
124 wxSizerFlags().Centre().Border());
127 sizerTop
->Add(CreateTextSizer(text
), wxSizerFlags(1).Border());
128 SetSizerAndFit(sizerTop
);
130 if ( timeout
!= wxGenericNotificationMessage::Timeout_Never
)
132 // wxTimer uses ms, timeout is in seconds
133 m_timer
.Start(timeout
*1000, true /* one shot only */);
135 else if ( m_timer
.IsRunning() )
141 void wxNotificationMessageDialog::OnClose(wxCloseEvent
& event
)
143 if ( m_deleteOnHide
)
145 // we don't need to keep this dialog alive any more
148 else // don't really close, just hide, as we can be shown again later
156 void wxNotificationMessageDialog::OnTimer(wxTimerEvent
& WXUNUSED(event
))
158 if ( m_deleteOnHide
)
164 // ============================================================================
165 // wxGenericNotificationMessage implementation
166 // ============================================================================
168 int wxGenericNotificationMessage::ms_timeout
= 10;
170 /* static */ void wxGenericNotificationMessage::SetDefaultTimeout(int timeout
)
172 wxASSERT_MSG( timeout
> 0,
173 "negative or zero default timeout doesn't make sense" );
175 ms_timeout
= timeout
;
178 void wxGenericNotificationMessage::Init()
183 wxGenericNotificationMessage::~wxGenericNotificationMessage()
185 if ( m_dialog
->IsAutomatic() )
187 // we want to allow the user to create an automatically hidden
188 // notification just by creating a local wxGenericNotificationMessage object
189 // and so we shouldn't hide the notification when this object goes out
191 m_dialog
->SetDeleteOnHide();
193 else // manual dialog, hide it immediately
195 // OTOH for permanently shown dialogs only the code can hide them and
196 // if the object is deleted, we must do it now as it won't be
197 // accessible programmatically any more
202 bool wxGenericNotificationMessage::Show(int timeout
)
204 if ( timeout
== Timeout_Auto
)
206 timeout
= GetDefaultTimeout();
211 m_dialog
= new wxNotificationMessageDialog
219 else // update the existing dialog
221 m_dialog
->Set(GetParent(), GetFullMessage(), timeout
, GetFlags());
229 bool wxGenericNotificationMessage::Close()
239 #endif // wxUSE_NOTIFICATION_MESSAGE && !wxUSE_LIBHILDON