summaryrefslogtreecommitdiff
Unidiff
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,211 +1,294 @@
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);
12 for (int i = 0; i < nRecs2; i++) 58 for (int i = 0; i < nRecs2; i++)
13 { 59 {
14 DWORD dwPos; 60 DWORD dwPos;
15 fseek(fin, 0x56 + 8*i, SEEK_SET); 61 fseek(fin, 0x56 + 8*i, SEEK_SET);
16 fread(&dwPos, 4, 1, fin); 62 fread(&dwPos, 4, 1, fin);
17 dwPos = SwapLong(dwPos); 63 dwPos = SwapLong(dwPos);
18 fseek(fin,dwPos,SEEK_SET); 64 fseek(fin,dwPos,SEEK_SET);
19 unsigned char ch; 65 unsigned char ch;
20 fread(&ch,1,1,fin); 66 fread(&ch,1,1,fin);
21 if (ch != 241) 67 if (ch != 241)
22 { 68 {
23 char name[17]; 69 char name[17];
24 name[16] = '\0'; 70 name[16] = '\0';
25 fseek(fin,dwPos,SEEK_SET); 71 fseek(fin,dwPos,SEEK_SET);
26 fread(name,1,16,fin); 72 fread(name,1,16,fin);
27 unsigned long lcn; 73 unsigned long lcn;
28 fread(&lcn,sizeof(lcn),1,fin); 74 fread(&lcn,sizeof(lcn),1,fin);
29 lcn = SwapLong(lcn); 75 lcn = SwapLong(lcn);
30#ifdef _UNICODE 76#ifdef _UNICODE
31 tchar tname[17]; 77 tchar tname[17];
32 memset(tname, 0, sizeof(tname)); 78 memset(tname, 0, sizeof(tname));
33 for (int i = 0; name[i] != 0; i++) 79 for (int i = 0; name[i] != 0; i++)
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
41 } 87 }
42 } 88 }
43 fseek(fin, cur, SEEK_SET); 89 fseek(fin, cur, SEEK_SET);
44 return t; 90 return t;
45} 91}
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
53 if (!Cpdb::openfile(src)) return -1; 98 if (!Cpdb::openfile(src)) return -1;
54 99
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
104 // it knows how to stretch to accomodate the decompress 180 // it knows how to stretch to accomodate the decompress
105 currentrec = 0; 181 currentrec = 0;
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
112int Aportis::getch() 189int Aportis::getch()
113{ 190{
114 if (bCompressed == 1) 191 if (bCompressed == 1)
115 { 192 {
116 if ((dwRecLen == 0) && !refreshbuffer()) return EOF; 193 if ((dwRecLen == 0) && !refreshbuffer()) return EOF;
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;
123 } 201 }
124 } 202 }
125 if (outptr != cbptr) 203 if (outptr != cbptr)
126 { 204 {
127 currentpos++; 205 currentpos++;
128 return (circbuf[outptr = (outptr + 1) % 2048]); 206 return (circbuf[outptr = (outptr + 1) % 2048]);
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
139 // codes 1...8 mean copy that many chars; for accented chars & binary 218 // codes 1...8 mean copy that many chars; for accented chars & binary
140 if (c == 0) 219 if (c == 0)
141 { 220 {
142 circbuf[outptr = cbptr = (cbptr+1)%2048] = c; 221 circbuf[outptr = cbptr = (cbptr+1)%2048] = c;
143 return c; 222 return c;
144 } 223 }
145 else if (c >= 0x09 && c <= 0x7F) 224 else if (c >= 0x09 && c <= 0x7F)
146 { 225 {
147 circbuf[outptr = cbptr = (cbptr+1)%2048] = c; 226 circbuf[outptr = cbptr = (cbptr+1)%2048] = c;
148 return c; 227 return c;
149 } 228 }
150 else if (c >= 0x01 && c <= 0x08) 229 else if (c >= 0x01 && c <= 0x08)
151 { 230 {
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 }
159 else if (c >= 0x80 && c <= 0xBF) 240 else if (c >= 0x80 && c <= 0xBF)
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);
167 n += 3; 250 n += 3;
168 while (n--) 251 while (n--)
169 { 252 {
170 cbptr = (cbptr+1)%2048; 253 cbptr = (cbptr+1)%2048;
171 circbuf[cbptr] = circbuf[(cbptr+2048-m)%2048]; 254 circbuf[cbptr] = circbuf[(cbptr+2048-m)%2048];
172 } 255 }
173 return circbuf[outptr = (outptr+1)%2048]; 256 return circbuf[outptr = (outptr+1)%2048];
174 } 257 }
175 else if (c >= 0xC0 && c <= 0xFF) 258 else if (c >= 0xC0 && c <= 0xFF)
176 { 259 {
177 circbuf[cbptr = (cbptr+1)%2048] = ' '; 260 circbuf[cbptr = (cbptr+1)%2048] = ' ';
178 circbuf[cbptr = (cbptr+1)%2048] = c^0x80; 261 circbuf[cbptr = (cbptr+1)%2048] = c^0x80;
179 return circbuf[outptr = (outptr+1)%2048]; 262 return circbuf[outptr = (outptr+1)%2048];
180 } 263 }
181} 264}
182 265
183unsigned int Aportis::GetBS(unsigned int bn) 266unsigned int Aportis::GetBS(unsigned int bn)
184{ 267{
185 DWORD dwPos; 268 DWORD dwPos;
186 WORD fs; 269 WORD fs;
187 270
188 fseek(fin, 0x56 + 8*bn, SEEK_SET); 271 fseek(fin, 0x56 + 8*bn, SEEK_SET);
189 fread(&dwPos, 4, 1, fin); 272 fread(&dwPos, 4, 1, fin);
190 dwPos = SwapLong(dwPos); 273 dwPos = SwapLong(dwPos);
191 fseek(fin,dwPos,SEEK_SET); 274 fseek(fin,dwPos,SEEK_SET);
192 275
193// gotorecordnumber(bn+1); 276// gotorecordnumber(bn+1);
194 unsigned char ch; 277 unsigned char ch;
195 fread(&ch,1,1,fin); 278 fread(&ch,1,1,fin);
196 if (ch == 241) 279 if (ch == 241)
197 { 280 {
198 fread(&fs,sizeof(fs),1,fin); 281 fread(&fs,sizeof(fs),1,fin);
199 fs = SwapWord(fs); 282 fs = SwapWord(fs);
200 } 283 }
201 else 284 else
202 fs = 0; 285 fs = 0;
203 return fs; 286 return fs;
204} 287}
205 288
206unsigned int Aportis::locate() 289unsigned int Aportis::locate()
207{ 290{
208 if (bCompressed == 4) 291 if (bCompressed == 4)
209 { 292 {
210 size_t cur = ftell(fin); 293 size_t cur = ftell(fin);
211 unsigned int clen = 0; 294 unsigned int clen = 0;
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
@@ -1,86 +1,100 @@
1/* 1/*
2 Derived from makedoc9 by Pat Beirne 2 Derived from makedoc9 by Pat Beirne
3*/ 3*/
4 4
5#ifndef __Aportis_h 5#ifndef __Aportis_h
6#define __Aportis_h 6#define __Aportis_h
7 7
8#include "CExpander.h" 8#include "CExpander.h"
9#include "pdb.h" 9#include "pdb.h"
10 10
11typedef UInt32 DWORD; 11typedef UInt32 DWORD;
12typedef UInt16 WORD; 12typedef UInt16 WORD;
13 13
14#define DISP_BITS 11 14#define DISP_BITS 11
15#define COUNT_BITS 3 15#define COUNT_BITS 3
16/* 16/*
17// all numbers in these structs are big-endian, MAC format 17// all numbers in these structs are big-endian, MAC format
18struct tDocHeader { 18struct tDocHeader {
19 char sName[32]; 19 char sName[32];
20 DWORD dwUnknown1; 20 DWORD dwUnknown1;
21 DWORD dwTime1; 21 DWORD dwTime1;
22 DWORD dwTime2; 22 DWORD dwTime2;
23 DWORD dwTime3; 23 DWORD dwTime3;
24 DWORD dwLastSync; 24 DWORD dwLastSync;
25 DWORD ofsSort; 25 DWORD ofsSort;
26 DWORD ofsCatagories; 26 DWORD ofsCatagories;
27 DWORD dwCreator; 27 DWORD dwCreator;
28 DWORD dwType; 28 DWORD dwType;
29 DWORD dwUnknown2; 29 DWORD dwUnknown2;
30 DWORD dwUnknown3; 30 DWORD dwUnknown3;
31 WORD wNumRecs; 31 WORD wNumRecs;
32}; 32};
33*/ 33*/
34struct tDocRecord0 { 34struct tDocRecord0 {
35 WORD wVersion;// 1=plain text, 2=compressed 35 WORD wVersion;// 1=plain text, 2=compressed
36 WORD wSpare; 36 WORD wSpare;
37 DWORD dwStoryLen; // in chars, when decompressed 37 DWORD dwStoryLen; // in chars, when decompressed
38 WORD wNumRecs; // text records only; equals tDocHeader.wNumRecs-1 38 WORD wNumRecs; // text records only; equals tDocHeader.wNumRecs-1
39 WORD wRecSize; // usually 0x1000 39 WORD wRecSize; // usually 0x1000
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)
46{ 54{
47 return (r>>8) + (r<<8); 55 return (r>>8) + (r<<8);
48} 56}
49 57
50inline DWORD SwapLong(DWORD r) 58inline DWORD SwapLong(DWORD r)
51{ 59{
52 return ((r>>24) & 0xFF) + (r<<24) + ((r>>8) & 0xFF00) + ((r<<8) & 0xFF0000); 60 return ((r>>24) & 0xFF) + (r<<24) + ((r>>8) & 0xFF00) + ((r<<8) & 0xFF0000);
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;
59 WORD nRecs; 69 WORD nRecs;
60 WORD BlockSize; 70 WORD BlockSize;
61 DWORD dwRecLen; 71 DWORD dwRecLen;
62 int currentrec, currentpos; 72 int currentrec, currentpos;
63 unsigned int cbptr; 73 unsigned int cbptr;
64 unsigned int outptr; 74 unsigned int outptr;
65 unsigned char circbuf[2048]; 75 unsigned char circbuf[2048];
66 char bCompressed; 76 char bCompressed;
67public: 77public:
68 virtual void sizes(unsigned long& _file, unsigned long& _text) 78 virtual void sizes(unsigned long& _file, unsigned long& _text)
69 { 79 {
70 _file = dwLen; 80 _file = dwLen;
71 _text = dwTLen; 81 _text = dwTLen;
72 } 82 }
73 virtual bool hasrandomaccess() { return true; } 83 virtual bool hasrandomaccess() { return true; }
74 virtual ~Aportis() {} 84 virtual ~Aportis() {}
75 Aportis(); 85 Aportis();
76 virtual int openfile(const char *src); 86 virtual int openfile(const char *src);
77 virtual int getch(); 87 virtual int getch();
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);
84}; 98};
85 99
86#endif 100#endif
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,126 +1,224 @@
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];
13 if (exp != NULL) exp->locate(n); 29 if (exp != NULL) exp->locate(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 }
66 lastispara = false; 82 lastispara = false;
67 for (int i = 0; i < len; i++) allsizes[i] = lastsizes[i]; 83 for (int i = 0; i < len; i++) allsizes[i] = lastsizes[i];
68 while (slen < w) 84 while (slen < 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 {
87 lastcheck = len; 103 lastcheck = len;
88 break; 104 break;
89 } 105 }
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,138 +1,84 @@
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;
43 filt = _f; 38 filt = _f;
44 filt->setsource(exp); 39 filt->setsource(exp);
45 } 40 }
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;
133 laststartline = exp->locate(); 79 laststartline = exp->locate();
134 return i; 80 return i;
135 } 81 }
136}; 82};
137 83
138#endif 84#endif
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
@@ -1,45 +1,55 @@
1#ifndef __CBUFFER_H 1#ifndef __CBUFFER_H
2#define __CBUFFER_H 2#define __CBUFFER_H
3 3
4#include <stdlib.h> 4#include <stdlib.h>
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,150 +1,210 @@
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))
11 { 16 {
12 unsigned char flags = ret << 1; 17 unsigned char flags = ret << 1;
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 }
20 switch (count) 26 switch (count)
21 { 27 {
22 case 0: 28 case 0:
23 break; 29 break;
24 case 1: 30 case 1:
25 ret &= 0x07ff; 31 ret &= 0x07ff;
26 break; 32 break;
27 case 2: 33 case 2:
28 break; 34 break;
29 case 3: 35 case 3:
30 case 4: 36 case 4:
31 case 5: 37 case 5:
32 default: 38 default:
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
@@ -1,53 +1,53 @@
1#ifndef __CENCODING_H 1#ifndef __CENCODING_H
2#define __CENCODING_H 2#define __CENCODING_H
3 3
4#include "CExpander.h" 4#include "CExpander.h"
5 5
6class CEncoding : public CCharacterSource 6class CEncoding : public CCharacterSource
7{ 7{
8 friend class CFilterChain; 8 friend class CFilterChain;
9 protected: 9 protected:
10 CExpander* parent; 10 CExpander* parent;
11public: 11public:
12 CEncoding() : parent(NULL) {} 12 CEncoding() : parent(NULL) {}
13 void setparent(CExpander* p) { parent = p; } 13 void setparent(CExpander* p) { parent = p; }
14 virtual ~CEncoding() {}; 14 virtual ~CEncoding() {};
15}; 15};
16 16
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,145 +1,43 @@
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
133{ 20{
134 public: 21 public:
135 CExpander() {}; 22 CExpander() {};
136 virtual ~CExpander() {}; 23 virtual ~CExpander() {};
137 virtual int openfile(const char *src) = 0; 24 virtual int openfile(const char *src) = 0;
138 virtual unsigned int locate() = 0; 25 virtual unsigned int locate() = 0;
139 virtual void locate(unsigned int n) = 0; 26 virtual void locate(unsigned int n) = 0;
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
@@ -1,354 +1,269 @@
1#ifndef __CFILTER_H 1#ifndef __CFILTER_H
2#define __CFILTER_H 2#define __CFILTER_H
3 3
4#include "CExpander.h" 4#include "CExpander.h"
5#include "CEncoding.h" 5#include "CEncoding.h"
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
34{ 19{
35 CExpander* expander; 20 CExpander* expander;
36 CEncoding* encoder; 21 CEncoding* encoder;
37 CFilter* first; 22 CFilter* first;
38 CCharacterSource* front; 23 CCharacterSource* front;
39 public: 24 public:
40 CFilterChain(CEncoding* _e) : encoder(_e), first(NULL), front(_e) {}; 25 CFilterChain(CEncoding* _e) : encoder(_e), first(NULL), front(_e) {};
41 ~CFilterChain() 26 ~CFilterChain()
42 { 27 {
43 CCharacterSource* p = front; 28 CCharacterSource* p = front;
44 while (p != encoder) 29 while (p != encoder)
45 { 30 {
46 CFilter* pnext = (CFilter*)p; 31 CFilter* pnext = (CFilter*)p;
47 p = ((CFilter*)p)->parent; 32 p = ((CFilter*)p)->parent;
48 delete pnext; 33 delete pnext;
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)
56 { 44 {
57 front = first = p; 45 front = first = p;
58 p->setparent(encoder); 46 p->setparent(encoder);
59 } 47 }
60 else 48 else
61 { 49 {
62 p->setparent(front); 50 p->setparent(front);
63 front = p; 51 front = p;
64 } 52 }
65 } 53 }
66 void setsource(CExpander* p) 54 void setsource(CExpander* p)
67 { 55 {
68 expander = p; 56 expander = p;
69 encoder->setparent(p); 57 encoder->setparent(p);
70 } 58 }
71 void setencoder(CEncoding* p) 59 void setencoder(CEncoding* p)
72 { 60 {
73 delete encoder; 61 delete encoder;
74 encoder = p; 62 encoder = p;
75 first->setparent(p); 63 first->setparent(p);
76 encoder->setparent(expander); 64 encoder->setparent(expander);
77 } 65 }
78}; 66};
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
@@ -1,1035 +1,1109 @@
1/**************************************************************************** 1/****************************************************************************
2** $Id$ 2** $Id$
3** 3**
4** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. 4** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
5** 5**
6** This file is part of an example program for Qt. This example 6** This file is part of an example program for Qt. This example
7** program may be used, distributed and modified without limitation. 7** program may be used, distributed and modified without limitation.
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>
17#include <stdio.h> //for sprintf 19#include <stdio.h> //for sprintf
18#include <qpe/config.h> 20#include <qpe/config.h>
19#include <qpe/applnk.h> 21#include <qpe/applnk.h>
20#include <qfontdatabase.h> 22#include <qfontdatabase.h>
21#include <qpe/global.h> 23#include <qpe/global.h>
22#include <qpe/qcopenvelope_qws.h> 24#include <qpe/qcopenvelope_qws.h>
23 25
24#ifdef _UNICODE 26#ifdef _UNICODE
25const char *QTReader::fonts[] = { "unifont", "Courier", "Times", 0 }; 27const char *QTReader::fonts[] = { "unifont", "Courier", "Times", 0 };
26#else 28#else
27const char *QTReader::fonts[] = { "Helvetica", "Courier", "Times", 0 }; 29const char *QTReader::fonts[] = { "Helvetica", "Courier", "Times", 0 };
28#endif 30#endif
29//const int QTReader::fontsizes[] = { 8, 10, 12, 14, 18, 24, 30, 40, 50, 60, 70, 80, 90, 100, 0 }; 31//const int QTReader::fontsizes[] = { 8, 10, 12, 14, 18, 24, 30, 40, 50, 60, 70, 80, 90, 100, 0 };
30 32
31//const tchar *QTReader::fonts[] = { "unifont", "fixed", "micro", "smoothtimes", "Courier", "Times", 0 }; 33//const tchar *QTReader::fonts[] = { "unifont", "fixed", "micro", "smoothtimes", "Courier", "Times", 0 };
32//const int QTReader::fontsizes[] = {10,16,17,22,0}; 34//const int QTReader::fontsizes[] = {10,16,17,22,0};
33//const tchar *QTReader::fonts[] = { "verdana", "Courier", "Times", 0 }; 35//const tchar *QTReader::fonts[] = { "verdana", "Courier", "Times", 0 };
34//const int QTReader::fontsizes[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0}; 36//const int QTReader::fontsizes[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0};
35 37
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/*
52QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0) : 57QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0) :
53 QWidget(parent, name, f), 58 QWidget(parent, name, f),
54 m_textfont(0), 59 m_textfont(0),
55 m_textsize(1), 60 m_textsize(1),
56 textarray(NULL), 61 textarray(NULL),
57 numlines(0), 62 numlines(0),
58 bstripcr(true), 63 bstripcr(true),
59 bunindent(false), 64 bunindent(false),
60 brepara(false), 65 brepara(false),
61 bdblspce(false), 66 bdblspce(false),
62 btight(false), 67 btight(false),
63 bindenter(0), 68 bindenter(0),
64 m_fm(NULL) 69 m_fm(NULL)
65{ 70{
66 init(); 71 init();
67 // qDebug("Load_file(1)"); 72 // qDebug("Load_file(1)");
68 load_file((const tchar*)filename); 73 load_file((const tchar*)filename);
69} 74}
70*/ 75*/
71 76
72long QTReader::real_delay() 77long QTReader::real_delay()
73{ 78{
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
127void QTReader::focusInEvent(QFocusEvent* e) 242void QTReader::focusInEvent(QFocusEvent* e)
128{ 243{
129 if (m_autoScroll) timer->start(real_delay(), false); 244 if (m_autoScroll) timer->start(real_delay(), false);
130 update(); 245 update();
131} 246}
132 247
133void QTReader::focusOutEvent(QFocusEvent* e) 248void 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
142#include <qapplication.h> 257#include <qapplication.h>
143#include <qdrawutil.h> 258#include <qdrawutil.h>
144#include <unistd.h> 259#include <unistd.h>
145 260
146void QTReader::goDown() 261void 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
158void QTReader::goUp() 273void 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
170void QTReader::keyPressEvent(QKeyEvent* e) 285void QTReader::keyPressEvent(QKeyEvent* e)
171{ 286{
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
294void QTReader::setautoscroll(bool _sc) 402void QTReader::setautoscroll(bool _sc)
295{ 403{
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
320void QTReader::doscroll() 430void 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 );
329 QBrush b( white); 439 QBrush b( white);
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
378void QTReader::autoscroll() 478void QTReader::autoscroll()
379{ 479{
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
515// 597//
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()
560{ 607{
561 // setCaption( "Qt Draw Demo Application" ); 608 // setCaption( "Qt Draw Demo Application" );
562 609
563 setBackgroundColor( white ); 610 setBackgroundColor( white );
564// QPainter p(this); 611// QPainter p(this);
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
582// 631//
583// Clean up 632// Clean up
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//
594// Calls the drawing function as specified by the radio buttons. 639// Calls the drawing function as specified by the radio buttons.
595// 640//
596 641
597void QTReader::drawIt( QPainter *p ) 642void QTReader::drawIt( QPainter *p )
598{ 643{
599 drawFonts(p); 644 drawFonts(p);
600} 645}
601 646
602// 647//
603// Called when the print button is clicked. 648// Called when the print button is clicked.
604// 649//
605/* 650/*
606void QTReader::printIt() 651void QTReader::printIt()
607{ 652{
608#ifndef QT_NO_PRINTER 653#ifndef QT_NO_PRINTER
609 if ( printer->setup( this ) ) { 654 if ( printer->setup( this ) ) {
610 QPainter paint; 655 QPainter paint;
611 if ( !paint.begin( printer ) ) 656 if ( !paint.begin( printer ) )
612 return; 657 return;
613 drawIt( &paint ); 658 drawIt( &paint );
614 } 659 }
615#endif 660#endif
616} 661}
617*/ 662*/
618// 663//
619// Called when the widget needs to be updated. 664// Called when the widget needs to be updated.
620// 665//
621 666
622void QTReader::paintEvent( QPaintEvent * ) 667void QTReader::paintEvent( QPaintEvent * )
623{ 668{
624 QPainter paint( this ); 669 QPainter paint( this );
625 drawIt( &paint ); 670 drawIt( &paint );
626} 671}
627 672
628// 673//
629// Called when the widget has been resized. 674// Called when the widget has been resized.
630// Moves the button group to the upper right corner 675// Moves the button group to the upper right corner
631// of the widget. 676// of the widget.
632 677
633/* 678/*
634void QTReader::resizeEvent( QResizeEvent * ) 679void QTReader::resizeEvent( QResizeEvent * )
635{ 680{
636 // qDebug("resize:(%u,%u)", width(), height()); 681 // qDebug("resize:(%u,%u)", width(), height());
637 // bgroup->move( width()-bgroup->width(), 0 ); 682 // bgroup->move( width()-bgroup->width(), 0 );
638} 683}
639*/ 684*/
640 685
641// 686//
642// Create and display our widget. 687// Create and display our widget.
643// 688//
644/* 689/*
645int main( int argc, tchar **argv ) 690int main( int argc, tchar **argv )
646{ 691{
647 QApplication app( argc, argv ); 692 QApplication app( argc, argv );
648 QTReader draw; 693 QTReader draw;
649 app.setMainWidget( &draw ); 694 app.setMainWidget( &draw );
650 draw.setCaption("Qt Example - Drawdemo"); 695 draw.setCaption("Qt Example - Drawdemo");
651 draw.show(); 696 draw.show();
652 return app.exec(); 697 return app.exec();
653} 698}
654*/ 699*/
655 700
656 701
657bool QTReader::locate(unsigned long n) { 702bool QTReader::locate(unsigned long n) {
658 //printf("Locate\n"); 703 //printf("Locate\n");
659 buffdoc.locate(n); 704 buffdoc.locate(n);
660 // qDebug("&buffdoc.located"); 705 // qDebug("&buffdoc.located");
661 fillbuffer(); 706 fillbuffer();
662 // qDebug("&Buffer filled"); 707 // qDebug("&Buffer filled");
663 update(); 708 update();
664 // qDebug("&Located"); 709 // qDebug("&Located");
665 return true; 710 return true;
666} 711}
667 712
668unsigned int QTReader::screenlines() 713unsigned int QTReader::screenlines()
669{ 714{
670 // int linespacing = (tight) ? m_ascent : m_ascent+m_descent; 715 // int linespacing = (tight) ? m_ascent : m_ascent+m_descent;
671 // return (height()-m_descent)/(m_linespacing); 716 // return (height()-m_descent)/(m_linespacing);
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
835bool QTReader::load_file(const char *newfile, unsigned int _lcn) 873bool QTReader::load_file(const char *newfile, unsigned int _lcn)
836{ 874{
837// QMessageBox::information(this, "Name", name, 1); 875// QMessageBox::information(this, "Name", name, 1);
838// QMessageBox::information(this, "load_file", newfile, 1); 876// QMessageBox::information(this, "load_file", newfile, 1);
839 877
840 bool bRC = false; 878 bool bRC = false;
841 unsigned int lcn = _lcn; 879 unsigned int lcn = _lcn;
842 if (m_lastfile == newfile) 880 if (m_lastfile == newfile)
843 { 881 {
844 lcn = m_lastposn; 882 lcn = m_lastposn;
845 } 883 }
846 m_lastfile = newfile; 884 m_lastfile = newfile;
847 // QMessageBox::information(0, "Opening...", newfile); 885 // QMessageBox::information(0, "Opening...", newfile);
848 if (buffdoc.openfile(this,newfile) == 0) 886 if (buffdoc.openfile(this,newfile) == 0)
849 { 887 {
850 bRC = true; 888 bRC = true;
851 // qDebug("buffdoc.openfile done"); 889 // qDebug("buffdoc.openfile done");
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;
858} 897}
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/*
882void QTReader::lineUp() 931void QTReader::lineUp()
883{ 932{
884 CBuffer** buff = textarray; 933 CBuffer** buff = textarray;
885 unsigned int *loc = new unsigned int[numlines]; 934 unsigned int *loc = new unsigned int[numlines];
886 int cbptr = 0; 935 int cbptr = 0;
887 if (locate() != mylastpos) jumpto(mylastpos); 936 if (locate() != mylastpos) jumpto(mylastpos);
888 unsigned int target = locnarray[numlines-1]; 937 unsigned int target = locnarray[numlines-1];
889 if (buffdoc.hasrandomaccess()) 938 if (buffdoc.hasrandomaccess())
890 { 939 {
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);
929#endif 978#endif
930 } 979 }
931 else 980 else
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)
942 { 991 {
943 loc[cbptr] = locate(); 992 loc[cbptr] = locate();
944 buffdoc.getline(buff[cbptr], width()); 993 buffdoc.getline(buff[cbptr], width());
945#ifdef WS 994#ifdef WS
946 //printf("Adding:%s\n",buff[cbptr]->data()); 995 //printf("Adding:%s\n",buff[cbptr]->data());
947#endif 996#endif
948 cbptr = (cbptr+1) % numlines; 997 cbptr = (cbptr+1) % numlines;
949 } 998 }
950 pagepos = loc[cbptr]; 999 pagepos = loc[cbptr];
951 textarray = new CBuffer*[numlines]; 1000 textarray = new CBuffer*[numlines];
952 for (int i = 0; i < numlines; i++) 1001 for (int i = 0; i < numlines; i++)
953 { 1002 {
954 int j = (cbptr+i)%numlines; 1003 int j = (cbptr+i)%numlines;
955 textarray[i] = buff[j]; 1004 textarray[i] = buff[j];
956 locnarray[i] = loc[j]; 1005 locnarray[i] = loc[j];
957 } 1006 }
958 delete [] buff; 1007 delete [] buff;
959 delete [] loc; 1008 delete [] loc;
960 mylastpos = locate(); 1009 mylastpos = locate();
961 update(); 1010 update();
962} 1011}
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
1006 { 1053 {
1007 jumpto(0); 1054 jumpto(0);
1008 loc = locate(); 1055 loc = locate();
1009 getline(buff); 1056 getline(buff);
1010 } 1057 }
1011 cbptr = 0; 1058 cbptr = 0;
1012 while (locate() < target) 1059 while (locate() < target)
1013 { 1060 {
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
1032bool QTReader::empty() 1088bool 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
@@ -1,217 +1,272 @@
1#ifndef __QTREADER_H 1#ifndef __QTREADER_H
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{
14 Q_OBJECT 19 Q_OBJECT
15 20
16 friend class QTReaderApp; 21 friend class QTReaderApp;
17 void drawText(QPainter& p, int x, int y, tchar* text); 22 void drawText(QPainter& p, int x, int y, tchar* text);
18 int m_delay; 23 int m_delay;
19 unsigned int m_overlap; 24 unsigned int m_overlap;
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);
33 ~QTReader(); 39 ~QTReader();
34 bool empty(); 40 bool empty();
35 void toggle_autoscroll(); 41 void toggle_autoscroll();
36 void setautoscroll(bool); 42 void setautoscroll(bool);
37 void disableAutoscroll() { m_autoScroll = false; } 43 void disableAutoscroll() { m_autoScroll = false; }
38 void copy() 44 void copy()
39 { 45 {
40/* 46/*
41 size_t nd = locate(); 47 size_t nd = locate();
42 jumpto(m_mark); 48 jumpto(m_mark);
43 QString text; 49 QString text;
44 while (m_mark < nd) 50 while (m_mark < nd)
45 { 51 {
46 text += buffdoc.getch(); 52 text += buffdoc.getch();
47 m_mark++; 53 m_mark++;
48 } 54 }
49 QApplication::clipboard()->setText(text); 55 QApplication::clipboard()->setText(text);
50 jumpto(nd); 56 jumpto(nd);
51*/ 57*/
52 }; 58 };
53 void clear() {}; 59 void clear() {};
54 void setText(const QString& n, const QString& s) { m_string = n; load_file((const char*)s); }; 60 void setText(const QString& n, const QString& s) { m_string = n; load_file((const char*)s); };
55 /* 61 /*
56 void setText(bool oldfile) 62 void setText(bool oldfile)
57 { 63 {
58 if (oldfile) 64 if (oldfile)
59 { 65 {
60 m_string = m_lastfile; 66 m_string = m_lastfile;
61 load_file((const tchar*)m_string); 67 load_file((const tchar*)m_string);
62 } 68 }
63 else 69 else
64 { 70 {
65 m_string = QString::null; 71 m_string = QString::null;
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;
72 setfilter(getfilter()); 109 setfilter(getfilter());
73 } 110 }
74 void setstriphtml(bool _b) 111 void setstriphtml(bool _b)
75 { 112 {
76 bstriphtml = _b; 113 bstriphtml = _b;
77 setfilter(getfilter()); 114 setfilter(getfilter());
78 } 115 }
79 void setdehyphen(bool _b) 116 void setdehyphen(bool _b)
80 { 117 {
81 bdehyphen = _b; 118 bdehyphen = _b;
82 setfilter(getfilter()); 119 setfilter(getfilter());
83 } 120 }
84 void setunindent(bool _b) 121 void setunindent(bool _b)
85 { 122 {
86 bunindent = _b; 123 bunindent = _b;
87 setfilter(getfilter()); 124 setfilter(getfilter());
88 } 125 }
89 void setrepara(bool _b) 126 void setrepara(bool _b)
90 { 127 {
91 brepara = _b; 128 brepara = _b;
92 setfilter(getfilter()); 129 setfilter(getfilter());
93 } 130 }
94 void setdblspce(bool _b) 131 void setdblspce(bool _b)
95 { 132 {
96 bdblspce = _b; 133 bdblspce = _b;
97 setfilter(getfilter()); 134 setfilter(getfilter());
98 } 135 }
99 void indentplus() 136 void indentplus()
100 { 137 {
101 if (bindenter < 15) bindenter += 2; 138 if (bindenter < 15) bindenter += 2;
102 setfilter(getfilter()); 139 setfilter(getfilter());
103 } 140 }
104 void indentminus() 141 void indentminus()
105 { 142 {
106 if (bindenter > 1) bindenter -= 2; 143 if (bindenter > 1) bindenter -= 2;
107 setfilter(getfilter()); 144 setfilter(getfilter());
108 } 145 }
109 void setpagemode(bool _b) 146 void setpagemode(bool _b)
110 { 147 {
111 m_bpagemode = _b; 148 m_bpagemode = _b;
112 } 149 }
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)
127 { 165 {
128 case 5: 166 case 5:
129 return new Ccp1252; 167 return new Ccp1252;
130 case 4: 168 case 4:
131 return new CPalm; 169 return new CPalm;
132 case 1: 170 case 1:
133 return new CUtf8; 171 return new CUtf8;
134 case 2: 172 case 2:
135 return new CUcs16be; 173 return new CUcs16be;
136 case 3: 174 case 3:
137 return new CUcs16le; 175 return new CUcs16le;
138 case 0: 176 case 0:
139 default: 177 default:
140 return new CAscii; 178 return new CAscii;
141 } 179 }
142 } 180 }
143 CFilterChain* getfilter() 181 CFilterChain* getfilter()
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
156 200
157private slots: 201private slots:
158 void doscroll(); 202 void doscroll();
159 void drawIt( QPainter * ); 203 void drawIt( QPainter * );
160 void paintEvent( QPaintEvent * ); 204 void paintEvent( QPaintEvent * );
161// void resizeEvent( QResizeEvent * p ) { update(); } 205// void resizeEvent( QResizeEvent * p ) { update(); }
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;
188 public: 237 public:
189 int getch() { return buffdoc.getch(); } 238 int getch() { return buffdoc.getch(); }
190 bool tight; 239 bool tight;
191 bool load_file(const char *newfile, unsigned int lcn=0); 240 bool load_file(const char *newfile, unsigned int lcn=0);
192 BuffDoc buffdoc; 241 BuffDoc buffdoc;
193 CList<Bkmk>* getbkmklist() { return buffdoc.getbkmklist(); } 242 CList<Bkmk>* getbkmklist() { return buffdoc.getbkmklist(); }
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
@@ -1,1433 +1,2029 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
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>
24#include <qpe/fontdatabase.h> 25#include <qpe/fontdatabase.h>
25#include <qcombobox.h> 26#include <qcombobox.h>
26#include <qpopupmenu.h> 27#include <qpopupmenu.h>
27#include <qaction.h> 28#include <qaction.h>
28#include <qapplication.h> 29#include <qapplication.h>
29#include <qlineedit.h> 30#include <qlineedit.h>
30#include <qtoolbutton.h> 31#include <qtoolbutton.h>
31#include <qspinbox.h> 32#include <qspinbox.h>
32#include <qobjectlist.h> 33#include <qobjectlist.h>
33#include <qpe/global.h> 34#include <qpe/global.h>
34#include <qpe/applnk.h> 35#include <qpe/applnk.h>
35#include <qfileinfo.h> 36#include <qfileinfo.h>
36#include <stdlib.h> //getenv 37#include <stdlib.h> //getenv
37#include <qprogressbar.h> 38#include <qprogressbar.h>
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>
48#include <qpe/qpeapplication.h> 53#include <qpe/qpeapplication.h>
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;
55 61
56void QTReaderApp::setScrollState(bool _b) { m_scrollButton->setOn(_b); } 62void QTReaderApp::setScrollState(bool _b) { m_scrollButton->setOn(_b); }
57 63
58#include <unistd.h> 64#include <unistd.h>
59#include <stddef.h> 65#include <stddef.h>
60#include <dirent.h> 66#include <dirent.h>
61 67
62void QTReaderApp::listBkmkFiles() 68void QTReaderApp::listBkmkFiles()
63{ 69{
64 bkmkselector->clear(); 70 bkmkselector->clear();
65 int cnt = 0; 71 int cnt = 0;
66 DIR *d; 72 DIR *d;
67 d = opendir((const char *)Global::applicationFileName("uqtreader","")); 73 d = opendir((const char *)Global::applicationFileName("uqtreader",""));
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
96 QMessageBox::information(this, "QTReader", "No bookmark files"); 102 QMessageBox::information(this, "QTReader", "No bookmark files");
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"));
104 110
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" ) );
116 122
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 );
124 QPopupMenu *format = new QPopupMenu( this ); 130 QPopupMenu *format = new QPopupMenu( this );
125 // QPopupMenu *edit = new QPopupMenu( this ); 131 // QPopupMenu *edit = new QPopupMenu( this );
126 132
127// bar = new QToolBar( this ); 133// bar = new QToolBar( this );
128 editBar = bar; 134 editBar = bar;
129 135
130 /* 136 /*
131 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); 137 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 );
132 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); 138 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
133 a->addTo( bar ); 139 a->addTo( bar );
134 a->addTo( file ); 140 a->addTo( file );
135 */ 141 */
136 142
137 editorStack = new QWidgetStack( this ); 143 editorStack = new QWidgetStack( this );
138 setCentralWidget( editorStack ); 144 setCentralWidget( editorStack );
139 145
140 searchVisible = FALSE; 146 searchVisible = FALSE;
141 regVisible = FALSE; 147 regVisible = FALSE;
142 m_fontVisible = false; 148 m_fontVisible = false;
143 149
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() ) );
150 161
151// bkmkselector = new QListBox(editorStack, "Bookmarks"); 162// bkmkselector = new QListBox(editorStack, "Bookmarks");
152 bkmkselector = new CBkmkSelector(editorStack, "Bookmarks"); 163 bkmkselector = new CBkmkSelector(editorStack, "Bookmarks");
153 // connect(bkmkselector, SIGNAL( selected(const QString&) ), this, SLOT( gotobkmk(const QString&) ) ); 164 // connect(bkmkselector, SIGNAL( selected(const QString&) ), this, SLOT( gotobkmk(const QString&) ) );
154 connect(bkmkselector, SIGNAL( selected(int) ), this, SLOT( gotobkmk(int) ) ); 165 connect(bkmkselector, SIGNAL( selected(int) ), this, SLOT( gotobkmk(int) ) );
155 connect(bkmkselector, SIGNAL( cancelled() ), this, SLOT( cancelbkmk() ) ); 166 connect(bkmkselector, SIGNAL( cancelled() ), this, SLOT( cancelbkmk() ) );
156 editorStack->addWidget( bkmkselector, get_unique_id() ); 167 editorStack->addWidget( bkmkselector, get_unique_id() );
157 168
158/* 169/*
159 importSelector = new FileSelector( "*", editorStack, "importselector", false ); 170 importSelector = new FileSelector( "*", editorStack, "importselector", false );
160 connect( importSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( importFile( const DocLnk & ) ) ); 171 connect( importSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( importFile( const DocLnk & ) ) );
161 172
162 editorStack->addWidget( importSelector, get_unique_id() ); 173 editorStack->addWidget( importSelector, get_unique_id() );
163 174
164 // don't need the close visible, it is redundant... 175 // don't need the close visible, it is redundant...
165 importSelector->setCloseVisible( FALSE ); 176 importSelector->setCloseVisible( FALSE );
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 );
184 reader->m_bpagemode = config.readBoolEntry( "PageMode", true ); 200 reader->m_bpagemode = config.readBoolEntry( "PageMode", true );
185 reader->m_bMonoSpaced = config.readBoolEntry( "MonoSpaced", false); 201 reader->m_bMonoSpaced = config.readBoolEntry( "MonoSpaced", false);
186 reader->m_fontname = config.readEntry( "Fontname", "helvetica" ); 202 reader->m_fontname = config.readEntry( "Fontname", "helvetica" );
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 );
196 connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); 224 connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) );
197 a->addTo( bar ); 225 a->addTo( bar );
198 a->addTo( file ); 226 a->addTo( file );
199 227
200 /* 228 /*
201 a = new QAction( tr( "Revert" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); 229 a = new QAction( tr( "Revert" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
202 connect( a, SIGNAL( activated() ), this, SLOT( fileRevert() ) ); 230 connect( a, SIGNAL( activated() ), this, SLOT( fileRevert() ) );
203 a->addTo( file ); 231 a->addTo( file );
204 232
205 a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); 233 a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 );
206 connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); 234 connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) );
207 a->addTo( editBar ); 235 a->addTo( editBar );
208 a->addTo( edit ); 236 a->addTo( edit );
209 */ 237 */
210 238
211 a = new QAction( tr( "Info" ), QString::null, 0, this, NULL); 239 a = new QAction( tr( "Info" ), QString::null, 0, this, NULL);
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) ) );
228 file->insertSeparator(); 262 file->insertSeparator();
229 a->addTo( bar ); 263 a->addTo( bar );
230 a->addTo( file ); 264 a->addTo( file );
231 265
232 /* 266 /*
233 a = new QAction( tr( "Find" ), QString::null, 0, this, NULL, true ); 267 a = new QAction( tr( "Find" ), QString::null, 0, this, NULL, true );
234 // connect( a, SIGNAL( activated() ), this, SLOT( pagedn() ) ); 268 // connect( a, SIGNAL( activated() ), this, SLOT( pagedn() ) );
235 a->addTo( file ); 269 a->addTo( file );
236 270
237 a = new QAction( tr( "Find Again" ), QString::null, 0, this, NULL, true ); 271 a = new QAction( tr( "Find Again" ), QString::null, 0, this, NULL, true );
238 // connect( a, SIGNAL( activated() ), this, SLOT( pagedn() ) ); 272 // connect( a, SIGNAL( activated() ), this, SLOT( pagedn() ) );
239 a->addTo( file ); 273 a->addTo( file );
240 */ 274 */
241 a = new QAction( tr( "Jump" ), QString::null, 0, this, NULL); 275 a = new QAction( tr( "Jump" ), QString::null, 0, this, NULL);
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 );
249 283
250 a = new QAction( tr( "Set Overlap" ), QString::null, 0, this, NULL); 284 a = new QAction( tr( "Set Overlap" ), QString::null, 0, this, NULL);
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() ) );
261 a->addTo( file ); 322 a->addTo( file );
262*/ 323*/
263 324
264 a = new QAction( tr( "Up" ), Resource::loadPixmap( "up" ), QString::null, 0, this, 0 ); 325 a = new QAction( tr( "Up" ), Resource::loadPixmap( "up" ), QString::null, 0, this, 0 );
265 connect( a, SIGNAL( activated() ), this, SLOT( pageup() ) ); 326 connect( a, SIGNAL( activated() ), this, SLOT( pageup() ) );
266 a->addTo( editBar ); 327 a->addTo( editBar );
267 328
268 a = new QAction( tr( "Down" ), Resource::loadPixmap( "down" ), QString::null, 0, this, 0 ); 329 a = new QAction( tr( "Down" ), Resource::loadPixmap( "down" ), QString::null, 0, this, 0 );
269 connect( a, SIGNAL( activated() ), this, SLOT( pagedn() ) ); 330 connect( a, SIGNAL( activated() ), this, SLOT( pagedn() ) );
270 a->addTo( editBar ); 331 a->addTo( editBar );
271 332
272 /* 333 /*
273 a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); 334 a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 );
274 connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); 335 connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) );
275 a->addTo( editBar ); 336 a->addTo( editBar );
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 );
332 a = new QAction( tr( "Zoom" ), QString::null, 0, this); 432 a = new QAction( tr( "Zoom" ), QString::null, 0, this);
333 connect( a, SIGNAL( activated() ), this, SLOT( TBDzoom() ) ); 433 connect( a, SIGNAL( activated() ), this, SLOT( TBDzoom() ) );
334 format->insertSeparator(); 434 format->insertSeparator();
335 a->addTo( format ); 435 a->addTo( format );
336 // a->addTo( editBar ); 436 // a->addTo( editBar );
337 437
338 438
339 a = new QAction( tr( "Ideogram/Word" ), QString::null, 0, this, NULL, true ); 439 a = new QAction( tr( "Ideogram/Word" ), QString::null, 0, this, NULL, true );
340 connect( a, SIGNAL( toggled(bool) ), this, SLOT( monospace(bool) ) ); 440 connect( a, SIGNAL( toggled(bool) ), this, SLOT( monospace(bool) ) );
341 a->setOn(reader->m_bMonoSpaced); 441 a->setOn(reader->m_bMonoSpaced);
342 format->insertSeparator(); 442 format->insertSeparator();
343 a->addTo( format ); 443 a->addTo( format );
344 444
345 a = new QAction( tr( "Set width" ), QString::null, 0, this, NULL); 445 a = new QAction( tr( "Set width" ), QString::null, 0, this, NULL);
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
357 m_EncodingAction[1] = new QAction( tr( "UTF-8" ), QString::null, 0, ag, NULL, true ); 457 m_EncodingAction[1] = new QAction( tr( "UTF-8" ), QString::null, 0, ag, NULL, true );
358 458
359 m_EncodingAction[2] = new QAction( tr( "UCS-2(BE)" ), QString::null, 0, ag, NULL, true ); 459 m_EncodingAction[2] = new QAction( tr( "UCS-2(BE)" ), QString::null, 0, ag, NULL, true );
360 460
361 m_EncodingAction[3] = new QAction( tr( "USC-2(LE)" ), QString::null, 0, ag, NULL, true ); 461 m_EncodingAction[3] = new QAction( tr( "USC-2(LE)" ), QString::null, 0, ag, NULL, true );
362 462
363 m_EncodingAction[4] = new QAction( tr( "Palm" ), QString::null, 0, ag, NULL, true ); 463 m_EncodingAction[4] = new QAction( tr( "Palm" ), QString::null, 0, ag, NULL, true );
364 464
365 m_EncodingAction[5] = new QAction( tr( "Windows(1252)" ), QString::null, 0, ag, NULL, true ); 465 m_EncodingAction[5] = new QAction( tr( "Windows(1252)" ), QString::null, 0, ag, NULL, true );
366 466
367 ag->addTo(encoding); 467 ag->addTo(encoding);
368 468
369 connect(ag, SIGNAL( selected(QAction*) ), this, SLOT( encodingSelected(QAction*) ) ); 469 connect(ag, SIGNAL( selected(QAction*) ), this, SLOT( encodingSelected(QAction*) ) );
370 470
371 a = new QAction( tr( "Set Font" ), QString::null, 0, this); 471 a = new QAction( tr( "Set Font" ), QString::null, 0, this);
372 connect( a, SIGNAL( activated() ), this, SLOT( setfont() ) ); 472 connect( a, SIGNAL( activated() ), this, SLOT( setfont() ) );
373 format->insertSeparator(); 473 format->insertSeparator();
374 a->addTo( format ); 474 a->addTo( format );
375 475
376 QPopupMenu *marks = new QPopupMenu( this ); 476 QPopupMenu *marks = new QPopupMenu( this );
377 477
378 a = new QAction( tr( "Mark" ), QString::null, 0, this, NULL); 478 a = new QAction( tr( "Mark" ), QString::null, 0, this, NULL);
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 );
385 489
386 a = new QAction( tr( "Delete" ), QString::null, 0, this, NULL); 490 a = new QAction( tr( "Delete" ), QString::null, 0, this, NULL);
387 connect( a, SIGNAL( activated() ), this, SLOT( do_delmark() ) ); 491 connect( a, SIGNAL( activated() ), this, SLOT( do_delmark() ) );
388 a->addTo( marks ); 492 a->addTo( marks );
389 493
390 a = new QAction( tr( "Autogen" ), QString::null, 0, this, NULL, false ); 494 a = new QAction( tr( "Autogen" ), QString::null, 0, this, NULL, false );
391 connect( a, SIGNAL( activated() ), this, SLOT( do_autogen() ) ); 495 connect( a, SIGNAL( activated() ), this, SLOT( do_autogen() ) );
392 marks->insertSeparator(); 496 marks->insertSeparator();
393 a->addTo( marks ); 497 a->addTo( marks );
394 498
395 a = new QAction( tr( "Clear" ), QString::null, 0, this, NULL); 499 a = new QAction( tr( "Clear" ), QString::null, 0, this, NULL);
396 connect( a, SIGNAL( activated() ), this, SLOT( clearBkmkList() ) ); 500 connect( a, SIGNAL( activated() ), this, SLOT( clearBkmkList() ) );
397 a->addTo( marks ); 501 a->addTo( marks );
398 502
399 a = new QAction( tr( "Save" ), QString::null, 0, this, NULL ); 503 a = new QAction( tr( "Save" ), QString::null, 0, this, NULL );
400 connect( a, SIGNAL( activated() ), this, SLOT( savebkmks() ) ); 504 connect( a, SIGNAL( activated() ), this, SLOT( savebkmks() ) );
401 a->addTo( marks ); 505 a->addTo( marks );
402 506
403 a = new QAction( tr( "Tidy" ), QString::null, 0, this, NULL); 507 a = new QAction( tr( "Tidy" ), QString::null, 0, this, NULL);
404 connect( a, SIGNAL( activated() ), this, SLOT( listBkmkFiles() ) ); 508 connect( a, SIGNAL( activated() ), this, SLOT( listBkmkFiles() ) );
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() ) );
430 a->addTo( searchBar ); 547 a->addTo( searchBar );
431 548
432 a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); 549 a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
433 connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); 550 connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) );
434 a->addTo( searchBar ); 551 a->addTo( searchBar );
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
442 regEdit = new QLineEdit( regBar, "regEdit" ); 560 regEdit = new QLineEdit( regBar, "regEdit" );
443// regEdit->setFont( f ); 561// regEdit->setFont( f );
444 562
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() ) );
452 a->addTo( regBar ); 570 a->addTo( regBar );
453 571
454 a = new QAction( tr( "Close Edit" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); 572 a = new QAction( tr( "Close Edit" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
455 connect( a, SIGNAL( activated() ), this, SLOT( regClose() ) ); 573 connect( a, SIGNAL( activated() ), this, SLOT( regClose() ) );
456 a->addTo( regBar ); 574 a->addTo( regBar );
457 575
458 regBar->hide(); 576 regBar->hide();
459 577
460 m_fontBar = new QToolBar( "Autogen", this, QMainWindow::Top, TRUE ); 578 m_fontBar = new QToolBar( "Autogen", this, QMainWindow::Top, TRUE );
461 579
462 m_fontBar->setHorizontalStretchable( TRUE ); 580 m_fontBar->setHorizontalStretchable( TRUE );
463 581
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
489void QTReaderApp::msgHandler(const QCString& _msg, const QByteArray& _data) 622void QTReaderApp::msgHandler(const QCString& _msg, const QByteArray& _data)
490{ 623{
491 QString msg = QString::fromUtf8(_msg); 624 QString msg = QString::fromUtf8(_msg);
492 625
493// qDebug("Received:%s", (const char*)msg); 626// qDebug("Received:%s", (const char*)msg);
494 627
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/*
517 if (_enc == "Ascii") return 0; 887 if (_enc == "Ascii") return 0;
518 if (_enc == "UTF-8") return 1; 888 if (_enc == "UTF-8") return 1;
519 if (_enc == "UCS-2(BE)") return 2; 889 if (_enc == "UCS-2(BE)") return 2;
520 if (_enc == "USC-2(LE)") return 3; 890 if (_enc == "USC-2(LE)") return 3;
521*/ 891*/
522} 892}
523 893
524void QTReaderApp::encodingSelected(QAction* _a) 894void QTReaderApp::encodingSelected(QAction* _a)
525{ 895{
526// qDebug("es:%x : %s", _a, (const char *)(_a->text())); 896// qDebug("es:%x : %s", _a, (const char *)(_a->text()));
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}
533 909
534void QTReaderApp::autoScroll(bool _b) 910void QTReaderApp::autoScroll(bool _b)
535{ 911{
536 reader->setautoscroll(_b); 912 reader->setautoscroll(_b);
537} 913}
538 914
539void QTReaderApp::TBD() 915void QTReaderApp::TBD()
540{ 916{
541 QMessageBox::information(this, "QTReader", "Not yet implemented", 1); 917 QMessageBox::information(this, "QTReader", "Not yet implemented", 1);
542} 918}
543 919
544void QTReaderApp::TBDzoom() 920void QTReaderApp::TBDzoom()
545{ 921{
546 QMessageBox::information(this, "QTReader", "Zooming is done interactively\nTry left/right cursor keys", 1); 922 QMessageBox::information(this, "QTReader", "Zooming is done interactively\nTry left/right cursor keys", 1);
547} 923}
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()
557{ 933{
558/* 934/*
559 menu->hide(); 935 menu->hide();
560 editBar->hide(); 936 editBar->hide();
561 if (regVisible) regBar->hide(); 937 if (regVisible) regBar->hide();
562 if (searchVisible) searchBar->hide(); 938 if (searchVisible) searchBar->hide();
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/*
577 editorStack->raiseWidget( fileSelector ); 953 editorStack->raiseWidget( fileSelector );
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()
595{ 972{
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
615void QTReaderApp::infoClose() 1093void QTReaderApp::infoClose()
616{ 1094{
617 showEditTools(); 1095 showEditTools();
618} 1096}
619 1097
620/* 1098/*
621void QTReaderApp::fileRevert() 1099void QTReaderApp::fileRevert()
622{ 1100{
623 clear(); 1101 clear();
624 fileOpen(); 1102 fileOpen();
625} 1103}
626 1104
627void QTReaderApp::editCut() 1105void QTReaderApp::editCut()
628{ 1106{
629#ifndef QT_NO_CLIPBOARD 1107#ifndef QT_NO_CLIPBOARD
630 editor->cut(); 1108 editor->cut();
631#endif 1109#endif
632} 1110}
633*/ 1111*/
634void QTReaderApp::editMark() 1112void QTReaderApp::editMark()
635{ 1113{
636 m_savedpos = reader->pagelocate(); 1114 m_savedpos = reader->pagelocate();
637} 1115}
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()
663{ 1134{
664 reader->goUp(); 1135 reader->goUp();
665} 1136}
666 1137
667void QTReaderApp::pagedn() 1138void QTReaderApp::pagedn()
668{ 1139{
669 reader->goDown(); 1140 reader->goDown();
670} 1141}
671 1142
672void QTReaderApp::stripcr(bool _b) 1143void 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);
679} 1170}
680void QTReaderApp::dehyphen(bool _b) 1171void QTReaderApp::dehyphen(bool _b)
681{ 1172{
682 reader->setdehyphen(_b); 1173 reader->setdehyphen(_b);
683} 1174}
684void QTReaderApp::unindent(bool _b) 1175void QTReaderApp::unindent(bool _b)
685{ 1176{
686 reader->setunindent(_b); 1177 reader->setunindent(_b);
687} 1178}
688void QTReaderApp::repara(bool _b) 1179void 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);
701} 1186}
702void QTReaderApp::pagemode(bool _b) 1187void QTReaderApp::pagemode(bool _b)
703{ 1188{
704 reader->setpagemode(_b); 1189 reader->setpagemode(_b);
705} 1190}
706 1191
707void QTReaderApp::monospace(bool _b) 1192void QTReaderApp::monospace(bool _b)
708{ 1193{
709 reader->setmono(_b); 1194 reader->setmono(_b);
710} 1195}
711 1196
712void QTReaderApp::setspacing() 1197void QTReaderApp::setspacing()
713{ 1198{
714 m_nRegAction = cMonoSpace; 1199 m_nRegAction = cMonoSpace;
715 char lcn[20]; 1200 char lcn[20];
716 sprintf(lcn, "%lu", reader->m_charpc); 1201 sprintf(lcn, "%lu", reader->m_charpc);
717 regEdit->setText(lcn); 1202 regEdit->setText(lcn);
718 do_regedit(); 1203 do_regedit();
719} 1204}
720 1205
721void QTReaderApp::setoverlap() 1206void QTReaderApp::setoverlap()
722{ 1207{
723 m_nRegAction = cOverlap; 1208 m_nRegAction = cOverlap;
724 char lcn[20]; 1209 char lcn[20];
725 sprintf(lcn, "%lu", reader->m_overlap); 1210 sprintf(lcn, "%lu", reader->m_overlap);
726 regEdit->setText(lcn); 1211 regEdit->setText(lcn);
727 do_regedit(); 1212 do_regedit();
728} 1213}
729 1214
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}
739 1224
740void QTReaderApp::do_overlap(const QString& lcn) 1225void QTReaderApp::do_overlap(const QString& lcn)
741{ 1226{
742 bool ok; 1227 bool ok;
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)
753{ 1238{
754 bool ok; 1239 bool ok;
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/*
766void QTReaderApp::editPaste() 1253void QTReaderApp::editPaste()
767{ 1254{
768#ifndef QT_NO_CLIPBOARD 1255#ifndef QT_NO_CLIPBOARD
769 editor->paste(); 1256 editor->paste();
770#endif 1257#endif
771} 1258}
772*/ 1259*/
773 1260
774void QTReaderApp::editFind() 1261void QTReaderApp::editFind()
775{ 1262{
776 searchStart = reader->pagelocate(); 1263 searchStart = reader->pagelocate();
777#ifdef __ISEARCH 1264#ifdef __ISEARCH
778 searchStack = new QStack<searchrecord>; 1265 searchStack = new QStack<searchrecord>;
779#endif 1266#endif
780 searchBar->show(); 1267 searchBar->show();
781 searchVisible = TRUE; 1268 searchVisible = TRUE;
782 searchEdit->setFocus(); 1269 searchEdit->setFocus();
783#ifdef __ISEARCH 1270#ifdef __ISEARCH
784 searchStack->push(new searchrecord("",reader->pagelocate())); 1271 searchStack->push(new searchrecord("",reader->pagelocate()));
785#endif 1272#endif
786} 1273}
787 1274
788void QTReaderApp::findNext() 1275void QTReaderApp::findNext()
789{ 1276{
790 // qDebug("findNext called\n"); 1277 // qDebug("findNext called\n");
791#ifdef __ISEARCH 1278#ifdef __ISEARCH
792 QString arg = searchEdit->text(); 1279 QString arg = searchEdit->text();
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());
800 dosearch(start, test, arg); 1287 dosearch(start, test, arg);
801} 1288}
802 1289
803void QTReaderApp::findClose() 1290void QTReaderApp::findClose()
804{ 1291{
805 searchVisible = FALSE; 1292 searchVisible = FALSE;
806 searchEdit->setText(""); 1293 searchEdit->setText("");
807 searchBar->hide(); 1294 searchBar->hide();
808#ifdef __ISEARCH 1295#ifdef __ISEARCH
809// searchStack = new QStack<searchrecord>; 1296// searchStack = new QStack<searchrecord>;
810 while (!searchStack->isEmpty()) 1297 while (!searchStack->isEmpty())
811 { 1298 {
812 delete searchStack->pop(); 1299 delete searchStack->pop();
813 } 1300 }
814 delete searchStack; 1301 delete searchStack;
815#endif 1302#endif
816 reader->setFocus(); 1303 reader->setFocus();
817} 1304}
818 1305
819void QTReaderApp::regClose() 1306void QTReaderApp::regClose()
820{ 1307{
821 regVisible = FALSE; 1308 regVisible = FALSE;
822 regEdit->setText(""); 1309 regEdit->setText("");
823 regBar->hide(); 1310 regBar->hide();
824 reader->setFocus(); 1311 reader->setFocus();
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)
838#else 1325#else
839#ifdef _UNICODE 1326#ifdef _UNICODE
840 while (arg.match(toQString(test.data())) == -1) 1327 while (arg.match(toQString(test.data())) == -1)
841#else 1328#else
842 while (arg.match(test.data()) == -1) 1329 while (arg.match(test.data()) == -1)
843#endif 1330#endif
844#endif 1331#endif
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;
860} 1347}
861 1348
862#ifdef __ISEARCH 1349#ifdef __ISEARCH
863void QTReaderApp::search(const QString & arg) 1350void QTReaderApp::search(const QString & arg)
864{ 1351{
865 searchrecord* ss = searchStack->top(); 1352 searchrecord* ss = searchStack->top();
866 CBuffer test; 1353 CBuffer test;
867 size_t start = reader->pagelocate(); 1354 size_t start = reader->pagelocate();
868 bool haspopped = false; 1355 bool haspopped = false;
869 while (arg.left(ss->s.length()) != ss->s) 1356 while (arg.left(ss->s.length()) != ss->s)
870 { 1357 {
871 haspopped = true; 1358 haspopped = true;
872 start = ss->pos; 1359 start = ss->pos;
873// reader->locate(start); 1360// reader->locate(start);
874 searchStack->pop(); 1361 searchStack->pop();
875 delete ss; 1362 delete ss;
876 } 1363 }
877 if (haspopped) reader->locate(start); 1364 if (haspopped) reader->locate(start);
878/* 1365/*
879 if (arg.length() < ss->len) 1366 if (arg.length() < ss->len)
880 { 1367 {
881 start = ss->pos; 1368 start = ss->pos;
882 reader->locate(start); 1369 reader->locate(start);
883 searchStack->pop(); 1370 searchStack->pop();
884 delete ss; 1371 delete ss;
885 } 1372 }
886*/ 1373*/
887 else 1374 else
888 { 1375 {
889 start = reader->pagelocate(); 1376 start = reader->pagelocate();
890 reader->jumpto(start); 1377 reader->jumpto(start);
891 searchStack->push(new searchrecord(arg,start)); 1378 searchStack->push(new searchrecord(arg,start));
892 } 1379 }
893 dosearch(start, test, arg); 1380 dosearch(start, test, arg);
894} 1381}
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
906void QTReaderApp::openFile( const QString &f ) 1389void QTReaderApp::openFile( const QString &f )
907{ 1390{
908 openFile(DocLnk(f)); 1391 openFile(DocLnk(f));
909} 1392}
910 1393
911void QTReaderApp::openFile( const DocLnk &f ) 1394void QTReaderApp::openFile( const DocLnk &f )
912{ 1395{
913 clear(); 1396 clear();
914 FileManager fm; 1397 FileManager fm;
915 if ( fm.exists( f ) ) 1398 if ( fm.exists( f ) )
916 { 1399 {
917// QMessageBox::information(0, "Progress", "Calling fileNew()"); 1400// QMessageBox::information(0, "Progress", "Calling fileNew()");
918 1401
919 clear(); 1402 clear();
920 1403
921 // editorStack->raiseWidget( reader ); 1404 // editorStack->raiseWidget( reader );
922 1405
923 // reader->setFocus(); 1406 // reader->setFocus();
924 1407
925 // QMessageBox::information(0, "DocLnk", "Begin"); 1408 // QMessageBox::information(0, "DocLnk", "Begin");
926 doc = new DocLnk(f); 1409 doc = new DocLnk(f);
927 // QMessageBox::information(0, "DocLnk done", doc->file()); 1410 // QMessageBox::information(0, "DocLnk done", doc->file());
928 // QMessageBox::information(0, "Progress", "Calling setText()"); 1411 // QMessageBox::information(0, "Progress", "Calling setText()");
929 // QMessageBox::information(0, "Progress", "Textset"); 1412 // QMessageBox::information(0, "Progress", "Textset");
930 1413
931 // updateCaption(); 1414 // updateCaption();
932 showEditTools(); 1415 showEditTools();
933 reader->setText(doc->name(), doc->file()); 1416 reader->setText(doc->name(), doc->file());
934 readbkmks(); 1417 readbkmks();
935 } 1418 }
936 else 1419 else
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();
957 editorStack->raiseWidget( reader ); 1440 editorStack->raiseWidget( reader );
958 reader->setFocus(); 1441 reader->setFocus();
959} 1442}
960/* 1443/*
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 );
988} 1471}
989*/ 1472*/
990 1473
991void QTReaderApp::clear() 1474void QTReaderApp::clear()
992{ 1475{
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}
1002 1485
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
1015void QTReaderApp::setDocument(const QString& fileref) 1498void QTReaderApp::setDocument(const QString& fileref)
1016{ 1499{
1017 bFromDocView = TRUE; 1500 bFromDocView = TRUE;
1018//QMessageBox::information(0, "setDocument", fileref); 1501//QMessageBox::information(0, "setDocument", fileref);
1019 openFile(DocLnk(fileref)); 1502 openFile(DocLnk(fileref));
1020// showEditTools(); 1503// showEditTools();
1021} 1504}
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
1062void QTReaderApp::do_gotomark() 1552void QTReaderApp::do_gotomark()
1063{ 1553{
1064 m_nRegAction = cGotoBkmk; 1554 m_nRegAction = cGotoBkmk;
1065 listbkmk(); 1555 listbkmk();
1066} 1556}
1067 1557
1068void QTReaderApp::do_delmark() 1558void QTReaderApp::do_delmark()
1069{ 1559{
1070 m_nRegAction = cDelBkmk; 1560 m_nRegAction = cDelBkmk;
1071 listbkmk(); 1561 listbkmk();
1072} 1562}
1073 1563
1074void QTReaderApp::listbkmk() 1564void QTReaderApp::listbkmk()
1075{ 1565{
1076 bkmkselector->clear(); 1566 bkmkselector->clear();
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();
1097 if (searchVisible) searchBar->hide(); 1586 if (searchVisible) searchBar->hide();
1098 editorStack->raiseWidget( bkmkselector ); 1587 editorStack->raiseWidget( bkmkselector );
1099 } 1588 }
1100 else 1589 else
1101 QMessageBox::information(this, "QTReader", "No bookmarks in memory"); 1590 QMessageBox::information(this, "QTReader", "No bookmarks in memory");
1102} 1591}
1103 1592
1104void QTReaderApp::do_autogen() 1593void QTReaderApp::do_autogen()
1105{ 1594{
1106 m_nRegAction = cAutoGen; 1595 m_nRegAction = cAutoGen;
1107 regEdit->setText(m_autogenstr); 1596 regEdit->setText(m_autogenstr);
1108 do_regedit(); 1597 do_regedit();
1109} 1598}
1110 1599
1111void QTReaderApp::do_regedit() 1600void QTReaderApp::do_regedit()
1112{ 1601{
1113// editBar->hide(); 1602// editBar->hide();
1114 regBar->show(); 1603 regBar->show();
1115 regVisible = true; 1604 regVisible = true;
1116 regEdit->setFocus(); 1605 regEdit->setFocus();
1117} 1606}
1118 1607
1119void QTReaderApp::gotobkmk(int ind) 1608void 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}
1137 1627
1138void QTReaderApp::cancelbkmk() 1628void QTReaderApp::cancelbkmk()
1139{ 1629{
1140 showEditTools(); 1630 showEditTools();
1141} 1631}
1142 1632
1143void QTReaderApp::jump() 1633void QTReaderApp::jump()
1144{ 1634{
1145 m_nRegAction = cJump; 1635 m_nRegAction = cJump;
1146 char lcn[20]; 1636 char lcn[20];
1147 sprintf(lcn, "%lu", reader->pagelocate()); 1637 sprintf(lcn, "%lu", reader->pagelocate());
1148 regEdit->setText(lcn); 1638 regEdit->setText(lcn);
1149 do_regedit(); 1639 do_regedit();
1150} 1640}
1151 1641
1152void QTReaderApp::do_jump(const QString& lcn) 1642void QTReaderApp::do_jump(const QString& lcn)
1153{ 1643{
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()
1163{ 1653{
1164 regBar->hide(); 1654 regBar->hide();
1165 regVisible = false; 1655 regVisible = false;
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();
1189 reader->setFocus(); 1679 reader->setFocus();
1190} 1680}
1191 1681
1192void QTReaderApp::do_settarget(const QString& _txt) 1682void QTReaderApp::do_settarget(const QString& _txt)
1193{ 1683{
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
1208void QTReaderApp::setfont() 1698void 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;
1239 reader->sizes(fs,ts); 1739 reader->sizes(fs,ts);
1240 // qDebug("Reg:%s\n", (const tchar*)(regEdit->text())); 1740 // qDebug("Reg:%s\n", (const tchar*)(regEdit->text()));
1241 m_autogenstr = regText; 1741 m_autogenstr = regText;
1242 QRegExp re(regText); 1742 QRegExp re(regText);
1243 CBuffer buff; 1743 CBuffer buff;
1244 if (pBkmklist != NULL) delete pBkmklist; 1744 if (pBkmklist != NULL) delete pBkmklist;
1245 pBkmklist = new CList<Bkmk>; 1745 pBkmklist = new CList<Bkmk>;
1246 m_fBkmksChanged = true; 1746 m_fBkmksChanged = true;
1247 pbar->show(); 1747 pbar->show();
1248pbar->resize(width(), editBar->height()); 1748pbar->resize(width(), editBar->height());
1249 pbar->reset(); 1749 pbar->reset();
1250 qApp->processEvents(); 1750 qApp->processEvents();
1251 reader->setFocus(); 1751 reader->setFocus();
1252 reader->jumpto(0); 1752 reader->jumpto(0);
1253 int lastpc = 0; 1753 int lastpc = 0;
1254 int i = 0; 1754 int i = 0;
1255 while (i >= 0) 1755 while (i >= 0)
1256 { 1756 {
1257 unsigned int lcn = reader->locate(); 1757 unsigned int lcn = reader->locate();
1258 int pc = (100*lcn)/ts; 1758 int pc = (100*lcn)/ts;
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);
1268#ifdef _UNICODE 1768#ifdef _UNICODE
1269 if (re.match(toQString(buff.data())) != -1) 1769 if (re.match(toQString(buff.data())) != -1)
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();
1278} 1779}
1279 1780
1280void QTReaderApp::saveprefs() 1781void QTReaderApp::saveprefs()
1281{ 1782{
1282// reader->saveprefs("uqtreader"); 1783// reader->saveprefs("uqtreader");
1283 Config config( "uqtreader" ); 1784 Config config( "uqtreader" );
1284 config.setGroup( "View" ); 1785 config.setGroup( "View" );
1285 1786
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()) );
1300 config.writeEntry( "PageMode", reader->m_bpagemode ); 1802 config.writeEntry( "PageMode", reader->m_bpagemode );
1301 config.writeEntry( "MonoSpaced", reader->m_bMonoSpaced ); 1803 config.writeEntry( "MonoSpaced", reader->m_bMonoSpaced );
1302 config.writeEntry( "Fontname", reader->m_fontname ); 1804 config.writeEntry( "Fontname", reader->m_fontname );
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()
1311{ 1821{
1312 reader->indentplus(); 1822 reader->indentplus();
1313} 1823}
1314 1824
1315void QTReaderApp::indentminus() 1825void QTReaderApp::indentminus()
1316{ 1826{
1317 reader->indentminus(); 1827 reader->indentminus();
1318} 1828}
1319 1829
1320/* 1830/*
1321void QTReaderApp::oldFile() 1831void QTReaderApp::oldFile()
1322{ 1832{
1323 qDebug("oldFile called"); 1833 qDebug("oldFile called");
1324 reader->setText(true); 1834 reader->setText(true);
1325 qDebug("settext called"); 1835 qDebug("settext called");
1326 showEditTools(); 1836 showEditTools();
1327 qDebug("showedit called"); 1837 qDebug("showedit called");
1328} 1838}
1329*/ 1839*/
1330 1840
1331/* 1841/*
1332void info_cb(Fl_Widget* o, void* _data) 1842void info_cb(Fl_Widget* o, void* _data)
1333{ 1843{
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}
1374*/ 1884*/
1375 1885
1376void QTReaderApp::savebkmks() 1886void 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()
1404{ 1914{
1405 m_nRegAction = cAddBkmk; 1915 m_nRegAction = cAddBkmk;
1406 regEdit->setText(reader->firstword()); 1916 regEdit->setText(reader->firstword());
1407 do_regedit(); 1917 do_regedit();
1408} 1918}
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
@@ -1,206 +1,263 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef __QTREADERAPP_H 20#ifndef __QTREADERAPP_H
21#define __QTREADERAPP_H 21#define __QTREADERAPP_H
22 22
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
47{ 60{
48 QString s; 61 QString s;
49 size_t pos; 62 size_t pos;
50 searchrecord(const QString& _s, size_t _pos) : s(_s), pos(_pos) {} 63 searchrecord(const QString& _s, size_t _pos) : s(_s), pos(_pos) {}
51}; 64};
52#endif 65#endif
53 66
54class infowin; 67class infowin;
55 68
56class QTReaderApp : public QMainWindow 69class QTReaderApp : public QMainWindow
57{ 70{
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 );
64 ~QTReaderApp(); 78 ~QTReaderApp();
65 79
66 void openFile( const QString & ); 80 void openFile( const QString & );
67 81
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&);
74 void do_jump(const QString&); 92 void do_jump(const QString&);
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();
86 void setoverlap(); 129 void setoverlap();
87 void settarget(); 130 void settarget();
88 void setspacing(); 131 void setspacing();
89 void setfont(); 132 void setfont();
90 void clearBkmkList(); 133 void clearBkmkList();
91 void listBkmkFiles(); 134 void listBkmkFiles();
92 void editMark(); 135 void editMark();
93 void autoScroll(bool); 136 void autoScroll(bool);
94 void addbkmk(); 137 void addbkmk();
95 void savebkmks(); 138 void savebkmks();
96 //void importFiles(); 139 //void importFiles();
97 void infoClose(); 140 void infoClose();
98 // void oldFile(); 141 // void oldFile();
99 void showinfo(); 142 void showinfo();
100 void setDocument(const QString&); 143 void setDocument(const QString&);
101 void TBD(); 144 void TBD();
102 void TBDzoom(); 145 void TBDzoom();
103 146
104 void indentplus(); 147 void indentplus();
105 void indentminus(); 148 void indentminus();
106 149
107 void fileOpen(); 150 void fileOpen();
108 151
109 void editCopy(); 152 void editCopy();
110 void editFind(); 153 void editFind();
111 154
112 void pageup(); 155 void pageup();
113 void pagedn(); 156 void pagedn();
114 157
115 void findNext(); 158 void findNext();
116 void findClose(); 159 void findClose();
117 160
118 void regClose(); 161 void regClose();
119 162
120#ifdef __ISEARCH 163#ifdef __ISEARCH
121// void search( const QString& ); 164// void search( const QString& );
122#else 165#else
123 void search(); 166 void search();
124#endif 167#endif
125 168
126 void openFile( const DocLnk & ); 169 void openFile( const DocLnk & );
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);
138 void gotobkmk(int); 185 void gotobkmk(int);
139 void cancelbkmk(); 186 void cancelbkmk();
140 void do_gotomark(); 187 void do_gotomark();
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 );
149 void clear(); 199 void clear();
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
156 QAction* m_scrollButton; 207 QAction* m_scrollButton;
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++; }
181 /* 237 /*
182 void resizeEvent( QResizeEvent * r) 238 void resizeEvent( QResizeEvent * r)
183 { 239 {
184 qDebug("resize:(%u,%u)", r->oldSize().width(), r->oldSize().height()); 240 qDebug("resize:(%u,%u)", r->oldSize().width(), r->oldSize().height());
185 qDebug("resize:(%u,%u)", r->size().width(), r->size().height()); 241 qDebug("resize:(%u,%u)", r->size().width(), r->size().height());
186 // bgroup->move( width()-bgroup->width(), 0 ); 242 // bgroup->move( width()-bgroup->width(), 0 );
187 } 243 }
188 */ 244 */
189 CList<Bkmk>* pBkmklist; 245 CList<Bkmk>* pBkmklist;
190 infowin* m_infoWin; 246 infowin* m_infoWin;
191 QProgressBar* pbar; 247 QProgressBar* pbar;
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;
198const int cAddBkmk = 1; 255const int cAddBkmk = 1;
199const int cDelBkmk = 2; 256const int cDelBkmk = 2;
200const int cGotoBkmk = 3; 257const int cGotoBkmk = 3;
201const int cRmBkmkFile = 4; 258const int cRmBkmkFile = 4;
202const int cJump = 5; 259const int cJump = 5;
203const int cMonoSpace = 6; 260const int cMonoSpace = 6;
204const int cOverlap = 7; 261const int cOverlap = 7;
205const int cSetTarget = 8; 262const int cSetTarget = 8;
206#endif 263#endif
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,36 +1,39 @@
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"
9 8
10class Text: public CExpander { 9class Text: public CExpander {
11 gzFile file; 10 gzFile file;
12 unsigned long fsize; 11 unsigned long fsize;
13public: 12public:
14 Text() : file(NULL) {}; 13 Text() : file(NULL) {};
15 virtual ~Text() 14 virtual ~Text()
16 { 15 {
17 if (file != NULL) gzclose(file); 16 if (file != NULL) gzclose(file);
18 } 17 }
19 virtual int openfile(const char *src) 18 virtual int openfile(const char *src)
20 { 19 {
21 if (file != NULL) gzclose(file); 20 if (file != NULL) gzclose(file);
22 struct stat _stat; 21 struct stat _stat;
23 stat(src,&_stat); 22 stat(src,&_stat);
24 fsize = _stat.st_size; 23 fsize = _stat.st_size;
25 return ((file = gzopen(src,"rb")) == NULL); 24 return ((file = gzopen(src,"rb")) == NULL);
26 } 25 }
27 virtual int getch() { return gzgetc(file); } 26 virtual int getch() { return gzgetc(file); }
28 virtual unsigned int locate() { return gztell(file); } 27 virtual unsigned int locate() { return gztell(file); }
29 virtual void locate(unsigned int n) { gzseek(file,n,SEEK_SET); } 28 virtual void locate(unsigned int n) { gzseek(file,n,SEEK_SET); }
30 virtual bool hasrandomaccess() { return true; } 29 virtual bool hasrandomaccess() { return true; }
31 virtual void sizes(unsigned long& _file, unsigned long& _text) 30 virtual void sizes(unsigned long& _file, unsigned long& _text)
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
@@ -1,185 +1,204 @@
1/**************************************************************************** 1/****************************************************************************
2 2
3Derived from a file browser which was 3Derived from a file browser which was
4 4
5** copyright 2001 ljp ljp@llornkcor.com 5** copyright 2001 ljp ljp@llornkcor.com
6 6
7Extensive modification by Tim Wentford to allow it to work in rotated mode 7Extensive modification by Tim Wentford to allow it to work in rotated mode
8 8
9****************************************************************************/ 9****************************************************************************/
10#include "fileBrowser.h" 10#include "fileBrowser.h"
11 11
12#include "QtrListView.h" 12#include "QtrListView.h"
13#include <qpushbutton.h> 13#include <qpushbutton.h>
14#include <qfile.h> 14#include <qfile.h>
15#include <qmessagebox.h> 15#include <qmessagebox.h>
16#include <unistd.h> 16#include <unistd.h>
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 )
24 setName( "fileBrowser" ); 24 setName( "fileBrowser" );
25 if (parent != NULL) resize( parent->width(), parent->height() ); 25 if (parent != NULL) resize( parent->width(), parent->height() );
26 setCaption(tr( "Browse for file" ) ); 26 setCaption(tr( "Browse for file" ) );
27 filterStr=filter; 27 filterStr=filter;
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
36 ListView = new QtrListView( this, "ListView" ); 44 ListView = new QtrListView( this, "ListView" );
37 ListView->addColumn( tr( "Name" ) ); 45 ListView->addColumn( tr( "Name" ) );
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 *)) );
48 connect( ListView, SIGNAL(OnOKButton( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); 56 connect( ListView, SIGNAL(OnOKButton( QListViewItem*)), SLOT(listClicked(QListViewItem *)) );
49 connect( ListView, SIGNAL(OnCentreButton( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); 57 connect( ListView, SIGNAL(OnCentreButton( QListViewItem*)), SLOT(listClicked(QListViewItem *)) );
50 connect( ListView, SIGNAL(OnCancelButton()), SLOT(OnCancel()) ); 58 connect( ListView, SIGNAL(OnCancelButton()), SLOT(OnCancel()) );
51 59
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
58 if (QFileInfo(iPath).exists()) 67 if (QFileInfo(iPath).exists())
59 { 68 {
60 currentDir.setPath(iPath); 69 currentDir.setPath(iPath);
61 chdir(iPath.latin1()); 70 chdir(iPath.latin1());
62 } 71 }
63 else 72 else
64 { 73 {
65 currentDir.setPath(QDir::currentDirPath()); 74 currentDir.setPath(QDir::currentDirPath());
66 chdir(QDir::currentDirPath().latin1()); 75 chdir(QDir::currentDirPath().latin1());
67 } 76 }
68 77
69 populateList(); 78 populateList();
70} 79}
71 80
72void fileBrowser::resizeEvent(QResizeEvent* e) 81void fileBrowser::resizeEvent(QResizeEvent* e)
73{ 82{
74 ListView->setColumnWidth(1,(ListView->width())/4); 83 ListView->setColumnWidth(1,(ListView->width())/4);
75 ListView->setColumnWidth(0,ListView->width()-20-ListView->columnWidth(1)); 84 ListView->setColumnWidth(0,ListView->width()-20-ListView->columnWidth(1));
76} 85}
77 86
78fileBrowser::~fileBrowser() 87fileBrowser::~fileBrowser()
79{ 88{
80} 89}
81 90
82 91
83void fileBrowser::populateList() 92void fileBrowser::populateList()
84{ 93{
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()) )
99 { 108 {
100 if (fi->fileName() != ".") 109 if (fi->fileName() != ".")
101 { 110 {
102 fileS.sprintf( "%10li", fi->size() ); 111 fileS.sprintf( "%10li", fi->size() );
103 fileL.sprintf( "%s",fi->fileName().data() ); 112 fileL.sprintf( "%s",fi->fileName().data() );
104 if( fi->isDir() ) 113 if( fi->isDir() )
105 { 114 {
106 fileL+="/"; 115 fileL+="/";
107 } 116 }
108 else 117 else
109 { 118 {
110// qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); 119// qDebug("Not a dir: "+currentDir.canonicalPath()+fileL);
111 } 120 }
112 new QListViewItem( ListView,fileL,fileS ); 121 new QListViewItem( ListView,fileL,fileS );
113 } 122 }
114 ++it; 123 ++it;
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()
121{ 131{
122// qDebug(currentDir.canonicalPath()); 132// qDebug(currentDir.canonicalPath());
123} 133}
124 134
125void fileBrowser::listClicked(QListViewItem *selectedItem) 135void fileBrowser::listClicked(QListViewItem *selectedItem)
126{ 136{
127 if (selectedItem == NULL) return; 137 if (selectedItem == NULL) return;
128 QString strItem=selectedItem->text(0); 138 QString strItem=selectedItem->text(0);
129 139
130// qDebug("%s", (const char*)strItem); 140// qDebug("%s", (const char*)strItem);
131 141
132 142
133 QString strSize=selectedItem->text(1); 143 QString strSize=selectedItem->text(1);
134 144
135 strSize.stripWhiteSpace(); 145 strSize.stripWhiteSpace();
136 146
137 bool ok; 147 bool ok;
138 148
139 QFileInfo fi(strItem); 149 QFileInfo fi(strItem);
140 while (fi.isSymLink()) fi.setFile(fi.readLink()); 150 while (fi.isSymLink()) fi.setFile(fi.readLink());
141 if (fi.isDir()) 151 if (fi.isDir())
142 { 152 {
143 strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); 153 strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem);
144 154
145 if(QDir(strItem).exists()) 155 if(QDir(strItem).exists())
146 { 156 {
147 currentDir.cd(strItem, TRUE); 157 currentDir.cd(strItem, TRUE);
148 populateList(); 158 populateList();
149 } 159 }
150 } else 160 } else
151 OnOK(); 161 OnOK();
152 chdir(strItem.latin1()); 162 chdir(strItem.latin1());
153// 163//
154 164
155} 165}
156 166
157// you may want to switch these 2 functions. I like single clicks 167// you may want to switch these 2 functions. I like single clicks
158void fileBrowser::listDoubleClicked(QListViewItem *selectedItem) 168void fileBrowser::listDoubleClicked(QListViewItem *selectedItem)
159{ 169{
160} 170}
161 171
162void fileBrowser::OnOK() { 172void fileBrowser::OnOK() {
163 173
164 QListViewItemIterator it1( ListView); 174 QListViewItemIterator it1( ListView);
165 for ( ; it1.current(); ++it1 ) { 175 for ( ; it1.current(); ++it1 ) {
166 if ( it1.current()->isSelected() ) { 176 if ( it1.current()->isSelected() ) {
167 selectedFileName=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+it1.current()->text(0)); 177 selectedFileName=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+it1.current()->text(0));
168 // qDebug("selected filename is "+selectedFileName); 178 // qDebug("selected filename is "+selectedFileName);
169 fileList.append( selectedFileName ); 179 fileList.append( selectedFileName );
170 } 180 }
171 } 181 }
172 accept(); 182 accept();
173} 183}
174 184
175void fileBrowser::OnRoot() 185void fileBrowser::OnRoot()
176{ 186{
177 currentDir.cd("/", TRUE); 187 currentDir.cd("/", TRUE);
178 populateList(); 188 populateList();
179 chdir("/"); 189 chdir("/");
180} 190}
181 191
182void fileBrowser::OnCancel() 192void 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
@@ -1,70 +1,74 @@
1/* 1/*
2Derived from the file browser published by ljp@llornkcor.com but extensively 2Derived from the file browser published by ljp@llornkcor.com but extensively
3modified to work in rotated views on the Zaurus 3modified to work in rotated views on the Zaurus
4*/ 4*/
5 5
6/**************************************************************************** 6/****************************************************************************
7** Form interface generated from reading ui file 'fileBrowzer.ui' 7** Form interface generated from reading ui file 'fileBrowzer.ui'
8** 8**
9** Created: Fri Dec 14 08:16:02 2001 9** Created: Fri Dec 14 08:16:02 2001
10** by: The User Interface Compiler (uic) 10** by: The User Interface Compiler (uic)
11** 11**
12** WARNING! All changes made in this file will be lost! 12** WARNING! All changes made in this file will be lost!
13blah,blah,blah 13blah,blah,blah
14****************************************************************************/ 14****************************************************************************/
15#ifndef FILEBROWSER_H 15#ifndef FILEBROWSER_H
16#define FILEBROWSER_H 16#define FILEBROWSER_H
17 17
18//#include <qvariant.h> 18//#include <qvariant.h>
19#include <qdialog.h> 19#include <qdialog.h>
20#include <qfile.h> 20#include <qfile.h>
21#include <qdir.h> 21#include <qdir.h>
22#include <qstringlist.h> 22#include <qstringlist.h>
23#include <qlabel.h> 23#include <qlabel.h>
24#include <qstring.h> 24#include <qstring.h>
25 25
26class QVBoxLayout; 26class QVBoxLayout;
27class QHBoxLayout; 27class QHBoxLayout;
28class QGridLayout; 28class QGridLayout;
29class QtrListView; 29class QtrListView;
30class QListViewItem; 30class QListViewItem;
31class QPushButton; 31class QPushButton;
32 32
33class fileBrowser : public QDialog 33class fileBrowser : public QDialog
34{ 34{
35 Q_OBJECT 35 Q_OBJECT
36 36
37public: 37public:
38 void populateList(); 38 void populateList();
39 fileBrowser( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ,const QString filter=0, const QString iPath=0); 39 fileBrowser( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ,const QString filter=0, const QString iPath=0);
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;
46 QString selectedFileName, filterStr; 47 QString selectedFileName, filterStr;
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:
53 56
54private: 57private:
55 58
56private slots: 59private slots:
57 void upDir(); 60 void upDir();
58 void listDoubleClicked(QListViewItem *); 61 void listDoubleClicked(QListViewItem *);
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
65protected: 69protected:
66 void OnOK(); 70 void OnOK();
67 virtual void resizeEvent(QResizeEvent* e); 71 virtual void resizeEvent(QResizeEvent* e);
68}; 72};
69 73
70#endif // FILEBROWSER_H 74#endif // FILEBROWSER_H
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,41 +1,42 @@
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)
8{ 7{
9 grid = new QGridLayout(this, 6, 2); 8 grid = new QGridLayout(this, 6, 2);
10 QLabel* l; 9 QLabel* l;
11 l = new QLabel("Compressed file size", this); 10 l = new QLabel("Compressed file size", this);
12 grid->addWidget(l, 0, 0); 11 grid->addWidget(l, 0, 0);
13 fileSize = new QLabel("0", this); 12 fileSize = new QLabel("0", this);
14 fileSize->setAlignment( AlignVCenter | AlignRight ); 13 fileSize->setAlignment( AlignVCenter | AlignRight );
15 grid->addWidget(fileSize, 0, 1); 14 grid->addWidget(fileSize, 0, 1);
16 l = new QLabel("Original text size", this); 15 l = new QLabel("Original text size", this);
17 grid->addWidget(l, 1, 0); 16 grid->addWidget(l, 1, 0);
18 textSize = new QLabel("0", this); 17 textSize = new QLabel("0", this);
19 textSize->setAlignment( AlignVCenter | AlignRight ); 18 textSize->setAlignment( AlignVCenter | AlignRight );
20 grid->addWidget(textSize, 1, 1); 19 grid->addWidget(textSize, 1, 1);
21 l = new QLabel("Compression Ratio", this); 20 l = new QLabel("Compression Ratio", this);
22 grid->addWidget(l, 2, 0); 21 grid->addWidget(l, 2, 0);
23 ratio = new QLabel("0", this); 22 ratio = new QLabel("0", this);
24 grid->addWidget(ratio, 2, 1); 23 grid->addWidget(ratio, 2, 1);
25 ratio->setAlignment( AlignVCenter | AlignRight ); 24 ratio->setAlignment( AlignVCenter | AlignRight );
26 l = new QLabel("Current location", this); 25 l = new QLabel("Current location", this);
27 grid->addWidget(l, 3, 0); 26 grid->addWidget(l, 3, 0);
28 location = new QLabel("0", this); 27 location = new QLabel("0", this);
29 location->setAlignment( AlignVCenter | AlignRight ); 28 location->setAlignment( AlignVCenter | AlignRight );
30 grid->addWidget(location, 3, 1); 29 grid->addWidget(location, 3, 1);
31 l = new QLabel("Per centage read", this); 30 l = new QLabel("Per centage read", this);
32 grid->addWidget(l, 4, 0); 31 grid->addWidget(l, 4, 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() ) );
40 grid->addWidget(exitbutton, 5, 1); 41 grid->addWidget(exitbutton, 5, 1);
41} 42}
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
@@ -1,172 +1,183 @@
1#ifndef __MY_LIST_H 1#ifndef __MY_LIST_H
2#define __MY_LIST_H 2#define __MY_LIST_H
3 3
4template<class T> 4template<class T>
5class CList 5class CList
6{ 6{
7 struct node 7 struct node
8 { 8 {
9 T data; 9 T data;
10 node* next; 10 node* next;
11 node(T _data, node* _next = NULL) : data(_data), next(_next) {} 11 node(T _data, node* _next = NULL) : data(_data), next(_next) {}
12 node() : next(NULL) {}; 12 node() : next(NULL) {};
13 }; 13 };
14 protected: 14 protected:
15 node* front; 15 node* front;
16 node* back; 16 node* back;
17 public: 17 public:
18 CList() : front(NULL), back(NULL) {} 18 CList() : front(NULL), back(NULL) {}
19 ~CList() 19 ~CList()
20 { 20 {
21 if (front != NULL) 21 if (front != NULL)
22 { 22 {
23 while (front != NULL) 23 while (front != NULL)
24 { 24 {
25 node *p = front; 25 node *p = front;
26 front = p->next; 26 front = p->next;
27 delete p; 27 delete p;
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;
34 while (n-- > 0) 36 while (n-- > 0)
35 { 37 {
36 if ((current = current->next) == NULL) 38 if ((current = current->next) == NULL)
37 return NULL; 39 return NULL;
38 } 40 }
39 return &(current->data); 41 return &(current->data);
40 } 42 }
41 void push_front(const T& t) 43 void push_front(const T& t)
42 { 44 {
43 node* n = new node(t,front); 45 node* n = new node(t,front);
44 if (front == NULL) 46 if (front == NULL)
45 { 47 {
46 front = back = n; 48 front = back = n;
47 } 49 }
48 else 50 else
49 front = n; 51 front = n;
50 } 52 }
51 void push_back(const T& t) 53 void push_back(const T& t)
52 { 54 {
53 node* n = new node(t); 55 node* n = new node(t);
54 if (front == NULL) 56 if (front == NULL)
55 { 57 {
56 front = back = n; 58 front = back = n;
57 } 59 }
58 else 60 else
59 { 61 {
60 back->next = n; 62 back->next = n;
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;
67 node* last = front; 70 node* last = front;
68 while (n-- > 0) 71 while (n-- > 0)
69 { 72 {
70 last = p; 73 last = p;
71 p = p->next; 74 p = p->next;
72 if (p == NULL) return; 75 if (p == NULL) return;
73 } 76 }
74 if (p == front) 77 if (p == front)
75 { 78 {
76 front = p->next; 79 front = p->next;
77 } 80 }
78 else 81 else
79 { 82 {
80 last->next = p->next; 83 last->next = p->next;
81 } 84 }
82 if (p == back) 85 if (p == back)
83 { 86 {
84 back = last; 87 back = last;
85 } 88 }
86 delete p; 89 delete p;
87 } 90 }
88 void sort() 91 void sort()
89 { 92 {
90 int i,j,inc,n; 93 int i,j,inc,n;
91 T v; 94 T v;
92 T* item; 95 T* item;
93 node* t; 96 node* t;
94 t = front; 97 t = front;
95 n = 0; 98 n = 0;
96 while (t != NULL) 99 while (t != NULL)
97 { 100 {
98 n++; 101 n++;
99 t = t->next; 102 t = t->next;
100 } 103 }
101 if (n >= 2) 104 if (n >= 2)
102 { 105 {
103 item = new T[n]; 106 item = new T[n];
104 i = 0; 107 i = 0;
105 t = front; 108 t = front;
106 for (t = front, i = 0; t != NULL; t = t->next, i++) 109 for (t = front, i = 0; t != NULL; t = t->next, i++)
107 { 110 {
108 item[i] = t->data; 111 item[i] = t->data;
109 } 112 }
110 113
111 for (inc = 1; inc <= n; inc = 3*inc+1); 114 for (inc = 1; inc <= n; inc = 3*inc+1);
112 115
113 do 116 do
114 { 117 {
115 inc /= 3; 118 inc /= 3;
116 for (i = inc; i < n; i++) 119 for (i = inc; i < n; i++)
117 { 120 {
118 v = item[i]; 121 v = item[i];
119 for (j = i; v < item[j-inc] && j >= inc; j -= inc) 122 for (j = i; v < item[j-inc] && j >= inc; j -= inc)
120 { 123 {
121 item[j] = item[j-inc]; 124 item[j] = item[j-inc];
122 } 125 }
123 item[j] = v; 126 item[j] = v;
124 } 127 }
125 } 128 }
126 while (inc > 1); 129 while (inc > 1);
127 for (t = front, i = 0; t != NULL; t = t->next, i++) 130 for (t = front, i = 0; t != NULL; t = t->next, i++)
128 { 131 {
129 t->data = item[i]; 132 t->data = item[i];
130 } 133 }
131 // back = *(item[n-1]); 134 // back = *(item[n-1]);
132 delete [] item; 135 delete [] item;
133 } 136 }
134 } 137 }
135 class iterator 138 class iterator
136 { 139 {
137 node* current; 140 node* current;
138 public: 141 public:
139 iterator(node* _c) : current(_c) {} 142 iterator(node* _c) : current(_c) {}
140 iterator& operator++() 143 iterator& operator++()
141 { 144 {
142 current = current->next; 145 current = current->next;
143 return *this; 146 return *this;
144 } 147 }
145 iterator& operator++(int) 148 iterator& operator++(int)
146 { 149 {
147 current = current->next; 150 current = current->next;
148 return *this; 151 return *this;
149 } 152 }
150 T operator*() 153 T operator*()
151 { 154 {
152 return current->data; 155 return current->data;
153 } 156 }
154 T* operator->() 157 T* operator->()
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 {
165 return iterator(front); 176 return iterator(front);
166 } 177 }
167 iterator end() 178 iterator end()
168 { 179 {
169 return iterator(NULL); 180 return iterator(NULL);
170 } 181 }
171}; 182};
172#endif 183#endif
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
@@ -1,67 +1,68 @@
1 1
2/* 2/*
3 * This header file defines some structures and types normally found in the 3 * This header file defines some structures and types normally found in the
4 * Palm SDK. However, I don't want to require the presense of the SDK for a 4 * Palm SDK. However, I don't want to require the presense of the SDK for a
5 * small utility since most Palm owners won't have it. 5 * small utility since most Palm owners won't have it.
6 * 6 *
7 * $Id$ 7 * $Id$
8 * 8 *
9 */ 9 */
10 10
11#ifndef __PDB_H__ 11#ifndef __PDB_H__
12#define __PDB_H__ 12#define __PDB_H__
13 13
14#include <netinet/in.h> 14#include <netinet/in.h>
15#include <stdio.h> 15#include <stdio.h>
16 16
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
23/* Max length of DB name */ 24/* Max length of DB name */
24#define dmDBNameLength 0x20 25#define dmDBNameLength 0x20
25 26
26 27
27/************************************************************ 28/************************************************************
28 * Structure of a Record entry 29 * Structure of a Record entry
29 *************************************************************/ 30 *************************************************************/
30typedef struct { 31typedef struct {
31 LocalID localChunkID; // local chunkID of a record 32 LocalID localChunkID; // local chunkID of a record
32 UInt8 attributes; // record attributes; 33 UInt8 attributes; // record attributes;
33 UInt8 uniqueID[3]; // unique ID of record; should 34 UInt8 uniqueID[3]; // unique ID of record; should
34 // not be 0 for a legal record. 35 // not be 0 for a legal record.
35} RecordEntryType; 36} RecordEntryType;
36 37
37 38
38/************************************************************ 39/************************************************************
39 * Structure of a record list extension. This is used if all 40 * Structure of a record list extension. This is used if all
40 * the database record/resource entries of a database can't fit into 41 * the database record/resource entries of a database can't fit into
41 * the database header. 42 * the database header.
42 *************************************************************/ 43 *************************************************************/
43typedef struct { 44typedef struct {
44 LocalID nextRecordListID; // local chunkID of next list 45 LocalID nextRecordListID; // local chunkID of next list
45 UInt16 numRecords; // number of records in this list 46 UInt16 numRecords; // number of records in this list
46 UInt16 firstEntry; // array of Record/Rsrc entries 47 UInt16 firstEntry; // array of Record/Rsrc entries
47 // starts here 48 // starts here
48} RecordListType; 49} RecordListType;
49 50
50 51
51/************************************************************ 52/************************************************************
52 * Structure of a Database Header 53 * Structure of a Database Header
53 *************************************************************/ 54 *************************************************************/
54typedef struct { 55typedef struct {
55 UInt8 name[dmDBNameLength]; // name of database 56 UInt8 name[dmDBNameLength]; // name of database
56 UInt16 attributes; // database attributes 57 UInt16 attributes; // database attributes
57 UInt16 version; // version of database 58 UInt16 version; // version of database
58 UInt32 creationDate; // creation date of database 59 UInt32 creationDate; // creation date of database
59 UInt32 modificationDate; // latest modification date 60 UInt32 modificationDate; // latest modification date
60 UInt32 lastBackupDate; // latest backup date 61 UInt32 lastBackupDate; // latest backup date
61 UInt32 modificationNumber; // modification number of database 62 UInt32 modificationNumber; // modification number of database
62 LocalID appInfoID; // application specific info 63 LocalID appInfoID; // application specific info
63 LocalID sortInfoID; // app specific sorting info 64 LocalID sortInfoID; // app specific sorting info
64 UInt32 type; // database type 65 UInt32 type; // database type
65 UInt32 creator; // database creator 66 UInt32 creator; // database creator
66 UInt32 uniqueIDSeed; // used to generate unique IDs. 67 UInt32 uniqueIDSeed; // used to generate unique IDs.
67 // Note that only the low order 68 // Note that only the low order
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
@@ -1,46 +1,50 @@
1#ifndef __ppm_expander_h 1#ifndef __ppm_expander_h
2#define __ppm_expander_h 2#define __ppm_expander_h
3 3
4#include "CExpander.h" 4#include "CExpander.h"
5#include <sys/stat.h> 5#include <sys/stat.h>
6 6
7 7
8#include "utypes.h" 8#include "utypes.h"
9#include "ppm.h" 9#include "ppm.h"
10#include "arith.h" 10#include "arith.h"
11 11
12 12
13#define SYM_EOF 256 13#define SYM_EOF 256
14 14
15class ppm_expander : public CExpander { 15class ppm_expander : public CExpander {
16 UCHAR *buf_in,*buf_out; 16 UCHAR *buf_in,*buf_out;
17 unsigned int bufsize; 17 unsigned int bufsize;
18 unsigned int outbytes; 18 unsigned int outbytes;
19 unsigned long blocksize; 19 unsigned long blocksize;
20 unsigned short numblocks; 20 unsigned short numblocks;
21 unsigned short curblock; 21 unsigned short curblock;
22 unsigned short maxnode; 22 unsigned short maxnode;
23 bool needppmend; 23 bool needppmend;
24 int home(); 24 int home();
25 FILE* my_file_in; 25 FILE* my_file_in;
26 PPM_ReadBuf* my_read_buf; 26 PPM_ReadBuf* my_read_buf;
27 ppm_worker ppm; 27 ppm_worker ppm;
28 public: 28 public:
29 ppm_expander() : needppmend(false), my_file_in(NULL), my_read_buf(NULL) 29 ppm_expander() : needppmend(false), my_file_in(NULL), my_read_buf(NULL)
30 { 30 {
31 bufsize = 1024; 31 bufsize = 1024;
32 buf_in = new UCHAR[bufsize]; 32 buf_in = new UCHAR[bufsize];
33 buf_out = new UCHAR[bufsize]; 33 buf_out = new UCHAR[bufsize];
34 outbytes = 0; 34 outbytes = 0;
35 } 35 }
36 virtual int openfile(const char* infile); 36 virtual int openfile(const char* infile);
37 virtual int getch(); 37 virtual int getch();
38 int locate(unsigned short block, unsigned int n); 38 int locate(unsigned short block, unsigned int n);
39 virtual ~ppm_expander(); 39 virtual ~ppm_expander();
40 virtual unsigned int locate() { return outbytes; } 40 virtual unsigned int locate() { return outbytes; }
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,51 +1,53 @@
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
7 9
8int ztxt::openfile(const char *src) 10int ztxt::openfile(const char *src)
9{ 11{
10 if (!Cpdb::openfile(src)) 12 if (!Cpdb::openfile(src))
11 { 13 {
12 return -1; 14 return -1;
13 } 15 }
14 16
15//printf("Okay %u\n", 4); 17//printf("Okay %u\n", 4);
16 18
17 if (head.type != ZTXT_ID) return -1; 19 if (head.type != ZTXT_ID) return -1;
18 20
19 gotorecordnumber(0); 21 gotorecordnumber(0);
20 fread(&hdr0, 1, sizeof(hdr0), fin); 22 fread(&hdr0, 1, sizeof(hdr0), fin);
21//printf("Okay %u\n", 5); 23//printf("Okay %u\n", 5);
22 buffersize = ntohl(hdr0.size); 24 buffersize = ntohl(hdr0.size);
23 compressedtextbuffer = new UInt8[buffersize]; 25 compressedtextbuffer = new UInt8[buffersize];
24 expandedtextbuffer = new UInt8[buffersize]; 26 expandedtextbuffer = new UInt8[buffersize];
25//printf("Okay %u\n", 6); 27//printf("Okay %u\n", 6);
26 28
27 home(); 29 home();
28//printf("Okay %u\n", 7); 30//printf("Okay %u\n", 7);
29 31
30// printf("Returning 0\n"); 32// printf("Returning 0\n");
31 33
32 return 0; 34 return 0;
33} 35}
34 36
35int ztxt::getch() 37int ztxt::getch()
36{ 38{
37 if (bufferpos >= buffercontent) 39 if (bufferpos >= buffercontent)
38 { 40 {
39 size_t reclen = recordlength(++bufferrec); 41 size_t reclen = recordlength(++bufferrec);
40 if (reclen == 0) return -1; 42 if (reclen == 0) return -1;
41 gotorecordnumber(bufferrec); 43 gotorecordnumber(bufferrec);
42 fread(compressedtextbuffer, reclen, sizeof(char), fin); 44 fread(compressedtextbuffer, reclen, sizeof(char), fin);
43 45
44 zstream.next_in = compressedtextbuffer; 46 zstream.next_in = compressedtextbuffer;
45 zstream.next_out = expandedtextbuffer; 47 zstream.next_out = expandedtextbuffer;
46 zstream.avail_out = buffersize; 48 zstream.avail_out = buffersize;
47 zstream.avail_in = reclen; 49 zstream.avail_in = reclen;
48 50
49 int ret = inflate(&zstream, Z_SYNC_FLUSH); 51 int ret = inflate(&zstream, Z_SYNC_FLUSH);
50 buffercontent = buffersize - zstream.avail_out; 52 buffercontent = buffersize - zstream.avail_out;
51 bufferpos = 0; 53 bufferpos = 0;
@@ -107,53 +109,53 @@ void ztxt::home()
107{ 109{
108 if (bInit) 110 if (bInit)
109 { 111 {
110 inflateEnd(&zstream); 112 inflateEnd(&zstream);
111 } 113 }
112 bInit = true; 114 bInit = true;
113 size_t reclen = recordlength(1); 115 size_t reclen = recordlength(1);
114 gotorecordnumber(1); 116 gotorecordnumber(1);
115 fread(compressedtextbuffer, reclen, sizeof(char), fin); 117 fread(compressedtextbuffer, reclen, sizeof(char), fin);
116 118
117 zstream.next_in = compressedtextbuffer; 119 zstream.next_in = compressedtextbuffer;
118 zstream.next_out = expandedtextbuffer; 120 zstream.next_out = expandedtextbuffer;
119 zstream.avail_out = buffersize; 121 zstream.avail_out = buffersize;
120 zstream.avail_in = reclen; 122 zstream.avail_in = reclen;
121 123
122 zstream.zalloc = Z_NULL; 124 zstream.zalloc = Z_NULL;
123 zstream.zfree = Z_NULL; 125 zstream.zfree = Z_NULL;
124 zstream.opaque = Z_NULL; 126 zstream.opaque = Z_NULL;
125 127
126// printf("Initialising\n"); 128// printf("Initialising\n");
127 129
128 inflateInit(&zstream); 130 inflateInit(&zstream);
129 131
130 int ret = inflate(&zstream, Z_SYNC_FLUSH); 132 int ret = inflate(&zstream, Z_SYNC_FLUSH);
131// printf("Inflate : %d\n", ret); 133// printf("Inflate : %d\n", ret);
132 bufferpos = 0; 134 bufferpos = 0;
133 bufferrec = 1; 135 bufferrec = 1;
134 currentpos = 0; 136 currentpos = 0;
135 buffercontent = buffersize - zstream.avail_out; 137 buffercontent = buffersize - zstream.avail_out;
136 //printf("buffercontent:%u\n", buffercontent); 138 //printf("buffercontent:%u\n", buffercontent);
137} 139}
138 140
139CList<Bkmk>* ztxt::getbkmklist() 141CList<Bkmk>* ztxt::getbkmklist()
140{ 142{
141 UInt16 recno = ntohs(hdr0.bookmarkRecord); 143 UInt16 recno = ntohs(hdr0.bookmarkRecord);
142 144
143// printf("Bookmarks - record %d contains %d\n", recno, ntohs(hdr0.numBookmarks)); 145// printf("Bookmarks - record %d contains %d\n", recno, ntohs(hdr0.numBookmarks));
144 146
145 if (recno == 0) return NULL; 147 if (recno == 0) return NULL;
146 148
147 CList<Bkmk>* t = new CList<Bkmk>; 149 CList<Bkmk>* t = new CList<Bkmk>;
148 size_t cur = ftell(fin); 150 size_t cur = ftell(fin);
149 gotorecordnumber(recno); 151 gotorecordnumber(recno);
150 for (int i = 0; i < ntohs(hdr0.numBookmarks); i++) 152 for (int i = 0; i < ntohs(hdr0.numBookmarks); i++)
151 { 153 {
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;
159} 161}
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
@@ -1,103 +1,105 @@
1#ifndef __ztxt_h 1#ifndef __ztxt_h
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
10 * 9 *
11 * $Id$ 10 * $Id$
12 * 11 *
13 */ 12 */
14 13
15#ifndef _WEASEL_COMMON_H_ 14#ifndef _WEASEL_COMMON_H_
16#define _WEASEL_COMMON_H_ 1 15#define _WEASEL_COMMON_H_ 1
17 16
18 17
19/* Padding is no good */ 18/* Padding is no good */
20#if defined(__GNUC__) && defined(__UNIX__) 19#if defined(__GNUC__) && defined(__UNIX__)
21# pragma pack(2) 20# pragma pack(2)
22#endif 21#endif
23 22
24/* The default creator is Weasel Reader 'GPlm' */ 23/* The default creator is Weasel Reader 'GPlm' */
25#define GPLM_CREATOR_ID "GPlm" 24#define GPLM_CREATOR_ID "GPlm"
26/* Databases of type 'zTXT' */ 25/* Databases of type 'zTXT' */
27#define ZTXT_TYPE_ID "zTXT" 26#define ZTXT_TYPE_ID "zTXT"
28/* Size of one database record */ 27/* Size of one database record */
29#define RECORD_SIZE 8192 28#define RECORD_SIZE 8192
30/* Allow largest WBIT size for data. Lower with command line options 29/* Allow largest WBIT size for data. Lower with command line options
31 in makeztxt */ 30 in makeztxt */
32#define MAXWBITS 15 31#define MAXWBITS 15
33/* Max length for a bookmark/annotation title */ 32/* Max length for a bookmark/annotation title */
34#define MAX_BMRK_LENGTH 20 33#define MAX_BMRK_LENGTH 20
35 34
36 35
37/***************************************************** 36/*****************************************************
38 * This is the zTXT document header (record #0) * 37 * This is the zTXT document header (record #0) *
39 * ----zTXT version 1.42---- * 38 * ----zTXT version 1.42---- *
40 *****************************************************/ 39 *****************************************************/
41typedef struct zTXT_record0Type { 40typedef struct zTXT_record0Type {
42 UInt16 version; /* zTXT format version */ 41 UInt16 version; /* zTXT format version */
43 UInt16 numRecords; /* Number of data (TEXT) records */ 42 UInt16 numRecords; /* Number of data (TEXT) records */
44 UInt32 size; /* Size in bytes of uncomp. data */ 43 UInt32 size; /* Size in bytes of uncomp. data */
45 UInt16 recordSize; /* Size of a single data record */ 44 UInt16 recordSize; /* Size of a single data record */
46 UInt16 numBookmarks; /* Number of bookmarks in DB */ 45 UInt16 numBookmarks; /* Number of bookmarks in DB */
47 UInt16 bookmarkRecord; /* Record containing bookmarks */ 46 UInt16 bookmarkRecord; /* Record containing bookmarks */
48 UInt16 numAnnotations; /* Number of annotation records */ 47 UInt16 numAnnotations; /* Number of annotation records */
49 UInt16 annotationRecord; /* Record # of annotation index */ 48 UInt16 annotationRecord; /* Record # of annotation index */
50 UInt8 randomAccess; /* 1 if compressed w/Z_FULL_FLUSH */ 49 UInt8 randomAccess; /* 1 if compressed w/Z_FULL_FLUSH */
51 UInt8 padding[0x20 - 19]; /* Pad to a size of 0x20 bytes */ 50 UInt8 padding[0x20 - 19]; /* Pad to a size of 0x20 bytes */
52} zTXT_record0; 51} zTXT_record0;
53 52
54struct zTXTbkmk 53struct zTXTbkmk
55{ 54{
56 UInt32 offset; 55 UInt32 offset;
57 tchar title[MAX_BMRK_LENGTH]; 56 tchar title[MAX_BMRK_LENGTH];
58}; 57};
59 58
60#endif 59#endif
61 60
62 61
63const UInt32 ZTXT_ID = 0x5458547a; 62const UInt32 ZTXT_ID = 0x5458547a;
64 63
65class ztxt : public CExpander, Cpdb 64class ztxt : public CExpander, Cpdb
66{ 65{
67 bool bInit; 66 bool bInit;
68 UInt32 buffersize; 67 UInt32 buffersize;
69 UInt32 buffercontent; 68 UInt32 buffercontent;
70 UInt8* expandedtextbuffer; 69 UInt8* expandedtextbuffer;
71 UInt8* compressedtextbuffer; 70 UInt8* compressedtextbuffer;
72 z_stream zstream; 71 z_stream zstream;
73 size_t bufferpos; 72 size_t bufferpos;
74 UInt16 bufferrec; 73 UInt16 bufferrec;
75 zTXT_record0 hdr0; 74 zTXT_record0 hdr0;
76 size_t currentpos; 75 size_t currentpos;
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