author | erik <erik> | 2007-01-19 01:12:38 (UTC) |
---|---|---|
committer | erik <erik> | 2007-01-19 01:12:38 (UTC) |
commit | 1ab92f1d2b346de7da8ca5c3aaa6bc75b43981e7 (patch) (unidiff) | |
tree | af4a12bc46e25853386dc53868b869e1bf05d863 | |
parent | 2b45dc71e79a3eb7d4e8553273c9bc4f4282d50a (diff) | |
download | opie-1ab92f1d2b346de7da8ca5c3aaa6bc75b43981e7.zip opie-1ab92f1d2b346de7da8ca5c3aaa6bc75b43981e7.tar.gz opie-1ab92f1d2b346de7da8ca5c3aaa6bc75b43981e7.tar.bz2 |
Every single file in this commit had a memory leak where a resource is
allocated in the constructor but not de-allocated in the destructor.
This commit fixes that.
-rw-r--r-- | core/apps/embeddedkonsole/TEScreen.cpp | 32 | ||||
-rw-r--r-- | inputmethods/dasher/PPMLanguageModel.cpp | 3 | ||||
-rw-r--r-- | noncore/apps/opie-reader/Bkmks.cpp | 18 | ||||
-rw-r--r-- | noncore/apps/opie-reader/Bkmks.h | 7 | ||||
-rw-r--r-- | noncore/apps/opie-reader/StyleConsts.cpp | 7 | ||||
-rw-r--r-- | noncore/apps/opie-reader/StyleConsts.h | 8 | ||||
-rw-r--r-- | noncore/apps/opie-write/qrichtext.cpp | 5 | ||||
-rw-r--r-- | noncore/apps/tinykate/libkate/document/katehighlight.cpp | 7 | ||||
-rw-r--r-- | noncore/apps/tinykate/libkate/document/katehighlight.h | 2 |
9 files changed, 57 insertions, 32 deletions
diff --git a/core/apps/embeddedkonsole/TEScreen.cpp b/core/apps/embeddedkonsole/TEScreen.cpp index 1db34d2..30ff49d 100644 --- a/core/apps/embeddedkonsole/TEScreen.cpp +++ b/core/apps/embeddedkonsole/TEScreen.cpp | |||
@@ -1,883 +1,885 @@ | |||
1 | /* -------------------------------------------------------------------------- */ | 1 | /* -------------------------------------------------------------------------- */ |
2 | /* */ | 2 | /* */ |
3 | /* [TEScreen.C] Screen Data Type */ | 3 | /* [TEScreen.C] Screen Data Type */ |
4 | /* */ | 4 | /* */ |
5 | /* -------------------------------------------------------------------------- */ | 5 | /* -------------------------------------------------------------------------- */ |
6 | /* */ | 6 | /* */ |
7 | /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ | 7 | /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ |
8 | /* */ | 8 | /* */ |
9 | /* This file is part of Konsole - an X terminal for KDE */ | 9 | /* This file is part of Konsole - an X terminal for KDE */ |
10 | /* */ | 10 | /* */ |
11 | /* -------------------------------------------------------------------------- */ | 11 | /* -------------------------------------------------------------------------- */ |
12 | /* */ | 12 | /* */ |
13 | /* Ported Konsole to Qt/Embedded */ | 13 | /* Ported Konsole to Qt/Embedded */ |
14 | /* */ | 14 | /* */ |
15 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ | 15 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ |
16 | /* */ | 16 | /* */ |
17 | /* -------------------------------------------------------------------------- */ | 17 | /* -------------------------------------------------------------------------- */ |
18 | // enhancements added by L.J. Potter <ljp@llornkcor.com> | 18 | // enhancements added by L.J. Potter <ljp@llornkcor.com> |
19 | 19 | ||
20 | /*! \file | 20 | /*! \file |
21 | */ | 21 | */ |
22 | 22 | ||
23 | /*! \class TEScreen | 23 | /*! \class TEScreen |
24 | 24 | ||
25 | \brief The image manipulated by the emulation. | 25 | \brief The image manipulated by the emulation. |
26 | 26 | ||
27 | This class implements the operations of the terminal emulation framework. | 27 | This class implements the operations of the terminal emulation framework. |
28 | It is a complete passive device, driven by the emulation decoder | 28 | It is a complete passive device, driven by the emulation decoder |
29 | (TEmuVT102). By this it forms in fact an ADT, that defines operations | 29 | (TEmuVT102). By this it forms in fact an ADT, that defines operations |
30 | on a rectangular image. | 30 | on a rectangular image. |
31 | 31 | ||
32 | It does neither know how to display its image nor about escape sequences. | 32 | It does neither know how to display its image nor about escape sequences. |
33 | It is further independent of the underlying toolkit. By this, one can even | 33 | It is further independent of the underlying toolkit. By this, one can even |
34 | use this module for an ordinary text surface. | 34 | use this module for an ordinary text surface. |
35 | 35 | ||
36 | Since the operations are called by a specific emulation decoder, one may | 36 | Since the operations are called by a specific emulation decoder, one may |
37 | collect their different operations here. | 37 | collect their different operations here. |
38 | 38 | ||
39 | The state manipulated by the operations is mainly kept in `image', though | 39 | The state manipulated by the operations is mainly kept in `image', though |
40 | it is a little more complex bejond this. See the header file of the class. | 40 | it is a little more complex bejond this. See the header file of the class. |
41 | 41 | ||
42 | \sa TEWidget \sa VT102Emulation | 42 | \sa TEWidget \sa VT102Emulation |
43 | */ | 43 | */ |
44 | 44 | ||
45 | #include <stdio.h> | 45 | #include <stdio.h> |
46 | #include <stdlib.h> | 46 | #include <stdlib.h> |
47 | #include <unistd.h> | 47 | #include <unistd.h> |
48 | // #include <kdebug.h> | 48 | // #include <kdebug.h> |
49 | 49 | ||
50 | #include <assert.h> | 50 | #include <assert.h> |
51 | #include <string.h> | 51 | #include <string.h> |
52 | #include <ctype.h> | 52 | #include <ctype.h> |
53 | 53 | ||
54 | #include <qpe/config.h> | 54 | #include <qpe/config.h> |
55 | #include "TEScreen.h" | 55 | #include "TEScreen.h" |
56 | 56 | ||
57 | #define HERE printf("%s(%d): here\n",__FILE__,__LINE__) | 57 | #define HERE printf("%s(%d): here\n",__FILE__,__LINE__) |
58 | 58 | ||
59 | //FIXME: this is emulation specific. Use FALSE for xterm, TRUE for ANSI. | 59 | //FIXME: this is emulation specific. Use FALSE for xterm, TRUE for ANSI. |
60 | //FIXME: see if we can get this from terminfo. | 60 | //FIXME: see if we can get this from terminfo. |
61 | #define BS_CLEARS FALSE | 61 | #define BS_CLEARS FALSE |
62 | 62 | ||
63 | #define loc(X,Y) ((Y) * columns + (X)) | 63 | #define loc(X,Y) ((Y) * columns + (X)) |
64 | 64 | ||
65 | /*! creates a `TEScreen' of `lines' lines and `columns' columns. | 65 | /*! creates a `TEScreen' of `lines' lines and `columns' columns. |
66 | */ | 66 | */ |
67 | 67 | ||
68 | TEScreen::TEScreen(int lines, int columns) | 68 | TEScreen::TEScreen(int _lines, int _columns) : |
69 | lines(_lines), | ||
70 | columns(_columns), | ||
71 | tabstops(0), | ||
72 | histCursor(0), | ||
73 | horzCursor(0) | ||
69 | { | 74 | { |
70 | this->lines = lines; | ||
71 | this->columns = columns; | ||
72 | // odebug << "Columns " << columns << "" << oendl; | 75 | // odebug << "Columns " << columns << "" << oendl; |
73 | 76 | ||
74 | image = (ca*) malloc(lines*columns*sizeof(ca)); | 77 | image = new ca[lines*columns]; |
75 | tabstops = NULL; initTabStops(); | 78 | initTabStops(); |
76 | |||
77 | histCursor = 0; | ||
78 | horzCursor = 0; | ||
79 | 79 | ||
80 | clearSelection(); | 80 | clearSelection(); |
81 | reset(); | 81 | reset(); |
82 | } | 82 | } |
83 | 83 | ||
84 | /*! Destructor | 84 | /*! Destructor |
85 | */ | 85 | */ |
86 | 86 | ||
87 | TEScreen::~TEScreen() | 87 | TEScreen::~TEScreen() |
88 | { | 88 | { |
89 | free(image); | 89 | delete [] image; |
90 | if (tabstops) free(tabstops); | 90 | delete [] tabstops; |
91 | } | 91 | } |
92 | 92 | ||
93 | /* ------------------------------------------------------------------------- */ | 93 | /* ------------------------------------------------------------------------- */ |
94 | /* */ | 94 | /* */ |
95 | /* Normalized Screen Operations */ | 95 | /* Normalized Screen Operations */ |
96 | /* */ | 96 | /* */ |
97 | /* ------------------------------------------------------------------------- */ | 97 | /* ------------------------------------------------------------------------- */ |
98 | 98 | ||
99 | // Cursor Setting -------------------------------------------------------------- | 99 | // Cursor Setting -------------------------------------------------------------- |
100 | 100 | ||
101 | /*! \section Cursor | 101 | /*! \section Cursor |
102 | 102 | ||
103 | The `cursor' is a location within the screen that is implicitely used in | 103 | The `cursor' is a location within the screen that is implicitely used in |
104 | many operations. The operations within this section allow to manipulate | 104 | many operations. The operations within this section allow to manipulate |
105 | the cursor explicitly and to obtain it's value. | 105 | the cursor explicitly and to obtain it's value. |
106 | 106 | ||
107 | The position of the cursor is guarantied to be between (including) 0 and | 107 | The position of the cursor is guarantied to be between (including) 0 and |
108 | `columns-1' and `lines-1'. | 108 | `columns-1' and `lines-1'. |
109 | */ | 109 | */ |
110 | 110 | ||
111 | /*! | 111 | /*! |
112 | Move the cursor up. | 112 | Move the cursor up. |
113 | 113 | ||
114 | The cursor will not be moved beyond the top margin. | 114 | The cursor will not be moved beyond the top margin. |
115 | */ | 115 | */ |
116 | 116 | ||
117 | void TEScreen::cursorUp(int n) | 117 | void TEScreen::cursorUp(int n) |
118 | //=CUU | 118 | //=CUU |
119 | { | 119 | { |
120 | if (n == 0) n = 1; // Default | 120 | if (n == 0) n = 1; // Default |
121 | int stop = cuY < tmargin ? 0 : tmargin; | 121 | int stop = cuY < tmargin ? 0 : tmargin; |
122 | cuX = QMIN(columns-1,cuX); // nowrap! | 122 | cuX = QMIN(columns-1,cuX); // nowrap! |
123 | cuY = QMAX(stop,cuY-n); | 123 | cuY = QMAX(stop,cuY-n); |
124 | } | 124 | } |
125 | 125 | ||
126 | /*! | 126 | /*! |
127 | Move the cursor down. | 127 | Move the cursor down. |
128 | 128 | ||
129 | The cursor will not be moved beyond the bottom margin. | 129 | The cursor will not be moved beyond the bottom margin. |
130 | */ | 130 | */ |
131 | 131 | ||
132 | void TEScreen::cursorDown(int n) | 132 | void TEScreen::cursorDown(int n) |
133 | //=CUD | 133 | //=CUD |
134 | { | 134 | { |
135 | if (n == 0) n = 1; // Default | 135 | if (n == 0) n = 1; // Default |
136 | int stop = cuY > bmargin ? lines-1 : bmargin; | 136 | int stop = cuY > bmargin ? lines-1 : bmargin; |
137 | cuX = QMIN(columns-1,cuX); // nowrap! | 137 | cuX = QMIN(columns-1,cuX); // nowrap! |
138 | cuY = QMIN(stop,cuY+n); | 138 | cuY = QMIN(stop,cuY+n); |
139 | } | 139 | } |
140 | 140 | ||
141 | /*! | 141 | /*! |
142 | Move the cursor left. | 142 | Move the cursor left. |
143 | 143 | ||
144 | The cursor will not move beyond the first column. | 144 | The cursor will not move beyond the first column. |
145 | */ | 145 | */ |
146 | 146 | ||
147 | void TEScreen::cursorLeft(int n) | 147 | void TEScreen::cursorLeft(int n) |
148 | //=CUB | 148 | //=CUB |
149 | { | 149 | { |
150 | if (n == 0) n = 1; // Default | 150 | if (n == 0) n = 1; // Default |
151 | cuX = QMIN(columns-1,cuX); // nowrap! | 151 | cuX = QMIN(columns-1,cuX); // nowrap! |
152 | cuX = QMAX(0,cuX-n); | 152 | cuX = QMAX(0,cuX-n); |
153 | } | 153 | } |
154 | 154 | ||
155 | /*! | 155 | /*! |
156 | Move the cursor left. | 156 | Move the cursor left. |
157 | 157 | ||
158 | The cursor will not move beyond the rightmost column. | 158 | The cursor will not move beyond the rightmost column. |
159 | */ | 159 | */ |
160 | 160 | ||
161 | void TEScreen::cursorRight(int n) | 161 | void TEScreen::cursorRight(int n) |
162 | //=CUF | 162 | //=CUF |
163 | { | 163 | { |
164 | if (n == 0) n = 1; // Default | 164 | if (n == 0) n = 1; // Default |
165 | cuX = QMIN(columns-1,cuX+n); | 165 | cuX = QMIN(columns-1,cuX+n); |
166 | } | 166 | } |
167 | 167 | ||
168 | /*! | 168 | /*! |
169 | Set top and bottom margin. | 169 | Set top and bottom margin. |
170 | */ | 170 | */ |
171 | 171 | ||
172 | void TEScreen::setMargins(int top, int bot) | 172 | void TEScreen::setMargins(int top, int bot) |
173 | //=STBM | 173 | //=STBM |
174 | { | 174 | { |
175 | if (top == 0) top = 1; // Default | 175 | if (top == 0) top = 1; // Default |
176 | if (bot == 0) bot = lines; // Default | 176 | if (bot == 0) bot = lines; // Default |
177 | top = top - 1; // Adjust to internal lineno | 177 | top = top - 1; // Adjust to internal lineno |
178 | bot = bot - 1; // Adjust to internal lineno | 178 | bot = bot - 1; // Adjust to internal lineno |
179 | if ( !( 0 <= top && top < bot && bot < lines ) ) | 179 | if ( !( 0 <= top && top < bot && bot < lines ) ) |
180 | { fprintf(stderr,"%s(%d) : setRegion(%d,%d) : bad range.\n", | 180 | { fprintf(stderr,"%s(%d) : setRegion(%d,%d) : bad range.\n", |
181 | __FILE__,__LINE__,top,bot); | 181 | __FILE__,__LINE__,top,bot); |
182 | return; // Default error action: ignore | 182 | return; // Default error action: ignore |
183 | } | 183 | } |
184 | tmargin = top; | 184 | tmargin = top; |
185 | bmargin = bot; | 185 | bmargin = bot; |
186 | cuX = 0; | 186 | cuX = 0; |
187 | cuY = getMode(MODE_Origin) ? top : 0; | 187 | cuY = getMode(MODE_Origin) ? top : 0; |
188 | } | 188 | } |
189 | 189 | ||
190 | /*! | 190 | /*! |
191 | Move the cursor down one line. | 191 | Move the cursor down one line. |
192 | 192 | ||
193 | If cursor is on bottom margin, the region between the | 193 | If cursor is on bottom margin, the region between the |
194 | actual top and bottom margin is scrolled up instead. | 194 | actual top and bottom margin is scrolled up instead. |
195 | */ | 195 | */ |
196 | 196 | ||
197 | void TEScreen::index() | 197 | void TEScreen::index() |
198 | //=IND | 198 | //=IND |
199 | { | 199 | { |
200 | if (cuY == bmargin) | 200 | if (cuY == bmargin) |
201 | { | 201 | { |
202 | if (tmargin == 0 && bmargin == lines-1) addHistLine(); // hist.history | 202 | if (tmargin == 0 && bmargin == lines-1) addHistLine(); // hist.history |
203 | scrollUp(tmargin,1); | 203 | scrollUp(tmargin,1); |
204 | } | 204 | } |
205 | else if (cuY < lines-1) | 205 | else if (cuY < lines-1) |
206 | cuY += 1; | 206 | cuY += 1; |
207 | } | 207 | } |
208 | 208 | ||
209 | /*! | 209 | /*! |
210 | Move the cursor up one line. | 210 | Move the cursor up one line. |
211 | 211 | ||
212 | If cursor is on the top margin, the region between the | 212 | If cursor is on the top margin, the region between the |
213 | actual top and bottom margin is scrolled down instead. | 213 | actual top and bottom margin is scrolled down instead. |
214 | */ | 214 | */ |
215 | 215 | ||
216 | void TEScreen::reverseIndex() | 216 | void TEScreen::reverseIndex() |
217 | //=RI | 217 | //=RI |
218 | { | 218 | { |
219 | if (cuY == tmargin) | 219 | if (cuY == tmargin) |
220 | scrollDown(tmargin,1); | 220 | scrollDown(tmargin,1); |
221 | else if (cuY > 0) | 221 | else if (cuY > 0) |
222 | cuY -= 1; | 222 | cuY -= 1; |
223 | } | 223 | } |
224 | 224 | ||
225 | /*! | 225 | /*! |
226 | Move the cursor to the begin of the next line. | 226 | Move the cursor to the begin of the next line. |
227 | 227 | ||
228 | If cursor is on bottom margin, the region between the | 228 | If cursor is on bottom margin, the region between the |
229 | actual top and bottom margin is scrolled up. | 229 | actual top and bottom margin is scrolled up. |
230 | */ | 230 | */ |
231 | 231 | ||
232 | void TEScreen::NextLine() | 232 | void TEScreen::NextLine() |
233 | //=NEL | 233 | //=NEL |
234 | { | 234 | { |
235 | Return(); index(); | 235 | Return(); index(); |
236 | } | 236 | } |
237 | 237 | ||
238 | // Line Editing ---------------------------------------------------------------- | 238 | // Line Editing ---------------------------------------------------------------- |
239 | 239 | ||
240 | /*! \section inserting / deleting characters | 240 | /*! \section inserting / deleting characters |
241 | */ | 241 | */ |
242 | 242 | ||
243 | /*! erase `n' characters starting from (including) the cursor position. | 243 | /*! erase `n' characters starting from (including) the cursor position. |
244 | 244 | ||
245 | The line is filled in from the right with spaces. | 245 | The line is filled in from the right with spaces. |
246 | */ | 246 | */ |
247 | 247 | ||
248 | void TEScreen::eraseChars(int n) | 248 | void TEScreen::eraseChars(int n) |
249 | { | 249 | { |
250 | if (n == 0) n = 1; // Default | 250 | if (n == 0) n = 1; // Default |
251 | int p = QMAX(0,QMIN(cuX+n-1,columns-1)); | 251 | int p = QMAX(0,QMIN(cuX+n-1,columns-1)); |
252 | clearImage(loc(cuX,cuY),loc(p,cuY),' '); | 252 | clearImage(loc(cuX,cuY),loc(p,cuY),' '); |
253 | } | 253 | } |
254 | 254 | ||
255 | /*! delete `n' characters starting from (including) the cursor position. | 255 | /*! delete `n' characters starting from (including) the cursor position. |
256 | 256 | ||
257 | The line is filled in from the right with spaces. | 257 | The line is filled in from the right with spaces. |
258 | */ | 258 | */ |
259 | 259 | ||
260 | void TEScreen::deleteChars(int n) | 260 | void TEScreen::deleteChars(int n) |
261 | { | 261 | { |
262 | if (n == 0) n = 1; // Default | 262 | if (n == 0) n = 1; // Default |
263 | int p = QMAX(0,QMIN(cuX+n,columns-1)); | 263 | int p = QMAX(0,QMIN(cuX+n,columns-1)); |
264 | moveImage(loc(cuX,cuY),loc(p,cuY),loc(columns-1,cuY)); | 264 | moveImage(loc(cuX,cuY),loc(p,cuY),loc(columns-1,cuY)); |
265 | clearImage(loc(columns-n,cuY),loc(columns-1,cuY),' '); | 265 | clearImage(loc(columns-n,cuY),loc(columns-1,cuY),' '); |
266 | } | 266 | } |
267 | 267 | ||
268 | /*! insert `n' spaces at the cursor position. | 268 | /*! insert `n' spaces at the cursor position. |
269 | 269 | ||
270 | The cursor is not moved by the operation. | 270 | The cursor is not moved by the operation. |
271 | */ | 271 | */ |
272 | 272 | ||
273 | void TEScreen::insertChars(int n) | 273 | void TEScreen::insertChars(int n) |
274 | { | 274 | { |
275 | if (n == 0) n = 1; // Default | 275 | if (n == 0) n = 1; // Default |
276 | int p = QMAX(0,QMIN(columns-1-n,columns-1)); | 276 | int p = QMAX(0,QMIN(columns-1-n,columns-1)); |
277 | int q = QMAX(0,QMIN(cuX+n,columns-1)); | 277 | int q = QMAX(0,QMIN(cuX+n,columns-1)); |
278 | moveImage(loc(q,cuY),loc(cuX,cuY),loc(p,cuY)); | 278 | moveImage(loc(q,cuY),loc(cuX,cuY),loc(p,cuY)); |
279 | clearImage(loc(cuX,cuY),loc(q-1,cuY),' '); | 279 | clearImage(loc(cuX,cuY),loc(q-1,cuY),' '); |
280 | } | 280 | } |
281 | 281 | ||
282 | /*! delete `n' lines starting from (including) the cursor position. | 282 | /*! delete `n' lines starting from (including) the cursor position. |
283 | 283 | ||
284 | The cursor is not moved by the operation. | 284 | The cursor is not moved by the operation. |
285 | */ | 285 | */ |
286 | 286 | ||
287 | void TEScreen::deleteLines(int n) | 287 | void TEScreen::deleteLines(int n) |
288 | { | 288 | { |
289 | if (n == 0) n = 1; // Default | 289 | if (n == 0) n = 1; // Default |
290 | scrollUp(cuY,n); | 290 | scrollUp(cuY,n); |
291 | } | 291 | } |
292 | 292 | ||
293 | /*! insert `n' lines at the cursor position. | 293 | /*! insert `n' lines at the cursor position. |
294 | 294 | ||
295 | The cursor is not moved by the operation. | 295 | The cursor is not moved by the operation. |
296 | */ | 296 | */ |
297 | 297 | ||
298 | void TEScreen::insertLines(int n) | 298 | void TEScreen::insertLines(int n) |
299 | { | 299 | { |
300 | if (n == 0) n = 1; // Default | 300 | if (n == 0) n = 1; // Default |
301 | scrollDown(cuY,n); | 301 | scrollDown(cuY,n); |
302 | } | 302 | } |
303 | 303 | ||
304 | // Mode Operations ----------------------------------------------------------- | 304 | // Mode Operations ----------------------------------------------------------- |
305 | 305 | ||
306 | /*! Set a specific mode. */ | 306 | /*! Set a specific mode. */ |
307 | 307 | ||
308 | void TEScreen::setMode(int m) | 308 | void TEScreen::setMode(int m) |
309 | { | 309 | { |
310 | currParm.mode[m] = TRUE; | 310 | currParm.mode[m] = TRUE; |
311 | switch(m) | 311 | switch(m) |
312 | { | 312 | { |
313 | case MODE_Origin : cuX = 0; cuY = tmargin; break; //FIXME: home | 313 | case MODE_Origin : cuX = 0; cuY = tmargin; break; //FIXME: home |
314 | } | 314 | } |
315 | } | 315 | } |
316 | 316 | ||
317 | /*! Reset a specific mode. */ | 317 | /*! Reset a specific mode. */ |
318 | 318 | ||
319 | void TEScreen::resetMode(int m) | 319 | void TEScreen::resetMode(int m) |
320 | { | 320 | { |
321 | currParm.mode[m] = FALSE; | 321 | currParm.mode[m] = FALSE; |
322 | switch(m) | 322 | switch(m) |
323 | { | 323 | { |
324 | case MODE_Origin : cuX = 0; cuY = 0; break; //FIXME: home | 324 | case MODE_Origin : cuX = 0; cuY = 0; break; //FIXME: home |
325 | } | 325 | } |
326 | } | 326 | } |
327 | 327 | ||
328 | /*! Save a specific mode. */ | 328 | /*! Save a specific mode. */ |
329 | 329 | ||
330 | void TEScreen::saveMode(int m) | 330 | void TEScreen::saveMode(int m) |
331 | { | 331 | { |
332 | saveParm.mode[m] = currParm.mode[m]; | 332 | saveParm.mode[m] = currParm.mode[m]; |
333 | } | 333 | } |
334 | 334 | ||
335 | /*! Restore a specific mode. */ | 335 | /*! Restore a specific mode. */ |
336 | 336 | ||
337 | void TEScreen::restoreMode(int m) | 337 | void TEScreen::restoreMode(int m) |
338 | { | 338 | { |
339 | currParm.mode[m] = saveParm.mode[m]; | 339 | currParm.mode[m] = saveParm.mode[m]; |
340 | } | 340 | } |
341 | 341 | ||
342 | //NOTE: this is a helper function | 342 | //NOTE: this is a helper function |
343 | /*! Return the setting a specific mode. */ | 343 | /*! Return the setting a specific mode. */ |
344 | BOOL TEScreen::getMode(int m) | 344 | BOOL TEScreen::getMode(int m) |
345 | { | 345 | { |
346 | return currParm.mode[m]; | 346 | return currParm.mode[m]; |
347 | } | 347 | } |
348 | 348 | ||
349 | /*! Save the cursor position and the rendition attribute settings. */ | 349 | /*! Save the cursor position and the rendition attribute settings. */ |
350 | 350 | ||
351 | void TEScreen::saveCursor() | 351 | void TEScreen::saveCursor() |
352 | { | 352 | { |
353 | sa_cuX = cuX; | 353 | sa_cuX = cuX; |
354 | sa_cuY = cuY; | 354 | sa_cuY = cuY; |
355 | sa_cu_re = cu_re; | 355 | sa_cu_re = cu_re; |
356 | sa_cu_fg = cu_fg; | 356 | sa_cu_fg = cu_fg; |
357 | sa_cu_bg = cu_bg; | 357 | sa_cu_bg = cu_bg; |
358 | } | 358 | } |
359 | 359 | ||
360 | /*! Restore the cursor position and the rendition attribute settings. */ | 360 | /*! Restore the cursor position and the rendition attribute settings. */ |
361 | 361 | ||
362 | void TEScreen::restoreCursor() | 362 | void TEScreen::restoreCursor() |
363 | { | 363 | { |
364 | cuX = QMIN(sa_cuX,columns-1); | 364 | cuX = QMIN(sa_cuX,columns-1); |
365 | cuY = QMIN(sa_cuY,lines-1); | 365 | cuY = QMIN(sa_cuY,lines-1); |
366 | cu_re = sa_cu_re; | 366 | cu_re = sa_cu_re; |
367 | cu_fg = sa_cu_fg; | 367 | cu_fg = sa_cu_fg; |
368 | cu_bg = sa_cu_bg; | 368 | cu_bg = sa_cu_bg; |
369 | effectiveRendition(); | 369 | effectiveRendition(); |
370 | } | 370 | } |
371 | 371 | ||
372 | /* ------------------------------------------------------------------------- */ | 372 | /* ------------------------------------------------------------------------- */ |
373 | /* */ | 373 | /* */ |
374 | /* Screen Operations */ | 374 | /* Screen Operations */ |
375 | /* */ | 375 | /* */ |
376 | /* ------------------------------------------------------------------------- */ | 376 | /* ------------------------------------------------------------------------- */ |
377 | 377 | ||
378 | /*! Assing a new size to the screen. | 378 | /*! Assing a new size to the screen. |
379 | 379 | ||
380 | The topmost left position is maintained, while lower lines | 380 | The topmost left position is maintained, while lower lines |
381 | or right hand side columns might be removed or filled with | 381 | or right hand side columns might be removed or filled with |
382 | spaces to fit the new size. | 382 | spaces to fit the new size. |
383 | 383 | ||
384 | The region setting is reset to the whole screen and the | 384 | The region setting is reset to the whole screen and the |
385 | tab positions reinitialized. | 385 | tab positions reinitialized. |
386 | */ | 386 | */ |
387 | 387 | ||
388 | void TEScreen::resizeImage(int new_lines, int new_columns) | 388 | void TEScreen::resizeImage(int new_lines, int new_columns) |
389 | { | 389 | { |
390 | if (cuY > new_lines-1) { | 390 | if (cuY > new_lines-1) { |
391 | // attempt to preserve focus and lines | 391 | // attempt to preserve focus and lines |
392 | bmargin = lines-1; //FIXME: margin lost | 392 | bmargin = lines-1; //FIXME: margin lost |
393 | for (int i = 0; i < cuY-(new_lines-1); i++) { | 393 | for (int i = 0; i < cuY-(new_lines-1); i++) { |
394 | addHistLine(); scrollUp(horzCursor,1); | 394 | addHistLine(); scrollUp(horzCursor,1); |
395 | } | 395 | } |
396 | } | 396 | } |
397 | 397 | ||
398 | // make new image | 398 | // make new image |
399 | ca* newimg = (ca*)malloc( new_lines * new_columns * sizeof( ca)); | 399 | ca* newimg = new ca[new_lines * new_columns]; |
400 | 400 | ||
401 | clearSelection(); | 401 | clearSelection(); |
402 | 402 | ||
403 | // clear new image | 403 | // clear new image |
404 | for (int y = 0; y < new_lines; y++) | 404 | for (int y = 0; y < new_lines; y++) |
405 | for (int x = 0; x < new_columns; x++) { | 405 | for (int x = 0; x < new_columns; x++) { |
406 | newimg[y*new_columns+x].c = ' '; | 406 | newimg[y*new_columns+x].c = ' '; |
407 | newimg[y*new_columns+x].f = DEFAULT_FORE_COLOR; | 407 | newimg[y*new_columns+x].f = DEFAULT_FORE_COLOR; |
408 | newimg[y*new_columns+x].b = DEFAULT_BACK_COLOR; | 408 | newimg[y*new_columns+x].b = DEFAULT_BACK_COLOR; |
409 | newimg[y*new_columns+x].r = DEFAULT_RENDITION; | 409 | newimg[y*new_columns+x].r = DEFAULT_RENDITION; |
410 | } | 410 | } |
411 | int cpy_lines = QMIN(new_lines, lines); | 411 | int cpy_lines = QMIN(new_lines, lines); |
412 | int cpy_columns = QMIN(new_columns,columns); | 412 | int cpy_columns = QMIN(new_columns,columns); |
413 | // copy to new image | 413 | // copy to new image |
414 | for (int y = 0; y < cpy_lines; y++) | 414 | for (int y = 0; y < cpy_lines; y++) |
415 | for (int x = 0; x < cpy_columns; x++) { | 415 | for (int x = 0; x < cpy_columns; x++) { |
416 | newimg[y*new_columns+x].c = image[loc(x,y)].c; | 416 | newimg[y*new_columns+x].c = image[loc(x,y)].c; |
417 | newimg[y*new_columns+x].f = image[loc(x,y)].f; | 417 | newimg[y*new_columns+x].f = image[loc(x,y)].f; |
418 | newimg[y*new_columns+x].b = image[loc(x,y)].b; | 418 | newimg[y*new_columns+x].b = image[loc(x,y)].b; |
419 | newimg[y*new_columns+x].r = image[loc(x,y)].r; | 419 | newimg[y*new_columns+x].r = image[loc(x,y)].r; |
420 | } | 420 | } |
421 | free(image); | 421 | delete [] image; |
422 | image = newimg; | 422 | image = newimg; |
423 | lines = new_lines; | 423 | lines = new_lines; |
424 | columns = new_columns; | 424 | columns = new_columns; |
425 | cuX = QMIN(cuX,columns-1); | 425 | cuX = QMIN(cuX,columns-1); |
426 | cuY = QMIN(cuY,lines-1); | 426 | cuY = QMIN(cuY,lines-1); |
427 | 427 | ||
428 | // FIXME: try to keep values, evtl. | 428 | // FIXME: try to keep values, evtl. |
429 | tmargin=0; | 429 | tmargin=0; |
430 | bmargin=lines-1; | 430 | bmargin=lines-1; |
431 | initTabStops(); | 431 | initTabStops(); |
432 | clearSelection(); | 432 | clearSelection(); |
433 | } | 433 | } |
434 | 434 | ||
435 | /* | 435 | /* |
436 | Clarifying rendition here and in TEWidget. | 436 | Clarifying rendition here and in TEWidget. |
437 | 437 | ||
438 | currently, TEWidget's color table is | 438 | currently, TEWidget's color table is |
439 | 0 1 2 .. 9 10 .. 17 | 439 | 0 1 2 .. 9 10 .. 17 |
440 | dft_fg, dft_bg, dim 0..7, intensive 0..7 | 440 | dft_fg, dft_bg, dim 0..7, intensive 0..7 |
441 | 441 | ||
442 | cu_fg, cu_bg contain values 0..8; | 442 | cu_fg, cu_bg contain values 0..8; |
443 | - 0 = default color | 443 | - 0 = default color |
444 | - 1..8 = ansi specified color | 444 | - 1..8 = ansi specified color |
445 | 445 | ||
446 | re_fg, re_bg contain values 0..17 | 446 | re_fg, re_bg contain values 0..17 |
447 | due to the TEWidget's color table | 447 | due to the TEWidget's color table |
448 | 448 | ||
449 | rendition attributes are | 449 | rendition attributes are |
450 | 450 | ||
451 | attr widget screen | 451 | attr widget screen |
452 | -------------- ------ ------ | 452 | -------------- ------ ------ |
453 | RE_UNDERLINE XX XX affects foreground only | 453 | RE_UNDERLINE XX XX affects foreground only |
454 | RE_BLINK XX XX affects foreground only | 454 | RE_BLINK XX XX affects foreground only |
455 | RE_BOLD XX XX affects foreground only | 455 | RE_BOLD XX XX affects foreground only |
456 | RE_REVERSE -- XX | 456 | RE_REVERSE -- XX |
457 | RE_TRANSPARENT XX -- affects background only | 457 | RE_TRANSPARENT XX -- affects background only |
458 | RE_INTENSIVE XX -- affects foreground only | 458 | RE_INTENSIVE XX -- affects foreground only |
459 | 459 | ||
460 | Note that RE_BOLD is used in both widget | 460 | Note that RE_BOLD is used in both widget |
461 | and screen rendition. Since xterm/vt102 | 461 | and screen rendition. Since xterm/vt102 |
462 | is to poor to distinguish between bold | 462 | is to poor to distinguish between bold |
463 | (which is a font attribute) and intensive | 463 | (which is a font attribute) and intensive |
464 | (which is a color attribute), we translate | 464 | (which is a color attribute), we translate |
465 | this and RE_BOLD in falls eventually appart | 465 | this and RE_BOLD in falls eventually appart |
466 | into RE_BOLD and RE_INTENSIVE. | 466 | into RE_BOLD and RE_INTENSIVE. |
467 | */ | 467 | */ |
468 | 468 | ||
469 | void TEScreen::reverseRendition(ca* p) | 469 | void TEScreen::reverseRendition(ca* p) |
470 | { UINT8 f = p->f; UINT8 b = p->b; | 470 | { UINT8 f = p->f; UINT8 b = p->b; |
471 | p->f = b; p->b = f; //p->r &= ~RE_TRANSPARENT; | 471 | p->f = b; p->b = f; //p->r &= ~RE_TRANSPARENT; |
472 | } | 472 | } |
473 | 473 | ||
474 | void TEScreen::effectiveRendition() | 474 | void TEScreen::effectiveRendition() |
475 | // calculate rendition | 475 | // calculate rendition |
476 | { | 476 | { |
477 | ef_re = cu_re & (RE_UNDERLINE | RE_BLINK); | 477 | ef_re = cu_re & (RE_UNDERLINE | RE_BLINK); |
478 | if (cu_re & RE_REVERSE) | 478 | if (cu_re & RE_REVERSE) |
479 | { | 479 | { |
480 | ef_fg = cu_bg; | 480 | ef_fg = cu_bg; |
481 | ef_bg = cu_fg; | 481 | ef_bg = cu_fg; |
482 | } | 482 | } |
483 | else | 483 | else |
484 | { | 484 | { |
485 | ef_fg = cu_fg; | 485 | ef_fg = cu_fg; |
486 | ef_bg = cu_bg; | 486 | ef_bg = cu_bg; |
487 | } | 487 | } |
488 | if (cu_re & RE_BOLD) | 488 | if (cu_re & RE_BOLD) |
489 | { | 489 | { |
490 | if (ef_fg < BASE_COLORS) | 490 | if (ef_fg < BASE_COLORS) |
491 | ef_fg += BASE_COLORS; | 491 | ef_fg += BASE_COLORS; |
492 | else | 492 | else |
493 | ef_fg -= BASE_COLORS; | 493 | ef_fg -= BASE_COLORS; |
494 | } | 494 | } |
495 | } | 495 | } |
496 | 496 | ||
497 | /*! | 497 | /*! |
498 | returns the image. | 498 | returns the image. |
499 | 499 | ||
500 | Get the size of the image by \sa getLines and \sa getColumns. | 500 | Get the size of the image by \sa getLines and \sa getColumns. |
501 | 501 | ||
502 | NOTE that the image returned by this function must later be | 502 | NOTE that the image returned by this function must later be |
503 | freed. | 503 | freed. |
504 | 504 | ||
505 | */ | 505 | */ |
506 | 506 | ||
507 | ca* TEScreen::getCookedImage() | 507 | ca* TEScreen::getCookedImage() |
508 | { | 508 | { |
509 | int x,y; | 509 | int x,y; |
510 | ca* merged = (ca*)malloc(lines*columns*sizeof(ca)); | 510 | ca* merged = new ca[lines*columns]; |
511 | ca dft(' ',DEFAULT_FORE_COLOR,DEFAULT_BACK_COLOR,DEFAULT_RENDITION); | 511 | ca dft(' ',DEFAULT_FORE_COLOR,DEFAULT_BACK_COLOR,DEFAULT_RENDITION); |
512 | 512 | ||
513 | if (histCursor > hist.getLines()) { | 513 | if (histCursor > hist.getLines()) { |
514 | histCursor = hist.getLines(); | 514 | histCursor = hist.getLines(); |
515 | } | 515 | } |
516 | 516 | ||
517 | for (y = 0; (y < lines) && (y < (hist.getLines()-histCursor)); y++) | 517 | for (y = 0; (y < lines) && (y < (hist.getLines()-histCursor)); y++) |
518 | { | 518 | { |
519 | int len = QMIN(columns,hist.getLineLen(y+histCursor)); | 519 | int len = QMIN(columns,hist.getLineLen(y+histCursor)); |
520 | int yp = y*columns; | 520 | int yp = y*columns; |
521 | int yq = (y+histCursor)*columns; | 521 | int yq = (y+histCursor)*columns; |
522 | 522 | ||
523 | hist.getCells(y+histCursor,0,len,merged+yp); | 523 | hist.getCells(y+histCursor,0,len,merged+yp); |
524 | for (x = len; x < columns; x++) merged[yp+x] = dft; | 524 | for (x = len; x < columns; x++) merged[yp+x] = dft; |
525 | for (x = 0; x < columns; x++) | 525 | for (x = 0; x < columns; x++) |
526 | { int p=x + yp; int q=x + yq; | 526 | { int p=x + yp; int q=x + yq; |
527 | if ( ( q >= sel_TL ) && ( q <= sel_BR ) ) | 527 | if ( ( q >= sel_TL ) && ( q <= sel_BR ) ) |
528 | reverseRendition(&merged[p]); // for selection | 528 | reverseRendition(&merged[p]); // for selection |
529 | } | 529 | } |
530 | } | 530 | } |
531 | if (lines >= hist.getLines()-histCursor) | 531 | if (lines >= hist.getLines()-histCursor) |
532 | { | 532 | { |
533 | for (y = (hist.getLines()-histCursor); y < lines ; y++) | 533 | for (y = (hist.getLines()-histCursor); y < lines ; y++) |
534 | { | 534 | { |
535 | int yp = y*columns; | 535 | int yp = y*columns; |
536 | int yq = (y+histCursor)*columns; | 536 | int yq = (y+histCursor)*columns; |
537 | int yr = (y-hist.getLines()+histCursor)*columns; | 537 | int yr = (y-hist.getLines()+histCursor)*columns; |
538 | for (x = 0; x < columns; x++) | 538 | for (x = 0; x < columns; x++) |
539 | { int p = x + yp; int q = x + yq; int r = x + yr; | 539 | { int p = x + yp; int q = x + yq; int r = x + yr; |
540 | merged[p] = image[r]; | 540 | merged[p] = image[r]; |
541 | if ( q >= sel_TL && q <= sel_BR ) | 541 | if ( q >= sel_TL && q <= sel_BR ) |
542 | reverseRendition(&merged[p]); // for selection | 542 | reverseRendition(&merged[p]); // for selection |
543 | } | 543 | } |
544 | 544 | ||
545 | } | 545 | } |
546 | } | 546 | } |
547 | // evtl. inverse display | 547 | // evtl. inverse display |
548 | if (getMode(MODE_Screen)) | 548 | if (getMode(MODE_Screen)) |
549 | { int i,n = lines*columns; | 549 | { int i,n = lines*columns; |
550 | for (i = 0; i < n; i++) | 550 | for (i = 0; i < n; i++) |
551 | reverseRendition(&merged[i]); // for reverse display | 551 | reverseRendition(&merged[i]); // for reverse display |
552 | } | 552 | } |
553 | if (getMode(MODE_Cursor) && (cuY+(hist.getLines()-histCursor) < lines)) // cursor visible | 553 | if (getMode(MODE_Cursor) && (cuY+(hist.getLines()-histCursor) < lines)) // cursor visible |
554 | reverseRendition(&merged[loc(cuX,cuY+(hist.getLines()-histCursor))]); | 554 | reverseRendition(&merged[loc(cuX,cuY+(hist.getLines()-histCursor))]); |
555 | return merged; | 555 | return merged; |
556 | 556 | ||
557 | } | 557 | } |
558 | 558 | ||
559 | 559 | ||
560 | /*! | 560 | /*! |
561 | */ | 561 | */ |
562 | 562 | ||
563 | void TEScreen::reset() | 563 | void TEScreen::reset() |
564 | { | 564 | { |
565 | Config cfg( "Konsole" ); | 565 | Config cfg( "Konsole" ); |
566 | cfg.setGroup("ScrollBar"); | 566 | cfg.setGroup("ScrollBar"); |
567 | if( !cfg.readBoolEntry("HorzScroll",0) ) | 567 | if( !cfg.readBoolEntry("HorzScroll",0) ) |
568 | setMode(MODE_Wrap ); saveMode(MODE_Wrap ); // wrap at end of margin | 568 | setMode(MODE_Wrap ); saveMode(MODE_Wrap ); // wrap at end of margin |
569 | 569 | ||
570 | 570 | ||
571 | resetMode(MODE_Origin); saveMode(MODE_Origin); // position refere to [1,1] | 571 | resetMode(MODE_Origin); saveMode(MODE_Origin); // position refere to [1,1] |
572 | resetMode(MODE_Insert); saveMode(MODE_Insert); // overstroke | 572 | resetMode(MODE_Insert); saveMode(MODE_Insert); // overstroke |
573 | setMode(MODE_Cursor); // cursor visible | 573 | setMode(MODE_Cursor); // cursor visible |
574 | resetMode(MODE_Screen); // screen not inverse | 574 | resetMode(MODE_Screen); // screen not inverse |
575 | resetMode(MODE_NewLine); | 575 | resetMode(MODE_NewLine); |
576 | 576 | ||
577 | tmargin=0; | 577 | tmargin=0; |
578 | bmargin=lines-1; | 578 | bmargin=lines-1; |
579 | 579 | ||
580 | setDefaultRendition(); | 580 | setDefaultRendition(); |
581 | saveCursor(); | 581 | saveCursor(); |
582 | 582 | ||
583 | clear(); | 583 | clear(); |
584 | } | 584 | } |
585 | 585 | ||
586 | /*! Clear the entire screen and home the cursor. | 586 | /*! Clear the entire screen and home the cursor. |
587 | */ | 587 | */ |
588 | 588 | ||
589 | void TEScreen::clear() | 589 | void TEScreen::clear() |
590 | { | 590 | { |
591 | clearEntireScreen(); | 591 | clearEntireScreen(); |
592 | home(); | 592 | home(); |
593 | } | 593 | } |
594 | 594 | ||
595 | /*! Moves the cursor left one column. | 595 | /*! Moves the cursor left one column. |
596 | */ | 596 | */ |
597 | 597 | ||
598 | void TEScreen::BackSpace() | 598 | void TEScreen::BackSpace() |
599 | { | 599 | { |
600 | cuX = QMAX(0,cuX-1); | 600 | cuX = QMAX(0,cuX-1); |
601 | if (BS_CLEARS) image[loc(cuX,cuY)].c = ' '; | 601 | if (BS_CLEARS) image[loc(cuX,cuY)].c = ' '; |
602 | } | 602 | } |
603 | 603 | ||
604 | /*! | 604 | /*! |
605 | */ | 605 | */ |
606 | 606 | ||
607 | void TEScreen::Tabulate() | 607 | void TEScreen::Tabulate() |
608 | { | 608 | { |
609 | // note that TAB is a format effector (does not write ' '); | 609 | // note that TAB is a format effector (does not write ' '); |
610 | cursorRight(1); while(cuX < columns-1 && !tabstops[cuX]) cursorRight(1); | 610 | cursorRight(1); while(cuX < columns-1 && !tabstops[cuX]) cursorRight(1); |
611 | } | 611 | } |
612 | 612 | ||
613 | void TEScreen::clearTabStops() | 613 | void TEScreen::clearTabStops() |
614 | { | 614 | { |
615 | for (int i = 0; i < columns; i++) tabstops[i-1] = FALSE; | 615 | for (int i = 0; i < columns; i++) tabstops[i-1] = FALSE; |
616 | } | 616 | } |
617 | 617 | ||
618 | void TEScreen::changeTabStop(bool set) | 618 | void TEScreen::changeTabStop(bool set) |
619 | { | 619 | { |
620 | if (cuX >= columns) return; | 620 | if (cuX >= columns) return; |
621 | tabstops[cuX] = set; | 621 | tabstops[cuX] = set; |
622 | } | 622 | } |
623 | 623 | ||
624 | void TEScreen::initTabStops() | 624 | void TEScreen::initTabStops() |
625 | { | 625 | { |
626 | if (tabstops) free(tabstops); | 626 | if (tabstops) |
627 | tabstops = (bool*)malloc(columns*sizeof(bool)); | 627 | delete [] tabstops; |
628 | |||
629 | tabstops = new bool[columns]; | ||
628 | // Arrg! The 1st tabstop has to be one longer than the other. | 630 | // Arrg! The 1st tabstop has to be one longer than the other. |
629 | // i.e. the kids start counting from 0 instead of 1. | 631 | // i.e. the kids start counting from 0 instead of 1. |
630 | // Other programs might behave correctly. Be aware. | 632 | // Other programs might behave correctly. Be aware. |
631 | for (int i = 0; i < columns; i++) tabstops[i] = (i%8 == 0 && i != 0); | 633 | for (int i = 0; i < columns; i++) tabstops[i] = (i%8 == 0 && i != 0); |
632 | } | 634 | } |
633 | 635 | ||
634 | /*! | 636 | /*! |
635 | This behaves either as IND (Screen::Index) or as NEL (Screen::NextLine) | 637 | This behaves either as IND (Screen::Index) or as NEL (Screen::NextLine) |
636 | depending on the NewLine Mode (LNM). This mode also | 638 | depending on the NewLine Mode (LNM). This mode also |
637 | affects the key sequence returned for newline ([CR]LF). | 639 | affects the key sequence returned for newline ([CR]LF). |
638 | */ | 640 | */ |
639 | 641 | ||
640 | void TEScreen::NewLine() | 642 | void TEScreen::NewLine() |
641 | { | 643 | { |
642 | if (getMode(MODE_NewLine)) Return(); | 644 | if (getMode(MODE_NewLine)) Return(); |
643 | index(); | 645 | index(); |
644 | } | 646 | } |
645 | 647 | ||
646 | /*! put `c' literally onto the screen at the current cursor position. | 648 | /*! put `c' literally onto the screen at the current cursor position. |
647 | 649 | ||
648 | VT100 uses the convention to produce an automatic newline (am) | 650 | VT100 uses the convention to produce an automatic newline (am) |
649 | with the *first* character that would fall onto the next line (xenl). | 651 | with the *first* character that would fall onto the next line (xenl). |
650 | */ | 652 | */ |
651 | 653 | ||
652 | void TEScreen::checkSelection(int from, int to) | 654 | void TEScreen::checkSelection(int from, int to) |
653 | { | 655 | { |
654 | if (sel_begin == -1) return; | 656 | if (sel_begin == -1) return; |
655 | int scr_TL = loc(0, hist.getLines()); | 657 | int scr_TL = loc(0, hist.getLines()); |
656 | //Clear entire selection if it overlaps region [from, to] | 658 | //Clear entire selection if it overlaps region [from, to] |
657 | if ( (sel_BR > (from+scr_TL) )&&(sel_TL < (to+scr_TL)) ) | 659 | if ( (sel_BR > (from+scr_TL) )&&(sel_TL < (to+scr_TL)) ) |
658 | { | 660 | { |
659 | clearSelection(); | 661 | clearSelection(); |
660 | } | 662 | } |
661 | } | 663 | } |
662 | 664 | ||
663 | void TEScreen::ShowCharacter(unsigned short c) | 665 | void TEScreen::ShowCharacter(unsigned short c) |
664 | { | 666 | { |
665 | // Note that VT100 does wrapping BEFORE putting the character. | 667 | // Note that VT100 does wrapping BEFORE putting the character. |
666 | // This has impact on the assumption of valid cursor positions. | 668 | // This has impact on the assumption of valid cursor positions. |
667 | // We indicate the fact that a newline has to be triggered by | 669 | // We indicate the fact that a newline has to be triggered by |
668 | // putting the cursor one right to the last column of the screen. | 670 | // putting the cursor one right to the last column of the screen. |
669 | 671 | ||
670 | if (cuX >= columns) | 672 | if (cuX >= columns) |
671 | { | 673 | { |
672 | if (getMode(MODE_Wrap)) NextLine(); else cuX = columns - 1; | 674 | if (getMode(MODE_Wrap)) NextLine(); else cuX = columns - 1; |
673 | // comment out for no wrap | 675 | // comment out for no wrap |
674 | } | 676 | } |
675 | 677 | ||
676 | if (getMode(MODE_Insert)) insertChars(1); | 678 | if (getMode(MODE_Insert)) insertChars(1); |
677 | 679 | ||
678 | int i = loc( cuX, cuY); | 680 | int i = loc( cuX, cuY); |
679 | 681 | ||
680 | checkSelection(i, i); // check if selection is still valid. | 682 | checkSelection(i, i); // check if selection is still valid. |
681 | 683 | ||
682 | image[i].c = c; | 684 | image[i].c = c; |
683 | image[i].f = ef_fg; | 685 | image[i].f = ef_fg; |
684 | image[i].b = ef_bg; | 686 | image[i].b = ef_bg; |
685 | image[i].r = ef_re; | 687 | image[i].r = ef_re; |
686 | 688 | ||
687 | cuX += 1; | 689 | cuX += 1; |
688 | } | 690 | } |
689 | 691 | ||
690 | // Region commands ------------------------------------------------------------- | 692 | // Region commands ------------------------------------------------------------- |
691 | 693 | ||
692 | 694 | ||
693 | /*! scroll up `n' lines within current region. | 695 | /*! scroll up `n' lines within current region. |
694 | The `n' new lines are cleared. | 696 | The `n' new lines are cleared. |
695 | \sa setRegion \sa scrollDown | 697 | \sa setRegion \sa scrollDown |
696 | */ | 698 | */ |
697 | 699 | ||
698 | void TEScreen::scrollUp(int from, int n) | 700 | void TEScreen::scrollUp(int from, int n) |
699 | { | 701 | { |
700 | if (n <= 0 || from + n > bmargin) return; | 702 | if (n <= 0 || from + n > bmargin) return; |
701 | //FIXME: make sure `tmargin', `bmargin', `from', `n' is in bounds. | 703 | //FIXME: make sure `tmargin', `bmargin', `from', `n' is in bounds. |
702 | 704 | ||
703 | moveImage( loc( 0, from), loc( 0, from + n), loc( columns - 1, bmargin)); | 705 | moveImage( loc( 0, from), loc( 0, from + n), loc( columns - 1, bmargin)); |
704 | clearImage( loc( 0, bmargin - n + 1), loc( columns - 1, bmargin), ' '); | 706 | clearImage( loc( 0, bmargin - n + 1), loc( columns - 1, bmargin), ' '); |
705 | } | 707 | } |
706 | 708 | ||
707 | /*! scroll down `n' lines within current region. | 709 | /*! scroll down `n' lines within current region. |
708 | The `n' new lines are cleared. | 710 | The `n' new lines are cleared. |
709 | \sa setRegion \sa scrollUp | 711 | \sa setRegion \sa scrollUp |
710 | */ | 712 | */ |
711 | 713 | ||
712 | void TEScreen::scrollDown(int from, int n) | 714 | void TEScreen::scrollDown(int from, int n) |
713 | { | 715 | { |
714 | 716 | ||
715 | //FIXME: make sure `tmargin', `bmargin', `from', `n' is in bounds. | 717 | //FIXME: make sure `tmargin', `bmargin', `from', `n' is in bounds. |
716 | if (n <= 0) return; | 718 | if (n <= 0) return; |
717 | if (from > bmargin) return; | 719 | if (from > bmargin) return; |
718 | if (from + n > bmargin) n = bmargin - from; | 720 | if (from + n > bmargin) n = bmargin - from; |
719 | 721 | ||
720 | moveImage( loc(0,from+n), loc(0,from), loc(columns-1,bmargin-n)); | 722 | moveImage( loc(0,from+n), loc(0,from), loc(columns-1,bmargin-n)); |
721 | clearImage(loc(0,from),loc(columns-1,from+n-1),' '); | 723 | clearImage(loc(0,from),loc(columns-1,from+n-1),' '); |
722 | } | 724 | } |
723 | 725 | ||
724 | 726 | ||
725 | 727 | ||
726 | /*! position the cursor to a specific line and column. */ | 728 | /*! position the cursor to a specific line and column. */ |
727 | void TEScreen::setCursorYX(int y, int x) | 729 | void TEScreen::setCursorYX(int y, int x) |
728 | { | 730 | { |
729 | setCursorY(y); setCursorX(x); | 731 | setCursorY(y); setCursorX(x); |
730 | } | 732 | } |
731 | 733 | ||
732 | /*! Set the cursor to x-th line. */ | 734 | /*! Set the cursor to x-th line. */ |
733 | 735 | ||
734 | void TEScreen::setCursorX(int x) | 736 | void TEScreen::setCursorX(int x) |
735 | { | 737 | { |
736 | if (x == 0) x = 1; // Default | 738 | if (x == 0) x = 1; // Default |
737 | x -= 1; // Adjust | 739 | x -= 1; // Adjust |
738 | cuX = QMAX(0,QMIN(columns-1, x)); | 740 | cuX = QMAX(0,QMIN(columns-1, x)); |
739 | } | 741 | } |
740 | 742 | ||
741 | /*! Set the cursor to y-th line. */ | 743 | /*! Set the cursor to y-th line. */ |
742 | 744 | ||
743 | void TEScreen::setCursorY(int y) | 745 | void TEScreen::setCursorY(int y) |
744 | { | 746 | { |
745 | if (y == 0) y = 1; // Default | 747 | if (y == 0) y = 1; // Default |
746 | y -= 1; // Adjust | 748 | y -= 1; // Adjust |
747 | cuY = QMAX(0,QMIN(lines -1, y + (getMode(MODE_Origin) ? tmargin : 0) )); | 749 | cuY = QMAX(0,QMIN(lines -1, y + (getMode(MODE_Origin) ? tmargin : 0) )); |
748 | } | 750 | } |
749 | 751 | ||
750 | /*! set cursor to the `left upper' corner of the screen (1,1). | 752 | /*! set cursor to the `left upper' corner of the screen (1,1). |
751 | */ | 753 | */ |
752 | 754 | ||
753 | void TEScreen::home() | 755 | void TEScreen::home() |
754 | { | 756 | { |
755 | cuX = 0; | 757 | cuX = 0; |
756 | cuY = 0; | 758 | cuY = 0; |
757 | } | 759 | } |
758 | 760 | ||
759 | /*! set cursor to the begin of the current line. | 761 | /*! set cursor to the begin of the current line. |
760 | */ | 762 | */ |
761 | 763 | ||
762 | void TEScreen::Return() | 764 | void TEScreen::Return() |
763 | { | 765 | { |
764 | cuX = 0; | 766 | cuX = 0; |
765 | } | 767 | } |
766 | 768 | ||
767 | /*! returns the current cursor columns. | 769 | /*! returns the current cursor columns. |
768 | */ | 770 | */ |
769 | 771 | ||
770 | int TEScreen::getCursorX() | 772 | int TEScreen::getCursorX() |
771 | { | 773 | { |
772 | return cuX; | 774 | return cuX; |
773 | } | 775 | } |
774 | 776 | ||
775 | /*! returns the current cursor line. | 777 | /*! returns the current cursor line. |
776 | */ | 778 | */ |
777 | 779 | ||
778 | int TEScreen::getCursorY() | 780 | int TEScreen::getCursorY() |
779 | { | 781 | { |
780 | return cuY; | 782 | return cuY; |
781 | } | 783 | } |
782 | 784 | ||
783 | // Erasing --------------------------------------------------------------------- | 785 | // Erasing --------------------------------------------------------------------- |
784 | 786 | ||
785 | /*! \section Erasing | 787 | /*! \section Erasing |
786 | 788 | ||
787 | This group of operations erase parts of the screen contents by filling | 789 | This group of operations erase parts of the screen contents by filling |
788 | it with spaces colored due to the current rendition settings. | 790 | it with spaces colored due to the current rendition settings. |
789 | 791 | ||
790 | Althought the cursor position is involved in most of these operations, | 792 | Althought the cursor position is involved in most of these operations, |
791 | it is never modified by them. | 793 | it is never modified by them. |
792 | */ | 794 | */ |
793 | 795 | ||
794 | /*! fill screen between (including) `loca' and `loce' with spaces. | 796 | /*! fill screen between (including) `loca' and `loce' with spaces. |
795 | 797 | ||
796 | This is an internal helper functions. The parameter types are internal | 798 | This is an internal helper functions. The parameter types are internal |
797 | addresses of within the screen image and make use of the way how the | 799 | addresses of within the screen image and make use of the way how the |
798 | screen matrix is mapped to the image vector. | 800 | screen matrix is mapped to the image vector. |
799 | */ | 801 | */ |
800 | 802 | ||
801 | void TEScreen::clearImage(int loca, int loce, char c) | 803 | void TEScreen::clearImage(int loca, int loce, char c) |
802 | { int i; | 804 | { int i; |
803 | int scr_TL=loc(0,hist.getLines()); | 805 | int scr_TL=loc(0,hist.getLines()); |
804 | //FIXME: check positions | 806 | //FIXME: check positions |
805 | 807 | ||
806 | //Clear entire selection if it overlaps region to be moved... | 808 | //Clear entire selection if it overlaps region to be moved... |
807 | if ( (sel_BR > (loca+scr_TL) )&&(sel_TL < (loce+scr_TL)) ) | 809 | if ( (sel_BR > (loca+scr_TL) )&&(sel_TL < (loce+scr_TL)) ) |
808 | { | 810 | { |
809 | clearSelection(); | 811 | clearSelection(); |
810 | } | 812 | } |
811 | for (i = loca; i <= loce; i++) | 813 | for (i = loca; i <= loce; i++) |
812 | { | 814 | { |
813 | image[i].c = c; | 815 | image[i].c = c; |
814 | image[i].f = ef_fg; //DEFAULT_FORE_COLOR; //FIXME: xterm and linux/ansi | 816 | image[i].f = ef_fg; //DEFAULT_FORE_COLOR; //FIXME: xterm and linux/ansi |
815 | image[i].b = ef_bg; //DEFAULT_BACK_COLOR; // many have different | 817 | image[i].b = ef_bg; //DEFAULT_BACK_COLOR; // many have different |
816 | image[i].r = ef_re; //DEFAULT_RENDITION; // ideas here. | 818 | image[i].r = ef_re; //DEFAULT_RENDITION; // ideas here. |
817 | } | 819 | } |
818 | } | 820 | } |
819 | 821 | ||
820 | /*! move image between (including) `loca' and `loce' to 'dst'. | 822 | /*! move image between (including) `loca' and `loce' to 'dst'. |
821 | 823 | ||
822 | This is an internal helper functions. The parameter types are internal | 824 | This is an internal helper functions. The parameter types are internal |
823 | addresses of within the screen image and make use of the way how the | 825 | addresses of within the screen image and make use of the way how the |
824 | screen matrix is mapped to the image vector. | 826 | screen matrix is mapped to the image vector. |
825 | */ | 827 | */ |
826 | 828 | ||
827 | void TEScreen::moveImage(int dst, int loca, int loce) | 829 | void TEScreen::moveImage(int dst, int loca, int loce) |
828 | { | 830 | { |
829 | //FIXME: check positions | 831 | //FIXME: check positions |
830 | if (loce < loca) { | 832 | if (loce < loca) { |
831 | // kdDebug() << "WARNING!!! call to TEScreen:moveImage with loce < loca!" << endl; | 833 | // kdDebug() << "WARNING!!! call to TEScreen:moveImage with loce < loca!" << endl; |
832 | return; | 834 | return; |
833 | } | 835 | } |
834 | memmove(&image[dst],&image[loca],(loce-loca+1)*sizeof(ca)); | 836 | memmove(&image[dst],&image[loca],(loce-loca+1)*sizeof(ca)); |
835 | } | 837 | } |
836 | 838 | ||
837 | /*! clear from (including) current cursor position to end of screen. | 839 | /*! clear from (including) current cursor position to end of screen. |
838 | */ | 840 | */ |
839 | 841 | ||
840 | void TEScreen::clearToEndOfScreen() | 842 | void TEScreen::clearToEndOfScreen() |
841 | { | 843 | { |
842 | clearImage(loc(cuX,cuY),loc(columns-1,lines-1),' '); | 844 | clearImage(loc(cuX,cuY),loc(columns-1,lines-1),' '); |
843 | } | 845 | } |
844 | 846 | ||
845 | /*! clear from begin of screen to (including) current cursor position. | 847 | /*! clear from begin of screen to (including) current cursor position. |
846 | */ | 848 | */ |
847 | 849 | ||
848 | void TEScreen::clearToBeginOfScreen() | 850 | void TEScreen::clearToBeginOfScreen() |
849 | { | 851 | { |
850 | clearImage(loc(0,0),loc(cuX,cuY),' '); | 852 | clearImage(loc(0,0),loc(cuX,cuY),' '); |
851 | } | 853 | } |
852 | 854 | ||
853 | /*! clear the entire screen. | 855 | /*! clear the entire screen. |
854 | */ | 856 | */ |
855 | 857 | ||
856 | void TEScreen::clearEntireScreen() | 858 | void TEScreen::clearEntireScreen() |
857 | { | 859 | { |
858 | clearImage(loc(0,0),loc(columns-1,lines-1),' '); | 860 | clearImage(loc(0,0),loc(columns-1,lines-1),' '); |
859 | } | 861 | } |
860 | 862 | ||
861 | /*! fill screen with 'E' | 863 | /*! fill screen with 'E' |
862 | This is to aid screen alignment | 864 | This is to aid screen alignment |
863 | */ | 865 | */ |
864 | 866 | ||
865 | void TEScreen::helpAlign() | 867 | void TEScreen::helpAlign() |
866 | { | 868 | { |
867 | clearImage(loc(0,0),loc(columns-1,lines-1),'E'); | 869 | clearImage(loc(0,0),loc(columns-1,lines-1),'E'); |
868 | } | 870 | } |
869 | 871 | ||
870 | /*! clear from (including) current cursor position to end of current cursor line. | 872 | /*! clear from (including) current cursor position to end of current cursor line. |
871 | */ | 873 | */ |
872 | 874 | ||
873 | void TEScreen::clearToEndOfLine() | 875 | void TEScreen::clearToEndOfLine() |
874 | { | 876 | { |
875 | clearImage(loc(cuX,cuY),loc(columns-1,cuY),' '); | 877 | clearImage(loc(cuX,cuY),loc(columns-1,cuY),' '); |
876 | } | 878 | } |
877 | 879 | ||
878 | /*! clear from begin of current cursor line to (including) current cursor position. | 880 | /*! clear from begin of current cursor line to (including) current cursor position. |
879 | */ | 881 | */ |
880 | 882 | ||
881 | void TEScreen::clearToBeginOfLine() | 883 | void TEScreen::clearToBeginOfLine() |
882 | { | 884 | { |
883 | clearImage(loc(0,cuY),loc(cuX,cuY),' '); | 885 | clearImage(loc(0,cuY),loc(cuX,cuY),' '); |
diff --git a/inputmethods/dasher/PPMLanguageModel.cpp b/inputmethods/dasher/PPMLanguageModel.cpp index 137b07f..d767d16 100644 --- a/inputmethods/dasher/PPMLanguageModel.cpp +++ b/inputmethods/dasher/PPMLanguageModel.cpp | |||
@@ -1,309 +1,310 @@ | |||
1 | // PPMLanguageModel.h | 1 | // PPMLanguageModel.h |
2 | // | 2 | // |
3 | ///////////////////////////////////////////////////////////////////////////// | 3 | ///////////////////////////////////////////////////////////////////////////// |
4 | // | 4 | // |
5 | // Copyright (c) 1999-2002 David Ward | 5 | // Copyright (c) 1999-2002 David Ward |
6 | // | 6 | // |
7 | ///////////////////////////////////////////////////////////////////////////// | 7 | ///////////////////////////////////////////////////////////////////////////// |
8 | 8 | ||
9 | #include <math.h> | 9 | #include <math.h> |
10 | #include "PPMLanguageModel.h" | 10 | #include "PPMLanguageModel.h" |
11 | 11 | ||
12 | using namespace Dasher; | 12 | using namespace Dasher; |
13 | using namespace std; | 13 | using namespace std; |
14 | 14 | ||
15 | // static TCHAR debug[256]; | 15 | // static TCHAR debug[256]; |
16 | typedef unsigned long ulong; | 16 | typedef unsigned long ulong; |
17 | 17 | ||
18 | //////////////////////////////////////////////////////////////////////// | 18 | //////////////////////////////////////////////////////////////////////// |
19 | /// PPMnode definitions | 19 | /// PPMnode definitions |
20 | //////////////////////////////////////////////////////////////////////// | 20 | //////////////////////////////////////////////////////////////////////// |
21 | 21 | ||
22 | CPPMLanguageModel::CPPMnode *CPPMLanguageModel::CPPMnode::find_symbol(int sym) | 22 | CPPMLanguageModel::CPPMnode *CPPMLanguageModel::CPPMnode::find_symbol(int sym) |
23 | // see if symbol is a child of node | 23 | // see if symbol is a child of node |
24 | { | 24 | { |
25 | // printf("finding symbol %d at node %d\n",sym,node->id); | 25 | // printf("finding symbol %d at node %d\n",sym,node->id); |
26 | CPPMnode *found=child; | 26 | CPPMnode *found=child; |
27 | while (found) { | 27 | while (found) { |
28 | if (found->symbol==sym) | 28 | if (found->symbol==sym) |
29 | return found; | 29 | return found; |
30 | found=found->next; | 30 | found=found->next; |
31 | } | 31 | } |
32 | return 0; | 32 | return 0; |
33 | } | 33 | } |
34 | 34 | ||
35 | 35 | ||
36 | CPPMLanguageModel::CPPMnode * CPPMLanguageModel::CPPMnode::add_symbol_to_node(int sym,int *update) | 36 | CPPMLanguageModel::CPPMnode * CPPMLanguageModel::CPPMnode::add_symbol_to_node(int sym,int *update) |
37 | { | 37 | { |
38 | CPPMnode *born,*search; | 38 | CPPMnode *born,*search; |
39 | search=find_symbol(sym); | 39 | search=find_symbol(sym); |
40 | if (!search) { | 40 | if (!search) { |
41 | born = new CPPMnode(sym); | 41 | born = new CPPMnode(sym); |
42 | born->next=child; | 42 | born->next=child; |
43 | child=born; | 43 | child=born; |
44 | // node->count=1; | 44 | // node->count=1; |
45 | return born; | 45 | return born; |
46 | } else { | 46 | } else { |
47 | if (*update) { // perform update exclusions | 47 | if (*update) { // perform update exclusions |
48 | search->count++; | 48 | search->count++; |
49 | *update=0; | 49 | *update=0; |
50 | } | 50 | } |
51 | return search; | 51 | return search; |
52 | } | 52 | } |
53 | 53 | ||
54 | } | 54 | } |
55 | 55 | ||
56 | 56 | ||
57 | ///////////////////////////////////////////////////////////////////// | 57 | ///////////////////////////////////////////////////////////////////// |
58 | // CPPMLanguageModel defs | 58 | // CPPMLanguageModel defs |
59 | ///////////////////////////////////////////////////////////////////// | 59 | ///////////////////////////////////////////////////////////////////// |
60 | 60 | ||
61 | CPPMLanguageModel::CPPMLanguageModel(CAlphabet *_alphabet,int _normalization) | 61 | CPPMLanguageModel::CPPMLanguageModel(CAlphabet *_alphabet,int _normalization) |
62 | : CLanguageModel(_alphabet,_normalization) | 62 | : CLanguageModel(_alphabet,_normalization), root(0), m_rootcontext(0) |
63 | { | 63 | { |
64 | root=new CPPMnode(-1); | 64 | root=new CPPMnode(-1); |
65 | m_rootcontext=new CPPMContext(root,0); | 65 | m_rootcontext=new CPPMContext(root,0); |
66 | } | 66 | } |
67 | 67 | ||
68 | 68 | ||
69 | CPPMLanguageModel::~CPPMLanguageModel() | 69 | CPPMLanguageModel::~CPPMLanguageModel() |
70 | { | 70 | { |
71 | delete m_rootcontext; | ||
71 | delete root; | 72 | delete root; |
72 | } | 73 | } |
73 | 74 | ||
74 | 75 | ||
75 | bool CPPMLanguageModel::GetProbs(CContext *context,vector<unsigned int> &probs,double ) | 76 | bool CPPMLanguageModel::GetProbs(CContext *context,vector<unsigned int> &probs,double ) |
76 | // get the probability distribution at the context | 77 | // get the probability distribution at the context |
77 | { | 78 | { |
78 | // seems like we have to have this hack for VC++ | 79 | // seems like we have to have this hack for VC++ |
79 | CPPMContext *ppmcontext=static_cast<CPPMContext *> (context); | 80 | CPPMContext *ppmcontext=static_cast<CPPMContext *> (context); |
80 | 81 | ||
81 | 82 | ||
82 | int modelchars=GetNumberModelChars(); | 83 | int modelchars=GetNumberModelChars(); |
83 | int norm=CLanguageModel::normalization(); | 84 | int norm=CLanguageModel::normalization(); |
84 | probs.resize(modelchars); | 85 | probs.resize(modelchars); |
85 | CPPMnode *temp,*s; | 86 | CPPMnode *temp,*s; |
86 | int loop,total; | 87 | int loop,total; |
87 | int sym; | 88 | int sym; |
88 | // ulong spent=0; | 89 | // ulong spent=0; |
89 | ulong size_of_slice; | 90 | ulong size_of_slice; |
90 | bool *exclusions=new bool [modelchars]; | 91 | bool *exclusions=new bool [modelchars]; |
91 | ulong uniform=modelchars; | 92 | ulong uniform=modelchars; |
92 | ulong tospend=norm-uniform; | 93 | ulong tospend=norm-uniform; |
93 | temp=ppmcontext->head; | 94 | temp=ppmcontext->head; |
94 | for (loop=0; loop <modelchars; loop++) { /* set up the exclusions array */ | 95 | for (loop=0; loop <modelchars; loop++) { /* set up the exclusions array */ |
95 | probs[loop]=0; | 96 | probs[loop]=0; |
96 | exclusions[loop]=0; | 97 | exclusions[loop]=0; |
97 | } | 98 | } |
98 | while (temp!=0) { | 99 | while (temp!=0) { |
99 | //Usprintf(debug,TEXT("tospend %u\n"),tospend); | 100 | //Usprintf(debug,TEXT("tospend %u\n"),tospend); |
100 | //DebugOutput(TEXT("round\n")); | 101 | //DebugOutput(TEXT("round\n")); |
101 | total=0; | 102 | total=0; |
102 | s=temp->child; | 103 | s=temp->child; |
103 | while (s) { | 104 | while (s) { |
104 | sym=s->symbol; | 105 | sym=s->symbol; |
105 | if (!exclusions[s->symbol]) | 106 | if (!exclusions[s->symbol]) |
106 | total=total+s->count; | 107 | total=total+s->count; |
107 | s=s->next; | 108 | s=s->next; |
108 | } | 109 | } |
109 | if (total) { | 110 | if (total) { |
110 | //Usprintf(debug,TEXT"escape %u\n"),tospend* | 111 | //Usprintf(debug,TEXT"escape %u\n"),tospend* |
111 | size_of_slice=tospend; | 112 | size_of_slice=tospend; |
112 | s=temp->child; | 113 | s=temp->child; |
113 | while (s) { | 114 | while (s) { |
114 | if (!exclusions[s->symbol]) { | 115 | if (!exclusions[s->symbol]) { |
115 | exclusions[s->symbol]=1; | 116 | exclusions[s->symbol]=1; |
116 | ulong p=size_of_slice*(2*s->count-1)/2/ulong(total); | 117 | ulong p=size_of_slice*(2*s->count-1)/2/ulong(total); |
117 | probs[s->symbol]+=p; | 118 | probs[s->symbol]+=p; |
118 | tospend-=p; | 119 | tospend-=p; |
119 | } | 120 | } |
120 | // Usprintf(debug,TEXT("sym %u counts %d p %u tospend %u \n"),sym,s->count,p,tospend); | 121 | // Usprintf(debug,TEXT("sym %u counts %d p %u tospend %u \n"),sym,s->count,p,tospend); |
121 | // DebugOutput(debug); | 122 | // DebugOutput(debug); |
122 | s=s->next; | 123 | s=s->next; |
123 | } | 124 | } |
124 | } | 125 | } |
125 | temp = temp->vine; | 126 | temp = temp->vine; |
126 | } | 127 | } |
127 | //Usprintf(debug,TEXT("Norm %u tospend %u\n"),Norm,tospend); | 128 | //Usprintf(debug,TEXT("Norm %u tospend %u\n"),Norm,tospend); |
128 | //DebugOutput(debug); | 129 | //DebugOutput(debug); |
129 | 130 | ||
130 | size_of_slice=tospend; | 131 | size_of_slice=tospend; |
131 | int symbolsleft=0; | 132 | int symbolsleft=0; |
132 | for (sym=1;sym<modelchars;sym++) | 133 | for (sym=1;sym<modelchars;sym++) |
133 | if (!probs[sym]) | 134 | if (!probs[sym]) |
134 | symbolsleft++; | 135 | symbolsleft++; |
135 | for (sym=1;sym<modelchars;sym++) | 136 | for (sym=1;sym<modelchars;sym++) |
136 | if (!probs[sym]) { | 137 | if (!probs[sym]) { |
137 | ulong p=size_of_slice/symbolsleft; | 138 | ulong p=size_of_slice/symbolsleft; |
138 | probs[sym]+=p; | 139 | probs[sym]+=p; |
139 | tospend-=p; | 140 | tospend-=p; |
140 | } | 141 | } |
141 | 142 | ||
142 | // distribute what's left evenly | 143 | // distribute what's left evenly |
143 | tospend+=uniform; | 144 | tospend+=uniform; |
144 | for (sym=1;sym<modelchars;sym++) { | 145 | for (sym=1;sym<modelchars;sym++) { |
145 | ulong p=tospend/(modelchars-sym); | 146 | ulong p=tospend/(modelchars-sym); |
146 | probs[sym]+=p; | 147 | probs[sym]+=p; |
147 | tospend-=p; | 148 | tospend-=p; |
148 | } | 149 | } |
149 | //Usprintf(debug,TEXT("finaltospend %u\n"),tospend); | 150 | //Usprintf(debug,TEXT("finaltospend %u\n"),tospend); |
150 | //DebugOutput(debug); | 151 | //DebugOutput(debug); |
151 | 152 | ||
152 | // free(exclusions); // !!! | 153 | // free(exclusions); // !!! |
153 | // !!! NB by IAM: p577 Stroustrup 3rd Edition: "Allocating an object using new and deleting it using free() is asking for trouble" | 154 | // !!! NB by IAM: p577 Stroustrup 3rd Edition: "Allocating an object using new and deleting it using free() is asking for trouble" |
154 | delete[] exclusions; | 155 | delete[] exclusions; |
155 | return true; | 156 | return true; |
156 | } | 157 | } |
157 | 158 | ||
158 | 159 | ||
159 | void CPPMLanguageModel::AddSymbol(CPPMLanguageModel::CPPMContext &context,int symbol) | 160 | void CPPMLanguageModel::AddSymbol(CPPMLanguageModel::CPPMContext &context,int symbol) |
160 | // add symbol to the context | 161 | // add symbol to the context |
161 | // creates new nodes, updates counts | 162 | // creates new nodes, updates counts |
162 | // and leaves 'context' at the new context | 163 | // and leaves 'context' at the new context |
163 | { | 164 | { |
164 | // sanity check | 165 | // sanity check |
165 | if (symbol==0 || symbol>=GetNumberModelChars()) | 166 | if (symbol==0 || symbol>=GetNumberModelChars()) |
166 | return; | 167 | return; |
167 | 168 | ||
168 | CPPMnode *vineptr,*temp; | 169 | CPPMnode *vineptr,*temp; |
169 | int updatecnt=1; | 170 | int updatecnt=1; |
170 | 171 | ||
171 | temp=context.head->vine; | 172 | temp=context.head->vine; |
172 | context.head=context.head->add_symbol_to_node(symbol,&updatecnt); | 173 | context.head=context.head->add_symbol_to_node(symbol,&updatecnt); |
173 | vineptr=context.head; | 174 | vineptr=context.head; |
174 | context.order++; | 175 | context.order++; |
175 | 176 | ||
176 | while (temp!=0) { | 177 | while (temp!=0) { |
177 | vineptr->vine=temp->add_symbol_to_node(symbol,&updatecnt); | 178 | vineptr->vine=temp->add_symbol_to_node(symbol,&updatecnt); |
178 | vineptr=vineptr->vine; | 179 | vineptr=vineptr->vine; |
179 | temp=temp->vine; | 180 | temp=temp->vine; |
180 | } | 181 | } |
181 | vineptr->vine=root; | 182 | vineptr->vine=root; |
182 | if (context.order>MAX_ORDER){ | 183 | if (context.order>MAX_ORDER){ |
183 | context.head=context.head->vine; | 184 | context.head=context.head->vine; |
184 | context.order--; | 185 | context.order--; |
185 | } | 186 | } |
186 | } | 187 | } |
187 | 188 | ||
188 | 189 | ||
189 | // update context with symbol 'Symbol' | 190 | // update context with symbol 'Symbol' |
190 | void CPPMLanguageModel::EnterSymbol(CContext* Context, modelchar Symbol) | 191 | void CPPMLanguageModel::EnterSymbol(CContext* Context, modelchar Symbol) |
191 | { | 192 | { |
192 | CPPMLanguageModel::CPPMContext& context = * static_cast<CPPMContext *> (Context); | 193 | CPPMLanguageModel::CPPMContext& context = * static_cast<CPPMContext *> (Context); |
193 | 194 | ||
194 | CPPMnode *find; | 195 | CPPMnode *find; |
195 | // CPPMnode *temp=context.head; | 196 | // CPPMnode *temp=context.head; |
196 | 197 | ||
197 | while (context.head) { | 198 | while (context.head) { |
198 | find =context.head->find_symbol(Symbol); | 199 | find =context.head->find_symbol(Symbol); |
199 | if (find) { | 200 | if (find) { |
200 | context.order++; | 201 | context.order++; |
201 | context.head=find; | 202 | context.head=find; |
202 | //Usprintf(debug,TEXT("found context %x order %d\n"),head,order); | 203 | //Usprintf(debug,TEXT("found context %x order %d\n"),head,order); |
203 | //DebugOutput(debug); | 204 | //DebugOutput(debug); |
204 | return; | 205 | return; |
205 | } | 206 | } |
206 | context.order--; | 207 | context.order--; |
207 | context.head=context.head->vine; | 208 | context.head=context.head->vine; |
208 | } | 209 | } |
209 | 210 | ||
210 | if (context.head==0) { | 211 | if (context.head==0) { |
211 | context.head=root; | 212 | context.head=root; |
212 | context.order=0; | 213 | context.order=0; |
213 | } | 214 | } |
214 | 215 | ||
215 | } | 216 | } |
216 | 217 | ||
217 | 218 | ||
218 | void CPPMLanguageModel::LearnSymbol(CContext* Context, modelchar Symbol) | 219 | void CPPMLanguageModel::LearnSymbol(CContext* Context, modelchar Symbol) |
219 | { | 220 | { |
220 | CPPMLanguageModel::CPPMContext& context = * static_cast<CPPMContext *> (Context); | 221 | CPPMLanguageModel::CPPMContext& context = * static_cast<CPPMContext *> (Context); |
221 | AddSymbol(context, Symbol); | 222 | AddSymbol(context, Symbol); |
222 | } | 223 | } |
223 | 224 | ||
224 | 225 | ||
225 | void CPPMLanguageModel::dumpSymbol(int symbol) | 226 | void CPPMLanguageModel::dumpSymbol(int symbol) |
226 | { | 227 | { |
227 | if ((symbol <= 32) || (symbol >= 127)) | 228 | if ((symbol <= 32) || (symbol >= 127)) |
228 | printf( "<%d>", symbol ); | 229 | printf( "<%d>", symbol ); |
229 | else | 230 | else |
230 | printf( "%c", symbol ); | 231 | printf( "%c", symbol ); |
231 | } | 232 | } |
232 | 233 | ||
233 | 234 | ||
234 | void CPPMLanguageModel::dumpString( char *str, int pos, int len ) | 235 | void CPPMLanguageModel::dumpString( char *str, int pos, int len ) |
235 | // Dump the string STR starting at position POS | 236 | // Dump the string STR starting at position POS |
236 | { | 237 | { |
237 | char cc; | 238 | char cc; |
238 | int p; | 239 | int p; |
239 | for (p = pos; p<pos+len; p++) { | 240 | for (p = pos; p<pos+len; p++) { |
240 | cc = str [p]; | 241 | cc = str [p]; |
241 | if ((cc <= 31) || (cc >= 127)) | 242 | if ((cc <= 31) || (cc >= 127)) |
242 | printf( "<%d>", cc ); | 243 | printf( "<%d>", cc ); |
243 | else | 244 | else |
244 | printf( "%c", cc ); | 245 | printf( "%c", cc ); |
245 | } | 246 | } |
246 | } | 247 | } |
247 | 248 | ||
248 | 249 | ||
249 | void CPPMLanguageModel::dumpTrie( CPPMLanguageModel::CPPMnode *, int ) | 250 | void CPPMLanguageModel::dumpTrie( CPPMLanguageModel::CPPMnode *, int ) |
250 | // diagnostic display of the PPM trie from node t and deeper | 251 | // diagnostic display of the PPM trie from node t and deeper |
251 | { | 252 | { |
252 | //TODO | 253 | //TODO |
253 | /* | 254 | /* |
254 | dchar debug[256]; | 255 | dchar debug[256]; |
255 | int sym; | 256 | int sym; |
256 | CPPMnode *s; | 257 | CPPMnode *s; |
257 | Usprintf( debug,TEXT("%5d %7x "), d, t ); | 258 | Usprintf( debug,TEXT("%5d %7x "), d, t ); |
258 | //TODO: Uncomment this when headers sort out | 259 | //TODO: Uncomment this when headers sort out |
259 | //DebugOutput(debug); | 260 | //DebugOutput(debug); |
260 | if (t < 0) // pointer to input | 261 | if (t < 0) // pointer to input |
261 | printf( " <" ); | 262 | printf( " <" ); |
262 | else { | 263 | else { |
263 | Usprintf(debug,TEXT( " %3d %5d %7x %7x %7x <"), t->symbol,t->count, t->vine, t->child, t->next ); | 264 | Usprintf(debug,TEXT( " %3d %5d %7x %7x %7x <"), t->symbol,t->count, t->vine, t->child, t->next ); |
264 | //TODO: Uncomment this when headers sort out | 265 | //TODO: Uncomment this when headers sort out |
265 | //DebugOutput(debug); | 266 | //DebugOutput(debug); |
266 | } | 267 | } |
267 | 268 | ||
268 | dumpString( dumpTrieStr, 0, d ); | 269 | dumpString( dumpTrieStr, 0, d ); |
269 | Usprintf( debug,TEXT(">\n") ); | 270 | Usprintf( debug,TEXT(">\n") ); |
270 | //TODO: Uncomment this when headers sort out | 271 | //TODO: Uncomment this when headers sort out |
271 | //DebugOutput(debug); | 272 | //DebugOutput(debug); |
272 | if (t != 0) { | 273 | if (t != 0) { |
273 | s = t->child; | 274 | s = t->child; |
274 | while (s != 0) { | 275 | while (s != 0) { |
275 | sym =s->symbol; | 276 | sym =s->symbol; |
276 | 277 | ||
277 | dumpTrieStr [d] = sym; | 278 | dumpTrieStr [d] = sym; |
278 | dumpTrie( s, d+1 ); | 279 | dumpTrie( s, d+1 ); |
279 | s = s->next; | 280 | s = s->next; |
280 | } | 281 | } |
281 | } | 282 | } |
282 | */ | 283 | */ |
283 | } | 284 | } |
284 | 285 | ||
285 | 286 | ||
286 | void CPPMLanguageModel::dump() | 287 | void CPPMLanguageModel::dump() |
287 | // diagnostic display of the whole PPM trie | 288 | // diagnostic display of the whole PPM trie |
288 | { | 289 | { |
289 | // TODO: | 290 | // TODO: |
290 | /* | 291 | /* |
291 | dchar debug[256]; | 292 | dchar debug[256]; |
292 | Usprintf(debug,TEXT( "Dump of Trie : \n" )); | 293 | Usprintf(debug,TEXT( "Dump of Trie : \n" )); |
293 | //TODO: Uncomment this when headers sort out | 294 | //TODO: Uncomment this when headers sort out |
294 | //DebugOutput(debug); | 295 | //DebugOutput(debug); |
295 | Usprintf(debug,TEXT( "---------------\n" )); | 296 | Usprintf(debug,TEXT( "---------------\n" )); |
296 | //TODO: Uncomment this when headers sort out | 297 | //TODO: Uncomment this when headers sort out |
297 | //DebugOutput(debug); | 298 | //DebugOutput(debug); |
298 | Usprintf( debug,TEXT( "depth node symbol count vine child next context\n") ); | 299 | Usprintf( debug,TEXT( "depth node symbol count vine child next context\n") ); |
299 | //TODO: Uncomment this when headers sort out | 300 | //TODO: Uncomment this when headers sort out |
300 | //DebugOutput(debug); | 301 | //DebugOutput(debug); |
301 | dumpTrie( root, 0 ); | 302 | dumpTrie( root, 0 ); |
302 | Usprintf( debug,TEXT( "---------------\n" )); | 303 | Usprintf( debug,TEXT( "---------------\n" )); |
303 | //TODO: Uncomment this when headers sort out | 304 | //TODO: Uncomment this when headers sort out |
304 | //DebugOutput(debug); | 305 | //DebugOutput(debug); |
305 | Usprintf(debug,TEXT( "\n" )); | 306 | Usprintf(debug,TEXT( "\n" )); |
306 | //TODO: Uncomment this when headers sort out | 307 | //TODO: Uncomment this when headers sort out |
307 | //DebugOutput(debug); | 308 | //DebugOutput(debug); |
308 | */ | 309 | */ |
309 | } | 310 | } |
diff --git a/noncore/apps/opie-reader/Bkmks.cpp b/noncore/apps/opie-reader/Bkmks.cpp index 440d8be..28f6318 100644 --- a/noncore/apps/opie-reader/Bkmks.cpp +++ b/noncore/apps/opie-reader/Bkmks.cpp | |||
@@ -1,278 +1,294 @@ | |||
1 | #include <qmessagebox.h> | 1 | #include <qmessagebox.h> |
2 | 2 | ||
3 | #include "Bkmks.h" | 3 | #include "Bkmks.h" |
4 | 4 | ||
5 | #include "StyleConsts.h" | 5 | #include "StyleConsts.h" |
6 | #include "Markups.h" | 6 | #include "Markups.h" |
7 | #include "my_list.h" | 7 | #include "my_list.h" |
8 | #include "version.h" | 8 | #include "version.h" |
9 | #include "names.h" | 9 | #include "names.h" |
10 | 10 | ||
11 | const unsigned long BkmkFile::magic = ((unsigned long)'q' << 24) | ((unsigned long)'t' << 16) | ((unsigned long)'r' << 8) | ((unsigned long)BKMKTYPE); | 11 | const unsigned long BkmkFile::magic = ((unsigned long)'q' << 24) | ((unsigned long)'t' << 16) | ((unsigned long)'r' << 8) | ((unsigned long)BKMKTYPE); |
12 | 12 | ||
13 | Bkmk::Bkmk(const unsigned char* _nm, unsigned short _nmlen, const unsigned char* _anno, unsigned short _annolen, unsigned int _p) | 13 | Bkmk::Bkmk(const unsigned char* _nm, unsigned short _nmlen, const unsigned char* _anno, unsigned short _annolen, unsigned int _p) : |
14 | m_name(0), | ||
15 | m_namelen(0), | ||
16 | m_anno(0), | ||
17 | m_annolen(0), | ||
18 | m_position(0) | ||
14 | { | 19 | { |
15 | init(_nm, _nmlen, _anno, _annolen, _p); | 20 | init(_nm, _nmlen, _anno, _annolen, _p); |
16 | } | 21 | } |
17 | 22 | ||
18 | Bkmk::Bkmk(const tchar* _nm, const unsigned char* _anno, unsigned short annolen, unsigned int _p) : m_position(_p) | 23 | Bkmk::Bkmk(const tchar* _nm, const unsigned char* _anno, unsigned short annolen, unsigned int _p) : m_position(_p) |
19 | { | 24 | { |
20 | init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), _anno, annolen, _p); | 25 | init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), _anno, annolen, _p); |
21 | } | 26 | } |
22 | 27 | ||
28 | Bkmk::Bkmk(const Bkmk& rhs) : | ||
29 | m_name(0), | ||
30 | m_namelen(0), | ||
31 | m_anno(0), | ||
32 | m_annolen(0), | ||
33 | m_position(0) | ||
34 | { | ||
35 | init(rhs.name(), sizeof(tchar)*(ustrlen(rhs.name())+1), rhs.anno(), | ||
36 | sizeof(tchar)*(ustrlen(rhs.anno())+1), rhs.value()); | ||
37 | } | ||
38 | |||
23 | Bkmk::Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p) : m_position(_p) | 39 | Bkmk::Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p) : m_position(_p) |
24 | { | 40 | { |
25 | if (_anno == NULL) | 41 | if (_anno == NULL) |
26 | { | 42 | { |
27 | tchar t = 0; | 43 | tchar t = 0; |
28 | init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), &t, sizeof(t), _p); | 44 | init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), &t, sizeof(t), _p); |
29 | } | 45 | } |
30 | else | 46 | else |
31 | { | 47 | { |
32 | init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), _anno, sizeof(tchar)*(ustrlen(_anno)+1), _p); | 48 | init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), _anno, sizeof(tchar)*(ustrlen(_anno)+1), _p); |
33 | } | 49 | } |
34 | } | 50 | } |
35 | 51 | ||
36 | Bkmk::Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p, unsigned int _p2) : m_position(_p) | 52 | Bkmk::Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p, unsigned int _p2) : m_position(_p) |
37 | { | 53 | { |
38 | if (_anno == NULL) | 54 | if (_anno == NULL) |
39 | { | 55 | { |
40 | tchar t = 0; | 56 | tchar t = 0; |
41 | init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), &t, sizeof(t), _p); | 57 | init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), &t, sizeof(t), _p); |
42 | } | 58 | } |
43 | else | 59 | else |
44 | { | 60 | { |
45 | init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), _anno, sizeof(tchar)*(ustrlen(_anno)+1), _p); | 61 | init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), _anno, sizeof(tchar)*(ustrlen(_anno)+1), _p); |
46 | } | 62 | } |
47 | m_position2 = _p2; | 63 | m_position2 = _p2; |
48 | m_red = m_green = m_blue = 127; | 64 | m_red = m_green = m_blue = 127; |
49 | } | 65 | } |
50 | 66 | ||
51 | void Bkmk::init(const void* _nm, unsigned short _nmlen, const void* _anno, unsigned short _annolen, unsigned int _p) | 67 | void Bkmk::init(const void* _nm, unsigned short _nmlen, const void* _anno, unsigned short _annolen, unsigned int _p) |
52 | { | 68 | { |
53 | m_namelen = _nmlen; | 69 | m_namelen = _nmlen; |
54 | if (m_namelen > 0) | 70 | if (m_namelen > 0) |
55 | { | 71 | { |
56 | m_name = new unsigned char[m_namelen]; | 72 | m_name = new unsigned char[m_namelen]; |
57 | memcpy(m_name, _nm, m_namelen); | 73 | memcpy(m_name, _nm, m_namelen); |
58 | } | 74 | } |
59 | else | 75 | else |
60 | { | 76 | { |
61 | m_name = NULL; | 77 | m_name = NULL; |
62 | } | 78 | } |
63 | 79 | ||
64 | m_annolen = _annolen; | 80 | m_annolen = _annolen; |
65 | if (m_annolen > 0) | 81 | if (m_annolen > 0) |
66 | { | 82 | { |
67 | m_anno = new unsigned char[m_annolen]; | 83 | m_anno = new unsigned char[m_annolen]; |
68 | memcpy(m_anno, _anno, m_annolen); | 84 | memcpy(m_anno, _anno, m_annolen); |
69 | } | 85 | } |
70 | else | 86 | else |
71 | { | 87 | { |
72 | m_anno = NULL; | 88 | m_anno = NULL; |
73 | } | 89 | } |
74 | m_position = _p; | 90 | m_position = _p; |
75 | m_position2 = _p; | 91 | m_position2 = _p; |
76 | m_red = m_green = m_blue = 255; | 92 | m_red = m_green = m_blue = 255; |
77 | m_level = 0; | 93 | m_level = 0; |
78 | } | 94 | } |
79 | 95 | ||
80 | Bkmk::~Bkmk() | 96 | Bkmk::~Bkmk() |
81 | { | 97 | { |
82 | if (m_name != NULL) delete [] m_name; | 98 | if (m_name != NULL) delete [] m_name; |
83 | m_name = NULL; | 99 | m_name = NULL; |
84 | if (m_anno != NULL) delete [] m_anno; | 100 | if (m_anno != NULL) delete [] m_anno; |
85 | m_anno = NULL; | 101 | m_anno = NULL; |
86 | } | 102 | } |
87 | 103 | ||
88 | Bkmk& Bkmk::operator=(const Bkmk& rhs) | 104 | Bkmk& Bkmk::operator=(const Bkmk& rhs) |
89 | { | 105 | { |
90 | if (m_name != NULL) | 106 | if (m_name != NULL) |
91 | { | 107 | { |
92 | delete [] m_name; | 108 | delete [] m_name; |
93 | m_name = NULL; | 109 | m_name = NULL; |
94 | } | 110 | } |
95 | if (m_anno != NULL) | 111 | if (m_anno != NULL) |
96 | { | 112 | { |
97 | delete [] m_anno; | 113 | delete [] m_anno; |
98 | m_anno = NULL; | 114 | m_anno = NULL; |
99 | } | 115 | } |
100 | if (rhs.m_name != NULL) | 116 | if (rhs.m_name != NULL) |
101 | { | 117 | { |
102 | m_namelen = rhs.m_namelen; | 118 | m_namelen = rhs.m_namelen; |
103 | m_name = new unsigned char[m_namelen]; | 119 | m_name = new unsigned char[m_namelen]; |
104 | memcpy(m_name, rhs.m_name, m_namelen); | 120 | memcpy(m_name, rhs.m_name, m_namelen); |
105 | } | 121 | } |
106 | else | 122 | else |
107 | m_name = NULL; | 123 | m_name = NULL; |
108 | if (rhs.m_anno != NULL) | 124 | if (rhs.m_anno != NULL) |
109 | { | 125 | { |
110 | m_annolen = rhs.m_annolen; | 126 | m_annolen = rhs.m_annolen; |
111 | m_anno = new unsigned char[m_annolen]; | 127 | m_anno = new unsigned char[m_annolen]; |
112 | memcpy(m_anno, rhs.m_anno, m_annolen); | 128 | memcpy(m_anno, rhs.m_anno, m_annolen); |
113 | } | 129 | } |
114 | else | 130 | else |
115 | m_anno = NULL; | 131 | m_anno = NULL; |
116 | m_position = rhs.m_position; | 132 | m_position = rhs.m_position; |
117 | m_position2 = rhs.m_position2; | 133 | m_position2 = rhs.m_position2; |
118 | m_red = rhs.m_red; | 134 | m_red = rhs.m_red; |
119 | m_green = rhs.m_green; | 135 | m_green = rhs.m_green; |
120 | m_blue = rhs.m_blue; | 136 | m_blue = rhs.m_blue; |
121 | m_level = rhs.m_level; | 137 | m_level = rhs.m_level; |
122 | return *this; | 138 | return *this; |
123 | } | 139 | } |
124 | 140 | ||
125 | bool Bkmk::operator==(const Bkmk& rhs) | 141 | bool Bkmk::operator==(const Bkmk& rhs) |
126 | { | 142 | { |
127 | return ((m_position == rhs.m_position) && (m_position2 == rhs.m_position2) && (rhs.m_namelen == m_namelen) && memcmp(m_name,rhs.m_name,m_namelen) == 0); | 143 | return ((m_position == rhs.m_position) && (m_position2 == rhs.m_position2) && (rhs.m_namelen == m_namelen) && memcmp(m_name,rhs.m_name,m_namelen) == 0); |
128 | } | 144 | } |
129 | 145 | ||
130 | void Bkmk::setAnno(unsigned char* t, unsigned short len) | 146 | void Bkmk::setAnno(unsigned char* t, unsigned short len) |
131 | { | 147 | { |
132 | if (m_anno != NULL) | 148 | if (m_anno != NULL) |
133 | { | 149 | { |
134 | delete [] m_anno; | 150 | delete [] m_anno; |
135 | m_anno = NULL; | 151 | m_anno = NULL; |
136 | } | 152 | } |
137 | if (t != NULL) | 153 | if (t != NULL) |
138 | { | 154 | { |
139 | m_annolen = len; | 155 | m_annolen = len; |
140 | m_anno = new unsigned char[m_annolen]; | 156 | m_anno = new unsigned char[m_annolen]; |
141 | memcpy(m_anno, t, m_annolen); | 157 | memcpy(m_anno, t, m_annolen); |
142 | } | 158 | } |
143 | else | 159 | else |
144 | { | 160 | { |
145 | m_annolen = sizeof(tchar); | 161 | m_annolen = sizeof(tchar); |
146 | m_anno = new unsigned char[m_annolen]; | 162 | m_anno = new unsigned char[m_annolen]; |
147 | *((tchar*)m_anno) = 0; | 163 | *((tchar*)m_anno) = 0; |
148 | } | 164 | } |
149 | } | 165 | } |
150 | 166 | ||
151 | void Bkmk::setAnno(tchar* t) | 167 | void Bkmk::setAnno(tchar* t) |
152 | { | 168 | { |
153 | if (m_anno != NULL) | 169 | if (m_anno != NULL) |
154 | { | 170 | { |
155 | delete [] m_anno; | 171 | delete [] m_anno; |
156 | m_anno = NULL; | 172 | m_anno = NULL; |
157 | } | 173 | } |
158 | if (t != NULL) | 174 | if (t != NULL) |
159 | { | 175 | { |
160 | unsigned short len = ustrlen(t)+1; | 176 | unsigned short len = ustrlen(t)+1; |
161 | m_annolen = sizeof(tchar)*len; | 177 | m_annolen = sizeof(tchar)*len; |
162 | m_anno = new unsigned char[m_annolen]; | 178 | m_anno = new unsigned char[m_annolen]; |
163 | memcpy(m_anno, t, m_annolen); | 179 | memcpy(m_anno, t, m_annolen); |
164 | } | 180 | } |
165 | else | 181 | else |
166 | { | 182 | { |
167 | m_annolen = sizeof(tchar); | 183 | m_annolen = sizeof(tchar); |
168 | m_anno = new unsigned char[m_annolen]; | 184 | m_anno = new unsigned char[m_annolen]; |
169 | *((tchar*)m_anno) = 0; | 185 | *((tchar*)m_anno) = 0; |
170 | } | 186 | } |
171 | } | 187 | } |
172 | 188 | ||
173 | BkmkFile::BkmkFile(const char *fnm, bool w, bool _x) | 189 | BkmkFile::BkmkFile(const char *fnm, bool w, bool _x) |
174 | : | 190 | : |
175 | wt(w), isUpgraded(false), m_extras(_x) | 191 | wt(w), isUpgraded(false), m_extras(_x) |
176 | { | 192 | { |
177 | if (w) | 193 | if (w) |
178 | { | 194 | { |
179 | f = fopen(fnm, "wb"); | 195 | f = fopen(fnm, "wb"); |
180 | } | 196 | } |
181 | else | 197 | else |
182 | { | 198 | { |
183 | f = fopen(fnm, "rb"); | 199 | f = fopen(fnm, "rb"); |
184 | } | 200 | } |
185 | } | 201 | } |
186 | 202 | ||
187 | BkmkFile::~BkmkFile() | 203 | BkmkFile::~BkmkFile() |
188 | { | 204 | { |
189 | if (f != NULL) fclose(f); | 205 | if (f != NULL) fclose(f); |
190 | } | 206 | } |
191 | 207 | ||
192 | void BkmkFile::write(const Bkmk& b) | 208 | void BkmkFile::write(const Bkmk& b) |
193 | { | 209 | { |
194 | if (f != NULL) | 210 | if (f != NULL) |
195 | { | 211 | { |
196 | fwrite(&b.m_namelen, sizeof(b.m_namelen),1,f); | 212 | fwrite(&b.m_namelen, sizeof(b.m_namelen),1,f); |
197 | fwrite(b.m_name,1,b.m_namelen,f); | 213 | fwrite(b.m_name,1,b.m_namelen,f); |
198 | fwrite(&b.m_annolen, sizeof(b.m_annolen),1,f); | 214 | fwrite(&b.m_annolen, sizeof(b.m_annolen),1,f); |
199 | fwrite(b.m_anno,1,b.m_annolen,f); | 215 | fwrite(b.m_anno,1,b.m_annolen,f); |
200 | fwrite(&b.m_position,sizeof(b.m_position),1,f); | 216 | fwrite(&b.m_position,sizeof(b.m_position),1,f); |
201 | if (m_extras) | 217 | if (m_extras) |
202 | { | 218 | { |
203 | fwrite(&b.m_position2,sizeof(b.m_position2),1,f); | 219 | fwrite(&b.m_position2,sizeof(b.m_position2),1,f); |
204 | fwrite(&b.m_red,sizeof(b.m_red),1,f); | 220 | fwrite(&b.m_red,sizeof(b.m_red),1,f); |
205 | fwrite(&b.m_green,sizeof(b.m_green),1,f); | 221 | fwrite(&b.m_green,sizeof(b.m_green),1,f); |
206 | fwrite(&b.m_blue,sizeof(b.m_blue),1,f); | 222 | fwrite(&b.m_blue,sizeof(b.m_blue),1,f); |
207 | fwrite(&b.m_level,sizeof(b.m_level),1,f); | 223 | fwrite(&b.m_level,sizeof(b.m_level),1,f); |
208 | } | 224 | } |
209 | } | 225 | } |
210 | } | 226 | } |
211 | 227 | ||
212 | void BkmkFile::write(CList<Bkmk>& bl) | 228 | void BkmkFile::write(CList<Bkmk>& bl) |
213 | { | 229 | { |
214 | if (f != NULL) | 230 | if (f != NULL) |
215 | { | 231 | { |
216 | fwrite(&magic, sizeof(magic), 1, f); | 232 | fwrite(&magic, sizeof(magic), 1, f); |
217 | for (CList<Bkmk>::iterator i = bl.begin(); i != bl.end(); i++) | 233 | for (CList<Bkmk>::iterator i = bl.begin(); i != bl.end(); i++) |
218 | { | 234 | { |
219 | write(*i); | 235 | write(*i); |
220 | } | 236 | } |
221 | } | 237 | } |
222 | } | 238 | } |
223 | 239 | ||
224 | CList<Bkmk>* BkmkFile::readall() | 240 | CList<Bkmk>* BkmkFile::readall() |
225 | { | 241 | { |
226 | CList<Bkmk>* bl = NULL; | 242 | CList<Bkmk>* bl = NULL; |
227 | if (f != NULL) | 243 | if (f != NULL) |
228 | { | 244 | { |
229 | unsigned long newmagic; | 245 | unsigned long newmagic; |
230 | fread(&newmagic, sizeof(newmagic), 1, f); | 246 | fread(&newmagic, sizeof(newmagic), 1, f); |
231 | if ((newmagic & 0xffffff00) != (magic & 0xffffff00)) | 247 | if ((newmagic & 0xffffff00) != (magic & 0xffffff00)) |
232 | { | 248 | { |
233 | if (QMessageBox::warning(NULL, "Old bookmark file!", "Which version of " PROGNAME "\ndid you upgrade from?", "0_4*", "Any other version") == 0) | 249 | if (QMessageBox::warning(NULL, "Old bookmark file!", "Which version of " PROGNAME "\ndid you upgrade from?", "0_4*", "Any other version") == 0) |
234 | { | 250 | { |
235 | fseek(f,0,SEEK_SET); | 251 | fseek(f,0,SEEK_SET); |
236 | bl = readall00(&read05); | 252 | bl = readall00(&read05); |
237 | } | 253 | } |
238 | else | 254 | else |
239 | { | 255 | { |
240 | fseek(f,0,SEEK_SET); | 256 | fseek(f,0,SEEK_SET); |
241 | bl = readall00(&read03); | 257 | bl = readall00(&read03); |
242 | } | 258 | } |
243 | isUpgraded = true; | 259 | isUpgraded = true; |
244 | } | 260 | } |
245 | else | 261 | else |
246 | { | 262 | { |
247 | switch(newmagic & 0xff) | 263 | switch(newmagic & 0xff) |
248 | { | 264 | { |
249 | case 7: | 265 | case 7: |
250 | isUpgraded = false; | 266 | isUpgraded = false; |
251 | bl = readall00(read07); | 267 | bl = readall00(read07); |
252 | // qDebug("Correct version!"); | 268 | // qDebug("Correct version!"); |
253 | break; | 269 | break; |
254 | case 6: | 270 | case 6: |
255 | isUpgraded = true; | 271 | isUpgraded = true; |
256 | bl = readall00(read06); | 272 | bl = readall00(read06); |
257 | // qDebug("Correct version!"); | 273 | // qDebug("Correct version!"); |
258 | break; | 274 | break; |
259 | case 5: | 275 | case 5: |
260 | isUpgraded = true; | 276 | isUpgraded = true; |
261 | bl = readall00(read05); | 277 | bl = readall00(read05); |
262 | // qDebug("Known version!"); | 278 | // qDebug("Known version!"); |
263 | break; | 279 | break; |
264 | default: | 280 | default: |
265 | // qDebug("Unknown version!"); | 281 | // qDebug("Unknown version!"); |
266 | isUpgraded = true; | 282 | isUpgraded = true; |
267 | bl = readall00(read05); | 283 | bl = readall00(read05); |
268 | } | 284 | } |
269 | } | 285 | } |
270 | } | 286 | } |
271 | return bl; | 287 | return bl; |
272 | } | 288 | } |
273 | 289 | ||
274 | CList<Bkmk>* BkmkFile::readall00(Bkmk* (*readfn)(BkmkFile*, FILE*)) | 290 | CList<Bkmk>* BkmkFile::readall00(Bkmk* (*readfn)(BkmkFile*, FILE*)) |
275 | { | 291 | { |
276 | CList<Bkmk>* bl = new CList<Bkmk>; | 292 | CList<Bkmk>* bl = new CList<Bkmk>; |
277 | while (1) | 293 | while (1) |
278 | { | 294 | { |
diff --git a/noncore/apps/opie-reader/Bkmks.h b/noncore/apps/opie-reader/Bkmks.h index c2275e2..985e158 100644 --- a/noncore/apps/opie-reader/Bkmks.h +++ b/noncore/apps/opie-reader/Bkmks.h | |||
@@ -1,84 +1,81 @@ | |||
1 | #ifndef __Bkmks_h | 1 | #ifndef __Bkmks_h |
2 | #define __Bkmks_h | 2 | #define __Bkmks_h |
3 | 3 | ||
4 | #include "config.h" | 4 | #include "config.h" |
5 | #include "Filedata.h" | 5 | #include "Filedata.h" |
6 | #include <stdio.h> | 6 | #include <stdio.h> |
7 | 7 | ||
8 | template<class T> | 8 | template<class T> |
9 | class CList; | 9 | class CList; |
10 | 10 | ||
11 | class Bkmk | 11 | class Bkmk |
12 | { | 12 | { |
13 | friend class BkmkFile; | 13 | friend class BkmkFile; |
14 | unsigned char* m_name; | 14 | unsigned char* m_name; |
15 | unsigned short m_namelen; | 15 | unsigned short m_namelen; |
16 | unsigned char* m_anno; | 16 | unsigned char* m_anno; |
17 | unsigned short m_annolen; | 17 | unsigned short m_annolen; |
18 | unsigned int m_position; | 18 | unsigned int m_position; |
19 | unsigned int m_position2; | 19 | unsigned int m_position2; |
20 | unsigned char m_red,m_green,m_blue, m_level; | 20 | unsigned char m_red,m_green,m_blue, m_level; |
21 | void init(const void*, unsigned short, const void*, unsigned short, unsigned int); | 21 | void init(const void*, unsigned short, const void*, unsigned short, unsigned int); |
22 | public: | 22 | public: |
23 | Bkmk() : m_name(NULL), m_namelen(0), m_anno(NULL), m_annolen(0), m_position(0) {}; | 23 | Bkmk() : m_name(0), m_namelen(0), m_anno(0), m_annolen(0), m_position(0) {}; |
24 | Bkmk(const unsigned char* _nm, unsigned short _nmlen, const unsigned char* _anno, unsigned short _annolen, unsigned int _p); | 24 | Bkmk(const unsigned char* _nm, unsigned short _nmlen, const unsigned char* _anno, unsigned short _annolen, unsigned int _p); |
25 | Bkmk(const tchar* _nm, const unsigned char* _anno, unsigned short _annolen, unsigned int _p); | 25 | Bkmk(const tchar* _nm, const unsigned char* _anno, unsigned short _annolen, unsigned int _p); |
26 | Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p); | 26 | Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p); |
27 | Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p, unsigned int _p2); | 27 | Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p, unsigned int _p2); |
28 | Bkmk(const Bkmk& rhs) : m_name(NULL), m_anno(NULL) | 28 | Bkmk(const Bkmk& rhs); |
29 | { | ||
30 | *this = rhs; | ||
31 | } | ||
32 | ~Bkmk(); | 29 | ~Bkmk(); |
33 | unsigned int value() const { return m_position; } | 30 | unsigned int value() const { return m_position; } |
34 | void value(unsigned int _v) { m_position = _v; } | 31 | void value(unsigned int _v) { m_position = _v; } |
35 | unsigned int value2() const { return m_position2; } | 32 | unsigned int value2() const { return m_position2; } |
36 | void value2(unsigned int _v) { m_position2 = _v; } | 33 | void value2(unsigned int _v) { m_position2 = _v; } |
37 | unsigned char red() { return m_red; } | 34 | unsigned char red() { return m_red; } |
38 | unsigned char green() { return m_green; } | 35 | unsigned char green() { return m_green; } |
39 | unsigned char blue() { return m_blue; } | 36 | unsigned char blue() { return m_blue; } |
40 | void red(unsigned char _v) { m_red = _v; } | 37 | void red(unsigned char _v) { m_red = _v; } |
41 | void green(unsigned char _v) { m_green = _v; } | 38 | void green(unsigned char _v) { m_green = _v; } |
42 | void blue(unsigned char _v) { m_blue = _v; } | 39 | void blue(unsigned char _v) { m_blue = _v; } |
43 | unsigned char level() { return m_level; } | 40 | unsigned char level() { return m_level; } |
44 | void level(unsigned char _v) { m_level = _v; } | 41 | void level(unsigned char _v) { m_level = _v; } |
45 | tchar *name() const { return (tchar*)m_name; } | 42 | tchar *name() const { return (tchar*)m_name; } |
46 | tchar *anno() const { return (tchar*)m_anno; } | 43 | tchar *anno() const { return (tchar*)m_anno; } |
47 | bool operator<(const Bkmk& rhs) { return (m_position < rhs.m_position); } | 44 | bool operator<(const Bkmk& rhs) { return (m_position < rhs.m_position); } |
48 | Bkmk& operator=(const Bkmk& rhs); | 45 | Bkmk& operator=(const Bkmk& rhs); |
49 | bool operator==(const Bkmk& rhs); | 46 | bool operator==(const Bkmk& rhs); |
50 | void setAnno(tchar* t); | 47 | void setAnno(tchar* t); |
51 | void setAnno(unsigned char* t, unsigned short len); | 48 | void setAnno(unsigned char* t, unsigned short len); |
52 | unsigned char* filedata() | 49 | unsigned char* filedata() |
53 | { | 50 | { |
54 | CFiledata fd(anno()); | 51 | CFiledata fd(anno()); |
55 | return m_anno+fd.length(); | 52 | return m_anno+fd.length(); |
56 | } | 53 | } |
57 | unsigned short filedatalen() | 54 | unsigned short filedatalen() |
58 | { | 55 | { |
59 | CFiledata fd(anno()); | 56 | CFiledata fd(anno()); |
60 | return m_annolen - fd.length(); | 57 | return m_annolen - fd.length(); |
61 | } | 58 | } |
62 | }; | 59 | }; |
63 | 60 | ||
64 | class BkmkFile | 61 | class BkmkFile |
65 | { | 62 | { |
66 | FILE* f; | 63 | FILE* f; |
67 | bool wt; | 64 | bool wt; |
68 | bool isUpgraded, m_extras; | 65 | bool isUpgraded, m_extras; |
69 | static const unsigned long magic; | 66 | static const unsigned long magic; |
70 | private: | 67 | private: |
71 | static Bkmk* read07(BkmkFile*, FILE*); | 68 | static Bkmk* read07(BkmkFile*, FILE*); |
72 | static Bkmk* read06(BkmkFile*, FILE*); | 69 | static Bkmk* read06(BkmkFile*, FILE*); |
73 | static Bkmk* read05(BkmkFile*, FILE*); | 70 | static Bkmk* read05(BkmkFile*, FILE*); |
74 | static Bkmk* read03(BkmkFile*, FILE*); | 71 | static Bkmk* read03(BkmkFile*, FILE*); |
75 | CList<Bkmk>* readall00(Bkmk*(*fn)(BkmkFile*, FILE*)); | 72 | CList<Bkmk>* readall00(Bkmk*(*fn)(BkmkFile*, FILE*)); |
76 | void write(const Bkmk& b); | 73 | void write(const Bkmk& b); |
77 | public: | 74 | public: |
78 | bool upgraded() { return isUpgraded; } | 75 | bool upgraded() { return isUpgraded; } |
79 | BkmkFile(const char *fnm, bool w, bool _x); | 76 | BkmkFile(const char *fnm, bool w, bool _x); |
80 | ~BkmkFile(); | 77 | ~BkmkFile(); |
81 | void write(CList<Bkmk>& bl); | 78 | void write(CList<Bkmk>& bl); |
82 | CList<Bkmk>* readall(); | 79 | CList<Bkmk>* readall(); |
83 | }; | 80 | }; |
84 | #endif | 81 | #endif |
diff --git a/noncore/apps/opie-reader/StyleConsts.cpp b/noncore/apps/opie-reader/StyleConsts.cpp index 77c9d3b..c19fa3d 100644 --- a/noncore/apps/opie-reader/StyleConsts.cpp +++ b/noncore/apps/opie-reader/StyleConsts.cpp | |||
@@ -1,108 +1,115 @@ | |||
1 | 1 | ||
2 | #include <qimage.h> | 2 | #include <qimage.h> |
3 | #include "StyleConsts.h" | 3 | #include "StyleConsts.h" |
4 | 4 | ||
5 | GraphicLink::~GraphicLink() { delete graphic; } | 5 | GraphicLink::~GraphicLink() { delete graphic; } |
6 | 6 | ||
7 | pmstore::pmstore(bool _canScale, QImage* p, bool isLnk, unsigned long tgt) : | ||
8 | count(1), | ||
9 | m_isScaleable(_canScale) | ||
10 | { | ||
11 | graphic = new GraphicLink(p, isLnk, tgt); | ||
12 | } | ||
13 | |||
7 | pmstore::~pmstore() | 14 | pmstore::~pmstore() |
8 | { | 15 | { |
9 | //// qDebug("Deleting image"); | 16 | //// qDebug("Deleting image"); |
10 | delete graphic; | 17 | delete graphic; |
11 | } | 18 | } |
12 | 19 | ||
13 | CStyle::~CStyle() | 20 | CStyle::~CStyle() |
14 | { | 21 | { |
15 | if (graphic != NULL) | 22 | if (graphic != NULL) |
16 | { | 23 | { |
17 | if (--(graphic->count) == 0) | 24 | if (--(graphic->count) == 0) |
18 | { | 25 | { |
19 | delete graphic; | 26 | delete graphic; |
20 | } | 27 | } |
21 | } | 28 | } |
22 | } | 29 | } |
23 | 30 | ||
24 | CStyle::CStyle(const CStyle& rhs) : graphic(NULL) | 31 | CStyle::CStyle(const CStyle& rhs) : graphic(NULL) |
25 | { | 32 | { |
26 | *this = rhs; | 33 | *this = rhs; |
27 | } | 34 | } |
28 | 35 | ||
29 | CStyle& CStyle::operator=(const CStyle& rhs) | 36 | CStyle& CStyle::operator=(const CStyle& rhs) |
30 | { | 37 | { |
31 | if (rhs.graphic != NULL) | 38 | if (rhs.graphic != NULL) |
32 | { | 39 | { |
33 | (rhs.graphic->count)++; | 40 | (rhs.graphic->count)++; |
34 | if (graphic != NULL) | 41 | if (graphic != NULL) |
35 | { | 42 | { |
36 | if (--(graphic->count) == 0) | 43 | if (--(graphic->count) == 0) |
37 | { | 44 | { |
38 | delete graphic; | 45 | delete graphic; |
39 | } | 46 | } |
40 | } | 47 | } |
41 | graphic = rhs.graphic; | 48 | graphic = rhs.graphic; |
42 | } | 49 | } |
43 | else | 50 | else |
44 | { | 51 | { |
45 | if (graphic != NULL) | 52 | if (graphic != NULL) |
46 | { | 53 | { |
47 | if (--(graphic->count) == 0) | 54 | if (--(graphic->count) == 0) |
48 | { | 55 | { |
49 | delete graphic; | 56 | delete graphic; |
50 | } | 57 | } |
51 | graphic = NULL; | 58 | graphic = NULL; |
52 | } | 59 | } |
53 | } | 60 | } |
54 | sty = rhs.sty; | 61 | sty = rhs.sty; |
55 | return *this; | 62 | return *this; |
56 | } | 63 | } |
57 | 64 | ||
58 | void CStyle::clearPicture() | 65 | void CStyle::clearPicture() |
59 | { | 66 | { |
60 | if (graphic != NULL) | 67 | if (graphic != NULL) |
61 | { | 68 | { |
62 | if (--(graphic->count) == 0) | 69 | if (--(graphic->count) == 0) |
63 | { | 70 | { |
64 | delete graphic; | 71 | delete graphic; |
65 | } | 72 | } |
66 | graphic = NULL; | 73 | graphic = NULL; |
67 | } | 74 | } |
68 | } | 75 | } |
69 | 76 | ||
70 | void CStyle::unset() | 77 | void CStyle::unset() |
71 | { | 78 | { |
72 | sty.unset(); | 79 | sty.unset(); |
73 | if (graphic != NULL) | 80 | if (graphic != NULL) |
74 | { | 81 | { |
75 | if (--(graphic->count) == 0) | 82 | if (--(graphic->count) == 0) |
76 | { | 83 | { |
77 | delete graphic; | 84 | delete graphic; |
78 | } | 85 | } |
79 | graphic = NULL; | 86 | graphic = NULL; |
80 | } | 87 | } |
81 | } | 88 | } |
82 | 89 | ||
83 | void CStyle::setPicture(bool canScale, QImage* _g, bool il, unsigned long tgt) | 90 | void CStyle::setPicture(bool canScale, QImage* _g, bool il, unsigned long tgt) |
84 | { | 91 | { |
85 | if (graphic != NULL) | 92 | if (graphic != NULL) |
86 | { | 93 | { |
87 | if (--(graphic->count) == 0) | 94 | if (--(graphic->count) == 0) |
88 | { | 95 | { |
89 | delete graphic; | 96 | delete graphic; |
90 | } | 97 | } |
91 | graphic = NULL; | 98 | graphic = NULL; |
92 | } | 99 | } |
93 | if (_g != NULL) graphic = new pmstore(canScale, _g, il, tgt); | 100 | if (_g != NULL) graphic = new pmstore(canScale, _g, il, tgt); |
94 | } | 101 | } |
95 | 102 | ||
96 | void CStyle::invert() | 103 | void CStyle::invert() |
97 | { | 104 | { |
98 | qDebug("Before:<%02x%02x%02x>", sty.bred, sty.bgreen, sty.bblue); | 105 | qDebug("Before:<%02x%02x%02x>", sty.bred, sty.bgreen, sty.bblue); |
99 | qDebug("Before:<%02x%02x%02x>", sty.red, sty.green, sty.blue); | 106 | qDebug("Before:<%02x%02x%02x>", sty.red, sty.green, sty.blue); |
100 | sty.bred = 255-sty.bred; | 107 | sty.bred = 255-sty.bred; |
101 | sty.bgreen = 255-sty.bgreen; | 108 | sty.bgreen = 255-sty.bgreen; |
102 | sty.bblue = 255-sty.bblue; | 109 | sty.bblue = 255-sty.bblue; |
103 | sty.red = 255-sty.red; | 110 | sty.red = 255-sty.red; |
104 | sty.green = 255-sty.green; | 111 | sty.green = 255-sty.green; |
105 | sty.blue = 255-sty.blue; | 112 | sty.blue = 255-sty.blue; |
106 | qDebug("After:<%02x%02x%02x>", sty.bred, sty.bgreen, sty.bblue); | 113 | qDebug("After:<%02x%02x%02x>", sty.bred, sty.bgreen, sty.bblue); |
107 | qDebug("After:<%02x%02x%02x>", sty.red, sty.green, sty.blue); | 114 | qDebug("After:<%02x%02x%02x>", sty.red, sty.green, sty.blue); |
108 | } | 115 | } |
diff --git a/noncore/apps/opie-reader/StyleConsts.h b/noncore/apps/opie-reader/StyleConsts.h index 4b7ff4b..5fd9669 100644 --- a/noncore/apps/opie-reader/StyleConsts.h +++ b/noncore/apps/opie-reader/StyleConsts.h | |||
@@ -1,232 +1,230 @@ | |||
1 | #ifndef __STYLECONSTS_H | 1 | #ifndef __STYLECONSTS_H |
2 | #define __STYLECONSTS_H | 2 | #define __STYLECONSTS_H |
3 | 3 | ||
4 | typedef unsigned short StyleType; | 4 | typedef unsigned short StyleType; |
5 | 5 | ||
6 | #ifdef _WINDOWS | 6 | #ifdef _WINDOWS |
7 | #include <string.h> | 7 | #include <string.h> |
8 | #endif | 8 | #endif |
9 | #include <string.h> | 9 | #include <string.h> |
10 | #include <stdlib.h> | 10 | #include <stdlib.h> |
11 | #include <qglobal.h> | 11 | #include <qglobal.h> |
12 | class QImage; | 12 | class QImage; |
13 | 13 | ||
14 | struct GraphicLink | 14 | struct GraphicLink |
15 | { | 15 | { |
16 | QImage* graphic; | 16 | QImage* graphic; |
17 | bool isLink; | 17 | bool isLink; |
18 | unsigned long link; | 18 | unsigned long link; |
19 | GraphicLink(QImage* p, bool isLnk, unsigned long tgt) : | 19 | GraphicLink(QImage* p, bool isLnk, unsigned long tgt) : |
20 | graphic(p), isLink(isLnk), link(tgt) {} | 20 | graphic(p), isLink(isLnk), link(tgt) {} |
21 | ~GraphicLink(); | 21 | ~GraphicLink(); |
22 | }; | 22 | }; |
23 | 23 | ||
24 | struct pmstore | 24 | class pmstore |
25 | { | 25 | { |
26 | public: | ||
26 | unsigned int count; | 27 | unsigned int count; |
27 | bool m_isScaleable; | 28 | bool m_isScaleable; |
28 | GraphicLink* graphic; | 29 | GraphicLink* graphic; |
29 | pmstore(bool _canScale, QImage* p, bool isLnk, unsigned long tgt) : count(1), m_isScaleable(_canScale) | 30 | pmstore(bool _canScale, QImage* p, bool isLnk, unsigned long tgt); |
30 | { | ||
31 | graphic = new GraphicLink(p, isLnk, tgt); | ||
32 | } | ||
33 | ~pmstore(); | 31 | ~pmstore(); |
34 | }; | 32 | }; |
35 | 33 | ||
36 | enum EalignmentType | 34 | enum EalignmentType |
37 | { | 35 | { |
38 | m_AlignLeft, | 36 | m_AlignLeft, |
39 | m_AlignRight, | 37 | m_AlignRight, |
40 | m_AlignCentre, | 38 | m_AlignCentre, |
41 | m_AlignJustify, | 39 | m_AlignJustify, |
42 | m_AlignNone | 40 | m_AlignNone |
43 | }; | 41 | }; |
44 | 42 | ||
45 | class CBasicStyle | 43 | class CBasicStyle |
46 | { | 44 | { |
47 | friend class CStyle; | 45 | friend class CStyle; |
48 | bool m_bold, | 46 | bool m_bold, |
49 | m_italic; | 47 | m_italic; |
50 | unsigned long m_table; | 48 | unsigned long m_table; |
51 | int m_fontsize; | 49 | int m_fontsize; |
52 | EalignmentType m_align; | 50 | EalignmentType m_align; |
53 | unsigned char red, green, blue; | 51 | unsigned char red, green, blue; |
54 | unsigned char bred, bgreen, bblue; | 52 | unsigned char bred, bgreen, bblue; |
55 | unsigned char pred, pgreen, pblue; | 53 | unsigned char pred, pgreen, pblue; |
56 | unsigned long data; | 54 | unsigned long data; |
57 | unsigned long offset; | 55 | unsigned long offset; |
58 | bool isLink; | 56 | bool isLink; |
59 | // bool isVisited; | 57 | // bool isVisited; |
60 | bool m_underline; | 58 | bool m_underline; |
61 | bool m_strikethru; | 59 | bool m_strikethru; |
62 | bool m_monospaced; | 60 | bool m_monospaced; |
63 | unsigned char m_leftmargin, m_rightmargin; | 61 | unsigned char m_leftmargin, m_rightmargin; |
64 | signed char m_extraspace; | 62 | signed char m_extraspace; |
65 | signed char m_voffset; | 63 | signed char m_voffset; |
66 | CBasicStyle() | 64 | CBasicStyle() |
67 | { | 65 | { |
68 | unset(); | 66 | unset(); |
69 | m_table = 0xffffffff; | 67 | m_table = 0xffffffff; |
70 | } | 68 | } |
71 | bool operator!=(const CBasicStyle& rhs) | 69 | bool operator!=(const CBasicStyle& rhs) |
72 | { | 70 | { |
73 | return (memcmp(this, &rhs, sizeof(CBasicStyle)) != 0); | 71 | return (memcmp(this, &rhs, sizeof(CBasicStyle)) != 0); |
74 | } | 72 | } |
75 | void unset() | 73 | void unset() |
76 | { | 74 | { |
77 | m_bold = false; | 75 | m_bold = false; |
78 | m_italic = false; | 76 | m_italic = false; |
79 | m_fontsize = 0; | 77 | m_fontsize = 0; |
80 | m_align = m_AlignLeft; | 78 | m_align = m_AlignLeft; |
81 | red = green = blue = 0; | 79 | red = green = blue = 0; |
82 | bred = bgreen = bblue = 255; | 80 | bred = bgreen = bblue = 255; |
83 | pred = pgreen = pblue = 255; | 81 | pred = pgreen = pblue = 255; |
84 | data = 0; | 82 | data = 0; |
85 | offset = 0; | 83 | offset = 0; |
86 | isLink = false; | 84 | isLink = false; |
87 | // isVisited = false; | 85 | // isVisited = false; |
88 | m_underline = false; | 86 | m_underline = false; |
89 | m_strikethru = false; | 87 | m_strikethru = false; |
90 | m_leftmargin = 0; | 88 | m_leftmargin = 0; |
91 | m_rightmargin = 0; | 89 | m_rightmargin = 0; |
92 | m_monospaced = false; | 90 | m_monospaced = false; |
93 | m_extraspace = 0; | 91 | m_extraspace = 0; |
94 | m_voffset = 0; | 92 | m_voffset = 0; |
95 | } | 93 | } |
96 | }; | 94 | }; |
97 | 95 | ||
98 | class CStyle | 96 | class CStyle |
99 | { | 97 | { |
100 | CBasicStyle sty; | 98 | CBasicStyle sty; |
101 | pmstore* graphic; | 99 | pmstore* graphic; |
102 | public: | 100 | public: |
103 | signed char getVOffset() { return sty.m_voffset; } | 101 | signed char getVOffset() { return sty.m_voffset; } |
104 | void setVOffset(signed char sp) { sty.m_voffset = sp; } | 102 | void setVOffset(signed char sp) { sty.m_voffset = sp; } |
105 | signed char getExtraSpace() { return sty.m_extraspace; } | 103 | signed char getExtraSpace() { return sty.m_extraspace; } |
106 | void setExtraSpace(signed char sp) { sty.m_extraspace = sp; } | 104 | void setExtraSpace(signed char sp) { sty.m_extraspace = sp; } |
107 | bool getPictureLink() | 105 | bool getPictureLink() |
108 | { | 106 | { |
109 | return (graphic != NULL && graphic->graphic->isLink); | 107 | return (graphic != NULL && graphic->graphic->isLink); |
110 | } | 108 | } |
111 | unsigned long getPictureLinkData() | 109 | unsigned long getPictureLinkData() |
112 | { | 110 | { |
113 | return graphic->graphic->link; | 111 | return graphic->graphic->link; |
114 | } | 112 | } |
115 | void setLeftMargin(unsigned char m) { sty.m_leftmargin = m; } | 113 | void setLeftMargin(unsigned char m) { sty.m_leftmargin = m; } |
116 | unsigned char getLeftMargin() { return sty.m_leftmargin; } | 114 | unsigned char getLeftMargin() { return sty.m_leftmargin; } |
117 | void setRightMargin(unsigned char m) { sty.m_rightmargin = m; } | 115 | void setRightMargin(unsigned char m) { sty.m_rightmargin = m; } |
118 | unsigned char getRightMargin() { return sty.m_rightmargin; } | 116 | unsigned char getRightMargin() { return sty.m_rightmargin; } |
119 | unsigned char Red() { return sty.red; } | 117 | unsigned char Red() { return sty.red; } |
120 | unsigned char Green() { return sty.green; } | 118 | unsigned char Green() { return sty.green; } |
121 | unsigned char Blue() { return sty.blue; } | 119 | unsigned char Blue() { return sty.blue; } |
122 | void setColour(unsigned char r, unsigned char g, unsigned char b) | 120 | void setColour(unsigned char r, unsigned char g, unsigned char b) |
123 | { | 121 | { |
124 | sty.red = r; | 122 | sty.red = r; |
125 | sty.green = g; | 123 | sty.green = g; |
126 | sty.blue = b; | 124 | sty.blue = b; |
127 | } | 125 | } |
128 | unsigned char bRed() { return sty.bred; } | 126 | unsigned char bRed() { return sty.bred; } |
129 | unsigned char bGreen() { return sty.bgreen; } | 127 | unsigned char bGreen() { return sty.bgreen; } |
130 | unsigned char bBlue() { return sty.bblue; } | 128 | unsigned char bBlue() { return sty.bblue; } |
131 | unsigned char pRed() { return sty.pred; } | 129 | unsigned char pRed() { return sty.pred; } |
132 | unsigned char pGreen() { return sty.pgreen; } | 130 | unsigned char pGreen() { return sty.pgreen; } |
133 | unsigned char pBlue() { return sty.pblue; } | 131 | unsigned char pBlue() { return sty.pblue; } |
134 | void setPaper(unsigned char r, unsigned char g, unsigned char b) | 132 | void setPaper(unsigned char r, unsigned char g, unsigned char b) |
135 | { | 133 | { |
136 | sty.pred = r; | 134 | sty.pred = r; |
137 | sty.pgreen = g; | 135 | sty.pgreen = g; |
138 | sty.pblue = b; | 136 | sty.pblue = b; |
139 | } | 137 | } |
140 | void setBackground(unsigned char r, unsigned char g, unsigned char b) | 138 | void setBackground(unsigned char r, unsigned char g, unsigned char b) |
141 | { | 139 | { |
142 | sty.bred = r; | 140 | sty.bred = r; |
143 | sty.bgreen = g; | 141 | sty.bgreen = g; |
144 | sty.bblue = b; | 142 | sty.bblue = b; |
145 | } | 143 | } |
146 | CStyle() : graphic(NULL) {} | 144 | CStyle() : graphic(NULL) {} |
147 | ~CStyle(); | 145 | ~CStyle(); |
148 | // CStyle(CStyle&); | 146 | // CStyle(CStyle&); |
149 | CStyle(const CStyle&); | 147 | CStyle(const CStyle&); |
150 | CStyle& operator=(const CStyle&); | 148 | CStyle& operator=(const CStyle&); |
151 | void unset(); | 149 | void unset(); |
152 | bool isTable() const { return (sty.m_table != 0xffffffff); } | 150 | bool isTable() const { return (sty.m_table != 0xffffffff); } |
153 | void setTable(unsigned long _b) { sty.m_table = _b; } | 151 | void setTable(unsigned long _b) { sty.m_table = _b; } |
154 | unsigned long getTable() { return sty.m_table; } | 152 | unsigned long getTable() { return sty.m_table; } |
155 | bool isPicture() const { return (graphic != NULL); } | 153 | bool isPicture() const { return (graphic != NULL); } |
156 | bool canScale() const { return graphic->m_isScaleable; } | 154 | bool canScale() const { return graphic->m_isScaleable; } |
157 | void clearPicture(); | 155 | void clearPicture(); |
158 | void setPicture(bool canScale, QImage* _g, bool il=false, unsigned long tgt=0); | 156 | void setPicture(bool canScale, QImage* _g, bool il=false, unsigned long tgt=0); |
159 | QImage* getPicture() | 157 | QImage* getPicture() |
160 | { | 158 | { |
161 | QImage* pm = ((graphic != NULL) ? graphic->graphic->graphic : NULL); | 159 | QImage* pm = ((graphic != NULL) ? graphic->graphic->graphic : NULL); |
162 | return pm; | 160 | return pm; |
163 | } | 161 | } |
164 | void setUnderline() { sty.m_underline = true; } | 162 | void setUnderline() { sty.m_underline = true; } |
165 | void unsetUnderline() { sty.m_underline = false; } | 163 | void unsetUnderline() { sty.m_underline = false; } |
166 | bool isUnderline() { return sty.m_underline; } | 164 | bool isUnderline() { return sty.m_underline; } |
167 | void setStrikethru() { sty.m_strikethru = true; } | 165 | void setStrikethru() { sty.m_strikethru = true; } |
168 | void unsetStrikethru() { sty.m_strikethru = false; } | 166 | void unsetStrikethru() { sty.m_strikethru = false; } |
169 | bool isStrikethru() { return sty.m_strikethru; } | 167 | bool isStrikethru() { return sty.m_strikethru; } |
170 | void setBold() { sty.m_bold = true; } | 168 | void setBold() { sty.m_bold = true; } |
171 | void unsetBold() { sty.m_bold = false; } | 169 | void unsetBold() { sty.m_bold = false; } |
172 | bool isBold() { return sty.m_bold; } | 170 | bool isBold() { return sty.m_bold; } |
173 | void setItalic() { sty.m_italic = true; } | 171 | void setItalic() { sty.m_italic = true; } |
174 | void unsetItalic() { sty.m_italic = false; } | 172 | void unsetItalic() { sty.m_italic = false; } |
175 | bool isItalic() { return sty.m_italic; } | 173 | bool isItalic() { return sty.m_italic; } |
176 | void setMono() { sty.m_monospaced = true; } | 174 | void setMono() { sty.m_monospaced = true; } |
177 | void unsetMono() { sty.m_monospaced = false; } | 175 | void unsetMono() { sty.m_monospaced = false; } |
178 | bool isMono() { return sty.m_monospaced; } | 176 | bool isMono() { return sty.m_monospaced; } |
179 | 177 | ||
180 | void setLeftJustify() | 178 | void setLeftJustify() |
181 | { | 179 | { |
182 | sty.m_align = m_AlignLeft; | 180 | sty.m_align = m_AlignLeft; |
183 | } | 181 | } |
184 | void setRightJustify() | 182 | void setRightJustify() |
185 | { | 183 | { |
186 | sty.m_align = m_AlignRight; | 184 | sty.m_align = m_AlignRight; |
187 | } | 185 | } |
188 | void setCentreJustify() | 186 | void setCentreJustify() |
189 | { | 187 | { |
190 | sty.m_align = m_AlignCentre; | 188 | sty.m_align = m_AlignCentre; |
191 | } | 189 | } |
192 | void setFullJustify() | 190 | void setFullJustify() |
193 | { | 191 | { |
194 | sty.m_align = m_AlignJustify; | 192 | sty.m_align = m_AlignJustify; |
195 | } | 193 | } |
196 | void setNoJustify() | 194 | void setNoJustify() |
197 | { | 195 | { |
198 | sty.m_align = m_AlignNone; | 196 | sty.m_align = m_AlignNone; |
199 | } | 197 | } |
200 | StyleType getJustify() | 198 | StyleType getJustify() |
201 | { | 199 | { |
202 | return sty.m_align; | 200 | return sty.m_align; |
203 | } | 201 | } |
204 | 202 | ||
205 | void setFontSize(int _fs) | 203 | void setFontSize(int _fs) |
206 | { | 204 | { |
207 | sty.m_fontsize = _fs; | 205 | sty.m_fontsize = _fs; |
208 | } | 206 | } |
209 | int getFontSize() const | 207 | int getFontSize() const |
210 | { | 208 | { |
211 | return sty.m_fontsize; | 209 | return sty.m_fontsize; |
212 | } | 210 | } |
213 | bool operator!=(const CStyle& rhs) | 211 | bool operator!=(const CStyle& rhs) |
214 | { | 212 | { |
215 | return | 213 | return |
216 | ( | 214 | ( |
217 | (sty != rhs.sty) || | 215 | (sty != rhs.sty) || |
218 | (graphic != rhs.graphic) | 216 | (graphic != rhs.graphic) |
219 | ); | 217 | ); |
220 | } | 218 | } |
221 | void setLink(bool _l) { sty.isLink = _l; } | 219 | void setLink(bool _l) { sty.isLink = _l; } |
222 | bool getLink() { return sty.isLink; } | 220 | bool getLink() { return sty.isLink; } |
223 | // void setVisited(bool _l) { sty.isVisited = _l; } | 221 | // void setVisited(bool _l) { sty.isVisited = _l; } |
224 | // bool getVisited() { return sty.isVisited; } | 222 | // bool getVisited() { return sty.isVisited; } |
225 | void setData(unsigned long _d) { sty.data = _d; } | 223 | void setData(unsigned long _d) { sty.data = _d; } |
226 | unsigned long getData() { return sty.data; } | 224 | unsigned long getData() { return sty.data; } |
227 | void setOffset(unsigned long _d) { sty.offset = _d; } | 225 | void setOffset(unsigned long _d) { sty.offset = _d; } |
228 | unsigned long getOffset() { return sty.offset; } | 226 | unsigned long getOffset() { return sty.offset; } |
229 | void invert(); | 227 | void invert(); |
230 | }; | 228 | }; |
231 | 229 | ||
232 | #endif | 230 | #endif |
diff --git a/noncore/apps/opie-write/qrichtext.cpp b/noncore/apps/opie-write/qrichtext.cpp index c27eb1e..f040f1e 100644 --- a/noncore/apps/opie-write/qrichtext.cpp +++ b/noncore/apps/opie-write/qrichtext.cpp | |||
@@ -5807,613 +5807,612 @@ void QTextFormat::setVAlign( VerticalAlignment a ) | |||
5807 | ha = a; | 5807 | ha = a; |
5808 | update(); | 5808 | update(); |
5809 | } | 5809 | } |
5810 | 5810 | ||
5811 | void QTextFormat::setItalic( bool b ) | 5811 | void QTextFormat::setItalic( bool b ) |
5812 | { | 5812 | { |
5813 | if ( b == fn.italic() ) | 5813 | if ( b == fn.italic() ) |
5814 | return; | 5814 | return; |
5815 | fn.setItalic( b ); | 5815 | fn.setItalic( b ); |
5816 | update(); | 5816 | update(); |
5817 | } | 5817 | } |
5818 | 5818 | ||
5819 | void QTextFormat::setUnderline( bool b ) | 5819 | void QTextFormat::setUnderline( bool b ) |
5820 | { | 5820 | { |
5821 | if ( b == fn.underline() ) | 5821 | if ( b == fn.underline() ) |
5822 | return; | 5822 | return; |
5823 | fn.setUnderline( b ); | 5823 | fn.setUnderline( b ); |
5824 | update(); | 5824 | update(); |
5825 | } | 5825 | } |
5826 | 5826 | ||
5827 | void QTextFormat::setStrikeOut( bool b ) | 5827 | void QTextFormat::setStrikeOut( bool b ) |
5828 | { | 5828 | { |
5829 | if ( b == fn.strikeOut() ) | 5829 | if ( b == fn.strikeOut() ) |
5830 | return; | 5830 | return; |
5831 | fn.setStrikeOut( b ); | 5831 | fn.setStrikeOut( b ); |
5832 | update(); | 5832 | update(); |
5833 | } | 5833 | } |
5834 | 5834 | ||
5835 | void QTextFormat::setFamily( const QString &f ) | 5835 | void QTextFormat::setFamily( const QString &f ) |
5836 | { | 5836 | { |
5837 | if ( f == fn.family() ) | 5837 | if ( f == fn.family() ) |
5838 | return; | 5838 | return; |
5839 | fn.setFamily( f ); | 5839 | fn.setFamily( f ); |
5840 | update(); | 5840 | update(); |
5841 | } | 5841 | } |
5842 | 5842 | ||
5843 | void QTextFormat::setPointSize( int s ) | 5843 | void QTextFormat::setPointSize( int s ) |
5844 | { | 5844 | { |
5845 | if ( s == fn.pointSize() ) | 5845 | if ( s == fn.pointSize() ) |
5846 | return; | 5846 | return; |
5847 | fn.setPointSize( s ); | 5847 | fn.setPointSize( s ); |
5848 | usePixelSizes = FALSE; | 5848 | usePixelSizes = FALSE; |
5849 | update(); | 5849 | update(); |
5850 | } | 5850 | } |
5851 | 5851 | ||
5852 | void QTextFormat::setFont( const QFont &f ) | 5852 | void QTextFormat::setFont( const QFont &f ) |
5853 | { | 5853 | { |
5854 | if ( f == fn && !k.isEmpty() ) | 5854 | if ( f == fn && !k.isEmpty() ) |
5855 | return; | 5855 | return; |
5856 | fn = f; | 5856 | fn = f; |
5857 | update(); | 5857 | update(); |
5858 | } | 5858 | } |
5859 | 5859 | ||
5860 | void QTextFormat::setColor( const QColor &c ) | 5860 | void QTextFormat::setColor( const QColor &c ) |
5861 | { | 5861 | { |
5862 | if ( c == col ) | 5862 | if ( c == col ) |
5863 | return; | 5863 | return; |
5864 | col = c; | 5864 | col = c; |
5865 | update(); | 5865 | update(); |
5866 | } | 5866 | } |
5867 | 5867 | ||
5868 | QString QTextFormat::makeFormatChangeTags( QTextFormat* defaultFormat, QTextFormat *f, | 5868 | QString QTextFormat::makeFormatChangeTags( QTextFormat* defaultFormat, QTextFormat *f, |
5869 | const QString& oldAnchorHref, const QString& anchorHref ) const | 5869 | const QString& oldAnchorHref, const QString& anchorHref ) const |
5870 | { | 5870 | { |
5871 | QString tag; | 5871 | QString tag; |
5872 | if ( f ) | 5872 | if ( f ) |
5873 | tag += f->makeFormatEndTags( defaultFormat, oldAnchorHref ); | 5873 | tag += f->makeFormatEndTags( defaultFormat, oldAnchorHref ); |
5874 | 5874 | ||
5875 | if ( !anchorHref.isEmpty() ) | 5875 | if ( !anchorHref.isEmpty() ) |
5876 | tag += "<a href=\"" + anchorHref + "\">"; | 5876 | tag += "<a href=\"" + anchorHref + "\">"; |
5877 | 5877 | ||
5878 | if ( font() != defaultFormat->font() | 5878 | if ( font() != defaultFormat->font() |
5879 | || vAlign() != defaultFormat->vAlign() | 5879 | || vAlign() != defaultFormat->vAlign() |
5880 | || color().rgb() != defaultFormat->color().rgb() ) { | 5880 | || color().rgb() != defaultFormat->color().rgb() ) { |
5881 | QString s; | 5881 | QString s; |
5882 | if ( font().family() != defaultFormat->font().family() ) | 5882 | if ( font().family() != defaultFormat->font().family() ) |
5883 | s += QString(!!s?";":"") + "font-family:" + fn.family(); | 5883 | s += QString(!!s?";":"") + "font-family:" + fn.family(); |
5884 | if ( font().italic() && font().italic() != defaultFormat->font().italic() ) | 5884 | if ( font().italic() && font().italic() != defaultFormat->font().italic() ) |
5885 | s += QString(!!s?";":"") + "font-style:" + (font().italic() ? "italic" : "normal"); | 5885 | s += QString(!!s?";":"") + "font-style:" + (font().italic() ? "italic" : "normal"); |
5886 | if ( font().pointSize() != defaultFormat->font().pointSize() ) | 5886 | if ( font().pointSize() != defaultFormat->font().pointSize() ) |
5887 | s += QString(!!s?";":"") + "font-size:" + QString::number( fn.pointSize() ) + "pt"; | 5887 | s += QString(!!s?";":"") + "font-size:" + QString::number( fn.pointSize() ) + "pt"; |
5888 | if ( font().weight() != defaultFormat->font().weight() ) | 5888 | if ( font().weight() != defaultFormat->font().weight() ) |
5889 | s += QString(!!s?";":"") + "font-weight:" + QString::number( fn.weight() * 8 ); | 5889 | s += QString(!!s?";":"") + "font-weight:" + QString::number( fn.weight() * 8 ); |
5890 | if ( font().underline() != defaultFormat->font().underline() ) | 5890 | if ( font().underline() != defaultFormat->font().underline() ) |
5891 | s += QString(!!s?";":"") + "text-decoration:" + ( font().underline() ? "underline" : "none"); | 5891 | s += QString(!!s?";":"") + "text-decoration:" + ( font().underline() ? "underline" : "none"); |
5892 | if ( vAlign() != defaultFormat->vAlign() ) { | 5892 | if ( vAlign() != defaultFormat->vAlign() ) { |
5893 | s += QString(!!s?";":"") + "vertical-align:"; | 5893 | s += QString(!!s?";":"") + "vertical-align:"; |
5894 | if ( vAlign() == QTextFormat::AlignSuperScript ) | 5894 | if ( vAlign() == QTextFormat::AlignSuperScript ) |
5895 | s += "super"; | 5895 | s += "super"; |
5896 | else if ( vAlign() == QTextFormat::AlignSubScript ) | 5896 | else if ( vAlign() == QTextFormat::AlignSubScript ) |
5897 | s += "sub"; | 5897 | s += "sub"; |
5898 | else | 5898 | else |
5899 | s += "normal"; | 5899 | s += "normal"; |
5900 | } | 5900 | } |
5901 | if ( color().rgb() != defaultFormat->color().rgb() ) | 5901 | if ( color().rgb() != defaultFormat->color().rgb() ) |
5902 | s += QString(!!s?";":"") + "color:" + col.name(); | 5902 | s += QString(!!s?";":"") + "color:" + col.name(); |
5903 | if ( !s.isEmpty() ) | 5903 | if ( !s.isEmpty() ) |
5904 | tag += "<span style=\"" + s + "\">"; | 5904 | tag += "<span style=\"" + s + "\">"; |
5905 | } | 5905 | } |
5906 | 5906 | ||
5907 | return tag; | 5907 | return tag; |
5908 | } | 5908 | } |
5909 | 5909 | ||
5910 | QString QTextFormat::makeFormatEndTags( QTextFormat* defaultFormat, const QString& anchorHref ) const | 5910 | QString QTextFormat::makeFormatEndTags( QTextFormat* defaultFormat, const QString& anchorHref ) const |
5911 | { | 5911 | { |
5912 | QString tag; | 5912 | QString tag; |
5913 | if ( font().family() != defaultFormat->font().family() | 5913 | if ( font().family() != defaultFormat->font().family() |
5914 | || font().pointSize() != defaultFormat->font().pointSize() | 5914 | || font().pointSize() != defaultFormat->font().pointSize() |
5915 | || font().weight() != defaultFormat->font().weight() | 5915 | || font().weight() != defaultFormat->font().weight() |
5916 | || font().italic() != defaultFormat->font().italic() | 5916 | || font().italic() != defaultFormat->font().italic() |
5917 | || font().underline() != defaultFormat->font().underline() | 5917 | || font().underline() != defaultFormat->font().underline() |
5918 | || font().strikeOut() != defaultFormat->font().strikeOut() | 5918 | || font().strikeOut() != defaultFormat->font().strikeOut() |
5919 | || vAlign() != defaultFormat->vAlign() | 5919 | || vAlign() != defaultFormat->vAlign() |
5920 | || color().rgb() != defaultFormat->color().rgb() ) | 5920 | || color().rgb() != defaultFormat->color().rgb() ) |
5921 | tag += "</span>"; | 5921 | tag += "</span>"; |
5922 | if ( !anchorHref.isEmpty() ) | 5922 | if ( !anchorHref.isEmpty() ) |
5923 | tag += "</a>"; | 5923 | tag += "</a>"; |
5924 | return tag; | 5924 | return tag; |
5925 | } | 5925 | } |
5926 | 5926 | ||
5927 | QTextFormat QTextFormat::makeTextFormat( const QStyleSheetItem *style, const QMap<QString,QString>& attr, double scaleFontsFactor ) const | 5927 | QTextFormat QTextFormat::makeTextFormat( const QStyleSheetItem *style, const QMap<QString,QString>& attr, double scaleFontsFactor ) const |
5928 | { | 5928 | { |
5929 | QTextFormat format(*this); | 5929 | QTextFormat format(*this); |
5930 | if (!style ) | 5930 | if (!style ) |
5931 | return format; | 5931 | return format; |
5932 | 5932 | ||
5933 | if ( !style->isAnchor() && style->color().isValid() ) { | 5933 | if ( !style->isAnchor() && style->color().isValid() ) { |
5934 | // the style is not an anchor and defines a color. | 5934 | // the style is not an anchor and defines a color. |
5935 | // It might be used inside an anchor and it should | 5935 | // It might be used inside an anchor and it should |
5936 | // override the link color. | 5936 | // override the link color. |
5937 | format.linkColor = FALSE; | 5937 | format.linkColor = FALSE; |
5938 | } | 5938 | } |
5939 | switch ( style->verticalAlignment() ) { | 5939 | switch ( style->verticalAlignment() ) { |
5940 | case QStyleSheetItem::VAlignBaseline: | 5940 | case QStyleSheetItem::VAlignBaseline: |
5941 | format.setVAlign( QTextFormat::AlignNormal ); | 5941 | format.setVAlign( QTextFormat::AlignNormal ); |
5942 | break; | 5942 | break; |
5943 | case QStyleSheetItem::VAlignSuper: | 5943 | case QStyleSheetItem::VAlignSuper: |
5944 | format.setVAlign( QTextFormat::AlignSuperScript ); | 5944 | format.setVAlign( QTextFormat::AlignSuperScript ); |
5945 | break; | 5945 | break; |
5946 | case QStyleSheetItem::VAlignSub: | 5946 | case QStyleSheetItem::VAlignSub: |
5947 | format.setVAlign( QTextFormat::AlignSubScript ); | 5947 | format.setVAlign( QTextFormat::AlignSubScript ); |
5948 | break; | 5948 | break; |
5949 | } | 5949 | } |
5950 | 5950 | ||
5951 | if ( style->fontWeight() != QStyleSheetItem::Undefined ) | 5951 | if ( style->fontWeight() != QStyleSheetItem::Undefined ) |
5952 | format.fn.setWeight( style->fontWeight() ); | 5952 | format.fn.setWeight( style->fontWeight() ); |
5953 | if ( style->fontSize() != QStyleSheetItem::Undefined ) { | 5953 | if ( style->fontSize() != QStyleSheetItem::Undefined ) { |
5954 | format.fn.setPointSize( style->fontSize() ); | 5954 | format.fn.setPointSize( style->fontSize() ); |
5955 | } else if ( style->logicalFontSize() != QStyleSheetItem::Undefined ) { | 5955 | } else if ( style->logicalFontSize() != QStyleSheetItem::Undefined ) { |
5956 | format.logicalFontSize = style->logicalFontSize(); | 5956 | format.logicalFontSize = style->logicalFontSize(); |
5957 | if ( format.usePixelSizes ) | 5957 | if ( format.usePixelSizes ) |
5958 | format.fn.setPixelSize( format.stdSize ); | 5958 | format.fn.setPixelSize( format.stdSize ); |
5959 | else | 5959 | else |
5960 | format.fn.setPointSize( format.stdSize ); | 5960 | format.fn.setPointSize( format.stdSize ); |
5961 | style->styleSheet()->scaleFont( format.fn, format.logicalFontSize ); | 5961 | style->styleSheet()->scaleFont( format.fn, format.logicalFontSize ); |
5962 | } else if ( style->logicalFontSizeStep() ) { | 5962 | } else if ( style->logicalFontSizeStep() ) { |
5963 | format.logicalFontSize += style->logicalFontSizeStep(); | 5963 | format.logicalFontSize += style->logicalFontSizeStep(); |
5964 | if ( format.usePixelSizes ) | 5964 | if ( format.usePixelSizes ) |
5965 | format.fn.setPixelSize( format.stdSize ); | 5965 | format.fn.setPixelSize( format.stdSize ); |
5966 | else | 5966 | else |
5967 | format.fn.setPointSize( format.stdSize ); | 5967 | format.fn.setPointSize( format.stdSize ); |
5968 | style->styleSheet()->scaleFont( format.fn, format.logicalFontSize ); | 5968 | style->styleSheet()->scaleFont( format.fn, format.logicalFontSize ); |
5969 | } | 5969 | } |
5970 | if ( !style->fontFamily().isEmpty() ) | 5970 | if ( !style->fontFamily().isEmpty() ) |
5971 | format.fn.setFamily( style->fontFamily() ); | 5971 | format.fn.setFamily( style->fontFamily() ); |
5972 | if ( style->color().isValid() ) | 5972 | if ( style->color().isValid() ) |
5973 | format.col = style->color(); | 5973 | format.col = style->color(); |
5974 | if ( style->definesFontItalic() ) | 5974 | if ( style->definesFontItalic() ) |
5975 | format.fn.setItalic( style->fontItalic() ); | 5975 | format.fn.setItalic( style->fontItalic() ); |
5976 | if ( style->definesFontUnderline() ) | 5976 | if ( style->definesFontUnderline() ) |
5977 | format.fn.setUnderline( style->fontUnderline() ); | 5977 | format.fn.setUnderline( style->fontUnderline() ); |
5978 | if ( style->definesFontStrikeOut() ) | 5978 | if ( style->definesFontStrikeOut() ) |
5979 | format.fn.setStrikeOut( style->fontStrikeOut() ); | 5979 | format.fn.setStrikeOut( style->fontStrikeOut() ); |
5980 | 5980 | ||
5981 | 5981 | ||
5982 | if ( style->name() == "font") { | 5982 | if ( style->name() == "font") { |
5983 | if ( attr.contains("color") ) { | 5983 | if ( attr.contains("color") ) { |
5984 | QString s = attr["color"]; | 5984 | QString s = attr["color"]; |
5985 | if ( !s.isEmpty() ) { | 5985 | if ( !s.isEmpty() ) { |
5986 | format.col.setNamedColor( s ); | 5986 | format.col.setNamedColor( s ); |
5987 | format.linkColor = FALSE; | 5987 | format.linkColor = FALSE; |
5988 | } | 5988 | } |
5989 | } | 5989 | } |
5990 | if ( attr.contains("face") ) { | 5990 | if ( attr.contains("face") ) { |
5991 | QString a = attr["face"]; | 5991 | QString a = attr["face"]; |
5992 | QString family = QTextDocument::section( a, ",", 0, 0 ); | 5992 | QString family = QTextDocument::section( a, ",", 0, 0 ); |
5993 | if ( !!family ) | 5993 | if ( !!family ) |
5994 | format.fn.setFamily( family ); | 5994 | format.fn.setFamily( family ); |
5995 | } | 5995 | } |
5996 | if ( attr.contains("size") ) { | 5996 | if ( attr.contains("size") ) { |
5997 | QString a = attr["size"]; | 5997 | QString a = attr["size"]; |
5998 | int n = a.toInt(); | 5998 | int n = a.toInt(); |
5999 | if ( a[0] == '+' || a[0] == '-' ) | 5999 | if ( a[0] == '+' || a[0] == '-' ) |
6000 | n += format.logicalFontSize; | 6000 | n += format.logicalFontSize; |
6001 | format.logicalFontSize = n; | 6001 | format.logicalFontSize = n; |
6002 | if ( format.usePixelSizes ) | 6002 | if ( format.usePixelSizes ) |
6003 | format.fn.setPixelSize( format.stdSize ); | 6003 | format.fn.setPixelSize( format.stdSize ); |
6004 | else | 6004 | else |
6005 | format.fn.setPointSize( format.stdSize ); | 6005 | format.fn.setPointSize( format.stdSize ); |
6006 | style->styleSheet()->scaleFont( format.fn, format.logicalFontSize ); | 6006 | style->styleSheet()->scaleFont( format.fn, format.logicalFontSize ); |
6007 | } | 6007 | } |
6008 | } | 6008 | } |
6009 | if ( attr.contains("style" ) ) { | 6009 | if ( attr.contains("style" ) ) { |
6010 | QString a = attr["style"]; | 6010 | QString a = attr["style"]; |
6011 | for ( int s = 0; s < a.contains(';')+1; s++ ) { | 6011 | for ( int s = 0; s < a.contains(';')+1; s++ ) { |
6012 | QString style = QTextDocument::section( a, ";", s, s ); | 6012 | QString style = QTextDocument::section( a, ";", s, s ); |
6013 | if ( style.startsWith("font-size:" ) && QTextDocument::endsWith(style, "pt") ) { | 6013 | if ( style.startsWith("font-size:" ) && QTextDocument::endsWith(style, "pt") ) { |
6014 | format.logicalFontSize = 0; | 6014 | format.logicalFontSize = 0; |
6015 | format.setPointSize( int( scaleFontsFactor * style.mid( 10, style.length() - 12 ).toInt() ) ); | 6015 | format.setPointSize( int( scaleFontsFactor * style.mid( 10, style.length() - 12 ).toInt() ) ); |
6016 | } if ( style.startsWith("font-style:" ) ) { | 6016 | } if ( style.startsWith("font-style:" ) ) { |
6017 | QString s = style.mid( 11 ).stripWhiteSpace(); | 6017 | QString s = style.mid( 11 ).stripWhiteSpace(); |
6018 | if ( s == "normal" ) | 6018 | if ( s == "normal" ) |
6019 | format.fn.setItalic( FALSE ); | 6019 | format.fn.setItalic( FALSE ); |
6020 | else if ( s == "italic" || s == "oblique" ) | 6020 | else if ( s == "italic" || s == "oblique" ) |
6021 | format.fn.setItalic( TRUE ); | 6021 | format.fn.setItalic( TRUE ); |
6022 | } else if ( style.startsWith("font-weight:" ) ) { | 6022 | } else if ( style.startsWith("font-weight:" ) ) { |
6023 | QString s = style.mid( 12 ); | 6023 | QString s = style.mid( 12 ); |
6024 | bool ok = TRUE; | 6024 | bool ok = TRUE; |
6025 | int n = s.toInt( &ok ); | 6025 | int n = s.toInt( &ok ); |
6026 | if ( ok ) | 6026 | if ( ok ) |
6027 | format.fn.setWeight( n/8 ); | 6027 | format.fn.setWeight( n/8 ); |
6028 | } else if ( style.startsWith("font-family:" ) ) { | 6028 | } else if ( style.startsWith("font-family:" ) ) { |
6029 | format.fn.setFamily( QTextDocument::section(style.mid(12),",",0,0).stripWhiteSpace() ); | 6029 | format.fn.setFamily( QTextDocument::section(style.mid(12),",",0,0).stripWhiteSpace() ); |
6030 | } else if ( style.startsWith("text-decoration:" ) ) { | 6030 | } else if ( style.startsWith("text-decoration:" ) ) { |
6031 | QString s = style.mid( 16 ).stripWhiteSpace(); | 6031 | QString s = style.mid( 16 ).stripWhiteSpace(); |
6032 | format.fn.setUnderline( s == "underline" ); | 6032 | format.fn.setUnderline( s == "underline" ); |
6033 | } else if ( style.startsWith("vertical-align:" ) ) { | 6033 | } else if ( style.startsWith("vertical-align:" ) ) { |
6034 | QString s = style.mid( 15 ).stripWhiteSpace(); | 6034 | QString s = style.mid( 15 ).stripWhiteSpace(); |
6035 | if ( s == "sub" ) | 6035 | if ( s == "sub" ) |
6036 | format.setVAlign( QTextFormat::AlignSubScript ); | 6036 | format.setVAlign( QTextFormat::AlignSubScript ); |
6037 | else if ( s == "super" ) | 6037 | else if ( s == "super" ) |
6038 | format.setVAlign( QTextFormat::AlignSuperScript ); | 6038 | format.setVAlign( QTextFormat::AlignSuperScript ); |
6039 | else | 6039 | else |
6040 | format.setVAlign( QTextFormat::AlignNormal ); | 6040 | format.setVAlign( QTextFormat::AlignNormal ); |
6041 | } else if ( style.startsWith("color:" ) ) { | 6041 | } else if ( style.startsWith("color:" ) ) { |
6042 | format.col.setNamedColor( style.mid(6) ); | 6042 | format.col.setNamedColor( style.mid(6) ); |
6043 | format.linkColor = FALSE; | 6043 | format.linkColor = FALSE; |
6044 | } | 6044 | } |
6045 | } | 6045 | } |
6046 | } | 6046 | } |
6047 | 6047 | ||
6048 | format.update(); | 6048 | format.update(); |
6049 | return format; | 6049 | return format; |
6050 | } | 6050 | } |
6051 | 6051 | ||
6052 | struct QPixmapInt | 6052 | struct QPixmapInt |
6053 | { | 6053 | { |
6054 | QPixmapInt() : ref( 0 ) {} | 6054 | QPixmapInt() : ref( 0 ) {} |
6055 | QPixmap pm; | 6055 | QPixmap pm; |
6056 | int ref; | 6056 | int ref; |
6057 | }; | 6057 | }; |
6058 | 6058 | ||
6059 | static QMap<QString, QPixmapInt> *pixmap_map = 0; | 6059 | static QMap<QString, QPixmapInt> *pixmap_map = 0; |
6060 | 6060 | ||
6061 | QTextImage::QTextImage( QTextDocument *p, const QMap<QString, QString> &attr, const QString& context, | 6061 | QTextImage::QTextImage( QTextDocument *p, const QMap<QString, QString> &attr, const QString& context, |
6062 | QMimeSourceFactory &factory ) | 6062 | QMimeSourceFactory &factory ) |
6063 | : QTextCustomItem( p ) | 6063 | : QTextCustomItem( p ), reg( 0 ) |
6064 | { | 6064 | { |
6065 | width = height = 0; | 6065 | width = height = 0; |
6066 | if ( attr.contains("width") ) | 6066 | if ( attr.contains("width") ) |
6067 | width = attr["width"].toInt(); | 6067 | width = attr["width"].toInt(); |
6068 | if ( attr.contains("height") ) | 6068 | if ( attr.contains("height") ) |
6069 | height = attr["height"].toInt(); | 6069 | height = attr["height"].toInt(); |
6070 | 6070 | ||
6071 | reg = 0; | ||
6072 | QString imageName = attr["src"]; | 6071 | QString imageName = attr["src"]; |
6073 | 6072 | ||
6074 | if (!imageName) | 6073 | if (!imageName) |
6075 | imageName = attr["source"]; | 6074 | imageName = attr["source"]; |
6076 | 6075 | ||
6077 | if ( !imageName.isEmpty() ) { | 6076 | if ( !imageName.isEmpty() ) { |
6078 | imgId = QString( "%1,%2,%3,%4" ).arg( imageName ).arg( width ).arg( height ).arg( (ulong)&factory ); | 6077 | imgId = QString( "%1,%2,%3,%4" ).arg( imageName ).arg( width ).arg( height ).arg( (ulong)&factory ); |
6079 | if ( !pixmap_map ) | 6078 | if ( !pixmap_map ) |
6080 | pixmap_map = new QMap<QString, QPixmapInt>; | 6079 | pixmap_map = new QMap<QString, QPixmapInt>; |
6081 | if ( pixmap_map->contains( imgId ) ) { | 6080 | if ( pixmap_map->contains( imgId ) ) { |
6082 | QPixmapInt& pmi = pixmap_map->operator[](imgId); | 6081 | QPixmapInt& pmi = pixmap_map->operator[](imgId); |
6083 | pm = pmi.pm; | 6082 | pm = pmi.pm; |
6084 | pmi.ref++; | 6083 | pmi.ref++; |
6085 | width = pm.width(); | 6084 | width = pm.width(); |
6086 | height = pm.height(); | 6085 | height = pm.height(); |
6087 | } else { | 6086 | } else { |
6088 | QImage img; | 6087 | QImage img; |
6089 | const QMimeSource* m = | 6088 | const QMimeSource* m = |
6090 | factory.data( imageName, context ); | 6089 | factory.data( imageName, context ); |
6091 | if ( !m ) { | 6090 | if ( !m ) { |
6092 | owarn << "QTextImage: no mimesource for " << imageName.latin1() << "" << oendl; | 6091 | owarn << "QTextImage: no mimesource for " << imageName.latin1() << "" << oendl; |
6093 | } | 6092 | } |
6094 | else { | 6093 | else { |
6095 | if ( !QImageDrag::decode( m, img ) ) { | 6094 | if ( !QImageDrag::decode( m, img ) ) { |
6096 | owarn << "QTextImage: cannot decode " << imageName.latin1() << "" << oendl; | 6095 | owarn << "QTextImage: cannot decode " << imageName.latin1() << "" << oendl; |
6097 | } | 6096 | } |
6098 | } | 6097 | } |
6099 | 6098 | ||
6100 | if ( !img.isNull() ) { | 6099 | if ( !img.isNull() ) { |
6101 | if ( width == 0 ) { | 6100 | if ( width == 0 ) { |
6102 | width = img.width(); | 6101 | width = img.width(); |
6103 | if ( height != 0 ) { | 6102 | if ( height != 0 ) { |
6104 | width = img.width() * height / img.height(); | 6103 | width = img.width() * height / img.height(); |
6105 | } | 6104 | } |
6106 | } | 6105 | } |
6107 | if ( height == 0 ) { | 6106 | if ( height == 0 ) { |
6108 | height = img.height(); | 6107 | height = img.height(); |
6109 | if ( width != img.width() ) { | 6108 | if ( width != img.width() ) { |
6110 | height = img.height() * width / img.width(); | 6109 | height = img.height() * width / img.width(); |
6111 | } | 6110 | } |
6112 | } | 6111 | } |
6113 | if ( img.width() != width || img.height() != height ){ | 6112 | if ( img.width() != width || img.height() != height ){ |
6114 | #ifndef QT_NO_IMAGE_SMOOTHSCALE | 6113 | #ifndef QT_NO_IMAGE_SMOOTHSCALE |
6115 | img = img.smoothScale(width, height); | 6114 | img = img.smoothScale(width, height); |
6116 | #endif | 6115 | #endif |
6117 | width = img.width(); | 6116 | width = img.width(); |
6118 | height = img.height(); | 6117 | height = img.height(); |
6119 | } | 6118 | } |
6120 | pm.convertFromImage( img ); | 6119 | pm.convertFromImage( img ); |
6121 | } | 6120 | } |
6122 | if ( !pm.isNull() ) { | 6121 | if ( !pm.isNull() ) { |
6123 | QPixmapInt& pmi = pixmap_map->operator[](imgId); | 6122 | QPixmapInt& pmi = pixmap_map->operator[](imgId); |
6124 | pmi.pm = pm; | 6123 | pmi.pm = pm; |
6125 | pmi.ref++; | 6124 | pmi.ref++; |
6126 | } | 6125 | } |
6127 | } | 6126 | } |
6128 | if ( pm.mask() ) { | 6127 | if ( pm.mask() ) { |
6129 | QRegion mask( *pm.mask() ); | 6128 | QRegion mask( *pm.mask() ); |
6130 | QRegion all( 0, 0, pm.width(), pm.height() ); | 6129 | QRegion all( 0, 0, pm.width(), pm.height() ); |
6131 | reg = new QRegion( all.subtract( mask ) ); | 6130 | reg = new QRegion( all.subtract( mask ) ); |
6132 | } | 6131 | } |
6133 | } | 6132 | } |
6134 | 6133 | ||
6135 | if ( pm.isNull() && (width*height)==0 ) | 6134 | if ( pm.isNull() && (width*height)==0 ) |
6136 | width = height = 50; | 6135 | width = height = 50; |
6137 | 6136 | ||
6138 | place = PlaceInline; | 6137 | place = PlaceInline; |
6139 | if ( attr["align"] == "left" ) | 6138 | if ( attr["align"] == "left" ) |
6140 | place = PlaceLeft; | 6139 | place = PlaceLeft; |
6141 | else if ( attr["align"] == "right" ) | 6140 | else if ( attr["align"] == "right" ) |
6142 | place = PlaceRight; | 6141 | place = PlaceRight; |
6143 | 6142 | ||
6144 | tmpwidth = width; | 6143 | tmpwidth = width; |
6145 | tmpheight = height; | 6144 | tmpheight = height; |
6146 | 6145 | ||
6147 | attributes = attr; | 6146 | attributes = attr; |
6148 | } | 6147 | } |
6149 | 6148 | ||
6150 | QTextImage::~QTextImage() | 6149 | QTextImage::~QTextImage() |
6151 | { | 6150 | { |
6151 | delete reg; | ||
6152 | if ( pixmap_map && pixmap_map->contains( imgId ) ) { | 6152 | if ( pixmap_map && pixmap_map->contains( imgId ) ) { |
6153 | QPixmapInt& pmi = pixmap_map->operator[](imgId); | 6153 | QPixmapInt& pmi = pixmap_map->operator[](imgId); |
6154 | pmi.ref--; | 6154 | pmi.ref--; |
6155 | if ( !pmi.ref ) { | 6155 | if ( !pmi.ref ) { |
6156 | pixmap_map->remove( imgId ); | 6156 | pixmap_map->remove( imgId ); |
6157 | if ( pixmap_map->isEmpty() ) { | 6157 | if ( pixmap_map->isEmpty() ) { |
6158 | delete pixmap_map; | 6158 | delete pixmap_map; |
6159 | pixmap_map = 0; | 6159 | pixmap_map = 0; |
6160 | } | 6160 | } |
6161 | } | 6161 | } |
6162 | } | 6162 | } |
6163 | delete reg; | ||
6164 | } | 6163 | } |
6165 | 6164 | ||
6166 | QString QTextImage::richText() const | 6165 | QString QTextImage::richText() const |
6167 | { | 6166 | { |
6168 | QString s; | 6167 | QString s; |
6169 | s += "<img "; | 6168 | s += "<img "; |
6170 | QMap<QString, QString>::ConstIterator it = attributes.begin(); | 6169 | QMap<QString, QString>::ConstIterator it = attributes.begin(); |
6171 | for ( ; it != attributes.end(); ++it ) | 6170 | for ( ; it != attributes.end(); ++it ) |
6172 | s += it.key() + "=" + *it + " "; | 6171 | s += it.key() + "=" + *it + " "; |
6173 | s += ">"; | 6172 | s += ">"; |
6174 | return s; | 6173 | return s; |
6175 | } | 6174 | } |
6176 | 6175 | ||
6177 | void QTextImage::adjustToPainter( QPainter* p ) | 6176 | void QTextImage::adjustToPainter( QPainter* p ) |
6178 | { | 6177 | { |
6179 | width = scale( tmpwidth, p ); | 6178 | width = scale( tmpwidth, p ); |
6180 | height = scale( tmpheight, p ); | 6179 | height = scale( tmpheight, p ); |
6181 | } | 6180 | } |
6182 | 6181 | ||
6183 | #if !defined(Q_WS_X11) | 6182 | #if !defined(Q_WS_X11) |
6184 | #include <qbitmap.h> | 6183 | #include <qbitmap.h> |
6185 | #include "qcleanuphandler.h" | 6184 | #include "qcleanuphandler.h" |
6186 | static QPixmap *qrt_selection = 0; | 6185 | static QPixmap *qrt_selection = 0; |
6187 | static QSingleCleanupHandler<QPixmap> qrt_cleanup_pixmap; | 6186 | static QSingleCleanupHandler<QPixmap> qrt_cleanup_pixmap; |
6188 | static void qrt_createSelectionPixmap( const QColorGroup &cg ) | 6187 | static void qrt_createSelectionPixmap( const QColorGroup &cg ) |
6189 | { | 6188 | { |
6190 | qrt_selection = new QPixmap( 2, 2 ); | 6189 | qrt_selection = new QPixmap( 2, 2 ); |
6191 | qrt_cleanup_pixmap.set( &qrt_selection ); | 6190 | qrt_cleanup_pixmap.set( &qrt_selection ); |
6192 | qrt_selection->fill( Qt::color0 ); | 6191 | qrt_selection->fill( Qt::color0 ); |
6193 | QBitmap m( 2, 2 ); | 6192 | QBitmap m( 2, 2 ); |
6194 | m.fill( Qt::color1 ); | 6193 | m.fill( Qt::color1 ); |
6195 | QPainter p( &m ); | 6194 | QPainter p( &m ); |
6196 | p.setPen( Qt::color0 ); | 6195 | p.setPen( Qt::color0 ); |
6197 | for ( int j = 0; j < 2; ++j ) { | 6196 | for ( int j = 0; j < 2; ++j ) { |
6198 | p.drawPoint( j % 2, j ); | 6197 | p.drawPoint( j % 2, j ); |
6199 | } | 6198 | } |
6200 | p.end(); | 6199 | p.end(); |
6201 | qrt_selection->setMask( m ); | 6200 | qrt_selection->setMask( m ); |
6202 | qrt_selection->fill( cg.highlight() ); | 6201 | qrt_selection->fill( cg.highlight() ); |
6203 | } | 6202 | } |
6204 | #endif | 6203 | #endif |
6205 | 6204 | ||
6206 | void QTextImage::draw( QPainter* p, int x, int y, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected ) | 6205 | void QTextImage::draw( QPainter* p, int x, int y, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected ) |
6207 | { | 6206 | { |
6208 | if ( placement() != PlaceInline ) { | 6207 | if ( placement() != PlaceInline ) { |
6209 | x = xpos; | 6208 | x = xpos; |
6210 | y = ypos; | 6209 | y = ypos; |
6211 | } | 6210 | } |
6212 | 6211 | ||
6213 | if ( pm.isNull() ) { | 6212 | if ( pm.isNull() ) { |
6214 | p->fillRect( x , y, width, height, cg.dark() ); | 6213 | p->fillRect( x , y, width, height, cg.dark() ); |
6215 | return; | 6214 | return; |
6216 | } | 6215 | } |
6217 | 6216 | ||
6218 | if ( is_printer( p ) ) { | 6217 | if ( is_printer( p ) ) { |
6219 | p->drawPixmap( x, y, pm ); | 6218 | p->drawPixmap( x, y, pm ); |
6220 | return; | 6219 | return; |
6221 | } | 6220 | } |
6222 | 6221 | ||
6223 | if ( placement() != PlaceInline && !QRect( xpos, ypos, width, height ).intersects( QRect( cx, cy, cw, ch ) ) ) | 6222 | if ( placement() != PlaceInline && !QRect( xpos, ypos, width, height ).intersects( QRect( cx, cy, cw, ch ) ) ) |
6224 | return; | 6223 | return; |
6225 | 6224 | ||
6226 | if ( placement() == PlaceInline ) | 6225 | if ( placement() == PlaceInline ) |
6227 | p->drawPixmap( x , y, pm ); | 6226 | p->drawPixmap( x , y, pm ); |
6228 | else | 6227 | else |
6229 | p->drawPixmap( cx , cy, pm, cx - x, cy - y, cw, ch ); | 6228 | p->drawPixmap( cx , cy, pm, cx - x, cy - y, cw, ch ); |
6230 | 6229 | ||
6231 | if ( selected && placement() == PlaceInline && is_printer( p ) ) { | 6230 | if ( selected && placement() == PlaceInline && is_printer( p ) ) { |
6232 | #if defined(Q_WS_X11) | 6231 | #if defined(Q_WS_X11) |
6233 | p->fillRect( QRect( QPoint( x, y ), pm.size() ), QBrush( cg.highlight(), QBrush::Dense4Pattern) ); | 6232 | p->fillRect( QRect( QPoint( x, y ), pm.size() ), QBrush( cg.highlight(), QBrush::Dense4Pattern) ); |
6234 | #else // in WIN32 Dense4Pattern doesn't work correctly (transparency problem), so work around it | 6233 | #else // in WIN32 Dense4Pattern doesn't work correctly (transparency problem), so work around it |
6235 | if ( !qrt_selection ) | 6234 | if ( !qrt_selection ) |
6236 | qrt_createSelectionPixmap( cg ); | 6235 | qrt_createSelectionPixmap( cg ); |
6237 | p->drawTiledPixmap( x, y, pm.width(), pm.height(), *qrt_selection ); | 6236 | p->drawTiledPixmap( x, y, pm.width(), pm.height(), *qrt_selection ); |
6238 | #endif | 6237 | #endif |
6239 | } | 6238 | } |
6240 | } | 6239 | } |
6241 | 6240 | ||
6242 | void QTextHorizontalLine::adjustToPainter( QPainter* p ) | 6241 | void QTextHorizontalLine::adjustToPainter( QPainter* p ) |
6243 | { | 6242 | { |
6244 | height = scale( tmpheight, p ); | 6243 | height = scale( tmpheight, p ); |
6245 | } | 6244 | } |
6246 | 6245 | ||
6247 | 6246 | ||
6248 | QTextHorizontalLine::QTextHorizontalLine( QTextDocument *p, const QMap<QString, QString> &attr, | 6247 | QTextHorizontalLine::QTextHorizontalLine( QTextDocument *p, const QMap<QString, QString> &attr, |
6249 | const QString &, | 6248 | const QString &, |
6250 | QMimeSourceFactory & ) | 6249 | QMimeSourceFactory & ) |
6251 | : QTextCustomItem( p ) | 6250 | : QTextCustomItem( p ) |
6252 | { | 6251 | { |
6253 | height = tmpheight = 8; | 6252 | height = tmpheight = 8; |
6254 | if ( attr.find( "color" ) != attr.end() ) | 6253 | if ( attr.find( "color" ) != attr.end() ) |
6255 | color = QColor( *attr.find( "color" ) ); | 6254 | color = QColor( *attr.find( "color" ) ); |
6256 | } | 6255 | } |
6257 | 6256 | ||
6258 | QTextHorizontalLine::~QTextHorizontalLine() | 6257 | QTextHorizontalLine::~QTextHorizontalLine() |
6259 | { | 6258 | { |
6260 | } | 6259 | } |
6261 | 6260 | ||
6262 | QString QTextHorizontalLine::richText() const | 6261 | QString QTextHorizontalLine::richText() const |
6263 | { | 6262 | { |
6264 | return "<hr>"; | 6263 | return "<hr>"; |
6265 | } | 6264 | } |
6266 | 6265 | ||
6267 | void QTextHorizontalLine::draw( QPainter* p, int x, int y, int , int , int , int , const QColorGroup& cg, bool selected ) | 6266 | void QTextHorizontalLine::draw( QPainter* p, int x, int y, int , int , int , int , const QColorGroup& cg, bool selected ) |
6268 | { | 6267 | { |
6269 | QRect r( x, y, width, height); | 6268 | QRect r( x, y, width, height); |
6270 | if ( is_printer( p ) ) { | 6269 | if ( is_printer( p ) ) { |
6271 | QPen oldPen = p->pen(); | 6270 | QPen oldPen = p->pen(); |
6272 | if ( !color.isValid() ) | 6271 | if ( !color.isValid() ) |
6273 | p->setPen( QPen( cg.text(), height/8 ) ); | 6272 | p->setPen( QPen( cg.text(), height/8 ) ); |
6274 | else | 6273 | else |
6275 | p->setPen( QPen( color, height/8 ) ); | 6274 | p->setPen( QPen( color, height/8 ) ); |
6276 | p->drawLine( r.left()-1, y + height / 2, r.right() + 1, y + height / 2 ); | 6275 | p->drawLine( r.left()-1, y + height / 2, r.right() + 1, y + height / 2 ); |
6277 | p->setPen( oldPen ); | 6276 | p->setPen( oldPen ); |
6278 | } else { | 6277 | } else { |
6279 | QColorGroup g( cg ); | 6278 | QColorGroup g( cg ); |
6280 | if ( color.isValid() ) | 6279 | if ( color.isValid() ) |
6281 | g.setColor( QColorGroup::Dark, color ); | 6280 | g.setColor( QColorGroup::Dark, color ); |
6282 | if ( selected ) | 6281 | if ( selected ) |
6283 | p->fillRect( r.left(), y, r.right(), y + height, g.highlight() ); | 6282 | p->fillRect( r.left(), y, r.right(), y + height, g.highlight() ); |
6284 | qDrawShadeLine( p, r.left() - 1, y + height / 2, r.right() + 1, y + height / 2, g, TRUE, height / 8 ); | 6283 | qDrawShadeLine( p, r.left() - 1, y + height / 2, r.right() + 1, y + height / 2, g, TRUE, height / 8 ); |
6285 | } | 6284 | } |
6286 | } | 6285 | } |
6287 | 6286 | ||
6288 | 6287 | ||
6289 | /*****************************************************************/ | 6288 | /*****************************************************************/ |
6290 | // Small set of utility functions to make the parser a bit simpler | 6289 | // Small set of utility functions to make the parser a bit simpler |
6291 | // | 6290 | // |
6292 | 6291 | ||
6293 | bool QTextDocument::hasPrefix(const QChar* doc, int length, int pos, QChar c) | 6292 | bool QTextDocument::hasPrefix(const QChar* doc, int length, int pos, QChar c) |
6294 | { | 6293 | { |
6295 | if ( pos >= length ) | 6294 | if ( pos >= length ) |
6296 | return FALSE; | 6295 | return FALSE; |
6297 | return doc[ pos ].lower() == c.lower(); | 6296 | return doc[ pos ].lower() == c.lower(); |
6298 | } | 6297 | } |
6299 | 6298 | ||
6300 | bool QTextDocument::hasPrefix( const QChar* doc, int length, int pos, const QString& s ) | 6299 | bool QTextDocument::hasPrefix( const QChar* doc, int length, int pos, const QString& s ) |
6301 | { | 6300 | { |
6302 | if ( pos + (int) s.length() >= length ) | 6301 | if ( pos + (int) s.length() >= length ) |
6303 | return FALSE; | 6302 | return FALSE; |
6304 | for ( int i = 0; i < (int)s.length(); i++ ) { | 6303 | for ( int i = 0; i < (int)s.length(); i++ ) { |
6305 | if ( doc[ pos + i ].lower() != s[ i ].lower() ) | 6304 | if ( doc[ pos + i ].lower() != s[ i ].lower() ) |
6306 | return FALSE; | 6305 | return FALSE; |
6307 | } | 6306 | } |
6308 | return TRUE; | 6307 | return TRUE; |
6309 | } | 6308 | } |
6310 | 6309 | ||
6311 | static bool qt_is_cell_in_use( QPtrList<QTextTableCell>& cells, int row, int col ) | 6310 | static bool qt_is_cell_in_use( QPtrList<QTextTableCell>& cells, int row, int col ) |
6312 | { | 6311 | { |
6313 | for ( QTextTableCell* c = cells.first(); c; c = cells.next() ) { | 6312 | for ( QTextTableCell* c = cells.first(); c; c = cells.next() ) { |
6314 | if ( row >= c->row() && row < c->row() + c->rowspan() | 6313 | if ( row >= c->row() && row < c->row() + c->rowspan() |
6315 | && col >= c->column() && col < c->column() + c->colspan() ) | 6314 | && col >= c->column() && col < c->column() + c->colspan() ) |
6316 | return TRUE; | 6315 | return TRUE; |
6317 | } | 6316 | } |
6318 | return FALSE; | 6317 | return FALSE; |
6319 | } | 6318 | } |
6320 | 6319 | ||
6321 | QTextCustomItem* QTextDocument::parseTable( const QMap<QString, QString> &attr, const QTextFormat &fmt, | 6320 | QTextCustomItem* QTextDocument::parseTable( const QMap<QString, QString> &attr, const QTextFormat &fmt, |
6322 | const QChar* doc, int length, int& pos, QTextParagraph *curpar ) | 6321 | const QChar* doc, int length, int& pos, QTextParagraph *curpar ) |
6323 | { | 6322 | { |
6324 | 6323 | ||
6325 | QTextTable* table = new QTextTable( this, attr ); | 6324 | QTextTable* table = new QTextTable( this, attr ); |
6326 | int row = -1; | 6325 | int row = -1; |
6327 | int col = -1; | 6326 | int col = -1; |
6328 | 6327 | ||
6329 | QString rowbgcolor; | 6328 | QString rowbgcolor; |
6330 | QString rowalign; | 6329 | QString rowalign; |
6331 | QString tablebgcolor = attr["bgcolor"]; | 6330 | QString tablebgcolor = attr["bgcolor"]; |
6332 | 6331 | ||
6333 | QPtrList<QTextTableCell> multicells; | 6332 | QPtrList<QTextTableCell> multicells; |
6334 | 6333 | ||
6335 | QString tagname; | 6334 | QString tagname; |
6336 | (void) eatSpace(doc, length, pos); | 6335 | (void) eatSpace(doc, length, pos); |
6337 | while ( pos < length) { | 6336 | while ( pos < length) { |
6338 | if (hasPrefix(doc, length, pos, QChar('<')) ){ | 6337 | if (hasPrefix(doc, length, pos, QChar('<')) ){ |
6339 | if (hasPrefix(doc, length, pos+1, QChar('/'))) { | 6338 | if (hasPrefix(doc, length, pos+1, QChar('/'))) { |
6340 | tagname = parseCloseTag( doc, length, pos ); | 6339 | tagname = parseCloseTag( doc, length, pos ); |
6341 | if ( tagname == "table" ) { | 6340 | if ( tagname == "table" ) { |
6342 | return table; | 6341 | return table; |
6343 | } | 6342 | } |
6344 | } else { | 6343 | } else { |
6345 | QMap<QString, QString> attr2; | 6344 | QMap<QString, QString> attr2; |
6346 | bool emptyTag = FALSE; | 6345 | bool emptyTag = FALSE; |
6347 | tagname = parseOpenTag( doc, length, pos, attr2, emptyTag ); | 6346 | tagname = parseOpenTag( doc, length, pos, attr2, emptyTag ); |
6348 | if ( tagname == "tr" ) { | 6347 | if ( tagname == "tr" ) { |
6349 | rowbgcolor = attr2["bgcolor"]; | 6348 | rowbgcolor = attr2["bgcolor"]; |
6350 | rowalign = attr2["align"]; | 6349 | rowalign = attr2["align"]; |
6351 | row++; | 6350 | row++; |
6352 | col = -1; | 6351 | col = -1; |
6353 | } | 6352 | } |
6354 | else if ( tagname == "td" || tagname == "th" ) { | 6353 | else if ( tagname == "td" || tagname == "th" ) { |
6355 | col++; | 6354 | col++; |
6356 | while ( qt_is_cell_in_use( multicells, row, col ) ) { | 6355 | while ( qt_is_cell_in_use( multicells, row, col ) ) { |
6357 | col++; | 6356 | col++; |
6358 | } | 6357 | } |
6359 | 6358 | ||
6360 | if ( row >= 0 && col >= 0 ) { | 6359 | if ( row >= 0 && col >= 0 ) { |
6361 | const QStyleSheetItem* s = sheet_->item(tagname); | 6360 | const QStyleSheetItem* s = sheet_->item(tagname); |
6362 | if ( !attr2.contains("bgcolor") ) { | 6361 | if ( !attr2.contains("bgcolor") ) { |
6363 | if (!rowbgcolor.isEmpty() ) | 6362 | if (!rowbgcolor.isEmpty() ) |
6364 | attr2["bgcolor"] = rowbgcolor; | 6363 | attr2["bgcolor"] = rowbgcolor; |
6365 | else if (!tablebgcolor.isEmpty() ) | 6364 | else if (!tablebgcolor.isEmpty() ) |
6366 | attr2["bgcolor"] = tablebgcolor; | 6365 | attr2["bgcolor"] = tablebgcolor; |
6367 | } | 6366 | } |
6368 | if ( !attr2.contains("align") ) { | 6367 | if ( !attr2.contains("align") ) { |
6369 | if (!rowalign.isEmpty() ) | 6368 | if (!rowalign.isEmpty() ) |
6370 | attr2["align"] = rowalign; | 6369 | attr2["align"] = rowalign; |
6371 | } | 6370 | } |
6372 | 6371 | ||
6373 | // extract the cell contents | 6372 | // extract the cell contents |
6374 | int end = pos; | 6373 | int end = pos; |
6375 | while ( end < length | 6374 | while ( end < length |
6376 | && !hasPrefix( doc, length, end, "</td") | 6375 | && !hasPrefix( doc, length, end, "</td") |
6377 | && !hasPrefix( doc, length, end, "<td") | 6376 | && !hasPrefix( doc, length, end, "<td") |
6378 | && !hasPrefix( doc, length, end, "</th") | 6377 | && !hasPrefix( doc, length, end, "</th") |
6379 | && !hasPrefix( doc, length, end, "<th") | 6378 | && !hasPrefix( doc, length, end, "<th") |
6380 | && !hasPrefix( doc, length, end, "<td") | 6379 | && !hasPrefix( doc, length, end, "<td") |
6381 | && !hasPrefix( doc, length, end, "</tr") | 6380 | && !hasPrefix( doc, length, end, "</tr") |
6382 | && !hasPrefix( doc, length, end, "<tr") | 6381 | && !hasPrefix( doc, length, end, "<tr") |
6383 | && !hasPrefix( doc, length, end, "</table") ) { | 6382 | && !hasPrefix( doc, length, end, "</table") ) { |
6384 | if ( hasPrefix( doc, length, end, "<table" ) ) { // nested table | 6383 | if ( hasPrefix( doc, length, end, "<table" ) ) { // nested table |
6385 | int nested = 1; | 6384 | int nested = 1; |
6386 | ++end; | 6385 | ++end; |
6387 | while ( end < length && nested != 0 ) { | 6386 | while ( end < length && nested != 0 ) { |
6388 | if ( hasPrefix( doc, length, end, "</table" ) ) | 6387 | if ( hasPrefix( doc, length, end, "</table" ) ) |
6389 | nested--; | 6388 | nested--; |
6390 | if ( hasPrefix( doc, length, end, "<table" ) ) | 6389 | if ( hasPrefix( doc, length, end, "<table" ) ) |
6391 | nested++; | 6390 | nested++; |
6392 | end++; | 6391 | end++; |
6393 | } | 6392 | } |
6394 | } | 6393 | } |
6395 | end++; | 6394 | end++; |
6396 | } | 6395 | } |
6397 | QTextTableCell* cell = new QTextTableCell( table, row, col, | 6396 | QTextTableCell* cell = new QTextTableCell( table, row, col, |
6398 | attr2, s, fmt.makeTextFormat( s, attr2, scaleFontsFactor ), | 6397 | attr2, s, fmt.makeTextFormat( s, attr2, scaleFontsFactor ), |
6399 | contxt, *factory_, sheet_, | 6398 | contxt, *factory_, sheet_, |
6400 | QString( doc, length).mid( pos, end - pos ) ); | 6399 | QString( doc, length).mid( pos, end - pos ) ); |
6401 | cell->richText()->parentPar = curpar; | 6400 | cell->richText()->parentPar = curpar; |
6402 | if ( cell->colspan() > 1 || cell->rowspan() > 1 ) | 6401 | if ( cell->colspan() > 1 || cell->rowspan() > 1 ) |
6403 | multicells.append( cell ); | 6402 | multicells.append( cell ); |
6404 | col += cell->colspan()-1; | 6403 | col += cell->colspan()-1; |
6405 | pos = end; | 6404 | pos = end; |
6406 | } | 6405 | } |
6407 | } | 6406 | } |
6408 | } | 6407 | } |
6409 | 6408 | ||
6410 | } else { | 6409 | } else { |
6411 | ++pos; | 6410 | ++pos; |
6412 | } | 6411 | } |
6413 | } | 6412 | } |
6414 | return table; | 6413 | return table; |
6415 | } | 6414 | } |
6416 | 6415 | ||
6417 | bool QTextDocument::eatSpace(const QChar* doc, int length, int& pos, bool includeNbsp ) | 6416 | bool QTextDocument::eatSpace(const QChar* doc, int length, int& pos, bool includeNbsp ) |
6418 | { | 6417 | { |
6419 | int old_pos = pos; | 6418 | int old_pos = pos; |
diff --git a/noncore/apps/tinykate/libkate/document/katehighlight.cpp b/noncore/apps/tinykate/libkate/document/katehighlight.cpp index 539d356..89024f7 100644 --- a/noncore/apps/tinykate/libkate/document/katehighlight.cpp +++ b/noncore/apps/tinykate/libkate/document/katehighlight.cpp | |||
@@ -136,519 +136,524 @@ HlRangeDetect::HlRangeDetect(int attribute, int context, QChar ch1, QChar ch2) | |||
136 | sChar1 = ch1; | 136 | sChar1 = ch1; |
137 | sChar2 = ch2; | 137 | sChar2 = ch2; |
138 | } | 138 | } |
139 | 139 | ||
140 | const QChar *HlRangeDetect::checkHgl(const QChar *s, int len, bool) { | 140 | const QChar *HlRangeDetect::checkHgl(const QChar *s, int len, bool) { |
141 | if (*s == sChar1) | 141 | if (*s == sChar1) |
142 | { | 142 | { |
143 | do | 143 | do |
144 | { | 144 | { |
145 | s++; | 145 | s++; |
146 | len--; | 146 | len--; |
147 | if (len == 0) return 0L; | 147 | if (len == 0) return 0L; |
148 | } | 148 | } |
149 | while (*s != sChar2); | 149 | while (*s != sChar2); |
150 | 150 | ||
151 | return s + 1; | 151 | return s + 1; |
152 | } | 152 | } |
153 | return 0L; | 153 | return 0L; |
154 | } | 154 | } |
155 | 155 | ||
156 | HlKeyword::HlKeyword (int attribute, int context,bool casesensitive, const QChar *deliminator, uint deliLen) | 156 | HlKeyword::HlKeyword (int attribute, int context,bool casesensitive, const QChar *deliminator, uint deliLen) |
157 | : HlItem(attribute,context), dict (113, casesensitive) | 157 | : HlItem(attribute,context), dict (113, casesensitive) |
158 | { | 158 | { |
159 | deliminatorChars = deliminator; | 159 | deliminatorChars = deliminator; |
160 | deliminatorLen = deliLen; | 160 | deliminatorLen = deliLen; |
161 | _caseSensitive=casesensitive; | 161 | _caseSensitive=casesensitive; |
162 | } | 162 | } |
163 | 163 | ||
164 | HlKeyword::~HlKeyword() { | 164 | HlKeyword::~HlKeyword() { |
165 | } | 165 | } |
166 | 166 | ||
167 | bool HlKeyword::startEnable(QChar c) | 167 | bool HlKeyword::startEnable(QChar c) |
168 | { | 168 | { |
169 | return ustrchr(deliminatorChars, deliminatorLen, c); | 169 | return ustrchr(deliminatorChars, deliminatorLen, c); |
170 | } | 170 | } |
171 | 171 | ||
172 | // If we use a dictionary for lookup we don't really need | 172 | // If we use a dictionary for lookup we don't really need |
173 | // an item as such we are using the key to lookup | 173 | // an item as such we are using the key to lookup |
174 | void HlKeyword::addWord(const QString &word) | 174 | void HlKeyword::addWord(const QString &word) |
175 | { | 175 | { |
176 | words.append(word); | 176 | words.append(word); |
177 | dict.insert(word,&trueBool); | 177 | dict.insert(word,&trueBool); |
178 | } | 178 | } |
179 | 179 | ||
180 | void HlKeyword::addList(const QStringList& list) | 180 | void HlKeyword::addList(const QStringList& list) |
181 | { | 181 | { |
182 | 182 | ||
183 | words+=list; | 183 | words+=list; |
184 | for(uint i=0;i<list.count();i++) dict.insert(list[i], &trueBool); | 184 | for(uint i=0;i<list.count();i++) dict.insert(list[i], &trueBool); |
185 | } | 185 | } |
186 | 186 | ||
187 | const QChar *HlKeyword::checkHgl(const QChar *s, int len, bool b) | 187 | const QChar *HlKeyword::checkHgl(const QChar *s, int len, bool b) |
188 | { | 188 | { |
189 | if (len == 0) return 0L; | 189 | if (len == 0) return 0L; |
190 | 190 | ||
191 | const QChar *s2 = s; | 191 | const QChar *s2 = s; |
192 | 192 | ||
193 | while ( (len > 0) && (!ustrchr(deliminatorChars, deliminatorLen, *s2)) ) | 193 | while ( (len > 0) && (!ustrchr(deliminatorChars, deliminatorLen, *s2)) ) |
194 | { | 194 | { |
195 | s2++; | 195 | s2++; |
196 | len--; | 196 | len--; |
197 | } | 197 | } |
198 | 198 | ||
199 | if (s2 == s) return 0L; | 199 | if (s2 == s) return 0L; |
200 | 200 | ||
201 | QString lookup = QString(s,s2-s); | 201 | QString lookup = QString(s,s2-s); |
202 | 202 | ||
203 | if ( dict.find(lookup) ) return s2; | 203 | if ( dict.find(lookup) ) return s2; |
204 | return 0L; | 204 | return 0L; |
205 | } | 205 | } |
206 | 206 | ||
207 | HlInt::HlInt(int attribute, int context) | 207 | HlInt::HlInt(int attribute, int context) |
208 | : HlItem(attribute,context) { | 208 | : HlItem(attribute,context) { |
209 | } | 209 | } |
210 | 210 | ||
211 | const QChar *HlInt::checkHgl(const QChar *str, int len, bool) { | 211 | const QChar *HlInt::checkHgl(const QChar *str, int len, bool) { |
212 | const QChar *s,*s1; | 212 | const QChar *s,*s1; |
213 | 213 | ||
214 | s = str; | 214 | s = str; |
215 | while (s->isDigit()) s++; | 215 | while (s->isDigit()) s++; |
216 | if (s > str) | 216 | if (s > str) |
217 | { | 217 | { |
218 | if (subItems) | 218 | if (subItems) |
219 | { | 219 | { |
220 | for (HlItem *it=subItems->first();it;it=subItems->next()) | 220 | for (HlItem *it=subItems->first();it;it=subItems->next()) |
221 | { | 221 | { |
222 | s1=it->checkHgl(s, len, false); | 222 | s1=it->checkHgl(s, len, false); |
223 | if (s1) return s1; | 223 | if (s1) return s1; |
224 | } | 224 | } |
225 | } | 225 | } |
226 | return s; | 226 | return s; |
227 | } | 227 | } |
228 | return 0L; | 228 | return 0L; |
229 | } | 229 | } |
230 | 230 | ||
231 | HlFloat::HlFloat(int attribute, int context) | 231 | HlFloat::HlFloat(int attribute, int context) |
232 | : HlItem(attribute,context) { | 232 | : HlItem(attribute,context) { |
233 | } | 233 | } |
234 | 234 | ||
235 | const QChar *HlFloat::checkHgl(const QChar *s, int len, bool) { | 235 | const QChar *HlFloat::checkHgl(const QChar *s, int len, bool) { |
236 | bool b, p; | 236 | bool b, p; |
237 | const QChar *s1; | 237 | const QChar *s1; |
238 | 238 | ||
239 | b = false; | 239 | b = false; |
240 | while (s->isDigit()){ | 240 | while (s->isDigit()){ |
241 | s++; | 241 | s++; |
242 | b = true; | 242 | b = true; |
243 | } | 243 | } |
244 | if (p = (*s == '.')) { | 244 | if (p = (*s == '.')) { |
245 | s++; | 245 | s++; |
246 | while (s->isDigit()) { | 246 | while (s->isDigit()) { |
247 | s++; | 247 | s++; |
248 | b = true; | 248 | b = true; |
249 | } | 249 | } |
250 | } | 250 | } |
251 | if (!b) return 0L; | 251 | if (!b) return 0L; |
252 | if ((*s&0xdf) == 'E') s++; | 252 | if ((*s&0xdf) == 'E') s++; |
253 | else | 253 | else |
254 | if (!p) return 0L; | 254 | if (!p) return 0L; |
255 | else | 255 | else |
256 | { | 256 | { |
257 | if (subItems) | 257 | if (subItems) |
258 | { | 258 | { |
259 | for (HlItem *it=subItems->first();it;it=subItems->next()) | 259 | for (HlItem *it=subItems->first();it;it=subItems->next()) |
260 | { | 260 | { |
261 | s1=it->checkHgl(s, len, false); | 261 | s1=it->checkHgl(s, len, false); |
262 | if (s1) return s1; | 262 | if (s1) return s1; |
263 | } | 263 | } |
264 | } | 264 | } |
265 | return s; | 265 | return s; |
266 | } | 266 | } |
267 | if ((*s == '-')||(*s =='+')) s++; | 267 | if ((*s == '-')||(*s =='+')) s++; |
268 | b = false; | 268 | b = false; |
269 | while (s->isDigit()) { | 269 | while (s->isDigit()) { |
270 | s++; | 270 | s++; |
271 | b = true; | 271 | b = true; |
272 | } | 272 | } |
273 | if (b) | 273 | if (b) |
274 | { | 274 | { |
275 | if (subItems) | 275 | if (subItems) |
276 | { | 276 | { |
277 | for (HlItem *it=subItems->first();it;it=subItems->next()) | 277 | for (HlItem *it=subItems->first();it;it=subItems->next()) |
278 | { | 278 | { |
279 | s1=it->checkHgl(s, len, false); | 279 | s1=it->checkHgl(s, len, false); |
280 | if (s1) return s1; | 280 | if (s1) return s1; |
281 | } | 281 | } |
282 | } | 282 | } |
283 | return s; | 283 | return s; |
284 | } | 284 | } |
285 | else return 0L; | 285 | else return 0L; |
286 | } | 286 | } |
287 | 287 | ||
288 | 288 | ||
289 | HlCInt::HlCInt(int attribute, int context) | 289 | HlCInt::HlCInt(int attribute, int context) |
290 | : HlInt(attribute,context) { | 290 | : HlInt(attribute,context) { |
291 | } | 291 | } |
292 | 292 | ||
293 | const QChar *HlCInt::checkHgl(const QChar *s, int len, bool lineStart) { | 293 | const QChar *HlCInt::checkHgl(const QChar *s, int len, bool lineStart) { |
294 | 294 | ||
295 | // if (*s == '0') s++; else s = HlInt::checkHgl(s); | 295 | // if (*s == '0') s++; else s = HlInt::checkHgl(s); |
296 | s = HlInt::checkHgl(s, len, lineStart); | 296 | s = HlInt::checkHgl(s, len, lineStart); |
297 | if (s != 0L) { | 297 | if (s != 0L) { |
298 | int l = 0; | 298 | int l = 0; |
299 | int u = 0; | 299 | int u = 0; |
300 | const QChar *str; | 300 | const QChar *str; |
301 | 301 | ||
302 | do { | 302 | do { |
303 | str = s; | 303 | str = s; |
304 | if ((*s&0xdf) == 'L' ) { | 304 | if ((*s&0xdf) == 'L' ) { |
305 | l++; | 305 | l++; |
306 | if (l > 2) return 0L; | 306 | if (l > 2) return 0L; |
307 | s++; | 307 | s++; |
308 | } | 308 | } |
309 | if ((*s&0xdf) == 'U' ){ | 309 | if ((*s&0xdf) == 'U' ){ |
310 | u++; | 310 | u++; |
311 | if (u > 1) return 0L; | 311 | if (u > 1) return 0L; |
312 | s++; | 312 | s++; |
313 | } | 313 | } |
314 | } while (s != str); | 314 | } while (s != str); |
315 | } | 315 | } |
316 | return s; | 316 | return s; |
317 | } | 317 | } |
318 | 318 | ||
319 | HlCOct::HlCOct(int attribute, int context) | 319 | HlCOct::HlCOct(int attribute, int context) |
320 | : HlItem(attribute,context) { | 320 | : HlItem(attribute,context) { |
321 | } | 321 | } |
322 | 322 | ||
323 | const QChar *HlCOct::checkHgl(const QChar *str, int len, bool) { | 323 | const QChar *HlCOct::checkHgl(const QChar *str, int len, bool) { |
324 | const QChar *s; | 324 | const QChar *s; |
325 | 325 | ||
326 | if (*str == '0') { | 326 | if (*str == '0') { |
327 | str++; | 327 | str++; |
328 | s = str; | 328 | s = str; |
329 | while (*s >= '0' && *s <= '7') s++; | 329 | while (*s >= '0' && *s <= '7') s++; |
330 | if (s > str) { | 330 | if (s > str) { |
331 | if ((*s&0xdf) == 'L' || (*s&0xdf) == 'U' ) s++; | 331 | if ((*s&0xdf) == 'L' || (*s&0xdf) == 'U' ) s++; |
332 | return s; | 332 | return s; |
333 | } | 333 | } |
334 | } | 334 | } |
335 | return 0L; | 335 | return 0L; |
336 | } | 336 | } |
337 | 337 | ||
338 | HlCHex::HlCHex(int attribute, int context) | 338 | HlCHex::HlCHex(int attribute, int context) |
339 | : HlItem(attribute,context) { | 339 | : HlItem(attribute,context) { |
340 | } | 340 | } |
341 | 341 | ||
342 | const QChar *HlCHex::checkHgl(const QChar *str, int len, bool) { | 342 | const QChar *HlCHex::checkHgl(const QChar *str, int len, bool) { |
343 | const QChar *s=str; | 343 | const QChar *s=str; |
344 | #if 0 | 344 | #if 0 |
345 | int i; | 345 | int i; |
346 | for (i=0;(*s)!='\0';s++,i++); | 346 | for (i=0;(*s)!='\0';s++,i++); |
347 | QString line(str,i); | 347 | QString line(str,i); |
348 | QRegExp3 rx("0[xX][a-fA-F\\d]+[UuLl]?"); // this matches but is also matching parenthesis | 348 | QRegExp3 rx("0[xX][a-fA-F\\d]+[UuLl]?"); // this matches but is also matching parenthesis |
349 | int pos=rx.search(line,0); | 349 | int pos=rx.search(line,0); |
350 | if(pos > -1) return str+rx.matchedLength(); | 350 | if(pos > -1) return str+rx.matchedLength(); |
351 | else | 351 | else |
352 | return 0L; | 352 | return 0L; |
353 | 353 | ||
354 | #else | 354 | #else |
355 | if (str[0] == '0' && ((str[1]&0xdf) == 'X' )) { | 355 | if (str[0] == '0' && ((str[1]&0xdf) == 'X' )) { |
356 | str += 2; | 356 | str += 2; |
357 | s = str; | 357 | s = str; |
358 | while (s->isDigit() || ((*s&0xdf) >= 'A' && (*s&0xdf) <= 'F') /*|| (*s >= 'a' && *s <= 'f')*/) s++; | 358 | while (s->isDigit() || ((*s&0xdf) >= 'A' && (*s&0xdf) <= 'F') /*|| (*s >= 'a' && *s <= 'f')*/) s++; |
359 | if (s > str) { | 359 | if (s > str) { |
360 | if ((*s&0xdf) == 'L' || (*s&0xdf) == 'U' ) s++; | 360 | if ((*s&0xdf) == 'L' || (*s&0xdf) == 'U' ) s++; |
361 | return s; | 361 | return s; |
362 | } | 362 | } |
363 | } | 363 | } |
364 | return 0L; | 364 | return 0L; |
365 | #endif | 365 | #endif |
366 | } | 366 | } |
367 | 367 | ||
368 | HlCFloat::HlCFloat(int attribute, int context) | 368 | HlCFloat::HlCFloat(int attribute, int context) |
369 | : HlFloat(attribute,context) { | 369 | : HlFloat(attribute,context) { |
370 | } | 370 | } |
371 | 371 | ||
372 | const QChar *HlCFloat::checkHgl(const QChar *s, int len, bool lineStart) { | 372 | const QChar *HlCFloat::checkHgl(const QChar *s, int len, bool lineStart) { |
373 | 373 | ||
374 | s = HlFloat::checkHgl(s, len, lineStart); | 374 | s = HlFloat::checkHgl(s, len, lineStart); |
375 | if (s && ((*s&0xdf) == 'F' )) s++; | 375 | if (s && ((*s&0xdf) == 'F' )) s++; |
376 | return s; | 376 | return s; |
377 | } | 377 | } |
378 | 378 | ||
379 | HlAnyChar::HlAnyChar(int attribute, int context, const QChar* charList, uint len) | 379 | HlAnyChar::HlAnyChar(int attribute, int context, const QChar* charList, uint len) |
380 | : HlItem(attribute, context) { | 380 | : HlItem(attribute, context) { |
381 | _charList=charList; | 381 | _charList=charList; |
382 | _charListLen=len; | 382 | _charListLen=len; |
383 | } | 383 | } |
384 | 384 | ||
385 | const QChar *HlAnyChar::checkHgl(const QChar *s, int len, bool) | 385 | const QChar *HlAnyChar::checkHgl(const QChar *s, int len, bool) |
386 | { | 386 | { |
387 | if (ustrchr(_charList, _charListLen, *s)) return s +1; | 387 | if (ustrchr(_charList, _charListLen, *s)) return s +1; |
388 | return 0L; | 388 | return 0L; |
389 | } | 389 | } |
390 | 390 | ||
391 | HlRegExpr::HlRegExpr(int attribute, int context,QString regexp) | 391 | HlRegExpr::HlRegExpr(int attribute, int context,QString regexp) |
392 | : HlItem(attribute, context) { | 392 | : HlItem(attribute, context), Expr(0) { |
393 | 393 | ||
394 | handlesLinestart=regexp.startsWith("^"); | 394 | handlesLinestart=regexp.startsWith("^"); |
395 | if(!handlesLinestart) regexp.prepend("^"); | 395 | if(!handlesLinestart) regexp.prepend("^"); |
396 | Expr=new QRegExp3(regexp); | 396 | Expr=new QRegExp3(regexp); |
397 | } | 397 | } |
398 | 398 | ||
399 | HlRegExpr::~HlRegExpr() | ||
400 | { | ||
401 | delete Expr; | ||
402 | } | ||
403 | |||
399 | const QChar *HlRegExpr::checkHgl(const QChar *s, int len, bool lineStart) | 404 | const QChar *HlRegExpr::checkHgl(const QChar *s, int len, bool lineStart) |
400 | { | 405 | { |
401 | if ((!lineStart) && handlesLinestart) return 0; | 406 | if ((!lineStart) && handlesLinestart) return 0; |
402 | 407 | ||
403 | QString line(s,len); | 408 | QString line(s,len); |
404 | int pos = Expr->search( line, 0 ); | 409 | int pos = Expr->search( line, 0 ); |
405 | if (pos==-1) return 0L; | 410 | if (pos==-1) return 0L; |
406 | else | 411 | else |
407 | return (s+Expr->matchedLength()); | 412 | return (s+Expr->matchedLength()); |
408 | }; | 413 | }; |
409 | 414 | ||
410 | 415 | ||
411 | HlLineContinue::HlLineContinue(int attribute, int context) | 416 | HlLineContinue::HlLineContinue(int attribute, int context) |
412 | : HlItem(attribute,context) { | 417 | : HlItem(attribute,context) { |
413 | } | 418 | } |
414 | 419 | ||
415 | const QChar *HlLineContinue::checkHgl(const QChar *s, int len, bool) { | 420 | const QChar *HlLineContinue::checkHgl(const QChar *s, int len, bool) { |
416 | 421 | ||
417 | if ((s[0].latin1() == '\\') && (len == 1)) | 422 | if ((s[0].latin1() == '\\') && (len == 1)) |
418 | { | 423 | { |
419 | return s + 1; | 424 | return s + 1; |
420 | } | 425 | } |
421 | return 0L; | 426 | return 0L; |
422 | } | 427 | } |
423 | 428 | ||
424 | 429 | ||
425 | HlCStringChar::HlCStringChar(int attribute, int context) | 430 | HlCStringChar::HlCStringChar(int attribute, int context) |
426 | : HlItem(attribute,context) { | 431 | : HlItem(attribute,context) { |
427 | } | 432 | } |
428 | 433 | ||
429 | //checks for hex and oct (for example \x1b or \033) | 434 | //checks for hex and oct (for example \x1b or \033) |
430 | const QChar *checkCharHexOct(const QChar *str) { | 435 | const QChar *checkCharHexOct(const QChar *str) { |
431 | const QChar *s; | 436 | const QChar *s; |
432 | s=str; | 437 | s=str; |
433 | int n; | 438 | int n; |
434 | if (*s == 'x') { | 439 | if (*s == 'x') { |
435 | n = 0; | 440 | n = 0; |
436 | do { | 441 | do { |
437 | s++; | 442 | s++; |
438 | n *= 16; | 443 | n *= 16; |
439 | if (s->isDigit()) n += *s - '0'; | 444 | if (s->isDigit()) n += *s - '0'; |
440 | else if ((*s&0xdf) >= 'A' && (*s&0xdf) <= 'F') n += (*s&0xdf) - 'A' + 10; | 445 | else if ((*s&0xdf) >= 'A' && (*s&0xdf) <= 'F') n += (*s&0xdf) - 'A' + 10; |
441 | // else if (*s >= 'a' && *s <= 'f') n += *s - 'a' + 10; | 446 | // else if (*s >= 'a' && *s <= 'f') n += *s - 'a' + 10; |
442 | else break; | 447 | else break; |
443 | if (n >= 256) return 0L; | 448 | if (n >= 256) return 0L; |
444 | } while (true); | 449 | } while (true); |
445 | if (s - str == 1) return 0L; | 450 | if (s - str == 1) return 0L; |
446 | } else { | 451 | } else { |
447 | if (!(*s >= '0' && *s <= '7')) return 0L; | 452 | if (!(*s >= '0' && *s <= '7')) return 0L; |
448 | n = *s - '0'; | 453 | n = *s - '0'; |
449 | do { | 454 | do { |
450 | s++; | 455 | s++; |
451 | n *= 8; | 456 | n *= 8; |
452 | if (*s >= '0' && *s <= '7') n += *s - '0'; else break; | 457 | if (*s >= '0' && *s <= '7') n += *s - '0'; else break; |
453 | if (n >= 256) return s; | 458 | if (n >= 256) return s; |
454 | } while (s - str < 3); | 459 | } while (s - str < 3); |
455 | } | 460 | } |
456 | return s; | 461 | return s; |
457 | } | 462 | } |
458 | // checks for C escaped chars \n and escaped hex/octal chars | 463 | // checks for C escaped chars \n and escaped hex/octal chars |
459 | const QChar *checkEscapedChar(const QChar *s, int len) { | 464 | const QChar *checkEscapedChar(const QChar *s, int len) { |
460 | int i; | 465 | int i; |
461 | if (s[0] == '\\' && (len > 1) ) { | 466 | if (s[0] == '\\' && (len > 1) ) { |
462 | s++; | 467 | s++; |
463 | switch(*s){ | 468 | switch(*s){ |
464 | case 'a': // checks for control chars | 469 | case 'a': // checks for control chars |
465 | case 'b': // we want to fall through | 470 | case 'b': // we want to fall through |
466 | case 'e': | 471 | case 'e': |
467 | case 'f': | 472 | case 'f': |
468 | 473 | ||
469 | case 'n': | 474 | case 'n': |
470 | case 'r': | 475 | case 'r': |
471 | case 't': | 476 | case 't': |
472 | case 'v': | 477 | case 'v': |
473 | case '\'': | 478 | case '\'': |
474 | case '\"': | 479 | case '\"': |
475 | case '?' : // added ? ANSI C classifies this as an escaped char | 480 | case '?' : // added ? ANSI C classifies this as an escaped char |
476 | case '\\': s++; | 481 | case '\\': s++; |
477 | break; | 482 | break; |
478 | case 'x': // if it's like \xff | 483 | case 'x': // if it's like \xff |
479 | s++; // eat the x | 484 | s++; // eat the x |
480 | // these for loops can probably be | 485 | // these for loops can probably be |
481 | // replaced with something else but | 486 | // replaced with something else but |
482 | // for right now they work | 487 | // for right now they work |
483 | // check for hexdigits | 488 | // check for hexdigits |
484 | for(i=0;i<2 &&(*s >= '0' && *s <= '9' || (*s&0xdf) >= 'A' && (*s&0xdf) <= 'F');i++,s++); | 489 | for(i=0;i<2 &&(*s >= '0' && *s <= '9' || (*s&0xdf) >= 'A' && (*s&0xdf) <= 'F');i++,s++); |
485 | if(i==0) return 0L; // takes care of case '\x' | 490 | if(i==0) return 0L; // takes care of case '\x' |
486 | break; | 491 | break; |
487 | 492 | ||
488 | case '0': case '1': case '2': case '3' : | 493 | case '0': case '1': case '2': case '3' : |
489 | case '4': case '5': case '6': case '7' : | 494 | case '4': case '5': case '6': case '7' : |
490 | for(i=0;i < 3 &&(*s >='0'&& *s<='7');i++,s++); | 495 | for(i=0;i < 3 &&(*s >='0'&& *s<='7');i++,s++); |
491 | break; | 496 | break; |
492 | default: return 0L; | 497 | default: return 0L; |
493 | } | 498 | } |
494 | return s; | 499 | return s; |
495 | } | 500 | } |
496 | return 0L; | 501 | return 0L; |
497 | } | 502 | } |
498 | 503 | ||
499 | const QChar *HlCStringChar::checkHgl(const QChar *str, int len, bool) { | 504 | const QChar *HlCStringChar::checkHgl(const QChar *str, int len, bool) { |
500 | return checkEscapedChar(str, len); | 505 | return checkEscapedChar(str, len); |
501 | } | 506 | } |
502 | 507 | ||
503 | 508 | ||
504 | HlCChar::HlCChar(int attribute, int context) | 509 | HlCChar::HlCChar(int attribute, int context) |
505 | : HlItem(attribute,context) { | 510 | : HlItem(attribute,context) { |
506 | } | 511 | } |
507 | 512 | ||
508 | const QChar *HlCChar::checkHgl(const QChar *str, int len, bool) { | 513 | const QChar *HlCChar::checkHgl(const QChar *str, int len, bool) { |
509 | const QChar *s; | 514 | const QChar *s; |
510 | 515 | ||
511 | if ((len > 1) && (str[0] == '\'') && (str[1] != '\'')) | 516 | if ((len > 1) && (str[0] == '\'') && (str[1] != '\'')) |
512 | { | 517 | { |
513 | s = checkEscapedChar(&str[1], len); //try to match escaped char | 518 | s = checkEscapedChar(&str[1], len); //try to match escaped char |
514 | if (!s) s = &str[2]; //match single non-escaped char | 519 | if (!s) s = &str[2]; //match single non-escaped char |
515 | if (*s == '\'') return s + 1; | 520 | if (*s == '\'') return s + 1; |
516 | } | 521 | } |
517 | return 0L; | 522 | return 0L; |
518 | } | 523 | } |
519 | 524 | ||
520 | 525 | ||
521 | //-------- | 526 | //-------- |
522 | ItemStyle::ItemStyle() : selCol(Qt::white), bold(false), italic(false) { | 527 | ItemStyle::ItemStyle() : selCol(Qt::white), bold(false), italic(false) { |
523 | } | 528 | } |
524 | 529 | ||
525 | ItemStyle::ItemStyle(const QColor &col, const QColor &selCol, | 530 | ItemStyle::ItemStyle(const QColor &col, const QColor &selCol, |
526 | bool bold, bool italic) | 531 | bool bold, bool italic) |
527 | : col(col), selCol(selCol), bold(bold), italic(italic) { | 532 | : col(col), selCol(selCol), bold(bold), italic(italic) { |
528 | } | 533 | } |
529 | 534 | ||
530 | ItemData::ItemData(const QString name, int defStyleNum) | 535 | ItemData::ItemData(const QString name, int defStyleNum) |
531 | : name(name), defStyleNum(defStyleNum), defStyle(true) { | 536 | : name(name), defStyleNum(defStyleNum), defStyle(true) { |
532 | } | 537 | } |
533 | 538 | ||
534 | ItemData::ItemData(const QString name, int defStyleNum, | 539 | ItemData::ItemData(const QString name, int defStyleNum, |
535 | const QColor &col, const QColor &selCol, bool bold, bool italic) | 540 | const QColor &col, const QColor &selCol, bool bold, bool italic) |
536 | : ItemStyle(col,selCol,bold,italic), name(name), defStyleNum(defStyleNum), | 541 | : ItemStyle(col,selCol,bold,italic), name(name), defStyleNum(defStyleNum), |
537 | defStyle(false) { | 542 | defStyle(false) { |
538 | } | 543 | } |
539 | 544 | ||
540 | HlData::HlData(const QString &wildcards, const QString &mimetypes, const QString &identifier) | 545 | HlData::HlData(const QString &wildcards, const QString &mimetypes, const QString &identifier) |
541 | : wildcards(wildcards), mimetypes(mimetypes), identifier(identifier) { | 546 | : wildcards(wildcards), mimetypes(mimetypes), identifier(identifier) { |
542 | 547 | ||
543 | //JW itemDataList.setAutoDelete(true); | 548 | //JW itemDataList.setAutoDelete(true); |
544 | } | 549 | } |
545 | 550 | ||
546 | HlContext::HlContext(int attribute, int lineEndContext, int _lineBeginContext) | 551 | HlContext::HlContext(int attribute, int lineEndContext, int _lineBeginContext) |
547 | : attr(attribute), ctx(lineEndContext),lineBeginContext(_lineBeginContext) { | 552 | : attr(attribute), ctx(lineEndContext),lineBeginContext(_lineBeginContext) { |
548 | items.setAutoDelete(true); | 553 | items.setAutoDelete(true); |
549 | } | 554 | } |
550 | 555 | ||
551 | Hl2CharDetect::Hl2CharDetect(int attribute, int context, const QChar *s) | 556 | Hl2CharDetect::Hl2CharDetect(int attribute, int context, const QChar *s) |
552 | : HlItem(attribute,context) { | 557 | : HlItem(attribute,context) { |
553 | sChar1 = s[0]; | 558 | sChar1 = s[0]; |
554 | sChar2 = s[1]; | 559 | sChar2 = s[1]; |
555 | } | 560 | } |
556 | 561 | ||
557 | Highlight::Highlight(syntaxModeListItem *def) : refCount(0) | 562 | Highlight::Highlight(syntaxModeListItem *def) : refCount(0) |
558 | { | 563 | { |
559 | noHl = false; | 564 | noHl = false; |
560 | 565 | ||
561 | if (def == 0) | 566 | if (def == 0) |
562 | { | 567 | { |
563 | noHl = true; | 568 | noHl = true; |
564 | iName = I18N_NOOP("Normal"); | 569 | iName = I18N_NOOP("Normal"); |
565 | iSection = ""; | 570 | iSection = ""; |
566 | } | 571 | } |
567 | else | 572 | else |
568 | { | 573 | { |
569 | iName = def->name; | 574 | iName = def->name; |
570 | iSection = def->section; | 575 | iSection = def->section; |
571 | iWildcards = def->extension; | 576 | iWildcards = def->extension; |
572 | iMimetypes = def->mimetype; | 577 | iMimetypes = def->mimetype; |
573 | identifier = def->identifier; | 578 | identifier = def->identifier; |
574 | } | 579 | } |
575 | deliminator = stdDeliminator; | 580 | deliminator = stdDeliminator; |
576 | deliminatorChars = deliminator.unicode(); | 581 | deliminatorChars = deliminator.unicode(); |
577 | deliminatorLen = deliminator.length(); | 582 | deliminatorLen = deliminator.length(); |
578 | } | 583 | } |
579 | 584 | ||
580 | Highlight::~Highlight() | 585 | Highlight::~Highlight() |
581 | { | 586 | { |
582 | } | 587 | } |
583 | 588 | ||
584 | int Highlight::doHighlight(int ctxNum, TextLine *textLine) | 589 | int Highlight::doHighlight(int ctxNum, TextLine *textLine) |
585 | { | 590 | { |
586 | if (noHl) | 591 | if (noHl) |
587 | { | 592 | { |
588 | textLine->setAttribs(0,0,textLine->length()); | 593 | textLine->setAttribs(0,0,textLine->length()); |
589 | textLine->setAttr(0); | 594 | textLine->setAttr(0); |
590 | return 0; | 595 | return 0; |
591 | } | 596 | } |
592 | 597 | ||
593 | HlContext *context; | 598 | HlContext *context; |
594 | const QChar *s2; | 599 | const QChar *s2; |
595 | HlItem *item; | 600 | HlItem *item; |
596 | 601 | ||
597 | context = contextList[ctxNum]; | 602 | context = contextList[ctxNum]; |
598 | if (context->lineBeginContext!=-1) | 603 | if (context->lineBeginContext!=-1) |
599 | { | 604 | { |
600 | ctxNum=context->lineBeginContext; | 605 | ctxNum=context->lineBeginContext; |
601 | context=contextList[ctxNum]; | 606 | context=contextList[ctxNum]; |
602 | } | 607 | } |
603 | 608 | ||
604 | QChar lastChar = ' '; | 609 | QChar lastChar = ' '; |
605 | 610 | ||
606 | // first char | 611 | // first char |
607 | const QChar *str = textLine->getText(); | 612 | const QChar *str = textLine->getText(); |
608 | 613 | ||
609 | // non space char - index of that char | 614 | // non space char - index of that char |
610 | const QChar *s1 = textLine->firstNonSpace(); | 615 | const QChar *s1 = textLine->firstNonSpace(); |
611 | uint z = textLine->firstChar(); | 616 | uint z = textLine->firstChar(); |
612 | 617 | ||
613 | // length of textline | 618 | // length of textline |
614 | uint len = textLine->length(); | 619 | uint len = textLine->length(); |
615 | 620 | ||
616 | bool found = false; | 621 | bool found = false; |
617 | while (z < len) | 622 | while (z < len) |
618 | { | 623 | { |
619 | found = false; | 624 | found = false; |
620 | 625 | ||
621 | for (item = context->items.first(); item != 0L; item = context->items.next()) | 626 | for (item = context->items.first(); item != 0L; item = context->items.next()) |
622 | { | 627 | { |
623 | if (item->startEnable(lastChar)) | 628 | if (item->startEnable(lastChar)) |
624 | { | 629 | { |
625 | s2 = item->checkHgl(s1, len-z, z==0); | 630 | s2 = item->checkHgl(s1, len-z, z==0); |
626 | if (s2 > s1) | 631 | if (s2 > s1) |
627 | { | 632 | { |
628 | odebug << "An item has been detected" << oendl; | 633 | odebug << "An item has been detected" << oendl; |
629 | textLine->setAttribs(item->attr,s1 - str,s2 - str); | 634 | textLine->setAttribs(item->attr,s1 - str,s2 - str); |
630 | ctxNum = item->ctx; | 635 | ctxNum = item->ctx; |
631 | context = contextList[ctxNum]; | 636 | context = contextList[ctxNum]; |
632 | z = z + s2 - s1 - 1; | 637 | z = z + s2 - s1 - 1; |
633 | s1 = s2 - 1; | 638 | s1 = s2 - 1; |
634 | found = true; | 639 | found = true; |
635 | break; | 640 | break; |
636 | } | 641 | } |
637 | } | 642 | } |
638 | } | 643 | } |
639 | 644 | ||
640 | // nothing found: set attribute of one char | 645 | // nothing found: set attribute of one char |
641 | if (!found) | 646 | if (!found) |
642 | textLine->setAttribs(context->attr,s1 - str,s1 - str + 1); | 647 | textLine->setAttribs(context->attr,s1 - str,s1 - str + 1); |
643 | 648 | ||
644 | lastChar = *s1; | 649 | lastChar = *s1; |
645 | s1++; | 650 | s1++; |
646 | z++; | 651 | z++; |
647 | } | 652 | } |
648 | 653 | ||
649 | //set "end of line"-properties | 654 | //set "end of line"-properties |
650 | textLine->setAttr(context->attr); | 655 | textLine->setAttr(context->attr); |
651 | 656 | ||
652 | //return new context | 657 | //return new context |
653 | return context->ctx; | 658 | return context->ctx; |
654 | } | 659 | } |
diff --git a/noncore/apps/tinykate/libkate/document/katehighlight.h b/noncore/apps/tinykate/libkate/document/katehighlight.h index fddf585..f0be27b 100644 --- a/noncore/apps/tinykate/libkate/document/katehighlight.h +++ b/noncore/apps/tinykate/libkate/document/katehighlight.h | |||
@@ -1,349 +1,349 @@ | |||
1 | /* | 1 | /* |
2 | Copyright (C) 1998, 1999 Jochen Wilhelmy | 2 | Copyright (C) 1998, 1999 Jochen Wilhelmy |
3 | digisnap@cs.tu-berlin.de | 3 | digisnap@cs.tu-berlin.de |
4 | (C) 2002, 2001 The Kate Team <kwrite-devel@kde.org> | 4 | (C) 2002, 2001 The Kate Team <kwrite-devel@kde.org> |
5 | (C) 2002 Joseph Wenninger <jowenn@kde.org> | 5 | (C) 2002 Joseph Wenninger <jowenn@kde.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #ifndef _HIGHLIGHT_H_ | 23 | #ifndef _HIGHLIGHT_H_ |
24 | #define _HIGHLIGHT_H_ | 24 | #define _HIGHLIGHT_H_ |
25 | 25 | ||
26 | #include <qlist.h> | 26 | #include <qlist.h> |
27 | #include <qdialog.h> | 27 | #include <qdialog.h> |
28 | 28 | ||
29 | #include <kcolorbtn.h> | 29 | #include <kcolorbtn.h> |
30 | #include <qstrvec.h> | 30 | #include <qstrvec.h> |
31 | #include <qdict.h> | 31 | #include <qdict.h> |
32 | #include <qregexp.h> | 32 | #include <qregexp.h> |
33 | #include "../qt3back/qregexp3.h" | 33 | #include "../qt3back/qregexp3.h" |
34 | #include <kdebug.h> | 34 | #include <kdebug.h> |
35 | 35 | ||
36 | class SyntaxDocument; | 36 | class SyntaxDocument; |
37 | struct syntaxModeListItem; | 37 | struct syntaxModeListItem; |
38 | struct syntaxContextData; | 38 | struct syntaxContextData; |
39 | 39 | ||
40 | class QCheckBox; | 40 | class QCheckBox; |
41 | class QComboBox; | 41 | class QComboBox; |
42 | class QLineEdit; | 42 | class QLineEdit; |
43 | 43 | ||
44 | class TextLine; | 44 | class TextLine; |
45 | class Attribute; | 45 | class Attribute; |
46 | 46 | ||
47 | class HlItem { | 47 | class HlItem { |
48 | public: | 48 | public: |
49 | HlItem(int attribute, int context); | 49 | HlItem(int attribute, int context); |
50 | virtual ~HlItem(); | 50 | virtual ~HlItem(); |
51 | virtual bool startEnable(QChar); | 51 | virtual bool startEnable(QChar); |
52 | virtual const QChar *checkHgl(const QChar *, int len, bool) = 0; | 52 | virtual const QChar *checkHgl(const QChar *, int len, bool) = 0; |
53 | QList<HlItem> *subItems; | 53 | QList<HlItem> *subItems; |
54 | int attr; | 54 | int attr; |
55 | int ctx; | 55 | int ctx; |
56 | }; | 56 | }; |
57 | 57 | ||
58 | class HlCharDetect : public HlItem { | 58 | class HlCharDetect : public HlItem { |
59 | public: | 59 | public: |
60 | HlCharDetect(int attribute, int context, QChar); | 60 | HlCharDetect(int attribute, int context, QChar); |
61 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 61 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
62 | protected: | 62 | protected: |
63 | QChar sChar; | 63 | QChar sChar; |
64 | }; | 64 | }; |
65 | 65 | ||
66 | class Hl2CharDetect : public HlItem { | 66 | class Hl2CharDetect : public HlItem { |
67 | public: | 67 | public: |
68 | Hl2CharDetect(int attribute, int context, QChar ch1, QChar ch2); | 68 | Hl2CharDetect(int attribute, int context, QChar ch1, QChar ch2); |
69 | Hl2CharDetect(int attribute, int context, const QChar *ch); | 69 | Hl2CharDetect(int attribute, int context, const QChar *ch); |
70 | 70 | ||
71 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 71 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
72 | protected: | 72 | protected: |
73 | QChar sChar1; | 73 | QChar sChar1; |
74 | QChar sChar2; | 74 | QChar sChar2; |
75 | }; | 75 | }; |
76 | 76 | ||
77 | class HlStringDetect : public HlItem { | 77 | class HlStringDetect : public HlItem { |
78 | public: | 78 | public: |
79 | HlStringDetect(int attribute, int context, const QString &, bool inSensitive=false); | 79 | HlStringDetect(int attribute, int context, const QString &, bool inSensitive=false); |
80 | virtual ~HlStringDetect(); | 80 | virtual ~HlStringDetect(); |
81 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 81 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
82 | protected: | 82 | protected: |
83 | const QString str; | 83 | const QString str; |
84 | bool _inSensitive; | 84 | bool _inSensitive; |
85 | }; | 85 | }; |
86 | 86 | ||
87 | class HlRangeDetect : public HlItem { | 87 | class HlRangeDetect : public HlItem { |
88 | public: | 88 | public: |
89 | HlRangeDetect(int attribute, int context, QChar ch1, QChar ch2); | 89 | HlRangeDetect(int attribute, int context, QChar ch1, QChar ch2); |
90 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 90 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
91 | protected: | 91 | protected: |
92 | QChar sChar1; | 92 | QChar sChar1; |
93 | QChar sChar2; | 93 | QChar sChar2; |
94 | }; | 94 | }; |
95 | 95 | ||
96 | class HlKeyword : public HlItem | 96 | class HlKeyword : public HlItem |
97 | { | 97 | { |
98 | public: | 98 | public: |
99 | HlKeyword(int attribute, int context,bool casesensitive, const QChar *deliminator, uint deliLen); | 99 | HlKeyword(int attribute, int context,bool casesensitive, const QChar *deliminator, uint deliLen); |
100 | virtual ~HlKeyword(); | 100 | virtual ~HlKeyword(); |
101 | 101 | ||
102 | virtual void addWord(const QString &); | 102 | virtual void addWord(const QString &); |
103 | virtual void addList(const QStringList &); | 103 | virtual void addList(const QStringList &); |
104 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 104 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
105 | QStringList getList() { return words;}; | 105 | QStringList getList() { return words;}; |
106 | virtual bool startEnable(QChar c); | 106 | virtual bool startEnable(QChar c); |
107 | 107 | ||
108 | protected: | 108 | protected: |
109 | QStringList words; | 109 | QStringList words; |
110 | QDict<bool> dict; | 110 | QDict<bool> dict; |
111 | bool _caseSensitive; | 111 | bool _caseSensitive; |
112 | const QChar *deliminatorChars; | 112 | const QChar *deliminatorChars; |
113 | uint deliminatorLen; | 113 | uint deliminatorLen; |
114 | }; | 114 | }; |
115 | 115 | ||
116 | class HlPHex : public HlItem { | 116 | class HlPHex : public HlItem { |
117 | public: | 117 | public: |
118 | HlPHex(int attribute,int context); | 118 | HlPHex(int attribute,int context); |
119 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 119 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
120 | }; | 120 | }; |
121 | class HlInt : public HlItem { | 121 | class HlInt : public HlItem { |
122 | public: | 122 | public: |
123 | HlInt(int attribute, int context); | 123 | HlInt(int attribute, int context); |
124 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 124 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
125 | }; | 125 | }; |
126 | 126 | ||
127 | class HlFloat : public HlItem { | 127 | class HlFloat : public HlItem { |
128 | public: | 128 | public: |
129 | HlFloat(int attribute, int context); | 129 | HlFloat(int attribute, int context); |
130 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 130 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
131 | }; | 131 | }; |
132 | 132 | ||
133 | class HlCInt : public HlInt { | 133 | class HlCInt : public HlInt { |
134 | public: | 134 | public: |
135 | HlCInt(int attribute, int context); | 135 | HlCInt(int attribute, int context); |
136 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 136 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
137 | }; | 137 | }; |
138 | 138 | ||
139 | class HlCOct : public HlItem { | 139 | class HlCOct : public HlItem { |
140 | public: | 140 | public: |
141 | HlCOct(int attribute, int context); | 141 | HlCOct(int attribute, int context); |
142 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 142 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
143 | }; | 143 | }; |
144 | 144 | ||
145 | class HlCHex : public HlItem { | 145 | class HlCHex : public HlItem { |
146 | public: | 146 | public: |
147 | HlCHex(int attribute, int context); | 147 | HlCHex(int attribute, int context); |
148 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 148 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
149 | }; | 149 | }; |
150 | 150 | ||
151 | class HlCFloat : public HlFloat { | 151 | class HlCFloat : public HlFloat { |
152 | public: | 152 | public: |
153 | HlCFloat(int attribute, int context); | 153 | HlCFloat(int attribute, int context); |
154 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 154 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
155 | }; | 155 | }; |
156 | 156 | ||
157 | class HlLineContinue : public HlItem { | 157 | class HlLineContinue : public HlItem { |
158 | public: | 158 | public: |
159 | HlLineContinue(int attribute, int context); | 159 | HlLineContinue(int attribute, int context); |
160 | virtual bool endEnable(QChar c) {return c == '\0';} | 160 | virtual bool endEnable(QChar c) {return c == '\0';} |
161 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 161 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
162 | }; | 162 | }; |
163 | 163 | ||
164 | class HlCStringChar : public HlItem { | 164 | class HlCStringChar : public HlItem { |
165 | public: | 165 | public: |
166 | HlCStringChar(int attribute, int context); | 166 | HlCStringChar(int attribute, int context); |
167 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 167 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
168 | }; | 168 | }; |
169 | 169 | ||
170 | class HlCChar : public HlItem { | 170 | class HlCChar : public HlItem { |
171 | public: | 171 | public: |
172 | HlCChar(int attribute, int context); | 172 | HlCChar(int attribute, int context); |
173 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 173 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
174 | }; | 174 | }; |
175 | 175 | ||
176 | class HlAnyChar : public HlItem { | 176 | class HlAnyChar : public HlItem { |
177 | public: | 177 | public: |
178 | HlAnyChar(int attribute, int context, const QChar* charList, uint len); | 178 | HlAnyChar(int attribute, int context, const QChar* charList, uint len); |
179 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 179 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
180 | const QChar* _charList; | 180 | const QChar* _charList; |
181 | uint _charListLen; | 181 | uint _charListLen; |
182 | }; | 182 | }; |
183 | 183 | ||
184 | class HlRegExpr : public HlItem { | 184 | class HlRegExpr : public HlItem { |
185 | public: | 185 | public: |
186 | HlRegExpr(int attribute, int context,QString expr); | 186 | HlRegExpr(int attribute, int context,QString expr); |
187 | ~HlRegExpr(){delete Expr;}; | 187 | ~HlRegExpr(); |
188 | virtual const QChar *checkHgl(const QChar *, int len, bool); | 188 | virtual const QChar *checkHgl(const QChar *, int len, bool); |
189 | QRegExp3 *Expr; | 189 | QRegExp3 *Expr; |
190 | bool handlesLinestart; | 190 | bool handlesLinestart; |
191 | }; | 191 | }; |
192 | 192 | ||
193 | //-------- | 193 | //-------- |
194 | 194 | ||
195 | 195 | ||
196 | //Item Style: color, selected color, bold, italic | 196 | //Item Style: color, selected color, bold, italic |
197 | class ItemStyle { | 197 | class ItemStyle { |
198 | public: | 198 | public: |
199 | ItemStyle(); | 199 | ItemStyle(); |
200 | // ItemStyle(const ItemStyle &); | 200 | // ItemStyle(const ItemStyle &); |
201 | ItemStyle(const QColor &, const QColor &, bool bold, bool italic); | 201 | ItemStyle(const QColor &, const QColor &, bool bold, bool italic); |
202 | ItemStyle(ItemStyle *its){col=its->col;selCol=its->selCol; bold=its->bold; italic=its->italic;} | 202 | ItemStyle(ItemStyle *its){col=its->col;selCol=its->selCol; bold=its->bold; italic=its->italic;} |
203 | // void setData(const ItemStyle &); | 203 | // void setData(const ItemStyle &); |
204 | QColor col; | 204 | QColor col; |
205 | QColor selCol; | 205 | QColor selCol; |
206 | int bold; //boolean value | 206 | int bold; //boolean value |
207 | int italic; //boolean value | 207 | int italic; //boolean value |
208 | }; | 208 | }; |
209 | 209 | ||
210 | typedef QList<ItemStyle> ItemStyleList; | 210 | typedef QList<ItemStyle> ItemStyleList; |
211 | 211 | ||
212 | //Item Properties: name, Item Style, Item Font | 212 | //Item Properties: name, Item Style, Item Font |
213 | class ItemData : public ItemStyle { | 213 | class ItemData : public ItemStyle { |
214 | public: | 214 | public: |
215 | ItemData(const QString name, int defStyleNum); | 215 | ItemData(const QString name, int defStyleNum); |
216 | ItemData(const QString name, int defStyleNum, | 216 | ItemData(const QString name, int defStyleNum, |
217 | const QColor&, const QColor&, bool bold, bool italic); | 217 | const QColor&, const QColor&, bool bold, bool italic); |
218 | ItemData(ItemData | 218 | ItemData(ItemData |
219 | *itd):ItemStyle((ItemStyle*)itd),name(itd->name),defStyleNum(itd->defStyleNum),defStyle(itd->defStyle){;} | 219 | *itd):ItemStyle((ItemStyle*)itd),name(itd->name),defStyleNum(itd->defStyleNum),defStyle(itd->defStyle){;} |
220 | const QString name; | 220 | const QString name; |
221 | int defStyleNum; | 221 | int defStyleNum; |
222 | int defStyle; //boolean value | 222 | int defStyle; //boolean value |
223 | }; | 223 | }; |
224 | 224 | ||
225 | typedef QList<ItemData> ItemDataList; | 225 | typedef QList<ItemData> ItemDataList; |
226 | 226 | ||
227 | class HlData { | 227 | class HlData { |
228 | public: | 228 | public: |
229 | HlData(const QString &wildcards, const QString &mimetypes,const QString &identifier); | 229 | HlData(const QString &wildcards, const QString &mimetypes,const QString &identifier); |
230 | ItemDataList itemDataList; | 230 | ItemDataList itemDataList; |
231 | QString wildcards; | 231 | QString wildcards; |
232 | QString mimetypes; | 232 | QString mimetypes; |
233 | QString identifier; | 233 | QString identifier; |
234 | }; | 234 | }; |
235 | 235 | ||
236 | typedef QList<HlData> HlDataList; | 236 | typedef QList<HlData> HlDataList; |
237 | 237 | ||
238 | class HlManager; | 238 | class HlManager; |
239 | class KateConfig; | 239 | class KateConfig; |
240 | 240 | ||
241 | //context | 241 | //context |
242 | class HlContext { | 242 | class HlContext { |
243 | public: | 243 | public: |
244 | HlContext(int attribute, int lineEndContext,int _lineBeginContext); | 244 | HlContext(int attribute, int lineEndContext,int _lineBeginContext); |
245 | QList<HlItem> items; | 245 | QList<HlItem> items; |
246 | int attr; | 246 | int attr; |
247 | int ctx; | 247 | int ctx; |
248 | int lineBeginContext; | 248 | int lineBeginContext; |
249 | }; | 249 | }; |
250 | 250 | ||
251 | class Highlight | 251 | class Highlight |
252 | { | 252 | { |
253 | friend class HlManager; | 253 | friend class HlManager; |
254 | 254 | ||
255 | public: | 255 | public: |
256 | Highlight(syntaxModeListItem *def); | 256 | Highlight(syntaxModeListItem *def); |
257 | ~Highlight(); | 257 | ~Highlight(); |
258 | 258 | ||
259 | int doHighlight(int ctxNum, TextLine *); | 259 | int doHighlight(int ctxNum, TextLine *); |
260 | 260 | ||
261 | KateConfig *getKateConfig(); | 261 | KateConfig *getKateConfig(); |
262 | QString getWildcards(); | 262 | QString getWildcards(); |
263 | QString getMimetypes(); | 263 | QString getMimetypes(); |
264 | HlData *getData(); | 264 | HlData *getData(); |
265 | void setData(HlData *); | 265 | void setData(HlData *); |
266 | void getItemDataList(ItemDataList &); | 266 | void getItemDataList(ItemDataList &); |
267 | void getItemDataList(ItemDataList &, KateConfig *); | 267 | void getItemDataList(ItemDataList &, KateConfig *); |
268 | void setItemDataList(ItemDataList &, KateConfig *); | 268 | void setItemDataList(ItemDataList &, KateConfig *); |
269 | QString name() {return iName;} | 269 | QString name() {return iName;} |
270 | QString section() {return iSection;} | 270 | QString section() {return iSection;} |
271 | void use(); | 271 | void use(); |
272 | void release(); | 272 | void release(); |
273 | bool isInWord(QChar c); | 273 | bool isInWord(QChar c); |
274 | 274 | ||
275 | QString getCommentStart() {return cmlStart;}; | 275 | QString getCommentStart() {return cmlStart;}; |
276 | QString getCommentEnd() {return cmlEnd;}; | 276 | QString getCommentEnd() {return cmlEnd;}; |
277 | QString getCommentSingleLineStart() { return cslStart;}; | 277 | QString getCommentSingleLineStart() { return cslStart;}; |
278 | 278 | ||
279 | protected: | 279 | protected: |
280 | void init(); | 280 | void init(); |
281 | void done(); | 281 | void done(); |
282 | void makeContextList (); | 282 | void makeContextList (); |
283 | void createItemData (ItemDataList &list); | 283 | void createItemData (ItemDataList &list); |
284 | void readGlobalKeywordConfig(); | 284 | void readGlobalKeywordConfig(); |
285 | void readCommentConfig(); | 285 | void readCommentConfig(); |
286 | HlItem *createHlItem(struct syntaxContextData *data, ItemDataList &iDl); | 286 | HlItem *createHlItem(struct syntaxContextData *data, ItemDataList &iDl); |
287 | int lookupAttrName(const QString& name, ItemDataList &iDl); | 287 | int lookupAttrName(const QString& name, ItemDataList &iDl); |
288 | ItemDataList internalIDList; | 288 | ItemDataList internalIDList; |
289 | static const int nContexts = 32; | 289 | static const int nContexts = 32; |
290 | HlContext *contextList[nContexts]; | 290 | HlContext *contextList[nContexts]; |
291 | 291 | ||
292 | bool noHl; | 292 | bool noHl; |
293 | bool casesensitive; | 293 | bool casesensitive; |
294 | QString weakDeliminator; | 294 | QString weakDeliminator; |
295 | QString deliminator; | 295 | QString deliminator; |
296 | const QChar *deliminatorChars; | 296 | const QChar *deliminatorChars; |
297 | uint deliminatorLen; | 297 | uint deliminatorLen; |
298 | QString cmlStart; | 298 | QString cmlStart; |
299 | QString cmlEnd; | 299 | QString cmlEnd; |
300 | QString cslStart; | 300 | QString cslStart; |
301 | QString iName; | 301 | QString iName; |
302 | QString iSection; | 302 | QString iSection; |
303 | QString iWildcards; | 303 | QString iWildcards; |
304 | QString iMimetypes; | 304 | QString iMimetypes; |
305 | QString identifier; | 305 | QString identifier; |
306 | int refCount; | 306 | int refCount; |
307 | }; | 307 | }; |
308 | 308 | ||
309 | class HlManager : public QObject { | 309 | class HlManager : public QObject { |
310 | Q_OBJECT | 310 | Q_OBJECT |
311 | public: | 311 | public: |
312 | HlManager(); | 312 | HlManager(); |
313 | ~HlManager(); | 313 | ~HlManager(); |
314 | 314 | ||
315 | static HlManager *self(); | 315 | static HlManager *self(); |
316 | 316 | ||
317 | Highlight *getHl(int n); | 317 | Highlight *getHl(int n); |
318 | int defaultHl(); | 318 | int defaultHl(); |
319 | int nameFind(const QString &name); | 319 | int nameFind(const QString &name); |
320 | 320 | ||
321 | int wildcardFind(const QString &fileName); | 321 | int wildcardFind(const QString &fileName); |
322 | int findHl(Highlight *h) {return hlList.find(h);} | 322 | int findHl(Highlight *h) {return hlList.find(h);} |
323 | 323 | ||
324 | int makeAttribs(Highlight *, Attribute *, int maxAttribs); | 324 | int makeAttribs(Highlight *, Attribute *, int maxAttribs); |
325 | 325 | ||
326 | int defaultStyles(); | 326 | int defaultStyles(); |
327 | QString defaultStyleName(int n); | 327 | QString defaultStyleName(int n); |
328 | void getDefaults(ItemStyleList &); | 328 | void getDefaults(ItemStyleList &); |
329 | void setDefaults(ItemStyleList &); | 329 | void setDefaults(ItemStyleList &); |
330 | 330 | ||
331 | int highlights(); | 331 | int highlights(); |
332 | QString hlName(int n); | 332 | QString hlName(int n); |
333 | QString hlSection(int n); | 333 | QString hlSection(int n); |
334 | void getHlDataList(HlDataList &); | 334 | void getHlDataList(HlDataList &); |
335 | void setHlDataList(HlDataList &); | 335 | void setHlDataList(HlDataList &); |
336 | 336 | ||
337 | SyntaxDocument *syntax; | 337 | SyntaxDocument *syntax; |
338 | 338 | ||
339 | signals: | 339 | signals: |
340 | void changed(); | 340 | void changed(); |
341 | protected: | 341 | protected: |
342 | QList<Highlight> hlList; | 342 | QList<Highlight> hlList; |
343 | static HlManager *s_pSelf; | 343 | static HlManager *s_pSelf; |
344 | }; | 344 | }; |
345 | 345 | ||
346 | 346 | ||
347 | 347 | ||
348 | 348 | ||
349 | #endif //_HIGHLIGHT_H_ | 349 | #endif //_HIGHLIGHT_H_ |