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 #ifndef wxUSE_LIBHILDON2
31 #define wxUSE_LIBHILDON2 0
34 #if wxUSE_NOTIFICATION_MESSAGE && (!wxUSE_LIBHILDON || !wxUSE_LIBHILDON2)
37 #include "wx/dialog.h"
40 #include "wx/statbmp.h"
43 #include "wx/artprov.h"
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"
54 // ----------------------------------------------------------------------------
55 // wxNotificationMessageDialog
56 // ----------------------------------------------------------------------------
58 class wxNotificationMessageDialog
: public wxDialog
61 wxNotificationMessageDialog(wxWindow
*parent
,
66 void Set(wxWindow
*parent
,
71 bool IsAutomatic() const { return m_timer
.IsRunning(); }
72 void SetDeleteOnHide() { m_deleteOnHide
= true; }
75 void OnClose(wxCloseEvent
& event
);
76 void OnTimer(wxTimerEvent
& event
);
78 // if true, delete the dialog when it should disappear, otherwise just hide
79 // it (initially false)
82 // timer which will hide this dialog when it expires, if it's not running
83 // it means we were created without timeout
88 wxDECLARE_NO_COPY_CLASS(wxNotificationMessageDialog
);
91 // ============================================================================
92 // wxNotificationMessageDialog implementation
93 // ============================================================================
95 BEGIN_EVENT_TABLE(wxNotificationMessageDialog
, wxDialog
)
96 EVT_CLOSE(wxNotificationMessageDialog::OnClose
)
98 EVT_TIMER(wxID_ANY
, wxNotificationMessageDialog::OnTimer
)
101 wxNotificationMessageDialog::wxNotificationMessageDialog(wxWindow
*parent
,
102 const wxString
& text
,
105 : wxDialog(parent
, wxID_ANY
, _("Notice"),
106 wxDefaultPosition
, wxDefaultSize
,
107 0 /* no caption, no border styles */),
110 m_deleteOnHide
= false;
112 Set(parent
, text
, timeout
, flags
);
116 wxNotificationMessageDialog::Set(wxWindow
* WXUNUSED(parent
),
117 const wxString
& text
,
121 wxSizer
* const sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
122 if ( flags
& wxICON_MASK
)
124 sizerTop
->Add(new wxStaticBitmap
128 wxArtProvider::GetMessageBoxIcon(flags
)
130 wxSizerFlags().Centre().Border());
133 sizerTop
->Add(CreateTextSizer(text
), wxSizerFlags(1).Border());
134 SetSizerAndFit(sizerTop
);
136 if ( timeout
!= wxGenericNotificationMessage::Timeout_Never
)
138 // wxTimer uses ms, timeout is in seconds
139 m_timer
.Start(timeout
*1000, true /* one shot only */);
141 else if ( m_timer
.IsRunning() )
147 void wxNotificationMessageDialog::OnClose(wxCloseEvent
& event
)
149 if ( m_deleteOnHide
)
151 // we don't need to keep this dialog alive any more
154 else // don't really close, just hide, as we can be shown again later
162 void wxNotificationMessageDialog::OnTimer(wxTimerEvent
& WXUNUSED(event
))
164 if ( m_deleteOnHide
)
170 // ============================================================================
171 // wxGenericNotificationMessage implementation
172 // ============================================================================
174 int wxGenericNotificationMessage::ms_timeout
= 10;
176 /* static */ void wxGenericNotificationMessage::SetDefaultTimeout(int timeout
)
178 wxASSERT_MSG( timeout
> 0,
179 "negative or zero default timeout doesn't make sense" );
181 ms_timeout
= timeout
;
184 void wxGenericNotificationMessage::Init()
189 wxGenericNotificationMessage::~wxGenericNotificationMessage()
191 if ( m_dialog
->IsAutomatic() )
193 // we want to allow the user to create an automatically hidden
194 // notification just by creating a local wxGenericNotificationMessage object
195 // and so we shouldn't hide the notification when this object goes out
197 m_dialog
->SetDeleteOnHide();
199 else // manual dialog, hide it immediately
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
208 bool wxGenericNotificationMessage::Show(int timeout
)
210 if ( timeout
== Timeout_Auto
)
212 timeout
= GetDefaultTimeout();
217 m_dialog
= new wxNotificationMessageDialog
225 else // update the existing dialog
227 m_dialog
->Set(GetParent(), GetFullMessage(), timeout
, GetFlags());
235 bool wxGenericNotificationMessage::Close()
245 #endif // wxUSE_NOTIFICATION_MESSAGE && (!wxUSE_LIBHILDON || !wxUSE_LIBHILDON2)