1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676
|
/////////////////////////////////////////////////////////////////////////////
// Name: validate.cpp
// Purpose: wxWidgets validator sample
// Author: Julian Smart
// Modified by:
// Created: 04/01/98
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// See online help for an overview of validators. In general, a
// validator transfers data between a control and a variable.
// It may also test for validity of a string transferred to or
// from a text control. All validators transfer data, but not
// all test validity, so don't be confused by the name.
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif // WX_PRECOMP
#include "validate.h"
#include "wx/sizer.h"
#include "wx/valgen.h"
#include "wx/valtext.h"
#include "wx/valnum.h"
#ifndef wxHAS_IMAGES_IN_RESOURCES
#include "../sample.xpm"
#endif
// ----------------------------------------------------------------------------
// Global data
// ----------------------------------------------------------------------------
wxString g_listbox_choices[] =
{"one", "two", "three"};
wxString g_combobox_choices[] =
{"yes", "no (doesn't validate)", "maybe (doesn't validate)"};
wxString g_radiobox_choices[] =
{"green", "yellow", "red"};
MyData g_data;
// ----------------------------------------------------------------------------
// MyData
// ----------------------------------------------------------------------------
MyData::MyData()
{
// This string will be passed to an alpha-only validator, which
// will complain because spaces aren't alpha. Note that validation
// is performed only when 'OK' is pressed.
m_string = "Spaces are invalid here";
m_string2 = "Valid text";
m_listbox_choices.Add(0);
m_combobox_choice = g_combobox_choices[0];
m_intValue = 0;
m_smallIntValue = 3;
m_doubleValue = 12354.31;
m_percentValue = 0.25;
}
// ----------------------------------------------------------------------------
// MyComboBoxValidator
// ----------------------------------------------------------------------------
bool MyComboBoxValidator::Validate(wxWindow *WXUNUSED(parent))
{
wxASSERT(GetWindow()->IsKindOf(CLASSINFO(wxComboBox)));
wxComboBox* cb = (wxComboBox*)GetWindow();
if (cb->GetValue() == g_combobox_choices[1] ||
cb->GetValue() == g_combobox_choices[2])
{
// we accept any string != g_combobox_choices[1|2] !
wxLogError("Invalid combo box text!");
return false;
}
if (m_var)
*m_var = cb->GetValue();
return true;
}
bool MyComboBoxValidator::TransferToWindow()
{
wxASSERT(GetWindow()->IsKindOf(CLASSINFO(wxComboBox)));
if ( m_var )
{
wxComboBox* cb = (wxComboBox*)GetWindow();
if ( !cb )
return false;
cb->SetValue(*m_var);
}
return true;
}
bool MyComboBoxValidator::TransferFromWindow()
{
wxASSERT(GetWindow()->IsKindOf(CLASSINFO(wxComboBox)));
if ( m_var )
{
wxComboBox* cb = (wxComboBox*)GetWindow();
if ( !cb )
return false;
*m_var = cb->GetValue();
}
return true;
}
// ----------------------------------------------------------------------------
// MyApp
// ----------------------------------------------------------------------------
wxIMPLEMENT_APP(MyApp);
bool MyApp::OnInit()
{
if ( !wxApp::OnInit() )
return false;
// Create and display the main frame window.
MyFrame *frame = new MyFrame((wxFrame *) NULL, "Validator Test",
50, 50, 300, 250);
frame->Show(true);
return true;
}
// ----------------------------------------------------------------------------
// MyFrame
// ----------------------------------------------------------------------------
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
EVT_MENU(VALIDATE_TEST_DIALOG, MyFrame::OnTestDialog)
EVT_MENU(VALIDATE_TOGGLE_BELL, MyFrame::OnToggleBell)
wxEND_EVENT_TABLE()
MyFrame::MyFrame(wxFrame *frame, const wxString&title, int x, int y, int w, int h)
: wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h)),
m_silent(true)
{
SetIcon(wxICON(sample));
// Create a listbox to display the validated data.
m_listbox = new wxListBox(this, wxID_ANY);
m_listbox->Append(wxString("Try 'File|Test' to see how validators work."));
wxMenu *file_menu = new wxMenu;
file_menu->Append(VALIDATE_TEST_DIALOG, "&Test dialog...\tCtrl-T", "Demonstrate validators");
file_menu->AppendCheckItem(VALIDATE_TOGGLE_BELL, "&Bell on error", "Toggle bell on error");
file_menu->AppendSeparator();
file_menu->Append(wxID_EXIT, "E&xit");
wxMenuBar *menu_bar = new wxMenuBar;
menu_bar->Append(file_menu, "&File");
SetMenuBar(menu_bar);
// All validators share a common (static) flag that controls
// whether they beep on error. Here we turn it off:
wxValidator::SuppressBellOnError(m_silent);
file_menu->Check(VALIDATE_TOGGLE_BELL, !wxValidator::IsSilent());
#if wxUSE_STATUSBAR
CreateStatusBar(1);
#endif // wxUSE_STATUSBAR
}
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
Close(true);
}
void MyFrame::OnTestDialog(wxCommandEvent& WXUNUSED(event))
{
// The validators defined in the dialog implementation bind controls
// and variables together. Values are transferred between them behind
// the scenes, so here we don't have to query the controls for their
// values.
MyDialog dialog(this, "Validator demonstration");
// When the dialog is displayed, validators automatically transfer
// data from variables to their corresponding controls.
if ( dialog.ShowModal() == wxID_OK )
{
// 'OK' was pressed, so controls that have validators are
// automatically transferred to the variables we specified
// when we created the validators.
m_listbox->Clear();
m_listbox->Append(wxString("string: ") + g_data.m_string);
m_listbox->Append(wxString("string #2: ") + g_data.m_string2);
for(unsigned int i = 0; i < g_data.m_listbox_choices.GetCount(); ++i)
{
int j = g_data.m_listbox_choices[i];
m_listbox->Append(wxString("listbox choice(s): ") + g_listbox_choices[j]);
}
wxString checkbox_state(g_data.m_checkbox_state ? "checked" : "unchecked");
m_listbox->Append(wxString("checkbox: ") + checkbox_state);
m_listbox->Append(wxString("combobox: ") + g_data.m_combobox_choice);
m_listbox->Append(wxString("radiobox: ") + g_radiobox_choices[g_data.m_radiobox_choice]);
m_listbox->Append(wxString::Format("integer value: %d", g_data.m_intValue));
m_listbox->Append(wxString::Format("small int value: %u", g_data.m_smallIntValue));
m_listbox->Append(wxString::Format("double value: %.3f", g_data.m_doubleValue));
m_listbox->Append(wxString::Format("percent value: %.4f", double(g_data.m_percentValue)));
}
}
void MyFrame::OnToggleBell(wxCommandEvent& event)
{
m_silent = !m_silent;
wxValidator::SuppressBellOnError(m_silent);
event.Skip();
}
// ----------------------------------------------------------------------------
// MyDialog
// ----------------------------------------------------------------------------
MyDialog::MyDialog( wxWindow *parent, const wxString& title,
const wxPoint& pos, const wxSize& size, const long WXUNUSED(style) ) :
wxDialog(parent, VALIDATE_DIALOG_ID, title, pos, size, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
{
// setup the flex grid sizer
// -------------------------
wxFlexGridSizer *flexgridsizer = new wxFlexGridSizer(3, 2, 5, 5);
// Create and add controls to sizers.
// Pointers to some of these controls are saved in member variables
// so that we can use them elsewhere, like this one.
m_text = new wxTextCtrl(this, VALIDATE_TEXT);
m_text->SetToolTip("wxTextValidator not set");
m_text->SetHint("Enter some text here, please...");
flexgridsizer->Add(m_text, 1, wxGROW);
// Make it possible to change the wxTextValidator for m_text at runtime.
wxButton* const button =
new wxButton(this, wxID_ANY, "Set new wxTextValidator...");
button->Bind(wxEVT_BUTTON, &MyDialog::OnChangeValidator, this);
flexgridsizer->Add(button, wxSizerFlags().Center());
flexgridsizer->Add(new wxListBox((wxWindow*)this, VALIDATE_LIST,
wxDefaultPosition, wxDefaultSize,
3, g_listbox_choices, wxLB_MULTIPLE,
wxGenericValidator(&g_data.m_listbox_choices)),
1, wxGROW);
m_combobox = new wxComboBox(this, VALIDATE_COMBO, wxEmptyString,
wxDefaultPosition, wxDefaultSize,
3, g_combobox_choices, 0L,
MyComboBoxValidator(&g_data.m_combobox_choice));
m_combobox->SetToolTip("uses a custom validator (MyComboBoxValidator)");
flexgridsizer->Add(m_combobox, 1, wxALIGN_CENTER);
// This wxCheckBox* doesn't need to be assigned to any pointer
// because we don't use it elsewhere--it can be anonymous.
// We don't need any such pointer to query its state, which
// can be gotten directly from g_data.
flexgridsizer->Add(new wxCheckBox(this, VALIDATE_CHECK, "Sample checkbox",
wxDefaultPosition, wxDefaultSize, 0,
wxGenericValidator(&g_data.m_checkbox_state)),
1, wxALIGN_CENTER|wxALL, 15);
flexgridsizer->AddGrowableCol(0);
flexgridsizer->AddGrowableCol(1);
flexgridsizer->AddGrowableRow(1);
// setup a sizer with the controls for numeric validators
// ------------------------------------------------------
wxFlexGridSizer* const
numSizer = new wxFlexGridSizer(5, FromDIP(wxSize(5, 5)));
const wxSizerFlags center = wxSizerFlags().CenterVertical();
wxIntegerValidator<int> valInt(&g_data.m_intValue,
wxNUM_VAL_THOUSANDS_SEPARATOR |
wxNUM_VAL_ZERO_AS_BLANK);
valInt.SetMin(0); // Only allow positive numbers
m_numericTextInt = new wxTextCtrl
(
this,
wxID_ANY,
"",
wxDefaultPosition,
wxDefaultSize,
wxTE_RIGHT,
valInt
);
numSizer->Add(new wxStaticText(this, wxID_ANY, "Positive integer:"),
center);
numSizer->Add(m_numericTextInt, wxSizerFlags(center).Expand());
numSizer->AddSpacer(FromDIP(10));
m_numericTextDouble = new wxTextCtrl
(
this,
wxID_ANY,
"",
wxDefaultPosition,
wxDefaultSize,
wxTE_RIGHT,
wxMakeFloatingPointValidator
(
3,
&g_data.m_doubleValue,
wxNUM_VAL_THOUSANDS_SEPARATOR |
wxNUM_VAL_NO_TRAILING_ZEROES
)
);
numSizer->Add(new wxStaticText(this, wxID_ANY, "Up to 3 decimals:"),
center);
numSizer->Add(m_numericTextDouble, wxSizerFlags(center).Expand());
wxIntegerValidator<unsigned short> smallIntVal(&g_data.m_smallIntValue);
smallIntVal.SetRange(1, 5);
numSizer->Add(new wxStaticText(this, wxID_ANY, "Int between 1 and 5:"),
center);
numSizer->Add(new wxTextCtrl(this, wxID_ANY, "",
wxDefaultPosition, wxDefaultSize, wxTE_RIGHT,
smallIntVal),
wxSizerFlags(center).Expand());
numSizer->AddSpacer(FromDIP(10));
wxFloatingPointValidator<float> percentVal(&g_data.m_percentValue);
percentVal.SetPrecision(2);
percentVal.SetFactor(100.0);
numSizer->Add(new wxStaticText(this, wxID_ANY, "Value displayed in %:"),
center);
numSizer->Add(new wxTextCtrl(this, wxID_ANY, "",
wxDefaultPosition, wxDefaultSize, wxTE_RIGHT,
percentVal),
wxSizerFlags(center).Expand());
// setup the main sizer
// --------------------
wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL );
mainsizer->Add(flexgridsizer, 1, wxGROW | wxALL, 10);
mainsizer->Add(new wxRadioBox((wxWindow*)this, VALIDATE_RADIO, "Pick a color",
wxDefaultPosition, wxDefaultSize,
3, g_radiobox_choices, 1, wxRA_SPECIFY_ROWS,
wxGenericValidator(&g_data.m_radiobox_choice)),
0, wxGROW | wxLEFT|wxBOTTOM|wxRIGHT, 10);
mainsizer->Add( numSizer, wxSizerFlags().Expand().DoubleBorder() );
mainsizer->Add(CreateButtonSizer(wxOK | wxCANCEL),
wxSizerFlags().Expand().DoubleBorder());
SetSizer(mainsizer);
mainsizer->SetSizeHints(this);
// make the dialog a bit bigger than its minimal size:
SetSize(GetBestSize()*1.5);
// Now sets the focus to m_text
m_text->SetFocus();
}
void MyDialog::OnChangeValidator(wxCommandEvent& WXUNUSED(event))
{
TextValidatorDialog dialog(this, m_text);
if ( dialog.ShowModal() == wxID_OK )
{
dialog.ApplyValidator();
}
}
// ----------------------------------------------------------------------------
// TextValidatorDialog
// ----------------------------------------------------------------------------
TextValidatorDialog::TextValidatorDialog(wxWindow *parent, wxTextCtrl* txtCtrl)
: wxDialog(parent, wxID_ANY, "wxTextValidator Dialog"),
m_txtCtrl(txtCtrl),
m_noValidation(true),
m_validatorStyle(wxFILTER_NONE)
{
if ( m_txtCtrl )
{
wxTextValidator* txtValidator =
wxDynamicCast(m_txtCtrl->GetValidator(), wxTextValidator);
if ( txtValidator )
{
m_validatorStyle = txtValidator->GetStyle();
if ( m_validatorStyle != wxFILTER_NONE )
m_noValidation = false;
m_charIncludes = txtValidator->GetCharIncludes();
m_charExcludes = txtValidator->GetCharExcludes();
m_includes = txtValidator->GetIncludes();
m_excludes = txtValidator->GetExcludes();
}
}
wxFlexGridSizer *fgSizer = new wxFlexGridSizer(2, FromDIP(wxSize(5, 5)));
const wxSizerFlags center = wxSizerFlags().CenterVertical();
const StyleValidator styleVal(&m_validatorStyle);
wxCheckBox* filterNone = new wxCheckBox(this, Id_None, "wxFILTER_NONE");
filterNone->SetValue(m_noValidation);
fgSizer->Add(filterNone);
fgSizer->Add(new wxStaticText(this, wxID_ANY, "No filtering takes place."));
fgSizer->Add(new wxCheckBox(this, Id_Empty, "wxFILTER_EMPTY"))
->GetWindow()->SetValidator(styleVal);
fgSizer->Add(new wxStaticText(this, wxID_ANY, "Empty strings are filtered out."));
fgSizer->Add(new wxCheckBox(this, Id_Ascii, "wxFILTER_ASCII"))
->GetWindow()->SetValidator(styleVal);
fgSizer->Add(new wxStaticText(this, wxID_ANY, "Non-ASCII characters are filtered out."));
fgSizer->Add(new wxCheckBox(this, Id_Alpha, "wxFILTER_ALPHA"))
->GetWindow()->SetValidator(styleVal);
fgSizer->Add(new wxStaticText(this, wxID_ANY, "Non-alpha characters are filtered out."));
fgSizer->Add(new wxCheckBox(this, Id_Alphanumeric, "wxFILTER_ALPHANUMERIC"))
->GetWindow()->SetValidator(styleVal);
fgSizer->Add(new wxStaticText(this, wxID_ANY, "Non-alphanumeric characters are filtered out."));
fgSizer->Add(new wxCheckBox(this, Id_Digits, "wxFILTER_DIGITS"))
->GetWindow()->SetValidator(styleVal);
fgSizer->Add(new wxStaticText(this, wxID_ANY, "Non-digit characters are filtered out."));
fgSizer->Add(new wxCheckBox(this, Id_Numeric, "wxFILTER_NUMERIC"))
->GetWindow()->SetValidator(styleVal);
fgSizer->Add(new wxStaticText(this, wxID_ANY, "Non-numeric characters are filtered out."));
fgSizer->Add(new wxCheckBox(this, Id_IncludeList, "wxFILTER_INCLUDE_LIST"), center)
->GetWindow()->SetValidator(styleVal);
fgSizer->Add(new wxTextCtrl(this, Id_IncludeListTxt), wxSizerFlags().Expand())
->GetWindow()->Bind(wxEVT_KILL_FOCUS, &TextValidatorDialog::OnKillFocus, this);
fgSizer->Add(new wxCheckBox(this, Id_IncludeCharList, "wxFILTER_INCLUDE_CHAR_LIST"), center)
->GetWindow()->SetValidator(styleVal);
fgSizer->Add(new wxTextCtrl(this, Id_IncludeCharListTxt, wxString(), wxDefaultPosition,
wxDefaultSize, 0, wxGenericValidator(&m_charIncludes)),
wxSizerFlags().Expand())
->GetWindow()->Bind(wxEVT_KILL_FOCUS, &TextValidatorDialog::OnKillFocus, this);
fgSizer->Add(new wxCheckBox(this, Id_ExcludeList, "wxFILTER_EXCLUDE_LIST"), center)
->GetWindow()->SetValidator(styleVal);
fgSizer->Add(new wxTextCtrl(this, Id_ExcludeListTxt), wxSizerFlags().Expand())
->GetWindow()->Bind(wxEVT_KILL_FOCUS, &TextValidatorDialog::OnKillFocus, this);
fgSizer->Add(new wxCheckBox(this, Id_ExcludeCharList, "wxFILTER_EXCLUDE_CHAR_LIST"), center)
->GetWindow()->SetValidator(styleVal);
fgSizer->Add(new wxTextCtrl(this, Id_ExcludeCharListTxt, wxString(), wxDefaultPosition,
wxDefaultSize, 0, wxGenericValidator(&m_charExcludes)),
wxSizerFlags().Expand())
->GetWindow()->Bind(wxEVT_KILL_FOCUS, &TextValidatorDialog::OnKillFocus, this);
fgSizer->Add(new wxCheckBox(this, Id_Xdigits, "wxFILTER_XDIGITS"))
->GetWindow()->SetValidator(styleVal);
fgSizer->Add(new wxStaticText(this, wxID_ANY, "Non-xdigit characters are filtered out."));
fgSizer->Add(new wxCheckBox(this, Id_Space, "wxFILTER_SPACE"))
->GetWindow()->SetValidator(styleVal);
fgSizer->Add(new wxStaticText(this, wxID_ANY, "Allow spaces."));
// Set the main sizer.
wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL );
mainsizer->Add(fgSizer, wxSizerFlags(1).Border(wxALL, 10).Expand());
mainsizer->Add(CreateButtonSizer(wxOK | wxCANCEL),
wxSizerFlags().Expand().DoubleBorder());
SetSizer(mainsizer);
mainsizer->SetSizeHints(this);
// Bind event handlers.
Bind(wxEVT_CHECKBOX, &TextValidatorDialog::OnChecked, this);
Bind(wxEVT_UPDATE_UI, &TextValidatorDialog::OnUpdateUI,
this, Id_Ascii, Id_ExcludeCharListTxt);
}
void TextValidatorDialog::OnUpdateUI(wxUpdateUIEvent& event)
{
event.Enable(!m_noValidation);
if ( m_noValidation )
event.Check(false);
}
void TextValidatorDialog::OnChecked(wxCommandEvent& event)
{
if ( event.GetId() == Id_None )
{
m_noValidation = event.IsChecked();
if ( m_noValidation )
{
long style = wxFILTER_NONE;
// we should keep this flag on if it has been set.
if ( HasFlag(wxFILTER_EMPTY) )
style = wxFILTER_EMPTY;
m_validatorStyle = style;
m_charIncludes.clear();
m_charExcludes.clear();
m_includes.clear();
m_excludes.clear();
}
}
}
void TextValidatorDialog::OnKillFocus(wxFocusEvent &event)
{
wxTextCtrl* txtCtrl = wxDynamicCast(event.GetEventObject(), wxTextCtrl);
if ( txtCtrl && txtCtrl->IsModified() )
{
const int id = event.GetId();
if ( id == Id_IncludeCharListTxt )
{
m_charIncludes = txtCtrl->GetValue();
}
else if ( id == Id_ExcludeCharListTxt )
{
m_charExcludes = txtCtrl->GetValue();
}
else if ( id == Id_IncludeListTxt )
{
m_includes = wxSplit(txtCtrl->GetValue(), ' ');
}
else if ( id == Id_ExcludeListTxt )
{
m_excludes = wxSplit(txtCtrl->GetValue(), ' ');
}
}
event.Skip();
}
void TextValidatorDialog::ApplyValidator()
{
if ( !m_txtCtrl )
return;
wxString tooltip = "uses wxTextValidator with ";
if ( m_noValidation )
{
tooltip += "wxFILTER_NONE|";
}
else
{
if ( HasFlag(wxFILTER_ASCII) )
tooltip += "wxFILTER_ASCII|";
if ( HasFlag(wxFILTER_ALPHA) )
tooltip += "wxFILTER_ALPHA|";
if ( HasFlag(wxFILTER_ALPHANUMERIC) )
tooltip += "wxFILTER_ALPHANUMERIC|";
if ( HasFlag(wxFILTER_DIGITS) )
tooltip += "wxFILTER_DIGITS|";
if ( HasFlag(wxFILTER_NUMERIC) )
tooltip += "wxFILTER_NUMERIC|";
if ( HasFlag(wxFILTER_XDIGITS) )
tooltip += "wxFILTER_XDIGITS|";
if ( HasFlag(wxFILTER_SPACE) )
tooltip += "wxFILTER_SPACE|";
if ( HasFlag(wxFILTER_INCLUDE_LIST) )
tooltip += "wxFILTER_INCLUDE_LIST|";
if ( HasFlag(wxFILTER_INCLUDE_CHAR_LIST) )
tooltip += "wxFILTER_INCLUDE_CHAR_LIST|";
if ( HasFlag(wxFILTER_EXCLUDE_LIST) )
tooltip += "wxFILTER_EXCLUDE_LIST|";
if ( HasFlag(wxFILTER_EXCLUDE_CHAR_LIST) )
tooltip += "wxFILTER_EXCLUDE_CHAR_LIST|";
}
if ( HasFlag(wxFILTER_EMPTY) )
{
tooltip += "wxFILTER_EMPTY|";
}
tooltip.RemoveLast(); // remove the trailing '|' char.
if ( !m_charIncludes.empty() )
{
tooltip += "\nAllowed chars: ";
tooltip += m_charIncludes;
}
if ( !m_charExcludes.empty() )
{
tooltip += "\nDisallowed chars: ";
tooltip += m_charExcludes;
}
m_txtCtrl->SetToolTip(tooltip);
// Prepare and set the wxTextValidator
wxTextValidator txtVal(m_validatorStyle, &g_data.m_string);
txtVal.SetCharIncludes(m_charIncludes);
txtVal.SetCharExcludes(m_charExcludes);
txtVal.SetIncludes(m_includes);
txtVal.SetExcludes(m_excludes);
m_txtCtrl->SetValidator(txtVal);
m_txtCtrl->SetFocus();
}
bool TextValidatorDialog::StyleValidator::TransferToWindow()
{
wxASSERT( wxDynamicCast(m_validatorWindow, wxCheckBox) );
if ( m_style )
{
wxCheckBox* cb = (wxCheckBox*)GetWindow();
if ( !cb )
return false;
const long style = 1L << (cb->GetId()-wxID_HIGHEST-1);
cb->SetValue((*m_style & style) != 0);
}
return true;
}
bool TextValidatorDialog::StyleValidator::TransferFromWindow()
{
wxASSERT( wxDynamicCast(m_validatorWindow, wxCheckBox) );
if ( m_style )
{
wxCheckBox* cb = (wxCheckBox*)GetWindow();
if ( !cb )
return false;
const long style = 1L << (cb->GetId()-wxID_HIGHEST-1);
if ( cb->IsChecked() )
*m_style |= style;
else
*m_style &= ~style;
}
return true;
}
|