[main]    [up]  

WxExtLib - StatusValidators.cpp

00001: 
00002: /*
00003: -------------------------------------------------------------------------
00004: This file is part of WxWidgetsExtensions library.
00005: -------------------------------------------------------------------------
00006: 
00007: WxExtLib (WxWidgetsExtensions) library
00008: -----------------------------
00009: 
00010: COPYRIGHT NOTICE:
00011: 
00012: WxExtLib library Copyright (c) 2003-2007 Daniel Käps
00013: 
00014: The WxWidgetsExtensions library and associated documentation files (the
00015: "Software") is provided "AS IS".  The author(s) disclaim all
00016: warranties, expressed or implied, including, without limitation, the
00017: warranties of merchantability and of fitness for any purpose.  The
00018: author(s) assume no liability for direct, indirect, incidental,
00019: special, exemplary, or consequential damages, which may result from
00020: the use of or other dealings in the Software, even if advised of the
00021: possibility of such damage.
00022: 
00023: Permission is hereby granted, free of charge, to any person obtaining
00024: a copy of this Software, to deal in the Software without restriction,
00025: including without limitation the rights to use, copy, modify, merge,
00026: publish, distribute, sublicense, and/or sell copies of the Software,
00027: and to permit persons to whom the Software is furnished to do so,
00028: subject to the following conditions:
00029: 
00030:  1. The origin of this source code must not be misrepresented.
00031:  2. Altered versions must be plainly marked as such and must not be
00032:     misrepresented as being the original source.
00033:  3. This Copyright notice may not be removed or altered from any 
00034:     source or altered source distribution.
00035: 
00036: End of WxExtLib library Copyright Notice
00037: 
00038: -------------------------------------------------------------------------
00039: */
00040: 
00041: //=========================================================================
00042: 
00043: #ifndef M_StatusValidators_IsEmitGenericImplementation
00044: 
00045: //=========================================================================
00046: 
00047: #ifndef _NO_HEADER_INCLUDE
00048: 
00049: #if defined(__GNUG__) && (!defined(__APPLE__)) && (!(defined M_NoPragmaInterface))
00050: #   pragma implementation "StatusValidators.h"
00051: #endif
00052: 
00053: #include "WxExtLibConfig.h"
00054: 
00055: // For compilers that support precompilation, includes "wx.h".
00056: #include "wx/wxprec.h"
00057: 
00058: #ifdef __BORLANDC__
00059:   #pragma hdrstop
00060: #endif
00061: 
00062: #ifndef WX_PRECOMP
00063:   // WARN removed stdio.h - it should not be required (or may be it is required?)
00064:   // maybe it doesn't hurt
00065:   // #include <stdio.h>
00066:   #include <wx/textctrl.h>
00067:   #include <wx/combobox.h>
00068:   #include <wx/utils.h>
00069:   #include <wx/msgdlg.h>
00070:   #include <wx/intl.h>
00071: #endif
00072: 
00073: // for setFocusAndSelectParentBookPages()
00074: #include <wx/notebook.h>
00075: #include <wx/listbook.h>
00076: // note: for newer versions, wx/bookctrl.h would be sufficient
00077: // for setFocusAndSelectParentBookPages() implementation
00078: //   #include <wx/bookctrl.h>
00079: 
00080: #include "wx/msw/private.h"
00081: 
00082: #include "StatusValidators.h"
00083: 
00084: // #include <ctype.h>
00085: // #include <string.h>
00086: // #include <stdlib.h>
00087: 
00088: // #ifdef __SALFORDC__
00089: //    #include <clib.h>
00090: // #endif
00091: 
00092: #include "MessageExtDialog.h"
00093: 
00094: #include "WxMisc.h"
00095: #include "safecast.h"
00096: 
00097: #endif // _NO_HEADER_INCLUDE
00098: 
00099: //=========================================================================
00100: 
00101: IMPLEMENT_DYNAMIC_CLASS(wxStatusMessageTarget, wxObject)
00102: 
00103: //-------------------------------------------------------------------------
00104: 
00105: wxStatusMessageTarget::wxStatusMessageTarget()
00106: {
00107:     m_ErrorMessageMultiLineText = NULL;
00108:     m_IsShowMessageBoxEnabled = true;
00109: }
00110: 
00111: wxStatusMessageTarget::wxStatusMessageTarget(wxMultiLineText * ErrorMessageMultiLineText,
00112:                                              const wxString & NonErrorMessageString)
00113: {
00114:     m_ErrorMessageMultiLineText = ErrorMessageMultiLineText;
00115:     m_NonErrorMessageString = NonErrorMessageString;
00116: }
00117: 
00118: wxStatusMessageTarget::wxStatusMessageTarget(const wxStatusMessageTarget& StatusMessageTarget)
00119:     : wxObject()
00120: {
00121:     Copy(StatusMessageTarget);
00122: }
00123: 
00124: bool wxStatusMessageTarget::Copy(const wxStatusMessageTarget& StatusMessageTarget)
00125: {
00126:     // wxObject::Copy(StatusMessageTarget);
00127: 
00128:     m_ErrorMessageMultiLineText = StatusMessageTarget.m_ErrorMessageMultiLineText;
00129:     m_NonErrorMessageString = StatusMessageTarget.m_NonErrorMessageString;
00130: 
00131:     return true;
00132: }
00133: 
00134: wxStatusMessageTarget::~wxStatusMessageTarget()
00135: {
00136: }
00137: 
00138: //-------------------------------------------------------------------------
00139: 
00140: void wxStatusMessageTarget::setMessage (const wxString & MessageString, bool IsError)
00141: {
00142:     m_MessageString = MessageString;
00143:     m_IsError = IsError;
00144: }
00145: 
00146: void wxStatusMessageTarget::display (wxWindow * WXUNUSED(ParentWindow))
00147: {
00148:     if (m_ErrorMessageMultiLineText != NULL)
00149:       {
00150:         if (! m_NonErrorMessageString.IsEmpty() && ! m_IsError)
00151:           {
00152:             m_ErrorMessageMultiLineText -> getWindow() -> SetForegroundColour (wxColour (128, 0, 64));
00153:             m_ErrorMessageMultiLineText -> setText (m_NonErrorMessageString);
00154:           }
00155:         else
00156:           {
00157:             m_ErrorMessageMultiLineText -> getWindow() -> SetForegroundColour (wxColour (64, 0, 128));
00158:             m_ErrorMessageMultiLineText -> setText (m_MessageString);
00159:           }
00160:       }
00161: 
00162: //  if (m_IsError && m_IsShowMessageBoxEnabled)
00163: //    {
00164: //      wxMessageBox(m_MessageString, _("Input error"),
00165: //                   wxOK | wxICON_EXCLAMATION, ParentWindow);
00166: //    }
00167: }
00168: 
00169: void wxStatusMessageTarget::clear ()
00170: {
00171:     if (m_ErrorMessageMultiLineText != NULL)
00172:       {
00173:         m_ErrorMessageMultiLineText -> getWindow() -> SetForegroundColour (*wxBLACK);
00174:         m_ErrorMessageMultiLineText -> setText ("");
00175:       }
00176: }
00177: 
00178: void wxStatusMessageTarget::enableShowMessageBox (bool IsShowMessageBoxEnabled)
00179: {
00180:     m_IsShowMessageBoxEnabled = IsShowMessageBoxEnabled;
00181: }
00182: 
00183: bool wxStatusMessageTarget::isShowMessageBoxEnabled ()
00184: {
00185:     return m_IsShowMessageBoxEnabled;
00186: }
00187: 
00188: //-------------------------------------------------------------------------
00189: 
00190: void wxStatusMessageTarget::setStatusOutput (wxMultiLineText * ErrorMessageMultiLineText)
00191: {
00192:     m_ErrorMessageMultiLineText = ErrorMessageMultiLineText;
00193: }
00194: 
00195: void wxStatusMessageTarget::setNonErrorMessageString (const wxString & NonErrorMessageString)
00196: {
00197:     m_NonErrorMessageString = NonErrorMessageString;
00198: }
00199: 
00200: //=========================================================================
00201: 
00202: IMPLEMENT_CLASS(wxROGenericValidator, wxGenericValidator)
00203: 
00204: //-------------------------------------------------------------------------
00205: 
00206: wxROGenericValidator::wxROGenericValidator(bool* val)
00207:   : wxGenericValidator (val)
00208: {
00209: }
00210: 
00211: wxROGenericValidator::wxROGenericValidator(int* val)
00212:   : wxGenericValidator (val)
00213: {
00214: }
00215: 
00216: wxROGenericValidator::wxROGenericValidator(wxString* val)
00217:   : wxGenericValidator (val)
00218: {
00219: }
00220: 
00221: wxROGenericValidator::wxROGenericValidator(wxArrayInt* val)
00222:   : wxGenericValidator (val)
00223: {
00224: }
00225: 
00226: //=========================================================================
00227: 
00228: IMPLEMENT_ABSTRACT_CLASS(wxTextCtrlStatusValidator, wxValidator)
00229: 
00230: BEGIN_EVENT_TABLE(wxTextCtrlStatusValidator, wxValidator)
00231:     EVT_CHAR(wxTextCtrlStatusValidator::OnChar)
00232:     EVT_TEXT(wxID_ANY, wxTextCtrlStatusValidator::OnTextChanged)
00233:     EVT_COMBOBOX(wxID_ANY, wxTextCtrlStatusValidator::OnComboBoxSelected) 
00234:     EVT_CHOICE(wxID_ANY, wxTextCtrlStatusValidator::OnChoiceSelected) 
00235: END_EVENT_TABLE()
00236: 
00237: //-------------------------------------------------------------------------
00238: 
00239: wxTextCtrlStatusValidator::wxTextCtrlStatusValidator()
00240: {
00241:     m_StatusMessageTarget = NULL;
00242:     m_Flags = 0;
00243:     m_IsInsideOnTextChanged = false;
00244: }
00245: 
00246: wxTextCtrlStatusValidator::wxTextCtrlStatusValidator(wxStatusMessageTarget * StatusMessageTarget,
00247:                                      int Flags)
00248: {
00249:     m_StatusMessageTarget = StatusMessageTarget;
00250:     m_Flags = Flags;
00251:     m_IsInsideOnTextChanged = false;
00252: }
00253: 
00254: wxTextCtrlStatusValidator::wxTextCtrlStatusValidator(const wxTextCtrlStatusValidator& TextCtrlStatusValidator)
00255:     : wxValidator()
00256: {
00257:     Copy(TextCtrlStatusValidator);
00258: }
00259: 
00260: bool wxTextCtrlStatusValidator::Copy(const wxTextCtrlStatusValidator& TextCtrlStatusValidator)
00261: {
00262:     wxValidator::Copy(TextCtrlStatusValidator);
00263: 
00264:     m_StatusMessageTarget = TextCtrlStatusValidator.m_StatusMessageTarget;
00265:     m_Flags = TextCtrlStatusValidator.m_Flags;
00266:     // WARN copy state of m_IsInsideOnTextChanged okay?
00267:     m_IsInsideOnTextChanged = TextCtrlStatusValidator.m_IsInsideOnTextChanged;
00268: 
00269:     return true;
00270: }
00271: 
00272: wxTextCtrlStatusValidator::~wxTextCtrlStatusValidator()
00273: {
00274: }
00275: 
00276: //-------------------------------------------------------------------------
00277: 
00278: bool wxTextCtrlStatusValidator::TransferToWindow(void)
00279: {
00280:     if( !checkValidator() )
00281:         return false;
00282: 
00283:     wxString TextCtrlContentString;
00284:     transferToWindow(TextCtrlContentString);
00285:     setTextCtrlContent (TextCtrlContentString);
00286: 
00287:     return true;
00288: }
00289: 
00290: //-------------------------------------------------------------------------
00291: 
00292: void wxTextCtrlStatusValidator::getTextCtrlContent (wxString & TextCtrlContentString)
00293: {
00294:     // wxControlWithItems * ControlWithItems = NULL;
00295: 
00296:     wxTextCtrl* TextCtrl = wxDynamicCast (m_validatorWindow, wxTextCtrl);
00297:     if (TextCtrl != NULL)
00298:       {
00299:         TextCtrlContentString = TextCtrl -> GetValue ();
00300:         return; 
00301:       }
00302:     wxChoice * ChoiceCtrl = wxDynamicCast (m_validatorWindow, wxChoice);
00303:     if (ChoiceCtrl != NULL)
00304:       {
00305:         TextCtrlContentString = ChoiceCtrl -> GetStringSelection ();
00306:         return;
00307:       }
00308:     wxListBox * ListBox = wxDynamicCast (m_validatorWindow, wxListBox);
00309:     if (ListBox != NULL)
00310:       {
00311:         TextCtrlContentString = ListBox -> GetStringSelection ();
00312:         return;
00313:       }
00314:     wxComboBox * ComboBox = wxDynamicCast (m_validatorWindow, wxComboBox);
00315:     if (ComboBox != NULL)
00316:       {
00317:         TextCtrlContentString = ComboBox -> GetValue ();
00318:         return;
00319:       }
00320: 
00321:     wxASSERT_MSG (false, "wxTextCtrlStatusValidator::getTextCtrlContent(): unsupported control type");
00322: }
00323: 
00324: void wxTextCtrlStatusValidator::setTextCtrlContent (const wxString & TextCtrlContentString)
00325: {
00326:     wxTextCtrl* TextCtrl = wxDynamicCast (m_validatorWindow, wxTextCtrl);
00327:     if (TextCtrl != NULL)
00328:       {
00329:         TextCtrl -> SetValue (TextCtrlContentString);
00330:         return;
00331:       }
00332:     wxChoice * ChoiceCtrl = wxDynamicCast (m_validatorWindow, wxChoice);
00333:     if (ChoiceCtrl != NULL)
00334:       {
00335:         if (TextCtrlContentString == "")
00336:           {
00337:             // HACK
00338:             // calling e.g. SetStringSelection ("") gives assertion failure
00339:             // if empty string is not element of string array
00340:             //
00341:             // WARN this hack means that empty string cannot be used for
00342:             // normal entries anymore
00343:             // - more correct solution would be to ask trait if 
00344:             //   TextCtrlContentString == m_UndefinedBasictype
00345:             ChoiceCtrl -> SetSelection (-1);
00346:           }
00347:         else
00348:           {
00349:             ChoiceCtrl -> SetStringSelection (TextCtrlContentString);
00350:           }
00351:         return;
00352:       }
00353:     wxListBox * ListBox = wxDynamicCast (m_validatorWindow, wxListBox);
00354:     if (ListBox != NULL)
00355:       {
00356:         if (TextCtrlContentString == "")
00357:           {
00358:             // HACK
00359:             // calling e.g. SetStringSelection ("") gives assertion failure
00360:             // if empty string is not element of string array
00361:             //
00362:             // WARN this hack means that empty string cannot be used for
00363:             // normal entries anymore
00364:             // - more correct solution would be to ask trait if 
00365:             //   TextCtrlContentString == m_UndefinedBasictype
00366:             ListBox -> SetSelection (-1);
00367:           }
00368:         else
00369:           {
00370:             ListBox -> SetStringSelection (TextCtrlContentString);
00371:           }
00372:         return;
00373:       }
00374:     wxComboBox * ComboBox = wxDynamicCast (m_validatorWindow, wxComboBox);
00375:     if (ComboBox != NULL)
00376:       {
00377:         // WARN need use above hacks for SetStringSelection() with empty string?
00378:         //
00379:         // TEST
00380:         if (0)
00381:           {
00382:             ComboBox -> SetValue (TextCtrlContentString);
00383:             // updateComboBoxSelectionFromText (ComboBox, TextCtrlContentString, true);
00384:           }
00385:         else
00386:           {
00387:             int FoundIndex = ComboBox -> FindString (TextCtrlContentString);
00388:             if (FoundIndex != -1)
00389:               {
00390:                 // ComboBox -> SetStringSelection (TextCtrlContentString);
00391:                 // ::SendMessage(GetHwnd(), CB_SETCURSEL, n, 0);
00392:                 ComboBox -> SetValue (TextCtrlContentString);
00393:               }
00394:             else
00395:               {
00396:                 // ComboBox -> Select (-1);
00397:                 // ComboBox -> SetSelection (-1);
00398: 
00399:                 // wxComboBox also has                 
00400:                 //   void SetSelection(long from, long to)
00401:                 // but this has a complete different meaning:
00402:                 //   Selects the text between the two positions, in the combobox text field.
00403: 
00404: #ifdef __WXMSW__
00405:                 // deal with following bug (scope: wx version 2.5.3, wxMSW)
00406:                 // - wxComboBox: setting values causes some other value with this
00407:                 //   prefix to be selected from the list (scope: wxMSW)
00408:                 // - note: SetValue() seems to work as expected with wxGTK
00409: 
00410:                 //-- trying to write text directly to control with MSW API
00411:                 // (this seems to have the same effect of selecting some
00412:                 // other entry with same prefix):
00413:                 //   WXHWND WindowHandle = ComboBox -> GetHWND();
00414:                 //   HWND WindowHandle = ComboBox -> GetHwnd(); // doesn't work, anyhow
00415:                 //   ::SetWindowText ((struct HWND__ *) WindowHandle, 
00416:                 //                     wxString (" ") + TextCtrlContentString.c_str());
00417: 
00418:                 //-- workaround:
00419:                 // - 1) could add empty space for text shown to avoid having same
00420:                 //   prefix:
00421:                 //     wxString ModifiedTextCtrlContentString = " ";
00422:                 //     ModifiedTextCtrlContentString << TextCtrlContentString;
00423:                 //     ComboBox -> SetValue (ModifiedTextCtrlContentString);
00424:                 // - 2) could add empty space to all list elements
00425:                 ComboBox -> SetValue (TextCtrlContentString);
00426: 
00427:                 // - notes: 
00428:                 //   - both methods probably require left-trimming of white space
00429:                 //     to be enabled for the wxTextCtrlStatusValidator
00430:                 //   - method 2 (currently used) causes automatic selection of matching
00431:                 //     list entry to faild (not critical)
00432: #else
00433:                 ComboBox -> SetValue (TextCtrlContentString);
00434: #endif
00435:               }
00436:             // updateComboBoxSelectionFromText (ComboBox, TextCtrlContentString, true);
00437:           }
00438: 
00439:         return;
00440:       }
00441: 
00442:     wxASSERT_MSG (false, "wxTextCtrlStatusValidator::setTextCtrlContent(): unsupported control type");
00443: }
00444: 
00445: //-------------------------------------------------------------------------
00446: 
00447: bool wxTextCtrlStatusValidator::Validate(wxWindow * ParentWindow)
00448: {
00449:     if (!checkValidator())
00450:         return false;
00451: 
00452:     // return if the window is disabled
00453:     if (!m_validatorWindow -> IsEnabled())
00454:       return true;
00455: 
00456:     wxString TextCtrlContentString;
00457:     getTextCtrlContent (TextCtrlContentString);
00458:     wxString ErrorMessageString;
00459:     bool IsOk = transferFromWindowTemporary (TextCtrlContentString,
00460:                                              ErrorMessageString);
00461: 
00462:     if (IsOk)
00463:       {
00464:         showStatusMessage ("", false, ParentWindow);
00465:       }
00466:     else
00467:       {
00468:         showStatusMessage (ErrorMessageString, true, ParentWindow);
00469: 
00470:         if (m_StatusMessageTarget != NULL
00471:             && m_StatusMessageTarget -> isShowMessageBoxEnabled())
00472:           {
00473:             // Because of intended handleWatchedControlChange()
00474:             // implementations which would call Validate() for any control
00475:             // change (e.g. any time a character is typed in a wxTextCtrl by
00476:             // the user), we set the focus to the wxTextCtrl with an input error
00477:             // only if the message box is enabled for the StatusMessageTarget.
00478:             setFocusAndSelectParentBookPages (GetWindow());
00479: 
00480: //          wxMessageBox(ErrorMessageString, _("Input error"),
00481: //                       wxOK | wxICON_EXCLAMATION, ParentWindow);
00482: 
00483:             wxMessageExtDialog MessageExtDialog (ParentWindow, 
00484:                                               ErrorMessageString,
00485:                                               _("Input error"));
00486:             MessageExtDialog.addButton (_("Cancel"), wxID_CANCEL);
00487:             MessageExtDialog.makeLastAddedButtonDefault ();
00488:             MessageExtDialog.ShowModal ();
00489:           }
00490:       }
00491: 
00492:     return IsOk;
00493: }
00494: 
00495: bool wxTextCtrlStatusValidator::TransferFromWindow(void)
00496: {
00497:     if (!checkValidator())
00498:         return false;
00499: 
00500:     // return if window is disabled
00501:     if (!m_validatorWindow -> IsEnabled())
00502:       return true;
00503: 
00504:     // theoretically, the string in the wxTextCtrl should be valid here
00505:     // because Validate() would have been called before successfully
00506:     wxString TextCtrlContentString;
00507:     getTextCtrlContent (TextCtrlContentString);
00508:     wxString ErrorMessageString;
00509:     bool IsOk = transferFromWindowPersistent (TextCtrlContentString,
00510:                                               ErrorMessageString);
00511: 
00512:     return IsOk;
00513: }
00514: 
00515: //-------------------------------------------------------------------------
00516: 
00517: void wxTextCtrlStatusValidator::OnChar(wxKeyEvent& Event)
00518: {
00519:     if (m_validatorWindow 
00520:         && (m_Flags & IsFilterInputChars))
00521:       {
00522:         // here, filtering of keyboard events could be realized
00523:       }
00524: 
00525:     Event.Skip();
00526: }
00527: 
00528: // Note that OnTextChanged() will always be sent when the text controls contents
00529: // changes (scope: wxMSW, wxGTK) - whether this is due to user input or comes 
00530: // from the program itself (for example, if SetValue() is called).
00531: void wxTextCtrlStatusValidator::OnTextChanged(wxCommandEvent& Event)
00532: {
00533:     if (m_IsInsideOnTextChanged)
00534:       return;
00535:     wxScopedSetToTrue ScopedSetToTrue (m_IsInsideOnTextChanged);
00536: 
00537:     if (m_validatorWindow)
00538:       {
00539:         wxComboBox * ComboBox = wxDynamicCast (m_validatorWindow, wxComboBox);
00540:         if (ComboBox != NULL)
00541:           {
00542:             wxString TextCtrlContentString = ComboBox -> GetValue();
00543:             updateComboBoxSelectionFromText (ComboBox, TextCtrlContentString, false);
00544:           }
00545: 
00546:         // check if string that is now in the TextCtrl is valid; if
00547:         // not, display the error message in the status control (if available)
00548:         wxString TextCtrlContentString;
00549:         getTextCtrlContent (TextCtrlContentString);
00550:         wxString ErrorMessageString;
00551:         if (transferFromWindowTemporary (TextCtrlContentString,
00552:                                          ErrorMessageString, true))
00553:           {
00554:             showStatusMessage ("", false, NULL);
00555:             // handleValidInput (TempLong);
00556:           }
00557:         else
00558:           {
00559:             showStatusMessage (ErrorMessageString, true, NULL);
00560:           }
00561:       }
00562: 
00563:     // skip is required here to get other handlers (e.g. watchControlChange...())
00564:     // called
00565:     Event.Skip ();
00566: }
00567: 
00568: // HACK for wxMSW wxComboBox: 
00569: // it doesn't seem to call SetValue() if an item is selected from
00570: // the list, and GetValue() returns the old value, not the selected
00571: // one
00572: // NOTE: however, even the wxEVT_COMMAND_COMBOBOX_SELECTED
00573: // event seems to be lost sometimes
00574: void wxTextCtrlStatusValidator::OnComboBoxSelected(wxCommandEvent& Event)
00575: {
00576:     wxComboBox * ComboBox = wxDynamicCast (m_validatorWindow, wxComboBox);
00577:     if (ComboBox != NULL)
00578:       {
00579:       }
00580: 
00581:     Event.Skip ();
00582: }
00583: 
00584: //-------------------------------------------------------------------------
00585: 
00586: void wxTextCtrlStatusValidator::OnChoiceSelected(wxCommandEvent& Event)
00587: {
00588:     wxChoice * ChoiceCtrl = wxDynamicCast (m_validatorWindow, wxChoice);
00589:     if (ChoiceCtrl != NULL)
00590:       {
00591:       }
00592: 
00593:     Event.Skip ();
00594: }
00595: 
00596: //-------------------------------------------------------------------------
00597: 
00598: void wxTextCtrlStatusValidator::showStatusMessage (const wxString & MessageString, 
00599:                                                    bool IsError,
00600:                                                    wxWindow * ParentWindow)
00601: {
00602:     // use m_StatusMessageTarget for output of error message if available,
00603:     // otherwise don't display error message immediatly (it will be shown in
00604:     // a message box later when Validate() is called by the dialog)
00605: 
00606:     if (m_StatusMessageTarget != NULL)
00607:       {
00608:         m_StatusMessageTarget -> setMessage (MessageString, IsError);
00609:         m_StatusMessageTarget -> display (ParentWindow);
00610:       }
00611: }
00612: 
00613: //-------------------------------------------------------------------------
00614: 
00615: bool wxTextCtrlStatusValidator::checkValidator() const
00616: {
00617:     wxCHECK_MSG (m_validatorWindow, false,
00618:                  _T("No window associated with validator"));
00619:     wxCHECK_MSG (m_validatorWindow -> IsKindOf (CLASSINFO (wxTextCtrl))
00620:                  || m_validatorWindow -> IsKindOf (CLASSINFO (wxChoice))
00621:                  || m_validatorWindow -> IsKindOf (CLASSINFO (wxListBox))
00622:                  || m_validatorWindow -> IsKindOf (CLASSINFO (wxComboBox)), false,
00623:                  _T("Associated control must be of type wxTextCtrl, wxChoiceCtrl, wxListBox or wxComboxBox"));
00624:     
00625:     return true;
00626: }
00627: 
00628: //=========================================================================
00629: 
00630: IMPLEMENT_ABSTRACT_CLASS(wxTraitedTextCtrlStatusValidator, wxTextCtrlStatusValidator)
00631: 
00632: BEGIN_EVENT_TABLE(wxTraitedTextCtrlStatusValidator, wxTextCtrlStatusValidator)
00633: END_EVENT_TABLE()
00634: 
00635: //-------------------------------------------------------------------------
00636: 
00637: wxTraitedTextCtrlStatusValidator::wxTraitedTextCtrlStatusValidator()
00638: {
00639:     m_TextCtrlStatusValidatorTrait = NULL;
00640: }
00641: 
00642: wxTraitedTextCtrlStatusValidator::wxTraitedTextCtrlStatusValidator(wxTextCtrlStatusValidatorTrait * TextCtrlStatusValidatorTrait,
00643:                                                                    wxStatusMessageTarget * StatusMessageTarget,
00644:                                                                    int Flags)
00645:     : wxTextCtrlStatusValidator (StatusMessageTarget, Flags)
00646: {
00647:     m_TextCtrlStatusValidatorTrait = TextCtrlStatusValidatorTrait;
00648: }
00649: 
00650: wxTraitedTextCtrlStatusValidator::wxTraitedTextCtrlStatusValidator(const wxTraitedTextCtrlStatusValidator& TraitedTextCtrlStatusValidator)
00651:     : wxTextCtrlStatusValidator()
00652: {
00653:     Copy(TraitedTextCtrlStatusValidator);
00654: }
00655: 
00656: bool wxTraitedTextCtrlStatusValidator::Copy(const wxTraitedTextCtrlStatusValidator& TraitedTextCtrlStatusValidator)
00657: {
00658:     wxTextCtrlStatusValidator::Copy(TraitedTextCtrlStatusValidator);
00659: 
00660:     m_TextCtrlStatusValidatorTrait = TraitedTextCtrlStatusValidator.m_TextCtrlStatusValidatorTrait;
00661: 
00662:     return true;
00663: }
00664: 
00665: wxTraitedTextCtrlStatusValidator::~wxTraitedTextCtrlStatusValidator()
00666: {
00667:     m_TextCtrlStatusValidatorTrait = NULL;
00668: }
00669: 
00670: //-------------------------------------------------------------------------
00671: 
00672: void wxTraitedTextCtrlStatusValidator::transferToWindow (wxString & TextCtrlContentString)
00673: {
00674:     if (!checkValidator())
00675:         return;
00676: 
00677:     m_TextCtrlStatusValidatorTrait -> convertToString (TextCtrlContentString);
00678: }
00679: 
00680: //-------------------------------------------------------------------------
00681: 
00682: bool wxTraitedTextCtrlStatusValidator::transferFromWindowTemporary (const wxString & TextCtrlContentString,
00683:                                                                     wxString & ErrorMessageString,
00684:                                                                     bool IsTextCtrlChangeEvent)
00685: {
00686:     if (!checkValidator())
00687:       {
00688:         ErrorMessageString = "[internal error: wxTraitedTextCtrlStatusValidator object not correctly initialized]";
00689:         return false;
00690:       }
00691: 
00692:     bool IsOk = false;
00693:     IsOk = m_TextCtrlStatusValidatorTrait -> convertFromStringTemporary (TextCtrlContentString,
00694:                                                                          ErrorMessageString,
00695:                                                                          IsTextCtrlChangeEvent);
00696:     if (IsOk && IsTextCtrlChangeEvent)
00697:       handleValidInput ();
00698: 
00699:     return IsOk;
00700: }
00701: 
00702: bool wxTraitedTextCtrlStatusValidator::transferFromWindowPersistent (const wxString & TextCtrlContentString,
00703:                                                                      wxString & ErrorMessageString)
00704: {
00705:     if (!checkValidator())
00706:       {
00707:         ErrorMessageString = "[internal error: wxTraitedTextCtrlStatusValidator object not correctly initialized]";
00708:         return false;
00709:       }
00710: 
00711:     bool IsOk = false;
00712:     IsOk = m_TextCtrlStatusValidatorTrait -> convertFromStringPersistent (TextCtrlContentString,
00713:                                                                           ErrorMessageString);
00714:     return IsOk;
00715: }
00716: 
00717: //-------------------------------------------------------------------------
00718: 
00719: void wxTraitedTextCtrlStatusValidator::handleValidInput ()
00720: {
00721: }
00722: 
00723: bool wxTraitedTextCtrlStatusValidator::checkValidator () const
00724: {
00725:     return m_TextCtrlStatusValidatorTrait != NULL;
00726: }
00727: 
00728: //=========================================================================
00729: // conversions basic-type to string
00730: 
00731: 
00732: void wxBasictypeValidatorTrait_convertULongToString (const char * WXUNUSED(FormatString),
00733:                                                      unsigned long ULong,
00734:                                                      wxString & String)
00735: {
00736:     String = wxString::Format ("%lu", ULong);
00737: }
00738: 
00739: void wxBasictypeValidatorTrait_convertLongToString (const char * WXUNUSED(FormatString),
00740:                                                     long Long,
00741:                                                     wxString & String)
00742: {
00743:     String = wxString::Format ("%ld", Long);
00744: }
00745: 
00746: void wxBasictypeValidatorTrait_convertDoubleToString (const char * FormatString,
00747:                                                       double Double,
00748:                                                       wxString & String)
00749: {
00750:     String = wxString::Format (FormatString, Double);
00751: }
00752: 
00753: //=========================================================================
00754: // conversions string to basic-type
00755:                                   
00756: bool wxBasictypeValidatorTrait_convertStringToLong (const char * WXUNUSED(DefaultScanfString),
00757:                                                     const wxString & TrimmedString,
00758:                                                     long & Long)
00759: {
00760:     return convertStringToLong (TrimmedString, Long);
00761: }
00762: 
00763: bool wxBasictypeValidatorTrait_convertStringToULong (const char * WXUNUSED(DefaultScanfString),
00764:                                                      const wxString & TrimmedString,
00765:                                                      unsigned long & ULong)
00766: {
00767:     return convertStringToLong (TrimmedString, ULong);
00768: }
00769: 
00770: //-------------------------------------------------------------------------
00771: 
00772: bool wxBasictypeValidatorTrait_convertStringToString (const char * WXUNUSED(DefaultScanfString),
00773:                                                       const wxString & TrimmedInputString,
00774:                                                       wxString & OutputString)
00775: {
00776:     OutputString = TrimmedInputString;
00777:     return true;
00778: }
00779: 
00780: 
00781: //=========================================================================
00782: 
00783: #define IMPLEMENT_FUNCTION_convertStringToBasictype(Functionname,TBasictype,ScanfFormatString) \
00784:  \
00785: bool Functionname (const char * WXUNUSED(DefaultScanfString), \
00786:                    const wxString & TrimmedString, \
00787:                    TBasictype & Basictype) \
00788: { \
00789:     char DummyChar; \
00790:     wxString CheckingFormatString (ScanfFormatString); \
00791:     CheckingFormatString += "%c"; \
00792:     int ReadArgumentCount = wxSscanf (TrimmedString, CheckingFormatString, \
00793:                                       & Basictype, \
00794:                                       & DummyChar); \
00795:     return ReadArgumentCount == 1; \
00796: } \
00797: 
00798: //-------------------------------------------------------------------------
00799: 
00800: #define IMPLEMENT_FUNCTION_convertStringToInttype(Functionname,TInttype,TLongType,MinInttype,MaxInttype) \
00801:  \
00802:   bool Functionname (const char * WXUNUSED(DefaultScanfString), \
00803:                      const wxString & String, \
00804:                      TInttype & Inttype) \
00805: { \
00806:     TLongType Long = 0; /* TLongType should be 'long' */ \
00807:     bool IsOk = convertStringToLong (String, Long); \
00808:     if ((Long < (TLongType) (MinInttype)) \
00809:         || (Long > (TLongType) (MaxInttype))) \
00810:       { \
00811:         IsOk = false; \
00812:       } \
00813:     if (IsOk) \
00814:        Inttype = (TInttype) Long; \
00815:  \
00816:     return IsOk; \
00817: } \
00818: 
00819: // unsigned-int-type version of function above to avoid GCC warnings like:
00820: //   ./src/StatusValidators.cpp: In function `bool
00821: //   wxBasictypeValidatorTrait_convertStringToUShort(const char*, const
00822: //   wxString&, short unsigned int&)':
00823: //   ./src/StatusValidators.cpp:722: warning: comparison of unsigned expression
00824: //   < 0 is always false
00825: #define IMPLEMENT_FUNCTION_convertStringToUInttype(Functionname,TInttype,TLongType,MinInttype,MaxInttype) \
00826:  \
00827:   bool Functionname (const char * WXUNUSED(DefaultScanfString), \
00828:                      const wxString & String, \
00829:                      TInttype & Inttype) \
00830: { \
00831:     TLongType Long; /* TLongType should be 'unsigned long' */ \
00832:     bool IsOk = convertStringToLong (String, Long); \
00833:     if (Long > (TLongType) (MaxInttype)) \
00834:       { \
00835:         IsOk = false; \
00836:       } \
00837:     if (IsOk) \
00838:        Inttype = (TInttype) Long; \
00839:  \
00840:     return IsOk; \
00841: } \
00842: 
00843: //-------------------------------------------------------------------------
00844: 
00845: IMPLEMENT_FUNCTION_convertStringToBasictype(wxBasictypeValidatorTrait_convertStringToFloat,
00846:                                             float, "%f")
00847: IMPLEMENT_FUNCTION_convertStringToBasictype(wxBasictypeValidatorTrait_convertStringToDouble,
00848:                                             double, "%lf")
00849: 
00850: IMPLEMENT_FUNCTION_convertStringToInttype(wxBasictypeValidatorTrait_convertStringToWxInt16, 
00851:                                           wxInt16, long, -32768, 32767)
00852: IMPLEMENT_FUNCTION_convertStringToUInttype(wxBasictypeValidatorTrait_convertStringToWxUint16, 
00853:                                            wxUint16, unsigned long, 0, USHRT_MAX)
00854: IMPLEMENT_FUNCTION_convertStringToInttype(wxBasictypeValidatorTrait_convertStringToWxInt32, 
00855:                                           wxInt32, long, -2147483647L - 1L, 2147483647)
00856: IMPLEMENT_FUNCTION_convertStringToUInttype(wxBasictypeValidatorTrait_convertStringToWxUint32, 
00857:                                            wxUint32, unsigned long, 0, ULONG_MAX)
00858: IMPLEMENT_FUNCTION_convertStringToInttype(wxBasictypeValidatorTrait_convertStringToShort, 
00859:                                           short, long, SHRT_MIN, SHRT_MAX)
00860: IMPLEMENT_FUNCTION_convertStringToUInttype(wxBasictypeValidatorTrait_convertStringToUShort, 
00861:                                            unsigned short, unsigned long, 0, SHRT_MAX)
00862: IMPLEMENT_FUNCTION_convertStringToInttype(wxBasictypeValidatorTrait_convertStringToInt, 
00863:                                           int, long, INT_MIN, INT_MAX)
00864: IMPLEMENT_FUNCTION_convertStringToUInttype(wxBasictypeValidatorTrait_convertStringToUInt, 
00865:                                            unsigned int, unsigned long, 0, UINT_MAX)
00866: 
00867: //=========================================================================
00868: 
00869: #else // M_StatusValidators_IsEmitGenericImplementation
00870: 
00871: //=========================================================================
00872: 
00873: #if (defined M_BasictypeValidatorTrait)
00874: 
00875: // macros which must be defined
00876: // - M_BasictypeValidatorTrait
00877: // - M_BasictypeValidatorTrait_Basictype
00878: // - M_BasictypeValidatorTrait_DefaultFormatString
00879: // - M_BasictypeValidatorTrait_DefaultScanfString
00880: // - M_BasictypeValidatorTrait_FormatFunction
00881: // - M_BasictypeValidatorTrait_ParseFunction
00882: 
00883: //-------------------------------------------------------------------------
00884: 
00885: // define a few shortcuts
00886:     #define M_Basictype M_BasictypeValidatorTrait_Basictype
00887: 
00888: //-------------------------------------------------------------------------
00889: 
00890: M_BasictypeValidatorTrait::M_BasictypeValidatorTrait ()
00891: {
00892:     // m_Flags = NotInitialized; 
00893: }
00894: 
00895: M_BasictypeValidatorTrait::M_BasictypeValidatorTrait (M_Basictype * BasictypeValue,
00896:                                                       M_Basictype MinBasictype,
00897:                                                       M_Basictype MaxBasictype,
00898:                                                       const wxString & FieldNameString,
00899:                                                       int Flags,
00900:                                                       M_Basictype UndefinedBasictype,
00901:                                                       const wxString & FormatString)
00902: {
00903:     init (BasictypeValue, MinBasictype, MaxBasictype,
00904:           FieldNameString, Flags,
00905:           UndefinedBasictype,
00906:           FormatString);
00907: }
00908: 
00909: M_BasictypeValidatorTrait::M_BasictypeValidatorTrait (const M_Basictype & BasictypeValueRef,
00910:                                                       M_Basictype MinBasictype,
00911:                                                       M_Basictype MaxBasictype,
00912:                                                       const wxString & FieldNameString,
00913:                                                       int Flags,
00914:                                                       M_Basictype UndefinedBasictype,
00915:                                                       const wxString & FormatString)
00916: {
00917:     init (BasictypeValueRef, MinBasictype, MaxBasictype,
00918:           FieldNameString, Flags,
00919:           UndefinedBasictype,
00920:           FormatString);
00921: }
00922: 
00923: //-------------------------------------------------------------------------
00924: 
00925: void M_BasictypeValidatorTrait::init (M_Basictype * BasictypeValuePtr,
00926:                                       M_Basictype MinBasictype,
00927:                                       M_Basictype MaxBasictype,
00928:                                       const wxString & FieldNameString,
00929:                                       int Flags, M_Basictype UndefinedBasictype,
00930:                                       const wxString & FormatString)
00931: {
00932:     if (Flags & IsWritebackToCopy)
00933:       {
00934:         m_BasictypeValuePtr = NULL;
00935:         m_CopyBasictype = * BasictypeValuePtr;
00936:       }
00937:     else
00938:       {
00939:         m_BasictypeValuePtr = BasictypeValuePtr;
00940:         m_CopyBasictype = * BasictypeValuePtr;
00941:       }
00942:     m_MinBasictype = MinBasictype;
00943:     m_MaxBasictype = MaxBasictype;
00944:     m_UndefinedBasictype = UndefinedBasictype;
00945: 
00946:     if (FormatString == wxEmptyString)
00947:       {
00948:         m_FormatString = M_BasictypeValidatorTrait_DefaultFormatString;
00949:       }
00950:     else
00951:       {
00952:         m_FormatString = FormatString;
00953:       }
00954:     m_FieldNameString = FieldNameString;
00955:     m_Flags = Flags;
00956: }
00957: 
00958: void M_BasictypeValidatorTrait::init (const M_Basictype & BasictypeValueRef,
00959:                                       M_Basictype MinBasictype,
00960:                                       M_Basictype MaxBasictype,
00961:                                       const wxString & FieldNameString,
00962:                                       int Flags, M_Basictype UndefinedBasictype,
00963:                                       const wxString & FormatString)
00964: {
00965:     Flags |= IsWritebackToCopy | IsReadFromCopy;
00966:     m_BasictypeValuePtr = NULL;
00967:     m_CopyBasictype = BasictypeValueRef;
00968: 
00969:     m_MinBasictype = MinBasictype;
00970:     m_MaxBasictype = MaxBasictype;
00971:     m_UndefinedBasictype = UndefinedBasictype;
00972: 
00973:     if (FormatString == wxEmptyString)
00974:       {
00975:         m_FormatString = M_BasictypeValidatorTrait_DefaultFormatString;
00976:       }
00977:     else
00978:       {
00979:         m_FormatString = FormatString;
00980:       }
00981:     m_FieldNameString = FieldNameString;
00982:     m_Flags = Flags;
00983: }
00984: 
00985: //-------------------------------------------------------------------------
00986: 
00987: void M_BasictypeValidatorTrait::convertToString (wxString & TextCtrlContentString)
00988: {
00989:     M_Basictype * BasictypePtr = (m_Flags & IsReadFromCopy) ? & m_CopyBasictype : m_BasictypeValuePtr;
00990:     if ((m_Flags & IsEmptyAllowed)
00991:         && (getIsUndefinedValue (*BasictypePtr)))
00992:       {
00993:         TextCtrlContentString = "";
00994:       }
00995:     else
00996:       {
00997:         // long Long = *BasictypePtr; 
00998:         // TextCtrlContentString = wxString::Format (m_FormatString, Long); 
00999:         convertBasictypeToString (*BasictypePtr, TextCtrlContentString);
01000:       }
01001: }
01002: 
01003: //-------------------------------------------------------------------------
01004: 
01005: bool M_BasictypeValidatorTrait::convertFromStringTemporary (const wxString & TextCtrlContentString,
01006:                                                             wxString & ErrorMessageString,
01007:                                                             bool WXUNUSED(IsTextCtrlChangeEvent))
01008: {
01009:     // M_Basictype TempBasictype = 0; 
01010:     return convertFromStringHelper (TextCtrlContentString, & m_LastValidationBasicType, ErrorMessageString);
01011: }
01012: 
01013: bool M_BasictypeValidatorTrait::convertFromStringPersistent (const wxString & TextCtrlContentString,
01014:                                                              wxString & ErrorMessageString)
01015: {
01016:     bool IsOkay = convertFromStringHelper (TextCtrlContentString, & m_CopyBasictype, ErrorMessageString);
01017:     if (IsOkay
01018:         && (!(m_Flags & IsWritebackToCopy)))
01019:       {
01020:         // write back to original location only if that's desired 
01021:         *m_BasictypeValuePtr = m_CopyBasictype;
01022:       }
01023:     return IsOkay;
01024: }
01025: 
01026: //-------------------------------------------------------------------------
01027: 
01028: bool M_BasictypeValidatorTrait::convertFromStringHelper (const wxString & TextCtrlContentString,
01029:                                                          M_Basictype * BasictypePtr,
01030:                                                          wxString & ErrorMessageString)
01031: {
01032:     wxString TrimmedInputString = TextCtrlContentString;
01033: 
01034:     if (!(m_Flags & IsNoTrimLeft))
01035:       {
01036:         TrimmedInputString.Trim (false /* IsTrimFromRight */);
01037:       }
01038:     if (!(m_Flags & IsNoTrimRight))
01039:       {
01040:         TrimmedInputString.Trim (true /* IsTrimFromRight */);
01041:       }
01042: 
01043:     bool IsOk = false;
01044:     if ((m_Flags & IsEmptyAllowed) && TrimmedInputString.IsEmpty())
01045:       {
01046:         *BasictypePtr = m_UndefinedBasictype;
01047:         IsOk = true;
01048:       }
01049:     else
01050:       {
01051:         IsOk = true;
01052:         if ((!(m_Flags & IsEmptyAllowed))
01053:             && TrimmedInputString.IsEmpty())
01054:           {
01055:             // handle case that input (after trimming) is empty, but 
01056:             // empty input is not allowed (needed e.g. for instantiations
01057:             // with type wxString):
01058:             IsOk = false;
01059:           }
01060: 
01061:         M_Basictype TempBasictype;
01062: 
01063:         if (IsOk)
01064:           IsOk = convertStringToBasictype (TrimmedInputString, TempBasictype);
01065: 
01066:         if (IsOk)
01067:           IsOk = checkValueRange (TempBasictype);
01068: 
01069:         if (IsOk)
01070:           *BasictypePtr = TempBasictype;
01071: 
01072:         if (!IsOk)
01073:           getErrorMessageString (ErrorMessageString);
01074:       }
01075: 
01076:     return IsOk;
01077: }
01078: 
01079: //-------------------------------------------------------------------------
01080: 
01081: // getErrorMessageString() must be implemented separated 
01082: 
01083: M_Basictype M_BasictypeValidatorTrait::getCopyValue ()
01084: {
01085:     return m_CopyBasictype;
01086: }
01087: 
01088: //-------------------------------------------------------------------------
01089: 
01090: #if (!(M_BasictypeValidatorTrait_IsUseSpecialParseAndFormatFunction == 1))
01091: 
01092: void M_BasictypeValidatorTrait::convertBasictypeToString (const M_Basictype & Basictype,
01093:                                                           wxString & String)
01094: {
01095:     // String = wxString::Format (m_FormatString, Basictype);
01096:     M_BasictypeValidatorTrait_FormatFunction (m_FormatString, Basictype, String);
01097: }
01098: 
01099: bool M_BasictypeValidatorTrait::convertStringToBasictype (const wxString & TrimmedString,
01100:                                                           M_Basictype & Basictype)
01101: {
01102:   /*  char DummyChar;
01103:     wxString CheckingFormatString (M_BasictypeValidatorTrait_DefaultScanfString);
01104:     CheckingFormatString += "%c";
01105:     int ReadArgumentCount = wxSscanf (TrimmedString, CheckingFormatString,
01106:                                       & Basictype,
01107:                                       & DummyChar);
01108:                                       return ReadArgumentCount == 1; */
01109:     // convertStringToLong (TrimmedString, Basictype); 
01110:     return M_BasictypeValidatorTrait_ParseFunction (M_BasictypeValidatorTrait_DefaultScanfString, 
01111:                                                     TrimmedString, Basictype);
01112: }
01113: 
01114: #endif
01115: 
01116: //-------------------------------------------------------------------------
01117: 
01118: #if (!(M_BasictypeValidatorTrait_IsSpecialUndefinedCheckFunction == 1))
01119: 
01120: bool M_BasictypeValidatorTrait::getIsUndefinedValue (const M_Basictype & Basictype)
01121: {
01122:     // this check is okay for builtin-types like int, long, float etc.
01123:     return Basictype == m_UndefinedBasictype;
01124: }
01125: 
01126: #endif
01127: 
01128: #if (!(M_BasictypeValidatorTrait_IsNoCheckValueRangeImplementation == 1))
01129: // implementation for checkValueRange() can be disabled so it's easier
01130: // to replace it by a custom function
01131: 
01132: bool M_BasictypeValidatorTrait::checkValueRange (const M_Basictype & Basictype)
01133: {
01134:     // TODO add support for left and/or right open intervals 
01135:     // (instead of closed) - required for float/double types 
01136:     bool IsOkay = true;
01137:     if ((m_Flags & IsIgnoreMinimum) == 0)
01138:       IsOkay = IsOkay && (Basictype >= m_MinBasictype);
01139:     if ((m_Flags & IsIgnoreMaximum) == 0)
01140:       IsOkay = IsOkay && (Basictype <= m_MaxBasictype);
01141:     return IsOkay;
01142: }
01143: 
01144: #endif
01145: 
01146: //-------------------------------------------------------------------------
01147: 
01148: #if (!(M_BasictypeValidatorTrait_IsNoGetErrorMessageStringImplementation == 1))
01149: 
01150: // implementation for getErrorMessageString() can be disabled to make it easier
01151: // to replace it by a custom message
01152: // (initially, M_BasictypeValidatorTrait was only used for numeric types, like
01153: // int, long, double, which explains the error message text here)
01154: 
01155: void M_BasictypeValidatorTrait::getErrorMessageString (wxString & ErrorMessageString)
01156: {
01157:     wxString MinBasictypeString;
01158:     wxString MaxBasictypeString;
01159: 
01160:     if (!(m_Flags & IsIgnoreMinimum))
01161:       convertBasictypeToString (m_MinBasictype, MinBasictypeString);
01162: 
01163:     if (!(m_Flags & IsIgnoreMaximum))
01164:       convertBasictypeToString (m_MaxBasictype, MaxBasictypeString);
01165: 
01166:     const char * FormatMessageString = NULL;
01167:     if ((m_Flags & IsIgnoreMinimum)
01168:         && (m_Flags & IsIgnoreMaximum))
01169:       FormatMessageString = _("ERROR: input must be a number%3 for \"%4\"");
01170:     else if ((m_Flags & IsIgnoreMinimum) == 0
01171:              && (m_Flags & IsIgnoreMaximum))
01172:       FormatMessageString = _("ERROR: input must be a number greater than or equal to %1%3 for \"%4\"");
01173:     else if ((m_Flags & IsIgnoreMinimum) != 0
01174:              && (m_Flags & IsIgnoreMaximum) == 0)
01175:       FormatMessageString = _("ERROR: input must be a number smaller than or equal to %2%3 for \"%4\"");
01176:     else
01177:       FormatMessageString = _("ERROR: input must be a number between %1 and %2%3 for \"%4\".");
01178: 
01179:     ErrorMessageString
01180:       += MessageFormatter (FormatMessageString)
01181:          % wxFormat (MinBasictypeString)
01182:          % wxFormat (MaxBasictypeString)
01183:          % ((m_Flags & IsEmptyAllowed) ? _(" (or empty)") : "")
01184:          % m_FieldNameString;
01185: }
01186: 
01187: #endif
01188: 
01189: //-------------------------------------------------------------------------
01190: 
01191: // undefine shortcuts
01192:     #undef M_Basictype
01193: 
01194: //=========================================================================
01195: 
01196: #endif // defined M_StatusValidators_IsEmitGenericImplementation
01197: 
01198: //-------------------------------------------------------------------------
01199: 
01200: #endif // defined M_StatusValidators_IsEmitGenericImplementation
01201: 
01202: //-------------------------------------------------------------------------
01203: 
01204: #ifndef M_StatusValidators_IsEmitGenericImplementation
01205: 
01206: //=========================================================================
01207: 
01208: // implementation of trait classes using generic includes
01209: 
01210: // NB format strings are ignored except for 'double' and 'float' types
01211: // currently
01212: 
01213: #define M_StatusValidators_IsEmitGenericImplementation
01214: 
01215: //-------------------------------------------------------------------------
01216: 
01217: // implement wxBasictypeValidatorTrait_wxInt16
01218:     #define M_BasictypeValidatorTrait wxBasictypeValidatorTrait_wxInt16
01219:     #define M_BasictypeValidatorTrait_Basictype wxInt16
01220:     #define M_BasictypeValidatorTrait_DefaultFormatString "%ld"
01221:     #define M_BasictypeValidatorTrait_DefaultScanfString "%hd"
01222:     #define M_BasictypeValidatorTrait_FormatFunction wxBasictypeValidatorTrait_convertLongToString
01223:     #define M_BasictypeValidatorTrait_ParseFunction wxBasictypeValidatorTrait_convertStringToWxInt16
01224:     #include "StatusValidators.cpp"
01225:     #undef M_BasictypeValidatorTrait
01226:     #undef M_BasictypeValidatorTrait_Basictype
01227:     #undef M_BasictypeValidatorTrait_DefaultFormatString
01228:     #undef M_BasictypeValidatorTrait_DefaultScanfString
01229:     #undef M_BasictypeValidatorTrait_FormatFunction
01230:     #undef M_BasictypeValidatorTrait_ParseFunction
01231: 
01232: // implement wxBasictypeValidatorTrait_wxUint16
01233:     #define M_BasictypeValidatorTrait wxBasictypeValidatorTrait_wxUint16
01234:     #define M_BasictypeValidatorTrait_Basictype wxUint16
01235:     #define M_BasictypeValidatorTrait_DefaultFormatString "%hu"
01236:     #define M_BasictypeValidatorTrait_DefaultScanfString "%hu"
01237:     #define M_BasictypeValidatorTrait_FormatFunction wxBasictypeValidatorTrait_convertULongToString
01238:     #define M_BasictypeValidatorTrait_ParseFunction wxBasictypeValidatorTrait_convertStringToWxUint16
01239:     #include "StatusValidators.cpp"
01240:     #undef M_BasictypeValidatorTrait
01241:     #undef M_BasictypeValidatorTrait_Basictype
01242:     #undef M_BasictypeValidatorTrait_DefaultFormatString
01243:     #undef M_BasictypeValidatorTrait_DefaultScanfString
01244:     #undef M_BasictypeValidatorTrait_FormatFunction
01245:     #undef M_BasictypeValidatorTrait_ParseFunction
01246: 
01247: // implement wxBasictypeValidatorTrait_wxInt32
01248:     #define M_BasictypeValidatorTrait wxBasictypeValidatorTrait_wxInt32
01249:     #define M_BasictypeValidatorTrait_Basictype wxInt32
01250:     #define M_BasictypeValidatorTrait_DefaultFormatString "%ld"
01251:     #define M_BasictypeValidatorTrait_DefaultScanfString "%ld"
01252:     #define M_BasictypeValidatorTrait_FormatFunction wxBasictypeValidatorTrait_convertLongToString
01253:     #define M_BasictypeValidatorTrait_ParseFunction wxBasictypeValidatorTrait_convertStringToWxInt32
01254:     #include "StatusValidators.cpp"
01255:     #undef M_BasictypeValidatorTrait
01256:     #undef M_BasictypeValidatorTrait_Basictype
01257:     #undef M_BasictypeValidatorTrait_DefaultFormatString
01258:     #undef M_BasictypeValidatorTrait_DefaultScanfString
01259:     #undef M_BasictypeValidatorTrait_FormatFunction
01260:     #undef M_BasictypeValidatorTrait_ParseFunction
01261: 
01262: // implement wxBasictypeValidatorTrait_wxUint32
01263:     #define M_BasictypeValidatorTrait wxBasictypeValidatorTrait_wxUint32
01264:     #define M_BasictypeValidatorTrait_Basictype wxUint32
01265:     #define M_BasictypeValidatorTrait_DefaultFormatString "%u"
01266:     #define M_BasictypeValidatorTrait_DefaultScanfString "%u"
01267:     #define M_BasictypeValidatorTrait_FormatFunction wxBasictypeValidatorTrait_convertULongToString
01268:     #define M_BasictypeValidatorTrait_ParseFunction wxBasictypeValidatorTrait_convertStringToWxUint32
01269:     #include "StatusValidators.cpp"
01270:     #undef M_BasictypeValidatorTrait
01271:     #undef M_BasictypeValidatorTrait_Basictype
01272:     #undef M_BasictypeValidatorTrait_DefaultFormatString
01273:     #undef M_BasictypeValidatorTrait_DefaultScanfString
01274:     #undef M_BasictypeValidatorTrait_FormatFunction
01275:     #undef M_BasictypeValidatorTrait_ParseFunction
01276: 
01277: // implement wxBasictypeValidatorTrait_short
01278:     #define M_BasictypeValidatorTrait wxBasictypeValidatorTrait_short
01279:     #define M_BasictypeValidatorTrait_Basictype short
01280:     #define M_BasictypeValidatorTrait_DefaultFormatString "%d"
01281:     #define M_BasictypeValidatorTrait_DefaultScanfString "%hd"
01282:     #define M_BasictypeValidatorTrait_FormatFunction wxBasictypeValidatorTrait_convertLongToString
01283:     #define M_BasictypeValidatorTrait_ParseFunction wxBasictypeValidatorTrait_convertStringToShort
01284:     #include "StatusValidators.cpp"
01285:     #undef M_BasictypeValidatorTrait
01286:     #undef M_BasictypeValidatorTrait_Basictype
01287:     #undef M_BasictypeValidatorTrait_DefaultFormatString
01288:     #undef M_BasictypeValidatorTrait_DefaultScanfString
01289:     #undef M_BasictypeValidatorTrait_FormatFunction
01290:     #undef M_BasictypeValidatorTrait_ParseFunction
01291: 
01292: // implement wxBasictypeValidatorTrait_ushort
01293:     #define M_BasictypeValidatorTrait wxBasictypeValidatorTrait_ushort
01294:     #define M_BasictypeValidatorTrait_Basictype unsigned short
01295:     #define M_BasictypeValidatorTrait_DefaultFormatString "%u"
01296:     #define M_BasictypeValidatorTrait_DefaultScanfString "%hu"
01297:     #define M_BasictypeValidatorTrait_FormatFunction wxBasictypeValidatorTrait_convertULongToString
01298:     #define M_BasictypeValidatorTrait_ParseFunction wxBasictypeValidatorTrait_convertStringToUShort
01299:     #include "StatusValidators.cpp"
01300:     #undef M_BasictypeValidatorTrait
01301:     #undef M_BasictypeValidatorTrait_Basictype
01302:     #undef M_BasictypeValidatorTrait_DefaultFormatString
01303:     #undef M_BasictypeValidatorTrait_DefaultScanfString
01304:     #undef M_BasictypeValidatorTrait_FormatFunction
01305:     #undef M_BasictypeValidatorTrait_ParseFunction
01306: 
01307: // implement wxBasictypeValidatorTrait_int
01308:     #define M_BasictypeValidatorTrait wxBasictypeValidatorTrait_int
01309:     #define M_BasictypeValidatorTrait_Basictype int
01310:     #define M_BasictypeValidatorTrait_DefaultFormatString "%d"
01311:     #define M_BasictypeValidatorTrait_DefaultScanfString "%d"
01312:     #define M_BasictypeValidatorTrait_FormatFunction wxBasictypeValidatorTrait_convertLongToString
01313:     #define M_BasictypeValidatorTrait_ParseFunction wxBasictypeValidatorTrait_convertStringToInt
01314:     #include "StatusValidators.cpp"
01315:     #undef M_BasictypeValidatorTrait
01316:     #undef M_BasictypeValidatorTrait_Basictype
01317:     #undef M_BasictypeValidatorTrait_DefaultFormatString
01318:     #undef M_BasictypeValidatorTrait_DefaultScanfString
01319:     #undef M_BasictypeValidatorTrait_FormatFunction
01320:     #undef M_BasictypeValidatorTrait_ParseFunction
01321: 
01322: // implement wxBasictypeValidatorTrait_uint
01323:     #define M_BasictypeValidatorTrait wxBasictypeValidatorTrait_uint
01324:     #define M_BasictypeValidatorTrait_Basictype unsigned int
01325:     #define M_BasictypeValidatorTrait_DefaultFormatString "%u"
01326:     #define M_BasictypeValidatorTrait_DefaultScanfString "%u"
01327:     #define M_BasictypeValidatorTrait_FormatFunction wxBasictypeValidatorTrait_convertULongToString
01328:     #define M_BasictypeValidatorTrait_ParseFunction wxBasictypeValidatorTrait_convertStringToUInt
01329:     #include "StatusValidators.cpp"
01330:     #undef M_BasictypeValidatorTrait
01331:     #undef M_BasictypeValidatorTrait_Basictype
01332:     #undef M_BasictypeValidatorTrait_DefaultFormatString
01333:     #undef M_BasictypeValidatorTrait_DefaultScanfString
01334:     #undef M_BasictypeValidatorTrait_FormatFunction
01335:     #undef M_BasictypeValidatorTrait_ParseFunction
01336: 
01337: // implement wxBasictypeValidatorTrait_long
01338:     #define M_BasictypeValidatorTrait wxBasictypeValidatorTrait_long
01339:     #define M_BasictypeValidatorTrait_Basictype long
01340:     #define M_BasictypeValidatorTrait_DefaultFormatString "%ld"
01341:     #define M_BasictypeValidatorTrait_DefaultScanfString "%ld"
01342:     #define M_BasictypeValidatorTrait_FormatFunction wxBasictypeValidatorTrait_convertLongToString
01343:     #define M_BasictypeValidatorTrait_ParseFunction wxBasictypeValidatorTrait_convertStringToLong
01344:     #include "StatusValidators.cpp"
01345:     #undef M_BasictypeValidatorTrait
01346:     #undef M_BasictypeValidatorTrait_Basictype
01347:     #undef M_BasictypeValidatorTrait_DefaultFormatString
01348:     #undef M_BasictypeValidatorTrait_DefaultScanfString
01349:     #undef M_BasictypeValidatorTrait_FormatFunction
01350:     #undef M_BasictypeValidatorTrait_ParseFunction
01351: 
01352: // implement wxBasictypeValidatorTrait_ulong
01353:     #define M_BasictypeValidatorTrait wxBasictypeValidatorTrait_ulong
01354:     #define M_BasictypeValidatorTrait_Basictype unsigned long
01355:     #define M_BasictypeValidatorTrait_DefaultFormatString "%ld"
01356:     #define M_BasictypeValidatorTrait_DefaultScanfString "%ld"
01357:     #define M_BasictypeValidatorTrait_FormatFunction wxBasictypeValidatorTrait_convertULongToString
01358:     #define M_BasictypeValidatorTrait_ParseFunction wxBasictypeValidatorTrait_convertStringToULong
01359:     #include "StatusValidators.cpp"
01360:     #undef M_BasictypeValidatorTrait
01361:     #undef M_BasictypeValidatorTrait_Basictype
01362:     #undef M_BasictypeValidatorTrait_DefaultFormatString
01363:     #undef M_BasictypeValidatorTrait_DefaultScanfString
01364:     #undef M_BasictypeValidatorTrait_FormatFunction
01365:     #undef M_BasictypeValidatorTrait_ParseFunction
01366: 
01367: // implement wxBasictypeValidatorTrait_wxFloat32
01368:     #define M_BasictypeValidatorTrait wxBasictypeValidatorTrait_wxFloat32
01369:     #define M_BasictypeValidatorTrait_Basictype wxFloat32
01370:     // float doesn't have direct printf() support (only scanf() support), so we
01371:     // use conversion function and printf format specifier for 'double'
01372:     #define M_BasictypeValidatorTrait_DefaultFormatString "%f"
01373:     #define M_BasictypeValidatorTrait_DefaultScanfString "%lf"
01374:     #define M_BasictypeValidatorTrait_FormatFunction wxBasictypeValidatorTrait_convertDoubleToString
01375:     #define M_BasictypeValidatorTrait_ParseFunction wxBasictypeValidatorTrait_convertStringToFloat
01376:     #include "StatusValidators.cpp"
01377:     #undef M_BasictypeValidatorTrait
01378:     #undef M_BasictypeValidatorTrait_Basictype
01379:     #undef M_BasictypeValidatorTrait_DefaultFormatString
01380:     #undef M_BasictypeValidatorTrait_DefaultScanfString
01381:     #undef M_BasictypeValidatorTrait_FormatFunction
01382:     #undef M_BasictypeValidatorTrait_ParseFunction
01383: 
01384: // implement wxBasictypeValidatorTrait_wxFloat64
01385:     #define M_BasictypeValidatorTrait wxBasictypeValidatorTrait_wxFloat64
01386:     #define M_BasictypeValidatorTrait_Basictype wxFloat64
01387:     // printf() %f is already double, not float, and float is not directly supported
01388:     #define M_BasictypeValidatorTrait_DefaultFormatString "%f" 
01389:     #define M_BasictypeValidatorTrait_DefaultScanfString "%lf"
01390:     #define M_BasictypeValidatorTrait_FormatFunction wxBasictypeValidatorTrait_convertDoubleToString
01391:     #define M_BasictypeValidatorTrait_ParseFunction wxBasictypeValidatorTrait_convertStringToDouble
01392:     #include "StatusValidators.cpp"
01393:     #undef M_BasictypeValidatorTrait
01394:     #undef M_BasictypeValidatorTrait_Basictype
01395:     #undef M_BasictypeValidatorTrait_DefaultFormatString
01396:     #undef M_BasictypeValidatorTrait_DefaultScanfString
01397:     #undef M_BasictypeValidatorTrait_FormatFunction
01398:     #undef M_BasictypeValidatorTrait_ParseFunction
01399: 
01400: // implement wxBasictypeValidatorTrait_wxStringBase
01401:     #define M_BasictypeValidatorTrait wxBasictypeValidatorTrait_wxStringBase
01402:     #define M_BasictypeValidatorTrait_Basictype wxString
01403:     #define M_BasictypeValidatorTrait_DefaultFormatString "%%"
01404:     #define M_BasictypeValidatorTrait_DefaultScanfString "%%" /* unused */
01405:     #define M_BasictypeValidatorTrait_FormatFunction wxBasictypeValidatorTrait_convertStringToString
01406:     #define M_BasictypeValidatorTrait_ParseFunction wxBasictypeValidatorTrait_convertStringToString
01407:     #include "StatusValidators.cpp"
01408:     #undef M_BasictypeValidatorTrait
01409:     #undef M_BasictypeValidatorTrait_Basictype
01410:     #undef M_BasictypeValidatorTrait_DefaultFormatString
01411:     #undef M_BasictypeValidatorTrait_DefaultScanfString
01412:     #undef M_BasictypeValidatorTrait_FormatFunction
01413:     #undef M_BasictypeValidatorTrait_ParseFunction
01414: 
01415: //-------------------------------------------------------------------------
01416: 
01417: // implement wxBasictypeValidatorTrait_wxDateTime
01418:     #define M_BasictypeValidatorTrait wxBasictypeValidatorTrait_wxDateTime
01419:     #define M_BasictypeValidatorTrait_Basictype wxDateTime
01420:     // #define M_BasictypeValidatorTrait_DefaultFormatString "%%"
01421:     #define M_BasictypeValidatorTrait_DefaultFormatString "%Y-%m-%d %H:%M:%S"
01422:     #define M_BasictypeValidatorTrait_DefaultScanfString "%%" /* unused */
01423:     #define M_BasictypeValidatorTrait_IsUseSpecialParseAndFormatFunction 1
01424:     #define M_BasictypeValidatorTrait_IsSpecialUndefinedCheckFunction 1
01425:     #define M_BasictypeValidatorTrait_IsNoGetErrorMessageStringImplementation 1
01426:     #include "StatusValidators.cpp"
01427:     #undef M_BasictypeValidatorTrait
01428:     #undef M_BasictypeValidatorTrait_Basictype
01429:     #undef M_BasictypeValidatorTrait_DefaultFormatString
01430:     #undef M_BasictypeValidatorTrait_DefaultScanfString
01431:     #undef M_BasictypeValidatorTrait_IsUseSpecialParseAndFormatFunction
01432:     #undef M_BasictypeValidatorTrait_IsSpecialUndefinedCheckFunction
01433:     #undef M_BasictypeValidatorTrait_IsNoGetErrorMessageStringImplementation
01434: 
01435: void wxBasictypeValidatorTrait_wxDateTime::convertBasictypeToString (const wxDateTime & Basictype,
01436:                                                                      wxString & String)
01437: {
01438:     // formatDateTimeInISOFormat (Basictype, String);
01439:     formatDateTimeWithFormat (Basictype, String, m_FormatString);
01440: }
01441: 
01442: bool wxBasictypeValidatorTrait_wxDateTime::convertStringToBasictype (const wxString & TrimmedString,
01443:                                                                      wxDateTime & Basictype)
01444: {
01445:     // return parseDateTimeFromISOFormat (TrimmedString, Basictype);
01446:     return parseDateTimeWithFormat (TrimmedString, Basictype, m_FormatString);
01447: }
01448: 
01449: bool wxBasictypeValidatorTrait_wxDateTime::getIsUndefinedValue (const wxDateTime & Basictype)
01450: {
01451:     // cannot compare Basictype == m_UndefinedBasictype
01452:     // because is wxDateTime, in case wxInvalidDateTime
01453:     // is used as m_UndefinedBasictype (in this case, the comparision causes
01454:     // an assertion failure, because supplied date is invalid)
01455:     if (!Basictype.IsValid())
01456:       return true;
01457: 
01458:     if (m_UndefinedBasictype.IsValid())
01459:       return (Basictype == m_UndefinedBasictype);
01460: 
01461:     return false;
01462: }
01463: 
01464: void wxBasictypeValidatorTrait_wxDateTime::getErrorMessageString (wxString & ErrorMessageString)
01465: {
01466:     wxString MinBasictypeString;
01467:     wxString MaxBasictypeString;
01468:     wxString ExampleDateTimeString;
01469: 
01470:     if (!(m_Flags & IsIgnoreMinimum))
01471:       convertBasictypeToString (m_MinBasictype, MinBasictypeString);
01472: 
01473:     if (!(m_Flags & IsIgnoreMaximum))
01474:       convertBasictypeToString (m_MaxBasictype, MaxBasictypeString);
01475: 
01476:     //-- formatting of date/time example string: this is quite tedious 
01477:     // because want to output a sample string which is in the valid
01478:     // range of accepted dates, to avoid confusing the user
01479:     wxDateTime ExampleDateTime;
01480:     if (m_Flags & IsIgnoreMinimum)
01481:       {
01482:         if (m_Flags & IsIgnoreMaximum)
01483:           {
01484:             // neither maximum nor minimum
01485:             ExampleDateTime =  wxDateTime::Now();
01486:           }
01487:         else
01488:           {
01489:             // maximum but no minimum
01490:             ExampleDateTime = m_MaxBasictype - wxTimeSpan::Days (50);
01491:           }
01492:       }
01493:     else
01494:       {
01495:         if (m_Flags & IsIgnoreMaximum)
01496:           {
01497:             // minimum but no maximum
01498:             ExampleDateTime = m_MaxBasictype - wxTimeSpan::Days (50);
01499:           }
01500:         else
01501:           {
01502:             // both minimum and maximum
01503:             // BUG: the calculation code for wxTimeSpan possibly has a bug or
01504:             // cannot deal with long distances in time (e.g. for Min==1900-01-01
01505:             // and Max==2100-01-01, result is 1904-03-03)
01506:             ExampleDateTime = m_MinBasictype + wxTimeSpan ((m_MaxBasictype - m_MinBasictype).GetDays() / 2);
01507:           }
01508:       }
01509:     convertBasictypeToString (ExampleDateTime, ExampleDateTimeString);
01510: 
01511:     //-- formatting of error message
01512:     const char * FormatMessageString = NULL;
01513:     if ((m_Flags & IsIgnoreMinimum)
01514:         && (m_Flags & IsIgnoreMaximum))
01515:       FormatMessageString = _("ERROR: input must be date/time%3 for \"%4\" (input format example: %5)");
01516:     else if ((m_Flags & IsIgnoreMinimum) == 0
01517:              && (m_Flags & IsIgnoreMaximum))
01518:       FormatMessageString = _("ERROR: input must be date/time greater than or equal to %1%3 for \"%4\" (input format example: %5)");
01519:     else if ((m_Flags & IsIgnoreMinimum) != 0
01520:              && (m_Flags & IsIgnoreMaximum) == 0)
01521:       FormatMessageString = _("ERROR: input must be date/time smaller than or equal to %2%3 for \"%4\" (input format example: %5)");
01522:     else
01523:       FormatMessageString = _("ERROR: input must be date/time between %1 and %2%3 for \"%4\" (input format example: %5)");
01524: 
01525:     ErrorMessageString
01526:       += MessageFormatter (FormatMessageString)
01527:          % wxFormat (MinBasictypeString)
01528:          % wxFormat (MaxBasictypeString)
01529:          % ((m_Flags & IsEmptyAllowed) ? _(" (or empty)") : "")
01530:          % m_FieldNameString
01531:          % ExampleDateTimeString;
01532: }
01533: 
01534: //-------------------------------------------------------------------------
01535: 
01536: wxBasictypeValidatorTrait_wxString::wxBasictypeValidatorTrait_wxString()
01537: {
01538:     m_MinStringLength = 0;
01539:     m_MaxStringLength = -1;
01540: }
01541: 
01542: void wxBasictypeValidatorTrait_wxString::setMinStringLength(int MinStringLength)
01543: {
01544:     m_MinStringLength = MinStringLength;
01545: }
01546: 
01547: void wxBasictypeValidatorTrait_wxString::setMaxStringLength(int MaxStringLength)
01548: {
01549:     m_MaxStringLength = MaxStringLength;
01550: }
01551: 
01552: void wxBasictypeValidatorTrait_wxString::setAllowedInputCharset (const wxString & AllowedCharsetString)
01553: {
01554:     m_AllowedCharsetString = AllowedCharsetString;
01555: }
01556: 
01557: void wxBasictypeValidatorTrait_wxString::setAllowedInputCharsetDescription (const wxString & AllowedCharsetDescriptionString)
01558: {
01559:     m_AllowedCharsetDescriptionString = AllowedCharsetDescriptionString;
01560: }
01561: 
01562: bool wxBasictypeValidatorTrait_wxString::convertFromStringHelper (const wxString & TextCtrlContentString,
01563:                                                                           wxString * TrimmedInputStringPtr,
01564:                                                                           wxString & ErrorMessageString)
01565: {
01566:     bool IsOkay
01567:       = wxBasictypeValidatorTrait_wxStringBase::convertFromStringHelper (TextCtrlContentString, 
01568:                                                                          TrimmedInputStringPtr, 
01569:                                                                          ErrorMessageString);
01570: 
01571:     if (IsOkay)
01572:       {
01573:         int Length = TrimmedInputStringPtr->Length();
01574: 
01575:         wxString FormatMessageString;
01576:         if (Length < m_MinStringLength)
01577:           {
01578:             FormatMessageString = _("ERROR: input must consist of at least %1 characters for \"%3\".");
01579:             IsOkay = false;
01580:           }
01581:         else if ((m_MaxStringLength != -1)
01582:                  && (Length > m_MaxStringLength))
01583:           {
01584:             FormatMessageString = _("ERROR: input must have no more than %2 characters for \"%3\".");
01585:             IsOkay = false;
01586:           }
01587: 
01588:         if (!IsOkay)
01589:           {
01590:             ErrorMessageString += wxFormatMessage (FormatMessageString,
01591:                                                    m_MinStringLength,
01592:                                                    m_MaxStringLength,
01593:                                                    m_FieldNameString);
01594:           }
01595:         else
01596:           {
01597:             // now check for accepted charset
01598: 
01599:             const char * InputCharPtr = TrimmedInputStringPtr -> c_str();
01600:             const char * AllowedCharsetStringCharPtr = m_AllowedCharsetString.c_str();
01601:             
01602:             if ((InputCharPtr != NULL)
01603:                 && (AllowedCharsetStringCharPtr != NULL)
01604:                 && (m_AllowedCharsetString.Length() > 0))
01605:               {
01606:                 if (strspn (InputCharPtr, AllowedCharsetStringCharPtr) != TrimmedInputStringPtr->Length())
01607:                   {
01608:                     IsOkay = false;
01609:                   }
01610:               }
01611: 
01612:             if (!IsOkay)
01613:               {
01614:                 FormatMessageString = _("ERROR: input must consist only of characters of type <%1> for \"%2\".");
01615:                 
01616:                 ErrorMessageString += wxFormatMessage (FormatMessageString,
01617:                                                        m_AllowedCharsetDescriptionString,
01618:                                                        m_FieldNameString);
01619:               }
01620: 
01621:           }
01622:       }
01623:     return IsOkay;
01624: }
01625: 
01626: void wxBasictypeValidatorTrait_wxString::getErrorMessageString (wxString & ErrorMessageString)
01627: {
01628:     const char * FormatMessageString = NULL;
01629: 
01630:     // unlike for numeric types, this error message doesn't contain a 
01631:     // full description of all required constraints (min, max count of characters,
01632:     // accepted characters) 
01633:     // - specialized error message is returned if a constraint doesn't hold
01634:     //   (see convertFromStringHelper())
01635:     FormatMessageString = _("ERROR: input must be a%1 string%2 for \"%3\"");
01636: 
01637:     ErrorMessageString
01638:       += MessageFormatter (FormatMessageString)
01639:       % ((m_Flags & IsEmptyAllowed) ? "" :  _(" non-empty"))
01640:       % ((m_Flags & IsEmptyAllowed) ? _(" (or empty)") : "")
01641:       % m_FieldNameString;
01642: }
01643: 
01644: //-------------------------------------------------------------------------
01645: 
01646: #undef M_StatusValidators_IsEmitGenericImplementation
01647: 
01648: //=========================================================================
01649: 
01650: wxNumberValidatorVariant::wxNumberValidatorVariant ()
01651: {
01652:     m_Type = UndefinedType;
01653:     m_Long = 0;
01654:     m_Double = 0.;
01655: }
01656: 
01657: bool wxNumberValidatorVariant::getIsLong () const
01658: {
01659:     return m_Type == LongType;
01660: }
01661: 
01662: bool wxNumberValidatorVariant::getIsDouble () const
01663: {
01664:     return m_Type == DoubleType;
01665: }
01666: 
01667: long wxNumberValidatorVariant::getLong () const
01668: {
01669:     return m_Long;
01670: }
01671: 
01672: double wxNumberValidatorVariant::getDouble () const
01673: {
01674:     return m_Double;
01675: }
01676: 
01677: void wxNumberValidatorVariant::getLong (long * Long) const
01678: {
01679:     * Long = m_Long;
01680: }
01681: 
01682: void wxNumberValidatorVariant::getDouble (double * Double) const
01683: {
01684:     * Double = m_Double;
01685: }
01686: 
01687: void wxNumberValidatorVariant::setLong (long Long)
01688: {
01689:     m_Long = Long;
01690:     m_Double = 0.;
01691:     m_Type = LongType;
01692: }
01693: 
01694: void wxNumberValidatorVariant::setDouble (const double & Double)
01695: {
01696:     m_Long = 0;
01697:     m_Double = Double;
01698:     m_Type = DoubleType;
01699: }
01700: 
01701: bool wxNumberValidatorVariant::operator== (const wxNumberValidatorVariant & Variant) const
01702: {
01703:     // this equality test operator requires unused elements to be uniquely set
01704:     // to a certain value (e.g. 0 or 0.) to work as expected.
01705:     bool IsEqual = m_Type == Variant.m_Type
01706:       && m_Long == Variant.m_Long
01707:       && m_Double == Variant.m_Double;
01708:     return IsEqual;
01709: }
01710: 
01711: //=========================================================================
01712: 
01713: IMPLEMENT_DYNAMIC_CLASS(wxNumberValidator, wxTraitedTextCtrlStatusValidator)
01714: 
01715: BEGIN_EVENT_TABLE(wxNumberValidator, wxTextCtrlStatusValidator)
01716: END_EVENT_TABLE()
01717: 
01718: //-------------------------------------------------------------------------
01719: 
01720: wxNumberValidator::wxNumberValidator()
01721: {
01722:     m_TextCtrlStatusValidatorTrait = NULL;
01723: }
01724: 
01725: wxNumberValidator::wxNumberValidator(int * IntegerValue, int MinInteger, int MaxInteger,
01726:                                      wxStatusMessageTarget * StatusMessageTarget,
01727:                                      const wxString & FieldNameString,
01728:                                      int Flags, int UndefinedInteger)
01729:   : wxTraitedTextCtrlStatusValidator(& m_IntBasictypeValidatorTrait, 
01730:                                      StatusMessageTarget, Flags)
01731: {
01732:     m_IntBasictypeValidatorTrait.init (IntegerValue, 
01733:                                        MinInteger, MaxInteger,
01734:                                        FieldNameString,
01735:                                        Flags, UndefinedInteger,
01736:                                        wxEmptyString);
01737:     // m_FormatString = "%ld";
01738: }
01739: 
01740: wxNumberValidator::wxNumberValidator(long * LongValue, long MinLong, long MaxLong,
01741:                                      wxStatusMessageTarget * StatusMessageTarget,
01742:                                      const wxString & FieldNameString,
01743:                                      int Flags, long UndefinedLong)
01744:   : wxTraitedTextCtrlStatusValidator(& m_LongBasictypeValidatorTrait, 
01745:                                      StatusMessageTarget, Flags)
01746: {
01747:     m_LongBasictypeValidatorTrait.init (LongValue, 
01748:                                         MinLong, MaxLong,
01749:                                         FieldNameString,
01750:                                         Flags, UndefinedLong,
01751:                                         wxEmptyString);
01752:     // m_FormatString = "%ld";
01753: }
01754: 
01755: wxNumberValidator::wxNumberValidator(double * DoubleValue, double MinDouble, double MaxDouble,
01756:                                      wxStatusMessageTarget * StatusMessageTarget,
01757:                                      const wxString & FieldNameString,
01758:                                      int Flags, 
01759:                                      const wxString & FormatString,
01760:                                      double UndefinedDouble)
01761:   : wxTraitedTextCtrlStatusValidator(& m_DoubleBasictypeValidatorTrait, 
01762:                                      StatusMessageTarget, Flags)
01763: {
01764:     m_DoubleBasictypeValidatorTrait.init (DoubleValue, 
01765:                                           MinDouble, MaxDouble,
01766:                                           FieldNameString,
01767:                                           Flags, UndefinedDouble,
01768:                                           FormatString);
01769: }
01770: 
01771: wxNumberValidator::wxNumberValidator(const wxNumberValidator& NumberValidator)
01772:     : wxTraitedTextCtrlStatusValidator()
01773: {
01774:     Copy(NumberValidator);
01775: }
01776: 
01777: bool wxNumberValidator::Copy(const wxNumberValidator& NumberValidator)
01778: {
01779:     wxTraitedTextCtrlStatusValidator::Copy(NumberValidator);
01780: 
01781:     m_IntBasictypeValidatorTrait = NumberValidator.m_IntBasictypeValidatorTrait;
01782:     m_LongBasictypeValidatorTrait = NumberValidator.m_LongBasictypeValidatorTrait;
01783:     m_DoubleBasictypeValidatorTrait = NumberValidator.m_DoubleBasictypeValidatorTrait;
01784: 
01785:     // HACK to deal with pointer to different types of BasictypeValidatorTrait
01786:     // the pointer must point the right BasictypeValidatorTrait within
01787:     // the destination object (this), not source object
01788:     // HACK (const wxTextCtrlStatusValidator *) cast is a cast to the base class
01789:     // and is added for VC++ compatibility
01790:     if (NumberValidator.m_TextCtrlStatusValidatorTrait == 
01791:         (const wxTextCtrlStatusValidatorTrait *) (& NumberValidator.m_IntBasictypeValidatorTrait))
01792:       {
01793:         m_TextCtrlStatusValidatorTrait = & m_IntBasictypeValidatorTrait;
01794:       }
01795:     else if (NumberValidator.m_TextCtrlStatusValidatorTrait == 
01796:         (const wxTextCtrlStatusValidatorTrait *) & NumberValidator.m_LongBasictypeValidatorTrait)
01797:       {
01798:         m_TextCtrlStatusValidatorTrait = & m_LongBasictypeValidatorTrait;
01799:       }
01800:     else if (NumberValidator.m_TextCtrlStatusValidatorTrait == 
01801:         (const wxTextCtrlStatusValidatorTrait *) & NumberValidator.m_DoubleBasictypeValidatorTrait)
01802:       {
01803:         m_TextCtrlStatusValidatorTrait = & m_DoubleBasictypeValidatorTrait;
01804:       }
01805:     else
01806:       {
01807:         m_TextCtrlStatusValidatorTrait = NULL;
01808:       }
01809:     return true;
01810: }
01811: 
01812: wxNumberValidator::~wxNumberValidator()
01813: {
01814: }
01815: 
01816: //=========================================================================
01817: 
01818: #else // M_StatusValidators_IsEmitGenericImplementation
01819: 
01820: //-------------------------------------------------------------------------
01821: 
01822: #define M_IsDefinePPMacros 1
01823: #   include "pp_basics.h" 
01824: // #undef M_IsDefinePPMacros
01825: 
01826: //=========================================================================
01827: 
01828: // #define IMPLEMENT_CLASS_wxTraitedTextCtrlStatusValidatorImpl(TClassname,M_BasictypeValidatorTrait,M_Basictype)
01829: 
01830: #if (defined M_TraitedTextCtrlStatusValidatorImpl)
01831: 
01832: // macros which must be defined
01833: // - M_TraitedTextCtrlStatusValidatorImpl
01834: // - M_TraitedTextCtrlStatusValidatorImpl_Basictype
01835: // - M_TraitedTextCtrlStatusValidatorImpl_BasictypeValidatorTrait
01836: 
01837: //-------------------------------------------------------------------------
01838: 
01839: // define a few shortcuts
01840: #define M_Basictype M_TraitedTextCtrlStatusValidatorImpl_Basictype
01841: #define M_BasictypeValidatorTrait M_TraitedTextCtrlStatusValidatorImpl_BasictypeValidatorTrait
01842: 
01843: //-------------------------------------------------------------------------
01844: 
01845: M_PP_eval2 (IMPLEMENT_DYNAMIC_CLASS, M_TraitedTextCtrlStatusValidatorImpl, wxTraitedTextCtrlStatusValidator)
01846: 
01847: M_PP_eval2 (BEGIN_EVENT_TABLE, M_TraitedTextCtrlStatusValidatorImpl, wxTraitedTextCtrlStatusValidator)
01848: M_PP_eval0 (END_EVENT_TABLE)
01849: 
01850: //-------------------------------------------------------------------------
01851: 
01852: M_TraitedTextCtrlStatusValidatorImpl::M_TraitedTextCtrlStatusValidatorImpl()
01853: {
01854:     m_TextCtrlStatusValidatorTrait = NULL;
01855: }
01856: 
01857: M_TraitedTextCtrlStatusValidatorImpl::M_TraitedTextCtrlStatusValidatorImpl(M_Basictype * BasictypeValue,
01858:                        M_Basictype MinBasictype, M_Basictype MaxBasictype,
01859:                        wxStatusMessageTarget * StatusMessageTarget,
01860:                        const wxString & FieldNameString,
01861:                        int Flags, M_Basictype UndefinedBasictype,
01862:                        const wxString & FormatString)
01863:   : wxTraitedTextCtrlStatusValidator(& m_BasictypeValidatorTrait,
01864:                                      StatusMessageTarget, Flags)
01865: {
01866:     m_BasictypeValidatorTrait.init (BasictypeValue,
01867:                                     MinBasictype, MaxBasictype,
01868:                                     FieldNameString,
01869:                                     Flags, UndefinedBasictype,
01870:                                     FormatString);
01871: }
01872: 
01873: M_TraitedTextCtrlStatusValidatorImpl::M_TraitedTextCtrlStatusValidatorImpl(const M_TraitedTextCtrlStatusValidatorImpl& TraitedTextCtrlStatusValidatorImpl)
01874:     : wxTraitedTextCtrlStatusValidator()
01875: {
01876:     Copy(TraitedTextCtrlStatusValidatorImpl);
01877: }
01878: 
01879: M_TraitedTextCtrlStatusValidatorImpl::~M_TraitedTextCtrlStatusValidatorImpl()
01880: {
01881: }
01882: 
01883: //-------------------------------------------------------------------------
01884: 
01885: bool M_TraitedTextCtrlStatusValidatorImpl::Copy(const M_TraitedTextCtrlStatusValidatorImpl& TraitedTextCtrlStatusValidatorImpl)
01886: {
01887:     wxTraitedTextCtrlStatusValidator::Copy(TraitedTextCtrlStatusValidatorImpl);
01888: 
01889:     m_BasictypeValidatorTrait = TraitedTextCtrlStatusValidatorImpl.m_BasictypeValidatorTrait;
01890:     m_TextCtrlStatusValidatorTrait = & m_BasictypeValidatorTrait;
01891:     return true;
01892: }
01893: 
01894: //-------------------------------------------------------------------------
01895: 
01896: // undefine shortcuts
01897:     #undef M_Basictype
01898:     #undef M_BasictypeValidatorTrait
01899: 
01900: //-------------------------------------------------------------------------
01901: 
01902: #endif // defined M_TraitedTextCtrlStatusValidatorImpl
01903: 
01904: //=========================================================================
01905: 
01906: #endif // defined M_StatusValidators_IsEmitGenericImplementation
01907: 
01908: //-------------------------------------------------------------------------
01909: 
01910: #if (!defined M_StatusValidators_IsEmitGenericImplementation)
01911: 
01912: //-------------------------------------------------------------------------
01913: 
01914: #define M_StatusValidators_IsEmitGenericImplementation
01915: 
01916: //-------------------------------------------------------------------------
01917: 
01918: // implement wxTraitedIntValidator
01919:     #define M_TraitedTextCtrlStatusValidatorImpl wxTraitedIntValidator
01920:     #define M_TraitedTextCtrlStatusValidatorImpl_BasictypeValidatorTrait wxBasictypeValidatorTrait_int
01921:     #define M_TraitedTextCtrlStatusValidatorImpl_Basictype int
01922:     #include "StatusValidators.cpp"
01923:     #undef M_TraitedTextCtrlStatusValidatorImpl
01924:     #undef M_TraitedTextCtrlStatusValidatorImpl_BasictypeValidatorTrait
01925:     #undef M_TraitedTextCtrlStatusValidatorImpl_Basictype
01926: 
01927: // implement wxTraitedUintValidator
01928:     #define M_TraitedTextCtrlStatusValidatorImpl wxTraitedUintValidator
01929:     #define M_TraitedTextCtrlStatusValidatorImpl_BasictypeValidatorTrait wxBasictypeValidatorTrait_uint
01930:     #define M_TraitedTextCtrlStatusValidatorImpl_Basictype unsigned int
01931:     #include "StatusValidators.cpp"
01932:     #undef M_TraitedTextCtrlStatusValidatorImpl
01933:     #undef M_TraitedTextCtrlStatusValidatorImpl_BasictypeValidatorTrait
01934:     #undef M_TraitedTextCtrlStatusValidatorImpl_Basictype
01935: 
01936: // implement wxTraitedLongValidator
01937:     #define M_TraitedTextCtrlStatusValidatorImpl wxTraitedLongValidator
01938:     #define M_TraitedTextCtrlStatusValidatorImpl_BasictypeValidatorTrait wxBasictypeValidatorTrait_long
01939:     #define M_TraitedTextCtrlStatusValidatorImpl_Basictype long
01940:     #include "StatusValidators.cpp"
01941:     #undef M_TraitedTextCtrlStatusValidatorImpl
01942:     #undef M_TraitedTextCtrlStatusValidatorImpl_BasictypeValidatorTrait
01943:     #undef M_TraitedTextCtrlStatusValidatorImpl_Basictype
01944: 
01945: // implement wxTraitedUlongValidator
01946:     #define M_TraitedTextCtrlStatusValidatorImpl wxTraitedUlongValidator
01947:     #define M_TraitedTextCtrlStatusValidatorImpl_BasictypeValidatorTrait wxBasictypeValidatorTrait_ulong
01948:     #define M_TraitedTextCtrlStatusValidatorImpl_Basictype unsigned long
01949:     #include "StatusValidators.cpp"
01950:     #undef M_TraitedTextCtrlStatusValidatorImpl
01951:     #undef M_TraitedTextCtrlStatusValidatorImpl_BasictypeValidatorTrait
01952:     #undef M_TraitedTextCtrlStatusValidatorImpl_Basictype
01953: 
01954: // implement wxTraitedStringValidatorBase
01955:     #define M_TraitedTextCtrlStatusValidatorImpl wxTraitedStringValidatorBase
01956:     #define M_TraitedTextCtrlStatusValidatorImpl_BasictypeValidatorTrait wxBasictypeValidatorTrait_wxString
01957:     #define M_TraitedTextCtrlStatusValidatorImpl_Basictype wxString
01958:     #include "StatusValidators.cpp"
01959:     #undef M_TraitedTextCtrlStatusValidatorImpl
01960:     #undef M_TraitedTextCtrlStatusValidatorImpl_BasictypeValidatorTrait
01961:     #undef M_TraitedTextCtrlStatusValidatorImpl_Basictype
01962: 
01963: // implement wxTraitedDateTimeValidatorBase
01964:     #define M_TraitedTextCtrlStatusValidatorImpl wxTraitedDateTimeValidatorBase
01965:     #define M_TraitedTextCtrlStatusValidatorImpl_BasictypeValidatorTrait wxBasictypeValidatorTrait_wxDateTime
01966:     #define M_TraitedTextCtrlStatusValidatorImpl_Basictype wxDateTime
01967:     #include "StatusValidators.cpp"
01968:     #undef M_TraitedTextCtrlStatusValidatorImpl
01969:     #undef M_TraitedTextCtrlStatusValidatorImpl_BasictypeValidatorTrait
01970:     #undef M_TraitedTextCtrlStatusValidatorImpl_Basictype
01971: 
01972: 
01973: //-------------------------------------------------------------------------
01974: 
01975: #undef M_StatusValidators_IsEmitGenericImplementation
01976: 
01977: //=========================================================================
01978: 
01979: IMPLEMENT_DYNAMIC_CLASS(wxRONumberValidator, wxNumberValidator)
01980: 
01981: //-------------------------------------------------------------------------
01982: 
01983: wxRONumberValidator::wxRONumberValidator()
01984: {
01985: }
01986: 
01987: wxRONumberValidator::wxRONumberValidator(int * IntegerValue,
01988:                                          int Flags, int UndefinedInteger)
01989:   : wxNumberValidator (IntegerValue, 0, 0, NULL, wxEmptyString, Flags, UndefinedInteger)
01990: {
01991: }
01992: 
01993: wxRONumberValidator::wxRONumberValidator(long * LongValue,
01994:                                          int Flags, int UndefinedLong)
01995:   : wxNumberValidator (LongValue, 0L, 0L, NULL, wxEmptyString, Flags, UndefinedLong)
01996: {
01997: }
01998: 
01999: //=========================================================================
02000: 
02001: IMPLEMENT_DYNAMIC_CLASS(wxTraitedStringValidator, wxTraitedStringValidatorBase)
02002: 
02003: BEGIN_EVENT_TABLE(wxTraitedStringValidator, wxTraitedStringValidatorBase)
02004: END_EVENT_TABLE()
02005: 
02006: //-------------------------------------------------------------------------
02007: 
02008: wxTraitedStringValidator::wxTraitedStringValidator ()
02009: {
02010: }
02011: 
02012: wxTraitedStringValidator::wxTraitedStringValidator(wxString * StringPtr, 
02013:                                                    wxStatusMessageTarget * StatusMessageTarget,
02014:                                                    const wxString & FieldNameString,
02015:                                                    int MaxStringLength, 
02016:                                                    int Flags, 
02017:                                                    const wxString & UndefinedString)
02018: {
02019:     // TODO: add init() function to base classes instead of directly 
02020:     // accessing member variables
02021:     m_TextCtrlStatusValidatorTrait = & m_BasictypeValidatorTrait;
02022:     m_StatusMessageTarget = StatusMessageTarget;
02023: 
02024:     Flags |= IsIgnoreMinimum | IsIgnoreMaximum;
02025: 
02026:     m_Flags = Flags;
02027: 
02028:     m_BasictypeValidatorTrait.init (StringPtr,
02029:                                     wxEmptyString /* MinBasictype (dummy) */,
02030:                                     wxEmptyString /* MaxBasictype (dummy) */,
02031:                                     FieldNameString,
02032:                                     Flags,
02033:                                     UndefinedString,
02034:                                     wxEmptyString /* FormatString */);
02035: 
02036:     m_BasictypeValidatorTrait.setMinStringLength (0);
02037:     m_BasictypeValidatorTrait.setMaxStringLength (MaxStringLength);
02038: }
02039: 
02040: wxTraitedStringValidator::wxTraitedStringValidator (const wxTraitedStringValidator & TraitedStringValidator)
02041: {
02042:     // WARN must Copy() of base class called here or in copy-ctr?
02043:     Copy (TraitedStringValidator);
02044: }
02045: 
02046: bool wxTraitedStringValidator::Copy (const wxTraitedStringValidator & TraitedStringValidator)
02047: {
02048:     // WARN must Copy() of base class called here or in copy-ctr?
02049:     wxTraitedStringValidatorBase::Copy (TraitedStringValidator);
02050:     return true;
02051: }
02052: 
02053: //=========================================================================
02054: 
02055: IMPLEMENT_DYNAMIC_CLASS(wxTraitedDateTimeValidator, wxTraitedDateTimeValidatorBase)
02056: 
02057: BEGIN_EVENT_TABLE(wxTraitedDateTimeValidator, wxTraitedDateTimeValidatorBase)
02058: END_EVENT_TABLE()
02059: 
02060: //-------------------------------------------------------------------------
02061: 
02062: wxTraitedDateTimeValidator::wxTraitedDateTimeValidator ()
02063: {
02064: }
02065: 
02066: wxTraitedDateTimeValidator::wxTraitedDateTimeValidator(wxDateTime * DateTimePtr, 
02067:                                                        wxStatusMessageTarget * StatusMessageTarget,
02068:                                                        const wxString & FieldNameString,
02069:                                                        int Flags,
02070:                                                        const wxString & DateTimeFormatString)
02071: {
02072:     // TODO: add init() function to base classes instead of directly 
02073:     // accessing member variables
02074:     m_TextCtrlStatusValidatorTrait = & m_BasictypeValidatorTrait;
02075:     m_StatusMessageTarget = StatusMessageTarget;
02076: 
02077:     Flags |= IsIgnoreMinimum | IsIgnoreMaximum;
02078: 
02079:     m_Flags = Flags;
02080: 
02081:     wxString UsedDateTimeFormatString = DateTimeFormatString;
02082:     if (UsedDateTimeFormatString.IsEmpty())
02083:       {
02084:         UsedDateTimeFormatString = "%Y-%m-%d %H:%M:%S";
02085:       }
02086: 
02087:     m_BasictypeValidatorTrait.init (DateTimePtr,
02088:                                     wxInvalidDateTime /* MinBasictype (dummy) */,
02089:                                     wxInvalidDateTime /* MaxBasictype (dummy) */,
02090:                                     FieldNameString,
02091:                                     Flags,
02092:                                     wxInvalidDateTime /* UndefinedBasictype */,
02093:                                     UsedDateTimeFormatString);
02094: }
02095: 
02096: wxTraitedDateTimeValidator::wxTraitedDateTimeValidator (wxDateTime * DateTimePtr, 
02097:                                                         wxDateTime MinDateTime, wxDateTime MaxDateTime,
02098:                                                         wxStatusMessageTarget * StatusMessageTarget,
02099:                                                         const wxString & FieldNameString,
02100:                                                         int Flags, wxDateTime UndefinedDateTime,
02101:                                                         const wxString & DateTimeFormatString)
02102: {
02103:     // TODO: add init() function to base classes instead of directly 
02104:     // accessing member variables
02105:     m_TextCtrlStatusValidatorTrait = & m_BasictypeValidatorTrait;
02106:     m_StatusMessageTarget = StatusMessageTarget;
02107: 
02108:     m_Flags = Flags;
02109: 
02110:     wxString UsedDateTimeFormatString = DateTimeFormatString;
02111:     if (UsedDateTimeFormatString.IsEmpty())
02112:       {
02113:         UsedDateTimeFormatString = "%Y-%m-%d %H:%M:%S";
02114:       }
02115: 
02116:     m_BasictypeValidatorTrait.init (DateTimePtr,
02117:                                     MinDateTime,
02118:                                     MaxDateTime,
02119:                                     FieldNameString,
02120:                                     Flags,
02121:                                     UndefinedDateTime,
02122:                                     UsedDateTimeFormatString);
02123: }
02124: 
02125: wxTraitedDateTimeValidator::wxTraitedDateTimeValidator (const wxTraitedDateTimeValidator & TraitedDateTimeValidator)
02126: {
02127:     // WARN must Copy() of base class called here or in copy-ctr?
02128:     Copy (TraitedDateTimeValidator);
02129: }
02130: 
02131: bool wxTraitedDateTimeValidator::Copy (const wxTraitedDateTimeValidator & TraitedDateTimeValidator)
02132: {
02133:     // WARN must Copy() of base class called here or in copy-ctr?
02134:     wxTraitedDateTimeValidatorBase::Copy (TraitedDateTimeValidator);
02135:     return true;
02136: }
02137: 
02138: //=========================================================================
02139: 
02140: IMPLEMENT_DYNAMIC_CLASS(wxNonTraitedDateTimeValidator, wxTextCtrlStatusValidator)
02141: 
02142: BEGIN_EVENT_TABLE(wxNonTraitedDateTimeValidator, wxTextCtrlStatusValidator)
02143: END_EVENT_TABLE()
02144: 
02145: //-------------------------------------------------------------------------
02146: 
02147: wxNonTraitedDateTimeValidator::wxNonTraitedDateTimeValidator()
02148: {
02149:     m_DateTimeValue = NULL;
02150:     m_FieldNameString = "";
02151: }
02152: 
02153: wxNonTraitedDateTimeValidator::wxNonTraitedDateTimeValidator(wxDateTime * DateTime, 
02154:                                          wxStatusMessageTarget * StatusMessageTarget,
02155:                                          const wxString & FieldNameString,
02156:                                          int Flags)
02157:   : wxTextCtrlStatusValidator (StatusMessageTarget, Flags)
02158: {
02159:     m_DateTimeValue = DateTime;
02160:     m_FieldNameString = FieldNameString;
02161: }
02162: 
02163: wxNonTraitedDateTimeValidator::wxNonTraitedDateTimeValidator(const wxNonTraitedDateTimeValidator& NonTraitedDateTimeValidator)
02164:     : wxTextCtrlStatusValidator()
02165: {
02166:     Copy(NonTraitedDateTimeValidator);
02167: }
02168: 
02169: bool wxNonTraitedDateTimeValidator::Copy(const wxNonTraitedDateTimeValidator& NonTraitedDateTimeValidator)
02170: {
02171:     wxTextCtrlStatusValidator::Copy(NonTraitedDateTimeValidator);
02172: 
02173:     m_DateTimeValue = NonTraitedDateTimeValidator.m_DateTimeValue ;
02174:     m_FieldNameString = NonTraitedDateTimeValidator.m_FieldNameString;
02175: 
02176:     return true;
02177: }
02178: 
02179: wxNonTraitedDateTimeValidator::~wxNonTraitedDateTimeValidator()
02180: {
02181: }
02182: 
02183: //-------------------------------------------------------------------------
02184: 
02185: void wxNonTraitedDateTimeValidator::transferToWindow (wxString & TextCtrlContentString)
02186: {
02187:     transferToWindowHelper (* m_DateTimeValue, TextCtrlContentString);
02188: }
02189: 
02190: void wxNonTraitedDateTimeValidator::transferToWindowHelper (const wxDateTime & TempDateTime, wxString & TextCtrlContentString)
02191: {
02192:     if ((m_Flags & IsEmptyAllowed) 
02193:         && (!TempDateTime.IsValid()))
02194:       {
02195:         TextCtrlContentString = "";
02196:       }
02197:     else
02198:       {
02199:         formatDate (TempDateTime, TextCtrlContentString);
02200:       }
02201: }
02202: 
02203: //-------------------------------------------------------------------------
02204: 
02205: bool wxNonTraitedDateTimeValidator::transferFromWindowTemporary (const wxString & TextCtrlContentString,
02206:                                                        wxString & ErrorMessageString,
02207:                                                        bool IsTextCtrlChangeEvent)
02208: {
02209:     wxDateTime TempDateTime;
02210:     bool IsOk = transferFromWindowHelper (TextCtrlContentString,
02211:                                           & TempDateTime, ErrorMessageString);
02212:     if (IsOk && IsTextCtrlChangeEvent)
02213:       handleValidInput (TempDateTime);
02214: 
02215:     return IsOk;
02216: }
02217: 
02218: bool wxNonTraitedDateTimeValidator::transferFromWindowPersistent (const wxString & TextCtrlContentString,
02219:                                                         wxString & ErrorMessageString)
02220: {
02221:     bool IsOk = true;
02222:     if (m_DateTimeValue)
02223:       {
02224:         IsOk = transferFromWindowHelper (TextCtrlContentString,
02225:                                          m_DateTimeValue, ErrorMessageString);
02226:       }
02227:     return IsOk;
02228: }
02229: 
02230: //-------------------------------------------------------------------------
02231: 
02232: bool wxNonTraitedDateTimeValidator::transferFromWindowHelper (const wxString & TextCtrlContentString,
02233:                                                     wxDateTime * DateTime, 
02234:                                                     wxString & ErrorMessageString)
02235: {
02236:     wxString TrimmedInputString = TextCtrlContentString;
02237:     TrimmedInputString.Trim (false);
02238:     TrimmedInputString.Trim (true);
02239: 
02240:     wxDateTime TempDateTime = wxInvalidDateTime;
02241:     if ((m_Flags & IsEmptyAllowed) && TrimmedInputString.IsEmpty())
02242:       {
02243:         TempDateTime = wxInvalidDateTime;
02244:       }
02245:     else
02246:       {
02247:         bool IsOk = parseDate (TrimmedInputString, TempDateTime);
02248:         if (IsOk)
02249:           {
02250:             if (!checkValue (TempDateTime))
02251:               IsOk = false;
02252:           }
02253: 
02254:         if (!IsOk)
02255:           {
02256:             // TODO: the error message should contain information about
02257:             // which date date format(s) are accepted for the current locale
02258:             getErrorMessageString (TempDateTime, ErrorMessageString);
02259:             return false;
02260:           }
02261:       }
02262:     *DateTime = TempDateTime;
02263:     return true;
02264: }
02265: 
02266: bool wxNonTraitedDateTimeValidator::checkValue (const wxDateTime & DateTime)
02267: {
02268:     return DateTime.IsValid();
02269:     // return true;
02270: }
02271: 
02272: void wxNonTraitedDateTimeValidator::getErrorMessageString (const wxDateTime & WXUNUSED(DateTime), 
02273:                                                  wxString & ErrorMessageString)
02274: {
02275:     ErrorMessageString
02276:       += MessageFormatter (_("ERROR: input must be a valid date%1 for \"%2\""))
02277:       % ((m_Flags & IsEmptyAllowed) ? _(" (or empty)") : "")
02278:       % m_FieldNameString;
02279: }
02280: 
02281: //-------------------------------------------------------------------------
02282: 
02283: void wxNonTraitedDateTimeValidator::handleValidInput (const wxDateTime & WXUNUSED(DateTime))
02284: {
02285: }
02286: 
02287: //=========================================================================
02288: 
02289: IMPLEMENT_DYNAMIC_CLASS(wxNonTraitedStringValidator, wxTextCtrlStatusValidator)
02290: 
02291: BEGIN_EVENT_TABLE(wxNonTraitedStringValidator, wxTextCtrlStatusValidator)
02292: END_EVENT_TABLE()
02293: 
02294: // WARN this should be better of type size_t:
02295: const int UnlimitedStringLength = -1;
02296: 
02297: //-------------------------------------------------------------------------
02298: 
02299: wxNonTraitedStringValidator::wxNonTraitedStringValidator()
02300: {
02301:     m_StringValue = NULL;
02302:     m_FieldNameString = "";
02303:     m_MaxStringLength = UnlimitedStringLength;
02304:     m_Flags = 0;
02305:     m_UndefinedString = "";
02306: }
02307: 
02308: wxNonTraitedStringValidator::wxNonTraitedStringValidator(wxString * StringValue, 
02309:                                      wxStatusMessageTarget * StatusMessageTarget,
02310:                                      const wxString & FieldNameString,
02311:                                      int MaxStringLength,
02312:                                      int Flags, const wxString & UndefinedString)
02313:   : wxTextCtrlStatusValidator (StatusMessageTarget, Flags)
02314: {
02315:     m_StringValue = StringValue;
02316:     m_FieldNameString = FieldNameString;
02317:     m_MaxStringLength = MaxStringLength;
02318:     m_Flags = Flags;
02319:     m_UndefinedString = UndefinedString;
02320: }
02321: 
02322: wxNonTraitedStringValidator::wxNonTraitedStringValidator(const wxNonTraitedStringValidator& StringValidator)
02323:     : wxTextCtrlStatusValidator()
02324: {
02325:     Copy(StringValidator);
02326: }
02327: 
02328: bool wxNonTraitedStringValidator::Copy(const wxNonTraitedStringValidator& StringValidator)
02329: {
02330:     wxTextCtrlStatusValidator::Copy(StringValidator);
02331: 
02332:     m_StringValue = StringValidator.m_StringValue;
02333:     m_FieldNameString = StringValidator.m_FieldNameString;
02334:     m_MaxStringLength = StringValidator.m_MaxStringLength;
02335:     m_Flags = StringValidator.m_Flags;
02336:     m_UndefinedString = StringValidator.m_UndefinedString;
02337: 
02338:     return true;
02339: }
02340: 
02341: wxNonTraitedStringValidator::~wxNonTraitedStringValidator()
02342: {
02343: }
02344: 
02345: //-------------------------------------------------------------------------
02346: 
02347: void wxNonTraitedStringValidator::transferToWindow (wxString & TextCtrlContentString)
02348: {
02349:     transferToWindowHelper (*m_StringValue, TextCtrlContentString);
02350: }
02351: 
02352: void wxNonTraitedStringValidator::transferToWindowHelper (const wxString & String, 
02353:                                                 wxString & TextCtrlContentString)
02354: {
02355:     if ((m_Flags & IsEmptyAllowed) 
02356:         && (String == m_UndefinedString))
02357:       {
02358:         TextCtrlContentString = "";
02359:       }
02360:     else
02361:       {
02362:         TextCtrlContentString = String;
02363:       }
02364: }
02365: 
02366: //-------------------------------------------------------------------------
02367: 
02368: bool wxNonTraitedStringValidator::transferFromWindowTemporary (const wxString & TextCtrlContentString,
02369:                                                      wxString & ErrorMessageString,
02370:                                                      bool IsTextCtrlChangeEvent)
02371: {
02372:     wxString TempString;
02373:     bool IsOk = transferFromWindowHelper (TextCtrlContentString,
02374:                                           & TempString, ErrorMessageString);
02375:     if (IsOk && IsTextCtrlChangeEvent)
02376:       handleValidInput (TempString);
02377: 
02378:     return IsOk;
02379: }
02380: 
02381: bool wxNonTraitedStringValidator::transferFromWindowPersistent (const wxString & TextCtrlContentString,
02382:                                                       wxString & ErrorMessageString)
02383: {
02384:     bool IsOk = true;
02385:     if (m_StringValue)
02386:       {
02387:         IsOk = transferFromWindowHelper (TextCtrlContentString,
02388:                                          m_StringValue, ErrorMessageString);
02389:       }
02390:     return IsOk;
02391: }
02392: 
02393: //-------------------------------------------------------------------------
02394: 
02395: bool wxNonTraitedStringValidator::transferFromWindowHelper (const wxString & TextCtrlContentString,
02396:                                                   wxString * String, 
02397:                                                   wxString & ErrorMessageString)
02398: {
02399:     wxString TempString = TextCtrlContentString;
02400:     // if trimming is desired:
02401:     // TODO: add a flag like 'IsRemoveLeadingTrailingSpaces'
02402:     // TempString.Trim (false);
02403:     // TempString.Trim (true);
02404: 
02405:     if ((m_Flags & IsEmptyAllowed) 
02406:         && TempString.IsEmpty())
02407:       {
02408:         TempString = m_UndefinedString;
02409:       }
02410:     else
02411:       {
02412:         if (!checkValue (TempString))
02413:           {
02414:             getErrorMessageString (TempString, ErrorMessageString);
02415:             return false;
02416:           }
02417:       }
02418:     *String = TempString;
02419:     return true;
02420: }
02421: 
02422: bool wxNonTraitedStringValidator::checkValue (const wxString & String)
02423: {
02424:     bool IsOK = true;
02425:     if (!m_Flags & IsEmptyAllowed)
02426:       {
02427:         if (String.IsEmpty())
02428:           IsOK = false;
02429:       }
02430:     if (m_MaxStringLength != UnlimitedStringLength)
02431:       {
02432:         if (cast_is_greater (String.Length(), m_MaxStringLength))
02433:           IsOK = false;
02434:       }
02435:     return IsOK;
02436: }
02437: 
02438: void wxNonTraitedStringValidator::getErrorMessageString (const wxString & WXUNUSED(String), 
02439:                                                wxString & ErrorMessageString)
02440: {
02441:     wxString MaxStringLengthDescriptionString;
02442:     if (m_MaxStringLength != UnlimitedStringLength)
02443:       {
02444:         MaxStringLengthDescriptionString 
02445:           = wxFormatMessage (_("with no more than %1 characters "), m_MaxStringLength);
02446:       }
02447: 
02448:     ErrorMessageString = wxFormatMessage 
02449:       (_("ERROR: input must be a string %1%2for \"%3\"."),
02450:        MaxStringLengthDescriptionString,
02451:        m_Flags & IsEmptyAllowed ? _("(or empty) ") : "",
02452:        m_FieldNameString);
02453: }
02454: 
02455: //-------------------------------------------------------------------------
02456: 
02457: void wxNonTraitedStringValidator::handleValidInput (const wxString & WXUNUSED(String))
02458: {
02459: }
02460: 
02461: //=========================================================================
02462: 
02463: wxFilenameValidatorTrait::wxFilenameValidatorTrait ()
02464:   : wxBasictypeValidatorTrait_wxString ()
02465: {
02466: }
02467: 
02468: /*
02469: wxFilenameValidatorTrait::wxFilenameValidatorTrait (wxString * FilenameStringPtr,
02470:                                                     const wxString & FieldNameString,
02471:                                                     int BasictypeValidatorTraitFlags,
02472:                                                     int FilenameValidatorTraitFlags,
02473:                                                     const wxString & UndefinedFilenameString)
02474: {
02475: }
02476: */
02477: 
02478: void wxFilenameValidatorTrait::init (wxString * FilenameStringPtr,
02479:                                      const wxString & FieldNameString,
02480:                                      int BasictypeValidatorTraitFlags,
02481:                                      int FilenameValidatorTraitFlags,
02482:                                      const wxString & RelativeRefPathString,
02483:                                      int NormalizeFlags)
02484: {
02485:     init (FilenameStringPtr,
02486:           wxEmptyString /* MinBasictype */, 
02487:           wxEmptyString /* MaxBasictype */,
02488:           FieldNameString,
02489:           BasictypeValidatorTraitFlags 
02490:           | wxBasictypeValidatorTrait_wxString::IsIgnoreMinimum
02491:           | wxBasictypeValidatorTrait_wxString::IsIgnoreMaximum, 
02492:           wxEmptyString,
02493:           wxEmptyString /* FormatString */);
02494: 
02495:     m_FilenameValidatorTraitFlags = FilenameValidatorTraitFlags;
02496:     m_RelativeRefPathString = RelativeRefPathString;
02497:     m_NormalizeFlags = NormalizeFlags;
02498: }
02499: 
02500: void wxFilenameValidatorTrait::init (wxString * BasictypeValuePtr, 
02501:                                      wxString MinBasictype, wxString MaxBasictype,
02502:                                      const wxString & FieldNameString,
02503:                                      int Flags, wxString UndefinedBasictype,
02504:                                      const wxString & FormatString)
02505: {
02506:     wxBasictypeValidatorTrait_wxString::init (BasictypeValuePtr,
02507:                                               MinBasictype, MaxBasictype,
02508:                                               FieldNameString,
02509:                                               Flags,
02510:                                               UndefinedBasictype,
02511:                                               FormatString);
02512: }
02513: 
02514: bool wxFilenameValidatorTrait::convertFromStringHelper (const wxString & TextCtrlContentString,
02515:                                                         wxString * FilenameStringPtr,
02516:                                                         wxString & ErrorMessageString)
02517: {
02518:     wxString TrimmedInputString = TextCtrlContentString;
02519:     TrimmedInputString.Trim (false);
02520:     TrimmedInputString.Trim (true);
02521: 
02522:     bool IsOk = false;
02523:     if ((m_Flags & IsEmptyAllowed) && TrimmedInputString.IsEmpty())
02524:       {
02525:         *FilenameStringPtr = m_UndefinedBasictype;
02526:         IsOk = true;
02527:       }
02528:     else
02529:       {
02530:         bool IsFilenameOk = true;
02531: 
02532:         wxFileName FileName (TrimmedInputString);
02533: 
02534:         if (m_FilenameValidatorTraitFlags & IsNormalize)
02535:           {
02536:             FileName.Normalize (m_NormalizeFlags, m_RelativeRefPathString 
02537:                                 /*, wxPATH_NATIVE */);
02538:           }
02539: 
02540:         const char * ErrorMessageFormatString = _("[no error]");
02541: 
02542:         if (TrimmedInputString.IsEmpty())
02543:           {
02544:             ErrorMessageFormatString = _("ERROR: filename must be given for \"%2\"");
02545:             IsFilenameOk = false;
02546:           }
02547: 
02548:         if (IsFilenameOk 
02549:             && (m_FilenameValidatorTraitFlags & IsErrorIfInvalid))
02550:           {
02551:             if (!FileName.IsOk())
02552:               {
02553:                 ErrorMessageFormatString = _("ERROR: not a valid filename for \"%2\"");
02554:                 IsFilenameOk = false;
02555:               }
02556:           }
02557:         if (IsFilenameOk 
02558:             && (m_FilenameValidatorTraitFlags & IsErrorIfNotFile))
02559:           {
02560:             if (!FileName.FileExists())
02561:               {
02562:                 ErrorMessageFormatString = _("ERROR: file does not exist for \"%2\"");
02563:                 IsFilenameOk = false;
02564:               }
02565:           }
02566:         if (IsFilenameOk 
02567:             && (m_FilenameValidatorTraitFlags & IsErrorIfNotDirectory))
02568:           {
02569:             if (!FileName.DirExists())
02570:               {
02571:                 ErrorMessageFormatString = _("ERROR: directory does not exist for \"%2\"");
02572:                 IsFilenameOk = false;
02573:               }
02574:           }
02575: 
02576:         IsOk = IsFilenameOk;
02577: 
02578:         if (IsOk)
02579:           {
02580:             if (m_FilenameValidatorTraitFlags & IsNormalize)
02581:               {
02582:                 if (m_FilenameValidatorTraitFlags & IsStoreRelative)
02583:                   {
02584:                     wxString FilenameString = FileName.GetFullPath();
02585:                     FileName.MakeRelativeTo (m_RelativeRefPathString /*, RelativeRefPathFormat */);
02586: 
02587:                     if (((m_FilenameValidatorTraitFlags & IsStoreNoRelativeParentDir) != 0)
02588:                         && (FileName.GetFullPath().StartsWith ("..")))
02589:                       {
02590:                         *FilenameStringPtr = FilenameString;
02591:                       }
02592:                     else
02593:                       {
02594:                         *FilenameStringPtr = FileName.GetFullPath ();
02595:                       }
02596:                   }
02597:                 else
02598:                   {
02599:                     *FilenameStringPtr = FileName.GetFullPath();
02600:                   }
02601:               }
02602:             else
02603:               {
02604:                 *FilenameStringPtr = TrimmedInputString;
02605:               }
02606:           }
02607: 
02608:         if (!IsOk)
02609:           {
02610:             ErrorMessageString = wxFormatMessage (ErrorMessageFormatString,
02611:                                                   TrimmedInputString,
02612:                                                   m_FieldNameString);
02613:           }
02614:       }
02615: 
02616:     return IsOk;
02617: }
02618: 
02619: //-------------------------------------------------------------------------
02620: 
02621: // implement wxFilenameValidatorBase
02622:   #define M_StatusValidators_IsEmitGenericImplementation
02623:     #define M_TraitedTextCtrlStatusValidatorImpl wxFilenameValidatorBase
02624:     #define M_TraitedTextCtrlStatusValidatorImpl_BasictypeValidatorTrait wxFilenameValidatorTrait
02625:     #define M_TraitedTextCtrlStatusValidatorImpl_Basictype wxString
02626:     #include "StatusValidators.cpp"
02627:     #undef M_TraitedTextCtrlStatusValidatorImpl
02628:     #undef M_TraitedTextCtrlStatusValidatorImpl_BasictypeValidatorTrait
02629:     #undef M_TraitedTextCtrlStatusValidatorImpl_Basictype
02630:   #undef M_StatusValidators_IsEmitGenericImplementation
02631: 
02632: //-------------------------------------------------------------------------
02633: 
02634: IMPLEMENT_DYNAMIC_CLASS(wxFilenameValidator, wxFilenameValidatorBase)
02635: 
02636: BEGIN_EVENT_TABLE(wxFilenameValidator, wxFilenameValidatorBase)
02637: END_EVENT_TABLE()
02638: 
02639: wxFilenameValidator::wxFilenameValidator ()
02640: {
02641: }
02642: 
02643: wxFilenameValidator::wxFilenameValidator (wxString * FilenameStringPtr,
02644:                                           wxStatusMessageTarget * StatusMessageTarget,
02645:                                           const wxString & FieldNameString,
02646:                                           int BasictypeValidatorTraitFlags,
02647:                                           int FilenameValidatorTraitFlags,
02648:                                           const wxString & RelativeRefPathString,
02649:                                           int NormalizeFlags)
02650: {
02651:     // TODO: add init() function to base classes instead of directly 
02652:     // accessing member variables
02653:     m_TextCtrlStatusValidatorTrait = & m_BasictypeValidatorTrait;
02654:     m_StatusMessageTarget = StatusMessageTarget;
02655:     m_Flags = BasictypeValidatorTraitFlags;
02656: 
02657:     m_BasictypeValidatorTrait.init (FilenameStringPtr,
02658:                                     FieldNameString,
02659:                                     BasictypeValidatorTraitFlags,
02660:                                     FilenameValidatorTraitFlags,
02661:                                     RelativeRefPathString,
02662:                                     NormalizeFlags);
02663: }
02664: 
02665: wxFilenameValidator::wxFilenameValidator (const wxFilenameValidator& FilenameValidator)
02666: {
02667:     // WARN must Copy() of base class called here or in copy-ctr?
02668:     Copy (FilenameValidator);
02669: }
02670: 
02671: bool wxFilenameValidator::Copy (const wxFilenameValidator & FilenameValidator)
02672: {
02673:     // WARN must Copy() of base class called here or in copy-ctr?
02674:     wxFilenameValidatorBase::Copy (FilenameValidator);
02675:     return true;
02676: }
02677: 
02678: //=========================================================================
02679: 
02680: void updateComboBoxSelectionFromText (wxComboBox * ComboBox, 
02681:                                       const wxString & TextCtrlString, bool IsForce)
02682: {
02683:     // HACK for wxMSW ComboBox (scope: wxWidgets 2.5.3): changing text
02684:     // in ComboBox's text fields seems to forget to update selection 
02685:     // state of items, so do this here
02686:     int CorrectSelectionIndex = ComboBox -> FindString (TextCtrlString);
02687:     int CurrentSelectionIndex = ComboBox -> GetSelection();
02688:     if (IsForce 
02689:         || (CurrentSelectionIndex != CorrectSelectionIndex))
02690:       {
02691:         // we must remember insertion index (cursor index)
02692:         // and text typed, because SetSelection(-1) resets
02693:         // them to 0/empty string
02694:         long InsertionIndex = ComboBox -> GetInsertionPoint ();
02695:                 
02696:         // the text typed into the ComboBox's text field doesn't
02697:         // have a corresponding item
02698:         // deselect if some item currently has the selected state
02699:         ComboBox -> SetSelection (CorrectSelectionIndex);
02700:         // WARN following may cause infinite recursive call of 
02701:         // this function, check
02702:         ComboBox -> SetValue (TextCtrlString);
02703:         ComboBox -> SetInsertionPoint (InsertionIndex);
02704:       }
02705: }
02706: 
02707: //-------------------------------------------------------------------------
02708: 
02709: #define M_activatePageIfBookCtrl(BookCtrlType) \
02710:     \
02711:         BookCtrlType * BookCtrl = wxDynamicCast (ParentWindow, BookCtrlType); \
02712:         if (BookCtrl != NULL) \
02713:           { \
02714:             /* try to find PageIndex which corresponds to CurrentWindow */  \
02715:             for (int PageIndex = 0; PageIndex < BookCtrl -> GetPageCount(); ++PageIndex) \
02716:               { \
02717:                 wxWindow * CurrentPageWindow = BookCtrl -> GetPage (PageIndex); \
02718:                 if (CurrentPageWindow == CurrentWindow) \
02719:                   { \
02720:                     /* activate page if found (but don't call SetSelection() if page */ \
02721:                     /* is already activated) */ \
02722:                     if (BookCtrl -> GetSelection() != PageIndex) \
02723:                       BookCtrl -> SetSelection (PageIndex); \
02724:  \
02725:                     break; \
02726:                   } \
02727:               } \
02728:           } \
02729: 
02730: void setFocusAndSelectParentBookPages (wxWindow * Window)
02731: {
02732:     Window -> SetFocus();
02733: 
02734:     wxWindow * CurrentWindow = Window;
02735:     wxWindow * ParentWindow = NULL;
02736: 
02737:     while (true)
02738:       {
02739:         ParentWindow = CurrentWindow -> GetParent();
02740:         if (ParentWindow == NULL)
02741:           break;
02742: 
02743: #if wxCHECK_VERSION (2, 5, 0)
02744:         // FUZZY don't know at which version exactly wxBookCtrl was added
02745:         // (sometime between 2.4.2 and 2.5.3)
02746: 
02747:         // could do:
02748:         //   M_activatePageIfBookCtrl (wxNotebook)
02749:         //   M_activatePageIfBookCtrl (wxListbook)
02750:         // but use of common base class wxBookCtrl class is better:
02751:         M_activatePageIfBookCtrl (wxBookCtrl)
02752: #else
02753:         M_activatePageIfBookCtrl (wxNotebook)
02754: #endif
02755: 
02756:         CurrentWindow = ParentWindow;
02757:       }
02758: }
02759: 
02760: #undef M_activatePageIfBookCtrl
02761: 
02762: //-------------------------------------------------------------------------
02763: 
02764: void transferDataToControl (wxWindow * Window)
02765: {
02766:     wxValidator * Validator = Window -> GetValidator();
02767:     if (Validator != NULL)
02768:       {
02769:         Validator -> TransferToWindow();
02770:       }
02771: }
02772: 
02773: bool validateControl (wxWindow * Window)
02774: {
02775:     wxValidator * Validator = Window -> GetValidator();
02776:     if (Validator != NULL)
02777:       {
02778:         // NOTE trap: Window->Validate() would only validate
02779:         // child windows (but not itself)
02780: 
02781:         // WARN according to the docs, Validate() expects pointer
02782:         // to parent window, but maybe associated dialog window was
02783:         // meant instead?
02784:         return (Validator -> Validate(Window -> GetParent()));
02785:       }
02786:     // default if no validator associated:
02787:     return true;
02788: }
02789: 
02790: bool transferDataFromControl (wxWindow * Window)
02791: {
02792:     wxValidator * Validator = Window -> GetValidator();
02793:     if (Validator != NULL)
02794:       {
02795:         // NOTE trap: Window->TransferToWindow() would only transfer
02796:         // data for all child windows (but not itself)
02797: 
02798:         return (Validator -> TransferFromWindow ());
02799:       }
02800:     // default if no validator associated:
02801:     return true;
02802: }
02803: 
02804: //=========================================================================
02805: 
02806: // #define M_IsUndefPPMacros 1
02807: // #   include "pp_basics.h" 
02808: // #undef M_IsUndefPPMacros
02809: 
02810: //-------------------------------------------------------------------------
02811: 
02812: #endif // M_StatusValidators_IsEmitGenericImplementation
02813: 
02814: //=========================================================================
02815: 
  [main]    [up]  
DaicasWeb v.1.50.0102  //   Daniel Käps  //   April 12, 2007  //   Impressum / Imprint 
http://www.daicas.net/WxExtLib/src/StatusValidators.cpp.html