2 // Copyright 2005 The Android Open Source Project
4 // Log preferences modal dialog.
7 // For compilers that support precompilation, include "wx/wx.h".
9 // Otherwise, include all standard headers
14 #include "LogPrefsDialog.h"
15 #include "Preferences.h"
19 BEGIN_EVENT_TABLE(LogPrefsDialog, wxDialog)
20 EVT_CHECKBOX(IDC_LOG_PREFS_WRITE_FILE, LogPrefsDialog::OnWriteFile)
23 static const wxString gSpacerChoices[] = {
24 wxT("0"), wxT("1"), wxT("2")
26 static const wxString gPointSizes[] = {
27 wxT("4"), wxT("6"), wxT("8"), wxT("10"), wxT("12"), wxT("14"), wxT("16")
34 LogPrefsDialog::LogPrefsDialog(wxWindow* parent)
35 : wxDialog(parent, IDD_LOG_PREFS, wxT("Log Preferences"), wxDefaultPosition,
36 wxDefaultSize, wxDEFAULT_DIALOG_STYLE),
37 mHeaderFormat(kHFFull), mSingleLine(false), mExtraSpacing(0),
38 mUseColor(false), mFontMonospace(false), mDisplayMax(0), mPoolSizeKB(0)
45 * Destructor. Not much to do.
47 LogPrefsDialog::~LogPrefsDialog(void)
52 * Create all of the pages and add them to the notebook.
54 void LogPrefsDialog::CreateControls(void)
56 wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
57 wxBoxSizer* okCancelSizer = new wxBoxSizer(wxHORIZONTAL);
58 mNotebook.Create(this, wxID_ANY);
61 page = CreateFormatPage(&mNotebook);
62 mNotebook.AddPage(page, wxT("Format"), true);
63 page = CreateLimitsPage(&mNotebook);
64 mNotebook.AddPage(page, wxT("Limits"), false);
65 page = CreateFilesPage(&mNotebook);
66 mNotebook.AddPage(page, wxT("Files"), false);
68 // note to self: could use CreateButtonSizer here?
69 wxButton* cancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"),
70 wxDefaultPosition, wxDefaultSize, 0);
71 okCancelSizer->Add(cancel, 0, wxALL, kInterSpacing);
73 wxButton* ok = new wxButton(this, wxID_OK, wxT("&OK"),
74 wxDefaultPosition, wxDefaultSize, 0);
75 okCancelSizer->Add(ok, 0, wxALL, kInterSpacing);
77 mainSizer->Add(&mNotebook);
78 mainSizer->Add(okCancelSizer, 0, wxALIGN_RIGHT);
82 mainSizer->Fit(this); // shrink-to-fit
83 mainSizer->SetSizeHints(this); // define minimum size
87 * Transfer data from our members to the window controls.
89 bool LogPrefsDialog::TransferDataToWindow(void)
92 * Do standard dialog setup.
94 wxRadioButton* fmtFull = (wxRadioButton*) FindWindow(IDC_LOG_PREFS_FMT_FULL);
95 wxRadioButton* fmtBrief = (wxRadioButton*) FindWindow(IDC_LOG_PREFS_FMT_BRIEF);
96 wxRadioButton* fmtMinimal = (wxRadioButton*) FindWindow(IDC_LOG_PREFS_FMT_MINIMAL);
97 wxCheckBox* singleLine = (wxCheckBox*) FindWindow(IDC_LOG_PREFS_SINGLE_LINE);
98 wxComboBox* extraSpacing = (wxComboBox*) FindWindow(IDC_LOG_PREFS_EXTRA_SPACING);
99 wxComboBox* pointSize = (wxComboBox*) FindWindow(IDC_LOG_PREFS_POINT_SIZE);
100 wxCheckBox* useColor = (wxCheckBox*) FindWindow(IDC_LOG_PREFS_USE_COLOR);
101 wxCheckBox* fontMono = (wxCheckBox*) FindWindow(IDC_LOG_PREFS_FONT_MONO);
103 wxTextCtrl* displayMax = (wxTextCtrl*) FindWindow(IDC_LOG_PREFS_DISPLAY_MAX);
104 wxTextCtrl* poolSize = (wxTextCtrl*) FindWindow(IDC_LOG_PREFS_POOL_SIZE);
106 wxCheckBox* writeFile = (wxCheckBox*) FindWindow(IDC_LOG_PREFS_WRITE_FILE);
107 wxTextCtrl* fileName = (wxTextCtrl*) FindWindow(IDC_LOG_PREFS_FILENAME);
108 wxCheckBox* truncateOld = (wxCheckBox*) FindWindow(IDC_LOG_PREFS_TRUNCATE_OLD);
111 fmtFull->SetValue(mHeaderFormat == kHFFull);
112 fmtBrief->SetValue(mHeaderFormat == kHFBrief);
113 fmtMinimal->SetValue(mHeaderFormat == kHFMinimal);
114 singleLine->SetValue(mSingleLine);
115 if (mExtraSpacing < 0 || mExtraSpacing > NELEM(gSpacerChoices))
117 extraSpacing->SetSelection(mExtraSpacing);
119 pointSize->SetSelection(0);
120 for (int i = 0; i < NELEM(gPointSizes); i++) {
121 if (atoi(gPointSizes[i].ToAscii()) == mPointSize) {
122 pointSize->SetSelection(i);
126 useColor->SetValue(mUseColor);
127 fontMono->SetValue(mFontMonospace);
130 tmpStr.Printf(wxT("%d"), mDisplayMax);
131 displayMax->SetValue(tmpStr);
132 tmpStr.Printf(wxT("%d"), mPoolSizeKB);
133 poolSize->SetValue(tmpStr);
135 writeFile->SetValue(mWriteFile);
136 fileName->SetValue(mFileName);
137 truncateOld->SetValue(mTruncateOld);
139 EnableFileControls(mWriteFile);
145 * Convert a string to a number. The number is expected to be unsigned.
146 * Returns < 0 on failure.
148 static long ConvertUnsigned(const wxString& str)
151 if (!str.ToLong(&val))
157 * Transfer and validate data from the window controls.
159 * This doesn't get called if the user cancels out of the dialog.
161 bool LogPrefsDialog::TransferDataFromWindow(void)
164 * Do standard dialog export.
166 //wxRadioButton* fmtFull = (wxRadioButton*) FindWindow(IDC_LOG_PREFS_FMT_FULL);
167 wxRadioButton* fmtBrief = (wxRadioButton*) FindWindow(IDC_LOG_PREFS_FMT_BRIEF);
168 wxRadioButton* fmtMinimal = (wxRadioButton*) FindWindow(IDC_LOG_PREFS_FMT_MINIMAL);
169 wxCheckBox* singleLine = (wxCheckBox*) FindWindow(IDC_LOG_PREFS_SINGLE_LINE);
170 wxComboBox* extraSpacing = (wxComboBox*) FindWindow(IDC_LOG_PREFS_EXTRA_SPACING);
171 wxComboBox* pointSize = (wxComboBox*) FindWindow(IDC_LOG_PREFS_POINT_SIZE);
172 wxCheckBox* useColor = (wxCheckBox*) FindWindow(IDC_LOG_PREFS_USE_COLOR);
173 wxCheckBox* fontMono = (wxCheckBox*) FindWindow(IDC_LOG_PREFS_FONT_MONO);
175 wxTextCtrl* displayMax = (wxTextCtrl*) FindWindow(IDC_LOG_PREFS_DISPLAY_MAX);
176 wxTextCtrl* poolSize = (wxTextCtrl*) FindWindow(IDC_LOG_PREFS_POOL_SIZE);
178 wxCheckBox* writeFile = (wxCheckBox*) FindWindow(IDC_LOG_PREFS_WRITE_FILE);
179 wxTextCtrl* fileName = (wxTextCtrl*) FindWindow(IDC_LOG_PREFS_FILENAME);
180 wxCheckBox* truncateOld = (wxCheckBox*) FindWindow(IDC_LOG_PREFS_TRUNCATE_OLD);
183 mHeaderFormat = kHFFull;
184 if (fmtBrief->GetValue())
185 mHeaderFormat = kHFBrief;
186 else if (fmtMinimal->GetValue())
187 mHeaderFormat = kHFMinimal;
191 mSingleLine = (singleLine->GetValue() != 0);
192 mExtraSpacing = extraSpacing->GetSelection();
193 mPointSize = ConvertUnsigned(pointSize->GetValue());
194 mUseColor = useColor->GetValue();
195 mFontMonospace = fontMono->GetValue();
197 tmpStr = displayMax->GetValue();
198 mDisplayMax = ConvertUnsigned(tmpStr);
199 if (mDisplayMax <= 0 || mDisplayMax > 1000 * 1000) {
200 wxMessageBox(wxT("Bad value for display max -- must be > 0 and <= 1,000,000"),
201 wxT("Hoser"), wxOK, this);
205 tmpStr = poolSize->GetValue();
206 mPoolSizeKB = ConvertUnsigned(tmpStr);
207 if (mDisplayMax <= 0 || mDisplayMax > 1048576) {
208 wxMessageBox(wxT("Bad value for pool size -- must be > 0 and <= 1048576"),
209 wxT("Hoser"), wxOK, this);
213 mWriteFile = (writeFile->GetValue() != 0);
214 mFileName = fileName->GetValue();
215 mTruncateOld = (truncateOld->GetValue() != 0);
216 if (mWriteFile && mFileName.IsEmpty()) {
217 wxMessageBox(wxT("Log filename may not be blank"),
218 wxT("Hoser"), wxOK, this);
227 * Create the log Format page.
229 wxPanel* LogPrefsDialog::CreateFormatPage(wxBookCtrlBase* parent)
231 wxPanel* panel = new wxPanel(parent);
233 wxStaticBoxSizer* headerOpts = new wxStaticBoxSizer(wxVERTICAL, panel,
235 headerOpts->Add(new wxRadioButton(panel, IDC_LOG_PREFS_FMT_FULL,
236 wxT("Full header"), wxDefaultPosition, wxDefaultSize,
238 headerOpts->Add(new wxRadioButton(panel, IDC_LOG_PREFS_FMT_BRIEF,
239 wxT("Brief header")));
240 headerOpts->Add(new wxRadioButton(panel, IDC_LOG_PREFS_FMT_MINIMAL,
241 wxT("Minimal, integrated header")));
243 wxCheckBox* singleLine = new wxCheckBox(panel, IDC_LOG_PREFS_SINGLE_LINE,
244 wxT("Put headers and message on same line"));
246 wxStaticText* extraSpacingDescr = new wxStaticText(panel, wxID_STATIC,
247 wxT("Extra line spacing:"));
248 wxComboBox* extraSpacing = new wxComboBox(panel,
249 IDC_LOG_PREFS_EXTRA_SPACING, wxT("blah"),
250 wxDefaultPosition, wxDefaultSize, NELEM(gSpacerChoices),
251 gSpacerChoices, wxCB_READONLY);
252 wxBoxSizer* extraSpacingSizer = new wxBoxSizer(wxHORIZONTAL);
253 extraSpacingSizer->Add(extraSpacingDescr, 0, wxALIGN_CENTER_VERTICAL);
254 extraSpacingSizer->AddSpacer(kInterSpacing);
255 extraSpacingSizer->Add(extraSpacing);
257 wxStaticBoxSizer* textOpts = new wxStaticBoxSizer(wxVERTICAL, panel,
260 new wxStaticText(panel, wxID_STATIC, wxT("Point size:")) );
261 textOpts->AddSpacer(kInterSpacing);
263 new wxComboBox(panel,
264 IDC_LOG_PREFS_POINT_SIZE, wxT("blah"),
265 wxDefaultPosition, wxDefaultSize, NELEM(gPointSizes),
266 gPointSizes, wxCB_READONLY) );
267 textOpts->AddSpacer(kInterSpacing);
269 new wxCheckBox(panel, IDC_LOG_PREFS_USE_COLOR,
270 wxT("Colorful messages")) );
271 textOpts->AddSpacer(kInterSpacing);
273 new wxCheckBox(panel, IDC_LOG_PREFS_FONT_MONO,
274 wxT("Use monospace font")) );
277 wxBoxSizer* sizerPanel = new wxBoxSizer(wxVERTICAL);
278 sizerPanel->Add(kMinWidth, kEdgeSpacing); // forces minimum width
279 sizerPanel->Add(headerOpts);
280 sizerPanel->AddSpacer(kInterSpacing);
281 sizerPanel->Add(singleLine);
282 sizerPanel->AddSpacer(kInterSpacing);
283 sizerPanel->Add(extraSpacingSizer);
284 sizerPanel->AddSpacer(kInterSpacing);
285 sizerPanel->Add(textOpts);
286 sizerPanel->AddSpacer(kInterSpacing);
288 wxBoxSizer* horizIndent = new wxBoxSizer(wxHORIZONTAL);
289 horizIndent->AddSpacer(kEdgeSpacing);
290 horizIndent->Add(sizerPanel);
291 horizIndent->AddSpacer(kEdgeSpacing);
292 panel->SetSizer(horizIndent);
298 * Create the log Limits page.
300 wxPanel* LogPrefsDialog::CreateLimitsPage(wxBookCtrlBase* parent)
302 wxPanel* panel = new wxPanel(parent);
304 wxBoxSizer* displayMaxSizer = new wxBoxSizer(wxHORIZONTAL);
305 displayMaxSizer->Add(
306 new wxStaticText(panel, wxID_ANY,
307 wxT("Maximum entries in log window:"),
308 wxDefaultPosition, wxDefaultSize,
310 0, wxALIGN_CENTER_VERTICAL);
311 displayMaxSizer->AddSpacer(kInterSpacing);
312 displayMaxSizer->Add(
313 new wxTextCtrl(panel, IDC_LOG_PREFS_DISPLAY_MAX));
315 wxBoxSizer* poolSizeSizer = new wxBoxSizer(wxHORIZONTAL);
317 new wxStaticText(panel, wxID_ANY,
318 wxT("Size of the log pool (KB):"),
319 wxDefaultPosition, wxDefaultSize,
321 0, wxALIGN_CENTER_VERTICAL);
322 poolSizeSizer->AddSpacer(kInterSpacing);
324 new wxTextCtrl(panel, IDC_LOG_PREFS_POOL_SIZE));
327 wxBoxSizer* sizerPanel = new wxBoxSizer(wxVERTICAL);
328 sizerPanel->Add(kMinWidth, kEdgeSpacing); // forces minimum width
329 sizerPanel->Add(displayMaxSizer);
330 sizerPanel->AddSpacer(kInterSpacing);
331 sizerPanel->Add(poolSizeSizer);
332 sizerPanel->AddSpacer(kInterSpacing);
334 wxBoxSizer* horizIndent = new wxBoxSizer(wxHORIZONTAL);
335 horizIndent->AddSpacer(kEdgeSpacing);
336 horizIndent->Add(sizerPanel);
337 horizIndent->AddSpacer(kEdgeSpacing);
338 panel->SetSizer(horizIndent);
344 * Create the log Files page.
346 wxPanel* LogPrefsDialog::CreateFilesPage(wxBookCtrlBase* parent)
348 wxPanel* panel = new wxPanel(parent);
349 wxStaticBoxSizer* logOpts = new wxStaticBoxSizer(wxVERTICAL, panel,
352 wxCheckBox* writeCopy =
353 new wxCheckBox(panel, IDC_LOG_PREFS_WRITE_FILE,
354 wxT("Write a copy of log output to a file"));
356 logOpts->AddSpacer(kInterSpacing);
358 new wxStaticText(panel, wxID_ANY,
360 wxDefaultPosition, wxDefaultSize,
362 logOpts->AddSpacer(kInterSpacing);
364 new wxTextCtrl(panel, IDC_LOG_PREFS_FILENAME), 0, wxEXPAND);
365 logOpts->AddSpacer(kInterSpacing);
367 new wxCheckBox(panel, IDC_LOG_PREFS_TRUNCATE_OLD,
368 wxT("Truncate the file if more than 8 hours old ")) );
371 wxBoxSizer* sizerPanel = new wxBoxSizer(wxVERTICAL);
372 sizerPanel->Add(kMinWidth, kEdgeSpacing); // forces minimum width
373 sizerPanel->Add(writeCopy);
374 sizerPanel->AddSpacer(kInterSpacing);
375 sizerPanel->Add(logOpts);
376 sizerPanel->AddSpacer(kInterSpacing);
378 wxBoxSizer* horizIndent = new wxBoxSizer(wxHORIZONTAL);
379 horizIndent->AddSpacer(kEdgeSpacing);
380 horizIndent->Add(sizerPanel);
381 horizIndent->AddSpacer(kEdgeSpacing);
382 panel->SetSizer(horizIndent);
389 * Handle clicks on the "write file" checkbox.
391 void LogPrefsDialog::OnWriteFile(wxCommandEvent& event)
393 EnableFileControls(event.GetInt());
397 * Enable or disable some of the controls on the "file" page.
399 void LogPrefsDialog::EnableFileControls(bool enable)
401 FindWindow(IDC_LOG_PREFS_FILENAME)->Enable(enable);
402 FindWindow(IDC_LOG_PREFS_TRUNCATE_OLD)->Enable(enable);