[main]    [up]  

WxExtLib - TextCtrlSliderPairValidators.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: #if defined(__GNUG__) && (!defined(__APPLE__)) && (!(defined M_NoPragmaInterface))
00044: #   pragma implementation "TextCtrlSliderPairValidators.h"
00045: #endif
00046: 
00047: #include "WxExtLibConfig.h"
00048: 
00049: // For compilers that support precompilation, includes "wx.h".
00050: #include <wx/wxprec.h>
00051: 
00052: #ifdef __BORLANDC__
00053:     #pragma hdrstop
00054: #endif
00055: 
00056: #ifndef WX_PRECOMP
00057:     #include "wx/dialog.h"
00058: #endif
00059: 
00060: #include "TextCtrlSliderPairValidators.h"
00061: 
00062: #include "WxExtDialog.h"
00063: 
00064: #endif // _NO_HEADER_INCLUDE
00065: 
00066: //-------------------------------------------------------------------------
00067: 
00068: IMPLEMENT_DYNAMIC_CLASS(wxTextCtrlSliderPairTextCtrlValidator, wxNumberValidator)
00069: 
00070: BEGIN_EVENT_TABLE(wxTextCtrlSliderPairTextCtrlValidator, wxNumberValidator)
00071: END_EVENT_TABLE()
00072: 
00073: //-------------------------------------------------------------------------
00074: 
00075: wxTextCtrlSliderPairTextCtrlValidator::wxTextCtrlSliderPairTextCtrlValidator()
00076: {
00077:     m_AssociatedSliderValidator = NULL;
00078: }
00079: 
00080: wxTextCtrlSliderPairTextCtrlValidator::wxTextCtrlSliderPairTextCtrlValidator
00081:         (
00082:          long * LongValue, long MinLong, long MaxLong,
00083:          wxStatusMessageTarget * StatusMessageTarget,
00084:          const wxString & FieldNameString
00085:          )
00086:           : wxNumberValidator (LongValue, MinLong, MaxLong, StatusMessageTarget,
00087:                                FieldNameString)
00088: {
00089:     m_AssociatedSliderValidator = NULL;
00090: }
00091: 
00092: wxTextCtrlSliderPairTextCtrlValidator::wxTextCtrlSliderPairTextCtrlValidator(const wxTextCtrlSliderPairTextCtrlValidator& TextCtrlSliderPairTextCtrlValidator)
00093:     : wxNumberValidator()
00094: {
00095:     Copy(TextCtrlSliderPairTextCtrlValidator);
00096: }
00097: 
00098: bool wxTextCtrlSliderPairTextCtrlValidator::Copy(const wxTextCtrlSliderPairTextCtrlValidator& TextCtrlSliderPairTextCtrlValidator)
00099: {
00100:     wxNumberValidator::Copy(TextCtrlSliderPairTextCtrlValidator);
00101: 
00102:     m_AssociatedSliderValidator = TextCtrlSliderPairTextCtrlValidator.m_AssociatedSliderValidator;
00103: 
00104:     return true;
00105: }
00106: 
00107: wxTextCtrlSliderPairTextCtrlValidator::~wxTextCtrlSliderPairTextCtrlValidator()
00108: {
00109:     if (m_AssociatedSliderValidator)
00110:       {
00111:         m_AssociatedSliderValidator -> setAssociatedTextCtrlValidator (NULL);
00112:       }
00113:     m_AssociatedSliderValidator = NULL;
00114: }
00115: 
00116: //-------------------------------------------------------------------------
00117: 
00118: void wxTextCtrlSliderPairTextCtrlValidator::setAssociatedSliderValidator (
00119:     wxTextCtrlSliderPairSliderValidator * AssociatedSliderValidator)
00120: {
00121:     m_AssociatedSliderValidator = AssociatedSliderValidator;
00122: }
00123: 
00124: //-------------------------------------------------------------------------
00125: 
00126: // called to transfer data to the window
00127: bool wxTextCtrlSliderPairTextCtrlValidator::TransferToWindow(void)
00128: {
00129:     wxNumberValidator::TransferToWindow ();
00130: 
00131: #if (defined(__WXMSW__) || defined(__WXGTK__))
00132:     // under WXMSW and WXGTK, a text control change message is generated
00133:     // when setting the wxTextCtrl which in turn causes informTextCtrlChange()
00134:     // to be called. This doesn't happen under some other ports (WXMOTIF,
00135:     // WXX11):
00136: #elif (defined(__WXMOTIF__) || defined(__WXX11__))
00137:     if (m_LongValue != NULL
00138:         && m_AssociatedSliderValidator != NULL)
00139:       {
00140:         m_AssociatedSliderValidator -> informTextCtrlChange (* m_LongValue);
00141:       }
00142: #else
00143: #   pragma message ("Please adjust function wxTextCtrlSliderPairTextCtrlValidator::TransferToWindow() for your wxWindows port.")
00144: #endif
00145:     return true;
00146: }
00147: 
00148: void wxTextCtrlSliderPairTextCtrlValidator::handleValidInput ()
00149: {
00150:     if (m_AssociatedSliderValidator)
00151:       {
00152:         long TempLong = m_LongBasictypeValidatorTrait.m_LastValidationBasicType;
00153:         m_AssociatedSliderValidator -> informTextCtrlChange (TempLong);
00154:       }
00155: }
00156: 
00157: //-------------------------------------------------------------------------
00158: 
00159: void wxTextCtrlSliderPairTextCtrlValidator::informSliderChange (long TempLong)
00160: {    
00161:     wxString TextCtrlContentString;
00162:     // wxNumberValidatorVariant TempVariant;
00163:     // TempVariant.setLong (TempLong);
00164:     // transferToWindowHelper (TempVariant, TextCtrlContentString);
00165:     m_LongBasictypeValidatorTrait.convertBasictypeToString (TempLong, TextCtrlContentString);
00166:     setTextCtrlContent (TextCtrlContentString);
00167: }
00168: 
00169: //=========================================================================
00170: 
00171: IMPLEMENT_DYNAMIC_CLASS(wxTextCtrlSliderPairSliderValidator, wxValidator)
00172: 
00173: BEGIN_EVENT_TABLE(wxTextCtrlSliderPairSliderValidator, wxValidator)
00174:     EVT_SCROLL (wxTextCtrlSliderPairSliderValidator::OnScrollEvent)
00175: END_EVENT_TABLE()
00176: 
00177: //-------------------------------------------------------------------------
00178: 
00179: wxTextCtrlSliderPairSliderValidator::wxTextCtrlSliderPairSliderValidator()
00180: {
00181:     m_AssociatedTextCtrlValidator = NULL;
00182: 
00183:     m_IsLastSliderPositionValid = FALSE;
00184:     m_LastSliderPositionLong = 0;
00185: }
00186: 
00187: wxTextCtrlSliderPairSliderValidator::wxTextCtrlSliderPairSliderValidator(const wxTextCtrlSliderPairSliderValidator& TextCtrlSliderPairSliderValidator)
00188:     : wxValidator()
00189: {
00190:     Copy(TextCtrlSliderPairSliderValidator);
00191: }
00192: 
00193: bool wxTextCtrlSliderPairSliderValidator::Copy(const wxTextCtrlSliderPairSliderValidator& TextCtrlSliderPairSliderValidator)
00194: {
00195:     wxValidator::Copy(TextCtrlSliderPairSliderValidator);
00196: 
00197:     m_AssociatedTextCtrlValidator = TextCtrlSliderPairSliderValidator.m_AssociatedTextCtrlValidator;
00198:     m_IsLastSliderPositionValid = TextCtrlSliderPairSliderValidator.m_IsLastSliderPositionValid;
00199:     m_LastSliderPositionLong = TextCtrlSliderPairSliderValidator.m_LastSliderPositionLong;
00200: 
00201:     return true;
00202: }
00203: 
00204: wxTextCtrlSliderPairSliderValidator::~wxTextCtrlSliderPairSliderValidator()
00205: {
00206:     if (m_AssociatedTextCtrlValidator)
00207:       {
00208:         m_AssociatedTextCtrlValidator -> setAssociatedSliderValidator (NULL);
00209:       }
00210:     m_AssociatedTextCtrlValidator = NULL;
00211: }
00212: 
00213: //-------------------------------------------------------------------------
00214: 
00215: void wxTextCtrlSliderPairSliderValidator::setAssociatedTextCtrlValidator (
00216:     wxTextCtrlSliderPairTextCtrlValidator * AssociatedTextCtrlValidator)
00217: {
00218:     m_AssociatedTextCtrlValidator = AssociatedTextCtrlValidator;
00219: }
00220: 
00221: //-------------------------------------------------------------------------
00222: 
00223: bool wxTextCtrlSliderPairSliderValidator::Validate(wxWindow * WXUNUSED(Parent))
00224: {
00225:     // validity check of associated wxTextCtrl is assumed to be done
00226:     // by wxTextCtrlSliderPairTextCtrlValidator
00227:     return true;
00228: }
00229: 
00230: bool wxTextCtrlSliderPairSliderValidator::TransferToWindow(void)
00231: {
00232:     // Currently, setting any value to the wxTextCtrl causes a 
00233:     // wxTextCtrl content change event to be generated. This will,
00234:     // in turn,  call our informTextCtrlChange() function, which
00235:     // will set the slider position. 
00236:     // So to avoid setting the slider position twice, we do nothing
00237:     // here.
00238:     return true;
00239: }
00240: 
00241: bool wxTextCtrlSliderPairSliderValidator::TransferFromWindow(void)
00242: {
00243:     // transfer of data into the variable is assumed to be done by
00244:     // wxTextCtrlSliderPairTextCtrlValidator, so to avoid setting the
00245:     // variable twice, we do nothing here
00246:     return true;
00247: }
00248: 
00249: //-------------------------------------------------------------------------
00250: 
00251: // void wxTextCtrlSliderPairSliderValidator::OnScrollEvent(wxCommandEvent& Event)
00252: void wxTextCtrlSliderPairSliderValidator::OnScrollEvent(wxScrollEvent & Event)
00253: {
00254:     Event.Skip();
00255: 
00256:     long CurrentSliderPositionLong;
00257:     wxSlider * Slider = (wxSlider *) m_validatorWindow ;
00258:     CurrentSliderPositionLong = Slider -> GetValue ();
00259: 
00260:     if (m_AssociatedTextCtrlValidator)
00261:       {
00262:         if (CurrentSliderPositionLong != m_LastSliderPositionLong)
00263:           {
00264:             m_AssociatedTextCtrlValidator -> informSliderChange (CurrentSliderPositionLong);
00265:             m_IsLastSliderPositionValid = true;
00266:             m_LastSliderPositionLong = CurrentSliderPositionLong;
00267:           }
00268:       }
00269: }
00270: 
00271: //-------------------------------------------------------------------------
00272: 
00273: void wxTextCtrlSliderPairSliderValidator::informTextCtrlChange (long TempLong)
00274: {
00275:     if (m_validatorWindow)
00276:       {
00277:         wxSlider * Slider = (wxSlider *) m_validatorWindow ;
00278:         Slider -> SetValue (TempLong);
00279:       }
00280: }
00281: 
00282: //-------------------------------------------------------------------------
00283: 
00284: 
00285: 
  [main]    [up]  
DaicasWeb v.1.50.0102  //   Daniel Käps  //   April 12, 2007  //   Impressum / Imprint 
http://www.daicas.net/WxExtLib/src/TextCtrlSliderPairValidators.cpp.html