2000-07-05 09:44:21 +02:00
|
|
|
/*
|
|
|
|
rdesktop: A Remote Desktop Protocol client.
|
|
|
|
User interface services - X-Windows
|
|
|
|
Copyright (C) Matthew Chapman 1999-2000
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include "rdesktop.h"
|
2000-07-05 09:44:21 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
extern int width;
|
|
|
|
extern int height;
|
|
|
|
extern BOOL motion;
|
|
|
|
|
|
|
|
static Display *display;
|
|
|
|
static Window wnd;
|
|
|
|
static GC gc;
|
|
|
|
static Visual *visual;
|
|
|
|
static XIM IM;
|
|
|
|
|
|
|
|
BOOL ui_create_window(char *title)
|
2000-07-05 09:44:21 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
Screen *screen;
|
2000-07-25 14:34:29 +02:00
|
|
|
XSetWindowAttributes attribs;
|
2000-08-15 12:23:24 +02:00
|
|
|
unsigned long input_mask;
|
|
|
|
int i;
|
2000-07-05 09:44:21 +02:00
|
|
|
|
|
|
|
display = XOpenDisplay(NULL);
|
|
|
|
if (display == NULL)
|
2000-08-15 12:23:24 +02:00
|
|
|
return False;
|
|
|
|
|
|
|
|
/* Check the screen supports 8-bit depth. */
|
|
|
|
screen = DefaultScreenOfDisplay(display);
|
|
|
|
for (i = 0; i < screen->ndepths; i++)
|
|
|
|
if (screen->depths[i].depth == 8)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (i >= screen->ndepths)
|
|
|
|
{
|
|
|
|
ERROR("8-bit depth required (in this version).\n");
|
|
|
|
XCloseDisplay(display);
|
|
|
|
return False;
|
|
|
|
}
|
2000-07-05 09:44:21 +02:00
|
|
|
|
2000-07-25 14:34:29 +02:00
|
|
|
visual = DefaultVisual(display, DefaultScreen(display));
|
2000-07-05 09:44:21 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
attribs.background_pixel = BlackPixel(display, DefaultScreen(display));
|
2000-07-25 14:34:29 +02:00
|
|
|
attribs.backing_store = Always;
|
2000-08-15 12:23:24 +02:00
|
|
|
wnd = XCreateWindow(display, DefaultRootWindow(display),
|
|
|
|
0, 0, width, height, 0, 8, InputOutput, visual,
|
2000-07-25 14:34:29 +02:00
|
|
|
CWBackingStore | CWBackPixel, &attribs);
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
XStoreName(display, wnd, title);
|
|
|
|
XMapWindow(display, wnd);
|
2000-07-05 09:44:21 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
input_mask = KeyPressMask | KeyReleaseMask;
|
|
|
|
input_mask |= ButtonPressMask | ButtonReleaseMask;
|
|
|
|
if (motion)
|
|
|
|
input_mask |= PointerMotionMask;
|
2000-07-05 09:44:21 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
XSelectInput(display, wnd, input_mask);
|
|
|
|
gc = XCreateGC(display, wnd, 0, NULL);
|
2000-07-07 11:40:03 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
IM = XOpenIM(display, NULL, NULL, NULL);
|
|
|
|
return True;
|
2000-07-05 09:44:21 +02:00
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
void ui_destroy_window()
|
2000-07-05 09:44:21 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
XCloseIM(IM);
|
|
|
|
XFreeGC(display, gc);
|
|
|
|
XDestroyWindow(display, wnd);
|
|
|
|
XCloseDisplay(display);
|
2000-07-05 09:44:21 +02:00
|
|
|
}
|
|
|
|
|
2000-07-25 14:34:29 +02:00
|
|
|
static uint8 xwin_translate_key(unsigned long key)
|
|
|
|
{
|
|
|
|
DEBUG("KEY(code=0x%lx)\n", key);
|
|
|
|
|
|
|
|
if ((key > 8) && (key <= 0x60))
|
|
|
|
return (key - 8);
|
|
|
|
|
|
|
|
switch (key)
|
|
|
|
{
|
|
|
|
case 0x62: /* left arrow */
|
|
|
|
return 0x48;
|
|
|
|
case 0x64: /* up arrow */
|
|
|
|
return 0x4b;
|
|
|
|
case 0x66: /* down arrow */
|
|
|
|
return 0x4d;
|
|
|
|
case 0x68: /* right arrow */
|
|
|
|
return 0x50;
|
|
|
|
case 0x73: /* Windows key */
|
|
|
|
DEBUG("CHECKPOINT\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint16 xwin_translate_mouse(unsigned long button)
|
|
|
|
{
|
|
|
|
switch (button)
|
|
|
|
{
|
|
|
|
case Button1: /* left */
|
|
|
|
return MOUSE_FLAG_BUTTON1;
|
|
|
|
case Button2: /* middle */
|
|
|
|
return MOUSE_FLAG_BUTTON3;
|
|
|
|
case Button3: /* right */
|
|
|
|
return MOUSE_FLAG_BUTTON2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
void ui_process_events()
|
2000-07-25 14:34:29 +02:00
|
|
|
{
|
|
|
|
XEvent event;
|
|
|
|
uint8 scancode;
|
|
|
|
uint16 button;
|
2000-08-15 12:23:24 +02:00
|
|
|
uint32 ev_time;
|
2000-07-25 14:34:29 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
if (display == NULL)
|
2000-07-25 14:34:29 +02:00
|
|
|
return;
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
while (XCheckWindowEvent(display, wnd, 0xffffffff, &event))
|
2000-07-25 14:34:29 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
ev_time = time(NULL);
|
|
|
|
|
2000-07-25 14:34:29 +02:00
|
|
|
switch (event.type)
|
|
|
|
{
|
|
|
|
case KeyPress:
|
|
|
|
scancode = xwin_translate_key(event.xkey.keycode);
|
|
|
|
if (scancode == 0)
|
|
|
|
break;
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0,
|
2000-07-25 14:34:29 +02:00
|
|
|
scancode, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KeyRelease:
|
|
|
|
scancode = xwin_translate_key(event.xkey.keycode);
|
|
|
|
if (scancode == 0)
|
|
|
|
break;
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE,
|
2000-07-25 14:34:29 +02:00
|
|
|
KBD_FLAG_DOWN | KBD_FLAG_UP,
|
|
|
|
scancode, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ButtonPress:
|
|
|
|
button = xwin_translate_mouse(event.xbutton.button);
|
|
|
|
|
|
|
|
if (button == 0)
|
|
|
|
break;
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
rdp_send_input(ev_time, RDP_INPUT_MOUSE,
|
2000-07-25 14:34:29 +02:00
|
|
|
button | MOUSE_FLAG_DOWN,
|
|
|
|
event.xbutton.x,
|
|
|
|
event.xbutton.y);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ButtonRelease:
|
|
|
|
button = xwin_translate_mouse(event.xbutton.button);
|
|
|
|
if (button == 0)
|
|
|
|
break;
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
rdp_send_input(ev_time, RDP_INPUT_MOUSE,
|
2000-07-25 14:34:29 +02:00
|
|
|
button,
|
|
|
|
event.xbutton.x,
|
|
|
|
event.xbutton.y);
|
2000-08-15 12:23:24 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MotionNotify:
|
|
|
|
rdp_send_input(ev_time, RDP_INPUT_MOUSE,
|
|
|
|
MOUSE_FLAG_MOVE,
|
|
|
|
event.xmotion.x,
|
|
|
|
event.xmotion.y);
|
2000-07-25 14:34:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
void ui_move_pointer(int x, int y)
|
2000-07-25 14:34:29 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
XWarpPointer(display, wnd, wnd, 0, 0, 0, 0, x, y);
|
2000-07-25 14:34:29 +02:00
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
HBITMAP ui_create_bitmap(int width, int height, uint8 *data)
|
2000-07-05 09:44:21 +02:00
|
|
|
{
|
|
|
|
XImage *image;
|
2000-07-25 14:34:29 +02:00
|
|
|
Pixmap bitmap;
|
2000-07-05 09:44:21 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
bitmap = XCreatePixmap(display, wnd, width, height, 8);
|
2000-07-05 09:44:21 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
image = XCreateImage(display, visual, 8, ZPixmap, 0,
|
2000-07-25 14:34:29 +02:00
|
|
|
data, width, height, 8, width);
|
2000-08-15 12:23:24 +02:00
|
|
|
XSetFunction(display, gc, GXcopy);
|
|
|
|
XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);
|
2000-07-25 14:34:29 +02:00
|
|
|
XFree(image);
|
|
|
|
|
|
|
|
return (HBITMAP)bitmap;
|
2000-07-05 09:44:21 +02:00
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
void ui_paint_bitmap(int x, int y, int cx, int cy,
|
|
|
|
int width, int height, uint8 *data)
|
2000-07-05 09:44:21 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
XImage *image;
|
|
|
|
|
|
|
|
image = XCreateImage(display, visual, 8, ZPixmap, 0,
|
|
|
|
data, width, height, 8, width);
|
|
|
|
XSetFunction(display, gc, GXcopy);
|
|
|
|
XPutImage(display, wnd, gc, image, 0, 0, x, y, cx, cy);
|
|
|
|
XFree(image);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ui_destroy_bitmap(HBITMAP bmp)
|
|
|
|
{
|
|
|
|
XFreePixmap(display, (Pixmap)bmp);
|
2000-07-05 09:44:21 +02:00
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
HGLYPH ui_create_glyph(int width, int height, uint8 *data)
|
2000-07-05 09:44:21 +02:00
|
|
|
{
|
2000-07-25 14:34:29 +02:00
|
|
|
XImage *image;
|
|
|
|
Pixmap bitmap;
|
|
|
|
int scanline;
|
|
|
|
GC gc;
|
|
|
|
|
|
|
|
scanline = (width + 7) / 8;
|
2000-07-05 09:44:21 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
bitmap = XCreatePixmap(display, wnd, width, height, 1);
|
|
|
|
gc = XCreateGC(display, bitmap, 0, NULL);
|
2000-07-05 09:44:21 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
image = XCreateImage(display, visual, 1, ZPixmap, 0,
|
2000-07-25 14:34:29 +02:00
|
|
|
data, width, height, 8, scanline);
|
2000-08-15 12:23:24 +02:00
|
|
|
XSetFunction(display, gc, GXcopy);
|
|
|
|
XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);
|
2000-07-25 14:34:29 +02:00
|
|
|
XFree(image);
|
2000-08-15 12:23:24 +02:00
|
|
|
XFreeGC(display, gc);
|
2000-07-25 14:34:29 +02:00
|
|
|
|
|
|
|
return (HGLYPH)bitmap;
|
2000-07-05 09:44:21 +02:00
|
|
|
}
|
2000-07-07 11:40:03 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
void ui_destroy_glyph(HGLYPH glyph)
|
2000-07-07 11:40:03 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
XFreePixmap(display, (Pixmap)glyph);
|
2000-07-25 14:34:29 +02:00
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
HCOLOURMAP ui_create_colourmap(COLOURMAP *colours)
|
2000-07-25 14:34:29 +02:00
|
|
|
{
|
|
|
|
COLOURENTRY *entry;
|
|
|
|
XColor *xcolours, *xentry;
|
2000-07-07 11:40:03 +02:00
|
|
|
Colormap map;
|
2000-07-25 14:34:29 +02:00
|
|
|
int i, ncolours = colours->ncolours;
|
2000-07-07 11:40:03 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
xcolours = xmalloc(sizeof(XColor) * ncolours);
|
2000-07-25 14:34:29 +02:00
|
|
|
for (i = 0; i < ncolours; i++)
|
2000-07-07 11:40:03 +02:00
|
|
|
{
|
2000-07-25 14:34:29 +02:00
|
|
|
entry = &colours->colours[i];
|
|
|
|
xentry = &xcolours[i];
|
2000-07-07 11:40:03 +02:00
|
|
|
|
|
|
|
xentry->pixel = i;
|
|
|
|
xentry->red = entry->red << 8;
|
|
|
|
xentry->blue = entry->blue << 8;
|
|
|
|
xentry->green = entry->green << 8;
|
|
|
|
xentry->flags = DoRed | DoBlue | DoGreen;
|
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
map = XCreateColormap(display, wnd, visual, AllocAll);
|
|
|
|
XStoreColors(display, map, xcolours, ncolours);
|
2000-07-07 11:40:03 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
xfree(xcolours);
|
2000-07-25 14:34:29 +02:00
|
|
|
return (HCOLOURMAP)map;
|
2000-07-07 11:40:03 +02:00
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
void ui_destroy_colourmap(HCOLOURMAP map)
|
2000-07-07 11:40:03 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
XFreeColormap(display, (Colormap)map);
|
2000-07-07 11:40:03 +02:00
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
void ui_set_colourmap(HCOLOURMAP map)
|
2000-07-07 11:40:03 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
XSetWindowColormap(display, wnd, (Colormap)map);
|
2000-07-07 11:40:03 +02:00
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
void ui_set_clip(int x, int y, int cx, int cy)
|
2000-07-25 14:34:29 +02:00
|
|
|
{
|
|
|
|
XRectangle rect;
|
|
|
|
|
|
|
|
rect.x = x;
|
|
|
|
rect.y = y;
|
|
|
|
rect.width = cx;
|
|
|
|
rect.height = cy;
|
2000-08-15 12:23:24 +02:00
|
|
|
XSetClipRectangles(display, gc, 0, 0, &rect, 1, YXBanded);
|
2000-07-25 14:34:29 +02:00
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
void ui_reset_clip()
|
2000-07-07 11:40:03 +02:00
|
|
|
{
|
2000-07-25 14:34:29 +02:00
|
|
|
XRectangle rect;
|
|
|
|
|
|
|
|
rect.x = 0;
|
|
|
|
rect.y = 0;
|
2000-08-15 12:23:24 +02:00
|
|
|
rect.width = width;
|
|
|
|
rect.height = height;
|
|
|
|
XSetClipRectangles(display, gc, 0, 0, &rect, 1, YXBanded);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ui_bell()
|
|
|
|
{
|
|
|
|
XBell(display, 0);
|
2000-07-25 14:34:29 +02:00
|
|
|
}
|
2000-07-07 11:40:03 +02:00
|
|
|
|
2000-07-25 14:34:29 +02:00
|
|
|
static int rop2_map[] = {
|
|
|
|
GXclear, /* 0 */
|
|
|
|
GXnor, /* DPon */
|
|
|
|
GXandInverted, /* DPna */
|
|
|
|
GXcopyInverted, /* Pn */
|
|
|
|
GXandReverse, /* PDna */
|
|
|
|
GXinvert, /* Dn */
|
|
|
|
GXxor, /* DPx */
|
|
|
|
GXnand, /* DPan */
|
|
|
|
GXand, /* DPa */
|
|
|
|
GXequiv, /* DPxn */
|
|
|
|
GXnoop, /* D */
|
|
|
|
GXorInverted, /* DPno */
|
|
|
|
GXcopy, /* P */
|
|
|
|
GXorReverse, /* PDno */
|
|
|
|
GXor, /* DPo */
|
|
|
|
GXset /* 1 */
|
|
|
|
};
|
2000-07-07 11:40:03 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
static void xwin_set_function(uint8 rop2)
|
2000-07-25 14:34:29 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
XSetFunction(display, gc, rop2_map[rop2]);
|
2000-07-07 11:40:03 +02:00
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
void ui_destblt(uint8 opcode,
|
2000-07-25 14:34:29 +02:00
|
|
|
/* dest */ int x, int y, int cx, int cy)
|
2000-07-07 11:40:03 +02:00
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
xwin_set_function(opcode);
|
2000-07-25 14:34:29 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
XFillRectangle(display, wnd, gc, x, y, cx, cy);
|
2000-07-25 14:34:29 +02:00
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
void ui_patblt(uint8 opcode,
|
2000-07-25 14:34:29 +02:00
|
|
|
/* dest */ int x, int y, int cx, int cy,
|
|
|
|
/* brush */ BRUSH *brush, int bgcolour, int fgcolour)
|
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
Display *dpy = display;
|
2000-07-25 14:34:29 +02:00
|
|
|
Pixmap fill;
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
xwin_set_function(opcode);
|
2000-07-25 14:34:29 +02:00
|
|
|
|
|
|
|
switch (brush->style)
|
|
|
|
{
|
|
|
|
case 0: /* Solid */
|
|
|
|
XSetForeground(dpy, gc, fgcolour);
|
2000-08-15 12:23:24 +02:00
|
|
|
XFillRectangle(dpy, wnd, gc, x, y, cx, cy);
|
2000-07-25 14:34:29 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3: /* Pattern */
|
2000-08-15 12:23:24 +02:00
|
|
|
fill = (Pixmap)ui_create_glyph(8, 8, brush->pattern);
|
2000-07-25 14:34:29 +02:00
|
|
|
|
|
|
|
XSetForeground(dpy, gc, fgcolour);
|
|
|
|
XSetBackground(dpy, gc, bgcolour);
|
|
|
|
XSetFillStyle(dpy, gc, FillOpaqueStippled);
|
|
|
|
XSetStipple(dpy, gc, fill);
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
XFillRectangle(dpy, wnd, gc, x, y, cx, cy);
|
2000-07-25 14:34:29 +02:00
|
|
|
|
|
|
|
XSetFillStyle(dpy, gc, FillSolid);
|
2000-08-15 12:23:24 +02:00
|
|
|
ui_destroy_glyph((HGLYPH)fill);
|
2000-07-25 14:34:29 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2000-08-15 12:23:24 +02:00
|
|
|
NOTIMP("brush %d\n", brush->style);
|
2000-07-25 14:34:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
void ui_screenblt(uint8 opcode,
|
2000-07-25 14:34:29 +02:00
|
|
|
/* dest */ int x, int y, int cx, int cy,
|
|
|
|
/* src */ int srcx, int srcy)
|
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
xwin_set_function(opcode);
|
2000-07-25 14:34:29 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
XCopyArea(display, wnd, wnd, gc, srcx, srcy,
|
2000-07-25 14:34:29 +02:00
|
|
|
cx, cy, x, y);
|
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
void ui_memblt(uint8 opcode,
|
2000-07-25 14:34:29 +02:00
|
|
|
/* dest */ int x, int y, int cx, int cy,
|
|
|
|
/* src */ HBITMAP src, int srcx, int srcy)
|
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
xwin_set_function(opcode);
|
2000-07-25 14:34:29 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
XCopyArea(display, (Pixmap)src, wnd, gc, srcx, srcy,
|
2000-07-25 14:34:29 +02:00
|
|
|
cx, cy, x, y);
|
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
void ui_triblt(uint8 opcode,
|
2000-07-25 14:34:29 +02:00
|
|
|
/* dest */ int x, int y, int cx, int cy,
|
|
|
|
/* src */ HBITMAP src, int srcx, int srcy,
|
|
|
|
/* brush */ BRUSH *brush, int bgcolour, int fgcolour)
|
|
|
|
{
|
|
|
|
/* This is potentially difficult to do in general. Until someone
|
2000-08-15 12:23:24 +02:00
|
|
|
comes up with a more efficient way of doing it I am using cases. */
|
2000-07-25 14:34:29 +02:00
|
|
|
|
|
|
|
switch (opcode)
|
|
|
|
{
|
|
|
|
case 0xb8: /* PSDPxax */
|
2000-08-15 12:23:24 +02:00
|
|
|
ui_patblt(ROP2_XOR, x, y, cx, cy,
|
2000-07-25 14:34:29 +02:00
|
|
|
brush, bgcolour, fgcolour);
|
2000-08-15 12:23:24 +02:00
|
|
|
ui_memblt(ROP2_AND, x, y, cx, cy,
|
2000-07-25 14:34:29 +02:00
|
|
|
src, srcx, srcy);
|
2000-08-15 12:23:24 +02:00
|
|
|
ui_patblt(ROP2_XOR, x, y, cx, cy,
|
2000-07-25 14:34:29 +02:00
|
|
|
brush, bgcolour, fgcolour);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2000-08-15 12:23:24 +02:00
|
|
|
NOTIMP("triblt 0x%x\n", opcode);
|
|
|
|
ui_memblt(ROP2_COPY, x, y, cx, cy,
|
2000-07-25 14:34:29 +02:00
|
|
|
brush, bgcolour, fgcolour);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
void ui_line(uint8 opcode,
|
2000-07-25 14:34:29 +02:00
|
|
|
/* dest */ int startx, int starty, int endx, int endy,
|
|
|
|
/* pen */ PEN *pen)
|
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
xwin_set_function(opcode);
|
2000-07-25 14:34:29 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
XSetForeground(display, gc, pen->colour);
|
|
|
|
XDrawLine(display, wnd, gc, startx, starty, endx, endy);
|
2000-07-25 14:34:29 +02:00
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
void ui_rect(
|
2000-07-25 14:34:29 +02:00
|
|
|
/* dest */ int x, int y, int cx, int cy,
|
|
|
|
/* brush */ int colour)
|
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
xwin_set_function(ROP2_COPY);
|
2000-07-25 14:34:29 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
XSetForeground(display, gc, colour);
|
|
|
|
XFillRectangle(display, wnd, gc, x, y, cx, cy);
|
2000-07-25 14:34:29 +02:00
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
void ui_draw_glyph(int mixmode,
|
2000-07-25 14:34:29 +02:00
|
|
|
/* dest */ int x, int y, int cx, int cy,
|
|
|
|
/* src */ HGLYPH glyph, int srcx, int srcy, int bgcolour, int fgcolour)
|
|
|
|
{
|
|
|
|
Pixmap pixmap = (Pixmap)glyph;
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
xwin_set_function(ROP2_COPY);
|
2000-07-25 14:34:29 +02:00
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
XSetForeground(display, gc, fgcolour);
|
2000-07-25 14:34:29 +02:00
|
|
|
|
|
|
|
switch (mixmode)
|
|
|
|
{
|
|
|
|
case MIX_TRANSPARENT:
|
2000-08-15 12:23:24 +02:00
|
|
|
XSetStipple(display, gc, pixmap);
|
|
|
|
XSetFillStyle(display, gc, FillStippled);
|
|
|
|
XSetTSOrigin(display, gc, x, y);
|
|
|
|
XFillRectangle(display, wnd, gc,
|
2000-07-25 14:34:29 +02:00
|
|
|
x, y, cx, cy);
|
2000-08-15 12:23:24 +02:00
|
|
|
XSetFillStyle(display, gc, FillSolid);
|
2000-07-25 14:34:29 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MIX_OPAQUE:
|
2000-08-15 12:23:24 +02:00
|
|
|
XSetBackground(display, gc, bgcolour);
|
|
|
|
XCopyPlane(display, pixmap, wnd, gc,
|
2000-07-25 14:34:29 +02:00
|
|
|
srcx, srcy, cx, cy, x, y, 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2000-08-15 12:23:24 +02:00
|
|
|
NOTIMP("mix %d\n", mixmode);
|
2000-07-25 14:34:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
void ui_draw_text(uint8 font, uint8 flags, int mixmode, int x,
|
2000-07-25 14:34:29 +02:00
|
|
|
int y, int boxx, int boxy, int boxcx, int boxcy,
|
|
|
|
int bgcolour, int fgcolour, uint8 *text, uint8 length)
|
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
FONTGLYPH *glyph;
|
2000-07-25 14:34:29 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (boxcx > 1)
|
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
ui_rect(boxx, boxy, boxcx, boxcy, bgcolour);
|
2000-07-25 14:34:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Paint text, character by character */
|
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
glyph = cache_get_font(font, text[i]);
|
2000-07-25 14:34:29 +02:00
|
|
|
|
|
|
|
if (glyph != NULL)
|
|
|
|
{
|
2000-08-15 12:23:24 +02:00
|
|
|
ui_draw_glyph(mixmode, x,
|
2000-07-25 14:34:29 +02:00
|
|
|
y + (short)glyph->baseline,
|
|
|
|
glyph->width, glyph->height,
|
|
|
|
glyph->pixmap, 0, 0,
|
|
|
|
bgcolour, fgcolour);
|
|
|
|
|
|
|
|
if (flags & TEXT2_IMPLICIT_X)
|
|
|
|
x += glyph->width;
|
|
|
|
else
|
|
|
|
x += text[++i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
void ui_desktop_save(uint32 offset, int x, int y, int cx, int cy)
|
2000-07-25 14:34:29 +02:00
|
|
|
{
|
|
|
|
XImage *image;
|
|
|
|
int scanline;
|
|
|
|
|
|
|
|
scanline = (cx + 3) & ~3;
|
2000-08-15 14:01:01 +02:00
|
|
|
DEBUG("XGetImage(%p,%x,%d,%d,%d,%d,%x,%d)\n", display, wnd, x, y,
|
2000-08-15 12:23:24 +02:00
|
|
|
cx, cy, 0xffffffff, ZPixmap);
|
|
|
|
image = XGetImage(display, wnd, x, y, cx, cy, 0xffffffff, ZPixmap);
|
|
|
|
cache_put_desktop(offset, scanline*cy, image->data);
|
|
|
|
XFree(image->data);
|
|
|
|
XFree(image);
|
2000-07-25 14:34:29 +02:00
|
|
|
}
|
|
|
|
|
2000-08-15 12:23:24 +02:00
|
|
|
void ui_desktop_restore(uint32 offset, int x, int y, int cx, int cy)
|
2000-07-25 14:34:29 +02:00
|
|
|
{
|
|
|
|
XImage *image;
|
|
|
|
int scanline;
|
2000-08-15 12:23:24 +02:00
|
|
|
uint8 *data;
|
2000-07-25 14:34:29 +02:00
|
|
|
|
|
|
|
scanline = (cx + 3) & ~3;
|
2000-08-15 12:23:24 +02:00
|
|
|
data = cache_get_desktop(offset, scanline*cy);
|
|
|
|
if (data == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
image = XCreateImage(display, visual, 8, ZPixmap, 0,
|
2000-07-25 14:34:29 +02:00
|
|
|
data, cx, cy, 32, scanline);
|
2000-08-15 12:23:24 +02:00
|
|
|
XSetFunction(display, gc, GXcopy);
|
|
|
|
XPutImage(display, wnd, gc, image, 0, 0, x, y, cx, cy);
|
2000-07-25 14:34:29 +02:00
|
|
|
XFree(image);
|
2000-07-07 11:40:03 +02:00
|
|
|
}
|