blob: d46fb455292850748c244870988150542a47c838 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
cristy45ef08f2012-12-07 13:13:34 +00002 Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization
cristy3ed852e2009-09-05 21:47:34 +00003 dedicated to making software imaging solutions freely available.
4
5 You may not use this file except in compliance with the License.
6 obtain a copy of the License at
7
8 http://www.imagemagick.org/script/license.php
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16 MagickCore X11 window methods.
17*/
18#ifndef _MAGICKCORE_XWINDOW_PRIVATE_H
19#define _MAGICKCORE_XWINDOW_PRIVATE_H
20
21#if defined(__cplusplus) || defined(c_plusplus)
22extern "C" {
23#endif
24
cristy1ffe9982013-04-13 16:46:51 +000025#include "MagickCore/exception.h"
26#include "MagickCore/geometry.h"
27#include "MagickCore/pixel-accessor.h"
28#include "MagickCore/quantize.h"
29
cristy3ed852e2009-09-05 21:47:34 +000030#if defined(MAGICKCORE_X11_DELEGATE)
31
32#include <X11/Xos.h>
33#include <X11/Xlib.h>
34#include <X11/Xatom.h>
35#include <X11/cursorfont.h>
36#include <X11/keysym.h>
37#include <X11/Xresource.h>
38#include <X11/Xutil.h>
cristy3ed852e2009-09-05 21:47:34 +000039
40#if defined(__cplusplus) || defined(c_plusplus)
41# define klass c_class
42#else
43# define klass class
44#endif
45
46/*
47 Invoke pre-X11R6 ICCCM routines if XlibSpecificationRelease is not 6.
48*/
49#if XlibSpecificationRelease < 6
50#if !defined(PRE_R6_ICCCM)
51#define PRE_R6_ICCCM
52#endif
53#endif
54/*
55 Invoke pre-X11R5 ICCCM routines if XlibSpecificationRelease is not defined.
56*/
57#if !defined(XlibSpecificationRelease)
58#define PRE_R5_ICCCM
59#endif
60/*
61 Invoke pre-X11R4 ICCCM routines if PWinGravity is not defined.
62*/
63#if !defined(PWinGravity)
64#define PRE_R4_ICCCM
65#endif
66
67#define MaxIconSize 96
68#define MaxNumberPens 11
69#define MaxNumberFonts 11
70#define MaxXWindows 12
71#undef index
72
73#define ThrowXWindowException(severity,tag,context) \
74{ \
75 ExceptionInfo \
76 exception; \
77 \
78 GetExceptionInfo(&exception); \
79 (void) ThrowMagickException(&exception,GetMagickModule(),severity, \
anthonye5b39652012-04-21 05:37:29 +000080 tag == (const char *) NULL ? "unknown" : tag,"'%s': %s",context, \
cristy3ed852e2009-09-05 21:47:34 +000081 strerror(errno)); \
82 CatchException(&exception); \
83 (void) DestroyExceptionInfo(&exception); \
84}
85#define ThrowXWindowFatalException(severity,tag,context) \
86{ \
87 ThrowXWindowException(severity,tag,context); \
88 _exit(1); \
89}
90
91typedef enum
92{
93 ForegroundStencil,
94 BackgroundStencil,
95 OpaqueStencil,
96 TransparentStencil
97} AnnotationStencil;
98
99typedef enum
100{
101 UndefinedElement,
102 PointElement,
103 LineElement,
104 RectangleElement,
105 FillRectangleElement,
106 CircleElement,
107 FillCircleElement,
108 EllipseElement,
109 FillEllipseElement,
110 PolygonElement,
111 FillPolygonElement,
112 ColorElement,
113 MatteElement,
114 TextElement,
115 ImageElement
116} ElementType;
117
118typedef enum
119{
120 UndefinedColormap,
121 PrivateColormap,
122 SharedColormap
123} XColormapType;
124
125typedef struct _XDrawInfo
126{
127 int
128 x,
129 y;
130
131 unsigned int
132 width,
133 height;
134
135 double
136 degrees;
137
138 AnnotationStencil
139 stencil;
140
141 ElementType
142 element;
143
144 Pixmap
145 stipple;
146
147 unsigned int
148 line_width;
149
150 XSegment
151 line_info;
152
153 unsigned int
154 number_coordinates;
155
156 RectangleInfo
157 rectangle_info;
158
159 XPoint
160 *coordinate_info;
161
162 char
163 geometry[MaxTextExtent];
164} XDrawInfo;
165
166typedef enum
167{
168 DefaultState = 0x0000,
169 EscapeState = 0x0001,
170 ExitState = 0x0002,
171 FormerImageState = 0x0004,
172 ModifierState = 0x0008,
173 MontageImageState = 0x0010,
174 NextImageState = 0x0020,
175 RetainColorsState = 0x0040,
176 SuspendTime = 50,
177 UpdateConfigurationState = 0x0080,
178 UpdateRegionState = 0x0100
179} XState;
180
181typedef struct _XAnnotateInfo
182{
183 int
184 x,
185 y;
186
187 unsigned int
188 width,
189 height;
190
191 double
192 degrees;
193
194 XFontStruct
195 *font_info;
196
197 char
198 *text;
199
200 AnnotationStencil
201 stencil;
202
203 char
204 geometry[MaxTextExtent];
205
206 struct _XAnnotateInfo
207 *next,
208 *previous;
209} XAnnotateInfo;
210
211typedef struct _XPixelInfo
212{
cristyf2faecf2010-05-28 19:19:36 +0000213 ssize_t
214 colors;
215
216 unsigned long
cristy3ed852e2009-09-05 21:47:34 +0000217 *pixels;
218
219 XColor
220 foreground_color,
221 background_color,
222 border_color,
223 matte_color,
224 highlight_color,
225 shadow_color,
226 depth_color,
227 trough_color,
228 box_color,
229 pen_color,
230 pen_colors[MaxNumberPens];
231
232 GC
233 annotate_context,
234 highlight_context,
235 widget_context;
236
237 unsigned short
238 box_index,
239 pen_index;
240} XPixelInfo;
241
cristye3099b72011-09-08 18:21:13 +0000242typedef struct _XResourceInfo
cristy3ed852e2009-09-05 21:47:34 +0000243{
244 XrmDatabase
245 resource_database;
246
247 ImageInfo
248 *image_info;
249
250 QuantizeInfo
251 *quantize_info;
252
cristybb503372010-05-27 20:51:26 +0000253 size_t
cristy3ed852e2009-09-05 21:47:34 +0000254 colors;
255
256 MagickBooleanType
257 close_server,
258 backdrop;
259
260 char
261 *background_color,
262 *border_color;
263
264 char
265 *client_name;
266
267 XColormapType
268 colormap;
269
270 unsigned int
271 border_width;
272
cristybb503372010-05-27 20:51:26 +0000273 size_t
cristy3ed852e2009-09-05 21:47:34 +0000274 delay;
275
276 MagickBooleanType
277 color_recovery,
278 confirm_exit,
279 confirm_edit;
280
281 char
282 *display_gamma;
283
284 char
285 *font,
286 *font_name[MaxNumberFonts],
287 *foreground_color;
288
289 MagickBooleanType
290 display_warnings,
291 gamma_correct;
292
293 char
294 *icon_geometry;
295
296 MagickBooleanType
297 iconic,
298 immutable;
299
300 char
301 *image_geometry;
302
303 char
304 *map_type,
305 *matte_color,
306 *name;
307
308 unsigned int
309 magnify,
310 pause;
311
312 char
313 *pen_colors[MaxNumberPens];
314
315 char
316 *text_font,
317 *title;
318
319 int
320 quantum;
321
322 unsigned int
323 update;
324
325 MagickBooleanType
326 use_pixmap,
327 use_shared_memory;
328
cristybb503372010-05-27 20:51:26 +0000329 size_t
cristy3ed852e2009-09-05 21:47:34 +0000330 undo_cache;
331
332 char
333 *visual_type,
334 *window_group,
335 *window_id,
336 *write_filename;
337
338 Image
339 *copy_image;
340
341 int
342 gravity;
343
344 char
345 home_directory[MaxTextExtent];
cristye3099b72011-09-08 18:21:13 +0000346} XResourceInfo;
cristy3ed852e2009-09-05 21:47:34 +0000347
348typedef struct _XWindowInfo
349{
350 Window
351 id;
352
353 Window
354 root;
355
356 Visual
357 *visual;
358
359 unsigned int
360 storage_class,
361 depth;
362
363 XVisualInfo
364 *visual_info;
365
366 XStandardColormap
367 *map_info;
368
369 XPixelInfo
370 *pixel_info;
371
372 XFontStruct
373 *font_info;
374
375 GC
376 annotate_context,
377 highlight_context,
378 widget_context;
379
380 Cursor
381 cursor,
382 busy_cursor;
383
384 char
385 *name,
386 *geometry,
387 *icon_name,
388 *icon_geometry,
389 *crop_geometry;
390
cristybb503372010-05-27 20:51:26 +0000391 size_t
cristy3ed852e2009-09-05 21:47:34 +0000392 data,
393 flags;
394
395 int
396 x,
397 y;
398
399 unsigned int
400 width,
401 height,
402 min_width,
403 min_height,
404 width_inc,
405 height_inc,
406 border_width;
407
408 MagickBooleanType
409 use_pixmap,
410 immutable,
411 shape,
412 shared_memory;
413
414 int
415 screen;
416
417 XImage
418 *ximage,
419 *matte_image;
420
421 Pixmap
422 highlight_stipple,
423 shadow_stipple,
424 pixmap,
425 *pixmaps,
426 matte_pixmap,
427 *matte_pixmaps;
428
429 XSetWindowAttributes
430 attributes;
431
432 XWindowChanges
433 window_changes;
434
435 void
436 *segment_info;
437
cristy8891f9c2010-06-04 23:32:17 +0000438 long
cristy3ed852e2009-09-05 21:47:34 +0000439 mask;
440
441 MagickBooleanType
442 orphan,
443 mapped,
444 stasis;
445
446 Image
447 *image;
448
449 MagickBooleanType
450 destroy;
451} XWindowInfo;
452
453typedef struct _XWindows
454{
455 Display
456 *display;
457
458 XStandardColormap
459 *map_info,
460 *icon_map;
461
462 XVisualInfo
463 *visual_info,
464 *icon_visual;
465
466 XPixelInfo
467 *pixel_info,
468 *icon_pixel;
469
470 XFontStruct
471 *font_info;
472
473 XResourceInfo
474 *icon_resources;
475
476 XClassHint
477 *class_hints;
478
479 XWMHints
480 *manager_hints;
481
482 XWindowInfo
483 context,
484 group_leader,
485 backdrop,
486 icon,
487 image,
488 info,
489 magnify,
490 pan,
491 command,
492 widget,
493 popup;
494
495 Atom
496 wm_protocols,
497 wm_delete_window,
498 wm_take_focus,
499 im_protocols,
500 im_remote_command,
501 im_update_widget,
502 im_update_colormap,
503 im_former_image,
504 im_retain_colors,
505 im_next_image,
506 im_exit,
507 dnd_protocols;
508} XWindows;
509
cristybcbda3f2011-09-03 13:01:22 +0000510extern MagickPrivate Cursor
cristy3ed852e2009-09-05 21:47:34 +0000511 XMakeCursor(Display *,Window,Colormap,char *,char *);
512
cristybcbda3f2011-09-03 13:01:22 +0000513extern MagickPrivate int
514 XCheckDefineCursor(Display *,Window,Cursor);
cristy3ed852e2009-09-05 21:47:34 +0000515
cristybcbda3f2011-09-03 13:01:22 +0000516extern MagickPrivate MagickBooleanType
cristy7c3af952011-10-20 16:04:16 +0000517 XAnnotateImage(Display *,const XPixelInfo *,XAnnotateInfo *,Image *,
518 ExceptionInfo *),
cristybcbda3f2011-09-03 13:01:22 +0000519 XComponentGenesis(void),
cristy6710d842011-10-20 23:23:00 +0000520 XDrawImage(Display *,const XPixelInfo *,XDrawInfo *,Image *,ExceptionInfo *),
521 XGetWindowColor(Display *,XWindows *,char *,ExceptionInfo *),
cristy3ed852e2009-09-05 21:47:34 +0000522 XMagickProgressMonitor(const char *,const MagickOffsetType,
523 const MagickSizeType,void *),
524 XMakeImage(Display *,const XResourceInfo *,XWindowInfo *,Image *,unsigned int,
cristy051718b2011-08-28 22:49:25 +0000525 unsigned int,ExceptionInfo *),
cristy1ffe9982013-04-13 16:46:51 +0000526 XQueryColorCompliance(const char *,XColor *);
cristy3ed852e2009-09-05 21:47:34 +0000527
cristybcbda3f2011-09-03 13:01:22 +0000528extern MagickPrivate void
cristy3ed852e2009-09-05 21:47:34 +0000529 XBestIconSize(Display *,XWindowInfo *,Image *),
530 XBestPixel(Display *,const Colormap,XColor *,unsigned int,XColor *),
531 XCheckRefreshWindows(Display *,XWindows *),
532 XClientMessage(Display *,const Window,const Atom,const Atom,const Time),
cristybcbda3f2011-09-03 13:01:22 +0000533 XComponentTerminus(void),
cristy6710d842011-10-20 23:23:00 +0000534 XConfigureImageColormap(Display *,XResourceInfo *,XWindows *,Image *,
535 ExceptionInfo *),
cristy3ed852e2009-09-05 21:47:34 +0000536 XConstrainWindowPosition(Display *,XWindowInfo *),
cristybb503372010-05-27 20:51:26 +0000537 XDelay(Display *,const size_t),
cristy6710d842011-10-20 23:23:00 +0000538 XDisplayImageInfo(Display *,const XResourceInfo *,XWindows *,Image *,Image *,
539 ExceptionInfo *),
cristy3ed852e2009-09-05 21:47:34 +0000540 XDestroyWindowColors(Display *,Window),
cristy3ed852e2009-09-05 21:47:34 +0000541 XFreeResources(Display *,XVisualInfo *,XStandardColormap *,XPixelInfo *,
542 XFontStruct *,XResourceInfo *,XWindowInfo *),
543 XFreeStandardColormap(Display *,const XVisualInfo *,XStandardColormap *,
544 XPixelInfo *),
545 XHighlightEllipse(Display *,Window,GC,const RectangleInfo *),
546 XHighlightLine(Display *,Window,GC,const XSegment *),
547 XHighlightRectangle(Display *,Window,GC,const RectangleInfo *),
548 XGetAnnotateInfo(XAnnotateInfo *),
cristy4c08aed2011-07-01 19:47:50 +0000549 XGetPixelInfo(Display *,const XVisualInfo *,const XStandardColormap *,
cristy3ed852e2009-09-05 21:47:34 +0000550 const XResourceInfo *,Image *,XPixelInfo *),
551 XGetMapInfo(const XVisualInfo *,const Colormap,XStandardColormap *),
cristy3ed852e2009-09-05 21:47:34 +0000552 XGetWindowInfo(Display *,XVisualInfo *,XStandardColormap *,XPixelInfo *,
553 XFontStruct *,XResourceInfo *,XWindowInfo *),
cristy6710d842011-10-20 23:23:00 +0000554 XMakeMagnifyImage(Display *,XWindows *,ExceptionInfo *),
cristy3ed852e2009-09-05 21:47:34 +0000555 XMakeStandardColormap(Display *,XVisualInfo *,XResourceInfo *,Image *,
cristy6710d842011-10-20 23:23:00 +0000556 XStandardColormap *,XPixelInfo *,ExceptionInfo *),
cristy3ed852e2009-09-05 21:47:34 +0000557 XMakeWindow(Display *,Window,char **,int,XClassHint *,XWMHints *,
558 XWindowInfo *),
559 XQueryPosition(Display *,const Window,int *,int *),
560 XRefreshWindow(Display *,const XWindowInfo *,const XEvent *),
cristy3ed852e2009-09-05 21:47:34 +0000561 XSetCursorState(Display *,XWindows *,const MagickStatusType),
562 XUserPreferences(XResourceInfo *),
563 XWarning(const ExceptionType,const char *,const char *);
564
cristybcbda3f2011-09-03 13:01:22 +0000565extern MagickPrivate Window
cristybb503372010-05-27 20:51:26 +0000566 XWindowByID(Display *,const Window,const size_t),
cristy3ed852e2009-09-05 21:47:34 +0000567 XWindowByName(Display *,const Window,const char *),
568 XWindowByProperty(Display *,const Window,const Atom);
569
cristybcbda3f2011-09-03 13:01:22 +0000570extern MagickPrivate XFontStruct
cristy3ed852e2009-09-05 21:47:34 +0000571 *XBestFont(Display *,const XResourceInfo *,const MagickBooleanType);
572
cristybcbda3f2011-09-03 13:01:22 +0000573extern MagickPrivate XVisualInfo
cristy3ed852e2009-09-05 21:47:34 +0000574 *XBestVisualInfo(Display *,XStandardColormap *,XResourceInfo *);
575
cristybcbda3f2011-09-03 13:01:22 +0000576extern MagickPrivate XWindows
cristy3ed852e2009-09-05 21:47:34 +0000577 *XInitializeWindows(Display *,XResourceInfo *),
578 *XSetWindows(XWindows *);
579
cristye3099b72011-09-08 18:21:13 +0000580extern MagickExport char
581 *XGetResourceClass(XrmDatabase,const char *,const char *,char *),
582 *XGetResourceInstance(XrmDatabase,const char *,const char *,const char *),
583 *XGetScreenDensity(Display *);
584
585extern MagickExport int
586 XError(Display *,XErrorEvent *);
587
588extern MagickExport MagickBooleanType
589 XRemoteCommand(Display *,const char *,const char *);
590
591extern MagickExport void
592 DestroyXResources(void),
593 XDestroyResourceInfo(XResourceInfo *),
594 XGetResourceInfo(const ImageInfo *,XrmDatabase,const char *,XResourceInfo *),
595 XRetainWindowColors(Display *,const Window);
596
597extern MagickExport XrmDatabase
598 XGetResourceDatabase(Display *,const char *);
599
cristya19f1d72012-08-07 18:24:38 +0000600static inline double XPixelIntensity(const XColor *pixel)
cristy3ed852e2009-09-05 21:47:34 +0000601{
cristyd7027ca2012-06-16 00:41:11 +0000602 double
603 blue,
604 green,
605 red;
606
cristyc8aff842012-12-24 16:59:46 +0000607 red=DecodePixelGamma((MagickRealType) pixel->red);
608 green=DecodePixelGamma((MagickRealType) pixel->green);
609 blue=DecodePixelGamma((MagickRealType) pixel->blue);
cristya86a5cb2012-10-14 13:40:33 +0000610 return(0.298839f*red+0.586811f*green+0.114350f*blue);
cristy3ed852e2009-09-05 21:47:34 +0000611}
612
613#endif
614
cristy1ffe9982013-04-13 16:46:51 +0000615extern MagickPrivate MagickBooleanType
616 XRenderImage(Image *,const DrawInfo *,const PointInfo *,TypeMetric *,
617 ExceptionInfo *);
618
cristy3ed852e2009-09-05 21:47:34 +0000619#if defined(__cplusplus) || defined(c_plusplus)
620}
621#endif
622
623#endif