summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-09-14 02:19:09 (UTC)
committer llornkcor <llornkcor>2002-09-14 02:19:09 (UTC)
commit2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975 (patch) (unidiff)
treeeeed16b5f80dd5883991a7a06133f5f7a6936256
parent5a95ed6a000a56849b8f093deea500214856c626 (diff)
downloadopie-2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975.zip
opie-2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975.tar.gz
opie-2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975.tar.bz2
update by Tim
Diffstat (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 @@
1#include <stdio.h> 1#include <stdio.h>
2#include <string.h> 2#include <string.h>
3#include "Aportis.h" 3#include "Aportis.h"
4#include "my_list.h"
5#include "Bkmks.h"
4 6
5Aportis::Aportis() { /*printf("constructing:%x\n",fin);*/ } 7Aportis::Aportis() : peanutfile(false) { /*printf("constructing:%x\n",fin);*/ }
8
9void Aportis::dePeanut(int& ch)
10{
11 if (peanutfile && ch != EOF)
12 {
13 unsigned char c = ch;
14 if (peanutfile) c ^= 0xa5;
15 ch = c;
16 }
17}
6 18
7CList<Bkmk>* Aportis::getbkmklist() 19CList<Bkmk>* Aportis::getbkmklist()
8{ 20{
21/*
22 if (peanutfile)
23 {
24 if (nRecs2 > nRecs)
25 {
26 CList<Bkmk>* t = new CList<Bkmk>;
27 for (int i = nRecs; i < nRecs2; i++)
28 {
29 char name[17];
30 name[16] = '\0';
31 qDebug("Record:%d, Length:%u",i,recordlength(i));
32 gotorecordnumber(i);
33 fread(name,1,16,fin);
34 unsigned long lcn;
35 fread(&lcn,sizeof(lcn),1,fin);
36 lcn ^= 0xa5a5a5a5;
37 lcn = SwapLong(lcn);
38 qDebug("Bookmark:%s:%u", name,lcn);
39 tchar tname[17];
40 memset(tname, 0, sizeof(tname));
41 for (int i = 0; name[i] != 0; i++)
42 {
43 tname[i] = name[i] ^ 0xa5;
44 }
45 t->push_back(Bkmk(tname, NULL, lcn));
46 }
47 return t;
48 }
49 else
50 {
51 return NULL;
52 }
53 }
54*/
9 if (bCompressed != 4) return NULL; 55 if (bCompressed != 4) return NULL;
10 CList<Bkmk>* t = new CList<Bkmk>; 56 CList<Bkmk>* t = new CList<Bkmk>;
11 size_t cur = ftell(fin); 57 size_t cur = ftell(fin);
@@ -34,7 +80,7 @@ CList<Bkmk>* Aportis::getbkmklist()
34 { 80 {
35 tname[i] = name[i]; 81 tname[i] = name[i];
36 } 82 }
37 t->push_back(Bkmk(tname,lcn)); 83 t->push_back(Bkmk(tname, NULL, lcn));
38#else 84#else
39 t->push_back(Bkmk(name,lcn)); 85 t->push_back(Bkmk(name,lcn));
40#endif 86#endif
@@ -46,7 +92,6 @@ CList<Bkmk>* Aportis::getbkmklist()
46 92
47int Aportis::openfile(const char *src) 93int Aportis::openfile(const char *src)
48{ 94{
49
50 // printf("In openfile\n"); 95 // printf("In openfile\n");
51 int ret = 0; 96 int ret = 0;
52 97
@@ -55,49 +100,80 @@ int Aportis::openfile(const char *src)
55 if (head.creator != 0x64414552 // 'dAER' 100 if (head.creator != 0x64414552 // 'dAER'
56 || head.type != 0x74584554) // 'tXET') 101 || head.type != 0x74584554) // 'tXET')
57 { 102 {
58 return -2; 103
104 if (memcmp(&head.creator, "PPrs", 4) == 0 && memcmp(&head.type, "PNRd", 4) == 0)
105 {
106 peanutfile = true;
107 }
108 else
109 {
110 return -2;
111 }
59 } 112 }
60 113
61 gotorecordnumber(0); 114 nRecs2 = nRecs = SwapWord(head.recordList.numRecords) - 1;
62 tDocRecord0 hdr0;
63 fread(&hdr0, sizeof(hdr0), 1, fin);
64 bCompressed = SwapWord(hdr0.wVersion);
65 if (bCompressed!=1 && bCompressed!=2 && bCompressed != 4) {
66 ret = bCompressed;
67 bCompressed = 2;
68 }
69
70 fseek(fin,0,SEEK_END); 115 fseek(fin,0,SEEK_END);
71 dwLen = ftell(fin); 116 dwLen = ftell(fin);
72 nRecs2 = nRecs = SwapWord(head.recordList.numRecords) - 1;
73 117
74 switch (bCompressed) 118 if (peanutfile)
75 { 119 {
76 case 4: 120
121 PeanutHeader hdr0;
122 gotorecordnumber(0);
123 fread(&hdr0, sizeof(hdr0), 1, fin);
124 qDebug("Version:%x", ntohs(hdr0.Version));
125 if (hdr0.Version && 0x0200)
77 { 126 {
78 dwTLen = 0; 127 bCompressed = 2;
79 int i; 128 }
80 for (i = 0; i < nRecs; i++) 129 else
130 {
131 bCompressed = 1;
132 }
133 BlockSize = 4096;
134 nRecs = SwapWord(hdr0.Records)-1;
135 dwTLen = nRecs*BlockSize;
136 }
137 else
138 {
139 gotorecordnumber(0);
140 tDocRecord0 hdr0;
141 fread(&hdr0, sizeof(hdr0), 1, fin);
142 bCompressed = SwapWord(hdr0.wVersion);
143 if (bCompressed!=1 && bCompressed!=2 && bCompressed != 4) {
144 ret = bCompressed;
145 bCompressed = 2;
146 }
147 switch (bCompressed)
148 {
149 case 4:
81 { 150 {
82 unsigned int bs = GetBS(i); 151 dwTLen = 0;
83 if (bs == 0) break; 152 int i;
84 else dwTLen += bs; 153 for (i = 0; i < nRecs; i++)
154 {
155 unsigned int bs = GetBS(i);
156 if (bs == 0) break;
157 else dwTLen += bs;
158 }
159 nRecs = i;
160 BlockSize = 0;
85 } 161 }
86 nRecs = i; 162 break;
87 BlockSize = 0; 163 case 1:
164 case 2:
165 default:
166 nRecs = SwapWord(hdr0.wNumRecs);
167 dwTLen = SwapLong(hdr0.dwStoryLen);
168 BlockSize = SwapWord(hdr0.wRecSize);
169 if (BlockSize == 0)
170 {
171 BlockSize = 4096;
172 printf("WARNING: Blocksize not set in source file\n");
173 }
88 } 174 }
89 break; 175 }
90 case 1: 176
91 case 2:
92 default:
93 dwTLen = SwapLong(hdr0.dwStoryLen);
94 BlockSize = SwapWord(hdr0.wRecSize);
95 if (BlockSize == 0)
96 {
97 BlockSize = 4096;
98 printf("WARNING: Blocksize not set in source file\n");
99 }
100 }
101 177
102 178
103 // this is the main record buffer 179 // this is the main record buffer
@@ -106,6 +182,7 @@ int Aportis::openfile(const char *src)
106 cbptr = 0; 182 cbptr = 0;
107 outptr = 0; 183 outptr = 0;
108 refreshbuffer(); 184 refreshbuffer();
185 qDebug("Number of records:[%u,%u]", nRecs, nRecs2);
109 return ret; 186 return ret;
110} 187}
111 188
@@ -117,6 +194,7 @@ int Aportis::getch()
117 else 194 else
118 { 195 {
119 int c = getc(fin); 196 int c = getc(fin);
197 dePeanut(c);
120 dwRecLen--; 198 dwRecLen--;
121 currentpos++; 199 currentpos++;
122 return c; 200 return c;
@@ -129,10 +207,11 @@ int Aportis::getch()
129 } 207 }
130 if ((dwRecLen == 0) && !refreshbuffer()) return EOF; 208 if ((dwRecLen == 0) && !refreshbuffer()) return EOF;
131 currentpos++; 209 currentpos++;
132 unsigned int c; 210 int c;
133 211
134 // take a char from the input buffer 212 // take a char from the input buffer
135 c = getc(fin); 213 c = getc(fin);
214 dePeanut(c);
136 dwRecLen--; 215 dwRecLen--;
137 // separate the char into zones: 0, 1...8, 9...0x7F, 0x80...0xBF, 0xC0...0xFF 216 // separate the char into zones: 0, 1...8, 9...0x7F, 0x80...0xBF, 0xC0...0xFF
138 217
@@ -152,7 +231,9 @@ int Aportis::getch()
152 dwRecLen -= c; 231 dwRecLen -= c;
153 while(c--) 232 while(c--)
154 { 233 {
155 circbuf[cbptr = (cbptr+1)%2048] = getc(fin); 234 int c = getc(fin);
235 dePeanut(c);
236 circbuf[cbptr = (cbptr+1)%2048] = c;
156 } 237 }
157 return circbuf[outptr = (outptr+1)%2048]; 238 return circbuf[outptr = (outptr+1)%2048];
158 } 239 }
@@ -160,7 +241,9 @@ int Aportis::getch()
160 { 241 {
161 int m,n; 242 int m,n;
162 c <<= 8; 243 c <<= 8;
163 c += getc(fin); 244 int c1 = getc(fin);
245 dePeanut(c1);
246 c += c1;
164 dwRecLen--; 247 dwRecLen--;
165 m = (c & 0x3FFF) >> COUNT_BITS; 248 m = (c & 0x3FFF) >> COUNT_BITS;
166 n = c & ((1<<COUNT_BITS) - 1); 249 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 {
40 DWORD dwSpare2; 40 DWORD dwSpare2;
41}; 41};
42 42
43struct PeanutHeader
44{
45 UInt16 Version;
46 UInt8 Junk1[6];
47 UInt16 Records;
48 UInt8 Junk2[106];
49};
50
43////////////// utilities ////////////////////////////////////// 51////////////// utilities //////////////////////////////////////
44 52
45inline WORD SwapWord(WORD r) 53inline WORD SwapWord(WORD r)
@@ -53,6 +61,8 @@ inline DWORD SwapLong(DWORD r)
53} 61}
54 62
55class Aportis : public CExpander, Cpdb { 63class Aportis : public CExpander, Cpdb {
64 bool peanutfile;
65 void dePeanut(int&);
56 DWORD dwLen; 66 DWORD dwLen;
57 WORD nRecs2; 67 WORD nRecs2;
58 DWORD dwTLen; 68 DWORD dwTLen;
@@ -78,6 +88,10 @@ public:
78 virtual unsigned int locate(); 88 virtual unsigned int locate();
79 virtual void locate(unsigned int n); 89 virtual void locate(unsigned int n);
80 virtual CList<Bkmk>* getbkmklist(); 90 virtual CList<Bkmk>* getbkmklist();
91 virtual MarkupType PreferredMarkup()
92 {
93 return (peanutfile) ? cPML : cTEXT;
94 }
81private: 95private:
82 bool refreshbuffer(); 96 bool refreshbuffer();
83 unsigned int GetBS(unsigned int bn); 97 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 @@
1#include <qmessagebox.h>
2
3#include "Bkmks.h"
4
5#include "StyleConsts.h"
6#include "Markups.h"
7#include "my_list.h"
8#include "version.h"
9
10const unsigned long BkmkFile::magic = ((unsigned long)'q' << 24) | ((unsigned long)'t' << 16) | ((unsigned long)'r' << 8) | ((unsigned long)BKMKTYPE);
11
12
13Bkmk::Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p) : m_position(_p)
14{
15 int len = ustrlen(_nm)+1;
16 m_name = new tchar[len];
17 for (int i = 0; i < len; i++) m_name[i] = _nm[i];
18
19 if (_anno == NULL)
20 {
21 m_anno = new tchar[1];
22 m_anno[0] = 0;
23 }
24 else
25 {
26 len = ustrlen(_anno)+1;
27 m_anno = new tchar[len];
28 for (int i = 0; i < len; i++) m_anno[i] = _anno[i];
29 }
30}
31
32Bkmk::~Bkmk()
33{
34 if (m_name != NULL) delete [] m_name;
35 m_name = NULL;
36 if (m_anno != NULL) delete [] m_anno;
37 m_anno = NULL;
38}
39
40Bkmk& Bkmk::operator=(const Bkmk& rhs)
41{
42 if (m_name != NULL)
43 {
44 delete [] m_name;
45 m_name = NULL;
46 }
47 if (m_anno != NULL)
48 {
49 delete [] m_anno;
50 m_anno = NULL;
51 }
52 if (rhs.m_name != NULL)
53 {
54 int len = ustrlen(rhs.m_name)+1;
55 m_name = new tchar[len];
56 for (int i = 0; i < len; i++) m_name[i] = rhs.m_name[i];
57 }
58 else
59 m_name = NULL;
60 if (rhs.m_anno != NULL)
61 {
62 int len = ustrlen(rhs.m_anno)+1;
63 m_anno = new tchar[len];
64 for (int i = 0; i < len; i++) m_anno[i] = rhs.m_anno[i];
65 }
66 else
67 m_anno = NULL;
68 m_position = rhs.m_position;
69 return *this;
70}
71
72bool Bkmk::operator==(const Bkmk& rhs)
73{
74 return (m_position == rhs.m_position && ustrcmp(m_name,rhs.m_name) == 0);
75}
76
77void Bkmk::setAnno(tchar* t)
78{
79 if (m_anno != NULL)
80 {
81 delete [] m_anno;
82 m_anno = NULL;
83 }
84 if (t != NULL)
85 {
86 int len = ustrlen(t)+1;
87 m_anno = new tchar[len];
88 for (int i = 0; i < len; i++) m_anno[i] = t[i];
89 }
90 else
91 m_anno = NULL;
92}
93
94BkmkFile::BkmkFile(const char *fnm, bool w = false)
95 :
96 wt(w), isUpgraded(false)
97{
98 if (w)
99 {
100 f = fopen(fnm, "wb");
101 }
102 else
103 {
104 f = fopen(fnm, "rb");
105 }
106}
107
108BkmkFile::~BkmkFile()
109{
110 if (f != NULL) fclose(f);
111}
112
113void BkmkFile::write(tchar* nm, tchar* an, const unsigned int& pos)
114{
115 if (f != NULL)
116 {
117 unsigned short ln = ustrlen(nm);
118 fwrite(&ln,sizeof(ln),1,f);
119 fwrite(nm,sizeof(tchar),ln,f);
120 ln = ustrlen(an);
121 fwrite(&ln,sizeof(ln),1,f);
122 if (ln > 0) fwrite(an,sizeof(tchar),ln,f);
123 fwrite(&pos,sizeof(pos),1,f);
124 }
125}
126
127void BkmkFile::write(const Bkmk& b) { write(b.name(), b.anno(), b.value()); }
128
129void BkmkFile::write(CList<Bkmk>& bl)
130{
131 if (f != NULL)
132 {
133 fwrite(&magic, sizeof(magic), 1, f);
134 for (CList<Bkmk>::iterator i = bl.begin(); i != bl.end(); i++)
135 {
136 write(*i);
137 }
138 }
139}
140
141Bkmk* BkmkFile::read()
142{
143 Bkmk* b = NULL;
144 if (f != NULL)
145 {
146 unsigned short ln;
147 if (fread(&ln,sizeof(ln),1,f) == 1)
148 {
149 b = new Bkmk;
150 b->m_name = new tchar[ln+1];
151 fread(b->m_name,sizeof(tchar),ln,f);
152 b->m_name[ln] = 0;
153
154 fread(&ln,sizeof(ln),1,f);
155 b->m_anno = new tchar[ln+1];
156 if (ln > 0) fread(b->m_anno,sizeof(tchar),ln,f);
157 b->m_anno[ln] = 0;
158 fread(&b->m_position,sizeof(b->m_position),1,f);
159 }
160 }
161 return b;
162}
163
164CList<Bkmk>* BkmkFile::readall()
165{
166 CList<Bkmk>* bl = NULL;
167 if (f != NULL)
168 {
169 unsigned long newmagic;
170 fread(&newmagic, sizeof(newmagic), 1, f);
171 if (newmagic != magic)
172 {
173 if (QMessageBox::warning(NULL, "Old bookmark file!", "Which version of QTReader\ndid you upgrade from?", "0_4*", "Any other version") == 0)
174 {
175 fseek(f,0,SEEK_SET);
176 bl = readall04();
177 }
178 else
179 {
180 fseek(f,0,SEEK_SET);
181 bl = readall03();
182 }
183 isUpgraded = true;
184 }
185 else
186 {
187 bl = readall04();
188 }
189 }
190 return bl;
191}
192
193CList<Bkmk>* BkmkFile::readall04()
194{
195 CList<Bkmk>* bl = new CList<Bkmk>;
196 while (1)
197 {
198 Bkmk* b = read();
199 if (b == NULL) break;
200 bl->push_back(*b);
201 delete b;
202 }
203 return bl;
204}
205
206CList<Bkmk>* BkmkFile::readall03()
207{
208 CList<Bkmk>* bl = new CList<Bkmk>;
209 while (1)
210 {
211 Bkmk* b = read03();
212 if (b == NULL) break;
213 bl->push_back(*b);
214 delete b;
215 }
216 return bl;
217}
218
219Bkmk* BkmkFile::read03()
220{
221 Bkmk* b = NULL;
222 if (f != NULL)
223 {
224 unsigned short ln;
225 if (fread(&ln,sizeof(ln),1,f) == 1)
226 {
227 b = new Bkmk;
228 b->m_name = new tchar[ln+1];
229 fread(b->m_name,sizeof(tchar),ln,f);
230 b->m_name[ln] = 0;
231
232 ln = 0;
233 b->m_anno = new tchar[ln+1];
234 b->m_anno[ln] = 0;
235
236 fread(&b->m_position,sizeof(b->m_position),1,f);
237 }
238 }
239 return b;
240}
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 @@
1#ifndef __Bkmks_h
2#define __Bkmks_h
3
4#include "config.h"
5#include <stdio.h>
6
7template<class T>
8class CList;
9
10class Bkmk
11{
12 friend class BkmkFile;
13 tchar* m_name;
14 tchar* m_anno;
15 unsigned int m_position;
16 public:
17 Bkmk() : m_name(NULL), m_anno(NULL), m_position(0) {};
18 Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p);
19 Bkmk(const Bkmk& rhs) : m_name(NULL), m_anno(NULL)
20 {
21 *this = rhs;
22 }
23 ~Bkmk();
24 unsigned int value() const { return m_position; }
25 tchar *name() const { return m_name; }
26 tchar *anno() const { return m_anno; }
27 bool operator<(const Bkmk& rhs) { return (m_position < rhs.m_position); }
28 Bkmk& operator=(const Bkmk& rhs);
29 bool operator==(const Bkmk& rhs);
30 void setAnno(tchar* t);
31};
32
33class BkmkFile
34{
35 FILE* f;
36 bool wt;
37 bool isUpgraded;
38 static const unsigned long magic;
39 private:
40 Bkmk* read();
41 Bkmk* read03();
42 CList<Bkmk>* readall03();
43 CList<Bkmk>* readall04();
44 void write(tchar* nm, tchar* an, const unsigned int& pos);
45 void write(const Bkmk& b);
46 public:
47 bool upgraded() { return isUpgraded; }
48 BkmkFile(const char *fnm, bool w = false);
49 ~BkmkFile();
50 void write(CList<Bkmk>& bl);
51 CList<Bkmk>* readall();
52};
53#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 @@
1#include "BuffDoc.h" 1#include "BuffDoc.h"
2//#include <FL/fl_draw.h> 2//#include <FL/fl_draw.h>
3#include "config.h" 3#include "config.h"
4#include "CDrawBuffer.h"
5#include "plucker.h"
6
7
8bool BuffDoc::hyperlink(unsigned int n)
9{
10 bool bRet = false;
11 lastword.empty();
12 lastsizes[0] = laststartline = n;
13 lastispara = false;
14 if (exp != NULL)
15 {
16 bRet = exp->hyperlink(n);
17 lastsizes[0] = laststartline = exp->locate();
18 }
19 return bRet;
20}
4 21
5void BuffDoc::locate(unsigned int n) 22void BuffDoc::locate(unsigned int n)
6{ 23{
7 // qDebug("BuffDoc:locating:%u",n); 24 // qDebug("BuffDoc:locating:%u",n);
8 25 lastword.empty();
9 lastword[0] = '\0';
10 lastsizes[0] = laststartline = n; 26 lastsizes[0] = laststartline = n;
11 lastispara = false; 27 lastispara = false;
12 // tchar linebuf[1024]; 28 // tchar linebuf[1024];
@@ -14,52 +30,52 @@ void BuffDoc::locate(unsigned int n)
14 // qDebug("BuffDoc:Located"); 30 // qDebug("BuffDoc:Located");
15} 31}
16 32
17bool BuffDoc::getline(CBuffer* buff, int w) 33bool BuffDoc::getline(CDrawBuffer* buff, int w)
18{ 34{
35 tchar ch = 32;
36 CStyle cs;
37 buff->empty();
19 if (exp == NULL) 38 if (exp == NULL)
20 { 39 {
21 (*buff)[0] = '\0'; 40 //(*buff)[0] = '\0';
41 buff->empty();
22 return false; 42 return false;
23 } 43 }
24 int len = 0, ch, lastcheck = 0; 44 int len = 0, lastcheck = 0;
25 *buff = lastword.data(); 45 if (lastword.length() > 0)
46 {
47 *buff = lastword;
48 cs = lastword.laststyle();
49 }
50 else buff->empty();
51// qDebug("Buff:%s Lastword:%s", (const char*)toQString(buff->data()), (const char*)toQString(lastword.data()));
26 lastcheck = len = buff->length(); 52 lastcheck = len = buff->length();
27 // unsigned int slen = fl_widthi(buff->data(),len); 53 unsigned int slen = buff->width(len);
28#ifdef _UNICODE
29 unsigned int slen = m_fm->width(toQString(buff->data()),len);
30#else
31 unsigned int slen = m_fm->width(buff->data(),len);
32#endif
33 if (slen > w) 54 if (slen > w)
34 { 55 {
35 for ( ; len > 0; len--) 56 for ( ; len > 0; len--)
36 { 57 {
37 // if (fl_widthi(buff->data(),len) < w) break; 58 if (buff->width(len) < w) break;
38#ifdef _UNICODE
39 if (m_fm->width(toQString(buff->data()),len) < w) break;
40#else
41 if (m_fm->width(buff->data(),len) < w) break;
42#endif
43 } 59 }
44 lastword = buff->data() + len - 1; 60// lastword = buff->data() + len - 1;
61 laststartline = lastsizes[len-1];
62 lastword.setright(*buff, len - 1);
45 for (int i = 0; i < buff->length(); i++) lastsizes[i] = lastsizes[i+len-1]; 63 for (int i = 0; i < buff->length(); i++) lastsizes[i] = lastsizes[i+len-1];
46 (*buff)[len-1] = '-'; 64// (*buff)[len-1] = '-';
65 buff->truncate(len-1);
66 buff->addch('-', cs);
47 (*buff)[len] = '\0'; 67 (*buff)[len] = '\0';
48 laststartline = lastsizes[len-1];
49 return true; 68 return true;
50 } 69 }
51 if (lastispara) 70 if (lastispara)
52 { 71 {
53 lastispara = false; 72 lastispara = false;
54 lastword[0] = '\0'; 73// lastword[0] = '\0';
74 lastword.empty();
55 len = buff->length(); 75 len = buff->length();
56 // while (fl_widthi(buff->data(),len) > w) len--; 76 while (buff->width(len) > w) len--;
57#ifdef _UNICODE 77// (*buff)[len] = '\0';
58 while (m_fm->width(toQString(buff->data()),len) > w) len--; 78 buff->truncate(len);
59#else
60 while (m_fm->width(buff->data(),len) > w) len--;
61#endif
62 (*buff)[len] = '\0';
63 laststartline = exp->locate(); 79 laststartline = exp->locate();
64 return true; 80 return true;
65 } 81 }
@@ -69,18 +85,18 @@ bool BuffDoc::getline(CBuffer* buff, int w)
69 { 85 {
70 lastcheck = len; 86 lastcheck = len;
71 allsizes[len] = exp->locate(); 87 allsizes[len] = exp->locate();
72 while ((ch = getch()) != ' ' && ch != '\012' && ch != UEOF && len < 128) 88 getch(ch, cs);
89 while (ch != ' ' && ch != '\012' && ch != UEOF && len < 128)
73 { 90 {
74 (*buff)[len++] = ch; 91 len++;
92 buff->addch(ch,cs);
75 allsizes[len] = exp->locate(); 93 allsizes[len] = exp->locate();
94 getch(ch, cs);
76 } 95 }
77 (*buff)[len] = 0; 96 (*buff)[len] = 0;
78#ifdef _UNICODE 97 slen = buff->width(len);
79 slen = m_fm->width(toQString(buff->data()),len); 98 len++;
80#else 99 buff->addch(' ', cs);
81 slen = m_fm->width(buff->data(),len);
82#endif
83 (*buff)[len++] = ' ';
84 allsizes[len] = exp->locate(); 100 allsizes[len] = exp->locate();
85 if (slen < w && ch != ' ') 101 if (slen < w && ch != ' ')
86 { 102 {
@@ -90,37 +106,119 @@ bool BuffDoc::getline(CBuffer* buff, int w)
90 lastispara = (ch == '\012'); 106 lastispara = (ch == '\012');
91 } 107 }
92 (*buff)[len] = '\0'; 108 (*buff)[len] = '\0';
93 lastword = buff->data()+lastcheck; 109// lastword = buff->data()+lastcheck;
110 lastword.setright(*buff, lastcheck);
94 for (int i = 0; i < lastword.length(); i++) lastsizes[i] = allsizes[i+lastcheck]; 111 for (int i = 0; i < lastword.length(); i++) lastsizes[i] = allsizes[i+lastcheck];
95 if (lastcheck > 0) 112 if (lastcheck > 0)
96 { 113 {
97 laststartline = allsizes[lastcheck]; 114 laststartline = allsizes[lastcheck];
98 (*buff)[lastcheck-1] = '\0'; 115// (*buff)[lastcheck-1] = '\0';
116 buff->truncate(lastcheck-1);
99 } 117 }
100 else 118 else
101 { 119 {
102 laststartline = (lastcheck == len) ? exp->locate() : allsizes[lastcheck+1]; 120 laststartline = (lastcheck == len) ? exp->locate() : allsizes[lastcheck+1];
103 (*buff)[lastcheck] = '\0'; 121// (*buff)[lastcheck] = '\0';
122 buff->truncate(lastcheck);
104 } 123 }
105// laststartline = sizes[lastcheck+1]; 124// buff->frig();
106// (*buff)[(lastcheck > 0) ? lastcheck-1:lastcheck] = '\0';
107 return (ch != UEOF); 125 return (ch != UEOF);
108} 126}
109 127
110bool BuffDoc::getline(CBuffer* buff, int w, int cw) 128bool BuffDoc::getline(CDrawBuffer* buff, int w, int cw)
111{ 129{
130 buff->empty();
112 if (exp == NULL) 131 if (exp == NULL)
113 { 132 {
114 (*buff)[0] = '\0';
115 return false; 133 return false;
116 } 134 }
117 tchar ch; 135 tchar ch;
136 CStyle cs;
118 int i = 0; 137 int i = 0;
119 while ((i < w/cw) && ((ch = getch()) != '\012') && (ch != UEOF)) 138 while (i*cw < w)
120 { 139 {
121 (*buff)[i++] = ch; 140 getch(ch, cs);
141 if (ch == '\12' || ch == UEOF) break;
142 buff->addch(ch,cs);
143 i++;
122 } 144 }
123 (*buff)[i] = '\0'; 145 buff->truncate(i);
124 laststartline = exp->locate(); 146 laststartline = exp->locate();
125 return (ch != UEOF); 147 return (ch != UEOF);
126} 148}
149
150int BuffDoc::openfile(QWidget* _parent, const char *src)
151{
152 // qDebug("BuffDoc:Openfile:%s", src);
153 // qDebug("Trying aportis %x",exp);
154 if (exp != NULL) delete exp;
155 lastword.empty();
156 lastsizes[0] = laststartline = 0;
157 lastispara = false;
158 /*
159 exp = new Text;
160 int ret = exp->openfile(src);
161 */
162
163 exp = new Aportis;
164 int ret = exp->openfile(src);
165 if (ret == -1)
166 {
167 delete exp;
168 exp = NULL;
169 return ret;
170 }
171 if (ret == -2)
172 {
173
174 delete exp;
175 exp = new ztxt;
176 ret = exp->openfile(src);
177 }
178 if (ret != 0)
179 {
180
181 delete exp;
182 exp = new CPlucker;
183 ret = exp->openfile(src);
184 }
185#ifndef SMALL
186 if (ret != 0)
187 {
188 delete exp;
189 qDebug("Trying ppms");
190 exp = new ppm_expander;
191 ret = exp->openfile(src);
192 }
193
194 if (ret != 0)
195 {
196 delete exp;
197 exp = new Text;
198 // qDebug("Trying text");
199 ret = exp->openfile(src);
200 }
201#else
202 if (ret != 0)
203 {
204 delete exp;
205 exp = new Text;
206 ret = exp->openfile(src);
207 }
208#endif
209 if (ret != 0)
210 {
211 delete exp;
212 QMessageBox::information(_parent, "QTReader", "Unknown file compression type","Try another file");
213 return ret;
214 }
215 // qDebug("Doing final open:%x:%x",exp,filt);
216
217 lastword.empty();
218 lastsizes[0] = laststartline = 0;
219 lastispara = false;
220 exp->locate(0);
221 filt->setsource(exp);
222 // qDebug("BuffDoc:file opened");
223 return 0;
224}
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 @@
1#ifndef __BuffDoc_h 1#ifndef __BuffDoc_h
2#define __BuffDoc_h 2#define __BuffDoc_h
3 3
4#include "CBuffer.h"
5#include "ZText.h" 4#include "ZText.h"
6#include "Aportis.h" 5#include "Aportis.h"
7#include "ztxt.h" 6#include "ztxt.h"
8#include "ppm_expander.h" 7#include "ppm_expander.h"
8#include "CDrawBuffer.h"
9#include "CFilter.h" 9#include "CFilter.h"
10#include <qfontmetrics.h> 10#include <qfontmetrics.h>
11#include <qmessagebox.h> 11#include <qmessagebox.h>
12 12
13class BuffDoc 13class BuffDoc
14{ 14{
15 CBuffer lastword; 15 CDrawBuffer lastword;
16 CSizeBuffer lastsizes, allsizes; 16 CSizeBuffer lastsizes, allsizes;
17 size_t laststartline; 17 size_t laststartline;
18 bool lastispara; 18 bool lastispara;
19 CExpander* exp; 19 CExpander* exp;
20 CFilterChain* filt; 20 CFilterChain* filt;
21 QFontMetrics* m_fm;
22 public: 21 public:
23 ~BuffDoc() 22 ~BuffDoc()
24 { 23 {
25 delete filt; 24 delete filt;
26 delete exp; 25 delete exp;
27 } 26 }
28 BuffDoc() : m_fm(NULL) 27 BuffDoc()
29 { 28 {
30 exp = NULL; 29 exp = NULL;
31 filt = NULL; 30 filt = NULL;
31 lastword.empty();
32 // qDebug("Buffdoc created"); 32 // qDebug("Buffdoc created");
33 } 33 }
34 bool empty() { return (exp == NULL); } 34 bool empty() { return (exp == NULL); }
35 void setfm(QFontMetrics* fm)
36 {
37 m_fm = fm;
38 // qDebug("Buffdoc:setfm");
39 }
40 void setfilter(CFilterChain* _f) 35 void setfilter(CFilterChain* _f)
41 { 36 {
42 if (filt != NULL) delete filt; 37 if (filt != NULL) delete filt;
@@ -46,87 +41,38 @@ class BuffDoc
46 CList<Bkmk>* getbkmklist() { return exp->getbkmklist(); } 41 CList<Bkmk>* getbkmklist() { return exp->getbkmklist(); }
47 bool hasrandomaccess() { return (exp == NULL) ? false : exp->hasrandomaccess(); } 42 bool hasrandomaccess() { return (exp == NULL) ? false : exp->hasrandomaccess(); }
48 bool iseol() { return (lastword[0] == '\0'); } 43 bool iseol() { return (lastword[0] == '\0'); }
49 int openfile(QWidget* _parent, const char *src) 44 int openfile(QWidget* _parent, const char *src);
45 tchar getch()
50 { 46 {
51 // qDebug("BuffDoc:Openfile:%s", src); 47 tchar ch = UEOF;
52 // qDebug("Trying aportis %x",exp); 48 CStyle sty;
53 if (exp != NULL) delete exp; 49 if (exp != NULL)
54 lastword[0] = '\0';
55 lastsizes[0] = laststartline = 0;
56 lastispara = false;
57 /*
58 exp = new Text;
59 int ret = exp->openfile(src);
60 */
61
62 exp = new Aportis;
63 // qDebug("Calling openfile");
64 int ret = exp->openfile(src);
65 // qDebug("Called openfile");
66 if (ret == -1)
67 { 50 {
68 // qDebug("problem opening source file:%s",src); 51 filt->getch(ch, sty);
69 delete exp;
70 exp = NULL;
71 return ret;
72 } 52 }
73 if (ret == -2) 53 return ch;
74 { 54 }
75 55 void getch(tchar& ch, CStyle& sty)
76 delete exp; 56 {
77 // qDebug("Trying ztxt"); 57 if (exp != NULL)
78 exp = new ztxt;
79 ret = exp->openfile(src);
80 }
81#ifndef SMALL
82 if (ret != 0)
83 {
84 delete exp;
85 // qDebug("Trying ppms");
86 exp = new ppm_expander;
87 ret = exp->openfile(src);
88 }
89
90 if (ret != 0)
91 {
92 delete exp;
93 exp = new Text;
94 // qDebug("Trying text");
95 ret = exp->openfile(src);
96 }
97#else
98 if (ret != 0)
99 {
100 delete exp;
101 exp = new Text;
102 ret = exp->openfile(src);
103 }
104#endif
105 if (ret != 0)
106 { 58 {
107 delete exp; 59 filt->getch(ch, sty);
108 QMessageBox::information(_parent, "QTReader", "Unknown file compression type","Try another file");
109 return ret;
110 } 60 }
111 // qDebug("Doing final open:%x:%x",exp,filt); 61 else
112 62 ch = UEOF;
113 lastword[0] = '\0';
114 lastsizes[0] = laststartline = 0;
115 lastispara = false;
116 exp->locate(0);
117 filt->setsource(exp);
118 // qDebug("BuffDoc:file opened");
119 return 0;
120 } 63 }
121 int getch() { return (exp == NULL) ? UEOF : filt->getch(); }
122 unsigned int locate() { return (exp == NULL) ? 0 : laststartline; } 64 unsigned int locate() { return (exp == NULL) ? 0 : laststartline; }
65 unsigned int explocate() { return (exp == NULL) ? 0 : exp->locate(); }
66 MarkupType PreferredMarkup() { return (exp == NULL) ? cTEXT : exp->PreferredMarkup(); }
67 bool hyperlink(unsigned int n);
123 void locate(unsigned int n); 68 void locate(unsigned int n);
124 bool getline(CBuffer* buff, int w); 69 bool getline(CDrawBuffer* buff, int w);
125 bool getline(CBuffer* buff, int w, int cw); 70 bool getline(CDrawBuffer* buff, int w, int cw);
126 void sizes(unsigned long& fs, unsigned long& ts) { exp->sizes(fs,ts); } 71 void sizes(unsigned long& fs, unsigned long& ts) { exp->sizes(fs,ts); }
127 int getpara(CBuffer& buff) 72 int getpara(CBuffer& buff)
128 { 73 {
129 int ch, i = 0; 74 tchar ch;
75 int i = 0;
130 while ((ch = getch()) != 10 && ch != UEOF) buff[i++] = ch; 76 while ((ch = getch()) != 10 && ch != UEOF) buff[i++] = ch;
131 buff[i] = '\0'; 77 buff[i] = '\0';
132 if (i == 0 && ch == UEOF) i = -1; 78 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 @@
1#ifndef __CANNOEDIT_H
2#define __CANNOEDIT_H
3#include <qlabel.h>
4#include <qlayout.h>
5#include <qpushbutton.h>
6#include <qlineedit.h>
7#include <qmultilineedit.h>
8
9class CAnnoEdit : public QWidget
10{
11 Q_OBJECT
12
13 QLineEdit* m_name;
14 QMultiLineEdit* m_anno;
15 size_t m_posn;
16 public:
17 void setPosn(size_t p) { m_posn = p; }
18 size_t getPosn() { return m_posn; }
19 void setName(const QString& name)
20 {
21 m_name->setText(name);
22 }
23 void setAnno(const QString& name)
24 {
25 m_anno->setText(name);
26 m_anno->setEdited(false);
27 }
28 bool edited() { return m_anno->edited(); }
29 CAnnoEdit(QWidget *parent=0, const char *name=0, WFlags f = 0) :
30 QWidget(parent, name, f)
31 {
32 QVBoxLayout* grid = new QVBoxLayout(this);
33 m_name = new QLineEdit(this, "Name");
34 m_anno = new QMultiLineEdit(this, "Annotation");
35 QPushButton* exitButton = new QPushButton("Okay", this);
36 connect(exitButton, SIGNAL( released() ), this, SLOT( slotOkay() ) );
37 QPushButton* cancelButton = new QPushButton("Cancel", this);
38 connect(cancelButton, SIGNAL( released() ), this, SLOT( slotCancel() ) );
39 QLabel *l = new QLabel("Text",this);
40 grid->addWidget(l);
41 grid->addWidget(m_name);
42 l = new QLabel("Annotation",this);
43 grid->addWidget(l);
44 grid->addWidget(m_anno,1);
45 QHBoxLayout* hgrid = new QHBoxLayout(grid);
46 hgrid->addWidget(cancelButton);
47 hgrid->addWidget(exitButton);
48 }
49 private slots:
50 void slotOkay() { emit finished(m_name->text(), m_anno->text()); }
51 void slotCancel() { emit cancelled(); }
52 public:
53 signals:
54 void finished(const QString&, const QString&);
55 void cancelled();
56};
57
58#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 @@
1#include "CBuffer.h" 1#include "CBuffer.h"
2 2
3CBuffer& CBuffer::operator=(const tchar*sztmp) 3CBufferBase& CBufferBase::assign(const void* sztmp, size_t ms)
4{ 4{
5 int i; 5 if (ms*membersize > len)
6 for (i = 0; sztmp[i] != '\0'; i++) (*this)[i] = sztmp[i]; 6 {
7 (*this)[i] = '\0'; 7 delete [] buffer;
8 return *this; 8 buffer = new unsigned char[len = ms*membersize];
9 }
10 memcpy(buffer, sztmp, ms*membersize);
11 return *this;
12}
13
14CBufferBase::CBufferBase(size_t ms, size_t n = 16) : len(n), membersize(ms)
15{
16 buffer = new unsigned char[len*membersize];
17 memset(buffer, 0, len*membersize);
9} 18}
10 19
11tchar& CBuffer::operator[](int i) 20void* CBufferBase::operator[](int i)
12{ 21{
13 if (i >= len) 22 if ((i+1)*membersize > len)
14 { 23 {
15 tchar *newbuff = new tchar[i+1]; 24 unsigned char* oldbuffer = buffer;
16 memcpy(newbuff,buffer,sizeof(tchar)*len); 25 buffer = new unsigned char[(i+1)*membersize];
17 delete [] buffer; 26 memcpy(buffer, oldbuffer, len);
18 buffer = newbuff; 27 memset(buffer+len, 0, (i+1)*membersize-len);
19 len = i+1; 28 len = (i+1)*membersize;
29 delete [] oldbuffer;
20 } 30 }
21 return buffer[i]; 31 return buffer+i*membersize;
22} 32}
23 33
24size_t& CSizeBuffer::operator[](int i) 34size_t CBufferBase::bstrlen(unsigned char* _buffer = NULL)
25{ 35{
26 if (i >= len) 36 if (_buffer == NULL) _buffer = buffer;
37 unsigned char* zero = new unsigned char[membersize];
38 memset(zero,0,membersize);
39 unsigned char* element = _buffer;
40 while (memcmp(element, zero, membersize) != 0)
27 { 41 {
28 size_t *newbuff = new size_t[i+1]; 42 element += membersize;
29 memcpy(newbuff,buffer,sizeof(size_t)*len);
30 delete [] buffer;
31 buffer = newbuff;
32 len = i+1;
33 } 43 }
34 return buffer[i]; 44 delete [] zero;
45 return (element - _buffer)/membersize;
35} 46}
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 @@
5#include <string.h> 5#include <string.h>
6#include "config.h" 6#include "config.h"
7 7
8class CBuffer 8
9class CBufferBase
9{ 10{
11 protected:
10 size_t len; 12 size_t len;
11 tchar *buffer; 13 unsigned char *buffer;
12 CBuffer(const CBuffer&); 14 size_t membersize;
15 CBufferBase(const CBufferBase&);
13 public: 16 public:
14 CBuffer& operator=(const tchar*sztmp); 17 CBufferBase& assign(const void* sztmp, size_t ms);
15#ifdef _UNICODE 18 void* data() { return buffer; }
16 size_t length() { return ustrlen(buffer); } 19 CBufferBase(size_t ms, size_t n = 16);
17#else 20 ~CBufferBase() { delete [] buffer; }
18 size_t length() { return strlen(buffer); } 21 void* operator[](int i);
19#endif 22 size_t bstrlen(unsigned char* _buffer = NULL);
20 tchar* data() { return buffer; } 23 size_t totallen() { return len; }
21 CBuffer(size_t n = 16) : len(n)
22 {
23 buffer = new tchar[len];
24 buffer[0] = '\0';
25 }
26 ~CBuffer() { delete [] buffer; }
27 tchar& operator[](int i);
28}; 24};
29 25
30class CSizeBuffer 26template<class T>
27class CBufferFace
31{ 28{
32 size_t len; 29 CBufferBase m_buffer;
33 size_t *buffer; 30 protected:
34 CSizeBuffer(const CSizeBuffer&); 31 CBufferFace(const CBufferFace&);
35 public: 32 public:
36 size_t* data() { return buffer; } 33 CBufferFace& operator=(const T* sztmp)
37 CSizeBuffer(size_t n = 16) : len(n) 34 {
38 { 35 m_buffer.assign(sztmp, m_buffer.bstrlen(sztmp));
39 buffer = new size_t[len]; 36 return *this;
40 } 37 }
41 ~CSizeBuffer() { delete [] buffer; } 38 void assign(const T* sztmp, size_t n)
42 size_t& operator[](int i); 39 {
40 m_buffer.assign(sztmp, n);
41 }
42 size_t length() { return m_buffer.bstrlen(); }
43 size_t totallen() { return m_buffer.totallen(); }
44 T* data() { return (T*)m_buffer.data(); }
45 CBufferFace(size_t n = 16) : m_buffer(sizeof(T), n) {}
46 T& operator[](int i)
47 {
48 return *((T*)m_buffer[i]);
49 }
43}; 50};
44 51
52typedef CBufferFace<tchar> CBuffer;
53typedef CBufferFace<size_t> CSizeBuffer;
54
45#endif 55#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 @@
1#include <stdio.h> 1#include <stdio.h>
2#include "CEncoding.h" 2#include "CEncoding.h"
3 3
4tchar CUtf8::getch() 4void CUtf8::getch(tchar& ch, CStyle& sty)
5{ 5{
6 int iret = parent->getch(); 6 int iret;
7 if (iret == EOF) return UEOF; 7 parent->getch(iret, sty);
8 if (iret == EOF)
9 {
10 ch = UEOF;
11 return;
12 }
8 tchar ret = iret; 13 tchar ret = iret;
9 int count = 0; 14 int count = 0;
10 if (ret & (1 << 7)) 15 if (ret & (1 << 7))
@@ -13,7 +18,8 @@ tchar CUtf8::getch()
13 while ((flags & (1 << 7)) != 0) 18 while ((flags & (1 << 7)) != 0)
14 { 19 {
15 ret <<= 6; 20 ret <<= 6;
16 ret += parent->getch() & 0x3f; 21 parent->getch(iret, sty);
22 ret += iret & 0x3f;
17 flags <<= 1; 23 flags <<= 1;
18 count++; 24 count++;
19 } 25 }
@@ -33,118 +39,172 @@ tchar CUtf8::getch()
33 printf("Only 16bit unicode supported..."); 39 printf("Only 16bit unicode supported...");
34 } 40 }
35 } 41 }
36 return ret; 42 ch = ret;
43 return;
37} 44}
38 45
39 46void CUcs16be::getch(tchar& ch, CStyle& sty)
40tchar CUcs16be::getch()
41{ 47{
42 int iret = parent->getch(); 48 int iret;
43 if (iret == EOF) return UEOF; 49 parent->getch(iret, sty);
50 if (iret == EOF)
51 {
52 ch = UEOF;
53 return;
54 }
44 tchar ret = iret; 55 tchar ret = iret;
45 return (ret << 8) + parent->getch(); 56 parent->getch(iret, sty);
57 ch = (ret << 8) + iret;
46} 58}
47 59
48tchar CUcs16le::getch() 60void CUcs16le::getch(tchar& ch, CStyle& sty)
49{ 61{
50 int iret = parent->getch(); 62 int iret;
51 if (iret == EOF) return UEOF; 63 parent->getch(iret, sty);
64 if (iret == EOF)
65 {
66 ch = UEOF;
67 return;
68 }
52 tchar ret = iret; 69 tchar ret = iret;
53 return ret + (parent->getch() << 8); 70 parent->getch(iret, sty);
71 ch = ret + (iret << 8);
54} 72}
55 73
56tchar Ccp1252::getch() 74void Ccp1252::getch(tchar& ch, CStyle& sty)
57{ 75{
58 int iret = parent->getch(); 76 int iret;
59 switch (iret) 77 parent->getch(iret, sty);
78 ch = iret;
79 switch (ch)
60 { 80 {
61 case EOF: 81 case EOF:
62 return UEOF; 82 ch = UEOF;
83 break;
63 case 0x80: 84 case 0x80:
64 return 0x20ac; 85 ch = 0x20ac;
86 break;
65 case 0x82: 87 case 0x82:
66 return 0x201a; 88 ch = 0x201a;
89 break;
67 case 0x83: 90 case 0x83:
68 return 0x0192; 91 ch = 0x0192;
92 break;
69 case 0x84: 93 case 0x84:
70 return 0x201e; 94 ch = 0x201e;
95 break;
71 case 0x85: 96 case 0x85:
72 return 0x2026; 97 ch = 0x2026;
98 break;
73 case 0x86: 99 case 0x86:
74 return 0x2020; 100 ch = 0x2020;
101 break;
75 case 0x87: 102 case 0x87:
76 return 0x2021; 103 ch = 0x2021;
104 break;
77 case 0x88: 105 case 0x88:
78 return 0x02c6; 106 ch = 0x02c6;
107 break;
79 case 0x89: 108 case 0x89:
80 return 0x2030; 109 ch = 0x2030;
110 break;
81 case 0x8a: 111 case 0x8a:
82 return 0x0160; 112 ch = 0x0160;
113 break;
83 case 0x8b: 114 case 0x8b:
84 return 0x2039; 115 ch = 0x2039;
116 break;
85 case 0x8c: 117 case 0x8c:
86 return 0x0152; 118 ch = 0x0152;
119 break;
87 case 0x8e: 120 case 0x8e:
88 return 0x017d; 121 ch = 0x017d;
122 break;
89 case 0x91: 123 case 0x91:
90 return 0x2018; 124 ch = 0x2018;
125 break;
91 case 0x92: 126 case 0x92:
92 return 0x2019; 127 ch = 0x2019;
128 break;
93 case 0x93: 129 case 0x93:
94 return 0x201c; 130 ch = 0x201c;
131 break;
95 case 0x94: 132 case 0x94:
96 return 0x201d; 133 ch = 0x201d;
134 break;
97 case 0x95: 135 case 0x95:
98 return 0x2022; 136 ch = 0x2022;
137 break;
99 case 0x96: 138 case 0x96:
100 return 0x2013; 139 ch = 0x2013;
140 break;
101 case 0x97: 141 case 0x97:
102 return 0x2014; 142 ch = 0x2014;
143 break;
103 case 0x98: 144 case 0x98:
104 return 0x02dc; 145 ch = 0x02dc;
146 break;
105 case 0x99: 147 case 0x99:
106 return 0x2122; 148 ch = 0x2122;
149 break;
107 case 0x9a: 150 case 0x9a:
108 return 0x0161; 151 ch = 0x0161;
152 break;
109 case 0x9b: 153 case 0x9b:
110 return 0x203a; 154 ch = 0x203a;
155 break;
111 case 0x9c: 156 case 0x9c:
112 return 0x0153; 157 ch = 0x0153;
158 break;
113 case 0x9e: 159 case 0x9e:
114 return 0x017e; 160 ch = 0x017e;
161 break;
115 case 0x9f: 162 case 0x9f:
116 return 0x0178; 163 ch = 0x0178;
164 break;
117 default: 165 default:
118 return iret; 166 break;
119 } 167 }
120} 168}
121 169
122tchar CPalm::getch() 170void CPalm::getch(tchar& ch, CStyle& sty)
123{ 171{
124 tchar iret = Ccp1252::getch(); 172 Ccp1252::getch(ch, sty);
125 switch (iret) 173 switch (ch)
126 { 174 {
127 case 0x18: 175 case 0x18:
128 return 0x2026; 176 ch = 0x2026;
177 break;
129 case 0x19: 178 case 0x19:
130 return 0x2007; 179 ch = 0x2007;
180 break;
131 case 0x8d: 181 case 0x8d:
132 return 0x2662; 182 ch = 0x2662;
183 break;
133 case 0x8e: 184 case 0x8e:
134 return 0x2663; 185 ch = 0x2663;
186 break;
135 case 0x8f: 187 case 0x8f:
136 return 0x2661; 188 ch = 0x2661;
189 break;
137 case 0x90: 190 case 0x90:
138 return 0x2660; 191 ch = 0x2660;
192 break;
139 default: 193 default:
140 return iret; 194 break;
141 } 195 }
142} 196}
143 197
144tchar CAscii::getch() 198void CAscii::getch(tchar& ch, CStyle& sty)
145{ 199{
146 int iret = parent->getch(); 200 int iret;
147 if (iret == EOF) return UEOF; 201 parent->getch(iret, sty);
148 return iret; 202 if (iret == EOF)
203 {
204 ch = UEOF;
205 }
206 else
207 {
208 ch = iret;
209 }
149} 210}
150
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:
17class CUtf8 : public CEncoding 17class CUtf8 : public CEncoding
18{ 18{
19public: 19public:
20 tchar getch(); 20 void getch(tchar& ch, CStyle& sty);
21}; 21};
22 22
23class CUcs16be : public CEncoding 23class CUcs16be : public CEncoding
24{ 24{
25public: 25public:
26 tchar getch(); 26 void getch(tchar& ch, CStyle& sty);
27}; 27};
28 28
29class CUcs16le : public CEncoding 29class CUcs16le : public CEncoding
30{ 30{
31public: 31public:
32 tchar getch(); 32 void getch(tchar& ch, CStyle& sty);
33}; 33};
34 34
35class Ccp1252 : public CEncoding 35class Ccp1252 : public CEncoding
36{ 36{
37public: 37public:
38 virtual tchar getch(); 38 void getch(tchar& ch, CStyle& sty);
39}; 39};
40 40
41class CPalm : public Ccp1252 41class CPalm : public Ccp1252
42{ 42{
43public: 43public:
44 tchar getch(); 44 void getch(tchar& ch, CStyle& sty);
45}; 45};
46 46
47class CAscii : public CEncoding 47class CAscii : public CEncoding
48{ 48{
49public: 49public:
50 tchar getch(); 50 void getch(tchar& ch, CStyle& sty);
51}; 51};
52 52
53#endif 53#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 @@
1#ifndef __CExpander_h 1#ifndef __CExpander_h
2#define __CExpander_h 2#define __CExpander_h
3 3
4#include "my_list.h"
5#include "config.h" 4#include "config.h"
5#include "StyleConsts.h"
6#include "Markups.h"
6 7
7class Bkmk 8class Bkmk;
8{
9 friend class BkmkFile;
10 tchar* m_name;
11 unsigned int m_position;
12 public:
13 Bkmk() : m_name(NULL), m_position(0) {};
14 Bkmk(const tchar* _nm, unsigned int _p) : m_position(_p)
15 {
16 int len = ustrlen(_nm)+1;
17 m_name = new tchar[len];
18 for (int i = 0; i < len; i++) m_name[i] = _nm[i];
19 }
20 Bkmk(const Bkmk& rhs) : m_name(NULL)
21 {
22 *this = rhs;
23 }
24 ~Bkmk() { if (m_name != NULL) delete [] m_name; }
25 unsigned int value() const { return m_position; }
26 tchar *name() const { return m_name; }
27 bool operator<(const Bkmk& rhs) { return (m_position < rhs.m_position); }
28 Bkmk& operator=(const Bkmk& rhs)
29 {
30 if (m_name != NULL) delete [] m_name;
31 if (rhs.m_name != NULL)
32 {
33 int len = ustrlen(rhs.m_name)+1;
34 m_name = new tchar[len];
35 for (int i = 0; i < len; i++) m_name[i] = rhs.m_name[i];
36 }
37 else
38 m_name = NULL;
39 m_position = rhs.m_position;
40 return *this;
41 }
42 bool operator==(const Bkmk& rhs)
43 {
44 return (m_position == rhs.m_position && ustrcmp(m_name,rhs.m_name) == 0);
45 }
46};
47 9
48class BkmkFile 10template<class T>
49{ 11class CList;
50 FILE* f;
51 bool wt;
52public:
53 BkmkFile(const char *fnm, bool w = false)
54 :
55 wt(w)
56 {
57 if (w)
58 f = fopen(fnm, "wb");
59 else
60 f = fopen(fnm, "rb");
61 }
62 ~BkmkFile()
63 {
64 if (f != NULL) fclose(f);
65 }
66 void write(tchar* nm, const unsigned int& pos)
67 {
68 if (f != NULL)
69 {
70 unsigned short ln = ustrlen(nm);
71 fwrite(&ln,sizeof(ln),1,f);
72 fwrite(nm,sizeof(tchar),ln,f);
73 fwrite(&pos,sizeof(pos),1,f);
74 }
75 }
76 void write(const Bkmk& b) { write(b.name(), b.value()); }
77 void write(CList<Bkmk>& bl)
78 {
79 if (f != NULL)
80 {
81 for (CList<Bkmk>::iterator i = bl.begin(); i != bl.end(); i++)
82 {
83 write(*i);
84 }
85 }
86 }
87 Bkmk* read()
88 {
89 Bkmk* b = NULL;
90 if (f != NULL)
91 {
92 unsigned short ln;
93 if (fread(&ln,sizeof(ln),1,f) == 1)
94 {
95 b = new Bkmk;
96 b->m_name = new tchar[ln+1];
97 fread(b->m_name,sizeof(tchar),ln,f);
98 b->m_name[ln] = 0;
99 fread(&b->m_position,sizeof(b->m_position),1,f);
100 }
101 }
102 return b;
103 }
104 CList<Bkmk>* readall()
105 {
106 CList<Bkmk>* bl = NULL;
107 if (f != NULL)
108 {
109 bl = new CList<Bkmk>;
110 while (1)
111 {
112 Bkmk* b = read();
113 if (b == NULL) break;
114 bl->push_back(*b);
115 delete b;
116 }
117 }
118 return bl;
119 }
120};
121 12
122class CCharacterSource 13class CCharacterSource
123{ 14{
124 public: 15 public:
125#ifdef _UNICODE 16 virtual void getch(tchar&, CStyle&) = 0;
126 virtual tchar getch() = 0;
127#else
128 virtual int getch() = 0;
129#endif
130}; 17};
131 18
132class CExpander 19class CExpander
@@ -140,6 +27,17 @@ class CExpander
140 virtual bool hasrandomaccess() = 0; 27 virtual bool hasrandomaccess() = 0;
141 virtual void sizes(unsigned long& file, unsigned long& text) = 0; 28 virtual void sizes(unsigned long& file, unsigned long& text) = 0;
142 virtual CList<Bkmk>* getbkmklist() { return NULL; } 29 virtual CList<Bkmk>* getbkmklist() { return NULL; }
30 virtual void getch(int& ch, CStyle& sty)
31 {
32 ch = getch();
33 sty.unset();
34 }
143 virtual int getch() = 0; 35 virtual int getch() = 0;
36 virtual bool hyperlink(unsigned int n)
37 {
38 locate(n);
39 return true;
40 }
41 virtual MarkupType PreferredMarkup() = 0;
144}; 42};
145#endif 43#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 @@
1#include "CDrawBuffer.h"
2#include "CFilter.h"
3
4unsigned short striphtml::skip_ws()
5{
6 tchar ch;
7 CStyle sty;
8 do
9 {
10 parent->getch(ch, sty);
11 }
12 while (ch < 33);
13 return ch;
14}
15
16unsigned short striphtml::skip_ws_end()
17{
18 tchar ch;
19 CStyle sty;
20 parent->getch(ch, sty);
21 if (ch == ' ')
22 {
23 do
24 {
25 parent->getch(ch, sty);
26 }
27 while (ch != '>');
28 }
29 return ch;
30}
31
32unsigned short striphtml::parse_m()
33{
34 tchar ch;
35 CStyle sty;
36 parent->getch(ch, sty);
37 if (ch == 'm' || ch == 'M')
38 {
39 ch = skip_ws_end();
40 if (ch == '>')
41 {
42 return 0;
43 }
44 }
45 return ch;
46}
47
48void striphtml::mygetch(tchar& ch, CStyle& sty)
49{
50 parent->getch(ch, sty);
51 if (ch == 10) ch = ' ';
52}
53
54void striphtml::getch(tchar& ch, CStyle& sty)
55{
56 CStyle dummy;
57 mygetch(ch, dummy);
58 if (ch == 10) ch = ' ';
59 while (ch == '<')
60 {
61 ch = skip_ws();
62
63 switch (ch)
64 {
65 case 'p':
66 case 'P':
67 ch = skip_ws_end();
68 if (ch == '>')
69 {
70 ch = 10;
71 continue;
72 }
73 break;
74 case 'b':
75 case 'B':
76 ch = skip_ws_end();
77 if (ch == '>')
78 {
79 currentstyle.setBold();
80 mygetch(ch, dummy);
81 continue;
82 }
83 else if (ch == 'r' || ch == 'R')
84 {
85 ch = skip_ws_end();
86 if (ch == '>')
87 {
88 ch = 10;
89 continue;
90 }
91 }
92 break;
93 case 'i':
94 case 'I':
95 ch = skip_ws_end();
96 if (ch == '>')
97 {
98 currentstyle.setItalic();
99 mygetch(ch, dummy);
100 continue;
101 }
102 break;
103 case 'e':
104 case 'E':
105 if ((ch = parse_m()) == 0)
106 {
107 currentstyle.setItalic();
108 mygetch(ch, dummy);
109 continue;
110 }
111 break;
112 case 'h':
113 case 'H':
114 mygetch(ch, dummy);
115 if ('0' < ch && ch <= '9')
116 {
117 tchar hs = ch;
118 ch = skip_ws_end();
119 if (ch == '>')
120 {
121 switch (hs)
122 {
123 case '1':
124 // currentstyle = ucBold | ucFontBase+2 | (ucAlignCentre << ucAlignShift);
125 currentstyle.unset();
126 currentstyle.setFontSize(2);
127 currentstyle.setBold();
128 currentstyle.setCentreJustify();
129 break;
130 case '2':
131 // currentstyle = ucBold | ucFontBase+1;
132 currentstyle.unset();
133 currentstyle.setFontSize(1);
134 currentstyle.setBold();
135 break;
136 default:
137 // currentstyle = ucBold | ucFontBase;
138 currentstyle.unset();
139 currentstyle.setBold();
140 }
141 ch = 10;
142 // mygetch(ch, dummy);
143 continue;
144 }
145 }
146 break;
147 case '/':
148 mygetch(ch, dummy);
149 switch (ch)
150 {
151 case 'b':
152 case 'B':
153 ch = skip_ws_end();
154 if (ch == '>')
155 {
156 currentstyle.unsetBold();
157 mygetch(ch, dummy);
158 continue;
159 }
160 break;
161 case 'i':
162 case 'I':
163 ch = skip_ws_end();
164 if (ch == '>')
165 {
166 currentstyle.unsetItalic();
167 mygetch(ch, dummy);
168 continue;
169 }
170 break;
171 case 'e':
172 case 'E':
173 if ((ch = parse_m()) == 0)
174 {
175 currentstyle.unsetItalic();
176 mygetch(ch, dummy);
177 continue;
178 }
179 break;
180 case 'h':
181 case 'H':
182 mygetch(ch, dummy);
183 if ('0' < ch && ch <= '9')
184 {
185 ch = skip_ws_end();
186 if (ch == '>')
187 {
188 currentstyle.unset();
189 //mygetch(ch, dummy);
190 ch = 10;
191 continue;
192 }
193 }
194 break;
195 default:
196 break;
197 }
198 break;
199 default:
200 break;
201 }
202 while (ch != '>' && ch != UEOF)
203 {
204 mygetch(ch, dummy);
205 }
206 mygetch(ch, dummy);
207 }
208 if (ch == '&')
209 {
210 mygetch(ch, dummy);
211 if (ch == '#')
212 {
213 int id = 0;
214 mygetch(ch, dummy);
215 while (ch != ';' && ch != UEOF)
216 {
217 id = 10*id+ch-'0';
218 mygetch(ch, dummy);
219 }
220 ch = id;
221 }
222 }
223// sty = (dummy == ucFontBase) ? currentstyle : dummy;
224 sty = currentstyle;
225 return;
226}
227
228
229void textfmt::mygetch(tchar& ch, CStyle& sty)
230{
231 if (uselast)
232 {
233 ch = lastchar;
234 uselast = false;
235 }
236 else
237 {
238 parent->getch(ch, sty);
239 }
240}
241
242void textfmt::getch(tchar& ch, CStyle& sty)
243{
244 mygetch(ch, sty);
245 do
246 {
247 sty = currentstyle;
248 switch (ch)
249 {
250 case 10:
251 currentstyle.unset();
252 sty = currentstyle;
253 break;
254// Use this if you want to replace -- by em-dash
255 case '-':
256 // parent->getch(ch, sty);
257 mygetch(ch, sty);
258 if (ch == '-')
259 {
260 ch = 0x2014;
261 }
262 else
263 {
264 lastchar = ch;
265 uselast = true;
266 ch = '-';
267 }
268 break;
269 case '*':
270 if (currentstyle.isBold())
271 {
272// Already bold - time to turn it off?
273// The next two lines ensure that * follows a character but it works better without
274 // QChar c(lastchar);
275 // if ((lastchar != '*') && (c.isPunct() || c.isLetterOrNumber()))
276 if (lastchar != '*')
277 {
278 currentstyle.unsetBold();
279 CStyle dummy;
280 // parent->getch(ch, dummy);
281 mygetch(ch, dummy);
282 }
283 }
284 else
285 {
286// not bold - time to turn it on?
287 CStyle dummy;
288 // parent->getch(ch, dummy);
289 mygetch(ch, dummy);
290 QChar c(ch);
291 if ((ch != '*') && (c.isPunct() || c.isLetterOrNumber()))
292 {
293 currentstyle.setBold();
294 }
295 else
296 {
297 lastchar = ch;
298 uselast = true;
299 ch = '*';
300 }
301
302 }
303 break;
304 case '_':
305 if (currentstyle.isItalic())
306 {
307// Already bold - time to turn it off?
308// The next two lines ensure that * follows a character but it works better without
309 // QChar c(lastchar);
310 // if ((lastchar != '_') && (c.isPunct() || c.isLetterOrNumber()))
311 if (lastchar != '_')
312 {
313 currentstyle.unsetItalic();
314 CStyle dummy;
315 // parent->getch(ch, dummy);
316 mygetch(ch, dummy);
317 }
318 }
319 else
320 {
321// not bold - time to turn it on?
322 CStyle dummy;
323 // parent->getch(ch, dummy);
324 mygetch(ch, dummy);
325 QChar c(ch);
326 if ((ch != '_') && (c.isPunct() || c.isLetterOrNumber()))
327 {
328 currentstyle.setItalic();
329 }
330 else
331 {
332 lastchar = ch;
333 uselast = true;
334 ch = '_';
335 }
336
337 }
338 break;
339 }
340 }
341 while (sty != currentstyle);
342 if (!uselast) lastchar = ch;
343 return;
344}
345
346void remap::getch(tchar& ch, CStyle& sty)
347{
348 if (q[offset] != 0)
349 {
350 q[offset++];
351 sty = currentstyle;
352 return;
353 }
354 parent->getch(ch, sty);
355 switch (ch)
356 {
357 case 0x201a:
358 ch = '\'';
359 break;
360 case 0x0192:
361 ch = 'f';
362 break;
363 case 0x201e:
364 ch = '"';
365 break;
366 case 0x2026:
367 offset = 0;
368 q[0] = '.';
369 q[1] = '.';
370 q[2] = 0;
371 ch = '.'; // should be ...
372 break;
373 case 0x0160:
374 ch = 'S';
375 break;
376 case 0x2039:
377 ch = '<';
378 break;
379 case 0x0152:
380 offset = 0;
381 q[0] = 'E';
382 q[1] = 0;
383 ch = 'O';
384 break;
385 case 0x017d:
386 ch = 'Z';
387 break;
388 case 0x2018:
389 ch = '\'';
390 break;
391 case 0x2019:
392 ch = '\'';
393 break;
394 case 0x201c:
395 ch = '"';
396 break;
397 case 0x201d:
398 ch = '"';
399 break;
400 case 0x2022:
401 ch = '>';
402 break;
403 case 0x2013:
404 ch = '-';
405 break;
406 case 0x2014:
407 offset = 0;
408 q[0] = '-';
409 q[1] = 0;
410 ch = '-'; // should be --
411 break;
412 case 0x02dc:
413 ch = '~';
414 break;
415 case 0x0161:
416 ch = 's';
417 break;
418 case 0x203a:
419 ch = '>';
420 break;
421 case 0x0153:
422 offset = 0;
423 q[0] = 'e';
424 q[1] = 0;
425 ch = 'o';// should be oe
426 break;
427 case 0x017e:
428 ch = 'z';
429 break;
430 case 0x0178:
431 ch = 'Y';
432 break;
433 }
434 currentstyle = sty;
435}
436
437void PeanutFormatter::getch(tchar& ch, CStyle& sty)
438{
439 CStyle dummy;
440 currentstyle.setColour(0,0,0);
441 parent->getch(ch, dummy);
442 while (ch == '\\')
443 {
444 parent->getch(ch, dummy);
445 if (ch == '\\') break;
446 switch(ch)
447 {
448 case 'a':
449 {
450 int code = 0;
451 for (int i = 0; i < 3; i++)
452 {
453 parent->getch(ch, dummy);
454 code = 10*code + ch - '0';
455 }
456 ch = code;
457 }
458 break;
459 case 'v':
460 {
461 while (1)
462 {
463 parent->getch(ch, dummy);
464 if (ch == '\\')
465 {
466 parent->getch(ch, dummy);
467 if (ch == 'v')
468 {
469 parent->getch(ch, dummy);
470 break;
471 }
472 }
473 }
474 }
475 break;
476 case 's':
477 case 'n':
478 currentstyle.setFontSize(0);
479 parent->getch(ch,dummy);
480 break;
481 case 'p':
482 currentstyle.unset();
483 // parent->getch(ch,dummy);
484 ch = 10;
485 break;
486 case 'l':
487 if (currentstyle.getFontSize() == 1)
488 {
489 currentstyle.setFontSize(0);
490 }
491 else
492 {
493 currentstyle.setFontSize(1);
494 }
495 parent->getch(ch, dummy);
496 break;
497 case 'x':
498 if (currentstyle.getFontSize() == 0)
499 {
500 // currentstyle.unset();
501 // currentstyle.setBold();
502 currentstyle.setFontSize(1);
503 }
504 else
505 {
506 currentstyle.unset();
507 }
508 // parent->getch(ch, dummy);
509 ch = 10;
510 break;
511 case 'i':
512 if (currentstyle.isItalic())
513 {
514 currentstyle.unsetItalic();
515 }
516 else
517 {
518 currentstyle.setItalic();
519 }
520 parent->getch(ch, dummy);
521 break;
522 case 'b':
523 case 'B':
524 if (currentstyle.isBold())
525 {
526 currentstyle.unsetBold();
527 }
528 else
529 {
530 currentstyle.setBold();
531 }
532 parent->getch(ch, dummy);
533 break;
534 case 'c':
535 if (currentstyle.getJustify() == CStyle::m_AlignCentre)
536 {
537 currentstyle.setLeftJustify();
538 }
539 else
540 {
541 currentstyle.setCentreJustify();
542 }
543 parent->getch(ch, dummy);
544 break;
545 case 'r':
546 if (currentstyle.getJustify() == CStyle::m_AlignRight)
547 {
548 currentstyle.setLeftJustify();
549 }
550 else
551 {
552 currentstyle.setRightJustify();
553 }
554 parent->getch(ch, dummy);
555 break;
556 default:
557 currentstyle.setColour(255,0,0);
558 }
559 }
560 sty = currentstyle;
561}
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 @@
6 6
7class CFilter : public CCharacterSource 7class CFilter : public CCharacterSource
8{ 8{
9 friend class CFilterChain; 9 friend class CFilterChain;
10 protected: 10 protected:
11 CCharacterSource* parent; 11 CCharacterSource* parent;
12public: 12 public:
13 CFilter() : parent(NULL) {} 13 CFilter() : parent(NULL) {}
14 void setparent(CCharacterSource* p) { parent = p; } 14 void setparent(CCharacterSource* p) { parent = p; }
15 virtual ~CFilter() {}; 15 virtual ~CFilter() {};
16};
17
18class vanilla : public CFilter
19{
20public:
21 vanilla() {}
22 virtual ~vanilla() {}
23#ifdef _UNICODE
24 virtual tchar getch()
25#else
26 virtual int getch()
27#endif
28 {
29 return parent->getch();
30 }
31}; 16};
32 17
33class CFilterChain 18class CFilterChain
@@ -49,7 +34,10 @@ class CFilterChain
49 } 34 }
50 delete encoder; 35 delete encoder;
51 } 36 }
52 int getch() { return front->getch(); } 37 void getch(tchar& ch, CStyle& sty)
38 {
39 front->getch(ch, sty);
40 }
53 void addfilter(CFilter* p) 41 void addfilter(CFilter* p)
54 { 42 {
55 if (first == NULL) 43 if (first == NULL)
@@ -79,276 +67,203 @@ class CFilterChain
79 67
80class stripcr : public CFilter 68class stripcr : public CFilter
81{ 69{
82public: 70 public:
83 stripcr() {} 71 stripcr() {}
84 virtual ~stripcr() {} 72 virtual ~stripcr() {}
85#ifdef _UNICODE 73 virtual void getch(tchar& ch, CStyle& sty)
86 virtual tchar getch() 74 {
87 { 75 do
88 tchar ch; 76 {
89 do 77 parent->getch(ch, sty);
90 { 78 }
91 ch = parent->getch(); 79 while (ch == 13);
92 } 80 }
93 while (ch == 13);
94 return ch;
95 }
96#else
97 virtual int getch()
98 {
99 int ch;
100 do
101 {
102 ch = parent->getch();
103 }
104 while (ch == 13);
105 return ch;
106 }
107#endif
108}; 81};
109 82
110class dehyphen : public CFilter 83class dehyphen : public CFilter
111{ 84{
112 bool m_bCharWaiting; 85 bool m_bCharWaiting;
113 tchar m_nextChar; 86 tchar m_nextChar;
87 CStyle m_nextSty;
114 public: 88 public:
115 dehyphen() : m_bCharWaiting(false) {} 89 dehyphen() : m_bCharWaiting(false) {}
116 virtual ~dehyphen() {} 90 virtual ~dehyphen() {}
117 virtual tchar getch() 91 virtual void getch(tchar& ch, CStyle& sty)
118 { 92 {
119 if (m_bCharWaiting) 93 if (m_bCharWaiting)
120 { 94 {
121 m_bCharWaiting = false; 95 m_bCharWaiting = false;
122 return m_nextChar; 96 ch = m_nextChar;
97 sty = m_nextSty;
98 return;
123 } 99 }
124 tchar ch = parent->getch(); 100 parent->getch(ch, sty);
125 if (ch != '-') return ch; 101 if (ch != '-') return;
126 m_nextChar = parent->getch(); 102 parent->getch(m_nextChar, m_nextSty);
127 if (m_nextChar != 10) 103 if (m_nextChar != 10)
128 { 104 {
129 m_bCharWaiting = true; 105 m_bCharWaiting = true;
130 return '-'; 106 ch = '-';
107 return;
131 } 108 }
132 return parent->getch(); 109 parent->getch(ch, sty);
133 } 110 }
134}; 111};
135 112
136class striphtml : public CFilter 113class striphtml : public CFilter
137{ 114{
138public: 115 CStyle currentstyle;
139 striphtml() {} 116 unsigned short skip_ws();
140 virtual ~striphtml() {} 117 unsigned short skip_ws_end();
141#ifdef _UNICODE 118 unsigned short parse_m();
142 virtual tchar getch() 119 void mygetch(tchar& ch, CStyle& sty);
143 { 120 public:
144 tchar ch; 121 striphtml() {}
145 ch = parent->getch(); 122 virtual ~striphtml() {}
146 while (ch == '<') 123 virtual void getch(tchar& ch, CStyle& sty);
147 {
148 while (ch != '>')
149 {
150 ch = parent->getch();
151 }
152 ch = parent->getch();
153 }
154 if (ch == '&')
155 {
156 ch = parent->getch();
157 if (ch == '#')
158 {
159 int id = 0;
160 while ((ch = parent->getch()) != ';') id = 10*id+ch-'0';
161 ch = id;
162 }
163 }
164 return ch;
165 }
166#else
167 virtual int getch()
168 {
169 int ch;
170 ch = parent->getch();
171 while (ch == '<')
172 {
173 while (ch != '>')
174 {
175 ch = parent->getch();
176 }
177 ch = parent->getch();
178 }
179 if (ch == '&')
180 {
181 ch = parent->getch();
182 if (ch == '#')
183 {
184 int id = 0;
185 while ((ch = parent->getch()) != ';') id = 10*id+ch-'0';
186 ch = id;
187 }
188 }
189 return ch;
190 }
191#endif
192}; 124};
193 125
194class unindent : public CFilter 126class unindent : public CFilter
195{ 127{
196 tchar lc; 128 tchar lc;
197public: 129 public:
198 unindent() : lc(0) {} 130 unindent() : lc(0) {}
199 virtual ~unindent() {} 131 virtual ~unindent() {}
200#ifdef _UNICODE 132 virtual void getch(tchar& ch, CStyle& sty)
201 virtual tchar getch() 133 {
202 { 134 if (lc == 10)
203 tchar ch; 135 {
204 if (lc == 10) 136 do
205 { 137 {
206 while ((ch = parent->getch()) == ' '); 138 parent->getch(ch, sty);
207 } 139 }
208 else ch = parent->getch(); 140 while (ch == ' ');
209 lc = ch; 141 }
210 return ch; 142 else parent->getch(ch, sty);
211 } 143 lc = ch;
212#else 144 return;
213 virtual int getch() 145 }
214 {
215 int ch;
216 if (lc == 10)
217 {
218 while ((ch = parent->getch()) == ' ');
219 }
220 else ch = parent->getch();
221 lc = ch;
222 return ch;
223 }
224#endif
225}; 146};
226 147
227#ifdef _UNICODE
228class repara : public CFilter 148class repara : public CFilter
229{ 149{
230 tchar tch; 150 tchar tch;
231public: 151 public:
232 repara() : tch(0) {} 152 repara() : tch(0) {}
233 virtual ~repara() {} 153 virtual ~repara() {}
234 virtual tchar getch() 154 virtual void getch(tchar& ch, CStyle& sty)
235 { 155 {
236 tchar ch = parent->getch(); 156 parent->getch(ch, sty);
237 if (ch == 10) 157 if (ch == 10)
238 { 158 {
239 if (tch == 10) 159 if (tch == 10)
240 { 160 {
241 return ch; 161 return;
242 } 162 }
243 else 163 else
244 { 164 {
245 tch = ch; 165 tch = ch;
246 return ' '; 166 ch = ' ';
247 } 167 return;
248 } 168 }
249 tch = ch; 169 }
250 return ch;
251 }
252};
253#else
254class repara : public CFilter
255{
256 int tch;
257public:
258 repara() : tch(0) {}
259 virtual ~repara() {}
260 virtual int getch()
261 {
262 int ch = parent->getch();
263 if (ch == 10)
264 {
265 if (tch == 10)
266 {
267 return ch;
268 }
269 else
270 {
271 tch = ch; 170 tch = ch;
272 return ' '; 171 return;
273 } 172 }
274 }
275 tch = ch;
276 return ch;
277 }
278}; 173};
279#endif
280 174
281class indenter : public CFilter 175class indenter : public CFilter
282{ 176{
283 int amnt; 177 int amnt;
284 int indent; 178 int indent;
285public: 179 CStyle lsty;
286 indenter(int _a=5) : amnt(_a), indent(0) {} 180 public:
287 virtual ~indenter() {} 181 indenter(int _a=5) : amnt(_a), indent(0) {}
288#ifdef _UNICODE 182 virtual ~indenter() {}
289 virtual tchar getch() 183 virtual void getch(tchar& ch, CStyle& sty)
290 {
291 if (indent > 0)
292 {
293 indent--;
294 return ' ';
295 }
296 tchar ch = parent->getch();
297 if (ch == 10)
298 {
299 indent = amnt;
300 }
301 return ch;
302 }
303#else
304 virtual int getch()
305 {
306 if (indent > 0)
307 {
308 indent--;
309 return ' ';
310 }
311 int ch = parent->getch();
312 if (ch == 10)
313 { 184 {
314 indent = amnt; 185 if (indent > 0)
186 {
187 indent--;
188 ch = ' ';
189 sty = lsty;
190 return;
191 }
192 parent->getch(ch, sty);
193 if (ch == 10)
194 {
195 indent = amnt;
196 lsty = sty;
197 }
198 return;
315 } 199 }
316 return ch;
317 }
318#endif
319}; 200};
320 201
321class dblspce : public CFilter 202class dblspce : public CFilter
322{ 203{
323 bool lastlf; 204 bool lastlf;
324public: 205 CStyle lsty;
325 dblspce() : lastlf(false) {} 206 public:
326 virtual ~dblspce() {} 207 dblspce() : lastlf(false) {}
327#ifdef _UNICODE 208 virtual ~dblspce() {}
328 virtual tchar getch() 209 virtual void getch(tchar& ch, CStyle& sty)
329 {
330 if (lastlf)
331 { 210 {
332 lastlf = false; 211 if (lastlf)
333 return 10; 212 {
213 lastlf = false;
214 ch = 10;
215 sty = lsty;
216 return;
217 }
218 parent->getch(ch, sty);
219 if (lastlf = (ch == 10))
220 {
221 lsty = sty;
222 }
223 return;
334 } 224 }
335 tchar ch = parent->getch(); 225};
336 lastlf = (ch == 10); 226
337 return ch; 227class textfmt : public CFilter
338 } 228{
339#else 229 CStyle currentstyle;
340 virtual int getch() 230 tchar lastchar;
341 { 231 bool uselast;
342 if (lastlf) 232 void mygetch(tchar&, CStyle&);
233 public:
234 textfmt() : lastchar(0), uselast(false) {}
235 virtual ~textfmt() {}
236 virtual void getch(tchar& ch, CStyle& sty);
237};
238
239class embolden : public CFilter
240{
241 public:
242 embolden() {}
243 virtual ~embolden() {}
244 virtual void getch(tchar& ch, CStyle& sty)
343 { 245 {
344 lastlf = false; 246 parent->getch(ch, sty);
345 return 10; 247 sty.setBold();
346 } 248 }
347 int ch = parent->getch();
348 lastlf = (ch == 10);
349 return ch;
350 }
351#endif
352}; 249};
353 250
251class remap : public CFilter
252{
253 tchar q[3];
254 int offset;
255 CStyle currentstyle;
256 public:
257 remap() : offset(0) { q[0] = 0; }
258 virtual ~remap() {}
259 virtual void getch(tchar& ch, CStyle& sty);
260};
261
262class PeanutFormatter : public CFilter
263{
264 CStyle currentstyle;
265 public:
266 virtual ~PeanutFormatter() {}
267 virtual void getch(tchar& ch, CStyle& sty);
268};
354#endif 269#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 @@
1#ifndef __FONTCONTROL_H
2#define __FONTCONTROL_H
3
4#include <qfontdatabase.h>
5#include <qfontmetrics.h>
6#include "StyleConsts.h"
7
8class FontControl
9{
10 int * m_fontsizes;
11 int m_size;
12 QString m_fontname;
13 int m_maxsize;
14 public:
15 FontControl(QString n = "helvetica", int size = 10)
16 :
17 m_fontsizes(NULL)
18 {
19 ChangeFont(n, size);
20 }
21 ~FontControl()
22 {
23 if (m_fontsizes != NULL) delete [] m_fontsizes;
24 }
25 QString name() { return m_fontname; }
26 int currentsize() { return m_fontsizes[m_size]; }
27 int getsize(CStyle size)
28 {
29 return m_fontsizes[m_size+size.getFontSize()];
30 }
31 int ascent()
32 {
33 QFont f(name(), currentsize());
34 QFontMetrics fm(f);
35 return fm.ascent();
36 }
37 int ascent(CStyle ch)
38 {
39 QFont f(name(), getsize(ch));
40 QFontMetrics fm(f);
41 return fm.ascent();
42 }
43 int descent()
44 {
45 QFont f(name(), currentsize());
46 QFontMetrics fm(f);
47 return fm.descent();
48 }
49 int descent(CStyle ch)
50 {
51 QFont f(name(), getsize(ch));
52 QFontMetrics fm(f);
53 return fm.descent();
54 }
55 int lineSpacing()
56 {
57 QFont f(name(), currentsize());
58 QFontMetrics fm(f);
59 return fm.lineSpacing();
60 }
61 int lineSpacing(CStyle ch)
62 {
63 QFont f(name(), getsize(ch));
64 QFontMetrics fm(f);
65 return fm.lineSpacing();
66 }
67 bool decreasesize()
68 {
69 if (--m_size < 0)
70 {
71 m_size = 0;
72 return false;
73 }
74 else return true;
75 }
76 bool increasesize()
77 {
78 if (++m_size >= m_maxsize)
79 {
80 m_size = m_maxsize - 1;
81 return false;
82 }
83 else return true;
84 }
85 bool ChangeFont(QString& n)
86 {
87 return ChangeFont(n, currentsize());
88 }
89 bool ChangeFont(QString& n, int tgt)
90 {
91 QValueList<int>::Iterator it;
92 QFontDatabase fdb;
93 QValueList<int> sizes = fdb.pointSizes(n);
94 if (sizes.count() == 0)
95 {
96 return false;
97 }
98 else
99 {
100 m_fontname = n;
101 m_maxsize = sizes.count();
102 if (m_fontsizes != NULL) delete [] m_fontsizes;
103 m_fontsizes = new int[m_maxsize];
104 uint i = 0;
105 uint best = 0;
106 for (it = sizes.begin(); it != sizes.end(); it++)
107 {
108 m_fontsizes[i] = (*it)/10;
109 if (abs(tgt-m_fontsizes[i]) < abs(tgt-m_fontsizes[best]))
110 {
111 best = i;
112 }
113 i++;
114 }
115 m_size = best;
116 }
117 return true;
118 }
119};
120
121#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 @@
1enum MarkupType
2{
3 cNONE,
4 cTEXT,
5 cHTML,
6 cPML
7};
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 @@
1#ifndef __QFLOATBAR_H
2#define __QFLOATBAR_H
3
4#include <qtoolbar.h>
5
6class QFloatBar : public QToolBar
7{
8 Q_OBJECT
9 virtual void hideEvent(QHideEvent* e)
10 {
11 /*if (e->spontaneous())*/ emit OnHide();
12 }
13 public:
14 QFloatBar(char* t, QMainWindow* mw, QMainWindow::ToolBarDock td, bool f) : QToolBar(t, mw, td, f) {}
15 signals:
16 void OnHide();
17};
18
19#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 @@
8** 8**
9*****************************************************************************/ 9*****************************************************************************/
10 10
11#include <qpainter.h>
11#include "config.h" 12#include "config.h"
12#include "QTReader.h" 13#include "QTReader.h"
13#include "QTReaderApp.h" 14#include "QTReaderApp.h"
15#include "CDrawBuffer.h"
14#include <qpe/qpeapplication.h> 16#include <qpe/qpeapplication.h>
15#include <math.h> 17#include <math.h>
16#include <ctype.h> 18#include <ctype.h>
@@ -36,16 +38,19 @@ const char *QTReader::fonts[] = { "Helvetica", "Courier", "Times", 0 };
36QTReader::QTReader( QWidget *parent=0, const char *name=0, WFlags f = 0) : 38QTReader::QTReader( QWidget *parent=0, const char *name=0, WFlags f = 0) :
37 QWidget(parent, name, f), 39 QWidget(parent, name, f),
38 m_delay(100), 40 m_delay(100),
39 m_scrolldy(0), 41 m_scrolldy1(0),
42 m_scrolldy2(0),
40 m_autoScroll(false), 43 m_autoScroll(false),
41 textarray(NULL), 44 //textarray(NULL),
42 locnarray(NULL), 45 //locnarray(NULL),
43 numlines(0), 46 numlines(0),
44 m_fontname("unifont"), 47 m_fontname("unifont"),
45 m_fm(NULL) 48 m_fm(NULL),
49 mouseUpOn(true),
50 m_twotouch(true),
51 m_touchone(true)
46{ 52{
47 m_overlap = 1; 53 m_overlap = 1;
48 fontsizes = NULL;
49// init(); 54// init();
50} 55}
51/* 56/*
@@ -74,53 +79,163 @@ long QTReader::real_delay()
74 return ( 8976 + m_delay ) / ( m_linespacing * m_linespacing ); 79 return ( 8976 + m_delay ) / ( m_linespacing * m_linespacing );
75} 80}
76 81
77void QTReader::mouseReleaseEvent( QMouseEvent* _e ) 82void QTReader::mousePressEvent( QMouseEvent* _e )
78//void QTReader::mouseDoubleClickEvent( QMouseEvent* _e )
79{ 83{
80 if (textarray != NULL) 84 if (_e->button() == RightButton)
81 { 85 {
82// printf("(%u, %u)\n", _e->x(), _e->y()); 86 mouseUpOn = false;
83 QString wrd = QString::null; 87 if (_e->y() > height()/2)
84 int lineno = _e->y()/m_linespacing; 88 {
85 if (m_bMonoSpaced) 89 goDown();
86 { 90 }
87 int chno = _e->x()/m_charWidth; 91 else
88 if (chno < ustrlen(textarray[lineno]->data())) 92 {
89 { 93 goUp();
90 wrd[0] = textarray[lineno]->data()[chno]; 94 }
91 } 95 }
92 } 96}
93 else 97
94 { 98bool QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt)
95 CBuffer* t = textarray[lineno]; 99{
96 int first = 0; 100 int lineno = 0;
97 while (1) 101 int ht = textarray[0]->lineSpacing();
98 { 102 while ((ht < y) && (lineno < numlines))
99 int i = first+1;
100// while ((*t)[i] != ' ' && (*t)[i] != 0) i++;
101 while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
102 if (m_fm->width(toQString(t->data()), i) > _e->x())
103 { 103 {
104 wrd = toQString(t->data()+first, i - first); 104 ht += textarray[++lineno]->lineSpacing();
105 break;
106 } 105 }
107// while ((*t)[i] == ' ' && (*t)[i] != 0) i++; 106 start = locnarray[lineno];
108 while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; 107 if (m_bMonoSpaced)
109 if ((*t)[i] == 0) break; 108 {
110 first = i; 109 offset = x/m_charWidth;
111 } 110 }
112 } 111 else
113 if (!wrd.isEmpty()) 112 {
114 { 113 int i;
115 QClipboard* cb = QApplication::clipboard(); 114 CDrawBuffer* t = textarray[lineno];
116 cb->setText(wrd); 115 for (i = t->length(); t->width(i) > x; i--);
117 Global::statusMessage(wrd); 116 offset = i;
118 if (!m_targetapp.isEmpty() && !m_targetmsg.isEmpty()) 117 }
119 { 118 return textarray[lineno]->isLink(offset, tgt);
120 QCopEnvelope e(("QPE/Application/"+m_targetapp).utf8(), (m_targetmsg+"(QString)").utf8()); 119}
121 e << wrd; 120
122 } 121void QTReader::setTwoTouch(bool _b)
123 } 122{
123 setBackgroundColor( white );
124 m_twotouch = m_touchone = _b;
125}
126
127void QTReader::mouseReleaseEvent( QMouseEvent* _e )
128{
129 if (_e->button() == LeftButton)
130 {
131 if (mouseUpOn)
132 {
133 if (textarray[0] != NULL)
134 {
135 QString wrd, line;
136 // int lineno = _e->y()/m_linespacing;
137 int lineno = 0;
138 int ht = textarray[0]->lineSpacing();
139 while ((ht < _e->y()) && (lineno < numlines))
140 {
141 ht += textarray[++lineno]->lineSpacing();
142 }
143 size_t startpos, startoffset, tgt;
144 if (getcurrentpos(_e->x(), _e->y(), startpos, startoffset, tgt))
145 {
146 if (buffdoc.hyperlink(tgt))
147 {
148 fillbuffer();
149 update();
150 }
151 else
152 {
153 locate(pagelocate());
154 }
155 return;
156 }
157 if (m_twotouch)
158 {
159 if (m_touchone)
160 {
161 m_touchone = false;
162 m_startpos = startpos;
163 m_startoffset = startoffset;
164 setBackgroundColor( lightGray );
165 }
166 else
167 {
168 m_touchone = true;
169 setBackgroundColor( white );
170 size_t endpos, endoffset;
171 endpos = startpos;
172 endoffset = startoffset;
173 size_t currentpos = locate();
174 if (endpos >= m_startpos)
175 {
176 jumpto(m_startpos);
177 for (int i = 0; i < m_startoffset; i++)
178 {
179 getch();
180 }
181 if (m_startpos == endpos)
182 {
183 for (int i = m_startoffset; i <= endoffset; i++)
184 {
185 wrd += QChar(getch());
186 }
187 }
188 else
189 {
190 while (buffdoc.explocate() <= endpos)
191 {
192 wrd += QChar(getch());
193 }
194 for (int i = 0; i < endoffset; i++)
195 {
196 wrd += QChar(getch());
197 }
198 }
199 jumpto(currentpos);
200 }
201 }
202 }
203 else if (m_bMonoSpaced)
204 {
205 int chno = _e->x()/m_charWidth;
206 if (chno < ustrlen(textarray[lineno]->data()))
207 {
208 wrd[0] = textarray[lineno]->data()[chno];
209 }
210 }
211 else
212 {
213 CDrawBuffer* t = textarray[lineno];
214 int first = 0;
215 while (1)
216 {
217 int i = first+1;
218 while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
219 if (t->width(i) > _e->x())
220 {
221 wrd = toQString(t->data()+first, i - first);
222 break;
223 }
224 while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
225 if ((*t)[i] == 0) break;
226 first = i;
227 }
228 }
229 if (!wrd.isEmpty())
230 {
231 emit OnWordSelected(wrd, locnarray[lineno], (m_twotouch) ? wrd : toQString(textarray[lineno]->data()));
232 }
233 }
234 }
235 else
236 {
237 mouseUpOn = true;
238 }
124 } 239 }
125} 240}
126 241
@@ -134,8 +249,8 @@ void QTReader::focusOutEvent(QFocusEvent* e)
134{ 249{
135 if (m_autoScroll) 250 if (m_autoScroll)
136 { 251 {
137 timer->stop(); 252 timer->stop();
138 m_scrolldy = 0; 253 m_scrolldy1 = m_scrolldy2 = 0;
139 } 254 }
140} 255}
141 256
@@ -147,11 +262,11 @@ void QTReader::goDown()
147{ 262{
148 if (m_bpagemode) 263 if (m_bpagemode)
149 { 264 {
150 dopagedn(); 265 dopagedn();
151 } 266 }
152 else 267 else
153 { 268 {
154 lineDown(); 269 lineDown();
155 } 270 }
156} 271}
157 272
@@ -159,11 +274,11 @@ void QTReader::goUp()
159{ 274{
160 if (m_bpagemode) 275 if (m_bpagemode)
161 { 276 {
162 dopageup(); 277 dopageup();
163 } 278 }
164 else 279 else
165 { 280 {
166 lineUp(); 281 lineUp();
167 } 282 }
168} 283}
169 284
@@ -172,122 +287,115 @@ void QTReader::keyPressEvent(QKeyEvent* e)
172 switch (e->key()) 287 switch (e->key())
173 { 288 {
174 case Key_Down: 289 case Key_Down:
175 { 290 {
176 e->accept(); 291 e->accept();
177 if (m_autoScroll) 292 if (m_autoScroll)
178 { 293 {
179 if (m_delay < 59049) 294 if (m_delay < 59049)
180 { 295 {
181 m_delay = (3*m_delay)/2; 296 m_delay = (3*m_delay)/2;
182 timer->changeInterval(real_delay()); 297 timer->changeInterval(real_delay());
183 } 298 }
184 else 299 else
185 { 300 {
186 m_delay = 59049; 301 m_delay = 59049;
187 } 302 }
188 } 303 }
189 else 304 else
190 { 305 {
191 goDown(); 306 goDown();
192 } 307 }
193 } 308 }
194 break; 309 break;
195 case Key_Up: 310 case Key_Up:
196 { 311 {
197 e->accept(); 312 e->accept();
198 if (m_autoScroll) 313 if (m_autoScroll)
199 { 314 {
200 if (m_delay > 1024) 315 if (m_delay > 1024)
201 { 316 {
202 m_delay = (2*m_delay)/3; 317 m_delay = (2*m_delay)/3;
203 timer->changeInterval(real_delay()); 318 timer->changeInterval(real_delay());
204 } 319 }
205 else 320 else
206 { 321 {
207 m_delay = 1024; 322 m_delay = 1024;
208 } 323 }
209 } 324 }
210 else 325 else
211 { 326 {
212 goUp(); 327 goUp();
213 } 328 }
214 } 329 }
215 break; 330 break;
216 /* 331 /*
217 case Key_Left: 332 case Key_Left:
218 { 333 {
219 e->accept(); 334 e->accept();
220 if (m_textfont > 0) 335 if (m_textfont > 0)
221 { 336 {
222 m_textfont--; 337 m_textfont--;
223 setfont(NULL); 338 setfont(NULL);
224 locate(pagelocate()); 339 locate(pagelocate());
225 update(); 340 update();
226 } 341 }
227 } 342 }
228 break; 343 break;
229 case Key_Right: 344 case Key_Right:
230 { 345 {
231 e->accept(); 346 e->accept();
232 if (fonts[++m_textfont] == 0) 347 if (fonts[++m_textfont] == 0)
233 { 348 {
234 m_textfont--; 349 m_textfont--;
235 } 350 }
236 else 351 else
237 { 352 {
238 setfont(NULL); 353 setfont(NULL);
239 locate(pagelocate()); 354 locate(pagelocate());
240 update(); 355 update();
241 } 356 }
242 } 357 }
243 break; 358 break;
244 */ 359 */
245 case Key_Right: 360 case Key_Right:
246 { 361 {
247 e->accept(); 362 e->accept();
248 if (fontsizes[++m_textsize] == 0) 363 if (m_fontControl.increasesize())
249 { 364 {
250 m_textsize--; 365 bool sc = m_autoScroll;
251 } 366 setfont();
252 else 367 m_autoScroll = false;
253 { 368 locate(pagelocate());
254 bool sc = m_autoScroll; 369 update();
255 m_autoScroll = false; 370 m_autoScroll = sc;
256 setfont(NULL); 371 if (m_autoScroll) autoscroll();
257 locate(pagelocate()); 372 }
258 update(); 373 }
259 m_autoScroll = sc;
260 if (m_autoScroll) autoscroll();
261 }
262 }
263 break; 374 break;
264 case Key_Left: 375 case Key_Left:
265 { 376 {
266 e->accept(); 377 e->accept();
267 if (m_textsize > 0) 378 if (m_fontControl.decreasesize())
268 { 379 {
269 bool sc = m_autoScroll; 380 bool sc = m_autoScroll;
270 m_autoScroll = false; 381 m_autoScroll = false;
271 m_textsize--; 382 setfont();
272 setfont(NULL); 383 locate(pagelocate());
273 locate(pagelocate()); 384 update();
274 update(); 385 m_autoScroll = sc;
275 m_autoScroll = sc; 386 if (m_autoScroll) autoscroll();
276 if (m_autoScroll) autoscroll(); 387 }
277 } 388 }
278 }
279 break; 389 break;
280 case Key_Space: 390 case Key_Space:
281// case Key_Enter: 391 case Key_Return:
282 case Key_Return: 392 {
283 { 393 e->accept();
284 e->accept(); 394 emit OnActionPressed();
285 setautoscroll(!m_autoScroll); 395 }
286 ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll); 396 break;
287 } 397 default:
288 break; 398 e->ignore();
289 default:
290 e->ignore();
291 } 399 }
292} 400}
293 401
@@ -296,24 +404,26 @@ void QTReader::setautoscroll(bool _sc)
296 if (_sc == m_autoScroll) return; 404 if (_sc == m_autoScroll) return;
297 if (m_autoScroll) 405 if (m_autoScroll)
298 { 406 {
299 m_autoScroll = false; 407 m_autoScroll = false;
300 } 408 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
409 }
301 else 410 else
302 { 411 {
303 m_autoScroll = true; 412 m_autoScroll = true;
304 autoscroll(); 413 autoscroll();
414 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; // light is even not dimmed
305 } 415 }
306} 416}
307 417
308bool QTReader::getline(CBuffer *buff) 418bool QTReader::getline(CDrawBuffer *buff)
309{ 419{
310 if (m_bMonoSpaced) 420 if (m_bMonoSpaced)
311 { 421 {
312 return buffdoc.getline(buff ,width(), m_charWidth); 422 return buffdoc.getline(buff ,width(), m_charWidth);
313 } 423 }
314 else 424 else
315 { 425 {
316 return buffdoc.getline(buff, width()); 426 return buffdoc.getline(buff, width());
317 } 427 }
318} 428}
319 429
@@ -321,8 +431,8 @@ void QTReader::doscroll()
321{ 431{
322 if (!m_autoScroll) 432 if (!m_autoScroll)
323 { 433 {
324 timer->stop(); 434 timer->stop();
325 return; 435 return;
326 } 436 }
327// timer->changeInterval(real_delay()); 437// timer->changeInterval(real_delay());
328 QPainter p( this ); 438 QPainter p( this );
@@ -330,48 +440,38 @@ void QTReader::doscroll()
330 bitBlt(this,0,0,this,0,1,width(),-1); 440 bitBlt(this,0,0,this,0,1,width(),-1);
331 qDrawPlainRect(&p,0,height() - 2,width(),2,white,1,&b); 441 qDrawPlainRect(&p,0,height() - 2,width(),2,white,1,&b);
332 442
333 if (++m_scrolldy == m_linespacing) 443 if (++m_scrolldy1 == textarray[0]->lineSpacing())
334 {
335 setfont(&p);
336 m_scrolldy = 0;
337// qDrawPlainRect(&p,0,height() - m_linespacing,width(),m_linespacing,white,1,&b);
338 pagepos = locnarray[1];
339 CBuffer* buff = textarray[0];
340 for (int i = 1; i < numlines; i++)
341 {
342 textarray[i-1] = textarray[i];
343 locnarray[i-1] = locnarray[i];
344 }
345 locnarray[numlines-1] = locate();
346 if (getline(buff))
347 {
348 textarray[numlines-1] = buff;
349 drawText( p, 0, height() - m_descent - 2, buff->data());
350 mylastpos = locate();
351 }
352 else
353 {
354// (*buff)[0] = '\0';
355 textarray[numlines-1] = buff;
356 m_autoScroll = false;
357 ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll);
358 }
359 }
360}
361
362void QTReader::drawText(QPainter& p, int x, int y, tchar* _text)
363{
364 QString text = toQString(_text);
365 if (m_bMonoSpaced)
366 { 444 {
367 for (int i = 0; i < text.length(); i++) 445 CDrawBuffer* buff = textarray[0];
368 { 446 for (int i = 1; i <= numlines; i++)
369 p.drawText( x+i*m_charWidth, y, QString(text[i]) ); 447 {
370 } 448 textarray[i-1] = textarray[i];
449 locnarray[i-1] = locnarray[i];
450 }
451 textarray[numlines] = buff;
452 --numlines;
453 m_scrolldy1 = 0;
371 } 454 }
372 else 455 if (++m_scrolldy2 == textarray[numlines]->lineSpacing())
373 { 456 {
374 p.drawText( x, y, text ); 457 m_scrolldy2 = 0;
458 numlines++;
459
460 if (textarray[numlines] == NULL)
461 {
462 textarray[numlines] = new CDrawBuffer;
463 }
464 locnarray[numlines] = locate();
465 int ch = getline(textarray[numlines]);
466 textarray[numlines-1]->render(&p, height() - textarray[numlines]->descent() - 2, m_bMonoSpaced, m_charWidth, width());
467 mylastpos = locate();
468 if (!ch)
469 {
470 m_autoScroll = false;
471 ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll);
472 emit OnRedraw();
473 }
474 emit OnRedraw();
375 } 475 }
376} 476}
377 477
@@ -380,135 +480,117 @@ void QTReader::autoscroll()
380 timer->start(real_delay(), false); 480 timer->start(real_delay(), false);
381} 481}
382 482
383void QTReader::setfont(QPainter* p) 483void QTReader::setfont()
384{ 484{
385 // qDebug("Fontsize = %u",fontsizes[m_textsize]); 485// m_fontControl.Change
386 // qDebug("SetFont %x",p); 486 m_charWidth = (m_charpc*m_fontControl.currentsize())/100;
387 QFont font(m_fontname, fontsizes[m_textsize], (m_bBold) ? QFont::Bold : QFont::Normal );
388 m_charWidth = (m_charpc*fontsizes[m_textsize])/100;
389 if (m_charWidth <= 0) m_charWidth = 1; 487 if (m_charWidth <= 0) m_charWidth = 1;
390// font.setFixedPitch(m_bMonoSpaced); 488 m_ascent = m_fontControl.ascent();
391// qDebug("Raw name = %s", (const char*)font.rawName()); 489 m_descent = m_fontControl.descent();
392 if (p != NULL) p->setFont( font ); 490 m_linespacing = m_fontControl.lineSpacing();
393 if (m_fm == NULL)
394 {
395 m_fm = new QFontMetrics(font);
396 buffdoc.setfm(m_fm);
397 }
398 else
399 {
400 *m_fm = QFontMetrics(font);
401 }
402 m_ascent = m_fm->ascent();
403 m_descent = m_fm->descent();
404 m_linespacing = m_fm->lineSpacing();
405} 491}
406 492
407void QTReader::drawFonts( QPainter *p ) 493void QTReader::drawFonts( QPainter *p )
408{ 494{
409 setfont(p); 495 setfont();
410 if (m_lastwidth != width()) 496 if (m_lastwidth != width() || m_lastheight != height())
411 { 497 {
412 m_lastwidth = width(); 498 m_lastwidth = width();
413 locate(pagepos); 499 m_lastheight = height();
500 locate(pagelocate());
414 } 501 }
415 else 502 else
416 { 503 {
504
505/*
417 int sl = screenlines(); 506 int sl = screenlines();
418 if (sl < numlines) 507 if (sl < numlines)
419 { 508 {
420// qDebug("df:<%u,%u>",sl,numlines); 509 //qDebug("df:<%u,%u>",sl,numlines);
421 510
422 size_t newpos = locnarray[sl]; 511 size_t newpos = locnarray[sl];
423 CBuffer** nta = new CBuffer*[sl]; 512 CDrawBuffer** nta = new CDrawBuffer*[sl];
424 size_t* nla = new size_t[sl]; 513 size_t* nla = new size_t[sl];
425 for (int i = 0; i < sl; i++) 514 for (int i = 0; i < sl; i++)
426 { 515 {
427 nta[i] = textarray[i]; 516 nta[i] = textarray[i];
428 nla[i] = locnarray[i]; 517 nla[i] = locnarray[i];
429 } 518 }
430 for (int i = sl; i < numlines; i++) delete textarray[i]; 519 for (int i = sl; i < numlines; i++) delete textarray[i];
431 delete [] textarray; 520 delete [] locnarray;
432 delete [] locnarray; 521 delete [] textarray;
433 textarray = nta; 522 textarray = nta;
434 locnarray = nla; 523 locnarray = nla;
435 numlines = sl; 524 numlines = sl;
436 jumpto(mylastpos = newpos); 525 jumpto(mylastpos = newpos);
437// locate(pagepos);
438 } 526 }
439 if (sl > numlines) 527 if (sl > numlines)
440 { 528 {
441// qDebug("df:<%u,%u>",sl,numlines); 529 //qDebug("df:<%u,%u>",sl,numlines);
442 CBuffer** nta = new CBuffer*[sl]; 530 CDrawBuffer** nta = new CDrawBuffer*[sl];
443 size_t* nla = new size_t[sl]; 531 size_t* nla = new size_t[sl];
444 for (int i = 0; i < numlines; i++) 532 for (int i = 0; i < numlines; i++)
445 { 533 {
446 nta[i] = textarray[i]; 534 nta[i] = textarray[i];
447 nla[i] = locnarray[i]; 535 nla[i] = locnarray[i];
448 } 536 }
449 if (locate() != mylastpos) jumpto(mylastpos); 537 if (locate() != mylastpos) jumpto(mylastpos);
450 for (int i = numlines; i < sl; i++) 538 for (int i = numlines; i < sl; i++)
451 { 539 {
452 nta[i] = new CBuffer; 540 nta[i] = new CDrawBuffer(&m_fontControl);
453 nla[i] = locate(); 541 nla[i] = locate();
454 getline(nta[i]); 542 getline(nta[i]);
455 } 543 }
456 mylastpos = locate(); 544 mylastpos = locate();
457 delete [] textarray; 545 delete [] locnarray;
458 delete [] locnarray; 546 delete [] textarray;
459 textarray = nta; 547 textarray = nta;
460 locnarray = nla; 548 locnarray = nla;
461 numlines = sl; 549 numlines = sl;
462 } 550 }
463 int ypos = (btight) ? 0 : m_ascent-m_linespacing; 551*/
464 // int linespacing = (tight) ? m_ascent : m_ascent+m_descent; 552 if (numlines > 0)
465 for (int i = 0; i < numlines; i++) 553 {
554 int ypos = textarray[0]->ascent();
555 textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, width());
556 for (int i = 1; i < numlines; i++)
466 { 557 {
467 drawText( *p, 0, ypos += m_linespacing, textarray[i]->data()); 558 ypos += (textarray[i-1]->lineSpacing() + textarray[i]->lineSpacing())/2;
559 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, width());
560
561 }
562// mylastpos = locate();
468 } 563 }
469 /*
470
471
472
473 int nlines = height()/(fontmetric.ascent()+fontmetric.descent());
474 tchar buffer[1024];
475 for (int i = 0; i < nlines; i++)
476 {
477 y += fontmetric.ascent();
478 sprintf(buffer, "%d:%d:%s[%d]:Lines %d:%s", i+1, m_textfont, fonts[m_textfont], m_fs, nlines, (const tchar*)m_string);
479 drawText( *p, 0, y, buffer );
480 y += fontmetric.descent();
481 }
482 */
483 } 564 }
484 m_scrolldy = 0; 565 m_scrolldy1 = m_scrolldy2 = 0;
566 emit OnRedraw();
485} 567}
486 568
487QString QTReader::firstword() 569QString QTReader::firstword()
488{ 570{
489 if (m_bMonoSpaced) 571 if (m_bMonoSpaced)
490 { 572 {
491 return toQString(textarray[0]->data()); 573 return toQString(textarray[0]->data());
492 } 574 }
493 else 575 else
494 { 576 {
495 int start, end, len, j; 577 int start, end, len, j;
496 for (j = 0; j < numlines; j++) 578 for (j = 0; j < numlines; j++)
497 { 579 {
498 len = textarray[j]->length(); 580 len = textarray[j]->length();
499 for (start = 0; start < len && !isalpha((*textarray[j])[start]); start++); 581 for (start = 0; start < len && !isalpha((*textarray[j])[start]); start++);
500 if (start < len) break; 582 if (start < len) break;
501 } 583 }
502 if (j < numlines) 584 if (j < numlines)
503 { 585 {
504 QString ret = ""; 586 QString ret = "";
505 for (end = start; end < len && isalpha((*textarray[j])[end]); end++) 587 for (end = start; end < len && isalpha((*textarray[j])[end]); end++)
506 ret += (*textarray[j])[end]; 588 ret += (*textarray[j])[end];
507 if (ret.isEmpty()) ret = "Current position"; 589 if (ret.isEmpty()) ret = "Current position";
508 return ret; 590 return ret;
509 } 591 }
510 else 592 else
511 return "Current position"; 593 return "Current position";
512 } 594 }
513} 595}
514 596
@@ -516,44 +598,9 @@ QString QTReader::firstword()
516// Construct the QTReader with buttons. 598// Construct the QTReader with buttons.
517// 599//
518 600
519void QTReader::ChangeFont(int tgt) 601bool QTReader::ChangeFont(int tgt)
520{ 602{
521 603 return m_fontControl.ChangeFont(m_fontname, tgt);
522 QValueList<int>::Iterator it;
523
524// QValueList<int> sizes = QFontDatabase::pointSizes(m_fontname, (m_bBold) ? QFont::Bold : QFont::Normal);
525 QFontDatabase fdb;
526/*
527 QStringList styles = fdb.styles(m_fontname);
528 for ( QStringList::Iterator it = styles.begin(); it != styles.end(); ++it )
529 {
530 printf( "%s \n", (*it).latin1() );
531 }
532*/
533 QValueList<int> sizes = fdb.pointSizes(m_fontname, (m_bBold) ? QString("Bold") : QString::null);
534 uint n = sizes.count();
535 if (fontsizes != NULL) delete [] fontsizes;
536 fontsizes = new unsigned int[n+1];
537 uint i = 0;
538 uint best = 0;
539 for (it = sizes.begin(); it != sizes.end(); it++)
540 {
541 fontsizes[i] = (*it)/10;
542 if (abs(tgt-fontsizes[i]) < abs(tgt-fontsizes[best]))
543 {
544 best = i;
545 }
546 i++;
547 }
548 m_textsize = best;
549 fontsizes[i] = 0;
550 setfont(NULL);
551 QFont font(m_fontname, fontsizes[m_textsize], (m_bBold) ? QFont::Bold : QFont::Normal );
552 if (m_fm == NULL)
553 {
554 m_fm = new QFontMetrics(font);
555 buffdoc.setfm(m_fm);
556 }
557} 604}
558 605
559void QTReader::init() 606void QTReader::init()
@@ -565,17 +612,19 @@ void QTReader::init()
565// p.setBackgroundMode( Qt::OpaqueMode ); 612// p.setBackgroundMode( Qt::OpaqueMode );
566 buffdoc.setfilter(getfilter()); 613 buffdoc.setfilter(getfilter());
567 ChangeFont(m_textsize); 614 ChangeFont(m_textsize);
568 // setFocusPolicy(QWidget::StrongFocus); 615 setFocusPolicy(QWidget::StrongFocus);
569 // resize( 240, 320 ); 616 // resize( 240, 320 );
570 //setFocus(); 617 //setFocus();
571 timer = new QTimer(this); 618 timer = new QTimer(this);
572 connect(timer, SIGNAL(timeout()), this, SLOT(doscroll())); 619 connect(timer, SIGNAL(timeout()), this, SLOT(doscroll()));
573// QMessageBox::information(this, "init", m_lastfile, 1); 620// QMessageBox::information(this, "init", m_lastfile, 1);
574 m_lastwidth = width(); 621 m_lastwidth = width();
622 m_lastheight = height();
623 setfont();
575 if (!m_lastfile.isEmpty()) 624 if (!m_lastfile.isEmpty())
576 { 625 {
577 m_string = DocLnk(m_lastfile).name(); 626 m_string = DocLnk(m_lastfile).name();
578 load_file(m_lastfile); 627 load_file(m_lastfile);
579 } 628 }
580} 629}
581 630
@@ -584,10 +633,6 @@ void QTReader::init()
584// 633//
585QTReader::~QTReader() 634QTReader::~QTReader()
586{ 635{
587 if (fontsizes != NULL) delete [] fontsizes;
588#ifndef QT_NO_PRINTER
589 // delete printer;
590#endif
591} 636}
592 637
593// 638//
@@ -672,163 +717,156 @@ unsigned int QTReader::screenlines()
672 return (height()-2)/(m_linespacing); 717 return (height()-2)/(m_linespacing);
673}; 718};
674 719
675bool QTReader::fillbuffer() { 720bool QTReader::fillbuffer(int reuse, int ht)
676 if (buffdoc.empty()) return false; 721{
677 //printf("Fillbuffer\n"); 722 if (buffdoc.empty()) return false;
678 m_scrolldy = 0; 723 m_scrolldy1 = m_scrolldy2 = 0;
679 int ch; 724 int ch;
680 bool ret = false; 725 bool ret = false;
681 int delta = screenlines(); 726 unsigned int oldpagepos = locnarray[reuse];
682 // qDebug("fillbuffer:%u-%u",delta,numlines); 727 int ypos = ht;
683 if (delta != numlines) 728 numlines = reuse;
684 { 729 while (ypos < height())
685 if (textarray != NULL)
686 {
687 for (int i = 0; i < numlines; i++) delete textarray[i];
688 delete [] textarray;
689 delete [] locnarray;
690 }
691 numlines = delta;
692 textarray = new CBuffer*[numlines];
693 locnarray = new size_t[numlines];
694 for (int i = 0; i < numlines; i++) textarray[i] = new CBuffer;
695 }
696 // qDebug("fillbuffer:pagepos:%u",pagepos);
697 unsigned int oldpagepos = pagepos;
698// if (textarray != NULL)
699// pagepos = locnarray[0];
700// else
701 pagepos = locate();
702 for (int i = 0; i < delta; i++)
703 { 730 {
704 locnarray[i] = locate(); 731 if (textarray[numlines] == NULL)
705 ch = getline(textarray[i]); 732 {
706 // if (ch == EOF) { 733 textarray[numlines] = new CDrawBuffer(&m_fontControl);
707 if (!ch) 734 }
708 { 735 locnarray[numlines] = locate();
709 if (i == 0) 736 int ch = getline(textarray[numlines]);
710 { 737 ypos += textarray[numlines]->lineSpacing();
711 locate(oldpagepos); 738 numlines++;
712 return false; 739 if (!ch)
713 } 740 {
714 else 741 if (numlines - reuse == 1/* && locnarray[0] == buffdoc.locate()*/)
715 { 742 {
716 ret = true; 743 locate(oldpagepos);
717 for (int j = i+1; j < delta; j++) 744 return false;
718 { 745 }
719 locnarray[j] = locnarray[j-1]; 746 else
720 (*(textarray[j]))[0] = '\0'; 747 {
721 } 748 --numlines;
722 break; 749 mylastpos = locate();
723 } 750 return true;
724 } 751 }
725 if (ch == '\012') ret = true; 752 }
726 } 753 }
727 mylastpos = locate(); 754
728 // qDebug("fillbuffer:lastpos:%u",mylastpos); 755 --numlines;
729 return true; 756 mylastpos = locate();
757
758 return true;
730} 759}
731 760
732 761
733void QTReader::dopagedn() 762void QTReader::dopagedn()
734{ 763{
735 if (m_overlap == 0) 764 int skip = 0, ypos = 0;
765 if (locate() != mylastpos)
736 { 766 {
737 if (locate() != mylastpos) jumpto(mylastpos); 767 //qDebug("Jumping to %u", mylastpos);
768 jumpto(mylastpos);
738 } 769 }
739 else 770 CDrawBuffer* reusebuffer = textarray[numlines];
771 if (reusebuffer != NULL)
740 { 772 {
741 if (m_overlap >= screenlines()) m_overlap = screenlines()/2; 773 for (int i = 0; i <= m_overlap; i++)
742 jumpto(locnarray[screenlines()-m_overlap]); 774 {
775 int offset = numlines - m_overlap + i;
776 reusebuffer = textarray[offset];
777 size_t reuselocn = locnarray[offset];
778 textarray[offset] = textarray[i];
779 textarray[i] = reusebuffer;
780 locnarray[offset] = locnarray[i];
781 locnarray[i] = reuselocn;
782 ypos += textarray[i]->lineSpacing();
783 skip++;
784 }
743 } 785 }
744 if (fillbuffer()) 786 if (fillbuffer(skip, ypos))
745 { 787 {
746 update(); 788 update();
747 } 789 }
748} 790}
749 791
750void QTReader::dopageup() 792void QTReader::dopageup()
751{ 793{
752 CBuffer** buff = textarray; 794 CBufferFace<CDrawBuffer*> buff;
753 unsigned int *loc = new unsigned int[numlines]; 795 CBufferFace<size_t> loc;
754 int cbptr = 0; 796 unsigned int target = locnarray[(m_overlap < numlines) ? m_overlap : numlines/2];
755 if (locate() != mylastpos) jumpto(mylastpos); 797
756 if (m_overlap >= screenlines()) m_overlap = screenlines()/2; 798 size_t delta;
757 unsigned int target = locnarray[m_overlap]; 799 if (target < 2048)
758 if (buffdoc.hasrandomaccess())
759 {
760 unsigned int delta = locate()-pagelocate();
761 if (delta < 64) delta = 64;
762 if (delta % 2 != 0) delta++;
763 if (target % 2 != 0) target++;
764 do
765 { 800 {
766 delta <<= 1; 801 delta = target;
767 if (delta >= target) 802 jumpto(0);
768 { 803 }
769 delta = target; 804 else
770 jumpto(0); 805 {
771 for (int i = 0; i < numlines; i++) 806 delta = 2048;
772 { 807
773 loc[i] = locate(); 808 jumpto(target - delta);
774 getline(buff[i]); 809
775 } 810 buff[0] = new CDrawBuffer(&m_fontControl);
776 break; 811
777 } 812 do
778 jumpto(target-delta);
779 do
780 {
781 getline(buff[0]);
782#ifdef WS
783 //printf("Trying:%s\n",buff[0]);
784#endif
785 if (locate() > target) continue;
786 }
787 while (!buffdoc.iseol());
788 for (int i = 0; i < numlines; i++)
789 { 813 {
790 loc[i] = locate(); 814
791 getline(buff[i]); 815 if (!getline(buff[0])) break;
792#ifdef WS 816
793 //printf("Filling:%s\n",buff[i]); 817 if (locate() > target) continue;
794#endif
795 } 818 }
819 while (!buffdoc.iseol());
796 } 820 }
797 while (locate() >= target && delta < 4096); 821 int nbfl = 0;
798#ifdef WS 822
799 //printf("Delta:%u\n",delta); 823 bool ch = true;
800#endif 824 int ypos = 0;
801 } 825 while (locate() < target)
802 else
803 {
804 jumpto(0);
805 for (int i = 0; i < numlines; i++)
806 { 826 {
807 loc[i] = locate(); 827 if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl);
808 getline(buff[i]); 828 loc[nbfl] = locate();
829 ch = getline(buff[nbfl]);
830 ypos += buff[nbfl]->lineSpacing();
831 nbfl++;
832 if (!ch) break;
809 } 833 }
810 } 834 if (ypos < height())
811 cbptr = 0; 835 {
812 while (locate() < target) 836 locate(0);
813 { 837 return;
814 loc[cbptr] = locate(); 838 }
815 getline(buff[cbptr]); 839 if (ch)
816#ifdef WS 840 {
817 //printf("Adding:%s\n",buff[cbptr]->data()); 841 if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl);
818#endif 842 loc[nbfl] = locate();
819 cbptr = (cbptr+1) % numlines; 843 int ch = getline(buff[nbfl]);
820 } 844 nbfl++;
821 pagepos = loc[cbptr]; 845 }
822 textarray = new CBuffer*[numlines]; 846 ypos = 0;
823 for (int i = 0; i < numlines; i++) 847 numlines = 0;
824 { 848 while (ypos < height() && numlines <= nbfl-2)
825 int j = (cbptr+i)%numlines; 849 {
826 textarray[i] = buff[j]; 850 ypos += buff[nbfl - numlines - 2]->lineSpacing();
827 locnarray[i] = loc[j]; 851 numlines++;
828 } 852 }
829 delete [] buff; 853 --numlines;
830 delete [] loc; 854 int offset = nbfl;
855 offset -= numlines+1;
856 for (int i = 0; i <= numlines; i++)
857 {
858 delete textarray[i];
859 textarray[i] = buff[offset+i];
860 locnarray[i] = loc[offset + i];
861 }
862 for (int i = 0; i < nbfl - numlines - 1; i++)
863 {
864 delete buff[i];
865 }
866
867// --numlines;
831 mylastpos = locate(); 868 mylastpos = locate();
869
832 update(); 870 update();
833} 871}
834 872
@@ -852,6 +890,7 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn)
852 locate(lcn); 890 locate(lcn);
853 // qDebug("buffdoc.locate done"); 891 // qDebug("buffdoc.locate done");
854 } 892 }
893 setfilter(getfilter());
855 update(); 894 update();
856 // qDebug("Updated"); 895 // qDebug("Updated");
857 return bRC; 896 return bRC;
@@ -859,23 +898,33 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn)
859 898
860void QTReader::lineDown() 899void QTReader::lineDown()
861{ 900{
862 pagepos = locnarray[1]; 901 int ypos = 0;
863 CBuffer* buff = textarray[0]; 902 int offset = numlines;
864 for (int i = 1; i < numlines; i++) 903
904 for (int i = 0; i <= numlines; i++)
865 { 905 {
866 textarray[i-1] = textarray[i]; 906 if ((ypos += textarray[numlines-i]->lineSpacing()) > height())
867 locnarray[i-1] = locnarray[i]; 907 {
908 offset = i-1;
909 break;
910 }
868 } 911 }
869 locnarray[numlines-1] = locate(); 912 offset = numlines - offset;
870 if (getline(buff)) 913 for (int i = offset; i <= numlines; i++)
871 { 914 {
872 textarray[numlines-1] = buff; 915 CDrawBuffer* buff = textarray[i-offset];
873 mylastpos = locate(); 916 textarray[i-offset] = textarray[i];
917 locnarray[i-offset] = locnarray[i];
918 textarray[i] = buff;
874 } 919 }
875 else 920 numlines = numlines - offset + 1;
921 locnarray[numlines] = locate();
922 if (textarray[numlines] == NULL)
876 { 923 {
877 textarray[numlines-1] = buff; 924 textarray[numlines] = new CDrawBuffer(&m_fontControl);
878 } 925 }
926 getline(textarray[numlines]);
927 mylastpos = locate();
879 update(); 928 update();
880} 929}
881/* 930/*
@@ -891,38 +940,38 @@ void QTReader::lineUp()
891 unsigned int delta = locate()-pagelocate(); 940 unsigned int delta = locate()-pagelocate();
892 if (delta < 64) delta = 64; 941 if (delta < 64) delta = 64;
893 do 942 do
894 { 943 {
895 delta <<= 1; 944 delta <<= 1;
896 if (delta >= target) 945 if (delta >= target)
897 { 946 {
898 delta = target; 947 delta = target;
899 jumpto(0); 948 jumpto(0);
900 for (int i = 0; i < numlines; i++) 949 for (int i = 0; i < numlines; i++)
901 { 950 {
902 loc[i] = locate(); 951 loc[i] = locate();
903 getline(buff[i]); 952 getline(buff[i]);
904 } 953 }
905 break; 954 break;
906 } 955 }
907 jumpto(target-delta); 956 jumpto(target-delta);
908 do 957 do
909 { 958 {
910 buffdoc.getline(buff[0],width()); 959 buffdoc.getline(buff[0],width());
911#ifdef WS 960#ifdef WS
912 //printf("Trying:%s\n",buff[0]); 961 //printf("Trying:%s\n",buff[0]);
913#endif 962#endif
914 if (locate() > target) continue; 963 if (locate() > target) continue;
915 } 964 }
916 while (!buffdoc.iseol()); 965 while (!buffdoc.iseol());
917 for (int i = 0; i < numlines; i++) 966 for (int i = 0; i < numlines; i++)
918 { 967 {
919 loc[i] = locate(); 968 loc[i] = locate();
920 buffdoc.getline(buff[i],width()); 969 buffdoc.getline(buff[i],width());
921#ifdef WS 970#ifdef WS
922 //printf("Filling:%s\n",buff[i]); 971 //printf("Filling:%s\n",buff[i]);
923#endif 972#endif
924 } 973 }
925 } 974 }
926 while (locate() >= target && delta < 4096); 975 while (locate() >= target && delta < 4096);
927#ifdef WS 976#ifdef WS
928 //printf("Delta:%u\n",delta); 977 //printf("Delta:%u\n",delta);
@@ -932,10 +981,10 @@ void QTReader::lineUp()
932 { 981 {
933 jumpto(0); 982 jumpto(0);
934 for (int i = 0; i < numlines; i++) 983 for (int i = 0; i < numlines; i++)
935 { 984 {
936 loc[i] = locate(); 985 loc[i] = locate();
937 buffdoc.getline(buff[i],width()); 986 buffdoc.getline(buff[i],width());
938 } 987 }
939 } 988 }
940 cbptr = 0; 989 cbptr = 0;
941 while (locate() < target) 990 while (locate() < target)
@@ -963,43 +1012,41 @@ void QTReader::lineUp()
963*/ 1012*/
964void QTReader::lineUp() 1013void QTReader::lineUp()
965{ 1014{
966 CBuffer* buff = textarray[numlines-1]; 1015 CDrawBuffer* buff = textarray[numlines];
967 unsigned int loc; 1016 unsigned int loc;
968 unsigned int end = locnarray[numlines-1]; 1017 unsigned int end = locnarray[numlines];
969 int cbptr = 0; 1018 int cbptr = 0;
970 if (locate() != mylastpos) jumpto(mylastpos); 1019 if (locate() != mylastpos) jumpto(mylastpos);
971 unsigned int target = locnarray[0]; 1020 unsigned int target = locnarray[0];
1021 if (target == 0) return;
972 if (buffdoc.hasrandomaccess()) 1022 if (buffdoc.hasrandomaccess())
973 { 1023 {
974 unsigned int delta = locate()-pagelocate(); 1024 unsigned int delta = locate()-pagelocate();
975 if (delta < 64) delta = 64; 1025 if (delta < 64) delta = 64;
976 do 1026 do
977 { 1027 {
978 delta <<= 1; 1028 delta <<= 1;
979 if (delta >= target) 1029 if (delta >= target)
980 { 1030 {
981 delta = target; 1031 delta = target;
982 jumpto(0); 1032 jumpto(0);
983 for (int i = 0; i < numlines; i++) 1033 loc = locate();
984 { 1034 getline(buff);
985 loc = locate(); 1035 break;
986 getline(buff); 1036 }
987 } 1037 jumpto(target-delta);
988 break; 1038 do
989 } 1039 {
990 jumpto(target-delta); 1040 getline(buff);
991 do
992 {
993 getline(buff);
994#ifdef WS 1041#ifdef WS
995 //printf("Trying:%s\n",buff[0]); 1042 //printf("Trying:%s\n",buff[0]);
996#endif 1043#endif
997 if (locate() > target) continue; 1044 if (locate() > target) continue;
998 } 1045 }
999 while (!buffdoc.iseol()); 1046 while (!buffdoc.iseol());
1000 loc = locate(); 1047 loc = locate();
1001 getline(buff); 1048 getline(buff);
1002 } 1049 }
1003 while (locate() >= target && delta < 4096); 1050 while (locate() >= target && delta < 4096);
1004 } 1051 }
1005 else 1052 else
@@ -1014,18 +1061,27 @@ void QTReader::lineUp()
1014 loc = locate(); 1061 loc = locate();
1015 getline(buff); 1062 getline(buff);
1016 } 1063 }
1017 pagepos = loc; 1064 for (int i = numlines; i > 0; i--)
1018 for (int i = numlines-1; i > 0; i--)
1019 { 1065 {
1020 textarray[i] = textarray[i-1]; 1066 textarray[i] = textarray[i-1];
1021 locnarray[i] = locnarray[i-1]; 1067 locnarray[i] = locnarray[i-1];
1022 } 1068 }
1023 textarray[0] = buff; 1069 textarray[0] = buff;
1024 locnarray[0] = loc; 1070 locnarray[0] = loc;
1025// delete [] buff; 1071 int start = numlines;
1026// delete [] loc; 1072 int ypos = 0;
1027 mylastpos = locate(); 1073 for (int i = 0; i <= numlines; i++)
1028 jumpto(end); 1074 {
1075 ypos += textarray[i]->lineSpacing();
1076 if (ypos > height())
1077 {
1078 start = i;
1079 ypos -= textarray[i]->lineSpacing();
1080 break;
1081 }
1082 }
1083 jumpto(locnarray[start]);
1084 fillbuffer(start, ypos);
1029 update(); 1085 update();
1030} 1086}
1031 1087
@@ -1033,3 +1089,21 @@ bool QTReader::empty()
1033{ 1089{
1034 return buffdoc.empty(); 1090 return buffdoc.empty();
1035} 1091}
1092
1093MarkupType QTReader::PreferredMarkup()
1094{
1095 MarkupType m = buffdoc.PreferredMarkup();
1096 if (m == cTEXT)
1097 {
1098 int ext = m_lastfile.findRev('.');
1099 if (ext >= 0)
1100 {
1101 QString ft = m_lastfile.right(m_lastfile.length()-ext-1).upper();
1102 if (ft.left(3) == "HTM")
1103 {
1104 m = cHTML;
1105 }
1106 }
1107 }
1108 return m;
1109}
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 @@
2#define __QTREADER_H 2#define __QTREADER_H
3 3
4#include <qwidget.h> 4#include <qwidget.h>
5#include <qpainter.h> 5//#include <qpainter.h>
6#include <qclipboard.h>
7#include "CBuffer.h"
8#include "my_list.h" 6#include "my_list.h"
9#include "BuffDoc.h" 7#include "BuffDoc.h"
10#include <qtimer.h> 8#include "FontControl.h"
9
10//#include <qtimer.h>
11
12class CDrawBuffer;
13//class CBuffer;
14class QPainter;
15class QTimer;
11 16
12class QTReader : public QWidget 17class QTReader : public QWidget
13{ 18{
@@ -20,13 +25,14 @@ class QTReader : public QWidget
20 bool m_autoScroll; 25 bool m_autoScroll;
21 void autoscroll(); 26 void autoscroll();
22 QTimer* timer; 27 QTimer* timer;
23 int m_scrolldy, m_encd; 28 int m_scrolldy1, m_scrolldy2, m_encd;
24 void focusInEvent(QFocusEvent*); 29 void focusInEvent(QFocusEvent*);
25 void focusOutEvent(QFocusEvent*); 30 void focusOutEvent(QFocusEvent*);
26 void ChangeFont(int); 31 bool ChangeFont(int);
27 bool getline(CBuffer*); 32 bool getline(CDrawBuffer*);
28 int m_charWidth; 33 int m_charWidth;
29 int m_charpc; 34 int m_charpc;
35 FontControl m_fontControl;
30public: 36public:
31 QTReader( QWidget *parent=0, const char *name=0, WFlags f = 0); 37 QTReader( QWidget *parent=0, const char *name=0, WFlags f = 0);
32 // QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0); 38 // QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0);
@@ -66,6 +72,37 @@ public:
66 } 72 }
67 }; 73 };
68 */ 74 */
75 void setpeanut(bool _b)
76 {
77 bpeanut = _b;
78 setfilter(getfilter());
79 }
80 void setremap(bool _b)
81 {
82 bremap = _b;
83 setfilter(getfilter());
84 }
85 void setmakebold(bool _b)
86 {
87 bmakebold = _b;
88 setfilter(getfilter());
89 }
90 void setautofmt(bool _b)
91 {
92 bautofmt = _b;
93 if (bautofmt)
94 {
95 btextfmt = false;
96 bstriphtml = false;;
97 bpeanut = false;
98 }
99 setfilter(getfilter());
100 }
101 void settextfmt(bool _b)
102 {
103 btextfmt = _b;
104 setfilter(getfilter());
105 }
69 void setstripcr(bool _b) 106 void setstripcr(bool _b)
70 { 107 {
71 bstripcr = _b; 108 bstripcr = _b;
@@ -113,14 +150,15 @@ public:
113 void setmono(bool _b) 150 void setmono(bool _b)
114 { 151 {
115 m_bMonoSpaced = _b; 152 m_bMonoSpaced = _b;
116 ChangeFont(fontsizes[m_textsize]); 153 ChangeFont(m_fontControl.currentsize());
117 locate(pagepos); 154 locate(pagelocate());
118 } 155 }
119 void setencoding(int _f) 156 void setencoding(int _f)
120 { 157 {
121 m_encd = _f; 158 m_encd = _f;
122 setfilter(getfilter()); 159 setfilter(getfilter());
123 } 160 }
161 MarkupType PreferredMarkup();
124 CEncoding* getencoding() 162 CEncoding* getencoding()
125 { 163 {
126 switch (m_encd) 164 switch (m_encd)
@@ -144,12 +182,18 @@ public:
144 { 182 {
145 CFilterChain * filt = new CFilterChain(getencoding()); 183 CFilterChain * filt = new CFilterChain(getencoding());
146 if (bstripcr) filt->addfilter(new stripcr); 184 if (bstripcr) filt->addfilter(new stripcr);
147 if (bstriphtml) filt->addfilter(new striphtml); 185
186 if (btextfmt || (bautofmt && (PreferredMarkup() == cTEXT))) filt->addfilter(new textfmt);
187 if (bpeanut || (bautofmt && (PreferredMarkup() == cPML))) filt->addfilter(new PeanutFormatter);
188 if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new striphtml);
189
148 if (bdehyphen) filt->addfilter(new dehyphen); 190 if (bdehyphen) filt->addfilter(new dehyphen);
149 if (bunindent) filt->addfilter(new unindent); 191 if (bunindent) filt->addfilter(new unindent);
150 if (brepara) filt->addfilter(new repara); 192 if (brepara) filt->addfilter(new repara);
151 if (bindenter) filt->addfilter(new indenter(bindenter)); 193 if (bindenter) filt->addfilter(new indenter(bindenter));
152 if (bdblspce) filt->addfilter(new dblspce); 194 if (bdblspce) filt->addfilter(new dblspce);
195 if (bremap) filt->addfilter(new remap);
196 if (bmakebold) filt->addfilter(new embolden);
153 return filt; 197 return filt;
154 } 198 }
155 199
@@ -162,26 +206,31 @@ private slots:
162 void keyPressEvent(QKeyEvent*); 206 void keyPressEvent(QKeyEvent*);
163 void drawFonts(QPainter*); 207 void drawFonts(QPainter*);
164 private: 208 private:
209 void setTwoTouch(bool _b);
165 void init(); 210 void init();
211 void mousePressEvent( QMouseEvent* );
166 void mouseReleaseEvent( QMouseEvent* ); 212 void mouseReleaseEvent( QMouseEvent* );
167// void mouseDoubleClickEvent( QMouseEvent* ); 213// void mouseDoubleClickEvent( QMouseEvent* );
168 QString m_string, m_fontname; 214 QString m_string, m_fontname;
169 void setfont(QPainter*); 215 void setfont();
170 //myoutput stuff 216 //myoutput stuff
171 private: 217 private:
218 bool mouseUpOn;
219 bool getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt);
220 bool m_twotouch, m_touchone;
221 size_t m_startpos, m_startoffset;
172 void dopageup(); 222 void dopageup();
173 void lineDown(); 223 void lineDown();
174 void lineUp(); 224 void lineUp();
175 void dopagedn(); 225 void dopagedn();
176 long real_delay(); 226 long real_delay();
177 int m_textsize; 227 int m_textsize;
178 int m_lastwidth; 228 int m_lastwidth, m_lastheight;
179 CBuffer** textarray; 229 CBufferFace<CDrawBuffer*> textarray;
180 size_t* locnarray; 230 CBufferFace<size_t> locnarray;
181 unsigned int numlines; 231 unsigned int numlines;
182 bool bstripcr, bstriphtml, bdehyphen, bunindent, brepara, bdblspce, btight, m_bBold; 232 bool bstripcr, btextfmt, bstriphtml, bdehyphen, bunindent, brepara, bdblspce, btight, bmakebold, bremap, bpeanut, bautofmt;
183 bool m_bpagemode, m_bMonoSpaced; 233 bool m_bpagemode, m_bMonoSpaced;
184 QString m_targetapp, m_targetmsg;
185 unsigned char bindenter; 234 unsigned char bindenter;
186 QString m_lastfile; 235 QString m_lastfile;
187 size_t m_lastposn; 236 size_t m_lastposn;
@@ -194,24 +243,30 @@ private slots:
194 bool locate(unsigned long n); 243 bool locate(unsigned long n);
195 void jumpto(unsigned long n) { buffdoc.locate(n); } 244 void jumpto(unsigned long n) { buffdoc.locate(n); }
196 unsigned long locate() { return buffdoc.locate(); } 245 unsigned long locate() { return buffdoc.locate(); }
197 unsigned long pagelocate() { return pagepos; } 246 unsigned long explocate() { return buffdoc.explocate(); }
198 unsigned long pagepos, mylastpos; 247 unsigned long pagelocate() { return locnarray[0]; }
199 void setfilter(CFilterChain *f) { buffdoc.setfilter(f); locate(pagepos); } 248 unsigned long mylastpos;
249 void setfilter(CFilterChain *f) { buffdoc.setfilter(f); locate(pagelocate()); }
200 void restore() { jumpto(mylastpos); } 250 void restore() { jumpto(mylastpos); }
201 void goUp(); 251 void goUp();
202 void refresh() { locate(pagepos); } 252 void refresh() { locate(pagelocate()); }
203 void goDown(); 253 void goDown();
204 // bool bold; 254 // bool bold;
205 int textsize() { return m_textsize; } 255 int textsize() { return m_textsize; }
206 void textsize(int ts) { m_textsize = ts; } 256 void textsize(int ts) { m_textsize = ts; }
207 bool fillbuffer(); 257 bool fillbuffer(int ru = 0, int ht = 0);
208 unsigned int screenlines(); 258 unsigned int screenlines();
209 void sizes(unsigned long& fs, unsigned long& ts) { buffdoc.sizes(fs,ts); } 259 void sizes(unsigned long& fs, unsigned long& ts) { buffdoc.sizes(fs,ts); }
210 static const char *fonts[]; 260 static const char *fonts[];
211 unsigned int *fontsizes; 261// unsigned int *fontsizes;
212 int m_ascent, m_descent, m_linespacing; 262 int m_ascent, m_descent, m_linespacing;
213 QFontMetrics* m_fm; 263 QFontMetrics* m_fm;
214 QString firstword(); 264 QString firstword();
265
266 signals:
267 void OnRedraw();
268 void OnWordSelected(const QString&, size_t, const QString&);
269 void OnActionPressed();
215}; 270};
216 271
217#endif 272#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 @@
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include <qclipboard.h>
21#include <qwidgetstack.h> 22#include <qwidgetstack.h>
22#include <qpe/qpemenubar.h> 23#include <qpe/qpemenubar.h>
23#include <qpe/qpetoolbar.h> 24#include <qpe/qpetoolbar.h>
@@ -38,10 +39,14 @@
38#include <qpe/config.h> 39#include <qpe/config.h>
39#include <qbuttongroup.h> 40#include <qbuttongroup.h>
40#include <qradiobutton.h> 41#include <qradiobutton.h>
42#include <qpe/qcopenvelope_qws.h>
41 43
44#include "QTReader.h"
45#include "Bkmks.h"
42#include "cbkmkselector.h" 46#include "cbkmkselector.h"
43#include "infowin.h" 47#include "infowin.h"
44 48#include "CAnnoEdit.h"
49#include "QFloatBar.h"
45//#include <qpe/fontdatabase.h> 50//#include <qpe/fontdatabase.h>
46 51
47#include <qpe/resource.h> 52#include <qpe/resource.h>
@@ -49,6 +54,7 @@
49 54
50#include "QTReaderApp.h" 55#include "QTReaderApp.h"
51#include "fileBrowser.h" 56#include "fileBrowser.h"
57#include "CDrawBuffer.h"
52 58
53 59
54unsigned long QTReaderApp::m_uid = 0; 60unsigned long QTReaderApp::m_uid = 0;
@@ -68,28 +74,28 @@ void QTReaderApp::listBkmkFiles()
68 74
69 while(1) 75 while(1)
70 { 76 {
71 struct dirent* de; 77 struct dirent* de;
72 struct stat buf; 78 struct stat buf;
73 de = readdir(d); 79 de = readdir(d);
74 if (de == NULL) break; 80 if (de == NULL) break;
75 81
76 if (lstat((const char *)Global::applicationFileName("uqtreader",de->d_name),&buf) == 0 && S_ISREG(buf.st_mode)) 82 if (lstat((const char *)Global::applicationFileName("uqtreader",de->d_name),&buf) == 0 && S_ISREG(buf.st_mode))
77 { 83 {
78 bkmkselector->insertItem(de->d_name); 84 bkmkselector->insertItem(de->d_name);
79 cnt++; 85 cnt++;
80 } 86 }
81 } 87 }
82 88
83 closedir(d); 89 closedir(d);
84 90
85 if (cnt > 0) 91 if (cnt > 0)
86 { 92 {
87 menu->hide(); 93//tjw menu->hide();
88 editBar->hide(); 94 editBar->hide();
89 if (m_fontVisible) m_fontBar->hide(); 95 if (m_fontVisible) m_fontBar->hide();
90 if (regVisible) regBar->hide(); 96 if (regVisible) regBar->hide();
91 if (searchVisible) searchBar->hide(); 97 if (searchVisible) searchBar->hide();
92 m_nRegAction = cRmBkmkFile; 98 m_nRegAction = cRmBkmkFile;
93 editorStack->raiseWidget( bkmkselector ); 99 editorStack->raiseWidget( bkmkselector );
94 } 100 }
95 else 101 else
@@ -97,7 +103,7 @@ void QTReaderApp::listBkmkFiles()
97} 103}
98 104
99QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) 105QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
100 : QMainWindow( parent, name, f ), bFromDocView( FALSE ) 106 : QMainWindow( parent, name, f ), bFromDocView( FALSE ), m_dontSave(false)
101{ 107{
102// qDebug("Application directory = %s", (const tchar *)QPEApplication::documentDir()); 108// qDebug("Application directory = %s", (const tchar *)QPEApplication::documentDir());
103// qDebug("Application directory = %s", (const tchar *)Global::applicationFileName("uqtreader","bkmks.xml")); 109// qDebug("Application directory = %s", (const tchar *)Global::applicationFileName("uqtreader","bkmks.xml"));
@@ -105,11 +111,11 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
105 pBkmklist = NULL; 111 pBkmklist = NULL;
106 doc = 0; 112 doc = 0;
107 113
108 m_fBkmksChanged = false; 114 m_fBkmksChanged = false;
109 115
110 QString lang = getenv( "LANG" ); 116 QString lang = getenv( "LANG" );
111 117
112 m_autogenstr = "^ *[A-Z].*[a-z] *$"; 118 m_autogenstr = "^ *[A-Z].*[a-z] *$";
113 setToolBarsMovable( FALSE ); 119 setToolBarsMovable( FALSE );
114 120
115 setIcon( Resource::loadPixmap( "uqtreader" ) ); 121 setIcon( Resource::loadPixmap( "uqtreader" ) );
@@ -117,7 +123,7 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
117 QPEToolBar *bar = new QPEToolBar( this ); 123 QPEToolBar *bar = new QPEToolBar( this );
118 bar->setHorizontalStretchable( TRUE ); 124 bar->setHorizontalStretchable( TRUE );
119 addToolBar(bar, "tool",QMainWindow::Top, true); 125 addToolBar(bar, "tool",QMainWindow::Top, true);
120 menu = bar; 126//tjw menu = bar;
121 127
122 QPEMenuBar *mb = new QPEMenuBar( bar ); 128 QPEMenuBar *mb = new QPEMenuBar( bar );
123 QPopupMenu *file = new QPopupMenu( this ); 129 QPopupMenu *file = new QPopupMenu( this );
@@ -144,6 +150,11 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
144 pbar = new QProgressBar(this); 150 pbar = new QProgressBar(this);
145 pbar->hide(); 151 pbar->hide();
146 152
153 m_annoWin = new CAnnoEdit(editorStack);
154 editorStack->addWidget(m_annoWin, get_unique_id());
155 connect( m_annoWin, SIGNAL( finished(const QString&, const QString&) ), this, SLOT( addAnno(const QString&, const QString&) ) );
156 connect( m_annoWin, SIGNAL( cancelled() ), this, SLOT( infoClose() ) );
157
147 m_infoWin = new infowin(editorStack); 158 m_infoWin = new infowin(editorStack);
148 editorStack->addWidget(m_infoWin, get_unique_id()); 159 editorStack->addWidget(m_infoWin, get_unique_id());
149 connect( m_infoWin, SIGNAL( Close() ), this, SLOT( infoClose() ) ); 160 connect( m_infoWin, SIGNAL( Close() ), this, SLOT( infoClose() ) );
@@ -166,18 +177,23 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
166*/ 177*/
167 178
168 reader = new QTReader( editorStack ); 179 reader = new QTReader( editorStack );
180
181 ((QPEApplication*)qApp)->setStylusOperation(reader, QPEApplication::RightOnHold);
182
169 Config config( "uqtreader" ); 183 Config config( "uqtreader" );
170 config.setGroup( "View" ); 184 config.setGroup( "View" );
171 185
172 reader->bstripcr = config.readBoolEntry( "StripCr", true ); 186 reader->bstripcr = config.readBoolEntry( "StripCr", true );
187 reader->btextfmt = config.readBoolEntry( "TextFmt", false );
188 reader->bautofmt = config.readBoolEntry( "AutoFmt", true );
173 reader->bstriphtml = config.readBoolEntry( "StripHtml", false ); 189 reader->bstriphtml = config.readBoolEntry( "StripHtml", false );
190 reader->bpeanut = config.readBoolEntry( "Peanut", false );
174 reader->bdehyphen = config.readBoolEntry( "Dehyphen", false ); 191 reader->bdehyphen = config.readBoolEntry( "Dehyphen", false );
175 reader->bunindent = config.readBoolEntry( "Unindent", false ); 192 reader->bunindent = config.readBoolEntry( "Unindent", false );
176 reader->brepara = config.readBoolEntry( "Repara", false ); 193 reader->brepara = config.readBoolEntry( "Repara", false );
177 reader->bdblspce = config.readBoolEntry( "DoubleSpace", false ); 194 reader->bdblspce = config.readBoolEntry( "DoubleSpace", false );
178 reader->bindenter = config.readNumEntry( "Indent", 0 ); 195 reader->bindenter = config.readNumEntry( "Indent", 0 );
179 reader->m_textsize = config.readNumEntry( "FontSize", 12 ); 196 reader->m_textsize = config.readNumEntry( "FontSize", 12 );
180 reader->m_bBold = config.readBoolEntry( "Bold", false );
181 reader->m_delay = config.readNumEntry( "ScrollDelay", 5184); 197 reader->m_delay = config.readNumEntry( "ScrollDelay", 5184);
182 reader->m_lastfile = config.readEntry( "LastFile", QString::null ); 198 reader->m_lastfile = config.readEntry( "LastFile", QString::null );
183 reader->m_lastposn = config.readNumEntry( "LastPosn", 0 ); 199 reader->m_lastposn = config.readNumEntry( "LastPosn", 0 );
@@ -187,9 +203,21 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
187 reader->m_encd = config.readNumEntry( "Encoding", 0 ); 203 reader->m_encd = config.readNumEntry( "Encoding", 0 );
188 reader->m_charpc = config.readNumEntry( "CharSpacing", 100 ); 204 reader->m_charpc = config.readNumEntry( "CharSpacing", 100 );
189 reader->m_overlap = config.readNumEntry( "Overlap", 0 ); 205 reader->m_overlap = config.readNumEntry( "Overlap", 0 );
190 reader->m_targetapp = config.readEntry( "TargetApp", QString::null ); 206 reader->bremap = config.readBoolEntry( "Remap", true );
191 reader->m_targetmsg = config.readEntry( "TargetMsg", QString::null ); 207 reader->bmakebold = config.readBoolEntry( "MakeBold", false );
192 reader->init(); 208 m_targetapp = config.readEntry( "TargetApp", QString::null );
209 m_targetmsg = config.readEntry( "TargetMsg", QString::null );
210 m_twoTouch = config.readBoolEntry( "TwoTouch", false);
211 m_doAnnotation = config.readBoolEntry( "Annotation", false);
212 m_doDictionary = config.readBoolEntry( "Dictionary", false);
213 m_doClipboard = config.readBoolEntry( "Clipboard", false);
214 m_spaceTarget = (ActionTypes)config.readNumEntry("SpaceTarget", cesAutoScroll);
215 setTwoTouch(m_twoTouch);
216
217
218 connect( reader, SIGNAL( OnRedraw() ), this, SLOT( OnRedraw() ) );
219 connect( reader, SIGNAL( OnActionPressed() ), this, SLOT( OnActionPressed() ) );
220 connect( reader, SIGNAL( OnWordSelected(const QString&, size_t, const QString&) ), this, SLOT( OnWordSelected(const QString&, size_t, const QString&) ) );
193 editorStack->addWidget( reader, get_unique_id() ); 221 editorStack->addWidget( reader, get_unique_id() );
194 222
195 QAction *a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); 223 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 )
212 connect( a, SIGNAL( activated() ), this, SLOT( showinfo() ) ); 240 connect( a, SIGNAL( activated() ), this, SLOT( showinfo() ) );
213 a->addTo( file ); 241 a->addTo( file );
214 242
215 a = new QAction( tr( "Start Block" ), QString::null, 0, this, NULL); 243 QActionGroup* ag = new QActionGroup(this);
216 connect( a, SIGNAL( activated() ), this, SLOT( editMark() ) ); 244 QPopupMenu *spacemenu = new QPopupMenu(this);
217 file->insertSeparator(); 245 file->insertItem( tr( "On Action..." ), spacemenu );
218 a->addTo( file );
219 246
220 a = new QAction( tr( "Copy Block" ), QString::null, 0, this, NULL); 247 m_buttonAction[0] = new QAction( tr( "Open File" ), QString::null, 0, ag, NULL, true );
221 connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); 248
222 a->addTo( file ); 249 m_buttonAction[1] = new QAction( tr( "Autoscroll" ), QString::null, 0, ag, NULL, true );
250
251 m_buttonAction[2] = new QAction( tr( "Mark" ), QString::null, 0, ag, NULL, true );
252
253 ag->addTo(spacemenu);
223 254
224 a = m_scrollButton = new QAction( tr( "Scroll" ), Resource::loadPixmap( "opie-reader/panel-arrow-down" ), QString::null, 0, this, 0, true ); 255 connect(ag, SIGNAL( selected(QAction*) ), this, SLOT( buttonActionSelected(QAction*) ) );
256
257
258 a = m_scrollButton = new QAction( tr( "Scroll" ), Resource::loadPixmap( "panel-arrow-down" ), QString::null, 0, this, 0, true );
225// connect( a, SIGNAL( activated() ), this, SLOT( autoScroll() ) ); 259// connect( a, SIGNAL( activated() ), this, SLOT( autoScroll() ) );
226 a->setOn(false); 260 a->setOn(false);
227 connect( a, SIGNAL( toggled(bool) ), this, SLOT( autoScroll(bool) ) ); 261 connect( a, SIGNAL( toggled(bool) ), this, SLOT( autoScroll(bool) ) );
@@ -242,7 +276,7 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
242 connect( a, SIGNAL( activated() ), this, SLOT( jump() ) ); 276 connect( a, SIGNAL( activated() ), this, SLOT( jump() ) );
243 a->addTo( file ); 277 a->addTo( file );
244 278
245 a = new QAction( tr( "Page/Line scroll" ), QString::null, 0, this, NULL, true ); 279 a = new QAction( tr( "Page/Line Scroll" ), QString::null, 0, this, NULL, true );
246 connect( a, SIGNAL( toggled(bool) ), this, SLOT( pagemode(bool) ) ); 280 connect( a, SIGNAL( toggled(bool) ), this, SLOT( pagemode(bool) ) );
247 a->setOn(reader->m_bpagemode); 281 a->setOn(reader->m_bpagemode);
248 a->addTo( file ); 282 a->addTo( file );
@@ -251,10 +285,37 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
251 connect( a, SIGNAL( activated() ), this, SLOT( setoverlap() ) ); 285 connect( a, SIGNAL( activated() ), this, SLOT( setoverlap() ) );
252 a->addTo( file ); 286 a->addTo( file );
253 287
288 file->insertSeparator();
289
254 a = new QAction( tr( "Set Dictionary" ), QString::null, 0, this, NULL); 290 a = new QAction( tr( "Set Dictionary" ), QString::null, 0, this, NULL);
255 connect( a, SIGNAL( activated() ), this, SLOT( settarget() ) ); 291 connect( a, SIGNAL( activated() ), this, SLOT( settarget() ) );
256 a->addTo( file ); 292 a->addTo( file );
257 293
294 a = new QAction( tr( "Two/One Touch" ), QString::null, 0, this, NULL, true );
295 connect( a, SIGNAL( toggled(bool) ), this, SLOT( setTwoTouch(bool) ) );
296 a->setOn(m_twoTouch);
297 a->addTo( file );
298
299 ag = new QActionGroup(this);
300 ag->setExclusive(false);
301 QPopupMenu *encoding = new QPopupMenu(this);
302 file->insertItem( tr( "Target" ), encoding );
303
304 a = new QAction( tr( "Annotation" ), QString::null, 0, ag, NULL, true );
305 connect( a, SIGNAL( toggled(bool) ), this, SLOT( OnAnnotation(bool) ) );
306 a->setOn(m_doAnnotation);
307
308 a = new QAction( tr( "Dictionary" ), QString::null, 0, ag, NULL, true );
309 connect( a, SIGNAL( toggled(bool) ), this, SLOT( OnDictionary(bool) ) );
310 a->setOn(m_doDictionary);
311
312 a = new QAction( tr( "Clipboard" ), QString::null, 0, ag, NULL, true );
313 connect( a, SIGNAL( toggled(bool) ), this, SLOT( OnClipboard(bool) ) );
314 a->setOn(m_doClipboard);
315
316 ag->addTo(encoding);
317
318
258/* 319/*
259 a = new QAction( tr( "Import" ), QString::null, 0, this, NULL ); 320 a = new QAction( tr( "Import" ), QString::null, 0, this, NULL );
260 connect( a, SIGNAL( activated() ), this, SLOT( importFiles() ) ); 321 connect( a, SIGNAL( activated() ), this, SLOT( importFiles() ) );
@@ -276,56 +337,95 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
276 a->addTo( edit ); 337 a->addTo( edit );
277 */ 338 */
278 339
279 a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); 340// a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 );
341 a = new QAction( tr( "Find..." ), QString::null, 0, this, NULL);
280 connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); 342 connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) );
281 file->insertSeparator(); 343 file->insertSeparator();
282 a->addTo( bar ); 344// a->addTo( bar );
283 a->addTo( file ); 345 a->addTo( file );
284 346
285 347
286 a = new QAction( tr( "Strip CR" ), QString::null, 0, this, NULL, true ); 348 a = m_bkmkAvail = new QAction( tr( "Annotation" ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 );
287 a->setOn(reader->bstripcr); 349 connect( a, SIGNAL( activated() ), this, SLOT( showAnnotation() ) );
288 connect( a, SIGNAL( toggled(bool) ), this, SLOT( stripcr(bool) ) ); 350 a->addTo( bar );
289 a->addTo( format );
290 // a->setOn(true);
291 351
292 a = new QAction( tr( "Strip HTML" ), QString::null, 0, this, NULL, true ); 352 m_bkmkAvail->setEnabled(false);
353
354
355 ag = new QActionGroup(this);
356// ag->setExclusive(false);
357 encoding = new QPopupMenu(this);
358 format->insertItem( tr( "Markup" ), encoding );
359
360 a = new QAction( tr( "Auto" ), QString::null, 0, ag, NULL, true );
361 a->setOn(reader->bautofmt);
362 connect( a, SIGNAL( toggled(bool) ), this, SLOT( autofmt(bool) ) );
363
364 a = new QAction( tr( "None" ), QString::null, 0, ag, NULL, true );
365 a->setOn(!reader->bautofmt && !(reader->btextfmt || reader->bstriphtml || reader->bpeanut));
366// connect( a, SIGNAL( toggled(bool) ), this, SLOT( textfmt(bool) ) );
367
368 a = new QAction( tr( "Text" ), QString::null, 0, ag, NULL, true );
369 a->setOn(reader->btextfmt);
370 connect( a, SIGNAL( toggled(bool) ), this, SLOT( textfmt(bool) ) );
371
372 a = new QAction( tr( "HTML" ), QString::null, 0, ag, NULL, true );
293 a->setOn(reader->bstriphtml); 373 a->setOn(reader->bstriphtml);
294 connect( a, SIGNAL( toggled(bool) ), this, SLOT( striphtml(bool) ) ); 374 connect( a, SIGNAL( toggled(bool) ), this, SLOT( striphtml(bool) ) );
295 a->addTo( format );
296 375
297 a = new QAction( tr( "Dehyphen" ), QString::null, 0, this, NULL, true ); 376 a = new QAction( tr( "Peanut/PML" ), QString::null, 0, ag, NULL, true );
377 a->setOn(reader->bpeanut);
378 connect( a, SIGNAL( toggled(bool) ), this, SLOT( peanut(bool) ) );
379
380 ag->addTo(encoding);
381
382
383
384 ag = new QActionGroup(this);
385 ag->setExclusive(false);
386 encoding = new QPopupMenu(this);
387 format->insertItem( tr( "Layout" ), encoding );
388
389 a = new QAction( tr( "Strip CR" ), QString::null, 0, ag, NULL, true );
390 a->setOn(reader->bstripcr);
391 connect( a, SIGNAL( toggled(bool) ), this, SLOT( stripcr(bool) ) );
392
393 a = new QAction( tr( "Dehyphen" ), QString::null, 0, ag, NULL, true );
298 a->setOn(reader->bdehyphen); 394 a->setOn(reader->bdehyphen);
299 connect( a, SIGNAL( toggled(bool) ), this, SLOT( dehyphen(bool) ) ); 395 connect( a, SIGNAL( toggled(bool) ), this, SLOT( dehyphen(bool) ) );
300 a->addTo( format ); 396// a->addTo( format );
301 397
302 a = new QAction( tr( "Unindent" ), QString::null, 0, this, NULL, true ); 398 a = new QAction( tr( "Unindent" ), QString::null, 0, ag, NULL, true );
303 connect( a, SIGNAL( toggled(bool) ), this, SLOT( unindent(bool) ) ); 399 connect( a, SIGNAL( toggled(bool) ), this, SLOT( unindent(bool) ) );
304 a->setOn(reader->bunindent); 400 a->setOn(reader->bunindent);
305 a->addTo( format ); 401// a->addTo( format );
306 402
307 a = new QAction( tr( "Re-paragraph" ), QString::null, 0, this, NULL, true ); 403 a = new QAction( tr( "Re-paragraph" ), QString::null, 0, ag, NULL, true );
308 connect( a, SIGNAL( toggled(bool) ), this, SLOT( repara(bool) ) ); 404 connect( a, SIGNAL( toggled(bool) ), this, SLOT( repara(bool) ) );
309 a->setOn(reader->brepara); 405 a->setOn(reader->brepara);
310 a->addTo( format ); 406// a->addTo( format );
311 407
312 a = new QAction( tr( "Double Space" ), QString::null, 0, this, NULL, true ); 408 a = new QAction( tr( "Double Space" ), QString::null, 0, ag, NULL, true );
313 connect( a, SIGNAL( toggled(bool) ), this, SLOT( dblspce(bool) ) ); 409 connect( a, SIGNAL( toggled(bool) ), this, SLOT( dblspce(bool) ) );
314 a->setOn(reader->bdblspce); 410 a->setOn(reader->bdblspce);
315 a->addTo( format ); 411// a->addTo( format );
316 412
317 a = new QAction( tr( "Indent+" ), QString::null, 0, this, NULL ); 413 a = new QAction( tr( "Indent+" ), QString::null, 0, ag, NULL );
318 connect( a, SIGNAL( activated() ), this, SLOT( indentplus() ) ); 414 connect( a, SIGNAL( activated() ), this, SLOT( indentplus() ) );
319 a->addTo( format ); 415// a->addTo( format );
320 416
321 a = new QAction( tr( "Indent-" ), QString::null, 0, this, NULL ); 417 a = new QAction( tr( "Indent-" ), QString::null, 0, ag, NULL );
322 connect( a, SIGNAL( activated() ), this, SLOT( indentminus() ) ); 418 connect( a, SIGNAL( activated() ), this, SLOT( indentminus() ) );
323 a->addTo( format );
324 419
325 a = new QAction( tr( "Bold" ), QString::null, 0, this, NULL, true ); 420 a = new QAction( tr( "Remap" ), QString::null, 0, ag, NULL, true );
326 a->setOn(reader->m_bBold); 421 connect( a, SIGNAL( toggled(bool) ), this, SLOT( remap(bool) ) );
327 connect( a, SIGNAL( toggled(bool) ), this, SLOT( setbold(bool) ) ); 422 a->setOn(reader->bremap);
328 a->addTo( format ); 423
424 a = new QAction( tr( "Embolden" ), QString::null, 0, ag, NULL, true );
425 connect( a, SIGNAL( toggled(bool) ), this, SLOT( embolden(bool) ) );
426 a->setOn(reader->bmakebold);
427
428 ag->addTo(encoding);
329 429
330 // a = new QAction( tr( "Zoom" ), QString::null, 0, this, NULL, true ); 430 // a = new QAction( tr( "Zoom" ), QString::null, 0, this, NULL, true );
331 // a = new QAction( tr( "Zoom" ), Resource::loadPixmap( "mag" ), QString::null, 0, this, 0 ); 431 // 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 )
346 connect( a, SIGNAL( activated() ), this, SLOT( setspacing() ) ); 446 connect( a, SIGNAL( activated() ), this, SLOT( setspacing() ) );
347 a->addTo( format ); 447 a->addTo( format );
348 448
349 QPopupMenu *encoding = new QPopupMenu(this); 449 encoding = new QPopupMenu(this);
350 format->insertSeparator(); 450// format->insertSeparator();
351 format->insertItem( tr( "Encoding" ), encoding ); 451 format->insertItem( tr( "Encoding" ), encoding );
352 452
353 QActionGroup* ag = new QActionGroup(this); 453 ag = new QActionGroup(this);
354 454
355 m_EncodingAction[0] = new QAction( tr( "Ascii" ), QString::null, 0, ag, NULL, true ); 455 m_EncodingAction[0] = new QAction( tr( "Ascii" ), QString::null, 0, ag, NULL, true );
356 456
@@ -379,6 +479,10 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
379 connect( a, SIGNAL( activated() ), this, SLOT( addbkmk() ) ); 479 connect( a, SIGNAL( activated() ), this, SLOT( addbkmk() ) );
380 a->addTo( marks ); 480 a->addTo( marks );
381 481
482 a = new QAction( tr( "Annotate" ), QString::null, 0, this, NULL);
483 connect( a, SIGNAL( activated() ), this, SLOT( addanno() ) );
484 a->addTo( marks );
485
382 a = new QAction( tr( "Goto" ), QString::null, 0, this, NULL, false ); 486 a = new QAction( tr( "Goto" ), QString::null, 0, this, NULL, false );
383 connect( a, SIGNAL( activated() ), this, SLOT( do_gotomark() ) ); 487 connect( a, SIGNAL( activated() ), this, SLOT( do_gotomark() ) );
384 a->addTo( marks ); 488 a->addTo( marks );
@@ -405,25 +509,38 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
405 marks->insertSeparator(); 509 marks->insertSeparator();
406 a->addTo( marks ); 510 a->addTo( marks );
407 511
512 a = new QAction( tr( "Start Block" ), QString::null, 0, this, NULL);
513 connect( a, SIGNAL( activated() ), this, SLOT( editMark() ) );
514 marks->insertSeparator();
515 a->addTo( marks );
516
517 a = new QAction( tr( "Copy Block" ), QString::null, 0, this, NULL);
518 connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) );
519 a->addTo( marks );
520
521
408 mb->insertItem( tr( "File" ), file ); 522 mb->insertItem( tr( "File" ), file );
409 // mb->insertItem( tr( "Edit" ), edit ); 523 // mb->insertItem( tr( "Edit" ), edit );
410 mb->insertItem( tr( "Format" ), format ); 524 mb->insertItem( tr( "Format" ), format );
411 mb->insertItem( tr( "Marks" ), marks ); 525 mb->insertItem( tr( "Marks" ), marks );
412 526
413 searchBar = new QToolBar( "Search", this, QMainWindow::Top, TRUE ); 527 searchBar = new QFloatBar( "Search", this, QMainWindow::Top, TRUE );
414 528
415 searchBar->setHorizontalStretchable( TRUE ); 529 searchBar->setHorizontalStretchable( TRUE );
416 530
531 connect(searchBar, SIGNAL( OnHide() ), this, SLOT( restoreFocus() ));
532
417 searchEdit = new QLineEdit( searchBar, "searchEdit" ); 533 searchEdit = new QLineEdit( searchBar, "searchEdit" );
418// QFont f("unifont", 16 /*, QFont::Bold*/); 534// QFont f("unifont", 16 /*, QFont::Bold*/);
419// searchEdit->setFont( f ); 535// searchEdit->setFont( f );
420 searchBar->setStretchableWidget( searchEdit ); 536 searchBar->setStretchableWidget( searchEdit );
537
421#ifdef __ISEARCH 538#ifdef __ISEARCH
422 connect( searchEdit, SIGNAL( textChanged( const QString & ) ), 539 connect( searchEdit, SIGNAL( textChanged( const QString & ) ),
423 this, SLOT( search( const QString& ) ) ); 540 this, SLOT( search( const QString& ) ) );
424#else 541#else
425 connect( searchEdit, SIGNAL( returnPressed( ) ), 542 connect( searchEdit, SIGNAL( returnPressed( ) ),
426 this, SLOT( search( ) ) ); 543 this, SLOT( search( ) ) );
427#endif 544#endif
428 a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); 545 a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 );
429 connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); 546 connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) );
@@ -435,7 +552,8 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
435 552
436 searchBar->hide(); 553 searchBar->hide();
437 554
438 regBar = new QToolBar( "Autogen", this, QMainWindow::Top, TRUE ); 555 regBar = new QFloatBar( "Autogen", this, QMainWindow::Top, TRUE );
556 connect(regBar, SIGNAL( OnHide() ), this, SLOT( restoreFocus() ));
439 557
440 regBar->setHorizontalStretchable( TRUE ); 558 regBar->setHorizontalStretchable( TRUE );
441 559
@@ -445,7 +563,7 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
445 regBar->setStretchableWidget( regEdit ); 563 regBar->setStretchableWidget( regEdit );
446 564
447 connect( regEdit, SIGNAL( returnPressed( ) ), 565 connect( regEdit, SIGNAL( returnPressed( ) ),
448 this, SLOT( do_regaction() ) ); 566 this, SLOT( do_regaction() ) );
449 567
450 a = new QAction( tr( "Do Reg" ), Resource::loadPixmap( "enter" ), QString::null, 0, this, 0 ); 568 a = new QAction( tr( "Do Reg" ), Resource::loadPixmap( "enter" ), QString::null, 0, this, 0 );
451 connect( a, SIGNAL( activated() ), this, SLOT( do_regaction() ) ); 569 connect( a, SIGNAL( activated() ), this, SLOT( do_regaction() ) );
@@ -464,25 +582,40 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
464 m_fontSelector = new QComboBox(false, m_fontBar); 582 m_fontSelector = new QComboBox(false, m_fontBar);
465 m_fontBar->setStretchableWidget( m_fontSelector ); 583 m_fontBar->setStretchableWidget( m_fontSelector );
466 { 584 {
467 FontDatabase f; 585 FontDatabase f;
468 m_fontSelector->insertStringList(f.families()); 586 QStringList flist = f.families();
587 m_fontSelector->insertStringList(flist);
588
589 bool realfont = false;
590 for (QStringList::Iterator nm = flist.begin(); nm != flist.end(); nm++)
591 {
592 if (reader->m_fontname == *nm)
593 {
594 realfont = true;
595 break;
596 }
597 }
598 if (!realfont) reader->m_fontname = flist[0];
469 } // delete the FontDatabase!!! 599 } // delete the FontDatabase!!!
600
470 connect( m_fontSelector, SIGNAL( activated(const QString& ) ), 601 connect( m_fontSelector, SIGNAL( activated(const QString& ) ),
471 this, SLOT( do_setfont(const QString&) ) ); 602 this, SLOT( do_setfont(const QString&) ) );
472 603
473 m_fontBar->hide(); 604 m_fontBar->hide();
474 m_fontVisible = false; 605 m_fontVisible = false;
475 606
476 connect(qApp, SIGNAL( appMessage(const QCString&, const QByteArray& ) ), 607 connect(qApp, SIGNAL( appMessage(const QCString&, const QByteArray& ) ),
477 this, SLOT( msgHandler(const QCString&, const QByteArray&) ) ); 608 this, SLOT( msgHandler(const QCString&, const QByteArray&) ) );
478 609
479 610
611 reader->init();
480 if (!reader->m_lastfile.isEmpty()) 612 if (!reader->m_lastfile.isEmpty())
481 { 613 {
482 openFile( reader->m_lastfile ); 614 openFile( reader->m_lastfile );
483 doc = new DocLnk(reader->m_lastfile); 615 doc = new DocLnk(reader->m_lastfile);
484 } 616 }
485 m_EncodingAction[reader->m_encd]->setOn(true); 617 m_EncodingAction[reader->m_encd]->setOn(true);
618 m_buttonAction[m_spaceTarget]->setOn(true);
486 do_setfont(reader->m_fontname); 619 do_setfont(reader->m_fontname);
487} 620}
488 621
@@ -495,22 +628,259 @@ void QTReaderApp::msgHandler(const QCString& _msg, const QByteArray& _data)
495 QDataStream stream( _data, IO_ReadOnly ); 628 QDataStream stream( _data, IO_ReadOnly );
496 if ( msg == "info(QString)" ) 629 if ( msg == "info(QString)" )
497 { 630 {
498 QString info; 631 QString info;
499 stream >> info; 632 stream >> info;
500 QMessageBox::information(this, "QTReader", info); 633 QMessageBox::information(this, "QTReader", info);
501 } else if ( msg == "warn(QString)" ) 634 }
635 else if ( msg == "warn(QString)" )
636 {
637 QString info;
638 stream >> info;
639 QMessageBox::warning(this, "QTReader", info);
640 }
641
642
643 else if ( msg == "exit()" )
644 {
645 m_dontSave = true;
646 close();
647 }
648 else if ( msg == "pageDown()" )
649 {
650 reader->dopagedn();
651 }
652 else if ( msg == "pageUp()" )
653 {
654 reader->dopageup();
655 }
656 else if ( msg == "lineDown()" )
657 {
658 reader->lineDown();
659 }
660 else if ( msg == "lineUp()" )
661 {
662 reader->lineUp();
663 }
664 else if ( msg == "showText()" )
665 {
666 showEditTools();
667 }
668 else if ( msg == "File/Open(QString)" )
669 {
670 QString info;
671 stream >> info;
672 openFile( info );
673 }
674 else if ( msg == "File/Info()" )
675 {
676 showinfo();
677 }
678 else if ( msg == "File/Start Block()" )
679 {
680 editMark();
681 }
682 else if ( msg == "File/Copy Block()" )
683 {
684 editCopy();
685 }
686 else if ( msg == "File/Scroll(int)" )
687 {
688 int info;
689 stream >> info;
690 autoScroll(info);
691 }
692 else if ( msg == "File/Jump(int)" )
693 {
694 int info;
695 stream >> info;
696 reader->locate(info);
697 }
698 else if ( msg == "File/Page/Line Scroll(int)" )
699 {
700 int info;
701 stream >> info;
702 pagemode(info);
703 }
704 else if ( msg == "File/Set Overlap(int)" )
705 {
706 int info;
707 stream >> info;
708 reader->m_overlap = info;
709 }
710 else if ( msg == "File/Set Dictionary(QString)" )
711 {
712 QString info;
713 stream >> info;
714 do_settarget(info);
715 }
716 else if ( msg == "File/Two/One Touch(int)" )
717 {
718 int info;
719 stream >> info;
720 setTwoTouch(info);
721 }
722 else if ( msg == "Target/Annotation(int)" )
723 {
724 int info;
725 stream >> info;
726 OnAnnotation(info);
727 }
728 else if ( msg == "Target/Dictionary(int)" )
729 {
730 int info;
731 stream >> info;
732 OnDictionary(info);
733 }
734 else if ( msg == "Target/Clipboard(int)" )
735 {
736 int info;
737 stream >> info;
738 OnClipboard(info);
739 }
740 else if ( msg == "File/Find(QString)" )
741 {
742 QString info;
743 stream >> info;
744 QRegExp arg(info);
745 size_t pos = reader->pagelocate();
746 size_t start = pos;
747 CDrawBuffer test(&(reader->m_fontControl));
748 reader->buffdoc.getline(&test,reader->width());
749 while (arg.match(toQString(test.data())) == -1)
750 {
751 pos = reader->locate();
752 if (!reader->buffdoc.getline(&test,reader->width()))
753 {
754 QMessageBox::information(this, "QTReader", QString("Can't find\n")+info);
755 pos = start;
756 break;
757 }
758 }
759 reader->locate(pos);
760 }
761 else if ( msg == "Layout/Strip CR(int)" )
762 {
763 int info;
764 stream >> info;
765 stripcr(info);
766 }
767 else if ( msg == "Markup/Auto(int)" )
768 {
769 int info;
770 stream >> info;
771 autofmt(info);
772 }
773 else if ( msg == "Markup/Text(int)" )
774 {
775 int info;
776 stream >> info;
777 textfmt(info);
778 }
779 else if ( msg == "Markup/HTML(int)" )
780 {
781 int info;
782 stream >> info;
783 striphtml(info);
784 }
785 else if ( msg == "Markup/Peanut(int)" )
786 {
787 int info;
788 stream >> info;
789 peanut(info);
790 }
791 else if ( msg == "Layout/Dehyphen(int)" )
792 {
793 int info;
794 stream >> info;
795 dehyphen(info);
796 }
797 else if ( msg == "Layout/Unindent(int)" )
798 {
799 int info;
800 stream >> info;
801 unindent(info);
802 }
803 else if ( msg == "Layout/Re-paragraph(int)" )
804 {
805 int info;
806 stream >> info;
807 repara(info);
808 }
809 else if ( msg == "Layout/Double Space(int)" )
810 {
811 int info;
812 stream >> info;
813 dblspce(info);
814 }
815 else if ( msg == "Layout/Indent(int)" )
816 {
817 int info;
818 stream >> info;
819 reader->bindenter = info;
820 reader->setfilter(reader->getfilter());
821 }
822 else if ( msg == "Layout/Remap(int)" )
823 {
824 int info;
825 stream >> info;
826 remap(info);
827 }
828 else if ( msg == "Layout/Embolden(int)" )
829 {
830 int info;
831 stream >> info;
832 embolden(info);
833 }
834 else if ( msg == "Format/Ideogram/Word(int)" )
835 {
836 int info;
837 stream >> info;
838 monospace(info);
839 }
840 else if ( msg == "Format/Set width(int)" )
841 {
842 int info;
843 stream >> info;
844 reader->m_charpc = info;
845 reader->setfont();
846 reader->refresh();
847 }
848 else if ( msg == "Format/Encoding(QString)" )
849 {
850 QString info;
851 stream >> info;
852 reader->setencoding(EncNameToInt(info));
853 }
854 else if ( msg == "Format/Set Font(QString,int)" )
502 { 855 {
503 QString info; 856 QString fontname;
504 stream >> info; 857 int size;
505 QMessageBox::warning(this, "QTReader", info); 858 stream >> fontname;
859 stream >> size;
860 setfontHelper(fontname, size);
861 }
862 else if ( msg == "Marks/Autogen(QString)" )
863 {
864 QString info;
865 stream >> info;
866 do_autogen(info);
506 } 867 }
507} 868}
508 869
870ActionTypes QTReaderApp::ActNameToInt(const QString& _enc)
871{
872 for (int i = 0; i < MAX_ACTIONS; i++)
873 {
874 if (m_buttonAction[i]->text() == _enc) return (ActionTypes)i;
875 }
876 return cesAutoScroll;
877}
878
509int QTReaderApp::EncNameToInt(const QString& _enc) 879int QTReaderApp::EncNameToInt(const QString& _enc)
510{ 880{
511 for (int i = 0; i < MAX_ENCODING; i++) 881 for (int i = 0; i < MAX_ENCODING; i++)
512 { 882 {
513 if (m_EncodingAction[i]->text() == _enc) return i; 883 if (m_EncodingAction[i]->text() == _enc) return i;
514 } 884 }
515 return 0; 885 return 0;
516/* 886/*
@@ -527,6 +897,12 @@ void QTReaderApp::encodingSelected(QAction* _a)
527 reader->setencoding(EncNameToInt(_a->text())); 897 reader->setencoding(EncNameToInt(_a->text()));
528} 898}
529 899
900void QTReaderApp::buttonActionSelected(QAction* _a)
901{
902// qDebug("es:%x : %s (%u)", _a, (const char *)(_a->text()), ActNameToInt(_a->text()));
903 m_spaceTarget = ActNameToInt(_a->text());
904}
905
530QTReaderApp::~QTReaderApp() 906QTReaderApp::~QTReaderApp()
531{ 907{
532} 908}
@@ -548,9 +924,9 @@ void QTReaderApp::TBDzoom()
548 924
549void QTReaderApp::clearBkmkList() 925void QTReaderApp::clearBkmkList()
550{ 926{
551 delete pBkmklist; 927 delete pBkmklist;
552 pBkmklist = NULL; 928 pBkmklist = NULL;
553 m_fBkmksChanged = false; 929 m_fBkmksChanged = false;
554} 930}
555 931
556void QTReaderApp::fileOpen() 932void QTReaderApp::fileOpen()
@@ -563,14 +939,14 @@ void QTReaderApp::fileOpen()
563*/ 939*/
564 if (pBkmklist != NULL) 940 if (pBkmklist != NULL)
565 { 941 {
566 if (m_fBkmksChanged) 942 if (m_fBkmksChanged)
567 { 943 {
568 if (QMessageBox::warning(this, "QTReader", "Save bookmarks?", "Save", "Don't bother") == 0) 944 if (QMessageBox::warning(this, "QTReader", "Save bookmarks?", "Save", "Don't bother") == 0)
569 savebkmks(); 945 savebkmks();
570 } 946 }
571 delete pBkmklist; 947 delete pBkmklist;
572 pBkmklist = NULL; 948 pBkmklist = NULL;
573 m_fBkmksChanged = false; 949 m_fBkmksChanged = false;
574 } 950 }
575 reader->disableAutoscroll(); 951 reader->disableAutoscroll();
576/* 952/*
@@ -578,17 +954,18 @@ void QTReaderApp::fileOpen()
578 fileSelector->reread(); 954 fileSelector->reread();
579*/ 955*/
580 fileBrowser* fb = new fileBrowser(this,"QTReader",TRUE, 956 fileBrowser* fb = new fileBrowser(this,"QTReader",TRUE,
581 0, 957 0,
582// WStyle_Customize | WStyle_NoBorderEx, 958 // WStyle_Customize | WStyle_NoBorderEx,
583 "*", QFileInfo(reader->m_lastfile).dirPath(true)); 959 "*", QFileInfo(reader->m_lastfile).dirPath(true));
584 960
585 if (fb->exec()) 961 if (fb->exec())
586 { 962 {
587 QString fn(fb->fileList[0]); 963 QString fn(fb->fileList[0]);
588// fb->populateList(); 964// fb->populateList();
589 if (!fn.isEmpty() && QFileInfo(fn).isFile()) openFile(fn); 965 if (!fn.isEmpty() && QFileInfo(fn).isFile()) openFile(fn);
590 } 966 }
591 delete fb; 967 delete fb;
968 reader->setFocus();
592} 969}
593 970
594void QTReaderApp::showinfo() 971void QTReaderApp::showinfo()
@@ -596,19 +973,120 @@ void QTReaderApp::showinfo()
596 unsigned long fs, ts, pl; 973 unsigned long fs, ts, pl;
597 if (reader->empty()) 974 if (reader->empty())
598 { 975 {
599 QMessageBox::information(this, "QTReader", "No file loaded", 1); 976 QMessageBox::information(this, "QTReader", "No file loaded", 1);
600 } 977 }
601 else 978 else
602 { 979 {
603 reader->sizes(fs,ts); 980 reader->sizes(fs,ts);
604 pl = reader->pagelocate(); 981 pl = reader->pagelocate();
605 m_infoWin->setFileSize(fs); 982 m_infoWin->setFileSize(fs);
606 m_infoWin->setTextSize(ts); 983 m_infoWin->setTextSize(ts);
607 m_infoWin->setRatio(100-(100*fs + (ts >> 1))/ts); 984 m_infoWin->setRatio(100-(100*fs + (ts >> 1))/ts);
608 m_infoWin->setLocation(pl); 985 m_infoWin->setLocation(pl);
609 m_infoWin->setRead((100*pl + (ts >> 1))/ts); 986 m_infoWin->setRead((100*pl + (ts >> 1))/ts);
610 editorStack->raiseWidget( m_infoWin ); 987 editorStack->raiseWidget( m_infoWin );
611 m_infoWin->setFocus(); 988 m_infoWin->setFocus();
989 }
990}
991
992void QTReaderApp::addAnno(const QString& name, const QString& text, size_t posn)
993{
994 if (pBkmklist == NULL) pBkmklist = new CList<Bkmk>;
995#ifdef _UNICODE
996 CBuffer buff(name.length()+1);
997 int i;
998 for (i = 0; i < name.length(); i++)
999 {
1000 buff[i] = name[i].unicode();
1001 }
1002 buff[i] = 0;
1003 CBuffer buff2(text.length()+1);
1004 for (i = 0; i < text.length(); i++)
1005 {
1006 buff2[i] = text[i].unicode();
1007 }
1008 buff2[i] = 0;
1009 pBkmklist->push_front(Bkmk(buff.data(), buff2.data(), posn));
1010#else
1011 pBkmklist->push_front(Bkmk((const tchar*)text,posn));
1012#endif
1013 m_fBkmksChanged = true;
1014 pBkmklist->sort();
1015}
1016
1017void QTReaderApp::addAnno(const QString& name, const QString& text)
1018{
1019 if (m_annoIsEditing)
1020 {
1021 if (name.isEmpty())
1022 {
1023 QMessageBox::information(this, "QTReader", "Need a name for the bookmark\nPlease try again", 1);
1024 }
1025 else
1026 {
1027 addAnno(name, text, m_annoWin->getPosn());
1028 }
1029 showEditTools();
1030 }
1031 else
1032 {
1033 if (m_annoWin->edited())
1034 {
1035 CBuffer buff(text.length()+1);
1036 int i;
1037 for (i = 0; i < text.length(); i++)
1038 {
1039 buff[i] = text[i].unicode();
1040 }
1041 buff[i] = 0;
1042 m_fBkmksChanged = true;
1043 m_anno->setAnno(buff.data());
1044 }
1045 bool found = findNextBookmark(m_anno->value()+1);
1046 if (found)
1047 {
1048 m_annoWin->setName(toQString(m_anno->name()));
1049 m_annoWin->setAnno(toQString(m_anno->anno()));
1050 }
1051 else
1052 {
1053 showEditTools();
1054 }
1055 }
1056}
1057
1058bool QTReaderApp::findNextBookmark(size_t start)
1059{
1060 bool found = false;
1061 for (CList<Bkmk>::iterator iter = pBkmklist->begin(); iter != pBkmklist->end(); iter++)
1062 {
1063 if (iter->value() >= start)
1064 {
1065 if (iter->value() < reader->locate())
1066 {
1067 found = true;
1068 m_anno = iter.pContent();
1069 }
1070 break;
1071 }
1072 }
1073 return found;
1074}
1075
1076void QTReaderApp::addanno()
1077{
1078 if (reader->empty())
1079 {
1080 QMessageBox::information(this, "QTReader", "No file loaded", 1);
1081 }
1082 else
1083 {
1084 m_annoWin->setName("");
1085 m_annoWin->setAnno("");
1086 m_annoWin->setPosn(reader->pagelocate());
1087 m_annoIsEditing = true;
1088 editorStack->raiseWidget( m_annoWin );
1089 m_annoWin->setFocus();
612 } 1090 }
613} 1091}
614 1092
@@ -638,25 +1116,18 @@ void QTReaderApp::editMark()
638 1116
639void QTReaderApp::editCopy() 1117void QTReaderApp::editCopy()
640{ 1118{
641 QClipboard* cb = QApplication::clipboard(); 1119 QClipboard* cb = QApplication::clipboard();
642 QString text; 1120 QString text;
643 int ch; 1121 int ch;
644 unsigned long currentpos = reader->pagelocate(); 1122 unsigned long currentpos = reader->pagelocate();
645 unsigned long endpos = reader->locate(); 1123 unsigned long endpos = reader->locate();
646 reader->jumpto(m_savedpos); 1124 reader->jumpto(m_savedpos);
647 while (reader->locate() < endpos && (ch = reader->getch()) != UEOF) 1125 while (reader->explocate() < endpos && (ch = reader->getch()) != UEOF)
648 { 1126 {
649 text += ch; 1127 text += ch;
650 } 1128 }
651 cb->setText(text); 1129 cb->setText(text);
652// text = cb->text(); 1130 reader->locate(currentpos);
653// if (text)
654// qDebug("The clipboard contains: %s", (const tchar*)text);
655 reader->locate(currentpos);
656#ifndef QT_NO_CLIPBOARD
657// TBD();
658 // reader->copy();
659#endif
660} 1131}
661 1132
662void QTReaderApp::pageup() 1133void QTReaderApp::pageup()
@@ -673,6 +1144,26 @@ void QTReaderApp::stripcr(bool _b)
673{ 1144{
674 reader->setstripcr(_b); 1145 reader->setstripcr(_b);
675} 1146}
1147void QTReaderApp::remap(bool _b)
1148{
1149 reader->setremap(_b);
1150}
1151void QTReaderApp::peanut(bool _b)
1152{
1153 reader->setpeanut(_b);
1154}
1155void QTReaderApp::embolden(bool _b)
1156{
1157 reader->setmakebold(_b);
1158}
1159void QTReaderApp::autofmt(bool _b)
1160{
1161 reader->setautofmt(_b);
1162}
1163void QTReaderApp::textfmt(bool _b)
1164{
1165 reader->settextfmt(_b);
1166}
676void QTReaderApp::striphtml(bool _b) 1167void QTReaderApp::striphtml(bool _b)
677{ 1168{
678 reader->setstriphtml(_b); 1169 reader->setstriphtml(_b);
@@ -689,12 +1180,6 @@ void QTReaderApp::repara(bool _b)
689{ 1180{
690 reader->setrepara(_b); 1181 reader->setrepara(_b);
691} 1182}
692void QTReaderApp::setbold(bool _b)
693{
694 reader->m_bBold = _b;
695 reader->ChangeFont(reader->fontsizes[reader->m_textsize]);
696 reader->refresh();
697}
698void QTReaderApp::dblspce(bool _b) 1183void QTReaderApp::dblspce(bool _b)
699{ 1184{
700 reader->setdblspce(_b); 1185 reader->setdblspce(_b);
@@ -730,9 +1215,9 @@ void QTReaderApp::setoverlap()
730void QTReaderApp::settarget() 1215void QTReaderApp::settarget()
731{ 1216{
732 m_nRegAction = cSetTarget; 1217 m_nRegAction = cSetTarget;
733 QString text = ((reader->m_targetapp.isEmpty()) ? QString("") : reader->m_targetapp) 1218 QString text = ((m_targetapp.isEmpty()) ? QString("") : m_targetapp)
734 + "/" 1219 + "/"
735 + ((reader->m_targetmsg.isEmpty()) ? QString("") : reader->m_targetmsg); 1220 + ((m_targetmsg.isEmpty()) ? QString("") : m_targetmsg);
736 regEdit->setText(text); 1221 regEdit->setText(text);
737 do_regedit(); 1222 do_regedit();
738} 1223}
@@ -743,10 +1228,10 @@ void QTReaderApp::do_overlap(const QString& lcn)
743 unsigned long ulcn = lcn.toULong(&ok); 1228 unsigned long ulcn = lcn.toULong(&ok);
744 if (ok) 1229 if (ok)
745 { 1230 {
746 reader->m_overlap = ulcn; 1231 reader->m_overlap = ulcn;
747 } 1232 }
748 else 1233 else
749 QMessageBox::information(this, "QTReader", "Must be a number"); 1234 QMessageBox::information(this, "QTReader", "Must be a number");
750} 1235}
751 1236
752void QTReaderApp::do_mono(const QString& lcn) 1237void QTReaderApp::do_mono(const QString& lcn)
@@ -755,11 +1240,13 @@ void QTReaderApp::do_mono(const QString& lcn)
755 unsigned long ulcn = lcn.toULong(&ok); 1240 unsigned long ulcn = lcn.toULong(&ok);
756 if (ok) 1241 if (ok)
757 { 1242 {
758 reader->m_charpc = ulcn; 1243 reader->m_charpc = ulcn;
759// reader->setmono(true); 1244 reader->setfont();
1245 reader->refresh();
1246 //reader->setmono(true);
760 } 1247 }
761 else 1248 else
762 QMessageBox::information(this, "QTReader", "Must be a number"); 1249 QMessageBox::information(this, "QTReader", "Must be a number");
763} 1250}
764 1251
765/* 1252/*
@@ -793,7 +1280,7 @@ void QTReaderApp::findNext()
793#else 1280#else
794 QRegExp arg = searchEdit->text(); 1281 QRegExp arg = searchEdit->text();
795#endif 1282#endif
796 CBuffer test; 1283 CDrawBuffer test(&(reader->m_fontControl));
797 size_t start = reader->pagelocate(); 1284 size_t start = reader->pagelocate();
798 reader->jumpto(start); 1285 reader->jumpto(start);
799 reader->buffdoc.getline(&test,reader->width()); 1286 reader->buffdoc.getline(&test,reader->width());
@@ -825,13 +1312,13 @@ void QTReaderApp::regClose()
825} 1312}
826 1313
827#ifdef __ISEARCH 1314#ifdef __ISEARCH
828bool QTReaderApp::dosearch(size_t start, CBuffer& test, const QString& arg) 1315bool QTReaderApp::dosearch(size_t start, CDrawBuffer& test, const QString& arg)
829#else 1316#else
830bool QTReaderApp::dosearch(size_t start, CBuffer& test, const QRegExp& arg) 1317bool QTReaderApp::dosearch(size_t start, CDrawBuffer& test, const QRegExp& arg)
831#endif 1318#endif
832{ 1319{
833 bool ret = true; 1320 bool ret = true;
834 size_t pos = start; 1321 size_t pos = reader->locate();
835 reader->buffdoc.getline(&test,reader->width()); 1322 reader->buffdoc.getline(&test,reader->width());
836#ifdef __ISEARCH 1323#ifdef __ISEARCH
837 while (strstr(test.data(),(const tchar*)arg) == NULL) 1324 while (strstr(test.data(),(const tchar*)arg) == NULL)
@@ -845,15 +1332,15 @@ bool QTReaderApp::dosearch(size_t start, CBuffer& test, const QRegExp& arg)
845 { 1332 {
846 pos = reader->locate(); 1333 pos = reader->locate();
847 if (!reader->buffdoc.getline(&test,reader->width())) 1334 if (!reader->buffdoc.getline(&test,reader->width()))
848 { 1335 {
849 if (QMessageBox::warning(this, "Can't find", searchEdit->text(), 1, 2) == 2) 1336 if (QMessageBox::warning(this, "Can't find", searchEdit->text(), 1, 2) == 2)
850 pos = searchStart; 1337 pos = searchStart;
851 else 1338 else
852 pos = start; 1339 pos = start;
853 ret = false; 1340 ret = false;
854 findClose(); 1341 findClose();
855 break; 1342 break;
856 } 1343 }
857 } 1344 }
858 reader->locate(pos); 1345 reader->locate(pos);
859 return ret; 1346 return ret;
@@ -895,11 +1382,7 @@ void QTReaderApp::search(const QString & arg)
895#else 1382#else
896void QTReaderApp::search() 1383void QTReaderApp::search()
897{ 1384{
898 QRegExp arg = searchEdit->text(); 1385 findNext();
899 CBuffer test;
900 size_t start = reader->pagelocate();
901// reader->jumpto(start);
902 dosearch(start, test, arg);
903} 1386}
904#endif 1387#endif
905 1388
@@ -937,20 +1420,20 @@ void QTReaderApp::openFile( const DocLnk &f )
937 { 1420 {
938 QMessageBox::information(this, "QTReader", "File does not exist"); 1421 QMessageBox::information(this, "QTReader", "File does not exist");
939 } 1422 }
940 1423
941} 1424}
942 1425
943void QTReaderApp::showEditTools() 1426void QTReaderApp::showEditTools()
944{ 1427{
945 if ( !doc ) 1428 if ( !doc )
946 close(); 1429 close();
947// fileSelector->hide(); 1430// fileSelector->hide();
948 menu->show(); 1431//tjw menu->show();
949 editBar->show(); 1432 editBar->show();
950 if ( searchVisible ) 1433 if ( searchVisible )
951 searchBar->show(); 1434 searchBar->show();
952 if ( regVisible ) 1435 if ( regVisible )
953 regBar->show(); 1436 regBar->show();
954 if (m_fontVisible) m_fontBar->show(); 1437 if (m_fontVisible) m_fontBar->show();
955 1438
956 updateCaption(); 1439 updateCaption();
@@ -961,27 +1444,27 @@ void QTReaderApp::showEditTools()
961void QTReaderApp::save() 1444void QTReaderApp::save()
962{ 1445{
963 if ( !doc ) 1446 if ( !doc )
964 return; 1447 return;
965 if ( !editor->edited() ) 1448 if ( !editor->edited() )
966 return; 1449 return;
967 1450
968 QString rt = editor->text(); 1451 QString rt = editor->text();
969 QString pt = rt; 1452 QString pt = rt;
970 1453
971 if ( doc->name().isEmpty() ) { 1454 if ( doc->name().isEmpty() ) {
972 unsigned ispace = pt.find( ' ' ); 1455 unsigned ispace = pt.find( ' ' );
973 unsigned ienter = pt.find( '\n' ); 1456 unsigned ienter = pt.find( '\n' );
974 int i = (ispace < ienter) ? ispace : ienter; 1457 int i = (ispace < ienter) ? ispace : ienter;
975 QString docname; 1458 QString docname;
976 if ( i == -1 ) { 1459 if ( i == -1 ) {
977 if ( pt.isEmpty() ) 1460 if ( pt.isEmpty() )
978 docname = "Empty Text"; 1461 docname = "Empty Text";
979 else 1462 else
980 docname = pt; 1463 docname = pt;
981 } else { 1464 } else {
982 docname = pt.left( i ); 1465 docname = pt.left( i );
983 } 1466 }
984 doc->setName(docname); 1467 doc->setName(docname);
985 } 1468 }
986 FileManager fm; 1469 FileManager fm;
987 fm.saveFile( *doc, rt ); 1470 fm.saveFile( *doc, rt );
@@ -993,9 +1476,9 @@ void QTReaderApp::clear()
993 if (doc != 0) 1476 if (doc != 0)
994 { 1477 {
995// QMessageBox::information(this, "QTReader", "Deleting doc", 1); 1478// QMessageBox::information(this, "QTReader", "Deleting doc", 1);
996 delete doc; 1479 delete doc;
997// QMessageBox::information(this, "QTReader", "Deleted doc", 1); 1480// QMessageBox::information(this, "QTReader", "Deleted doc", 1);
998 doc = 0; 1481 doc = 0;
999 } 1482 }
1000 reader->clear(); 1483 reader->clear();
1001} 1484}
@@ -1003,12 +1486,12 @@ void QTReaderApp::clear()
1003void QTReaderApp::updateCaption() 1486void QTReaderApp::updateCaption()
1004{ 1487{
1005 if ( !doc ) 1488 if ( !doc )
1006 setCaption( tr("Opie Reader") ); 1489 setCaption( tr("QTReader") );
1007 else { 1490 else {
1008 QString s = doc->name(); 1491 QString s = doc->name();
1009 if ( s.isEmpty() ) 1492 if ( s.isEmpty() )
1010 s = tr( "Unnamed" ); 1493 s = tr( "Unnamed" );
1011 setCaption( s + " - " + tr("Opie Reader") ); 1494 setCaption( s + " - " + tr("QTReader") );
1012 } 1495 }
1013} 1496}
1014 1497
@@ -1022,40 +1505,47 @@ void QTReaderApp::setDocument(const QString& fileref)
1022 1505
1023void QTReaderApp::closeEvent( QCloseEvent *e ) 1506void QTReaderApp::closeEvent( QCloseEvent *e )
1024{ 1507{
1025 if (editorStack->visibleWidget() == reader) 1508 if (m_dontSave)
1026 { 1509 {
1027 if (m_fontVisible) 1510 e->accept();
1028 {
1029 m_fontBar->hide();
1030 m_fontVisible = false;
1031 }
1032 if (regVisible)
1033 {
1034 regBar->hide();
1035 regVisible = false;
1036 return;
1037 }
1038 if (searchVisible)
1039 {
1040 searchBar->hide();
1041 searchVisible = false;
1042 return;
1043 }
1044 if (m_fBkmksChanged && pBkmklist != NULL)
1045 {
1046 if (QMessageBox::warning(this, "QTReader", "Save bookmarks?", "Save", "Don't bother") == 0)
1047 savebkmks();
1048 delete pBkmklist;
1049 pBkmklist = NULL;
1050 m_fBkmksChanged = false;
1051 }
1052 bFromDocView = FALSE;
1053 saveprefs();
1054 e->accept();
1055 } 1511 }
1056 else 1512 else
1057 { 1513 {
1058 showEditTools(); 1514 if (editorStack->visibleWidget() == reader)
1515 {
1516 if (m_fontVisible)
1517 {
1518 m_fontBar->hide();
1519 m_fontVisible = false;
1520 }
1521 if (regVisible)
1522 {
1523 regBar->hide();
1524 regVisible = false;
1525 return;
1526 }
1527 if (searchVisible)
1528 {
1529 searchBar->hide();
1530 searchVisible = false;
1531 return;
1532 }
1533 if (m_fBkmksChanged && pBkmklist != NULL)
1534 {
1535 if (QMessageBox::warning(this, "QTReader", "Save bookmarks?", "Save", "Don't bother") == 0)
1536 savebkmks();
1537 delete pBkmklist;
1538 pBkmklist = NULL;
1539 m_fBkmksChanged = false;
1540 }
1541 bFromDocView = FALSE;
1542 saveprefs();
1543 e->accept();
1544 }
1545 else
1546 {
1547 showEditTools();
1548 }
1059 } 1549 }
1060} 1550}
1061 1551
@@ -1077,20 +1567,19 @@ void QTReaderApp::listbkmk()
1077 int cnt = 0; 1567 int cnt = 0;
1078 if (pBkmklist != NULL) 1568 if (pBkmklist != NULL)
1079 { 1569 {
1080 if (m_fBkmksChanged) pBkmklist->sort(); 1570 for (CList<Bkmk>::iterator i = pBkmklist->begin(); i != pBkmklist->end(); i++)
1081 for (CList<Bkmk>::iterator i = pBkmklist->begin(); i != pBkmklist->end(); i++) 1571 {
1082 {
1083#ifdef _UNICODE 1572#ifdef _UNICODE
1084 bkmkselector->insertItem(toQString(i->name())); 1573 bkmkselector->insertItem(toQString(i->name()));
1085#else 1574#else
1086 bkmkselector->insertItem(i->name()); 1575 bkmkselector->insertItem(i->name());
1087#endif 1576#endif
1088 cnt++; 1577 cnt++;
1089 } 1578 }
1090 } 1579 }
1091 if (cnt > 0) 1580 if (cnt > 0)
1092 { 1581 {
1093 menu->hide(); 1582//tjw menu->hide();
1094 editBar->hide(); 1583 editBar->hide();
1095 if (m_fontVisible) m_fontBar->hide(); 1584 if (m_fontVisible) m_fontBar->hide();
1096 if (regVisible) regBar->hide(); 1585 if (regVisible) regBar->hide();
@@ -1120,17 +1609,18 @@ void QTReaderApp::gotobkmk(int ind)
1120{ 1609{
1121 switch (m_nRegAction) 1610 switch (m_nRegAction)
1122 { 1611 {
1123 case cGotoBkmk: 1612 case cGotoBkmk:
1124 reader->locate((*pBkmklist)[ind]->value()); 1613 reader->locate((*pBkmklist)[ind]->value());
1125 break; 1614 break;
1126 case cDelBkmk: 1615 case cDelBkmk:
1127// qDebug("Deleting:%s\n",(*pBkmklist)[ind]->name()); 1616 // qDebug("Deleting:%s\n",(*pBkmklist)[ind]->name());
1128 pBkmklist->erase(ind); 1617 pBkmklist->erase(ind);
1129 m_fBkmksChanged = true; 1618 m_fBkmksChanged = true;
1130 break; 1619 // pBkmklist->sort();
1131 case cRmBkmkFile: 1620 break;
1132 unlink((const char *)Global::applicationFileName("uqtreader",bkmkselector->text(ind))); 1621 case cRmBkmkFile:
1133 break; 1622 unlink((const char *)Global::applicationFileName("uqtreader",bkmkselector->text(ind)));
1623 break;
1134 } 1624 }
1135 showEditTools(); 1625 showEditTools();
1136} 1626}
@@ -1154,9 +1644,9 @@ void QTReaderApp::do_jump(const QString& lcn)
1154 bool ok; 1644 bool ok;
1155 unsigned long ulcn = lcn.toULong(&ok); 1645 unsigned long ulcn = lcn.toULong(&ok);
1156 if (ok) 1646 if (ok)
1157 reader->locate(ulcn); 1647 reader->locate(ulcn);
1158 else 1648 else
1159 QMessageBox::information(this, "QTReader", "Must be a number"); 1649 QMessageBox::information(this, "QTReader", "Must be a number");
1160} 1650}
1161 1651
1162void QTReaderApp::do_regaction() 1652void QTReaderApp::do_regaction()
@@ -1166,23 +1656,23 @@ void QTReaderApp::do_regaction()
1166 switch(m_nRegAction) 1656 switch(m_nRegAction)
1167 { 1657 {
1168 case cAutoGen: 1658 case cAutoGen:
1169 do_autogen(regEdit->text()); 1659 do_autogen(regEdit->text());
1170 break; 1660 break;
1171 case cAddBkmk: 1661 case cAddBkmk:
1172 do_addbkmk(regEdit->text()); 1662 do_addbkmk(regEdit->text());
1173 break; 1663 break;
1174 case cJump: 1664 case cJump:
1175 do_jump(regEdit->text()); 1665 do_jump(regEdit->text());
1176 break; 1666 break;
1177 case cMonoSpace: 1667 case cMonoSpace:
1178 do_mono(regEdit->text()); 1668 do_mono(regEdit->text());
1179 break; 1669 break;
1180 case cOverlap: 1670 case cOverlap:
1181 do_overlap(regEdit->text()); 1671 do_overlap(regEdit->text());
1182 break; 1672 break;
1183 case cSetTarget: 1673 case cSetTarget:
1184 do_settarget(regEdit->text()); 1674 do_settarget(regEdit->text());
1185 break; 1675 break;
1186 } 1676 }
1187 reader->restore(); 1677 reader->restore();
1188// editBar->show(); 1678// editBar->show();
@@ -1194,14 +1684,14 @@ void QTReaderApp::do_settarget(const QString& _txt)
1194 int ind = _txt.find('/'); 1684 int ind = _txt.find('/');
1195 if (ind == -1) 1685 if (ind == -1)
1196 { 1686 {
1197 reader->m_targetapp = ""; 1687 m_targetapp = "";
1198 reader->m_targetmsg = ""; 1688 m_targetmsg = "";
1199 QMessageBox::information(this, "QTReader", "Format is\nappname/messagename"); 1689 QMessageBox::information(this, "QTReader", "Format is\nappname/messagename");
1200 } 1690 }
1201 else 1691 else
1202 { 1692 {
1203 reader->m_targetapp = _txt.left(ind); 1693 m_targetapp = _txt.left(ind);
1204 reader->m_targetmsg = _txt.right(_txt.length()-ind-1); 1694 m_targetmsg = _txt.right(_txt.length()-ind-1);
1205 } 1695 }
1206} 1696}
1207 1697
@@ -1209,30 +1699,40 @@ void QTReaderApp::setfont()
1209{ 1699{
1210 for (int i = 1; i <= m_fontSelector->count(); i++) 1700 for (int i = 1; i <= m_fontSelector->count(); i++)
1211 { 1701 {
1212 if (m_fontSelector->text(i) == reader->m_fontname) 1702 if (m_fontSelector->text(i) == reader->m_fontname)
1213 { 1703 {
1214 m_fontSelector->setCurrentItem(i); 1704 m_fontSelector->setCurrentItem(i);
1215 break; 1705 break;
1216 } 1706 }
1217 } 1707 }
1218 m_fontBar->show(); 1708 m_fontBar->show();
1219 m_fontVisible = true; 1709 m_fontVisible = true;
1220} 1710}
1221 1711
1222void QTReaderApp::do_setfont(const QString& lcn) 1712void QTReaderApp::setfontHelper(const QString& lcn, int size = 0)
1223{ 1713{
1714 if (size == 0) size = reader->m_fontControl.currentsize();
1224 QFont f(lcn, 10 /*, QFont::Bold*/); 1715 QFont f(lcn, 10 /*, QFont::Bold*/);
1225 bkmkselector->setFont( f ); 1716 bkmkselector->setFont( f );
1226 regEdit->setFont( f ); 1717 regEdit->setFont( f );
1227 searchEdit->setFont( f ); 1718 searchEdit->setFont( f );
1719 m_annoWin->setFont( f );
1228 reader->m_fontname = lcn; 1720 reader->m_fontname = lcn;
1229 reader->ChangeFont(reader->fontsizes[reader->m_textsize]); 1721 if (!reader->ChangeFont(size))
1722 {
1723 reader->ChangeFont(size);
1724 }
1230 reader->refresh(); 1725 reader->refresh();
1231 m_fontBar->hide(); 1726 m_fontBar->hide();
1232 m_fontVisible = false; 1727 m_fontVisible = false;
1233 showEditTools(); 1728 showEditTools();
1234} 1729}
1235 1730
1731void QTReaderApp::do_setfont(const QString& lcn)
1732{
1733 setfontHelper(lcn);
1734}
1735
1236void QTReaderApp::do_autogen(const QString& regText) 1736void QTReaderApp::do_autogen(const QString& regText)
1237{ 1737{
1238 unsigned long fs, ts; 1738 unsigned long fs, ts;
@@ -1259,9 +1759,9 @@ pbar->resize(width(), editBar->height());
1259 if (pc != lastpc) 1759 if (pc != lastpc)
1260 { 1760 {
1261 pbar->setProgress(pc); 1761 pbar->setProgress(pc);
1262 qApp->processEvents(); 1762 qApp->processEvents();
1263 if (reader->locate() != lcn) reader->jumpto(lcn); 1763 if (reader->locate() != lcn) reader->jumpto(lcn);
1264 reader->setFocus(); 1764 reader->setFocus();
1265 lastpc = pc; 1765 lastpc = pc;
1266 } 1766 }
1267 i = reader->buffdoc.getpara(buff); 1767 i = reader->buffdoc.getpara(buff);
@@ -1270,8 +1770,9 @@ pbar->resize(width(), editBar->height());
1270#else 1770#else
1271 if (re.match(buff.data()) != -1) 1771 if (re.match(buff.data()) != -1)
1272#endif 1772#endif
1273 pBkmklist->push_back(Bkmk(buff.data(),lcn)); 1773 pBkmklist->push_back(Bkmk(buff.data(), NULL, lcn));
1274 } 1774 }
1775 pBkmklist->sort();
1275 pbar->setProgress(100); 1776 pbar->setProgress(100);
1276 qApp->processEvents(); 1777 qApp->processEvents();
1277 pbar->hide(); 1778 pbar->hide();
@@ -1286,14 +1787,15 @@ void QTReaderApp::saveprefs()
1286 reader->m_lastposn = reader->pagelocate(); 1787 reader->m_lastposn = reader->pagelocate();
1287 1788
1288 config.writeEntry( "StripCr", reader->bstripcr ); 1789 config.writeEntry( "StripCr", reader->bstripcr );
1790 config.writeEntry( "AutoFmt", reader->bautofmt );
1791 config.writeEntry( "TextFmt", reader->btextfmt );
1289 config.writeEntry( "StripHtml", reader->bstriphtml ); 1792 config.writeEntry( "StripHtml", reader->bstriphtml );
1290 config.writeEntry( "Dehyphen", reader->bdehyphen ); 1793 config.writeEntry( "Dehyphen", reader->bdehyphen );
1291 config.writeEntry( "Unindent", reader->bunindent ); 1794 config.writeEntry( "Unindent", reader->bunindent );
1292 config.writeEntry( "Repara", reader->brepara ); 1795 config.writeEntry( "Repara", reader->brepara );
1293 config.writeEntry( "DoubleSpace", reader->bdblspce ); 1796 config.writeEntry( "DoubleSpace", reader->bdblspce );
1294 config.writeEntry( "Indent", reader->bindenter ); 1797 config.writeEntry( "Indent", reader->bindenter );
1295 config.writeEntry( "FontSize", (int)(reader->fontsizes[reader->m_textsize]) ); 1798 config.writeEntry( "FontSize", (int)(reader->m_fontControl.currentsize()) );
1296 config.writeEntry( "Bold", reader->m_bBold );
1297 config.writeEntry( "ScrollDelay", reader->m_delay); 1799 config.writeEntry( "ScrollDelay", reader->m_delay);
1298 config.writeEntry( "LastFile", reader->m_lastfile ); 1800 config.writeEntry( "LastFile", reader->m_lastfile );
1299 config.writeEntry( "LastPosn", (int)(reader->pagelocate()) ); 1801 config.writeEntry( "LastPosn", (int)(reader->pagelocate()) );
@@ -1303,8 +1805,16 @@ void QTReaderApp::saveprefs()
1303 config.writeEntry( "Encoding", reader->m_encd ); 1805 config.writeEntry( "Encoding", reader->m_encd );
1304 config.writeEntry( "CharSpacing", reader->m_charpc ); 1806 config.writeEntry( "CharSpacing", reader->m_charpc );
1305 config.writeEntry( "Overlap", (int)(reader->m_overlap) ); 1807 config.writeEntry( "Overlap", (int)(reader->m_overlap) );
1306 config.writeEntry( "TargetApp", reader->m_targetapp ); 1808 config.writeEntry( "TargetApp", m_targetapp );
1307 config.writeEntry( "TargetMsg", reader->m_targetmsg ); 1809 config.writeEntry( "TargetMsg", m_targetmsg );
1810 config.writeEntry( "TwoTouch", m_twoTouch );
1811 config.writeEntry( "Annotation", m_doAnnotation);
1812 config.writeEntry( "Dictionary", m_doDictionary);
1813 config.writeEntry( "Clipboard", m_doClipboard);
1814 config.writeEntry( "SpaceTarget", m_spaceTarget);
1815 config.writeEntry( "Remap", reader->bremap );
1816 config.writeEntry( "Peanut", reader->bpeanut );
1817 config.writeEntry( "MakeBold", reader->bmakebold );
1308} 1818}
1309 1819
1310void QTReaderApp::indentplus() 1820void QTReaderApp::indentplus()
@@ -1334,40 +1844,40 @@ void info_cb(Fl_Widget* o, void* _data)
1334 1844
1335 if (infowin == NULL) 1845 if (infowin == NULL)
1336 { 1846 {
1337 1847
1338 infowin = new Fl_Window(160,240); 1848 infowin = new Fl_Window(160,240);
1339 filename = new Fl_Output(45,5,110,14,"Filename"); 1849 filename = new Fl_Output(45,5,110,14,"Filename");
1340 filesize = new Fl_Output(45,25,110,14,"Filesize"); 1850 filesize = new Fl_Output(45,25,110,14,"Filesize");
1341 textsize = new Fl_Output(45,45,110,14,"Textsize"); 1851 textsize = new Fl_Output(45,45,110,14,"Textsize");
1342 comprat = new CBar(45,65,110,14,"Ratio %"); 1852 comprat = new CBar(45,65,110,14,"Ratio %");
1343 posn = new Fl_Output(45,85,110,14,"Location"); 1853 posn = new Fl_Output(45,85,110,14,"Location");
1344 frcn = new CBar(45,105,110,14,"% Read"); 1854 frcn = new CBar(45,105,110,14,"% Read");
1345 about = new Fl_Multiline_Output(5,125,150,90); 1855 about = new Fl_Multiline_Output(5,125,150,90);
1346 about->value("TWReader - $Name$\n\nA file reader program for the Agenda\n\nReads text, PalmDoc and ppms format files"); 1856 about->value("TWReader - $Name$\n\nA file reader program for the Agenda\n\nReads text, PalmDoc and ppms format files");
1347 Fl_Button *jump_accept = new Fl_Button(62,220,35,14,"Okay"); 1857 Fl_Button *jump_accept = new Fl_Button(62,220,35,14,"Okay");
1348 infowin->set_modal(); 1858 infowin->set_modal();
1349 } 1859 }
1350 if (((reader_ui *)_data)->g_filename[0] != '\0') 1860 if (((reader_ui *)_data)->g_filename[0] != '\0')
1351 { 1861 {
1352 unsigned long fs,ts; 1862 unsigned long fs,ts;
1353 tchar sz[20]; 1863 tchar sz[20];
1354 ((reader_ui *)_data)->input->sizes(fs,ts); 1864 ((reader_ui *)_data)->input->sizes(fs,ts);
1355 unsigned long pl = ((reader_ui *)_data)->input->locate(); 1865 unsigned long pl = ((reader_ui *)_data)->input->locate();
1356 1866
1357 filename->value(((reader_ui *)_data)->g_filename); 1867 filename->value(((reader_ui *)_data)->g_filename);
1358 1868
1359 sprintf(sz,"%u",fs); 1869 sprintf(sz,"%u",fs);
1360 filesize->value(sz); 1870 filesize->value(sz);
1361 1871
1362 sprintf(sz,"%u",ts); 1872 sprintf(sz,"%u",ts);
1363 textsize->value(sz); 1873 textsize->value(sz);
1364 1874
1365 comprat->value(100-(100*fs + (ts >> 1))/ts); 1875 comprat->value(100-(100*fs + (ts >> 1))/ts);
1366 1876
1367 sprintf(sz,"%u",pl); 1877 sprintf(sz,"%u",pl);
1368 posn->value(sz); 1878 posn->value(sz);
1369 1879
1370 frcn->value((100*pl + (ts >> 1))/ts); 1880 frcn->value((100*pl + (ts >> 1))/ts);
1371 } 1881 }
1372 infowin->show(); 1882 infowin->show();
1373} 1883}
@@ -1377,27 +1887,27 @@ void QTReaderApp::savebkmks()
1377{ 1887{
1378 if (pBkmklist != NULL) 1888 if (pBkmklist != NULL)
1379 { 1889 {
1380 BkmkFile bf((const char *)Global::applicationFileName("uqtreader",reader->m_string), true); 1890 BkmkFile bf((const char *)Global::applicationFileName("uqtreader",reader->m_string), true);
1381 bf.write(*pBkmklist); 1891 bf.write(*pBkmklist);
1382 } 1892 }
1383 m_fBkmksChanged = false; 1893 m_fBkmksChanged = false;
1384} 1894}
1385 1895
1386void QTReaderApp::readbkmks() 1896void QTReaderApp::readbkmks()
1387{ 1897{
1388 if (pBkmklist != NULL) 1898 if (pBkmklist != NULL)
1389 { 1899 {
1390 delete pBkmklist; 1900 delete pBkmklist;
1391 } 1901 }
1392 BkmkFile bf((const char *)Global::applicationFileName("uqtreader",reader->m_string)); 1902 BkmkFile bf((const char *)Global::applicationFileName("uqtreader",reader->m_string));
1393 pBkmklist = bf.readall(); 1903 pBkmklist = bf.readall();
1394 m_fBkmksChanged = false; 1904 m_fBkmksChanged = bf.upgraded();
1395 if (pBkmklist == NULL) 1905 if (pBkmklist == NULL)
1396 { 1906 {
1397 pBkmklist = reader->getbkmklist(); 1907 pBkmklist = reader->getbkmklist();
1398 } 1908 }
1399 if (pBkmklist != NULL) 1909 if (pBkmklist != NULL)
1400 pBkmklist->sort(); 1910 pBkmklist->sort();
1401} 1911}
1402 1912
1403void QTReaderApp::addbkmk() 1913void QTReaderApp::addbkmk()
@@ -1409,25 +1919,111 @@ void QTReaderApp::addbkmk()
1409 1919
1410void QTReaderApp::do_addbkmk(const QString& text) 1920void QTReaderApp::do_addbkmk(const QString& text)
1411{ 1921{
1412 if (text.isEmpty()) 1922 if (text.isEmpty())
1413 { 1923 {
1414 QMessageBox::information(this, "QTReader", "Need a name for the bookmark\nSelect add again", 1); 1924 QMessageBox::information(this, "QTReader", "Need a name for the bookmark\nSelect add again", 1);
1415 } 1925 }
1416 else 1926 else
1417 { 1927 {
1418 if (pBkmklist == NULL) pBkmklist = new CList<Bkmk>; 1928 if (pBkmklist == NULL) pBkmklist = new CList<Bkmk>;
1419#ifdef _UNICODE 1929#ifdef _UNICODE
1420 CBuffer buff; 1930 CBuffer buff;
1421 int i = 0; 1931 int i = 0;
1422 for (i = 0; i < text.length(); i++) 1932 for (i = 0; i < text.length(); i++)
1423 { 1933 {
1424 buff[i] = text[i].unicode(); 1934 buff[i] = text[i].unicode();
1425 } 1935 }
1426 buff[i] = 0; 1936 buff[i] = 0;
1427 pBkmklist->push_front(Bkmk(buff.data(), reader->pagelocate())); 1937 pBkmklist->push_front(Bkmk(buff.data(), NULL, reader->pagelocate()));
1428#else 1938#else
1429 pBkmklist->push_front(Bkmk((const tchar*)text,reader->pagelocate())); 1939 pBkmklist->push_front(Bkmk((const tchar*)text,reader->pagelocate()));
1430#endif 1940#endif
1431 m_fBkmksChanged = true; 1941 m_fBkmksChanged = true;
1432 } 1942 pBkmklist->sort();
1943 }
1944}
1945
1946void QTReaderApp::OnRedraw()
1947{
1948 if (pBkmklist != NULL)
1949 {
1950 bool found = findNextBookmark(reader->pagelocate());
1951 m_bkmkAvail->setEnabled(found);
1952 }
1953}
1954
1955void QTReaderApp::showAnnotation()
1956{
1957 m_annoWin->setName(toQString(m_anno->name()));
1958 m_annoWin->setAnno(toQString(m_anno->anno()));
1959 m_annoIsEditing = false;
1960 editorStack->raiseWidget( m_annoWin );
1961 m_annoWin->setFocus();
1962}
1963
1964void QTReaderApp::OnWordSelected(const QString& wrd, size_t posn, const QString& line)
1965{
1966// qDebug("OnWordSelected(%u):%s", posn, (const char*)wrd);
1967
1968 if (m_doClipboard)
1969 {
1970 QClipboard* cb = QApplication::clipboard();
1971 cb->setText(wrd);
1972 if (wrd.length() > 10)
1973 {
1974 Global::statusMessage(wrd.left(8) + "..");
1975 }
1976 else
1977 {
1978 Global::statusMessage(wrd);
1979 }
1980 }
1981 if (m_doAnnotation)
1982 {
1983 //addAnno(wrd, "Need to be able to edit this", posn);
1984 m_annoWin->setName(line);
1985 m_annoWin->setAnno("");
1986 m_annoWin->setPosn(posn);
1987 m_annoIsEditing = true;
1988 editorStack->raiseWidget( m_annoWin );
1989 }
1990 if (m_doDictionary)
1991 {
1992 if (!m_targetapp.isEmpty() && !m_targetmsg.isEmpty())
1993 {
1994 QCopEnvelope e(("QPE/Application/"+m_targetapp).utf8(), (m_targetmsg+"(QString)").utf8());
1995 e << wrd;
1996 }
1997 }
1433} 1998}
1999
2000void QTReaderApp::OnActionPressed()
2001{
2002 switch (m_spaceTarget)
2003 {
2004 case cesOpenFile:
2005 {
2006 fileOpen();
2007 }
2008 break;
2009 case cesAutoScroll:
2010 {
2011 reader->setautoscroll(!reader->m_autoScroll);
2012 setScrollState(reader->m_autoScroll);
2013 }
2014 break;
2015 case cesActionMark:
2016 {
2017 addbkmk();
2018 }
2019 break;
2020 default:
2021 {
2022 qDebug("Unknown ActionType:%u", m_spaceTarget);
2023 }
2024 break;
2025 }
2026}
2027
2028void QTReaderApp::setTwoTouch(bool _b) { reader->setTwoTouch(_b); }
2029void 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 @@
23//#define __ISEARCH 23//#define __ISEARCH
24 24
25#define MAX_ENCODING 6 25#define MAX_ENCODING 6
26#define MAX_ACTIONS 3
26 27
27#include <qmainwindow.h> 28#include <qmainwindow.h>
28#include "QTReader.h" 29#include "CExpander.h"
29#include <qlist.h> 30#include <qlist.h>
30#include <qpe/filemanager.h> 31#include <qpe/filemanager.h>
31#include <qmap.h> 32#include <qmap.h>
32#include <qlineedit.h> 33#include <qlineedit.h>
33#include <qstack.h> 34#include <qstack.h>
34#include <qlistbox.h> 35#include <qlistbox.h>
35#include "Queue.h" 36//#include "Queue.h"
36 37
37class QWidgetStack; 38class QWidgetStack;
38class QToolButton; 39class QToolButton;
39class QPopupMenu; 40class QPopupMenu;
40class QToolBar; 41class QToolBar;
42class QPEToolBar;
41class CBkmkSelector; 43class CBkmkSelector;
42class QProgressBar; 44class QProgressBar;
43class QAction; 45class QAction;
46class CAnnoEdit;
47class QFloatBar;
48class CDrawBuffer;
49class QTReader;
50
51enum ActionTypes
52{
53 cesOpenFile = 0,
54 cesAutoScroll,
55 cesActionMark
56};
44 57
45#ifdef __ISEARCH 58#ifdef __ISEARCH
46struct searchrecord 59struct searchrecord
@@ -58,6 +71,7 @@ class QTReaderApp : public QMainWindow
58 Q_OBJECT 71 Q_OBJECT
59 72
60 unsigned long m_savedpos; 73 unsigned long m_savedpos;
74 bool m_annoIsEditing;
61 75
62 public: 76 public:
63 QTReaderApp( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); 77 QTReaderApp( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
@@ -68,6 +82,10 @@ class QTReaderApp : public QMainWindow
68 void setScrollState(bool _b); 82 void setScrollState(bool _b);
69 83
70 protected: 84 protected:
85 void setfontHelper(const QString& lcn, int size = 0);
86 QAction* m_bkmkAvail;
87 CAnnoEdit* m_annoWin;
88 Bkmk* m_anno;
71 void closeEvent( QCloseEvent *e ); 89 void closeEvent( QCloseEvent *e );
72 void readbkmks(); 90 void readbkmks();
73 void do_mono(const QString&); 91 void do_mono(const QString&);
@@ -75,11 +93,36 @@ class QTReaderApp : public QMainWindow
75 void do_overlap(const QString&); 93 void do_overlap(const QString&);
76 void do_settarget(const QString&); 94 void do_settarget(const QString&);
77 int EncNameToInt(const QString&); 95 int EncNameToInt(const QString&);
78 void saveprefs(); 96 ActionTypes ActNameToInt(const QString&);
97 bool m_doAnnotation;
98 bool m_doDictionary;
99 bool m_doClipboard;
79 100
101 public:
102 void saveprefs();
80private slots: 103private slots:
104 void setTwoTouch(bool _b);
105 void restoreFocus();
106 void OnAnnotation(bool _b)
107 {
108 m_doAnnotation = _b;
109 }
110 void OnDictionary(bool _b)
111 {
112 m_doDictionary = _b;
113 }
114 void OnClipboard(bool _b)
115 {
116 m_doClipboard = _b;
117 }
118 void OnWordSelected(const QString&, size_t, const QString&);
119 void addAnno(const QString&, const QString&, size_t);
120 void addAnno(const QString&, const QString&);
121 void addanno();
122 void showAnnotation();
81 void do_setfont(const QString&); 123 void do_setfont(const QString&);
82 void encodingSelected(QAction*); 124 void encodingSelected(QAction*);
125 void buttonActionSelected(QAction*);
83 void msgHandler(const QCString&, const QByteArray&); 126 void msgHandler(const QCString&, const QByteArray&);
84 void monospace(bool); 127 void monospace(bool);
85 void jump(); 128 void jump();
@@ -127,11 +170,15 @@ private slots:
127 void showEditTools(); 170 void showEditTools();
128 171
129 void stripcr(bool); 172 void stripcr(bool);
173 void peanut(bool _b);
174 void remap(bool);
175 void embolden(bool);
176 void autofmt(bool);
177 void textfmt(bool);
130 void striphtml(bool); 178 void striphtml(bool);
131 void dehyphen(bool); 179 void dehyphen(bool);
132 void unindent(bool); 180 void unindent(bool);
133 void repara(bool); 181 void repara(bool);
134 void setbold(bool);
135 void dblspce(bool); 182 void dblspce(bool);
136 void pagemode(bool); 183 void pagemode(bool);
137 // void gotobkmk(const QString& bm); 184 // void gotobkmk(const QString& bm);
@@ -141,8 +188,11 @@ private slots:
141 void do_delmark(); 188 void do_delmark();
142 void do_autogen(); 189 void do_autogen();
143 void do_regaction(); 190 void do_regaction();
191 void OnRedraw();
192 void OnActionPressed();
144 193
145 private: 194 private:
195 QString m_targetapp, m_targetmsg;
146 void listbkmk(); 196 void listbkmk();
147 void do_regedit(); 197 void do_regedit();
148 void colorChanged( const QColor &c ); 198 void colorChanged( const QColor &c );
@@ -150,6 +200,7 @@ private slots:
150 void updateCaption(); 200 void updateCaption();
151 void do_autogen(const QString&); 201 void do_autogen(const QString&);
152 void do_addbkmk(const QString&); 202 void do_addbkmk(const QString&);
203 bool findNextBookmark(size_t start);
153 204
154 private: 205 private:
155 206
@@ -157,24 +208,29 @@ private slots:
157 208
158 QAction* m_EncodingAction[MAX_ENCODING]; 209 QAction* m_EncodingAction[MAX_ENCODING];
159 210
211 QAction* m_buttonAction[MAX_ACTIONS];
212
160 CBkmkSelector* bkmkselector; 213 CBkmkSelector* bkmkselector;
161 214
215 ActionTypes m_spaceTarget;
162 size_t searchStart; 216 size_t searchStart;
163#ifdef __ISEARCH 217#ifdef __ISEARCH
164 QStack<searchrecord>* searchStack; 218 QStack<searchrecord>* searchStack;
165 bool dosearch(size_t start, CBuffer& test, const QString& arg); 219 bool dosearch(size_t start, CDrawBuffer& test, const QString& arg);
166#else 220#else
167 bool dosearch(size_t start, CBuffer& test, const QRegExp& arg); 221 bool dosearch(size_t start, CDrawBuffer& test, const QRegExp& arg);
168#endif 222#endif
169 QWidgetStack *editorStack; 223 QWidgetStack *editorStack;
170 QTReader* reader; 224 QTReader* reader;
171 QComboBox* m_fontSelector; 225 QComboBox* m_fontSelector;
172 QToolBar *menu, *editBar, *searchBar, *regBar, *m_fontBar; 226 QPEToolBar /* *menu,*/ *editBar;
227 QFloatBar *searchBar, *regBar/*, *m_fontBar*/;
228 QToolBar /* *searchBar, *regBar,*/ *m_fontBar;
173 QLineEdit *searchEdit, *regEdit; 229 QLineEdit *searchEdit, *regEdit;
174 DocLnk *doc; 230 DocLnk *doc;
175 bool searchVisible; 231 bool searchVisible;
176 bool regVisible; 232 bool regVisible;
177 bool m_fontVisible; 233 bool m_fontVisible, m_twoTouch;
178 bool bFromDocView; 234 bool bFromDocView;
179 static unsigned long m_uid; 235 static unsigned long m_uid;
180 long unsigned get_unique_id() { return m_uid++; } 236 long unsigned get_unique_id() { return m_uid++; }
@@ -192,6 +248,7 @@ private slots:
192 bool m_fBkmksChanged; 248 bool m_fBkmksChanged;
193 int m_nRegAction; 249 int m_nRegAction;
194 QString m_autogenstr; 250 QString m_autogenstr;
251 bool m_dontSave;
195}; 252};
196 253
197const int cAutoGen = 0; 254const 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 @@
1#ifndef __STYLECONSTS_H
2#define __STYLECONSTS_H
3
4typedef unsigned short StyleType;
5
6class CStyle
7{
8// 15 14 13-5 4 3 2 1 0
9//bold italic spare align align fs fs fs
10 static const StyleType m_Bold = 1 << 15;
11 static const StyleType m_Italic = 1 << 14;
12 static const StyleType m_FontMask = 7;
13 static const StyleType m_FontBase = 3;
14
15 static const StyleType m_AlignShift = 3;
16 static const StyleType m_AlignMask = 3 << m_AlignShift;
17 static const StyleType m_EveryBit = 0xffff;
18
19
20 StyleType sty;
21
22 void unjustify() { sty &= m_EveryBit ^ m_AlignMask; }
23 unsigned char red, green, blue;
24 unsigned long data;
25 bool isLink;
26 public:
27 unsigned char Red() { return red; }
28 unsigned char Green() { return green; }
29 unsigned char Blue() { return blue; }
30 void setColour(unsigned char r, unsigned char g, unsigned char b)
31 {
32 red = r;
33 green = g;
34 blue = b;
35 }
36 static const StyleType m_AlignLeft = 0;
37 static const StyleType m_AlignRight = 1 << m_AlignShift;
38 static const StyleType m_AlignCentre = 2 << m_AlignShift;
39 static const StyleType m_AlignJustify = 3 << m_AlignShift;
40 CStyle()
41 :
42 sty(m_FontBase),
43 red(0), green(0), blue(0),
44 data(0), isLink(false)
45 {}
46// CStyle(const int _fs) : sty(m_FontBase+_fs) {}
47
48 void unset()
49 {
50 sty = m_FontBase;
51 red = green = blue = 0;
52 data = 0;
53 isLink = false;
54 }
55
56 void setBold() { sty |= m_Bold; }
57 void setItalic() { sty |= m_Italic; }
58 void unsetBold() { sty &= m_EveryBit ^ m_Bold; }
59 void unsetItalic() { sty &= m_EveryBit ^ m_Italic; }
60 bool isBold() { return ((sty & m_Bold) != 0); }
61 bool isItalic() { return ((sty & m_Italic) != 0); }
62
63 void setLeftJustify()
64 {
65 unjustify();
66 sty |= m_AlignLeft;
67 }
68 void setRightJustify()
69 {
70 unjustify();
71 sty |= m_AlignRight;
72 }
73 void setCentreJustify()
74 {
75 unjustify();
76 sty |= m_AlignCentre;
77 }
78 void setFullJustify()
79 {
80 unjustify();
81 sty |= m_AlignJustify;
82 }
83 StyleType getJustify()
84 {
85 return sty & m_AlignMask;
86 }
87
88 void setFontSize(int _fs)
89 {
90 sty &= m_EveryBit ^ m_FontMask;
91 sty |= m_FontBase + _fs;
92 }
93 int getFontSize()
94 {
95 return (sty & m_FontMask) - m_FontBase;
96 }
97 bool operator!=(const CStyle& rhs)
98 {
99 return
100 (
101 (sty != rhs.sty) || (red != rhs.red) || (green != rhs.green) ||
102 (blue != rhs.blue) ||
103 (data != rhs.data) ||
104 (isLink != rhs.isLink)
105 );
106 }
107 void setLink(bool _l) { isLink = _l; }
108 bool getLink() { return isLink; }
109 void setData(unsigned long _d) { data = _d; }
110 unsigned long getData() { return data; }
111};
112
113#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 @@
1#ifndef __Text_h 1#ifndef __Text_h
2#define __Text_h 2#define __Text_h
3#include <stdio.h> 3#include <stdio.h>
4#include "zlib/zlib.h" 4#include <zlib.h>
5//#include <zlib.h>
6#include <sys/stat.h> 5#include <sys/stat.h>
7 6
8#include "CExpander.h" 7#include "CExpander.h"
@@ -32,5 +31,9 @@ public:
32 { 31 {
33 _text = _file = fsize; 32 _text = _file = fsize;
34 } 33 }
34 virtual MarkupType PreferredMarkup()
35 {
36 return cTEXT;
37 }
35}; 38};
36#endif 39#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
17#include <qlayout.h> 17#include <qlayout.h>
18 18
19fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags fl , const QString filter, const QString iPath ) 19fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags fl , const QString filter, const QString iPath )
20 : QDialog( parent, name, modal, fl ) 20 : QDialog( parent, name, modal, fl ), filterspec(QDir::All)
21{ 21{
22// showMaximized(); 22// showMaximized();
23 if ( !name ) 23 if ( !name )
@@ -28,8 +28,16 @@ fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags
28 28
29 buttonOk = new QPushButton( this, "buttonOk" ); 29 buttonOk = new QPushButton( this, "buttonOk" );
30 buttonOk->setFixedSize( 25, 25 ); 30 buttonOk->setFixedSize( 25, 25 );
31 buttonOk->setAutoDefault( false );
31 buttonOk->setText( tr( "/" ) ); 32 buttonOk->setText( tr( "/" ) );
32 33
34 buttonShowHidden = new QPushButton( this, "buttonShowHidden" );
35// buttonShowHidden->setFixedSize( 50, 25 );
36 buttonShowHidden->setText( tr( "Hidden" ) );
37 buttonShowHidden->setAutoDefault( false );
38 buttonShowHidden->setToggleButton( true );
39 buttonShowHidden->setOn( false );
40
33 dirLabel = new QLabel(this, "DirLabel"); 41 dirLabel = new QLabel(this, "DirLabel");
34 dirLabel->setText(currentDir.canonicalPath()); 42 dirLabel->setText(currentDir.canonicalPath());
35 43
@@ -38,10 +46,10 @@ fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags
38 ListView->setSorting( 2, FALSE); 46 ListView->setSorting( 2, FALSE);
39 ListView->addColumn( tr( "Size" ) ); 47 ListView->addColumn( tr( "Size" ) );
40 ListView->setSelectionMode(QListView::Single); 48 ListView->setSelectionMode(QListView::Single);
41
42 ListView->setAllColumnsShowFocus( TRUE ); 49 ListView->setAllColumnsShowFocus( TRUE );
43 50
44 // signals and slots connections 51 // signals and slots connections
52 connect( buttonShowHidden, SIGNAL( toggled(bool) ), this, SLOT( setHidden(bool) ) );
45 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( OnRoot() ) ); 53 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( OnRoot() ) );
46 connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) ); 54 connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) );
47 connect( ListView, SIGNAL(clicked( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); 55 connect( ListView, SIGNAL(clicked( QListViewItem*)), SLOT(listClicked(QListViewItem *)) );
@@ -52,6 +60,7 @@ fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags
52 QVBoxLayout* grid = new QVBoxLayout(this); 60 QVBoxLayout* grid = new QVBoxLayout(this);
53 QHBoxLayout* hgrid = new QHBoxLayout(grid); 61 QHBoxLayout* hgrid = new QHBoxLayout(grid);
54 hgrid->addWidget(dirLabel,1); 62 hgrid->addWidget(dirLabel,1);
63 hgrid->addWidget(buttonShowHidden);
55 hgrid->addWidget(buttonOk); 64 hgrid->addWidget(buttonOk);
56 grid->addWidget(ListView,1); 65 grid->addWidget(ListView,1);
57 66
@@ -85,14 +94,14 @@ void fileBrowser::populateList()
85 ListView->clear(); 94 ListView->clear();
86//qDebug(currentDir.canonicalPath()); 95//qDebug(currentDir.canonicalPath());
87// currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::NoSymLinks ); 96// currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::NoSymLinks );
88 currentDir.setFilter( QDir::All ); 97 currentDir.setFilter( filterspec );
89 currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); 98 currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst);
90 currentDir.setMatchAllDirs(TRUE); 99 currentDir.setMatchAllDirs(TRUE);
91 100
92 currentDir.setNameFilter(filterStr); 101 currentDir.setNameFilter(filterStr);
93// currentDir.setNameFilter("*.txt;*.etx"); 102// currentDir.setNameFilter("*.txt;*.etx");
94 QString fileL, fileS; 103 QString fileL, fileS;
95 const QFileInfoList *list = currentDir.entryInfoList(QDir::All); 104 const QFileInfoList *list = currentDir.entryInfoList();
96 QFileInfoListIterator it(*list); 105 QFileInfoListIterator it(*list);
97 QFileInfo *fi; 106 QFileInfo *fi;
98 while ( (fi=it.current()) ) 107 while ( (fi=it.current()) )
@@ -115,6 +124,7 @@ void fileBrowser::populateList()
115 } 124 }
116 ListView->setSorting( 2, FALSE); 125 ListView->setSorting( 2, FALSE);
117 dirLabel->setText("Current Directory:\n"+currentDir.canonicalPath()); 126 dirLabel->setText("Current Directory:\n"+currentDir.canonicalPath());
127 ListView->setFocus();
118} 128}
119 129
120void fileBrowser::upDir() 130void fileBrowser::upDir()
@@ -183,3 +193,12 @@ void fileBrowser::OnCancel()
183{ 193{
184 reject(); 194 reject();
185} 195}
196
197void fileBrowser::setHidden(bool _hidden)
198{
199 if (_hidden)
200 filterspec = QDir::All | QDir::Hidden;
201 else
202 filterspec = QDir::All;
203 populateList();
204}
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:
40 ~fileBrowser(); 40 ~fileBrowser();
41 41
42 QPushButton* buttonOk; 42 QPushButton* buttonOk;
43 QPushButton* buttonShowHidden;
43 QtrListView* ListView; 44 QtrListView* ListView;
44 QPushButton* buttonCancel; 45 QPushButton* buttonCancel;
45 QLabel *dirLabel; 46 QLabel *dirLabel;
@@ -47,6 +48,8 @@ public:
47 QDir currentDir; 48 QDir currentDir;
48 QFile file; 49 QFile file;
49 QStringList fileList; 50 QStringList fileList;
51 int filterspec;
52// QDir::FilterSpec filterspec;
50 53
51//QListViewItem * item; 54//QListViewItem * item;
52public slots: 55public slots:
@@ -59,6 +62,7 @@ private slots:
59 void listClicked(QListViewItem *); 62 void listClicked(QListViewItem *);
60 void OnRoot(); 63 void OnRoot();
61 void OnCancel(); 64 void OnCancel();
65 void setHidden(bool);
62 66
63protected slots: 67protected slots:
64 68
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 @@
1#include "infowin.h" 1#include "infowin.h"
2#include "version.h" 2#include "version.h"
3 3#include <stdio.h>
4#define VERSION_STRING "QT Reader v" ## MAJOR ## "." ## MINOR ## " (" ## RELEASE_TYPE ## ")\nA small e-text reader"
5 4
6infowin::infowin( QWidget *parent=0, const char *name=0, WFlags f = 0) : 5infowin::infowin( QWidget *parent=0, const char *name=0, WFlags f = 0) :
7 QWidget(parent, name, f) 6 QWidget(parent, name, f)
@@ -33,7 +32,9 @@ infowin::infowin( QWidget *parent=0, const char *name=0, WFlags f = 0) :
33 read = new QLabel("0", this); 32 read = new QLabel("0", this);
34 read->setAlignment( AlignVCenter | AlignRight ); 33 read->setAlignment( AlignVCenter | AlignRight );
35 grid->addWidget(read, 4, 1); 34 grid->addWidget(read, 4, 1);
36 l = new QLabel(VERSION_STRING, this); 35 char vstr[128];
36 sprintf(vstr, "QT Reader v%u.%u%c (%s)\nA small e-text reader", MAJOR, BKMKTYPE, MINOR, RELEASE_TYPE);
37 l = new QLabel(vstr, this);
37 grid->addWidget(l, 5, 0); 38 grid->addWidget(l, 5, 0);
38 QPushButton* exitbutton = new QPushButton("Cancel", this); 39 QPushButton* exitbutton = new QPushButton("Cancel", this);
39 connect( exitbutton, SIGNAL( released() ), this, SLOT( infoClose() ) ); 40 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 @@
1#include <qpe/qpeapplication.h> 1#include <qpe/qpeapplication.h>
2//#include <qmainwindow.h>
3#include "QTReaderApp.h" 2#include "QTReaderApp.h"
4 3
4#include "signal.h"
5#include "stdio.h"
6#include "time.h"
5 7
8QTReaderApp* app = NULL;
6 9
7 10void handler(int signum)
8
9/*
10class myapp : public QPEApplication
11{ 11{
12 public slots: 12 if (app != NULL) app->saveprefs();
13 void receive( const QCString& msg, const QByteArray& data ) 13 signal(signum, handler);
14 {
15
16 QDataStream stream( data, IO_ReadOnly );
17 if ( msg == "someMessage(int,int,int)" ) {
18 int a,b,c;
19 stream >> a >> b >> c;
20 ...
21 } else if ( msg == "otherMessage(QString)" ) {
22 ...
23 }
24
25 }
26} 14}
27*/
28 15
29int main( int argc, char ** argv ) 16int main( int argc, char ** argv )
30{ 17{
18 signal(SIGCONT, handler);
19
31 QPEApplication a( argc, argv ); 20 QPEApplication a( argc, argv );
32 21
33 QTReaderApp m; 22 QTReaderApp m;
23
34 a.showMainDocumentWidget( &m ); 24 a.showMainDocumentWidget( &m );
35 25
26 app = &m;
27
36 return a.exec(); 28 return a.exec();
37} 29}
38 30
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
28 } 28 }
29 } 29 }
30 } 30 }
31 T& first() { return front->data; }
32 T& last() { return back->data; }
31 T* operator[](int n) 33 T* operator[](int n)
32 { 34 {
33 node* current = front; 35 node* current = front;
@@ -61,6 +63,7 @@ class CList
61 back = n; 63 back = n;
62 } 64 }
63 } 65 }
66 bool isEmpty() { return (front == NULL); }
64 void erase(unsigned int n) 67 void erase(unsigned int n)
65 { 68 {
66 node* p = front; 69 node* p = front;
@@ -155,10 +158,18 @@ class CList
155 { 158 {
156 return &(current->data); 159 return &(current->data);
157 } 160 }
161 T* pContent()
162 {
163 return &(current->data);
164 }
158 bool operator!=(iterator t) 165 bool operator!=(iterator t)
159 { 166 {
160 return (current != t.current); 167 return (current != t.current);
161 } 168 }
169 bool operator==(iterator t)
170 {
171 return (current == t.current);
172 }
162 }; 173 };
163 iterator begin() 174 iterator begin()
164 { 175 {
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 @@
1 TEMPLATE= app 1TEMPLATE = app
2 CONFIG = qt warn_on release 2CONFIG = qt warn_on release
3 HEADERS = Aportis.h \ 3HEADERS = Aportis.h \
4 BuffDoc.h \ 4 BuffDoc.h \
5 CBuffer.h \ 5 CBuffer.h \
6 CExpander.h \ 6 CDrawBuffer.h \
7 CFilter.h \ 7 CExpander.h \
8 QTReader.h \ 8 CFilter.h \
9 QTReaderApp.h \ 9 QTReader.h \
10 Text.h \ 10 QTReaderApp.h \
11 ZText.h \ 11 ZText.h \
12 arith.h \ 12 arith.h \
13 my_list.h \ 13 my_list.h \
14 ppm.h \ 14 ppm.h \
15 ppm_expander.h \ 15 ppm_expander.h \
16 cbkmkselector.h \ 16 cbkmkselector.h \
17 fileBrowser.h \ 17 fileBrowser.h \
18 ztxt.h \ 18 ztxt.h \
19 QtrListView.h \ 19 QtrListView.h \
20 infowin.h \ 20 infowin.h \
21 version.h \ 21 version.h \
22 pdb.h \ 22 pdb.h \
23 utypes.h \ 23 utypes.h \
24 ustring.h \ 24 ustring.h \
25 CEncoding.h \ 25 CEncoding.h \
26 config.h 26 CAnnoEdit.h \
27 SOURCES = Aportis.cpp \ 27 QFloatBar.h \
28 BuffDoc.cpp \ 28 StyleConsts.h \
29 CBuffer.cpp \ 29 FontControl.h \
30 QTReader.cpp \ 30 plucker.h \
31 QTReaderApp.cpp \ 31 Markups.h \
32 arith_d.cpp \ 32 Bkmks.h \
33 main.cpp \ 33 config.h
34 ppm.cpp \ 34SOURCES = Aportis.cpp \
35 ppm_expander.cpp \ 35 BuffDoc.cpp \
36 ztxt.cpp \ 36 CBuffer.cpp \
37 QtrListView.cpp \ 37 CDrawBuffer.cpp \
38 infowin.cpp \ 38 QTReader.cpp \
39 pdb.cpp \ 39 QTReaderApp.cpp \
40 CEncoding.cpp \ 40 arith_d.cpp \
41 fileBrowser.cpp 41 main.cpp \
42 INTERFACES= 42 ppm.cpp \
43 DESTDIR = $(OPIEDIR)/bin 43 ppm_expander.cpp \
44 INCLUDEPATH+= $(OPIEDIR)/include 44 ztxt.cpp \
45 DEPENDPATH+= $(OPIEDIR)/include 45 QtrListView.cpp \
46 TARGET = reader 46 infowin.cpp \
47 LIBS += -lqpe 47 pdb.cpp \
48 CEncoding.cpp \
49 CFilter.cpp \
50 plucker.cpp \
51 Bkmks.cpp \
52 fileBrowser.cpp
53DESTDIR = $(OPIEDIR)/bin
54INCLUDEPATH += $(OPIEDIR)/include
55DEPENDPATH += $(OPIEDIR)/include
56TARGET = reader
57LIBS += -lqpe
48 58
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 @@
17/* Normal Palm typedefs */ 17/* Normal Palm typedefs */
18typedef unsigned char UInt8; 18typedef unsigned char UInt8;
19typedef unsigned short UInt16; 19typedef unsigned short UInt16;
20typedef signed short Int16;
20typedef unsigned long UInt32; 21typedef unsigned long UInt32;
21typedef UInt32 LocalID; 22typedef UInt32 LocalID;
22 23
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 @@
1#ifndef __plucker_h
2#define __plucker_h
3
4#include "CExpander.h"
5#include <zlib.h>
6#include "ztxt.h"
7#include "pdb.h"
8#include "CBuffer.h"
9
10struct CPlucker_dataRecord
11{
12 UInt16 uid;
13 UInt16 nParagraphs;
14 UInt16 size;
15 UInt8 type;
16 UInt8 reserved;
17};
18
19struct CPlucker_record0
20{
21 UInt16 uid;
22 UInt16 version;
23 UInt16 nRecords;
24};
25
26struct CPluckerbkmk
27{
28 UInt32 offset;
29 tchar title[MAX_BMRK_LENGTH];
30};
31
32
33const UInt32 CPLUCKER_ID = 0x5458547a;
34
35class CPlucker : public CExpander, Cpdb
36{
37 size_t textlength;
38 UInt16 uid;
39 int m_nextPara, m_nextParaIndex;
40 CBufferFace<UInt16> m_ParaOffsets;
41 CBufferFace<UInt16> m_ParaAttrs;
42 UInt16 m_nParas;
43 CStyle mystyle;
44// bool bInit;
45 UInt32 buffersize;
46 UInt32 buffercontent;
47 UInt8* expandedtextbuffer;
48 UInt8* compressedtextbuffer;
49 size_t bufferpos;
50 UInt16 bufferrec;
51 CPlucker_record0 hdr0;
52 size_t currentpos;
53 bool expand(int);
54 void UnZip(size_t, UInt8*, UInt16);
55 void UnDoc(size_t, UInt8*, UInt16);
56 void expandimg(UInt16 tgt);
57 void home();
58 int bgetch();
59 public:
60 virtual void sizes(unsigned long& _file, unsigned long& _text)
61 {
62 _file = file_length;
63 _text = textlength;
64//ntohl(hdr0.size);
65 }
66 virtual bool hasrandomaccess() { return true; }
67 virtual ~CPlucker()
68 {
69 if (expandedtextbuffer != NULL) delete [] expandedtextbuffer;
70 if (compressedtextbuffer != NULL) delete [] compressedtextbuffer;
71 }
72 CPlucker();
73 virtual int openfile(const char *src);
74 virtual int getch();
75 virtual void getch(int&, CStyle&);
76 virtual unsigned int locate();
77 virtual void locate(unsigned int n);
78 virtual CList<Bkmk>* getbkmklist();
79 virtual bool hyperlink(unsigned int n);
80 virtual MarkupType PreferredMarkup()
81 {
82 return cNONE;
83 }
84};
85
86#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 {
41 virtual void locate(unsigned int n); 41 virtual void locate(unsigned int n);
42 virtual bool hasrandomaccess() { return (numblocks > 1); } 42 virtual bool hasrandomaccess() { return (numblocks > 1); }
43 virtual void sizes(unsigned long& file, unsigned long& text); 43 virtual void sizes(unsigned long& file, unsigned long& text);
44 virtual MarkupType PreferredMarkup()
45 {
46 return cTEXT;
47 }
44}; 48};
45 49
46#endif 50#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 @@
1#define MAJOR "0" 1
2#define MINOR "3r" 2#define MAJOR 0
3#define RELEASE_TYPE "beta(U)" 3#define BKMKTYPE 5
4#define MINOR 'a'
5#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 @@
1#include <stdio.h> 1#include <stdio.h>
2#include <string.h> 2#include <string.h>
3#include "ztxt.h" 3#include "ztxt.h"
4#include "my_list.h"
5#include "Bkmks.h"
4 6
5ztxt::ztxt() : bInit(false), expandedtextbuffer(NULL), compressedtextbuffer(NULL) { /*printf("constructing:%x\n",fin);*/ } 7ztxt::ztxt() : bInit(false), expandedtextbuffer(NULL), compressedtextbuffer(NULL) { /*printf("constructing:%x\n",fin);*/ }
6 8
@@ -152,7 +154,7 @@ CList<Bkmk>* ztxt::getbkmklist()
152 zTXTbkmk bkmk; 154 zTXTbkmk bkmk;
153 if (fread(&bkmk, sizeof(bkmk), 1, fin) != 1) break; 155 if (fread(&bkmk, sizeof(bkmk), 1, fin) != 1) break;
154// printf("Bookmark number:%d:%.20s\n", i, bkmk.title); 156// printf("Bookmark number:%d:%.20s\n", i, bkmk.title);
155 t->push_back(Bkmk(bkmk.title, ntohl(bkmk.offset))); 157 t->push_back(Bkmk(bkmk.title, NULL, ntohl(bkmk.offset)));
156 } 158 }
157 fseek(fin, cur, SEEK_SET); 159 fseek(fin, cur, SEEK_SET);
158 return t; 160 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 @@
2#define __ztxt_h 2#define __ztxt_h
3 3
4#include "CExpander.h" 4#include "CExpander.h"
5#include "zlib/zlib.h" 5#include <zlib.h>
6//#include <zlib.h>
7#include "pdb.h" 6#include "pdb.h"
8/* 7/*
9 * Stuff common to both Weasel Reader and makeztxt 8 * Stuff common to both Weasel Reader and makeztxt
@@ -77,27 +76,30 @@ class ztxt : public CExpander, Cpdb
77 void home(); 76 void home();
78 public: 77 public:
79 virtual void sizes(unsigned long& _file, unsigned long& _text) 78 virtual void sizes(unsigned long& _file, unsigned long& _text)
80 { 79 {
81 _file = file_length; 80 _file = file_length;
82 _text = ntohl(hdr0.size); 81 _text = ntohl(hdr0.size);
83 } 82 }
84 virtual bool hasrandomaccess() { return (hdr0.randomAccess != 0); } 83 virtual bool hasrandomaccess() { return (hdr0.randomAccess != 0); }
85 virtual ~ztxt() 84 virtual ~ztxt()
86 { 85 {
87 if (expandedtextbuffer != NULL) delete [] expandedtextbuffer; 86 if (expandedtextbuffer != NULL) delete [] expandedtextbuffer;
88 if (compressedtextbuffer != NULL) delete [] compressedtextbuffer; 87 if (compressedtextbuffer != NULL) delete [] compressedtextbuffer;
89 if (bInit) 88 if (bInit)
90 { 89 {
91 inflateEnd(&zstream); 90 inflateEnd(&zstream);
92 } 91 }
93 } 92 }
94 ztxt(); 93 ztxt();
95 virtual int openfile(const char *src); 94 virtual int openfile(const char *src);
96 virtual int getch(); 95 virtual int getch();
97 virtual unsigned int locate(); 96 virtual unsigned int locate();
98 virtual void locate(unsigned int n); 97 virtual void locate(unsigned int n);
99 virtual CList<Bkmk>* getbkmklist(); 98 virtual CList<Bkmk>* getbkmklist();
99 virtual MarkupType PreferredMarkup()
100 {
101 return cTEXT;
102 }
100}; 103};
101 104
102#endif 105#endif
103