Diffstat (limited to 'noncore/apps/opie-reader/BuffDoc.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/BuffDoc.cpp | 166 |
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 +1,3 @@ | |||
1 | #include "name.h" | ||
2 | |||
1 | #include "BuffDoc.h" | 3 | #include "BuffDoc.h" |
@@ -32,4 +34,108 @@ void BuffDoc::locate(unsigned int n) | |||
32 | 34 | ||
33 | bool BuffDoc::getline(CDrawBuffer* buff, int w) | 35 | #define NEWLINEBREAK |
36 | #ifdef NEWLINEBREAK | ||
37 | bool 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 | ||
137 | bool 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; |
@@ -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,3 +163,3 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w) | |||
55 | { | 163 | { |
56 | for ( ; len > 0; len--) | 164 | for ( ; len > 1; len--) |
57 | { | 165 | { |
@@ -61,5 +169,7 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w) | |||
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); |
@@ -67,2 +177,10 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w) | |||
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; |
@@ -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; |
@@ -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(); |
@@ -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 | ||
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(); |
@@ -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); |
@@ -184,3 +325,2 @@ int BuffDoc::openfile(QWidget* _parent, const char *src) | |||
184 | } | 325 | } |
185 | #ifndef SMALL | ||
186 | if (ret != 0) | 326 | if (ret != 0) |
@@ -192,3 +332,2 @@ int BuffDoc::openfile(QWidget* _parent, const char *src) | |||
192 | } | 332 | } |
193 | |||
194 | if (ret != 0) | 333 | if (ret != 0) |
@@ -200,10 +339,3 @@ int BuffDoc::openfile(QWidget* _parent, const char *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) |
@@ -211,3 +343,3 @@ int BuffDoc::openfile(QWidget* _parent, const char *src) | |||
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; |