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