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 // even if the platform has the native implementation, we still normally want
38 // to use the generic one (unless it's totally unsuitable for the target UI as
39 // is the case of Hildon) because it may provide more features, so include
40 // wx/generic/notifmsg.h to get wxGenericNotificationMessage declaration even
41 // if wx/notifmsg.h only declares wxNotificationMessage itself (if it already
42 // uses the generic version, the second inclusion will do no harm)
43 #include "wx/notifmsg.h"
44 #include "wx/generic/notifmsg.h"
46 // ----------------------------------------------------------------------------
47 // wxNotificationMessageDialog
48 // ----------------------------------------------------------------------------
50 class wxNotificationMessageDialog
: public wxDialog
53 wxNotificationMessageDialog(wxWindow
*parent
,
57 void Set(wxWindow
*parent
,
61 bool IsAutomatic() const { return m_timer
.IsRunning(); }
62 void SetDeleteOnHide() { m_deleteOnHide
= true; }
65 void OnClose(wxCloseEvent
& event
);
66 void OnTimer(wxTimerEvent
& event
);
68 // if true, delete the dialog when it should disappear, otherwise just hide
69 // it (initially false)
72 // timer which will hide this dialog when it expires, if it's not running
73 // it means we were created without timeout
78 DECLARE_NO_COPY_CLASS(wxNotificationMessageDialog
)
81 // ============================================================================
82 // wxNotificationMessageDialog implementation
83 // ============================================================================
85 BEGIN_EVENT_TABLE(wxNotificationMessageDialog
, wxDialog
)
86 EVT_CLOSE(wxNotificationMessageDialog::OnClose
)
88 EVT_TIMER(wxID_ANY
, wxNotificationMessageDialog::OnTimer
)
91 wxNotificationMessageDialog::wxNotificationMessageDialog(wxWindow
*parent
,
94 : wxDialog(parent
, wxID_ANY
, _("Notice"),
95 wxDefaultPosition
, wxDefaultSize
,
96 0 /* no caption, no border styles */),
99 m_deleteOnHide
= false;
101 Set(parent
, text
, timeout
);
105 wxNotificationMessageDialog::Set(wxWindow
* WXUNUSED(parent
),
106 const wxString
& text
,
109 wxSizer
*sizer
= CreateTextSizer(text
);
110 SetSizerAndFit(sizer
);
112 if ( timeout
!= wxGenericNotificationMessage::Timeout_Never
)
114 // wxTimer uses ms, timeout is in seconds
115 m_timer
.Start(timeout
*1000, true /* one shot only */);
117 else if ( m_timer
.IsRunning() )
123 void wxNotificationMessageDialog::OnClose(wxCloseEvent
& event
)
125 if ( m_deleteOnHide
)
127 // we don't need to keep this dialog alive any more
130 else // don't really close, just hide, as we can be shown again later
138 void wxNotificationMessageDialog::OnTimer(wxTimerEvent
& WXUNUSED(event
))
140 if ( m_deleteOnHide
)
146 // ============================================================================
147 // wxGenericNotificationMessage implementation
148 // ============================================================================
150 int wxGenericNotificationMessage::ms_timeout
= 10;
152 /* static */ void wxGenericNotificationMessage::SetDefaultTimeout(int timeout
)
154 wxASSERT_MSG( timeout
> 0,
155 "negative or zero default timeout doesn't make sense" );
157 ms_timeout
= timeout
;
160 void wxGenericNotificationMessage::Init()
165 wxGenericNotificationMessage::~wxGenericNotificationMessage()
167 if ( m_dialog
->IsAutomatic() )
169 // we want to allow the user to create an automatically hidden
170 // notification just by creating a local wxGenericNotificationMessage object
171 // and so we shouldn't hide the notification when this object goes out
173 m_dialog
->SetDeleteOnHide();
175 else // manual dialog, hide it immediately
177 // OTOH for permanently shown dialogs only the code can hide them and
178 // if the object is deleted, we must do it now as it won't be
179 // accessible programmatically any more
184 bool wxGenericNotificationMessage::Show(int timeout
)
186 if ( timeout
== Timeout_Auto
)
188 timeout
= GetDefaultTimeout();
193 m_dialog
= new wxNotificationMessageDialog
200 else // update the existing dialog
202 m_dialog
->Set(GetParent(), GetFullMessage(), timeout
);
210 bool wxGenericNotificationMessage::Close()
220 #endif // wxUSE_NOTIFICATION_MESSAGE && !wxUSE_LIBHILDON