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"
46 #include "wx/statline.h"
48 #include "wx/tipdlg.h"
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 static const int wxID_NEXT_TIP
= -100; // whatever
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 // an implementation which takes the tips from the text file - each line
62 class WXDLLEXPORT wxFileTipProvider
: public wxTipProvider
65 wxFileTipProvider(const wxString
& filename
, size_t currentTip
);
67 virtual wxString
GetTip();
70 wxTextFile m_textfile
;
74 // TODO an implementation which takes the tips from the given registry key
75 class WXDLLEXPORT wxRegTipProvider
: public wxTipProvider
78 wxRegTipProvider(const wxString
& keyname
);
80 virtual wxString
GetTip();
83 // Empty implementation for now to keep the linker happy
84 wxString
wxRegTipProvider::GetTip()
91 // the dialog we show in wxShowTip()
92 class WXDLLEXPORT wxTipDialog
: public wxDialog
95 wxTipDialog(wxWindow
*parent
,
96 wxTipProvider
*tipProvider
,
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(); }
103 // sets the (next) tip text
104 void SetTipText() { m_text
->SetValue(m_tipProvider
->GetTip()); }
106 // "Next" button handler
107 void OnNextTip(wxCommandEvent
& WXUNUSED(event
)) { SetTipText(); }
110 wxTipProvider
*m_tipProvider
;
113 wxCheckBox
*m_checkbox
;
115 DECLARE_EVENT_TABLE()
118 // ============================================================================
120 // ============================================================================
122 // ----------------------------------------------------------------------------
124 // ----------------------------------------------------------------------------
126 wxFileTipProvider::wxFileTipProvider(const wxString
& filename
,
128 : wxTipProvider(currentTip
), m_textfile(filename
)
133 wxString
wxFileTipProvider::GetTip()
135 size_t count
= m_textfile
.GetLineCount();
137 return _("Tips not available, sorry!");
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
)
147 return m_textfile
.GetLine(m_currentTip
++);
150 // ----------------------------------------------------------------------------
152 // ----------------------------------------------------------------------------
154 BEGIN_EVENT_TABLE(wxTipDialog
, wxDialog
)
155 EVT_BUTTON(wxID_NEXT_TIP
, wxTipDialog::OnNextTip
)
158 wxTipDialog::wxTipDialog(wxWindow
*parent
,
159 wxTipProvider
*tipProvider
,
161 : wxDialog(parent
, -1, _("Tip of the Day"),
162 wxDefaultPosition
, wxDefaultSize
,
163 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
165 m_tipProvider
= tipProvider
;
167 // 1) create all controls in tab order
169 wxButton
*btnClose
= new wxButton(this, wxID_CANCEL
, _("&Close"));
171 m_checkbox
= new wxCheckBox(this, -1, _("&Show tips at startup"));
172 m_checkbox
->SetValue(showAtStartup
);
174 wxButton
*btnNext
= new wxButton(this, wxID_NEXT_TIP
, _("&Next"));
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
));
182 m_text
= new wxTextCtrl(this, -1, _T(""),
183 wxDefaultPosition
, wxSize(200, 160),
184 wxTE_MULTILINE
| wxTE_READONLY
| wxSUNKEN_BORDER
);
185 m_text
->SetFont(wxFont(14, wxROMAN
, wxNORMAL
, wxNORMAL
));
187 #if defined(__WXMSW__) || defined(__WXPM__)
188 wxIcon
icon("wxICON_TIP");
190 #include "wx/generic/tip.xpm"
191 wxIcon
icon(tipIcon
);
193 wxStaticBitmap
*bmp
= new wxStaticBitmap(this, -1, icon
);
195 // 2) put them in boxes
197 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
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 );
204 topsizer
->Add( m_text
, 1, wxEXPAND
| wxLEFT
|wxRIGHT
, 10 );
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 );
215 SetSizer( topsizer
);
217 topsizer
->SetSizeHints( this );
218 topsizer
->Fit( this );
220 Centre(wxBOTH
| wxCENTER_FRAME
);
224 // ----------------------------------------------------------------------------
225 // our public interface
226 // ----------------------------------------------------------------------------
228 wxTipProvider
*wxCreateFileTipProvider(const wxString
& filename
,
231 return new wxFileTipProvider(filename
, currentTip
);
234 bool wxShowTip(wxWindow
*parent
,
235 wxTipProvider
*tipProvider
,
238 wxTipDialog
dlg(parent
, tipProvider
, showAtStartup
);
241 return dlg
.ShowTipsOnStartup();
244 #endif // wxUSE_STARTUP_TIPS