NIREP
|
00001 00002 // Name: ViewRDL.cpp 00003 // Purpose: 00004 // Author: 00005 // Modified by: 00006 // Created: 22/07/2010 12:31:31 00007 // RCS-ID: 00008 // Copyright: 00009 // Licence: 00011 00012 // For compilers that support precompilation, includes "wx/wx.h". 00013 #include "wx/wxprec.h" 00014 00015 #ifdef __BORLANDC__ 00016 #pragma hdrstop 00017 #endif 00018 00019 #ifndef WX_PRECOMP 00020 #include "wx/wx.h" 00021 #endif 00022 00023 00024 #include "ViewRDL.h" 00025 00026 00027 00028 /* 00029 * ViewRDL type definition 00030 */ 00031 00032 IMPLEMENT_CLASS( ViewRDL, wxFrame ) 00033 00034 00035 /* 00036 * ViewRDL event table definition 00037 */ 00038 00039 BEGIN_EVENT_TABLE( ViewRDL, wxFrame ) 00040 00041 EVT_BUTTON( ID_BROWSE, ViewRDL::OnBrowseClick ) 00042 00043 EVT_BUTTON( ID_SAVE, ViewRDL::OnSaveClick ) 00044 00045 EVT_BUTTON( ID_APPEND, ViewRDL::OnAppendClick ) 00046 00047 EVT_BUTTON( wxID_CANCEL, ViewRDL::OnCancelClick ) 00048 00049 00050 END_EVENT_TABLE() 00051 00052 00053 /* 00054 * ViewRDL constructors 00055 */ 00056 00057 ViewRDL::ViewRDL() 00058 { 00059 Init(); 00060 } 00061 00062 ViewRDL::ViewRDL( wxWindow* parent,ResourceDescriptionList* rdl, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style ) 00063 { 00064 Init(); 00065 m_rdl = rdl; 00066 Create( parent, id, caption, pos, size, style ); 00067 } 00068 00069 00070 /* 00071 * ViewRDL creator 00072 */ 00073 00074 bool ViewRDL::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style ) 00075 { 00076 wxFrame::Create( parent, id, caption, pos, size, style ); 00077 00078 CreateControls(); 00079 Centre(); 00080 return true; 00081 } 00082 00083 00084 /* 00085 * ViewRDL destructor 00086 */ 00087 00088 ViewRDL::~ViewRDL() 00089 { 00090 } 00091 00092 00093 /* 00094 * Member initialisation 00095 */ 00096 00097 void ViewRDL::Init() 00098 { 00099 m_rdl =NULL; 00100 } 00101 00102 00103 /* 00104 * Control creation for ViewRDL 00105 */ 00106 00107 void ViewRDL::CreateControls() 00108 { 00109 ViewRDL* itemFrame1 = this; 00110 00111 wxPanel* itemPanel2 = new wxPanel( itemFrame1, ID_PANEL8, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL ); 00112 00113 wxFlexGridSizer* itemFlexGridSizer3 = new wxFlexGridSizer(3, 1, 0, 0); 00114 itemFlexGridSizer3->AddGrowableRow(0); 00115 itemFlexGridSizer3->AddGrowableCol(0); 00116 itemPanel2->SetSizer(itemFlexGridSizer3); 00117 00118 00119 wxRichTextCtrl* itemRichTextCtrl4 = new wxRichTextCtrl( itemPanel2, ID_TEXT, wxEmptyString, wxDefaultPosition, wxSize(100, 100), wxWANTS_CHARS ); 00120 itemFlexGridSizer3->Add(itemRichTextCtrl4, 0, wxGROW|wxGROW|wxALL, 5); 00121 00122 00123 FILE * tempfile = fopen("tempfile.txt", "w+"); 00124 m_rdl->Save(tempfile); 00125 rewind(tempfile); 00126 int character; 00127 while( (character = fgetc(tempfile) ) != EOF ) { 00128 wxString temp; 00129 temp.Append(static_cast<char>(character) ); 00130 itemRichTextCtrl4->AppendText(temp); 00131 } 00132 fclose(tempfile); 00133 00134 wxFlexGridSizer* itemFlexGridSizer5 = new wxFlexGridSizer(0, 3, 0, 0); 00135 itemFlexGridSizer5->AddGrowableCol(1); 00136 itemFlexGridSizer3->Add(itemFlexGridSizer5, 0, wxGROW|wxGROW|wxALL, 5); 00137 00138 wxStaticText* itemStaticText6 = new wxStaticText( itemPanel2, wxID_STATIC, _("File Location"), wxDefaultPosition, wxDefaultSize, 0 ); 00139 itemFlexGridSizer5->Add(itemStaticText6, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5); 00140 00141 wxTextCtrl* itemTextCtrl7 = new wxTextCtrl( itemPanel2, ID_FILE_LOCATION, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); 00142 itemFlexGridSizer5->Add(itemTextCtrl7, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW|wxALL, 5); 00143 00144 wxButton* itemButton8 = new wxButton( itemPanel2, ID_BROWSE, _("Browse"), wxDefaultPosition, wxDefaultSize, 0 ); 00145 itemFlexGridSizer5->Add(itemButton8, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5); 00146 00147 wxBoxSizer* itemBoxSizer9 = new wxBoxSizer(wxHORIZONTAL); 00148 itemFlexGridSizer3->Add(itemBoxSizer9, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_TOP|wxALL, 5); 00149 00150 wxButton* itemButton10 = new wxButton( itemPanel2, ID_SAVE, _("Save"), wxDefaultPosition, wxDefaultSize, 0 ); 00151 itemBoxSizer9->Add(itemButton10, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); 00152 00153 wxButton* itemButton11 = new wxButton( itemPanel2, ID_APPEND, _("Append"), wxDefaultPosition, wxDefaultSize, 0 ); 00154 itemBoxSizer9->Add(itemButton11, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); 00155 00156 wxButton* itemButton12 = new wxButton( itemPanel2, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 ); 00157 itemBoxSizer9->Add(itemButton12, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); 00158 } 00159 00160 00161 /* 00162 * Should we show tooltips? 00163 */ 00164 00165 bool ViewRDL::ShowToolTips() 00166 { 00167 return true; 00168 } 00169 00170 /* 00171 * Get bitmap resources 00172 */ 00173 00174 wxBitmap ViewRDL::GetBitmapResource( const wxString& name ) 00175 { 00176 // Bitmap retrieval 00177 wxUnusedVar(name); 00178 return wxNullBitmap; 00179 } 00180 00181 /* 00182 * Get icon resources 00183 */ 00184 00185 wxIcon ViewRDL::GetIconResource( const wxString& name ) 00186 { 00187 // Icon retrieval 00188 wxUnusedVar(name); 00189 return wxNullIcon; 00190 } 00191 00192 00193 /* 00194 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BROWSE 00195 */ 00196 00197 void ViewRDL::OnBrowseClick( wxCommandEvent& event ) 00198 { 00199 wxFileDialog * filedialog = new wxFileDialog(this, wxT("Choose a file name and location"), wxT(""), wxT("untitled.rdl"), wxT("(*.rdl)|*.rdl"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT, wxDefaultPosition, wxDefaultSize, wxT("Select")); 00200 if( filedialog->ShowModal() == wxID_CANCEL ){ delete filedialog; return;} 00201 00202 dynamic_cast<wxTextCtrl *>(this->FindWindow(ID_FILE_LOCATION))->SetValue(filedialog->GetPath() ); 00203 00204 delete filedialog; 00205 } 00206 00207 00208 /* 00209 * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CANCEL 00210 */ 00211 00212 void ViewRDL::OnCancelClick( wxCommandEvent& event ) 00213 { 00214 // Before editing this code, remove the block markers. 00215 this->Close(); 00216 } 00217 00218 00219 /* 00220 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_APPEND 00221 */ 00222 00223 void ViewRDL::OnAppendClick( wxCommandEvent& event ) 00224 { 00225 wxString filename = dynamic_cast<wxTextCtrl *>(this->FindWindow(ID_FILE_LOCATION))->GetValue(); 00226 FILE * file = fopen(filename.mb_str(), "a"); 00227 int nol = dynamic_cast<wxRichTextCtrl*>(this->FindWindow(ID_TEXT))->GetNumberOfLines(); 00228 for(int i=0; i< nol; i++) { 00229 wxString lineText = dynamic_cast<wxRichTextCtrl*>(this->FindWindow(ID_TEXT))->GetLineText(i); 00230 fputs(lineText.mb_str(), file); 00231 } 00232 fclose(file); 00233 this->Close(); 00234 } 00235 00236 00237 /* 00238 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_SAVE 00239 */ 00240 00241 void ViewRDL::OnSaveClick( wxCommandEvent& event ) 00242 { 00243 wxString filename = dynamic_cast<wxTextCtrl *>(this->FindWindow(ID_FILE_LOCATION))->GetValue(); 00244 FILE * file = fopen(filename.mb_str(), "w"); 00245 int nol = dynamic_cast<wxRichTextCtrl*>(this->FindWindow(ID_TEXT))->GetNumberOfLines(); 00246 for(int i=0; i< nol; i++) { 00247 wxString lineText = dynamic_cast<wxRichTextCtrl*>(this->FindWindow(ID_TEXT))->GetLineText(i); 00248 fputs(lineText.mb_str(), file); 00249 fputs("\n", file); 00250 } 00251 fclose(file); 00252 this->Close(); 00253 } 00254