⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tex2rtf.cpp

📁 Wxpython Implemented on Windows CE, Source code
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    }
#ifdef NO_GUI
    return true;
#else
    OnExit(); // Do cleanup since OnExit won't be called now
    return false;
#endif
  }
}

#ifndef NO_GUI
int MyApp::OnExit()
{
  wxNode *node = CustomMacroList.GetFirst();
  while (node)
  {
    CustomMacro *macro = (CustomMacro *)node->GetData();
    delete macro;
    delete node;
    node = CustomMacroList.GetFirst();
  }
  MacroDefs.BeginFind();
  wxHashTable::Node* mNode = MacroDefs.Next();
  while (mNode)
  {
    TexMacroDef* def = (TexMacroDef*) mNode->GetData();
    delete def;
    mNode = MacroDefs.Next();
  }
  MacroDefs.Clear();
#ifdef __WXMSW__
  delete TheTex2RTFServer;
  wxDDECleanUp();
#endif

#if wxUSE_HELP
  delete HelpInstance;
#endif // wxUSE_HELP

    if (BigBuffer)
    {
      delete BigBuffer;
      BigBuffer = NULL;
    }
    if (currentArgData)
    {
      delete currentArgData;
      currentArgData = NULL;
    }
    if (TexFileRoot)
    {
      delete TexFileRoot;
      TexFileRoot = NULL;
    }
    if (TexBibName)
    {
      delete TexBibName;
      TexBibName = NULL;
    }
    if (TexTmpBibName)
    {
      delete TexTmpBibName;
      TexTmpBibName = NULL;
    }
    if (FileRoot)
    {
      delete FileRoot;
      FileRoot = NULL;
    }
    if (ContentsName)
    {
      delete ContentsName;
      ContentsName = NULL;
    }
    if (TmpContentsName)
    {
      delete TmpContentsName;
      TmpContentsName = NULL;
    }
    if (TmpFrameContentsName)
    {
      delete TmpFrameContentsName;
      TmpFrameContentsName = NULL;
    }
    if (WinHelpContentsFileName)
    {
      delete WinHelpContentsFileName;
      WinHelpContentsFileName = NULL;
    }
    if (RefFileName)
    {
      delete RefFileName;
      RefFileName = NULL;
    }
    if (TopLevel)
    {
      delete TopLevel;
      TopLevel = NULL;
    }
    if (MacroFile)
    {
      delete MacroFile;
      MacroFile = NULL;
    }
    if (RTFCharset)
    {
      delete RTFCharset;
      RTFCharset = NULL;
    }

    delete [] PageStyle;
    delete [] BibliographyStyleString;
    delete [] DocumentStyleString;
    delete [] bitmapMethod;
    delete [] backgroundColourString;
    delete [] ContentsNameString;
    delete [] AbstractNameString;
    delete [] GlossaryNameString;
    delete [] ReferencesNameString;
    delete [] FiguresNameString;
    delete [] TablesNameString;
    delete [] FigureNameString;
    delete [] TableNameString;
    delete [] IndexNameString;
    delete [] ChapterNameString;
    delete [] SectionNameString;
    delete [] SubsectionNameString;
    delete [] SubsubsectionNameString;
    delete [] UpNameString;
    if (winHelpTitle)
      delete[] winHelpTitle;

  // TODO: this simulates zero-memory leaks!
  // Otherwise there are just too many...
#ifndef __WXGTK__
#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
  wxDebugContext::SetCheckpoint();
#endif
#endif

  return 0;
}
#endif
void ShowOptions(void)
{
    wxChar buf[100];
    wxSnprintf(buf, sizeof(buf), _T("Tex2RTF version %.2f"), versionNo);
    OnInform(buf);
    OnInform(_T("Usage: tex2rtf [input] [output] [switches]\n"));
    OnInform(_T("where valid switches are"));
#ifndef NO_GUI
    OnInform(_T("    -interactive"));
#endif
    OnInform(_T("    -bufsize <size in K>"));
    OnInform(_T("    -charset <pc | pca | ansi | mac> (default ansi)"));
    OnInform(_T("    -twice"));
    OnInform(_T("    -sync"));
    OnInform(_T("    -checkcurlybraces"));
    OnInform(_T("    -checksyntax"));
    OnInform(_T("    -macros <filename>"));
    OnInform(_T("    -winhelp"));
    OnInform(_T("    -rtf"));
    OnInform(_T("    -html"));
    OnInform(_T("    -xlp\n"));
}

