1 // $Id: SupressibleMessageDialog.cpp 587 2010-10-21 22:35:37Z felfert $
2 //
3 // Copyright (C) 2010 The OpenNX team
4 // Author: Fritz Elfert
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU Library General Public License as
8 // published by the Free Software Foundation; either version 2 of the
9 // License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU Library General Public
17 // License along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 //
21 
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25 
26 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
27 #pragma implementation "SupessibleMessageDialog.h"
28 #endif
29 
30 // For compilers that support precompilation, includes "wx/wx.h".
31 #include "wx/wxprec.h"
32 
33 #ifdef __BORLANDC__
34 #pragma hdrstop
35 #endif
36 
37 #ifndef WX_PRECOMP
38 #include "wx/wx.h"
39 #endif
40 
41 #include <wx/config.h>
42 ////@begin includes
43 ////@end includes
44 
45 #include "SupressibleMessageDialog.h"
46 #include "Icon.h"
47 
48 ////@begin XPM images
49 ////@end XPM images
50 
51 
52 /*!
53  * SupressibleMessageDialog type definition
54  */
55 
IMPLEMENT_DYNAMIC_CLASS(SupressibleMessageDialog,wxDialog)56 IMPLEMENT_DYNAMIC_CLASS( SupressibleMessageDialog, wxDialog )
57 
58 
59 /*!
60  * SupressibleMessageDialog event table definition
61  */
62 
63 BEGIN_EVENT_TABLE( SupressibleMessageDialog, wxDialog )
64 
65 ////@begin SupressibleMessageDialog event table entries
66 ////@end SupressibleMessageDialog event table entries
67 
68 END_EVENT_TABLE()
69 
70 int SupressibleMessageDialog::ShowConditional(const wxString &msgid, int defaultResult)
71 {
72     wxString cfgname(wxT("SupressedDialogs/"));
73     cfgname.Append(msgid);
74     bool hide = false;
75     wxConfigBase::Get()->Read(cfgname, &hide, false);
76     if (hide)
77         return defaultResult;
78     int ret = wxDialog::ShowModal();
79     if ((wxID_CANCEL == ret) && (wxYES_NO == (m_lButtonStyle & (wxCANCEL|wxYES_NO)))) {
80         // No cancel button: Closing dialog => defaultResult
81         ret = defaultResult;
82     }
83     if (m_bHide)
84         wxConfigBase::Get()->Write(cfgname, true);
85     return ret;
86 }
87 
88 /*!
89  * SupressibleMessageDialog constructors
90  */
91 
SupressibleMessageDialog()92 SupressibleMessageDialog::SupressibleMessageDialog()
93 {
94     Init();
95 }
96 
SupressibleMessageDialog(wxWindow * parent,wxWindowID id,const wxString & caption,const wxPoint & pos,const wxSize & size,long style)97 SupressibleMessageDialog::SupressibleMessageDialog( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
98 {
99     Init();
100     Create(parent, id, caption, pos, size, style);
101 }
102 
103 
SupressibleMessageDialog(wxWindow * parent,const wxString & message,const wxString & caption,long style)104 SupressibleMessageDialog::SupressibleMessageDialog(wxWindow *parent, const wxString &message, const wxString &caption, long style /* = wxICON_EXCLAMATION|wxOK */)
105 {
106     Init();
107     Create(parent, SYMBOL_SUPRESSIBLEMESSAGEDIALOG_IDNAME, caption,
108             SYMBOL_SUPRESSIBLEMESSAGEDIALOG_POSITION, SYMBOL_SUPRESSIBLEMESSAGEDIALOG_SIZE,
109             SYMBOL_SUPRESSIBLEMESSAGEDIALOG_STYLE);
110     m_lIconStyle = style & wxICON_MASK;
111     m_lButtonStyle = style & ~wxICON_MASK;
112     switch (m_lIconStyle) {
113         case wxICON_EXCLAMATION:
114             m_pDialogIcon->SetBitmap(wxArtProvider::GetBitmap(wxART_WARNING, wxART_MESSAGE_BOX));
115             break;
116         case wxICON_ERROR:
117             m_pDialogIcon->SetBitmap(wxArtProvider::GetBitmap(wxART_ERROR, wxART_MESSAGE_BOX));
118             break;
119         case wxICON_QUESTION:
120             m_pDialogIcon->SetBitmap(wxArtProvider::GetBitmap(wxART_QUESTION, wxART_MESSAGE_BOX));
121             break;
122         case wxICON_INFORMATION:
123             m_pDialogIcon->SetBitmap(wxArtProvider::GetBitmap(wxART_INFORMATION, wxART_MESSAGE_BOX));
124             break;
125     }
126     wxSizer *sz = GetSizer();
127     if (sz) {
128         wxSizer *bs = CreateSeparatedButtonSizer(m_lButtonStyle);
129         if (bs) {
130             sz->Add(bs, wxSizerFlags().Expand().Border(wxALL, 5));
131         }
132         if (m_lButtonStyle & wxYES_NO) {
133             // Add missing event handler for "No" button.
134             Connect(XRCID("wxID_NO"), wxEVT_COMMAND_BUTTON_CLICKED,
135                     wxCommandEventHandler(SupressibleMessageDialog::OnNoClick));
136         }
137     }
138     SetTitle(caption);
139     m_pMessage->SetLabel(message);
140     Fit();
141 }
142 
143 /*!
144  * SupessibleMessageDialog creator
145  */
146 
Create(wxWindow * parent,wxWindowID,const wxString &,const wxPoint &,const wxSize &,long)147 bool SupressibleMessageDialog::Create( wxWindow* parent, wxWindowID, const wxString&, const wxPoint&, const wxSize&, long)
148 {
149     ////@begin SupressibleMessageDialog creation
150     SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
151     SetParent(parent);
152     CreateControls();
153     SetIcon(GetIconResource(wxT("res/nx.png")));
154     if (GetSizer())
155     {
156         GetSizer()->SetSizeHints(this);
157     }
158     Centre();
159     ////@end SupressibleMessageDialog creation
160     return true;
161 }
162 
163 
164 /*!
165  * SupressibleMessageDialog destructor
166  */
167 
~SupressibleMessageDialog()168 SupressibleMessageDialog::~SupressibleMessageDialog()
169 {
170     ////@begin SupressibleMessageDialog destruction
171     ////@end SupressibleMessageDialog destruction
172 }
173 
174 
175 /*!
176  * Member initialisation
177  */
178 
Init()179 void SupressibleMessageDialog::Init()
180 {
181     ////@begin SupressibleMessageDialog member initialisation
182     m_bHide = false;
183     m_lButtonStyle = 0;
184     m_lIconStyle = 0;
185     m_pDialogIcon = NULL;
186     m_pMessage = NULL;
187     ////@end SupressibleMessageDialog member initialisation
188 }
189 
190 
191 /*!
192  * Control creation for SupessibleMessageDialog
193  */
194 
CreateControls()195 void SupressibleMessageDialog::CreateControls()
196 {
197     ////@begin SupressibleMessageDialog content construction
198     if (!wxXmlResource::Get()->LoadDialog(this, GetParent(), _T("ID_SUPRESSIBLEMESSAGEDIALOG")))
199         wxLogError(wxT("Missing wxXmlResource::Get()->Load() in OnInit()?"));
200     m_pDialogIcon = XRCCTRL(*this, "wxID_STATIC", wxStaticBitmap);
201     m_pMessage = XRCCTRL(*this, "wxID_DLGMESSAGE", wxStaticText);
202     // Set validators
203     if (FindWindow(XRCID("ID_CHECKBOX")))
204         FindWindow(XRCID("ID_CHECKBOX"))->SetValidator( wxGenericValidator(& m_bHide) );
205     ////@end SupressibleMessageDialog content construction
206 
207     // Create custom windows not generated automatically here.
208     ////@begin SupressibleMessageDialog content initialisation
209     ////@end SupressibleMessageDialog content initialisation
210 }
211 
212 
213 /*!
214  * Should we show tooltips?
215  */
216 
ShowToolTips()217 bool SupressibleMessageDialog::ShowToolTips()
218 {
219     return true;
220 }
221 
222 /*!
223  * Get bitmap resources
224  */
225 
GetBitmapResource(const wxString & name)226 wxBitmap SupressibleMessageDialog::GetBitmapResource( const wxString& name )
227 {
228     // Bitmap retrieval
229     return CreateBitmapFromFile(name);
230 }
231 
232 /*!
233  * Get icon resources
234  */
235 
GetIconResource(const wxString & name)236 wxIcon SupressibleMessageDialog::GetIconResource( const wxString& name )
237 {
238     // Icon retrieval
239     return CreateIconFromFile(name);
240 }
241 
242 
OnNoClick(wxCommandEvent &)243 void SupressibleMessageDialog::OnNoClick( wxCommandEvent& )
244 {
245     EndModal(wxID_NO);
246 }
247 
248