blob: 38a37bfcf82583e189a82397085828cf05c893a7 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
cristyfe676ee2013-11-18 13:03:38 +00002 Copyright 1999-2014 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
cristyc2694c42013-04-14 12:28:58 +000025#include "MagickCore/draw.h"
cristy1ffe9982013-04-13 16:46:51 +000026#include "MagickCore/exception.h"
27#include "MagickCore/geometry.h"
28#include "MagickCore/pixel-accessor.h"
29#include "MagickCore/quantize.h"
30
cristy3ed852e2009-09-05 21:47:34 +000031#if defined(MAGICKCORE_X11_DELEGATE)
32
33#include <X11/Xos.h>
34#include <X11/Xlib.h>
35#include <X11/Xatom.h>
36#include <X11/cursorfont.h>
37#include <X11/keysym.h>
38#include <X11/Xresource.h>
39#include <X11/Xutil.h>
cristy3ed852e2009-09-05 21:47:34 +000040
41#if defined(__cplusplus) || defined(c_plusplus)
42# define klass c_class
43#else
44# define klass class
45#endif
46
47/*
48 Invoke pre-X11R6 ICCCM routines if XlibSpecificationRelease is not 6.
49*/
50#if XlibSpecificationRelease < 6
51#if !defined(PRE_R6_ICCCM)
52#define PRE_R6_ICCCM
53#endif
54#endif
55/*
56 Invoke pre-X11R5 ICCCM routines if XlibSpecificationRelease is not defined.
57*/
58#if !defined(XlibSpecificationRelease)
59#define PRE_R5_ICCCM
60#endif
61/*
62 Invoke pre-X11R4 ICCCM routines if PWinGravity is not defined.
63*/
64#if !defined(PWinGravity)
65#define PRE_R4_ICCCM
66#endif
67
68#define MaxIconSize 96
69#define MaxNumberPens 11
70#define MaxNumberFonts 11
71#define MaxXWindows 12
72#undef index
73
74#define ThrowXWindowException(severity,tag,context) \
75{ \
76 ExceptionInfo \
77 exception; \
78 \
79 GetExceptionInfo(&exception); \
80 (void) ThrowMagickException(&exception,GetMagickModule(),severity, \
anthonye5b39652012-04-21 05:37:29 +000081 tag == (const char *) NULL ? "unknown" : tag,"'%s': %s",context, \
cristy3ed852e2009-09-05 21:47:34 +000082 strerror(errno)); \
83 CatchException(&exception); \
84 (void) DestroyExceptionInfo(&exception); \
85}
86#define ThrowXWindowFatalException(severity,tag,context) \
87{ \
88 ThrowXWindowException(severity,tag,context); \
89 _exit(1); \
90}
91
92typedef enum
93{
94 ForegroundStencil,
95 BackgroundStencil,
96 OpaqueStencil,
97 TransparentStencil
98} AnnotationStencil;
99
100typedef enum
101{
102 UndefinedElement,
103 PointElement,
104 LineElement,
105 RectangleElement,
106 FillRectangleElement,
107 CircleElement,
108 FillCircleElement,
109 EllipseElement,
110 FillEllipseElement,
111 PolygonElement,
112 FillPolygonElement,
113 ColorElement,
114 MatteElement,
115 TextElement,
116 ImageElement
117} ElementType;
118
119typedef enum
120{
121 UndefinedColormap,
122 PrivateColormap,
123 SharedColormap
124} XColormapType;
125
126typedef struct _XDrawInfo
127{
128 int
129 x,
130 y;
131
132 unsigned int
133 width,
134 height;
135
136 double
137 degrees;
138
139 AnnotationStencil
140 stencil;
141
142 ElementType
143 element;
144
145 Pixmap
146 stipple;
147
148 unsigned int
149 line_width;
150
151 XSegment
152 line_info;
153
154 unsigned int
155 number_coordinates;
156
157 RectangleInfo
158 rectangle_info;
159
160 XPoint
161 *coordinate_info;
162
163 char
164 geometry[MaxTextExtent];
165} XDrawInfo;
166
167typedef enum
168{
169 DefaultState = 0x0000,
170 EscapeState = 0x0001,
171 ExitState = 0x0002,
172 FormerImageState = 0x0004,
173 ModifierState = 0x0008,
174 MontageImageState = 0x0010,
175 NextImageState = 0x0020,
176 RetainColorsState = 0x0040,
177 SuspendTime = 50,
178 UpdateConfigurationState = 0x0080,
179 UpdateRegionState = 0x0100
180} XState;
181
182typedef struct _XAnnotateInfo
183{
184 int
185 x,
186 y;
187
188 unsigned int
189 width,
190 height;
191
192 double
193 degrees;
194
195 XFontStruct
196 *font_info;
197
198 char
199 *text;
200
201 AnnotationStencil
202 stencil;
203
204 char
205 geometry[MaxTextExtent];
206
207 struct _XAnnotateInfo
208 *next,
209 *previous;
210} XAnnotateInfo;
211
212typedef struct _XPixelInfo
213{
cristyf2faecf2010-05-28 19:19:36 +0000214 ssize_t
215 colors;
216
217 unsigned long
cristy3ed852e2009-09-05 21:47:34 +0000218 *pixels;
219
220 XColor
221 foreground_color,
222 background_color,
223 border_color,
224 matte_color,
225 highlight_color,
226 shadow_color,
227 depth_color,
228 trough_color,
229 box_color,
230 pen_color,
231 pen_colors[MaxNumberPens];
232
233 GC
234 annotate_context,
235 highlight_context,
236 widget_context;
237
238 unsigned short
239 box_index,
240 pen_index;
241} XPixelInfo;
242
cristye3099b72011-09-08 18:21:13 +0000243typedef struct _XResourceInfo
cristy3ed852e2009-09-05 21:47:34 +0000244{
245 XrmDatabase
246 resource_database;
247
248 ImageInfo
249 *image_info;
250
251 QuantizeInfo
252 *quantize_info;
253
cristybb503372010-05-27 20:51:26 +0000254 size_t
cristy3ed852e2009-09-05 21:47:34 +0000255 colors;
256
257 MagickBooleanType
258 close_server,
259 backdrop;
260
261 char
262 *background_color,
263 *border_color;
264
265 char
266 *client_name;
267
268 XColormapType
269 colormap;
270
271 unsigned int
272 border_width;
273
cristybb503372010-05-27 20:51:26 +0000274 size_t
cristy3ed852e2009-09-05 21:47:34 +0000275 delay;
276
277 MagickBooleanType
278 color_recovery,
279 confirm_exit,
280 confirm_edit;
281
282 char
283 *display_gamma;
284
285 char
286 *font,
287 *font_name[MaxNumberFonts],
288 *foreground_color;
289
290 MagickBooleanType
291 display_warnings,
292 gamma_correct;
293
294 char
295 *icon_geometry;
296
297 MagickBooleanType
298 iconic,
299 immutable;
300
301 char
302 *image_geometry;
303
304 char
305 *map_type,
306 *matte_color,
307 *name;
308
309 unsigned int
310 magnify,
311 pause;
312
313 char
314 *pen_colors[MaxNumberPens];
315
316 char
317 *text_font,
318 *title;
319
320 int
321 quantum;
322
323 unsigned int
324 update;
325
326 MagickBooleanType
327 use_pixmap,
328 use_shared_memory;
329
cristybb503372010-05-27 20:51:26 +0000330 size_t
cristy3ed852e2009-09-05 21:47:34 +0000331 undo_cache;
332
333 char
334 *visual_type,
335 *window_group,
336 *window_id,
337 *write_filename;
338
339 Image
340 *copy_image;
341
342 int
343 gravity;
344
345 char
346 home_directory[MaxTextExtent];
cristye3099b72011-09-08 18:21:13 +0000347} XResourceInfo;
cristy3ed852e2009-09-05 21:47:34 +0000348
349typedef struct _XWindowInfo
350{
351 Window
352 id;
353
354 Window
355 root;
356
357 Visual
358 *visual;
359
360 unsigned int
361 storage_class,
362 depth;
363
364 XVisualInfo
365 *visual_info;
366
367 XStandardColormap
368 *map_info;
369
370 XPixelInfo
371 *pixel_info;
372
373 XFontStruct
374 *font_info;
375
376 GC
377 annotate_context,
378 highlight_context,
379 widget_context;
380
381 Cursor
382 cursor,
383 busy_cursor;
384
385 char
386 *name,
387 *geometry,
388 *icon_name,
389 *icon_geometry,
390 *crop_geometry;
391
cristybb503372010-05-27 20:51:26 +0000392 size_t
cristy3ed852e2009-09-05 21:47:34 +0000393 data,
394 flags;
395
396 int
397 x,
398 y;
399
400 unsigned int
401 width,
402 height,
403 min_width,
404 min_height,
405 width_inc,
406 height_inc,
407 border_width;
408
409 MagickBooleanType
410 use_pixmap,
411 immutable,
412 shape,
413 shared_memory;
414
415 int
416 screen;
417
418 XImage
419 *ximage,
420 *matte_image;
421
422 Pixmap
423 highlight_stipple,
424 shadow_stipple,
425 pixmap,
426 *pixmaps,
427 matte_pixmap,
428 *matte_pixmaps;
429
430 XSetWindowAttributes
431 attributes;
432
433 XWindowChanges
434 window_changes;
435
436 void
437 *segment_info;
438
cristy8891f9c2010-06-04 23:32:17 +0000439 long
cristy3ed852e2009-09-05 21:47:34 +0000440 mask;
441
442 MagickBooleanType
443 orphan,
444 mapped,
445 stasis;
446
447 Image
448 *image;
449
450 MagickBooleanType
451 destroy;
452} XWindowInfo;
453
454typedef struct _XWindows
455{
456 Display
457 *display;
458
459 XStandardColormap
460 *map_info,
461 *icon_map;
462
463 XVisualInfo
464 *visual_info,
465 *icon_visual;
466
467 XPixelInfo
468 *pixel_info,
469 *icon_pixel;
470
471 XFontStruct
472 *font_info;
473
474 XResourceInfo
475 *icon_resources;
476
477 XClassHint
478 *class_hints;
479
480 XWMHints
481 *manager_hints;
482
483 XWindowInfo
484 context,
485 group_leader,
486 backdrop,
487 icon,
488 image,
489 info,
490 magnify,
491 pan,
492 command,
493 widget,
494 popup;
495
496 Atom
497 wm_protocols,
498 wm_delete_window,
499 wm_take_focus,
500 im_protocols,
501 im_remote_command,
502 im_update_widget,
503 im_update_colormap,
504 im_former_image,
505 im_retain_colors,
506 im_next_image,
507 im_exit,
508 dnd_protocols;
509} XWindows;
510
cristybcbda3f2011-09-03 13:01:22 +0000511extern MagickPrivate Cursor
cristy3ed852e2009-09-05 21:47:34 +0000512 XMakeCursor(Display *,Window,Colormap,char *,char *);
513
cristybcbda3f2011-09-03 13:01:22 +0000514extern MagickPrivate int
515 XCheckDefineCursor(Display *,Window,Cursor);
cristy3ed852e2009-09-05 21:47:34 +0000516
cristybcbda3f2011-09-03 13:01:22 +0000517extern MagickPrivate MagickBooleanType
cristy7c3af952011-10-20 16:04:16 +0000518 XAnnotateImage(Display *,const XPixelInfo *,XAnnotateInfo *,Image *,
519 ExceptionInfo *),
cristybcbda3f2011-09-03 13:01:22 +0000520 XComponentGenesis(void),
cristy6710d842011-10-20 23:23:00 +0000521 XDrawImage(Display *,const XPixelInfo *,XDrawInfo *,Image *,ExceptionInfo *),
522 XGetWindowColor(Display *,XWindows *,char *,ExceptionInfo *),
cristy3ed852e2009-09-05 21:47:34 +0000523 XMagickProgressMonitor(const char *,const MagickOffsetType,
524 const MagickSizeType,void *),
525 XMakeImage(Display *,const XResourceInfo *,XWindowInfo *,Image *,unsigned int,
cristy051718b2011-08-28 22:49:25 +0000526 unsigned int,ExceptionInfo *),
cristy1ffe9982013-04-13 16:46:51 +0000527 XQueryColorCompliance(const char *,XColor *);
cristy3ed852e2009-09-05 21:47:34 +0000528
cristybcbda3f2011-09-03 13:01:22 +0000529extern MagickPrivate void
cristy3ed852e2009-09-05 21:47:34 +0000530 XBestIconSize(Display *,XWindowInfo *,Image *),
531 XBestPixel(Display *,const Colormap,XColor *,unsigned int,XColor *),
532 XCheckRefreshWindows(Display *,XWindows *),
533 XClientMessage(Display *,const Window,const Atom,const Atom,const Time),
cristybcbda3f2011-09-03 13:01:22 +0000534 XComponentTerminus(void),
cristy6710d842011-10-20 23:23:00 +0000535 XConfigureImageColormap(Display *,XResourceInfo *,XWindows *,Image *,
536 ExceptionInfo *),
cristy3ed852e2009-09-05 21:47:34 +0000537 XConstrainWindowPosition(Display *,XWindowInfo *),
cristybb503372010-05-27 20:51:26 +0000538 XDelay(Display *,const size_t),
cristy6710d842011-10-20 23:23:00 +0000539 XDisplayImageInfo(Display *,const XResourceInfo *,XWindows *,Image *,Image *,
540 ExceptionInfo *),
cristy3ed852e2009-09-05 21:47:34 +0000541 XDestroyWindowColors(Display *,Window),
cristy3ed852e2009-09-05 21:47:34 +0000542 XFreeResources(Display *,XVisualInfo *,XStandardColormap *,XPixelInfo *,
543 XFontStruct *,XResourceInfo *,XWindowInfo *),
544 XFreeStandardColormap(Display *,const XVisualInfo *,XStandardColormap *,
545 XPixelInfo *),
546 XHighlightEllipse(Display *,Window,GC,const RectangleInfo *),
547 XHighlightLine(Display *,Window,GC,const XSegment *),
548 XHighlightRectangle(Display *,Window,GC,const RectangleInfo *),
549 XGetAnnotateInfo(XAnnotateInfo *),
cristy4c08aed2011-07-01 19:47:50 +0000550 XGetPixelInfo(Display *,const XVisualInfo *,const XStandardColormap *,
cristy3ed852e2009-09-05 21:47:34 +0000551 const XResourceInfo *,Image *,XPixelInfo *),
552 XGetMapInfo(const XVisualInfo *,const Colormap,XStandardColormap *),
cristy3ed852e2009-09-05 21:47:34 +0000553 XGetWindowInfo(Display *,XVisualInfo *,XStandardColormap *,XPixelInfo *,
554 XFontStruct *,XResourceInfo *,XWindowInfo *),
cristy6710d842011-10-20 23:23:00 +0000555 XMakeMagnifyImage(Display *,XWindows *,ExceptionInfo *),
cristy3ed852e2009-09-05 21:47:34 +0000556 XMakeStandardColormap(Display *,XVisualInfo *,XResourceInfo *,Image *,
cristy6710d842011-10-20 23:23:00 +0000557 XStandardColormap *,XPixelInfo *,ExceptionInfo *),
cristy3ed852e2009-09-05 21:47:34 +0000558 XMakeWindow(Display *,Window,char **,int,XClassHint *,XWMHints *,
559 XWindowInfo *),
560 XQueryPosition(Display *,const Window,int *,int *),
561 XRefreshWindow(Display *,const XWindowInfo *,const XEvent *),
cristy3ed852e2009-09-05 21:47:34 +0000562 XSetCursorState(Display *,XWindows *,const MagickStatusType),
563 XUserPreferences(XResourceInfo *),
564 XWarning(const ExceptionType,const char *,const char *);
565
cristybcbda3f2011-09-03 13:01:22 +0000566extern MagickPrivate Window
cristybb503372010-05-27 20:51:26 +0000567 XWindowByID(Display *,const Window,const size_t),
cristy3ed852e2009-09-05 21:47:34 +0000568 XWindowByName(Display *,const Window,const char *),
569 XWindowByProperty(Display *,const Window,const Atom);
570
cristybcbda3f2011-09-03 13:01:22 +0000571extern MagickPrivate XFontStruct
cristy3ed852e2009-09-05 21:47:34 +0000572 *XBestFont(Display *,const XResourceInfo *,const MagickBooleanType);
573
cristybcbda3f2011-09-03 13:01:22 +0000574extern MagickPrivate XVisualInfo
cristy3ed852e2009-09-05 21:47:34 +0000575 *XBestVisualInfo(Display *,XStandardColormap *,XResourceInfo *);
576
cristybcbda3f2011-09-03 13:01:22 +0000577extern MagickPrivate XWindows
cristy3ed852e2009-09-05 21:47:34 +0000578 *XInitializeWindows(Display *,XResourceInfo *),
579 *XSetWindows(XWindows *);
580
cristye3099b72011-09-08 18:21:13 +0000581extern MagickExport char
582 *XGetResourceClass(XrmDatabase,const char *,const char *,char *),
583 *XGetResourceInstance(XrmDatabase,const char *,const char *,const char *),
584 *XGetScreenDensity(Display *);
585
586extern MagickExport int
587 XError(Display *,XErrorEvent *);
588
589extern MagickExport MagickBooleanType
590 XRemoteCommand(Display *,const char *,const char *);
591
592extern MagickExport void
593 DestroyXResources(void),
594 XDestroyResourceInfo(XResourceInfo *),
595 XGetResourceInfo(const ImageInfo *,XrmDatabase,const char *,XResourceInfo *),
596 XRetainWindowColors(Display *,const Window);
597
598extern MagickExport XrmDatabase
599 XGetResourceDatabase(Display *,const char *);
600
cristya19f1d72012-08-07 18:24:38 +0000601static inline double XPixelIntensity(const XColor *pixel)
cristy3ed852e2009-09-05 21:47:34 +0000602{
cristyd7027ca2012-06-16 00:41:11 +0000603 double
cristyd3d2a272013-06-24 16:09:41 +0000604 intensity;
cristyd7027ca2012-06-16 00:41:11 +0000605
cristyd3d2a272013-06-24 16:09:41 +0000606 if ((pixel->red == pixel->green) && (pixel->green == pixel->blue))
607 return((double) pixel->red);
608 intensity=0.212656*pixel->red+0.715158*pixel->green+0.072186*pixel->blue;
609 return(intensity);
cristy3ed852e2009-09-05 21:47:34 +0000610}
611
612#endif
613
cristy1ffe9982013-04-13 16:46:51 +0000614extern MagickPrivate MagickBooleanType
615 XRenderImage(Image *,const DrawInfo *,const PointInfo *,TypeMetric *,
616 ExceptionInfo *);
617
cristy3ed852e2009-09-05 21:47:34 +0000618#if defined(__cplusplus) || defined(c_plusplus)
619}
620#endif
621
622#endif