00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013 #ifdef __GNUG__
00014 #pragma implementation "CRSliderUpdateEvent.h"
00015 #endif
00016
00017 #include "CRSliderUpdateEvent.h"
00018
00019 #include <wxGuiTest/CRWindowHierarchyHandler.h>
00020 #include <wxGuiTest/CRCppEmitter.h>
00021
00022 using namespace wxTst;
00023
00024
00025 CRSliderUpdateEvent::CRSliderUpdateEvent (wxEvent *event) :
00026 CRCapturedEvent (event)
00027 {
00028
00029 }
00030
00031
00032 CRSliderUpdateEvent::~CRSliderUpdateEvent ()
00033 {
00034
00035 }
00036
00037
00038 bool CRSliderUpdateEvent::IsPending () const
00039 {
00040 return true;
00041 }
00042
00043
00044 void CRSliderUpdateEvent::Process (CRCapturedEvent **pendingEvt)
00045 {
00046
00047
00048 if (*pendingEvt != NULL) {
00049
00050 CRSliderUpdateEvent *pendingSliderUpdateEvt =
00051 dynamic_cast< CRSliderUpdateEvent * >(*pendingEvt);
00052 if (pendingSliderUpdateEvt != NULL) {
00053
00054 if (m_event->GetEventObject () ==
00055 pendingSliderUpdateEvt->GetEvent ()->GetEventObject ()) {
00056
00057 delete *pendingEvt;
00058 *pendingEvt = NULL;
00059 }
00060 }
00061 }
00062
00063 wxWindow *wdwEvtObject = wxDynamicCast (m_event->GetEventObject (), wxWindow);
00064 wxASSERT (wdwEvtObject != NULL);
00065
00066 CRWindowHierarchyHandler *hierarchy = CRWindowHierarchyHandler::GetInstance();
00067 wxASSERT (hierarchy != NULL);
00068 m_sliderName = wdwEvtObject->GetName ();
00069 m_containerName = hierarchy->FindContainerName (wdwEvtObject);
00070 wxASSERT (!m_containerName.IsEmpty ());
00071
00072 wxASSERT (m_event->IsCommandEvent ());
00073 wxCommandEvent *cmdEvt = wxDynamicCast (m_event, wxCommandEvent);
00074 wxASSERT (cmdEvt != NULL);
00075 m_sliderValue = cmdEvt->GetInt ();
00076 }
00077
00078
00079 void CRSliderUpdateEvent::EmitCpp ()
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("slider '%s'"),
00107 m_sliderName.c_str ()));
00108
00109 wxString sliderWdwVarName = emitter->MakeVarName (m_sliderName, _T("Wdw"));
00110
00111 wxString str;
00112 str << _T("wxWindow *") << sliderWdwVarName << _T(" = ") <<
00113 containerVarName << _T("->FindWindow (");
00114 str << _T("_T(\"") << m_sliderName << _T("\"));");
00115 emitter->AddCode (str);
00116
00117 str.Clear ();
00118 str << _T("CPPUNIT_ASSERT_MESSAGE (\"Window for slider '") <<
00119 m_sliderName << _T("' not found\", ") << sliderWdwVarName <<
00120 _T(" != NULL);");
00121 emitter->AddCode (str);
00122
00123 wxString sliderVarName = emitter->MakeVarName (m_sliderName);
00124
00125 str.Clear ();
00126 str << _T("wxSlider *") << sliderVarName << _T(" = wxDynamicCast (") <<
00127 sliderWdwVarName << _T(", wxSlider);");
00128 emitter->AddCode (str);
00129
00130 str.Clear ();
00131 str << _T("CPPUNIT_ASSERT_MESSAGE (\"Converting window for slider '") <<
00132 m_sliderName << _T("' failed\", ") << sliderVarName << _T(" != NULL);");
00133 emitter->AddCode (str);
00134
00135 str.Clear ();
00136 str << _T("wxTst::EventSimulationHelper::SetSliderValue (") <<
00137 sliderVarName << _T(", ") << m_sliderValue << _T(");");
00138 emitter->AddCode (str);
00139
00140 str.Clear ();
00141 str << _T("wxTst::WxGuiTestHelper::FlushEventQueue ();\n");
00142 emitter->AddCode (str);
00143 }