blob: 20190c8f22f799ad0b291896927a3d61056aa3cc [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% %
7% IIIII CCCC CCCC CCCC M M %
8% I C C C MM MM %
9% I C C C M M M %
10% I C C C M M %
11% IIIII CCCC CCCC CCCC M M %
12% %
13% MagickCore X11 Compatibility Methods %
14% %
15% Software Design %
16% John Cristy %
17% December 1994 %
18% %
19% %
cristy1454be72011-12-19 01:52:48 +000020% Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36%
37*/
38
cristy4c08aed2011-07-01 19:47:50 +000039#include "MagickCore/studio.h"
cristy3ed852e2009-09-05 21:47:34 +000040#if defined(MAGICKCORE_X11_DELEGATE)
cristy4c08aed2011-07-01 19:47:50 +000041#include "MagickCore/xwindow-private.h"
cristy3ed852e2009-09-05 21:47:34 +000042
43#if defined(PRE_R6_ICCCM)
44/*
45 Compatibility methods for pre X11R6 ICCCM.
46*/
47Status XInitImage(XImage *ximage)
48{
49 Display
50 display;
51
52 ScreenFormat
53 screen_format;
54
55 XImage
56 *created_ximage,
57 target_ximage;
58
59 /*
60 Initialize the X image.
61 */
62 screen_format.depth=ximage->depth;
63 screen_format.bits_per_pixel=(int) ximage->bits_per_pixel;
64 display.byte_order=ximage->byte_order;
65 display.bitmap_unit=ximage->bitmap_unit;
66 display.bitmap_bit_order=ximage->bitmap_bit_order;
67 display.pixmap_format=(&screen_format);
68 display.nformats=1;
69 created_ximage=XCreateImage(&display,(Visual *) NULL,ximage->depth,
70 ximage->format,ximage->xoffset,(char *) NULL,ximage->width,ximage->height,
71 ximage->bitmap_pad,ximage->bytes_per_line);
72 if (created_ximage == (XImage *) NULL)
73 return(0);
74 target_ximage=(*ximage);
75 *ximage=(*created_ximage);
76 created_ximage->data=(char *) NULL;
77 XDestroyImage(created_ximage);
78 ximage->red_mask=target_ximage.red_mask;
79 ximage->green_mask=target_ximage.green_mask;
80 ximage->blue_mask=target_ximage.blue_mask;
81 return(1);
82}
83#endif
84
85#if defined(PRE_R5_ICCCM)
86/*
87 Compatibility methods for pre X11R5 ICCCM.
88*/
89void XrmCombineDatabase(XrmDatabase source,XrmDatabase *target,
90 Bool override)
91{
92 XrmMergeDatabases(source,target);
93}
94
95Status XrmCombineFileDatabase(const char *filename,XrmDatabase *target,
96 Bool override)
97{
98 XrmDatabase
99 *combined_database,
100 source;
101
102 source=XrmGetFileDatabase(filename);
103 if (override == MagickFalse)
104 XrmMergeDatabases(source,target);
105 return(1);
106}
107
108XrmDatabase XrmGetDatabase(Display *display)
109{
110 return(display->db);
111}
112
113char *XSetLocaleModifiers(char *modifiers)
114{
115 return((char *) NULL);
116}
117
118Bool XSupportsLocale()
119{
120 return(0);
121}
122#endif
123
124#if defined(PRE_R4_ICCCM)
125/*
126 Compatibility methods for pre X11R4 ICCCM.
127*/
128XClassHint *XAllocClassHint)
129{
cristy73bd4a52010-10-05 11:24:23 +0000130 return((XClassHint *) AcquireMagickMemory(sizeof(XClassHint)));
cristy3ed852e2009-09-05 21:47:34 +0000131}
132
133XIconSize *XAllocIconSize)
134{
cristy73bd4a52010-10-05 11:24:23 +0000135 return((XIconSize *) AcquireMagickMemory(sizeof(XIconSize)));
cristy3ed852e2009-09-05 21:47:34 +0000136}
137
138XSizeHints *XAllocSizeHints)
139{
cristy73bd4a52010-10-05 11:24:23 +0000140 return((XSizeHints *) AcquireMagickMemory(sizeof(XSizeHints)));
cristy3ed852e2009-09-05 21:47:34 +0000141}
142
143Status XReconfigureWMWindow(Display *display,Window window,int screen_number,
144 unsigned int value_mask,XWindowChanges *values)
145{
146 return(XConfigureWindow(display,window,value_mask,values));
147}
148
149XStandardColormap *XAllocStandardColormap)
150{
cristy73bd4a52010-10-05 11:24:23 +0000151 return((XStandardColormap *) AcquireMagickMemory(sizeof(XStandardColormap)));
cristy3ed852e2009-09-05 21:47:34 +0000152}
153
154XWMHints *XAllocWMHints)
155{
cristy73bd4a52010-10-05 11:24:23 +0000156 return((XWMHints *) AcquireMagickMemory(sizeof(XWMHints)));
cristy3ed852e2009-09-05 21:47:34 +0000157}
158
cristybb503372010-05-27 20:51:26 +0000159Status XGetGCValues(Display *display,GC gc,size_t mask,
cristy3ed852e2009-09-05 21:47:34 +0000160 XGCValues *values)
161{
162 return(MagickTrue);
163}
164
165Status XGetRGBColormaps(Display *display,Window window,
166 XStandardColormap **colormap,int *count,Atom property)
167{
168 *count=1;
169 return(XGetStandardColormap(display,window,*colormap,property));
170}
171
172Status XGetWMColormapWindows(Display *display,Window window,
173 Window **colormap_windows,int *number_windows)
174{
175 Atom
176 actual_type,
177 *data,
178 property;
179
180 int
181 actual_format,
182 status;
183
cristybb503372010-05-27 20:51:26 +0000184 size_t
cristy3ed852e2009-09-05 21:47:34 +0000185 leftover,
186 number_items;
187
188 property=XInternAtom(display,"WM_COLORMAP_WINDOWS",MagickFalse);
189 if (property == None)
190 return(MagickFalse);
191 /*
192 Get the window property.
193 */
194 *data=(Atom) NULL;
195 status=XGetWindowProperty(display,window,property,0L,1000000L,MagickFalse,
196 XA_WINDOW,&actual_type,&actual_format,&number_items,&leftover,
197 (unsigned char **) &data);
198 if (status != Success)
199 return(MagickFalse);
200 if ((actual_type != XA_WINDOW) || (actual_format != 32))
201 {
202 if (data != (Atom *) NULL)
203 XFree((char *) data);
204 return(MagickFalse);
205 }
206 *colormap_windows=(Window *) data;
207 *number_windows=(int) number_items;
208 return(MagickTrue);
209}
210
211Status XGetWMName(Display *display,Window window,XTextProperty *text_property)
212{
213 char
214 *window_name;
215
216 if (XFetchName(display,window,&window_name) == 0)
217 return(MagickFalse);
218 text_property->value=(unsigned char *) window_name;
219 text_property->encoding=XA_STRING;
220 text_property->format=8;
221 text_property->nitems=strlen(window_name);
222 return(MagickTrue);
223}
224
225char *XResourceManagerString(Display *display)
226{
227 return(display->xdefaults);
228}
229
230void XrmDestroyDatabase(XrmDatabase database)
231{
232}
233
234void XSetWMIconName(Display *display,Window window,XTextProperty *property)
235{
236 XSetIconName(display,window,property->value);
237}
238
239void XSetWMName(Display *display,Window window,XTextProperty *property)
240{
241 XStoreName(display,window,property->value);
242}
243
244void XSetWMProperties(Display *display,Window window,
245 XTextProperty *window_name,XTextProperty *icon_name,char **argv,
246 int argc,XSizeHints *size_hints,XWMHints *manager_hints,
247 XClassHint *class_hint)
248{
249 XSetStandardProperties(display,window,window_name->value,icon_name->value,
250 None,argv,argc,size_hints);
251 XSetWMHints(display,window,manager_hints);
252 XSetClassHint(display,window,class_hint);
253}
254
255Status XSetWMProtocols(Display *display,Window window,Atom *protocols,
256 int count)
257{
258 Atom
259 wm_protocols;
260
261 wm_protocols=XInternAtom(display,"WM_PROTOCOLS",MagickFalse);
262 XChangeProperty(display,window,wm_protocols,XA_ATOM,32,PropModeReplace,
263 (unsigned char *) protocols,count);
264 return(MagickTrue);
265}
266
267int XStringListToTextProperty(char **argv,int argc,XTextProperty *property)
268{
269 register int
270 i;
271
272 register unsigned int
273 number_bytes;
274
275 XTextProperty
276 protocol;
277
278 number_bytes=0;
cristybb503372010-05-27 20:51:26 +0000279 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000280 number_bytes+=(unsigned int) ((argv[i] ? strlen(argv[i]) : 0)+1);
281 protocol.encoding=XA_STRING;
282 protocol.format=8;
283 protocol.nitems=0;
284 if (number_bytes)
285 protocol.nitems=number_bytes-1;
286 protocol.value=NULL;
287 if (number_bytes <= 0)
288 {
289 protocol.value=(unsigned char *) AcquireQuantumMemory(1UL,
290 sizeof(*protocol.value));
291 if (protocol.value == MagickFalse)
292 return(MagickFalse);
293 *protocol.value='\0';
294 }
295 else
296 {
297 register char
298 *buffer;
299
300 buffer=(char *) AcquireQuantumMemory(number_bytes,sizeof(*buffer));
301 if (buffer == (char *) NULL)
302 return(MagickFalse);
303 protocol.value=(unsigned char *) buffer;
cristybb503372010-05-27 20:51:26 +0000304 for (i=0; i < (ssize_t) argc; i++)
cristy3ed852e2009-09-05 21:47:34 +0000305 {
306 char
307 *argument;
308
309 argument=argv[i];
310 if (argument == MagickFalse)
311 *buffer++='\0';
312 else
313 {
314 (void) CopyMagickString(buffer,argument,MaxTextExtent);
315 buffer+=(strlen(argument)+1);
316 }
317 }
318 }
319 *property=protocol;
320 return(MagickTrue);
321}
322
323VisualID XVisualIDFromVisual(Visual *visual)
324{
325 return(visual->visualid);
326}
327
328Status XWithdrawWindow(Display *display,Window window,int screen)
329{
330 return(XUnmapWindow(display,window));
331}
332
333int XWMGeometry(Display *display,int screen,char *user_geometry,
334 char *default_geometry,unsigned int border_width,XSizeHints *size_hints,
335 int *x,int *y,int *width,int *height,int *gravity)
336{
337 int
338 status;
339
340 status=XGeometry(display,screen,user_geometry,default_geometry,border_width,
341 0,0,0,0,x,y,width,height);
342 *gravity=NorthWestGravity;
343 return(status);
344}
345#endif
346
347#endif