author | llornkcor <llornkcor> | 2002-12-20 01:35:01 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-12-20 01:35:01 (UTC) |
commit | 876e1a4724a7bd75dc642e295de354241096e028 (patch) (unidiff) | |
tree | a37c5dcc9d78e04bb6b859ab89d8cf81e6745087 /noncore/apps/opie-reader/BuffDoc.cpp | |
parent | 5fd6636ba3d94b48dd543887316c47c5388a43c2 (diff) | |
download | opie-876e1a4724a7bd75dc642e295de354241096e028.zip opie-876e1a4724a7bd75dc642e295de354241096e028.tar.gz opie-876e1a4724a7bd75dc642e295de354241096e028.tar.bz2 |
update - sorry it took so long. hope this works correctly
Diffstat (limited to 'noncore/apps/opie-reader/BuffDoc.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/BuffDoc.cpp | 248 |
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,6 +1,8 @@ | |||
1 | #include "name.h" | ||
2 | |||
1 | #include "BuffDoc.h" | 3 | #include "BuffDoc.h" |
2 | //#include <FL/fl_draw.h> | 4 | //#include <FL/fl_draw.h> |
3 | #include "config.h" | 5 | #include "config.h" |
4 | #include "CDrawBuffer.h" | 6 | #include "CDrawBuffer.h" |
5 | #include "plucker.h" | 7 | #include "plucker.h" |
6 | 8 | ||
@@ -10,14 +12,14 @@ bool BuffDoc::hyperlink(unsigned int n) | |||
10 | bool bRet = false; | 12 | bool bRet = false; |
11 | lastword.empty(); | 13 | lastword.empty(); |
12 | lastsizes[0] = laststartline = n; | 14 | lastsizes[0] = laststartline = n; |
13 | lastispara = false; | 15 | lastispara = false; |
14 | if (exp != NULL) | 16 | if (exp != NULL) |
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 | } |
19 | return bRet; | 21 | return bRet; |
20 | } | 22 | } |
21 | 23 | ||
22 | void BuffDoc::locate(unsigned int n) | 24 | void BuffDoc::locate(unsigned int n) |
23 | { | 25 | { |
@@ -27,91 +29,221 @@ void BuffDoc::locate(unsigned int n) | |||
27 | lastispara = false; | 29 | lastispara = false; |
28 | // tchar linebuf[1024]; | 30 | // tchar linebuf[1024]; |
29 | if (exp != NULL) exp->locate(n); | 31 | if (exp != NULL) exp->locate(n); |
30 | // qDebug("BuffDoc:Located"); | 32 | // qDebug("BuffDoc:Located"); |
31 | } | 33 | } |
32 | 34 | ||
33 | bool BuffDoc::getline(CDrawBuffer* buff, int w) | 35 | #define NEWLINEBREAK |
36 | #ifdef NEWLINEBREAK | ||
37 | bool 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; |
36 | CStyle cs; | 43 | CStyle cs; |
37 | buff->empty(); | 44 | buff->empty(); |
38 | if (exp == NULL) | 45 | if (exp == NULL) |
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 | ||
137 | bool 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 | } |
44 | int len = 0, lastcheck = 0; | 150 | int len = 0, lastcheck = 0; |
45 | if (lastword.length() > 0) | 151 | if (lastword.length() > 0) |
46 | { | 152 | { |
47 | *buff = lastword; | 153 | *buff = lastword; |
48 | cs = lastword.laststyle(); | 154 | cs = lastword.laststyle(); |
155 | w -= buff->leftMargin() + buff->rightMargin(); | ||
156 | margindone = true; | ||
49 | } | 157 | } |
50 | else buff->empty(); | 158 | else buff->empty(); |
51 | // qDebug("Buff:%s Lastword:%s", (const char*)toQString(buff->data()), (const char*)toQString(lastword.data())); | 159 | // qDebug("Buff:%s Lastword:%s", (const char*)toQString(buff->data()), (const char*)toQString(lastword.data())); |
52 | lastcheck = len = buff->length(); | 160 | lastcheck = len = buff->length(); |
53 | unsigned int slen = buff->width(len); | 161 | unsigned int slen = buff->width(len); |
54 | if (slen > w) | 162 | if (slen > 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; |
69 | } | 187 | } |
70 | if (lastispara) | 188 | if (lastispara) |
71 | { | 189 | { |
72 | lastispara = false; | 190 | lastispara = false; |
73 | // lastword[0] = '\0'; | 191 | // lastword[0] = '\0'; |
74 | lastword.empty(); | 192 | lastword.empty(); |
75 | len = buff->length(); | 193 | len = buff->length(); |
76 | while (buff->width(len) > w) len--; | 194 | while (buff->width(len) > w) len--; |
77 | // (*buff)[len] = '\0'; | 195 | // (*buff)[len] = '\0'; |
78 | buff->truncate(len); | 196 | buff->truncate(len); |
79 | laststartline = exp->locate(); | 197 | laststartline = exp->locate(); |
198 | buff->resize(); | ||
80 | return true; | 199 | return true; |
81 | } | 200 | } |
82 | lastispara = false; | 201 | lastispara = false; |
83 | for (int i = 0; i < len; i++) allsizes[i] = lastsizes[i]; | 202 | for (int i = 0; i < len; i++) allsizes[i] = lastsizes[i]; |
84 | while (slen < w) | 203 | while (slen < w) |
85 | { | 204 | { |
86 | lastcheck = len; | 205 | lastcheck = len; |
87 | allsizes[len] = exp->locate(); | 206 | allsizes[len] = exp->locate(); |
88 | getch(ch, cs); | 207 | getch(ch, cs); |
89 | while (ch != ' ' && ch != '\012' && ch != UEOF && len < 128) | 208 | while (ch != ' ' && ch != '\012' && ch != UEOF && len < 128) |
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 | } |
96 | (*buff)[len] = 0; | 215 | (*buff)[len] = 0; |
97 | slen = buff->width(len); | 216 | slen = buff->width(len); |
98 | len++; | 217 | len++; |
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(); |
101 | if (slen < w && ch != ' ') | 225 | if (slen < w && ch != ' ') |
102 | { | 226 | { |
103 | lastcheck = len; | 227 | lastcheck = len; |
104 | break; | 228 | break; |
105 | } | 229 | } |
106 | lastispara = (ch == '\012'); | 230 | lastispara = (ch == '\012'); |
107 | } | 231 | } |
108 | (*buff)[len] = '\0'; | 232 | (*buff)[len] = '\0'; |
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) |
113 | { | 245 | { |
114 | laststartline = allsizes[lastcheck]; | 246 | laststartline = allsizes[lastcheck]; |
115 | // (*buff)[lastcheck-1] = '\0'; | 247 | // (*buff)[lastcheck-1] = '\0'; |
116 | buff->truncate(lastcheck-1); | 248 | buff->truncate(lastcheck-1); |
117 | } | 249 | } |
@@ -119,34 +251,43 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w) | |||
119 | { | 251 | { |
120 | laststartline = (lastcheck == len) ? exp->locate() : allsizes[lastcheck+1]; | 252 | laststartline = (lastcheck == len) ? exp->locate() : allsizes[lastcheck+1]; |
121 | // (*buff)[lastcheck] = '\0'; | 253 | // (*buff)[lastcheck] = '\0'; |
122 | buff->truncate(lastcheck); | 254 | buff->truncate(lastcheck); |
123 | } | 255 | } |
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 | ||
128 | bool BuffDoc::getline(CDrawBuffer* buff, int w, int cw) | 267 | bool BuffDoc::getline(CDrawBuffer* buff, int wth, int cw) |
129 | { | 268 | { |
269 | int w = wth-2*BORDER; | ||
130 | buff->empty(); | 270 | buff->empty(); |
131 | if (exp == NULL) | 271 | if (exp == NULL) |
132 | { | 272 | { |
133 | return false; | 273 | return false; |
134 | } | 274 | } |
135 | tchar ch; | 275 | tchar ch; |
136 | CStyle cs; | 276 | CStyle cs; |
137 | int i = 0; | 277 | int i = 0; |
138 | while (i*cw < w) | 278 | while (i*cw < w) |
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 | } |
145 | buff->truncate(i); | 285 | buff->truncate(i); |
146 | laststartline = exp->locate(); | 286 | laststartline = exp->locate(); |
287 | buff->resize(); | ||
147 | return (ch != UEOF); | 288 | return (ch != UEOF); |
148 | } | 289 | } |
149 | 290 | ||
150 | int BuffDoc::openfile(QWidget* _parent, const char *src) | 291 | int BuffDoc::openfile(QWidget* _parent, const char *src) |
151 | { | 292 | { |
152 | // qDebug("BuffDoc:Openfile:%s", src); | 293 | // qDebug("BuffDoc:Openfile:%s", src); |
@@ -161,59 +302,50 @@ int BuffDoc::openfile(QWidget* _parent, const char *src) | |||
161 | */ | 302 | */ |
162 | 303 | ||
163 | exp = new Aportis; | 304 | exp = new Aportis; |
164 | int ret = exp->openfile(src); | 305 | int ret = exp->openfile(src); |
165 | if (ret == -1) | 306 | if (ret == -1) |
166 | { | 307 | { |
167 | delete exp; | 308 | delete exp; |
168 | exp = NULL; | 309 | exp = NULL; |
169 | return ret; | 310 | return ret; |
170 | } | 311 | } |
171 | if (ret == -2) | 312 | if (ret == -2) |
172 | { | 313 | { |
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 | } |
178 | if (ret != 0) | 319 | if (ret != 0) |
179 | { | 320 | { |
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 | } |
215 | // qDebug("Doing final open:%x:%x",exp,filt); | 347 | // qDebug("Doing final open:%x:%x",exp,filt); |
216 | 348 | ||
217 | lastword.empty(); | 349 | lastword.empty(); |
218 | lastsizes[0] = laststartline = 0; | 350 | lastsizes[0] = laststartline = 0; |
219 | lastispara = false; | 351 | lastispara = false; |