#ifndef NO_GUI

BEGIN_EVENT_TABLE(MyFrame, wxFrame)
    EVT_CLOSE(MyFrame::OnCloseWindow)
    EVT_MENU(TEX_QUIT, MyFrame::OnExit)
    EVT_MENU(TEX_GO, MyFrame::OnGo)
    EVT_MENU(TEX_SET_INPUT, MyFrame::OnSetInput)
    EVT_MENU(TEX_SET_OUTPUT, MyFrame::OnSetOutput)
    EVT_MENU(TEX_SAVE_FILE, MyFrame::OnSaveFile)
    EVT_MENU(TEX_VIEW_LATEX, MyFrame::OnViewLatex)
    EVT_MENU(TEX_VIEW_OUTPUT, MyFrame::OnViewOutput)
    EVT_MENU(TEX_VIEW_CUSTOM_MACROS, MyFrame::OnShowMacros)
    EVT_MENU(TEX_LOAD_CUSTOM_MACROS, MyFrame::OnLoadMacros)
    EVT_MENU(TEX_MODE_RTF, MyFrame::OnModeRTF)
    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_CURLY_BRACE, MyFrame::OnOptionsCurlyBrace)
    EVT_MENU(TEX_OPTIONS_SYNTAX_CHECKING, MyFrame::OnOptionsSyntaxChecking)
    EVT_MENU(TEX_HELP, MyFrame::OnHelp)
    EVT_MENU(TEX_ABOUT, MyFrame::OnAbout)
END_EVENT_TABLE()

// My frame constructor
MyFrame::MyFrame(wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size):
  wxFrame(frame, id, title, pos, size)
{}

void MyFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
{
  if (!stopRunning && !OkToClose)
  {
    stopRunning = true;
    runTwice = false;
    return;
  }
  else if (OkToClose)
  {
    this->Destroy();
  }
}

void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event))
{
  Close();
//    this->Destroy();
}

void MyFrame::OnGo(wxCommandEvent& WXUNUSED(event))
{
      passNumber = 1;
      errorCount = 0;
      menuBar->EnableTop(0, false);
      menuBar->EnableTop(1, false);
      menuBar->EnableTop(2, false);
      menuBar->EnableTop(3, false);
      textWindow->Clear();
      Tex2RTFYield(true);
      Go();

      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());
      }


      if (runTwice && !stopRunning)
      {
        Tex2RTFYield(true);
        Go();
      }
      menuBar->EnableTop(0, true);
      menuBar->EnableTop(1, true);
      menuBar->EnableTop(2, true);
      menuBar->EnableTop(3, true);
}

void MyFrame::OnSetInput(wxCommandEvent& WXUNUSED(event))
{
      ChooseInputFile(true);
}

void MyFrame::OnSetOutput(wxCommandEvent& WXUNUSED(event))
{
      ChooseOutputFile(true);
}

void MyFrame::OnSaveFile(wxCommandEvent& WXUNUSED(event))
{
#if wxUSE_FILEDLG
    wxString s = wxFileSelector(_T("Save text to file"), wxEmptyString, wxEmptyString, _T("txt"), _T("*.txt"));
    if (!s.empty())
    {
        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
    }
#endif // wxUSE_FILEDLG
}

void MyFrame::OnViewOutput(wxCommandEvent& WXUNUSED(event))
{
    ChooseOutputFile();
    if (!OutputFile.empty() && wxFileExists(OutputFile))
    {
        textWindow->LoadFile(OutputFile);
        wxChar buf[300];
        wxString str(wxFileNameFromPath(OutputFile));
        wxSnprintf(buf, sizeof(buf), _T("Tex2RTF [%s]"), (const wxChar*) str.c_str());
        frame->SetTitle(buf);
    }
}

void MyFrame::OnViewLatex(wxCommandEvent& WXUNUSED(event))
{
    ChooseInputFile();
    if (!InputFile.empty() && wxFileExists(InputFile))
    {
        textWindow->LoadFile(InputFile);
        wxChar buf[300];
        wxString str(wxFileNameFromPath(OutputFile));
        wxSnprintf(buf, sizeof(buf), _T("Tex2RTF [%s]"), (const wxChar*) str.c_str());
        frame->SetTitle(buf);
    }
}

