/[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 776 - (show annotations)
Sat Oct 2 01:30:33 2004 UTC (19 years, 7 months ago) by jsorg71
File size: 47762 byte(s)
change HANDLE to NTHANDLE to avoid conflics

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

  ViewVC Help
Powered by ViewVC 1.1.26