summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/BuffDoc.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-reader/BuffDoc.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-reader/BuffDoc.cpp248
1 files changed, 190 insertions, 58 deletions
diff --git a/noncore/apps/opie-reader/BuffDoc.cpp b/noncore/apps/opie-reader/BuffDoc.cpp
index d4541ea..1123960 100644
--- a/noncore/apps/opie-reader/BuffDoc.cpp
+++ b/noncore/apps/opie-reader/BuffDoc.cpp
@@ -1 +1,3 @@
1#include "name.h"
2
1#include "BuffDoc.h" 3#include "BuffDoc.h"
@@ -15,4 +17,4 @@ bool BuffDoc::hyperlink(unsigned int n)
15 { 17 {
16 bRet = exp->hyperlink(n); 18 bRet = exp->hyperlink(n);
17 lastsizes[0] = laststartline = exp->locate(); 19 lastsizes[0] = laststartline = exp->locate();
18 } 20 }
@@ -32,4 +34,9 @@ void BuffDoc::locate(unsigned int n)
32 34
33bool BuffDoc::getline(CDrawBuffer* buff, int w) 35#define NEWLINEBREAK
36#ifdef NEWLINEBREAK
37bool BuffDoc::getline(CDrawBuffer* buff, int wth)
34{ 38{
39 bool moreleft = true;
40 bool margindone = false;
41 int w = wth-2*BORDER;
35 tchar ch = 32; 42 tchar ch = 32;
@@ -39,5 +46,104 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w)
39 { 46 {
40// (*buff)[0] = '\0'; 47 buff->empty();
41 buff->empty(); 48 buff->setEof();
42 return false; 49 return false;
50 }
51 int len = 0;
52 if (lastword.length() > 0)
53 {
54 *buff = lastword;
55 cs = lastword.laststyle();
56 w -= buff->leftMargin() + buff->rightMargin();
57 margindone = true;
58 len = lastword.length();
59 }
60 else buff->empty();
61 lastword.empty();
62 unsigned int slen = buff->width(len);
63 lastispara = false;
64 while (1)
65 {
66 lastsizes[len] = exp->locate();
67 getch(ch, cs);
68 if (ch == UEOF)
69 {
70 lastword.empty();
71 if (len == 0)
72 {
73 buff->setEof();
74 moreleft = false;
75 }
76 laststartline = exp->locate();
77 break;
78 }
79 if (ch == 10)
80 {
81 lastword.empty();
82 lastispara = true;
83 laststartline = exp->locate();
84 break;
85 }
86 buff->addch(ch, cs);
87 len++;
88 if (!margindone)
89 {
90 w -= buff->leftMargin() + buff->rightMargin();
91 margindone = true;
92 }
93 if ((slen = buff->width(len)) > w)
94 {
95 if (ch == ' ' || len == 1)
96 {
97 lastword.empty();
98 laststartline = exp->locate();
99 break;
100 }
101 else // should do a backward search for spaces, first.
102 {
103 for (int i = len-1; i > 0; i--)
104 {
105 if ((*buff)[i] == ' ')
106 {
107 (*buff)[len] = 0;
108 lastword.setright(*buff, i+1);
109 buff->truncate(i);
110 (*buff)[i] = '\0';
111 laststartline = lastsizes[i+1];
112 buff->resize();
113 for (int j = 0; j < lastword.length(); j++)
114 {
115 lastsizes[j] = lastsizes[j+i+1];
116 }
117 return true;
118 }
119 }
120 laststartline = lastsizes[len-1];
121 lastword.setright(*buff, len - 1);
122 buff->truncate(len-1);
123 buff->addch('-', cs);
124 for (int j = 0; j < lastword.length(); j++)
125 {
126 lastsizes[j] = lastsizes[j+len];
127 }
128 break;
129 }
130 }
131 }
132 (*buff)[len] = '\0';
133 buff->resize();
134 return moreleft;
135}
136#else
137bool BuffDoc::getline(CDrawBuffer* buff, int wth)
138{
139 bool margindone = false;
140 int w = wth-2*BORDER;
141 tchar ch = 32;
142 CStyle cs;
143 buff->empty();
144 if (exp == NULL)
145 {
146 //(*buff)[0] = '\0';
147 buff->empty();
148 return false;
43 } 149 }
@@ -48,2 +154,4 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w)
48 cs = lastword.laststyle(); 154 cs = lastword.laststyle();
155 w -= buff->leftMargin() + buff->rightMargin();
156 margindone = true;
49 } 157 }
@@ -55,14 +163,24 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w)
55 { 163 {
56 for ( ; len > 0; len--) 164 for ( ; len > 1; len--)
57 { 165 {
58 if (buff->width(len) < w) break; 166 if (buff->width(len) < w) break;
59 } 167 }
60// lastword = buff->data() + len - 1; 168// lastword = buff->data() + len - 1;
61 laststartline = lastsizes[len-1]; 169 laststartline = lastsizes[len-1];
62 lastword.setright(*buff, len - 1);
63 for (int i = 0; i < buff->length(); i++) lastsizes[i] = lastsizes[i+len-1]; 170 for (int i = 0; i < buff->length(); i++) lastsizes[i] = lastsizes[i+len-1];
64// (*buff)[len-1] = '-'; 171// (*buff)[len-1] = '-';
65 buff->truncate(len-1); 172 if (len > 2)
66 buff->addch('-', cs); 173 {
67 (*buff)[len] = '\0'; 174 lastword.setright(*buff, len - 1);
175 buff->truncate(len-1);
176 buff->addch('-', cs);
177 (*buff)[len] = '\0';
178 }
179
180 else
181 {
182 lastword.empty();
183 (*buff)[len] = '\0';
184 }
185 buff->resize();
68 return true; 186 return true;
@@ -79,2 +197,3 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w)
79 laststartline = exp->locate(); 197 laststartline = exp->locate();
198 buff->resize();
80 return true; 199 return true;
@@ -90,6 +209,6 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w)
90 { 209 {
91 len++; 210 len++;
92 buff->addch(ch,cs); 211 buff->addch(ch,cs);
93 allsizes[len] = exp->locate(); 212 allsizes[len] = exp->locate();
94 getch(ch, cs); 213 getch(ch, cs);
95 } 214 }
@@ -99,2 +218,7 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w)
99 buff->addch(' ', cs); 218 buff->addch(' ', cs);
219 if (!margindone)
220 {
221 w -= buff->leftMargin() + buff->rightMargin();
222 margindone = true;
223 }
100 allsizes[len] = exp->locate(); 224 allsizes[len] = exp->locate();
@@ -102,4 +226,4 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w)
102 { 226 {
103 lastcheck = len; 227 lastcheck = len;
104 break; 228 break;
105 } 229 }
@@ -109,4 +233,12 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w)
109// lastword = buff->data()+lastcheck; 233// lastword = buff->data()+lastcheck;
110 lastword.setright(*buff, lastcheck); 234#ifdef WINDOWS
235 lastword.setright(*buff, (lastcheck > 0) ? lastcheck : 1);
236 {
237 int i;
238 for (i = 0; i < lastword.length(); i++) lastsizes[i] = allsizes[i+lastcheck];
239 }
240#else
241 lastword.setright(*buff, (lastcheck > 0) ? lastcheck : 1);
111 for (int i = 0; i < lastword.length(); i++) lastsizes[i] = allsizes[i+lastcheck]; 242 for (int i = 0; i < lastword.length(); i++) lastsizes[i] = allsizes[i+lastcheck];
243#endif
112 if (lastcheck > 0) 244 if (lastcheck > 0)
@@ -124,7 +256,15 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w)
124// buff->frig(); 256// buff->frig();
125 return (ch != UEOF); 257 buff->resize();
258 if (ch == UEOF && buff->length() == 0)
259 {
260 buff->setEof();
261 return false;
262 }
263 return true;
126} 264}
265#endif
127 266
128bool BuffDoc::getline(CDrawBuffer* buff, int w, int cw) 267bool BuffDoc::getline(CDrawBuffer* buff, int wth, int cw)
129{ 268{
269 int w = wth-2*BORDER;
130 buff->empty(); 270 buff->empty();
@@ -132,3 +272,3 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w, int cw)
132 { 272 {
133 return false; 273 return false;
134 } 274 }
@@ -139,6 +279,6 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w, int cw)
139 { 279 {
140 getch(ch, cs); 280 getch(ch, cs);
141 if (ch == '\12' || ch == UEOF) break; 281 if (ch == '\12' || ch == UEOF) break;
142 buff->addch(ch,cs); 282 buff->addch(ch,cs);
143 i++; 283 i++;
144 } 284 }
@@ -146,2 +286,3 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w, int cw)
146 laststartline = exp->locate(); 286 laststartline = exp->locate();
287 buff->resize();
147 return (ch != UEOF); 288 return (ch != UEOF);
@@ -166,5 +307,5 @@ int BuffDoc::openfile(QWidget* _parent, const char *src)
166 { 307 {
167 delete exp; 308 delete exp;
168 exp = NULL; 309 exp = NULL;
169 return ret; 310 return ret;
170 } 311 }
@@ -173,5 +314,5 @@ int BuffDoc::openfile(QWidget* _parent, const char *src)
173 314
174 delete exp; 315 delete exp;
175 exp = new ztxt; 316 exp = new ztxt;
176 ret = exp->openfile(src); 317 ret = exp->openfile(src);
177 } 318 }
@@ -180,35 +321,26 @@ int BuffDoc::openfile(QWidget* _parent, const char *src)
180 321
181 delete exp; 322 delete exp;
182 exp = new CPlucker; 323 exp = new CPlucker;
183 ret = exp->openfile(src); 324 ret = exp->openfile(src);
184 } 325 }
185#ifndef SMALL
186 if (ret != 0) 326 if (ret != 0)
187 { 327 {
188 delete exp; 328 delete exp;
189 qDebug("Trying ppms"); 329 qDebug("Trying ppms");
190 exp = new ppm_expander; 330 exp = new ppm_expander;
191 ret = exp->openfile(src); 331 ret = exp->openfile(src);
192 } 332 }
193
194 if (ret != 0) 333 if (ret != 0)
195 { 334 {
196 delete exp; 335 delete exp;
197 exp = new Text; 336 exp = new Text;
198// qDebug("Trying text"); 337 // qDebug("Trying text");
199 ret = exp->openfile(src); 338 ret = exp->openfile(src);
200 } 339 }
201#else 340
202 if (ret != 0)
203 {
204 delete exp;
205 exp = new Text;
206 ret = exp->openfile(src);
207 }
208#endif
209 if (ret != 0) 341 if (ret != 0)
210 { 342 {
211 delete exp; 343 delete exp;
212 QMessageBox::information(_parent, "OpieReader", "Unknown file compression type","Try another file"); 344 QMessageBox::information(_parent, PROGNAME, "Unknown file compression type","Try another file");
213 return ret; 345 return ret;
214 } 346 }