summaryrefslogtreecommitdiff
path: root/noncore
Side-by-side diff
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-reader/Aportis.cpp163
-rw-r--r--noncore/apps/opie-reader/Aportis.h14
-rw-r--r--noncore/apps/opie-reader/Bkmks.cpp240
-rw-r--r--noncore/apps/opie-reader/Bkmks.h53
-rw-r--r--noncore/apps/opie-reader/BuffDoc.cpp192
-rw-r--r--noncore/apps/opie-reader/BuffDoc.h104
-rw-r--r--noncore/apps/opie-reader/CAnnoEdit.h58
-rw-r--r--noncore/apps/opie-reader/CBuffer.cpp53
-rw-r--r--noncore/apps/opie-reader/CBuffer.h66
-rw-r--r--noncore/apps/opie-reader/CEncoding.cpp182
-rw-r--r--noncore/apps/opie-reader/CEncoding.h12
-rw-r--r--noncore/apps/opie-reader/CExpander.h136
-rw-r--r--noncore/apps/opie-reader/CFilter.cpp561
-rw-r--r--noncore/apps/opie-reader/CFilter.h407
-rw-r--r--noncore/apps/opie-reader/FontControl.h121
-rw-r--r--noncore/apps/opie-reader/Markups.h7
-rw-r--r--noncore/apps/opie-reader/QFloatBar.h19
-rw-r--r--noncore/apps/opie-reader/QTReader.cpp1186
-rw-r--r--noncore/apps/opie-reader/QTReader.h99
-rw-r--r--noncore/apps/opie-reader/QTReaderApp.cpp1224
-rw-r--r--noncore/apps/opie-reader/QTReaderApp.h73
-rw-r--r--noncore/apps/opie-reader/StyleConsts.h113
-rw-r--r--noncore/apps/opie-reader/ZText.h7
-rw-r--r--noncore/apps/opie-reader/fileBrowser.cpp27
-rw-r--r--noncore/apps/opie-reader/fileBrowser.h4
-rw-r--r--noncore/apps/opie-reader/infowin.cpp7
-rw-r--r--noncore/apps/opie-reader/main.cpp32
-rw-r--r--noncore/apps/opie-reader/my_list.h11
-rw-r--r--noncore/apps/opie-reader/opie-reader.pro104
-rw-r--r--noncore/apps/opie-reader/pdb.h1
-rw-r--r--noncore/apps/opie-reader/plucker.h86
-rw-r--r--noncore/apps/opie-reader/ppm_expander.h4
-rw-r--r--noncore/apps/opie-reader/version.h8
-rw-r--r--noncore/apps/opie-reader/ztxt.cpp4
-rw-r--r--noncore/apps/opie-reader/ztxt.h32
35 files changed, 3768 insertions, 1642 deletions
diff --git a/noncore/apps/opie-reader/Aportis.cpp b/noncore/apps/opie-reader/Aportis.cpp
index 595b385..1327ff8 100644
--- a/noncore/apps/opie-reader/Aportis.cpp
+++ b/noncore/apps/opie-reader/Aportis.cpp
@@ -1,11 +1,57 @@
#include <stdio.h>
#include <string.h>
#include "Aportis.h"
+#include "my_list.h"
+#include "Bkmks.h"
-Aportis::Aportis() { /*printf("constructing:%x\n",fin);*/ }
+Aportis::Aportis() : peanutfile(false) { /*printf("constructing:%x\n",fin);*/ }
+
+void Aportis::dePeanut(int& ch)
+{
+ if (peanutfile && ch != EOF)
+ {
+ unsigned char c = ch;
+ if (peanutfile) c ^= 0xa5;
+ ch = c;
+ }
+}
CList<Bkmk>* Aportis::getbkmklist()
{
+/*
+ if (peanutfile)
+ {
+ if (nRecs2 > nRecs)
+ {
+ CList<Bkmk>* t = new CList<Bkmk>;
+ for (int i = nRecs; i < nRecs2; i++)
+ {
+ char name[17];
+ name[16] = '\0';
+ qDebug("Record:%d, Length:%u",i,recordlength(i));
+ gotorecordnumber(i);
+ fread(name,1,16,fin);
+ unsigned long lcn;
+ fread(&lcn,sizeof(lcn),1,fin);
+ lcn ^= 0xa5a5a5a5;
+ lcn = SwapLong(lcn);
+ qDebug("Bookmark:%s:%u", name,lcn);
+ tchar tname[17];
+ memset(tname, 0, sizeof(tname));
+ for (int i = 0; name[i] != 0; i++)
+ {
+ tname[i] = name[i] ^ 0xa5;
+ }
+ t->push_back(Bkmk(tname, NULL, lcn));
+ }
+ return t;
+ }
+ else
+ {
+ return NULL;
+ }
+ }
+*/
if (bCompressed != 4) return NULL;
CList<Bkmk>* t = new CList<Bkmk>;
size_t cur = ftell(fin);
@@ -34,7 +80,7 @@ CList<Bkmk>* Aportis::getbkmklist()
{
tname[i] = name[i];
}
- t->push_back(Bkmk(tname,lcn));
+ t->push_back(Bkmk(tname, NULL, lcn));
#else
t->push_back(Bkmk(name,lcn));
#endif
@@ -46,7 +92,6 @@ CList<Bkmk>* Aportis::getbkmklist()
int Aportis::openfile(const char *src)
{
-
// printf("In openfile\n");
int ret = 0;
@@ -55,49 +100,80 @@ int Aportis::openfile(const char *src)
if (head.creator != 0x64414552 // 'dAER'
|| head.type != 0x74584554) // 'tXET')
{
- return -2;
+
+ if (memcmp(&head.creator, "PPrs", 4) == 0 && memcmp(&head.type, "PNRd", 4) == 0)
+ {
+ peanutfile = true;
+ }
+ else
+ {
+ return -2;
+ }
}
- gotorecordnumber(0);
- tDocRecord0 hdr0;
- fread(&hdr0, sizeof(hdr0), 1, fin);
- bCompressed = SwapWord(hdr0.wVersion);
- if (bCompressed!=1 && bCompressed!=2 && bCompressed != 4) {
- ret = bCompressed;
- bCompressed = 2;
- }
-
+ nRecs2 = nRecs = SwapWord(head.recordList.numRecords) - 1;
fseek(fin,0,SEEK_END);
dwLen = ftell(fin);
- nRecs2 = nRecs = SwapWord(head.recordList.numRecords) - 1;
- switch (bCompressed)
- {
- case 4:
+ if (peanutfile)
+ {
+
+ PeanutHeader hdr0;
+ gotorecordnumber(0);
+ fread(&hdr0, sizeof(hdr0), 1, fin);
+ qDebug("Version:%x", ntohs(hdr0.Version));
+ if (hdr0.Version && 0x0200)
{
- dwTLen = 0;
- int i;
- for (i = 0; i < nRecs; i++)
+ bCompressed = 2;
+ }
+ else
+ {
+ bCompressed = 1;
+ }
+ BlockSize = 4096;
+ nRecs = SwapWord(hdr0.Records)-1;
+ dwTLen = nRecs*BlockSize;
+ }
+ else
+ {
+ gotorecordnumber(0);
+ tDocRecord0 hdr0;
+ fread(&hdr0, sizeof(hdr0), 1, fin);
+ bCompressed = SwapWord(hdr0.wVersion);
+ if (bCompressed!=1 && bCompressed!=2 && bCompressed != 4) {
+ ret = bCompressed;
+ bCompressed = 2;
+ }
+ switch (bCompressed)
+ {
+ case 4:
{
- unsigned int bs = GetBS(i);
- if (bs == 0) break;
- else dwTLen += bs;
+ dwTLen = 0;
+ int i;
+ for (i = 0; i < nRecs; i++)
+ {
+ unsigned int bs = GetBS(i);
+ if (bs == 0) break;
+ else dwTLen += bs;
+ }
+ nRecs = i;
+ BlockSize = 0;
}
- nRecs = i;
- BlockSize = 0;
+ break;
+ case 1:
+ case 2:
+ default:
+ nRecs = SwapWord(hdr0.wNumRecs);
+ dwTLen = SwapLong(hdr0.dwStoryLen);
+ BlockSize = SwapWord(hdr0.wRecSize);
+ if (BlockSize == 0)
+ {
+ BlockSize = 4096;
+ printf("WARNING: Blocksize not set in source file\n");
+ }
}
- break;
- case 1:
- case 2:
- default:
- dwTLen = SwapLong(hdr0.dwStoryLen);
- BlockSize = SwapWord(hdr0.wRecSize);
- if (BlockSize == 0)
- {
- BlockSize = 4096;
- printf("WARNING: Blocksize not set in source file\n");
- }
- }
+ }
+
// this is the main record buffer
@@ -106,6 +182,7 @@ int Aportis::openfile(const char *src)
cbptr = 0;
outptr = 0;
refreshbuffer();
+ qDebug("Number of records:[%u,%u]", nRecs, nRecs2);
return ret;
}
@@ -117,6 +194,7 @@ int Aportis::getch()
else
{
int c = getc(fin);
+ dePeanut(c);
dwRecLen--;
currentpos++;
return c;
@@ -129,10 +207,11 @@ int Aportis::getch()
}
if ((dwRecLen == 0) && !refreshbuffer()) return EOF;
currentpos++;
- unsigned int c;
+ int c;
// take a char from the input buffer
c = getc(fin);
+ dePeanut(c);
dwRecLen--;
// separate the char into zones: 0, 1...8, 9...0x7F, 0x80...0xBF, 0xC0...0xFF
@@ -152,7 +231,9 @@ int Aportis::getch()
dwRecLen -= c;
while(c--)
{
- circbuf[cbptr = (cbptr+1)%2048] = getc(fin);
+ int c = getc(fin);
+ dePeanut(c);
+ circbuf[cbptr = (cbptr+1)%2048] = c;
}
return circbuf[outptr = (outptr+1)%2048];
}
@@ -160,7 +241,9 @@ int Aportis::getch()
{
int m,n;
c <<= 8;
- c += getc(fin);
+ int c1 = getc(fin);
+ dePeanut(c1);
+ c += c1;
dwRecLen--;
m = (c & 0x3FFF) >> COUNT_BITS;
n = c & ((1<<COUNT_BITS) - 1);
diff --git a/noncore/apps/opie-reader/Aportis.h b/noncore/apps/opie-reader/Aportis.h
index 08016f4..1ca5e73 100644
--- a/noncore/apps/opie-reader/Aportis.h
+++ b/noncore/apps/opie-reader/Aportis.h
@@ -40,6 +40,14 @@ struct tDocRecord0 {
DWORD dwSpare2;
};
+struct PeanutHeader
+{
+ UInt16 Version;
+ UInt8 Junk1[6];
+ UInt16 Records;
+ UInt8 Junk2[106];
+};
+
////////////// utilities //////////////////////////////////////
inline WORD SwapWord(WORD r)
@@ -53,6 +61,8 @@ inline DWORD SwapLong(DWORD r)
}
class Aportis : public CExpander, Cpdb {
+ bool peanutfile;
+ void dePeanut(int&);
DWORD dwLen;
WORD nRecs2;
DWORD dwTLen;
@@ -78,6 +88,10 @@ public:
virtual unsigned int locate();
virtual void locate(unsigned int n);
virtual CList<Bkmk>* getbkmklist();
+ virtual MarkupType PreferredMarkup()
+ {
+ return (peanutfile) ? cPML : cTEXT;
+ }
private:
bool refreshbuffer();
unsigned int GetBS(unsigned int bn);
diff --git a/noncore/apps/opie-reader/Bkmks.cpp b/noncore/apps/opie-reader/Bkmks.cpp
new file mode 100644
index 0000000..92ed69f
--- a/dev/null
+++ b/noncore/apps/opie-reader/Bkmks.cpp
@@ -0,0 +1,240 @@
+#include <qmessagebox.h>
+
+#include "Bkmks.h"
+
+#include "StyleConsts.h"
+#include "Markups.h"
+#include "my_list.h"
+#include "version.h"
+
+const unsigned long BkmkFile::magic = ((unsigned long)'q' << 24) | ((unsigned long)'t' << 16) | ((unsigned long)'r' << 8) | ((unsigned long)BKMKTYPE);
+
+
+Bkmk::Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p) : m_position(_p)
+{
+ int len = ustrlen(_nm)+1;
+ m_name = new tchar[len];
+ for (int i = 0; i < len; i++) m_name[i] = _nm[i];
+
+ if (_anno == NULL)
+ {
+ m_anno = new tchar[1];
+ m_anno[0] = 0;
+ }
+ else
+ {
+ len = ustrlen(_anno)+1;
+ m_anno = new tchar[len];
+ for (int i = 0; i < len; i++) m_anno[i] = _anno[i];
+ }
+}
+
+Bkmk::~Bkmk()
+{
+ if (m_name != NULL) delete [] m_name;
+ m_name = NULL;
+ if (m_anno != NULL) delete [] m_anno;
+ m_anno = NULL;
+}
+
+Bkmk& Bkmk::operator=(const Bkmk& rhs)
+{
+ if (m_name != NULL)
+ {
+ delete [] m_name;
+ m_name = NULL;
+ }
+ if (m_anno != NULL)
+ {
+ delete [] m_anno;
+ m_anno = NULL;
+ }
+ if (rhs.m_name != NULL)
+ {
+ int len = ustrlen(rhs.m_name)+1;
+ m_name = new tchar[len];
+ for (int i = 0; i < len; i++) m_name[i] = rhs.m_name[i];
+ }
+ else
+ m_name = NULL;
+ if (rhs.m_anno != NULL)
+ {
+ int len = ustrlen(rhs.m_anno)+1;
+ m_anno = new tchar[len];
+ for (int i = 0; i < len; i++) m_anno[i] = rhs.m_anno[i];
+ }
+ else
+ m_anno = NULL;
+ m_position = rhs.m_position;
+ return *this;
+}
+
+bool Bkmk::operator==(const Bkmk& rhs)
+{
+ return (m_position == rhs.m_position && ustrcmp(m_name,rhs.m_name) == 0);
+}
+
+void Bkmk::setAnno(tchar* t)
+{
+ if (m_anno != NULL)
+ {
+ delete [] m_anno;
+ m_anno = NULL;
+ }
+ if (t != NULL)
+ {
+ int len = ustrlen(t)+1;
+ m_anno = new tchar[len];
+ for (int i = 0; i < len; i++) m_anno[i] = t[i];
+ }
+ else
+ m_anno = NULL;
+}
+
+BkmkFile::BkmkFile(const char *fnm, bool w = false)
+ :
+ wt(w), isUpgraded(false)
+{
+ if (w)
+ {
+ f = fopen(fnm, "wb");
+ }
+ else
+ {
+ f = fopen(fnm, "rb");
+ }
+}
+
+BkmkFile::~BkmkFile()
+{
+ if (f != NULL) fclose(f);
+}
+
+void BkmkFile::write(tchar* nm, tchar* an, const unsigned int& pos)
+{
+ if (f != NULL)
+ {
+ unsigned short ln = ustrlen(nm);
+ fwrite(&ln,sizeof(ln),1,f);
+ fwrite(nm,sizeof(tchar),ln,f);
+ ln = ustrlen(an);
+ fwrite(&ln,sizeof(ln),1,f);
+ if (ln > 0) fwrite(an,sizeof(tchar),ln,f);
+ fwrite(&pos,sizeof(pos),1,f);
+ }
+}
+
+void BkmkFile::write(const Bkmk& b) { write(b.name(), b.anno(), b.value()); }
+
+void BkmkFile::write(CList<Bkmk>& bl)
+{
+ if (f != NULL)
+ {
+ fwrite(&magic, sizeof(magic), 1, f);
+ for (CList<Bkmk>::iterator i = bl.begin(); i != bl.end(); i++)
+ {
+ write(*i);
+ }
+ }
+}
+
+Bkmk* BkmkFile::read()
+{
+ Bkmk* b = NULL;
+ if (f != NULL)
+ {
+ unsigned short ln;
+ if (fread(&ln,sizeof(ln),1,f) == 1)
+ {
+ b = new Bkmk;
+ b->m_name = new tchar[ln+1];
+ fread(b->m_name,sizeof(tchar),ln,f);
+ b->m_name[ln] = 0;
+
+ fread(&ln,sizeof(ln),1,f);
+ b->m_anno = new tchar[ln+1];
+ if (ln > 0) fread(b->m_anno,sizeof(tchar),ln,f);
+ b->m_anno[ln] = 0;
+ fread(&b->m_position,sizeof(b->m_position),1,f);
+ }
+ }
+ return b;
+}
+
+CList<Bkmk>* BkmkFile::readall()
+{
+ CList<Bkmk>* bl = NULL;
+ if (f != NULL)
+ {
+ unsigned long newmagic;
+ fread(&newmagic, sizeof(newmagic), 1, f);
+ if (newmagic != magic)
+ {
+ if (QMessageBox::warning(NULL, "Old bookmark file!", "Which version of QTReader\ndid you upgrade from?", "0_4*", "Any other version") == 0)
+ {
+ fseek(f,0,SEEK_SET);
+ bl = readall04();
+ }
+ else
+ {
+ fseek(f,0,SEEK_SET);
+ bl = readall03();
+ }
+ isUpgraded = true;
+ }
+ else
+ {
+ bl = readall04();
+ }
+ }
+ return bl;
+}
+
+CList<Bkmk>* BkmkFile::readall04()
+{
+ CList<Bkmk>* bl = new CList<Bkmk>;
+ while (1)
+ {
+ Bkmk* b = read();
+ if (b == NULL) break;
+ bl->push_back(*b);
+ delete b;
+ }
+ return bl;
+}
+
+CList<Bkmk>* BkmkFile::readall03()
+{
+ CList<Bkmk>* bl = new CList<Bkmk>;
+ while (1)
+ {
+ Bkmk* b = read03();
+ if (b == NULL) break;
+ bl->push_back(*b);
+ delete b;
+ }
+ return bl;
+}
+
+Bkmk* BkmkFile::read03()
+{
+ Bkmk* b = NULL;
+ if (f != NULL)
+ {
+ unsigned short ln;
+ if (fread(&ln,sizeof(ln),1,f) == 1)
+ {
+ b = new Bkmk;
+ b->m_name = new tchar[ln+1];
+ fread(b->m_name,sizeof(tchar),ln,f);
+ b->m_name[ln] = 0;
+
+ ln = 0;
+ b->m_anno = new tchar[ln+1];
+ b->m_anno[ln] = 0;
+
+ fread(&b->m_position,sizeof(b->m_position),1,f);
+ }
+ }
+ return b;
+}
diff --git a/noncore/apps/opie-reader/Bkmks.h b/noncore/apps/opie-reader/Bkmks.h
new file mode 100644
index 0000000..b38184a
--- a/dev/null
+++ b/noncore/apps/opie-reader/Bkmks.h
@@ -0,0 +1,53 @@
+#ifndef __Bkmks_h
+#define __Bkmks_h
+
+#include "config.h"
+#include <stdio.h>
+
+template<class T>
+class CList;
+
+class Bkmk
+{
+ friend class BkmkFile;
+ tchar* m_name;
+ tchar* m_anno;
+ unsigned int m_position;
+ public:
+ Bkmk() : m_name(NULL), m_anno(NULL), m_position(0) {};
+ Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p);
+ Bkmk(const Bkmk& rhs) : m_name(NULL), m_anno(NULL)
+ {
+ *this = rhs;
+ }
+ ~Bkmk();
+ unsigned int value() const { return m_position; }
+ tchar *name() const { return m_name; }
+ tchar *anno() const { return m_anno; }
+ bool operator<(const Bkmk& rhs) { return (m_position < rhs.m_position); }
+ Bkmk& operator=(const Bkmk& rhs);
+ bool operator==(const Bkmk& rhs);
+ void setAnno(tchar* t);
+};
+
+class BkmkFile
+{
+ FILE* f;
+ bool wt;
+ bool isUpgraded;
+ static const unsigned long magic;
+ private:
+ Bkmk* read();
+ Bkmk* read03();
+ CList<Bkmk>* readall03();
+ CList<Bkmk>* readall04();
+ void write(tchar* nm, tchar* an, const unsigned int& pos);
+ void write(const Bkmk& b);
+ public:
+ bool upgraded() { return isUpgraded; }
+ BkmkFile(const char *fnm, bool w = false);
+ ~BkmkFile();
+ void write(CList<Bkmk>& bl);
+ CList<Bkmk>* readall();
+};
+#endif
diff --git a/noncore/apps/opie-reader/BuffDoc.cpp b/noncore/apps/opie-reader/BuffDoc.cpp
index df2f4eb..e37b136 100644
--- a/noncore/apps/opie-reader/BuffDoc.cpp
+++ b/noncore/apps/opie-reader/BuffDoc.cpp
@@ -1,12 +1,28 @@
#include "BuffDoc.h"
//#include <FL/fl_draw.h>
#include "config.h"
+#include "CDrawBuffer.h"
+#include "plucker.h"
+
+
+bool BuffDoc::hyperlink(unsigned int n)
+{
+ bool bRet = false;
+ lastword.empty();
+ lastsizes[0] = laststartline = n;
+ lastispara = false;
+ if (exp != NULL)
+ {
+ bRet = exp->hyperlink(n);
+ lastsizes[0] = laststartline = exp->locate();
+ }
+ return bRet;
+}
void BuffDoc::locate(unsigned int n)
{
// qDebug("BuffDoc:locating:%u",n);
-
- lastword[0] = '\0';
+ lastword.empty();
lastsizes[0] = laststartline = n;
lastispara = false;
// tchar linebuf[1024];
@@ -14,52 +30,52 @@ void BuffDoc::locate(unsigned int n)
// qDebug("BuffDoc:Located");
}
-bool BuffDoc::getline(CBuffer* buff, int w)
+bool BuffDoc::getline(CDrawBuffer* buff, int w)
{
+ tchar ch = 32;
+ CStyle cs;
+ buff->empty();
if (exp == NULL)
{
- (*buff)[0] = '\0';
+// (*buff)[0] = '\0';
+ buff->empty();
return false;
}
- int len = 0, ch, lastcheck = 0;
- *buff = lastword.data();
+ int len = 0, lastcheck = 0;
+ if (lastword.length() > 0)
+ {
+ *buff = lastword;
+ cs = lastword.laststyle();
+ }
+ else buff->empty();
+// qDebug("Buff:%s Lastword:%s", (const char*)toQString(buff->data()), (const char*)toQString(lastword.data()));
lastcheck = len = buff->length();
- // unsigned int slen = fl_widthi(buff->data(),len);
-#ifdef _UNICODE
- unsigned int slen = m_fm->width(toQString(buff->data()),len);
-#else
- unsigned int slen = m_fm->width(buff->data(),len);
-#endif
+ unsigned int slen = buff->width(len);
if (slen > w)
{
for ( ; len > 0; len--)
{
- // if (fl_widthi(buff->data(),len) < w) break;
-#ifdef _UNICODE
- if (m_fm->width(toQString(buff->data()),len) < w) break;
-#else
- if (m_fm->width(buff->data(),len) < w) break;
-#endif
+ if (buff->width(len) < w) break;
}
- lastword = buff->data() + len - 1;
+// lastword = buff->data() + len - 1;
+ laststartline = lastsizes[len-1];
+ lastword.setright(*buff, len - 1);
for (int i = 0; i < buff->length(); i++) lastsizes[i] = lastsizes[i+len-1];
- (*buff)[len-1] = '-';
+// (*buff)[len-1] = '-';
+ buff->truncate(len-1);
+ buff->addch('-', cs);
(*buff)[len] = '\0';
- laststartline = lastsizes[len-1];
return true;
}
if (lastispara)
{
lastispara = false;
- lastword[0] = '\0';
+// lastword[0] = '\0';
+ lastword.empty();
len = buff->length();
- // while (fl_widthi(buff->data(),len) > w) len--;
-#ifdef _UNICODE
- while (m_fm->width(toQString(buff->data()),len) > w) len--;
-#else
- while (m_fm->width(buff->data(),len) > w) len--;
-#endif
- (*buff)[len] = '\0';
+ while (buff->width(len) > w) len--;
+// (*buff)[len] = '\0';
+ buff->truncate(len);
laststartline = exp->locate();
return true;
}
@@ -69,18 +85,18 @@ bool BuffDoc::getline(CBuffer* buff, int w)
{
lastcheck = len;
allsizes[len] = exp->locate();
- while ((ch = getch()) != ' ' && ch != '\012' && ch != UEOF && len < 128)
+ getch(ch, cs);
+ while (ch != ' ' && ch != '\012' && ch != UEOF && len < 128)
{
- (*buff)[len++] = ch;
+ len++;
+ buff->addch(ch,cs);
allsizes[len] = exp->locate();
+ getch(ch, cs);
}
(*buff)[len] = 0;
-#ifdef _UNICODE
- slen = m_fm->width(toQString(buff->data()),len);
-#else
- slen = m_fm->width(buff->data(),len);
-#endif
- (*buff)[len++] = ' ';
+ slen = buff->width(len);
+ len++;
+ buff->addch(' ', cs);
allsizes[len] = exp->locate();
if (slen < w && ch != ' ')
{
@@ -90,37 +106,119 @@ bool BuffDoc::getline(CBuffer* buff, int w)
lastispara = (ch == '\012');
}
(*buff)[len] = '\0';
- lastword = buff->data()+lastcheck;
+// lastword = buff->data()+lastcheck;
+ lastword.setright(*buff, lastcheck);
for (int i = 0; i < lastword.length(); i++) lastsizes[i] = allsizes[i+lastcheck];
if (lastcheck > 0)
{
laststartline = allsizes[lastcheck];
- (*buff)[lastcheck-1] = '\0';
+// (*buff)[lastcheck-1] = '\0';
+ buff->truncate(lastcheck-1);
}
else
{
laststartline = (lastcheck == len) ? exp->locate() : allsizes[lastcheck+1];
- (*buff)[lastcheck] = '\0';
+// (*buff)[lastcheck] = '\0';
+ buff->truncate(lastcheck);
}
-// laststartline = sizes[lastcheck+1];
-// (*buff)[(lastcheck > 0) ? lastcheck-1:lastcheck] = '\0';
+// buff->frig();
return (ch != UEOF);
}
-bool BuffDoc::getline(CBuffer* buff, int w, int cw)
+bool BuffDoc::getline(CDrawBuffer* buff, int w, int cw)
{
+ buff->empty();
if (exp == NULL)
{
- (*buff)[0] = '\0';
return false;
}
tchar ch;
+ CStyle cs;
int i = 0;
- while ((i < w/cw) && ((ch = getch()) != '\012') && (ch != UEOF))
+ while (i*cw < w)
{
- (*buff)[i++] = ch;
+ getch(ch, cs);
+ if (ch == '\12' || ch == UEOF) break;
+ buff->addch(ch,cs);
+ i++;
}
- (*buff)[i] = '\0';
+ buff->truncate(i);
laststartline = exp->locate();
return (ch != UEOF);
}
+
+int BuffDoc::openfile(QWidget* _parent, const char *src)
+{
+ // qDebug("BuffDoc:Openfile:%s", src);
+ // qDebug("Trying aportis %x",exp);
+ if (exp != NULL) delete exp;
+ lastword.empty();
+ lastsizes[0] = laststartline = 0;
+ lastispara = false;
+ /*
+ exp = new Text;
+ int ret = exp->openfile(src);
+ */
+
+ exp = new Aportis;
+ int ret = exp->openfile(src);
+ if (ret == -1)
+ {
+ delete exp;
+ exp = NULL;
+ return ret;
+ }
+ if (ret == -2)
+ {
+
+ delete exp;
+ exp = new ztxt;
+ ret = exp->openfile(src);
+ }
+ if (ret != 0)
+ {
+
+ delete exp;
+ exp = new CPlucker;
+ ret = exp->openfile(src);
+ }
+#ifndef SMALL
+ if (ret != 0)
+ {
+ delete exp;
+ qDebug("Trying ppms");
+ exp = new ppm_expander;
+ ret = exp->openfile(src);
+ }
+
+ if (ret != 0)
+ {
+ delete exp;
+ exp = new Text;
+// qDebug("Trying text");
+ ret = exp->openfile(src);
+ }
+#else
+ if (ret != 0)
+ {
+ delete exp;
+ exp = new Text;
+ ret = exp->openfile(src);
+ }
+#endif
+ if (ret != 0)
+ {
+ delete exp;
+ QMessageBox::information(_parent, "QTReader", "Unknown file compression type","Try another file");
+ return ret;
+ }
+ // qDebug("Doing final open:%x:%x",exp,filt);
+
+ lastword.empty();
+ lastsizes[0] = laststartline = 0;
+ lastispara = false;
+ exp->locate(0);
+ filt->setsource(exp);
+ // qDebug("BuffDoc:file opened");
+ return 0;
+}
diff --git a/noncore/apps/opie-reader/BuffDoc.h b/noncore/apps/opie-reader/BuffDoc.h
index 7c5ef9a..1aac817 100644
--- a/noncore/apps/opie-reader/BuffDoc.h
+++ b/noncore/apps/opie-reader/BuffDoc.h
@@ -1,42 +1,37 @@
#ifndef __BuffDoc_h
#define __BuffDoc_h
-#include "CBuffer.h"
#include "ZText.h"
#include "Aportis.h"
#include "ztxt.h"
#include "ppm_expander.h"
+#include "CDrawBuffer.h"
#include "CFilter.h"
#include <qfontmetrics.h>
#include <qmessagebox.h>
class BuffDoc
{
- CBuffer lastword;
+ CDrawBuffer lastword;
CSizeBuffer lastsizes, allsizes;
size_t laststartline;
bool lastispara;
CExpander* exp;
CFilterChain* filt;
- QFontMetrics* m_fm;
public:
~BuffDoc()
{
delete filt;
delete exp;
}
- BuffDoc() : m_fm(NULL)
+ BuffDoc()
{
exp = NULL;
filt = NULL;
+ lastword.empty();
// qDebug("Buffdoc created");
}
bool empty() { return (exp == NULL); }
- void setfm(QFontMetrics* fm)
- {
- m_fm = fm;
- // qDebug("Buffdoc:setfm");
- }
void setfilter(CFilterChain* _f)
{
if (filt != NULL) delete filt;
@@ -46,87 +41,38 @@ class BuffDoc
CList<Bkmk>* getbkmklist() { return exp->getbkmklist(); }
bool hasrandomaccess() { return (exp == NULL) ? false : exp->hasrandomaccess(); }
bool iseol() { return (lastword[0] == '\0'); }
- int openfile(QWidget* _parent, const char *src)
+ int openfile(QWidget* _parent, const char *src);
+ tchar getch()
{
- // qDebug("BuffDoc:Openfile:%s", src);
- // qDebug("Trying aportis %x",exp);
- if (exp != NULL) delete exp;
- lastword[0] = '\0';
- lastsizes[0] = laststartline = 0;
- lastispara = false;
- /*
- exp = new Text;
- int ret = exp->openfile(src);
- */
-
- exp = new Aportis;
- // qDebug("Calling openfile");
- int ret = exp->openfile(src);
- // qDebug("Called openfile");
- if (ret == -1)
+ tchar ch = UEOF;
+ CStyle sty;
+ if (exp != NULL)
{
- // qDebug("problem opening source file:%s",src);
- delete exp;
- exp = NULL;
- return ret;
+ filt->getch(ch, sty);
}
- if (ret == -2)
- {
-
- delete exp;
-// qDebug("Trying ztxt");
- exp = new ztxt;
- ret = exp->openfile(src);
- }
-#ifndef SMALL
- if (ret != 0)
- {
- delete exp;
-// qDebug("Trying ppms");
- exp = new ppm_expander;
- ret = exp->openfile(src);
- }
-
- if (ret != 0)
- {
- delete exp;
- exp = new Text;
-// qDebug("Trying text");
- ret = exp->openfile(src);
- }
-#else
- if (ret != 0)
- {
- delete exp;
- exp = new Text;
- ret = exp->openfile(src);
- }
-#endif
- if (ret != 0)
+ return ch;
+ }
+ void getch(tchar& ch, CStyle& sty)
+ {
+ if (exp != NULL)
{
- delete exp;
- QMessageBox::information(_parent, "QTReader", "Unknown file compression type","Try another file");
- return ret;
+ filt->getch(ch, sty);
}
- // qDebug("Doing final open:%x:%x",exp,filt);
-
- lastword[0] = '\0';
- lastsizes[0] = laststartline = 0;
- lastispara = false;
- exp->locate(0);
- filt->setsource(exp);
- // qDebug("BuffDoc:file opened");
- return 0;
+ else
+ ch = UEOF;
}
- int getch() { return (exp == NULL) ? UEOF : filt->getch(); }
unsigned int locate() { return (exp == NULL) ? 0 : laststartline; }
+ unsigned int explocate() { return (exp == NULL) ? 0 : exp->locate(); }
+ MarkupType PreferredMarkup() { return (exp == NULL) ? cTEXT : exp->PreferredMarkup(); }
+ bool hyperlink(unsigned int n);
void locate(unsigned int n);
- bool getline(CBuffer* buff, int w);
- bool getline(CBuffer* buff, int w, int cw);
+ bool getline(CDrawBuffer* buff, int w);
+ bool getline(CDrawBuffer* buff, int w, int cw);
void sizes(unsigned long& fs, unsigned long& ts) { exp->sizes(fs,ts); }
int getpara(CBuffer& buff)
{
- int ch, i = 0;
+ tchar ch;
+ int i = 0;
while ((ch = getch()) != 10 && ch != UEOF) buff[i++] = ch;
buff[i] = '\0';
if (i == 0 && ch == UEOF) i = -1;
diff --git a/noncore/apps/opie-reader/CAnnoEdit.h b/noncore/apps/opie-reader/CAnnoEdit.h
new file mode 100644
index 0000000..3cc9f78
--- a/dev/null
+++ b/noncore/apps/opie-reader/CAnnoEdit.h
@@ -0,0 +1,58 @@
+#ifndef __CANNOEDIT_H
+#define __CANNOEDIT_H
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qpushbutton.h>
+#include <qlineedit.h>
+#include <qmultilineedit.h>
+
+class CAnnoEdit : public QWidget
+{
+ Q_OBJECT
+
+ QLineEdit* m_name;
+ QMultiLineEdit* m_anno;
+ size_t m_posn;
+ public:
+ void setPosn(size_t p) { m_posn = p; }
+ size_t getPosn() { return m_posn; }
+ void setName(const QString& name)
+ {
+ m_name->setText(name);
+ }
+ void setAnno(const QString& name)
+ {
+ m_anno->setText(name);
+ m_anno->setEdited(false);
+ }
+ bool edited() { return m_anno->edited(); }
+ CAnnoEdit(QWidget *parent=0, const char *name=0, WFlags f = 0) :
+ QWidget(parent, name, f)
+ {
+ QVBoxLayout* grid = new QVBoxLayout(this);
+ m_name = new QLineEdit(this, "Name");
+ m_anno = new QMultiLineEdit(this, "Annotation");
+ QPushButton* exitButton = new QPushButton("Okay", this);
+ connect(exitButton, SIGNAL( released() ), this, SLOT( slotOkay() ) );
+ QPushButton* cancelButton = new QPushButton("Cancel", this);
+ connect(cancelButton, SIGNAL( released() ), this, SLOT( slotCancel() ) );
+ QLabel *l = new QLabel("Text",this);
+ grid->addWidget(l);
+ grid->addWidget(m_name);
+ l = new QLabel("Annotation",this);
+ grid->addWidget(l);
+ grid->addWidget(m_anno,1);
+ QHBoxLayout* hgrid = new QHBoxLayout(grid);
+ hgrid->addWidget(cancelButton);
+ hgrid->addWidget(exitButton);
+ }
+ private slots:
+ void slotOkay() { emit finished(m_name->text(), m_anno->text()); }
+ void slotCancel() { emit cancelled(); }
+ public:
+ signals:
+ void finished(const QString&, const QString&);
+ void cancelled();
+};
+
+#endif
diff --git a/noncore/apps/opie-reader/CBuffer.cpp b/noncore/apps/opie-reader/CBuffer.cpp
index db52476..526b25f 100644
--- a/noncore/apps/opie-reader/CBuffer.cpp
+++ b/noncore/apps/opie-reader/CBuffer.cpp
@@ -1,35 +1,46 @@
#include "CBuffer.h"
-CBuffer& CBuffer::operator=(const tchar*sztmp)
+CBufferBase& CBufferBase::assign(const void* sztmp, size_t ms)
{
- int i;
- for (i = 0; sztmp[i] != '\0'; i++) (*this)[i] = sztmp[i];
- (*this)[i] = '\0';
- return *this;
+ if (ms*membersize > len)
+ {
+ delete [] buffer;
+ buffer = new unsigned char[len = ms*membersize];
+ }
+ memcpy(buffer, sztmp, ms*membersize);
+ return *this;
+}
+
+CBufferBase::CBufferBase(size_t ms, size_t n = 16) : len(n), membersize(ms)
+{
+ buffer = new unsigned char[len*membersize];
+ memset(buffer, 0, len*membersize);
}
-tchar& CBuffer::operator[](int i)
+void* CBufferBase::operator[](int i)
{
- if (i >= len)
+ if ((i+1)*membersize > len)
{
- tchar *newbuff = new tchar[i+1];
- memcpy(newbuff,buffer,sizeof(tchar)*len);
- delete [] buffer;
- buffer = newbuff;
- len = i+1;
+ unsigned char* oldbuffer = buffer;
+ buffer = new unsigned char[(i+1)*membersize];
+ memcpy(buffer, oldbuffer, len);
+ memset(buffer+len, 0, (i+1)*membersize-len);
+ len = (i+1)*membersize;
+ delete [] oldbuffer;
}
- return buffer[i];
+ return buffer+i*membersize;
}
-size_t& CSizeBuffer::operator[](int i)
+size_t CBufferBase::bstrlen(unsigned char* _buffer = NULL)
{
- if (i >= len)
+ if (_buffer == NULL) _buffer = buffer;
+ unsigned char* zero = new unsigned char[membersize];
+ memset(zero,0,membersize);
+ unsigned char* element = _buffer;
+ while (memcmp(element, zero, membersize) != 0)
{
- size_t *newbuff = new size_t[i+1];
- memcpy(newbuff,buffer,sizeof(size_t)*len);
- delete [] buffer;
- buffer = newbuff;
- len = i+1;
+ element += membersize;
}
- return buffer[i];
+ delete [] zero;
+ return (element - _buffer)/membersize;
}
diff --git a/noncore/apps/opie-reader/CBuffer.h b/noncore/apps/opie-reader/CBuffer.h
index 9807d27..252f3ac 100644
--- a/noncore/apps/opie-reader/CBuffer.h
+++ b/noncore/apps/opie-reader/CBuffer.h
@@ -5,41 +5,51 @@
#include <string.h>
#include "config.h"
-class CBuffer
+
+class CBufferBase
{
+ protected:
size_t len;
- tchar *buffer;
- CBuffer(const CBuffer&);
+ unsigned char *buffer;
+ size_t membersize;
+ CBufferBase(const CBufferBase&);
public:
- CBuffer& operator=(const tchar*sztmp);
-#ifdef _UNICODE
- size_t length() { return ustrlen(buffer); }
-#else
- size_t length() { return strlen(buffer); }
-#endif
- tchar* data() { return buffer; }
- CBuffer(size_t n = 16) : len(n)
- {
- buffer = new tchar[len];
- buffer[0] = '\0';
- }
- ~CBuffer() { delete [] buffer; }
- tchar& operator[](int i);
+ CBufferBase& assign(const void* sztmp, size_t ms);
+ void* data() { return buffer; }
+ CBufferBase(size_t ms, size_t n = 16);
+ ~CBufferBase() { delete [] buffer; }
+ void* operator[](int i);
+ size_t bstrlen(unsigned char* _buffer = NULL);
+ size_t totallen() { return len; }
};
-class CSizeBuffer
+template<class T>
+class CBufferFace
{
- size_t len;
- size_t *buffer;
- CSizeBuffer(const CSizeBuffer&);
+ CBufferBase m_buffer;
+ protected:
+ CBufferFace(const CBufferFace&);
public:
- size_t* data() { return buffer; }
- CSizeBuffer(size_t n = 16) : len(n)
- {
- buffer = new size_t[len];
- }
- ~CSizeBuffer() { delete [] buffer; }
- size_t& operator[](int i);
+ CBufferFace& operator=(const T* sztmp)
+ {
+ m_buffer.assign(sztmp, m_buffer.bstrlen(sztmp));
+ return *this;
+ }
+ void assign(const T* sztmp, size_t n)
+ {
+ m_buffer.assign(sztmp, n);
+ }
+ size_t length() { return m_buffer.bstrlen(); }
+ size_t totallen() { return m_buffer.totallen(); }
+ T* data() { return (T*)m_buffer.data(); }
+ CBufferFace(size_t n = 16) : m_buffer(sizeof(T), n) {}
+ T& operator[](int i)
+ {
+ return *((T*)m_buffer[i]);
+ }
};
+typedef CBufferFace<tchar> CBuffer;
+typedef CBufferFace<size_t> CSizeBuffer;
+
#endif
diff --git a/noncore/apps/opie-reader/CEncoding.cpp b/noncore/apps/opie-reader/CEncoding.cpp
index 18d18d3..c1dcfe8 100644
--- a/noncore/apps/opie-reader/CEncoding.cpp
+++ b/noncore/apps/opie-reader/CEncoding.cpp
@@ -1,10 +1,15 @@
#include <stdio.h>
#include "CEncoding.h"
-tchar CUtf8::getch()
+void CUtf8::getch(tchar& ch, CStyle& sty)
{
- int iret = parent->getch();
- if (iret == EOF) return UEOF;
+ int iret;
+ parent->getch(iret, sty);
+ if (iret == EOF)
+ {
+ ch = UEOF;
+ return;
+ }
tchar ret = iret;
int count = 0;
if (ret & (1 << 7))
@@ -13,7 +18,8 @@ tchar CUtf8::getch()
while ((flags & (1 << 7)) != 0)
{
ret <<= 6;
- ret += parent->getch() & 0x3f;
+ parent->getch(iret, sty);
+ ret += iret & 0x3f;
flags <<= 1;
count++;
}
@@ -33,118 +39,172 @@ tchar CUtf8::getch()
printf("Only 16bit unicode supported...");
}
}
- return ret;
+ ch = ret;
+ return;
}
-
-tchar CUcs16be::getch()
+void CUcs16be::getch(tchar& ch, CStyle& sty)
{
- int iret = parent->getch();
- if (iret == EOF) return UEOF;
+ int iret;
+ parent->getch(iret, sty);
+ if (iret == EOF)
+ {
+ ch = UEOF;
+ return;
+ }
tchar ret = iret;
- return (ret << 8) + parent->getch();
+ parent->getch(iret, sty);
+ ch = (ret << 8) + iret;
}
-tchar CUcs16le::getch()
+void CUcs16le::getch(tchar& ch, CStyle& sty)
{
- int iret = parent->getch();
- if (iret == EOF) return UEOF;
+ int iret;
+ parent->getch(iret, sty);
+ if (iret == EOF)
+ {
+ ch = UEOF;
+ return;
+ }
tchar ret = iret;
- return ret + (parent->getch() << 8);
+ parent->getch(iret, sty);
+ ch = ret + (iret << 8);
}
-tchar Ccp1252::getch()
+void Ccp1252::getch(tchar& ch, CStyle& sty)
{
- int iret = parent->getch();
- switch (iret)
+ int iret;
+ parent->getch(iret, sty);
+ ch = iret;
+ switch (ch)
{
case EOF:
- return UEOF;
+ ch = UEOF;
+ break;
case 0x80:
- return 0x20ac;
+ ch = 0x20ac;
+ break;
case 0x82:
- return 0x201a;
+ ch = 0x201a;
+ break;
case 0x83:
- return 0x0192;
+ ch = 0x0192;
+ break;
case 0x84:
- return 0x201e;
+ ch = 0x201e;
+ break;
case 0x85:
- return 0x2026;
+ ch = 0x2026;
+ break;
case 0x86:
- return 0x2020;
+ ch = 0x2020;
+ break;
case 0x87:
- return 0x2021;
+ ch = 0x2021;
+ break;
case 0x88:
- return 0x02c6;
+ ch = 0x02c6;
+ break;
case 0x89:
- return 0x2030;
+ ch = 0x2030;
+ break;
case 0x8a:
- return 0x0160;
+ ch = 0x0160;
+ break;
case 0x8b:
- return 0x2039;
+ ch = 0x2039;
+ break;
case 0x8c:
- return 0x0152;
+ ch = 0x0152;
+ break;
case 0x8e:
- return 0x017d;
+ ch = 0x017d;
+ break;
case 0x91:
- return 0x2018;
+ ch = 0x2018;
+ break;
case 0x92:
- return 0x2019;
+ ch = 0x2019;
+ break;
case 0x93:
- return 0x201c;
+ ch = 0x201c;
+ break;
case 0x94:
- return 0x201d;
+ ch = 0x201d;
+ break;
case 0x95:
- return 0x2022;
+ ch = 0x2022;
+ break;
case 0x96:
- return 0x2013;
+ ch = 0x2013;
+ break;
case 0x97:
- return 0x2014;
+ ch = 0x2014;
+ break;
case 0x98:
- return 0x02dc;
+ ch = 0x02dc;
+ break;
case 0x99:
- return 0x2122;
+ ch = 0x2122;
+ break;
case 0x9a:
- return 0x0161;
+ ch = 0x0161;
+ break;
case 0x9b:
- return 0x203a;
+ ch = 0x203a;
+ break;
case 0x9c:
- return 0x0153;
+ ch = 0x0153;
+ break;
case 0x9e:
- return 0x017e;
+ ch = 0x017e;
+ break;
case 0x9f:
- return 0x0178;
+ ch = 0x0178;
+ break;
default:
- return iret;
+ break;
}
}
-tchar CPalm::getch()
+void CPalm::getch(tchar& ch, CStyle& sty)
{
- tchar iret = Ccp1252::getch();
- switch (iret)
+ Ccp1252::getch(ch, sty);
+ switch (ch)
{
case 0x18:
- return 0x2026;
+ ch = 0x2026;
+ break;
case 0x19:
- return 0x2007;
+ ch = 0x2007;
+ break;
case 0x8d:
- return 0x2662;
+ ch = 0x2662;
+ break;
case 0x8e:
- return 0x2663;
+ ch = 0x2663;
+ break;
case 0x8f:
- return 0x2661;
+ ch = 0x2661;
+ break;
case 0x90:
- return 0x2660;
+ ch = 0x2660;
+ break;
default:
- return iret;
+ break;
}
}
-tchar CAscii::getch()
+void CAscii::getch(tchar& ch, CStyle& sty)
{
- int iret = parent->getch();
- if (iret == EOF) return UEOF;
- return iret;
+ int iret;
+ parent->getch(iret, sty);
+ if (iret == EOF)
+ {
+ ch = UEOF;
+ }
+ else
+ {
+ ch = iret;
+ }
}
-
diff --git a/noncore/apps/opie-reader/CEncoding.h b/noncore/apps/opie-reader/CEncoding.h
index 1eee29e..86562e7 100644
--- a/noncore/apps/opie-reader/CEncoding.h
+++ b/noncore/apps/opie-reader/CEncoding.h
@@ -17,37 +17,37 @@ public:
class CUtf8 : public CEncoding
{
public:
- tchar getch();
+ void getch(tchar& ch, CStyle& sty);
};
class CUcs16be : public CEncoding
{
public:
- tchar getch();
+ void getch(tchar& ch, CStyle& sty);
};
class CUcs16le : public CEncoding
{
public:
- tchar getch();
+ void getch(tchar& ch, CStyle& sty);
};
class Ccp1252 : public CEncoding
{
public:
- virtual tchar getch();
+ void getch(tchar& ch, CStyle& sty);
};
class CPalm : public Ccp1252
{
public:
- tchar getch();
+ void getch(tchar& ch, CStyle& sty);
};
class CAscii : public CEncoding
{
public:
- tchar getch();
+ void getch(tchar& ch, CStyle& sty);
};
#endif
diff --git a/noncore/apps/opie-reader/CExpander.h b/noncore/apps/opie-reader/CExpander.h
index 07c14fa..b1147a6 100644
--- a/noncore/apps/opie-reader/CExpander.h
+++ b/noncore/apps/opie-reader/CExpander.h
@@ -1,132 +1,19 @@
#ifndef __CExpander_h
#define __CExpander_h
-#include "my_list.h"
#include "config.h"
+#include "StyleConsts.h"
+#include "Markups.h"
-class Bkmk
-{
- friend class BkmkFile;
- tchar* m_name;
- unsigned int m_position;
- public:
- Bkmk() : m_name(NULL), m_position(0) {};
- Bkmk(const tchar* _nm, unsigned int _p) : m_position(_p)
- {
- int len = ustrlen(_nm)+1;
- m_name = new tchar[len];
- for (int i = 0; i < len; i++) m_name[i] = _nm[i];
- }
- Bkmk(const Bkmk& rhs) : m_name(NULL)
- {
- *this = rhs;
- }
- ~Bkmk() { if (m_name != NULL) delete [] m_name; }
- unsigned int value() const { return m_position; }
- tchar *name() const { return m_name; }
- bool operator<(const Bkmk& rhs) { return (m_position < rhs.m_position); }
- Bkmk& operator=(const Bkmk& rhs)
- {
- if (m_name != NULL) delete [] m_name;
- if (rhs.m_name != NULL)
- {
- int len = ustrlen(rhs.m_name)+1;
- m_name = new tchar[len];
- for (int i = 0; i < len; i++) m_name[i] = rhs.m_name[i];
- }
- else
- m_name = NULL;
- m_position = rhs.m_position;
- return *this;
- }
- bool operator==(const Bkmk& rhs)
- {
- return (m_position == rhs.m_position && ustrcmp(m_name,rhs.m_name) == 0);
- }
-};
+class Bkmk;
-class BkmkFile
-{
- FILE* f;
- bool wt;
-public:
- BkmkFile(const char *fnm, bool w = false)
- :
- wt(w)
- {
- if (w)
- f = fopen(fnm, "wb");
- else
- f = fopen(fnm, "rb");
- }
- ~BkmkFile()
- {
- if (f != NULL) fclose(f);
- }
- void write(tchar* nm, const unsigned int& pos)
- {
- if (f != NULL)
- {
- unsigned short ln = ustrlen(nm);
- fwrite(&ln,sizeof(ln),1,f);
- fwrite(nm,sizeof(tchar),ln,f);
- fwrite(&pos,sizeof(pos),1,f);
- }
- }
- void write(const Bkmk& b) { write(b.name(), b.value()); }
- void write(CList<Bkmk>& bl)
- {
- if (f != NULL)
- {
- for (CList<Bkmk>::iterator i = bl.begin(); i != bl.end(); i++)
- {
- write(*i);
- }
- }
- }
- Bkmk* read()
- {
- Bkmk* b = NULL;
- if (f != NULL)
- {
- unsigned short ln;
- if (fread(&ln,sizeof(ln),1,f) == 1)
- {
- b = new Bkmk;
- b->m_name = new tchar[ln+1];
- fread(b->m_name,sizeof(tchar),ln,f);
- b->m_name[ln] = 0;
- fread(&b->m_position,sizeof(b->m_position),1,f);
- }
- }
- return b;
- }
- CList<Bkmk>* readall()
- {
- CList<Bkmk>* bl = NULL;
- if (f != NULL)
- {
- bl = new CList<Bkmk>;
- while (1)
- {
- Bkmk* b = read();
- if (b == NULL) break;
- bl->push_back(*b);
- delete b;
- }
- }
- return bl;
- }
-};
+template<class T>
+class CList;
class CCharacterSource
{
public:
-#ifdef _UNICODE
- virtual tchar getch() = 0;
-#else
- virtual int getch() = 0;
-#endif
+ virtual void getch(tchar&, CStyle&) = 0;
};
class CExpander
@@ -140,6 +27,17 @@ class CExpander
virtual bool hasrandomaccess() = 0;
virtual void sizes(unsigned long& file, unsigned long& text) = 0;
virtual CList<Bkmk>* getbkmklist() { return NULL; }
+ virtual void getch(int& ch, CStyle& sty)
+ {
+ ch = getch();
+ sty.unset();
+ }
virtual int getch() = 0;
+ virtual bool hyperlink(unsigned int n)
+ {
+ locate(n);
+ return true;
+ }
+ virtual MarkupType PreferredMarkup() = 0;
};
#endif
diff --git a/noncore/apps/opie-reader/CFilter.cpp b/noncore/apps/opie-reader/CFilter.cpp
new file mode 100644
index 0000000..c17cf61
--- a/dev/null
+++ b/noncore/apps/opie-reader/CFilter.cpp
@@ -0,0 +1,561 @@
+#include "CDrawBuffer.h"
+#include "CFilter.h"
+
+unsigned short striphtml::skip_ws()
+{
+ tchar ch;
+ CStyle sty;
+ do
+ {
+ parent->getch(ch, sty);
+ }
+ while (ch < 33);
+ return ch;
+}
+
+unsigned short striphtml::skip_ws_end()
+{
+ tchar ch;
+ CStyle sty;
+ parent->getch(ch, sty);
+ if (ch == ' ')
+ {
+ do
+ {
+ parent->getch(ch, sty);
+ }
+ while (ch != '>');
+ }
+ return ch;
+}
+
+unsigned short striphtml::parse_m()
+{
+ tchar ch;
+ CStyle sty;
+ parent->getch(ch, sty);
+ if (ch == 'm' || ch == 'M')
+ {
+ ch = skip_ws_end();
+ if (ch == '>')
+ {
+ return 0;
+ }
+ }
+ return ch;
+}
+
+void striphtml::mygetch(tchar& ch, CStyle& sty)
+{
+ parent->getch(ch, sty);
+ if (ch == 10) ch = ' ';
+}
+
+void striphtml::getch(tchar& ch, CStyle& sty)
+{
+ CStyle dummy;
+ mygetch(ch, dummy);
+ if (ch == 10) ch = ' ';
+ while (ch == '<')
+ {
+ ch = skip_ws();
+
+ switch (ch)
+ {
+ case 'p':
+ case 'P':
+ ch = skip_ws_end();
+ if (ch == '>')
+ {
+ ch = 10;
+ continue;
+ }
+ break;
+ case 'b':
+ case 'B':
+ ch = skip_ws_end();
+ if (ch == '>')
+ {
+ currentstyle.setBold();
+ mygetch(ch, dummy);
+ continue;
+ }
+ else if (ch == 'r' || ch == 'R')
+ {
+ ch = skip_ws_end();
+ if (ch == '>')
+ {
+ ch = 10;
+ continue;
+ }
+ }
+ break;
+ case 'i':
+ case 'I':
+ ch = skip_ws_end();
+ if (ch == '>')
+ {
+ currentstyle.setItalic();
+ mygetch(ch, dummy);
+ continue;
+ }
+ break;
+ case 'e':
+ case 'E':
+ if ((ch = parse_m()) == 0)
+ {
+ currentstyle.setItalic();
+ mygetch(ch, dummy);
+ continue;
+ }
+ break;
+ case 'h':
+ case 'H':
+ mygetch(ch, dummy);
+ if ('0' < ch && ch <= '9')
+ {
+ tchar hs = ch;
+ ch = skip_ws_end();
+ if (ch == '>')
+ {
+ switch (hs)
+ {
+ case '1':
+// currentstyle = ucBold | ucFontBase+2 | (ucAlignCentre << ucAlignShift);
+ currentstyle.unset();
+ currentstyle.setFontSize(2);
+ currentstyle.setBold();
+ currentstyle.setCentreJustify();
+ break;
+ case '2':
+// currentstyle = ucBold | ucFontBase+1;
+ currentstyle.unset();
+ currentstyle.setFontSize(1);
+ currentstyle.setBold();
+ break;
+ default:
+// currentstyle = ucBold | ucFontBase;
+ currentstyle.unset();
+ currentstyle.setBold();
+ }
+ ch = 10;
+// mygetch(ch, dummy);
+ continue;
+ }
+ }
+ break;
+ case '/':
+ mygetch(ch, dummy);
+ switch (ch)
+ {
+ case 'b':
+ case 'B':
+ ch = skip_ws_end();
+ if (ch == '>')
+ {
+ currentstyle.unsetBold();
+ mygetch(ch, dummy);
+ continue;
+ }
+ break;
+ case 'i':
+ case 'I':
+ ch = skip_ws_end();
+ if (ch == '>')
+ {
+ currentstyle.unsetItalic();
+ mygetch(ch, dummy);
+ continue;
+ }
+ break;
+ case 'e':
+ case 'E':
+ if ((ch = parse_m()) == 0)
+ {
+ currentstyle.unsetItalic();
+ mygetch(ch, dummy);
+ continue;
+ }
+ break;
+ case 'h':
+ case 'H':
+ mygetch(ch, dummy);
+ if ('0' < ch && ch <= '9')
+ {
+ ch = skip_ws_end();
+ if (ch == '>')
+ {
+ currentstyle.unset();
+ //mygetch(ch, dummy);
+ ch = 10;
+ continue;
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+ while (ch != '>' && ch != UEOF)
+ {
+ mygetch(ch, dummy);
+ }
+ mygetch(ch, dummy);
+ }
+ if (ch == '&')
+ {
+ mygetch(ch, dummy);
+ if (ch == '#')
+ {
+ int id = 0;
+ mygetch(ch, dummy);
+ while (ch != ';' && ch != UEOF)
+ {
+ id = 10*id+ch-'0';
+ mygetch(ch, dummy);
+ }
+ ch = id;
+ }
+ }
+// sty = (dummy == ucFontBase) ? currentstyle : dummy;
+ sty = currentstyle;
+ return;
+}
+
+
+void textfmt::mygetch(tchar& ch, CStyle& sty)
+{
+ if (uselast)
+ {
+ ch = lastchar;
+ uselast = false;
+ }
+ else
+ {
+ parent->getch(ch, sty);
+ }
+}
+
+void textfmt::getch(tchar& ch, CStyle& sty)
+{
+ mygetch(ch, sty);
+ do
+ {
+ sty = currentstyle;
+ switch (ch)
+ {
+ case 10:
+ currentstyle.unset();
+ sty = currentstyle;
+ break;
+// Use this if you want to replace -- by em-dash
+ case '-':
+// parent->getch(ch, sty);
+ mygetch(ch, sty);
+ if (ch == '-')
+ {
+ ch = 0x2014;
+ }
+ else
+ {
+ lastchar = ch;
+ uselast = true;
+ ch = '-';
+ }
+ break;
+ case '*':
+ if (currentstyle.isBold())
+ {
+// Already bold - time to turn it off?
+// The next two lines ensure that * follows a character but it works better without
+// QChar c(lastchar);
+// if ((lastchar != '*') && (c.isPunct() || c.isLetterOrNumber()))
+ if (lastchar != '*')
+ {
+ currentstyle.unsetBold();
+ CStyle dummy;
+// parent->getch(ch, dummy);
+ mygetch(ch, dummy);
+ }
+ }
+ else
+ {
+// not bold - time to turn it on?
+ CStyle dummy;
+// parent->getch(ch, dummy);
+ mygetch(ch, dummy);
+ QChar c(ch);
+ if ((ch != '*') && (c.isPunct() || c.isLetterOrNumber()))
+ {
+ currentstyle.setBold();
+ }
+ else
+ {
+ lastchar = ch;
+ uselast = true;
+ ch = '*';
+ }
+
+ }
+ break;
+ case '_':
+ if (currentstyle.isItalic())
+ {
+// Already bold - time to turn it off?
+// The next two lines ensure that * follows a character but it works better without
+// QChar c(lastchar);
+// if ((lastchar != '_') && (c.isPunct() || c.isLetterOrNumber()))
+ if (lastchar != '_')
+ {
+ currentstyle.unsetItalic();
+ CStyle dummy;
+// parent->getch(ch, dummy);
+ mygetch(ch, dummy);
+ }
+ }
+ else
+ {
+// not bold - time to turn it on?
+ CStyle dummy;
+// parent->getch(ch, dummy);
+ mygetch(ch, dummy);
+ QChar c(ch);
+ if ((ch != '_') && (c.isPunct() || c.isLetterOrNumber()))
+ {
+ currentstyle.setItalic();
+ }
+ else
+ {
+ lastchar = ch;
+ uselast = true;
+ ch = '_';
+ }
+
+ }
+ break;
+ }
+ }
+ while (sty != currentstyle);
+ if (!uselast) lastchar = ch;
+ return;
+}
+
+void remap::getch(tchar& ch, CStyle& sty)
+{
+ if (q[offset] != 0)
+ {
+ q[offset++];
+ sty = currentstyle;
+ return;
+ }
+ parent->getch(ch, sty);
+ switch (ch)
+ {
+ case 0x201a:
+ ch = '\'';
+ break;
+ case 0x0192:
+ ch = 'f';
+ break;
+ case 0x201e:
+ ch = '"';
+ break;
+ case 0x2026:
+ offset = 0;
+ q[0] = '.';
+ q[1] = '.';
+ q[2] = 0;
+ ch = '.'; // should be ...
+ break;
+ case 0x0160:
+ ch = 'S';
+ break;
+ case 0x2039:
+ ch = '<';
+ break;
+ case 0x0152:
+ offset = 0;
+ q[0] = 'E';
+ q[1] = 0;
+ ch = 'O';
+ break;
+ case 0x017d:
+ ch = 'Z';
+ break;
+ case 0x2018:
+ ch = '\'';
+ break;
+ case 0x2019:
+ ch = '\'';
+ break;
+ case 0x201c:
+ ch = '"';
+ break;
+ case 0x201d:
+ ch = '"';
+ break;
+ case 0x2022:
+ ch = '>';
+ break;
+ case 0x2013:
+ ch = '-';
+ break;
+ case 0x2014:
+ offset = 0;
+ q[0] = '-';
+ q[1] = 0;
+ ch = '-'; // should be --
+ break;
+ case 0x02dc:
+ ch = '~';
+ break;
+ case 0x0161:
+ ch = 's';
+ break;
+ case 0x203a:
+ ch = '>';
+ break;
+ case 0x0153:
+ offset = 0;
+ q[0] = 'e';
+ q[1] = 0;
+ ch = 'o';// should be oe
+ break;
+ case 0x017e:
+ ch = 'z';
+ break;
+ case 0x0178:
+ ch = 'Y';
+ break;
+ }
+ currentstyle = sty;
+}
+
+void PeanutFormatter::getch(tchar& ch, CStyle& sty)
+{
+ CStyle dummy;
+ currentstyle.setColour(0,0,0);
+ parent->getch(ch, dummy);
+ while (ch == '\\')
+ {
+ parent->getch(ch, dummy);
+ if (ch == '\\') break;
+ switch(ch)
+ {
+ case 'a':
+ {
+ int code = 0;
+ for (int i = 0; i < 3; i++)
+ {
+ parent->getch(ch, dummy);
+ code = 10*code + ch - '0';
+ }
+ ch = code;
+ }
+ break;
+ case 'v':
+ {
+ while (1)
+ {
+ parent->getch(ch, dummy);
+ if (ch == '\\')
+ {
+ parent->getch(ch, dummy);
+ if (ch == 'v')
+ {
+ parent->getch(ch, dummy);
+ break;
+ }
+ }
+ }
+ }
+ break;
+ case 's':
+ case 'n':
+ currentstyle.setFontSize(0);
+ parent->getch(ch,dummy);
+ break;
+ case 'p':
+ currentstyle.unset();
+// parent->getch(ch,dummy);
+ ch = 10;
+ break;
+ case 'l':
+ if (currentstyle.getFontSize() == 1)
+ {
+ currentstyle.setFontSize(0);
+ }
+ else
+ {
+ currentstyle.setFontSize(1);
+ }
+ parent->getch(ch, dummy);
+ break;
+ case 'x':
+ if (currentstyle.getFontSize() == 0)
+ {
+// currentstyle.unset();
+// currentstyle.setBold();
+ currentstyle.setFontSize(1);
+ }
+ else
+ {
+ currentstyle.unset();
+ }
+// parent->getch(ch, dummy);
+ ch = 10;
+ break;
+ case 'i':
+ if (currentstyle.isItalic())
+ {
+ currentstyle.unsetItalic();
+ }
+ else
+ {
+ currentstyle.setItalic();
+ }
+ parent->getch(ch, dummy);
+ break;
+ case 'b':
+ case 'B':
+ if (currentstyle.isBold())
+ {
+ currentstyle.unsetBold();
+ }
+ else
+ {
+ currentstyle.setBold();
+ }
+ parent->getch(ch, dummy);
+ break;
+ case 'c':
+ if (currentstyle.getJustify() == CStyle::m_AlignCentre)
+ {
+ currentstyle.setLeftJustify();
+ }
+ else
+ {
+ currentstyle.setCentreJustify();
+ }
+ parent->getch(ch, dummy);
+ break;
+ case 'r':
+ if (currentstyle.getJustify() == CStyle::m_AlignRight)
+ {
+ currentstyle.setLeftJustify();
+ }
+ else
+ {
+ currentstyle.setRightJustify();
+ }
+ parent->getch(ch, dummy);
+ break;
+ default:
+ currentstyle.setColour(255,0,0);
+ }
+ }
+ sty = currentstyle;
+}
diff --git a/noncore/apps/opie-reader/CFilter.h b/noncore/apps/opie-reader/CFilter.h
index 4f609dc..8cfd7eb 100644
--- a/noncore/apps/opie-reader/CFilter.h
+++ b/noncore/apps/opie-reader/CFilter.h
@@ -6,28 +6,13 @@
class CFilter : public CCharacterSource
{
- friend class CFilterChain;
+ friend class CFilterChain;
protected:
- CCharacterSource* parent;
-public:
- CFilter() : parent(NULL) {}
- void setparent(CCharacterSource* p) { parent = p; }
- virtual ~CFilter() {};
-};
-
-class vanilla : public CFilter
-{
-public:
- vanilla() {}
- virtual ~vanilla() {}
-#ifdef _UNICODE
- virtual tchar getch()
-#else
- virtual int getch()
-#endif
- {
- return parent->getch();
- }
+ CCharacterSource* parent;
+ public:
+ CFilter() : parent(NULL) {}
+ void setparent(CCharacterSource* p) { parent = p; }
+ virtual ~CFilter() {};
};
class CFilterChain
@@ -49,7 +34,10 @@ class CFilterChain
}
delete encoder;
}
- int getch() { return front->getch(); }
+ void getch(tchar& ch, CStyle& sty)
+ {
+ front->getch(ch, sty);
+ }
void addfilter(CFilter* p)
{
if (first == NULL)
@@ -79,276 +67,203 @@ class CFilterChain
class stripcr : public CFilter
{
-public:
- stripcr() {}
- virtual ~stripcr() {}
-#ifdef _UNICODE
- virtual tchar getch()
- {
- tchar ch;
- do
- {
- ch = parent->getch();
- }
- while (ch == 13);
- return ch;
- }
-#else
- virtual int getch()
- {
- int ch;
- do
- {
- ch = parent->getch();
- }
- while (ch == 13);
- return ch;
- }
-#endif
+ public:
+ stripcr() {}
+ virtual ~stripcr() {}
+ virtual void getch(tchar& ch, CStyle& sty)
+ {
+ do
+ {
+ parent->getch(ch, sty);
+ }
+ while (ch == 13);
+ }
};
class dehyphen : public CFilter
{
bool m_bCharWaiting;
tchar m_nextChar;
+ CStyle m_nextSty;
public:
dehyphen() : m_bCharWaiting(false) {}
virtual ~dehyphen() {}
- virtual tchar getch()
+ virtual void getch(tchar& ch, CStyle& sty)
{
if (m_bCharWaiting)
{
m_bCharWaiting = false;
- return m_nextChar;
+ ch = m_nextChar;
+ sty = m_nextSty;
+ return;
}
- tchar ch = parent->getch();
- if (ch != '-') return ch;
- m_nextChar = parent->getch();
+ parent->getch(ch, sty);
+ if (ch != '-') return;
+ parent->getch(m_nextChar, m_nextSty);
if (m_nextChar != 10)
{
m_bCharWaiting = true;
- return '-';
+ ch = '-';
+ return;
}
- return parent->getch();
+ parent->getch(ch, sty);
}
};
class striphtml : public CFilter
{
-public:
- striphtml() {}
- virtual ~striphtml() {}
-#ifdef _UNICODE
- virtual tchar getch()
- {
- tchar ch;
- ch = parent->getch();
- while (ch == '<')
- {
- while (ch != '>')
- {
- ch = parent->getch();
- }
- ch = parent->getch();
- }
- if (ch == '&')
- {
- ch = parent->getch();
- if (ch == '#')
- {
- int id = 0;
- while ((ch = parent->getch()) != ';') id = 10*id+ch-'0';
- ch = id;
- }
- }
- return ch;
- }
-#else
- virtual int getch()
- {
- int ch;
- ch = parent->getch();
- while (ch == '<')
- {
- while (ch != '>')
- {
- ch = parent->getch();
- }
- ch = parent->getch();
- }
- if (ch == '&')
- {
- ch = parent->getch();
- if (ch == '#')
- {
- int id = 0;
- while ((ch = parent->getch()) != ';') id = 10*id+ch-'0';
- ch = id;
- }
- }
- return ch;
- }
-#endif
+ CStyle currentstyle;
+ unsigned short skip_ws();
+ unsigned short skip_ws_end();
+ unsigned short parse_m();
+ void mygetch(tchar& ch, CStyle& sty);
+ public:
+ striphtml() {}
+ virtual ~striphtml() {}
+ virtual void getch(tchar& ch, CStyle& sty);
};
class unindent : public CFilter
{
- tchar lc;
-public:
- unindent() : lc(0) {}
- virtual ~unindent() {}
-#ifdef _UNICODE
- virtual tchar getch()
- {
- tchar ch;
- if (lc == 10)
- {
- while ((ch = parent->getch()) == ' ');
- }
- else ch = parent->getch();
- lc = ch;
- return ch;
- }
-#else
- virtual int getch()
- {
- int ch;
- if (lc == 10)
- {
- while ((ch = parent->getch()) == ' ');
- }
- else ch = parent->getch();
- lc = ch;
- return ch;
- }
-#endif
+ tchar lc;
+ public:
+ unindent() : lc(0) {}
+ virtual ~unindent() {}
+ virtual void getch(tchar& ch, CStyle& sty)
+ {
+ if (lc == 10)
+ {
+ do
+ {
+ parent->getch(ch, sty);
+ }
+ while (ch == ' ');
+ }
+ else parent->getch(ch, sty);
+ lc = ch;
+ return;
+ }
};
-#ifdef _UNICODE
class repara : public CFilter
{
- tchar tch;
-public:
- repara() : tch(0) {}
- virtual ~repara() {}
- virtual tchar getch()
- {
- tchar ch = parent->getch();
- if (ch == 10)
- {
- if (tch == 10)
- {
- return ch;
- }
- else
- {
- tch = ch;
- return ' ';
- }
- }
- tch = ch;
- return ch;
- }
-};
-#else
-class repara : public CFilter
-{
- int tch;
-public:
- repara() : tch(0) {}
- virtual ~repara() {}
- virtual int getch()
- {
- int ch = parent->getch();
- if (ch == 10)
- {
- if (tch == 10)
- {
- return ch;
- }
- else
- {
+ tchar tch;
+ public:
+ repara() : tch(0) {}
+ virtual ~repara() {}
+ virtual void getch(tchar& ch, CStyle& sty)
+ {
+ parent->getch(ch, sty);
+ if (ch == 10)
+ {
+ if (tch == 10)
+ {
+ return;
+ }
+ else
+ {
+ tch = ch;
+ ch = ' ';
+ return;
+ }
+ }
tch = ch;
- return ' ';
- }
- }
- tch = ch;
- return ch;
- }
+ return;
+ }
};
-#endif
class indenter : public CFilter
{
- int amnt;
- int indent;
-public:
- indenter(int _a=5) : amnt(_a), indent(0) {}
- virtual ~indenter() {}
-#ifdef _UNICODE
- virtual tchar getch()
- {
- if (indent > 0)
- {
- indent--;
- return ' ';
- }
- tchar ch = parent->getch();
- if (ch == 10)
- {
- indent = amnt;
- }
- return ch;
- }
-#else
- virtual int getch()
- {
- if (indent > 0)
- {
- indent--;
- return ' ';
- }
- int ch = parent->getch();
- if (ch == 10)
+ int amnt;
+ int indent;
+ CStyle lsty;
+ public:
+ indenter(int _a=5) : amnt(_a), indent(0) {}
+ virtual ~indenter() {}
+ virtual void getch(tchar& ch, CStyle& sty)
{
- indent = amnt;
+ if (indent > 0)
+ {
+ indent--;
+ ch = ' ';
+ sty = lsty;
+ return;
+ }
+ parent->getch(ch, sty);
+ if (ch == 10)
+ {
+ indent = amnt;
+ lsty = sty;
+ }
+ return;
}
- return ch;
- }
-#endif
};
class dblspce : public CFilter
{
- bool lastlf;
-public:
- dblspce() : lastlf(false) {}
- virtual ~dblspce() {}
-#ifdef _UNICODE
- virtual tchar getch()
- {
- if (lastlf)
+ bool lastlf;
+ CStyle lsty;
+ public:
+ dblspce() : lastlf(false) {}
+ virtual ~dblspce() {}
+ virtual void getch(tchar& ch, CStyle& sty)
{
- lastlf = false;
- return 10;
+ if (lastlf)
+ {
+ lastlf = false;
+ ch = 10;
+ sty = lsty;
+ return;
+ }
+ parent->getch(ch, sty);
+ if (lastlf = (ch == 10))
+ {
+ lsty = sty;
+ }
+ return;
}
- tchar ch = parent->getch();
- lastlf = (ch == 10);
- return ch;
- }
-#else
- virtual int getch()
- {
- if (lastlf)
+};
+
+class textfmt : public CFilter
+{
+ CStyle currentstyle;
+ tchar lastchar;
+ bool uselast;
+ void mygetch(tchar&, CStyle&);
+ public:
+ textfmt() : lastchar(0), uselast(false) {}
+ virtual ~textfmt() {}
+ virtual void getch(tchar& ch, CStyle& sty);
+};
+
+class embolden : public CFilter
+{
+ public:
+ embolden() {}
+ virtual ~embolden() {}
+ virtual void getch(tchar& ch, CStyle& sty)
{
- lastlf = false;
- return 10;
+ parent->getch(ch, sty);
+ sty.setBold();
}
- int ch = parent->getch();
- lastlf = (ch == 10);
- return ch;
- }
-#endif
};
+class remap : public CFilter
+{
+ tchar q[3];
+ int offset;
+ CStyle currentstyle;
+ public:
+ remap() : offset(0) { q[0] = 0; }
+ virtual ~remap() {}
+ virtual void getch(tchar& ch, CStyle& sty);
+};
+
+class PeanutFormatter : public CFilter
+{
+ CStyle currentstyle;
+ public:
+ virtual ~PeanutFormatter() {}
+ virtual void getch(tchar& ch, CStyle& sty);
+};
#endif
diff --git a/noncore/apps/opie-reader/FontControl.h b/noncore/apps/opie-reader/FontControl.h
new file mode 100644
index 0000000..ed6c33f
--- a/dev/null
+++ b/noncore/apps/opie-reader/FontControl.h
@@ -0,0 +1,121 @@
+#ifndef __FONTCONTROL_H
+#define __FONTCONTROL_H
+
+#include <qfontdatabase.h>
+#include <qfontmetrics.h>
+#include "StyleConsts.h"
+
+class FontControl
+{
+ int * m_fontsizes;
+ int m_size;
+ QString m_fontname;
+ int m_maxsize;
+ public:
+ FontControl(QString n = "helvetica", int size = 10)
+ :
+ m_fontsizes(NULL)
+ {
+ ChangeFont(n, size);
+ }
+ ~FontControl()
+ {
+ if (m_fontsizes != NULL) delete [] m_fontsizes;
+ }
+ QString name() { return m_fontname; }
+ int currentsize() { return m_fontsizes[m_size]; }
+ int getsize(CStyle size)
+ {
+ return m_fontsizes[m_size+size.getFontSize()];
+ }
+ int ascent()
+ {
+ QFont f(name(), currentsize());
+ QFontMetrics fm(f);
+ return fm.ascent();
+ }
+ int ascent(CStyle ch)
+ {
+ QFont f(name(), getsize(ch));
+ QFontMetrics fm(f);
+ return fm.ascent();
+ }
+ int descent()
+ {
+ QFont f(name(), currentsize());
+ QFontMetrics fm(f);
+ return fm.descent();
+ }
+ int descent(CStyle ch)
+ {
+ QFont f(name(), getsize(ch));
+ QFontMetrics fm(f);
+ return fm.descent();
+ }
+ int lineSpacing()
+ {
+ QFont f(name(), currentsize());
+ QFontMetrics fm(f);
+ return fm.lineSpacing();
+ }
+ int lineSpacing(CStyle ch)
+ {
+ QFont f(name(), getsize(ch));
+ QFontMetrics fm(f);
+ return fm.lineSpacing();
+ }
+ bool decreasesize()
+ {
+ if (--m_size < 0)
+ {
+ m_size = 0;
+ return false;
+ }
+ else return true;
+ }
+ bool increasesize()
+ {
+ if (++m_size >= m_maxsize)
+ {
+ m_size = m_maxsize - 1;
+ return false;
+ }
+ else return true;
+ }
+ bool ChangeFont(QString& n)
+ {
+ return ChangeFont(n, currentsize());
+ }
+ bool ChangeFont(QString& n, int tgt)
+ {
+ QValueList<int>::Iterator it;
+ QFontDatabase fdb;
+ QValueList<int> sizes = fdb.pointSizes(n);
+ if (sizes.count() == 0)
+ {
+ return false;
+ }
+ else
+ {
+ m_fontname = n;
+ m_maxsize = sizes.count();
+ if (m_fontsizes != NULL) delete [] m_fontsizes;
+ m_fontsizes = new int[m_maxsize];
+ uint i = 0;
+ uint best = 0;
+ for (it = sizes.begin(); it != sizes.end(); it++)
+ {
+ m_fontsizes[i] = (*it)/10;
+ if (abs(tgt-m_fontsizes[i]) < abs(tgt-m_fontsizes[best]))
+ {
+ best = i;
+ }
+ i++;
+ }
+ m_size = best;
+ }
+ return true;
+ }
+};
+
+#endif
diff --git a/noncore/apps/opie-reader/Markups.h b/noncore/apps/opie-reader/Markups.h
new file mode 100644
index 0000000..960489f
--- a/dev/null
+++ b/noncore/apps/opie-reader/Markups.h
@@ -0,0 +1,7 @@
+enum MarkupType
+{
+ cNONE,
+ cTEXT,
+ cHTML,
+ cPML
+};
diff --git a/noncore/apps/opie-reader/QFloatBar.h b/noncore/apps/opie-reader/QFloatBar.h
new file mode 100644
index 0000000..bc70566
--- a/dev/null
+++ b/noncore/apps/opie-reader/QFloatBar.h
@@ -0,0 +1,19 @@
+#ifndef __QFLOATBAR_H
+#define __QFLOATBAR_H
+
+#include <qtoolbar.h>
+
+class QFloatBar : public QToolBar
+{
+ Q_OBJECT
+ virtual void hideEvent(QHideEvent* e)
+ {
+ /*if (e->spontaneous())*/ emit OnHide();
+ }
+ public:
+ QFloatBar(char* t, QMainWindow* mw, QMainWindow::ToolBarDock td, bool f) : QToolBar(t, mw, td, f) {}
+ signals:
+ void OnHide();
+};
+
+#endif
diff --git a/noncore/apps/opie-reader/QTReader.cpp b/noncore/apps/opie-reader/QTReader.cpp
index 6335ea2..e7bfc28 100644
--- a/noncore/apps/opie-reader/QTReader.cpp
+++ b/noncore/apps/opie-reader/QTReader.cpp
@@ -8,9 +8,11 @@
**
*****************************************************************************/
+#include <qpainter.h>
#include "config.h"
#include "QTReader.h"
#include "QTReaderApp.h"
+#include "CDrawBuffer.h"
#include <qpe/qpeapplication.h>
#include <math.h>
#include <ctype.h>
@@ -36,16 +38,19 @@ const char *QTReader::fonts[] = { "Helvetica", "Courier", "Times", 0 };
QTReader::QTReader( QWidget *parent=0, const char *name=0, WFlags f = 0) :
QWidget(parent, name, f),
m_delay(100),
- m_scrolldy(0),
+ m_scrolldy1(0),
+ m_scrolldy2(0),
m_autoScroll(false),
- textarray(NULL),
- locnarray(NULL),
+ //textarray(NULL),
+ //locnarray(NULL),
numlines(0),
m_fontname("unifont"),
- m_fm(NULL)
+ m_fm(NULL),
+ mouseUpOn(true),
+ m_twotouch(true),
+ m_touchone(true)
{
m_overlap = 1;
- fontsizes = NULL;
// init();
}
/*
@@ -74,53 +79,163 @@ long QTReader::real_delay()
return ( 8976 + m_delay ) / ( m_linespacing * m_linespacing );
}
-void QTReader::mouseReleaseEvent( QMouseEvent* _e )
-//void QTReader::mouseDoubleClickEvent( QMouseEvent* _e )
+void QTReader::mousePressEvent( QMouseEvent* _e )
{
- if (textarray != NULL)
+ if (_e->button() == RightButton)
{
-// printf("(%u, %u)\n", _e->x(), _e->y());
- QString wrd = QString::null;
- int lineno = _e->y()/m_linespacing;
- if (m_bMonoSpaced)
- {
- int chno = _e->x()/m_charWidth;
- if (chno < ustrlen(textarray[lineno]->data()))
- {
- wrd[0] = textarray[lineno]->data()[chno];
- }
- }
- else
- {
- CBuffer* t = textarray[lineno];
- int first = 0;
- while (1)
- {
- int i = first+1;
-// while ((*t)[i] != ' ' && (*t)[i] != 0) i++;
- while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
- if (m_fm->width(toQString(t->data()), i) > _e->x())
+ mouseUpOn = false;
+ if (_e->y() > height()/2)
+ {
+ goDown();
+ }
+ else
+ {
+ goUp();
+ }
+ }
+}
+
+bool QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt)
+{
+ int lineno = 0;
+ int ht = textarray[0]->lineSpacing();
+ while ((ht < y) && (lineno < numlines))
{
- wrd = toQString(t->data()+first, i - first);
- break;
+ ht += textarray[++lineno]->lineSpacing();
}
-// while ((*t)[i] == ' ' && (*t)[i] != 0) i++;
- while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
- if ((*t)[i] == 0) break;
- first = i;
- }
- }
- if (!wrd.isEmpty())
- {
- QClipboard* cb = QApplication::clipboard();
- cb->setText(wrd);
- Global::statusMessage(wrd);
- if (!m_targetapp.isEmpty() && !m_targetmsg.isEmpty())
- {
- QCopEnvelope e(("QPE/Application/"+m_targetapp).utf8(), (m_targetmsg+"(QString)").utf8());
- e << wrd;
- }
- }
+ start = locnarray[lineno];
+ if (m_bMonoSpaced)
+ {
+ offset = x/m_charWidth;
+ }
+ else
+ {
+ int i;
+ CDrawBuffer* t = textarray[lineno];
+ for (i = t->length(); t->width(i) > x; i--);
+ offset = i;
+ }
+ return textarray[lineno]->isLink(offset, tgt);
+}
+
+void QTReader::setTwoTouch(bool _b)
+{
+ setBackgroundColor( white );
+ m_twotouch = m_touchone = _b;
+}
+
+void QTReader::mouseReleaseEvent( QMouseEvent* _e )
+{
+ if (_e->button() == LeftButton)
+ {
+ if (mouseUpOn)
+ {
+ if (textarray[0] != NULL)
+ {
+ QString wrd, line;
+// int lineno = _e->y()/m_linespacing;
+ int lineno = 0;
+ int ht = textarray[0]->lineSpacing();
+ while ((ht < _e->y()) && (lineno < numlines))
+ {
+ ht += textarray[++lineno]->lineSpacing();
+ }
+ size_t startpos, startoffset, tgt;
+ if (getcurrentpos(_e->x(), _e->y(), startpos, startoffset, tgt))
+ {
+ if (buffdoc.hyperlink(tgt))
+ {
+ fillbuffer();
+ update();
+ }
+ else
+ {
+ locate(pagelocate());
+ }
+ return;
+ }
+ if (m_twotouch)
+ {
+ if (m_touchone)
+ {
+ m_touchone = false;
+ m_startpos = startpos;
+ m_startoffset = startoffset;
+ setBackgroundColor( lightGray );
+ }
+ else
+ {
+ m_touchone = true;
+ setBackgroundColor( white );
+ size_t endpos, endoffset;
+ endpos = startpos;
+ endoffset = startoffset;
+ size_t currentpos = locate();
+ if (endpos >= m_startpos)
+ {
+ jumpto(m_startpos);
+ for (int i = 0; i < m_startoffset; i++)
+ {
+ getch();
+ }
+ if (m_startpos == endpos)
+ {
+ for (int i = m_startoffset; i <= endoffset; i++)
+ {
+ wrd += QChar(getch());
+ }
+ }
+ else
+ {
+ while (buffdoc.explocate() <= endpos)
+ {
+ wrd += QChar(getch());
+ }
+ for (int i = 0; i < endoffset; i++)
+ {
+ wrd += QChar(getch());
+ }
+ }
+ jumpto(currentpos);
+ }
+ }
+ }
+ else if (m_bMonoSpaced)
+ {
+ int chno = _e->x()/m_charWidth;
+ if (chno < ustrlen(textarray[lineno]->data()))
+ {
+ wrd[0] = textarray[lineno]->data()[chno];
+ }
+ }
+ else
+ {
+ CDrawBuffer* t = textarray[lineno];
+ int first = 0;
+ while (1)
+ {
+ int i = first+1;
+ while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
+ if (t->width(i) > _e->x())
+ {
+ wrd = toQString(t->data()+first, i - first);
+ break;
+ }
+ while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
+ if ((*t)[i] == 0) break;
+ first = i;
+ }
+ }
+ if (!wrd.isEmpty())
+ {
+ emit OnWordSelected(wrd, locnarray[lineno], (m_twotouch) ? wrd : toQString(textarray[lineno]->data()));
+ }
+ }
+ }
+ else
+ {
+ mouseUpOn = true;
+ }
}
}
@@ -134,8 +249,8 @@ void QTReader::focusOutEvent(QFocusEvent* e)
{
if (m_autoScroll)
{
- timer->stop();
- m_scrolldy = 0;
+ timer->stop();
+ m_scrolldy1 = m_scrolldy2 = 0;
}
}
@@ -147,11 +262,11 @@ void QTReader::goDown()
{
if (m_bpagemode)
{
- dopagedn();
+ dopagedn();
}
else
{
- lineDown();
+ lineDown();
}
}
@@ -159,11 +274,11 @@ void QTReader::goUp()
{
if (m_bpagemode)
{
- dopageup();
+ dopageup();
}
else
{
- lineUp();
+ lineUp();
}
}
@@ -172,122 +287,115 @@ void QTReader::keyPressEvent(QKeyEvent* e)
switch (e->key())
{
case Key_Down:
- {
- e->accept();
- if (m_autoScroll)
- {
- if (m_delay < 59049)
- {
- m_delay = (3*m_delay)/2;
- timer->changeInterval(real_delay());
- }
- else
- {
- m_delay = 59049;
- }
- }
- else
- {
- goDown();
- }
- }
+ {
+ e->accept();
+ if (m_autoScroll)
+ {
+ if (m_delay < 59049)
+ {
+ m_delay = (3*m_delay)/2;
+ timer->changeInterval(real_delay());
+ }
+ else
+ {
+ m_delay = 59049;
+ }
+ }
+ else
+ {
+ goDown();
+ }
+ }
break;
case Key_Up:
- {
- e->accept();
- if (m_autoScroll)
- {
- if (m_delay > 1024)
- {
- m_delay = (2*m_delay)/3;
- timer->changeInterval(real_delay());
- }
- else
- {
- m_delay = 1024;
- }
- }
- else
- {
- goUp();
- }
- }
+ {
+ e->accept();
+ if (m_autoScroll)
+ {
+ if (m_delay > 1024)
+ {
+ m_delay = (2*m_delay)/3;
+ timer->changeInterval(real_delay());
+ }
+ else
+ {
+ m_delay = 1024;
+ }
+ }
+ else
+ {
+ goUp();
+ }
+ }
break;
/*
case Key_Left:
- {
- e->accept();
- if (m_textfont > 0)
- {
- m_textfont--;
- setfont(NULL);
- locate(pagelocate());
- update();
- }
- }
+ {
+ e->accept();
+ if (m_textfont > 0)
+ {
+ m_textfont--;
+ setfont(NULL);
+ locate(pagelocate());
+ update();
+ }
+ }
break;
case Key_Right:
- {
- e->accept();
- if (fonts[++m_textfont] == 0)
- {
- m_textfont--;
- }
- else
- {
- setfont(NULL);
- locate(pagelocate());
- update();
- }
- }
+ {
+ e->accept();
+ if (fonts[++m_textfont] == 0)
+ {
+ m_textfont--;
+ }
+ else
+ {
+ setfont(NULL);
+ locate(pagelocate());
+ update();
+ }
+ }
break;
*/
case Key_Right:
- {
- e->accept();
- if (fontsizes[++m_textsize] == 0)
- {
- m_textsize--;
- }
- else
- {
- bool sc = m_autoScroll;
- m_autoScroll = false;
- setfont(NULL);
- locate(pagelocate());
- update();
- m_autoScroll = sc;
- if (m_autoScroll) autoscroll();
- }
- }
+ {
+ e->accept();
+ if (m_fontControl.increasesize())
+ {
+ bool sc = m_autoScroll;
+ setfont();
+ m_autoScroll = false;
+ locate(pagelocate());
+ update();
+ m_autoScroll = sc;
+ if (m_autoScroll) autoscroll();
+ }
+ }
break;
case Key_Left:
- {
- e->accept();
- if (m_textsize > 0)
- {
- bool sc = m_autoScroll;
- m_autoScroll = false;
- m_textsize--;
- setfont(NULL);
- locate(pagelocate());
- update();
- m_autoScroll = sc;
- if (m_autoScroll) autoscroll();
- }
- }
+ {
+ e->accept();
+ if (m_fontControl.decreasesize())
+ {
+ bool sc = m_autoScroll;
+ m_autoScroll = false;
+ setfont();
+ locate(pagelocate());
+ update();
+ m_autoScroll = sc;
+ if (m_autoScroll) autoscroll();
+ }
+ }
break;
- case Key_Space:
-// case Key_Enter:
- case Key_Return:
- {
- e->accept();
- setautoscroll(!m_autoScroll);
- ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll);
- }
- break;
- default:
- e->ignore();
+ case Key_Space:
+ case Key_Return:
+ {
+ e->accept();
+ emit OnActionPressed();
+ }
+ break;
+ default:
+ e->ignore();
}
}
@@ -296,24 +404,26 @@ void QTReader::setautoscroll(bool _sc)
if (_sc == m_autoScroll) return;
if (m_autoScroll)
{
- m_autoScroll = false;
- }
+ m_autoScroll = false;
+ QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
+ }
else
{
- m_autoScroll = true;
- autoscroll();
+ m_autoScroll = true;
+ autoscroll();
+ QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; // light is even not dimmed
}
}
-bool QTReader::getline(CBuffer *buff)
+bool QTReader::getline(CDrawBuffer *buff)
{
if (m_bMonoSpaced)
{
- return buffdoc.getline(buff ,width(), m_charWidth);
+ return buffdoc.getline(buff ,width(), m_charWidth);
}
else
{
- return buffdoc.getline(buff, width());
+ return buffdoc.getline(buff, width());
}
}
@@ -321,8 +431,8 @@ void QTReader::doscroll()
{
if (!m_autoScroll)
{
- timer->stop();
- return;
+ timer->stop();
+ return;
}
// timer->changeInterval(real_delay());
QPainter p( this );
@@ -330,48 +440,38 @@ void QTReader::doscroll()
bitBlt(this,0,0,this,0,1,width(),-1);
qDrawPlainRect(&p,0,height() - 2,width(),2,white,1,&b);
- if (++m_scrolldy == m_linespacing)
- {
- setfont(&p);
- m_scrolldy = 0;
-// qDrawPlainRect(&p,0,height() - m_linespacing,width(),m_linespacing,white,1,&b);
- pagepos = locnarray[1];
- CBuffer* buff = textarray[0];
- for (int i = 1; i < numlines; i++)
- {
- textarray[i-1] = textarray[i];
- locnarray[i-1] = locnarray[i];
- }
- locnarray[numlines-1] = locate();
- if (getline(buff))
- {
- textarray[numlines-1] = buff;
- drawText( p, 0, height() - m_descent - 2, buff->data());
- mylastpos = locate();
- }
- else
- {
-// (*buff)[0] = '\0';
- textarray[numlines-1] = buff;
- m_autoScroll = false;
- ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll);
- }
- }
-}
-
-void QTReader::drawText(QPainter& p, int x, int y, tchar* _text)
-{
- QString text = toQString(_text);
- if (m_bMonoSpaced)
+ if (++m_scrolldy1 == textarray[0]->lineSpacing())
{
- for (int i = 0; i < text.length(); i++)
- {
- p.drawText( x+i*m_charWidth, y, QString(text[i]) );
- }
+ CDrawBuffer* buff = textarray[0];
+ for (int i = 1; i <= numlines; i++)
+ {
+ textarray[i-1] = textarray[i];
+ locnarray[i-1] = locnarray[i];
+ }
+ textarray[numlines] = buff;
+ --numlines;
+ m_scrolldy1 = 0;
}
- else
+ if (++m_scrolldy2 == textarray[numlines]->lineSpacing())
{
- p.drawText( x, y, text );
+ m_scrolldy2 = 0;
+ numlines++;
+
+ if (textarray[numlines] == NULL)
+ {
+ textarray[numlines] = new CDrawBuffer;
+ }
+ locnarray[numlines] = locate();
+ int ch = getline(textarray[numlines]);
+ textarray[numlines-1]->render(&p, height() - textarray[numlines]->descent() - 2, m_bMonoSpaced, m_charWidth, width());
+ mylastpos = locate();
+ if (!ch)
+ {
+ m_autoScroll = false;
+ ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll);
+ emit OnRedraw();
+ }
+ emit OnRedraw();
}
}
@@ -380,135 +480,117 @@ void QTReader::autoscroll()
timer->start(real_delay(), false);
}
-void QTReader::setfont(QPainter* p)
+void QTReader::setfont()
{
- // qDebug("Fontsize = %u",fontsizes[m_textsize]);
- // qDebug("SetFont %x",p);
- QFont font(m_fontname, fontsizes[m_textsize], (m_bBold) ? QFont::Bold : QFont::Normal );
- m_charWidth = (m_charpc*fontsizes[m_textsize])/100;
+// m_fontControl.Change
+ m_charWidth = (m_charpc*m_fontControl.currentsize())/100;
if (m_charWidth <= 0) m_charWidth = 1;
-// font.setFixedPitch(m_bMonoSpaced);
-// qDebug("Raw name = %s", (const char*)font.rawName());
- if (p != NULL) p->setFont( font );
- if (m_fm == NULL)
- {
- m_fm = new QFontMetrics(font);
- buffdoc.setfm(m_fm);
- }
- else
- {
- *m_fm = QFontMetrics(font);
- }
- m_ascent = m_fm->ascent();
- m_descent = m_fm->descent();
- m_linespacing = m_fm->lineSpacing();
+ m_ascent = m_fontControl.ascent();
+ m_descent = m_fontControl.descent();
+ m_linespacing = m_fontControl.lineSpacing();
}
void QTReader::drawFonts( QPainter *p )
{
- setfont(p);
- if (m_lastwidth != width())
+ setfont();
+ if (m_lastwidth != width() || m_lastheight != height())
{
m_lastwidth = width();
- locate(pagepos);
+ m_lastheight = height();
+ locate(pagelocate());
}
else
{
+
+/*
int sl = screenlines();
if (sl < numlines)
{
-// qDebug("df:<%u,%u>",sl,numlines);
-
- size_t newpos = locnarray[sl];
- CBuffer** nta = new CBuffer*[sl];
- size_t* nla = new size_t[sl];
- for (int i = 0; i < sl; i++)
- {
- nta[i] = textarray[i];
- nla[i] = locnarray[i];
- }
- for (int i = sl; i < numlines; i++) delete textarray[i];
- delete [] textarray;
- delete [] locnarray;
- textarray = nta;
- locnarray = nla;
- numlines = sl;
- jumpto(mylastpos = newpos);
-// locate(pagepos);
+// qDebug("df:<%u,%u>",sl,numlines);
+
+ size_t newpos = locnarray[sl];
+ CDrawBuffer** nta = new CDrawBuffer*[sl];
+ size_t* nla = new size_t[sl];
+ for (int i = 0; i < sl; i++)
+ {
+ nta[i] = textarray[i];
+ nla[i] = locnarray[i];
+ }
+ for (int i = sl; i < numlines; i++) delete textarray[i];
+ delete [] locnarray;
+ delete [] textarray;
+ textarray = nta;
+ locnarray = nla;
+ numlines = sl;
+ jumpto(mylastpos = newpos);
}
if (sl > numlines)
{
-// qDebug("df:<%u,%u>",sl,numlines);
- CBuffer** nta = new CBuffer*[sl];
- size_t* nla = new size_t[sl];
- for (int i = 0; i < numlines; i++)
- {
- nta[i] = textarray[i];
- nla[i] = locnarray[i];
- }
- if (locate() != mylastpos) jumpto(mylastpos);
- for (int i = numlines; i < sl; i++)
- {
- nta[i] = new CBuffer;
- nla[i] = locate();
- getline(nta[i]);
- }
- mylastpos = locate();
- delete [] textarray;
- delete [] locnarray;
- textarray = nta;
- locnarray = nla;
- numlines = sl;
+// qDebug("df:<%u,%u>",sl,numlines);
+ CDrawBuffer** nta = new CDrawBuffer*[sl];
+ size_t* nla = new size_t[sl];
+ for (int i = 0; i < numlines; i++)
+ {
+ nta[i] = textarray[i];
+ nla[i] = locnarray[i];
+ }
+ if (locate() != mylastpos) jumpto(mylastpos);
+ for (int i = numlines; i < sl; i++)
+ {
+ nta[i] = new CDrawBuffer(&m_fontControl);
+ nla[i] = locate();
+ getline(nta[i]);
+ }
+ mylastpos = locate();
+ delete [] locnarray;
+ delete [] textarray;
+ textarray = nta;
+ locnarray = nla;
+ numlines = sl;
}
- int ypos = (btight) ? 0 : m_ascent-m_linespacing;
- // int linespacing = (tight) ? m_ascent : m_ascent+m_descent;
- for (int i = 0; i < numlines; i++)
+*/
+ if (numlines > 0)
+ {
+ int ypos = textarray[0]->ascent();
+ textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, width());
+ for (int i = 1; i < numlines; i++)
{
- drawText( *p, 0, ypos += m_linespacing, textarray[i]->data());
+ ypos += (textarray[i-1]->lineSpacing() + textarray[i]->lineSpacing())/2;
+ textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, width());
+
+ }
+// mylastpos = locate();
}
- /*
-
-
-
- int nlines = height()/(fontmetric.ascent()+fontmetric.descent());
- tchar buffer[1024];
- for (int i = 0; i < nlines; i++)
- {
- y += fontmetric.ascent();
- sprintf(buffer, "%d:%d:%s[%d]:Lines %d:%s", i+1, m_textfont, fonts[m_textfont], m_fs, nlines, (const tchar*)m_string);
- drawText( *p, 0, y, buffer );
- y += fontmetric.descent();
- }
- */
}
- m_scrolldy = 0;
+ m_scrolldy1 = m_scrolldy2 = 0;
+ emit OnRedraw();
}
QString QTReader::firstword()
{
if (m_bMonoSpaced)
{
- return toQString(textarray[0]->data());
+ return toQString(textarray[0]->data());
}
else
{
- int start, end, len, j;
- for (j = 0; j < numlines; j++)
- {
- len = textarray[j]->length();
- for (start = 0; start < len && !isalpha((*textarray[j])[start]); start++);
- if (start < len) break;
- }
- if (j < numlines)
- {
- QString ret = "";
- for (end = start; end < len && isalpha((*textarray[j])[end]); end++)
- ret += (*textarray[j])[end];
- if (ret.isEmpty()) ret = "Current position";
- return ret;
- }
- else
- return "Current position";
+ int start, end, len, j;
+ for (j = 0; j < numlines; j++)
+ {
+ len = textarray[j]->length();
+ for (start = 0; start < len && !isalpha((*textarray[j])[start]); start++);
+ if (start < len) break;
+ }
+ if (j < numlines)
+ {
+ QString ret = "";
+ for (end = start; end < len && isalpha((*textarray[j])[end]); end++)
+ ret += (*textarray[j])[end];
+ if (ret.isEmpty()) ret = "Current position";
+ return ret;
+ }
+ else
+ return "Current position";
}
}
@@ -516,44 +598,9 @@ QString QTReader::firstword()
// Construct the QTReader with buttons.
//
-void QTReader::ChangeFont(int tgt)
+bool QTReader::ChangeFont(int tgt)
{
-
- QValueList<int>::Iterator it;
-
-// QValueList<int> sizes = QFontDatabase::pointSizes(m_fontname, (m_bBold) ? QFont::Bold : QFont::Normal);
- QFontDatabase fdb;
-/*
- QStringList styles = fdb.styles(m_fontname);
- for ( QStringList::Iterator it = styles.begin(); it != styles.end(); ++it )
- {
- printf( "%s \n", (*it).latin1() );
- }
-*/
- QValueList<int> sizes = fdb.pointSizes(m_fontname, (m_bBold) ? QString("Bold") : QString::null);
- uint n = sizes.count();
- if (fontsizes != NULL) delete [] fontsizes;
- fontsizes = new unsigned int[n+1];
- uint i = 0;
- uint best = 0;
- for (it = sizes.begin(); it != sizes.end(); it++)
- {
- fontsizes[i] = (*it)/10;
- if (abs(tgt-fontsizes[i]) < abs(tgt-fontsizes[best]))
- {
- best = i;
- }
- i++;
- }
- m_textsize = best;
- fontsizes[i] = 0;
- setfont(NULL);
- QFont font(m_fontname, fontsizes[m_textsize], (m_bBold) ? QFont::Bold : QFont::Normal );
- if (m_fm == NULL)
- {
- m_fm = new QFontMetrics(font);
- buffdoc.setfm(m_fm);
- }
+ return m_fontControl.ChangeFont(m_fontname, tgt);
}
void QTReader::init()
@@ -565,17 +612,19 @@ void QTReader::init()
// p.setBackgroundMode( Qt::OpaqueMode );
buffdoc.setfilter(getfilter());
ChangeFont(m_textsize);
- // setFocusPolicy(QWidget::StrongFocus);
+ setFocusPolicy(QWidget::StrongFocus);
// resize( 240, 320 );
//setFocus();
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(doscroll()));
// QMessageBox::information(this, "init", m_lastfile, 1);
m_lastwidth = width();
+ m_lastheight = height();
+ setfont();
if (!m_lastfile.isEmpty())
{
- m_string = DocLnk(m_lastfile).name();
- load_file(m_lastfile);
+ m_string = DocLnk(m_lastfile).name();
+ load_file(m_lastfile);
}
}
@@ -584,10 +633,6 @@ void QTReader::init()
//
QTReader::~QTReader()
{
- if (fontsizes != NULL) delete [] fontsizes;
-#ifndef QT_NO_PRINTER
- // delete printer;
-#endif
}
//
@@ -672,163 +717,156 @@ unsigned int QTReader::screenlines()
return (height()-2)/(m_linespacing);
};
-bool QTReader::fillbuffer() {
- if (buffdoc.empty()) return false;
- //printf("Fillbuffer\n");
- m_scrolldy = 0;
- int ch;
- bool ret = false;
- int delta = screenlines();
- // qDebug("fillbuffer:%u-%u",delta,numlines);
- if (delta != numlines)
- {
- if (textarray != NULL)
- {
- for (int i = 0; i < numlines; i++) delete textarray[i];
- delete [] textarray;
- delete [] locnarray;
- }
- numlines = delta;
- textarray = new CBuffer*[numlines];
- locnarray = new size_t[numlines];
- for (int i = 0; i < numlines; i++) textarray[i] = new CBuffer;
- }
- // qDebug("fillbuffer:pagepos:%u",pagepos);
- unsigned int oldpagepos = pagepos;
-// if (textarray != NULL)
-// pagepos = locnarray[0];
-// else
- pagepos = locate();
- for (int i = 0; i < delta; i++)
+bool QTReader::fillbuffer(int reuse, int ht)
+{
+ if (buffdoc.empty()) return false;
+ m_scrolldy1 = m_scrolldy2 = 0;
+ int ch;
+ bool ret = false;
+ unsigned int oldpagepos = locnarray[reuse];
+ int ypos = ht;
+ numlines = reuse;
+ while (ypos < height())
{
- locnarray[i] = locate();
- ch = getline(textarray[i]);
- // if (ch == EOF) {
- if (!ch)
- {
- if (i == 0)
- {
- locate(oldpagepos);
- return false;
- }
- else
- {
- ret = true;
- for (int j = i+1; j < delta; j++)
- {
- locnarray[j] = locnarray[j-1];
- (*(textarray[j]))[0] = '\0';
- }
- break;
- }
- }
- if (ch == '\012') ret = true;
+ if (textarray[numlines] == NULL)
+ {
+ textarray[numlines] = new CDrawBuffer(&m_fontControl);
+ }
+ locnarray[numlines] = locate();
+ int ch = getline(textarray[numlines]);
+ ypos += textarray[numlines]->lineSpacing();
+ numlines++;
+ if (!ch)
+ {
+ if (numlines - reuse == 1/* && locnarray[0] == buffdoc.locate()*/)
+ {
+ locate(oldpagepos);
+ return false;
+ }
+ else
+ {
+ --numlines;
+ mylastpos = locate();
+ return true;
+ }
+ }
}
- mylastpos = locate();
- // qDebug("fillbuffer:lastpos:%u",mylastpos);
- return true;
+
+ --numlines;
+ mylastpos = locate();
+
+ return true;
}
void QTReader::dopagedn()
{
- if (m_overlap == 0)
+ int skip = 0, ypos = 0;
+ if (locate() != mylastpos)
{
- if (locate() != mylastpos) jumpto(mylastpos);
+// qDebug("Jumping to %u", mylastpos);
+ jumpto(mylastpos);
}
- else
+ CDrawBuffer* reusebuffer = textarray[numlines];
+ if (reusebuffer != NULL)
{
- if (m_overlap >= screenlines()) m_overlap = screenlines()/2;
- jumpto(locnarray[screenlines()-m_overlap]);
+ for (int i = 0; i <= m_overlap; i++)
+ {
+ int offset = numlines - m_overlap + i;
+ reusebuffer = textarray[offset];
+ size_t reuselocn = locnarray[offset];
+ textarray[offset] = textarray[i];
+ textarray[i] = reusebuffer;
+ locnarray[offset] = locnarray[i];
+ locnarray[i] = reuselocn;
+ ypos += textarray[i]->lineSpacing();
+ skip++;
+ }
}
- if (fillbuffer())
+ if (fillbuffer(skip, ypos))
{
- update();
+ update();
}
}
void QTReader::dopageup()
{
- CBuffer** buff = textarray;
- unsigned int *loc = new unsigned int[numlines];
- int cbptr = 0;
- if (locate() != mylastpos) jumpto(mylastpos);
- if (m_overlap >= screenlines()) m_overlap = screenlines()/2;
- unsigned int target = locnarray[m_overlap];
- if (buffdoc.hasrandomaccess())
- {
- unsigned int delta = locate()-pagelocate();
- if (delta < 64) delta = 64;
- if (delta % 2 != 0) delta++;
- if (target % 2 != 0) target++;
- do
+ CBufferFace<CDrawBuffer*> buff;
+ CBufferFace<size_t> loc;
+ unsigned int target = locnarray[(m_overlap < numlines) ? m_overlap : numlines/2];
+
+ size_t delta;
+ if (target < 2048)
{
- delta <<= 1;
- if (delta >= target)
- {
- delta = target;
- jumpto(0);
- for (int i = 0; i < numlines; i++)
- {
- loc[i] = locate();
- getline(buff[i]);
- }
- break;
- }
- jumpto(target-delta);
- do
- {
- getline(buff[0]);
-#ifdef WS
- //printf("Trying:%s\n",buff[0]);
-#endif
- if (locate() > target) continue;
- }
- while (!buffdoc.iseol());
- for (int i = 0; i < numlines; i++)
+ delta = target;
+ jumpto(0);
+ }
+ else
+ {
+ delta = 2048;
+
+ jumpto(target - delta);
+
+ buff[0] = new CDrawBuffer(&m_fontControl);
+
+ do
{
- loc[i] = locate();
- getline(buff[i]);
-#ifdef WS
- //printf("Filling:%s\n",buff[i]);
-#endif
+
+ if (!getline(buff[0])) break;
+
+ if (locate() > target) continue;
}
+ while (!buffdoc.iseol());
}
- while (locate() >= target && delta < 4096);
-#ifdef WS
- //printf("Delta:%u\n",delta);
-#endif
- }
- else
- {
- jumpto(0);
- for (int i = 0; i < numlines; i++)
+ int nbfl = 0;
+
+ bool ch = true;
+ int ypos = 0;
+ while (locate() < target)
{
- loc[i] = locate();
- getline(buff[i]);
+ if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl);
+ loc[nbfl] = locate();
+ ch = getline(buff[nbfl]);
+ ypos += buff[nbfl]->lineSpacing();
+ nbfl++;
+ if (!ch) break;
}
- }
- cbptr = 0;
- while (locate() < target)
- {
- loc[cbptr] = locate();
- getline(buff[cbptr]);
-#ifdef WS
- //printf("Adding:%s\n",buff[cbptr]->data());
-#endif
- cbptr = (cbptr+1) % numlines;
- }
- pagepos = loc[cbptr];
- textarray = new CBuffer*[numlines];
- for (int i = 0; i < numlines; i++)
- {
- int j = (cbptr+i)%numlines;
- textarray[i] = buff[j];
- locnarray[i] = loc[j];
- }
- delete [] buff;
- delete [] loc;
+ if (ypos < height())
+ {
+ locate(0);
+ return;
+ }
+ if (ch)
+ {
+ if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl);
+ loc[nbfl] = locate();
+ int ch = getline(buff[nbfl]);
+ nbfl++;
+ }
+ ypos = 0;
+ numlines = 0;
+ while (ypos < height() && numlines <= nbfl-2)
+ {
+ ypos += buff[nbfl - numlines - 2]->lineSpacing();
+ numlines++;
+ }
+ --numlines;
+ int offset = nbfl;
+ offset -= numlines+1;
+ for (int i = 0; i <= numlines; i++)
+ {
+ delete textarray[i];
+ textarray[i] = buff[offset+i];
+ locnarray[i] = loc[offset + i];
+ }
+ for (int i = 0; i < nbfl - numlines - 1; i++)
+ {
+ delete buff[i];
+ }
+
+// --numlines;
mylastpos = locate();
+
update();
}
@@ -852,6 +890,7 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn)
locate(lcn);
// qDebug("buffdoc.locate done");
}
+ setfilter(getfilter());
update();
// qDebug("Updated");
return bRC;
@@ -859,23 +898,33 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn)
void QTReader::lineDown()
{
- pagepos = locnarray[1];
- CBuffer* buff = textarray[0];
- for (int i = 1; i < numlines; i++)
+ int ypos = 0;
+ int offset = numlines;
+
+ for (int i = 0; i <= numlines; i++)
{
- textarray[i-1] = textarray[i];
- locnarray[i-1] = locnarray[i];
+ if ((ypos += textarray[numlines-i]->lineSpacing()) > height())
+ {
+ offset = i-1;
+ break;
+ }
}
- locnarray[numlines-1] = locate();
- if (getline(buff))
+ offset = numlines - offset;
+ for (int i = offset; i <= numlines; i++)
{
- textarray[numlines-1] = buff;
- mylastpos = locate();
+ CDrawBuffer* buff = textarray[i-offset];
+ textarray[i-offset] = textarray[i];
+ locnarray[i-offset] = locnarray[i];
+ textarray[i] = buff;
}
- else
+ numlines = numlines - offset + 1;
+ locnarray[numlines] = locate();
+ if (textarray[numlines] == NULL)
{
- textarray[numlines-1] = buff;
+ textarray[numlines] = new CDrawBuffer(&m_fontControl);
}
+ getline(textarray[numlines]);
+ mylastpos = locate();
update();
}
/*
@@ -891,38 +940,38 @@ void QTReader::lineUp()
unsigned int delta = locate()-pagelocate();
if (delta < 64) delta = 64;
do
- {
- delta <<= 1;
- if (delta >= target)
- {
- delta = target;
- jumpto(0);
- for (int i = 0; i < numlines; i++)
- {
- loc[i] = locate();
- getline(buff[i]);
- }
- break;
- }
- jumpto(target-delta);
- do
- {
- buffdoc.getline(buff[0],width());
+ {
+ delta <<= 1;
+ if (delta >= target)
+ {
+ delta = target;
+ jumpto(0);
+ for (int i = 0; i < numlines; i++)
+ {
+ loc[i] = locate();
+ getline(buff[i]);
+ }
+ break;
+ }
+ jumpto(target-delta);
+ do
+ {
+ buffdoc.getline(buff[0],width());
#ifdef WS
- //printf("Trying:%s\n",buff[0]);
+ //printf("Trying:%s\n",buff[0]);
#endif
- if (locate() > target) continue;
- }
- while (!buffdoc.iseol());
- for (int i = 0; i < numlines; i++)
- {
- loc[i] = locate();
- buffdoc.getline(buff[i],width());
+ if (locate() > target) continue;
+ }
+ while (!buffdoc.iseol());
+ for (int i = 0; i < numlines; i++)
+ {
+ loc[i] = locate();
+ buffdoc.getline(buff[i],width());
#ifdef WS
- //printf("Filling:%s\n",buff[i]);
+ //printf("Filling:%s\n",buff[i]);
#endif
- }
- }
+ }
+ }
while (locate() >= target && delta < 4096);
#ifdef WS
//printf("Delta:%u\n",delta);
@@ -932,10 +981,10 @@ void QTReader::lineUp()
{
jumpto(0);
for (int i = 0; i < numlines; i++)
- {
- loc[i] = locate();
- buffdoc.getline(buff[i],width());
- }
+ {
+ loc[i] = locate();
+ buffdoc.getline(buff[i],width());
+ }
}
cbptr = 0;
while (locate() < target)
@@ -963,43 +1012,41 @@ void QTReader::lineUp()
*/
void QTReader::lineUp()
{
- CBuffer* buff = textarray[numlines-1];
+ CDrawBuffer* buff = textarray[numlines];
unsigned int loc;
- unsigned int end = locnarray[numlines-1];
+ unsigned int end = locnarray[numlines];
int cbptr = 0;
if (locate() != mylastpos) jumpto(mylastpos);
unsigned int target = locnarray[0];
+ if (target == 0) return;
if (buffdoc.hasrandomaccess())
{
unsigned int delta = locate()-pagelocate();
if (delta < 64) delta = 64;
do
- {
- delta <<= 1;
- if (delta >= target)
- {
- delta = target;
- jumpto(0);
- for (int i = 0; i < numlines; i++)
- {
- loc = locate();
- getline(buff);
- }
- break;
- }
- jumpto(target-delta);
- do
- {
- getline(buff);
+ {
+ delta <<= 1;
+ if (delta >= target)
+ {
+ delta = target;
+ jumpto(0);
+ loc = locate();
+ getline(buff);
+ break;
+ }
+ jumpto(target-delta);
+ do
+ {
+ getline(buff);
#ifdef WS
- //printf("Trying:%s\n",buff[0]);
+ //printf("Trying:%s\n",buff[0]);
#endif
- if (locate() > target) continue;
- }
- while (!buffdoc.iseol());
- loc = locate();
- getline(buff);
- }
+ if (locate() > target) continue;
+ }
+ while (!buffdoc.iseol());
+ loc = locate();
+ getline(buff);
+ }
while (locate() >= target && delta < 4096);
}
else
@@ -1014,18 +1061,27 @@ void QTReader::lineUp()
loc = locate();
getline(buff);
}
- pagepos = loc;
- for (int i = numlines-1; i > 0; i--)
+ for (int i = numlines; i > 0; i--)
{
textarray[i] = textarray[i-1];
locnarray[i] = locnarray[i-1];
}
textarray[0] = buff;
locnarray[0] = loc;
-// delete [] buff;
-// delete [] loc;
- mylastpos = locate();
- jumpto(end);
+ int start = numlines;
+ int ypos = 0;
+ for (int i = 0; i <= numlines; i++)
+ {
+ ypos += textarray[i]->lineSpacing();
+ if (ypos > height())
+ {
+ start = i;
+ ypos -= textarray[i]->lineSpacing();
+ break;
+ }
+ }
+ jumpto(locnarray[start]);
+ fillbuffer(start, ypos);
update();
}
@@ -1033,3 +1089,21 @@ bool QTReader::empty()
{
return buffdoc.empty();
}
+
+MarkupType QTReader::PreferredMarkup()
+{
+ MarkupType m = buffdoc.PreferredMarkup();
+ if (m == cTEXT)
+ {
+ int ext = m_lastfile.findRev('.');
+ if (ext >= 0)
+ {
+ QString ft = m_lastfile.right(m_lastfile.length()-ext-1).upper();
+ if (ft.left(3) == "HTM")
+ {
+ m = cHTML;
+ }
+ }
+ }
+ return m;
+}
diff --git a/noncore/apps/opie-reader/QTReader.h b/noncore/apps/opie-reader/QTReader.h
index 2efb988..78230b4 100644
--- a/noncore/apps/opie-reader/QTReader.h
+++ b/noncore/apps/opie-reader/QTReader.h
@@ -2,12 +2,17 @@
#define __QTREADER_H
#include <qwidget.h>
-#include <qpainter.h>
-#include <qclipboard.h>
-#include "CBuffer.h"
+//#include <qpainter.h>
#include "my_list.h"
#include "BuffDoc.h"
-#include <qtimer.h>
+#include "FontControl.h"
+
+//#include <qtimer.h>
+
+class CDrawBuffer;
+//class CBuffer;
+class QPainter;
+class QTimer;
class QTReader : public QWidget
{
@@ -20,13 +25,14 @@ class QTReader : public QWidget
bool m_autoScroll;
void autoscroll();
QTimer* timer;
- int m_scrolldy, m_encd;
+ int m_scrolldy1, m_scrolldy2, m_encd;
void focusInEvent(QFocusEvent*);
void focusOutEvent(QFocusEvent*);
- void ChangeFont(int);
- bool getline(CBuffer*);
+ bool ChangeFont(int);
+ bool getline(CDrawBuffer*);
int m_charWidth;
int m_charpc;
+ FontControl m_fontControl;
public:
QTReader( QWidget *parent=0, const char *name=0, WFlags f = 0);
// QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0);
@@ -66,6 +72,37 @@ public:
}
};
*/
+ void setpeanut(bool _b)
+ {
+ bpeanut = _b;
+ setfilter(getfilter());
+ }
+ void setremap(bool _b)
+ {
+ bremap = _b;
+ setfilter(getfilter());
+ }
+ void setmakebold(bool _b)
+ {
+ bmakebold = _b;
+ setfilter(getfilter());
+ }
+ void setautofmt(bool _b)
+ {
+ bautofmt = _b;
+ if (bautofmt)
+ {
+ btextfmt = false;
+ bstriphtml = false;;
+ bpeanut = false;
+ }
+ setfilter(getfilter());
+ }
+ void settextfmt(bool _b)
+ {
+ btextfmt = _b;
+ setfilter(getfilter());
+ }
void setstripcr(bool _b)
{
bstripcr = _b;
@@ -113,14 +150,15 @@ public:
void setmono(bool _b)
{
m_bMonoSpaced = _b;
- ChangeFont(fontsizes[m_textsize]);
- locate(pagepos);
+ ChangeFont(m_fontControl.currentsize());
+ locate(pagelocate());
}
void setencoding(int _f)
{
m_encd = _f;
setfilter(getfilter());
}
+ MarkupType PreferredMarkup();
CEncoding* getencoding()
{
switch (m_encd)
@@ -144,12 +182,18 @@ public:
{
CFilterChain * filt = new CFilterChain(getencoding());
if (bstripcr) filt->addfilter(new stripcr);
- if (bstriphtml) filt->addfilter(new striphtml);
+
+ if (btextfmt || (bautofmt && (PreferredMarkup() == cTEXT))) filt->addfilter(new textfmt);
+ if (bpeanut || (bautofmt && (PreferredMarkup() == cPML))) filt->addfilter(new PeanutFormatter);
+ if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new striphtml);
+
if (bdehyphen) filt->addfilter(new dehyphen);
if (bunindent) filt->addfilter(new unindent);
if (brepara) filt->addfilter(new repara);
if (bindenter) filt->addfilter(new indenter(bindenter));
if (bdblspce) filt->addfilter(new dblspce);
+ if (bremap) filt->addfilter(new remap);
+ if (bmakebold) filt->addfilter(new embolden);
return filt;
}
@@ -162,26 +206,31 @@ private slots:
void keyPressEvent(QKeyEvent*);
void drawFonts(QPainter*);
private:
+ void setTwoTouch(bool _b);
void init();
+ void mousePressEvent( QMouseEvent* );
void mouseReleaseEvent( QMouseEvent* );
// void mouseDoubleClickEvent( QMouseEvent* );
QString m_string, m_fontname;
- void setfont(QPainter*);
+ void setfont();
//myoutput stuff
private:
+ bool mouseUpOn;
+ bool getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt);
+ bool m_twotouch, m_touchone;
+ size_t m_startpos, m_startoffset;
void dopageup();
void lineDown();
void lineUp();
void dopagedn();
long real_delay();
int m_textsize;
- int m_lastwidth;
- CBuffer** textarray;
- size_t* locnarray;
+ int m_lastwidth, m_lastheight;
+ CBufferFace<CDrawBuffer*> textarray;
+ CBufferFace<size_t> locnarray;
unsigned int numlines;
- bool bstripcr, bstriphtml, bdehyphen, bunindent, brepara, bdblspce, btight, m_bBold;
+ bool bstripcr, btextfmt, bstriphtml, bdehyphen, bunindent, brepara, bdblspce, btight, bmakebold, bremap, bpeanut, bautofmt;
bool m_bpagemode, m_bMonoSpaced;
- QString m_targetapp, m_targetmsg;
unsigned char bindenter;
QString m_lastfile;
size_t m_lastposn;
@@ -194,24 +243,30 @@ private slots:
bool locate(unsigned long n);
void jumpto(unsigned long n) { buffdoc.locate(n); }
unsigned long locate() { return buffdoc.locate(); }
- unsigned long pagelocate() { return pagepos; }
- unsigned long pagepos, mylastpos;
- void setfilter(CFilterChain *f) { buffdoc.setfilter(f); locate(pagepos); }
+ unsigned long explocate() { return buffdoc.explocate(); }
+ unsigned long pagelocate() { return locnarray[0]; }
+ unsigned long mylastpos;
+ void setfilter(CFilterChain *f) { buffdoc.setfilter(f); locate(pagelocate()); }
void restore() { jumpto(mylastpos); }
void goUp();
- void refresh() { locate(pagepos); }
+ void refresh() { locate(pagelocate()); }
void goDown();
// bool bold;
int textsize() { return m_textsize; }
void textsize(int ts) { m_textsize = ts; }
- bool fillbuffer();
+ bool fillbuffer(int ru = 0, int ht = 0);
unsigned int screenlines();
void sizes(unsigned long& fs, unsigned long& ts) { buffdoc.sizes(fs,ts); }
static const char *fonts[];
- unsigned int *fontsizes;
+// unsigned int *fontsizes;
int m_ascent, m_descent, m_linespacing;
QFontMetrics* m_fm;
QString firstword();
+
+ signals:
+ void OnRedraw();
+ void OnWordSelected(const QString&, size_t, const QString&);
+ void OnActionPressed();
};
#endif
diff --git a/noncore/apps/opie-reader/QTReaderApp.cpp b/noncore/apps/opie-reader/QTReaderApp.cpp
index 68c80c1..0608b66 100644
--- a/noncore/apps/opie-reader/QTReaderApp.cpp
+++ b/noncore/apps/opie-reader/QTReaderApp.cpp
@@ -18,6 +18,7 @@
**
**********************************************************************/
+#include <qclipboard.h>
#include <qwidgetstack.h>
#include <qpe/qpemenubar.h>
#include <qpe/qpetoolbar.h>
@@ -38,10 +39,14 @@
#include <qpe/config.h>
#include <qbuttongroup.h>
#include <qradiobutton.h>
+#include <qpe/qcopenvelope_qws.h>
+#include "QTReader.h"
+#include "Bkmks.h"
#include "cbkmkselector.h"
#include "infowin.h"
-
+#include "CAnnoEdit.h"
+#include "QFloatBar.h"
//#include <qpe/fontdatabase.h>
#include <qpe/resource.h>
@@ -49,6 +54,7 @@
#include "QTReaderApp.h"
#include "fileBrowser.h"
+#include "CDrawBuffer.h"
unsigned long QTReaderApp::m_uid = 0;
@@ -68,28 +74,28 @@ void QTReaderApp::listBkmkFiles()
while(1)
{
- struct dirent* de;
- struct stat buf;
- de = readdir(d);
- if (de == NULL) break;
-
- if (lstat((const char *)Global::applicationFileName("uqtreader",de->d_name),&buf) == 0 && S_ISREG(buf.st_mode))
- {
- bkmkselector->insertItem(de->d_name);
- cnt++;
- }
+ struct dirent* de;
+ struct stat buf;
+ de = readdir(d);
+ if (de == NULL) break;
+
+ if (lstat((const char *)Global::applicationFileName("uqtreader",de->d_name),&buf) == 0 && S_ISREG(buf.st_mode))
+ {
+ bkmkselector->insertItem(de->d_name);
+ cnt++;
+ }
}
closedir(d);
if (cnt > 0)
{
- menu->hide();
+//tjw menu->hide();
editBar->hide();
if (m_fontVisible) m_fontBar->hide();
if (regVisible) regBar->hide();
if (searchVisible) searchBar->hide();
- m_nRegAction = cRmBkmkFile;
+ m_nRegAction = cRmBkmkFile;
editorStack->raiseWidget( bkmkselector );
}
else
@@ -97,7 +103,7 @@ void QTReaderApp::listBkmkFiles()
}
QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
- : QMainWindow( parent, name, f ), bFromDocView( FALSE )
+ : QMainWindow( parent, name, f ), bFromDocView( FALSE ), m_dontSave(false)
{
// qDebug("Application directory = %s", (const tchar *)QPEApplication::documentDir());
// qDebug("Application directory = %s", (const tchar *)Global::applicationFileName("uqtreader","bkmks.xml"));
@@ -105,11 +111,11 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
pBkmklist = NULL;
doc = 0;
- m_fBkmksChanged = false;
+ m_fBkmksChanged = false;
QString lang = getenv( "LANG" );
- m_autogenstr = "^ *[A-Z].*[a-z] *$";
+ m_autogenstr = "^ *[A-Z].*[a-z] *$";
setToolBarsMovable( FALSE );
setIcon( Resource::loadPixmap( "uqtreader" ) );
@@ -117,7 +123,7 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
QPEToolBar *bar = new QPEToolBar( this );
bar->setHorizontalStretchable( TRUE );
addToolBar(bar, "tool",QMainWindow::Top, true);
- menu = bar;
+//tjw menu = bar;
QPEMenuBar *mb = new QPEMenuBar( bar );
QPopupMenu *file = new QPopupMenu( this );
@@ -144,6 +150,11 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
pbar = new QProgressBar(this);
pbar->hide();
+ m_annoWin = new CAnnoEdit(editorStack);
+ editorStack->addWidget(m_annoWin, get_unique_id());
+ connect( m_annoWin, SIGNAL( finished(const QString&, const QString&) ), this, SLOT( addAnno(const QString&, const QString&) ) );
+ connect( m_annoWin, SIGNAL( cancelled() ), this, SLOT( infoClose() ) );
+
m_infoWin = new infowin(editorStack);
editorStack->addWidget(m_infoWin, get_unique_id());
connect( m_infoWin, SIGNAL( Close() ), this, SLOT( infoClose() ) );
@@ -166,18 +177,23 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
*/
reader = new QTReader( editorStack );
+
+ ((QPEApplication*)qApp)->setStylusOperation(reader, QPEApplication::RightOnHold);
+
Config config( "uqtreader" );
config.setGroup( "View" );
reader->bstripcr = config.readBoolEntry( "StripCr", true );
+ reader->btextfmt = config.readBoolEntry( "TextFmt", false );
+ reader->bautofmt = config.readBoolEntry( "AutoFmt", true );
reader->bstriphtml = config.readBoolEntry( "StripHtml", false );
+ reader->bpeanut = config.readBoolEntry( "Peanut", false );
reader->bdehyphen = config.readBoolEntry( "Dehyphen", false );
reader->bunindent = config.readBoolEntry( "Unindent", false );
reader->brepara = config.readBoolEntry( "Repara", false );
reader->bdblspce = config.readBoolEntry( "DoubleSpace", false );
reader->bindenter = config.readNumEntry( "Indent", 0 );
reader->m_textsize = config.readNumEntry( "FontSize", 12 );
- reader->m_bBold = config.readBoolEntry( "Bold", false );
reader->m_delay = config.readNumEntry( "ScrollDelay", 5184);
reader->m_lastfile = config.readEntry( "LastFile", QString::null );
reader->m_lastposn = config.readNumEntry( "LastPosn", 0 );
@@ -187,9 +203,21 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
reader->m_encd = config.readNumEntry( "Encoding", 0 );
reader->m_charpc = config.readNumEntry( "CharSpacing", 100 );
reader->m_overlap = config.readNumEntry( "Overlap", 0 );
- reader->m_targetapp = config.readEntry( "TargetApp", QString::null );
- reader->m_targetmsg = config.readEntry( "TargetMsg", QString::null );
- reader->init();
+ reader->bremap = config.readBoolEntry( "Remap", true );
+ reader->bmakebold = config.readBoolEntry( "MakeBold", false );
+ m_targetapp = config.readEntry( "TargetApp", QString::null );
+ m_targetmsg = config.readEntry( "TargetMsg", QString::null );
+ m_twoTouch = config.readBoolEntry( "TwoTouch", false);
+ m_doAnnotation = config.readBoolEntry( "Annotation", false);
+ m_doDictionary = config.readBoolEntry( "Dictionary", false);
+ m_doClipboard = config.readBoolEntry( "Clipboard", false);
+ m_spaceTarget = (ActionTypes)config.readNumEntry("SpaceTarget", cesAutoScroll);
+ setTwoTouch(m_twoTouch);
+
+
+ connect( reader, SIGNAL( OnRedraw() ), this, SLOT( OnRedraw() ) );
+ connect( reader, SIGNAL( OnActionPressed() ), this, SLOT( OnActionPressed() ) );
+ connect( reader, SIGNAL( OnWordSelected(const QString&, size_t, const QString&) ), this, SLOT( OnWordSelected(const QString&, size_t, const QString&) ) );
editorStack->addWidget( reader, get_unique_id() );
QAction *a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 );
@@ -212,16 +240,22 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
connect( a, SIGNAL( activated() ), this, SLOT( showinfo() ) );
a->addTo( file );
- a = new QAction( tr( "Start Block" ), QString::null, 0, this, NULL);
- connect( a, SIGNAL( activated() ), this, SLOT( editMark() ) );
- file->insertSeparator();
- a->addTo( file );
+ QActionGroup* ag = new QActionGroup(this);
+ QPopupMenu *spacemenu = new QPopupMenu(this);
+ file->insertItem( tr( "On Action..." ), spacemenu );
- a = new QAction( tr( "Copy Block" ), QString::null, 0, this, NULL);
- connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) );
- a->addTo( file );
+ m_buttonAction[0] = new QAction( tr( "Open File" ), QString::null, 0, ag, NULL, true );
+
+ m_buttonAction[1] = new QAction( tr( "Autoscroll" ), QString::null, 0, ag, NULL, true );
+
+ m_buttonAction[2] = new QAction( tr( "Mark" ), QString::null, 0, ag, NULL, true );
+
+ ag->addTo(spacemenu);
- a = m_scrollButton = new QAction( tr( "Scroll" ), Resource::loadPixmap( "opie-reader/panel-arrow-down" ), QString::null, 0, this, 0, true );
+ connect(ag, SIGNAL( selected(QAction*) ), this, SLOT( buttonActionSelected(QAction*) ) );
+
+
+ a = m_scrollButton = new QAction( tr( "Scroll" ), Resource::loadPixmap( "panel-arrow-down" ), QString::null, 0, this, 0, true );
// connect( a, SIGNAL( activated() ), this, SLOT( autoScroll() ) );
a->setOn(false);
connect( a, SIGNAL( toggled(bool) ), this, SLOT( autoScroll(bool) ) );
@@ -242,7 +276,7 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
connect( a, SIGNAL( activated() ), this, SLOT( jump() ) );
a->addTo( file );
- a = new QAction( tr( "Page/Line scroll" ), QString::null, 0, this, NULL, true );
+ a = new QAction( tr( "Page/Line Scroll" ), QString::null, 0, this, NULL, true );
connect( a, SIGNAL( toggled(bool) ), this, SLOT( pagemode(bool) ) );
a->setOn(reader->m_bpagemode);
a->addTo( file );
@@ -251,10 +285,37 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
connect( a, SIGNAL( activated() ), this, SLOT( setoverlap() ) );
a->addTo( file );
+ file->insertSeparator();
+
a = new QAction( tr( "Set Dictionary" ), QString::null, 0, this, NULL);
connect( a, SIGNAL( activated() ), this, SLOT( settarget() ) );
a->addTo( file );
+ a = new QAction( tr( "Two/One Touch" ), QString::null, 0, this, NULL, true );
+ connect( a, SIGNAL( toggled(bool) ), this, SLOT( setTwoTouch(bool) ) );
+ a->setOn(m_twoTouch);
+ a->addTo( file );
+
+ ag = new QActionGroup(this);
+ ag->setExclusive(false);
+ QPopupMenu *encoding = new QPopupMenu(this);
+ file->insertItem( tr( "Target" ), encoding );
+
+ a = new QAction( tr( "Annotation" ), QString::null, 0, ag, NULL, true );
+ connect( a, SIGNAL( toggled(bool) ), this, SLOT( OnAnnotation(bool) ) );
+ a->setOn(m_doAnnotation);
+
+ a = new QAction( tr( "Dictionary" ), QString::null, 0, ag, NULL, true );
+ connect( a, SIGNAL( toggled(bool) ), this, SLOT( OnDictionary(bool) ) );
+ a->setOn(m_doDictionary);
+
+ a = new QAction( tr( "Clipboard" ), QString::null, 0, ag, NULL, true );
+ connect( a, SIGNAL( toggled(bool) ), this, SLOT( OnClipboard(bool) ) );
+ a->setOn(m_doClipboard);
+
+ ag->addTo(encoding);
+
+
/*
a = new QAction( tr( "Import" ), QString::null, 0, this, NULL );
connect( a, SIGNAL( activated() ), this, SLOT( importFiles() ) );
@@ -276,56 +337,95 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
a->addTo( edit );
*/
- a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 );
+// a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 );
+ a = new QAction( tr( "Find..." ), QString::null, 0, this, NULL);
connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) );
file->insertSeparator();
- a->addTo( bar );
+// a->addTo( bar );
a->addTo( file );
- a = new QAction( tr( "Strip CR" ), QString::null, 0, this, NULL, true );
- a->setOn(reader->bstripcr);
- connect( a, SIGNAL( toggled(bool) ), this, SLOT( stripcr(bool) ) );
- a->addTo( format );
- // a->setOn(true);
+ a = m_bkmkAvail = new QAction( tr( "Annotation" ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 );
+ connect( a, SIGNAL( activated() ), this, SLOT( showAnnotation() ) );
+ a->addTo( bar );
- a = new QAction( tr( "Strip HTML" ), QString::null, 0, this, NULL, true );
+ m_bkmkAvail->setEnabled(false);
+
+
+ ag = new QActionGroup(this);
+// ag->setExclusive(false);
+ encoding = new QPopupMenu(this);
+ format->insertItem( tr( "Markup" ), encoding );
+
+ a = new QAction( tr( "Auto" ), QString::null, 0, ag, NULL, true );
+ a->setOn(reader->bautofmt);
+ connect( a, SIGNAL( toggled(bool) ), this, SLOT( autofmt(bool) ) );
+
+ a = new QAction( tr( "None" ), QString::null, 0, ag, NULL, true );
+ a->setOn(!reader->bautofmt && !(reader->btextfmt || reader->bstriphtml || reader->bpeanut));
+// connect( a, SIGNAL( toggled(bool) ), this, SLOT( textfmt(bool) ) );
+
+ a = new QAction( tr( "Text" ), QString::null, 0, ag, NULL, true );
+ a->setOn(reader->btextfmt);
+ connect( a, SIGNAL( toggled(bool) ), this, SLOT( textfmt(bool) ) );
+
+ a = new QAction( tr( "HTML" ), QString::null, 0, ag, NULL, true );
a->setOn(reader->bstriphtml);
connect( a, SIGNAL( toggled(bool) ), this, SLOT( striphtml(bool) ) );
- a->addTo( format );
- a = new QAction( tr( "Dehyphen" ), QString::null, 0, this, NULL, true );
+ a = new QAction( tr( "Peanut/PML" ), QString::null, 0, ag, NULL, true );
+ a->setOn(reader->bpeanut);
+ connect( a, SIGNAL( toggled(bool) ), this, SLOT( peanut(bool) ) );
+
+ ag->addTo(encoding);
+
+
+
+ ag = new QActionGroup(this);
+ ag->setExclusive(false);
+ encoding = new QPopupMenu(this);
+ format->insertItem( tr( "Layout" ), encoding );
+
+ a = new QAction( tr( "Strip CR" ), QString::null, 0, ag, NULL, true );
+ a->setOn(reader->bstripcr);
+ connect( a, SIGNAL( toggled(bool) ), this, SLOT( stripcr(bool) ) );
+
+ a = new QAction( tr( "Dehyphen" ), QString::null, 0, ag, NULL, true );
a->setOn(reader->bdehyphen);
connect( a, SIGNAL( toggled(bool) ), this, SLOT( dehyphen(bool) ) );
- a->addTo( format );
+// a->addTo( format );
- a = new QAction( tr( "Unindent" ), QString::null, 0, this, NULL, true );
+ a = new QAction( tr( "Unindent" ), QString::null, 0, ag, NULL, true );
connect( a, SIGNAL( toggled(bool) ), this, SLOT( unindent(bool) ) );
a->setOn(reader->bunindent);
- a->addTo( format );
+// a->addTo( format );
- a = new QAction( tr( "Re-paragraph" ), QString::null, 0, this, NULL, true );
+ a = new QAction( tr( "Re-paragraph" ), QString::null, 0, ag, NULL, true );
connect( a, SIGNAL( toggled(bool) ), this, SLOT( repara(bool) ) );
a->setOn(reader->brepara);
- a->addTo( format );
+// a->addTo( format );
- a = new QAction( tr( "Double Space" ), QString::null, 0, this, NULL, true );
+ a = new QAction( tr( "Double Space" ), QString::null, 0, ag, NULL, true );
connect( a, SIGNAL( toggled(bool) ), this, SLOT( dblspce(bool) ) );
a->setOn(reader->bdblspce);
- a->addTo( format );
+// a->addTo( format );
- a = new QAction( tr( "Indent+" ), QString::null, 0, this, NULL );
+ a = new QAction( tr( "Indent+" ), QString::null, 0, ag, NULL );
connect( a, SIGNAL( activated() ), this, SLOT( indentplus() ) );
- a->addTo( format );
+// a->addTo( format );
- a = new QAction( tr( "Indent-" ), QString::null, 0, this, NULL );
+ a = new QAction( tr( "Indent-" ), QString::null, 0, ag, NULL );
connect( a, SIGNAL( activated() ), this, SLOT( indentminus() ) );
- a->addTo( format );
- a = new QAction( tr( "Bold" ), QString::null, 0, this, NULL, true );
- a->setOn(reader->m_bBold);
- connect( a, SIGNAL( toggled(bool) ), this, SLOT( setbold(bool) ) );
- a->addTo( format );
+ a = new QAction( tr( "Remap" ), QString::null, 0, ag, NULL, true );
+ connect( a, SIGNAL( toggled(bool) ), this, SLOT( remap(bool) ) );
+ a->setOn(reader->bremap);
+
+ a = new QAction( tr( "Embolden" ), QString::null, 0, ag, NULL, true );
+ connect( a, SIGNAL( toggled(bool) ), this, SLOT( embolden(bool) ) );
+ a->setOn(reader->bmakebold);
+
+ ag->addTo(encoding);
// a = new QAction( tr( "Zoom" ), QString::null, 0, this, NULL, true );
// a = new QAction( tr( "Zoom" ), Resource::loadPixmap( "mag" ), QString::null, 0, this, 0 );
@@ -346,11 +446,11 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
connect( a, SIGNAL( activated() ), this, SLOT( setspacing() ) );
a->addTo( format );
- QPopupMenu *encoding = new QPopupMenu(this);
- format->insertSeparator();
+ encoding = new QPopupMenu(this);
+// format->insertSeparator();
format->insertItem( tr( "Encoding" ), encoding );
- QActionGroup* ag = new QActionGroup(this);
+ ag = new QActionGroup(this);
m_EncodingAction[0] = new QAction( tr( "Ascii" ), QString::null, 0, ag, NULL, true );
@@ -379,6 +479,10 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
connect( a, SIGNAL( activated() ), this, SLOT( addbkmk() ) );
a->addTo( marks );
+ a = new QAction( tr( "Annotate" ), QString::null, 0, this, NULL);
+ connect( a, SIGNAL( activated() ), this, SLOT( addanno() ) );
+ a->addTo( marks );
+
a = new QAction( tr( "Goto" ), QString::null, 0, this, NULL, false );
connect( a, SIGNAL( activated() ), this, SLOT( do_gotomark() ) );
a->addTo( marks );
@@ -405,25 +509,38 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
marks->insertSeparator();
a->addTo( marks );
+ a = new QAction( tr( "Start Block" ), QString::null, 0, this, NULL);
+ connect( a, SIGNAL( activated() ), this, SLOT( editMark() ) );
+ marks->insertSeparator();
+ a->addTo( marks );
+
+ a = new QAction( tr( "Copy Block" ), QString::null, 0, this, NULL);
+ connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) );
+ a->addTo( marks );
+
+
mb->insertItem( tr( "File" ), file );
// mb->insertItem( tr( "Edit" ), edit );
mb->insertItem( tr( "Format" ), format );
mb->insertItem( tr( "Marks" ), marks );
- searchBar = new QToolBar( "Search", this, QMainWindow::Top, TRUE );
+ searchBar = new QFloatBar( "Search", this, QMainWindow::Top, TRUE );
searchBar->setHorizontalStretchable( TRUE );
+ connect(searchBar, SIGNAL( OnHide() ), this, SLOT( restoreFocus() ));
+
searchEdit = new QLineEdit( searchBar, "searchEdit" );
// QFont f("unifont", 16 /*, QFont::Bold*/);
// searchEdit->setFont( f );
searchBar->setStretchableWidget( searchEdit );
+
#ifdef __ISEARCH
connect( searchEdit, SIGNAL( textChanged( const QString & ) ),
- this, SLOT( search( const QString& ) ) );
+ this, SLOT( search( const QString& ) ) );
#else
connect( searchEdit, SIGNAL( returnPressed( ) ),
- this, SLOT( search( ) ) );
+ this, SLOT( search( ) ) );
#endif
a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) );
@@ -435,7 +552,8 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
searchBar->hide();
- regBar = new QToolBar( "Autogen", this, QMainWindow::Top, TRUE );
+ regBar = new QFloatBar( "Autogen", this, QMainWindow::Top, TRUE );
+ connect(regBar, SIGNAL( OnHide() ), this, SLOT( restoreFocus() ));
regBar->setHorizontalStretchable( TRUE );
@@ -445,7 +563,7 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
regBar->setStretchableWidget( regEdit );
connect( regEdit, SIGNAL( returnPressed( ) ),
- this, SLOT( do_regaction() ) );
+ this, SLOT( do_regaction() ) );
a = new QAction( tr( "Do Reg" ), Resource::loadPixmap( "enter" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( do_regaction() ) );
@@ -464,25 +582,40 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
m_fontSelector = new QComboBox(false, m_fontBar);
m_fontBar->setStretchableWidget( m_fontSelector );
{
- FontDatabase f;
- m_fontSelector->insertStringList(f.families());
+ FontDatabase f;
+ QStringList flist = f.families();
+ m_fontSelector->insertStringList(flist);
+
+ bool realfont = false;
+ for (QStringList::Iterator nm = flist.begin(); nm != flist.end(); nm++)
+ {
+ if (reader->m_fontname == *nm)
+ {
+ realfont = true;
+ break;
+ }
+ }
+ if (!realfont) reader->m_fontname = flist[0];
} // delete the FontDatabase!!!
+
connect( m_fontSelector, SIGNAL( activated(const QString& ) ),
- this, SLOT( do_setfont(const QString&) ) );
+ this, SLOT( do_setfont(const QString&) ) );
m_fontBar->hide();
m_fontVisible = false;
connect(qApp, SIGNAL( appMessage(const QCString&, const QByteArray& ) ),
- this, SLOT( msgHandler(const QCString&, const QByteArray&) ) );
+ this, SLOT( msgHandler(const QCString&, const QByteArray&) ) );
+ reader->init();
if (!reader->m_lastfile.isEmpty())
{
- openFile( reader->m_lastfile );
- doc = new DocLnk(reader->m_lastfile);
+ openFile( reader->m_lastfile );
+ doc = new DocLnk(reader->m_lastfile);
}
m_EncodingAction[reader->m_encd]->setOn(true);
+ m_buttonAction[m_spaceTarget]->setOn(true);
do_setfont(reader->m_fontname);
}
@@ -495,22 +628,259 @@ void QTReaderApp::msgHandler(const QCString& _msg, const QByteArray& _data)
QDataStream stream( _data, IO_ReadOnly );
if ( msg == "info(QString)" )
{
- QString info;
- stream >> info;
- QMessageBox::information(this, "QTReader", info);
- } else if ( msg == "warn(QString)" )
+ QString info;
+ stream >> info;
+ QMessageBox::information(this, "QTReader", info);
+ }
+ else if ( msg == "warn(QString)" )
+ {
+ QString info;
+ stream >> info;
+ QMessageBox::warning(this, "QTReader", info);
+ }
+
+
+ else if ( msg == "exit()" )
+ {
+ m_dontSave = true;
+ close();
+ }
+ else if ( msg == "pageDown()" )
+ {
+ reader->dopagedn();
+ }
+ else if ( msg == "pageUp()" )
+ {
+ reader->dopageup();
+ }
+ else if ( msg == "lineDown()" )
+ {
+ reader->lineDown();
+ }
+ else if ( msg == "lineUp()" )
+ {
+ reader->lineUp();
+ }
+ else if ( msg == "showText()" )
+ {
+ showEditTools();
+ }
+ else if ( msg == "File/Open(QString)" )
+ {
+ QString info;
+ stream >> info;
+ openFile( info );
+ }
+ else if ( msg == "File/Info()" )
+ {
+ showinfo();
+ }
+ else if ( msg == "File/Start Block()" )
+ {
+ editMark();
+ }
+ else if ( msg == "File/Copy Block()" )
+ {
+ editCopy();
+ }
+ else if ( msg == "File/Scroll(int)" )
+ {
+ int info;
+ stream >> info;
+ autoScroll(info);
+ }
+ else if ( msg == "File/Jump(int)" )
+ {
+ int info;
+ stream >> info;
+ reader->locate(info);
+ }
+ else if ( msg == "File/Page/Line Scroll(int)" )
+ {
+ int info;
+ stream >> info;
+ pagemode(info);
+ }
+ else if ( msg == "File/Set Overlap(int)" )
+ {
+ int info;
+ stream >> info;
+ reader->m_overlap = info;
+ }
+ else if ( msg == "File/Set Dictionary(QString)" )
+ {
+ QString info;
+ stream >> info;
+ do_settarget(info);
+ }
+ else if ( msg == "File/Two/One Touch(int)" )
+ {
+ int info;
+ stream >> info;
+ setTwoTouch(info);
+ }
+ else if ( msg == "Target/Annotation(int)" )
+ {
+ int info;
+ stream >> info;
+ OnAnnotation(info);
+ }
+ else if ( msg == "Target/Dictionary(int)" )
+ {
+ int info;
+ stream >> info;
+ OnDictionary(info);
+ }
+ else if ( msg == "Target/Clipboard(int)" )
+ {
+ int info;
+ stream >> info;
+ OnClipboard(info);
+ }
+ else if ( msg == "File/Find(QString)" )
+ {
+ QString info;
+ stream >> info;
+ QRegExp arg(info);
+ size_t pos = reader->pagelocate();
+ size_t start = pos;
+ CDrawBuffer test(&(reader->m_fontControl));
+ reader->buffdoc.getline(&test,reader->width());
+ while (arg.match(toQString(test.data())) == -1)
+ {
+ pos = reader->locate();
+ if (!reader->buffdoc.getline(&test,reader->width()))
+ {
+ QMessageBox::information(this, "QTReader", QString("Can't find\n")+info);
+ pos = start;
+ break;
+ }
+ }
+ reader->locate(pos);
+ }
+ else if ( msg == "Layout/Strip CR(int)" )
+ {
+ int info;
+ stream >> info;
+ stripcr(info);
+ }
+ else if ( msg == "Markup/Auto(int)" )
+ {
+ int info;
+ stream >> info;
+ autofmt(info);
+ }
+ else if ( msg == "Markup/Text(int)" )
+ {
+ int info;
+ stream >> info;
+ textfmt(info);
+ }
+ else if ( msg == "Markup/HTML(int)" )
+ {
+ int info;
+ stream >> info;
+ striphtml(info);
+ }
+ else if ( msg == "Markup/Peanut(int)" )
+ {
+ int info;
+ stream >> info;
+ peanut(info);
+ }
+ else if ( msg == "Layout/Dehyphen(int)" )
+ {
+ int info;
+ stream >> info;
+ dehyphen(info);
+ }
+ else if ( msg == "Layout/Unindent(int)" )
+ {
+ int info;
+ stream >> info;
+ unindent(info);
+ }
+ else if ( msg == "Layout/Re-paragraph(int)" )
+ {
+ int info;
+ stream >> info;
+ repara(info);
+ }
+ else if ( msg == "Layout/Double Space(int)" )
+ {
+ int info;
+ stream >> info;
+ dblspce(info);
+ }
+ else if ( msg == "Layout/Indent(int)" )
+ {
+ int info;
+ stream >> info;
+ reader->bindenter = info;
+ reader->setfilter(reader->getfilter());
+ }
+ else if ( msg == "Layout/Remap(int)" )
+ {
+ int info;
+ stream >> info;
+ remap(info);
+ }
+ else if ( msg == "Layout/Embolden(int)" )
+ {
+ int info;
+ stream >> info;
+ embolden(info);
+ }
+ else if ( msg == "Format/Ideogram/Word(int)" )
+ {
+ int info;
+ stream >> info;
+ monospace(info);
+ }
+ else if ( msg == "Format/Set width(int)" )
+ {
+ int info;
+ stream >> info;
+ reader->m_charpc = info;
+ reader->setfont();
+ reader->refresh();
+ }
+ else if ( msg == "Format/Encoding(QString)" )
+ {
+ QString info;
+ stream >> info;
+ reader->setencoding(EncNameToInt(info));
+ }
+ else if ( msg == "Format/Set Font(QString,int)" )
{
- QString info;
- stream >> info;
- QMessageBox::warning(this, "QTReader", info);
+ QString fontname;
+ int size;
+ stream >> fontname;
+ stream >> size;
+ setfontHelper(fontname, size);
+ }
+ else if ( msg == "Marks/Autogen(QString)" )
+ {
+ QString info;
+ stream >> info;
+ do_autogen(info);
}
}
+ActionTypes QTReaderApp::ActNameToInt(const QString& _enc)
+{
+ for (int i = 0; i < MAX_ACTIONS; i++)
+ {
+ if (m_buttonAction[i]->text() == _enc) return (ActionTypes)i;
+ }
+ return cesAutoScroll;
+}
+
int QTReaderApp::EncNameToInt(const QString& _enc)
{
for (int i = 0; i < MAX_ENCODING; i++)
{
- if (m_EncodingAction[i]->text() == _enc) return i;
+ if (m_EncodingAction[i]->text() == _enc) return i;
}
return 0;
/*
@@ -527,6 +897,12 @@ void QTReaderApp::encodingSelected(QAction* _a)
reader->setencoding(EncNameToInt(_a->text()));
}
+void QTReaderApp::buttonActionSelected(QAction* _a)
+{
+// qDebug("es:%x : %s (%u)", _a, (const char *)(_a->text()), ActNameToInt(_a->text()));
+ m_spaceTarget = ActNameToInt(_a->text());
+}
+
QTReaderApp::~QTReaderApp()
{
}
@@ -548,9 +924,9 @@ void QTReaderApp::TBDzoom()
void QTReaderApp::clearBkmkList()
{
- delete pBkmklist;
- pBkmklist = NULL;
- m_fBkmksChanged = false;
+ delete pBkmklist;
+ pBkmklist = NULL;
+ m_fBkmksChanged = false;
}
void QTReaderApp::fileOpen()
@@ -563,14 +939,14 @@ void QTReaderApp::fileOpen()
*/
if (pBkmklist != NULL)
{
- if (m_fBkmksChanged)
- {
- if (QMessageBox::warning(this, "QTReader", "Save bookmarks?", "Save", "Don't bother") == 0)
- savebkmks();
- }
- delete pBkmklist;
- pBkmklist = NULL;
- m_fBkmksChanged = false;
+ if (m_fBkmksChanged)
+ {
+ if (QMessageBox::warning(this, "QTReader", "Save bookmarks?", "Save", "Don't bother") == 0)
+ savebkmks();
+ }
+ delete pBkmklist;
+ pBkmklist = NULL;
+ m_fBkmksChanged = false;
}
reader->disableAutoscroll();
/*
@@ -578,17 +954,18 @@ void QTReaderApp::fileOpen()
fileSelector->reread();
*/
fileBrowser* fb = new fileBrowser(this,"QTReader",TRUE,
- 0,
-// WStyle_Customize | WStyle_NoBorderEx,
- "*", QFileInfo(reader->m_lastfile).dirPath(true));
+ 0,
+// WStyle_Customize | WStyle_NoBorderEx,
+ "*", QFileInfo(reader->m_lastfile).dirPath(true));
if (fb->exec())
{
- QString fn(fb->fileList[0]);
+ QString fn(fb->fileList[0]);
// fb->populateList();
- if (!fn.isEmpty() && QFileInfo(fn).isFile()) openFile(fn);
+ if (!fn.isEmpty() && QFileInfo(fn).isFile()) openFile(fn);
}
delete fb;
+ reader->setFocus();
}
void QTReaderApp::showinfo()
@@ -596,19 +973,120 @@ void QTReaderApp::showinfo()
unsigned long fs, ts, pl;
if (reader->empty())
{
- QMessageBox::information(this, "QTReader", "No file loaded", 1);
+ QMessageBox::information(this, "QTReader", "No file loaded", 1);
}
else
{
- reader->sizes(fs,ts);
- pl = reader->pagelocate();
- m_infoWin->setFileSize(fs);
- m_infoWin->setTextSize(ts);
- m_infoWin->setRatio(100-(100*fs + (ts >> 1))/ts);
- m_infoWin->setLocation(pl);
- m_infoWin->setRead((100*pl + (ts >> 1))/ts);
- editorStack->raiseWidget( m_infoWin );
- m_infoWin->setFocus();
+ reader->sizes(fs,ts);
+ pl = reader->pagelocate();
+ m_infoWin->setFileSize(fs);
+ m_infoWin->setTextSize(ts);
+ m_infoWin->setRatio(100-(100*fs + (ts >> 1))/ts);
+ m_infoWin->setLocation(pl);
+ m_infoWin->setRead((100*pl + (ts >> 1))/ts);
+ editorStack->raiseWidget( m_infoWin );
+ m_infoWin->setFocus();
+ }
+}
+
+void QTReaderApp::addAnno(const QString& name, const QString& text, size_t posn)
+{
+ if (pBkmklist == NULL) pBkmklist = new CList<Bkmk>;
+#ifdef _UNICODE
+ CBuffer buff(name.length()+1);
+ int i;
+ for (i = 0; i < name.length(); i++)
+ {
+ buff[i] = name[i].unicode();
+ }
+ buff[i] = 0;
+ CBuffer buff2(text.length()+1);
+ for (i = 0; i < text.length(); i++)
+ {
+ buff2[i] = text[i].unicode();
+ }
+ buff2[i] = 0;
+ pBkmklist->push_front(Bkmk(buff.data(), buff2.data(), posn));
+#else
+ pBkmklist->push_front(Bkmk((const tchar*)text,posn));
+#endif
+ m_fBkmksChanged = true;
+ pBkmklist->sort();
+}
+
+void QTReaderApp::addAnno(const QString& name, const QString& text)
+{
+ if (m_annoIsEditing)
+ {
+ if (name.isEmpty())
+ {
+ QMessageBox::information(this, "QTReader", "Need a name for the bookmark\nPlease try again", 1);
+ }
+ else
+ {
+ addAnno(name, text, m_annoWin->getPosn());
+ }
+ showEditTools();
+ }
+ else
+ {
+ if (m_annoWin->edited())
+ {
+ CBuffer buff(text.length()+1);
+ int i;
+ for (i = 0; i < text.length(); i++)
+ {
+ buff[i] = text[i].unicode();
+ }
+ buff[i] = 0;
+ m_fBkmksChanged = true;
+ m_anno->setAnno(buff.data());
+ }
+ bool found = findNextBookmark(m_anno->value()+1);
+ if (found)
+ {
+ m_annoWin->setName(toQString(m_anno->name()));
+ m_annoWin->setAnno(toQString(m_anno->anno()));
+ }
+ else
+ {
+ showEditTools();
+ }
+ }
+}
+
+bool QTReaderApp::findNextBookmark(size_t start)
+{
+ bool found = false;
+ for (CList<Bkmk>::iterator iter = pBkmklist->begin(); iter != pBkmklist->end(); iter++)
+ {
+ if (iter->value() >= start)
+ {
+ if (iter->value() < reader->locate())
+ {
+ found = true;
+ m_anno = iter.pContent();
+ }
+ break;
+ }
+ }
+ return found;
+}
+
+void QTReaderApp::addanno()
+{
+ if (reader->empty())
+ {
+ QMessageBox::information(this, "QTReader", "No file loaded", 1);
+ }
+ else
+ {
+ m_annoWin->setName("");
+ m_annoWin->setAnno("");
+ m_annoWin->setPosn(reader->pagelocate());
+ m_annoIsEditing = true;
+ editorStack->raiseWidget( m_annoWin );
+ m_annoWin->setFocus();
}
}
@@ -638,25 +1116,18 @@ void QTReaderApp::editMark()
void QTReaderApp::editCopy()
{
- QClipboard* cb = QApplication::clipboard();
- QString text;
- int ch;
- unsigned long currentpos = reader->pagelocate();
- unsigned long endpos = reader->locate();
- reader->jumpto(m_savedpos);
- while (reader->locate() < endpos && (ch = reader->getch()) != UEOF)
- {
- text += ch;
- }
- cb->setText(text);
-// text = cb->text();
-// if (text)
-// qDebug("The clipboard contains: %s", (const tchar*)text);
- reader->locate(currentpos);
-#ifndef QT_NO_CLIPBOARD
-// TBD();
- // reader->copy();
-#endif
+ QClipboard* cb = QApplication::clipboard();
+ QString text;
+ int ch;
+ unsigned long currentpos = reader->pagelocate();
+ unsigned long endpos = reader->locate();
+ reader->jumpto(m_savedpos);
+ while (reader->explocate() < endpos && (ch = reader->getch()) != UEOF)
+ {
+ text += ch;
+ }
+ cb->setText(text);
+ reader->locate(currentpos);
}
void QTReaderApp::pageup()
@@ -673,6 +1144,26 @@ void QTReaderApp::stripcr(bool _b)
{
reader->setstripcr(_b);
}
+void QTReaderApp::remap(bool _b)
+{
+ reader->setremap(_b);
+}
+void QTReaderApp::peanut(bool _b)
+{
+ reader->setpeanut(_b);
+}
+void QTReaderApp::embolden(bool _b)
+{
+ reader->setmakebold(_b);
+}
+void QTReaderApp::autofmt(bool _b)
+{
+ reader->setautofmt(_b);
+}
+void QTReaderApp::textfmt(bool _b)
+{
+ reader->settextfmt(_b);
+}
void QTReaderApp::striphtml(bool _b)
{
reader->setstriphtml(_b);
@@ -689,12 +1180,6 @@ void QTReaderApp::repara(bool _b)
{
reader->setrepara(_b);
}
-void QTReaderApp::setbold(bool _b)
-{
- reader->m_bBold = _b;
- reader->ChangeFont(reader->fontsizes[reader->m_textsize]);
- reader->refresh();
-}
void QTReaderApp::dblspce(bool _b)
{
reader->setdblspce(_b);
@@ -730,9 +1215,9 @@ void QTReaderApp::setoverlap()
void QTReaderApp::settarget()
{
m_nRegAction = cSetTarget;
- QString text = ((reader->m_targetapp.isEmpty()) ? QString("") : reader->m_targetapp)
- + "/"
- + ((reader->m_targetmsg.isEmpty()) ? QString("") : reader->m_targetmsg);
+ QString text = ((m_targetapp.isEmpty()) ? QString("") : m_targetapp)
+ + "/"
+ + ((m_targetmsg.isEmpty()) ? QString("") : m_targetmsg);
regEdit->setText(text);
do_regedit();
}
@@ -743,10 +1228,10 @@ void QTReaderApp::do_overlap(const QString& lcn)
unsigned long ulcn = lcn.toULong(&ok);
if (ok)
{
- reader->m_overlap = ulcn;
+ reader->m_overlap = ulcn;
}
else
- QMessageBox::information(this, "QTReader", "Must be a number");
+ QMessageBox::information(this, "QTReader", "Must be a number");
}
void QTReaderApp::do_mono(const QString& lcn)
@@ -755,11 +1240,13 @@ void QTReaderApp::do_mono(const QString& lcn)
unsigned long ulcn = lcn.toULong(&ok);
if (ok)
{
- reader->m_charpc = ulcn;
-// reader->setmono(true);
+ reader->m_charpc = ulcn;
+ reader->setfont();
+ reader->refresh();
+// reader->setmono(true);
}
else
- QMessageBox::information(this, "QTReader", "Must be a number");
+ QMessageBox::information(this, "QTReader", "Must be a number");
}
/*
@@ -793,7 +1280,7 @@ void QTReaderApp::findNext()
#else
QRegExp arg = searchEdit->text();
#endif
- CBuffer test;
+ CDrawBuffer test(&(reader->m_fontControl));
size_t start = reader->pagelocate();
reader->jumpto(start);
reader->buffdoc.getline(&test,reader->width());
@@ -825,13 +1312,13 @@ void QTReaderApp::regClose()
}
#ifdef __ISEARCH
-bool QTReaderApp::dosearch(size_t start, CBuffer& test, const QString& arg)
+bool QTReaderApp::dosearch(size_t start, CDrawBuffer& test, const QString& arg)
#else
-bool QTReaderApp::dosearch(size_t start, CBuffer& test, const QRegExp& arg)
+bool QTReaderApp::dosearch(size_t start, CDrawBuffer& test, const QRegExp& arg)
#endif
{
bool ret = true;
- size_t pos = start;
+ size_t pos = reader->locate();
reader->buffdoc.getline(&test,reader->width());
#ifdef __ISEARCH
while (strstr(test.data(),(const tchar*)arg) == NULL)
@@ -845,15 +1332,15 @@ bool QTReaderApp::dosearch(size_t start, CBuffer& test, const QRegExp& arg)
{
pos = reader->locate();
if (!reader->buffdoc.getline(&test,reader->width()))
- {
- if (QMessageBox::warning(this, "Can't find", searchEdit->text(), 1, 2) == 2)
- pos = searchStart;
- else
- pos = start;
- ret = false;
- findClose();
- break;
- }
+ {
+ if (QMessageBox::warning(this, "Can't find", searchEdit->text(), 1, 2) == 2)
+ pos = searchStart;
+ else
+ pos = start;
+ ret = false;
+ findClose();
+ break;
+ }
}
reader->locate(pos);
return ret;
@@ -895,11 +1382,7 @@ void QTReaderApp::search(const QString & arg)
#else
void QTReaderApp::search()
{
- QRegExp arg = searchEdit->text();
- CBuffer test;
- size_t start = reader->pagelocate();
-// reader->jumpto(start);
- dosearch(start, test, arg);
+ findNext();
}
#endif
@@ -937,20 +1420,20 @@ void QTReaderApp::openFile( const DocLnk &f )
{
QMessageBox::information(this, "QTReader", "File does not exist");
}
-
+
}
void QTReaderApp::showEditTools()
{
if ( !doc )
- close();
+ close();
// fileSelector->hide();
- menu->show();
+//tjw menu->show();
editBar->show();
if ( searchVisible )
- searchBar->show();
+ searchBar->show();
if ( regVisible )
- regBar->show();
+ regBar->show();
if (m_fontVisible) m_fontBar->show();
updateCaption();
@@ -961,27 +1444,27 @@ void QTReaderApp::showEditTools()
void QTReaderApp::save()
{
if ( !doc )
- return;
+ return;
if ( !editor->edited() )
- return;
+ return;
QString rt = editor->text();
QString pt = rt;
if ( doc->name().isEmpty() ) {
- unsigned ispace = pt.find( ' ' );
- unsigned ienter = pt.find( '\n' );
- int i = (ispace < ienter) ? ispace : ienter;
- QString docname;
- if ( i == -1 ) {
- if ( pt.isEmpty() )
- docname = "Empty Text";
- else
- docname = pt;
- } else {
- docname = pt.left( i );
- }
- doc->setName(docname);
+ unsigned ispace = pt.find( ' ' );
+ unsigned ienter = pt.find( '\n' );
+ int i = (ispace < ienter) ? ispace : ienter;
+ QString docname;
+ if ( i == -1 ) {
+ if ( pt.isEmpty() )
+ docname = "Empty Text";
+ else
+ docname = pt;
+ } else {
+ docname = pt.left( i );
+ }
+ doc->setName(docname);
}
FileManager fm;
fm.saveFile( *doc, rt );
@@ -993,9 +1476,9 @@ void QTReaderApp::clear()
if (doc != 0)
{
// QMessageBox::information(this, "QTReader", "Deleting doc", 1);
- delete doc;
+ delete doc;
// QMessageBox::information(this, "QTReader", "Deleted doc", 1);
- doc = 0;
+ doc = 0;
}
reader->clear();
}
@@ -1003,12 +1486,12 @@ void QTReaderApp::clear()
void QTReaderApp::updateCaption()
{
if ( !doc )
- setCaption( tr("Opie Reader") );
+ setCaption( tr("QTReader") );
else {
- QString s = doc->name();
- if ( s.isEmpty() )
- s = tr( "Unnamed" );
- setCaption( s + " - " + tr("Opie Reader") );
+ QString s = doc->name();
+ if ( s.isEmpty() )
+ s = tr( "Unnamed" );
+ setCaption( s + " - " + tr("QTReader") );
}
}
@@ -1022,40 +1505,47 @@ void QTReaderApp::setDocument(const QString& fileref)
void QTReaderApp::closeEvent( QCloseEvent *e )
{
- if (editorStack->visibleWidget() == reader)
+ if (m_dontSave)
{
- if (m_fontVisible)
- {
- m_fontBar->hide();
- m_fontVisible = false;
- }
- if (regVisible)
- {
- regBar->hide();
- regVisible = false;
- return;
- }
- if (searchVisible)
- {
- searchBar->hide();
- searchVisible = false;
- return;
- }
- if (m_fBkmksChanged && pBkmklist != NULL)
- {
- if (QMessageBox::warning(this, "QTReader", "Save bookmarks?", "Save", "Don't bother") == 0)
- savebkmks();
- delete pBkmklist;
- pBkmklist = NULL;
- m_fBkmksChanged = false;
- }
- bFromDocView = FALSE;
- saveprefs();
- e->accept();
+ e->accept();
}
else
{
- showEditTools();
+ if (editorStack->visibleWidget() == reader)
+ {
+ if (m_fontVisible)
+ {
+ m_fontBar->hide();
+ m_fontVisible = false;
+ }
+ if (regVisible)
+ {
+ regBar->hide();
+ regVisible = false;
+ return;
+ }
+ if (searchVisible)
+ {
+ searchBar->hide();
+ searchVisible = false;
+ return;
+ }
+ if (m_fBkmksChanged && pBkmklist != NULL)
+ {
+ if (QMessageBox::warning(this, "QTReader", "Save bookmarks?", "Save", "Don't bother") == 0)
+ savebkmks();
+ delete pBkmklist;
+ pBkmklist = NULL;
+ m_fBkmksChanged = false;
+ }
+ bFromDocView = FALSE;
+ saveprefs();
+ e->accept();
+ }
+ else
+ {
+ showEditTools();
+ }
}
}
@@ -1077,20 +1567,19 @@ void QTReaderApp::listbkmk()
int cnt = 0;
if (pBkmklist != NULL)
{
- if (m_fBkmksChanged) pBkmklist->sort();
- for (CList<Bkmk>::iterator i = pBkmklist->begin(); i != pBkmklist->end(); i++)
- {
+ for (CList<Bkmk>::iterator i = pBkmklist->begin(); i != pBkmklist->end(); i++)
+ {
#ifdef _UNICODE
- bkmkselector->insertItem(toQString(i->name()));
+ bkmkselector->insertItem(toQString(i->name()));
#else
- bkmkselector->insertItem(i->name());
+ bkmkselector->insertItem(i->name());
#endif
- cnt++;
- }
+ cnt++;
+ }
}
if (cnt > 0)
{
- menu->hide();
+//tjw menu->hide();
editBar->hide();
if (m_fontVisible) m_fontBar->hide();
if (regVisible) regBar->hide();
@@ -1120,17 +1609,18 @@ void QTReaderApp::gotobkmk(int ind)
{
switch (m_nRegAction)
{
- case cGotoBkmk:
- reader->locate((*pBkmklist)[ind]->value());
- break;
- case cDelBkmk:
-// qDebug("Deleting:%s\n",(*pBkmklist)[ind]->name());
- pBkmklist->erase(ind);
- m_fBkmksChanged = true;
- break;
- case cRmBkmkFile:
- unlink((const char *)Global::applicationFileName("uqtreader",bkmkselector->text(ind)));
- break;
+ case cGotoBkmk:
+ reader->locate((*pBkmklist)[ind]->value());
+ break;
+ case cDelBkmk:
+// qDebug("Deleting:%s\n",(*pBkmklist)[ind]->name());
+ pBkmklist->erase(ind);
+ m_fBkmksChanged = true;
+// pBkmklist->sort();
+ break;
+ case cRmBkmkFile:
+ unlink((const char *)Global::applicationFileName("uqtreader",bkmkselector->text(ind)));
+ break;
}
showEditTools();
}
@@ -1154,9 +1644,9 @@ void QTReaderApp::do_jump(const QString& lcn)
bool ok;
unsigned long ulcn = lcn.toULong(&ok);
if (ok)
- reader->locate(ulcn);
+ reader->locate(ulcn);
else
- QMessageBox::information(this, "QTReader", "Must be a number");
+ QMessageBox::information(this, "QTReader", "Must be a number");
}
void QTReaderApp::do_regaction()
@@ -1166,23 +1656,23 @@ void QTReaderApp::do_regaction()
switch(m_nRegAction)
{
case cAutoGen:
- do_autogen(regEdit->text());
- break;
+ do_autogen(regEdit->text());
+ break;
case cAddBkmk:
- do_addbkmk(regEdit->text());
- break;
+ do_addbkmk(regEdit->text());
+ break;
case cJump:
- do_jump(regEdit->text());
- break;
+ do_jump(regEdit->text());
+ break;
case cMonoSpace:
- do_mono(regEdit->text());
- break;
+ do_mono(regEdit->text());
+ break;
case cOverlap:
- do_overlap(regEdit->text());
- break;
+ do_overlap(regEdit->text());
+ break;
case cSetTarget:
- do_settarget(regEdit->text());
- break;
+ do_settarget(regEdit->text());
+ break;
}
reader->restore();
// editBar->show();
@@ -1194,14 +1684,14 @@ void QTReaderApp::do_settarget(const QString& _txt)
int ind = _txt.find('/');
if (ind == -1)
{
- reader->m_targetapp = "";
- reader->m_targetmsg = "";
- QMessageBox::information(this, "QTReader", "Format is\nappname/messagename");
+ m_targetapp = "";
+ m_targetmsg = "";
+ QMessageBox::information(this, "QTReader", "Format is\nappname/messagename");
}
else
{
- reader->m_targetapp = _txt.left(ind);
- reader->m_targetmsg = _txt.right(_txt.length()-ind-1);
+ m_targetapp = _txt.left(ind);
+ m_targetmsg = _txt.right(_txt.length()-ind-1);
}
}
@@ -1209,30 +1699,40 @@ void QTReaderApp::setfont()
{
for (int i = 1; i <= m_fontSelector->count(); i++)
{
- if (m_fontSelector->text(i) == reader->m_fontname)
- {
- m_fontSelector->setCurrentItem(i);
- break;
- }
+ if (m_fontSelector->text(i) == reader->m_fontname)
+ {
+ m_fontSelector->setCurrentItem(i);
+ break;
+ }
}
m_fontBar->show();
m_fontVisible = true;
}
-void QTReaderApp::do_setfont(const QString& lcn)
+void QTReaderApp::setfontHelper(const QString& lcn, int size = 0)
{
+ if (size == 0) size = reader->m_fontControl.currentsize();
QFont f(lcn, 10 /*, QFont::Bold*/);
bkmkselector->setFont( f );
regEdit->setFont( f );
searchEdit->setFont( f );
+ m_annoWin->setFont( f );
reader->m_fontname = lcn;
- reader->ChangeFont(reader->fontsizes[reader->m_textsize]);
+ if (!reader->ChangeFont(size))
+ {
+ reader->ChangeFont(size);
+ }
reader->refresh();
m_fontBar->hide();
m_fontVisible = false;
showEditTools();
}
+void QTReaderApp::do_setfont(const QString& lcn)
+{
+ setfontHelper(lcn);
+}
+
void QTReaderApp::do_autogen(const QString& regText)
{
unsigned long fs, ts;
@@ -1259,9 +1759,9 @@ pbar->resize(width(), editBar->height());
if (pc != lastpc)
{
pbar->setProgress(pc);
- qApp->processEvents();
- if (reader->locate() != lcn) reader->jumpto(lcn);
- reader->setFocus();
+ qApp->processEvents();
+ if (reader->locate() != lcn) reader->jumpto(lcn);
+ reader->setFocus();
lastpc = pc;
}
i = reader->buffdoc.getpara(buff);
@@ -1270,8 +1770,9 @@ pbar->resize(width(), editBar->height());
#else
if (re.match(buff.data()) != -1)
#endif
- pBkmklist->push_back(Bkmk(buff.data(),lcn));
+ pBkmklist->push_back(Bkmk(buff.data(), NULL, lcn));
}
+ pBkmklist->sort();
pbar->setProgress(100);
qApp->processEvents();
pbar->hide();
@@ -1286,14 +1787,15 @@ void QTReaderApp::saveprefs()
reader->m_lastposn = reader->pagelocate();
config.writeEntry( "StripCr", reader->bstripcr );
+ config.writeEntry( "AutoFmt", reader->bautofmt );
+ config.writeEntry( "TextFmt", reader->btextfmt );
config.writeEntry( "StripHtml", reader->bstriphtml );
config.writeEntry( "Dehyphen", reader->bdehyphen );
config.writeEntry( "Unindent", reader->bunindent );
config.writeEntry( "Repara", reader->brepara );
config.writeEntry( "DoubleSpace", reader->bdblspce );
config.writeEntry( "Indent", reader->bindenter );
- config.writeEntry( "FontSize", (int)(reader->fontsizes[reader->m_textsize]) );
- config.writeEntry( "Bold", reader->m_bBold );
+ config.writeEntry( "FontSize", (int)(reader->m_fontControl.currentsize()) );
config.writeEntry( "ScrollDelay", reader->m_delay);
config.writeEntry( "LastFile", reader->m_lastfile );
config.writeEntry( "LastPosn", (int)(reader->pagelocate()) );
@@ -1303,8 +1805,16 @@ void QTReaderApp::saveprefs()
config.writeEntry( "Encoding", reader->m_encd );
config.writeEntry( "CharSpacing", reader->m_charpc );
config.writeEntry( "Overlap", (int)(reader->m_overlap) );
- config.writeEntry( "TargetApp", reader->m_targetapp );
- config.writeEntry( "TargetMsg", reader->m_targetmsg );
+ config.writeEntry( "TargetApp", m_targetapp );
+ config.writeEntry( "TargetMsg", m_targetmsg );
+ config.writeEntry( "TwoTouch", m_twoTouch );
+ config.writeEntry( "Annotation", m_doAnnotation);
+ config.writeEntry( "Dictionary", m_doDictionary);
+ config.writeEntry( "Clipboard", m_doClipboard);
+ config.writeEntry( "SpaceTarget", m_spaceTarget);
+ config.writeEntry( "Remap", reader->bremap );
+ config.writeEntry( "Peanut", reader->bpeanut );
+ config.writeEntry( "MakeBold", reader->bmakebold );
}
void QTReaderApp::indentplus()
@@ -1334,40 +1844,40 @@ void info_cb(Fl_Widget* o, void* _data)
if (infowin == NULL)
{
-
- infowin = new Fl_Window(160,240);
- filename = new Fl_Output(45,5,110,14,"Filename");
- filesize = new Fl_Output(45,25,110,14,"Filesize");
- textsize = new Fl_Output(45,45,110,14,"Textsize");
- comprat = new CBar(45,65,110,14,"Ratio %");
- posn = new Fl_Output(45,85,110,14,"Location");
- frcn = new CBar(45,105,110,14,"% Read");
- about = new Fl_Multiline_Output(5,125,150,90);
- about->value("TWReader - $Name$\n\nA file reader program for the Agenda\n\nReads text, PalmDoc and ppms format files");
- Fl_Button *jump_accept = new Fl_Button(62,220,35,14,"Okay");
- infowin->set_modal();
+
+ infowin = new Fl_Window(160,240);
+ filename = new Fl_Output(45,5,110,14,"Filename");
+ filesize = new Fl_Output(45,25,110,14,"Filesize");
+ textsize = new Fl_Output(45,45,110,14,"Textsize");
+ comprat = new CBar(45,65,110,14,"Ratio %");
+ posn = new Fl_Output(45,85,110,14,"Location");
+ frcn = new CBar(45,105,110,14,"% Read");
+ about = new Fl_Multiline_Output(5,125,150,90);
+ about->value("TWReader - $Name$\n\nA file reader program for the Agenda\n\nReads text, PalmDoc and ppms format files");
+ Fl_Button *jump_accept = new Fl_Button(62,220,35,14,"Okay");
+ infowin->set_modal();
}
if (((reader_ui *)_data)->g_filename[0] != '\0')
{
- unsigned long fs,ts;
- tchar sz[20];
- ((reader_ui *)_data)->input->sizes(fs,ts);
- unsigned long pl = ((reader_ui *)_data)->input->locate();
+ unsigned long fs,ts;
+ tchar sz[20];
+ ((reader_ui *)_data)->input->sizes(fs,ts);
+ unsigned long pl = ((reader_ui *)_data)->input->locate();
- filename->value(((reader_ui *)_data)->g_filename);
+ filename->value(((reader_ui *)_data)->g_filename);
- sprintf(sz,"%u",fs);
- filesize->value(sz);
+ sprintf(sz,"%u",fs);
+ filesize->value(sz);
- sprintf(sz,"%u",ts);
- textsize->value(sz);
+ sprintf(sz,"%u",ts);
+ textsize->value(sz);
- comprat->value(100-(100*fs + (ts >> 1))/ts);
+ comprat->value(100-(100*fs + (ts >> 1))/ts);
- sprintf(sz,"%u",pl);
- posn->value(sz);
+ sprintf(sz,"%u",pl);
+ posn->value(sz);
- frcn->value((100*pl + (ts >> 1))/ts);
+ frcn->value((100*pl + (ts >> 1))/ts);
}
infowin->show();
}
@@ -1377,27 +1887,27 @@ void QTReaderApp::savebkmks()
{
if (pBkmklist != NULL)
{
- BkmkFile bf((const char *)Global::applicationFileName("uqtreader",reader->m_string), true);
- bf.write(*pBkmklist);
+ BkmkFile bf((const char *)Global::applicationFileName("uqtreader",reader->m_string), true);
+ bf.write(*pBkmklist);
}
- m_fBkmksChanged = false;
+ m_fBkmksChanged = false;
}
void QTReaderApp::readbkmks()
{
if (pBkmklist != NULL)
{
- delete pBkmklist;
+ delete pBkmklist;
}
BkmkFile bf((const char *)Global::applicationFileName("uqtreader",reader->m_string));
pBkmklist = bf.readall();
- m_fBkmksChanged = false;
+ m_fBkmksChanged = bf.upgraded();
if (pBkmklist == NULL)
{
- pBkmklist = reader->getbkmklist();
+ pBkmklist = reader->getbkmklist();
}
if (pBkmklist != NULL)
- pBkmklist->sort();
+ pBkmklist->sort();
}
void QTReaderApp::addbkmk()
@@ -1409,25 +1919,111 @@ void QTReaderApp::addbkmk()
void QTReaderApp::do_addbkmk(const QString& text)
{
- if (text.isEmpty())
- {
- QMessageBox::information(this, "QTReader", "Need a name for the bookmark\nSelect add again", 1);
- }
- else
- {
- if (pBkmklist == NULL) pBkmklist = new CList<Bkmk>;
+ if (text.isEmpty())
+ {
+ QMessageBox::information(this, "QTReader", "Need a name for the bookmark\nSelect add again", 1);
+ }
+ else
+ {
+ if (pBkmklist == NULL) pBkmklist = new CList<Bkmk>;
#ifdef _UNICODE
- CBuffer buff;
- int i = 0;
- for (i = 0; i < text.length(); i++)
- {
- buff[i] = text[i].unicode();
- }
- buff[i] = 0;
- pBkmklist->push_front(Bkmk(buff.data(), reader->pagelocate()));
+ CBuffer buff;
+ int i = 0;
+ for (i = 0; i < text.length(); i++)
+ {
+ buff[i] = text[i].unicode();
+ }
+ buff[i] = 0;
+ pBkmklist->push_front(Bkmk(buff.data(), NULL, reader->pagelocate()));
#else
- pBkmklist->push_front(Bkmk((const tchar*)text,reader->pagelocate()));
+ pBkmklist->push_front(Bkmk((const tchar*)text,reader->pagelocate()));
#endif
- m_fBkmksChanged = true;
- }
+ m_fBkmksChanged = true;
+ pBkmklist->sort();
+ }
+}
+
+void QTReaderApp::OnRedraw()
+{
+ if (pBkmklist != NULL)
+ {
+ bool found = findNextBookmark(reader->pagelocate());
+ m_bkmkAvail->setEnabled(found);
+ }
+}
+
+void QTReaderApp::showAnnotation()
+{
+ m_annoWin->setName(toQString(m_anno->name()));
+ m_annoWin->setAnno(toQString(m_anno->anno()));
+ m_annoIsEditing = false;
+ editorStack->raiseWidget( m_annoWin );
+ m_annoWin->setFocus();
+}
+
+void QTReaderApp::OnWordSelected(const QString& wrd, size_t posn, const QString& line)
+{
+// qDebug("OnWordSelected(%u):%s", posn, (const char*)wrd);
+
+ if (m_doClipboard)
+ {
+ QClipboard* cb = QApplication::clipboard();
+ cb->setText(wrd);
+ if (wrd.length() > 10)
+ {
+ Global::statusMessage(wrd.left(8) + "..");
+ }
+ else
+ {
+ Global::statusMessage(wrd);
+ }
+ }
+ if (m_doAnnotation)
+ {
+// addAnno(wrd, "Need to be able to edit this", posn);
+ m_annoWin->setName(line);
+ m_annoWin->setAnno("");
+ m_annoWin->setPosn(posn);
+ m_annoIsEditing = true;
+ editorStack->raiseWidget( m_annoWin );
+ }
+ if (m_doDictionary)
+ {
+ if (!m_targetapp.isEmpty() && !m_targetmsg.isEmpty())
+ {
+ QCopEnvelope e(("QPE/Application/"+m_targetapp).utf8(), (m_targetmsg+"(QString)").utf8());
+ e << wrd;
+ }
+ }
}
+
+void QTReaderApp::OnActionPressed()
+{
+ switch (m_spaceTarget)
+ {
+ case cesOpenFile:
+ {
+ fileOpen();
+ }
+ break;
+ case cesAutoScroll:
+ {
+ reader->setautoscroll(!reader->m_autoScroll);
+ setScrollState(reader->m_autoScroll);
+ }
+ break;
+ case cesActionMark:
+ {
+ addbkmk();
+ }
+ break;
+ default:
+ {
+ qDebug("Unknown ActionType:%u", m_spaceTarget);
+ }
+ break;
+ }
+}
+
+void QTReaderApp::setTwoTouch(bool _b) { reader->setTwoTouch(_b); }
+void QTReaderApp::restoreFocus() { reader->setFocus(); }
diff --git a/noncore/apps/opie-reader/QTReaderApp.h b/noncore/apps/opie-reader/QTReaderApp.h
index 48575e9..22c57e4 100644
--- a/noncore/apps/opie-reader/QTReaderApp.h
+++ b/noncore/apps/opie-reader/QTReaderApp.h
@@ -23,24 +23,37 @@
//#define __ISEARCH
#define MAX_ENCODING 6
+#define MAX_ACTIONS 3
#include <qmainwindow.h>
-#include "QTReader.h"
+#include "CExpander.h"
#include <qlist.h>
#include <qpe/filemanager.h>
#include <qmap.h>
#include <qlineedit.h>
#include <qstack.h>
#include <qlistbox.h>
-#include "Queue.h"
+//#include "Queue.h"
class QWidgetStack;
class QToolButton;
class QPopupMenu;
class QToolBar;
+class QPEToolBar;
class CBkmkSelector;
class QProgressBar;
class QAction;
+class CAnnoEdit;
+class QFloatBar;
+class CDrawBuffer;
+class QTReader;
+
+enum ActionTypes
+{
+ cesOpenFile = 0,
+ cesAutoScroll,
+ cesActionMark
+};
#ifdef __ISEARCH
struct searchrecord
@@ -58,6 +71,7 @@ class QTReaderApp : public QMainWindow
Q_OBJECT
unsigned long m_savedpos;
+ bool m_annoIsEditing;
public:
QTReaderApp( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
@@ -68,6 +82,10 @@ class QTReaderApp : public QMainWindow
void setScrollState(bool _b);
protected:
+ void setfontHelper(const QString& lcn, int size = 0);
+ QAction* m_bkmkAvail;
+ CAnnoEdit* m_annoWin;
+ Bkmk* m_anno;
void closeEvent( QCloseEvent *e );
void readbkmks();
void do_mono(const QString&);
@@ -75,11 +93,36 @@ class QTReaderApp : public QMainWindow
void do_overlap(const QString&);
void do_settarget(const QString&);
int EncNameToInt(const QString&);
- void saveprefs();
+ ActionTypes ActNameToInt(const QString&);
+ bool m_doAnnotation;
+ bool m_doDictionary;
+ bool m_doClipboard;
+ public:
+ void saveprefs();
private slots:
+ void setTwoTouch(bool _b);
+ void restoreFocus();
+ void OnAnnotation(bool _b)
+ {
+ m_doAnnotation = _b;
+ }
+ void OnDictionary(bool _b)
+ {
+ m_doDictionary = _b;
+ }
+ void OnClipboard(bool _b)
+ {
+ m_doClipboard = _b;
+ }
+ void OnWordSelected(const QString&, size_t, const QString&);
+ void addAnno(const QString&, const QString&, size_t);
+ void addAnno(const QString&, const QString&);
+ void addanno();
+ void showAnnotation();
void do_setfont(const QString&);
void encodingSelected(QAction*);
+ void buttonActionSelected(QAction*);
void msgHandler(const QCString&, const QByteArray&);
void monospace(bool);
void jump();
@@ -127,11 +170,15 @@ private slots:
void showEditTools();
void stripcr(bool);
+ void peanut(bool _b);
+ void remap(bool);
+ void embolden(bool);
+ void autofmt(bool);
+ void textfmt(bool);
void striphtml(bool);
void dehyphen(bool);
void unindent(bool);
void repara(bool);
- void setbold(bool);
void dblspce(bool);
void pagemode(bool);
// void gotobkmk(const QString& bm);
@@ -141,8 +188,11 @@ private slots:
void do_delmark();
void do_autogen();
void do_regaction();
+ void OnRedraw();
+ void OnActionPressed();
private:
+ QString m_targetapp, m_targetmsg;
void listbkmk();
void do_regedit();
void colorChanged( const QColor &c );
@@ -150,6 +200,7 @@ private slots:
void updateCaption();
void do_autogen(const QString&);
void do_addbkmk(const QString&);
+ bool findNextBookmark(size_t start);
private:
@@ -157,24 +208,29 @@ private slots:
QAction* m_EncodingAction[MAX_ENCODING];
+ QAction* m_buttonAction[MAX_ACTIONS];
+
CBkmkSelector* bkmkselector;
+ ActionTypes m_spaceTarget;
size_t searchStart;
#ifdef __ISEARCH
QStack<searchrecord>* searchStack;
- bool dosearch(size_t start, CBuffer& test, const QString& arg);
+ bool dosearch(size_t start, CDrawBuffer& test, const QString& arg);
#else
- bool dosearch(size_t start, CBuffer& test, const QRegExp& arg);
+ bool dosearch(size_t start, CDrawBuffer& test, const QRegExp& arg);
#endif
QWidgetStack *editorStack;
QTReader* reader;
QComboBox* m_fontSelector;
- QToolBar *menu, *editBar, *searchBar, *regBar, *m_fontBar;
+ QPEToolBar /* *menu,*/ *editBar;
+ QFloatBar *searchBar, *regBar/*, *m_fontBar*/;
+ QToolBar /* *searchBar, *regBar,*/ *m_fontBar;
QLineEdit *searchEdit, *regEdit;
DocLnk *doc;
bool searchVisible;
bool regVisible;
- bool m_fontVisible;
+ bool m_fontVisible, m_twoTouch;
bool bFromDocView;
static unsigned long m_uid;
long unsigned get_unique_id() { return m_uid++; }
@@ -192,6 +248,7 @@ private slots:
bool m_fBkmksChanged;
int m_nRegAction;
QString m_autogenstr;
+ bool m_dontSave;
};
const int cAutoGen = 0;
diff --git a/noncore/apps/opie-reader/StyleConsts.h b/noncore/apps/opie-reader/StyleConsts.h
new file mode 100644
index 0000000..b6dd861
--- a/dev/null
+++ b/noncore/apps/opie-reader/StyleConsts.h
@@ -0,0 +1,113 @@
+#ifndef __STYLECONSTS_H
+#define __STYLECONSTS_H
+
+typedef unsigned short StyleType;
+
+class CStyle
+{
+// 15 14 13-5 4 3 2 1 0
+//bold italic spare align align fs fs fs
+ static const StyleType m_Bold = 1 << 15;
+ static const StyleType m_Italic = 1 << 14;
+ static const StyleType m_FontMask = 7;
+ static const StyleType m_FontBase = 3;
+
+ static const StyleType m_AlignShift = 3;
+ static const StyleType m_AlignMask = 3 << m_AlignShift;
+ static const StyleType m_EveryBit = 0xffff;
+
+
+ StyleType sty;
+
+ void unjustify() { sty &= m_EveryBit ^ m_AlignMask; }
+ unsigned char red, green, blue;
+ unsigned long data;
+ bool isLink;
+ public:
+ unsigned char Red() { return red; }
+ unsigned char Green() { return green; }
+ unsigned char Blue() { return blue; }
+ void setColour(unsigned char r, unsigned char g, unsigned char b)
+ {
+ red = r;
+ green = g;
+ blue = b;
+ }
+ static const StyleType m_AlignLeft = 0;
+ static const StyleType m_AlignRight = 1 << m_AlignShift;
+ static const StyleType m_AlignCentre = 2 << m_AlignShift;
+ static const StyleType m_AlignJustify = 3 << m_AlignShift;
+ CStyle()
+ :
+ sty(m_FontBase),
+ red(0), green(0), blue(0),
+ data(0), isLink(false)
+ {}
+// CStyle(const int _fs) : sty(m_FontBase+_fs) {}
+
+ void unset()
+ {
+ sty = m_FontBase;
+ red = green = blue = 0;
+ data = 0;
+ isLink = false;
+ }
+
+ void setBold() { sty |= m_Bold; }
+ void setItalic() { sty |= m_Italic; }
+ void unsetBold() { sty &= m_EveryBit ^ m_Bold; }
+ void unsetItalic() { sty &= m_EveryBit ^ m_Italic; }
+ bool isBold() { return ((sty & m_Bold) != 0); }
+ bool isItalic() { return ((sty & m_Italic) != 0); }
+
+ void setLeftJustify()
+ {
+ unjustify();
+ sty |= m_AlignLeft;
+ }
+ void setRightJustify()
+ {
+ unjustify();
+ sty |= m_AlignRight;
+ }
+ void setCentreJustify()
+ {
+ unjustify();
+ sty |= m_AlignCentre;
+ }
+ void setFullJustify()
+ {
+ unjustify();
+ sty |= m_AlignJustify;
+ }
+ StyleType getJustify()
+ {
+ return sty & m_AlignMask;
+ }
+
+ void setFontSize(int _fs)
+ {
+ sty &= m_EveryBit ^ m_FontMask;
+ sty |= m_FontBase + _fs;
+ }
+ int getFontSize()
+ {
+ return (sty & m_FontMask) - m_FontBase;
+ }
+ bool operator!=(const CStyle& rhs)
+ {
+ return
+ (
+ (sty != rhs.sty) || (red != rhs.red) || (green != rhs.green) ||
+ (blue != rhs.blue) ||
+ (data != rhs.data) ||
+ (isLink != rhs.isLink)
+ );
+ }
+ void setLink(bool _l) { isLink = _l; }
+ bool getLink() { return isLink; }
+ void setData(unsigned long _d) { data = _d; }
+ unsigned long getData() { return data; }
+};
+
+#endif
diff --git a/noncore/apps/opie-reader/ZText.h b/noncore/apps/opie-reader/ZText.h
index 4b1b96e..9e72161 100644
--- a/noncore/apps/opie-reader/ZText.h
+++ b/noncore/apps/opie-reader/ZText.h
@@ -1,8 +1,7 @@
#ifndef __Text_h
#define __Text_h
#include <stdio.h>
-#include "zlib/zlib.h"
-//#include <zlib.h>
+#include <zlib.h>
#include <sys/stat.h>
#include "CExpander.h"
@@ -32,5 +31,9 @@ public:
{
_text = _file = fsize;
}
+ virtual MarkupType PreferredMarkup()
+ {
+ return cTEXT;
+ }
};
#endif
diff --git a/noncore/apps/opie-reader/fileBrowser.cpp b/noncore/apps/opie-reader/fileBrowser.cpp
index def988f..b21d59d 100644
--- a/noncore/apps/opie-reader/fileBrowser.cpp
+++ b/noncore/apps/opie-reader/fileBrowser.cpp
@@ -17,7 +17,7 @@ Extensive modification by Tim Wentford to allow it to work in rotated mode
#include <qlayout.h>
fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags fl , const QString filter, const QString iPath )
- : QDialog( parent, name, modal, fl )
+ : QDialog( parent, name, modal, fl ), filterspec(QDir::All)
{
// showMaximized();
if ( !name )
@@ -28,8 +28,16 @@ fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags
buttonOk = new QPushButton( this, "buttonOk" );
buttonOk->setFixedSize( 25, 25 );
+ buttonOk->setAutoDefault( false );
buttonOk->setText( tr( "/" ) );
+ buttonShowHidden = new QPushButton( this, "buttonShowHidden" );
+// buttonShowHidden->setFixedSize( 50, 25 );
+ buttonShowHidden->setText( tr( "Hidden" ) );
+ buttonShowHidden->setAutoDefault( false );
+ buttonShowHidden->setToggleButton( true );
+ buttonShowHidden->setOn( false );
+
dirLabel = new QLabel(this, "DirLabel");
dirLabel->setText(currentDir.canonicalPath());
@@ -38,10 +46,10 @@ fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags
ListView->setSorting( 2, FALSE);
ListView->addColumn( tr( "Size" ) );
ListView->setSelectionMode(QListView::Single);
-
ListView->setAllColumnsShowFocus( TRUE );
// signals and slots connections
+ connect( buttonShowHidden, SIGNAL( toggled(bool) ), this, SLOT( setHidden(bool) ) );
connect( buttonOk, SIGNAL( clicked() ), this, SLOT( OnRoot() ) );
connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) );
connect( ListView, SIGNAL(clicked( QListViewItem*)), SLOT(listClicked(QListViewItem *)) );
@@ -52,6 +60,7 @@ fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags
QVBoxLayout* grid = new QVBoxLayout(this);
QHBoxLayout* hgrid = new QHBoxLayout(grid);
hgrid->addWidget(dirLabel,1);
+ hgrid->addWidget(buttonShowHidden);
hgrid->addWidget(buttonOk);
grid->addWidget(ListView,1);
@@ -85,14 +94,14 @@ void fileBrowser::populateList()
ListView->clear();
//qDebug(currentDir.canonicalPath());
// currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::NoSymLinks );
- currentDir.setFilter( QDir::All );
+ currentDir.setFilter( filterspec );
currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst);
currentDir.setMatchAllDirs(TRUE);
currentDir.setNameFilter(filterStr);
// currentDir.setNameFilter("*.txt;*.etx");
QString fileL, fileS;
- const QFileInfoList *list = currentDir.entryInfoList(QDir::All);
+ const QFileInfoList *list = currentDir.entryInfoList();
QFileInfoListIterator it(*list);
QFileInfo *fi;
while ( (fi=it.current()) )
@@ -115,6 +124,7 @@ void fileBrowser::populateList()
}
ListView->setSorting( 2, FALSE);
dirLabel->setText("Current Directory:\n"+currentDir.canonicalPath());
+ ListView->setFocus();
}
void fileBrowser::upDir()
@@ -183,3 +193,12 @@ void fileBrowser::OnCancel()
{
reject();
}
+
+void fileBrowser::setHidden(bool _hidden)
+{
+ if (_hidden)
+ filterspec = QDir::All | QDir::Hidden;
+ else
+ filterspec = QDir::All;
+ populateList();
+}
diff --git a/noncore/apps/opie-reader/fileBrowser.h b/noncore/apps/opie-reader/fileBrowser.h
index d222791..5521383 100644
--- a/noncore/apps/opie-reader/fileBrowser.h
+++ b/noncore/apps/opie-reader/fileBrowser.h
@@ -40,6 +40,7 @@ public:
~fileBrowser();
QPushButton* buttonOk;
+ QPushButton* buttonShowHidden;
QtrListView* ListView;
QPushButton* buttonCancel;
QLabel *dirLabel;
@@ -47,6 +48,8 @@ public:
QDir currentDir;
QFile file;
QStringList fileList;
+ int filterspec;
+// QDir::FilterSpec filterspec;
//QListViewItem * item;
public slots:
@@ -59,6 +62,7 @@ private slots:
void listClicked(QListViewItem *);
void OnRoot();
void OnCancel();
+ void setHidden(bool);
protected slots:
diff --git a/noncore/apps/opie-reader/infowin.cpp b/noncore/apps/opie-reader/infowin.cpp
index f9a6f5f..9637a62 100644
--- a/noncore/apps/opie-reader/infowin.cpp
+++ b/noncore/apps/opie-reader/infowin.cpp
@@ -1,7 +1,6 @@
#include "infowin.h"
#include "version.h"
-
-#define VERSION_STRING "QT Reader v" ## MAJOR ## "." ## MINOR ## " (" ## RELEASE_TYPE ## ")\nA small e-text reader"
+#include <stdio.h>
infowin::infowin( QWidget *parent=0, const char *name=0, WFlags f = 0) :
QWidget(parent, name, f)
@@ -33,7 +32,9 @@ infowin::infowin( QWidget *parent=0, const char *name=0, WFlags f = 0) :
read = new QLabel("0", this);
read->setAlignment( AlignVCenter | AlignRight );
grid->addWidget(read, 4, 1);
- l = new QLabel(VERSION_STRING, this);
+ char vstr[128];
+ sprintf(vstr, "QT Reader v%u.%u%c (%s)\nA small e-text reader", MAJOR, BKMKTYPE, MINOR, RELEASE_TYPE);
+ l = new QLabel(vstr, this);
grid->addWidget(l, 5, 0);
QPushButton* exitbutton = new QPushButton("Cancel", this);
connect( exitbutton, SIGNAL( released() ), this, SLOT( infoClose() ) );
diff --git a/noncore/apps/opie-reader/main.cpp b/noncore/apps/opie-reader/main.cpp
index e37f12c..08f59a8 100644
--- a/noncore/apps/opie-reader/main.cpp
+++ b/noncore/apps/opie-reader/main.cpp
@@ -1,38 +1,30 @@
#include <qpe/qpeapplication.h>
-//#include <qmainwindow.h>
#include "QTReaderApp.h"
+#include "signal.h"
+#include "stdio.h"
+#include "time.h"
+QTReaderApp* app = NULL;
-
-
-/*
-class myapp : public QPEApplication
+void handler(int signum)
{
- public slots:
- void receive( const QCString& msg, const QByteArray& data )
- {
-
- QDataStream stream( data, IO_ReadOnly );
- if ( msg == "someMessage(int,int,int)" ) {
- int a,b,c;
- stream >> a >> b >> c;
- ...
- } else if ( msg == "otherMessage(QString)" ) {
- ...
- }
-
- }
+ if (app != NULL) app->saveprefs();
+ signal(signum, handler);
}
-*/
int main( int argc, char ** argv )
{
+ signal(SIGCONT, handler);
+
QPEApplication a( argc, argv );
QTReaderApp m;
+
a.showMainDocumentWidget( &m );
+ app = &m;
+
return a.exec();
}
diff --git a/noncore/apps/opie-reader/my_list.h b/noncore/apps/opie-reader/my_list.h
index b3f0cc0..f180d3d 100644
--- a/noncore/apps/opie-reader/my_list.h
+++ b/noncore/apps/opie-reader/my_list.h
@@ -28,6 +28,8 @@ class CList
}
}
}
+ T& first() { return front->data; }
+ T& last() { return back->data; }
T* operator[](int n)
{
node* current = front;
@@ -61,6 +63,7 @@ class CList
back = n;
}
}
+ bool isEmpty() { return (front == NULL); }
void erase(unsigned int n)
{
node* p = front;
@@ -155,10 +158,18 @@ class CList
{
return &(current->data);
}
+ T* pContent()
+ {
+ return &(current->data);
+ }
bool operator!=(iterator t)
{
return (current != t.current);
}
+ bool operator==(iterator t)
+ {
+ return (current == t.current);
+ }
};
iterator begin()
{
diff --git a/noncore/apps/opie-reader/opie-reader.pro b/noncore/apps/opie-reader/opie-reader.pro
index 5d074c3..51849a3 100644
--- a/noncore/apps/opie-reader/opie-reader.pro
+++ b/noncore/apps/opie-reader/opie-reader.pro
@@ -1,48 +1,58 @@
-TEMPLATE = app
-CONFIG = qt warn_on release
-HEADERS = Aportis.h \
- BuffDoc.h \
- CBuffer.h \
- CExpander.h \
- CFilter.h \
- QTReader.h \
- QTReaderApp.h \
- Text.h \
- ZText.h \
- arith.h \
- my_list.h \
- ppm.h \
- ppm_expander.h \
- cbkmkselector.h \
- fileBrowser.h \
- ztxt.h \
- QtrListView.h \
- infowin.h \
- version.h \
- pdb.h \
- utypes.h \
- ustring.h \
- CEncoding.h \
- config.h
-SOURCES = Aportis.cpp \
- BuffDoc.cpp \
- CBuffer.cpp \
- QTReader.cpp \
- QTReaderApp.cpp \
- arith_d.cpp \
- main.cpp \
- ppm.cpp \
- ppm_expander.cpp \
- ztxt.cpp \
- QtrListView.cpp \
- infowin.cpp \
- pdb.cpp \
- CEncoding.cpp \
- fileBrowser.cpp
-INTERFACES =
-DESTDIR = $(OPIEDIR)/bin
-INCLUDEPATH += $(OPIEDIR)/include
-DEPENDPATH += $(OPIEDIR)/include
-TARGET = reader
-LIBS += -lqpe
+TEMPLATE = app
+CONFIG = qt warn_on release
+HEADERS = Aportis.h \
+ BuffDoc.h \
+ CBuffer.h \
+ CDrawBuffer.h \
+ CExpander.h \
+ CFilter.h \
+ QTReader.h \
+ QTReaderApp.h \
+ ZText.h \
+ arith.h \
+ my_list.h \
+ ppm.h \
+ ppm_expander.h \
+ cbkmkselector.h \
+ fileBrowser.h \
+ ztxt.h \
+ QtrListView.h \
+ infowin.h \
+ version.h \
+ pdb.h \
+ utypes.h \
+ ustring.h \
+ CEncoding.h \
+ CAnnoEdit.h \
+ QFloatBar.h \
+ StyleConsts.h \
+ FontControl.h \
+ plucker.h \
+ Markups.h \
+ Bkmks.h \
+ config.h
+SOURCES = Aportis.cpp \
+ BuffDoc.cpp \
+ CBuffer.cpp \
+ CDrawBuffer.cpp \
+ QTReader.cpp \
+ QTReaderApp.cpp \
+ arith_d.cpp \
+ main.cpp \
+ ppm.cpp \
+ ppm_expander.cpp \
+ ztxt.cpp \
+ QtrListView.cpp \
+ infowin.cpp \
+ pdb.cpp \
+ CEncoding.cpp \
+ CFilter.cpp \
+ plucker.cpp \
+ Bkmks.cpp \
+ fileBrowser.cpp
+DESTDIR = $(OPIEDIR)/bin
+INCLUDEPATH += $(OPIEDIR)/include
+DEPENDPATH += $(OPIEDIR)/include
+TARGET = reader
+LIBS += -lqpe
diff --git a/noncore/apps/opie-reader/pdb.h b/noncore/apps/opie-reader/pdb.h
index 143c5cb..41649bd 100644
--- a/noncore/apps/opie-reader/pdb.h
+++ b/noncore/apps/opie-reader/pdb.h
@@ -17,6 +17,7 @@
/* Normal Palm typedefs */
typedef unsigned char UInt8;
typedef unsigned short UInt16;
+typedef signed short Int16;
typedef unsigned long UInt32;
typedef UInt32 LocalID;
diff --git a/noncore/apps/opie-reader/plucker.h b/noncore/apps/opie-reader/plucker.h
new file mode 100644
index 0000000..84e855c
--- a/dev/null
+++ b/noncore/apps/opie-reader/plucker.h
@@ -0,0 +1,86 @@
+#ifndef __plucker_h
+#define __plucker_h
+
+#include "CExpander.h"
+#include <zlib.h>
+#include "ztxt.h"
+#include "pdb.h"
+#include "CBuffer.h"
+
+struct CPlucker_dataRecord
+{
+ UInt16 uid;
+ UInt16 nParagraphs;
+ UInt16 size;
+ UInt8 type;
+ UInt8 reserved;
+};
+
+struct CPlucker_record0
+{
+ UInt16 uid;
+ UInt16 version;
+ UInt16 nRecords;
+};
+
+struct CPluckerbkmk
+{
+ UInt32 offset;
+ tchar title[MAX_BMRK_LENGTH];
+};
+
+
+const UInt32 CPLUCKER_ID = 0x5458547a;
+
+class CPlucker : public CExpander, Cpdb
+{
+ size_t textlength;
+ UInt16 uid;
+ int m_nextPara, m_nextParaIndex;
+ CBufferFace<UInt16> m_ParaOffsets;
+ CBufferFace<UInt16> m_ParaAttrs;
+ UInt16 m_nParas;
+ CStyle mystyle;
+// bool bInit;
+ UInt32 buffersize;
+ UInt32 buffercontent;
+ UInt8* expandedtextbuffer;
+ UInt8* compressedtextbuffer;
+ size_t bufferpos;
+ UInt16 bufferrec;
+ CPlucker_record0 hdr0;
+ size_t currentpos;
+ bool expand(int);
+ void UnZip(size_t, UInt8*, UInt16);
+ void UnDoc(size_t, UInt8*, UInt16);
+ void expandimg(UInt16 tgt);
+ void home();
+ int bgetch();
+ public:
+ virtual void sizes(unsigned long& _file, unsigned long& _text)
+ {
+ _file = file_length;
+ _text = textlength;
+//ntohl(hdr0.size);
+ }
+ virtual bool hasrandomaccess() { return true; }
+ virtual ~CPlucker()
+ {
+ if (expandedtextbuffer != NULL) delete [] expandedtextbuffer;
+ if (compressedtextbuffer != NULL) delete [] compressedtextbuffer;
+ }
+ CPlucker();
+ virtual int openfile(const char *src);
+ virtual int getch();
+ virtual void getch(int&, CStyle&);
+ virtual unsigned int locate();
+ virtual void locate(unsigned int n);
+ virtual CList<Bkmk>* getbkmklist();
+ virtual bool hyperlink(unsigned int n);
+ virtual MarkupType PreferredMarkup()
+ {
+ return cNONE;
+ }
+};
+
+#endif
diff --git a/noncore/apps/opie-reader/ppm_expander.h b/noncore/apps/opie-reader/ppm_expander.h
index ce95db7..115988d 100644
--- a/noncore/apps/opie-reader/ppm_expander.h
+++ b/noncore/apps/opie-reader/ppm_expander.h
@@ -41,6 +41,10 @@ class ppm_expander : public CExpander {
virtual void locate(unsigned int n);
virtual bool hasrandomaccess() { return (numblocks > 1); }
virtual void sizes(unsigned long& file, unsigned long& text);
+ virtual MarkupType PreferredMarkup()
+ {
+ return cTEXT;
+ }
};
#endif
diff --git a/noncore/apps/opie-reader/version.h b/noncore/apps/opie-reader/version.h
index bd32e4d..8b6c756 100644
--- a/noncore/apps/opie-reader/version.h
+++ b/noncore/apps/opie-reader/version.h
@@ -1,3 +1,5 @@
-#define MAJOR "0"
-#define MINOR "3r"
-#define RELEASE_TYPE "beta(U)"
+
+#define MAJOR 0
+#define BKMKTYPE 5
+#define MINOR 'a'
+#define RELEASE_TYPE "beta"
diff --git a/noncore/apps/opie-reader/ztxt.cpp b/noncore/apps/opie-reader/ztxt.cpp
index c30e4fd..289b13a 100644
--- a/noncore/apps/opie-reader/ztxt.cpp
+++ b/noncore/apps/opie-reader/ztxt.cpp
@@ -1,6 +1,8 @@
#include <stdio.h>
#include <string.h>
#include "ztxt.h"
+#include "my_list.h"
+#include "Bkmks.h"
ztxt::ztxt() : bInit(false), expandedtextbuffer(NULL), compressedtextbuffer(NULL) { /*printf("constructing:%x\n",fin);*/ }
@@ -152,7 +154,7 @@ CList<Bkmk>* ztxt::getbkmklist()
zTXTbkmk bkmk;
if (fread(&bkmk, sizeof(bkmk), 1, fin) != 1) break;
// printf("Bookmark number:%d:%.20s\n", i, bkmk.title);
- t->push_back(Bkmk(bkmk.title, ntohl(bkmk.offset)));
+ t->push_back(Bkmk(bkmk.title, NULL, ntohl(bkmk.offset)));
}
fseek(fin, cur, SEEK_SET);
return t;
diff --git a/noncore/apps/opie-reader/ztxt.h b/noncore/apps/opie-reader/ztxt.h
index 6352cfc..7be45c0 100644
--- a/noncore/apps/opie-reader/ztxt.h
+++ b/noncore/apps/opie-reader/ztxt.h
@@ -2,8 +2,7 @@
#define __ztxt_h
#include "CExpander.h"
-#include "zlib/zlib.h"
-//#include <zlib.h>
+#include <zlib.h>
#include "pdb.h"
/*
* Stuff common to both Weasel Reader and makeztxt
@@ -77,27 +76,30 @@ class ztxt : public CExpander, Cpdb
void home();
public:
virtual void sizes(unsigned long& _file, unsigned long& _text)
- {
- _file = file_length;
- _text = ntohl(hdr0.size);
- }
+ {
+ _file = file_length;
+ _text = ntohl(hdr0.size);
+ }
virtual bool hasrandomaccess() { return (hdr0.randomAccess != 0); }
virtual ~ztxt()
- {
- if (expandedtextbuffer != NULL) delete [] expandedtextbuffer;
- if (compressedtextbuffer != NULL) delete [] compressedtextbuffer;
- if (bInit)
- {
- inflateEnd(&zstream);
- }
- }
+ {
+ if (expandedtextbuffer != NULL) delete [] expandedtextbuffer;
+ if (compressedtextbuffer != NULL) delete [] compressedtextbuffer;
+ if (bInit)
+ {
+ inflateEnd(&zstream);
+ }
+ }
ztxt();
virtual int openfile(const char *src);
virtual int getch();
virtual unsigned int locate();
virtual void locate(unsigned int n);
virtual CList<Bkmk>* getbkmklist();
+ virtual MarkupType PreferredMarkup()
+ {
+ return cTEXT;
+ }
};
#endif
-