00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013 #ifdef __GNUG__
00014 #pragma implementation "CRTreeItemRightClickEvent.h"
00015 #endif
00016
00017 #include "CRTreeItemRightClickEvent.h"
00018
00019 #include <wxGuiTest/CRWindowHierarchyHandler.h>
00020 #include <wxGuiTest/CRCppEmitter.h>
00021
00022 using namespace wxTst;
00023
00024
00025 CRTreeItemRightClickEvent::CRTreeItemRightClickEvent (wxEvent *event) :
00026 CRAbstractTreeEvent (event)
00027 {
00028
00029 }
00030
00031
00032 CRTreeItemRightClickEvent::~CRTreeItemRightClickEvent ()
00033 {
00034
00035 }
00036
00037
00038 void CRTreeItemRightClickEvent::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 m_treeCtrlName = wdwEvtObject->GetName ();
00046 m_containerName = hierarchy->FindContainerName (wdwEvtObject);
00047 wxASSERT (!m_containerName.IsEmpty ());
00048
00049 this->BuildTreeItemSiblingIdxHierarchyList ();
00050 }
00051
00052
00053 void CRTreeItemRightClickEvent::EmitCpp ()
00054 {
00055
00056
00057
00058
00059
00060
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 CRCppEmitter *emitter = CRCppEmitter::GetInstance ();
00086
00087 wxString containerVarName = emitter->AddContainerLookupCode (
00088 m_containerName, wxString::Format (_T("tree control '%s'"),
00089 m_treeCtrlName.c_str ()));
00090
00091 wxString treeCtrlWdwVarName = emitter->MakeVarName (m_treeCtrlName,
00092 _T("Wdw"));
00093
00094 wxString str;
00095 str << _T("wxWindow *") << treeCtrlWdwVarName << _T(" = ") <<
00096 containerVarName << _T("->FindWindow (");
00097 str << _T("_T(\"") << m_treeCtrlName << _T("\"));");
00098 emitter->AddCode (str);
00099
00100 str.Clear ();
00101 str << _T("CPPUNIT_ASSERT_MESSAGE (\"Window for tree control '") <<
00102 m_treeCtrlName << _T("' not found\", ") << treeCtrlWdwVarName <<
00103 _T(" != NULL);");
00104 emitter->AddCode (str);
00105
00106 wxString treeCtrlVarName = emitter->MakeVarName (m_treeCtrlName);
00107
00108 str.Clear ();
00109 str << _T("wxTreeCtrl *") << treeCtrlVarName << _T(" = wxDynamicCast (") <<
00110 treeCtrlWdwVarName << _T(", wxTreeCtrl);");
00111 emitter->AddCode (str);
00112
00113 str.Clear ();
00114 str << _T("CPPUNIT_ASSERT_MESSAGE (\"Converting window for tree control '") <<
00115 m_treeCtrlName << _T("' failed\", ") << treeCtrlVarName <<
00116 _T(" != NULL);");
00117 emitter->AddCode (str);
00118
00119 wxString rootIdVarName = _T("rootId");
00120
00121 str.Clear ();
00122 str << _T("wxTreeItemId ") << rootIdVarName << _T(" = ") << treeCtrlVarName <<
00123 _T("->GetRootItem ();");
00124 emitter->AddCode (str);
00125
00126 str.Clear ();
00127 str << _T("CPPUNIT_ASSERT_MESSAGE (\"Tree control root item is invalid\", ")
00128 << rootIdVarName << _T(".IsOk ());");
00129 emitter->AddCode (str);
00130
00131 wxString parentItemIdVarName = rootIdVarName;
00132
00133 unsigned int cnt;
00134 UnsignedIntList::const_iterator it;
00135 for (it = m_treeItemSiblingIdxHierarchyList.begin (), cnt = 1;
00136 it != m_treeItemSiblingIdxHierarchyList.end (); it++, cnt++) {
00137
00138
00139
00140 str.Clear ();
00141 str << treeCtrlVarName << _T("->Expand (") << parentItemIdVarName <<
00142 _T(");");
00143 emitter->AddCode (str);
00144
00145 wxString curTreeItemIdVarName = emitter->MakeVarName (
00146 wxString::Format (_T("treeItemId%d"), cnt));
00147
00148 str.Clear ();
00149 str << _T("wxTreeItemId ") << curTreeItemIdVarName <<
00150 _T(" = wxTst::EventSimulationHelper::GetNthTreeChild (") << treeCtrlVarName <<
00151 _T(", ") << (*it) << _T(", ") << parentItemIdVarName << _T(");");
00152 emitter->AddCode (str);
00153
00154 str.Clear ();
00155 str << _T("CPPUNIT_ASSERT_MESSAGE (\"Tree control item is invalid\", ") <<
00156 curTreeItemIdVarName << _T(".IsOk ());");
00157 emitter->AddCode (str);
00158
00159 parentItemIdVarName = curTreeItemIdVarName;
00160 }
00161
00162 str.Clear ();
00163 str << _T("wxTst::EventSimulationHelper::RightClickTreeItem (") <<
00164 parentItemIdVarName << _T(", ") << treeCtrlVarName << _T(");");
00165 emitter->AddCode (str);
00166
00167 str.Clear ();
00168 str << _T("wxTst::WxGuiTestHelper::FlushEventQueue ();\n");
00169 emitter->AddCode (str);
00170 }
00171