00001 00002 // MathGUI = a WYSIWYG equation editor + a powerful math engine // 00003 // Copyright (C) 2003 by Francesco Montorsi // 00004 // // 00005 // This library is free software; you can redistribute it and/or // 00006 // modify it under the terms of the GNU Lesser General Public // 00007 // License as published by the Free Software Foundation; either // 00008 // version 2.1 of the License, or (at your option) any later // 00009 // version. // 00010 // // 00011 // This library is distributed in the hope that it will be useful, // 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of // 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 00014 // GNU Lesser General Public License for more details. // 00015 // // 00016 // You should have received a copy of the GNU Lesser General Public // 00017 // License along with this program; if not, write to the Free // 00018 // Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, // 00019 // MA 02111-1307, USA. // 00020 // // 00021 // For any comment, suggestion or feature request, please contact // 00022 // the administrator of the project at frm@users.sourceforge.net // 00023 // // 00030 00031 00032 00033 // optimization for GCC compiler 00034 #ifdef __GNUG__ 00035 #pragma implementation "ImportDlg.h" 00036 #endif 00037 00038 // includes 00039 #include "mg/mgprec.h" 00040 00041 #ifndef mgPRECOMP 00042 #include <wx/wxprec.h> 00043 #include "mg/ImportDlg.h" 00044 #include "mg/GUIUtils.h" 00045 #endif 00046 00047 00048 00049 00050 // event table for mgImportDlg 00051 BEGIN_EVENT_TABLE(mgImportDlg, wxDialog) 00052 00053 // buttons 00054 EVT_BUTTON( IDC_IMPORTDLG_IMPORT_BTN, mgImportDlg::OnImport ) 00055 00056 // checkboxes 00057 00058 // textctrls 00059 EVT_TEXT( IDC_IMPORTDLG_INLINEDEXPR_FIELD, mgImportDlg::OnInlinedExprChange ) 00060 00061 // radio buttons 00062 00063 // choices 00064 00065 END_EVENT_TABLE() 00066 00067 00068 00069 00070 // -------------------------------------------- 00071 // mgIMPORTDLG 00072 // -------------------------------------------- 00073 00074 mgImportDlg::mgImportDlg( wxWindow *parent, mgMathWnd *wnd, mgMathBox *box, 00075 wxWindowID id, const wxString &title, 00076 const wxPoint &position, const wxSize& size, long style ) : 00077 // init base classes 00078 wxDialog( parent, id, title, position, size, style), 00079 mgMathBoxWndUser(wnd, box) 00080 { 00081 // it is VERY IMPORTANT that this file dialog has THIS window as parent. 00082 // If not, when clicking Browse button, this dialog would continue to accept 00083 // user inputs: we need instead that this window becomes disabled when 00084 // showing the browse window to the user, but we cannot do it with a call 00085 // to Disable(). The only way is to set this file dialog as child of this 00086 // window... 00087 00088 // build everything of this dialog 00089 BuildAll(); 00090 } 00091 00092 mgImportDlg::~mgImportDlg() 00093 { 00094 // delete all windows not managed by sizers 00095 mcSAFE_DELETE(m_pFD); 00096 } 00097 00098 00099 00100 void mgImportDlg::BuildCtrls() 00101 { 00102 m_pFD = new wxFileDialog(this, wxT("Load an XHTML/XML file"), wxT(""), wxT(""), 00103 wxT("XHTML files (*.htm; *.html)|*.htm;*.html"), wxSAVE | wxCHANGE_DIR | 00104 wxOVERWRITE_PROMPT); 00105 00106 m_pExpr = new wxTextCtrl(this, IDC_IMPORTDLG_INLINEDEXPR_FIELD, wxT("")); 00107 } 00108 00109 void mgImportDlg::BuildAll() 00110 { 00111 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL); 00112 00113 // first of all, the controls must be created... 00114 BuildCtrls(); 00115 00117 // insert DESCRIPTION 00118 wxStaticText *hdr = new wxStaticText(this, -1, 00119 wxT("This dialog allows you to import MathML 2.0 ") 00120 wxT("documents and inlined expressions.\n") 00121 wxT("However, you cannot import both: the following radio") 00122 wxT("buttons allow you to choose which you want to import.")); 00123 sizer->Add( 00124 hdr, 00125 0, // make horizontally unstretchable 00126 wxALL | wxALIGN_LEFT, // center it & use borders 00127 10); 00128 00129 00131 // insert the import type selector 00132 wxBoxSizer *type = new wxBoxSizer(wxHORIZONTAL); 00133 type->Add(new wxRadioButton( 00134 this, IDC_IMPORTDLG_MATHML, wxT("MathML"), wxDefaultPosition, 00135 wxSize(-1,-1), wxRB_GROUP), 00136 0, wxALIGN_CENTER | wxRIGHT, 20); 00137 type->Add(new wxRadioButton( 00138 this, IDC_IMPORTDLG_INLINEDEXPR, wxT("Inlined expression")), 00139 0, wxALIGN_CENTER | wxLEFT, 10); 00140 00141 00143 // add MathML static box sizer 00144 wxStaticBox *sb1 = new wxStaticBox(this, -1, wxT("MathML")); 00145 wxStaticBoxSizer *mathml = new wxStaticBoxSizer(sb1, wxVERTICAL); 00146 mathml->Add(new wxStaticText(this, -1, 00147 wxT("Sorry, MathML import system is not working yet")), 0, wxGROW | wxALL, 5); 00148 00149 00151 // add Inlined Expressions static box sizer 00152 wxStaticBox *sb2 = new wxStaticBox(this, -1, wxT("Inlined expressions")); 00153 wxStaticBoxSizer *ex = new wxStaticBoxSizer(sb2, wxVERTICAL); 00154 ex->Add(new wxStaticText(this, -1, wxT("Inlined expressions are the most ") 00155 wxT("commonly used form of math typing: using some simple rules\n") 00156 wxT("(like ^=introduce exponent, *=multiplication ...) complex ") 00157 wxT("expressions can be created\n(even if they become difficult to ") 00158 wxT("write and to understand).")), 0, wxGROW | wxALL, 5); 00159 ex->Add(new wxStaticText(this, -1, wxT("The textbox below allows you to ") 00160 wxT("paste an inlined expression and then to import it.")), 0, wxGROW | wxALL, 5); 00161 ex->Add(m_pExpr, 1, wxGROW | wxALL, 5); 00162 00163 00165 // add the buttons 00166 wxBoxSizer *btn = new wxBoxSizer(wxHORIZONTAL); 00167 btn->Add(new wxButton(this, wxID_CANCEL, wxT("Cancel")), 3, wxGROW | wxTOP, 10); 00168 btn->Add(1, 1, 1, wxGROW); 00169 00170 wxButton *def = new wxButton(this, IDC_IMPORTDLG_IMPORT_BTN, wxT("Import")); 00171 btn->Add(def, 3, wxGROW | wxTOP, 10); 00172 def->SetDefault(); 00173 00174 00175 // set up global sizer 00176 sizer->Add(type, 0, wxALIGN_CENTER | wxALL, 10); 00177 sizer->Add(mathml, 2, wxGROW | wxALL, 10); 00178 sizer->Add(ex, 2, wxGROW | wxALL, 10); 00179 sizer->Add(btn, 1, wxGROW | wxALL, 10); 00180 00181 SetSizer(sizer); // use the sizer for layout 00182 sizer->SetSizeHints(this); // set size hints to honour minimum size 00183 00184 // set up controls 00185 00186 // center the dialog 00187 this->CentreOnScreen(); 00188 } 00189 00190 bool mgImportDlg::isImportingMathML() 00191 { 00192 wxRadioButton *btn = (wxRadioButton *)FindWindowById(IDC_IMPORTDLG_MATHML, this); 00193 00194 // are we importing mathML ? 00195 return btn->GetValue(); 00196 } 00197 00198 00199 00200 // event handlers 00201 00202 void mgImportDlg::OnImport(wxCommandEvent &ev) 00203 { 00204 mgLogDebug(wxT("mgImportDlg::OnImport() - importing %s..."), 00205 (isImportingMathML() ? wxT("a MathML file") : wxT("an inlined expression"))); 00206 00207 if (isImportingMathML()) { 00208 00209 } else { 00210 00211 // just check that there is something to import... 00212 if (m_pExpr->GetValue().IsEmpty()) { 00213 00214 wxMessageBox(wxT("Cannot import an empty string !"), wxT("Warning"), 00215 wxICON_EXCLAMATION | wxOK | wxCENTRE); 00216 return; 00217 } 00218 00219 // then drop import request to mgMathBox 00220 GetBox()->ImportInlinedExpr(m_pExpr->GetValue()); 00221 } 00222 00223 EndModal(wxID_OK); 00224 } 00225 00226 void mgImportDlg::OnInlinedExprChange(wxCommandEvent &ev) 00227 { 00228 wxRadioButton *btn = (wxRadioButton *)FindWindowById(IDC_IMPORTDLG_INLINEDEXPR, this); 00229 00230 // "click" on the radio button 00231 btn->SetValue(TRUE); 00232 } 00233 00234 00235
[ Top ] |