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 "windowbase.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/statbmp.h"
38 #include "wx/dialog.h"
41 #include "wx/statline.h"
43 #include "wx/tipdlg.h"
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 static const int wxID_NEXT_TIP
= -100; // whatever
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 // an implementation which takes the tips from the text file - each line
57 class WXDLLEXPORT wxFileTipProvider
: public wxTipProvider
60 wxFileTipProvider(const wxString
& filename
, size_t currentTip
);
62 virtual wxString
GetTip();
65 wxTextFile m_textfile
;
69 // TODO an implementation which takes the tips from the given registry key
70 class WXDLLEXPORT wxRegTipProvider
: public wxTipProvider
73 wxRegTipProvider(const wxString
& keyname
);
75 virtual wxString
GetTip();
79 // the dialog we show in wxShowTip()
80 class WXDLLEXPORT wxTipDialog
: public wxDialog
83 wxTipDialog(wxWindow
*parent
,
84 wxTipProvider
*tipProvider
,
87 // the tip dialog has "Show tips on startup" checkbox - return TRUE if it
88 // was checked (or wasn't unchecked)
89 bool ShowTipsOnStartup() const { return m_checkbox
->GetValue(); }
91 // sets the (next) tip text
92 void SetTipText() { m_text
->SetValue(m_tipProvider
->GetTip()); }
94 // "Next" button handler
95 void OnNextTip(wxCommandEvent
& WXUNUSED(event
)) { SetTipText(); }
98 wxTipProvider
*m_tipProvider
;
101 wxCheckBox
*m_checkbox
;
103 DECLARE_EVENT_TABLE()
106 // ============================================================================
108 // ============================================================================
110 // ----------------------------------------------------------------------------
112 // ----------------------------------------------------------------------------
114 wxFileTipProvider::wxFileTipProvider(const wxString
& filename
,
116 : wxTipProvider(currentTip
), m_textfile(filename
)
121 wxString
wxFileTipProvider::GetTip()
123 size_t count
= m_textfile
.GetLineCount();
125 return _("Tips not available, sorry!");
127 // notice that it may be greater, actually, if we remembered it from the
128 // last time and the number of tips changed
129 if ( m_currentTip
== count
)
135 return m_textfile
.GetLine(m_currentTip
++);
138 // ----------------------------------------------------------------------------
140 // ----------------------------------------------------------------------------
142 BEGIN_EVENT_TABLE(wxTipDialog
, wxDialog
)
143 EVT_BUTTON(wxID_NEXT_TIP
, OnNextTip
)
146 wxTipDialog::wxTipDialog(wxWindow
*parent
,
147 wxTipProvider
*tipProvider
,
149 : wxDialog(parent
, -1, _("Tip of the Day"),
150 wxDefaultPosition
, wxDefaultSize
,
151 wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
153 m_tipProvider
= tipProvider
;
155 wxSize sizeBtn
= GetStandardButtonSize();
156 wxLayoutConstraints
*c
;
158 // create the controls in the right order, then set the constraints
159 wxButton
*btnClose
= new wxButton(this, wxID_CANCEL
, _("&Close"));
160 m_checkbox
= new wxCheckBox(this, -1, _("&Show tips at startup"));
161 wxButton
*btnNext
= new wxButton(this, wxID_NEXT_TIP
, _("&Next"));
163 wxTextCtrl
*text
= new wxTextCtrl(this, -1, _("Did you know..."),
164 wxDefaultPosition
, wxDefaultSize
,
165 wxTE_READONLY
| wxNO_BORDER
);
166 text
->SetFont(wxFont(18, wxSWISS
, wxNORMAL
, wxBOLD
));
167 text
->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE
));
169 m_text
= new wxTextCtrl(this, -1, _T(""),
170 wxDefaultPosition
, wxDefaultSize
,
171 wxTE_MULTILINE
| wxTE_READONLY
| wxSUNKEN_BORDER
);
172 m_text
->SetFont(wxFont(14, wxROMAN
, wxNORMAL
, wxNORMAL
));
175 wxIcon
icon("wxICON_TIP");
177 #include "wx/generic/tip.xpm"
181 wxStaticBitmap
*bmp
= new wxStaticBitmap(this, -1, icon
);
183 const int iconSize
= icon
.GetWidth();
185 c
= new wxLayoutConstraints
;
186 c
->top
.SameAs(this, wxTop
, 2*LAYOUT_Y_MARGIN
);
187 c
->left
.RightOf(bmp
, 2*LAYOUT_X_MARGIN
);
188 c
->right
.SameAs(this, wxRight
, 2*LAYOUT_X_MARGIN
);
189 c
->height
.Absolute(2*text
->GetSize().GetHeight());
190 text
->SetConstraints(c
);
192 c
= new wxLayoutConstraints
;
193 c
->centreY
.SameAs(text
, wxCentreY
);
194 c
->left
.SameAs(this, wxLeft
, 2*LAYOUT_X_MARGIN
);
195 c
->width
.Absolute(iconSize
);
196 c
->height
.Absolute(iconSize
);
197 bmp
->SetConstraints(c
);
199 c
= new wxLayoutConstraints
;
200 c
->bottom
.SameAs(this, wxBottom
, 2*LAYOUT_X_MARGIN
);
201 c
->right
.SameAs(this, wxRight
, 2*LAYOUT_X_MARGIN
);
202 c
->width
.Absolute(sizeBtn
.GetWidth());
203 c
->height
.Absolute(sizeBtn
.GetHeight());
204 btnClose
->SetConstraints(c
);
206 c
= new wxLayoutConstraints
;
207 c
->bottom
.SameAs(this, wxBottom
, 2*LAYOUT_X_MARGIN
);
208 c
->right
.LeftOf(btnClose
, 2*LAYOUT_X_MARGIN
);
209 c
->width
.Absolute(sizeBtn
.GetWidth());
210 c
->height
.Absolute(sizeBtn
.GetHeight());
211 btnNext
->SetConstraints(c
);
213 c
= new wxLayoutConstraints
;
214 c
->bottom
.SameAs(this, wxBottom
, 2*LAYOUT_X_MARGIN
);
215 c
->left
.SameAs(this, wxLeft
, 2*LAYOUT_X_MARGIN
);
218 m_checkbox
->SetConstraints(c
);
219 m_checkbox
->SetValue(showAtStartup
);
221 c
= new wxLayoutConstraints
;
223 c
->left
.SameAs(this, wxLeft
, 2*LAYOUT_X_MARGIN
);
224 c
->right
.SameAs(this, wxRight
, 2*LAYOUT_X_MARGIN
);
225 c
->bottom
.Above(btnClose
, -2*LAYOUT_Y_MARGIN
);
226 m_text
->SetConstraints(c
);
230 Centre(wxBOTH
| wxCENTER_FRAME
);
232 wxSize
size(5*sizeBtn
.GetWidth(), 10*sizeBtn
.GetHeight());
234 SetSizeHints(size
.x
, size
.y
);
239 // ----------------------------------------------------------------------------
240 // our public interface
241 // ----------------------------------------------------------------------------
243 wxTipProvider
*wxCreateFileTipProvider(const wxString
& filename
,
246 return new wxFileTipProvider(filename
, currentTip
);
249 bool wxShowTip(wxWindow
*parent
,
250 wxTipProvider
*tipProvider
,
253 wxTipDialog
dlg(parent
, tipProvider
, showAtStartup
);
256 return dlg
.ShowTipsOnStartup();
259 #endif // wxUSE_STARTUP_TIPS