author | erik <erik> | 2007-01-10 17:31:08 (UTC) |
---|---|---|
committer | erik <erik> | 2007-01-10 17:31:08 (UTC) |
commit | 6825f30b665952864dbe35fe8329a0e4c264d4b8 (patch) (unidiff) | |
tree | 7c8d178f835d4a7d294b6ef65e0040c40579e84e | |
parent | d8e580a239ab84fbe063b2f3779d417598d5ca0a (diff) | |
download | opie-6825f30b665952864dbe35fe8329a0e4c264d4b8.zip opie-6825f30b665952864dbe35fe8329a0e4c264d4b8.tar.gz opie-6825f30b665952864dbe35fe8329a0e4c264d4b8.tar.bz2 |
All of the files included have instances where an array is new'ed but
the corresponding delete does not have the corresponding [] argument.
-rw-r--r-- | core/apps/embeddedkonsole/TEScreen.cpp | 4 | ||||
-rw-r--r-- | noncore/apps/checkbook/listedit.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/opie-console/TEScreen.cpp | 4 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/Excel.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/tinykate/libkate/document/katedocument.cpp | 4 | ||||
-rw-r--r-- | noncore/comm/keypebble/krfbdecoder.cpp | 6 | ||||
-rw-r--r-- | noncore/games/sfcave/sfcave.cpp | 2 | ||||
-rw-r--r-- | noncore/settings/aqpkg/settingsimpl.cpp | 2 | ||||
-rw-r--r-- | noncore/settings/aqpkg/version.cpp | 2 |
9 files changed, 14 insertions, 14 deletions
diff --git a/core/apps/embeddedkonsole/TEScreen.cpp b/core/apps/embeddedkonsole/TEScreen.cpp index 8e69a88..1db34d2 100644 --- a/core/apps/embeddedkonsole/TEScreen.cpp +++ b/core/apps/embeddedkonsole/TEScreen.cpp | |||
@@ -1,1236 +1,1236 @@ | |||
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 | { | 69 | { |
70 | this->lines = lines; | 70 | this->lines = lines; |
71 | this->columns = columns; | 71 | this->columns = columns; |
72 | // odebug << "Columns " << columns << "" << oendl; | 72 | // odebug << "Columns " << columns << "" << oendl; |
73 | 73 | ||
74 | image = (ca*) malloc(lines*columns*sizeof(ca)); | 74 | image = (ca*) malloc(lines*columns*sizeof(ca)); |
75 | tabstops = NULL; initTabStops(); | 75 | tabstops = NULL; initTabStops(); |
76 | 76 | ||
77 | histCursor = 0; | 77 | histCursor = 0; |
78 | horzCursor = 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 | free(image); |
90 | if (tabstops) free(tabstops); | 90 | if (tabstops) free(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 = (ca*)malloc( new_lines * new_columns * sizeof( ca)); |
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 | free(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 = (ca*)malloc(lines*columns*sizeof(ca)); |
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) free(tabstops); |
627 | tabstops = (bool*)malloc(columns*sizeof(bool)); | 627 | tabstops = (bool*)malloc(columns*sizeof(bool)); |
628 | // Arrg! The 1st tabstop has to be one longer than the other. | 628 | // Arrg! The 1st tabstop has to be one longer than the other. |
629 | // i.e. the kids start counting from 0 instead of 1. | 629 | // i.e. the kids start counting from 0 instead of 1. |
630 | // Other programs might behave correctly. Be aware. | 630 | // Other programs might behave correctly. Be aware. |
631 | for (int i = 0; i < columns; i++) tabstops[i] = (i%8 == 0 && i != 0); | 631 | for (int i = 0; i < columns; i++) tabstops[i] = (i%8 == 0 && i != 0); |
632 | } | 632 | } |
633 | 633 | ||
634 | /*! | 634 | /*! |
635 | This behaves either as IND (Screen::Index) or as NEL (Screen::NextLine) | 635 | This behaves either as IND (Screen::Index) or as NEL (Screen::NextLine) |
636 | depending on the NewLine Mode (LNM). This mode also | 636 | depending on the NewLine Mode (LNM). This mode also |
637 | affects the key sequence returned for newline ([CR]LF). | 637 | affects the key sequence returned for newline ([CR]LF). |
638 | */ | 638 | */ |
639 | 639 | ||
640 | void TEScreen::NewLine() | 640 | void TEScreen::NewLine() |
641 | { | 641 | { |
642 | if (getMode(MODE_NewLine)) Return(); | 642 | if (getMode(MODE_NewLine)) Return(); |
643 | index(); | 643 | index(); |
644 | } | 644 | } |
645 | 645 | ||
646 | /*! put `c' literally onto the screen at the current cursor position. | 646 | /*! put `c' literally onto the screen at the current cursor position. |
647 | 647 | ||
648 | VT100 uses the convention to produce an automatic newline (am) | 648 | VT100 uses the convention to produce an automatic newline (am) |
649 | with the *first* character that would fall onto the next line (xenl). | 649 | with the *first* character that would fall onto the next line (xenl). |
650 | */ | 650 | */ |
651 | 651 | ||
652 | void TEScreen::checkSelection(int from, int to) | 652 | void TEScreen::checkSelection(int from, int to) |
653 | { | 653 | { |
654 | if (sel_begin == -1) return; | 654 | if (sel_begin == -1) return; |
655 | int scr_TL = loc(0, hist.getLines()); | 655 | int scr_TL = loc(0, hist.getLines()); |
656 | //Clear entire selection if it overlaps region [from, to] | 656 | //Clear entire selection if it overlaps region [from, to] |
657 | if ( (sel_BR > (from+scr_TL) )&&(sel_TL < (to+scr_TL)) ) | 657 | if ( (sel_BR > (from+scr_TL) )&&(sel_TL < (to+scr_TL)) ) |
658 | { | 658 | { |
659 | clearSelection(); | 659 | clearSelection(); |
660 | } | 660 | } |
661 | } | 661 | } |
662 | 662 | ||
663 | void TEScreen::ShowCharacter(unsigned short c) | 663 | void TEScreen::ShowCharacter(unsigned short c) |
664 | { | 664 | { |
665 | // Note that VT100 does wrapping BEFORE putting the character. | 665 | // Note that VT100 does wrapping BEFORE putting the character. |
666 | // This has impact on the assumption of valid cursor positions. | 666 | // This has impact on the assumption of valid cursor positions. |
667 | // We indicate the fact that a newline has to be triggered by | 667 | // 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. | 668 | // putting the cursor one right to the last column of the screen. |
669 | 669 | ||
670 | if (cuX >= columns) | 670 | if (cuX >= columns) |
671 | { | 671 | { |
672 | if (getMode(MODE_Wrap)) NextLine(); else cuX = columns - 1; | 672 | if (getMode(MODE_Wrap)) NextLine(); else cuX = columns - 1; |
673 | // comment out for no wrap | 673 | // comment out for no wrap |
674 | } | 674 | } |
675 | 675 | ||
676 | if (getMode(MODE_Insert)) insertChars(1); | 676 | if (getMode(MODE_Insert)) insertChars(1); |
677 | 677 | ||
678 | int i = loc( cuX, cuY); | 678 | int i = loc( cuX, cuY); |
679 | 679 | ||
680 | checkSelection(i, i); // check if selection is still valid. | 680 | checkSelection(i, i); // check if selection is still valid. |
681 | 681 | ||
682 | image[i].c = c; | 682 | image[i].c = c; |
683 | image[i].f = ef_fg; | 683 | image[i].f = ef_fg; |
684 | image[i].b = ef_bg; | 684 | image[i].b = ef_bg; |
685 | image[i].r = ef_re; | 685 | image[i].r = ef_re; |
686 | 686 | ||
687 | cuX += 1; | 687 | cuX += 1; |
688 | } | 688 | } |
689 | 689 | ||
690 | // Region commands ------------------------------------------------------------- | 690 | // Region commands ------------------------------------------------------------- |
691 | 691 | ||
692 | 692 | ||
693 | /*! scroll up `n' lines within current region. | 693 | /*! scroll up `n' lines within current region. |
694 | The `n' new lines are cleared. | 694 | The `n' new lines are cleared. |
695 | \sa setRegion \sa scrollDown | 695 | \sa setRegion \sa scrollDown |
696 | */ | 696 | */ |
697 | 697 | ||
698 | void TEScreen::scrollUp(int from, int n) | 698 | void TEScreen::scrollUp(int from, int n) |
699 | { | 699 | { |
700 | if (n <= 0 || from + n > bmargin) return; | 700 | if (n <= 0 || from + n > bmargin) return; |
701 | //FIXME: make sure `tmargin', `bmargin', `from', `n' is in bounds. | 701 | //FIXME: make sure `tmargin', `bmargin', `from', `n' is in bounds. |
702 | 702 | ||
703 | moveImage( loc( 0, from), loc( 0, from + n), loc( columns - 1, bmargin)); | 703 | moveImage( loc( 0, from), loc( 0, from + n), loc( columns - 1, bmargin)); |
704 | clearImage( loc( 0, bmargin - n + 1), loc( columns - 1, bmargin), ' '); | 704 | clearImage( loc( 0, bmargin - n + 1), loc( columns - 1, bmargin), ' '); |
705 | } | 705 | } |
706 | 706 | ||
707 | /*! scroll down `n' lines within current region. | 707 | /*! scroll down `n' lines within current region. |
708 | The `n' new lines are cleared. | 708 | The `n' new lines are cleared. |
709 | \sa setRegion \sa scrollUp | 709 | \sa setRegion \sa scrollUp |
710 | */ | 710 | */ |
711 | 711 | ||
712 | void TEScreen::scrollDown(int from, int n) | 712 | void TEScreen::scrollDown(int from, int n) |
713 | { | 713 | { |
714 | 714 | ||
715 | //FIXME: make sure `tmargin', `bmargin', `from', `n' is in bounds. | 715 | //FIXME: make sure `tmargin', `bmargin', `from', `n' is in bounds. |
716 | if (n <= 0) return; | 716 | if (n <= 0) return; |
717 | if (from > bmargin) return; | 717 | if (from > bmargin) return; |
718 | if (from + n > bmargin) n = bmargin - from; | 718 | if (from + n > bmargin) n = bmargin - from; |
719 | 719 | ||
720 | moveImage( loc(0,from+n), loc(0,from), loc(columns-1,bmargin-n)); | 720 | moveImage( loc(0,from+n), loc(0,from), loc(columns-1,bmargin-n)); |
721 | clearImage(loc(0,from),loc(columns-1,from+n-1),' '); | 721 | clearImage(loc(0,from),loc(columns-1,from+n-1),' '); |
722 | } | 722 | } |
723 | 723 | ||
724 | 724 | ||
725 | 725 | ||
726 | /*! position the cursor to a specific line and column. */ | 726 | /*! position the cursor to a specific line and column. */ |
727 | void TEScreen::setCursorYX(int y, int x) | 727 | void TEScreen::setCursorYX(int y, int x) |
728 | { | 728 | { |
729 | setCursorY(y); setCursorX(x); | 729 | setCursorY(y); setCursorX(x); |
730 | } | 730 | } |
731 | 731 | ||
732 | /*! Set the cursor to x-th line. */ | 732 | /*! Set the cursor to x-th line. */ |
733 | 733 | ||
734 | void TEScreen::setCursorX(int x) | 734 | void TEScreen::setCursorX(int x) |
735 | { | 735 | { |
736 | if (x == 0) x = 1; // Default | 736 | if (x == 0) x = 1; // Default |
737 | x -= 1; // Adjust | 737 | x -= 1; // Adjust |
738 | cuX = QMAX(0,QMIN(columns-1, x)); | 738 | cuX = QMAX(0,QMIN(columns-1, x)); |
739 | } | 739 | } |
740 | 740 | ||
741 | /*! Set the cursor to y-th line. */ | 741 | /*! Set the cursor to y-th line. */ |
742 | 742 | ||
743 | void TEScreen::setCursorY(int y) | 743 | void TEScreen::setCursorY(int y) |
744 | { | 744 | { |
745 | if (y == 0) y = 1; // Default | 745 | if (y == 0) y = 1; // Default |
746 | y -= 1; // Adjust | 746 | y -= 1; // Adjust |
747 | cuY = QMAX(0,QMIN(lines -1, y + (getMode(MODE_Origin) ? tmargin : 0) )); | 747 | cuY = QMAX(0,QMIN(lines -1, y + (getMode(MODE_Origin) ? tmargin : 0) )); |
748 | } | 748 | } |
749 | 749 | ||
750 | /*! set cursor to the `left upper' corner of the screen (1,1). | 750 | /*! set cursor to the `left upper' corner of the screen (1,1). |
751 | */ | 751 | */ |
752 | 752 | ||
753 | void TEScreen::home() | 753 | void TEScreen::home() |
754 | { | 754 | { |
755 | cuX = 0; | 755 | cuX = 0; |
756 | cuY = 0; | 756 | cuY = 0; |
757 | } | 757 | } |
758 | 758 | ||
759 | /*! set cursor to the begin of the current line. | 759 | /*! set cursor to the begin of the current line. |
760 | */ | 760 | */ |
761 | 761 | ||
762 | void TEScreen::Return() | 762 | void TEScreen::Return() |
763 | { | 763 | { |
764 | cuX = 0; | 764 | cuX = 0; |
765 | } | 765 | } |
766 | 766 | ||
767 | /*! returns the current cursor columns. | 767 | /*! returns the current cursor columns. |
768 | */ | 768 | */ |
769 | 769 | ||
770 | int TEScreen::getCursorX() | 770 | int TEScreen::getCursorX() |
771 | { | 771 | { |
772 | return cuX; | 772 | return cuX; |
773 | } | 773 | } |
774 | 774 | ||
775 | /*! returns the current cursor line. | 775 | /*! returns the current cursor line. |
776 | */ | 776 | */ |
777 | 777 | ||
778 | int TEScreen::getCursorY() | 778 | int TEScreen::getCursorY() |
779 | { | 779 | { |
780 | return cuY; | 780 | return cuY; |
781 | } | 781 | } |
782 | 782 | ||
783 | // Erasing --------------------------------------------------------------------- | 783 | // Erasing --------------------------------------------------------------------- |
784 | 784 | ||
785 | /*! \section Erasing | 785 | /*! \section Erasing |
786 | 786 | ||
787 | This group of operations erase parts of the screen contents by filling | 787 | This group of operations erase parts of the screen contents by filling |
788 | it with spaces colored due to the current rendition settings. | 788 | it with spaces colored due to the current rendition settings. |
789 | 789 | ||
790 | Althought the cursor position is involved in most of these operations, | 790 | Althought the cursor position is involved in most of these operations, |
791 | it is never modified by them. | 791 | it is never modified by them. |
792 | */ | 792 | */ |
793 | 793 | ||
794 | /*! fill screen between (including) `loca' and `loce' with spaces. | 794 | /*! fill screen between (including) `loca' and `loce' with spaces. |
795 | 795 | ||
796 | This is an internal helper functions. The parameter types are internal | 796 | 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 | 797 | addresses of within the screen image and make use of the way how the |
798 | screen matrix is mapped to the image vector. | 798 | screen matrix is mapped to the image vector. |
799 | */ | 799 | */ |
800 | 800 | ||
801 | void TEScreen::clearImage(int loca, int loce, char c) | 801 | void TEScreen::clearImage(int loca, int loce, char c) |
802 | { int i; | 802 | { int i; |
803 | int scr_TL=loc(0,hist.getLines()); | 803 | int scr_TL=loc(0,hist.getLines()); |
804 | //FIXME: check positions | 804 | //FIXME: check positions |
805 | 805 | ||
806 | //Clear entire selection if it overlaps region to be moved... | 806 | //Clear entire selection if it overlaps region to be moved... |
807 | if ( (sel_BR > (loca+scr_TL) )&&(sel_TL < (loce+scr_TL)) ) | 807 | if ( (sel_BR > (loca+scr_TL) )&&(sel_TL < (loce+scr_TL)) ) |
808 | { | 808 | { |
809 | clearSelection(); | 809 | clearSelection(); |
810 | } | 810 | } |
811 | for (i = loca; i <= loce; i++) | 811 | for (i = loca; i <= loce; i++) |
812 | { | 812 | { |
813 | image[i].c = c; | 813 | image[i].c = c; |
814 | image[i].f = ef_fg; //DEFAULT_FORE_COLOR; //FIXME: xterm and linux/ansi | 814 | 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 | 815 | image[i].b = ef_bg; //DEFAULT_BACK_COLOR; // many have different |
816 | image[i].r = ef_re; //DEFAULT_RENDITION; // ideas here. | 816 | image[i].r = ef_re; //DEFAULT_RENDITION; // ideas here. |
817 | } | 817 | } |
818 | } | 818 | } |
819 | 819 | ||
820 | /*! move image between (including) `loca' and `loce' to 'dst'. | 820 | /*! move image between (including) `loca' and `loce' to 'dst'. |
821 | 821 | ||
822 | This is an internal helper functions. The parameter types are internal | 822 | 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 | 823 | addresses of within the screen image and make use of the way how the |
824 | screen matrix is mapped to the image vector. | 824 | screen matrix is mapped to the image vector. |
825 | */ | 825 | */ |
826 | 826 | ||
827 | void TEScreen::moveImage(int dst, int loca, int loce) | 827 | void TEScreen::moveImage(int dst, int loca, int loce) |
828 | { | 828 | { |
829 | //FIXME: check positions | 829 | //FIXME: check positions |
830 | if (loce < loca) { | 830 | if (loce < loca) { |
831 | // kdDebug() << "WARNING!!! call to TEScreen:moveImage with loce < loca!" << endl; | 831 | // kdDebug() << "WARNING!!! call to TEScreen:moveImage with loce < loca!" << endl; |
832 | return; | 832 | return; |
833 | } | 833 | } |
834 | memmove(&image[dst],&image[loca],(loce-loca+1)*sizeof(ca)); | 834 | memmove(&image[dst],&image[loca],(loce-loca+1)*sizeof(ca)); |
835 | } | 835 | } |
836 | 836 | ||
837 | /*! clear from (including) current cursor position to end of screen. | 837 | /*! clear from (including) current cursor position to end of screen. |
838 | */ | 838 | */ |
839 | 839 | ||
840 | void TEScreen::clearToEndOfScreen() | 840 | void TEScreen::clearToEndOfScreen() |
841 | { | 841 | { |
842 | clearImage(loc(cuX,cuY),loc(columns-1,lines-1),' '); | 842 | clearImage(loc(cuX,cuY),loc(columns-1,lines-1),' '); |
843 | } | 843 | } |
844 | 844 | ||
845 | /*! clear from begin of screen to (including) current cursor position. | 845 | /*! clear from begin of screen to (including) current cursor position. |
846 | */ | 846 | */ |
847 | 847 | ||
848 | void TEScreen::clearToBeginOfScreen() | 848 | void TEScreen::clearToBeginOfScreen() |
849 | { | 849 | { |
850 | clearImage(loc(0,0),loc(cuX,cuY),' '); | 850 | clearImage(loc(0,0),loc(cuX,cuY),' '); |
851 | } | 851 | } |
852 | 852 | ||
853 | /*! clear the entire screen. | 853 | /*! clear the entire screen. |
854 | */ | 854 | */ |
855 | 855 | ||
856 | void TEScreen::clearEntireScreen() | 856 | void TEScreen::clearEntireScreen() |
857 | { | 857 | { |
858 | clearImage(loc(0,0),loc(columns-1,lines-1),' '); | 858 | clearImage(loc(0,0),loc(columns-1,lines-1),' '); |
859 | } | 859 | } |
860 | 860 | ||
861 | /*! fill screen with 'E' | 861 | /*! fill screen with 'E' |
862 | This is to aid screen alignment | 862 | This is to aid screen alignment |
863 | */ | 863 | */ |
864 | 864 | ||
865 | void TEScreen::helpAlign() | 865 | void TEScreen::helpAlign() |
866 | { | 866 | { |
867 | clearImage(loc(0,0),loc(columns-1,lines-1),'E'); | 867 | clearImage(loc(0,0),loc(columns-1,lines-1),'E'); |
868 | } | 868 | } |
869 | 869 | ||
870 | /*! clear from (including) current cursor position to end of current cursor line. | 870 | /*! clear from (including) current cursor position to end of current cursor line. |
871 | */ | 871 | */ |
872 | 872 | ||
873 | void TEScreen::clearToEndOfLine() | 873 | void TEScreen::clearToEndOfLine() |
874 | { | 874 | { |
875 | clearImage(loc(cuX,cuY),loc(columns-1,cuY),' '); | 875 | clearImage(loc(cuX,cuY),loc(columns-1,cuY),' '); |
876 | } | 876 | } |
877 | 877 | ||
878 | /*! clear from begin of current cursor line to (including) current cursor position. | 878 | /*! clear from begin of current cursor line to (including) current cursor position. |
879 | */ | 879 | */ |
880 | 880 | ||
881 | void TEScreen::clearToBeginOfLine() | 881 | void TEScreen::clearToBeginOfLine() |
882 | { | 882 | { |
883 | clearImage(loc(0,cuY),loc(cuX,cuY),' '); | 883 | clearImage(loc(0,cuY),loc(cuX,cuY),' '); |
884 | } | 884 | } |
885 | 885 | ||
886 | /*! clears entire current cursor line | 886 | /*! clears entire current cursor line |
887 | */ | 887 | */ |
888 | 888 | ||
889 | void TEScreen::clearEntireLine() | 889 | void TEScreen::clearEntireLine() |
890 | { | 890 | { |
891 | clearImage( loc( 0, cuY),loc( columns - 1, cuY),' '); | 891 | clearImage( loc( 0, cuY),loc( columns - 1, cuY),' '); |
892 | } | 892 | } |
893 | 893 | ||
894 | // Rendition ------------------------------------------------------------------ | 894 | // Rendition ------------------------------------------------------------------ |
895 | 895 | ||
896 | /*! | 896 | /*! |
897 | set rendition mode | 897 | set rendition mode |
898 | */ | 898 | */ |
899 | 899 | ||
900 | void TEScreen::setRendition(int re) | 900 | void TEScreen::setRendition(int re) |
901 | { | 901 | { |
902 | cu_re |= re; | 902 | cu_re |= re; |
903 | effectiveRendition(); | 903 | effectiveRendition(); |
904 | } | 904 | } |
905 | 905 | ||
906 | /*! | 906 | /*! |
907 | reset rendition mode | 907 | reset rendition mode |
908 | */ | 908 | */ |
909 | 909 | ||
910 | void TEScreen::resetRendition(int re) | 910 | void TEScreen::resetRendition(int re) |
911 | { | 911 | { |
912 | cu_re &= ~re; | 912 | cu_re &= ~re; |
913 | effectiveRendition(); | 913 | effectiveRendition(); |
914 | } | 914 | } |
915 | 915 | ||
916 | /*! | 916 | /*! |
917 | */ | 917 | */ |
918 | 918 | ||
919 | void TEScreen::setDefaultRendition() | 919 | void TEScreen::setDefaultRendition() |
920 | { | 920 | { |
921 | setForeColorToDefault(); | 921 | setForeColorToDefault(); |
922 | setBackColorToDefault(); | 922 | setBackColorToDefault(); |
923 | cu_re = DEFAULT_RENDITION; | 923 | cu_re = DEFAULT_RENDITION; |
924 | effectiveRendition(); | 924 | effectiveRendition(); |
925 | } | 925 | } |
926 | 926 | ||
927 | /*! | 927 | /*! |
928 | */ | 928 | */ |
929 | 929 | ||
930 | void TEScreen::setForeColor(int fgcolor) | 930 | void TEScreen::setForeColor(int fgcolor) |
931 | { | 931 | { |
932 | cu_fg = (fgcolor&7)+((fgcolor&8) ? 4+8 : 2); | 932 | cu_fg = (fgcolor&7)+((fgcolor&8) ? 4+8 : 2); |
933 | effectiveRendition(); | 933 | effectiveRendition(); |
934 | } | 934 | } |
935 | 935 | ||
936 | /*! | 936 | /*! |
937 | */ | 937 | */ |
938 | 938 | ||
939 | void TEScreen::setBackColor(int bgcolor) | 939 | void TEScreen::setBackColor(int bgcolor) |
940 | { | 940 | { |
941 | cu_bg = (bgcolor&7)+((bgcolor&8) ? 4+8 : 2); | 941 | cu_bg = (bgcolor&7)+((bgcolor&8) ? 4+8 : 2); |
942 | effectiveRendition(); | 942 | effectiveRendition(); |
943 | } | 943 | } |
944 | 944 | ||
945 | /*! | 945 | /*! |
946 | */ | 946 | */ |
947 | 947 | ||
948 | void TEScreen::setBackColorToDefault() | 948 | void TEScreen::setBackColorToDefault() |
949 | { | 949 | { |
950 | cu_bg = DEFAULT_BACK_COLOR; | 950 | cu_bg = DEFAULT_BACK_COLOR; |
951 | effectiveRendition(); | 951 | effectiveRendition(); |
952 | } | 952 | } |
953 | 953 | ||
954 | /*! | 954 | /*! |
955 | */ | 955 | */ |
956 | 956 | ||
957 | void TEScreen::setForeColorToDefault() | 957 | void TEScreen::setForeColorToDefault() |
958 | { | 958 | { |
959 | cu_fg = DEFAULT_FORE_COLOR; | 959 | cu_fg = DEFAULT_FORE_COLOR; |
960 | effectiveRendition(); | 960 | effectiveRendition(); |
961 | } | 961 | } |
962 | 962 | ||
963 | /* ------------------------------------------------------------------------- */ | 963 | /* ------------------------------------------------------------------------- */ |
964 | /* */ | 964 | /* */ |
965 | /* Marking & Selection */ | 965 | /* Marking & Selection */ |
966 | /* */ | 966 | /* */ |
967 | /* ------------------------------------------------------------------------- */ | 967 | /* ------------------------------------------------------------------------- */ |
968 | 968 | ||
969 | void TEScreen::clearSelection() | 969 | void TEScreen::clearSelection() |
970 | { | 970 | { |
971 | sel_BR = -1; | 971 | sel_BR = -1; |
972 | sel_TL = -1; | 972 | sel_TL = -1; |
973 | sel_begin = -1; | 973 | sel_begin = -1; |
974 | } | 974 | } |
975 | 975 | ||
976 | void TEScreen::setSelBeginXY(const int x, const int y) | 976 | void TEScreen::setSelBeginXY(const int x, const int y) |
977 | { | 977 | { |
978 | if (histCursor > hist.getLines()) { | 978 | if (histCursor > hist.getLines()) { |
979 | histCursor = hist.getLines(); | 979 | histCursor = hist.getLines(); |
980 | } | 980 | } |
981 | sel_begin = loc(x,y+histCursor) ; | 981 | sel_begin = loc(x,y+histCursor) ; |
982 | sel_BR = sel_begin; | 982 | sel_BR = sel_begin; |
983 | sel_TL = sel_begin; | 983 | sel_TL = sel_begin; |
984 | } | 984 | } |
985 | 985 | ||
986 | void TEScreen::setSelExtentXY(const int x, const int y) | 986 | void TEScreen::setSelExtentXY(const int x, const int y) |
987 | { | 987 | { |
988 | if (sel_begin == -1) return; | 988 | if (sel_begin == -1) return; |
989 | if (histCursor > hist.getLines()) { | 989 | if (histCursor > hist.getLines()) { |
990 | histCursor = hist.getLines(); | 990 | histCursor = hist.getLines(); |
991 | } | 991 | } |
992 | int l = loc(x,y + histCursor); | 992 | int l = loc(x,y + histCursor); |
993 | 993 | ||
994 | if (l < sel_begin) | 994 | if (l < sel_begin) |
995 | { | 995 | { |
996 | sel_TL = l; | 996 | sel_TL = l; |
997 | sel_BR = sel_begin; | 997 | sel_BR = sel_begin; |
998 | } | 998 | } |
999 | else | 999 | else |
1000 | { | 1000 | { |
1001 | /* FIXME, HACK to correct for x too far to the right... */ | 1001 | /* FIXME, HACK to correct for x too far to the right... */ |
1002 | if (( x == columns )|| (x == 0)) l--; | 1002 | if (( x == columns )|| (x == 0)) l--; |
1003 | 1003 | ||
1004 | sel_TL = sel_begin; | 1004 | sel_TL = sel_begin; |
1005 | sel_BR = l; | 1005 | sel_BR = l; |
1006 | } | 1006 | } |
1007 | } | 1007 | } |
1008 | 1008 | ||
1009 | QString TEScreen::getSelText(const BOOL preserve_line_breaks) | 1009 | QString TEScreen::getSelText(const BOOL preserve_line_breaks) |
1010 | { | 1010 | { |
1011 | if (sel_begin == -1) | 1011 | if (sel_begin == -1) |
1012 | return QString::null; // Selection got clear while selecting. | 1012 | return QString::null; // Selection got clear while selecting. |
1013 | 1013 | ||
1014 | int *m; // buffer to fill. | 1014 | int *m; // buffer to fill. |
1015 | int s, d; // source index, dest. index. | 1015 | int s, d; // source index, dest. index. |
1016 | int hist_BR = loc(0, hist.getLines()); | 1016 | int hist_BR = loc(0, hist.getLines()); |
1017 | int hY = sel_TL / columns; | 1017 | int hY = sel_TL / columns; |
1018 | int hX = sel_TL % columns; | 1018 | int hX = sel_TL % columns; |
1019 | int eol; // end of line | 1019 | int eol; // end of line |
1020 | 1020 | ||
1021 | s = sel_TL; // tracks copy in source. | 1021 | s = sel_TL; // tracks copy in source. |
1022 | 1022 | ||
1023 | // allocate buffer for maximum | 1023 | // allocate buffer for maximum |
1024 | // possible size... | 1024 | // possible size... |
1025 | d = (sel_BR - sel_TL) / columns + 1; | 1025 | d = (sel_BR - sel_TL) / columns + 1; |
1026 | m = new int[d * (columns + 1) + 2]; | 1026 | m = new int[d * (columns + 1) + 2]; |
1027 | d = 0; | 1027 | d = 0; |
1028 | 1028 | ||
1029 | while (s <= sel_BR) | 1029 | while (s <= sel_BR) |
1030 | { | 1030 | { |
1031 | if (s < hist_BR) | 1031 | if (s < hist_BR) |
1032 | { // get lines from hist.history | 1032 | { // get lines from hist.history |
1033 | // buffer. | 1033 | // buffer. |
1034 | eol = hist.getLineLen(hY); | 1034 | eol = hist.getLineLen(hY); |
1035 | 1035 | ||
1036 | if ((hY == (sel_BR / columns)) && | 1036 | if ((hY == (sel_BR / columns)) && |
1037 | (eol >= (sel_BR % columns))) | 1037 | (eol >= (sel_BR % columns))) |
1038 | { | 1038 | { |
1039 | eol = sel_BR % columns + 1; | 1039 | eol = sel_BR % columns + 1; |
1040 | } | 1040 | } |
1041 | 1041 | ||
1042 | while (hX < eol) | 1042 | while (hX < eol) |
1043 | { | 1043 | { |
1044 | m[d++] = hist.getCell(hY, hX++).c; | 1044 | m[d++] = hist.getCell(hY, hX++).c; |
1045 | s++; | 1045 | s++; |
1046 | } | 1046 | } |
1047 | 1047 | ||
1048 | if (s <= sel_BR) | 1048 | if (s <= sel_BR) |
1049 | { | 1049 | { |
1050 | // The line break handling | 1050 | // The line break handling |
1051 | // It's different from the screen | 1051 | // It's different from the screen |
1052 | // image case! | 1052 | // image case! |
1053 | if (eol % columns == 0) | 1053 | if (eol % columns == 0) |
1054 | { | 1054 | { |
1055 | // That's either a completely filled | 1055 | // That's either a completely filled |
1056 | // line or an empty line | 1056 | // line or an empty line |
1057 | if (eol == 0) | 1057 | if (eol == 0) |
1058 | { | 1058 | { |
1059 | m[d++] = '\n'; | 1059 | m[d++] = '\n'; |
1060 | } | 1060 | } |
1061 | else | 1061 | else |
1062 | { | 1062 | { |
1063 | // We have a full line. | 1063 | // We have a full line. |
1064 | // FIXME: How can we handle newlines | 1064 | // FIXME: How can we handle newlines |
1065 | // at this position?! | 1065 | // at this position?! |
1066 | } | 1066 | } |
1067 | } | 1067 | } |
1068 | else if ((eol + 1) % columns == 0) | 1068 | else if ((eol + 1) % columns == 0) |
1069 | { | 1069 | { |
1070 | // FIXME: We don't know if this was a | 1070 | // FIXME: We don't know if this was a |
1071 | // space at the last position or a | 1071 | // space at the last position or a |
1072 | // short line!! | 1072 | // short line!! |
1073 | m[d++] = ' '; | 1073 | m[d++] = ' '; |
1074 | } | 1074 | } |
1075 | else | 1075 | else |
1076 | { | 1076 | { |
1077 | // We have a short line here. Put a | 1077 | // We have a short line here. Put a |
1078 | // newline or a space into the | 1078 | // newline or a space into the |
1079 | // buffer. | 1079 | // buffer. |
1080 | m[d++] = preserve_line_breaks ? '\n' : ' '; | 1080 | m[d++] = preserve_line_breaks ? '\n' : ' '; |
1081 | } | 1081 | } |
1082 | } | 1082 | } |
1083 | 1083 | ||
1084 | hY++; | 1084 | hY++; |
1085 | hX = 0; | 1085 | hX = 0; |
1086 | s = hY * columns; | 1086 | s = hY * columns; |
1087 | } | 1087 | } |
1088 | else | 1088 | else |
1089 | { // or from screen image. | 1089 | { // or from screen image. |
1090 | eol = (s / columns + 1) * columns - 1; | 1090 | eol = (s / columns + 1) * columns - 1; |
1091 | 1091 | ||
1092 | if (eol < sel_BR) | 1092 | if (eol < sel_BR) |
1093 | { | 1093 | { |
1094 | while ((eol > s) && | 1094 | while ((eol > s) && |
1095 | isspace(image[eol - hist_BR].c)) | 1095 | isspace(image[eol - hist_BR].c)) |
1096 | { | 1096 | { |
1097 | eol--; | 1097 | eol--; |
1098 | } | 1098 | } |
1099 | } | 1099 | } |
1100 | else | 1100 | else |
1101 | { | 1101 | { |
1102 | eol = sel_BR; | 1102 | eol = sel_BR; |
1103 | } | 1103 | } |
1104 | 1104 | ||
1105 | while (s <= eol) | 1105 | while (s <= eol) |
1106 | { | 1106 | { |
1107 | m[d++] = image[s++ - hist_BR].c; | 1107 | m[d++] = image[s++ - hist_BR].c; |
1108 | } | 1108 | } |
1109 | 1109 | ||
1110 | if (eol < sel_BR) | 1110 | if (eol < sel_BR) |
1111 | { | 1111 | { |
1112 | // eol processing see below ... | 1112 | // eol processing see below ... |
1113 | if ((eol + 1) % columns == 0) | 1113 | if ((eol + 1) % columns == 0) |
1114 | { | 1114 | { |
1115 | if (image[eol - hist_BR].c == ' ') | 1115 | if (image[eol - hist_BR].c == ' ') |
1116 | { | 1116 | { |
1117 | m[d++] = ' '; | 1117 | m[d++] = ' '; |
1118 | } | 1118 | } |
1119 | } | 1119 | } |
1120 | else | 1120 | else |
1121 | { | 1121 | { |
1122 | m[d++] = ((preserve_line_breaks || | 1122 | m[d++] = ((preserve_line_breaks || |
1123 | ((eol % columns) == 0)) ? | 1123 | ((eol % columns) == 0)) ? |
1124 | '\n' : ' '); | 1124 | '\n' : ' '); |
1125 | } | 1125 | } |
1126 | } | 1126 | } |
1127 | 1127 | ||
1128 | s = (eol / columns + 1) * columns; | 1128 | s = (eol / columns + 1) * columns; |
1129 | } | 1129 | } |
1130 | } | 1130 | } |
1131 | 1131 | ||
1132 | QChar* qc = new QChar[d]; | 1132 | QChar* qc = new QChar[d]; |
1133 | 1133 | ||
1134 | for (int i = 0; i < d; i++) | 1134 | for (int i = 0; i < d; i++) |
1135 | { | 1135 | { |
1136 | qc[i] = m[i]; | 1136 | qc[i] = m[i]; |
1137 | } | 1137 | } |
1138 | 1138 | ||
1139 | QString res(qc, d); | 1139 | QString res(qc, d); |
1140 | 1140 | ||
1141 | delete m; | 1141 | delete [] m; |
1142 | delete qc; | 1142 | delete [] qc; |
1143 | 1143 | ||
1144 | return res; | 1144 | return res; |
1145 | } | 1145 | } |
1146 | /* above ... end of line processing for selection -- psilva | 1146 | /* above ... end of line processing for selection -- psilva |
1147 | cases: | 1147 | cases: |
1148 | 1148 | ||
1149 | 1) (eol+1)%columns == 0 --> the whole line is filled. | 1149 | 1) (eol+1)%columns == 0 --> the whole line is filled. |
1150 | If the last char is a space, insert (preserve) space. otherwise | 1150 | If the last char is a space, insert (preserve) space. otherwise |
1151 | leave the text alone, so that words that are broken by linewrap | 1151 | leave the text alone, so that words that are broken by linewrap |
1152 | are preserved. | 1152 | are preserved. |
1153 | 1153 | ||
1154 | FIXME: | 1154 | FIXME: |
1155 | * this suppresses \n for command output that is | 1155 | * this suppresses \n for command output that is |
1156 | sized to the exact column width of the screen. | 1156 | sized to the exact column width of the screen. |
1157 | 1157 | ||
1158 | 2) eol%columns == 0 --> blank line. | 1158 | 2) eol%columns == 0 --> blank line. |
1159 | insert a \n unconditionally. | 1159 | insert a \n unconditionally. |
1160 | Do it either you would because you are in preserve_line_break mode, | 1160 | Do it either you would because you are in preserve_line_break mode, |
1161 | or because it's an ASCII paragraph delimiter, so even when | 1161 | or because it's an ASCII paragraph delimiter, so even when |
1162 | not preserving line_breaks, you want to preserve paragraph breaks. | 1162 | not preserving line_breaks, you want to preserve paragraph breaks. |
1163 | 1163 | ||
1164 | 3) else --> partially filled line | 1164 | 3) else --> partially filled line |
1165 | insert a \n in preserve line break mode, else a space | 1165 | insert a \n in preserve line break mode, else a space |
1166 | The space prevents concatenation of the last word of one | 1166 | The space prevents concatenation of the last word of one |
1167 | line with the first of the next. | 1167 | line with the first of the next. |
1168 | 1168 | ||
1169 | */ | 1169 | */ |
1170 | 1170 | ||
1171 | void TEScreen::addHistLine() | 1171 | void TEScreen::addHistLine() |
1172 | { | 1172 | { |
1173 | assert(hasScroll() || histCursor == 0); | 1173 | assert(hasScroll() || histCursor == 0); |
1174 | 1174 | ||
1175 | // add to hist buffer | 1175 | // add to hist buffer |
1176 | // we have to take care about scrolling, too... | 1176 | // we have to take care about scrolling, too... |
1177 | 1177 | ||
1178 | if (hasScroll()){ | 1178 | if (hasScroll()){ |
1179 | ca dft; | 1179 | ca dft; |
1180 | 1180 | ||
1181 | int end = columns - 1; | 1181 | int end = columns - 1; |
1182 | while (end >= 0 && image[end] == dft) | 1182 | while (end >= 0 && image[end] == dft) |
1183 | end -= 1; | 1183 | end -= 1; |
1184 | 1184 | ||
1185 | hist.addCells( image, end + 1); | 1185 | hist.addCells( image, end + 1); |
1186 | hist.addLine(); | 1186 | hist.addLine(); |
1187 | 1187 | ||
1188 | // adjust history cursor | 1188 | // adjust history cursor |
1189 | histCursor += ( hist.getLines() - 1 == histCursor); | 1189 | histCursor += ( hist.getLines() - 1 == histCursor); |
1190 | } | 1190 | } |
1191 | 1191 | ||
1192 | if (!hasScroll()) histCursor = 0; //FIXME: a poor workaround | 1192 | if (!hasScroll()) histCursor = 0; //FIXME: a poor workaround |
1193 | } | 1193 | } |
1194 | 1194 | ||
1195 | void TEScreen::setHistCursor(int cursor) | 1195 | void TEScreen::setHistCursor(int cursor) |
1196 | { | 1196 | { |
1197 | histCursor = cursor; //FIXME:rangecheck | 1197 | histCursor = cursor; //FIXME:rangecheck |
1198 | if (histCursor > hist.getLines()) { | 1198 | if (histCursor > hist.getLines()) { |
1199 | histCursor = hist.getLines(); | 1199 | histCursor = hist.getLines(); |
1200 | } | 1200 | } |
1201 | if (histCursor < 0) { | 1201 | if (histCursor < 0) { |
1202 | histCursor = 0; | 1202 | histCursor = 0; |
1203 | } | 1203 | } |
1204 | } | 1204 | } |
1205 | 1205 | ||
1206 | void TEScreen::setHorzCursor(int cursor) | 1206 | void TEScreen::setHorzCursor(int cursor) |
1207 | { | 1207 | { |
1208 | horzCursor = cursor; | 1208 | horzCursor = cursor; |
1209 | } | 1209 | } |
1210 | 1210 | ||
1211 | int TEScreen::getHistCursor() | 1211 | int TEScreen::getHistCursor() |
1212 | { | 1212 | { |
1213 | return histCursor; | 1213 | return histCursor; |
1214 | } | 1214 | } |
1215 | 1215 | ||
1216 | int TEScreen::getHorzCursor() | 1216 | int TEScreen::getHorzCursor() |
1217 | { | 1217 | { |
1218 | return horzCursor; | 1218 | return horzCursor; |
1219 | } | 1219 | } |
1220 | 1220 | ||
1221 | int TEScreen::getHistLines() | 1221 | int TEScreen::getHistLines() |
1222 | { | 1222 | { |
1223 | return hist.getLines(); | 1223 | return hist.getLines(); |
1224 | } | 1224 | } |
1225 | 1225 | ||
1226 | void TEScreen::setScroll(bool on) | 1226 | void TEScreen::setScroll(bool on) |
1227 | { | 1227 | { |
1228 | histCursor = 0; | 1228 | histCursor = 0; |
1229 | clearSelection(); | 1229 | clearSelection(); |
1230 | hist.setScroll(on); | 1230 | hist.setScroll(on); |
1231 | } | 1231 | } |
1232 | 1232 | ||
1233 | bool TEScreen::hasScroll() | 1233 | bool TEScreen::hasScroll() |
1234 | { | 1234 | { |
1235 | return hist.hasScroll(); | 1235 | return hist.hasScroll(); |
1236 | } | 1236 | } |
diff --git a/noncore/apps/checkbook/listedit.cpp b/noncore/apps/checkbook/listedit.cpp index e40377b..b297d69 100644 --- a/noncore/apps/checkbook/listedit.cpp +++ b/noncore/apps/checkbook/listedit.cpp | |||
@@ -1,355 +1,355 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the OPIE Project | 2 | This file is part of the OPIE Project |
3 | =. | 3 | =. |
4 | .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> | 4 | .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This file is free software; you can | 6 | _;:, .> :=|. This file is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This file is distributed in the hope that | 13 | .i_,=:_. -<s. This file is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General |
18 | ..}^=.= = ; Public License for more details. | 18 | ..}^=.= = ; Public License for more details. |
19 | ++= -. .` .: | 19 | ++= -. .` .: |
20 | : = ...= . :.=- You should have received a copy of the GNU | 20 | : = ...= . :.=- You should have received a copy of the GNU |
21 | -. .:....=;==+<; General Public License along with this file; | 21 | -. .:....=;==+<; General Public License along with this file; |
22 | -_. . . )=. = see the file COPYING. If not, write to the | 22 | -_. . . )=. = see the file COPYING. If not, write to the |
23 | -- :-=` Free Software Foundation, Inc., | 23 | -- :-=` Free Software Foundation, Inc., |
24 | 59 Temple Place - Suite 330, | 24 | 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include "listedit.h" | 29 | #include "listedit.h" |
30 | 30 | ||
31 | /* OPIE */ | 31 | /* OPIE */ |
32 | #include <opie2/odebug.h> | 32 | #include <opie2/odebug.h> |
33 | #include <opie2/oresource.h> | 33 | #include <opie2/oresource.h> |
34 | 34 | ||
35 | #include <qpe/applnk.h> | 35 | #include <qpe/applnk.h> |
36 | 36 | ||
37 | using namespace Opie::Core; | 37 | using namespace Opie::Core; |
38 | 38 | ||
39 | /* QT */ | 39 | /* QT */ |
40 | #include <qlayout.h> | 40 | #include <qlayout.h> |
41 | #include <qlineedit.h> | 41 | #include <qlineedit.h> |
42 | #include <qlistview.h> | 42 | #include <qlistview.h> |
43 | #include <qwidgetstack.h> | 43 | #include <qwidgetstack.h> |
44 | #include <qcombobox.h> | 44 | #include <qcombobox.h> |
45 | #include <qpushbutton.h> | 45 | #include <qpushbutton.h> |
46 | 46 | ||
47 | // --- ListEdit --------------------------------------------------------------- | 47 | // --- ListEdit --------------------------------------------------------------- |
48 | ListEdit::ListEdit( QWidget *parent, const char *sName ) | 48 | ListEdit::ListEdit( QWidget *parent, const char *sName ) |
49 | : QWidget(parent, sName), TableDef(sName) | 49 | : QWidget(parent, sName), TableDef(sName) |
50 | { | 50 | { |
51 | // get font height | 51 | // get font height |
52 | int fh = fontMetrics().height(); | 52 | int fh = fontMetrics().height(); |
53 | 53 | ||
54 | // create layout | 54 | // create layout |
55 | QGridLayout *layout=new QGridLayout(this); | 55 | QGridLayout *layout=new QGridLayout(this); |
56 | layout->setSpacing( 2 ); | 56 | layout->setSpacing( 2 ); |
57 | layout->setMargin( 4 ); | 57 | layout->setMargin( 4 ); |
58 | 58 | ||
59 | // type table | 59 | // type table |
60 | _typeTable = new QListView( this ); | 60 | _typeTable = new QListView( this ); |
61 | ColumnDef *def=first(); | 61 | ColumnDef *def=first(); |
62 | while( def ) { | 62 | while( def ) { |
63 | _typeTable->addColumn( def->getName() ); | 63 | _typeTable->addColumn( def->getName() ); |
64 | def=next(); | 64 | def=next(); |
65 | } | 65 | } |
66 | connect( _typeTable, SIGNAL( clicked(QListViewItem*,const QPoint&,int) ), this, SLOT( slotClick(QListViewItem*,const QPoint&,int) ) ); | 66 | connect( _typeTable, SIGNAL( clicked(QListViewItem*,const QPoint&,int) ), this, SLOT( slotClick(QListViewItem*,const QPoint&,int) ) ); |
67 | layout->addMultiCellWidget(_typeTable, 0,4,0,4); | 67 | layout->addMultiCellWidget(_typeTable, 0,4,0,4); |
68 | _currentItem=NULL; | 68 | _currentItem=NULL; |
69 | 69 | ||
70 | // edit field | 70 | // edit field |
71 | _stack=new QWidgetStack( this ); | 71 | _stack=new QWidgetStack( this ); |
72 | _stack->setMaximumHeight(fh+5); | 72 | _stack->setMaximumHeight(fh+5); |
73 | layout->addMultiCellWidget(_stack, 5,5,0,2); | 73 | layout->addMultiCellWidget(_stack, 5,5,0,2); |
74 | _typeEdit = new QLineEdit( _stack ); | 74 | _typeEdit = new QLineEdit( _stack ); |
75 | _stack->raiseWidget(_typeEdit ); | 75 | _stack->raiseWidget(_typeEdit ); |
76 | connect( _typeEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( slotEditChanged(const QString&) ) ); | 76 | connect( _typeEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( slotEditChanged(const QString&) ) ); |
77 | 77 | ||
78 | // combo box | 78 | // combo box |
79 | _box=new QComboBox( _stack ); | 79 | _box=new QComboBox( _stack ); |
80 | connect( _box, SIGNAL( activated(const QString&) ), this, SLOT( slotActivated(const QString&) ) ); | 80 | connect( _box, SIGNAL( activated(const QString&) ), this, SLOT( slotActivated(const QString&) ) ); |
81 | 81 | ||
82 | 82 | ||
83 | // add button | 83 | // add button |
84 | QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), | 84 | QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), |
85 | tr( "Add" ), this ); | 85 | tr( "Add" ), this ); |
86 | btn->setFixedHeight( AppLnk::smallIconSize()+4 ); | 86 | btn->setFixedHeight( AppLnk::smallIconSize()+4 ); |
87 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotAdd() ) ); | 87 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotAdd() ) ); |
88 | layout->addWidget( btn, 5, 3 ); | 88 | layout->addWidget( btn, 5, 3 ); |
89 | 89 | ||
90 | // delete button | 90 | // delete button |
91 | btn = new QPushButton( Opie::Core::OResource::loadPixmap( "trash", Opie::Core::OResource::SmallIcon ), tr( "Delete" ), this ); | 91 | btn = new QPushButton( Opie::Core::OResource::loadPixmap( "trash", Opie::Core::OResource::SmallIcon ), tr( "Delete" ), this ); |
92 | btn->setFixedHeight( AppLnk::smallIconSize()+4 ); | 92 | btn->setFixedHeight( AppLnk::smallIconSize()+4 ); |
93 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotDel() ) ); | 93 | connect( btn, SIGNAL( clicked() ), this, SLOT( slotDel() ) ); |
94 | layout->addWidget( btn, 5, 4 ); | 94 | layout->addWidget( btn, 5, 4 ); |
95 | } | 95 | } |
96 | 96 | ||
97 | // --- ~ListEdit -------------------------------------------------------------- | 97 | // --- ~ListEdit -------------------------------------------------------------- |
98 | ListEdit::~ListEdit() | 98 | ListEdit::~ListEdit() |
99 | { | 99 | { |
100 | } | 100 | } |
101 | 101 | ||
102 | 102 | ||
103 | // --- slotEditTypeChanged ---------------------------------------------------- | 103 | // --- slotEditTypeChanged ---------------------------------------------------- |
104 | void ListEdit::slotEditChanged(const QString &str) | 104 | void ListEdit::slotEditChanged(const QString &str) |
105 | { | 105 | { |
106 | if( !_currentItem || _currentColumn<0 ) return; | 106 | if( !_currentItem || _currentColumn<0 ) return; |
107 | _currentItem->setText(_currentColumn, str); | 107 | _currentItem->setText(_currentColumn, str); |
108 | } | 108 | } |
109 | 109 | ||
110 | // --- slotAddType ------------------------------------------------------------ | 110 | // --- slotAddType ------------------------------------------------------------ |
111 | void ListEdit::slotAdd() | 111 | void ListEdit::slotAdd() |
112 | { | 112 | { |
113 | // construct new row | 113 | // construct new row |
114 | QString args[8]; | 114 | QString args[8]; |
115 | ColumnDef *pCol=this->first(); | 115 | ColumnDef *pCol=this->first(); |
116 | int i=0; | 116 | int i=0; |
117 | while( pCol && i<8 ) { | 117 | while( pCol && i<8 ) { |
118 | args[i++]=pCol->getNewValue(); | 118 | args[i++]=pCol->getNewValue(); |
119 | pCol=this->next(); | 119 | pCol=this->next(); |
120 | } | 120 | } |
121 | _currentItem=new QListViewItem(_typeTable, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7] ); | 121 | _currentItem=new QListViewItem(_typeTable, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7] ); |
122 | 122 | ||
123 | // fix uniques | 123 | // fix uniques |
124 | fixTypes(); | 124 | fixTypes(); |
125 | 125 | ||
126 | // display col 0 of new value | 126 | // display col 0 of new value |
127 | QPoint pnt; | 127 | QPoint pnt; |
128 | slotClick(_currentItem, pnt, 0); | 128 | slotClick(_currentItem, pnt, 0); |
129 | _typeTable->setSelected( _currentItem, true ); | 129 | _typeTable->setSelected( _currentItem, true ); |
130 | 130 | ||
131 | // make it selected | 131 | // make it selected |
132 | _typeEdit->setCursorPosition(0); | 132 | _typeEdit->setCursorPosition(0); |
133 | _typeEdit->setSelection(0, _typeEdit->text().length() ); | 133 | _typeEdit->setSelection(0, _typeEdit->text().length() ); |
134 | } | 134 | } |
135 | 135 | ||
136 | // --- slotDel ------------------------------------------------------------- | 136 | // --- slotDel ------------------------------------------------------------- |
137 | void ListEdit::slotDel() | 137 | void ListEdit::slotDel() |
138 | { | 138 | { |
139 | if( !_currentItem ) return; | 139 | if( !_currentItem ) return; |
140 | delete _currentItem; | 140 | delete _currentItem; |
141 | _currentItem=NULL; | 141 | _currentItem=NULL; |
142 | _typeEdit->setText(""); | 142 | _typeEdit->setText(""); |
143 | _stack->raiseWidget(_typeEdit); | 143 | _stack->raiseWidget(_typeEdit); |
144 | } | 144 | } |
145 | 145 | ||
146 | 146 | ||
147 | // --- fixTypes ---------------------------------------------------------------- | 147 | // --- fixTypes ---------------------------------------------------------------- |
148 | // Makes sure all entries have a unique name and empty entries are replaced | 148 | // Makes sure all entries have a unique name and empty entries are replaced |
149 | // by a generic string. The first version performs the operation on a particular | 149 | // by a generic string. The first version performs the operation on a particular |
150 | // column, whereas the 2nd does it for all unique columns. | 150 | // column, whereas the 2nd does it for all unique columns. |
151 | class ColMap { | 151 | class ColMap { |
152 | public: | 152 | public: |
153 | ColMap(QString sValue, QListViewItem *pEntry) { | 153 | ColMap(QString sValue, QListViewItem *pEntry) { |
154 | _sValue=sValue; | 154 | _sValue=sValue; |
155 | _pEntry=pEntry; | 155 | _pEntry=pEntry; |
156 | } | 156 | } |
157 | QString &getValue() { return(_sValue); } | 157 | QString &getValue() { return(_sValue); } |
158 | QListViewItem *getItem() { return(_pEntry); } | 158 | QListViewItem *getItem() { return(_pEntry); } |
159 | 159 | ||
160 | protected: | 160 | protected: |
161 | QString _sValue; | 161 | QString _sValue; |
162 | QListViewItem *_pEntry; | 162 | QListViewItem *_pEntry; |
163 | }; | 163 | }; |
164 | 164 | ||
165 | class ColList : public QList<QString> | 165 | class ColList : public QList<QString> |
166 | { | 166 | { |
167 | public: | 167 | public: |
168 | ColList() : QList<QString>() { } | 168 | ColList() : QList<QString>() { } |
169 | 169 | ||
170 | protected: | 170 | protected: |
171 | int compareItems(QCollection::Item, QCollection::Item); | 171 | int compareItems(QCollection::Item, QCollection::Item); |
172 | }; | 172 | }; |
173 | 173 | ||
174 | int ColList::compareItems(QCollection::Item i1, QCollection::Item i2) { | 174 | int ColList::compareItems(QCollection::Item i1, QCollection::Item i2) { |
175 | return( ((QString *)i1)->compare(*(QString *)i2) ); | 175 | return( ((QString *)i1)->compare(*(QString *)i2) ); |
176 | } | 176 | } |
177 | 177 | ||
178 | void ListEdit::fixTypes(int iColumn) | 178 | void ListEdit::fixTypes(int iColumn) |
179 | { | 179 | { |
180 | // get column def | 180 | // get column def |
181 | ColumnDef *pDef=this->at(iColumn); | 181 | ColumnDef *pDef=this->at(iColumn); |
182 | 182 | ||
183 | // create map of entries | 183 | // create map of entries |
184 | if( !_typeTable->childCount() ) return; | 184 | if( !_typeTable->childCount() ) return; |
185 | ColMap **colMap=new ColMap *[_typeTable->childCount()]; | 185 | ColMap **colMap=new ColMap *[_typeTable->childCount()]; |
186 | QListViewItem *cur=_typeTable->firstChild(); | 186 | QListViewItem *cur=_typeTable->firstChild(); |
187 | ColList lst; | 187 | ColList lst; |
188 | for(int i=0; i<_typeTable->childCount(); i++) { | 188 | for(int i=0; i<_typeTable->childCount(); i++) { |
189 | colMap[i]=new ColMap(cur->text(iColumn), cur); | 189 | colMap[i]=new ColMap(cur->text(iColumn), cur); |
190 | lst.append( &(colMap[i]->getValue()) ); | 190 | lst.append( &(colMap[i]->getValue()) ); |
191 | cur=cur->nextSibling(); | 191 | cur=cur->nextSibling(); |
192 | } | 192 | } |
193 | 193 | ||
194 | // fix empty entries | 194 | // fix empty entries |
195 | int i=0; | 195 | int i=0; |
196 | for(QString *ptr=lst.first(); ptr; ptr=lst.next()) { | 196 | for(QString *ptr=lst.first(); ptr; ptr=lst.next()) { |
197 | *ptr=ptr->stripWhiteSpace(); | 197 | *ptr=ptr->stripWhiteSpace(); |
198 | if( ptr->isEmpty() ) { | 198 | if( ptr->isEmpty() ) { |
199 | i++; | 199 | i++; |
200 | if( i==1 ) *ptr=pDef->getNewValue(); | 200 | if( i==1 ) *ptr=pDef->getNewValue(); |
201 | else ptr->sprintf("%s %d", (const char *)pDef->getNewValue(), i); | 201 | else ptr->sprintf("%s %d", (const char *)pDef->getNewValue(), i); |
202 | } | 202 | } |
203 | } | 203 | } |
204 | 204 | ||
205 | // fix dups | 205 | // fix dups |
206 | lst.sort(); | 206 | lst.sort(); |
207 | QString repl; | 207 | QString repl; |
208 | for(uint iCur=0; iCur<lst.count()-1; iCur++) { | 208 | for(uint iCur=0; iCur<lst.count()-1; iCur++) { |
209 | QString *current=lst.at(iCur); | 209 | QString *current=lst.at(iCur); |
210 | for(uint iNext=iCur+1; iNext<lst.count(); iNext++ ) { | 210 | for(uint iNext=iCur+1; iNext<lst.count(); iNext++ ) { |
211 | if( *current!=*lst.at(iNext) ) continue; | 211 | if( *current!=*lst.at(iNext) ) continue; |
212 | for(int i=2; ; i++) { | 212 | for(int i=2; ; i++) { |
213 | repl.sprintf("%s %d", (const char *)*current, i); | 213 | repl.sprintf("%s %d", (const char *)*current, i); |
214 | bool bDup=false; | 214 | bool bDup=false; |
215 | uint iChk=iNext+1; | 215 | uint iChk=iNext+1; |
216 | while( iChk<lst.count() ) { | 216 | while( iChk<lst.count() ) { |
217 | QString *chk=lst.at(iChk); | 217 | QString *chk=lst.at(iChk); |
218 | if( !chk->startsWith(*current) ) break; | 218 | if( !chk->startsWith(*current) ) break; |
219 | if( *chk==repl ) { | 219 | if( *chk==repl ) { |
220 | bDup=true; | 220 | bDup=true; |
221 | break; | 221 | break; |
222 | } | 222 | } |
223 | iChk++; | 223 | iChk++; |
224 | } | 224 | } |
225 | if( !bDup ) { | 225 | if( !bDup ) { |
226 | *lst.at(iNext)=repl; | 226 | *lst.at(iNext)=repl; |
227 | break; | 227 | break; |
228 | } | 228 | } |
229 | } | 229 | } |
230 | } | 230 | } |
231 | } | 231 | } |
232 | lst.sort(); | 232 | lst.sort(); |
233 | 233 | ||
234 | // copy back clean up col map | 234 | // copy back clean up col map |
235 | for(int i=0; i<_typeTable->childCount(); i++) { | 235 | for(int i=0; i<_typeTable->childCount(); i++) { |
236 | colMap[i]->getItem()->setText(iColumn, colMap[i]->getValue()); | 236 | colMap[i]->getItem()->setText(iColumn, colMap[i]->getValue()); |
237 | delete colMap[i]; | 237 | delete colMap[i]; |
238 | } | 238 | } |
239 | delete colMap; | 239 | delete [] colMap; |
240 | } | 240 | } |
241 | 241 | ||
242 | void ListEdit::fixTypes() | 242 | void ListEdit::fixTypes() |
243 | { | 243 | { |
244 | int i; | 244 | int i; |
245 | ColumnDef *pDef; | 245 | ColumnDef *pDef; |
246 | for(pDef=this->first(), i=0; pDef; pDef=this->next(), i++) { | 246 | for(pDef=this->first(), i=0; pDef; pDef=this->next(), i++) { |
247 | if( pDef->hasFlag(ColumnDef::typeUnique) ) | 247 | if( pDef->hasFlag(ColumnDef::typeUnique) ) |
248 | fixTypes(i); | 248 | fixTypes(i); |
249 | } | 249 | } |
250 | _typeTable->sort(); | 250 | _typeTable->sort(); |
251 | } | 251 | } |
252 | 252 | ||
253 | 253 | ||
254 | // --- storeInList ------------------------------------------------------------ | 254 | // --- storeInList ------------------------------------------------------------ |
255 | void ListEdit::storeInList(QStringList &lst) | 255 | void ListEdit::storeInList(QStringList &lst) |
256 | { | 256 | { |
257 | // delete old content | 257 | // delete old content |
258 | lst.clear(); | 258 | lst.clear(); |
259 | 259 | ||
260 | // add new one | 260 | // add new one |
261 | fixTypes(); | 261 | fixTypes(); |
262 | QListViewItem *itm=_typeTable->firstChild(); | 262 | QListViewItem *itm=_typeTable->firstChild(); |
263 | while( itm ) { | 263 | while( itm ) { |
264 | int i=0; | 264 | int i=0; |
265 | QString sAdd; | 265 | QString sAdd; |
266 | ColumnDef *pDef; | 266 | ColumnDef *pDef; |
267 | for(pDef=this->first(), i=0; pDef; pDef=this->next(), i++) { | 267 | for(pDef=this->first(), i=0; pDef; pDef=this->next(), i++) { |
268 | if( i>=1 ) sAdd+=";"; | 268 | if( i>=1 ) sAdd+=";"; |
269 | sAdd += itm->text(i); | 269 | sAdd += itm->text(i); |
270 | } | 270 | } |
271 | lst.append( sAdd ); | 271 | lst.append( sAdd ); |
272 | itm=itm->nextSibling(); | 272 | itm=itm->nextSibling(); |
273 | } | 273 | } |
274 | } | 274 | } |
275 | 275 | ||
276 | 276 | ||
277 | // --- slotClicked ------------------------------------------------------------ | 277 | // --- slotClicked ------------------------------------------------------------ |
278 | void ListEdit::slotClick(QListViewItem *itm, const QPoint &pnt, int col) | 278 | void ListEdit::slotClick(QListViewItem *itm, const QPoint &pnt, int col) |
279 | { | 279 | { |
280 | (void)pnt; // get rid of unused warning; | 280 | (void)pnt; // get rid of unused warning; |
281 | 281 | ||
282 | // save values | 282 | // save values |
283 | _currentItem=itm; | 283 | _currentItem=itm; |
284 | _currentColumn=col; | 284 | _currentColumn=col; |
285 | if( itm==NULL ) { | 285 | if( itm==NULL ) { |
286 | _typeEdit->setText(""); | 286 | _typeEdit->setText(""); |
287 | _stack->raiseWidget(_typeEdit); | 287 | _stack->raiseWidget(_typeEdit); |
288 | return; | 288 | return; |
289 | } | 289 | } |
290 | 290 | ||
291 | // display value | 291 | // display value |
292 | if( _currentColumn<0 ) _currentColumn=0; | 292 | if( _currentColumn<0 ) _currentColumn=0; |
293 | ColumnDef *pDef=this->at(_currentColumn); | 293 | ColumnDef *pDef=this->at(_currentColumn); |
294 | if( pDef->isType(ColumnDef::typeString) ) { | 294 | if( pDef->isType(ColumnDef::typeString) ) { |
295 | _typeEdit->setText( _currentItem->text(_currentColumn) ); | 295 | _typeEdit->setText( _currentItem->text(_currentColumn) ); |
296 | _stack->raiseWidget(_typeEdit); | 296 | _stack->raiseWidget(_typeEdit); |
297 | } else if( pDef->isType(ColumnDef::typeList) ){ | 297 | } else if( pDef->isType(ColumnDef::typeList) ){ |
298 | _box->clear(); | 298 | _box->clear(); |
299 | _box->insertStringList( pDef->getValueList() ); | 299 | _box->insertStringList( pDef->getValueList() ); |
300 | QStringList::Iterator itr; | 300 | QStringList::Iterator itr; |
301 | int i=0; | 301 | int i=0; |
302 | for(itr=pDef->getValueList().begin(); itr!=pDef->getValueList().end(); itr++) { | 302 | for(itr=pDef->getValueList().begin(); itr!=pDef->getValueList().end(); itr++) { |
303 | if( (*itr)==_currentItem->text(_currentColumn) ) { | 303 | if( (*itr)==_currentItem->text(_currentColumn) ) { |
304 | _box->setCurrentItem(i); | 304 | _box->setCurrentItem(i); |
305 | i=-1; | 305 | i=-1; |
306 | break; | 306 | break; |
307 | } | 307 | } |
308 | i++; | 308 | i++; |
309 | } | 309 | } |
310 | if( i>=0 ) { | 310 | if( i>=0 ) { |
311 | _box->insertItem( _currentItem->text(_currentColumn) ); | 311 | _box->insertItem( _currentItem->text(_currentColumn) ); |
312 | _box->setCurrentItem(i); | 312 | _box->setCurrentItem(i); |
313 | } | 313 | } |
314 | _stack->raiseWidget(_box); | 314 | _stack->raiseWidget(_box); |
315 | } else { | 315 | } else { |
316 | odebug << "Unsupported column type for column " << (const char *)pDef->getName() << "" << oendl; | 316 | odebug << "Unsupported column type for column " << (const char *)pDef->getName() << "" << oendl; |
317 | _typeEdit->setText(""); | 317 | _typeEdit->setText(""); |
318 | _stack->raiseWidget(_typeEdit); | 318 | _stack->raiseWidget(_typeEdit); |
319 | } | 319 | } |
320 | } | 320 | } |
321 | 321 | ||
322 | 322 | ||
323 | // --- addColumnDef ----------------------------------------------------------- | 323 | // --- addColumnDef ----------------------------------------------------------- |
324 | void ListEdit::addColumnDef(ColumnDef *pDef) | 324 | void ListEdit::addColumnDef(ColumnDef *pDef) |
325 | { | 325 | { |
326 | _typeTable->addColumn( pDef->getName() ); | 326 | _typeTable->addColumn( pDef->getName() ); |
327 | _vColumns.append(pDef); | 327 | _vColumns.append(pDef); |
328 | } | 328 | } |
329 | 329 | ||
330 | // --- addData ---------------------------------------------------------------- | 330 | // --- addData ---------------------------------------------------------------- |
331 | void ListEdit::addData(QStringList &lst) | 331 | void ListEdit::addData(QStringList &lst) |
332 | { | 332 | { |
333 | // run through list | 333 | // run through list |
334 | QStringList::Iterator itr; | 334 | QStringList::Iterator itr; |
335 | for(itr=lst.begin(); itr!=lst.end(); itr++) { | 335 | for(itr=lst.begin(); itr!=lst.end(); itr++) { |
336 | QStringList split=QStringList::split(";", *itr, true); | 336 | QStringList split=QStringList::split(";", *itr, true); |
337 | QStringList::Iterator entry; | 337 | QStringList::Iterator entry; |
338 | QString args[8]; | 338 | QString args[8]; |
339 | int i=0; | 339 | int i=0; |
340 | for(entry=split.begin(); entry!=split.end() && i<8; entry++, i++) { | 340 | for(entry=split.begin(); entry!=split.end() && i<8; entry++, i++) { |
341 | args[i]= (*entry); | 341 | args[i]= (*entry); |
342 | } | 342 | } |
343 | while(i<8) { | 343 | while(i<8) { |
344 | args[i++]=""; | 344 | args[i++]=""; |
345 | } | 345 | } |
346 | new QListViewItem(_typeTable, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]); | 346 | new QListViewItem(_typeTable, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]); |
347 | } | 347 | } |
348 | } | 348 | } |
349 | 349 | ||
350 | // --- slotActivated ---------------------------------------------------------- | 350 | // --- slotActivated ---------------------------------------------------------- |
351 | void ListEdit::slotActivated(const QString &str) | 351 | void ListEdit::slotActivated(const QString &str) |
352 | { | 352 | { |
353 | if( _currentItem==NULL || _currentColumn<0 ) return; | 353 | if( _currentItem==NULL || _currentColumn<0 ) return; |
354 | _currentItem->setText(_currentColumn, str); | 354 | _currentItem->setText(_currentColumn, str); |
355 | } | 355 | } |
diff --git a/noncore/apps/opie-console/TEScreen.cpp b/noncore/apps/opie-console/TEScreen.cpp index 2675d31..8e91532 100644 --- a/noncore/apps/opie-console/TEScreen.cpp +++ b/noncore/apps/opie-console/TEScreen.cpp | |||
@@ -1,1208 +1,1208 @@ | |||
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 | 18 | ||
19 | /*! \file | 19 | /*! \file |
20 | */ | 20 | */ |
21 | 21 | ||
22 | /*! \class TEScreen | 22 | /*! \class TEScreen |
23 | 23 | ||
24 | \brief The image manipulated by the emulation. | 24 | \brief The image manipulated by the emulation. |
25 | 25 | ||
26 | This class implements the operations of the terminal emulation framework. | 26 | This class implements the operations of the terminal emulation framework. |
27 | It is a complete passive device, driven by the emulation decoder | 27 | It is a complete passive device, driven by the emulation decoder |
28 | (TEmuVT102). By this it forms in fact an ADT, that defines operations | 28 | (TEmuVT102). By this it forms in fact an ADT, that defines operations |
29 | on a rectangular image. | 29 | on a rectangular image. |
30 | 30 | ||
31 | It does neither know how to display its image nor about escape sequences. | 31 | It does neither know how to display its image nor about escape sequences. |
32 | It is further independent of the underlying toolkit. By this, one can even | 32 | It is further independent of the underlying toolkit. By this, one can even |
33 | use this module for an ordinary text surface. | 33 | use this module for an ordinary text surface. |
34 | 34 | ||
35 | Since the operations are called by a specific emulation decoder, one may | 35 | Since the operations are called by a specific emulation decoder, one may |
36 | collect their different operations here. | 36 | collect their different operations here. |
37 | 37 | ||
38 | The state manipulated by the operations is mainly kept in `image', though | 38 | The state manipulated by the operations is mainly kept in `image', though |
39 | it is a little more complex bejond this. See the header file of the class. | 39 | it is a little more complex bejond this. See the header file of the class. |
40 | 40 | ||
41 | \sa TEWidget \sa VT102Emulation | 41 | \sa TEWidget \sa VT102Emulation |
42 | */ | 42 | */ |
43 | 43 | ||
44 | #include <stdio.h> | 44 | #include <stdio.h> |
45 | #include <stdlib.h> | 45 | #include <stdlib.h> |
46 | #include <unistd.h> | 46 | #include <unistd.h> |
47 | // #include <kdebug.h> | 47 | // #include <kdebug.h> |
48 | 48 | ||
49 | #include <assert.h> | 49 | #include <assert.h> |
50 | #include <string.h> | 50 | #include <string.h> |
51 | #include <ctype.h> | 51 | #include <ctype.h> |
52 | 52 | ||
53 | #include "TEScreen.h" | 53 | #include "TEScreen.h" |
54 | 54 | ||
55 | #define HERE printf("%s(%d): here\n",__FILE__,__LINE__) | 55 | #define HERE printf("%s(%d): here\n",__FILE__,__LINE__) |
56 | 56 | ||
57 | //FIXME: this is emulation specific. Use FALSE for xterm, TRUE for ANSI. | 57 | //FIXME: this is emulation specific. Use FALSE for xterm, TRUE for ANSI. |
58 | //FIXME: see if we can get this from terminfo. | 58 | //FIXME: see if we can get this from terminfo. |
59 | #define BS_CLEARS FALSE | 59 | #define BS_CLEARS FALSE |
60 | 60 | ||
61 | #define loc(X,Y) ((Y)*columns+(X)) | 61 | #define loc(X,Y) ((Y)*columns+(X)) |
62 | 62 | ||
63 | /*! creates a `TEScreen' of `lines' lines and `columns' columns. | 63 | /*! creates a `TEScreen' of `lines' lines and `columns' columns. |
64 | */ | 64 | */ |
65 | 65 | ||
66 | TEScreen::TEScreen(int lines, int columns) | 66 | TEScreen::TEScreen(int lines, int columns) |
67 | { | 67 | { |
68 | this->lines = lines; | 68 | this->lines = lines; |
69 | this->columns = columns; | 69 | this->columns = columns; |
70 | 70 | ||
71 | image = (ca*) malloc(lines*columns*sizeof(ca)); | 71 | image = (ca*) malloc(lines*columns*sizeof(ca)); |
72 | tabstops = NULL; initTabStops(); | 72 | tabstops = NULL; initTabStops(); |
73 | 73 | ||
74 | histCursor = 0; | 74 | histCursor = 0; |
75 | 75 | ||
76 | clearSelection(); | 76 | clearSelection(); |
77 | reset(); | 77 | reset(); |
78 | } | 78 | } |
79 | 79 | ||
80 | /*! Destructor | 80 | /*! Destructor |
81 | */ | 81 | */ |
82 | 82 | ||
83 | TEScreen::~TEScreen() | 83 | TEScreen::~TEScreen() |
84 | { | 84 | { |
85 | free(image); | 85 | free(image); |
86 | if (tabstops) free(tabstops); | 86 | if (tabstops) free(tabstops); |
87 | } | 87 | } |
88 | 88 | ||
89 | /* ------------------------------------------------------------------------- */ | 89 | /* ------------------------------------------------------------------------- */ |
90 | /* */ | 90 | /* */ |
91 | /* Normalized Screen Operations */ | 91 | /* Normalized Screen Operations */ |
92 | /* */ | 92 | /* */ |
93 | /* ------------------------------------------------------------------------- */ | 93 | /* ------------------------------------------------------------------------- */ |
94 | 94 | ||
95 | // Cursor Setting -------------------------------------------------------------- | 95 | // Cursor Setting -------------------------------------------------------------- |
96 | 96 | ||
97 | /*! \section Cursor | 97 | /*! \section Cursor |
98 | 98 | ||
99 | The `cursor' is a location within the screen that is implicitely used in | 99 | The `cursor' is a location within the screen that is implicitely used in |
100 | many operations. The operations within this section allow to manipulate | 100 | many operations. The operations within this section allow to manipulate |
101 | the cursor explicitly and to obtain it's value. | 101 | the cursor explicitly and to obtain it's value. |
102 | 102 | ||
103 | The position of the cursor is guarantied to be between (including) 0 and | 103 | The position of the cursor is guarantied to be between (including) 0 and |
104 | `columns-1' and `lines-1'. | 104 | `columns-1' and `lines-1'. |
105 | */ | 105 | */ |
106 | 106 | ||
107 | /*! | 107 | /*! |
108 | Move the cursor up. | 108 | Move the cursor up. |
109 | 109 | ||
110 | The cursor will not be moved beyond the top margin. | 110 | The cursor will not be moved beyond the top margin. |
111 | */ | 111 | */ |
112 | 112 | ||
113 | void TEScreen::cursorUp(int n) | 113 | void TEScreen::cursorUp(int n) |
114 | //=CUU | 114 | //=CUU |
115 | { | 115 | { |
116 | if (n == 0) n = 1; // Default | 116 | if (n == 0) n = 1; // Default |
117 | int stop = cuY < tmargin ? 0 : tmargin; | 117 | int stop = cuY < tmargin ? 0 : tmargin; |
118 | cuX = QMIN(columns-1,cuX); // nowrap! | 118 | cuX = QMIN(columns-1,cuX); // nowrap! |
119 | cuY = QMAX(stop,cuY-n); | 119 | cuY = QMAX(stop,cuY-n); |
120 | } | 120 | } |
121 | 121 | ||
122 | /*! | 122 | /*! |
123 | Move the cursor down. | 123 | Move the cursor down. |
124 | 124 | ||
125 | The cursor will not be moved beyond the bottom margin. | 125 | The cursor will not be moved beyond the bottom margin. |
126 | */ | 126 | */ |
127 | 127 | ||
128 | void TEScreen::cursorDown(int n) | 128 | void TEScreen::cursorDown(int n) |
129 | //=CUD | 129 | //=CUD |
130 | { | 130 | { |
131 | if (n == 0) n = 1; // Default | 131 | if (n == 0) n = 1; // Default |
132 | int stop = cuY > bmargin ? lines-1 : bmargin; | 132 | int stop = cuY > bmargin ? lines-1 : bmargin; |
133 | cuX = QMIN(columns-1,cuX); // nowrap! | 133 | cuX = QMIN(columns-1,cuX); // nowrap! |
134 | cuY = QMIN(stop,cuY+n); | 134 | cuY = QMIN(stop,cuY+n); |
135 | } | 135 | } |
136 | 136 | ||
137 | /*! | 137 | /*! |
138 | Move the cursor left. | 138 | Move the cursor left. |
139 | 139 | ||
140 | The cursor will not move beyond the first column. | 140 | The cursor will not move beyond the first column. |
141 | */ | 141 | */ |
142 | 142 | ||
143 | void TEScreen::cursorLeft(int n) | 143 | void TEScreen::cursorLeft(int n) |
144 | //=CUB | 144 | //=CUB |
145 | { | 145 | { |
146 | if (n == 0) n = 1; // Default | 146 | if (n == 0) n = 1; // Default |
147 | cuX = QMIN(columns-1,cuX); // nowrap! | 147 | cuX = QMIN(columns-1,cuX); // nowrap! |
148 | cuX = QMAX(0,cuX-n); | 148 | cuX = QMAX(0,cuX-n); |
149 | } | 149 | } |
150 | 150 | ||
151 | /*! | 151 | /*! |
152 | Move the cursor left. | 152 | Move the cursor left. |
153 | 153 | ||
154 | The cursor will not move beyond the rightmost column. | 154 | The cursor will not move beyond the rightmost column. |
155 | */ | 155 | */ |
156 | 156 | ||
157 | void TEScreen::cursorRight(int n) | 157 | void TEScreen::cursorRight(int n) |
158 | //=CUF | 158 | //=CUF |
159 | { | 159 | { |
160 | if (n == 0) n = 1; // Default | 160 | if (n == 0) n = 1; // Default |
161 | cuX = QMIN(columns-1,cuX+n); | 161 | cuX = QMIN(columns-1,cuX+n); |
162 | } | 162 | } |
163 | 163 | ||
164 | /*! | 164 | /*! |
165 | Set top and bottom margin. | 165 | Set top and bottom margin. |
166 | */ | 166 | */ |
167 | 167 | ||
168 | void TEScreen::setMargins(int top, int bot) | 168 | void TEScreen::setMargins(int top, int bot) |
169 | //=STBM | 169 | //=STBM |
170 | { | 170 | { |
171 | if (top == 0) top = 1; // Default | 171 | if (top == 0) top = 1; // Default |
172 | if (bot == 0) bot = lines; // Default | 172 | if (bot == 0) bot = lines; // Default |
173 | top = top - 1; // Adjust to internal lineno | 173 | top = top - 1; // Adjust to internal lineno |
174 | bot = bot - 1; // Adjust to internal lineno | 174 | bot = bot - 1; // Adjust to internal lineno |
175 | if ( !( 0 <= top && top < bot && bot < lines ) ) | 175 | if ( !( 0 <= top && top < bot && bot < lines ) ) |
176 | { fprintf(stderr,"%s(%d) : setRegion(%d,%d) : bad range.\n", | 176 | { fprintf(stderr,"%s(%d) : setRegion(%d,%d) : bad range.\n", |
177 | __FILE__,__LINE__,top,bot); | 177 | __FILE__,__LINE__,top,bot); |
178 | return; // Default error action: ignore | 178 | return; // Default error action: ignore |
179 | } | 179 | } |
180 | tmargin = top; | 180 | tmargin = top; |
181 | bmargin = bot; | 181 | bmargin = bot; |
182 | cuX = 0; | 182 | cuX = 0; |
183 | cuY = getMode(MODE_Origin) ? top : 0; | 183 | cuY = getMode(MODE_Origin) ? top : 0; |
184 | } | 184 | } |
185 | 185 | ||
186 | /*! | 186 | /*! |
187 | Move the cursor down one line. | 187 | Move the cursor down one line. |
188 | 188 | ||
189 | If cursor is on bottom margin, the region between the | 189 | If cursor is on bottom margin, the region between the |
190 | actual top and bottom margin is scrolled up instead. | 190 | actual top and bottom margin is scrolled up instead. |
191 | */ | 191 | */ |
192 | 192 | ||
193 | void TEScreen::index() | 193 | void TEScreen::index() |
194 | //=IND | 194 | //=IND |
195 | { | 195 | { |
196 | if (cuY == bmargin) | 196 | if (cuY == bmargin) |
197 | { | 197 | { |
198 | if (tmargin == 0 && bmargin == lines-1) addHistLine(); // hist.history | 198 | if (tmargin == 0 && bmargin == lines-1) addHistLine(); // hist.history |
199 | scrollUp(tmargin,1); | 199 | scrollUp(tmargin,1); |
200 | } | 200 | } |
201 | else if (cuY < lines-1) | 201 | else if (cuY < lines-1) |
202 | cuY += 1; | 202 | cuY += 1; |
203 | } | 203 | } |
204 | 204 | ||
205 | /*! | 205 | /*! |
206 | Move the cursor up one line. | 206 | Move the cursor up one line. |
207 | 207 | ||
208 | If cursor is on the top margin, the region between the | 208 | If cursor is on the top margin, the region between the |
209 | actual top and bottom margin is scrolled down instead. | 209 | actual top and bottom margin is scrolled down instead. |
210 | */ | 210 | */ |
211 | 211 | ||
212 | void TEScreen::reverseIndex() | 212 | void TEScreen::reverseIndex() |
213 | //=RI | 213 | //=RI |
214 | { | 214 | { |
215 | if (cuY == tmargin) | 215 | if (cuY == tmargin) |
216 | scrollDown(tmargin,1); | 216 | scrollDown(tmargin,1); |
217 | else if (cuY > 0) | 217 | else if (cuY > 0) |
218 | cuY -= 1; | 218 | cuY -= 1; |
219 | } | 219 | } |
220 | 220 | ||
221 | /*! | 221 | /*! |
222 | Move the cursor to the begin of the next line. | 222 | Move the cursor to the begin of the next line. |
223 | 223 | ||
224 | If cursor is on bottom margin, the region between the | 224 | If cursor is on bottom margin, the region between the |
225 | actual top and bottom margin is scrolled up. | 225 | actual top and bottom margin is scrolled up. |
226 | */ | 226 | */ |
227 | 227 | ||
228 | void TEScreen::NextLine() | 228 | void TEScreen::NextLine() |
229 | //=NEL | 229 | //=NEL |
230 | { | 230 | { |
231 | Return(); index(); | 231 | Return(); index(); |
232 | } | 232 | } |
233 | 233 | ||
234 | // Line Editing ---------------------------------------------------------------- | 234 | // Line Editing ---------------------------------------------------------------- |
235 | 235 | ||
236 | /*! \section inserting / deleting characters | 236 | /*! \section inserting / deleting characters |
237 | */ | 237 | */ |
238 | 238 | ||
239 | /*! erase `n' characters starting from (including) the cursor position. | 239 | /*! erase `n' characters starting from (including) the cursor position. |
240 | 240 | ||
241 | The line is filled in from the right with spaces. | 241 | The line is filled in from the right with spaces. |
242 | */ | 242 | */ |
243 | 243 | ||
244 | void TEScreen::eraseChars(int n) | 244 | void TEScreen::eraseChars(int n) |
245 | { | 245 | { |
246 | if (n == 0) n = 1; // Default | 246 | if (n == 0) n = 1; // Default |
247 | int p = QMAX(0,QMIN(cuX+n-1,columns-1)); | 247 | int p = QMAX(0,QMIN(cuX+n-1,columns-1)); |
248 | clearImage(loc(cuX,cuY),loc(p,cuY),' '); | 248 | clearImage(loc(cuX,cuY),loc(p,cuY),' '); |
249 | } | 249 | } |
250 | 250 | ||
251 | /*! delete `n' characters starting from (including) the cursor position. | 251 | /*! delete `n' characters starting from (including) the cursor position. |
252 | 252 | ||
253 | The line is filled in from the right with spaces. | 253 | The line is filled in from the right with spaces. |
254 | */ | 254 | */ |
255 | 255 | ||
256 | void TEScreen::deleteChars(int n) | 256 | void TEScreen::deleteChars(int n) |
257 | { | 257 | { |
258 | if (n == 0) n = 1; // Default | 258 | if (n == 0) n = 1; // Default |
259 | int p = QMAX(0,QMIN(cuX+n,columns-1)); | 259 | int p = QMAX(0,QMIN(cuX+n,columns-1)); |
260 | moveImage(loc(cuX,cuY),loc(p,cuY),loc(columns-1,cuY)); | 260 | moveImage(loc(cuX,cuY),loc(p,cuY),loc(columns-1,cuY)); |
261 | clearImage(loc(columns-n,cuY),loc(columns-1,cuY),' '); | 261 | clearImage(loc(columns-n,cuY),loc(columns-1,cuY),' '); |
262 | } | 262 | } |
263 | 263 | ||
264 | /*! insert `n' spaces at the cursor position. | 264 | /*! insert `n' spaces at the cursor position. |
265 | 265 | ||
266 | The cursor is not moved by the operation. | 266 | The cursor is not moved by the operation. |
267 | */ | 267 | */ |
268 | 268 | ||
269 | void TEScreen::insertChars(int n) | 269 | void TEScreen::insertChars(int n) |
270 | { | 270 | { |
271 | if (n == 0) n = 1; // Default | 271 | if (n == 0) n = 1; // Default |
272 | int p = QMAX(0,QMIN(columns-1-n,columns-1)); | 272 | int p = QMAX(0,QMIN(columns-1-n,columns-1)); |
273 | int q = QMAX(0,QMIN(cuX+n,columns-1)); | 273 | int q = QMAX(0,QMIN(cuX+n,columns-1)); |
274 | moveImage(loc(q,cuY),loc(cuX,cuY),loc(p,cuY)); | 274 | moveImage(loc(q,cuY),loc(cuX,cuY),loc(p,cuY)); |
275 | clearImage(loc(cuX,cuY),loc(q-1,cuY),' '); | 275 | clearImage(loc(cuX,cuY),loc(q-1,cuY),' '); |
276 | } | 276 | } |
277 | 277 | ||
278 | /*! delete `n' lines starting from (including) the cursor position. | 278 | /*! delete `n' lines starting from (including) the cursor position. |
279 | 279 | ||
280 | The cursor is not moved by the operation. | 280 | The cursor is not moved by the operation. |
281 | */ | 281 | */ |
282 | 282 | ||
283 | void TEScreen::deleteLines(int n) | 283 | void TEScreen::deleteLines(int n) |
284 | { | 284 | { |
285 | if (n == 0) n = 1; // Default | 285 | if (n == 0) n = 1; // Default |
286 | scrollUp(cuY,n); | 286 | scrollUp(cuY,n); |
287 | } | 287 | } |
288 | 288 | ||
289 | /*! insert `n' lines at the cursor position. | 289 | /*! insert `n' lines at the cursor position. |
290 | 290 | ||
291 | The cursor is not moved by the operation. | 291 | The cursor is not moved by the operation. |
292 | */ | 292 | */ |
293 | 293 | ||
294 | void TEScreen::insertLines(int n) | 294 | void TEScreen::insertLines(int n) |
295 | { | 295 | { |
296 | if (n == 0) n = 1; // Default | 296 | if (n == 0) n = 1; // Default |
297 | scrollDown(cuY,n); | 297 | scrollDown(cuY,n); |
298 | } | 298 | } |
299 | 299 | ||
300 | // Mode Operations ----------------------------------------------------------- | 300 | // Mode Operations ----------------------------------------------------------- |
301 | 301 | ||
302 | /*! Set a specific mode. */ | 302 | /*! Set a specific mode. */ |
303 | 303 | ||
304 | void TEScreen::setMode(int m) | 304 | void TEScreen::setMode(int m) |
305 | { | 305 | { |
306 | currParm.mode[m] = TRUE; | 306 | currParm.mode[m] = TRUE; |
307 | switch(m) | 307 | switch(m) |
308 | { | 308 | { |
309 | case MODE_Origin : cuX = 0; cuY = tmargin; break; //FIXME: home | 309 | case MODE_Origin : cuX = 0; cuY = tmargin; break; //FIXME: home |
310 | } | 310 | } |
311 | } | 311 | } |
312 | 312 | ||
313 | /*! Reset a specific mode. */ | 313 | /*! Reset a specific mode. */ |
314 | 314 | ||
315 | void TEScreen::resetMode(int m) | 315 | void TEScreen::resetMode(int m) |
316 | { | 316 | { |
317 | currParm.mode[m] = FALSE; | 317 | currParm.mode[m] = FALSE; |
318 | switch(m) | 318 | switch(m) |
319 | { | 319 | { |
320 | case MODE_Origin : cuX = 0; cuY = 0; break; //FIXME: home | 320 | case MODE_Origin : cuX = 0; cuY = 0; break; //FIXME: home |
321 | } | 321 | } |
322 | } | 322 | } |
323 | 323 | ||
324 | /*! Save a specific mode. */ | 324 | /*! Save a specific mode. */ |
325 | 325 | ||
326 | void TEScreen::saveMode(int m) | 326 | void TEScreen::saveMode(int m) |
327 | { | 327 | { |
328 | saveParm.mode[m] = currParm.mode[m]; | 328 | saveParm.mode[m] = currParm.mode[m]; |
329 | } | 329 | } |
330 | 330 | ||
331 | /*! Restore a specific mode. */ | 331 | /*! Restore a specific mode. */ |
332 | 332 | ||
333 | void TEScreen::restoreMode(int m) | 333 | void TEScreen::restoreMode(int m) |
334 | { | 334 | { |
335 | currParm.mode[m] = saveParm.mode[m]; | 335 | currParm.mode[m] = saveParm.mode[m]; |
336 | } | 336 | } |
337 | 337 | ||
338 | //NOTE: this is a helper function | 338 | //NOTE: this is a helper function |
339 | /*! Return the setting a specific mode. */ | 339 | /*! Return the setting a specific mode. */ |
340 | BOOL TEScreen::getMode(int m) | 340 | BOOL TEScreen::getMode(int m) |
341 | { | 341 | { |
342 | return currParm.mode[m]; | 342 | return currParm.mode[m]; |
343 | } | 343 | } |
344 | 344 | ||
345 | /*! Save the cursor position and the rendition attribute settings. */ | 345 | /*! Save the cursor position and the rendition attribute settings. */ |
346 | 346 | ||
347 | void TEScreen::saveCursor() | 347 | void TEScreen::saveCursor() |
348 | { | 348 | { |
349 | sa_cuX = cuX; | 349 | sa_cuX = cuX; |
350 | sa_cuY = cuY; | 350 | sa_cuY = cuY; |
351 | sa_cu_re = cu_re; | 351 | sa_cu_re = cu_re; |
352 | sa_cu_fg = cu_fg; | 352 | sa_cu_fg = cu_fg; |
353 | sa_cu_bg = cu_bg; | 353 | sa_cu_bg = cu_bg; |
354 | } | 354 | } |
355 | 355 | ||
356 | /*! Restore the cursor position and the rendition attribute settings. */ | 356 | /*! Restore the cursor position and the rendition attribute settings. */ |
357 | 357 | ||
358 | void TEScreen::restoreCursor() | 358 | void TEScreen::restoreCursor() |
359 | { | 359 | { |
360 | cuX = QMIN(sa_cuX,columns-1); | 360 | cuX = QMIN(sa_cuX,columns-1); |
361 | cuY = QMIN(sa_cuY,lines-1); | 361 | cuY = QMIN(sa_cuY,lines-1); |
362 | cu_re = sa_cu_re; | 362 | cu_re = sa_cu_re; |
363 | cu_fg = sa_cu_fg; | 363 | cu_fg = sa_cu_fg; |
364 | cu_bg = sa_cu_bg; | 364 | cu_bg = sa_cu_bg; |
365 | effectiveRendition(); | 365 | effectiveRendition(); |
366 | } | 366 | } |
367 | 367 | ||
368 | /* ------------------------------------------------------------------------- */ | 368 | /* ------------------------------------------------------------------------- */ |
369 | /* */ | 369 | /* */ |
370 | /* Screen Operations */ | 370 | /* Screen Operations */ |
371 | /* */ | 371 | /* */ |
372 | /* ------------------------------------------------------------------------- */ | 372 | /* ------------------------------------------------------------------------- */ |
373 | 373 | ||
374 | /*! Assing a new size to the screen. | 374 | /*! Assing a new size to the screen. |
375 | 375 | ||
376 | The topmost left position is maintained, while lower lines | 376 | The topmost left position is maintained, while lower lines |
377 | or right hand side columns might be removed or filled with | 377 | or right hand side columns might be removed or filled with |
378 | spaces to fit the new size. | 378 | spaces to fit the new size. |
379 | 379 | ||
380 | The region setting is reset to the whole screen and the | 380 | The region setting is reset to the whole screen and the |
381 | tab positions reinitialized. | 381 | tab positions reinitialized. |
382 | */ | 382 | */ |
383 | 383 | ||
384 | void TEScreen::resizeImage(int new_lines, int new_columns) | 384 | void TEScreen::resizeImage(int new_lines, int new_columns) |
385 | { | 385 | { |
386 | 386 | ||
387 | if (cuY > new_lines-1) | 387 | if (cuY > new_lines-1) |
388 | { // attempt to preserve focus and lines | 388 | { // attempt to preserve focus and lines |
389 | bmargin = lines-1; //FIXME: margin lost | 389 | bmargin = lines-1; //FIXME: margin lost |
390 | for (int i = 0; i < cuY-(new_lines-1); i++) | 390 | for (int i = 0; i < cuY-(new_lines-1); i++) |
391 | { | 391 | { |
392 | addHistLine(); scrollUp(0,1); | 392 | addHistLine(); scrollUp(0,1); |
393 | } | 393 | } |
394 | } | 394 | } |
395 | 395 | ||
396 | // make new image | 396 | // make new image |
397 | ca* newimg = (ca*)malloc(new_lines*new_columns*sizeof(ca)); | 397 | ca* newimg = (ca*)malloc(new_lines*new_columns*sizeof(ca)); |
398 | 398 | ||
399 | clearSelection(); | 399 | clearSelection(); |
400 | 400 | ||
401 | // clear new image | 401 | // clear new image |
402 | for (int y = 0; y < new_lines; y++) | 402 | for (int y = 0; y < new_lines; y++) |
403 | for (int x = 0; x < new_columns; x++) | 403 | for (int x = 0; x < new_columns; x++) |
404 | { | 404 | { |
405 | newimg[y*new_columns+x].c = ' '; | 405 | newimg[y*new_columns+x].c = ' '; |
406 | newimg[y*new_columns+x].f = DEFAULT_FORE_COLOR; | 406 | newimg[y*new_columns+x].f = DEFAULT_FORE_COLOR; |
407 | newimg[y*new_columns+x].b = DEFAULT_BACK_COLOR; | 407 | newimg[y*new_columns+x].b = DEFAULT_BACK_COLOR; |
408 | newimg[y*new_columns+x].r = DEFAULT_RENDITION; | 408 | newimg[y*new_columns+x].r = DEFAULT_RENDITION; |
409 | } | 409 | } |
410 | int cpy_lines = QMIN(new_lines, lines); | 410 | int cpy_lines = QMIN(new_lines, lines); |
411 | int cpy_columns = QMIN(new_columns,columns); | 411 | int cpy_columns = QMIN(new_columns,columns); |
412 | // copy to new image | 412 | // copy to new image |
413 | for (int y = 0; y < cpy_lines; y++) | 413 | for (int y = 0; y < cpy_lines; y++) |
414 | for (int x = 0; x < cpy_columns; x++) | 414 | for (int x = 0; x < cpy_columns; x++) |
415 | { | 415 | { |
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 | free(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 | { int x,y; | 508 | { int x,y; |
509 | ca* merged = (ca*)malloc(lines*columns*sizeof(ca)); | 509 | ca* merged = (ca*)malloc(lines*columns*sizeof(ca)); |
510 | ca dft(' ',DEFAULT_FORE_COLOR,DEFAULT_BACK_COLOR,DEFAULT_RENDITION); | 510 | ca dft(' ',DEFAULT_FORE_COLOR,DEFAULT_BACK_COLOR,DEFAULT_RENDITION); |
511 | 511 | ||
512 | for (y = 0; (y < lines) && (y < (hist.getLines()-histCursor)); y++) | 512 | for (y = 0; (y < lines) && (y < (hist.getLines()-histCursor)); y++) |
513 | { | 513 | { |
514 | int len = QMIN(columns,hist.getLineLen(y+histCursor)); | 514 | int len = QMIN(columns,hist.getLineLen(y+histCursor)); |
515 | int yp = y*columns; | 515 | int yp = y*columns; |
516 | int yq = (y+histCursor)*columns; | 516 | int yq = (y+histCursor)*columns; |
517 | 517 | ||
518 | hist.getCells(y+histCursor,0,len,merged+yp); | 518 | hist.getCells(y+histCursor,0,len,merged+yp); |
519 | for (x = len; x < columns; x++) merged[yp+x] = dft; | 519 | for (x = len; x < columns; x++) merged[yp+x] = dft; |
520 | for (x = 0; x < columns; x++) | 520 | for (x = 0; x < columns; x++) |
521 | { int p=x + yp; int q=x + yq; | 521 | { int p=x + yp; int q=x + yq; |
522 | if ( ( q >= sel_TL ) && ( q <= sel_BR ) ) | 522 | if ( ( q >= sel_TL ) && ( q <= sel_BR ) ) |
523 | reverseRendition(&merged[p]); // for selection | 523 | reverseRendition(&merged[p]); // for selection |
524 | } | 524 | } |
525 | } | 525 | } |
526 | if (lines >= hist.getLines()-histCursor) | 526 | if (lines >= hist.getLines()-histCursor) |
527 | { | 527 | { |
528 | for (y = (hist.getLines()-histCursor); y < lines ; y++) | 528 | for (y = (hist.getLines()-histCursor); y < lines ; y++) |
529 | { | 529 | { |
530 | int yp = y*columns; | 530 | int yp = y*columns; |
531 | int yq = (y+histCursor)*columns; | 531 | int yq = (y+histCursor)*columns; |
532 | int yr = (y-hist.getLines()+histCursor)*columns; | 532 | int yr = (y-hist.getLines()+histCursor)*columns; |
533 | for (x = 0; x < columns; x++) | 533 | for (x = 0; x < columns; x++) |
534 | { int p = x + yp; int q = x + yq; int r = x + yr; | 534 | { int p = x + yp; int q = x + yq; int r = x + yr; |
535 | merged[p] = image[r]; | 535 | merged[p] = image[r]; |
536 | if ( q >= sel_TL && q <= sel_BR ) | 536 | if ( q >= sel_TL && q <= sel_BR ) |
537 | reverseRendition(&merged[p]); // for selection | 537 | reverseRendition(&merged[p]); // for selection |
538 | } | 538 | } |
539 | 539 | ||
540 | } | 540 | } |
541 | } | 541 | } |
542 | // evtl. inverse display | 542 | // evtl. inverse display |
543 | if (getMode(MODE_Screen)) | 543 | if (getMode(MODE_Screen)) |
544 | { int i,n = lines*columns; | 544 | { int i,n = lines*columns; |
545 | for (i = 0; i < n; i++) | 545 | for (i = 0; i < n; i++) |
546 | reverseRendition(&merged[i]); // for reverse display | 546 | reverseRendition(&merged[i]); // for reverse display |
547 | } | 547 | } |
548 | if (getMode(MODE_Cursor) && (cuY+(hist.getLines()-histCursor) < lines)) // cursor visible | 548 | if (getMode(MODE_Cursor) && (cuY+(hist.getLines()-histCursor) < lines)) // cursor visible |
549 | reverseRendition(&merged[loc(cuX,cuY+(hist.getLines()-histCursor))]); | 549 | reverseRendition(&merged[loc(cuX,cuY+(hist.getLines()-histCursor))]); |
550 | return merged; | 550 | return merged; |
551 | } | 551 | } |
552 | 552 | ||
553 | 553 | ||
554 | /*! | 554 | /*! |
555 | */ | 555 | */ |
556 | 556 | ||
557 | void TEScreen::reset() | 557 | void TEScreen::reset() |
558 | { | 558 | { |
559 | setMode(MODE_Wrap ); saveMode(MODE_Wrap ); // wrap at end of margin | 559 | setMode(MODE_Wrap ); saveMode(MODE_Wrap ); // wrap at end of margin |
560 | resetMode(MODE_Origin); saveMode(MODE_Origin); // position refere to [1,1] | 560 | resetMode(MODE_Origin); saveMode(MODE_Origin); // position refere to [1,1] |
561 | resetMode(MODE_Insert); saveMode(MODE_Insert); // overstroke | 561 | resetMode(MODE_Insert); saveMode(MODE_Insert); // overstroke |
562 | setMode(MODE_Cursor); // cursor visible | 562 | setMode(MODE_Cursor); // cursor visible |
563 | resetMode(MODE_Screen); // screen not inverse | 563 | resetMode(MODE_Screen); // screen not inverse |
564 | resetMode(MODE_NewLine); | 564 | resetMode(MODE_NewLine); |
565 | 565 | ||
566 | tmargin=0; | 566 | tmargin=0; |
567 | bmargin=lines-1; | 567 | bmargin=lines-1; |
568 | 568 | ||
569 | setDefaultRendition(); | 569 | setDefaultRendition(); |
570 | saveCursor(); | 570 | saveCursor(); |
571 | 571 | ||
572 | clear(); | 572 | clear(); |
573 | } | 573 | } |
574 | 574 | ||
575 | /*! Clear the entire screen and home the cursor. | 575 | /*! Clear the entire screen and home the cursor. |
576 | */ | 576 | */ |
577 | 577 | ||
578 | void TEScreen::clear() | 578 | void TEScreen::clear() |
579 | { | 579 | { |
580 | clearEntireScreen(); | 580 | clearEntireScreen(); |
581 | home(); | 581 | home(); |
582 | } | 582 | } |
583 | 583 | ||
584 | /*! Moves the cursor left one column. | 584 | /*! Moves the cursor left one column. |
585 | */ | 585 | */ |
586 | 586 | ||
587 | void TEScreen::BackSpace() | 587 | void TEScreen::BackSpace() |
588 | { | 588 | { |
589 | cuX = QMAX(0,cuX-1); | 589 | cuX = QMAX(0,cuX-1); |
590 | if (BS_CLEARS) image[loc(cuX,cuY)].c = ' '; | 590 | if (BS_CLEARS) image[loc(cuX,cuY)].c = ' '; |
591 | } | 591 | } |
592 | 592 | ||
593 | /*! | 593 | /*! |
594 | */ | 594 | */ |
595 | 595 | ||
596 | void TEScreen::Tabulate() | 596 | void TEScreen::Tabulate() |
597 | { | 597 | { |
598 | // note that TAB is a format effector (does not write ' '); | 598 | // note that TAB is a format effector (does not write ' '); |
599 | cursorRight(1); while(cuX < columns-1 && !tabstops[cuX]) cursorRight(1); | 599 | cursorRight(1); while(cuX < columns-1 && !tabstops[cuX]) cursorRight(1); |
600 | } | 600 | } |
601 | 601 | ||
602 | void TEScreen::clearTabStops() | 602 | void TEScreen::clearTabStops() |
603 | { | 603 | { |
604 | for (int i = 0; i < columns; i++) tabstops[i-1] = FALSE; | 604 | for (int i = 0; i < columns; i++) tabstops[i-1] = FALSE; |
605 | } | 605 | } |
606 | 606 | ||
607 | void TEScreen::changeTabStop(bool set) | 607 | void TEScreen::changeTabStop(bool set) |
608 | { | 608 | { |
609 | if (cuX >= columns) return; | 609 | if (cuX >= columns) return; |
610 | tabstops[cuX] = set; | 610 | tabstops[cuX] = set; |
611 | } | 611 | } |
612 | 612 | ||
613 | void TEScreen::initTabStops() | 613 | void TEScreen::initTabStops() |
614 | { | 614 | { |
615 | if (tabstops) free(tabstops); | 615 | if (tabstops) free(tabstops); |
616 | tabstops = (bool*)malloc(columns*sizeof(bool)); | 616 | tabstops = (bool*)malloc(columns*sizeof(bool)); |
617 | // Arrg! The 1st tabstop has to be one longer than the other. | 617 | // Arrg! The 1st tabstop has to be one longer than the other. |
618 | // i.e. the kids start counting from 0 instead of 1. | 618 | // i.e. the kids start counting from 0 instead of 1. |
619 | // Other programs might behave correctly. Be aware. | 619 | // Other programs might behave correctly. Be aware. |
620 | for (int i = 0; i < columns; i++) tabstops[i] = (i%8 == 0 && i != 0); | 620 | for (int i = 0; i < columns; i++) tabstops[i] = (i%8 == 0 && i != 0); |
621 | } | 621 | } |
622 | 622 | ||
623 | /*! | 623 | /*! |
624 | This behaves either as IND (Screen::Index) or as NEL (Screen::NextLine) | 624 | This behaves either as IND (Screen::Index) or as NEL (Screen::NextLine) |
625 | depending on the NewLine Mode (LNM). This mode also | 625 | depending on the NewLine Mode (LNM). This mode also |
626 | affects the key sequence returned for newline ([CR]LF). | 626 | affects the key sequence returned for newline ([CR]LF). |
627 | */ | 627 | */ |
628 | 628 | ||
629 | void TEScreen::NewLine() | 629 | void TEScreen::NewLine() |
630 | { | 630 | { |
631 | if (getMode(MODE_NewLine)) Return(); | 631 | if (getMode(MODE_NewLine)) Return(); |
632 | index(); | 632 | index(); |
633 | } | 633 | } |
634 | 634 | ||
635 | /*! put `c' literally onto the screen at the current cursor position. | 635 | /*! put `c' literally onto the screen at the current cursor position. |
636 | 636 | ||
637 | VT100 uses the convention to produce an automatic newline (am) | 637 | VT100 uses the convention to produce an automatic newline (am) |
638 | with the *first* character that would fall onto the next line (xenl). | 638 | with the *first* character that would fall onto the next line (xenl). |
639 | */ | 639 | */ |
640 | 640 | ||
641 | void TEScreen::checkSelection(int from, int to) | 641 | void TEScreen::checkSelection(int from, int to) |
642 | { | 642 | { |
643 | if (sel_begin == -1) return; | 643 | if (sel_begin == -1) return; |
644 | int scr_TL = loc(0, hist.getLines()); | 644 | int scr_TL = loc(0, hist.getLines()); |
645 | //Clear entire selection if it overlaps region [from, to] | 645 | //Clear entire selection if it overlaps region [from, to] |
646 | if ( (sel_BR > (from+scr_TL) )&&(sel_TL < (to+scr_TL)) ) | 646 | if ( (sel_BR > (from+scr_TL) )&&(sel_TL < (to+scr_TL)) ) |
647 | { | 647 | { |
648 | clearSelection(); | 648 | clearSelection(); |
649 | } | 649 | } |
650 | } | 650 | } |
651 | 651 | ||
652 | void TEScreen::ShowCharacter(unsigned short c) | 652 | void TEScreen::ShowCharacter(unsigned short c) |
653 | { | 653 | { |
654 | // Note that VT100 does wrapping BEFORE putting the character. | 654 | // Note that VT100 does wrapping BEFORE putting the character. |
655 | // This has impact on the assumption of valid cursor positions. | 655 | // This has impact on the assumption of valid cursor positions. |
656 | // We indicate the fact that a newline has to be triggered by | 656 | // We indicate the fact that a newline has to be triggered by |
657 | // putting the cursor one right to the last column of the screen. | 657 | // putting the cursor one right to the last column of the screen. |
658 | 658 | ||
659 | if (cuX >= columns) | 659 | if (cuX >= columns) |
660 | { | 660 | { |
661 | if (getMode(MODE_Wrap)) NextLine(); else cuX = columns-1; | 661 | if (getMode(MODE_Wrap)) NextLine(); else cuX = columns-1; |
662 | } | 662 | } |
663 | 663 | ||
664 | if (getMode(MODE_Insert)) insertChars(1); | 664 | if (getMode(MODE_Insert)) insertChars(1); |
665 | 665 | ||
666 | int i = loc(cuX,cuY); | 666 | int i = loc(cuX,cuY); |
667 | 667 | ||
668 | checkSelection(i, i); // check if selection is still valid. | 668 | checkSelection(i, i); // check if selection is still valid. |
669 | 669 | ||
670 | image[i].c = c; | 670 | image[i].c = c; |
671 | image[i].f = ef_fg; | 671 | image[i].f = ef_fg; |
672 | image[i].b = ef_bg; | 672 | image[i].b = ef_bg; |
673 | image[i].r = ef_re; | 673 | image[i].r = ef_re; |
674 | 674 | ||
675 | cuX += 1; | 675 | cuX += 1; |
676 | } | 676 | } |
677 | 677 | ||
678 | // Region commands ------------------------------------------------------------- | 678 | // Region commands ------------------------------------------------------------- |
679 | 679 | ||
680 | 680 | ||
681 | /*! scroll up `n' lines within current region. | 681 | /*! scroll up `n' lines within current region. |
682 | The `n' new lines are cleared. | 682 | The `n' new lines are cleared. |
683 | \sa setRegion \sa scrollDown | 683 | \sa setRegion \sa scrollDown |
684 | */ | 684 | */ |
685 | 685 | ||
686 | void TEScreen::scrollUp(int from, int n) | 686 | void TEScreen::scrollUp(int from, int n) |
687 | { | 687 | { |
688 | if (n <= 0 || from + n > bmargin) return; | 688 | if (n <= 0 || from + n > bmargin) return; |
689 | //FIXME: make sure `tmargin', `bmargin', `from', `n' is in bounds. | 689 | //FIXME: make sure `tmargin', `bmargin', `from', `n' is in bounds. |
690 | moveImage(loc(0,from),loc(0,from+n),loc(columns-1,bmargin)); | 690 | moveImage(loc(0,from),loc(0,from+n),loc(columns-1,bmargin)); |
691 | clearImage(loc(0,bmargin-n+1),loc(columns-1,bmargin),' '); | 691 | clearImage(loc(0,bmargin-n+1),loc(columns-1,bmargin),' '); |
692 | } | 692 | } |
693 | 693 | ||
694 | /*! scroll down `n' lines within current region. | 694 | /*! scroll down `n' lines within current region. |
695 | The `n' new lines are cleared. | 695 | The `n' new lines are cleared. |
696 | \sa setRegion \sa scrollUp | 696 | \sa setRegion \sa scrollUp |
697 | */ | 697 | */ |
698 | 698 | ||
699 | void TEScreen::scrollDown(int from, int n) | 699 | void TEScreen::scrollDown(int from, int n) |
700 | { | 700 | { |
701 | //FIXME: make sure `tmargin', `bmargin', `from', `n' is in bounds. | 701 | //FIXME: make sure `tmargin', `bmargin', `from', `n' is in bounds. |
702 | if (n <= 0) return; | 702 | if (n <= 0) return; |
703 | if (from > bmargin) return; | 703 | if (from > bmargin) return; |
704 | if (from + n > bmargin) n = bmargin - from; | 704 | if (from + n > bmargin) n = bmargin - from; |
705 | moveImage(loc(0,from+n),loc(0,from),loc(columns-1,bmargin-n)); | 705 | moveImage(loc(0,from+n),loc(0,from),loc(columns-1,bmargin-n)); |
706 | clearImage(loc(0,from),loc(columns-1,from+n-1),' '); | 706 | clearImage(loc(0,from),loc(columns-1,from+n-1),' '); |
707 | } | 707 | } |
708 | 708 | ||
709 | /*! position the cursor to a specific line and column. */ | 709 | /*! position the cursor to a specific line and column. */ |
710 | void TEScreen::setCursorYX(int y, int x) | 710 | void TEScreen::setCursorYX(int y, int x) |
711 | { | 711 | { |
712 | setCursorY(y); setCursorX(x); | 712 | setCursorY(y); setCursorX(x); |
713 | } | 713 | } |
714 | 714 | ||
715 | /*! Set the cursor to x-th line. */ | 715 | /*! Set the cursor to x-th line. */ |
716 | 716 | ||
717 | void TEScreen::setCursorX(int x) | 717 | void TEScreen::setCursorX(int x) |
718 | { | 718 | { |
719 | if (x == 0) x = 1; // Default | 719 | if (x == 0) x = 1; // Default |
720 | x -= 1; // Adjust | 720 | x -= 1; // Adjust |
721 | cuX = QMAX(0,QMIN(columns-1, x)); | 721 | cuX = QMAX(0,QMIN(columns-1, x)); |
722 | } | 722 | } |
723 | 723 | ||
724 | /*! Set the cursor to y-th line. */ | 724 | /*! Set the cursor to y-th line. */ |
725 | 725 | ||
726 | void TEScreen::setCursorY(int y) | 726 | void TEScreen::setCursorY(int y) |
727 | { | 727 | { |
728 | if (y == 0) y = 1; // Default | 728 | if (y == 0) y = 1; // Default |
729 | y -= 1; // Adjust | 729 | y -= 1; // Adjust |
730 | cuY = QMAX(0,QMIN(lines -1, y + (getMode(MODE_Origin) ? tmargin : 0) )); | 730 | cuY = QMAX(0,QMIN(lines -1, y + (getMode(MODE_Origin) ? tmargin : 0) )); |
731 | } | 731 | } |
732 | 732 | ||
733 | /*! set cursor to the `left upper' corner of the screen (1,1). | 733 | /*! set cursor to the `left upper' corner of the screen (1,1). |
734 | */ | 734 | */ |
735 | 735 | ||
736 | void TEScreen::home() | 736 | void TEScreen::home() |
737 | { | 737 | { |
738 | cuX = 0; | 738 | cuX = 0; |
739 | cuY = 0; | 739 | cuY = 0; |
740 | } | 740 | } |
741 | 741 | ||
742 | /*! set cursor to the begin of the current line. | 742 | /*! set cursor to the begin of the current line. |
743 | */ | 743 | */ |
744 | 744 | ||
745 | void TEScreen::Return() | 745 | void TEScreen::Return() |
746 | { | 746 | { |
747 | cuX = 0; | 747 | cuX = 0; |
748 | } | 748 | } |
749 | 749 | ||
750 | /*! returns the current cursor columns. | 750 | /*! returns the current cursor columns. |
751 | */ | 751 | */ |
752 | 752 | ||
753 | int TEScreen::getCursorX() | 753 | int TEScreen::getCursorX() |
754 | { | 754 | { |
755 | return cuX; | 755 | return cuX; |
756 | } | 756 | } |
757 | 757 | ||
758 | /*! returns the current cursor line. | 758 | /*! returns the current cursor line. |
759 | */ | 759 | */ |
760 | 760 | ||
761 | int TEScreen::getCursorY() | 761 | int TEScreen::getCursorY() |
762 | { | 762 | { |
763 | return cuY; | 763 | return cuY; |
764 | } | 764 | } |
765 | 765 | ||
766 | // Erasing --------------------------------------------------------------------- | 766 | // Erasing --------------------------------------------------------------------- |
767 | 767 | ||
768 | /*! \section Erasing | 768 | /*! \section Erasing |
769 | 769 | ||
770 | This group of operations erase parts of the screen contents by filling | 770 | This group of operations erase parts of the screen contents by filling |
771 | it with spaces colored due to the current rendition settings. | 771 | it with spaces colored due to the current rendition settings. |
772 | 772 | ||
773 | Althought the cursor position is involved in most of these operations, | 773 | Althought the cursor position is involved in most of these operations, |
774 | it is never modified by them. | 774 | it is never modified by them. |
775 | */ | 775 | */ |
776 | 776 | ||
777 | /*! fill screen between (including) `loca' and `loce' with spaces. | 777 | /*! fill screen between (including) `loca' and `loce' with spaces. |
778 | 778 | ||
779 | This is an internal helper functions. The parameter types are internal | 779 | This is an internal helper functions. The parameter types are internal |
780 | addresses of within the screen image and make use of the way how the | 780 | addresses of within the screen image and make use of the way how the |
781 | screen matrix is mapped to the image vector. | 781 | screen matrix is mapped to the image vector. |
782 | */ | 782 | */ |
783 | 783 | ||
784 | void TEScreen::clearImage(int loca, int loce, char c) | 784 | void TEScreen::clearImage(int loca, int loce, char c) |
785 | { int i; | 785 | { int i; |
786 | int scr_TL=loc(0,hist.getLines()); | 786 | int scr_TL=loc(0,hist.getLines()); |
787 | //FIXME: check positions | 787 | //FIXME: check positions |
788 | 788 | ||
789 | //Clear entire selection if it overlaps region to be moved... | 789 | //Clear entire selection if it overlaps region to be moved... |
790 | if ( (sel_BR > (loca+scr_TL) )&&(sel_TL < (loce+scr_TL)) ) | 790 | if ( (sel_BR > (loca+scr_TL) )&&(sel_TL < (loce+scr_TL)) ) |
791 | { | 791 | { |
792 | clearSelection(); | 792 | clearSelection(); |
793 | } | 793 | } |
794 | for (i = loca; i <= loce; i++) | 794 | for (i = loca; i <= loce; i++) |
795 | { | 795 | { |
796 | image[i].c = c; | 796 | image[i].c = c; |
797 | image[i].f = ef_fg; //DEFAULT_FORE_COLOR; //FIXME: xterm and linux/ansi | 797 | image[i].f = ef_fg; //DEFAULT_FORE_COLOR; //FIXME: xterm and linux/ansi |
798 | image[i].b = ef_bg; //DEFAULT_BACK_COLOR; // many have different | 798 | image[i].b = ef_bg; //DEFAULT_BACK_COLOR; // many have different |
799 | image[i].r = ef_re; //DEFAULT_RENDITION; // ideas here. | 799 | image[i].r = ef_re; //DEFAULT_RENDITION; // ideas here. |
800 | } | 800 | } |
801 | } | 801 | } |
802 | 802 | ||
803 | /*! move image between (including) `loca' and `loce' to 'dst'. | 803 | /*! move image between (including) `loca' and `loce' to 'dst'. |
804 | 804 | ||
805 | This is an internal helper functions. The parameter types are internal | 805 | This is an internal helper functions. The parameter types are internal |
806 | addresses of within the screen image and make use of the way how the | 806 | addresses of within the screen image and make use of the way how the |
807 | screen matrix is mapped to the image vector. | 807 | screen matrix is mapped to the image vector. |
808 | */ | 808 | */ |
809 | 809 | ||
810 | void TEScreen::moveImage(int dst, int loca, int loce) | 810 | void TEScreen::moveImage(int dst, int loca, int loce) |
811 | { | 811 | { |
812 | //FIXME: check positions | 812 | //FIXME: check positions |
813 | if (loce < loca) { | 813 | if (loce < loca) { |
814 | // kdDebug() << "WARNING!!! call to TEScreen:moveImage with loce < loca!" << endl; | 814 | // kdDebug() << "WARNING!!! call to TEScreen:moveImage with loce < loca!" << endl; |
815 | return; | 815 | return; |
816 | } | 816 | } |
817 | memmove(&image[dst],&image[loca],(loce-loca+1)*sizeof(ca)); | 817 | memmove(&image[dst],&image[loca],(loce-loca+1)*sizeof(ca)); |
818 | } | 818 | } |
819 | 819 | ||
820 | /*! clear from (including) current cursor position to end of screen. | 820 | /*! clear from (including) current cursor position to end of screen. |
821 | */ | 821 | */ |
822 | 822 | ||
823 | void TEScreen::clearToEndOfScreen() | 823 | void TEScreen::clearToEndOfScreen() |
824 | { | 824 | { |
825 | clearImage(loc(cuX,cuY),loc(columns-1,lines-1),' '); | 825 | clearImage(loc(cuX,cuY),loc(columns-1,lines-1),' '); |
826 | } | 826 | } |
827 | 827 | ||
828 | /*! clear from begin of screen to (including) current cursor position. | 828 | /*! clear from begin of screen to (including) current cursor position. |
829 | */ | 829 | */ |
830 | 830 | ||
831 | void TEScreen::clearToBeginOfScreen() | 831 | void TEScreen::clearToBeginOfScreen() |
832 | { | 832 | { |
833 | clearImage(loc(0,0),loc(cuX,cuY),' '); | 833 | clearImage(loc(0,0),loc(cuX,cuY),' '); |
834 | } | 834 | } |
835 | 835 | ||
836 | /*! clear the entire screen. | 836 | /*! clear the entire screen. |
837 | */ | 837 | */ |
838 | 838 | ||
839 | void TEScreen::clearEntireScreen() | 839 | void TEScreen::clearEntireScreen() |
840 | { | 840 | { |
841 | clearImage(loc(0,0),loc(columns-1,lines-1),' '); | 841 | clearImage(loc(0,0),loc(columns-1,lines-1),' '); |
842 | } | 842 | } |
843 | 843 | ||
844 | /*! fill screen with 'E' | 844 | /*! fill screen with 'E' |
845 | This is to aid screen alignment | 845 | This is to aid screen alignment |
846 | */ | 846 | */ |
847 | 847 | ||
848 | void TEScreen::helpAlign() | 848 | void TEScreen::helpAlign() |
849 | { | 849 | { |
850 | clearImage(loc(0,0),loc(columns-1,lines-1),'E'); | 850 | clearImage(loc(0,0),loc(columns-1,lines-1),'E'); |
851 | } | 851 | } |
852 | 852 | ||
853 | /*! clear from (including) current cursor position to end of current cursor line. | 853 | /*! clear from (including) current cursor position to end of current cursor line. |
854 | */ | 854 | */ |
855 | 855 | ||
856 | void TEScreen::clearToEndOfLine() | 856 | void TEScreen::clearToEndOfLine() |
857 | { | 857 | { |
858 | clearImage(loc(cuX,cuY),loc(columns-1,cuY),' '); | 858 | clearImage(loc(cuX,cuY),loc(columns-1,cuY),' '); |
859 | } | 859 | } |
860 | 860 | ||
861 | /*! clear from begin of current cursor line to (including) current cursor position. | 861 | /*! clear from begin of current cursor line to (including) current cursor position. |
862 | */ | 862 | */ |
863 | 863 | ||
864 | void TEScreen::clearToBeginOfLine() | 864 | void TEScreen::clearToBeginOfLine() |
865 | { | 865 | { |
866 | clearImage(loc(0,cuY),loc(cuX,cuY),' '); | 866 | clearImage(loc(0,cuY),loc(cuX,cuY),' '); |
867 | } | 867 | } |
868 | 868 | ||
869 | /*! clears entire current cursor line | 869 | /*! clears entire current cursor line |
870 | */ | 870 | */ |
871 | 871 | ||
872 | void TEScreen::clearEntireLine() | 872 | void TEScreen::clearEntireLine() |
873 | { | 873 | { |
874 | clearImage(loc(0,cuY),loc(columns-1,cuY),' '); | 874 | clearImage(loc(0,cuY),loc(columns-1,cuY),' '); |
875 | } | 875 | } |
876 | 876 | ||
877 | // Rendition ------------------------------------------------------------------ | 877 | // Rendition ------------------------------------------------------------------ |
878 | 878 | ||
879 | /*! | 879 | /*! |
880 | set rendition mode | 880 | set rendition mode |
881 | */ | 881 | */ |
882 | 882 | ||
883 | void TEScreen::setRendition(int re) | 883 | void TEScreen::setRendition(int re) |
884 | { | 884 | { |
885 | cu_re |= re; | 885 | cu_re |= re; |
886 | effectiveRendition(); | 886 | effectiveRendition(); |
887 | } | 887 | } |
888 | 888 | ||
889 | /*! | 889 | /*! |
890 | reset rendition mode | 890 | reset rendition mode |
891 | */ | 891 | */ |
892 | 892 | ||
893 | void TEScreen::resetRendition(int re) | 893 | void TEScreen::resetRendition(int re) |
894 | { | 894 | { |
895 | cu_re &= ~re; | 895 | cu_re &= ~re; |
896 | effectiveRendition(); | 896 | effectiveRendition(); |
897 | } | 897 | } |
898 | 898 | ||
899 | /*! | 899 | /*! |
900 | */ | 900 | */ |
901 | 901 | ||
902 | void TEScreen::setDefaultRendition() | 902 | void TEScreen::setDefaultRendition() |
903 | { | 903 | { |
904 | setForeColorToDefault(); | 904 | setForeColorToDefault(); |
905 | setBackColorToDefault(); | 905 | setBackColorToDefault(); |
906 | cu_re = DEFAULT_RENDITION; | 906 | cu_re = DEFAULT_RENDITION; |
907 | effectiveRendition(); | 907 | effectiveRendition(); |
908 | } | 908 | } |
909 | 909 | ||
910 | /*! | 910 | /*! |
911 | */ | 911 | */ |
912 | 912 | ||
913 | void TEScreen::setForeColor(int fgcolor) | 913 | void TEScreen::setForeColor(int fgcolor) |
914 | { | 914 | { |
915 | cu_fg = (fgcolor&7)+((fgcolor&8) ? 4+8 : 2); | 915 | cu_fg = (fgcolor&7)+((fgcolor&8) ? 4+8 : 2); |
916 | effectiveRendition(); | 916 | effectiveRendition(); |
917 | } | 917 | } |
918 | 918 | ||
919 | /*! | 919 | /*! |
920 | */ | 920 | */ |
921 | 921 | ||
922 | void TEScreen::setBackColor(int bgcolor) | 922 | void TEScreen::setBackColor(int bgcolor) |
923 | { | 923 | { |
924 | cu_bg = (bgcolor&7)+((bgcolor&8) ? 4+8 : 2); | 924 | cu_bg = (bgcolor&7)+((bgcolor&8) ? 4+8 : 2); |
925 | effectiveRendition(); | 925 | effectiveRendition(); |
926 | } | 926 | } |
927 | 927 | ||
928 | /*! | 928 | /*! |
929 | */ | 929 | */ |
930 | 930 | ||
931 | void TEScreen::setBackColorToDefault() | 931 | void TEScreen::setBackColorToDefault() |
932 | { | 932 | { |
933 | cu_bg = DEFAULT_BACK_COLOR; | 933 | cu_bg = DEFAULT_BACK_COLOR; |
934 | effectiveRendition(); | 934 | effectiveRendition(); |
935 | } | 935 | } |
936 | 936 | ||
937 | /*! | 937 | /*! |
938 | */ | 938 | */ |
939 | 939 | ||
940 | void TEScreen::setForeColorToDefault() | 940 | void TEScreen::setForeColorToDefault() |
941 | { | 941 | { |
942 | cu_fg = DEFAULT_FORE_COLOR; | 942 | cu_fg = DEFAULT_FORE_COLOR; |
943 | effectiveRendition(); | 943 | effectiveRendition(); |
944 | } | 944 | } |
945 | 945 | ||
946 | /* ------------------------------------------------------------------------- */ | 946 | /* ------------------------------------------------------------------------- */ |
947 | /* */ | 947 | /* */ |
948 | /* Marking & Selection */ | 948 | /* Marking & Selection */ |
949 | /* */ | 949 | /* */ |
950 | /* ------------------------------------------------------------------------- */ | 950 | /* ------------------------------------------------------------------------- */ |
951 | 951 | ||
952 | void TEScreen::clearSelection() | 952 | void TEScreen::clearSelection() |
953 | { | 953 | { |
954 | sel_BR = -1; | 954 | sel_BR = -1; |
955 | sel_TL = -1; | 955 | sel_TL = -1; |
956 | sel_begin = -1; | 956 | sel_begin = -1; |
957 | } | 957 | } |
958 | 958 | ||
959 | void TEScreen::setSelBeginXY(const int x, const int y) | 959 | void TEScreen::setSelBeginXY(const int x, const int y) |
960 | { | 960 | { |
961 | sel_begin = loc(x,y+histCursor) ; | 961 | sel_begin = loc(x,y+histCursor) ; |
962 | sel_BR = sel_begin; | 962 | sel_BR = sel_begin; |
963 | sel_TL = sel_begin; | 963 | sel_TL = sel_begin; |
964 | } | 964 | } |
965 | 965 | ||
966 | void TEScreen::setSelExtentXY(const int x, const int y) | 966 | void TEScreen::setSelExtentXY(const int x, const int y) |
967 | { | 967 | { |
968 | if (sel_begin == -1) return; | 968 | if (sel_begin == -1) return; |
969 | int l = loc(x,y + histCursor); | 969 | int l = loc(x,y + histCursor); |
970 | 970 | ||
971 | if (l < sel_begin) | 971 | if (l < sel_begin) |
972 | { | 972 | { |
973 | sel_TL = l; | 973 | sel_TL = l; |
974 | sel_BR = sel_begin; | 974 | sel_BR = sel_begin; |
975 | } | 975 | } |
976 | else | 976 | else |
977 | { | 977 | { |
978 | /* FIXME, HACK to correct for x too far to the right... */ | 978 | /* FIXME, HACK to correct for x too far to the right... */ |
979 | if (( x == columns )|| (x == 0)) l--; | 979 | if (( x == columns )|| (x == 0)) l--; |
980 | 980 | ||
981 | sel_TL = sel_begin; | 981 | sel_TL = sel_begin; |
982 | sel_BR = l; | 982 | sel_BR = l; |
983 | } | 983 | } |
984 | } | 984 | } |
985 | 985 | ||
986 | QString TEScreen::getSelText(const BOOL preserve_line_breaks) | 986 | QString TEScreen::getSelText(const BOOL preserve_line_breaks) |
987 | { | 987 | { |
988 | if (sel_begin == -1) | 988 | if (sel_begin == -1) |
989 | return QString::null; // Selection got clear while selecting. | 989 | return QString::null; // Selection got clear while selecting. |
990 | 990 | ||
991 | int *m; // buffer to fill. | 991 | int *m; // buffer to fill. |
992 | int s, d; // source index, dest. index. | 992 | int s, d; // source index, dest. index. |
993 | int hist_BR = loc(0, hist.getLines()); | 993 | int hist_BR = loc(0, hist.getLines()); |
994 | int hY = sel_TL / columns; | 994 | int hY = sel_TL / columns; |
995 | int hX = sel_TL % columns; | 995 | int hX = sel_TL % columns; |
996 | int eol; // end of line | 996 | int eol; // end of line |
997 | 997 | ||
998 | s = sel_TL; // tracks copy in source. | 998 | s = sel_TL; // tracks copy in source. |
999 | 999 | ||
1000 | // allocate buffer for maximum | 1000 | // allocate buffer for maximum |
1001 | // possible size... | 1001 | // possible size... |
1002 | d = (sel_BR - sel_TL) / columns + 1; | 1002 | d = (sel_BR - sel_TL) / columns + 1; |
1003 | m = new int[d * (columns + 1) + 2]; | 1003 | m = new int[d * (columns + 1) + 2]; |
1004 | d = 0; | 1004 | d = 0; |
1005 | 1005 | ||
1006 | while (s <= sel_BR) | 1006 | while (s <= sel_BR) |
1007 | { | 1007 | { |
1008 | if (s < hist_BR) | 1008 | if (s < hist_BR) |
1009 | { // get lines from hist.history | 1009 | { // get lines from hist.history |
1010 | // buffer. | 1010 | // buffer. |
1011 | eol = hist.getLineLen(hY); | 1011 | eol = hist.getLineLen(hY); |
1012 | 1012 | ||
1013 | if ((hY == (sel_BR / columns)) && | 1013 | if ((hY == (sel_BR / columns)) && |
1014 | (eol >= (sel_BR % columns))) | 1014 | (eol >= (sel_BR % columns))) |
1015 | { | 1015 | { |
1016 | eol = sel_BR % columns + 1; | 1016 | eol = sel_BR % columns + 1; |
1017 | } | 1017 | } |
1018 | 1018 | ||
1019 | while (hX < eol) | 1019 | while (hX < eol) |
1020 | { | 1020 | { |
1021 | m[d++] = hist.getCell(hY, hX++).c; | 1021 | m[d++] = hist.getCell(hY, hX++).c; |
1022 | s++; | 1022 | s++; |
1023 | } | 1023 | } |
1024 | 1024 | ||
1025 | if (s <= sel_BR) | 1025 | if (s <= sel_BR) |
1026 | { | 1026 | { |
1027 | // The line break handling | 1027 | // The line break handling |
1028 | // It's different from the screen | 1028 | // It's different from the screen |
1029 | // image case! | 1029 | // image case! |
1030 | if (eol % columns == 0) | 1030 | if (eol % columns == 0) |
1031 | { | 1031 | { |
1032 | // That's either a completely filled | 1032 | // That's either a completely filled |
1033 | // line or an empty line | 1033 | // line or an empty line |
1034 | if (eol == 0) | 1034 | if (eol == 0) |
1035 | { | 1035 | { |
1036 | m[d++] = '\n'; | 1036 | m[d++] = '\n'; |
1037 | } | 1037 | } |
1038 | else | 1038 | else |
1039 | { | 1039 | { |
1040 | // We have a full line. | 1040 | // We have a full line. |
1041 | // FIXME: How can we handle newlines | 1041 | // FIXME: How can we handle newlines |
1042 | // at this position?! | 1042 | // at this position?! |
1043 | } | 1043 | } |
1044 | } | 1044 | } |
1045 | else if ((eol + 1) % columns == 0) | 1045 | else if ((eol + 1) % columns == 0) |
1046 | { | 1046 | { |
1047 | // FIXME: We don't know if this was a | 1047 | // FIXME: We don't know if this was a |
1048 | // space at the last position or a | 1048 | // space at the last position or a |
1049 | // short line!! | 1049 | // short line!! |
1050 | m[d++] = ' '; | 1050 | m[d++] = ' '; |
1051 | } | 1051 | } |
1052 | else | 1052 | else |
1053 | { | 1053 | { |
1054 | // We have a short line here. Put a | 1054 | // We have a short line here. Put a |
1055 | // newline or a space into the | 1055 | // newline or a space into the |
1056 | // buffer. | 1056 | // buffer. |
1057 | m[d++] = preserve_line_breaks ? '\n' : ' '; | 1057 | m[d++] = preserve_line_breaks ? '\n' : ' '; |
1058 | } | 1058 | } |
1059 | } | 1059 | } |
1060 | 1060 | ||
1061 | hY++; | 1061 | hY++; |
1062 | hX = 0; | 1062 | hX = 0; |
1063 | s = hY * columns; | 1063 | s = hY * columns; |
1064 | } | 1064 | } |
1065 | else | 1065 | else |
1066 | { // or from screen image. | 1066 | { // or from screen image. |
1067 | eol = (s / columns + 1) * columns - 1; | 1067 | eol = (s / columns + 1) * columns - 1; |
1068 | 1068 | ||
1069 | if (eol < sel_BR) | 1069 | if (eol < sel_BR) |
1070 | { | 1070 | { |
1071 | while ((eol > s) && | 1071 | while ((eol > s) && |
1072 | isspace(image[eol - hist_BR].c)) | 1072 | isspace(image[eol - hist_BR].c)) |
1073 | { | 1073 | { |
1074 | eol--; | 1074 | eol--; |
1075 | } | 1075 | } |
1076 | } | 1076 | } |
1077 | else | 1077 | else |
1078 | { | 1078 | { |
1079 | eol = sel_BR; | 1079 | eol = sel_BR; |
1080 | } | 1080 | } |
1081 | 1081 | ||
1082 | while (s <= eol) | 1082 | while (s <= eol) |
1083 | { | 1083 | { |
1084 | m[d++] = image[s++ - hist_BR].c; | 1084 | m[d++] = image[s++ - hist_BR].c; |
1085 | } | 1085 | } |
1086 | 1086 | ||
1087 | if (eol < sel_BR) | 1087 | if (eol < sel_BR) |
1088 | { | 1088 | { |
1089 | // eol processing see below ... | 1089 | // eol processing see below ... |
1090 | if ((eol + 1) % columns == 0) | 1090 | if ((eol + 1) % columns == 0) |
1091 | { | 1091 | { |
1092 | if (image[eol - hist_BR].c == ' ') | 1092 | if (image[eol - hist_BR].c == ' ') |
1093 | { | 1093 | { |
1094 | m[d++] = ' '; | 1094 | m[d++] = ' '; |
1095 | } | 1095 | } |
1096 | } | 1096 | } |
1097 | else | 1097 | else |
1098 | { | 1098 | { |
1099 | m[d++] = ((preserve_line_breaks || | 1099 | m[d++] = ((preserve_line_breaks || |
1100 | ((eol % columns) == 0)) ? | 1100 | ((eol % columns) == 0)) ? |
1101 | '\n' : ' '); | 1101 | '\n' : ' '); |
1102 | } | 1102 | } |
1103 | } | 1103 | } |
1104 | 1104 | ||
1105 | s = (eol / columns + 1) * columns; | 1105 | s = (eol / columns + 1) * columns; |
1106 | } | 1106 | } |
1107 | } | 1107 | } |
1108 | 1108 | ||
1109 | QChar* qc = new QChar[d]; | 1109 | QChar* qc = new QChar[d]; |
1110 | 1110 | ||
1111 | for (int i = 0; i < d; i++) | 1111 | for (int i = 0; i < d; i++) |
1112 | { | 1112 | { |
1113 | qc[i] = m[i]; | 1113 | qc[i] = m[i]; |
1114 | } | 1114 | } |
1115 | 1115 | ||
1116 | QString res(qc, d); | 1116 | QString res(qc, d); |
1117 | 1117 | ||
1118 | delete m; | 1118 | delete [] m; |
1119 | delete qc; | 1119 | delete [] qc; |
1120 | 1120 | ||
1121 | return res; | 1121 | return res; |
1122 | } | 1122 | } |
1123 | QString TEScreen::getHistory() { | 1123 | QString TEScreen::getHistory() { |
1124 | sel_begin = 0; | 1124 | sel_begin = 0; |
1125 | sel_BR = sel_begin; | 1125 | sel_BR = sel_begin; |
1126 | sel_TL = sel_begin; | 1126 | sel_TL = sel_begin; |
1127 | setSelExtentXY(columns-1,lines-1); | 1127 | setSelExtentXY(columns-1,lines-1); |
1128 | QString tmp=getSelText(true); | 1128 | QString tmp=getSelText(true); |
1129 | while (tmp.at(tmp.length()-2).unicode()==10 && tmp.at(tmp.length()-1).unicode()==10) | 1129 | while (tmp.at(tmp.length()-2).unicode()==10 && tmp.at(tmp.length()-1).unicode()==10) |
1130 | tmp.truncate(tmp.length()-1); | 1130 | tmp.truncate(tmp.length()-1); |
1131 | 1131 | ||
1132 | return tmp; | 1132 | return tmp; |
1133 | } | 1133 | } |
1134 | /* above ... end of line processing for selection -- psilva | 1134 | /* above ... end of line processing for selection -- psilva |
1135 | cases: | 1135 | cases: |
1136 | 1136 | ||
1137 | 1) (eol+1)%columns == 0 --> the whole line is filled. | 1137 | 1) (eol+1)%columns == 0 --> the whole line is filled. |
1138 | If the last char is a space, insert (preserve) space. otherwise | 1138 | If the last char is a space, insert (preserve) space. otherwise |
1139 | leave the text alone, so that words that are broken by linewrap | 1139 | leave the text alone, so that words that are broken by linewrap |
1140 | are preserved. | 1140 | are preserved. |
1141 | 1141 | ||
1142 | FIXME: | 1142 | FIXME: |
1143 | * this suppresses \n for command output that is | 1143 | * this suppresses \n for command output that is |
1144 | sized to the exact column width of the screen. | 1144 | sized to the exact column width of the screen. |
1145 | 1145 | ||
1146 | 2) eol%columns == 0 --> blank line. | 1146 | 2) eol%columns == 0 --> blank line. |
1147 | insert a \n unconditionally. | 1147 | insert a \n unconditionally. |
1148 | Do it either you would because you are in preserve_line_break mode, | 1148 | Do it either you would because you are in preserve_line_break mode, |
1149 | or because it's an ASCII paragraph delimiter, so even when | 1149 | or because it's an ASCII paragraph delimiter, so even when |
1150 | not preserving line_breaks, you want to preserve paragraph breaks. | 1150 | not preserving line_breaks, you want to preserve paragraph breaks. |
1151 | 1151 | ||
1152 | 3) else --> partially filled line | 1152 | 3) else --> partially filled line |
1153 | insert a \n in preserve line break mode, else a space | 1153 | insert a \n in preserve line break mode, else a space |
1154 | The space prevents concatenation of the last word of one | 1154 | The space prevents concatenation of the last word of one |
1155 | line with the first of the next. | 1155 | line with the first of the next. |
1156 | 1156 | ||
1157 | */ | 1157 | */ |
1158 | 1158 | ||
1159 | void TEScreen::addHistLine() | 1159 | void TEScreen::addHistLine() |
1160 | { | 1160 | { |
1161 | assert(hasScroll() || histCursor == 0); | 1161 | assert(hasScroll() || histCursor == 0); |
1162 | 1162 | ||
1163 | // add to hist buffer | 1163 | // add to hist buffer |
1164 | // we have to take care about scrolling, too... | 1164 | // we have to take care about scrolling, too... |
1165 | 1165 | ||
1166 | if (hasScroll()) | 1166 | if (hasScroll()) |
1167 | { ca dft; | 1167 | { ca dft; |
1168 | 1168 | ||
1169 | int end = columns-1; | 1169 | int end = columns-1; |
1170 | while (end >= 0 && image[end] == dft) | 1170 | while (end >= 0 && image[end] == dft) |
1171 | end -= 1; | 1171 | end -= 1; |
1172 | 1172 | ||
1173 | hist.addCells(image,end+1); | 1173 | hist.addCells(image,end+1); |
1174 | hist.addLine(); | 1174 | hist.addLine(); |
1175 | 1175 | ||
1176 | // adjust history cursor | 1176 | // adjust history cursor |
1177 | histCursor += (hist.getLines()-1 == histCursor); | 1177 | histCursor += (hist.getLines()-1 == histCursor); |
1178 | } | 1178 | } |
1179 | 1179 | ||
1180 | if (!hasScroll()) histCursor = 0; //FIXME: a poor workaround | 1180 | if (!hasScroll()) histCursor = 0; //FIXME: a poor workaround |
1181 | } | 1181 | } |
1182 | 1182 | ||
1183 | void TEScreen::setHistCursor(int cursor) | 1183 | void TEScreen::setHistCursor(int cursor) |
1184 | { | 1184 | { |
1185 | histCursor = cursor; //FIXME:rangecheck | 1185 | histCursor = cursor; //FIXME:rangecheck |
1186 | } | 1186 | } |
1187 | 1187 | ||
1188 | int TEScreen::getHistCursor() | 1188 | int TEScreen::getHistCursor() |
1189 | { | 1189 | { |
1190 | return histCursor; | 1190 | return histCursor; |
1191 | } | 1191 | } |
1192 | 1192 | ||
1193 | int TEScreen::getHistLines() | 1193 | int TEScreen::getHistLines() |
1194 | { | 1194 | { |
1195 | return hist.getLines(); | 1195 | return hist.getLines(); |
1196 | } | 1196 | } |
1197 | 1197 | ||
1198 | void TEScreen::setScroll(bool on) | 1198 | void TEScreen::setScroll(bool on) |
1199 | { | 1199 | { |
1200 | histCursor = 0; | 1200 | histCursor = 0; |
1201 | clearSelection(); | 1201 | clearSelection(); |
1202 | hist.setScroll(on); | 1202 | hist.setScroll(on); |
1203 | } | 1203 | } |
1204 | 1204 | ||
1205 | bool TEScreen::hasScroll() | 1205 | bool TEScreen::hasScroll() |
1206 | { | 1206 | { |
1207 | return hist.hasScroll(); | 1207 | return hist.hasScroll(); |
1208 | } | 1208 | } |
diff --git a/noncore/apps/opie-sheet/Excel.cpp b/noncore/apps/opie-sheet/Excel.cpp index 338bc30..51fe707 100644 --- a/noncore/apps/opie-sheet/Excel.cpp +++ b/noncore/apps/opie-sheet/Excel.cpp | |||
@@ -1,1709 +1,1709 @@ | |||
1 | /* | 1 | /* |
2 | =. This file is part of the Opie Project | 2 | =. This file is part of the Opie Project |
3 | .=l. Copyright (C) 2004 Opie Developer Team <opie-devel@handhelds.org> | 3 | .=l. Copyright (C) 2004 Opie Developer Team <opie-devel@handhelds.org> |
4 | .>+-= | 4 | .>+-= |
5 | _;:, .> :=|. This program is free software; you can | 5 | _;:, .> :=|. This program is free software; you can |
6 | .> <`_, > . <= redistribute it and/or modify it under | 6 | .> <`_, > . <= redistribute it and/or modify it under |
7 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 7 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
8 | .="- .-=="i, .._ License as published by the Free Software | 8 | .="- .-=="i, .._ License as published by the Free Software |
9 | - . .-<_> .<> Foundation; either version 2 of the License, | 9 | - . .-<_> .<> Foundation; either version 2 of the License, |
10 | ._= =} : or (at your option) any later version. | 10 | ._= =} : or (at your option) any later version. |
11 | .%`+i> _;_. | 11 | .%`+i> _;_. |
12 | .i_,=:_. -<s. This program is distributed in the hope that | 12 | .i_,=:_. -<s. This program is distributed in the hope that |
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
14 | : .. .:, . . . without even the implied warranty of | 14 | : .. .:, . . . without even the implied warranty of |
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
17 | ..}^=.= = ; Library General Public License for more | 17 | ..}^=.= = ; Library General Public License for more |
18 | ++= -. .` .: details. | 18 | ++= -. .` .: details. |
19 | : = ...= . :.=- | 19 | : = ...= . :.=- |
20 | -. .:....=;==+<; You should have received a copy of the GNU | 20 | -. .:....=;==+<; You should have received a copy of the GNU |
21 | -_. . . )=. = Library General Public License along with | 21 | -_. . . )=. = Library General Public License along with |
22 | -- :-=` this library; see the file COPYING.LIB. | 22 | -- :-=` this library; see the file COPYING.LIB. |
23 | If not, write to the Free Software Foundation, | 23 | If not, write to the Free Software Foundation, |
24 | Inc., 59 Temple Place - Suite 330, | 24 | Inc., 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include "Excel.h" | 29 | #include "Excel.h" |
30 | 30 | ||
31 | /* STD */ | 31 | /* STD */ |
32 | #include <stdio.h> | 32 | #include <stdio.h> |
33 | #include <stdlib.h> | 33 | #include <stdlib.h> |
34 | #include <math.h> | 34 | #include <math.h> |
35 | #include <time.h> | 35 | #include <time.h> |
36 | #include <sys/types.h> | 36 | #include <sys/types.h> |
37 | #include <strings.h> | 37 | #include <strings.h> |
38 | 38 | ||
39 | static xfrecord formatter[] = { | 39 | static xfrecord formatter[] = { |
40 | { 0xe , DATEFORMAT, "%m/%d/%y"}, | 40 | { 0xe , DATEFORMAT, "%m/%d/%y"}, |
41 | { 0xf , DATEFORMAT, "%d-%b-%y"}, | 41 | { 0xf , DATEFORMAT, "%d-%b-%y"}, |
42 | { 0x10, DATEFORMAT, "%d-%b"}, | 42 | { 0x10, DATEFORMAT, "%d-%b"}, |
43 | { 0x11, DATEFORMAT, "%b-%y"}, | 43 | { 0x11, DATEFORMAT, "%b-%y"}, |
44 | { 0x12, DATEFORMAT, "%I:%M %p"}, | 44 | { 0x12, DATEFORMAT, "%I:%M %p"}, |
45 | { 0x13, DATEFORMAT, "%I:%M:%S %p"}, | 45 | { 0x13, DATEFORMAT, "%I:%M:%S %p"}, |
46 | { 0x14, DATEFORMAT, "%H:%M"}, | 46 | { 0x14, DATEFORMAT, "%H:%M"}, |
47 | { 0x15, DATEFORMAT, "%H:%M:%S"}, | 47 | { 0x15, DATEFORMAT, "%H:%M:%S"}, |
48 | { 0x16, DATEFORMAT, "%m/%d/%y %H:%M"}, | 48 | { 0x16, DATEFORMAT, "%m/%d/%y %H:%M"}, |
49 | { 0x2d, DATEFORMAT, "%M:%S"}, | 49 | { 0x2d, DATEFORMAT, "%M:%S"}, |
50 | { 0x2e, DATEFORMAT, "%H:%M:%S"}, | 50 | { 0x2e, DATEFORMAT, "%H:%M:%S"}, |
51 | { 0x2f, DATEFORMAT, "%M:%S"}, | 51 | { 0x2f, DATEFORMAT, "%M:%S"}, |
52 | { 0xa5, DATEFORMAT, "%m/%d/%y %I:%M %p"}, | 52 | { 0xa5, DATEFORMAT, "%m/%d/%y %I:%M %p"}, |
53 | { 0x1 , NUMBERFORMAT, "%.0f"}, | 53 | { 0x1 , NUMBERFORMAT, "%.0f"}, |
54 | { 0x2 , NUMBERFORMAT, "%.2f"}, | 54 | { 0x2 , NUMBERFORMAT, "%.2f"}, |
55 | { 0x3 , NUMBERFORMAT, "#,##%.0f"}, | 55 | { 0x3 , NUMBERFORMAT, "#,##%.0f"}, |
56 | { 0x4 , NUMBERFORMAT, "#,##%.2f"}, | 56 | { 0x4 , NUMBERFORMAT, "#,##%.2f"}, |
57 | { 0x5 , NUMBERFORMAT, "$#,##%.0f"}, | 57 | { 0x5 , NUMBERFORMAT, "$#,##%.0f"}, |
58 | { 0x6 , NUMBERFORMAT, "$#,##%.0f"}, | 58 | { 0x6 , NUMBERFORMAT, "$#,##%.0f"}, |
59 | { 0x7 , NUMBERFORMAT, "$#,##%.2f"}, | 59 | { 0x7 , NUMBERFORMAT, "$#,##%.2f"}, |
60 | { 0x8 , NUMBERFORMAT, "$#,##%.2f"}, | 60 | { 0x8 , NUMBERFORMAT, "$#,##%.2f"}, |
61 | { 0x9 , NUMBERFORMAT, "%.0f%%"}, | 61 | { 0x9 , NUMBERFORMAT, "%.0f%%"}, |
62 | { 0xa , NUMBERFORMAT, "%.2f%%"}, | 62 | { 0xa , NUMBERFORMAT, "%.2f%%"}, |
63 | { 0xb , NUMBERFORMAT, "%e"}, | 63 | { 0xb , NUMBERFORMAT, "%e"}, |
64 | { 0x25, NUMBERFORMAT, "#,##%.0f;(#,##0)"}, | 64 | { 0x25, NUMBERFORMAT, "#,##%.0f;(#,##0)"}, |
65 | { 0x26, NUMBERFORMAT, "#,##%.0f;(#,##0)"}, | 65 | { 0x26, NUMBERFORMAT, "#,##%.0f;(#,##0)"}, |
66 | { 0x27, NUMBERFORMAT, "#,##%.2f;(#,##0.00)"}, | 66 | { 0x27, NUMBERFORMAT, "#,##%.2f;(#,##0.00)"}, |
67 | { 0x28, NUMBERFORMAT, "#,##%.2f;(#,##0.00)"}, | 67 | { 0x28, NUMBERFORMAT, "#,##%.2f;(#,##0.00)"}, |
68 | { 0x29, NUMBERFORMAT, "#,##%.0f;(#,##0)"}, | 68 | { 0x29, NUMBERFORMAT, "#,##%.0f;(#,##0)"}, |
69 | { 0x2a, NUMBERFORMAT, "$#,##%.0f;($#,##0)"}, | 69 | { 0x2a, NUMBERFORMAT, "$#,##%.0f;($#,##0)"}, |
70 | { 0x2b, NUMBERFORMAT, "#,##%.2f;(#,##0.00)"}, | 70 | { 0x2b, NUMBERFORMAT, "#,##%.2f;(#,##0.00)"}, |
71 | { 0x2c, NUMBERFORMAT, "$#,##%.2f;($#,##0.00)"}, | 71 | { 0x2c, NUMBERFORMAT, "$#,##%.2f;($#,##0.00)"}, |
72 | { 0x30, NUMBERFORMAT, "##0.0E0"}, | 72 | { 0x30, NUMBERFORMAT, "##0.0E0"}, |
73 | { 0, 0, ""} | 73 | { 0, 0, ""} |
74 | }; | 74 | }; |
75 | 75 | ||
76 | 76 | ||
77 | 77 | ||
78 | int ExcelBook::Integer2Byte(int b1, int b2) | 78 | int ExcelBook::Integer2Byte(int b1, int b2) |
79 | { | 79 | { |
80 | int i1 = b1 & 0xff; | 80 | int i1 = b1 & 0xff; |
81 | int i2 = b2 & 0xff; | 81 | int i2 = b2 & 0xff; |
82 | int val = i2 << 8 | i1; | 82 | int val = i2 << 8 | i1; |
83 | return val; | 83 | return val; |
84 | }; | 84 | }; |
85 | 85 | ||
86 | int ExcelBook::Integer4Byte(int b1,int b2,int b3,int b4) | 86 | int ExcelBook::Integer4Byte(int b1,int b2,int b3,int b4) |
87 | { | 87 | { |
88 | int i1 = Integer2Byte(b1, b2); | 88 | int i1 = Integer2Byte(b1, b2); |
89 | int i2 = Integer2Byte(b3, b4); | 89 | int i2 = Integer2Byte(b3, b4); |
90 | int val = i2 << 16 | i1; | 90 | int val = i2 << 16 | i1; |
91 | return val; | 91 | return val; |
92 | }; | 92 | }; |
93 | 93 | ||
94 | int ExcelBook::Integer2ByteFile(FILE *f) | 94 | int ExcelBook::Integer2ByteFile(FILE *f) |
95 | { | 95 | { |
96 | int i1, i2; | 96 | int i1, i2; |
97 | i1 = fgetc(f); | 97 | i1 = fgetc(f); |
98 | i2 = fgetc(f); | 98 | i2 = fgetc(f); |
99 | return Integer2Byte(i1,i2); | 99 | return Integer2Byte(i1,i2); |
100 | }; | 100 | }; |
101 | 101 | ||
102 | float ExcelBook::Float4Byte(int b1, int b2, int b3, int b4) | 102 | float ExcelBook::Float4Byte(int b1, int b2, int b3, int b4) |
103 | { | 103 | { |
104 | int i; | 104 | int i; |
105 | float f; | 105 | float f; |
106 | unsigned char *ieee; | 106 | unsigned char *ieee; |
107 | ieee = (unsigned char *) &f; | 107 | ieee = (unsigned char *) &f; |
108 | for (i = 0; i < 4; i++) ieee[i] = 0; | 108 | for (i = 0; i < 4; i++) ieee[i] = 0; |
109 | ieee[0] = ((int)b4) & 0xff; | 109 | ieee[0] = ((int)b4) & 0xff; |
110 | ieee[1] = ((int)b3) & 0xff; | 110 | ieee[1] = ((int)b3) & 0xff; |
111 | ieee[2] = ((int)b2) & 0xff; | 111 | ieee[2] = ((int)b2) & 0xff; |
112 | ieee[3] = ((int)b1) & 0xff; | 112 | ieee[3] = ((int)b1) & 0xff; |
113 | return f; | 113 | return f; |
114 | }; | 114 | }; |
115 | 115 | ||
116 | double ExcelBook::Double4Byte(int b1, int b2, int b3, int b4) | 116 | double ExcelBook::Double4Byte(int b1, int b2, int b3, int b4) |
117 | { | 117 | { |
118 | long int rk; | 118 | long int rk; |
119 | double value; | 119 | double value; |
120 | 120 | ||
121 | rk=Integer4Byte(b1,b2,b3,b4); | 121 | rk=Integer4Byte(b1,b2,b3,b4); |
122 | //printf("Double4Bytes:%d,%d,%d,%d\r\n",b1,b2,b3,b4); | 122 | //printf("Double4Bytes:%d,%d,%d,%d\r\n",b1,b2,b3,b4); |
123 | if ( (rk & 0x02) != 0) | 123 | if ( (rk & 0x02) != 0) |
124 | { | 124 | { |
125 | long int intval = rk >> 2; //drops the 2 bits | 125 | long int intval = rk >> 2; //drops the 2 bits |
126 | printf("Double4Byte:intval=%d, rk=%d, rk>>2=%d\r\n",intval,rk,rk>>2); | 126 | printf("Double4Byte:intval=%d, rk=%d, rk>>2=%d\r\n",intval,rk,rk>>2); |
127 | value = (double) intval; | 127 | value = (double) intval; |
128 | printf("Double4Byte: VALUEINT=%f\r\n",value); | 128 | printf("Double4Byte: VALUEINT=%f\r\n",value); |
129 | if ( (rk & 0x01) != 0) | 129 | if ( (rk & 0x01) != 0) |
130 | { | 130 | { |
131 | value /= 100.0; | 131 | value /= 100.0; |
132 | }; | 132 | }; |
133 | return value; | 133 | return value; |
134 | } | 134 | } |
135 | else | 135 | else |
136 | { | 136 | { |
137 | 137 | ||
138 | union { double d; unsigned long int b[2]; } dbl_byte; | 138 | union { double d; unsigned long int b[2]; } dbl_byte; |
139 | unsigned long int valbits = (rk & 0xfffffffc); | 139 | unsigned long int valbits = (rk & 0xfffffffc); |
140 | #if defined(__arm__) && !defined(__vfp__) | 140 | #if defined(__arm__) && !defined(__vfp__) |
141 | dbl_byte.b[0]=valbits; | 141 | dbl_byte.b[0]=valbits; |
142 | dbl_byte.b[1]=0; | 142 | dbl_byte.b[1]=0; |
143 | #else | 143 | #else |
144 | dbl_byte.b[0]=0; | 144 | dbl_byte.b[0]=0; |
145 | dbl_byte.b[1]=valbits; | 145 | dbl_byte.b[1]=valbits; |
146 | #endif | 146 | #endif |
147 | printf("dbl_byte.b[0]=%d,dbl_byte.b[1]=%d\r\n",dbl_byte.b[0],dbl_byte.b[1]); | 147 | printf("dbl_byte.b[0]=%d,dbl_byte.b[1]=%d\r\n",dbl_byte.b[0],dbl_byte.b[1]); |
148 | value=dbl_byte.d; | 148 | value=dbl_byte.d; |
149 | printf("Double4Byte: VALUE=%f\r\n",value); | 149 | printf("Double4Byte: VALUE=%f\r\n",value); |
150 | 150 | ||
151 | if ( (rk & 0x01) != 0) | 151 | if ( (rk & 0x01) != 0) |
152 | { | 152 | { |
153 | value /= 100.0; | 153 | value /= 100.0; |
154 | }; | 154 | }; |
155 | return value; | 155 | return value; |
156 | }; | 156 | }; |
157 | }; | 157 | }; |
158 | 158 | ||
159 | void ExcelBook::DetectEndian(void) | 159 | void ExcelBook::DetectEndian(void) |
160 | { | 160 | { |
161 | int end; | 161 | int end; |
162 | long i = 0x44332211; | 162 | long i = 0x44332211; |
163 | unsigned char* a = (unsigned char*) &i; | 163 | unsigned char* a = (unsigned char*) &i; |
164 | end = (*a != 0x11); | 164 | end = (*a != 0x11); |
165 | if (end == 1) | 165 | if (end == 1) |
166 | { | 166 | { |
167 | endian = BIG_ENDIAN; | 167 | endian = BIG_ENDIAN; |
168 | printf("BIGENDIAN!\r\n"); | 168 | printf("BIGENDIAN!\r\n"); |
169 | } | 169 | } |
170 | else | 170 | else |
171 | { | 171 | { |
172 | endian = LITTLE_ENDIAN; | 172 | endian = LITTLE_ENDIAN; |
173 | printf("LITTLEENDIAN!\r\n"); | 173 | printf("LITTLEENDIAN!\r\n"); |
174 | } | 174 | } |
175 | }; | 175 | }; |
176 | 176 | ||
177 | double ExcelBook::Double8Byte(int b1, int b2, int b3, int b4, int b5, int b6, int b7, int b8) | 177 | double ExcelBook::Double8Byte(int b1, int b2, int b3, int b4, int b5, int b6, int b7, int b8) |
178 | { | 178 | { |
179 | int i; | 179 | int i; |
180 | double d; | 180 | double d; |
181 | unsigned char *ieee; | 181 | unsigned char *ieee; |
182 | ieee = (unsigned char *)&d; | 182 | ieee = (unsigned char *)&d; |
183 | for (i = 0; i < 8; i++) ieee[i] = 0; | 183 | for (i = 0; i < 8; i++) ieee[i] = 0; |
184 | if (endian == BIG_ENDIAN) | 184 | if (endian == BIG_ENDIAN) |
185 | { | 185 | { |
186 | ieee[0] = ((int)b8) & 0xff;ieee[1] = ((int)b7) & 0xff; | 186 | ieee[0] = ((int)b8) & 0xff;ieee[1] = ((int)b7) & 0xff; |
187 | ieee[2] = ((int)b6) & 0xff;ieee[3] = ((int)b5) & 0xff; | 187 | ieee[2] = ((int)b6) & 0xff;ieee[3] = ((int)b5) & 0xff; |
188 | ieee[4] = ((int)b4) & 0xff;ieee[5] = ((int)b3) & 0xff; | 188 | ieee[4] = ((int)b4) & 0xff;ieee[5] = ((int)b3) & 0xff; |
189 | ieee[6] = ((int)b2) & 0xff;ieee[7] = ((int)b1) & 0xff; | 189 | ieee[6] = ((int)b2) & 0xff;ieee[7] = ((int)b1) & 0xff; |
190 | } | 190 | } |
191 | else | 191 | else |
192 | { | 192 | { |
193 | ieee[0] = ((int)b1) & 0xff;ieee[1] = ((int)b2) & 0xff; | 193 | ieee[0] = ((int)b1) & 0xff;ieee[1] = ((int)b2) & 0xff; |
194 | ieee[2] = ((int)b3) & 0xff;ieee[3] = ((int)b4) & 0xff; | 194 | ieee[2] = ((int)b3) & 0xff;ieee[3] = ((int)b4) & 0xff; |
195 | ieee[4] = ((int)b5) & 0xff;ieee[5] = ((int)b6) & 0xff; | 195 | ieee[4] = ((int)b5) & 0xff;ieee[5] = ((int)b6) & 0xff; |
196 | ieee[6] = ((int)b7) & 0xff;ieee[7] = ((int)b8) & 0xff; | 196 | ieee[6] = ((int)b7) & 0xff;ieee[7] = ((int)b8) & 0xff; |
197 | } | 197 | } |
198 | return d; | 198 | return d; |
199 | }; | 199 | }; |
200 | 200 | ||
201 | bool ExcelBook::OpenFile(char *Filename) | 201 | bool ExcelBook::OpenFile(char *Filename) |
202 | { | 202 | { |
203 | printf("Opening excel file!\r\n"); | 203 | printf("Opening excel file!\r\n"); |
204 | File= fopen(Filename, "r"); | 204 | File= fopen(Filename, "r"); |
205 | Position=0; // first byte index in file | 205 | Position=0; // first byte index in file |
206 | XFRecords.resize(0); | 206 | XFRecords.resize(0); |
207 | SharedStrings.resize(0); | 207 | SharedStrings.resize(0); |
208 | Names.resize(0); | 208 | Names.resize(0); |
209 | Sheets.resize(0); | 209 | Sheets.resize(0); |
210 | if(File==NULL) return false; | 210 | if(File==NULL) return false; |
211 | printf("Opened excel file!\r\n"); | 211 | printf("Opened excel file!\r\n"); |
212 | return true; | 212 | return true; |
213 | }; | 213 | }; |
214 | 214 | ||
215 | bool ExcelBook::CloseFile(void) | 215 | bool ExcelBook::CloseFile(void) |
216 | { | 216 | { |
217 | int w1; | 217 | int w1; |
218 | for(w1=0;w1<(int)XFRecords.count();w1++) | 218 | for(w1=0;w1<(int)XFRecords.count();w1++) |
219 | { | 219 | { |
220 | if(XFRecords[w1]!=NULL) {delete XFRecords[w1];XFRecords[w1]=NULL;}; | 220 | if(XFRecords[w1]!=NULL) {delete XFRecords[w1];XFRecords[w1]=NULL;}; |
221 | }; | 221 | }; |
222 | for(w1=0;w1<(int)SharedStrings.count();w1++) | 222 | for(w1=0;w1<(int)SharedStrings.count();w1++) |
223 | { | 223 | { |
224 | if(SharedStrings[w1]!=NULL) {delete SharedStrings[w1];SharedStrings[w1]=NULL;}; | 224 | if(SharedStrings[w1]!=NULL) {delete SharedStrings[w1];SharedStrings[w1]=NULL;}; |
225 | }; | 225 | }; |
226 | for(w1=0;w1<(int)Names.count();w1++) | 226 | for(w1=0;w1<(int)Names.count();w1++) |
227 | { | 227 | { |
228 | if(Names[w1]!=NULL) {delete Names[w1];Names[w1]=NULL;}; | 228 | if(Names[w1]!=NULL) {delete Names[w1];Names[w1]=NULL;}; |
229 | }; | 229 | }; |
230 | for(w1=0;w1<(int)Sheets.count();w1++) | 230 | for(w1=0;w1<(int)Sheets.count();w1++) |
231 | { | 231 | { |
232 | if(Sheets[w1]!=NULL) {delete Sheets[w1];Sheets[w1]=NULL;}; | 232 | if(Sheets[w1]!=NULL) {delete Sheets[w1];Sheets[w1]=NULL;}; |
233 | }; | 233 | }; |
234 | XFRecords.resize(0); | 234 | XFRecords.resize(0); |
235 | SharedStrings.resize(0); | 235 | SharedStrings.resize(0); |
236 | Names.resize(0); | 236 | Names.resize(0); |
237 | Sheets.resize(0); | 237 | Sheets.resize(0); |
238 | fclose(File); | 238 | fclose(File); |
239 | printf("closed excel file!\r\n"); | 239 | printf("closed excel file!\r\n"); |
240 | if(File==NULL) return true; | 240 | if(File==NULL) return true; |
241 | return false; | 241 | return false; |
242 | }; | 242 | }; |
243 | 243 | ||
244 | void ExcelBook::SeekPosition(int pos) | 244 | void ExcelBook::SeekPosition(int pos) |
245 | { | 245 | { |
246 | if(!feof(File)) | 246 | if(!feof(File)) |
247 | { | 247 | { |
248 | Position=pos; | 248 | Position=pos; |
249 | //printf("SeekPosition:Pos:%d\r\n",Position); | 249 | //printf("SeekPosition:Pos:%d\r\n",Position); |
250 | fseek(File,pos,SEEK_SET); | 250 | fseek(File,pos,SEEK_SET); |
251 | }; | 251 | }; |
252 | }; | 252 | }; |
253 | 253 | ||
254 | void ExcelBook::SeekSkip(int pos) | 254 | void ExcelBook::SeekSkip(int pos) |
255 | { | 255 | { |
256 | if(!feof(File)) | 256 | if(!feof(File)) |
257 | { | 257 | { |
258 | Position=Position+pos; | 258 | Position=Position+pos; |
259 | //printf("SeekSkip:Pos:%d\r\n",Position); | 259 | //printf("SeekSkip:Pos:%d\r\n",Position); |
260 | fseek(File, Position, SEEK_SET); | 260 | fseek(File, Position, SEEK_SET); |
261 | }; | 261 | }; |
262 | }; | 262 | }; |
263 | 263 | ||
264 | int ExcelBook::FileEOF(void) | 264 | int ExcelBook::FileEOF(void) |
265 | { | 265 | { |
266 | if(File!=NULL) return(feof(File)); else return 0; | 266 | if(File!=NULL) return(feof(File)); else return 0; |
267 | //EOF is defined in stdlib as -1 | 267 | //EOF is defined in stdlib as -1 |
268 | }; | 268 | }; |
269 | 269 | ||
270 | int ExcelBook::Get2Bytes(void) | 270 | int ExcelBook::Get2Bytes(void) |
271 | { | 271 | { |
272 | int i1,i2; | 272 | int i1,i2; |
273 | i1=0; i2=0; | 273 | i1=0; i2=0; |
274 | if (!feof(File)) | 274 | if (!feof(File)) |
275 | { | 275 | { |
276 | i1=fgetc(File); | 276 | i1=fgetc(File); |
277 | Position++; | 277 | Position++; |
278 | }; | 278 | }; |
279 | if (!feof(File)) | 279 | if (!feof(File)) |
280 | { | 280 | { |
281 | i2=fgetc(File); | 281 | i2=fgetc(File); |
282 | Position++; | 282 | Position++; |
283 | }; | 283 | }; |
284 | return Integer2Byte(i1,i2); | 284 | return Integer2Byte(i1,i2); |
285 | }; | 285 | }; |
286 | 286 | ||
287 | char* ExcelBook::Read(int pos, int length) | 287 | char* ExcelBook::Read(int pos, int length) |
288 | { | 288 | { |
289 | int i; | 289 | int i; |
290 | char *data; | 290 | char *data; |
291 | data= new char[length]; | 291 | data= new char[length]; |
292 | SeekPosition(pos); | 292 | SeekPosition(pos); |
293 | for(i=0; i<length; i++) | 293 | for(i=0; i<length; i++) |
294 | { | 294 | { |
295 | if(!feof(File)) data[i]=fgetc(File); | 295 | if(!feof(File)) data[i]=fgetc(File); |
296 | }; | 296 | }; |
297 | Position= Position+length; | 297 | Position= Position+length; |
298 | return data; | 298 | return data; |
299 | }; | 299 | }; |
300 | 300 | ||
301 | QString ExcelBook::ReadUnicodeChar(int pos, int length) | 301 | QString ExcelBook::ReadUnicodeChar(int pos, int length) |
302 | { | 302 | { |
303 | int i; | 303 | int i; |
304 | QString data; | 304 | QString data; |
305 | int i1=' ',i2=' ',ii; | 305 | int i1=' ',i2=' ',ii; |
306 | SeekPosition(pos); | 306 | SeekPosition(pos); |
307 | for(i=0; i<length; i++) | 307 | for(i=0; i<length; i++) |
308 | { | 308 | { |
309 | if(!feof(File)) i1=fgetc(File); | 309 | if(!feof(File)) i1=fgetc(File); |
310 | if(!feof(File)) i2=fgetc(File); | 310 | if(!feof(File)) i2=fgetc(File); |
311 | ii=Integer2Byte(i1,i2); | 311 | ii=Integer2Byte(i1,i2); |
312 | data.append(ii); | 312 | data.append(ii); |
313 | Position+=2; | 313 | Position+=2; |
314 | }; | 314 | }; |
315 | return data; | 315 | return data; |
316 | }; | 316 | }; |
317 | 317 | ||
318 | QString* ExcelBook::GetString(int num) | 318 | QString* ExcelBook::GetString(int num) |
319 | { | 319 | { |
320 | if(num>=0 && num<(int)SharedStrings.count()) | 320 | if(num>=0 && num<(int)SharedStrings.count()) |
321 | { | 321 | { |
322 | return SharedStrings[num]; | 322 | return SharedStrings[num]; |
323 | }; | 323 | }; |
324 | return new QString(""); | 324 | return new QString(""); |
325 | }; | 325 | }; |
326 | 326 | ||
327 | int ExcelBook::SeekBOF(void) | 327 | int ExcelBook::SeekBOF(void) |
328 | { | 328 | { |
329 | int opcode,version,streamtype,length,ret=0; | 329 | int opcode,version,streamtype,length,ret=0; |
330 | char *data; | 330 | char *data; |
331 | while(!feof(File)) | 331 | while(!feof(File)) |
332 | { | 332 | { |
333 | opcode=Get2Bytes(); | 333 | opcode=Get2Bytes(); |
334 | if(opcode==XL_BOF) | 334 | if(opcode==XL_BOF) |
335 | { | 335 | { |
336 | length=Get2Bytes(); | 336 | length=Get2Bytes(); |
337 | data=Read(Position,length); | 337 | data=Read(Position,length); |
338 | version=Integer2Byte(data[0], data[1]); | 338 | version=Integer2Byte(data[0], data[1]); |
339 | streamtype=Integer2Byte(data[2], data[3]); | 339 | streamtype=Integer2Byte(data[2], data[3]); |
340 | printf("SEEKBOF:opcode=XLBOF, %d ,version %d\r\n",Position,version); | 340 | printf("SEEKBOF:opcode=XLBOF, %d ,version %d\r\n",Position,version); |
341 | delete data; data=NULL; | 341 | delete [] data; data=NULL; |
342 | if (version==BIFF8) ret=8; | 342 | if (version==BIFF8) ret=8; |
343 | else if(version==BIFF7) ret=7; | 343 | else if(version==BIFF7) ret=7; |
344 | printf("SEEKBOF:versionBIFF%d\r\n",ret); | 344 | printf("SEEKBOF:versionBIFF%d\r\n",ret); |
345 | if(streamtype==WBKGLOBAL) return ret *2; | 345 | if(streamtype==WBKGLOBAL) return ret *2; |
346 | else if(streamtype==WRKSHEET) return ret *1; | 346 | else if(streamtype==WRKSHEET) return ret *1; |
347 | return 1; | 347 | return 1; |
348 | }; | 348 | }; |
349 | }; | 349 | }; |
350 | return 0; | 350 | return 0; |
351 | }; | 351 | }; |
352 | 352 | ||
353 | ExcelBREC* ExcelBook::GetBREC(void) | 353 | ExcelBREC* ExcelBook::GetBREC(void) |
354 | { | 354 | { |
355 | ExcelBREC* rec; | 355 | ExcelBREC* rec; |
356 | rec= new ExcelBREC; | 356 | rec= new ExcelBREC; |
357 | if(FileEOF()) return NULL; | 357 | if(FileEOF()) return NULL; |
358 | rec->data=NULL; | 358 | rec->data=NULL; |
359 | rec->code=Get2Bytes(); | 359 | rec->code=Get2Bytes(); |
360 | rec->length=Get2Bytes(); | 360 | rec->length=Get2Bytes(); |
361 | rec->position=Position; | 361 | rec->position=Position; |
362 | SeekSkip(rec->length); | 362 | SeekSkip(rec->length); |
363 | return rec; | 363 | return rec; |
364 | }; | 364 | }; |
365 | 365 | ||
366 | ExcelBREC* ExcelBook::PeekBREC(void) | 366 | ExcelBREC* ExcelBook::PeekBREC(void) |
367 | { | 367 | { |
368 | int oldpos; | 368 | int oldpos; |
369 | ExcelBREC* NextRec; | 369 | ExcelBREC* NextRec; |
370 | oldpos=Position; | 370 | oldpos=Position; |
371 | NextRec=GetBREC(); | 371 | NextRec=GetBREC(); |
372 | SeekPosition(oldpos); | 372 | SeekPosition(oldpos); |
373 | return NextRec; | 373 | return NextRec; |
374 | }; | 374 | }; |
375 | 375 | ||
376 | char* ExcelBook::GetDataOfBREC(ExcelBREC* record) | 376 | char* ExcelBook::GetDataOfBREC(ExcelBREC* record) |
377 | { | 377 | { |
378 | if(record->data==NULL) | 378 | if(record->data==NULL) |
379 | { | 379 | { |
380 | ConvertCharToArray(record,Read(record->position,record->length),record->length); | 380 | ConvertCharToArray(record,Read(record->position,record->length),record->length); |
381 | }; | 381 | }; |
382 | return record->data;//new? | 382 | return record->data;//new? |
383 | }; | 383 | }; |
384 | 384 | ||
385 | void ExcelBook::ConvertCharToArray(ExcelBREC* record, char* chars, int length) | 385 | void ExcelBook::ConvertCharToArray(ExcelBREC* record, char* chars, int length) |
386 | { | 386 | { |
387 | record->data=new char[length]; | 387 | record->data=new char[length]; |
388 | for(int w1=0;w1<=length-1;w1++) | 388 | for(int w1=0;w1<=length-1;w1++) |
389 | record->data[w1]=chars[w1]; | 389 | record->data[w1]=chars[w1]; |
390 | }; | 390 | }; |
391 | 391 | ||
392 | 392 | ||
393 | bool ExcelSheet::InitCells() | 393 | bool ExcelSheet::InitCells() |
394 | { | 394 | { |
395 | int r; | 395 | int r; |
396 | Cells.resize(rows * cols + cols+1); | 396 | Cells.resize(rows * cols + cols+1); |
397 | if(Cells.count()==0) return false; | 397 | if(Cells.count()==0) return false; |
398 | for(r=0;r < Cells.count();r++) | 398 | for(r=0;r < Cells.count();r++) |
399 | { | 399 | { |
400 | Cells[r]=NULL; | 400 | Cells[r]=NULL; |
401 | }; | 401 | }; |
402 | return true; | 402 | return true; |
403 | }; | 403 | }; |
404 | 404 | ||
405 | void ExcelSheet::Set(int row, int col, ExcelCell* cell) | 405 | void ExcelSheet::Set(int row, int col, ExcelCell* cell) |
406 | { | 406 | { |
407 | if(cell!=NULL&&(row*cols+col)<Cells.count()) | 407 | if(cell!=NULL&&(row*cols+col)<Cells.count()) |
408 | { | 408 | { |
409 | Cells[row*cols+col]=cell; | 409 | Cells[row*cols+col]=cell; |
410 | }; | 410 | }; |
411 | }; | 411 | }; |
412 | 412 | ||
413 | ExcelCell* ExcelSheet::Get(int row, int col) | 413 | ExcelCell* ExcelSheet::Get(int row, int col) |
414 | { | 414 | { |
415 | ExcelCell* cell; | 415 | ExcelCell* cell; |
416 | cell=Cells[row*cols+col]; | 416 | cell=Cells[row*cols+col]; |
417 | if(cell==NULL) return NULL; | 417 | if(cell==NULL) return NULL; |
418 | return cell; | 418 | return cell; |
419 | }; | 419 | }; |
420 | 420 | ||
421 | int ExcelBook::SheetHandleRecord(ExcelSheet* sheet, ExcelBREC* record) | 421 | int ExcelBook::SheetHandleRecord(ExcelSheet* sheet, ExcelBREC* record) |
422 | { | 422 | { |
423 | char* data=NULL; | 423 | char* data=NULL; |
424 | switch (record->code) | 424 | switch (record->code) |
425 | { | 425 | { |
426 | case XL_DIMENSION: | 426 | case XL_DIMENSION: |
427 | data = GetDataOfBREC(record); | 427 | data = GetDataOfBREC(record); |
428 | if (record->length == 10) | 428 | if (record->length == 10) |
429 | { | 429 | { |
430 | sheet->rows = Integer2Byte(data[2], data[3]); | 430 | sheet->rows = Integer2Byte(data[2], data[3]); |
431 | sheet->cols = Integer2Byte(data[6], data[7]); | 431 | sheet->cols = Integer2Byte(data[6], data[7]); |
432 | } | 432 | } |
433 | else | 433 | else |
434 | { | 434 | { |
435 | sheet->rows = Integer4Byte(data[4], data[5], data[6], data[7]); | 435 | sheet->rows = Integer4Byte(data[4], data[5], data[6], data[7]); |
436 | sheet->cols = Integer2Byte(data[10], data[11]); | 436 | sheet->cols = Integer2Byte(data[10], data[11]); |
437 | } | 437 | } |
438 | sheet->InitCells(); | 438 | sheet->InitCells(); |
439 | break; | 439 | break; |
440 | 440 | ||
441 | case XL_LABELSST: | 441 | case XL_LABELSST: |
442 | HandleLabelSST(sheet, record); | 442 | HandleLabelSST(sheet, record); |
443 | break; | 443 | break; |
444 | 444 | ||
445 | case XL_RK: | 445 | case XL_RK: |
446 | case XL_RK2: | 446 | case XL_RK2: |
447 | HandleRK(sheet, record); | 447 | HandleRK(sheet, record); |
448 | break; | 448 | break; |
449 | 449 | ||
450 | case XL_MULRK: | 450 | case XL_MULRK: |
451 | HandleMulrk(sheet, record); | 451 | HandleMulrk(sheet, record); |
452 | break; | 452 | break; |
453 | 453 | ||
454 | case XL_ROW: | 454 | case XL_ROW: |
455 | break; | 455 | break; |
456 | 456 | ||
457 | case XL_NUMBER: | 457 | case XL_NUMBER: |
458 | HandleNumber(sheet, record); | 458 | HandleNumber(sheet, record); |
459 | break; | 459 | break; |
460 | 460 | ||
461 | case XL_BOOLERR: | 461 | case XL_BOOLERR: |
462 | break; | 462 | break; |
463 | 463 | ||
464 | case XL_CONTINUE: | 464 | case XL_CONTINUE: |
465 | break; | 465 | break; |
466 | 466 | ||
467 | case XL_FORMULA: | 467 | case XL_FORMULA: |
468 | case XL_FORMULA2: | 468 | case XL_FORMULA2: |
469 | HandleFormula(sheet, record); | 469 | HandleFormula(sheet, record); |
470 | break; | 470 | break; |
471 | 471 | ||
472 | case XL_LABEL: | 472 | case XL_LABEL: |
473 | break; | 473 | break; |
474 | 474 | ||
475 | case XL_NAME: | 475 | case XL_NAME: |
476 | HandleName(sheet, record); | 476 | HandleName(sheet, record); |
477 | break; | 477 | break; |
478 | 478 | ||
479 | case XL_BOF: | 479 | case XL_BOF: |
480 | break; | 480 | break; |
481 | case XL_EOF: | 481 | case XL_EOF: |
482 | return 0; | 482 | return 0; |
483 | default: | 483 | default: |
484 | break; | 484 | break; |
485 | }; | 485 | }; |
486 | return 1; | 486 | return 1; |
487 | }; | 487 | }; |
488 | 488 | ||
489 | int ExcelBook::ReadSheet(ExcelSheet* sheet) | 489 | int ExcelBook::ReadSheet(ExcelSheet* sheet) |
490 | { | 490 | { |
491 | ExcelBREC* record; | 491 | ExcelBREC* record; |
492 | int oldpos; | 492 | int oldpos; |
493 | oldpos = Position; | 493 | oldpos = Position; |
494 | SeekPosition(sheet->position); | 494 | SeekPosition(sheet->position); |
495 | record = GetBREC(); | 495 | record = GetBREC(); |
496 | while (record!=NULL) | 496 | while (record!=NULL) |
497 | { | 497 | { |
498 | if (!SheetHandleRecord(sheet, record)) break; | 498 | if (!SheetHandleRecord(sheet, record)) break; |
499 | record=GetBREC(); | 499 | record=GetBREC(); |
500 | }; | 500 | }; |
501 | SeekPosition(oldpos); | 501 | SeekPosition(oldpos); |
502 | return 1; | 502 | return 1; |
503 | }; | 503 | }; |
504 | 504 | ||
505 | ExcelSheet* ExcelBook::GetSheet(void) | 505 | ExcelSheet* ExcelBook::GetSheet(void) |
506 | { | 506 | { |
507 | ExcelSheet* sh=NULL; | 507 | ExcelSheet* sh=NULL; |
508 | int type; | 508 | int type; |
509 | type=SeekBOF(); | 509 | type=SeekBOF(); |
510 | Version=type; | 510 | Version=type; |
511 | sh=new ExcelSheet; | 511 | sh=new ExcelSheet; |
512 | if(type) | 512 | if(type) |
513 | { | 513 | { |
514 | sh->type=type; | 514 | sh->type=type; |
515 | sh->position=Position; | 515 | sh->position=Position; |
516 | sh->name=QString(""); | 516 | sh->name=QString(""); |
517 | }; | 517 | }; |
518 | if(type==8||type==7) | 518 | if(type==8||type==7) |
519 | { | 519 | { |
520 | ReadSheet(sh); | 520 | ReadSheet(sh); |
521 | }; | 521 | }; |
522 | return sh; | 522 | return sh; |
523 | }; | 523 | }; |
524 | 524 | ||
525 | void ExcelBook::ParseSheets(void) | 525 | void ExcelBook::ParseSheets(void) |
526 | { | 526 | { |
527 | int BOFs; | 527 | int BOFs; |
528 | ExcelBREC* r; | 528 | ExcelBREC* r; |
529 | BOFs=1; | 529 | BOFs=1; |
530 | r=GetBREC(); | 530 | r=GetBREC(); |
531 | while(BOFs) | 531 | while(BOFs) |
532 | { | 532 | { |
533 | r=GetBREC(); | 533 | r=GetBREC(); |
534 | switch(r->code) | 534 | switch(r->code) |
535 | { | 535 | { |
536 | case XL_SST: | 536 | case XL_SST: |
537 | HandleSST(r); | 537 | HandleSST(r); |
538 | break; | 538 | break; |
539 | 539 | ||
540 | case XL_TXO: | 540 | case XL_TXO: |
541 | break; | 541 | break; |
542 | case XL_NAME: | 542 | case XL_NAME: |
543 | break; | 543 | break; |
544 | case XL_ROW: | 544 | case XL_ROW: |
545 | break; | 545 | break; |
546 | 546 | ||
547 | case XL_FORMAT: | 547 | case XL_FORMAT: |
548 | HandleFormat(r); | 548 | HandleFormat(r); |
549 | break; | 549 | break; |
550 | 550 | ||
551 | case XL_XF: | 551 | case XL_XF: |
552 | HandleXF(r); | 552 | HandleXF(r); |
553 | break; | 553 | break; |
554 | 554 | ||
555 | case XL_BOUNDSHEET: | 555 | case XL_BOUNDSHEET: |
556 | HandleBoundSheet(r); | 556 | HandleBoundSheet(r); |
557 | break; | 557 | break; |
558 | 558 | ||
559 | case XL_EXTSST: | 559 | case XL_EXTSST: |
560 | break; | 560 | break; |
561 | case XL_CONTINUE: | 561 | case XL_CONTINUE: |
562 | break; | 562 | break; |
563 | 563 | ||
564 | case XL_EOF: | 564 | case XL_EOF: |
565 | BOFs--; | 565 | BOFs--; |
566 | break; | 566 | break; |
567 | 567 | ||
568 | default: | 568 | default: |
569 | break; | 569 | break; |
570 | }; | 570 | }; |
571 | }; | 571 | }; |
572 | }; | 572 | }; |
573 | 573 | ||
574 | void ExcelBook::GetSheets(void) | 574 | void ExcelBook::GetSheets(void) |
575 | { | 575 | { |
576 | ExcelSheet* sheet; | 576 | ExcelSheet* sheet; |
577 | Sheets.resize(0); | 577 | Sheets.resize(0); |
578 | sheet=GetSheet(); | 578 | sheet=GetSheet(); |
579 | while (sheet->Cells.count()!= 0 ) | 579 | while (sheet->Cells.count()!= 0 ) |
580 | { | 580 | { |
581 | Sheets.resize(Sheets.count()+1); | 581 | Sheets.resize(Sheets.count()+1); |
582 | Sheets[Sheets.count()-1]=sheet; | 582 | Sheets[Sheets.count()-1]=sheet; |
583 | sheet->name=*Names[Sheets.count()-1]; | 583 | sheet->name=*Names[Sheets.count()-1]; |
584 | sheet=GetSheet(); | 584 | sheet=GetSheet(); |
585 | }; | 585 | }; |
586 | }; | 586 | }; |
587 | 587 | ||
588 | bool ExcelBook::ParseBook(char *file) | 588 | bool ExcelBook::ParseBook(char *file) |
589 | { | 589 | { |
590 | dateformat=QString(""); | 590 | dateformat=QString(""); |
591 | DetectEndian(); | 591 | DetectEndian(); |
592 | if ( !OpenFile( file ) ) | 592 | if ( !OpenFile( file ) ) |
593 | return false; | 593 | return false; |
594 | SeekBOF(); | 594 | SeekBOF(); |
595 | ParseSheets(); | 595 | ParseSheets(); |
596 | GetSheets(); | 596 | GetSheets(); |
597 | return true; | 597 | return true; |
598 | }; | 598 | }; |
599 | 599 | ||
600 | QString ExcelBook::GetASCII(char* inbytes, int pos, int chars) | 600 | QString ExcelBook::GetASCII(char* inbytes, int pos, int chars) |
601 | { | 601 | { |
602 | int i; | 602 | int i; |
603 | QString outstr=""; | 603 | QString outstr=""; |
604 | for (i = 0; i < chars; i++) | 604 | for (i = 0; i < chars; i++) |
605 | { | 605 | { |
606 | outstr.append(inbytes[i+pos]); | 606 | outstr.append(inbytes[i+pos]); |
607 | }; | 607 | }; |
608 | return outstr; | 608 | return outstr; |
609 | }; | 609 | }; |
610 | 610 | ||
611 | QString ExcelBook::GetUnicode(char * inbytes, int pos, int chars) | 611 | QString ExcelBook::GetUnicode(char * inbytes, int pos, int chars) |
612 | { | 612 | { |
613 | QString outstr=""; | 613 | QString outstr=""; |
614 | int i; | 614 | int i; |
615 | int rc; | 615 | int rc; |
616 | for (i=0; i<chars*2; i++) | 616 | for (i=0; i<chars*2; i++) |
617 | { | 617 | { |
618 | rc=Integer2Byte(inbytes[i+pos],inbytes[i+pos+1]); | 618 | rc=Integer2Byte(inbytes[i+pos],inbytes[i+pos+1]); |
619 | outstr.append(QChar(rc)); | 619 | outstr.append(QChar(rc)); |
620 | i++; | 620 | i++; |
621 | }; | 621 | }; |
622 | return outstr; | 622 | return outstr; |
623 | }; | 623 | }; |
624 | 624 | ||
625 | 625 | ||
626 | void ExcelBook::HandleBoundSheet(ExcelBREC* rec) | 626 | void ExcelBook::HandleBoundSheet(ExcelBREC* rec) |
627 | { | 627 | { |
628 | char* data; | 628 | char* data; |
629 | int type; | 629 | int type; |
630 | int visibility; | 630 | int visibility; |
631 | int length; | 631 | int length; |
632 | int pos; | 632 | int pos; |
633 | QString name; | 633 | QString name; |
634 | pos = 8; | 634 | pos = 8; |
635 | data = GetDataOfBREC(rec); | 635 | data = GetDataOfBREC(rec); |
636 | type = data[4]; | 636 | type = data[4]; |
637 | visibility = data[5]; | 637 | visibility = data[5]; |
638 | length = data[6]; | 638 | length = data[6]; |
639 | if(data[7]==0) | 639 | if(data[7]==0) |
640 | { | 640 | { |
641 | //ascii | 641 | //ascii |
642 | name=GetASCII(data,pos,length); | 642 | name=GetASCII(data,pos,length); |
643 | } | 643 | } |
644 | else | 644 | else |
645 | { | 645 | { |
646 | name=GetUnicode(data,pos,length); | 646 | name=GetUnicode(data,pos,length); |
647 | }; | 647 | }; |
648 | Names.resize(Names.count()+1); | 648 | Names.resize(Names.count()+1); |
649 | Names[Names.count()-1]=new QString(name); | 649 | Names[Names.count()-1]=new QString(name); |
650 | }; | 650 | }; |
651 | 651 | ||
652 | void ExcelBook::HandleName(ExcelSheet* sheet, ExcelBREC* rec) | 652 | void ExcelBook::HandleName(ExcelSheet* sheet, ExcelBREC* rec) |
653 | { | 653 | { |
654 | char* data; | 654 | char* data; |
655 | QString name; | 655 | QString name; |
656 | int length; | 656 | int length; |
657 | int pos; | 657 | int pos; |
658 | pos = 15; | 658 | pos = 15; |
659 | data = GetDataOfBREC(rec); | 659 | data = GetDataOfBREC(rec); |
660 | length = data[3]; | 660 | length = data[3]; |
661 | name = GetASCII(data,pos,length); | 661 | name = GetASCII(data,pos,length); |
662 | 662 | ||
663 | 663 | ||
664 | }; | 664 | }; |
665 | 665 | ||
666 | ExcelFormat* ExcelBook::GetFormatting(int xf) | 666 | ExcelFormat* ExcelBook::GetFormatting(int xf) |
667 | { | 667 | { |
668 | int i; | 668 | int i; |
669 | ExcelFormat* rec; | 669 | ExcelFormat* rec; |
670 | rec=new ExcelFormat(); | 670 | rec=new ExcelFormat(); |
671 | for (i = 0; formatter[i].code != 0; i++) | 671 | for (i = 0; formatter[i].code != 0; i++) |
672 | { | 672 | { |
673 | if (xf == formatter[i].code) break; | 673 | if (xf == formatter[i].code) break; |
674 | }; | 674 | }; |
675 | if (formatter[i].format ==NULL) return NULL; | 675 | if (formatter[i].format ==NULL) return NULL; |
676 | rec->code = xf; | 676 | rec->code = xf; |
677 | rec->type = formatter[i].type; | 677 | rec->type = formatter[i].type; |
678 | rec->format = formatter[i].format; | 678 | rec->format = formatter[i].format; |
679 | return rec; | 679 | return rec; |
680 | }; | 680 | }; |
681 | 681 | ||
682 | void ExcelBook::HandleSetOfSST(ExcelBREC* rec/*, SSTList* cont*/, char* bytes) | 682 | void ExcelBook::HandleSetOfSST(ExcelBREC* rec/*, SSTList* cont*/, char* bytes) |
683 | { | 683 | { |
684 | QString str=QString(""); | 684 | QString str=QString(""); |
685 | char* data; | 685 | char* data; |
686 | int chars, pos, options, i; | 686 | int chars, pos, options, i; |
687 | int richstring, fareaststring, runlength=0; | 687 | int richstring, fareaststring, runlength=0; |
688 | int richruns=0,fareastsize=0; | 688 | int richruns=0,fareastsize=0; |
689 | int totalstrings; | 689 | int totalstrings; |
690 | int uniquestrings; | 690 | int uniquestrings; |
691 | data = GetDataOfBREC(rec); | 691 | data = GetDataOfBREC(rec); |
692 | totalstrings = Integer4Byte(data[0], data[1], data[2], data[3]); | 692 | totalstrings = Integer4Byte(data[0], data[1], data[2], data[3]); |
693 | uniquestrings = Integer4Byte(data[4], data[5], data[6], data[7]); | 693 | uniquestrings = Integer4Byte(data[4], data[5], data[6], data[7]); |
694 | pos = 8; | 694 | pos = 8; |
695 | for (i = 0; i < uniquestrings; i++) | 695 | for (i = 0; i < uniquestrings; i++) |
696 | { | 696 | { |
697 | richruns=0; fareastsize=0; | 697 | richruns=0; fareastsize=0; |
698 | chars = Integer2Byte(data[pos], data[pos+1]); | 698 | chars = Integer2Byte(data[pos], data[pos+1]); |
699 | pos += 2; | 699 | pos += 2; |
700 | options = data[pos]; | 700 | options = data[pos]; |
701 | pos++; | 701 | pos++; |
702 | fareaststring = ((options & 0x04) != 0); | 702 | fareaststring = ((options & 0x04) != 0); |
703 | richstring = ((options & 0x08) != 0); | 703 | richstring = ((options & 0x08) != 0); |
704 | if(richstring) | 704 | if(richstring) |
705 | { | 705 | { |
706 | richruns= Integer2Byte(data[pos],data[pos+1]); | 706 | richruns= Integer2Byte(data[pos],data[pos+1]); |
707 | pos+=2; | 707 | pos+=2; |
708 | }; | 708 | }; |
709 | if(fareaststring) | 709 | if(fareaststring) |
710 | { | 710 | { |
711 | fareastsize=Integer4Byte(data[pos], data[pos+1], data[pos+2], data[pos+3]); | 711 | fareastsize=Integer4Byte(data[pos], data[pos+1], data[pos+2], data[pos+3]); |
712 | pos+=4; | 712 | pos+=4; |
713 | }; | 713 | }; |
714 | 714 | ||
715 | if ((options & 0x01) == 0) //8 bit chars | 715 | if ((options & 0x01) == 0) //8 bit chars |
716 | { | 716 | { |
717 | /* ascii */ | 717 | /* ascii */ |
718 | str = GetASCII(bytes,pos,chars); | 718 | str = GetASCII(bytes,pos,chars); |
719 | pos=pos+chars; | 719 | pos=pos+chars; |
720 | if(str[0]=='=') str[0]=' '; | 720 | if(str[0]=='=') str[0]=' '; |
721 | }else //16 bit chars | 721 | }else //16 bit chars |
722 | { | 722 | { |
723 | /* unicode */ | 723 | /* unicode */ |
724 | str = GetUnicode(bytes,pos,chars); | 724 | str = GetUnicode(bytes,pos,chars); |
725 | pos=pos+chars*2; | 725 | pos=pos+chars*2; |
726 | }; | 726 | }; |
727 | // HERE TO PUT richformat handling | 727 | // HERE TO PUT richformat handling |
728 | if (richstring) | 728 | if (richstring) |
729 | { | 729 | { |
730 | pos += 4 * richruns; | 730 | pos += 4 * richruns; |
731 | }; | 731 | }; |
732 | if (fareaststring) | 732 | if (fareaststring) |
733 | { | 733 | { |
734 | pos += fareastsize; | 734 | pos += fareastsize; |
735 | }; | 735 | }; |
736 | //printf("String=%s, length=%d first=0x%x\r\n",str.ascii(),str.length(),str[0].unicode()); | 736 | //printf("String=%s, length=%d first=0x%x\r\n",str.ascii(),str.length(),str[0].unicode()); |
737 | SharedStrings.resize(SharedStrings.count()+1); | 737 | SharedStrings.resize(SharedStrings.count()+1); |
738 | SharedStrings[SharedStrings.count()-1]=new QString(str); | 738 | SharedStrings[SharedStrings.count()-1]=new QString(str); |
739 | } | 739 | } |
740 | }; | 740 | }; |
741 | 741 | ||
742 | 742 | ||
743 | char* ExcelBook::MergeBytesFromSSTs(ExcelBREC* rec,SSTList* cont) | 743 | char* ExcelBook::MergeBytesFromSSTs(ExcelBREC* rec,SSTList* cont) |
744 | { | 744 | { |
745 | int i, pos; | 745 | int i, pos; |
746 | int length; | 746 | int length; |
747 | 747 | ||
748 | char* data; | 748 | char* data; |
749 | char* bytes; | 749 | char* bytes; |
750 | length = rec->length; | 750 | length = rec->length; |
751 | for (i = 0; i < (int) cont->rec.count(); i++) | 751 | for (i = 0; i < (int) cont->rec.count(); i++) |
752 | { | 752 | { |
753 | length += cont->rec[i]->length; | 753 | length += cont->rec[i]->length; |
754 | } | 754 | } |
755 | bytes = GetDataOfBREC(rec); | 755 | bytes = GetDataOfBREC(rec); |
756 | pos = rec->length; | 756 | pos = rec->length; |
757 | for (i = 0; i < (int) cont->rec.count(); i++) | 757 | for (i = 0; i < (int) cont->rec.count(); i++) |
758 | { | 758 | { |
759 | data = GetDataOfBREC(cont->rec[i]); | 759 | data = GetDataOfBREC(cont->rec[i]); |
760 | *bytes += pos; | 760 | *bytes += pos; |
761 | bytes = data; | 761 | bytes = data; |
762 | pos += cont->rec[i]->length; | 762 | pos += cont->rec[i]->length; |
763 | } | 763 | } |
764 | return bytes; | 764 | return bytes; |
765 | }; | 765 | }; |
766 | 766 | ||
767 | 767 | ||
768 | void ExcelBook::HandleSST(ExcelBREC* rec) | 768 | void ExcelBook::HandleSST(ExcelBREC* rec) |
769 | { | 769 | { |
770 | char* bytes; | 770 | char* bytes; |
771 | SSTList* cont; | 771 | SSTList* cont; |
772 | cont= new SSTList; | 772 | cont= new SSTList; |
773 | ExcelBREC* nr; | 773 | ExcelBREC* nr; |
774 | nr = PeekBREC(); | 774 | nr = PeekBREC(); |
775 | while (nr->code == XL_CONTINUE) | 775 | while (nr->code == XL_CONTINUE) |
776 | { | 776 | { |
777 | cont->rec.resize(cont->rec.count()+1); | 777 | cont->rec.resize(cont->rec.count()+1); |
778 | cont->rec[cont->rec.count()-1]=GetBREC(); | 778 | cont->rec[cont->rec.count()-1]=GetBREC(); |
779 | nr = PeekBREC(); | 779 | nr = PeekBREC(); |
780 | } | 780 | } |
781 | bytes = MergeBytesFromSSTs(rec,cont); | 781 | bytes = MergeBytesFromSSTs(rec,cont); |
782 | HandleSetOfSST(rec, bytes); | 782 | HandleSetOfSST(rec, bytes); |
783 | for(int w1=0;w1<(int)cont->rec.count();w1++) | 783 | for(int w1=0;w1<(int)cont->rec.count();w1++) |
784 | { | 784 | { |
785 | if(cont->rec[w1]!=NULL) {delete cont->rec[w1];cont->rec[w1]=NULL;}; | 785 | if(cont->rec[w1]!=NULL) {delete cont->rec[w1];cont->rec[w1]=NULL;}; |
786 | }; | 786 | }; |
787 | cont->rec.resize(0); | 787 | cont->rec.resize(0); |
788 | }; | 788 | }; |
789 | 789 | ||
790 | void ExcelBook::HandleLabelSST(ExcelSheet* sheet, ExcelBREC* rec) | 790 | void ExcelBook::HandleLabelSST(ExcelSheet* sheet, ExcelBREC* rec) |
791 | { | 791 | { |
792 | int index, row, col; | 792 | int index, row, col; |
793 | char* data; | 793 | char* data; |
794 | data = GetDataOfBREC(rec); | 794 | data = GetDataOfBREC(rec); |
795 | index = Integer4Byte(data[6], data[7], data[8], data[9]); | 795 | index = Integer4Byte(data[6], data[7], data[8], data[9]); |
796 | row = Integer2Byte(data[0], data[1]); | 796 | row = Integer2Byte(data[0], data[1]); |
797 | col = Integer2Byte(data[2], data[3]); | 797 | col = Integer2Byte(data[2], data[3]); |
798 | sheet->Set(row,col, CellLabel(row, col, *GetString(index))); | 798 | sheet->Set(row,col, CellLabel(row, col, *GetString(index))); |
799 | }; | 799 | }; |
800 | 800 | ||
801 | ExcelCell* ExcelBook::CellLabel(int row, int col, QString str) | 801 | ExcelCell* ExcelBook::CellLabel(int row, int col, QString str) |
802 | { | 802 | { |
803 | ExcelCell* c; | 803 | ExcelCell* c; |
804 | c= new ExcelCell; | 804 | c= new ExcelCell; |
805 | c->row = row; | 805 | c->row = row; |
806 | c->col = col; | 806 | c->col = col; |
807 | c->type = CELL_LABEL; | 807 | c->type = CELL_LABEL; |
808 | c->valuec = str; | 808 | c->valuec = str; |
809 | return c; | 809 | return c; |
810 | }; | 810 | }; |
811 | 811 | ||
812 | ExcelCell* ExcelBook::CellNumber(int row, int col, int index, double d) | 812 | ExcelCell* ExcelBook::CellNumber(int row, int col, int index, double d) |
813 | { | 813 | { |
814 | ExcelCell* c; | 814 | ExcelCell* c; |
815 | c=new ExcelCell; | 815 | c=new ExcelCell; |
816 | c->row = row; | 816 | c->row = row; |
817 | c->col = col; | 817 | c->col = col; |
818 | c->xfindex = index; | 818 | c->xfindex = index; |
819 | c->type = CELL_NUMBER; | 819 | c->type = CELL_NUMBER; |
820 | c->valued = d; | 820 | c->valued = d; |
821 | return c; | 821 | return c; |
822 | }; | 822 | }; |
823 | 823 | ||
824 | QString* ExcelBook::CellDataString(ExcelSheet* sh, int row, int col) | 824 | QString* ExcelBook::CellDataString(ExcelSheet* sh, int row, int col) |
825 | { | 825 | { |
826 | time_t date; | 826 | time_t date; |
827 | struct tm *tmptr; | 827 | struct tm *tmptr; |
828 | ExcelCell* c; | 828 | ExcelCell* c; |
829 | char str[128]; | 829 | char str[128]; |
830 | QString format; | 830 | QString format; |
831 | int precision; | 831 | int precision; |
832 | int utcOffsetDays = 25569; | 832 | int utcOffsetDays = 25569; |
833 | int sInADay = 24 * 60 * 60; | 833 | int sInADay = 24 * 60 * 60; |
834 | c = sh->Get(row,col); | 834 | c = sh->Get(row,col); |
835 | if (c == NULL) return new QString(""); | 835 | if (c == NULL) return new QString(""); |
836 | switch (c->type) | 836 | switch (c->type) |
837 | { | 837 | { |
838 | case CELL_LABEL: | 838 | case CELL_LABEL: |
839 | return new QString(c->valuec); | 839 | return new QString(c->valuec); |
840 | case CELL_NUMBER: | 840 | case CELL_NUMBER: |
841 | if (XFRecords[c->xfindex]->type == DATEFORMAT) | 841 | if (XFRecords[c->xfindex]->type == DATEFORMAT) |
842 | { | 842 | { |
843 | 843 | ||
844 | format = XFRecords[c->xfindex]->format; | 844 | format = XFRecords[c->xfindex]->format; |
845 | date = (time_t) ((c->valued - utcOffsetDays) * sInADay); | 845 | date = (time_t) ((c->valued - utcOffsetDays) * sInADay); |
846 | tmptr = gmtime(&date); | 846 | tmptr = gmtime(&date); |
847 | if (dateformat) | 847 | if (dateformat) |
848 | { | 848 | { |
849 | strftime(str,1024,dateformat.ascii(),tmptr); | 849 | strftime(str,1024,dateformat.ascii(),tmptr); |
850 | } | 850 | } |
851 | else | 851 | else |
852 | { | 852 | { |
853 | strftime(str,1024,format.ascii(),tmptr); | 853 | strftime(str,1024,format.ascii(),tmptr); |
854 | }; | 854 | }; |
855 | } | 855 | } |
856 | else | 856 | else |
857 | if (XFRecords[c->xfindex]->type == NUMBERFORMAT) | 857 | if (XFRecords[c->xfindex]->type == NUMBERFORMAT) |
858 | { | 858 | { |
859 | format = XFRecords[c->xfindex]->format; | 859 | format = XFRecords[c->xfindex]->format; |
860 | //sprintf(str,format.ascii(),c->valued); | 860 | //sprintf(str,format.ascii(),c->valued); |
861 | // the real format is ignored... | 861 | // the real format is ignored... |
862 | // because there is more work to be done in the field | 862 | // because there is more work to be done in the field |
863 | precision = CellGetPrecision(c->valued); | 863 | precision = CellGetPrecision(c->valued); |
864 | sprintf(str,"%.*f",precision,c->valued); | 864 | sprintf(str,"%.*f",precision,c->valued); |
865 | } | 865 | } |
866 | else | 866 | else |
867 | { | 867 | { |
868 | precision = CellGetPrecision(c->valued); | 868 | precision = CellGetPrecision(c->valued); |
869 | sprintf(str,"%.*f",precision,c->valued); | 869 | sprintf(str,"%.*f",precision,c->valued); |
870 | }; | 870 | }; |
871 | break; | 871 | break; |
872 | case CELL_DATE: | 872 | case CELL_DATE: |
873 | break; | 873 | break; |
874 | case CELL_BOOLEAN: | 874 | case CELL_BOOLEAN: |
875 | break; | 875 | break; |
876 | case CELL_ERROR: | 876 | case CELL_ERROR: |
877 | break; | 877 | break; |
878 | } | 878 | } |
879 | return new QString(str); | 879 | return new QString(str); |
880 | }; | 880 | }; |
881 | 881 | ||
882 | int ExcelBook::CellGetPrecision(double d) | 882 | int ExcelBook::CellGetPrecision(double d) |
883 | { | 883 | { |
884 | double t; | 884 | double t; |
885 | int i,x; | 885 | int i,x; |
886 | int count; | 886 | int count; |
887 | if (d < 0) d *= -1; | 887 | if (d < 0) d *= -1; |
888 | i = (int)d; | 888 | i = (int)d; |
889 | t = d - (double)i; | 889 | t = d - (double)i; |
890 | if (t <= 0) | 890 | if (t <= 0) |
891 | { | 891 | { |
892 | return 0; | 892 | return 0; |
893 | }; | 893 | }; |
894 | count = 0; | 894 | count = 0; |
895 | for (x = 6; x > 1; x--) | 895 | for (x = 6; x > 1; x--) |
896 | { | 896 | { |
897 | i = (int)d; | 897 | i = (int)d; |
898 | t = d - (double)i; | 898 | t = d - (double)i; |
899 | t *= pow(10,x - 2); | 899 | t *= pow(10,x - 2); |
900 | i = (int)t; | 900 | i = (int)t; |
901 | t = t - (double)i; | 901 | t = t - (double)i; |
902 | t *= 10; | 902 | t *= 10; |
903 | i = (int)t; | 903 | i = (int)t; |
904 | if (i > 0) break; | 904 | if (i > 0) break; |
905 | count++; | 905 | count++; |
906 | }; | 906 | }; |
907 | return (5 - count); | 907 | return (5 - count); |
908 | }; | 908 | }; |
909 | 909 | ||
910 | 910 | ||
911 | void ExcelBook::CellSetDateFormat(char *d) | 911 | void ExcelBook::CellSetDateFormat(char *d) |
912 | { | 912 | { |
913 | dateformat = QString(d); | 913 | dateformat = QString(d); |
914 | }; | 914 | }; |
915 | 915 | ||
916 | void ExcelBook::HandleMulrk(ExcelSheet* sheet, ExcelBREC* record) | 916 | void ExcelBook::HandleMulrk(ExcelSheet* sheet, ExcelBREC* record) |
917 | { | 917 | { |
918 | struct mulrk mulrk; | 918 | struct mulrk mulrk; |
919 | char* data; | 919 | char* data; |
920 | ExcelCell* cell; | 920 | ExcelCell* cell; |
921 | int len; | 921 | int len; |
922 | int i; | 922 | int i; |
923 | len = record->length; | 923 | len = record->length; |
924 | data = GetDataOfBREC(record); | 924 | data = GetDataOfBREC(record); |
925 | mulrk.row = Integer2Byte(data[0],data[1]); | 925 | mulrk.row = Integer2Byte(data[0],data[1]); |
926 | mulrk.first = Integer2Byte(data[2],data[3]); | 926 | mulrk.first = Integer2Byte(data[2],data[3]); |
927 | mulrk.last = Integer2Byte(data[len - 2],data[len - 1]); | 927 | mulrk.last = Integer2Byte(data[len - 2],data[len - 1]); |
928 | mulrk.numrks = mulrk.last - mulrk.first + 1; | 928 | mulrk.numrks = mulrk.last - mulrk.first + 1; |
929 | MulrkRead(&mulrk, data); | 929 | MulrkRead(&mulrk, data); |
930 | for (i = 0; i < mulrk.numrks; i++) | 930 | for (i = 0; i < mulrk.numrks; i++) |
931 | { | 931 | { |
932 | cell = CellNumber(mulrk.row, mulrk.first + i, mulrk.xfindices[i], mulrk.rkdbls[i]); | 932 | cell = CellNumber(mulrk.row, mulrk.first + i, mulrk.xfindices[i], mulrk.rkdbls[i]); |
933 | sheet->Set(mulrk.row,mulrk.first+ i, cell); | 933 | sheet->Set(mulrk.row,mulrk.first+ i, cell); |
934 | //printf("handleMULRK:row=%d,col=%d,val=%f\r\n",mulrk.row,mulrk.first+i,mulrk.rkdbls[i]); | 934 | //printf("handleMULRK:row=%d,col=%d,val=%f\r\n",mulrk.row,mulrk.first+i,mulrk.rkdbls[i]); |
935 | } | 935 | } |
936 | //delete(mulrk.xfindices); | 936 | //delete(mulrk.xfindices); |
937 | //delete(mulrk.rkdbls); | 937 | //delete(mulrk.rkdbls); |
938 | }; | 938 | }; |
939 | 939 | ||
940 | void ExcelBook::MulrkRead(struct mulrk *mulrk, char* data) | 940 | void ExcelBook::MulrkRead(struct mulrk *mulrk, char* data) |
941 | { | 941 | { |
942 | double d; | 942 | double d; |
943 | int i; | 943 | int i; |
944 | int pos; | 944 | int pos; |
945 | pos = 4; | 945 | pos = 4; |
946 | mulrk->xfindices.resize(mulrk->numrks); | 946 | mulrk->xfindices.resize(mulrk->numrks); |
947 | mulrk->rkdbls.resize(mulrk->numrks); | 947 | mulrk->rkdbls.resize(mulrk->numrks); |
948 | for (i = 0; i < mulrk->numrks; i++) | 948 | for (i = 0; i < mulrk->numrks; i++) |
949 | { | 949 | { |
950 | mulrk->xfindices[i] = Integer2Byte(data[pos], data[pos+1]); | 950 | mulrk->xfindices[i] = Integer2Byte(data[pos], data[pos+1]); |
951 | d=Double4Byte(data[pos+2], data[pos+3], data[pos+4], data[pos+5]); | 951 | d=Double4Byte(data[pos+2], data[pos+3], data[pos+4], data[pos+5]); |
952 | //printf("double:%f\r\n",d); | 952 | //printf("double:%f\r\n",d); |
953 | mulrk->rkdbls[i] = d; | 953 | mulrk->rkdbls[i] = d; |
954 | pos += 6; | 954 | pos += 6; |
955 | } | 955 | } |
956 | }; | 956 | }; |
957 | 957 | ||
958 | 958 | ||
959 | void ExcelBook::HandleNumber(ExcelSheet* sheet, ExcelBREC* record) | 959 | void ExcelBook::HandleNumber(ExcelSheet* sheet, ExcelBREC* record) |
960 | { | 960 | { |
961 | int xfindex, row, col; | 961 | int xfindex, row, col; |
962 | char* data; | 962 | char* data; |
963 | double d; | 963 | double d; |
964 | data = GetDataOfBREC(record); | 964 | data = GetDataOfBREC(record); |
965 | row = Integer2Byte(data[0], data[1]); | 965 | row = Integer2Byte(data[0], data[1]); |
966 | col = Integer2Byte(data[2], data[3]); | 966 | col = Integer2Byte(data[2], data[3]); |
967 | xfindex = Integer2Byte(data[4], data[5]); | 967 | xfindex = Integer2Byte(data[4], data[5]); |
968 | #if defined(__arm__) && !defined(__vfp__) | 968 | #if defined(__arm__) && !defined(__vfp__) |
969 | d=Double8Byte(data[10], data[11], data[12], data[13],data[6], data[7], data[8], data[9]); | 969 | d=Double8Byte(data[10], data[11], data[12], data[13],data[6], data[7], data[8], data[9]); |
970 | #else | 970 | #else |
971 | d=Double8Byte(data[6], data[7], data[8], data[9],data[10], data[11], data[12], data[13]); | 971 | d=Double8Byte(data[6], data[7], data[8], data[9],data[10], data[11], data[12], data[13]); |
972 | #endif | 972 | #endif |
973 | //even if ARM is little endian... doubles are been placed as bigendian words. | 973 | //even if ARM is little endian... doubles are been placed as bigendian words. |
974 | //thanks pb_ for that. :) | 974 | //thanks pb_ for that. :) |
975 | sheet->Set(row,col, CellNumber(row,col,xfindex,d)); | 975 | sheet->Set(row,col, CellNumber(row,col,xfindex,d)); |
976 | //printf("handleNumber:row=%d,col=%d,val=%f\r\n",row,col,d); | 976 | //printf("handleNumber:row=%d,col=%d,val=%f\r\n",row,col,d); |
977 | }; | 977 | }; |
978 | 978 | ||
979 | ExcelFormat::ExcelFormat() | 979 | ExcelFormat::ExcelFormat() |
980 | { | 980 | { |
981 | code=0;type=0;format=""; | 981 | code=0;type=0;format=""; |
982 | }; | 982 | }; |
983 | 983 | ||
984 | ExcelFormat::ExcelFormat(int c,int t, QString s) | 984 | ExcelFormat::ExcelFormat(int c,int t, QString s) |
985 | { | 985 | { |
986 | code=c;type=t;format=s; | 986 | code=c;type=t;format=s; |
987 | }; | 987 | }; |
988 | 988 | ||
989 | 989 | ||
990 | void ExcelBook::HandleFormat(ExcelBREC* rec) | 990 | void ExcelBook::HandleFormat(ExcelBREC* rec) |
991 | { | 991 | { |
992 | ExcelFormat* xfrec; | 992 | ExcelFormat* xfrec; |
993 | char* data; | 993 | char* data; |
994 | int format; | 994 | int format; |
995 | data = GetDataOfBREC(rec); | 995 | data = GetDataOfBREC(rec); |
996 | format = Integer2Byte(data[2],data[3]); | 996 | format = Integer2Byte(data[2],data[3]); |
997 | xfrec = GetFormatting(format); | 997 | xfrec = GetFormatting(format); |
998 | /*int idx; | 998 | /*int idx; |
999 | idx=XFRecords.count()-1; | 999 | idx=XFRecords.count()-1; |
1000 | XFRecords[idx]->code=xfrec->code; | 1000 | XFRecords[idx]->code=xfrec->code; |
1001 | XFRecords[idx]->type=xfrec->type; | 1001 | XFRecords[idx]->type=xfrec->type; |
1002 | XFRecords[idx]->format="manos"; | 1002 | XFRecords[idx]->format="manos"; |
1003 | //XFRecords[XFRecords.count()-1]=xfrec; | 1003 | //XFRecords[XFRecords.count()-1]=xfrec; |
1004 | printf("6\r\n");*/ | 1004 | printf("6\r\n");*/ |
1005 | }; | 1005 | }; |
1006 | 1006 | ||
1007 | void ExcelBook::HandleXF(ExcelBREC* rec) | 1007 | void ExcelBook::HandleXF(ExcelBREC* rec) |
1008 | { | 1008 | { |
1009 | ExcelFormat* xfrec; | 1009 | ExcelFormat* xfrec; |
1010 | char* data; | 1010 | char* data; |
1011 | int format; | 1011 | int format; |
1012 | data = GetDataOfBREC(rec); | 1012 | data = GetDataOfBREC(rec); |
1013 | format = Integer2Byte(data[2],data[3]); | 1013 | format = Integer2Byte(data[2],data[3]); |
1014 | xfrec = GetFormatting(format); | 1014 | xfrec = GetFormatting(format); |
1015 | XFRecords.resize(XFRecords.count()+1); | 1015 | XFRecords.resize(XFRecords.count()+1); |
1016 | XFRecords[XFRecords.count()-1]=xfrec; | 1016 | XFRecords[XFRecords.count()-1]=xfrec; |
1017 | }; | 1017 | }; |
1018 | 1018 | ||
1019 | 1019 | ||
1020 | 1020 | ||
1021 | void ExcelBook::HandleRK(ExcelSheet* sheet, ExcelBREC* record) | 1021 | void ExcelBook::HandleRK(ExcelSheet* sheet, ExcelBREC* record) |
1022 | { | 1022 | { |
1023 | int xfindex, row, col; | 1023 | int xfindex, row, col; |
1024 | char* data; | 1024 | char* data; |
1025 | double d; | 1025 | double d; |
1026 | data = GetDataOfBREC(record); | 1026 | data = GetDataOfBREC(record); |
1027 | row = Integer2Byte(data[0], data[1]); | 1027 | row = Integer2Byte(data[0], data[1]); |
1028 | col = Integer2Byte(data[2], data[3]); | 1028 | col = Integer2Byte(data[2], data[3]); |
1029 | xfindex = Integer2Byte(data[4], data[5]); | 1029 | xfindex = Integer2Byte(data[4], data[5]); |
1030 | d=Double4Byte(data[6], data[7], data[8], data[9]); | 1030 | d=Double4Byte(data[6], data[7], data[8], data[9]); |
1031 | sheet->Set(row,col,CellNumber(row,col,xfindex,d)); | 1031 | sheet->Set(row,col,CellNumber(row,col,xfindex,d)); |
1032 | //printf("handleRK:row=%d,col=%d,val=%f\r\n",row,col,d); | 1032 | //printf("handleRK:row=%d,col=%d,val=%f\r\n",row,col,d); |
1033 | }; | 1033 | }; |
1034 | 1034 | ||
1035 | 1035 | ||
1036 | void ExcelBook::HandleFormula(ExcelSheet* sheet, ExcelBREC* record) | 1036 | void ExcelBook::HandleFormula(ExcelSheet* sheet, ExcelBREC* record) |
1037 | { | 1037 | { |
1038 | int xfindex, row, col; | 1038 | int xfindex, row, col; |
1039 | char* data; | 1039 | char* data; |
1040 | double d; | 1040 | double d; |
1041 | data = GetDataOfBREC(record); | 1041 | data = GetDataOfBREC(record); |
1042 | row = Integer2Byte(data[0], data[1]); | 1042 | row = Integer2Byte(data[0], data[1]); |
1043 | col = Integer2Byte(data[2], data[3]); | 1043 | col = Integer2Byte(data[2], data[3]); |
1044 | if (data[6] == 0 && data[12] == -1 && data[13] == -1) | 1044 | if (data[6] == 0 && data[12] == -1 && data[13] == -1) |
1045 | { | 1045 | { |
1046 | // string | 1046 | // string |
1047 | } | 1047 | } |
1048 | else | 1048 | else |
1049 | if (data[6] == 1 && data[12] == -1 && data[13] == -1) | 1049 | if (data[6] == 1 && data[12] == -1 && data[13] == -1) |
1050 | { | 1050 | { |
1051 | // boolean | 1051 | // boolean |
1052 | } | 1052 | } |
1053 | else | 1053 | else |
1054 | if ( data[6] == 2 && data[12] == -1 && data[13] == -1) | 1054 | if ( data[6] == 2 && data[12] == -1 && data[13] == -1) |
1055 | { | 1055 | { |
1056 | // error | 1056 | // error |
1057 | } | 1057 | } |
1058 | else | 1058 | else |
1059 | { | 1059 | { |
1060 | // number | 1060 | // number |
1061 | xfindex = Integer2Byte(data[4], data[5]); | 1061 | xfindex = Integer2Byte(data[4], data[5]); |
1062 | d=Double8Byte(data[6], data[7], data[8], data[9],data[10], data[11], data[12], data[13]); | 1062 | d=Double8Byte(data[6], data[7], data[8], data[9],data[10], data[11], data[12], data[13]); |
1063 | QString s1; | 1063 | QString s1; |
1064 | int sz; | 1064 | int sz; |
1065 | sz=Integer2Byte(data[20],data[21]);// size of the formula | 1065 | sz=Integer2Byte(data[20],data[21]);// size of the formula |
1066 | char* formuladata; | 1066 | char* formuladata; |
1067 | formuladata=new char[sz]; | 1067 | formuladata=new char[sz]; |
1068 | for(int w1=0;w1<sz;w1++) | 1068 | for(int w1=0;w1<sz;w1++) |
1069 | { | 1069 | { |
1070 | formuladata[w1]=data[22+w1]; | 1070 | formuladata[w1]=data[22+w1]; |
1071 | }; | 1071 | }; |
1072 | //22 is the first 0 idx of formula data | 1072 | //22 is the first 0 idx of formula data |
1073 | s1="="+GetFormula(row,col,sheet,formuladata,sz); | 1073 | s1="="+GetFormula(row,col,sheet,formuladata,sz); |
1074 | //printf("GetFormula:Formula=%s\r\n",s1.ascii()); | 1074 | //printf("GetFormula:Formula=%s\r\n",s1.ascii()); |
1075 | sheet->Set(row,col,CellLabel(row,col,s1)); | 1075 | sheet->Set(row,col,CellLabel(row,col,s1)); |
1076 | } | 1076 | } |
1077 | }; | 1077 | }; |
1078 | 1078 | ||
1079 | 1079 | ||
1080 | QString ExcelBook::GetFormula(int row, int col, ExcelSheet* sheet, char* data, int sz) | 1080 | QString ExcelBook::GetFormula(int row, int col, ExcelSheet* sheet, char* data, int sz) |
1081 | { | 1081 | { |
1082 | int length=sz; | 1082 | int length=sz; |
1083 | printf("{FormulaParser}\r\n"); | 1083 | printf("{FormulaParser}\r\n"); |
1084 | printf("row=%d, col=%d, length=%d\r\n",row,col,length); | 1084 | printf("row=%d, col=%d, length=%d\r\n",row,col,length); |
1085 | int idx=0; | 1085 | int idx=0; |
1086 | int w1,w2,w3,w4; | 1086 | int w1,w2,w3,w4; |
1087 | double d1; | 1087 | double d1; |
1088 | int token; | 1088 | int token; |
1089 | QString s1; | 1089 | QString s1; |
1090 | QList <QString> operands; | 1090 | QList <QString> operands; |
1091 | operands.setAutoDelete(TRUE); | 1091 | operands.setAutoDelete(TRUE); |
1092 | QString formula; | 1092 | QString formula; |
1093 | operands.clear(); | 1093 | operands.clear(); |
1094 | while( idx<length ) | 1094 | while( idx<length ) |
1095 | { | 1095 | { |
1096 | token= data[idx]; idx++; | 1096 | token= data[idx]; idx++; |
1097 | switch(token) | 1097 | switch(token) |
1098 | { | 1098 | { |
1099 | case 0x1E: //prtInt | 1099 | case 0x1E: //prtInt |
1100 | w1=Integer2Byte(data[idx],data[idx+1]); | 1100 | w1=Integer2Byte(data[idx],data[idx+1]); |
1101 | idx=idx+2; | 1101 | idx=idx+2; |
1102 | operands.prepend(new QString(QString::number(w1))); | 1102 | operands.prepend(new QString(QString::number(w1))); |
1103 | printf(" token:ptgInt,num=%d\r\n",w1); | 1103 | printf(" token:ptgInt,num=%d\r\n",w1); |
1104 | break; | 1104 | break; |
1105 | case 0x1F: //ptgNumber | 1105 | case 0x1F: //ptgNumber |
1106 | #if defined(__arm__) && !defined(__vfp__) | 1106 | #if defined(__arm__) && !defined(__vfp__) |
1107 | d1=Double8Byte(data[idx+4],data[idx+5],data[idx+6],data[idx+7] | 1107 | d1=Double8Byte(data[idx+4],data[idx+5],data[idx+6],data[idx+7] |
1108 | ,data[idx],data[idx+1],data[idx+2],data[idx+3]); | 1108 | ,data[idx],data[idx+1],data[idx+2],data[idx+3]); |
1109 | #else | 1109 | #else |
1110 | d1=Double8Byte(data[idx],data[idx+1],data[idx+2],data[idx+3] | 1110 | d1=Double8Byte(data[idx],data[idx+1],data[idx+2],data[idx+3] |
1111 | ,data[idx+4],data[idx+5],data[idx+6],data[idx+7]); | 1111 | ,data[idx+4],data[idx+5],data[idx+6],data[idx+7]); |
1112 | #endif | 1112 | #endif |
1113 | idx=idx+8; | 1113 | idx=idx+8; |
1114 | operands.prepend(new QString(QString::number(d1))); | 1114 | operands.prepend(new QString(QString::number(d1))); |
1115 | printf(" token:ptgNumber,num=%f\r\n",d1); | 1115 | printf(" token:ptgNumber,num=%f\r\n",d1); |
1116 | break; | 1116 | break; |
1117 | case 0x17: //ptgStr | 1117 | case 0x17: //ptgStr |
1118 | if(Version==8) | 1118 | if(Version==8) |
1119 | { | 1119 | { |
1120 | //unicode string | 1120 | //unicode string |
1121 | //w1=Integer2Byte(data[idx],data[idx+1]);idx+=2; | 1121 | //w1=Integer2Byte(data[idx],data[idx+1]);idx+=2; |
1122 | w1=data[idx];idx++; | 1122 | w1=data[idx];idx++; |
1123 | printf("len=%d\r\n",w1); | 1123 | printf("len=%d\r\n",w1); |
1124 | int richruns=0; int fareastsize=0; | 1124 | int richruns=0; int fareastsize=0; |
1125 | int richstring,fareaststring; | 1125 | int richstring,fareaststring; |
1126 | int options = data[idx];idx++; | 1126 | int options = data[idx];idx++; |
1127 | fareaststring = ((options & 0x04) != 0); | 1127 | fareaststring = ((options & 0x04) != 0); |
1128 | richstring = ((options & 0x08) != 0); | 1128 | richstring = ((options & 0x08) != 0); |
1129 | if(richstring) | 1129 | if(richstring) |
1130 | { | 1130 | { |
1131 | //containts rich string formatting. | 1131 | //containts rich string formatting. |
1132 | printf("STRING:richstring\r\n"); | 1132 | printf("STRING:richstring\r\n"); |
1133 | richruns= Integer2Byte(data[idx],data[idx+1]); | 1133 | richruns= Integer2Byte(data[idx],data[idx+1]); |
1134 | printf("richruns:%d\r\n",richruns); | 1134 | printf("richruns:%d\r\n",richruns); |
1135 | idx+=2; | 1135 | idx+=2; |
1136 | }; | 1136 | }; |
1137 | if(fareaststring) | 1137 | if(fareaststring) |
1138 | { | 1138 | { |
1139 | //contains far east formatting | 1139 | //contains far east formatting |
1140 | printf("STRING:fareast!\r\n"); | 1140 | printf("STRING:fareast!\r\n"); |
1141 | fareastsize=Integer4Byte(data[idx], data[idx+1], | 1141 | fareastsize=Integer4Byte(data[idx], data[idx+1], |
1142 | data[idx+2], data[idx+3]); | 1142 | data[idx+2], data[idx+3]); |
1143 | printf("fareastsize=%d",fareastsize); | 1143 | printf("fareastsize=%d",fareastsize); |
1144 | idx+=4; | 1144 | idx+=4; |
1145 | }; | 1145 | }; |
1146 | if ((options & 0x01) == 0) //8 bit chars | 1146 | if ((options & 0x01) == 0) //8 bit chars |
1147 | { | 1147 | { |
1148 | /* ascii */ | 1148 | /* ascii */ |
1149 | s1 = GetASCII(data,idx,w1); | 1149 | s1 = GetASCII(data,idx,w1); |
1150 | idx=idx+w1; | 1150 | idx=idx+w1; |
1151 | printf("STRING:ASCII=%s\r\n",s1.ascii()); | 1151 | printf("STRING:ASCII=%s\r\n",s1.ascii()); |
1152 | }else //16 bit chars | 1152 | }else //16 bit chars |
1153 | { | 1153 | { |
1154 | /* unicode */ | 1154 | /* unicode */ |
1155 | s1 = GetUnicode(data,idx,w1); | 1155 | s1 = GetUnicode(data,idx,w1); |
1156 | idx=idx+w1*2; | 1156 | idx=idx+w1*2; |
1157 | printf("STRING:unicode=%s\r\n",s1.ascii()); | 1157 | printf("STRING:unicode=%s\r\n",s1.ascii()); |
1158 | }; | 1158 | }; |
1159 | // HERE TO PUT richformat handling | 1159 | // HERE TO PUT richformat handling |
1160 | if (richstring) | 1160 | if (richstring) |
1161 | { | 1161 | { |
1162 | idx += 4 * richruns; | 1162 | idx += 4 * richruns; |
1163 | }; | 1163 | }; |
1164 | if (fareaststring) | 1164 | if (fareaststring) |
1165 | { | 1165 | { |
1166 | idx += fareastsize; | 1166 | idx += fareastsize; |
1167 | }; | 1167 | }; |
1168 | s1=QString("""")+s1+QString(""""); | 1168 | s1=QString("""")+s1+QString(""""); |
1169 | operands.prepend(new QString(s1)); | 1169 | operands.prepend(new QString(s1)); |
1170 | } | 1170 | } |
1171 | else | 1171 | else |
1172 | { | 1172 | { |
1173 | w1=data[idx];idx++; | 1173 | w1=data[idx];idx++; |
1174 | s1=GetASCII(data,idx,w1); | 1174 | s1=GetASCII(data,idx,w1); |
1175 | s1=QString("""")+s1+QString(""""); | 1175 | s1=QString("""")+s1+QString(""""); |
1176 | idx=idx+w1; | 1176 | idx=idx+w1; |
1177 | operands.prepend(new QString(s1)); | 1177 | operands.prepend(new QString(s1)); |
1178 | }; | 1178 | }; |
1179 | printf(" token:ptgStr,num=%d\r\n",w1); | 1179 | printf(" token:ptgStr,num=%d\r\n",w1); |
1180 | break; | 1180 | break; |
1181 | case 0x25: | 1181 | case 0x25: |
1182 | case 0x45: | 1182 | case 0x45: |
1183 | case 0x65: // ptgArea | 1183 | case 0x65: // ptgArea |
1184 | if(Version==8) | 1184 | if(Version==8) |
1185 | { | 1185 | { |
1186 | w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//row1 | 1186 | w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//row1 |
1187 | w2=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//row2 | 1187 | w2=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//row2 |
1188 | w3=Integer2Byte(data[idx],data[idx+1]) & 0x00FF;idx=idx+2;//col1 | 1188 | w3=Integer2Byte(data[idx],data[idx+1]) & 0x00FF;idx=idx+2;//col1 |
1189 | w4=Integer2Byte(data[idx],data[idx+1]) & 0x00FF;idx=idx+2;//col2 | 1189 | w4=Integer2Byte(data[idx],data[idx+1]) & 0x00FF;idx=idx+2;//col2 |
1190 | } | 1190 | } |
1191 | else | 1191 | else |
1192 | { | 1192 | { |
1193 | w1=Integer2Byte(data[idx],data[idx+1]) & 0x3FFF;idx=idx+2;//row1 | 1193 | w1=Integer2Byte(data[idx],data[idx+1]) & 0x3FFF;idx=idx+2;//row1 |
1194 | w2=Integer2Byte(data[idx],data[idx+1]) & 0x3FFF;idx=idx+2;//row2 | 1194 | w2=Integer2Byte(data[idx],data[idx+1]) & 0x3FFF;idx=idx+2;//row2 |
1195 | w3=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//col1 | 1195 | w3=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//col1 |
1196 | w4=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//col2 | 1196 | w4=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//col2 |
1197 | }; | 1197 | }; |
1198 | //ignores relative or absolute refs | 1198 | //ignores relative or absolute refs |
1199 | s1=FindCellName(w1,w3)+":"+FindCellName(w2,w4); | 1199 | s1=FindCellName(w1,w3)+":"+FindCellName(w2,w4); |
1200 | printf(" token:ptgArea,ref=%s\r\n",s1.ascii()); | 1200 | printf(" token:ptgArea,ref=%s\r\n",s1.ascii()); |
1201 | operands.prepend(new QString(s1)); | 1201 | operands.prepend(new QString(s1)); |
1202 | break; | 1202 | break; |
1203 | case 0x24: | 1203 | case 0x24: |
1204 | case 0x44: | 1204 | case 0x44: |
1205 | case 0x64://ptgRef | 1205 | case 0x64://ptgRef |
1206 | if(Version==8) | 1206 | if(Version==8) |
1207 | { | 1207 | { |
1208 | w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//row | 1208 | w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//row |
1209 | w2=Integer2Byte(data[idx],data[idx+1]) & 0x00FF;idx=idx+2;//col | 1209 | w2=Integer2Byte(data[idx],data[idx+1]) & 0x00FF;idx=idx+2;//col |
1210 | } | 1210 | } |
1211 | else | 1211 | else |
1212 | { | 1212 | { |
1213 | w1=Integer2Byte(data[idx],data[idx+1]) & 0x3FFF;idx=idx+2;//row | 1213 | w1=Integer2Byte(data[idx],data[idx+1]) & 0x3FFF;idx=idx+2;//row |
1214 | w2=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//col | 1214 | w2=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//col |
1215 | }; | 1215 | }; |
1216 | s1=FindCellName(w1,w2); | 1216 | s1=FindCellName(w1,w2); |
1217 | printf("token:ptgRef,ref=%s\r\n",s1.ascii()); | 1217 | printf("token:ptgRef,ref=%s\r\n",s1.ascii()); |
1218 | operands.prepend(new QString(s1)); | 1218 | operands.prepend(new QString(s1)); |
1219 | break; | 1219 | break; |
1220 | case 0x1D: // ptgBool | 1220 | case 0x1D: // ptgBool |
1221 | w1=data[idx];idx++; | 1221 | w1=data[idx];idx++; |
1222 | printf("token:ptgBool,val=%d\r\n",w1); | 1222 | printf("token:ptgBool,val=%d\r\n",w1); |
1223 | operands.prepend(new QString(QString::number(w1))); | 1223 | operands.prepend(new QString(QString::number(w1))); |
1224 | break; | 1224 | break; |
1225 | case 0x16://ptg MissArg | 1225 | case 0x16://ptg MissArg |
1226 | printf("token:ptgMissArg, val=' '\r\n"); | 1226 | printf("token:ptgMissArg, val=' '\r\n"); |
1227 | operands.prepend(new QString("0")); | 1227 | operands.prepend(new QString("0")); |
1228 | break; | 1228 | break; |
1229 | case 0x12://ptgUplus== | 1229 | case 0x12://ptgUplus== |
1230 | printf("token:ptgUplus\r\n"); | 1230 | printf("token:ptgUplus\r\n"); |
1231 | s1=QString("+")+operands.first()->ascii(); | 1231 | s1=QString("+")+operands.first()->ascii(); |
1232 | operands.removeFirst(); | 1232 | operands.removeFirst(); |
1233 | operands.prepend(new QString(s1)); | 1233 | operands.prepend(new QString(s1)); |
1234 | break; | 1234 | break; |
1235 | case 0x13://ptgUminus | 1235 | case 0x13://ptgUminus |
1236 | printf("token:ptgUminus\r\n"); | 1236 | printf("token:ptgUminus\r\n"); |
1237 | s1=QString("-")+operands.first()->ascii(); | 1237 | s1=QString("-")+operands.first()->ascii(); |
1238 | operands.removeFirst(); | 1238 | operands.removeFirst(); |
1239 | operands.prepend(new QString(s1)); | 1239 | operands.prepend(new QString(s1)); |
1240 | break; | 1240 | break; |
1241 | case 0x03://ptgAdd | 1241 | case 0x03://ptgAdd |
1242 | printf("token:ptgAdd\r\n"); | 1242 | printf("token:ptgAdd\r\n"); |
1243 | operands.first(); | 1243 | operands.first(); |
1244 | s1=operands.next()->ascii() | 1244 | s1=operands.next()->ascii() |
1245 | +QString("+")+operands.first()->ascii(); | 1245 | +QString("+")+operands.first()->ascii(); |
1246 | operands.removeFirst();operands.removeFirst(); | 1246 | operands.removeFirst();operands.removeFirst(); |
1247 | operands.prepend(new QString(s1)); | 1247 | operands.prepend(new QString(s1)); |
1248 | break; | 1248 | break; |
1249 | case 0x04://ptgSub | 1249 | case 0x04://ptgSub |
1250 | printf("token:ptgSub\r\n"); | 1250 | printf("token:ptgSub\r\n"); |
1251 | operands.first(); | 1251 | operands.first(); |
1252 | s1=operands.next()->ascii() | 1252 | s1=operands.next()->ascii() |
1253 | +QString("-")+operands.first()->ascii(); | 1253 | +QString("-")+operands.first()->ascii(); |
1254 | operands.removeFirst();operands.removeFirst(); | 1254 | operands.removeFirst();operands.removeFirst(); |
1255 | operands.prepend(new QString(s1)); | 1255 | operands.prepend(new QString(s1)); |
1256 | break; | 1256 | break; |
1257 | case 0x05://ptgMul | 1257 | case 0x05://ptgMul |
1258 | printf("token:ptgMul\r\n"); | 1258 | printf("token:ptgMul\r\n"); |
1259 | operands.first(); | 1259 | operands.first(); |
1260 | s1=operands.next()->ascii() | 1260 | s1=operands.next()->ascii() |
1261 | +QString("*")+operands.first()->ascii(); | 1261 | +QString("*")+operands.first()->ascii(); |
1262 | operands.removeFirst();operands.removeFirst(); | 1262 | operands.removeFirst();operands.removeFirst(); |
1263 | operands.prepend(new QString(s1)); | 1263 | operands.prepend(new QString(s1)); |
1264 | break; | 1264 | break; |
1265 | case 0x06://ptgDiv | 1265 | case 0x06://ptgDiv |
1266 | printf("token:ptgDiv\r\n"); | 1266 | printf("token:ptgDiv\r\n"); |
1267 | operands.first(); | 1267 | operands.first(); |
1268 | s1=operands.next()->ascii() | 1268 | s1=operands.next()->ascii() |
1269 | +QString("/")+operands.first()->ascii(); | 1269 | +QString("/")+operands.first()->ascii(); |
1270 | operands.removeFirst();operands.removeFirst(); | 1270 | operands.removeFirst();operands.removeFirst(); |
1271 | operands.prepend(new QString(s1)); | 1271 | operands.prepend(new QString(s1)); |
1272 | break; | 1272 | break; |
1273 | case 0x07://ptgPOWER | 1273 | case 0x07://ptgPOWER |
1274 | printf("token:ptgPow\r\n"); | 1274 | printf("token:ptgPow\r\n"); |
1275 | operands.first(); | 1275 | operands.first(); |
1276 | s1=QString("POWER(")+operands.next()->ascii() | 1276 | s1=QString("POWER(")+operands.next()->ascii() |
1277 | +QString(",")+operands.first()->ascii()+QString(")"); | 1277 | +QString(",")+operands.first()->ascii()+QString(")"); |
1278 | operands.removeFirst();operands.removeFirst(); | 1278 | operands.removeFirst();operands.removeFirst(); |
1279 | operands.prepend(new QString(s1)); | 1279 | operands.prepend(new QString(s1)); |
1280 | break; | 1280 | break; |
1281 | case 0x08://ptgConcat | 1281 | case 0x08://ptgConcat |
1282 | printf("token:ptgConcat\r\n"); | 1282 | printf("token:ptgConcat\r\n"); |
1283 | operands.first(); | 1283 | operands.first(); |
1284 | s1=QString("CONCATENATE(")+operands.next()->ascii() | 1284 | s1=QString("CONCATENATE(")+operands.next()->ascii() |
1285 | +QString(",")+operands.first()->ascii()+QString(")"); | 1285 | +QString(",")+operands.first()->ascii()+QString(")"); |
1286 | operands.removeFirst();operands.removeFirst(); | 1286 | operands.removeFirst();operands.removeFirst(); |
1287 | operands.prepend(new QString(s1)); | 1287 | operands.prepend(new QString(s1)); |
1288 | break; | 1288 | break; |
1289 | case 0x15://ptgParenthesis | 1289 | case 0x15://ptgParenthesis |
1290 | printf("token:ptgParenthesis\r\n"); | 1290 | printf("token:ptgParenthesis\r\n"); |
1291 | s1=QString("(")+operands.first()->ascii()+QString(")"); | 1291 | s1=QString("(")+operands.first()->ascii()+QString(")"); |
1292 | operands.removeFirst(); | 1292 | operands.removeFirst(); |
1293 | operands.prepend(new QString(s1)); | 1293 | operands.prepend(new QString(s1)); |
1294 | break; | 1294 | break; |
1295 | case 0x14://ptgPercent | 1295 | case 0x14://ptgPercent |
1296 | printf("token:ptgPercent\r\n"); | 1296 | printf("token:ptgPercent\r\n"); |
1297 | s1=operands.first()->ascii()+QString("*0.01"); | 1297 | s1=operands.first()->ascii()+QString("*0.01"); |
1298 | operands.removeFirst(); | 1298 | operands.removeFirst(); |
1299 | operands.prepend(new QString(s1)); | 1299 | operands.prepend(new QString(s1)); |
1300 | break; | 1300 | break; |
1301 | case 0x9://ptgLessThan | 1301 | case 0x9://ptgLessThan |
1302 | printf("token:ptgLESS\r\n"); | 1302 | printf("token:ptgLESS\r\n"); |
1303 | operands.first(); | 1303 | operands.first(); |
1304 | s1=operands.next()->ascii() | 1304 | s1=operands.next()->ascii() |
1305 | +QString("<")+operands.first()->ascii(); | 1305 | +QString("<")+operands.first()->ascii(); |
1306 | operands.removeFirst();operands.removeFirst(); | 1306 | operands.removeFirst();operands.removeFirst(); |
1307 | operands.prepend(new QString(s1)); | 1307 | operands.prepend(new QString(s1)); |
1308 | break; | 1308 | break; |
1309 | case 0xa://ptgLessEqual | 1309 | case 0xa://ptgLessEqual |
1310 | printf("token:ptgLESS_EQUAL\r\n"); | 1310 | printf("token:ptgLESS_EQUAL\r\n"); |
1311 | operands.first(); | 1311 | operands.first(); |
1312 | s1=operands.next()->ascii() | 1312 | s1=operands.next()->ascii() |
1313 | +QString("<=")+operands.first()->ascii(); | 1313 | +QString("<=")+operands.first()->ascii(); |
1314 | operands.removeFirst();operands.removeFirst(); | 1314 | operands.removeFirst();operands.removeFirst(); |
1315 | operands.prepend(new QString(s1)); | 1315 | operands.prepend(new QString(s1)); |
1316 | break; | 1316 | break; |
1317 | case 0xb://ptgEQUAL | 1317 | case 0xb://ptgEQUAL |
1318 | printf("token:ptgEQUAL\r\n"); | 1318 | printf("token:ptgEQUAL\r\n"); |
1319 | operands.first(); | 1319 | operands.first(); |
1320 | s1=operands.next()->ascii() | 1320 | s1=operands.next()->ascii() |
1321 | +QString("==")+operands.first()->ascii(); | 1321 | +QString("==")+operands.first()->ascii(); |
1322 | operands.removeFirst();operands.removeFirst(); | 1322 | operands.removeFirst();operands.removeFirst(); |
1323 | operands.prepend(new QString(s1)); | 1323 | operands.prepend(new QString(s1)); |
1324 | break; | 1324 | break; |
1325 | case 0xc://ptgGREATER_EQUAL | 1325 | case 0xc://ptgGREATER_EQUAL |
1326 | printf("token:ptgGREAT_EQUAL\r\n"); | 1326 | printf("token:ptgGREAT_EQUAL\r\n"); |
1327 | operands.first(); | 1327 | operands.first(); |
1328 | s1=operands.next()->ascii() | 1328 | s1=operands.next()->ascii() |
1329 | +QString(">=")+operands.first()->ascii(); | 1329 | +QString(">=")+operands.first()->ascii(); |
1330 | operands.removeFirst();operands.removeFirst(); | 1330 | operands.removeFirst();operands.removeFirst(); |
1331 | operands.prepend(new QString(s1)); | 1331 | operands.prepend(new QString(s1)); |
1332 | break; | 1332 | break; |
1333 | case 0xd://ptgGREAT_THAN | 1333 | case 0xd://ptgGREAT_THAN |
1334 | printf("token:ptgGREAT_THAN\r\n"); | 1334 | printf("token:ptgGREAT_THAN\r\n"); |
1335 | operands.first(); | 1335 | operands.first(); |
1336 | s1=operands.next()->ascii() | 1336 | s1=operands.next()->ascii() |
1337 | +QString(">")+operands.first()->ascii(); | 1337 | +QString(">")+operands.first()->ascii(); |
1338 | operands.removeFirst();operands.removeFirst(); | 1338 | operands.removeFirst();operands.removeFirst(); |
1339 | operands.prepend(new QString(s1)); | 1339 | operands.prepend(new QString(s1)); |
1340 | break; | 1340 | break; |
1341 | case 0xe://ptgNOT_EQUAL | 1341 | case 0xe://ptgNOT_EQUAL |
1342 | printf("token:ptgNOTequal\r\n"); | 1342 | printf("token:ptgNOTequal\r\n"); |
1343 | operands.first(); | 1343 | operands.first(); |
1344 | s1=operands.next()->ascii() | 1344 | s1=operands.next()->ascii() |
1345 | +QString("!=")+operands.first()->ascii(); | 1345 | +QString("!=")+operands.first()->ascii(); |
1346 | operands.removeFirst();operands.removeFirst(); | 1346 | operands.removeFirst();operands.removeFirst(); |
1347 | operands.prepend(new QString(s1)); | 1347 | operands.prepend(new QString(s1)); |
1348 | break; | 1348 | break; |
1349 | case 0x19://attribute can be Sum,If,Choose | 1349 | case 0x19://attribute can be Sum,If,Choose |
1350 | w3=Integer2Byte(data[idx],data[idx+1]);idx=idx+2; | 1350 | w3=Integer2Byte(data[idx],data[idx+1]);idx=idx+2; |
1351 | idx++; | 1351 | idx++; |
1352 | printf("token:ATTRIBUTE:0x%x\r\n",w3); | 1352 | printf("token:ATTRIBUTE:0x%x\r\n",w3); |
1353 | for(w4=idx;w4<length;w4++) | 1353 | for(w4=idx;w4<length;w4++) |
1354 | printf("0x%x, ",data[w4]); | 1354 | printf("0x%x, ",data[w4]); |
1355 | if(w3&0x01)//choose | 1355 | if(w3&0x01)//choose |
1356 | { | 1356 | { |
1357 | printf("token:CHOOSE\r\n"); | 1357 | printf("token:CHOOSE\r\n"); |
1358 | } | 1358 | } |
1359 | else if(w3&0x02)//if | 1359 | else if(w3&0x02)//if |
1360 | { | 1360 | { |
1361 | printf("token:IF\r\n"); | 1361 | printf("token:IF\r\n"); |
1362 | } | 1362 | } |
1363 | else if(w3&0x10)//sum | 1363 | else if(w3&0x10)//sum |
1364 | { | 1364 | { |
1365 | printf("token:SUM\r\n"); | 1365 | printf("token:SUM\r\n"); |
1366 | }; | 1366 | }; |
1367 | 1367 | ||
1368 | break; | 1368 | break; |
1369 | 1369 | ||
1370 | 1370 | ||
1371 | case 0x21: | 1371 | case 0x21: |
1372 | case 0x22: | 1372 | case 0x22: |
1373 | case 0x42: | 1373 | case 0x42: |
1374 | case 0x62: | 1374 | case 0x62: |
1375 | case 0x41: | 1375 | case 0x41: |
1376 | case 0x61://ptgFunction | 1376 | case 0x61://ptgFunction |
1377 | printf("token:ptgFunction\r\n"); | 1377 | printf("token:ptgFunction\r\n"); |
1378 | if(token==0x22||token==0x42||token==0x62) | 1378 | if(token==0x22||token==0x42||token==0x62) |
1379 | { | 1379 | { |
1380 | w2=(int)data[idx];idx++; | 1380 | w2=(int)data[idx];idx++; |
1381 | w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2; | 1381 | w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2; |
1382 | } | 1382 | } |
1383 | else | 1383 | else |
1384 | { | 1384 | { |
1385 | w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2; | 1385 | w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2; |
1386 | }; | 1386 | }; |
1387 | switch(w1) | 1387 | switch(w1) |
1388 | { | 1388 | { |
1389 | case 0xf://SIN | 1389 | case 0xf://SIN |
1390 | s1=QString("SIN(")+operands.first()->ascii()+QString(")"); | 1390 | s1=QString("SIN(")+operands.first()->ascii()+QString(")"); |
1391 | operands.removeFirst(); | 1391 | operands.removeFirst(); |
1392 | operands.prepend(new QString(s1)); | 1392 | operands.prepend(new QString(s1)); |
1393 | break; | 1393 | break; |
1394 | case 0x10://COS | 1394 | case 0x10://COS |
1395 | s1=QString("COS(")+operands.first()->ascii()+QString(")"); | 1395 | s1=QString("COS(")+operands.first()->ascii()+QString(")"); |
1396 | operands.removeFirst(); | 1396 | operands.removeFirst(); |
1397 | operands.prepend(new QString(s1)); | 1397 | operands.prepend(new QString(s1)); |
1398 | break; | 1398 | break; |
1399 | case 0x11://tan | 1399 | case 0x11://tan |
1400 | s1=QString("TAN(")+operands.first()->ascii()+QString(")"); | 1400 | s1=QString("TAN(")+operands.first()->ascii()+QString(")"); |
1401 | operands.removeFirst(); | 1401 | operands.removeFirst(); |
1402 | operands.prepend(new QString(s1)); | 1402 | operands.prepend(new QString(s1)); |
1403 | break; | 1403 | break; |
1404 | case 0x62://asin | 1404 | case 0x62://asin |
1405 | s1=QString("ASIN(")+operands.first()->ascii()+QString(")"); | 1405 | s1=QString("ASIN(")+operands.first()->ascii()+QString(")"); |
1406 | operands.removeFirst(); | 1406 | operands.removeFirst(); |
1407 | operands.prepend(new QString(s1)); | 1407 | operands.prepend(new QString(s1)); |
1408 | break; | 1408 | break; |
1409 | case 0x63://ACOS | 1409 | case 0x63://ACOS |
1410 | s1=QString("ACOS(")+operands.first()->ascii()+QString(")"); | 1410 | s1=QString("ACOS(")+operands.first()->ascii()+QString(")"); |
1411 | operands.removeFirst(); | 1411 | operands.removeFirst(); |
1412 | operands.prepend(new QString(s1)); | 1412 | operands.prepend(new QString(s1)); |
1413 | break; | 1413 | break; |
1414 | case 0x12://ATAN | 1414 | case 0x12://ATAN |
1415 | s1=QString("ATAN(")+operands.first()->ascii()+QString(")"); | 1415 | s1=QString("ATAN(")+operands.first()->ascii()+QString(")"); |
1416 | operands.removeFirst(); | 1416 | operands.removeFirst(); |
1417 | operands.prepend(new QString(s1)); | 1417 | operands.prepend(new QString(s1)); |
1418 | break; | 1418 | break; |
1419 | case 0xe5://SINH | 1419 | case 0xe5://SINH |
1420 | s1=QString("SINH(")+operands.first()->ascii()+QString(")"); | 1420 | s1=QString("SINH(")+operands.first()->ascii()+QString(")"); |
1421 | operands.removeFirst(); | 1421 | operands.removeFirst(); |
1422 | operands.prepend(new QString(s1)); | 1422 | operands.prepend(new QString(s1)); |
1423 | break; | 1423 | break; |
1424 | case 0xe6://COSH | 1424 | case 0xe6://COSH |
1425 | s1=QString("COSH(")+operands.first()->ascii()+QString(")"); | 1425 | s1=QString("COSH(")+operands.first()->ascii()+QString(")"); |
1426 | operands.removeFirst(); | 1426 | operands.removeFirst(); |
1427 | operands.prepend(new QString(s1)); | 1427 | operands.prepend(new QString(s1)); |
1428 | break; | 1428 | break; |
1429 | case 0xe7://TANH | 1429 | case 0xe7://TANH |
1430 | s1=QString("TANH(")+operands.first()->ascii()+QString(")"); | 1430 | s1=QString("TANH(")+operands.first()->ascii()+QString(")"); |
1431 | operands.removeFirst(); | 1431 | operands.removeFirst(); |
1432 | operands.prepend(new QString(s1)); | 1432 | operands.prepend(new QString(s1)); |
1433 | break; | 1433 | break; |
1434 | case 0xe8://ASINH | 1434 | case 0xe8://ASINH |
1435 | s1=QString("ASINH(")+operands.first()->ascii()+QString(")"); | 1435 | s1=QString("ASINH(")+operands.first()->ascii()+QString(")"); |
1436 | operands.removeFirst(); | 1436 | operands.removeFirst(); |
1437 | operands.prepend(new QString(s1)); | 1437 | operands.prepend(new QString(s1)); |
1438 | break; | 1438 | break; |
1439 | case 0xe9://ACOSH | 1439 | case 0xe9://ACOSH |
1440 | s1=QString("ACOSH(")+operands.first()->ascii()+QString(")"); | 1440 | s1=QString("ACOSH(")+operands.first()->ascii()+QString(")"); |
1441 | operands.removeFirst(); | 1441 | operands.removeFirst(); |
1442 | operands.prepend(new QString(s1)); | 1442 | operands.prepend(new QString(s1)); |
1443 | break; | 1443 | break; |
1444 | case 0xea://ATANH | 1444 | case 0xea://ATANH |
1445 | s1=QString("ATANH(")+operands.first()->ascii()+QString(")"); | 1445 | s1=QString("ATANH(")+operands.first()->ascii()+QString(")"); |
1446 | operands.removeFirst(); | 1446 | operands.removeFirst(); |
1447 | operands.prepend(new QString(s1)); | 1447 | operands.prepend(new QString(s1)); |
1448 | break; | 1448 | break; |
1449 | case 0x13://pi | 1449 | case 0x13://pi |
1450 | s1="PI()"; | 1450 | s1="PI()"; |
1451 | operands.prepend(new QString(s1)); | 1451 | operands.prepend(new QString(s1)); |
1452 | break; | 1452 | break; |
1453 | case 0x14://sqrt | 1453 | case 0x14://sqrt |
1454 | s1=QString("SQRT(")+operands.first()->ascii()+QString(")"); | 1454 | s1=QString("SQRT(")+operands.first()->ascii()+QString(")"); |
1455 | operands.removeFirst(); | 1455 | operands.removeFirst(); |
1456 | operands.prepend(new QString(s1)); | 1456 | operands.prepend(new QString(s1)); |
1457 | break; | 1457 | break; |
1458 | case 0x15://exp | 1458 | case 0x15://exp |
1459 | s1=QString("EXP(")+operands.first()->ascii()+QString(")"); | 1459 | s1=QString("EXP(")+operands.first()->ascii()+QString(")"); |
1460 | operands.removeFirst(); | 1460 | operands.removeFirst(); |
1461 | operands.prepend(new QString(s1)); | 1461 | operands.prepend(new QString(s1)); |
1462 | break; | 1462 | break; |
1463 | case 0x16://LN | 1463 | case 0x16://LN |
1464 | s1=QString("LN(")+operands.first()->ascii()+QString(")"); | 1464 | s1=QString("LN(")+operands.first()->ascii()+QString(")"); |
1465 | operands.removeFirst(); | 1465 | operands.removeFirst(); |
1466 | operands.prepend(new QString(s1)); | 1466 | operands.prepend(new QString(s1)); |
1467 | break; | 1467 | break; |
1468 | case 0x17://LOG10 | 1468 | case 0x17://LOG10 |
1469 | s1=QString("LOG10(")+operands.first()->ascii()+QString(")"); | 1469 | s1=QString("LOG10(")+operands.first()->ascii()+QString(")"); |
1470 | operands.removeFirst(); | 1470 | operands.removeFirst(); |
1471 | operands.prepend(new QString(s1)); | 1471 | operands.prepend(new QString(s1)); |
1472 | break; | 1472 | break; |
1473 | case 0x18://ABS | 1473 | case 0x18://ABS |
1474 | s1=QString("ABS(")+operands.first()->ascii()+QString(")"); | 1474 | s1=QString("ABS(")+operands.first()->ascii()+QString(")"); |
1475 | operands.removeFirst(); | 1475 | operands.removeFirst(); |
1476 | operands.prepend(new QString(s1)); | 1476 | operands.prepend(new QString(s1)); |
1477 | break; | 1477 | break; |
1478 | case 0x19://int | 1478 | case 0x19://int |
1479 | s1=QString("INT(")+operands.first()->ascii()+QString(")"); | 1479 | s1=QString("INT(")+operands.first()->ascii()+QString(")"); |
1480 | operands.removeFirst(); | 1480 | operands.removeFirst(); |
1481 | operands.prepend(new QString(s1)); | 1481 | operands.prepend(new QString(s1)); |
1482 | break; | 1482 | break; |
1483 | case 0x1a://sign | 1483 | case 0x1a://sign |
1484 | s1=QString("SIGN(")+operands.first()->ascii()+QString(")"); | 1484 | s1=QString("SIGN(")+operands.first()->ascii()+QString(")"); |
1485 | operands.removeFirst(); | 1485 | operands.removeFirst(); |
1486 | operands.prepend(new QString(s1)); | 1486 | operands.prepend(new QString(s1)); |
1487 | break; | 1487 | break; |
1488 | case 0x1b://round | 1488 | case 0x1b://round |
1489 | operands.first(); | 1489 | operands.first(); |
1490 | s1=QString("ROUND(")+operands.next()->ascii() | 1490 | s1=QString("ROUND(")+operands.next()->ascii() |
1491 | +QString(",")+operands.first()->ascii() | 1491 | +QString(",")+operands.first()->ascii() |
1492 | +QString(")"); | 1492 | +QString(")"); |
1493 | operands.removeFirst();operands.removeFirst(); | 1493 | operands.removeFirst();operands.removeFirst(); |
1494 | operands.prepend(new QString(s1)); | 1494 | operands.prepend(new QString(s1)); |
1495 | break; | 1495 | break; |
1496 | case 0x1d://index | 1496 | case 0x1d://index |
1497 | operands.first(); | 1497 | operands.first(); |
1498 | s1=QString("INDEX(")+operands.next()->ascii() | 1498 | s1=QString("INDEX(")+operands.next()->ascii() |
1499 | +QString(",") | 1499 | +QString(",") |
1500 | +operands.first()->ascii()+QString(")"); | 1500 | +operands.first()->ascii()+QString(")"); |
1501 | operands.removeFirst(); | 1501 | operands.removeFirst(); |
1502 | operands.removeFirst(); | 1502 | operands.removeFirst(); |
1503 | operands.prepend(new QString(s1)); | 1503 | operands.prepend(new QString(s1)); |
1504 | break; | 1504 | break; |
1505 | case 0x1: // if ATTRIBUTE | 1505 | case 0x1: // if ATTRIBUTE |
1506 | operands.first();operands.next(); | 1506 | operands.first();operands.next(); |
1507 | s1=QString("IF(")+operands.next()->ascii()+QString(","); | 1507 | s1=QString("IF(")+operands.next()->ascii()+QString(","); |
1508 | operands.first(); | 1508 | operands.first(); |
1509 | s1=s1+operands.next()->ascii()+QString(","); | 1509 | s1=s1+operands.next()->ascii()+QString(","); |
1510 | s1=s1+operands.first()->ascii()+QString(")"); | 1510 | s1=s1+operands.first()->ascii()+QString(")"); |
1511 | operands.removeFirst(); | 1511 | operands.removeFirst(); |
1512 | operands.removeFirst(); | 1512 | operands.removeFirst(); |
1513 | operands.removeFirst(); | 1513 | operands.removeFirst(); |
1514 | operands.prepend(new QString(s1)); | 1514 | operands.prepend(new QString(s1)); |
1515 | break; | 1515 | break; |
1516 | case 0x81://isblank | 1516 | case 0x81://isblank |
1517 | s1=QString("ISBLANK(")+operands.first()->ascii() | 1517 | s1=QString("ISBLANK(")+operands.first()->ascii() |
1518 | +QString(")"); | 1518 | +QString(")"); |
1519 | operands.removeFirst(); | 1519 | operands.removeFirst(); |
1520 | operands.prepend(new QString(s1)); | 1520 | operands.prepend(new QString(s1)); |
1521 | break; | 1521 | break; |
1522 | case 0x80://isnumber | 1522 | case 0x80://isnumber |
1523 | s1=QString("ISNUMBER(")+operands.first()->ascii() | 1523 | s1=QString("ISNUMBER(")+operands.first()->ascii() |
1524 | +QString(")"); | 1524 | +QString(")"); |
1525 | operands.removeFirst(); | 1525 | operands.removeFirst(); |
1526 | operands.prepend(new QString(s1)); | 1526 | operands.prepend(new QString(s1)); |
1527 | break; | 1527 | break; |
1528 | case 0x120://ceiling | 1528 | case 0x120://ceiling |
1529 | operands.first(); | 1529 | operands.first(); |
1530 | s1=QString("CEILING(")+operands.next()->ascii() | 1530 | s1=QString("CEILING(")+operands.next()->ascii() |
1531 | +QString(",")+operands.first()->ascii() | 1531 | +QString(",")+operands.first()->ascii() |
1532 | +QString(")"); | 1532 | +QString(")"); |
1533 | operands.removeFirst();operands.removeFirst(); | 1533 | operands.removeFirst();operands.removeFirst(); |
1534 | operands.prepend(new QString(s1)); | 1534 | operands.prepend(new QString(s1)); |
1535 | break; | 1535 | break; |
1536 | case 0x11d://floor | 1536 | case 0x11d://floor |
1537 | operands.first(); | 1537 | operands.first(); |
1538 | s1=QString("FLOOR(")+operands.next()->ascii() | 1538 | s1=QString("FLOOR(")+operands.next()->ascii() |
1539 | +QString(",")+operands.first()->ascii() | 1539 | +QString(",")+operands.first()->ascii() |
1540 | +QString(")"); | 1540 | +QString(")"); |
1541 | operands.removeFirst();operands.removeFirst(); | 1541 | operands.removeFirst();operands.removeFirst(); |
1542 | operands.prepend(new QString(s1)); | 1542 | operands.prepend(new QString(s1)); |
1543 | break; | 1543 | break; |
1544 | case 0x157://degrees | 1544 | case 0x157://degrees |
1545 | s1=QString("DEGREES(")+operands.first()->ascii() | 1545 | s1=QString("DEGREES(")+operands.first()->ascii() |
1546 | +QString(")"); | 1546 | +QString(")"); |
1547 | operands.removeFirst(); | 1547 | operands.removeFirst(); |
1548 | operands.prepend(new QString(s1)); | 1548 | operands.prepend(new QString(s1)); |
1549 | break; | 1549 | break; |
1550 | case 0x156://radians | 1550 | case 0x156://radians |
1551 | s1=QString("RADIANS(")+operands.first()->ascii() | 1551 | s1=QString("RADIANS(")+operands.first()->ascii() |
1552 | +QString(")"); | 1552 | +QString(")"); |
1553 | operands.removeFirst(); | 1553 | operands.removeFirst(); |
1554 | operands.prepend(new QString(s1)); | 1554 | operands.prepend(new QString(s1)); |
1555 | break; | 1555 | break; |
1556 | case 0xb8://fact | 1556 | case 0xb8://fact |
1557 | s1=QString("FACT(")+operands.first()->ascii() | 1557 | s1=QString("FACT(")+operands.first()->ascii() |
1558 | +QString(")"); | 1558 | +QString(")"); |
1559 | operands.removeFirst(); | 1559 | operands.removeFirst(); |
1560 | operands.prepend(new QString(s1)); | 1560 | operands.prepend(new QString(s1)); |
1561 | break; | 1561 | break; |
1562 | case 0x27://MOD | 1562 | case 0x27://MOD |
1563 | operands.first(); | 1563 | operands.first(); |
1564 | s1=QString("MOD(")+operands.next()->ascii() | 1564 | s1=QString("MOD(")+operands.next()->ascii() |
1565 | +QString(",")+operands.first()->ascii() | 1565 | +QString(",")+operands.first()->ascii() |
1566 | +QString(")"); | 1566 | +QString(")"); |
1567 | operands.removeFirst();operands.removeFirst(); | 1567 | operands.removeFirst();operands.removeFirst(); |
1568 | operands.prepend(new QString(s1)); | 1568 | operands.prepend(new QString(s1)); |
1569 | break; | 1569 | break; |
1570 | case 0x151://power | 1570 | case 0x151://power |
1571 | operands.first(); | 1571 | operands.first(); |
1572 | s1=QString("POWER(")+operands.next()->ascii() | 1572 | s1=QString("POWER(")+operands.next()->ascii() |
1573 | +QString(",")+operands.first()->ascii() | 1573 | +QString(",")+operands.first()->ascii() |
1574 | +QString(")"); | 1574 | +QString(")"); |
1575 | operands.removeFirst();operands.removeFirst(); | 1575 | operands.removeFirst();operands.removeFirst(); |
1576 | operands.prepend(new QString(s1)); | 1576 | operands.prepend(new QString(s1)); |
1577 | break; | 1577 | break; |
1578 | case 0x3f://rand() | 1578 | case 0x3f://rand() |
1579 | s1="RAND()"; | 1579 | s1="RAND()"; |
1580 | operands.prepend(new QString(s1)); | 1580 | operands.prepend(new QString(s1)); |
1581 | break; | 1581 | break; |
1582 | case 0x4://sum | 1582 | case 0x4://sum |
1583 | for(w4=1;w4<w2;w4++) operands.removeFirst(); | 1583 | for(w4=1;w4<w2;w4++) operands.removeFirst(); |
1584 | s1=QString("SUM(")+operands.first()->ascii() | 1584 | s1=QString("SUM(")+operands.first()->ascii() |
1585 | +QString(")"); | 1585 | +QString(")"); |
1586 | operands.removeFirst(); | 1586 | operands.removeFirst(); |
1587 | operands.prepend(new QString(s1)); | 1587 | operands.prepend(new QString(s1)); |
1588 | break; | 1588 | break; |
1589 | case 0x6://min | 1589 | case 0x6://min |
1590 | for(w4=1;w4<w2;w4++) operands.removeFirst(); | 1590 | for(w4=1;w4<w2;w4++) operands.removeFirst(); |
1591 | s1=QString("MIN(")+operands.first()->ascii() | 1591 | s1=QString("MIN(")+operands.first()->ascii() |
1592 | +QString(")"); | 1592 | +QString(")"); |
1593 | operands.removeFirst(); | 1593 | operands.removeFirst(); |
1594 | operands.prepend(new QString(s1)); | 1594 | operands.prepend(new QString(s1)); |
1595 | break; | 1595 | break; |
1596 | case 0x7://max | 1596 | case 0x7://max |
1597 | for(w4=1;w4<w2;w4++) operands.removeFirst(); | 1597 | for(w4=1;w4<w2;w4++) operands.removeFirst(); |
1598 | s1=QString("MAX(")+operands.first()->ascii() | 1598 | s1=QString("MAX(")+operands.first()->ascii() |
1599 | +QString(")"); | 1599 | +QString(")"); |
1600 | operands.removeFirst(); | 1600 | operands.removeFirst(); |
1601 | operands.prepend(new QString(s1)); | 1601 | operands.prepend(new QString(s1)); |
1602 | break; | 1602 | break; |
1603 | case 0x5://average | 1603 | case 0x5://average |
1604 | for(w4=1;w4<w2;w4++) operands.removeFirst(); | 1604 | for(w4=1;w4<w2;w4++) operands.removeFirst(); |
1605 | s1=QString("AVERAGE(")+operands.first()->ascii() | 1605 | s1=QString("AVERAGE(")+operands.first()->ascii() |
1606 | +QString(")"); | 1606 | +QString(")"); |
1607 | operands.removeFirst(); | 1607 | operands.removeFirst(); |
1608 | operands.prepend(new QString(s1)); | 1608 | operands.prepend(new QString(s1)); |
1609 | break; | 1609 | break; |
1610 | case 0x2e://var | 1610 | case 0x2e://var |
1611 | for(w4=1;w4<w2;w4++) operands.removeFirst(); | 1611 | for(w4=1;w4<w2;w4++) operands.removeFirst(); |
1612 | s1=QString("VAR(")+operands.first()->ascii() | 1612 | s1=QString("VAR(")+operands.first()->ascii() |
1613 | +QString(")"); | 1613 | +QString(")"); |
1614 | operands.removeFirst(); | 1614 | operands.removeFirst(); |
1615 | operands.prepend(new QString(s1)); | 1615 | operands.prepend(new QString(s1)); |
1616 | break; | 1616 | break; |
1617 | case 0xc2://varp | 1617 | case 0xc2://varp |
1618 | for(w4=1;w4<w2;w4++) operands.removeFirst(); | 1618 | for(w4=1;w4<w2;w4++) operands.removeFirst(); |
1619 | s1=QString("VARP(")+operands.first()->ascii() | 1619 | s1=QString("VARP(")+operands.first()->ascii() |
1620 | +QString(")"); | 1620 | +QString(")"); |
1621 | operands.removeFirst(); | 1621 | operands.removeFirst(); |
1622 | operands.prepend(new QString(s1)); | 1622 | operands.prepend(new QString(s1)); |
1623 | break; | 1623 | break; |
1624 | case 0xc://stdev | 1624 | case 0xc://stdev |
1625 | for(w4=1;w4<w2;w4++) operands.removeFirst(); | 1625 | for(w4=1;w4<w2;w4++) operands.removeFirst(); |
1626 | s1=QString("STDEV(")+operands.first()->ascii() | 1626 | s1=QString("STDEV(")+operands.first()->ascii() |
1627 | +QString(")"); | 1627 | +QString(")"); |
1628 | operands.removeFirst(); | 1628 | operands.removeFirst(); |
1629 | operands.prepend(new QString(s1)); | 1629 | operands.prepend(new QString(s1)); |
1630 | break; | 1630 | break; |
1631 | case 0xc1://stdevp | 1631 | case 0xc1://stdevp |
1632 | for(w4=1;w4<w2;w4++) operands.removeFirst(); | 1632 | for(w4=1;w4<w2;w4++) operands.removeFirst(); |
1633 | s1=QString("STDEVP(")+operands.first()->ascii() | 1633 | s1=QString("STDEVP(")+operands.first()->ascii() |
1634 | +QString(")"); | 1634 | +QString(")"); |
1635 | operands.removeFirst(); | 1635 | operands.removeFirst(); |
1636 | operands.prepend(new QString(s1)); | 1636 | operands.prepend(new QString(s1)); |
1637 | break; | 1637 | break; |
1638 | case 0x143://skew | 1638 | case 0x143://skew |
1639 | for(w4=1;w4<w2;w4++) operands.removeFirst(); | 1639 | for(w4=1;w4<w2;w4++) operands.removeFirst(); |
1640 | s1=QString("SKEW(")+operands.first()->ascii() | 1640 | s1=QString("SKEW(")+operands.first()->ascii() |
1641 | +QString(")"); | 1641 | +QString(")"); |
1642 | operands.removeFirst(); | 1642 | operands.removeFirst(); |
1643 | operands.prepend(new QString(s1)); | 1643 | operands.prepend(new QString(s1)); |
1644 | break; | 1644 | break; |
1645 | case 0x142://kurt | 1645 | case 0x142://kurt |
1646 | for(w4=1;w4<w2;w4++) operands.removeFirst(); | 1646 | for(w4=1;w4<w2;w4++) operands.removeFirst(); |
1647 | s1=QString("KURT(")+operands.first()->ascii() | 1647 | s1=QString("KURT(")+operands.first()->ascii() |
1648 | +QString(")"); | 1648 | +QString(")"); |
1649 | operands.removeFirst(); | 1649 | operands.removeFirst(); |
1650 | operands.prepend(new QString(s1)); | 1650 | operands.prepend(new QString(s1)); |
1651 | break; | 1651 | break; |
1652 | case 0x0://count | 1652 | case 0x0://count |
1653 | for(w4=1;w4<w2;w4++) operands.removeFirst(); | 1653 | for(w4=1;w4<w2;w4++) operands.removeFirst(); |
1654 | s1=QString("COUNT(")+operands.first()->ascii() | 1654 | s1=QString("COUNT(")+operands.first()->ascii() |
1655 | +QString(")"); | 1655 | +QString(")"); |
1656 | operands.removeFirst(); | 1656 | operands.removeFirst(); |
1657 | operands.prepend(new QString(s1)); | 1657 | operands.prepend(new QString(s1)); |
1658 | break; | 1658 | break; |
1659 | 1659 | ||
1660 | default: | 1660 | default: |
1661 | printf("token:FUNCTION_UNKNOWN=0x%x\r\n",w1); | 1661 | printf("token:FUNCTION_UNKNOWN=0x%x\r\n",w1); |
1662 | return QString("FUNC_UNKNOWN"); | 1662 | return QString("FUNC_UNKNOWN"); |
1663 | break; | 1663 | break; |
1664 | 1664 | ||
1665 | }; | 1665 | }; |
1666 | 1666 | ||
1667 | break; | 1667 | break; |
1668 | 1668 | ||
1669 | default: | 1669 | default: |
1670 | printf("tokenUNKNOWN=0x%x\r\n",token); | 1670 | printf("tokenUNKNOWN=0x%x\r\n",token); |
1671 | return QString("TOKEN_UKNOWN"); | 1671 | return QString("TOKEN_UKNOWN"); |
1672 | //it is dangerous to go to idx++ and not return | 1672 | //it is dangerous to go to idx++ and not return |
1673 | // because the result is unexpected. | 1673 | // because the result is unexpected. |
1674 | // but there is a possibility the the parser will give the correct | 1674 | // but there is a possibility the the parser will give the correct |
1675 | // answer, because there are some tokens in excel formulas that can be //ignored. | 1675 | // answer, because there are some tokens in excel formulas that can be //ignored. |
1676 | idx++; | 1676 | idx++; |
1677 | break; | 1677 | break; |
1678 | }; | 1678 | }; |
1679 | 1679 | ||
1680 | }; | 1680 | }; |
1681 | 1681 | ||
1682 | 1682 | ||
1683 | 1683 | ||
1684 | printf("{////FormulaParser}\r\n"); | 1684 | printf("{////FormulaParser}\r\n"); |
1685 | printf("GetFormula:::::::r=%d,c=%d,,,%s\r\n",row,col,s1.ascii()); | 1685 | printf("GetFormula:::::::r=%d,c=%d,,,%s\r\n",row,col,s1.ascii()); |
1686 | printf("\r\n"); | 1686 | printf("\r\n"); |
1687 | s1=operands.first()->ascii(); | 1687 | s1=operands.first()->ascii(); |
1688 | operands.clear(); | 1688 | operands.clear(); |
1689 | return QString(s1); | 1689 | return QString(s1); |
1690 | }; | 1690 | }; |
1691 | 1691 | ||
1692 | QString ExcelBook::FindCellName(int row, int col) | 1692 | QString ExcelBook::FindCellName(int row, int col) |
1693 | { | 1693 | { |
1694 | row++;col++; | 1694 | row++;col++; |
1695 | QString s1=""; | 1695 | QString s1=""; |
1696 | int i1=col % 26; | 1696 | int i1=col % 26; |
1697 | int i2=col / 26; | 1697 | int i2=col / 26; |
1698 | if (i2!=0) s1=(char)(i2+65); //65 =A | 1698 | if (i2!=0) s1=(char)(i2+65); //65 =A |
1699 | s1=s1+(char)(i1+65-1); | 1699 | s1=s1+(char)(i1+65-1); |
1700 | return (s1+QString::number(row)); | 1700 | return (s1+QString::number(row)); |
1701 | }; | 1701 | }; |
1702 | 1702 | ||
1703 | 1703 | ||
1704 | 1704 | ||
1705 | 1705 | ||
1706 | 1706 | ||
1707 | 1707 | ||
1708 | 1708 | ||
1709 | 1709 | ||
diff --git a/noncore/apps/tinykate/libkate/document/katedocument.cpp b/noncore/apps/tinykate/libkate/document/katedocument.cpp index 6dc4fd2..a70f3aa 100644 --- a/noncore/apps/tinykate/libkate/document/katedocument.cpp +++ b/noncore/apps/tinykate/libkate/document/katedocument.cpp | |||
@@ -1,3175 +1,3175 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | katedocument.cpp - description | 2 | katedocument.cpp - description |
3 | ------------------- | 3 | ------------------- |
4 | begin : Mon Jan 15 2001 | 4 | begin : Mon Jan 15 2001 |
5 | copyright : (C) 2001 by Christoph "Crossfire" Cullmann | 5 | copyright : (C) 2001 by Christoph "Crossfire" Cullmann |
6 | (C) 2002 by Joseph Wenninger | 6 | (C) 2002 by Joseph Wenninger |
7 | email : crossfire@babylon2k.de | 7 | email : crossfire@babylon2k.de |
8 | jowenn@kde.org | 8 | jowenn@kde.org |
9 | 9 | ||
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | 11 | ||
12 | /*************************************************************************** | 12 | /*************************************************************************** |
13 | * * | 13 | * * |
14 | * This program is free software; you can redistribute it and/or modify * | 14 | * This program is free software; you can redistribute it and/or modify * |
15 | * it under the terms of the GNU General Public License as published by * | 15 | * it under the terms of the GNU General Public License as published by * |
16 | * the Free Software Foundation; either version 2 of the License, or * | 16 | * the Free Software Foundation; either version 2 of the License, or * |
17 | * (at your option) any later version. * | 17 | * (at your option) any later version. * |
18 | * * | 18 | * * |
19 | ***************************************************************************/ | 19 | ***************************************************************************/ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Copyright (C) 1998, 1999 Jochen Wilhelmy | 22 | Copyright (C) 1998, 1999 Jochen Wilhelmy |
23 | digisnap@cs.tu-berlin.de | 23 | digisnap@cs.tu-berlin.de |
24 | 24 | ||
25 | This library is free software; you can redistribute it and/or | 25 | This library is free software; you can redistribute it and/or |
26 | modify it under the terms of the GNU Library General Public | 26 | modify it under the terms of the GNU Library General Public |
27 | License as published by the Free Software Foundation; either | 27 | License as published by the Free Software Foundation; either |
28 | version 2 of the License, or (at your option) any later version. | 28 | version 2 of the License, or (at your option) any later version. |
29 | 29 | ||
30 | This library is distributed in the hope that it will be useful, | 30 | This library is distributed in the hope that it will be useful, |
31 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 31 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
32 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 32 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
33 | Library General Public License for more details. | 33 | Library General Public License for more details. |
34 | 34 | ||
35 | You should have received a copy of the GNU Library General Public License | 35 | You should have received a copy of the GNU Library General Public License |
36 | along with this library; see the file COPYING.LIB. If not, write to | 36 | along with this library; see the file COPYING.LIB. If not, write to |
37 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 37 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
38 | Boston, MA 02111-1307, USA. | 38 | Boston, MA 02111-1307, USA. |
39 | */ | 39 | */ |
40 | 40 | ||
41 | #include "katedocument.h" | 41 | #include "katedocument.h" |
42 | #include "kmessagebox.h" | 42 | #include "kmessagebox.h" |
43 | #include "kglobal.h" | 43 | #include "kglobal.h" |
44 | 44 | ||
45 | //#include "kcharsets.h" | 45 | //#include "kcharsets.h" |
46 | #include "kdebug.h" | 46 | #include "kdebug.h" |
47 | //#include "kinstance.h" | 47 | //#include "kinstance.h" |
48 | 48 | ||
49 | #include "kglobalsettings.h" | 49 | #include "kglobalsettings.h" |
50 | //#include "kaction.h" | 50 | //#include "kaction.h" |
51 | //#include "kstdaction.h" | 51 | //#include "kstdaction.h" |
52 | 52 | ||
53 | #include "../view/kateview.h" | 53 | #include "../view/kateview.h" |
54 | #include "katebuffer.h" | 54 | #include "katebuffer.h" |
55 | #include "katetextline.h" | 55 | #include "katetextline.h" |
56 | 56 | ||
57 | #include "katecmd.h" | 57 | #include "katecmd.h" |
58 | 58 | ||
59 | /* OPIE */ | 59 | /* OPIE */ |
60 | #include <opie2/odebug.h> | 60 | #include <opie2/odebug.h> |
61 | #include <qpe/config.h> | 61 | #include <qpe/config.h> |
62 | 62 | ||
63 | /* QT */ | 63 | /* QT */ |
64 | #include <qfileinfo.h> | 64 | #include <qfileinfo.h> |
65 | #include <qdatetime.h> | 65 | #include <qdatetime.h> |
66 | #include <qstring.h> | 66 | #include <qstring.h> |
67 | #include <qtimer.h> | 67 | #include <qtimer.h> |
68 | #include <qobject.h> | 68 | #include <qobject.h> |
69 | #include <qapplication.h> | 69 | #include <qapplication.h> |
70 | #include <qclipboard.h> | 70 | #include <qclipboard.h> |
71 | #include <qfont.h> | 71 | #include <qfont.h> |
72 | #include <qpainter.h> | 72 | #include <qpainter.h> |
73 | #include <qfile.h> | 73 | #include <qfile.h> |
74 | #include <qtextstream.h> | 74 | #include <qtextstream.h> |
75 | #include <qtextcodec.h> | 75 | #include <qtextcodec.h> |
76 | 76 | ||
77 | /* STD */ | 77 | /* STD */ |
78 | #include <sys/time.h> | 78 | #include <sys/time.h> |
79 | #include <unistd.h> | 79 | #include <unistd.h> |
80 | #include <stdio.h> | 80 | #include <stdio.h> |
81 | 81 | ||
82 | KateAction::KateAction(Action a, PointStruc &cursor, int len, const QString &text) | 82 | KateAction::KateAction(Action a, PointStruc &cursor, int len, const QString &text) |
83 | : action(a), cursor(cursor), len(len), text(text) { | 83 | : action(a), cursor(cursor), len(len), text(text) { |
84 | } | 84 | } |
85 | 85 | ||
86 | KateActionGroup::KateActionGroup(PointStruc &aStart, int type) | 86 | KateActionGroup::KateActionGroup(PointStruc &aStart, int type) |
87 | : start(aStart), action(0L), undoType(type) { | 87 | : start(aStart), action(0L), undoType(type) { |
88 | } | 88 | } |
89 | 89 | ||
90 | KateActionGroup::~KateActionGroup() { | 90 | KateActionGroup::~KateActionGroup() { |
91 | KateAction *current, *next; | 91 | KateAction *current, *next; |
92 | 92 | ||
93 | current = action; | 93 | current = action; |
94 | while (current) { | 94 | while (current) { |
95 | next = current->next; | 95 | next = current->next; |
96 | delete current; | 96 | delete current; |
97 | current = next; | 97 | current = next; |
98 | } | 98 | } |
99 | } | 99 | } |
100 | 100 | ||
101 | void KateActionGroup::insertAction(KateAction *a) { | 101 | void KateActionGroup::insertAction(KateAction *a) { |
102 | a->next = action; | 102 | a->next = action; |
103 | action = a; | 103 | action = a; |
104 | } | 104 | } |
105 | 105 | ||
106 | const char * KateActionGroup::typeName(int type) | 106 | const char * KateActionGroup::typeName(int type) |
107 | { | 107 | { |
108 | // return a short text description of the given undo group type suitable for a menu | 108 | // return a short text description of the given undo group type suitable for a menu |
109 | // not the lack of i18n's, the caller is expected to handle translation | 109 | // not the lack of i18n's, the caller is expected to handle translation |
110 | switch (type) { | 110 | switch (type) { |
111 | case ugPaste : return "Paste Text"; | 111 | case ugPaste : return "Paste Text"; |
112 | case ugDelBlock : return "Selection Overwrite"; | 112 | case ugDelBlock : return "Selection Overwrite"; |
113 | case ugIndent : return "Indent"; | 113 | case ugIndent : return "Indent"; |
114 | case ugUnindent : return "Unindent"; | 114 | case ugUnindent : return "Unindent"; |
115 | case ugComment : return "Comment"; | 115 | case ugComment : return "Comment"; |
116 | case ugUncomment : return "Uncomment"; | 116 | case ugUncomment : return "Uncomment"; |
117 | case ugReplace : return "Text Replace"; | 117 | case ugReplace : return "Text Replace"; |
118 | case ugSpell : return "Spell Check"; | 118 | case ugSpell : return "Spell Check"; |
119 | case ugInsChar : return "Typing"; | 119 | case ugInsChar : return "Typing"; |
120 | case ugDelChar : return "Delete Text"; | 120 | case ugDelChar : return "Delete Text"; |
121 | case ugInsLine : return "New Line"; | 121 | case ugInsLine : return "New Line"; |
122 | case ugDelLine : return "Delete Line"; | 122 | case ugDelLine : return "Delete Line"; |
123 | } | 123 | } |
124 | return ""; | 124 | return ""; |
125 | } | 125 | } |
126 | 126 | ||
127 | const int KateDocument::maxAttribs = 32; | 127 | const int KateDocument::maxAttribs = 32; |
128 | 128 | ||
129 | QStringList KateDocument::searchForList = QStringList(); | 129 | QStringList KateDocument::searchForList = QStringList(); |
130 | QStringList KateDocument::replaceWithList = QStringList(); | 130 | QStringList KateDocument::replaceWithList = QStringList(); |
131 | 131 | ||
132 | uint KateDocument::uniqueID = 0; | 132 | uint KateDocument::uniqueID = 0; |
133 | 133 | ||
134 | QPtrDict<KateDocument::KateDocPrivate>* KateDocument::d_ptr = 0; | 134 | QPtrDict<KateDocument::KateDocPrivate>* KateDocument::d_ptr = 0; |
135 | 135 | ||
136 | 136 | ||
137 | KateDocument::KateDocument(bool bSingleViewMode, bool bBrowserView, | 137 | KateDocument::KateDocument(bool bSingleViewMode, bool bBrowserView, |
138 | QWidget *parentWidget, const char *widgetName, | 138 | QWidget *parentWidget, const char *widgetName, |
139 | QObject *, const char *) | 139 | QObject *, const char *) |
140 | : Kate::Document (), | 140 | : Kate::Document (), |
141 | myFont(KGlobalSettings::generalFont()), myFontBold(KGlobalSettings::generalFont()), myFontItalic(KGlobalSettings::generalFont()), myFontBI(KGlobalSettings::generalFont()), | 141 | myFont(KGlobalSettings::generalFont()), myFontBold(KGlobalSettings::generalFont()), myFontItalic(KGlobalSettings::generalFont()), myFontBI(KGlobalSettings::generalFont()), |
142 | myFontMetrics (myFont), myFontMetricsBold (myFontBold), myFontMetricsItalic (myFontItalic), myFontMetricsBI (myFontBI), | 142 | myFontMetrics (myFont), myFontMetricsBold (myFontBold), myFontMetricsItalic (myFontItalic), myFontMetricsBI (myFontBI), |
143 | hlManager(HlManager::self ()) | 143 | hlManager(HlManager::self ()) |
144 | { | 144 | { |
145 | 145 | ||
146 | d(this)->hlSetByUser = false; | 146 | d(this)->hlSetByUser = false; |
147 | PreHighlightedTill=0; | 147 | PreHighlightedTill=0; |
148 | RequestPreHighlightTill=0; | 148 | RequestPreHighlightTill=0; |
149 | 149 | ||
150 | m_bSingleViewMode=bSingleViewMode; | 150 | m_bSingleViewMode=bSingleViewMode; |
151 | m_bBrowserView = bBrowserView; | 151 | m_bBrowserView = bBrowserView; |
152 | 152 | ||
153 | m_url = QString::null; | 153 | m_url = QString::null; |
154 | 154 | ||
155 | // NOTE: QFont::CharSet doesn't provide all the charsets KDE supports | 155 | // NOTE: QFont::CharSet doesn't provide all the charsets KDE supports |
156 | // (esp. it doesn't distinguish between UTF-8 and iso10646-1) | 156 | // (esp. it doesn't distinguish between UTF-8 and iso10646-1) |
157 | 157 | ||
158 | myEncoding = QString::fromLatin1(QTextCodec::codecForLocale()->name()); | 158 | myEncoding = QString::fromLatin1(QTextCodec::codecForLocale()->name()); |
159 | 159 | ||
160 | maxLength = -1; | 160 | maxLength = -1; |
161 | 161 | ||
162 | setFont (KGlobalSettings::generalFont()); | 162 | setFont (KGlobalSettings::generalFont()); |
163 | 163 | ||
164 | myDocID = uniqueID; | 164 | myDocID = uniqueID; |
165 | uniqueID++; | 165 | uniqueID++; |
166 | 166 | ||
167 | myDocName = QString (""); | 167 | myDocName = QString (""); |
168 | fileInfo = new QFileInfo (); | 168 | fileInfo = new QFileInfo (); |
169 | 169 | ||
170 | myCmd = new KateCmd (this); | 170 | myCmd = new KateCmd (this); |
171 | 171 | ||
172 | connect(this,SIGNAL(modifiedChanged()),this,SLOT(slotModChanged())); | 172 | connect(this,SIGNAL(modifiedChanged()),this,SLOT(slotModChanged())); |
173 | 173 | ||
174 | buffer = new KWBuffer; | 174 | buffer = new KWBuffer; |
175 | connect(buffer, SIGNAL(linesChanged(int)), this, SLOT(slotBufferChanged())); | 175 | connect(buffer, SIGNAL(linesChanged(int)), this, SLOT(slotBufferChanged())); |
176 | // connect(buffer, SIGNAL(textChanged()), this, SIGNAL(textChanged())); | 176 | // connect(buffer, SIGNAL(textChanged()), this, SIGNAL(textChanged())); |
177 | connect(buffer, SIGNAL(needHighlight(long,long)),this,SLOT(slotBufferHighlight(long,long))); | 177 | connect(buffer, SIGNAL(needHighlight(long,long)),this,SLOT(slotBufferHighlight(long,long))); |
178 | 178 | ||
179 | colors[0] = KGlobalSettings::baseColor(); | 179 | colors[0] = KGlobalSettings::baseColor(); |
180 | colors[1] = KGlobalSettings::highlightColor(); | 180 | colors[1] = KGlobalSettings::highlightColor(); |
181 | 181 | ||
182 | m_attribs = new Attribute[maxAttribs]; | 182 | m_attribs = new Attribute[maxAttribs]; |
183 | 183 | ||
184 | m_highlight = 0L; | 184 | m_highlight = 0L; |
185 | tabChars = 8; | 185 | tabChars = 8; |
186 | 186 | ||
187 | m_singleSelection = false; | 187 | m_singleSelection = false; |
188 | 188 | ||
189 | newDocGeometry = false; | 189 | newDocGeometry = false; |
190 | readOnly = false; | 190 | readOnly = false; |
191 | newDoc = false; | 191 | newDoc = false; |
192 | 192 | ||
193 | modified = false; | 193 | modified = false; |
194 | 194 | ||
195 | undoList.setAutoDelete(true); | 195 | undoList.setAutoDelete(true); |
196 | undoState = 0; | 196 | undoState = 0; |
197 | undoSteps = 50; | 197 | undoSteps = 50; |
198 | 198 | ||
199 | pseudoModal = 0L; | 199 | pseudoModal = 0L; |
200 | clear(); | 200 | clear(); |
201 | 201 | ||
202 | setHighlight(0); //calls updateFontData() | 202 | setHighlight(0); //calls updateFontData() |
203 | // if the user changes the highlight with the dialog, notify the doc | 203 | // if the user changes the highlight with the dialog, notify the doc |
204 | connect(hlManager,SIGNAL(changed()),SLOT(hlChanged())); | 204 | connect(hlManager,SIGNAL(changed()),SLOT(hlChanged())); |
205 | 205 | ||
206 | newDocGeometry = false; | 206 | newDocGeometry = false; |
207 | 207 | ||
208 | readConfig(); | 208 | readConfig(); |
209 | 209 | ||
210 | setReadOnly(false); | 210 | setReadOnly(false); |
211 | } | 211 | } |
212 | 212 | ||
213 | void KateDocument::setDontChangeHlOnSave() | 213 | void KateDocument::setDontChangeHlOnSave() |
214 | { | 214 | { |
215 | d(this)->hlSetByUser = true; | 215 | d(this)->hlSetByUser = true; |
216 | } | 216 | } |
217 | 217 | ||
218 | void KateDocument::setFont (QFont font) | 218 | void KateDocument::setFont (QFont font) |
219 | { | 219 | { |
220 | kdDebug()<<"Kate:: setFont"<<endl; | 220 | kdDebug()<<"Kate:: setFont"<<endl; |
221 | int oldwidth=myFontMetrics.width('W'); //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 | 221 | int oldwidth=myFontMetrics.width('W'); //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 |
222 | myFont = font; | 222 | myFont = font; |
223 | myFontBold = QFont (font); | 223 | myFontBold = QFont (font); |
224 | myFontBold.setBold (true); | 224 | myFontBold.setBold (true); |
225 | 225 | ||
226 | myFontItalic = QFont (font); | 226 | myFontItalic = QFont (font); |
227 | myFontItalic.setItalic (true); | 227 | myFontItalic.setItalic (true); |
228 | 228 | ||
229 | myFontBI = QFont (font); | 229 | myFontBI = QFont (font); |
230 | myFontBI.setBold (true); | 230 | myFontBI.setBold (true); |
231 | myFontBI.setItalic (true); | 231 | myFontBI.setItalic (true); |
232 | 232 | ||
233 | myFontMetrics = CachedFontMetrics (myFont); | 233 | myFontMetrics = CachedFontMetrics (myFont); |
234 | myFontMetricsBold = CachedFontMetrics (myFontBold); | 234 | myFontMetricsBold = CachedFontMetrics (myFontBold); |
235 | myFontMetricsItalic = CachedFontMetrics (myFontItalic); | 235 | myFontMetricsItalic = CachedFontMetrics (myFontItalic); |
236 | myFontMetricsBI = CachedFontMetrics (myFontBI); | 236 | myFontMetricsBI = CachedFontMetrics (myFontBI); |
237 | int newwidth=myFontMetrics.width('W'); //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 | 237 | int newwidth=myFontMetrics.width('W'); //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 |
238 | maxLength=maxLength*(float)newwidth/(float)oldwidth; //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 | 238 | maxLength=maxLength*(float)newwidth/(float)oldwidth; //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 |
239 | 239 | ||
240 | updateFontData(); | 240 | updateFontData(); |
241 | updateViews(); //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 | 241 | updateViews(); //Quick & Dirty Hack (by JoWenn) //Remove in KDE 3.0 |
242 | 242 | ||
243 | } | 243 | } |
244 | 244 | ||
245 | long KateDocument::needPreHighlight(long till) | 245 | long KateDocument::needPreHighlight(long till) |
246 | { | 246 | { |
247 | int max=numLines()-1; | 247 | int max=numLines()-1; |
248 | if (till>max) | 248 | if (till>max) |
249 | { | 249 | { |
250 | till=max; | 250 | till=max; |
251 | } | 251 | } |
252 | if (PreHighlightedTill>=till) return -1; | 252 | if (PreHighlightedTill>=till) return -1; |
253 | 253 | ||
254 | long tmp=RequestPreHighlightTill; | 254 | long tmp=RequestPreHighlightTill; |
255 | if (RequestPreHighlightTill<till) | 255 | if (RequestPreHighlightTill<till) |
256 | { | 256 | { |
257 | RequestPreHighlightTill=till; | 257 | RequestPreHighlightTill=till; |
258 | if (tmp<=PreHighlightedTill) QTimer::singleShot(10,this,SLOT(doPreHighlight())); | 258 | if (tmp<=PreHighlightedTill) QTimer::singleShot(10,this,SLOT(doPreHighlight())); |
259 | } | 259 | } |
260 | return RequestPreHighlightTill; | 260 | return RequestPreHighlightTill; |
261 | } | 261 | } |
262 | 262 | ||
263 | void KateDocument::doPreHighlight() | 263 | void KateDocument::doPreHighlight() |
264 | { | 264 | { |
265 | int from = PreHighlightedTill; | 265 | int from = PreHighlightedTill; |
266 | int till = PreHighlightedTill+200; | 266 | int till = PreHighlightedTill+200; |
267 | int max = numLines()-1; | 267 | int max = numLines()-1; |
268 | if (till > max) | 268 | if (till > max) |
269 | { | 269 | { |
270 | till = max; | 270 | till = max; |
271 | } | 271 | } |
272 | PreHighlightedTill = till; | 272 | PreHighlightedTill = till; |
273 | updateLines(from,till); | 273 | updateLines(from,till); |
274 | emit preHighlightChanged(PreHighlightedTill); | 274 | emit preHighlightChanged(PreHighlightedTill); |
275 | if (PreHighlightedTill<RequestPreHighlightTill) | 275 | if (PreHighlightedTill<RequestPreHighlightTill) |
276 | QTimer::singleShot(10,this,SLOT(doPreHighlight())); | 276 | QTimer::singleShot(10,this,SLOT(doPreHighlight())); |
277 | } | 277 | } |
278 | 278 | ||
279 | KateDocument::~KateDocument() | 279 | KateDocument::~KateDocument() |
280 | { | 280 | { |
281 | m_highlight->release(); | 281 | m_highlight->release(); |
282 | writeConfig(); | 282 | writeConfig(); |
283 | 283 | ||
284 | if ( !m_bSingleViewMode ) | 284 | if ( !m_bSingleViewMode ) |
285 | { | 285 | { |
286 | m_views.setAutoDelete( true ); | 286 | m_views.setAutoDelete( true ); |
287 | m_views.clear(); | 287 | m_views.clear(); |
288 | m_views.setAutoDelete( false ); | 288 | m_views.setAutoDelete( false ); |
289 | } | 289 | } |
290 | delete_d(this); | 290 | delete_d(this); |
291 | } | 291 | } |
292 | 292 | ||
293 | void KateDocument::openURL(const QString &filename) | 293 | void KateDocument::openURL(const QString &filename) |
294 | { | 294 | { |
295 | 295 | ||
296 | m_file=filename; | 296 | m_file=filename; |
297 | fileInfo->setFile (m_file); | 297 | fileInfo->setFile (m_file); |
298 | setMTime(); | 298 | setMTime(); |
299 | 299 | ||
300 | if (!fileInfo->exists() || !fileInfo->isReadable()) | 300 | if (!fileInfo->exists() || !fileInfo->isReadable()) |
301 | { | 301 | { |
302 | odebug << "File doesn't exit or couldn't be read" << oendl; | 302 | odebug << "File doesn't exit or couldn't be read" << oendl; |
303 | return ; | 303 | return ; |
304 | } | 304 | } |
305 | 305 | ||
306 | buffer->clear(); | 306 | buffer->clear(); |
307 | #warning fixme | 307 | #warning fixme |
308 | // buffer->insertFile(0, m_file, KGlobal::charsets()->codecForName(myEncoding)); | 308 | // buffer->insertFile(0, m_file, KGlobal::charsets()->codecForName(myEncoding)); |
309 | odebug << "Telling buffer to open file" << oendl; | 309 | odebug << "Telling buffer to open file" << oendl; |
310 | buffer->insertFile(0, m_file, QTextCodec::codecForLocale()); | 310 | buffer->insertFile(0, m_file, QTextCodec::codecForLocale()); |
311 | 311 | ||
312 | setMTime(); | 312 | setMTime(); |
313 | 313 | ||
314 | if (myWordWrap) | 314 | if (myWordWrap) |
315 | wrapText (myWordWrapAt); | 315 | wrapText (myWordWrapAt); |
316 | 316 | ||
317 | int hl = hlManager->wildcardFind( m_file ); | 317 | int hl = hlManager->wildcardFind( m_file ); |
318 | 318 | ||
319 | setHighlight(hl); | 319 | setHighlight(hl); |
320 | 320 | ||
321 | updateLines(); | 321 | updateLines(); |
322 | updateViews(); | 322 | updateViews(); |
323 | 323 | ||
324 | emit fileNameChanged(); | 324 | emit fileNameChanged(); |
325 | 325 | ||
326 | return ; | 326 | return ; |
327 | } | 327 | } |
328 | 328 | ||
329 | bool KateDocument::saveFile() | 329 | bool KateDocument::saveFile() |
330 | { | 330 | { |
331 | 331 | ||
332 | QFile f( m_file ); | 332 | QFile f( m_file ); |
333 | if ( !f.open( IO_WriteOnly ) ) | 333 | if ( !f.open( IO_WriteOnly ) ) |
334 | return false; // Error | 334 | return false; // Error |
335 | 335 | ||
336 | QTextStream stream(&f); | 336 | QTextStream stream(&f); |
337 | 337 | ||
338 | stream.setEncoding(QTextStream::RawUnicode); // disable Unicode headers | 338 | stream.setEncoding(QTextStream::RawUnicode); // disable Unicode headers |
339 | #warning fixme | 339 | #warning fixme |
340 | // stream.setCodec(KGlobal::charsets()->codecForName(myEncoding)); | 340 | // stream.setCodec(KGlobal::charsets()->codecForName(myEncoding)); |
341 | stream.setCodec(QTextCodec::codecForLocale()); // this line sets the mapper to the correct codec | 341 | stream.setCodec(QTextCodec::codecForLocale()); // this line sets the mapper to the correct codec |
342 | 342 | ||
343 | int maxLine = numLines(); | 343 | int maxLine = numLines(); |
344 | int line = 0; | 344 | int line = 0; |
345 | while(true) | 345 | while(true) |
346 | { | 346 | { |
347 | stream << getTextLine(line)->getString(); | 347 | stream << getTextLine(line)->getString(); |
348 | line++; | 348 | line++; |
349 | if (line >= maxLine) break; | 349 | if (line >= maxLine) break; |
350 | 350 | ||
351 | if (eolMode == KateDocument::eolUnix) stream << "\n"; | 351 | if (eolMode == KateDocument::eolUnix) stream << "\n"; |
352 | else if (eolMode == KateDocument::eolDos) stream << "\r\n"; | 352 | else if (eolMode == KateDocument::eolDos) stream << "\r\n"; |
353 | else if (eolMode == KateDocument::eolMacintosh) stream << '\r'; | 353 | else if (eolMode == KateDocument::eolMacintosh) stream << '\r'; |
354 | }; | 354 | }; |
355 | f.close(); | 355 | f.close(); |
356 | 356 | ||
357 | fileInfo->setFile (m_file); | 357 | fileInfo->setFile (m_file); |
358 | setMTime(); | 358 | setMTime(); |
359 | 359 | ||
360 | if (!(d(this)->hlSetByUser)) | 360 | if (!(d(this)->hlSetByUser)) |
361 | { | 361 | { |
362 | int hl = hlManager->wildcardFind( m_file ); | 362 | int hl = hlManager->wildcardFind( m_file ); |
363 | 363 | ||
364 | setHighlight(hl); | 364 | setHighlight(hl); |
365 | } | 365 | } |
366 | emit fileNameChanged (); | 366 | emit fileNameChanged (); |
367 | 367 | ||
368 | return (f.status() == IO_Ok); | 368 | return (f.status() == IO_Ok); |
369 | } | 369 | } |
370 | 370 | ||
371 | KTextEditor::View *KateDocument::createView( QWidget *parent, const char *name ) | 371 | KTextEditor::View *KateDocument::createView( QWidget *parent, const char *name ) |
372 | { | 372 | { |
373 | return new KateView( this, parent, name); | 373 | return new KateView( this, parent, name); |
374 | } | 374 | } |
375 | 375 | ||
376 | QString KateDocument::textLine( int line ) const | 376 | QString KateDocument::textLine( int line ) const |
377 | { | 377 | { |
378 | TextLine::Ptr l = getTextLine( line ); | 378 | TextLine::Ptr l = getTextLine( line ); |
379 | if ( !l ) | 379 | if ( !l ) |
380 | return QString(); | 380 | return QString(); |
381 | 381 | ||
382 | return l->getString(); | 382 | return l->getString(); |
383 | } | 383 | } |
384 | 384 | ||
385 | void KateDocument::replaceLine(const QString& s,int line) | 385 | void KateDocument::replaceLine(const QString& s,int line) |
386 | { | 386 | { |
387 | remove_Line(line,false); | 387 | remove_Line(line,false); |
388 | insert_Line(s,line,true); | 388 | insert_Line(s,line,true); |
389 | } | 389 | } |
390 | 390 | ||
391 | void KateDocument::insertLine( const QString &str, int l ) { | 391 | void KateDocument::insertLine( const QString &str, int l ) { |
392 | insert_Line(str,l,true); | 392 | insert_Line(str,l,true); |
393 | } | 393 | } |
394 | 394 | ||
395 | void KateDocument::insert_Line(const QString& s,int line, bool update) | 395 | void KateDocument::insert_Line(const QString& s,int line, bool update) |
396 | { | 396 | { |
397 | kdDebug(13020)<<"KateDocument::insertLine "<<s<<QString(" %1").arg(line)<<endl; | 397 | kdDebug(13020)<<"KateDocument::insertLine "<<s<<QString(" %1").arg(line)<<endl; |
398 | TextLine::Ptr TL=new TextLine(); | 398 | TextLine::Ptr TL=new TextLine(); |
399 | TL->append(s.unicode(),s.length()); | 399 | TL->append(s.unicode(),s.length()); |
400 | buffer->insertLine(line,TL); | 400 | buffer->insertLine(line,TL); |
401 | if (update) | 401 | if (update) |
402 | { | 402 | { |
403 | newDocGeometry=true; | 403 | newDocGeometry=true; |
404 | updateLines(line); | 404 | updateLines(line); |
405 | updateViews(); | 405 | updateViews(); |
406 | } | 406 | } |
407 | } | 407 | } |
408 | 408 | ||
409 | void KateDocument::insertAt( const QString &s, int line, int col, bool ) | 409 | void KateDocument::insertAt( const QString &s, int line, int col, bool ) |
410 | { | 410 | { |
411 | VConfig c; | 411 | VConfig c; |
412 | c.view = 0; // ### FIXME | 412 | c.view = 0; // ### FIXME |
413 | c.cursor.x = col; | 413 | c.cursor.x = col; |
414 | c.cursor.y = line; | 414 | c.cursor.y = line; |
415 | c.cXPos = 0; // ### FIXME | 415 | c.cXPos = 0; // ### FIXME |
416 | c.flags = 0; // ### FIXME | 416 | c.flags = 0; // ### FIXME |
417 | insert( c, s ); | 417 | insert( c, s ); |
418 | } | 418 | } |
419 | 419 | ||
420 | void KateDocument::removeLine( int line ) { | 420 | void KateDocument::removeLine( int line ) { |
421 | remove_Line(line,true); | 421 | remove_Line(line,true); |
422 | } | 422 | } |
423 | 423 | ||
424 | void KateDocument::remove_Line(int line,bool update) | 424 | void KateDocument::remove_Line(int line,bool update) |
425 | { | 425 | { |
426 | kdDebug(13020)<<"KateDocument::removeLine "<<QString("%1").arg(line)<<endl; | 426 | kdDebug(13020)<<"KateDocument::removeLine "<<QString("%1").arg(line)<<endl; |
427 | buffer->removeLine(line); | 427 | buffer->removeLine(line); |
428 | // newDocGeometry=true; | 428 | // newDocGeometry=true; |
429 | // if line==0) | 429 | // if line==0) |
430 | if (update) | 430 | if (update) |
431 | { | 431 | { |
432 | updateLines(line); | 432 | updateLines(line); |
433 | updateViews(); | 433 | updateViews(); |
434 | } | 434 | } |
435 | } | 435 | } |
436 | 436 | ||
437 | int KateDocument::length() const | 437 | int KateDocument::length() const |
438 | { | 438 | { |
439 | return text().length(); | 439 | return text().length(); |
440 | } | 440 | } |
441 | 441 | ||
442 | void KateDocument::setSelection( int , int , int , int ) | 442 | void KateDocument::setSelection( int , int , int , int ) |
443 | { | 443 | { |
444 | } | 444 | } |
445 | 445 | ||
446 | bool KateDocument::hasSelection() const | 446 | bool KateDocument::hasSelection() const |
447 | { | 447 | { |
448 | return (selectEnd >= selectStart); | 448 | return (selectEnd >= selectStart); |
449 | } | 449 | } |
450 | 450 | ||
451 | QString KateDocument::selection() const | 451 | QString KateDocument::selection() const |
452 | { | 452 | { |
453 | uint flags = 0; | 453 | uint flags = 0; |
454 | TextLine::Ptr textLine; | 454 | TextLine::Ptr textLine; |
455 | int len, z, start, end, i; | 455 | int len, z, start, end, i; |
456 | 456 | ||
457 | len = 1; | 457 | len = 1; |
458 | if (!(flags & KateView::cfVerticalSelect)) { | 458 | if (!(flags & KateView::cfVerticalSelect)) { |
459 | for (z = selectStart; z <= selectEnd; z++) { | 459 | for (z = selectStart; z <= selectEnd; z++) { |
460 | textLine = getTextLine(z); | 460 | textLine = getTextLine(z); |
461 | len += textLine->numSelected(); | 461 | len += textLine->numSelected(); |
462 | if (textLine->isSelected()) len++; | 462 | if (textLine->isSelected()) len++; |
463 | } | 463 | } |
464 | QString s; | 464 | QString s; |
465 | len = 0; | 465 | len = 0; |
466 | for (z = selectStart; z <= selectEnd; z++) { | 466 | for (z = selectStart; z <= selectEnd; z++) { |
467 | textLine = getTextLine(z); | 467 | textLine = getTextLine(z); |
468 | end = 0; | 468 | end = 0; |
469 | do { | 469 | do { |
470 | start = textLine->findUnselected(end); | 470 | start = textLine->findUnselected(end); |
471 | end = textLine->findSelected(start); | 471 | end = textLine->findSelected(start); |
472 | for (i = start; i < end; i++) { | 472 | for (i = start; i < end; i++) { |
473 | s[len] = textLine->getChar(i); | 473 | s[len] = textLine->getChar(i); |
474 | len++; | 474 | len++; |
475 | } | 475 | } |
476 | } while (start < end); | 476 | } while (start < end); |
477 | if (textLine->isSelected()) { | 477 | if (textLine->isSelected()) { |
478 | s[len] = '\n'; | 478 | s[len] = '\n'; |
479 | len++; | 479 | len++; |
480 | } | 480 | } |
481 | } | 481 | } |
482 | // s[len] = '\0'; | 482 | // s[len] = '\0'; |
483 | return s; | 483 | return s; |
484 | } else { | 484 | } else { |
485 | for (z = selectStart; z <= selectEnd; z++) { | 485 | for (z = selectStart; z <= selectEnd; z++) { |
486 | textLine = getTextLine(z); | 486 | textLine = getTextLine(z); |
487 | len += textLine->numSelected() + 1; | 487 | len += textLine->numSelected() + 1; |
488 | } | 488 | } |
489 | QString s; | 489 | QString s; |
490 | len = 0; | 490 | len = 0; |
491 | for (z = selectStart; z <= selectEnd; z++) { | 491 | for (z = selectStart; z <= selectEnd; z++) { |
492 | textLine = getTextLine(z); | 492 | textLine = getTextLine(z); |
493 | end = 0; | 493 | end = 0; |
494 | do { | 494 | do { |
495 | start = textLine->findUnselected(end); | 495 | start = textLine->findUnselected(end); |
496 | end = textLine->findSelected(start); | 496 | end = textLine->findSelected(start); |
497 | for (i = start; i < end; i++) { | 497 | for (i = start; i < end; i++) { |
498 | s[len] = textLine->getChar(i); | 498 | s[len] = textLine->getChar(i); |
499 | len++; | 499 | len++; |
500 | } | 500 | } |
501 | } while (start < end); | 501 | } while (start < end); |
502 | s[len] = '\n'; | 502 | s[len] = '\n'; |
503 | len++; | 503 | len++; |
504 | } | 504 | } |
505 | // s[len] = '\0'; // the final \0 is not counted in length() | 505 | // s[len] = '\0'; // the final \0 is not counted in length() |
506 | return s; | 506 | return s; |
507 | } | 507 | } |
508 | } | 508 | } |
509 | 509 | ||
510 | int KateDocument::numLines() const | 510 | int KateDocument::numLines() const |
511 | { | 511 | { |
512 | return buffer->count(); | 512 | return buffer->count(); |
513 | } | 513 | } |
514 | 514 | ||
515 | 515 | ||
516 | TextLine::Ptr KateDocument::getTextLine(int line) const | 516 | TextLine::Ptr KateDocument::getTextLine(int line) const |
517 | { | 517 | { |
518 | // This is a hack to get this stuff working. | 518 | // This is a hack to get this stuff working. |
519 | return buffer->line(line); | 519 | return buffer->line(line); |
520 | } | 520 | } |
521 | 521 | ||
522 | int KateDocument::textLength(int line) { | 522 | int KateDocument::textLength(int line) { |
523 | TextLine::Ptr textLine = getTextLine(line); | 523 | TextLine::Ptr textLine = getTextLine(line); |
524 | if (!textLine) return 0; | 524 | if (!textLine) return 0; |
525 | return textLine->length(); | 525 | return textLine->length(); |
526 | } | 526 | } |
527 | 527 | ||
528 | void KateDocument::setTabWidth(int chars) { | 528 | void KateDocument::setTabWidth(int chars) { |
529 | if (tabChars == chars) return; | 529 | if (tabChars == chars) return; |
530 | if (chars < 1) chars = 1; | 530 | if (chars < 1) chars = 1; |
531 | if (chars > 16) chars = 16; | 531 | if (chars > 16) chars = 16; |
532 | tabChars = chars; | 532 | tabChars = chars; |
533 | updateFontData(); | 533 | updateFontData(); |
534 | 534 | ||
535 | maxLength = -1; | 535 | maxLength = -1; |
536 | for (int i=0; i < buffer->count(); i++) | 536 | for (int i=0; i < buffer->count(); i++) |
537 | { | 537 | { |
538 | TextLine::Ptr textLine = buffer->line(i); | 538 | TextLine::Ptr textLine = buffer->line(i); |
539 | int len = textWidth(textLine,textLine->length()); | 539 | int len = textWidth(textLine,textLine->length()); |
540 | if (len > maxLength) { | 540 | if (len > maxLength) { |
541 | maxLength = len; | 541 | maxLength = len; |
542 | longestLine = textLine; | 542 | longestLine = textLine; |
543 | } | 543 | } |
544 | } | 544 | } |
545 | } | 545 | } |
546 | 546 | ||
547 | void KateDocument::setReadOnly(bool m) { | 547 | void KateDocument::setReadOnly(bool m) { |
548 | KTextEditor::View *view; | 548 | KTextEditor::View *view; |
549 | 549 | ||
550 | if (m != readOnly) { | 550 | if (m != readOnly) { |
551 | readOnly = m; | 551 | readOnly = m; |
552 | // if (readOnly) recordReset(); | 552 | // if (readOnly) recordReset(); |
553 | for (view = m_views.first(); view != 0L; view = m_views.next() ) { | 553 | for (view = m_views.first(); view != 0L; view = m_views.next() ) { |
554 | emit static_cast<KateView *>( view )->newStatus(); | 554 | emit static_cast<KateView *>( view )->newStatus(); |
555 | } | 555 | } |
556 | } | 556 | } |
557 | } | 557 | } |
558 | 558 | ||
559 | bool KateDocument::isReadOnly() const { | 559 | bool KateDocument::isReadOnly() const { |
560 | return readOnly; | 560 | return readOnly; |
561 | } | 561 | } |
562 | 562 | ||
563 | void KateDocument::setNewDoc( bool m ) | 563 | void KateDocument::setNewDoc( bool m ) |
564 | { | 564 | { |
565 | // KTextEditor::View *view; | 565 | // KTextEditor::View *view; |
566 | 566 | ||
567 | if ( m != newDoc ) | 567 | if ( m != newDoc ) |
568 | { | 568 | { |
569 | newDoc = m; | 569 | newDoc = m; |
570 | //// if (readOnly) recordReset(); | 570 | //// if (readOnly) recordReset(); |
571 | // for (view = m_views.first(); view != 0L; view = m_views.next() ) { | 571 | // for (view = m_views.first(); view != 0L; view = m_views.next() ) { |
572 | // emit static_cast<KateView *>( view )->newStatus(); | 572 | // emit static_cast<KateView *>( view )->newStatus(); |
573 | // } | 573 | // } |
574 | } | 574 | } |
575 | } | 575 | } |
576 | 576 | ||
577 | bool KateDocument::isNewDoc() const { | 577 | bool KateDocument::isNewDoc() const { |
578 | return newDoc; | 578 | return newDoc; |
579 | } | 579 | } |
580 | 580 | ||
581 | void KateDocument::setModified(bool m) { | 581 | void KateDocument::setModified(bool m) { |
582 | KTextEditor::View *view; | 582 | KTextEditor::View *view; |
583 | 583 | ||
584 | if (m != modified) { | 584 | if (m != modified) { |
585 | modified = m; | 585 | modified = m; |
586 | for (view = m_views.first(); view != 0L; view = m_views.next() ) { | 586 | for (view = m_views.first(); view != 0L; view = m_views.next() ) { |
587 | emit static_cast<KateView *>( view )->newStatus(); | 587 | emit static_cast<KateView *>( view )->newStatus(); |
588 | } | 588 | } |
589 | emit modifiedChanged (); | 589 | emit modifiedChanged (); |
590 | } | 590 | } |
591 | } | 591 | } |
592 | 592 | ||
593 | bool KateDocument::isModified() const { | 593 | bool KateDocument::isModified() const { |
594 | return modified; | 594 | return modified; |
595 | } | 595 | } |
596 | 596 | ||
597 | void KateDocument::readConfig() | 597 | void KateDocument::readConfig() |
598 | { | 598 | { |
599 | KateConfig *config = KGlobal::config(); | 599 | KateConfig *config = KGlobal::config(); |
600 | config->setGroup("Kate Document"); | 600 | config->setGroup("Kate Document"); |
601 | 601 | ||
602 | myWordWrap = config->readBoolEntry("Word Wrap On", false); | 602 | myWordWrap = config->readBoolEntry("Word Wrap On", false); |
603 | myWordWrapAt = config->readNumEntry("Word Wrap At", 80); | 603 | myWordWrapAt = config->readNumEntry("Word Wrap At", 80); |
604 | if (myWordWrap) | 604 | if (myWordWrap) |
605 | wrapText (myWordWrapAt); | 605 | wrapText (myWordWrapAt); |
606 | 606 | ||
607 | setTabWidth(config->readNumEntry("TabWidth", 8)); | 607 | setTabWidth(config->readNumEntry("TabWidth", 8)); |
608 | setUndoSteps(config->readNumEntry("UndoSteps", 50)); | 608 | setUndoSteps(config->readNumEntry("UndoSteps", 50)); |
609 | m_singleSelection = config->readBoolEntry("SingleSelection", false); | 609 | m_singleSelection = config->readBoolEntry("SingleSelection", false); |
610 | myEncoding = config->readEntry("Encoding", QString::fromLatin1(QTextCodec::codecForLocale()->name())); | 610 | myEncoding = config->readEntry("Encoding", QString::fromLatin1(QTextCodec::codecForLocale()->name())); |
611 | setFont (config->readFontEntry("Font", myFont)); | 611 | setFont (config->readFontEntry("Font", myFont)); |
612 | 612 | ||
613 | colors[0] = config->readColorEntry("Color Background", colors[0]); | 613 | colors[0] = config->readColorEntry("Color Background", colors[0]); |
614 | colors[1] = config->readColorEntry("Color Selected", colors[1]); | 614 | colors[1] = config->readColorEntry("Color Selected", colors[1]); |
615 | 615 | ||
616 | // config->sync(); | 616 | // config->sync(); |
617 | } | 617 | } |
618 | 618 | ||
619 | void KateDocument::writeConfig() | 619 | void KateDocument::writeConfig() |
620 | { | 620 | { |
621 | KateConfig *config = KGlobal::config(); | 621 | KateConfig *config = KGlobal::config(); |
622 | config->setGroup("Kate Document"); | 622 | config->setGroup("Kate Document"); |
623 | config->writeEntry("Word Wrap On", myWordWrap); | 623 | config->writeEntry("Word Wrap On", myWordWrap); |
624 | config->writeEntry("Word Wrap At", myWordWrapAt); | 624 | config->writeEntry("Word Wrap At", myWordWrapAt); |
625 | config->writeEntry("TabWidth", tabChars); | 625 | config->writeEntry("TabWidth", tabChars); |
626 | config->writeEntry("UndoSteps", undoSteps); | 626 | config->writeEntry("UndoSteps", undoSteps); |
627 | config->writeEntry("SingleSelection", m_singleSelection); | 627 | config->writeEntry("SingleSelection", m_singleSelection); |
628 | config->writeEntry("Encoding", myEncoding); | 628 | config->writeEntry("Encoding", myEncoding); |
629 | config->writeEntry("Font", myFont); | 629 | config->writeEntry("Font", myFont); |
630 | config->writeEntry("Color Background", colors[0]); | 630 | config->writeEntry("Color Background", colors[0]); |
631 | config->writeEntry("Color Selected", colors[1]); | 631 | config->writeEntry("Color Selected", colors[1]); |
632 | // config->sync(); | 632 | // config->sync(); |
633 | } | 633 | } |
634 | 634 | ||
635 | void KateDocument::readSessionConfig(KateConfig *config) | 635 | void KateDocument::readSessionConfig(KateConfig *config) |
636 | { | 636 | { |
637 | m_url = config->readEntry("URL"); // ### doesn't this break the encoding? (Simon) | 637 | m_url = config->readEntry("URL"); // ### doesn't this break the encoding? (Simon) |
638 | setHighlight(hlManager->nameFind(config->readEntry("Highlight"))); | 638 | setHighlight(hlManager->nameFind(config->readEntry("Highlight"))); |
639 | // anders: restore bookmarks if possible | 639 | // anders: restore bookmarks if possible |
640 | QValueList<int> l = config->readIntListEntry("Bookmarks"); | 640 | QValueList<int> l = config->readIntListEntry("Bookmarks"); |
641 | if ( l.count() ) { | 641 | if ( l.count() ) { |
642 | for (uint i=0; i < l.count(); i++) { | 642 | for (uint i=0; i < l.count(); i++) { |
643 | if ( numLines() < l[i] ) break; | 643 | if ( numLines() < l[i] ) break; |
644 | getTextLine( l[i] )->addMark( Bookmark ); | 644 | getTextLine( l[i] )->addMark( Bookmark ); |
645 | } | 645 | } |
646 | } | 646 | } |
647 | } | 647 | } |
648 | 648 | ||
649 | void KateDocument::writeSessionConfig(KateConfig *config) | 649 | void KateDocument::writeSessionConfig(KateConfig *config) |
650 | { | 650 | { |
651 | #if 0 | 651 | #if 0 |
652 | config->writeEntry("URL", m_url); // ### encoding?? (Simon) | 652 | config->writeEntry("URL", m_url); // ### encoding?? (Simon) |
653 | config->writeEntry("Highlight", m_highlight->name()); | 653 | config->writeEntry("Highlight", m_highlight->name()); |
654 | // anders: save bookmarks | 654 | // anders: save bookmarks |
655 | QList<Kate::Mark> l = marks(); | 655 | QList<Kate::Mark> l = marks(); |
656 | QValueList<int> ml; | 656 | QValueList<int> ml; |
657 | for (uint i=0; i < l.count(); i++) { | 657 | for (uint i=0; i < l.count(); i++) { |
658 | if ( l.at(i)->type == 1) // only save bookmarks | 658 | if ( l.at(i)->type == 1) // only save bookmarks |
659 | ml << l.at(i)->line; | 659 | ml << l.at(i)->line; |
660 | } | 660 | } |
661 | if ( ml.count() ) | 661 | if ( ml.count() ) |
662 | config->writeEntry("Bookmarks", ml); | 662 | config->writeEntry("Bookmarks", ml); |
663 | #endif | 663 | #endif |
664 | } | 664 | } |
665 | 665 | ||
666 | 666 | ||
667 | void KateDocument::setHighlight(int n) { | 667 | void KateDocument::setHighlight(int n) { |
668 | Highlight *h; | 668 | Highlight *h; |
669 | 669 | ||
670 | // hlNumber = n; | 670 | // hlNumber = n; |
671 | 671 | ||
672 | h = hlManager->getHl(n); | 672 | h = hlManager->getHl(n); |
673 | if (h == m_highlight) { | 673 | if (h == m_highlight) { |
674 | updateLines(); | 674 | updateLines(); |
675 | } else { | 675 | } else { |
676 | if (m_highlight != 0L) m_highlight->release(); | 676 | if (m_highlight != 0L) m_highlight->release(); |
677 | h->use(); | 677 | h->use(); |
678 | m_highlight = h; | 678 | m_highlight = h; |
679 | makeAttribs(); | 679 | makeAttribs(); |
680 | } | 680 | } |
681 | PreHighlightedTill=0; | 681 | PreHighlightedTill=0; |
682 | RequestPreHighlightTill=0; | 682 | RequestPreHighlightTill=0; |
683 | emit(highlightChanged()); | 683 | emit(highlightChanged()); |
684 | } | 684 | } |
685 | 685 | ||
686 | void KateDocument::makeAttribs() { | 686 | void KateDocument::makeAttribs() { |
687 | odebug << "KateDocument::makeAttribs()" << oendl; | 687 | odebug << "KateDocument::makeAttribs()" << oendl; |
688 | m_numAttribs = hlManager->makeAttribs(m_highlight, m_attribs, maxAttribs); | 688 | m_numAttribs = hlManager->makeAttribs(m_highlight, m_attribs, maxAttribs); |
689 | updateFontData(); | 689 | updateFontData(); |
690 | updateLines(); | 690 | updateLines(); |
691 | } | 691 | } |
692 | 692 | ||
693 | void KateDocument::updateFontData() { | 693 | void KateDocument::updateFontData() { |
694 | int maxAscent, maxDescent; | 694 | int maxAscent, maxDescent; |
695 | int tabWidth; | 695 | int tabWidth; |
696 | KateView *view; | 696 | KateView *view; |
697 | 697 | ||
698 | maxAscent = myFontMetrics.ascent(); | 698 | maxAscent = myFontMetrics.ascent(); |
699 | maxDescent = myFontMetrics.descent(); | 699 | maxDescent = myFontMetrics.descent(); |
700 | tabWidth = myFontMetrics.width(' '); | 700 | tabWidth = myFontMetrics.width(' '); |
701 | 701 | ||
702 | fontHeight = maxAscent + maxDescent + 1; | 702 | fontHeight = maxAscent + maxDescent + 1; |
703 | fontAscent = maxAscent; | 703 | fontAscent = maxAscent; |
704 | m_tabWidth = tabChars*tabWidth; | 704 | m_tabWidth = tabChars*tabWidth; |
705 | 705 | ||
706 | for (view = views.first(); view != 0L; view = views.next() ) { | 706 | for (view = views.first(); view != 0L; view = views.next() ) { |
707 | view->myViewInternal->drawBuffer->resize(view->width(),fontHeight); | 707 | view->myViewInternal->drawBuffer->resize(view->width(),fontHeight); |
708 | view->tagAll(); | 708 | view->tagAll(); |
709 | view->updateCursor(); | 709 | view->updateCursor(); |
710 | } | 710 | } |
711 | } | 711 | } |
712 | 712 | ||
713 | void KateDocument::hlChanged() { //slot | 713 | void KateDocument::hlChanged() { //slot |
714 | makeAttribs(); | 714 | makeAttribs(); |
715 | updateViews(); | 715 | updateViews(); |
716 | } | 716 | } |
717 | 717 | ||
718 | 718 | ||
719 | void KateDocument::addView(KTextEditor::View *view) { | 719 | void KateDocument::addView(KTextEditor::View *view) { |
720 | views.append( static_cast<KateView *>( view ) ); | 720 | views.append( static_cast<KateView *>( view ) ); |
721 | KTextEditor::Document::addView( view ); | 721 | KTextEditor::Document::addView( view ); |
722 | connect( static_cast<KateView *>( view ), SIGNAL( destroyed() ), this, SLOT( slotViewDestroyed() ) ); | 722 | connect( static_cast<KateView *>( view ), SIGNAL( destroyed() ), this, SLOT( slotViewDestroyed() ) ); |
723 | } | 723 | } |
724 | 724 | ||
725 | void KateDocument::removeView(KTextEditor::View *view) { | 725 | void KateDocument::removeView(KTextEditor::View *view) { |
726 | // if (undoView == view) recordReset(); | 726 | // if (undoView == view) recordReset(); |
727 | disconnect( static_cast<KateView *>( view ), SIGNAL( destroyed() ), this, SLOT( slotViewDestroyed() ) ); | 727 | disconnect( static_cast<KateView *>( view ), SIGNAL( destroyed() ), this, SLOT( slotViewDestroyed() ) ); |
728 | views.removeRef( static_cast<KateView *>( view ) ); | 728 | views.removeRef( static_cast<KateView *>( view ) ); |
729 | KTextEditor::Document::removeView( view ); | 729 | KTextEditor::Document::removeView( view ); |
730 | } | 730 | } |
731 | 731 | ||
732 | void KateDocument::slotViewDestroyed() | 732 | void KateDocument::slotViewDestroyed() |
733 | { | 733 | { |
734 | views.removeRef( static_cast<const KateView *>( sender() ) ); | 734 | views.removeRef( static_cast<const KateView *>( sender() ) ); |
735 | } | 735 | } |
736 | 736 | ||
737 | bool KateDocument::ownedView(KateView *view) { | 737 | bool KateDocument::ownedView(KateView *view) { |
738 | // do we own the given view? | 738 | // do we own the given view? |
739 | return (views.containsRef(view) > 0); | 739 | return (views.containsRef(view) > 0); |
740 | } | 740 | } |
741 | 741 | ||
742 | bool KateDocument::isLastView(int numViews) { | 742 | bool KateDocument::isLastView(int numViews) { |
743 | return ((int) views.count() == numViews); | 743 | return ((int) views.count() == numViews); |
744 | } | 744 | } |
745 | 745 | ||
746 | int KateDocument::textWidth(const TextLine::Ptr &textLine, int cursorX) { | 746 | int KateDocument::textWidth(const TextLine::Ptr &textLine, int cursorX) { |
747 | int x; | 747 | int x; |
748 | int z; | 748 | int z; |
749 | QChar ch; | 749 | QChar ch; |
750 | Attribute *a; | 750 | Attribute *a; |
751 | 751 | ||
752 | x = 0; | 752 | x = 0; |
753 | for (z = 0; z < cursorX; z++) { | 753 | for (z = 0; z < cursorX; z++) { |
754 | ch = textLine->getChar(z); | 754 | ch = textLine->getChar(z); |
755 | a = &m_attribs[textLine->getAttr(z)]; | 755 | a = &m_attribs[textLine->getAttr(z)]; |
756 | 756 | ||
757 | if (ch == '\t') | 757 | if (ch == '\t') |
758 | x += m_tabWidth - (x % m_tabWidth); | 758 | x += m_tabWidth - (x % m_tabWidth); |
759 | else if (a->bold && a->italic) | 759 | else if (a->bold && a->italic) |
760 | x += myFontMetricsBI.width(ch); | 760 | x += myFontMetricsBI.width(ch); |
761 | else if (a->bold) | 761 | else if (a->bold) |
762 | x += myFontMetricsBold.width(ch); | 762 | x += myFontMetricsBold.width(ch); |
763 | else if (a->italic) | 763 | else if (a->italic) |
764 | x += myFontMetricsItalic.width(ch); | 764 | x += myFontMetricsItalic.width(ch); |
765 | else | 765 | else |
766 | x += myFontMetrics.width(ch); | 766 | x += myFontMetrics.width(ch); |
767 | } | 767 | } |
768 | return x; | 768 | return x; |
769 | } | 769 | } |
770 | 770 | ||
771 | int KateDocument::textWidth(PointStruc &cursor) { | 771 | int KateDocument::textWidth(PointStruc &cursor) { |
772 | if (cursor.x < 0) | 772 | if (cursor.x < 0) |
773 | cursor.x = 0; | 773 | cursor.x = 0; |
774 | if (cursor.y < 0) | 774 | if (cursor.y < 0) |
775 | cursor.y = 0; | 775 | cursor.y = 0; |
776 | if (cursor.y >= numLines()) | 776 | if (cursor.y >= numLines()) |
777 | cursor.y = lastLine(); | 777 | cursor.y = lastLine(); |
778 | return textWidth(getTextLine(cursor.y),cursor.x); | 778 | return textWidth(getTextLine(cursor.y),cursor.x); |
779 | } | 779 | } |
780 | 780 | ||
781 | int KateDocument::textWidth(bool wrapCursor, PointStruc &cursor, int xPos) { | 781 | int KateDocument::textWidth(bool wrapCursor, PointStruc &cursor, int xPos) { |
782 | int len; | 782 | int len; |
783 | int x, oldX; | 783 | int x, oldX; |
784 | int z; | 784 | int z; |
785 | QChar ch; | 785 | QChar ch; |
786 | Attribute *a; | 786 | Attribute *a; |
787 | 787 | ||
788 | if (cursor.y < 0) cursor.y = 0; | 788 | if (cursor.y < 0) cursor.y = 0; |
789 | if (cursor.y > lastLine()) cursor.y = lastLine(); | 789 | if (cursor.y > lastLine()) cursor.y = lastLine(); |
790 | TextLine::Ptr textLine = getTextLine(cursor.y); | 790 | TextLine::Ptr textLine = getTextLine(cursor.y); |
791 | len = textLine->length(); | 791 | len = textLine->length(); |
792 | 792 | ||
793 | x = oldX = z = 0; | 793 | x = oldX = z = 0; |
794 | while (x < xPos && (!wrapCursor || z < len)) { | 794 | while (x < xPos && (!wrapCursor || z < len)) { |
795 | oldX = x; | 795 | oldX = x; |
796 | ch = textLine->getChar(z); | 796 | ch = textLine->getChar(z); |
797 | a = &m_attribs[textLine->getAttr(z)]; | 797 | a = &m_attribs[textLine->getAttr(z)]; |
798 | 798 | ||
799 | if (ch == '\t') | 799 | if (ch == '\t') |
800 | x += m_tabWidth - (x % m_tabWidth); | 800 | x += m_tabWidth - (x % m_tabWidth); |
801 | else if (a->bold && a->italic) | 801 | else if (a->bold && a->italic) |
802 | x += myFontMetricsBI.width(ch); | 802 | x += myFontMetricsBI.width(ch); |
803 | else if (a->bold) | 803 | else if (a->bold) |
804 | x += myFontMetricsBold.width(ch); | 804 | x += myFontMetricsBold.width(ch); |
805 | else if (a->italic) | 805 | else if (a->italic) |
806 | x += myFontMetricsItalic.width(ch); | 806 | x += myFontMetricsItalic.width(ch); |
807 | else | 807 | else |
808 | x += myFontMetrics.width(ch); | 808 | x += myFontMetrics.width(ch); |
809 | 809 | ||
810 | z++; | 810 | z++; |
811 | } | 811 | } |
812 | if (xPos - oldX < x - xPos && z > 0) { | 812 | if (xPos - oldX < x - xPos && z > 0) { |
813 | z--; | 813 | z--; |
814 | x = oldX; | 814 | x = oldX; |
815 | } | 815 | } |
816 | cursor.x = z; | 816 | cursor.x = z; |
817 | return x; | 817 | return x; |
818 | } | 818 | } |
819 | 819 | ||
820 | 820 | ||
821 | int KateDocument::textPos(const TextLine::Ptr &textLine, int xPos) { | 821 | int KateDocument::textPos(const TextLine::Ptr &textLine, int xPos) { |
822 | int x, oldX; | 822 | int x, oldX; |
823 | int z; | 823 | int z; |
824 | QChar ch; | 824 | QChar ch; |
825 | Attribute *a; | 825 | Attribute *a; |
826 | 826 | ||
827 | x = oldX = z = 0; | 827 | x = oldX = z = 0; |
828 | while (x < xPos) { // && z < len) { | 828 | while (x < xPos) { // && z < len) { |
829 | oldX = x; | 829 | oldX = x; |
830 | ch = textLine->getChar(z); | 830 | ch = textLine->getChar(z); |
831 | a = &m_attribs[textLine->getAttr(z)]; | 831 | a = &m_attribs[textLine->getAttr(z)]; |
832 | 832 | ||
833 | if (ch == '\t') | 833 | if (ch == '\t') |
834 | x += m_tabWidth - (x % m_tabWidth); | 834 | x += m_tabWidth - (x % m_tabWidth); |
835 | else if (a->bold && a->italic) | 835 | else if (a->bold && a->italic) |
836 | x += myFontMetricsBI.width(ch); | 836 | x += myFontMetricsBI.width(ch); |
837 | else if (a->bold) | 837 | else if (a->bold) |
838 | x += myFontMetricsBold.width(ch); | 838 | x += myFontMetricsBold.width(ch); |
839 | else if (a->italic) | 839 | else if (a->italic) |
840 | x += myFontMetricsItalic.width(ch); | 840 | x += myFontMetricsItalic.width(ch); |
841 | else | 841 | else |
842 | x += myFontMetrics.width(ch); | 842 | x += myFontMetrics.width(ch); |
843 | 843 | ||
844 | z++; | 844 | z++; |
845 | } | 845 | } |
846 | if (xPos - oldX < x - xPos && z > 0) { | 846 | if (xPos - oldX < x - xPos && z > 0) { |
847 | z--; | 847 | z--; |
848 | // newXPos = oldX; | 848 | // newXPos = oldX; |
849 | }// else newXPos = x; | 849 | }// else newXPos = x; |
850 | return z; | 850 | return z; |
851 | } | 851 | } |
852 | 852 | ||
853 | int KateDocument::textWidth() { | 853 | int KateDocument::textWidth() { |
854 | return int(maxLength + 8); | 854 | return int(maxLength + 8); |
855 | } | 855 | } |
856 | 856 | ||
857 | int KateDocument::textHeight() { | 857 | int KateDocument::textHeight() { |
858 | return numLines()*fontHeight; | 858 | return numLines()*fontHeight; |
859 | } | 859 | } |
860 | 860 | ||
861 | void KateDocument::insert(VConfig &c, const QString &s) { | 861 | void KateDocument::insert(VConfig &c, const QString &s) { |
862 | int pos; | 862 | int pos; |
863 | QChar ch; | 863 | QChar ch; |
864 | QString buf; | 864 | QString buf; |
865 | 865 | ||
866 | if (s.isEmpty()) return; | 866 | if (s.isEmpty()) return; |
867 | 867 | ||
868 | recordStart(c, KateActionGroup::ugPaste); | 868 | recordStart(c, KateActionGroup::ugPaste); |
869 | 869 | ||
870 | pos = 0; | 870 | pos = 0; |
871 | if (!(c.flags & KateView::cfVerticalSelect)) { | 871 | if (!(c.flags & KateView::cfVerticalSelect)) { |
872 | do { | 872 | do { |
873 | ch = s[pos]; | 873 | ch = s[pos]; |
874 | if (ch.isPrint() || ch == '\t') { | 874 | if (ch.isPrint() || ch == '\t') { |
875 | buf += ch; // append char to buffer | 875 | buf += ch; // append char to buffer |
876 | } else if (ch == '\n') { | 876 | } else if (ch == '\n') { |
877 | recordAction(KateAction::newLine, c.cursor); // wrap contents behind cursor to new line | 877 | recordAction(KateAction::newLine, c.cursor); // wrap contents behind cursor to new line |
878 | recordInsert(c, buf); // append to old line | 878 | recordInsert(c, buf); // append to old line |
879 | // c.cursor.x += buf.length(); | 879 | // c.cursor.x += buf.length(); |
880 | buf.truncate(0); // clear buffer | 880 | buf.truncate(0); // clear buffer |
881 | c.cursor.y++; | 881 | c.cursor.y++; |
882 | c.cursor.x = 0; | 882 | c.cursor.x = 0; |
883 | } | 883 | } |
884 | pos++; | 884 | pos++; |
885 | } while (pos < (int) s.length()); | 885 | } while (pos < (int) s.length()); |
886 | } else { | 886 | } else { |
887 | int xPos; | 887 | int xPos; |
888 | 888 | ||
889 | xPos = textWidth(c.cursor); | 889 | xPos = textWidth(c.cursor); |
890 | do { | 890 | do { |
891 | ch = s[pos]; | 891 | ch = s[pos]; |
892 | if (ch.isPrint() || ch == '\t') { | 892 | if (ch.isPrint() || ch == '\t') { |
893 | buf += ch; | 893 | buf += ch; |
894 | } else if (ch == '\n') { | 894 | } else if (ch == '\n') { |
895 | recordInsert(c, buf); | 895 | recordInsert(c, buf); |
896 | c.cursor.x += buf.length(); | 896 | c.cursor.x += buf.length(); |
897 | buf.truncate(0); | 897 | buf.truncate(0); |
898 | c.cursor.y++; | 898 | c.cursor.y++; |
899 | if (c.cursor.y >= numLines()) | 899 | if (c.cursor.y >= numLines()) |
900 | recordAction(KateAction::insLine, c.cursor); | 900 | recordAction(KateAction::insLine, c.cursor); |
901 | c.cursor.x = textPos(getTextLine(c.cursor.y), xPos); | 901 | c.cursor.x = textPos(getTextLine(c.cursor.y), xPos); |
902 | } | 902 | } |
903 | pos++; | 903 | pos++; |
904 | } while (pos < (int) s.length()); | 904 | } while (pos < (int) s.length()); |
905 | } | 905 | } |
906 | recordInsert(c, buf); | 906 | recordInsert(c, buf); |
907 | c.cursor.x += buf.length(); | 907 | c.cursor.x += buf.length(); |
908 | recordEnd(c); | 908 | recordEnd(c); |
909 | } | 909 | } |
910 | 910 | ||
911 | void KateDocument::insertFile(VConfig &c, QIODevice &dev) | 911 | void KateDocument::insertFile(VConfig &c, QIODevice &dev) |
912 | { | 912 | { |
913 | recordStart(c, KateActionGroup::ugPaste); | 913 | recordStart(c, KateActionGroup::ugPaste); |
914 | 914 | ||
915 | QString buf; | 915 | QString buf; |
916 | QChar ch, last; | 916 | QChar ch, last; |
917 | 917 | ||
918 | QTextStream stream( &dev ); | 918 | QTextStream stream( &dev ); |
919 | 919 | ||
920 | while ( !stream.atEnd() ) { | 920 | while ( !stream.atEnd() ) { |
921 | stream >> ch; | 921 | stream >> ch; |
922 | 922 | ||
923 | if (ch.isPrint() || ch == '\t') { | 923 | if (ch.isPrint() || ch == '\t') { |
924 | buf += ch; | 924 | buf += ch; |
925 | } else if (ch == '\n' || ch == '\r') { | 925 | } else if (ch == '\n' || ch == '\r') { |
926 | if (last != '\r' || ch != '\n') { | 926 | if (last != '\r' || ch != '\n') { |
927 | recordAction(KateAction::newLine, c.cursor); | 927 | recordAction(KateAction::newLine, c.cursor); |
928 | recordInsert(c, buf); | 928 | recordInsert(c, buf); |
929 | buf.truncate(0); | 929 | buf.truncate(0); |
930 | c.cursor.y++; | 930 | c.cursor.y++; |
931 | c.cursor.x = 0; | 931 | c.cursor.x = 0; |
932 | } | 932 | } |
933 | last = ch; | 933 | last = ch; |
934 | } | 934 | } |
935 | } | 935 | } |
936 | 936 | ||
937 | recordInsert(c, buf); | 937 | recordInsert(c, buf); |
938 | recordEnd(c); | 938 | recordEnd(c); |
939 | } | 939 | } |
940 | 940 | ||
941 | int KateDocument::currentColumn(PointStruc &cursor) { | 941 | int KateDocument::currentColumn(PointStruc &cursor) { |
942 | return getTextLine(cursor.y)->cursorX(cursor.x,tabChars); | 942 | return getTextLine(cursor.y)->cursorX(cursor.x,tabChars); |
943 | } | 943 | } |
944 | 944 | ||
945 | bool KateDocument::insertChars(VConfig &c, const QString &chars) { | 945 | bool KateDocument::insertChars(VConfig &c, const QString &chars) { |
946 | int z, pos, l; | 946 | int z, pos, l; |
947 | bool onlySpaces; | 947 | bool onlySpaces; |
948 | QChar ch; | 948 | QChar ch; |
949 | QString buf; | 949 | QString buf; |
950 | 950 | ||
951 | TextLine::Ptr textLine = getTextLine(c.cursor.y); | 951 | TextLine::Ptr textLine = getTextLine(c.cursor.y); |
952 | 952 | ||
953 | pos = 0; | 953 | pos = 0; |
954 | onlySpaces = true; | 954 | onlySpaces = true; |
955 | for (z = 0; z < (int) chars.length(); z++) { | 955 | for (z = 0; z < (int) chars.length(); z++) { |
956 | ch = chars[z]; | 956 | ch = chars[z]; |
957 | if (ch == '\t' && c.flags & KateView::cfReplaceTabs) { | 957 | if (ch == '\t' && c.flags & KateView::cfReplaceTabs) { |
958 | l = tabChars - (textLine->cursorX(c.cursor.x, tabChars) % tabChars); | 958 | l = tabChars - (textLine->cursorX(c.cursor.x, tabChars) % tabChars); |
959 | while (l > 0) { | 959 | while (l > 0) { |
960 | buf.insert(pos, ' '); | 960 | buf.insert(pos, ' '); |
961 | pos++; | 961 | pos++; |
962 | l--; | 962 | l--; |
963 | } | 963 | } |
964 | } else if (ch.isPrint() || ch == '\t') { | 964 | } else if (ch.isPrint() || ch == '\t') { |
965 | buf.insert(pos, ch); | 965 | buf.insert(pos, ch); |
966 | pos++; | 966 | pos++; |
967 | if (ch != ' ') onlySpaces = false; | 967 | if (ch != ' ') onlySpaces = false; |
968 | if (c.flags & KateView::cfAutoBrackets) { | 968 | if (c.flags & KateView::cfAutoBrackets) { |
969 | if (ch == '(') buf.insert(pos, ')'); | 969 | if (ch == '(') buf.insert(pos, ')'); |
970 | if (ch == '[') buf.insert(pos, ']'); | 970 | if (ch == '[') buf.insert(pos, ']'); |
971 | if (ch == '{') buf.insert(pos, '}'); | 971 | if (ch == '{') buf.insert(pos, '}'); |
972 | } | 972 | } |
973 | } | 973 | } |
974 | } | 974 | } |
975 | //pos = cursor increment | 975 | //pos = cursor increment |
976 | 976 | ||
977 | //return false if nothing has to be inserted | 977 | //return false if nothing has to be inserted |
978 | if (buf.isEmpty()) return false; | 978 | if (buf.isEmpty()) return false; |
979 | 979 | ||
980 | //auto deletion of the marked text occurs not very often and can therefore | 980 | //auto deletion of the marked text occurs not very often and can therefore |
981 | // be recorded separately | 981 | // be recorded separately |
982 | if (c.flags &KateView:: cfDelOnInput) delMarkedText(c); | 982 | if (c.flags &KateView:: cfDelOnInput) delMarkedText(c); |
983 | 983 | ||
984 | recordStart(c, KateActionGroup::ugInsChar); | 984 | recordStart(c, KateActionGroup::ugInsChar); |
985 | recordReplace(c/*.cursor*/, (c.flags & KateView::cfOvr) ? buf.length() : 0, buf); | 985 | recordReplace(c/*.cursor*/, (c.flags & KateView::cfOvr) ? buf.length() : 0, buf); |
986 | c.cursor.x += pos; | 986 | c.cursor.x += pos; |
987 | 987 | ||
988 | if (myWordWrap && myWordWrapAt > 0) { | 988 | if (myWordWrap && myWordWrapAt > 0) { |
989 | int line; | 989 | int line; |
990 | const QChar *s; | 990 | const QChar *s; |
991 | // int pos; | 991 | // int pos; |
992 | PointStruc actionCursor; | 992 | PointStruc actionCursor; |
993 | 993 | ||
994 | line = c.cursor.y; | 994 | line = c.cursor.y; |
995 | do { | 995 | do { |
996 | textLine = getTextLine(line); | 996 | textLine = getTextLine(line); |
997 | s = textLine->getText(); | 997 | s = textLine->getText(); |
998 | l = textLine->length(); | 998 | l = textLine->length(); |
999 | for (z = myWordWrapAt; z < l; z++) if (!s[z].isSpace()) break; //search for text to wrap | 999 | for (z = myWordWrapAt; z < l; z++) if (!s[z].isSpace()) break; //search for text to wrap |
1000 | if (z >= l) break; // nothing more to wrap | 1000 | if (z >= l) break; // nothing more to wrap |
1001 | pos = myWordWrapAt; | 1001 | pos = myWordWrapAt; |
1002 | for (; z >= 0; z--) { //find wrap position | 1002 | for (; z >= 0; z--) { //find wrap position |
1003 | if (s[z].isSpace()) { | 1003 | if (s[z].isSpace()) { |
1004 | pos = z + 1; | 1004 | pos = z + 1; |
1005 | break; | 1005 | break; |
1006 | } | 1006 | } |
1007 | } | 1007 | } |
1008 | //pos = wrap position | 1008 | //pos = wrap position |
1009 | 1009 | ||
1010 | if (line == c.cursor.y && pos <= c.cursor.x) { | 1010 | if (line == c.cursor.y && pos <= c.cursor.x) { |
1011 | //wrap cursor | 1011 | //wrap cursor |
1012 | c.cursor.y++; | 1012 | c.cursor.y++; |
1013 | c.cursor.x -= pos; | 1013 | c.cursor.x -= pos; |
1014 | } | 1014 | } |
1015 | 1015 | ||
1016 | if (line == lastLine() || (getTextLine(line+1)->length() == 0) ) { | 1016 | if (line == lastLine() || (getTextLine(line+1)->length() == 0) ) { |
1017 | //at end of doc: create new line | 1017 | //at end of doc: create new line |
1018 | actionCursor.x = pos; | 1018 | actionCursor.x = pos; |
1019 | actionCursor.y = line; | 1019 | actionCursor.y = line; |
1020 | recordAction(KateAction::newLine,actionCursor); | 1020 | recordAction(KateAction::newLine,actionCursor); |
1021 | } else { | 1021 | } else { |
1022 | //wrap | 1022 | //wrap |
1023 | actionCursor.y = line + 1; | 1023 | actionCursor.y = line + 1; |
1024 | if (!s[l - 1].isSpace()) { //add space in next line if necessary | 1024 | if (!s[l - 1].isSpace()) { //add space in next line if necessary |
1025 | actionCursor.x = 0; | 1025 | actionCursor.x = 0; |
1026 | recordInsert(actionCursor, " "); | 1026 | recordInsert(actionCursor, " "); |
1027 | } | 1027 | } |
1028 | actionCursor.x = textLine->length() - pos; | 1028 | actionCursor.x = textLine->length() - pos; |
1029 | recordAction(KateAction::wordWrap, actionCursor); | 1029 | recordAction(KateAction::wordWrap, actionCursor); |
1030 | } | 1030 | } |
1031 | line++; | 1031 | line++; |
1032 | } while (true); | 1032 | } while (true); |
1033 | } | 1033 | } |
1034 | recordEnd(c); | 1034 | recordEnd(c); |
1035 | return true; | 1035 | return true; |
1036 | } | 1036 | } |
1037 | 1037 | ||
1038 | QString tabString(int pos, int tabChars) { | 1038 | QString tabString(int pos, int tabChars) { |
1039 | QString s; | 1039 | QString s; |
1040 | while (pos >= tabChars) { | 1040 | while (pos >= tabChars) { |
1041 | s += '\t'; | 1041 | s += '\t'; |
1042 | pos -= tabChars; | 1042 | pos -= tabChars; |
1043 | } | 1043 | } |
1044 | while (pos > 0) { | 1044 | while (pos > 0) { |
1045 | s += ' '; | 1045 | s += ' '; |
1046 | pos--; | 1046 | pos--; |
1047 | } | 1047 | } |
1048 | return s; | 1048 | return s; |
1049 | } | 1049 | } |
1050 | 1050 | ||
1051 | void KateDocument::newLine(VConfig &c) { | 1051 | void KateDocument::newLine(VConfig &c) { |
1052 | 1052 | ||
1053 | //auto deletion of marked text is done by the view to have a more | 1053 | //auto deletion of marked text is done by the view to have a more |
1054 | // "low level" KateDocument::newLine method | 1054 | // "low level" KateDocument::newLine method |
1055 | recordStart(c, KateActionGroup::ugInsLine); | 1055 | recordStart(c, KateActionGroup::ugInsLine); |
1056 | 1056 | ||
1057 | if (!(c.flags & KateView::cfAutoIndent)) { | 1057 | if (!(c.flags & KateView::cfAutoIndent)) { |
1058 | recordAction(KateAction::newLine,c.cursor); | 1058 | recordAction(KateAction::newLine,c.cursor); |
1059 | c.cursor.y++; | 1059 | c.cursor.y++; |
1060 | c.cursor.x = 0; | 1060 | c.cursor.x = 0; |
1061 | } else { | 1061 | } else { |
1062 | TextLine::Ptr textLine = getTextLine(c.cursor.y); | 1062 | TextLine::Ptr textLine = getTextLine(c.cursor.y); |
1063 | int pos = textLine->firstChar(); | 1063 | int pos = textLine->firstChar(); |
1064 | if (c.cursor.x < pos) c.cursor.x = pos; // place cursor on first char if before | 1064 | if (c.cursor.x < pos) c.cursor.x = pos; // place cursor on first char if before |
1065 | 1065 | ||
1066 | int y = c.cursor.y; | 1066 | int y = c.cursor.y; |
1067 | while ((y > 0) && (pos < 0)) { // search a not empty text line | 1067 | while ((y > 0) && (pos < 0)) { // search a not empty text line |
1068 | textLine = getTextLine(--y); | 1068 | textLine = getTextLine(--y); |
1069 | pos = textLine->firstChar(); | 1069 | pos = textLine->firstChar(); |
1070 | } | 1070 | } |
1071 | recordAction(KateAction::newLine, c.cursor); | 1071 | recordAction(KateAction::newLine, c.cursor); |
1072 | c.cursor.y++; | 1072 | c.cursor.y++; |
1073 | c.cursor.x = 0; | 1073 | c.cursor.x = 0; |
1074 | if (pos > 0) { | 1074 | if (pos > 0) { |
1075 | pos = textLine->cursorX(pos, tabChars); | 1075 | pos = textLine->cursorX(pos, tabChars); |
1076 | // if (getTextLine(c.cursor.y)->length() > 0) { | 1076 | // if (getTextLine(c.cursor.y)->length() > 0) { |
1077 | QString s = tabString(pos, (c.flags & KateView::cfSpaceIndent) ? 0xffffff : tabChars); | 1077 | QString s = tabString(pos, (c.flags & KateView::cfSpaceIndent) ? 0xffffff : tabChars); |
1078 | recordInsert(c.cursor, s); | 1078 | recordInsert(c.cursor, s); |
1079 | pos = s.length(); | 1079 | pos = s.length(); |
1080 | // } | 1080 | // } |
1081 | // recordInsert(c.cursor, QString(textLine->getText(), pos)); | 1081 | // recordInsert(c.cursor, QString(textLine->getText(), pos)); |
1082 | c.cursor.x = pos; | 1082 | c.cursor.x = pos; |
1083 | } | 1083 | } |
1084 | } | 1084 | } |
1085 | 1085 | ||
1086 | recordEnd(c); | 1086 | recordEnd(c); |
1087 | } | 1087 | } |
1088 | 1088 | ||
1089 | void KateDocument::killLine(VConfig &c) { | 1089 | void KateDocument::killLine(VConfig &c) { |
1090 | 1090 | ||
1091 | recordStart(c, KateActionGroup::ugDelLine); | 1091 | recordStart(c, KateActionGroup::ugDelLine); |
1092 | c.cursor.x = 0; | 1092 | c.cursor.x = 0; |
1093 | recordDelete(c.cursor, 0xffffff); | 1093 | recordDelete(c.cursor, 0xffffff); |
1094 | if (c.cursor.y < lastLine()) { | 1094 | if (c.cursor.y < lastLine()) { |
1095 | recordAction(KateAction::killLine, c.cursor); | 1095 | recordAction(KateAction::killLine, c.cursor); |
1096 | } | 1096 | } |
1097 | recordEnd(c); | 1097 | recordEnd(c); |
1098 | } | 1098 | } |
1099 | 1099 | ||
1100 | void KateDocument::backspace(VConfig &c) { | 1100 | void KateDocument::backspace(VConfig &c) { |
1101 | 1101 | ||
1102 | if (c.cursor.x <= 0 && c.cursor.y <= 0) return; | 1102 | if (c.cursor.x <= 0 && c.cursor.y <= 0) return; |
1103 | 1103 | ||
1104 | if (c.cursor.x > 0) { | 1104 | if (c.cursor.x > 0) { |
1105 | recordStart(c, KateActionGroup::ugDelChar); | 1105 | recordStart(c, KateActionGroup::ugDelChar); |
1106 | if (!(c.flags & KateView::cfBackspaceIndents)) { | 1106 | if (!(c.flags & KateView::cfBackspaceIndents)) { |
1107 | // ordinary backspace | 1107 | // ordinary backspace |
1108 | c.cursor.x--; | 1108 | c.cursor.x--; |
1109 | recordDelete(c.cursor, 1); | 1109 | recordDelete(c.cursor, 1); |
1110 | } else { | 1110 | } else { |
1111 | // backspace indents: erase to next indent position | 1111 | // backspace indents: erase to next indent position |
1112 | int l = 1; // del one char | 1112 | int l = 1; // del one char |
1113 | 1113 | ||
1114 | TextLine::Ptr textLine = getTextLine(c.cursor.y); | 1114 | TextLine::Ptr textLine = getTextLine(c.cursor.y); |
1115 | int pos = textLine->firstChar(); | 1115 | int pos = textLine->firstChar(); |
1116 | if (pos < 0 || pos >= c.cursor.x) { | 1116 | if (pos < 0 || pos >= c.cursor.x) { |
1117 | // only spaces on left side of cursor | 1117 | // only spaces on left side of cursor |
1118 | // search a line with less spaces | 1118 | // search a line with less spaces |
1119 | int y = c.cursor.y; | 1119 | int y = c.cursor.y; |
1120 | while (y > 0) { | 1120 | while (y > 0) { |
1121 | textLine = getTextLine(--y); | 1121 | textLine = getTextLine(--y); |
1122 | pos = textLine->firstChar(); | 1122 | pos = textLine->firstChar(); |
1123 | if (pos >= 0 && pos < c.cursor.x) { | 1123 | if (pos >= 0 && pos < c.cursor.x) { |
1124 | l = c.cursor.x - pos; // del more chars | 1124 | l = c.cursor.x - pos; // del more chars |
1125 | break; | 1125 | break; |
1126 | } | 1126 | } |
1127 | } | 1127 | } |
1128 | } | 1128 | } |
1129 | // break effectively jumps here | 1129 | // break effectively jumps here |
1130 | c.cursor.x -= l; | 1130 | c.cursor.x -= l; |
1131 | recordDelete(c.cursor, l); | 1131 | recordDelete(c.cursor, l); |
1132 | } | 1132 | } |
1133 | } else { | 1133 | } else { |
1134 | // c.cursor.x == 0: wrap to previous line | 1134 | // c.cursor.x == 0: wrap to previous line |
1135 | recordStart(c, KateActionGroup::ugDelLine); | 1135 | recordStart(c, KateActionGroup::ugDelLine); |
1136 | c.cursor.y--; | 1136 | c.cursor.y--; |
1137 | c.cursor.x = getTextLine(c.cursor.y)->length(); | 1137 | c.cursor.x = getTextLine(c.cursor.y)->length(); |
1138 | recordAction(KateAction::delLine,c.cursor); | 1138 | recordAction(KateAction::delLine,c.cursor); |
1139 | } | 1139 | } |
1140 | recordEnd(c); | 1140 | recordEnd(c); |
1141 | } | 1141 | } |
1142 | 1142 | ||
1143 | 1143 | ||
1144 | void KateDocument::del(VConfig &c) { | 1144 | void KateDocument::del(VConfig &c) { |
1145 | TextLine::Ptr textLine = getTextLine(c.cursor.y); | 1145 | TextLine::Ptr textLine = getTextLine(c.cursor.y); |
1146 | int len = (c.flags & KateView::cfRemoveSpaces) ? textLine->lastChar() : textLine->length(); | 1146 | int len = (c.flags & KateView::cfRemoveSpaces) ? textLine->lastChar() : textLine->length(); |
1147 | if (c.cursor.x < len/*getTextLine(c.cursor.y)->length()*/) { | 1147 | if (c.cursor.x < len/*getTextLine(c.cursor.y)->length()*/) { |
1148 | // delete one character | 1148 | // delete one character |
1149 | recordStart(c, KateActionGroup::ugDelChar); | 1149 | recordStart(c, KateActionGroup::ugDelChar); |
1150 | recordDelete(c.cursor, 1); | 1150 | recordDelete(c.cursor, 1); |
1151 | recordEnd(c); | 1151 | recordEnd(c); |
1152 | } else { | 1152 | } else { |
1153 | if (c.cursor.y < lastLine()) { | 1153 | if (c.cursor.y < lastLine()) { |
1154 | // wrap next line to this line | 1154 | // wrap next line to this line |
1155 | textLine->truncate(c.cursor.x); // truncate spaces | 1155 | textLine->truncate(c.cursor.x); // truncate spaces |
1156 | recordStart(c, KateActionGroup::ugDelLine); | 1156 | recordStart(c, KateActionGroup::ugDelLine); |
1157 | recordAction(KateAction::delLine,c.cursor); | 1157 | recordAction(KateAction::delLine,c.cursor); |
1158 | recordEnd(c); | 1158 | recordEnd(c); |
1159 | } | 1159 | } |
1160 | } | 1160 | } |
1161 | } | 1161 | } |
1162 | 1162 | ||
1163 | void KateDocument::clear() { | 1163 | void KateDocument::clear() { |
1164 | PointStruc cursor; | 1164 | PointStruc cursor; |
1165 | KateView *view; | 1165 | KateView *view; |
1166 | 1166 | ||
1167 | setPseudoModal(0L); | 1167 | setPseudoModal(0L); |
1168 | cursor.x = cursor.y = 0; | 1168 | cursor.x = cursor.y = 0; |
1169 | for (view = views.first(); view != 0L; view = views.next() ) { | 1169 | for (view = views.first(); view != 0L; view = views.next() ) { |
1170 | view->updateCursor(cursor); | 1170 | view->updateCursor(cursor); |
1171 | view->tagAll(); | 1171 | view->tagAll(); |
1172 | } | 1172 | } |
1173 | 1173 | ||
1174 | eolMode = KateDocument::eolUnix; | 1174 | eolMode = KateDocument::eolUnix; |
1175 | 1175 | ||
1176 | buffer->clear(); | 1176 | buffer->clear(); |
1177 | longestLine = buffer->line(0); | 1177 | longestLine = buffer->line(0); |
1178 | 1178 | ||
1179 | maxLength = 0; | 1179 | maxLength = 0; |
1180 | 1180 | ||
1181 | select.x = -1; | 1181 | select.x = -1; |
1182 | 1182 | ||
1183 | selectStart = 0xffffff; | 1183 | selectStart = 0xffffff; |
1184 | selectEnd = 0; | 1184 | selectEnd = 0; |
1185 | oldMarkState = false; | 1185 | oldMarkState = false; |
1186 | 1186 | ||
1187 | setModified(false); | 1187 | setModified(false); |
1188 | 1188 | ||
1189 | undoList.clear(); | 1189 | undoList.clear(); |
1190 | currentUndo = 0; | 1190 | currentUndo = 0; |
1191 | newUndo(); | 1191 | newUndo(); |
1192 | } | 1192 | } |
1193 | 1193 | ||
1194 | void KateDocument::cut(VConfig &c) { | 1194 | void KateDocument::cut(VConfig &c) { |
1195 | 1195 | ||
1196 | if (selectEnd < selectStart) return; | 1196 | if (selectEnd < selectStart) return; |
1197 | 1197 | ||
1198 | copy(c.flags); | 1198 | copy(c.flags); |
1199 | delMarkedText(c); | 1199 | delMarkedText(c); |
1200 | } | 1200 | } |
1201 | 1201 | ||
1202 | void KateDocument::copy(int flags) { | 1202 | void KateDocument::copy(int flags) { |
1203 | 1203 | ||
1204 | if (selectEnd < selectStart) return; | 1204 | if (selectEnd < selectStart) return; |
1205 | 1205 | ||
1206 | QString s = markedText(flags); | 1206 | QString s = markedText(flags); |
1207 | if (!s.isEmpty()) { | 1207 | if (!s.isEmpty()) { |
1208 | //#if defined(_WS_X11_) | 1208 | //#if defined(_WS_X11_) |
1209 | if (m_singleSelection) | 1209 | if (m_singleSelection) |
1210 | disconnect(QApplication::clipboard(), SIGNAL(dataChanged()), this, 0); | 1210 | disconnect(QApplication::clipboard(), SIGNAL(dataChanged()), this, 0); |
1211 | //#endif | 1211 | //#endif |
1212 | QApplication::clipboard()->setText(s); | 1212 | QApplication::clipboard()->setText(s); |
1213 | //#if defined(_WS_X11_) | 1213 | //#if defined(_WS_X11_) |
1214 | if (m_singleSelection) { | 1214 | if (m_singleSelection) { |
1215 | connect(QApplication::clipboard(), SIGNAL(dataChanged()), | 1215 | connect(QApplication::clipboard(), SIGNAL(dataChanged()), |
1216 | this, SLOT(clipboardChanged())); | 1216 | this, SLOT(clipboardChanged())); |
1217 | } | 1217 | } |
1218 | //#endif | 1218 | //#endif |
1219 | } | 1219 | } |
1220 | } | 1220 | } |
1221 | 1221 | ||
1222 | void KateDocument::paste(VConfig &c) { | 1222 | void KateDocument::paste(VConfig &c) { |
1223 | QString s = QApplication::clipboard()->text(); | 1223 | QString s = QApplication::clipboard()->text(); |
1224 | if (!s.isEmpty()) { | 1224 | if (!s.isEmpty()) { |
1225 | insert(c, s); | 1225 | insert(c, s); |
1226 | } | 1226 | } |
1227 | } | 1227 | } |
1228 | 1228 | ||
1229 | void KateDocument::toggleRect(int start, int end, int x1, int x2) { | 1229 | void KateDocument::toggleRect(int start, int end, int x1, int x2) { |
1230 | int z, line; | 1230 | int z, line; |
1231 | bool t; | 1231 | bool t; |
1232 | 1232 | ||
1233 | if (x1 > x2) { | 1233 | if (x1 > x2) { |
1234 | z = x1; | 1234 | z = x1; |
1235 | x1 = x2; | 1235 | x1 = x2; |
1236 | x2 = z; | 1236 | x2 = z; |
1237 | } | 1237 | } |
1238 | if (start > end) { | 1238 | if (start > end) { |
1239 | z = start; | 1239 | z = start; |
1240 | start = end; | 1240 | start = end; |
1241 | end = z; | 1241 | end = z; |
1242 | } | 1242 | } |
1243 | 1243 | ||
1244 | t = false; | 1244 | t = false; |
1245 | for (line = start; line < end; line++) { | 1245 | for (line = start; line < end; line++) { |
1246 | int x, oldX, s, e, newX1, newX2; | 1246 | int x, oldX, s, e, newX1, newX2; |
1247 | QChar ch; | 1247 | QChar ch; |
1248 | Attribute *a; | 1248 | Attribute *a; |
1249 | 1249 | ||
1250 | TextLine::Ptr textLine = getTextLine(line); | 1250 | TextLine::Ptr textLine = getTextLine(line); |
1251 | 1251 | ||
1252 | //--- speed optimization | 1252 | //--- speed optimization |
1253 | //s = textPos(textLine, x1, newX1); | 1253 | //s = textPos(textLine, x1, newX1); |
1254 | x = oldX = z = 0; | 1254 | x = oldX = z = 0; |
1255 | while (x < x1) { // && z < len) { | 1255 | while (x < x1) { // && z < len) { |
1256 | oldX = x; | 1256 | oldX = x; |
1257 | ch = textLine->getChar(z); | 1257 | ch = textLine->getChar(z); |
1258 | a = &m_attribs[textLine->getAttr(z)]; | 1258 | a = &m_attribs[textLine->getAttr(z)]; |
1259 | 1259 | ||
1260 | if (ch == '\t') | 1260 | if (ch == '\t') |
1261 | x += m_tabWidth - (x % m_tabWidth); | 1261 | x += m_tabWidth - (x % m_tabWidth); |
1262 | else if (a->bold && a->italic) | 1262 | else if (a->bold && a->italic) |
1263 | x += myFontMetricsBI.width(ch); | 1263 | x += myFontMetricsBI.width(ch); |
1264 | else if (a->bold) | 1264 | else if (a->bold) |
1265 | x += myFontMetricsBold.width(ch); | 1265 | x += myFontMetricsBold.width(ch); |
1266 | else if (a->italic) | 1266 | else if (a->italic) |
1267 | x += myFontMetricsItalic.width(ch); | 1267 | x += myFontMetricsItalic.width(ch); |
1268 | else | 1268 | else |
1269 | x += myFontMetrics.width(ch); | 1269 | x += myFontMetrics.width(ch); |
1270 | 1270 | ||
1271 | z++; | 1271 | z++; |
1272 | } | 1272 | } |
1273 | s = z; | 1273 | s = z; |
1274 | if (x1 - oldX < x - x1 && z > 0) { | 1274 | if (x1 - oldX < x - x1 && z > 0) { |
1275 | s--; | 1275 | s--; |
1276 | newX1 = oldX; | 1276 | newX1 = oldX; |
1277 | } else newX1 = x; | 1277 | } else newX1 = x; |
1278 | //e = textPos(textLine, x2, newX2); | 1278 | //e = textPos(textLine, x2, newX2); |
1279 | while (x < x2) { // && z < len) { | 1279 | while (x < x2) { // && z < len) { |
1280 | oldX = x; | 1280 | oldX = x; |
1281 | ch = textLine->getChar(z); | 1281 | ch = textLine->getChar(z); |
1282 | a = &m_attribs[textLine->getAttr(z)]; | 1282 | a = &m_attribs[textLine->getAttr(z)]; |
1283 | 1283 | ||
1284 | if (ch == '\t') | 1284 | if (ch == '\t') |
1285 | x += m_tabWidth - (x % m_tabWidth); | 1285 | x += m_tabWidth - (x % m_tabWidth); |
1286 | else if (a->bold && a->italic) | 1286 | else if (a->bold && a->italic) |
1287 | x += myFontMetricsBI.width(ch); | 1287 | x += myFontMetricsBI.width(ch); |
1288 | else if (a->bold) | 1288 | else if (a->bold) |
1289 | x += myFontMetricsBold.width(ch); | 1289 | x += myFontMetricsBold.width(ch); |
1290 | else if (a->italic) | 1290 | else if (a->italic) |
1291 | x += myFontMetricsItalic.width(ch); | 1291 | x += myFontMetricsItalic.width(ch); |
1292 | else | 1292 | else |
1293 | x += myFontMetrics.width(ch); | 1293 | x += myFontMetrics.width(ch); |
1294 | 1294 | ||
1295 | z++; | 1295 | z++; |
1296 | } | 1296 | } |
1297 | e = z; | 1297 | e = z; |
1298 | if (x2 - oldX < x - x2 && z > 0) { | 1298 | if (x2 - oldX < x - x2 && z > 0) { |
1299 | e--; | 1299 | e--; |
1300 | newX2 = oldX; | 1300 | newX2 = oldX; |
1301 | } else newX2 = x; | 1301 | } else newX2 = x; |
1302 | //--- | 1302 | //--- |
1303 | 1303 | ||
1304 | if (e > s) { | 1304 | if (e > s) { |
1305 | textLine->toggleSelect(s, e); | 1305 | textLine->toggleSelect(s, e); |
1306 | tagLineRange(line, newX1, newX2); | 1306 | tagLineRange(line, newX1, newX2); |
1307 | t = true; | 1307 | t = true; |
1308 | } | 1308 | } |
1309 | } | 1309 | } |
1310 | if (t) { | 1310 | if (t) { |
1311 | end--; | 1311 | end--; |
1312 | // tagLines(start, end); | 1312 | // tagLines(start, end); |
1313 | 1313 | ||
1314 | if (start < selectStart) selectStart = start; | 1314 | if (start < selectStart) selectStart = start; |
1315 | if (end > selectEnd) selectEnd = end; | 1315 | if (end > selectEnd) selectEnd = end; |
1316 | emit selectionChanged(); | 1316 | emit selectionChanged(); |
1317 | } | 1317 | } |
1318 | } | 1318 | } |
1319 | 1319 | ||
1320 | void KateDocument::selectTo(VConfig &c, PointStruc &cursor, int cXPos) { | 1320 | void KateDocument::selectTo(VConfig &c, PointStruc &cursor, int cXPos) { |
1321 | //c.cursor = old cursor position | 1321 | //c.cursor = old cursor position |
1322 | //cursor = new cursor position | 1322 | //cursor = new cursor position |
1323 | 1323 | ||
1324 | if (c.cursor.x != select.x || c.cursor.y != select.y) { | 1324 | if (c.cursor.x != select.x || c.cursor.y != select.y) { |
1325 | //new selection | 1325 | //new selection |
1326 | 1326 | ||
1327 | if (!(c.flags & KateView::cfKeepSelection)) deselectAll(); | 1327 | if (!(c.flags & KateView::cfKeepSelection)) deselectAll(); |
1328 | // else recordReset(); | 1328 | // else recordReset(); |
1329 | 1329 | ||
1330 | anchor = c.cursor; | 1330 | anchor = c.cursor; |
1331 | aXPos = c.cXPos; | 1331 | aXPos = c.cXPos; |
1332 | } | 1332 | } |
1333 | 1333 | ||
1334 | if (!(c.flags & KateView::cfVerticalSelect)) { | 1334 | if (!(c.flags & KateView::cfVerticalSelect)) { |
1335 | //horizontal selections | 1335 | //horizontal selections |
1336 | int x, y, sXPos; | 1336 | int x, y, sXPos; |
1337 | int ex, ey, eXPos; | 1337 | int ex, ey, eXPos; |
1338 | bool sel; | 1338 | bool sel; |
1339 | 1339 | ||
1340 | if (cursor.y > c.cursor.y || (cursor.y == c.cursor.y && cursor.x > c.cursor.x)) { | 1340 | if (cursor.y > c.cursor.y || (cursor.y == c.cursor.y && cursor.x > c.cursor.x)) { |
1341 | x = c.cursor.x; | 1341 | x = c.cursor.x; |
1342 | y = c.cursor.y; | 1342 | y = c.cursor.y; |
1343 | sXPos = c.cXPos; | 1343 | sXPos = c.cXPos; |
1344 | ex = cursor.x; | 1344 | ex = cursor.x; |
1345 | ey = cursor.y; | 1345 | ey = cursor.y; |
1346 | eXPos = cXPos; | 1346 | eXPos = cXPos; |
1347 | sel = true; | 1347 | sel = true; |
1348 | } else { | 1348 | } else { |
1349 | x = cursor.x; | 1349 | x = cursor.x; |
1350 | y = cursor.y; | 1350 | y = cursor.y; |
1351 | sXPos = cXPos; | 1351 | sXPos = cXPos; |
1352 | ex = c.cursor.x; | 1352 | ex = c.cursor.x; |
1353 | ey = c.cursor.y; | 1353 | ey = c.cursor.y; |
1354 | eXPos = c.cXPos; | 1354 | eXPos = c.cXPos; |
1355 | sel = false; | 1355 | sel = false; |
1356 | } | 1356 | } |
1357 | 1357 | ||
1358 | // tagLines(y, ye); | 1358 | // tagLines(y, ye); |
1359 | if (y < ey) { | 1359 | if (y < ey) { |
1360 | //tagLineRange(y, sXPos, 0xffffff); | 1360 | //tagLineRange(y, sXPos, 0xffffff); |
1361 | tagLines(y, ey -1); | 1361 | tagLines(y, ey -1); |
1362 | tagLineRange(ey, 0, eXPos); | 1362 | tagLineRange(ey, 0, eXPos); |
1363 | } else tagLineRange(y, sXPos, eXPos); | 1363 | } else tagLineRange(y, sXPos, eXPos); |
1364 | 1364 | ||
1365 | if (y < selectStart) selectStart = y; | 1365 | if (y < selectStart) selectStart = y; |
1366 | if (ey > selectEnd) selectEnd = ey; | 1366 | if (ey > selectEnd) selectEnd = ey; |
1367 | 1367 | ||
1368 | TextLine::Ptr textLine = getTextLine(y); | 1368 | TextLine::Ptr textLine = getTextLine(y); |
1369 | 1369 | ||
1370 | if (c.flags & KateView::cfXorSelect) { | 1370 | if (c.flags & KateView::cfXorSelect) { |
1371 | //xor selection with old selection | 1371 | //xor selection with old selection |
1372 | while (y < ey) { | 1372 | while (y < ey) { |
1373 | textLine->toggleSelectEol(x); | 1373 | textLine->toggleSelectEol(x); |
1374 | x = 0; | 1374 | x = 0; |
1375 | y++; | 1375 | y++; |
1376 | textLine = getTextLine(y); | 1376 | textLine = getTextLine(y); |
1377 | } | 1377 | } |
1378 | textLine->toggleSelect(x, ex); | 1378 | textLine->toggleSelect(x, ex); |
1379 | } else { | 1379 | } else { |
1380 | //set selection over old selection | 1380 | //set selection over old selection |
1381 | 1381 | ||
1382 | if (anchor.y > y || (anchor.y == y && anchor.x > x)) { | 1382 | if (anchor.y > y || (anchor.y == y && anchor.x > x)) { |
1383 | if (anchor.y < ey || (anchor.y == ey && anchor.x < ex)) { | 1383 | if (anchor.y < ey || (anchor.y == ey && anchor.x < ex)) { |
1384 | sel = !sel; | 1384 | sel = !sel; |
1385 | while (y < anchor.y) { | 1385 | while (y < anchor.y) { |
1386 | textLine->selectEol(sel, x); | 1386 | textLine->selectEol(sel, x); |
1387 | x = 0; | 1387 | x = 0; |
1388 | y++; | 1388 | y++; |
1389 | textLine = getTextLine(y); | 1389 | textLine = getTextLine(y); |
1390 | } | 1390 | } |
1391 | textLine->select(sel, x, anchor.x); | 1391 | textLine->select(sel, x, anchor.x); |
1392 | x = anchor.x; | 1392 | x = anchor.x; |
1393 | } | 1393 | } |
1394 | sel = !sel; | 1394 | sel = !sel; |
1395 | } | 1395 | } |
1396 | while (y < ey) { | 1396 | while (y < ey) { |
1397 | textLine->selectEol(sel, x); | 1397 | textLine->selectEol(sel, x); |
1398 | x = 0; | 1398 | x = 0; |
1399 | y++; | 1399 | y++; |
1400 | textLine = getTextLine(y); | 1400 | textLine = getTextLine(y); |
1401 | } | 1401 | } |
1402 | textLine->select(sel, x, ex); | 1402 | textLine->select(sel, x, ex); |
1403 | } | 1403 | } |
1404 | } else { | 1404 | } else { |
1405 | //vertical (block) selections | 1405 | //vertical (block) selections |
1406 | // int ax, sx, ex; | 1406 | // int ax, sx, ex; |
1407 | 1407 | ||
1408 | // ax = textWidth(anchor); | 1408 | // ax = textWidth(anchor); |
1409 | // sx = textWidth(start); | 1409 | // sx = textWidth(start); |
1410 | // ex = textWidth(end); | 1410 | // ex = textWidth(end); |
1411 | 1411 | ||
1412 | toggleRect(c.cursor.y + 1, cursor.y + 1, aXPos, c.cXPos); | 1412 | toggleRect(c.cursor.y + 1, cursor.y + 1, aXPos, c.cXPos); |
1413 | toggleRect(anchor.y, cursor.y + 1, c.cXPos, cXPos); | 1413 | toggleRect(anchor.y, cursor.y + 1, c.cXPos, cXPos); |
1414 | } | 1414 | } |
1415 | select = cursor; | 1415 | select = cursor; |
1416 | optimizeSelection(); | 1416 | optimizeSelection(); |
1417 | emit selectionChanged(); | 1417 | emit selectionChanged(); |
1418 | } | 1418 | } |
1419 | 1419 | ||
1420 | 1420 | ||
1421 | void KateDocument::selectAll() { | 1421 | void KateDocument::selectAll() { |
1422 | int z; | 1422 | int z; |
1423 | TextLine::Ptr textLine; | 1423 | TextLine::Ptr textLine; |
1424 | 1424 | ||
1425 | select.x = -1; | 1425 | select.x = -1; |
1426 | 1426 | ||
1427 | // if (selectStart != 0 || selectEnd != lastLine()) recordReset(); | 1427 | // if (selectStart != 0 || selectEnd != lastLine()) recordReset(); |
1428 | 1428 | ||
1429 | selectStart = 0; | 1429 | selectStart = 0; |
1430 | selectEnd = lastLine(); | 1430 | selectEnd = lastLine(); |
1431 | 1431 | ||
1432 | tagLines(selectStart,selectEnd); | 1432 | tagLines(selectStart,selectEnd); |
1433 | 1433 | ||
1434 | for (z = selectStart; z < selectEnd; z++) { | 1434 | for (z = selectStart; z < selectEnd; z++) { |
1435 | textLine = getTextLine(z); | 1435 | textLine = getTextLine(z); |
1436 | textLine->selectEol(true,0); | 1436 | textLine->selectEol(true,0); |
1437 | } | 1437 | } |
1438 | textLine = getTextLine(z); | 1438 | textLine = getTextLine(z); |
1439 | textLine->select(true,0,textLine->length()); | 1439 | textLine->select(true,0,textLine->length()); |
1440 | emit selectionChanged(); | 1440 | emit selectionChanged(); |
1441 | } | 1441 | } |
1442 | 1442 | ||
1443 | void KateDocument::deselectAll() { | 1443 | void KateDocument::deselectAll() { |
1444 | select.x = -1; | 1444 | select.x = -1; |
1445 | if (selectEnd < selectStart) return; | 1445 | if (selectEnd < selectStart) return; |
1446 | 1446 | ||
1447 | // recordReset(); | 1447 | // recordReset(); |
1448 | 1448 | ||
1449 | tagLines(selectStart,selectEnd); | 1449 | tagLines(selectStart,selectEnd); |
1450 | 1450 | ||
1451 | for (int z = selectStart; z <= selectEnd; z++) { | 1451 | for (int z = selectStart; z <= selectEnd; z++) { |
1452 | TextLine::Ptr textLine = getTextLine(z); | 1452 | TextLine::Ptr textLine = getTextLine(z); |
1453 | textLine->selectEol(false,0); | 1453 | textLine->selectEol(false,0); |
1454 | } | 1454 | } |
1455 | selectStart = 0xffffff; | 1455 | selectStart = 0xffffff; |
1456 | selectEnd = 0; | 1456 | selectEnd = 0; |
1457 | emit selectionChanged(); | 1457 | emit selectionChanged(); |
1458 | } | 1458 | } |
1459 | 1459 | ||
1460 | void KateDocument::invertSelection() { | 1460 | void KateDocument::invertSelection() { |
1461 | TextLine::Ptr textLine; | 1461 | TextLine::Ptr textLine; |
1462 | 1462 | ||
1463 | select.x = -1; | 1463 | select.x = -1; |
1464 | 1464 | ||
1465 | // if (selectStart != 0 || selectEnd != lastLine()) recordReset(); | 1465 | // if (selectStart != 0 || selectEnd != lastLine()) recordReset(); |
1466 | 1466 | ||
1467 | selectStart = 0; | 1467 | selectStart = 0; |
1468 | selectEnd = lastLine(); | 1468 | selectEnd = lastLine(); |
1469 | 1469 | ||
1470 | tagLines(selectStart,selectEnd); | 1470 | tagLines(selectStart,selectEnd); |
1471 | 1471 | ||
1472 | for (int z = selectStart; z < selectEnd; z++) { | 1472 | for (int z = selectStart; z < selectEnd; z++) { |
1473 | textLine = getTextLine(z); | 1473 | textLine = getTextLine(z); |
1474 | textLine->toggleSelectEol(0); | 1474 | textLine->toggleSelectEol(0); |
1475 | } | 1475 | } |
1476 | textLine = getTextLine(selectEnd); | 1476 | textLine = getTextLine(selectEnd); |
1477 | textLine->toggleSelect(0,textLine->length()); | 1477 | textLine->toggleSelect(0,textLine->length()); |
1478 | optimizeSelection(); | 1478 | optimizeSelection(); |
1479 | emit selectionChanged(); | 1479 | emit selectionChanged(); |
1480 | } | 1480 | } |
1481 | 1481 | ||
1482 | void KateDocument::selectWord(PointStruc &cursor, int flags) { | 1482 | void KateDocument::selectWord(PointStruc &cursor, int flags) { |
1483 | int start, end, len; | 1483 | int start, end, len; |
1484 | 1484 | ||
1485 | TextLine::Ptr textLine = getTextLine(cursor.y); | 1485 | TextLine::Ptr textLine = getTextLine(cursor.y); |
1486 | len = textLine->length(); | 1486 | len = textLine->length(); |
1487 | start = end = cursor.x; | 1487 | start = end = cursor.x; |
1488 | while (start > 0 && m_highlight->isInWord(textLine->getChar(start - 1))) start--; | 1488 | while (start > 0 && m_highlight->isInWord(textLine->getChar(start - 1))) start--; |
1489 | while (end < len && m_highlight->isInWord(textLine->getChar(end))) end++; | 1489 | while (end < len && m_highlight->isInWord(textLine->getChar(end))) end++; |
1490 | if (end <= start) return; | 1490 | if (end <= start) return; |
1491 | if (!(flags & KateView::cfKeepSelection)) deselectAll(); | 1491 | if (!(flags & KateView::cfKeepSelection)) deselectAll(); |
1492 | // else recordReset(); | 1492 | // else recordReset(); |
1493 | 1493 | ||
1494 | textLine->select(true, start, end); | 1494 | textLine->select(true, start, end); |
1495 | 1495 | ||
1496 | anchor.x = start; | 1496 | anchor.x = start; |
1497 | select.x = end; | 1497 | select.x = end; |
1498 | anchor.y = select.y = cursor.y; | 1498 | anchor.y = select.y = cursor.y; |
1499 | tagLines(cursor.y, cursor.y); | 1499 | tagLines(cursor.y, cursor.y); |
1500 | if (cursor.y < selectStart) selectStart = cursor.y; | 1500 | if (cursor.y < selectStart) selectStart = cursor.y; |
1501 | if (cursor.y > selectEnd) selectEnd = cursor.y; | 1501 | if (cursor.y > selectEnd) selectEnd = cursor.y; |
1502 | emit selectionChanged(); | 1502 | emit selectionChanged(); |
1503 | } | 1503 | } |
1504 | 1504 | ||
1505 | void KateDocument::selectLength(PointStruc &cursor, int length, int flags) { | 1505 | void KateDocument::selectLength(PointStruc &cursor, int length, int flags) { |
1506 | int start, end; | 1506 | int start, end; |
1507 | 1507 | ||
1508 | TextLine::Ptr textLine = getTextLine(cursor.y); | 1508 | TextLine::Ptr textLine = getTextLine(cursor.y); |
1509 | start = cursor.x; | 1509 | start = cursor.x; |
1510 | end = start + length; | 1510 | end = start + length; |
1511 | if (end <= start) return; | 1511 | if (end <= start) return; |
1512 | if (!(flags & KateView::cfKeepSelection)) deselectAll(); | 1512 | if (!(flags & KateView::cfKeepSelection)) deselectAll(); |
1513 | 1513 | ||
1514 | textLine->select(true, start, end); | 1514 | textLine->select(true, start, end); |
1515 | 1515 | ||
1516 | anchor.x = start; | 1516 | anchor.x = start; |
1517 | select.x = end; | 1517 | select.x = end; |
1518 | anchor.y = select.y = cursor.y; | 1518 | anchor.y = select.y = cursor.y; |
1519 | tagLines(cursor.y, cursor.y); | 1519 | tagLines(cursor.y, cursor.y); |
1520 | if (cursor.y < selectStart) selectStart = cursor.y; | 1520 | if (cursor.y < selectStart) selectStart = cursor.y; |
1521 | if (cursor.y > selectEnd) selectEnd = cursor.y; | 1521 | if (cursor.y > selectEnd) selectEnd = cursor.y; |
1522 | emit selectionChanged(); | 1522 | emit selectionChanged(); |
1523 | } | 1523 | } |
1524 | 1524 | ||
1525 | void KateDocument::doIndent(VConfig &c, int change) { | 1525 | void KateDocument::doIndent(VConfig &c, int change) { |
1526 | 1526 | ||
1527 | c.cursor.x = 0; | 1527 | c.cursor.x = 0; |
1528 | 1528 | ||
1529 | recordStart(c, (change < 0) ? KateActionGroup::ugUnindent | 1529 | recordStart(c, (change < 0) ? KateActionGroup::ugUnindent |
1530 | : KateActionGroup::ugIndent); | 1530 | : KateActionGroup::ugIndent); |
1531 | 1531 | ||
1532 | if (selectEnd < selectStart) { | 1532 | if (selectEnd < selectStart) { |
1533 | // single line | 1533 | // single line |
1534 | optimizeLeadingSpace(c.cursor.y, c.flags, change); | 1534 | optimizeLeadingSpace(c.cursor.y, c.flags, change); |
1535 | } else { | 1535 | } else { |
1536 | // entire selection | 1536 | // entire selection |
1537 | TextLine::Ptr textLine; | 1537 | TextLine::Ptr textLine; |
1538 | int line, z; | 1538 | int line, z; |
1539 | QChar ch; | 1539 | QChar ch; |
1540 | 1540 | ||
1541 | if (c.flags & KateView::cfKeepIndentProfile && change < 0) { | 1541 | if (c.flags & KateView::cfKeepIndentProfile && change < 0) { |
1542 | // unindent so that the existing indent profile doesn´t get screwed | 1542 | // unindent so that the existing indent profile doesn´t get screwed |
1543 | // if any line we may unindent is already full left, don't do anything | 1543 | // if any line we may unindent is already full left, don't do anything |
1544 | for (line = selectStart; line <= selectEnd; line++) { | 1544 | for (line = selectStart; line <= selectEnd; line++) { |
1545 | textLine = getTextLine(line); | 1545 | textLine = getTextLine(line); |
1546 | if (textLine->isSelected() || textLine->numSelected()) { | 1546 | if (textLine->isSelected() || textLine->numSelected()) { |
1547 | for (z = 0; z < tabChars; z++) { | 1547 | for (z = 0; z < tabChars; z++) { |
1548 | ch = textLine->getChar(z); | 1548 | ch = textLine->getChar(z); |
1549 | if (ch == '\t') break; | 1549 | if (ch == '\t') break; |
1550 | if (ch != ' ') { | 1550 | if (ch != ' ') { |
1551 | change = 0; | 1551 | change = 0; |
1552 | goto jumpOut; | 1552 | goto jumpOut; |
1553 | } | 1553 | } |
1554 | } | 1554 | } |
1555 | } | 1555 | } |
1556 | } | 1556 | } |
1557 | jumpOut:; | 1557 | jumpOut:; |
1558 | } | 1558 | } |
1559 | 1559 | ||
1560 | for (line = selectStart; line <= selectEnd; line++) { | 1560 | for (line = selectStart; line <= selectEnd; line++) { |
1561 | textLine = getTextLine(line); | 1561 | textLine = getTextLine(line); |
1562 | if (textLine->isSelected() || textLine->numSelected()) { | 1562 | if (textLine->isSelected() || textLine->numSelected()) { |
1563 | optimizeLeadingSpace(line, c.flags, change); | 1563 | optimizeLeadingSpace(line, c.flags, change); |
1564 | } | 1564 | } |
1565 | } | 1565 | } |
1566 | } | 1566 | } |
1567 | // recordEnd now removes empty undo records | 1567 | // recordEnd now removes empty undo records |
1568 | recordEnd(c.view, c.cursor, c.flags | KateView::cfPersistent); | 1568 | recordEnd(c.view, c.cursor, c.flags | KateView::cfPersistent); |
1569 | } | 1569 | } |
1570 | 1570 | ||
1571 | /* | 1571 | /* |
1572 | Optimize the leading whitespace for a single line. | 1572 | Optimize the leading whitespace for a single line. |
1573 | If change is > 0, it adds indentation units (tabChars) | 1573 | If change is > 0, it adds indentation units (tabChars) |
1574 | if change is == 0, it only optimizes | 1574 | if change is == 0, it only optimizes |
1575 | If change is < 0, it removes indentation units | 1575 | If change is < 0, it removes indentation units |
1576 | This will be used to indent, unindent, and optimal-fill a line. | 1576 | This will be used to indent, unindent, and optimal-fill a line. |
1577 | If excess space is removed depends on the flag cfKeepExtraSpaces | 1577 | If excess space is removed depends on the flag cfKeepExtraSpaces |
1578 | which has to be set by the user | 1578 | which has to be set by the user |
1579 | */ | 1579 | */ |
1580 | void KateDocument::optimizeLeadingSpace(int line, int flags, int change) { | 1580 | void KateDocument::optimizeLeadingSpace(int line, int flags, int change) { |
1581 | int len; | 1581 | int len; |
1582 | int chars, space, okLen; | 1582 | int chars, space, okLen; |
1583 | QChar ch; | 1583 | QChar ch; |
1584 | int extra; | 1584 | int extra; |
1585 | QString s; | 1585 | QString s; |
1586 | PointStruc cursor; | 1586 | PointStruc cursor; |
1587 | 1587 | ||
1588 | TextLine::Ptr textLine = getTextLine(line); | 1588 | TextLine::Ptr textLine = getTextLine(line); |
1589 | len = textLine->length(); | 1589 | len = textLine->length(); |
1590 | space = 0; // length of space at the beginning of the textline | 1590 | space = 0; // length of space at the beginning of the textline |
1591 | okLen = 0; // length of space which does not have to be replaced | 1591 | okLen = 0; // length of space which does not have to be replaced |
1592 | for (chars = 0; chars < len; chars++) { | 1592 | for (chars = 0; chars < len; chars++) { |
1593 | ch = textLine->getChar(chars); | 1593 | ch = textLine->getChar(chars); |
1594 | if (ch == ' ') { | 1594 | if (ch == ' ') { |
1595 | space++; | 1595 | space++; |
1596 | if (flags & KateView::cfSpaceIndent && okLen == chars) okLen++; | 1596 | if (flags & KateView::cfSpaceIndent && okLen == chars) okLen++; |
1597 | } else if (ch == '\t') { | 1597 | } else if (ch == '\t') { |
1598 | space += tabChars - space % tabChars; | 1598 | space += tabChars - space % tabChars; |
1599 | if (!(flags & KateView::cfSpaceIndent) && okLen == chars) okLen++; | 1599 | if (!(flags & KateView::cfSpaceIndent) && okLen == chars) okLen++; |
1600 | } else break; | 1600 | } else break; |
1601 | } | 1601 | } |
1602 | 1602 | ||
1603 | space += change*tabChars; // modify space width | 1603 | space += change*tabChars; // modify space width |
1604 | // if line contains only spaces it will be cleared | 1604 | // if line contains only spaces it will be cleared |
1605 | if (space < 0 || chars == len) space = 0; | 1605 | if (space < 0 || chars == len) space = 0; |
1606 | 1606 | ||
1607 | extra = space % tabChars; // extra spaces which don´t fit the indentation pattern | 1607 | extra = space % tabChars; // extra spaces which don´t fit the indentation pattern |
1608 | if (flags & KateView::cfKeepExtraSpaces) chars -= extra; | 1608 | if (flags & KateView::cfKeepExtraSpaces) chars -= extra; |
1609 | 1609 | ||
1610 | if (flags & KateView::cfSpaceIndent) { | 1610 | if (flags & KateView::cfSpaceIndent) { |
1611 | space -= extra; | 1611 | space -= extra; |
1612 | ch = ' '; | 1612 | ch = ' '; |
1613 | } else { | 1613 | } else { |
1614 | space /= tabChars; | 1614 | space /= tabChars; |
1615 | ch = '\t'; | 1615 | ch = '\t'; |
1616 | } | 1616 | } |
1617 | 1617 | ||
1618 | // don´t replace chars which are already ok | 1618 | // don´t replace chars which are already ok |
1619 | cursor.x = QMIN(okLen, QMIN(chars, space)); | 1619 | cursor.x = QMIN(okLen, QMIN(chars, space)); |
1620 | chars -= cursor.x; | 1620 | chars -= cursor.x; |
1621 | space -= cursor.x; | 1621 | space -= cursor.x; |
1622 | if (chars == 0 && space == 0) return; //nothing to do | 1622 | if (chars == 0 && space == 0) return; //nothing to do |
1623 | 1623 | ||
1624 | s.fill(ch, space); | 1624 | s.fill(ch, space); |
1625 | 1625 | ||
1626 | //printf("chars %d insert %d cursor.x %d\n", chars, insert, cursor.x); | 1626 | //printf("chars %d insert %d cursor.x %d\n", chars, insert, cursor.x); |
1627 | cursor.y = line; | 1627 | cursor.y = line; |
1628 | recordReplace(cursor, chars, s); | 1628 | recordReplace(cursor, chars, s); |
1629 | } | 1629 | } |
1630 | 1630 | ||
1631 | void KateDocument::doComment(VConfig &c, int change) | 1631 | void KateDocument::doComment(VConfig &c, int change) |
1632 | { | 1632 | { |
1633 | c.flags |=KateView:: cfPersistent; | 1633 | c.flags |=KateView:: cfPersistent; |
1634 | 1634 | ||
1635 | recordStart(c, (change < 0) ? KateActionGroup::ugUncomment | 1635 | recordStart(c, (change < 0) ? KateActionGroup::ugUncomment |
1636 | : KateActionGroup::ugComment); | 1636 | : KateActionGroup::ugComment); |
1637 | 1637 | ||
1638 | QString startComment = m_highlight->getCommentStart(); | 1638 | QString startComment = m_highlight->getCommentStart(); |
1639 | QString startLineComment = m_highlight->getCommentSingleLineStart(); | 1639 | QString startLineComment = m_highlight->getCommentSingleLineStart(); |
1640 | QString endComment = m_highlight->getCommentEnd(); | 1640 | QString endComment = m_highlight->getCommentEnd(); |
1641 | 1641 | ||
1642 | int startCommentLen = startComment.length(); | 1642 | int startCommentLen = startComment.length(); |
1643 | int startLineCommentLen = startLineComment.length(); | 1643 | int startLineCommentLen = startLineComment.length(); |
1644 | int endCommentLen = endComment.length(); | 1644 | int endCommentLen = endComment.length(); |
1645 | 1645 | ||
1646 | if (change > 0) | 1646 | if (change > 0) |
1647 | { | 1647 | { |
1648 | if ( !hasMarkedText() ) | 1648 | if ( !hasMarkedText() ) |
1649 | { | 1649 | { |
1650 | if (startLineComment != "") | 1650 | if (startLineComment != "") |
1651 | { | 1651 | { |
1652 | // Add a start comment mark | 1652 | // Add a start comment mark |
1653 | c.cursor.x = 0; | 1653 | c.cursor.x = 0; |
1654 | recordReplace(c.cursor, 0, startLineComment); | 1654 | recordReplace(c.cursor, 0, startLineComment); |
1655 | } | 1655 | } |
1656 | else if ((startComment != "") && (endComment != "")) | 1656 | else if ((startComment != "") && (endComment != "")) |
1657 | { | 1657 | { |
1658 | // Add a start comment mark | 1658 | // Add a start comment mark |
1659 | c.cursor.x = 0; | 1659 | c.cursor.x = 0; |
1660 | recordReplace(c.cursor, 0, startComment); | 1660 | recordReplace(c.cursor, 0, startComment); |
1661 | 1661 | ||
1662 | // Add an end comment mark | 1662 | // Add an end comment mark |
1663 | TextLine* textline = getTextLine(c.cursor.y); | 1663 | TextLine* textline = getTextLine(c.cursor.y); |
1664 | c.cursor.x = textline->length(); | 1664 | c.cursor.x = textline->length(); |
1665 | recordReplace(c.cursor, 0, endComment); | 1665 | recordReplace(c.cursor, 0, endComment); |
1666 | c.cursor.x = 0; | 1666 | c.cursor.x = 0; |
1667 | } | 1667 | } |
1668 | } | 1668 | } |
1669 | else if ((startComment != "") && (endComment != "")) | 1669 | else if ((startComment != "") && (endComment != "")) |
1670 | { | 1670 | { |
1671 | QString marked (c.view->markedText ()); | 1671 | QString marked (c.view->markedText ()); |
1672 | int preDeleteLine = -1, preDeleteCol = -1; | 1672 | int preDeleteLine = -1, preDeleteCol = -1; |
1673 | c.view->getCursorPosition (&preDeleteLine, &preDeleteCol); | 1673 | c.view->getCursorPosition (&preDeleteLine, &preDeleteCol); |
1674 | 1674 | ||
1675 | if (marked.length() > 0) | 1675 | if (marked.length() > 0) |
1676 | c.view->keyDelete (); | 1676 | c.view->keyDelete (); |
1677 | 1677 | ||
1678 | int line = -1, col = -1; | 1678 | int line = -1, col = -1; |
1679 | c.view->getCursorPosition (&line, &col); | 1679 | c.view->getCursorPosition (&line, &col); |
1680 | 1680 | ||
1681 | c.view->insertText (startComment + marked + endComment); | 1681 | c.view->insertText (startComment + marked + endComment); |
1682 | } | 1682 | } |
1683 | } | 1683 | } |
1684 | else | 1684 | else |
1685 | { | 1685 | { |
1686 | if ( !hasMarkedText() ) | 1686 | if ( !hasMarkedText() ) |
1687 | { | 1687 | { |
1688 | TextLine* textline = getTextLine(c.cursor.y); | 1688 | TextLine* textline = getTextLine(c.cursor.y); |
1689 | 1689 | ||
1690 | if(textline->startingWith(startLineComment)) | 1690 | if(textline->startingWith(startLineComment)) |
1691 | { | 1691 | { |
1692 | // Remove start comment mark | 1692 | // Remove start comment mark |
1693 | c.cursor.x = 0; | 1693 | c.cursor.x = 0; |
1694 | recordReplace(c.cursor, startLineCommentLen, ""); | 1694 | recordReplace(c.cursor, startLineCommentLen, ""); |
1695 | } | 1695 | } |
1696 | else if (textline->startingWith(startComment) && textline->endingWith(endComment)) | 1696 | else if (textline->startingWith(startComment) && textline->endingWith(endComment)) |
1697 | { | 1697 | { |
1698 | // Remove start comment mark | 1698 | // Remove start comment mark |
1699 | c.cursor.x = 0; | 1699 | c.cursor.x = 0; |
1700 | recordReplace(c.cursor, startCommentLen, ""); | 1700 | recordReplace(c.cursor, startCommentLen, ""); |
1701 | 1701 | ||
1702 | // Remove end comment mark | 1702 | // Remove end comment mark |
1703 | if(endComment != "") | 1703 | if(endComment != "") |
1704 | { | 1704 | { |
1705 | c.cursor.x = textline->length() - endCommentLen; | 1705 | c.cursor.x = textline->length() - endCommentLen; |
1706 | recordReplace(c.cursor, endCommentLen, ""); | 1706 | recordReplace(c.cursor, endCommentLen, ""); |
1707 | c.cursor.x = 0; | 1707 | c.cursor.x = 0; |
1708 | } | 1708 | } |
1709 | } | 1709 | } |
1710 | } | 1710 | } |
1711 | else | 1711 | else |
1712 | { | 1712 | { |
1713 | QString marked (c.view->markedText ()); | 1713 | QString marked (c.view->markedText ()); |
1714 | int preDeleteLine = -1, preDeleteCol = -1; | 1714 | int preDeleteLine = -1, preDeleteCol = -1; |
1715 | c.view->getCursorPosition (&preDeleteLine, &preDeleteCol); | 1715 | c.view->getCursorPosition (&preDeleteLine, &preDeleteCol); |
1716 | 1716 | ||
1717 | int start = marked.find (startComment); | 1717 | int start = marked.find (startComment); |
1718 | int end = marked.findRev (endComment); | 1718 | int end = marked.findRev (endComment); |
1719 | 1719 | ||
1720 | if ((start > -1) && (end > -1)) | 1720 | if ((start > -1) && (end > -1)) |
1721 | { | 1721 | { |
1722 | marked.remove (start, startCommentLen); | 1722 | marked.remove (start, startCommentLen); |
1723 | marked.remove (end-startCommentLen, endCommentLen); | 1723 | marked.remove (end-startCommentLen, endCommentLen); |
1724 | 1724 | ||
1725 | c.view->keyDelete (); | 1725 | c.view->keyDelete (); |
1726 | 1726 | ||
1727 | int line = -1, col = -1; | 1727 | int line = -1, col = -1; |
1728 | c.view->getCursorPosition (&line, &col); | 1728 | c.view->getCursorPosition (&line, &col); |
1729 | c.view->insertText (marked); | 1729 | c.view->insertText (marked); |
1730 | } | 1730 | } |
1731 | } | 1731 | } |
1732 | } | 1732 | } |
1733 | 1733 | ||
1734 | recordEnd(c.view, c.cursor, c.flags | KateView::cfPersistent); | 1734 | recordEnd(c.view, c.cursor, c.flags | KateView::cfPersistent); |
1735 | } | 1735 | } |
1736 | 1736 | ||
1737 | 1737 | ||
1738 | QString KateDocument::text() const | 1738 | QString KateDocument::text() const |
1739 | { | 1739 | { |
1740 | QString s; | 1740 | QString s; |
1741 | 1741 | ||
1742 | for (int i=0; i < buffer->count(); i++) | 1742 | for (int i=0; i < buffer->count(); i++) |
1743 | { | 1743 | { |
1744 | TextLine::Ptr textLine = buffer->line(i); | 1744 | TextLine::Ptr textLine = buffer->line(i); |
1745 | s.insert(s.length(), textLine->getText(), textLine->length()); | 1745 | s.insert(s.length(), textLine->getText(), textLine->length()); |
1746 | if ( (i < (buffer->count()-1)) ) | 1746 | if ( (i < (buffer->count()-1)) ) |
1747 | s.append('\n'); | 1747 | s.append('\n'); |
1748 | } | 1748 | } |
1749 | 1749 | ||
1750 | return s; | 1750 | return s; |
1751 | } | 1751 | } |
1752 | 1752 | ||
1753 | QString KateDocument::getWord(PointStruc &cursor) { | 1753 | QString KateDocument::getWord(PointStruc &cursor) { |
1754 | int start, end, len; | 1754 | int start, end, len; |
1755 | 1755 | ||
1756 | TextLine::Ptr textLine = getTextLine(cursor.y); | 1756 | TextLine::Ptr textLine = getTextLine(cursor.y); |
1757 | len = textLine->length(); | 1757 | len = textLine->length(); |
1758 | start = end = cursor.x; | 1758 | start = end = cursor.x; |
1759 | while (start > 0 && m_highlight->isInWord(textLine->getChar(start - 1))) start--; | 1759 | while (start > 0 && m_highlight->isInWord(textLine->getChar(start - 1))) start--; |
1760 | while (end < len && m_highlight->isInWord(textLine->getChar(end))) end++; | 1760 | while (end < len && m_highlight->isInWord(textLine->getChar(end))) end++; |
1761 | len = end - start; | 1761 | len = end - start; |
1762 | return QString(&textLine->getText()[start], len); | 1762 | return QString(&textLine->getText()[start], len); |
1763 | } | 1763 | } |
1764 | 1764 | ||
1765 | void KateDocument::setText(const QString &s) { | 1765 | void KateDocument::setText(const QString &s) { |
1766 | int pos; | 1766 | int pos; |
1767 | QChar ch; | 1767 | QChar ch; |
1768 | 1768 | ||
1769 | clear(); | 1769 | clear(); |
1770 | 1770 | ||
1771 | int line=1; | 1771 | int line=1; |
1772 | 1772 | ||
1773 | TextLine::Ptr textLine = buffer->line(0); | 1773 | TextLine::Ptr textLine = buffer->line(0); |
1774 | for (pos = 0; pos <= (int) s.length(); pos++) { | 1774 | for (pos = 0; pos <= (int) s.length(); pos++) { |
1775 | ch = s[pos]; | 1775 | ch = s[pos]; |
1776 | if (ch.isPrint() || ch == '\t') { | 1776 | if (ch.isPrint() || ch == '\t') { |
1777 | textLine->append(&ch, 1); | 1777 | textLine->append(&ch, 1); |
1778 | } else if (ch == '\n') | 1778 | } else if (ch == '\n') |
1779 | { | 1779 | { |
1780 | textLine = new TextLine(); | 1780 | textLine = new TextLine(); |
1781 | buffer->insertLine (line, textLine); | 1781 | buffer->insertLine (line, textLine); |
1782 | line++; | 1782 | line++; |
1783 | } | 1783 | } |
1784 | } | 1784 | } |
1785 | updateLines(); | 1785 | updateLines(); |
1786 | } | 1786 | } |
1787 | 1787 | ||
1788 | 1788 | ||
1789 | QString KateDocument::markedText(int flags) { | 1789 | QString KateDocument::markedText(int flags) { |
1790 | TextLine::Ptr textLine; | 1790 | TextLine::Ptr textLine; |
1791 | int len, z, start, end, i; | 1791 | int len, z, start, end, i; |
1792 | 1792 | ||
1793 | len = 1; | 1793 | len = 1; |
1794 | if (!(flags & KateView::cfVerticalSelect)) { | 1794 | if (!(flags & KateView::cfVerticalSelect)) { |
1795 | for (z = selectStart; z <= selectEnd; z++) { | 1795 | for (z = selectStart; z <= selectEnd; z++) { |
1796 | textLine = getTextLine(z); | 1796 | textLine = getTextLine(z); |
1797 | len += textLine->numSelected(); | 1797 | len += textLine->numSelected(); |
1798 | if (textLine->isSelected()) len++; | 1798 | if (textLine->isSelected()) len++; |
1799 | } | 1799 | } |
1800 | QString s; | 1800 | QString s; |
1801 | len = 0; | 1801 | len = 0; |
1802 | for (z = selectStart; z <= selectEnd; z++) { | 1802 | for (z = selectStart; z <= selectEnd; z++) { |
1803 | textLine = getTextLine(z); | 1803 | textLine = getTextLine(z); |
1804 | end = 0; | 1804 | end = 0; |
1805 | do { | 1805 | do { |
1806 | start = textLine->findUnselected(end); | 1806 | start = textLine->findUnselected(end); |
1807 | end = textLine->findSelected(start); | 1807 | end = textLine->findSelected(start); |
1808 | for (i = start; i < end; i++) { | 1808 | for (i = start; i < end; i++) { |
1809 | s[len] = textLine->getChar(i); | 1809 | s[len] = textLine->getChar(i); |
1810 | len++; | 1810 | len++; |
1811 | } | 1811 | } |
1812 | } while (start < end); | 1812 | } while (start < end); |
1813 | if (textLine->isSelected()) { | 1813 | if (textLine->isSelected()) { |
1814 | s[len] = '\n'; | 1814 | s[len] = '\n'; |
1815 | len++; | 1815 | len++; |
1816 | } | 1816 | } |
1817 | } | 1817 | } |
1818 | // s[len] = '\0'; | 1818 | // s[len] = '\0'; |
1819 | return s; | 1819 | return s; |
1820 | } else { | 1820 | } else { |
1821 | for (z = selectStart; z <= selectEnd; z++) { | 1821 | for (z = selectStart; z <= selectEnd; z++) { |
1822 | textLine = getTextLine(z); | 1822 | textLine = getTextLine(z); |
1823 | len += textLine->numSelected() + 1; | 1823 | len += textLine->numSelected() + 1; |
1824 | } | 1824 | } |
1825 | QString s; | 1825 | QString s; |
1826 | len = 0; | 1826 | len = 0; |
1827 | for (z = selectStart; z <= selectEnd; z++) { | 1827 | for (z = selectStart; z <= selectEnd; z++) { |
1828 | textLine = getTextLine(z); | 1828 | textLine = getTextLine(z); |
1829 | end = 0; | 1829 | end = 0; |
1830 | do { | 1830 | do { |
1831 | start = textLine->findUnselected(end); | 1831 | start = textLine->findUnselected(end); |
1832 | end = textLine->findSelected(start); | 1832 | end = textLine->findSelected(start); |
1833 | for (i = start; i < end; i++) { | 1833 | for (i = start; i < end; i++) { |
1834 | s[len] = textLine->getChar(i); | 1834 | s[len] = textLine->getChar(i); |
1835 | len++; | 1835 | len++; |
1836 | } | 1836 | } |
1837 | } while (start < end); | 1837 | } while (start < end); |
1838 | s[len] = '\n'; | 1838 | s[len] = '\n'; |
1839 | len++; | 1839 | len++; |
1840 | } | 1840 | } |
1841 | // s[len] = '\0'; // the final \0 is not counted in length() | 1841 | // s[len] = '\0'; // the final \0 is not counted in length() |
1842 | return s; | 1842 | return s; |
1843 | } | 1843 | } |
1844 | } | 1844 | } |
1845 | 1845 | ||
1846 | void KateDocument::delMarkedText(VConfig &c/*, bool undo*/) { | 1846 | void KateDocument::delMarkedText(VConfig &c/*, bool undo*/) { |
1847 | int end = 0; | 1847 | int end = 0; |
1848 | 1848 | ||
1849 | if (selectEnd < selectStart) return; | 1849 | if (selectEnd < selectStart) return; |
1850 | 1850 | ||
1851 | // the caller may have already started an undo record for the current action | 1851 | // the caller may have already started an undo record for the current action |
1852 | // if (undo) | 1852 | // if (undo) |
1853 | 1853 | ||
1854 | //auto deletion of the marked text occurs not very often and can therefore | 1854 | //auto deletion of the marked text occurs not very often and can therefore |
1855 | // be recorded separately | 1855 | // be recorded separately |
1856 | recordStart(c, KateActionGroup::ugDelBlock); | 1856 | recordStart(c, KateActionGroup::ugDelBlock); |
1857 | 1857 | ||
1858 | for (c.cursor.y = selectEnd; c.cursor.y >= selectStart; c.cursor.y--) { | 1858 | for (c.cursor.y = selectEnd; c.cursor.y >= selectStart; c.cursor.y--) { |
1859 | TextLine::Ptr textLine = getTextLine(c.cursor.y); | 1859 | TextLine::Ptr textLine = getTextLine(c.cursor.y); |
1860 | 1860 | ||
1861 | c.cursor.x = textLine->length(); | 1861 | c.cursor.x = textLine->length(); |
1862 | do { | 1862 | do { |
1863 | end = textLine->findRevUnselected(c.cursor.x); | 1863 | end = textLine->findRevUnselected(c.cursor.x); |
1864 | if (end == 0) break; | 1864 | if (end == 0) break; |
1865 | c.cursor.x = textLine->findRevSelected(end); | 1865 | c.cursor.x = textLine->findRevSelected(end); |
1866 | recordDelete(c.cursor, end - c.cursor.x); | 1866 | recordDelete(c.cursor, end - c.cursor.x); |
1867 | } while (true); | 1867 | } while (true); |
1868 | end = c.cursor.x; | 1868 | end = c.cursor.x; |
1869 | c.cursor.x = textLine->length(); | 1869 | c.cursor.x = textLine->length(); |
1870 | if (textLine->isSelected()) recordAction(KateAction::delLine,c.cursor); | 1870 | if (textLine->isSelected()) recordAction(KateAction::delLine,c.cursor); |
1871 | } | 1871 | } |
1872 | c.cursor.y++; | 1872 | c.cursor.y++; |
1873 | /*if (end < c.cursor.x)*/ c.cursor.x = end; | 1873 | /*if (end < c.cursor.x)*/ c.cursor.x = end; |
1874 | 1874 | ||
1875 | selectEnd = -1; | 1875 | selectEnd = -1; |
1876 | select.x = -1; | 1876 | select.x = -1; |
1877 | 1877 | ||
1878 | /*if (undo)*/ recordEnd(c); | 1878 | /*if (undo)*/ recordEnd(c); |
1879 | } | 1879 | } |
1880 | 1880 | ||
1881 | void KateDocument::tagLineRange(int line, int x1, int x2) { | 1881 | void KateDocument::tagLineRange(int line, int x1, int x2) { |
1882 | int z; | 1882 | int z; |
1883 | 1883 | ||
1884 | for (z = 0; z < (int) views.count(); z++) { | 1884 | for (z = 0; z < (int) views.count(); z++) { |
1885 | views.at(z)->tagLines(line, line, x1, x2); | 1885 | views.at(z)->tagLines(line, line, x1, x2); |
1886 | } | 1886 | } |
1887 | } | 1887 | } |
1888 | 1888 | ||
1889 | void KateDocument::tagLines(int start, int end) { | 1889 | void KateDocument::tagLines(int start, int end) { |
1890 | int z; | 1890 | int z; |
1891 | 1891 | ||
1892 | for (z = 0; z < (int) views.count(); z++) { | 1892 | for (z = 0; z < (int) views.count(); z++) { |
1893 | views.at(z)->tagLines(start, end, 0, 0xffffff); | 1893 | views.at(z)->tagLines(start, end, 0, 0xffffff); |
1894 | } | 1894 | } |
1895 | } | 1895 | } |
1896 | 1896 | ||
1897 | void KateDocument::tagAll() { | 1897 | void KateDocument::tagAll() { |
1898 | int z; | 1898 | int z; |
1899 | 1899 | ||
1900 | for (z = 0; z < (int) views.count(); z++) { | 1900 | for (z = 0; z < (int) views.count(); z++) { |
1901 | views.at(z)->tagAll(); | 1901 | views.at(z)->tagAll(); |
1902 | } | 1902 | } |
1903 | } | 1903 | } |
1904 | 1904 | ||
1905 | void KateDocument::updateLines(int startLine, int endLine, int flags, int cursorY) { | 1905 | void KateDocument::updateLines(int startLine, int endLine, int flags, int cursorY) { |
1906 | TextLine::Ptr textLine; | 1906 | TextLine::Ptr textLine; |
1907 | int line, last_line; | 1907 | int line, last_line; |
1908 | int ctxNum, endCtx; | 1908 | int ctxNum, endCtx; |
1909 | // kdDebug(13020)<<"******************KateDocument::updateLines Checkpoint 1"<<endl; | 1909 | // kdDebug(13020)<<"******************KateDocument::updateLines Checkpoint 1"<<endl; |
1910 | if (buffer->line(startLine)==0) {kdDebug(13020)<<"********************No buffer for line " << startLine << " found**************"<<endl; return;}; | 1910 | if (buffer->line(startLine)==0) {kdDebug(13020)<<"********************No buffer for line " << startLine << " found**************"<<endl; return;}; |
1911 | // kdDebug(13020)<<"KateDocument::updateLines Checkpoint 2"<<endl; | 1911 | // kdDebug(13020)<<"KateDocument::updateLines Checkpoint 2"<<endl; |
1912 | last_line = lastLine(); | 1912 | last_line = lastLine(); |
1913 | // if (endLine >= last_line) endLine = last_line; | 1913 | // if (endLine >= last_line) endLine = last_line; |
1914 | 1914 | ||
1915 | line = startLine; | 1915 | line = startLine; |
1916 | ctxNum = 0; | 1916 | ctxNum = 0; |
1917 | if (line > 0) ctxNum = getTextLine(line - 1)->getContext(); | 1917 | if (line > 0) ctxNum = getTextLine(line - 1)->getContext(); |
1918 | do { | 1918 | do { |
1919 | // kdDebug(13020)<<QString("**************Working on line: %1").arg(line)<<endl; | 1919 | // kdDebug(13020)<<QString("**************Working on line: %1").arg(line)<<endl; |
1920 | textLine = getTextLine(line); | 1920 | textLine = getTextLine(line); |
1921 | if (textLine==0) kdDebug(13020)<<"****updateLines()>> error textLine==0"<<endl; | 1921 | if (textLine==0) kdDebug(13020)<<"****updateLines()>> error textLine==0"<<endl; |
1922 | if (line <= endLine && line != cursorY) { | 1922 | if (line <= endLine && line != cursorY) { |
1923 | if (flags & KateView::cfRemoveSpaces) textLine->removeSpaces(); | 1923 | if (flags & KateView::cfRemoveSpaces) textLine->removeSpaces(); |
1924 | updateMaxLength(textLine); | 1924 | updateMaxLength(textLine); |
1925 | } | 1925 | } |
1926 | endCtx = textLine->getContext(); | 1926 | endCtx = textLine->getContext(); |
1927 | // odebug << "DOHIGHLIGHT" << oendl; | 1927 | // odebug << "DOHIGHLIGHT" << oendl; |
1928 | 1928 | ||
1929 | ctxNum = m_highlight->doHighlight(ctxNum,textLine); | 1929 | ctxNum = m_highlight->doHighlight(ctxNum,textLine); |
1930 | textLine->setContext(ctxNum); | 1930 | textLine->setContext(ctxNum); |
1931 | line++; | 1931 | line++; |
1932 | } while ((buffer->line(line)!=0) && (line <= endLine || endCtx != ctxNum)); | 1932 | } while ((buffer->line(line)!=0) && (line <= endLine || endCtx != ctxNum)); |
1933 | // kdDebug(13020)<<"updateLines :: while loop left"<<endl; | 1933 | // kdDebug(13020)<<"updateLines :: while loop left"<<endl; |
1934 | tagLines(startLine, line - 1); | 1934 | tagLines(startLine, line - 1); |
1935 | } | 1935 | } |
1936 | 1936 | ||
1937 | 1937 | ||
1938 | void KateDocument::updateMaxLength(TextLine::Ptr &textLine) { | 1938 | void KateDocument::updateMaxLength(TextLine::Ptr &textLine) { |
1939 | int len; | 1939 | int len; |
1940 | 1940 | ||
1941 | len = textWidth(textLine,textLine->length()); | 1941 | len = textWidth(textLine,textLine->length()); |
1942 | 1942 | ||
1943 | if (len > maxLength) { | 1943 | if (len > maxLength) { |
1944 | longestLine = textLine; | 1944 | longestLine = textLine; |
1945 | maxLength = len; | 1945 | maxLength = len; |
1946 | newDocGeometry = true; | 1946 | newDocGeometry = true; |
1947 | } else { | 1947 | } else { |
1948 | if (!longestLine || (textLine == longestLine && len <= maxLength*3/4)) { | 1948 | if (!longestLine || (textLine == longestLine && len <= maxLength*3/4)) { |
1949 | maxLength = -1; | 1949 | maxLength = -1; |
1950 | for (int i = 0; i < numLines();i++) { | 1950 | for (int i = 0; i < numLines();i++) { |
1951 | textLine = getTextLine(i); | 1951 | textLine = getTextLine(i); |
1952 | len = textWidth(textLine,textLine->length()); | 1952 | len = textWidth(textLine,textLine->length()); |
1953 | if (len > maxLength) { | 1953 | if (len > maxLength) { |
1954 | maxLength = len; | 1954 | maxLength = len; |
1955 | longestLine = textLine; | 1955 | longestLine = textLine; |
1956 | } | 1956 | } |
1957 | } | 1957 | } |
1958 | newDocGeometry = true; | 1958 | newDocGeometry = true; |
1959 | } | 1959 | } |
1960 | } | 1960 | } |
1961 | } | 1961 | } |
1962 | 1962 | ||
1963 | void KateDocument::slotBufferChanged() { | 1963 | void KateDocument::slotBufferChanged() { |
1964 | newDocGeometry = true; | 1964 | newDocGeometry = true; |
1965 | //updateLines();//JW | 1965 | //updateLines();//JW |
1966 | updateViews(); | 1966 | updateViews(); |
1967 | } | 1967 | } |
1968 | 1968 | ||
1969 | void KateDocument::slotBufferHighlight(long start,long stop) { | 1969 | void KateDocument::slotBufferHighlight(long start,long stop) { |
1970 | kdDebug(13020)<<"KateDocument::slotBufferHighlight"<<QString("%1-%2").arg(start).arg(stop)<<endl; | 1970 | kdDebug(13020)<<"KateDocument::slotBufferHighlight"<<QString("%1-%2").arg(start).arg(stop)<<endl; |
1971 | updateLines(start,stop); | 1971 | updateLines(start,stop); |
1972 | // buffer->startLoadTimer(); | 1972 | // buffer->startLoadTimer(); |
1973 | } | 1973 | } |
1974 | 1974 | ||
1975 | void KateDocument::updateViews(KateView *exclude) { | 1975 | void KateDocument::updateViews(KateView *exclude) { |
1976 | KateView *view; | 1976 | KateView *view; |
1977 | int flags; | 1977 | int flags; |
1978 | bool markState = hasMarkedText(); | 1978 | bool markState = hasMarkedText(); |
1979 | 1979 | ||
1980 | flags = (newDocGeometry) ? KateView::ufDocGeometry : 0; | 1980 | flags = (newDocGeometry) ? KateView::ufDocGeometry : 0; |
1981 | for (view = views.first(); view != 0L; view = views.next() ) { | 1981 | for (view = views.first(); view != 0L; view = views.next() ) { |
1982 | if (view != exclude) view->updateView(flags); | 1982 | if (view != exclude) view->updateView(flags); |
1983 | 1983 | ||
1984 | // notify every view about the changed mark state.... | 1984 | // notify every view about the changed mark state.... |
1985 | if (oldMarkState != markState) emit view->newMarkStatus(); | 1985 | if (oldMarkState != markState) emit view->newMarkStatus(); |
1986 | } | 1986 | } |
1987 | oldMarkState = markState; | 1987 | oldMarkState = markState; |
1988 | newDocGeometry = false; | 1988 | newDocGeometry = false; |
1989 | } | 1989 | } |
1990 | 1990 | ||
1991 | QColor &KateDocument::cursorCol(int x, int y) { | 1991 | QColor &KateDocument::cursorCol(int x, int y) { |
1992 | int attr; | 1992 | int attr; |
1993 | Attribute *a; | 1993 | Attribute *a; |
1994 | 1994 | ||
1995 | TextLine::Ptr textLine = getTextLine(y); | 1995 | TextLine::Ptr textLine = getTextLine(y); |
1996 | attr = textLine->getRawAttr(x); | 1996 | attr = textLine->getRawAttr(x); |
1997 | a = &m_attribs[attr & taAttrMask]; | 1997 | a = &m_attribs[attr & taAttrMask]; |
1998 | if (attr & taSelected) return a->selCol; else return a->col; | 1998 | if (attr & taSelected) return a->selCol; else return a->col; |
1999 | } | 1999 | } |
2000 | 2000 | ||
2001 | void KateDocument::paintTextLine(QPainter &paint, int line, int xStart, int xEnd, bool showTabs) | 2001 | void KateDocument::paintTextLine(QPainter &paint, int line, int xStart, int xEnd, bool showTabs) |
2002 | { | 2002 | { |
2003 | paintTextLine (paint, line, 0, xStart, xEnd, showTabs); | 2003 | paintTextLine (paint, line, 0, xStart, xEnd, showTabs); |
2004 | } | 2004 | } |
2005 | 2005 | ||
2006 | void KateDocument::paintTextLine(QPainter &paint, int line, int y, int xStart, int xEnd, bool showTabs) | 2006 | void KateDocument::paintTextLine(QPainter &paint, int line, int y, int xStart, int xEnd, bool showTabs) |
2007 | { | 2007 | { |
2008 | TextLine::Ptr textLine; | 2008 | TextLine::Ptr textLine; |
2009 | int len; | 2009 | int len; |
2010 | const QChar *s; | 2010 | const QChar *s; |
2011 | int z, x; | 2011 | int z, x; |
2012 | QChar ch; | 2012 | QChar ch; |
2013 | Attribute *a = 0L; | 2013 | Attribute *a = 0L; |
2014 | int attr, nextAttr; | 2014 | int attr, nextAttr; |
2015 | int xs; | 2015 | int xs; |
2016 | int xc, zc; | 2016 | int xc, zc; |
2017 | 2017 | ||
2018 | if (line > lastLine()) { | 2018 | if (line > lastLine()) { |
2019 | paint.fillRect(0, y, xEnd - xStart,fontHeight, colors[0]); | 2019 | paint.fillRect(0, y, xEnd - xStart,fontHeight, colors[0]); |
2020 | return; | 2020 | return; |
2021 | } | 2021 | } |
2022 | 2022 | ||
2023 | textLine = getTextLine(line); | 2023 | textLine = getTextLine(line); |
2024 | len = textLine->length(); | 2024 | len = textLine->length(); |
2025 | s = textLine->getText(); | 2025 | s = textLine->getText(); |
2026 | 2026 | ||
2027 | // skip to first visible character | 2027 | // skip to first visible character |
2028 | x = 0; | 2028 | x = 0; |
2029 | z = 0; | 2029 | z = 0; |
2030 | do { | 2030 | do { |
2031 | xc = x; | 2031 | xc = x; |
2032 | zc = z; | 2032 | zc = z; |
2033 | if (z == len) break; | 2033 | if (z == len) break; |
2034 | ch = s[z];//textLine->getChar(z); | 2034 | ch = s[z];//textLine->getChar(z); |
2035 | if (ch == '\t') { | 2035 | if (ch == '\t') { |
2036 | x += m_tabWidth - (x % m_tabWidth); | 2036 | x += m_tabWidth - (x % m_tabWidth); |
2037 | } else { | 2037 | } else { |
2038 | a = &m_attribs[textLine->getAttr(z)]; | 2038 | a = &m_attribs[textLine->getAttr(z)]; |
2039 | 2039 | ||
2040 | if (a->bold && a->italic) | 2040 | if (a->bold && a->italic) |
2041 | x += myFontMetricsBI.width(ch); | 2041 | x += myFontMetricsBI.width(ch); |
2042 | else if (a->bold) | 2042 | else if (a->bold) |
2043 | x += myFontMetricsBold.width(ch); | 2043 | x += myFontMetricsBold.width(ch); |
2044 | else if (a->italic) | 2044 | else if (a->italic) |
2045 | x += myFontMetricsItalic.width(ch); | 2045 | x += myFontMetricsItalic.width(ch); |
2046 | else | 2046 | else |
2047 | x += myFontMetrics.width(ch); | 2047 | x += myFontMetrics.width(ch); |
2048 | } | 2048 | } |
2049 | z++; | 2049 | z++; |
2050 | } while (x <= xStart); | 2050 | } while (x <= xStart); |
2051 | 2051 | ||
2052 | // draw background | 2052 | // draw background |
2053 | xs = xStart; | 2053 | xs = xStart; |
2054 | attr = textLine->getRawAttr(zc); | 2054 | attr = textLine->getRawAttr(zc); |
2055 | while (x < xEnd) | 2055 | while (x < xEnd) |
2056 | { | 2056 | { |
2057 | nextAttr = textLine->getRawAttr(z); | 2057 | nextAttr = textLine->getRawAttr(z); |
2058 | if ((nextAttr ^ attr) & taSelected) | 2058 | if ((nextAttr ^ attr) & taSelected) |
2059 | { | 2059 | { |
2060 | if (attr & taSelected) | 2060 | if (attr & taSelected) |
2061 | paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[1]); | 2061 | paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[1]); |
2062 | else | 2062 | else |
2063 | paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[0]); | 2063 | paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[0]); |
2064 | 2064 | ||
2065 | xs = x; | 2065 | xs = x; |
2066 | attr = nextAttr; | 2066 | attr = nextAttr; |
2067 | } | 2067 | } |
2068 | 2068 | ||
2069 | if (z == len) break; | 2069 | if (z == len) break; |
2070 | 2070 | ||
2071 | ch = s[z];//textLine->getChar(z); | 2071 | ch = s[z];//textLine->getChar(z); |
2072 | 2072 | ||
2073 | if (ch == '\t') | 2073 | if (ch == '\t') |
2074 | x += m_tabWidth - (x % m_tabWidth); | 2074 | x += m_tabWidth - (x % m_tabWidth); |
2075 | else | 2075 | else |
2076 | { | 2076 | { |
2077 | a = &m_attribs[textLine->getAttr(z)]; | 2077 | a = &m_attribs[textLine->getAttr(z)]; |
2078 | 2078 | ||
2079 | if (a->bold && a->italic) | 2079 | if (a->bold && a->italic) |
2080 | x += myFontMetricsBI.width(ch); | 2080 | x += myFontMetricsBI.width(ch); |
2081 | else if (a->bold) | 2081 | else if (a->bold) |
2082 | x += myFontMetricsBold.width(ch); | 2082 | x += myFontMetricsBold.width(ch); |
2083 | else if (a->italic) | 2083 | else if (a->italic) |
2084 | x += myFontMetricsItalic.width(ch); | 2084 | x += myFontMetricsItalic.width(ch); |
2085 | else | 2085 | else |
2086 | x += myFontMetrics.width(ch); | 2086 | x += myFontMetrics.width(ch); |
2087 | } | 2087 | } |
2088 | z++; | 2088 | z++; |
2089 | } | 2089 | } |
2090 | 2090 | ||
2091 | if (attr & taSelected) | 2091 | if (attr & taSelected) |
2092 | paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[1]); | 2092 | paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[1]); |
2093 | else | 2093 | else |
2094 | paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[0]); | 2094 | paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[0]); |
2095 | 2095 | ||
2096 | len = z; //reduce length to visible length | 2096 | len = z; //reduce length to visible length |
2097 | 2097 | ||
2098 | // draw text | 2098 | // draw text |
2099 | x = xc; | 2099 | x = xc; |
2100 | z = zc; | 2100 | z = zc; |
2101 | y += fontAscent;// -1; | 2101 | y += fontAscent;// -1; |
2102 | attr = -1; | 2102 | attr = -1; |
2103 | while (z < len) { | 2103 | while (z < len) { |
2104 | ch = s[z];//textLine->getChar(z); | 2104 | ch = s[z];//textLine->getChar(z); |
2105 | if (ch == '\t') { | 2105 | if (ch == '\t') { |
2106 | if (z > zc) { | 2106 | if (z > zc) { |
2107 | //this should cause no copy at all | 2107 | //this should cause no copy at all |
2108 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); | 2108 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); |
2109 | QString s = str.string(); | 2109 | QString s = str.string(); |
2110 | paint.drawText(x - xStart, y, s); | 2110 | paint.drawText(x - xStart, y, s); |
2111 | 2111 | ||
2112 | if (a->bold && a->italic) | 2112 | if (a->bold && a->italic) |
2113 | x += myFontMetricsBI.width(s); | 2113 | x += myFontMetricsBI.width(s); |
2114 | else if (a->bold) | 2114 | else if (a->bold) |
2115 | x += myFontMetricsBold.width(s); | 2115 | x += myFontMetricsBold.width(s); |
2116 | else if (a->italic) | 2116 | else if (a->italic) |
2117 | x += myFontMetricsItalic.width(s); | 2117 | x += myFontMetricsItalic.width(s); |
2118 | else | 2118 | else |
2119 | x += myFontMetrics.width(s); | 2119 | x += myFontMetrics.width(s); |
2120 | } | 2120 | } |
2121 | zc = z +1; | 2121 | zc = z +1; |
2122 | 2122 | ||
2123 | if (showTabs) { | 2123 | if (showTabs) { |
2124 | nextAttr = textLine->getRawAttr(z); | 2124 | nextAttr = textLine->getRawAttr(z); |
2125 | if (nextAttr != attr) { | 2125 | if (nextAttr != attr) { |
2126 | attr = nextAttr; | 2126 | attr = nextAttr; |
2127 | a = &m_attribs[attr & taAttrMask]; | 2127 | a = &m_attribs[attr & taAttrMask]; |
2128 | 2128 | ||
2129 | if (attr & taSelected) paint.setPen(a->selCol); | 2129 | if (attr & taSelected) paint.setPen(a->selCol); |
2130 | else paint.setPen(a->col); | 2130 | else paint.setPen(a->col); |
2131 | 2131 | ||
2132 | if (a->bold && a->italic) | 2132 | if (a->bold && a->italic) |
2133 | paint.setFont(myFontBI); | 2133 | paint.setFont(myFontBI); |
2134 | else if (a->bold) | 2134 | else if (a->bold) |
2135 | paint.setFont(myFontBold); | 2135 | paint.setFont(myFontBold); |
2136 | else if (a->italic) | 2136 | else if (a->italic) |
2137 | paint.setFont(myFontItalic); | 2137 | paint.setFont(myFontItalic); |
2138 | else | 2138 | else |
2139 | paint.setFont(myFont); | 2139 | paint.setFont(myFont); |
2140 | } | 2140 | } |
2141 | 2141 | ||
2142 | // paint.drawLine(x - xStart, y -2, x - xStart, y); | 2142 | // paint.drawLine(x - xStart, y -2, x - xStart, y); |
2143 | // paint.drawLine(x - xStart, y, x - xStart + 2, y); | 2143 | // paint.drawLine(x - xStart, y, x - xStart + 2, y); |
2144 | paint.drawPoint(x - xStart, y); | 2144 | paint.drawPoint(x - xStart, y); |
2145 | paint.drawPoint(x - xStart +1, y); | 2145 | paint.drawPoint(x - xStart +1, y); |
2146 | paint.drawPoint(x - xStart, y -1); | 2146 | paint.drawPoint(x - xStart, y -1); |
2147 | } | 2147 | } |
2148 | x += m_tabWidth - (x % m_tabWidth); | 2148 | x += m_tabWidth - (x % m_tabWidth); |
2149 | } else { | 2149 | } else { |
2150 | nextAttr = textLine->getRawAttr(z); | 2150 | nextAttr = textLine->getRawAttr(z); |
2151 | if (nextAttr != attr) { | 2151 | if (nextAttr != attr) { |
2152 | if (z > zc) { | 2152 | if (z > zc) { |
2153 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); | 2153 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); |
2154 | QString s = str.string(); | 2154 | QString s = str.string(); |
2155 | paint.drawText(x - xStart, y, s); | 2155 | paint.drawText(x - xStart, y, s); |
2156 | 2156 | ||
2157 | if (a->bold && a->italic) | 2157 | if (a->bold && a->italic) |
2158 | x += myFontMetricsBI.width(s); | 2158 | x += myFontMetricsBI.width(s); |
2159 | else if (a->bold) | 2159 | else if (a->bold) |
2160 | x += myFontMetricsBold.width(s); | 2160 | x += myFontMetricsBold.width(s); |
2161 | else if (a->italic) | 2161 | else if (a->italic) |
2162 | x += myFontMetricsItalic.width(s); | 2162 | x += myFontMetricsItalic.width(s); |
2163 | else | 2163 | else |
2164 | x += myFontMetrics.width(s); | 2164 | x += myFontMetrics.width(s); |
2165 | zc = z; | 2165 | zc = z; |
2166 | } | 2166 | } |
2167 | attr = nextAttr; | 2167 | attr = nextAttr; |
2168 | a = &m_attribs[attr & taAttrMask]; | 2168 | a = &m_attribs[attr & taAttrMask]; |
2169 | 2169 | ||
2170 | if (attr & taSelected) paint.setPen(a->selCol); | 2170 | if (attr & taSelected) paint.setPen(a->selCol); |
2171 | else paint.setPen(a->col); | 2171 | else paint.setPen(a->col); |
2172 | 2172 | ||
2173 | if (a->bold && a->italic) | 2173 | if (a->bold && a->italic) |
2174 | paint.setFont(myFontBI); | 2174 | paint.setFont(myFontBI); |
2175 | else if (a->bold) | 2175 | else if (a->bold) |
2176 | paint.setFont(myFontBold); | 2176 | paint.setFont(myFontBold); |
2177 | else if (a->italic) | 2177 | else if (a->italic) |
2178 | paint.setFont(myFontItalic); | 2178 | paint.setFont(myFontItalic); |
2179 | else | 2179 | else |
2180 | paint.setFont(myFont); | 2180 | paint.setFont(myFont); |
2181 | } | 2181 | } |
2182 | } | 2182 | } |
2183 | z++; | 2183 | z++; |
2184 | } | 2184 | } |
2185 | if (z > zc) { | 2185 | if (z > zc) { |
2186 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); | 2186 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); |
2187 | paint.drawText(x - xStart, y, str.string()); | 2187 | paint.drawText(x - xStart, y, str.string()); |
2188 | } | 2188 | } |
2189 | } | 2189 | } |
2190 | 2190 | ||
2191 | // Applies the search context, and returns whether a match was found. If one is, | 2191 | // Applies the search context, and returns whether a match was found. If one is, |
2192 | // the length of the string matched is also returned. | 2192 | // the length of the string matched is also returned. |
2193 | bool KateDocument::doSearch(SConfig &sc, const QString &searchFor) { | 2193 | bool KateDocument::doSearch(SConfig &sc, const QString &searchFor) { |
2194 | int line, col; | 2194 | int line, col; |
2195 | int searchEnd; | 2195 | int searchEnd; |
2196 | int bufLen, tlen; | 2196 | int bufLen, tlen; |
2197 | QChar *t; | 2197 | QChar *t; |
2198 | TextLine::Ptr textLine; | 2198 | TextLine::Ptr textLine; |
2199 | int pos, newPos; | 2199 | int pos, newPos; |
2200 | 2200 | ||
2201 | if (searchFor.isEmpty()) return false; | 2201 | if (searchFor.isEmpty()) return false; |
2202 | 2202 | ||
2203 | bufLen = 0; | 2203 | bufLen = 0; |
2204 | t = 0L; | 2204 | t = 0L; |
2205 | 2205 | ||
2206 | line = sc.cursor.y; | 2206 | line = sc.cursor.y; |
2207 | col = sc.cursor.x; | 2207 | col = sc.cursor.x; |
2208 | if (!(sc.flags & KateView::sfBackward)) { | 2208 | if (!(sc.flags & KateView::sfBackward)) { |
2209 | //forward search | 2209 | //forward search |
2210 | if (sc.flags & KateView::sfSelected) { | 2210 | if (sc.flags & KateView::sfSelected) { |
2211 | if (line < selectStart) { | 2211 | if (line < selectStart) { |
2212 | line = selectStart; | 2212 | line = selectStart; |
2213 | col = 0; | 2213 | col = 0; |
2214 | } | 2214 | } |
2215 | searchEnd = selectEnd; | 2215 | searchEnd = selectEnd; |
2216 | } else searchEnd = lastLine(); | 2216 | } else searchEnd = lastLine(); |
2217 | 2217 | ||
2218 | while (line <= searchEnd) { | 2218 | while (line <= searchEnd) { |
2219 | textLine = getTextLine(line); | 2219 | textLine = getTextLine(line); |
2220 | tlen = textLine->length(); | 2220 | tlen = textLine->length(); |
2221 | if (tlen > bufLen) { | 2221 | if (tlen > bufLen) { |
2222 | delete t; | 2222 | delete [] t; |
2223 | bufLen = (tlen + 255) & (~255); | 2223 | bufLen = (tlen + 255) & (~255); |
2224 | t = new QChar[bufLen]; | 2224 | t = new QChar[bufLen]; |
2225 | } | 2225 | } |
2226 | memcpy(t, textLine->getText(), tlen*sizeof(QChar)); | 2226 | memcpy(t, textLine->getText(), tlen*sizeof(QChar)); |
2227 | if (sc.flags & KateView::sfSelected) { | 2227 | if (sc.flags & KateView::sfSelected) { |
2228 | pos = 0; | 2228 | pos = 0; |
2229 | do { | 2229 | do { |
2230 | pos = textLine->findSelected(pos); | 2230 | pos = textLine->findSelected(pos); |
2231 | newPos = textLine->findUnselected(pos); | 2231 | newPos = textLine->findUnselected(pos); |
2232 | memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); | 2232 | memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); |
2233 | pos = newPos; | 2233 | pos = newPos; |
2234 | } while (pos < tlen); | 2234 | } while (pos < tlen); |
2235 | } | 2235 | } |
2236 | 2236 | ||
2237 | QString text(t, tlen); | 2237 | QString text(t, tlen); |
2238 | if (sc.flags & KateView::sfWholeWords) { | 2238 | if (sc.flags & KateView::sfWholeWords) { |
2239 | // Until the end of the line... | 2239 | // Until the end of the line... |
2240 | while (col < tlen) { | 2240 | while (col < tlen) { |
2241 | // ...find the next match. | 2241 | // ...find the next match. |
2242 | col = sc.search(text, col); | 2242 | col = sc.search(text, col); |
2243 | if (col != -1) { | 2243 | if (col != -1) { |
2244 | // Is the match delimited correctly? | 2244 | // Is the match delimited correctly? |
2245 | if (((col == 0) || (!m_highlight->isInWord(t[col]))) && | 2245 | if (((col == 0) || (!m_highlight->isInWord(t[col]))) && |
2246 | ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { | 2246 | ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { |
2247 | goto found; | 2247 | goto found; |
2248 | } | 2248 | } |
2249 | else { | 2249 | else { |
2250 | // Start again from the next character. | 2250 | // Start again from the next character. |
2251 | col++; | 2251 | col++; |
2252 | } | 2252 | } |
2253 | } | 2253 | } |
2254 | else { | 2254 | else { |
2255 | // No match. | 2255 | // No match. |
2256 | break; | 2256 | break; |
2257 | } | 2257 | } |
2258 | } | 2258 | } |
2259 | } | 2259 | } |
2260 | else { | 2260 | else { |
2261 | // Non-whole-word search. | 2261 | // Non-whole-word search. |
2262 | col = sc.search(text, col); | 2262 | col = sc.search(text, col); |
2263 | if (col != -1) | 2263 | if (col != -1) |
2264 | goto found; | 2264 | goto found; |
2265 | } | 2265 | } |
2266 | col = 0; | 2266 | col = 0; |
2267 | line++; | 2267 | line++; |
2268 | } | 2268 | } |
2269 | } else { | 2269 | } else { |
2270 | // backward search | 2270 | // backward search |
2271 | if (sc.flags & KateView::sfSelected) { | 2271 | if (sc.flags & KateView::sfSelected) { |
2272 | if (line > selectEnd) { | 2272 | if (line > selectEnd) { |
2273 | line = selectEnd; | 2273 | line = selectEnd; |
2274 | col = -1; | 2274 | col = -1; |
2275 | } | 2275 | } |
2276 | searchEnd = selectStart; | 2276 | searchEnd = selectStart; |
2277 | } else searchEnd = 0; | 2277 | } else searchEnd = 0; |
2278 | 2278 | ||
2279 | while (line >= searchEnd) { | 2279 | while (line >= searchEnd) { |
2280 | textLine = getTextLine(line); | 2280 | textLine = getTextLine(line); |
2281 | tlen = textLine->length(); | 2281 | tlen = textLine->length(); |
2282 | if (tlen > bufLen) { | 2282 | if (tlen > bufLen) { |
2283 | delete t; | 2283 | delete [] t; |
2284 | bufLen = (tlen + 255) & (~255); | 2284 | bufLen = (tlen + 255) & (~255); |
2285 | t = new QChar[bufLen]; | 2285 | t = new QChar[bufLen]; |
2286 | } | 2286 | } |
2287 | memcpy(t, textLine->getText(), tlen*sizeof(QChar)); | 2287 | memcpy(t, textLine->getText(), tlen*sizeof(QChar)); |
2288 | if (sc.flags & KateView::sfSelected) { | 2288 | if (sc.flags & KateView::sfSelected) { |
2289 | pos = 0; | 2289 | pos = 0; |
2290 | do { | 2290 | do { |
2291 | pos = textLine->findSelected(pos); | 2291 | pos = textLine->findSelected(pos); |
2292 | newPos = textLine->findUnselected(pos); | 2292 | newPos = textLine->findUnselected(pos); |
2293 | memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); | 2293 | memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); |
2294 | pos = newPos; | 2294 | pos = newPos; |
2295 | } while (pos < tlen); | 2295 | } while (pos < tlen); |
2296 | } | 2296 | } |
2297 | 2297 | ||
2298 | if (col < 0 || col > tlen) col = tlen; | 2298 | if (col < 0 || col > tlen) col = tlen; |
2299 | 2299 | ||
2300 | QString text(t, tlen); | 2300 | QString text(t, tlen); |
2301 | if (sc.flags & KateView::sfWholeWords) { | 2301 | if (sc.flags & KateView::sfWholeWords) { |
2302 | // Until the beginning of the line... | 2302 | // Until the beginning of the line... |
2303 | while (col >= 0) { | 2303 | while (col >= 0) { |
2304 | // ...find the next match. | 2304 | // ...find the next match. |
2305 | col = sc.search(text, col); | 2305 | col = sc.search(text, col); |
2306 | if (col != -1) { | 2306 | if (col != -1) { |
2307 | // Is the match delimited correctly? | 2307 | // Is the match delimited correctly? |
2308 | if (((col == 0) || (!m_highlight->isInWord(t[col]))) && | 2308 | if (((col == 0) || (!m_highlight->isInWord(t[col]))) && |
2309 | ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { | 2309 | ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { |
2310 | goto found; | 2310 | goto found; |
2311 | } | 2311 | } |
2312 | else { | 2312 | else { |
2313 | // Start again from the previous character. | 2313 | // Start again from the previous character. |
2314 | col--; | 2314 | col--; |
2315 | } | 2315 | } |
2316 | } | 2316 | } |
2317 | else { | 2317 | else { |
2318 | // No match. | 2318 | // No match. |
2319 | break; | 2319 | break; |
2320 | } | 2320 | } |
2321 | } | 2321 | } |
2322 | } | 2322 | } |
2323 | else { | 2323 | else { |
2324 | // Non-whole-word search. | 2324 | // Non-whole-word search. |
2325 | col = sc.search(text, col); | 2325 | col = sc.search(text, col); |
2326 | if (col != -1) | 2326 | if (col != -1) |
2327 | goto found; | 2327 | goto found; |
2328 | } | 2328 | } |
2329 | col = -1; | 2329 | col = -1; |
2330 | line--; | 2330 | line--; |
2331 | } | 2331 | } |
2332 | } | 2332 | } |
2333 | sc.flags |= KateView::sfWrapped; | 2333 | sc.flags |= KateView::sfWrapped; |
2334 | return false; | 2334 | return false; |
2335 | found: | 2335 | found: |
2336 | if (sc.flags & KateView::sfWrapped) { | 2336 | if (sc.flags & KateView::sfWrapped) { |
2337 | if ((line > sc.startCursor.y || (line == sc.startCursor.y && col >= sc.startCursor.x)) | 2337 | if ((line > sc.startCursor.y || (line == sc.startCursor.y && col >= sc.startCursor.x)) |
2338 | ^ ((sc.flags & KateView::sfBackward) != 0)) return false; | 2338 | ^ ((sc.flags & KateView::sfBackward) != 0)) return false; |
2339 | } | 2339 | } |
2340 | sc.cursor.x = col; | 2340 | sc.cursor.x = col; |
2341 | sc.cursor.y = line; | 2341 | sc.cursor.y = line; |
2342 | return true; | 2342 | return true; |
2343 | } | 2343 | } |
2344 | 2344 | ||
2345 | void KateDocument::tagLine(int line) { | 2345 | void KateDocument::tagLine(int line) { |
2346 | 2346 | ||
2347 | if (tagStart > line) tagStart = line; | 2347 | if (tagStart > line) tagStart = line; |
2348 | if (tagEnd < line) tagEnd = line; | 2348 | if (tagEnd < line) tagEnd = line; |
2349 | } | 2349 | } |
2350 | 2350 | ||
2351 | void KateDocument::insLine(int line) { | 2351 | void KateDocument::insLine(int line) { |
2352 | KateView *view; | 2352 | KateView *view; |
2353 | 2353 | ||
2354 | if (selectStart >= line) selectStart++; | 2354 | if (selectStart >= line) selectStart++; |
2355 | if (selectEnd >= line) selectEnd++; | 2355 | if (selectEnd >= line) selectEnd++; |
2356 | if (tagStart >= line) tagStart++; | 2356 | if (tagStart >= line) tagStart++; |
2357 | if (tagEnd >= line) tagEnd++; | 2357 | if (tagEnd >= line) tagEnd++; |
2358 | 2358 | ||
2359 | newDocGeometry = true; | 2359 | newDocGeometry = true; |
2360 | for (view = views.first(); view != 0L; view = views.next() ) { | 2360 | for (view = views.first(); view != 0L; view = views.next() ) { |
2361 | view->insLine(line); | 2361 | view->insLine(line); |
2362 | } | 2362 | } |
2363 | } | 2363 | } |
2364 | 2364 | ||
2365 | void KateDocument::delLine(int line) { | 2365 | void KateDocument::delLine(int line) { |
2366 | KateView *view; | 2366 | KateView *view; |
2367 | 2367 | ||
2368 | if (selectStart >= line && selectStart > 0) selectStart--; | 2368 | if (selectStart >= line && selectStart > 0) selectStart--; |
2369 | if (selectEnd >= line) selectEnd--; | 2369 | if (selectEnd >= line) selectEnd--; |
2370 | if (tagStart >= line && tagStart > 0) tagStart--; | 2370 | if (tagStart >= line && tagStart > 0) tagStart--; |
2371 | if (tagEnd >= line) tagEnd--; | 2371 | if (tagEnd >= line) tagEnd--; |
2372 | 2372 | ||
2373 | newDocGeometry = true; | 2373 | newDocGeometry = true; |
2374 | for (view = views.first(); view != 0L; view = views.next() ) { | 2374 | for (view = views.first(); view != 0L; view = views.next() ) { |
2375 | view->delLine(line); | 2375 | view->delLine(line); |
2376 | } | 2376 | } |
2377 | } | 2377 | } |
2378 | 2378 | ||
2379 | void KateDocument::optimizeSelection() { | 2379 | void KateDocument::optimizeSelection() { |
2380 | TextLine::Ptr textLine; | 2380 | TextLine::Ptr textLine; |
2381 | 2381 | ||
2382 | while (selectStart <= selectEnd) { | 2382 | while (selectStart <= selectEnd) { |
2383 | textLine = getTextLine(selectStart); | 2383 | textLine = getTextLine(selectStart); |
2384 | if (textLine->isSelected() || textLine->numSelected() > 0) break; | 2384 | if (textLine->isSelected() || textLine->numSelected() > 0) break; |
2385 | selectStart++; | 2385 | selectStart++; |
2386 | } | 2386 | } |
2387 | while (selectEnd >= selectStart) { | 2387 | while (selectEnd >= selectStart) { |
2388 | textLine = getTextLine(selectEnd); | 2388 | textLine = getTextLine(selectEnd); |
2389 | if (textLine->isSelected() || textLine->numSelected() > 0) break; | 2389 | if (textLine->isSelected() || textLine->numSelected() > 0) break; |
2390 | selectEnd--; | 2390 | selectEnd--; |
2391 | } | 2391 | } |
2392 | if (selectStart > selectEnd) { | 2392 | if (selectStart > selectEnd) { |
2393 | selectStart = 0xffffff; | 2393 | selectStart = 0xffffff; |
2394 | selectEnd = 0; | 2394 | selectEnd = 0; |
2395 | } | 2395 | } |
2396 | } | 2396 | } |
2397 | 2397 | ||
2398 | void KateDocument::doAction(KateAction *a) { | 2398 | void KateDocument::doAction(KateAction *a) { |
2399 | 2399 | ||
2400 | switch (a->action) { | 2400 | switch (a->action) { |
2401 | case KateAction::replace: | 2401 | case KateAction::replace: |
2402 | doReplace(a); | 2402 | doReplace(a); |
2403 | break; | 2403 | break; |
2404 | case KateAction::wordWrap: | 2404 | case KateAction::wordWrap: |
2405 | doWordWrap(a); | 2405 | doWordWrap(a); |
2406 | break; | 2406 | break; |
2407 | case KateAction::wordUnWrap: | 2407 | case KateAction::wordUnWrap: |
2408 | doWordUnWrap(a); | 2408 | doWordUnWrap(a); |
2409 | break; | 2409 | break; |
2410 | case KateAction::newLine: | 2410 | case KateAction::newLine: |
2411 | doNewLine(a); | 2411 | doNewLine(a); |
2412 | break; | 2412 | break; |
2413 | case KateAction::delLine: | 2413 | case KateAction::delLine: |
2414 | doDelLine(a); | 2414 | doDelLine(a); |
2415 | break; | 2415 | break; |
2416 | case KateAction::insLine: | 2416 | case KateAction::insLine: |
2417 | doInsLine(a); | 2417 | doInsLine(a); |
2418 | break; | 2418 | break; |
2419 | case KateAction::killLine: | 2419 | case KateAction::killLine: |
2420 | doKillLine(a); | 2420 | doKillLine(a); |
2421 | break; | 2421 | break; |
2422 | /* case KateAction::doubleLine: | 2422 | /* case KateAction::doubleLine: |
2423 | break; | 2423 | break; |
2424 | case KateAction::removeLine: | 2424 | case KateAction::removeLine: |
2425 | break;*/ | 2425 | break;*/ |
2426 | } | 2426 | } |
2427 | } | 2427 | } |
2428 | 2428 | ||
2429 | void KateDocument::doReplace(KateAction *a) { | 2429 | void KateDocument::doReplace(KateAction *a) { |
2430 | TextLine::Ptr textLine; | 2430 | TextLine::Ptr textLine; |
2431 | int l; | 2431 | int l; |
2432 | 2432 | ||
2433 | //exchange current text with stored text in KateAction *a | 2433 | //exchange current text with stored text in KateAction *a |
2434 | 2434 | ||
2435 | textLine = getTextLine(a->cursor.y); | 2435 | textLine = getTextLine(a->cursor.y); |
2436 | l = textLine->length() - a->cursor.x; | 2436 | l = textLine->length() - a->cursor.x; |
2437 | if (l > a->len) l = a->len; | 2437 | if (l > a->len) l = a->len; |
2438 | 2438 | ||
2439 | QString oldText(&textLine->getText()[a->cursor.x], (l < 0) ? 0 : l); | 2439 | QString oldText(&textLine->getText()[a->cursor.x], (l < 0) ? 0 : l); |
2440 | textLine->replace(a->cursor.x, a->len, a->text.unicode(), a->text.length()); | 2440 | textLine->replace(a->cursor.x, a->len, a->text.unicode(), a->text.length()); |
2441 | 2441 | ||
2442 | a->len = a->text.length(); | 2442 | a->len = a->text.length(); |
2443 | a->text = oldText; | 2443 | a->text = oldText; |
2444 | 2444 | ||
2445 | buffer->changeLine(a->cursor.y); | 2445 | buffer->changeLine(a->cursor.y); |
2446 | 2446 | ||
2447 | tagLine(a->cursor.y); | 2447 | tagLine(a->cursor.y); |
2448 | } | 2448 | } |
2449 | 2449 | ||
2450 | void KateDocument::doWordWrap(KateAction *a) { | 2450 | void KateDocument::doWordWrap(KateAction *a) { |
2451 | TextLine::Ptr textLine; | 2451 | TextLine::Ptr textLine; |
2452 | 2452 | ||
2453 | textLine = getTextLine(a->cursor.y - 1); | 2453 | textLine = getTextLine(a->cursor.y - 1); |
2454 | a->len = textLine->length() - a->cursor.x; | 2454 | a->len = textLine->length() - a->cursor.x; |
2455 | textLine->wrap(getTextLine(a->cursor.y),a->len); | 2455 | textLine->wrap(getTextLine(a->cursor.y),a->len); |
2456 | 2456 | ||
2457 | buffer->changeLine(a->cursor.y - 1); | 2457 | buffer->changeLine(a->cursor.y - 1); |
2458 | buffer->changeLine(a->cursor.y); | 2458 | buffer->changeLine(a->cursor.y); |
2459 | 2459 | ||
2460 | tagLine(a->cursor.y - 1); | 2460 | tagLine(a->cursor.y - 1); |
2461 | tagLine(a->cursor.y); | 2461 | tagLine(a->cursor.y); |
2462 | if (selectEnd == a->cursor.y - 1) selectEnd++; | 2462 | if (selectEnd == a->cursor.y - 1) selectEnd++; |
2463 | 2463 | ||
2464 | a->action = KateAction::wordUnWrap; | 2464 | a->action = KateAction::wordUnWrap; |
2465 | } | 2465 | } |
2466 | 2466 | ||
2467 | void KateDocument::doWordUnWrap(KateAction *a) { | 2467 | void KateDocument::doWordUnWrap(KateAction *a) { |
2468 | TextLine::Ptr textLine; | 2468 | TextLine::Ptr textLine; |
2469 | 2469 | ||
2470 | textLine = getTextLine(a->cursor.y - 1); | 2470 | textLine = getTextLine(a->cursor.y - 1); |
2471 | // textLine->setLength(a->len); | 2471 | // textLine->setLength(a->len); |
2472 | textLine->unWrap(a->len, getTextLine(a->cursor.y),a->cursor.x); | 2472 | textLine->unWrap(a->len, getTextLine(a->cursor.y),a->cursor.x); |
2473 | 2473 | ||
2474 | buffer->changeLine(a->cursor.y - 1); | 2474 | buffer->changeLine(a->cursor.y - 1); |
2475 | buffer->changeLine(a->cursor.y); | 2475 | buffer->changeLine(a->cursor.y); |
2476 | 2476 | ||
2477 | tagLine(a->cursor.y - 1); | 2477 | tagLine(a->cursor.y - 1); |
2478 | tagLine(a->cursor.y); | 2478 | tagLine(a->cursor.y); |
2479 | 2479 | ||
2480 | a->action = KateAction::wordWrap; | 2480 | a->action = KateAction::wordWrap; |
2481 | } | 2481 | } |
2482 | 2482 | ||
2483 | void KateDocument::doNewLine(KateAction *a) { | 2483 | void KateDocument::doNewLine(KateAction *a) { |
2484 | TextLine::Ptr textLine, newLine; | 2484 | TextLine::Ptr textLine, newLine; |
2485 | 2485 | ||
2486 | textLine = getTextLine(a->cursor.y); | 2486 | textLine = getTextLine(a->cursor.y); |
2487 | newLine = new TextLine(textLine->getRawAttr(), textLine->getContext()); | 2487 | newLine = new TextLine(textLine->getRawAttr(), textLine->getContext()); |
2488 | textLine->wrap(newLine,a->cursor.x); | 2488 | textLine->wrap(newLine,a->cursor.x); |
2489 | 2489 | ||
2490 | buffer->insertLine(a->cursor.y + 1, newLine); | 2490 | buffer->insertLine(a->cursor.y + 1, newLine); |
2491 | buffer->changeLine(a->cursor.y); | 2491 | buffer->changeLine(a->cursor.y); |
2492 | 2492 | ||
2493 | insLine(a->cursor.y + 1); | 2493 | insLine(a->cursor.y + 1); |
2494 | tagLine(a->cursor.y); | 2494 | tagLine(a->cursor.y); |
2495 | tagLine(a->cursor.y + 1); | 2495 | tagLine(a->cursor.y + 1); |
2496 | if (selectEnd == a->cursor.y) selectEnd++;//addSelection(a->cursor.y + 1); | 2496 | if (selectEnd == a->cursor.y) selectEnd++;//addSelection(a->cursor.y + 1); |
2497 | 2497 | ||
2498 | a->action = KateAction::delLine; | 2498 | a->action = KateAction::delLine; |
2499 | } | 2499 | } |
2500 | 2500 | ||
2501 | void KateDocument::doDelLine(KateAction *a) { | 2501 | void KateDocument::doDelLine(KateAction *a) { |
2502 | TextLine::Ptr textLine, nextLine; | 2502 | TextLine::Ptr textLine, nextLine; |
2503 | 2503 | ||
2504 | textLine = getTextLine(a->cursor.y); | 2504 | textLine = getTextLine(a->cursor.y); |
2505 | nextLine = getTextLine(a->cursor.y+1); | 2505 | nextLine = getTextLine(a->cursor.y+1); |
2506 | // textLine->setLength(a->cursor.x); | 2506 | // textLine->setLength(a->cursor.x); |
2507 | textLine->unWrap(a->cursor.x, nextLine,nextLine->length()); | 2507 | textLine->unWrap(a->cursor.x, nextLine,nextLine->length()); |
2508 | textLine->setContext(nextLine->getContext()); | 2508 | textLine->setContext(nextLine->getContext()); |
2509 | if (longestLine == nextLine) longestLine = 0L; | 2509 | if (longestLine == nextLine) longestLine = 0L; |
2510 | 2510 | ||
2511 | buffer->changeLine(a->cursor.y); | 2511 | buffer->changeLine(a->cursor.y); |
2512 | buffer->removeLine(a->cursor.y+1); | 2512 | buffer->removeLine(a->cursor.y+1); |
2513 | 2513 | ||
2514 | tagLine(a->cursor.y); | 2514 | tagLine(a->cursor.y); |
2515 | delLine(a->cursor.y + 1); | 2515 | delLine(a->cursor.y + 1); |
2516 | 2516 | ||
2517 | a->action = KateAction::newLine; | 2517 | a->action = KateAction::newLine; |
2518 | } | 2518 | } |
2519 | 2519 | ||
2520 | void KateDocument::doInsLine(KateAction *a) { | 2520 | void KateDocument::doInsLine(KateAction *a) { |
2521 | 2521 | ||
2522 | buffer->insertLine(a->cursor.y, new TextLine()); | 2522 | buffer->insertLine(a->cursor.y, new TextLine()); |
2523 | 2523 | ||
2524 | insLine(a->cursor.y); | 2524 | insLine(a->cursor.y); |
2525 | 2525 | ||
2526 | a->action = KateAction::killLine; | 2526 | a->action = KateAction::killLine; |
2527 | } | 2527 | } |
2528 | 2528 | ||
2529 | void KateDocument::doKillLine(KateAction *a) { | 2529 | void KateDocument::doKillLine(KateAction *a) { |
2530 | TextLine::Ptr textLine = getTextLine(a->cursor.y); | 2530 | TextLine::Ptr textLine = getTextLine(a->cursor.y); |
2531 | if (longestLine == textLine) longestLine = 0L; | 2531 | if (longestLine == textLine) longestLine = 0L; |
2532 | 2532 | ||
2533 | buffer->removeLine(a->cursor.y); | 2533 | buffer->removeLine(a->cursor.y); |
2534 | 2534 | ||
2535 | delLine(a->cursor.y); | 2535 | delLine(a->cursor.y); |
2536 | tagLine(a->cursor.y); | 2536 | tagLine(a->cursor.y); |
2537 | 2537 | ||
2538 | a->action = KateAction::insLine; | 2538 | a->action = KateAction::insLine; |
2539 | } | 2539 | } |
2540 | 2540 | ||
2541 | void KateDocument::newUndo() { | 2541 | void KateDocument::newUndo() { |
2542 | KTextEditor::View *view; | 2542 | KTextEditor::View *view; |
2543 | int state; | 2543 | int state; |
2544 | 2544 | ||
2545 | state = 0; | 2545 | state = 0; |
2546 | if (currentUndo > 0) state |= 1; | 2546 | if (currentUndo > 0) state |= 1; |
2547 | if (currentUndo < (int) undoList.count()) state |= 2; | 2547 | if (currentUndo < (int) undoList.count()) state |= 2; |
2548 | undoState = state; | 2548 | undoState = state; |
2549 | for (view = m_views.first(); view != 0L; view = m_views.next() ) { | 2549 | for (view = m_views.first(); view != 0L; view = m_views.next() ) { |
2550 | emit static_cast<KateView *>( view )->newUndo(); | 2550 | emit static_cast<KateView *>( view )->newUndo(); |
2551 | } | 2551 | } |
2552 | } | 2552 | } |
2553 | 2553 | ||
2554 | void KateDocument::recordStart(VConfig &c, int newUndoType) { | 2554 | void KateDocument::recordStart(VConfig &c, int newUndoType) { |
2555 | recordStart(c.view, c.cursor, c.flags, newUndoType); | 2555 | recordStart(c.view, c.cursor, c.flags, newUndoType); |
2556 | } | 2556 | } |
2557 | 2557 | ||
2558 | void KateDocument::recordStart(KateView *, PointStruc &cursor, int flags, | 2558 | void KateDocument::recordStart(KateView *, PointStruc &cursor, int flags, |
2559 | int newUndoType, bool keepModal, bool mergeUndo) { | 2559 | int newUndoType, bool keepModal, bool mergeUndo) { |
2560 | 2560 | ||
2561 | KateActionGroup *g; | 2561 | KateActionGroup *g; |
2562 | 2562 | ||
2563 | // if (newUndoType == KateActionGroup::ugNone) { | 2563 | // if (newUndoType == KateActionGroup::ugNone) { |
2564 | // only a bug would cause this | 2564 | // only a bug would cause this |
2565 | //why should someone do this? we can't prevent all programming errors :) (jochen whilhelmy) | 2565 | //why should someone do this? we can't prevent all programming errors :) (jochen whilhelmy) |
2566 | // debug("KateDocument::recordStart() called with no undo group type!"); | 2566 | // debug("KateDocument::recordStart() called with no undo group type!"); |
2567 | // return; | 2567 | // return; |
2568 | // } | 2568 | // } |
2569 | 2569 | ||
2570 | if (!keepModal) setPseudoModal(0L); | 2570 | if (!keepModal) setPseudoModal(0L); |
2571 | 2571 | ||
2572 | //i optimized the group undo stuff a bit (jochen wilhelmy) | 2572 | //i optimized the group undo stuff a bit (jochen wilhelmy) |
2573 | // recordReset() is not needed any more | 2573 | // recordReset() is not needed any more |
2574 | g = undoList.getLast(); | 2574 | g = undoList.getLast(); |
2575 | if (g != 0L && ((undoCount < 1024 && flags & KateView::cfGroupUndo | 2575 | if (g != 0L && ((undoCount < 1024 && flags & KateView::cfGroupUndo |
2576 | && g->end.x == cursor.x && g->end.y == cursor.y) || mergeUndo)) { | 2576 | && g->end.x == cursor.x && g->end.y == cursor.y) || mergeUndo)) { |
2577 | 2577 | ||
2578 | //undo grouping : same actions are put into one undo step | 2578 | //undo grouping : same actions are put into one undo step |
2579 | //precondition : new action starts where old stops or mergeUndo flag | 2579 | //precondition : new action starts where old stops or mergeUndo flag |
2580 | if (g->undoType == newUndoType | 2580 | if (g->undoType == newUndoType |
2581 | || (g->undoType == KateActionGroup::ugInsChar | 2581 | || (g->undoType == KateActionGroup::ugInsChar |
2582 | && newUndoType == KateActionGroup::ugInsLine) | 2582 | && newUndoType == KateActionGroup::ugInsLine) |
2583 | || (g->undoType == KateActionGroup::ugDelChar | 2583 | || (g->undoType == KateActionGroup::ugDelChar |
2584 | && newUndoType == KateActionGroup::ugDelLine)) { | 2584 | && newUndoType == KateActionGroup::ugDelLine)) { |
2585 | 2585 | ||
2586 | undoCount++; | 2586 | undoCount++; |
2587 | if (g->undoType != newUndoType) undoCount = 0xffffff; | 2587 | if (g->undoType != newUndoType) undoCount = 0xffffff; |
2588 | return; | 2588 | return; |
2589 | } | 2589 | } |
2590 | } | 2590 | } |
2591 | undoCount = 0; | 2591 | undoCount = 0; |
2592 | /* | 2592 | /* |
2593 | if (undoView != view) { | 2593 | if (undoView != view) { |
2594 | // always kill the current undo group if the editing view changes | 2594 | // always kill the current undo group if the editing view changes |
2595 | recordReset(); | 2595 | recordReset(); |
2596 | undoType = newUndoType; | 2596 | undoType = newUndoType; |
2597 | } else if (newUndoType == undoType) { | 2597 | } else if (newUndoType == undoType) { |
2598 | printf("bla!!!\n"); | 2598 | printf("bla!!!\n"); |
2599 | // same as current type, keep using it | 2599 | // same as current type, keep using it |
2600 | return; | 2600 | return; |
2601 | } else if ( (undoType == KateActionGroup::ugInsChar && newUndoType == KateActionGroup::ugInsLine) || | 2601 | } else if ( (undoType == KateActionGroup::ugInsChar && newUndoType == KateActionGroup::ugInsLine) || |
2602 | (undoType == KateActionGroup::ugDelChar && newUndoType == KateActionGroup::ugDelLine) ) { | 2602 | (undoType == KateActionGroup::ugDelChar && newUndoType == KateActionGroup::ugDelLine) ) { |
2603 | // some type combinations can run together... | 2603 | // some type combinations can run together... |
2604 | undoType += 1000; | 2604 | undoType += 1000; |
2605 | return; | 2605 | return; |
2606 | } else { | 2606 | } else { |
2607 | recordReset(); | 2607 | recordReset(); |
2608 | undoType = newUndoType; | 2608 | undoType = newUndoType; |
2609 | } | 2609 | } |
2610 | 2610 | ||
2611 | undoView = view; | 2611 | undoView = view; |
2612 | */ | 2612 | */ |
2613 | while ((int) undoList.count() > currentUndo) undoList.removeLast(); | 2613 | while ((int) undoList.count() > currentUndo) undoList.removeLast(); |
2614 | while ((int) undoList.count() > undoSteps) { | 2614 | while ((int) undoList.count() > undoSteps) { |
2615 | undoList.removeFirst(); | 2615 | undoList.removeFirst(); |
2616 | currentUndo--; | 2616 | currentUndo--; |
2617 | } | 2617 | } |
2618 | 2618 | ||
2619 | g = new KateActionGroup(cursor, newUndoType); | 2619 | g = new KateActionGroup(cursor, newUndoType); |
2620 | undoList.append(g); | 2620 | undoList.append(g); |
2621 | // currentUndo++; | 2621 | // currentUndo++; |
2622 | 2622 | ||
2623 | tagEnd = 0; | 2623 | tagEnd = 0; |
2624 | tagStart = 0xffffff; | 2624 | tagStart = 0xffffff; |
2625 | } | 2625 | } |
2626 | 2626 | ||
2627 | void KateDocument::recordAction(KateAction::Action action, PointStruc &cursor) { | 2627 | void KateDocument::recordAction(KateAction::Action action, PointStruc &cursor) { |
2628 | KateAction *a; | 2628 | KateAction *a; |
2629 | 2629 | ||
2630 | a = new KateAction(action, cursor); | 2630 | a = new KateAction(action, cursor); |
2631 | doAction(a); | 2631 | doAction(a); |
2632 | undoList.getLast()->insertAction(a); | 2632 | undoList.getLast()->insertAction(a); |
2633 | } | 2633 | } |
2634 | 2634 | ||
2635 | void KateDocument::recordInsert(VConfig &c, const QString &text) { | 2635 | void KateDocument::recordInsert(VConfig &c, const QString &text) { |
2636 | recordReplace(c, 0, text); | 2636 | recordReplace(c, 0, text); |
2637 | } | 2637 | } |
2638 | 2638 | ||
2639 | void KateDocument::recordReplace(VConfig &c, int len, const QString &text) { | 2639 | void KateDocument::recordReplace(VConfig &c, int len, const QString &text) { |
2640 | if (c.cursor.x > 0 && !(c.flags & KateView::cfSpaceIndent)) { | 2640 | if (c.cursor.x > 0 && !(c.flags & KateView::cfSpaceIndent)) { |
2641 | TextLine::Ptr textLine = getTextLine(c.cursor.y); | 2641 | TextLine::Ptr textLine = getTextLine(c.cursor.y); |
2642 | if (textLine->length() == 0) { | 2642 | if (textLine->length() == 0) { |
2643 | QString s = tabString(c.cursor.x, tabChars); | 2643 | QString s = tabString(c.cursor.x, tabChars); |
2644 | int len = s.length(); | 2644 | int len = s.length(); |
2645 | s += text; | 2645 | s += text; |
2646 | c.cursor.x = 0; | 2646 | c.cursor.x = 0; |
2647 | recordReplace(c.cursor, len, s); | 2647 | recordReplace(c.cursor, len, s); |
2648 | c.cursor.x = len; | 2648 | c.cursor.x = len; |
2649 | return; | 2649 | return; |
2650 | } | 2650 | } |
2651 | } | 2651 | } |
2652 | recordReplace(c.cursor, len, text); | 2652 | recordReplace(c.cursor, len, text); |
2653 | } | 2653 | } |
2654 | 2654 | ||
2655 | void KateDocument::recordInsert(PointStruc &cursor, const QString &text) { | 2655 | void KateDocument::recordInsert(PointStruc &cursor, const QString &text) { |
2656 | recordReplace(cursor, 0, text); | 2656 | recordReplace(cursor, 0, text); |
2657 | } | 2657 | } |
2658 | 2658 | ||
2659 | void KateDocument::recordDelete(PointStruc &cursor, int len) { | 2659 | void KateDocument::recordDelete(PointStruc &cursor, int len) { |
2660 | recordReplace(cursor, len, QString::null); | 2660 | recordReplace(cursor, len, QString::null); |
2661 | } | 2661 | } |
2662 | 2662 | ||
2663 | void KateDocument::recordReplace(PointStruc &cursor, int len, const QString &text) { | 2663 | void KateDocument::recordReplace(PointStruc &cursor, int len, const QString &text) { |
2664 | KateAction *a; | 2664 | KateAction *a; |
2665 | TextLine::Ptr textLine; | 2665 | TextLine::Ptr textLine; |
2666 | int l; | 2666 | int l; |
2667 | 2667 | ||
2668 | if (len == 0 && text.isEmpty()) return; | 2668 | if (len == 0 && text.isEmpty()) return; |
2669 | 2669 | ||
2670 | //try to append to last replace action | 2670 | //try to append to last replace action |
2671 | a = undoList.getLast()->action; | 2671 | a = undoList.getLast()->action; |
2672 | if (a == 0L || a->action != KateAction::replace | 2672 | if (a == 0L || a->action != KateAction::replace |
2673 | || a->cursor.x + a->len != cursor.x || a->cursor.y != cursor.y) { | 2673 | || a->cursor.x + a->len != cursor.x || a->cursor.y != cursor.y) { |
2674 | 2674 | ||
2675 | //if (a != 0L) printf("new %d %d\n", a->cursor.x + a->len, cursor.x); | 2675 | //if (a != 0L) printf("new %d %d\n", a->cursor.x + a->len, cursor.x); |
2676 | a = new KateAction(KateAction::replace, cursor); | 2676 | a = new KateAction(KateAction::replace, cursor); |
2677 | undoList.getLast()->insertAction(a); | 2677 | undoList.getLast()->insertAction(a); |
2678 | } | 2678 | } |
2679 | 2679 | ||
2680 | //replace | 2680 | //replace |
2681 | textLine = getTextLine(cursor.y); | 2681 | textLine = getTextLine(cursor.y); |
2682 | l = textLine->length() - cursor.x; | 2682 | l = textLine->length() - cursor.x; |
2683 | if (l > len) l = len; | 2683 | if (l > len) l = len; |
2684 | a->text.insert(a->text.length(), &textLine->getText()[cursor.x], (l < 0) ? 0 : l); | 2684 | a->text.insert(a->text.length(), &textLine->getText()[cursor.x], (l < 0) ? 0 : l); |
2685 | textLine->replace(cursor.x, len, text.unicode(), text.length()); | 2685 | textLine->replace(cursor.x, len, text.unicode(), text.length()); |
2686 | a->len += text.length(); | 2686 | a->len += text.length(); |
2687 | 2687 | ||
2688 | buffer->changeLine(a->cursor.y); | 2688 | buffer->changeLine(a->cursor.y); |
2689 | updateMaxLength(textLine); | 2689 | updateMaxLength(textLine); |
2690 | tagLine(a->cursor.y); | 2690 | tagLine(a->cursor.y); |
2691 | } | 2691 | } |
2692 | 2692 | ||
2693 | void KateDocument::recordEnd(VConfig &c) { | 2693 | void KateDocument::recordEnd(VConfig &c) { |
2694 | recordEnd(c.view, c.cursor, c.flags); | 2694 | recordEnd(c.view, c.cursor, c.flags); |
2695 | } | 2695 | } |
2696 | 2696 | ||
2697 | void KateDocument::recordEnd(KateView *view, PointStruc &cursor, int flags) { | 2697 | void KateDocument::recordEnd(KateView *view, PointStruc &cursor, int flags) { |
2698 | KateActionGroup *g; | 2698 | KateActionGroup *g; |
2699 | 2699 | ||
2700 | // clear selection if option "persistent selections" is off | 2700 | // clear selection if option "persistent selections" is off |
2701 | // if (!(flags & cfPersistent)) deselectAll(); | 2701 | // if (!(flags & cfPersistent)) deselectAll(); |
2702 | 2702 | ||
2703 | g = undoList.getLast(); | 2703 | g = undoList.getLast(); |
2704 | if (g->action == 0L) { | 2704 | if (g->action == 0L) { |
2705 | // no action has been done: remove empty undo record | 2705 | // no action has been done: remove empty undo record |
2706 | undoList.removeLast(); | 2706 | undoList.removeLast(); |
2707 | return; | 2707 | return; |
2708 | } | 2708 | } |
2709 | // store end cursor position for redo | 2709 | // store end cursor position for redo |
2710 | g->end = cursor; | 2710 | g->end = cursor; |
2711 | currentUndo = undoList.count(); | 2711 | currentUndo = undoList.count(); |
2712 | 2712 | ||
2713 | if (tagStart <= tagEnd) { | 2713 | if (tagStart <= tagEnd) { |
2714 | optimizeSelection(); | 2714 | optimizeSelection(); |
2715 | updateLines(tagStart, tagEnd, flags, cursor.y); | 2715 | updateLines(tagStart, tagEnd, flags, cursor.y); |
2716 | setModified(true); | 2716 | setModified(true); |
2717 | } | 2717 | } |
2718 | 2718 | ||
2719 | view->updateCursor(cursor, flags); | 2719 | view->updateCursor(cursor, flags); |
2720 | 2720 | ||
2721 | // newUndo(); | 2721 | // newUndo(); |
2722 | /* | 2722 | /* |
2723 | undoCount++; | 2723 | undoCount++; |
2724 | // we limit the number of individual undo operations for sanity - is 1K reasonable? | 2724 | // we limit the number of individual undo operations for sanity - is 1K reasonable? |
2725 | // this is also where we handle non-group undo preference | 2725 | // this is also where we handle non-group undo preference |
2726 | // if the undo type is singlular, we always finish it now | 2726 | // if the undo type is singlular, we always finish it now |
2727 | if ( undoType == KateActionGroup::ugPaste || | 2727 | if ( undoType == KateActionGroup::ugPaste || |
2728 | undoType == KateActionGroup::ugDelBlock || | 2728 | undoType == KateActionGroup::ugDelBlock || |
2729 | undoType > 1000 || | 2729 | undoType > 1000 || |
2730 | undoCount > 1024 || !(flags & cfGroupUndo) ) { | 2730 | undoCount > 1024 || !(flags & cfGroupUndo) ) { |
2731 | printf("recordend %d %d\n", undoType, undoCount); | 2731 | printf("recordend %d %d\n", undoType, undoCount); |
2732 | recordReset(); | 2732 | recordReset(); |
2733 | } | 2733 | } |
2734 | */ | 2734 | */ |
2735 | 2735 | ||
2736 | // this should keep the flood of signals down a little... | 2736 | // this should keep the flood of signals down a little... |
2737 | if (undoCount == 0) newUndo(); | 2737 | if (undoCount == 0) newUndo(); |
2738 | emit textChanged(); | 2738 | emit textChanged(); |
2739 | } | 2739 | } |
2740 | /* | 2740 | /* |
2741 | void KateDocument::recordReset() | 2741 | void KateDocument::recordReset() |
2742 | { | 2742 | { |
2743 | if (pseudoModal) | 2743 | if (pseudoModal) |
2744 | return; | 2744 | return; |
2745 | 2745 | ||
2746 | // forces the next call of recordStart() to begin a new undo group | 2746 | // forces the next call of recordStart() to begin a new undo group |
2747 | // not used in normal editing, but used by markFound(), etc. | 2747 | // not used in normal editing, but used by markFound(), etc. |
2748 | undoType = KateActionGroup::ugNone; | 2748 | undoType = KateActionGroup::ugNone; |
2749 | undoCount = 0; | 2749 | undoCount = 0; |
2750 | undoView = NULL; | 2750 | undoView = NULL; |
2751 | undoReported = false; | 2751 | undoReported = false; |
2752 | printf("recordreset\n"); | 2752 | printf("recordreset\n"); |
2753 | } | 2753 | } |
2754 | */ | 2754 | */ |
2755 | 2755 | ||
2756 | /* | 2756 | /* |
2757 | void KateDocument::recordDel(PointStruc &cursor, TextLine::Ptr &textLine, int l) { | 2757 | void KateDocument::recordDel(PointStruc &cursor, TextLine::Ptr &textLine, int l) { |
2758 | int len; | 2758 | int len; |
2759 | 2759 | ||
2760 | len = textLine->length() - cursor.x; | 2760 | len = textLine->length() - cursor.x; |
2761 | if (len > l) len = l; | 2761 | if (len > l) len = l; |
2762 | if (len > 0) { | 2762 | if (len > 0) { |
2763 | insertUndo(new KateAction(KateAction::replace,cursor,&textLine->getText()[cursor.x],len)); | 2763 | insertUndo(new KateAction(KateAction::replace,cursor,&textLine->getText()[cursor.x],len)); |
2764 | } | 2764 | } |
2765 | } | 2765 | } |
2766 | */ | 2766 | */ |
2767 | 2767 | ||
2768 | 2768 | ||
2769 | void KateDocument::doActionGroup(KateActionGroup *g, int flags, bool undo) { | 2769 | void KateDocument::doActionGroup(KateActionGroup *g, int flags, bool undo) { |
2770 | KateAction *a, *next; | 2770 | KateAction *a, *next; |
2771 | 2771 | ||
2772 | setPseudoModal(0L); | 2772 | setPseudoModal(0L); |
2773 | if (!(flags & KateView::cfPersistent)) deselectAll(); | 2773 | if (!(flags & KateView::cfPersistent)) deselectAll(); |
2774 | tagEnd = 0; | 2774 | tagEnd = 0; |
2775 | tagStart = 0xffffff; | 2775 | tagStart = 0xffffff; |
2776 | 2776 | ||
2777 | a = g->action; | 2777 | a = g->action; |
2778 | g->action = 0L; | 2778 | g->action = 0L; |
2779 | while (a) { | 2779 | while (a) { |
2780 | doAction(a); | 2780 | doAction(a); |
2781 | next = a->next; | 2781 | next = a->next; |
2782 | g->insertAction(a); | 2782 | g->insertAction(a); |
2783 | a = next; | 2783 | a = next; |
2784 | } | 2784 | } |
2785 | optimizeSelection(); | 2785 | optimizeSelection(); |
2786 | if (tagStart <= tagEnd) updateLines(tagStart, tagEnd, flags); | 2786 | if (tagStart <= tagEnd) updateLines(tagStart, tagEnd, flags); |
2787 | 2787 | ||
2788 | // the undo/redo functions set undo to true, all others should leave it | 2788 | // the undo/redo functions set undo to true, all others should leave it |
2789 | // alone (default) | 2789 | // alone (default) |
2790 | if (!undo) { | 2790 | if (!undo) { |
2791 | setModified(true); | 2791 | setModified(true); |
2792 | newUndo(); | 2792 | newUndo(); |
2793 | } | 2793 | } |
2794 | } | 2794 | } |
2795 | 2795 | ||
2796 | int KateDocument::nextUndoType() | 2796 | int KateDocument::nextUndoType() |
2797 | { | 2797 | { |
2798 | KateActionGroup *g; | 2798 | KateActionGroup *g; |
2799 | 2799 | ||
2800 | if (currentUndo <= 0) return KateActionGroup::ugNone; | 2800 | if (currentUndo <= 0) return KateActionGroup::ugNone; |
2801 | g = undoList.at(currentUndo - 1); | 2801 | g = undoList.at(currentUndo - 1); |
2802 | return g->undoType; | 2802 | return g->undoType; |
2803 | } | 2803 | } |
2804 | 2804 | ||
2805 | int KateDocument::nextRedoType() | 2805 | int KateDocument::nextRedoType() |
2806 | { | 2806 | { |
2807 | KateActionGroup *g; | 2807 | KateActionGroup *g; |
2808 | 2808 | ||
2809 | if (currentUndo >= (int) undoList.count()) return KateActionGroup::ugNone; | 2809 | if (currentUndo >= (int) undoList.count()) return KateActionGroup::ugNone; |
2810 | g = undoList.at(currentUndo); | 2810 | g = undoList.at(currentUndo); |
2811 | // if (!g) return KateActionGroup::ugNone; | 2811 | // if (!g) return KateActionGroup::ugNone; |
2812 | return g->undoType; | 2812 | return g->undoType; |
2813 | } | 2813 | } |
2814 | 2814 | ||
2815 | void KateDocument::undoTypeList(QValueList<int> &lst) | 2815 | void KateDocument::undoTypeList(QValueList<int> &lst) |
2816 | { | 2816 | { |
2817 | lst.clear(); | 2817 | lst.clear(); |
2818 | for (int i = currentUndo-1; i>=0 ;i--) | 2818 | for (int i = currentUndo-1; i>=0 ;i--) |
2819 | lst.append(undoList.at(i)->undoType); | 2819 | lst.append(undoList.at(i)->undoType); |
2820 | } | 2820 | } |
2821 | 2821 | ||
2822 | void KateDocument::redoTypeList(QValueList<int> &lst) | 2822 | void KateDocument::redoTypeList(QValueList<int> &lst) |
2823 | { | 2823 | { |
2824 | lst.clear(); | 2824 | lst.clear(); |
2825 | for (int i = currentUndo+1; i<(int)undoList.count(); i++) | 2825 | for (int i = currentUndo+1; i<(int)undoList.count(); i++) |
2826 | lst.append(undoList.at(i)->undoType); | 2826 | lst.append(undoList.at(i)->undoType); |
2827 | } | 2827 | } |
2828 | 2828 | ||
2829 | void KateDocument::undo(VConfig &c, int count) { | 2829 | void KateDocument::undo(VConfig &c, int count) { |
2830 | KateActionGroup *g = 0L; | 2830 | KateActionGroup *g = 0L; |
2831 | int num; | 2831 | int num; |
2832 | bool needUpdate = false; // don't update the cursor until completely done | 2832 | bool needUpdate = false; // don't update the cursor until completely done |
2833 | 2833 | ||
2834 | if (count <= 0) return; | 2834 | if (count <= 0) return; |
2835 | 2835 | ||
2836 | for (num = 0 ; num < count ; num++) { | 2836 | for (num = 0 ; num < count ; num++) { |
2837 | if (currentUndo <= 0) break; | 2837 | if (currentUndo <= 0) break; |
2838 | currentUndo--; | 2838 | currentUndo--; |
2839 | g = undoList.at(currentUndo); | 2839 | g = undoList.at(currentUndo); |
2840 | doActionGroup(g, c.flags, true); // do not setModified() or newUndo() | 2840 | doActionGroup(g, c.flags, true); // do not setModified() or newUndo() |
2841 | needUpdate = true; | 2841 | needUpdate = true; |
2842 | 2842 | ||
2843 | // if (num == 0) recordReset(); | 2843 | // if (num == 0) recordReset(); |
2844 | } | 2844 | } |
2845 | 2845 | ||
2846 | if (needUpdate) { | 2846 | if (needUpdate) { |
2847 | // since we told doActionGroup() not to do this stuff, we need to do it now | 2847 | // since we told doActionGroup() not to do this stuff, we need to do it now |
2848 | c.view->updateCursor(g->start); | 2848 | c.view->updateCursor(g->start); |
2849 | setModified(true); | 2849 | setModified(true); |
2850 | newUndo(); | 2850 | newUndo(); |
2851 | } | 2851 | } |
2852 | } | 2852 | } |
2853 | 2853 | ||
2854 | void KateDocument::redo(VConfig &c, int count) { | 2854 | void KateDocument::redo(VConfig &c, int count) { |
2855 | KateActionGroup *g = 0L; | 2855 | KateActionGroup *g = 0L; |
2856 | int num; | 2856 | int num; |
2857 | bool needUpdate = false; // don't update the cursor until completely done | 2857 | bool needUpdate = false; // don't update the cursor until completely done |
2858 | 2858 | ||
2859 | if (count <= 0) return; | 2859 | if (count <= 0) return; |
2860 | 2860 | ||
2861 | for (num = 0 ; num < count ; num++) { | 2861 | for (num = 0 ; num < count ; num++) { |
2862 | if (currentUndo+1 > (int)undoList.count()) break; | 2862 | if (currentUndo+1 > (int)undoList.count()) break; |
2863 | g = undoList.at(currentUndo); | 2863 | g = undoList.at(currentUndo); |
2864 | currentUndo++; | 2864 | currentUndo++; |
2865 | doActionGroup(g, c.flags, true); // do not setModified() or newUndo() | 2865 | doActionGroup(g, c.flags, true); // do not setModified() or newUndo() |
2866 | needUpdate = true; | 2866 | needUpdate = true; |
2867 | 2867 | ||
2868 | // if (num == 0) recordReset(); | 2868 | // if (num == 0) recordReset(); |
2869 | } | 2869 | } |
2870 | 2870 | ||
2871 | if (needUpdate) { | 2871 | if (needUpdate) { |
2872 | // since we told doActionGroup() not to do this stuff, we need to do it now | 2872 | // since we told doActionGroup() not to do this stuff, we need to do it now |
2873 | c.view->updateCursor(g->end); | 2873 | c.view->updateCursor(g->end); |
2874 | setModified(true); | 2874 | setModified(true); |
2875 | newUndo(); | 2875 | newUndo(); |
2876 | } | 2876 | } |
2877 | } | 2877 | } |
2878 | 2878 | ||
2879 | void KateDocument::clearRedo() { | 2879 | void KateDocument::clearRedo() { |
2880 | // disable redos | 2880 | // disable redos |
2881 | // this was added as an assist to the spell checker | 2881 | // this was added as an assist to the spell checker |
2882 | bool deleted = false; | 2882 | bool deleted = false; |
2883 | 2883 | ||
2884 | while ((int) undoList.count() > currentUndo) { | 2884 | while ((int) undoList.count() > currentUndo) { |
2885 | deleted = true; | 2885 | deleted = true; |
2886 | undoList.removeLast(); | 2886 | undoList.removeLast(); |
2887 | } | 2887 | } |
2888 | 2888 | ||
2889 | if (deleted) newUndo(); | 2889 | if (deleted) newUndo(); |
2890 | } | 2890 | } |
2891 | 2891 | ||
2892 | void KateDocument::setUndoSteps(int steps) { | 2892 | void KateDocument::setUndoSteps(int steps) { |
2893 | if (steps < 5) steps = 5; | 2893 | if (steps < 5) steps = 5; |
2894 | undoSteps = steps; | 2894 | undoSteps = steps; |
2895 | } | 2895 | } |
2896 | 2896 | ||
2897 | void KateDocument::setPseudoModal(QWidget *w) { | 2897 | void KateDocument::setPseudoModal(QWidget *w) { |
2898 | // QWidget *old = pseudoModal; | 2898 | // QWidget *old = pseudoModal; |
2899 | 2899 | ||
2900 | // (glenebob) | 2900 | // (glenebob) |
2901 | // this is a temporary hack to make the spell checker work a little | 2901 | // this is a temporary hack to make the spell checker work a little |
2902 | // better - as kspell progresses, this sort of thing should become | 2902 | // better - as kspell progresses, this sort of thing should become |
2903 | // obsolete or worked around more cleanly | 2903 | // obsolete or worked around more cleanly |
2904 | // this is relied upon *only* by the spell-check code | 2904 | // this is relied upon *only* by the spell-check code |
2905 | if (pseudoModal && pseudoModal != (QWidget*)1L) | 2905 | if (pseudoModal && pseudoModal != (QWidget*)1L) |
2906 | delete pseudoModal; | 2906 | delete pseudoModal; |
2907 | 2907 | ||
2908 | // pseudoModal = 0L; | 2908 | // pseudoModal = 0L; |
2909 | // if (old || w) recordReset(); | 2909 | // if (old || w) recordReset(); |
2910 | 2910 | ||
2911 | pseudoModal = w; | 2911 | pseudoModal = w; |
2912 | } | 2912 | } |
2913 | 2913 | ||
2914 | 2914 | ||
2915 | void KateDocument::newBracketMark(PointStruc &cursor, BracketMark &bm) | 2915 | void KateDocument::newBracketMark(PointStruc &cursor, BracketMark &bm) |
2916 | { | 2916 | { |
2917 | TextLine::Ptr textLine; | 2917 | TextLine::Ptr textLine; |
2918 | int x, line, count, attr; | 2918 | int x, line, count, attr; |
2919 | QChar bracket, opposite, ch; | 2919 | QChar bracket, opposite, ch; |
2920 | Attribute *a; | 2920 | Attribute *a; |
2921 | 2921 | ||
2922 | bm.eXPos = -1; //mark bracked mark as invalid | 2922 | bm.eXPos = -1; //mark bracked mark as invalid |
2923 | x = cursor.x -1; // -1 to look at left side of cursor | 2923 | x = cursor.x -1; // -1 to look at left side of cursor |
2924 | if (x < 0) return; | 2924 | if (x < 0) return; |
2925 | line = cursor.y; //current line | 2925 | line = cursor.y; //current line |
2926 | count = 0; //bracket counter for nested brackets | 2926 | count = 0; //bracket counter for nested brackets |
2927 | 2927 | ||
2928 | textLine = getTextLine(line); | 2928 | textLine = getTextLine(line); |
2929 | if (!textLine) return; | 2929 | if (!textLine) return; |
2930 | 2930 | ||
2931 | bracket = textLine->getChar(x); | 2931 | bracket = textLine->getChar(x); |
2932 | attr = textLine->getAttr(x); | 2932 | attr = textLine->getAttr(x); |
2933 | 2933 | ||
2934 | if (bracket == '(' || bracket == '[' || bracket == '{') | 2934 | if (bracket == '(' || bracket == '[' || bracket == '{') |
2935 | { | 2935 | { |
2936 | //get opposite bracket | 2936 | //get opposite bracket |
2937 | opposite = ')'; | 2937 | opposite = ')'; |
2938 | if (bracket == '[') opposite = ']'; | 2938 | if (bracket == '[') opposite = ']'; |
2939 | if (bracket == '{') opposite = '}'; | 2939 | if (bracket == '{') opposite = '}'; |
2940 | //get attribute of bracket (opposite bracket must have the same attribute) | 2940 | //get attribute of bracket (opposite bracket must have the same attribute) |
2941 | x++; | 2941 | x++; |
2942 | while (line - cursor.y < 40) { | 2942 | while (line - cursor.y < 40) { |
2943 | //go to next line on end of line | 2943 | //go to next line on end of line |
2944 | while (x >= (int) textLine->length()) { | 2944 | while (x >= (int) textLine->length()) { |
2945 | line++; | 2945 | line++; |
2946 | if (line > lastLine()) return; | 2946 | if (line > lastLine()) return; |
2947 | textLine = getTextLine(line); | 2947 | textLine = getTextLine(line); |
2948 | x = 0; | 2948 | x = 0; |
2949 | } | 2949 | } |
2950 | if (textLine->getAttr(x) == attr) { | 2950 | if (textLine->getAttr(x) == attr) { |
2951 | //try to find opposite bracked | 2951 | //try to find opposite bracked |
2952 | ch = textLine->getChar(x); | 2952 | ch = textLine->getChar(x); |
2953 | if (ch == bracket) count++; //same bracket : increase counter | 2953 | if (ch == bracket) count++; //same bracket : increase counter |
2954 | if (ch == opposite) { | 2954 | if (ch == opposite) { |
2955 | count--; | 2955 | count--; |
2956 | if (count < 0) goto found; | 2956 | if (count < 0) goto found; |
2957 | } | 2957 | } |
2958 | } | 2958 | } |
2959 | x++; | 2959 | x++; |
2960 | } | 2960 | } |
2961 | } | 2961 | } |
2962 | else if (bracket == ')' || bracket == ']' || bracket == '}') | 2962 | else if (bracket == ')' || bracket == ']' || bracket == '}') |
2963 | { | 2963 | { |
2964 | opposite = '('; | 2964 | opposite = '('; |
2965 | if (bracket == ']') opposite = '['; | 2965 | if (bracket == ']') opposite = '['; |
2966 | if (bracket == '}') opposite = '{'; | 2966 | if (bracket == '}') opposite = '{'; |
2967 | x--; | 2967 | x--; |
2968 | while (cursor.y - line < 20) { | 2968 | while (cursor.y - line < 20) { |
2969 | 2969 | ||
2970 | while (x < 0) { | 2970 | while (x < 0) { |
2971 | line--; | 2971 | line--; |
2972 | if (line < 0) return; | 2972 | if (line < 0) return; |
2973 | textLine = getTextLine(line); | 2973 | textLine = getTextLine(line); |
2974 | x = textLine->length() -1; | 2974 | x = textLine->length() -1; |
2975 | } | 2975 | } |
2976 | if (textLine->getAttr(x) == attr) { | 2976 | if (textLine->getAttr(x) == attr) { |
2977 | ch = textLine->getChar(x); | 2977 | ch = textLine->getChar(x); |
2978 | if (ch == bracket) count++; | 2978 | if (ch == bracket) count++; |
2979 | if (ch == opposite) { | 2979 | if (ch == opposite) { |
2980 | count--; | 2980 | count--; |
2981 | if (count < 0) goto found; | 2981 | if (count < 0) goto found; |
2982 | } | 2982 | } |
2983 | } | 2983 | } |
2984 | x--; | 2984 | x--; |
2985 | } | 2985 | } |
2986 | } | 2986 | } |
2987 | return; | 2987 | return; |
2988 | 2988 | ||
2989 | found: | 2989 | found: |
2990 | //cursor position of opposite bracket | 2990 | //cursor position of opposite bracket |
2991 | bm.cursor.x = x; | 2991 | bm.cursor.x = x; |
2992 | bm.cursor.y = line; | 2992 | bm.cursor.y = line; |
2993 | //x position (start and end) of related bracket | 2993 | //x position (start and end) of related bracket |
2994 | bm.sXPos = textWidth(textLine, x); | 2994 | bm.sXPos = textWidth(textLine, x); |
2995 | a = &m_attribs[attr]; | 2995 | a = &m_attribs[attr]; |
2996 | 2996 | ||
2997 | if (a->bold && a->italic) | 2997 | if (a->bold && a->italic) |
2998 | bm.eXPos = bm.sXPos + myFontMetricsBI.width(bracket); | 2998 | bm.eXPos = bm.sXPos + myFontMetricsBI.width(bracket); |
2999 | else if (a->bold) | 2999 | else if (a->bold) |
3000 | bm.eXPos = bm.sXPos + myFontMetricsBold.width(bracket); | 3000 | bm.eXPos = bm.sXPos + myFontMetricsBold.width(bracket); |
3001 | else if (a->italic) | 3001 | else if (a->italic) |
3002 | bm.eXPos = bm.sXPos + myFontMetricsItalic.width(bracket); | 3002 | bm.eXPos = bm.sXPos + myFontMetricsItalic.width(bracket); |
3003 | else | 3003 | else |
3004 | bm.eXPos = bm.sXPos + myFontMetrics.width(bracket); | 3004 | bm.eXPos = bm.sXPos + myFontMetrics.width(bracket); |
3005 | } | 3005 | } |
3006 | 3006 | ||
3007 | void KateDocument::clipboardChanged() { //slot | 3007 | void KateDocument::clipboardChanged() { //slot |
3008 | //#if defined(_WS_X11_) | 3008 | //#if defined(_WS_X11_) |
3009 | if (m_singleSelection) { | 3009 | if (m_singleSelection) { |
3010 | disconnect(QApplication::clipboard(), SIGNAL(dataChanged()), | 3010 | disconnect(QApplication::clipboard(), SIGNAL(dataChanged()), |
3011 | this, SLOT(clipboardChanged())); | 3011 | this, SLOT(clipboardChanged())); |
3012 | deselectAll(); | 3012 | deselectAll(); |
3013 | updateViews(); | 3013 | updateViews(); |
3014 | } | 3014 | } |
3015 | //#endif | 3015 | //#endif |
3016 | } | 3016 | } |
3017 | 3017 | ||
3018 | #if 0 | 3018 | #if 0 |
3019 | void KateDocument::guiActivateEvent( KParts::GUIActivateEvent *ev ) | 3019 | void KateDocument::guiActivateEvent( KParts::GUIActivateEvent *ev ) |
3020 | { | 3020 | { |
3021 | KParts::ReadWritePart::guiActivateEvent( ev ); | 3021 | KParts::ReadWritePart::guiActivateEvent( ev ); |
3022 | if ( ev->activated() ) | 3022 | if ( ev->activated() ) |
3023 | emit selectionChanged(); | 3023 | emit selectionChanged(); |
3024 | } | 3024 | } |
3025 | #endif | 3025 | #endif |
3026 | 3026 | ||
3027 | void KateDocument::setDocName (QString docName) | 3027 | void KateDocument::setDocName (QString docName) |
3028 | { | 3028 | { |
3029 | myDocName = docName; | 3029 | myDocName = docName; |
3030 | emit nameChanged (this); | 3030 | emit nameChanged (this); |
3031 | } | 3031 | } |
3032 | 3032 | ||
3033 | void KateDocument::setDocFile (QString docFile) | 3033 | void KateDocument::setDocFile (QString docFile) |
3034 | { | 3034 | { |
3035 | m_file = docFile; | 3035 | m_file = docFile; |
3036 | emit fileNameChanged (); | 3036 | emit fileNameChanged (); |
3037 | } | 3037 | } |
3038 | 3038 | ||
3039 | void KateDocument::setMTime() | 3039 | void KateDocument::setMTime() |
3040 | { | 3040 | { |
3041 | if (fileInfo && !fileInfo->fileName().isEmpty()) { | 3041 | if (fileInfo && !fileInfo->fileName().isEmpty()) { |
3042 | fileInfo->refresh(); | 3042 | fileInfo->refresh(); |
3043 | mTime = fileInfo->lastModified(); | 3043 | mTime = fileInfo->lastModified(); |
3044 | } | 3044 | } |
3045 | } | 3045 | } |
3046 | 3046 | ||
3047 | void KateDocument::isModOnHD(bool forceReload) | 3047 | void KateDocument::isModOnHD(bool forceReload) |
3048 | { | 3048 | { |
3049 | if (fileInfo && !fileInfo->fileName().isEmpty()) { | 3049 | if (fileInfo && !fileInfo->fileName().isEmpty()) { |
3050 | fileInfo->refresh(); | 3050 | fileInfo->refresh(); |
3051 | if (fileInfo->lastModified() > mTime) { | 3051 | if (fileInfo->lastModified() > mTime) { |
3052 | if ( forceReload || | 3052 | if ( forceReload || |
3053 | (KMessageBox::warningContinueCancel(0, | 3053 | (KMessageBox::warningContinueCancel(0, |
3054 | (i18n("The file %1 has changed on disk.\nDo you want to reload it?\n\nIf you cancel you will lose these changes next time you save this file")).arg(m_url), | 3054 | (i18n("The file %1 has changed on disk.\nDo you want to reload it?\n\nIf you cancel you will lose these changes next time you save this file")).arg(m_url), |
3055 | i18n("File has changed on Disk"), | 3055 | i18n("File has changed on Disk"), |
3056 | i18n("Yes") ) == KMessageBox::Continue) | 3056 | i18n("Yes") ) == KMessageBox::Continue) |
3057 | ) | 3057 | ) |
3058 | reloadFile(); | 3058 | reloadFile(); |
3059 | else | 3059 | else |
3060 | setMTime(); | 3060 | setMTime(); |
3061 | } | 3061 | } |
3062 | } | 3062 | } |
3063 | } | 3063 | } |
3064 | 3064 | ||
3065 | void KateDocument::reloadFile() | 3065 | void KateDocument::reloadFile() |
3066 | { | 3066 | { |
3067 | #warning fixme | 3067 | #warning fixme |
3068 | #if 0 | 3068 | #if 0 |
3069 | if (fileInfo && !fileInfo->fileName().isEmpty()) { | 3069 | if (fileInfo && !fileInfo->fileName().isEmpty()) { |
3070 | KateDocument::openFile(); | 3070 | KateDocument::openFile(); |
3071 | setMTime(); | 3071 | setMTime(); |
3072 | } | 3072 | } |
3073 | #endif | 3073 | #endif |
3074 | } | 3074 | } |
3075 | 3075 | ||
3076 | void KateDocument::slotModChanged() | 3076 | void KateDocument::slotModChanged() |
3077 | { | 3077 | { |
3078 | emit modStateChanged (this); | 3078 | emit modStateChanged (this); |
3079 | } | 3079 | } |
3080 | 3080 | ||
3081 | QList<Kate::Mark> KateDocument::marks () | 3081 | QList<Kate::Mark> KateDocument::marks () |
3082 | { | 3082 | { |
3083 | QList<Kate::Mark> list; | 3083 | QList<Kate::Mark> list; |
3084 | TextLine::Ptr line; | 3084 | TextLine::Ptr line; |
3085 | 3085 | ||
3086 | for (int i=0; i < numLines(); i++) | 3086 | for (int i=0; i < numLines(); i++) |
3087 | { | 3087 | { |
3088 | line = getTextLine(i); | 3088 | line = getTextLine(i); |
3089 | if (line->mark() != 0) | 3089 | if (line->mark() != 0) |
3090 | { | 3090 | { |
3091 | Kate::Mark *mark=new Kate::Mark; | 3091 | Kate::Mark *mark=new Kate::Mark; |
3092 | mark->line = i; | 3092 | mark->line = i; |
3093 | mark->type = line->mark(); | 3093 | mark->type = line->mark(); |
3094 | list.append (mark); | 3094 | list.append (mark); |
3095 | } | 3095 | } |
3096 | } | 3096 | } |
3097 | 3097 | ||
3098 | return list; | 3098 | return list; |
3099 | } | 3099 | } |
3100 | 3100 | ||
3101 | void KateDocument::flush () | 3101 | void KateDocument::flush () |
3102 | { | 3102 | { |
3103 | if (isReadOnly()) | 3103 | if (isReadOnly()) |
3104 | return; | 3104 | return; |
3105 | 3105 | ||
3106 | m_url = QString::null; | 3106 | m_url = QString::null; |
3107 | fileInfo->setFile (QString()); | 3107 | fileInfo->setFile (QString()); |
3108 | setMTime(); | 3108 | setMTime(); |
3109 | 3109 | ||
3110 | clear(); | 3110 | clear(); |
3111 | updateViews(); | 3111 | updateViews(); |
3112 | 3112 | ||
3113 | emit fileNameChanged (); | 3113 | emit fileNameChanged (); |
3114 | } | 3114 | } |
3115 | 3115 | ||
3116 | void KateDocument::open (const QString &name) | 3116 | void KateDocument::open (const QString &name) |
3117 | { | 3117 | { |
3118 | openURL (name); | 3118 | openURL (name); |
3119 | } | 3119 | } |
3120 | 3120 | ||
3121 | void KateDocument::wrapText (uint col) | 3121 | void KateDocument::wrapText (uint col) |
3122 | { | 3122 | { |
3123 | int line = 0; | 3123 | int line = 0; |
3124 | int z = 0; | 3124 | int z = 0; |
3125 | 3125 | ||
3126 | while(true) | 3126 | while(true) |
3127 | { | 3127 | { |
3128 | TextLine::Ptr l = getTextLine(line); | 3128 | TextLine::Ptr l = getTextLine(line); |
3129 | 3129 | ||
3130 | if (l->length() > col) | 3130 | if (l->length() > col) |
3131 | { | 3131 | { |
3132 | TextLine::Ptr tl = new TextLine(); | 3132 | TextLine::Ptr tl = new TextLine(); |
3133 | buffer->insertLine(line+1,tl); | 3133 | buffer->insertLine(line+1,tl); |
3134 | const QChar *text = l->getText(); | 3134 | const QChar *text = l->getText(); |
3135 | 3135 | ||
3136 | for (z=col; z>0; z--) | 3136 | for (z=col; z>0; z--) |
3137 | { | 3137 | { |
3138 | if (z < 1) break; | 3138 | if (z < 1) break; |
3139 | if (text[z].isSpace()) break; | 3139 | if (text[z].isSpace()) break; |
3140 | } | 3140 | } |
3141 | 3141 | ||
3142 | if (z < 1) z=col; | 3142 | if (z < 1) z=col; |
3143 | 3143 | ||
3144 | l->wrap (tl, z); | 3144 | l->wrap (tl, z); |
3145 | } | 3145 | } |
3146 | 3146 | ||
3147 | line++; | 3147 | line++; |
3148 | if (line >= numLines()) break; | 3148 | if (line >= numLines()) break; |
3149 | }; | 3149 | }; |
3150 | 3150 | ||
3151 | newDocGeometry=true; | 3151 | newDocGeometry=true; |
3152 | updateLines(); | 3152 | updateLines(); |
3153 | updateViews(); | 3153 | updateViews(); |
3154 | } | 3154 | } |
3155 | 3155 | ||
3156 | void KateDocument::setWordWrap (bool on) | 3156 | void KateDocument::setWordWrap (bool on) |
3157 | { | 3157 | { |
3158 | if (on != myWordWrap && on) | 3158 | if (on != myWordWrap && on) |
3159 | wrapText (myWordWrapAt); | 3159 | wrapText (myWordWrapAt); |
3160 | 3160 | ||
3161 | myWordWrap = on; | 3161 | myWordWrap = on; |
3162 | } | 3162 | } |
3163 | 3163 | ||
3164 | void KateDocument::setWordWrapAt (uint col) | 3164 | void KateDocument::setWordWrapAt (uint col) |
3165 | { | 3165 | { |
3166 | if (myWordWrapAt != col && myWordWrap) | 3166 | if (myWordWrapAt != col && myWordWrap) |
3167 | wrapText (myWordWrapAt); | 3167 | wrapText (myWordWrapAt); |
3168 | 3168 | ||
3169 | myWordWrapAt = col; | 3169 | myWordWrapAt = col; |
3170 | } | 3170 | } |
3171 | 3171 | ||
3172 | void KateDocument::applyWordWrap () | 3172 | void KateDocument::applyWordWrap () |
3173 | { | 3173 | { |
3174 | wrapText (myWordWrapAt); | 3174 | wrapText (myWordWrapAt); |
3175 | } | 3175 | } |
diff --git a/noncore/comm/keypebble/krfbdecoder.cpp b/noncore/comm/keypebble/krfbdecoder.cpp index 837fcc5..27ae101 100644 --- a/noncore/comm/keypebble/krfbdecoder.cpp +++ b/noncore/comm/keypebble/krfbdecoder.cpp | |||
@@ -1,831 +1,831 @@ | |||
1 | #include "krfbconnection.h" | 1 | #include "krfbconnection.h" |
2 | #include "krfbserverinfo.h" | 2 | #include "krfbserverinfo.h" |
3 | #include "krfbdecoder.h" | 3 | #include "krfbdecoder.h" |
4 | #include "krfbbuffer.h" | 4 | #include "krfbbuffer.h" |
5 | 5 | ||
6 | /* OPIE */ | 6 | /* OPIE */ |
7 | #include <opie2/odebug.h> | 7 | #include <opie2/odebug.h> |
8 | using namespace Opie::Core; | 8 | using namespace Opie::Core; |
9 | 9 | ||
10 | /* QT */ | 10 | /* QT */ |
11 | #include <qpixmap.h> | 11 | #include <qpixmap.h> |
12 | 12 | ||
13 | /* STD */ | 13 | /* STD */ |
14 | #include <assert.h> | 14 | #include <assert.h> |
15 | 15 | ||
16 | // | 16 | // |
17 | // Endian stuff | 17 | // Endian stuff |
18 | // | 18 | // |
19 | //#ifndef OPIE_NO_DEBUG | 19 | //#ifndef OPIE_NO_DEBUG |
20 | const int endianTest = 1; | 20 | const int endianTest = 1; |
21 | //#endif | 21 | //#endif |
22 | 22 | ||
23 | #define Swap16IfLE(s) \ | 23 | #define Swap16IfLE(s) \ |
24 | (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s)) | 24 | (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s)) |
25 | 25 | ||
26 | #define Swap32IfLE(l) \ | 26 | #define Swap32IfLE(l) \ |
27 | (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \ | 27 | (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \ |
28 | (((l) & 0x00ff0000) >> 8) | \ | 28 | (((l) & 0x00ff0000) >> 8) | \ |
29 | (((l) & 0x0000ff00) << 8) | \ | 29 | (((l) & 0x0000ff00) << 8) | \ |
30 | (((l) & 0x000000ff) << 24)) : (l)) | 30 | (((l) & 0x000000ff) << 24)) : (l)) |
31 | 31 | ||
32 | // | 32 | // |
33 | // The lengths of the messages we need to wait for | 33 | // The lengths of the messages we need to wait for |
34 | // | 34 | // |
35 | const int ServerInitLength = 24; | 35 | const int ServerInitLength = 24; |
36 | const int UpdateHeaderLength = 4; | 36 | const int UpdateHeaderLength = 4; |
37 | const int RectHeaderLength = 12; | 37 | const int RectHeaderLength = 12; |
38 | const int RectChunkSize = 4; | 38 | const int RectChunkSize = 4; |
39 | const int CopyRectPosLength = 4; | 39 | const int CopyRectPosLength = 4; |
40 | const int ServerCutLenLength = 7; | 40 | const int ServerCutLenLength = 7; |
41 | 41 | ||
42 | // | 42 | // |
43 | // Client -> Server Message Identifiers | 43 | // Client -> Server Message Identifiers |
44 | // | 44 | // |
45 | static CARD8 SetPixelFormatId = 0; | 45 | static CARD8 SetPixelFormatId = 0; |
46 | //static CARD8 FixColourMapEntriesId = 1; // Not used | 46 | //static CARD8 FixColourMapEntriesId = 1; // Not used |
47 | static CARD8 SetEncodingsId = 2; | 47 | static CARD8 SetEncodingsId = 2; |
48 | static CARD8 UpdateRequestId = 3; | 48 | static CARD8 UpdateRequestId = 3; |
49 | static CARD8 KeyEventId = 4; | 49 | static CARD8 KeyEventId = 4; |
50 | static CARD8 PointerEventId = 5; | 50 | static CARD8 PointerEventId = 5; |
51 | static CARD8 ClientCutTextId = 6; | 51 | static CARD8 ClientCutTextId = 6; |
52 | 52 | ||
53 | // | 53 | // |
54 | // Server -> Client Message Identifiers | 54 | // Server -> Client Message Identifiers |
55 | // | 55 | // |
56 | static CARD8 UpdateId = 0; | 56 | static CARD8 UpdateId = 0; |
57 | static CARD8 BellId = 2; | 57 | static CARD8 BellId = 2; |
58 | static CARD8 ServerCutId = 3; | 58 | static CARD8 ServerCutId = 3; |
59 | 59 | ||
60 | // | 60 | // |
61 | // Encoding identifiers | 61 | // Encoding identifiers |
62 | // | 62 | // |
63 | static CARD32 RawEncoding = Swap32IfLE( 0 ); | 63 | static CARD32 RawEncoding = Swap32IfLE( 0 ); |
64 | static CARD32 CopyRectEncoding = Swap32IfLE(1 ); | 64 | static CARD32 CopyRectEncoding = Swap32IfLE(1 ); |
65 | static CARD32 RreEncoding = Swap32IfLE( 2 ); | 65 | static CARD32 RreEncoding = Swap32IfLE( 2 ); |
66 | static CARD32 CorreEncoding = Swap32IfLE( 4 ); | 66 | static CARD32 CorreEncoding = Swap32IfLE( 4 ); |
67 | static CARD32 HexTileEncoding = Swap32IfLE( 5 ); | 67 | static CARD32 HexTileEncoding = Swap32IfLE( 5 ); |
68 | 68 | ||
69 | static struct { | 69 | static struct { |
70 | int keysym; | 70 | int keysym; |
71 | int keycode; | 71 | int keycode; |
72 | } keyMap[] = { | 72 | } keyMap[] = { |
73 | { 0xff08, Qt::Key_Backspace }, | 73 | { 0xff08, Qt::Key_Backspace }, |
74 | { 0xff09, Qt::Key_Tab }, | 74 | { 0xff09, Qt::Key_Tab }, |
75 | { 0xff0d, Qt::Key_Return }, | 75 | { 0xff0d, Qt::Key_Return }, |
76 | { 0xff1b, Qt::Key_Escape }, | 76 | { 0xff1b, Qt::Key_Escape }, |
77 | { 0xff63, Qt::Key_Insert }, | 77 | { 0xff63, Qt::Key_Insert }, |
78 | { 0xffff, Qt::Key_Delete }, | 78 | { 0xffff, Qt::Key_Delete }, |
79 | { 0xff50, Qt::Key_Home }, | 79 | { 0xff50, Qt::Key_Home }, |
80 | { 0xff57, Qt::Key_End }, | 80 | { 0xff57, Qt::Key_End }, |
81 | { 0xff55, Qt::Key_Prior }, | 81 | { 0xff55, Qt::Key_Prior }, |
82 | { 0xff56, Qt::Key_Next }, | 82 | { 0xff56, Qt::Key_Next }, |
83 | { 0xff51, Qt::Key_Left }, | 83 | { 0xff51, Qt::Key_Left }, |
84 | { 0xff52, Qt::Key_Up }, | 84 | { 0xff52, Qt::Key_Up }, |
85 | { 0xff53, Qt::Key_Right }, | 85 | { 0xff53, Qt::Key_Right }, |
86 | { 0xff54, Qt::Key_Down }, | 86 | { 0xff54, Qt::Key_Down }, |
87 | { 0xffbe, Qt::Key_F1 }, | 87 | { 0xffbe, Qt::Key_F1 }, |
88 | { 0xffbf, Qt::Key_F2 }, | 88 | { 0xffbf, Qt::Key_F2 }, |
89 | { 0xffc0, Qt::Key_F3 }, | 89 | { 0xffc0, Qt::Key_F3 }, |
90 | { 0xffc1, Qt::Key_F4 }, | 90 | { 0xffc1, Qt::Key_F4 }, |
91 | { 0xffc2, Qt::Key_F5 }, | 91 | { 0xffc2, Qt::Key_F5 }, |
92 | { 0xffc3, Qt::Key_F6 }, | 92 | { 0xffc3, Qt::Key_F6 }, |
93 | { 0xffc4, Qt::Key_F7 }, | 93 | { 0xffc4, Qt::Key_F7 }, |
94 | { 0xffc5, Qt::Key_F8 }, | 94 | { 0xffc5, Qt::Key_F8 }, |
95 | { 0xffc6, Qt::Key_F9 }, | 95 | { 0xffc6, Qt::Key_F9 }, |
96 | { 0xffc7, Qt::Key_F10 }, | 96 | { 0xffc7, Qt::Key_F10 }, |
97 | { 0xffc8, Qt::Key_F11 }, | 97 | { 0xffc8, Qt::Key_F11 }, |
98 | { 0xffc9, Qt::Key_F12 }, | 98 | { 0xffc9, Qt::Key_F12 }, |
99 | { 0xffe1, Qt::Key_Shift }, | 99 | { 0xffe1, Qt::Key_Shift }, |
100 | { 0xffe2, Qt::Key_Shift }, | 100 | { 0xffe2, Qt::Key_Shift }, |
101 | { 0xffe3, Qt::Key_Control }, | 101 | { 0xffe3, Qt::Key_Control }, |
102 | { 0xffe4, Qt::Key_Control }, | 102 | { 0xffe4, Qt::Key_Control }, |
103 | { 0xffe7, Qt::Key_Meta }, | 103 | { 0xffe7, Qt::Key_Meta }, |
104 | { 0xffe8, Qt::Key_Meta }, | 104 | { 0xffe8, Qt::Key_Meta }, |
105 | { 0xffe9, Qt::Key_Alt }, | 105 | { 0xffe9, Qt::Key_Alt }, |
106 | { 0xffea, Qt::Key_Alt }, | 106 | { 0xffea, Qt::Key_Alt }, |
107 | { 0, 0 } | 107 | { 0, 0 } |
108 | }; | 108 | }; |
109 | 109 | ||
110 | 110 | ||
111 | KRFBDecoder::KRFBDecoder( KRFBConnection *con ) | 111 | KRFBDecoder::KRFBDecoder( KRFBConnection *con ) |
112 | : QObject( con, "RFB Decoder" ) | 112 | : QObject( con, "RFB Decoder" ) |
113 | { | 113 | { |
114 | assert( con ); | 114 | assert( con ); |
115 | assert( con->state() == KRFBConnection::Connected ); | 115 | assert( con->state() == KRFBConnection::Connected ); |
116 | 116 | ||
117 | this->con = con; | 117 | this->con = con; |
118 | this->buf = 0; | 118 | this->buf = 0; |
119 | this->info = 0; | 119 | this->info = 0; |
120 | this->format = 0; | 120 | this->format = 0; |
121 | this->buttonMask = 0; | 121 | this->buttonMask = 0; |
122 | currentState = Idle; | 122 | currentState = Idle; |
123 | } | 123 | } |
124 | 124 | ||
125 | KRFBDecoder::~KRFBDecoder() | 125 | KRFBDecoder::~KRFBDecoder() |
126 | { | 126 | { |
127 | if ( info ) | 127 | if ( info ) |
128 | delete info; | 128 | delete info; |
129 | if ( format ) | 129 | if ( format ) |
130 | delete format; | 130 | delete format; |
131 | } | 131 | } |
132 | 132 | ||
133 | void KRFBDecoder::start() | 133 | void KRFBDecoder::start() |
134 | { | 134 | { |
135 | sendClientInit(); | 135 | sendClientInit(); |
136 | } | 136 | } |
137 | 137 | ||
138 | void KRFBDecoder::sendClientInit() | 138 | void KRFBDecoder::sendClientInit() |
139 | { | 139 | { |
140 | con->write( &( con->options()->shared ), 1 ); | 140 | con->write( &( con->options()->shared ), 1 ); |
141 | 141 | ||
142 | // Wait for server init | 142 | // Wait for server init |
143 | owarn << "Waiting for server init" << oendl; | 143 | owarn << "Waiting for server init" << oendl; |
144 | 144 | ||
145 | static QString statusMsg = tr( "Waiting for server initialization..." ); | 145 | static QString statusMsg = tr( "Waiting for server initialization..." ); |
146 | emit status( statusMsg ); | 146 | emit status( statusMsg ); |
147 | 147 | ||
148 | currentState = AwaitingServerInit; | 148 | currentState = AwaitingServerInit; |
149 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerInit() ) ); | 149 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerInit() ) ); |
150 | con->waitForData( ServerInitLength ); | 150 | con->waitForData( ServerInitLength ); |
151 | } | 151 | } |
152 | 152 | ||
153 | void KRFBDecoder::gotServerInit() | 153 | void KRFBDecoder::gotServerInit() |
154 | { | 154 | { |
155 | owarn << "Got server init" << oendl; | 155 | owarn << "Got server init" << oendl; |
156 | disconnect( con, SIGNAL( gotEnoughData() ), this, SLOT( gotServerInit() ) ); | 156 | disconnect( con, SIGNAL( gotEnoughData() ), this, SLOT( gotServerInit() ) ); |
157 | 157 | ||
158 | if ( info ) | 158 | if ( info ) |
159 | delete info; | 159 | delete info; |
160 | info = new KRFBServerInfo; | 160 | info = new KRFBServerInfo; |
161 | CHECK_PTR( info ); | 161 | CHECK_PTR( info ); |
162 | 162 | ||
163 | con->read( &(info->width), 2 ); | 163 | con->read( &(info->width), 2 ); |
164 | info->width = Swap16IfLE( info->width ); | 164 | info->width = Swap16IfLE( info->width ); |
165 | con->read( &info->height, 2 ); | 165 | con->read( &info->height, 2 ); |
166 | info->height = Swap16IfLE( info->height ); | 166 | info->height = Swap16IfLE( info->height ); |
167 | 167 | ||
168 | con->read( &(info->bpp), 1 ); | 168 | con->read( &(info->bpp), 1 ); |
169 | con->read( &(info->depth), 1 ); | 169 | con->read( &(info->depth), 1 ); |
170 | con->read( &(info->bigEndian), 1 ); | 170 | con->read( &(info->bigEndian), 1 ); |
171 | con->read( &(info->trueColor), 1 ); | 171 | con->read( &(info->trueColor), 1 ); |
172 | 172 | ||
173 | con->read( &(info->redMax), 2 ); | 173 | con->read( &(info->redMax), 2 ); |
174 | info->redMax = Swap16IfLE( info->redMax ); | 174 | info->redMax = Swap16IfLE( info->redMax ); |
175 | con->read( &(info->greenMax), 2 ); | 175 | con->read( &(info->greenMax), 2 ); |
176 | info->greenMax = Swap16IfLE( info->greenMax ); | 176 | info->greenMax = Swap16IfLE( info->greenMax ); |
177 | con->read( &(info->blueMax), 2 ); | 177 | con->read( &(info->blueMax), 2 ); |
178 | info->blueMax = Swap16IfLE( info->blueMax ); | 178 | info->blueMax = Swap16IfLE( info->blueMax ); |
179 | 179 | ||
180 | con->read( &(info->redShift), 1 ); | 180 | con->read( &(info->redShift), 1 ); |
181 | con->read( &(info->greenShift), 1 ); | 181 | con->read( &(info->greenShift), 1 ); |
182 | con->read( &(info->blueShift), 1 ); | 182 | con->read( &(info->blueShift), 1 ); |
183 | 183 | ||
184 | con->read( info->padding, 3 ); | 184 | con->read( info->padding, 3 ); |
185 | 185 | ||
186 | con->read( &(info->nameLength), 4 ); | 186 | con->read( &(info->nameLength), 4 ); |
187 | info->nameLength = Swap32IfLE( info->nameLength ); | 187 | info->nameLength = Swap32IfLE( info->nameLength ); |
188 | 188 | ||
189 | owarn << "Width = " << info->width << ", Height = " << info->height << "" << oendl; | 189 | owarn << "Width = " << info->width << ", Height = " << info->height << "" << oendl; |
190 | owarn << "Bpp = " << info->bpp << ", Depth = " << info->depth << ", Big = " << info->bigEndian | 190 | owarn << "Bpp = " << info->bpp << ", Depth = " << info->depth << ", Big = " << info->bigEndian |
191 | << ", True = " << info->trueColor << oendl; | 191 | << ", True = " << info->trueColor << oendl; |
192 | owarn << "RedMax = " << info->redMax << ", GreenMax = " << info->greenMax << ", BlueMax = " << info->blueMax << oendl; | 192 | owarn << "RedMax = " << info->redMax << ", GreenMax = " << info->greenMax << ", BlueMax = " << info->blueMax << oendl; |
193 | owarn << "RedShift = " << info->redShift << ", GreenShift = " << info->greenShift | 193 | owarn << "RedShift = " << info->redShift << ", GreenShift = " << info->greenShift |
194 | << ", BlueShift = " << info-> blueShift << oendl; | 194 | << ", BlueShift = " << info-> blueShift << oendl; |
195 | 195 | ||
196 | buf->resize( info->width/con->options()->scaleFactor, info->height /con->options()->scaleFactor); | 196 | buf->resize( info->width/con->options()->scaleFactor, info->height /con->options()->scaleFactor); |
197 | 197 | ||
198 | // Wait for desktop name | 198 | // Wait for desktop name |
199 | owarn << "Waiting for desktop name" << oendl; | 199 | owarn << "Waiting for desktop name" << oendl; |
200 | 200 | ||
201 | static QString statusMsg = tr( "Waiting for desktop name..." ); | 201 | static QString statusMsg = tr( "Waiting for desktop name..." ); |
202 | emit status( statusMsg ); | 202 | emit status( statusMsg ); |
203 | 203 | ||
204 | currentState = AwaitingDesktopName; | 204 | currentState = AwaitingDesktopName; |
205 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotDesktopName() ) ); | 205 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotDesktopName() ) ); |
206 | con->waitForData( info->nameLength ); | 206 | con->waitForData( info->nameLength ); |
207 | } | 207 | } |
208 | 208 | ||
209 | void KRFBDecoder::gotDesktopName() | 209 | void KRFBDecoder::gotDesktopName() |
210 | { | 210 | { |
211 | assert( info ); | 211 | assert( info ); |
212 | assert( currentState == AwaitingDesktopName ); | 212 | assert( currentState == AwaitingDesktopName ); |
213 | 213 | ||
214 | owarn << "Got desktop name" << oendl; | 214 | owarn << "Got desktop name" << oendl; |
215 | 215 | ||
216 | disconnect( con, SIGNAL( gotEnoughData() ), | 216 | disconnect( con, SIGNAL( gotEnoughData() ), |
217 | this, SLOT( gotDesktopName() ) ); | 217 | this, SLOT( gotDesktopName() ) ); |
218 | 218 | ||
219 | char *buf = new char[ info->nameLength + 1 ]; | 219 | char *buf = new char[ info->nameLength + 1 ]; |
220 | CHECK_PTR( buf ); | 220 | CHECK_PTR( buf ); |
221 | 221 | ||
222 | con->read( buf, info->nameLength ); | 222 | con->read( buf, info->nameLength ); |
223 | buf[ info->nameLength ] = '\0'; | 223 | buf[ info->nameLength ] = '\0'; |
224 | info->name = buf; | 224 | info->name = buf; |
225 | 225 | ||
226 | owarn << "Desktop: " << info->name.latin1() << "" << oendl; | 226 | owarn << "Desktop: " << info->name.latin1() << "" << oendl; |
227 | 227 | ||
228 | delete buf; | 228 | delete [] buf; |
229 | 229 | ||
230 | // Get the format we'll really use and tell the server | 230 | // Get the format we'll really use and tell the server |
231 | decidePixelFormat(); | 231 | decidePixelFormat(); |
232 | sendPixelFormat(); | 232 | sendPixelFormat(); |
233 | sendAllowedEncodings(); | 233 | sendAllowedEncodings(); |
234 | currentState = Idle; | 234 | currentState = Idle; |
235 | 235 | ||
236 | QString msg; | 236 | QString msg; |
237 | msg = tr( "Connected to %1" ); | 237 | msg = tr( "Connected to %1" ); |
238 | msg = msg.arg( info->name ); | 238 | msg = msg.arg( info->name ); |
239 | emit status( msg ); | 239 | emit status( msg ); |
240 | 240 | ||
241 | sendUpdateRequest( false ); | 241 | sendUpdateRequest( false ); |
242 | } | 242 | } |
243 | 243 | ||
244 | void KRFBDecoder::decidePixelFormat() | 244 | void KRFBDecoder::decidePixelFormat() |
245 | { | 245 | { |
246 | assert( info ); | 246 | assert( info ); |
247 | 247 | ||
248 | if ( format ) | 248 | if ( format ) |
249 | delete format; | 249 | delete format; |
250 | format = new KRFBPixelFormat; | 250 | format = new KRFBPixelFormat; |
251 | CHECK_PTR( format ); | 251 | CHECK_PTR( format ); |
252 | 252 | ||
253 | // What depth do we want? | 253 | // What depth do we want? |
254 | // | 254 | // |
255 | // We'll use the minimum of the remote and local depths, UNLESS an | 255 | // We'll use the minimum of the remote and local depths, UNLESS an |
256 | // eight bit session has been specifically requested by the user. | 256 | // eight bit session has been specifically requested by the user. |
257 | int screenDepth = QPixmap::defaultDepth(); | 257 | int screenDepth = QPixmap::defaultDepth(); |
258 | int bestDepth = ( screenDepth > info->depth ) ? info->depth : screenDepth; | 258 | int bestDepth = ( screenDepth > info->depth ) ? info->depth : screenDepth; |
259 | int chosenDepth; | 259 | int chosenDepth; |
260 | 260 | ||
261 | if ( con->options()->colors256 ) | 261 | if ( con->options()->colors256 ) |
262 | chosenDepth = 8; | 262 | chosenDepth = 8; |
263 | else | 263 | else |
264 | chosenDepth = bestDepth; | 264 | chosenDepth = bestDepth; |
265 | 265 | ||
266 | owarn << "Screen depth=" << screenDepth << ", server depth=" << info->depth | 266 | owarn << "Screen depth=" << screenDepth << ", server depth=" << info->depth |
267 | << ", best depth=" << bestDepth << "eight bit " << con->options()->colors256 | 267 | << ", best depth=" << bestDepth << "eight bit " << con->options()->colors256 |
268 | << ", chosenDepth=" << chosenDepth << oendl; | 268 | << ", chosenDepth=" << chosenDepth << oendl; |
269 | 269 | ||
270 | format->depth = chosenDepth; | 270 | format->depth = chosenDepth; |
271 | 271 | ||
272 | // If we're using the servers native depth | 272 | // If we're using the servers native depth |
273 | if ( chosenDepth == info->depth ) { | 273 | if ( chosenDepth == info->depth ) { |
274 | // Use the servers native format | 274 | // Use the servers native format |
275 | format->bpp = info->bpp; | 275 | format->bpp = info->bpp; |
276 | // format->bigEndian = info->bigEndian; | 276 | // format->bigEndian = info->bigEndian; |
277 | format->bigEndian = true; | 277 | format->bigEndian = true; |
278 | format->trueColor = info->trueColor; | 278 | format->trueColor = info->trueColor; |
279 | format->redMax = info->redMax; | 279 | format->redMax = info->redMax; |
280 | format->greenMax = info->greenMax; | 280 | format->greenMax = info->greenMax; |
281 | format->blueMax = info->blueMax; | 281 | format->blueMax = info->blueMax; |
282 | format->redShift = info->redShift; | 282 | format->redShift = info->redShift; |
283 | format->greenShift = info->greenShift; | 283 | format->greenShift = info->greenShift; |
284 | format->blueShift = info->blueShift; | 284 | format->blueShift = info->blueShift; |
285 | } | 285 | } |
286 | else { | 286 | else { |
287 | if ( chosenDepth == 8 ) { | 287 | if ( chosenDepth == 8 ) { |
288 | format->bpp = 8; | 288 | format->bpp = 8; |
289 | format->bigEndian = true; | 289 | format->bigEndian = true; |
290 | format->trueColor = true; | 290 | format->trueColor = true; |
291 | format->redMax = 7; | 291 | format->redMax = 7; |
292 | format->greenMax = 7; | 292 | format->greenMax = 7; |
293 | format->blueMax = 3; | 293 | format->blueMax = 3; |
294 | format->redShift = 0; | 294 | format->redShift = 0; |
295 | format->greenShift = 3; | 295 | format->greenShift = 3; |
296 | format->blueShift = 6; | 296 | format->blueShift = 6; |
297 | } | 297 | } |
298 | } | 298 | } |
299 | 299 | ||
300 | format->redMax = Swap16IfLE( format->redMax ); | 300 | format->redMax = Swap16IfLE( format->redMax ); |
301 | format->greenMax = Swap16IfLE( format->greenMax ); | 301 | format->greenMax = Swap16IfLE( format->greenMax ); |
302 | format->blueMax = Swap16IfLE( format->blueMax ); | 302 | format->blueMax = Swap16IfLE( format->blueMax ); |
303 | } | 303 | } |
304 | 304 | ||
305 | void KRFBDecoder::sendPixelFormat() | 305 | void KRFBDecoder::sendPixelFormat() |
306 | { | 306 | { |
307 | static char padding[3]; | 307 | static char padding[3]; |
308 | con->write( &SetPixelFormatId, 1 ); | 308 | con->write( &SetPixelFormatId, 1 ); |
309 | con->write( padding, 3 ); | 309 | con->write( padding, 3 ); |
310 | 310 | ||
311 | con->write( &(format->bpp), 1 ); | 311 | con->write( &(format->bpp), 1 ); |
312 | con->write( &(format->depth), 1 ); | 312 | con->write( &(format->depth), 1 ); |
313 | con->write( &(format->bigEndian), 1 ); | 313 | con->write( &(format->bigEndian), 1 ); |
314 | con->write( &(format->trueColor), 1 ); | 314 | con->write( &(format->trueColor), 1 ); |
315 | 315 | ||
316 | con->write( &(format->redMax), 2 ); | 316 | con->write( &(format->redMax), 2 ); |
317 | con->write( &(format->greenMax), 2 ); | 317 | con->write( &(format->greenMax), 2 ); |
318 | con->write( &(format->blueMax), 2 ); | 318 | con->write( &(format->blueMax), 2 ); |
319 | 319 | ||
320 | con->write( &(format->redShift), 1 ); | 320 | con->write( &(format->redShift), 1 ); |
321 | con->write( &(format->greenShift), 1 ); | 321 | con->write( &(format->greenShift), 1 ); |
322 | con->write( &(format->blueShift), 1 ); | 322 | con->write( &(format->blueShift), 1 ); |
323 | con->write( format->padding, 3 ); // Padding | 323 | con->write( format->padding, 3 ); // Padding |
324 | } | 324 | } |
325 | 325 | ||
326 | void KRFBDecoder::sendAllowedEncodings() | 326 | void KRFBDecoder::sendAllowedEncodings() |
327 | { | 327 | { |
328 | static CARD8 padding[1]; | 328 | static CARD8 padding[1]; |
329 | con->write( &SetEncodingsId, 1 ); | 329 | con->write( &SetEncodingsId, 1 ); |
330 | con->write( padding, 1 ); | 330 | con->write( padding, 1 ); |
331 | 331 | ||
332 | CARD16 noEncodings = con->options()->encodings(); | 332 | CARD16 noEncodings = con->options()->encodings(); |
333 | noEncodings = Swap16IfLE( noEncodings ); | 333 | noEncodings = Swap16IfLE( noEncodings ); |
334 | con->write( &noEncodings, 2 ); | 334 | con->write( &noEncodings, 2 ); |
335 | 335 | ||
336 | if ( con->options()->corre ) | 336 | if ( con->options()->corre ) |
337 | con->write( &CorreEncoding, 4 ); | 337 | con->write( &CorreEncoding, 4 ); |
338 | if ( con->options()->hexTile ) | 338 | if ( con->options()->hexTile ) |
339 | con->write( &HexTileEncoding, 4 ); | 339 | con->write( &HexTileEncoding, 4 ); |
340 | if ( con->options()->rre ) | 340 | if ( con->options()->rre ) |
341 | con->write( &RreEncoding, 4 ); | 341 | con->write( &RreEncoding, 4 ); |
342 | if ( con->options()->copyrect ) | 342 | if ( con->options()->copyrect ) |
343 | con->write( &CopyRectEncoding, 4 ); | 343 | con->write( &CopyRectEncoding, 4 ); |
344 | // We always support this | 344 | // We always support this |
345 | con->write( &RawEncoding, 4 ); | 345 | con->write( &RawEncoding, 4 ); |
346 | } | 346 | } |
347 | 347 | ||
348 | void KRFBDecoder::sendUpdateRequest( bool incremental ) | 348 | void KRFBDecoder::sendUpdateRequest( bool incremental ) |
349 | { | 349 | { |
350 | if ( currentState != Idle ) | 350 | if ( currentState != Idle ) |
351 | return; | 351 | return; |
352 | 352 | ||
353 | con->write( &UpdateRequestId, 1 ); | 353 | con->write( &UpdateRequestId, 1 ); |
354 | con->write( &incremental, 1 ); | 354 | con->write( &incremental, 1 ); |
355 | 355 | ||
356 | static CARD16 x = 0, y = 0; | 356 | static CARD16 x = 0, y = 0; |
357 | static CARD16 w = Swap16IfLE( info->width ); | 357 | static CARD16 w = Swap16IfLE( info->width ); |
358 | static CARD16 h = Swap16IfLE( info->height ); | 358 | static CARD16 h = Swap16IfLE( info->height ); |
359 | 359 | ||
360 | con->write( &x, 2 ); | 360 | con->write( &x, 2 ); |
361 | con->write( &y, 2 ); | 361 | con->write( &y, 2 ); |
362 | con->write( &w, 2 ); | 362 | con->write( &w, 2 ); |
363 | con->write( &h, 2 ); | 363 | con->write( &h, 2 ); |
364 | 364 | ||
365 | // Now wait for the update | 365 | // Now wait for the update |
366 | currentState = AwaitingUpdate; | 366 | currentState = AwaitingUpdate; |
367 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); | 367 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); |
368 | con->waitForData( UpdateHeaderLength ); | 368 | con->waitForData( UpdateHeaderLength ); |
369 | } | 369 | } |
370 | 370 | ||
371 | void KRFBDecoder::gotUpdateHeader() | 371 | void KRFBDecoder::gotUpdateHeader() |
372 | { | 372 | { |
373 | assert( currentState == AwaitingUpdate ); | 373 | assert( currentState == AwaitingUpdate ); |
374 | 374 | ||
375 | // owarn << "Got update header" << oendl; | 375 | // owarn << "Got update header" << oendl; |
376 | 376 | ||
377 | disconnect( con, SIGNAL( gotEnoughData() ), | 377 | disconnect( con, SIGNAL( gotEnoughData() ), |
378 | this, SLOT( gotUpdateHeader() ) ); | 378 | this, SLOT( gotUpdateHeader() ) ); |
379 | 379 | ||
380 | CARD8 msgType; | 380 | CARD8 msgType; |
381 | con->read( &msgType, 1 ); | 381 | con->read( &msgType, 1 ); |
382 | 382 | ||
383 | if ( msgType != UpdateId ) { | 383 | if ( msgType != UpdateId ) { |
384 | // We might have a bell or server cut | 384 | // We might have a bell or server cut |
385 | if ( msgType == ServerCutId ) { | 385 | if ( msgType == ServerCutId ) { |
386 | oldState = currentState; | 386 | oldState = currentState; |
387 | gotServerCut(); | 387 | gotServerCut(); |
388 | } | 388 | } |
389 | else if ( msgType == BellId ) { | 389 | else if ( msgType == BellId ) { |
390 | oldState = currentState; | 390 | oldState = currentState; |
391 | gotBell(); | 391 | gotBell(); |
392 | } | 392 | } |
393 | else { | 393 | else { |
394 | int msg = msgType; | 394 | int msg = msgType; |
395 | QString protocolError = tr( "Protocol Error: Message Id %1 was " | 395 | QString protocolError = tr( "Protocol Error: Message Id %1 was " |
396 | "found when expecting an update " | 396 | "found when expecting an update " |
397 | "message." ).arg( msg ); | 397 | "message." ).arg( msg ); |
398 | currentState = Error; | 398 | currentState = Error; |
399 | emit error( protocolError ); | 399 | emit error( protocolError ); |
400 | } | 400 | } |
401 | return; | 401 | return; |
402 | } | 402 | } |
403 | 403 | ||
404 | CARD8 padding; | 404 | CARD8 padding; |
405 | con->read( &padding, 1 ); | 405 | con->read( &padding, 1 ); |
406 | 406 | ||
407 | con->read( &noRects, 2 ); | 407 | con->read( &noRects, 2 ); |
408 | noRects = Swap16IfLE( noRects ); | 408 | noRects = Swap16IfLE( noRects ); |
409 | 409 | ||
410 | // owarn << "Expecting " << noRects << " rects" << oendl; | 410 | // owarn << "Expecting " << noRects << " rects" << oendl; |
411 | 411 | ||
412 | // Now wait for the data | 412 | // Now wait for the data |
413 | currentState = AwaitingRectHeader; | 413 | currentState = AwaitingRectHeader; |
414 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); | 414 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); |
415 | con->waitForData( RectHeaderLength ); | 415 | con->waitForData( RectHeaderLength ); |
416 | } | 416 | } |
417 | 417 | ||
418 | void KRFBDecoder::gotRectHeader() | 418 | void KRFBDecoder::gotRectHeader() |
419 | { | 419 | { |
420 | assert( currentState == AwaitingRectHeader ); | 420 | assert( currentState == AwaitingRectHeader ); |
421 | 421 | ||
422 | // owarn << "Got rect header" << oendl; | 422 | // owarn << "Got rect header" << oendl; |
423 | 423 | ||
424 | disconnect( con, SIGNAL( gotEnoughData() ), | 424 | disconnect( con, SIGNAL( gotEnoughData() ), |
425 | this, SLOT( gotRectHeader() ) ); | 425 | this, SLOT( gotRectHeader() ) ); |
426 | 426 | ||
427 | con->read( &x, 2 ); | 427 | con->read( &x, 2 ); |
428 | x = Swap16IfLE( x ); | 428 | x = Swap16IfLE( x ); |
429 | con->read( &y, 2 ); | 429 | con->read( &y, 2 ); |
430 | y = Swap16IfLE( y ); | 430 | y = Swap16IfLE( y ); |
431 | 431 | ||
432 | con->read( &w, 2 ); | 432 | con->read( &w, 2 ); |
433 | w = Swap16IfLE( w ); | 433 | w = Swap16IfLE( w ); |
434 | con->read( &h, 2 ); | 434 | con->read( &h, 2 ); |
435 | h = Swap16IfLE( h ); | 435 | h = Swap16IfLE( h ); |
436 | 436 | ||
437 | con->read( &encoding, 4 ); | 437 | con->read( &encoding, 4 ); |
438 | 438 | ||
439 | // CARD32 encodingLocal = Swap32IfLE( encoding ); | 439 | // CARD32 encodingLocal = Swap32IfLE( encoding ); |
440 | // owarn << "Rect: x=" << x << ", y= " << y << ", w=" << w << ", h=" << h | 440 | // owarn << "Rect: x=" << x << ", y= " << y << ", w=" << w << ", h=" << h |
441 | // << ", encoding= " << encodingLocal << oendl; | 441 | // << ", encoding= " << encodingLocal << oendl; |
442 | 442 | ||
443 | // | 443 | // |
444 | // Each encoding needs to be handled differently. Some require | 444 | // Each encoding needs to be handled differently. Some require |
445 | // waiting for more data, but others like a copyrect do not. | 445 | // waiting for more data, but others like a copyrect do not. |
446 | // Our constants have already been byte swapped, so we use | 446 | // Our constants have already been byte swapped, so we use |
447 | // the remote value as is. | 447 | // the remote value as is. |
448 | // | 448 | // |
449 | if ( encoding == RawEncoding ) { | 449 | if ( encoding == RawEncoding ) { |
450 | // owarn << "Raw encoding" << oendl; | 450 | // owarn << "Raw encoding" << oendl; |
451 | handleRawRect(); | 451 | handleRawRect(); |
452 | } | 452 | } |
453 | else if ( encoding == CopyRectEncoding ) { | 453 | else if ( encoding == CopyRectEncoding ) { |
454 | // owarn << "CopyRect encoding" << oendl; | 454 | // owarn << "CopyRect encoding" << oendl; |
455 | handleCopyRect(); | 455 | handleCopyRect(); |
456 | } | 456 | } |
457 | else if ( encoding == RreEncoding ) { | 457 | else if ( encoding == RreEncoding ) { |
458 | owarn << "RRE encoding" << oendl; | 458 | owarn << "RRE encoding" << oendl; |
459 | handleRRERect(); | 459 | handleRRERect(); |
460 | } | 460 | } |
461 | else if ( encoding == CorreEncoding ) { | 461 | else if ( encoding == CorreEncoding ) { |
462 | owarn << "CoRRE encoding" << oendl; | 462 | owarn << "CoRRE encoding" << oendl; |
463 | handleCoRRERect(); | 463 | handleCoRRERect(); |
464 | } | 464 | } |
465 | else if ( encoding == HexTileEncoding ) { | 465 | else if ( encoding == HexTileEncoding ) { |
466 | owarn << "HexTile encoding" << oendl; | 466 | owarn << "HexTile encoding" << oendl; |
467 | handleHexTileRect(); | 467 | handleHexTileRect(); |
468 | } | 468 | } |
469 | else { | 469 | else { |
470 | int msg = Swap32IfLE( encoding ); | 470 | int msg = Swap32IfLE( encoding ); |
471 | QString protocolError = tr( "Protocol Error: An unknown encoding was " | 471 | QString protocolError = tr( "Protocol Error: An unknown encoding was " |
472 | "used by the server %1" ).arg( msg ); | 472 | "used by the server %1" ).arg( msg ); |
473 | currentState = Error; | 473 | currentState = Error; |
474 | owarn << "Unknown encoding, " << msg << "" << oendl; | 474 | owarn << "Unknown encoding, " << msg << "" << oendl; |
475 | emit error( protocolError ); | 475 | emit error( protocolError ); |
476 | return; | 476 | return; |
477 | } | 477 | } |
478 | } | 478 | } |
479 | 479 | ||
480 | // | 480 | // |
481 | // Raw Encoding | 481 | // Raw Encoding |
482 | // | 482 | // |
483 | 483 | ||
484 | void KRFBDecoder::handleRawRect() | 484 | void KRFBDecoder::handleRawRect() |
485 | { | 485 | { |
486 | // We need something a bit cleverer here to handle large | 486 | // We need something a bit cleverer here to handle large |
487 | // rectanges nicely. The chunking should be based on the | 487 | // rectanges nicely. The chunking should be based on the |
488 | // overall size (but has to be in complete lines). | 488 | // overall size (but has to be in complete lines). |
489 | 489 | ||
490 | // owarn << "Handling a raw rect chunk" << oendl; | 490 | // owarn << "Handling a raw rect chunk" << oendl; |
491 | 491 | ||
492 | // CARD32 lineCount = w * format->bpp / 8; | 492 | // CARD32 lineCount = w * format->bpp / 8; |
493 | 493 | ||
494 | if ( h > RectChunkSize ) { | 494 | if ( h > RectChunkSize ) { |
495 | // if ( con->sock->size() / lineCount ) { | 495 | // if ( con->sock->size() / lineCount ) { |
496 | // getRawRectChunk( con->sock->size() / lineCount ); | 496 | // getRawRectChunk( con->sock->size() / lineCount ); |
497 | // } | 497 | // } |
498 | // else { | 498 | // else { |
499 | getRawRectChunk( RectChunkSize ); | 499 | getRawRectChunk( RectChunkSize ); |
500 | // } | 500 | // } |
501 | } | 501 | } |
502 | else { | 502 | else { |
503 | getRawRectChunk( h ); | 503 | getRawRectChunk( h ); |
504 | } | 504 | } |
505 | } | 505 | } |
506 | 506 | ||
507 | void KRFBDecoder::getRawRectChunk( int lines ) | 507 | void KRFBDecoder::getRawRectChunk( int lines ) |
508 | { | 508 | { |
509 | this->lines = lines; | 509 | this->lines = lines; |
510 | CARD32 count = lines * w * format->bpp / 8; | 510 | CARD32 count = lines * w * format->bpp / 8; |
511 | 511 | ||
512 | // Wait for server init | 512 | // Wait for server init |
513 | // owarn << "Waiting for raw rect chunk, " << count << "" << oendl; | 513 | // owarn << "Waiting for raw rect chunk, " << count << "" << oendl; |
514 | 514 | ||
515 | currentState = AwaitingRawRectChunk; | 515 | currentState = AwaitingRawRectChunk; |
516 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRawRectChunk() ) ); | 516 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRawRectChunk() ) ); |
517 | con->waitForData( count ); | 517 | con->waitForData( count ); |
518 | } | 518 | } |
519 | 519 | ||
520 | void KRFBDecoder::gotRawRectChunk() | 520 | void KRFBDecoder::gotRawRectChunk() |
521 | { | 521 | { |
522 | assert( currentState == AwaitingRawRectChunk ); | 522 | assert( currentState == AwaitingRawRectChunk ); |
523 | 523 | ||
524 | disconnect( con, SIGNAL( gotEnoughData() ), | 524 | disconnect( con, SIGNAL( gotEnoughData() ), |
525 | this, SLOT( gotRawRectChunk() ) ); | 525 | this, SLOT( gotRawRectChunk() ) ); |
526 | 526 | ||
527 | // owarn << "Got raw rect chunk" << oendl; | 527 | // owarn << "Got raw rect chunk" << oendl; |
528 | 528 | ||
529 | // | 529 | // |
530 | // Read the rect data and copy it to the buffer. | 530 | // Read the rect data and copy it to the buffer. |
531 | // | 531 | // |
532 | 532 | ||
533 | // TODO: Replace this! | 533 | // TODO: Replace this! |
534 | int count = lines * w * format->bpp / 8; | 534 | int count = lines * w * format->bpp / 8; |
535 | char *hack = new char[ count ]; | 535 | char *hack = new char[ count ]; |
536 | con->read( hack, count ); | 536 | con->read( hack, count ); |
537 | buf->drawRawRectChunk( hack, x, y, w, lines ); | 537 | buf->drawRawRectChunk( hack, x, y, w, lines ); |
538 | delete hack; | 538 | delete [] hack; |
539 | // /TODO: | 539 | // /TODO: |
540 | 540 | ||
541 | h = h - lines; | 541 | h = h - lines; |
542 | y = y + lines; | 542 | y = y + lines; |
543 | 543 | ||
544 | if ( h > 0 ) { | 544 | if ( h > 0 ) { |
545 | handleRawRect(); | 545 | handleRawRect(); |
546 | } | 546 | } |
547 | else { | 547 | else { |
548 | noRects--; | 548 | noRects--; |
549 | 549 | ||
550 | // owarn << "There are " << noRects << " rects left" << oendl; | 550 | // owarn << "There are " << noRects << " rects left" << oendl; |
551 | 551 | ||
552 | if ( noRects ) { | 552 | if ( noRects ) { |
553 | currentState = AwaitingRectHeader; | 553 | currentState = AwaitingRectHeader; |
554 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); | 554 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); |
555 | con->waitForData( RectHeaderLength ); | 555 | con->waitForData( RectHeaderLength ); |
556 | } | 556 | } |
557 | else { | 557 | else { |
558 | // we are now ready for the next update - no need to wait for the timer | 558 | // we are now ready for the next update - no need to wait for the timer |
559 | currentState = Idle; | 559 | currentState = Idle; |
560 | sendUpdateRequest (1); | 560 | sendUpdateRequest (1); |
561 | } | 561 | } |
562 | } | 562 | } |
563 | } | 563 | } |
564 | 564 | ||
565 | // | 565 | // |
566 | // Copy Rectangle Encoding | 566 | // Copy Rectangle Encoding |
567 | // | 567 | // |
568 | 568 | ||
569 | void KRFBDecoder::handleCopyRect() | 569 | void KRFBDecoder::handleCopyRect() |
570 | { | 570 | { |
571 | currentState = AwaitingCopyRectPos; | 571 | currentState = AwaitingCopyRectPos; |
572 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotCopyRectPos() ) ); | 572 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotCopyRectPos() ) ); |
573 | con->waitForData( CopyRectPosLength ); | 573 | con->waitForData( CopyRectPosLength ); |
574 | } | 574 | } |
575 | 575 | ||
576 | void KRFBDecoder::gotCopyRectPos() | 576 | void KRFBDecoder::gotCopyRectPos() |
577 | { | 577 | { |
578 | disconnect( con, SIGNAL( gotEnoughData() ), | 578 | disconnect( con, SIGNAL( gotEnoughData() ), |
579 | this, SLOT( gotCopyRectPos() ) ); | 579 | this, SLOT( gotCopyRectPos() ) ); |
580 | 580 | ||
581 | CARD16 srcX; | 581 | CARD16 srcX; |
582 | CARD16 srcY; | 582 | CARD16 srcY; |
583 | 583 | ||
584 | con->read( &srcX, 2 ); | 584 | con->read( &srcX, 2 ); |
585 | con->read( &srcY, 2 ); | 585 | con->read( &srcY, 2 ); |
586 | 586 | ||
587 | srcX = Swap16IfLE( srcX ); | 587 | srcX = Swap16IfLE( srcX ); |
588 | srcY = Swap16IfLE( srcY ); | 588 | srcY = Swap16IfLE( srcY ); |
589 | 589 | ||
590 | buf->copyRect( srcX, srcY, x, y, w, h ); | 590 | buf->copyRect( srcX, srcY, x, y, w, h ); |
591 | 591 | ||
592 | noRects--; | 592 | noRects--; |
593 | 593 | ||
594 | // owarn << "There are " << noRects << " rects left" << oendl; | 594 | // owarn << "There are " << noRects << " rects left" << oendl; |
595 | 595 | ||
596 | if ( noRects ) { | 596 | if ( noRects ) { |
597 | currentState = AwaitingRectHeader; | 597 | currentState = AwaitingRectHeader; |
598 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); | 598 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); |
599 | con->waitForData( RectHeaderLength ); | 599 | con->waitForData( RectHeaderLength ); |
600 | } | 600 | } |
601 | else | 601 | else |
602 | currentState = Idle; | 602 | currentState = Idle; |
603 | } | 603 | } |
604 | 604 | ||
605 | void KRFBDecoder::handleRRERect() | 605 | void KRFBDecoder::handleRRERect() |
606 | { | 606 | { |
607 | owarn << "RRE not implemented" << oendl; | 607 | owarn << "RRE not implemented" << oendl; |
608 | } | 608 | } |
609 | 609 | ||
610 | void KRFBDecoder::handleCoRRERect() | 610 | void KRFBDecoder::handleCoRRERect() |
611 | { | 611 | { |
612 | owarn << "CoRRE not implemented" << oendl; | 612 | owarn << "CoRRE not implemented" << oendl; |
613 | } | 613 | } |
614 | 614 | ||
615 | void KRFBDecoder::handleHexTileRect() | 615 | void KRFBDecoder::handleHexTileRect() |
616 | { | 616 | { |
617 | owarn << "HexTile not implemented" << oendl; | 617 | owarn << "HexTile not implemented" << oendl; |
618 | } | 618 | } |
619 | 619 | ||
620 | void KRFBDecoder::sendMouseEvent( QMouseEvent *e ) | 620 | void KRFBDecoder::sendMouseEvent( QMouseEvent *e ) |
621 | { | 621 | { |
622 | // Deal with the buttons | 622 | // Deal with the buttons |
623 | if ( e->type() != QEvent::MouseMove ) { | 623 | if ( e->type() != QEvent::MouseMove ) { |
624 | buttonMask = 0; | 624 | buttonMask = 0; |
625 | if ( e->type() == QEvent::MouseButtonPress ) { | 625 | if ( e->type() == QEvent::MouseButtonPress ) { |
626 | if ( e->button() & LeftButton ) | 626 | if ( e->button() & LeftButton ) |
627 | buttonMask |= 0x01; | 627 | buttonMask |= 0x01; |
628 | if ( e->button() & MidButton ) | 628 | if ( e->button() & MidButton ) |
629 | buttonMask |= 0x04; | 629 | buttonMask |= 0x04; |
630 | if ( e->button() & RightButton ) | 630 | if ( e->button() & RightButton ) |
631 | buttonMask |= 0x02; | 631 | buttonMask |= 0x02; |
632 | } | 632 | } |
633 | else if ( e->type() == QEvent::MouseButtonRelease ) { | 633 | else if ( e->type() == QEvent::MouseButtonRelease ) { |
634 | if ( e->button() & LeftButton ) | 634 | if ( e->button() & LeftButton ) |
635 | buttonMask &= 0x06; | 635 | buttonMask &= 0x06; |
636 | if ( e->button() & MidButton ) | 636 | if ( e->button() & MidButton ) |
637 | buttonMask |= 0x03; | 637 | buttonMask |= 0x03; |
638 | if ( e->button() & RightButton ) | 638 | if ( e->button() & RightButton ) |
639 | buttonMask |= 0x05; | 639 | buttonMask |= 0x05; |
640 | } | 640 | } |
641 | } | 641 | } |
642 | 642 | ||
643 | // HACK: Scaling | 643 | // HACK: Scaling |
644 | CARD16 x = Swap16IfLE( e->x() * con->options()->scaleFactor ); | 644 | CARD16 x = Swap16IfLE( e->x() * con->options()->scaleFactor ); |
645 | CARD16 y = Swap16IfLE( e->y() * con->options()->scaleFactor ); | 645 | CARD16 y = Swap16IfLE( e->y() * con->options()->scaleFactor ); |
646 | 646 | ||
647 | con->write( &PointerEventId, 1 ); | 647 | con->write( &PointerEventId, 1 ); |
648 | con->write( &buttonMask, 1 ); | 648 | con->write( &buttonMask, 1 ); |
649 | con->write( &x, 2 ); | 649 | con->write( &x, 2 ); |
650 | con->write( &y, 2 ); | 650 | con->write( &y, 2 ); |
651 | } | 651 | } |
652 | 652 | ||
653 | 653 | ||
654 | void KRFBDecoder::sendCutEvent( const QString &unicode ) | 654 | void KRFBDecoder::sendCutEvent( const QString &unicode ) |
655 | { | 655 | { |
656 | // | 656 | // |
657 | // Warning: There is a bug in the RFB protocol because there is no way to find | 657 | // Warning: There is a bug in the RFB protocol because there is no way to find |
658 | // out the codepage in use on the remote machine. This could be fixed by requiring | 658 | // out the codepage in use on the remote machine. This could be fixed by requiring |
659 | // the remote server to use utf8 etc. but for now we have to assume they're the | 659 | // the remote server to use utf8 etc. but for now we have to assume they're the |
660 | // same. I've reported this problem to the ORL guys, but they apparantly have no | 660 | // same. I've reported this problem to the ORL guys, but they apparantly have no |
661 | // immediate plans to fix the issue. :-( (rich) | 661 | // immediate plans to fix the issue. :-( (rich) |
662 | // | 662 | // |
663 | 663 | ||
664 | CARD8 padding[3]; | 664 | CARD8 padding[3]; |
665 | QCString text = unicode.local8Bit(); | 665 | QCString text = unicode.local8Bit(); |
666 | CARD32 length = text.length(); | 666 | CARD32 length = text.length(); |
667 | length = Swap32IfLE( length ); | 667 | length = Swap32IfLE( length ); |
668 | 668 | ||
669 | con->write( &ClientCutTextId, 1 ); | 669 | con->write( &ClientCutTextId, 1 ); |
670 | con->write( &padding, 3 ); | 670 | con->write( &padding, 3 ); |
671 | con->write( &length, 4 ); | 671 | con->write( &length, 4 ); |
672 | con->write( text.data(), length ); | 672 | con->write( text.data(), length ); |
673 | } | 673 | } |
674 | 674 | ||
675 | void KRFBDecoder::gotServerCut() | 675 | void KRFBDecoder::gotServerCut() |
676 | { | 676 | { |
677 | owarn << "Got server cut" << oendl; | 677 | owarn << "Got server cut" << oendl; |
678 | 678 | ||
679 | currentState = AwaitingServerCutLength; | 679 | currentState = AwaitingServerCutLength; |
680 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutLength() ) ); | 680 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutLength() ) ); |
681 | con->waitForData( ServerCutLenLength ); | 681 | con->waitForData( ServerCutLenLength ); |
682 | } | 682 | } |
683 | 683 | ||
684 | void KRFBDecoder::gotServerCutLength() | 684 | void KRFBDecoder::gotServerCutLength() |
685 | { | 685 | { |
686 | assert( currentState = AwaitingServerCutLength ); | 686 | assert( currentState = AwaitingServerCutLength ); |
687 | disconnect( con, SIGNAL( gotEnoughData() ), | 687 | disconnect( con, SIGNAL( gotEnoughData() ), |
688 | this, SLOT( gotServerCutLength() ) ); | 688 | this, SLOT( gotServerCutLength() ) ); |
689 | 689 | ||
690 | CARD8 padding[3]; | 690 | CARD8 padding[3]; |
691 | con->read( padding, 3 ); | 691 | con->read( padding, 3 ); |
692 | 692 | ||
693 | con->read( &serverCutTextLen, 4 ); | 693 | con->read( &serverCutTextLen, 4 ); |
694 | serverCutTextLen = Swap32IfLE( serverCutTextLen ); | 694 | serverCutTextLen = Swap32IfLE( serverCutTextLen ); |
695 | 695 | ||
696 | currentState = AwaitingServerCutText; | 696 | currentState = AwaitingServerCutText; |
697 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutText() ) ); | 697 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutText() ) ); |
698 | con->waitForData( serverCutTextLen ); | 698 | con->waitForData( serverCutTextLen ); |
699 | } | 699 | } |
700 | 700 | ||
701 | void KRFBDecoder::gotServerCutText() | 701 | void KRFBDecoder::gotServerCutText() |
702 | { | 702 | { |
703 | assert( currentState = AwaitingServerCutText ); | 703 | assert( currentState = AwaitingServerCutText ); |
704 | 704 | ||
705 | disconnect( con, SIGNAL( gotEnoughData() ), | 705 | disconnect( con, SIGNAL( gotEnoughData() ), |
706 | this, SLOT( gotServerCutText() ) ); | 706 | this, SLOT( gotServerCutText() ) ); |
707 | 707 | ||
708 | 708 | ||
709 | // | 709 | // |
710 | // Warning: There is a bug in the RFB protocol because there is no way to find | 710 | // Warning: There is a bug in the RFB protocol because there is no way to find |
711 | // out the codepage in use on the remote machine. This could be fixed by requiring | 711 | // out the codepage in use on the remote machine. This could be fixed by requiring |
712 | // the remote server to use utf8 etc. but for now we have to assume they're the | 712 | // the remote server to use utf8 etc. but for now we have to assume they're the |
713 | // same. I've reported this problem to the ORL guys, but they apparantly have no | 713 | // same. I've reported this problem to the ORL guys, but they apparantly have no |
714 | // immediate plans to fix the issue. :-( (rich) | 714 | // immediate plans to fix the issue. :-( (rich) |
715 | // | 715 | // |
716 | 716 | ||
717 | char *cutbuf = new char[ serverCutTextLen + 1 ]; | 717 | char *cutbuf = new char[ serverCutTextLen + 1 ]; |
718 | CHECK_PTR( cutbuf ); | 718 | CHECK_PTR( cutbuf ); |
719 | 719 | ||
720 | con->read( cutbuf, serverCutTextLen ); | 720 | con->read( cutbuf, serverCutTextLen ); |
721 | cutbuf[ serverCutTextLen ] = '\0'; | 721 | cutbuf[ serverCutTextLen ] = '\0'; |
722 | 722 | ||
723 | /* For some reason QApplication::clipboard()->setText() segfaults when called | 723 | /* For some reason QApplication::clipboard()->setText() segfaults when called |
724 | * from within keypebble's mass of signals and slots | 724 | * from within keypebble's mass of signals and slots |
725 | owarn << "Server cut: " << cutbuf << "" << oendl; | 725 | owarn << "Server cut: " << cutbuf << "" << oendl; |
726 | 726 | ||
727 | QString cutText( cutbuf ); // DANGER!! | 727 | QString cutText( cutbuf ); // DANGER!! |
728 | qApp->clipboard()->setText( cutText ); | 728 | qApp->clipboard()->setText( cutText ); |
729 | */ | 729 | */ |
730 | 730 | ||
731 | delete cutbuf; | 731 | delete [] cutbuf; |
732 | // Now wait for the update (again) | 732 | // Now wait for the update (again) |
733 | if ( oldState == AwaitingUpdate ) { | 733 | if ( oldState == AwaitingUpdate ) { |
734 | currentState = AwaitingUpdate; | 734 | currentState = AwaitingUpdate; |
735 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); | 735 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); |
736 | con->waitForData( UpdateHeaderLength ); | 736 | con->waitForData( UpdateHeaderLength ); |
737 | } | 737 | } |
738 | else if ( oldState == Idle ) { | 738 | else if ( oldState == Idle ) { |
739 | currentState = Idle; | 739 | currentState = Idle; |
740 | } | 740 | } |
741 | else { | 741 | else { |
742 | owarn << "Async handled in weird state" << oendl; | 742 | owarn << "Async handled in weird state" << oendl; |
743 | currentState = oldState; | 743 | currentState = oldState; |
744 | }; | 744 | }; |
745 | } | 745 | } |
746 | 746 | ||
747 | void KRFBDecoder::gotBell() | 747 | void KRFBDecoder::gotBell() |
748 | { | 748 | { |
749 | owarn << "Got server bell" << oendl; | 749 | owarn << "Got server bell" << oendl; |
750 | buf->soundBell(); | 750 | buf->soundBell(); |
751 | 751 | ||
752 | // Now wait for the update (again) | 752 | // Now wait for the update (again) |
753 | if ( oldState == AwaitingUpdate ) { | 753 | if ( oldState == AwaitingUpdate ) { |
754 | currentState = AwaitingUpdate; | 754 | currentState = AwaitingUpdate; |
755 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); | 755 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); |
756 | con->waitForData( UpdateHeaderLength ); | 756 | con->waitForData( UpdateHeaderLength ); |
757 | } | 757 | } |
758 | else if ( oldState == Idle ) { | 758 | else if ( oldState == Idle ) { |
759 | currentState = Idle; | 759 | currentState = Idle; |
760 | } | 760 | } |
761 | else { | 761 | else { |
762 | owarn << "Async handled in weird state" << oendl; | 762 | owarn << "Async handled in weird state" << oendl; |
763 | currentState = oldState; | 763 | currentState = oldState; |
764 | }; | 764 | }; |
765 | } | 765 | } |
766 | 766 | ||
767 | void KRFBDecoder::sendKeyPressEvent( QKeyEvent *event ) | 767 | void KRFBDecoder::sendKeyPressEvent( QKeyEvent *event ) |
768 | { | 768 | { |
769 | int key; | 769 | int key; |
770 | key = toKeySym( event ); | 770 | key = toKeySym( event ); |
771 | if ( key ) { | 771 | if ( key ) { |
772 | key = Swap32IfLE( key ); | 772 | key = Swap32IfLE( key ); |
773 | 773 | ||
774 | CARD8 mask = true; | 774 | CARD8 mask = true; |
775 | 775 | ||
776 | CARD16 padding = 0; | 776 | CARD16 padding = 0; |
777 | con->write( &KeyEventId, 1 ); | 777 | con->write( &KeyEventId, 1 ); |
778 | con->write( &mask, 1 ); | 778 | con->write( &mask, 1 ); |
779 | con->write( &padding, 2 ); | 779 | con->write( &padding, 2 ); |
780 | con->write( &key, 4 ); | 780 | con->write( &key, 4 ); |
781 | } | 781 | } |
782 | } | 782 | } |
783 | 783 | ||
784 | void KRFBDecoder::sendKeyReleaseEvent( QKeyEvent *event ) | 784 | void KRFBDecoder::sendKeyReleaseEvent( QKeyEvent *event ) |
785 | { | 785 | { |
786 | int key; | 786 | int key; |
787 | key = toKeySym( event ); | 787 | key = toKeySym( event ); |
788 | if ( key ) { | 788 | if ( key ) { |
789 | key = Swap32IfLE( key ); | 789 | key = Swap32IfLE( key ); |
790 | 790 | ||
791 | CARD8 mask = false; | 791 | CARD8 mask = false; |
792 | 792 | ||
793 | CARD16 padding = 0; | 793 | CARD16 padding = 0; |
794 | con->write( &KeyEventId, 1 ); | 794 | con->write( &KeyEventId, 1 ); |
795 | con->write( &mask, 1 ); | 795 | con->write( &mask, 1 ); |
796 | con->write( &padding, 2 ); | 796 | con->write( &padding, 2 ); |
797 | con->write( &key, 4 ); | 797 | con->write( &key, 4 ); |
798 | } | 798 | } |
799 | } | 799 | } |
800 | 800 | ||
801 | 801 | ||
802 | 802 | ||
803 | 803 | ||
804 | // | 804 | // |
805 | // The RFB protocol spec says 'For most ordinary keys, the 'keysym' | 805 | // The RFB protocol spec says 'For most ordinary keys, the 'keysym' |
806 | // is the same as the corresponding ASCII value.', but doesn't | 806 | // is the same as the corresponding ASCII value.', but doesn't |
807 | // elaborate what the most ordinary keys are. The spec also lists | 807 | // elaborate what the most ordinary keys are. The spec also lists |
808 | // a set (possibly subset, it's unspecified) of mappings for | 808 | // a set (possibly subset, it's unspecified) of mappings for |
809 | // "other common keys" (backspace, tab, return, escape, etc). | 809 | // "other common keys" (backspace, tab, return, escape, etc). |
810 | // | 810 | // |
811 | int KRFBDecoder::toKeySym( QKeyEvent *k ) | 811 | int KRFBDecoder::toKeySym( QKeyEvent *k ) |
812 | { | 812 | { |
813 | 813 | ||
814 | // | 814 | // |
815 | // Try and map these "other common keys" first. | 815 | // Try and map these "other common keys" first. |
816 | // | 816 | // |
817 | if ((k->key() >= Qt::Key_Escape) && (k->key() <= Qt::Key_F12)) { | 817 | if ((k->key() >= Qt::Key_Escape) && (k->key() <= Qt::Key_F12)) { |
818 | for(int i = 0; keyMap[i].keycode != 0; i++) { | 818 | for(int i = 0; keyMap[i].keycode != 0; i++) { |
819 | if (k->key() == keyMap[i].keycode) { | 819 | if (k->key() == keyMap[i].keycode) { |
820 | return keyMap[i].keysym; | 820 | return keyMap[i].keysym; |
821 | } | 821 | } |
822 | } | 822 | } |
823 | } | 823 | } |
824 | 824 | ||
825 | // | 825 | // |
826 | // If these keys aren't matched, return the ascii code and let the | 826 | // If these keys aren't matched, return the ascii code and let the |
827 | // server figure it out. We don't return k->key(), as the data in | 827 | // server figure it out. We don't return k->key(), as the data in |
828 | // key differs between input methods, and we don't want special cases. | 828 | // key differs between input methods, and we don't want special cases. |
829 | // | 829 | // |
830 | return k->ascii(); | 830 | return k->ascii(); |
831 | } | 831 | } |
diff --git a/noncore/games/sfcave/sfcave.cpp b/noncore/games/sfcave/sfcave.cpp index a6c92a0..516dc93 100644 --- a/noncore/games/sfcave/sfcave.cpp +++ b/noncore/games/sfcave/sfcave.cpp | |||
@@ -1,1211 +1,1211 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <math.h> | 3 | #include <math.h> |
4 | #include <time.h> | 4 | #include <time.h> |
5 | 5 | ||
6 | #include <opie2/oapplicationfactory.h> | 6 | #include <opie2/oapplicationfactory.h> |
7 | #include <qpe/qpeapplication.h> | 7 | #include <qpe/qpeapplication.h> |
8 | #include <qpe/config.h> | 8 | #include <qpe/config.h> |
9 | #include <qpe/global.h> | 9 | #include <qpe/global.h> |
10 | 10 | ||
11 | #include <qdir.h> | 11 | #include <qdir.h> |
12 | 12 | ||
13 | #include "helpwindow.h" | 13 | #include "helpwindow.h" |
14 | #include "sfcave.h" | 14 | #include "sfcave.h" |
15 | 15 | ||
16 | #define CAPTION "SFCave 1.13 by AndyQ" | 16 | #define CAPTION "SFCave 1.13 by AndyQ" |
17 | 17 | ||
18 | #define UP_THRUST 0.6 | 18 | #define UP_THRUST 0.6 |
19 | #define NO_THRUST 0.8 | 19 | #define NO_THRUST 0.8 |
20 | #define MAX_DOWN_THRUST 4.0 | 20 | #define MAX_DOWN_THRUST 4.0 |
21 | #define MAX_UP_THRUST -3.5 | 21 | #define MAX_UP_THRUST -3.5 |
22 | 22 | ||
23 | // States | 23 | // States |
24 | #define STATE_BOSS 0 | 24 | #define STATE_BOSS 0 |
25 | #define STATE_RUNNING 1 | 25 | #define STATE_RUNNING 1 |
26 | #define STATE_CRASHING 2 | 26 | #define STATE_CRASHING 2 |
27 | #define STATE_CRASHED 3 | 27 | #define STATE_CRASHED 3 |
28 | #define STATE_NEWGAME 4 | 28 | #define STATE_NEWGAME 4 |
29 | #define STATE_MENU 5 | 29 | #define STATE_MENU 5 |
30 | #define STATE_REPLAY 6 | 30 | #define STATE_REPLAY 6 |
31 | 31 | ||
32 | // Menus | 32 | // Menus |
33 | #define MENU_MAIN_MENU 0 | 33 | #define MENU_MAIN_MENU 0 |
34 | #define MENU_OPTIONS_MENU 1 | 34 | #define MENU_OPTIONS_MENU 1 |
35 | #define MENU_REPLAY_MENU 2 | 35 | #define MENU_REPLAY_MENU 2 |
36 | 36 | ||
37 | // Main Menu Options | 37 | // Main Menu Options |
38 | #define MENU_START_GAME 0 | 38 | #define MENU_START_GAME 0 |
39 | #define MENU_REPLAY 1 | 39 | #define MENU_REPLAY 1 |
40 | #define MENU_OPTIONS 2 | 40 | #define MENU_OPTIONS 2 |
41 | #define MENU_HELP 3 | 41 | #define MENU_HELP 3 |
42 | #define MENU_QUIT 4 | 42 | #define MENU_QUIT 4 |
43 | 43 | ||
44 | // Option Menu Options | 44 | // Option Menu Options |
45 | #define MENU_GAME_TYPE 0 | 45 | #define MENU_GAME_TYPE 0 |
46 | #define MENU_GAME_DIFFICULTY 1 | 46 | #define MENU_GAME_DIFFICULTY 1 |
47 | #define MENU_CLEAR_HIGHSCORES 2 | 47 | #define MENU_CLEAR_HIGHSCORES 2 |
48 | #define MENU_BACK 3 | 48 | #define MENU_BACK 3 |
49 | 49 | ||
50 | // Replay Menu Options | 50 | // Replay Menu Options |
51 | #define MENU_REPLAY_START 0 | 51 | #define MENU_REPLAY_START 0 |
52 | #define MENU_REPLAY_LOAD 1 | 52 | #define MENU_REPLAY_LOAD 1 |
53 | #define MENU_REPLAY_SAVE 2 | 53 | #define MENU_REPLAY_SAVE 2 |
54 | #define MENU_REPLAY_BACK 3 | 54 | #define MENU_REPLAY_BACK 3 |
55 | 55 | ||
56 | 56 | ||
57 | #define NR_GAME_DIFFICULTIES 3 | 57 | #define NR_GAME_DIFFICULTIES 3 |
58 | #define NR_GAME_TYPES 3 | 58 | #define NR_GAME_TYPES 3 |
59 | 59 | ||
60 | #define DIFICULTY_EASY 0 | 60 | #define DIFICULTY_EASY 0 |
61 | #define DIFICULTY_NORMAL 1 | 61 | #define DIFICULTY_NORMAL 1 |
62 | #define DIFICULTY_HARD 2 | 62 | #define DIFICULTY_HARD 2 |
63 | #define EASY "Easy" | 63 | #define EASY "Easy" |
64 | #define NORMAL "Normal" | 64 | #define NORMAL "Normal" |
65 | #define HARD "Hard" | 65 | #define HARD "Hard" |
66 | 66 | ||
67 | #define SFCAVE_GAME_TYPE 0 | 67 | #define SFCAVE_GAME_TYPE 0 |
68 | #define GATES_GAME_TYPE 1 | 68 | #define GATES_GAME_TYPE 1 |
69 | #define FLY_GAME_TYPE 2 | 69 | #define FLY_GAME_TYPE 2 |
70 | #define SFCAVE_GAME "SFCave" | 70 | #define SFCAVE_GAME "SFCave" |
71 | #define GATES_GAME "Gates" | 71 | #define GATES_GAME "Gates" |
72 | #define FLY_GAME "Fly" | 72 | #define FLY_GAME "Fly" |
73 | #define CURRENT_GAME_TYPE gameTypes[currentGameType] | 73 | #define CURRENT_GAME_TYPE gameTypes[currentGameType] |
74 | #define CURRENT_GAME_DIFFICULTY difficultyOption[currentGameDifficulty]; | 74 | #define CURRENT_GAME_DIFFICULTY difficultyOption[currentGameDifficulty]; |
75 | 75 | ||
76 | QString SFCave::dificultyOption[] = { EASY, NORMAL, HARD }; | 76 | QString SFCave::dificultyOption[] = { EASY, NORMAL, HARD }; |
77 | QString SFCave::gameTypes[] = { SFCAVE_GAME, GATES_GAME, FLY_GAME }; | 77 | QString SFCave::gameTypes[] = { SFCAVE_GAME, GATES_GAME, FLY_GAME }; |
78 | 78 | ||
79 | QString SFCave::menuOptions[NR_MENUS][MAX_MENU_OPTIONS] = { { "Start Game", "Replays", "Options", "Help", "Quit", "", "", "" }, | 79 | QString SFCave::menuOptions[NR_MENUS][MAX_MENU_OPTIONS] = { { "Start Game", "Replays", "Options", "Help", "Quit", "", "", "" }, |
80 | { "Game Type - %s", "Game Difficulty - %s", "Clear High Scores for this game", "Back", "", "", "", "" }, | 80 | { "Game Type - %s", "Game Difficulty - %s", "Clear High Scores for this game", "Back", "", "", "", "" }, |
81 | { "Play Reply", "Load Replay", "Save Replay", "Back", "", "", "", "" } }; | 81 | { "Play Reply", "Load Replay", "Save Replay", "Back", "", "", "", "" } }; |
82 | 82 | ||
83 | int SFCave::nrMenuOptions[NR_MENUS] = { 5, 4, 4 }; | 83 | int SFCave::nrMenuOptions[NR_MENUS] = { 5, 4, 4 }; |
84 | int SFCave ::currentMenuOption[NR_MENUS] = { 0, 0, 0 }; | 84 | int SFCave ::currentMenuOption[NR_MENUS] = { 0, 0, 0 }; |
85 | 85 | ||
86 | #define UP_THRUST 0.6 | 86 | #define UP_THRUST 0.6 |
87 | #define NO_THRUST 0.8 | 87 | #define NO_THRUST 0.8 |
88 | #define MAX_DOWN_THRUST 4.0 | 88 | #define MAX_DOWN_THRUST 4.0 |
89 | #define MAX_UP_THRUST -3.5 | 89 | #define MAX_UP_THRUST -3.5 |
90 | double SFCave::UpThrustVals[3][3] = {{ 0.6, 0.6, 0.6 }, // SFCave | 90 | double SFCave::UpThrustVals[3][3] = {{ 0.6, 0.6, 0.6 }, // SFCave |
91 | { 0.6, 0.6, 0.8 }, // Gates | 91 | { 0.6, 0.6, 0.8 }, // Gates |
92 | { 0.4, 0.7, 1.0 } }; // Fly | 92 | { 0.4, 0.7, 1.0 } }; // Fly |
93 | 93 | ||
94 | double SFCave::DownThrustVals[3][3] = {{ 0.8, 0.8, 0.8 }, // SFCave | 94 | double SFCave::DownThrustVals[3][3] = {{ 0.8, 0.8, 0.8 }, // SFCave |
95 | { 0.8, 0.8, 1.0 }, // Gates | 95 | { 0.8, 0.8, 1.0 }, // Gates |
96 | { 0.4, 0.7, 1.0 } }; // Fly | 96 | { 0.4, 0.7, 1.0 } }; // Fly |
97 | 97 | ||
98 | double SFCave::MaxUpThrustVals[3][3] = {{ -3.5, -3.5, -3.5 }, // SFCave | 98 | double SFCave::MaxUpThrustVals[3][3] = {{ -3.5, -3.5, -3.5 }, // SFCave |
99 | { -3.5, -4.0, -5.0 }, // Gates | 99 | { -3.5, -4.0, -5.0 }, // Gates |
100 | { -3.5, -4.0, -5.0 } }; // Fly | 100 | { -3.5, -4.0, -5.0 } }; // Fly |
101 | 101 | ||
102 | double SFCave::MaxDownThrustVals[3][3] = {{ 4.0, 4.0, 4.0 }, // SFCave | 102 | double SFCave::MaxDownThrustVals[3][3] = {{ 4.0, 4.0, 4.0 }, // SFCave |
103 | { 4.0, 5.0, 5.5 }, // Gates | 103 | { 4.0, 5.0, 5.5 }, // Gates |
104 | { 3.5, 4.0, 5.0 } }; // Fly | 104 | { 3.5, 4.0, 5.0 } }; // Fly |
105 | 105 | ||
106 | int SFCave::flyEasyScores[7][3] = { { 0, 10, 5 }, | 106 | int SFCave::flyEasyScores[7][3] = { { 0, 10, 5 }, |
107 | { 10, 20, 3 }, | 107 | { 10, 20, 3 }, |
108 | { 20, 30, 2 }, | 108 | { 20, 30, 2 }, |
109 | { 30, 40, 1 }, | 109 | { 30, 40, 1 }, |
110 | { 50, 70, -2 }, | 110 | { 50, 70, -2 }, |
111 | { 70, 300, -5 }, | 111 | { 70, 300, -5 }, |
112 | { -1, -1, -1 } }; | 112 | { -1, -1, -1 } }; |
113 | int SFCave::flyNormalScores[7][3] = { { 0, 10, 5 }, | 113 | int SFCave::flyNormalScores[7][3] = { { 0, 10, 5 }, |
114 | { 10, 20, 3 }, | 114 | { 10, 20, 3 }, |
115 | { 20, 30, 2 }, | 115 | { 20, 30, 2 }, |
116 | { 30, 40, 1 }, | 116 | { 30, 40, 1 }, |
117 | { 50, 70, -2 }, | 117 | { 50, 70, -2 }, |
118 | { 70, 300, -5 }, | 118 | { 70, 300, -5 }, |
119 | { -1, -1, -1 } }; | 119 | { -1, -1, -1 } }; |
120 | int SFCave::flyHardScores[7][3] = { { 0, 20, 5 }, | 120 | int SFCave::flyHardScores[7][3] = { { 0, 20, 5 }, |
121 | { 20, 40, 3 }, | 121 | { 20, 40, 3 }, |
122 | { 40, 100, 1 }, | 122 | { 40, 100, 1 }, |
123 | { 100, 150, -2 }, | 123 | { 100, 150, -2 }, |
124 | { 150, 300, -5 }, | 124 | { 150, 300, -5 }, |
125 | { -1, -1, -1 } }; | 125 | { -1, -1, -1 } }; |
126 | 126 | ||
127 | int SFCave::initialGateGaps[] = { 75, 50, 25 }; | 127 | int SFCave::initialGateGaps[] = { 75, 50, 25 }; |
128 | 128 | ||
129 | 129 | ||
130 | #define FLYSCORES( x, y ) (*(flyScores + ((x)*3) + y)) | 130 | #define FLYSCORES( x, y ) (*(flyScores + ((x)*3) + y)) |
131 | bool movel; | 131 | bool movel; |
132 | 132 | ||
133 | 133 | ||
134 | OPIE_EXPORT_APP( Opie::Core::OApplicationFactory<SFCave> ) | 134 | OPIE_EXPORT_APP( Opie::Core::OApplicationFactory<SFCave> ) |
135 | 135 | ||
136 | SFCave :: SFCave( QWidget *w, const char *name, WFlags fl ) | 136 | SFCave :: SFCave( QWidget *w, const char *name, WFlags fl ) |
137 | : QMainWindow( w, name, fl ) | 137 | : QMainWindow( w, name, fl ) |
138 | 138 | ||
139 | { | 139 | { |
140 | showMaximized(); | 140 | showMaximized(); |
141 | movel = true; | 141 | movel = true; |
142 | int spd = 3; | 142 | int spd = 3; |
143 | 143 | ||
144 | 144 | ||
145 | replayIt = 0; | 145 | replayIt = 0; |
146 | 146 | ||
147 | replayFile = Global::applicationFileName("sfcave", "replay"); | 147 | replayFile = Global::applicationFileName("sfcave", "replay"); |
148 | 148 | ||
149 | sWidth = width(); | 149 | sWidth = width(); |
150 | sHeight = height(); | 150 | sHeight = height(); |
151 | segSize = sWidth/(MAPSIZE-1)+1; | 151 | segSize = sWidth/(MAPSIZE-1)+1; |
152 | 152 | ||
153 | currentMenuNr = 0; | 153 | currentMenuNr = 0; |
154 | currentGameType = 0; | 154 | currentGameType = 0; |
155 | currentGameDifficulty = 0; | 155 | currentGameDifficulty = 0; |
156 | 156 | ||
157 | setCaption( CAPTION ); | 157 | setCaption( CAPTION ); |
158 | showScoreZones = false; | 158 | showScoreZones = false; |
159 | 159 | ||
160 | #ifdef QWS | 160 | #ifdef QWS |
161 | Config cfg( "sfcave" ); | 161 | Config cfg( "sfcave" ); |
162 | cfg.setGroup( "settings" ); | 162 | cfg.setGroup( "settings" ); |
163 | QString key = "highScore_"; | 163 | QString key = "highScore_"; |
164 | 164 | ||
165 | for ( int i = 0 ; i < 3 ; ++i ) | 165 | for ( int i = 0 ; i < 3 ; ++i ) |
166 | { | 166 | { |
167 | for ( int j = 0 ; j < 3 ; ++j ) | 167 | for ( int j = 0 ; j < 3 ; ++j ) |
168 | highestScore[i][j] = cfg.readNumEntry( key + gameTypes[i] + "_" + dificultyOption[j], 0 ); | 168 | highestScore[i][j] = cfg.readNumEntry( key + gameTypes[i] + "_" + dificultyOption[j], 0 ); |
169 | } | 169 | } |
170 | 170 | ||
171 | currentGameType = cfg.readNumEntry( "gameType", 0 ); | 171 | currentGameType = cfg.readNumEntry( "gameType", 0 ); |
172 | currentGameDifficulty = cfg.readNumEntry( "difficulty", 0 ); | 172 | currentGameDifficulty = cfg.readNumEntry( "difficulty", 0 ); |
173 | #endif | 173 | #endif |
174 | speed = spd; // Change to 2 for PC | 174 | speed = spd; // Change to 2 for PC |
175 | press = false; | 175 | press = false; |
176 | showEyeCandy = false; | 176 | showEyeCandy = false; |
177 | 177 | ||
178 | offscreen = new QPixmap( sWidth, sHeight ); | 178 | offscreen = new QPixmap( sWidth, sHeight ); |
179 | offscreen->fill( Qt::black ); | 179 | offscreen->fill( Qt::black ); |
180 | 180 | ||
181 | // setUp(); | 181 | // setUp(); |
182 | crashLineLength = -1; | 182 | crashLineLength = -1; |
183 | state = STATE_MENU; | 183 | state = STATE_MENU; |
184 | prevState = STATE_MENU; | 184 | prevState = STATE_MENU; |
185 | 185 | ||
186 | gameTimer = new QTimer( this, "game timer" ); | 186 | gameTimer = new QTimer( this, "game timer" ); |
187 | connect( gameTimer, SIGNAL( timeout() ), | 187 | connect( gameTimer, SIGNAL( timeout() ), |
188 | this, SLOT( run() ) ); | 188 | this, SLOT( run() ) ); |
189 | 189 | ||
190 | QTimer::singleShot(0, this, SLOT(start())); | 190 | QTimer::singleShot(0, this, SLOT(start())); |
191 | } | 191 | } |
192 | 192 | ||
193 | SFCave :: ~SFCave() | 193 | SFCave :: ~SFCave() |
194 | { | 194 | { |
195 | } | 195 | } |
196 | 196 | ||
197 | void SFCave :: start() | 197 | void SFCave :: start() |
198 | { | 198 | { |
199 | gameTimer->start( 10 ); | 199 | gameTimer->start( 10 ); |
200 | 200 | ||
201 | } | 201 | } |
202 | 202 | ||
203 | void SFCave :: setSeed( int seed ) | 203 | void SFCave :: setSeed( int seed ) |
204 | { | 204 | { |
205 | if ( seed == -1 ) | 205 | if ( seed == -1 ) |
206 | currentSeed = ((unsigned long) time((time_t *) NULL)); | 206 | currentSeed = ((unsigned long) time((time_t *) NULL)); |
207 | else | 207 | else |
208 | currentSeed = seed; | 208 | currentSeed = seed; |
209 | PutSeed( currentSeed ); | 209 | PutSeed( currentSeed ); |
210 | } | 210 | } |
211 | 211 | ||
212 | int SFCave :: nextInt( int range ) | 212 | int SFCave :: nextInt( int range ) |
213 | { | 213 | { |
214 | int val = (int)(Random( ) * range); | 214 | int val = (int)(Random( ) * range); |
215 | 215 | ||
216 | return val; | 216 | return val; |
217 | 217 | ||
218 | } | 218 | } |
219 | 219 | ||
220 | void SFCave :: setUp() | 220 | void SFCave :: setUp() |
221 | { | 221 | { |
222 | score = 0; | 222 | score = 0; |
223 | offset = 0; | 223 | offset = 0; |
224 | nrFrames = 0; | 224 | nrFrames = 0; |
225 | dir = 1; | 225 | dir = 1; |
226 | thrust = 0; | 226 | thrust = 0; |
227 | startScoring = false; | 227 | startScoring = false; |
228 | press = false; | 228 | press = false; |
229 | 229 | ||
230 | if ( CURRENT_GAME_TYPE == SFCAVE_GAME ) | 230 | if ( CURRENT_GAME_TYPE == SFCAVE_GAME ) |
231 | { | 231 | { |
232 | thrustUp = UpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; | 232 | thrustUp = UpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; |
233 | noThrust = DownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; | 233 | noThrust = DownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; |
234 | maxUpThrust = MaxUpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; | 234 | maxUpThrust = MaxUpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; |
235 | maxDownThrust = MaxDownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; | 235 | maxDownThrust = MaxDownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; |
236 | 236 | ||
237 | if ( currentGameDifficulty == DIFICULTY_EASY ) | 237 | if ( currentGameDifficulty == DIFICULTY_EASY ) |
238 | gateDistance = 100; | 238 | gateDistance = 100; |
239 | else if ( currentGameDifficulty == DIFICULTY_NORMAL ) | 239 | else if ( currentGameDifficulty == DIFICULTY_NORMAL ) |
240 | gateDistance = 60; | 240 | gateDistance = 60; |
241 | else | 241 | else |
242 | gateDistance = 40; | 242 | gateDistance = 40; |
243 | } | 243 | } |
244 | else if ( CURRENT_GAME_TYPE == GATES_GAME ) | 244 | else if ( CURRENT_GAME_TYPE == GATES_GAME ) |
245 | { | 245 | { |
246 | thrustUp = UpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; | 246 | thrustUp = UpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; |
247 | noThrust = DownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; | 247 | noThrust = DownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; |
248 | maxUpThrust = MaxUpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; | 248 | maxUpThrust = MaxUpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; |
249 | maxDownThrust = MaxDownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; | 249 | maxDownThrust = MaxDownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; |
250 | gateDistance = 75; | 250 | gateDistance = 75; |
251 | nextGate = nextInt( 50 ) + gateDistance; | 251 | nextGate = nextInt( 50 ) + gateDistance; |
252 | } | 252 | } |
253 | else | 253 | else |
254 | { | 254 | { |
255 | thrustUp = UpThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; | 255 | thrustUp = UpThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; |
256 | noThrust = DownThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; | 256 | noThrust = DownThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; |
257 | maxUpThrust = MaxUpThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; | 257 | maxUpThrust = MaxUpThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; |
258 | maxDownThrust = MaxDownThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; | 258 | maxDownThrust = MaxDownThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; |
259 | 259 | ||
260 | if ( currentGameDifficulty == DIFICULTY_EASY ) | 260 | if ( currentGameDifficulty == DIFICULTY_EASY ) |
261 | flyScores = (int*)flyEasyScores; | 261 | flyScores = (int*)flyEasyScores; |
262 | else if ( currentGameDifficulty == DIFICULTY_NORMAL ) | 262 | else if ( currentGameDifficulty == DIFICULTY_NORMAL ) |
263 | flyScores = (int*)flyNormalScores; | 263 | flyScores = (int*)flyNormalScores; |
264 | else | 264 | else |
265 | flyScores = (int*)flyHardScores; | 265 | flyScores = (int*)flyHardScores; |
266 | } | 266 | } |
267 | 267 | ||
268 | crashLineLength = 0; | 268 | crashLineLength = 0; |
269 | lastGateBottomY = 0; | 269 | lastGateBottomY = 0; |
270 | 270 | ||
271 | user.setRect( 50, sWidth/2, 4, 4 ); | 271 | user.setRect( 50, sWidth/2, 4, 4 ); |
272 | 272 | ||
273 | blockWidth = 20; | 273 | blockWidth = 20; |
274 | blockHeight = 70; | 274 | blockHeight = 70; |
275 | gapHeight = initialGateGaps[currentGameDifficulty]; | 275 | gapHeight = initialGateGaps[currentGameDifficulty]; |
276 | 276 | ||
277 | for ( int i = 0 ; i < TRAILSIZE ; ++i ) | 277 | for ( int i = 0 ; i < TRAILSIZE ; ++i ) |
278 | { | 278 | { |
279 | trail[i].setX( -1 ); | 279 | trail[i].setX( -1 ); |
280 | trail[i].setY( 0 ); | 280 | trail[i].setY( 0 ); |
281 | } | 281 | } |
282 | 282 | ||
283 | if ( CURRENT_GAME_TYPE != FLY_GAME ) | 283 | if ( CURRENT_GAME_TYPE != FLY_GAME ) |
284 | { | 284 | { |
285 | maxHeight = 50; | 285 | maxHeight = 50; |
286 | 286 | ||
287 | mapTop[0] = (int)(nextInt(50)) + 5; | 287 | mapTop[0] = (int)(nextInt(50)) + 5; |
288 | mapBottom[0] = (int)(nextInt(50)) + 5; | 288 | mapBottom[0] = (int)(nextInt(50)) + 5; |
289 | for ( int i = 1 ; i < MAPSIZE ; ++i ) | 289 | for ( int i = 1 ; i < MAPSIZE ; ++i ) |
290 | setPoint( i ); | 290 | setPoint( i ); |
291 | } | 291 | } |
292 | else | 292 | else |
293 | { | 293 | { |
294 | maxHeight = 100; | 294 | maxHeight = 100; |
295 | 295 | ||
296 | for ( int i = 0 ; i < MAPSIZE ; ++i ) | 296 | for ( int i = 0 ; i < MAPSIZE ; ++i ) |
297 | mapBottom[i] = sHeight - 10; | 297 | mapBottom[i] = sHeight - 10; |
298 | } | 298 | } |
299 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) | 299 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) |
300 | blocks[i].setY( -1 ); | 300 | blocks[i].setY( -1 ); |
301 | 301 | ||
302 | } | 302 | } |
303 | 303 | ||
304 | void SFCave :: run() | 304 | void SFCave :: run() |
305 | { | 305 | { |
306 | switch ( state ) | 306 | switch ( state ) |
307 | { | 307 | { |
308 | case STATE_MENU: | 308 | case STATE_MENU: |
309 | displayMenu(); | 309 | displayMenu(); |
310 | break; | 310 | break; |
311 | case STATE_NEWGAME: | 311 | case STATE_NEWGAME: |
312 | setSeed( -1 ); | 312 | setSeed( -1 ); |
313 | setUp(); | 313 | setUp(); |
314 | draw(); | 314 | draw(); |
315 | state = STATE_RUNNING; | 315 | state = STATE_RUNNING; |
316 | replay = false; | 316 | replay = false; |
317 | replayList.clear(); | 317 | replayList.clear(); |
318 | break; | 318 | break; |
319 | case STATE_REPLAY: | 319 | case STATE_REPLAY: |
320 | setSeed( currentSeed ); | 320 | setSeed( currentSeed ); |
321 | setUp(); | 321 | setUp(); |
322 | draw(); | 322 | draw(); |
323 | state = STATE_RUNNING; | 323 | state = STATE_RUNNING; |
324 | replay = true; | 324 | replay = true; |
325 | if ( replayIt ) | 325 | if ( replayIt ) |
326 | delete replayIt; | 326 | delete replayIt; |
327 | replayIt = new QListIterator<int>( replayList ); | 327 | replayIt = new QListIterator<int>( replayList ); |
328 | break; | 328 | break; |
329 | case STATE_BOSS: | 329 | case STATE_BOSS: |
330 | drawBoss(); | 330 | drawBoss(); |
331 | break; | 331 | break; |
332 | 332 | ||
333 | case STATE_CRASHING: | 333 | case STATE_CRASHING: |
334 | case STATE_CRASHED: | 334 | case STATE_CRASHED: |
335 | press = false; | 335 | press = false; |
336 | draw(); | 336 | draw(); |
337 | break; | 337 | break; |
338 | 338 | ||
339 | case STATE_RUNNING: | 339 | case STATE_RUNNING: |
340 | { | 340 | { |
341 | if ( nrFrames % 2 == 0 ) | 341 | if ( nrFrames % 2 == 0 ) |
342 | handleKeys(); | 342 | handleKeys(); |
343 | 343 | ||
344 | // Apply Game rules | 344 | // Apply Game rules |
345 | nrFrames ++; | 345 | nrFrames ++; |
346 | 346 | ||
347 | if ( replay ) | 347 | if ( replay ) |
348 | { | 348 | { |
349 | while( replayIt->current() && *(replayIt->current()) == nrFrames ) | 349 | while( replayIt->current() && *(replayIt->current()) == nrFrames ) |
350 | { | 350 | { |
351 | press = !press; | 351 | press = !press; |
352 | ++(*replayIt); | 352 | ++(*replayIt); |
353 | } | 353 | } |
354 | } | 354 | } |
355 | 355 | ||
356 | if ( CURRENT_GAME_TYPE == SFCAVE_GAME ) | 356 | if ( CURRENT_GAME_TYPE == SFCAVE_GAME ) |
357 | handleGameSFCave(); | 357 | handleGameSFCave(); |
358 | else if ( CURRENT_GAME_TYPE == GATES_GAME ) | 358 | else if ( CURRENT_GAME_TYPE == GATES_GAME ) |
359 | handleGameGates(); | 359 | handleGameGates(); |
360 | else if ( CURRENT_GAME_TYPE == FLY_GAME ) | 360 | else if ( CURRENT_GAME_TYPE == FLY_GAME ) |
361 | handleGameFly(); | 361 | handleGameFly(); |
362 | 362 | ||
363 | draw(); | 363 | draw(); |
364 | break; | 364 | break; |
365 | } | 365 | } |
366 | } | 366 | } |
367 | } | 367 | } |
368 | 368 | ||
369 | void SFCave :: handleGameSFCave() | 369 | void SFCave :: handleGameSFCave() |
370 | { | 370 | { |
371 | // Update score | 371 | // Update score |
372 | if ( nrFrames % 5 == 0 ) | 372 | if ( nrFrames % 5 == 0 ) |
373 | score ++; | 373 | score ++; |
374 | 374 | ||
375 | if ( nrFrames % 500 == 0 ) | 375 | if ( nrFrames % 500 == 0 ) |
376 | { | 376 | { |
377 | if ( maxHeight < sHeight - 100 ) | 377 | if ( maxHeight < sHeight - 100 ) |
378 | { | 378 | { |
379 | maxHeight += 10; | 379 | maxHeight += 10; |
380 | 380 | ||
381 | // Reduce block height | 381 | // Reduce block height |
382 | if ( maxHeight > sHeight - 150 ) | 382 | if ( maxHeight > sHeight - 150 ) |
383 | blockHeight -= 5; | 383 | blockHeight -= 5; |
384 | } | 384 | } |
385 | } | 385 | } |
386 | 386 | ||
387 | if ( nrFrames % gateDistance == 0 ) | 387 | if ( nrFrames % gateDistance == 0 ) |
388 | addBlock(); | 388 | addBlock(); |
389 | 389 | ||
390 | if ( checkCollision() ) | 390 | if ( checkCollision() ) |
391 | { | 391 | { |
392 | if ( score > highestScore[currentGameType][currentGameDifficulty] ) | 392 | if ( score > highestScore[currentGameType][currentGameDifficulty] ) |
393 | { | 393 | { |
394 | highestScore[currentGameType][currentGameDifficulty] = score; | 394 | highestScore[currentGameType][currentGameDifficulty] = score; |
395 | saveScore(); | 395 | saveScore(); |
396 | } | 396 | } |
397 | state = STATE_CRASHING; | 397 | state = STATE_CRASHING; |
398 | } | 398 | } |
399 | else | 399 | else |
400 | { | 400 | { |
401 | moveLandscape(); | 401 | moveLandscape(); |
402 | } | 402 | } |
403 | 403 | ||
404 | } | 404 | } |
405 | 405 | ||
406 | 406 | ||
407 | void SFCave :: handleGameGates() | 407 | void SFCave :: handleGameGates() |
408 | { | 408 | { |
409 | // Update score | 409 | // Update score |
410 | if ( nrFrames % 5 == 0 ) | 410 | if ( nrFrames % 5 == 0 ) |
411 | score ++; | 411 | score ++; |
412 | 412 | ||
413 | // Slightly random gap distance | 413 | // Slightly random gap distance |
414 | if ( nrFrames >= nextGate ) | 414 | if ( nrFrames >= nextGate ) |
415 | { | 415 | { |
416 | nextGate = nrFrames + nextInt( 50 ) + gateDistance; | 416 | nextGate = nrFrames + nextInt( 50 ) + gateDistance; |
417 | addGate(); | 417 | addGate(); |
418 | } | 418 | } |
419 | 419 | ||
420 | if ( nrFrames % 500 == 0 ) | 420 | if ( nrFrames % 500 == 0 ) |
421 | { | 421 | { |
422 | if ( gapHeight > 75 ) | 422 | if ( gapHeight > 75 ) |
423 | gapHeight -= 5; | 423 | gapHeight -= 5; |
424 | } | 424 | } |
425 | 425 | ||
426 | if ( checkCollision() ) | 426 | if ( checkCollision() ) |
427 | { | 427 | { |
428 | if ( score > highestScore[currentGameType][currentGameDifficulty] ) | 428 | if ( score > highestScore[currentGameType][currentGameDifficulty] ) |
429 | { | 429 | { |
430 | highestScore[currentGameType][currentGameDifficulty] = score; | 430 | highestScore[currentGameType][currentGameDifficulty] = score; |
431 | saveScore(); | 431 | saveScore(); |
432 | } | 432 | } |
433 | state = STATE_CRASHING; | 433 | state = STATE_CRASHING; |
434 | } | 434 | } |
435 | else | 435 | else |
436 | { | 436 | { |
437 | moveLandscape(); | 437 | moveLandscape(); |
438 | } | 438 | } |
439 | 439 | ||
440 | } | 440 | } |
441 | 441 | ||
442 | void SFCave :: handleGameFly() | 442 | void SFCave :: handleGameFly() |
443 | { | 443 | { |
444 | int diff = mapBottom[10] - user.y(); | 444 | int diff = mapBottom[10] - user.y(); |
445 | 445 | ||
446 | if ( nrFrames % 4 == 0 ) | 446 | if ( nrFrames % 4 == 0 ) |
447 | { | 447 | { |
448 | if ( !startScoring ) | 448 | if ( !startScoring ) |
449 | { | 449 | { |
450 | if ( diff < 40 ) | 450 | if ( diff < 40 ) |
451 | startScoring = true; | 451 | startScoring = true; |
452 | } | 452 | } |
453 | 453 | ||
454 | if ( startScoring ) | 454 | if ( startScoring ) |
455 | { | 455 | { |
456 | // Update score | 456 | // Update score |
457 | // get distance between landscape and ship | 457 | // get distance between landscape and ship |
458 | 458 | ||
459 | // the closer the difference is to 0 means more points | 459 | // the closer the difference is to 0 means more points |
460 | for ( int i = 0 ; i < 10 && FLYSCORES( i, 0 ) != -1 ; ++i ) | 460 | for ( int i = 0 ; i < 10 && FLYSCORES( i, 0 ) != -1 ; ++i ) |
461 | { | 461 | { |
462 | if ( FLYSCORES( i, 0 ) <= diff && FLYSCORES(i, 1 ) > diff ) | 462 | if ( FLYSCORES( i, 0 ) <= diff && FLYSCORES(i, 1 ) > diff ) |
463 | { | 463 | { |
464 | score += FLYSCORES( i, 2 ); | 464 | score += FLYSCORES( i, 2 ); |
465 | break; | 465 | break; |
466 | } | 466 | } |
467 | } | 467 | } |
468 | } | 468 | } |
469 | } | 469 | } |
470 | 470 | ||
471 | if ( checkFlyGameCollision() ) | 471 | if ( checkFlyGameCollision() ) |
472 | { | 472 | { |
473 | if ( score > highestScore[currentGameType][currentGameDifficulty] ) | 473 | if ( score > highestScore[currentGameType][currentGameDifficulty] ) |
474 | { | 474 | { |
475 | highestScore[currentGameType][currentGameDifficulty] = score; | 475 | highestScore[currentGameType][currentGameDifficulty] = score; |
476 | saveScore(); | 476 | saveScore(); |
477 | } | 477 | } |
478 | state = STATE_CRASHING; | 478 | state = STATE_CRASHING; |
479 | } | 479 | } |
480 | else | 480 | else |
481 | { | 481 | { |
482 | moveFlyGameLandscape(); | 482 | moveFlyGameLandscape(); |
483 | } | 483 | } |
484 | } | 484 | } |
485 | 485 | ||
486 | bool SFCave :: checkFlyGameCollision() | 486 | bool SFCave :: checkFlyGameCollision() |
487 | { | 487 | { |
488 | if ( (user.y() + user.width()) >= mapBottom[11] ) | 488 | if ( (user.y() + user.width()) >= mapBottom[11] ) |
489 | return true; | 489 | return true; |
490 | 490 | ||
491 | return false; | 491 | return false; |
492 | } | 492 | } |
493 | 493 | ||
494 | void SFCave :: moveFlyGameLandscape() | 494 | void SFCave :: moveFlyGameLandscape() |
495 | { | 495 | { |
496 | offset++; | 496 | offset++; |
497 | 497 | ||
498 | if ( offset >= segSize ) | 498 | if ( offset >= segSize ) |
499 | { | 499 | { |
500 | offset = 0; | 500 | offset = 0; |
501 | for ( int i = 0 ; i < MAPSIZE-speed ; ++i ) | 501 | for ( int i = 0 ; i < MAPSIZE-speed ; ++i ) |
502 | mapBottom[i] = mapBottom[i+speed]; | 502 | mapBottom[i] = mapBottom[i+speed]; |
503 | 503 | ||
504 | for ( int i = speed ; i > 0 ; --i ) | 504 | for ( int i = speed ; i > 0 ; --i ) |
505 | setFlyPoint( MAPSIZE-i ); | 505 | setFlyPoint( MAPSIZE-i ); |
506 | } | 506 | } |
507 | } | 507 | } |
508 | 508 | ||
509 | void SFCave :: setFlyPoint( int point ) | 509 | void SFCave :: setFlyPoint( int point ) |
510 | { | 510 | { |
511 | static int fly_difficulty_levels[] = { 5, 10, 15 }; | 511 | static int fly_difficulty_levels[] = { 5, 10, 15 }; |
512 | if ( nextInt(100) >= 75 ) | 512 | if ( nextInt(100) >= 75 ) |
513 | dir *= -1; | 513 | dir *= -1; |
514 | 514 | ||
515 | int prevPoint = mapBottom[point-1]; | 515 | int prevPoint = mapBottom[point-1]; |
516 | 516 | ||
517 | int nextPoint = prevPoint + (dir * nextInt( fly_difficulty_levels[currentGameDifficulty] ) ); | 517 | int nextPoint = prevPoint + (dir * nextInt( fly_difficulty_levels[currentGameDifficulty] ) ); |
518 | 518 | ||
519 | if ( nextPoint > sHeight ) | 519 | if ( nextPoint > sHeight ) |
520 | { | 520 | { |
521 | nextPoint = sHeight; | 521 | nextPoint = sHeight; |
522 | dir *= -1; | 522 | dir *= -1; |
523 | } | 523 | } |
524 | else if ( nextPoint < maxHeight ) | 524 | else if ( nextPoint < maxHeight ) |
525 | { | 525 | { |
526 | nextPoint = maxHeight; | 526 | nextPoint = maxHeight; |
527 | dir *= 1; | 527 | dir *= 1; |
528 | } | 528 | } |
529 | 529 | ||
530 | mapBottom[point] = nextPoint; | 530 | mapBottom[point] = nextPoint; |
531 | } | 531 | } |
532 | 532 | ||
533 | bool SFCave :: checkCollision() | 533 | bool SFCave :: checkCollision() |
534 | { | 534 | { |
535 | if ( (user.y() + user.width()) >= mapBottom[11] || user.y() <= mapTop[11] ) | 535 | if ( (user.y() + user.width()) >= mapBottom[11] || user.y() <= mapTop[11] ) |
536 | return true; | 536 | return true; |
537 | 537 | ||
538 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) | 538 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) |
539 | { | 539 | { |
540 | if ( blocks[i].y() != -1 ) | 540 | if ( blocks[i].y() != -1 ) |
541 | { | 541 | { |
542 | if ( blocks[i].intersects( user ) ) | 542 | if ( blocks[i].intersects( user ) ) |
543 | return true; | 543 | return true; |
544 | } | 544 | } |
545 | } | 545 | } |
546 | return false; | 546 | return false; |
547 | } | 547 | } |
548 | 548 | ||
549 | void SFCave :: moveLandscape() | 549 | void SFCave :: moveLandscape() |
550 | { | 550 | { |
551 | offset++; | 551 | offset++; |
552 | 552 | ||
553 | if ( offset >= segSize ) | 553 | if ( offset >= segSize ) |
554 | { | 554 | { |
555 | offset = 0; | 555 | offset = 0; |
556 | for ( int i = 0 ; i < MAPSIZE-speed ; ++i ) | 556 | for ( int i = 0 ; i < MAPSIZE-speed ; ++i ) |
557 | { | 557 | { |
558 | mapTop[i] = mapTop[i+speed]; | 558 | mapTop[i] = mapTop[i+speed]; |
559 | mapBottom[i] = mapBottom[i+speed]; | 559 | mapBottom[i] = mapBottom[i+speed]; |
560 | } | 560 | } |
561 | 561 | ||
562 | for ( int i = speed ; i > 0 ; --i ) | 562 | for ( int i = speed ; i > 0 ; --i ) |
563 | setPoint( MAPSIZE-i ); | 563 | setPoint( MAPSIZE-i ); |
564 | } | 564 | } |
565 | 565 | ||
566 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) | 566 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) |
567 | { | 567 | { |
568 | if ( blocks[i].y() != -1 ) | 568 | if ( blocks[i].y() != -1 ) |
569 | { | 569 | { |
570 | blocks[i].moveBy( -speed, 0 ); | 570 | blocks[i].moveBy( -speed, 0 ); |
571 | if ( blocks[i].x() + blocks[i].width() < 0 ) | 571 | if ( blocks[i].x() + blocks[i].width() < 0 ) |
572 | blocks[i].setY( -1 ); | 572 | blocks[i].setY( -1 ); |
573 | } | 573 | } |
574 | } | 574 | } |
575 | } | 575 | } |
576 | 576 | ||
577 | void SFCave :: addBlock() | 577 | void SFCave :: addBlock() |
578 | { | 578 | { |
579 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) | 579 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) |
580 | { | 580 | { |
581 | if ( blocks[i].y() == -1 ) | 581 | if ( blocks[i].y() == -1 ) |
582 | { | 582 | { |
583 | int x = sWidth; | 583 | int x = sWidth; |
584 | 584 | ||
585 | int y = mapTop[50] + (int)(nextInt(mapBottom[50] - mapTop[50] - blockHeight)); | 585 | int y = mapTop[50] + (int)(nextInt(mapBottom[50] - mapTop[50] - blockHeight)); |
586 | 586 | ||
587 | blocks[i].setRect( x, y, blockWidth, blockHeight ); | 587 | blocks[i].setRect( x, y, blockWidth, blockHeight ); |
588 | 588 | ||
589 | break; | 589 | break; |
590 | } | 590 | } |
591 | } | 591 | } |
592 | } | 592 | } |
593 | 593 | ||
594 | void SFCave :: addGate() | 594 | void SFCave :: addGate() |
595 | { | 595 | { |
596 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) | 596 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) |
597 | { | 597 | { |
598 | if ( blocks[i].y() == -1 ) | 598 | if ( blocks[i].y() == -1 ) |
599 | { | 599 | { |
600 | int x1 = sWidth; | 600 | int x1 = sWidth; |
601 | int y1 = mapTop[50]; | 601 | int y1 = mapTop[50]; |
602 | int b1Height = nextInt(mapBottom[50] - mapTop[50] - gapHeight); | 602 | int b1Height = nextInt(mapBottom[50] - mapTop[50] - gapHeight); |
603 | 603 | ||
604 | // See if height between last gate and this one is too big | 604 | // See if height between last gate and this one is too big |
605 | if ( b1Height - 100 > lastGateBottomY ) | 605 | if ( b1Height - 100 > lastGateBottomY ) |
606 | b1Height -= 25; | 606 | b1Height -= 25; |
607 | else if ( b1Height + 100 < lastGateBottomY ) | 607 | else if ( b1Height + 100 < lastGateBottomY ) |
608 | b1Height += 25; | 608 | b1Height += 25; |
609 | lastGateBottomY = b1Height; | 609 | lastGateBottomY = b1Height; |
610 | 610 | ||
611 | 611 | ||
612 | int x2 = sWidth; | 612 | int x2 = sWidth; |
613 | int y2 = y1 + b1Height + gapHeight; | 613 | int y2 = y1 + b1Height + gapHeight; |
614 | int b2Height = mapBottom[50] - y2; | 614 | int b2Height = mapBottom[50] - y2; |
615 | 615 | ||
616 | 616 | ||
617 | blocks[i].setRect( x1, y1, blockWidth, b1Height ); | 617 | blocks[i].setRect( x1, y1, blockWidth, b1Height ); |
618 | blocks[i+1].setRect( x2, y2, blockWidth, b2Height ); | 618 | blocks[i+1].setRect( x2, y2, blockWidth, b2Height ); |
619 | 619 | ||
620 | break; | 620 | break; |
621 | } | 621 | } |
622 | } | 622 | } |
623 | } | 623 | } |
624 | 624 | ||
625 | void SFCave :: setPoint( int point ) | 625 | void SFCave :: setPoint( int point ) |
626 | { | 626 | { |
627 | if ( nextInt(100) >= 80 ) | 627 | if ( nextInt(100) >= 80 ) |
628 | dir *= -1; | 628 | dir *= -1; |
629 | 629 | ||
630 | mapTop[point] = mapTop[point-1] + (dir * nextInt( 5 ) ); | 630 | mapTop[point] = mapTop[point-1] + (dir * nextInt( 5 ) ); |
631 | if ( mapTop[point] < 0 ) | 631 | if ( mapTop[point] < 0 ) |
632 | { | 632 | { |
633 | mapTop[point] = 0; | 633 | mapTop[point] = 0; |
634 | dir *= -1; | 634 | dir *= -1; |
635 | } | 635 | } |
636 | else if ( mapTop[point] >= maxHeight ) | 636 | else if ( mapTop[point] >= maxHeight ) |
637 | { | 637 | { |
638 | mapTop[point] = maxHeight; | 638 | mapTop[point] = maxHeight; |
639 | dir *= -1; | 639 | dir *= -1; |
640 | } | 640 | } |
641 | 641 | ||
642 | // mapBottom[point] = sHeight - (maxHeight - mapBottom[point]); | 642 | // mapBottom[point] = sHeight - (maxHeight - mapBottom[point]); |
643 | mapBottom[point] = sHeight - (maxHeight - mapTop[point]); | 643 | mapBottom[point] = sHeight - (maxHeight - mapTop[point]); |
644 | } | 644 | } |
645 | 645 | ||
646 | void SFCave :: drawBoss() | 646 | void SFCave :: drawBoss() |
647 | { | 647 | { |
648 | offscreen->fill( Qt::black ); | 648 | offscreen->fill( Qt::black ); |
649 | 649 | ||
650 | bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); | 650 | bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); |
651 | } | 651 | } |
652 | 652 | ||
653 | void SFCave :: draw() | 653 | void SFCave :: draw() |
654 | { | 654 | { |
655 | //printf( "Paint\n" ); | 655 | //printf( "Paint\n" ); |
656 | offscreen->fill( Qt::black ); | 656 | offscreen->fill( Qt::black ); |
657 | 657 | ||
658 | QPainter p( offscreen ); | 658 | QPainter p( offscreen ); |
659 | QFontMetrics fm = p.fontMetrics(); | 659 | QFontMetrics fm = p.fontMetrics(); |
660 | p.setPen( Qt::white ); | 660 | p.setPen( Qt::white ); |
661 | 661 | ||
662 | for ( int i = 0 ; i < MAPSIZE -3; ++i ) | 662 | for ( int i = 0 ; i < MAPSIZE -3; ++i ) |
663 | { | 663 | { |
664 | // Only display top landscape if not running FLY_GAME | 664 | // Only display top landscape if not running FLY_GAME |
665 | if ( CURRENT_GAME_TYPE != FLY_GAME ) | 665 | if ( CURRENT_GAME_TYPE != FLY_GAME ) |
666 | p.drawLine( (i*segSize) - (offset*speed), mapTop[i], ((i+1)*segSize)-(offset*speed), mapTop[i+1] ); | 666 | p.drawLine( (i*segSize) - (offset*speed), mapTop[i], ((i+1)*segSize)-(offset*speed), mapTop[i+1] ); |
667 | 667 | ||
668 | p.drawLine( (i*segSize) - (offset*speed), mapBottom[i], ((i+1)*segSize)-(offset*speed), mapBottom[i+1] ); | 668 | p.drawLine( (i*segSize) - (offset*speed), mapBottom[i], ((i+1)*segSize)-(offset*speed), mapBottom[i+1] ); |
669 | 669 | ||
670 | if ( CURRENT_GAME_TYPE == FLY_GAME && showScoreZones ) | 670 | if ( CURRENT_GAME_TYPE == FLY_GAME && showScoreZones ) |
671 | { | 671 | { |
672 | p.setPen( Qt::blue ); | 672 | p.setPen( Qt::blue ); |
673 | for ( int j = 1 ; j < 10 && FLYSCORES( j, 0 ) != -1 ; ++j ) | 673 | for ( int j = 1 ; j < 10 && FLYSCORES( j, 0 ) != -1 ; ++j ) |
674 | { | 674 | { |
675 | if ( FLYSCORES( j, 2 ) < 0 ) | 675 | if ( FLYSCORES( j, 2 ) < 0 ) |
676 | p.setPen( Qt::red ); | 676 | p.setPen( Qt::red ); |
677 | 677 | ||
678 | p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-FLYSCORES( j, 0 ), ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-FLYSCORES( j, 0 ) ); | 678 | p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-FLYSCORES( j, 0 ), ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-FLYSCORES( j, 0 ) ); |
679 | } | 679 | } |
680 | 680 | ||
681 | p.setPen( Qt::white ); | 681 | p.setPen( Qt::white ); |
682 | } | 682 | } |
683 | } | 683 | } |
684 | 684 | ||
685 | // Uncomment this to show user segment (usful for checking collision boundary with landscape | 685 | // Uncomment this to show user segment (usful for checking collision boundary with landscape |
686 | // p.setPen( Qt::red ); | 686 | // p.setPen( Qt::red ); |
687 | // p.drawLine( (11*segSize) - (offset*speed), 0, ((11)*segSize)-(offset*speed), sHeight ); | 687 | // p.drawLine( (11*segSize) - (offset*speed), 0, ((11)*segSize)-(offset*speed), sHeight ); |
688 | // p.setPen( Qt::white ); | 688 | // p.setPen( Qt::white ); |
689 | 689 | ||
690 | // Draw user | 690 | // Draw user |
691 | p.drawRect( user ); | 691 | p.drawRect( user ); |
692 | 692 | ||
693 | // Draw trails | 693 | // Draw trails |
694 | for ( int i = 0 ; i < TRAILSIZE ; ++i ) | 694 | for ( int i = 0 ; i < TRAILSIZE ; ++i ) |
695 | if ( trail[i].x() >= 0 ) | 695 | if ( trail[i].x() >= 0 ) |
696 | { | 696 | { |
697 | if ( showEyeCandy ) | 697 | if ( showEyeCandy ) |
698 | p.setPen( Qt::white.light((int)(100.0-3*(user.x()/100.0)* (user.x()-trail[i].x())) ) ); | 698 | p.setPen( Qt::white.light((int)(100.0-3*(user.x()/100.0)* (user.x()-trail[i].x())) ) ); |
699 | p.drawRect( trail[i].x(), trail[i].y(), 2, 2 ); | 699 | p.drawRect( trail[i].x(), trail[i].y(), 2, 2 ); |
700 | } | 700 | } |
701 | 701 | ||
702 | p.setPen( Qt::white ); | 702 | p.setPen( Qt::white ); |
703 | // Draw blocks | 703 | // Draw blocks |
704 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) | 704 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) |
705 | if ( blocks[i].y() != -1 ) | 705 | if ( blocks[i].y() != -1 ) |
706 | { | 706 | { |
707 | p.fillRect( blocks[i], Qt::black ); | 707 | p.fillRect( blocks[i], Qt::black ); |
708 | p.drawRect( blocks[i] ); | 708 | p.drawRect( blocks[i] ); |
709 | } | 709 | } |
710 | 710 | ||
711 | // draw score | 711 | // draw score |
712 | QString s; | 712 | QString s; |
713 | s.sprintf( "score %06d high score %06d", score, highestScore[currentGameType][currentGameDifficulty] ); | 713 | s.sprintf( "score %06d high score %06d", score, highestScore[currentGameType][currentGameDifficulty] ); |
714 | p.drawText( 5, 10, s ); | 714 | p.drawText( 5, 10, s ); |
715 | 715 | ||
716 | 716 | ||
717 | if ( state == STATE_CRASHING || state == STATE_CRASHED ) | 717 | if ( state == STATE_CRASHING || state == STATE_CRASHED ) |
718 | { | 718 | { |
719 | // add next crash line | 719 | // add next crash line |
720 | 720 | ||
721 | if ( crashLineLength != -1 ) | 721 | if ( crashLineLength != -1 ) |
722 | { | 722 | { |
723 | for ( int i = 0 ; i < 36 ; ++i ) | 723 | for ( int i = 0 ; i < 36 ; ++i ) |
724 | { | 724 | { |
725 | int x = (int)(user.x() + (crashLineLength+nextInt(10)) * cos( (M_PI/180) * (10.0 * i) ) ); | 725 | int x = (int)(user.x() + (crashLineLength+nextInt(10)) * cos( (M_PI/180) * (10.0 * i) ) ); |
726 | int y = (int)(user.y() + (crashLineLength+nextInt(10)) * sin( (M_PI/180) * (10.0 * i) ) ); p.drawLine( user.x(), user.y(), x, y ); | 726 | int y = (int)(user.y() + (crashLineLength+nextInt(10)) * sin( (M_PI/180) * (10.0 * i) ) ); p.drawLine( user.x(), user.y(), x, y ); |
727 | } | 727 | } |
728 | } | 728 | } |
729 | 729 | ||
730 | if ( state == STATE_CRASHING && crashLineLength >= 15 ) //|| crashLineLength == -1) ) | 730 | if ( state == STATE_CRASHING && crashLineLength >= 15 ) //|| crashLineLength == -1) ) |
731 | state = STATE_CRASHED; | 731 | state = STATE_CRASHED; |
732 | 732 | ||
733 | if ( state == STATE_CRASHED ) | 733 | if ( state == STATE_CRASHED ) |
734 | { | 734 | { |
735 | QString text = "Press up or down to start"; | 735 | QString text = "Press up or down to start"; |
736 | p.drawText( (sWidth/2) - (fm.width( text )/2), 120, text ); | 736 | p.drawText( (sWidth/2) - (fm.width( text )/2), 120, text ); |
737 | 737 | ||
738 | text = "Press OK for menu"; | 738 | text = "Press OK for menu"; |
739 | p.drawText( (sWidth/2) - (fm.width( text )/2), 135, text ); | 739 | p.drawText( (sWidth/2) - (fm.width( text )/2), 135, text ); |
740 | /* | 740 | /* |
741 | text = "Press r to replay"; | 741 | text = "Press r to replay"; |
742 | p.drawText( (sWidth/2) - (fm.width( text )/2), 150, text ); | 742 | p.drawText( (sWidth/2) - (fm.width( text )/2), 150, text ); |
743 | 743 | ||
744 | text = "Press s to save the replay"; | 744 | text = "Press s to save the replay"; |
745 | p.drawText( (sWidth/2) - (fm.width( text )/2), 165, text ); | 745 | p.drawText( (sWidth/2) - (fm.width( text )/2), 165, text ); |
746 | 746 | ||
747 | text = "Press r to load a saved replay"; | 747 | text = "Press r to load a saved replay"; |
748 | p.drawText( (sWidth/2) - (fm.width( text )/2), 180, text ); | 748 | p.drawText( (sWidth/2) - (fm.width( text )/2), 180, text ); |
749 | */ | 749 | */ |
750 | } | 750 | } |
751 | else | 751 | else |
752 | crashLineLength ++; | 752 | crashLineLength ++; |
753 | } | 753 | } |
754 | 754 | ||
755 | p.end(); | 755 | p.end(); |
756 | bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); | 756 | bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); |
757 | //printf( "endpaint\n" ); | 757 | //printf( "endpaint\n" ); |
758 | } | 758 | } |
759 | 759 | ||
760 | void SFCave :: handleKeys() | 760 | void SFCave :: handleKeys() |
761 | { | 761 | { |
762 | // Find enpty trail and move others | 762 | // Find enpty trail and move others |
763 | bool done = false; | 763 | bool done = false; |
764 | for ( int i = 0 ; i < TRAILSIZE ; ++i ) | 764 | for ( int i = 0 ; i < TRAILSIZE ; ++i ) |
765 | { | 765 | { |
766 | if ( trail[i].x() < 0 ) | 766 | if ( trail[i].x() < 0 ) |
767 | { | 767 | { |
768 | if ( !done ) | 768 | if ( !done ) |
769 | { | 769 | { |
770 | trail[i].setX( user.x() - 5 ); | 770 | trail[i].setX( user.x() - 5 ); |
771 | trail[i].setY( user.y() ); | 771 | trail[i].setY( user.y() ); |
772 | done = true; | 772 | done = true; |
773 | } | 773 | } |
774 | } | 774 | } |
775 | else | 775 | else |
776 | { | 776 | { |
777 | trail[i].setX( trail[i].x() - (2) ); | 777 | trail[i].setX( trail[i].x() - (2) ); |
778 | } | 778 | } |
779 | } | 779 | } |
780 | 780 | ||
781 | if ( speed <= 3 ) | 781 | if ( speed <= 3 ) |
782 | { | 782 | { |
783 | if ( press ) | 783 | if ( press ) |
784 | thrust -= thrustUp; | 784 | thrust -= thrustUp; |
785 | else | 785 | else |
786 | thrust += noThrust; | 786 | thrust += noThrust; |
787 | 787 | ||
788 | if ( thrust > maxDownThrust ) | 788 | if ( thrust > maxDownThrust ) |
789 | thrust = maxDownThrust; | 789 | thrust = maxDownThrust; |
790 | else if ( thrust < maxUpThrust ) | 790 | else if ( thrust < maxUpThrust ) |
791 | thrust = maxUpThrust; | 791 | thrust = maxUpThrust; |
792 | } | 792 | } |
793 | else | 793 | else |
794 | { | 794 | { |
795 | if ( press ) | 795 | if ( press ) |
796 | thrust -= 0.5; | 796 | thrust -= 0.5; |
797 | else | 797 | else |
798 | thrust += 0.8; | 798 | thrust += 0.8; |
799 | 799 | ||
800 | if ( thrust > 5.0 ) | 800 | if ( thrust > 5.0 ) |
801 | thrust = 5.0; | 801 | thrust = 5.0; |
802 | else if ( thrust < -3.5 ) | 802 | else if ( thrust < -3.5 ) |
803 | thrust = -3.5; | 803 | thrust = -3.5; |
804 | } | 804 | } |
805 | user.moveBy( 0, (int)thrust ); | 805 | user.moveBy( 0, (int)thrust ); |
806 | } | 806 | } |
807 | 807 | ||
808 | void SFCave :: keyPressEvent( QKeyEvent *e ) | 808 | void SFCave :: keyPressEvent( QKeyEvent *e ) |
809 | { | 809 | { |
810 | if ( state == STATE_MENU ) | 810 | if ( state == STATE_MENU ) |
811 | handleMenuKeys( e ); | 811 | handleMenuKeys( e ); |
812 | else | 812 | else |
813 | { | 813 | { |
814 | switch( e->key() ) | 814 | switch( e->key() ) |
815 | { | 815 | { |
816 | case Qt::Key_Up: | 816 | case Qt::Key_Up: |
817 | case Qt::Key_F9: | 817 | case Qt::Key_F9: |
818 | case Qt::Key_Space: | 818 | case Qt::Key_Space: |
819 | if ( state == STATE_RUNNING ) | 819 | if ( state == STATE_RUNNING ) |
820 | { | 820 | { |
821 | if ( !replay && !press ) | 821 | if ( !replay && !press ) |
822 | { | 822 | { |
823 | press = true; | 823 | press = true; |
824 | replayList.append( new int( nrFrames ) ); | 824 | replayList.append( new int( nrFrames ) ); |
825 | } | 825 | } |
826 | } | 826 | } |
827 | else if ( state == STATE_CRASHED ) | 827 | else if ( state == STATE_CRASHED ) |
828 | { | 828 | { |
829 | if ( e->key() == Key_Up ) | 829 | if ( e->key() == Key_Up ) |
830 | state = STATE_NEWGAME; | 830 | state = STATE_NEWGAME; |
831 | } | 831 | } |
832 | 832 | ||
833 | break; | 833 | break; |
834 | case Qt::Key_M: | 834 | case Qt::Key_M: |
835 | case Qt::Key_Return: | 835 | case Qt::Key_Return: |
836 | case Qt::Key_Enter: | 836 | case Qt::Key_Enter: |
837 | if ( state == STATE_CRASHED ) | 837 | if ( state == STATE_CRASHED ) |
838 | { | 838 | { |
839 | state = STATE_MENU; | 839 | state = STATE_MENU; |
840 | currentMenuNr = 0; | 840 | currentMenuNr = 0; |
841 | currentMenuOption[currentMenuNr] = 0; | 841 | currentMenuOption[currentMenuNr] = 0; |
842 | } | 842 | } |
843 | break; | 843 | break; |
844 | 844 | ||
845 | case Qt::Key_Z: | 845 | case Qt::Key_Z: |
846 | showScoreZones = !showScoreZones; | 846 | showScoreZones = !showScoreZones; |
847 | break; | 847 | break; |
848 | 848 | ||
849 | default: | 849 | default: |
850 | e->ignore(); | 850 | e->ignore(); |
851 | break; | 851 | break; |
852 | } | 852 | } |
853 | } | 853 | } |
854 | } | 854 | } |
855 | 855 | ||
856 | void SFCave :: keyReleaseEvent( QKeyEvent *e ) | 856 | void SFCave :: keyReleaseEvent( QKeyEvent *e ) |
857 | { | 857 | { |
858 | if ( state == STATE_MENU ) | 858 | if ( state == STATE_MENU ) |
859 | { | 859 | { |
860 | } | 860 | } |
861 | else | 861 | else |
862 | { | 862 | { |
863 | switch( e->key() ) | 863 | switch( e->key() ) |
864 | { | 864 | { |
865 | case Qt::Key_F9: | 865 | case Qt::Key_F9: |
866 | case Qt::Key_Space: | 866 | case Qt::Key_Space: |
867 | case Qt::Key_Up: | 867 | case Qt::Key_Up: |
868 | if ( state == STATE_RUNNING ) | 868 | if ( state == STATE_RUNNING ) |
869 | { | 869 | { |
870 | if ( !replay && press ) | 870 | if ( !replay && press ) |
871 | { | 871 | { |
872 | press = false; | 872 | press = false; |
873 | replayList.append( new int( nrFrames ) ); | 873 | replayList.append( new int( nrFrames ) ); |
874 | } | 874 | } |
875 | } | 875 | } |
876 | break; | 876 | break; |
877 | 877 | ||
878 | case Qt::Key_E: | 878 | case Qt::Key_E: |
879 | showEyeCandy = !showEyeCandy; | 879 | showEyeCandy = !showEyeCandy; |
880 | break; | 880 | break; |
881 | 881 | ||
882 | case Qt::Key_R: | 882 | case Qt::Key_R: |
883 | if ( state == STATE_CRASHED ) | 883 | if ( state == STATE_CRASHED ) |
884 | state = STATE_REPLAY; | 884 | state = STATE_REPLAY; |
885 | break; | 885 | break; |
886 | 886 | ||
887 | case Qt::Key_Down: | 887 | case Qt::Key_Down: |
888 | if ( state == STATE_CRASHED ) | 888 | if ( state == STATE_CRASHED ) |
889 | state = STATE_NEWGAME; | 889 | state = STATE_NEWGAME; |
890 | break; | 890 | break; |
891 | 891 | ||
892 | case Qt::Key_S: | 892 | case Qt::Key_S: |
893 | if ( state == STATE_CRASHED ) | 893 | if ( state == STATE_CRASHED ) |
894 | saveReplay(); | 894 | saveReplay(); |
895 | break; | 895 | break; |
896 | 896 | ||
897 | case Qt::Key_L: | 897 | case Qt::Key_L: |
898 | if ( state == STATE_CRASHED ) | 898 | if ( state == STATE_CRASHED ) |
899 | loadReplay(); | 899 | loadReplay(); |
900 | break; | 900 | break; |
901 | default: | 901 | default: |
902 | e->ignore(); | 902 | e->ignore(); |
903 | break; | 903 | break; |
904 | } | 904 | } |
905 | } | 905 | } |
906 | 906 | ||
907 | } | 907 | } |
908 | 908 | ||
909 | 909 | ||
910 | void SFCave :: saveScore() | 910 | void SFCave :: saveScore() |
911 | { | 911 | { |
912 | #ifdef QWS | 912 | #ifdef QWS |
913 | Config cfg( "sfcave" ); | 913 | Config cfg( "sfcave" ); |
914 | cfg.setGroup( "settings" ); | 914 | cfg.setGroup( "settings" ); |
915 | QString key = "highScore_"; | 915 | QString key = "highScore_"; |
916 | 916 | ||
917 | cfg.writeEntry( key + gameTypes[currentGameType] + "_" + dificultyOption[currentGameDifficulty], highestScore[currentGameType][currentGameDifficulty] ); | 917 | cfg.writeEntry( key + gameTypes[currentGameType] + "_" + dificultyOption[currentGameDifficulty], highestScore[currentGameType][currentGameDifficulty] ); |
918 | key += CURRENT_GAME_TYPE; | 918 | key += CURRENT_GAME_TYPE; |
919 | cfg.writeEntry( key, highestScore[currentGameType] ); | 919 | cfg.writeEntry( key, highestScore[currentGameType] ); |
920 | #endif | 920 | #endif |
921 | } | 921 | } |
922 | 922 | ||
923 | void SFCave :: saveReplay() | 923 | void SFCave :: saveReplay() |
924 | { | 924 | { |
925 | FILE *out; | 925 | FILE *out; |
926 | out = fopen( QFile::encodeName(replayFile).data(), "w" ); | 926 | out = fopen( QFile::encodeName(replayFile).data(), "w" ); |
927 | if ( !out ) | 927 | if ( !out ) |
928 | { | 928 | { |
929 | printf( "Couldn't write to %s\n", QFile::encodeName(replayFile).data() ); | 929 | printf( "Couldn't write to %s\n", QFile::encodeName(replayFile).data() ); |
930 | return; | 930 | return; |
931 | } | 931 | } |
932 | 932 | ||
933 | // Build up string of values | 933 | // Build up string of values |
934 | // Format is:: <landscape seed> <game type> <difficulty> <framenr> <framenr>....... | 934 | // Format is:: <landscape seed> <game type> <difficulty> <framenr> <framenr>....... |
935 | QString val; | 935 | QString val; |
936 | val.sprintf( "%d %d %d ", currentSeed, currentGameType, currentGameDifficulty ); | 936 | val.sprintf( "%d %d %d ", currentSeed, currentGameType, currentGameDifficulty ); |
937 | 937 | ||
938 | QListIterator<int> it( replayList ); | 938 | QListIterator<int> it( replayList ); |
939 | while( it.current() ) | 939 | while( it.current() ) |
940 | { | 940 | { |
941 | QString tmp; | 941 | QString tmp; |
942 | tmp.sprintf( "%d ", (*it.current()) ); | 942 | tmp.sprintf( "%d ", (*it.current()) ); |
943 | val += tmp; | 943 | val += tmp; |
944 | 944 | ||
945 | ++it; | 945 | ++it; |
946 | } | 946 | } |
947 | val += "\n"; | 947 | val += "\n"; |
948 | 948 | ||
949 | QString line; | 949 | QString line; |
950 | line.sprintf( "%d\n", val.length() ); | 950 | line.sprintf( "%d\n", val.length() ); |
951 | fwrite( (const char *)line, 1, line.length(), out ); | 951 | fwrite( (const char *)line, 1, line.length(), out ); |
952 | 952 | ||
953 | fwrite( (const char *)val, 1, val.length(), out ); | 953 | fwrite( (const char *)val, 1, val.length(), out ); |
954 | 954 | ||
955 | fclose( out ); | 955 | fclose( out ); |
956 | 956 | ||
957 | printf( "Replay saved to %s\n", QFile::encodeName(replayFile).data() ); | 957 | printf( "Replay saved to %s\n", QFile::encodeName(replayFile).data() ); |
958 | 958 | ||
959 | } | 959 | } |
960 | 960 | ||
961 | void SFCave :: loadReplay() | 961 | void SFCave :: loadReplay() |
962 | { | 962 | { |
963 | FILE *in = fopen( QFile::encodeName(replayFile).data() , "r" ); | 963 | FILE *in = fopen( QFile::encodeName(replayFile).data() , "r" ); |
964 | 964 | ||
965 | if ( in == 0 ) | 965 | if ( in == 0 ) |
966 | { | 966 | { |
967 | printf( "Couldn't load replay file!\n" ); | 967 | printf( "Couldn't load replay file!\n" ); |
968 | return; | 968 | return; |
969 | } | 969 | } |
970 | 970 | ||
971 | // Read next line - contains the size of the options | 971 | // Read next line - contains the size of the options |
972 | char line[10+1]; | 972 | char line[10+1]; |
973 | fgets( line, 10, in ); | 973 | fgets( line, 10, in ); |
974 | 974 | ||
975 | int length = -1; | 975 | int length = -1; |
976 | sscanf( line, "%d", &length ); | 976 | sscanf( line, "%d", &length ); |
977 | char *data = new char[length+1]; | 977 | char *data = new char[length+1]; |
978 | 978 | ||
979 | fread( data, 1, length, in ); | 979 | fread( data, 1, length, in ); |
980 | // printf( "data - %s", data ); | 980 | // printf( "data - %s", data ); |
981 | 981 | ||
982 | QString sep = " "; | 982 | QString sep = " "; |
983 | QStringList list = QStringList::split( sep, QString( data ) ); | 983 | QStringList list = QStringList::split( sep, QString( data ) ); |
984 | 984 | ||
985 | // print it out | 985 | // print it out |
986 | QStringList::Iterator it = list.begin(); | 986 | QStringList::Iterator it = list.begin(); |
987 | currentSeed = (*it).toInt(); | 987 | currentSeed = (*it).toInt(); |
988 | ++it; | 988 | ++it; |
989 | currentGameType = (*it).toInt(); | 989 | currentGameType = (*it).toInt(); |
990 | ++it; | 990 | ++it; |
991 | currentGameDifficulty = (*it).toInt(); | 991 | currentGameDifficulty = (*it).toInt(); |
992 | ++it; | 992 | ++it; |
993 | 993 | ||
994 | replayList.clear(); | 994 | replayList.clear(); |
995 | for ( ; it != list.end(); ++it ) | 995 | for ( ; it != list.end(); ++it ) |
996 | { | 996 | { |
997 | int v = (*it).toInt(); | 997 | int v = (*it).toInt(); |
998 | replayList.append( new int( v ) ); | 998 | replayList.append( new int( v ) ); |
999 | } | 999 | } |
1000 | 1000 | ||
1001 | delete data; | 1001 | delete [] data; |
1002 | 1002 | ||
1003 | fclose( in ); | 1003 | fclose( in ); |
1004 | 1004 | ||
1005 | printf( "Replay loaded from %s\n", QFile::encodeName(replayFile).data() ); | 1005 | printf( "Replay loaded from %s\n", QFile::encodeName(replayFile).data() ); |
1006 | } | 1006 | } |
1007 | 1007 | ||
1008 | 1008 | ||
1009 | //--------------- MENU CODE --------------------- | 1009 | //--------------- MENU CODE --------------------- |
1010 | void SFCave :: handleMenuKeys( QKeyEvent *e ) | 1010 | void SFCave :: handleMenuKeys( QKeyEvent *e ) |
1011 | { | 1011 | { |
1012 | switch( e->key() ) | 1012 | switch( e->key() ) |
1013 | { | 1013 | { |
1014 | case Qt::Key_Down: | 1014 | case Qt::Key_Down: |
1015 | currentMenuOption[currentMenuNr] ++; | 1015 | currentMenuOption[currentMenuNr] ++; |
1016 | if ( menuOptions[currentMenuNr][currentMenuOption[currentMenuNr]] == "" ) | 1016 | if ( menuOptions[currentMenuNr][currentMenuOption[currentMenuNr]] == "" ) |
1017 | currentMenuOption[currentMenuNr] = 0; | 1017 | currentMenuOption[currentMenuNr] = 0; |
1018 | break; | 1018 | break; |
1019 | case Qt::Key_Up: | 1019 | case Qt::Key_Up: |
1020 | currentMenuOption[currentMenuNr] --; | 1020 | currentMenuOption[currentMenuNr] --; |
1021 | if ( currentMenuOption[currentMenuNr] < 0 ) | 1021 | if ( currentMenuOption[currentMenuNr] < 0 ) |
1022 | currentMenuOption[currentMenuNr] = nrMenuOptions[currentMenuNr]-1; | 1022 | currentMenuOption[currentMenuNr] = nrMenuOptions[currentMenuNr]-1; |
1023 | break; | 1023 | break; |
1024 | 1024 | ||
1025 | case Qt::Key_Left: | 1025 | case Qt::Key_Left: |
1026 | if ( currentMenuNr == MENU_OPTIONS_MENU ) | 1026 | if ( currentMenuNr == MENU_OPTIONS_MENU ) |
1027 | { | 1027 | { |
1028 | if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE ) | 1028 | if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE ) |
1029 | { | 1029 | { |
1030 | currentGameType --; | 1030 | currentGameType --; |
1031 | if ( currentGameType < 0 ) | 1031 | if ( currentGameType < 0 ) |
1032 | currentGameType = NR_GAME_TYPES - 1; | 1032 | currentGameType = NR_GAME_TYPES - 1; |
1033 | } | 1033 | } |
1034 | else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY ) | 1034 | else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY ) |
1035 | { | 1035 | { |
1036 | currentGameDifficulty --; | 1036 | currentGameDifficulty --; |
1037 | if ( currentGameDifficulty < 0 ) | 1037 | if ( currentGameDifficulty < 0 ) |
1038 | currentGameDifficulty = NR_GAME_DIFFICULTIES - 1; | 1038 | currentGameDifficulty = NR_GAME_DIFFICULTIES - 1; |
1039 | } | 1039 | } |
1040 | } | 1040 | } |
1041 | break; | 1041 | break; |
1042 | 1042 | ||
1043 | case Qt::Key_Right: | 1043 | case Qt::Key_Right: |
1044 | if ( currentMenuNr == MENU_OPTIONS_MENU ) | 1044 | if ( currentMenuNr == MENU_OPTIONS_MENU ) |
1045 | { | 1045 | { |
1046 | if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE ) | 1046 | if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE ) |
1047 | { | 1047 | { |
1048 | currentGameType ++; | 1048 | currentGameType ++; |
1049 | if ( currentGameType == NR_GAME_TYPES ) | 1049 | if ( currentGameType == NR_GAME_TYPES ) |
1050 | currentGameType = 0; | 1050 | currentGameType = 0; |
1051 | } | 1051 | } |
1052 | else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY ) | 1052 | else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY ) |
1053 | { | 1053 | { |
1054 | currentGameDifficulty ++; | 1054 | currentGameDifficulty ++; |
1055 | if ( currentGameDifficulty == NR_GAME_DIFFICULTIES ) | 1055 | if ( currentGameDifficulty == NR_GAME_DIFFICULTIES ) |
1056 | currentGameDifficulty = 0; | 1056 | currentGameDifficulty = 0; |
1057 | } | 1057 | } |
1058 | } | 1058 | } |
1059 | break; | 1059 | break; |
1060 | 1060 | ||
1061 | case Qt::Key_Space: | 1061 | case Qt::Key_Space: |
1062 | case Qt::Key_Return: | 1062 | case Qt::Key_Return: |
1063 | case Qt::Key_Enter: | 1063 | case Qt::Key_Enter: |
1064 | dealWithMenuSelection(); | 1064 | dealWithMenuSelection(); |
1065 | break; | 1065 | break; |
1066 | } | 1066 | } |
1067 | } | 1067 | } |
1068 | 1068 | ||
1069 | void SFCave :: displayMenu() | 1069 | void SFCave :: displayMenu() |
1070 | { | 1070 | { |
1071 | offscreen->fill( Qt::black ); | 1071 | offscreen->fill( Qt::black ); |
1072 | 1072 | ||
1073 | QPainter p( offscreen ); | 1073 | QPainter p( offscreen ); |
1074 | p.setPen( Qt::white ); | 1074 | p.setPen( Qt::white ); |
1075 | 1075 | ||
1076 | QFont f( "Helvetica", 16 ); | 1076 | QFont f( "Helvetica", 16 ); |
1077 | p.setFont( f ); | 1077 | p.setFont( f ); |
1078 | 1078 | ||
1079 | QFontMetrics fm = p.fontMetrics(); | 1079 | QFontMetrics fm = p.fontMetrics(); |
1080 | 1080 | ||
1081 | QString text = "SFCave"; | 1081 | QString text = "SFCave"; |
1082 | p.drawText( (sWidth/2) - (fm.width( text )/2), 60, text ); | 1082 | p.drawText( (sWidth/2) - (fm.width( text )/2), 60, text ); |
1083 | 1083 | ||
1084 | text = "Written by Andy Qua"; | 1084 | text = "Written by Andy Qua"; |
1085 | p.drawText( (sWidth/2) - (fm.width( text )/2), 85, text ); | 1085 | p.drawText( (sWidth/2) - (fm.width( text )/2), 85, text ); |
1086 | 1086 | ||
1087 | // Draw options | 1087 | // Draw options |
1088 | int pos = 140; | 1088 | int pos = 140; |
1089 | for ( int i = 0 ; menuOptions[currentMenuNr][i] != "" ; ++i, pos += 25 ) | 1089 | for ( int i = 0 ; menuOptions[currentMenuNr][i] != "" ; ++i, pos += 25 ) |
1090 | { | 1090 | { |
1091 | if ( currentMenuOption[currentMenuNr] == i ) | 1091 | if ( currentMenuOption[currentMenuNr] == i ) |
1092 | p.setPen( Qt::yellow ); | 1092 | p.setPen( Qt::yellow ); |
1093 | else | 1093 | else |
1094 | p.setPen( Qt::white ); | 1094 | p.setPen( Qt::white ); |
1095 | 1095 | ||
1096 | QString text; | 1096 | QString text; |
1097 | if ( menuOptions[currentMenuNr][i].find( "%s" ) != -1 ) | 1097 | if ( menuOptions[currentMenuNr][i].find( "%s" ) != -1 ) |
1098 | { | 1098 | { |
1099 | QString val; | 1099 | QString val; |
1100 | if ( i == MENU_GAME_TYPE ) | 1100 | if ( i == MENU_GAME_TYPE ) |
1101 | val = gameTypes[currentGameType]; | 1101 | val = gameTypes[currentGameType]; |
1102 | else | 1102 | else |
1103 | val = dificultyOption[currentGameDifficulty]; | 1103 | val = dificultyOption[currentGameDifficulty]; |
1104 | 1104 | ||
1105 | text.sprintf( (const char *)menuOptions[currentMenuNr][i], (const char *)val ); | 1105 | text.sprintf( (const char *)menuOptions[currentMenuNr][i], (const char *)val ); |
1106 | } | 1106 | } |
1107 | else | 1107 | else |
1108 | text = menuOptions[currentMenuNr][i]; | 1108 | text = menuOptions[currentMenuNr][i]; |
1109 | 1109 | ||
1110 | p.drawText( (sWidth/2) - (fm.width( text )/2), pos, text ); | 1110 | p.drawText( (sWidth/2) - (fm.width( text )/2), pos, text ); |
1111 | } | 1111 | } |
1112 | 1112 | ||
1113 | p.end(); | 1113 | p.end(); |
1114 | bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); | 1114 | bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); |
1115 | } | 1115 | } |
1116 | 1116 | ||
1117 | void SFCave :: dealWithMenuSelection() | 1117 | void SFCave :: dealWithMenuSelection() |
1118 | { | 1118 | { |
1119 | switch( currentMenuNr ) | 1119 | switch( currentMenuNr ) |
1120 | { | 1120 | { |
1121 | case MENU_MAIN_MENU: | 1121 | case MENU_MAIN_MENU: |
1122 | { | 1122 | { |
1123 | switch( currentMenuOption[currentMenuNr] ) | 1123 | switch( currentMenuOption[currentMenuNr] ) |
1124 | { | 1124 | { |
1125 | case MENU_START_GAME: | 1125 | case MENU_START_GAME: |
1126 | state = STATE_NEWGAME; | 1126 | state = STATE_NEWGAME; |
1127 | break; | 1127 | break; |
1128 | 1128 | ||
1129 | case MENU_REPLAY: | 1129 | case MENU_REPLAY: |
1130 | currentMenuNr = MENU_REPLAY_MENU; | 1130 | currentMenuNr = MENU_REPLAY_MENU; |
1131 | currentMenuOption[currentMenuNr] = 0; | 1131 | currentMenuOption[currentMenuNr] = 0; |
1132 | break; | 1132 | break; |
1133 | 1133 | ||
1134 | case MENU_OPTIONS: | 1134 | case MENU_OPTIONS: |
1135 | currentMenuNr = MENU_OPTIONS_MENU; | 1135 | currentMenuNr = MENU_OPTIONS_MENU; |
1136 | currentMenuOption[currentMenuNr] = 0; | 1136 | currentMenuOption[currentMenuNr] = 0; |
1137 | break; | 1137 | break; |
1138 | 1138 | ||
1139 | case MENU_HELP: | 1139 | case MENU_HELP: |
1140 | { | 1140 | { |
1141 | // Display Help Menu | 1141 | // Display Help Menu |
1142 | HelpWindow *win = new HelpWindow( ); | 1142 | HelpWindow *win = new HelpWindow( ); |
1143 | QPEApplication::showWidget( win ); | 1143 | QPEApplication::showWidget( win ); |
1144 | break; | 1144 | break; |
1145 | } | 1145 | } |
1146 | 1146 | ||
1147 | case MENU_QUIT: | 1147 | case MENU_QUIT: |
1148 | QApplication::exit(); | 1148 | QApplication::exit(); |
1149 | break; | 1149 | break; |
1150 | } | 1150 | } |
1151 | 1151 | ||
1152 | break; | 1152 | break; |
1153 | } | 1153 | } |
1154 | 1154 | ||
1155 | case MENU_OPTIONS_MENU: | 1155 | case MENU_OPTIONS_MENU: |
1156 | { | 1156 | { |
1157 | switch( currentMenuOption[currentMenuNr] ) | 1157 | switch( currentMenuOption[currentMenuNr] ) |
1158 | { | 1158 | { |
1159 | case MENU_GAME_TYPE: | 1159 | case MENU_GAME_TYPE: |
1160 | break; | 1160 | break; |
1161 | 1161 | ||
1162 | case MENU_GAME_DIFFICULTY: | 1162 | case MENU_GAME_DIFFICULTY: |
1163 | break; | 1163 | break; |
1164 | 1164 | ||
1165 | case MENU_CLEAR_HIGHSCORES: | 1165 | case MENU_CLEAR_HIGHSCORES: |
1166 | for ( int i = 0 ; i < 3 ; ++i ) | 1166 | for ( int i = 0 ; i < 3 ; ++i ) |
1167 | highestScore[currentGameType][i] = 0; | 1167 | highestScore[currentGameType][i] = 0; |
1168 | break; | 1168 | break; |
1169 | 1169 | ||
1170 | case MENU_BACK: | 1170 | case MENU_BACK: |
1171 | currentMenuNr = MENU_MAIN_MENU; | 1171 | currentMenuNr = MENU_MAIN_MENU; |
1172 | 1172 | ||
1173 | #ifdef QWS | 1173 | #ifdef QWS |
1174 | Config cfg( "sfcave" ); | 1174 | Config cfg( "sfcave" ); |
1175 | cfg.setGroup( "settings" ); | 1175 | cfg.setGroup( "settings" ); |
1176 | cfg.writeEntry( "difficulty", currentGameDifficulty ); | 1176 | cfg.writeEntry( "difficulty", currentGameDifficulty ); |
1177 | cfg.writeEntry( "gameType", currentGameType ); | 1177 | cfg.writeEntry( "gameType", currentGameType ); |
1178 | #endif | 1178 | #endif |
1179 | break; | 1179 | break; |
1180 | } | 1180 | } |
1181 | 1181 | ||
1182 | break; | 1182 | break; |
1183 | } | 1183 | } |
1184 | 1184 | ||
1185 | case MENU_REPLAY_MENU: | 1185 | case MENU_REPLAY_MENU: |
1186 | { | 1186 | { |
1187 | switch( currentMenuOption[currentMenuNr] ) | 1187 | switch( currentMenuOption[currentMenuNr] ) |
1188 | { | 1188 | { |
1189 | case MENU_REPLAY_START: | 1189 | case MENU_REPLAY_START: |
1190 | if ( currentSeed != 0 ) | 1190 | if ( currentSeed != 0 ) |
1191 | state = STATE_REPLAY; | 1191 | state = STATE_REPLAY; |
1192 | // Display No Replay | 1192 | // Display No Replay |
1193 | break; | 1193 | break; |
1194 | 1194 | ||
1195 | case MENU_REPLAY_LOAD: | 1195 | case MENU_REPLAY_LOAD: |
1196 | loadReplay(); | 1196 | loadReplay(); |
1197 | break; | 1197 | break; |
1198 | 1198 | ||
1199 | case MENU_REPLAY_SAVE: | 1199 | case MENU_REPLAY_SAVE: |
1200 | saveReplay(); | 1200 | saveReplay(); |
1201 | break; | 1201 | break; |
1202 | 1202 | ||
1203 | case MENU_REPLAY_BACK: | 1203 | case MENU_REPLAY_BACK: |
1204 | currentMenuNr = MENU_MAIN_MENU; | 1204 | currentMenuNr = MENU_MAIN_MENU; |
1205 | break; | 1205 | break; |
1206 | 1206 | ||
1207 | } | 1207 | } |
1208 | } | 1208 | } |
1209 | } | 1209 | } |
1210 | } | 1210 | } |
1211 | 1211 | ||
diff --git a/noncore/settings/aqpkg/settingsimpl.cpp b/noncore/settings/aqpkg/settingsimpl.cpp index 7ffa1d6..0886e69 100644 --- a/noncore/settings/aqpkg/settingsimpl.cpp +++ b/noncore/settings/aqpkg/settingsimpl.cpp | |||
@@ -1,490 +1,490 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the OPIE Project | 2 | This file is part of the OPIE Project |
3 | 3 | ||
4 | =. Copyright (c) 2002 Andy Qua <andy.qua@blueyonder.co.uk> | 4 | =. Copyright (c) 2002 Andy Qua <andy.qua@blueyonder.co.uk> |
5 | .=l. Dan Williams <drw@handhelds.org> | 5 | .=l. Dan Williams <drw@handhelds.org> |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This file is free software; you can | 7 | _;:, .> :=|. This file is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This file is distributed in the hope that | 14 | .i_,=:_. -<s. This file is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General |
19 | ..}^=.= = ; Public License for more details. | 19 | ..}^=.= = ; Public License for more details. |
20 | ++= -. .` .: | 20 | ++= -. .` .: |
21 | : = ...= . :.=- You should have received a copy of the GNU | 21 | : = ...= . :.=- You should have received a copy of the GNU |
22 | -. .:....=;==+<; General Public License along with this file; | 22 | -. .:....=;==+<; General Public License along with this file; |
23 | -_. . . )=. = see the file COPYING. If not, write to the | 23 | -_. . . )=. = see the file COPYING. If not, write to the |
24 | -- :-=` Free Software Foundation, Inc., | 24 | -- :-=` Free Software Foundation, Inc., |
25 | 59 Temple Place - Suite 330, | 25 | 59 Temple Place - Suite 330, |
26 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
27 | 27 | ||
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include "settingsimpl.h" | 30 | #include "settingsimpl.h" |
31 | #include "global.h" | 31 | #include "global.h" |
32 | 32 | ||
33 | /* OPIE */ | 33 | /* OPIE */ |
34 | #include <opie2/otabwidget.h> | 34 | #include <opie2/otabwidget.h> |
35 | #include <opie2/oresource.h> | 35 | #include <opie2/oresource.h> |
36 | #include <qpe/config.h> | 36 | #include <qpe/config.h> |
37 | #include <qpe/qpeapplication.h> | 37 | #include <qpe/qpeapplication.h> |
38 | 38 | ||
39 | /* QT */ | 39 | /* QT */ |
40 | #include <qcheckbox.h> | 40 | #include <qcheckbox.h> |
41 | #include <qgroupbox.h> | 41 | #include <qgroupbox.h> |
42 | #include <qlabel.h> | 42 | #include <qlabel.h> |
43 | #include <qlayout.h> | 43 | #include <qlayout.h> |
44 | #include <qlineedit.h> | 44 | #include <qlineedit.h> |
45 | #include <qlistbox.h> | 45 | #include <qlistbox.h> |
46 | #include <qpushbutton.h> | 46 | #include <qpushbutton.h> |
47 | 47 | ||
48 | using namespace Opie::Ui; | 48 | using namespace Opie::Ui; |
49 | using namespace Opie::Ui; | 49 | using namespace Opie::Ui; |
50 | SettingsImpl :: SettingsImpl( DataManager *dataManager, QWidget * parent, const char* name, bool modal, WFlags fl ) | 50 | SettingsImpl :: SettingsImpl( DataManager *dataManager, QWidget * parent, const char* name, bool modal, WFlags fl ) |
51 | : QDialog( parent, name, modal, fl ) | 51 | : QDialog( parent, name, modal, fl ) |
52 | { | 52 | { |
53 | setCaption( tr( "Configuration" ) ); | 53 | setCaption( tr( "Configuration" ) ); |
54 | 54 | ||
55 | // Setup layout to make everything pretty | 55 | // Setup layout to make everything pretty |
56 | QVBoxLayout *layout = new QVBoxLayout( this ); | 56 | QVBoxLayout *layout = new QVBoxLayout( this ); |
57 | layout->setMargin( 2 ); | 57 | layout->setMargin( 2 ); |
58 | layout->setSpacing( 4 ); | 58 | layout->setSpacing( 4 ); |
59 | 59 | ||
60 | // Setup tabs for all info | 60 | // Setup tabs for all info |
61 | OTabWidget *tabwidget = new OTabWidget( this ); | 61 | OTabWidget *tabwidget = new OTabWidget( this ); |
62 | layout->addWidget( tabwidget ); | 62 | layout->addWidget( tabwidget ); |
63 | 63 | ||
64 | tabwidget->addTab( initServerTab(), "aqpkg/servertab", tr( "Servers" ) ); | 64 | tabwidget->addTab( initServerTab(), "aqpkg/servertab", tr( "Servers" ) ); |
65 | tabwidget->addTab( initDestinationTab(), "aqpkg/desttab", tr( "Destinations" ) ); | 65 | tabwidget->addTab( initDestinationTab(), "aqpkg/desttab", tr( "Destinations" ) ); |
66 | tabwidget->addTab( initProxyTab(), "aqpkg/proxytab", tr( "Proxies" ) ); | 66 | tabwidget->addTab( initProxyTab(), "aqpkg/proxytab", tr( "Proxies" ) ); |
67 | tabwidget->setCurrentTab( tr( "Servers" ) ); | 67 | tabwidget->setCurrentTab( tr( "Servers" ) ); |
68 | 68 | ||
69 | dataMgr = dataManager; | 69 | dataMgr = dataManager; |
70 | setupData(); | 70 | setupData(); |
71 | changed = false; | 71 | changed = false; |
72 | newserver = false; | 72 | newserver = false; |
73 | newdestination = false; | 73 | newdestination = false; |
74 | } | 74 | } |
75 | 75 | ||
76 | SettingsImpl :: ~SettingsImpl() | 76 | SettingsImpl :: ~SettingsImpl() |
77 | { | 77 | { |
78 | } | 78 | } |
79 | 79 | ||
80 | bool SettingsImpl :: showDlg() | 80 | bool SettingsImpl :: showDlg() |
81 | { | 81 | { |
82 | QPEApplication::execDialog( this ); | 82 | QPEApplication::execDialog( this ); |
83 | if ( changed ) | 83 | if ( changed ) |
84 | dataMgr->writeOutIpkgConf(); | 84 | dataMgr->writeOutIpkgConf(); |
85 | 85 | ||
86 | return changed; | 86 | return changed; |
87 | } | 87 | } |
88 | 88 | ||
89 | QWidget *SettingsImpl :: initServerTab() | 89 | QWidget *SettingsImpl :: initServerTab() |
90 | { | 90 | { |
91 | QWidget *control = new QWidget( this ); | 91 | QWidget *control = new QWidget( this ); |
92 | 92 | ||
93 | QVBoxLayout *vb = new QVBoxLayout( control ); | 93 | QVBoxLayout *vb = new QVBoxLayout( control ); |
94 | 94 | ||
95 | QScrollView *sv = new QScrollView( control ); | 95 | QScrollView *sv = new QScrollView( control ); |
96 | vb->addWidget( sv, 0, 0 ); | 96 | vb->addWidget( sv, 0, 0 ); |
97 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 97 | sv->setResizePolicy( QScrollView::AutoOneFit ); |
98 | sv->setFrameStyle( QFrame::NoFrame ); | 98 | sv->setFrameStyle( QFrame::NoFrame ); |
99 | 99 | ||
100 | QWidget *container = new QWidget( sv->viewport() ); | 100 | QWidget *container = new QWidget( sv->viewport() ); |
101 | sv->addChild( container ); | 101 | sv->addChild( container ); |
102 | 102 | ||
103 | QGridLayout *layout = new QGridLayout( container ); | 103 | QGridLayout *layout = new QGridLayout( container ); |
104 | layout->setSpacing( 2 ); | 104 | layout->setSpacing( 2 ); |
105 | layout->setMargin( 4 ); | 105 | layout->setMargin( 4 ); |
106 | 106 | ||
107 | servers = new QListBox( container ); | 107 | servers = new QListBox( container ); |
108 | servers->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) ); | 108 | servers->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) ); |
109 | connect( servers, SIGNAL( highlighted(int) ), this, SLOT( editServer(int) ) ); | 109 | connect( servers, SIGNAL( highlighted(int) ), this, SLOT( editServer(int) ) ); |
110 | layout->addMultiCellWidget( servers, 0, 0, 0, 1 ); | 110 | layout->addMultiCellWidget( servers, 0, 0, 0, 1 ); |
111 | 111 | ||
112 | QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), | 112 | QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), |
113 | tr( "New" ), container ); | 113 | tr( "New" ), container ); |
114 | connect( btn, SIGNAL( clicked() ), this, SLOT( newServer() ) ); | 114 | connect( btn, SIGNAL( clicked() ), this, SLOT( newServer() ) ); |
115 | layout->addWidget( btn, 1, 0 ); | 115 | layout->addWidget( btn, 1, 0 ); |
116 | 116 | ||
117 | btn = new QPushButton( Opie::Core::OResource::loadPixmap( "trash", Opie::Core::OResource::SmallIcon ), tr( "Delete" ), container ); | 117 | btn = new QPushButton( Opie::Core::OResource::loadPixmap( "trash", Opie::Core::OResource::SmallIcon ), tr( "Delete" ), container ); |
118 | connect( btn, SIGNAL( clicked() ), this, SLOT( removeServer() ) ); | 118 | connect( btn, SIGNAL( clicked() ), this, SLOT( removeServer() ) ); |
119 | layout->addWidget( btn, 1, 1 ); | 119 | layout->addWidget( btn, 1, 1 ); |
120 | 120 | ||
121 | QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "Server" ), container ); | 121 | QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "Server" ), container ); |
122 | grpbox->layout()->setSpacing( 2 ); | 122 | grpbox->layout()->setSpacing( 2 ); |
123 | grpbox->layout()->setMargin( 4 ); | 123 | grpbox->layout()->setMargin( 4 ); |
124 | layout->addMultiCellWidget( grpbox, 2, 2, 0, 1 ); | 124 | layout->addMultiCellWidget( grpbox, 2, 2, 0, 1 ); |
125 | 125 | ||
126 | QGridLayout *grplayout = new QGridLayout( grpbox->layout() ); | 126 | QGridLayout *grplayout = new QGridLayout( grpbox->layout() ); |
127 | 127 | ||
128 | QLabel *label = new QLabel( tr( "Name:" ), grpbox ); | 128 | QLabel *label = new QLabel( tr( "Name:" ), grpbox ); |
129 | grplayout->addWidget( label, 0, 0 ); | 129 | grplayout->addWidget( label, 0, 0 ); |
130 | servername = new QLineEdit( grpbox ); | 130 | servername = new QLineEdit( grpbox ); |
131 | grplayout->addWidget( servername, 0, 1 ); | 131 | grplayout->addWidget( servername, 0, 1 ); |
132 | 132 | ||
133 | label = new QLabel( tr( "Address:" ), grpbox ); | 133 | label = new QLabel( tr( "Address:" ), grpbox ); |
134 | grplayout->addWidget( label, 1, 0 ); | 134 | grplayout->addWidget( label, 1, 0 ); |
135 | serverurl = new QLineEdit( grpbox ); | 135 | serverurl = new QLineEdit( grpbox ); |
136 | grplayout->addWidget( serverurl, 1, 1 ); | 136 | grplayout->addWidget( serverurl, 1, 1 ); |
137 | 137 | ||
138 | active = new QCheckBox( tr( "Active Server" ), grpbox ); | 138 | active = new QCheckBox( tr( "Active Server" ), grpbox ); |
139 | grplayout->addMultiCellWidget( active, 2, 2, 0, 1 ); | 139 | grplayout->addMultiCellWidget( active, 2, 2, 0, 1 ); |
140 | 140 | ||
141 | btn = new QPushButton( Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ), tr( "Update" ), grpbox ); | 141 | btn = new QPushButton( Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ), tr( "Update" ), grpbox ); |
142 | connect( btn, SIGNAL( clicked() ), this, SLOT( changeServerDetails() ) ); | 142 | connect( btn, SIGNAL( clicked() ), this, SLOT( changeServerDetails() ) ); |
143 | grplayout->addMultiCellWidget( btn, 3, 3, 0, 1 ); | 143 | grplayout->addMultiCellWidget( btn, 3, 3, 0, 1 ); |
144 | 144 | ||
145 | return control; | 145 | return control; |
146 | } | 146 | } |
147 | 147 | ||
148 | QWidget *SettingsImpl :: initDestinationTab() | 148 | QWidget *SettingsImpl :: initDestinationTab() |
149 | { | 149 | { |
150 | QWidget *control = new QWidget( this ); | 150 | QWidget *control = new QWidget( this ); |
151 | 151 | ||
152 | QVBoxLayout *vb = new QVBoxLayout( control ); | 152 | QVBoxLayout *vb = new QVBoxLayout( control ); |
153 | 153 | ||
154 | QScrollView *sv = new QScrollView( control ); | 154 | QScrollView *sv = new QScrollView( control ); |
155 | vb->addWidget( sv, 0, 0 ); | 155 | vb->addWidget( sv, 0, 0 ); |
156 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 156 | sv->setResizePolicy( QScrollView::AutoOneFit ); |
157 | sv->setFrameStyle( QFrame::NoFrame ); | 157 | sv->setFrameStyle( QFrame::NoFrame ); |
158 | 158 | ||
159 | QWidget *container = new QWidget( sv->viewport() ); | 159 | QWidget *container = new QWidget( sv->viewport() ); |
160 | sv->addChild( container ); | 160 | sv->addChild( container ); |
161 | 161 | ||
162 | QGridLayout *layout = new QGridLayout( container ); | 162 | QGridLayout *layout = new QGridLayout( container ); |
163 | layout->setSpacing( 2 ); | 163 | layout->setSpacing( 2 ); |
164 | layout->setMargin( 4 ); | 164 | layout->setMargin( 4 ); |
165 | 165 | ||
166 | destinations = new QListBox( container ); | 166 | destinations = new QListBox( container ); |
167 | destinations->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) ); | 167 | destinations->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ) ); |
168 | connect( destinations, SIGNAL( highlighted(int) ), this, SLOT( editDestination(int) ) ); | 168 | connect( destinations, SIGNAL( highlighted(int) ), this, SLOT( editDestination(int) ) ); |
169 | layout->addMultiCellWidget( destinations, 0, 0, 0, 1 ); | 169 | layout->addMultiCellWidget( destinations, 0, 0, 0, 1 ); |
170 | 170 | ||
171 | QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), tr( "New" ), container ); | 171 | QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), tr( "New" ), container ); |
172 | connect( btn, SIGNAL( clicked() ), this, SLOT( newDestination() ) ); | 172 | connect( btn, SIGNAL( clicked() ), this, SLOT( newDestination() ) ); |
173 | layout->addWidget( btn, 1, 0 ); | 173 | layout->addWidget( btn, 1, 0 ); |
174 | 174 | ||
175 | btn = new QPushButton( Opie::Core::OResource::loadPixmap( "trash", Opie::Core::OResource::SmallIcon ), tr( "Delete" ), container ); | 175 | btn = new QPushButton( Opie::Core::OResource::loadPixmap( "trash", Opie::Core::OResource::SmallIcon ), tr( "Delete" ), container ); |
176 | connect( btn, SIGNAL( clicked() ), this, SLOT( removeDestination() ) ); | 176 | connect( btn, SIGNAL( clicked() ), this, SLOT( removeDestination() ) ); |
177 | layout->addWidget( btn, 1, 1 ); | 177 | layout->addWidget( btn, 1, 1 ); |
178 | 178 | ||
179 | QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "Destination" ), container ); | 179 | QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "Destination" ), container ); |
180 | grpbox->layout()->setSpacing( 2 ); | 180 | grpbox->layout()->setSpacing( 2 ); |
181 | grpbox->layout()->setMargin( 4 ); | 181 | grpbox->layout()->setMargin( 4 ); |
182 | layout->addMultiCellWidget( grpbox, 2, 2, 0, 1 ); | 182 | layout->addMultiCellWidget( grpbox, 2, 2, 0, 1 ); |
183 | 183 | ||
184 | QGridLayout *grplayout = new QGridLayout( grpbox->layout() ); | 184 | QGridLayout *grplayout = new QGridLayout( grpbox->layout() ); |
185 | 185 | ||
186 | QLabel *label = new QLabel( tr( "Name:" ), grpbox ); | 186 | QLabel *label = new QLabel( tr( "Name:" ), grpbox ); |
187 | grplayout->addWidget( label, 0, 0 ); | 187 | grplayout->addWidget( label, 0, 0 ); |
188 | destinationname = new QLineEdit( grpbox ); | 188 | destinationname = new QLineEdit( grpbox ); |
189 | grplayout->addWidget( destinationname, 0, 1 ); | 189 | grplayout->addWidget( destinationname, 0, 1 ); |
190 | 190 | ||
191 | label = new QLabel( tr( "Location:" ), grpbox ); | 191 | label = new QLabel( tr( "Location:" ), grpbox ); |
192 | grplayout->addWidget( label, 1, 0 ); | 192 | grplayout->addWidget( label, 1, 0 ); |
193 | destinationurl = new QLineEdit( grpbox ); | 193 | destinationurl = new QLineEdit( grpbox ); |
194 | grplayout->addWidget( destinationurl, 1, 1 ); | 194 | grplayout->addWidget( destinationurl, 1, 1 ); |
195 | 195 | ||
196 | linkToRoot = new QCheckBox( tr( "Link to root" ), grpbox ); | 196 | linkToRoot = new QCheckBox( tr( "Link to root" ), grpbox ); |
197 | grplayout->addMultiCellWidget( linkToRoot, 2, 2, 0, 1 ); | 197 | grplayout->addMultiCellWidget( linkToRoot, 2, 2, 0, 1 ); |
198 | 198 | ||
199 | btn = new QPushButton( Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ), tr( "Update" ), grpbox ); | 199 | btn = new QPushButton( Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ), tr( "Update" ), grpbox ); |
200 | connect( btn, SIGNAL( clicked() ), this, SLOT( changeDestinationDetails() ) ); | 200 | connect( btn, SIGNAL( clicked() ), this, SLOT( changeDestinationDetails() ) ); |
201 | grplayout->addMultiCellWidget( btn, 3, 3, 0, 1 ); | 201 | grplayout->addMultiCellWidget( btn, 3, 3, 0, 1 ); |
202 | 202 | ||
203 | return control; | 203 | return control; |
204 | } | 204 | } |
205 | 205 | ||
206 | QWidget *SettingsImpl :: initProxyTab() | 206 | QWidget *SettingsImpl :: initProxyTab() |
207 | { | 207 | { |
208 | QWidget *control = new QWidget( this ); | 208 | QWidget *control = new QWidget( this ); |
209 | 209 | ||
210 | QVBoxLayout *vb = new QVBoxLayout( control ); | 210 | QVBoxLayout *vb = new QVBoxLayout( control ); |
211 | 211 | ||
212 | QScrollView *sv = new QScrollView( control ); | 212 | QScrollView *sv = new QScrollView( control ); |
213 | vb->addWidget( sv, 0, 0 ); | 213 | vb->addWidget( sv, 0, 0 ); |
214 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 214 | sv->setResizePolicy( QScrollView::AutoOneFit ); |
215 | sv->setFrameStyle( QFrame::NoFrame ); | 215 | sv->setFrameStyle( QFrame::NoFrame ); |
216 | 216 | ||
217 | QWidget *container = new QWidget( sv->viewport() ); | 217 | QWidget *container = new QWidget( sv->viewport() ); |
218 | sv->addChild( container ); | 218 | sv->addChild( container ); |
219 | 219 | ||
220 | QGridLayout *layout = new QGridLayout( container ); | 220 | QGridLayout *layout = new QGridLayout( container ); |
221 | layout->setSpacing( 2 ); | 221 | layout->setSpacing( 2 ); |
222 | layout->setMargin( 4 ); | 222 | layout->setMargin( 4 ); |
223 | 223 | ||
224 | QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "HTTP Proxy" ), container ); | 224 | QGroupBox *grpbox = new QGroupBox( 0, Qt::Vertical, tr( "HTTP Proxy" ), container ); |
225 | grpbox->layout()->setSpacing( 2 ); | 225 | grpbox->layout()->setSpacing( 2 ); |
226 | grpbox->layout()->setMargin( 4 ); | 226 | grpbox->layout()->setMargin( 4 ); |
227 | layout->addMultiCellWidget( grpbox, 0, 0, 0, 1 ); | 227 | layout->addMultiCellWidget( grpbox, 0, 0, 0, 1 ); |
228 | QVBoxLayout *grplayout = new QVBoxLayout( grpbox->layout() ); | 228 | QVBoxLayout *grplayout = new QVBoxLayout( grpbox->layout() ); |
229 | txtHttpProxy = new QLineEdit( grpbox ); | 229 | txtHttpProxy = new QLineEdit( grpbox ); |
230 | grplayout->addWidget( txtHttpProxy ); | 230 | grplayout->addWidget( txtHttpProxy ); |
231 | chkHttpProxyEnabled = new QCheckBox( tr( "Enabled" ), grpbox ); | 231 | chkHttpProxyEnabled = new QCheckBox( tr( "Enabled" ), grpbox ); |
232 | grplayout->addWidget( chkHttpProxyEnabled ); | 232 | grplayout->addWidget( chkHttpProxyEnabled ); |
233 | 233 | ||
234 | grpbox = new QGroupBox( 0, Qt::Vertical, tr( "FTP Proxy" ), container ); | 234 | grpbox = new QGroupBox( 0, Qt::Vertical, tr( "FTP Proxy" ), container ); |
235 | grpbox->layout()->setSpacing( 2 ); | 235 | grpbox->layout()->setSpacing( 2 ); |
236 | grpbox->layout()->setMargin( 4 ); | 236 | grpbox->layout()->setMargin( 4 ); |
237 | layout->addMultiCellWidget( grpbox, 1, 1, 0, 1 ); | 237 | layout->addMultiCellWidget( grpbox, 1, 1, 0, 1 ); |
238 | grplayout = new QVBoxLayout( grpbox->layout() ); | 238 | grplayout = new QVBoxLayout( grpbox->layout() ); |
239 | txtFtpProxy = new QLineEdit( grpbox ); | 239 | txtFtpProxy = new QLineEdit( grpbox ); |
240 | grplayout->addWidget( txtFtpProxy ); | 240 | grplayout->addWidget( txtFtpProxy ); |
241 | chkFtpProxyEnabled = new QCheckBox( tr( "Enabled" ), grpbox ); | 241 | chkFtpProxyEnabled = new QCheckBox( tr( "Enabled" ), grpbox ); |
242 | grplayout->addWidget( chkFtpProxyEnabled ); | 242 | grplayout->addWidget( chkFtpProxyEnabled ); |
243 | 243 | ||
244 | QLabel *label = new QLabel( tr( "Username:" ), container ); | 244 | QLabel *label = new QLabel( tr( "Username:" ), container ); |
245 | layout->addWidget( label, 2, 0 ); | 245 | layout->addWidget( label, 2, 0 ); |
246 | txtUsername = new QLineEdit( container ); | 246 | txtUsername = new QLineEdit( container ); |
247 | layout->addWidget( txtUsername, 2, 1 ); | 247 | layout->addWidget( txtUsername, 2, 1 ); |
248 | 248 | ||
249 | label = new QLabel( tr( "Password:" ), container ); | 249 | label = new QLabel( tr( "Password:" ), container ); |
250 | layout->addWidget( label, 3, 0 ); | 250 | layout->addWidget( label, 3, 0 ); |
251 | txtPassword = new QLineEdit( container ); | 251 | txtPassword = new QLineEdit( container ); |
252 | layout->addWidget( txtPassword, 3, 1 ); | 252 | layout->addWidget( txtPassword, 3, 1 ); |
253 | 253 | ||
254 | QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ), tr( "Update" ), container ); | 254 | QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ), tr( "Update" ), container ); |
255 | connect( btn, SIGNAL( clicked() ), this, SLOT( proxyApplyChanges() ) ); | 255 | connect( btn, SIGNAL( clicked() ), this, SLOT( proxyApplyChanges() ) ); |
256 | layout->addMultiCellWidget( btn, 4, 4, 0, 1 ); | 256 | layout->addMultiCellWidget( btn, 4, 4, 0, 1 ); |
257 | 257 | ||
258 | return control; | 258 | return control; |
259 | } | 259 | } |
260 | 260 | ||
261 | void SettingsImpl :: setupData() | 261 | void SettingsImpl :: setupData() |
262 | { | 262 | { |
263 | // add servers | 263 | // add servers |
264 | QString serverName; | 264 | QString serverName; |
265 | QListIterator<Server> it( dataMgr->getServerList() ); | 265 | QListIterator<Server> it( dataMgr->getServerList() ); |
266 | for ( ; it.current(); ++it ) | 266 | for ( ; it.current(); ++it ) |
267 | { | 267 | { |
268 | serverName = it.current()->getServerName(); | 268 | serverName = it.current()->getServerName(); |
269 | if ( serverName == LOCAL_SERVER || serverName == LOCAL_IPKGS ) | 269 | if ( serverName == LOCAL_SERVER || serverName == LOCAL_IPKGS ) |
270 | continue; | 270 | continue; |
271 | 271 | ||
272 | servers->insertItem( serverName ); | 272 | servers->insertItem( serverName ); |
273 | } | 273 | } |
274 | 274 | ||
275 | 275 | ||
276 | // add destinations | 276 | // add destinations |
277 | QListIterator<Destination> it2( dataMgr->getDestinationList() ); | 277 | QListIterator<Destination> it2( dataMgr->getDestinationList() ); |
278 | for ( ; it2.current(); ++it2 ) | 278 | for ( ; it2.current(); ++it2 ) |
279 | destinations->insertItem( it2.current()->getDestinationName() ); | 279 | destinations->insertItem( it2.current()->getDestinationName() ); |
280 | 280 | ||
281 | // setup proxy tab | 281 | // setup proxy tab |
282 | txtHttpProxy->setText( dataMgr->getHttpProxy() ); | 282 | txtHttpProxy->setText( dataMgr->getHttpProxy() ); |
283 | txtFtpProxy->setText( dataMgr->getFtpProxy() ); | 283 | txtFtpProxy->setText( dataMgr->getFtpProxy() ); |
284 | txtUsername->setText( dataMgr->getProxyUsername() ); | 284 | txtUsername->setText( dataMgr->getProxyUsername() ); |
285 | txtPassword->setText( dataMgr->getProxyPassword() ); | 285 | txtPassword->setText( dataMgr->getProxyPassword() ); |
286 | chkHttpProxyEnabled->setChecked( dataMgr->getHttpProxyEnabled() ); | 286 | chkHttpProxyEnabled->setChecked( dataMgr->getHttpProxyEnabled() ); |
287 | chkFtpProxyEnabled->setChecked( dataMgr->getFtpProxyEnabled() ); | 287 | chkFtpProxyEnabled->setChecked( dataMgr->getFtpProxyEnabled() ); |
288 | } | 288 | } |
289 | 289 | ||
290 | //------------------ Servers tab ---------------------- | 290 | //------------------ Servers tab ---------------------- |
291 | 291 | ||
292 | void SettingsImpl :: editServer( int sel ) | 292 | void SettingsImpl :: editServer( int sel ) |
293 | { | 293 | { |
294 | currentSelectedServer = sel; | 294 | currentSelectedServer = sel; |
295 | Server *s = dataMgr->getServer( servers->currentText() ); | 295 | Server *s = dataMgr->getServer( servers->currentText() ); |
296 | if ( s ) | 296 | if ( s ) |
297 | { | 297 | { |
298 | serverName = s->getServerName(); | 298 | serverName = s->getServerName(); |
299 | servername->setText( s->getServerName() ); | 299 | servername->setText( s->getServerName() ); |
300 | serverurl->setText( s->getServerUrl() ); | 300 | serverurl->setText( s->getServerUrl() ); |
301 | active->setChecked( s->isServerActive() ); | 301 | active->setChecked( s->isServerActive() ); |
302 | } | 302 | } |
303 | else | 303 | else |
304 | { | 304 | { |
305 | serverName = ""; | 305 | serverName = ""; |
306 | servername->setText( "" ); | 306 | servername->setText( "" ); |
307 | serverurl->setText( "" ); | 307 | serverurl->setText( "" ); |
308 | active->setChecked( false ); | 308 | active->setChecked( false ); |
309 | } | 309 | } |
310 | } | 310 | } |
311 | 311 | ||
312 | void SettingsImpl :: newServer() | 312 | void SettingsImpl :: newServer() |
313 | { | 313 | { |
314 | newserver = true; | 314 | newserver = true; |
315 | servername->setText( "" ); | 315 | servername->setText( "" ); |
316 | serverurl->setText( "" ); | 316 | serverurl->setText( "" ); |
317 | servername->setFocus(); | 317 | servername->setFocus(); |
318 | active->setChecked( true ); | 318 | active->setChecked( true ); |
319 | } | 319 | } |
320 | 320 | ||
321 | void SettingsImpl :: removeServer() | 321 | void SettingsImpl :: removeServer() |
322 | { | 322 | { |
323 | changed = true; | 323 | changed = true; |
324 | Server *s = dataMgr->getServer( servers->currentText() ); | 324 | Server *s = dataMgr->getServer( servers->currentText() ); |
325 | if ( s ) | 325 | if ( s ) |
326 | { | 326 | { |
327 | dataMgr->getServerList().removeRef( s ); | 327 | dataMgr->getServerList().removeRef( s ); |
328 | servers->removeItem( currentSelectedServer ); | 328 | servers->removeItem( currentSelectedServer ); |
329 | } | 329 | } |
330 | } | 330 | } |
331 | 331 | ||
332 | void SettingsImpl :: changeServerDetails() | 332 | void SettingsImpl :: changeServerDetails() |
333 | { | 333 | { |
334 | changed = true; | 334 | changed = true; |
335 | 335 | ||
336 | QString newName = servername->text(); | 336 | QString newName = servername->text(); |
337 | 337 | ||
338 | // Convert any spaces to underscores | 338 | // Convert any spaces to underscores |
339 | char *tmpStr = new char[newName.length() + 1]; | 339 | char *tmpStr = new char[newName.length() + 1]; |
340 | for ( unsigned int i = 0 ; i < newName.length() ; ++i ) | 340 | for ( unsigned int i = 0 ; i < newName.length() ; ++i ) |
341 | { | 341 | { |
342 | if ( newName[i] == ' ' ) | 342 | if ( newName[i] == ' ' ) |
343 | tmpStr[i] = '_'; | 343 | tmpStr[i] = '_'; |
344 | else | 344 | else |
345 | tmpStr[i] = newName[i].latin1(); | 345 | tmpStr[i] = newName[i].latin1(); |
346 | } | 346 | } |
347 | tmpStr[newName.length()] = '\0'; | 347 | tmpStr[newName.length()] = '\0'; |
348 | 348 | ||
349 | newName = tmpStr; | 349 | newName = tmpStr; |
350 | delete tmpStr; | 350 | delete [] tmpStr; |
351 | 351 | ||
352 | if ( !newserver ) | 352 | if ( !newserver ) |
353 | { | 353 | { |
354 | Server *s = dataMgr->getServer( servers->currentText() ); | 354 | Server *s = dataMgr->getServer( servers->currentText() ); |
355 | if ( s ) | 355 | if ( s ) |
356 | { | 356 | { |
357 | // Update url | 357 | // Update url |
358 | s->setServerUrl( serverurl->text() ); | 358 | s->setServerUrl( serverurl->text() ); |
359 | s->setActive( active->isChecked() ); | 359 | s->setActive( active->isChecked() ); |
360 | 360 | ||
361 | // Check if server name has changed, if it has then we need to replace the key in the map | 361 | // Check if server name has changed, if it has then we need to replace the key in the map |
362 | if ( serverName != newName ) | 362 | if ( serverName != newName ) |
363 | { | 363 | { |
364 | // Update server name | 364 | // Update server name |
365 | s->setServerName( newName ); | 365 | s->setServerName( newName ); |
366 | } | 366 | } |
367 | 367 | ||
368 | // Update list box | 368 | // Update list box |
369 | servers->changeItem( newName, currentSelectedServer ); | 369 | servers->changeItem( newName, currentSelectedServer ); |
370 | } | 370 | } |
371 | } | 371 | } |
372 | else | 372 | else |
373 | { | 373 | { |
374 | Server s( newName, serverurl->text() ); | 374 | Server s( newName, serverurl->text() ); |
375 | dataMgr->getServerList().append( new Server( newName, serverurl->text() ) ); | 375 | dataMgr->getServerList().append( new Server( newName, serverurl->text() ) ); |
376 | dataMgr->getServerList().last()->setActive( active->isChecked() ); | 376 | dataMgr->getServerList().last()->setActive( active->isChecked() ); |
377 | servers->insertItem( newName ); | 377 | servers->insertItem( newName ); |
378 | servers->setCurrentItem( servers->count() ); | 378 | servers->setCurrentItem( servers->count() ); |
379 | newserver = false; | 379 | newserver = false; |
380 | } | 380 | } |
381 | } | 381 | } |
382 | 382 | ||
383 | //------------------ Destinations tab ---------------------- | 383 | //------------------ Destinations tab ---------------------- |
384 | 384 | ||
385 | void SettingsImpl :: editDestination( int sel ) | 385 | void SettingsImpl :: editDestination( int sel ) |
386 | { | 386 | { |
387 | currentSelectedDestination = sel; | 387 | currentSelectedDestination = sel; |
388 | Destination *d = dataMgr->getDestination( destinations->currentText() ); | 388 | Destination *d = dataMgr->getDestination( destinations->currentText() ); |
389 | if ( d ) | 389 | if ( d ) |
390 | { | 390 | { |
391 | destinationName = d->getDestinationName(); | 391 | destinationName = d->getDestinationName(); |
392 | destinationname->setText( d->getDestinationName() ); | 392 | destinationname->setText( d->getDestinationName() ); |
393 | destinationurl->setText( d->getDestinationPath() ); | 393 | destinationurl->setText( d->getDestinationPath() ); |
394 | linkToRoot->setChecked( d->linkToRoot() ); | 394 | linkToRoot->setChecked( d->linkToRoot() ); |
395 | } | 395 | } |
396 | else | 396 | else |
397 | { | 397 | { |
398 | destinationName = ""; | 398 | destinationName = ""; |
399 | destinationname->setText( "" ); | 399 | destinationname->setText( "" ); |
400 | destinationurl->setText( "" ); | 400 | destinationurl->setText( "" ); |
401 | linkToRoot->setChecked( false ); | 401 | linkToRoot->setChecked( false ); |
402 | } | 402 | } |
403 | } | 403 | } |
404 | 404 | ||
405 | void SettingsImpl :: newDestination() | 405 | void SettingsImpl :: newDestination() |
406 | { | 406 | { |
407 | newdestination = true; | 407 | newdestination = true; |
408 | destinationname->setText( "" ); | 408 | destinationname->setText( "" ); |
409 | destinationurl->setText( "" ); | 409 | destinationurl->setText( "" ); |
410 | destinationname->setFocus(); | 410 | destinationname->setFocus(); |
411 | linkToRoot->setChecked( true ); | 411 | linkToRoot->setChecked( true ); |
412 | } | 412 | } |
413 | 413 | ||
414 | void SettingsImpl :: removeDestination() | 414 | void SettingsImpl :: removeDestination() |
415 | { | 415 | { |
416 | changed = true; | 416 | changed = true; |
417 | Destination *d = dataMgr->getDestination( destinations->currentText() ); | 417 | Destination *d = dataMgr->getDestination( destinations->currentText() ); |
418 | if ( d ) | 418 | if ( d ) |
419 | { | 419 | { |
420 | dataMgr->getDestinationList().removeRef( d ); | 420 | dataMgr->getDestinationList().removeRef( d ); |
421 | destinations->removeItem( currentSelectedDestination ); | 421 | destinations->removeItem( currentSelectedDestination ); |
422 | } | 422 | } |
423 | } | 423 | } |
424 | 424 | ||
425 | void SettingsImpl :: changeDestinationDetails() | 425 | void SettingsImpl :: changeDestinationDetails() |
426 | { | 426 | { |
427 | changed = true; | 427 | changed = true; |
428 | 428 | ||
429 | #ifdef QWS | 429 | #ifdef QWS |
430 | Config cfg( "aqpkg" ); | 430 | Config cfg( "aqpkg" ); |
431 | cfg.setGroup( "destinations" ); | 431 | cfg.setGroup( "destinations" ); |
432 | #endif | 432 | #endif |
433 | 433 | ||
434 | QString newName = destinationname->text(); | 434 | QString newName = destinationname->text(); |
435 | if ( !newdestination ) | 435 | if ( !newdestination ) |
436 | { | 436 | { |
437 | Destination *d = dataMgr->getDestination( destinations->currentText() ); | 437 | Destination *d = dataMgr->getDestination( destinations->currentText() ); |
438 | if ( d ) | 438 | if ( d ) |
439 | { | 439 | { |
440 | // Update url | 440 | // Update url |
441 | d->setDestinationPath( destinationurl->text() ); | 441 | d->setDestinationPath( destinationurl->text() ); |
442 | d->linkToRoot( linkToRoot->isChecked() ); | 442 | d->linkToRoot( linkToRoot->isChecked() ); |
443 | 443 | ||
444 | // Check if server name has changed, if it has then we need to replace the key in the map | 444 | // Check if server name has changed, if it has then we need to replace the key in the map |
445 | if ( destinationName != newName ) | 445 | if ( destinationName != newName ) |
446 | { | 446 | { |
447 | // Update server name | 447 | // Update server name |
448 | d->setDestinationName( newName ); | 448 | d->setDestinationName( newName ); |
449 | 449 | ||
450 | // Update list box | 450 | // Update list box |
451 | destinations->changeItem( newName, currentSelectedDestination ); | 451 | destinations->changeItem( newName, currentSelectedDestination ); |
452 | } | 452 | } |
453 | 453 | ||
454 | #ifdef QWS | 454 | #ifdef QWS |
455 | QString key = newName; | 455 | QString key = newName; |
456 | key += "_linkToRoot"; | 456 | key += "_linkToRoot"; |
457 | int val = d->linkToRoot(); | 457 | int val = d->linkToRoot(); |
458 | cfg.writeEntry( key, val ); | 458 | cfg.writeEntry( key, val ); |
459 | #endif | 459 | #endif |
460 | 460 | ||
461 | } | 461 | } |
462 | } | 462 | } |
463 | else | 463 | else |
464 | { | 464 | { |
465 | dataMgr->getDestinationList().append( new Destination( newName, destinationurl->text() ) ); | 465 | dataMgr->getDestinationList().append( new Destination( newName, destinationurl->text() ) ); |
466 | destinations->insertItem( newName ); | 466 | destinations->insertItem( newName ); |
467 | destinations->setCurrentItem( destinations->count() ); | 467 | destinations->setCurrentItem( destinations->count() ); |
468 | newdestination = false; | 468 | newdestination = false; |
469 | 469 | ||
470 | #ifdef QWS | 470 | #ifdef QWS |
471 | QString key = newName; | 471 | QString key = newName; |
472 | key += "_linkToRoot"; | 472 | key += "_linkToRoot"; |
473 | cfg.writeEntry( key, true ); | 473 | cfg.writeEntry( key, true ); |
474 | #endif | 474 | #endif |
475 | 475 | ||
476 | } | 476 | } |
477 | } | 477 | } |
478 | 478 | ||
479 | //------------------ Proxy tab ---------------------- | 479 | //------------------ Proxy tab ---------------------- |
480 | void SettingsImpl :: proxyApplyChanges() | 480 | void SettingsImpl :: proxyApplyChanges() |
481 | { | 481 | { |
482 | changed = true; | 482 | changed = true; |
483 | dataMgr->setHttpProxy( txtHttpProxy->text() ); | 483 | dataMgr->setHttpProxy( txtHttpProxy->text() ); |
484 | dataMgr->setFtpProxy( txtFtpProxy->text() ); | 484 | dataMgr->setFtpProxy( txtFtpProxy->text() ); |
485 | dataMgr->setProxyUsername( txtUsername->text() ); | 485 | dataMgr->setProxyUsername( txtUsername->text() ); |
486 | dataMgr->setProxyPassword( txtPassword->text() ); | 486 | dataMgr->setProxyPassword( txtPassword->text() ); |
487 | 487 | ||
488 | dataMgr->setHttpProxyEnabled( chkHttpProxyEnabled->isChecked() ); | 488 | dataMgr->setHttpProxyEnabled( chkHttpProxyEnabled->isChecked() ); |
489 | dataMgr->setFtpProxyEnabled( chkFtpProxyEnabled->isChecked() ); | 489 | dataMgr->setFtpProxyEnabled( chkFtpProxyEnabled->isChecked() ); |
490 | } | 490 | } |
diff --git a/noncore/settings/aqpkg/version.cpp b/noncore/settings/aqpkg/version.cpp index 59e6f3f..ce2de7b 100644 --- a/noncore/settings/aqpkg/version.cpp +++ b/noncore/settings/aqpkg/version.cpp | |||
@@ -1,219 +1,219 @@ | |||
1 | /* | 1 | /* |
2 | * libdpkg - Debian packaging suite library routines | 2 | * libdpkg - Debian packaging suite library routines |
3 | * vercmp.c - comparison of version numbers | 3 | * vercmp.c - comparison of version numbers |
4 | * | 4 | * |
5 | * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk> | 5 | * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk> |
6 | * | 6 | * |
7 | * This is free software; you can redistribute it and/or modify | 7 | * This is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as | 8 | * it under the terms of the GNU General Public License as |
9 | * published by the Free Software Foundation; either version 2, | 9 | * published by the Free Software Foundation; either version 2, |
10 | * or (at your option) any later version. | 10 | * or (at your option) any later version. |
11 | * | 11 | * |
12 | * This is distributed in the hope that it will be useful, but | 12 | * This is distributed in the hope that it will be useful, but |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. | 15 | * GNU General Public License for more details. |
16 | * | 16 | * |
17 | * You should have received a copy of the GNU General Public | 17 | * You should have received a copy of the GNU General Public |
18 | * License along with dpkg; if not, write to the Free Software | 18 | * License along with dpkg; if not, write to the Free Software |
19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | */ | 20 | */ |
21 | #include <stdio.h> | 21 | #include <stdio.h> |
22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
23 | #include <ctype.h> | 23 | #include <ctype.h> |
24 | #include <string.h> | 24 | #include <string.h> |
25 | 25 | ||
26 | #include <qobject.h> | 26 | #include <qobject.h> |
27 | 27 | ||
28 | //# define _(Text) Text | 28 | //# define _(Text) Text |
29 | 29 | ||
30 | class versionrevision | 30 | class versionrevision |
31 | { | 31 | { |
32 | public: | 32 | public: |
33 | versionrevision() | 33 | versionrevision() |
34 | { | 34 | { |
35 | version = 0; | 35 | version = 0; |
36 | } | 36 | } |
37 | 37 | ||
38 | ~versionrevision() | 38 | ~versionrevision() |
39 | { | 39 | { |
40 | if ( version ) | 40 | if ( version ) |
41 | delete version; | 41 | delete [] version; |
42 | } | 42 | } |
43 | 43 | ||
44 | void setVersion( const char *str ) | 44 | void setVersion( const char *str ) |
45 | { | 45 | { |
46 | version = new char[(strlen(str)+1)]; | 46 | version = new char[(strlen(str)+1)]; |
47 | strcpy( version, str ); | 47 | strcpy( version, str ); |
48 | } | 48 | } |
49 | 49 | ||
50 | unsigned long epoch; | 50 | unsigned long epoch; |
51 | char *version; | 51 | char *version; |
52 | const char *revision; | 52 | const char *revision; |
53 | const char *familiar_revision; | 53 | const char *familiar_revision; |
54 | }; | 54 | }; |
55 | 55 | ||
56 | static int verrevcmp(const char *val, const char *ref) | 56 | static int verrevcmp(const char *val, const char *ref) |
57 | { | 57 | { |
58 | int vc, rc; | 58 | int vc, rc; |
59 | long vl, rl; | 59 | long vl, rl; |
60 | const char *vp, *rp; | 60 | const char *vp, *rp; |
61 | 61 | ||
62 | if (!val) val= ""; | 62 | if (!val) val= ""; |
63 | if (!ref) ref= ""; | 63 | if (!ref) ref= ""; |
64 | for (;;) { | 64 | for (;;) { |
65 | vp= val; while (*vp && !isdigit(*vp)) vp++; | 65 | vp= val; while (*vp && !isdigit(*vp)) vp++; |
66 | rp= ref; while (*rp && !isdigit(*rp)) rp++; | 66 | rp= ref; while (*rp && !isdigit(*rp)) rp++; |
67 | for (;;) { | 67 | for (;;) { |
68 | vc= val == vp ? 0 : *val++; | 68 | vc= val == vp ? 0 : *val++; |
69 | rc= ref == rp ? 0 : *ref++; | 69 | rc= ref == rp ? 0 : *ref++; |
70 | if (!rc && !vc) break; | 70 | if (!rc && !vc) break; |
71 | if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */ | 71 | if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */ |
72 | if (rc && !isalpha(rc)) rc += 256; | 72 | if (rc && !isalpha(rc)) rc += 256; |
73 | if (vc != rc) return vc - rc; | 73 | if (vc != rc) return vc - rc; |
74 | } | 74 | } |
75 | val= vp; | 75 | val= vp; |
76 | ref= rp; | 76 | ref= rp; |
77 | vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10); | 77 | vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10); |
78 | rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10); | 78 | rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10); |
79 | if (vl != rl) return vl - rl; | 79 | if (vl != rl) return vl - rl; |
80 | if (!*val && !*ref) return 0; | 80 | if (!*val && !*ref) return 0; |
81 | if (!*val) return -1; | 81 | if (!*val) return -1; |
82 | if (!*ref) return +1; | 82 | if (!*ref) return +1; |
83 | } | 83 | } |
84 | } | 84 | } |
85 | 85 | ||
86 | int versioncompare(const struct versionrevision *version, | 86 | int versioncompare(const struct versionrevision *version, |
87 | const struct versionrevision *refversion) | 87 | const struct versionrevision *refversion) |
88 | { | 88 | { |
89 | int r; | 89 | int r; |
90 | 90 | ||
91 | if (version->epoch > refversion->epoch) return 1; | 91 | if (version->epoch > refversion->epoch) return 1; |
92 | if (version->epoch < refversion->epoch) return -1; | 92 | if (version->epoch < refversion->epoch) return -1; |
93 | r= verrevcmp(version->version,refversion->version); if (r) return r; | 93 | r= verrevcmp(version->version,refversion->version); if (r) return r; |
94 | r= verrevcmp(version->revision,refversion->revision); if (r) return r; | 94 | r= verrevcmp(version->revision,refversion->revision); if (r) return r; |
95 | return verrevcmp(version->familiar_revision,refversion->familiar_revision); | 95 | return verrevcmp(version->familiar_revision,refversion->familiar_revision); |
96 | } | 96 | } |
97 | 97 | ||
98 | int versionsatisfied3(const struct versionrevision *it, | 98 | int versionsatisfied3(const struct versionrevision *it, |
99 | const struct versionrevision *ref, | 99 | const struct versionrevision *ref, |
100 | const char *op) | 100 | const char *op) |
101 | { | 101 | { |
102 | int r; | 102 | int r; |
103 | r= versioncompare(it,ref); | 103 | r= versioncompare(it,ref); |
104 | if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) | 104 | if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) |
105 | return r <= 0; | 105 | return r <= 0; |
106 | if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) | 106 | if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) |
107 | return r >= 0; | 107 | return r >= 0; |
108 | if (strcmp(op, "<<") == 0) | 108 | if (strcmp(op, "<<") == 0) |
109 | return r < 0; | 109 | return r < 0; |
110 | if (strcmp(op, ">>") == 0) | 110 | if (strcmp(op, ">>") == 0) |
111 | return r > 0; | 111 | return r > 0; |
112 | if (strcmp(op, "=") == 0) | 112 | if (strcmp(op, "=") == 0) |
113 | return r == 0; | 113 | return r == 0; |
114 | // fprintf(stderr, "unknown operator: %s", op); | 114 | // fprintf(stderr, "unknown operator: %s", op); |
115 | 115 | ||
116 | exit(1); | 116 | exit(1); |
117 | } | 117 | } |
118 | 118 | ||
119 | const char *parseversion(struct versionrevision *rversion, const char *string) | 119 | const char *parseversion(struct versionrevision *rversion, const char *string) |
120 | { | 120 | { |
121 | char *hyphen, *colon, *eepochcolon; | 121 | char *hyphen, *colon, *eepochcolon; |
122 | unsigned long epoch; | 122 | unsigned long epoch; |
123 | 123 | ||
124 | if ( !*string ) | 124 | if ( !*string ) |
125 | return QObject::tr( "Version string is empty." ); | 125 | return QObject::tr( "Version string is empty." ); |
126 | 126 | ||
127 | colon= strchr(string,':'); | 127 | colon= strchr(string,':'); |
128 | if (colon) { | 128 | if (colon) { |
129 | epoch= strtoul(string,&eepochcolon,10); | 129 | epoch= strtoul(string,&eepochcolon,10); |
130 | if ( colon != eepochcolon ) | 130 | if ( colon != eepochcolon ) |
131 | return QObject::tr( "Epoch in version is not number." ); | 131 | return QObject::tr( "Epoch in version is not number." ); |
132 | if ( !*++colon ) | 132 | if ( !*++colon ) |
133 | return QObject::tr( "Nothing after colon in version number." ); | 133 | return QObject::tr( "Nothing after colon in version number." ); |
134 | string= colon; | 134 | string= colon; |
135 | rversion->epoch= epoch; | 135 | rversion->epoch= epoch; |
136 | } else { | 136 | } else { |
137 | rversion->epoch= 0; | 137 | rversion->epoch= 0; |
138 | } | 138 | } |
139 | 139 | ||
140 | rversion->revision = ""; | 140 | rversion->revision = ""; |
141 | rversion->familiar_revision = ""; | 141 | rversion->familiar_revision = ""; |
142 | 142 | ||
143 | rversion->setVersion( string ); | 143 | rversion->setVersion( string ); |
144 | hyphen= strrchr(rversion->version,'-'); | 144 | hyphen= strrchr(rversion->version,'-'); |
145 | if (hyphen) { | 145 | if (hyphen) { |
146 | *hyphen++= 0; | 146 | *hyphen++= 0; |
147 | if (strncmp("fam", hyphen, 3) == 0) { | 147 | if (strncmp("fam", hyphen, 3) == 0) { |
148 | rversion->familiar_revision=hyphen+3; | 148 | rversion->familiar_revision=hyphen+3; |
149 | hyphen= strrchr(rversion->version,'-'); | 149 | hyphen= strrchr(rversion->version,'-'); |
150 | if (hyphen) { | 150 | if (hyphen) { |
151 | *hyphen++= 0; | 151 | *hyphen++= 0; |
152 | rversion->revision = hyphen; | 152 | rversion->revision = hyphen; |
153 | } | 153 | } |
154 | } else { | 154 | } else { |
155 | rversion->revision = hyphen; | 155 | rversion->revision = hyphen; |
156 | } | 156 | } |
157 | } | 157 | } |
158 | /* | 158 | /* |
159 | fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n", | 159 | fprintf(stderr,"Parsed version: %lu, %s, %s, %s\n", |
160 | rversion->epoch, | 160 | rversion->epoch, |
161 | rversion->version, | 161 | rversion->version, |
162 | rversion->revision, | 162 | rversion->revision, |
163 | rversion->familiar_revision); | 163 | rversion->familiar_revision); |
164 | */ | 164 | */ |
165 | return 0; | 165 | return 0; |
166 | } | 166 | } |
167 | 167 | ||
168 | int compareVersions( const char *v1, const char *v2 ) | 168 | int compareVersions( const char *v1, const char *v2 ) |
169 | { | 169 | { |
170 | const char *err; | 170 | const char *err; |
171 | versionrevision ver, ref; | 171 | versionrevision ver, ref; |
172 | 172 | ||
173 | err = parseversion(&ref, v1); | 173 | err = parseversion(&ref, v1); |
174 | if (err) { | 174 | if (err) { |
175 | // fprintf(stderr, "Invalid version `%s': %s\n", v2, err); | 175 | // fprintf(stderr, "Invalid version `%s': %s\n", v2, err); |
176 | return -2; | 176 | return -2; |
177 | } | 177 | } |
178 | 178 | ||
179 | err = parseversion(&ver, v2); | 179 | err = parseversion(&ver, v2); |
180 | if (err) { | 180 | if (err) { |
181 | // fprintf(stderr, "Invalid version `%s': %s\n", v1, err); | 181 | // fprintf(stderr, "Invalid version `%s': %s\n", v1, err); |
182 | return -2; | 182 | return -2; |
183 | } | 183 | } |
184 | 184 | ||
185 | if ( versionsatisfied3( &ver, &ref, "=" ) ) | 185 | if ( versionsatisfied3( &ver, &ref, "=" ) ) |
186 | return 0; | 186 | return 0; |
187 | else if ( versionsatisfied3( &ver, &ref, "<" ) ) | 187 | else if ( versionsatisfied3( &ver, &ref, "<" ) ) |
188 | return -1; | 188 | return -1; |
189 | else | 189 | else |
190 | return 1; | 190 | return 1; |
191 | } | 191 | } |
192 | 192 | ||
193 | /* | 193 | /* |
194 | int main(int argc, char *argv[]) | 194 | int main(int argc, char *argv[]) |
195 | { | 195 | { |
196 | const char *err; | 196 | const char *err; |
197 | versionrevision ver, ref; | 197 | versionrevision ver, ref; |
198 | 198 | ||
199 | if (argc < 4) { | 199 | if (argc < 4) { |
200 | fprintf(stderr, "usage: %s: version op refversion\n", argv[0]); | 200 | fprintf(stderr, "usage: %s: version op refversion\n", argv[0]); |
201 | return 2; | 201 | return 2; |
202 | } | 202 | } |
203 | 203 | ||
204 | err = parseversion(&ver, argv[1]); | 204 | err = parseversion(&ver, argv[1]); |
205 | if (err) { | 205 | if (err) { |
206 | fprintf(stderr, "Invalid version `%s': %s\n", argv[1], err); | 206 | fprintf(stderr, "Invalid version `%s': %s\n", argv[1], err); |
207 | return 2; | 207 | return 2; |
208 | } | 208 | } |
209 | 209 | ||
210 | err = parseversion(&ref, argv[3]); | 210 | err = parseversion(&ref, argv[3]); |
211 | if (err) { | 211 | if (err) { |
212 | fprintf(stderr, "Invalid version `%s': %s\n", argv[3], err); | 212 | fprintf(stderr, "Invalid version `%s': %s\n", argv[3], err); |
213 | return 2; | 213 | return 2; |
214 | } | 214 | } |
215 | 215 | ||
216 | printf( "Result: %d\n", versionsatisfied3(&ver, &ref, argv[2]) ); | 216 | printf( "Result: %d\n", versionsatisfied3(&ver, &ref, argv[2]) ); |
217 | } | 217 | } |
218 | 218 | ||
219 | */ | 219 | */ |