1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/notifmsgg.cpp
3 // Purpose: generic implementation of wxGenericNotificationMessage
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 // ============================================================================
12 // ============================================================================
14 // ----------------------------------------------------------------------------
16 // ----------------------------------------------------------------------------
18 // for compilers that support precompilation, includes "wx.h".
19 #include "wx/wxprec.h"
25 #ifndef wxUSE_LIBHILDON
26 #define wxUSE_LIBHILDON 0
29 #ifndef wxUSE_LIBHILDON2
30 #define wxUSE_LIBHILDON2 0
33 #if wxUSE_NOTIFICATION_MESSAGE && (!wxUSE_LIBHILDON || !wxUSE_LIBHILDON2)
36 #include "wx/dialog.h"
39 #include "wx/statbmp.h"
42 #include "wx/artprov.h"
44 // even if the platform has the native implementation, we still normally want
45 // to use the generic one (unless it's totally unsuitable for the target UI as
46 // is the case of Hildon) because it may provide more features, so include
47 // wx/generic/notifmsg.h to get wxGenericNotificationMessage declaration even
48 // if wx/notifmsg.h only declares wxNotificationMessage itself (if it already
49 // uses the generic version, the second inclusion will do no harm)
50 #include "wx/notifmsg.h"
51 #include "wx/generic/notifmsg.h"
53 // ----------------------------------------------------------------------------
54 // wxNotificationMessageDialog
55 // ----------------------------------------------------------------------------
57 class wxNotificationMessageDialog
: public wxDialog
60 wxNotificationMessageDialog(wxWindow
*parent
,
65 void Set(wxWindow
*parent
,
70 bool IsAutomatic() const { return m_timer
.IsRunning(); }
71 void SetDeleteOnHide() { m_deleteOnHide
= true; }
74 void OnClose(wxCloseEvent
& event
);
75 void OnTimer(wxTimerEvent
& event
);
77 // if true, delete the dialog when it should disappear, otherwise just hide
78 // it (initially false)
81 // timer which will hide this dialog when it expires, if it's not running
82 // it means we were created without timeout
87 wxDECLARE_NO_COPY_CLASS(wxNotificationMessageDialog
);
90 // ============================================================================
91 // wxNotificationMessageDialog implementation
92 // ============================================================================
94 BEGIN_EVENT_TABLE(wxNotificationMessageDialog
, wxDialog
)
95 EVT_CLOSE(wxNotificationMessageDialog::OnClose
)
97 EVT_TIMER(wxID_ANY
, wxNotificationMessageDialog::OnTimer
)
100 wxNotificationMessageDialog::wxNotificationMessageDialog(wxWindow
*parent
,
101 const wxString
& text
,
104 : wxDialog(parent
, wxID_ANY
, _("Notice"),
105 wxDefaultPosition
, wxDefaultSize
,
106 0 /* no caption, no border styles */),
109 m_deleteOnHide
= false;
111 Set(parent
, text
, timeout
, flags
);
115 wxNotificationMessageDialog::Set(wxWindow
* WXUNUSED(parent
),
116 const wxString
& text
,
120 wxSizer
* const sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
121 if ( flags
& wxICON_MASK
)
123 sizerTop
->Add(new wxStaticBitmap
127 wxArtProvider::GetMessageBoxIcon(flags
)
129 wxSizerFlags().Centre().Border());
132 sizerTop
->Add(CreateTextSizer(text
), wxSizerFlags(1).Border());
133 SetSizerAndFit(sizerTop
);
135 if ( timeout
!= wxGenericNotificationMessage::Timeout_Never
)
137 // wxTimer uses ms, timeout is in seconds
138 m_timer
.Start(timeout
*1000, true /* one shot only */);
140 else if ( m_timer
.IsRunning() )
146 void wxNotificationMessageDialog::OnClose(wxCloseEvent
& event
)
148 if ( m_deleteOnHide
)
150 // we don't need to keep this dialog alive any more
153 else // don't really close, just hide, as we can be shown again later
161 void wxNotificationMessageDialog::OnTimer(wxTimerEvent
& WXUNUSED(event
))
163 if ( m_deleteOnHide
)
169 // ============================================================================
170 // wxGenericNotificationMessage implementation
171 // ============================================================================
173 int wxGenericNotificationMessage::ms_timeout
= 10;
175 /* static */ void wxGenericNotificationMessage::SetDefaultTimeout(int timeout
)
177 wxASSERT_MSG( timeout
> 0,
178 "negative or zero default timeout doesn't make sense" );
180 ms_timeout
= timeout
;
183 void wxGenericNotificationMessage::Init()
188 wxGenericNotificationMessage::~wxGenericNotificationMessage()
190 if ( m_dialog
->IsAutomatic() )
192 // we want to allow the user to create an automatically hidden
193 // notification just by creating a local wxGenericNotificationMessage object
194 // and so we shouldn't hide the notification when this object goes out
196 m_dialog
->SetDeleteOnHide();
198 else // manual dialog, hide it immediately
200 // OTOH for permanently shown dialogs only the code can hide them and
201 // if the object is deleted, we must do it now as it won't be
202 // accessible programmatically any more
207 bool wxGenericNotificationMessage::Show(int timeout
)
209 if ( timeout
== Timeout_Auto
)
211 timeout
= GetDefaultTimeout();
216 m_dialog
= new wxNotificationMessageDialog
224 else // update the existing dialog
226 m_dialog
->Set(GetParent(), GetFullMessage(), timeout
, GetFlags());
234 bool wxGenericNotificationMessage::Close()
244 #endif // wxUSE_NOTIFICATION_MESSAGE && (!wxUSE_LIBHILDON || !wxUSE_LIBHILDON2)