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 "ExportDlg.h" 00036 #endif 00037 00038 // includes 00039 #include "mg/mgprec.h" 00040 #include <wx/filename.h> // not included in wxprec.h 00041 00042 #ifndef mgPRECOMP 00043 #include <wx/wxprec.h> 00044 #include "mg/ExportDlg.h" 00045 #include "mg/GUIUtils.h" 00046 #endif 00047 00048 00049 00050 // the wxWindow RTTI registration of mgExportBasePanel is required 00051 // because mgExportBasePanel's derived classes must be able to use 00052 // event tables.... 00053 IMPLEMENT_ABSTRACT_CLASS(mgExportBasePanel, wxPanel) 00054 00055 00056 // event table for mgExportBasicOpt 00057 IMPLEMENT_CLASS(mgExportBasicOpt, mgExportBasePanel) 00058 BEGIN_EVENT_TABLE(mgExportBasicOpt, mgExportBasePanel) 00059 00060 // miscellaneous 00061 EVT_BUTTON( IDC_EXPDLG_SHOWADV, mgExportBasicOpt::OnShowAdv ) 00062 EVT_BUTTON( IDC_EXPDLG_BROWSE, mgExportBasicOpt::OnBrowse ) 00063 EVT_TEXT( IDC_EXPDLG_TITLE, mgExportBasicOpt::OnTitleChanged ) 00064 EVT_CHOICE( IDC_EXPDLG_BROWSER_LIST, mgExportBasicOpt::OnBrowserModeChanged ) 00065 00066 END_EVENT_TABLE() 00067 00068 00069 00070 // event table for mgExportAdvOpt 00071 IMPLEMENT_CLASS(mgExportAdvOpt, mgExportBasePanel) 00072 BEGIN_EVENT_TABLE(mgExportAdvOpt, mgExportBasePanel) 00073 00074 // checkboxes 00075 EVT_CHECKBOX( IDC_EXPDLG_USE_NS, mgExportAdvOpt::OnUseNS ) 00076 EVT_CHECKBOX( IDC_EXPDLG_UPPER, mgExportAdvOpt::OnPreviewChanged ) 00077 EVT_CHECKBOX( IDC_EXPDLG_MATH_PLAYER, mgExportAdvOpt::OnMathPlayer ) 00078 00079 // textctrls 00080 EVT_TEXT( IDC_EXPDLG_INDENTATION, mgExportAdvOpt::OnPreviewChanged ) 00081 EVT_TEXT( IDC_EXPDLG_NS, mgExportAdvOpt::OnPreviewChanged ) 00082 00083 // radio buttons 00084 EVT_RADIOBUTTON( IDC_EXPDLG_XML, mgExportAdvOpt::OnTypeChanged ) 00085 EVT_RADIOBUTTON( IDC_EXPDLG_XHTML, mgExportAdvOpt::OnTypeChanged ) 00086 00087 END_EVENT_TABLE() 00088 00089 00090 00091 // event table for mgExportDlg 00092 IMPLEMENT_CLASS(mgExportDlg, wxDialog) 00093 BEGIN_EVENT_TABLE(mgExportDlg, wxDialog) 00094 00095 // buttons 00096 EVT_BUTTON( IDC_EXPDLG_EXPORT_AND_OPEN, mgExportDlg::OnExportAndOpen ) 00097 EVT_BUTTON( IDC_EXPDLG_EXPORT, mgExportDlg::OnExport ) 00098 00099 END_EVENT_TABLE() 00100 00101 00102 00103 00104 00105 00106 // -------------------------------------------- 00107 // mgEXPORTBASICOPT 00108 // -------------------------------------------- 00109 00110 void mgExportBasicOpt::BuildCtrls() 00111 { 00112 // Build the controls which will be used very often in the sources, storing 00113 // their pointers. In this way, we do not have to use wxWindow::FindWindowById 00114 // each time we must access them. Please note that IDs are still required for 00115 // event handling. 00116 // The controls which are not used very often are created directly by Build** 00117 // functions without storing their addresses. This means that if you want to access 00118 // them, you have to use wxWindow::FindWindowById and to cast them to their 00119 // right class (wxTextCtrl, wxRadioButton...) 00120 // 00121 00122 // it is VERY IMPORTANT that this file dialog has THIS window as parent. 00123 // If not, when clicking Browse button, this dialog would continue to accept 00124 // user inputs: we need instead that this window becomes disabled when 00125 // showing the browse window to the user, but we cannot do it with a call 00126 // to Disable(). The only way is to set this file dialog as child of this 00127 // window... 00128 m_pFD = new wxFileDialog(this, wxT("Save as XHTML file"), wxT(""), wxT(""), 00129 wxT("XHTML files (*.htm; *.html)|*.htm;*.html"), wxSAVE | wxCHANGE_DIR | 00130 wxOVERWRITE_PROMPT); 00131 00132 wxString choices[] = { wxT("Internet Explorer (version 5.5 or higher) with MathPlayer"), 00133 wxT("Mozilla or Netscape (versions 1.2.x or higher)"), 00134 wxT("<do not use preset options>") }; 00135 00136 // text controls 00137 m_pDest = new wxTextCtrl(this, IDC_EXPDLG_FILE, wxT("")); 00138 m_pTitle = new wxTextCtrl(this, IDC_EXPDLG_TITLE, wxT("")); 00139 00140 #ifdef mgEXPDLG_STILL_NOT_WORKING 00141 m_pIndentation = new wxTextCtrl(this, IDC_EXPDLG_INDENTATION, wxT(""), 00142 wxDefaultPosition, wxSize(40, -1)); 00143 #endif 00144 00145 // choices 00146 m_pChoice = new wxChoice(this, IDC_EXPDLG_BROWSER_LIST, wxDefaultPosition, 00147 wxDefaultSize, 3, choices); 00148 00149 // buttons 00150 m_pShowAdv = new wxButton(this, IDC_EXPDLG_SHOWADV, GetShowAdvLabel()); 00151 00152 } 00153 00154 void mgExportBasicOpt::BuildAll() 00155 { 00156 // first of all, build all the controls of this panel 00157 BuildCtrls(); 00158 00159 // prepare the BASIC OPTIONS sizer: in this sizer, the only elements which 00160 // grow are the empty space placed between (almost) every two elements 00161 wxStaticBoxSizer *basic = new wxStaticBoxSizer( 00162 new wxStaticBox(this, -1, wxT("Basic export options")), wxVERTICAL); 00163 00164 wxBoxSizer *list = new wxBoxSizer(wxHORIZONTAL), 00165 *title = new wxBoxSizer(wxHORIZONTAL), 00166 *browse = new wxBoxSizer(wxHORIZONTAL); 00167 00168 basic->Add( 00169 new wxStaticText(this, -1, 00170 wxT("Changing the options in the BASIC panel, you will change ") 00171 wxT("ADVANCED panel options, too.")), 00172 0, 00173 wxALL | wxGROW, 00174 5); 00175 basic->Add(1, 1, 1, wxGROW); 00176 00177 00178 list->Add( 00179 new wxStaticText(this, -1, 00180 wxT("Adjust options to make the exported file compatible ") 00181 wxT("(i.e. viewable) with:")), 00182 0, 00183 wxALL | wxALIGN_CENTER, 00184 5); 00185 list->Add( 00186 m_pChoice, 00187 1, 00188 wxALL | wxGROW, 00189 5); 00190 00191 basic->Add(list, 0, wxGROW); 00192 basic->Add(1, 1, 1, wxGROW); 00193 00194 title->Add( 00195 new wxStaticText(this, -1, 00196 wxT("Title of the exported XHTML/XML file:")), 00197 0, 00198 wxALL | wxALIGN_CENTER, 00199 5); 00200 title->Add( 00201 m_pTitle, 00202 1, 00203 wxALL | wxGROW, 00204 5); 00205 00206 basic->Add(title, 0, wxGROW); 00207 basic->Add(1, 1, 1, wxGROW); 00208 00209 browse->Add( 00210 new wxStaticText(this, -1, wxT("Export in: ")), 00211 0, 00212 wxALL | wxALIGN_CENTER, 00213 5); 00214 browse->Add( 00215 m_pDest, 00216 1, 00217 wxALL | wxGROW, 00218 5); 00219 browse->Add( 00220 new wxButton(this, IDC_EXPDLG_BROWSE, wxT("Browse")), 00221 0, 00222 wxALL | wxGROW, 00223 5); 00224 00225 browse->Add( 00226 m_pShowAdv, 00227 0, 00228 wxALL | wxGROW, 00229 5); 00230 00231 basic->Add(browse, 0, wxGROW); 00232 00233 // finally set the sizer as the handler of this panel... 00234 SetSizer(basic); 00235 basic->SetSizeHints(this); 00236 00237 // do a little setup 00238 m_pChoice->SetSelection(m_pChoice->GetCount()-1); 00239 00240 } 00241 00242 00243 00244 // -------------------------------------------- 00245 // mgEXPORTBASICOPT - event handlers 00246 // -------------------------------------------- 00247 00248 wxString mgExportBasicOpt::GetShowAdvLabel() 00249 { 00250 mgExportDlg *parent = wxDynamicCast(GetParent(), mgExportDlg); 00251 00252 mcASSERT(parent != NULL, 00253 wxT("mgExportBasicOpt can be created only inside a mgExportDlg...")); 00254 00255 if (parent->isShowingAdvOpt()) 00256 return wxT("Show advanced options <<"); 00257 return wxT("Show advanced options >>"); 00258 } 00259 00260 void mgExportBasicOpt::OnShowAdv(wxCommandEvent &event) 00261 { 00262 // get a pointer to the mgExportDlg which contains this panel 00263 mgExportDlg *parent = wxDynamicCast(GetParent(), mgExportDlg); 00264 mcASSERT(parent != NULL, 00265 wxT("mgExportBasicOpt can be created only inside a mgExportDlg...")); 00266 00267 // call its event-handler 00268 parent->ShowAdv(); 00269 00270 // change button label 00271 m_pShowAdv->SetLabel(GetShowAdvLabel()); 00272 } 00273 00274 void mgExportBasicOpt::OnBrowse( wxCommandEvent &event ) 00275 { 00276 // show the file dialog to let the user choose the destination file 00277 if (m_pFD->ShowModal() == wxID_CANCEL) { 00278 00279 // user changed idea.... 00280 return; 00281 } 00282 00283 // change the destination file 00284 m_pDest->Clear(); 00285 m_pDest->WriteText(m_pFD->GetPath()); 00286 } 00287 00288 void mgExportBasicOpt::OnBrowserModeChanged( wxCommandEvent &event ) 00289 { 00290 // if there is no advanced panels linked to this class, we cannot 00291 // do anything... 00292 if (m_pAdv == NULL) 00293 return; 00294 00295 // change all the options to reflect user's choice 00296 if (m_pChoice->GetSelection() == 0) { // IE with MathPlayer 00297 00298 // simulate user click on "use namespace" checkbox 00299 m_pAdv->m_pMathPlayer->SetValue(TRUE); 00300 m_pAdv->OnMathPlayer(event); 00301 00302 m_pAdv->m_pNS->Clear(); 00303 m_pAdv->m_pNS->WriteText(wxT("m")); 00304 00305 } else { // Mozilla or Netscape 00306 00307 // use XML 00308 m_pAdv->m_pXHTML->SetValue(FALSE); 00309 m_pAdv->m_pXML->SetValue(TRUE); 00310 m_pAdv->OnTypeChanged(event); 00311 00312 // simulate user click on "use namespace" checkbox 00313 m_pAdv->m_pUseNS->SetValue(FALSE); 00314 m_pAdv->OnUseNS(event); 00315 00316 m_pAdv->m_pMathPlayer->SetValue(FALSE); 00317 m_pAdv->OnMathPlayer(event); 00318 } 00319 } 00320 00321 void mgExportBasicOpt::OnTitleChanged(wxCommandEvent &event) 00322 { 00323 // if lined, notify a change to the advanced panel... 00324 if (m_pAdv) 00325 m_pAdv->OnPreviewChanged(event); 00326 } 00327 00328 00329 00330 00331 00332 00333 // -------------------------------------------- 00334 // mgEXPORTADVOPT 00335 // -------------------------------------------- 00336 00337 void mgExportAdvOpt::BuildCtrls() 00338 { 00339 // under Win32, use Rich edit controls, version 2 with auto url recognition 00340 m_pPreview = new wxTextCtrl(this, IDC_EXPDLG_PREVIEW, wxT(""), wxDefaultPosition, 00341 wxSize(0, 0), wxTE_READONLY | wxTE_MULTILINE | wxTE_RICH2);// | wxTE_AUTO_URL); 00342 00343 m_pNS = new wxTextCtrl(this, IDC_EXPDLG_NS, wxT("m"), wxDefaultPosition, 00344 wxSize(40, -1)); 00345 00346 // checkboxes 00347 m_pUseNS = new wxCheckBox(this, IDC_EXPDLG_USE_NS, wxT("Use namespace:")); 00348 m_pUpper = new wxCheckBox(this, IDC_EXPDLG_UPPER, wxT("Make tags UPPERCASE")); 00349 m_pMathPlayer = new wxCheckBox(this, IDC_EXPDLG_MATH_PLAYER, 00350 wxT("Add MathPlayer support")); 00351 00352 // radio buttons 00353 m_pXHTML = new wxRadioButton(this, IDC_EXPDLG_XHTML, wxT("XHTML"), wxDefaultPosition, 00354 wxSize(-1,-1), wxRB_GROUP); 00355 m_pXML = new wxRadioButton(this, IDC_EXPDLG_XML, wxT("XML")); 00356 } 00357 00358 void mgExportAdvOpt::BuildAll() 00359 { 00360 // first of all, build all the controls of this panel 00361 BuildCtrls(); 00362 00363 // prepare ADVANCED OPTIONS sizer: DO NOT TOUCH PROPORTIONS !!!!!!! 00364 wxStaticBoxSizer *adv = new wxStaticBoxSizer( 00365 new wxStaticBox(this, -1, wxT("Advanced export options")), wxHORIZONTAL); 00366 wxBoxSizer *subadv1 = new wxBoxSizer(wxHORIZONTAL), 00367 #ifdef mgEXPDLG_STILL_NOT_WORKING 00368 *subadv2 = new wxBoxSizer(wxHORIZONTAL), 00369 #endif 00370 *subadv3 = new wxBoxSizer(wxHORIZONTAL); 00371 wxBoxSizer *subadv1container = new wxBoxSizer(wxVERTICAL), 00372 *column1 = new wxBoxSizer(wxVERTICAL), 00373 *column2 = new wxBoxSizer(wxVERTICAL), 00374 *column3 = new wxBoxSizer(wxVERTICAL); 00375 00376 column1->Add( 00377 new wxStaticText(this, -1, wxT("Export as:")), 00378 0, 00379 wxALL | wxALIGN_LEFT, 00380 5); 00381 column1->Add(1, 1, 1, wxGROW); 00382 column1->Add( 00383 m_pXHTML, 00384 0, 00385 wxALL | wxALIGN_LEFT, 00386 5); 00387 column1->Add(1, 1, 1, wxGROW); 00388 column1->Add( 00389 m_pXML, 00390 0, 00391 wxALL | wxALIGN_LEFT, 00392 5); 00393 column1->Add(1, 1, 1, wxGROW); 00394 00395 00396 00397 column2->Add( 00398 new wxStaticText(this, -1, wxT("Export:")), 00399 0, 00400 wxALL | wxALIGN_LEFT, 00401 5); 00402 column2->Add(1, 1, 1, wxGROW); 00403 column2->Add( 00404 new wxRadioButton(this, IDC_EXPDLG_EVERYTHING, 00405 wxT("Everything"), wxDefaultPosition, 00406 wxSize(-1,-1), wxRB_GROUP), 00407 0, 00408 wxALL | wxALIGN_LEFT, 00409 5); 00410 column2->Add(1, 1, 1, wxGROW); 00411 column2->Add( 00412 new wxRadioButton(this, IDC_EXPDLG_SELECTION, wxT("Only selection")), 00413 0, 00414 wxALL | wxALIGN_LEFT, 00415 5); 00416 column2->Add(1, 1, 1, wxGROW); 00417 00418 00419 00420 column3->Add( 00421 new wxStaticText(this, -1, wxT("Tag preview:")), 00422 0, 00423 wxALL | wxALIGN_LEFT, 00424 5); 00425 column3->Add( 00426 m_pPreview, 00427 1, 00428 wxALL | wxGROW, 00429 5); 00430 00431 #ifdef mgEXPDLG_STILL_NOT_WORKING 00432 subadv2->Add( 00433 new wxStaticText(this, -1, wxT("Indentation step:"))), 00434 0, 00435 wxALL | wxALIGN_CENTER, 00436 5); 00437 subadv2->Add( 00438 m_pIndentation, 00439 1, 00440 wxALL | wxGROW, 00441 5); 00442 #endif 00443 00444 subadv3->Add( 00445 m_pUseNS, 00446 1, 00447 wxALL | wxALIGN_CENTER, 00448 5); 00449 subadv3->Add( 00450 m_pNS, 00451 0, 00452 wxALL | wxGROW,//ALIGN_CENTER, 00453 5); 00454 00455 // add wxT("Export as") & "Export" radio groups 00456 subadv1->Add(column1, 1, wxGROW, 0); 00457 subadv1->Add(column2, 1, wxGROW, 0); 00458 00459 // add "indentation step" 00460 subadv1container->Add(subadv1, 6, wxGROW, 0); 00461 #ifdef mgEXPDLG_STILL_NOT_WORKING 00462 subadv1container->Add(1, 1, 1, wxGROW); 00463 subadv1container->Add(subadv2, 0, wxALIGN_LEFT | wxLEFT, 5); 00464 #endif 00465 00466 // border is = 10 because other elements have subadv* borders + their own borders 00467 subadv1container->Add(1, 1, 1, wxGROW); 00468 subadv1container->Add(m_pMathPlayer, 0, wxALIGN_LEFT | wxLEFT | wxBOTTOM, 10); 00469 subadv1container->Add(m_pUpper, 0, wxALIGN_LEFT | wxLEFT, 10); 00470 00471 // add wxT("use namespace") & "namespace" field 00472 subadv1container->Add(subadv3, 0, wxALIGN_LEFT | wxLEFT | wxBOTTOM, 5); 00473 00474 // add "tag preview" 00475 adv->Add(subadv1container, 4, wxGROW, 0); 00476 adv->Add(column3, 7, wxGROW | wxLEFT, 10); 00477 00478 SetSizer(adv); 00479 adv->SetSizeHints(this); 00480 00481 // simulate user click on "use namespace" checkbox 00482 m_pUseNS->SetValue(FALSE); 00483 wxCommandEvent fake; 00484 OnUseNS(fake); 00485 00486 #ifdef mgEXPDLG_STILL_NOT_WORKING 00487 m_pIndentation->WriteText(wxT("2"); 00488 #endif 00489 } 00490 00491 int mgExportAdvOpt::GetIndentation() 00492 { 00493 long tmp; 00494 00495 // get INDENTATION 00496 #ifdef mgEXPDLG_STILL_NOT_WORKING 00497 m_pIndentation->GetValue().ToLong(&tmp, 0); 00498 #else 00499 tmp = 0; 00500 #endif 00501 00502 return tmp; 00503 } 00504 00505 00506 00507 00508 00509 // -------------------------------------------- 00510 // mgEXPORTADVOPT - event handlers 00511 // -------------------------------------------- 00512 00513 void mgExportAdvOpt::OnUseNS( wxCommandEvent &event ) 00514 { 00515 // if the "use namespace" checkbox is not checked, disable namespace field 00516 if (!m_pUseNS->GetValue()) { 00517 m_pNS->Disable(); 00518 m_pMathPlayer->SetValue(FALSE); 00519 OnMathPlayer(event); 00520 } else { 00521 m_pNS->Enable(); 00522 } 00523 00524 OnPreviewChanged(event); 00525 } 00526 00527 void mgExportAdvOpt::OnMathPlayer( wxCommandEvent &event ) 00528 { 00529 // if the "use namespace" checkbox is not checked, 00530 // disable namespace field 00531 if (m_pMathPlayer->GetValue()) { 00532 m_pUseNS->SetValue(TRUE); 00533 OnUseNS(event); 00534 00535 } else { 00536 00537 if (m_pBasic == NULL) 00538 return; 00539 00540 if (m_pBasic->m_pChoice->GetSelection() == 0) // IE + MathPlayer 00541 m_pBasic->m_pChoice->SetSelection(-1); 00542 } 00543 00544 OnPreviewChanged(event); 00545 } 00546 00547 void mgExportAdvOpt::OnPreviewChanged( wxCommandEvent &event ) 00548 { 00549 if (!m_bPreviewEnabled) 00550 return; 00551 00552 wxString title; 00553 if (m_pBasic) 00554 title = m_pBasic->m_pTitle->GetValue(); 00555 00556 // update preview textctrl 00557 m_pPreview->Clear(); 00558 m_pPreview->WriteText( 00559 m_pBox->GetExportPreview( 00560 m_pXHTML->GetValue(), 00561 title, 00562 m_pMathPlayer->GetValue(), 00563 m_pUpper->GetValue(), 00564 m_pUseNS->GetValue(), 00565 m_pNS->GetValue(), 00566 m_strXSLPath, 00567 0)); 00568 //GetIndentation())); 00569 m_pPreview->SetInsertionPoint(0); 00570 } 00571 00572 void mgExportAdvOpt::OnTypeChanged( wxCommandEvent &event ) 00573 { 00574 wxString newstr; 00575 wxString dest; 00576 00577 // update basic panel, if linked 00578 if (m_pBasic) { 00579 dest = m_pBasic->m_pDest->GetValue(); 00580 00581 if (m_pXHTML->GetValue()) { 00582 newstr = dest.BeforeLast(wxT('.')) + wxT(".xhtml"); 00583 } else { 00584 newstr = dest.BeforeLast(wxT('.')) + wxT(".xml"); 00585 } 00586 00587 // clear & retype the new destination 00588 m_pBasic->m_pDest->Clear(); 00589 m_pBasic->m_pDest->WriteText(newstr); 00590 } 00591 00592 // preview has changed 00593 OnPreviewChanged(event); 00594 } 00595 00596 00597 00598 00599 00600 00601 // -------------------------------------------- 00602 // mgEXPORTDLG 00603 // -------------------------------------------- 00604 00605 mgExportDlg::mgExportDlg(wxWindow *parent, mgMathWnd *mathwnd, mgMathBox *mathbox, 00606 const wxString &href, wxWindowID id, const wxString &title, 00607 const wxPoint &position, const wxSize& size, long style ) : 00608 // init base classes 00609 wxDialog(parent, id, title, position, size, style), 00610 mgMathBoxWndUser(mathwnd, mathbox) 00611 { 00612 wxCommandEvent fake; 00613 00614 // register associated mathbox window 00615 m_pMathWnd = mathwnd; 00616 m_pMathBox = mathbox; 00617 00618 #ifdef CEXPDLG_USE_BOLD_FONT 00619 // create a bold font to use for the main descriptions 00620 m_fBoldFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); 00621 m_fBoldFont.SetWeight(wxBOLD); 00622 #endif 00623 00624 m_bBuildComplete = FALSE; 00625 m_strXSLPath = href; 00626 00627 00628 // build everything of this dialog 00629 m_bShowAdv = FALSE; 00630 BuildAll(); 00631 m_bBuildComplete = TRUE; 00632 00633 // by default, do *not* show advanced options: they make the dialog 00634 // more complex to newbies.... 00635 m_bShowAdv = TRUE; 00636 ShowAdv(); // this sets m_bShowAdv as !m_bShowAdv and hides the adv panel 00637 00638 // init all 00639 GetBasicOpt()->OnBrowse(fake); 00640 GetAdvOpt()->EnablePreview(); 00641 GetAdvOpt()->OnPreviewChanged(fake); 00642 00643 // auto detect the system where this program is working on and select 00644 // the most appropriate browser's preset options to use... 00645 switch (wxGetOsVersion()) { 00646 00647 // for all type of windows, choose 00648 case wxWINDOWS: 00649 case wxWINDOWS_NT: 00650 case wxWIN95: 00651 case wxWIN32S: 00652 case wxWIN386: 00653 GetBasicOpt()->m_pChoice->SetSelection(0); // IE 00654 mgLogDebug(wxT("mgExportDlg::mgExportDlg() - IE settings choosen")); 00655 break; 00656 00657 // for all type of linux/unix, choose 00658 case wxGTK: 00659 case wxMOTIF_X: 00660 GetBasicOpt()->m_pChoice->SetSelection(1); // mozilla 00661 mgLogDebug(wxT("mgExportDlg::mgExportDlg() - Mozilla settings chosen")); 00662 00663 /*case wxMAC: 00664 case wxMAC_DARWIN:*/ 00665 00666 default: 00667 GetBasicOpt()->m_pChoice->SetSelection(2); // do not use preset options 00668 } 00669 00670 // notify the change of the browser set of options 00671 GetBasicOpt()->OnBrowserModeChanged(fake); 00672 } 00673 00674 mgExportDlg::~mgExportDlg() 00675 { 00676 // nothing to do... 00677 } 00678 00679 00680 00681 wxSizer *mgExportDlg::BuildButtons() 00682 { 00684 // add BUTTONS 00685 wxBoxSizer *bttn = new wxBoxSizer(wxHORIZONTAL); 00686 bttn->Add( 00687 new wxButton(this, wxID_CANCEL, wxT("Cancel")), 00688 1, 00689 wxALL | wxGROW, 00690 10); 00691 bttn->Add( 00692 new wxButton(this, IDC_EXPDLG_EXPORT, wxT("Export only")), 00693 1, 00694 wxALL | wxGROW, 00695 10); 00696 bttn->Add( 00697 new wxButton(this, IDC_EXPDLG_EXPORT_AND_OPEN, 00698 wxT("Export and open\nin default browser"), 00699 wxDefaultPosition, wxSize(1, 40)), // if we do not specify size, 00700 1, // button calculates its width as if 00701 wxALL | wxGROW, // the label is single-line !!! 00702 10); 00703 00704 return bttn; 00705 } 00706 00707 void mgExportDlg::BuildCtrls() 00708 { 00709 // everything is built in the BASIC and ADVANCED panel windows... 00710 // here, we just have to build those panels.... 00711 m_pBasicOptPanel = new mgExportBasicOpt(this); 00712 m_pAdvOptPanel = new mgExportAdvOpt(this, m_pBasicOptPanel, 00713 GetBox(), m_strXSLPath, -1); 00714 00715 // now we can link the basic panel with the advanced one... 00716 GetBasicOpt()->SetAdvPanel(GetAdvOpt()); 00717 00718 // build everything inside the panels 00719 GetBasicOpt()->BuildAll(); 00720 GetAdvOpt()->BuildAll(); 00721 } 00722 00723 void mgExportDlg::BuildAll() 00724 { 00725 m_pMainPanel = new wxBoxSizer(wxVERTICAL); 00726 00728 // insert DESCRIPTION 00729 wxStaticText *hdr = new wxStaticText(this, -1, 00730 wxT("This dialog allows you to export as MathML 2.0 the document ") 00731 wxT("you have created with MathStudio.\n"), wxDefaultPosition, 00732 wxDefaultSize, wxALIGN_CENTRE), 00733 00734 *description = new wxStaticText(this, -1, 00735 wxT("The goal of MathML is to enable mathematics to be served, ") 00736 wxT("received,\nand processed on the World Wide Web, ") 00737 wxT("just as HTML has enabled this functionality ") 00738 wxT("for text.\nMathML is an XML extension and thus MathML can ") 00739 wxT("be saved in two different\nformats: pure XML or XHTML. ") 00740 wxT("XHTML is a flexible and powerful mix of HTML and XML which\n") 00741 wxT("allows you to embed math && formatted text in the same document.") 00742 wxT("\nThis is why it should be your preferred choice.\n"), wxDefaultPosition, 00743 wxDefaultSize, wxALIGN_CENTRE); 00744 00745 #ifdef CEXPDLG_USE_BOLD_FONT 00746 hdr->SetFont(m_fBoldFont); 00747 description->SetFont(m_fBoldFont); 00748 #endif 00749 00750 m_pMainPanel->Add( 00751 hdr, 00752 0, // make horizontally unstretchable 00753 wxLEFT | wxRIGHT | wxTOP | wxALIGN_CENTER, // center it & user borders 00754 10); 00755 00756 m_pMainPanel->Add( 00757 description, 00758 0, // make horizontally unstretchable 00759 wxLEFT | wxRIGHT | wxALIGN_CENTER, // center it & user borders 00760 10); 00761 00762 // create all main controls of the dialog... 00763 BuildCtrls(); 00764 00765 // add BASIC & ADVANCED OPTIONS & BUTTONS sizer to the main one 00766 m_pMainPanel->Add(m_pBasicOptPanel, 2, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 10); 00767 00768 // here the advanced sizer is ALWAYS added to the main panel; this avoids 00769 // problems with the controls which have been created for the advanced 00770 // panel; if you want it hidden, call the OnShowAdv() function 00771 m_pMainPanel->Add(m_pAdvOptPanel, 3, wxGROW | wxALL, 10); 00772 00773 m_pButtonsPanel = BuildButtons(); 00774 m_pMainPanel->Add(m_pButtonsPanel, 1, wxGROW, 10); 00775 00776 // set up global sizer 00777 SetSizer(m_pMainPanel); // use the sizer for layout 00778 m_pMainPanel->SetSizeHints(this); // set size hints to honour minimum size 00779 00780 00781 // set up destionation file name & XHTML/XML's title 00782 wxString separator = wxFileName::GetPathSeparator(); 00783 GetBasicOpt()->m_pDest->WriteText(wxGetCwd() + separator + 00784 wxT("Untitled document.html")); 00785 00786 wxString tmp = GetBasicOpt()->m_pDest->GetValue().BeforeLast(wxT('.')); 00787 GetBasicOpt()->m_pTitle->WriteText( 00788 tmp.AfterLast(separator.GetChar(0))); 00789 00790 // center the dialog 00791 this->CentreOnScreen(); 00792 } 00793 00794 00795 00796 00798 // BUTTON EVENT HANDLERS 00799 00800 void mgExportDlg::OnExport( wxCommandEvent &event ) 00801 { 00802 GetBox()->Export( 00803 GetAdvOpt()->m_pXHTML->GetValue(), GetBasicOpt()->m_pDest->GetValue(), 00804 GetBasicOpt()->m_pTitle->GetValue(), GetAdvOpt()->m_pMathPlayer->GetValue(), 00805 GetAdvOpt()->m_pUpper->GetValue(), 00806 GetAdvOpt()->m_pUseNS->GetValue(), 00807 GetAdvOpt()->m_pNS->GetValue(), m_strXSLPath, 00808 GetAdvOpt()->GetIndentation()); 00809 EndModal(wxOK); 00810 } 00811 00812 void mgExportDlg::OnExportAndOpen( wxCommandEvent &event ) 00813 { 00814 m_pMathBox->Export( 00815 GetAdvOpt()->m_pXHTML->GetValue(), GetBasicOpt()->m_pDest->GetValue(), 00816 GetBasicOpt()->m_pTitle->GetValue(), GetAdvOpt()->m_pMathPlayer->GetValue(), 00817 GetAdvOpt()->m_pUpper->GetValue(), 00818 GetAdvOpt()->m_pUseNS->GetValue(), 00819 GetAdvOpt()->m_pNS->GetValue(), m_strXSLPath, 00820 GetAdvOpt()->GetIndentation()); 00821 wxViewHTMLFile(GetBasicOpt()->m_pDest->GetValue()); 00822 EndModal(wxOK); 00823 } 00824 00825 /* 00826 void ChangeOptionOf(wxSizer *s, wxSizer *tochange, int n) 00827 { 00828 // OPTION = PROPORTION 00829 00830 wxNode *node = s->GetChildren().First(); 00831 while (node) 00832 { 00833 wxSizerItem *item = (wxSizerItem*)node->Data(); 00834 if (item->GetSizer() == tochange) 00835 { 00836 item->SetOption(n); 00837 break; 00838 } 00839 node = node->Next(); 00840 } 00841 } 00842 */ 00843 void mgExportDlg::ShowAdv() 00844 { 00845 // change flag & button's state 00846 m_bShowAdv = !m_bShowAdv; 00847 00848 if (m_bShowAdv) { 00849 00850 // show the advanced panel 00851 m_pAdvOptPanel->Show(); 00852 m_pMainPanel->Show(m_pAdvOptPanel); 00853 m_pMainPanel->Layout(); 00854 //m_pAdvOptPanel->GetStaticBox()->Show(); 00855 00856 } else { 00857 00858 // hide the advanced panel 00859 m_pAdvOptPanel->Hide(); 00860 m_pMainPanel->Hide(m_pAdvOptPanel); 00861 /*m_pAdvOptPanel->GetStaticBox()->Hide(); 00862 m_pAdvOptPanel->SetDimension(0, 0, 0, 0);*/ 00863 this->SetSize(-1, -1, 0, 0); 00864 m_pMainPanel->Layout(); 00865 //m_pButtonsPanel->Layout(); 00866 //m_pMainPanel->SetSizeHints(this); 00867 //SetSize(m_pMainPanel->GetMinSize()); 00868 //m_pAdvOptPanel 00869 00870 //ChangeOptionOf(m_pMainPanel, m_pAdvOptPanel, 1); 00871 //m_pMainPanel->Remove(m_pAdvOptPanel); 00872 00873 //ChangeOptionOf(m_pMainPanel, m_pBasicOptPanel, 2); 00874 //ChangeOptionOf(m_pMainPanel, m_pButtonsPanel, 1); 00875 } 00876 00877 // this is VERY IMPORTANT to resize the dialog !!! 00878 m_pMainPanel->SetSizeHints(this); 00879 this->SetSize(-1, -1, 0, 0); 00880 //this->CentreOnScreen(); 00881 Refresh(); 00882 } 00883 00884 00885 00886 00887 00889 // MISCELLANEOUS EVENT HANDLERS 00890 00891 00892 00894 // HELPER FUNCTIONS (NOT EVENT-HANDLERS) 00895 00896 00897 00898 00899 00900
[ Top ] |