Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

ww2rtf.cpp

Go to the documentation of this file.
00001 //**********************************************************************
00002 //                                                                     *
00003 //    Filename:      ww2rtf.cpp                                        *
00004 //    Date:          16 Feb 2002                                       *
00005 //    File Version:  1                                                 *
00006 //                                                                     *
00007 //    Author:        Chris White (whitecf@bcs.org.uk)                  *
00008 //    Company:       Monitor Computing Services Ltd.                   *
00009 //                                                                     *
00010 //**********************************************************************
00011 //                                                                     *
00012 //    Copyright (C) 2002  Monitor Computing Services Ltd.              *
00013 //                                                                     *
00014 //    This program is free software; you can redistribute it and/or    *
00015 //    modify it under the terms of the GNU General Public License      *
00016 //    as published by the Free Software Foundation; either version 2   *
00017 //    of the License, or any later version.                            *
00018 //                                                                     *
00019 //    This program is distributed in the hope that it will be useful,  *
00020 //    but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00021 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00022 //    GNU General Public License for more details.                     *
00023 //                                                                     *
00024 //    You should have received a copy of the GNU General Public        *
00025 //    License (http://www.gnu.org/copyleft/gpl.html) along with this   *
00026 //    program; if not, write to:                                       *
00027 //       The Free Software Foundation Inc.,                            *
00028 //       59 Temple Place - Suite 330,                                  *
00029 //       Boston, MA  02111-1307,                                       *
00030 //       USA.                                                          *
00031 //                                                                     *
00032 //**********************************************************************
00033 //                                                                     *
00034 //    Notes:                                                           *
00035 //                                                                     *
00036 //**********************************************************************
00037 
00038 #include <dir.h>
00039 #include <stdlib.h>
00040 #include <string.h>
00041 
00042 #include <classlib\arrays.h>
00043 #include <owl\applicat.h>
00044 #include <owl\edit.h>
00045 #include <owl\framewin.h>
00046 #include <owl\inputdia.h>
00047 #include <owl\opensave.h>
00048 #include <owl\owlpch.h>
00049 #include <owl\scroller.h>
00050 
00051 #include "ww2rtf.rc"
00052 #include "monrtfwr.h"
00053 #include "monwwrd.h"
00054 
00055 class TMyWindow : public TWindow
00056 {
00057   public:
00058      TMyWindow(TWindow *parent = 0);
00059      virtual  ~TMyWindow();
00060 
00061   protected:
00062      void  CmFileOpen();
00063      void  CmFileDirectory();
00064      void  CmFileExit();
00065      void  CmAbout();
00066      DECLARE_RESPONSE_TABLE(TMyWindow);
00067 
00068      void  ConvertFile(const char*    fileName, ifstream&    fileStream);
00069      void  OpenFile();
00070      void  OpenDirectory();
00071 
00072      static void  traceConversionCb(void  *traceObj, const char  *traceText);
00073      void         traceConversion(const char  *traceText);
00074 
00075      TEdit                   *textArea;
00076      TOpenSaveDialog::TData  *fileData;
00077 };
00078 
00079 DEFINE_RESPONSE_TABLE1(TMyWindow,TWindow)
00080   EV_COMMAND(CM_FILEOPEN, CmFileOpen),
00081   EV_COMMAND(CM_FILEDIRECTORY, CmFileDirectory),
00082   EV_COMMAND(CM_FILEEXIT, CmFileExit),
00083   EV_COMMAND(CM_ABOUT, CmAbout),
00084 END_RESPONSE_TABLE;
00085 
00086 
00087 TMyWindow::TMyWindow(TWindow *parent)
00088 {
00089     Init(parent, 0, 0);
00090     fileData = new TFileOpenDialog::TData(OFN_HIDEREADONLY|OFN_FILEMUSTEXIST,
00091                                           "Wordwise Files (*.BBC)|*.bbc|",
00092                                           0,
00093                                           "",
00094                                           "BBC");
00095     textArea = new TEdit(this, 0, "", 0, 0, Attr.W, Attr.H, 0, TRUE);
00096     textArea->SetReadOnly(TRUE);
00097     textArea->FormatLines(TRUE);
00098 }
00099 
00100 
00101 TMyWindow::~TMyWindow()
00102 {
00103   delete fileData;
00104   delete textArea;
00105 }
00106 
00107 
00108 void
00109 TMyWindow::CmFileOpen()
00110 {
00111   if (TFileOpenDialog(this, *fileData).Execute() == IDOK)
00112   {
00113      OpenFile();
00114   }
00115 }
00116 
00117 
00118 void
00119 TMyWindow::CmFileDirectory()
00120 {
00121     if (TFileOpenDialog(this, *fileData).Execute() == IDOK)
00122     {
00123         OpenDirectory();
00124     }
00125 }
00126 
00127 
00128 void
00129 TMyWindow::CmFileExit()
00130 {
00131 EvClose();
00132 //  CloseWindow();
00133 }
00134 
00135 
00136 void
00137 TMyWindow::CmAbout()
00138 {
00139     TDialog(this, IDD_ABOUT).Execute();
00140 }
00141 
00142 
00143 void
00144 TMyWindow::ConvertFile(const char*    fileName, ifstream&    fileStream)
00145 {
00146     MonRtfWriter       writer(fileName);
00147     MonWordWiseReader  reader(&fileStream, &writer, this, traceConversionCb);
00148 
00149     textArea->SetWindowPos(0, 0, 0, Attr.W, Attr.H, SWP_NOZORDER);
00150     textArea->Clear();
00151     reader.convert();
00152 }
00153 
00154 
00155 
00156 void
00157 TMyWindow::OpenFile()
00158 {
00159     ifstream  is(fileData->FileName, ios::in | ios::binary);
00160 
00161     if (!is)
00162     {
00163         MessageBox("Unable to open file",
00164                    "File Error",
00165                    MB_OK | MB_ICONEXCLAMATION);
00166     }
00167     else
00168     {
00169         ConvertFile(fileData->FileName, is);
00170         MessageBox(fileData->FileName,
00171                    "Converted file",
00172                    MB_OK);
00173         is.close();
00174     }
00175 }
00176 
00177 
00178 void
00179 TMyWindow::OpenDirectory()
00180 {
00181     const char    dirSepChar = '\\';
00182 
00183 
00184     if (0 != strchr(fileData->FileName, dirSepChar))
00185     {
00186         char*    fileName = strchr(fileData->FileName, '\0');
00187 
00188 
00189         while (*fileName != dirSepChar)
00190         {
00191             *fileName = '\0';
00192             --fileName;
00193         }
00194 
00195         ++fileName;
00196         strcpy(fileName, "*.bbc");
00197 
00198 
00199         ffblk    findBlock;
00200 
00201 
00202         if (0 == findfirst(fileData->FileName, &findBlock, 0))
00203         {
00204             do
00205             {
00206                 ifstream    is(findBlock.ff_name, ios::in | ios::binary);
00207 
00208                 if (is)
00209                 {
00210                     ConvertFile(findBlock.ff_name, is);
00211                 }
00212 
00213                 is.close();
00214 
00215             } while (0 == findnext(&findBlock));
00216 
00217             MessageBox(fileData->FileName,
00218                        "Converted files",
00219                        MB_OK);
00220         }
00221     }
00222 }
00223 
00224 
00225 
00226 void
00227 TMyWindow::traceConversionCb(void  *traceObj, const char  *traceText)
00228 {
00229   if (0 != traceObj)
00230   {
00231      ((TMyWindow*)traceObj)->traceConversion(traceText);
00232   }
00233 }
00234 
00235 
00236 void
00237 TMyWindow::traceConversion(const char  *traceText)
00238 {
00239   textArea->Insert(traceText);
00240 }
00241 
00242 
00243 class TMyApp : public TApplication {
00244   public:
00245      TMyApp() : TApplication() {}
00246 
00247      void InitMainWindow()
00248      {
00249         SetMainWindow(new TFrameWindow(0,
00250                                                  "Wordwise to RTF filter",
00251                                                  new TMyWindow));
00252         GetMainWindow()->AssignMenu("COMMANDS");
00253      }
00254 };
00255 
00256 
00257 int OwlMain(int /*argc*/, char* /*argv*/ [])
00258 {
00259   return TMyApp().Run();
00260 }

Generated on Sun Jul 20 02:35:50 2003 for WordWise to RTF, Win32 by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002