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"
36 #include "wx/statbmp.h"
39 #include "wx/artprov.h"
41 // even if the platform has the native implementation, we still normally want
42 // to use the generic one (unless it's totally unsuitable for the target UI as
43 // is the case of Hildon) because it may provide more features, so include
44 // wx/generic/notifmsg.h to get wxGenericNotificationMessage declaration even
45 // if wx/notifmsg.h only declares wxNotificationMessage itself (if it already
46 // uses the generic version, the second inclusion will do no harm)
47 #include "wx/notifmsg.h"
48 #include "wx/generic/notifmsg.h"
50 // ----------------------------------------------------------------------------
51 // wxNotificationMessageDialog
52 // ----------------------------------------------------------------------------
54 class wxNotificationMessageDialog
: public wxDialog
57 wxNotificationMessageDialog(wxWindow
*parent
,
62 void Set(wxWindow
*parent
,
67 bool IsAutomatic() const { return m_timer
.IsRunning(); }
68 void SetDeleteOnHide() { m_deleteOnHide
= true; }
71 void OnClose(wxCloseEvent
& event
);
72 void OnTimer(wxTimerEvent
& event
);
74 // if true, delete the dialog when it should disappear, otherwise just hide
75 // it (initially false)
78 // timer which will hide this dialog when it expires, if it's not running
79 // it means we were created without timeout
84 wxDECLARE_NO_COPY_CLASS(wxNotificationMessageDialog
);
87 // ============================================================================
88 // wxNotificationMessageDialog implementation
89 // ============================================================================
91 BEGIN_EVENT_TABLE(wxNotificationMessageDialog
, wxDialog
)
92 EVT_CLOSE(wxNotificationMessageDialog::OnClose
)
94 EVT_TIMER(wxID_ANY
, wxNotificationMessageDialog::OnTimer
)
97 wxNotificationMessageDialog::wxNotificationMessageDialog(wxWindow
*parent
,
101 : wxDialog(parent
, wxID_ANY
, _("Notice"),
102 wxDefaultPosition
, wxDefaultSize
,
103 0 /* no caption, no border styles */),
106 m_deleteOnHide
= false;
108 Set(parent
, text
, timeout
, flags
);
112 wxNotificationMessageDialog::Set(wxWindow
* WXUNUSED(parent
),
113 const wxString
& text
,
117 wxSizer
* const sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
118 if ( flags
& wxICON_MASK
)
120 sizerTop
->Add(new wxStaticBitmap
124 wxArtProvider::GetMessageBoxIcon(flags
)
126 wxSizerFlags().Centre().Border());
129 sizerTop
->Add(CreateTextSizer(text
), wxSizerFlags(1).Border());
130 SetSizerAndFit(sizerTop
);
132 if ( timeout
!= wxGenericNotificationMessage::Timeout_Never
)
134 // wxTimer uses ms, timeout is in seconds
135 m_timer
.Start(timeout
*1000, true /* one shot only */);
137 else if ( m_timer
.IsRunning() )
143 void wxNotificationMessageDialog::OnClose(wxCloseEvent
& event
)
145 if ( m_deleteOnHide
)
147 // we don't need to keep this dialog alive any more
150 else // don't really close, just hide, as we can be shown again later
158 void wxNotificationMessageDialog::OnTimer(wxTimerEvent
& WXUNUSED(event
))
160 if ( m_deleteOnHide
)
166 // ============================================================================
167 // wxGenericNotificationMessage implementation
168 // ============================================================================
170 int wxGenericNotificationMessage::ms_timeout
= 10;
172 /* static */ void wxGenericNotificationMessage::SetDefaultTimeout(int timeout
)
174 wxASSERT_MSG( timeout
> 0,
175 "negative or zero default timeout doesn't make sense" );
177 ms_timeout
= timeout
;
180 void wxGenericNotificationMessage::Init()
185 wxGenericNotificationMessage::~wxGenericNotificationMessage()
187 if ( m_dialog
->IsAutomatic() )
189 // we want to allow the user to create an automatically hidden
190 // notification just by creating a local wxGenericNotificationMessage object
191 // and so we shouldn't hide the notification when this object goes out
193 m_dialog
->SetDeleteOnHide();
195 else // manual dialog, hide it immediately
197 // OTOH for permanently shown dialogs only the code can hide them and
198 // if the object is deleted, we must do it now as it won't be
199 // accessible programmatically any more
204 bool wxGenericNotificationMessage::Show(int timeout
)
206 if ( timeout
== Timeout_Auto
)
208 timeout
= GetDefaultTimeout();
213 m_dialog
= new wxNotificationMessageDialog
221 else // update the existing dialog
223 m_dialog
->Set(GetParent(), GetFullMessage(), timeout
, GetFlags());
231 bool wxGenericNotificationMessage::Close()
241 #endif // wxUSE_NOTIFICATION_MESSAGE && !wxUSE_LIBHILDON