1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/notifmsgg.cpp
3 // Purpose: generic implementation of wxNotificationMessage
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 // include this before the test below, wxUSE_GENERIC_NOTIFICATION_MESSAGE is
27 // defined in this header
28 #include "wx/notifmsg.h"
30 #if wxUSE_GENERIC_NOTIFICATION_MESSAGE
33 #include "wx/dialog.h"
37 // ----------------------------------------------------------------------------
38 // wxNotificationMessageDialog
39 // ----------------------------------------------------------------------------
41 class wxNotificationMessageDialog
: public wxDialog
44 wxNotificationMessageDialog(wxWindow
*parent
,
48 void Set(wxWindow
*parent
,
52 bool IsAutomatic() const { return m_timer
.IsRunning(); }
53 void SetDeleteOnHide() { m_deleteOnHide
= true; }
56 void OnClose(wxCloseEvent
& event
);
57 void OnTimer(wxTimerEvent
& event
);
59 // if true, delete the dialog when it should disappear, otherwise just hide
60 // it (initially false)
63 // timer which will hide this dialog when it expires, if it's not running
64 // it means we were created without timeout
69 DECLARE_NO_COPY_CLASS(wxNotificationMessageDialog
)
72 // ============================================================================
73 // wxNotificationMessageDialog implementation
74 // ============================================================================
76 BEGIN_EVENT_TABLE(wxNotificationMessageDialog
, wxDialog
)
77 EVT_CLOSE(wxNotificationMessageDialog::OnClose
)
79 EVT_TIMER(wxID_ANY
, wxNotificationMessageDialog::OnTimer
)
82 wxNotificationMessageDialog::wxNotificationMessageDialog(wxWindow
*parent
,
85 : wxDialog(parent
, wxID_ANY
, _("Notice"),
86 wxDefaultPosition
, wxDefaultSize
,
87 0 /* no caption, no border styles */),
90 m_deleteOnHide
= false;
92 Set(parent
, text
, timeout
);
96 wxNotificationMessageDialog::Set(wxWindow
* WXUNUSED(parent
),
100 wxSizer
*sizer
= CreateTextSizer(text
);
101 SetSizerAndFit(sizer
);
103 if ( timeout
!= wxNotificationMessage::Timeout_Never
)
105 // wxTimer uses ms, timeout is in seconds
106 m_timer
.Start(timeout
*1000, true /* one shot only */);
108 else if ( m_timer
.IsRunning() )
114 void wxNotificationMessageDialog::OnClose(wxCloseEvent
& event
)
116 if ( m_deleteOnHide
)
118 // we don't need to keep this dialog alive any more
121 else // don't really close, just hide, as we can be shown again later
129 void wxNotificationMessageDialog::OnTimer(wxTimerEvent
& WXUNUSED(event
))
131 if ( m_deleteOnHide
)
137 // ============================================================================
138 // wxNotificationMessage implementation
139 // ============================================================================
141 int wxNotificationMessage::ms_timeout
= 10;
143 /* static */ void wxNotificationMessage::SetDefaultTimeout(int timeout
)
145 wxASSERT_MSG( timeout
> 0,
146 "negative or zero default timeout doesn't make sense" );
148 ms_timeout
= timeout
;
151 void wxNotificationMessage::Init()
156 wxNotificationMessage::~wxNotificationMessage()
158 if ( m_dialog
->IsAutomatic() )
160 // we want to allow the user to create an automatically hidden
161 // notification just by creating a local wxNotificationMessage object
162 // and so we shouldn't hide the notification when this object goes out
164 m_dialog
->SetDeleteOnHide();
166 else // manual dialog, hide it immediately
168 // OTOH for permanently shown dialogs only the code can hide them and
169 // if the object is deleted, we must do it now as it won't be
170 // accessible programmatically any more
175 bool wxNotificationMessage::Show(int timeout
)
177 if ( timeout
== Timeout_Auto
)
179 timeout
= GetDefaultTimeout();
184 m_dialog
= new wxNotificationMessageDialog
191 else // update the existing dialog
193 m_dialog
->Set(GetParent(), GetFullMessage(), timeout
);
201 bool wxNotificationMessage::Close()
211 #endif // wxUSE_GENERIC_NOTIFICATION_MESSAGE