1 |
/* |
2 |
rdesktop: A Remote Desktop Protocol client. |
3 |
User interface services - X-Windows |
4 |
Copyright (C) Matthew Chapman 1999-2000 |
5 |
|
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 |
#include "includes.h" |
22 |
|
23 |
HWINDOW ui_create_window(int width, int height) |
24 |
{ |
25 |
struct window *wnd; |
26 |
Display *display; |
27 |
Window window; |
28 |
int black; |
29 |
GC gc; |
30 |
|
31 |
display = XOpenDisplay(NULL); |
32 |
if (display == NULL) |
33 |
return NULL; |
34 |
|
35 |
black = BlackPixel(display, DefaultScreen(display)); |
36 |
window = XCreateSimpleWindow(display, DefaultRootWindow(display), |
37 |
0, 0, width, height, 0, black, black); |
38 |
|
39 |
XMapWindow(display, window); |
40 |
XSync(display, True); |
41 |
|
42 |
gc = XCreateGC(display, window, 0, NULL); |
43 |
|
44 |
wnd = xmalloc(sizeof(struct window)); |
45 |
wnd->display = display; |
46 |
wnd->wnd = window; |
47 |
wnd->gc = gc; |
48 |
wnd->visual = DefaultVisual(wnd->display, DefaultScreen(wnd->display)); |
49 |
|
50 |
return wnd; |
51 |
} |
52 |
|
53 |
void ui_destroy_window(HWINDOW wnd) |
54 |
{ |
55 |
XFreeGC(wnd->display, wnd->gc); |
56 |
XDestroyWindow(wnd->display, wnd->wnd); |
57 |
XCloseDisplay(wnd->display); |
58 |
} |
59 |
|
60 |
HBITMAP ui_create_bitmap(HWINDOW wnd, int width, int height, uint8 *data) |
61 |
{ |
62 |
XImage *image; |
63 |
|
64 |
image = XCreateImage(wnd->display, wnd->visual, 8, ZPixmap, 0, |
65 |
data, width, height, 32, width); |
66 |
|
67 |
return (HBITMAP)image; |
68 |
} |
69 |
|
70 |
void ui_destroy_bitmap(HWINDOW wnd, HBITMAP bmp) |
71 |
{ |
72 |
XDestroyImage((XImage *)bmp); |
73 |
} |
74 |
|
75 |
void ui_paint_bitmap(HWINDOW wnd, HBITMAP bmp, int x, int y) |
76 |
{ |
77 |
XImage *image = (XImage *)bmp; |
78 |
|
79 |
XPutImage(wnd->display, wnd->wnd, wnd->gc, image, |
80 |
0, 0, x, y, image->width, image->height); |
81 |
|
82 |
XSync(wnd->display, True); |
83 |
} |
84 |
|
85 |
HCOLORMAP ui_create_colormap(HWINDOW wnd, COLORMAP *colors) |
86 |
{ |
87 |
COLORENTRY *entry; |
88 |
XColor *xcolors, *xentry; |
89 |
Colormap map; |
90 |
int i, ncolors = colors->ncolors; |
91 |
|
92 |
xcolors = malloc(sizeof(XColor) * ncolors); |
93 |
for (i = 0; i < ncolors; i++) |
94 |
{ |
95 |
entry = &colors->colors[i]; |
96 |
xentry = &xcolors[i]; |
97 |
|
98 |
xentry->pixel = i; |
99 |
xentry->red = entry->red << 8; |
100 |
xentry->blue = entry->blue << 8; |
101 |
xentry->green = entry->green << 8; |
102 |
xentry->flags = DoRed | DoBlue | DoGreen; |
103 |
} |
104 |
|
105 |
map = XCreateColormap(wnd->display, wnd->wnd, wnd->visual, AllocAll); |
106 |
XStoreColors(wnd->display, map, xcolors, ncolors); |
107 |
|
108 |
free(xcolors); |
109 |
return (HCOLORMAP)map; |
110 |
} |
111 |
|
112 |
void ui_destroy_colormap(HWINDOW wnd, HCOLORMAP map) |
113 |
{ |
114 |
XFreeColormap(wnd->display, (Colormap)map); |
115 |
} |
116 |
|
117 |
void ui_set_colormap(HWINDOW wnd, HCOLORMAP map) |
118 |
{ |
119 |
XSetWindowColormap(wnd->display, wnd->wnd, (Colormap)map); |
120 |
} |
121 |
|
122 |
void ui_draw_rectangle(HWINDOW wnd, int x, int y, int width, int height) |
123 |
{ |
124 |
static int white = 0; |
125 |
|
126 |
XSetForeground(wnd->display, wnd->gc, white); |
127 |
XFillRectangle(wnd->display, wnd->wnd, wnd->gc, x, y, width, height); |
128 |
|
129 |
white++; |
130 |
} |
131 |
|
132 |
void ui_move_pointer(HWINDOW wnd, int x, int y) |
133 |
{ |
134 |
XWarpPointer(wnd->display, wnd->wnd, wnd->wnd, 0, 0, 0, 0, x, y); |
135 |
} |