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