X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3a5bcc4db0851bf8cd3063917511b0b17c7f9679..e18c3e02072753d45643316005bfd022a9d3d7cd:/utils/tex2rtf/src/tex2rtf.cpp diff --git a/utils/tex2rtf/src/tex2rtf.cpp b/utils/tex2rtf/src/tex2rtf.cpp index 464dc6656e..83b624cab4 100644 --- a/utils/tex2rtf/src/tex2rtf.cpp +++ b/utils/tex2rtf/src/tex2rtf.cpp @@ -27,13 +27,21 @@ #include "wx/textctrl.h" #include "wx/filedlg.h" #include "wx/msgdlg.h" + #include "wx/icon.h" #endif #endif #ifndef NO_GUI -#include "wx/help.h" -#include "wx/timer.h" -#endif + #include "wx/timer.h" + #include "wx/help.h" + #include "wx/cshelp.h" + #include "wx/helphtml.h" + #ifdef __WXMSW__ + #include "wx/msw/helpchm.h" + #else + #include "wx/html/helpctrl.h" + #endif +#endif // !NO_GUI #if wxUSE_IOSTREAMH #include @@ -59,7 +67,7 @@ static inline wxChar* copystring(const wxChar* s) { return wxStrcpy(new wxChar[wxStrlen(s) + 1], s); } #endif -const float versionNo = TEX2RTF_VERSION_NUMBER; +const float versionNo = float(TEX2RTF_VERSION_NUMBER); TexChunk *currentMember = NULL; bool startedSections = false; @@ -78,18 +86,17 @@ extern wxChar *TexTmpBibName; // Temporary bibliography output file name extern wxList ColourTable; extern TexChunk *TopLevel; - - #if wxUSE_HELP -wxHelpController *HelpInstance = NULL; +wxHelpControllerBase *HelpInstance = NULL; #endif // wxUSE_HELP #ifdef __WXMSW__ static wxChar *ipc_buffer = NULL; static wxChar Tex2RTFLastStatus[100]; Tex2RTFServer *TheTex2RTFServer = NULL; -#endif -#endif +#endif // __WXMSW__ + +#endif // !NO_GUI wxChar *bulletFile = NULL; @@ -148,7 +155,7 @@ bool MyApp::OnInit() WinHelpContentsFileName = new wxChar[300]; RefFileName = new wxChar[300]; - ColourTable.DeleteContents(true); + WX_CLEAR_LIST(wxList,ColourTable); int n = 1; @@ -263,10 +270,17 @@ bool MyApp::OnInit() } } } + else if (wxStrcmp(argv[i], _T("-checkcurlybraces")) == 0) + { + i ++; + checkCurlyBraces = true; + } else if (wxStrcmp(argv[i], _T("-checkcurleybraces")) == 0) { + // Support the old, incorrectly spelled version of -checkcurlybraces + // so that old scripts which run tex2rtf -checkcurleybraces still work. i ++; - checkCurleyBraces = true; + checkCurlyBraces = true; } else if (wxStrcmp(argv[i], _T("-checksyntax")) == 0) { @@ -281,8 +295,9 @@ bool MyApp::OnInit() #ifdef NO_GUI ShowOptions(); exit(1); -#endif +#else return false; +#endif } } @@ -304,7 +319,9 @@ bool MyApp::OnInit() // Create the main frame window frame = new MyFrame(NULL, wxID_ANY, _T("Tex2RTF"), wxDefaultPosition, wxSize(400, 300)); +#if wxUSE_STATUSBAR frame->CreateStatusBar(2); +#endif // wxUSE_STATUSBAR // Give it an icon // TODO: uncomment this when we have tex2rtf.xpm @@ -342,10 +359,10 @@ bool MyApp::OnInit() wxMenu *options_menu = new wxMenu; - options_menu->Append(TEX_OPTIONS_CURELY_BRACE, _T("Curley brace matching"), _T("Checks for mismatched curley braces"),true); + options_menu->Append(TEX_OPTIONS_CURLY_BRACE, _T("Curly brace matching"), _T("Checks for mismatched curly braces"),true); options_menu->Append(TEX_OPTIONS_SYNTAX_CHECKING, _T("Syntax checking"), _T("Syntax checking for common errors"),true); - options_menu->Check(TEX_OPTIONS_CURELY_BRACE, checkCurleyBraces); + options_menu->Check(TEX_OPTIONS_CURLY_BRACE, checkCurlyBraces); options_menu->Check(TEX_OPTIONS_SYNTAX_CHECKING, checkSyntax); wxMenu *help_menu = new wxMenu; @@ -367,7 +384,11 @@ bool MyApp::OnInit() // ShowOptions(); #if wxUSE_HELP - HelpInstance = new wxHelpController(); +#if wxUSE_MS_HTML_HELP && !defined(__WXUNIVERSAL__) + HelpInstance = new wxCHMHelpController; +#else + HelpInstance = new wxHtmlHelpController; +#endif HelpInstance->Initialize(_T("tex2rtf")); #endif // wxUSE_HELP @@ -377,19 +398,29 @@ bool MyApp::OnInit() */ wxString path = TexPathList.FindValidPath(MacroFile); - if (path != _T("")) + if (!path.empty()) ReadCustomMacros((wxChar *)path.c_str()); +#if wxUSE_STATUSBAR wxStrcpy(buf, _T("In ")); - - if (winHelp && (convertMode == TEX_RTF)) - wxStrcat(buf, _T("WinHelp RTF")); - else if (!winHelp && (convertMode == TEX_RTF)) - wxStrcat(buf, _T("linear RTF")); - else if (convertMode == TEX_HTML) wxStrcat(buf, _T("HTML")); - else if (convertMode == TEX_XLP) wxStrcat(buf, _T("XLP")); - wxStrcat(buf, _T(" mode.")); + switch (convertMode) + { + case TEX_RTF: + wxStrcat(buf, (winHelp) ? _T("WinHelp RTF") : _T("linear RTF")); + break; + case TEX_HTML: + wxStrcat(buf, _T("HTML")); + break; + case TEX_XLP: + wxStrcat(buf, _T("XLP")); + break; + default: + wxStrcat(buf, _T("unknown")); + break; + } + wxStrcat(buf, _T(" mode.")); frame->SetStatusText(buf, 1); +#endif // wxUSE_STATUSBAR frame->Show(true); return true; @@ -403,11 +434,11 @@ bool MyApp::OnInit() */ wxString path = TexPathList.FindValidPath(MacroFile); - if (path != _T("")) + if (!path.empty()) ReadCustomMacros((wxChar*)path.c_str()); Go(); - if (runTwice) + if (runTwice) { Go(); } @@ -432,12 +463,12 @@ int MyApp::OnExit() node = CustomMacroList.GetFirst(); } MacroDefs.BeginFind(); - node = MacroDefs.Next(); - while (node) + wxHashTable::Node* mNode = MacroDefs.Next(); + while (mNode) { - TexMacroDef* def = (TexMacroDef*) node->GetData(); + TexMacroDef* def = (TexMacroDef*) mNode->GetData(); delete def; - node = MacroDefs.Next(); + mNode = MacroDefs.Next(); } MacroDefs.Clear(); #ifdef __WXMSW__ @@ -567,7 +598,7 @@ void ShowOptions(void) OnInform(_T(" -charset (default ansi)")); OnInform(_T(" -twice")); OnInform(_T(" -sync")); - OnInform(_T(" -checkcurleybraces")); + OnInform(_T(" -checkcurlybraces")); OnInform(_T(" -checksyntax")); OnInform(_T(" -macros ")); OnInform(_T(" -winhelp")); @@ -593,7 +624,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(TEX_MODE_WINHELP, MyFrame::OnModeWinHelp) EVT_MENU(TEX_MODE_HTML, MyFrame::OnModeHTML) EVT_MENU(TEX_MODE_XLP, MyFrame::OnModeXLP) - EVT_MENU(TEX_OPTIONS_CURELY_BRACE, MyFrame::OnOptionsCurleyBrace) + EVT_MENU(TEX_OPTIONS_CURLY_BRACE, MyFrame::OnOptionsCurlyBrace) EVT_MENU(TEX_OPTIONS_SYNTAX_CHECKING, MyFrame::OnOptionsSyntaxChecking) EVT_MENU(TEX_HELP, MyFrame::OnHelp) EVT_MENU(TEX_ABOUT, MyFrame::OnAbout) @@ -638,7 +669,9 @@ void MyFrame::OnGo(wxCommandEvent& WXUNUSED(event)) if (stopRunning) { +#if wxUSE_STATUSBAR SetStatusText(_T("Build aborted!")); +#endif // wxUSE_STATUSBAR wxString errBuf; errBuf.Printf(_T("\nErrors encountered during this pass: %lu\n"), errorCount); OnInform((wxChar *)errBuf.c_str()); @@ -672,9 +705,11 @@ void MyFrame::OnSaveFile(wxCommandEvent& WXUNUSED(event)) if (s != _T("")) { textWindow->SaveFile(s); +#if wxUSE_STATUSBAR wxChar buf[350]; wxSnprintf(buf, sizeof(buf), _T("Saved text to %s"), (const wxChar*) s.c_str()); frame->SetStatusText(buf, 0); +#endif // wxUSE_STATUSBAR } } @@ -708,7 +743,7 @@ void MyFrame::OnLoadMacros(wxCommandEvent& WXUNUSED(event)) { textWindow->Clear(); wxString s = wxFileSelector(_T("Choose custom macro file"), wxPathOnly(MacroFile), wxFileNameFromPath(MacroFile), _T("ini"), _T("*.ini")); - if (s != _T("") && wxFileExists(s)) + if (!s.empty() && wxFileExists(s)) { MacroFile = copystring(s); ReadCustomMacros((wxChar *)s.c_str()); @@ -729,7 +764,9 @@ void MyFrame::OnModeRTF(wxCommandEvent& WXUNUSED(event)) winHelp = false; InputFile = NULL; OutputFile = NULL; +#if wxUSE_STATUSBAR SetStatusText(_T("In linear RTF mode."), 1); +#endif // wxUSE_STATUSBAR } void MyFrame::OnModeWinHelp(wxCommandEvent& WXUNUSED(event)) @@ -738,7 +775,9 @@ void MyFrame::OnModeWinHelp(wxCommandEvent& WXUNUSED(event)) winHelp = true; InputFile = NULL; OutputFile = NULL; +#if wxUSE_STATUSBAR SetStatusText(_T("In WinHelp RTF mode."), 1); +#endif // wxUSE_STATUSBAR } void MyFrame::OnModeHTML(wxCommandEvent& WXUNUSED(event)) @@ -747,7 +786,9 @@ void MyFrame::OnModeHTML(wxCommandEvent& WXUNUSED(event)) winHelp = false; InputFile = NULL; OutputFile = NULL; +#if wxUSE_STATUSBAR SetStatusText(_T("In HTML mode."), 1); +#endif // wxUSE_STATUSBAR } void MyFrame::OnModeXLP(wxCommandEvent& WXUNUSED(event)) @@ -755,26 +796,31 @@ void MyFrame::OnModeXLP(wxCommandEvent& WXUNUSED(event)) convertMode = TEX_XLP; InputFile = NULL; OutputFile = NULL; +#if wxUSE_STATUSBAR SetStatusText(_T("In XLP mode."), 1); +#endif // wxUSE_STATUSBAR } -void MyFrame::OnOptionsCurleyBrace(wxCommandEvent& WXUNUSED(event)) +void MyFrame::OnOptionsCurlyBrace(wxCommandEvent& WXUNUSED(event)) { - checkCurleyBraces = !checkCurleyBraces; - if (checkCurleyBraces) + checkCurlyBraces = !checkCurlyBraces; +#if wxUSE_STATUSBAR + if (checkCurlyBraces) { - SetStatusText(_T("Checking curley braces: YES"), 1); + SetStatusText(_T("Checking curly braces: YES"), 1); } else { - SetStatusText(_T("Checking curley braces: NO"), 1); + SetStatusText(_T("Checking curly braces: NO"), 1); } +#endif // wxUSE_STATUSBAR } void MyFrame::OnOptionsSyntaxChecking(wxCommandEvent& WXUNUSED(event)) { checkSyntax = !checkSyntax; +#if wxUSE_STATUSBAR if (checkSyntax) { SetStatusText(_T("Checking syntax: YES"), 1); @@ -783,6 +829,7 @@ void MyFrame::OnOptionsSyntaxChecking(wxCommandEvent& WXUNUSED(event)) { SetStatusText(_T("Checking syntax: NO"), 1); } +#endif // wxUSE_STATUSBAR } @@ -815,7 +862,7 @@ void ChooseInputFile(bool force) if (force || !InputFile) { wxString s = wxFileSelector(_T("Choose LaTeX input file"), wxPathOnly(InputFile), wxFileNameFromPath(InputFile), _T("tex"), _T("*.tex")); - if (s != _T("")) + if (!s.empty()) { // Different file, so clear index entries. ClearKeyWordTable(); @@ -869,7 +916,7 @@ void ChooseOutputFile(bool force) { wxString s = wxFileSelector(_T("Choose output file"), path, wxFileNameFromPath(OutputFile), extensionBuf, wildBuf); - if (s != _T("")) + if (!s.empty()) OutputFile = copystring(s); } } @@ -924,7 +971,7 @@ bool Go(void) if (!bulletFile) { wxString s = TexPathList.FindValidPath(_T("bullet.bmp")); - if (s != _T("")) + if (!s.empty()) { wxString str = wxFileNameFromPath(s); bulletFile = copystring(str); @@ -944,7 +991,7 @@ bool Go(void) TexCleanUp(); return false; } -#ifndef NO_GUI +#if !defined(NO_GUI) && wxUSE_STATUSBAR if (isInteractive) { wxString buf; @@ -1007,11 +1054,13 @@ bool Go(void) OnInform((wxChar *)buf.c_str()); } +#if wxUSE_STATUSBAR if (isInteractive) { buf.Printf(_T("Done, %d %s."), passNumber, (passNumber > 1) ? _T("passes") : _T("pass")); frame->SetStatusText((wxChar *)buf.c_str()); } +#endif // wxUSE_STATUSBAR #else buf.Printf(_T("Done, %d %s."), passNumber, (passNumber > 1) ? _T("passes") : _T("pass")); OnInform((wxChar *)buf.c_str()); @@ -1030,7 +1079,7 @@ bool Go(void) TexCleanUp(); startedSections = false; -#ifndef NO_GUI +#if !defined(NO_GUI) && wxUSE_STATUSBAR frame->SetStatusText(_T("Aborted by user.")); #endif // GUI @@ -1076,9 +1125,9 @@ void OnInform(const wxChar *msg) (*frame->textWindow) << msg << _T("\n"); /* This whole block of code is just wrong I think. It would behave completely wrong under anything other than MSW due to the ELSE - with no statement, and the cout calls would fail under MSW, as - the code in this block is compiled if !NO_GUI This code has been - here since v1.1 of this file too. - gt + with no statement, and the cout calls would fail under MSW, as + the code in this block is compiled if !NO_GUI This code has been + here since v1.1 of this file too. - gt else #ifdef __WXMSW__ { @@ -1172,10 +1221,6 @@ Tex2RTFConnection::Tex2RTFConnection(wxChar *buf, int size):wxDDEConnection(buf, { } -Tex2RTFConnection::~Tex2RTFConnection(void) -{ -} - bool SplitCommand(wxChar *data, wxChar *firstArg, wxChar *secondArg) { firstArg[0] = 0; @@ -1265,7 +1310,7 @@ bool Tex2RTFConnection::OnExecute(const wxString& WXUNUSED(topic), wxChar *data, { // Try for a setting wxStrcpy(Tex2RTFLastStatus, RegisterSetting(firstArg, secondArg, false)); -#ifndef NO_GUI +#if !defined(NO_GUI) && wxUSE_STATUSBAR if (frame && wxStrcmp(firstArg, _T("conversionMode")) == 0) { wxChar buf[100];