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-2015 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 % http://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/PreRvIcccm.h"
52 #include "MagickCore/string_.h"
53 #include "MagickCore/token.h"
54 #include "MagickCore/token-private.h"
55 #include "MagickCore/utility.h"
56 #include "MagickCore/utility-private.h"
57 #include "MagickCore/xwindow-private.h"
58 #include "MagickCore/widget.h"
59 #include "MagickCore/widget-private.h"
61 #if defined(MAGICKCORE_X11_DELEGATE)
66 #define AreaIsActive(matte_info,position) ( \
67 ((position.y >= (int) (matte_info.y-matte_info.bevel_width)) && \
68 (position.y < (int) (matte_info.y+matte_info.height+matte_info.bevel_width))) \
69 ? MagickTrue : MagickFalse)
70 #define Extent(s) ((int) strlen(s))
71 #define MatteIsActive(matte_info,position) ( \
72 ((position.x >= (int) (matte_info.x-matte_info.bevel_width)) && \
73 (position.y >= (int) (matte_info.y-matte_info.bevel_width)) && \
74 (position.x < (int) (matte_info.x+matte_info.width+matte_info.bevel_width)) && \
75 (position.y < (int) (matte_info.y+matte_info.height+matte_info.bevel_width))) \
76 ? MagickTrue : MagickFalse)
77 #define MaxTextWidth ((unsigned int) (255*XTextWidth(font_info,"_",1)))
78 #define MinTextWidth (26*XTextWidth(font_info,"_",1))
79 #define QuantumMargin MagickMax(font_info->max_bounds.width,12)
80 #define WidgetTextWidth(font_info,text) \
81 ((unsigned int) XTextWidth(font_info,text,Extent(text)))
82 #define WindowIsActive(window_info,position) ( \
83 ((position.x >= 0) && (position.y >= 0) && \
84 (position.x < (int) window_info.width) && \
85 (position.y < (int) window_info.height)) ? MagickTrue : MagickFalse)
92 ControlState = 0x0001,
93 InactiveWidgetState = 0x0004,
94 JumpListState = 0x0008,
95 RedrawActionState = 0x0010,
96 RedrawListState = 0x0020,
97 RedrawWidgetState = 0x0040,
98 UpdateListState = 0x0100
102 Typedef declarations.
104 typedef struct _XWidgetInfo
134 Variable declarations.
139 (char *) NULL, (char *) NULL, (char *) NULL, 0, 0, 0, 0, 0, 0, 0, 0,
140 MagickFalse, MagickFalse, MagickFalse, MagickFalse, MagickFalse
144 (char *) NULL, (char *) NULL, (char *) NULL, 0, 0, 0, 0, 0, 0, 0, 0,
145 MagickFalse, MagickFalse, MagickFalse, MagickFalse, MagickFalse
147 *selection_info = (XWidgetInfo *) NULL,
150 (char *) NULL, (char *) NULL, (char *) NULL, 0, 0, 0, 0, 0, 0, 0, 0,
151 MagickFalse, MagickFalse, MagickFalse, MagickFalse, MagickFalse
155 Constant declarations.
165 XDrawMatte(Display *,const XWindowInfo *,const XWidgetInfo *),
166 XSetBevelColor(Display *,const XWindowInfo *,const MagickStatusType),
167 XSetMatteColor(Display *,const XWindowInfo *,const MagickStatusType),
168 XSetTextColor(Display *,const XWindowInfo *,const MagickStatusType);
171 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
175 % D e s t r o y X W i d g e t %
179 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181 % DestroyXWidget() destroys resources associated with the X widget.
183 % The format of the DestroyXWidget method is:
185 % void DestroyXWidget()
187 % A description of each parameter follows:
190 MagickPrivate void DestroyXWidget(void)
192 if (selection_info != (XWidgetInfo *) NULL)
193 selection_info=(XWidgetInfo *) RelinquishMagickMemory(selection_info);
197 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201 + X D r a w B e v e l %
205 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
207 % XDrawBevel() "sets off" an area with a highlighted upper and left bevel and
208 % a shadowed lower and right bevel. The highlighted and shadowed bevels
209 % create a 3-D effect.
211 % The format of the XDrawBevel function is:
213 % XDrawBevel(display,window_info,bevel_info)
215 % A description of each parameter follows:
217 % o display: Specifies a pointer to the Display structure; returned from
220 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
222 % o bevel_info: Specifies a pointer to a XWidgetInfo structure. It
223 % contains the extents of the bevel.
226 static void XDrawBevel(Display *display,const XWindowInfo *window_info,
227 const XWidgetInfo *bevel_info)
242 Draw upper and left beveled border.
245 y1=bevel_info->y+bevel_info->height;
246 x2=bevel_info->x+bevel_info->width;
248 bevel_width=bevel_info->bevel_width;
255 points[3].x=x2+bevel_width;
256 points[3].y=y2-bevel_width;
257 points[4].x=x1-bevel_width;
258 points[4].y=y2-bevel_width;
259 points[5].x=x1-bevel_width;
260 points[5].y=y1+bevel_width;
261 XSetBevelColor(display,window_info,bevel_info->raised);
262 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
263 points,6,Complex,CoordModeOrigin);
265 Draw lower and right beveled border.
273 points[3].x=x2+bevel_width;
274 points[3].y=y2-bevel_width;
275 points[4].x=x2+bevel_width;
276 points[4].y=y1+bevel_width;
277 points[5].x=x1-bevel_width;
278 points[5].y=y1+bevel_width;
279 XSetBevelColor(display,window_info,!bevel_info->raised);
280 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
281 points,6,Complex,CoordModeOrigin);
282 (void) XSetFillStyle(display,window_info->widget_context,FillSolid);
286 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
290 + X D r a w B e v e l e d B u t t o n %
294 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
296 % XDrawBeveledButton() draws a button with a highlighted upper and left bevel
297 % and a shadowed lower and right bevel. The highlighted and shadowed bevels
298 % create a 3-D effect.
300 % The format of the XDrawBeveledButton function is:
302 % XDrawBeveledButton(display,window_info,button_info)
304 % A description of each parameter follows:
306 % o display: Specifies a pointer to the Display structure; returned from
309 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
311 % o button_info: Specifies a pointer to a XWidgetInfo structure. It
312 % contains the extents of the button.
316 static void XDrawBeveledButton(Display *display,const XWindowInfo *window_info,
317 const XWidgetInfo *button_info)
335 XDrawBevel(display,window_info,button_info);
336 XSetMatteColor(display,window_info,button_info->raised);
337 (void) XFillRectangle(display,window_info->id,window_info->widget_context,
338 button_info->x,button_info->y,button_info->width,button_info->height);
339 x=button_info->x-button_info->bevel_width-1;
340 y=button_info->y-button_info->bevel_width-1;
341 (void) XSetForeground(display,window_info->widget_context,
342 window_info->pixel_info->trough_color.pixel);
343 if (button_info->raised || (window_info->depth == 1))
344 (void) XDrawRectangle(display,window_info->id,window_info->widget_context,
345 x,y,button_info->width+(button_info->bevel_width << 1)+1,
346 button_info->height+(button_info->bevel_width << 1)+1);
347 if (button_info->text == (char *) NULL)
352 crop_info.width=(unsigned short) button_info->width;
353 crop_info.height=(unsigned short) button_info->height;
354 crop_info.x=button_info->x;
355 crop_info.y=button_info->y;
359 font_info=window_info->font_info;
360 width=WidgetTextWidth(font_info,button_info->text);
361 x=button_info->x+(QuantumMargin >> 1);
362 if (button_info->center)
363 x=button_info->x+(button_info->width >> 1)-(width >> 1);
364 y=button_info->y+((button_info->height-
365 (font_info->ascent+font_info->descent)) >> 1)+font_info->ascent;
366 if ((int) button_info->width == (QuantumMargin >> 1))
369 Option button-- write label to right of button.
371 XSetTextColor(display,window_info,MagickTrue);
372 x=button_info->x+button_info->width+button_info->bevel_width+
373 (QuantumMargin >> 1);
374 (void) XDrawString(display,window_info->id,window_info->widget_context,
375 x,y,button_info->text,Extent(button_info->text));
378 (void) XSetClipRectangles(display,window_info->widget_context,0,0,&crop_info,
380 XSetTextColor(display,window_info,button_info->raised);
381 (void) XDrawString(display,window_info->id,window_info->widget_context,x,y,
382 button_info->text,Extent(button_info->text));
383 (void) XSetClipMask(display,window_info->widget_context,None);
384 if (button_info->raised == MagickFalse)
385 XDelay(display,SuspendTime << 2);
389 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
393 + X D r a w B e v e l e d M a t t e %
397 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
399 % XDrawBeveledMatte() draws a matte with a shadowed upper and left bevel and
400 % a highlighted lower and right bevel. The highlighted and shadowed bevels
401 % create a 3-D effect.
403 % The format of the XDrawBeveledMatte function is:
405 % XDrawBeveledMatte(display,window_info,matte_info)
407 % A description of each parameter follows:
409 % o display: Specifies a pointer to the Display structure; returned from
412 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
414 % o matte_info: Specifies a pointer to a XWidgetInfo structure. It
415 % contains the extents of the matte.
418 static void XDrawBeveledMatte(Display *display,const XWindowInfo *window_info,
419 const XWidgetInfo *matte_info)
424 XDrawBevel(display,window_info,matte_info);
425 XDrawMatte(display,window_info,matte_info);
429 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
433 + X D r a w M a t t e %
437 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
439 % XDrawMatte() fills a rectangular area with the matte color.
441 % The format of the XDrawMatte function is:
443 % XDrawMatte(display,window_info,matte_info)
445 % A description of each parameter follows:
447 % o display: Specifies a pointer to the Display structure; returned from
450 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
452 % o matte_info: Specifies a pointer to a XWidgetInfo structure. It
453 % contains the extents of the matte.
456 static void XDrawMatte(Display *display,const XWindowInfo *window_info,
457 const XWidgetInfo *matte_info)
462 if ((matte_info->trough == MagickFalse) || (window_info->depth == 1))
463 (void) XFillRectangle(display,window_info->id,
464 window_info->highlight_context,matte_info->x,matte_info->y,
465 matte_info->width,matte_info->height);
468 (void) XSetForeground(display,window_info->widget_context,
469 window_info->pixel_info->trough_color.pixel);
470 (void) XFillRectangle(display,window_info->id,window_info->widget_context,
471 matte_info->x,matte_info->y,matte_info->width,matte_info->height);
476 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
480 + X D r a w M a t t e T e x t %
484 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
486 % XDrawMatteText() draws a matte with text. If the text exceeds the extents
487 % of the text, a portion of the text relative to the cursor is displayed.
489 % The format of the XDrawMatteText function is:
491 % XDrawMatteText(display,window_info,text_info)
493 % A description of each parameter follows:
495 % o display: Specifies a pointer to the Display structure; returned from
498 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
500 % o text_info: Specifies a pointer to a XWidgetInfo structure. It
501 % contains the extents of the text.
504 static void XDrawMatteText(Display *display,const XWindowInfo *window_info,
505 XWidgetInfo *text_info)
531 XSetMatteColor(display,window_info,MagickFalse);
532 (void) XFillRectangle(display,window_info->id,window_info->widget_context,
533 text_info->x,text_info->y,text_info->width,text_info->height);
534 if (text_info->text == (char *) NULL)
536 XSetTextColor(display,window_info,text_info->highlight);
537 font_info=window_info->font_info;
538 x=text_info->x+(QuantumMargin >> 2);
539 y=text_info->y+font_info->ascent+(text_info->height >> 2);
540 width=text_info->width-(QuantumMargin >> 1);
541 height=(unsigned int) (font_info->ascent+font_info->descent);
542 if (*text_info->text == '\0')
545 No text-- just draw cursor.
547 (void) XDrawLine(display,window_info->id,window_info->annotate_context,
554 crop_info.width=(unsigned short) text_info->width;
555 crop_info.height=(unsigned short) text_info->height;
556 crop_info.x=text_info->x;
557 crop_info.y=text_info->y;
559 Determine beginning of the visible text.
561 if (text_info->cursor < text_info->marker)
562 text_info->marker=text_info->cursor;
565 text=text_info->marker;
566 if (XTextWidth(font_info,(char *) text,(int) (text_info->cursor-text)) >
569 text=text_info->text;
570 for (i=0; i < Extent(text); i++)
572 n=XTextWidth(font_info,(char *) text+i,(int)
573 (text_info->cursor-text-i));
574 if (n <= (int) width)
577 text_info->marker=(char *) text+i;
581 Draw text and cursor.
583 if (text_info->highlight == MagickFalse)
585 (void) XSetClipRectangles(display,window_info->widget_context,0,0,
586 &crop_info,1,Unsorted);
587 (void) XDrawString(display,window_info->id,window_info->widget_context,
588 x,y,text_info->marker,Extent(text_info->marker));
589 (void) XSetClipMask(display,window_info->widget_context,None);
593 (void) XSetClipRectangles(display,window_info->annotate_context,0,0,
594 &crop_info,1,Unsorted);
595 width=WidgetTextWidth(font_info,text_info->marker);
596 (void) XFillRectangle(display,window_info->id,
597 window_info->annotate_context,x,y-font_info->ascent,width,height);
598 (void) XSetClipMask(display,window_info->annotate_context,None);
599 (void) XSetClipRectangles(display,window_info->highlight_context,0,0,
600 &crop_info,1,Unsorted);
601 (void) XDrawString(display,window_info->id,
602 window_info->highlight_context,x,y,text_info->marker,
603 Extent(text_info->marker));
604 (void) XSetClipMask(display,window_info->highlight_context,None);
606 x+=XTextWidth(font_info,text_info->marker,(int)
607 (text_info->cursor-text_info->marker));
608 (void) XDrawLine(display,window_info->id,window_info->annotate_context,x,y+3,
613 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
617 + X D r a w T r i a n g l e E a s t %
621 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
623 % XDrawTriangleEast() draws a triangle with a highlighted left bevel and a
624 % shadowed right and lower bevel. The highlighted and shadowed bevels create
627 % The format of the XDrawTriangleEast function is:
629 % XDrawTriangleEast(display,window_info,triangle_info)
631 % A description of each parameter follows:
633 % o display: Specifies a pointer to the Display structure; returned from
636 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
638 % o triangle_info: Specifies a pointer to a XWidgetInfo structure. It
639 % contains the extents of the triangle.
642 static void XDrawTriangleEast(Display *display,const XWindowInfo *window_info,
643 const XWidgetInfo *triangle_info)
667 x2=triangle_info->x+triangle_info->width;
668 y2=triangle_info->y+(triangle_info->height >> 1);
670 y3=triangle_info->y+triangle_info->height;
671 bevel_width=triangle_info->bevel_width;
678 XSetMatteColor(display,window_info,triangle_info->raised);
679 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
680 points,3,Complex,CoordModeOrigin);
688 points[2].x=x3-bevel_width;
689 points[2].y=y3+bevel_width;
690 points[3].x=x2+bevel_width;
692 XSetBevelColor(display,window_info,!triangle_info->raised);
693 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
694 points,4,Complex,CoordModeOrigin);
702 points[2].x=x1-bevel_width+1;
703 points[2].y=y1-bevel_width;
704 points[3].x=x3-bevel_width+1;
705 points[3].y=y3+bevel_width;
706 XSetBevelColor(display,window_info,triangle_info->raised);
707 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
708 points,4,Complex,CoordModeOrigin);
716 points[2].x=x2+bevel_width;
718 points[3].x=x1-bevel_width;
719 points[3].y=y1-bevel_width;
720 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
721 points,4,Complex,CoordModeOrigin);
722 (void) XSetFillStyle(display,window_info->widget_context,FillSolid);
723 if (triangle_info->text == (char *) NULL)
726 Write label to right of triangle.
728 font_info=window_info->font_info;
729 XSetTextColor(display,window_info,MagickTrue);
730 x1=triangle_info->x+triangle_info->width+triangle_info->bevel_width+
731 (QuantumMargin >> 1);
732 y1=triangle_info->y+((triangle_info->height-
733 (font_info->ascent+font_info->descent)) >> 1)+font_info->ascent;
734 (void) XDrawString(display,window_info->id,window_info->widget_context,x1,y1,
735 triangle_info->text,Extent(triangle_info->text));
739 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
743 + X D r a w T r i a n g l e N o r t h %
747 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
749 % XDrawTriangleNorth() draws a triangle with a highlighted left bevel and a
750 % shadowed right and lower bevel. The highlighted and shadowed bevels create
753 % The format of the XDrawTriangleNorth function is:
755 % XDrawTriangleNorth(display,window_info,triangle_info)
757 % A description of each parameter follows:
759 % o display: Specifies a pointer to the Display structure; returned from
762 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
764 % o triangle_info: Specifies a pointer to a XWidgetInfo structure. It
765 % contains the extents of the triangle.
768 static void XDrawTriangleNorth(Display *display,const XWindowInfo *window_info,
769 const XWidgetInfo *triangle_info)
789 y1=triangle_info->y+triangle_info->height;
790 x2=triangle_info->x+(triangle_info->width >> 1);
792 x3=triangle_info->x+triangle_info->width;
793 y3=triangle_info->y+triangle_info->height;
794 bevel_width=triangle_info->bevel_width;
801 XSetMatteColor(display,window_info,triangle_info->raised);
802 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
803 points,3,Complex,CoordModeOrigin);
812 points[2].y=y2-bevel_width-2;
813 points[3].x=x1-bevel_width-1;
814 points[3].y=y1+bevel_width;
815 XSetBevelColor(display,window_info,triangle_info->raised);
816 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
817 points,4,Complex,CoordModeOrigin);
825 points[2].x=x3+bevel_width;
826 points[2].y=y3+bevel_width;
828 points[3].y=y2-bevel_width;
829 XSetBevelColor(display,window_info,!triangle_info->raised);
830 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
831 points,4,Complex,CoordModeOrigin);
839 points[2].x=x1-bevel_width;
840 points[2].y=y1+bevel_width;
841 points[3].x=x3+bevel_width;
842 points[3].y=y3+bevel_width;
843 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
844 points,4,Complex,CoordModeOrigin);
845 (void) XSetFillStyle(display,window_info->widget_context,FillSolid);
849 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
853 + X D r a w T r i a n g l e S o u t h %
857 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
859 % XDrawTriangleSouth() draws a border with a highlighted left and right bevel
860 % and a shadowed lower bevel. The highlighted and shadowed bevels create a
863 % The format of the XDrawTriangleSouth function is:
865 % XDrawTriangleSouth(display,window_info,triangle_info)
867 % A description of each parameter follows:
869 % o display: Specifies a pointer to the Display structure; returned from
872 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
874 % o triangle_info: Specifies a pointer to a XWidgetInfo structure. It
875 % contains the extents of the triangle.
878 static void XDrawTriangleSouth(Display *display,const XWindowInfo *window_info,
879 const XWidgetInfo *triangle_info)
900 x2=triangle_info->x+(triangle_info->width >> 1);
901 y2=triangle_info->y+triangle_info->height;
902 x3=triangle_info->x+triangle_info->width;
904 bevel_width=triangle_info->bevel_width;
911 XSetMatteColor(display,window_info,triangle_info->raised);
912 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
913 points,3,Complex,CoordModeOrigin);
921 points[2].x=x1-bevel_width;
922 points[2].y=y1-bevel_width;
923 points[3].x=x3+bevel_width;
924 points[3].y=y3-bevel_width;
925 XSetBevelColor(display,window_info,triangle_info->raised);
926 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
927 points,4,Complex,CoordModeOrigin);
934 points[1].y=y3-bevel_width;
935 points[2].x=x3+bevel_width;
936 points[2].y=y3-bevel_width;
938 points[3].y=y2+bevel_width;
939 XSetBevelColor(display,window_info,!triangle_info->raised);
940 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
941 points,4,Complex,CoordModeOrigin);
950 points[2].y=y2+bevel_width;
951 points[3].x=x1-bevel_width;
952 points[3].y=y1-bevel_width;
953 XSetBevelColor(display,window_info,triangle_info->raised);
954 (void) XFillPolygon(display,window_info->id,window_info->widget_context,
955 points,4,Complex,CoordModeOrigin);
956 (void) XSetFillStyle(display,window_info->widget_context,FillSolid);
960 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
964 + X D r a w W i d g e t T e x t %
968 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
970 % XDrawWidgetText() first clears the widget and draws a text string justifed
971 % left (or center) in the x-direction and centered within the y-direction.
973 % The format of the XDrawWidgetText function is:
975 % XDrawWidgetText(display,window_info,text_info)
977 % A description of each parameter follows:
979 % o display: Specifies a pointer to the Display structure; returned from
982 % o window_info: Specifies a pointer to a XWindowText structure.
984 % o text_info: Specifies a pointer to XWidgetInfo structure.
987 static void XDrawWidgetText(Display *display,const XWindowInfo *window_info,
988 XWidgetInfo *text_info)
1008 Clear the text area.
1010 widget_context=window_info->annotate_context;
1011 if (text_info->raised)
1012 (void) XClearArea(display,window_info->id,text_info->x,text_info->y,
1013 text_info->width,text_info->height,MagickFalse);
1016 (void) XFillRectangle(display,window_info->id,widget_context,text_info->x,
1017 text_info->y,text_info->width,text_info->height);
1018 widget_context=window_info->highlight_context;
1020 if (text_info->text == (char *) NULL)
1022 if (*text_info->text == '\0')
1025 Set cropping region.
1027 font_info=window_info->font_info;
1028 crop_info.width=(unsigned short) text_info->width;
1029 crop_info.height=(unsigned short) text_info->height;
1030 crop_info.x=text_info->x;
1031 crop_info.y=text_info->y;
1035 width=WidgetTextWidth(font_info,text_info->text);
1036 x=text_info->x+(QuantumMargin >> 1);
1037 if (text_info->center)
1038 x=text_info->x+(text_info->width >> 1)-(width >> 1);
1039 if (text_info->raised)
1040 if (width > (text_info->width-QuantumMargin))
1041 x+=(text_info->width-QuantumMargin-width);
1042 height=(unsigned int) (font_info->ascent+font_info->descent);
1043 y=text_info->y+((text_info->height-height) >> 1)+font_info->ascent;
1044 (void) XSetClipRectangles(display,widget_context,0,0,&crop_info,1,Unsorted);
1045 (void) XDrawString(display,window_info->id,widget_context,x,y,text_info->text,
1046 Extent(text_info->text));
1047 (void) XSetClipMask(display,widget_context,None);
1048 if (x < text_info->x)
1049 (void) XDrawLine(display,window_info->id,window_info->annotate_context,
1050 text_info->x,text_info->y,text_info->x,text_info->y+text_info->height-1);
1054 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1058 + X E d i t T e x t %
1062 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1064 % XEditText() edits a text string as indicated by the key symbol.
1066 % The format of the XEditText function is:
1068 % XEditText(display,text_info,key_symbol,text,state)
1070 % A description of each parameter follows:
1072 % o display: Specifies a connection to an X server; returned from
1075 % o text_info: Specifies a pointer to a XWidgetInfo structure. It
1076 % contains the extents of the text.
1078 % o key_symbol: A X11 KeySym that indicates what editing function to
1079 % perform to the text.
1081 % o text: A character string to insert into the text.
1083 % o state: An size_t that indicates whether the key symbol is a
1084 % control character or not.
1087 static void XEditText(Display *display,XWidgetInfo *text_info,
1088 const KeySym key_symbol,char *text,const size_t state)
1090 switch ((int) key_symbol)
1095 if (text_info->highlight)
1098 Erase the entire line of text.
1100 *text_info->text='\0';
1101 text_info->cursor=text_info->text;
1102 text_info->marker=text_info->text;
1103 text_info->highlight=MagickFalse;
1106 Erase one character.
1108 if (text_info->cursor != text_info->text)
1110 text_info->cursor--;
1111 (void) CopyMagickString(text_info->cursor,text_info->cursor+1,
1113 text_info->highlight=MagickFalse;
1121 Move cursor one position left.
1123 if (text_info->cursor == text_info->text)
1125 text_info->cursor--;
1132 Move cursor one position right.
1134 if (text_info->cursor == (text_info->text+Extent(text_info->text)))
1136 text_info->cursor++;
1148 if (state & ControlState)
1152 if ((Extent(text_info->text)+1) >= (int) MagickPathExtent)
1153 (void) XBell(display,0);
1156 if (text_info->highlight)
1159 Erase the entire line of text.
1161 *text_info->text='\0';
1162 text_info->cursor=text_info->text;
1163 text_info->marker=text_info->text;
1164 text_info->highlight=MagickFalse;
1167 Insert a string into the text.
1169 q=text_info->text+Extent(text_info->text)+strlen(text);
1170 for (i=0; i <= Extent(text_info->cursor); i++)
1172 *q=(*(q-Extent(text)));
1176 for (i=0; i < Extent(text); i++)
1177 *text_info->cursor++=(*p++);
1185 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1189 + X G e t W i d g e t I n f o %
1193 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1195 % XGetWidgetInfo() initializes the XWidgetInfo structure.
1197 % The format of the XGetWidgetInfo function is:
1199 % XGetWidgetInfo(text,widget_info)
1201 % A description of each parameter follows:
1203 % o text: A string of characters associated with the widget.
1205 % o widget_info: Specifies a pointer to a X11 XWidgetInfo structure.
1208 static void XGetWidgetInfo(const char *text,XWidgetInfo *widget_info)
1211 Initialize widget info.
1213 widget_info->id=(~0);
1214 widget_info->bevel_width=3;
1215 widget_info->width=1;
1216 widget_info->height=1;
1219 widget_info->min_y=0;
1220 widget_info->max_y=0;
1221 widget_info->raised=MagickTrue;
1222 widget_info->active=MagickFalse;
1223 widget_info->center=MagickTrue;
1224 widget_info->trough=MagickFalse;
1225 widget_info->highlight=MagickFalse;
1226 widget_info->text=(char *) text;
1227 widget_info->cursor=(char *) text;
1228 if (text != (char *) NULL)
1229 widget_info->cursor+=Extent(text);
1230 widget_info->marker=(char *) text;
1234 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1238 + X H i g h l i g h t W i d g e t %
1242 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1244 % XHighlightWidget() draws a highlighted border around a window.
1246 % The format of the XHighlightWidget function is:
1248 % XHighlightWidget(display,window_info,x,y)
1250 % A description of each parameter follows:
1252 % o display: Specifies a pointer to the Display structure; returned from
1255 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
1257 % o x: Specifies an integer representing the rectangle offset in the
1260 % o y: Specifies an integer representing the rectangle offset in the
1264 static void XHighlightWidget(Display *display,const XWindowInfo *window_info,
1265 const int x,const int y)
1268 Draw the widget highlighting rectangle.
1270 XSetBevelColor(display,window_info,MagickTrue);
1271 (void) XDrawRectangle(display,window_info->id,window_info->widget_context,x,y,
1272 window_info->width-(x << 1),window_info->height-(y << 1));
1273 (void) XDrawRectangle(display,window_info->id,window_info->widget_context,
1274 x-1,y-1,window_info->width-(x << 1)+1,window_info->height-(y << 1)+1);
1275 XSetBevelColor(display,window_info,MagickFalse);
1276 (void) XDrawRectangle(display,window_info->id,window_info->widget_context,
1277 x-1,y-1,window_info->width-(x << 1),window_info->height-(y << 1));
1278 (void) XSetFillStyle(display,window_info->widget_context,FillSolid);
1282 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1286 + X S c r e e n E v e n t %
1290 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1292 % XScreenEvent() returns MagickTrue if the any event on the X server queue is
1293 % associated with the widget window.
1295 % The format of the XScreenEvent function is:
1297 % int XScreenEvent(Display *display,XEvent *event,char *data)
1299 % A description of each parameter follows:
1301 % o display: Specifies a pointer to the Display structure; returned from
1304 % o event: Specifies a pointer to a X11 XEvent structure.
1306 % o data: Specifies a pointer to a XWindows structure.
1310 #if defined(__cplusplus) || defined(c_plusplus)
1314 static int XScreenEvent(Display *display,XEvent *event,char *data)
1319 windows=(XWindows *) data;
1320 if (event->xany.window == windows->popup.id)
1322 if (event->type == MapNotify)
1323 windows->popup.mapped=MagickTrue;
1324 if (event->type == UnmapNotify)
1325 windows->popup.mapped=MagickFalse;
1328 if (event->xany.window == windows->widget.id)
1330 if (event->type == MapNotify)
1331 windows->widget.mapped=MagickTrue;
1332 if (event->type == UnmapNotify)
1333 windows->widget.mapped=MagickFalse;
1336 switch (event->type)
1340 if ((event->xbutton.button == Button3) &&
1341 (event->xbutton.state & Mod1Mask))
1344 Convert Alt-Button3 to Button2.
1346 event->xbutton.button=Button2;
1347 event->xbutton.state&=(~Mod1Mask);
1353 if (event->xexpose.window == windows->image.id)
1355 XRefreshWindow(display,&windows->image,event);
1358 if (event->xexpose.window == windows->magnify.id)
1359 if (event->xexpose.count == 0)
1360 if (windows->magnify.mapped)
1365 exception=AcquireExceptionInfo();
1366 XMakeMagnifyImage(display,windows,exception);
1367 exception=DestroyExceptionInfo(exception);
1370 if (event->xexpose.window == windows->command.id)
1371 if (event->xexpose.count == 0)
1373 (void) XCommandWidget(display,windows,(const char **) NULL,event);
1381 Set input focus for backdrop window.
1383 if (event->xfocus.window == windows->image.id)
1384 (void) XSetInputFocus(display,windows->image.id,RevertToNone,
1392 case SelectionNotify:
1397 return(MagickFalse);
1400 #if defined(__cplusplus) || defined(c_plusplus)
1405 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1409 + X S e t B e v e l C o l o r %
1413 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1415 % XSetBevelColor() sets the graphic context for drawing a beveled border.
1417 % The format of the XSetBevelColor function is:
1419 % XSetBevelColor(display,window_info,raised)
1421 % A description of each parameter follows:
1423 % o display: Specifies a pointer to the Display structure; returned from
1426 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
1428 % o raised: A value other than zero indicates the color show be a
1429 % "highlight" color, otherwise the "shadow" color is set.
1432 static void XSetBevelColor(Display *display,const XWindowInfo *window_info,
1433 const MagickStatusType raised)
1435 if (window_info->depth == 1)
1443 (void) XSetBackground(display,window_info->widget_context,
1444 XBlackPixel(display,window_info->screen));
1445 (void) XSetForeground(display,window_info->widget_context,
1446 XWhitePixel(display,window_info->screen));
1447 (void) XSetFillStyle(display,window_info->widget_context,
1448 FillOpaqueStippled);
1449 stipple=window_info->highlight_stipple;
1450 if (raised == MagickFalse)
1451 stipple=window_info->shadow_stipple;
1452 (void) XSetStipple(display,window_info->widget_context,stipple);
1456 (void) XSetForeground(display,window_info->widget_context,
1457 window_info->pixel_info->highlight_color.pixel);
1459 (void) XSetForeground(display,window_info->widget_context,
1460 window_info->pixel_info->shadow_color.pixel);
1464 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1468 + X S e t M a t t e C o l o r %
1472 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1474 % XSetMatteColor() sets the graphic context for drawing the matte.
1476 % The format of the XSetMatteColor function is:
1478 % XSetMatteColor(display,window_info,raised)
1480 % A description of each parameter follows:
1482 % o display: Specifies a pointer to the Display structure; returned from
1485 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
1487 % o raised: A value other than zero indicates the matte is active.
1490 static void XSetMatteColor(Display *display,const XWindowInfo *window_info,
1491 const MagickStatusType raised)
1493 if (window_info->depth == 1)
1499 (void) XSetForeground(display,window_info->widget_context,
1500 XWhitePixel(display,window_info->screen));
1502 (void) XSetForeground(display,window_info->widget_context,
1503 XBlackPixel(display,window_info->screen));
1507 (void) XSetForeground(display,window_info->widget_context,
1508 window_info->pixel_info->matte_color.pixel);
1510 (void) XSetForeground(display,window_info->widget_context,
1511 window_info->pixel_info->depth_color.pixel);
1515 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1519 + X S e t T e x t C o l o r %
1523 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1525 % XSetTextColor() sets the graphic context for drawing text on a matte.
1527 % The format of the XSetTextColor function is:
1529 % XSetTextColor(display,window_info,raised)
1531 % A description of each parameter follows:
1533 % o display: Specifies a pointer to the Display structure; returned from
1536 % o window_info: Specifies a pointer to a X11 XWindowInfo structure.
1538 % o raised: A value other than zero indicates the color show be a
1539 % "highlight" color, otherwise the "shadow" color is set.
1542 static void XSetTextColor(Display *display,const XWindowInfo *window_info,
1543 const MagickStatusType raised)
1549 if (window_info->depth == 1)
1555 (void) XSetForeground(display,window_info->widget_context,
1556 XBlackPixel(display,window_info->screen));
1558 (void) XSetForeground(display,window_info->widget_context,
1559 XWhitePixel(display,window_info->screen));
1562 foreground=(ssize_t) XPixelIntensity(
1563 &window_info->pixel_info->foreground_color);
1564 matte=(ssize_t) XPixelIntensity(&window_info->pixel_info->matte_color);
1565 if (MagickAbsoluteValue((int) (foreground-matte)) > (65535L >> 3))
1566 (void) XSetForeground(display,window_info->widget_context,
1567 window_info->pixel_info->foreground_color.pixel);
1569 (void) XSetForeground(display,window_info->widget_context,
1570 window_info->pixel_info->background_color.pixel);
1574 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1578 % X C o l o r B r o w s e r W i d g e t %
1582 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1584 % XColorBrowserWidget() displays a Color Browser widget with a color query
1585 % to the user. The user keys a reply and presses the Action or Cancel button
1586 % to exit. The typed text is returned as the reply function parameter.
1588 % The format of the XColorBrowserWidget method is:
1590 % void XColorBrowserWidget(Display *display,XWindows *windows,
1591 % const char *action,char *reply)
1593 % A description of each parameter follows:
1595 % o display: Specifies a connection to an X server; returned from
1598 % o window: Specifies a pointer to a XWindows structure.
1600 % o action: Specifies a pointer to the action of this widget.
1602 % o reply: the response from the user is returned in this parameter.
1605 MagickPrivate void XColorBrowserWidget(Display *display,XWindows *windows,
1606 const char *action,char *reply)
1608 #define CancelButtonText "Cancel"
1609 #define ColornameText "Name:"
1610 #define ColorPatternText "Pattern:"
1611 #define GrabButtonText "Grab"
1612 #define ResetButtonText "Reset"
1616 primary_selection[MagickPathExtent],
1617 reset_pattern[MagickPathExtent],
1618 text[MagickPathExtent];
1631 glob_pattern[MagickPathExtent] = "*";
1633 static MagickStatusType
1634 mask = (MagickStatusType) (CWWidth | CWHeight | CWX | CWY);
1682 Get color list and sort in ascending order.
1684 assert(display != (Display *) NULL);
1685 assert(windows != (XWindows *) NULL);
1686 assert(action != (char *) NULL);
1687 assert(reply != (char *) NULL);
1688 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",action);
1689 XSetCursorState(display,windows,MagickTrue);
1690 XCheckRefreshWindows(display,windows);
1691 (void) CopyMagickString(reset_pattern,"*",MagickPathExtent);
1692 exception=AcquireExceptionInfo();
1693 colorlist=GetColorList(glob_pattern,&colors,exception);
1694 if (colorlist == (char **) NULL)
1697 Pattern failed, obtain all the colors.
1699 (void) CopyMagickString(glob_pattern,"*",MagickPathExtent);
1700 colorlist=GetColorList(glob_pattern,&colors,exception);
1701 if (colorlist == (char **) NULL)
1703 XNoticeWidget(display,windows,"Unable to obtain colors names:",
1705 (void) XDialogWidget(display,windows,action,"Enter color name:",
1711 Determine Color Browser widget attributes.
1713 font_info=windows->widget.font_info;
1715 for (i=0; i < (int) colors; i++)
1716 if (WidgetTextWidth(font_info,colorlist[i]) > text_width)
1717 text_width=WidgetTextWidth(font_info,colorlist[i]);
1718 width=WidgetTextWidth(font_info,(char *) action);
1719 if (WidgetTextWidth(font_info,CancelButtonText) > width)
1720 width=WidgetTextWidth(font_info,CancelButtonText);
1721 if (WidgetTextWidth(font_info,ResetButtonText) > width)
1722 width=WidgetTextWidth(font_info,ResetButtonText);
1723 if (WidgetTextWidth(font_info,GrabButtonText) > width)
1724 width=WidgetTextWidth(font_info,GrabButtonText);
1725 width+=QuantumMargin;
1726 if (WidgetTextWidth(font_info,ColorPatternText) > width)
1727 width=WidgetTextWidth(font_info,ColorPatternText);
1728 if (WidgetTextWidth(font_info,ColornameText) > width)
1729 width=WidgetTextWidth(font_info,ColornameText);
1730 height=(unsigned int) (font_info->ascent+font_info->descent);
1732 Position Color Browser widget.
1734 windows->widget.width=(unsigned int)
1735 (width+MagickMin((int) text_width,(int) MaxTextWidth)+6*QuantumMargin);
1736 windows->widget.min_width=(unsigned int)
1737 (width+MinTextWidth+4*QuantumMargin);
1738 if (windows->widget.width < windows->widget.min_width)
1739 windows->widget.width=windows->widget.min_width;
1740 windows->widget.height=(unsigned int)
1741 ((81*height) >> 2)+((13*QuantumMargin) >> 1)+4;
1742 windows->widget.min_height=(unsigned int)
1743 (((23*height) >> 1)+((13*QuantumMargin) >> 1)+4);
1744 if (windows->widget.height < windows->widget.min_height)
1745 windows->widget.height=windows->widget.min_height;
1746 XConstrainWindowPosition(display,&windows->widget);
1748 Map Color Browser widget.
1750 (void) CopyMagickString(windows->widget.name,"Browse and Select a Color",
1752 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
1753 if (status != False)
1755 XSetWMName(display,windows->widget.id,&window_name);
1756 XSetWMIconName(display,windows->widget.id,&window_name);
1757 (void) XFree((void *) window_name.value);
1759 window_changes.width=(int) windows->widget.width;
1760 window_changes.height=(int) windows->widget.height;
1761 window_changes.x=windows->widget.x;
1762 window_changes.y=windows->widget.y;
1763 (void) XReconfigureWMWindow(display,windows->widget.id,windows->widget.screen,
1764 mask,&window_changes);
1765 (void) XMapRaised(display,windows->widget.id);
1766 windows->widget.mapped=MagickFalse;
1768 Respond to X events.
1770 XGetWidgetInfo((char *) NULL,&mode_info);
1771 XGetWidgetInfo((char *) NULL,&slider_info);
1772 XGetWidgetInfo((char *) NULL,&north_info);
1773 XGetWidgetInfo((char *) NULL,&south_info);
1774 XGetWidgetInfo((char *) NULL,&expose_info);
1775 XGetWidgetInfo((char *) NULL,&selection_info);
1777 delay=SuspendTime << 2;
1778 state=UpdateConfigurationState;
1781 if (state & UpdateConfigurationState)
1787 Initialize button information.
1789 XGetWidgetInfo(CancelButtonText,&cancel_info);
1790 cancel_info.width=width;
1791 cancel_info.height=(unsigned int) ((3*height) >> 1);
1793 (windows->widget.width-cancel_info.width-QuantumMargin-2);
1795 (windows->widget.height-cancel_info.height-QuantumMargin);
1796 XGetWidgetInfo(action,&action_info);
1797 action_info.width=width;
1798 action_info.height=(unsigned int) ((3*height) >> 1);
1799 action_info.x=cancel_info.x-(cancel_info.width+(QuantumMargin >> 1)+
1800 (action_info.bevel_width << 1));
1801 action_info.y=cancel_info.y;
1802 XGetWidgetInfo(GrabButtonText,&grab_info);
1803 grab_info.width=width;
1804 grab_info.height=(unsigned int) ((3*height) >> 1);
1805 grab_info.x=QuantumMargin;
1806 grab_info.y=((5*QuantumMargin) >> 1)+height;
1807 XGetWidgetInfo(ResetButtonText,&reset_info);
1808 reset_info.width=width;
1809 reset_info.height=(unsigned int) ((3*height) >> 1);
1810 reset_info.x=QuantumMargin;
1811 reset_info.y=grab_info.y+grab_info.height+QuantumMargin;
1813 Initialize reply information.
1815 XGetWidgetInfo(reply,&reply_info);
1816 reply_info.raised=MagickFalse;
1817 reply_info.bevel_width--;
1818 reply_info.width=windows->widget.width-width-((6*QuantumMargin) >> 1);
1819 reply_info.height=height << 1;
1820 reply_info.x=(int) (width+(QuantumMargin << 1));
1821 reply_info.y=action_info.y-reply_info.height-QuantumMargin;
1823 Initialize mode information.
1825 XGetWidgetInfo((char *) NULL,&mode_info);
1826 mode_info.active=MagickTrue;
1827 mode_info.bevel_width=0;
1828 mode_info.width=(unsigned int) (action_info.x-(QuantumMargin << 1));
1829 mode_info.height=action_info.height;
1830 mode_info.x=QuantumMargin;
1831 mode_info.y=action_info.y;
1833 Initialize scroll information.
1835 XGetWidgetInfo((char *) NULL,&scroll_info);
1836 scroll_info.bevel_width--;
1837 scroll_info.width=height;
1838 scroll_info.height=(unsigned int) (reply_info.y-grab_info.y-
1839 (QuantumMargin >> 1));
1840 scroll_info.x=reply_info.x+(reply_info.width-scroll_info.width);
1841 scroll_info.y=grab_info.y-reply_info.bevel_width;
1842 scroll_info.raised=MagickFalse;
1843 scroll_info.trough=MagickTrue;
1844 north_info=scroll_info;
1845 north_info.raised=MagickTrue;
1846 north_info.width-=(north_info.bevel_width << 1);
1847 north_info.height=north_info.width-1;
1848 north_info.x+=north_info.bevel_width;
1849 north_info.y+=north_info.bevel_width;
1850 south_info=north_info;
1851 south_info.y=scroll_info.y+scroll_info.height-scroll_info.bevel_width-
1854 slider_info=north_info;
1856 slider_info.width-=2;
1857 slider_info.min_y=north_info.y+north_info.height+north_info.bevel_width+
1858 slider_info.bevel_width+2;
1859 slider_info.height=scroll_info.height-((slider_info.min_y-
1860 scroll_info.y+1) << 1)+4;
1861 visible_colors=scroll_info.height/(height+(height >> 3));
1862 if (colors > visible_colors)
1863 slider_info.height=(unsigned int)
1864 ((visible_colors*slider_info.height)/colors);
1865 slider_info.max_y=south_info.y-south_info.bevel_width-
1866 slider_info.bevel_width-2;
1867 slider_info.x=scroll_info.x+slider_info.bevel_width+1;
1868 slider_info.y=slider_info.min_y;
1869 expose_info=scroll_info;
1870 expose_info.y=slider_info.y;
1872 Initialize list information.
1874 XGetWidgetInfo((char *) NULL,&list_info);
1875 list_info.raised=MagickFalse;
1876 list_info.bevel_width--;
1877 list_info.width=(unsigned int)
1878 (scroll_info.x-reply_info.x-(QuantumMargin >> 1));
1879 list_info.height=scroll_info.height;
1880 list_info.x=reply_info.x;
1881 list_info.y=scroll_info.y;
1882 if (windows->widget.mapped == MagickFalse)
1883 state|=JumpListState;
1885 Initialize text information.
1888 XGetWidgetInfo(text,&text_info);
1889 text_info.center=MagickFalse;
1890 text_info.width=reply_info.width;
1891 text_info.height=height;
1892 text_info.x=list_info.x-(QuantumMargin >> 1);
1893 text_info.y=QuantumMargin;
1895 Initialize selection information.
1897 XGetWidgetInfo((char *) NULL,&selection_info);
1898 selection_info.center=MagickFalse;
1899 selection_info.width=list_info.width;
1900 selection_info.height=(unsigned int) ((9*height) >> 3);
1901 selection_info.x=list_info.x;
1902 state&=(~UpdateConfigurationState);
1904 if (state & RedrawWidgetState)
1907 Redraw Color Browser window.
1910 y=text_info.y+((text_info.height-height) >> 1)+font_info->ascent;
1911 (void) XDrawString(display,windows->widget.id,
1912 windows->widget.annotate_context,x,y,ColorPatternText,
1913 Extent(ColorPatternText));
1914 (void) CopyMagickString(text_info.text,glob_pattern,MagickPathExtent);
1915 XDrawWidgetText(display,&windows->widget,&text_info);
1916 XDrawBeveledButton(display,&windows->widget,&grab_info);
1917 XDrawBeveledButton(display,&windows->widget,&reset_info);
1918 XDrawBeveledMatte(display,&windows->widget,&list_info);
1919 XDrawBeveledMatte(display,&windows->widget,&scroll_info);
1920 XDrawTriangleNorth(display,&windows->widget,&north_info);
1921 XDrawBeveledButton(display,&windows->widget,&slider_info);
1922 XDrawTriangleSouth(display,&windows->widget,&south_info);
1924 y=reply_info.y+((reply_info.height-height) >> 1)+font_info->ascent;
1925 (void) XDrawString(display,windows->widget.id,
1926 windows->widget.annotate_context,x,y,ColornameText,
1927 Extent(ColornameText));
1928 XDrawBeveledMatte(display,&windows->widget,&reply_info);
1929 XDrawMatteText(display,&windows->widget,&reply_info);
1930 XDrawBeveledButton(display,&windows->widget,&action_info);
1931 XDrawBeveledButton(display,&windows->widget,&cancel_info);
1932 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
1933 selection_info.id=(~0);
1934 state|=RedrawActionState;
1935 state|=RedrawListState;
1936 state&=(~RedrawWidgetState);
1938 if (state & UpdateListState)
1946 status=XParseColor(display,windows->widget.map_info->colormap,
1947 glob_pattern,&color);
1948 if ((status != False) || (strchr(glob_pattern,'-') != (char *) NULL))
1951 Reply is a single color name-- exit.
1953 (void) CopyMagickString(reply,glob_pattern,MagickPathExtent);
1954 (void) CopyMagickString(glob_pattern,reset_pattern,MagickPathExtent);
1955 action_info.raised=MagickFalse;
1956 XDrawBeveledButton(display,&windows->widget,&action_info);
1962 checklist=GetColorList(glob_pattern,&number_colors,exception);
1963 if (number_colors == 0)
1965 (void) CopyMagickString(glob_pattern,reset_pattern,MagickPathExtent);
1966 (void) XBell(display,0);
1970 for (i=0; i < (int) colors; i++)
1971 colorlist[i]=DestroyString(colorlist[i]);
1972 if (colorlist != (char **) NULL)
1973 colorlist=(char **) RelinquishMagickMemory(colorlist);
1974 colorlist=checklist;
1975 colors=number_colors;
1978 Sort color list in ascending order.
1981 scroll_info.height-((slider_info.min_y-scroll_info.y+1) << 1)+1;
1982 if (colors > visible_colors)
1983 slider_info.height=(unsigned int)
1984 ((visible_colors*slider_info.height)/colors);
1985 slider_info.max_y=south_info.y-south_info.bevel_width-
1986 slider_info.bevel_width-2;
1988 slider_info.y=slider_info.min_y;
1989 expose_info.y=slider_info.y;
1990 selection_info.id=(~0);
1992 state|=RedrawListState;
1994 Redraw color name & reply.
1996 *reply_info.text='\0';
1997 reply_info.cursor=reply_info.text;
1998 (void) CopyMagickString(text_info.text,glob_pattern,MagickPathExtent);
1999 XDrawWidgetText(display,&windows->widget,&text_info);
2000 XDrawMatteText(display,&windows->widget,&reply_info);
2001 XDrawBeveledMatte(display,&windows->widget,&scroll_info);
2002 XDrawTriangleNorth(display,&windows->widget,&north_info);
2003 XDrawBeveledButton(display,&windows->widget,&slider_info);
2004 XDrawTriangleSouth(display,&windows->widget,&south_info);
2005 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
2006 state&=(~UpdateListState);
2008 if (state & JumpListState)
2011 Jump scroll to match user color.
2014 for (i=0; i < (int) colors; i++)
2015 if (LocaleCompare(colorlist[i],reply) >= 0)
2017 list_info.id=LocaleCompare(colorlist[i],reply) == 0 ? i : ~0;
2020 if ((i < slider_info.id) ||
2021 (i >= (int) (slider_info.id+visible_colors)))
2022 slider_info.id=i-(visible_colors >> 1);
2023 selection_info.id=(~0);
2024 state|=RedrawListState;
2025 state&=(~JumpListState);
2027 if (state & RedrawListState)
2030 Determine slider id and position.
2032 if (slider_info.id >= (int) (colors-visible_colors))
2033 slider_info.id=(int) (colors-visible_colors);
2034 if ((slider_info.id < 0) || (colors <= visible_colors))
2036 slider_info.y=slider_info.min_y;
2038 slider_info.y+=(int) (slider_info.id*(slider_info.max_y-
2039 slider_info.min_y+1)/colors);
2040 if (slider_info.id != selection_info.id)
2043 Redraw scroll bar and file names.
2045 selection_info.id=slider_info.id;
2046 selection_info.y=list_info.y+(height >> 3)+2;
2047 for (i=0; i < (int) visible_colors; i++)
2049 selection_info.raised=(slider_info.id+i) != list_info.id ?
2050 MagickTrue : MagickFalse;
2051 selection_info.text=(char *) NULL;
2052 if ((slider_info.id+i) < (int) colors)
2053 selection_info.text=colorlist[slider_info.id+i];
2054 XDrawWidgetText(display,&windows->widget,&selection_info);
2055 selection_info.y+=(int) selection_info.height;
2060 if (slider_info.y > expose_info.y)
2062 expose_info.height=(unsigned int) slider_info.y-expose_info.y;
2063 expose_info.y=slider_info.y-expose_info.height-
2064 slider_info.bevel_width-1;
2068 expose_info.height=(unsigned int) expose_info.y-slider_info.y;
2069 expose_info.y=slider_info.y+slider_info.height+
2070 slider_info.bevel_width+1;
2072 XDrawTriangleNorth(display,&windows->widget,&north_info);
2073 XDrawMatte(display,&windows->widget,&expose_info);
2074 XDrawBeveledButton(display,&windows->widget,&slider_info);
2075 XDrawTriangleSouth(display,&windows->widget,&south_info);
2076 expose_info.y=slider_info.y;
2078 state&=(~RedrawListState);
2080 if (state & RedrawActionState)
2083 colorname[MagickPathExtent];
2086 Display the selected color in a drawing area.
2088 color=windows->widget.pixel_info->matte_color;
2089 (void) XParseColor(display,windows->widget.map_info->colormap,
2090 reply_info.text,&windows->widget.pixel_info->matte_color);
2091 XBestPixel(display,windows->widget.map_info->colormap,(XColor *) NULL,
2092 (unsigned int) windows->widget.visual_info->colormap_size,
2093 &windows->widget.pixel_info->matte_color);
2094 mode_info.text=colorname;
2095 (void) FormatLocaleString(mode_info.text,MagickPathExtent,"#%02x%02x%02x",
2096 windows->widget.pixel_info->matte_color.red,
2097 windows->widget.pixel_info->matte_color.green,
2098 windows->widget.pixel_info->matte_color.blue);
2099 XDrawBeveledButton(display,&windows->widget,&mode_info);
2100 windows->widget.pixel_info->matte_color=color;
2101 state&=(~RedrawActionState);
2104 Wait for next event.
2106 if (north_info.raised && south_info.raised)
2107 (void) XIfEvent(display,&event,XScreenEvent,(char *) windows);
2111 Brief delay before advancing scroll bar.
2113 XDelay(display,delay);
2115 (void) XCheckIfEvent(display,&event,XScreenEvent,(char *) windows);
2116 if (north_info.raised == MagickFalse)
2117 if (slider_info.id > 0)
2123 state|=RedrawListState;
2125 if (south_info.raised == MagickFalse)
2126 if (slider_info.id < (int) colors)
2132 state|=RedrawListState;
2134 if (event.type != ButtonRelease)
2141 if (MatteIsActive(slider_info,event.xbutton))
2146 slider_info.active=MagickTrue;
2149 if (MatteIsActive(north_info,event.xbutton))
2150 if (slider_info.id > 0)
2155 north_info.raised=MagickFalse;
2157 state|=RedrawListState;
2160 if (MatteIsActive(south_info,event.xbutton))
2161 if (slider_info.id < (int) colors)
2166 south_info.raised=MagickFalse;
2168 state|=RedrawListState;
2171 if (MatteIsActive(scroll_info,event.xbutton))
2176 if (event.xbutton.y < slider_info.y)
2177 slider_info.id-=(visible_colors-1);
2179 slider_info.id+=(visible_colors-1);
2180 state|=RedrawListState;
2183 if (MatteIsActive(list_info,event.xbutton))
2189 User pressed list matte.
2191 id=slider_info.id+(event.xbutton.y-(list_info.y+(height >> 1))+1)/
2192 selection_info.height;
2193 if (id >= (int) colors)
2195 (void) CopyMagickString(reply_info.text,colorlist[id],
2197 reply_info.highlight=MagickFalse;
2198 reply_info.marker=reply_info.text;
2199 reply_info.cursor=reply_info.text+Extent(reply_info.text);
2200 XDrawMatteText(display,&windows->widget,&reply_info);
2201 state|=RedrawActionState;
2202 if (id == list_info.id)
2204 (void) CopyMagickString(glob_pattern,reply_info.text,
2206 state|=UpdateListState;
2208 selection_info.id=(~0);
2210 state|=RedrawListState;
2213 if (MatteIsActive(grab_info,event.xbutton))
2216 User pressed Grab button.
2218 grab_info.raised=MagickFalse;
2219 XDrawBeveledButton(display,&windows->widget,&grab_info);
2222 if (MatteIsActive(reset_info,event.xbutton))
2225 User pressed Reset button.
2227 reset_info.raised=MagickFalse;
2228 XDrawBeveledButton(display,&windows->widget,&reset_info);
2231 if (MatteIsActive(mode_info,event.xbutton))
2234 User pressed mode button.
2236 if (mode_info.text != (char *) NULL)
2237 (void) CopyMagickString(reply_info.text,mode_info.text,
2239 (void) CopyMagickString(primary_selection,reply_info.text,
2241 (void) XSetSelectionOwner(display,XA_PRIMARY,windows->widget.id,
2242 event.xbutton.time);
2243 reply_info.highlight=XGetSelectionOwner(display,XA_PRIMARY) ==
2244 windows->widget.id ? MagickTrue : MagickFalse;
2245 reply_info.marker=reply_info.text;
2246 reply_info.cursor=reply_info.text+Extent(reply_info.text);
2247 XDrawMatteText(display,&windows->widget,&reply_info);
2250 if (MatteIsActive(action_info,event.xbutton))
2253 User pressed action button.
2255 action_info.raised=MagickFalse;
2256 XDrawBeveledButton(display,&windows->widget,&action_info);
2259 if (MatteIsActive(cancel_info,event.xbutton))
2262 User pressed Cancel button.
2264 cancel_info.raised=MagickFalse;
2265 XDrawBeveledButton(display,&windows->widget,&cancel_info);
2268 if (MatteIsActive(reply_info,event.xbutton) == MagickFalse)
2270 if (event.xbutton.button != Button2)
2276 Move text cursor to position of button press.
2278 x=event.xbutton.x-reply_info.x-(QuantumMargin >> 2);
2279 for (i=1; i <= Extent(reply_info.marker); i++)
2280 if (XTextWidth(font_info,reply_info.marker,i) > x)
2282 reply_info.cursor=reply_info.marker+i-1;
2283 if (event.xbutton.time > (click_time+DoubleClick))
2284 reply_info.highlight=MagickFalse;
2288 Become the XA_PRIMARY selection owner.
2290 (void) CopyMagickString(primary_selection,reply_info.text,
2292 (void) XSetSelectionOwner(display,XA_PRIMARY,windows->widget.id,
2293 event.xbutton.time);
2294 reply_info.highlight=XGetSelectionOwner(display,XA_PRIMARY) ==
2295 windows->widget.id ? MagickTrue : MagickFalse;
2297 XDrawMatteText(display,&windows->widget,&reply_info);
2298 click_time=event.xbutton.time;
2302 Request primary selection.
2304 (void) XConvertSelection(display,XA_PRIMARY,XA_STRING,XA_STRING,
2305 windows->widget.id,event.xbutton.time);
2310 if (windows->widget.mapped == MagickFalse)
2312 if (north_info.raised == MagickFalse)
2315 User released up button.
2317 delay=SuspendTime << 2;
2318 north_info.raised=MagickTrue;
2319 XDrawTriangleNorth(display,&windows->widget,&north_info);
2321 if (south_info.raised == MagickFalse)
2324 User released down button.
2326 delay=SuspendTime << 2;
2327 south_info.raised=MagickTrue;
2328 XDrawTriangleSouth(display,&windows->widget,&south_info);
2330 if (slider_info.active)
2333 Stop tracking slider.
2335 slider_info.active=MagickFalse;
2338 if (grab_info.raised == MagickFalse)
2340 if (event.xbutton.window == windows->widget.id)
2341 if (MatteIsActive(grab_info,event.xbutton))
2344 Select a fill color from the X server.
2346 (void) XGetWindowColor(display,windows,reply_info.text,
2348 reply_info.marker=reply_info.text;
2349 reply_info.cursor=reply_info.text+Extent(reply_info.text);
2350 XDrawMatteText(display,&windows->widget,&reply_info);
2351 state|=RedrawActionState;
2353 grab_info.raised=MagickTrue;
2354 XDrawBeveledButton(display,&windows->widget,&grab_info);
2356 if (reset_info.raised == MagickFalse)
2358 if (event.xbutton.window == windows->widget.id)
2359 if (MatteIsActive(reset_info,event.xbutton))
2361 (void) CopyMagickString(glob_pattern,reset_pattern,
2363 state|=UpdateListState;
2365 reset_info.raised=MagickTrue;
2366 XDrawBeveledButton(display,&windows->widget,&reset_info);
2368 if (action_info.raised == MagickFalse)
2370 if (event.xbutton.window == windows->widget.id)
2372 if (MatteIsActive(action_info,event.xbutton))
2374 if (*reply_info.text == '\0')
2375 (void) XBell(display,0);
2380 action_info.raised=MagickTrue;
2381 XDrawBeveledButton(display,&windows->widget,&action_info);
2383 if (cancel_info.raised == MagickFalse)
2385 if (event.xbutton.window == windows->widget.id)
2386 if (MatteIsActive(cancel_info,event.xbutton))
2388 *reply_info.text='\0';
2391 cancel_info.raised=MagickTrue;
2392 XDrawBeveledButton(display,&windows->widget,&cancel_info);
2394 if (MatteIsActive(reply_info,event.xbutton) == MagickFalse)
2401 If client window delete message, exit.
2403 if (event.xclient.message_type != windows->wm_protocols)
2405 if (*event.xclient.data.l == (int) windows->wm_take_focus)
2407 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
2408 (Time) event.xclient.data.l[1]);
2411 if (*event.xclient.data.l != (int) windows->wm_delete_window)
2413 if (event.xclient.window == windows->widget.id)
2415 *reply_info.text='\0';
2421 case ConfigureNotify:
2424 Update widget configuration.
2426 if (event.xconfigure.window != windows->widget.id)
2428 if ((event.xconfigure.width == (int) windows->widget.width) &&
2429 (event.xconfigure.height == (int) windows->widget.height))
2431 windows->widget.width=(unsigned int)
2432 MagickMax(event.xconfigure.width,(int) windows->widget.min_width);
2433 windows->widget.height=(unsigned int)
2434 MagickMax(event.xconfigure.height,(int) windows->widget.min_height);
2435 state|=UpdateConfigurationState;
2440 if (event.xcrossing.window != windows->widget.id)
2442 state&=(~InactiveWidgetState);
2447 if (event.xexpose.window != windows->widget.id)
2449 if (event.xexpose.count != 0)
2451 state|=RedrawWidgetState;
2457 command[MagickPathExtent];
2466 Respond to a user key press.
2468 if (event.xkey.window != windows->widget.id)
2470 length=XLookupString((XKeyEvent *) &event.xkey,command,
2471 (int) sizeof(command),&key_symbol,(XComposeStatus *) NULL);
2472 *(command+length)='\0';
2473 if (AreaIsActive(scroll_info,event.xkey))
2478 switch ((int) key_symbol)
2501 slider_info.id-=visible_colors;
2507 slider_info.id+=visible_colors;
2513 slider_info.id=(int) colors;
2517 state|=RedrawListState;
2520 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
2523 Read new color or glob patterm.
2525 if (*reply_info.text == '\0')
2527 (void) CopyMagickString(glob_pattern,reply_info.text,MagickPathExtent);
2528 state|=UpdateListState;
2531 if (key_symbol == XK_Control_L)
2533 state|=ControlState;
2536 if (state & ControlState)
2537 switch ((int) key_symbol)
2543 Erase the entire line of text.
2545 *reply_info.text='\0';
2546 reply_info.cursor=reply_info.text;
2547 reply_info.marker=reply_info.text;
2548 reply_info.highlight=MagickFalse;
2554 XEditText(display,&reply_info,key_symbol,command,state);
2555 XDrawMatteText(display,&windows->widget,&reply_info);
2556 state|=JumpListState;
2557 status=XParseColor(display,windows->widget.map_info->colormap,
2558 reply_info.text,&color);
2559 if (status != False)
2560 state|=RedrawActionState;
2566 command[MagickPathExtent];
2572 Respond to a user key release.
2574 if (event.xkey.window != windows->widget.id)
2576 (void) XLookupString((XKeyEvent *) &event.xkey,command,
2577 (int) sizeof(command),&key_symbol,(XComposeStatus *) NULL);
2578 if (key_symbol == XK_Control_L)
2579 state&=(~ControlState);
2584 if (event.xcrossing.window != windows->widget.id)
2586 state|=InactiveWidgetState;
2598 Discard pending button motion events.
2600 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
2601 if (slider_info.active)
2606 slider_info.y=event.xmotion.y-
2607 ((slider_info.height+slider_info.bevel_width) >> 1)+1;
2608 if (slider_info.y < slider_info.min_y)
2609 slider_info.y=slider_info.min_y;
2610 if (slider_info.y > slider_info.max_y)
2611 slider_info.y=slider_info.max_y;
2613 if (slider_info.y != slider_info.min_y)
2614 slider_info.id=(int) ((colors*(slider_info.y-
2615 slider_info.min_y+1))/(slider_info.max_y-slider_info.min_y+1));
2616 state|=RedrawListState;
2619 if (state & InactiveWidgetState)
2621 if (grab_info.raised == MatteIsActive(grab_info,event.xmotion))
2624 Grab button status changed.
2626 grab_info.raised=!grab_info.raised;
2627 XDrawBeveledButton(display,&windows->widget,&grab_info);
2630 if (reset_info.raised == MatteIsActive(reset_info,event.xmotion))
2633 Reset button status changed.
2635 reset_info.raised=!reset_info.raised;
2636 XDrawBeveledButton(display,&windows->widget,&reset_info);
2639 if (action_info.raised == MatteIsActive(action_info,event.xmotion))
2642 Action button status changed.
2644 action_info.raised=action_info.raised == MagickFalse ?
2645 MagickTrue : MagickFalse;
2646 XDrawBeveledButton(display,&windows->widget,&action_info);
2649 if (cancel_info.raised == MatteIsActive(cancel_info,event.xmotion))
2652 Cancel button status changed.
2654 cancel_info.raised=cancel_info.raised == MagickFalse ?
2655 MagickTrue : MagickFalse;
2656 XDrawBeveledButton(display,&windows->widget,&cancel_info);
2661 case SelectionClear:
2663 reply_info.highlight=MagickFalse;
2664 XDrawMatteText(display,&windows->widget,&reply_info);
2667 case SelectionNotify:
2683 Obtain response from primary selection.
2685 if (event.xselection.property == (Atom) None)
2687 status=XGetWindowProperty(display,event.xselection.requestor,
2688 event.xselection.property,0L,2047L,MagickTrue,XA_STRING,&type,
2689 &format,&length,&after,&data);
2690 if ((status != Success) || (type != XA_STRING) || (format == 32) ||
2693 if ((Extent(reply_info.text)+length) >= (MagickPathExtent-1))
2694 (void) XBell(display,0);
2698 Insert primary selection in reply text.
2700 *(data+length)='\0';
2701 XEditText(display,&reply_info,(KeySym) XK_Insert,(char *) data,
2703 XDrawMatteText(display,&windows->widget,&reply_info);
2704 state|=JumpListState;
2705 state|=RedrawActionState;
2707 (void) XFree((void *) data);
2710 case SelectionRequest:
2715 XSelectionRequestEvent
2718 if (reply_info.highlight == MagickFalse)
2721 Set primary selection.
2723 request=(&(event.xselectionrequest));
2724 (void) XChangeProperty(request->display,request->requestor,
2725 request->property,request->target,8,PropModeReplace,
2726 (unsigned char *) primary_selection,Extent(primary_selection));
2727 notify.type=SelectionNotify;
2728 notify.send_event=MagickTrue;
2729 notify.display=request->display;
2730 notify.requestor=request->requestor;
2731 notify.selection=request->selection;
2732 notify.target=request->target;
2733 notify.time=request->time;
2734 if (request->property == None)
2735 notify.property=request->target;
2737 notify.property=request->property;
2738 (void) XSendEvent(request->display,request->requestor,False,
2739 NoEventMask,(XEvent *) ¬ify);
2744 } while ((state & ExitState) == 0);
2745 XSetCursorState(display,windows,MagickFalse);
2746 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
2747 XCheckRefreshWindows(display,windows);
2751 for (i=0; i < (int) colors; i++)
2752 colorlist[i]=DestroyString(colorlist[i]);
2753 if (colorlist != (char **) NULL)
2754 colorlist=(char **) RelinquishMagickMemory(colorlist);
2755 exception=DestroyExceptionInfo(exception);
2756 if ((*reply == '\0') || (strchr(reply,'-') != (char *) NULL))
2758 status=XParseColor(display,windows->widget.map_info->colormap,reply,&color);
2759 if (status != False)
2761 XNoticeWidget(display,windows,"Color is unknown to X server:",reply);
2762 (void) CopyMagickString(reply,"gray",MagickPathExtent);
2766 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2770 % X C o m m a n d W i d g e t %
2774 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2776 % XCommandWidget() maps a menu and returns the command pointed to by the user
2777 % when the button is released.
2779 % The format of the XCommandWidget method is:
2781 % int XCommandWidget(Display *display,XWindows *windows,
2782 % const char **selections,XEvent *event)
2784 % A description of each parameter follows:
2786 % o selection_number: Specifies the number of the selection that the
2789 % o display: Specifies a connection to an X server; returned from
2792 % o window: Specifies a pointer to a XWindows structure.
2794 % o selections: Specifies a pointer to one or more strings that comprise
2795 % the choices in the menu.
2797 % o event: Specifies a pointer to a X11 XEvent structure.
2800 MagickPrivate int XCommandWidget(Display *display,XWindows *windows,
2801 const char **selections,XEvent *event)
2803 #define tile_width 112
2804 #define tile_height 70
2806 static const unsigned char
2809 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2810 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2811 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2812 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
2813 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00,
2814 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00,
2815 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2816 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2817 0x00, 0x00, 0x1e, 0x38, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2818 0x00, 0x00, 0x00, 0x00, 0x1e, 0xbc, 0x9f, 0x03, 0x00, 0x3e, 0x00, 0xc0,
2819 0x1f, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x1e, 0xfc, 0xff, 0x0f, 0x80, 0x3f,
2820 0x00, 0xf0, 0x1f, 0xc0, 0x0f, 0x00, 0x00, 0x00, 0x1e, 0xfc, 0xff, 0x1f,
2821 0xe0, 0x3f, 0x00, 0xfc, 0x1f, 0xf0, 0x0f, 0x00, 0x00, 0x00, 0x1e, 0xfc,
2822 0xff, 0x1f, 0xf0, 0x3f, 0x00, 0xfe, 0x1f, 0xf8, 0x0f, 0x00, 0x00, 0x00,
2823 0x1e, 0xfc, 0xfc, 0x3f, 0xf8, 0x3f, 0x00, 0xff, 0x1e, 0xfc, 0x0f, 0x00,
2824 0x00, 0x00, 0x1e, 0x7c, 0xfc, 0x3e, 0xf8, 0x3c, 0x80, 0x1f, 0x1e, 0x7c,
2825 0x0f, 0x00, 0x00, 0x00, 0x1e, 0x78, 0x78, 0x3c, 0x7c, 0x3c, 0xc0, 0x0f,
2826 0x1e, 0x3e, 0x0f, 0x00, 0x00, 0x00, 0x1e, 0x78, 0x78, 0x3c, 0x7c, 0x3c,
2827 0xc0, 0x07, 0x1e, 0x3e, 0x0f, 0x00, 0x00, 0x00, 0x1e, 0x78, 0x78, 0x3c,
2828 0x7c, 0x7c, 0xc0, 0x0f, 0x1e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x78,
2829 0x78, 0x3c, 0xfc, 0x7c, 0x80, 0x7f, 0x1e, 0x7c, 0x00, 0x00, 0x00, 0x00,
2830 0x1e, 0xf8, 0x78, 0x7c, 0xf8, 0xff, 0x00, 0xff, 0x1f, 0xf8, 0xff, 0x00,
2831 0x00, 0x00, 0x1e, 0xf8, 0x78, 0x7c, 0xf0, 0xff, 0x07, 0xfe, 0x1f, 0xf8,
2832 0xff, 0x00, 0x00, 0x00, 0x1e, 0xf8, 0x78, 0x7c, 0xf0, 0xff, 0x07, 0xf8,
2833 0x1f, 0xf0, 0xff, 0x01, 0x00, 0x00, 0x1e, 0xf8, 0x78, 0x7c, 0xc0, 0xef,
2834 0x07, 0xe0, 0x1f, 0xc0, 0xff, 0x01, 0x00, 0x00, 0x1e, 0x70, 0x40, 0x78,
2835 0x00, 0xc7, 0x07, 0x00, 0x1e, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x1e, 0x00,
2836 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00,
2837 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00,
2838 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00,
2839 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
2840 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2841 0x00, 0xc0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2842 0x00, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2843 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
2844 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x01, 0x00, 0x00, 0x00,
2845 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00,
2846 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78,
2847 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2848 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x02, 0x00,
2849 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07,
2850 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2851 0xc0, 0x0f, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2852 0x60, 0x00, 0xc0, 0x0f, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2853 0x00, 0x00, 0x78, 0x00, 0xc0, 0x8f, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00,
2854 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0xc0, 0x8f, 0x3f, 0x00, 0x00, 0x00,
2855 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0xe0, 0x9f, 0x7f, 0x00,
2856 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0xe0, 0xdf,
2857 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x78, 0x00,
2858 0xe0, 0xdf, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x0c,
2859 0x78, 0x30, 0xf0, 0xff, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e,
2860 0x00, 0x0f, 0xf8, 0x70, 0xf0, 0xff, 0x7b, 0x00, 0x00, 0x1f, 0x00, 0xe0,
2861 0x0f, 0x1e, 0x80, 0x0f, 0xf8, 0x78, 0xf0, 0xfd, 0xf9, 0x00, 0xc0, 0x1f,
2862 0x00, 0xf8, 0x0f, 0x00, 0xe0, 0x1f, 0xf8, 0x7c, 0xf0, 0xfc, 0xf9, 0x00,
2863 0xf0, 0x1f, 0x00, 0xfe, 0x0f, 0x00, 0xf0, 0x07, 0xf8, 0x3e, 0xf8, 0xfc,
2864 0xf0, 0x01, 0xf8, 0x1f, 0x00, 0xff, 0x0f, 0x1e, 0xf0, 0x03, 0xf8, 0x3f,
2865 0xf8, 0xf8, 0xf0, 0x01, 0xfc, 0x1f, 0x80, 0x7f, 0x0f, 0x1e, 0xf8, 0x00,
2866 0xf8, 0x1f, 0x78, 0x18, 0xf0, 0x01, 0x7c, 0x1e, 0xc0, 0x0f, 0x0f, 0x1e,
2867 0x7c, 0x00, 0xf0, 0x0f, 0x78, 0x00, 0xf0, 0x01, 0x3e, 0x1e, 0xe0, 0x07,
2868 0x0f, 0x1e, 0x7c, 0x00, 0xf0, 0x07, 0x7c, 0x00, 0xe0, 0x01, 0x3e, 0x1e,
2869 0xe0, 0x03, 0x0f, 0x1e, 0x3e, 0x00, 0xf0, 0x0f, 0x7c, 0x00, 0xe0, 0x03,
2870 0x3e, 0x3e, 0xe0, 0x07, 0x0f, 0x1e, 0x1e, 0x00, 0xf0, 0x1f, 0x3c, 0x00,
2871 0xe0, 0x03, 0x7e, 0x3e, 0xc0, 0x3f, 0x0f, 0x1e, 0x3e, 0x00, 0xf0, 0x1f,
2872 0x3e, 0x00, 0xe0, 0x03, 0xfc, 0x7f, 0x80, 0xff, 0x0f, 0x1e, 0xfc, 0x00,
2873 0xf0, 0x3e, 0x3e, 0x00, 0xc0, 0x03, 0xf8, 0xff, 0x03, 0xff, 0x0f, 0x1e,
2874 0xfc, 0x07, 0xf0, 0x7c, 0x1e, 0x00, 0xc0, 0x03, 0xf8, 0xff, 0x03, 0xfc,
2875 0x0f, 0x1e, 0xf8, 0x1f, 0xf0, 0xf8, 0x1e, 0x00, 0xc0, 0x03, 0xe0, 0xf7,
2876 0x03, 0xf0, 0x0f, 0x1e, 0xe0, 0x3f, 0xf0, 0x78, 0x1c, 0x00, 0x80, 0x03,
2877 0x80, 0xe3, 0x03, 0x00, 0x0f, 0x1e, 0xc0, 0x3f, 0xf0, 0x30, 0x00, 0x00,
2878 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0e, 0x00, 0x3e, 0x00, 0x00,
2879 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x0f, 0x00, 0x00, 0x10,
2880 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x0f, 0x00,
2881 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
2882 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2883 0x00, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2884 0x00, 0x00, 0x00, 0xf0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2885 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
2886 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00,
2887 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00,
2888 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c,
2889 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2890 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2912 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2913 assert(display != (Display *) NULL);
2914 assert(windows != (XWindows *) NULL);
2915 font_info=windows->command.font_info;
2916 height=(unsigned int) (font_info->ascent+font_info->descent);
2919 if (event == (XEvent *) NULL)
2931 Determine command window attributes.
2933 assert(selections != (const char **) NULL);
2934 windows->command.width=0;
2935 for (i=0; selections[i] != (char *) NULL; i++)
2937 width=WidgetTextWidth(font_info,(char *) selections[i]);
2938 if (width > windows->command.width)
2939 windows->command.width=width;
2941 number_selections=(unsigned int) i;
2942 windows->command.width+=3*QuantumMargin+10;
2943 if ((int) windows->command.width < (tile_width+QuantumMargin+10))
2944 windows->command.width=(unsigned int) (tile_width+QuantumMargin+10);
2945 windows->command.height=(unsigned int) (number_selections*
2946 (((3*height) >> 1)+10)+tile_height+20);
2947 windows->command.min_width=windows->command.width;
2948 windows->command.min_height=windows->command.height;
2949 XConstrainWindowPosition(display,&windows->command);
2950 if (windows->command.id != (Window) NULL)
2956 Reconfigure command window.
2958 status=XStringListToTextProperty(&windows->command.name,1,
2960 if (status != False)
2962 XSetWMName(display,windows->command.id,&window_name);
2963 XSetWMIconName(display,windows->command.id,&window_name);
2964 (void) XFree((void *) window_name.value);
2966 window_changes.width=(int) windows->command.width;
2967 window_changes.height=(int) windows->command.height;
2968 (void) XReconfigureWMWindow(display,windows->command.id,
2969 windows->command.screen,(unsigned int) (CWWidth | CWHeight),
2973 Allocate selection info memory.
2975 if (selection_info != (XWidgetInfo *) NULL)
2976 selection_info=(XWidgetInfo *) RelinquishMagickMemory(selection_info);
2977 selection_info=(XWidgetInfo *) AcquireQuantumMemory(number_selections,
2978 sizeof(*selection_info));
2979 if (selection_info == (XWidgetInfo *) NULL)
2981 ThrowXWindowFatalException(ResourceLimitFatalError,
2982 "MemoryAllocationFailed","...");
2985 state|=UpdateConfigurationState | RedrawWidgetState;
2988 Wait for next event.
2990 if (event != (XEvent *) NULL)
2991 switch (event->type)
2995 for (i=0; i < (int) number_selections; i++)
2997 if (MatteIsActive(selection_info[i],event->xbutton) == MagickFalse)
2999 if (i >= (int) windows->command.data)
3001 selection_info[i].raised=MagickFalse;
3002 XDrawBeveledButton(display,&windows->command,&selection_info[i]);
3005 submenu_info=selection_info[i];
3006 submenu_info.active=MagickTrue;
3007 toggle_info.y=submenu_info.y+(submenu_info.height >> 1)-
3008 (toggle_info.height >> 1);
3010 (void) XCheckWindowEvent(display,windows->widget.id,LeaveWindowMask,
3018 for (i=0; i < (int) number_selections; i++)
3020 if (MatteIsActive(selection_info[i],event->xbutton) == MagickFalse)
3023 if (id >= (int) windows->command.data)
3025 selection_info[id].raised=MagickTrue;
3026 XDrawBeveledButton(display,&windows->command,&selection_info[id]);
3036 If client window delete message, withdraw command widget.
3038 if (event->xclient.message_type != windows->wm_protocols)
3040 if (*event->xclient.data.l != (int) windows->wm_delete_window)
3042 (void) XWithdrawWindow(display,windows->command.id,
3043 windows->command.screen);
3046 case ConfigureNotify:
3049 Update widget configuration.
3051 if (event->xconfigure.window != windows->command.id)
3053 if (event->xconfigure.send_event != 0)
3055 windows->command.x=event->xconfigure.x;
3056 windows->command.y=event->xconfigure.y;
3058 if ((event->xconfigure.width == (int) windows->command.width) &&
3059 (event->xconfigure.height == (int) windows->command.height))
3061 windows->command.width=(unsigned int)
3062 MagickMax(event->xconfigure.width,(int) windows->command.min_width);
3063 windows->command.height=(unsigned int)
3064 MagickMax(event->xconfigure.height,(int) windows->command.min_height);
3065 state|=UpdateConfigurationState;
3070 if (event->xexpose.window != windows->command.id)
3072 if (event->xexpose.count != 0)
3074 state|=RedrawWidgetState;
3080 Return the ID of the highlighted menu entry.
3084 for (i=0; i < (int) number_selections; i++)
3086 if (i >= (int) windows->command.data)
3088 if (selection_info[i].raised ==
3089 MatteIsActive(selection_info[i],event->xmotion))
3092 Button status changed.
3094 selection_info[i].raised=!selection_info[i].raised;
3095 XDrawBeveledButton(display,&windows->command,
3096 &selection_info[i]);
3100 if (MatteIsActive(selection_info[i],event->xmotion) == MagickFalse)
3102 submenu_info=selection_info[i];
3103 submenu_info.active=MagickTrue;
3104 toggle_info.raised=MagickTrue;
3105 toggle_info.y=submenu_info.y+(submenu_info.height >> 1)-
3106 (toggle_info.height >> 1);
3107 XDrawTriangleEast(display,&windows->command,&toggle_info);
3110 XDelay(display,SuspendTime);
3111 if (XCheckMaskEvent(display,ButtonMotionMask,event) == MagickFalse)
3113 while (XCheckMaskEvent(display,ButtonMotionMask,event)) ;
3114 toggle_info.raised=MagickFalse;
3115 if (windows->command.data != 0)
3116 XDrawTriangleEast(display,&windows->command,&toggle_info);
3122 windows->command.mapped=MagickTrue;
3127 windows->command.mapped=MagickFalse;
3133 if (state & UpdateConfigurationState)
3136 Initialize button information.
3138 assert(selections != (const char **) NULL);
3140 for (i=0; i < (int) number_selections; i++)
3142 XGetWidgetInfo(selections[i],&selection_info[i]);
3143 selection_info[i].center=MagickFalse;
3144 selection_info[i].bevel_width--;
3145 selection_info[i].height=(unsigned int) ((3*height) >> 1);
3146 selection_info[i].x=(QuantumMargin >> 1)+4;
3147 selection_info[i].width=(unsigned int) (windows->command.width-
3148 (selection_info[i].x << 1));
3149 selection_info[i].y=y;
3150 y+=selection_info[i].height+(selection_info[i].bevel_width << 1)+6;
3152 XGetWidgetInfo((char *) NULL,&toggle_info);
3153 toggle_info.bevel_width--;
3154 toggle_info.width=(unsigned int) (((5*height) >> 3)-
3155 (toggle_info.bevel_width << 1));
3156 toggle_info.height=toggle_info.width;
3157 toggle_info.x=selection_info[0].x+selection_info[0].width-
3158 toggle_info.width-(QuantumMargin >> 1);
3159 if (windows->command.mapped)
3160 (void) XClearWindow(display,windows->command.id);
3162 if (state & RedrawWidgetState)
3168 Draw command buttons.
3170 tile_pixmap=XCreatePixmapFromBitmapData(display,windows->command.id,
3171 (char *) tile_bits,tile_width,tile_height,1L,0L,1);
3172 if (tile_pixmap != (Pixmap) NULL)
3174 (void) XCopyPlane(display,tile_pixmap,windows->command.id,
3175 windows->command.annotate_context,0,0,tile_width,tile_height,
3176 (int) ((windows->command.width-tile_width) >> 1),10,1L);
3177 (void) XFreePixmap(display,tile_pixmap);
3179 for (i=0; i < (int) number_selections; i++)
3181 XDrawBeveledButton(display,&windows->command,&selection_info[i]);
3182 if (i >= (int) windows->command.data)
3184 toggle_info.raised=MagickFalse;
3185 toggle_info.y=selection_info[i].y+(selection_info[i].height >> 1)-
3186 (toggle_info.height >> 1);
3187 XDrawTriangleEast(display,&windows->command,&toggle_info);
3189 XHighlightWidget(display,&windows->command,BorderOffset,BorderOffset);
3195 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3199 % X C o n f i r m W i d g e t %
3203 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3205 % XConfirmWidget() displays a Confirm widget with a notice to the user. The
3206 % function returns -1 if Dismiss is pressed, 0 for Cancel, and 1 for Yes.
3208 % The format of the XConfirmWidget method is:
3210 % int XConfirmWidget(Display *display,XWindows *windows,
3211 % const char *reason,const char *description)
3213 % A description of each parameter follows:
3215 % o display: Specifies a connection to an X server; returned from
3218 % o window: Specifies a pointer to a XWindows structure.
3220 % o reason: Specifies the message to display before terminating the
3223 % o description: Specifies any description to the message.
3226 MagickPrivate int XConfirmWidget(Display *display,XWindows *windows,
3227 const char *reason,const char *description)
3229 #define CancelButtonText "Cancel"
3230 #define DismissButtonText "Dismiss"
3231 #define YesButtonText "Yes"
3266 Determine Confirm widget attributes.
3268 assert(display != (Display *) NULL);
3269 assert(windows != (XWindows *) NULL);
3270 assert(reason != (char *) NULL);
3271 assert(description != (char *) NULL);
3272 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",reason);
3273 XCheckRefreshWindows(display,windows);
3274 font_info=windows->widget.font_info;
3275 width=WidgetTextWidth(font_info,CancelButtonText);
3276 if (WidgetTextWidth(font_info,DismissButtonText) > width)
3277 width=WidgetTextWidth(font_info,DismissButtonText);
3278 if (WidgetTextWidth(font_info,YesButtonText) > width)
3279 width=WidgetTextWidth(font_info,YesButtonText);
3281 if (description != (char *) NULL)
3282 if (WidgetTextWidth(font_info,(char *) description) > width)
3283 width=WidgetTextWidth(font_info,(char *) description);
3284 height=(unsigned int) (font_info->ascent+font_info->descent);
3286 Position Confirm widget.
3288 windows->widget.width=(unsigned int) (width+9*QuantumMargin);
3289 windows->widget.min_width=(unsigned int) (9*QuantumMargin+
3290 WidgetTextWidth(font_info,CancelButtonText)+
3291 WidgetTextWidth(font_info,DismissButtonText)+
3292 WidgetTextWidth(font_info,YesButtonText));
3293 if (windows->widget.width < windows->widget.min_width)
3294 windows->widget.width=windows->widget.min_width;
3295 windows->widget.height=(unsigned int) (12*height);
3296 windows->widget.min_height=(unsigned int) (7*height);
3297 if (windows->widget.height < windows->widget.min_height)
3298 windows->widget.height=windows->widget.min_height;
3299 XConstrainWindowPosition(display,&windows->widget);
3303 (void) CopyMagickString(windows->widget.name,"Confirm",MagickPathExtent);
3304 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
3305 if (status != False)
3307 XSetWMName(display,windows->widget.id,&window_name);
3308 XSetWMIconName(display,windows->widget.id,&window_name);
3309 (void) XFree((void *) window_name.value);
3311 window_changes.width=(int) windows->widget.width;
3312 window_changes.height=(int) windows->widget.height;
3313 window_changes.x=windows->widget.x;
3314 window_changes.y=windows->widget.y;
3315 (void) XReconfigureWMWindow(display,windows->widget.id,windows->widget.screen,
3316 (unsigned int) (CWWidth | CWHeight | CWX | CWY),&window_changes);
3317 (void) XMapRaised(display,windows->widget.id);
3318 windows->widget.mapped=MagickFalse;
3320 Respond to X events.
3323 state=UpdateConfigurationState;
3324 XSetCursorState(display,windows,MagickTrue);
3327 if (state & UpdateConfigurationState)
3330 Initialize button information.
3332 XGetWidgetInfo(CancelButtonText,&cancel_info);
3333 cancel_info.width=(unsigned int) QuantumMargin+
3334 WidgetTextWidth(font_info,CancelButtonText);
3335 cancel_info.height=(unsigned int) ((3*height) >> 1);
3336 cancel_info.x=(int) (windows->widget.width-cancel_info.width-
3338 cancel_info.y=(int) (windows->widget.height-(cancel_info.height << 1));
3339 dismiss_info=cancel_info;
3340 dismiss_info.text=(char *) DismissButtonText;
3341 if (LocaleCompare(description,"Do you want to save it") == 0)
3342 dismiss_info.text=(char *) "Don't Save";
3343 dismiss_info.width=(unsigned int) QuantumMargin+
3344 WidgetTextWidth(font_info,dismiss_info.text);
3345 dismiss_info.x=(int)
3346 ((windows->widget.width >> 1)-(dismiss_info.width >> 1));
3347 yes_info=cancel_info;
3348 yes_info.text=(char *) YesButtonText;
3349 if (LocaleCompare(description,"Do you want to save it") == 0)
3350 yes_info.text=(char *) "Save";
3351 yes_info.width=(unsigned int) QuantumMargin+
3352 WidgetTextWidth(font_info,yes_info.text);
3353 if (yes_info.width < cancel_info.width)
3354 yes_info.width=cancel_info.width;
3355 yes_info.x=QuantumMargin;
3356 state&=(~UpdateConfigurationState);
3358 if (state & RedrawWidgetState)
3361 Redraw Confirm widget.
3363 width=WidgetTextWidth(font_info,(char *) reason);
3364 x=(int) ((windows->widget.width >> 1)-(width >> 1));
3365 y=(int) ((windows->widget.height >> 1)-(height << 1));
3366 (void) XDrawString(display,windows->widget.id,
3367 windows->widget.annotate_context,x,y,(char *) reason,Extent(reason));
3368 if (description != (char *) NULL)
3371 question[MagickPathExtent];
3373 (void) CopyMagickString(question,description,MagickPathExtent);
3374 (void) ConcatenateMagickString(question,"?",MagickPathExtent);
3375 width=WidgetTextWidth(font_info,question);
3376 x=(int) ((windows->widget.width >> 1)-(width >> 1));
3378 (void) XDrawString(display,windows->widget.id,
3379 windows->widget.annotate_context,x,y,question,Extent(question));
3381 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3382 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
3383 XDrawBeveledButton(display,&windows->widget,&yes_info);
3384 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
3385 state&=(~RedrawWidgetState);
3388 Wait for next event.
3390 (void) XIfEvent(display,&event,XScreenEvent,(char *) windows);
3395 if (MatteIsActive(cancel_info,event.xbutton))
3398 User pressed No button.
3400 cancel_info.raised=MagickFalse;
3401 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3404 if (MatteIsActive(dismiss_info,event.xbutton))
3407 User pressed Dismiss button.
3409 dismiss_info.raised=MagickFalse;
3410 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
3413 if (MatteIsActive(yes_info,event.xbutton))
3416 User pressed Yes button.
3418 yes_info.raised=MagickFalse;
3419 XDrawBeveledButton(display,&windows->widget,&yes_info);
3426 if (windows->widget.mapped == MagickFalse)
3428 if (cancel_info.raised == MagickFalse)
3430 if (event.xbutton.window == windows->widget.id)
3431 if (MatteIsActive(cancel_info,event.xbutton))
3436 cancel_info.raised=MagickTrue;
3437 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3439 if (dismiss_info.raised == MagickFalse)
3441 if (event.xbutton.window == windows->widget.id)
3442 if (MatteIsActive(dismiss_info,event.xbutton))
3447 dismiss_info.raised=MagickTrue;
3448 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
3450 if (yes_info.raised == MagickFalse)
3452 if (event.xbutton.window == windows->widget.id)
3453 if (MatteIsActive(yes_info,event.xbutton))
3458 yes_info.raised=MagickTrue;
3459 XDrawBeveledButton(display,&windows->widget,&yes_info);
3466 If client window delete message, exit.
3468 if (event.xclient.message_type != windows->wm_protocols)
3470 if (*event.xclient.data.l == (int) windows->wm_take_focus)
3472 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
3473 (Time) event.xclient.data.l[1]);
3476 if (*event.xclient.data.l != (int) windows->wm_delete_window)
3478 if (event.xclient.window == windows->widget.id)
3485 case ConfigureNotify:
3488 Update widget configuration.
3490 if (event.xconfigure.window != windows->widget.id)
3492 if ((event.xconfigure.width == (int) windows->widget.width) &&
3493 (event.xconfigure.height == (int) windows->widget.height))
3495 windows->widget.width=(unsigned int)
3496 MagickMax(event.xconfigure.width,(int) windows->widget.min_width);
3497 windows->widget.height=(unsigned int)
3498 MagickMax(event.xconfigure.height,(int) windows->widget.min_height);
3499 state|=UpdateConfigurationState;
3504 if (event.xcrossing.window != windows->widget.id)
3506 state&=(~InactiveWidgetState);
3511 if (event.xexpose.window != windows->widget.id)
3513 if (event.xexpose.count != 0)
3515 state|=RedrawWidgetState;
3521 command[MagickPathExtent];
3527 Respond to a user key press.
3529 if (event.xkey.window != windows->widget.id)
3531 (void) XLookupString((XKeyEvent *) &event.xkey,command,
3532 (int) sizeof(command),&key_symbol,(XComposeStatus *) NULL);
3533 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
3535 yes_info.raised=MagickFalse;
3536 XDrawBeveledButton(display,&windows->widget,&yes_info);
3545 if (event.xcrossing.window != windows->widget.id)
3547 state|=InactiveWidgetState;
3553 Discard pending button motion events.
3555 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
3556 if (state & InactiveWidgetState)
3558 if (cancel_info.raised == MatteIsActive(cancel_info,event.xmotion))
3561 Cancel button status changed.
3563 cancel_info.raised=cancel_info.raised == MagickFalse ?
3564 MagickTrue : MagickFalse;
3565 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3568 if (dismiss_info.raised == MatteIsActive(dismiss_info,event.xmotion))
3571 Dismiss button status changed.
3573 dismiss_info.raised=dismiss_info.raised == MagickFalse ?
3574 MagickTrue : MagickFalse;
3575 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
3578 if (yes_info.raised == MatteIsActive(yes_info,event.xmotion))
3581 Yes button status changed.
3583 yes_info.raised=yes_info.raised == MagickFalse ?
3584 MagickTrue : MagickFalse;
3585 XDrawBeveledButton(display,&windows->widget,&yes_info);
3593 } while ((state & ExitState) == 0);
3594 XSetCursorState(display,windows,MagickFalse);
3595 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
3596 XCheckRefreshWindows(display,windows);
3601 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3605 % X D i a l o g W i d g e t %
3609 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3611 % XDialogWidget() displays a Dialog widget with a query to the user. The user
3612 % keys a reply and presses the Ok or Cancel button to exit. The typed text is
3613 % returned as the reply function parameter.
3615 % The format of the XDialogWidget method is:
3617 % int XDialogWidget(Display *display,XWindows *windows,const char *action,
3618 % const char *query,char *reply)
3620 % A description of each parameter follows:
3622 % o display: Specifies a connection to an X server; returned from
3625 % o window: Specifies a pointer to a XWindows structure.
3627 % o action: Specifies a pointer to the action of this widget.
3629 % o query: Specifies a pointer to the query to present to the user.
3631 % o reply: the response from the user is returned in this parameter.
3634 MagickPrivate int XDialogWidget(Display *display,XWindows *windows,
3635 const char *action,const char *query,char *reply)
3637 #define CancelButtonText "Cancel"
3640 primary_selection[MagickPathExtent];
3648 static MagickBooleanType
3649 raised = MagickFalse;
3682 Determine Dialog widget attributes.
3684 assert(display != (Display *) NULL);
3685 assert(windows != (XWindows *) NULL);
3686 assert(action != (char *) NULL);
3687 assert(query != (char *) NULL);
3688 assert(reply != (char *) NULL);
3689 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",action);
3690 XCheckRefreshWindows(display,windows);
3691 font_info=windows->widget.font_info;
3692 width=WidgetTextWidth(font_info,(char *) action);
3693 if (WidgetTextWidth(font_info,CancelButtonText) > width)
3694 width=WidgetTextWidth(font_info,CancelButtonText);
3695 width+=(3*QuantumMargin) >> 1;
3696 height=(unsigned int) (font_info->ascent+font_info->descent);
3698 Position Dialog widget.
3700 windows->widget.width=(unsigned int) MagickMax((int) (2*width),(int)
3701 WidgetTextWidth(font_info,(char *) query));
3702 if (windows->widget.width < WidgetTextWidth(font_info,reply))
3703 windows->widget.width=WidgetTextWidth(font_info,reply);
3704 windows->widget.width+=6*QuantumMargin;
3705 windows->widget.min_width=(unsigned int)
3706 (width+28*XTextWidth(font_info,"#",1)+4*QuantumMargin);
3707 if (windows->widget.width < windows->widget.min_width)
3708 windows->widget.width=windows->widget.min_width;
3709 windows->widget.height=(unsigned int) (7*height+(QuantumMargin << 1));
3710 windows->widget.min_height=windows->widget.height;
3711 if (windows->widget.height < windows->widget.min_height)
3712 windows->widget.height=windows->widget.min_height;
3713 XConstrainWindowPosition(display,&windows->widget);
3717 (void) CopyMagickString(windows->widget.name,"Dialog",MagickPathExtent);
3718 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
3719 if (status != False)
3721 XSetWMName(display,windows->widget.id,&window_name);
3722 XSetWMIconName(display,windows->widget.id,&window_name);
3723 (void) XFree((void *) window_name.value);
3725 window_changes.width=(int) windows->widget.width;
3726 window_changes.height=(int) windows->widget.height;
3727 window_changes.x=windows->widget.x;
3728 window_changes.y=windows->widget.y;
3729 (void) XReconfigureWMWindow(display,windows->widget.id,windows->widget.screen,
3730 (unsigned int) (CWWidth | CWHeight | CWX | CWY),&window_changes);
3731 (void) XMapRaised(display,windows->widget.id);
3732 windows->widget.mapped=MagickFalse;
3734 Respond to X events.
3736 anomaly=(LocaleCompare(action,"Background") == 0) ||
3737 (LocaleCompare(action,"New") == 0) ||
3738 (LocaleCompare(action,"Quantize") == 0) ||
3739 (LocaleCompare(action,"Resize") == 0) ||
3740 (LocaleCompare(action,"Save") == 0) ||
3741 (LocaleCompare(action,"Shade") == 0);
3742 state=UpdateConfigurationState;
3743 XSetCursorState(display,windows,MagickTrue);
3746 if (state & UpdateConfigurationState)
3749 Initialize button information.
3751 XGetWidgetInfo(CancelButtonText,&cancel_info);
3752 cancel_info.width=width;
3753 cancel_info.height=(unsigned int) ((3*height) >> 1);
3755 (windows->widget.width-cancel_info.width-((3*QuantumMargin) >> 1));
3757 (windows->widget.height-cancel_info.height-((3*QuantumMargin) >> 1));
3758 XGetWidgetInfo(action,&action_info);
3759 action_info.width=width;
3760 action_info.height=(unsigned int) ((3*height) >> 1);
3761 action_info.x=cancel_info.x-(cancel_info.width+QuantumMargin+
3762 (action_info.bevel_width << 1));
3763 action_info.y=cancel_info.y;
3765 Initialize reply information.
3767 XGetWidgetInfo(reply,&reply_info);
3768 reply_info.raised=MagickFalse;
3769 reply_info.bevel_width--;
3770 reply_info.width=windows->widget.width-(3*QuantumMargin);
3771 reply_info.height=height << 1;
3772 reply_info.x=(3*QuantumMargin) >> 1;
3773 reply_info.y=action_info.y-reply_info.height-QuantumMargin;
3775 Initialize option information.
3777 XGetWidgetInfo("Dither",&special_info);
3778 special_info.raised=raised;
3779 special_info.bevel_width--;
3780 special_info.width=(unsigned int) QuantumMargin >> 1;
3781 special_info.height=(unsigned int) QuantumMargin >> 1;
3782 special_info.x=reply_info.x;
3783 special_info.y=action_info.y+action_info.height-special_info.height;
3784 if (LocaleCompare(action,"Background") == 0)
3785 special_info.text=(char *) "Backdrop";
3786 if (LocaleCompare(action,"New") == 0)
3787 special_info.text=(char *) "Gradation";
3788 if (LocaleCompare(action,"Resize") == 0)
3789 special_info.text=(char *) "Constrain ratio";
3790 if (LocaleCompare(action,"Save") == 0)
3791 special_info.text=(char *) "Non-progressive";
3792 if (LocaleCompare(action,"Shade") == 0)
3793 special_info.text=(char *) "Color shading";
3795 Initialize text information.
3797 XGetWidgetInfo(query,&text_info);
3798 text_info.width=reply_info.width;
3799 text_info.height=height;
3800 text_info.x=reply_info.x-(QuantumMargin >> 1);
3801 text_info.y=QuantumMargin;
3802 text_info.center=MagickFalse;
3803 state&=(~UpdateConfigurationState);
3805 if (state & RedrawWidgetState)
3808 Redraw Dialog widget.
3810 XDrawWidgetText(display,&windows->widget,&text_info);
3811 XDrawBeveledMatte(display,&windows->widget,&reply_info);
3812 XDrawMatteText(display,&windows->widget,&reply_info);
3814 XDrawBeveledButton(display,&windows->widget,&special_info);
3815 XDrawBeveledButton(display,&windows->widget,&action_info);
3816 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3817 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
3818 state&=(~RedrawWidgetState);
3821 Wait for next event.
3823 (void) XIfEvent(display,&event,XScreenEvent,(char *) windows);
3829 if (MatteIsActive(special_info,event.xbutton))
3832 Option button status changed.
3834 special_info.raised=!special_info.raised;
3835 XDrawBeveledButton(display,&windows->widget,&special_info);
3838 if (MatteIsActive(action_info,event.xbutton))
3841 User pressed Action button.
3843 action_info.raised=MagickFalse;
3844 XDrawBeveledButton(display,&windows->widget,&action_info);
3847 if (MatteIsActive(cancel_info,event.xbutton))
3850 User pressed Cancel button.
3852 cancel_info.raised=MagickFalse;
3853 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3856 if (MatteIsActive(reply_info,event.xbutton) == MagickFalse)
3858 if (event.xbutton.button != Button2)
3864 Move text cursor to position of button press.
3866 x=event.xbutton.x-reply_info.x-(QuantumMargin >> 2);
3867 for (i=1; i <= Extent(reply_info.marker); i++)
3868 if (XTextWidth(font_info,reply_info.marker,i) > x)
3870 reply_info.cursor=reply_info.marker+i-1;
3871 if (event.xbutton.time > (click_time+DoubleClick))
3872 reply_info.highlight=MagickFalse;
3876 Become the XA_PRIMARY selection owner.
3878 (void) CopyMagickString(primary_selection,reply_info.text,
3880 (void) XSetSelectionOwner(display,XA_PRIMARY,windows->widget.id,
3881 event.xbutton.time);
3882 reply_info.highlight=XGetSelectionOwner(display,XA_PRIMARY) ==
3883 windows->widget.id ? MagickTrue : MagickFalse;
3885 XDrawMatteText(display,&windows->widget,&reply_info);
3886 click_time=event.xbutton.time;
3890 Request primary selection.
3892 (void) XConvertSelection(display,XA_PRIMARY,XA_STRING,XA_STRING,
3893 windows->widget.id,event.xbutton.time);
3898 if (windows->widget.mapped == MagickFalse)
3900 if (action_info.raised == MagickFalse)
3902 if (event.xbutton.window == windows->widget.id)
3903 if (MatteIsActive(action_info,event.xbutton))
3905 action_info.raised=MagickTrue;
3906 XDrawBeveledButton(display,&windows->widget,&action_info);
3908 if (cancel_info.raised == MagickFalse)
3910 if (event.xbutton.window == windows->widget.id)
3911 if (MatteIsActive(cancel_info,event.xbutton))
3913 *reply_info.text='\0';
3916 cancel_info.raised=MagickTrue;
3917 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3924 If client window delete message, exit.
3926 if (event.xclient.message_type != windows->wm_protocols)
3928 if (*event.xclient.data.l == (int) windows->wm_take_focus)
3930 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
3931 (Time) event.xclient.data.l[1]);
3934 if (*event.xclient.data.l != (int) windows->wm_delete_window)
3936 if (event.xclient.window == windows->widget.id)
3938 *reply_info.text='\0';
3944 case ConfigureNotify:
3947 Update widget configuration.
3949 if (event.xconfigure.window != windows->widget.id)
3951 if ((event.xconfigure.width == (int) windows->widget.width) &&
3952 (event.xconfigure.height == (int) windows->widget.height))
3954 windows->widget.width=(unsigned int)
3955 MagickMax(event.xconfigure.width,(int) windows->widget.min_width);
3956 windows->widget.height=(unsigned int)
3957 MagickMax(event.xconfigure.height,(int) windows->widget.min_height);
3958 state|=UpdateConfigurationState;
3963 if (event.xcrossing.window != windows->widget.id)
3965 state&=(~InactiveWidgetState);
3970 if (event.xexpose.window != windows->widget.id)
3972 if (event.xexpose.count != 0)
3974 state|=RedrawWidgetState;
3980 command[MagickPathExtent];
3989 Respond to a user key press.
3991 if (event.xkey.window != windows->widget.id)
3993 length=XLookupString((XKeyEvent *) &event.xkey,command,
3994 (int) sizeof(command),&key_symbol,(XComposeStatus *) NULL);
3995 *(command+length)='\0';
3996 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
3998 action_info.raised=MagickFalse;
3999 XDrawBeveledButton(display,&windows->widget,&action_info);
4003 if (key_symbol == XK_Control_L)
4005 state|=ControlState;
4008 if (state & ControlState)
4009 switch ((int) key_symbol)
4015 Erase the entire line of text.
4017 *reply_info.text='\0';
4018 reply_info.cursor=reply_info.text;
4019 reply_info.marker=reply_info.text;
4020 reply_info.highlight=MagickFalse;
4026 XEditText(display,&reply_info,key_symbol,command,state);
4027 XDrawMatteText(display,&windows->widget,&reply_info);
4033 command[MagickPathExtent];
4039 Respond to a user key release.
4041 if (event.xkey.window != windows->widget.id)
4043 (void) XLookupString((XKeyEvent *) &event.xkey,command,
4044 (int) sizeof(command),&key_symbol,(XComposeStatus *) NULL);
4045 if (key_symbol == XK_Control_L)
4046 state&=(~ControlState);
4051 if (event.xcrossing.window != windows->widget.id)
4053 state|=InactiveWidgetState;
4059 Discard pending button motion events.
4061 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
4062 if (state & InactiveWidgetState)
4064 if (action_info.raised == MatteIsActive(action_info,event.xmotion))
4067 Action button status changed.
4069 action_info.raised=action_info.raised == MagickFalse ?
4070 MagickTrue : MagickFalse;
4071 XDrawBeveledButton(display,&windows->widget,&action_info);
4074 if (cancel_info.raised == MatteIsActive(cancel_info,event.xmotion))
4077 Cancel button status changed.
4079 cancel_info.raised=cancel_info.raised == MagickFalse ?
4080 MagickTrue : MagickFalse;
4081 XDrawBeveledButton(display,&windows->widget,&cancel_info);
4086 case SelectionClear:
4088 reply_info.highlight=MagickFalse;
4089 XDrawMatteText(display,&windows->widget,&reply_info);
4092 case SelectionNotify:
4108 Obtain response from primary selection.
4110 if (event.xselection.property == (Atom) None)
4112 status=XGetWindowProperty(display,event.xselection.requestor,
4113 event.xselection.property,0L,2047L,MagickTrue,XA_STRING,&type,
4114 &format,&length,&after,&data);
4115 if ((status != Success) || (type != XA_STRING) || (format == 32) ||
4118 if ((Extent(reply_info.text)+length) >= (MagickPathExtent-1))
4119 (void) XBell(display,0);
4123 Insert primary selection in reply text.
4125 *(data+length)='\0';
4126 XEditText(display,&reply_info,(KeySym) XK_Insert,(char *) data,
4128 XDrawMatteText(display,&windows->widget,&reply_info);
4130 (void) XFree((void *) data);
4133 case SelectionRequest:
4138 XSelectionRequestEvent
4141 if (reply_info.highlight == MagickFalse)
4144 Set primary selection.
4146 request=(&(event.xselectionrequest));
4147 (void) XChangeProperty(request->display,request->requestor,
4148 request->property,request->target,8,PropModeReplace,
4149 (unsigned char *) primary_selection,Extent(primary_selection));
4150 notify.type=SelectionNotify;
4151 notify.display=request->display;
4152 notify.requestor=request->requestor;
4153 notify.selection=request->selection;
4154 notify.target=request->target;
4155 notify.time=request->time;
4156 if (request->property == None)
4157 notify.property=request->target;
4159 notify.property=request->property;
4160 (void) XSendEvent(request->display,request->requestor,False,0,
4161 (XEvent *) ¬ify);
4166 } while ((state & ExitState) == 0);
4167 XSetCursorState(display,windows,MagickFalse);
4168 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
4169 XCheckRefreshWindows(display,windows);
4171 if (special_info.raised)
4174 return(raised == MagickFalse);
4178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4182 % X F i l e B r o w s e r W i d g e t %
4186 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4188 % XFileBrowserWidget() displays a File Browser widget with a file query to the
4189 % user. The user keys a reply and presses the Action or Cancel button to
4190 % exit. The typed text is returned as the reply function parameter.
4192 % The format of the XFileBrowserWidget method is:
4194 % void XFileBrowserWidget(Display *display,XWindows *windows,
4195 % const char *action,char *reply)
4197 % A description of each parameter follows:
4199 % o display: Specifies a connection to an X server; returned from
4202 % o window: Specifies a pointer to a XWindows structure.
4204 % o action: Specifies a pointer to the action of this widget.
4206 % o reply: the response from the user is returned in this parameter.
4209 MagickPrivate void XFileBrowserWidget(Display *display,XWindows *windows,
4210 const char *action,char *reply)
4212 #define CancelButtonText "Cancel"
4213 #define DirectoryText "Directory:"
4214 #define FilenameText "File name:"
4215 #define GrabButtonText "Grab"
4216 #define FormatButtonText "Format"
4217 #define HomeButtonText "Home"
4218 #define UpButtonText "Up"
4223 home_directory[MagickPathExtent],
4224 primary_selection[MagickPathExtent],
4225 text[MagickPathExtent],
4226 working_path[MagickPathExtent];
4236 glob_pattern[MagickPathExtent] = "*",
4237 format[MagickPathExtent] = "miff";
4239 static MagickStatusType
4240 mask = (MagickStatusType) (CWWidth | CWHeight | CWX | CWY);
4286 Read filelist from current directory.
4288 assert(display != (Display *) NULL);
4289 assert(windows != (XWindows *) NULL);
4290 assert(action != (char *) NULL);
4291 assert(reply != (char *) NULL);
4292 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",action);
4293 XSetCursorState(display,windows,MagickTrue);
4294 XCheckRefreshWindows(display,windows);
4295 directory=getcwd(home_directory,MagickPathExtent);
4297 (void) CopyMagickString(working_path,home_directory,MagickPathExtent);
4298 filelist=ListFiles(working_path,glob_pattern,&files);
4299 if (filelist == (char **) NULL)
4302 Directory read failed.
4304 XNoticeWidget(display,windows,"Unable to read directory:",working_path);
4305 (void) XDialogWidget(display,windows,action,"Enter filename:",reply);
4309 Determine File Browser widget attributes.
4311 font_info=windows->widget.font_info;
4313 for (i=0; i < (ssize_t) files; i++)
4314 if (WidgetTextWidth(font_info,filelist[i]) > text_width)
4315 text_width=WidgetTextWidth(font_info,filelist[i]);
4316 width=WidgetTextWidth(font_info,(char *) action);
4317 if (WidgetTextWidth(font_info,GrabButtonText) > width)
4318 width=WidgetTextWidth(font_info,GrabButtonText);
4319 if (WidgetTextWidth(font_info,FormatButtonText) > width)
4320 width=WidgetTextWidth(font_info,FormatButtonText);
4321 if (WidgetTextWidth(font_info,CancelButtonText) > width)
4322 width=WidgetTextWidth(font_info,CancelButtonText);
4323 if (WidgetTextWidth(font_info,HomeButtonText) > width)
4324 width=WidgetTextWidth(font_info,HomeButtonText);
4325 if (WidgetTextWidth(font_info,UpButtonText) > width)
4326 width=WidgetTextWidth(font_info,UpButtonText);
4327 width+=QuantumMargin;
4328 if (WidgetTextWidth(font_info,DirectoryText) > width)
4329 width=WidgetTextWidth(font_info,DirectoryText);
4330 if (WidgetTextWidth(font_info,FilenameText) > width)
4331 width=WidgetTextWidth(font_info,FilenameText);
4332 height=(unsigned int) (font_info->ascent+font_info->descent);
4334 Position File Browser widget.
4336 windows->widget.width=width+MagickMin((int) text_width,(int) MaxTextWidth)+
4338 windows->widget.min_width=width+MinTextWidth+4*QuantumMargin;
4339 if (windows->widget.width < windows->widget.min_width)
4340 windows->widget.width=windows->widget.min_width;
4341 windows->widget.height=(unsigned int)
4342 (((81*height) >> 2)+((13*QuantumMargin) >> 1)+4);
4343 windows->widget.min_height=(unsigned int)
4344 (((23*height) >> 1)+((13*QuantumMargin) >> 1)+4);
4345 if (windows->widget.height < windows->widget.min_height)
4346 windows->widget.height=windows->widget.min_height;
4347 XConstrainWindowPosition(display,&windows->widget);
4349 Map File Browser widget.
4351 (void) CopyMagickString(windows->widget.name,"Browse and Select a File",
4353 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
4354 if (status != False)
4356 XSetWMName(display,windows->widget.id,&window_name);
4357 XSetWMIconName(display,windows->widget.id,&window_name);
4358 (void) XFree((void *) window_name.value);
4360 window_changes.width=(int) windows->widget.width;
4361 window_changes.height=(int) windows->widget.height;
4362 window_changes.x=windows->widget.x;
4363 window_changes.y=windows->widget.y;
4364 (void) XReconfigureWMWindow(display,windows->widget.id,
4365 windows->widget.screen,mask,&window_changes);
4366 (void) XMapRaised(display,windows->widget.id);
4367 windows->widget.mapped=MagickFalse;
4369 Respond to X events.
4371 XGetWidgetInfo((char *) NULL,&slider_info);
4372 XGetWidgetInfo((char *) NULL,&north_info);
4373 XGetWidgetInfo((char *) NULL,&south_info);
4374 XGetWidgetInfo((char *) NULL,&expose_info);
4376 anomaly=(LocaleCompare(action,"Composite") == 0) ||
4377 (LocaleCompare(action,"Open") == 0) || (LocaleCompare(action,"Map") == 0);
4379 delay=SuspendTime << 2;
4380 state=UpdateConfigurationState;
4383 if (state & UpdateConfigurationState)
4389 Initialize button information.
4391 XGetWidgetInfo(CancelButtonText,&cancel_info);
4392 cancel_info.width=width;
4393 cancel_info.height=(unsigned int) ((3*height) >> 1);
4395 (windows->widget.width-cancel_info.width-QuantumMargin-2);
4397 (windows->widget.height-cancel_info.height-QuantumMargin);
4398 XGetWidgetInfo(action,&action_info);
4399 action_info.width=width;
4400 action_info.height=(unsigned int) ((3*height) >> 1);
4401 action_info.x=cancel_info.x-(cancel_info.width+(QuantumMargin >> 1)+
4402 (action_info.bevel_width << 1));
4403 action_info.y=cancel_info.y;
4404 XGetWidgetInfo(GrabButtonText,&special_info);
4405 special_info.width=width;
4406 special_info.height=(unsigned int) ((3*height) >> 1);
4407 special_info.x=action_info.x-(action_info.width+(QuantumMargin >> 1)+
4408 (special_info.bevel_width << 1));
4409 special_info.y=action_info.y;
4410 if (anomaly == MagickFalse)
4415 special_info.text=(char *) FormatButtonText;
4416 p=reply+Extent(reply)-1;
4417 while ((p > (reply+1)) && (*(p-1) != '.'))
4419 if ((p > (reply+1)) && (*(p-1) == '.'))
4420 (void) CopyMagickString(format,p,MagickPathExtent);
4422 XGetWidgetInfo(UpButtonText,&up_info);
4423 up_info.width=width;
4424 up_info.height=(unsigned int) ((3*height) >> 1);
4425 up_info.x=QuantumMargin;
4426 up_info.y=((5*QuantumMargin) >> 1)+height;
4427 XGetWidgetInfo(HomeButtonText,&home_info);
4428 home_info.width=width;
4429 home_info.height=(unsigned int) ((3*height) >> 1);
4430 home_info.x=QuantumMargin;
4431 home_info.y=up_info.y+up_info.height+QuantumMargin;
4433 Initialize reply information.
4435 XGetWidgetInfo(reply,&reply_info);
4436 reply_info.raised=MagickFalse;
4437 reply_info.bevel_width--;
4438 reply_info.width=windows->widget.width-width-((6*QuantumMargin) >> 1);
4439 reply_info.height=height << 1;
4440 reply_info.x=(int) (width+(QuantumMargin << 1));
4441 reply_info.y=action_info.y-reply_info.height-QuantumMargin;
4443 Initialize scroll information.
4445 XGetWidgetInfo((char *) NULL,&scroll_info);
4446 scroll_info.bevel_width--;
4447 scroll_info.width=height;
4448 scroll_info.height=(unsigned int)
4449 (reply_info.y-up_info.y-(QuantumMargin >> 1));
4450 scroll_info.x=reply_info.x+(reply_info.width-scroll_info.width);
4451 scroll_info.y=up_info.y-reply_info.bevel_width;
4452 scroll_info.raised=MagickFalse;
4453 scroll_info.trough=MagickTrue;
4454 north_info=scroll_info;
4455 north_info.raised=MagickTrue;
4456 north_info.width-=(north_info.bevel_width << 1);
4457 north_info.height=north_info.width-1;
4458 north_info.x+=north_info.bevel_width;
4459 north_info.y+=north_info.bevel_width;
4460 south_info=north_info;
4461 south_info.y=scroll_info.y+scroll_info.height-scroll_info.bevel_width-
4464 slider_info=north_info;
4466 slider_info.width-=2;
4467 slider_info.min_y=north_info.y+north_info.height+north_info.bevel_width+
4468 slider_info.bevel_width+2;
4469 slider_info.height=scroll_info.height-((slider_info.min_y-
4470 scroll_info.y+1) << 1)+4;
4471 visible_files=scroll_info.height/(height+(height >> 3));
4472 if (files > visible_files)
4473 slider_info.height=(unsigned int)
4474 ((visible_files*slider_info.height)/files);
4475 slider_info.max_y=south_info.y-south_info.bevel_width-
4476 slider_info.bevel_width-2;
4477 slider_info.x=scroll_info.x+slider_info.bevel_width+1;
4478 slider_info.y=slider_info.min_y;
4479 expose_info=scroll_info;
4480 expose_info.y=slider_info.y;
4482 Initialize list information.
4484 XGetWidgetInfo((char *) NULL,&list_info);
4485 list_info.raised=MagickFalse;
4486 list_info.bevel_width--;
4487 list_info.width=(unsigned int)
4488 (scroll_info.x-reply_info.x-(QuantumMargin >> 1));
4489 list_info.height=scroll_info.height;
4490 list_info.x=reply_info.x;
4491 list_info.y=scroll_info.y;
4492 if (windows->widget.mapped == MagickFalse)
4493 state|=JumpListState;
4495 Initialize text information.
4498 XGetWidgetInfo(text,&text_info);
4499 text_info.center=MagickFalse;
4500 text_info.width=reply_info.width;
4501 text_info.height=height;
4502 text_info.x=list_info.x-(QuantumMargin >> 1);
4503 text_info.y=QuantumMargin;
4505 Initialize selection information.
4507 XGetWidgetInfo((char *) NULL,&selection_info);
4508 selection_info.center=MagickFalse;
4509 selection_info.width=list_info.width;
4510 selection_info.height=(unsigned int) ((9*height) >> 3);
4511 selection_info.x=list_info.x;
4512 state&=(~UpdateConfigurationState);
4514 if (state & RedrawWidgetState)
4517 Redraw File Browser window.
4520 y=text_info.y+((text_info.height-height) >> 1)+font_info->ascent;
4521 (void) XDrawString(display,windows->widget.id,
4522 windows->widget.annotate_context,x,y,DirectoryText,
4523 Extent(DirectoryText));
4524 (void) CopyMagickString(text_info.text,working_path,MagickPathExtent);
4525 (void) ConcatenateMagickString(text_info.text,DirectorySeparator,
4527 (void) ConcatenateMagickString(text_info.text,glob_pattern,
4529 XDrawWidgetText(display,&windows->widget,&text_info);
4530 XDrawBeveledButton(display,&windows->widget,&up_info);
4531 XDrawBeveledButton(display,&windows->widget,&home_info);
4532 XDrawBeveledMatte(display,&windows->widget,&list_info);
4533 XDrawBeveledMatte(display,&windows->widget,&scroll_info);
4534 XDrawTriangleNorth(display,&windows->widget,&north_info);
4535 XDrawBeveledButton(display,&windows->widget,&slider_info);
4536 XDrawTriangleSouth(display,&windows->widget,&south_info);
4538 y=reply_info.y+((reply_info.height-height) >> 1)+font_info->ascent;
4539 (void) XDrawString(display,windows->widget.id,
4540 windows->widget.annotate_context,x,y,FilenameText,
4541 Extent(FilenameText));
4542 XDrawBeveledMatte(display,&windows->widget,&reply_info);
4543 XDrawMatteText(display,&windows->widget,&reply_info);
4544 XDrawBeveledButton(display,&windows->widget,&special_info);
4545 XDrawBeveledButton(display,&windows->widget,&action_info);
4546 XDrawBeveledButton(display,&windows->widget,&cancel_info);
4547 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
4548 selection_info.id=(~0);
4549 state|=RedrawListState;
4550 state&=(~RedrawWidgetState);
4552 if (state & UpdateListState)
4563 checklist=ListFiles(working_path,glob_pattern,&number_files);
4564 if (checklist == (char **) NULL)
4567 Reply is a filename, exit.
4569 action_info.raised=MagickFalse;
4570 XDrawBeveledButton(display,&windows->widget,&action_info);
4573 for (i=0; i < (ssize_t) files; i++)
4574 filelist[i]=DestroyString(filelist[i]);
4575 if (filelist != (char **) NULL)
4576 filelist=(char **) RelinquishMagickMemory(filelist);
4583 scroll_info.height-((slider_info.min_y-scroll_info.y+1) << 1)+1;
4584 if (files > visible_files)
4585 slider_info.height=(unsigned int)
4586 ((visible_files*slider_info.height)/files);
4587 slider_info.max_y=south_info.y-south_info.bevel_width-
4588 slider_info.bevel_width-2;
4590 slider_info.y=slider_info.min_y;
4591 expose_info.y=slider_info.y;
4592 selection_info.id=(~0);
4594 state|=RedrawListState;
4596 Redraw directory name & reply.
4598 if (IsGlob(reply_info.text) == MagickFalse)
4600 *reply_info.text='\0';
4601 reply_info.cursor=reply_info.text;
4603 (void) CopyMagickString(text_info.text,working_path,MagickPathExtent);
4604 (void) ConcatenateMagickString(text_info.text,DirectorySeparator,
4606 (void) ConcatenateMagickString(text_info.text,glob_pattern,
4608 XDrawWidgetText(display,&windows->widget,&text_info);
4609 XDrawMatteText(display,&windows->widget,&reply_info);
4610 XDrawBeveledMatte(display,&windows->widget,&scroll_info);
4611 XDrawTriangleNorth(display,&windows->widget,&north_info);
4612 XDrawBeveledButton(display,&windows->widget,&slider_info);
4613 XDrawTriangleSouth(display,&windows->widget,&south_info);
4614 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
4615 state&=(~UpdateListState);
4617 if (state & JumpListState)
4620 Jump scroll to match user filename.
4623 for (i=0; i < (ssize_t) files; i++)
4624 if (LocaleCompare(filelist[i],reply) >= 0)
4627 (LocaleCompare(filelist[i],reply) == 0 ? i : ~0);
4630 if ((i < (ssize_t) slider_info.id) ||
4631 (i >= (ssize_t) (slider_info.id+visible_files)))
4632 slider_info.id=(int) i-(visible_files >> 1);
4633 selection_info.id=(~0);
4634 state|=RedrawListState;
4635 state&=(~JumpListState);
4637 if (state & RedrawListState)
4640 Determine slider id and position.
4642 if (slider_info.id >= (int) (files-visible_files))
4643 slider_info.id=(int) (files-visible_files);
4644 if ((slider_info.id < 0) || (files <= visible_files))
4646 slider_info.y=slider_info.min_y;
4648 slider_info.y+=(int) (slider_info.id*(slider_info.max_y-
4649 slider_info.min_y+1)/files);
4650 if (slider_info.id != selection_info.id)
4653 Redraw scroll bar and file names.
4655 selection_info.id=slider_info.id;
4656 selection_info.y=list_info.y+(height >> 3)+2;
4657 for (i=0; i < (ssize_t) visible_files; i++)
4659 selection_info.raised=(int) (slider_info.id+i) != list_info.id ?
4660 MagickTrue : MagickFalse;
4661 selection_info.text=(char *) NULL;
4662 if ((slider_info.id+i) < (ssize_t) files)
4663 selection_info.text=filelist[slider_info.id+i];
4664 XDrawWidgetText(display,&windows->widget,&selection_info);
4665 selection_info.y+=(int) selection_info.height;
4670 if (slider_info.y > expose_info.y)
4672 expose_info.height=(unsigned int) slider_info.y-expose_info.y;
4673 expose_info.y=slider_info.y-expose_info.height-
4674 slider_info.bevel_width-1;
4678 expose_info.height=(unsigned int) expose_info.y-slider_info.y;
4679 expose_info.y=slider_info.y+slider_info.height+
4680 slider_info.bevel_width+1;
4682 XDrawTriangleNorth(display,&windows->widget,&north_info);
4683 XDrawMatte(display,&windows->widget,&expose_info);
4684 XDrawBeveledButton(display,&windows->widget,&slider_info);
4685 XDrawTriangleSouth(display,&windows->widget,&south_info);
4686 expose_info.y=slider_info.y;
4688 state&=(~RedrawListState);
4691 Wait for next event.
4693 if (north_info.raised && south_info.raised)
4694 (void) XIfEvent(display,&event,XScreenEvent,(char *) windows);
4698 Brief delay before advancing scroll bar.
4700 XDelay(display,delay);
4702 (void) XCheckIfEvent(display,&event,XScreenEvent,(char *) windows);
4703 if (north_info.raised == MagickFalse)
4704 if (slider_info.id > 0)
4710 state|=RedrawListState;
4712 if (south_info.raised == MagickFalse)
4713 if (slider_info.id < (int) files)
4719 state|=RedrawListState;
4721 if (event.type != ButtonRelease)
4728 if (MatteIsActive(slider_info,event.xbutton))
4733 slider_info.active=MagickTrue;
4736 if (MatteIsActive(north_info,event.xbutton))
4737 if (slider_info.id > 0)
4742 north_info.raised=MagickFalse;
4744 state|=RedrawListState;
4747 if (MatteIsActive(south_info,event.xbutton))
4748 if (slider_info.id < (int) files)
4753 south_info.raised=MagickFalse;
4755 state|=RedrawListState;
4758 if (MatteIsActive(scroll_info,event.xbutton))
4763 if (event.xbutton.y < slider_info.y)
4764 slider_info.id-=(visible_files-1);
4766 slider_info.id+=(visible_files-1);
4767 state|=RedrawListState;
4770 if (MatteIsActive(list_info,event.xbutton))
4776 User pressed file matte.
4778 id=slider_info.id+(event.xbutton.y-(list_info.y+(height >> 1))+1)/
4779 selection_info.height;
4780 if (id >= (int) files)
4782 (void) CopyMagickString(reply_info.text,filelist[id],MagickPathExtent);
4783 reply_info.highlight=MagickFalse;
4784 reply_info.marker=reply_info.text;
4785 reply_info.cursor=reply_info.text+Extent(reply_info.text);
4786 XDrawMatteText(display,&windows->widget,&reply_info);
4787 if (id == list_info.id)
4792 p=reply_info.text+strlen(reply_info.text)-1;
4793 if (*p == *DirectorySeparator)
4794 ChopPathComponents(reply_info.text,1);
4795 (void) ConcatenateMagickString(working_path,DirectorySeparator,
4797 (void) ConcatenateMagickString(working_path,reply_info.text,
4800 state|=UpdateListState;
4802 selection_info.id=(~0);
4804 state|=RedrawListState;
4807 if (MatteIsActive(up_info,event.xbutton))
4810 User pressed Up button.
4812 up_info.raised=MagickFalse;
4813 XDrawBeveledButton(display,&windows->widget,&up_info);
4816 if (MatteIsActive(home_info,event.xbutton))
4819 User pressed Home button.
4821 home_info.raised=MagickFalse;
4822 XDrawBeveledButton(display,&windows->widget,&home_info);
4825 if (MatteIsActive(special_info,event.xbutton))
4828 User pressed Special button.
4830 special_info.raised=MagickFalse;
4831 XDrawBeveledButton(display,&windows->widget,&special_info);
4834 if (MatteIsActive(action_info,event.xbutton))
4837 User pressed action button.
4839 action_info.raised=MagickFalse;
4840 XDrawBeveledButton(display,&windows->widget,&action_info);
4843 if (MatteIsActive(cancel_info,event.xbutton))
4846 User pressed Cancel button.
4848 cancel_info.raised=MagickFalse;
4849 XDrawBeveledButton(display,&windows->widget,&cancel_info);
4852 if (MatteIsActive(reply_info,event.xbutton) == MagickFalse)
4854 if (event.xbutton.button != Button2)
4860 Move text cursor to position of button press.
4862 x=event.xbutton.x-reply_info.x-(QuantumMargin >> 2);
4863 for (i=1; i <= (ssize_t) Extent(reply_info.marker); i++)
4864 if (XTextWidth(font_info,reply_info.marker,(int) i) > x)
4866 reply_info.cursor=reply_info.marker+i-1;
4867 if (event.xbutton.time > (click_time+DoubleClick))
4868 reply_info.highlight=MagickFalse;
4872 Become the XA_PRIMARY selection owner.
4874 (void) CopyMagickString(primary_selection,reply_info.text,
4876 (void) XSetSelectionOwner(display,XA_PRIMARY,windows->widget.id,
4877 event.xbutton.time);
4878 reply_info.highlight=XGetSelectionOwner(display,XA_PRIMARY) ==
4879 windows->widget.id ? MagickTrue : MagickFalse;
4881 XDrawMatteText(display,&windows->widget,&reply_info);
4882 click_time=event.xbutton.time;
4886 Request primary selection.
4888 (void) XConvertSelection(display,XA_PRIMARY,XA_STRING,XA_STRING,
4889 windows->widget.id,event.xbutton.time);
4894 if (windows->widget.mapped == MagickFalse)
4896 if (north_info.raised == MagickFalse)
4899 User released up button.
4901 delay=SuspendTime << 2;
4902 north_info.raised=MagickTrue;
4903 XDrawTriangleNorth(display,&windows->widget,&north_info);
4905 if (south_info.raised == MagickFalse)
4908 User released down button.
4910 delay=SuspendTime << 2;
4911 south_info.raised=MagickTrue;
4912 XDrawTriangleSouth(display,&windows->widget,&south_info);
4914 if (slider_info.active)
4917 Stop tracking slider.
4919 slider_info.active=MagickFalse;
4922 if (up_info.raised == MagickFalse)
4924 if (event.xbutton.window == windows->widget.id)
4925 if (MatteIsActive(up_info,event.xbutton))
4927 ChopPathComponents(working_path,1);
4928 if (*working_path == '\0')
4929 (void) CopyMagickString(working_path,DirectorySeparator,
4931 state|=UpdateListState;
4933 up_info.raised=MagickTrue;
4934 XDrawBeveledButton(display,&windows->widget,&up_info);
4936 if (home_info.raised == MagickFalse)
4938 if (event.xbutton.window == windows->widget.id)
4939 if (MatteIsActive(home_info,event.xbutton))
4941 (void) CopyMagickString(working_path,home_directory,
4943 state|=UpdateListState;
4945 home_info.raised=MagickTrue;
4946 XDrawBeveledButton(display,&windows->widget,&home_info);
4948 if (special_info.raised == MagickFalse)
4950 if (anomaly == MagickFalse)
4962 Let user select image format.
4964 exception=AcquireExceptionInfo();
4965 formats=GetMagickList("*",&number_formats,exception);
4966 exception=DestroyExceptionInfo(exception);
4967 (void) XCheckDefineCursor(display,windows->widget.id,
4968 windows->widget.busy_cursor);
4969 windows->popup.x=windows->widget.x+60;
4970 windows->popup.y=windows->widget.y+60;
4971 XListBrowserWidget(display,windows,&windows->popup,
4972 (const char **) formats,"Select","Select image format type:",
4974 XSetCursorState(display,windows,MagickTrue);
4975 (void) XCheckDefineCursor(display,windows->widget.id,
4976 windows->widget.cursor);
4977 LocaleLower(format);
4978 AppendImageFormat(format,reply_info.text);
4979 reply_info.cursor=reply_info.text+Extent(reply_info.text);
4980 XDrawMatteText(display,&windows->widget,&reply_info);
4981 special_info.raised=MagickTrue;
4982 XDrawBeveledButton(display,&windows->widget,&special_info);
4983 for (i=0; i < (ssize_t) number_formats; i++)
4984 formats[i]=DestroyString(formats[i]);
4985 formats=(char **) RelinquishMagickMemory(formats);
4988 if (event.xbutton.window == windows->widget.id)
4989 if (MatteIsActive(special_info,event.xbutton))
4991 (void) CopyMagickString(working_path,"x:",MagickPathExtent);
4994 special_info.raised=MagickTrue;
4995 XDrawBeveledButton(display,&windows->widget,&special_info);
4997 if (action_info.raised == MagickFalse)
4999 if (event.xbutton.window == windows->widget.id)
5001 if (MatteIsActive(action_info,event.xbutton))
5003 if (*reply_info.text == '\0')
5004 (void) XBell(display,0);
5009 action_info.raised=MagickTrue;
5010 XDrawBeveledButton(display,&windows->widget,&action_info);
5012 if (cancel_info.raised == MagickFalse)
5014 if (event.xbutton.window == windows->widget.id)
5015 if (MatteIsActive(cancel_info,event.xbutton))
5017 *reply_info.text='\0';
5021 cancel_info.raised=MagickTrue;
5022 XDrawBeveledButton(display,&windows->widget,&cancel_info);
5029 If client window delete message, exit.
5031 if (event.xclient.message_type != windows->wm_protocols)
5033 if (*event.xclient.data.l == (int) windows->wm_take_focus)
5035 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
5036 (Time) event.xclient.data.l[1]);
5039 if (*event.xclient.data.l != (int) windows->wm_delete_window)
5041 if (event.xclient.window == windows->widget.id)
5043 *reply_info.text='\0';
5049 case ConfigureNotify:
5052 Update widget configuration.
5054 if (event.xconfigure.window != windows->widget.id)
5056 if ((event.xconfigure.width == (int) windows->widget.width) &&
5057 (event.xconfigure.height == (int) windows->widget.height))
5059 windows->widget.width=(unsigned int)
5060 MagickMax(event.xconfigure.width,(int) windows->widget.min_width);
5061 windows->widget.height=(unsigned int)
5062 MagickMax(event.xconfigure.height,(int) windows->widget.min_height);
5063 state|=UpdateConfigurationState;
5068 if (event.xcrossing.window != windows->widget.id)
5070 state&=(~InactiveWidgetState);
5075 if (event.xexpose.window != windows->widget.id)
5077 if (event.xexpose.count != 0)
5079 state|=RedrawWidgetState;
5085 command[MagickPathExtent];
5094 Respond to a user key press.
5096 if (event.xkey.window != windows->widget.id)
5098 length=XLookupString((XKeyEvent *) &event.xkey,command,
5099 (int) sizeof(command),&key_symbol,(XComposeStatus *) NULL);
5100 *(command+length)='\0';
5101 if (AreaIsActive(scroll_info,event.xkey))
5106 switch ((int) key_symbol)
5129 slider_info.id-=visible_files;
5135 slider_info.id+=visible_files;
5141 slider_info.id=(int) files;
5145 state|=RedrawListState;
5148 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
5151 Read new directory or glob patterm.
5153 if (*reply_info.text == '\0')
5155 if (IsGlob(reply_info.text))
5156 (void) CopyMagickString(glob_pattern,reply_info.text,
5160 (void) ConcatenateMagickString(working_path,DirectorySeparator,
5162 (void) ConcatenateMagickString(working_path,reply_info.text,
5164 if (*working_path == '~')
5165 ExpandFilename(working_path);
5168 state|=UpdateListState;
5171 if (key_symbol == XK_Control_L)
5173 state|=ControlState;
5176 if (state & ControlState)
5177 switch ((int) key_symbol)
5183 Erase the entire line of text.
5185 *reply_info.text='\0';
5186 reply_info.cursor=reply_info.text;
5187 reply_info.marker=reply_info.text;
5188 reply_info.highlight=MagickFalse;
5194 XEditText(display,&reply_info,key_symbol,command,state);
5195 XDrawMatteText(display,&windows->widget,&reply_info);
5196 state|=JumpListState;
5202 command[MagickPathExtent];
5208 Respond to a user key release.
5210 if (event.xkey.window != windows->widget.id)
5212 (void) XLookupString((XKeyEvent *) &event.xkey,command,
5213 (int) sizeof(command),&key_symbol,(XComposeStatus *) NULL);
5214 if (key_symbol == XK_Control_L)
5215 state&=(~ControlState);
5220 if (event.xcrossing.window != windows->widget.id)
5222 state|=InactiveWidgetState;
5234 Discard pending button motion events.
5236 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
5237 if (slider_info.active)
5242 slider_info.y=event.xmotion.y-
5243 ((slider_info.height+slider_info.bevel_width) >> 1)+1;
5244 if (slider_info.y < slider_info.min_y)
5245 slider_info.y=slider_info.min_y;
5246 if (slider_info.y > slider_info.max_y)
5247 slider_info.y=slider_info.max_y;
5249 if (slider_info.y != slider_info.min_y)
5250 slider_info.id=(int) ((files*(slider_info.y-slider_info.min_y+1))/
5251 (slider_info.max_y-slider_info.min_y+1));
5252 state|=RedrawListState;
5255 if (state & InactiveWidgetState)
5257 if (up_info.raised == MatteIsActive(up_info,event.xmotion))
5260 Up button status changed.
5262 up_info.raised=!up_info.raised;
5263 XDrawBeveledButton(display,&windows->widget,&up_info);
5266 if (home_info.raised == MatteIsActive(home_info,event.xmotion))
5269 Home button status changed.
5271 home_info.raised=!home_info.raised;
5272 XDrawBeveledButton(display,&windows->widget,&home_info);
5275 if (special_info.raised == MatteIsActive(special_info,event.xmotion))
5278 Grab button status changed.
5280 special_info.raised=!special_info.raised;
5281 XDrawBeveledButton(display,&windows->widget,&special_info);
5284 if (action_info.raised == MatteIsActive(action_info,event.xmotion))
5287 Action button status changed.
5289 action_info.raised=action_info.raised == MagickFalse ?
5290 MagickTrue : MagickFalse;
5291 XDrawBeveledButton(display,&windows->widget,&action_info);
5294 if (cancel_info.raised == MatteIsActive(cancel_info,event.xmotion))
5297 Cancel button status changed.
5299 cancel_info.raised=cancel_info.raised == MagickFalse ?
5300 MagickTrue : MagickFalse;
5301 XDrawBeveledButton(display,&windows->widget,&cancel_info);
5306 case SelectionClear:
5308 reply_info.highlight=MagickFalse;
5309 XDrawMatteText(display,&windows->widget,&reply_info);
5312 case SelectionNotify:
5328 Obtain response from primary selection.
5330 if (event.xselection.property == (Atom) None)
5332 status=XGetWindowProperty(display,event.xselection.requestor,
5333 event.xselection.property,0L,2047L,MagickTrue,XA_STRING,&type,
5334 &format,&length,&after,&data);
5335 if ((status != Success) || (type != XA_STRING) || (format == 32) ||
5338 if ((Extent(reply_info.text)+length) >= (MagickPathExtent-1))
5339 (void) XBell(display,0);
5343 Insert primary selection in reply text.
5345 *(data+length)='\0';
5346 XEditText(display,&reply_info,(KeySym) XK_Insert,(char *) data,
5348 XDrawMatteText(display,&windows->widget,&reply_info);
5349 state|=JumpListState;
5350 state|=RedrawActionState;
5352 (void) XFree((void *) data);
5355 case SelectionRequest:
5360 XSelectionRequestEvent
5363 if (reply_info.highlight == MagickFalse)
5366 Set primary selection.
5368 request=(&(event.xselectionrequest));
5369 (void) XChangeProperty(request->display,request->requestor,
5370 request->property,request->target,8,PropModeReplace,
5371 (unsigned char *) primary_selection,Extent(primary_selection));
5372 notify.type=SelectionNotify;
5373 notify.display=request->display;
5374 notify.requestor=request->requestor;
5375 notify.selection=request->selection;
5376 notify.target=request->target;
5377 notify.time=request->time;
5378 if (request->property == None)
5379 notify.property=request->target;
5381 notify.property=request->property;
5382 (void) XSendEvent(request->display,request->requestor,False,0,
5383 (XEvent *) ¬ify);
5388 } while ((state & ExitState) == 0);
5389 XSetCursorState(display,windows,MagickFalse);
5390 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
5391 XCheckRefreshWindows(display,windows);
5395 for (i=0; i < (ssize_t) files; i++)
5396 filelist[i]=DestroyString(filelist[i]);
5397 if (filelist != (char **) NULL)
5398 filelist=(char **) RelinquishMagickMemory(filelist);
5401 (void) ConcatenateMagickString(working_path,DirectorySeparator,
5403 (void) ConcatenateMagickString(working_path,reply,MagickPathExtent);
5405 (void) CopyMagickString(reply,working_path,MagickPathExtent);
5407 ExpandFilename(reply);
5411 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5415 % X F o n t B r o w s e r W i d g e t %
5419 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5421 % XFontBrowserWidget() displays a Font Browser widget with a font query to the
5422 % user. The user keys a reply and presses the Action or Cancel button to
5423 % exit. The typed text is returned as the reply function parameter.
5425 % The format of the XFontBrowserWidget method is:
5427 % void XFontBrowserWidget(Display *display,XWindows *windows,
5428 % const char *action,char *reply)
5430 % A description of each parameter follows:
5432 % o display: Specifies a connection to an X server; returned from
5435 % o window: Specifies a pointer to a XWindows structure.
5437 % o action: Specifies a pointer to the action of this widget.
5439 % o reply: the response from the user is returned in this parameter.
5444 #if defined(__cplusplus) || defined(c_plusplus)
5448 static int FontCompare(const void *x,const void *y)
5454 p=(char *) *((char **) x);
5455 q=(char *) *((char **) y);
5456 while ((*p != '\0') && (*q != '\0') && (*p == *q))
5464 #if defined(__cplusplus) || defined(c_plusplus)
5468 MagickPrivate void XFontBrowserWidget(Display *display,XWindows *windows,
5469 const char *action,char *reply)
5471 #define BackButtonText "Back"
5472 #define CancelButtonText "Cancel"
5473 #define FontnameText "Name:"
5474 #define FontPatternText "Pattern:"
5475 #define ResetButtonText "Reset"
5478 back_pattern[MagickPathExtent],
5481 primary_selection[MagickPathExtent],
5482 reset_pattern[MagickPathExtent],
5483 text[MagickPathExtent];
5494 glob_pattern[MagickPathExtent] = "*";
5496 static MagickStatusType
5497 mask = (MagickStatusType) (CWWidth | CWHeight | CWX | CWY);
5541 Get font list and sort in ascending order.
5543 assert(display != (Display *) NULL);
5544 assert(windows != (XWindows *) NULL);
5545 assert(action != (char *) NULL);
5546 assert(reply != (char *) NULL);
5547 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",action);
5548 XSetCursorState(display,windows,MagickTrue);
5549 XCheckRefreshWindows(display,windows);
5550 (void) CopyMagickString(back_pattern,glob_pattern,MagickPathExtent);
5551 (void) CopyMagickString(reset_pattern,"*",MagickPathExtent);
5552 fontlist=XListFonts(display,glob_pattern,32767,&fonts);
5556 Pattern failed, obtain all the fonts.
5558 XNoticeWidget(display,windows,"Unable to obtain fonts names:",
5560 (void) CopyMagickString(glob_pattern,"*",MagickPathExtent);
5561 fontlist=XListFonts(display,glob_pattern,32767,&fonts);
5562 if (fontlist == (char **) NULL)
5564 XNoticeWidget(display,windows,"Unable to obtain fonts names:",
5570 Sort font list in ascending order.
5573 fontlist=(char **) AcquireQuantumMemory((size_t) fonts,sizeof(*fontlist));
5574 if (fontlist == (char **) NULL)
5576 XNoticeWidget(display,windows,"MemoryAllocationFailed",
5577 "UnableToViewFonts");
5580 for (i=0; i < fonts; i++)
5581 fontlist[i]=listhead[i];
5582 qsort((void *) fontlist,(size_t) fonts,sizeof(*fontlist),FontCompare);
5584 Determine Font Browser widget attributes.
5586 font_info=windows->widget.font_info;
5588 for (i=0; i < fonts; i++)
5589 if (WidgetTextWidth(font_info,fontlist[i]) > text_width)
5590 text_width=WidgetTextWidth(font_info,fontlist[i]);
5591 width=WidgetTextWidth(font_info,(char *) action);
5592 if (WidgetTextWidth(font_info,CancelButtonText) > width)
5593 width=WidgetTextWidth(font_info,CancelButtonText);
5594 if (WidgetTextWidth(font_info,ResetButtonText) > width)
5595 width=WidgetTextWidth(font_info,ResetButtonText);
5596 if (WidgetTextWidth(font_info,BackButtonText) > width)
5597 width=WidgetTextWidth(font_info,BackButtonText);
5598 width+=QuantumMargin;
5599 if (WidgetTextWidth(font_info,FontPatternText) > width)
5600 width=WidgetTextWidth(font_info,FontPatternText);
5601 if (WidgetTextWidth(font_info,FontnameText) > width)
5602 width=WidgetTextWidth(font_info,FontnameText);
5603 height=(unsigned int) (font_info->ascent+font_info->descent);
5605 Position Font Browser widget.
5607 windows->widget.width=width+MagickMin((int) text_width,(int) MaxTextWidth)+
5609 windows->widget.min_width=width+MinTextWidth+4*QuantumMargin;
5610 if (windows->widget.width < windows->widget.min_width)
5611 windows->widget.width=windows->widget.min_width;
5612 windows->widget.height=(unsigned int)
5613 (((85*height) >> 2)+((13*QuantumMargin) >> 1)+4);
5614 windows->widget.min_height=(unsigned int)
5615 (((27*height) >> 1)+((13*QuantumMargin) >> 1)+4);
5616 if (windows->widget.height < windows->widget.min_height)
5617 windows->widget.height=windows->widget.min_height;
5618 XConstrainWindowPosition(display,&windows->widget);
5620 Map Font Browser widget.
5622 (void) CopyMagickString(windows->widget.name,"Browse and Select a Font",
5624 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
5625 if (status != False)
5627 XSetWMName(display,windows->widget.id,&window_name);
5628 XSetWMIconName(display,windows->widget.id,&window_name);
5629 (void) XFree((void *) window_name.value);
5631 window_changes.width=(int) windows->widget.width;
5632 window_changes.height=(int) windows->widget.height;
5633 window_changes.x=windows->widget.x;
5634 window_changes.y=windows->widget.y;
5635 (void) XReconfigureWMWindow(display,windows->widget.id,
5636 windows->widget.screen,mask,&window_changes);
5637 (void) XMapRaised(display,windows->widget.id);
5638 windows->widget.mapped=MagickFalse;
5640 Respond to X events.
5642 XGetWidgetInfo((char *) NULL,&slider_info);
5643 XGetWidgetInfo((char *) NULL,&north_info);
5644 XGetWidgetInfo((char *) NULL,&south_info);
5645 XGetWidgetInfo((char *) NULL,&expose_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);