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.cpp166
1 files changed, 149 insertions, 17 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,2 +1,4 @@
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>
@@ -31,6 +33,110 @@ void BuffDoc::locate(unsigned int n)
31} 33}
32 34
33bool BuffDoc::getline(CDrawBuffer* buff, int w) 35#define NEWLINEBREAK
36#ifdef NEWLINEBREAK
37bool BuffDoc::getline(CDrawBuffer* buff, int wth)
38{
39 bool moreleft = true;
40 bool margindone = false;
41 int w = wth-2*BORDER;
42 tchar ch = 32;
43 CStyle cs;
44 buff->empty();
45 if (exp == NULL)
46 {
47 buff->empty();
48 buff->setEof();
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++)
34{ 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;
35 tchar ch = 32; 141 tchar ch = 32;
36 CStyle cs; 142 CStyle cs;
@@ -47,4 +153,6 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w)
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();
@@ -54,5 +162,5 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w)
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;
@@ -60,10 +168,20 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w)
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] = '-';
172 if (len > 2)
173 {
174 lastword.setright(*buff, len - 1);
65 buff->truncate(len-1); 175 buff->truncate(len-1);
66 buff->addch('-', cs); 176 buff->addch('-', cs);
67 (*buff)[len] = '\0'; 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 }
@@ -78,4 +196,5 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w)
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 }
@@ -98,4 +217,9 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w)
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 != ' ')
@@ -108,6 +232,14 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w)
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 {
@@ -123,9 +255,17 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w)
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
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();
131 if (exp == NULL) 271 if (exp == NULL)
@@ -145,4 +285,5 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w, int cw)
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}
@@ -183,5 +324,4 @@ int BuffDoc::openfile(QWidget* _parent, const char *src)
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 {
@@ -191,5 +331,4 @@ int BuffDoc::openfile(QWidget* _parent, const char *src)
191 ret = exp->openfile(src); 331 ret = exp->openfile(src);
192 } 332 }
193
194 if (ret != 0) 333 if (ret != 0)
195 { 334 {
@@ -199,16 +338,9 @@ int BuffDoc::openfile(QWidget* _parent, const char *src)
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 }