/[rdesktop]/sourceforge.net/trunk/rdesktop/uiports/qtewin.cpp
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /sourceforge.net/trunk/rdesktop/uiports/qtewin.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 792 - (show annotations)
Wed Nov 3 03:27:53 2004 UTC (19 years, 6 months ago) by jsorg71
File size: 65564 byte(s)
added optimizes to qtewin.cpp

1 /*
2 rdesktop: A Remote Desktop Protocol client.
3 User interface services - QT Emb System
4 Copyright (C) Jay Sorg 2004
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 //#define SHARP
22
23 #ifdef SHARP
24 #include <qpe/qpeapplication.h>
25 #else
26 #include <qapplication.h>
27 #endif
28 #include <qcursor.h>
29 #include <qmainwindow.h>
30 #include <qwidget.h>
31 #include <qpainter.h>
32 #include <qimage.h>
33 #include <qsocketnotifier.h>
34 #include <qscrollview.h>
35 #include <qmessagebox.h>
36 #include <qpushbutton.h>
37 #include <qlineedit.h>
38 #include <qcombobox.h>
39 #include <qlabel.h>
40 #include <qfile.h>
41 #include <qcheckbox.h>
42 #include <qpopupmenu.h>
43 #include <stdlib.h>
44 #include <stdarg.h> // va_list va_start va_end
45 #include <unistd.h> // gethostname
46 #include <pwd.h> // getpwuid
47
48 #include "../rdesktop.h"
49 #include "qtewin.h"
50
51 #define QT_OPTI
52
53 /* types */
54 struct QColorMap
55 {
56 uint32 RGBColors[256];
57 uint32 NumColors;
58 };
59
60 struct bitmap
61 {
62 int w;
63 int h;
64 uint8 * data;
65 };
66
67 extern int g_tcp_port_rdp;
68 extern int g_dsp_fd;
69
70 #ifdef WITH_RDPSND
71 BOOL g_rdpsnd = True;
72 extern int g_dsp_busy;
73 #endif
74 int g_encryption = 1;
75 int g_bitmap_cache = 1;
76 int g_bitmap_cache_persist_enable = 0;
77 int g_bitmap_cache_precache = 1;
78 int g_use_rdp5 = 1;
79 int g_desktop_save = 1;
80 int g_bitmap_compression = 1;
81 int g_rdp5_performanceflags = 0;
82 int g_console_session = 0;
83 int g_keylayout = 0x409; /* Defaults to US keyboard layout */
84 int g_width = 640;
85 int g_height = 480;
86 int g_server_bpp = 8;
87 char g_hostname[16] = "";
88 char g_username[100] = "";
89
90 static int g_client_width = 640;
91 static int g_client_height = 480;
92 static uint32 g_flags = RDP_LOGON_NORMAL;
93 static char g_server[64] = "";
94 static char g_domain[16] = "";
95 static char g_password[16] = "";
96 static char g_shell[128] = "";
97 static char g_directory[32] = "";
98 static int g_fullscreen = 0;
99 static int g_global_sock = 0;
100 static int g_deactivated = 0;
101 static uint32 g_ext_disc_reason = 0;
102
103 static QSocketNotifier * g_SocketNotifier = 0;
104 static QSocketNotifier * g_SoundNotifier = 0;
105 #ifdef SHARP
106 static QPEApplication * g_App = 0;
107 #else
108 static QApplication * g_App = 0;
109 #endif
110 static QMyMainWindow * g_MW = 0;
111 static QMyScrollView * g_SV = 0;
112 static struct QColorMap * g_CM = 0;
113 static uint8 * g_BS = 0; /* the screen data */
114 static int g_clipx = 0;
115 static int g_clipy = 0;
116 static int g_clipcx = 0;
117 static int g_clipcy = 0;
118
119 #define BPP ((g_server_bpp + 7) / 8)
120 #define GETPIXEL8(d, x, y, w) (*(((uint8*)d) + ((y) * (w) + (x))))
121 #define GETPIXEL16(d, x, y, w) (*(((uint16*)d) + ((y) * (w) + (x))))
122 #define GETPIXEL32(d, x, y, w) (*(((uint32*)d) + ((y) * (w) + (x))))
123 #define SETPIXEL8(d, x, y, w, v) *(((uint8*)d) + ((y) * (w) + (x))) = v
124 #define SETPIXEL16(d, x, y, w, v) *(((uint16*)d) + ((y) * (w) + (x))) = v
125 #define SETPIXEL32(d, x, y, w, v) *(((uint32*)d) + ((y) * (w) + (x))) = v
126
127 /******************************************************************************/
128 void CleanString(QString * Item)
129 {
130 int i;
131
132 i = Item->length() - 1;
133 while (i >= 0)
134 {
135 if (Item->at(i) == 10 || Item->at(i) == 13)
136 Item->remove(i, 1);
137 i--;
138 }
139 }
140
141 /******************************************************************************/
142 QMyDialog::QMyDialog(QWidget * parent) : QDialog(parent, "Settings", true)
143 {
144 int i, j;
145 char * home;
146 char Text[256];
147 QString Line;
148 QString ItemName;
149 QString ItemValue;
150
151 // resize dialog
152 resize(230, 270);
153 // main list box
154 ListBox = new QListBox(this);
155 ListBox->move(10, 10);
156 ListBox->resize(200, 100);
157 connect(ListBox, SIGNAL(selectionChanged()), this, SLOT(ListBoxChanged()));
158 connect(ListBox, SIGNAL(selected(int)), this, SLOT(ListBoxSelected(int)));
159 // server
160 Label1 = new QLabel(this);
161 Label1->setText("Server Desc");
162 Label1->move(10, 120);
163 Label1->resize(100, 20);
164 ServerNameEdit = new QLineEdit(this);
165 ServerNameEdit->move(75, 120);
166 ServerNameEdit->resize(100, 20);
167 // username
168 Label2 = new QLabel(this);
169 Label2->setText("User Name");
170 Label2->move(10, 150);
171 Label2->resize(100, 20);
172 UserNameEdit = new QLineEdit(this);
173 UserNameEdit->move(75, 150);
174 UserNameEdit->resize(100, 20);
175 // ip
176 Label3 = new QLabel(this);
177 Label3->setText("Server IP");
178 Label3->move(10, 180);
179 Label3->resize(100, 20);
180 IPEdit = new QLineEdit(this);
181 IPEdit->move(75, 180);
182 IPEdit->resize(100, 20);
183 // width and height
184 WidthHeightBox = new QComboBox(this);
185 WidthHeightBox->move(10, 210);
186 WidthHeightBox->resize(100, 20);
187 WidthHeightBox->insertItem("240x320");
188 WidthHeightBox->insertItem("640x480");
189 WidthHeightBox->insertItem("800x600");
190 connect(WidthHeightBox, SIGNAL(activated(int)), this, SLOT(ComboChanged(int)));
191 WidthHeightBox->setCurrentItem(1);
192 WidthEdit = new QLineEdit(this);
193 WidthEdit->move(110, 210);
194 WidthEdit->resize(30, 20);
195 WidthEdit->setText("800");
196 HeightEdit = new QLineEdit(this);
197 HeightEdit->move(140, 210);
198 HeightEdit->resize(30, 20);
199 HeightEdit->setText("600");
200 // add to list button
201 AddButton = new QPushButton(this);
202 AddButton->move(180, 120);
203 AddButton->resize(50, 20);
204 AddButton->setText("Add");
205 connect(AddButton, SIGNAL(clicked()), this, SLOT(AddClicked()));
206 // change list item button
207 EditButton = new QPushButton(this);
208 EditButton->move(180, 140);
209 EditButton->resize(50, 20);
210 EditButton->setText("Edit");
211 connect(EditButton, SIGNAL(clicked()), this, SLOT(EditClicked()));
212 // save to file button
213 SaveButton = new QPushButton(this);
214 SaveButton->move(180, 160);
215 SaveButton->resize(50, 20);
216 SaveButton->setText("Save");
217 connect(SaveButton, SIGNAL(clicked()), this, SLOT(SaveClicked()));
218 // remove an item button
219 RemoveButton = new QPushButton(this);
220 RemoveButton->move(180, 180);
221 RemoveButton->resize(50, 20);
222 RemoveButton->setText("Remove");
223 connect(RemoveButton, SIGNAL(clicked()), this, SLOT(RemoveClicked()));
224 // full screen check box
225 FullScreenCheckBox = new QCheckBox(this, "Full Screen");
226 FullScreenCheckBox->setText("Full Screen");
227 FullScreenCheckBox->move(10, 230);
228 // ok button
229 OKButton = new QPushButton(this);
230 OKButton->setText("OK");
231 OKButton->move(100, 240);
232 OKButton->resize(50, 20);
233 connect(OKButton, SIGNAL(clicked()), this, SLOT(OKClicked()));
234 // cancel button
235 CancelButton = new QPushButton(this);
236 CancelButton->setText("Cancel");
237 CancelButton->move(160, 240);
238 CancelButton->resize(50, 20);
239 connect(CancelButton, SIGNAL(clicked()), this, SLOT(CancelClicked()));
240
241 for (i = 0; i < 10; i++)
242 {
243 ConnectionList[i] = new QMyConnectionItem;
244 ConnectionList[i]->ServerName = "";
245 ConnectionList[i]->UserName = "";
246 ConnectionList[i]->ServerIP = "";
247 ConnectionList[i]->Width = 0;
248 ConnectionList[i]->Height = 0;
249 ConnectionList[i]->FullScreen = 0;
250 }
251 home = getenv("HOME");
252 if (home != NULL)
253 {
254 sprintf(Text, "%s/rdesktop.ini", home);
255 QFile * File = new QFile(Text);
256 if (File->open(IO_ReadOnly))
257 {
258 i = -1;
259 while (!File->atEnd())
260 {
261 File->readLine(Line, 255);
262 j = Line.find("=");
263 if (j > 0)
264 {
265 ItemName = Line.mid(0, j);
266 CleanString(&ItemName);
267 ItemValue = Line.mid(j + 1);
268 CleanString(&ItemValue);
269 if (ItemName == "Server")
270 {
271 i++;
272 ConnectionList[i]->ServerName = ItemValue;
273 ListBox->insertItem(ItemValue);
274 }
275 else if (ItemName == "UserName")
276 ConnectionList[i]->UserName = ItemValue;
277 else if (ItemName == "Width")
278 ConnectionList[i]->Width = ItemValue.toInt();
279 else if (ItemName == "Height")
280 ConnectionList[i]->Height = ItemValue.toInt();
281 else if (ItemName == "IP")
282 ConnectionList[i]->ServerIP = ItemValue;
283 else if (ItemName == "FullScreen")
284 ConnectionList[i]->FullScreen = (ItemValue != "0");
285 }
286 }
287 }
288 delete File;
289 }
290 }
291
292 /******************************************************************************/
293 QMyDialog::~QMyDialog()
294 {
295 QMyConnectionItem * Item;
296 int i;
297
298 for (i = 0; i < 10; i++)
299 {
300 Item = ConnectionList[i];
301 delete Item;
302 }
303 }
304
305 /******************************************************************************/
306 void QMyDialog::ComboChanged(int index)
307 {
308 if (index == 0)
309 {
310 WidthEdit->setText("240");
311 HeightEdit->setText("320");
312 }
313 if (index == 1)
314 {
315 WidthEdit->setText("640");
316 HeightEdit->setText("480");
317 }
318 else if (index == 2)
319 {
320 WidthEdit->setText("800");
321 HeightEdit->setText("600");
322 }
323 }
324
325 /******************************************************************************/
326 void QMyDialog::OKClicked()
327 {
328 ServerName = ServerNameEdit->text();
329 UserName = UserNameEdit->text();
330 Width = WidthEdit->text().toInt();
331 Height = HeightEdit->text().toInt();
332 ServerIP = IPEdit->text();
333 FullScreen = FullScreenCheckBox->isChecked();
334 done(1);
335 }
336
337 /******************************************************************************/
338 void QMyDialog::CancelClicked()
339 {
340 done(0);
341 }
342
343 /******************************************************************************/
344 void QMyDialog::AddClicked()
345 {
346 int i;
347 QMyConnectionItem * Item;
348
349 i = ListBox->count();
350 if (i < 10)
351 {
352 ListBox->insertItem(ServerNameEdit->text());
353 Item = ConnectionList[i];
354 Item->ServerName = ServerNameEdit->text();
355 Item->UserName = UserNameEdit->text();
356 Item->Width = WidthEdit->text().toInt();
357 Item->Height = HeightEdit->text().toInt();
358 Item->ServerIP = IPEdit->text();
359 Item->FullScreen = FullScreenCheckBox->isChecked();
360 }
361 }
362
363 /******************************************************************************/
364 void QMyDialog::EditClicked()
365 {
366 int i;
367 QMyConnectionItem * Item;
368
369 i = ListBox->currentItem();
370 if (i >= 0)
371 {
372 Item = ConnectionList[i];
373 Item->ServerName = ServerNameEdit->text();
374 Item->UserName = UserNameEdit->text();
375 Item->Width = WidthEdit->text().toInt();
376 Item->Height = HeightEdit->text().toInt();
377 Item->ServerIP = IPEdit->text();
378 Item->FullScreen = FullScreenCheckBox->isChecked();
379 ListBox->changeItem(ServerNameEdit->text(), i);
380 }
381 }
382
383 /******************************************************************************/
384 void WriteString(QFile* File, QString* Line)
385 {
386 File->writeBlock((const char*)(*Line), Line->length());
387 }
388
389 /******************************************************************************/
390 void QMyDialog::SaveClicked()
391 {
392 int i, j;
393 QMyConnectionItem * Item;
394 QString Line;
395 char * home;
396 char Text[256];
397 QFile* File;
398
399 home = getenv("HOME");
400 if (home != NULL)
401 {
402 sprintf(Text, "%s/rdesktop.ini", home);
403 File = new QFile(Text);
404 if (File->open(IO_Truncate | IO_ReadWrite))
405 {
406 i = ListBox->count();
407 for (j = 0; j < i; j++)
408 {
409 Item = ConnectionList[j];
410 Line = "Server=";
411 Line += Item->ServerName;
412 Line += (char)10;
413 WriteString(File, &Line);
414 Line = "UserName=";
415 Line += Item->UserName;
416 Line += (char)10;
417 WriteString(File, &Line);
418 Line = "Width=";
419 sprintf(Text, "%d", Item->Width);
420 Line += Text;
421 Line += (char)10;
422 WriteString(File, &Line);
423 Line = "Height=";
424 sprintf(Text, "%d", Item->Height);
425 Line += Text;
426 Line += (char)10;
427 WriteString(File, &Line);
428 Line = "IP=";
429 Line += Item->ServerIP;
430 Line += (char)10;
431 WriteString(File, &Line);
432 Line = "FullScreen=";
433 if (Item->FullScreen)
434 Line += "1";
435 else
436 Line += "0";
437 Line += (char)10;
438 WriteString(File, &Line);
439 }
440 }
441 File->flush();
442 File->close();
443 delete File;
444 }
445 }
446
447 /******************************************************************************/
448 void QMyDialog::RemoveClicked()
449 {
450 int i, j, c;
451 QMyConnectionItem * Item1;
452 QMyConnectionItem * Item2;
453
454 i = ListBox->currentItem();
455 if (i >= 0)
456 {
457 c = ListBox->count();
458 for (j = i; j < c - 1; j++)
459 {
460 Item1 = ConnectionList[i];
461 Item2 = ConnectionList[i + 1];
462 Item1->ServerName = Item2->ServerName;
463 Item1->UserName = Item2->UserName;
464 Item1->Width = Item2->Width;
465 Item1->Height = Item2->Height;
466 Item1->ServerIP = Item2->ServerIP;
467 Item1->FullScreen = Item2->FullScreen;
468 }
469 ListBox->removeItem(i);
470 }
471 }
472
473 /******************************************************************************/
474 void QMyDialog::ListBoxChanged()
475 {
476 int i;
477 QMyConnectionItem * Item;
478 char Text[100];
479
480 i = ListBox->currentItem();
481 if (i >= 0 && i < 10)
482 {
483 Item = ConnectionList[i];
484 ServerNameEdit->setText(Item->ServerName);
485 UserNameEdit->setText(Item->UserName);
486 sprintf(Text, "%d", Item->Width);
487 WidthEdit->setText(Text);
488 sprintf(Text, "%d", Item->Height);
489 HeightEdit->setText(Text);
490 IPEdit->setText(Item->ServerIP);
491 FullScreenCheckBox->setChecked(Item->FullScreen != 0);
492 }
493 }
494
495 /******************************************************************************/
496 void QMyDialog::ListBoxSelected(int /*index*/)
497 {
498 }
499
500 /******************************************************************************/
501 void GetScanCode(QKeyEvent * e, int * ScanCode, int * code)
502 {
503 int key;
504 int mod;
505 int ascii;
506
507 key = e->key();
508 mod = e->state();
509 ascii = e->ascii();
510
511 *ScanCode = 0;
512 *code = mod; // 8 shift, 16 control, 32 alt
513
514 switch (key)
515 {
516 case 4096: // esc
517 case 4097: // tab
518 case 4099: // backspace
519 case 4100: // enter
520 case 4101: // enter
521 case 4103: // delete
522 ascii = 0;
523 }
524
525 if (ascii == 0)
526 {
527 switch (key)
528 {
529 case 4096: *ScanCode = 0x01; break; // esc
530 case 4097: *ScanCode = 0x0f; break; // tab
531 case 4099: *ScanCode = 0x0e; break; // backspace
532 case 4100: *ScanCode = 0x1c; break; // enter
533 case 4101: *ScanCode = 0x1c; break; // enter
534 case 4112: *ScanCode = 0xc7; break; // home
535 case 4113: *ScanCode = 0xcf; break; // end
536 case 4102: *ScanCode = 0xd2; break; // insert
537 case 4103: *ScanCode = 0xd3; break; // delete
538 case 4118: *ScanCode = 0xc9; break; // page up
539 case 4119: *ScanCode = 0xd1; break; // page down
540 case 4117: *ScanCode = 0xd0; break; // down arrow
541 case 4115: *ScanCode = 0xc8; break; // up arrow
542 case 4114: *ScanCode = 0xcb; break; // left arrow
543 case 4116: *ScanCode = 0xcd; break; // right arrow
544 case 4128: *ScanCode = 0x2a; break; // shift
545 case 4131: *ScanCode = 0x38; break; // alt
546 case 4129: *ScanCode = 0x1d; break; // ctrl
547 }
548 if (*ScanCode != 0)
549 return;
550 }
551
552 switch (ascii)
553 {
554 // first row
555 case 'q': *ScanCode = 0x10; break;
556 case 'Q': *ScanCode = 0x10; *code |= 8; break;
557 case '1': *ScanCode = 0x02; break;
558 case 'w': *ScanCode = 0x11; break;
559 case 'W': *ScanCode = 0x11; *code |= 8; break;
560 case '2': *ScanCode = 0x03; break;
561 case 'e': *ScanCode = 0x12; break;
562 case 'E': *ScanCode = 0x12; *code |= 8; break;
563 case '3': *ScanCode = 0x04; break;
564 case 'r': *ScanCode = 0x13; break;
565 case 'R': *ScanCode = 0x13; *code |= 8; break;
566 case '4': *ScanCode = 0x05; break;
567 case 't': *ScanCode = 0x14; break;
568 case 'T': *ScanCode = 0x14; *code |= 8; break;
569 case '5': *ScanCode = 0x06; break;
570 case 'y': *ScanCode = 0x15; break;
571 case 'Y': *ScanCode = 0x15; *code |= 8; break;
572 case '6': *ScanCode = 0x07; break;
573 case 'u': *ScanCode = 0x16; break;
574 case 'U': *ScanCode = 0x16; *code |= 8; break;
575 case '7': *ScanCode = 0x08; break;
576 case 'i': *ScanCode = 0x17; break;
577 case 'I': *ScanCode = 0x17; *code |= 8; break;
578 case '8': *ScanCode = 0x09; break;
579 case 'o': *ScanCode = 0x18; break;
580 case 'O': *ScanCode = 0x18; *code |= 8; break;
581 case '9': *ScanCode = 0x0a; break;
582 case 'p': *ScanCode = 0x19; break;
583 case 'P': *ScanCode = 0x19; *code |= 8; break;
584 case '0': *ScanCode = 0x0b; break;
585 // second row
586 case 'a': *ScanCode = 0x1e; break;
587 case 'A': *ScanCode = 0x1e; *code |= 8; break;
588 case '!': *ScanCode = 0x02; *code |= 8; break;
589 case 's': *ScanCode = 0x1f; break;
590 case 'S': *ScanCode = 0x1f; *code |= 8; break;
591 case '@': *ScanCode = 0x03; *code |= 8; break;
592 case 'd': *ScanCode = 0x20; break;
593 case 'D': *ScanCode = 0x20; *code |= 8; break;
594 case '#': *ScanCode = 0x04; *code |= 8; break;
595 case 'f': *ScanCode = 0x21; break;
596 case 'F': *ScanCode = 0x21; *code |= 8; break;
597 case '$': *ScanCode = 0x05; *code |= 8; break;
598 case 'g': *ScanCode = 0x22; break;
599 case 'G': *ScanCode = 0x22; *code |= 8; break;
600 case '%': *ScanCode = 0x06; *code |= 8; break;
601 case 'h': *ScanCode = 0x23; break;
602 case 'H': *ScanCode = 0x23; *code |= 8; break;
603 case '_': *ScanCode = 0x0c; *code |= 8; break;
604 case 'j': *ScanCode = 0x24; break;
605 case 'J': *ScanCode = 0x24; *code |= 8; break;
606 case '&': *ScanCode = 0x08; *code |= 8; break;
607 case 'k': *ScanCode = 0x25; break;
608 case 'K': *ScanCode = 0x25; *code |= 8; break;
609 case '*': *ScanCode = 0x09; *code |= 8; break;
610 case 'l': *ScanCode = 0x26; break;
611 case 'L': *ScanCode = 0x26; *code |= 8; break;
612 case '(': *ScanCode = 0x0a; *code |= 8; break;
613 // case 8: *ScanCode = 0x0e; break; // backspace
614 // third row
615 case 'z': *ScanCode = 0x2c; break;
616 case 'Z': *ScanCode = 0x2c; *code |= 8; break;
617 case 'x': *ScanCode = 0x2d; break;
618 case 'X': *ScanCode = 0x2d; *code |= 8; break;
619 case 'c': *ScanCode = 0x2e; break;
620 case 'C': *ScanCode = 0x2e; *code |= 8; break;
621 case 'v': *ScanCode = 0x2f; break;
622 case 'V': *ScanCode = 0x2f; *code |= 8; break;
623 case 'b': *ScanCode = 0x30; break;
624 case 'B': *ScanCode = 0x30; *code |= 8; break;
625 case '-': *ScanCode = 0x0c; break;
626 case 'n': *ScanCode = 0x31; break;
627 case 'N': *ScanCode = 0x31; *code |= 8; break;
628 case '+': *ScanCode = 0x0d; *code |= 8; break;
629 case 'm': *ScanCode = 0x32; break;
630 case 'M': *ScanCode = 0x32; *code |= 8; break;
631 case '=': *ScanCode = 0x0d; break;
632 case ',': *ScanCode = 0x33; break;
633 case ';': *ScanCode = 0x27; break;
634 case ')': *ScanCode = 0x0b; *code |= 8; break;
635 // fourth row
636 // case 9: *ScanCode = 0x0f; break; // tab
637 case '/': *ScanCode = 0x35; break;
638 case '?': *ScanCode = 0x35; *code |= 8; break;
639 case ' ': *ScanCode = 0x39; break;
640 case '\'': *ScanCode = 0x28; break;
641 case '"': *ScanCode = 0x28; *code |= 8; break;
642 case '~': *ScanCode = 0x29; *code |= 8; break;
643 case '.': *ScanCode = 0x34; break;
644 case ':': *ScanCode = 0x27; *code |= 8; break;
645 case '<': *ScanCode = 0x33; *code |= 8; break;
646 // case 13: *ScanCode = 0x1c; break; // enter
647 case '>': *ScanCode = 0x34; *code |= 8; break;
648 // others
649 // case 27: *ScanCode = 0x01; break; // esc
650 case '`': *ScanCode = 0x29; break;
651 case '^': *ScanCode = 0x07; *code |= 8; break;
652 case '[': *ScanCode = 0x1a; break;
653 case '{': *ScanCode = 0x1a; *code |= 8; break;
654 case ']': *ScanCode = 0x1b; break;
655 case '}': *ScanCode = 0x1b; *code |= 8; break;
656 case '\\': *ScanCode = 0x2b; break;
657 case '|': *ScanCode = 0x2b; *code |= 8; break;
658 // ctrl keys
659 case 1: *ScanCode = 0x1e; *code |= 16; break; // a
660 case 2: *ScanCode = 0x30; *code |= 16; break; // b
661 }
662
663 if (*ScanCode == 0 && key < 3000)
664 printf("unknown key %d mod %d ascii %d\n", key, mod, ascii);
665
666 }
667
668 /******************************************************************************/
669 QMyScrollView::QMyScrollView() : QScrollView()
670 {
671 }
672
673 /******************************************************************************/
674 QMyScrollView::~QMyScrollView()
675 {
676 }
677
678 /******************************************************************************/
679 void QMyScrollView::keyPressEvent(QKeyEvent* e)
680 {
681 int ScanCode, code;
682 GetScanCode(e, &ScanCode, &code);
683 if (ScanCode != 0)
684 {
685 if (code & 8) // send shift
686 rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x2a, 0);
687 if (code & 16) // send control
688 rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x1d, 0);
689 if (code & 32) // send alt
690 rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x38, 0);
691 rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYPRESS, ScanCode, 0);
692 e->accept();
693 }
694 }
695
696 /******************************************************************************/
697 void QMyScrollView::keyReleaseEvent(QKeyEvent* e)
698 {
699 int ScanCode, code;
700 GetScanCode(e, &ScanCode, &code);
701 if (ScanCode != 0)
702 {
703 rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, ScanCode, 0);
704 if (code & 8) // send shift
705 rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, 0x2a, 0);
706 if (code & 16) // send control
707 rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, 0x1d, 0);
708 if (code & 32) // send alt
709 rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, 0x38, 0);
710 e->accept();
711 }
712 }
713
714 /******************************************************************************/
715 void QMyScrollView::showEvent(QShowEvent* e)
716 {
717 QScrollView::showEvent(e);
718 }
719
720 /******************************************************************************/
721 void QMyScrollView::show()
722 {
723 QScrollView::show();
724 }
725
726 /******************************************************************************/
727 void QMyScrollView::polish()
728 {
729 QScrollView::polish();
730 }
731
732 /******************************************************************************/
733 void QMyScrollView::timerEvent(QTimerEvent * e)
734 {
735 QScrollView::timerEvent(e);
736 killTimer(timer_id);
737 QMyDialog * d;
738 QWidget * Desktop;
739 int dw;
740 int dh;
741
742 d = new QMyDialog(this);
743 if (d->exec() == 1) // ok clicked
744 {
745 g_width = d->Width;
746 g_height = d->Height;
747 g_client_width = g_width;
748 g_client_height = g_height;
749 g_fullscreen = d->FullScreen;
750 sprintf(g_server, "%s", (const char*)d->ServerIP);
751 sprintf(g_username, "%s", (const char*)d->UserName);
752 if (!rdp_connect(g_server, g_flags, g_domain, g_password, g_shell,
753 g_directory))
754 {
755 delete d;
756 g_SV->close();
757 return;
758 }
759 g_BS = (uint8*)xmalloc(g_width * g_height * 4);
760 memset(g_BS, 0, g_width * g_height * 4);
761 g_clipx = 0;
762 g_clipy = 0;
763 g_clipcx = g_width;
764 g_clipcy = g_height;
765 g_CM = (QColorMap*)xmalloc(sizeof(struct QColorMap));
766 memset(g_CM, 0, sizeof(struct QColorMap));
767 g_CM->NumColors = 256;
768 g_MW = new QMyMainWindow();
769 g_MW->resize(g_client_width, g_client_height);
770 g_MW->show();
771 g_SV->addChild(g_MW);
772 g_MW->setMouseTracking(true);
773 g_SocketNotifier = new QSocketNotifier(g_global_sock,
774 QSocketNotifier::Read,
775 g_MW);
776 g_MW->connect(g_SocketNotifier, SIGNAL(activated(int)), g_MW,
777 SLOT(dataReceived()));
778 if (g_fullscreen)
779 {
780 Desktop = g_App->desktop();
781 dw = Desktop->width();
782 dh = Desktop->height();
783 if (dw == g_client_width && dh == g_client_height)
784 g_MW->resize(g_client_width - 4, g_client_height - 4);
785 g_SV->showFullScreen();
786 }
787 delete d;
788 }
789 else // cancel clicked
790 {
791 delete d;
792 g_SV->close();
793 }
794 }
795
796 /******************************************************************************/
797 QMyMainWindow::QMyMainWindow() : QWidget(g_SV->viewport())
798 {
799 PopupMenu = new QPopupMenu(this);
800 PopupMenu->insertItem("Right click", 1, 0);
801 PopupMenu->insertItem("Toggle fullscreen", 2, 1);
802 PopupMenu->insertItem("Reset keyboard", 3, 2);
803 PopupMenu->insertItem("Double click", 4, 3);
804 connect(PopupMenu, SIGNAL(activated(int)), this, SLOT(MemuClicked(int)));
805 }
806
807 /******************************************************************************/
808 QMyMainWindow::~QMyMainWindow()
809 {
810 delete PopupMenu;
811 }
812
813 /******************************************************************************/
814 int rd(double in)
815 {
816 return (int)(in + 0.50);
817 }
818
819 /******************************************************************************/
820 int c2sx(int cx)
821 {
822 double sx;
823
824 sx = (double)g_client_width / (double)g_width;
825 return rd(cx / sx);
826 }
827
828 /******************************************************************************/
829 int c2sy(int cy)
830 {
831 double sy;
832
833 sy = (double)g_client_height / (double)g_height;
834 return rd(cy / sy);
835 }
836
837 /******************************************************************************/
838 void QMyMainWindow::timerEvent(QTimerEvent * e)
839 {
840 QWidget::timerEvent(e);
841 if (e->timerId() == timer_id)
842 {
843 // send mouse up
844 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1,
845 rd(c2sx(mx)), rd(c2sy(my)));
846 // if in fullscreen, take it out or the menu won't work
847 if (g_fullscreen)
848 {
849 g_fullscreen = 0;
850 g_SV->showNormal();
851 g_SV->showMaximized();
852 }
853 else
854 PopupMenu->popup(mapToGlobal(QPoint(mx, my)));
855 }
856 killTimer(timer_id);
857 }
858
859 /******************************************************************************/
860 void QMyMainWindow::MemuClicked(int MenuID)
861 {
862 QWidget * Desktop;
863 int dw;
864 int dh;
865
866 if (MenuID == 1) // right click
867 {
868 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON2,
869 rd(c2sx(mx)), rd(c2sy(my)));
870 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON2,
871 rd(c2sx(mx)), rd(c2sy(my)));
872 }
873 else if (MenuID == 2) // toggle full screen
874 {
875 g_fullscreen = ~g_fullscreen;
876 if (g_fullscreen)
877 {
878 Desktop = g_App->desktop();
879 dw = Desktop->width();
880 dh = Desktop->height();
881 if (dw == g_client_width && dh == g_client_height)
882 g_MW->resize(g_client_width - 4, g_client_height - 4);
883 g_SV->showFullScreen();
884 }
885 else
886 {
887 g_SV->showNormal();
888 g_SV->showMaximized();
889 g_MW->resize(g_client_width, g_client_height);
890 }
891 }
892 else if (MenuID == 3) // reset keyboard
893 {
894 rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, 0x2a, 0); // shift
895 rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, 0x1d, 0); // control
896 rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, 0x38, 0); // alt
897 }
898 else if (MenuID == 4) // double click
899 {
900 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON1,
901 rd(c2sx(mx)), rd(c2sy(my)));
902 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1,
903 rd(c2sx(mx)), rd(c2sy(my)));
904 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON1,
905 rd(c2sx(mx)), rd(c2sy(my)));
906 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1,
907 rd(c2sx(mx)), rd(c2sy(my)));
908 }
909 }
910
911 /******************************************************************************/
912 void QMyMainWindow::mouseMoveEvent(QMouseEvent* e)
913 {
914 int x, y;
915
916 x = e->x();
917 y = e->y();
918 if (timer_id)
919 {
920 x = x - mx;
921 y = y - my;
922 if (x < -10 || x > 10 || y < -10 || y > 10)
923 {
924 killTimer(timer_id);
925 timer_id = 0;
926 }
927 }
928 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_MOVE, c2sx(e->x()),
929 c2sy(e->y()));
930 }
931
932 /******************************************************************************/
933 void QMyMainWindow::mousePressEvent(QMouseEvent* e)
934 {
935 timer_id = startTimer(1000);
936 mx = e->x();
937 my = e->y();
938 if (e->button() == LeftButton)
939 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON1,
940 c2sx(e->x()), c2sy(e->y()));
941 else if (e->button() == RightButton)
942 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON2,
943 c2sx(e->x()), c2sy(e->y()));
944 else if (e->button() == MidButton)
945 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON3,
946 c2sx(e->x()), c2sy(e->y()));
947 }
948
949 /******************************************************************************/
950 void QMyMainWindow::mouseReleaseEvent(QMouseEvent* e)
951 {
952 killTimer(timer_id);
953 timer_id = 0;
954 if (e->button() == LeftButton)
955 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1, c2sx(e->x()),
956 c2sy(e->y()));
957 else if (e->button() == RightButton)
958 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON2, c2sx(e->x()),
959 c2sy(e->y()));
960 else if (e->button() == MidButton)
961 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON3, c2sx(e->x()),
962 c2sy(e->y()));
963 }
964
965 /******************************************************************************/
966 void QMyMainWindow::wheelEvent(QWheelEvent* e)
967 {
968 if (e->delta() > 0)
969 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON4, c2sx(e->x()),
970 c2sy(e->y()));
971 else if (e->delta() < 0)
972 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON5, c2sx(e->x()),
973 c2sy(e->y()));
974 }
975
976 #define NOT(x) (~x)
977
978 /******************************************************************************/
979 int rop(int rop, int src, int dst)
980 {
981 switch (rop)
982 {
983 case 0x0: return 0;
984 case 0x1: return NOT (src | dst);
985 case 0x2: return NOT (src) & dst;
986 case 0x3: return NOT (src);
987 case 0x4: return src & NOT (dst);
988 case 0x5: return NOT (dst);
989 case 0x6: return src ^ dst;
990 case 0x7: return NOT (src & dst);
991 case 0x8: return src & dst;
992 case 0x9: return NOT (src) ^ dst;
993 case 0xa: return dst;
994 case 0xb: return NOT (src) | dst;
995 case 0xc: return src;
996 case 0xd: return src | NOT (dst);
997 case 0xe: return src | dst;
998 case 0xf: return NOT (0);
999 }
1000 return dst;
1001 }
1002
1003 /*****************************************************************************/
1004 int get_pixel(int x, int y)
1005 {
1006 if (x >= 0 && x < g_width && y >= 0 && y < g_height)
1007 {
1008 if (g_server_bpp == 8)
1009 return GETPIXEL8(g_BS, x, y, g_width);
1010 else if (g_server_bpp == 16)
1011 return GETPIXEL16(g_BS, x, y, g_width);
1012 else if (g_server_bpp == 24)
1013 return GETPIXEL32(g_BS, x, y, g_width);
1014 else
1015 return 0;
1016 }
1017 else
1018 return 0;
1019 }
1020
1021 /******************************************************************************/
1022 void set_pixel(int x, int y, int pixel, int op = 0xc)
1023 {
1024 int p;
1025
1026 if (x >= g_clipx && x < (g_clipx + g_clipcx) &&
1027 y >= g_clipy && y < (g_clipy + g_clipcy))
1028 {
1029 if (x >= 0 && x < g_width && y >= 0 && y < g_height)
1030 {
1031 if (op == 0xc)
1032 {
1033 if (g_server_bpp == 8)
1034 {
1035 SETPIXEL8(g_BS, x, y, g_width, pixel);
1036 }
1037 else if (g_server_bpp == 16)
1038 {
1039 SETPIXEL16(g_BS, x, y, g_width, pixel);
1040 }
1041 else if (g_server_bpp == 24)
1042 {
1043 SETPIXEL32(g_BS, x, y, g_width, pixel);
1044 }
1045 }
1046 else
1047 {
1048 if (g_server_bpp == 8)
1049 {
1050 p = GETPIXEL8(g_BS, x, y, g_width);
1051 p = rop(op, pixel, p);
1052 SETPIXEL8(g_BS, x, y, g_width, p);
1053 }
1054 else if (g_server_bpp == 16)
1055 {
1056 p = GETPIXEL16(g_BS, x, y, g_width);
1057 p = rop(op, pixel, p);
1058 SETPIXEL16(g_BS, x, y, g_width, p);
1059 }
1060 else if (g_server_bpp == 24)
1061 {
1062 p = GETPIXEL32(g_BS, x, y, g_width);
1063 p = rop(op, pixel, p);
1064 SETPIXEL32(g_BS, x, y, g_width, p);
1065 }
1066 }
1067 }
1068 }
1069 }
1070
1071 /******************************************************************************/
1072 // adjust coordinates for cliping rect
1073 bool WarpCoords(int * x, int * y, int * cx, int * cy, int * srcx, int * srcy)
1074 {
1075 int dx, dy;
1076 QRect InRect(*x, *y, *cx, *cy);
1077 QRect OutRect;
1078 QRect CRect(g_clipx, g_clipy, g_clipcx, g_clipcy);
1079 OutRect = InRect.intersect(CRect);
1080 if (OutRect.isEmpty())
1081 return false;
1082 dx = OutRect.x() - InRect.x();
1083 dy = OutRect.y() - InRect.y();
1084 *x = OutRect.x();
1085 *y = OutRect.y();
1086 *cx = OutRect.width();
1087 *cy = OutRect.height();
1088 if (srcx != NULL)
1089 *srcx = *srcx + dx;
1090 if (srcy != NULL)
1091 *srcy = *srcy + dy;
1092 return true;
1093 }
1094
1095 /******************************************************************************/
1096 void QMyMainWindow::paintEvent(QPaintEvent * pe)
1097 {
1098 QImage * Image;
1099 QPainter * Painter;
1100 QRect Rect;
1101 int i, j, w, h, l, t, pixel, r, g, b;
1102 uint8 * data;
1103 double sx, sy;
1104
1105 Image = 0;
1106 data = 0;
1107 if (!testWFlags(WRepaintNoErase))
1108 setWFlags(WRepaintNoErase);
1109 if (g_CM != NULL || g_server_bpp > 8)
1110 {
1111 sx = (double)g_client_width / (double)g_width;
1112 sy = (double)g_client_height / (double)g_height;
1113 Rect = pe->rect();
1114 l = rd(Rect.left() / sx);
1115 t = rd(Rect.top() / sy);
1116 w = rd(Rect.width() / sx);
1117 h = rd(Rect.height() / sy);
1118 if (w > 0 && h > 0)
1119 {
1120 if (g_server_bpp == 8 && g_CM->NumColors > 0)
1121 {
1122 w = (w + 3) & ~3;
1123 data = (uint8*)xmalloc(w * h);
1124 for (i = 0; i < h; i++)
1125 for (j = 0; j < w; j++)
1126 data[i * w + j] = GETPIXEL8(g_BS, l + j, t + i, g_width);
1127 Image = new QImage(data, w, h, 8,(QRgb*)g_CM->RGBColors,
1128 g_CM->NumColors, QImage::IgnoreEndian);
1129 }
1130 else if (g_server_bpp == 16)
1131 {
1132 w = (w + 3) & ~3;
1133 data = (uint8*)xmalloc(w * h * 4);
1134 for (i = 0; i < h; i++)
1135 for (j = 0; j < w; j++)
1136 {
1137 pixel = GETPIXEL16(g_BS, l + j, t + i, g_width);
1138 r = ((pixel >> 8) & 0xf8) | ((pixel >> 13) & 0x7);
1139 g = ((pixel >> 3) & 0xfc) | ((pixel >> 9) & 0x3);
1140 b = ((pixel << 3) & 0xf8) | ((pixel >> 2) & 0x7);
1141 pixel = ((r << 16) | (g << 8) | b);
1142 SETPIXEL32(data, j, i, w, pixel);
1143 }
1144 Image = new QImage(data, w, h, 32, NULL,
1145 0, QImage::IgnoreEndian);
1146 }
1147 else if (g_server_bpp == 24)
1148 {
1149 w = (w + 3) & ~3;
1150 data = (uint8*)xmalloc(w * h * 4);
1151 for (i = 0; i < h; i++)
1152 for (j = 0; j < w; j++)
1153 {
1154 pixel = GETPIXEL32(g_BS, l + j, t + i, g_width);
1155 r = (pixel >> 0) & 0xff;
1156 g = (pixel >> 8) & 0xff;
1157 b = (pixel >> 16) & 0xff;
1158 pixel = ((r << 16) | (g << 8) | b);
1159 SETPIXEL32(data, j, i, w, pixel);
1160 }
1161 Image = new QImage(data, w, h, 32, NULL,
1162 0, QImage::IgnoreEndian);
1163 }
1164 if (Image != 0)
1165 {
1166 Painter = new QPainter(this);
1167 Painter->scale(sx, sy);
1168 Painter->drawImage(l, t, *Image, 0, 0, w, h);
1169 delete Painter;
1170 delete Image;
1171 }
1172 xfree(data);
1173 }
1174 }
1175 }
1176
1177 /******************************************************************************/
1178 void QMyMainWindow::closeEvent(QCloseEvent * e)
1179 {
1180 e->accept();
1181 }
1182
1183 /******************************************************************************/
1184 void QMyMainWindow::dataReceived()
1185 {
1186 if (!rdp_loop(&g_deactivated, &g_ext_disc_reason))
1187 g_SV->close();
1188 #ifdef WITH_RDPSND
1189 if (g_dsp_busy)
1190 {
1191 if (g_SoundNotifier == 0)
1192 {
1193 g_SoundNotifier = new QSocketNotifier(g_dsp_fd, QSocketNotifier::Write,
1194 g_MW);
1195 g_MW->connect(g_SoundNotifier, SIGNAL(activated(int)), g_MW,
1196 SLOT(soundSend()));
1197 }
1198 else
1199 {
1200 if (!g_SoundNotifier->isEnabled())
1201 g_SoundNotifier->setEnabled(true);
1202 }
1203 }
1204 #endif
1205 }
1206
1207 /******************************************************************************/
1208 void QMyMainWindow::soundSend()
1209 {
1210 g_SoundNotifier->setEnabled(false);
1211 #ifdef WITH_RDPSND
1212 wave_out_play();
1213 if (g_dsp_busy)
1214 g_SoundNotifier->setEnabled(true);
1215 #endif
1216 }
1217
1218 /******************************************************************************/
1219 void redraw(int x, int y, int cx, int cy)
1220 {
1221 double sx, sy;
1222
1223 if (WarpCoords(&x, &y, &cx, &cy, NULL, NULL))
1224 {
1225 sx = (double)g_client_width / (double)g_width;
1226 sy = (double)g_client_height / (double)g_height;
1227 x = rd(x * sx);
1228 y = rd(y * sy);
1229 cx = rd(cx * sx);
1230 cy = rd(cy * sy);
1231 g_MW->update(x, y, cx, cy);
1232 }
1233 }
1234
1235 /******************************************************************************/
1236 /* Returns 0 after user quit, 1 otherwise */
1237 int ui_select(int rdp_socket)
1238 {
1239 if (g_global_sock == 0)
1240 g_global_sock = rdp_socket;
1241 return 1;
1242 }
1243
1244 /******************************************************************************/
1245 void ui_move_pointer(int /*x*/, int /*y*/)
1246 {
1247 }
1248
1249 /******************************************************************************/
1250 void ui_set_null_cursor(void)
1251 {
1252 }
1253
1254 /******************************************************************************/
1255 HBITMAP ui_create_bitmap(int width, int height, uint8 * data)
1256 {
1257 struct bitmap * the_bitmap;
1258 uint8 * bitmap_data;
1259 int i, j;
1260 int r, g, b, pixel;
1261
1262 bitmap_data = (uint8*)xmalloc(width * height * 4);
1263 the_bitmap = (struct bitmap*)xmalloc(sizeof(struct bitmap));
1264 the_bitmap->w = width;
1265 the_bitmap->h = height;
1266 the_bitmap->data = bitmap_data;
1267 if (g_server_bpp == 8)
1268 {
1269 for (i = 0; i < height; i++)
1270 for (j = 0; j < width; j++)
1271 bitmap_data[i * width + j] = data[i * width + j];
1272 }
1273 else if (g_server_bpp == 16)
1274 {
1275 for (i = 0; i < height; i++)
1276 for (j = 0; j < width; j++)
1277 *(((uint16*)bitmap_data) + (i * width + j)) =
1278 *(((uint16*)data) + (i * width + j));
1279 }
1280 else if (g_server_bpp == 24)
1281 {
1282 for (i = 0; i < height; i++)
1283 for (j = 0; j < width; j++)
1284 {
1285 r = data[(i * width + j) * 3 + 0];
1286 g = data[(i * width + j) * 3 + 1];
1287 b = data[(i * width + j) * 3 + 2];
1288 pixel = (r << 16) | (g << 8) | b;
1289 SETPIXEL32(bitmap_data, j, i, width, pixel);
1290 }
1291 }
1292 return the_bitmap;
1293 }
1294
1295 /******************************************************************************/
1296 void ui_paint_bitmap(int x, int y, int cx, int cy, int width,
1297 int height, uint8 * data)
1298 {
1299 int i, j;
1300 int r, g, b, pixel;
1301
1302 if (g_server_bpp == 8)
1303 {
1304 for (i = 0; i < cy; i++)
1305 for (j = 0; j < cx; j++)
1306 if (i < height)
1307 if (j < width)
1308 set_pixel(x + j, y + i, data[i * width + j]);
1309 }
1310 else if (g_server_bpp == 16)
1311 {
1312 for (i = 0; i < cy; i++)
1313 for (j = 0; j < cx; j++)
1314 if (i < height)
1315 if (j < width)
1316 set_pixel(x + j, y + i, *(((uint16*)data) + (i * width + j)));
1317 }
1318 else if (g_server_bpp == 24)
1319 {
1320 for (i = 0; i < cy; i++)
1321 for (j = 0; j < cx; j++)
1322 if (i < height)
1323 if (j < width)
1324 {
1325 r = data[(i * width + j) * 3 + 0];
1326 g = data[(i * width + j) * 3 + 1];
1327 b = data[(i * width + j) * 3 + 2];
1328 pixel = (r << 16) | (g << 8) | b;
1329 set_pixel(x + j, y + i, pixel);
1330 }
1331 }
1332 redraw(x, y, cx, cy);
1333 }
1334
1335 /******************************************************************************/
1336 void ui_destroy_bitmap(HBITMAP bmp)
1337 {
1338 struct bitmap* the_bitmap;
1339
1340 the_bitmap = (struct bitmap*)bmp;
1341 if (the_bitmap != NULL)
1342 {
1343 if (the_bitmap->data != NULL)
1344 xfree(the_bitmap->data);
1345 xfree(the_bitmap);
1346 }
1347 }
1348
1349 /******************************************************************************/
1350 bool is_pixel_on(uint8 * data, int x, int y, int width, int bpp)
1351 {
1352 int start, shift;
1353
1354 if (bpp == 1)
1355 {
1356 width = (width + 7) / 8;
1357 start = (y * width) + x / 8;
1358 shift = x % 8;
1359 return (data[start] & (0x80 >> shift)) != 0;
1360 }
1361 else if (bpp == 8)
1362 return data[y * width + x] != 0;
1363 else
1364 return false;
1365 }
1366
1367 /******************************************************************************/
1368 void set_pixel_on(uint8 * data, int x, int y, int width, int bpp, uint8 pixel)
1369 {
1370 if (bpp == 8)
1371 data[y * width + x] = pixel;
1372 }
1373
1374 /******************************************************************************/
1375 HGLYPH ui_create_glyph(int width, int height, uint8 * data)
1376 {
1377 int i, j;
1378 uint8* glyph_data;
1379 struct bitmap* the_glyph;
1380
1381 glyph_data = (uint8*)xmalloc(width * height);
1382 the_glyph = (struct bitmap*)xmalloc(sizeof(struct bitmap));
1383 the_glyph->w = width;
1384 the_glyph->h = height;
1385 the_glyph->data = glyph_data;
1386 memset(glyph_data, 0, width * height);
1387 for (i = 0; i < height; i++)
1388 for (j = 0; j < width; j++)
1389 if (is_pixel_on(data, j, i, width, 1))
1390 set_pixel_on(glyph_data, j, i, width, 8, 255);
1391 return the_glyph;
1392 }
1393
1394 /******************************************************************************/
1395 void ui_destroy_glyph(HGLYPH glyph)
1396 {
1397 struct bitmap* the_glyph;
1398
1399 the_glyph = (struct bitmap*)glyph;
1400 if (the_glyph != NULL)
1401 {
1402 if (the_glyph->data != NULL)
1403 xfree(the_glyph->data);
1404 xfree(the_glyph);
1405 }
1406 }
1407
1408 /******************************************************************************/
1409 HCURSOR ui_create_cursor(uint32 x, uint32 y,
1410 int width, int height,
1411 uint8 * andmask, uint8 * xormask)
1412 {
1413 return (void*)1;
1414 }
1415
1416 /******************************************************************************/
1417 void ui_set_cursor(HCURSOR /*cursor*/)
1418 {
1419 }
1420
1421 /*****************************************************************************/
1422 uint16 ui_get_numlock_state(uint32 state)
1423 {
1424 return 0;
1425 }
1426
1427 /*****************************************************************************/
1428 unsigned int read_keyboard_state(void)
1429 {
1430 return 0;
1431 }
1432
1433 /*****************************************************************************/
1434 void ui_resize_window(void)
1435 {
1436 }
1437
1438 /******************************************************************************/
1439 void ui_destroy_cursor(HCURSOR /*cursor*/)
1440 {
1441 }
1442
1443 /******************************************************************************/
1444 HCOLOURMAP ui_create_colourmap(COLOURMAP * colours)
1445 {
1446 int i;
1447 int x;
1448 uint8 r, g, b;
1449 i = 0;
1450 while (i < colours->ncolours && i < 256)
1451 {
1452 r = colours->colours[i].red;
1453 g = colours->colours[i].green;
1454 b = colours->colours[i].blue;
1455 x = (r << 16) | (g << 8) | b;
1456 g_CM->RGBColors[i] = x;
1457 i++;
1458 }
1459 g_CM->NumColors = colours->ncolours;
1460 return g_CM;
1461 }
1462
1463 /******************************************************************************/
1464 void ui_set_colourmap(HCOLOURMAP map)
1465 {
1466 }
1467
1468 /******************************************************************************/
1469 void ui_destroy_colourmap(HCOLOURMAP map)
1470 {
1471 }
1472
1473 /******************************************************************************/
1474 void ui_begin_update(void)
1475 {
1476 }
1477
1478 /******************************************************************************/
1479 void ui_end_update(void)
1480 {
1481 }
1482
1483 /******************************************************************************/
1484 void ui_set_clip(int x, int y, int cx, int cy)
1485 {
1486 g_clipx = x;
1487 g_clipy = y;
1488 g_clipcx = cx;
1489 g_clipcy = cy;
1490 }
1491
1492 /******************************************************************************/
1493 void ui_reset_clip(void)
1494 {
1495 g_clipx = 0;
1496 g_clipy = 0;
1497 g_clipcx = g_width;
1498 g_clipcy = g_height;
1499 }
1500
1501 /******************************************************************************/
1502 void ui_bell(void)
1503 {
1504 g_App->beep();
1505 }
1506
1507 /******************************************************************************/
1508 void ui_destblt(uint8 opcode, int x, int y, int cx, int cy)
1509 {
1510 int i, j;
1511
1512 for (i = 0; i < cy; i++)
1513 for (j = 0; j < cx; j++)
1514 set_pixel(x + j, y + i, get_pixel(x + j, y + i), opcode);
1515 redraw(x, y, cx, cy);
1516 }
1517
1518 /******************************************************************************/
1519 // does not repaint
1520 void fill_rect(int x, int y, int cx, int cy, int colour, int opcode = 0xc)
1521 {
1522 int i, j;
1523
1524 if (x + cx > g_width)
1525 cx = g_width - x;
1526 if (y + cy > g_height)
1527 cy = g_height - y;
1528 #ifdef QT_OPTI
1529 if (opcode == 0xc) /* optimize */
1530 {
1531 if (WarpCoords(&x, &y, &cx, &cy, 0, 0))
1532 {
1533 if (g_server_bpp == 8)
1534 {
1535 for (i = 0; i < cy; i++)
1536 for (j = 0; j < cx; j++)
1537 SETPIXEL8(g_BS, x + j, y + i, g_width, colour);
1538 }
1539 else if (g_server_bpp == 16)
1540 {
1541 for (i = 0; i < cy; i++)
1542 for (j = 0; j < cx; j++)
1543 SETPIXEL16(g_BS, x + j, y + i, g_width, colour);
1544 }
1545 else if (g_server_bpp == 24)
1546 {
1547 for (i = 0; i < cy; i++)
1548 for (j = 0; j < cx; j++)
1549 SETPIXEL32(g_BS, x + j, y + i, g_width, colour);
1550 }
1551 }
1552 }
1553 else
1554 #endif
1555 {
1556 for (i = 0; i < cy; i++)
1557 for (j = 0; j < cx; j++)
1558 set_pixel(x + j, y + i, colour, opcode);
1559 }
1560 }
1561
1562 /******************************************************************************/
1563 void ui_rect(int x, int y, int cx, int cy, int colour)
1564 {
1565 fill_rect(x, y, cx, cy, colour);
1566 redraw(x, y, cx, cy);
1567 }
1568
1569 /******************************************************************************/
1570 void ui_patblt(uint8 opcode, int x, int y, int cx, int cy,
1571 BRUSH * brush, int bgcolour, int fgcolour)
1572 {
1573 int i, j;
1574 uint8 ipattern[8];
1575
1576 switch (brush->style)
1577 {
1578 case 0:
1579 fill_rect(x, y, cx, cy, fgcolour, opcode);
1580 break;
1581 case 3:
1582 for (i = 0; i < 8; i++)
1583 ipattern[i] = ~brush->pattern[7 - i];
1584 for (i = 0; i < cy; i++)
1585 for (j = 0; j < cx; j++)
1586 if (is_pixel_on(ipattern, (x + j + brush->xorigin) % 8,
1587 (y + i + brush->yorigin) % 8, 8, 1))
1588 set_pixel(x + j, y + i, fgcolour, opcode);
1589 else
1590 set_pixel(x + j, y + i, bgcolour, opcode);
1591 break;
1592 }
1593 redraw(x, y, cx, cy);
1594 }
1595
1596 /******************************************************************************/
1597 void ui_screenblt(uint8 opcode, int x, int y, int cx, int cy,
1598 int srcx, int srcy)
1599 {
1600 int i, j, pixel;
1601 uint8 * temp;
1602
1603 temp = (uint8*)xmalloc(cx * cy * 4);
1604 if (g_server_bpp == 8)
1605 {
1606 for (i = 0; i < cy; i++)
1607 for (j = 0; j < cx; j++)
1608 temp[i * cx + j] = get_pixel(srcx + j, srcy + i);
1609 for (i = 0; i < cy; i++)
1610 for (j = 0; j < cx; j++)
1611 set_pixel(x + j, y + i, temp[i * cx + j], opcode);
1612 }
1613 else if (g_server_bpp == 16)
1614 {
1615 for (i = 0; i < cy; i++)
1616 for (j = 0; j < cx; j++)
1617 {
1618 pixel = get_pixel(srcx + j, srcy + i);
1619 SETPIXEL16(temp, j, i, cx, pixel);
1620 }
1621 for (i = 0; i < cy; i++)
1622 for (j = 0; j < cx; j++)
1623 {
1624 pixel = GETPIXEL16(temp, j, i, cx);
1625 set_pixel(x + j, y + i, pixel, opcode);
1626 }
1627 }
1628 else if (g_server_bpp == 24)
1629 {
1630 for (i = 0; i < cy; i++)
1631 for (j = 0; j < cx; j++)
1632 *(((uint32*)temp) + (i * cx + j)) = get_pixel(srcx + j, srcy + i);
1633 for (i = 0; i < cy; i++)
1634 for (j = 0; j < cx; j++)
1635 set_pixel(x + j, y + i, *(((uint32*)temp) + (i * cx + j)), opcode);
1636 }
1637 xfree(temp);
1638 redraw(x, y, cx, cy);
1639 }
1640
1641 /******************************************************************************/
1642 void ui_memblt(uint8 opcode, int x, int y, int cx, int cy,
1643 HBITMAP src, int srcx, int srcy)
1644 {
1645 int i, j, p;
1646 struct bitmap * the_bitmap;
1647
1648 the_bitmap = (struct bitmap*)src;
1649 if (the_bitmap == NULL)
1650 return;
1651 #ifdef QT_OPTI
1652 if (opcode == 0xc) /* optimize */
1653 {
1654 if (WarpCoords(&x, &y, &cx, &cy, &srcx, &srcy))
1655 {
1656 if (g_server_bpp == 8)
1657 {
1658 for (i = 0; i < cy; i++)
1659 for (j = 0; j < cx; j++)
1660 {
1661 p = GETPIXEL8(the_bitmap->data, srcx + j, srcy + i, the_bitmap->w);
1662 SETPIXEL8(g_BS, x + j, y + i, g_width, p);
1663 }
1664 }
1665 else if (g_server_bpp == 16)
1666 {
1667 for (i = 0; i < cy; i++)
1668 for (j = 0; j < cx; j++)
1669 {
1670 p = GETPIXEL16(the_bitmap->data, srcx + j, srcy + i, the_bitmap->w);
1671 SETPIXEL16(g_BS, x + j, y + i, g_width, p);
1672 }
1673 }
1674 else if (g_server_bpp == 24)
1675 {
1676 for (i = 0; i < cy; i++)
1677 for (j = 0; j < cx; j++)
1678 {
1679 p = GETPIXEL32(the_bitmap->data, srcx + j, srcy + i, the_bitmap->w);
1680 SETPIXEL32(g_BS, x + j, y + i, g_width, p);
1681 }
1682 }
1683 }
1684 }
1685 else
1686 #endif
1687 {
1688 if (g_server_bpp == 8)
1689 {
1690 for (i = 0; i < cy; i++)
1691 for (j = 0; j < cx; j++)
1692 if ((i + srcy) < the_bitmap->h && (j + srcx) < the_bitmap->w)
1693 set_pixel(x + j, y + i,
1694 the_bitmap->data[(i + srcy) * the_bitmap->w + (j + srcx)],
1695 opcode);
1696 }
1697 else if (g_server_bpp == 16)
1698 {
1699 for (i = 0; i < cy; i++)
1700 for (j = 0; j < cx; j++)
1701 if ((i + srcy) < the_bitmap->h && (j + srcx) < the_bitmap->w)
1702 set_pixel(x + j, y + i,
1703 *(((uint16*)the_bitmap->data) + ((i + srcy) * the_bitmap->w + (j + srcx))),
1704 opcode);
1705 }
1706 else if (g_server_bpp == 24)
1707 {
1708 for (i = 0; i < cy; i++)
1709 for (j = 0; j < cx; j++)
1710 if ((i + srcy) < the_bitmap->h && (j + srcx) < the_bitmap->w)
1711 set_pixel(x + j, y + i,
1712 *(((uint32*)the_bitmap->data) + ((i + srcy) * the_bitmap->w + (j + srcx))),
1713 opcode);
1714 }
1715 }
1716 redraw(x, y, cx, cy);
1717 }
1718
1719 /******************************************************************************/
1720 // not used
1721 void ui_triblt(uint8 opcode, int x, int y, int cx, int cy,
1722 HBITMAP src, int srcx, int srcy, BRUSH * brush,
1723 int bgcolour, int fgcolour)
1724 {
1725 }
1726
1727 /******************************************************************************/
1728 /* Bresenham's line drawing algorithm */
1729 void ui_line(uint8 opcode, int startx, int starty, int endx,
1730 int endy, PEN * pen)
1731 {
1732 int dx, dy, incx, incy, dpr, dpru, p, left, top, right, bottom;
1733
1734 if (startx > endx)
1735 {
1736 dx = startx - endx;
1737 incx = -1;
1738 left = endx;
1739 right = startx;
1740 }
1741 else
1742 {
1743 dx = endx - startx;
1744 incx = 1;
1745 left = startx;
1746 right = endx;
1747 }
1748 if (starty > endy)
1749 {
1750 dy = starty - endy;
1751 incy = -1;
1752 top = endy;
1753 bottom = starty;
1754 }
1755 else
1756 {
1757 dy = endy - starty;
1758 incy = 1;
1759 top = starty;
1760 bottom = endy;
1761 }
1762 if (dx >= dy)
1763 {
1764 dpr = dy << 1;
1765 dpru = dpr - (dx << 1);
1766 p = dpr - dx;
1767 for (; dx >= 0; dx--)
1768 {
1769 set_pixel(startx, starty, pen->colour, opcode);
1770 if (p > 0)
1771 {
1772 startx += incx;
1773 starty += incy;
1774 p += dpru;
1775 }
1776 else
1777 {
1778 startx += incx;
1779 p += dpr;
1780 }
1781 }
1782 }
1783 else
1784 {
1785 dpr = dx << 1;
1786 dpru = dpr - (dy << 1);
1787 p = dpr - dy;
1788 for (; dy >= 0; dy--)
1789 {
1790 set_pixel(startx, starty, pen->colour, opcode);
1791 if (p > 0)
1792 {
1793 startx += incx;
1794 starty += incy;
1795 p += dpru;
1796 }
1797 else
1798 {
1799 starty += incy;
1800 p += dpr;
1801 }
1802 }
1803 }
1804 redraw(left, top, (right - left) + 1, (bottom - top) + 1);
1805 }
1806
1807 /******************************************************************************/
1808 void draw_glyph (int x, int y, HGLYPH glyph, int fgcolour)
1809 {
1810 struct bitmap *the_glyph;
1811 int i, j;
1812
1813 the_glyph = (struct bitmap*)glyph;
1814 if (the_glyph == NULL)
1815 return;
1816 for (i = 0; i < the_glyph->h; i++)
1817 for (j = 0; j < the_glyph->w; j++)
1818 if (is_pixel_on(the_glyph->data, j, i, the_glyph->w, 8))
1819 set_pixel(x + j, y + i, fgcolour);
1820 }
1821
1822 #define DO_GLYPH(ttext,idx) \
1823 {\
1824 glyph = cache_get_font (font, ttext[idx]);\
1825 if (!(flags & TEXT2_IMPLICIT_X))\
1826 {\
1827 xyoffset = ttext[++idx];\
1828 if ((xyoffset & 0x80))\
1829 {\
1830 if (flags & TEXT2_VERTICAL) \
1831 y += ttext[idx+1] | (ttext[idx+2] << 8);\
1832 else\
1833 x += ttext[idx+1] | (ttext[idx+2] << 8);\
1834 idx += 2;\
1835 }\
1836 else\
1837 {\
1838 if (flags & TEXT2_VERTICAL) \
1839 y += xyoffset;\
1840 else\
1841 x += xyoffset;\
1842 }\
1843 }\
1844 if (glyph != NULL)\
1845 {\
1846 draw_glyph (x + glyph->offset, y + glyph->baseline, glyph->pixmap, fgcolour);\
1847 if (flags & TEXT2_IMPLICIT_X)\
1848 x += glyph->width;\
1849 }\
1850 }
1851
1852 /******************************************************************************/
1853 void ui_draw_text(uint8 font, uint8 flags, int mixmode,
1854 int x, int y, int clipx, int clipy,
1855 int clipcx, int clipcy, int boxx,
1856 int boxy, int boxcx, int boxcy, int bgcolour,
1857 int fgcolour, uint8 * text, uint8 length)
1858 {
1859 FONTGLYPH * glyph;
1860 int i, j, xyoffset;
1861 DATABLOB * entry;
1862
1863 if (boxx + boxcx > g_width)
1864 boxcx = g_width - boxx;
1865 if (boxy + boxcy > g_height)
1866 boxcy = g_height - boxy;
1867
1868 if (boxcx > 1)
1869 fill_rect(boxx, boxy, boxcx, boxcy, bgcolour);
1870 else if (mixmode == MIX_OPAQUE)
1871 fill_rect(clipx, clipy, clipcx, clipcy, bgcolour);
1872
1873 /* Paint text, character by character */
1874 for (i = 0; i < length;)
1875 {
1876 switch (text[i])
1877 {
1878 case 0xff:
1879 if (i + 2 < length)
1880 cache_put_text(text[i + 1], text, text[i + 2]);
1881 else
1882 {
1883 error("this shouldn't be happening\n");
1884 exit(1);
1885 }
1886 /* this will move pointer from start to first character after FF command */
1887 length -= i + 3;
1888 text = &(text[i + 3]);
1889 i = 0;
1890 break;
1891
1892 case 0xfe:
1893 entry = cache_get_text(text[i + 1]);
1894 if (entry != NULL)
1895 {
1896 if ((((uint8 *) (entry->data))[1] == 0) && (!(flags & TEXT2_IMPLICIT_X)))
1897 {
1898 if (flags & TEXT2_VERTICAL)
1899 y += text[i + 2];
1900 else
1901 x += text[i + 2];
1902 }
1903 for (j = 0; j < entry->size; j++)
1904 DO_GLYPH(((uint8 *) (entry->data)), j);
1905 }
1906 if (i + 2 < length)
1907 i += 3;
1908 else
1909 i += 2;
1910 length -= i;
1911 /* this will move pointer from start to first character after FE command */
1912 text = &(text[i]);
1913 i = 0;
1914 break;
1915
1916 default:
1917 DO_GLYPH(text, i);
1918 i++;
1919 break;
1920 }
1921 }
1922 if (boxcx > 1)
1923 redraw(boxx, boxy, boxcx, boxcy);
1924 else
1925 redraw(clipx, clipy, clipcx, clipcy);
1926 }
1927
1928 /******************************************************************************/
1929 void ui_desktop_save(uint32 offset, int x, int y, int cx, int cy)
1930 {
1931 uint8 * data;
1932 int i, j, Bpp, pixel;
1933
1934 Bpp = 4;
1935 switch (g_server_bpp)
1936 {
1937 case 8: Bpp = 1; break;
1938 case 15: Bpp = 2; break;
1939 case 16: Bpp = 2; break;
1940 }
1941 data = (uint8*)xmalloc(cx * cy * Bpp);
1942 if (g_server_bpp == 8)
1943 {
1944 for (i = 0; i < cy; i++)
1945 for (j = 0; j < cx; j++)
1946 {
1947 pixel = get_pixel(x + j, y + i);
1948 SETPIXEL8(data, j, i, cx, pixel);
1949 }
1950 }
1951 else if (g_server_bpp == 16)
1952 {
1953 for (i = 0; i < cy; i++)
1954 for (j = 0; j < cx; j++)
1955 {
1956 pixel = get_pixel(x + j, y + i);
1957 SETPIXEL16(data, j, i, cx, pixel);
1958 }
1959 }
1960 else if (g_server_bpp == 24)
1961 {
1962 for (i = 0; i < cy; i++)
1963 for (j = 0; j < cx; j++)
1964 *(((uint32*)data) + (i * cx + j)) = get_pixel(x + j, y + i);
1965 }
1966 offset *= Bpp;
1967 cache_put_desktop(offset, cx, cy, cx * Bpp, Bpp, data);
1968 xfree(data);
1969 }
1970
1971 /******************************************************************************/
1972 void ui_desktop_restore(uint32 offset, int x, int y, int cx, int cy)
1973 {
1974 uint8 * data;
1975 int i, j;
1976 int Bpp;
1977
1978 Bpp = 4;
1979 switch (g_server_bpp)
1980 {
1981 case 8: Bpp = 1; break;
1982 case 15: Bpp = 2; break;
1983 case 16: Bpp = 2; break;
1984 }
1985 offset *= Bpp;
1986 data = cache_get_desktop(offset, cx, cy, Bpp);
1987 if (g_server_bpp == 8)
1988 {
1989 for (i = 0; i < cy; i++)
1990 for (j = 0; j < cx; j++)
1991 set_pixel(x + j, y + i, data[i * cx + j]);
1992 }
1993 else if (g_server_bpp == 16)
1994 {
1995 for (i = 0; i < cy; i++)
1996 for (j = 0; j < cx; j++)
1997 set_pixel(x + j, y + i, *(((uint16*)data) + (i * cx + j)));
1998 }
1999 else if (g_server_bpp == 24)
2000 {
2001 for (i = 0; i < cy; i++)
2002 for (j = 0; j < cx; j++)
2003 set_pixel(x + j, y + i, *(((uint32*)data) + (i * cx + j)));
2004 }
2005 redraw(x, y, cx, cy);
2006 }
2007
2008 /*****************************************************************************/
2009 void* xrealloc(void * in_val, int size)
2010 {
2011 if (size < 1)
2012 size = 1;
2013 return realloc(in_val, size);
2014 }
2015
2016 /*****************************************************************************/
2017 void* xmalloc(int size)
2018 {
2019 return malloc(size);
2020 }
2021
2022 /*****************************************************************************/
2023 void xfree(void * in_val)
2024 {
2025 if (in_val != NULL)
2026 free(in_val);
2027 }
2028
2029 /*****************************************************************************/
2030 void warning(char * format, ...)
2031 {
2032 va_list ap;
2033
2034 fprintf(stderr, "WARNING: ");
2035 va_start(ap, format);
2036 vfprintf(stderr, format, ap);
2037 va_end(ap);
2038 }
2039
2040 /*****************************************************************************/
2041 void unimpl(char * format, ...)
2042 {
2043 va_list ap;
2044
2045 fprintf(stderr, "NOT IMPLEMENTED: ");
2046 va_start(ap, format);
2047 vfprintf(stderr, format, ap);
2048 va_end(ap);
2049 }
2050
2051 /*****************************************************************************/
2052 void error(char * format, ...)
2053 {
2054 va_list ap;
2055
2056 fprintf(stderr, "ERROR: ");
2057 va_start(ap, format);
2058 vfprintf(stderr, format, ap);
2059 va_end(ap);
2060 }
2061
2062 /*****************************************************************************/
2063 BOOL rd_pstcache_mkdir(void)
2064 {
2065 return 0;
2066 }
2067
2068 /*****************************************************************************/
2069 int rd_open_file(char * filename)
2070 {
2071 return 0;
2072 }
2073
2074 /*****************************************************************************/
2075 void rd_close_file(int fd)
2076 {
2077 return;
2078 }
2079
2080 /*****************************************************************************/
2081 int rd_read_file(int fd, void * ptr, int len)
2082 {
2083 return 0;
2084 }
2085
2086 /*****************************************************************************/
2087 int rd_write_file(int fd, void * ptr, int len)
2088 {
2089 return 0;
2090 }
2091
2092 /*****************************************************************************/
2093 int rd_lseek_file(int fd, int offset)
2094 {
2095 return 0;
2096 }
2097
2098 /*****************************************************************************/
2099 BOOL rd_lock_file(int fd, int start, int len)
2100 {
2101 return False;
2102 }
2103
2104 /*****************************************************************************/
2105 int load_licence(uint8 ** data)
2106 {
2107 return 0;
2108 }
2109
2110 /*****************************************************************************/
2111 void save_licence(uint8 * data, int length)
2112 {
2113 }
2114
2115 /*****************************************************************************/
2116 void generate_random(uint8 * random)
2117 {
2118 QFile File("/dev/random");
2119 File.open(IO_ReadOnly);
2120 if (File.readBlock((char*)random, 32) == 32)
2121 return;
2122 warning("no /dev/random\n");
2123 memcpy(random, "12345678901234567890123456789012", 32);
2124 }
2125
2126 /*****************************************************************************/
2127 /* produce a hex dump */
2128 void hexdump(uint8 * p, uint32 len)
2129 {
2130 uint8 * line = p;
2131 int i, thisline;
2132 uint32 offset = 0;
2133
2134 while (offset < len)
2135 {
2136 printf("%04x ", offset);
2137 thisline = len - offset;
2138 if (thisline > 16)
2139 thisline = 16;
2140
2141 for (i = 0; i < thisline; i++)
2142 printf("%02x ", line[i]);
2143
2144 for (; i < 16; i++)
2145 printf(" ");
2146
2147 for (i = 0; i < thisline; i++)
2148 printf("%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.');
2149
2150 printf("\n");
2151 offset += thisline;
2152 line += thisline;
2153 }
2154 }
2155
2156 /*****************************************************************************/
2157 void get_username_and_hostname(void)
2158 {
2159 char fullhostname[64];
2160 char * p;
2161 struct passwd * pw;
2162
2163 STRNCPY(g_username, "unknown", sizeof(g_username));
2164 STRNCPY(g_hostname, "unknown", sizeof(g_hostname));
2165 pw = getpwuid(getuid());
2166 if (pw != NULL && pw->pw_name != NULL)
2167 {
2168 STRNCPY(g_username, pw->pw_name, sizeof(g_username));
2169 }
2170 if (gethostname(fullhostname, sizeof(fullhostname)) != -1)
2171 {
2172 p = strchr(fullhostname, '.');
2173 if (p != NULL)
2174 *p = 0;
2175 STRNCPY(g_hostname, fullhostname, sizeof(g_hostname));
2176 }
2177 }
2178
2179 /*****************************************************************************/
2180 void out_params(void)
2181 {
2182 fprintf(stderr, "qterdesktop: A Remote Desktop Protocol client.\n");
2183 fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2004 Matt Chapman.\n");
2184 fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n");
2185 fprintf(stderr, "Usage: qterdesktop [options] server\n");
2186 fprintf(stderr, " -g: desktop geometry (WxH)\n");
2187 fprintf(stderr, " -4: use RDP version 4\n");
2188 fprintf(stderr, " -5: use RDP version 5 (default)\n");
2189 fprintf(stderr, " -t: tcp port)\n");
2190 fprintf(stderr, " -a: connection colour depth\n");
2191
2192 fprintf(stderr, " -u: user name\n");
2193 fprintf(stderr, " -d: domain\n");
2194 fprintf(stderr, " -s: shell\n");
2195 fprintf(stderr, " -c: working directory\n");
2196 fprintf(stderr, " -p: password (- to prompt)\n");
2197 fprintf(stderr, " -n: client hostname\n");
2198 fprintf(stderr, " -f: full screen\n");
2199
2200 fprintf(stderr, "\n");
2201 }
2202
2203 /*****************************************************************************/
2204 int parse_parameters(int in_argc, char ** in_argv)
2205 {
2206 int i;
2207 char * p;
2208
2209 for (i = 1; i < in_argc; i++)
2210 {
2211 strcpy(g_server, in_argv[i]);
2212 if (strcmp(in_argv[i], "-h") == 0)
2213 {
2214 out_params();
2215 return 0;
2216 }
2217 else if (strcmp(in_argv[i], "-g") == 0)
2218 {
2219 g_width = strtol(in_argv[i + 1], &p, 10);
2220 if (*p == 'x')
2221 g_height = strtol(p + 1, &p, 10);
2222 if (*p == '-')
2223 g_client_width = strtol(p + 1, &p, 10);
2224 else
2225 {
2226 g_client_width = g_width;
2227 g_client_height = g_height;
2228 }
2229 if (*p == 'x')
2230 g_client_height = strtol(p + 1, NULL, 10);
2231 g_width = (g_width + 3) & ~3;
2232 g_height = (g_height + 3) & ~3;
2233 g_client_width = (g_client_width + 3) & ~3;
2234 g_client_height = (g_client_height + 3) & ~3;
2235 //printf("%d %d %d %d\n", g_width, g_height, g_client_width, g_client_height);
2236 }
2237 else if (strcmp(in_argv[i], "-4") == 0)
2238 g_use_rdp5 = 0;
2239 else if (strcmp(in_argv[i], "-5") == 0)
2240 g_use_rdp5 = 1;
2241 else if (strcmp(in_argv[i], "-a") == 0)
2242 {
2243 g_server_bpp = strtol(in_argv[i + 1], &p, 10);
2244 if (g_server_bpp != 8 &&
2245 g_server_bpp != 16 && g_server_bpp != 24)
2246 {
2247 error("invalid bpp\n");
2248 return 0;
2249 }
2250 }
2251 else if (strcmp(in_argv[i], "-t") == 0)
2252 g_tcp_port_rdp = strtol(in_argv[i + 1], &p, 10);
2253
2254 else if (strcmp(in_argv[i], "-u") == 0)
2255 {
2256 STRNCPY(g_username, in_argv[i + 1], sizeof(g_username));
2257 }
2258 else if (strcmp(in_argv[i], "-d") == 0)
2259 {
2260 STRNCPY(g_domain, in_argv[i + 1], sizeof(g_domain));
2261 }
2262 else if (strcmp(in_argv[i], "-s") == 0)
2263 {
2264 STRNCPY(g_shell, in_argv[i + 1], sizeof(g_shell));
2265 }
2266 else if (strcmp(in_argv[i], "-c") == 0)
2267 {
2268 STRNCPY(g_directory, in_argv[i + 1], sizeof(g_directory));
2269 }
2270 else if (strcmp(in_argv[i], "-p") == 0)
2271 {
2272 STRNCPY(g_password, in_argv[i + 1], sizeof(g_password));
2273 g_flags |= RDP_LOGON_AUTO;
2274 }
2275 else if (strcmp(in_argv[i], "-n") == 0)
2276 {
2277 STRNCPY(g_hostname, in_argv[i + 1], sizeof(g_hostname));
2278 }
2279 else if (strcmp(in_argv[i], "-f") == 0)
2280 {
2281 g_fullscreen = 1;
2282 }
2283 }
2284 return 1;
2285 }
2286
2287 /******************************************************************************/
2288 int param_connect(void)
2289 {
2290 QWidget * Desktop;
2291 int dw, dh;
2292
2293 #ifdef WITH_RDPSND
2294 rdpsnd_init();
2295 #endif
2296 if (rdp_connect(g_server, g_flags, g_domain, g_password, g_shell,
2297 g_directory))
2298 {
2299 g_BS = (uint8*)xmalloc(g_width * g_height * 4);
2300 memset(g_BS, 0, g_width * g_height * 4);
2301 g_clipx = 0;
2302 g_clipy = 0;
2303 g_clipcx = g_width;
2304 g_clipcy = g_height;
2305 g_CM = (QColorMap*)xmalloc(sizeof(struct QColorMap));
2306 memset(g_CM, 0, sizeof(struct QColorMap));
2307 g_CM->NumColors = 256;
2308 g_MW = new QMyMainWindow();
2309 g_MW->resize(g_client_width, g_client_height);
2310 g_MW->show();
2311 g_SV->addChild(g_MW);
2312 g_MW->setMouseTracking(true);
2313 g_SocketNotifier = new QSocketNotifier(g_global_sock,
2314 QSocketNotifier::Read,
2315 g_MW);
2316 g_MW->connect(g_SocketNotifier, SIGNAL(activated(int)), g_MW,
2317 SLOT(dataReceived()));
2318 if (g_fullscreen)
2319 {
2320 Desktop = g_App->desktop();
2321 dw = Desktop->width();
2322 dh = Desktop->height();
2323 if (dw == g_client_width && dh == g_client_height)
2324 g_MW->resize(g_client_width - 4, g_client_height - 4);
2325 g_SV->showFullScreen();
2326 }
2327 g_MW->setCursor((int)10); /* Qt::BlankCursor */
2328 g_App->exec();
2329 }
2330 return 0;
2331 }
2332
2333 /******************************************************************************/
2334 int main(int argc, char ** argv)
2335 {
2336 #ifdef SHARP
2337 g_App = new QPEApplication(argc, argv);
2338 #else
2339 //g_App = new QApplication(argc, argv, QApplication::GuiServer);
2340 g_App = new QApplication(argc, argv);
2341 #endif
2342 g_SV = new QMyScrollView();
2343 g_App->setMainWidget(g_SV);
2344 g_SV->showMaximized();
2345 if (argc > 1)
2346 {
2347 get_username_and_hostname();
2348 if (parse_parameters(argc, argv))
2349 param_connect();
2350 }
2351 else
2352 {
2353 g_SV->timer_id = g_SV->startTimer(1000); /* one sec delay, then dialog */
2354 g_MW->setCursor((int)10); /* Qt::BlankCursor */
2355 g_App->exec();
2356 }
2357 delete g_SV;
2358 delete g_App;
2359 xfree(g_CM);
2360 xfree(g_BS);
2361 return 0;
2362 }

  ViewVC Help
Powered by ViewVC 1.1.26