00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013 #ifdef __GNUG__
00014 #pragma implementation "CRTextUpdateEvent.h"
00015 #endif
00016
00017 #include "CRTextUpdateEvent.h"
00018
00019 #include <wx/spinctrl.h>
00020
00021 #include <wxGuiTest/CRWindowHierarchyHandler.h>
00022 #include <wxGuiTest/CRCppEmitter.h>
00023 #include <wxGuiTest/EventSimulationHelper.h>
00024
00025
00026 using namespace wxTst;
00027
00028
00029 CRTextUpdateEvent::CRTextUpdateEvent (wxEvent *event) :
00030 CRCapturedEvent (event), m_isIrrelevant(false)
00031 {
00032
00033 }
00034
00035
00036 CRTextUpdateEvent::~CRTextUpdateEvent ()
00037 {
00038
00039 }
00040
00041
00042 bool CRTextUpdateEvent::IsPending () const
00043 {
00044 return true;
00045 }
00046
00047
00048 bool CRTextUpdateEvent::IsIrrelevant () const
00049 {
00050 return m_isIrrelevant;
00051 }
00052
00053
00054 void CRTextUpdateEvent::Process (CRCapturedEvent **pendingEvt)
00055 {
00056 wxWindow *wdwEvtObject = wxDynamicCast (m_event->GetEventObject (), wxWindow);
00057 wxASSERT (wdwEvtObject != NULL);
00058
00059
00060 if (wdwEvtObject->GetParent () != NULL
00061 && wdwEvtObject->IsKindOf (CLASSINFO(wxSpinCtrl))) {
00062
00063 if (!EventSimulationHelper::IsSettingSpinCtrlValue ()) {
00064
00065 m_isIrrelevant = true;
00066
00067
00068
00069 wxSpinCtrl *spinCtrl = wxDynamicCast (wdwEvtObject, wxSpinCtrl);
00070 wxASSERT (spinCtrl != NULL);
00071 EventSimulationHelper::SetSpinCtrlValue(spinCtrl,
00072 spinCtrl->GetValue());
00073 }
00074 return;
00075 }
00076
00077
00078
00079
00080 if (*pendingEvt != NULL) {
00081
00082 CRTextUpdateEvent *pendingTextUpdateEvt =
00083 dynamic_cast< CRTextUpdateEvent * >(*pendingEvt);
00084 if (pendingTextUpdateEvt != NULL) {
00085
00086 if (m_event->GetEventObject () ==
00087 pendingTextUpdateEvt->GetEvent ()->GetEventObject ()) {
00088
00089 delete *pendingEvt;
00090 *pendingEvt = NULL;
00091 }
00092 }
00093 }
00094
00095 CRWindowHierarchyHandler *hierarchy = CRWindowHierarchyHandler::GetInstance ();
00096 wxASSERT (hierarchy != NULL);
00097
00098 m_textCtrlName = wdwEvtObject->GetName ();
00099 m_containerName = hierarchy->FindContainerName (wdwEvtObject);
00100 wxASSERT (!m_containerName.IsEmpty ());
00101
00102 wxASSERT (m_event->IsCommandEvent ());
00103 wxCommandEvent *cmdEvt = wxDynamicCast (m_event, wxCommandEvent);
00104 wxASSERT (cmdEvt != NULL);
00105 m_textCtrlValue = cmdEvt->GetString ();
00106 }
00107
00108
00109 void CRTextUpdateEvent::EmitCpp ()
00110 {
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 CRCppEmitter *emitter = CRCppEmitter::GetInstance ();
00135
00136 wxString containerVarName = emitter->AddContainerLookupCode (
00137 m_containerName, wxString::Format (_T("text control '%s'"),
00138 m_textCtrlName.c_str ()));
00139
00140 wxString textCtrlWdwVarName = emitter->MakeVarName (m_textCtrlName,
00141 _T("Wdw"));
00142
00143 wxString str;
00144 str << _T("wxWindow *") << textCtrlWdwVarName << _T(" = ") <<
00145 containerVarName << _T("->FindWindow (");
00146 str << _T("_T(\"") << m_textCtrlName << _T("\"));");
00147 emitter->AddCode (str);
00148
00149 str.Clear ();
00150 str << _T("CPPUNIT_ASSERT_MESSAGE (\"Window for text control '") <<
00151 m_textCtrlName << _T("' not found\", ") << textCtrlWdwVarName <<
00152 _T(" != NULL);");
00153 emitter->AddCode (str);
00154
00155 wxString textCtrlVarName = emitter->MakeVarName (m_textCtrlName);
00156
00157 str.Clear ();
00158 str << _T("wxTextCtrl *") << textCtrlVarName << _T(" = wxDynamicCast (")
00159 << textCtrlWdwVarName << _T(", wxTextCtrl);");
00160 emitter->AddCode (str);
00161
00162 str.Clear ();
00163 str << _T("CPPUNIT_ASSERT_MESSAGE (\"Converting window for text control '")
00164 << m_textCtrlName << _T("' failed\", ") << textCtrlVarName
00165 << _T(" != NULL);");
00166 emitter->AddCode (str);
00167
00168 str.Clear ();
00169 str << _T("wxTst::EventSimulationHelper::SetTextCtrlValue (")
00170 << textCtrlVarName << _T(", _T(\"") << this->GetEscaped (m_textCtrlValue)
00171 << _T("\"));");
00172 emitter->AddCode (str);
00173
00174 str.Clear ();
00175 str << _T("wxTst::WxGuiTestHelper::FlushEventQueue ();\n");
00176 emitter->AddCode (str);
00177 }
00178
00179
00180 wxString CRTextUpdateEvent::GetEscaped (const wxString &str) const
00181 {
00182 wxString escaped;
00183
00184 for (size_t i = 0; i < str.Length (); i++) {
00185
00186 if (str[i] == 92) {
00187
00188 escaped.Append (_T("\\\\"));
00189
00190 } else {
00191
00192 escaped.Append (str[i]);
00193 }
00194 }
00195
00196 return escaped;
00197 }