Diffstat (limited to 'noncore/net/opierdesktop/qtwin.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/opierdesktop/qtwin.cpp | 1725 |
1 files changed, 1725 insertions, 0 deletions
diff --git a/noncore/net/opierdesktop/qtwin.cpp b/noncore/net/opierdesktop/qtwin.cpp new file mode 100644 index 0000000..d2a5ef1 --- a/dev/null +++ b/noncore/net/opierdesktop/qtwin.cpp | |||
@@ -0,0 +1,1725 @@ | |||
1 | /* | ||
2 | rdesktop: A Remote Desktop Protocol client. | ||
3 | User interface services - X Window System | ||
4 | Copyright (C) Matthew Chapman 1999-2002 | ||
5 | qt.cpp by Jay Sorg | ||
6 | |||
7 | This program is free software; you can redistribute it and/or modify | ||
8 | it under the terms of the GNU General Public License as published by | ||
9 | the Free Software Foundation; either version 2 of the License, or | ||
10 | (at your option) any later version. | ||
11 | |||
12 | This program is distributed in the hope that it will be useful, | ||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | GNU General Public License for more details. | ||
16 | |||
17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program; if not, write to the Free Software | ||
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
20 | */ | ||
21 | |||
22 | #include "rdesktop.h" | ||
23 | #ifdef SHARP | ||
24 | #include <qpe/qpeapplication.h> | ||
25 | #else | ||
26 | #include <qapplication.h> | ||
27 | #endif | ||
28 | #include <qmainwindow.h> | ||
29 | #include <qwidget.h> | ||
30 | #include <qpainter.h> | ||
31 | #include <qimage.h> | ||
32 | #include <qsocketnotifier.h> | ||
33 | #include <qscrollview.h> | ||
34 | #include <qmessagebox.h> | ||
35 | #include <qpushbutton.h> | ||
36 | #include <qlineedit.h> | ||
37 | #include <qcombobox.h> | ||
38 | #include <qlabel.h> | ||
39 | #include <qfile.h> | ||
40 | #include <qcheckbox.h> | ||
41 | #include <qpopupmenu.h> | ||
42 | #include "qtwin.h" | ||
43 | #include <stdlib.h> | ||
44 | |||
45 | uint32 flags; | ||
46 | char server[64] = ""; | ||
47 | char domain[16] = ""; | ||
48 | char password[16] = ""; | ||
49 | char shell[128] = ""; | ||
50 | char directory[32] = ""; | ||
51 | |||
52 | extern int g_width; | ||
53 | extern int g_height; | ||
54 | extern int server_bpp; | ||
55 | extern BOOL fullscreen; | ||
56 | extern char username[]; | ||
57 | int global_sock; | ||
58 | |||
59 | QSocketNotifier* SocketNotifier; | ||
60 | #ifdef SHARP | ||
61 | QPEApplication* App; | ||
62 | #else | ||
63 | QApplication* App; | ||
64 | #endif | ||
65 | QMyMainWindow* MW; | ||
66 | QMyScrollView* SV; | ||
67 | struct QColorMap | ||
68 | { | ||
69 | uint32 RGBColors[256]; | ||
70 | int NumColors; | ||
71 | }; | ||
72 | QColorMap* CM; | ||
73 | uint8* BS; | ||
74 | int clipx; | ||
75 | int clipy; | ||
76 | int clipcx; | ||
77 | int clipcy; | ||
78 | |||
79 | struct bitmap | ||
80 | { | ||
81 | int w; | ||
82 | int h; | ||
83 | uint8* data; | ||
84 | }; | ||
85 | |||
86 | BOOL owncolmap = False; | ||
87 | |||
88 | //***************************************************************************** | ||
89 | void CleanString(QString* Item) | ||
90 | { | ||
91 | int i; | ||
92 | |||
93 | i = Item->length() - 1; | ||
94 | while (i >= 0) | ||
95 | { | ||
96 | if (Item->at(i) == 10 || Item->at(i) == 13) | ||
97 | Item->remove(i, 1); | ||
98 | i--; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | //***************************************************************************** | ||
103 | QMyDialog::QMyDialog(QWidget* parent) : QDialog(parent, "Settings", true) | ||
104 | { | ||
105 | int i, j; | ||
106 | char* home; | ||
107 | char Text[256]; | ||
108 | QString Line; | ||
109 | QString ItemName; | ||
110 | QString ItemValue; | ||
111 | |||
112 | // resize dialog | ||
113 | resize(230, 270); | ||
114 | // main list box | ||
115 | ListBox = new QListBox(this); | ||
116 | ListBox->move(10, 10); | ||
117 | ListBox->resize(200, 100); | ||
118 | connect(ListBox, SIGNAL(selectionChanged()), this, SLOT(ListBoxChanged())); | ||
119 | connect(ListBox, SIGNAL(selected(int)), this, SLOT(ListBoxSelected(int))); | ||
120 | // server | ||
121 | Label1 = new QLabel(this); | ||
122 | Label1->setText("Server Desc"); | ||
123 | Label1->move(10, 120); | ||
124 | Label1->resize(100, 20); | ||
125 | ServerNameEdit = new QLineEdit(this); | ||
126 | ServerNameEdit->move(75, 120); | ||
127 | ServerNameEdit->resize(100, 20); | ||
128 | // username | ||
129 | Label2 = new QLabel(this); | ||
130 | Label2->setText("User Name"); | ||
131 | Label2->move(10, 150); | ||
132 | Label2->resize(100, 20); | ||
133 | UserNameEdit = new QLineEdit(this); | ||
134 | UserNameEdit->move(75, 150); | ||
135 | UserNameEdit->resize(100, 20); | ||
136 | // ip | ||
137 | Label3 = new QLabel(this); | ||
138 | Label3->setText("Server IP"); | ||
139 | Label3->move(10, 180); | ||
140 | Label3->resize(100, 20); | ||
141 | IPEdit = new QLineEdit(this); | ||
142 | IPEdit->move(75, 180); | ||
143 | IPEdit->resize(100, 20); | ||
144 | // width and height | ||
145 | WidthHeightBox = new QComboBox(this); | ||
146 | WidthHeightBox->move(10, 210); | ||
147 | WidthHeightBox->resize(100, 20); | ||
148 | WidthHeightBox->insertItem("240x320"); | ||
149 | WidthHeightBox->insertItem("640x480"); | ||
150 | WidthHeightBox->insertItem("800x600"); | ||
151 | connect(WidthHeightBox, SIGNAL(activated(int)), this, SLOT(ComboChanged(int))); | ||
152 | WidthHeightBox->setCurrentItem(1); | ||
153 | WidthEdit = new QLineEdit(this); | ||
154 | WidthEdit->move(110, 210); | ||
155 | WidthEdit->resize(30, 20); | ||
156 | WidthEdit->setText("800"); | ||
157 | HeightEdit = new QLineEdit(this); | ||
158 | HeightEdit->move(140, 210); | ||
159 | HeightEdit->resize(30, 20); | ||
160 | HeightEdit->setText("600"); | ||
161 | // add to list button | ||
162 | AddButton = new QPushButton(this); | ||
163 | AddButton->move(180, 120); | ||
164 | AddButton->resize(50, 20); | ||
165 | AddButton->setText("Add"); | ||
166 | connect(AddButton, SIGNAL(clicked()), this, SLOT(AddClicked())); | ||
167 | // change list item button | ||
168 | EditButton = new QPushButton(this); | ||
169 | EditButton->move(180, 140); | ||
170 | EditButton->resize(50, 20); | ||
171 | EditButton->setText("Edit"); | ||
172 | connect(EditButton, SIGNAL(clicked()), this, SLOT(EditClicked())); | ||
173 | // save to file button | ||
174 | SaveButton = new QPushButton(this); | ||
175 | SaveButton->move(180, 160); | ||
176 | SaveButton->resize(50, 20); | ||
177 | SaveButton->setText("Save"); | ||
178 | connect(SaveButton, SIGNAL(clicked()), this, SLOT(SaveClicked())); | ||
179 | // remove an item button | ||
180 | RemoveButton = new QPushButton(this); | ||
181 | RemoveButton->move(180, 180); | ||
182 | RemoveButton->resize(50, 20); | ||
183 | RemoveButton->setText("Remove"); | ||
184 | connect(RemoveButton, SIGNAL(clicked()), this, SLOT(RemoveClicked())); | ||
185 | // full screen check box | ||
186 | FullScreenCheckBox = new QCheckBox(this, "Full Screen"); | ||
187 | FullScreenCheckBox->setText("Full Screen"); | ||
188 | FullScreenCheckBox->move(10, 230); | ||
189 | // ok button | ||
190 | OKButton = new QPushButton(this); | ||
191 | OKButton->setText("OK"); | ||
192 | OKButton->move(100, 240); | ||
193 | OKButton->resize(50, 20); | ||
194 | connect(OKButton, SIGNAL(clicked()), this, SLOT(OKClicked())); | ||
195 | // cancel button | ||
196 | CancelButton = new QPushButton(this); | ||
197 | CancelButton->setText("Cancel"); | ||
198 | CancelButton->move(160, 240); | ||
199 | CancelButton->resize(50, 20); | ||
200 | connect(CancelButton, SIGNAL(clicked()), this, SLOT(CancelClicked())); | ||
201 | |||
202 | for (i = 0; i < 10; i++) | ||
203 | { | ||
204 | ConnectionList[i] = new QMyConnectionItem; | ||
205 | ConnectionList[i]->ServerName = ""; | ||
206 | ConnectionList[i]->UserName = ""; | ||
207 | ConnectionList[i]->ServerIP = ""; | ||
208 | ConnectionList[i]->Width = 0; | ||
209 | ConnectionList[i]->Height = 0; | ||
210 | ConnectionList[i]->FullScreen = 0; | ||
211 | } | ||
212 | home = getenv("HOME"); | ||
213 | if (home != NULL) | ||
214 | { | ||
215 | sprintf(Text, "%s/rdesktop.ini", home); | ||
216 | QFile* File = new QFile(Text); | ||
217 | if (File->open(IO_ReadOnly)) | ||
218 | { | ||
219 | i = -1; | ||
220 | while (!File->atEnd()) | ||
221 | { | ||
222 | File->readLine(Line, 255); | ||
223 | j = Line.find("="); | ||
224 | if (j > 0) | ||
225 | { | ||
226 | ItemName = Line.mid(0, j); | ||
227 | CleanString(&ItemName); | ||
228 | ItemValue = Line.mid(j + 1); | ||
229 | CleanString(&ItemValue); | ||
230 | if (ItemName == "Server") | ||
231 | { | ||
232 | i++; | ||
233 | ConnectionList[i]->ServerName = ItemValue; | ||
234 | ListBox->insertItem(ItemValue); | ||
235 | } | ||
236 | else if (ItemName == "UserName") | ||
237 | ConnectionList[i]->UserName = ItemValue; | ||
238 | else if (ItemName == "Width") | ||
239 | ConnectionList[i]->Width = ItemValue.toInt(); | ||
240 | else if (ItemName == "Height") | ||
241 | ConnectionList[i]->Height = ItemValue.toInt(); | ||
242 | else if (ItemName == "IP") | ||
243 | ConnectionList[i]->ServerIP = ItemValue; | ||
244 | else if (ItemName == "FullScreen") | ||
245 | ConnectionList[i]->FullScreen = (ItemValue != "0"); | ||
246 | } | ||
247 | } | ||
248 | } | ||
249 | delete File; | ||
250 | } | ||
251 | } | ||
252 | |||
253 | //***************************************************************************** | ||
254 | QMyDialog::~QMyDialog() | ||
255 | { | ||
256 | QMyConnectionItem* Item; | ||
257 | int i; | ||
258 | |||
259 | for (i = 0; i < 10; i++) | ||
260 | { | ||
261 | Item = ConnectionList[i]; | ||
262 | delete Item; | ||
263 | } | ||
264 | } | ||
265 | |||
266 | //***************************************************************************** | ||
267 | void QMyDialog::ComboChanged(int index) | ||
268 | { | ||
269 | if (index == 0) | ||
270 | { | ||
271 | WidthEdit->setText("240"); | ||
272 | HeightEdit->setText("320"); | ||
273 | } | ||
274 | if (index == 1) | ||
275 | { | ||
276 | WidthEdit->setText("640"); | ||
277 | HeightEdit->setText("480"); | ||
278 | } | ||
279 | else if (index == 2) | ||
280 | { | ||
281 | WidthEdit->setText("800"); | ||
282 | HeightEdit->setText("600"); | ||
283 | } | ||
284 | } | ||
285 | |||
286 | //***************************************************************************** | ||
287 | void QMyDialog::OKClicked() | ||
288 | { | ||
289 | ServerName = ServerNameEdit->text(); | ||
290 | UserName = UserNameEdit->text(); | ||
291 | Width = WidthEdit->text().toInt(); | ||
292 | Height = HeightEdit->text().toInt(); | ||
293 | ServerIP = IPEdit->text(); | ||
294 | FullScreen = FullScreenCheckBox->isChecked(); | ||
295 | done(1); | ||
296 | } | ||
297 | |||
298 | //***************************************************************************** | ||
299 | void QMyDialog::CancelClicked() | ||
300 | { | ||
301 | done(0); | ||
302 | } | ||
303 | |||
304 | //***************************************************************************** | ||
305 | void QMyDialog::AddClicked() | ||
306 | { | ||
307 | int i; | ||
308 | QMyConnectionItem* Item; | ||
309 | |||
310 | i = ListBox->count(); | ||
311 | if (i < 10) | ||
312 | { | ||
313 | ListBox->insertItem(ServerNameEdit->text()); | ||
314 | Item = ConnectionList[i]; | ||
315 | Item->ServerName = ServerNameEdit->text(); | ||
316 | Item->UserName = UserNameEdit->text(); | ||
317 | Item->Width = WidthEdit->text().toInt(); | ||
318 | Item->Height = HeightEdit->text().toInt(); | ||
319 | Item->ServerIP = IPEdit->text(); | ||
320 | Item->FullScreen = FullScreenCheckBox->isChecked(); | ||
321 | } | ||
322 | } | ||
323 | |||
324 | //***************************************************************************** | ||
325 | void QMyDialog::EditClicked() | ||
326 | { | ||
327 | int i; | ||
328 | QMyConnectionItem* Item; | ||
329 | |||
330 | i = ListBox->currentItem(); | ||
331 | if (i >= 0) | ||
332 | { | ||
333 | Item = ConnectionList[i]; | ||
334 | Item->ServerName = ServerNameEdit->text(); | ||
335 | Item->UserName = UserNameEdit->text(); | ||
336 | Item->Width = WidthEdit->text().toInt(); | ||
337 | Item->Height = HeightEdit->text().toInt(); | ||
338 | Item->ServerIP = IPEdit->text(); | ||
339 | Item->FullScreen = FullScreenCheckBox->isChecked(); | ||
340 | ListBox->changeItem(ServerNameEdit->text(), i); | ||
341 | } | ||
342 | } | ||
343 | |||
344 | //***************************************************************************** | ||
345 | void WriteString(QFile* File, QString* Line) | ||
346 | { | ||
347 | File->writeBlock((const char*)(*Line), Line->length()); | ||
348 | } | ||
349 | |||
350 | //***************************************************************************** | ||
351 | void QMyDialog::SaveClicked() | ||
352 | { | ||
353 | int i, j; | ||
354 | QMyConnectionItem* Item; | ||
355 | QString Line; | ||
356 | char* home; | ||
357 | char Text[256]; | ||
358 | QFile* File; | ||
359 | |||
360 | home = getenv("HOME"); | ||
361 | if (home != NULL) | ||
362 | { | ||
363 | sprintf(Text, "%s/rdesktop.ini", home); | ||
364 | File = new QFile(Text); | ||
365 | if (File->open(IO_Truncate | IO_ReadWrite)) | ||
366 | { | ||
367 | i = ListBox->count(); | ||
368 | for (j = 0; j < i; j++) | ||
369 | { | ||
370 | Item = ConnectionList[j]; | ||
371 | Line = "Server="; | ||
372 | Line += Item->ServerName; | ||
373 | Line += (char)10; | ||
374 | WriteString(File, &Line); | ||
375 | Line = "UserName="; | ||
376 | Line += Item->UserName; | ||
377 | Line += (char)10; | ||
378 | WriteString(File, &Line); | ||
379 | Line = "Width="; | ||
380 | sprintf(Text, "%d", Item->Width); | ||
381 | Line += Text; | ||
382 | Line += (char)10; | ||
383 | WriteString(File, &Line); | ||
384 | Line = "Height="; | ||
385 | sprintf(Text, "%d", Item->Height); | ||
386 | Line += Text; | ||
387 | Line += (char)10; | ||
388 | WriteString(File, &Line); | ||
389 | Line = "IP="; | ||
390 | Line += Item->ServerIP; | ||
391 | Line += (char)10; | ||
392 | WriteString(File, &Line); | ||
393 | Line = "FullScreen="; | ||
394 | if (Item->FullScreen) | ||
395 | Line += "1"; | ||
396 | else | ||
397 | Line += "0"; | ||
398 | Line += (char)10; | ||
399 | WriteString(File, &Line); | ||
400 | } | ||
401 | } | ||
402 | File->flush(); | ||
403 | File->close(); | ||
404 | delete File; | ||
405 | } | ||
406 | } | ||
407 | |||
408 | //***************************************************************************** | ||
409 | void QMyDialog::RemoveClicked() | ||
410 | { | ||
411 | int i, j, c; | ||
412 | QMyConnectionItem* Item1; | ||
413 | QMyConnectionItem* Item2; | ||
414 | |||
415 | i = ListBox->currentItem(); | ||
416 | if (i >= 0) | ||
417 | { | ||
418 | c = ListBox->count(); | ||
419 | for (j = i; j < c - 1; j++) | ||
420 | { | ||
421 | Item1 = ConnectionList[i]; | ||
422 | Item2 = ConnectionList[i + 1]; | ||
423 | Item1->ServerName = Item2->ServerName; | ||
424 | Item1->UserName = Item2->UserName; | ||
425 | Item1->Width = Item2->Width; | ||
426 | Item1->Height = Item2->Height; | ||
427 | Item1->ServerIP = Item2->ServerIP; | ||
428 | Item1->FullScreen = Item2->FullScreen; | ||
429 | } | ||
430 | ListBox->removeItem(i); | ||
431 | } | ||
432 | } | ||
433 | |||
434 | //***************************************************************************** | ||
435 | void QMyDialog::ListBoxChanged() | ||
436 | { | ||
437 | int i; | ||
438 | QMyConnectionItem* Item; | ||
439 | char Text[100]; | ||
440 | |||
441 | i = ListBox->currentItem(); | ||
442 | if (i >= 0 && i < 10) | ||
443 | { | ||
444 | Item = ConnectionList[i]; | ||
445 | ServerNameEdit->setText(Item->ServerName); | ||
446 | UserNameEdit->setText(Item->UserName); | ||
447 | sprintf(Text, "%d", Item->Width); | ||
448 | WidthEdit->setText(Text); | ||
449 | sprintf(Text, "%d", Item->Height); | ||
450 | HeightEdit->setText(Text); | ||
451 | IPEdit->setText(Item->ServerIP); | ||
452 | FullScreenCheckBox->setChecked(Item->FullScreen != 0); | ||
453 | } | ||
454 | } | ||
455 | |||
456 | //***************************************************************************** | ||
457 | void QMyDialog::ListBoxSelected(int /*index*/) | ||
458 | { | ||
459 | } | ||
460 | |||
461 | //***************************************************************************** | ||
462 | void GetScanCode(QKeyEvent* e, int* ScanCode, int* code) | ||
463 | { | ||
464 | int key; | ||
465 | int mod; | ||
466 | int ascii; | ||
467 | |||
468 | key = e->key(); | ||
469 | mod = e->state(); | ||
470 | ascii = e->ascii(); | ||
471 | |||
472 | *ScanCode = 0; | ||
473 | *code = mod; // 8 shift, 16 control, 32 alt | ||
474 | |||
475 | switch (key) | ||
476 | { | ||
477 | case 4096: // esc | ||
478 | case 4097: // tab | ||
479 | case 4099: // backspace | ||
480 | case 4100: // enter | ||
481 | case 4101: // enter | ||
482 | case 4103: // delete | ||
483 | ascii = 0; | ||
484 | } | ||
485 | |||
486 | if (ascii == 0) | ||
487 | { | ||
488 | switch (key) | ||
489 | { | ||
490 | case 4096: *ScanCode = 0x01; break; // esc | ||
491 | case 4097: *ScanCode = 0x0f; break; // tab | ||
492 | case 4099: *ScanCode = 0x0e; break; // backspace | ||
493 | case 4100: *ScanCode = 0x1c; break; // enter | ||
494 | case 4101: *ScanCode = 0x1c; break; // enter | ||
495 | case 4112: *ScanCode = 0xc7; break; // home | ||
496 | case 4113: *ScanCode = 0xcf; break; // end | ||
497 | case 4102: *ScanCode = 0xd2; break; // insert | ||
498 | case 4103: *ScanCode = 0xd3; break; // delete | ||
499 | case 4118: *ScanCode = 0xc9; break; // page up | ||
500 | case 4119: *ScanCode = 0xd1; break; // page down | ||
501 | case 4117: *ScanCode = 0xd0; break; // down arrow | ||
502 | case 4115: *ScanCode = 0xc8; break; // up arrow | ||
503 | case 4114: *ScanCode = 0xcb; break; // left arrow | ||
504 | case 4116: *ScanCode = 0xcd; break; // right arrow | ||
505 | case 4128: *ScanCode = 0x2a; break; // shift | ||
506 | case 4131: *ScanCode = 0x38; break; // alt | ||
507 | case 4129: *ScanCode = 0x1d; break; // ctrl | ||
508 | } | ||
509 | if (*ScanCode != 0) | ||
510 | return; | ||
511 | } | ||
512 | |||
513 | switch (ascii) | ||
514 | { | ||
515 | // first row | ||
516 | case 'q': *ScanCode = 0x10; break; | ||
517 | case 'Q': *ScanCode = 0x10; *code |= 8; break; | ||
518 | case '1': *ScanCode = 0x02; break; | ||
519 | case 'w': *ScanCode = 0x11; break; | ||
520 | case 'W': *ScanCode = 0x11; *code |= 8; break; | ||
521 | case '2': *ScanCode = 0x03; break; | ||
522 | case 'e': *ScanCode = 0x12; break; | ||
523 | case 'E': *ScanCode = 0x12; *code |= 8; break; | ||
524 | case '3': *ScanCode = 0x04; break; | ||
525 | case 'r': *ScanCode = 0x13; break; | ||
526 | case 'R': *ScanCode = 0x13; *code |= 8; break; | ||
527 | case '4': *ScanCode = 0x05; break; | ||
528 | case 't': *ScanCode = 0x14; break; | ||
529 | case 'T': *ScanCode = 0x14; *code |= 8; break; | ||
530 | case '5': *ScanCode = 0x06; break; | ||
531 | case 'y': *ScanCode = 0x15; break; | ||
532 | case 'Y': *ScanCode = 0x15; *code |= 8; break; | ||
533 | case '6': *ScanCode = 0x07; break; | ||
534 | case 'u': *ScanCode = 0x16; break; | ||
535 | case 'U': *ScanCode = 0x16; *code |= 8; break; | ||
536 | case '7': *ScanCode = 0x08; break; | ||
537 | case 'i': *ScanCode = 0x17; break; | ||
538 | case 'I': *ScanCode = 0x17; *code |= 8; break; | ||
539 | case '8': *ScanCode = 0x09; break; | ||
540 | case 'o': *ScanCode = 0x18; break; | ||
541 | case 'O': *ScanCode = 0x18; *code |= 8; break; | ||
542 | case '9': *ScanCode = 0x0a; break; | ||
543 | case 'p': *ScanCode = 0x19; break; | ||
544 | case 'P': *ScanCode = 0x19; *code |= 8; break; | ||
545 | case '0': *ScanCode = 0x0b; break; | ||
546 | // second row | ||
547 | case 'a': *ScanCode = 0x1e; break; | ||
548 | case 'A': *ScanCode = 0x1e; *code |= 8; break; | ||
549 | case '!': *ScanCode = 0x02; *code |= 8; break; | ||
550 | case 's': *ScanCode = 0x1f; break; | ||
551 | case 'S': *ScanCode = 0x1f; *code |= 8; break; | ||
552 | case '@': *ScanCode = 0x03; *code |= 8; break; | ||
553 | case 'd': *ScanCode = 0x20; break; | ||
554 | case 'D': *ScanCode = 0x20; *code |= 8; break; | ||
555 | case '#': *ScanCode = 0x04; *code |= 8; break; | ||
556 | case 'f': *ScanCode = 0x21; break; | ||
557 | case 'F': *ScanCode = 0x21; *code |= 8; break; | ||
558 | case '$': *ScanCode = 0x05; *code |= 8; break; | ||
559 | case 'g': *ScanCode = 0x22; break; | ||
560 | case 'G': *ScanCode = 0x22; *code |= 8; break; | ||
561 | case '%': *ScanCode = 0x06; *code |= 8; break; | ||
562 | case 'h': *ScanCode = 0x23; break; | ||
563 | case 'H': *ScanCode = 0x23; *code |= 8; break; | ||
564 | case '_': *ScanCode = 0x0c; *code |= 8; break; | ||
565 | case 'j': *ScanCode = 0x24; break; | ||
566 | case 'J': *ScanCode = 0x24; *code |= 8; break; | ||
567 | case '&': *ScanCode = 0x08; *code |= 8; break; | ||
568 | case 'k': *ScanCode = 0x25; break; | ||
569 | case 'K': *ScanCode = 0x25; *code |= 8; break; | ||
570 | case '*': *ScanCode = 0x09; *code |= 8; break; | ||
571 | case 'l': *ScanCode = 0x26; break; | ||
572 | case 'L': *ScanCode = 0x26; *code |= 8; break; | ||
573 | case '(': *ScanCode = 0x0a; *code |= 8; break; | ||
574 | // case 8: *ScanCode = 0x0e; break; // backspace | ||
575 | // third row | ||
576 | case 'z': *ScanCode = 0x2c; break; | ||
577 | case 'Z': *ScanCode = 0x2c; *code |= 8; break; | ||
578 | case 'x': *ScanCode = 0x2d; break; | ||
579 | case 'X': *ScanCode = 0x2d; *code |= 8; break; | ||
580 | case 'c': *ScanCode = 0x2e; break; | ||
581 | case 'C': *ScanCode = 0x2e; *code |= 8; break; | ||
582 | case 'v': *ScanCode = 0x2f; break; | ||
583 | case 'V': *ScanCode = 0x2f; *code |= 8; break; | ||
584 | case 'b': *ScanCode = 0x30; break; | ||
585 | case 'B': *ScanCode = 0x30; *code |= 8; break; | ||
586 | case '-': *ScanCode = 0x0c; break; | ||
587 | case 'n': *ScanCode = 0x31; break; | ||
588 | case 'N': *ScanCode = 0x31; *code |= 8; break; | ||
589 | case '+': *ScanCode = 0x0d; *code |= 8; break; | ||
590 | case 'm': *ScanCode = 0x32; break; | ||
591 | case 'M': *ScanCode = 0x32; *code |= 8; break; | ||
592 | case '=': *ScanCode = 0x0d; break; | ||
593 | case ',': *ScanCode = 0x33; break; | ||
594 | case ';': *ScanCode = 0x27; break; | ||
595 | case ')': *ScanCode = 0x0b; *code |= 8; break; | ||
596 | // fourth row | ||
597 | // case 9: *ScanCode = 0x0f; break; // tab | ||
598 | case '/': *ScanCode = 0x35; break; | ||
599 | case '?': *ScanCode = 0x35; *code |= 8; break; | ||
600 | case ' ': *ScanCode = 0x39; break; | ||
601 | case '\'': *ScanCode = 0x28; break; | ||
602 | case '"': *ScanCode = 0x28; *code |= 8; break; | ||
603 | case '~': *ScanCode = 0x29; *code |= 8; break; | ||
604 | case '.': *ScanCode = 0x34; break; | ||
605 | case ':': *ScanCode = 0x27; *code |= 8; break; | ||
606 | case '<': *ScanCode = 0x33; *code |= 8; break; | ||
607 | // case 13: *ScanCode = 0x1c; break; // enter | ||
608 | case '>': *ScanCode = 0x34; *code |= 8; break; | ||
609 | // others | ||
610 | // case 27: *ScanCode = 0x01; break; // esc | ||
611 | case '`': *ScanCode = 0x29; break; | ||
612 | case '^': *ScanCode = 0x07; *code |= 8; break; | ||
613 | case '[': *ScanCode = 0x1a; break; | ||
614 | case '{': *ScanCode = 0x1a; *code |= 8; break; | ||
615 | case ']': *ScanCode = 0x1b; break; | ||
616 | case '}': *ScanCode = 0x1b; *code |= 8; break; | ||
617 | case '\\': *ScanCode = 0x2b; break; | ||
618 | case '|': *ScanCode = 0x2b; *code |= 8; break; | ||
619 | // ctrl keys | ||
620 | case 1: *ScanCode = 0x1e; *code |= 16; break; // a | ||
621 | case 2: *ScanCode = 0x30; *code |= 16; break; // b | ||
622 | } | ||
623 | |||
624 | if (*ScanCode == 0 && key < 3000) | ||
625 | printf("unknown key %d mod %d ascii %d\n", key, mod, ascii); | ||
626 | |||
627 | } | ||
628 | |||
629 | //***************************************************************************** | ||
630 | QMyScrollView::QMyScrollView() : QScrollView() | ||
631 | { | ||
632 | } | ||
633 | |||
634 | //***************************************************************************** | ||
635 | QMyScrollView::~QMyScrollView() | ||
636 | { | ||
637 | } | ||
638 | |||
639 | //***************************************************************************** | ||
640 | void QMyScrollView::keyPressEvent(QKeyEvent* e) | ||
641 | { | ||
642 | int ScanCode, code; | ||
643 | GetScanCode(e, &ScanCode, &code); | ||
644 | if (ScanCode != 0) | ||
645 | { | ||
646 | if (code & 8) // send shift | ||
647 | rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x2a, 0); | ||
648 | if (code & 16) // send control | ||
649 | rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x1d, 0); | ||
650 | if (code & 32) // send alt | ||
651 | rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x38, 0); | ||
652 | rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYPRESS, ScanCode, 0); | ||
653 | e->accept(); | ||
654 | } | ||
655 | } | ||
656 | |||
657 | //***************************************************************************** | ||
658 | void QMyScrollView::keyReleaseEvent(QKeyEvent* e) | ||
659 | { | ||
660 | int ScanCode, code; | ||
661 | GetScanCode(e, &ScanCode, &code); | ||
662 | if (ScanCode != 0) | ||
663 | { | ||
664 | rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, ScanCode, 0); | ||
665 | if (code & 8) // send shift | ||
666 | rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, 0x2a, 0); | ||
667 | if (code & 16) // send control | ||
668 | rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, 0x1d, 0); | ||
669 | if (code & 32) // send alt | ||
670 | rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, 0x38, 0); | ||
671 | e->accept(); | ||
672 | } | ||
673 | } | ||
674 | |||
675 | //***************************************************************************** | ||
676 | void QMyScrollView::showEvent(QShowEvent* e) | ||
677 | { | ||
678 | QScrollView::showEvent(e); | ||
679 | } | ||
680 | |||
681 | //***************************************************************************** | ||
682 | void QMyScrollView::show() | ||
683 | { | ||
684 | QScrollView::show(); | ||
685 | } | ||
686 | |||
687 | //***************************************************************************** | ||
688 | void QMyScrollView::polish() | ||
689 | { | ||
690 | QScrollView::polish(); | ||
691 | } | ||
692 | |||
693 | //***************************************************************************** | ||
694 | void QMyScrollView::timerEvent(QTimerEvent* e) | ||
695 | { | ||
696 | QScrollView::timerEvent(e); | ||
697 | killTimer(timer_id); | ||
698 | QMyDialog* d; | ||
699 | QWidget* Desktop; | ||
700 | int dw; | ||
701 | int dh; | ||
702 | |||
703 | d = new QMyDialog(this); | ||
704 | if (d->exec() == 1) // ok clicked | ||
705 | { | ||
706 | flags = RDP_LOGON_NORMAL; | ||
707 | g_width = d->Width; | ||
708 | g_height = d->Height; | ||
709 | fullscreen = d->FullScreen; | ||
710 | sprintf(server, "%s", (const char*)d->ServerIP); | ||
711 | sprintf(username, "%s", (const char*)d->UserName); | ||
712 | if (!rdp_connect(server, flags, domain, password, shell, directory)) | ||
713 | { | ||
714 | delete d; | ||
715 | SV->close(); | ||
716 | return; | ||
717 | } | ||
718 | BS = (uint8*)xmalloc(g_width * g_height); | ||
719 | memset(BS, 0, g_width * g_height); | ||
720 | clipx = 0; | ||
721 | clipy = 0; | ||
722 | clipcx = g_width; | ||
723 | clipcy = g_height; | ||
724 | CM = (QColorMap*)xmalloc(sizeof(struct QColorMap)); | ||
725 | memset(CM, 0, sizeof(struct QColorMap)); | ||
726 | CM->NumColors = 256; | ||
727 | MW = new QMyMainWindow(); | ||
728 | MW->resize(g_width, g_height); | ||
729 | MW->show(); | ||
730 | SV->addChild(MW); | ||
731 | MW->setMouseTracking(true); | ||
732 | SocketNotifier = new QSocketNotifier(global_sock, QSocketNotifier::Read, MW); | ||
733 | MW->connect(SocketNotifier, SIGNAL(activated(int)), MW, SLOT(dataReceived())); | ||
734 | if (fullscreen) | ||
735 | { | ||
736 | Desktop = App->desktop(); | ||
737 | dw = Desktop->width(); | ||
738 | dh = Desktop->height(); | ||
739 | if (dw == g_width && dh == g_height) | ||
740 | MW->resize(g_width - 4, g_height - 4); | ||
741 | SV->showFullScreen(); | ||
742 | } | ||
743 | delete d; | ||
744 | } | ||
745 | else // cancel clicked | ||
746 | { | ||
747 | delete d; | ||
748 | SV->close(); | ||
749 | } | ||
750 | } | ||
751 | |||
752 | //***************************************************************************** | ||
753 | QMyMainWindow::QMyMainWindow() : QWidget(SV->viewport()) | ||
754 | { | ||
755 | PopupMenu = new QPopupMenu(this); | ||
756 | PopupMenu->insertItem("Right click", 1, 0); | ||
757 | PopupMenu->insertItem("Toggle fullscreen", 2, 1); | ||
758 | PopupMenu->insertItem("Reset keyboard", 3, 2); | ||
759 | PopupMenu->insertItem("Double click", 4, 3); | ||
760 | connect(PopupMenu, SIGNAL(activated(int)), this, SLOT(MemuClicked(int))); | ||
761 | } | ||
762 | |||
763 | //***************************************************************************** | ||
764 | QMyMainWindow::~QMyMainWindow() | ||
765 | { | ||
766 | delete PopupMenu; | ||
767 | } | ||
768 | |||
769 | //***************************************************************************** | ||
770 | void QMyMainWindow::timerEvent(QTimerEvent* e) | ||
771 | { | ||
772 | QWidget::timerEvent(e); | ||
773 | if (e->timerId() == timer_id) | ||
774 | { | ||
775 | // send mouse up | ||
776 | rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1, mx, my); | ||
777 | // if in fullscreen, take it out or the menu won't work | ||
778 | if (fullscreen) | ||
779 | { | ||
780 | fullscreen = 0; | ||
781 | SV->showNormal(); | ||
782 | SV->showMaximized(); | ||
783 | } | ||
784 | else | ||
785 | PopupMenu->popup(mapToGlobal(QPoint(mx, my))); | ||
786 | } | ||
787 | killTimer(timer_id); | ||
788 | } | ||
789 | |||
790 | //***************************************************************************** | ||
791 | void QMyMainWindow::MemuClicked(int MenuID) | ||
792 | { | ||
793 | QWidget* Desktop; | ||
794 | int dw; | ||
795 | int dh; | ||
796 | |||
797 | if (MenuID == 1) // right click | ||
798 | { | ||
799 | rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON2, mx, my); | ||
800 | rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON2, mx, my); | ||
801 | } | ||
802 | else if (MenuID == 2) // toggle full screen | ||
803 | { | ||
804 | fullscreen = ~fullscreen; | ||
805 | if (fullscreen) | ||
806 | { | ||
807 | Desktop = App->desktop(); | ||
808 | dw = Desktop->width(); | ||
809 | dh = Desktop->height(); | ||
810 | if (dw == g_width && dh == g_height) | ||
811 | MW->resize(g_width - 4, g_height - 4); | ||
812 | SV->showFullScreen(); | ||
813 | } | ||
814 | else | ||
815 | { | ||
816 | SV->showNormal(); | ||
817 | SV->showMaximized(); | ||
818 | MW->resize(g_width, g_height); | ||
819 | } | ||
820 | } | ||
821 | else if (MenuID == 3) // reset keyboard | ||
822 | { | ||
823 | rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, 0x2a, 0); // shift | ||
824 | rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, 0x1d, 0); // control | ||
825 | rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, 0x38, 0); // alt | ||
826 | } | ||
827 | else if (MenuID == 4) // double click | ||
828 | { | ||
829 | rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON1, mx, my); | ||
830 | rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1, mx, my); | ||
831 | rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON1, mx, my); | ||
832 | rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1, mx, my); | ||
833 | } | ||
834 | } | ||
835 | |||
836 | //***************************************************************************** | ||
837 | void QMyMainWindow::mouseMoveEvent(QMouseEvent* e) | ||
838 | { | ||
839 | int x; | ||
840 | int y; | ||
841 | |||
842 | x = e->x(); | ||
843 | y = e->y(); | ||
844 | |||
845 | if (timer_id) | ||
846 | { | ||
847 | x = x - mx; | ||
848 | y = y - my; | ||
849 | if (x < -10 || x > 10 || y < -10 || y > 10) | ||
850 | { | ||
851 | killTimer(timer_id); | ||
852 | timer_id = 0; | ||
853 | } | ||
854 | } | ||
855 | rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_MOVE, e->x(), e->y()); | ||
856 | } | ||
857 | |||
858 | //***************************************************************************** | ||
859 | void QMyMainWindow::mousePressEvent(QMouseEvent* e) | ||
860 | { | ||
861 | timer_id = startTimer(1000); | ||
862 | mx = e->x(); | ||
863 | my = e->y(); | ||
864 | if (e->button() == LeftButton) | ||
865 | rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON1, e->x(), e->y()); | ||
866 | else if (e->button() == RightButton) | ||
867 | rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON2, e->x(), e->y()); | ||
868 | else if (e->button() == MidButton) | ||
869 | rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON3, e->x(), e->y()); | ||
870 | } | ||
871 | |||
872 | //***************************************************************************** | ||
873 | void QMyMainWindow::mouseReleaseEvent(QMouseEvent* e) | ||
874 | { | ||
875 | killTimer(timer_id); | ||
876 | timer_id = 0; | ||
877 | if (e->button() == LeftButton) | ||
878 | rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1, e->x(), e->y()); | ||
879 | else if (e->button() == RightButton) | ||
880 | rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON2, e->x(), e->y()); | ||
881 | else if (e->button() == MidButton) | ||
882 | rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON3, e->x(), e->y()); | ||
883 | } | ||
884 | |||
885 | //***************************************************************************** | ||
886 | void QMyMainWindow::wheelEvent(QWheelEvent* e) | ||
887 | { | ||
888 | if (e->delta() > 0) | ||
889 | rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON4, e->x(), e->y()); | ||
890 | else if (e->delta() < 0) | ||
891 | rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON5, e->x(), e->y()); | ||
892 | } | ||
893 | |||
894 | #define NOT(x) (255-(x)) | ||
895 | |||
896 | //***************************************************************************** | ||
897 | uint8 rop(int rop, uint8 src, uint8 dst) | ||
898 | { | ||
899 | switch (rop) | ||
900 | { | ||
901 | case 0x0: return 0; | ||
902 | case 0x1: return NOT (src | dst); | ||
903 | case 0x2: return NOT (src) & dst; | ||
904 | case 0x3: return NOT (src); | ||
905 | case 0x4: return src & NOT (dst); | ||
906 | case 0x5: return NOT (dst); | ||
907 | case 0x6: return src ^ dst; | ||
908 | case 0x7: return NOT (src & dst); | ||
909 | case 0x8: return src & dst; | ||
910 | case 0x9: return NOT (src) ^ dst; | ||
911 | case 0xa: return dst; | ||
912 | case 0xb: return NOT (src) | dst; | ||
913 | case 0xc: return src; | ||
914 | case 0xd: return src | NOT (dst); | ||
915 | case 0xe: return src | dst; | ||
916 | case 0xf: return NOT (0); | ||
917 | } | ||
918 | return dst; | ||
919 | } | ||
920 | |||
921 | //***************************************************************************** | ||
922 | uint8 get_pixel(int x, int y) | ||
923 | { | ||
924 | if (x >= 0 && x < g_width && y >= 0 && y < g_height) | ||
925 | return BS[y * g_width + x]; | ||
926 | else | ||
927 | return 0; | ||
928 | } | ||
929 | |||
930 | //***************************************************************************** | ||
931 | void set_pixel(int x, int y, uint8 pixel, int op = 0xc) | ||
932 | { | ||
933 | if (x >= clipx && x < (clipx + clipcx) && y >= clipy && y < (clipy + clipcy)) | ||
934 | if (x >= 0 && x < g_width && y >= 0 && y < g_height) | ||
935 | if (op == 0xc) | ||
936 | BS[y * g_width + x] = pixel; | ||
937 | else | ||
938 | BS[y * g_width + x] = rop(op, pixel, BS[y * g_width + x]); | ||
939 | } | ||
940 | |||
941 | //****************************************************************************** | ||
942 | // adjust coordinates for cliping rect | ||
943 | bool WarpCoords(int* x, int* y, int* cx, int* cy, int* srcx, int* srcy) | ||
944 | { | ||
945 | int dx, dy; | ||
946 | QRect InRect(*x, *y, *cx, *cy); | ||
947 | QRect OutRect; | ||
948 | QRect CRect(clipx, clipy, clipcx, clipcy); | ||
949 | OutRect = InRect.intersect(CRect); | ||
950 | if (OutRect.isEmpty()) | ||
951 | return false; | ||
952 | dx = OutRect.x() - InRect.x(); | ||
953 | dy = OutRect.y() - InRect.y(); | ||
954 | *x = OutRect.x(); | ||
955 | *y = OutRect.y(); | ||
956 | *cx = OutRect.width(); | ||
957 | *cy = OutRect.height(); | ||
958 | if (srcx != NULL) | ||
959 | *srcx = *srcx + dx; | ||
960 | if (srcy != NULL) | ||
961 | *srcy = *srcy + dy; | ||
962 | return true; | ||
963 | } | ||
964 | |||
965 | //***************************************************************************** | ||
966 | void QMyMainWindow::paintEvent(QPaintEvent* pe) | ||
967 | { | ||
968 | QImage* Image; | ||
969 | QPainter* Painter; | ||
970 | QRect Rect; | ||
971 | int i, j, w, h, l, t; | ||
972 | uint8* data; | ||
973 | |||
974 | if (!testWFlags(WRepaintNoErase)) | ||
975 | setWFlags(WRepaintNoErase); | ||
976 | if (CM != NULL) | ||
977 | { | ||
978 | Rect = pe->rect(); | ||
979 | l = Rect.left(); | ||
980 | t = Rect.top(); | ||
981 | w = Rect.width(); | ||
982 | h = Rect.height(); | ||
983 | if (w > 0 && h > 0 && CM->NumColors > 0) | ||
984 | { | ||
985 | data = (uint8*)xmalloc(w * h); | ||
986 | for (i = 0; i < h; i++) | ||
987 | for (j = 0; j < w; j++) | ||
988 | data[i * w + j] = get_pixel(l + j, t + i); | ||
989 | Image = new QImage(data, w, h, 8,(QRgb*)CM->RGBColors, CM->NumColors, QImage::IgnoreEndian); | ||
990 | Painter = new QPainter(this); | ||
991 | Painter->drawImage(l, t, *Image, 0, 0, w, h); | ||
992 | xfree(data); | ||
993 | delete Painter; | ||
994 | delete Image; | ||
995 | } | ||
996 | } | ||
997 | } | ||
998 | |||
999 | //***************************************************************************** | ||
1000 | void QMyMainWindow::closeEvent(QCloseEvent* e) | ||
1001 | { | ||
1002 | e->accept(); | ||
1003 | } | ||
1004 | |||
1005 | //***************************************************************************** | ||
1006 | void QMyMainWindow::dataReceived() | ||
1007 | { | ||
1008 | if (rdp_main_loop()) | ||
1009 | return; | ||
1010 | else | ||
1011 | SV->close(); | ||
1012 | } | ||
1013 | |||
1014 | //***************************************************************************** | ||
1015 | void redraw(int x, int y, int cx, int cy) | ||
1016 | { | ||
1017 | if (WarpCoords(&x, &y, &cx, &cy, NULL, NULL)) | ||
1018 | { | ||
1019 | MW->update(x, y, cx, cy); | ||
1020 | } | ||
1021 | } | ||
1022 | |||
1023 | /* | ||
1024 | BOOL ui_init(void) | ||
1025 | { | ||
1026 | QWidget* d; | ||
1027 | |||
1028 | CM = NULL; | ||
1029 | BS = NULL; | ||
1030 | #ifdef SHARP | ||
1031 | App = new QPEApplication(g_argc, g_argv); | ||
1032 | #else | ||
1033 | App = new QApplication(g_argc, g_argv, QApplication::GuiServer); | ||
1034 | #endif | ||
1035 | if (fullscreen) | ||
1036 | { | ||
1037 | d = QApplication::desktop(); | ||
1038 | width = d->width(); // returns screen width | ||
1039 | height = d->height(); // returns screen height | ||
1040 | } | ||
1041 | return True; | ||
1042 | } | ||
1043 | */ | ||
1044 | |||
1045 | /* | ||
1046 | void ui_deinit(void) | ||
1047 | { | ||
1048 | delete App; | ||
1049 | } | ||
1050 | */ | ||
1051 | |||
1052 | /* | ||
1053 | BOOL ui_create_window(void) | ||
1054 | { | ||
1055 | MW = new QMyMainWindow(); | ||
1056 | MW->resize(width, height); | ||
1057 | SV = new QMyScrollView(); | ||
1058 | SV->resize(width + 4, height + 4); | ||
1059 | App->setMainWidget(SV); | ||
1060 | SV->addChild(MW); | ||
1061 | MW->setMouseTracking(true); | ||
1062 | SocketNotifier = new QSocketNotifier(global_sock, QSocketNotifier::Read, MW); | ||
1063 | MW->connect(SocketNotifier, SIGNAL(activated(int)), MW, SLOT(dataReceived())); | ||
1064 | if (fullscreen) | ||
1065 | SV->showFullScreen(); | ||
1066 | else | ||
1067 | SV->showMaximized(); | ||
1068 | BS = (uint8*)xmalloc(width * height); | ||
1069 | memset(BS, 0, width * height); | ||
1070 | clipx = 0; | ||
1071 | clipy = 0; | ||
1072 | clipcx = width; | ||
1073 | clipcy = height; | ||
1074 | CM = (QColorMap*)xmalloc(sizeof(struct QColorMap)); | ||
1075 | memset(CM, 0, sizeof(struct QColorMap)); | ||
1076 | SV->timer_id = SV->startTimer(1000); | ||
1077 | return True; | ||
1078 | } | ||
1079 | */ | ||
1080 | |||
1081 | /* | ||
1082 | void ui_destroy_window(void) | ||
1083 | { | ||
1084 | delete MW; | ||
1085 | delete SV; | ||
1086 | xfree(BS); | ||
1087 | xfree(CM); | ||
1088 | } | ||
1089 | */ | ||
1090 | |||
1091 | //***************************************************************************** | ||
1092 | /* Returns 0 after user quit, 1 otherwise */ | ||
1093 | int ui_select(int rdp_socket) | ||
1094 | { | ||
1095 | global_sock = rdp_socket; | ||
1096 | return 1; | ||
1097 | } | ||
1098 | |||
1099 | //***************************************************************************** | ||
1100 | void ui_move_pointer(int /*x*/, int /*y*/) | ||
1101 | { | ||
1102 | } | ||
1103 | |||
1104 | //***************************************************************************** | ||
1105 | HBITMAP ui_create_bitmap(int width, int height, uint8 * data) | ||
1106 | { | ||
1107 | struct bitmap* the_bitmap; | ||
1108 | uint8* bitmap_data; | ||
1109 | int i, j; | ||
1110 | |||
1111 | // printf("width %d height %d times %d\n", width, height, width * height); | ||
1112 | bitmap_data = (uint8*)xmalloc(width * height); | ||
1113 | the_bitmap = (struct bitmap*)xmalloc(sizeof(struct bitmap)); | ||
1114 | the_bitmap->w = width; | ||
1115 | the_bitmap->h = height; | ||
1116 | the_bitmap->data = bitmap_data; | ||
1117 | for (i = 0; i < height; i++) | ||
1118 | for (j = 0; j < width; j++) | ||
1119 | bitmap_data[i * width + j] = data[i * width + j]; | ||
1120 | return the_bitmap; | ||
1121 | } | ||
1122 | |||
1123 | //***************************************************************************** | ||
1124 | void ui_paint_bitmap(int x, int y, int cx, int cy, int width, | ||
1125 | int height, uint8 * data) | ||
1126 | { | ||
1127 | int i, j; | ||
1128 | |||
1129 | for (i = 0; i < cy; i++) | ||
1130 | for (j = 0; j < cx; j++) | ||
1131 | if (i < height) | ||
1132 | if (j < width) | ||
1133 | set_pixel(x + j, y + i, data[i * width + j]); | ||
1134 | redraw(x, y, cx, cy); | ||
1135 | } | ||
1136 | |||
1137 | //***************************************************************************** | ||
1138 | void ui_destroy_bitmap(HBITMAP bmp) | ||
1139 | { | ||
1140 | struct bitmap* the_bitmap; | ||
1141 | |||
1142 | the_bitmap = (struct bitmap*)bmp; | ||
1143 | if (the_bitmap != NULL) | ||
1144 | { | ||
1145 | if (the_bitmap->data != NULL) | ||
1146 | xfree(the_bitmap->data); | ||
1147 | xfree(the_bitmap); | ||
1148 | } | ||
1149 | } | ||
1150 | |||
1151 | //***************************************************************************** | ||
1152 | bool is_pixel_on(uint8* data, int x, int y, int width, int bpp) | ||
1153 | { | ||
1154 | int start, shift; | ||
1155 | |||
1156 | if (bpp == 1) | ||
1157 | { | ||
1158 | width = (width + 7) / 8; | ||
1159 | start = (y * width) + x / 8; | ||
1160 | shift = x % 8; | ||
1161 | return (data[start] & (0x80 >> shift)) != 0; | ||
1162 | } | ||
1163 | else if (bpp == 8) | ||
1164 | return data[y * width + x] != 0; | ||
1165 | else | ||
1166 | return false; | ||
1167 | } | ||
1168 | |||
1169 | //***************************************************************************** | ||
1170 | void set_pixel_on(uint8* data, int x, int y, int width, int bpp, uint8 pixel) | ||
1171 | { | ||
1172 | if (bpp == 8) | ||
1173 | data[y * width + x] = pixel; | ||
1174 | } | ||
1175 | |||
1176 | //***************************************************************************** | ||
1177 | HGLYPH ui_create_glyph(int width, int height, uint8 * data) | ||
1178 | { | ||
1179 | int i, j; | ||
1180 | uint8* glyph_data; | ||
1181 | struct bitmap* the_glyph; | ||
1182 | |||
1183 | glyph_data = (uint8*)xmalloc(width * height); | ||
1184 | the_glyph = (struct bitmap*)xmalloc(sizeof(struct bitmap)); | ||
1185 | the_glyph->w = width; | ||
1186 | the_glyph->h = height; | ||
1187 | the_glyph->data = glyph_data; | ||
1188 | memset(glyph_data, 0, width * height); | ||
1189 | for (i = 0; i < height; i++) | ||
1190 | for (j = 0; j < width; j++) | ||
1191 | if (is_pixel_on(data, j, i, width, 1)) | ||
1192 | set_pixel_on(glyph_data, j, i, width, 8, 255); | ||
1193 | return the_glyph; | ||
1194 | } | ||
1195 | |||
1196 | //***************************************************************************** | ||
1197 | void ui_destroy_glyph(HGLYPH glyph) | ||
1198 | { | ||
1199 | struct bitmap* the_glyph; | ||
1200 | |||
1201 | the_glyph = (struct bitmap*)glyph; | ||
1202 | if (the_glyph != NULL) | ||
1203 | { | ||
1204 | if (the_glyph->data != NULL) | ||
1205 | xfree(the_glyph->data); | ||
1206 | xfree(the_glyph); | ||
1207 | } | ||
1208 | } | ||
1209 | |||
1210 | //***************************************************************************** | ||
1211 | HCURSOR ui_create_cursor(unsigned int /*x*/, unsigned int /*y*/, | ||
1212 | int /*width*/, int /*height*/, uint8 * /*andmask*/, | ||
1213 | uint8 * /*xormask*/) | ||
1214 | { | ||
1215 | return (void*)1; | ||
1216 | } | ||
1217 | |||
1218 | //***************************************************************************** | ||
1219 | void ui_set_cursor(HCURSOR /*cursor*/) | ||
1220 | { | ||
1221 | } | ||
1222 | |||
1223 | //***************************************************************************** | ||
1224 | void ui_destroy_cursor(HCURSOR /*cursor*/) | ||
1225 | { | ||
1226 | } | ||
1227 | |||
1228 | //***************************************************************************** | ||
1229 | HCOLOURMAP ui_create_colourmap(COLOURMAP * colours) | ||
1230 | { | ||
1231 | int i; | ||
1232 | int x; | ||
1233 | uint8 r, g, b; | ||
1234 | i = 0; | ||
1235 | while (i < colours->ncolours && i < 256) | ||
1236 | { | ||
1237 | r = colours->colours[i].red; | ||
1238 | g = colours->colours[i].green; | ||
1239 | b = colours->colours[i].blue; | ||
1240 | x = (r << 16) | (g << 8) | b; | ||
1241 | CM->RGBColors[i] = x; | ||
1242 | i++; | ||
1243 | } | ||
1244 | CM->NumColors = colours->ncolours; | ||
1245 | return CM; | ||
1246 | } | ||
1247 | |||
1248 | //***************************************************************************** | ||
1249 | void ui_destroy_colourmap(HCOLOURMAP /*map*/) | ||
1250 | { | ||
1251 | } | ||
1252 | |||
1253 | //***************************************************************************** | ||
1254 | void ui_set_colourmap(HCOLOURMAP /*map*/) | ||
1255 | { | ||
1256 | } | ||
1257 | |||
1258 | //***************************************************************************** | ||
1259 | void ui_begin_update(void) | ||
1260 | { | ||
1261 | } | ||
1262 | |||
1263 | //***************************************************************************** | ||
1264 | void ui_end_update(void) | ||
1265 | { | ||
1266 | } | ||
1267 | |||
1268 | //***************************************************************************** | ||
1269 | void ui_set_clip(int x, int y, int cx, int cy) | ||
1270 | { | ||
1271 | clipx = x; | ||
1272 | clipy = y; | ||
1273 | clipcx = cx; | ||
1274 | clipcy = cy; | ||
1275 | } | ||
1276 | |||
1277 | //***************************************************************************** | ||
1278 | void ui_reset_clip(void) | ||
1279 | { | ||
1280 | clipx = 0; | ||
1281 | clipy = 0; | ||
1282 | clipcx = g_width; | ||
1283 | clipcy = g_height; | ||
1284 | } | ||
1285 | |||
1286 | //***************************************************************************** | ||
1287 | void ui_bell(void) | ||
1288 | { | ||
1289 | App->beep(); | ||
1290 | } | ||
1291 | |||
1292 | //***************************************************************************** | ||
1293 | void ui_destblt(uint8 opcode, int x, int y, int cx, int cy) | ||
1294 | { | ||
1295 | int i, j; | ||
1296 | |||
1297 | for (i = 0; i < cy; i++) | ||
1298 | for (j = 0; j < cx; j++) | ||
1299 | set_pixel(x + j, y + i, get_pixel(x + j, y + i), opcode); | ||
1300 | redraw(x, y, cx, cy); | ||
1301 | } | ||
1302 | |||
1303 | //***************************************************************************** | ||
1304 | // does not repaint | ||
1305 | void fill_rect(int x, int y, int cx, int cy, int colour, int opcode = 0xc) | ||
1306 | { | ||
1307 | int i, j; | ||
1308 | |||
1309 | for (i = 0; i < cy; i++) | ||
1310 | for (j = 0; j < cx; j++) | ||
1311 | set_pixel(x + j, y + i, colour, opcode); | ||
1312 | } | ||
1313 | |||
1314 | //***************************************************************************** | ||
1315 | void ui_rect(int x, int y, int cx, int cy, int colour) | ||
1316 | { | ||
1317 | fill_rect(x, y, cx, cy, colour); | ||
1318 | redraw(x, y, cx, cy); | ||
1319 | } | ||
1320 | |||
1321 | //***************************************************************************** | ||
1322 | void ui_patblt(uint8 opcode, int x, int y, int cx, int cy, | ||
1323 | BRUSH * brush, int bgcolour, int fgcolour) | ||
1324 | { | ||
1325 | int i, j; | ||
1326 | uint8 ipattern[8]; | ||
1327 | |||
1328 | switch (brush->style) | ||
1329 | { | ||
1330 | case 0: | ||
1331 | fill_rect(x, y, cx, cy, fgcolour, opcode); | ||
1332 | break; | ||
1333 | case 3: | ||
1334 | for (i = 0; i < 8; i++) | ||
1335 | ipattern[i] = ~brush->pattern[7 - i]; | ||
1336 | for (i = 0; i < cy; i++) | ||
1337 | for (j = 0; j < cx; j++) | ||
1338 | if (is_pixel_on(ipattern, (x + j + brush->xorigin) % 8, | ||
1339 | (y + i + brush->yorigin) % 8, 8, 1)) | ||
1340 | set_pixel(x + j, y + i, fgcolour, opcode); | ||
1341 | else | ||
1342 | set_pixel(x + j, y + i, bgcolour, opcode); | ||
1343 | break; | ||
1344 | } | ||
1345 | redraw(x, y, cx, cy); | ||
1346 | } | ||
1347 | |||
1348 | //***************************************************************************** | ||
1349 | void ui_screenblt(uint8 opcode, int x, int y, int cx, int cy, | ||
1350 | int srcx, int srcy) | ||
1351 | { | ||
1352 | int i, j; | ||
1353 | uint8* temp; | ||
1354 | |||
1355 | temp = (uint8*)xmalloc(cx * cy); | ||
1356 | for (i = 0; i < cy; i++) | ||
1357 | for (j = 0; j < cx; j++) | ||
1358 | temp[i * cx + j] = get_pixel(srcx + j, srcy + i); | ||
1359 | for (i = 0; i < cy; i++) | ||
1360 | for (j = 0; j < cx; j++) | ||
1361 | set_pixel(x + j, y + i, temp[i * cx + j], opcode); | ||
1362 | xfree(temp); | ||
1363 | redraw(x, y, cx, cy); | ||
1364 | } | ||
1365 | |||
1366 | //***************************************************************************** | ||
1367 | void ui_memblt(uint8 opcode, int x, int y, int cx, int cy, | ||
1368 | HBITMAP src, int srcx, int srcy) | ||
1369 | { | ||
1370 | int i, j; | ||
1371 | struct bitmap* the_bitmap; | ||
1372 | |||
1373 | the_bitmap = (struct bitmap*)src; | ||
1374 | if (the_bitmap == NULL) | ||
1375 | return; | ||
1376 | for (i = 0; i < cy; i++) | ||
1377 | for (j = 0; j < cx; j++) | ||
1378 | if ((i + srcy) < the_bitmap->h && (j + srcx) < the_bitmap->w) | ||
1379 | set_pixel(x + j, y + i, the_bitmap->data[(i + srcy) * the_bitmap->w + (j + srcx)], opcode); | ||
1380 | redraw(x, y, cx, cy); | ||
1381 | } | ||
1382 | |||
1383 | //***************************************************************************** | ||
1384 | // not used | ||
1385 | void ui_triblt(uint8 /*opcode*/, int /*x*/, int /*y*/, int /*cx*/, int /*cy*/, | ||
1386 | HBITMAP /*src*/, int /*srcx*/, int /*srcy*/, BRUSH * /*brush*/, | ||
1387 | int /*bgcolour*/, int /*fgcolour*/) | ||
1388 | { | ||
1389 | } | ||
1390 | |||
1391 | //***************************************************************************** | ||
1392 | // Bresenham's line drawing algorithm | ||
1393 | void ui_line(uint8 opcode, int startx, int starty, int endx, | ||
1394 | int endy, PEN * pen) | ||
1395 | { | ||
1396 | int dx, dy, incx, incy, dpr, dpru, p, left, top, right, bottom; | ||
1397 | |||
1398 | if (startx > endx) | ||
1399 | { | ||
1400 | dx = startx - endx; | ||
1401 | incx = -1; | ||
1402 | left = endx; | ||
1403 | right = startx; | ||
1404 | } | ||
1405 | else | ||
1406 | { | ||
1407 | dx = endx - startx; | ||
1408 | incx = 1; | ||
1409 | left = startx; | ||
1410 | right = endx; | ||
1411 | } | ||
1412 | if (starty > endy) | ||
1413 | { | ||
1414 | dy = starty - endy; | ||
1415 | incy = -1; | ||
1416 | top = endy; | ||
1417 | bottom = starty; | ||
1418 | } | ||
1419 | else | ||
1420 | { | ||
1421 | dy = endy - starty; | ||
1422 | incy = 1; | ||
1423 | top = starty; | ||
1424 | bottom = endy; | ||
1425 | } | ||
1426 | if (dx >= dy) | ||
1427 | { | ||
1428 | dpr = dy << 1; | ||
1429 | dpru = dpr - (dx << 1); | ||
1430 | p = dpr - dx; | ||
1431 | for (; dx >= 0; dx--) | ||
1432 | { | ||
1433 | set_pixel(startx, starty, pen->colour, opcode); | ||
1434 | if (p > 0) | ||
1435 | { | ||
1436 | startx += incx; | ||
1437 | starty += incy; | ||
1438 | p += dpru; | ||
1439 | } | ||
1440 | else | ||
1441 | { | ||
1442 | startx += incx; | ||
1443 | p += dpr; | ||
1444 | } | ||
1445 | } | ||
1446 | } | ||
1447 | else | ||
1448 | { | ||
1449 | dpr = dx << 1; | ||
1450 | dpru = dpr - (dy << 1); | ||
1451 | p = dpr - dy; | ||
1452 | for (; dy >= 0; dy--) | ||
1453 | { | ||
1454 | set_pixel(startx, starty, pen->colour, opcode); | ||
1455 | if (p > 0) | ||
1456 | { | ||
1457 | startx += incx; | ||
1458 | starty += incy; | ||
1459 | p += dpru; | ||
1460 | } | ||
1461 | else | ||
1462 | { | ||
1463 | starty += incy; | ||
1464 | p += dpr; | ||
1465 | } | ||
1466 | } | ||
1467 | } | ||
1468 | redraw(left, top, (right - left) + 1, (bottom - top) + 1); | ||
1469 | } | ||
1470 | |||
1471 | //***************************************************************************** | ||
1472 | void draw_glyph (int x, int y, HGLYPH glyph, int fgcolour) | ||
1473 | { | ||
1474 | struct bitmap* the_glyph; | ||
1475 | int i, j; | ||
1476 | |||
1477 | the_glyph = (struct bitmap*)glyph; | ||
1478 | if (the_glyph == NULL) | ||
1479 | return; | ||
1480 | for (i = 0; i < the_glyph->h; i++) | ||
1481 | for (j = 0; j < the_glyph->w; j++) | ||
1482 | if (is_pixel_on(the_glyph->data, j, i, the_glyph->w, 8)) | ||
1483 | set_pixel(x + j, y + i, fgcolour); | ||
1484 | } | ||
1485 | |||
1486 | #define DO_GLYPH(ttext,idx) \ | ||
1487 | {\ | ||
1488 | glyph = cache_get_font (font, ttext[idx]);\ | ||
1489 | if (!(flags & TEXT2_IMPLICIT_X))\ | ||
1490 | {\ | ||
1491 | xyoffset = ttext[++idx];\ | ||
1492 | if ((xyoffset & 0x80))\ | ||
1493 | {\ | ||
1494 | if (flags & TEXT2_VERTICAL) \ | ||
1495 | y += ttext[idx+1] | (ttext[idx+2] << 8);\ | ||
1496 | else\ | ||
1497 | x += ttext[idx+1] | (ttext[idx+2] << 8);\ | ||
1498 | idx += 2;\ | ||
1499 | }\ | ||
1500 | else\ | ||
1501 | {\ | ||
1502 | if (flags & TEXT2_VERTICAL) \ | ||
1503 | y += xyoffset;\ | ||
1504 | else\ | ||
1505 | x += xyoffset;\ | ||
1506 | }\ | ||
1507 | }\ | ||
1508 | if (glyph != NULL)\ | ||
1509 | {\ | ||
1510 | draw_glyph (x + glyph->offset, y + glyph->baseline, glyph->pixmap, fgcolour);\ | ||
1511 | if (flags & TEXT2_IMPLICIT_X)\ | ||
1512 | x += glyph->width;\ | ||
1513 | }\ | ||
1514 | } | ||
1515 | |||
1516 | //***************************************************************************** | ||
1517 | void ui_draw_text(uint8 font, uint8 flags, int mixmode, | ||
1518 | int x, int y, int clipx, int clipy, | ||
1519 | int clipcx, int clipcy, int boxx, | ||
1520 | int boxy, int boxcx, int boxcy, int bgcolour, | ||
1521 | int fgcolour, uint8 * text, uint8 length) | ||
1522 | { | ||
1523 | FONTGLYPH *glyph; | ||
1524 | int i, j, xyoffset; | ||
1525 | DATABLOB *entry; | ||
1526 | |||
1527 | if (boxcx > 1) | ||
1528 | fill_rect(boxx, boxy, boxcx, boxcy, bgcolour); | ||
1529 | else if (mixmode == MIX_OPAQUE) | ||
1530 | fill_rect(clipx, clipy, clipcx, clipcy, bgcolour); | ||
1531 | |||
1532 | /* Paint text, character by character */ | ||
1533 | for (i = 0; i < length;) | ||
1534 | { | ||
1535 | switch (text[i]) | ||
1536 | { | ||
1537 | case 0xff: | ||
1538 | if (i + 2 < length) | ||
1539 | cache_put_text(text[i + 1], text, text[i + 2]); | ||
1540 | else | ||
1541 | { | ||
1542 | error("this shouldn't be happening\n"); | ||
1543 | exit(1); | ||
1544 | } | ||
1545 | /* this will move pointer from start to first character after FF command */ | ||
1546 | length -= i + 3; | ||
1547 | text = &(text[i + 3]); | ||
1548 | i = 0; | ||
1549 | break; | ||
1550 | |||
1551 | case 0xfe: | ||
1552 | entry = cache_get_text(text[i + 1]); | ||
1553 | if (entry != NULL) | ||
1554 | { | ||
1555 | if ((((uint8 *) (entry->data))[1] == 0) && (!(flags & TEXT2_IMPLICIT_X))) | ||
1556 | { | ||
1557 | if (flags & TEXT2_VERTICAL) | ||
1558 | y += text[i + 2]; | ||
1559 | else | ||
1560 | x += text[i + 2]; | ||
1561 | } | ||
1562 | for (j = 0; j < entry->size; j++) | ||
1563 | DO_GLYPH(((uint8 *) (entry->data)), j); | ||
1564 | } | ||
1565 | if (i + 2 < length) | ||
1566 | i += 3; | ||
1567 | else | ||
1568 | i += 2; | ||
1569 | length -= i; | ||
1570 | /* this will move pointer from start to first character after FE command */ | ||
1571 | text = &(text[i]); | ||
1572 | i = 0; | ||
1573 | break; | ||
1574 | |||
1575 | default: | ||
1576 | DO_GLYPH(text, i); | ||
1577 | i++; | ||
1578 | break; | ||
1579 | } | ||
1580 | } | ||
1581 | if (boxcx > 1) | ||
1582 | redraw(boxx, boxy, boxcx, boxcy); | ||
1583 | else | ||
1584 | redraw(clipx, clipy, clipcx, clipcy); | ||
1585 | } | ||
1586 | |||
1587 | //***************************************************************************** | ||
1588 | void ui_desktop_save(uint32 offset, int x, int y, int cx, int cy) | ||
1589 | { | ||
1590 | uint8* data; | ||
1591 | int i, j; | ||
1592 | |||
1593 | data = (uint8*)xmalloc(cx * cy); | ||
1594 | for (i = 0; i < cy; i++) | ||
1595 | for (j = 0; j < cx; j++) | ||
1596 | data[i * cx + j] = get_pixel(x + j, y + i); | ||
1597 | cache_put_desktop(offset, cx, cy, cx, 1, data); | ||
1598 | xfree(data); | ||
1599 | } | ||
1600 | |||
1601 | //***************************************************************************** | ||
1602 | void ui_desktop_restore(uint32 offset, int x, int y, int cx, int cy) | ||
1603 | { | ||
1604 | uint8* data; | ||
1605 | int i, j; | ||
1606 | |||
1607 | data = cache_get_desktop(offset, cx, cy, 1); | ||
1608 | for (i = 0; i < cy; i++) | ||
1609 | for (j = 0; j < cx; j++) | ||
1610 | set_pixel(x + j, y + i, data[i * cx + j]); | ||
1611 | redraw(x, y, cx, cy); | ||
1612 | } | ||
1613 | |||
1614 | //***************************************************************************** | ||
1615 | int main(int argc, char** argv) | ||
1616 | { | ||
1617 | CM = NULL; | ||
1618 | BS = NULL; | ||
1619 | #ifdef SHARP | ||
1620 | App = new QPEApplication(argc, argv); | ||
1621 | #else | ||
1622 | App = new QApplication(argc, argv, QApplication::GuiServer); | ||
1623 | #endif | ||
1624 | SV = new QMyScrollView(); | ||
1625 | App->setMainWidget(SV); | ||
1626 | SV->showMaximized(); | ||
1627 | SV->timer_id = SV->startTimer(1000); | ||
1628 | App->exec(); | ||
1629 | delete SV; | ||
1630 | delete App; | ||
1631 | if (CM != NULL) | ||
1632 | xfree(CM); | ||
1633 | if (BS !=NULL) | ||
1634 | xfree(BS); | ||
1635 | return 0; | ||
1636 | } | ||
1637 | |||
1638 | /* | ||
1639 | MW = new QMyMainWindow(); | ||
1640 | MW->resize(width, height); | ||
1641 | SV->resize(width + 4, height + 4); | ||
1642 | App->setMainWidget(SV); | ||
1643 | SV->addChild(MW); | ||
1644 | MW->setMouseTracking(true); | ||
1645 | SocketNotifier = new QSocketNotifier(global_sock, QSocketNotifier::Read, MW); | ||
1646 | MW->connect(SocketNotifier, SIGNAL(activated(int)), MW, SLOT(dataReceived())); | ||
1647 | if (fullscreen) | ||
1648 | SV->showFullScreen(); | ||
1649 | else | ||
1650 | SV->showMaximized(); | ||
1651 | BS = (uint8*)xmalloc(width * height); | ||
1652 | memset(BS, 0, width * height); | ||
1653 | clipx = 0; | ||
1654 | clipy = 0; | ||
1655 | clipcx = width; | ||
1656 | clipcy = height; | ||
1657 | CM = (QColorMap*)xmalloc(sizeof(struct QColorMap)); | ||
1658 | memset(CM, 0, sizeof(struct QColorMap)); | ||
1659 | SV->timer_id = SV->startTimer(1000); | ||
1660 | return True; | ||
1661 | |||
1662 | |||
1663 | |||
1664 | |||
1665 | |||
1666 | int main(int argc, char ** argv) | ||
1667 | { | ||
1668 | uint32 flags; | ||
1669 | int i, total_params; | ||
1670 | char server[64] = "192.168.0.164"; | ||
1671 | char domain[16] = ""; | ||
1672 | char password[16] = ""; | ||
1673 | char shell[128] = ""; | ||
1674 | char directory[32] = ""; | ||
1675 | char* p; | ||
1676 | QString param, s1, s2, s3; | ||
1677 | |||
1678 | flags = RDP_LOGON_NORMAL; | ||
1679 | |||
1680 | g_argc = argc; | ||
1681 | g_argv = argv; | ||
1682 | |||
1683 | if (!ui_init()) | ||
1684 | return 1; | ||
1685 | |||
1686 | total_params = App->argc(); | ||
1687 | |||
1688 | for (i = 1; (i + 1) < total_params; i = i + 2) | ||
1689 | { | ||
1690 | s1 = App->argv()[i]; | ||
1691 | s2 = App->argv()[i + 1]; | ||
1692 | if (s1 == "-g") | ||
1693 | { | ||
1694 | width = strtol((const char*)s2, &p, 10); | ||
1695 | if (*p == 'x') | ||
1696 | height = strtol(p + 1, NULL, 10); | ||
1697 | } | ||
1698 | else if (s1 = "-u") | ||
1699 | strcpy(username, (const char*)s2); | ||
1700 | } | ||
1701 | if (i < total_params) | ||
1702 | strcpy(server, App->argv()[i]); | ||
1703 | |||
1704 | // printf("server %s width %d height %d\n", server, width, height); | ||
1705 | |||
1706 | if (width == 0 || height == 0) | ||
1707 | { | ||
1708 | ui_deinit(); | ||
1709 | return 1; | ||
1710 | } | ||
1711 | |||
1712 | if (!rdp_connect(server, flags, domain, password, shell, directory)) | ||
1713 | { | ||
1714 | ui_deinit(); | ||
1715 | return 1; | ||
1716 | } | ||
1717 | if (ui_create_window()) | ||
1718 | { | ||
1719 | ui_main_loop(); | ||
1720 | ui_destroy_window(); | ||
1721 | } | ||
1722 | rdp_disconnect(); | ||
1723 | ui_deinit(); | ||
1724 | } | ||
1725 | */ | ||