MatOCAD Logo

Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

TxtValue.cpp

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 //
00003 // Name:        TxtValue.cpp
00004 // Author:      Silvestro Jacopo
00005 //
00006 //------------------------------------------------------------------------------
00007 
00008 #include "../../include/TxtValore/TxtValue.h"
00009 IMPLEMENT_CLASS(TxtValue,wxTextCtrl)
00010 
00011 //------------------------------------------------------------------------------
00012 //
00013 //                             EVENT TABLE
00014 //
00015 //------------------------------------------------------------------------------
00016 
00017 
00018 BEGIN_EVENT_TABLE(TxtValue,wxTextCtrl)
00019 EVT_KILL_FOCUS(TxtValue::OnKillFocus)
00020 EVT_KEY_DOWN(TxtValue::OnKeyDown)
00021 
00022 END_EVENT_TABLE()
00023 
00024 //------------------------------------------------------------------------------
00025 //
00026 //           TxtValue METHODS IMPLEMENTATION
00027 //
00028 //------------------------------------------------------------------------------
00029 
00030 
00031 TxtValue::TxtValue (wxWindow* parent,
00032                           wxWindowID id,
00033                           const wxString& value,
00034                           const wxPoint& pos,
00035                           const wxSize& size,
00036                           long style,
00037                           const wxValidator& validator,
00038                           const wxString& name)
00039 
00040                           :  wxTextCtrl(parent,id,value,pos,size,style,validator,name)
00041 {
00042 
00043 old_value=value;
00044 }
00045 //------------------------------------------------------------------------------
00046 //
00047 //          EVENTI HANDLED BY TxtValue
00048 //
00049 //------------------------------------------------------------------------------
00050 
00051 
00052 //______________________________________________________________________________
00053 void TxtValue::OnKillFocus(wxFocusEvent& event)
00054 {
00055 
00056   if(old_value.Cmp(GetValue()))
00057   {
00058    old_value=GetValue();
00059      if(Isnumeric(old_value.ToAscii())&&(!old_value.IsEmpty()))
00060      {
00061      //segnalo cambiamento
00062      ValueChangedEvent cevent(EVT_VALUE_CHANGED);
00063      cevent.SetEventObject( this );
00064      cevent.valid=true;
00065      cevent.value=atof(old_value.ToAscii());
00066     // Send it
00067      if (GetParent())
00068        GetParent()->ProcessEvent(cevent);
00069 
00070      }
00071      else
00072      {
00073        //Segnalo Annulla
00074      ValueChangedEvent cevent(EVT_VALUE_CHANGED);
00075      cevent.SetEventObject( this );
00076      cevent.valid=false;
00077      cevent.value=0;
00078     // Send it
00079      if (GetParent())
00080      GetParent()->ProcessEvent(cevent);
00081      }
00082   }
00083      event.Skip();
00084 }
00085 //______________________________________________________________________________
00086 void TxtValue::OnKeyDown(wxKeyEvent& event)
00087 {
00088  if((event.GetKeyCode()==WXK_RETURN)||(event.GetKeyCode()==WXK_NUMPAD_ENTER))
00089  {
00090        if(old_value.Cmp(GetValue()))
00091   {
00092    old_value=GetValue();
00093      if(Isnumeric(old_value.ToAscii())&&(!old_value.IsEmpty()))
00094      {
00095      //segnalo cambiamento
00096      ValueChangedEvent cevent(EVT_VALUE_CHANGED);
00097      cevent.SetEventObject( this );
00098      cevent.valid=true;
00099      cevent.value=atof(old_value.ToAscii());
00100     // Send it
00101      if (GetParent())
00102        GetParent()->ProcessEvent(cevent);
00103 
00104      }
00105      else
00106      {
00107        //Segnalo Annulla
00108      ValueChangedEvent cevent(EVT_VALUE_CHANGED);
00109      cevent.SetEventObject( this );
00110      cevent.valid=false;
00111      cevent.value=0;
00112     // Send it
00113      if (GetParent())
00114      GetParent()->ProcessEvent(cevent);
00115      }
00116   }
00117  }
00118      event.Skip();
00119 
00120 }
00121 
00122 //______________________________________________________________________________
00123 
00124 //------------------------------------------------------------------------------
00125 //
00126 //                              END OF FILE
00127 //
00128 //------------------------------------------------------------------------------
00129 
00130 
00131 

 

SourceForge Logo