]> git.saurik.com Git - wxWidgets.git/blame - src/generic/tipdlg.cpp
Augmented beta to 9,
[wxWidgets.git] / src / generic / tipdlg.cpp
CommitLineData
c50f1fb9
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: tipdlg.cpp
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
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20#ifdef __GNUG__
dfe1eee3 21 #pragma implementation "tipdlg.h"
c50f1fb9
VZ
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
28 #pragma hdrstop
29#endif
30
31#if wxUSE_STARTUP_TIPS
32
33#ifndef WX_PRECOMP
34 #include "wx/button.h"
35 #include "wx/checkbox.h"
36 #include "wx/statbox.h"
c50f1fb9 37 #include "wx/dialog.h"
dfe1eee3
VZ
38 #include "wx/icon.h"
39 #include "wx/intl.h"
dfe1eee3
VZ
40 #include "wx/settings.h"
41 #include "wx/textctrl.h"
3bb0b01c 42 #include "wx/statbmp.h"
92afa2b1 43 #include "wx/sizer.h"
c50f1fb9
VZ
44#endif // WX_PRECOMP
45
46#include "wx/statline.h"
47
48#include "wx/tipdlg.h"
49
50// ----------------------------------------------------------------------------
51// constants
52// ----------------------------------------------------------------------------
53
54static const int wxID_NEXT_TIP = -100; // whatever
55
56// ----------------------------------------------------------------------------
57// private classes
58// ----------------------------------------------------------------------------
59
60// an implementation which takes the tips from the text file - each line
61// represents a tip
62class WXDLLEXPORT wxFileTipProvider : public wxTipProvider
63{
64public:
65 wxFileTipProvider(const wxString& filename, size_t currentTip);
66
67 virtual wxString GetTip();
68
69private:
70 wxTextFile m_textfile;
71};
72
73#ifdef __WIN32__
74// TODO an implementation which takes the tips from the given registry key
75class WXDLLEXPORT wxRegTipProvider : public wxTipProvider
76{
77public:
78 wxRegTipProvider(const wxString& keyname);
79
80 virtual wxString GetTip();
81};
06d7fdef
RD
82
83// Empty implementation for now to keep the linker happy
84wxString wxRegTipProvider::GetTip()
85{
86 return "";
87}
88
c50f1fb9
VZ
89#endif // __WIN32__
90
91// the dialog we show in wxShowTip()
92class WXDLLEXPORT wxTipDialog : public wxDialog
93{
94public:
95 wxTipDialog(wxWindow *parent,
96 wxTipProvider *tipProvider,
97 bool showAtStartup);
98
99 // the tip dialog has "Show tips on startup" checkbox - return TRUE if it
100 // was checked (or wasn't unchecked)
101 bool ShowTipsOnStartup() const { return m_checkbox->GetValue(); }
102
103 // sets the (next) tip text
104 void SetTipText() { m_text->SetValue(m_tipProvider->GetTip()); }
105
106 // "Next" button handler
107 void OnNextTip(wxCommandEvent& WXUNUSED(event)) { SetTipText(); }
108
109private:
110 wxTipProvider *m_tipProvider;
111
112 wxTextCtrl *m_text;
113 wxCheckBox *m_checkbox;
114
115 DECLARE_EVENT_TABLE()
116};
117
118// ============================================================================
119// implementation
120// ============================================================================
121
122// ----------------------------------------------------------------------------
123// wxFileTipProvider
124// ----------------------------------------------------------------------------
125
126wxFileTipProvider::wxFileTipProvider(const wxString& filename,
127 size_t currentTip)
128 : wxTipProvider(currentTip), m_textfile(filename)
129{
130 m_textfile.Open();
131}
132
133wxString wxFileTipProvider::GetTip()
134{
135 size_t count = m_textfile.GetLineCount();
136 if ( !count )
137 return _("Tips not available, sorry!");
138
139 // notice that it may be greater, actually, if we remembered it from the
140 // last time and the number of tips changed
141 if ( m_currentTip == count )
142 {
143 // wrap
144 m_currentTip = 0;
145 }
146
147 return m_textfile.GetLine(m_currentTip++);
148}
149
150// ----------------------------------------------------------------------------
151// wxTipDialog
152// ----------------------------------------------------------------------------
153
154BEGIN_EVENT_TABLE(wxTipDialog, wxDialog)
65fd5cb0 155 EVT_BUTTON(wxID_NEXT_TIP, wxTipDialog::OnNextTip)
c50f1fb9
VZ
156END_EVENT_TABLE()
157
158wxTipDialog::wxTipDialog(wxWindow *parent,
159 wxTipProvider *tipProvider,
160 bool showAtStartup)
161 : wxDialog(parent, -1, _("Tip of the Day"),
162 wxDefaultPosition, wxDefaultSize,
163 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
164{
165 m_tipProvider = tipProvider;
166
92afa2b1
RR
167 // 1) create all controls in tab order
168
c50f1fb9 169 wxButton *btnClose = new wxButton(this, wxID_CANCEL, _("&Close"));
92afa2b1 170
c50f1fb9 171 m_checkbox = new wxCheckBox(this, -1, _("&Show tips at startup"));
92afa2b1
RR
172 m_checkbox->SetValue(showAtStartup);
173
c50f1fb9
VZ
174 wxButton *btnNext = new wxButton(this, wxID_NEXT_TIP, _("&Next"));
175
176 wxTextCtrl *text = new wxTextCtrl(this, -1, _("Did you know..."),
177 wxDefaultPosition, wxDefaultSize,
178 wxTE_READONLY | wxNO_BORDER);
179 text->SetFont(wxFont(18, wxSWISS, wxNORMAL, wxBOLD));
180 text->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE));
181
182 m_text = new wxTextCtrl(this, -1, _T(""),
92afa2b1 183 wxDefaultPosition, wxSize(200, 160),
c50f1fb9
VZ
184 wxTE_MULTILINE | wxTE_READONLY | wxSUNKEN_BORDER);
185 m_text->SetFont(wxFont(14, wxROMAN, wxNORMAL, wxNORMAL));
186
913df6f2 187#if defined(__WXMSW__) || defined(__WXPM__)
c50f1fb9
VZ
188 wxIcon icon("wxICON_TIP");
189#else
190 #include "wx/generic/tip.xpm"
dfe1eee3 191 wxIcon icon(tipIcon);
c50f1fb9 192#endif
c50f1fb9
VZ
193 wxStaticBitmap *bmp = new wxStaticBitmap(this, -1, icon);
194
92afa2b1 195 // 2) put them in boxes
c50f1fb9 196
92afa2b1
RR
197 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
198
199 wxBoxSizer *icon_text = new wxBoxSizer( wxHORIZONTAL );
200 icon_text->Add( bmp, 0, wxCENTER );
201 icon_text->Add( text, 1, wxCENTER | wxLEFT, 10 );
202 topsizer->Add( icon_text, 0, wxEXPAND | wxALL, 10 );
203
204 topsizer->Add( m_text, 1, wxEXPAND | wxLEFT|wxRIGHT, 10 );
205
206 wxBoxSizer *bottom = new wxBoxSizer( wxHORIZONTAL );
207 bottom->Add( m_checkbox, 0, wxCENTER );
208 bottom->Add( btnNext, 0, wxCENTER | wxLEFT, 10 );
209 bottom->Add( btnClose, 0, wxCENTER | wxLEFT, 10 );
210 topsizer->Add( bottom, 0, wxALIGN_RIGHT | wxALL, 10 );
c50f1fb9
VZ
211
212 SetTipText();
92afa2b1
RR
213
214 SetAutoLayout(TRUE);
215 SetSizer( topsizer );
216
217 topsizer->SetSizeHints( this );
218 topsizer->Fit( this );
c50f1fb9
VZ
219
220 Centre(wxBOTH | wxCENTER_FRAME);
221
c50f1fb9
VZ
222}
223
224// ----------------------------------------------------------------------------
225// our public interface
226// ----------------------------------------------------------------------------
227
228wxTipProvider *wxCreateFileTipProvider(const wxString& filename,
229 size_t currentTip)
230{
231 return new wxFileTipProvider(filename, currentTip);
232}
233
234bool wxShowTip(wxWindow *parent,
235 wxTipProvider *tipProvider,
236 bool showAtStartup)
237{
238 wxTipDialog dlg(parent, tipProvider, showAtStartup);
239 dlg.ShowModal();
240
241 return dlg.ShowTipsOnStartup();
242}
243
244#endif // wxUSE_STARTUP_TIPS
245