Diffstat (limited to 'noncore/apps/opie-reader/BuffDoc.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/BuffDoc.cpp | 128 |
1 files changed, 94 insertions, 34 deletions
diff --git a/noncore/apps/opie-reader/BuffDoc.cpp b/noncore/apps/opie-reader/BuffDoc.cpp index 1123960..2402904 100644 --- a/noncore/apps/opie-reader/BuffDoc.cpp +++ b/noncore/apps/opie-reader/BuffDoc.cpp | |||
@@ -1,47 +1,63 @@ | |||
1 | #include "name.h" | 1 | #include "names.h" |
2 | |||
3 | #define NEWLINEBREAK | ||
2 | 4 | ||
3 | #include "BuffDoc.h" | 5 | #include "BuffDoc.h" |
4 | //#include <FL/fl_draw.h> | 6 | //#include <FL/fl_draw.h> |
5 | #include "config.h" | 7 | #include "config.h" |
6 | #include "CDrawBuffer.h" | 8 | #include "CDrawBuffer.h" |
7 | #include "plucker.h" | 9 | #include "plucker.h" |
10 | #include "usenef.h" | ||
11 | #ifdef USENEF | ||
12 | #include "nef.h" | ||
13 | #include "arrierego.h" | ||
14 | #endif | ||
8 | 15 | ||
9 | 16 | linkType BuffDoc::hyperlink(unsigned int n, QString& wrd) | |
10 | bool BuffDoc::hyperlink(unsigned int n) | ||
11 | { | 17 | { |
12 | bool bRet = false; | 18 | linkType bRet = eNone; |
13 | lastword.empty(); | ||
14 | lastsizes[0] = laststartline = n; | ||
15 | lastispara = false; | ||
16 | if (exp != NULL) | 19 | if (exp != NULL) |
17 | { | 20 | { |
18 | bRet = exp->hyperlink(n); | 21 | bRet = exp->hyperlink(n, wrd); |
19 | lastsizes[0] = laststartline = exp->locate(); | 22 | if (bRet == eLink) |
23 | { | ||
24 | lastword.empty(); | ||
25 | lastsizes[0] = laststartline = n; | ||
26 | #ifdef NEWLINEBREAK | ||
27 | lastispara = true; | ||
28 | #else | ||
29 | lastispara = false; | ||
30 | #endif | ||
31 | lastsizes[0] = laststartline = exp->locate(); | ||
32 | } | ||
20 | } | 33 | } |
21 | return bRet; | 34 | return bRet; |
22 | } | 35 | } |
23 | 36 | ||
24 | void BuffDoc::locate(unsigned int n) | 37 | void BuffDoc::locate(unsigned int n) |
25 | { | 38 | { |
26 | // qDebug("BuffDoc:locating:%u",n); | 39 | // //qDebug("BuffDoc:locating:%u",n); |
27 | lastword.empty(); | 40 | lastword.empty(); |
28 | lastsizes[0] = laststartline = n; | 41 | lastsizes[0] = laststartline = n; |
29 | lastispara = false; | 42 | #ifdef NEWLINEBREAK |
43 | lastispara = true; | ||
44 | #else | ||
45 | lastispara = false; | ||
46 | #endif | ||
30 | // tchar linebuf[1024]; | 47 | // tchar linebuf[1024]; |
31 | if (exp != NULL) exp->locate(n); | 48 | if (exp != NULL) exp->locate(n); |
32 | // qDebug("BuffDoc:Located"); | 49 | // //qDebug("BuffDoc:Located"); |
33 | } | 50 | } |
34 | 51 | ||
35 | #define NEWLINEBREAK | ||
36 | #ifdef NEWLINEBREAK | 52 | #ifdef NEWLINEBREAK |
37 | bool BuffDoc::getline(CDrawBuffer* buff, int wth) | 53 | bool BuffDoc::getline(CDrawBuffer* buff, int wth, unsigned char _border) |
38 | { | 54 | { |
39 | bool moreleft = true; | 55 | bool moreleft = true; |
40 | bool margindone = false; | 56 | bool margindone = false; |
41 | int w = wth-2*BORDER; | 57 | int w = wth-2*_border; |
42 | tchar ch = 32; | 58 | tchar ch = 32; |
43 | CStyle cs; | 59 | CStyle cs; |
44 | buff->empty(); | 60 | buff->empty(); |
45 | if (exp == NULL) | 61 | if (exp == NULL) |
46 | { | 62 | { |
47 | buff->empty(); | 63 | buff->empty(); |
@@ -57,53 +73,58 @@ bool BuffDoc::getline(CDrawBuffer* buff, int wth) | |||
57 | margindone = true; | 73 | margindone = true; |
58 | len = lastword.length(); | 74 | len = lastword.length(); |
59 | } | 75 | } |
60 | else buff->empty(); | 76 | else buff->empty(); |
61 | lastword.empty(); | 77 | lastword.empty(); |
62 | unsigned int slen = buff->width(len); | 78 | unsigned int slen = buff->width(len); |
63 | lastispara = false; | 79 | if (lastispara) buff->setstartpara(); |
64 | while (1) | 80 | while (1) |
65 | { | 81 | { |
66 | lastsizes[len] = exp->locate(); | 82 | lastsizes[len] = exp->locate(); |
67 | getch(ch, cs); | 83 | getch(ch, cs); |
84 | if (ch == 10 && len == 0 && !lastispara) | ||
85 | { | ||
86 | lastsizes[len] = exp->locate(); | ||
87 | getch(ch, cs); | ||
88 | } | ||
68 | if (ch == UEOF) | 89 | if (ch == UEOF) |
69 | { | 90 | { |
70 | lastword.empty(); | ||
71 | if (len == 0) | 91 | if (len == 0) |
72 | { | 92 | { |
73 | buff->setEof(); | 93 | buff->setEof(); |
74 | moreleft = false; | 94 | moreleft = false; |
75 | } | 95 | } |
76 | laststartline = exp->locate(); | 96 | laststartline = exp->locate(); |
77 | break; | 97 | break; |
78 | } | 98 | } |
79 | if (ch == 10) | 99 | if (ch == 10) |
80 | { | 100 | { |
81 | lastword.empty(); | 101 | buff->setendpara(); |
82 | lastispara = true; | 102 | lastispara = true; |
83 | laststartline = exp->locate(); | 103 | laststartline = exp->locate(); |
84 | break; | 104 | break; |
85 | } | 105 | } |
106 | lastispara = false; | ||
86 | buff->addch(ch, cs); | 107 | buff->addch(ch, cs); |
87 | len++; | 108 | len++; |
88 | if (!margindone) | 109 | if (!margindone) |
89 | { | 110 | { |
90 | w -= buff->leftMargin() + buff->rightMargin(); | 111 | w -= buff->leftMargin() + buff->rightMargin(); |
91 | margindone = true; | 112 | margindone = true; |
92 | } | 113 | } |
93 | if ((slen = buff->width(len)) > w) | 114 | if ((slen = buff->width(len)) > w) |
94 | { | 115 | { |
95 | if (ch == ' ' || len == 1) | 116 | if (ch == ' ' || len == 1) |
96 | { | 117 | { |
97 | lastword.empty(); | 118 | if (ch == ' ') buff->truncate(len-1); |
98 | laststartline = exp->locate(); | 119 | laststartline = exp->locate(); |
99 | break; | 120 | break; |
100 | } | 121 | } |
101 | else // should do a backward search for spaces, first. | 122 | else // should do a backward search for spaces, first. |
102 | { | 123 | { |
103 | for (int i = len-1; i > 0; i--) | 124 | for (int i = len-2; i > 0; i--) |
104 | { | 125 | { |
105 | if ((*buff)[i] == ' ') | 126 | if ((*buff)[i] == ' ') |
106 | { | 127 | { |
107 | (*buff)[len] = 0; | 128 | (*buff)[len] = 0; |
108 | lastword.setright(*buff, i+1); | 129 | lastword.setright(*buff, i+1); |
109 | buff->truncate(i); | 130 | buff->truncate(i); |
@@ -113,14 +134,29 @@ bool BuffDoc::getline(CDrawBuffer* buff, int wth) | |||
113 | for (int j = 0; j < lastword.length(); j++) | 134 | for (int j = 0; j < lastword.length(); j++) |
114 | { | 135 | { |
115 | lastsizes[j] = lastsizes[j+i+1]; | 136 | lastsizes[j] = lastsizes[j+i+1]; |
116 | } | 137 | } |
117 | return true; | 138 | return true; |
118 | } | 139 | } |
140 | if ((*buff)[i] == '-' && !(((*buff)[i-1] == '-') || ((*buff)[i+1] == '-'))) | ||
141 | { | ||
142 | (*buff)[len] = 0; | ||
143 | lastword.setright(*buff, i+1); | ||
144 | buff->truncate(i+1); | ||
145 | (*buff)[i+1] = '\0'; | ||
146 | laststartline = lastsizes[i+1]; | ||
147 | buff->resize(); | ||
148 | for (int j = 0; j < lastword.length(); j++) | ||
149 | { | ||
150 | lastsizes[j] = lastsizes[j+i+1]; | ||
151 | } | ||
152 | return true; | ||
153 | } | ||
119 | } | 154 | } |
120 | laststartline = lastsizes[len-1]; | 155 | laststartline = lastsizes[len-1]; |
156 | (*buff)[len] = 0; | ||
121 | lastword.setright(*buff, len - 1); | 157 | lastword.setright(*buff, len - 1); |
122 | buff->truncate(len-1); | 158 | buff->truncate(len-1); |
123 | buff->addch('-', cs); | 159 | buff->addch('-', cs); |
124 | for (int j = 0; j < lastword.length(); j++) | 160 | for (int j = 0; j < lastword.length(); j++) |
125 | { | 161 | { |
126 | lastsizes[j] = lastsizes[j+len]; | 162 | lastsizes[j] = lastsizes[j+len]; |
@@ -131,16 +167,16 @@ bool BuffDoc::getline(CDrawBuffer* buff, int wth) | |||
131 | } | 167 | } |
132 | (*buff)[len] = '\0'; | 168 | (*buff)[len] = '\0'; |
133 | buff->resize(); | 169 | buff->resize(); |
134 | return moreleft; | 170 | return moreleft; |
135 | } | 171 | } |
136 | #else | 172 | #else |
137 | bool BuffDoc::getline(CDrawBuffer* buff, int wth) | 173 | bool BuffDoc::getline(CDrawBuffer* buff, int wth, unsigned char _border) |
138 | { | 174 | { |
139 | bool margindone = false; | 175 | bool margindone = false; |
140 | int w = wth-2*BORDER; | 176 | int w = wth-2*_border; |
141 | tchar ch = 32; | 177 | tchar ch = 32; |
142 | CStyle cs; | 178 | CStyle cs; |
143 | buff->empty(); | 179 | buff->empty(); |
144 | if (exp == NULL) | 180 | if (exp == NULL) |
145 | { | 181 | { |
146 | //(*buff)[0] = '\0'; | 182 | //(*buff)[0] = '\0'; |
@@ -153,13 +189,13 @@ bool BuffDoc::getline(CDrawBuffer* buff, int wth) | |||
153 | *buff = lastword; | 189 | *buff = lastword; |
154 | cs = lastword.laststyle(); | 190 | cs = lastword.laststyle(); |
155 | w -= buff->leftMargin() + buff->rightMargin(); | 191 | w -= buff->leftMargin() + buff->rightMargin(); |
156 | margindone = true; | 192 | margindone = true; |
157 | } | 193 | } |
158 | else buff->empty(); | 194 | else buff->empty(); |
159 | // qDebug("Buff:%s Lastword:%s", (const char*)toQString(buff->data()), (const char*)toQString(lastword.data())); | 195 | // //qDebug("Buff:%s Lastword:%s", (const char*)toQString(buff->data()), (const char*)toQString(lastword.data())); |
160 | lastcheck = len = buff->length(); | 196 | lastcheck = len = buff->length(); |
161 | unsigned int slen = buff->width(len); | 197 | unsigned int slen = buff->width(len); |
162 | if (slen > w) | 198 | if (slen > w) |
163 | { | 199 | { |
164 | for ( ; len > 1; len--) | 200 | for ( ; len > 1; len--) |
165 | { | 201 | { |
@@ -228,13 +264,13 @@ bool BuffDoc::getline(CDrawBuffer* buff, int wth) | |||
228 | break; | 264 | break; |
229 | } | 265 | } |
230 | lastispara = (ch == '\012'); | 266 | lastispara = (ch == '\012'); |
231 | } | 267 | } |
232 | (*buff)[len] = '\0'; | 268 | (*buff)[len] = '\0'; |
233 | // lastword = buff->data()+lastcheck; | 269 | // lastword = buff->data()+lastcheck; |
234 | #ifdef WINDOWS | 270 | #ifdef _WINDOWS |
235 | lastword.setright(*buff, (lastcheck > 0) ? lastcheck : 1); | 271 | lastword.setright(*buff, (lastcheck > 0) ? lastcheck : 1); |
236 | { | 272 | { |
237 | int i; | 273 | int i; |
238 | for (i = 0; i < lastword.length(); i++) lastsizes[i] = allsizes[i+lastcheck]; | 274 | for (i = 0; i < lastword.length(); i++) lastsizes[i] = allsizes[i+lastcheck]; |
239 | } | 275 | } |
240 | #else | 276 | #else |
@@ -261,24 +297,24 @@ bool BuffDoc::getline(CDrawBuffer* buff, int wth) | |||
261 | return false; | 297 | return false; |
262 | } | 298 | } |
263 | return true; | 299 | return true; |
264 | } | 300 | } |
265 | #endif | 301 | #endif |
266 | 302 | ||
267 | bool BuffDoc::getline(CDrawBuffer* buff, int wth, int cw) | 303 | bool BuffDoc::getline(CDrawBuffer* buff, int wth, int cw, unsigned char _border) |
268 | { | 304 | { |
269 | int w = wth-2*BORDER; | 305 | int w = wth-2*_border; |
270 | buff->empty(); | 306 | buff->empty(); |
271 | if (exp == NULL) | 307 | if (exp == NULL) |
272 | { | 308 | { |
273 | return false; | 309 | return false; |
274 | } | 310 | } |
275 | tchar ch; | 311 | tchar ch; |
276 | CStyle cs; | 312 | CStyle cs; |
277 | int i = 0; | 313 | int i = 1; |
278 | while (i*cw < w) | 314 | while (i*cw < w-buff->offset(w,0)) |
279 | { | 315 | { |
280 | getch(ch, cs); | 316 | getch(ch, cs); |
281 | if (ch == '\12' || ch == UEOF) break; | 317 | if (ch == '\12' || ch == UEOF) break; |
282 | buff->addch(ch,cs); | 318 | buff->addch(ch,cs); |
283 | i++; | 319 | i++; |
284 | } | 320 | } |
@@ -287,18 +323,22 @@ bool BuffDoc::getline(CDrawBuffer* buff, int wth, int cw) | |||
287 | buff->resize(); | 323 | buff->resize(); |
288 | return (ch != UEOF); | 324 | return (ch != UEOF); |
289 | } | 325 | } |
290 | 326 | ||
291 | int BuffDoc::openfile(QWidget* _parent, const char *src) | 327 | int BuffDoc::openfile(QWidget* _parent, const char *src) |
292 | { | 328 | { |
293 | // qDebug("BuffDoc:Openfile:%s", src); | 329 | // //qDebug("BuffDoc:Openfile:%s", src); |
294 | // qDebug("Trying aportis %x",exp); | 330 | // //qDebug("Trying aportis %x",exp); |
295 | if (exp != NULL) delete exp; | 331 | if (exp != NULL) delete exp; |
296 | lastword.empty(); | 332 | lastword.empty(); |
297 | lastsizes[0] = laststartline = 0; | 333 | lastsizes[0] = laststartline = 0; |
334 | #ifdef NEWLINEBREAK | ||
335 | lastispara = true; | ||
336 | #else | ||
298 | lastispara = false; | 337 | lastispara = false; |
338 | #endif | ||
299 | /* | 339 | /* |
300 | exp = new Text; | 340 | exp = new Text; |
301 | int ret = exp->openfile(src); | 341 | int ret = exp->openfile(src); |
302 | */ | 342 | */ |
303 | 343 | ||
304 | exp = new Aportis; | 344 | exp = new Aportis; |
@@ -313,44 +353,64 @@ int BuffDoc::openfile(QWidget* _parent, const char *src) | |||
313 | { | 353 | { |
314 | 354 | ||
315 | delete exp; | 355 | delete exp; |
316 | exp = new ztxt; | 356 | exp = new ztxt; |
317 | ret = exp->openfile(src); | 357 | ret = exp->openfile(src); |
318 | } | 358 | } |
359 | #ifdef USENEF | ||
360 | if (ret != 0) | ||
361 | { | ||
362 | |||
363 | delete exp; | ||
364 | exp = new CArriere; | ||
365 | ret = exp->openfile(src); | ||
366 | } | ||
367 | if (ret != 0) | ||
368 | { | ||
369 | |||
370 | delete exp; | ||
371 | exp = new CNEF; | ||
372 | ret = exp->openfile(src); | ||
373 | } | ||
374 | #endif | ||
319 | if (ret != 0) | 375 | if (ret != 0) |
320 | { | 376 | { |
321 | 377 | ||
322 | delete exp; | 378 | delete exp; |
323 | exp = new CPlucker; | 379 | exp = new CPlucker; |
324 | ret = exp->openfile(src); | 380 | ret = exp->openfile(src); |
325 | } | 381 | } |
326 | if (ret != 0) | 382 | if (ret != 0) |
327 | { | 383 | { |
328 | delete exp; | 384 | delete exp; |
329 | qDebug("Trying ppms"); | 385 | //qDebug("Trying ppms"); |
330 | exp = new ppm_expander; | 386 | exp = new ppm_expander; |
331 | ret = exp->openfile(src); | 387 | ret = exp->openfile(src); |
332 | } | 388 | } |
333 | if (ret != 0) | 389 | if (ret != 0) |
334 | { | 390 | { |
335 | delete exp; | 391 | delete exp; |
336 | exp = new Text; | 392 | exp = new Text; |
337 | // qDebug("Trying text"); | 393 | // //qDebug("Trying text"); |
338 | ret = exp->openfile(src); | 394 | ret = exp->openfile(src); |
339 | } | 395 | } |
340 | 396 | ||
341 | if (ret != 0) | 397 | if (ret != 0) |
342 | { | 398 | { |
343 | delete exp; | 399 | delete exp; |
344 | QMessageBox::information(_parent, PROGNAME, "Unknown file compression type","Try another file"); | 400 | QMessageBox::information(_parent, PROGNAME, "Unknown file compression type","Try another file"); |
345 | return ret; | 401 | return ret; |
346 | } | 402 | } |
347 | // qDebug("Doing final open:%x:%x",exp,filt); | 403 | // //qDebug("Doing final open:%x:%x",exp,filt); |
348 | 404 | ||
349 | lastword.empty(); | 405 | lastword.empty(); |
350 | lastsizes[0] = laststartline = 0; | 406 | lastsizes[0] = laststartline = 0; |
407 | #ifdef NEWLINEBREAK | ||
408 | lastispara = true; | ||
409 | #else | ||
351 | lastispara = false; | 410 | lastispara = false; |
411 | #endif | ||
352 | exp->locate(0); | 412 | exp->locate(0); |
353 | filt->setsource(exp); | 413 | filt->setsource(exp); |
354 | // qDebug("BuffDoc:file opened"); | 414 | // //qDebug("BuffDoc:file opened"); |
355 | return 0; | 415 | return 0; |
356 | } | 416 | } |