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