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