34 |
#include <qfile.h> |
#include <qfile.h> |
35 |
|
|
36 |
#include "qtwin.h" |
#include "qtwin.h" |
37 |
|
|
38 |
#include <unistd.h> // gethostname |
#include <unistd.h> // gethostname |
39 |
#include <pwd.h> // getpwuid |
#include <pwd.h> // getpwuid |
40 |
#include <stdarg.h> // va_list va_start va_end |
#include <stdarg.h> // va_list va_start va_end |
41 |
|
|
42 |
|
#include <errno.h> |
43 |
|
#include <fcntl.h> |
44 |
|
|
45 |
/* rdesktop globals */ |
/* rdesktop globals */ |
46 |
extern int g_tcp_port_rdp; |
extern int g_tcp_port_rdp; |
47 |
int g_use_rdp5 = 1; |
int g_use_rdp5 = 1; |
62 |
int g_keylayout = 0x409; /* Defaults to US keyboard layout */ |
int g_keylayout = 0x409; /* Defaults to US keyboard layout */ |
63 |
|
|
64 |
/* hack globals */ |
/* hack globals */ |
65 |
int g_argc = 0; |
static int g_argc = 0; |
66 |
char** g_argv = 0; |
static char ** g_argv = 0; |
67 |
int UpAndRunning = 0; |
static int g_UpAndRunning = 0; |
68 |
int g_sock = 0; |
static int g_sock = 0; |
69 |
int deactivated = 0; |
static int g_deactivated = 0; |
70 |
uint32 ext_disc_reason = 0; |
static uint32 g_ext_disc_reason = 0; |
71 |
char g_servername[128]; |
static char g_servername[128]; |
72 |
char g_title[128] = ""; |
static char g_title[128] = ""; |
73 |
|
static int g_flags = RDP_LOGON_NORMAL; |
74 |
|
|
75 |
/* qt globals */ |
/* qt globals */ |
76 |
QSocketNotifier* SocketNotifier; |
static QSocketNotifier * g_SocketNotifier; |
77 |
QApplication* App; |
static QApplication * g_App; |
78 |
QMyMainWindow* g_MW; |
static QMyMainWindow * g_MW; |
79 |
QMyScrollView* SV; |
static QMyScrollView * g_SV; |
80 |
QPixmap* BS; |
static QPixmap * g_BS; |
81 |
QPixmap* DS; |
static QPixmap * g_DS; |
82 |
QPainter* P1; |
static QPainter * g_P1; |
83 |
QPainter* P2; |
static QPainter * g_P2; |
84 |
QColor Color1; |
static QColor g_Color1; |
85 |
QColor Color2; |
static QColor g_Color2; |
86 |
|
|
87 |
struct QColorMap |
struct QColorMap |
88 |
{ |
{ |
89 |
uint32 RGBColors[256]; |
uint32 RGBColors[256]; |
90 |
int NumColors; |
int NumColors; |
91 |
}; |
}; |
92 |
QColorMap* CM = 0; |
static struct QColorMap * g_CM = 0; |
93 |
QRegion* ClipRect; |
static QRegion * g_ClipRect; |
94 |
|
|
95 |
Qt::RasterOp OpCodes[16] = { |
static Qt::RasterOp g_OpCodes[16] = { |
96 |
Qt::ClearROP, // BLACKNESS 0 |
Qt::ClearROP, // BLACKNESS 0 |
97 |
Qt::NorROP, // NOTSRCERASE DSon |
Qt::NorROP, // NOTSRCERASE DSon |
98 |
Qt::NotAndROP, // DSna |
Qt::NotAndROP, // DSna |
114 |
uint32 Color15to32(uint32 InColor) |
uint32 Color15to32(uint32 InColor) |
115 |
{ |
{ |
116 |
uint32 r, g, b; |
uint32 r, g, b; |
117 |
|
|
118 |
r = (InColor & 0x7c00) >> 10; |
r = (InColor & 0x7c00) >> 10; |
119 |
r = (r * 0xff) / 0x1f; |
r = (r * 0xff) / 0x1f; |
120 |
g = (InColor & 0x03e0) >> 5; |
g = (InColor & 0x03e0) >> 5; |
128 |
uint32 Color16to32(uint32 InColor) |
uint32 Color16to32(uint32 InColor) |
129 |
{ |
{ |
130 |
uint32 r, g, b; |
uint32 r, g, b; |
131 |
|
|
132 |
r = (InColor & 0xf800) >> 11; |
r = (InColor & 0xf800) >> 11; |
133 |
r = (r * 0xff) / 0x1f; |
r = (r * 0xff) / 0x1f; |
134 |
g = (InColor & 0x07e0) >> 5; |
g = (InColor & 0x07e0) >> 5; |
141 |
//***************************************************************************** |
//***************************************************************************** |
142 |
uint32 Color24to32(uint32 InColor) |
uint32 Color24to32(uint32 InColor) |
143 |
{ |
{ |
144 |
return ((InColor & 0x00ff0000) >> 16) | ((InColor & 0x000000ff) << 16) | |
return ((InColor & 0x00ff0000) >> 16) | |
145 |
|
((InColor & 0x000000ff) << 16) | |
146 |
(InColor & 0x0000ff00); |
(InColor & 0x0000ff00); |
147 |
} |
} |
148 |
|
|
149 |
//***************************************************************************** |
//***************************************************************************** |
150 |
void SetColorx(QColor* Color, uint32 InColor) |
void SetColorx(QColor * Color, uint32 InColor) |
151 |
{ |
{ |
152 |
switch (g_server_bpp) |
switch (g_server_bpp) |
153 |
{ |
{ |
154 |
case 8: |
case 8: |
155 |
if (CM == NULL || InColor > 255) |
if (g_CM == NULL || InColor > 255) |
156 |
{ |
{ |
157 |
Color->setRgb(0); |
Color->setRgb(0); |
158 |
return; |
return; |
159 |
} |
} |
160 |
Color->setRgb(CM->RGBColors[InColor]); |
Color->setRgb(g_CM->RGBColors[InColor]); |
161 |
break; |
break; |
162 |
case 15: |
case 15: |
163 |
Color->setRgb(Color15to32(InColor)); |
Color->setRgb(Color15to32(InColor)); |
178 |
{ |
{ |
179 |
if (opcode >= 0 && opcode < 16) |
if (opcode >= 0 && opcode < 16) |
180 |
{ |
{ |
181 |
Qt::RasterOp op = OpCodes[opcode]; |
Qt::RasterOp op = g_OpCodes[opcode]; |
182 |
if (op != Qt::CopyROP) |
if (op != Qt::CopyROP) |
183 |
{ |
{ |
184 |
P1->setRasterOp(op); |
g_P1->setRasterOp(op); |
185 |
P2->setRasterOp(op); |
g_P2->setRasterOp(op); |
186 |
} |
} |
187 |
} |
} |
188 |
} |
} |
192 |
{ |
{ |
193 |
if (opcode >= 0 && opcode < 16) |
if (opcode >= 0 && opcode < 16) |
194 |
{ |
{ |
195 |
Qt::RasterOp op = OpCodes[opcode]; |
Qt::RasterOp op = g_OpCodes[opcode]; |
196 |
if (op != Qt::CopyROP) |
if (op != Qt::CopyROP) |
197 |
{ |
{ |
198 |
P1->setRasterOp(Qt::CopyROP); |
g_P1->setRasterOp(Qt::CopyROP); |
199 |
P2->setRasterOp(Qt::CopyROP); |
g_P2->setRasterOp(Qt::CopyROP); |
200 |
} |
} |
201 |
} |
} |
202 |
} |
} |
203 |
|
|
204 |
/*****************************************************************************/ |
/*****************************************************************************/ |
205 |
QMyMainWindow::QMyMainWindow() : QWidget() |
QMyMainWindow::QMyMainWindow(): QWidget() |
206 |
{ |
{ |
207 |
} |
} |
208 |
|
|
212 |
} |
} |
213 |
|
|
214 |
//***************************************************************************** |
//***************************************************************************** |
215 |
void QMyMainWindow::mouseMoveEvent(QMouseEvent* e) |
void QMyMainWindow::mouseMoveEvent(QMouseEvent * e) |
216 |
{ |
{ |
217 |
if (!UpAndRunning) |
if (!g_UpAndRunning) |
218 |
|
{ |
219 |
return; |
return; |
220 |
|
} |
221 |
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_MOVE, e->x(), e->y()); |
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_MOVE, e->x(), e->y()); |
222 |
} |
} |
223 |
|
|
224 |
//***************************************************************************** |
//***************************************************************************** |
225 |
void QMyMainWindow::mousePressEvent(QMouseEvent* e) |
void QMyMainWindow::mousePressEvent(QMouseEvent * e) |
226 |
{ |
{ |
227 |
if (!UpAndRunning) |
if (!g_UpAndRunning) |
228 |
|
{ |
229 |
return; |
return; |
230 |
|
} |
231 |
if (e->button() == LeftButton) |
if (e->button() == LeftButton) |
232 |
|
{ |
233 |
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON1, |
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON1, |
234 |
e->x(), e->y()); |
e->x(), e->y()); |
235 |
|
} |
236 |
else if (e->button() == RightButton) |
else if (e->button() == RightButton) |
237 |
|
{ |
238 |
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON2, |
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON2, |
239 |
e->x(), e->y()); |
e->x(), e->y()); |
240 |
|
} |
241 |
else if (e->button() == MidButton) |
else if (e->button() == MidButton) |
242 |
|
{ |
243 |
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON3, |
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON3, |
244 |
e->x(), e->y()); |
e->x(), e->y()); |
245 |
|
} |
246 |
} |
} |
247 |
|
|
248 |
//***************************************************************************** |
//***************************************************************************** |
249 |
void QMyMainWindow::mouseReleaseEvent(QMouseEvent* e) |
void QMyMainWindow::mouseReleaseEvent(QMouseEvent * e) |
250 |
{ |
{ |
251 |
if (!UpAndRunning) |
if (!g_UpAndRunning) |
252 |
|
{ |
253 |
return; |
return; |
254 |
|
} |
255 |
if (e->button() == LeftButton) |
if (e->button() == LeftButton) |
256 |
|
{ |
257 |
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1, e->x(), e->y()); |
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1, e->x(), e->y()); |
258 |
|
} |
259 |
else if (e->button() == RightButton) |
else if (e->button() == RightButton) |
260 |
|
{ |
261 |
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON2, e->x(), e->y()); |
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON2, e->x(), e->y()); |
262 |
|
} |
263 |
else if (e->button() == MidButton) |
else if (e->button() == MidButton) |
264 |
|
{ |
265 |
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON3, e->x(), e->y()); |
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON3, e->x(), e->y()); |
266 |
|
} |
267 |
} |
} |
268 |
|
|
269 |
//***************************************************************************** |
//***************************************************************************** |
270 |
void QMyMainWindow::wheelEvent(QWheelEvent* e) |
void QMyMainWindow::wheelEvent(QWheelEvent * e) |
271 |
{ |
{ |
272 |
if (!UpAndRunning) |
if (!g_UpAndRunning) |
273 |
|
{ |
274 |
return; |
return; |
275 |
|
} |
276 |
if (e->delta() > 0) |
if (e->delta() > 0) |
277 |
|
{ |
278 |
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON4, e->x(), e->y()); |
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON4, e->x(), e->y()); |
279 |
|
} |
280 |
else if (e->delta() < 0) |
else if (e->delta() < 0) |
281 |
|
{ |
282 |
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON5, e->x(), e->y()); |
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON5, e->x(), e->y()); |
283 |
|
} |
284 |
} |
} |
285 |
|
|
286 |
//***************************************************************************** |
//***************************************************************************** |
408 |
//***************************************************************************** |
//***************************************************************************** |
409 |
void QMyMainWindow::keyPressEvent(QKeyEvent* e) |
void QMyMainWindow::keyPressEvent(QKeyEvent* e) |
410 |
{ |
{ |
411 |
if (!UpAndRunning) |
if (!g_UpAndRunning) |
412 |
return; |
return; |
413 |
int ScanCode = GetScanCode(e); |
int ScanCode = GetScanCode(e); |
414 |
if (ScanCode != 0) |
if (ScanCode != 0) |
421 |
//***************************************************************************** |
//***************************************************************************** |
422 |
void QMyMainWindow::keyReleaseEvent(QKeyEvent* e) |
void QMyMainWindow::keyReleaseEvent(QKeyEvent* e) |
423 |
{ |
{ |
424 |
if (!UpAndRunning) |
if (!g_UpAndRunning) |
425 |
|
{ |
426 |
return; |
return; |
427 |
|
} |
428 |
int ScanCode = GetScanCode(e); |
int ScanCode = GetScanCode(e); |
429 |
if (ScanCode != 0) |
if (ScanCode != 0) |
430 |
{ |
{ |
434 |
} |
} |
435 |
|
|
436 |
//***************************************************************************** |
//***************************************************************************** |
437 |
void QMyMainWindow::paintEvent(QPaintEvent* pe) |
void QMyMainWindow::paintEvent(QPaintEvent * pe) |
438 |
{ |
{ |
439 |
QRect Rect; |
QRect Rect; |
440 |
|
|
441 |
Rect = pe->rect(); |
Rect = pe->rect(); |
442 |
bitBlt(this, Rect.left(), Rect.top(), BS, Rect.left(), Rect.top(), |
bitBlt(this, Rect.left(), Rect.top(), g_BS, Rect.left(), Rect.top(), |
443 |
Rect.width(), Rect.height()); |
Rect.width(), Rect.height()); |
444 |
} |
} |
445 |
|
|
446 |
//***************************************************************************** |
//***************************************************************************** |
447 |
void QMyMainWindow::closeEvent(QCloseEvent* e) |
void QMyMainWindow::closeEvent(QCloseEvent * e) |
448 |
{ |
{ |
449 |
e->accept(); |
e->accept(); |
450 |
} |
} |
451 |
|
|
452 |
//***************************************************************************** |
//***************************************************************************** |
453 |
bool QMyMainWindow::event(QEvent* e) |
bool QMyMainWindow::event(QEvent * e) |
454 |
{ |
{ |
455 |
return QWidget::event(e); |
return QWidget::event(e); |
456 |
} |
} |
458 |
//***************************************************************************** |
//***************************************************************************** |
459 |
void QMyMainWindow::dataReceived() |
void QMyMainWindow::dataReceived() |
460 |
{ |
{ |
461 |
if (!rdp_loop(&deactivated, &ext_disc_reason)) |
if (!rdp_loop(&g_deactivated, &g_ext_disc_reason)) |
462 |
SV->close(); |
{ |
463 |
|
g_SV->close(); |
464 |
|
} |
465 |
} |
} |
466 |
|
|
467 |
//***************************************************************************** |
//***************************************************************************** |
468 |
void QMyScrollView::keyPressEvent(QKeyEvent* e) |
void QMyScrollView::keyPressEvent(QKeyEvent * e) |
469 |
{ |
{ |
470 |
g_MW->keyPressEvent(e); |
g_MW->keyPressEvent(e); |
471 |
} |
} |
472 |
|
|
473 |
//***************************************************************************** |
//***************************************************************************** |
474 |
void QMyScrollView::keyReleaseEvent(QKeyEvent* e) |
void QMyScrollView::keyReleaseEvent(QKeyEvent * e) |
475 |
{ |
{ |
476 |
g_MW->keyReleaseEvent(e); |
g_MW->keyReleaseEvent(e); |
477 |
} |
} |
480 |
//***************************************************************************** |
//***************************************************************************** |
481 |
void ui_begin_update(void) |
void ui_begin_update(void) |
482 |
{ |
{ |
483 |
P1->begin(g_MW); |
g_P1->begin(g_MW); |
484 |
P2->begin(BS); |
g_P2->begin(g_BS); |
485 |
} |
} |
486 |
|
|
487 |
//***************************************************************************** |
//***************************************************************************** |
488 |
void ui_end_update(void) |
void ui_end_update(void) |
489 |
{ |
{ |
490 |
P1->end(); |
g_P1->end(); |
491 |
P2->end(); |
g_P2->end(); |
492 |
} |
} |
493 |
|
|
494 |
/*****************************************************************************/ |
/*****************************************************************************/ |
495 |
int ui_init(void) |
int ui_init(void) |
496 |
{ |
{ |
497 |
App = new QApplication(g_argc, g_argv); |
g_App = new QApplication(g_argc, g_argv); |
498 |
return 1; |
return 1; |
499 |
} |
} |
500 |
|
|
501 |
/*****************************************************************************/ |
/*****************************************************************************/ |
502 |
void ui_deinit(void) |
void ui_deinit(void) |
503 |
{ |
{ |
504 |
delete App; |
delete g_App; |
505 |
} |
} |
506 |
|
|
507 |
/*****************************************************************************/ |
/*****************************************************************************/ |
508 |
int ui_create_window(void) |
int ui_create_window(void) |
509 |
{ |
{ |
510 |
int w, h; |
int w, h; |
511 |
|
QPainter * painter; |
512 |
|
QWidget * desktop; |
513 |
|
|
514 |
g_MW = new QMyMainWindow(); |
g_MW = new QMyMainWindow(); |
515 |
SV = new QMyScrollView(); |
g_SV = new QMyScrollView(); |
516 |
SV->addChild(g_MW); |
g_SV->addChild(g_MW); |
517 |
BS = new QPixmap(g_width, g_height); |
g_BS = new QPixmap(g_width, g_height); |
518 |
QPainter* P = new QPainter(BS); |
painter = new QPainter(g_BS); |
519 |
P->fillRect(0, 0, g_width, g_height, QBrush(QColor("white"))); |
painter->fillRect(0, 0, g_width, g_height, QBrush(QColor("white"))); |
520 |
P->fillRect(0, 0, g_width, g_height, QBrush(QBrush::CrossPattern)); |
painter->fillRect(0, 0, g_width, g_height, QBrush(QBrush::CrossPattern)); |
521 |
delete P; |
delete painter; |
522 |
DS = new QPixmap(480, 480); |
g_DS = new QPixmap(480, 480); |
523 |
P1 = new QPainter(); |
g_P1 = new QPainter(); |
524 |
P2 = new QPainter(); |
g_P2 = new QPainter(); |
525 |
ClipRect = new QRegion(0, 0, g_width, g_height); |
g_ClipRect = new QRegion(0, 0, g_width, g_height); |
526 |
QWidget* d = QApplication::desktop(); |
desktop = QApplication::desktop(); |
527 |
w = d->width(); // returns screen width |
w = desktop->width(); // returns screen width |
528 |
h = d->height(); // returns screen height |
h = desktop->height(); // returns screen height |
529 |
g_MW->resize(g_width, g_height); |
g_MW->resize(g_width, g_height); |
530 |
if (w < g_width || h < g_height) |
if (w < g_width || h < g_height) |
531 |
SV->resize(w, h); |
{ |
532 |
|
g_SV->resize(w, h); |
533 |
|
} |
534 |
else |
else |
535 |
SV->resize(g_width + 4, g_height + 4); |
{ |
536 |
SV->setMaximumWidth(g_width + 4); |
g_SV->resize(g_width + 4, g_height + 4); |
537 |
SV->setMaximumHeight(g_height + 4); |
} |
538 |
App->setMainWidget(SV); |
g_SV->setMaximumWidth(g_width + 4); |
539 |
SV->show(); |
g_SV->setMaximumHeight(g_height + 4); |
540 |
|
g_App->setMainWidget(g_SV); |
541 |
|
g_SV->show(); |
542 |
g_MW->setMouseTracking(true); |
g_MW->setMouseTracking(true); |
543 |
if (g_title[0] != 0) |
if (g_title[0] != 0) |
544 |
SV->setCaption(g_title); |
{ |
545 |
|
g_SV->setCaption(g_title); |
546 |
|
} |
547 |
|
|
548 |
/* XGrayKey(0, 64, AnyModifie, SV->winId(), 0, GrabModeAsync, GrabModeAsync); |
/* XGrayKey(0, 64, AnyModifie, SV->winId(), 0, GrabModeAsync, GrabModeAsync); |
549 |
XGrayKey(0, 113, AnyModifie, SV->winId(), 0, GrabModeAsync, GrabModeAsync); |
XGrayKey(0, 113, AnyModifie, SV->winId(), 0, GrabModeAsync, GrabModeAsync); |
562 |
void ui_main_loop(void) |
void ui_main_loop(void) |
563 |
{ |
{ |
564 |
// connect |
// connect |
565 |
if (!rdp_connect(g_servername, RDP_LOGON_NORMAL, "", "", "", "")) |
if (!rdp_connect(g_servername, g_flags, "", "", "", "")) |
566 |
|
{ |
567 |
return; |
return; |
568 |
|
} |
569 |
// start notifier |
// start notifier |
570 |
SocketNotifier = new QSocketNotifier(g_sock, QSocketNotifier::Read, g_MW); |
g_SocketNotifier = new QSocketNotifier(g_sock, QSocketNotifier::Read, g_MW); |
571 |
g_MW->connect(SocketNotifier, SIGNAL(activated(int)), g_MW, SLOT(dataReceived())); |
g_MW->connect(g_SocketNotifier, SIGNAL(activated(int)), |
572 |
UpAndRunning = 1; |
g_MW, SLOT(dataReceived())); |
573 |
|
g_UpAndRunning = 1; |
574 |
// app main loop |
// app main loop |
575 |
App->exec(); |
g_App->exec(); |
576 |
} |
} |
577 |
|
|
578 |
//***************************************************************************** |
//***************************************************************************** |
579 |
void ui_destroy_window(void) |
void ui_destroy_window(void) |
580 |
{ |
{ |
581 |
delete g_MW; |
delete g_MW; |
582 |
delete SV; |
delete g_SV; |
583 |
delete BS; |
delete g_BS; |
584 |
delete DS; |
delete g_DS; |
585 |
delete P1; |
delete g_P1; |
586 |
delete P2; |
delete g_P2; |
587 |
delete ClipRect; |
delete g_ClipRect; |
588 |
} |
} |
589 |
|
|
590 |
/*****************************************************************************/ |
/*****************************************************************************/ |
595 |
/*****************************************************************************/ |
/*****************************************************************************/ |
596 |
int ui_select(int in_val) |
int ui_select(int in_val) |
597 |
{ |
{ |
598 |
g_sock = in_val; |
if (g_sock == 0) |
599 |
|
{ |
600 |
|
g_sock = in_val; |
601 |
|
} |
602 |
return 1; |
return 1; |
603 |
} |
} |
604 |
|
|
605 |
/*****************************************************************************/ |
/*****************************************************************************/ |
606 |
void ui_destroy_cursor(void* cursor) |
void ui_destroy_cursor(void * cursor) |
607 |
{ |
{ |
608 |
QCursor* Cursor; |
QCursor * Cursor; |
609 |
Cursor = (QCursor*)cursor; |
Cursor = (QCursor*)cursor; |
610 |
if (Cursor != NULL) |
if (Cursor != NULL) |
611 |
|
{ |
612 |
delete Cursor; |
delete Cursor; |
613 |
|
} |
614 |
} |
} |
615 |
|
|
616 |
/*****************************************************************************/ |
/*****************************************************************************/ |
617 |
void* ui_create_glyph(int width, int height, uint8* data) |
void* ui_create_glyph(int width, int height, uint8 * data) |
618 |
{ |
{ |
619 |
QBitmap* Bitmap; |
QBitmap * Bitmap; |
620 |
Bitmap = new QBitmap(width, height, data); |
Bitmap = new QBitmap(width, height, data); |
621 |
Bitmap->setMask(*Bitmap); |
Bitmap->setMask(*Bitmap); |
622 |
return (HGLYPH)Bitmap; |
return (HGLYPH)Bitmap; |
623 |
} |
} |
624 |
|
|
625 |
/*****************************************************************************/ |
/*****************************************************************************/ |
626 |
void ui_destroy_glyph(void* glyph) |
void ui_destroy_glyph(void * glyph) |
627 |
{ |
{ |
628 |
QBitmap* Bitmap; |
QBitmap* Bitmap; |
629 |
Bitmap = (QBitmap*)glyph; |
Bitmap = (QBitmap*)glyph; |
631 |
} |
} |
632 |
|
|
633 |
/*****************************************************************************/ |
/*****************************************************************************/ |
634 |
void ui_destroy_bitmap(void* bmp) |
void ui_destroy_bitmap(void * bmp) |
635 |
{ |
{ |
636 |
QPixmap* Pixmap; |
QPixmap * Pixmap; |
637 |
Pixmap = (QPixmap*)bmp; |
Pixmap = (QPixmap*)bmp; |
638 |
delete Pixmap; |
delete Pixmap; |
639 |
} |
} |
641 |
/*****************************************************************************/ |
/*****************************************************************************/ |
642 |
void ui_reset_clip(void) |
void ui_reset_clip(void) |
643 |
{ |
{ |
644 |
P1->setClipRect(0, 0, g_width, g_height); |
g_P1->setClipRect(0, 0, g_width, g_height); |
645 |
P2->setClipRect(0, 0, g_width, g_height); |
g_P2->setClipRect(0, 0, g_width, g_height); |
646 |
delete ClipRect; |
delete g_ClipRect; |
647 |
ClipRect = new QRegion(0, 0, g_width, g_height); |
g_ClipRect = new QRegion(0, 0, g_width, g_height); |
648 |
} |
} |
649 |
|
|
650 |
/*****************************************************************************/ |
/*****************************************************************************/ |
651 |
void ui_set_clip(int x, int y, int cx, int cy) |
void ui_set_clip(int x, int y, int cx, int cy) |
652 |
{ |
{ |
653 |
P1->setClipRect(x, y, cx, cy); |
g_P1->setClipRect(x, y, cx, cy); |
654 |
P2->setClipRect(x, y, cx, cy); |
g_P2->setClipRect(x, y, cx, cy); |
655 |
delete ClipRect; |
delete g_ClipRect; |
656 |
ClipRect = new QRegion(x, y, cx, cy); |
g_ClipRect = new QRegion(x, y, cx, cy); |
657 |
} |
} |
658 |
|
|
659 |
/*****************************************************************************/ |
/*****************************************************************************/ |
660 |
void* ui_create_colourmap(COLOURMAP* colours) |
void * ui_create_colourmap(COLOURMAP * colours) |
661 |
{ |
{ |
662 |
QColorMap* LCM; |
QColorMap* LCM; |
663 |
int i, r, g, b; |
int i, r, g, b; |
680 |
// todo, does this leak at end of program |
// todo, does this leak at end of program |
681 |
void ui_destroy_colourmap(HCOLOURMAP map) |
void ui_destroy_colourmap(HCOLOURMAP map) |
682 |
{ |
{ |
683 |
QColorMap* LCM; |
QColorMap * LCM; |
684 |
LCM = (QColorMap*)map; |
LCM = (QColorMap*)map; |
685 |
if (LCM == NULL) |
if (LCM == NULL) |
686 |
return; |
return; |
688 |
} |
} |
689 |
|
|
690 |
/*****************************************************************************/ |
/*****************************************************************************/ |
691 |
void ui_set_colourmap(void* map) |
void ui_set_colourmap(void * map) |
692 |
{ |
{ |
693 |
// destoy old colormap |
// destoy old colormap |
694 |
ui_destroy_colourmap(CM); |
ui_destroy_colourmap(g_CM); |
695 |
CM = (QColorMap*)map; |
g_CM = (QColorMap*)map; |
696 |
} |
} |
697 |
|
|
698 |
/*****************************************************************************/ |
/*****************************************************************************/ |
699 |
HBITMAP ui_create_bitmap(int width, int height, uint8* data) |
HBITMAP ui_create_bitmap(int width, int height, uint8 * data) |
700 |
{ |
{ |
701 |
QImage* Image = NULL; |
QImage * Image = NULL; |
702 |
QPixmap* Pixmap; |
QPixmap * Pixmap; |
703 |
uint32* d = NULL; |
uint32 * d = NULL; |
704 |
uint16* s; |
uint16 * s; |
705 |
|
int i; |
706 |
|
|
707 |
switch (g_server_bpp) |
switch (g_server_bpp) |
708 |
{ |
{ |
709 |
case 8: |
case 8: |
710 |
Image = new QImage(data, width, height, 8, (QRgb*)&CM->RGBColors, |
Image = new QImage(data, width, height, 8, (QRgb*)&g_CM->RGBColors, |
711 |
CM->NumColors, QImage::IgnoreEndian); |
g_CM->NumColors, QImage::IgnoreEndian); |
712 |
break; |
break; |
713 |
case 15: |
case 15: |
714 |
d = (uint32*)malloc(width * height * 4); |
d = (uint32*)malloc(width * height * 4); |
715 |
s = (uint16*)data; |
s = (uint16*)data; |
716 |
for (int i = 0; i < width * height; i++) |
for (i = 0; i < width * height; i++) |
717 |
|
{ |
718 |
d[i] = Color15to32(s[i]); |
d[i] = Color15to32(s[i]); |
719 |
|
} |
720 |
Image = new QImage((uint8*)d, width, height, 32, NULL, |
Image = new QImage((uint8*)d, width, height, 32, NULL, |
721 |
0, QImage::IgnoreEndian); |
0, QImage::IgnoreEndian); |
722 |
break; |
break; |
723 |
case 16: |
case 16: |
724 |
d = (uint32*)malloc(width * height * 4); |
d = (uint32*)malloc(width * height * 4); |
725 |
s = (uint16*)data; |
s = (uint16*)data; |
726 |
for (int i = 0; i < width * height; i++) |
for (i = 0; i < width * height; i++) |
727 |
|
{ |
728 |
d[i] = Color16to32(s[i]); |
d[i] = Color16to32(s[i]); |
729 |
|
} |
730 |
Image = new QImage((uint8*)d, width, height, 32, NULL, |
Image = new QImage((uint8*)d, width, height, 32, NULL, |
731 |
0, QImage::IgnoreEndian); |
0, QImage::IgnoreEndian); |
732 |
break; |
break; |
733 |
case 24: |
case 24: |
734 |
d = (uint32*)malloc(width * height * 4); |
d = (uint32*)malloc(width * height * 4); |
735 |
memset(d, 0, width * height * 4); |
memset(d, 0, width * height * 4); |
736 |
for (int i = 0; i < width * height; i++) |
for (i = 0; i < width * height; i++) |
737 |
|
{ |
738 |
memcpy(d + i, data + i * 3, 3); |
memcpy(d + i, data + i * 3, 3); |
739 |
|
} |
740 |
Image = new QImage((uint8*)d, width, height, 32, NULL, |
Image = new QImage((uint8*)d, width, height, 32, NULL, |
741 |
0, QImage::IgnoreEndian); |
0, QImage::IgnoreEndian); |
|
//Image = new QImage(data, width, height, 24, NULL, |
|
|
// 0, QImage::IgnoreEndian); |
|
742 |
break; |
break; |
743 |
} |
} |
744 |
if (Image == NULL) |
if (Image == NULL) |
745 |
|
{ |
746 |
return NULL; |
return NULL; |
747 |
|
} |
748 |
Pixmap = new QPixmap(); |
Pixmap = new QPixmap(); |
749 |
Pixmap->convertFromImage(*Image); |
Pixmap->convertFromImage(*Image); |
750 |
delete Image; |
delete Image; |
751 |
if (d != NULL) |
if (d != NULL) |
752 |
|
{ |
753 |
free(d); |
free(d); |
754 |
|
} |
755 |
return (HBITMAP)Pixmap; |
return (HBITMAP)Pixmap; |
756 |
} |
} |
757 |
|
|
758 |
//****************************************************************************** |
//****************************************************************************** |
759 |
// adjust coordinates for cliping rect |
// adjust coordinates for cliping rect |
760 |
BOOL WarpCoords(int* x, int* y, int* cx, int* cy, int* srcx, int* srcy) |
int WarpCoords(int * x, int * y, int * cx, int * cy, int * srcx, int * srcy) |
761 |
{ |
{ |
762 |
int dx, dy; |
int dx, dy; |
763 |
QRect InRect(*x, *y, *cx, *cy); |
QRect InRect(*x, *y, *cx, *cy); |
764 |
QRect OutRect; |
QRect OutRect; |
765 |
QRect CRect = ClipRect->boundingRect(); |
QRect CRect = g_ClipRect->boundingRect(); |
766 |
OutRect = InRect.intersect(CRect); |
OutRect = InRect.intersect(CRect); |
767 |
if (OutRect.isEmpty()) |
if (OutRect.isEmpty()) |
768 |
|
{ |
769 |
return False; |
return False; |
770 |
|
} |
771 |
dx = OutRect.x() - InRect.x(); |
dx = OutRect.x() - InRect.x(); |
772 |
dy = OutRect.y() - InRect.y(); |
dy = OutRect.y() - InRect.y(); |
773 |
*x = OutRect.x(); |
*x = OutRect.x(); |
781 |
|
|
782 |
//****************************************************************************** |
//****************************************************************************** |
783 |
// needed because bitBlt don't seem to care about clipping rects |
// needed because bitBlt don't seem to care about clipping rects |
784 |
// also has 2 dsts and src can be nil |
// also has 2 dsts and src can be null |
785 |
void bitBltClip(QPaintDevice* dst1, QPaintDevice* dst2, int dx, int dy, |
void bitBltClip(QPaintDevice * dst1, QPaintDevice * dst2, int dx, int dy, |
786 |
QPaintDevice* src, int sx, int sy, int sw, int sh, |
QPaintDevice * src, int sx, int sy, int sw, int sh, |
787 |
Qt::RasterOp rop, bool im) |
Qt::RasterOp rop, bool im) |
788 |
{ |
{ |
789 |
if (WarpCoords(&dx, &dy, &sw, &sh, &sx, &sy)) |
if (WarpCoords(&dx, &dy, &sw, &sh, &sx, &sy)) |
790 |
{ |
{ |
791 |
if (dst1 != NULL) |
if (dst1 != NULL) |
792 |
|
{ |
793 |
if (src == NULL) |
if (src == NULL) |
794 |
|
{ |
795 |
bitBlt(dst1, dx, dy, dst1, sx, sy, sw, sh, rop, im); |
bitBlt(dst1, dx, dy, dst1, sx, sy, sw, sh, rop, im); |
796 |
|
} |
797 |
else |
else |
798 |
|
{ |
799 |
bitBlt(dst1, dx, dy, src, sx, sy, sw, sh, rop, im); |
bitBlt(dst1, dx, dy, src, sx, sy, sw, sh, rop, im); |
800 |
|
} |
801 |
|
} |
802 |
if (dst2 != NULL) |
if (dst2 != NULL) |
803 |
|
{ |
804 |
if (src == NULL) |
if (src == NULL) |
805 |
|
{ |
806 |
bitBlt(dst2, dx, dy, dst2, sx, sy, sw, sh, rop, im); |
bitBlt(dst2, dx, dy, dst2, sx, sy, sw, sh, rop, im); |
807 |
|
} |
808 |
else |
else |
809 |
|
{ |
810 |
bitBlt(dst2, dx, dy, src, sx, sy, sw, sh, rop, im); |
bitBlt(dst2, dx, dy, src, sx, sy, sw, sh, rop, im); |
811 |
|
} |
812 |
|
} |
813 |
} |
} |
814 |
} |
} |
815 |
|
|
816 |
#define DO_GLYPH(ttext,idx) \ |
#define DO_GLYPH(ttext,idx) \ |
817 |
{\ |
{ \ |
818 |
glyph = cache_get_font (font, ttext[idx]);\ |
glyph = cache_get_font (font, ttext[idx]); \ |
819 |
if (!(flags & TEXT2_IMPLICIT_X))\ |
if (!(flags & TEXT2_IMPLICIT_X)) \ |
820 |
{\ |
{ \ |
821 |
xyoffset = ttext[++idx];\ |
xyoffset = ttext[++idx]; \ |
822 |
if ((xyoffset & 0x80))\ |
if ((xyoffset & 0x80)) \ |
823 |
{\ |
{ \ |
824 |
if (flags & TEXT2_VERTICAL) \ |
if (flags & TEXT2_VERTICAL) \ |
825 |
y += ttext[idx+1] | (ttext[idx+2] << 8);\ |
y += ttext[idx+1] | (ttext[idx+2] << 8); \ |
826 |
else\ |
else \ |
827 |
x += ttext[idx+1] | (ttext[idx+2] << 8);\ |
x += ttext[idx+1] | (ttext[idx+2] << 8); \ |
828 |
idx += 2;\ |
idx += 2; \ |
829 |
}\ |
} \ |
830 |
else\ |
else \ |
831 |
{\ |
{ \ |
832 |
if (flags & TEXT2_VERTICAL) \ |
if (flags & TEXT2_VERTICAL) \ |
833 |
y += xyoffset;\ |
y += xyoffset; \ |
834 |
else\ |
else \ |
835 |
x += xyoffset;\ |
x += xyoffset; \ |
836 |
}\ |
} \ |
837 |
}\ |
} \ |
838 |
if (glyph != NULL)\ |
if (glyph != NULL) \ |
839 |
{\ |
{ \ |
840 |
P2->drawPixmap(x + glyph->offset, y + glyph->baseline, *((QBitmap*)glyph->pixmap)); \ |
g_P2->drawPixmap(x + glyph->offset, y + glyph->baseline, \ |
841 |
if (flags & TEXT2_IMPLICIT_X)\ |
*((QBitmap*)glyph->pixmap)); \ |
842 |
x += glyph->width;\ |
if (flags & TEXT2_IMPLICIT_X) \ |
843 |
}\ |
x += glyph->width; \ |
844 |
|
} \ |
845 |
} |
} |
846 |
|
|
847 |
//***************************************************************************** |
//***************************************************************************** |
851 |
int boxy, int boxcx, int boxcy, BRUSH * brush, |
int boxy, int boxcx, int boxcy, BRUSH * brush, |
852 |
int bgcolour, int fgcolour, uint8 * text, uint8 length) |
int bgcolour, int fgcolour, uint8 * text, uint8 length) |
853 |
{ |
{ |
854 |
FONTGLYPH *glyph; |
FONTGLYPH * glyph; |
855 |
int i, j, xyoffset; |
int i, j, xyoffset; |
856 |
DATABLOB *entry; |
DATABLOB * entry; |
857 |
|
|
858 |
SetColorx(&Color1, fgcolour); |
SetColorx(&g_Color1, fgcolour); |
859 |
SetColorx(&Color2, bgcolour); |
SetColorx(&g_Color2, bgcolour); |
860 |
P2->setBackgroundColor(Color2); |
g_P2->setBackgroundColor(g_Color2); |
861 |
P2->setPen(Color1); |
g_P2->setPen(g_Color1); |
862 |
if (boxcx > 1) |
if (boxcx > 1) |
863 |
P2->fillRect(boxx, boxy, boxcx, boxcy, QBrush(Color2)); |
{ |
864 |
|
g_P2->fillRect(boxx, boxy, boxcx, boxcy, QBrush(g_Color2)); |
865 |
|
} |
866 |
else if (mixmode == MIX_OPAQUE) |
else if (mixmode == MIX_OPAQUE) |
867 |
P2->fillRect(clipx, clipy, clipcx, clipcy, QBrush(Color2)); |
{ |
868 |
|
g_P2->fillRect(clipx, clipy, clipcx, clipcy, QBrush(g_Color2)); |
869 |
|
} |
870 |
|
|
871 |
/* Paint text, character by character */ |
/* Paint text, character by character */ |
872 |
for (i = 0; i < length;) |
for (i = 0; i < length;) |
875 |
{ |
{ |
876 |
case 0xff: |
case 0xff: |
877 |
if (i + 2 < length) |
if (i + 2 < length) |
878 |
|
{ |
879 |
cache_put_text(text[i + 1], text, text[i + 2]); |
cache_put_text(text[i + 1], text, text[i + 2]); |
880 |
|
} |
881 |
else |
else |
882 |
{ |
{ |
883 |
error("this shouldn't be happening\n"); |
error("this shouldn't be happening\n"); |
884 |
exit(1); |
exit(1); |
885 |
} |
} |
886 |
/* this will move pointer from start to first character after FF command */ |
/* this will move pointer from start to first character after FF |
887 |
|
command */ |
888 |
length -= i + 3; |
length -= i + 3; |
889 |
text = &(text[i + 3]); |
text = &(text[i + 3]); |
890 |
i = 0; |
i = 0; |
894 |
entry = cache_get_text(text[i + 1]); |
entry = cache_get_text(text[i + 1]); |
895 |
if (entry != NULL) |
if (entry != NULL) |
896 |
{ |
{ |
897 |
if ((((uint8 *) (entry->data))[1] == 0) && (!(flags & TEXT2_IMPLICIT_X))) |
if ((((uint8 *) (entry->data))[1] == 0) && |
898 |
|
(!(flags & TEXT2_IMPLICIT_X))) |
899 |
{ |
{ |
900 |
if (flags & TEXT2_VERTICAL) |
if (flags & TEXT2_VERTICAL) |
901 |
|
{ |
902 |
y += text[i + 2]; |
y += text[i + 2]; |
903 |
|
} |
904 |
else |
else |
905 |
|
{ |
906 |
x += text[i + 2]; |
x += text[i + 2]; |
907 |
|
} |
908 |
} |
} |
909 |
for (j = 0; j < entry->size; j++) |
for (j = 0; j < entry->size; j++) |
910 |
|
{ |
911 |
DO_GLYPH(((uint8 *) (entry->data)), j); |
DO_GLYPH(((uint8 *) (entry->data)), j); |
912 |
|
} |
913 |
} |
} |
914 |
if (i + 2 < length) |
if (i + 2 < length) |
915 |
|
{ |
916 |
i += 3; |
i += 3; |
917 |
|
} |
918 |
else |
else |
919 |
|
{ |
920 |
i += 2; |
i += 2; |
921 |
|
} |
922 |
length -= i; |
length -= i; |
923 |
/* this will move pointer from start to first character after FE command */ |
/* this will move pointer from start to first character after FE |
924 |
|
command */ |
925 |
text = &(text[i]); |
text = &(text[i]); |
926 |
i = 0; |
i = 0; |
927 |
break; |
break; |
933 |
} |
} |
934 |
} |
} |
935 |
if (boxcx > 1) |
if (boxcx > 1) |
936 |
bitBltClip(g_MW, NULL, boxx, boxy, BS, boxx, boxy, boxcx, boxcy, Qt::CopyROP, true); |
{ |
937 |
|
bitBltClip(g_MW, NULL, boxx, boxy, g_BS, boxx, boxy, boxcx, boxcy, |
938 |
|
Qt::CopyROP, true); |
939 |
|
} |
940 |
else |
else |
941 |
bitBltClip(g_MW, NULL, clipx, clipy, BS, clipx, clipy, clipcx, clipcy, Qt::CopyROP, true); |
{ |
942 |
|
bitBltClip(g_MW, NULL, clipx, clipy, g_BS, clipx, clipy, clipcx, |
943 |
|
clipcy, Qt::CopyROP, true); |
944 |
|
} |
945 |
} |
} |
946 |
|
|
947 |
/*****************************************************************************/ |
/*****************************************************************************/ |
948 |
void ui_line(uint8 opcode, int startx, int starty, int endx, int endy, |
void ui_line(uint8 opcode, int startx, int starty, int endx, int endy, |
949 |
PEN* pen) |
PEN * pen) |
950 |
{ |
{ |
951 |
SetColorx(&Color1, pen->colour); |
SetColorx(&g_Color1, pen->colour); |
952 |
SetOpCode(opcode); |
SetOpCode(opcode); |
953 |
P1->setPen(Color1); |
g_P1->setPen(g_Color1); |
954 |
P1->moveTo(startx, starty); |
g_P1->moveTo(startx, starty); |
955 |
P1->lineTo(endx, endy); |
g_P1->lineTo(endx, endy); |
956 |
P2->setPen(Color1); |
g_P2->setPen(g_Color1); |
957 |
P2->moveTo(startx, starty); |
g_P2->moveTo(startx, starty); |
958 |
P2->lineTo(endx, endy); |
g_P2->lineTo(endx, endy); |
959 |
ResetOpCode(opcode); |
ResetOpCode(opcode); |
960 |
} |
} |
961 |
|
|
962 |
/*****************************************************************************/ |
/*****************************************************************************/ |
963 |
|
// not used |
964 |
void ui_triblt(uint8 opcode, int x, int y, int cx, int cy, |
void ui_triblt(uint8 opcode, int x, int y, int cx, int cy, |
965 |
HBITMAP src, int srcx, int srcy, |
HBITMAP src, int srcx, int srcy, |
966 |
BRUSH* brush, int bgcolour, int fgcolour) |
BRUSH* brush, int bgcolour, int fgcolour) |
976 |
if (Pixmap != NULL) |
if (Pixmap != NULL) |
977 |
{ |
{ |
978 |
SetOpCode(opcode); |
SetOpCode(opcode); |
979 |
P1->drawPixmap(x, y, *Pixmap, srcx, srcy, cx, cy); |
g_P1->drawPixmap(x, y, *Pixmap, srcx, srcy, cx, cy); |
980 |
P2->drawPixmap(x, y, *Pixmap, srcx, srcy, cx, cy); |
g_P2->drawPixmap(x, y, *Pixmap, srcx, srcy, cx, cy); |
981 |
ResetOpCode(opcode); |
ResetOpCode(opcode); |
982 |
} |
} |
983 |
} |
} |
1030 |
/*****************************************************************************/ |
/*****************************************************************************/ |
1031 |
void ui_desktop_restore(uint32 offset, int x, int y, int cx, int cy) |
void ui_desktop_restore(uint32 offset, int x, int y, int cx, int cy) |
1032 |
{ |
{ |
1033 |
QPixmap* Pixmap; |
QPixmap * Pixmap; |
1034 |
|
|
1035 |
Pixmap = new QPixmap(cx, cy); |
Pixmap = new QPixmap(cx, cy); |
1036 |
CommonDeskSave(DS, Pixmap, offset, 0, 0, cx, cy, 1); |
CommonDeskSave(g_DS, Pixmap, offset, 0, 0, cx, cy, 1); |
1037 |
bitBltClip(g_MW, BS, x, y, Pixmap, 0, 0, cx, cy, Qt::CopyROP, true); |
bitBltClip(g_MW, g_BS, x, y, Pixmap, 0, 0, cx, cy, Qt::CopyROP, true); |
1038 |
delete Pixmap; |
delete Pixmap; |
1039 |
} |
} |
1040 |
|
|
1041 |
/*****************************************************************************/ |
/*****************************************************************************/ |
1042 |
void ui_desktop_save(uint32 offset, int x, int y, int cx, int cy) |
void ui_desktop_save(uint32 offset, int x, int y, int cx, int cy) |
1043 |
{ |
{ |
1044 |
CommonDeskSave(DS, BS, offset, x, y, cx, cy, 0); |
CommonDeskSave(g_DS, g_BS, offset, x, y, cx, cy, 0); |
1045 |
} |
} |
1046 |
|
|
1047 |
/*****************************************************************************/ |
/*****************************************************************************/ |
1048 |
void ui_rect(int x, int y, int cx, int cy, int colour) |
void ui_rect(int x, int y, int cx, int cy, int colour) |
1049 |
{ |
{ |
1050 |
SetColorx(&Color1, colour); |
SetColorx(&g_Color1, colour); |
1051 |
P1->fillRect(x, y, cx, cy, QBrush(Color1)); |
g_P1->fillRect(x, y, cx, cy, QBrush(g_Color1)); |
1052 |
P2->fillRect(x, y, cx, cy, QBrush(Color1)); |
g_P2->fillRect(x, y, cx, cy, QBrush(g_Color1)); |
1053 |
} |
} |
1054 |
|
|
1055 |
/*****************************************************************************/ |
/*****************************************************************************/ |
1057 |
int srcx, int srcy) |
int srcx, int srcy) |
1058 |
{ |
{ |
1059 |
SetOpCode(opcode); |
SetOpCode(opcode); |
1060 |
bitBltClip(g_MW, BS, x, y, NULL, srcx, srcy, cx, cy, Qt::CopyROP, true); |
bitBltClip(g_MW, g_BS, x, y, NULL, srcx, srcy, cx, cy, Qt::CopyROP, true); |
1061 |
ResetOpCode(opcode); |
ResetOpCode(opcode); |
1062 |
} |
} |
1063 |
|
|
1072 |
switch (brush->style) |
switch (brush->style) |
1073 |
{ |
{ |
1074 |
case 0: |
case 0: |
1075 |
SetColorx(&Color1, fgcolour); |
SetColorx(&g_Color1, fgcolour); |
1076 |
P2->fillRect(x, y, cx, cy, QBrush(Color1)); |
g_P2->fillRect(x, y, cx, cy, QBrush(g_Color1)); |
1077 |
break; |
break; |
1078 |
case 3: |
case 3: |
1079 |
SetColorx(&Color1, fgcolour); |
SetColorx(&g_Color1, fgcolour); |
1080 |
SetColorx(&Color2, bgcolour); |
SetColorx(&g_Color2, bgcolour); |
1081 |
for (i = 0; i != 8; i++) |
for (i = 0; i != 8; i++) |
1082 |
|
{ |
1083 |
ipattern[7 - i] = ~brush->pattern[i]; |
ipattern[7 - i] = ~brush->pattern[i]; |
1084 |
|
} |
1085 |
Bitmap = new QBitmap(8, 8, ipattern); |
Bitmap = new QBitmap(8, 8, ipattern); |
1086 |
Brush = new QBrush(Color1, *Bitmap); |
Brush = new QBrush(g_Color1, *Bitmap); |
1087 |
P2->setBackgroundMode(Qt::OpaqueMode); |
g_P2->setBackgroundMode(Qt::OpaqueMode); |
1088 |
P2->setBrushOrigin(brush->xorigin, brush->yorigin); |
g_P2->setBrushOrigin(brush->xorigin, brush->yorigin); |
1089 |
P2->setBackgroundColor(Color2); |
g_P2->setBackgroundColor(g_Color2); |
1090 |
P2->fillRect(x, y, cx, cy, *Brush); |
g_P2->fillRect(x, y, cx, cy, *Brush); |
1091 |
delete Brush; |
delete Brush; |
1092 |
delete Bitmap; |
delete Bitmap; |
1093 |
P2->setBackgroundMode(Qt::TransparentMode); |
g_P2->setBackgroundMode(Qt::TransparentMode); |
1094 |
P2->setBrushOrigin(0, 0); |
g_P2->setBrushOrigin(0, 0); |
1095 |
break; |
break; |
1096 |
} |
} |
1097 |
ResetOpCode(opcode); |
ResetOpCode(opcode); |
1098 |
bitBltClip(g_MW, NULL, x, y, BS, x, y, cx, cy, Qt::CopyROP, true); |
bitBltClip(g_MW, NULL, x, y, g_BS, x, y, cx, cy, Qt::CopyROP, true); |
1099 |
} |
} |
1100 |
|
|
1101 |
/*****************************************************************************/ |
/*****************************************************************************/ |
1102 |
void ui_destblt(uint8 opcode, int x, int y, int cx, int cy) |
void ui_destblt(uint8 opcode, int x, int y, int cx, int cy) |
1103 |
{ |
{ |
1104 |
SetOpCode(opcode); |
SetOpCode(opcode); |
1105 |
P1->fillRect(x, y, cx, cy, QBrush(QColor("black"))); |
g_P1->fillRect(x, y, cx, cy, QBrush(QColor("black"))); |
1106 |
P2->fillRect(x, y, cx, cy, QBrush(QColor("black"))); |
g_P2->fillRect(x, y, cx, cy, QBrush(QColor("black"))); |
1107 |
ResetOpCode(opcode); |
ResetOpCode(opcode); |
1108 |
} |
} |
1109 |
|
|
1122 |
void ui_paint_bitmap(int x, int y, int cx, int cy, |
void ui_paint_bitmap(int x, int y, int cx, int cy, |
1123 |
int width, int height, uint8* data) |
int width, int height, uint8* data) |
1124 |
{ |
{ |
1125 |
QImage* Image = NULL; |
QImage * Image = NULL; |
1126 |
QPixmap* Pixmap; |
QPixmap * Pixmap; |
1127 |
uint32* d = NULL; |
uint32 * d = NULL; |
1128 |
uint16* s; |
uint16 * s; |
1129 |
|
int i; |
1130 |
|
|
1131 |
switch (g_server_bpp) |
switch (g_server_bpp) |
1132 |
{ |
{ |
1133 |
case 8: |
case 8: |
1134 |
Image = new QImage(data, width, height, 8, (QRgb*)&CM->RGBColors, |
Image = new QImage(data, width, height, 8, (QRgb*)&g_CM->RGBColors, |
1135 |
CM->NumColors, QImage::IgnoreEndian); |
g_CM->NumColors, QImage::IgnoreEndian); |
1136 |
break; |
break; |
1137 |
case 15: |
case 15: |
1138 |
d = (uint32*)malloc(width * height * 4); |
d = (uint32*)malloc(width * height * 4); |
1139 |
s = (uint16*)data; |
s = (uint16*)data; |
1140 |
for (int i = 0; i < width * height; i++) |
for (i = 0; i < width * height; i++) |
1141 |
|
{ |
1142 |
d[i] = Color15to32(s[i]); |
d[i] = Color15to32(s[i]); |
1143 |
|
} |
1144 |
Image = new QImage((uint8*)d, width, height, 32, NULL, |
Image = new QImage((uint8*)d, width, height, 32, NULL, |
1145 |
0, QImage::IgnoreEndian); |
0, QImage::IgnoreEndian); |
1146 |
break; |
break; |
1147 |
case 16: |
case 16: |
1148 |
d = (uint32*)malloc(width * height * 4); |
d = (uint32*)malloc(width * height * 4); |
1149 |
s = (uint16*)data; |
s = (uint16*)data; |
1150 |
for (int i = 0; i < width * height; i++) |
for (i = 0; i < width * height; i++) |
1151 |
|
{ |
1152 |
d[i] = Color16to32(s[i]); |
d[i] = Color16to32(s[i]); |
1153 |
|
} |
1154 |
Image = new QImage((uint8*)d, width, height, 32, NULL, |
Image = new QImage((uint8*)d, width, height, 32, NULL, |
1155 |
0, QImage::IgnoreEndian); |
0, QImage::IgnoreEndian); |
1156 |
break; |
break; |
1157 |
case 24: |
case 24: |
1158 |
d = (uint32*)malloc(width * height * 4); |
d = (uint32*)malloc(width * height * 4); |
1159 |
memset(d, 0, width * height * 4); |
memset(d, 0, width * height * 4); |
1160 |
for (int i = 0; i < width * height; i++) |
for (i = 0; i < width * height; i++) |
1161 |
|
{ |
1162 |
memcpy(d + i, data + i * 3, 3); |
memcpy(d + i, data + i * 3, 3); |
1163 |
|
} |
1164 |
Image = new QImage((uint8*)d, width, height, 32, NULL, |
Image = new QImage((uint8*)d, width, height, 32, NULL, |
1165 |
0, QImage::IgnoreEndian); |
0, QImage::IgnoreEndian); |
1166 |
break; |
break; |
1167 |
} |
} |
1168 |
if (Image == NULL) |
if (Image == NULL) |
1169 |
|
{ |
1170 |
return; |
return; |
1171 |
|
} |
1172 |
Pixmap = new QPixmap(); |
Pixmap = new QPixmap(); |
1173 |
Pixmap->convertFromImage(*Image); |
Pixmap->convertFromImage(*Image); |
1174 |
P1->drawPixmap(x, y, *Pixmap, 0, 0, cx, cy); |
g_P1->drawPixmap(x, y, *Pixmap, 0, 0, cx, cy); |
1175 |
P2->drawPixmap(x, y, *Pixmap, 0, 0, cx, cy); |
g_P2->drawPixmap(x, y, *Pixmap, 0, 0, cx, cy); |
1176 |
delete Image; |
delete Image; |
1177 |
delete Pixmap; |
delete Pixmap; |
1178 |
if (d != NULL) |
if (d != NULL) |
1179 |
|
{ |
1180 |
free(d); |
free(d); |
1181 |
|
} |
1182 |
} |
} |
1183 |
|
|
1184 |
//****************************************************************************** |
//****************************************************************************** |
1185 |
BOOL Is24On(uint8* Data, int X, int Y) |
int Is24On(uint8* Data, int X, int Y) |
1186 |
{ |
{ |
1187 |
uint8 R, G, B; |
uint8 R, G, B; |
1188 |
int Start; |
int Start; |
1194 |
} |
} |
1195 |
|
|
1196 |
//****************************************************************************** |
//****************************************************************************** |
1197 |
BOOL Is1On(uint8* Data, int X, int Y) |
int Is1On(uint8* Data, int X, int Y) |
1198 |
{ |
{ |
1199 |
int Start; |
int Start; |
1200 |
int Shift; |
int Shift; |
1247 |
QBitmap* DataBitmap; |
QBitmap* DataBitmap; |
1248 |
QBitmap* MaskBitmap; |
QBitmap* MaskBitmap; |
1249 |
QCursor* Cursor; |
QCursor* Cursor; |
1250 |
int I1; |
int I1, I2, BOn, MOn; |
1251 |
int I2; |
|
|
BOOL BOn; |
|
|
BOOL MOn; |
|
1252 |
if (width != 32 || height != 32) |
if (width != 32 || height != 32) |
1253 |
|
{ |
1254 |
return 0; |
return 0; |
1255 |
|
} |
1256 |
memset(AData, 0, 128); |
memset(AData, 0, 128); |
1257 |
memset(AMask, 0, 128); |
memset(AMask, 0, 128); |
1258 |
for (I1 = 0; I1 <= 31; I1++) |
for (I1 = 0; I1 <= 31; I1++) |
1259 |
|
{ |
1260 |
for (I2 = 0; I2 <= 31; I2++) |
for (I2 = 0; I2 <= 31; I2++) |
1261 |
{ |
{ |
1262 |
MOn = Is24On(xormask, I1, I2); |
MOn = Is24On(xormask, I1, I2); |
1265 |
{ |
{ |
1266 |
Set1(AData, I1, I2); |
Set1(AData, I1, I2); |
1267 |
if (!MOn) |
if (!MOn) |
1268 |
|
{ |
1269 |
Set1(AMask, I1, I2); |
Set1(AMask, I1, I2); |
1270 |
|
} |
1271 |
} |
} |
1272 |
if (MOn) |
if (MOn) |
1273 |
|
{ |
1274 |
Set1(AMask, I1, I2); |
Set1(AMask, I1, I2); |
1275 |
|
} |
1276 |
} |
} |
1277 |
|
} |
1278 |
FlipOver(AData); |
FlipOver(AData); |
1279 |
FlipOver(AMask); |
FlipOver(AMask); |
1280 |
DataBitmap = new QBitmap(32, 32, AData); |
DataBitmap = new QBitmap(32, 32, AData); |
1286 |
} |
} |
1287 |
|
|
1288 |
/*****************************************************************************/ |
/*****************************************************************************/ |
1289 |
uint16 ui_get_numlock_state(unsigned int state) |
uint16 ui_get_numlock_state(uint32 state) |
1290 |
{ |
{ |
1291 |
return 0; |
return 0; |
1292 |
} |
} |
1293 |
|
|
1294 |
/*****************************************************************************/ |
/*****************************************************************************/ |
1295 |
unsigned int read_keyboard_state(void) |
uint32 read_keyboard_state(void) |
1296 |
{ |
{ |
1297 |
return 0; |
return 0; |
1298 |
} |
} |
1313 |
void ui_polyline(uint8 opcode, POINT * points, int npoints, PEN * pen) |
void ui_polyline(uint8 opcode, POINT * points, int npoints, PEN * pen) |
1314 |
{ |
{ |
1315 |
int i, x, y, dx, dy; |
int i, x, y, dx, dy; |
1316 |
|
|
1317 |
if (npoints > 0) |
if (npoints > 0) |
1318 |
{ |
{ |
1319 |
x = points[0].x; |
x = points[0].x; |
1337 |
} |
} |
1338 |
|
|
1339 |
/*****************************************************************************/ |
/*****************************************************************************/ |
1340 |
void generate_random(uint8* random) |
void generate_random(uint8 * random) |
1341 |
{ |
{ |
1342 |
QFile File("/dev/random"); |
QFile File("/dev/random"); |
1343 |
File.open(IO_ReadOnly); |
File.open(IO_ReadOnly); |
1344 |
if (File.readBlock((char*)random, 32) == 32) |
if (File.readBlock((char*)random, 32) == 32) |
1345 |
|
{ |
1346 |
return; |
return; |
1347 |
|
} |
1348 |
warning("no /dev/random\n"); |
warning("no /dev/random\n"); |
1349 |
memcpy(random, "12345678901234567890123456789012", 32); |
memcpy(random, "12345678901234567890123456789012", 32); |
1350 |
} |
} |
1351 |
|
|
1352 |
/*****************************************************************************/ |
/*****************************************************************************/ |
1353 |
void save_licence(uint8* data, int length) |
void save_licence(uint8 * data, int length) |
1354 |
{ |
{ |
1355 |
|
char * home, * path, * tmppath; |
1356 |
|
int fd; |
1357 |
|
|
1358 |
|
home = getenv("HOME"); |
1359 |
|
if (home == NULL) |
1360 |
|
{ |
1361 |
|
return; |
1362 |
|
} |
1363 |
|
path = (char *) xmalloc(strlen(home) + strlen(g_hostname) + |
1364 |
|
sizeof("/.rdesktop/licence.")); |
1365 |
|
sprintf(path, "%s/.rdesktop", home); |
1366 |
|
if ((mkdir(path, 0700) == -1) && errno != EEXIST) |
1367 |
|
{ |
1368 |
|
perror(path); |
1369 |
|
return; |
1370 |
|
} |
1371 |
|
/* write licence to licence.hostname.new, then atomically rename to |
1372 |
|
licence.hostname */ |
1373 |
|
sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname); |
1374 |
|
tmppath = (char *) xmalloc(strlen(path) + sizeof(".new")); |
1375 |
|
strcpy(tmppath, path); |
1376 |
|
strcat(tmppath, ".new"); |
1377 |
|
fd = open(tmppath, O_WRONLY | O_CREAT | O_TRUNC, 0600); |
1378 |
|
if (fd == -1) |
1379 |
|
{ |
1380 |
|
perror(tmppath); |
1381 |
|
return; |
1382 |
|
} |
1383 |
|
if (write(fd, data, length) != length) |
1384 |
|
{ |
1385 |
|
perror(tmppath); |
1386 |
|
unlink(tmppath); |
1387 |
|
} |
1388 |
|
else if (rename(tmppath, path) == -1) |
1389 |
|
{ |
1390 |
|
perror(path); |
1391 |
|
unlink(tmppath); |
1392 |
|
} |
1393 |
|
close(fd); |
1394 |
|
xfree(tmppath); |
1395 |
|
xfree(path); |
1396 |
} |
} |
1397 |
|
|
1398 |
/*****************************************************************************/ |
/*****************************************************************************/ |
1399 |
int load_licence(uint8** data) |
int load_licence(uint8 ** data) |
1400 |
{ |
{ |
1401 |
return 0; |
char * home, * path; |
1402 |
|
struct stat st; |
1403 |
|
int fd, length; |
1404 |
|
|
1405 |
|
home = getenv("HOME"); |
1406 |
|
if (home == NULL) |
1407 |
|
{ |
1408 |
|
return -1; |
1409 |
|
} |
1410 |
|
path = (char *) xmalloc(strlen(home) + strlen(g_hostname) + |
1411 |
|
sizeof("/.rdesktop/licence.")); |
1412 |
|
sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname); |
1413 |
|
fd = open(path, O_RDONLY); |
1414 |
|
if (fd == -1) |
1415 |
|
{ |
1416 |
|
return -1; |
1417 |
|
} |
1418 |
|
if (fstat(fd, &st)) |
1419 |
|
{ |
1420 |
|
return -1; |
1421 |
|
} |
1422 |
|
*data = (uint8 *) xmalloc(st.st_size); |
1423 |
|
length = read(fd, *data, st.st_size); |
1424 |
|
close(fd); |
1425 |
|
xfree(path); |
1426 |
|
return length; |
1427 |
} |
} |
1428 |
|
|
1429 |
/*****************************************************************************/ |
/*****************************************************************************/ |
1430 |
void* xrealloc(void* in_val, int size) |
void* xrealloc(void * in_val, int size) |
1431 |
{ |
{ |
1432 |
return realloc(in_val, size); |
return realloc(in_val, size); |
1433 |
} |
} |
1439 |
} |
} |
1440 |
|
|
1441 |
/*****************************************************************************/ |
/*****************************************************************************/ |
1442 |
void xfree(void* in_val) |
void xfree(void * in_val) |
1443 |
{ |
{ |
1444 |
free(in_val); |
if (in_val != NULL) |
1445 |
|
{ |
1446 |
|
free(in_val); |
1447 |
|
} |
1448 |
} |
} |
1449 |
|
|
1450 |
/*****************************************************************************/ |
/*****************************************************************************/ |
1451 |
void warning(char* format, ...) |
void warning(char * format, ...) |
1452 |
{ |
{ |
1453 |
va_list ap; |
va_list ap; |
1454 |
|
|
1459 |
} |
} |
1460 |
|
|
1461 |
/*****************************************************************************/ |
/*****************************************************************************/ |
1462 |
void unimpl(char* format, ...) |
void unimpl(char * format, ...) |
1463 |
{ |
{ |
1464 |
va_list ap; |
va_list ap; |
1465 |
|
|
1470 |
} |
} |
1471 |
|
|
1472 |
/*****************************************************************************/ |
/*****************************************************************************/ |
1473 |
void error(char* format, ...) |
void error(char * format, ...) |
1474 |
{ |
{ |
1475 |
va_list ap; |
va_list ap; |
1476 |
|
|
1484 |
void out_params(void) |
void out_params(void) |
1485 |
{ |
{ |
1486 |
fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n"); |
fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n"); |
1487 |
fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2003 Matt Chapman.\n"); |
fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2005 Matt Chapman.\n"); |
1488 |
|
fprintf(stderr, "QT uiport by Jay Sorg\n"); |
1489 |
fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n"); |
fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n"); |
1490 |
fprintf(stderr, "Usage: qtrdesktop [options] server\n"); |
fprintf(stderr, "Usage: qtrdesktop [options] server\n"); |
1491 |
fprintf(stderr, " -g: desktop geometry (WxH)\n"); |
fprintf(stderr, " -g: desktop geometry (WxH)\n"); |
1494 |
fprintf(stderr, " -t: tcp port)\n"); |
fprintf(stderr, " -t: tcp port)\n"); |
1495 |
fprintf(stderr, " -a: connection colour depth\n"); |
fprintf(stderr, " -a: connection colour depth\n"); |
1496 |
fprintf(stderr, " -T: window title\n"); |
fprintf(stderr, " -T: window title\n"); |
1497 |
|
fprintf(stderr, " -P: use persistent bitmap caching\n"); |
1498 |
|
fprintf(stderr, " -0: attach to console\n"); |
1499 |
|
fprintf(stderr, " -z: enable rdp compression\n"); |
1500 |
fprintf(stderr, "\n"); |
fprintf(stderr, "\n"); |
1501 |
} |
} |
1502 |
|
|
1503 |
/*****************************************************************************/ |
/*****************************************************************************/ |
1504 |
/* produce a hex dump */ |
/* produce a hex dump */ |
1505 |
void hexdump(unsigned char *p, unsigned int len) |
void hexdump(uint8 * p, uint32 len) |
1506 |
{ |
{ |
1507 |
unsigned char *line = p; |
uint8 * line = p; |
1508 |
int i, thisline; |
int i, thisline; |
1509 |
unsigned int offset = 0; |
uint32 offset = 0; |
1510 |
|
|
1511 |
while (offset < len) |
while (offset < len) |
1512 |
{ |
{ |
1513 |
printf("%04x ", offset); |
printf("%04x ", offset); |
1514 |
thisline = len - offset; |
thisline = len - offset; |
1515 |
if (thisline > 16) |
if (thisline > 16) |
1516 |
|
{ |
1517 |
thisline = 16; |
thisline = 16; |
1518 |
|
} |
1519 |
for (i = 0; i < thisline; i++) |
for (i = 0; i < thisline; i++) |
1520 |
|
{ |
1521 |
printf("%02x ", line[i]); |
printf("%02x ", line[i]); |
1522 |
|
} |
1523 |
for (; i < 16; i++) |
for (; i < 16; i++) |
1524 |
|
{ |
1525 |
printf(" "); |
printf(" "); |
1526 |
|
} |
1527 |
for (i = 0; i < thisline; i++) |
for (i = 0; i < thisline; i++) |
1528 |
|
{ |
1529 |
printf("%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.'); |
printf("%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.'); |
1530 |
|
} |
1531 |
printf("\n"); |
printf("\n"); |
1532 |
offset += thisline; |
offset += thisline; |
1533 |
line += thisline; |
line += thisline; |
1534 |
} |
} |
1535 |
} |
} |
1536 |
|
|
1537 |
BOOL rd_pstcache_mkdir(void) |
/*****************************************************************************/ |
1538 |
|
int rd_pstcache_mkdir(void) |
1539 |
{ |
{ |
1540 |
return 0; |
char * home; |
1541 |
|
char bmpcache_dir[256]; |
1542 |
|
|
1543 |
|
home = getenv("HOME"); |
1544 |
|
if (home == NULL) |
1545 |
|
{ |
1546 |
|
return False; |
1547 |
|
} |
1548 |
|
sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop"); |
1549 |
|
if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST) |
1550 |
|
{ |
1551 |
|
perror(bmpcache_dir); |
1552 |
|
return False; |
1553 |
|
} |
1554 |
|
sprintf(bmpcache_dir, "%s/%s", home, ".rdesktop/cache"); |
1555 |
|
if ((mkdir(bmpcache_dir, S_IRWXU) == -1) && errno != EEXIST) |
1556 |
|
{ |
1557 |
|
perror(bmpcache_dir); |
1558 |
|
return False; |
1559 |
|
} |
1560 |
|
return True; |
1561 |
} |
} |
1562 |
|
|
1563 |
/*****************************************************************************/ |
/*****************************************************************************/ |
1564 |
int rd_open_file(char *filename) |
int rd_open_file(char * filename) |
1565 |
{ |
{ |
1566 |
return 0; |
char * home; |
1567 |
|
char fn[256]; |
1568 |
|
int fd; |
1569 |
|
|
1570 |
|
home = getenv("HOME"); |
1571 |
|
if (home == NULL) |
1572 |
|
{ |
1573 |
|
return -1; |
1574 |
|
} |
1575 |
|
sprintf(fn, "%s/.rdesktop/%s", home, filename); |
1576 |
|
fd = open(fn, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); |
1577 |
|
if (fd == -1) |
1578 |
|
{ |
1579 |
|
perror(fn); |
1580 |
|
} |
1581 |
|
return fd; |
1582 |
} |
} |
1583 |
|
|
1584 |
/*****************************************************************************/ |
/*****************************************************************************/ |
1585 |
void rd_close_file(int fd) |
void rd_close_file(int fd) |
1586 |
{ |
{ |
1587 |
return; |
close(fd); |
1588 |
} |
} |
1589 |
|
|
1590 |
/*****************************************************************************/ |
/*****************************************************************************/ |
1591 |
int rd_read_file(int fd, void *ptr, int len) |
int rd_read_file(int fd, void * ptr, int len) |
1592 |
{ |
{ |
1593 |
return 0; |
return read(fd, ptr, len); |
1594 |
} |
} |
1595 |
|
|
1596 |
/*****************************************************************************/ |
/*****************************************************************************/ |
1597 |
int rd_write_file(int fd, void* ptr, int len) |
int rd_write_file(int fd, void * ptr, int len) |
1598 |
{ |
{ |
1599 |
return 0; |
return write(fd, ptr, len); |
1600 |
} |
} |
1601 |
|
|
1602 |
/*****************************************************************************/ |
/*****************************************************************************/ |
1603 |
int rd_lseek_file(int fd, int offset) |
int rd_lseek_file(int fd, int offset) |
1604 |
{ |
{ |
1605 |
return 0; |
return lseek(fd, offset, SEEK_SET); |
1606 |
} |
} |
1607 |
|
|
1608 |
/*****************************************************************************/ |
/*****************************************************************************/ |
1609 |
BOOL rd_lock_file(int fd, int start, int len) |
int rd_lock_file(int fd, int start, int len) |
1610 |
{ |
{ |
1611 |
return False; |
struct flock lock; |
1612 |
|
|
1613 |
|
lock.l_type = F_WRLCK; |
1614 |
|
lock.l_whence = SEEK_SET; |
1615 |
|
lock.l_start = start; |
1616 |
|
lock.l_len = len; |
1617 |
|
if (fcntl(fd, F_SETLK, &lock) == -1) |
1618 |
|
{ |
1619 |
|
return False; |
1620 |
|
} |
1621 |
|
return True; |
1622 |
} |
} |
1623 |
|
|
1624 |
/*****************************************************************************/ |
/*****************************************************************************/ |
1625 |
void get_username_and_hostname(void) |
void get_username_and_hostname(void) |
1626 |
{ |
{ |
1627 |
char fullhostname[64]; |
char fullhostname[64]; |
1628 |
char* p; |
char * p; |
1629 |
struct passwd* pw; |
struct passwd * pw; |
1630 |
|
|
1631 |
STRNCPY(g_username, "unknown", sizeof(g_username)); |
STRNCPY(g_username, "unknown", sizeof(g_username)); |
1632 |
STRNCPY(g_hostname, "unknown", sizeof(g_hostname)); |
STRNCPY(g_hostname, "unknown", sizeof(g_hostname)); |
1639 |
{ |
{ |
1640 |
p = strchr(fullhostname, '.'); |
p = strchr(fullhostname, '.'); |
1641 |
if (p != NULL) |
if (p != NULL) |
1642 |
|
{ |
1643 |
*p = 0; |
*p = 0; |
1644 |
|
} |
1645 |
STRNCPY(g_hostname, fullhostname, sizeof(g_hostname)); |
STRNCPY(g_hostname, fullhostname, sizeof(g_hostname)); |
1646 |
} |
} |
1647 |
} |
} |
1648 |
|
|
1649 |
/*****************************************************************************/ |
/*****************************************************************************/ |
1650 |
int parse_parameters(int in_argc, char** in_argv) |
int parse_parameters(int in_argc, char ** in_argv) |
1651 |
{ |
{ |
1652 |
int i; |
int i; |
1653 |
char* p; |
char * p; |
1654 |
|
|
1655 |
if (in_argc <= 1) |
if (in_argc <= 1) |
1656 |
{ |
{ |
1671 |
return 0; |
return 0; |
1672 |
} |
} |
1673 |
if (*p == 'x') |
if (*p == 'x') |
1674 |
|
{ |
1675 |
g_height = strtol(p + 1, NULL, 10); |
g_height = strtol(p + 1, NULL, 10); |
1676 |
|
} |
1677 |
if (g_height <= 0) |
if (g_height <= 0) |
1678 |
{ |
{ |
1679 |
error("invalid geometry\n"); |
error("invalid geometry\n"); |
1682 |
g_width = (g_width + 3) & ~3; |
g_width = (g_width + 3) & ~3; |
1683 |
} |
} |
1684 |
else if (strcmp(in_argv[i], "-T") == 0) |
else if (strcmp(in_argv[i], "-T") == 0) |
1685 |
|
{ |
1686 |
strcpy(g_title, in_argv[i + 1]); |
strcpy(g_title, in_argv[i + 1]); |
1687 |
|
} |
1688 |
else if (strcmp(in_argv[i], "-4") == 0) |
else if (strcmp(in_argv[i], "-4") == 0) |
1689 |
|
{ |
1690 |
g_use_rdp5 = 0; |
g_use_rdp5 = 0; |
1691 |
|
} |
1692 |
else if (strcmp(in_argv[i], "-5") == 0) |
else if (strcmp(in_argv[i], "-5") == 0) |
1693 |
|
{ |
1694 |
g_use_rdp5 = 1; |
g_use_rdp5 = 1; |
1695 |
|
} |
1696 |
else if (strcmp(in_argv[i], "-a") == 0) |
else if (strcmp(in_argv[i], "-a") == 0) |
1697 |
{ |
{ |
1698 |
g_server_bpp = strtol(in_argv[i + 1], &p, 10); |
g_server_bpp = strtol(in_argv[i + 1], &p, 10); |
1704 |
} |
} |
1705 |
} |
} |
1706 |
else if (strcmp(in_argv[i], "-t") == 0) |
else if (strcmp(in_argv[i], "-t") == 0) |
1707 |
|
{ |
1708 |
g_tcp_port_rdp = strtol(in_argv[i + 1], &p, 10); |
g_tcp_port_rdp = strtol(in_argv[i + 1], &p, 10); |
1709 |
|
} |
1710 |
|
else if (strcmp(in_argv[i], "-P") == 0) |
1711 |
|
{ |
1712 |
|
g_bitmap_cache_persist_enable = 1; |
1713 |
|
} |
1714 |
|
else if (strcmp(in_argv[i], "-0") == 0) |
1715 |
|
{ |
1716 |
|
g_console_session = 1; |
1717 |
|
} |
1718 |
|
else if (strcmp(in_argv[i], "-z") == 0) |
1719 |
|
{ |
1720 |
|
g_flags |= RDP_COMPRESSION; |
1721 |
|
} |
1722 |
} |
} |
1723 |
return 1; |
return 1; |
1724 |
} |
} |
1728 |
{ |
{ |
1729 |
get_username_and_hostname(); |
get_username_and_hostname(); |
1730 |
if (!parse_parameters(in_argc, in_argv)) |
if (!parse_parameters(in_argc, in_argv)) |
1731 |
|
{ |
1732 |
return 0; |
return 0; |
1733 |
|
} |
1734 |
if (!ui_init()) |
if (!ui_init()) |
1735 |
|
{ |
1736 |
return 1; |
return 1; |
1737 |
|
} |
1738 |
if (!ui_create_window()) |
if (!ui_create_window()) |
1739 |
|
{ |
1740 |
return 1; |
return 1; |
1741 |
|
} |
1742 |
ui_main_loop(); |
ui_main_loop(); |
1743 |
ui_destroy_window(); |
ui_destroy_window(); |
1744 |
ui_deinit(); |
ui_deinit(); |