📄 qtwin.cpp
字号:
QRect Rect;
Rect = pe->rect();
bitBlt(this, Rect.left(), Rect.top(), g_BS, Rect.left(), Rect.top(),
Rect.width(), Rect.height());
}
//*****************************************************************************
void QMyMainWindow::closeEvent(QCloseEvent * e)
{
e->accept();
}
//*****************************************************************************
bool QMyMainWindow::event(QEvent * e)
{
return QWidget::event(e);
}
//*****************************************************************************
void QMyMainWindow::dataReceived()
{
if (!rdp_loop(&g_deactivated, &g_ext_disc_reason))
{
g_SV->close();
}
#ifdef WITH_RDPSND
if (g_dsp_busy)
{
if (g_SoundNotifier == 0)
{
g_SoundNotifier = new QSocketNotifier(g_dsp_fd, QSocketNotifier::Write,
g_MW);
g_MW->connect(g_SoundNotifier, SIGNAL(activated(int)), g_MW,
SLOT(soundSend()));
}
else
{
if (!g_SoundNotifier->isEnabled())
{
g_SoundNotifier->setEnabled(true);
}
}
}
#endif
}
/******************************************************************************/
void QMyMainWindow::soundSend()
{
#ifdef WITH_RDPSND
g_SoundNotifier->setEnabled(false);
wave_out_play();
if (g_dsp_busy)
{
g_SoundNotifier->setEnabled(true);
}
#endif
}
//*****************************************************************************
void QMyScrollView::keyPressEvent(QKeyEvent * e)
{
g_MW->keyPressEvent(e);
}
//*****************************************************************************
void QMyScrollView::keyReleaseEvent(QKeyEvent * e)
{
g_MW->keyReleaseEvent(e);
}
//*****************************************************************************
void ui_begin_update(void)
{
g_P1->begin(g_MW);
g_P2->begin(g_BS);
}
//*****************************************************************************
void ui_end_update(void)
{
g_P1->end();
g_P2->end();
}
/*****************************************************************************/
int ui_init(void)
{
g_App = new QApplication(g_argc, g_argv);
return 1;
}
/*****************************************************************************/
void ui_deinit(void)
{
delete g_App;
}
/*****************************************************************************/
int ui_create_window(void)
{
int w, h;
QPainter * painter;
QWidget * desktop;
g_MW = new QMyMainWindow();
g_SV = new QMyScrollView();
g_SV->addChild(g_MW);
g_BS = new QPixmap(g_width, g_height);
painter = new QPainter(g_BS);
painter->fillRect(0, 0, g_width, g_height, QBrush(QColor("white")));
painter->fillRect(0, 0, g_width, g_height, QBrush(QBrush::CrossPattern));
delete painter;
g_DS = new QPixmap(480, 480);
g_P1 = new QPainter();
g_P2 = new QPainter();
g_ClipRect = new QRegion(0, 0, g_width, g_height);
desktop = QApplication::desktop();
w = desktop->width(); // returns screen width
h = desktop->height(); // returns screen height
g_MW->resize(g_width, g_height);
if (w < g_width || h < g_height)
{
g_SV->resize(w, h);
}
else
{
g_SV->resize(g_width + 4, g_height + 4);
}
g_SV->setMaximumWidth(g_width + 4);
g_SV->setMaximumHeight(g_height + 4);
g_App->setMainWidget(g_SV);
g_SV->show();
g_MW->setMouseTracking(true);
if (g_title[0] != 0)
{
g_SV->setCaption(g_title);
}
/* XGrayKey(0, 64, AnyModifie, SV->winId(), 0, GrabModeAsync, GrabModeAsync);
XGrayKey(0, 113, AnyModifie, SV->winId(), 0, GrabModeAsync, GrabModeAsync);
XGrayKey(0, 37, AnyModifie, SV-winId(), 0, GrabModeAsync, GrabModeAsync);
XGrayKey(0, 109, AnyModifie, SV->winId(), 0, GrabModeAsync, GrabModeAsync);
XGrayKey(0, 115, AnyModifie, SV->winId(), 0, GrabModeAsync, GrabModeAsync);
XGrayKey(0, 116, AnyModifie, SV->winId(), 0, GrabModeAsync, GrabModeAsync);
XGrayKey(0, 117, AnyModifie, SV->winId(), 0, GrabModeAsync, GrabModeAsync);
XGrayKey(0, 62, AnyModifie, SV->winId(), 0, GrabModeAsync, GrabModeAsync);
XGrayKey(0, 50, AnyModifie, SV->winId(), 0, GrabModeAsync, GrabModeAsync);*/
return 1;
}
//*****************************************************************************
void ui_main_loop(void)
{
#ifdef WITH_RDPSND
// init sound
if (g_rdpsnd)
{
rdpsnd_init();
}
#endif
// connect
if (!rdp_connect(g_servername, g_flags, "", "", "", ""))
{
return;
}
// start notifier
g_SocketNotifier = new QSocketNotifier(g_sock, QSocketNotifier::Read, g_MW);
g_MW->connect(g_SocketNotifier, SIGNAL(activated(int)),
g_MW, SLOT(dataReceived()));
g_UpAndRunning = 1;
// app main loop
g_App->exec();
}
//*****************************************************************************
void ui_destroy_window(void)
{
delete g_MW;
delete g_SV;
delete g_BS;
delete g_DS;
delete g_P1;
delete g_P2;
delete g_ClipRect;
}
/*****************************************************************************/
void ui_bell(void)
{
}
/*****************************************************************************/
int ui_select(int in_val)
{
if (g_sock == 0)
{
g_sock = in_val;
}
return 1;
}
/*****************************************************************************/
void ui_destroy_cursor(void * cursor)
{
QCursor * Cursor;
Cursor = (QCursor*)cursor;
if (Cursor != NULL)
{
delete Cursor;
}
}
/*****************************************************************************/
void* ui_create_glyph(int width, int height, uint8 * data)
{
QBitmap * Bitmap;
Bitmap = new QBitmap(width, height, data);
Bitmap->setMask(*Bitmap);
return (HGLYPH)Bitmap;
}
/*****************************************************************************/
void ui_destroy_glyph(void * glyph)
{
QBitmap* Bitmap;
Bitmap = (QBitmap*)glyph;
delete Bitmap;
}
/*****************************************************************************/
void ui_destroy_bitmap(void * bmp)
{
QPixmap * Pixmap;
Pixmap = (QPixmap*)bmp;
delete Pixmap;
}
/*****************************************************************************/
void ui_reset_clip(void)
{
g_P1->setClipRect(0, 0, g_width, g_height);
g_P2->setClipRect(0, 0, g_width, g_height);
delete g_ClipRect;
g_ClipRect = new QRegion(0, 0, g_width, g_height);
}
/*****************************************************************************/
void ui_set_clip(int x, int y, int cx, int cy)
{
g_P1->setClipRect(x, y, cx, cy);
g_P2->setClipRect(x, y, cx, cy);
delete g_ClipRect;
g_ClipRect = new QRegion(x, y, cx, cy);
}
/*****************************************************************************/
void * ui_create_colourmap(COLOURMAP * colours)
{
QColorMap* LCM;
int i, r, g, b;
LCM = (QColorMap*)malloc(sizeof(QColorMap));
memset(LCM, 0, sizeof(QColorMap));
i = 0;
while (i < colours->ncolours && i < 256)
{
r = colours->colours[i].red;
g = colours->colours[i].green;
b = colours->colours[i].blue;
LCM->RGBColors[i] = (r << 16) | (g << 8) | b;
i++;
}
LCM->NumColors = colours->ncolours;
return LCM;
}
//*****************************************************************************
// todo, does this leak at end of program
void ui_destroy_colourmap(HCOLOURMAP map)
{
QColorMap * LCM;
LCM = (QColorMap*)map;
if (LCM == NULL)
return;
free(LCM);
}
/*****************************************************************************/
void ui_set_colourmap(void * map)
{
// destoy old colormap
ui_destroy_colourmap(g_CM);
g_CM = (QColorMap*)map;
}
/*****************************************************************************/
HBITMAP ui_create_bitmap(int width, int height, uint8 * data)
{
QImage * Image = NULL;
QPixmap * Pixmap;
uint32 * d = NULL;
uint16 * s;
int i;
switch (g_server_depth)
{
case 8:
Image = new QImage(data, width, height, 8, (QRgb*)&g_CM->RGBColors,
g_CM->NumColors, QImage::IgnoreEndian);
break;
case 15:
d = (uint32*)malloc(width * height * 4);
s = (uint16*)data;
for (i = 0; i < width * height; i++)
{
d[i] = Color15to32(s[i]);
}
Image = new QImage((uint8*)d, width, height, 32, NULL,
0, QImage::IgnoreEndian);
break;
case 16:
d = (uint32*)malloc(width * height * 4);
s = (uint16*)data;
for (i = 0; i < width * height; i++)
{
d[i] = Color16to32(s[i]);
}
Image = new QImage((uint8*)d, width, height, 32, NULL,
0, QImage::IgnoreEndian);
break;
case 24:
d = (uint32*)malloc(width * height * 4);
memset(d, 0, width * height * 4);
for (i = 0; i < width * height; i++)
{
memcpy(d + i, data + i * 3, 3);
}
Image = new QImage((uint8*)d, width, height, 32, NULL,
0, QImage::IgnoreEndian);
break;
}
if (Image == NULL)
{
return NULL;
}
Pixmap = new QPixmap();
Pixmap->convertFromImage(*Image);
delete Image;
if (d != NULL)
{
free(d);
}
return (HBITMAP)Pixmap;
}
//******************************************************************************
// adjust coordinates for cliping rect
int WarpCoords(int * x, int * y, int * cx, int * cy, int * srcx, int * srcy)
{
int dx, dy;
QRect InRect(*x, *y, *cx, *cy);
QRect OutRect;
QRect CRect = g_ClipRect->boundingRect();
OutRect = InRect.intersect(CRect);
if (OutRect.isEmpty())
{
return False;
}
dx = OutRect.x() - InRect.x();
dy = OutRect.y() - InRect.y();
*x = OutRect.x();
*y = OutRect.y();
*cx = OutRect.width();
*cy = OutRect.height();
*srcx = *srcx + dx;
*srcy = *srcy + dy;
return True;
}
//******************************************************************************
// needed because bitBlt don't seem to care about clipping rects
// also has 2 dsts and src can be null
void bitBltClip(QPaintDevice * dst1, QPaintDevice * dst2, int dx, int dy,
QPaintDevice * src, int sx, int sy, int sw, int sh,
Qt::RasterOp rop, bool im)
{
if (WarpCoords(&dx, &dy, &sw, &sh, &sx, &sy))
{
if (dst1 != NULL)
{
if (src == NULL)
{
bitBlt(dst1, dx, dy, dst1, sx, sy, sw, sh, rop, im);
}
else
{
bitBlt(dst1, dx, dy, src, sx, sy, sw, sh, rop, im);
}
}
if (dst2 != NULL)
{
if (src == NULL)
{
bitBlt(dst2, dx, dy, dst2, sx, sy, sw, sh, rop, im);
}
else
{
bitBlt(dst2, dx, dy, src, sx, sy, sw, sh, rop, im);
}
}
}
}
#define DO_GLYPH(ttext,idx) \
{ \
glyph = cache_get_font (font, ttext[idx]); \
if (!(flags & TEXT2_IMPLICIT_X)) \
{ \
xyoffset = ttext[++idx]; \
if ((xyoffset & 0x80)) \
{ \
if (flags & TEXT2_VERTICAL) \
y += ttext[idx+1] | (ttext[idx+2] << 8); \
else \
x += ttext[idx+1] | (ttext[idx+2] << 8); \
idx += 2; \
} \
else \
{ \
if (flags & TEXT2_VERTICAL) \
y += xyoffset; \
else \
x += xyoffset; \
} \
} \
if (glyph != NULL) \
{ \
g_P2->drawPixmap(x + glyph->offset, y + glyph->baseline, \
*((QBitmap*)glyph->pixmap)); \
if (flags & TEXT2_IMPLICIT_X) \
x += glyph->width; \
} \
}
//*****************************************************************************
void ui_draw_text(uint8 font, uint8 flags, uint8 opcode, int mixmode,
int x, int y, int clipx, int clipy,
int clipcx, int clipcy, int boxx,
int boxy, int boxcx, int boxcy, BRUSH * brush,
int bgcolour, int fgcolour, uint8 * text, uint8 length)
{
FONTGLYPH * glyph;
int i, j, xyoffset;
DATABLOB * entry;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -