summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/BuffDoc.cpp
authorllornkcor <llornkcor>2002-09-14 02:19:09 (UTC)
committer llornkcor <llornkcor>2002-09-14 02:19:09 (UTC)
commit2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975 (patch) (side-by-side diff)
treeeeed16b5f80dd5883991a7a06133f5f7a6936256 /noncore/apps/opie-reader/BuffDoc.cpp
parent5a95ed6a000a56849b8f093deea500214856c626 (diff)
downloadopie-2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975.zip
opie-2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975.tar.gz
opie-2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975.tar.bz2
update by Tim
Diffstat (limited to 'noncore/apps/opie-reader/BuffDoc.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-reader/BuffDoc.cpp192
1 files changed, 145 insertions, 47 deletions
diff --git a/noncore/apps/opie-reader/BuffDoc.cpp b/noncore/apps/opie-reader/BuffDoc.cpp
index df2f4eb..e37b136 100644
--- a/noncore/apps/opie-reader/BuffDoc.cpp
+++ b/noncore/apps/opie-reader/BuffDoc.cpp
@@ -1,12 +1,28 @@
#include "BuffDoc.h"
//#include <FL/fl_draw.h>
#include "config.h"
+#include "CDrawBuffer.h"
+#include "plucker.h"
+
+
+bool BuffDoc::hyperlink(unsigned int n)
+{
+ bool bRet = false;
+ lastword.empty();
+ lastsizes[0] = laststartline = n;
+ lastispara = false;
+ if (exp != NULL)
+ {
+ bRet = exp->hyperlink(n);
+ lastsizes[0] = laststartline = exp->locate();
+ }
+ return bRet;
+}
void BuffDoc::locate(unsigned int n)
{
// qDebug("BuffDoc:locating:%u",n);
-
- lastword[0] = '\0';
+ lastword.empty();
lastsizes[0] = laststartline = n;
lastispara = false;
// tchar linebuf[1024];
@@ -14,52 +30,52 @@ void BuffDoc::locate(unsigned int n)
// qDebug("BuffDoc:Located");
}
-bool BuffDoc::getline(CBuffer* buff, int w)
+bool BuffDoc::getline(CDrawBuffer* buff, int w)
{
+ tchar ch = 32;
+ CStyle cs;
+ buff->empty();
if (exp == NULL)
{
- (*buff)[0] = '\0';
+// (*buff)[0] = '\0';
+ buff->empty();
return false;
}
- int len = 0, ch, lastcheck = 0;
- *buff = lastword.data();
+ int len = 0, lastcheck = 0;
+ if (lastword.length() > 0)
+ {
+ *buff = lastword;
+ cs = lastword.laststyle();
+ }
+ else buff->empty();
+// qDebug("Buff:%s Lastword:%s", (const char*)toQString(buff->data()), (const char*)toQString(lastword.data()));
lastcheck = len = buff->length();
- // unsigned int slen = fl_widthi(buff->data(),len);
-#ifdef _UNICODE
- unsigned int slen = m_fm->width(toQString(buff->data()),len);
-#else
- unsigned int slen = m_fm->width(buff->data(),len);
-#endif
+ unsigned int slen = buff->width(len);
if (slen > w)
{
for ( ; len > 0; len--)
{
- // if (fl_widthi(buff->data(),len) < w) break;
-#ifdef _UNICODE
- if (m_fm->width(toQString(buff->data()),len) < w) break;
-#else
- if (m_fm->width(buff->data(),len) < w) break;
-#endif
+ if (buff->width(len) < w) break;
}
- lastword = buff->data() + len - 1;
+// lastword = buff->data() + len - 1;
+ 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] = '-';
+// (*buff)[len-1] = '-';
+ buff->truncate(len-1);
+ buff->addch('-', cs);
(*buff)[len] = '\0';
- laststartline = lastsizes[len-1];
return true;
}
if (lastispara)
{
lastispara = false;
- lastword[0] = '\0';
+// lastword[0] = '\0';
+ lastword.empty();
len = buff->length();
- // while (fl_widthi(buff->data(),len) > w) len--;
-#ifdef _UNICODE
- while (m_fm->width(toQString(buff->data()),len) > w) len--;
-#else
- while (m_fm->width(buff->data(),len) > w) len--;
-#endif
- (*buff)[len] = '\0';
+ while (buff->width(len) > w) len--;
+// (*buff)[len] = '\0';
+ buff->truncate(len);
laststartline = exp->locate();
return true;
}
@@ -69,18 +85,18 @@ bool BuffDoc::getline(CBuffer* buff, int w)
{
lastcheck = len;
allsizes[len] = exp->locate();
- while ((ch = getch()) != ' ' && ch != '\012' && ch != UEOF && len < 128)
+ getch(ch, cs);
+ while (ch != ' ' && ch != '\012' && ch != UEOF && len < 128)
{
- (*buff)[len++] = ch;
+ len++;
+ buff->addch(ch,cs);
allsizes[len] = exp->locate();
+ getch(ch, cs);
}
(*buff)[len] = 0;
-#ifdef _UNICODE
- slen = m_fm->width(toQString(buff->data()),len);
-#else
- slen = m_fm->width(buff->data(),len);
-#endif
- (*buff)[len++] = ' ';
+ slen = buff->width(len);
+ len++;
+ buff->addch(' ', cs);
allsizes[len] = exp->locate();
if (slen < w && ch != ' ')
{
@@ -90,37 +106,119 @@ bool BuffDoc::getline(CBuffer* buff, int w)
lastispara = (ch == '\012');
}
(*buff)[len] = '\0';
- lastword = buff->data()+lastcheck;
+// lastword = buff->data()+lastcheck;
+ lastword.setright(*buff, lastcheck);
for (int i = 0; i < lastword.length(); i++) lastsizes[i] = allsizes[i+lastcheck];
if (lastcheck > 0)
{
laststartline = allsizes[lastcheck];
- (*buff)[lastcheck-1] = '\0';
+// (*buff)[lastcheck-1] = '\0';
+ buff->truncate(lastcheck-1);
}
else
{
laststartline = (lastcheck == len) ? exp->locate() : allsizes[lastcheck+1];
- (*buff)[lastcheck] = '\0';
+// (*buff)[lastcheck] = '\0';
+ buff->truncate(lastcheck);
}
-// laststartline = sizes[lastcheck+1];
-// (*buff)[(lastcheck > 0) ? lastcheck-1:lastcheck] = '\0';
+// buff->frig();
return (ch != UEOF);
}
-bool BuffDoc::getline(CBuffer* buff, int w, int cw)
+bool BuffDoc::getline(CDrawBuffer* buff, int w, int cw)
{
+ buff->empty();
if (exp == NULL)
{
- (*buff)[0] = '\0';
return false;
}
tchar ch;
+ CStyle cs;
int i = 0;
- while ((i < w/cw) && ((ch = getch()) != '\012') && (ch != UEOF))
+ while (i*cw < w)
{
- (*buff)[i++] = ch;
+ getch(ch, cs);
+ if (ch == '\12' || ch == UEOF) break;
+ buff->addch(ch,cs);
+ i++;
}
- (*buff)[i] = '\0';
+ buff->truncate(i);
laststartline = exp->locate();
return (ch != UEOF);
}
+
+int BuffDoc::openfile(QWidget* _parent, const char *src)
+{
+ // qDebug("BuffDoc:Openfile:%s", src);
+ // qDebug("Trying aportis %x",exp);
+ if (exp != NULL) delete exp;
+ lastword.empty();
+ lastsizes[0] = laststartline = 0;
+ lastispara = false;
+ /*
+ exp = new Text;
+ int ret = exp->openfile(src);
+ */
+
+ exp = new Aportis;
+ int ret = exp->openfile(src);
+ if (ret == -1)
+ {
+ delete exp;
+ exp = NULL;
+ return ret;
+ }
+ if (ret == -2)
+ {
+
+ delete exp;
+ exp = new ztxt;
+ ret = exp->openfile(src);
+ }
+ if (ret != 0)
+ {
+
+ delete exp;
+ exp = new CPlucker;
+ ret = exp->openfile(src);
+ }
+#ifndef SMALL
+ if (ret != 0)
+ {
+ delete exp;
+ qDebug("Trying ppms");
+ exp = new ppm_expander;
+ ret = exp->openfile(src);
+ }
+
+ if (ret != 0)
+ {
+ delete exp;
+ exp = new Text;
+// qDebug("Trying text");
+ ret = exp->openfile(src);
+ }
+#else
+ if (ret != 0)
+ {
+ delete exp;
+ exp = new Text;
+ ret = exp->openfile(src);
+ }
+#endif
+ if (ret != 0)
+ {
+ delete exp;
+ QMessageBox::information(_parent, "QTReader", "Unknown file compression type","Try another file");
+ return ret;
+ }
+ // qDebug("Doing final open:%x:%x",exp,filt);
+
+ lastword.empty();
+ lastsizes[0] = laststartline = 0;
+ lastispara = false;
+ exp->locate(0);
+ filt->setsource(exp);
+ // qDebug("BuffDoc:file opened");
+ return 0;
+}