summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/BuffDoc.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-reader/BuffDoc.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-reader/BuffDoc.cpp122
1 files changed, 91 insertions, 31 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,3 +1,5 @@
1#include "name.h" 1#include "names.h"
2
3#define NEWLINEBREAK
2 4
3#include "BuffDoc.h" 5#include "BuffDoc.h"
@@ -6,17 +8,28 @@
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 16linkType BuffDoc::hyperlink(unsigned int n, QString& wrd)
10bool BuffDoc::hyperlink(unsigned int n) 17{
18 linkType bRet = eNone;
19 if (exp != NULL)
20 {
21 bRet = exp->hyperlink(n, wrd);
22 if (bRet == eLink)
11{ 23{
12 bool bRet = false;
13 lastword.empty(); 24 lastword.empty();
14 lastsizes[0] = laststartline = n; 25 lastsizes[0] = laststartline = n;
26#ifdef NEWLINEBREAK
27 lastispara = true;
28#else
15 lastispara = false; 29 lastispara = false;
16 if (exp != NULL) 30#endif
17 {
18 bRet = exp->hyperlink(n);
19 lastsizes[0] = laststartline = exp->locate(); 31 lastsizes[0] = laststartline = exp->locate();
20 } 32 }
33 }
21 return bRet; 34 return bRet;
22} 35}
@@ -24,20 +37,23 @@ bool BuffDoc::hyperlink(unsigned int n)
24void BuffDoc::locate(unsigned int n) 37void 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;
42#ifdef NEWLINEBREAK
43 lastispara = true;
44#else
29 lastispara = false; 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
37bool BuffDoc::getline(CDrawBuffer* buff, int wth) 53bool 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;
@@ -61,12 +77,16 @@ bool BuffDoc::getline(CDrawBuffer* buff, int wth)
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 {
@@ -79,9 +99,10 @@ bool BuffDoc::getline(CDrawBuffer* buff, int wth)
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++;
@@ -95,5 +116,5 @@ bool BuffDoc::getline(CDrawBuffer* buff, int wth)
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;
@@ -101,5 +122,5 @@ bool BuffDoc::getline(CDrawBuffer* buff, int wth)
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] == ' ')
@@ -117,6 +138,21 @@ bool BuffDoc::getline(CDrawBuffer* buff, int wth)
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);
@@ -135,8 +171,8 @@ bool BuffDoc::getline(CDrawBuffer* buff, int wth)
135} 171}
136#else 172#else
137bool BuffDoc::getline(CDrawBuffer* buff, int wth) 173bool 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;
@@ -157,5 +193,5 @@ bool BuffDoc::getline(CDrawBuffer* buff, int wth)
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);
@@ -232,5 +268,5 @@ bool BuffDoc::getline(CDrawBuffer* buff, int wth)
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 {
@@ -265,7 +301,7 @@ bool BuffDoc::getline(CDrawBuffer* buff, int wth)
265#endif 301#endif
266 302
267bool BuffDoc::getline(CDrawBuffer* buff, int wth, int cw) 303bool 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)
@@ -275,6 +311,6 @@ bool BuffDoc::getline(CDrawBuffer* buff, int wth, int cw)
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);
@@ -291,10 +327,14 @@ bool BuffDoc::getline(CDrawBuffer* buff, int wth, int cw)
291int BuffDoc::openfile(QWidget* _parent, const char *src) 327int 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;
@@ -317,4 +357,20 @@ int BuffDoc::openfile(QWidget* _parent, const char *src)
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 {
@@ -327,5 +383,5 @@ int BuffDoc::openfile(QWidget* _parent, const char *src)
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);
@@ -335,5 +391,5 @@ int BuffDoc::openfile(QWidget* _parent, const char *src)
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 }
@@ -345,12 +401,16 @@ int BuffDoc::openfile(QWidget* _parent, const char *src)
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}