2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 % W W IIIII DDDD GGGG EEEEE TTTTT %
9 % W W W I D D G GG EEE T %
10 % WW WW I D D G G E T %
11 % W W IIIII DDDD GGGG EEEEE T %
14 % MagickCore X11 User Interface Methods %
21 % Copyright 1999-2017 ImageMagick Studio LLC, a non-profit organization %
22 % dedicated to making software imaging solutions freely available. %
24 % You may not use this file except in compliance with the License. You may %
25 % obtain a copy of the License at %
27 % https://www.imagemagick.org/script/license.php %
29 % Unless required by applicable law or agreed to in writing, software %
30 % distributed under the License is distributed on an "AS IS" BASIS, %
31 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
32 % See the License for the specific language governing permissions and %
33 % limitations under the License. %
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 #include "MagickCore/studio.h"
44 #include "MagickCore/color.h"
45 #include "MagickCore/color-private.h"
46 #include "MagickCore/exception.h"
47 #include "MagickCore/exception-private.h"
48 #include "MagickCore/image.h"
49 #include "MagickCore/magick.h"
50 #include "MagickCore/memory_.h"
51 #include "MagickCore/string_.h"
52 #include "MagickCore/token.h"
53 #include "MagickCore/token-private.h"
54 #include "MagickCore/utility.h"
55 #include "MagickCore/utility-private.h"
56 #include "MagickCore/xwindow-private.h"
57 #include "MagickCore/widget.h"
58 #include "MagickCore/widget-private.h"
60 #if defined(MAGICKCORE_X11_DELEGATE)
65 #define AreaIsActive(matte_info,position) ( \
66 ((position.y >= (int) (matte_info.y-matte_info.bevel_width)) && \
67 (position.y < (int) (matte_info.y+matte_info.height+matte_info.bevel_width))) \
68 ? MagickTrue : MagickFalse)
69 #define Extent(s) ((int) strlen(s))
70 #define MatteIsActive(matte_info,position) ( \
71 ((position.x >= (int) (matte_info.x-matte_info.bevel_width)) && \
72 (position.y >= (int) (matte_info.y-matte_info.bevel_width)) && \
73 (position.x < (int) (matte_info.x+matte_info.width+matte_info.bevel_width)) && \
74 (position.y < (int) (matte_info.y+matte_info.height+matte_info.bevel_width))) \
75 ? MagickTrue : MagickFalse)
76 #define MaxTextWidth ((unsigned int) (255*XTextWidth(font_info,"_",1)))
77 #define MinTextWidth (26*XTextWidth(font_info,"_",1))
78 #define QuantumMargin MagickMax(font_info->max_bounds.width,12)
79 #define WidgetTextWidth(font_info,text) \
80 ((unsigned int) XTextWidth(font_info,text,Extent(text)))
81 #define WindowIsActive(window_info,position) ( \
82 ((position.x >= 0) && (position.y >= 0) && \
83 (position.x < (int) window_info.width) && \
84 (position.y < (int) window_info.height)) ? MagickTrue : MagickFalse)
91 ControlState = 0x0001,
92 InactiveWidgetState = 0x0004,
93 JumpListState = 0x0008,
94 RedrawActionState = 0x0010,
95 RedrawListState = 0x0020,
96 RedrawWidgetState = 0x0040,
97 UpdateListState = 0x0100
101 Typedef declarations.
103 typedef struct _XWidgetInfo
133 Variable declarations.
138 (char *) NULL, (char *) NULL, (char *) NULL, 0, 0, 0, 0, 0, 0, 0, 0,
139 MagickFalse, MagickFalse, MagickFalse, MagickFalse, MagickFalse
143 (char *) NULL, (char *) NULL, (char *) NULL, 0, 0, 0, 0, 0, 0, 0, 0,
144 MagickFalse, MagickFalse, MagickFalse, MagickFalse, MagickFalse
146 *selection_info = (XWidgetInfo *) NULL,
149 (char *) NULL, (char *) NULL, (char *) NULL, 0, 0, 0, 0, 0, 0, 0, 0,
150 MagickFalse, MagickFalse, MagickFalse, MagickFalse, MagickFalse
154 Constant declarations.
164 XDrawMatte(Display *,const XWindowInfo *,const XWidgetInfo *),
165 XSetBevelColor(Display *,const XWindowInfo *,const MagickStatusType),
166 XSetMatteColor(Display *,const XWindowInfo *,const MagickStatusType),
167 XSetTextColor(Display *,const XWindowInfo *,const MagickStatusType);
170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
174 % D e s t r o y X W i d g e t %
178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
180 % DestroyXWidget() destroys resources associated with the X widget.
182 % The format of the DestroyXWidget method is:
184 % void DestroyXWidget()
186 % A description of each parameter follows:
189 MagickPrivate void DestroyXWidget(void)
191 if (selection_info != (XWidgetInfo *) NULL)
192 selection_info=(XWidgetInfo *) RelinquishMagickMemory(selection_info);
196 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
200 + X D r a w B e v e l %
204 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
206 % XDrawBevel() "sets off" an area with a highlighted upper and left bevel and
207 % a shadowed lower and right bevel. The highlighted and shadowed bevels
208 % create a 3-D effect.
210 % The format of the XDrawBevel function is:
212 % XDrawBevel(display,window_info,bevel_info)
214 % A description of each parameter follows:
216 % o display: Specifies a pointer to the Display structure; returned from
219 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
221 % o bevel_info: Specifies a pointer to a XWidgetInfo structure. It
222 % contains the extents of the bevel.
225 static void XDrawBevel(Display *display,const XWindowInfo *window_info,
226 const XWidgetInfo *bevel_info)
241 Draw upper and left beveled border.
244 y1=bevel_info->y+bevel_info->height;
245 x2=bevel_info->x+bevel_info->width;
247 bevel_width=bevel_info->bevel_width;
254 points[3].x=x2+bevel_width;
255 points[3].y=y2-bevel_width;
256 points[4].x=x1-bevel_width;
257 points[4].y=y2-bevel_width;
258 points[5].x=x1-bevel_width;
259 points[5].y=y1+bevel_width;
260 XSetBevelColor(display,window_info,bevel_info->raised);
261 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
262 points,6,Complex,CoordModeOrigin);
264 Draw lower and right beveled border.
272 points[3].x=x2+bevel_width;
273 points[3].y=y2-bevel_width;
274 points[4].x=x2+bevel_width;
275 points[4].y=y1+bevel_width;
276 points[5].x=x1-bevel_width;
277 points[5].y=y1+bevel_width;
278 XSetBevelColor(display,window_info,!bevel_info->raised);
279 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
280 points,6,Complex,CoordModeOrigin);
281 (void) XSetFillStyle(display,window_info->widget_context,FillSolid);
285 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
289 + X D r a w B e v e l e d B u t t o n %
293 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
295 % XDrawBeveledButton() draws a button with a highlighted upper and left bevel
296 % and a shadowed lower and right bevel. The highlighted and shadowed bevels
297 % create a 3-D effect.
299 % The format of the XDrawBeveledButton function is:
301 % XDrawBeveledButton(display,window_info,button_info)
303 % A description of each parameter follows:
305 % o display: Specifies a pointer to the Display structure; returned from
308 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
310 % o button_info: Specifies a pointer to a XWidgetInfo structure. It
311 % contains the extents of the button.
315 static void XDrawBeveledButton(Display *display,const XWindowInfo *window_info,
316 const XWidgetInfo *button_info)
334 XDrawBevel(display,window_info,button_info);
335 XSetMatteColor(display,window_info,button_info->raised);
336 (void) XFillRectangle(display,window_info->id,window_info->widget_context,
337 button_info->x,button_info->y,button_info->width,button_info->height);
338 x=button_info->x-button_info->bevel_width-1;
339 y=button_info->y-button_info->bevel_width-1;
340 (void) XSetForeground(display,window_info->widget_context,
341 window_info->pixel_info->trough_color.pixel);
342 if (button_info->raised || (window_info->depth == 1))
343 (void) XDrawRectangle(display,window_info->id,window_info->widget_context,
344 x,y,button_info->width+(button_info->bevel_width << 1)+1,
345 button_info->height+(button_info->bevel_width << 1)+1);
346 if (button_info->text == (char *) NULL)
351 crop_info.width=(unsigned short) button_info->width;
352 crop_info.height=(unsigned short) button_info->height;
353 crop_info.x=button_info->x;
354 crop_info.y=button_info->y;
358 font_info=window_info->font_info;
359 width=WidgetTextWidth(font_info,button_info->text);
360 x=button_info->x+(QuantumMargin >> 1);
361 if (button_info->center)
362 x=button_info->x+(button_info->width >> 1)-(width >> 1);
363 y=button_info->y+((button_info->height-
364 (font_info->ascent+font_info->descent)) >> 1)+font_info->ascent;
365 if ((int) button_info->width == (QuantumMargin >> 1))
368 Option button-- write label to right of button.
370 XSetTextColor(display,window_info,MagickTrue);
371 x=button_info->x+button_info->width+button_info->bevel_width+
372 (QuantumMargin >> 1);
373 (void) XDrawString(display,window_info->id,window_info->widget_context,
374 x,y,button_info->text,Extent(button_info->text));
377 (void) XSetClipRectangles(display,window_info->widget_context,0,0,&crop_info,
379 XSetTextColor(display,window_info,button_info->raised);
380 (void) XDrawString(display,window_info->id,window_info->widget_context,x,y,
381 button_info->text,Extent(button_info->text));
382 (void) XSetClipMask(display,window_info->widget_context,None);
383 if (button_info->raised == MagickFalse)
384 XDelay(display,SuspendTime << 2);
388 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
392 + X D r a w B e v e l e d M a t t e %
396 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
398 % XDrawBeveledMatte() draws a matte with a shadowed upper and left bevel and
399 % a highlighted lower and right bevel. The highlighted and shadowed bevels
400 % create a 3-D effect.
402 % The format of the XDrawBeveledMatte function is:
404 % XDrawBeveledMatte(display,window_info,matte_info)
406 % A description of each parameter follows:
408 % o display: Specifies a pointer to the Display structure; returned from
411 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
413 % o matte_info: Specifies a pointer to a XWidgetInfo structure. It
414 % contains the extents of the matte.
417 static void XDrawBeveledMatte(Display *display,const XWindowInfo *window_info,
418 const XWidgetInfo *matte_info)
423 XDrawBevel(display,window_info,matte_info);
424 XDrawMatte(display,window_info,matte_info);
428 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
432 + X D r a w M a t t e %
436 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
438 % XDrawMatte() fills a rectangular area with the matte color.
440 % The format of the XDrawMatte function is:
442 % XDrawMatte(display,window_info,matte_info)
444 % A description of each parameter follows:
446 % o display: Specifies a pointer to the Display structure; returned from
449 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
451 % o matte_info: Specifies a pointer to a XWidgetInfo structure. It
452 % contains the extents of the matte.
455 static void XDrawMatte(Display *display,const XWindowInfo *window_info,
456 const XWidgetInfo *matte_info)
461 if ((matte_info->trough == MagickFalse) || (window_info->depth == 1))
462 (void) XFillRectangle(display,window_info->id,
463 window_info->highlight_context,matte_info->x,matte_info->y,
464 matte_info->width,matte_info->height);
467 (void) XSetForeground(display,window_info->widget_context,
468 window_info->pixel_info->trough_color.pixel);
469 (void) XFillRectangle(display,window_info->id,window_info->widget_context,
470 matte_info->x,matte_info->y,matte_info->width,matte_info->height);
475 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
479 + X D r a w M a t t e T e x t %
483 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
485 % XDrawMatteText() draws a matte with text. If the text exceeds the extents
486 % of the text, a portion of the text relative to the cursor is displayed.
488 % The format of the XDrawMatteText function is:
490 % XDrawMatteText(display,window_info,text_info)
492 % A description of each parameter follows:
494 % o display: Specifies a pointer to the Display structure; returned from
497 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
499 % o text_info: Specifies a pointer to a XWidgetInfo structure. It
500 % contains the extents of the text.
503 static void XDrawMatteText(Display *display,const XWindowInfo *window_info,
504 XWidgetInfo *text_info)
530 XSetMatteColor(display,window_info,MagickFalse);
531 (void) XFillRectangle(display,window_info->id,window_info->widget_context,
532 text_info->x,text_info->y,text_info->width,text_info->height);
533 if (text_info->text == (char *) NULL)
535 XSetTextColor(display,window_info,text_info->highlight);
536 font_info=window_info->font_info;
537 x=text_info->x+(QuantumMargin >> 2);
538 y=text_info->y+font_info->ascent+(text_info->height >> 2);
539 width=text_info->width-(QuantumMargin >> 1);
540 height=(unsigned int) (font_info->ascent+font_info->descent);
541 if (*text_info->text == '\0')
544 No text-- just draw cursor.
546 (void) XDrawLine(display,window_info->id,window_info->annotate_context,
553 crop_info.width=(unsigned short) text_info->width;
554 crop_info.height=(unsigned short) text_info->height;
555 crop_info.x=text_info->x;
556 crop_info.y=text_info->y;
558 Determine beginning of the visible text.
560 if (text_info->cursor < text_info->marker)
561 text_info->marker=text_info->cursor;
564 text=text_info->marker;
565 if (XTextWidth(font_info,(char *) text,(int) (text_info->cursor-text)) >
568 text=text_info->text;
569 for (i=0; i < Extent(text); i++)
571 n=XTextWidth(font_info,(char *) text+i,(int)
572 (text_info->cursor-text-i));
573 if (n <= (int) width)
576 text_info->marker=(char *) text+i;
580 Draw text and cursor.
582 if (text_info->highlight == MagickFalse)
584 (void) XSetClipRectangles(display,window_info->widget_context,0,0,
585 &crop_info,1,Unsorted);
586 (void) XDrawString(display,window_info->id,window_info->widget_context,
587 x,y,text_info->marker,Extent(text_info->marker));
588 (void) XSetClipMask(display,window_info->widget_context,None);
592 (void) XSetClipRectangles(display,window_info->annotate_context,0,0,
593 &crop_info,1,Unsorted);
594 width=WidgetTextWidth(font_info,text_info->marker);
595 (void) XFillRectangle(display,window_info->id,
596 window_info->annotate_context,x,y-font_info->ascent,width,height);
597 (void) XSetClipMask(display,window_info->annotate_context,None);
598 (void) XSetClipRectangles(display,window_info->highlight_context,0,0,
599 &crop_info,1,Unsorted);
600 (void) XDrawString(display,window_info->id,
601 window_info->highlight_context,x,y,text_info->marker,
602 Extent(text_info->marker));
603 (void) XSetClipMask(display,window_info->highlight_context,None);
605 x+=XTextWidth(font_info,text_info->marker,(int)
606 (text_info->cursor-text_info->marker));
607 (void) XDrawLine(display,window_info->id,window_info->annotate_context,x,y+3,
612 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
616 + X D r a w T r i a n g l e E a s t %
620 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
622 % XDrawTriangleEast() draws a triangle with a highlighted left bevel and a
623 % shadowed right and lower bevel. The highlighted and shadowed bevels create
626 % The format of the XDrawTriangleEast function is:
628 % XDrawTriangleEast(display,window_info,triangle_info)
630 % A description of each parameter follows:
632 % o display: Specifies a pointer to the Display structure; returned from
635 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
637 % o triangle_info: Specifies a pointer to a XWidgetInfo structure. It
638 % contains the extents of the triangle.
641 static void XDrawTriangleEast(Display *display,const XWindowInfo *window_info,
642 const XWidgetInfo *triangle_info)
666 x2=triangle_info->x+triangle_info->width;
667 y2=triangle_info->y+(triangle_info->height >> 1);
669 y3=triangle_info->y+triangle_info->height;
670 bevel_width=triangle_info->bevel_width;
677 XSetMatteColor(display,window_info,triangle_info->raised);
678 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
679 points,3,Complex,CoordModeOrigin);
687 points[2].x=x3-bevel_width;
688 points[2].y=y3+bevel_width;
689 points[3].x=x2+bevel_width;
691 XSetBevelColor(display,window_info,!triangle_info->raised);
692 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
693 points,4,Complex,CoordModeOrigin);
701 points[2].x=x1-bevel_width+1;
702 points[2].y=y1-bevel_width;
703 points[3].x=x3-bevel_width+1;
704 points[3].y=y3+bevel_width;
705 XSetBevelColor(display,window_info,triangle_info->raised);
706 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
707 points,4,Complex,CoordModeOrigin);
715 points[2].x=x2+bevel_width;
717 points[3].x=x1-bevel_width;
718 points[3].y=y1-bevel_width;
719 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
720 points,4,Complex,CoordModeOrigin);
721 (void) XSetFillStyle(display,window_info->widget_context,FillSolid);
722 if (triangle_info->text == (char *) NULL)
725 Write label to right of triangle.
727 font_info=window_info->font_info;
728 XSetTextColor(display,window_info,MagickTrue);
729 x1=triangle_info->x+triangle_info->width+triangle_info->bevel_width+
730 (QuantumMargin >> 1);
731 y1=triangle_info->y+((triangle_info->height-
732 (font_info->ascent+font_info->descent)) >> 1)+font_info->ascent;
733 (void) XDrawString(display,window_info->id,window_info->widget_context,x1,y1,
734 triangle_info->text,Extent(triangle_info->text));
738 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
742 + X D r a w T r i a n g l e N o r t h %
746 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
748 % XDrawTriangleNorth() draws a triangle with a highlighted left bevel and a
749 % shadowed right and lower bevel. The highlighted and shadowed bevels create
752 % The format of the XDrawTriangleNorth function is:
754 % XDrawTriangleNorth(display,window_info,triangle_info)
756 % A description of each parameter follows:
758 % o display: Specifies a pointer to the Display structure; returned from
761 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
763 % o triangle_info: Specifies a pointer to a XWidgetInfo structure. It
764 % contains the extents of the triangle.
767 static void XDrawTriangleNorth(Display *display,const XWindowInfo *window_info,
768 const XWidgetInfo *triangle_info)
788 y1=triangle_info->y+triangle_info->height;
789 x2=triangle_info->x+(triangle_info->width >> 1);
791 x3=triangle_info->x+triangle_info->width;
792 y3=triangle_info->y+triangle_info->height;
793 bevel_width=triangle_info->bevel_width;
800 XSetMatteColor(display,window_info,triangle_info->raised);
801 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
802 points,3,Complex,CoordModeOrigin);
811 points[2].y=y2-bevel_width-2;
812 points[3].x=x1-bevel_width-1;
813 points[3].y=y1+bevel_width;
814 XSetBevelColor(display,window_info,triangle_info->raised);
815 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
816 points,4,Complex,CoordModeOrigin);
824 points[2].x=x3+bevel_width;
825 points[2].y=y3+bevel_width;
827 points[3].y=y2-bevel_width;
828 XSetBevelColor(display,window_info,!triangle_info->raised);
829 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
830 points,4,Complex,CoordModeOrigin);
838 points[2].x=x1-bevel_width;
839 points[2].y=y1+bevel_width;
840 points[3].x=x3+bevel_width;
841 points[3].y=y3+bevel_width;
842 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
843 points,4,Complex,CoordModeOrigin);
844 (void) XSetFillStyle(display,window_info->widget_context,FillSolid);
848 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
852 + X D r a w T r i a n g l e S o u t h %
856 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
858 % XDrawTriangleSouth() draws a border with a highlighted left and right bevel
859 % and a shadowed lower bevel. The highlighted and shadowed bevels create a
862 % The format of the XDrawTriangleSouth function is:
864 % XDrawTriangleSouth(display,window_info,triangle_info)
866 % A description of each parameter follows:
868 % o display: Specifies a pointer to the Display structure; returned from
871 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
873 % o triangle_info: Specifies a pointer to a XWidgetInfo structure. It
874 % contains the extents of the triangle.
877 static void XDrawTriangleSouth(Display *display,const XWindowInfo *window_info,
878 const XWidgetInfo *triangle_info)
899 x2=triangle_info->x+(triangle_info->width >> 1);
900 y2=triangle_info->y+triangle_info->height;
901 x3=triangle_info->x+triangle_info->width;
903 bevel_width=triangle_info->bevel_width;
910 XSetMatteColor(display,window_info,triangle_info->raised);
911 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
912 points,3,Complex,CoordModeOrigin);
920 points[2].x=x1-bevel_width;
921 points[2].y=y1-bevel_width;
922 points[3].x=x3+bevel_width;
923 points[3].y=y3-bevel_width;
924 XSetBevelColor(display,window_info,triangle_info->raised);
925 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
926 points,4,Complex,CoordModeOrigin);
933 points[1].y=y3-bevel_width;
934 points[2].x=x3+bevel_width;
935 points[2].y=y3-bevel_width;
937 points[3].y=y2+bevel_width;
938 XSetBevelColor(display,window_info,!triangle_info->raised);
939 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
940 points,4,Complex,CoordModeOrigin);
949 points[2].y=y2+bevel_width;
950 points[3].x=x1-bevel_width;
951 points[3].y=y1-bevel_width;
952 XSetBevelColor(display,window_info,triangle_info->raised);
953 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
954 points,4,Complex,CoordModeOrigin);
955 (void) XSetFillStyle(display,window_info->widget_context,FillSolid);
959 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
963 + X D r a w W i d g e t T e x t %
967 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
969 % XDrawWidgetText() first clears the widget and draws a text string justifed
970 % left (or center) in the x-direction and centered within the y-direction.
972 % The format of the XDrawWidgetText function is:
974 % XDrawWidgetText(display,window_info,text_info)
976 % A description of each parameter follows:
978 % o display: Specifies a pointer to the Display structure; returned from
981 % o window_info: Specifies a pointer to a XWindowText structure.
983 % o text_info: Specifies a pointer to XWidgetInfo structure.
986 static void XDrawWidgetText(Display *display,const XWindowInfo *window_info,
987 XWidgetInfo *text_info)
1007 Clear the text area.
1009 widget_context=window_info->annotate_context;
1010 if (text_info->raised)
1011 (void) XClearArea(display,window_info->id,text_info->x,text_info->y,
1012 text_info->width,text_info->height,MagickFalse);
1015 (void) XFillRectangle(display,window_info->id,widget_context,text_info->x,
1016 text_info->y,text_info->width,text_info->height);
1017 widget_context=window_info->highlight_context;
1019 if (text_info->text == (char *) NULL)
1021 if (*text_info->text == '\0')
1024 Set cropping region.
1026 font_info=window_info->font_info;
1027 crop_info.width=(unsigned short) text_info->width;
1028 crop_info.height=(unsigned short) text_info->height;
1029 crop_info.x=text_info->x;
1030 crop_info.y=text_info->y;
1034 width=WidgetTextWidth(font_info,text_info->text);
1035 x=text_info->x+(QuantumMargin >> 1);
1036 if (text_info->center)
1037 x=text_info->x+(text_info->width >> 1)-(width >> 1);
1038 if (text_info->raised)
1039 if (width > (text_info->width-QuantumMargin))
1040 x+=(text_info->width-QuantumMargin-width);
1041 height=(unsigned int) (font_info->ascent+font_info->descent);
1042 y=text_info->y+((text_info->height-height) >> 1)+font_info->ascent;
1043 (void) XSetClipRectangles(display,widget_context,0,0,&crop_info,1,Unsorted);
1044 (void) XDrawString(display,window_info->id,widget_context,x,y,text_info->text,
1045 Extent(text_info->text));
1046 (void) XSetClipMask(display,widget_context,None);
1047 if (x < text_info->x)
1048 (void) XDrawLine(display,window_info->id,window_info->annotate_context,
1049 text_info->x,text_info->y,text_info->x,text_info->y+text_info->height-1);
1053 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1057 + X E d i t T e x t %
1061 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1063 % XEditText() edits a text string as indicated by the key symbol.
1065 % The format of the XEditText function is:
1067 % XEditText(display,text_info,key_symbol,text,state)
1069 % A description of each parameter follows:
1071 % o display: Specifies a connection to an X server; returned from
1074 % o text_info: Specifies a pointer to a XWidgetInfo structure. It
1075 % contains the extents of the text.
1077 % o key_symbol: A X11 KeySym that indicates what editing function to
1078 % perform to the text.
1080 % o text: A character string to insert into the text.
1082 % o state: An size_t that indicates whether the key symbol is a
1083 % control character or not.
1086 static void XEditText(Display *display,XWidgetInfo *text_info,
1087 const KeySym key_symbol,char *text,const size_t state)
1089 switch ((int) key_symbol)
1094 if (text_info->highlight)
1097 Erase the entire line of text.
1099 *text_info->text='\0';
1100 text_info->cursor=text_info->text;
1101 text_info->marker=text_info->text;
1102 text_info->highlight=MagickFalse;
1105 Erase one character.
1107 if (text_info->cursor != text_info->text)
1109 text_info->cursor--;
1110 (void) CopyMagickString(text_info->cursor,text_info->cursor+1,
1112 text_info->highlight=MagickFalse;
1120 Move cursor one position left.
1122 if (text_info->cursor == text_info->text)
1124 text_info->cursor--;
1131 Move cursor one position right.
1133 if (text_info->cursor == (text_info->text+Extent(text_info->text)))
1135 text_info->cursor++;
1147 if (state & ControlState)
1151 if ((Extent(text_info->text)+1) >= (int) MagickPathExtent)
1152 (void) XBell(display,0);
1155 if (text_info->highlight)
1158 Erase the entire line of text.
1160 *text_info->text='\0';
1161 text_info->cursor=text_info->text;
1162 text_info->marker=text_info->text;
1163 text_info->highlight=MagickFalse;
1166 Insert a string into the text.
1168 q=text_info->text+Extent(text_info->text)+strlen(text);
1169 for (i=0; i <= Extent(text_info->cursor); i++)
1171 *q=(*(q-Extent(text)));
1175 for (i=0; i < Extent(text); i++)
1176 *text_info->cursor++=(*p++);
1184 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1188 + X G e t W i d g e t I n f o %
1192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1194 % XGetWidgetInfo() initializes the XWidgetInfo structure.
1196 % The format of the XGetWidgetInfo function is:
1198 % XGetWidgetInfo(text,widget_info)
1200 % A description of each parameter follows:
1202 % o text: A string of characters associated with the widget.
1204 % o widget_info: Specifies a pointer to a X11 XWidgetInfo structure.
1207 static void XGetWidgetInfo(const char *text,XWidgetInfo *widget_info)
1210 Initialize widget info.
1212 widget_info->id=(~0);
1213 widget_info->bevel_width=3;
1214 widget_info->width=1;
1215 widget_info->height=1;
1218 widget_info->min_y=0;
1219 widget_info->max_y=0;
1220 widget_info->raised=MagickTrue;
1221 widget_info->active=MagickFalse;
1222 widget_info->center=MagickTrue;
1223 widget_info->trough=MagickFalse;
1224 widget_info->highlight=MagickFalse;
1225 widget_info->text=(char *) text;
1226 widget_info->cursor=(char *) text;
1227 if (text != (char *) NULL)
1228 widget_info->cursor+=Extent(text);
1229 widget_info->marker=(char *) text;
1233 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1237 + X H i g h l i g h t W i d g e t %
1241 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1243 % XHighlightWidget() draws a highlighted border around a window.
1245 % The format of the XHighlightWidget function is:
1247 % XHighlightWidget(display,window_info,x,y)
1249 % A description of each parameter follows:
1251 % o display: Specifies a pointer to the Display structure; returned from
1254 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
1256 % o x: Specifies an integer representing the rectangle offset in the
1259 % o y: Specifies an integer representing the rectangle offset in the
1263 static void XHighlightWidget(Display *display,const XWindowInfo *window_info,
1264 const int x,const int y)
1267 Draw the widget highlighting rectangle.
1269 XSetBevelColor(display,window_info,MagickTrue);
1270 (void) XDrawRectangle(display,window_info->id,window_info->widget_context,x,y,
1271 window_info->width-(x << 1),window_info->height-(y << 1));
1272 (void) XDrawRectangle(display,window_info->id,window_info->widget_context,
1273 x-1,y-1,window_info->width-(x << 1)+1,window_info->height-(y << 1)+1);
1274 XSetBevelColor(display,window_info,MagickFalse);
1275 (void) XDrawRectangle(display,window_info->id,window_info->widget_context,
1276 x-1,y-1,window_info->width-(x << 1),window_info->height-(y << 1));
1277 (void) XSetFillStyle(display,window_info->widget_context,FillSolid);
1281 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1285 + X S c r e e n E v e n t %
1289 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1291 % XScreenEvent() returns MagickTrue if the any event on the X server queue is
1292 % associated with the widget window.
1294 % The format of the XScreenEvent function is:
1296 % int XScreenEvent(Display *display,XEvent *event,char *data)
1298 % A description of each parameter follows:
1300 % o display: Specifies a pointer to the Display structure; returned from
1303 % o event: Specifies a pointer to a X11 XEvent structure.
1305 % o data: Specifies a pointer to a XWindows structure.
1309 #if defined(__cplusplus) || defined(c_plusplus)
1313 static int XScreenEvent(Display *display,XEvent *event,char *data)
1318 windows=(XWindows *) data;
1319 if (event->xany.window == windows->popup.id)
1321 if (event->type == MapNotify)
1322 windows->popup.mapped=MagickTrue;
1323 if (event->type == UnmapNotify)
1324 windows->popup.mapped=MagickFalse;
1327 if (event->xany.window == windows->widget.id)
1329 if (event->type == MapNotify)
1330 windows->widget.mapped=MagickTrue;
1331 if (event->type == UnmapNotify)
1332 windows->widget.mapped=MagickFalse;
1335 switch (event->type)
1339 if ((event->xbutton.button == Button3) &&
1340 (event->xbutton.state & Mod1Mask))
1343 Convert Alt-Button3 to Button2.
1345 event->xbutton.button=Button2;
1346 event->xbutton.state&=(~Mod1Mask);
1352 if (event->xexpose.window == windows->image.id)
1354 XRefreshWindow(display,&windows->image,event);
1357 if (event->xexpose.window == windows->magnify.id)
1358 if (event->xexpose.count == 0)
1359 if (windows->magnify.mapped)
1364 exception=AcquireExceptionInfo();
1365 XMakeMagnifyImage(display,windows,exception);
1366 exception=DestroyExceptionInfo(exception);
1369 if (event->xexpose.window == windows->command.id)
1370 if (event->xexpose.count == 0)
1372 (void) XCommandWidget(display,windows,(const char **) NULL,event);
1380 Set input focus for backdrop window.
1382 if (event->xfocus.window == windows->image.id)
1383 (void) XSetInputFocus(display,windows->image.id,RevertToNone,
1391 case SelectionNotify:
1396 return(MagickFalse);
1399 #if defined(__cplusplus) || defined(c_plusplus)
1404 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1408 + X S e t B e v e l C o l o r %
1412 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1414 % XSetBevelColor() sets the graphic context for drawing a beveled border.
1416 % The format of the XSetBevelColor function is:
1418 % XSetBevelColor(display,window_info,raised)
1420 % A description of each parameter follows:
1422 % o display: Specifies a pointer to the Display structure; returned from
1425 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
1427 % o raised: A value other than zero indicates the color show be a
1428 % "highlight" color, otherwise the "shadow" color is set.
1431 static void XSetBevelColor(Display *display,const XWindowInfo *window_info,
1432 const MagickStatusType raised)
1434 if (window_info->depth == 1)
1442 (void) XSetBackground(display,window_info->widget_context,
1443 XBlackPixel(display,window_info->screen));
1444 (void) XSetForeground(display,window_info->widget_context,
1445 XWhitePixel(display,window_info->screen));
1446 (void) XSetFillStyle(display,window_info->widget_context,
1447 FillOpaqueStippled);
1448 stipple=window_info->highlight_stipple;
1449 if (raised == MagickFalse)
1450 stipple=window_info->shadow_stipple;
1451 (void) XSetStipple(display,window_info->widget_context,stipple);
1455 (void) XSetForeground(display,window_info->widget_context,
1456 window_info->pixel_info->highlight_color.pixel);
1458 (void) XSetForeground(display,window_info->widget_context,
1459 window_info->pixel_info->shadow_color.pixel);
1463 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1467 + X S e t M a t t e C o l o r %
1471 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1473 % XSetMatteColor() sets the graphic context for drawing the matte.
1475 % The format of the XSetMatteColor function is:
1477 % XSetMatteColor(display,window_info,raised)
1479 % A description of each parameter follows:
1481 % o display: Specifies a pointer to the Display structure; returned from
1484 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
1486 % o raised: A value other than zero indicates the matte is active.
1489 static void XSetMatteColor(Display *display,const XWindowInfo *window_info,
1490 const MagickStatusType raised)
1492 if (window_info->depth == 1)
1498 (void) XSetForeground(display,window_info->widget_context,
1499 XWhitePixel(display,window_info->screen));
1501 (void) XSetForeground(display,window_info->widget_context,
1502 XBlackPixel(display,window_info->screen));
1506 (void) XSetForeground(display,window_info->widget_context,
1507 window_info->pixel_info->matte_color.pixel);
1509 (void) XSetForeground(display,window_info->widget_context,
1510 window_info->pixel_info->depth_color.pixel);
1514 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1518 + X S e t T e x t C o l o r %
1522 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1524 % XSetTextColor() sets the graphic context for drawing text on a matte.
1526 % The format of the XSetTextColor function is:
1528 % XSetTextColor(display,window_info,raised)
1530 % A description of each parameter follows:
1532 % o display: Specifies a pointer to the Display structure; returned from
1535 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
1537 % o raised: A value other than zero indicates the color show be a
1538 % "highlight" color, otherwise the "shadow" color is set.
1541 static void XSetTextColor(Display *display,const XWindowInfo *window_info,
1542 const MagickStatusType raised)
1548 if (window_info->depth == 1)
1554 (void) XSetForeground(display,window_info->widget_context,
1555 XBlackPixel(display,window_info->screen));
1557 (void) XSetForeground(display,window_info->widget_context,
1558 XWhitePixel(display,window_info->screen));
1561 foreground=(ssize_t) XPixelIntensity(
1562 &window_info->pixel_info->foreground_color);
1563 matte=(ssize_t) XPixelIntensity(&window_info->pixel_info->matte_color);
1564 if (MagickAbsoluteValue((int) (foreground-matte)) > (65535L >> 3))
1565 (void) XSetForeground(display,window_info->widget_context,
1566 window_info->pixel_info->foreground_color.pixel);
1568 (void) XSetForeground(display,window_info->widget_context,
1569 window_info->pixel_info->background_color.pixel);
1573 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1577 % X C o l o r B r o w s e r W i d g e t %
1581 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1583 % XColorBrowserWidget() displays a Color Browser widget with a color query
1584 % to the user. The user keys a reply and presses the Action or Cancel button
1585 % to exit. The typed text is returned as the reply function parameter.
1587 % The format of the XColorBrowserWidget method is:
1589 % void XColorBrowserWidget(Display *display,XWindows *windows,
1590 % const char *action,char *reply)
1592 % A description of each parameter follows:
1594 % o display: Specifies a connection to an X server; returned from
1597 % o window: Specifies a pointer to a XWindows structure.
1599 % o action: Specifies a pointer to the action of this widget.
1601 % o reply: the response from the user is returned in this parameter.
1604 MagickPrivate void XColorBrowserWidget(Display *display,XWindows *windows,
1605 const char *action,char *reply)
1607 #define CancelButtonText "Cancel"
1608 #define ColornameText "Name:"
1609 #define ColorPatternText "Pattern:"
1610 #define GrabButtonText "Grab"
1611 #define ResetButtonText "Reset"
1615 primary_selection[MagickPathExtent],
1616 reset_pattern[MagickPathExtent],
1617 text[MagickPathExtent];
1630 glob_pattern[MagickPathExtent] = "*";
1632 static MagickStatusType
1633 mask = (MagickStatusType) (CWWidth | CWHeight | CWX | CWY);
1681 Get color list and sort in ascending order.
1683 assert(display != (Display *) NULL);
1684 assert(windows != (XWindows *) NULL);
1685 assert(action != (char *) NULL);
1686 assert(reply != (char *) NULL);
1687 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",action);
1688 XSetCursorState(display,windows,MagickTrue);
1689 XCheckRefreshWindows(display,windows);
1690 (void) CopyMagickString(reset_pattern,"*",MagickPathExtent);
1691 exception=AcquireExceptionInfo();
1692 colorlist=GetColorList(glob_pattern,&colors,exception);
1693 if (colorlist == (char **) NULL)
1696 Pattern failed, obtain all the colors.
1698 (void) CopyMagickString(glob_pattern,"*",MagickPathExtent);
1699 colorlist=GetColorList(glob_pattern,&colors,exception);
1700 if (colorlist == (char **) NULL)
1702 XNoticeWidget(display,windows,"Unable to obtain colors names:",
1704 (void) XDialogWidget(display,windows,action,"Enter color name:",
1710 Determine Color Browser widget attributes.
1712 font_info=windows->widget.font_info;
1714 for (i=0; i < (int) colors; i++)
1715 if (WidgetTextWidth(font_info,colorlist[i]) > text_width)
1716 text_width=WidgetTextWidth(font_info,colorlist[i]);
1717 width=WidgetTextWidth(font_info,(char *) action);
1718 if (WidgetTextWidth(font_info,CancelButtonText) > width)
1719 width=WidgetTextWidth(font_info,CancelButtonText);
1720 if (WidgetTextWidth(font_info,ResetButtonText) > width)
1721 width=WidgetTextWidth(font_info,ResetButtonText);
1722 if (WidgetTextWidth(font_info,GrabButtonText) > width)
1723 width=WidgetTextWidth(font_info,GrabButtonText);
1724 width+=QuantumMargin;
1725 if (WidgetTextWidth(font_info,ColorPatternText) > width)
1726 width=WidgetTextWidth(font_info,ColorPatternText);
1727 if (WidgetTextWidth(font_info,ColornameText) > width)
1728 width=WidgetTextWidth(font_info,ColornameText);
1729 height=(unsigned int) (font_info->ascent+font_info->descent);
1731 Position Color Browser widget.
1733 windows->widget.width=(unsigned int)
1734 (width+MagickMin((int) text_width,(int) MaxTextWidth)+6*QuantumMargin);
1735 windows->widget.min_width=(unsigned int)
1736 (width+MinTextWidth+4*QuantumMargin);
1737 if (windows->widget.width < windows->widget.min_width)
1738 windows->widget.width=windows->widget.min_width;
1739 windows->widget.height=(unsigned int)
1740 ((81*height) >> 2)+((13*QuantumMargin) >> 1)+4;
1741 windows->widget.min_height=(unsigned int)
1742 (((23*height) >> 1)+((13*QuantumMargin) >> 1)+4);
1743 if (windows->widget.height < windows->widget.min_height)
1744 windows->widget.height=windows->widget.min_height;
1745 XConstrainWindowPosition(display,&windows->widget);
1747 Map Color Browser widget.
1749 (void) CopyMagickString(windows->widget.name,"Browse and Select a Color",
1751 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
1752 if (status != False)
1754 XSetWMName(display,windows->widget.id,&window_name);
1755 XSetWMIconName(display,windows->widget.id,&window_name);
1756 (void) XFree((void *) window_name.value);
1758 window_changes.width=(int) windows->widget.width;
1759 window_changes.height=(int) windows->widget.height;
1760 window_changes.x=windows->widget.x;
1761 window_changes.y=windows->widget.y;
1762 (void) XReconfigureWMWindow(display,windows->widget.id,windows->widget.screen,
1763 mask,&window_changes);
1764 (void) XMapRaised(display,windows->widget.id);
1765 windows->widget.mapped=MagickFalse;
1767 Respond to X events.
1769 XGetWidgetInfo((char *) NULL,&mode_info);
1770 XGetWidgetInfo((char *) NULL,&slider_info);
1771 XGetWidgetInfo((char *) NULL,&north_info);
1772 XGetWidgetInfo((char *) NULL,&south_info);
1773 XGetWidgetInfo((char *) NULL,&expose_info);
1774 XGetWidgetInfo((char *) NULL,&selection_info);
1776 delay=SuspendTime << 2;
1777 state=UpdateConfigurationState;
1780 if (state & UpdateConfigurationState)
1786 Initialize button information.
1788 XGetWidgetInfo(CancelButtonText,&cancel_info);
1789 cancel_info.width=width;
1790 cancel_info.height=(unsigned int) ((3*height) >> 1);
1792 (windows->widget.width-cancel_info.width-QuantumMargin-2);
1794 (windows->widget.height-cancel_info.height-QuantumMargin);
1795 XGetWidgetInfo(action,&action_info);
1796 action_info.width=width;
1797 action_info.height=(unsigned int) ((3*height) >> 1);
1798 action_info.x=cancel_info.x-(cancel_info.width+(QuantumMargin >> 1)+
1799 (action_info.bevel_width << 1));
1800 action_info.y=cancel_info.y;
1801 XGetWidgetInfo(GrabButtonText,&grab_info);
1802 grab_info.width=width;
1803 grab_info.height=(unsigned int) ((3*height) >> 1);
1804 grab_info.x=QuantumMargin;
1805 grab_info.y=((5*QuantumMargin) >> 1)+height;
1806 XGetWidgetInfo(ResetButtonText,&reset_info);
1807 reset_info.width=width;
1808 reset_info.height=(unsigned int) ((3*height) >> 1);
1809 reset_info.x=QuantumMargin;
1810 reset_info.y=grab_info.y+grab_info.height+QuantumMargin;
1812 Initialize reply information.
1814 XGetWidgetInfo(reply,&reply_info);
1815 reply_info.raised=MagickFalse;
1816 reply_info.bevel_width--;
1817 reply_info.width=windows->widget.width-width-((6*QuantumMargin) >> 1);
1818 reply_info.height=height << 1;
1819 reply_info.x=(int) (width+(QuantumMargin << 1));
1820 reply_info.y=action_info.y-reply_info.height-QuantumMargin;
1822 Initialize mode information.
1824 XGetWidgetInfo((char *) NULL,&mode_info);
1825 mode_info.active=MagickTrue;
1826 mode_info.bevel_width=0;
1827 mode_info.width=(unsigned int) (action_info.x-(QuantumMargin << 1));
1828 mode_info.height=action_info.height;
1829 mode_info.x=QuantumMargin;
1830 mode_info.y=action_info.y;
1832 Initialize scroll information.
1834 XGetWidgetInfo((char *) NULL,&scroll_info);
1835 scroll_info.bevel_width--;
1836 scroll_info.width=height;
1837 scroll_info.height=(unsigned int) (reply_info.y-grab_info.y-
1838 (QuantumMargin >> 1));
1839 scroll_info.x=reply_info.x+(reply_info.width-scroll_info.width);
1840 scroll_info.y=grab_info.y-reply_info.bevel_width;
1841 scroll_info.raised=MagickFalse;
1842 scroll_info.trough=MagickTrue;
1843 north_info=scroll_info;
1844 north_info.raised=MagickTrue;
1845 north_info.width-=(north_info.bevel_width << 1);
1846 north_info.height=north_info.width-1;
1847 north_info.x+=north_info.bevel_width;
1848 north_info.y+=north_info.bevel_width;
1849 south_info=north_info;
1850 south_info.y=scroll_info.y+scroll_info.height-scroll_info.bevel_width-
1853 slider_info=north_info;
1855 slider_info.width-=2;
1856 slider_info.min_y=north_info.y+north_info.height+north_info.bevel_width+
1857 slider_info.bevel_width+2;
1858 slider_info.height=scroll_info.height-((slider_info.min_y-
1859 scroll_info.y+1) << 1)+4;
1860 visible_colors=scroll_info.height/(height+(height >> 3));
1861 if (colors > visible_colors)
1862 slider_info.height=(unsigned int)
1863 ((visible_colors*slider_info.height)/colors);
1864 slider_info.max_y=south_info.y-south_info.bevel_width-
1865 slider_info.bevel_width-2;
1866 slider_info.x=scroll_info.x+slider_info.bevel_width+1;
1867 slider_info.y=slider_info.min_y;
1868 expose_info=scroll_info;
1869 expose_info.y=slider_info.y;
1871 Initialize list information.
1873 XGetWidgetInfo((char *) NULL,&list_info);
1874 list_info.raised=MagickFalse;
1875 list_info.bevel_width--;
1876 list_info.width=(unsigned int)
1877 (scroll_info.x-reply_info.x-(QuantumMargin >> 1));
1878 list_info.height=scroll_info.height;
1879 list_info.x=reply_info.x;
1880 list_info.y=scroll_info.y;
1881 if (windows->widget.mapped == MagickFalse)
1882 state|=JumpListState;
1884 Initialize text information.
1887 XGetWidgetInfo(text,&text_info);
1888 text_info.center=MagickFalse;
1889 text_info.width=reply_info.width;
1890 text_info.height=height;
1891 text_info.x=list_info.x-(QuantumMargin >> 1);
1892 text_info.y=QuantumMargin;
1894 Initialize selection information.
1896 XGetWidgetInfo((char *) NULL,&selection_info);
1897 selection_info.center=MagickFalse;
1898 selection_info.width=list_info.width;
1899 selection_info.height=(unsigned int) ((9*height) >> 3);
1900 selection_info.x=list_info.x;
1901 state&=(~UpdateConfigurationState);
1903 if (state & RedrawWidgetState)
1906 Redraw Color Browser window.
1909 y=text_info.y+((text_info.height-height) >> 1)+font_info->ascent;
1910 (void) XDrawString(display,windows->widget.id,
1911 windows->widget.annotate_context,x,y,ColorPatternText,
1912 Extent(ColorPatternText));
1913 (void) CopyMagickString(text_info.text,glob_pattern,MagickPathExtent);
1914 XDrawWidgetText(display,&windows->widget,&text_info);
1915 XDrawBeveledButton(display,&windows->widget,&grab_info);
1916 XDrawBeveledButton(display,&windows->widget,&reset_info);
1917 XDrawBeveledMatte(display,&windows->widget,&list_info);
1918 XDrawBeveledMatte(display,&windows->widget,&scroll_info);
1919 XDrawTriangleNorth(display,&windows->widget,&north_info);
1920 XDrawBeveledButton(display,&windows->widget,&slider_info);
1921 XDrawTriangleSouth(display,&windows->widget,&south_info);
1923 y=reply_info.y+((reply_info.height-height) >> 1)+font_info->ascent;
1924 (void) XDrawString(display,windows->widget.id,
1925 windows->widget.annotate_context,x,y,ColornameText,
1926 Extent(ColornameText));
1927 XDrawBeveledMatte(display,&windows->widget,&reply_info);
1928 XDrawMatteText(display,&windows->widget,&reply_info);
1929 XDrawBeveledButton(display,&windows->widget,&action_info);
1930 XDrawBeveledButton(display,&windows->widget,&cancel_info);
1931 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
1932 selection_info.id=(~0);
1933 state|=RedrawActionState;
1934 state|=RedrawListState;
1935 state&=(~RedrawWidgetState);
1937 if (state & UpdateListState)
1945 status=XParseColor(display,windows->widget.map_info->colormap,
1946 glob_pattern,&color);
1947 if ((status != False) || (strchr(glob_pattern,'-') != (char *) NULL))
1950 Reply is a single color name-- exit.
1952 (void) CopyMagickString(reply,glob_pattern,MagickPathExtent);
1953 (void) CopyMagickString(glob_pattern,reset_pattern,MagickPathExtent);
1954 action_info.raised=MagickFalse;
1955 XDrawBeveledButton(display,&windows->widget,&action_info);
1961 checklist=GetColorList(glob_pattern,&number_colors,exception);
1962 if (number_colors == 0)
1964 (void) CopyMagickString(glob_pattern,reset_pattern,MagickPathExtent);
1965 (void) XBell(display,0);
1969 for (i=0; i < (int) colors; i++)
1970 colorlist[i]=DestroyString(colorlist[i]);
1971 if (colorlist != (char **) NULL)
1972 colorlist=(char **) RelinquishMagickMemory(colorlist);
1973 colorlist=checklist;
1974 colors=number_colors;
1977 Sort color list in ascending order.
1980 scroll_info.height-((slider_info.min_y-scroll_info.y+1) << 1)+1;
1981 if (colors > visible_colors)
1982 slider_info.height=(unsigned int)
1983 ((visible_colors*slider_info.height)/colors);
1984 slider_info.max_y=south_info.y-south_info.bevel_width-
1985 slider_info.bevel_width-2;
1987 slider_info.y=slider_info.min_y;
1988 expose_info.y=slider_info.y;
1989 selection_info.id=(~0);
1991 state|=RedrawListState;
1993 Redraw color name & reply.
1995 *reply_info.text='\0';
1996 reply_info.cursor=reply_info.text;
1997 (void) CopyMagickString(text_info.text,glob_pattern,MagickPathExtent);
1998 XDrawWidgetText(display,&windows->widget,&text_info);
1999 XDrawMatteText(display,&windows->widget,&reply_info);
2000 XDrawBeveledMatte(display,&windows->widget,&scroll_info);
2001 XDrawTriangleNorth(display,&windows->widget,&north_info);
2002 XDrawBeveledButton(display,&windows->widget,&slider_info);
2003 XDrawTriangleSouth(display,&windows->widget,&south_info);
2004 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
2005 state&=(~UpdateListState);
2007 if (state & JumpListState)
2010 Jump scroll to match user color.
2013 for (i=0; i < (int) colors; i++)
2014 if (LocaleCompare(colorlist[i],reply) >= 0)
2016 list_info.id=LocaleCompare(colorlist[i],reply) == 0 ? i : ~0;
2019 if ((i < slider_info.id) ||
2020 (i >= (int) (slider_info.id+visible_colors)))
2021 slider_info.id=i-(visible_colors >> 1);
2022 selection_info.id=(~0);
2023 state|=RedrawListState;
2024 state&=(~JumpListState);
2026 if (state & RedrawListState)
2029 Determine slider id and position.
2031 if (slider_info.id >= (int) (colors-visible_colors))
2032 slider_info.id=(int) (colors-visible_colors);
2033 if ((slider_info.id < 0) || (colors <= visible_colors))
2035 slider_info.y=slider_info.min_y;
2037 slider_info.y+=(int) (slider_info.id*(slider_info.max_y-
2038 slider_info.min_y+1)/colors);
2039 if (slider_info.id != selection_info.id)
2042 Redraw scroll bar and file names.
2044 selection_info.id=slider_info.id;
2045 selection_info.y=list_info.y+(height >> 3)+2;
2046 for (i=0; i < (int) visible_colors; i++)
2048 selection_info.raised=(slider_info.id+i) != list_info.id ?
2049 MagickTrue : MagickFalse;
2050 selection_info.text=(char *) NULL;
2051 if ((slider_info.id+i) < (int) colors)
2052 selection_info.text=colorlist[slider_info.id+i];
2053 XDrawWidgetText(display,&windows->widget,&selection_info);
2054 selection_info.y+=(int) selection_info.height;
2059 if (slider_info.y > expose_info.y)
2061 expose_info.height=(unsigned int) slider_info.y-expose_info.y;
2062 expose_info.y=slider_info.y-expose_info.height-
2063 slider_info.bevel_width-1;
2067 expose_info.height=(unsigned int) expose_info.y-slider_info.y;
2068 expose_info.y=slider_info.y+slider_info.height+
2069 slider_info.bevel_width+1;
2071 XDrawTriangleNorth(display,&windows->widget,&north_info);
2072 XDrawMatte(display,&windows->widget,&expose_info);
2073 XDrawBeveledButton(display,&windows->widget,&slider_info);
2074 XDrawTriangleSouth(display,&windows->widget,&south_info);
2075 expose_info.y=slider_info.y;
2077 state&=(~RedrawListState);
2079 if (state & RedrawActionState)
2082 colorname[MagickPathExtent];
2085 Display the selected color in a drawing area.
2087 color=windows->widget.pixel_info->matte_color;
2088 (void) XParseColor(display,windows->widget.map_info->colormap,
2089 reply_info.text,&windows->widget.pixel_info->matte_color);
2090 XBestPixel(display,windows->widget.map_info->colormap,(XColor *) NULL,
2091 (unsigned int) windows->widget.visual_info->colormap_size,
2092 &windows->widget.pixel_info->matte_color);
2093 mode_info.text=colorname;
2094 (void) FormatLocaleString(mode_info.text,MagickPathExtent,
2095 "#%02x%02x%02x",windows->widget.pixel_info->matte_color.red,
2096 windows->widget.pixel_info->matte_color.green,
2097 windows->widget.pixel_info->matte_color.blue);
2098 XDrawBeveledButton(display,&windows->widget,&mode_info);
2099 windows->widget.pixel_info->matte_color=color;
2100 state&=(~RedrawActionState);
2103 Wait for next event.
2105 if (north_info.raised && south_info.raised)
2106 (void) XIfEvent(display,&event,XScreenEvent,(char *) windows);
2110 Brief delay before advancing scroll bar.
2112 XDelay(display,delay);
2114 (void) XCheckIfEvent(display,&event,XScreenEvent,(char *) windows);
2115 if (north_info.raised == MagickFalse)
2116 if (slider_info.id > 0)
2122 state|=RedrawListState;
2124 if (south_info.raised == MagickFalse)
2125 if (slider_info.id < (int) colors)
2131 state|=RedrawListState;
2133 if (event.type != ButtonRelease)
2140 if (MatteIsActive(slider_info,event.xbutton))
2145 slider_info.active=MagickTrue;
2148 if (MatteIsActive(north_info,event.xbutton))
2149 if (slider_info.id > 0)
2154 north_info.raised=MagickFalse;
2156 state|=RedrawListState;
2159 if (MatteIsActive(south_info,event.xbutton))
2160 if (slider_info.id < (int) colors)
2165 south_info.raised=MagickFalse;
2167 state|=RedrawListState;
2170 if (MatteIsActive(scroll_info,event.xbutton))
2175 if (event.xbutton.y < slider_info.y)
2176 slider_info.id-=(visible_colors-1);
2178 slider_info.id+=(visible_colors-1);
2179 state|=RedrawListState;
2182 if (MatteIsActive(list_info,event.xbutton))
2188 User pressed list matte.
2190 id=slider_info.id+(event.xbutton.y-(list_info.y+(height >> 1))+1)/
2191 selection_info.height;
2192 if (id >= (int) colors)
2194 (void) CopyMagickString(reply_info.text,colorlist[id],
2196 reply_info.highlight=MagickFalse;
2197 reply_info.marker=reply_info.text;
2198 reply_info.cursor=reply_info.text+Extent(reply_info.text);
2199 XDrawMatteText(display,&windows->widget,&reply_info);
2200 state|=RedrawActionState;
2201 if (id == list_info.id)
2203 (void) CopyMagickString(glob_pattern,reply_info.text,
2205 state|=UpdateListState;
2207 selection_info.id=(~0);
2209 state|=RedrawListState;
2212 if (MatteIsActive(grab_info,event.xbutton))
2215 User pressed Grab button.
2217 grab_info.raised=MagickFalse;
2218 XDrawBeveledButton(display,&windows->widget,&grab_info);
2221 if (MatteIsActive(reset_info,event.xbutton))
2224 User pressed Reset button.
2226 reset_info.raised=MagickFalse;
2227 XDrawBeveledButton(display,&windows->widget,&reset_info);
2230 if (MatteIsActive(mode_info,event.xbutton))
2233 User pressed mode button.
2235 if (mode_info.text != (char *) NULL)
2236 (void) CopyMagickString(reply_info.text,mode_info.text,
2238 (void) CopyMagickString(primary_selection,reply_info.text,
2240 (void) XSetSelectionOwner(display,XA_PRIMARY,windows->widget.id,
2241 event.xbutton.time);
2242 reply_info.highlight=XGetSelectionOwner(display,XA_PRIMARY) ==
2243 windows->widget.id ? MagickTrue : MagickFalse;
2244 reply_info.marker=reply_info.text;
2245 reply_info.cursor=reply_info.text+Extent(reply_info.text);
2246 XDrawMatteText(display,&windows->widget,&reply_info);
2249 if (MatteIsActive(action_info,event.xbutton))
2252 User pressed action button.
2254 action_info.raised=MagickFalse;
2255 XDrawBeveledButton(display,&windows->widget,&action_info);
2258 if (MatteIsActive(cancel_info,event.xbutton))
2261 User pressed Cancel button.
2263 cancel_info.raised=MagickFalse;
2264 XDrawBeveledButton(display,&windows->widget,&cancel_info);
2267 if (MatteIsActive(reply_info,event.xbutton) == MagickFalse)
2269 if (event.xbutton.button != Button2)
2275 Move text cursor to position of button press.
2277 x=event.xbutton.x-reply_info.x-(QuantumMargin >> 2);
2278 for (i=1; i <= Extent(reply_info.marker); i++)
2279 if (XTextWidth(font_info,reply_info.marker,i) > x)
2281 reply_info.cursor=reply_info.marker+i-1;
2282 if (event.xbutton.time > (click_time+DoubleClick))
2283 reply_info.highlight=MagickFalse;
2287 Become the XA_PRIMARY selection owner.
2289 (void) CopyMagickString(primary_selection,reply_info.text,
2291 (void) XSetSelectionOwner(display,XA_PRIMARY,windows->widget.id,
2292 event.xbutton.time);
2293 reply_info.highlight=XGetSelectionOwner(display,XA_PRIMARY) ==
2294 windows->widget.id ? MagickTrue : MagickFalse;
2296 XDrawMatteText(display,&windows->widget,&reply_info);
2297 click_time=event.xbutton.time;
2301 Request primary selection.
2303 (void) XConvertSelection(display,XA_PRIMARY,XA_STRING,XA_STRING,
2304 windows->widget.id,event.xbutton.time);
2309 if (windows->widget.mapped == MagickFalse)
2311 if (north_info.raised == MagickFalse)
2314 User released up button.
2316 delay=SuspendTime << 2;
2317 north_info.raised=MagickTrue;
2318 XDrawTriangleNorth(display,&windows->widget,&north_info);
2320 if (south_info.raised == MagickFalse)
2323 User released down button.
2325 delay=SuspendTime << 2;
2326 south_info.raised=MagickTrue;
2327 XDrawTriangleSouth(display,&windows->widget,&south_info);
2329 if (slider_info.active)
2332 Stop tracking slider.
2334 slider_info.active=MagickFalse;
2337 if (grab_info.raised == MagickFalse)
2339 if (event.xbutton.window == windows->widget.id)
2340 if (MatteIsActive(grab_info,event.xbutton))
2343 Select a fill color from the X server.
2345 (void) XGetWindowColor(display,windows,reply_info.text,
2347 reply_info.marker=reply_info.text;
2348 reply_info.cursor=reply_info.text+Extent(reply_info.text);
2349 XDrawMatteText(display,&windows->widget,&reply_info);
2350 state|=RedrawActionState;
2352 grab_info.raised=MagickTrue;
2353 XDrawBeveledButton(display,&windows->widget,&grab_info);
2355 if (reset_info.raised == MagickFalse)
2357 if (event.xbutton.window == windows->widget.id)
2358 if (MatteIsActive(reset_info,event.xbutton))
2360 (void) CopyMagickString(glob_pattern,reset_pattern,
2362 state|=UpdateListState;
2364 reset_info.raised=MagickTrue;
2365 XDrawBeveledButton(display,&windows->widget,&reset_info);
2367 if (action_info.raised == MagickFalse)
2369 if (event.xbutton.window == windows->widget.id)
2371 if (MatteIsActive(action_info,event.xbutton))
2373 if (*reply_info.text == '\0')
2374 (void) XBell(display,0);
2379 action_info.raised=MagickTrue;
2380 XDrawBeveledButton(display,&windows->widget,&action_info);
2382 if (cancel_info.raised == MagickFalse)
2384 if (event.xbutton.window == windows->widget.id)
2385 if (MatteIsActive(cancel_info,event.xbutton))
2387 *reply_info.text='\0';
2390 cancel_info.raised=MagickTrue;
2391 XDrawBeveledButton(display,&windows->widget,&cancel_info);
2393 if (MatteIsActive(reply_info,event.xbutton) == MagickFalse)
2400 If client window delete message, exit.
2402 if (event.xclient.message_type != windows->wm_protocols)
2404 if (*event.xclient.data.l == (int) windows->wm_take_focus)
2406 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
2407 (Time) event.xclient.data.l[1]);
2410 if (*event.xclient.data.l != (int) windows->wm_delete_window)
2412 if (event.xclient.window == windows->widget.id)
2414 *reply_info.text='\0';
2420 case ConfigureNotify:
2423 Update widget configuration.
2425 if (event.xconfigure.window != windows->widget.id)
2427 if ((event.xconfigure.width == (int) windows->widget.width) &&
2428 (event.xconfigure.height == (int) windows->widget.height))
2430 windows->widget.width=(unsigned int)
2431 MagickMax(event.xconfigure.width,(int) windows->widget.min_width);
2432 windows->widget.height=(unsigned int)
2433 MagickMax(event.xconfigure.height,(int) windows->widget.min_height);
2434 state|=UpdateConfigurationState;
2439 if (event.xcrossing.window != windows->widget.id)
2441 state&=(~InactiveWidgetState);
2446 if (event.xexpose.window != windows->widget.id)
2448 if (event.xexpose.count != 0)
2450 state|=RedrawWidgetState;
2456 command[MagickPathExtent];
2465 Respond to a user key press.
2467 if (event.xkey.window != windows->widget.id)
2469 length=XLookupString((XKeyEvent *) &event.xkey,command,
2470 (int) sizeof(command),&key_symbol,(XComposeStatus *) NULL);
2471 *(command+length)='\0';
2472 if (AreaIsActive(scroll_info,event.xkey))
2477 switch ((int) key_symbol)
2500 slider_info.id-=visible_colors;
2506 slider_info.id+=visible_colors;
2512 slider_info.id=(int) colors;
2516 state|=RedrawListState;
2519 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
2522 Read new color or glob patterm.
2524 if (*reply_info.text == '\0')
2526 (void) CopyMagickString(glob_pattern,reply_info.text,MagickPathExtent);
2527 state|=UpdateListState;
2530 if (key_symbol == XK_Control_L)
2532 state|=ControlState;
2535 if (state & ControlState)
2536 switch ((int) key_symbol)
2542 Erase the entire line of text.
2544 *reply_info.text='\0';
2545 reply_info.cursor=reply_info.text;
2546 reply_info.marker=reply_info.text;
2547 reply_info.highlight=MagickFalse;
2553 XEditText(display,&reply_info,key_symbol,command,state);
2554 XDrawMatteText(display,&windows->widget,&reply_info);
2555 state|=JumpListState;
2556 status=XParseColor(display,windows->widget.map_info->colormap,
2557 reply_info.text,&color);
2558 if (status != False)
2559 state|=RedrawActionState;
2565 command[MagickPathExtent];
2571 Respond to a user key release.
2573 if (event.xkey.window != windows->widget.id)
2575 (void) XLookupString((XKeyEvent *) &event.xkey,command,
2576 (int) sizeof(command),&key_symbol,(XComposeStatus *) NULL);
2577 if (key_symbol == XK_Control_L)
2578 state&=(~ControlState);
2583 if (event.xcrossing.window != windows->widget.id)
2585 state|=InactiveWidgetState;
2597 Discard pending button motion events.
2599 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
2600 if (slider_info.active)
2605 slider_info.y=event.xmotion.y-
2606 ((slider_info.height+slider_info.bevel_width) >> 1)+1;
2607 if (slider_info.y < slider_info.min_y)
2608 slider_info.y=slider_info.min_y;
2609 if (slider_info.y > slider_info.max_y)
2610 slider_info.y=slider_info.max_y;
2612 if (slider_info.y != slider_info.min_y)
2613 slider_info.id=(int) ((colors*(slider_info.y-
2614 slider_info.min_y+1))/(slider_info.max_y-slider_info.min_y+1));
2615 state|=RedrawListState;
2618 if (state & InactiveWidgetState)
2620 if (grab_info.raised == MatteIsActive(grab_info,event.xmotion))
2623 Grab button status changed.
2625 grab_info.raised=!grab_info.raised;
2626 XDrawBeveledButton(display,&windows->widget,&grab_info);
2629 if (reset_info.raised == MatteIsActive(reset_info,event.xmotion))
2632 Reset button status changed.
2634 reset_info.raised=!reset_info.raised;
2635 XDrawBeveledButton(display,&windows->widget,&reset_info);
2638 if (action_info.raised == MatteIsActive(action_info,event.xmotion))
2641 Action button status changed.
2643 action_info.raised=action_info.raised == MagickFalse ?
2644 MagickTrue : MagickFalse;
2645 XDrawBeveledButton(display,&windows->widget,&action_info);
2648 if (cancel_info.raised == MatteIsActive(cancel_info,event.xmotion))
2651 Cancel button status changed.
2653 cancel_info.raised=cancel_info.raised == MagickFalse ?
2654 MagickTrue : MagickFalse;
2655 XDrawBeveledButton(display,&windows->widget,&cancel_info);
2660 case SelectionClear:
2662 reply_info.highlight=MagickFalse;
2663 XDrawMatteText(display,&windows->widget,&reply_info);
2666 case SelectionNotify:
2682 Obtain response from primary selection.
2684 if (event.xselection.property == (Atom) None)
2686 status=XGetWindowProperty(display,event.xselection.requestor,
2687 event.xselection.property,0L,2047L,MagickTrue,XA_STRING,&type,
2688 &format,&length,&after,&data);
2689 if ((status != Success) || (type != XA_STRING) || (format == 32) ||
2692 if ((Extent(reply_info.text)+length) >= (MagickPathExtent-1))
2693 (void) XBell(display,0);
2697 Insert primary selection in reply text.
2699 *(data+length)='\0';
2700 XEditText(display,&reply_info,(KeySym) XK_Insert,(char *) data,
2702 XDrawMatteText(display,&windows->widget,&reply_info);
2703 state|=JumpListState;
2704 state|=RedrawActionState;
2706 (void) XFree((void *) data);
2709 case SelectionRequest:
2714 XSelectionRequestEvent
2717 if (reply_info.highlight == MagickFalse)
2720 Set primary selection.
2722 request=(&(event.xselectionrequest));
2723 (void) XChangeProperty(request->display,request->requestor,
2724 request->property,request->target,8,PropModeReplace,
2725 (unsigned char *) primary_selection,Extent(primary_selection));
2726 notify.type=SelectionNotify;
2727 notify.send_event=MagickTrue;
2728 notify.display=request->display;
2729 notify.requestor=request->requestor;
2730 notify.selection=request->selection;
2731 notify.target=request->target;
2732 notify.time=request->time;
2733 if (request->property == None)
2734 notify.property=request->target;
2736 notify.property=request->property;
2737 (void) XSendEvent(request->display,request->requestor,False,
2738 NoEventMask,(XEvent *) ¬ify);
2743 } while ((state & ExitState) == 0);
2744 XSetCursorState(display,windows,MagickFalse);
2745 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
2746 XCheckRefreshWindows(display,windows);
2750 for (i=0; i < (int) colors; i++)
2751 colorlist[i]=DestroyString(colorlist[i]);
2752 if (colorlist != (char **) NULL)
2753 colorlist=(char **) RelinquishMagickMemory(colorlist);
2754 exception=DestroyExceptionInfo(exception);
2755 if ((*reply == '\0') || (strchr(reply,'-') != (char *) NULL))
2757 status=XParseColor(display,windows->widget.map_info->colormap,reply,&color);
2758 if (status != False)
2760 XNoticeWidget(display,windows,"Color is unknown to X server:",reply);
2761 (void) CopyMagickString(reply,"gray",MagickPathExtent);
2765 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2769 % X C o m m a n d W i d g e t %
2773 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2775 % XCommandWidget() maps a menu and returns the command pointed to by the user
2776 % when the button is released.
2778 % The format of the XCommandWidget method is:
2780 % int XCommandWidget(Display *display,XWindows *windows,
2781 % const char **selections,XEvent *event)
2783 % A description of each parameter follows:
2785 % o selection_number: Specifies the number of the selection that the
2788 % o display: Specifies a connection to an X server; returned from
2791 % o window: Specifies a pointer to a XWindows structure.
2793 % o selections: Specifies a pointer to one or more strings that comprise
2794 % the choices in the menu.
2796 % o event: Specifies a pointer to a X11 XEvent structure.
2799 MagickPrivate int XCommandWidget(Display *display,XWindows *windows,
2800 const char **selections,XEvent *event)
2802 #define tile_width 112
2803 #define tile_height 70
2805 static const unsigned char
2808 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2809 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2810 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2811 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
2812 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00,
2813 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00,
2814 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2815 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2816 0x00, 0x00, 0x1e, 0x38, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2817 0x00, 0x00, 0x00, 0x00, 0x1e, 0xbc, 0x9f, 0x03, 0x00, 0x3e, 0x00, 0xc0,
2818 0x1f, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x1e, 0xfc, 0xff, 0x0f, 0x80, 0x3f,
2819 0x00, 0xf0, 0x1f, 0xc0, 0x0f, 0x00, 0x00, 0x00, 0x1e, 0xfc, 0xff, 0x1f,
2820 0xe0, 0x3f, 0x00, 0xfc, 0x1f, 0xf0, 0x0f, 0x00, 0x00, 0x00, 0x1e, 0xfc,
2821 0xff, 0x1f, 0xf0, 0x3f, 0x00, 0xfe, 0x1f, 0xf8, 0x0f, 0x00, 0x00, 0x00,
2822 0x1e, 0xfc, 0xfc, 0x3f, 0xf8, 0x3f, 0x00, 0xff, 0x1e, 0xfc, 0x0f, 0x00,
2823 0x00, 0x00, 0x1e, 0x7c, 0xfc, 0x3e, 0xf8, 0x3c, 0x80, 0x1f, 0x1e, 0x7c,
2824 0x0f, 0x00, 0x00, 0x00, 0x1e, 0x78, 0x78, 0x3c, 0x7c, 0x3c, 0xc0, 0x0f,
2825 0x1e, 0x3e, 0x0f, 0x00, 0x00, 0x00, 0x1e, 0x78, 0x78, 0x3c, 0x7c, 0x3c,
2826 0xc0, 0x07, 0x1e, 0x3e, 0x0f, 0x00, 0x00, 0x00, 0x1e, 0x78, 0x78, 0x3c,
2827 0x7c, 0x7c, 0xc0, 0x0f, 0x1e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x78,
2828 0x78, 0x3c, 0xfc, 0x7c, 0x80, 0x7f, 0x1e, 0x7c, 0x00, 0x00, 0x00, 0x00,
2829 0x1e, 0xf8, 0x78, 0x7c, 0xf8, 0xff, 0x00, 0xff, 0x1f, 0xf8, 0xff, 0x00,
2830 0x00, 0x00, 0x1e, 0xf8, 0x78, 0x7c, 0xf0, 0xff, 0x07, 0xfe, 0x1f, 0xf8,
2831 0xff, 0x00, 0x00, 0x00, 0x1e, 0xf8, 0x78, 0x7c, 0xf0, 0xff, 0x07, 0xf8,
2832 0x1f, 0xf0, 0xff, 0x01, 0x00, 0x00, 0x1e, 0xf8, 0x78, 0x7c, 0xc0, 0xef,
2833 0x07, 0xe0, 0x1f, 0xc0, 0xff, 0x01, 0x00, 0x00, 0x1e, 0x70, 0x40, 0x78,
2834 0x00, 0xc7, 0x07, 0x00, 0x1e, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x1e, 0x00,
2835 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00,
2836 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00,
2837 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00,
2838 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
2839 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2840 0x00, 0xc0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2841 0x00, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2842 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
2843 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x01, 0x00, 0x00, 0x00,
2844 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00,
2845 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78,
2846 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2847 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x02, 0x00,
2848 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07,
2849 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2850 0xc0, 0x0f, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2851 0x60, 0x00, 0xc0, 0x0f, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2852 0x00, 0x00, 0x78, 0x00, 0xc0, 0x8f, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00,
2853 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0xc0, 0x8f, 0x3f, 0x00, 0x00, 0x00,
2854 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0xe0, 0x9f, 0x7f, 0x00,
2855 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0xe0, 0xdf,
2856 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x78, 0x00,
2857 0xe0, 0xdf, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x0c,
2858 0x78, 0x30, 0xf0, 0xff, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e,
2859 0x00, 0x0f, 0xf8, 0x70, 0xf0, 0xff, 0x7b, 0x00, 0x00, 0x1f, 0x00, 0xe0,
2860 0x0f, 0x1e, 0x80, 0x0f, 0xf8, 0x78, 0xf0, 0xfd, 0xf9, 0x00, 0xc0, 0x1f,
2861 0x00, 0xf8, 0x0f, 0x00, 0xe0, 0x1f, 0xf8, 0x7c, 0xf0, 0xfc, 0xf9, 0x00,
2862 0xf0, 0x1f, 0x00, 0xfe, 0x0f, 0x00, 0xf0, 0x07, 0xf8, 0x3e, 0xf8, 0xfc,
2863 0xf0, 0x01, 0xf8, 0x1f, 0x00, 0xff, 0x0f, 0x1e, 0xf0, 0x03, 0xf8, 0x3f,
2864 0xf8, 0xf8, 0xf0, 0x01, 0xfc, 0x1f, 0x80, 0x7f, 0x0f, 0x1e, 0xf8, 0x00,
2865 0xf8, 0x1f, 0x78, 0x18, 0xf0, 0x01, 0x7c, 0x1e, 0xc0, 0x0f, 0x0f, 0x1e,
2866 0x7c, 0x00, 0xf0, 0x0f, 0x78, 0x00, 0xf0, 0x01, 0x3e, 0x1e, 0xe0, 0x07,
2867 0x0f, 0x1e, 0x7c, 0x00, 0xf0, 0x07, 0x7c, 0x00, 0xe0, 0x01, 0x3e, 0x1e,
2868 0xe0, 0x03, 0x0f, 0x1e, 0x3e, 0x00, 0xf0, 0x0f, 0x7c, 0x00, 0xe0, 0x03,
2869 0x3e, 0x3e, 0xe0, 0x07, 0x0f, 0x1e, 0x1e, 0x00, 0xf0, 0x1f, 0x3c, 0x00,
2870 0xe0, 0x03, 0x7e, 0x3e, 0xc0, 0x3f, 0x0f, 0x1e, 0x3e, 0x00, 0xf0, 0x1f,
2871 0x3e, 0x00, 0xe0, 0x03, 0xfc, 0x7f, 0x80, 0xff, 0x0f, 0x1e, 0xfc, 0x00,
2872 0xf0, 0x3e, 0x3e, 0x00, 0xc0, 0x03, 0xf8, 0xff, 0x03, 0xff, 0x0f, 0x1e,
2873 0xfc, 0x07, 0xf0, 0x7c, 0x1e, 0x00, 0xc0, 0x03, 0xf8, 0xff, 0x03, 0xfc,
2874 0x0f, 0x1e, 0xf8, 0x1f, 0xf0, 0xf8, 0x1e, 0x00, 0xc0, 0x03, 0xe0, 0xf7,
2875 0x03, 0xf0, 0x0f, 0x1e, 0xe0, 0x3f, 0xf0, 0x78, 0x1c, 0x00, 0x80, 0x03,
2876 0x80, 0xe3, 0x03, 0x00, 0x0f, 0x1e, 0xc0, 0x3f, 0xf0, 0x30, 0x00, 0x00,
2877 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0e, 0x00, 0x3e, 0x00, 0x00,
2878 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x0f, 0x00, 0x00, 0x10,
2879 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x0f, 0x00,
2880 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
2881 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2882 0x00, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2883 0x00, 0x00, 0x00, 0xf0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2884 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
2885 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00,
2886 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00,
2887 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c,
2888 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2889 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2911 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2912 assert(display != (Display *) NULL);
2913 assert(windows != (XWindows *) NULL);
2914 font_info=windows->command.font_info;
2915 height=(unsigned int) (font_info->ascent+font_info->descent);
2918 if (event == (XEvent *) NULL)
2930 Determine command window attributes.
2932 assert(selections != (const char **) NULL);
2933 windows->command.width=0;
2934 for (i=0; selections[i] != (char *) NULL; i++)
2936 width=WidgetTextWidth(font_info,(char *) selections[i]);
2937 if (width > windows->command.width)
2938 windows->command.width=width;
2940 number_selections=(unsigned int) i;
2941 windows->command.width+=3*QuantumMargin+10;
2942 if ((int) windows->command.width < (tile_width+QuantumMargin+10))
2943 windows->command.width=(unsigned int) (tile_width+QuantumMargin+10);
2944 windows->command.height=(unsigned int) (number_selections*
2945 (((3*height) >> 1)+10)+tile_height+20);
2946 windows->command.min_width=windows->command.width;
2947 windows->command.min_height=windows->command.height;
2948 XConstrainWindowPosition(display,&windows->command);
2949 if (windows->command.id != (Window) NULL)
2955 Reconfigure command window.
2957 status=XStringListToTextProperty(&windows->command.name,1,
2959 if (status != False)
2961 XSetWMName(display,windows->command.id,&window_name);
2962 XSetWMIconName(display,windows->command.id,&window_name);
2963 (void) XFree((void *) window_name.value);
2965 window_changes.width=(int) windows->command.width;
2966 window_changes.height=(int) windows->command.height;
2967 (void) XReconfigureWMWindow(display,windows->command.id,
2968 windows->command.screen,(unsigned int) (CWWidth | CWHeight),
2972 Allocate selection info memory.
2974 if (selection_info != (XWidgetInfo *) NULL)
2975 selection_info=(XWidgetInfo *) RelinquishMagickMemory(selection_info);
2976 selection_info=(XWidgetInfo *) AcquireQuantumMemory(number_selections,
2977 sizeof(*selection_info));
2978 if (selection_info == (XWidgetInfo *) NULL)
2980 ThrowXWindowFatalException(ResourceLimitFatalError,
2981 "MemoryAllocationFailed","...");
2984 state|=UpdateConfigurationState | RedrawWidgetState;
2987 Wait for next event.
2989 if (event != (XEvent *) NULL)
2990 switch (event->type)
2994 for (i=0; i < (int) number_selections; i++)
2996 if (MatteIsActive(selection_info[i],event->xbutton) == MagickFalse)
2998 if (i >= (int) windows->command.data)
3000 selection_info[i].raised=MagickFalse;
3001 XDrawBeveledButton(display,&windows->command,&selection_info[i]);
3004 submenu_info=selection_info[i];
3005 submenu_info.active=MagickTrue;
3006 toggle_info.y=submenu_info.y+(submenu_info.height >> 1)-
3007 (toggle_info.height >> 1);
3009 (void) XCheckWindowEvent(display,windows->widget.id,LeaveWindowMask,
3017 for (i=0; i < (int) number_selections; i++)
3019 if (MatteIsActive(selection_info[i],event->xbutton) == MagickFalse)
3022 if (id >= (int) windows->command.data)
3024 selection_info[id].raised=MagickTrue;
3025 XDrawBeveledButton(display,&windows->command,&selection_info[id]);
3035 If client window delete message, withdraw command widget.
3037 if (event->xclient.message_type != windows->wm_protocols)
3039 if (*event->xclient.data.l != (int) windows->wm_delete_window)
3041 (void) XWithdrawWindow(display,windows->command.id,
3042 windows->command.screen);
3045 case ConfigureNotify:
3048 Update widget configuration.
3050 if (event->xconfigure.window != windows->command.id)
3052 if (event->xconfigure.send_event != 0)
3054 windows->command.x=event->xconfigure.x;
3055 windows->command.y=event->xconfigure.y;
3057 if ((event->xconfigure.width == (int) windows->command.width) &&
3058 (event->xconfigure.height == (int) windows->command.height))
3060 windows->command.width=(unsigned int)
3061 MagickMax(event->xconfigure.width,(int) windows->command.min_width);
3062 windows->command.height=(unsigned int)
3063 MagickMax(event->xconfigure.height,(int) windows->command.min_height);
3064 state|=UpdateConfigurationState;
3069 if (event->xexpose.window != windows->command.id)
3071 if (event->xexpose.count != 0)
3073 state|=RedrawWidgetState;
3079 Return the ID of the highlighted menu entry.
3083 for (i=0; i < (int) number_selections; i++)
3085 if (i >= (int) windows->command.data)
3087 if (selection_info[i].raised ==
3088 MatteIsActive(selection_info[i],event->xmotion))
3091 Button status changed.
3093 selection_info[i].raised=!selection_info[i].raised;
3094 XDrawBeveledButton(display,&windows->command,
3095 &selection_info[i]);
3099 if (MatteIsActive(selection_info[i],event->xmotion) == MagickFalse)
3101 submenu_info=selection_info[i];
3102 submenu_info.active=MagickTrue;
3103 toggle_info.raised=MagickTrue;
3104 toggle_info.y=submenu_info.y+(submenu_info.height >> 1)-
3105 (toggle_info.height >> 1);
3106 XDrawTriangleEast(display,&windows->command,&toggle_info);
3109 XDelay(display,SuspendTime);
3110 if (XCheckMaskEvent(display,ButtonMotionMask,event) == MagickFalse)
3112 while (XCheckMaskEvent(display,ButtonMotionMask,event)) ;
3113 toggle_info.raised=MagickFalse;
3114 if (windows->command.data != 0)
3115 XDrawTriangleEast(display,&windows->command,&toggle_info);
3121 windows->command.mapped=MagickTrue;
3126 windows->command.mapped=MagickFalse;
3132 if (state & UpdateConfigurationState)
3135 Initialize button information.
3137 assert(selections != (const char **) NULL);
3139 for (i=0; i < (int) number_selections; i++)
3141 XGetWidgetInfo(selections[i],&selection_info[i]);
3142 selection_info[i].center=MagickFalse;
3143 selection_info[i].bevel_width--;
3144 selection_info[i].height=(unsigned int) ((3*height) >> 1);
3145 selection_info[i].x=(QuantumMargin >> 1)+4;
3146 selection_info[i].width=(unsigned int) (windows->command.width-
3147 (selection_info[i].x << 1));
3148 selection_info[i].y=y;
3149 y+=selection_info[i].height+(selection_info[i].bevel_width << 1)+6;
3151 XGetWidgetInfo((char *) NULL,&toggle_info);
3152 toggle_info.bevel_width--;
3153 toggle_info.width=(unsigned int) (((5*height) >> 3)-
3154 (toggle_info.bevel_width << 1));
3155 toggle_info.height=toggle_info.width;
3156 toggle_info.x=selection_info[0].x+selection_info[0].width-
3157 toggle_info.width-(QuantumMargin >> 1);
3158 if (windows->command.mapped)
3159 (void) XClearWindow(display,windows->command.id);
3161 if (state & RedrawWidgetState)
3167 Draw command buttons.
3169 tile_pixmap=XCreatePixmapFromBitmapData(display,windows->command.id,
3170 (char *) tile_bits,tile_width,tile_height,1L,0L,1);
3171 if (tile_pixmap != (Pixmap) NULL)
3173 (void) XCopyPlane(display,tile_pixmap,windows->command.id,
3174 windows->command.annotate_context,0,0,tile_width,tile_height,
3175 (int) ((windows->command.width-tile_width) >> 1),10,1L);
3176 (void) XFreePixmap(display,tile_pixmap);
3178 for (i=0; i < (int) number_selections; i++)
3180 XDrawBeveledButton(display,&windows->command,&selection_info[i]);
3181 if (i >= (int) windows->command.data)
3183 toggle_info.raised=MagickFalse;
3184 toggle_info.y=selection_info[i].y+(selection_info[i].height >> 1)-
3185 (toggle_info.height >> 1);
3186 XDrawTriangleEast(display,&windows->command,&toggle_info);
3188 XHighlightWidget(display,&windows->command,BorderOffset,BorderOffset);
3194 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3198 % X C o n f i r m W i d g e t %
3202 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3204 % XConfirmWidget() displays a Confirm widget with a notice to the user. The
3205 % function returns -1 if Dismiss is pressed, 0 for Cancel, and 1 for Yes.
3207 % The format of the XConfirmWidget method is:
3209 % int XConfirmWidget(Display *display,XWindows *windows,
3210 % const char *reason,const char *description)
3212 % A description of each parameter follows:
3214 % o display: Specifies a connection to an X server; returned from
3217 % o window: Specifies a pointer to a XWindows structure.
3219 % o reason: Specifies the message to display before terminating the
3222 % o description: Specifies any description to the message.
3225 MagickPrivate int XConfirmWidget(Display *display,XWindows *windows,
3226 const char *reason,const char *description)
3228 #define CancelButtonText "Cancel"
3229 #define DismissButtonText "Dismiss"
3230 #define YesButtonText "Yes"
3265 Determine Confirm widget attributes.
3267 assert(display != (Display *) NULL);
3268 assert(windows != (XWindows *) NULL);
3269 assert(reason != (char *) NULL);
3270 assert(description != (char *) NULL);
3271 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",reason);
3272 XCheckRefreshWindows(display,windows);
3273 font_info=windows->widget.font_info;
3274 width=WidgetTextWidth(font_info,CancelButtonText);
3275 if (WidgetTextWidth(font_info,DismissButtonText) > width)
3276 width=WidgetTextWidth(font_info,DismissButtonText);
3277 if (WidgetTextWidth(font_info,YesButtonText) > width)
3278 width=WidgetTextWidth(font_info,YesButtonText);
3280 if (description != (char *) NULL)
3281 if (WidgetTextWidth(font_info,(char *) description) > width)
3282 width=WidgetTextWidth(font_info,(char *) description);
3283 height=(unsigned int) (font_info->ascent+font_info->descent);
3285 Position Confirm widget.
3287 windows->widget.width=(unsigned int) (width+9*QuantumMargin);
3288 windows->widget.min_width=(unsigned int) (9*QuantumMargin+
3289 WidgetTextWidth(font_info,CancelButtonText)+
3290 WidgetTextWidth(font_info,DismissButtonText)+
3291 WidgetTextWidth(font_info,YesButtonText));
3292 if (windows->widget.width < windows->widget.min_width)
3293 windows->widget.width=windows->widget.min_width;
3294 windows->widget.height=(unsigned int) (12*height);
3295 windows->widget.min_height=(unsigned int) (7*height);
3296 if (windows->widget.height < windows->widget.min_height)
3297 windows->widget.height=windows->widget.min_height;
3298 XConstrainWindowPosition(display,&windows->widget);
3302 (void) CopyMagickString(windows->widget.name,"Confirm",MagickPathExtent);
3303 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
3304 if (status != False)
3306 XSetWMName(display,windows->widget.id,&window_name);
3307 XSetWMIconName(display,windows->widget.id,&window_name);
3308 (void) XFree((void *) window_name.value);
3310 window_changes.width=(int) windows->widget.width;
3311 window_changes.height=(int) windows->widget.height;
3312 window_changes.x=windows->widget.x;
3313 window_changes.y=windows->widget.y;
3314 (void) XReconfigureWMWindow(display,windows->widget.id,windows->widget.screen,
3315 (unsigned int) (CWWidth | CWHeight | CWX | CWY),&window_changes);
3316 (void) XMapRaised(display,windows->widget.id);
3317 windows->widget.mapped=MagickFalse;
3319 Respond to X events.
3322 state=UpdateConfigurationState;
3323 XSetCursorState(display,windows,MagickTrue);
3326 if (state & UpdateConfigurationState)
3329 Initialize button information.
3331 XGetWidgetInfo(CancelButtonText,&cancel_info);
3332 cancel_info.width=(unsigned int) QuantumMargin+
3333 WidgetTextWidth(font_info,CancelButtonText);
3334 cancel_info.height=(unsigned int) ((3*height) >> 1);
3335 cancel_info.x=(int) (windows->widget.width-cancel_info.width-
3337 cancel_info.y=(int) (windows->widget.height-(cancel_info.height << 1));
3338 dismiss_info=cancel_info;
3339 dismiss_info.text=(char *) DismissButtonText;
3340 if (LocaleCompare(description,"Do you want to save it") == 0)
3341 dismiss_info.text=(char *) "Don't Save";
3342 dismiss_info.width=(unsigned int) QuantumMargin+
3343 WidgetTextWidth(font_info,dismiss_info.text);
3344 dismiss_info.x=(int)
3345 ((windows->widget.width >> 1)-(dismiss_info.width >> 1));
3346 yes_info=cancel_info;
3347 yes_info.text=(char *) YesButtonText;
3348 if (LocaleCompare(description,"Do you want to save it") == 0)
3349 yes_info.text=(char *) "Save";
3350 yes_info.width=(unsigned int) QuantumMargin+
3351 WidgetTextWidth(font_info,yes_info.text);
3352 if (yes_info.width < cancel_info.width)
3353 yes_info.width=cancel_info.width;
3354 yes_info.x=QuantumMargin;
3355 state&=(~UpdateConfigurationState);
3357 if (state & RedrawWidgetState)
3360 Redraw Confirm widget.
3362 width=WidgetTextWidth(font_info,(char *) reason);
3363 x=(int) ((windows->widget.width >> 1)-(width >> 1));
3364 y=(int) ((windows->widget.height >> 1)-(height << 1));
3365 (void) XDrawString(display,windows->widget.id,
3366 windows->widget.annotate_context,x,y,(char *) reason,Extent(reason));
3367 if (description != (char *) NULL)
3370 question[MagickPathExtent];
3372 (void) CopyMagickString(question,description,MagickPathExtent);
3373 (void) ConcatenateMagickString(question,"?",MagickPathExtent);
3374 width=WidgetTextWidth(font_info,question);
3375 x=(int) ((windows->widget.width >> 1)-(width >> 1));
3377 (void) XDrawString(display,windows->widget.id,
3378 windows->widget.annotate_context,x,y,question,Extent(question));
3380 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3381 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
3382 XDrawBeveledButton(display,&windows->widget,&yes_info);
3383 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
3384 state&=(~RedrawWidgetState);
3387 Wait for next event.
3389 (void) XIfEvent(display,&event,XScreenEvent,(char *) windows);
3394 if (MatteIsActive(cancel_info,event.xbutton))
3397 User pressed No button.
3399 cancel_info.raised=MagickFalse;
3400 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3403 if (MatteIsActive(dismiss_info,event.xbutton))
3406 User pressed Dismiss button.
3408 dismiss_info.raised=MagickFalse;
3409 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
3412 if (MatteIsActive(yes_info,event.xbutton))
3415 User pressed Yes button.
3417 yes_info.raised=MagickFalse;
3418 XDrawBeveledButton(display,&windows->widget,&yes_info);
3425 if (windows->widget.mapped == MagickFalse)
3427 if (cancel_info.raised == MagickFalse)
3429 if (event.xbutton.window == windows->widget.id)
3430 if (MatteIsActive(cancel_info,event.xbutton))
3435 cancel_info.raised=MagickTrue;
3436 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3438 if (dismiss_info.raised == MagickFalse)
3440 if (event.xbutton.window == windows->widget.id)
3441 if (MatteIsActive(dismiss_info,event.xbutton))
3446 dismiss_info.raised=MagickTrue;
3447 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
3449 if (yes_info.raised == MagickFalse)
3451 if (event.xbutton.window == windows->widget.id)
3452 if (MatteIsActive(yes_info,event.xbutton))
3457 yes_info.raised=MagickTrue;
3458 XDrawBeveledButton(display,&windows->widget,&yes_info);
3465 If client window delete message, exit.
3467 if (event.xclient.message_type != windows->wm_protocols)
3469 if (*event.xclient.data.l == (int) windows->wm_take_focus)
3471 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
3472 (Time) event.xclient.data.l[1]);
3475 if (*event.xclient.data.l != (int) windows->wm_delete_window)
3477 if (event.xclient.window == windows->widget.id)
3484 case ConfigureNotify:
3487 Update widget configuration.
3489 if (event.xconfigure.window != windows->widget.id)
3491 if ((event.xconfigure.width == (int) windows->widget.width) &&
3492 (event.xconfigure.height == (int) windows->widget.height))
3494 windows->widget.width=(unsigned int)
3495 MagickMax(event.xconfigure.width,(int) windows->widget.min_width);
3496 windows->widget.height=(unsigned int)
3497 MagickMax(event.xconfigure.height,(int) windows->widget.min_height);
3498 state|=UpdateConfigurationState;
3503 if (event.xcrossing.window != windows->widget.id)
3505 state&=(~InactiveWidgetState);
3510 if (event.xexpose.window != windows->widget.id)
3512 if (event.xexpose.count != 0)
3514 state|=RedrawWidgetState;
3520 command[MagickPathExtent];
3526 Respond to a user key press.
3528 if (event.xkey.window != windows->widget.id)
3530 (void) XLookupString((XKeyEvent *) &event.xkey,command,
3531 (int) sizeof(command),&key_symbol,(XComposeStatus *) NULL);
3532 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
3534 yes_info.raised=MagickFalse;
3535 XDrawBeveledButton(display,&windows->widget,&yes_info);
3544 if (event.xcrossing.window != windows->widget.id)
3546 state|=InactiveWidgetState;
3552 Discard pending button motion events.
3554 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
3555 if (state & InactiveWidgetState)
3557 if (cancel_info.raised == MatteIsActive(cancel_info,event.xmotion))
3560 Cancel button status changed.
3562 cancel_info.raised=cancel_info.raised == MagickFalse ?
3563 MagickTrue : MagickFalse;
3564 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3567 if (dismiss_info.raised == MatteIsActive(dismiss_info,event.xmotion))
3570 Dismiss button status changed.
3572 dismiss_info.raised=dismiss_info.raised == MagickFalse ?
3573 MagickTrue : MagickFalse;
3574 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
3577 if (yes_info.raised == MatteIsActive(yes_info,event.xmotion))
3580 Yes button status changed.
3582 yes_info.raised=yes_info.raised == MagickFalse ?
3583 MagickTrue : MagickFalse;
3584 XDrawBeveledButton(display,&windows->widget,&yes_info);
3592 } while ((state & ExitState) == 0);
3593 XSetCursorState(display,windows,MagickFalse);
3594 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
3595 XCheckRefreshWindows(display,windows);
3600 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3604 % X D i a l o g W i d g e t %
3608 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3610 % XDialogWidget() displays a Dialog widget with a query to the user. The user
3611 % keys a reply and presses the Ok or Cancel button to exit. The typed text is
3612 % returned as the reply function parameter.
3614 % The format of the XDialogWidget method is:
3616 % int XDialogWidget(Display *display,XWindows *windows,const char *action,
3617 % const char *query,char *reply)
3619 % A description of each parameter follows:
3621 % o display: Specifies a connection to an X server; returned from
3624 % o window: Specifies a pointer to a XWindows structure.
3626 % o action: Specifies a pointer to the action of this widget.
3628 % o query: Specifies a pointer to the query to present to the user.
3630 % o reply: the response from the user is returned in this parameter.
3633 MagickPrivate int XDialogWidget(Display *display,XWindows *windows,
3634 const char *action,const char *query,char *reply)
3636 #define CancelButtonText "Cancel"
3639 primary_selection[MagickPathExtent];
3647 static MagickBooleanType
3648 raised = MagickFalse;
3681 Determine Dialog widget attributes.
3683 assert(display != (Display *) NULL);
3684 assert(windows != (XWindows *) NULL);
3685 assert(action != (char *) NULL);
3686 assert(query != (char *) NULL);
3687 assert(reply != (char *) NULL);
3688 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",action);
3689 XCheckRefreshWindows(display,windows);
3690 font_info=windows->widget.font_info;
3691 width=WidgetTextWidth(font_info,(char *) action);
3692 if (WidgetTextWidth(font_info,CancelButtonText) > width)
3693 width=WidgetTextWidth(font_info,CancelButtonText);
3694 width+=(3*QuantumMargin) >> 1;
3695 height=(unsigned int) (font_info->ascent+font_info->descent);
3697 Position Dialog widget.
3699 windows->widget.width=(unsigned int) MagickMax((int) (2*width),(int)
3700 WidgetTextWidth(font_info,(char *) query));
3701 if (windows->widget.width < WidgetTextWidth(font_info,reply))
3702 windows->widget.width=WidgetTextWidth(font_info,reply);
3703 windows->widget.width+=6*QuantumMargin;
3704 windows->widget.min_width=(unsigned int)
3705 (width+28*XTextWidth(font_info,"#",1)+4*QuantumMargin);
3706 if (windows->widget.width < windows->widget.min_width)
3707 windows->widget.width=windows->widget.min_width;
3708 windows->widget.height=(unsigned int) (7*height+(QuantumMargin << 1));
3709 windows->widget.min_height=windows->widget.height;
3710 if (windows->widget.height < windows->widget.min_height)
3711 windows->widget.height=windows->widget.min_height;
3712 XConstrainWindowPosition(display,&windows->widget);
3716 (void) CopyMagickString(windows->widget.name,"Dialog",MagickPathExtent);
3717 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
3718 if (status != False)
3720 XSetWMName(display,windows->widget.id,&window_name);
3721 XSetWMIconName(display,windows->widget.id,&window_name);
3722 (void) XFree((void *) window_name.value);
3724 window_changes.width=(int) windows->widget.width;
3725 window_changes.height=(int) windows->widget.height;
3726 window_changes.x=windows->widget.x;
3727 window_changes.y=windows->widget.y;
3728 (void) XReconfigureWMWindow(display,windows->widget.id,windows->widget.screen,
3729 (unsigned int) (CWWidth | CWHeight | CWX | CWY),&window_changes);
3730 (void) XMapRaised(display,windows->widget.id);
3731 windows->widget.mapped=MagickFalse;
3733 Respond to X events.
3735 anomaly=(LocaleCompare(action,"Background") == 0) ||
3736 (LocaleCompare(action,"New") == 0) ||
3737 (LocaleCompare(action,"Quantize") == 0) ||
3738 (LocaleCompare(action,"Resize") == 0) ||
3739 (LocaleCompare(action,"Save") == 0) ||
3740 (LocaleCompare(action,"Shade") == 0);
3741 state=UpdateConfigurationState;
3742 XSetCursorState(display,windows,MagickTrue);
3745 if (state & UpdateConfigurationState)
3748 Initialize button information.
3750 XGetWidgetInfo(CancelButtonText,&cancel_info);
3751 cancel_info.width=width;
3752 cancel_info.height=(unsigned int) ((3*height) >> 1);
3754 (windows->widget.width-cancel_info.width-((3*QuantumMargin) >> 1));
3756 (windows->widget.height-cancel_info.height-((3*QuantumMargin) >> 1));
3757 XGetWidgetInfo(action,&action_info);
3758 action_info.width=width;
3759 action_info.height=(unsigned int) ((3*height) >> 1);
3760 action_info.x=cancel_info.x-(cancel_info.width+QuantumMargin+
3761 (action_info.bevel_width << 1));
3762 action_info.y=cancel_info.y;
3764 Initialize reply information.
3766 XGetWidgetInfo(reply,&reply_info);
3767 reply_info.raised=MagickFalse;
3768 reply_info.bevel_width--;
3769 reply_info.width=windows->widget.width-(3*QuantumMargin);
3770 reply_info.height=height << 1;
3771 reply_info.x=(3*QuantumMargin) >> 1;
3772 reply_info.y=action_info.y-reply_info.height-QuantumMargin;
3774 Initialize option information.
3776 XGetWidgetInfo("Dither",&special_info);
3777 special_info.raised=raised;
3778 special_info.bevel_width--;
3779 special_info.width=(unsigned int) QuantumMargin >> 1;
3780 special_info.height=(unsigned int) QuantumMargin >> 1;
3781 special_info.x=reply_info.x;
3782 special_info.y=action_info.y+action_info.height-special_info.height;
3783 if (LocaleCompare(action,"Background") == 0)
3784 special_info.text=(char *) "Backdrop";
3785 if (LocaleCompare(action,"New") == 0)
3786 special_info.text=(char *) "Gradation";
3787 if (LocaleCompare(action,"Resize") == 0)
3788 special_info.text=(char *) "Constrain ratio";
3789 if (LocaleCompare(action,"Save") == 0)
3790 special_info.text=(char *) "Non-progressive";
3791 if (LocaleCompare(action,"Shade") == 0)
3792 special_info.text=(char *) "Color shading";
3794 Initialize text information.
3796 XGetWidgetInfo(query,&text_info);
3797 text_info.width=reply_info.width;
3798 text_info.height=height;
3799 text_info.x=reply_info.x-(QuantumMargin >> 1);
3800 text_info.y=QuantumMargin;
3801 text_info.center=MagickFalse;
3802 state&=(~UpdateConfigurationState);
3804 if (state & RedrawWidgetState)
3807 Redraw Dialog widget.
3809 XDrawWidgetText(display,&windows->widget,&text_info);
3810 XDrawBeveledMatte(display,&windows->widget,&reply_info);
3811 XDrawMatteText(display,&windows->widget,&reply_info);
3813 XDrawBeveledButton(display,&windows->widget,&special_info);
3814 XDrawBeveledButton(display,&windows->widget,&action_info);
3815 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3816 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
3817 state&=(~RedrawWidgetState);
3820 Wait for next event.
3822 (void) XIfEvent(display,&event,XScreenEvent,(char *) windows);
3828 if (MatteIsActive(special_info,event.xbutton))
3831 Option button status changed.
3833 special_info.raised=!special_info.raised;
3834 XDrawBeveledButton(display,&windows->widget,&special_info);
3837 if (MatteIsActive(action_info,event.xbutton))
3840 User pressed Action button.
3842 action_info.raised=MagickFalse;
3843 XDrawBeveledButton(display,&windows->widget,&action_info);
3846 if (MatteIsActive(cancel_info,event.xbutton))
3849 User pressed Cancel button.
3851 cancel_info.raised=MagickFalse;
3852 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3855 if (MatteIsActive(reply_info,event.xbutton) == MagickFalse)
3857 if (event.xbutton.button != Button2)
3863 Move text cursor to position of button press.
3865 x=event.xbutton.x-reply_info.x-(QuantumMargin >> 2);
3866 for (i=1; i <= Extent(reply_info.marker); i++)
3867 if (XTextWidth(font_info,reply_info.marker,i) > x)
3869 reply_info.cursor=reply_info.marker+i-1;
3870 if (event.xbutton.time > (click_time+DoubleClick))
3871 reply_info.highlight=MagickFalse;
3875 Become the XA_PRIMARY selection owner.
3877 (void) CopyMagickString(primary_selection,reply_info.text,
3879 (void) XSetSelectionOwner(display,XA_PRIMARY,windows->widget.id,
3880 event.xbutton.time);
3881 reply_info.highlight=XGetSelectionOwner(display,XA_PRIMARY) ==
3882 windows->widget.id ? MagickTrue : MagickFalse;
3884 XDrawMatteText(display,&windows->widget,&reply_info);
3885 click_time=event.xbutton.time;
3889 Request primary selection.
3891 (void) XConvertSelection(display,XA_PRIMARY,XA_STRING,XA_STRING,
3892 windows->widget.id,event.xbutton.time);
3897 if (windows->widget.mapped == MagickFalse)
3899 if (action_info.raised == MagickFalse)
3901 if (event.xbutton.window == windows->widget.id)
3902 if (MatteIsActive(action_info,event.xbutton))
3904 action_info.raised=MagickTrue;
3905 XDrawBeveledButton(display,&windows->widget,&action_info);
3907 if (cancel_info.raised == MagickFalse)
3909 if (event.xbutton.window == windows->widget.id)
3910 if (MatteIsActive(cancel_info,event.xbutton))
3912 *reply_info.text='\0';
3915 cancel_info.raised=MagickTrue;
3916 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3923 If client window delete message, exit.
3925 if (event.xclient.message_type != windows->wm_protocols)
3927 if (*event.xclient.data.l == (int) windows->wm_take_focus)
3929 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
3930 (Time) event.xclient.data.l[1]);
3933 if (*event.xclient.data.l != (int) windows->wm_delete_window)
3935 if (event.xclient.window == windows->widget.id)
3937 *reply_info.text='\0';
3943 case ConfigureNotify:
3946 Update widget configuration.
3948 if (event.xconfigure.window != windows->widget.id)
3950 if ((event.xconfigure.width == (int) windows->widget.width) &&
3951 (event.xconfigure.height == (int) windows->widget.height))
3953 windows->widget.width=(unsigned int)
3954 MagickMax(event.xconfigure.width,(int) windows->widget.min_width);
3955 windows->widget.height=(unsigned int)
3956 MagickMax(event.xconfigure.height,(int) windows->widget.min_height);
3957 state|=UpdateConfigurationState;
3962 if (event.xcrossing.window != windows->widget.id)
3964 state&=(~InactiveWidgetState);
3969 if (event.xexpose.window != windows->widget.id)
3971 if (event.xexpose.count != 0)
3973 state|=RedrawWidgetState;
3979 command[MagickPathExtent];
3988 Respond to a user key press.
3990 if (event.xkey.window != windows->widget.id)
3992 length=XLookupString((XKeyEvent *) &event.xkey,command,
3993 (int) sizeof(command),&key_symbol,(XComposeStatus *) NULL);
3994 *(command+length)='\0';
3995 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
3997 action_info.raised=MagickFalse;
3998 XDrawBeveledButton(display,&windows->widget,&action_info);
4002 if (key_symbol == XK_Control_L)
4004 state|=ControlState;
4007 if (state & ControlState)
4008 switch ((int) key_symbol)
4014 Erase the entire line of text.
4016 *reply_info.text='\0';
4017 reply_info.cursor=reply_info.text;
4018 reply_info.marker=reply_info.text;
4019 reply_info.highlight=MagickFalse;
4025 XEditText(display,&reply_info,key_symbol,command,state);
4026 XDrawMatteText(display,&windows->widget,&reply_info);
4032 command[MagickPathExtent];
4038 Respond to a user key release.
4040 if (event.xkey.window != windows->widget.id)
4042 (void) XLookupString((XKeyEvent *) &event.xkey,command,
4043 (int) sizeof(command),&key_symbol,(XComposeStatus *) NULL);
4044 if (key_symbol == XK_Control_L)
4045 state&=(~ControlState);
4050 if (event.xcrossing.window != windows->widget.id)
4052 state|=InactiveWidgetState;
4058 Discard pending button motion events.
4060 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
4061 if (state & InactiveWidgetState)
4063 if (action_info.raised == MatteIsActive(action_info,event.xmotion))
4066 Action button status changed.
4068 action_info.raised=action_info.raised == MagickFalse ?
4069 MagickTrue : MagickFalse;
4070 XDrawBeveledButton(display,&windows->widget,&action_info);
4073 if (cancel_info.raised == MatteIsActive(cancel_info,event.xmotion))
4076 Cancel button status changed.
4078 cancel_info.raised=cancel_info.raised == MagickFalse ?
4079 MagickTrue : MagickFalse;
4080 XDrawBeveledButton(display,&windows->widget,&cancel_info);
4085 case SelectionClear:
4087 reply_info.highlight=MagickFalse;
4088 XDrawMatteText(display,&windows->widget,&reply_info);
4091 case SelectionNotify:
4107 Obtain response from primary selection.
4109 if (event.xselection.property == (Atom) None)
4111 status=XGetWindowProperty(display,event.xselection.requestor,
4112 event.xselection.property,0L,2047L,MagickTrue,XA_STRING,&type,
4113 &format,&length,&after,&data);
4114 if ((status != Success) || (type != XA_STRING) || (format == 32) ||
4117 if ((Extent(reply_info.text)+length) >= (MagickPathExtent-1))
4118 (void) XBell(display,0);
4122 Insert primary selection in reply text.
4124 *(data+length)='\0';
4125 XEditText(display,&reply_info,(KeySym) XK_Insert,(char *) data,
4127 XDrawMatteText(display,&windows->widget,&reply_info);
4129 (void) XFree((void *) data);
4132 case SelectionRequest:
4137 XSelectionRequestEvent
4140 if (reply_info.highlight == MagickFalse)
4143 Set primary selection.
4145 request=(&(event.xselectionrequest));
4146 (void) XChangeProperty(request->display,request->requestor,
4147 request->property,request->target,8,PropModeReplace,
4148 (unsigned char *) primary_selection,Extent(primary_selection));
4149 notify.type=SelectionNotify;
4150 notify.display=request->display;
4151 notify.requestor=request->requestor;
4152 notify.selection=request->selection;
4153 notify.target=request->target;
4154 notify.time=request->time;
4155 if (request->property == None)
4156 notify.property=request->target;
4158 notify.property=request->property;
4159 (void) XSendEvent(request->display,request->requestor,False,0,
4160 (XEvent *) ¬ify);
4165 } while ((state & ExitState) == 0);
4166 XSetCursorState(display,windows,MagickFalse);
4167 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
4168 XCheckRefreshWindows(display,windows);
4170 if (special_info.raised)
4173 return(raised == MagickFalse);
4177 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4181 % X F i l e B r o w s e r W i d g e t %
4185 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4187 % XFileBrowserWidget() displays a File Browser widget with a file query to the
4188 % user. The user keys a reply and presses the Action or Cancel button to
4189 % exit. The typed text is returned as the reply function parameter.
4191 % The format of the XFileBrowserWidget method is:
4193 % void XFileBrowserWidget(Display *display,XWindows *windows,
4194 % const char *action,char *reply)
4196 % A description of each parameter follows:
4198 % o display: Specifies a connection to an X server; returned from
4201 % o window: Specifies a pointer to a XWindows structure.
4203 % o action: Specifies a pointer to the action of this widget.
4205 % o reply: the response from the user is returned in this parameter.
4208 MagickPrivate void XFileBrowserWidget(Display *display,XWindows *windows,
4209 const char *action,char *reply)
4211 #define CancelButtonText "Cancel"
4212 #define DirectoryText "Directory:"
4213 #define FilenameText "File name:"
4214 #define GrabButtonText "Grab"
4215 #define FormatButtonText "Format"
4216 #define HomeButtonText "Home"
4217 #define UpButtonText "Up"
4222 home_directory[MagickPathExtent],
4223 primary_selection[MagickPathExtent],
4224 text[MagickPathExtent],
4225 working_path[MagickPathExtent];
4235 glob_pattern[MagickPathExtent] = "*",
4236 format[MagickPathExtent] = "miff";
4238 static MagickStatusType
4239 mask = (MagickStatusType) (CWWidth | CWHeight | CWX | CWY);
4285 Read filelist from current directory.
4287 assert(display != (Display *) NULL);
4288 assert(windows != (XWindows *) NULL);
4289 assert(action != (char *) NULL);
4290 assert(reply != (char *) NULL);
4291 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",action);
4292 XSetCursorState(display,windows,MagickTrue);
4293 XCheckRefreshWindows(display,windows);
4294 directory=getcwd(home_directory,MagickPathExtent);
4296 (void) CopyMagickString(working_path,home_directory,MagickPathExtent);
4297 filelist=ListFiles(working_path,glob_pattern,&files);
4298 if (filelist == (char **) NULL)
4301 Directory read failed.
4303 XNoticeWidget(display,windows,"Unable to read directory:",working_path);
4304 (void) XDialogWidget(display,windows,action,"Enter filename:",reply);
4308 Determine File Browser widget attributes.
4310 font_info=windows->widget.font_info;
4312 for (i=0; i < (ssize_t) files; i++)
4313 if (WidgetTextWidth(font_info,filelist[i]) > text_width)
4314 text_width=WidgetTextWidth(font_info,filelist[i]);
4315 width=WidgetTextWidth(font_info,(char *) action);
4316 if (WidgetTextWidth(font_info,GrabButtonText) > width)
4317 width=WidgetTextWidth(font_info,GrabButtonText);
4318 if (WidgetTextWidth(font_info,FormatButtonText) > width)
4319 width=WidgetTextWidth(font_info,FormatButtonText);
4320 if (WidgetTextWidth(font_info,CancelButtonText) > width)
4321 width=WidgetTextWidth(font_info,CancelButtonText);
4322 if (WidgetTextWidth(font_info,HomeButtonText) > width)
4323 width=WidgetTextWidth(font_info,HomeButtonText);
4324 if (WidgetTextWidth(font_info,UpButtonText) > width)
4325 width=WidgetTextWidth(font_info,UpButtonText);
4326 width+=QuantumMargin;
4327 if (WidgetTextWidth(font_info,DirectoryText) > width)
4328 width=WidgetTextWidth(font_info,DirectoryText);
4329 if (WidgetTextWidth(font_info,FilenameText) > width)
4330 width=WidgetTextWidth(font_info,FilenameText);
4331 height=(unsigned int) (font_info->ascent+font_info->descent);
4333 Position File Browser widget.
4335 windows->widget.width=width+MagickMin((int) text_width,(int) MaxTextWidth)+
4337 windows->widget.min_width=width+MinTextWidth+4*QuantumMargin;
4338 if (windows->widget.width < windows->widget.min_width)
4339 windows->widget.width=windows->widget.min_width;
4340 windows->widget.height=(unsigned int)
4341 (((81*height) >> 2)+((13*QuantumMargin) >> 1)+4);
4342 windows->widget.min_height=(unsigned int)
4343 (((23*height) >> 1)+((13*QuantumMargin) >> 1)+4);
4344 if (windows->widget.height < windows->widget.min_height)
4345 windows->widget.height=windows->widget.min_height;
4346 XConstrainWindowPosition(display,&windows->widget);
4348 Map File Browser widget.
4350 (void) CopyMagickString(windows->widget.name,"Browse and Select a File",
4352 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
4353 if (status != False)
4355 XSetWMName(display,windows->widget.id,&window_name);
4356 XSetWMIconName(display,windows->widget.id,&window_name);
4357 (void) XFree((void *) window_name.value);
4359 window_changes.width=(int) windows->widget.width;
4360 window_changes.height=(int) windows->widget.height;
4361 window_changes.x=windows->widget.x;
4362 window_changes.y=windows->widget.y;
4363 (void) XReconfigureWMWindow(display,windows->widget.id,
4364 windows->widget.screen,mask,&window_changes);
4365 (void) XMapRaised(display,windows->widget.id);
4366 windows->widget.mapped=MagickFalse;
4368 Respond to X events.
4370 XGetWidgetInfo((char *) NULL,&slider_info);
4371 XGetWidgetInfo((char *) NULL,&north_info);
4372 XGetWidgetInfo((char *) NULL,&south_info);
4373 XGetWidgetInfo((char *) NULL,&expose_info);
4375 anomaly=(LocaleCompare(action,"Composite") == 0) ||
4376 (LocaleCompare(action,"Open") == 0) || (LocaleCompare(action,"Map") == 0);
4378 delay=SuspendTime << 2;
4379 state=UpdateConfigurationState;
4382 if (state & UpdateConfigurationState)
4388 Initialize button information.
4390 XGetWidgetInfo(CancelButtonText,&cancel_info);
4391 cancel_info.width=width;
4392 cancel_info.height=(unsigned int) ((3*height) >> 1);
4394 (windows->widget.width-cancel_info.width-QuantumMargin-2);
4396 (windows->widget.height-cancel_info.height-QuantumMargin);
4397 XGetWidgetInfo(action,&action_info);
4398 action_info.width=width;
4399 action_info.height=(unsigned int) ((3*height) >> 1);
4400 action_info.x=cancel_info.x-(cancel_info.width+(QuantumMargin >> 1)+
4401 (action_info.bevel_width << 1));
4402 action_info.y=cancel_info.y;
4403 XGetWidgetInfo(GrabButtonText,&special_info);
4404 special_info.width=width;
4405 special_info.height=(unsigned int) ((3*height) >> 1);
4406 special_info.x=action_info.x-(action_info.width+(QuantumMargin >> 1)+
4407 (special_info.bevel_width << 1));
4408 special_info.y=action_info.y;
4409 if (anomaly == MagickFalse)
4414 special_info.text=(char *) FormatButtonText;
4415 p=reply+Extent(reply)-1;
4416 while ((p > (reply+1)) && (*(p-1) != '.'))
4418 if ((p > (reply+1)) && (*(p-1) == '.'))
4419 (void) CopyMagickString(format,p,MagickPathExtent);
4421 XGetWidgetInfo(UpButtonText,&up_info);
4422 up_info.width=width;
4423 up_info.height=(unsigned int) ((3*height) >> 1);
4424 up_info.x=QuantumMargin;
4425 up_info.y=((5*QuantumMargin) >> 1)+height;
4426 XGetWidgetInfo(HomeButtonText,&home_info);
4427 home_info.width=width;
4428 home_info.height=(unsigned int) ((3*height) >> 1);
4429 home_info.x=QuantumMargin;
4430 home_info.y=up_info.y+up_info.height+QuantumMargin;
4432 Initialize reply information.
4434 XGetWidgetInfo(reply,&reply_info);
4435 reply_info.raised=MagickFalse;
4436 reply_info.bevel_width--;
4437 reply_info.width=windows->widget.width-width-((6*QuantumMargin) >> 1);
4438 reply_info.height=height << 1;
4439 reply_info.x=(int) (width+(QuantumMargin << 1));
4440 reply_info.y=action_info.y-reply_info.height-QuantumMargin;
4442 Initialize scroll information.
4444 XGetWidgetInfo((char *) NULL,&scroll_info);
4445 scroll_info.bevel_width--;
4446 scroll_info.width=height;
4447 scroll_info.height=(unsigned int)
4448 (reply_info.y-up_info.y-(QuantumMargin >> 1));
4449 scroll_info.x=reply_info.x+(reply_info.width-scroll_info.width);
4450 scroll_info.y=up_info.y-reply_info.bevel_width;
4451 scroll_info.raised=MagickFalse;
4452 scroll_info.trough=MagickTrue;
4453 north_info=scroll_info;
4454 north_info.raised=MagickTrue;
4455 north_info.width-=(north_info.bevel_width << 1);
4456 north_info.height=north_info.width-1;
4457 north_info.x+=north_info.bevel_width;
4458 north_info.y+=north_info.bevel_width;
4459 south_info=north_info;
4460 south_info.y=scroll_info.y+scroll_info.height-scroll_info.bevel_width-
4463 slider_info=north_info;
4465 slider_info.width-=2;
4466 slider_info.min_y=north_info.y+north_info.height+north_info.bevel_width+
4467 slider_info.bevel_width+2;
4468 slider_info.height=scroll_info.height-((slider_info.min_y-
4469 scroll_info.y+1) << 1)+4;
4470 visible_files=scroll_info.height/(height+(height >> 3));
4471 if (files > visible_files)
4472 slider_info.height=(unsigned int)
4473 ((visible_files*slider_info.height)/files);
4474 slider_info.max_y=south_info.y-south_info.bevel_width-
4475 slider_info.bevel_width-2;
4476 slider_info.x=scroll_info.x+slider_info.bevel_width+1;
4477 slider_info.y=slider_info.min_y;
4478 expose_info=scroll_info;
4479 expose_info.y=slider_info.y;
4481 Initialize list information.
4483 XGetWidgetInfo((char *) NULL,&list_info);
4484 list_info.raised=MagickFalse;
4485 list_info.bevel_width--;
4486 list_info.width=(unsigned int)
4487 (scroll_info.x-reply_info.x-(QuantumMargin >> 1));
4488 list_info.height=scroll_info.height;
4489 list_info.x=reply_info.x;
4490 list_info.y=scroll_info.y;
4491 if (windows->widget.mapped == MagickFalse)
4492 state|=JumpListState;
4494 Initialize text information.
4497 XGetWidgetInfo(text,&text_info);
4498 text_info.center=MagickFalse;
4499 text_info.width=reply_info.width;
4500 text_info.height=height;
4501 text_info.x=list_info.x-(QuantumMargin >> 1);
4502 text_info.y=QuantumMargin;
4504 Initialize selection information.
4506 XGetWidgetInfo((char *) NULL,&selection_info);
4507 selection_info.center=MagickFalse;
4508 selection_info.width=list_info.width;
4509 selection_info.height=(unsigned int) ((9*height) >> 3);
4510 selection_info.x=list_info.x;
4511 state&=(~UpdateConfigurationState);
4513 if (state & RedrawWidgetState)
4516 Redraw File Browser window.
4519 y=text_info.y+((text_info.height-height) >> 1)+font_info->ascent;
4520 (void) XDrawString(display,windows->widget.id,
4521 windows->widget.annotate_context,x,y,DirectoryText,
4522 Extent(DirectoryText));
4523 (void) CopyMagickString(text_info.text,working_path,MagickPathExtent);
4524 (void) ConcatenateMagickString(text_info.text,DirectorySeparator,
4526 (void) ConcatenateMagickString(text_info.text,glob_pattern,
4528 XDrawWidgetText(display,&windows->widget,&text_info);
4529 XDrawBeveledButton(display,&windows->widget,&up_info);
4530 XDrawBeveledButton(display,&windows->widget,&home_info);
4531 XDrawBeveledMatte(display,&windows->widget,&list_info);
4532 XDrawBeveledMatte(display,&windows->widget,&scroll_info);
4533 XDrawTriangleNorth(display,&windows->widget,&north_info);
4534 XDrawBeveledButton(display,&windows->widget,&slider_info);
4535 XDrawTriangleSouth(display,&windows->widget,&south_info);
4537 y=reply_info.y+((reply_info.height-height) >> 1)+font_info->ascent;
4538 (void) XDrawString(display,windows->widget.id,
4539 windows->widget.annotate_context,x,y,FilenameText,
4540 Extent(FilenameText));
4541 XDrawBeveledMatte(display,&windows->widget,&reply_info);
4542 XDrawMatteText(display,&windows->widget,&reply_info);
4543 XDrawBeveledButton(display,&windows->widget,&special_info);
4544 XDrawBeveledButton(display,&windows->widget,&action_info);
4545 XDrawBeveledButton(display,&windows->widget,&cancel_info);
4546 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
4547 selection_info.id=(~0);
4548 state|=RedrawListState;
4549 state&=(~RedrawWidgetState);
4551 if (state & UpdateListState)
4562 checklist=ListFiles(working_path,glob_pattern,&number_files);
4563 if (checklist == (char **) NULL)
4566 Reply is a filename, exit.
4568 action_info.raised=MagickFalse;
4569 XDrawBeveledButton(display,&windows->widget,&action_info);
4572 for (i=0; i < (ssize_t) files; i++)
4573 filelist[i]=DestroyString(filelist[i]);
4574 if (filelist != (char **) NULL)
4575 filelist=(char **) RelinquishMagickMemory(filelist);
4582 scroll_info.height-((slider_info.min_y-scroll_info.y+1) << 1)+1;
4583 if (files > visible_files)
4584 slider_info.height=(unsigned int)
4585 ((visible_files*slider_info.height)/files);
4586 slider_info.max_y=south_info.y-south_info.bevel_width-
4587 slider_info.bevel_width-2;
4589 slider_info.y=slider_info.min_y;
4590 expose_info.y=slider_info.y;
4591 selection_info.id=(~0);
4593 state|=RedrawListState;
4595 Redraw directory name & reply.
4597 if (IsGlob(reply_info.text) == MagickFalse)
4599 *reply_info.text='\0';
4600 reply_info.cursor=reply_info.text;
4602 (void) CopyMagickString(text_info.text,working_path,MagickPathExtent);
4603 (void) ConcatenateMagickString(text_info.text,DirectorySeparator,
4605 (void) ConcatenateMagickString(text_info.text,glob_pattern,
4607 XDrawWidgetText(display,&windows->widget,&text_info);
4608 XDrawMatteText(display,&windows->widget,&reply_info);
4609 XDrawBeveledMatte(display,&windows->widget,&scroll_info);
4610 XDrawTriangleNorth(display,&windows->widget,&north_info);
4611 XDrawBeveledButton(display,&windows->widget,&slider_info);
4612 XDrawTriangleSouth(display,&windows->widget,&south_info);
4613 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
4614 state&=(~UpdateListState);
4616 if (state & JumpListState)
4619 Jump scroll to match user filename.
4622 for (i=0; i < (ssize_t) files; i++)
4623 if (LocaleCompare(filelist[i],reply) >= 0)
4626 (LocaleCompare(filelist[i],reply) == 0 ? i : ~0);
4629 if ((i < (ssize_t) slider_info.id) ||
4630 (i >= (ssize_t) (slider_info.id+visible_files)))
4631 slider_info.id=(int) i-(visible_files >> 1);
4632 selection_info.id=(~0);
4633 state|=RedrawListState;
4634 state&=(~JumpListState);
4636 if (state & RedrawListState)
4639 Determine slider id and position.
4641 if (slider_info.id >= (int) (files-visible_files))
4642 slider_info.id=(int) (files-visible_files);
4643 if ((slider_info.id < 0) || (files <= visible_files))
4645 slider_info.y=slider_info.min_y;
4647 slider_info.y+=(int) (slider_info.id*(slider_info.max_y-
4648 slider_info.min_y+1)/files);
4649 if (slider_info.id != selection_info.id)
4652 Redraw scroll bar and file names.
4654 selection_info.id=slider_info.id;
4655 selection_info.y=list_info.y+(height >> 3)+2;
4656 for (i=0; i < (ssize_t) visible_files; i++)
4658 selection_info.raised=(int) (slider_info.id+i) != list_info.id ?
4659 MagickTrue : MagickFalse;
4660 selection_info.text=(char *) NULL;
4661 if ((slider_info.id+i) < (ssize_t) files)
4662 selection_info.text=filelist[slider_info.id+i];
4663 XDrawWidgetText(display,&windows->widget,&selection_info);
4664 selection_info.y+=(int) selection_info.height;
4669 if (slider_info.y > expose_info.y)
4671 expose_info.height=(unsigned int) slider_info.y-expose_info.y;
4672 expose_info.y=slider_info.y-expose_info.height-
4673 slider_info.bevel_width-1;
4677 expose_info.height=(unsigned int) expose_info.y-slider_info.y;
4678 expose_info.y=slider_info.y+slider_info.height+
4679 slider_info.bevel_width+1;
4681 XDrawTriangleNorth(display,&windows->widget,&north_info);
4682 XDrawMatte(display,&windows->widget,&expose_info);
4683 XDrawBeveledButton(display,&windows->widget,&slider_info);
4684 XDrawTriangleSouth(display,&windows->widget,&south_info);
4685 expose_info.y=slider_info.y;
4687 state&=(~RedrawListState);
4690 Wait for next event.
4692 if (north_info.raised && south_info.raised)
4693 (void) XIfEvent(display,&event,XScreenEvent,(char *) windows);
4697 Brief delay before advancing scroll bar.
4699 XDelay(display,delay);
4701 (void) XCheckIfEvent(display,&event,XScreenEvent,(char *) windows);
4702 if (north_info.raised == MagickFalse)
4703 if (slider_info.id > 0)
4709 state|=RedrawListState;
4711 if (south_info.raised == MagickFalse)
4712 if (slider_info.id < (int) files)
4718 state|=RedrawListState;
4720 if (event.type != ButtonRelease)
4727 if (MatteIsActive(slider_info,event.xbutton))
4732 slider_info.active=MagickTrue;
4735 if (MatteIsActive(north_info,event.xbutton))
4736 if (slider_info.id > 0)
4741 north_info.raised=MagickFalse;
4743 state|=RedrawListState;
4746 if (MatteIsActive(south_info,event.xbutton))
4747 if (slider_info.id < (int) files)
4752 south_info.raised=MagickFalse;
4754 state|=RedrawListState;
4757 if (MatteIsActive(scroll_info,event.xbutton))
4762 if (event.xbutton.y < slider_info.y)
4763 slider_info.id-=(visible_files-1);
4765 slider_info.id+=(visible_files-1);
4766 state|=RedrawListState;
4769 if (MatteIsActive(list_info,event.xbutton))
4775 User pressed file matte.
4777 id=slider_info.id+(event.xbutton.y-(list_info.y+(height >> 1))+1)/
4778 selection_info.height;
4779 if (id >= (int) files)
4781 (void) CopyMagickString(reply_info.text,filelist[id],MagickPathExtent);
4782 reply_info.highlight=MagickFalse;
4783 reply_info.marker=reply_info.text;
4784 reply_info.cursor=reply_info.text+Extent(reply_info.text);
4785 XDrawMatteText(display,&windows->widget,&reply_info);
4786 if (id == list_info.id)
4791 p=reply_info.text+strlen(reply_info.text)-1;
4792 if (*p == *DirectorySeparator)
4793 ChopPathComponents(reply_info.text,1);
4794 (void) ConcatenateMagickString(working_path,DirectorySeparator,
4796 (void) ConcatenateMagickString(working_path,reply_info.text,
4799 state|=UpdateListState;
4801 selection_info.id=(~0);
4803 state|=RedrawListState;
4806 if (MatteIsActive(up_info,event.xbutton))
4809 User pressed Up button.
4811 up_info.raised=MagickFalse;
4812 XDrawBeveledButton(display,&windows->widget,&up_info);
4815 if (MatteIsActive(home_info,event.xbutton))
4818 User pressed Home button.
4820 home_info.raised=MagickFalse;
4821 XDrawBeveledButton(display,&windows->widget,&home_info);
4824 if (MatteIsActive(special_info,event.xbutton))
4827 User pressed Special button.
4829 special_info.raised=MagickFalse;
4830 XDrawBeveledButton(display,&windows->widget,&special_info);
4833 if (MatteIsActive(action_info,event.xbutton))
4836 User pressed action button.
4838 action_info.raised=MagickFalse;
4839 XDrawBeveledButton(display,&windows->widget,&action_info);
4842 if (MatteIsActive(cancel_info,event.xbutton))
4845 User pressed Cancel button.
4847 cancel_info.raised=MagickFalse;
4848 XDrawBeveledButton(display,&windows->widget,&cancel_info);
4851 if (MatteIsActive(reply_info,event.xbutton) == MagickFalse)
4853 if (event.xbutton.button != Button2)
4859 Move text cursor to position of button press.
4861 x=event.xbutton.x-reply_info.x-(QuantumMargin >> 2);
4862 for (i=1; i <= (ssize_t) Extent(reply_info.marker); i++)
4863 if (XTextWidth(font_info,reply_info.marker,(int) i) > x)
4865 reply_info.cursor=reply_info.marker+i-1;
4866 if (event.xbutton.time > (click_time+DoubleClick))
4867 reply_info.highlight=MagickFalse;
4871 Become the XA_PRIMARY selection owner.
4873 (void) CopyMagickString(primary_selection,reply_info.text,
4875 (void) XSetSelectionOwner(display,XA_PRIMARY,windows->widget.id,
4876 event.xbutton.time);
4877 reply_info.highlight=XGetSelectionOwner(display,XA_PRIMARY) ==
4878 windows->widget.id ? MagickTrue : MagickFalse;
4880 XDrawMatteText(display,&windows->widget,&reply_info);
4881 click_time=event.xbutton.time;
4885 Request primary selection.
4887 (void) XConvertSelection(display,XA_PRIMARY,XA_STRING,XA_STRING,
4888 windows->widget.id,event.xbutton.time);
4893 if (windows->widget.mapped == MagickFalse)
4895 if (north_info.raised == MagickFalse)
4898 User released up button.
4900 delay=SuspendTime << 2;
4901 north_info.raised=MagickTrue;
4902 XDrawTriangleNorth(display,&windows->widget,&north_info);
4904 if (south_info.raised == MagickFalse)
4907 User released down button.
4909 delay=SuspendTime << 2;
4910 south_info.raised=MagickTrue;
4911 XDrawTriangleSouth(display,&windows->widget,&south_info);
4913 if (slider_info.active)
4916 Stop tracking slider.
4918 slider_info.active=MagickFalse;
4921 if (up_info.raised == MagickFalse)
4923 if (event.xbutton.window == windows->widget.id)
4924 if (MatteIsActive(up_info,event.xbutton))
4926 ChopPathComponents(working_path,1);
4927 if (*working_path == '\0')
4928 (void) CopyMagickString(working_path,DirectorySeparator,
4930 state|=UpdateListState;
4932 up_info.raised=MagickTrue;
4933 XDrawBeveledButton(display,&windows->widget,&up_info);
4935 if (home_info.raised == MagickFalse)
4937 if (event.xbutton.window == windows->widget.id)
4938 if (MatteIsActive(home_info,event.xbutton))
4940 (void) CopyMagickString(working_path,home_directory,
4942 state|=UpdateListState;
4944 home_info.raised=MagickTrue;
4945 XDrawBeveledButton(display,&windows->widget,&home_info);
4947 if (special_info.raised == MagickFalse)
4949 if (anomaly == MagickFalse)
4961 Let user select image format.
4963 exception=AcquireExceptionInfo();
4964 formats=GetMagickList("*",&number_formats,exception);
4965 exception=DestroyExceptionInfo(exception);
4966 (void) XCheckDefineCursor(display,windows->widget.id,
4967 windows->widget.busy_cursor);
4968 windows->popup.x=windows->widget.x+60;
4969 windows->popup.y=windows->widget.y+60;
4970 XListBrowserWidget(display,windows,&windows->popup,
4971 (const char **) formats,"Select","Select image format type:",
4973 XSetCursorState(display,windows,MagickTrue);
4974 (void) XCheckDefineCursor(display,windows->widget.id,
4975 windows->widget.cursor);
4976 LocaleLower(format);
4977 AppendImageFormat(format,reply_info.text);
4978 reply_info.cursor=reply_info.text+Extent(reply_info.text);
4979 XDrawMatteText(display,&windows->widget,&reply_info);
4980 special_info.raised=MagickTrue;
4981 XDrawBeveledButton(display,&windows->widget,&special_info);
4982 for (i=0; i < (ssize_t) number_formats; i++)
4983 formats[i]=DestroyString(formats[i]);
4984 formats=(char **) RelinquishMagickMemory(formats);
4987 if (event.xbutton.window == windows->widget.id)
4988 if (MatteIsActive(special_info,event.xbutton))
4990 (void) CopyMagickString(working_path,"x:",MagickPathExtent);
4993 special_info.raised=MagickTrue;
4994 XDrawBeveledButton(display,&windows->widget,&special_info);
4996 if (action_info.raised == MagickFalse)
4998 if (event.xbutton.window == windows->widget.id)
5000 if (MatteIsActive(action_info,event.xbutton))
5002 if (*reply_info.text == '\0')
5003 (void) XBell(display,0);
5008 action_info.raised=MagickTrue;
5009 XDrawBeveledButton(display,&windows->widget,&action_info);
5011 if (cancel_info.raised == MagickFalse)
5013 if (event.xbutton.window == windows->widget.id)
5014 if (MatteIsActive(cancel_info,event.xbutton))
5016 *reply_info.text='\0';
5020 cancel_info.raised=MagickTrue;
5021 XDrawBeveledButton(display,&windows->widget,&cancel_info);
5028 If client window delete message, exit.
5030 if (event.xclient.message_type != windows->wm_protocols)
5032 if (*event.xclient.data.l == (int) windows->wm_take_focus)
5034 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
5035 (Time) event.xclient.data.l[1]);
5038 if (*event.xclient.data.l != (int) windows->wm_delete_window)
5040 if (event.xclient.window == windows->widget.id)
5042 *reply_info.text='\0';
5048 case ConfigureNotify:
5051 Update widget configuration.
5053 if (event.xconfigure.window != windows->widget.id)
5055 if ((event.xconfigure.width == (int) windows->widget.width) &&
5056 (event.xconfigure.height == (int) windows->widget.height))
5058 windows->widget.width=(unsigned int)
5059 MagickMax(event.xconfigure.width,(int) windows->widget.min_width);
5060 windows->widget.height=(unsigned int)
5061 MagickMax(event.xconfigure.height,(int) windows->widget.min_height);
5062 state|=UpdateConfigurationState;
5067 if (event.xcrossing.window != windows->widget.id)
5069 state&=(~InactiveWidgetState);
5074 if (event.xexpose.window != windows->widget.id)
5076 if (event.xexpose.count != 0)
5078 state|=RedrawWidgetState;
5084 command[MagickPathExtent];
5093 Respond to a user key press.
5095 if (event.xkey.window != windows->widget.id)
5097 length=XLookupString((XKeyEvent *) &event.xkey,command,
5098 (int) sizeof(command),&key_symbol,(XComposeStatus *) NULL);
5099 *(command+length)='\0';
5100 if (AreaIsActive(scroll_info,event.xkey))
5105 switch ((int) key_symbol)
5128 slider_info.id-=visible_files;
5134 slider_info.id+=visible_files;
5140 slider_info.id=(int) files;
5144 state|=RedrawListState;
5147 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
5150 Read new directory or glob patterm.
5152 if (*reply_info.text == '\0')
5154 if (IsGlob(reply_info.text))
5155 (void) CopyMagickString(glob_pattern,reply_info.text,
5159 (void) ConcatenateMagickString(working_path,DirectorySeparator,
5161 (void) ConcatenateMagickString(working_path,reply_info.text,
5163 if (*working_path == '~')
5164 ExpandFilename(working_path);
5167 state|=UpdateListState;
5170 if (key_symbol == XK_Control_L)
5172 state|=ControlState;
5175 if (state & ControlState)
5176 switch ((int) key_symbol)
5182 Erase the entire line of text.
5184 *reply_info.text='\0';
5185 reply_info.cursor=reply_info.text;
5186 reply_info.marker=reply_info.text;
5187 reply_info.highlight=MagickFalse;
5193 XEditText(display,&reply_info,key_symbol,command,state);
5194 XDrawMatteText(display,&windows->widget,&reply_info);
5195 state|=JumpListState;
5201 command[MagickPathExtent];
5207 Respond to a user key release.
5209 if (event.xkey.window != windows->widget.id)
5211 (void) XLookupString((XKeyEvent *) &event.xkey,command,
5212 (int) sizeof(command),&key_symbol,(XComposeStatus *) NULL);
5213 if (key_symbol == XK_Control_L)
5214 state&=(~ControlState);
5219 if (event.xcrossing.window != windows->widget.id)
5221 state|=InactiveWidgetState;
5233 Discard pending button motion events.
5235 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
5236 if (slider_info.active)
5241 slider_info.y=event.xmotion.y-
5242 ((slider_info.height+slider_info.bevel_width) >> 1)+1;
5243 if (slider_info.y < slider_info.min_y)
5244 slider_info.y=slider_info.min_y;
5245 if (slider_info.y > slider_info.max_y)
5246 slider_info.y=slider_info.max_y;
5248 if (slider_info.y != slider_info.min_y)
5249 slider_info.id=(int) ((files*(slider_info.y-slider_info.min_y+1))/
5250 (slider_info.max_y-slider_info.min_y+1));
5251 state|=RedrawListState;
5254 if (state & InactiveWidgetState)
5256 if (up_info.raised == MatteIsActive(up_info,event.xmotion))
5259 Up button status changed.
5261 up_info.raised=!up_info.raised;
5262 XDrawBeveledButton(display,&windows->widget,&up_info);
5265 if (home_info.raised == MatteIsActive(home_info,event.xmotion))
5268 Home button status changed.
5270 home_info.raised=!home_info.raised;
5271 XDrawBeveledButton(display,&windows->widget,&home_info);
5274 if (special_info.raised == MatteIsActive(special_info,event.xmotion))
5277 Grab button status changed.
5279 special_info.raised=!special_info.raised;
5280 XDrawBeveledButton(display,&windows->widget,&special_info);
5283 if (action_info.raised == MatteIsActive(action_info,event.xmotion))
5286 Action button status changed.
5288 action_info.raised=action_info.raised == MagickFalse ?
5289 MagickTrue : MagickFalse;
5290 XDrawBeveledButton(display,&windows->widget,&action_info);
5293 if (cancel_info.raised == MatteIsActive(cancel_info,event.xmotion))
5296 Cancel button status changed.
5298 cancel_info.raised=cancel_info.raised == MagickFalse ?
5299 MagickTrue : MagickFalse;
5300 XDrawBeveledButton(display,&windows->widget,&cancel_info);
5305 case SelectionClear:
5307 reply_info.highlight=MagickFalse;
5308 XDrawMatteText(display,&windows->widget,&reply_info);
5311 case SelectionNotify:
5327 Obtain response from primary selection.
5329 if (event.xselection.property == (Atom) None)
5331 status=XGetWindowProperty(display,event.xselection.requestor,
5332 event.xselection.property,0L,2047L,MagickTrue,XA_STRING,&type,
5333 &format,&length,&after,&data);
5334 if ((status != Success) || (type != XA_STRING) || (format == 32) ||
5337 if ((Extent(reply_info.text)+length) >= (MagickPathExtent-1))
5338 (void) XBell(display,0);
5342 Insert primary selection in reply text.
5344 *(data+length)='\0';
5345 XEditText(display,&reply_info,(KeySym) XK_Insert,(char *) data,
5347 XDrawMatteText(display,&windows->widget,&reply_info);
5348 state|=JumpListState;
5349 state|=RedrawActionState;
5351 (void) XFree((void *) data);
5354 case SelectionRequest:
5359 XSelectionRequestEvent
5362 if (reply_info.highlight == MagickFalse)
5365 Set primary selection.
5367 request=(&(event.xselectionrequest));
5368 (void) XChangeProperty(request->display,request->requestor,
5369 request->property,request->target,8,PropModeReplace,
5370 (unsigned char *) primary_selection,Extent(primary_selection));
5371 notify.type=SelectionNotify;
5372 notify.display=request->display;
5373 notify.requestor=request->requestor;
5374 notify.selection=request->selection;
5375 notify.target=request->target;
5376 notify.time=request->time;
5377 if (request->property == None)
5378 notify.property=request->target;
5380 notify.property=request->property;
5381 (void) XSendEvent(request->display,request->requestor,False,0,
5382 (XEvent *) ¬ify);
5387 } while ((state & ExitState) == 0);
5388 XSetCursorState(display,windows,MagickFalse);
5389 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
5390 XCheckRefreshWindows(display,windows);
5394 for (i=0; i < (ssize_t) files; i++)
5395 filelist[i]=DestroyString(filelist[i]);
5396 if (filelist != (char **) NULL)
5397 filelist=(char **) RelinquishMagickMemory(filelist);
5400 (void) ConcatenateMagickString(working_path,DirectorySeparator,
5402 (void) ConcatenateMagickString(working_path,reply,MagickPathExtent);
5404 (void) CopyMagickString(reply,working_path,MagickPathExtent);
5406 ExpandFilename(reply);
5410 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5414 % X F o n t B r o w s e r W i d g e t %
5418 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5420 % XFontBrowserWidget() displays a Font Browser widget with a font query to the
5421 % user. The user keys a reply and presses the Action or Cancel button to
5422 % exit. The typed text is returned as the reply function parameter.
5424 % The format of the XFontBrowserWidget method is:
5426 % void XFontBrowserWidget(Display *display,XWindows *windows,
5427 % const char *action,char *reply)
5429 % A description of each parameter follows:
5431 % o display: Specifies a connection to an X server; returned from
5434 % o window: Specifies a pointer to a XWindows structure.
5436 % o action: Specifies a pointer to the action of this widget.
5438 % o reply: the response from the user is returned in this parameter.
5443 #if defined(__cplusplus) || defined(c_plusplus)
5447 static int FontCompare(const void *x,const void *y)
5453 p=(char *) *((char **) x);
5454 q=(char *) *((char **) y);
5455 while ((*p != '\0') && (*q != '\0') && (*p == *q))
5463 #if defined(__cplusplus) || defined(c_plusplus)
5467 MagickPrivate void XFontBrowserWidget(Display *display,XWindows *windows,
5468 const char *action,char *reply)
5470 #define BackButtonText "Back"
5471 #define CancelButtonText "Cancel"
5472 #define FontnameText "Name:"
5473 #define FontPatternText "Pattern:"
5474 #define ResetButtonText "Reset"
5477 back_pattern[MagickPathExtent],
5480 primary_selection[MagickPathExtent],
5481 reset_pattern[MagickPathExtent],
5482 text[MagickPathExtent];
5493 glob_pattern[MagickPathExtent] = "*";
5495 static MagickStatusType
5496 mask = (MagickStatusType) (CWWidth | CWHeight | CWX | CWY);
5540 Get font list and sort in ascending order.
5542 assert(display != (Display *) NULL);
5543 assert(windows != (XWindows *) NULL);
5544 assert(action != (char *) NULL);
5545 assert(reply != (char *) NULL);
5546 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",action);
5547 XSetCursorState(display,windows,MagickTrue);
5548 XCheckRefreshWindows(display,windows);
5549 (void) CopyMagickString(back_pattern,glob_pattern,MagickPathExtent);
5550 (void) CopyMagickString(reset_pattern,"*",MagickPathExtent);
5551 fontlist=XListFonts(display,glob_pattern,32767,&fonts);
5555 Pattern failed, obtain all the fonts.
5557 XNoticeWidget(display,windows,"Unable to obtain fonts names:",
5559 (void) CopyMagickString(glob_pattern,"*",MagickPathExtent);
5560 fontlist=XListFonts(display,glob_pattern,32767,&fonts);
5561 if (fontlist == (char **) NULL)
5563 XNoticeWidget(display,windows,"Unable to obtain fonts names:",
5569 Sort font list in ascending order.
5572 fontlist=(char **) AcquireQuantumMemory((size_t) fonts,sizeof(*fontlist));
5573 if (fontlist == (char **) NULL)
5575 XNoticeWidget(display,windows,"MemoryAllocationFailed",
5576 "UnableToViewFonts");
5579 for (i=0; i < fonts; i++)
5580 fontlist[i]=listhead[i];
5581 qsort((void *) fontlist,(size_t) fonts,sizeof(*fontlist),FontCompare);
5583 Determine Font Browser widget attributes.
5585 font_info=windows->widget.font_info;
5587 for (i=0; i < fonts; i++)
5588 if (WidgetTextWidth(font_info,fontlist[i]) > text_width)
5589 text_width=WidgetTextWidth(font_info,fontlist[i]);
5590 width=WidgetTextWidth(font_info,(char *) action);
5591 if (WidgetTextWidth(font_info,CancelButtonText) > width)
5592 width=WidgetTextWidth(font_info,CancelButtonText);
5593 if (WidgetTextWidth(font_info,ResetButtonText) > width)
5594 width=WidgetTextWidth(font_info,ResetButtonText);
5595 if (WidgetTextWidth(font_info,BackButtonText) > width)
5596 width=WidgetTextWidth(font_info,BackButtonText);
5597 width+=QuantumMargin;
5598 if (WidgetTextWidth(font_info,FontPatternText) > width)
5599 width=WidgetTextWidth(font_info,FontPatternText);
5600 if (WidgetTextWidth(font_info,FontnameText) > width)
5601 width=WidgetTextWidth(font_info,FontnameText);
5602 height=(unsigned int) (font_info->ascent+font_info->descent);
5604 Position Font Browser widget.
5606 windows->widget.width=width+MagickMin((int) text_width,(int) MaxTextWidth)+
5608 windows->widget.min_width=width+MinTextWidth+4*QuantumMargin;
5609 if (windows->widget.width < windows->widget.min_width)
5610 windows->widget.width=windows->widget.min_width;
5611 windows->widget.height=(unsigned int)
5612 (((85*height) >> 2)+((13*QuantumMargin) >> 1)+4);
5613 windows->widget.min_height=(unsigned int)
5614 (((27*height) >> 1)+((13*QuantumMargin) >> 1)+4);
5615 if (windows->widget.height < windows->widget.min_height)
5616 windows->widget.height=windows->widget.min_height;
5617 XConstrainWindowPosition(display,&windows->widget);
5619 Map Font Browser widget.
5621 (void) CopyMagickString(windows->widget.name,"Browse and Select a Font",
5623 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
5624 if (status != False)
5626 XSetWMName(display,windows->widget.id,&window_name);
5627 XSetWMIconName(display,windows->widget.id,&window_name);
5628 (void) XFree((void *) window_name.value);
5630 window_changes.width=(int) windows->widget.width;
5631 window_changes.height=(int) windows->widget.height;
5632 window_changes.x=windows->widget.x;
5633 window_changes.y=windows->widget.y;
5634 (void) XReconfigureWMWindow(display,windows->widget.id,
5635 windows->widget.screen,mask,&window_changes);
5636 (void) XMapRaised(display,windows->widget.id);
5637 windows->widget.mapped=MagickFalse;
5639 Respond to X events.
5641 XGetWidgetInfo((char *) NULL,&slider_info);
5642 XGetWidgetInfo((char *) NULL,&north_info);
5643 XGetWidgetInfo((char *) NULL,&south_info);
5644 XGetWidgetInfo((char *) NULL,&expose_info);
5645 XGetWidgetInfo((char *) NULL,&selection_info);
5647 delay=SuspendTime << 2;
5648 state=UpdateConfigurationState;
5651 if (state & UpdateConfigurationState)
5657 Initialize button information.
5659 XGetWidgetInfo(CancelButtonText,&cancel_info);
5660 cancel_info.width=width;
5661 cancel_info.height=(unsigned int) ((3*height) >> 1);
5663 (windows->widget.width-cancel_info.width-QuantumMargin-2);
5665 (windows->widget.height-cancel_info.height-QuantumMargin);
5666 XGetWidgetInfo(action,&action_info);
5667 action_info.width=width;
5668 action_info.height=(unsigned int) ((3*height) >> 1);
5669 action_info.x=cancel_info.x-(cancel_info.width+(QuantumMargin >> 1)+
5670 (action_info.bevel_width << 1));
5671 action_info.y=cancel_info.y;
5672 XGetWidgetInfo(BackButtonText,&back_info);
5673 back_info.width=width;
5674 back_info.height=(unsigned int) ((3*height) >> 1);
5675 back_info.x=QuantumMargin;
5676 back_info.y=((5*QuantumMargin) >> 1)+height;
5677 XGetWidgetInfo(ResetButtonText,&reset_info);
5678 reset_info.width=width;
5679 reset_info.height=(unsigned int) ((3*height) >> 1);
5680 reset_info.x=QuantumMargin;
5681 reset_info.y=back_info.y+back_info.height+QuantumMargin;
5683 Initialize reply information.
5685 XGetWidgetInfo(reply,&reply_info);
5686 reply_info.raised=MagickFalse;
5687 reply_info.bevel_width--;
5688 reply_info.width=windows->widget.width-width-((6*QuantumMargin) >> 1);
5689 reply_info.height=height << 1;
5690 reply_info.x=(int) (width+(QuantumMargin << 1));
5691 reply_info.y=action_info.y-(action_info.height << 1)-QuantumMargin;
5693 Initialize mode information.
5695 XGetWidgetInfo(reply,&mode_info);
5696 mode_info.bevel_width=0;
5697 mode_info.width=(unsigned int)
5698 (action_info.x-reply_info.x-QuantumMargin);
5699 mode_info.height=action_info.height << 1;
5700 mode_info.x=reply_info.x;
5701 mode_info.y=action_info.y-action_info.height+action_info.bevel_width;
5703 Initialize scroll information.
5705 XGetWidgetInfo((char *) NULL,&scroll_info);
5706 scroll_info.bevel_width--;
5707 scroll_info.width=height;
5708 scroll_info.height=(unsigned int)
5709 (reply_info.y-back_info.y-(QuantumMargin >> 1));
5710 scroll_info.x=reply_info.x+(reply_info.width-scroll_info.width);
5711 scroll_info.y=back_info.y-reply_info.bevel_width;
5712 scroll_info.raised=MagickFalse;
5713 scroll_info.trough=MagickTrue;
5714 north_info=scroll_info;
5715 north_info.raised=MagickTrue;
5716 north_info.width-=(north_info.bevel_width << 1);
5717 north_info.height=north_info.width-1;
5718 north_info.x+=north_info.bevel_width;
5719 north_info.y+=north_info.bevel_width;
5720 south_info=north_info;
5721 south_info.y=scroll_info.y+scroll_info.height-scroll_info.bevel_width-
5724 slider_info=north_info;
5726 slider_info.width-=2;
5727 slider_info.min_y=north_info.y+north_info.height+north_info.bevel_width+
5728 slider_info.bevel_width+2;
5729 slider_info.height=scroll_info.height-((slider_info.min_y-
5730 scroll_info.y+1) << 1)+4;
5731 visible_fonts=scroll_info.height/(height+(height >> 3));
5732 if (fonts > (int) visible_fonts)
5733 slider_info.height=(visible_fonts*slider_info.height)/fonts;
5734 slider_info.max_y=south_info.y-south_info.bevel_width-
5735 slider_info.bevel_width-2;
5736 slider_info.x=scroll_info.x+slider_info.bevel_width+1;
5737 slider_info.y=slider_info.min_y;
5738 expose_info=scroll_info;
5739 expose_info.y=slider_info.y;
5741 Initialize list information.
5743 XGetWidgetInfo((char *) NULL,&list_info);
5744 list_info.raised=MagickFalse;
5745 list_info.bevel_width--;
5746 list_info.width=(unsigned int)
5747 (scroll_info.x-reply_info.x-(QuantumMargin >> 1));
5748 list_info.height=scroll_info.height;
5749 list_info.x=reply_info.x;
5750 list_info.y=scroll_info.y;
5751 if (windows->widget.mapped == MagickFalse)
5752 state|=JumpListState;
5754 Initialize text information.
5757 XGetWidgetInfo(text,&text_info);
5758 text_info.center=MagickFalse;
5759 text_info.width=reply_info.width;
5760 text_info.height=height;
5761 text_info.x=list_info.x-(QuantumMargin >> 1);
5762 text_info.y=QuantumMargin;
5764 Initialize selection information.
5766 XGetWidgetInfo((char *) NULL,&selection_info);
5767 selection_info.center=MagickFalse;
5768 selection_info.width=list_info.width;
5769 selection_info.height=(unsigned int) ((9*height) >> 3);
5770 selection_info.x=list_info.x;
5771 state&=(~UpdateConfigurationState);
5773 if (state & RedrawWidgetState)
5776 Redraw Font Browser window.
5779 y=text_info.y+((text_info.height-height) >> 1)+font_info->ascent;
5780 (void) XDrawString(display,windows->widget.id,
5781 windows->widget.annotate_context,x,y,FontPatternText,
5782 Extent(FontPatternText));
5783 (void) CopyMagickString(text_info.text,glob_pattern,MagickPathExtent);
5784 XDrawWidgetText(display,&windows->widget,&text_info);
5785 XDrawBeveledButton(display,&windows->widget,&back_info);
5786 XDrawBeveledButton(display,&windows->widget,&reset_info);
5787 XDrawBeveledMatte(display,&windows->widget,&list_info);
5788 XDrawBeveledMatte(display,&windows->widget,&scroll_info);
5789 XDrawTriangleNorth(display,&windows->widget,&north_info);
5790 XDrawBeveledButton(display,&windows->widget,&slider_info);
5791 XDrawTriangleSouth(display,&windows->widget,&south_info);
5793 y=reply_info.y+((reply_info.height-height) >> 1)+font_info->ascent;
5794 (void) XDrawString(display,windows->widget.id,
5795 windows->widget.annotate_context,x,y,FontnameText,
5796 Extent(FontnameText));
5797 XDrawBeveledMatte(display,&windows->widget,&reply_info);
5798 XDrawMatteText(display,&windows->widget,&reply_info);
5799 XDrawBeveledButton(display,&windows->widget,&action_info);
5800 XDrawBeveledButton(display,&windows->widget,&cancel_info);
5801 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
5802 selection_info.id=(~0);
5803 state|=RedrawActionState;
5804 state|=RedrawListState;
5805 state&=(~RedrawWidgetState);
5807 if (state & UpdateListState)
5818 checklist=XListFonts(display,glob_pattern,32767,&number_fonts);
5819 if (checklist == (char **) NULL)
5821 if ((strchr(glob_pattern,'*') == (char *) NULL) &&
5822 (strchr(glob_pattern,'?') == (char *) NULL))
5825 Might be a scaleable font-- exit.
5827 (void) CopyMagickString(reply,glob_pattern,MagickPathExtent);
5828 (void) CopyMagickString(glob_pattern,back_pattern,MagickPathExtent);
5829 action_info.raised=MagickFalse;
5830 XDrawBeveledButton(display,&windows->widget,&action_info);
5833 (void) CopyMagickString(glob_pattern,back_pattern,MagickPathExtent);
5834 (void) XBell(display,0);
5837 if (number_fonts == 1)
5840 Reply is a single font name-- exit.
5842 (void) CopyMagickString(reply,checklist[0],MagickPathExtent);
5843 (void) CopyMagickString(glob_pattern,back_pattern,MagickPathExtent);
5844 (void) XFreeFontNames(checklist);
5845 action_info.raised=MagickFalse;
5846 XDrawBeveledButton(display,&windows->widget,&action_info);
5851 (void) XFreeFontNames(listhead);
5852 fontlist=(char **) RelinquishMagickMemory(fontlist);
5857 Sort font list in ascending order.
5860 fontlist=(char **) AcquireQuantumMemory((size_t) fonts,
5862 if (fontlist == (char **) NULL)
5864 XNoticeWidget(display,windows,"MemoryAllocationFailed",
5865 "UnableToViewFonts");
5868 for (i=0; i < fonts; i++)
5869 fontlist[i]=listhead[i];
5870 qsort((void *) fontlist,(size_t) fonts,sizeof(*fontlist),FontCompare);
5872 scroll_info.height-((slider_info.min_y-scroll_info.y+1) << 1)+1;
5873 if (fonts > (int) visible_fonts)
5874 slider_info.height=(visible_fonts*slider_info.height)/fonts;
5875 slider_info.max_y=south_info.y-south_info.bevel_width-
5876 slider_info.bevel_width-2;
5878 slider_info.y=slider_info.min_y;
5879 expose_info.y=slider_info.y;
5880 selection_info.id=(~0);
5882 state|=RedrawListState;
5884 Redraw font name & reply.
5886 *reply_info.text='\0';
5887 reply_info.cursor=reply_info.text;
5888 (void) CopyMagickString(text_info.text,glob_pattern,MagickPathExtent);
5889 XDrawWidgetText(display,&windows->widget,&text_info);
5890 XDrawMatteText(display,&windows->widget,&reply_info);
5891 XDrawBeveledMatte(display,&windows->widget,&scroll_info);
5892 XDrawTriangleNorth(display,&windows->widget,&north_info);
5893 XDrawBeveledButton(display,&windows->widget,&slider_info);
5894 XDrawTriangleSouth(display,&windows->widget,&south_info);
5895 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
5896 state&=(~UpdateListState);
5898 if (state & JumpListState)
5901 Jump scroll to match user font.
5904 for (i=0; i < fonts; i++)
5905 if (LocaleCompare(fontlist[i],reply) >= 0)
5907 list_info.id=LocaleCompare(fontlist[i],reply) == 0 ? i : ~0;
5910 if ((i < slider_info.id) || (i >= (int) (slider_info.id+visible_fonts)))
5911 slider_info.id=i-(visible_fonts >> 1);
5912 selection_info.id=(~0);
5913 state|=RedrawListState;
5914 state&=(~JumpListState);
5916 if (state & RedrawListState)
5919 Determine slider id and position.
5921 if (slider_info.id >= (int) (fonts-visible_fonts))
5922 slider_info.id=fonts-visible_fonts;
5923 if ((slider_info.id < 0) || (fonts <= (int) visible_fonts))
5925 slider_info.y=slider_info.min_y;
5928 slider_info.id*(slider_info.max_y-slider_info.min_y+1)/fonts;
5929 if (slider_info.id != selection_info.id)
5932 Redraw scroll bar and file names.
5934 selection_info.id=slider_info.id;
5935 selection_info.y=list_info.y+(height >> 3)+2;
5936 for (i=0; i < (int) visible_fonts; i++)
5938 selection_info.raised=(slider_info.id+i) != list_info.id ?
5939 MagickTrue : MagickFalse;
5940 selection_info.text=(char *) NULL;
5941 if ((slider_info.id+i) < fonts)
5942 selection_info.text=fontlist[slider_info.id+i];
5943 XDrawWidgetText(display,&windows->widget,&selection_info);
5944 selection_info.y+=(int) selection_info.height;
5949 if (slider_info.y > expose_info.y)
5951 expose_info.height=(unsigned int) slider_info.y-expose_info.y;
5952 expose_info.y=slider_info.y-expose_info.height-
5953 slider_info.bevel_width-1;
5957 expose_info.height=(unsigned int) expose_info.y-slider_info.y;
5958 expose_info.y=slider_info.y+slider_info.height+
5959 slider_info.bevel_width+1;
5961 XDrawTriangleNorth(display,&windows->widget,&north_info);
5962 XDrawMatte(display,&windows->widget,&expose_info);
5963 XDrawBeveledButton(display,&windows->widget,&slider_info);
5964 XDrawTriangleSouth(display,&windows->widget,&south_info);
5965 expose_info.y=slider_info.y;
5967 state&=(~RedrawListState);
5969 if (state & RedrawActionState)
5975 Display the selected font in a drawing area.
5977 save_info=windows->widget.font_info;
5978 font_info=XLoadQueryFont(display,reply_info.text);
5979 if (font_info != (XFontStruct *) NULL)
5981 windows->widget.font_info=font_info;
5982 (void) XSetFont(display,windows->widget.widget_context,
5985 XDrawBeveledButton(display,&windows->widget,&mode_info);
5986 windows->widget.font_info=save_info;
5987 if (font_info != (XFontStruct *) NULL)
5989 (void) XSetFont(display,windows->widget.widget_context,
5990 windows->widget.font_info->fid);
5991 (void) XFreeFont(display,font_info);
5993 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
5994 XDrawMatteText(display,&windows->widget,&reply_info);
5995 state&=(~RedrawActionState);
5998 Wait for next event.
6000 if (north_info.raised && south_info.raised)
6001 (void) XIfEvent(display,&event,XScreenEvent,(char *) windows);
6005 Brief delay before advancing scroll bar.
6007 XDelay(display,delay);
6009 (void) XCheckIfEvent(display,&event,XScreenEvent,(char *) windows);
6010 if (north_info.raised == MagickFalse)
6011 if (slider_info.id > 0)
6017 state|=RedrawListState;
6019 if (south_info.raised == MagickFalse)
6020 if (slider_info.id < fonts)
6026 state|=RedrawListState;
6028 if (event.type != ButtonRelease)
6035 if (MatteIsActive(slider_info,event.xbutton))
6040 slider_info.active=MagickTrue;
6043 if (MatteIsActive(north_info,event.xbutton))
6044 if (slider_info.id > 0)
6049 north_info.raised=MagickFalse;
6051 state|=RedrawListState;
6054 if (MatteIsActive(south_info,event.xbutton))
6055 if (slider_info.id < fonts)
6060 south_info.raised=MagickFalse;
6062 state|=RedrawListState;
6065 if (MatteIsActive(scroll_info,event.xbutton))
6070 if (event.xbutton.y < slider_info.y)
6071 slider_info.id-=(visible_fonts-1);
6073 slider_info.id+=(visible_fonts-1);
6074 state|=RedrawListState;
6077 if (MatteIsActive(list_info,event.xbutton))
6083 User pressed list matte.
6085 id=slider_info.id+(event.xbutton.y-(list_info.y+(height >> 1))+1)/
6086 selection_info.height;
6087 if (id >= (int) fonts)
6089 (void) CopyMagickString(reply_info.text,fontlist[id],MagickPathExtent);
6090 reply_info.highlight=MagickFalse;
6091 reply_info.marker=reply_info.text;
6092 reply_info.cursor=reply_info.text+Extent(reply_info.text);
6093 XDrawMatteText(display,&windows->widget,&reply_info);
6094 state|=RedrawActionState;
6095 if (id == list_info.id)
6097 (void) CopyMagickString(glob_pattern,reply_info.text,
6099 state|=UpdateListState;
6101 selection_info.id=(~0);
6103 state|=RedrawListState;
6106 if (MatteIsActive(back_info,event.xbutton))
6109 User pressed Back button.
6111 back_info.raised=MagickFalse;
6112 XDrawBeveledButton(display,&windows->widget,&back_info);
6115 if (MatteIsActive(reset_info,event.xbutton))
6118 User pressed Reset button.
6120 reset_info.raised=MagickFalse;
6121 XDrawBeveledButton(display,&windows->widget,&reset_info);
6124 if (MatteIsActive(action_info,event.xbutton))
6127 User pressed action button.
6129 action_info.raised=MagickFalse;
6130 XDrawBeveledButton(display,&windows->widget,&action_info);
6133 if (MatteIsActive(cancel_info,event.xbutton))
6136 User pressed Cancel button.
6138 cancel_info.raised=MagickFalse;
6139 XDrawBeveledButton(display,&windows->widget,&cancel_info);
6142 if (MatteIsActive(reply_info,event.xbutton) == MagickFalse)
6144 if (event.xbutton.button != Button2)
6150 Move text cursor to position of button press.
6152 x=event.xbutton.x-reply_info.x-(QuantumMargin >> 2);
6153 for (i=1; i <= Extent(reply_info.marker); i++)
6154 if (XTextWidth(font_info,reply_info.marker,i) > x)
6156 reply_info.cursor=reply_info.marker+i-1;
6157 if (event.xbutton.time > (click_time+DoubleClick))
6158 reply_info.highlight=MagickFalse;
6162 Become the XA_PRIMARY selection owner.
6164 (void) CopyMagickString(primary_selection,reply_info.text,
6166 (void) XSetSelectionOwner(display,XA_PRIMARY,windows->widget.id,
6167 event.xbutton.time);
6168 reply_info.highlight=XGetSelectionOwner(display,XA_PRIMARY) ==
6169 windows->widget.id ? MagickTrue : MagickFalse;
6171 XDrawMatteText(display,&windows->widget,&reply_info);
6172 click_time=event.xbutton.time;
6176 Request primary selection.
6178 (void) XConvertSelection(display,XA_PRIMARY,XA_STRING,XA_STRING,
6179 windows->widget.id,event.xbutton.time);
6184 if (windows->widget.mapped == MagickFalse)
6186 if (north_info.raised == MagickFalse)
6189 User released up button.
6191 delay=SuspendTime << 2;
6192 north_info.raised=MagickTrue;
6193 XDrawTriangleNorth(display,&windows->widget,&north_info);
6195 if (south_info.raised == MagickFalse)
6198 User released down button.
6200 delay=SuspendTime << 2;
6201 south_info.raised=MagickTrue;
6202 XDrawTriangleSouth(display,&windows->widget,&south_info);
6204 if (slider_info.active)
6207 Stop tracking slider.
6209 slider_info.active=MagickFalse;
6212 if (back_info.raised == MagickFalse)
6214 if (event.xbutton.window == windows->widget.id)
6215 if (MatteIsActive(back_info,event.xbutton))
6217 (void) CopyMagickString(glob_pattern,back_pattern,
6219 state|=UpdateListState;
6221 back_info.raised=MagickTrue;
6222 XDrawBeveledButton(display,&windows->widget,&back_info);
6224 if (reset_info.raised == MagickFalse)
6226 if (event.xbutton.window == windows->widget.id)
6227 if (MatteIsActive(reset_info,event.xbutton))
6229 (void) CopyMagickString(back_pattern,glob_pattern,MagickPathExtent);
6230 (void) CopyMagickString(glob_pattern,reset_pattern,MagickPathExtent);
6231 state|=UpdateListState;
6233 reset_info.raised=MagickTrue;
6234 XDrawBeveledButton(display,&windows->widget,&reset_info);
6236 if (action_info.raised == MagickFalse)
6238 if (event.xbutton.window == windows->widget.id)
6240 if (MatteIsActive(action_info,event.xbutton))
6242 if (*reply_info.text == '\0')
6243 (void) XBell(display,0);
6248 action_info.raised=MagickTrue;
6249 XDrawBeveledButton(display,&windows->widget,&action_info);
6251 if (cancel_info.raised == MagickFalse)
6253 if (event.xbutton.window == windows->widget.id)
6254 if (MatteIsActive(cancel_info,event.xbutton))
6256 *reply_info.text='\0';
6259 cancel_info.raised=MagickTrue;
6260 XDrawBeveledButton(display,&windows->widget,&cancel_info);
6267 If client window delete message, exit.
6269 if (event.xclient.message_type != windows->wm_protocols)
6271 if (*event.xclient.data.l == (int) windows->wm_take_focus)
6273 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
6274 (Time) event.xclient.data.l[1]);
6277 if (*event.xclient.data.l != (int) windows->wm_delete_window)
6279 if (event.xclient.window == windows->widget.id)
6281 *reply_info.text='\0';
6287 case ConfigureNotify:
6290 Update widget configuration.
6292 if (event.xconfigure.window != windows->widget.id)
6294 if ((event.xconfigure.width == (int) windows->widget.width) &&
6295 (event.xconfigure.height == (int) windows->widget.height))
6297 windows->widget.width=(unsigned int)
6298 MagickMax(event.xconfigure.width,(int) windows->widget.min_width);
6299 windows->widget.height=(unsigned int)
6300 MagickMax(event.xconfigure.height,(int) windows->widget.min_height);
6301 state|=UpdateConfigurationState;
6306 if (event.xcrossing.window != windows->widget.id)
6308 state&=(~InactiveWidgetState);
6313 if (event.xexpose.window != windows->widget.id)
6315 if (event.xexpose.count != 0)
6317 state|=RedrawWidgetState;
6323 command[MagickPathExtent];
6332 Respond to a user key press.
6334 if (event.xkey.window != windows->widget.id)
6336 length=XLookupString((XKeyEvent *) &event.xkey,command,
6337 (int) sizeof(command),&key_symbol,(XComposeStatus *) NULL);
6338 *(command+length)='\0';
6339 if (AreaIsActive(scroll_info,event.xkey))
6344 switch ((int) key_symbol)
6367 slider_info.id-=visible_fonts;
6373 slider_info.id+=visible_fonts;
6379 slider_info.id=fonts;
6383 state|=RedrawListState;
6386 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
6389 Read new font or glob patterm.
6391 if (*reply_info.text == '\0')
6393 (void) CopyMagickString(back_pattern,glob_pattern,MagickPathExtent);
6394 (void) CopyMagickString(glob_pattern,reply_info.text,MagickPathExtent);
6395 state|=UpdateListState;
6398 if (key_symbol == XK_Control_L)
6400 state|=ControlState;
6403 if (state & ControlState)
6404 switch ((int) key_symbol)
6410 Erase the entire line of text.
6412 *reply_info.text='\0';
6413 reply_info.cursor=reply_info.text;
6414 reply_info.marker=reply_info.text;
6415 reply_info.highlight=MagickFalse;
6421 XEditText(display,&reply_info,key_symbol,command,state);
6422 XDrawMatteText(display,&windows->widget,&reply_info);
6423 state|=JumpListState;
6429 command[MagickPathExtent];
6435 Respond to a user key release.
6437 if (event.xkey.window != windows->widget.id)
6439 (void) XLookupString((XKeyEvent *) &event.xkey,command,
6440 (int) sizeof(command),&key_symbol,(XComposeStatus *) NULL);
6441 if (key_symbol == XK_Control_L)
6442 state&=(~ControlState);
6447 if (event.xcrossing.window != windows->widget.id)
6449 state|=InactiveWidgetState;
6461 Discard pending button motion events.
6463 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
6464 if (slider_info.active)
6469 slider_info.y=event.xmotion.y-
6470 ((slider_info.height+slider_info.bevel_width) >> 1)+1;
6471 if (slider_info.y < slider_info.min_y)
6472 slider_info.y=slider_info.min_y;
6473 if (slider_info.y > slider_info.max_y)
6474 slider_info.y=slider_info.max_y;
6476 if (slider_info.y != slider_info.min_y)
6477 slider_info.id=(fonts*(slider_info.y-slider_info.min_y+1))/
6478 (slider_info.max_y-slider_info.min_y+1);
6479 state|=RedrawListState;
6482 if (state & InactiveWidgetState)
6484 if (back_info.raised == MatteIsActive(back_info,event.xmotion))
6487 Back button status changed.
6489 back_info.raised=!back_info.raised;
6490 XDrawBeveledButton(display,&windows->widget,&back_info);
6493 if (reset_info.raised == MatteIsActive(reset_info,event.xmotion))
6496 Reset button status changed.
6498 reset_info.raised=!reset_info.raised;
6499 XDrawBeveledButton(display,&windows->widget,&reset_info);
6502 if (action_info.raised == MatteIsActive(action_info,event.xmotion))
6505 Action button status changed.
6507 action_info.raised=action_info.raised == MagickFalse ?
6508 MagickTrue : MagickFalse;
6509 XDrawBeveledButton(display,&windows->widget,&action_info);
6512 if (cancel_info.raised == MatteIsActive(cancel_info,event.xmotion))
6515 Cancel button status changed.
6517 cancel_info.raised=cancel_info.raised == MagickFalse ?
6518 MagickTrue : MagickFalse;
6519 XDrawBeveledButton(display,&windows->widget,&cancel_info);
6524 case SelectionClear:
6526 reply_info.highlight=MagickFalse;
6527 XDrawMatteText(display,&windows->widget,&reply_info);
6530 case SelectionNotify:
6546 Obtain response from primary selection.
6548 if (event.xselection.property == (Atom) None)
6550 status=XGetWindowProperty(display,event.xselection.requestor,
6551 event.xselection.property,0L,2047L,MagickTrue,XA_STRING,&type,
6552 &format,&length,&after,&data);
6553 if ((status != Success) || (type != XA_STRING) || (format == 32) ||
6556 if ((Extent(reply_info.text)+length) >= (MagickPathExtent-1))
6557 (void) XBell(display,0);
6561 Insert primary selection in reply text.
6563 *(data+length)='\0';
6564 XEditText(display,&reply_info,(KeySym) XK_Insert,(char *) data,
6566 XDrawMatteText(display,&windows->widget,&reply_info);
6567 state|=JumpListState;
6568 state|=RedrawActionState;
6570 (void) XFree((void *) data);
6573 case SelectionRequest:
6578 XSelectionRequestEvent
6582 Set XA_PRIMARY selection.
6584 request=(&(event.xselectionrequest));
6585 (void) XChangeProperty(request->display,request->requestor,
6586 request->property,request->target,8,PropModeReplace,
6587 (unsigned char *) primary_selection,Extent(primary_selection));
6588 notify.type=SelectionNotify;
6589 notify.display=request->display;
6590 notify.requestor=request->requestor;
6591 notify.selection=request->selection;
6592 notify.target=request->target;
6593 notify.time=request->time;
6594 if (request->property == None)
6595 notify.property=request->target;
6597 notify.property=request->property;
6598 (void) XSendEvent(request->display,request->requestor,False,0,
6599 (XEvent *) ¬ify);
6604 } while ((state & ExitState) == 0);
6605 XSetCursorState(display,windows,MagickFalse);
6606 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
6607 XCheckRefreshWindows(display,windows);
6611 (void) XFreeFontNames(listhead);
6612 fontlist=(char **) RelinquishMagickMemory(fontlist);
6616 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6620 % X I n f o W i d g e t %
6624 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6626 % XInfoWidget() displays text in the Info widget. The purpose is to inform
6627 % the user that what activity is currently being performed (e.g. reading
6628 % an image, rotating an image, etc.).
6630 % The format of the XInfoWidget method is:
6632 % void XInfoWidget(Display *display,XWindows *windows,const char *activity)
6634 % A description of each parameter follows:
6636 % o display: Specifies a connection to an X server; returned from
6639 % o window: Specifies a pointer to a XWindows structure.
6641 % o activity: This character string reflects the current activity and is
6642 % displayed in the Info widget.
6645 MagickPrivate void XInfoWidget(Display *display,XWindows *windows,
6646 const char *activity)
6662 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
6663 assert(display != (Display *) NULL);
6664 assert(windows != (XWindows *) NULL);
6665 assert(activity != (char *) NULL);
6666 font_info=windows->info.font_info;
6667 width=WidgetTextWidth(font_info,(char *) activity)+((3*QuantumMargin) >> 1)+4;
6668 height=(unsigned int) (((6*(font_info->ascent+font_info->descent)) >> 2)+4);
6669 if ((windows->info.width != width) || (windows->info.height != height))
6672 Size Info widget to accommodate the activity text.
6674 windows->info.width=width;
6675 windows->info.height=height;
6676 window_changes.width=(int) width;
6677 window_changes.height=(int) height;
6678 (void) XReconfigureWMWindow(display,windows->info.id,windows->info.screen,
6679 (unsigned int) (CWWidth | CWHeight),&window_changes);
6681 if (windows->info.mapped == MagickFalse)
6683 (void) XMapRaised(display,windows->info.id);
6684 windows->info.mapped=MagickTrue;
6687 Initialize Info matte information.
6689 height=(unsigned int) (font_info->ascent+font_info->descent);
6690 XGetWidgetInfo(activity,&monitor_info);
6691 monitor_info.bevel_width--;
6692 margin=monitor_info.bevel_width+((windows->info.height-height) >> 1)-2;
6693 monitor_info.center=MagickFalse;
6694 monitor_info.x=(int) margin;
6695 monitor_info.y=(int) margin;
6696 monitor_info.width=windows->info.width-(margin << 1);
6697 monitor_info.height=windows->info.height-(margin << 1)+1;
6701 monitor_info.raised=MagickFalse;
6702 XDrawBeveledMatte(display,&windows->info,&monitor_info);
6703 monitor_info.raised=MagickTrue;
6704 XDrawWidgetText(display,&windows->info,&monitor_info);
6708 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6712 % X L i s t B r o w s e r W i d g e t %
6716 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6718 % XListBrowserWidget() displays a List Browser widget with a query to the
6719 % user. The user keys a reply or select a reply from the list. Finally, the
6720 % user presses the Action or Cancel button to exit. The typed text is
6721 % returned as the reply function parameter.
6723 % The format of the XListBrowserWidget method is:
6725 % void XListBrowserWidget(Display *display,XWindows *windows,
6726 % XWindowInfo *window_info,const char **list,const char *action,
6727 % const char *query,char *reply)
6729 % A description of each parameter follows:
6731 % o display: Specifies a connection to an X server; returned from
6734 % o window: Specifies a pointer to a XWindows structure.
6736 % o list: Specifies a pointer to an array of strings. The user can
6737 % select from these strings as a possible reply value.
6739 % o action: Specifies a pointer to the action of this widget.
6741 % o query: Specifies a pointer to the query to present to the user.
6743 % o reply: the response from the user is returned in this parameter.
6746 MagickPrivate void XListBrowserWidget(Display *display,XWindows *windows,
6747 XWindowInfo *window_info,const char **list,const char *action,
6748 const char *query,char *reply)
6750 #define CancelButtonText "Cancel"
6753 primary_selection[MagickPathExtent];
6761 static MagickStatusType
6762 mask = (MagickStatusType) (CWWidth | CWHeight | CWX | CWY);
6804 Count the number of entries in the list.
6806 assert(display != (Display *) NULL);
6807 assert(windows != (XWindows *) NULL);
6808 assert(window_info != (XWindowInfo *) NULL);
6809 assert(list != (const char **) NULL);
6810 assert(action != (char *) NULL);
6811 assert(query != (char *) NULL);
6812 assert(reply != (char *) NULL);
6813 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",action);
6814 XSetCursorState(display,windows,MagickTrue);
6815 XCheckRefreshWindows(display,windows);
6816 if (list == (const char **) NULL)
6818 XNoticeWidget(display,windows,"No text to browse:",(char *) NULL);
6821 for (entries=0; ; entries++)
6822 if (list[entries] == (char *) NULL)
6825 Determine Font Browser widget attributes.
6827 font_info=window_info->font_info;
6828 text_width=WidgetTextWidth(font_info,(char *) query);
6829 for (i=0; i < (int) entries; i++)
6830 if (WidgetTextWidth(font_info,(char *) list[i]) > text_width)
6831 text_width=WidgetTextWidth(font_info,(char *) list[i]);
6832 width=WidgetTextWidth(font_info,(char *) action);
6833 if (WidgetTextWidth(font_info,CancelButtonText) > width)
6834 width=WidgetTextWidth(font_info,CancelButtonText);
6835 width+=QuantumMargin;
6836 height=(unsigned int) (font_info->ascent+font_info->descent);
6838 Position List Browser widget.
6840 window_info->width=(unsigned int) MagickMin((int) text_width,(int)
6841 MaxTextWidth)+((9*QuantumMargin) >> 1);
6842 window_info->min_width=(unsigned int) (MinTextWidth+4*QuantumMargin);
6843 if (window_info->width < window_info->min_width)
6844 window_info->width=window_info->min_width;
6845 window_info->height=(unsigned int)
6846 (((81*height) >> 2)+((13*QuantumMargin) >> 1)+4);
6847 window_info->min_height=(unsigned int)
6848 (((23*height) >> 1)+((13*QuantumMargin) >> 1)+4);
6849 if (window_info->height < window_info->min_height)
6850 window_info->height=window_info->min_height;
6851 XConstrainWindowPosition(display,window_info);
6853 Map List Browser widget.
6855 (void) CopyMagickString(window_info->name,"Browse",MagickPathExtent);
6856 status=XStringListToTextProperty(&window_info->name,1,&window_name);
6857 if (status != False)
6859 XSetWMName(display,window_info->id,&window_name);
6860 XSetWMIconName(display,windows->widget.id,&window_name);
6861 (void) XFree((void *) window_name.value);
6863 window_changes.width=(int) window_info->width;
6864 window_changes.height=(int) window_info->height;
6865 window_changes.x=window_info->x;
6866 window_changes.y=window_info->y;
6867 (void) XReconfigureWMWindow(display,window_info->id,window_info->screen,mask,
6869 (void) XMapRaised(display,window_info->id);
6870 window_info->mapped=MagickFalse;
6872 Respond to X events.
6874 XGetWidgetInfo((char *) NULL,&slider_info);
6875 XGetWidgetInfo((char *) NULL,&north_info);
6876 XGetWidgetInfo((char *) NULL,&south_info);
6877 XGetWidgetInfo((char *) NULL,&expose_info);
6878 XGetWidgetInfo((char *) NULL,&selection_info);
6880 delay=SuspendTime << 2;
6881 state=UpdateConfigurationState;
6884 if (state & UpdateConfigurationState)
6890 Initialize button information.
6892 XGetWidgetInfo(CancelButtonText,&cancel_info);
6893 cancel_info.width=width;
6894 cancel_info.height=(unsigned int) ((3*height) >> 1);
6896 (window_info->width-cancel_info.width-QuantumMargin-2);
6898 (window_info->height-cancel_info.height-QuantumMargin);
6899 XGetWidgetInfo(action,&action_info);
6900 action_info.width=width;
6901 action_info.height=(unsigned int) ((3*height) >> 1);
6902 action_info.x=cancel_info.x-(cancel_info.width+(QuantumMargin >> 1)+
6903 (action_info.bevel_width << 1));
6904 action_info.y=cancel_info.y;
6906 Initialize reply information.
6908 XGetWidgetInfo(reply,&reply_info);
6909 reply_info.raised=MagickFalse;
6910 reply_info.bevel_width--;
6911 reply_info.width=window_info->width-((4*QuantumMargin) >> 1);
6912 reply_info.height=height << 1;
6913 reply_info.x=QuantumMargin;
6914 reply_info.y=action_info.y-reply_info.height-QuantumMargin;
6916 Initialize scroll information.
6918 XGetWidgetInfo((char *) NULL,&scroll_info);
6919 scroll_info.bevel_width--;
6920 scroll_info.width=height;
6921 scroll_info.height=(unsigned int)
6922 (reply_info.y-((6*QuantumMargin) >> 1)-height);
6923 scroll_info.x=reply_info.x+(reply_info.width-scroll_info.width);
6924 scroll_info.y=((5*QuantumMargin) >> 1)+height-reply_info.bevel_width;
6925 scroll_info.raised=MagickFalse;
6926 scroll_info.trough=MagickTrue;
6927 north_info=scroll_info;
6928 north_info.raised=MagickTrue;
6929 north_info.width-=(north_info.bevel_width << 1);
6930 north_info.height=north_info.width-1;
6931 north_info.x+=north_info.bevel_width;
6932 north_info.y+=north_info.bevel_width;
6933 south_info=north_info;
6934 south_info.y=scroll_info.y+scroll_info.height-scroll_info.bevel_width-
6937 slider_info=north_info;
6939 slider_info.width-=2;
6940 slider_info.min_y=north_info.y+north_info.height+north_info.bevel_width+
6941 slider_info.bevel_width+2;
6942 slider_info.height=scroll_info.height-((slider_info.min_y-
6943 scroll_info.y+1) << 1)+4;
6944 visible_entries=scroll_info.height/(height+(height >> 3));
6945 if (entries > visible_entries)
6946 slider_info.height=(visible_entries*slider_info.height)/entries;
6947 slider_info.max_y=south_info.y-south_info.bevel_width-
6948 slider_info.bevel_width-2;
6949 slider_info.x=scroll_info.x+slider_info.bevel_width+1;
6950 slider_info.y=slider_info.min_y;
6951 expose_info=scroll_info;
6952 expose_info.y=slider_info.y;
6954 Initialize list information.
6956 XGetWidgetInfo((char *) NULL,&list_info);
6957 list_info.raised=MagickFalse;
6958 list_info.bevel_width--;
6959 list_info.width=(unsigned int)
6960 (scroll_info.x-reply_info.x-(QuantumMargin >> 1));
6961 list_info.height=scroll_info.height;
6962 list_info.x=reply_info.x;
6963 list_info.y=scroll_info.y;
6964 if (window_info->mapped == MagickFalse)
6965 for (i=0; i < (int) entries; i++)
6966 if (LocaleCompare(list[i],reply) == 0)
6969 slider_info.id=i-(visible_entries >> 1);
6970 if (slider_info.id < 0)
6974 Initialize text information.
6976 XGetWidgetInfo(query,&text_info);
6977 text_info.width=reply_info.width;
6978 text_info.height=height;
6979 text_info.x=list_info.x-(QuantumMargin >> 1);
6980 text_info.y=QuantumMargin;
6982 Initialize selection information.
6984 XGetWidgetInfo((char *) NULL,&selection_info);
6985 selection_info.center=MagickFalse;
6986 selection_info.width=list_info.width;
6987 selection_info.height=(unsigned int) ((9*height) >> 3);
6988 selection_info.x=list_info.x;
6989 state&=(~UpdateConfigurationState);
6991 if (state & RedrawWidgetState)
6994 Redraw List Browser window.
6996 XDrawWidgetText(display,window_info,&text_info);
6997 XDrawBeveledMatte(display,window_info,&list_info);
6998 XDrawBeveledMatte(display,window_info,&scroll_info);
6999 XDrawTriangleNorth(display,window_info,&north_info);
7000 XDrawBeveledButton(display,window_info,&slider_info);
7001 XDrawTriangleSouth(display,window_info,&south_info);
7002 XDrawBeveledMatte(display,window_info,&reply_info);
7003 XDrawMatteText(display,window_info,&reply_info);
7004 XDrawBeveledButton(display,window_info,&action_info);
7005 XDrawBeveledButton(display,window_info,&cancel_info);
7006 XHighlightWidget(display,window_info,BorderOffset,BorderOffset);
7007 selection_info.id=(~0);
7008 state|=RedrawActionState;
7009 state|=RedrawListState;
7010 state&=(~RedrawWidgetState);
7012 if (state & RedrawListState)
7015 Determine slider id and position.
7017 if (slider_info.id >= (int) (entries-visible_entries))
7018 slider_info.id=(int) (entries-visible_entries);
7019 if ((slider_info.id < 0) || (entries <= visible_entries))
7021 slider_info.y=slider_info.min_y;
7024 slider_info.id*(slider_info.max_y-slider_info.min_y+1)/entries;
7025 if (slider_info.id != selection_info.id)
7028 Redraw scroll bar and file names.
7030 selection_info.id=slider_info.id;
7031 selection_info.y=list_info.y+(height >> 3)+2;
7032 for (i=0; i < (int) visible_entries; i++)
7034 selection_info.raised=(slider_info.id+i) != list_info.id ?
7035 MagickTrue : MagickFalse;
7036 selection_info.text=(char *) NULL;
7037 if ((slider_info.id+i) < (int) entries)
7038 selection_info.text=(char *) list[slider_info.id+i];
7039 XDrawWidgetText(display,window_info,&selection_info);
7040 selection_info.y+=(int) selection_info.height;
7045 if (slider_info.y > expose_info.y)
7047 expose_info.height=(unsigned int) slider_info.y-expose_info.y;
7048 expose_info.y=slider_info.y-expose_info.height-
7049 slider_info.bevel_width-1;
7053 expose_info.height=(unsigned int) expose_info.y-slider_info.y;
7054 expose_info.y=slider_info.y+slider_info.height+
7055 slider_info.bevel_width+1;
7057 XDrawTriangleNorth(display,window_info,&north_info);
7058 XDrawMatte(display,window_info,&expose_info);
7059 XDrawBeveledButton(display,window_info,&slider_info);
7060 XDrawTriangleSouth(display,window_info,&south_info);
7061 expose_info.y=slider_info.y;
7063 state&=(~RedrawListState);
7066 Wait for next event.
7068 if (north_info.raised && south_info.raised)
7069 (void) XIfEvent(display,&event,XScreenEvent,(char *) windows);
7073 Brief delay before advancing scroll bar.
7075 XDelay(display,delay);
7077 (void) XCheckIfEvent(display,&event,XScreenEvent,(char *) windows);
7078 if (north_info.raised == MagickFalse)
7079 if (slider_info.id > 0)
7085 state|=RedrawListState;
7087 if (south_info.raised == MagickFalse)
7088 if (slider_info.id < (int) entries)
7094 state|=RedrawListState;
7096 if (event.type != ButtonRelease)
7103 if (MatteIsActive(slider_info,event.xbutton))
7108 slider_info.active=MagickTrue;
7111 if (MatteIsActive(north_info,event.xbutton))
7112 if (slider_info.id > 0)
7117 north_info.raised=MagickFalse;
7119 state|=RedrawListState;
7122 if (MatteIsActive(south_info,event.xbutton))
7123 if (slider_info.id < (int) entries)
7128 south_info.raised=MagickFalse;
7130 state|=RedrawListState;
7133 if (MatteIsActive(scroll_info,event.xbutton))
7138 if (event.xbutton.y < slider_info.y)
7139 slider_info.id-=(visible_entries-1);
7141 slider_info.id+=(visible_entries-1);
7142 state|=RedrawListState;
7145 if (MatteIsActive(list_info,event.xbutton))
7151 User pressed list matte.
7153 id=slider_info.id+(event.xbutton.y-(list_info.y+(height >> 1))+1)/
7154 selection_info.height;
7155 if (id >= (int) entries)
7157 (void) CopyMagickString(reply_info.text,list[id],MagickPathExtent);
7158 reply_info.highlight=MagickFalse;
7159 reply_info.marker=reply_info.text;
7160 reply_info.cursor=reply_info.text+Extent(reply_info.text);
7161 XDrawMatteText(display,window_info,&reply_info);
7162 selection_info.id=(~0);
7163 if (id == list_info.id)
7165 action_info.raised=MagickFalse;
7166 XDrawBeveledButton(display,window_info,&action_info);
7170 state|=RedrawListState;
7173 if (MatteIsActive(action_info,event.xbutton))
7176 User pressed action button.
7178 action_info.raised=MagickFalse;
7179 XDrawBeveledButton(display,window_info,&action_info);
7182 if (MatteIsActive(cancel_info,event.xbutton))
7185 User pressed Cancel button.
7187 cancel_info.raised=MagickFalse;
7188 XDrawBeveledButton(display,window_info,&cancel_info);
7191 if (MatteIsActive(reply_info,event.xbutton) == MagickFalse)
7193 if (event.xbutton.button != Button2)
7199 Move text cursor to position of button press.
7201 x=event.xbutton.x-reply_info.x-(QuantumMargin >> 2);
7202 for (i=1; i <= Extent(reply_info.marker); i++)
7203 if (XTextWidth(font_info,reply_info.marker,i) > x)
7205 reply_info.cursor=reply_info.marker+i-1;
7206 if (event.xbutton.time > (click_time+DoubleClick))
7207 reply_info.highlight=MagickFalse;
7211 Become the XA_PRIMARY selection owner.
7213 (void) CopyMagickString(primary_selection,reply_info.text,
7215 (void) XSetSelectionOwner(display,XA_PRIMARY,window_info->id,
7216 event.xbutton.time);
7217 reply_info.highlight=XGetSelectionOwner(display,XA_PRIMARY) ==
7218 window_info->id ? MagickTrue : MagickFalse;
7220 XDrawMatteText(display,window_info,&reply_info);
7221 click_time=event.xbutton.time;
7225 Request primary selection.
7227 (void) XConvertSelection(display,XA_PRIMARY,XA_STRING,XA_STRING,
7228 window_info->id,event.xbutton.time);
7233 if (window_info->mapped == MagickFalse)
7235 if (north_info.raised == MagickFalse)
7238 User released up button.
7240 delay=SuspendTime << 2;
7241 north_info.raised=MagickTrue;
7242 XDrawTriangleNorth(display,window_info,&north_info);
7244 if (south_info.raised == MagickFalse)
7247 User released down button.
7249 delay=SuspendTime << 2;
7250 south_info.raised=MagickTrue;
7251 XDrawTriangleSouth(display,window_info,&south_info);
7253 if (slider_info.active)
7256 Stop tracking slider.
7258 slider_info.active=MagickFalse;
7261 if (action_info.raised == MagickFalse)
7263 if (event.xbutton.window == window_info->id)
7265 if (MatteIsActive(action_info,event.xbutton))
7267 if (*reply_info.text == '\0')
7268 (void) XBell(display,0);
7273 action_info.raised=MagickTrue;
7274 XDrawBeveledButton(display,window_info,&action_info);
7276 if (cancel_info.raised == MagickFalse)
7278 if (event.xbutton.window == window_info->id)
7279 if (MatteIsActive(cancel_info,event.xbutton))
7281 *reply_info.text='\0';
7284 cancel_info.raised=MagickTrue;
7285 XDrawBeveledButton(display,window_info,&cancel_info);
7287 if (MatteIsActive(reply_info,event.xbutton) == MagickFalse)
7294 If client window delete message, exit.
7296 if (event.xclient.message_type != windows->wm_protocols)
7298 if (*event.xclient.data.l == (int) windows->wm_take_focus)
7300 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
7301 (Time) event.xclient.data.l[1]);
7304 if (*event.xclient.data.l != (int) windows->wm_delete_window)
7306 if (event.xclient.window == window_info->id)
7308 *reply_info.text='\0';
7314 case ConfigureNotify:
7317 Update widget configuration.
7319 if (event.xconfigure.window != window_info->id)
7321 if ((event.xconfigure.width == (int) window_info->width) &&
7322 (event.xconfigure.height == (int) window_info->height))
7324 window_info->width=(unsigned int)
7325 MagickMax(event.xconfigure.width,(int) window_info->min_width);
7326 window_info->height=(unsigned int)
7327 MagickMax(event.xconfigure.height,(int) window_info->min_height);
7328 state|=UpdateConfigurationState;
7333 if (event.xcrossing.window != window_info->id)
7335 state&=(~InactiveWidgetState);
7340 if (event.xexpose.window != window_info->id)
7342 if (event.xexpose.count != 0)
7344 state|=RedrawWidgetState;
7350 command[MagickPathExtent];
7359 Respond to a user key press.
7361 if (event.xkey.window != window_info->id)
7363 length=XLookupString((XKeyEvent *) &event.xkey,command,
7364 (int) sizeof(command),&key_symbol,(XComposeStatus *) NULL);
7365 *(command+length)='\0';
7366 if (AreaIsActive(scroll_info,event.xkey))
7371 switch ((int) key_symbol)
7394 slider_info.id-=visible_entries;
7400 slider_info.id+=visible_entries;
7406 slider_info.id=(int) entries;
7410 state|=RedrawListState;
7413 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
7418 if (*reply_info.text == '\0')
7420 action_info.raised=MagickFalse;
7421 XDrawBeveledButton(display,window_info,&action_info);
7425 if (key_symbol == XK_Control_L)
7427 state|=ControlState;
7430 if (state & ControlState)
7431 switch ((int) key_symbol)
7437 Erase the entire line of text.
7439 *reply_info.text='\0';
7440 reply_info.cursor=reply_info.text;
7441 reply_info.marker=reply_info.text;
7442 reply_info.highlight=MagickFalse;
7448 XEditText(display,&reply_info,key_symbol,command,state);
7449 XDrawMatteText(display,window_info,&reply_info);
7455 command[MagickPathExtent];
7461 Respond to a user key release.
7463 if (event.xkey.window != window_info->id)
7465 (void) XLookupString((XKeyEvent *) &event.xkey,command,
7466 (int) sizeof(command),&key_symbol,(XComposeStatus *) NULL);
7467 if (key_symbol == XK_Control_L)
7468 state&=(~ControlState);
7473 if (event.xcrossing.window != window_info->id)
7475 state|=InactiveWidgetState;
7487 Discard pending button motion events.
7489 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
7490 if (slider_info.active)
7495 slider_info.y=event.xmotion.y-
7496 ((slider_info.height+slider_info.bevel_width) >> 1)+1;
7497 if (slider_info.y < slider_info.min_y)
7498 slider_info.y=slider_info.min_y;
7499 if (slider_info.y > slider_info.max_y)
7500 slider_info.y=slider_info.max_y;
7502 if (slider_info.y != slider_info.min_y)
7503 slider_info.id=(int) ((entries*(slider_info.y-
7504 slider_info.min_y+1))/(slider_info.max_y-slider_info.min_y+1));
7505 state|=RedrawListState;
7508 if (state & InactiveWidgetState)
7510 if (action_info.raised == MatteIsActive(action_info,event.xmotion))
7513 Action button status changed.
7515 action_info.raised=action_info.raised == MagickFalse ?
7516 MagickTrue : MagickFalse;
7517 XDrawBeveledButton(display,window_info,&action_info);
7520 if (cancel_info.raised == MatteIsActive(cancel_info,event.xmotion))
7523 Cancel button status changed.
7525 cancel_info.raised=cancel_info.raised == MagickFalse ?
7526 MagickTrue : MagickFalse;
7527 XDrawBeveledButton(display,window_info,&cancel_info);
7532 case SelectionClear:
7534 reply_info.highlight=MagickFalse;
7535 XDrawMatteText(display,window_info,&reply_info);
7538 case SelectionNotify:
7554 Obtain response from primary selection.
7556 if (event.xselection.property == (Atom) None)
7558 status=XGetWindowProperty(display,
7559 event.xselection.requestor,event.xselection.property,0L,2047L,
7560 MagickTrue,XA_STRING,&type,&format,&length,&after,&data);
7561 if ((status != Success) || (type != XA_STRING) || (format == 32) ||
7564 if ((Extent(reply_info.text)+length) >= (MagickPathExtent-1))
7565 (void) XBell(display,0);
7569 Insert primary selection in reply text.
7571 *(data+length)='\0';
7572 XEditText(display,&reply_info,(KeySym) XK_Insert,(char *) data,
7574 XDrawMatteText(display,window_info,&reply_info);
7575 state|=RedrawActionState;
7577 (void) XFree((void *) data);
7580 case SelectionRequest:
7585 XSelectionRequestEvent
7588 if (reply_info.highlight == MagickFalse)
7591 Set primary selection.
7593 request=(&(event.xselectionrequest));
7594 (void) XChangeProperty(request->display,request->requestor,
7595 request->property,request->target,8,PropModeReplace,
7596 (unsigned char *) primary_selection,Extent(primary_selection));
7597 notify.type=SelectionNotify;
7598 notify.send_event=MagickTrue;
7599 notify.display=request->display;
7600 notify.requestor=request->requestor;
7601 notify.selection=request->selection;
7602 notify.target=request->target;
7603 notify.time=request->time;
7604 if (request->property == None)
7605 notify.property=request->target;
7607 notify.property=request->property;
7608 (void) XSendEvent(request->display,request->requestor,False,NoEventMask,
7609 (XEvent *) ¬ify);
7614 } while ((state & ExitState) == 0);
7615 XSetCursorState(display,windows,MagickFalse);
7616 (void) XWithdrawWindow(display,window_info->id,window_info->screen);
7617 XCheckRefreshWindows(display,windows);
7621 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7625 % X M e n u W i d g e t %
7629 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7631 % XMenuWidget() maps a menu and returns the command pointed to by the user
7632 % when the button is released.
7634 % The format of the XMenuWidget method is:
7636 % int XMenuWidget(Display *display,XWindows *windows,const char *title,
7637 % const char **selections,char *item)
7639 % A description of each parameter follows:
7641 % o selection_number: Specifies the number of the selection that the
7644 % o display: Specifies a connection to an X server; returned from
7647 % o window: Specifies a pointer to a XWindows structure.
7649 % o title: Specifies a character string that describes the menu selections.
7651 % o selections: Specifies a pointer to one or more strings that comprise
7652 % the choices in the menu.
7654 % o item: Specifies a character array. The item selected from the menu
7658 MagickPrivate int XMenuWidget(Display *display,XWindows *windows,
7659 const char *title,const char **selections,char *item)
7685 XSetWindowAttributes
7697 Determine Menu widget attributes.
7699 assert(display != (Display *) NULL);
7700 assert(windows != (XWindows *) NULL);
7701 assert(title != (char *) NULL);
7702 assert(selections != (const char **) NULL);
7703 assert(item != (char *) NULL);
7704 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",title);
7705 font_info=windows->widget.font_info;
7706 windows->widget.width=submenu_info.active == 0 ?
7707 WidgetTextWidth(font_info,(char *) title) : 0;
7708 for (id=0; selections[id] != (char *) NULL; id++)
7710 width=WidgetTextWidth(font_info,(char *) selections[id]);
7711 if (width > windows->widget.width)
7712 windows->widget.width=width;
7714 number_selections=(unsigned int) id;
7715 XGetWidgetInfo((char *) NULL,&menu_info);
7716 title_height=(unsigned int) (submenu_info.active == 0 ?
7717 (3*(font_info->descent+font_info->ascent) >> 1)+5 : 2);
7718 width=WidgetTextWidth(font_info,(char *) title);
7719 height=(unsigned int) ((3*(font_info->ascent+font_info->descent)) >> 1);
7721 Position Menu widget.
7723 windows->widget.width+=QuantumMargin+(menu_info.bevel_width << 1);
7724 top_offset=title_height+menu_info.bevel_width-1;
7725 windows->widget.height=top_offset+number_selections*height+4;
7726 windows->widget.min_width=windows->widget.width;
7727 windows->widget.min_height=windows->widget.height;
7728 XQueryPosition(display,windows->widget.root,&x,&y);
7729 windows->widget.x=x-(QuantumMargin >> 1);
7730 if (submenu_info.active != 0)
7733 windows->command.x+windows->command.width-QuantumMargin;
7734 toggle_info.raised=MagickTrue;
7735 XDrawTriangleEast(display,&windows->command,&toggle_info);
7737 windows->widget.y=submenu_info.active == 0 ? y-(int)
7738 ((3*title_height) >> 2) : y;
7739 if (submenu_info.active != 0)
7740 windows->widget.y=windows->command.y+submenu_info.y;
7741 XConstrainWindowPosition(display,&windows->widget);
7745 window_attributes.override_redirect=MagickTrue;
7746 (void) XChangeWindowAttributes(display,windows->widget.id,
7747 (size_t) CWOverrideRedirect,&window_attributes);
7748 window_changes.width=(int) windows->widget.width;
7749 window_changes.height=(int) windows->widget.height;
7750 window_changes.x=windows->widget.x;
7751 window_changes.y=windows->widget.y;
7752 (void) XReconfigureWMWindow(display,windows->widget.id,windows->widget.screen,
7753 (unsigned int) (CWWidth | CWHeight | CWX | CWY),&window_changes);
7754 (void) XMapRaised(display,windows->widget.id);
7755 windows->widget.mapped=MagickFalse;
7757 Respond to X events.
7759 selection_info.height=height;
7760 cursor=XCreateFontCursor(display,XC_right_ptr);
7761 (void) XCheckDefineCursor(display,windows->image.id,cursor);
7762 (void) XCheckDefineCursor(display,windows->command.id,cursor);
7763 (void) XCheckDefineCursor(display,windows->widget.id,cursor);
7764 state=UpdateConfigurationState;
7767 if (state & UpdateConfigurationState)
7770 Initialize selection information.
7772 XGetWidgetInfo((char *) NULL,&menu_info);
7773 menu_info.bevel_width--;
7774 menu_info.width=windows->widget.width-((menu_info.bevel_width) << 1);
7775 menu_info.height=windows->widget.height-((menu_info.bevel_width) << 1);
7776 menu_info.x=(int) menu_info.bevel_width;
7777 menu_info.y=(int) menu_info.bevel_width;
7778 XGetWidgetInfo((char *) NULL,&selection_info);
7779 selection_info.center=MagickFalse;
7780 selection_info.width=menu_info.width;
7781 selection_info.height=height;
7782 selection_info.x=menu_info.x;
7783 highlight_info=selection_info;
7784 highlight_info.bevel_width--;
7785 highlight_info.width-=(highlight_info.bevel_width << 1);
7786 highlight_info.height-=(highlight_info.bevel_width << 1);
7787 highlight_info.x+=highlight_info.bevel_width;
7788 state&=(~UpdateConfigurationState);
7790 if (state & RedrawWidgetState)
7795 if (submenu_info.active == 0)
7797 y=(int) title_height;
7798 XSetBevelColor(display,&windows->widget,MagickFalse);
7799 (void) XDrawLine(display,windows->widget.id,
7800 windows->widget.widget_context,selection_info.x,y-1,
7801 (int) selection_info.width,y-1);
7802 XSetBevelColor(display,&windows->widget,MagickTrue);
7803 (void) XDrawLine(display,windows->widget.id,
7804 windows->widget.widget_context,selection_info.x,y,
7805 (int) selection_info.width,y);
7806 (void) XSetFillStyle(display,windows->widget.widget_context,
7810 Draw menu selections.
7812 selection_info.center=MagickTrue;
7813 selection_info.y=(int) menu_info.bevel_width;
7814 selection_info.text=(char *) title;
7815 if (submenu_info.active == 0)
7816 XDrawWidgetText(display,&windows->widget,&selection_info);
7817 selection_info.center=MagickFalse;
7818 selection_info.y=(int) top_offset;
7819 for (id=0; id < (int) number_selections; id++)
7821 selection_info.text=(char *) selections[id];
7822 XDrawWidgetText(display,&windows->widget,&selection_info);
7823 highlight_info.y=selection_info.y+highlight_info.bevel_width;
7824 if (id == selection_info.id)
7825 XDrawBevel(display,&windows->widget,&highlight_info);
7826 selection_info.y+=(int) selection_info.height;
7828 XDrawBevel(display,&windows->widget,&menu_info);
7829 state&=(~RedrawWidgetState);
7831 if (number_selections > 2)
7836 y=(int) (top_offset+selection_info.height*(number_selections-1));
7837 XSetBevelColor(display,&windows->widget,MagickFalse);
7838 (void) XDrawLine(display,windows->widget.id,
7839 windows->widget.widget_context,selection_info.x,y-1,
7840 (int) selection_info.width,y-1);
7841 XSetBevelColor(display,&windows->widget,MagickTrue);
7842 (void) XDrawLine(display,windows->widget.id,
7843 windows->widget.widget_context,selection_info.x,y,
7844 (int) selection_info.width,y);
7845 (void) XSetFillStyle(display,windows->widget.widget_context,FillSolid);
7848 Wait for next event.
7850 (void) XIfEvent(display,&event,XScreenEvent,(char *) windows);
7855 if (event.xbutton.window != windows->widget.id)
7860 if (event.xbutton.window == windows->command.id)
7861 (void) XPutBackEvent(display,&event);
7862 selection_info.id=(~0);
7867 state&=(~InactiveWidgetState);
7868 id=(event.xbutton.y-top_offset)/(int) selection_info.height;
7869 selection_info.id=id;
7870 if ((id < 0) || (id >= (int) number_selections))
7873 Highlight this selection.
7875 selection_info.y=(int) (top_offset+id*selection_info.height);
7876 selection_info.text=(char *) selections[id];
7877 XDrawWidgetText(display,&windows->widget,&selection_info);
7878 highlight_info.y=selection_info.y+highlight_info.bevel_width;
7879 XDrawBevel(display,&windows->widget,&highlight_info);
7884 if (windows->widget.mapped == MagickFalse)
7886 if (event.xbutton.window == windows->command.id)
7887 if ((state & InactiveWidgetState) == 0)
7892 XSetCursorState(display,windows,MagickFalse);
7897 case ConfigureNotify:
7900 Update widget configuration.
7902 if (event.xconfigure.window != windows->widget.id)
7904 if ((event.xconfigure.width == (int) windows->widget.width) &&
7905 (event.xconfigure.height == (int) windows->widget.height))
7907 windows->widget.width=(unsigned int)
7908 MagickMax(event.xconfigure.width,(int) windows->widget.min_width);
7909 windows->widget.height=(unsigned int)
7910 MagickMax(event.xconfigure.height,(int) windows->widget.min_height);
7911 state|=UpdateConfigurationState;
7916 if (event.xcrossing.window != windows->widget.id)
7918 if (event.xcrossing.state == 0)
7920 state&=(~InactiveWidgetState);
7921 id=((event.xcrossing.y-top_offset)/(int) selection_info.height);
7922 if ((selection_info.id >= 0) &&
7923 (selection_info.id < (int) number_selections))
7926 Unhighlight last selection.
7928 if (id == selection_info.id)
7930 selection_info.y=(int)
7931 (top_offset+selection_info.id*selection_info.height);
7932 selection_info.text=(char *) selections[selection_info.id];
7933 XDrawWidgetText(display,&windows->widget,&selection_info);
7935 if ((id < 0) || (id >= (int) number_selections))
7938 Highlight this selection.
7940 selection_info.id=id;
7941 selection_info.y=(int)
7942 (top_offset+selection_info.id*selection_info.height);
7943 selection_info.text=(char *) selections[selection_info.id];
7944 XDrawWidgetText(display,&windows->widget,&selection_info);
7945 highlight_info.y=selection_info.y+highlight_info.bevel_width;
7946 XDrawBevel(display,&windows->widget,&highlight_info);
7951 if (event.xexpose.window != windows->widget.id)
7953 if (event.xexpose.count != 0)
7955 state|=RedrawWidgetState;
7960 if (event.xcrossing.window != windows->widget.id)
7962 state|=InactiveWidgetState;
7963 id=selection_info.id;
7964 if ((id < 0) || (id >= (int) number_selections))
7967 Unhighlight last selection.
7969 selection_info.y=(int) (top_offset+id*selection_info.height);
7970 selection_info.id=(~0);
7971 selection_info.text=(char *) selections[id];
7972 XDrawWidgetText(display,&windows->widget,&selection_info);
7978 Discard pending button motion events.
7980 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
7981 if (submenu_info.active != 0)
7982 if (event.xmotion.window == windows->command.id)
7984 if ((state & InactiveWidgetState) == 0)
7986 if (MatteIsActive(submenu_info,event.xmotion) == MagickFalse)
7988 selection_info.id=(~0);
7995 if (WindowIsActive(windows->command,event.xmotion))
7997 selection_info.id=(~0);
8003 if (event.xmotion.window != windows->widget.id)
8005 if (state & InactiveWidgetState)
8007 id=(event.xmotion.y-top_offset)/(int) selection_info.height;
8008 if ((selection_info.id >= 0) &&
8009 (selection_info.id < (int) number_selections))
8012 Unhighlight last selection.
8014 if (id == selection_info.id)
8016 selection_info.y=(int)
8017 (top_offset+selection_info.id*selection_info.height);
8018 selection_info.text=(char *) selections[selection_info.id];
8019 XDrawWidgetText(display,&windows->widget,&selection_info);
8021 selection_info.id=id;
8022 if ((id < 0) || (id >= (int) number_selections))
8025 Highlight this selection.
8027 selection_info.y=(int) (top_offset+id*selection_info.height);
8028 selection_info.text=(char *) selections[id];
8029 XDrawWidgetText(display,&windows->widget,&selection_info);
8030 highlight_info.y=selection_info.y+highlight_info.bevel_width;
8031 XDrawBevel(display,&windows->widget,&highlight_info);
8037 } while ((state & ExitState) == 0);
8038 (void) XFreeCursor(display,cursor);
8039 window_attributes.override_redirect=MagickFalse;
8040 (void) XChangeWindowAttributes(display,windows->widget.id,
8041 (size_t) CWOverrideRedirect,&window_attributes);
8042 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
8043 XCheckRefreshWindows(display,windows);
8044 if (submenu_info.active != 0)
8046 submenu_info.active=MagickFalse;
8047 toggle_info.raised=MagickFalse;
8048 XDrawTriangleEast(display,&windows->command,&toggle_info);
8050 if ((selection_info.id < 0) || (selection_info.id >= (int) number_selections))
8052 (void) CopyMagickString(item,selections[selection_info.id],MagickPathExtent);
8053 return(selection_info.id);
8057 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8061 % X N o t i c e W i d g e t %
8065 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8067 % XNoticeWidget() displays a Notice widget with a notice to the user. The
8068 % function returns when the user presses the "Dismiss" button.
8070 % The format of the XNoticeWidget method is:
8072 % void XNoticeWidget(Display *display,XWindows *windows,
8073 % const char *reason,const char *description)
8075 % A description of each parameter follows:
8077 % o display: Specifies a connection to an X server; returned from
8080 % o window: Specifies a pointer to a XWindows structure.
8082 % o reason: Specifies the message to display before terminating the
8085 % o description: Specifies any description to the message.
8088 MagickPrivate void XNoticeWidget(Display *display,XWindows *windows,
8089 const char *reason,const char *description)
8091 #define DismissButtonText "Dismiss"
8130 Determine Notice widget attributes.
8132 assert(display != (Display *) NULL);
8133 assert(windows != (XWindows *) NULL);
8134 assert(reason != (char *) NULL);
8135 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",reason);
8136 XDelay(display,SuspendTime << 3); /* avoid surpise with delay */
8137 XSetCursorState(display,windows,MagickTrue);
8138 XCheckRefreshWindows(display,windows);
8139 font_info=windows->widget.font_info;
8140 width=WidgetTextWidth(font_info,DismissButtonText);
8141 text=GetLocaleExceptionMessage(XServerError,reason);
8142 if (text != (char *) NULL)
8143 if (WidgetTextWidth(font_info,(char *) text) > width)
8144 width=WidgetTextWidth(font_info,(char *) text);
8145 if (description != (char *) NULL)
8147 text=GetLocaleExceptionMessage(XServerError,description);
8148 if (text != (char *) NULL)
8149 if (WidgetTextWidth(font_info,(char *) text) > width)
8150 width=WidgetTextWidth(font_info,(char *) text);
8152 height=(unsigned int) (font_info->ascent+font_info->descent);
8154 Position Notice widget.
8156 windows->widget.width=width+4*QuantumMargin;
8157 windows->widget.min_width=width+QuantumMargin;
8158 if (windows->widget.width < windows->widget.min_width)
8159 windows->widget.width=windows->widget.min_width;
8160 windows->widget.height=(unsigned int) (12*height);
8161 windows->widget.min_height=(unsigned int) (7*height);
8162 if (windows->widget.height < windows->widget.min_height)
8163 windows->widget.height=windows->widget.min_height;
8164 XConstrainWindowPosition(display,&windows->widget);
8168 (void) CopyMagickString(windows->widget.name,"Notice",MagickPathExtent);
8169 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
8170 if (status != False)
8172 XSetWMName(display,windows->widget.id,&window_name);
8173 XSetWMIconName(display,windows->widget.id,&window_name);
8174 (void) XFree((void *) window_name.value);
8176 window_changes.width=(int) windows->widget.width;
8177 window_changes.height=(int) windows->widget.height;
8178 window_changes.x=windows->widget.x;
8179 window_changes.y=windows->widget.y;
8180 (void) XReconfigureWMWindow(display,windows->widget.id,windows->widget.screen,
8181 (unsigned int) (CWWidth | CWHeight | CWX | CWY),&window_changes);
8182 (void) XMapRaised(display,windows->widget.id);
8183 windows->widget.mapped=MagickFalse;
8184 (void) XBell(display,0);
8186 Respond to X events.
8188 timer=time((time_t *) NULL)+Timeout;
8189 state=UpdateConfigurationState;
8192 if (time((time_t *) NULL) > timer)
8194 if (state & UpdateConfigurationState)
8197 Initialize Dismiss button information.
8199 XGetWidgetInfo(DismissButtonText,&dismiss_info);
8200 dismiss_info.width=(unsigned int) QuantumMargin+
8201 WidgetTextWidth(font_info,DismissButtonText);
8202 dismiss_info.height=(unsigned int) ((3*height) >> 1);
8203 dismiss_info.x=(int)
8204 ((windows->widget.width >> 1)-(dismiss_info.width >> 1));
8205 dismiss_info.y=(int)
8206 (windows->widget.height-(dismiss_info.height << 1));
8207 state&=(~UpdateConfigurationState);
8209 if (state & RedrawWidgetState)
8212 Redraw Notice widget.
8214 width=WidgetTextWidth(font_info,(char *) reason);
8215 x=(int) ((windows->widget.width >> 1)-(width >> 1));
8216 y=(int) ((windows->widget.height >> 1)-(height << 1));
8217 (void) XDrawString(display,windows->widget.id,
8218 windows->widget.annotate_context,x,y,(char *) reason,Extent(reason));
8219 if (description != (char *) NULL)
8221 width=WidgetTextWidth(font_info,(char *) description);
8222 x=(int) ((windows->widget.width >> 1)-(width >> 1));
8224 (void) XDrawString(display,windows->widget.id,
8225 windows->widget.annotate_context,x,y,(char *) description,
8226 Extent(description));
8228 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
8229 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
8230 state&=(~RedrawWidgetState);
8233 Wait for next event.
8235 if (XCheckIfEvent(display,&event,XScreenEvent,(char *) windows) == MagickFalse)
8238 Do not block if delay > 0.
8240 XDelay(display,SuspendTime << 2);
8247 if (MatteIsActive(dismiss_info,event.xbutton))
8250 User pressed Dismiss button.
8252 dismiss_info.raised=MagickFalse;
8253 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
8260 if (windows->widget.mapped == MagickFalse)
8262 if (dismiss_info.raised == MagickFalse)
8264 if (event.xbutton.window == windows->widget.id)
8265 if (MatteIsActive(dismiss_info,event.xbutton))
8267 dismiss_info.raised=MagickTrue;
8268 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
8275 If client window delete message, exit.
8277 if (event.xclient.message_type != windows->wm_protocols)
8279 if (*event.xclient.data.l == (int) windows->wm_take_focus)
8281 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
8282 (Time) event.xclient.data.l[1]);
8285 if (*event.xclient.data.l != (int) windows->wm_delete_window)
8287 if (event.xclient.window == windows->widget.id)
8294 case ConfigureNotify:
8297 Update widget configuration.
8299 if (event.xconfigure.window != windows->widget.id)
8301 if ((event.xconfigure.width == (int) windows->widget.width) &&
8302 (event.xconfigure.height == (int) windows->widget.height))
8304 windows->widget.width=(unsigned int)
8305 MagickMax(event.xconfigure.width,(int) windows->widget.min_width);
8306 windows->widget.height=(unsigned int)
8307 MagickMax(event.xconfigure.height,(int) windows->widget.min_height);
8308 state|=UpdateConfigurationState;
8313 if (event.xcrossing.window != windows->widget.id)
8315 state&=(~InactiveWidgetState);
8320 if (event.xexpose.window != windows->widget.id)
8322 if (event.xexpose.count != 0)
8324 state|=RedrawWidgetState;
8330 command[MagickPathExtent];
8336 Respond to a user key press.
8338 if (event.xkey.window != windows->widget.id)
8340 (void) XLookupString((XKeyEvent *) &event.xkey,command,
8341 (int) sizeof(command),&key_symbol,(XComposeStatus *) NULL);
8342 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
8344 dismiss_info.raised=MagickFalse;
8345 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
8353 if (event.xcrossing.window != windows->widget.id)
8355 state|=InactiveWidgetState;
8361 Discard pending button motion events.
8363 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
8364 if (state & InactiveWidgetState)
8366 if (dismiss_info.raised == MatteIsActive(dismiss_info,event.xmotion))
8369 Dismiss button status changed.
8371 dismiss_info.raised=
8372 dismiss_info.raised == MagickFalse ? MagickTrue : MagickFalse;
8373 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
8381 } while ((state & ExitState) == 0);
8382 XSetCursorState(display,windows,MagickFalse);
8383 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
8384 XCheckRefreshWindows(display,windows);
8388 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8392 % X P r e f e r e n c e s W i d g e t %
8396 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8398 % XPreferencesWidget() displays a Preferences widget with program preferences.
8399 % If the user presses the Apply button, the preferences are stored in a
8400 % configuration file in the users' home directory.
8402 % The format of the XPreferencesWidget method is:
8404 % MagickBooleanType XPreferencesWidget(Display *display,
8405 % XResourceInfo *resource_info,XWindows *windows)
8407 % A description of each parameter follows:
8409 % o display: Specifies a connection to an X server; returned from
8412 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
8414 % o window: Specifies a pointer to a XWindows structure.
8417 MagickPrivate MagickBooleanType XPreferencesWidget(Display *display,
8418 XResourceInfo *resource_info,XWindows *windows)
8420 #define ApplyButtonText "Apply"
8421 #define CacheButtonText "%lu mega-bytes of memory in the undo edit cache "
8422 #define CancelButtonText "Cancel"
8423 #define NumberPreferences 8
8428 "display image centered on a backdrop",
8429 "confirm on program exit",
8430 "confirm on image edits",
8431 "correct image for display gamma",
8432 "display warning messages",
8433 "apply Floyd/Steinberg error diffusion to image",
8434 "use a shared colormap for colormapped X visuals",
8435 "display images as an X server pixmap"
8439 cache[MagickPathExtent];
8472 preferences_info[NumberPreferences];
8478 Determine Preferences widget attributes.
8480 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
8481 assert(display != (Display *) NULL);
8482 assert(resource_info != (XResourceInfo *) NULL);
8483 assert(windows != (XWindows *) NULL);
8484 XCheckRefreshWindows(display,windows);
8485 font_info=windows->widget.font_info;
8486 text_width=WidgetTextWidth(font_info,CacheButtonText);
8487 for (i=0; i < NumberPreferences; i++)
8488 if (WidgetTextWidth(font_info,(char *) Preferences[i]) > text_width)
8489 text_width=WidgetTextWidth(font_info,(char *) Preferences[i]);
8490 width=WidgetTextWidth(font_info,ApplyButtonText);
8491 if (WidgetTextWidth(font_info,CancelButtonText) > width)
8492 width=WidgetTextWidth(font_info,CancelButtonText);
8493 width+=(unsigned int) QuantumMargin;
8494 height=(unsigned int) (font_info->ascent+font_info->descent);
8496 Position Preferences widget.
8498 windows->widget.width=(unsigned int) (MagickMax((int) (width << 1),
8499 (int) text_width)+6*QuantumMargin);
8500 windows->widget.min_width=(width << 1)+QuantumMargin;
8501 if (windows->widget.width < windows->widget.min_width)
8502 windows->widget.width=windows->widget.min_width;
8503 windows->widget.height=(unsigned int)
8504 (7*height+NumberPreferences*(height+(QuantumMargin >> 1)));
8505 windows->widget.min_height=(unsigned int)
8506 (7*height+NumberPreferences*(height+(QuantumMargin >> 1)));
8507 if (windows->widget.height < windows->widget.min_height)
8508 windows->widget.height=windows->widget.min_height;
8509 XConstrainWindowPosition(display,&windows->widget);
8511 Map Preferences widget.
8513 (void) CopyMagickString(windows->widget.name,"Preferences",MagickPathExtent);
8514 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
8515 if (status != False)
8517 XSetWMName(display,windows->widget.id,&window_name);
8518 XSetWMIconName(display,windows->widget.id,&window_name);
8519 (void) XFree((void *) window_name.value);
8521 window_changes.width=(int) windows->widget.width;
8522 window_changes.height=(int) windows->widget.height;
8523 window_changes.x=windows->widget.x;
8524 window_changes.y=windows->widget.y;
8525 (void) XReconfigureWMWindow(display,windows->widget.id,windows->widget.screen,
8526 (unsigned int) (CWWidth | CWHeight | CWX | CWY),&window_changes);
8527 (void) XMapRaised(display,windows->widget.id);
8528 windows->widget.mapped=MagickFalse;
8530 Respond to X events.
8532 state=UpdateConfigurationState;
8533 XSetCursorState(display,windows,MagickTrue);
8536 if (state & UpdateConfigurationState)
8539 Initialize button information.
8541 XGetWidgetInfo(CancelButtonText,&cancel_info);
8542 cancel_info.width=width;
8543 cancel_info.height=(unsigned int) (3*height) >> 1;
8544 cancel_info.x=(int) windows->widget.width-cancel_info.width-
8545 (QuantumMargin << 1);
8546 cancel_info.y=(int) windows->widget.height-
8547 cancel_info.height-QuantumMargin;
8548 XGetWidgetInfo(ApplyButtonText,&apply_info);
8549 apply_info.width=width;
8550 apply_info.height=(unsigned int) (3*height) >> 1;
8551 apply_info.x=QuantumMargin << 1;
8552 apply_info.y=cancel_info.y;
8553 y=(int) (height << 1);
8554 for (i=0; i < NumberPreferences; i++)
8556 XGetWidgetInfo(Preferences[i],&preferences_info[i]);
8557 preferences_info[i].bevel_width--;
8558 preferences_info[i].width=(unsigned int) QuantumMargin >> 1;
8559 preferences_info[i].height=(unsigned int) QuantumMargin >> 1;
8560 preferences_info[i].x=QuantumMargin << 1;
8561 preferences_info[i].y=y;
8562 y+=height+(QuantumMargin >> 1);
8564 preferences_info[0].raised=resource_info->backdrop ==
8565 MagickFalse ? MagickTrue : MagickFalse;
8566 preferences_info[1].raised=resource_info->confirm_exit ==
8567 MagickFalse ? MagickTrue : MagickFalse;
8568 preferences_info[2].raised=resource_info->confirm_edit ==
8569 MagickFalse ? MagickTrue : MagickFalse;
8570 preferences_info[3].raised=resource_info->gamma_correct ==
8571 MagickFalse ? MagickTrue : MagickFalse;
8572 preferences_info[4].raised=resource_info->display_warnings ==
8573 MagickFalse ? MagickTrue : MagickFalse;
8574 preferences_info[5].raised=
8575 resource_info->quantize_info->dither_method == NoDitherMethod ?
8576 MagickTrue : MagickFalse;
8577 preferences_info[6].raised=resource_info->colormap !=
8578 SharedColormap ? MagickTrue : MagickFalse;
8579 preferences_info[7].raised=resource_info->use_pixmap ==
8580 MagickFalse ? MagickTrue : MagickFalse;
8581 (void) FormatLocaleString(cache,MagickPathExtent,CacheButtonText,
8582 (unsigned long) resource_info->undo_cache);
8583 XGetWidgetInfo(cache,&cache_info);
8584 cache_info.bevel_width--;
8585 cache_info.width=(unsigned int) QuantumMargin >> 1;
8586 cache_info.height=(unsigned int) QuantumMargin >> 1;
8587 cache_info.x=QuantumMargin << 1;
8589 state&=(~UpdateConfigurationState);
8591 if (state & RedrawWidgetState)
8594 Redraw Preferences widget.
8596 XDrawBeveledButton(display,&windows->widget,&apply_info);
8597 XDrawBeveledButton(display,&windows->widget,&cancel_info);
8598 for (i=0; i < NumberPreferences; i++)
8599 XDrawBeveledButton(display,&windows->widget,&preferences_info[i]);
8600 XDrawTriangleEast(display,&windows->widget,&cache_info);
8601 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
8602 state&=(~RedrawWidgetState);
8605 Wait for next event.
8607 (void) XIfEvent(display,&event,XScreenEvent,(char *) windows);
8612 if (MatteIsActive(apply_info,event.xbutton))
8615 User pressed Apply button.
8617 apply_info.raised=MagickFalse;
8618 XDrawBeveledButton(display,&windows->widget,&apply_info);
8621 if (MatteIsActive(cancel_info,event.xbutton))
8624 User pressed Cancel button.
8626 cancel_info.raised=MagickFalse;
8627 XDrawBeveledButton(display,&windows->widget,&cancel_info);
8630 for (i=0; i < NumberPreferences; i++)
8631 if (MatteIsActive(preferences_info[i],event.xbutton))
8634 User pressed a Preferences button.
8636 preferences_info[i].raised=preferences_info[i].raised ==
8637 MagickFalse ? MagickTrue : MagickFalse;
8638 XDrawBeveledButton(display,&windows->widget,&preferences_info[i]);
8641 if (MatteIsActive(cache_info,event.xbutton))
8644 User pressed Cache button.
8646 x=cache_info.x+cache_info.width+cache_info.bevel_width+
8647 (QuantumMargin >> 1);
8648 y=cache_info.y+((cache_info.height-height) >> 1);
8649 width=WidgetTextWidth(font_info,cache);
8650 (void) XClearArea(display,windows->widget.id,x,y,width,height,
8652 resource_info->undo_cache<<=1;
8653 if (resource_info->undo_cache > 256)
8654 resource_info->undo_cache=1;
8655 (void) FormatLocaleString(cache,MagickPathExtent,CacheButtonText,
8656 (unsigned long) resource_info->undo_cache);
8657 cache_info.raised=MagickFalse;
8658 XDrawTriangleEast(display,&windows->widget,&cache_info);
8665 if (windows->widget.mapped == MagickFalse)
8667 if (apply_info.raised == MagickFalse)
8669 if (event.xbutton.window == windows->widget.id)
8670 if (MatteIsActive(apply_info,event.xbutton))
8672 apply_info.raised=MagickTrue;
8673 XDrawBeveledButton(display,&windows->widget,&apply_info);
8674 apply_info.raised=MagickFalse;
8676 if (cancel_info.raised == MagickFalse)
8678 if (event.xbutton.window == windows->widget.id)
8679 if (MatteIsActive(cancel_info,event.xbutton))
8681 cancel_info.raised=MagickTrue;
8682 XDrawBeveledButton(display,&windows->widget,&cancel_info);
8684 if (cache_info.raised == MagickFalse)
8686 cache_info.raised=MagickTrue;
8687 XDrawTriangleEast(display,&windows->widget,&cache_info);
8694 If client window delete message, exit.
8696 if (event.xclient.message_type != windows->wm_protocols)
8698 if (*event.xclient.data.l == (int) windows->wm_take_focus)
8700 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
8701 (Time) event.xclient.data.l[1]);
8704 if (*event.xclient.data.l != (int) windows->wm_delete_window)
8706 if (event.xclient.window == windows->widget.id)
8713 case ConfigureNotify:
8716 Update widget configuration.
8718 if (event.xconfigure.window != windows->widget.id)
8720 if ((event.xconfigure.width == (int) windows->widget.width) &&
8721 (event.xconfigure.height == (int) windows->widget.height))
8723 windows->widget.width=(unsigned int)
8724 MagickMax(event.xconfigure.width,(int) windows->widget.min_width);
8725 windows->widget.height=(unsigned int)
8726 MagickMax(event.xconfigure.height,(int) windows->widget.min_height);
8727 state|=UpdateConfigurationState;
8732 if (event.xcrossing.window != windows->widget.id)
8734 state&=(~InactiveWidgetState);
8739 if (event.xexpose.window != windows->widget.id)
8741 if (event.xexpose.count != 0)
8743 state|=RedrawWidgetState;
8749 command[MagickPathExtent];
8755 Respond to a user key press.
8757 if (event.xkey.window != windows->widget.id)
8759 (void) XLookupString((XKeyEvent *) &event.xkey,command,
8760 (int) sizeof(command),&key_symbol,(XComposeStatus *) NULL);
8761 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
8763 apply_info.raised=MagickFalse;
8764 XDrawBeveledButton(display,&windows->widget,&apply_info);
8772 if (event.xcrossing.window != windows->widget.id)
8774 state|=InactiveWidgetState;
8780 Discard pending button motion events.
8782 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
8783 if (state & InactiveWidgetState)
8785 if (apply_info.raised == MatteIsActive(apply_info,event.xmotion))
8788 Apply button status changed.
8791 apply_info.raised == MagickFalse ? MagickTrue : MagickFalse;
8792 XDrawBeveledButton(display,&windows->widget,&apply_info);
8795 if (cancel_info.raised == MatteIsActive(cancel_info,event.xmotion))
8798 Cancel button status changed.
8801 cancel_info.raised == MagickFalse ? MagickTrue : MagickFalse;
8802 XDrawBeveledButton(display,&windows->widget,&cancel_info);
8810 } while ((state & ExitState) == 0);
8811 XSetCursorState(display,windows,MagickFalse);
8812 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
8813 XCheckRefreshWindows(display,windows);
8814 if (apply_info.raised)
8815 return(MagickFalse);
8817 Save user preferences to the client configuration file.
8819 resource_info->backdrop=
8820 preferences_info[0].raised == MagickFalse ? MagickTrue : MagickFalse;
8821 resource_info->confirm_exit=
8822 preferences_info[1].raised == MagickFalse ? MagickTrue : MagickFalse;
8823 resource_info->confirm_edit=
8824 preferences_info[2].raised == MagickFalse ? MagickTrue : MagickFalse;
8825 resource_info->gamma_correct=
8826 preferences_info[3].raised == MagickFalse ? MagickTrue : MagickFalse;
8827 resource_info->display_warnings=
8828 preferences_info[4].raised == MagickFalse ? MagickTrue : MagickFalse;
8829 resource_info->quantize_info->dither_method=
8830 preferences_info[5].raised == MagickFalse ?
8831 RiemersmaDitherMethod : NoDitherMethod;
8832 resource_info->colormap=SharedColormap;
8833 if (preferences_info[6].raised)
8834 resource_info->colormap=PrivateColormap;
8835 resource_info->use_pixmap=
8836 preferences_info[7].raised == MagickFalse ? MagickTrue : MagickFalse;
8837 XUserPreferences(resource_info);
8842 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8846 % X P r o g r e s s M o n i t o r W i d g e t %
8850 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8852 % XProgressMonitorWidget() displays the progress a task is making in
8853 % completing a task. A span of zero toggles the active status. An inactive
8854 % state disables the progress monitor.
8856 % The format of the XProgressMonitorWidget method is:
8858 % void XProgressMonitorWidget(Display *display,XWindows *windows,
8859 % const char *task,const MagickOffsetType offset,
8860 % const MagickSizeType span)
8862 % A description of each parameter follows:
8864 % o display: Specifies a connection to an X server; returned from
8867 % o window: Specifies a pointer to a XWindows structure.
8869 % o task: Identifies the task in progress.
8871 % o offset: Specifies the offset position within the span which represents
8872 % how much progress has been made in completing a task.
8874 % o span: Specifies the span relative to completing a task.
8877 MagickPrivate void XProgressMonitorWidget(Display *display,XWindows *windows,
8878 const char *task,const MagickOffsetType offset,const MagickSizeType span)
8886 assert(display != (Display *) NULL);
8887 assert(windows != (XWindows *) NULL);
8888 assert(task != (const char *) NULL);
8889 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",task);
8893 Update image windows if there is a pending expose event.
8895 while (XCheckTypedWindowEvent(display,windows->command.id,Expose,&event))
8896 (void) XCommandWidget(display,windows,(const char **) NULL,&event);
8897 while (XCheckTypedWindowEvent(display,windows->image.id,Expose,&event))
8898 XRefreshWindow(display,&windows->image,&event);
8899 while (XCheckTypedWindowEvent(display,windows->info.id,Expose,&event))
8900 if (monitor_info.text != (char *) NULL)
8901 XInfoWidget(display,windows,monitor_info.text);
8903 Draw progress monitor bar to represent percent completion of a task.
8905 if ((windows->info.mapped == MagickFalse) || (task != monitor_info.text))
8906 XInfoWidget(display,windows,task);
8907 width=(unsigned int) (((offset+1)*(windows->info.width-
8908 (2*monitor_info.x)))/span);
8909 if (width < monitor_info.width)
8911 monitor_info.raised=MagickTrue;
8912 XDrawWidgetText(display,&windows->info,&monitor_info);
8913 monitor_info.raised=MagickFalse;
8915 monitor_info.width=width;
8916 XDrawWidgetText(display,&windows->info,&monitor_info);
8917 (void) XFlush(display);
8921 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8925 % X T e x t V i e w W i d g e t %
8929 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8931 % XTextViewWidget() displays text in a Text View widget.
8933 % The format of the XTextViewWidget method is:
8935 % void XTextViewWidget(Display *display,const XResourceInfo *resource_info,
8936 % XWindows *windows,const MagickBooleanType mono,const char *title,
8937 % const char **textlist)
8939 % A description of each parameter follows:
8941 % o display: Specifies a connection to an X server; returned from
8944 % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
8946 % o window: Specifies a pointer to a XWindows structure.
8948 % o mono: Use mono-spaced font when displaying text.
8950 % o title: This character string is displayed at the top of the widget
8953 % o textlist: This string list is displayed within the Text View widget.
8956 MagickPrivate void XTextViewWidget(Display *display,
8957 const XResourceInfo *resource_info,XWindows *windows,
8958 const MagickBooleanType mono,const char *title,const char **textlist)
8960 #define DismissButtonText "Dismiss"
8963 primary_selection[MagickPathExtent];
8968 static MagickStatusType
8969 mask = (MagickStatusType) (CWWidth | CWHeight | CWX | CWY);
9009 Convert text string to a text list.
9011 assert(display != (Display *) NULL);
9012 assert(resource_info != (XResourceInfo *) NULL);
9013 assert(windows != (XWindows *) NULL);
9014 assert(title != (const char *) NULL);
9015 assert(textlist != (const char **) NULL);
9016 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",title);
9017 XSetCursorState(display,windows,MagickTrue);
9018 XCheckRefreshWindows(display,windows);
9019 if (textlist == (const char **) NULL)
9021 XNoticeWidget(display,windows,"No text to view:",(char *) NULL);
9025 Determine Text View widget attributes.
9027 font_info=windows->widget.font_info;
9028 text_info=(XFontStruct *) NULL;
9029 if (mono != MagickFalse)
9030 text_info=XBestFont(display,resource_info,MagickTrue);
9031 if (text_info == (XFontStruct *) NULL)
9032 text_info=windows->widget.font_info;
9034 for (i=0; textlist[i] != (char *) NULL; i++)
9035 if (WidgetTextWidth(text_info,(char *) textlist[i]) > text_width)
9036 text_width=(unsigned int) XTextWidth(text_info,(char *) textlist[i],
9037 MagickMin(Extent(textlist[i]),160));
9038 lines=(unsigned int) i;
9039 width=WidgetTextWidth(font_info,DismissButtonText);
9040 width+=QuantumMargin;
9041 height=(unsigned int) (text_info->ascent+text_info->descent);
9043 Position Text View widget.
9045 windows->widget.width=(unsigned int) (MagickMin((int) text_width,
9046 (int) MaxTextWidth)+5*QuantumMargin);
9047 windows->widget.min_width=(unsigned int) (MinTextWidth+4*QuantumMargin);
9048 if (windows->widget.width < windows->widget.min_width)
9049 windows->widget.width=windows->widget.min_width;
9050 windows->widget.height=(unsigned int) (MagickMin(MagickMax((int) lines,3),32)*
9051 height+((13*height) >> 1)+((9*QuantumMargin) >> 1));
9052 windows->widget.min_height=(unsigned int) (3*height+((13*height) >> 1)+((9*
9053 QuantumMargin) >> 1));
9054 if (windows->widget.height < windows->widget.min_height)
9055 windows->widget.height=windows->widget.min_height;
9056 XConstrainWindowPosition(display,&windows->widget);
9058 Map Text View widget.
9060 (void) CopyMagickString(windows->widget.name,title,MagickPathExtent);
9061 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
9062 if (status != False)
9064 XSetWMName(display,windows->widget.id,&window_name);
9065 XSetWMIconName(display,windows->widget.id,&window_name);
9066 (void) XFree((void *) window_name.value);
9068 window_changes.width=(int) windows->widget.width;
9069 window_changes.height=(int) windows->widget.height;
9070 window_changes.x=windows->widget.x;
9071 window_changes.y=windows->widget.y;
9072 (void) XReconfigureWMWindow(display,windows->widget.id,
9073 windows->widget.screen,(unsigned int) mask,&window_changes);
9074 (void) XMapRaised(display,windows->widget.id);
9075 windows->widget.mapped=MagickFalse;
9077 Respond to X events.
9079 XGetWidgetInfo((char *) NULL,&slider_info);
9080 XGetWidgetInfo((char *) NULL,&north_info);
9081 XGetWidgetInfo((char *) NULL,&south_info);
9082 XGetWidgetInfo((char *) NULL,&expose_info);
9083 XGetWidgetInfo((char *) NULL,&selection_info);
9085 delay=SuspendTime << 2;
9086 height=(unsigned int) (font_info->ascent+font_info->descent);
9087 state=UpdateConfigurationState;
9090 if (state & UpdateConfigurationState)
9096 Initialize button information.
9098 XGetWidgetInfo(DismissButtonText,&dismiss_info);
9099 dismiss_info.width=width;
9100 dismiss_info.height=(unsigned int) ((3*height) >> 1);
9101 dismiss_info.x=(int) windows->widget.width-dismiss_info.width-
9103 dismiss_info.y=(int) windows->widget.height-dismiss_info.height-
9106 Initialize scroll information.
9108 XGetWidgetInfo((char *) NULL,&scroll_info);
9109 scroll_info.bevel_width--;
9110 scroll_info.width=height;
9111 scroll_info.height=(unsigned int) (dismiss_info.y-((5*QuantumMargin) >>
9113 scroll_info.x=(int) windows->widget.width-QuantumMargin-
9115 scroll_info.y=(3*QuantumMargin) >> 1;
9116 scroll_info.raised=MagickFalse;
9117 scroll_info.trough=MagickTrue;
9118 north_info=scroll_info;
9119 north_info.raised=MagickTrue;
9120 north_info.width-=(north_info.bevel_width << 1);
9121 north_info.height=north_info.width-1;
9122 north_info.x+=north_info.bevel_width;
9123 north_info.y+=north_info.bevel_width;
9124 south_info=north_info;
9125 south_info.y=scroll_info.y+scroll_info.height-scroll_info.bevel_width-
9128 slider_info=north_info;
9130 slider_info.width-=2;
9131 slider_info.min_y=north_info.y+north_info.height+north_info.bevel_width+
9132 slider_info.bevel_width+2;
9133 slider_info.height=scroll_info.height-((slider_info.min_y-
9134 scroll_info.y+1) << 1)+4;
9135 visible_lines=scroll_info.height/(text_info->ascent+text_info->descent+
9136 ((text_info->ascent+text_info->descent) >> 3));
9137 if (lines > visible_lines)
9138 slider_info.height=(unsigned int) (visible_lines*slider_info.height)/
9140 slider_info.max_y=south_info.y-south_info.bevel_width-
9141 slider_info.bevel_width-2;
9142 slider_info.x=scroll_info.x+slider_info.bevel_width+1;
9143 slider_info.y=slider_info.min_y;
9144 expose_info=scroll_info;
9145 expose_info.y=slider_info.y;
9147 Initialize list information.
9149 XGetWidgetInfo((char *) NULL,&list_info);
9150 list_info.raised=MagickFalse;
9151 list_info.bevel_width--;
9152 list_info.width=(unsigned int) scroll_info.x-((3*QuantumMargin) >> 1);
9153 list_info.height=scroll_info.height;
9154 list_info.x=QuantumMargin;
9155 list_info.y=scroll_info.y;
9157 Initialize selection information.
9159 XGetWidgetInfo((char *) NULL,&selection_info);
9160 selection_info.center=MagickFalse;
9161 selection_info.width=list_info.width;
9162 selection_info.height=(unsigned int)
9163 (9*(text_info->ascent+text_info->descent)) >> 3;
9164 selection_info.x=list_info.x;
9165 state&=(~UpdateConfigurationState);
9167 if (state & RedrawWidgetState)
9170 Redraw Text View window.
9172 XDrawBeveledMatte(display,&windows->widget,&list_info);
9173 XDrawBeveledMatte(display,&windows->widget,&scroll_info);
9174 XDrawTriangleNorth(display,&windows->widget,&north_info);
9175 XDrawBeveledButton(display,&windows->widget,&slider_info);
9176 XDrawTriangleSouth(display,&windows->widget,&south_info);
9177 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
9178 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
9179 selection_info.id=(~0);
9180 state|=RedrawListState;
9181 state&=(~RedrawWidgetState);
9183 if (state & RedrawListState)
9186 Determine slider id and position.
9188 if (slider_info.id >= (int) (lines-visible_lines))
9189 slider_info.id=(int) lines-visible_lines;
9190 if ((slider_info.id < 0) || (lines <= visible_lines))
9192 slider_info.y=slider_info.min_y;
9195 slider_info.id*(slider_info.max_y-slider_info.min_y+1)/lines;
9196 if (slider_info.id != selection_info.id)
9199 Redraw scroll bar and text.
9201 windows->widget.font_info=text_info;
9202 (void) XSetFont(display,windows->widget.annotate_context,
9204 (void) XSetFont(display,windows->widget.highlight_context,
9206 selection_info.id=slider_info.id;
9207 selection_info.y=list_info.y+(height >> 3)+2;
9208 for (i=0; i < (int) visible_lines; i++)
9210 selection_info.raised=
9211 (slider_info.id+i) != list_info.id ? MagickTrue : MagickFalse;
9212 selection_info.text=(char *) NULL;
9213 if ((slider_info.id+i) < (int) lines)
9214 selection_info.text=(char *) textlist[slider_info.id+i];
9215 XDrawWidgetText(display,&windows->widget,&selection_info);
9216 selection_info.y+=(int) selection_info.height;
9218 windows->widget.font_info=font_info;
9219 (void) XSetFont(display,windows->widget.annotate_context,
9221 (void) XSetFont(display,windows->widget.highlight_context,
9226 if (slider_info.y > expose_info.y)
9228 expose_info.height=(unsigned int) slider_info.y-expose_info.y;
9229 expose_info.y=slider_info.y-expose_info.height-
9230 slider_info.bevel_width-1;
9234 expose_info.height=(unsigned int) expose_info.y-slider_info.y;
9235 expose_info.y=slider_info.y+slider_info.height+
9236 slider_info.bevel_width+1;
9238 XDrawTriangleNorth(display,&windows->widget,&north_info);
9239 XDrawMatte(display,&windows->widget,&expose_info);
9240 XDrawBeveledButton(display,&windows->widget,&slider_info);
9241 XDrawTriangleSouth(display,&windows->widget,&south_info);
9242 expose_info.y=slider_info.y;
9244 state&=(~RedrawListState);
9247 Wait for next event.
9249 if (north_info.raised && south_info.raised)
9250 (void) XIfEvent(display,&event,XScreenEvent,(char *) windows);
9254 Brief delay before advancing scroll bar.
9256 XDelay(display,delay);
9258 (void) XCheckIfEvent(display,&event,XScreenEvent,(char *) windows);
9259 if (north_info.raised == MagickFalse)
9260 if (slider_info.id > 0)
9266 state|=RedrawListState;
9268 if (south_info.raised == MagickFalse)
9269 if (slider_info.id < (int) lines)
9275 state|=RedrawListState;
9277 if (event.type != ButtonRelease)
9284 if (MatteIsActive(slider_info,event.xbutton))
9289 slider_info.active=MagickTrue;
9292 if (MatteIsActive(north_info,event.xbutton))
9293 if (slider_info.id > 0)
9298 north_info.raised=MagickFalse;
9300 state|=RedrawListState;
9303 if (MatteIsActive(south_info,event.xbutton))
9304 if (slider_info.id < (int) lines)
9309 south_info.raised=MagickFalse;
9311 state|=RedrawListState;
9314 if (MatteIsActive(scroll_info,event.xbutton))
9319 if (event.xbutton.y < slider_info.y)
9320 slider_info.id-=(visible_lines-1);
9322 slider_info.id+=(visible_lines-1);
9323 state|=RedrawListState;
9326 if (MatteIsActive(dismiss_info,event.xbutton))
9329 User pressed Dismiss button.
9331 dismiss_info.raised=MagickFalse;
9332 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
9335 if (MatteIsActive(list_info,event.xbutton))
9344 User pressed list matte.
9346 id=slider_info.id+(event.xbutton.y-(list_info.y+(height >> 1))+1)/
9347 selection_info.height;
9348 if (id >= (int) lines)
9350 if (id != list_info.id)
9353 click_time=event.xbutton.time;
9357 if (event.xbutton.time >= (click_time+DoubleClick))
9359 click_time=event.xbutton.time;
9362 click_time=event.xbutton.time;
9364 Become the XA_PRIMARY selection owner.
9366 (void) CopyMagickString(primary_selection,textlist[list_info.id],
9368 (void) XSetSelectionOwner(display,XA_PRIMARY,windows->widget.id,
9369 event.xbutton.time);
9370 if (XGetSelectionOwner(display,XA_PRIMARY) != windows->widget.id)
9372 selection_info.id=(~0);
9374 state|=RedrawListState;
9381 if (windows->widget.mapped == MagickFalse)
9383 if (north_info.raised == MagickFalse)
9386 User released up button.
9388 delay=SuspendTime << 2;
9389 north_info.raised=MagickTrue;
9390 XDrawTriangleNorth(display,&windows->widget,&north_info);
9392 if (south_info.raised == MagickFalse)
9395 User released down button.
9397 delay=SuspendTime << 2;
9398 south_info.raised=MagickTrue;
9399 XDrawTriangleSouth(display,&windows->widget,&south_info);
9401 if (slider_info.active)
9404 Stop tracking slider.
9406 slider_info.active=MagickFalse;
9409 if (dismiss_info.raised == MagickFalse)
9411 if (event.xbutton.window == windows->widget.id)
9412 if (MatteIsActive(dismiss_info,event.xbutton))
9414 dismiss_info.raised=MagickTrue;
9415 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
9422 If client window delete message, exit.
9424 if (event.xclient.message_type != windows->wm_protocols)
9426 if (*event.xclient.data.l == (int) windows->wm_take_focus)
9428 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
9429 (Time) event.xclient.data.l[1]);
9432 if (*event.xclient.data.l != (int) windows->wm_delete_window)
9434 if (event.xclient.window == windows->widget.id)
9441 case ConfigureNotify:
9444 Update widget configuration.
9446 if (event.xconfigure.window != windows->widget.id)
9448 if ((event.xconfigure.width == (int) windows->widget.width) &&
9449 (event.xconfigure.height == (int) windows->widget.height))
9451 windows->widget.width=(unsigned int)
9452 MagickMax(event.xconfigure.width,(int) windows->widget.min_width);
9453 windows->widget.height=(unsigned int)
9454 MagickMax(event.xconfigure.height,(int) windows->widget.min_height);
9455 state|=UpdateConfigurationState;
9460 if (event.xcrossing.window != windows->widget.id)
9462 state&=(~InactiveWidgetState);
9467 if (event.xexpose.window != windows->widget.id)
9469 if (event.xexpose.count != 0)
9471 state|=RedrawWidgetState;
9477 command[MagickPathExtent];
9486 Respond to a user key press.
9488 if (event.xkey.window != windows->widget.id)
9490 length=XLookupString((XKeyEvent *) &event.xkey,command,
9491 (int) sizeof(command),&key_symbol,(XComposeStatus *) NULL);
9492 *(command+length)='\0';
9493 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
9495 dismiss_info.raised=MagickFalse;
9496 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
9500 if (AreaIsActive(scroll_info,event.xkey))
9505 switch ((int) key_symbol)
9528 slider_info.id-=visible_lines;
9534 slider_info.id+=visible_lines;
9540 slider_info.id=(int) lines;
9544 state|=RedrawListState;
9553 if (event.xcrossing.window != windows->widget.id)
9555 state|=InactiveWidgetState;
9567 Discard pending button motion events.
9569 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
9570 if (slider_info.active)
9575 slider_info.y=event.xmotion.y-
9576 ((slider_info.height+slider_info.bevel_width) >> 1)+1;
9577 if (slider_info.y < slider_info.min_y)
9578 slider_info.y=slider_info.min_y;
9579 if (slider_info.y > slider_info.max_y)
9580 slider_info.y=slider_info.max_y;
9582 if (slider_info.y != slider_info.min_y)
9583 slider_info.id=(int) (lines*(slider_info.y-slider_info.min_y+1))/
9584 (slider_info.max_y-slider_info.min_y+1);
9585 state|=RedrawListState;
9588 if (state & InactiveWidgetState)
9590 if (dismiss_info.raised == MatteIsActive(dismiss_info,event.xmotion))
9593 Dismiss button status changed.
9595 dismiss_info.raised=
9596 dismiss_info.raised == MagickFalse ? MagickTrue : MagickFalse;
9597 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
9602 case SelectionClear:
9605 selection_info.id=(~0);
9606 state|=RedrawListState;
9609 case SelectionRequest:
9614 XSelectionRequestEvent
9617 if (list_info.id == (~0))
9620 Set primary selection.
9622 request=(&(event.xselectionrequest));
9623 (void) XChangeProperty(request->display,request->requestor,
9624 request->property,request->target,8,PropModeReplace,
9625 (unsigned char *) primary_selection,Extent(primary_selection));
9626 notify.type=SelectionNotify;
9627 notify.send_event=MagickTrue;
9628 notify.display=request->display;
9629 notify.requestor=request->requestor;
9630 notify.selection=request->selection;
9631 notify.target=request->target;
9632 notify.time=request->time;
9633 if (request->property == None)
9634 notify.property=request->target;
9636 notify.property=request->property;
9637 (void) XSendEvent(request->display,request->requestor,False,NoEventMask,
9638 (XEvent *) ¬ify);
9643 } while ((state & ExitState) == 0);
9644 if (text_info != windows->widget.font_info)
9645 (void) XFreeFont(display,text_info);
9646 XSetCursorState(display,windows,MagickFalse);
9647 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
9648 XCheckRefreshWindows(display,windows);