Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

plucker.cpp

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <string.h>
00003 #include <qmessagebox.h>
00004 #include <qpixmap.h>
00005 #ifdef USEQPE
00006 #include <qpe/qcopenvelope_qws.h>
00007 #endif
00008 #ifdef LOCALPICTURES
00009 #include <qscrollview.h>
00010 #endif
00011 #ifdef USEQPE
00012 #include <qpe/global.h>
00013 #include <qpe/qpeapplication.h>
00014 #else
00015 #include <qapplication.h>
00016 #endif
00017 #include <qclipboard.h>
00018 
00019 #include "plucker.h"
00020 #include "Aportis.h"
00021 #include "Palm2QImage.h"
00022 
00023 
00024 struct CPlucker_dataRecord
00025 {
00026     UInt16 uid;
00027     UInt16 nParagraphs;
00028     UInt16 size;
00029     UInt8 type;
00030     UInt8 reserved;
00031 };
00032 
00033 int CPlucker::HeaderSize()
00034 {
00035     return sizeof(CPlucker_dataRecord);
00036 }
00037 
00038 void CPlucker::GetHeader(UInt16& uid, UInt16& nParagraphs, UInt32& size, UInt8& type, UInt8& reserved)
00039 {
00040     CPlucker_dataRecord thishdr;
00041     fread(&thishdr, 1, HeaderSize(), fin);
00042     uid = ntohs(thishdr.uid);
00043     nParagraphs = ntohs(thishdr.nParagraphs);
00044     size = ntohs(thishdr.size);
00045     type = thishdr.type;
00046     reserved = thishdr.reserved;
00047 }
00048 
00049 CPlucker::CPlucker()
00050  { /*printf("constructing:%x\n",fin);*/
00051      EOPPhase = 0;
00052  }
00053 
00054 bool CPlucker::CorrectDecoder()
00055 {
00056     return (memcmp(&head.type, "DataPlkr", 8) == 0);
00057 }
00058 
00059 int CPlucker::bgetch()
00060 {
00061     int ch = EOF;
00062     if (bufferpos >= buffercontent)
00063     {
00064         if (isEndOfSection(bufferrec))
00065         {
00066           if (!m_continuous) return EOF;
00067         }
00068         if (bufferrec >= ntohs(head.recordList.numRecords) - 1)
00069         {
00070                 return EOF;
00071         }
00072         if (!expand(bufferrec+1))
00073         {
00074                 return EOF;
00075         }
00076         mystyle.unset();
00077         if (m_ParaOffsets[m_nextParaIndex] == 0)
00078         {
00079             while (m_ParaOffsets[m_nextParaIndex+1] == 0)
00080             {
00081 //              qDebug("Skipping extraspace:%d", m_ParaAttrs[m_nextParaIndex]&7);
00082                 m_nextParaIndex++;
00083             }
00084         }
00085         mystyle.setExtraSpace((m_ParaAttrs[m_nextParaIndex]&7)*2);
00086 //      qDebug("Using extraspace:%d", m_ParaAttrs[m_nextParaIndex]&7);
00087         ch = 10;
00088         if (m_continuous) EOPPhase = 4;
00089     }
00090     else if (bufferpos == m_nextPara)
00091     {
00092         while (bufferpos == m_nextPara)
00093         {
00094             UInt16 attr = m_ParaAttrs[m_nextParaIndex];
00095             m_nextParaIndex++;
00096 //          qDebug("Skipping extraspace:%d", m_ParaAttrs[m_nextParaIndex]&7);
00097             if (m_nextParaIndex == m_nParas)
00098             {
00099                 m_nextPara = -1;
00100             }
00101             else
00102             {
00103                 m_nextPara += m_ParaOffsets[m_nextParaIndex];
00104             }
00105         }
00106         mystyle.unset();
00107         mystyle.setExtraSpace((m_ParaAttrs[m_nextParaIndex]&7)*2);
00108 //      qDebug("Using extraspace:%d", m_ParaAttrs[m_nextParaIndex]&7);
00109         if (m_lastBreak == locate())
00110         {
00111             currentpos++;
00112             ch = expandedtextbuffer[bufferpos++];
00113         }
00114         else
00115         {
00116             ch = 10;
00117         }
00118     }
00119     else
00120     {
00121         currentpos++;
00122         ch = expandedtextbuffer[bufferpos++];
00123     }
00124     return ch;
00125 }
00126 
00127 tchar CPlucker::getch(bool fast)
00128 {
00129     mystyle.clearPicture();
00130 
00131     if (EOPPhase > 0)
00132     {
00133         int ch = 10;
00134         switch (EOPPhase)
00135         {
00136             case 4:
00137                 if (!fast) mystyle.setPicture(false, hRule(100,5));
00138                 mystyle.setCentreJustify();
00139                 ch = '#';
00140                 break;
00141             case 3:
00142                 mystyle.setFontSize(3);
00143                 ch = 10;
00144                 break;
00145             case 2:
00146                 ch = 10;
00147                 break;
00148             case 1:
00149                 mystyle.unset();
00150             default:
00151                 ch = 10;
00152         }
00153         EOPPhase--;
00154         return ch;
00155     }
00156 
00157     return getch_base(fast);
00158 }
00159 
00160 QImage* CPlucker::imagefromdata(UInt8* imgbuffer, UInt32 imgsize)
00161 {
00162     QImage* qimage = Palm2QImage(imgbuffer, imgsize);
00163     delete [] imgbuffer;
00164     return qimage;
00165 }
00166 
00167 void CPlucker::start2endSection() // to plucker base
00168 {
00169     m_currentstart = NEFstartSection();
00170     m_currentend = NEFendSection();
00171 }
00172 
00173 unsigned long CPlucker::NEFstartSection() // virtual in plucker base - differs only in obsoleted nef so move implementation
00174 {
00175 //inefficient - Should calc start/end of section on entry to section?
00176     UInt16 thishdr_uid, thishdr_nParagraphs;
00177     UInt32 thishdr_size;
00178     UInt8 thishdr_type, thishdr_reserved;
00179     unsigned long textlength = currentpos-bufferpos;
00180     for (UInt16 recptr = bufferrec-1; recptr >= 1; recptr--)
00181     {
00182         gotorecordnumber(recptr);
00183         //qDebug("recptr:%u", recptr);
00184         GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
00185         if (thishdr_type < 2)
00186         {
00187             if ((thishdr_reserved && continuation_bit) == 0) break;
00188             textlength -= thishdr_size;
00189             //qDebug("Textlength:%u, reserved:%u, recptr:%u", textlength, thishdr_reserved, recptr);
00190         }
00191     }
00192     return textlength;
00193 }
00194 
00195 unsigned long CPlucker::NEFendSection() // virtual in plucker base - differs only in obsoleted nef so move implementation
00196 {
00197 //inefficient - Should calc start/end of section on entry to section?
00198     unsigned long textlength = currentpos-bufferpos+buffercontent;
00199     gotorecordnumber(bufferrec);
00200     UInt16 thishdr_uid, thishdr_nParagraphs;
00201     UInt32 thishdr_size;
00202     UInt8 thishdr_type, thishdr_reserved;
00203     GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
00204     if ((thishdr_reserved && continuation_bit) != 0)
00205       {
00206         for (UInt16 recptr = bufferrec+1; recptr < ntohs(head.recordList.numRecords); recptr++)
00207           {
00208             gotorecordnumber(recptr);
00209             UInt16 thishdr_uid, thishdr_nParagraphs;
00210             UInt32 thishdr_size;
00211             UInt8 thishdr_type, thishdr_reserved;
00212             GetHeader(thishdr_uid, thishdr_nParagraphs, thishdr_size, thishdr_type, thishdr_reserved);
00213             //  qDebug("recptr %u bufferrec %u type %u m_reserved %u", recptr, bufferrec, typ
00214             if (thishdr_type < 2)
00215               {
00216                 textlength += thishdr_size;
00217                 if ((thishdr_reserved && continuation_bit) == 0) break;
00218               }
00219           }
00220       }
00221     return textlength;
00222 }
00223 
00224 #ifndef __STATIC
00225 extern "C"
00226 {
00227   CExpander* newcodec() { return new CPlucker; }
00228 }
00229 #endif

Generated on Sat Nov 5 16:16:56 2005 for OPIE by  doxygen 1.4.2