]> git.saurik.com Git - wxWidgets.git/blame - samples/widgets/textctrl.cpp
Removed regextest :).
[wxWidgets.git] / samples / widgets / textctrl.cpp
CommitLineData
32b8ec41
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Program: wxWindows Widgets Sample
3// Name: textctrl.cpp
4// Purpose: part of the widgets sample showing wxTextCtrl
5// Author: Vadim Zeitlin
6// Created: 27.03.01
7// Id: $Id$
8// Copyright: (c) 2001 Vadim Zeitlin
9// License: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20// for compilers that support precompilation, includes "wx/wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
27// for all others, include the necessary headers
28#ifndef WX_PRECOMP
29 #include "wx/log.h"
30 #include "wx/timer.h"
31
3bb70c40 32 #include "wx/bitmap.h"
32b8ec41
VZ
33 #include "wx/button.h"
34 #include "wx/checkbox.h"
35 #include "wx/radiobox.h"
36 #include "wx/statbox.h"
37 #include "wx/stattext.h"
38 #include "wx/textctrl.h"
39#endif
40
41#include "wx/sizer.h"
42
43#include "widgets.h"
44
45#include "icons/text.xpm"
46
47// ----------------------------------------------------------------------------
48// constants
49// ----------------------------------------------------------------------------
50
51// control ids
52enum
53{
54 TextPage_Reset = 100,
55
56 TextPage_Set,
57 TextPage_Add,
58 TextPage_Insert,
59 TextPage_Clear,
60 TextPage_Load,
61
62 TextPage_Password,
63 TextPage_WrapLines,
64 TextPage_Textctrl
65};
66
67// textctrl line number radiobox values
68enum TextLines
69{
70 TextLines_Single,
71 TextLines_Multi
72};
73
64b54de8
VZ
74#ifdef __WXMSW__
75
76// textctrl kind values
77enum TextKind
78{
79 TextKind_Plain,
80 TextKind_Rich,
81 TextKind_Rich2
82};
83
84#endif // __WXMSW__
85
32b8ec41
VZ
86// default values for the controls
87static const struct ControlValues
88{
89 TextLines textLines;
90 bool password;
91 bool wraplines;
92 bool readonly;
64b54de8
VZ
93#ifdef __WXMSW__
94 TextKind textKind;
95#endif // __WXMSW__
32b8ec41
VZ
96} DEFAULTS =
97{
98 TextLines_Multi, // multiline
206d3a16
JS
99 false, // not password
100 true, // do wrap lines
101 false, // not readonly
64b54de8
VZ
102#ifdef __WXMSW__
103 TextKind_Plain // plain EDIT control
104#endif // __WXMSW__
32b8ec41
VZ
105};
106
107// ----------------------------------------------------------------------------
108// TextWidgetsPage
109// ----------------------------------------------------------------------------
110
111// Define a new frame type: this is going to be our main frame
112class TextWidgetsPage : public WidgetsPage
113{
114public:
115 // ctor(s) and dtor
116 TextWidgetsPage(wxNotebook *notebook, wxImageList *imaglist);
117 virtual ~TextWidgetsPage();
118
119protected:
120 // create an info text contorl
121 wxTextCtrl *CreateInfoText();
122
123 // create a horz sizer holding a static text and this text control
124 wxSizer *CreateTextWithLabelSizer(const wxString& label,
125 wxTextCtrl *text,
126 const wxString& label2 = wxEmptyString,
127 wxTextCtrl *text2 = NULL);
128
129 // event handlers
130 void OnButtonReset(wxCommandEvent& event);
131 void OnButtonClearLog(wxCommandEvent& event);
132
133 void OnButtonSet(wxCommandEvent& event);
134 void OnButtonAdd(wxCommandEvent& event);
135 void OnButtonInsert(wxCommandEvent& event);
136 void OnButtonClear(wxCommandEvent& event);
137 void OnButtonLoad(wxCommandEvent& event);
138
139 void OnButtonQuit(wxCommandEvent& event);
140
141 void OnText(wxCommandEvent& event);
142 void OnTextEnter(wxCommandEvent& event);
143
144 void OnCheckOrRadioBox(wxCommandEvent& event);
145
146 void OnUpdateUIClearButton(wxUpdateUIEvent& event);
147
148 void OnUpdateUIPasswordCheckbox(wxUpdateUIEvent& event);
149 void OnUpdateUIWrapLinesCheckbox(wxUpdateUIEvent& event);
150
151 void OnUpdateUIResetButton(wxUpdateUIEvent& event);
152
153 void OnIdle(wxIdleEvent& event);
154
155 // reset the textctrl parameters
156 void Reset();
157
158 // (re)create the textctrl
159 void CreateText();
160
161 // is the control currently single line?
162 bool IsSingleLine() const
163 {
164 return m_radioTextLines->GetSelection() == TextLines_Single;
165 }
166
167 // the controls
168 // ------------
169
170 // the radiobox to choose between single and multi line
171 wxRadioBox *m_radioTextLines;
172
173 // the checkboxes controlling text ctrl styles
174 wxCheckBox *m_chkPassword,
175 *m_chkWrapLines,
176 *m_chkReadonly;
177
64b54de8
VZ
178 // under MSW we test rich edit controls as well here
179#ifdef __WXMSW__
180 wxRadioBox *m_radioKind;
181#endif // __WXMSW__
182
32b8ec41
VZ
183 // the textctrl itself and the sizer it is in
184 wxTextCtrl *m_text;
185 wxSizer *m_sizerText;
186
187 // the information text zones
188 wxTextCtrl *m_textPosCur,
189 *m_textRowCur,
190 *m_textColCur,
191 *m_textPosLast,
192 *m_textLineLast,
193 *m_textSelFrom,
64b54de8
VZ
194 *m_textSelTo,
195 *m_textRange;
32b8ec41
VZ
196
197 // and the data to show in them
198 long m_posCur,
199 m_posLast,
200 m_selFrom,
201 m_selTo;
202
626117f7
VZ
203 wxString m_range10_20;
204
32b8ec41
VZ
205private:
206 // any class wishing to process wxWindows events must use this macro
5e173f35
GD
207 DECLARE_EVENT_TABLE()
208 DECLARE_WIDGETS_PAGE(TextWidgetsPage)
32b8ec41
VZ
209};
210
211// ----------------------------------------------------------------------------
212// event tables
213// ----------------------------------------------------------------------------
214
215BEGIN_EVENT_TABLE(TextWidgetsPage, WidgetsPage)
216 EVT_IDLE(TextWidgetsPage::OnIdle)
217
218 EVT_BUTTON(TextPage_Reset, TextWidgetsPage::OnButtonReset)
219
220 EVT_BUTTON(TextPage_Clear, TextWidgetsPage::OnButtonClear)
221 EVT_BUTTON(TextPage_Set, TextWidgetsPage::OnButtonSet)
222 EVT_BUTTON(TextPage_Add, TextWidgetsPage::OnButtonAdd)
223 EVT_BUTTON(TextPage_Insert, TextWidgetsPage::OnButtonInsert)
224 EVT_BUTTON(TextPage_Load, TextWidgetsPage::OnButtonLoad)
225
226 EVT_UPDATE_UI(TextPage_Clear, TextWidgetsPage::OnUpdateUIClearButton)
227
228 EVT_UPDATE_UI(TextPage_Password, TextWidgetsPage::OnUpdateUIPasswordCheckbox)
229 EVT_UPDATE_UI(TextPage_WrapLines, TextWidgetsPage::OnUpdateUIWrapLinesCheckbox)
230
231 EVT_UPDATE_UI(TextPage_Reset, TextWidgetsPage::OnUpdateUIResetButton)
232
233 EVT_TEXT(TextPage_Textctrl, TextWidgetsPage::OnText)
234 EVT_TEXT_ENTER(TextPage_Textctrl, TextWidgetsPage::OnTextEnter)
235
206d3a16
JS
236 EVT_CHECKBOX(wxID_ANY, TextWidgetsPage::OnCheckOrRadioBox)
237 EVT_RADIOBOX(wxID_ANY, TextWidgetsPage::OnCheckOrRadioBox)
32b8ec41
VZ
238END_EVENT_TABLE()
239
240// ============================================================================
241// implementation
242// ============================================================================
243
244IMPLEMENT_WIDGETS_PAGE(TextWidgetsPage, _T("Text"));
245
246// ----------------------------------------------------------------------------
247// TextWidgetsPage creation
248// ----------------------------------------------------------------------------
249
250TextWidgetsPage::TextWidgetsPage(wxNotebook *notebook, wxImageList *imaglist)
251 : WidgetsPage(notebook)
252{
253 imaglist->Add(wxBitmap(text_xpm));
254
255 // init everything
64b54de8
VZ
256#ifdef __WXMSW__
257 m_radioKind =
258#endif // __WXMSW__
32b8ec41
VZ
259 m_radioTextLines = (wxRadioBox *)NULL;
260
261 m_chkPassword =
262 m_chkWrapLines =
263 m_chkReadonly = (wxCheckBox *)NULL;
264
265 m_text =
266 m_textPosCur =
267 m_textRowCur =
268 m_textColCur =
269 m_textPosLast =
270 m_textLineLast =
271 m_textSelFrom =
64b54de8
VZ
272 m_textSelTo =
273 m_textRange = (wxTextCtrl *)NULL;
274
32b8ec41
VZ
275 m_sizerText = (wxSizer *)NULL;
276
277 m_posCur =
278 m_posLast =
279 m_selFrom =
280 m_selTo = -2; // not -1 which means "no selection"
281
282 // left pane
283 static const wxString modes[] =
284 {
285 _T("single line"),
286 _T("multi line"),
287 };
288
206d3a16
JS
289 wxStaticBox *box = new wxStaticBox(this, wxID_ANY, _T("&Set textctrl parameters"));
290 m_radioTextLines = new wxRadioBox(this, wxID_ANY, _T("&Number of lines:"),
32b8ec41
VZ
291 wxDefaultPosition, wxDefaultSize,
292 WXSIZEOF(modes), modes,
293 1, wxRA_SPECIFY_COLS);
294
295 wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
296
297 sizerLeft->Add(m_radioTextLines, 0, wxGROW | wxALL, 5);
298 sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
299
300 m_chkPassword = CreateCheckBoxAndAddToSizer(
301 sizerLeft, _T("&Password control"), TextPage_Password
302 );
303 m_chkWrapLines = CreateCheckBoxAndAddToSizer(
304 sizerLeft, _T("Line &wrap"), TextPage_WrapLines
305 );
306 m_chkReadonly = CreateCheckBoxAndAddToSizer(
307 sizerLeft, _T("&Read-only mode")
308 );
309
64b54de8
VZ
310#ifdef __WXMSW__
311 static const wxString kinds[] =
312 {
313 _T("plain edit"),
314 _T("rich edit"),
315 _T("rich edit 2.0"),
316 };
317
206d3a16 318 m_radioKind = new wxRadioBox(this, wxID_ANY, _T("Control &kind"),
64b54de8
VZ
319 wxDefaultPosition, wxDefaultSize,
320 WXSIZEOF(kinds), kinds,
321 1, wxRA_SPECIFY_COLS);
322
323 sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
324 sizerLeft->Add(m_radioKind, 0, wxGROW | wxALL, 5);
325#endif // __WXMSW__
326
32b8ec41 327 wxButton *btn = new wxButton(this, TextPage_Reset, _T("&Reset"));
7b127900 328 sizerLeft->Add(2, 2, 0, wxGROW | wxALL, 1); // spacer
32b8ec41
VZ
329 sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
330
331 // middle pane
206d3a16 332 wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY, _T("&Change contents:"));
32b8ec41
VZ
333 wxSizer *sizerMiddleUp = new wxStaticBoxSizer(box2, wxVERTICAL);
334
335 btn = new wxButton(this, TextPage_Set, _T("&Set text value"));
7b127900 336 sizerMiddleUp->Add(btn, 0, wxALL | wxGROW, 1);
32b8ec41
VZ
337
338 btn = new wxButton(this, TextPage_Add, _T("&Append text"));
7b127900 339 sizerMiddleUp->Add(btn, 0, wxALL | wxGROW, 1);
32b8ec41
VZ
340
341 btn = new wxButton(this, TextPage_Insert, _T("&Insert text"));
7b127900 342 sizerMiddleUp->Add(btn, 0, wxALL | wxGROW, 1);
32b8ec41
VZ
343
344 btn = new wxButton(this, TextPage_Load, _T("&Load file"));
7b127900 345 sizerMiddleUp->Add(btn, 0, wxALL | wxGROW, 1);
32b8ec41
VZ
346
347 btn = new wxButton(this, TextPage_Clear, _T("&Clear"));
7b127900 348 sizerMiddleUp->Add(btn, 0, wxALL | wxGROW, 1);
32b8ec41 349
206d3a16 350 wxStaticBox *box4 = new wxStaticBox(this, wxID_ANY, _T("&Info:"));
32b8ec41
VZ
351 wxSizer *sizerMiddleDown = new wxStaticBoxSizer(box4, wxVERTICAL);
352
353 m_textPosCur = CreateInfoText();
354 m_textRowCur = CreateInfoText();
355 m_textColCur = CreateInfoText();
356
357 wxSizer *sizerRow = new wxBoxSizer(wxHORIZONTAL);
358 sizerRow->Add(CreateTextWithLabelSizer
359 (
360 _T("Current pos:"),
361 m_textPosCur
362 ),
363 0, wxRIGHT, 5);
364 sizerRow->Add(CreateTextWithLabelSizer
365 (
366 _T("Col:"),
367 m_textColCur
368 ),
369 0, wxLEFT | wxRIGHT, 5);
370 sizerRow->Add(CreateTextWithLabelSizer
371 (
372 _T("Row:"),
373 m_textRowCur
374 ),
375 0, wxLEFT, 5);
376 sizerMiddleDown->Add(sizerRow, 0, wxALL, 5);
377
378 m_textLineLast = CreateInfoText();
379 m_textPosLast = CreateInfoText();
380 sizerMiddleDown->Add
381 (
382 CreateTextWithLabelSizer
383 (
384 _T("Number of lines:"),
385 m_textLineLast,
386 _T("Last position:"),
387 m_textPosLast
388 ),
389 0, wxALL, 5
390 );
391
392 m_textSelFrom = CreateInfoText();
393 m_textSelTo = CreateInfoText();
394 sizerMiddleDown->Add
395 (
396 CreateTextWithLabelSizer
397 (
398 _T("Selection: from"),
399 m_textSelFrom,
400 _T("to"),
401 m_textSelTo
402 ),
403 0, wxALL, 5
404 );
64b54de8 405
206d3a16 406 m_textRange = new wxTextCtrl(this, wxID_ANY, wxEmptyString,
64b54de8
VZ
407 wxDefaultPosition, wxDefaultSize,
408 wxTE_READONLY);
409 sizerMiddleDown->Add
410 (
411 CreateTextWithLabelSizer
412 (
413 _T("Range 10..20:"),
414 m_textRange
415 ),
416 0, wxALL, 5
417 );
418
32b8ec41
VZ
419 wxSizer *sizerMiddle = new wxBoxSizer(wxVERTICAL);
420 sizerMiddle->Add(sizerMiddleUp, 0, wxGROW);
421 sizerMiddle->Add(sizerMiddleDown, 1, wxGROW | wxTOP, 5);
422
423 // right pane
206d3a16 424 wxStaticBox *box3 = new wxStaticBox(this, wxID_ANY, _T("&Text:"));
32b8ec41
VZ
425 m_sizerText = new wxStaticBoxSizer(box3, wxHORIZONTAL);
426 Reset();
427 CreateText();
7b127900 428 m_sizerText->SetMinSize(150, 0);
32b8ec41
VZ
429
430 // the 3 panes panes compose the upper part of the window
431 wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
432 sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10);
433 sizerTop->Add(sizerMiddle, 0, wxGROW | wxALL, 10);
434 sizerTop->Add(m_sizerText, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
435
32b8ec41
VZ
436 SetSizer(sizerTop);
437
438 sizerTop->Fit(this);
439}
440
441TextWidgetsPage::~TextWidgetsPage()
442{
443}
444
445// ----------------------------------------------------------------------------
446// creation helpers
447// ----------------------------------------------------------------------------
448
449wxTextCtrl *TextWidgetsPage::CreateInfoText()
450{
451 static int s_maxWidth = 0;
452 if ( !s_maxWidth )
453 {
454 // calc it once only
455 GetTextExtent(_T("9999999"), &s_maxWidth, NULL);
456 }
457
206d3a16 458 wxTextCtrl *text = new wxTextCtrl(this, wxID_ANY, wxEmptyString,
32b8ec41
VZ
459 wxDefaultPosition,
460 wxSize(s_maxWidth, -1),
461 wxTE_READONLY);
462 return text;
463}
464
465wxSizer *TextWidgetsPage::CreateTextWithLabelSizer(const wxString& label,
466 wxTextCtrl *text,
467 const wxString& label2,
468 wxTextCtrl *text2)
469{
470 wxSizer *sizerRow = new wxBoxSizer(wxHORIZONTAL);
206d3a16 471 sizerRow->Add(new wxStaticText(this, wxID_ANY, label), 0,
32b8ec41
VZ
472 wxALIGN_CENTRE_VERTICAL | wxRIGHT, 5);
473 sizerRow->Add(text, 0, wxALIGN_CENTRE_VERTICAL);
474 if ( text2 )
475 {
206d3a16 476 sizerRow->Add(new wxStaticText(this, wxID_ANY, label2), 0,
32b8ec41
VZ
477 wxALIGN_CENTRE_VERTICAL | wxLEFT | wxRIGHT, 5);
478 sizerRow->Add(text2, 0, wxALIGN_CENTRE_VERTICAL);
479 }
480
481 return sizerRow;
482}
483
484// ----------------------------------------------------------------------------
485// operations
486// ----------------------------------------------------------------------------
487
488void TextWidgetsPage::Reset()
489{
490 m_radioTextLines->SetSelection(DEFAULTS.textLines);
491 m_chkPassword->SetValue(DEFAULTS.password);
492 m_chkWrapLines->SetValue(DEFAULTS.wraplines);
493 m_chkReadonly->SetValue(DEFAULTS.readonly);
64b54de8
VZ
494#ifdef __WXMSW__
495 m_radioKind->SetSelection(DEFAULTS.textKind);
496#endif // __WXMSW__
32b8ec41
VZ
497}
498
499void TextWidgetsPage::CreateText()
500{
501 int flags = 0;
502 switch ( m_radioTextLines->GetSelection() )
503 {
504 default:
64b54de8 505 wxFAIL_MSG( _T("unexpected lines radio box selection") );
32b8ec41
VZ
506
507 case TextLines_Single:
508 break;
509
510 case TextLines_Multi:
511 flags |= wxTE_MULTILINE;
206d3a16 512 m_chkPassword->SetValue(false);
32b8ec41
VZ
513 break;
514 }
515
516 if ( m_chkPassword->GetValue() )
517 flags |= wxTE_PASSWORD;
518 if ( m_chkReadonly->GetValue() )
519 flags |= wxTE_READONLY;
520 if ( !m_chkWrapLines->GetValue() )
521 flags |= wxHSCROLL;
522
64b54de8
VZ
523#ifdef __WXMSW__
524 switch ( m_radioKind->GetSelection() )
525 {
526 default:
527 wxFAIL_MSG( _T("unexpected kind radio box selection") );
528
529 case TextKind_Plain:
530 break;
531
532 case TextKind_Rich:
533 flags |= wxTE_RICH;
534 break;
535
536 case TextKind_Rich2:
537 flags |= wxTE_RICH2;
538 break;
539 }
540#endif // __WXMSW__
541
32b8ec41
VZ
542 wxString valueOld;
543 if ( m_text )
544 {
545 valueOld = m_text->GetValue();
546
12a3f227 547 m_sizerText->Detach( m_text );
32b8ec41
VZ
548 delete m_text;
549 }
550 else
551 {
552 valueOld = _T("Hello, Universe!");
553 }
554
555 m_text = new wxTextCtrl(this, TextPage_Textctrl,
556 valueOld,
557 wxDefaultPosition, wxDefaultSize,
558 flags);
72383a72
VZ
559
560 // cast to int needed to silence gcc warning about different enums
32b8ec41 561 m_sizerText->Add(m_text, 1, wxALL |
72383a72 562 (flags & wxTE_MULTILINE ? (int)wxGROW
32b8ec41
VZ
563 : wxALIGN_TOP), 5);
564 m_sizerText->Layout();
565}
566
567// ----------------------------------------------------------------------------
568// event handlers
569// ----------------------------------------------------------------------------
570
571void TextWidgetsPage::OnIdle(wxIdleEvent& WXUNUSED(event))
572{
573 // update all info texts
574
575 if ( m_textPosCur )
576 {
577 long posCur = m_text->GetInsertionPoint();
578 if ( posCur != m_posCur )
579 {
580 m_textPosCur->Clear();
581 m_textRowCur->Clear();
582 m_textColCur->Clear();
583
584 long col, row;
585 m_text->PositionToXY(posCur, &col, &row);
586
587 *m_textPosCur << posCur;
588 *m_textRowCur << row;
589 *m_textColCur << col;
590
591 m_posCur = posCur;
592 }
593 }
594
595 if ( m_textPosLast )
596 {
597 long posLast = m_text->GetLastPosition();
598 if ( posLast != m_posLast )
599 {
600 m_textPosLast->Clear();
601 *m_textPosLast << posLast;
602
603 m_posLast = posLast;
604 }
605 }
606
607 if ( m_textLineLast )
608 {
609 m_textLineLast->SetValue(
aec18ff7 610 wxString::Format(_T("%d"), m_text->GetNumberOfLines()) );
32b8ec41
VZ
611 }
612
613 if ( m_textSelFrom && m_textSelTo )
614 {
615 long selFrom, selTo;
616 m_text->GetSelection(&selFrom, &selTo);
617 if ( selFrom != m_selFrom )
618 {
619 m_textSelFrom->Clear();
620 *m_textSelFrom << selFrom;
621
622 m_selFrom = selFrom;
623 }
624
625 if ( selTo != m_selTo )
626 {
627 m_textSelTo->Clear();
628 *m_textSelTo << selTo;
629
630 m_selTo = selTo;
631 }
632 }
64b54de8
VZ
633
634 if ( m_textRange )
635 {
626117f7
VZ
636 wxString range = m_text->GetRange(10, 20);
637 if ( range != m_range10_20 )
638 {
639 m_range10_20 = range;
640 m_textRange->SetValue(range);
641 }
64b54de8 642 }
32b8ec41
VZ
643}
644
645void TextWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
646{
647 Reset();
648
649 CreateText();
650}
651
652void TextWidgetsPage::OnButtonSet(wxCommandEvent& WXUNUSED(event))
653{
64b54de8
VZ
654 m_text->SetValue(m_text->GetWindowStyle() & wxTE_MULTILINE
655 ? _T("Here,\nthere and\neverywhere")
656 : _T("Yellow submarine"));
657
32b8ec41
VZ
658 m_text->SetFocus();
659}
660
661void TextWidgetsPage::OnButtonAdd(wxCommandEvent& WXUNUSED(event))
662{
64b54de8
VZ
663 if ( m_text->GetWindowStyle() & wxTE_MULTILINE )
664 {
665 m_text->AppendText(_T("We all live in a\n"));
666 }
667
668 m_text->AppendText(_T("Yellow submarine"));
32b8ec41
VZ
669}
670
671void TextWidgetsPage::OnButtonInsert(wxCommandEvent& WXUNUSED(event))
672{
64b54de8
VZ
673 m_text->WriteText(_T("Is there anybody going to listen to my story"));
674 if ( m_text->GetWindowStyle() & wxTE_MULTILINE )
675 {
676 m_text->WriteText(_T("\nall about the girl who came to stay"));
677 }
32b8ec41
VZ
678}
679
680void TextWidgetsPage::OnButtonClear(wxCommandEvent& WXUNUSED(event))
681{
682 m_text->Clear();
683 m_text->SetFocus();
684}
685
686void TextWidgetsPage::OnButtonLoad(wxCommandEvent& WXUNUSED(event))
687{
688 // search for the file in several dirs where it's likely to be
689 wxPathList pathlist;
690 pathlist.Add(_T("."));
691 pathlist.Add(_T(".."));
692 pathlist.Add(_T("../../../samples/widgets"));
693
694 wxString filename = pathlist.FindValidPath(_T("textctrl.cpp"));
695 if ( !filename )
696 {
697 wxLogError(_T("File textctrl.cpp not found."));
698 }
699 else // load it
700 {
701 wxStopWatch sw;
702 if ( !m_text->LoadFile(filename) )
703 {
704 // this is not supposed to happen ...
705 wxLogError(_T("Error loading file."));
706 }
707 else
708 {
709 long elapsed = sw.Time();
aec18ff7 710 wxLogMessage(_T("Loaded file '%s' in %lu.%us"),
8b1d8f36
VZ
711 filename.c_str(), elapsed / 1000,
712 (unsigned int) elapsed % 1000);
32b8ec41
VZ
713 }
714 }
715}
716
717void TextWidgetsPage::OnUpdateUIClearButton(wxUpdateUIEvent& event)
718{
719 event.Enable(!m_text->GetValue().empty());
720}
721
722void TextWidgetsPage::OnUpdateUIWrapLinesCheckbox(wxUpdateUIEvent& event)
723{
724 event.Enable( !IsSingleLine() );
725}
726
727void TextWidgetsPage::OnUpdateUIPasswordCheckbox(wxUpdateUIEvent& event)
728{
729 // can't put multiline control in password mode
730 event.Enable( IsSingleLine() );
731}
732
733void TextWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event)
734{
735 event.Enable( (m_radioTextLines->GetSelection() != DEFAULTS.textLines) ||
64b54de8
VZ
736#ifdef __WXMSW__
737 (m_radioKind->GetSelection() != DEFAULTS.textKind) ||
738#endif // __WXMSW__
32b8ec41
VZ
739 (m_chkReadonly->GetValue() != DEFAULTS.readonly) ||
740 (m_chkPassword->GetValue() != DEFAULTS.password) ||
741 (m_chkWrapLines->GetValue() != DEFAULTS.wraplines) );
742}
743
c02e5a31 744void TextWidgetsPage::OnText(wxCommandEvent& WXUNUSED(event))
32b8ec41
VZ
745{
746 // small hack to suppress the very first message: by then the logging is
747 // not yet redirected and so initial setting of the text value results in
748 // an annoying message box
206d3a16 749 static bool s_firstTime = true;
32b8ec41
VZ
750 if ( s_firstTime )
751 {
206d3a16 752 s_firstTime = false;
32b8ec41
VZ
753 return;
754 }
755
756 wxLogMessage(_T("Text ctrl value changed"));
757}
758
759void TextWidgetsPage::OnTextEnter(wxCommandEvent& event)
760{
761 wxLogMessage(_T("Text entered: '%s'"), event.GetString().c_str());
762}
763
c02e5a31 764void TextWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
32b8ec41
VZ
765{
766 CreateText();
767}
72383a72 768