00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013 #ifdef __GNUG__
00014 #pragma implementation "CRSpinCtrlUpdateEvent.h"
00015 #endif
00016
00017 #include "CRSpinCtrlUpdateEvent.h"
00018
00019 #include <wx/spinctrl.h>
00020
00021 #include <wxGuiTest/CRWindowHierarchyHandler.h>
00022 #include <wxGuiTest/CRCppEmitter.h>
00023 #include "CRTextUpdateEvent.h"
00024
00025
00026 using namespace wxTst;
00027
00028
00029 CRSpinCtrlUpdateEvent::CRSpinCtrlUpdateEvent (wxEvent *event) :
00030 CRCapturedEvent (event)
00031 {
00032
00033 }
00034
00035
00036 CRSpinCtrlUpdateEvent::~CRSpinCtrlUpdateEvent ()
00037 {
00038
00039 }
00040
00041
00042 void CRSpinCtrlUpdateEvent::Process (CRCapturedEvent **pendingEvt)
00043 {
00044 wxWindow *wdwEvtObject = wxDynamicCast (m_event->GetEventObject (), wxWindow);
00045 wxASSERT (wdwEvtObject != NULL);
00046
00047
00048
00049 if (*pendingEvt != NULL) {
00050
00051 CRTextUpdateEvent *pendingTextUpdateEvt =
00052 dynamic_cast< CRTextUpdateEvent * >(*pendingEvt);
00053 if (pendingTextUpdateEvt != NULL) {
00054 if (m_event->GetEventObject () ==
00055 pendingTextUpdateEvt->GetEvent ()->GetEventObject ()) {
00056
00057 delete *pendingEvt;
00058 *pendingEvt = NULL;
00059 }
00060 }
00061 }
00062
00063 CRWindowHierarchyHandler *hierarchy = CRWindowHierarchyHandler::GetInstance ();
00064 wxASSERT (hierarchy != NULL);
00065
00066 m_spinCtrlName = wdwEvtObject->GetName ();
00067 m_containerName = hierarchy->FindContainerName (wdwEvtObject);
00068 wxASSERT (!m_containerName.IsEmpty ());
00069
00070 wxASSERT (m_event->IsCommandEvent ());
00071 wxCommandEvent *cmdEvt = wxDynamicCast (m_event, wxCommandEvent);
00072 wxASSERT (cmdEvt != NULL);
00073 m_spinCtrlValue = cmdEvt->GetInt ();
00074 }
00075
00076
00077 void CRSpinCtrlUpdateEvent::EmitCpp ()
00078 {
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 CRCppEmitter *emitter = CRCppEmitter::GetInstance ();
00104
00105 wxString containerVarName = emitter->AddContainerLookupCode (
00106 m_containerName, wxString::Format (_T("spin control '%s'"),
00107 m_spinCtrlName.c_str ()));
00108
00109 wxString spinCtrlWdwVarName = emitter->MakeVarName(m_spinCtrlName, _T("Wdw"));
00110
00111 wxString str;
00112 str << _T("wxWindow *") << spinCtrlWdwVarName << _T(" = ") <<
00113 containerVarName << _T("->FindWindow (");
00114 str << _T("_T(\"") << m_spinCtrlName << _T("\"));");
00115 emitter->AddCode (str);
00116
00117 str.Clear ();
00118 str << _T("CPPUNIT_ASSERT_MESSAGE (\"Window for spin control '") <<
00119 m_spinCtrlName << _T("' not found\", ") << spinCtrlWdwVarName <<
00120 _T(" != NULL);");
00121 emitter->AddCode (str);
00122
00123 wxString spinCtrlVarName = emitter->MakeVarName (m_spinCtrlName);
00124
00125 str.Clear ();
00126 str << _T("wxSpinCtrl *") << spinCtrlVarName <<
00127 _T(" = wxDynamicCast (") << spinCtrlWdwVarName <<
00128 _T(", wxSpinCtrl);");
00129 emitter->AddCode (str);
00130
00131 str.Clear ();
00132 str << _T("CPPUNIT_ASSERT_MESSAGE (\"Converting window for spin control '") <<
00133 m_spinCtrlName << _T("' failed\", ") << spinCtrlVarName <<
00134 _T(" != NULL);");
00135 emitter->AddCode (str);
00136
00137 str.Clear ();
00138 str << _T("wxTst::EventSimulationHelper::SetSpinCtrlValue (") <<
00139 spinCtrlVarName << _T(", ") << m_spinCtrlValue << _T(");");
00140 emitter->AddCode (str);
00141
00142 str.Clear ();
00143 str << _T("wxTst::WxGuiTestHelper::FlushEventQueue ();\n");
00144 emitter->AddCode (str);
00145 }
00146
00147