]> git.saurik.com Git - wxWidgets.git/blame - src/generic/notifmsgg.cpp
Improve drawing of the tree item buttons in the generic renderer.
[wxWidgets.git] / src / generic / notifmsgg.cpp
CommitLineData
e36a1739
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: src/generic/notifmsgg.cpp
e2d5abbf 3// Purpose: generic implementation of wxGenericNotificationMessage
e36a1739
VZ
4// Author: Vadim Zeitlin
5// Created: 2007-11-24
e36a1739
VZ
6// Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
7// Licence: wxWindows licence
8///////////////////////////////////////////////////////////////////////////////
9
10// ============================================================================
11// declarations
12// ============================================================================
13
14// ----------------------------------------------------------------------------
15// headers
16// ----------------------------------------------------------------------------
17
18// for compilers that support precompilation, includes "wx.h".
19#include "wx/wxprec.h"
20
21#ifdef __BORLANDC__
22 #pragma hdrstop
23#endif
24
e2d5abbf
VZ
25#ifndef wxUSE_LIBHILDON
26 #define wxUSE_LIBHILDON 0
27#endif
e36a1739 28
426d19f1
JS
29#ifndef wxUSE_LIBHILDON2
30 #define wxUSE_LIBHILDON2 0
31#endif
32
33#if wxUSE_NOTIFICATION_MESSAGE && (!wxUSE_LIBHILDON || !wxUSE_LIBHILDON2)
e36a1739
VZ
34
35#ifndef WX_PRECOMP
36 #include "wx/dialog.h"
37 #include "wx/timer.h"
aa71af91
PC
38 #include "wx/sizer.h"
39 #include "wx/statbmp.h"
e36a1739
VZ
40#endif //WX_PRECOMP
41
e5dbea49
VZ
42#include "wx/artprov.h"
43
e2d5abbf
VZ
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"
52
e36a1739
VZ
53// ----------------------------------------------------------------------------
54// wxNotificationMessageDialog
55// ----------------------------------------------------------------------------
56
57class wxNotificationMessageDialog : public wxDialog
58{
59public:
60 wxNotificationMessageDialog(wxWindow *parent,
61 const wxString& text,
e5dbea49
VZ
62 int timeout,
63 int flags);
e36a1739
VZ
64
65 void Set(wxWindow *parent,
66 const wxString& text,
e5dbea49
VZ
67 int timeout,
68 int flags);
e36a1739
VZ
69
70 bool IsAutomatic() const { return m_timer.IsRunning(); }
71 void SetDeleteOnHide() { m_deleteOnHide = true; }
72
73private:
74 void OnClose(wxCloseEvent& event);
75 void OnTimer(wxTimerEvent& event);
76
77 // if true, delete the dialog when it should disappear, otherwise just hide
78 // it (initially false)
79 bool m_deleteOnHide;
80
81 // timer which will hide this dialog when it expires, if it's not running
82 // it means we were created without timeout
83 wxTimer m_timer;
84
85
86 DECLARE_EVENT_TABLE()
c0c133e1 87 wxDECLARE_NO_COPY_CLASS(wxNotificationMessageDialog);
e36a1739
VZ
88};
89
90// ============================================================================
91// wxNotificationMessageDialog implementation
92// ============================================================================
93
94BEGIN_EVENT_TABLE(wxNotificationMessageDialog, wxDialog)
95 EVT_CLOSE(wxNotificationMessageDialog::OnClose)
96
97 EVT_TIMER(wxID_ANY, wxNotificationMessageDialog::OnTimer)
98END_EVENT_TABLE()
99
100wxNotificationMessageDialog::wxNotificationMessageDialog(wxWindow *parent,
101 const wxString& text,
e5dbea49
VZ
102 int timeout,
103 int flags)
e36a1739
VZ
104 : wxDialog(parent, wxID_ANY, _("Notice"),
105 wxDefaultPosition, wxDefaultSize,
106 0 /* no caption, no border styles */),
107 m_timer(this)
108{
109 m_deleteOnHide = false;
110
e5dbea49 111 Set(parent, text, timeout, flags);
e36a1739
VZ
112}
113
114void
115wxNotificationMessageDialog::Set(wxWindow * WXUNUSED(parent),
116 const wxString& text,
e5dbea49
VZ
117 int timeout,
118 int flags)
e36a1739 119{
e5dbea49
VZ
120 wxSizer * const sizerTop = new wxBoxSizer(wxHORIZONTAL);
121 if ( flags & wxICON_MASK )
122 {
123 sizerTop->Add(new wxStaticBitmap
124 (
125 this,
126 wxID_ANY,
127 wxArtProvider::GetMessageBoxIcon(flags)
128 ),
129 wxSizerFlags().Centre().Border());
130 }
131
132 sizerTop->Add(CreateTextSizer(text), wxSizerFlags(1).Border());
133 SetSizerAndFit(sizerTop);
e36a1739 134
e2d5abbf 135 if ( timeout != wxGenericNotificationMessage::Timeout_Never )
e36a1739
VZ
136 {
137 // wxTimer uses ms, timeout is in seconds
138 m_timer.Start(timeout*1000, true /* one shot only */);
139 }
140 else if ( m_timer.IsRunning() )
141 {
142 m_timer.Stop();
143 }
144}
145
146void wxNotificationMessageDialog::OnClose(wxCloseEvent& event)
147{
148 if ( m_deleteOnHide )
149 {
150 // we don't need to keep this dialog alive any more
151 Destroy();
152 }
153 else // don't really close, just hide, as we can be shown again later
154 {
155 event.Veto();
156
157 Hide();
158 }
159}
160
161void wxNotificationMessageDialog::OnTimer(wxTimerEvent& WXUNUSED(event))
162{
163 if ( m_deleteOnHide )
164 Destroy();
165 else
166 Hide();
167}
168
169// ============================================================================
e2d5abbf 170// wxGenericNotificationMessage implementation
e36a1739
VZ
171// ============================================================================
172
e2d5abbf 173int wxGenericNotificationMessage::ms_timeout = 10;
e36a1739 174
e2d5abbf 175/* static */ void wxGenericNotificationMessage::SetDefaultTimeout(int timeout)
e36a1739
VZ
176{
177 wxASSERT_MSG( timeout > 0,
178 "negative or zero default timeout doesn't make sense" );
179
180 ms_timeout = timeout;
181}
182
e2d5abbf 183void wxGenericNotificationMessage::Init()
e36a1739
VZ
184{
185 m_dialog = NULL;
186}
187
e2d5abbf 188wxGenericNotificationMessage::~wxGenericNotificationMessage()
e36a1739
VZ
189{
190 if ( m_dialog->IsAutomatic() )
191 {
192 // we want to allow the user to create an automatically hidden
e2d5abbf 193 // notification just by creating a local wxGenericNotificationMessage object
e36a1739
VZ
194 // and so we shouldn't hide the notification when this object goes out
195 // of scope
196 m_dialog->SetDeleteOnHide();
197 }
198 else // manual dialog, hide it immediately
199 {
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
203 delete m_dialog;
204 }
205}
206
e2d5abbf 207bool wxGenericNotificationMessage::Show(int timeout)
e36a1739
VZ
208{
209 if ( timeout == Timeout_Auto )
210 {
211 timeout = GetDefaultTimeout();
212 }
213
214 if ( !m_dialog )
215 {
216 m_dialog = new wxNotificationMessageDialog
217 (
218 GetParent(),
219 GetFullMessage(),
e5dbea49
VZ
220 timeout,
221 GetFlags()
e36a1739
VZ
222 );
223 }
224 else // update the existing dialog
225 {
e5dbea49 226 m_dialog->Set(GetParent(), GetFullMessage(), timeout, GetFlags());
e36a1739
VZ
227 }
228
229 m_dialog->Show();
230
231 return true;
232}
233
e2d5abbf 234bool wxGenericNotificationMessage::Close()
e36a1739
VZ
235{
236 if ( !m_dialog )
237 return false;
238
239 m_dialog->Hide();
240
241 return true;
242}
243
426d19f1 244#endif // wxUSE_NOTIFICATION_MESSAGE && (!wxUSE_LIBHILDON || !wxUSE_LIBHILDON2)