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