cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 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 | % % |
cristy | 1454be7 | 2011-12-19 01:52:48 +0000 | [diff] [blame] | 20 | % Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 21 | % 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 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 39 | #include "MagickCore/studio.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 40 | #if defined(MAGICKCORE_X11_DELEGATE) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 41 | #include "MagickCore/xwindow-private.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 42 | |
| 43 | #if defined(PRE_R6_ICCCM) |
| 44 | /* |
| 45 | Compatibility methods for pre X11R6 ICCCM. |
| 46 | */ |
| 47 | Status 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 | */ |
| 89 | void XrmCombineDatabase(XrmDatabase source,XrmDatabase *target, |
| 90 | Bool override) |
| 91 | { |
| 92 | XrmMergeDatabases(source,target); |
| 93 | } |
| 94 | |
| 95 | Status 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 | |
| 108 | XrmDatabase XrmGetDatabase(Display *display) |
| 109 | { |
| 110 | return(display->db); |
| 111 | } |
| 112 | |
| 113 | char *XSetLocaleModifiers(char *modifiers) |
| 114 | { |
| 115 | return((char *) NULL); |
| 116 | } |
| 117 | |
| 118 | Bool XSupportsLocale() |
| 119 | { |
| 120 | return(0); |
| 121 | } |
| 122 | #endif |
| 123 | |
| 124 | #if defined(PRE_R4_ICCCM) |
| 125 | /* |
| 126 | Compatibility methods for pre X11R4 ICCCM. |
| 127 | */ |
| 128 | XClassHint *XAllocClassHint) |
| 129 | { |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 130 | return((XClassHint *) AcquireMagickMemory(sizeof(XClassHint))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | XIconSize *XAllocIconSize) |
| 134 | { |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 135 | return((XIconSize *) AcquireMagickMemory(sizeof(XIconSize))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | XSizeHints *XAllocSizeHints) |
| 139 | { |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 140 | return((XSizeHints *) AcquireMagickMemory(sizeof(XSizeHints))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | Status 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 | |
| 149 | XStandardColormap *XAllocStandardColormap) |
| 150 | { |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 151 | return((XStandardColormap *) AcquireMagickMemory(sizeof(XStandardColormap))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | XWMHints *XAllocWMHints) |
| 155 | { |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 156 | return((XWMHints *) AcquireMagickMemory(sizeof(XWMHints))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 157 | } |
| 158 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 159 | Status XGetGCValues(Display *display,GC gc,size_t mask, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 160 | XGCValues *values) |
| 161 | { |
| 162 | return(MagickTrue); |
| 163 | } |
| 164 | |
| 165 | Status 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 | |
| 172 | Status 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 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 184 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 185 | 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 | |
| 211 | Status 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 | |
| 225 | char *XResourceManagerString(Display *display) |
| 226 | { |
| 227 | return(display->xdefaults); |
| 228 | } |
| 229 | |
| 230 | void XrmDestroyDatabase(XrmDatabase database) |
| 231 | { |
| 232 | } |
| 233 | |
| 234 | void XSetWMIconName(Display *display,Window window,XTextProperty *property) |
| 235 | { |
| 236 | XSetIconName(display,window,property->value); |
| 237 | } |
| 238 | |
| 239 | void XSetWMName(Display *display,Window window,XTextProperty *property) |
| 240 | { |
| 241 | XStoreName(display,window,property->value); |
| 242 | } |
| 243 | |
| 244 | void 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 | |
| 255 | Status 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 | |
| 267 | int 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; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 279 | for (i=0; i < (ssize_t) argc; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 280 | 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; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 304 | for (i=0; i < (ssize_t) argc; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 305 | { |
| 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 | |
| 323 | VisualID XVisualIDFromVisual(Visual *visual) |
| 324 | { |
| 325 | return(visual->visualid); |
| 326 | } |
| 327 | |
| 328 | Status XWithdrawWindow(Display *display,Window window,int screen) |
| 329 | { |
| 330 | return(XUnmapWindow(display,window)); |
| 331 | } |
| 332 | |
| 333 | int 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 |