1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: implementation of wxTipDialog
4 // Author: Vadim Zeitlin
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "tipdlg.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
31 #if wxUSE_STARTUP_TIPS
34 #include "wx/button.h"
35 #include "wx/checkbox.h"
36 #include "wx/statbox.h"
37 #include "wx/dialog.h"
40 #include "wx/settings.h"
41 #include "wx/textctrl.h"
42 #include "wx/statbmp.h"
43 #include "wx/stattext.h"
47 #include "wx/statline.h"
49 #include "wx/tipdlg.h"
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 static const int wxID_NEXT_TIP
= -100; // whatever
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
61 // an implementation which takes the tips from the text file - each line
63 class WXDLLEXPORT wxFileTipProvider
: public wxTipProvider
66 wxFileTipProvider(const wxString
& filename
, size_t currentTip
);
68 virtual wxString
GetTip();
71 wxTextFile m_textfile
;
75 // TODO an implementation which takes the tips from the given registry key
76 class WXDLLEXPORT wxRegTipProvider
: public wxTipProvider
79 wxRegTipProvider(const wxString
& keyname
);
81 virtual wxString
GetTip();
84 // Empty implementation for now to keep the linker happy
85 wxString
wxRegTipProvider::GetTip()
92 // the dialog we show in wxShowTip()
93 class WXDLLEXPORT wxTipDialog
: public wxDialog
96 wxTipDialog(wxWindow
*parent
,
97 wxTipProvider
*tipProvider
,
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(); }
104 // sets the (next) tip text
105 void SetTipText() { m_text
->SetValue(m_tipProvider
->GetTip()); }
107 // "Next" button handler
108 void OnNextTip(wxCommandEvent
& WXUNUSED(event
)) { SetTipText(); }
111 wxTipProvider
*m_tipProvider
;
114 wxCheckBox
*m_checkbox
;
116 DECLARE_EVENT_TABLE()
119 // ============================================================================
121 // ============================================================================
123 // ----------------------------------------------------------------------------
125 // ----------------------------------------------------------------------------
127 wxFileTipProvider::wxFileTipProvider(const wxString
& filename
,
129 : wxTipProvider(currentTip
), m_textfile(filename
)
134 wxString
wxFileTipProvider::GetTip()
136 size_t count
= m_textfile
.GetLineCount();
138 return _("Tips not available, sorry!");
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
)
148 return m_textfile
.GetLine(m_currentTip
++);
151 // ----------------------------------------------------------------------------
153 // ----------------------------------------------------------------------------
155 BEGIN_EVENT_TABLE(wxTipDialog
, wxDialog
)
156 EVT_BUTTON(wxID_NEXT_TIP
, wxTipDialog::OnNextTip
)
159 wxTipDialog::wxTipDialog(wxWindow
*parent
,
160 wxTipProvider
*tipProvider
,
162 : wxDialog(parent
, -1, _("Tip of the Day"),
163 wxDefaultPosition
, wxDefaultSize
,
164 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
166 m_tipProvider
= tipProvider
;
168 // 1) create all controls in tab order
170 wxButton
*btnClose
= new wxButton(this, wxID_CANCEL
, _("&Close"));
172 m_checkbox
= new wxCheckBox(this, -1, _("&Show tips at startup"));
173 m_checkbox
->SetValue(showAtStartup
);
175 wxButton
*btnNext
= new wxButton(this, wxID_NEXT_TIP
, _("&Next Tip"));
177 wxStaticText
*text
= new wxStaticText(this, -1, _("Did you know..."), wxDefaultPosition
, wxSize(-1,30) );
178 #if defined(__WXMSW__)
179 text
->SetFont(wxFont(16, wxSWISS
, wxNORMAL
, wxBOLD
));
181 text
->SetFont(wxFont(18, wxSWISS
, wxNORMAL
, wxBOLD
));
184 // text->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
186 m_text
= new wxTextCtrl(this, -1, wxT(""),
187 wxDefaultPosition
, wxSize(200, 160),
190 wxTE_RICH
| // a hack to get rid of vert scrollbar
192 #if defined(__WXMSW__)
193 m_text
->SetFont(wxFont(12, wxROMAN
, wxNORMAL
, wxNORMAL
));
195 m_text
->SetFont(wxFont(14, wxROMAN
, wxNORMAL
, wxNORMAL
));
198 #if defined(__WXMSW__) || defined(__WXPM__)
199 wxIcon
icon("wxICON_TIP");
201 // XPM hack: make the arrays const
202 #define static static const
204 #include "wx/generic/tip.xpm"
208 wxIcon
icon(tipIcon
);
210 wxStaticBitmap
*bmp
= new wxStaticBitmap(this, -1, icon
);
212 // 2) put them in boxes
214 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
216 wxBoxSizer
*icon_text
= new wxBoxSizer( wxHORIZONTAL
);
217 icon_text
->Add( bmp
, 0, wxCENTER
);
218 icon_text
->Add( text
, 1, wxCENTER
| wxLEFT
, 20 );
219 topsizer
->Add( icon_text
, 0, wxEXPAND
| wxALL
, 10 );
221 topsizer
->Add( m_text
, 1, wxEXPAND
| wxLEFT
|wxRIGHT
, 10 );
223 wxBoxSizer
*bottom
= new wxBoxSizer( wxHORIZONTAL
);
224 bottom
->Add( m_checkbox
, 0, wxCENTER
);
225 bottom
->Add( 10,10,1 );
226 bottom
->Add( btnNext
, 0, wxCENTER
| wxLEFT
, 10 );
227 bottom
->Add( btnClose
, 0, wxCENTER
| wxLEFT
, 10 );
228 topsizer
->Add( bottom
, 0, wxEXPAND
| wxALL
, 10 );
233 SetSizer( topsizer
);
235 topsizer
->SetSizeHints( this );
236 topsizer
->Fit( this );
238 Centre(wxBOTH
| wxCENTER_FRAME
);
242 // ----------------------------------------------------------------------------
243 // our public interface
244 // ----------------------------------------------------------------------------
246 wxTipProvider
*wxCreateFileTipProvider(const wxString
& filename
,
249 return new wxFileTipProvider(filename
, currentTip
);
252 bool wxShowTip(wxWindow
*parent
,
253 wxTipProvider
*tipProvider
,
256 wxTipDialog
dlg(parent
, tipProvider
, showAtStartup
);
259 return dlg
.ShowTipsOnStartup();
262 #endif // wxUSE_STARTUP_TIPS