00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013 #ifdef __GNUG__
00014 #pragma implementation "CRCapture.h"
00015 #endif
00016
00017 #include <wxGuiTest/CRCapture.h>
00018
00019 #include <iostream>
00020
00021 #include <wx/xrc/xmlres.h>
00022
00023 #include <wxGuiTest/WxGuiTestHelper.h>
00024 #include <wxGuiTest/CREventCaptureManager.h>
00025
00026
00027 extern void InitCapturePanelXRC ();
00028
00029 namespace wxTst {
00030
00031
00032 CRCapture::CRCapture ()
00033 {
00034 wxXmlResource::Get()->InitAllHandlers();
00035
00036 m_dialog = NULL;
00037 m_control = NULL;
00038 m_logTextCtrl = NULL;
00039 }
00040
00041
00042 CRCapture::~CRCapture ()
00043 {
00044 if (m_dialog != NULL) {
00045
00046 m_dialog->PopEventHandler (true);
00047 m_dialog->Destroy ();
00048 }
00049 }
00050
00051
00052 void CRCapture::Capture (const char *file, int line)
00053 {
00054 wxString filestr(file, *wxConvCurrent);
00055 CRCppEmitter::GetInstance ()->SetTestCaseFileContext (filestr, line);
00056
00057 this->Show ();
00058 }
00059
00060
00061 void CRCapture::Log (const wxString &text)
00062 {
00063 m_logTextCtrl->AppendText (text);
00064 }
00065
00066
00067 void CRCapture::Show ()
00068 {
00069
00070 bool oldInteractive = WxGuiTestHelper::GetInteractive();
00071 WxGuiTestHelper::SetInteractive (true);
00072
00073
00074 bool oldShowModalDialogsNonModal = WxGuiTestHelper::GetShowModalDialogsNonModalFlag ();
00075 WxGuiTestHelper::SetShowModalDialogsNonModalFlag (false);
00076 bool oldShowPopupMenus = WxGuiTestHelper::GetShowPopupMenusFlag ();
00077 WxGuiTestHelper::SetShowPopupMenusFlag (true);
00078
00079 if (m_dialog == NULL) {
00080
00081 this->CreateDialog ();
00082 m_control = this->CreateEvtHandler ();
00083 m_dialog->PushEventHandler (m_control);
00084
00085 CREventCaptureManager::GetInstance ()->IgnoreWindow (m_dialog);
00086 CREventCaptureManager::GetInstance ()->SetLogger (this);
00087 }
00088 m_control->SetButtonStates ();
00089 m_dialog->Show ();
00090
00091
00092 wxTheApp->MainLoop ();
00093
00094
00095 WxGuiTestHelper::SetInteractive(oldInteractive);
00096
00097 WxGuiTestHelper::SetShowModalDialogsNonModalFlag (oldShowModalDialogsNonModal);
00098 WxGuiTestHelper::SetShowPopupMenusFlag (oldShowPopupMenus);
00099 }
00100
00101
00102 CRCaptureControl * CRCapture::CreateEvtHandler () const
00103 {
00104 return new CRCaptureControl (m_dialog);
00105 }
00106
00107
00108 void CRCapture::CreateDialog ()
00109 {
00110 m_dialog = new wxDialog (NULL, -1, _("Capture Dialog"), wxDefaultPosition,
00111 wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER);
00112
00113 wxBoxSizer *topsizer = new wxBoxSizer (wxVERTICAL);
00114
00115 wxPanel *panel = this->LoadPanel ();
00116 wxASSERT (panel != NULL);
00117 topsizer->Add (panel, 1, wxGROW | wxADJUST_MINSIZE, 0);
00118
00119 m_logTextCtrl = XRCCTRL (*panel, "LoggingTextCtrl", wxTextCtrl);
00120 wxASSERT (m_logTextCtrl != NULL);
00121
00122 m_dialog->SetSizer (topsizer);
00123 topsizer->SetSizeHints (m_dialog);
00124 m_dialog->Layout ();
00125 }
00126
00127
00128 wxPanel * CRCapture::LoadPanel ()
00129 {
00130 InitCapturePanelXRC ();
00131 return wxXmlResource::Get ()->LoadPanel (m_dialog, _T("CapturePanel"));
00132 }
00133
00134 }