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