summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/CExpander.h
authorllornkcor <llornkcor>2002-09-14 02:19:09 (UTC)
committer llornkcor <llornkcor>2002-09-14 02:19:09 (UTC)
commit2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975 (patch) (unidiff)
treeeeed16b5f80dd5883991a7a06133f5f7a6936256 /noncore/apps/opie-reader/CExpander.h
parent5a95ed6a000a56849b8f093deea500214856c626 (diff)
downloadopie-2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975.zip
opie-2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975.tar.gz
opie-2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975.tar.bz2
update by Tim
Diffstat (limited to 'noncore/apps/opie-reader/CExpander.h') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-reader/CExpander.h136
1 files changed, 17 insertions, 119 deletions
diff --git a/noncore/apps/opie-reader/CExpander.h b/noncore/apps/opie-reader/CExpander.h
index 07c14fa..b1147a6 100644
--- a/noncore/apps/opie-reader/CExpander.h
+++ b/noncore/apps/opie-reader/CExpander.h
@@ -1,132 +1,19 @@
1#ifndef __CExpander_h 1#ifndef __CExpander_h
2#define __CExpander_h 2#define __CExpander_h
3 3
4#include "my_list.h"
5#include "config.h" 4#include "config.h"
5#include "StyleConsts.h"
6#include "Markups.h"
6 7
7class Bkmk 8class Bkmk;
8{
9 friend class BkmkFile;
10 tchar* m_name;
11 unsigned int m_position;
12 public:
13 Bkmk() : m_name(NULL), m_position(0) {};
14 Bkmk(const tchar* _nm, unsigned int _p) : m_position(_p)
15 {
16 int len = ustrlen(_nm)+1;
17 m_name = new tchar[len];
18 for (int i = 0; i < len; i++) m_name[i] = _nm[i];
19 }
20 Bkmk(const Bkmk& rhs) : m_name(NULL)
21 {
22 *this = rhs;
23 }
24 ~Bkmk() { if (m_name != NULL) delete [] m_name; }
25 unsigned int value() const { return m_position; }
26 tchar *name() const { return m_name; }
27 bool operator<(const Bkmk& rhs) { return (m_position < rhs.m_position); }
28 Bkmk& operator=(const Bkmk& rhs)
29 {
30 if (m_name != NULL) delete [] m_name;
31 if (rhs.m_name != NULL)
32 {
33 int len = ustrlen(rhs.m_name)+1;
34 m_name = new tchar[len];
35 for (int i = 0; i < len; i++) m_name[i] = rhs.m_name[i];
36 }
37 else
38 m_name = NULL;
39 m_position = rhs.m_position;
40 return *this;
41 }
42 bool operator==(const Bkmk& rhs)
43 {
44 return (m_position == rhs.m_position && ustrcmp(m_name,rhs.m_name) == 0);
45 }
46};
47 9
48class BkmkFile 10template<class T>
49{ 11class CList;
50 FILE* f;
51 bool wt;
52public:
53 BkmkFile(const char *fnm, bool w = false)
54 :
55 wt(w)
56 {
57 if (w)
58 f = fopen(fnm, "wb");
59 else
60 f = fopen(fnm, "rb");
61 }
62 ~BkmkFile()
63 {
64 if (f != NULL) fclose(f);
65 }
66 void write(tchar* nm, const unsigned int& pos)
67 {
68 if (f != NULL)
69 {
70 unsigned short ln = ustrlen(nm);
71 fwrite(&ln,sizeof(ln),1,f);
72 fwrite(nm,sizeof(tchar),ln,f);
73 fwrite(&pos,sizeof(pos),1,f);
74 }
75 }
76 void write(const Bkmk& b) { write(b.name(), b.value()); }
77 void write(CList<Bkmk>& bl)
78 {
79 if (f != NULL)
80 {
81 for (CList<Bkmk>::iterator i = bl.begin(); i != bl.end(); i++)
82 {
83 write(*i);
84 }
85 }
86 }
87 Bkmk* read()
88 {
89 Bkmk* b = NULL;
90 if (f != NULL)
91 {
92 unsigned short ln;
93 if (fread(&ln,sizeof(ln),1,f) == 1)
94 {
95 b = new Bkmk;
96 b->m_name = new tchar[ln+1];
97 fread(b->m_name,sizeof(tchar),ln,f);
98 b->m_name[ln] = 0;
99 fread(&b->m_position,sizeof(b->m_position),1,f);
100 }
101 }
102 return b;
103 }
104 CList<Bkmk>* readall()
105 {
106 CList<Bkmk>* bl = NULL;
107 if (f != NULL)
108 {
109 bl = new CList<Bkmk>;
110 while (1)
111 {
112 Bkmk* b = read();
113 if (b == NULL) break;
114 bl->push_back(*b);
115 delete b;
116 }
117 }
118 return bl;
119 }
120};
121 12
122class CCharacterSource 13class CCharacterSource
123{ 14{
124 public: 15 public:
125#ifdef _UNICODE 16 virtual void getch(tchar&, CStyle&) = 0;
126 virtual tchar getch() = 0;
127#else
128 virtual int getch() = 0;
129#endif
130}; 17};
131 18
132class CExpander 19class CExpander
@@ -140,6 +27,17 @@ class CExpander
140 virtual bool hasrandomaccess() = 0; 27 virtual bool hasrandomaccess() = 0;
141 virtual void sizes(unsigned long& file, unsigned long& text) = 0; 28 virtual void sizes(unsigned long& file, unsigned long& text) = 0;
142 virtual CList<Bkmk>* getbkmklist() { return NULL; } 29 virtual CList<Bkmk>* getbkmklist() { return NULL; }
30 virtual void getch(int& ch, CStyle& sty)
31 {
32 ch = getch();
33 sty.unset();
34 }
143 virtual int getch() = 0; 35 virtual int getch() = 0;
36 virtual bool hyperlink(unsigned int n)
37 {
38 locate(n);
39 return true;
40 }
41 virtual MarkupType PreferredMarkup() = 0;
144}; 42};
145#endif 43#endif