]> git.saurik.com Git - wxWidgets.git/blame - src/generic/tipdlg.cpp
Fix broken and missing DataView interface items for Phoenix
[wxWidgets.git] / src / generic / tipdlg.cpp
CommitLineData
c50f1fb9 1///////////////////////////////////////////////////////////////////////////////
f43255e8 2// Name: src/generic/tipdlg.cpp
c50f1fb9
VZ
3// Purpose: implementation of wxTipDialog
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 28.06.99
7// RCS-ID: $Id$
8// Copyright: (c) Vadim Zeitlin
65571936 9// Licence: wxWindows licence
c50f1fb9
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
c50f1fb9
VZ
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
27#if wxUSE_STARTUP_TIPS
28
29#ifndef WX_PRECOMP
30 #include "wx/button.h"
31 #include "wx/checkbox.h"
32 #include "wx/statbox.h"
c50f1fb9 33 #include "wx/dialog.h"
dfe1eee3
VZ
34 #include "wx/icon.h"
35 #include "wx/intl.h"
dfe1eee3 36 #include "wx/textctrl.h"
3bb0b01c 37 #include "wx/statbmp.h"
9c884972 38 #include "wx/stattext.h"
92afa2b1 39 #include "wx/sizer.h"
9eddec69 40 #include "wx/settings.h"
c50f1fb9
VZ
41#endif // WX_PRECOMP
42
43#include "wx/statline.h"
91f43f15 44#include "wx/artprov.h"
c50f1fb9
VZ
45
46#include "wx/tipdlg.h"
47
48// ----------------------------------------------------------------------------
49// constants
50// ----------------------------------------------------------------------------
51
d8d18184 52static const int wxID_NEXT_TIP = 32000; // whatever
c50f1fb9 53
8b3d02a1
WS
54// ---------------------------------------------------------------------------
55// macros
56// ---------------------------------------------------------------------------
57
58/* Macro for avoiding #ifdefs when value have to be different depending on size of
9a357011 59 device we display on - take it from something like wxDesktopPolicy in the future
8b3d02a1
WS
60 */
61
62#if defined(__SMARTPHONE__)
63 #define wxLARGESMALL(large,small) small
64#else
65 #define wxLARGESMALL(large,small) large
66#endif
67
c50f1fb9
VZ
68// ----------------------------------------------------------------------------
69// private classes
70// ----------------------------------------------------------------------------
71
72// an implementation which takes the tips from the text file - each line
73// represents a tip
6502dc68 74#if wxUSE_TEXTFILE
12f190b0 75class WXDLLIMPEXP_ADV wxFileTipProvider : public wxTipProvider
c50f1fb9
VZ
76{
77public:
78 wxFileTipProvider(const wxString& filename, size_t currentTip);
79
80 virtual wxString GetTip();
81
82private:
83 wxTextFile m_textfile;
fc7a2a60 84
c0c133e1 85 wxDECLARE_NO_COPY_CLASS(wxFileTipProvider);
c50f1fb9 86};
6502dc68 87#endif // wxUSE_TEXTFILE
c50f1fb9
VZ
88
89#ifdef __WIN32__
90// TODO an implementation which takes the tips from the given registry key
12f190b0 91class WXDLLIMPEXP_ADV wxRegTipProvider : public wxTipProvider
c50f1fb9
VZ
92{
93public:
94 wxRegTipProvider(const wxString& keyname);
95
96 virtual wxString GetTip();
97};
06d7fdef
RD
98
99// Empty implementation for now to keep the linker happy
100wxString wxRegTipProvider::GetTip()
101{
abceee76 102 return wxEmptyString;
06d7fdef
RD
103}
104
c50f1fb9
VZ
105#endif // __WIN32__
106
107// the dialog we show in wxShowTip()
12f190b0 108class WXDLLIMPEXP_ADV wxTipDialog : public wxDialog
c50f1fb9
VZ
109{
110public:
111 wxTipDialog(wxWindow *parent,
112 wxTipProvider *tipProvider,
113 bool showAtStartup);
114
dabbc6a5 115 // the tip dialog has "Show tips on startup" checkbox - return true if it
c50f1fb9
VZ
116 // was checked (or wasn't unchecked)
117 bool ShowTipsOnStartup() const { return m_checkbox->GetValue(); }
118
119 // sets the (next) tip text
120 void SetTipText() { m_text->SetValue(m_tipProvider->GetTip()); }
121
122 // "Next" button handler
123 void OnNextTip(wxCommandEvent& WXUNUSED(event)) { SetTipText(); }
124
125private:
126 wxTipProvider *m_tipProvider;
127
128 wxTextCtrl *m_text;
129 wxCheckBox *m_checkbox;
130
131 DECLARE_EVENT_TABLE()
c0c133e1 132 wxDECLARE_NO_COPY_CLASS(wxTipDialog);
c50f1fb9
VZ
133};
134
135// ============================================================================
136// implementation
137// ============================================================================
138
139// ----------------------------------------------------------------------------
140// wxFileTipProvider
141// ----------------------------------------------------------------------------
6502dc68 142#if wxUSE_TEXTFILE
c50f1fb9
VZ
143wxFileTipProvider::wxFileTipProvider(const wxString& filename,
144 size_t currentTip)
145 : wxTipProvider(currentTip), m_textfile(filename)
146{
147 m_textfile.Open();
148}
149
150wxString wxFileTipProvider::GetTip()
151{
152 size_t count = m_textfile.GetLineCount();
153 if ( !count )
c50f1fb9 154 {
70373b5a 155 return _("Tips not available, sorry!");
c50f1fb9 156 }
dabbc6a5 157
70373b5a
JS
158 wxString tip;
159
160 // Comments start with a # symbol.
161 // Loop reading lines until get the first one that isn't a comment.
dabbc6a5
DS
162 // The max number of loop executions is the number of lines in the
163 // textfile so that can't go into an eternal loop in the [oddball]
164 // case of a comment-only tips file, or the developer has vetoed
70373b5a
JS
165 // them all via PreprecessTip().
166 for ( size_t i=0; i < count; i++ )
dabbc6a5
DS
167 {
168 // The current tip may be at the last line of the textfile, (or
169 // past it, if the number of lines in the textfile changed, such
70373b5a
JS
170 // as changing to a different textfile, with less tips). So check
171 // to see at last line of text file, (or past it)...
172 if ( m_currentTip >= count )
173 {
174 // .. and if so, wrap back to line 0.
175 m_currentTip = 0;
dabbc6a5
DS
176 }
177
70373b5a
JS
178 // Read the tip, and increment the current tip counter.
179 tip = m_textfile.GetLine(m_currentTip++);
dabbc6a5
DS
180
181 // Allow a derived class's overrided virtual to modify the tip
70373b5a 182 // now if so desired.
dabbc6a5
DS
183 tip = PreprocessTip(tip);
184
70373b5a
JS
185 // Break if tip isn't a comment, and isn't an empty string
186 // (or only stray space characters).
187 if ( !tip.StartsWith(wxT("#")) && (tip.Trim() != wxEmptyString) )
188 {
189 break;
190 }
191 }
dabbc6a5 192
70373b5a
JS
193 // If tip starts with '_(', then it is a gettext string of format
194 // _("My \"global\" tip text") so first strip off the leading '_("'...
195 if ( tip.StartsWith(wxT("_(\"" ), &tip))
196 {
197 //...and strip off the trailing '")'...
198 tip = tip.BeforeLast(wxT('\"'));
dabbc6a5
DS
199 // ...and replace escaped quotes
200 tip.Replace(wxT("\\\""), wxT("\""));
321fe98c
VZ
201
202 // and translate it as requested
203 tip = wxGetTranslation(tip);
dabbc6a5
DS
204 }
205
206 return tip;
c50f1fb9 207}
6502dc68 208#endif // wxUSE_TEXTFILE
c50f1fb9
VZ
209
210// ----------------------------------------------------------------------------
211// wxTipDialog
212// ----------------------------------------------------------------------------
213
214BEGIN_EVENT_TABLE(wxTipDialog, wxDialog)
65fd5cb0 215 EVT_BUTTON(wxID_NEXT_TIP, wxTipDialog::OnNextTip)
c50f1fb9
VZ
216END_EVENT_TABLE()
217
218wxTipDialog::wxTipDialog(wxWindow *parent,
219 wxTipProvider *tipProvider,
220 bool showAtStartup)
cdc48273 221 : wxDialog(GetParentForModalDialog(parent, 0), wxID_ANY, _("Tip of the Day"),
c50f1fb9 222 wxDefaultPosition, wxDefaultSize,
f43255e8 223 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER
aa66250b 224 )
c50f1fb9
VZ
225{
226 m_tipProvider = tipProvider;
94f53923 227 bool isPda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
c50f1fb9 228
92afa2b1 229 // 1) create all controls in tab order
abceee76 230
4e4688be
VS
231 wxStaticText *text = new wxStaticText(this, wxID_ANY, _("Did you know..."));
232
94f53923
JS
233 if (!isPda)
234 {
235 wxFont font = text->GetFont();
236 font.SetPointSize(int(1.6 * font.GetPointSize()));
237 font.SetWeight(wxFONTWEIGHT_BOLD);
238 text->SetFont(font);
239 }
c50f1fb9 240
dabbc6a5 241 m_text = new wxTextCtrl(this, wxID_ANY, wxEmptyString,
92afa2b1 242 wxDefaultPosition, wxSize(200, 160),
abceee76
VZ
243 wxTE_MULTILINE |
244 wxTE_READONLY |
58ec2255 245 wxTE_NO_VSCROLL |
e111012a 246 wxTE_RICH2 | // a hack to get rid of vert scrollbar
aa66250b
JS
247 wxDEFAULT_CONTROL_BORDER
248 );
e16ebee6 249#if defined(__WXMSW__)
58ec2255 250 m_text->SetFont(wxFont(12, wxSWISS, wxNORMAL, wxNORMAL));
e16ebee6 251#endif
c50f1fb9 252
e225b106 253//#if defined(__WXPM__)
1c4fbbf1
DW
254 //
255 // The only way to get icons into an OS/2 static bitmap control
256 //
e225b106 257// wxBitmap vBitmap;
1c4fbbf1 258
e225b106
DW
259// vBitmap.SetId(wxICON_TIP); // OS/2 specific bitmap method--OS/2 wxBitmaps all have an ID.
260// // and for StatBmp's under OS/2 it MUST be a valid resource ID.
261//
dabbc6a5 262// wxStaticBitmap* bmp = new wxStaticBitmap(this, wxID_ANY, vBitmap);
e225b106
DW
263//
264//#else
1c4fbbf1 265
91f43f15 266 wxIcon icon = wxArtProvider::GetIcon(wxART_TIP, wxART_CMN_DIALOG);
dabbc6a5 267 wxStaticBitmap *bmp = new wxStaticBitmap(this, wxID_ANY, icon);
c50f1fb9 268
e225b106 269//#endif
1c4fbbf1 270
66470d87
VS
271 m_checkbox = new wxCheckBox(this, wxID_ANY, _("&Show tips at startup"));
272 m_checkbox->SetValue(showAtStartup);
273 m_checkbox->SetFocus();
274
275 // smart phones does not support or do not waste space for wxButtons
276#ifndef __SMARTPHONE__
277 wxButton *btnNext = new wxButton(this, wxID_NEXT_TIP, _("&Next Tip"));
278#endif
279
280 // smart phones does not support or do not waste space for wxButtons
281#ifndef __SMARTPHONE__
282 wxButton *btnClose = new wxButton(this, wxID_CLOSE);
283 SetAffirmativeId(wxID_CLOSE);
284#endif
285
286
92afa2b1 287 // 2) put them in boxes
c50f1fb9 288
92afa2b1 289 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
abceee76 290
92afa2b1
RR
291 wxBoxSizer *icon_text = new wxBoxSizer( wxHORIZONTAL );
292 icon_text->Add( bmp, 0, wxCENTER );
8b3d02a1
WS
293 icon_text->Add( text, 1, wxCENTER | wxLEFT, wxLARGESMALL(20,0) );
294 topsizer->Add( icon_text, 0, wxEXPAND | wxALL, wxLARGESMALL(10,0) );
abceee76 295
8b3d02a1 296 topsizer->Add( m_text, 1, wxEXPAND | wxLEFT|wxRIGHT, wxLARGESMALL(10,0) );
92afa2b1
RR
297
298 wxBoxSizer *bottom = new wxBoxSizer( wxHORIZONTAL );
94f53923
JS
299 if (isPda)
300 topsizer->Add( m_checkbox, 0, wxCENTER|wxTOP );
301 else
302 bottom->Add( m_checkbox, 0, wxCENTER );
8b3d02a1 303
9a357011
WS
304 // smart phones does not support or do not waste space for wxButtons
305#ifdef __SMARTPHONE__
306 SetRightMenu(wxID_NEXT_TIP, _("Next"));
eb3e6de3 307 SetLeftMenu(wxID_CLOSE);
9a357011 308#else
94f53923
JS
309 if (!isPda)
310 bottom->Add( 10,10,1 );
8b3d02a1
WS
311 bottom->Add( btnNext, 0, wxCENTER | wxLEFT, wxLARGESMALL(10,0) );
312 bottom->Add( btnClose, 0, wxCENTER | wxLEFT, wxLARGESMALL(10,0) );
313#endif
314
94f53923
JS
315 if (isPda)
316 topsizer->Add( bottom, 0, wxCENTER | wxALL, 5 );
317 else
318 topsizer->Add( bottom, 0, wxEXPAND | wxALL, wxLARGESMALL(10,0) );
c50f1fb9
VZ
319
320 SetTipText();
abceee76 321
92afa2b1 322 SetSizer( topsizer );
abceee76 323
92afa2b1
RR
324 topsizer->SetSizeHints( this );
325 topsizer->Fit( this );
c50f1fb9
VZ
326
327 Centre(wxBOTH | wxCENTER_FRAME);
c50f1fb9
VZ
328}
329
330// ----------------------------------------------------------------------------
331// our public interface
332// ----------------------------------------------------------------------------
333
6502dc68 334#if wxUSE_TEXTFILE
c50f1fb9
VZ
335wxTipProvider *wxCreateFileTipProvider(const wxString& filename,
336 size_t currentTip)
337{
338 return new wxFileTipProvider(filename, currentTip);
339}
6502dc68 340#endif // wxUSE_TEXTFILE
c50f1fb9
VZ
341
342bool wxShowTip(wxWindow *parent,
343 wxTipProvider *tipProvider,
344 bool showAtStartup)
345{
346 wxTipDialog dlg(parent, tipProvider, showAtStartup);
347 dlg.ShowModal();
348
349 return dlg.ShowTipsOnStartup();
350}
351
352#endif // wxUSE_STARTUP_TIPS