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 @@ +#include "name.h" + #include "BuffDoc.h" @@ -32,4 +34,108 @@ void BuffDoc::locate(unsigned int n) -bool BuffDoc::getline(CDrawBuffer* buff, int w) +#define NEWLINEBREAK +#ifdef NEWLINEBREAK +bool BuffDoc::getline(CDrawBuffer* buff, int wth) +{ + bool moreleft = true; + bool margindone = false; + int w = wth-2*BORDER; + tchar ch = 32; + CStyle cs; + buff->empty(); + if (exp == NULL) + { + buff->empty(); + buff->setEof(); + return false; + } + int len = 0; + if (lastword.length() > 0) + { + *buff = lastword; + cs = lastword.laststyle(); + w -= buff->leftMargin() + buff->rightMargin(); + margindone = true; + len = lastword.length(); + } + else buff->empty(); + lastword.empty(); + unsigned int slen = buff->width(len); + lastispara = false; + while (1) + { + lastsizes[len] = exp->locate(); + getch(ch, cs); + if (ch == UEOF) + { + lastword.empty(); + if (len == 0) + { + buff->setEof(); + moreleft = false; + } + laststartline = exp->locate(); + break; + } + if (ch == 10) + { + lastword.empty(); + lastispara = true; + laststartline = exp->locate(); + break; + } + buff->addch(ch, cs); + len++; + if (!margindone) + { + w -= buff->leftMargin() + buff->rightMargin(); + margindone = true; + } + if ((slen = buff->width(len)) > w) + { + if (ch == ' ' || len == 1) + { + lastword.empty(); + laststartline = exp->locate(); + break; + } + else // should do a backward search for spaces, first. + { + for (int i = len-1; i > 0; i--) + { + if ((*buff)[i] == ' ') + { + (*buff)[len] = 0; + lastword.setright(*buff, i+1); + buff->truncate(i); + (*buff)[i] = '\0'; + laststartline = lastsizes[i+1]; + buff->resize(); + for (int j = 0; j < lastword.length(); j++) + { + lastsizes[j] = lastsizes[j+i+1]; + } + return true; + } + } + laststartline = lastsizes[len-1]; + lastword.setright(*buff, len - 1); + buff->truncate(len-1); + buff->addch('-', cs); + for (int j = 0; j < lastword.length(); j++) { + lastsizes[j] = lastsizes[j+len]; + } + break; + } + } + } + (*buff)[len] = '\0'; + buff->resize(); + return moreleft; +} +#else +bool BuffDoc::getline(CDrawBuffer* buff, int wth) +{ + bool margindone = false; + int w = wth-2*BORDER; tchar ch = 32; @@ -48,2 +154,4 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w) cs = lastword.laststyle(); + w -= buff->leftMargin() + buff->rightMargin(); + margindone = true; } @@ -55,3 +163,3 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w) { - for ( ; len > 0; len--) + for ( ; len > 1; len--) { @@ -61,5 +169,7 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w) laststartline = lastsizes[len-1]; - lastword.setright(*buff, len - 1); for (int i = 0; i < buff->length(); i++) lastsizes[i] = lastsizes[i+len-1]; // (*buff)[len-1] = '-'; + if (len > 2) + { + lastword.setright(*buff, len - 1); buff->truncate(len-1); @@ -67,2 +177,10 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w) (*buff)[len] = '\0'; + } + + else + { + lastword.empty(); + (*buff)[len] = '\0'; + } + buff->resize(); return true; @@ -79,2 +197,3 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w) laststartline = exp->locate(); + buff->resize(); return true; @@ -99,2 +218,7 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w) buff->addch(' ', cs); + if (!margindone) + { + w -= buff->leftMargin() + buff->rightMargin(); + margindone = true; + } allsizes[len] = exp->locate(); @@ -109,4 +233,12 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w) // lastword = buff->data()+lastcheck; - lastword.setright(*buff, lastcheck); +#ifdef WINDOWS + lastword.setright(*buff, (lastcheck > 0) ? lastcheck : 1); + { + int i; + for (i = 0; i < lastword.length(); i++) lastsizes[i] = allsizes[i+lastcheck]; + } +#else + lastword.setright(*buff, (lastcheck > 0) ? lastcheck : 1); for (int i = 0; i < lastword.length(); i++) lastsizes[i] = allsizes[i+lastcheck]; +#endif if (lastcheck > 0) @@ -124,7 +256,15 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w) // buff->frig(); - return (ch != UEOF); + buff->resize(); + if (ch == UEOF && buff->length() == 0) + { + buff->setEof(); + return false; + } + return true; } +#endif -bool BuffDoc::getline(CDrawBuffer* buff, int w, int cw) +bool BuffDoc::getline(CDrawBuffer* buff, int wth, int cw) { + int w = wth-2*BORDER; buff->empty(); @@ -146,2 +286,3 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w, int cw) laststartline = exp->locate(); + buff->resize(); return (ch != UEOF); @@ -184,3 +325,2 @@ int BuffDoc::openfile(QWidget* _parent, const char *src) } -#ifndef SMALL if (ret != 0) @@ -192,3 +332,2 @@ int BuffDoc::openfile(QWidget* _parent, const char *src) } - if (ret != 0) @@ -200,10 +339,3 @@ int BuffDoc::openfile(QWidget* _parent, const char *src) } -#else - if (ret != 0) - { - delete exp; - exp = new Text; - ret = exp->openfile(src); - } -#endif + if (ret != 0) @@ -211,3 +343,3 @@ int BuffDoc::openfile(QWidget* _parent, const char *src) delete exp; - QMessageBox::information(_parent, "OpieReader", "Unknown file compression type","Try another file"); + QMessageBox::information(_parent, PROGNAME, "Unknown file compression type","Try another file"); return ret; |