[main]    [up]  

WxExtLib - ConfigEntry.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: #ifndef _NO_HEADER_INCLUDE
00042: 
00043: #include "WxExtLibConfig.h"
00044: 
00045: #if defined(__GNUG__) && (!defined(__APPLE__)) && (!defined(M_NoPragmaInterface))
00046: #   pragma implementation "ConfigEntry.cpp"
00047: #endif
00048: 
00049: // #include <wx/config.h>
00050: #include <wx/confbase.h>
00051: 
00052: #include "ConfigEntry.h"
00053: 
00054: // for possible HACK (see below)
00055: // #include <wx/fileconf.h>
00056: 
00057: #endif // _NO_HEADER_INCLUDE
00058: 
00059: //=========================================================================
00060: 
00061: wxConfigEntryManager::wxConfigEntryManager()
00062: {
00063:     m_ConfigBase = NULL;
00064: }
00065: 
00066: wxConfigEntryManager::~wxConfigEntryManager()
00067: {
00068: }
00069: 
00070: //-------------------------------------------------------------------------
00071: 
00072: void wxConfigEntryManager::addConfigEntry (wxConfigEntry * ConfigEntry)
00073: {
00074:     m_ConfigEntryArray.Add (ConfigEntry);
00075:     ConfigEntry -> setAssociatedConfig (m_ConfigBase);
00076: }
00077: 
00078: //-------------------------------------------------------------------------
00079: 
00080: void wxConfigEntryManager::setAssociatedConfig (wxConfigBase * ConfigBase)
00081: {
00082:     m_ConfigBase = ConfigBase;
00083: }
00084: 
00085: wxConfigBase * wxConfigEntryManager::getAssociatedConfig ()
00086: {
00087:     return m_ConfigBase;
00088: }
00089: 
00090: 
00091: //-------------------------------------------------------------------------
00092: 
00093: bool wxConfigEntryManager::readAllConfigEntries ()
00094: {
00095:     bool IsOk = true;
00096:     // OutputString: intended to collect messages about invalid entries etc.
00097:     // (not yet used)
00098:     wxString OutputString;
00099: 
00100:     int ConfigEntryCount = m_ConfigEntryArray.GetCount ();
00101:     for (int Index=0; Index < ConfigEntryCount; ++Index)
00102:       {
00103:         wxString MessageString;
00104:         if (! m_ConfigEntryArray.Item(Index) -> read (MessageString))
00105:           IsOk = FALSE;
00106: 
00107:         if (! MessageString.IsEmpty())
00108:           OutputString.Append (MessageString);
00109:       }
00110: 
00111:     return IsOk;
00112: }
00113: 
00114: bool wxConfigEntryManager::writeAllConfigEntries ()
00115: {
00116:     bool IsOk = true;
00117:     // OutputString: intended to collect messages about invalid entries etc.
00118:     // (not yet used)
00119:     wxString OutputString; 
00120: 
00121:     int ConfigEntryCount = m_ConfigEntryArray.GetCount ();
00122:     for (int Index=0; Index < ConfigEntryCount; ++Index)
00123:       {
00124:         wxString MessageString;
00125:         if (! m_ConfigEntryArray.Item(Index) -> write (MessageString))
00126:           IsOk = FALSE;
00127: 
00128:         if (! MessageString.IsEmpty())
00129:           OutputString.Append (MessageString);
00130:       }
00131: 
00132:     // HACK to get config values actually written if wxConfig is of
00133:     // type wxFileConfig (this class seems to call Flush()
00134:     // only in its destructor) - unfortunately, apprarently
00135:     // type information is not available for wxFileConfig
00136: //  if (m_ConfigBase -> IsKindOf (CLASSINFO (wxFileConfig)))
00137: //    {
00138: //      wxFileConfig * FileConfig = (*wxFileConfig) m_ConfigBase;
00139: //      FileConfig -> Flush ();
00140: //    }
00141: 
00142:     return IsOk;
00143: }
00144: 
00145: bool wxConfigEntryManager::setDefaultValues ()
00146: {
00147:     bool IsOk = true;
00148: 
00149:     int ConfigEntryCount = m_ConfigEntryArray.GetCount ();
00150:     for (int Index=0; Index < ConfigEntryCount; ++Index)
00151:       {
00152:         m_ConfigEntryArray.Item(Index) -> setToDefault ();
00153:       }
00154: 
00155:     return IsOk;
00156: }
00157: 
00158: //=========================================================================
00159: 
00160: wxConfigEntry::wxConfigEntry ()
00161: {
00162:     m_IsDontReread = FALSE;
00163:     m_IsDontWrite = FALSE;
00164:     m_IsForcedWrite = FALSE;
00165: 
00166:     m_IsAlreadyRead = FALSE;
00167:     m_IsChangePending = FALSE;
00168:     m_IsSetPending = FALSE;
00169:     m_ConfigBase = NULL;
00170: 
00171:     m_ReadMinimalTimeInterval.setMinimalTimeInterval (MinRereadIntervalMS);
00172: }
00173: 
00174: wxConfigEntry::~wxConfigEntry ()
00175: {
00176: }
00177: 
00178: //-------------------------------------------------------------------------
00179: 
00180: void wxConfigEntry::setEntryPath (const wxString & EntryPath)
00181: {
00182:     m_EntryPath = EntryPath;
00183: }
00184: 
00185: void wxConfigEntry::getEntryPath (wxString & EntryPath)
00186: {
00187:     EntryPath = m_EntryPath;
00188: }
00189: 
00190: void wxConfigEntry::setAssociatedConfig (wxConfigBase * ConfigBase)
00191: {
00192:     m_ConfigBase = ConfigBase;
00193: }
00194: 
00195: void wxConfigEntry::setDontReread (bool IsDontReread)
00196: {
00197:     m_IsDontReread = IsDontReread;
00198: }
00199: 
00200: void wxConfigEntry::setDontWrite (bool IsDontWrite)
00201: {
00202:     m_IsDontWrite = IsDontWrite;
00203: }
00204: 
00205: void wxConfigEntry::setForcedWrite (bool IsForcedWrite)
00206: {
00207:     m_IsForcedWrite = IsForcedWrite;
00208: }
00209: 
00210: //-------------------------------------------------------------------------
00211: 
00212: bool wxConfigEntry::readInternal (wxString & String)
00213: {
00214:     setReadState ();
00215:     wxASSERT(m_ConfigBase != NULL); // possibly wxConfigEntry was not initialized
00216:     return m_ConfigBase -> Read (m_EntryPath, & String);
00217: }
00218: 
00219: bool wxConfigEntry::readInternal (long & Long)
00220: {
00221:     setReadState ();
00222:     wxASSERT(m_ConfigBase != NULL); // possibly wxConfigEntry was not initialized
00223:     return m_ConfigBase -> Read (m_EntryPath, & Long);
00224: }
00225: 
00226: bool wxConfigEntry::readInternal (double & Double)
00227: {
00228:     setReadState ();
00229:     wxASSERT(m_ConfigBase != NULL); // possibly wxConfigEntry was not initialized
00230:     return m_ConfigBase -> Read (m_EntryPath, & Double);
00231: }
00232: 
00233: bool wxConfigEntry::readInternal (bool & Boolean)
00234: {
00235:     setReadState ();
00236:     wxASSERT(m_ConfigBase != NULL); // wxConfigEntry possibly not initialized
00237:     return m_ConfigBase -> Read (m_EntryPath, & Boolean);
00238: }
00239: 
00240: //-------------------------------------------------------------------------
00241: 
00242: bool wxConfigEntry::writeInternal (const wxString & String)
00243: {
00244:     if (m_IsDontWrite)
00245:       return true;
00246: 
00247:     if (getIsWriteRequired())
00248:       {
00249:         setWriteState ();
00250:         wxASSERT(m_ConfigBase != NULL); // wxConfigEntry possibly not initialized
00251:         return m_ConfigBase -> Write (m_EntryPath, String);
00252:       }
00253:     else
00254:       {
00255:         setWriteState ();
00256:         wxASSERT(m_ConfigBase != NULL); // wxConfigEntry possibly not initialized
00257:         return true;
00258:       }
00259: }
00260: 
00261: bool wxConfigEntry::writeInternal (long Long)
00262: {
00263:     if (m_IsDontWrite)
00264:       return true;
00265: 
00266:     if (getIsWriteRequired())
00267:       {
00268:         setWriteState ();
00269:         wxASSERT(m_ConfigBase != NULL); // wxConfigEntry possibly not initialized
00270:         return m_ConfigBase -> Write (m_EntryPath, Long);
00271:       }
00272:     else
00273:       {
00274:         setWriteState ();
00275:         wxASSERT(m_ConfigBase != NULL); // wxConfigEntry possibly not initialized
00276:         return true;
00277:       }
00278: }
00279: 
00280: bool wxConfigEntry::writeInternal (double Double)
00281: {
00282:     if (m_IsDontWrite)
00283:       return true;
00284: 
00285:     if (getIsWriteRequired())
00286:       {
00287:         setWriteState ();
00288:         wxASSERT(m_ConfigBase != NULL); // wxConfigEntry possibly not initialized
00289:         return m_ConfigBase -> Write (m_EntryPath, Double);
00290:       }
00291:     else
00292:       {
00293:         setWriteState ();
00294:         return true;
00295:       }
00296: }
00297: 
00298: bool wxConfigEntry::writeInternal (bool Boolean)
00299: {
00300:     if (m_IsDontWrite)
00301:       return true;
00302: 
00303:     if (getIsWriteRequired())
00304:       {
00305:         setWriteState ();
00306:         wxASSERT(m_ConfigBase != NULL); // wxConfigEntry possibly not initialized
00307:         return m_ConfigBase -> Write (m_EntryPath, Boolean);
00308:       }
00309:     else
00310:       {
00311:         setWriteState ();
00312:         return true;
00313:       }
00314: }
00315: 
00316: //-------------------------------------------------------------------------
00317: 
00318: void wxConfigEntry::setReadState ()
00319: {
00320:     m_IsAlreadyRead = true;
00321:     m_IsSetPending = FALSE;
00322:     m_IsChangePending = FALSE;
00323:     // m_LastReadTimeMS.Start ();
00324:     m_ReadMinimalTimeInterval.setBegin ();
00325: }
00326: 
00327: bool wxConfigEntry::getIsReadRequired ()
00328: {
00329:     if (m_IsSetPending)
00330:       return FALSE;
00331: 
00332:     return ((! m_IsAlreadyRead)
00333:             || ((! m_IsDontReread) 
00334:                 && /* m_LastReadTimeMS.Time() >= MinRereadIntervalMS */
00335:                    m_ReadMinimalTimeInterval.check()));
00336: }
00337: 
00338: void wxConfigEntry::setWriteState ()
00339: {
00340:     m_IsAlreadyRead = true;
00341:     m_IsSetPending = FALSE;
00342:     m_IsChangePending = FALSE;
00343: }
00344: 
00345: bool wxConfigEntry::getIsWriteRequired ()
00346: {
00347:     return ((m_IsSetPending && m_IsChangePending)
00348:             || m_IsForcedWrite);
00349: }
00350: 
00351: //=========================================================================
00352: 
00353: wxIntegerConfigEntry::wxIntegerConfigEntry()
00354: {
00355:     setRangeAndDefault (0, 0, 0);
00356:     m_CurrentValue = 0;
00357: }
00358: 
00359: void wxIntegerConfigEntry::init (const wxString & EntryPath, int MinInteger,
00360:                                 int MaxInteger, int DefaultInteger)
00361: {
00362:     setEntryPath (EntryPath);
00363:     setRangeAndDefault (MinInteger, MaxInteger, DefaultInteger);
00364:     m_CurrentValue = 0;
00365: }
00366: 
00367: void wxIntegerConfigEntry::setRangeAndDefault (int MinInteger, int MaxInteger, int DefaultInteger)
00368: {
00369:     m_MinInteger = MinInteger;
00370:     m_MaxInteger = MaxInteger;
00371:     m_DefaultInteger = DefaultInteger;
00372: }
00373: 
00374: void wxIntegerConfigEntry::get (int & Integer)
00375: {
00376:     wxString MessageString;
00377:     read (MessageString);
00378: 
00379:     Integer = m_CurrentValue;
00380: }
00381: 
00382: int wxIntegerConfigEntry::get ()
00383: {
00384:     int Integer;
00385:     get (Integer);
00386:     return Integer;
00387: }
00388: 
00389: void wxIntegerConfigEntry::get (long & Long)
00390: {
00391:     int TempInteger;
00392:     get (TempInteger);
00393:     Long = TempInteger;
00394: }
00395: 
00396: void wxIntegerConfigEntry::get (unsigned int & UInt)
00397: {
00398:     int TempInteger;
00399:     get (TempInteger);
00400:     UInt = TempInteger;
00401: }
00402: 
00403: void wxIntegerConfigEntry::get (unsigned long & ULong)
00404: {
00405:     int TempInteger;
00406:     get (TempInteger);
00407:     ULong = TempInteger;
00408: }
00409: 
00410: void wxIntegerConfigEntry::set (const int & Integer)
00411: {
00412:     m_IsSetPending = true;
00413:     if ((! m_IsChangePending) && (Integer != m_CurrentValue))
00414:       m_IsChangePending = true;
00415: 
00416:     if (! (m_MinInteger <= Integer && Integer <= m_MaxInteger))
00417:       {
00418:         // NOTE this case could be an indication of an application internal
00419:         // error
00420:         m_CurrentValue = m_DefaultInteger;
00421:       }
00422:     else
00423:       {
00424:         m_CurrentValue = Integer;
00425:       }
00426: }
00427: 
00428: //-------------------------------------------------------------------------
00429: 
00430: bool wxIntegerConfigEntry::write (wxString & WXUNUSED(MessageString))
00431: {
00432:     long TempLong = m_CurrentValue;
00433:     return writeInternal (TempLong);
00434: }
00435: 
00436: bool wxIntegerConfigEntry::read (wxString & WXUNUSED(MessageString))
00437: {
00438:     long Long = m_CurrentValue;
00439:     if (getIsReadRequired())
00440:       {
00441:         if (readInternal (Long))
00442:           {
00443:             int TempInteger = Long;
00444:             if (m_MinInteger <= TempInteger && TempInteger <= m_MaxInteger)
00445:               {
00446:                 m_CurrentValue = TempInteger;
00447:               }
00448:             else
00449:               {
00450:                 m_CurrentValue = m_DefaultInteger;
00451:               }
00452:           }
00453:         else
00454:           {
00455:             m_CurrentValue = m_DefaultInteger;
00456:             m_IsSetPending = true;
00457:             m_IsChangePending = true;
00458:           }
00459:         return true;
00460:       }
00461:     else
00462:       return FALSE;
00463: }
00464: 
00465: void wxIntegerConfigEntry::setToDefault ()
00466: {
00467:     set (m_DefaultInteger);
00468: }
00469: 
00470: //=========================================================================
00471: 
00472: wxBooleanConfigEntry::wxBooleanConfigEntry ()
00473: {
00474:     setDefault (FALSE);
00475:     m_CurrentValue = FALSE;
00476: }
00477: 
00478: void wxBooleanConfigEntry::init (const wxString & EntryPath, bool DefaultBoolean)
00479: {
00480:     setEntryPath (EntryPath);
00481:     setDefault (DefaultBoolean);
00482:     m_CurrentValue = FALSE;
00483: }
00484: 
00485: void wxBooleanConfigEntry::setDefault (bool DefaultBoolean)
00486: {
00487:     m_DefaultBoolean = DefaultBoolean;
00488: }
00489: 
00490: void wxBooleanConfigEntry::get (bool & Boolean)
00491: {
00492:     wxString MessageString;
00493:     read (MessageString);
00494: 
00495:     Boolean = m_CurrentValue;
00496: }
00497: 
00498: bool wxBooleanConfigEntry::get ()
00499: {
00500:     bool Boolean;
00501:     get (Boolean);
00502:     return Boolean;
00503: }
00504: 
00505: void wxBooleanConfigEntry::set (const bool & Boolean)
00506: {
00507:     m_IsSetPending = true;
00508:     if ((! m_IsChangePending) && (Boolean != m_CurrentValue))
00509:       m_IsChangePending = true;
00510: 
00511:     m_CurrentValue = Boolean;
00512: }
00513: 
00514: #if defined(__WXMSW__)
00515: void wxBooleanConfigEntry::get (BOOL & Boolean)
00516: {
00517:     bool TempBoolean;
00518:     get (TempBoolean);
00519:     Boolean = TempBoolean;
00520: }
00521: 
00522: void wxBooleanConfigEntry::set (const BOOL & Boolean)
00523: {
00524:     bool TempBoolean = ((Boolean) ? true : FALSE);
00525:     set (TempBoolean);
00526: }
00527: #endif
00528: 
00529: //-------------------------------------------------------------------------
00530: 
00531: bool wxBooleanConfigEntry::write (wxString & WXUNUSED(MessageString))
00532: {
00533:     return writeInternal (m_CurrentValue);
00534: }
00535: 
00536: bool wxBooleanConfigEntry::read (wxString & WXUNUSED(MessageString))
00537: {
00538:     bool TempBoolean = m_CurrentValue;
00539:     if (getIsReadRequired())
00540:       {
00541:         if (readInternal (TempBoolean))
00542:           {
00543:             m_CurrentValue = TempBoolean;
00544:           }
00545:         else
00546:           {
00547:             m_CurrentValue = m_DefaultBoolean;
00548:             m_IsSetPending = true;
00549:             m_IsChangePending = true;
00550:           }
00551:         return true;
00552:       }
00553:     else
00554:       return FALSE;
00555: }
00556: 
00557: void wxBooleanConfigEntry::setToDefault ()
00558: {
00559:     set (m_DefaultBoolean);
00560: }
00561: 
00562: //=========================================================================
00563: 
00564: wxStringConfigEntry::wxStringConfigEntry ()
00565: {
00566:     setDefault ("");
00567:     m_CurrentValue = "";
00568: }
00569: 
00570: void wxStringConfigEntry::init (const wxString & EntryPath, const wxString & DefaultString)
00571: {
00572:     setEntryPath (EntryPath);
00573:     setDefault (DefaultString);
00574:     m_CurrentValue = "";
00575: }
00576: 
00577: void wxStringConfigEntry::setDefault (const wxString & DefaultString)
00578: {
00579:     m_DefaultString = DefaultString;
00580: }
00581: 
00582: void wxStringConfigEntry::get (wxString & String)
00583: {
00584:     wxString MessageString;
00585:     read (MessageString);
00586: 
00587:     String = m_CurrentValue;
00588: }
00589: 
00590: wxString wxStringConfigEntry::get ()
00591: {
00592:     wxString String;
00593:     get (String);
00594:     return String;
00595: }
00596: 
00597: void wxStringConfigEntry::set (const wxString & String)
00598: {
00599:     m_IsSetPending = true;
00600:     if ((! m_IsChangePending) && (String != m_CurrentValue))
00601:       m_IsChangePending = true;
00602: 
00603:     m_CurrentValue = String;
00604: }
00605: 
00606: //-------------------------------------------------------------------------
00607: 
00608: bool wxStringConfigEntry::write (wxString & WXUNUSED(MessageString))
00609: {
00610:     return writeInternal (m_CurrentValue);
00611: }
00612: 
00613: bool wxStringConfigEntry::read (wxString & WXUNUSED(MessageString))
00614: {
00615:     wxString TempString = m_CurrentValue;
00616:     if (getIsReadRequired())
00617:       {
00618:         if (readInternal (TempString))
00619:           {
00620:             m_CurrentValue = TempString;
00621:           }
00622:         else
00623:           {
00624:             m_CurrentValue = m_DefaultString;
00625:             m_IsSetPending = true;
00626:             m_IsChangePending = true;
00627:           }
00628:         return true;
00629:       }
00630:     else
00631:       return FALSE;
00632: }
00633: 
00634: void wxStringConfigEntry::setToDefault ()
00635: {
00636:     set (m_DefaultString);
00637: }
00638: 
00639: //=========================================================================
00640: 
00641: wxDoubleConfigEntry::wxDoubleConfigEntry()
00642: {
00643:     setRangeAndDefault (0., 0., 0.);
00644:     m_CurrentValue = 0.;
00645: }
00646: 
00647: void wxDoubleConfigEntry::init (const wxString & EntryPath, double MinDouble,
00648:                                 double MaxDouble, double DefaultDouble)
00649: {
00650:     setEntryPath (EntryPath);
00651:     setRangeAndDefault (MinDouble, MaxDouble, DefaultDouble);
00652:     m_CurrentValue = 0.;
00653: }
00654: 
00655: void wxDoubleConfigEntry::setRangeAndDefault (double MinDouble, double MaxDouble, double DefaultDouble)
00656: {
00657:     m_MinDouble = MinDouble;
00658:     m_MaxDouble = MaxDouble;
00659:     m_DefaultDouble = DefaultDouble;
00660: }
00661: 
00662: void wxDoubleConfigEntry::get (double & Double)
00663: {
00664:     wxString MessageString;
00665:     read (MessageString);
00666: 
00667:     Double = m_CurrentValue;
00668: }
00669: 
00670: double wxDoubleConfigEntry::get ()
00671: {
00672:     double Double;
00673:     get (Double);
00674:     return Double;
00675: }
00676: 
00677: void wxDoubleConfigEntry::set (const double & Double)
00678: {
00679:     m_IsSetPending = true;
00680:     if ((! m_IsChangePending) && (Double != m_CurrentValue))
00681:       m_IsChangePending = true;
00682: 
00683:     if (! (m_MinDouble <= Double && Double <= m_MaxDouble))
00684:       {
00685:         // NOTE this case could be an indication of an application internal
00686:         // error
00687:         m_CurrentValue = m_DefaultDouble;
00688:       }
00689:     else
00690:       {
00691:         m_CurrentValue = Double;
00692:       }
00693: }
00694: 
00695: //-------------------------------------------------------------------------
00696: 
00697: bool wxDoubleConfigEntry::write (wxString & WXUNUSED(MessageString))
00698: {
00699:     double TempDouble = m_CurrentValue;
00700:     return writeInternal (TempDouble);
00701: }
00702: 
00703: bool wxDoubleConfigEntry::read (wxString & WXUNUSED(MessageString))
00704: {
00705:     double Double = m_CurrentValue;
00706:     if (getIsReadRequired())
00707:       {
00708:         if (readInternal (Double))
00709:           {
00710:             double TempDouble = Double;
00711:             if (m_MinDouble <= TempDouble && TempDouble <= m_MaxDouble)
00712:               {
00713:                 m_CurrentValue = TempDouble;
00714:               }
00715:             else
00716:               {
00717:                 m_CurrentValue = m_DefaultDouble;
00718:               }
00719:           }
00720:         else
00721:           {
00722:             m_CurrentValue = m_DefaultDouble;
00723:             m_IsSetPending = true;
00724:             m_IsChangePending = true;
00725:           }
00726:         return true;
00727:       }
00728:     else
00729:       return FALSE;
00730: }
00731: 
00732: void wxDoubleConfigEntry::setToDefault ()
00733: {
00734:     set (m_DefaultDouble);
00735: }
00736: 
00737: //=========================================================================
00738: 
00739: wxDateTimeConfigEntry::wxDateTimeConfigEntry()
00740: {
00741:     // setRangeAndDefault (0, 0, 0);
00742:     // m_CurrentValue = 0;
00743: }
00744: 
00745: void wxDateTimeConfigEntry::init (const wxString & EntryPath, 
00746:                                   const wxDateTime & MinDateTime,
00747:                                   const wxDateTime & MaxDateTime,
00748:                                   const wxDateTime & DefaultDateTime)
00749: {
00750:     setEntryPath (EntryPath);
00751:     setRangeAndDefault (MinDateTime, MaxDateTime, DefaultDateTime);
00752:     m_CurrentValue = wxDateTime ();
00753: }
00754: 
00755: void wxDateTimeConfigEntry::setRangeAndDefault (const wxDateTime & MinDateTime, 
00756:                                                 const wxDateTime & MaxDateTime, 
00757:                                                 const wxDateTime & DefaultDateTime)
00758: {
00759:     m_MinDateTime = MinDateTime;
00760:     m_MaxDateTime = MaxDateTime;
00761:     m_DefaultDateTime = DefaultDateTime;
00762: }
00763: 
00764: void wxDateTimeConfigEntry::get (wxDateTime & DateTime)
00765: {
00766:     wxString MessageString;
00767:     read (MessageString);
00768: 
00769:     DateTime = m_CurrentValue;
00770: }
00771: 
00772: wxDateTime wxDateTimeConfigEntry::get ()
00773: {
00774:     wxDateTime DateTime;
00775:     get (DateTime);
00776:     return DateTime;
00777: }
00778: 
00779: void wxDateTimeConfigEntry::set (const wxDateTime & DateTime)
00780: {
00781:     m_IsSetPending = true;
00782:     // (!m_CurrentValue.IsValid())
00783:     if ((! m_IsChangePending) && (DateTime != m_CurrentValue))
00784:       {
00785:         m_IsChangePending = true;
00786:       }
00787: 
00788:     // if (!((!m_MinDateTime.IsValid()) || (m_MinDateTime <= DateTime) 
00789:     // && ((!m_MaxDateTime.IsValid()) || (DateTime <= m_MaxDateTime))))
00790:     if (0)
00791:       {
00792:         wxASSERT (0);
00793:         // NOTE this case could be an indication of an application internal
00794:         // error
00795:         m_CurrentValue = m_DefaultDateTime;
00796:       }
00797:     else
00798:       {
00799:         m_CurrentValue = DateTime;
00800:       }
00801: }
00802: 
00803: //-------------------------------------------------------------------------
00804: 
00805: bool wxDateTimeConfigEntry::write (wxString & WXUNUSED(MessageString))
00806: {
00807:     wxString DateTimeString;
00808:     if (m_CurrentValue.IsValid())
00809:       DateTimeString = m_CurrentValue.FormatISODate() << " " << m_CurrentValue.FormatISOTime();
00810: 
00811:     return writeInternal (DateTimeString);
00812: }
00813: 
00814: bool wxDateTimeConfigEntry::read (wxString & WXUNUSED(MessageString))
00815: {
00816:     wxDateTime TempDateTime;
00817:     if (getIsReadRequired())
00818:       {
00819:         if (readDateTime (TempDateTime)
00820:             && TempDateTime.IsValid())
00821:           {
00822:             if (((!m_MinDateTime.IsValid()) || (m_MinDateTime <= TempDateTime))
00823:                 && ((!m_MaxDateTime.IsValid()) || (TempDateTime <= m_MaxDateTime)))
00824:               {
00825:                 m_CurrentValue = TempDateTime;
00826:               }
00827:             else
00828:               {
00829:                 m_CurrentValue = m_DefaultDateTime;
00830:               }
00831:           }
00832:         else
00833:           {
00834:             m_CurrentValue = m_DefaultDateTime;
00835:             m_IsSetPending = true;
00836:             m_IsChangePending = true;
00837:           }
00838:         return true;
00839:       }
00840:     else
00841:       return FALSE;
00842: }
00843: 
00844: bool wxDateTimeConfigEntry::readDateTime(wxDateTime & DateTime)
00845: {
00846:     wxString ISODateTimeFormatString = "%Y-%m-%d %H:%M:%S";
00847: 
00848:     wxDateTime TempDateTime;
00849:     wxString TempDateTimeString;
00850: 
00851:     if (!readInternal (TempDateTimeString))
00852:       return false;
00853: 
00854:     // TODO handling of parse results could be improved, this should be put into
00855:     // a new parseDateTime() function (similar to existing parseDate())
00856:     // TODO add support for date-only and time-only entries
00857:     // TODO use more strict function parseDateTimeWithFormat()
00858:     if (TempDateTime.ParseFormat (TempDateTimeString, ISODateTimeFormatString) != NULL)
00859:       {
00860:         DateTime = TempDateTime;
00861:         return true;
00862:       }
00863:     else
00864:       {
00865:         return false;
00866:       }
00867: }
00868: 
00869: void wxDateTimeConfigEntry::setToDefault ()
00870: {
00871:     set (m_DefaultDateTime);
00872: }
00873: 
00874: //=========================================================================
00875:  
00876: 
  [main]    [up]  
DaicasWeb v.1.50.0102  //   Daniel Käps  //   April 12, 2007  //   Impressum / Imprint 
http://www.daicas.net/WxExtLib/src/ConfigEntry.cpp.html