00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "rdesktop.h"
00023 #include <qpe/qpeapplication.h>
00024 #include <qmainwindow.h>
00025 #include <qwidget.h>
00026 #include <qpainter.h>
00027 #include <qimage.h>
00028 #include <qsocketnotifier.h>
00029 #include <qscrollview.h>
00030 #include <qmessagebox.h>
00031 #include <qpushbutton.h>
00032 #include <qlineedit.h>
00033 #include <qcombobox.h>
00034 #include <qlabel.h>
00035 #include <qfile.h>
00036 #include <qcheckbox.h>
00037 #include <qpopupmenu.h>
00038 #include "qtwin.h"
00039 #include <stdlib.h>
00040
00041 uint32 flags;
00042 char server[64] = "";
00043 char domain[16] = "";
00044 char password[16] = "";
00045 char shell[128] = "";
00046 char directory[32] = "";
00047
00048 extern int g_width;
00049 extern int g_height;
00050 extern int server_bpp;
00051 extern BOOL fullscreen;
00052 extern char username[];
00053 int global_sock;
00054
00055 QSocketNotifier* SocketNotifier;
00056 QPEApplication* App;
00057 QMyMainWindow* MW;
00058 QMyScrollView* SV;
00059 struct QColorMap
00060 {
00061 uint32 RGBColors[256];
00062 int NumColors;
00063 };
00064 QColorMap* CM;
00065 uint8* BS;
00066 int clipx;
00067 int clipy;
00068 int clipcx;
00069 int clipcy;
00070
00071 struct bitmap
00072 {
00073 int w;
00074 int h;
00075 uint8* data;
00076 };
00077
00078 BOOL owncolmap = False;
00079
00080
00081 void CleanString(QString* Item)
00082 {
00083 int i;
00084
00085 i = Item->length() - 1;
00086 while (i >= 0)
00087 {
00088 if (Item->at(i) == 10 || Item->at(i) == 13)
00089 Item->remove(i, 1);
00090 i--;
00091 }
00092 }
00093
00094
00095 QMyDialog::QMyDialog(QWidget* parent) : QDialog(parent, "Settings", true)
00096 {
00097 setCaption( tr( "Configuration" ) );
00098 int i, j;
00099 char* home;
00100 char Text[256];
00101 QString Line;
00102 QString ItemName;
00103 QString ItemValue;
00104
00105
00106 resize(230, 270);
00107
00108 ListBox = new QListBox(this);
00109 ListBox->move(10, 10);
00110 ListBox->resize(200, 100);
00111 connect(ListBox, SIGNAL(selectionChanged()), this, SLOT(ListBoxChanged()));
00112 connect(ListBox, SIGNAL(selected(int)), this, SLOT(ListBoxSelected(int)));
00113
00114 Label1 = new QLabel(this);
00115 Label1->setText( tr("Server Desc") );
00116 Label1->move(10, 120);
00117 Label1->resize(100, 20);
00118 ServerNameEdit = new QLineEdit(this);
00119 ServerNameEdit->move(75, 120);
00120 ServerNameEdit->resize(100, 20);
00121
00122 Label2 = new QLabel(this);
00123 Label2->setText( tr("User Name") );
00124 Label2->move(10, 150);
00125 Label2->resize(100, 20);
00126 UserNameEdit = new QLineEdit(this);
00127 UserNameEdit->move(75, 150);
00128 UserNameEdit->resize(100, 20);
00129
00130 Label3 = new QLabel(this);
00131 Label3->setText( tr("Server Address") );
00132 Label3->move(10, 180);
00133 Label3->resize(100, 20);
00134 IPEdit = new QLineEdit(this);
00135 IPEdit->move(75, 180);
00136 IPEdit->resize(100, 20);
00137
00138 WidthHeightBox = new QComboBox(this);
00139 WidthHeightBox->move(10, 210);
00140 WidthHeightBox->resize(100, 20);
00141 WidthHeightBox->insertItem("240x320");
00142 WidthHeightBox->insertItem("640x480");
00143 WidthHeightBox->insertItem("800x600");
00144 connect(WidthHeightBox, SIGNAL(activated(int)), this, SLOT(ComboChanged(int)));
00145 WidthHeightBox->setCurrentItem(1);
00146 WidthEdit = new QLineEdit(this);
00147 WidthEdit->move(110, 210);
00148 WidthEdit->resize(30, 20);
00149 WidthEdit->setText("800");
00150 HeightEdit = new QLineEdit(this);
00151 HeightEdit->move(140, 210);
00152 HeightEdit->resize(30, 20);
00153 HeightEdit->setText("600");
00154
00155 AddButton = new QPushButton(this);
00156 AddButton->move(180, 120);
00157 AddButton->resize(50, 20);
00158 AddButton->setText(tr("Add", "Add Connection"));
00159 connect(AddButton, SIGNAL(clicked()), this, SLOT(AddClicked()));
00160
00161 EditButton = new QPushButton(this);
00162 EditButton->move(180, 140);
00163 EditButton->resize(50, 20);
00164 EditButton->setText(tr("Edit"));
00165 connect(EditButton, SIGNAL(clicked()), this, SLOT(EditClicked()));
00166
00167 SaveButton = new QPushButton(this);
00168 SaveButton->move(180, 160);
00169 SaveButton->resize(50, 20);
00170 SaveButton->setText(tr("Save"));
00171 connect(SaveButton, SIGNAL(clicked()), this, SLOT(SaveClicked()));
00172
00173 RemoveButton = new QPushButton(this);
00174 RemoveButton->move(180, 180);
00175 RemoveButton->resize(50, 20);
00176 RemoveButton->setText(tr("Remove"));
00177 connect(RemoveButton, SIGNAL(clicked()), this, SLOT(RemoveClicked()));
00178
00179 FullScreenCheckBox = new QCheckBox(this, "Full Screen");
00180 FullScreenCheckBox->setText(tr("Full Screen"));
00181 FullScreenCheckBox->move(10, 230);
00182
00183
00184 for (i = 0; i < 10; i++)
00185 {
00186 ConnectionList[i] = new QMyConnectionItem;
00187 ConnectionList[i]->ServerName = "";
00188 ConnectionList[i]->UserName = "";
00189 ConnectionList[i]->ServerIP = "";
00190 ConnectionList[i]->Width = 0;
00191 ConnectionList[i]->Height = 0;
00192 ConnectionList[i]->FullScreen = 0;
00193 }
00194 home = getenv("HOME");
00195 if (home != NULL)
00196 {
00197 sprintf(Text, "%s/rdesktop.ini", home);
00198 QFile* File = new QFile(Text);
00199 if (File->open(IO_ReadOnly))
00200 {
00201 i = -1;
00202 while (!File->atEnd())
00203 {
00204 File->readLine(Line, 255);
00205 j = Line.find("=");
00206 if (j > 0)
00207 {
00208 ItemName = Line.mid(0, j);
00209 CleanString(&ItemName);
00210 ItemValue = Line.mid(j + 1);
00211 CleanString(&ItemValue);
00212 if (ItemName == "Server")
00213 {
00214 i++;
00215 ConnectionList[i]->ServerName = ItemValue;
00216 ListBox->insertItem(ItemValue);
00217 }
00218 else if (ItemName == "UserName")
00219 ConnectionList[i]->UserName = ItemValue;
00220 else if (ItemName == "Width")
00221 ConnectionList[i]->Width = ItemValue.toInt();
00222 else if (ItemName == "Height")
00223 ConnectionList[i]->Height = ItemValue.toInt();
00224 else if (ItemName == "IP")
00225 ConnectionList[i]->ServerIP = ItemValue;
00226 else if (ItemName == "FullScreen")
00227 ConnectionList[i]->FullScreen = (ItemValue != "0");
00228 }
00229 }
00230 }
00231 delete File;
00232 }
00233 }
00234
00235
00236 QMyDialog::~QMyDialog()
00237 {
00238 QMyConnectionItem* Item;
00239 int i;
00240
00241 for (i = 0; i < 10; i++)
00242 {
00243 Item = ConnectionList[i];
00244 delete Item;
00245 }
00246 }
00247
00248
00249 void QMyDialog::ComboChanged(int index)
00250 {
00251 if (index == 0)
00252 {
00253 WidthEdit->setText("240");
00254 HeightEdit->setText("320");
00255 }
00256 if (index == 1)
00257 {
00258 WidthEdit->setText("640");
00259 HeightEdit->setText("480");
00260 }
00261 else if (index == 2)
00262 {
00263 WidthEdit->setText("800");
00264 HeightEdit->setText("600");
00265 }
00266 }
00267
00268
00269 void QMyDialog::accept()
00270 {
00271 ServerName = ServerNameEdit->text();
00272 UserName = UserNameEdit->text();
00273 Width = WidthEdit->text().toInt();
00274 Height = HeightEdit->text().toInt();
00275 ServerIP = IPEdit->text();
00276 FullScreen = FullScreenCheckBox->isChecked();
00277
00278 QDialog::accept();
00279 }
00280
00281
00282
00283 void QMyDialog::AddClicked()
00284 {
00285 int i;
00286 QMyConnectionItem* Item;
00287
00288 i = ListBox->count();
00289 if (i < 10)
00290 {
00291 ListBox->insertItem(ServerNameEdit->text());
00292 Item = ConnectionList[i];
00293 Item->ServerName = ServerNameEdit->text();
00294 Item->UserName = UserNameEdit->text();
00295 Item->Width = WidthEdit->text().toInt();
00296 Item->Height = HeightEdit->text().toInt();
00297 Item->ServerIP = IPEdit->text();
00298 Item->FullScreen = FullScreenCheckBox->isChecked();
00299 }
00300 }
00301
00302
00303 void QMyDialog::EditClicked()
00304 {
00305 int i;
00306 QMyConnectionItem* Item;
00307
00308 i = ListBox->currentItem();
00309 if (i >= 0)
00310 {
00311 Item = ConnectionList[i];
00312 Item->ServerName = ServerNameEdit->text();
00313 Item->UserName = UserNameEdit->text();
00314 Item->Width = WidthEdit->text().toInt();
00315 Item->Height = HeightEdit->text().toInt();
00316 Item->ServerIP = IPEdit->text();
00317 Item->FullScreen = FullScreenCheckBox->isChecked();
00318 ListBox->changeItem(ServerNameEdit->text(), i);
00319 }
00320 }
00321
00322
00323 void WriteString(QFile* File, QString* Line)
00324 {
00325 File->writeBlock((const char*)(*Line), Line->length());
00326 }
00327
00328
00329 void QMyDialog::SaveClicked()
00330 {
00331 int i, j;
00332 QMyConnectionItem* Item;
00333 QString Line;
00334 char* home;
00335 char Text[256];
00336 QFile* File;
00337
00338 home = getenv("HOME");
00339 if (home != NULL)
00340 {
00341 sprintf(Text, "%s/rdesktop.ini", home);
00342 File = new QFile(Text);
00343 if (File->open(IO_Truncate | IO_ReadWrite))
00344 {
00345 i = ListBox->count();
00346 for (j = 0; j < i; j++)
00347 {
00348 Item = ConnectionList[j];
00349 Line = "Server=";
00350 Line += Item->ServerName;
00351 Line += (char)10;
00352 WriteString(File, &Line);
00353 Line = "UserName=";
00354 Line += Item->UserName;
00355 Line += (char)10;
00356 WriteString(File, &Line);
00357 Line = "Width=";
00358 sprintf(Text, "%d", Item->Width);
00359 Line += Text;
00360 Line += (char)10;
00361 WriteString(File, &Line);
00362 Line = "Height=";
00363 sprintf(Text, "%d", Item->Height);
00364 Line += Text;
00365 Line += (char)10;
00366 WriteString(File, &Line);
00367 Line = "IP=";
00368 Line += Item->ServerIP;
00369 Line += (char)10;
00370 WriteString(File, &Line);
00371 Line = "FullScreen=";
00372 if (Item->FullScreen)
00373 Line += "1";
00374 else
00375 Line += "0";
00376 Line += (char)10;
00377 WriteString(File, &Line);
00378 }
00379 }
00380 File->flush();
00381 File->close();
00382 delete File;
00383 }
00384 }
00385
00386
00387 void QMyDialog::RemoveClicked()
00388 {
00389 int i, j, c;
00390 QMyConnectionItem* Item1;
00391 QMyConnectionItem* Item2;
00392
00393 i = ListBox->currentItem();
00394 if (i >= 0)
00395 {
00396 c = ListBox->count();
00397 for (j = i; j < c - 1; j++)
00398 {
00399 Item1 = ConnectionList[i];
00400 Item2 = ConnectionList[i + 1];
00401 Item1->ServerName = Item2->ServerName;
00402 Item1->UserName = Item2->UserName;
00403 Item1->Width = Item2->Width;
00404 Item1->Height = Item2->Height;
00405 Item1->ServerIP = Item2->ServerIP;
00406 Item1->FullScreen = Item2->FullScreen;
00407 }
00408 ListBox->removeItem(i);
00409 }
00410 }
00411
00412
00413 void QMyDialog::ListBoxChanged()
00414 {
00415 int i;
00416 QMyConnectionItem* Item;
00417 char Text[100];
00418
00419 i = ListBox->currentItem();
00420 if (i >= 0 && i < 10)
00421 {
00422 Item = ConnectionList[i];
00423 ServerNameEdit->setText(Item->ServerName);
00424 UserNameEdit->setText(Item->UserName);
00425 sprintf(Text, "%d", Item->Width);
00426 WidthEdit->setText(Text);
00427 sprintf(Text, "%d", Item->Height);
00428 HeightEdit->setText(Text);
00429 IPEdit->setText(Item->ServerIP);
00430 FullScreenCheckBox->setChecked(Item->FullScreen != 0);
00431 }
00432 }
00433
00434
00435 void QMyDialog::ListBoxSelected(int )
00436 {
00437 }
00438
00439
00440 void GetScanCode(QKeyEvent* e, int* ScanCode, int* code)
00441 {
00442 int key;
00443 int mod;
00444 int ascii;
00445
00446 key = e->key();
00447 mod = e->state();
00448 ascii = e->ascii();
00449
00450 *ScanCode = 0;
00451 *code = mod;
00452
00453 switch (key)
00454 {
00455 case 4096:
00456 case 4097:
00457 case 4099:
00458 case 4100:
00459 case 4101:
00460 case 4103:
00461 ascii = 0;
00462 }
00463
00464 if (ascii == 0)
00465 {
00466 switch (key)
00467 {
00468 case 4096: *ScanCode = 0x01; break;
00469 case 4097: *ScanCode = 0x0f; break;
00470 case 4099: *ScanCode = 0x0e; break;
00471 case 4100: *ScanCode = 0x1c; break;
00472 case 4101: *ScanCode = 0x1c; break;
00473 case 4112: *ScanCode = 0xc7; break;
00474 case 4113: *ScanCode = 0xcf; break;
00475 case 4102: *ScanCode = 0xd2; break;
00476 case 4103: *ScanCode = 0xd3; break;
00477 case 4118: *ScanCode = 0xc9; break;
00478 case 4119: *ScanCode = 0xd1; break;
00479 case 4117: *ScanCode = 0xd0; break;
00480 case 4115: *ScanCode = 0xc8; break;
00481 case 4114: *ScanCode = 0xcb; break;
00482 case 4116: *ScanCode = 0xcd; break;
00483 case 4128: *ScanCode = 0x2a; break;
00484 case 4131: *ScanCode = 0x38; break;
00485 case 4129: *ScanCode = 0x1d; break;
00486 }
00487 if (*ScanCode != 0)
00488 return;
00489 }
00490
00491 switch (ascii)
00492 {
00493
00494 case 'q': *ScanCode = 0x10; break;
00495 case 'Q': *ScanCode = 0x10; *code |= 8; break;
00496 case '1': *ScanCode = 0x02; break;
00497 case 'w': *ScanCode = 0x11; break;
00498 case 'W': *ScanCode = 0x11; *code |= 8; break;
00499 case '2': *ScanCode = 0x03; break;
00500 case 'e': *ScanCode = 0x12; break;
00501 case 'E': *ScanCode = 0x12; *code |= 8; break;
00502 case '3': *ScanCode = 0x04; break;
00503 case 'r': *ScanCode = 0x13; break;
00504 case 'R': *ScanCode = 0x13; *code |= 8; break;
00505 case '4': *ScanCode = 0x05; break;
00506 case 't': *ScanCode = 0x14; break;
00507 case 'T': *ScanCode = 0x14; *code |= 8; break;
00508 case '5': *ScanCode = 0x06; break;
00509 case 'y': *ScanCode = 0x15; break;
00510 case 'Y': *ScanCode = 0x15; *code |= 8; break;
00511 case '6': *ScanCode = 0x07; break;
00512 case 'u': *ScanCode = 0x16; break;
00513 case 'U': *ScanCode = 0x16; *code |= 8; break;
00514 case '7': *ScanCode = 0x08; break;
00515 case 'i': *ScanCode = 0x17; break;
00516 case 'I': *ScanCode = 0x17; *code |= 8; break;
00517 case '8': *ScanCode = 0x09; break;
00518 case 'o': *ScanCode = 0x18; break;
00519 case 'O': *ScanCode = 0x18; *code |= 8; break;
00520 case '9': *ScanCode = 0x0a; break;
00521 case 'p': *ScanCode = 0x19; break;
00522 case 'P': *ScanCode = 0x19; *code |= 8; break;
00523 case '0': *ScanCode = 0x0b; break;
00524
00525 case 'a': *ScanCode = 0x1e; break;
00526 case 'A': *ScanCode = 0x1e; *code |= 8; break;
00527 case '!': *ScanCode = 0x02; *code |= 8; break;
00528 case 's': *ScanCode = 0x1f; break;
00529 case 'S': *ScanCode = 0x1f; *code |= 8; break;
00530 case '@': *ScanCode = 0x03; *code |= 8; break;
00531 case 'd': *ScanCode = 0x20; break;
00532 case 'D': *ScanCode = 0x20; *code |= 8; break;
00533 case '#': *ScanCode = 0x04; *code |= 8; break;
00534 case 'f': *ScanCode = 0x21; break;
00535 case 'F': *ScanCode = 0x21; *code |= 8; break;
00536 case '$': *ScanCode = 0x05; *code |= 8; break;
00537 case 'g': *ScanCode = 0x22; break;
00538 case 'G': *ScanCode = 0x22; *code |= 8; break;
00539 case '%': *ScanCode = 0x06; *code |= 8; break;
00540 case 'h': *ScanCode = 0x23; break;
00541 case 'H': *ScanCode = 0x23; *code |= 8; break;
00542 case '_': *ScanCode = 0x0c; *code |= 8; break;
00543 case 'j': *ScanCode = 0x24; break;
00544 case 'J': *ScanCode = 0x24; *code |= 8; break;
00545 case '&': *ScanCode = 0x08; *code |= 8; break;
00546 case 'k': *ScanCode = 0x25; break;
00547 case 'K': *ScanCode = 0x25; *code |= 8; break;
00548 case '*': *ScanCode = 0x09; *code |= 8; break;
00549 case 'l': *ScanCode = 0x26; break;
00550 case 'L': *ScanCode = 0x26; *code |= 8; break;
00551 case '(': *ScanCode = 0x0a; *code |= 8; break;
00552
00553
00554 case 'z': *ScanCode = 0x2c; break;
00555 case 'Z': *ScanCode = 0x2c; *code |= 8; break;
00556 case 'x': *ScanCode = 0x2d; break;
00557 case 'X': *ScanCode = 0x2d; *code |= 8; break;
00558 case 'c': *ScanCode = 0x2e; break;
00559 case 'C': *ScanCode = 0x2e; *code |= 8; break;
00560 case 'v': *ScanCode = 0x2f; break;
00561 case 'V': *ScanCode = 0x2f; *code |= 8; break;
00562 case 'b': *ScanCode = 0x30; break;
00563 case 'B': *ScanCode = 0x30; *code |= 8; break;
00564 case '-': *ScanCode = 0x0c; break;
00565 case 'n': *ScanCode = 0x31; break;
00566 case 'N': *ScanCode = 0x31; *code |= 8; break;
00567 case '+': *ScanCode = 0x0d; *code |= 8; break;
00568 case 'm': *ScanCode = 0x32; break;
00569 case 'M': *ScanCode = 0x32; *code |= 8; break;
00570 case '=': *ScanCode = 0x0d; break;
00571 case ',': *ScanCode = 0x33; break;
00572 case ';': *ScanCode = 0x27; break;
00573 case ')': *ScanCode = 0x0b; *code |= 8; break;
00574
00575
00576 case '/': *ScanCode = 0x35; break;
00577 case '?': *ScanCode = 0x35; *code |= 8; break;
00578 case ' ': *ScanCode = 0x39; break;
00579 case '\'': *ScanCode = 0x28; break;
00580 case '"': *ScanCode = 0x28; *code |= 8; break;
00581 case '~': *ScanCode = 0x29; *code |= 8; break;
00582 case '.': *ScanCode = 0x34; break;
00583 case ':': *ScanCode = 0x27; *code |= 8; break;
00584 case '<': *ScanCode = 0x33; *code |= 8; break;
00585
00586 case '>': *ScanCode = 0x34; *code |= 8; break;
00587
00588
00589 case '`': *ScanCode = 0x29; break;
00590 case '^': *ScanCode = 0x07; *code |= 8; break;
00591 case '[': *ScanCode = 0x1a; break;
00592 case '{': *ScanCode = 0x1a; *code |= 8; break;
00593 case ']': *ScanCode = 0x1b; break;
00594 case '}': *ScanCode = 0x1b; *code |= 8; break;
00595 case '\\': *ScanCode = 0x2b; break;
00596 case '|': *ScanCode = 0x2b; *code |= 8; break;
00597
00598 case 1: *ScanCode = 0x1e; *code |= 16; break;
00599 case 2: *ScanCode = 0x30; *code |= 16; break;
00600 }
00601
00602 if (*ScanCode == 0 && key < 3000)
00603 printf("unknown key %d mod %d ascii %d\n", key, mod, ascii);
00604
00605 }
00606
00607
00608 QMyScrollView::QMyScrollView() : QScrollView()
00609 {
00610 }
00611
00612
00613 QMyScrollView::~QMyScrollView()
00614 {
00615 }
00616
00617
00618 void QMyScrollView::keyPressEvent(QKeyEvent* e)
00619 {
00620 int ScanCode, code;
00621 GetScanCode(e, &ScanCode, &code);
00622 if (ScanCode != 0)
00623 {
00624 if (code & 8)
00625 rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x2a, 0);
00626 if (code & 16)
00627 rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x1d, 0);
00628 if (code & 32)
00629 rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x38, 0);
00630 rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYPRESS, ScanCode, 0);
00631 e->accept();
00632 }
00633 }
00634
00635
00636 void QMyScrollView::keyReleaseEvent(QKeyEvent* e)
00637 {
00638 int ScanCode, code;
00639 GetScanCode(e, &ScanCode, &code);
00640 if (ScanCode != 0)
00641 {
00642 rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, ScanCode, 0);
00643 if (code & 8)
00644 rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, 0x2a, 0);
00645 if (code & 16)
00646 rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, 0x1d, 0);
00647 if (code & 32)
00648 rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, 0x38, 0);
00649 e->accept();
00650 }
00651 }
00652
00653
00654 void QMyScrollView::showEvent(QShowEvent* e)
00655 {
00656 QScrollView::showEvent(e);
00657 }
00658
00659
00660 void QMyScrollView::show()
00661 {
00662 QScrollView::show();
00663 }
00664
00665
00666 void QMyScrollView::polish()
00667 {
00668 QScrollView::polish();
00669 }
00670
00671
00672 void QMyScrollView::timerEvent(QTimerEvent* e)
00673 {
00674 QScrollView::timerEvent(e);
00675 killTimer(timer_id);
00676 QMyDialog* d;
00677 QWidget* Desktop;
00678 int dw;
00679 int dh;
00680
00681 d = new QMyDialog(this);
00682 if (d->exec() == 1)
00683 {
00684 flags = RDP_LOGON_NORMAL;
00685 g_width = d->Width;
00686 g_height = d->Height;
00687 fullscreen = d->FullScreen;
00688 sprintf(server, "%s", (const char*)d->ServerIP);
00689 sprintf(username, "%s", (const char*)d->UserName);
00690 if (!rdp_connect(server, flags, domain, password, shell, directory))
00691 {
00692 delete d;
00693 SV->close();
00694 return;
00695 }
00696 BS = (uint8*)xmalloc(g_width * g_height);
00697 memset(BS, 0, g_width * g_height);
00698 clipx = 0;
00699 clipy = 0;
00700 clipcx = g_width;
00701 clipcy = g_height;
00702 CM = (QColorMap*)xmalloc(sizeof(struct QColorMap));
00703 memset(CM, 0, sizeof(struct QColorMap));
00704 CM->NumColors = 256;
00705 MW = new QMyMainWindow();
00706 MW->resize(g_width, g_height);
00707 MW->show();
00708 SV->addChild(MW);
00709 MW->setMouseTracking(true);
00710 SocketNotifier = new QSocketNotifier(global_sock, QSocketNotifier::Read, MW);
00711 MW->connect(SocketNotifier, SIGNAL(activated(int)), MW, SLOT(dataReceived()));
00712 if (fullscreen)
00713 {
00714 Desktop = App->desktop();
00715 dw = Desktop->width();
00716 dh = Desktop->height();
00717 if (dw == g_width && dh == g_height)
00718 MW->resize(g_width - 4, g_height - 4);
00719 SV->showFullScreen();
00720 }
00721 delete d;
00722 }
00723 else
00724 {
00725 delete d;
00726 SV->close();
00727 }
00728 }
00729
00730
00731 QMyMainWindow::QMyMainWindow() : QWidget(SV->viewport())
00732 {
00733 PopupMenu = new QPopupMenu(this);
00734 PopupMenu->insertItem("Right click", 1, 0);
00735 PopupMenu->insertItem("Toggle fullscreen", 2, 1);
00736 PopupMenu->insertItem("Reset keyboard", 3, 2);
00737 PopupMenu->insertItem("Double click", 4, 3);
00738 connect(PopupMenu, SIGNAL(activated(int)), this, SLOT(MemuClicked(int)));
00739 }
00740
00741
00742 QMyMainWindow::~QMyMainWindow()
00743 {
00744 delete PopupMenu;
00745 }
00746
00747
00748 void QMyMainWindow::timerEvent(QTimerEvent* e)
00749 {
00750 QWidget::timerEvent(e);
00751 if (e->timerId() == timer_id)
00752 {
00753
00754 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1, mx, my);
00755
00756 if (fullscreen)
00757 {
00758 fullscreen = 0;
00759 SV->showNormal();
00760 SV->showMaximized();
00761 }
00762 else
00763 PopupMenu->popup(mapToGlobal(QPoint(mx, my)));
00764 }
00765 killTimer(timer_id);
00766 }
00767
00768
00769 void QMyMainWindow::MemuClicked(int MenuID)
00770 {
00771 QWidget* Desktop;
00772 int dw;
00773 int dh;
00774
00775 if (MenuID == 1)
00776 {
00777 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON2, mx, my);
00778 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON2, mx, my);
00779 }
00780 else if (MenuID == 2)
00781 {
00782 fullscreen = ~fullscreen;
00783 if (fullscreen)
00784 {
00785 Desktop = App->desktop();
00786 dw = Desktop->width();
00787 dh = Desktop->height();
00788 if (dw == g_width && dh == g_height)
00789 MW->resize(g_width - 4, g_height - 4);
00790 SV->showFullScreen();
00791 }
00792 else
00793 {
00794 SV->showNormal();
00795 SV->showMaximized();
00796 MW->resize(g_width, g_height);
00797 }
00798 }
00799 else if (MenuID == 3)
00800 {
00801 rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, 0x2a, 0);
00802 rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, 0x1d, 0);
00803 rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, 0x38, 0);
00804 }
00805 else if (MenuID == 4)
00806 {
00807 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON1, mx, my);
00808 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1, mx, my);
00809 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON1, mx, my);
00810 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1, mx, my);
00811 }
00812 }
00813
00814
00815 void QMyMainWindow::mouseMoveEvent(QMouseEvent* e)
00816 {
00817 int x;
00818 int y;
00819
00820 x = e->x();
00821 y = e->y();
00822
00823 if (timer_id)
00824 {
00825 x = x - mx;
00826 y = y - my;
00827 if (x < -10 || x > 10 || y < -10 || y > 10)
00828 {
00829 killTimer(timer_id);
00830 timer_id = 0;
00831 }
00832 }
00833 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_MOVE, e->x(), e->y());
00834 }
00835
00836
00837 void QMyMainWindow::mousePressEvent(QMouseEvent* e)
00838 {
00839 timer_id = startTimer(1000);
00840 mx = e->x();
00841 my = e->y();
00842 if (e->button() == LeftButton)
00843 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON1, e->x(), e->y());
00844 else if (e->button() == RightButton)
00845 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON2, e->x(), e->y());
00846 else if (e->button() == MidButton)
00847 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON3, e->x(), e->y());
00848 }
00849
00850
00851 void QMyMainWindow::mouseReleaseEvent(QMouseEvent* e)
00852 {
00853 killTimer(timer_id);
00854 timer_id = 0;
00855 if (e->button() == LeftButton)
00856 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1, e->x(), e->y());
00857 else if (e->button() == RightButton)
00858 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON2, e->x(), e->y());
00859 else if (e->button() == MidButton)
00860 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON3, e->x(), e->y());
00861 }
00862
00863
00864 void QMyMainWindow::wheelEvent(QWheelEvent* e)
00865 {
00866 if (e->delta() > 0)
00867 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON4, e->x(), e->y());
00868 else if (e->delta() < 0)
00869 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON5, e->x(), e->y());
00870 }
00871
00872 #define NOT(x) (255-(x))
00873
00874
00875 uint8 rop(int rop, uint8 src, uint8 dst)
00876 {
00877 switch (rop)
00878 {
00879 case 0x0: return 0;
00880 case 0x1: return NOT (src | dst);
00881 case 0x2: return NOT (src) & dst;
00882 case 0x3: return NOT (src);
00883 case 0x4: return src & NOT (dst);
00884 case 0x5: return NOT (dst);
00885 case 0x6: return src ^ dst;
00886 case 0x7: return NOT (src & dst);
00887 case 0x8: return src & dst;
00888 case 0x9: return NOT (src) ^ dst;
00889 case 0xa: return dst;
00890 case 0xb: return NOT (src) | dst;
00891 case 0xc: return src;
00892 case 0xd: return src | NOT (dst);
00893 case 0xe: return src | dst;
00894 case 0xf: return NOT (0);
00895 }
00896 return dst;
00897 }
00898
00899
00900 uint8 get_pixel(int x, int y)
00901 {
00902 if (x >= 0 && x < g_width && y >= 0 && y < g_height)
00903 return BS[y * g_width + x];
00904 else
00905 return 0;
00906 }
00907
00908
00909 void set_pixel(int x, int y, uint8 pixel, int op = 0xc)
00910 {
00911 if (x >= clipx && x < (clipx + clipcx) && y >= clipy && y < (clipy + clipcy))
00912 if (x >= 0 && x < g_width && y >= 0 && y < g_height)
00913 if (op == 0xc)
00914 BS[y * g_width + x] = pixel;
00915 else
00916 BS[y * g_width + x] = rop(op, pixel, BS[y * g_width + x]);
00917 }
00918
00919
00920
00921 bool WarpCoords(int* x, int* y, int* cx, int* cy, int* srcx, int* srcy)
00922 {
00923 int dx, dy;
00924 QRect InRect(*x, *y, *cx, *cy);
00925 QRect OutRect;
00926 QRect CRect(clipx, clipy, clipcx, clipcy);
00927 OutRect = InRect.intersect(CRect);
00928 if (OutRect.isEmpty())
00929 return false;
00930 dx = OutRect.x() - InRect.x();
00931 dy = OutRect.y() - InRect.y();
00932 *x = OutRect.x();
00933 *y = OutRect.y();
00934 *cx = OutRect.width();
00935 *cy = OutRect.height();
00936 if (srcx != NULL)
00937 *srcx = *srcx + dx;
00938 if (srcy != NULL)
00939 *srcy = *srcy + dy;
00940 return true;
00941 }
00942
00943
00944 void QMyMainWindow::paintEvent(QPaintEvent* pe)
00945 {
00946 QImage* Image;
00947 QPainter* Painter;
00948 QRect Rect;
00949 int i, j, w, h, l, t;
00950 uint8* data;
00951
00952 if (!testWFlags(WRepaintNoErase))
00953 setWFlags(WRepaintNoErase);
00954 if (CM != NULL)
00955 {
00956 Rect = pe->rect();
00957 l = Rect.left();
00958 t = Rect.top();
00959 w = Rect.width();
00960 h = Rect.height();
00961 if (w > 0 && h > 0 && CM->NumColors > 0)
00962 {
00963 data = (uint8*)xmalloc(w * h);
00964 for (i = 0; i < h; i++)
00965 for (j = 0; j < w; j++)
00966 data[i * w + j] = get_pixel(l + j, t + i);
00967 Image = new QImage(data, w, h, 8,(QRgb*)CM->RGBColors, CM->NumColors, QImage::IgnoreEndian);
00968 Painter = new QPainter(this);
00969 Painter->drawImage(l, t, *Image, 0, 0, w, h);
00970 xfree(data);
00971 delete Painter;
00972 delete Image;
00973 }
00974 }
00975 }
00976
00977
00978 void QMyMainWindow::closeEvent(QCloseEvent* e)
00979 {
00980 e->accept();
00981 }
00982
00983
00984 void QMyMainWindow::dataReceived()
00985 {
00986 if (rdp_main_loop())
00987 return;
00988 else
00989 SV->close();
00990 }
00991
00992
00993 void redraw(int x, int y, int cx, int cy)
00994 {
00995 if (WarpCoords(&x, &y, &cx, &cy, NULL, NULL))
00996 {
00997 MW->update(x, y, cx, cy);
00998 }
00999 }
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067 int ui_select(int rdp_socket)
01068 {
01069 global_sock = rdp_socket;
01070 return 1;
01071 }
01072
01073
01074 void ui_move_pointer(int , int )
01075 {
01076 }
01077
01078
01079 HBITMAP ui_create_bitmap(int width, int height, uint8 * data)
01080 {
01081 struct bitmap* the_bitmap;
01082 uint8* bitmap_data;
01083 int i, j;
01084
01085
01086 bitmap_data = (uint8*)xmalloc(width * height);
01087 the_bitmap = (struct bitmap*)xmalloc(sizeof(struct bitmap));
01088 the_bitmap->w = width;
01089 the_bitmap->h = height;
01090 the_bitmap->data = bitmap_data;
01091 for (i = 0; i < height; i++)
01092 for (j = 0; j < width; j++)
01093 bitmap_data[i * width + j] = data[i * width + j];
01094 return the_bitmap;
01095 }
01096
01097
01098 void ui_paint_bitmap(int x, int y, int cx, int cy, int width,
01099 int height, uint8 * data)
01100 {
01101 int i, j;
01102
01103 for (i = 0; i < cy; i++)
01104 for (j = 0; j < cx; j++)
01105 if (i < height)
01106 if (j < width)
01107 set_pixel(x + j, y + i, data[i * width + j]);
01108 redraw(x, y, cx, cy);
01109 }
01110
01111
01112 void ui_destroy_bitmap(HBITMAP bmp)
01113 {
01114 struct bitmap* the_bitmap;
01115
01116 the_bitmap = (struct bitmap*)bmp;
01117 if (the_bitmap != NULL)
01118 {
01119 if (the_bitmap->data != NULL)
01120 xfree(the_bitmap->data);
01121 xfree(the_bitmap);
01122 }
01123 }
01124
01125
01126 bool is_pixel_on(uint8* data, int x, int y, int width, int bpp)
01127 {
01128 int start, shift;
01129
01130 if (bpp == 1)
01131 {
01132 width = (width + 7) / 8;
01133 start = (y * width) + x / 8;
01134 shift = x % 8;
01135 return (data[start] & (0x80 >> shift)) != 0;
01136 }
01137 else if (bpp == 8)
01138 return data[y * width + x] != 0;
01139 else
01140 return false;
01141 }
01142
01143
01144 void set_pixel_on(uint8* data, int x, int y, int width, int bpp, uint8 pixel)
01145 {
01146 if (bpp == 8)
01147 data[y * width + x] = pixel;
01148 }
01149
01150
01151 HGLYPH ui_create_glyph(int width, int height, uint8 * data)
01152 {
01153 int i, j;
01154 uint8* glyph_data;
01155 struct bitmap* the_glyph;
01156
01157 glyph_data = (uint8*)xmalloc(width * height);
01158 the_glyph = (struct bitmap*)xmalloc(sizeof(struct bitmap));
01159 the_glyph->w = width;
01160 the_glyph->h = height;
01161 the_glyph->data = glyph_data;
01162 memset(glyph_data, 0, width * height);
01163 for (i = 0; i < height; i++)
01164 for (j = 0; j < width; j++)
01165 if (is_pixel_on(data, j, i, width, 1))
01166 set_pixel_on(glyph_data, j, i, width, 8, 255);
01167 return the_glyph;
01168 }
01169
01170
01171 void ui_destroy_glyph(HGLYPH glyph)
01172 {
01173 struct bitmap* the_glyph;
01174
01175 the_glyph = (struct bitmap*)glyph;
01176 if (the_glyph != NULL)
01177 {
01178 if (the_glyph->data != NULL)
01179 xfree(the_glyph->data);
01180 xfree(the_glyph);
01181 }
01182 }
01183
01184
01185 HCURSOR ui_create_cursor(unsigned int , unsigned int ,
01186 int , int , uint8 * ,
01187 uint8 * )
01188 {
01189 return (void*)1;
01190 }
01191
01192
01193 void ui_set_cursor(HCURSOR )
01194 {
01195 }
01196
01197
01198 void ui_destroy_cursor(HCURSOR )
01199 {
01200 }
01201
01202
01203 HCOLOURMAP ui_create_colourmap(COLOURMAP * colours)
01204 {
01205 int i;
01206 int x;
01207 uint8 r, g, b;
01208 i = 0;
01209 while (i < colours->ncolours && i < 256)
01210 {
01211 r = colours->colours[i].red;
01212 g = colours->colours[i].green;
01213 b = colours->colours[i].blue;
01214 x = (r << 16) | (g << 8) | b;
01215 CM->RGBColors[i] = x;
01216 i++;
01217 }
01218 CM->NumColors = colours->ncolours;
01219 return CM;
01220 }
01221
01222
01223 void ui_destroy_colourmap(HCOLOURMAP )
01224 {
01225 }
01226
01227
01228 void ui_set_colourmap(HCOLOURMAP )
01229 {
01230 }
01231
01232
01233 void ui_begin_update(void)
01234 {
01235 }
01236
01237
01238 void ui_end_update(void)
01239 {
01240 }
01241
01242
01243 void ui_set_clip(int x, int y, int cx, int cy)
01244 {
01245 clipx = x;
01246 clipy = y;
01247 clipcx = cx;
01248 clipcy = cy;
01249 }
01250
01251
01252 void ui_reset_clip(void)
01253 {
01254 clipx = 0;
01255 clipy = 0;
01256 clipcx = g_width;
01257 clipcy = g_height;
01258 }
01259
01260
01261 void ui_bell(void)
01262 {
01263 App->beep();
01264 }
01265
01266
01267 void ui_destblt(uint8 opcode, int x, int y, int cx, int cy)
01268 {
01269 int i, j;
01270
01271 for (i = 0; i < cy; i++)
01272 for (j = 0; j < cx; j++)
01273 set_pixel(x + j, y + i, get_pixel(x + j, y + i), opcode);
01274 redraw(x, y, cx, cy);
01275 }
01276
01277
01278
01279 void fill_rect(int x, int y, int cx, int cy, int colour, int opcode = 0xc)
01280 {
01281 int i, j;
01282
01283 for (i = 0; i < cy; i++)
01284 for (j = 0; j < cx; j++)
01285 set_pixel(x + j, y + i, colour, opcode);
01286 }
01287
01288
01289 void ui_rect(int x, int y, int cx, int cy, int colour)
01290 {
01291 fill_rect(x, y, cx, cy, colour);
01292 redraw(x, y, cx, cy);
01293 }
01294
01295
01296 void ui_patblt(uint8 opcode, int x, int y, int cx, int cy,
01297 BRUSH * brush, int bgcolour, int fgcolour)
01298 {
01299 int i, j;
01300 uint8 ipattern[8];
01301
01302 switch (brush->style)
01303 {
01304 case 0:
01305 fill_rect(x, y, cx, cy, fgcolour, opcode);
01306 break;
01307 case 3:
01308 for (i = 0; i < 8; i++)
01309 ipattern[i] = ~brush->pattern[7 - i];
01310 for (i = 0; i < cy; i++)
01311 for (j = 0; j < cx; j++)
01312 if (is_pixel_on(ipattern, (x + j + brush->xorigin) % 8,
01313 (y + i + brush->yorigin) % 8, 8, 1))
01314 set_pixel(x + j, y + i, fgcolour, opcode);
01315 else
01316 set_pixel(x + j, y + i, bgcolour, opcode);
01317 break;
01318 }
01319 redraw(x, y, cx, cy);
01320 }
01321
01322
01323 void ui_screenblt(uint8 opcode, int x, int y, int cx, int cy,
01324 int srcx, int srcy)
01325 {
01326 int i, j;
01327 uint8* temp;
01328
01329 temp = (uint8*)xmalloc(cx * cy);
01330 for (i = 0; i < cy; i++)
01331 for (j = 0; j < cx; j++)
01332 temp[i * cx + j] = get_pixel(srcx + j, srcy + i);
01333 for (i = 0; i < cy; i++)
01334 for (j = 0; j < cx; j++)
01335 set_pixel(x + j, y + i, temp[i * cx + j], opcode);
01336 xfree(temp);
01337 redraw(x, y, cx, cy);
01338 }
01339
01340
01341 void ui_memblt(uint8 opcode, int x, int y, int cx, int cy,
01342 HBITMAP src, int srcx, int srcy)
01343 {
01344 int i, j;
01345 struct bitmap* the_bitmap;
01346
01347 the_bitmap = (struct bitmap*)src;
01348 if (the_bitmap == NULL)
01349 return;
01350 for (i = 0; i < cy; i++)
01351 for (j = 0; j < cx; j++)
01352 if ((i + srcy) < the_bitmap->h && (j + srcx) < the_bitmap->w)
01353 set_pixel(x + j, y + i, the_bitmap->data[(i + srcy) * the_bitmap->w + (j + srcx)], opcode);
01354 redraw(x, y, cx, cy);
01355 }
01356
01357
01358
01359 void ui_triblt(uint8 , int , int , int , int ,
01360 HBITMAP , int , int , BRUSH * ,
01361 int , int )
01362 {
01363 }
01364
01365
01366
01367 void ui_line(uint8 opcode, int startx, int starty, int endx,
01368 int endy, PEN * pen)
01369 {
01370 int dx, dy, incx, incy, dpr, dpru, p, left, top, right, bottom;
01371
01372 if (startx > endx)
01373 {
01374 dx = startx - endx;
01375 incx = -1;
01376 left = endx;
01377 right = startx;
01378 }
01379 else
01380 {
01381 dx = endx - startx;
01382 incx = 1;
01383 left = startx;
01384 right = endx;
01385 }
01386 if (starty > endy)
01387 {
01388 dy = starty - endy;
01389 incy = -1;
01390 top = endy;
01391 bottom = starty;
01392 }
01393 else
01394 {
01395 dy = endy - starty;
01396 incy = 1;
01397 top = starty;
01398 bottom = endy;
01399 }
01400 if (dx >= dy)
01401 {
01402 dpr = dy << 1;
01403 dpru = dpr - (dx << 1);
01404 p = dpr - dx;
01405 for (; dx >= 0; dx--)
01406 {
01407 set_pixel(startx, starty, pen->colour, opcode);
01408 if (p > 0)
01409 {
01410 startx += incx;
01411 starty += incy;
01412 p += dpru;
01413 }
01414 else
01415 {
01416 startx += incx;
01417 p += dpr;
01418 }
01419 }
01420 }
01421 else
01422 {
01423 dpr = dx << 1;
01424 dpru = dpr - (dy << 1);
01425 p = dpr - dy;
01426 for (; dy >= 0; dy--)
01427 {
01428 set_pixel(startx, starty, pen->colour, opcode);
01429 if (p > 0)
01430 {
01431 startx += incx;
01432 starty += incy;
01433 p += dpru;
01434 }
01435 else
01436 {
01437 starty += incy;
01438 p += dpr;
01439 }
01440 }
01441 }
01442 redraw(left, top, (right - left) + 1, (bottom - top) + 1);
01443 }
01444
01445
01446 void draw_glyph (int x, int y, HGLYPH glyph, int fgcolour)
01447 {
01448 struct bitmap* the_glyph;
01449 int i, j;
01450
01451 the_glyph = (struct bitmap*)glyph;
01452 if (the_glyph == NULL)
01453 return;
01454 for (i = 0; i < the_glyph->h; i++)
01455 for (j = 0; j < the_glyph->w; j++)
01456 if (is_pixel_on(the_glyph->data, j, i, the_glyph->w, 8))
01457 set_pixel(x + j, y + i, fgcolour);
01458 }
01459
01460 #define DO_GLYPH(ttext,idx) \
01461 {\
01462 glyph = cache_get_font (font, ttext[idx]);\
01463 if (!(flags & TEXT2_IMPLICIT_X))\
01464 {\
01465 xyoffset = ttext[++idx];\
01466 if ((xyoffset & 0x80))\
01467 {\
01468 if (flags & TEXT2_VERTICAL) \
01469 y += ttext[idx+1] | (ttext[idx+2] << 8);\
01470 else\
01471 x += ttext[idx+1] | (ttext[idx+2] << 8);\
01472 idx += 2;\
01473 }\
01474 else\
01475 {\
01476 if (flags & TEXT2_VERTICAL) \
01477 y += xyoffset;\
01478 else\
01479 x += xyoffset;\
01480 }\
01481 }\
01482 if (glyph != NULL)\
01483 {\
01484 draw_glyph (x + glyph->offset, y + glyph->baseline, glyph->pixmap, fgcolour);\
01485 if (flags & TEXT2_IMPLICIT_X)\
01486 x += glyph->width;\
01487 }\
01488 }
01489
01490
01491 void ui_draw_text(uint8 font, uint8 flags, int mixmode,
01492 int x, int y, int clipx, int clipy,
01493 int clipcx, int clipcy, int boxx,
01494 int boxy, int boxcx, int boxcy, int bgcolour,
01495 int fgcolour, uint8 * text, uint8 length)
01496 {
01497 FONTGLYPH *glyph;
01498 int i, j, xyoffset;
01499 DATABLOB *entry;
01500
01501 if (boxcx > 1)
01502 fill_rect(boxx, boxy, boxcx, boxcy, bgcolour);
01503 else if (mixmode == MIX_OPAQUE)
01504 fill_rect(clipx, clipy, clipcx, clipcy, bgcolour);
01505
01506
01507 for (i = 0; i < length;)
01508 {
01509 switch (text[i])
01510 {
01511 case 0xff:
01512 if (i + 2 < length)
01513 cache_put_text(text[i + 1], text, text[i + 2]);
01514 else
01515 {
01516 error("this shouldn't be happening\n");
01517 exit(1);
01518 }
01519
01520 length -= i + 3;
01521 text = &(text[i + 3]);
01522 i = 0;
01523 break;
01524
01525 case 0xfe:
01526 entry = cache_get_text(text[i + 1]);
01527 if (entry != NULL)
01528 {
01529 if ((((uint8 *) (entry->data))[1] == 0) && (!(flags & TEXT2_IMPLICIT_X)))
01530 {
01531 if (flags & TEXT2_VERTICAL)
01532 y += text[i + 2];
01533 else
01534 x += text[i + 2];
01535 }
01536 for (j = 0; j < entry->size; j++)
01537 DO_GLYPH(((uint8 *) (entry->data)), j);
01538 }
01539 if (i + 2 < length)
01540 i += 3;
01541 else
01542 i += 2;
01543 length -= i;
01544
01545 text = &(text[i]);
01546 i = 0;
01547 break;
01548
01549 default:
01550 DO_GLYPH(text, i);
01551 i++;
01552 break;
01553 }
01554 }
01555 if (boxcx > 1)
01556 redraw(boxx, boxy, boxcx, boxcy);
01557 else
01558 redraw(clipx, clipy, clipcx, clipcy);
01559 }
01560
01561
01562 void ui_desktop_save(uint32 offset, int x, int y, int cx, int cy)
01563 {
01564 uint8* data;
01565 int i, j;
01566
01567 data = (uint8*)xmalloc(cx * cy);
01568 for (i = 0; i < cy; i++)
01569 for (j = 0; j < cx; j++)
01570 data[i * cx + j] = get_pixel(x + j, y + i);
01571 cache_put_desktop(offset, cx, cy, cx, 1, data);
01572 xfree(data);
01573 }
01574
01575
01576 void ui_desktop_restore(uint32 offset, int x, int y, int cx, int cy)
01577 {
01578 uint8* data;
01579 int i, j;
01580
01581 data = cache_get_desktop(offset, cx, cy, 1);
01582 for (i = 0; i < cy; i++)
01583 for (j = 0; j < cx; j++)
01584 set_pixel(x + j, y + i, data[i * cx + j]);
01585 redraw(x, y, cx, cy);
01586 }
01587
01588
01589 int main(int argc, char** argv)
01590 {
01591 CM = NULL;
01592 BS = NULL;
01593 App = new QPEApplication(argc, argv);
01594 SV = new QMyScrollView();
01595 App->setMainWidget(SV);
01596 SV->showMaximized();
01597 SV->setCaption( QMyScrollView::tr("Remote Desktop Client (RDP)") );
01598 SV->timer_id = SV->startTimer(1000);
01599 App->exec();
01600 delete SV;
01601 delete App;
01602 if (CM != NULL)
01603 xfree(CM);
01604 if (BS !=NULL)
01605 xfree(BS);
01606 return 0;
01607 }
01608
01609
01610
01611
01612
01613
01614
01615
01616
01617
01618
01619
01620
01621
01622
01623
01624
01625
01626
01627
01628
01629
01630
01631
01632
01633
01634
01635
01636
01637
01638
01639
01640
01641
01642
01643
01644
01645
01646
01647
01648
01649
01650
01651
01652
01653
01654
01655
01656
01657
01658
01659
01660
01661
01662
01663
01664
01665
01666
01667
01668
01669
01670
01671
01672
01673
01674
01675
01676
01677
01678
01679
01680
01681
01682
01683
01684
01685
01686
01687
01688
01689
01690
01691
01692
01693
01694
01695
01696