summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/BuffDoc.h
blob: d6bfd99f766a390542be578f3d1ad16ea001f46c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#ifndef __BuffDoc_h
#define __BuffDoc_h

#include "CDrawBuffer.h"
#include "CFilter.h"
#include "CExpander.h"
#include <qfontmetrics.h>
#include <qmessagebox.h>

class BuffDoc
{
    CDrawBuffer lastword;
    CSizeBuffer lastsizes, allsizes;
    size_t laststartline;
    bool lastispara;
    CExpander_Interface* exp;
    CFilterChain* filt;
    int m_hyphenthreshold;
    //    bool m_customhyphen;
 public:
    QString about();
    bool findanchor(const QString& nm)
      {
	return filt->findanchor(nm);
      }
    //    void setCustomHyphen(bool _v) { m_customhyphen = _v; }
    //    bool getCustomHyphen() { return m_customhyphen; }
    void setHyphenThreshold(int _v) { m_hyphenthreshold = _v; }
    void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen)
	{
	    if (exp == NULL)
	    {
		data = NULL;
		len = 0;
	    }
	    else
	    {
		exp->setSaveData(data, len, src, srclen);
	    }
	}
    void putSaveData(unsigned char*& src, unsigned short& srclen)
	{
	    if (exp != NULL)
	    {
		exp->putSaveData(src, srclen);
	    }
	}
#ifdef USEQPE
    void suspend() { if (exp != NULL) exp->suspend(); }
#else
    void suspend() {}
#endif
    ~BuffDoc()
	{
	    delete filt;
	    delete exp;
	}
    BuffDoc()
	{
	    exp = NULL;
	    filt = NULL;
	    lastword.empty();
//	    //    qDebug("Buffdoc created");
	}
    bool empty() { return (exp == NULL); }
    void setfilter(CFilterChain* _f)
	{
	    if (filt != NULL) delete filt;
	    filt = _f;
	    filt->setsource(exp);
	}
    CList<Bkmk>* getbkmklist() { return exp->getbkmklist(); }
    bool hasrandomaccess() { return (exp == NULL) ? false : exp->hasrandomaccess(); }
    bool iseol() { return (lastword[0] == '\0'); }
    int openfile(QWidget* _parent, const char *src);
    tchar getch()
	{
	    tchar ch = UEOF;
	    CStyle sty;
	    if (exp != NULL)
	    {
	      unsigned long dummy;
		filt->getch(ch, sty, dummy);
	    }
	    return ch;
	}
    void getch(tchar& ch, CStyle& sty, unsigned long& pos)
	{
	    if (exp != NULL)
	    {
		filt->getch(ch, sty, pos);
	    }
	    else
		ch = UEOF;
	}
    /*
    void rawgetch(tchar& ch, CStyle& sty, unsigned long& pos)
	{
	    if (exp != NULL)
	    {
		filt->rawgetch(ch, sty, pos);
	    }
	    else
		ch = UEOF;
	}
    */
    void setwidth(int w) { if (exp != NULL) exp->setwidth(w); }
    QImage* getPicture(unsigned long tgt) { return (exp == NULL) ? NULL : exp->getPicture(tgt); }
    unsigned int startSection() { return (exp == NULL) ? 0 : exp->startSection(); }
    unsigned int endSection() { return (exp == NULL) ? 0 : exp->endSection(); }
    void resetPos();
    unsigned int locate() { return (exp == NULL) ? 0 : laststartline; }
    unsigned int explocate() { return (exp == NULL) ? 0 : exp->locate(); }
    void setContinuous(bool _b) { if (exp != NULL) exp->setContinuous(_b); }
    MarkupType PreferredMarkup() { return (exp == NULL) ? cTEXT : exp->PreferredMarkup(); }
    linkType hyperlink(unsigned int n, unsigned int noff, QString& wrd, QString& nm);
    size_t getHome() { return ((exp != NULL) ? exp->getHome() : 0); }
    void locate(unsigned int n);
    bool getline(CDrawBuffer* buff, int w, unsigned short _lborder, unsigned short _rborder, bool hyphenate, int availht);
    bool getline(CDrawBuffer* buff, int w, int cw, unsigned short _lborder, unsigned short _rborder, int availht);
    void sizes(unsigned long& fs, unsigned long& ts)
      {
	if (exp != NULL)
	  {
	    exp->sizes(fs,ts);
	  }
	else
	  {
	    fs = ts = 0;
	  }
      }
    int getpara(CBuffer& buff)
	{
	    tchar ch;
	    int i = 0;
	    while ((ch = getch()) != 10 && ch != UEOF) buff[i++] = ch;
	    buff[i] = '\0';
	    if (i == 0 && ch == UEOF) i = -1;
	    laststartline = exp->locate();
	    return i;
	}
    int getsentence(CBuffer& buff);
    void saveposn(const QString& f, size_t posn) { filt->saveposn(f, posn); }
    void writeposn(const QString& f, size_t posn) { filt->writeposn(f, posn); }
    linkType forward(QString& f, size_t& loc) { return filt->forward(f, loc); }
    linkType back(QString& f, size_t& loc) { return filt->back(f, loc); }
    bool hasnavigation() { return (exp == NULL) ? false : filt->hasnavigation(); }
    bool getFile(const QString& href, QString& nm)
      {
	return (exp == NULL) ? false : exp->getFile(href, nm);
      }
    QString getTableAsHtml(unsigned long loc)
      {
	return (exp != NULL) ? filt->getTableAsHtml(loc) : QString("");
      }
};

#endif