00001
00002
00003
00004
00005
00006
00007
00008
00010
00011 #ifdef __GNUG__
00012 #pragma implementation "CRNotebookPageChangeEvent.h"
00013 #endif
00014
00015 #include "CRNotebookPageChangeEvent.h"
00016
00017 #include <wx/notebook.h>
00018
00019 #include <wxGuiTest/CRWindowHierarchyHandler.h>
00020 #include <wxGuiTest/CRCppEmitter.h>
00021
00022 namespace wxTst {
00023
00024
00025 CRNotebookPageChangeEvent::CRNotebookPageChangeEvent (wxEvent *event) :
00026 CRCapturedEvent (event)
00027 {
00028 m_isFirstAndPending = true;
00029 }
00030
00031
00032 CRNotebookPageChangeEvent::~CRNotebookPageChangeEvent ()
00033 {
00034
00035 }
00036
00037
00038 bool CRNotebookPageChangeEvent::IsPending () const
00039 {
00040 return m_isFirstAndPending;
00041 }
00042
00043
00044 void CRNotebookPageChangeEvent::Process (CRCapturedEvent **pendingEvt)
00045 {
00046
00047
00048 if (*pendingEvt != NULL) {
00049
00050 CRNotebookPageChangeEvent *pendingNbPgChgEvt =
00051 dynamic_cast< CRNotebookPageChangeEvent * >(*pendingEvt);
00052 if (pendingNbPgChgEvt != NULL) {
00053
00054 if (m_event->GetEventObject () ==
00055 pendingNbPgChgEvt->GetEvent ()->GetEventObject ()) {
00056
00057 m_isFirstAndPending = false;
00058 delete *pendingEvt;
00059 *pendingEvt = NULL;
00060 }
00061 }
00062 }
00063
00064 wxWindow *wdwEvtObject = wxDynamicCast (m_event->GetEventObject (), wxWindow);
00065 wxASSERT (wdwEvtObject != NULL);
00066
00067 CRWindowHierarchyHandler *hierarchy = CRWindowHierarchyHandler::GetInstance ();
00068 wxASSERT (hierarchy != NULL);
00069
00070 m_notebookName = wdwEvtObject->GetName ();
00071 m_containerName = hierarchy->FindContainerName (wdwEvtObject);
00072 wxASSERT (!m_containerName.IsEmpty ());
00073 wxASSERT (m_notebookName == m_containerName);
00074
00075 wxASSERT (m_event->IsCommandEvent ());
00076 wxNotebookEvent *nbEvt = wxDynamicCast (m_event, wxNotebookEvent);
00077 wxASSERT (nbEvt != NULL);
00078 int page = nbEvt->GetSelection ();
00079 wxNotebook *notebook = wxDynamicCast (wdwEvtObject, wxNotebook);
00080 wxASSERT (notebook != NULL);
00081 m_notebookPageText = notebook->GetPageText (page);
00082 }
00083
00084
00085 void CRNotebookPageChangeEvent::EmitCpp ()
00086 {
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 CRCppEmitter *emitter = CRCppEmitter::GetInstance ();
00110
00111 wxString notebookWdwVarName = emitter->AddContainerLookupCode (
00112 m_containerName, wxString::Format (_T("notebook '%s'"), m_notebookName.c_str ()),
00113 _T("Wdw"));
00114
00115 wxString notebookVarName = emitter->MakeVarName (m_notebookName);
00116
00117 wxString str;
00118 str.Clear ();
00119 str << _T("wxNotebook *") << notebookVarName << _T(" = wxDynamicCast (") <<
00120 notebookWdwVarName << _T(", wxNotebook);");
00121 emitter->AddCode (str);
00122
00123 str.Clear ();
00124 str << _T("CPPUNIT_ASSERT_MESSAGE (\"Converting window for notebook '") <<
00125 m_notebookName << _T("' failed\", ") << notebookVarName <<
00126 _T(" != NULL);");
00127 emitter->AddCode (str);
00128
00129 wxString pageTextVarName = emitter->MakeVarName (notebookVarName,
00130 _T("PageText"));
00131
00132 str.Clear ();
00133 str << _T("const wxString ") << pageTextVarName << _T(" (_(\"") <<
00134 m_notebookPageText << _T("\"));");
00135 emitter->AddCode (str);
00136
00137 wxString pageVarName = emitter->MakeVarName (notebookVarName, _T("Page"));
00138
00139 str.Clear ();
00140 str << _T("int ") << pageVarName << _T(" = 0;");
00141 emitter->AddCode (str);
00142
00143 str.Clear ();
00144 str << _T("while ((") << pageVarName << _T(" < ") << notebookVarName <<
00145 _T("->GetPageCount ()) && (") << notebookVarName <<
00146 _T("->GetPageText (") << pageVarName << _T(") != ") << pageTextVarName <<
00147 _T(")) {\n");
00148 emitter->AddCode (str);
00149
00150 str.Clear ();
00151 str << emitter->GetTab () << pageVarName << _T("++;");
00152 emitter->AddCode (str);
00153
00154 str.Clear ();
00155 str << _T("}");
00156 emitter->AddCode (str);
00157
00158 str.Clear ();
00159 str << _T("CPPUNIT_ASSERT_MESSAGE (\"Page of notebook '") << m_notebookName <<
00160 _T("' not found\", ") << pageVarName << _T(" < ") << notebookVarName <<
00161 _T("->GetPageCount ());");
00162 emitter->AddCode (str);
00163
00164 str.Clear ();
00165 str << _T("wxTst::EventSimulationHelper::SelectNotebookPage (") <<
00166 notebookVarName << _T(", ") << pageVarName << _T(");");
00167 emitter->AddCode (str);
00168
00169 str.Clear ();
00170 str << _T("wxTst::WxGuiTestHelper::FlushEventQueue ();\n");
00171 emitter->AddCode (str);
00172 }
00173
00174 }
00175