void MyFrame::OnLoadMacros(wxCommandEvent& WXUNUSED(event))
{
    textWindow->Clear();
#if wxUSE_FILEDLG
    wxString s = wxFileSelector(_T("Choose custom macro file"), wxPathOnly(MacroFile), wxFileNameFromPath(MacroFile), _T("ini"), _T("*.ini"));
    if (!s.empty() && wxFileExists(s))
    {
        MacroFile = copystring(s);
        ReadCustomMacros(s);
        ShowCustomMacros();
    }
#endif // wxUSE_FILEDLG
}

void MyFrame::OnShowMacros(wxCommandEvent& WXUNUSED(event))
{
    textWindow->Clear();
    Tex2RTFYield(true);
    ShowCustomMacros();
}

void MyFrame::OnModeRTF(wxCommandEvent& WXUNUSED(event))
{
    convertMode = TEX_RTF;
    winHelp = false;
    InputFile = wxEmptyString;
    OutputFile = wxEmptyString;
#if wxUSE_STATUSBAR
    SetStatusText(_T("In linear RTF mode."), 1);
#endif // wxUSE_STATUSBAR
}

void MyFrame::OnModeWinHelp(wxCommandEvent& WXUNUSED(event))
{
    convertMode = TEX_RTF;
    winHelp = true;
    InputFile = wxEmptyString;
    OutputFile = wxEmptyString;
#if wxUSE_STATUSBAR
    SetStatusText(_T("In WinHelp RTF mode."), 1);
#endif // wxUSE_STATUSBAR
}

void MyFrame::OnModeHTML(wxCommandEvent& WXUNUSED(event))
{
    convertMode = TEX_HTML;
    winHelp = false;
    InputFile = wxEmptyString;
    OutputFile = wxEmptyString;
#if wxUSE_STATUSBAR
    SetStatusText(_T("In HTML mode."), 1);
#endif // wxUSE_STATUSBAR
}

void MyFrame::OnModeXLP(wxCommandEvent& WXUNUSED(event))
{
    convertMode = TEX_XLP;
    InputFile = wxEmptyString;
    OutputFile = wxEmptyString;
#if wxUSE_STATUSBAR
    SetStatusText(_T("In XLP mode."), 1);
#endif // wxUSE_STATUSBAR
}

void MyFrame::OnOptionsCurlyBrace(wxCommandEvent& WXUNUSED(event))
{
    checkCurlyBraces = !checkCurlyBraces;
#if wxUSE_STATUSBAR
    if (checkCurlyBraces)
    {
        SetStatusText(_T("Checking curly braces: YES"), 1);
    }
    else
    {
        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);
    }
    else
    {
        SetStatusText(_T("Checking syntax: NO"), 1);
    }
#endif // wxUSE_STATUSBAR
}


void MyFrame::OnHelp(wxCommandEvent& WXUNUSED(event))
{
#if wxUSE_HELP
      HelpInstance->LoadFile();
      HelpInstance->DisplayContents();
#endif // wxUSE_HELP
}

void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
      wxChar buf[300];
      wxString platform = wxGetOsDescription();
      wxSnprintf(buf, sizeof(buf), _T("Tex2RTF Version %.2f %s\nLaTeX to RTF, WinHelp, and HTML Conversion\n\n(c) Julian Smart, George Tasker and others, 1999-2005"), versionNo, platform.c_str());
      wxMessageBox(buf, _T("About Tex2RTF"));
}

void ChooseInputFile(bool force)
{
#if wxUSE_FILEDLG
    if (force || InputFile.empty())
    {
        wxString s = wxFileSelector(_T("Choose LaTeX input file"), wxPathOnly(InputFile), wxFileNameFromPath(InputFile), _T("tex"), _T("*.tex"));
        if (!s.empty())
        {
            // Different file, so clear index entries.
            ClearKeyWordTable();
            ResetContentsLevels(0);
            passNumber = 1;
            errorCount = 0;

            InputFile = s;
            wxString str = wxFileNameFromPath(InputFile);
            wxString buf;
            buf.Printf(_T("Tex2RTF [%s]"), str.c_str());
            frame->SetTitle((wxChar *)buf.c_str());
            OutputFile = wxEmptyString;
        }
    }
#else
    wxUnusedVar(force);
#endif // wxUSE_FILEDLG
}

void ChooseOutputFile(bool force)
{
    wxChar extensionBuf[10];
    wxChar wildBuf[10];
    wxStrcpy(wildBuf, _T("*."));
    wxString path;
    if (!OutputFile.empty())
        path = wxPathOnly(OutputFile);
    else if (!InputFile.empty())
        path = wxPathOnly(InputFile);

    switch (convertMode)
    {
        case TEX_RTF:
        {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -