43#include "MagickCore/studio.h"
44#include "MagickCore/color.h"
45#include "MagickCore/color-private.h"
46#include "MagickCore/exception.h"
47#include "MagickCore/exception-private.h"
48#include "MagickCore/image.h"
49#include "MagickCore/magick.h"
50#include "MagickCore/memory_.h"
51#include "MagickCore/string_.h"
52#include "MagickCore/timer-private.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 >= (matte_info.y-(int) matte_info.bevel_width)) && \
68 (position.y < (matte_info.y+(int) matte_info.height+(int) matte_info.bevel_width))) \
69 ? MagickTrue : MagickFalse)
70#define Extent(s) ((int) strlen(s))
71#define MatteIsActive(matte_info,position) ( \
72 ((position.x >= (matte_info.x-(int) matte_info.bevel_width)) && \
73 (position.y >= (matte_info.y-(int) matte_info.bevel_width)) && \
74 (position.x < (matte_info.x+(int) matte_info.width+(int) matte_info.bevel_width)) && \
75 (position.y < (matte_info.y+(int) matte_info.height+(int) matte_info.bevel_width))) \
76 ? MagickTrue : MagickFalse)
77#define MaxTextWidth ((unsigned int) (255*XTextWidth(font_info,"_",1)))
78#define MinTextWidth ((unsigned int) (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
104typedef struct _XWidgetInfo
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
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);
190MagickPrivate
void DestroyXWidget(
void)
192 if (selection_info != (XWidgetInfo *) NULL)
193 selection_info=(XWidgetInfo *) RelinquishMagickMemory(selection_info);
226static void XDrawBevel(Display *display,
const XWindowInfo *window_info,
227 const XWidgetInfo *bevel_info)
245 y1=bevel_info->y+(int) bevel_info->height;
246 x2=bevel_info->x+(int) bevel_info->width;
248 bevel_width=bevel_info->bevel_width;
255 points[3].x=x2+(int) bevel_width;
256 points[3].y=y2-(int) bevel_width;
257 points[4].x=x1-(int) bevel_width;
258 points[4].y=y2-(int) bevel_width;
259 points[5].x=x1-(int) bevel_width;
260 points[5].y=y1+(int) 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);
273 points[3].x=x2+(int) bevel_width;
274 points[3].y=y2-(int) bevel_width;
275 points[4].x=x2+(int) bevel_width;
276 points[4].y=y1+(int) bevel_width;
277 points[5].x=x1-(int) bevel_width;
278 points[5].y=y1+(int) 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);
316static 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-(int) button_info->bevel_width-1;
340 y=button_info->y-(int) 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+(int) (QuantumMargin >> 1);
362 if (button_info->center)
363 x=button_info->x+(int) (button_info->width >> 1)-(int) (width >> 1);
364 y=button_info->y+(int) (((
int) button_info->height-(
int)
365 (font_info->ascent+font_info->descent)) >> 1)+font_info->ascent;
366 if ((
int) button_info->width == (QuantumMargin >> 1))
371 XSetTextColor(display,window_info,MagickTrue);
372 x=button_info->x+(int) button_info->width+(
int) 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);
418static 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);
456static 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);
504static 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+(int) (QuantumMargin >> 2);
539 y=text_info->y+font_info->ascent+(int) (text_info->height >> 2);
540 width=text_info->width-(
unsigned int) (QuantumMargin >> 1);
541 height=(
unsigned int) (font_info->ascent+font_info->descent);
542 if (*text_info->text ==
'\0')
547 (void) XDrawLine(display,window_info->id,window_info->annotate_context,
548 x,y+3,x,y-(
int) height+3);
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;
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;
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,
642static void XDrawTriangleEast(Display *display,
const XWindowInfo *window_info,
643 const XWidgetInfo *triangle_info)
667 x2=triangle_info->x+(int) triangle_info->width;
668 y2=triangle_info->y+(int) (triangle_info->height >> 1);
670 y3=triangle_info->y+(int) 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-(int) bevel_width;
689 points[2].y=y3+(int) bevel_width;
690 points[3].x=x2+(int) 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-(int) bevel_width+1;
703 points[2].y=y1-(int) bevel_width;
704 points[3].x=x3-(int) bevel_width+1;
705 points[3].y=y3+(int) 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+(int) bevel_width;
718 points[3].x=x1-(int) bevel_width;
719 points[3].y=y1-(int) 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)
728 font_info=window_info->font_info;
729 XSetTextColor(display,window_info,MagickTrue);
730 x1=triangle_info->x+(int) triangle_info->width+(
int)
731 triangle_info->bevel_width+(QuantumMargin >> 1);
732 y1=triangle_info->y+(((int) triangle_info->height-(int)
733 (font_info->ascent+font_info->descent)) >> 1)+(
int) font_info->ascent;
734 (void) XDrawString(display,window_info->id,window_info->widget_context,x1,y1,
735 triangle_info->text,Extent(triangle_info->text));
768static void XDrawTriangleNorth(Display *display,
const XWindowInfo *window_info,
769 const XWidgetInfo *triangle_info)
789 y1=triangle_info->y+(int) triangle_info->height;
790 x2=triangle_info->x+(int) (triangle_info->width >> 1);
792 x3=triangle_info->x+(int) triangle_info->width;
793 y3=triangle_info->y+(int) 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-(int) bevel_width-2;
813 points[3].x=x1-(int) bevel_width-1;
814 points[3].y=y1+(int) 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+(int) bevel_width;
826 points[2].y=y3+(int) bevel_width;
828 points[3].y=y2-(int) 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-(int) bevel_width;
840 points[2].y=y1+(int) bevel_width;
841 points[3].x=x3+(int) bevel_width;
842 points[3].y=y3+(int) 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);
878static void XDrawTriangleSouth(Display *display,
const XWindowInfo *window_info,
879 const XWidgetInfo *triangle_info)
900 x2=triangle_info->x+(int) (triangle_info->width >> 1);
901 y2=triangle_info->y+(int) triangle_info->height;
902 x3=triangle_info->x+(int) 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-(int) bevel_width;
922 points[2].y=y1-(int) bevel_width;
923 points[3].x=x3+(int) bevel_width;
924 points[3].y=y3-(int) 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-(int) bevel_width;
935 points[2].x=x3+(int) bevel_width;
936 points[2].y=y3-(int) bevel_width;
938 points[3].y=y2+(int) 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+(int) bevel_width;
951 points[3].x=x1-(int) bevel_width;
952 points[3].y=y1-(int) 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);
987static void XDrawWidgetText(Display *display,
const XWindowInfo *window_info,
988 XWidgetInfo *text_info)
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')
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+(int) (QuantumMargin >> 1);
1037 if (text_info->center)
1038 x=text_info->x+(int) (text_info->width >> 1)-(int) (width >> 1);
1039 if (text_info->raised)
1040 if (width > (text_info->width-(
unsigned int) QuantumMargin))
1041 x+=(int) (text_info->width-(
unsigned int) QuantumMargin-width);
1042 height=(
unsigned int) (font_info->ascent+font_info->descent);
1043 y=text_info->y+(int) ((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+(
int)
1051 text_info->height-1);
1088static void XEditText(Display *display,XWidgetInfo *text_info,
1089 const KeySym key_symbol,
char *text,
const size_t state)
1091 switch ((
int) key_symbol)
1096 if (text_info->highlight)
1101 *text_info->text=
'\0';
1102 text_info->cursor=text_info->text;
1103 text_info->marker=text_info->text;
1104 text_info->highlight=MagickFalse;
1109 if (text_info->cursor != text_info->text)
1111 text_info->cursor--;
1112 (void) memmove(text_info->cursor,text_info->cursor+1,
1113 strlen(text_info->cursor+1)+1);
1114 text_info->highlight=MagickFalse;
1125 if (text_info->cursor == text_info->text)
1127 text_info->cursor--;
1136 if (text_info->cursor == (text_info->text+Extent(text_info->text)))
1138 text_info->cursor++;
1150 if (state & ControlState)
1154 if ((Extent(text_info->text)+1) >= (
int) MagickPathExtent)
1155 (void) XBell(display,0);
1158 if (text_info->highlight)
1163 *text_info->text=
'\0';
1164 text_info->cursor=text_info->text;
1165 text_info->marker=text_info->text;
1166 text_info->highlight=MagickFalse;
1171 q=text_info->text+Extent(text_info->text)+strlen(text);
1172 for (i=0; i <= Extent(text_info->cursor); i++)
1174 if ((q-Extent(text)) > text_info->text)
1175 *q=(*(q-Extent(text)));
1179 for (i=0; i < Extent(text); i++)
1180 *text_info->cursor++=(*p++);
1211static void XGetWidgetInfo(
const char *text,XWidgetInfo *widget_info)
1216 widget_info->id=(~0);
1217 widget_info->bevel_width=3;
1218 widget_info->width=1;
1219 widget_info->height=1;
1222 widget_info->min_y=0;
1223 widget_info->max_y=0;
1224 widget_info->raised=MagickTrue;
1225 widget_info->active=MagickFalse;
1226 widget_info->center=MagickTrue;
1227 widget_info->trough=MagickFalse;
1228 widget_info->highlight=MagickFalse;
1229 widget_info->text=(
char *) text;
1230 widget_info->cursor=(
char *) text;
1231 if (text != (
char *) NULL)
1232 widget_info->cursor+=Extent(text);
1233 widget_info->marker=(
char *) text;
1267static void XHighlightWidget(Display *display,
const XWindowInfo *window_info,
1268 const int x,
const int y)
1273 XSetBevelColor(display,window_info,MagickTrue);
1274 (void) XDrawRectangle(display,window_info->id,window_info->widget_context,x,y,
1275 (
unsigned int) ((
int) window_info->width-(x << 1)),(
unsigned int)
1276 ((
int) window_info->height-(y << 1)));
1277 (void) XDrawRectangle(display,window_info->id,window_info->widget_context,
1278 x-1,y-1,(
unsigned int) ((
int) window_info->width-(x << 1)+1),(
unsigned int)
1279 ((
int) window_info->height-(y << 1)+1));
1280 XSetBevelColor(display,window_info,MagickFalse);
1281 (void) XDrawRectangle(display,window_info->id,window_info->widget_context,
1282 x-1,y-1,(
unsigned int) ((
int) window_info->width-(x << 1)),(
unsigned int)
1283 ((
int) window_info->height-(y << 1)));
1284 (void) XSetFillStyle(display,window_info->widget_context,FillSolid);
1316#if defined(__cplusplus) || defined(c_plusplus)
1320static int XScreenEvent(Display *display,XEvent *event,
char *data)
1325 windows=(XWindows *) data;
1326 if (event->xany.window == windows->popup.id)
1328 if (event->type == MapNotify)
1329 windows->popup.mapped=MagickTrue;
1330 if (event->type == UnmapNotify)
1331 windows->popup.mapped=MagickFalse;
1334 if (event->xany.window == windows->widget.id)
1336 if (event->type == MapNotify)
1337 windows->widget.mapped=MagickTrue;
1338 if (event->type == UnmapNotify)
1339 windows->widget.mapped=MagickFalse;
1342 switch (event->type)
1346 if ((event->xbutton.button == Button3) &&
1347 (event->xbutton.state & Mod1Mask))
1352 event->xbutton.button=Button2;
1353 event->xbutton.state&=(
unsigned int) (~Mod1Mask);
1359 if (event->xexpose.window == windows->image.id)
1361 XRefreshWindow(display,&windows->image,event);
1364 if (event->xexpose.window == windows->magnify.id)
1365 if (event->xexpose.count == 0)
1366 if (windows->magnify.mapped)
1371 exception=AcquireExceptionInfo();
1372 XMakeMagnifyImage(display,windows,exception);
1373 exception=DestroyExceptionInfo(exception);
1376 if (event->xexpose.window == windows->command.id)
1377 if (event->xexpose.count == 0)
1379 (void) XCommandWidget(display,windows,(
const char *
const *) NULL,
1390 if (event->xfocus.window == windows->image.id)
1391 (void) XSetInputFocus(display,windows->image.id,RevertToNone,
1399 case SelectionNotify:
1404 return(MagickFalse);
1407#if defined(__cplusplus) || defined(c_plusplus)
1439static void XSetBevelColor(Display *display,
const XWindowInfo *window_info,
1440 const MagickStatusType raised)
1442 if (window_info->depth == 1)
1450 (void) XSetBackground(display,window_info->widget_context,
1451 XBlackPixel(display,window_info->screen));
1452 (void) XSetForeground(display,window_info->widget_context,
1453 XWhitePixel(display,window_info->screen));
1454 (void) XSetFillStyle(display,window_info->widget_context,
1455 FillOpaqueStippled);
1456 stipple=window_info->highlight_stipple;
1457 if (raised == MagickFalse)
1458 stipple=window_info->shadow_stipple;
1459 (void) XSetStipple(display,window_info->widget_context,stipple);
1463 (void) XSetForeground(display,window_info->widget_context,
1464 window_info->pixel_info->highlight_color.pixel);
1466 (
void) XSetForeground(display,window_info->widget_context,
1467 window_info->pixel_info->shadow_color.pixel);
1497static void XSetMatteColor(Display *display,
const XWindowInfo *window_info,
1498 const MagickStatusType raised)
1500 if (window_info->depth == 1)
1506 (void) XSetForeground(display,window_info->widget_context,
1507 XWhitePixel(display,window_info->screen));
1509 (
void) XSetForeground(display,window_info->widget_context,
1510 XBlackPixel(display,window_info->screen));
1514 (void) XSetForeground(display,window_info->widget_context,
1515 window_info->pixel_info->matte_color.pixel);
1517 (
void) XSetForeground(display,window_info->widget_context,
1518 window_info->pixel_info->depth_color.pixel);
1549static void XSetTextColor(Display *display,
const XWindowInfo *window_info,
1550 const MagickStatusType raised)
1556 if (window_info->depth == 1)
1562 (void) XSetForeground(display,window_info->widget_context,
1563 XBlackPixel(display,window_info->screen));
1565 (
void) XSetForeground(display,window_info->widget_context,
1566 XWhitePixel(display,window_info->screen));
1569 foreground=(ssize_t) XPixelIntensity(
1570 &window_info->pixel_info->foreground_color);
1571 matte=(ssize_t) XPixelIntensity(&window_info->pixel_info->matte_color);
1572 if (MagickAbsoluteValue((
int) (foreground-matte)) > (65535L >> 3))
1573 (void) XSetForeground(display,window_info->widget_context,
1574 window_info->pixel_info->foreground_color.pixel);
1576 (
void) XSetForeground(display,window_info->widget_context,
1577 window_info->pixel_info->background_color.pixel);
1612MagickPrivate
void XColorBrowserWidget(Display *display,XWindows *windows,
1613 const char *action,
char *reply)
1615#define CancelButtonText "Cancel"
1616#define ColornameText "Name:"
1617#define ColorPatternText "Pattern:"
1618#define GrabButtonText "Grab"
1619#define ResetButtonText "Reset"
1623 primary_selection[MagickPathExtent],
1624 reset_pattern[MagickPathExtent],
1625 text[MagickPathExtent];
1638 glob_pattern[MagickPathExtent] =
"*";
1640 static MagickStatusType
1641 mask = (MagickStatusType) (CWWidth | CWHeight | CWX | CWY);
1691 assert(display != (Display *) NULL);
1692 assert(windows != (XWindows *) NULL);
1693 assert(action != (
char *) NULL);
1694 assert(reply != (
char *) NULL);
1695 if (IsEventLogging() != MagickFalse)
1696 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",action);
1697 XSetCursorState(display,windows,MagickTrue);
1698 XCheckRefreshWindows(display,windows);
1699 (void) CopyMagickString(reset_pattern,
"*",MagickPathExtent);
1700 exception=AcquireExceptionInfo();
1701 colorlist=GetColorList(glob_pattern,&colors,exception);
1702 if (colorlist == (
char **) NULL)
1707 (void) CopyMagickString(glob_pattern,
"*",MagickPathExtent);
1708 colorlist=GetColorList(glob_pattern,&colors,exception);
1709 if (colorlist == (
char **) NULL)
1711 XNoticeWidget(display,windows,
"Unable to obtain colors names:",
1713 (void) XDialogWidget(display,windows,action,
"Enter color name:",
1721 font_info=windows->widget.font_info;
1723 for (i=0; i < (int) colors; i++)
1724 if (WidgetTextWidth(font_info,colorlist[i]) > text_width)
1725 text_width=WidgetTextWidth(font_info,colorlist[i]);
1726 width=WidgetTextWidth(font_info,(
char *) action);
1727 if (WidgetTextWidth(font_info,CancelButtonText) > width)
1728 width=WidgetTextWidth(font_info,CancelButtonText);
1729 if (WidgetTextWidth(font_info,ResetButtonText) > width)
1730 width=WidgetTextWidth(font_info,ResetButtonText);
1731 if (WidgetTextWidth(font_info,GrabButtonText) > width)
1732 width=WidgetTextWidth(font_info,GrabButtonText);
1733 width+=(
unsigned int) QuantumMargin;
1734 if (WidgetTextWidth(font_info,ColorPatternText) > width)
1735 width=WidgetTextWidth(font_info,ColorPatternText);
1736 if (WidgetTextWidth(font_info,ColornameText) > width)
1737 width=WidgetTextWidth(font_info,ColornameText);
1738 height=(
unsigned int) (font_info->ascent+font_info->descent);
1742 windows->widget.width=width+MagickMin(text_width,MaxTextWidth)+
1743 6*(
unsigned int) QuantumMargin;
1744 windows->widget.min_width=width+MinTextWidth+4*(
unsigned int) QuantumMargin;
1745 if (windows->widget.width < windows->widget.min_width)
1746 windows->widget.width=windows->widget.min_width;
1747 windows->widget.height=(
unsigned int)
1748 ((81*height) >> 2)+((13*(
unsigned int) QuantumMargin) >> 1)+4;
1749 windows->widget.min_height=(
unsigned int)
1750 (((23*height) >> 1)+((13*(
unsigned int) QuantumMargin) >> 1)+4);
1751 if (windows->widget.height < windows->widget.min_height)
1752 windows->widget.height=windows->widget.min_height;
1753 XConstrainWindowPosition(display,&windows->widget);
1757 (void) CopyMagickString(windows->widget.name,
"Browse and Select a Color",
1759 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
1760 if (status != False)
1762 XSetWMName(display,windows->widget.id,&window_name);
1763 XSetWMIconName(display,windows->widget.id,&window_name);
1764 (void) XFree((
void *) window_name.value);
1766 window_changes.width=(int) windows->widget.width;
1767 window_changes.height=(int) windows->widget.height;
1768 window_changes.x=windows->widget.x;
1769 window_changes.y=windows->widget.y;
1770 (void) XReconfigureWMWindow(display,windows->widget.id,windows->widget.screen,
1771 mask,&window_changes);
1772 (void) XMapRaised(display,windows->widget.id);
1773 windows->widget.mapped=MagickFalse;
1777 XGetWidgetInfo((
char *) NULL,&mode_info);
1778 XGetWidgetInfo((
char *) NULL,&slider_info);
1779 XGetWidgetInfo((
char *) NULL,&north_info);
1780 XGetWidgetInfo((
char *) NULL,&south_info);
1781 XGetWidgetInfo((
char *) NULL,&expose_info);
1782 XGetWidgetInfo((
char *) NULL,&selection_info);
1784 delay=SuspendTime << 2;
1785 state=UpdateConfigurationState;
1788 if (state & UpdateConfigurationState)
1796 XGetWidgetInfo(CancelButtonText,&cancel_info);
1797 cancel_info.width=width;
1798 cancel_info.height=(
unsigned int) ((3*height) >> 1);
1799 cancel_info.x=(int) windows->widget.width-(
int) cancel_info.width-
1801 cancel_info.y=(int) windows->widget.height-(
int) cancel_info.height-
1803 XGetWidgetInfo(action,&action_info);
1804 action_info.width=width;
1805 action_info.height=(
unsigned int) ((3*height) >> 1);
1806 action_info.x=(int) windows->widget.width-(
int) action_info.width-
1807 (int) cancel_info.width-2*QuantumMargin-2;
1808 action_info.y=cancel_info.y;
1809 XGetWidgetInfo(GrabButtonText,&grab_info);
1810 grab_info.width=width;
1811 grab_info.height=(
unsigned int) ((3*height) >> 1);
1812 grab_info.x=QuantumMargin;
1813 grab_info.y=((5*QuantumMargin) >> 1)+(
int) height;
1814 XGetWidgetInfo(ResetButtonText,&reset_info);
1815 reset_info.width=width;
1816 reset_info.height=(
unsigned int) ((3*height) >> 1);
1817 reset_info.x=QuantumMargin;
1818 reset_info.y=grab_info.y+(int) grab_info.height+QuantumMargin;
1822 XGetWidgetInfo(reply,&reply_info);
1823 reply_info.raised=MagickFalse;
1824 reply_info.bevel_width--;
1825 reply_info.width=windows->widget.width-width-(
unsigned int)
1826 ((6*QuantumMargin) >> 1);
1827 reply_info.height=height << 1;
1828 reply_info.x=(int) width+(QuantumMargin << 1);
1829 reply_info.y=action_info.y-(int) reply_info.height-QuantumMargin;
1833 XGetWidgetInfo((
char *) NULL,&mode_info);
1834 mode_info.active=MagickTrue;
1835 mode_info.bevel_width=0;
1836 mode_info.width=(
unsigned int) (action_info.x-(
int) (QuantumMargin << 1));
1837 mode_info.height=action_info.height;
1838 mode_info.x=QuantumMargin;
1839 mode_info.y=action_info.y;
1843 XGetWidgetInfo((
char *) NULL,&scroll_info);
1844 scroll_info.bevel_width--;
1845 scroll_info.width=height;
1846 scroll_info.height=(
unsigned int) (reply_info.y-grab_info.y-
1847 (QuantumMargin >> 1));
1848 scroll_info.x=reply_info.x+(int) (reply_info.width-scroll_info.width);
1849 scroll_info.y=grab_info.y-(int) reply_info.bevel_width;
1850 scroll_info.raised=MagickFalse;
1851 scroll_info.trough=MagickTrue;
1852 north_info=scroll_info;
1853 north_info.raised=MagickTrue;
1854 north_info.width-=(north_info.bevel_width << 1);
1855 north_info.height=north_info.width-1;
1856 north_info.x+=(int) north_info.bevel_width;
1857 north_info.y+=(int) north_info.bevel_width;
1858 south_info=north_info;
1859 south_info.y=scroll_info.y+(int) scroll_info.height-(
int)
1860 scroll_info.bevel_width-(int) south_info.height;
1862 slider_info=north_info;
1864 slider_info.width-=2;
1865 slider_info.min_y=north_info.y+(int) north_info.height+(
int)
1866 north_info.bevel_width+(int) slider_info.bevel_width+2;
1867 slider_info.height=(
unsigned int) ((
int) scroll_info.height-
1868 ((slider_info.min_y-scroll_info.y+1) << 1)+4);
1869 visible_colors=(
unsigned int) (scroll_info.height*
1870 PerceptibleReciprocal((
double) height+(height >> 3)));
1871 if (colors > visible_colors)
1872 slider_info.height=(
unsigned int) ((visible_colors*
1873 slider_info.height)/colors);
1874 slider_info.max_y=south_info.y-(int) south_info.bevel_width-
1875 (
int) slider_info.bevel_width-2;
1876 slider_info.x=scroll_info.x+(int) slider_info.bevel_width+1;
1877 slider_info.y=slider_info.min_y;
1878 expose_info=scroll_info;
1879 expose_info.y=slider_info.y;
1883 XGetWidgetInfo((
char *) NULL,&list_info);
1884 list_info.raised=MagickFalse;
1885 list_info.bevel_width--;
1886 list_info.width=(
unsigned int)
1887 (scroll_info.x-reply_info.x-(
int) (QuantumMargin >> 1));
1888 list_info.height=scroll_info.height;
1889 list_info.x=reply_info.x;
1890 list_info.y=scroll_info.y;
1891 if (windows->widget.mapped == MagickFalse)
1892 state|=JumpListState;
1897 XGetWidgetInfo(text,&text_info);
1898 text_info.center=MagickFalse;
1899 text_info.width=reply_info.width;
1900 text_info.height=height;
1901 text_info.x=list_info.x-(int) (QuantumMargin >> 1);
1902 text_info.y=QuantumMargin;
1906 XGetWidgetInfo((
char *) NULL,&selection_info);
1907 selection_info.center=MagickFalse;
1908 selection_info.width=list_info.width;
1909 selection_info.height=(
unsigned int) ((9*height) >> 3);
1910 selection_info.x=list_info.x;
1911 state&=(
unsigned int) (~UpdateConfigurationState);
1913 if (state & RedrawWidgetState)
1919 y=text_info.y+(int) ((text_info.height-height) >> 1)+font_info->ascent;
1920 (void) XDrawString(display,windows->widget.id,
1921 windows->widget.annotate_context,x,y,ColorPatternText,
1922 Extent(ColorPatternText));
1923 (void) CopyMagickString(text_info.text,glob_pattern,MagickPathExtent);
1924 XDrawWidgetText(display,&windows->widget,&text_info);
1925 XDrawBeveledButton(display,&windows->widget,&grab_info);
1926 XDrawBeveledButton(display,&windows->widget,&reset_info);
1927 XDrawBeveledMatte(display,&windows->widget,&list_info);
1928 XDrawBeveledMatte(display,&windows->widget,&scroll_info);
1929 XDrawTriangleNorth(display,&windows->widget,&north_info);
1930 XDrawBeveledButton(display,&windows->widget,&slider_info);
1931 XDrawTriangleSouth(display,&windows->widget,&south_info);
1933 y=reply_info.y+(int) ((reply_info.height-height) >> 1)+
1935 (void) XDrawString(display,windows->widget.id,
1936 windows->widget.annotate_context,x,y,ColornameText,
1937 Extent(ColornameText));
1938 XDrawBeveledMatte(display,&windows->widget,&reply_info);
1939 XDrawMatteText(display,&windows->widget,&reply_info);
1940 XDrawBeveledButton(display,&windows->widget,&action_info);
1941 XDrawBeveledButton(display,&windows->widget,&cancel_info);
1942 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
1943 selection_info.id=(~0);
1944 state|=RedrawActionState;
1945 state|=RedrawListState;
1946 state&=(
unsigned int) (~RedrawWidgetState);
1948 if (state & UpdateListState)
1956 status=XParseColor(display,windows->widget.map_info->colormap,
1957 glob_pattern,&color);
1958 if ((status != False) || (strchr(glob_pattern,
'-') != (
char *) NULL))
1963 (void) CopyMagickString(reply,glob_pattern,MagickPathExtent);
1964 (void) CopyMagickString(glob_pattern,reset_pattern,MagickPathExtent);
1965 action_info.raised=MagickFalse;
1966 XDrawBeveledButton(display,&windows->widget,&action_info);
1972 checklist=GetColorList(glob_pattern,&number_colors,exception);
1973 if (number_colors == 0)
1975 (void) CopyMagickString(glob_pattern,reset_pattern,MagickPathExtent);
1976 (void) XBell(display,0);
1980 for (i=0; i < (int) colors; i++)
1981 colorlist[i]=DestroyString(colorlist[i]);
1982 if (colorlist != (
char **) NULL)
1983 colorlist=(
char **) RelinquishMagickMemory(colorlist);
1984 colorlist=checklist;
1985 colors=number_colors;
1990 slider_info.height=(
unsigned int) ((
int) scroll_info.height-
1991 ((slider_info.min_y-scroll_info.y+1) << 1)+1);
1992 if (colors > visible_colors)
1993 slider_info.height=(
unsigned int) ((visible_colors*
1994 slider_info.height)/colors);
1995 slider_info.max_y=south_info.y-(int) south_info.bevel_width-
1996 (
int) slider_info.bevel_width-2;
1998 slider_info.y=slider_info.min_y;
1999 expose_info.y=slider_info.y;
2000 selection_info.id=(~0);
2002 state|=RedrawListState;
2006 *reply_info.text=
'\0';
2007 reply_info.cursor=reply_info.text;
2008 (void) CopyMagickString(text_info.text,glob_pattern,MagickPathExtent);
2009 XDrawWidgetText(display,&windows->widget,&text_info);
2010 XDrawMatteText(display,&windows->widget,&reply_info);
2011 XDrawBeveledMatte(display,&windows->widget,&scroll_info);
2012 XDrawTriangleNorth(display,&windows->widget,&north_info);
2013 XDrawBeveledButton(display,&windows->widget,&slider_info);
2014 XDrawTriangleSouth(display,&windows->widget,&south_info);
2015 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
2016 state&=(
unsigned int) (~UpdateListState);
2018 if (state & JumpListState)
2024 for (i=0; i < (int) colors; i++)
2025 if (LocaleCompare(colorlist[i],reply) >= 0)
2027 list_info.id=LocaleCompare(colorlist[i],reply) == 0 ? i : ~0;
2030 if ((i < slider_info.id) ||
2031 (i >= (
int) (slider_info.id+(
int) visible_colors)))
2032 slider_info.id=i-(int) (visible_colors >> 1);
2033 selection_info.id=(~0);
2034 state|=RedrawListState;
2035 state&=(
unsigned int) (~JumpListState);
2037 if (state & RedrawListState)
2042 if (slider_info.id >= (
int) (colors-visible_colors))
2043 slider_info.id=(int) (colors-visible_colors);
2044 if ((slider_info.id < 0) || (colors <= visible_colors))
2046 slider_info.y=slider_info.min_y;
2048 slider_info.y+=(int) slider_info.id*(slider_info.max_y-
2049 slider_info.min_y+1)/(int) colors;
2050 if (slider_info.id != selection_info.id)
2055 selection_info.id=slider_info.id;
2056 selection_info.y=list_info.y+(int) (height >> 3)+2;
2057 for (i=0; i < (int) visible_colors; i++)
2059 selection_info.raised=(slider_info.id+i) != list_info.id ?
2060 MagickTrue : MagickFalse;
2061 selection_info.text=(
char *) NULL;
2062 if ((slider_info.id+i) < (
int) colors)
2063 selection_info.text=colorlist[slider_info.id+i];
2064 XDrawWidgetText(display,&windows->widget,&selection_info);
2065 selection_info.y+=(int) selection_info.height;
2070 if (slider_info.y > expose_info.y)
2072 expose_info.height=(
unsigned int) (slider_info.y-expose_info.y);
2073 expose_info.y=slider_info.y-(int) expose_info.height-(
int)
2074 slider_info.bevel_width-1;
2078 expose_info.height=(
unsigned int) (expose_info.y-slider_info.y);
2079 expose_info.y=slider_info.y+(int) slider_info.height+(
int)
2080 slider_info.bevel_width+1;
2082 XDrawTriangleNorth(display,&windows->widget,&north_info);
2083 XDrawMatte(display,&windows->widget,&expose_info);
2084 XDrawBeveledButton(display,&windows->widget,&slider_info);
2085 XDrawTriangleSouth(display,&windows->widget,&south_info);
2086 expose_info.y=slider_info.y;
2088 state&=(
unsigned int) (~RedrawListState);
2090 if (state & RedrawActionState)
2093 colorname[MagickPathExtent];
2098 color=windows->widget.pixel_info->matte_color;
2099 (void) XParseColor(display,windows->widget.map_info->colormap,
2100 reply_info.text,&windows->widget.pixel_info->matte_color);
2101 XBestPixel(display,windows->widget.map_info->colormap,(XColor *) NULL,
2102 (
unsigned int) windows->widget.visual_info->colormap_size,
2103 &windows->widget.pixel_info->matte_color);
2104 mode_info.text=colorname;
2105 (void) FormatLocaleString(mode_info.text,MagickPathExtent,
2106 "#%02x%02x%02x",windows->widget.pixel_info->matte_color.red,
2107 windows->widget.pixel_info->matte_color.green,
2108 windows->widget.pixel_info->matte_color.blue);
2109 XDrawBeveledButton(display,&windows->widget,&mode_info);
2110 windows->widget.pixel_info->matte_color=color;
2111 state&=(
unsigned int) (~RedrawActionState);
2116 if (north_info.raised && south_info.raised)
2117 (void) XIfEvent(display,&event,XScreenEvent,(
char *) windows);
2123 XDelay(display,delay);
2125 (void) XCheckIfEvent(display,&event,XScreenEvent,(
char *) windows);
2126 if (north_info.raised == MagickFalse)
2127 if (slider_info.id > 0)
2133 state|=RedrawListState;
2135 if (south_info.raised == MagickFalse)
2136 if (slider_info.id < (
int) colors)
2142 state|=RedrawListState;
2144 if (event.type != ButtonRelease)
2151 if (MatteIsActive(slider_info,event.xbutton))
2156 slider_info.active=MagickTrue;
2159 if (MatteIsActive(north_info,event.xbutton))
2160 if (slider_info.id > 0)
2165 north_info.raised=MagickFalse;
2167 state|=RedrawListState;
2170 if (MatteIsActive(south_info,event.xbutton))
2171 if (slider_info.id < (
int) colors)
2176 south_info.raised=MagickFalse;
2178 state|=RedrawListState;
2181 if (MatteIsActive(scroll_info,event.xbutton))
2186 if (event.xbutton.y < slider_info.y)
2187 slider_info.id-=(int) (visible_colors-1);
2189 slider_info.id+=(int) (visible_colors-1);
2190 state|=RedrawListState;
2193 if (MatteIsActive(list_info,event.xbutton))
2201 id=slider_info.id+(
event.xbutton.y-(list_info.y+(int)
2202 (height >> 1))+1)/(
int) selection_info.height;
2203 if (
id >= (
int) colors)
2205 (void) CopyMagickString(reply_info.text,colorlist[
id],
2207 reply_info.highlight=MagickFalse;
2208 reply_info.marker=reply_info.text;
2209 reply_info.cursor=reply_info.text+Extent(reply_info.text);
2210 XDrawMatteText(display,&windows->widget,&reply_info);
2211 state|=RedrawActionState;
2212 if (
id == list_info.id)
2214 (void) CopyMagickString(glob_pattern,reply_info.text,
2216 state|=UpdateListState;
2218 selection_info.id=(~0);
2220 state|=RedrawListState;
2223 if (MatteIsActive(grab_info,event.xbutton))
2228 grab_info.raised=MagickFalse;
2229 XDrawBeveledButton(display,&windows->widget,&grab_info);
2232 if (MatteIsActive(reset_info,event.xbutton))
2237 reset_info.raised=MagickFalse;
2238 XDrawBeveledButton(display,&windows->widget,&reset_info);
2241 if (MatteIsActive(mode_info,event.xbutton))
2246 if (mode_info.text != (
char *) NULL)
2247 (void) CopyMagickString(reply_info.text,mode_info.text,
2249 (void) CopyMagickString(primary_selection,reply_info.text,
2251 (void) XSetSelectionOwner(display,XA_PRIMARY,windows->widget.id,
2252 event.xbutton.time);
2253 reply_info.highlight=XGetSelectionOwner(display,XA_PRIMARY) ==
2254 windows->widget.id ? MagickTrue : MagickFalse;
2255 reply_info.marker=reply_info.text;
2256 reply_info.cursor=reply_info.text+Extent(reply_info.text);
2257 XDrawMatteText(display,&windows->widget,&reply_info);
2260 if (MatteIsActive(action_info,event.xbutton))
2265 action_info.raised=MagickFalse;
2266 XDrawBeveledButton(display,&windows->widget,&action_info);
2269 if (MatteIsActive(cancel_info,event.xbutton))
2274 cancel_info.raised=MagickFalse;
2275 XDrawBeveledButton(display,&windows->widget,&cancel_info);
2278 if (MatteIsActive(reply_info,event.xbutton) == MagickFalse)
2280 if (event.xbutton.button != Button2)
2288 x=
event.xbutton.x-reply_info.x-(int) (QuantumMargin >> 2);
2289 for (i=1; i <= Extent(reply_info.marker); i++)
2290 if (XTextWidth(font_info,reply_info.marker,i) > x)
2292 reply_info.cursor=reply_info.marker+i-1;
2293 if (event.xbutton.time > (click_time+(
unsigned long) DoubleClick))
2294 reply_info.highlight=MagickFalse;
2300 (void) CopyMagickString(primary_selection,reply_info.text,
2302 (void) XSetSelectionOwner(display,XA_PRIMARY,windows->widget.id,
2303 event.xbutton.time);
2304 reply_info.highlight=XGetSelectionOwner(display,XA_PRIMARY) ==
2305 windows->widget.id ? MagickTrue : MagickFalse;
2307 XDrawMatteText(display,&windows->widget,&reply_info);
2308 click_time=
event.xbutton.time;
2314 (void) XConvertSelection(display,XA_PRIMARY,XA_STRING,XA_STRING,
2315 windows->widget.id,event.xbutton.time);
2320 if (windows->widget.mapped == MagickFalse)
2322 if (north_info.raised == MagickFalse)
2327 delay=SuspendTime << 2;
2328 north_info.raised=MagickTrue;
2329 XDrawTriangleNorth(display,&windows->widget,&north_info);
2331 if (south_info.raised == MagickFalse)
2336 delay=SuspendTime << 2;
2337 south_info.raised=MagickTrue;
2338 XDrawTriangleSouth(display,&windows->widget,&south_info);
2340 if (slider_info.active)
2345 slider_info.active=MagickFalse;
2348 if (grab_info.raised == MagickFalse)
2350 if (event.xbutton.window == windows->widget.id)
2351 if (MatteIsActive(grab_info,event.xbutton))
2356 (void) XGetWindowColor(display,windows,reply_info.text,
2358 reply_info.marker=reply_info.text;
2359 reply_info.cursor=reply_info.text+Extent(reply_info.text);
2360 XDrawMatteText(display,&windows->widget,&reply_info);
2361 state|=RedrawActionState;
2363 grab_info.raised=MagickTrue;
2364 XDrawBeveledButton(display,&windows->widget,&grab_info);
2366 if (reset_info.raised == MagickFalse)
2368 if (event.xbutton.window == windows->widget.id)
2369 if (MatteIsActive(reset_info,event.xbutton))
2371 (void) CopyMagickString(glob_pattern,reset_pattern,
2373 state|=UpdateListState;
2375 reset_info.raised=MagickTrue;
2376 XDrawBeveledButton(display,&windows->widget,&reset_info);
2378 if (action_info.raised == MagickFalse)
2380 if (event.xbutton.window == windows->widget.id)
2382 if (MatteIsActive(action_info,event.xbutton))
2384 if (*reply_info.text ==
'\0')
2385 (void) XBell(display,0);
2390 action_info.raised=MagickTrue;
2391 XDrawBeveledButton(display,&windows->widget,&action_info);
2393 if (cancel_info.raised == MagickFalse)
2395 if (event.xbutton.window == windows->widget.id)
2396 if (MatteIsActive(cancel_info,event.xbutton))
2398 *reply_info.text=
'\0';
2401 cancel_info.raised=MagickTrue;
2402 XDrawBeveledButton(display,&windows->widget,&cancel_info);
2404 if (MatteIsActive(reply_info,event.xbutton) == MagickFalse)
2413 if (event.xclient.message_type != windows->wm_protocols)
2415 if (*event.xclient.data.l == (
int) windows->wm_take_focus)
2417 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
2418 (Time) event.xclient.data.l[1]);
2421 if (*event.xclient.data.l != (
int) windows->wm_delete_window)
2423 if (event.xclient.window == windows->widget.id)
2425 *reply_info.text=
'\0';
2431 case ConfigureNotify:
2436 if (event.xconfigure.window != windows->widget.id)
2438 if ((event.xconfigure.width == (
int) windows->widget.width) &&
2439 (event.xconfigure.height == (
int) windows->widget.height))
2441 windows->widget.width=(
unsigned int)
2442 MagickMax(event.xconfigure.width,(
int) windows->widget.min_width);
2443 windows->widget.height=(
unsigned int)
2444 MagickMax(event.xconfigure.height,(
int) windows->widget.min_height);
2445 state|=UpdateConfigurationState;
2450 if (event.xcrossing.window != windows->widget.id)
2452 state&=(
unsigned int) (~InactiveWidgetState);
2457 if (event.xexpose.window != windows->widget.id)
2459 if (event.xexpose.count != 0)
2461 state|=RedrawWidgetState;
2467 command[MagickPathExtent];
2478 if (event.xkey.window != windows->widget.id)
2480 length=XLookupString((XKeyEvent *) &event.xkey,command,
2481 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
2482 *(command+length)=
'\0';
2483 if (AreaIsActive(scroll_info,event.xkey))
2488 switch ((
int) key_symbol)
2511 slider_info.id-=(int) visible_colors;
2517 slider_info.id+=(int) visible_colors;
2523 slider_info.id=(int) colors;
2527 state|=RedrawListState;
2530 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
2535 if (*reply_info.text ==
'\0')
2537 (void) CopyMagickString(glob_pattern,reply_info.text,MagickPathExtent);
2538 state|=UpdateListState;
2541 if (key_symbol == XK_Control_L)
2543 state|=ControlState;
2546 if (state & ControlState)
2547 switch ((
int) key_symbol)
2555 *reply_info.text=
'\0';
2556 reply_info.cursor=reply_info.text;
2557 reply_info.marker=reply_info.text;
2558 reply_info.highlight=MagickFalse;
2564 XEditText(display,&reply_info,key_symbol,command,state);
2565 XDrawMatteText(display,&windows->widget,&reply_info);
2566 state|=JumpListState;
2567 status=XParseColor(display,windows->widget.map_info->colormap,
2568 reply_info.text,&color);
2569 if (status != False)
2570 state|=RedrawActionState;
2576 command[MagickPathExtent];
2584 if (event.xkey.window != windows->widget.id)
2586 (void) XLookupString((XKeyEvent *) &event.xkey,command,
2587 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
2588 if (key_symbol == XK_Control_L)
2589 state&=(
unsigned int) (~ControlState);
2594 if (event.xcrossing.window != windows->widget.id)
2596 state|=InactiveWidgetState;
2601 mask&=(
unsigned int) (~CWX);
2602 mask&=(
unsigned int) (~CWY);
2610 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
2611 if (slider_info.active)
2616 slider_info.y=
event.xmotion.y-(int)
2617 ((slider_info.height+slider_info.bevel_width) >> 1)+1;
2618 if (slider_info.y < slider_info.min_y)
2619 slider_info.y=slider_info.min_y;
2620 if (slider_info.y > slider_info.max_y)
2621 slider_info.y=slider_info.max_y;
2623 if (slider_info.y != slider_info.min_y)
2624 slider_info.id=(int) (((
int) colors*(slider_info.y-
2625 slider_info.min_y+1))/(slider_info.max_y-slider_info.min_y+1));
2626 state|=RedrawListState;
2629 if (state & InactiveWidgetState)
2631 if (grab_info.raised == MatteIsActive(grab_info,event.xmotion))
2636 grab_info.raised=!grab_info.raised;
2637 XDrawBeveledButton(display,&windows->widget,&grab_info);
2640 if (reset_info.raised == MatteIsActive(reset_info,event.xmotion))
2645 reset_info.raised=!reset_info.raised;
2646 XDrawBeveledButton(display,&windows->widget,&reset_info);
2649 if (action_info.raised == MatteIsActive(action_info,event.xmotion))
2654 action_info.raised=action_info.raised == MagickFalse ?
2655 MagickTrue : MagickFalse;
2656 XDrawBeveledButton(display,&windows->widget,&action_info);
2659 if (cancel_info.raised == MatteIsActive(cancel_info,event.xmotion))
2664 cancel_info.raised=cancel_info.raised == MagickFalse ?
2665 MagickTrue : MagickFalse;
2666 XDrawBeveledButton(display,&windows->widget,&cancel_info);
2671 case SelectionClear:
2673 reply_info.highlight=MagickFalse;
2674 XDrawMatteText(display,&windows->widget,&reply_info);
2677 case SelectionNotify:
2695 if (event.xselection.property == (Atom) None)
2697 status=XGetWindowProperty(display,event.xselection.requestor,
2698 event.xselection.property,0L,2047L,MagickTrue,XA_STRING,&type,
2699 &format,&length,&after,&data);
2700 if ((status != Success) || (type != XA_STRING) || (format == 32) ||
2703 if ((Extent(reply_info.text)+(
int) length) >= (MagickPathExtent-1))
2704 (void) XBell(display,0);
2710 *(data+length)=
'\0';
2711 XEditText(display,&reply_info,(KeySym) XK_Insert,(
char *) data,
2713 XDrawMatteText(display,&windows->widget,&reply_info);
2714 state|=JumpListState;
2715 state|=RedrawActionState;
2717 (void) XFree((
void *) data);
2720 case SelectionRequest:
2725 XSelectionRequestEvent
2728 if (reply_info.highlight == MagickFalse)
2733 request=(&(
event.xselectionrequest));
2734 (void) XChangeProperty(request->display,request->requestor,
2735 request->property,request->target,8,PropModeReplace,
2736 (
unsigned char *) primary_selection,Extent(primary_selection));
2737 notify.type=SelectionNotify;
2738 notify.send_event=MagickTrue;
2739 notify.display=request->display;
2740 notify.requestor=request->requestor;
2741 notify.selection=request->selection;
2742 notify.target=request->target;
2743 notify.time=request->time;
2744 if (request->property == None)
2745 notify.property=request->target;
2747 notify.property=request->property;
2748 (void) XSendEvent(request->display,request->requestor,False,
2749 NoEventMask,(XEvent *) ¬ify);
2754 }
while ((state & ExitState) == 0);
2755 XSetCursorState(display,windows,MagickFalse);
2756 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
2757 XCheckRefreshWindows(display,windows);
2761 for (i=0; i < (int) colors; i++)
2762 colorlist[i]=DestroyString(colorlist[i]);
2763 if (colorlist != (
char **) NULL)
2764 colorlist=(
char **) RelinquishMagickMemory(colorlist);
2765 exception=DestroyExceptionInfo(exception);
2766 if ((*reply ==
'\0') || (strchr(reply,
'-') != (
char *) NULL))
2768 status=XParseColor(display,windows->widget.map_info->colormap,reply,&color);
2769 if (status != False)
2771 XNoticeWidget(display,windows,
"Color is unknown to X server:",reply);
2772 (void) CopyMagickString(reply,
"gray",MagickPathExtent);
2810MagickPrivate
int XCommandWidget(Display *display,XWindows *windows,
2811 const char *
const *selections,XEvent *event)
2813#define tile_width 112
2814#define tile_height 70
2816 static const unsigned char
2819 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2820 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2821 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2822 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
2823 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00,
2824 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00,
2825 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2826 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2827 0x00, 0x00, 0x1e, 0x38, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2828 0x00, 0x00, 0x00, 0x00, 0x1e, 0xbc, 0x9f, 0x03, 0x00, 0x3e, 0x00, 0xc0,
2829 0x1f, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x1e, 0xfc, 0xff, 0x0f, 0x80, 0x3f,
2830 0x00, 0xf0, 0x1f, 0xc0, 0x0f, 0x00, 0x00, 0x00, 0x1e, 0xfc, 0xff, 0x1f,
2831 0xe0, 0x3f, 0x00, 0xfc, 0x1f, 0xf0, 0x0f, 0x00, 0x00, 0x00, 0x1e, 0xfc,
2832 0xff, 0x1f, 0xf0, 0x3f, 0x00, 0xfe, 0x1f, 0xf8, 0x0f, 0x00, 0x00, 0x00,
2833 0x1e, 0xfc, 0xfc, 0x3f, 0xf8, 0x3f, 0x00, 0xff, 0x1e, 0xfc, 0x0f, 0x00,
2834 0x00, 0x00, 0x1e, 0x7c, 0xfc, 0x3e, 0xf8, 0x3c, 0x80, 0x1f, 0x1e, 0x7c,
2835 0x0f, 0x00, 0x00, 0x00, 0x1e, 0x78, 0x78, 0x3c, 0x7c, 0x3c, 0xc0, 0x0f,
2836 0x1e, 0x3e, 0x0f, 0x00, 0x00, 0x00, 0x1e, 0x78, 0x78, 0x3c, 0x7c, 0x3c,
2837 0xc0, 0x07, 0x1e, 0x3e, 0x0f, 0x00, 0x00, 0x00, 0x1e, 0x78, 0x78, 0x3c,
2838 0x7c, 0x7c, 0xc0, 0x0f, 0x1e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x78,
2839 0x78, 0x3c, 0xfc, 0x7c, 0x80, 0x7f, 0x1e, 0x7c, 0x00, 0x00, 0x00, 0x00,
2840 0x1e, 0xf8, 0x78, 0x7c, 0xf8, 0xff, 0x00, 0xff, 0x1f, 0xf8, 0xff, 0x00,
2841 0x00, 0x00, 0x1e, 0xf8, 0x78, 0x7c, 0xf0, 0xff, 0x07, 0xfe, 0x1f, 0xf8,
2842 0xff, 0x00, 0x00, 0x00, 0x1e, 0xf8, 0x78, 0x7c, 0xf0, 0xff, 0x07, 0xf8,
2843 0x1f, 0xf0, 0xff, 0x01, 0x00, 0x00, 0x1e, 0xf8, 0x78, 0x7c, 0xc0, 0xef,
2844 0x07, 0xe0, 0x1f, 0xc0, 0xff, 0x01, 0x00, 0x00, 0x1e, 0x70, 0x40, 0x78,
2845 0x00, 0xc7, 0x07, 0x00, 0x1e, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x1e, 0x00,
2846 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00,
2847 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00,
2848 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00,
2849 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
2850 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2851 0x00, 0xc0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2852 0x00, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2853 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
2854 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x01, 0x00, 0x00, 0x00,
2855 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00,
2856 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78,
2857 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2858 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x02, 0x00,
2859 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07,
2860 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2861 0xc0, 0x0f, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2862 0x60, 0x00, 0xc0, 0x0f, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2863 0x00, 0x00, 0x78, 0x00, 0xc0, 0x8f, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00,
2864 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0xc0, 0x8f, 0x3f, 0x00, 0x00, 0x00,
2865 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0xe0, 0x9f, 0x7f, 0x00,
2866 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0xe0, 0xdf,
2867 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x78, 0x00,
2868 0xe0, 0xdf, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x0c,
2869 0x78, 0x30, 0xf0, 0xff, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e,
2870 0x00, 0x0f, 0xf8, 0x70, 0xf0, 0xff, 0x7b, 0x00, 0x00, 0x1f, 0x00, 0xe0,
2871 0x0f, 0x1e, 0x80, 0x0f, 0xf8, 0x78, 0xf0, 0xfd, 0xf9, 0x00, 0xc0, 0x1f,
2872 0x00, 0xf8, 0x0f, 0x00, 0xe0, 0x1f, 0xf8, 0x7c, 0xf0, 0xfc, 0xf9, 0x00,
2873 0xf0, 0x1f, 0x00, 0xfe, 0x0f, 0x00, 0xf0, 0x07, 0xf8, 0x3e, 0xf8, 0xfc,
2874 0xf0, 0x01, 0xf8, 0x1f, 0x00, 0xff, 0x0f, 0x1e, 0xf0, 0x03, 0xf8, 0x3f,
2875 0xf8, 0xf8, 0xf0, 0x01, 0xfc, 0x1f, 0x80, 0x7f, 0x0f, 0x1e, 0xf8, 0x00,
2876 0xf8, 0x1f, 0x78, 0x18, 0xf0, 0x01, 0x7c, 0x1e, 0xc0, 0x0f, 0x0f, 0x1e,
2877 0x7c, 0x00, 0xf0, 0x0f, 0x78, 0x00, 0xf0, 0x01, 0x3e, 0x1e, 0xe0, 0x07,
2878 0x0f, 0x1e, 0x7c, 0x00, 0xf0, 0x07, 0x7c, 0x00, 0xe0, 0x01, 0x3e, 0x1e,
2879 0xe0, 0x03, 0x0f, 0x1e, 0x3e, 0x00, 0xf0, 0x0f, 0x7c, 0x00, 0xe0, 0x03,
2880 0x3e, 0x3e, 0xe0, 0x07, 0x0f, 0x1e, 0x1e, 0x00, 0xf0, 0x1f, 0x3c, 0x00,
2881 0xe0, 0x03, 0x7e, 0x3e, 0xc0, 0x3f, 0x0f, 0x1e, 0x3e, 0x00, 0xf0, 0x1f,
2882 0x3e, 0x00, 0xe0, 0x03, 0xfc, 0x7f, 0x80, 0xff, 0x0f, 0x1e, 0xfc, 0x00,
2883 0xf0, 0x3e, 0x3e, 0x00, 0xc0, 0x03, 0xf8, 0xff, 0x03, 0xff, 0x0f, 0x1e,
2884 0xfc, 0x07, 0xf0, 0x7c, 0x1e, 0x00, 0xc0, 0x03, 0xf8, 0xff, 0x03, 0xfc,
2885 0x0f, 0x1e, 0xf8, 0x1f, 0xf0, 0xf8, 0x1e, 0x00, 0xc0, 0x03, 0xe0, 0xf7,
2886 0x03, 0xf0, 0x0f, 0x1e, 0xe0, 0x3f, 0xf0, 0x78, 0x1c, 0x00, 0x80, 0x03,
2887 0x80, 0xe3, 0x03, 0x00, 0x0f, 0x1e, 0xc0, 0x3f, 0xf0, 0x30, 0x00, 0x00,
2888 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0e, 0x00, 0x3e, 0x00, 0x00,
2889 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x0f, 0x00, 0x00, 0x10,
2890 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x0f, 0x00,
2891 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
2892 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2893 0x00, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2894 0x00, 0x00, 0x00, 0xf0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2895 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
2896 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00,
2897 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00,
2898 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c,
2899 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2900 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2922 assert(display != (Display *) NULL);
2923 assert(windows != (XWindows *) NULL);
2924 if (IsEventLogging() != MagickFalse)
2925 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2926 font_info=windows->command.font_info;
2927 height=(
unsigned int) (font_info->ascent+font_info->descent);
2930 if (event == (XEvent *) NULL)
2944 assert(selections != (
const char **) NULL);
2945 windows->command.width=0;
2946 for (i=0; selections[i] != (
char *) NULL; i++)
2948 width=WidgetTextWidth(font_info,(
char *) selections[i]);
2949 if (width > windows->command.width)
2950 windows->command.width=width;
2952 number_selections=(
unsigned int) i;
2953 windows->command.width+=(
unsigned int) (3*QuantumMargin+10);
2954 if ((
int) windows->command.width < (tile_width+QuantumMargin+10))
2955 windows->command.width=(
unsigned int) (tile_width+QuantumMargin+10);
2956 windows->command.height=(
unsigned int) (number_selections*
2957 (((3*height) >> 1)+10)+tile_height+20);
2958 windows->command.min_width=windows->command.width;
2959 windows->command.min_height=windows->command.height;
2960 XConstrainWindowPosition(display,&windows->command);
2961 if (windows->command.id != (Window) NULL)
2969 status=XStringListToTextProperty(&windows->command.name,1,
2971 if (status != False)
2973 XSetWMName(display,windows->command.id,&window_name);
2974 XSetWMIconName(display,windows->command.id,&window_name);
2975 (void) XFree((
void *) window_name.value);
2977 window_changes.width=(int) windows->command.width;
2978 window_changes.height=(int) windows->command.height;
2979 (void) XReconfigureWMWindow(display,windows->command.id,
2980 windows->command.screen,(
unsigned int) (CWWidth | CWHeight),
2986 if (selection_info != (XWidgetInfo *) NULL)
2987 selection_info=(XWidgetInfo *) RelinquishMagickMemory(selection_info);
2988 selection_info=(XWidgetInfo *) AcquireQuantumMemory(number_selections,
2989 sizeof(*selection_info));
2990 if (selection_info == (XWidgetInfo *) NULL)
2992 ThrowXWindowFatalException(ResourceLimitFatalError,
2993 "MemoryAllocationFailed",
"...");
2996 state|=UpdateConfigurationState | RedrawWidgetState;
3001 if (event != (XEvent *) NULL)
3002 switch (event->type)
3006 for (i=0; i < (int) number_selections; i++)
3008 if (MatteIsActive(selection_info[i],event->xbutton) == MagickFalse)
3010 if (i >= (
int) windows->command.data)
3012 selection_info[i].raised=MagickFalse;
3013 XDrawBeveledButton(display,&windows->command,&selection_info[i]);
3016 submenu_info=selection_info[i];
3017 submenu_info.active=MagickTrue;
3018 toggle_info.y=submenu_info.y+(int) (submenu_info.height >> 1)-
3019 (int) (toggle_info.height >> 1);
3021 (void) XCheckWindowEvent(display,windows->widget.id,LeaveWindowMask,
3029 for (i=0; i < (int) number_selections; i++)
3031 if (MatteIsActive(selection_info[i],event->xbutton) == MagickFalse)
3034 if (
id >= (
int) windows->command.data)
3036 selection_info[id].raised=MagickTrue;
3037 XDrawBeveledButton(display,&windows->command,&selection_info[
id]);
3049 if (event->xclient.message_type != windows->wm_protocols)
3051 if (*event->xclient.data.l != (
int) windows->wm_delete_window)
3053 (void) XWithdrawWindow(display,windows->command.id,
3054 windows->command.screen);
3057 case ConfigureNotify:
3062 if (event->xconfigure.window != windows->command.id)
3064 if (event->xconfigure.send_event != 0)
3066 windows->command.x=
event->xconfigure.x;
3067 windows->command.y=
event->xconfigure.y;
3069 if ((event->xconfigure.width == (
int) windows->command.width) &&
3070 (event->xconfigure.height == (
int) windows->command.height))
3072 windows->command.width=(
unsigned int)
3073 MagickMax(event->xconfigure.width,(
int) windows->command.min_width);
3074 windows->command.height=(
unsigned int)
3075 MagickMax(event->xconfigure.height,(
int) windows->command.min_height);
3076 state|=UpdateConfigurationState;
3081 if (event->xexpose.window != windows->command.id)
3083 if (event->xexpose.count != 0)
3085 state|=RedrawWidgetState;
3095 for (i=0; i < (int) number_selections; i++)
3097 if (i >= (
int) windows->command.data)
3099 if (selection_info[i].raised ==
3100 MatteIsActive(selection_info[i],event->xmotion))
3105 selection_info[i].raised=!selection_info[i].raised;
3106 XDrawBeveledButton(display,&windows->command,
3107 &selection_info[i]);
3111 if (MatteIsActive(selection_info[i],event->xmotion) == MagickFalse)
3113 submenu_info=selection_info[i];
3114 submenu_info.active=MagickTrue;
3115 toggle_info.raised=MagickTrue;
3116 toggle_info.y=submenu_info.y+(int) (submenu_info.height >> 1)-
3117 (int) (toggle_info.height >> 1);
3118 XDrawTriangleEast(display,&windows->command,&toggle_info);
3121 XDelay(display,SuspendTime);
3122 if (XCheckMaskEvent(display,ButtonMotionMask,event) == MagickFalse)
3124 while (XCheckMaskEvent(display,ButtonMotionMask,event)) ;
3125 toggle_info.raised=MagickFalse;
3126 if (windows->command.data != 0)
3127 XDrawTriangleEast(display,&windows->command,&toggle_info);
3133 windows->command.mapped=MagickTrue;
3138 windows->command.mapped=MagickFalse;
3144 if (state & UpdateConfigurationState)
3149 assert(selections != (
const char **) NULL);
3151 for (i=0; i < (int) number_selections; i++)
3153 XGetWidgetInfo(selections[i],&selection_info[i]);
3154 selection_info[i].center=MagickFalse;
3155 selection_info[i].bevel_width--;
3156 selection_info[i].height=(
unsigned int) ((3*height) >> 1);
3157 selection_info[i].x=(QuantumMargin >> 1)+4;
3158 selection_info[i].width=(
unsigned int) ((
int) windows->command.width-
3159 (selection_info[i].x << 1));
3160 selection_info[i].y=y;
3161 y+=(int) selection_info[i].height+(
int)
3162 (selection_info[i].bevel_width << 1)+6;
3164 XGetWidgetInfo((
char *) NULL,&toggle_info);
3165 toggle_info.bevel_width--;
3166 toggle_info.width=(
unsigned int) (((5*height) >> 3)-
3167 (toggle_info.bevel_width << 1));
3168 toggle_info.height=toggle_info.width;
3169 toggle_info.x=selection_info[0].x+(int) selection_info[0].width-
3170 (
int) toggle_info.width-(int) (QuantumMargin >> 1);
3171 if (windows->command.mapped)
3172 (void) XClearWindow(display,windows->command.id);
3174 if (state & RedrawWidgetState)
3182 tile_pixmap=XCreatePixmapFromBitmapData(display,windows->command.id,
3183 (
char *) tile_bits,tile_width,tile_height,1L,0L,1);
3184 if (tile_pixmap != (Pixmap) NULL)
3186 (void) XCopyPlane(display,tile_pixmap,windows->command.id,
3187 windows->command.annotate_context,0,0,tile_width,tile_height,
3188 (
int) ((windows->command.width-tile_width) >> 1),10,1L);
3189 (void) XFreePixmap(display,tile_pixmap);
3191 for (i=0; i < (int) number_selections; i++)
3193 XDrawBeveledButton(display,&windows->command,&selection_info[i]);
3194 if (i >= (
int) windows->command.data)
3196 toggle_info.raised=MagickFalse;
3197 toggle_info.y=selection_info[i].y+(int) (selection_info[i].height >> 1)-
3198 (int) (toggle_info.height >> 1);
3199 XDrawTriangleEast(display,&windows->command,&toggle_info);
3201 XHighlightWidget(display,&windows->command,BorderOffset,BorderOffset);
3238MagickPrivate
int XConfirmWidget(Display *display,XWindows *windows,
3239 const char *reason,
const char *description)
3241#define CancelButtonText "Cancel"
3242#define DismissButtonText "Dismiss"
3243#define YesButtonText "Yes"
3280 assert(display != (Display *) NULL);
3281 assert(windows != (XWindows *) NULL);
3282 assert(reason != (
char *) NULL);
3283 assert(description != (
char *) NULL);
3284 if (IsEventLogging() != MagickFalse)
3285 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",reason);
3286 XCheckRefreshWindows(display,windows);
3287 font_info=windows->widget.font_info;
3288 width=WidgetTextWidth(font_info,CancelButtonText);
3289 if (WidgetTextWidth(font_info,DismissButtonText) > width)
3290 width=WidgetTextWidth(font_info,DismissButtonText);
3291 if (WidgetTextWidth(font_info,YesButtonText) > width)
3292 width=WidgetTextWidth(font_info,YesButtonText);
3294 if (description != (
char *) NULL)
3295 if (WidgetTextWidth(font_info,(
char *) description) > width)
3296 width=WidgetTextWidth(font_info,(
char *) description);
3297 height=(
unsigned int) (font_info->ascent+font_info->descent);
3301 windows->widget.width=(
unsigned int) ((
int) width+9*QuantumMargin);
3302 windows->widget.min_width=9*(
unsigned int) QuantumMargin+
3303 WidgetTextWidth(font_info,CancelButtonText)+
3304 WidgetTextWidth(font_info,DismissButtonText)+
3305 WidgetTextWidth(font_info,YesButtonText);
3306 if (windows->widget.width < windows->widget.min_width)
3307 windows->widget.width=windows->widget.min_width;
3308 windows->widget.height=(
unsigned int) (12*height);
3309 windows->widget.min_height=(
unsigned int) (7*height);
3310 if (windows->widget.height < windows->widget.min_height)
3311 windows->widget.height=windows->widget.min_height;
3312 XConstrainWindowPosition(display,&windows->widget);
3316 (void) CopyMagickString(windows->widget.name,
"Confirm",MagickPathExtent);
3317 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
3318 if (status != False)
3320 XSetWMName(display,windows->widget.id,&window_name);
3321 XSetWMIconName(display,windows->widget.id,&window_name);
3322 (void) XFree((
void *) window_name.value);
3324 window_changes.width=(int) windows->widget.width;
3325 window_changes.height=(int) windows->widget.height;
3326 window_changes.x=windows->widget.x;
3327 window_changes.y=windows->widget.y;
3328 (void) XReconfigureWMWindow(display,windows->widget.id,windows->widget.screen,
3329 (
unsigned int) (CWWidth | CWHeight | CWX | CWY),&window_changes);
3330 (void) XMapRaised(display,windows->widget.id);
3331 windows->widget.mapped=MagickFalse;
3336 state=UpdateConfigurationState;
3337 XSetCursorState(display,windows,MagickTrue);
3340 if (state & UpdateConfigurationState)
3345 XGetWidgetInfo(CancelButtonText,&cancel_info);
3346 cancel_info.width=(
unsigned int) QuantumMargin+
3347 WidgetTextWidth(font_info,CancelButtonText);
3348 cancel_info.height=(
unsigned int) ((3*height) >> 1);
3349 cancel_info.x=(int) windows->widget.width-(
int) cancel_info.width-
3351 cancel_info.y=(int) (windows->widget.height-(cancel_info.height << 1));
3352 dismiss_info=cancel_info;
3353 dismiss_info.text=(
char *) DismissButtonText;
3354 if (LocaleCompare(description,
"Do you want to save it") == 0)
3355 dismiss_info.text=(
char *)
"Don't Save";
3356 dismiss_info.width=(
unsigned int) QuantumMargin+
3357 WidgetTextWidth(font_info,dismiss_info.text);
3358 dismiss_info.x=(int)
3359 ((windows->widget.width >> 1)-(dismiss_info.width >> 1));
3360 yes_info=cancel_info;
3361 yes_info.text=(
char *) YesButtonText;
3362 if (LocaleCompare(description,
"Do you want to save it") == 0)
3363 yes_info.text=(
char *)
"Save";
3364 yes_info.width=(
unsigned int) QuantumMargin+
3365 WidgetTextWidth(font_info,yes_info.text);
3366 if (yes_info.width < cancel_info.width)
3367 yes_info.width=cancel_info.width;
3368 yes_info.x=QuantumMargin;
3369 state&=(
unsigned int) (~UpdateConfigurationState);
3371 if (state & RedrawWidgetState)
3376 width=WidgetTextWidth(font_info,(
char *) reason);
3377 x=(int) ((windows->widget.width >> 1)-(width >> 1));
3378 y=(int) ((windows->widget.height >> 1)-(height << 1));
3379 (void) XDrawString(display,windows->widget.id,
3380 windows->widget.annotate_context,x,y,(
char *) reason,Extent(reason));
3381 if (description != (
char *) NULL)
3384 question[MagickPathExtent];
3386 (void) CopyMagickString(question,description,MagickPathExtent);
3387 (void) ConcatenateMagickString(question,
"?",MagickPathExtent);
3388 width=WidgetTextWidth(font_info,question);
3389 x=((int) (windows->widget.width >> 1)-(int) (width >> 1));
3391 (void) XDrawString(display,windows->widget.id,
3392 windows->widget.annotate_context,x,y,question,Extent(question));
3394 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3395 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
3396 XDrawBeveledButton(display,&windows->widget,&yes_info);
3397 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
3398 state&=(
unsigned int) (~RedrawWidgetState);
3403 (void) XIfEvent(display,&event,XScreenEvent,(
char *) windows);
3408 if (MatteIsActive(cancel_info,event.xbutton))
3413 cancel_info.raised=MagickFalse;
3414 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3417 if (MatteIsActive(dismiss_info,event.xbutton))
3422 dismiss_info.raised=MagickFalse;
3423 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
3426 if (MatteIsActive(yes_info,event.xbutton))
3431 yes_info.raised=MagickFalse;
3432 XDrawBeveledButton(display,&windows->widget,&yes_info);
3439 if (windows->widget.mapped == MagickFalse)
3441 if (cancel_info.raised == MagickFalse)
3443 if (event.xbutton.window == windows->widget.id)
3444 if (MatteIsActive(cancel_info,event.xbutton))
3449 cancel_info.raised=MagickTrue;
3450 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3452 if (dismiss_info.raised == MagickFalse)
3454 if (event.xbutton.window == windows->widget.id)
3455 if (MatteIsActive(dismiss_info,event.xbutton))
3460 dismiss_info.raised=MagickTrue;
3461 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
3463 if (yes_info.raised == MagickFalse)
3465 if (event.xbutton.window == windows->widget.id)
3466 if (MatteIsActive(yes_info,event.xbutton))
3471 yes_info.raised=MagickTrue;
3472 XDrawBeveledButton(display,&windows->widget,&yes_info);
3481 if (event.xclient.message_type != windows->wm_protocols)
3483 if (*event.xclient.data.l == (
int) windows->wm_take_focus)
3485 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
3486 (Time) event.xclient.data.l[1]);
3489 if (*event.xclient.data.l != (
int) windows->wm_delete_window)
3491 if (event.xclient.window == windows->widget.id)
3498 case ConfigureNotify:
3503 if (event.xconfigure.window != windows->widget.id)
3505 if ((event.xconfigure.width == (
int) windows->widget.width) &&
3506 (event.xconfigure.height == (
int) windows->widget.height))
3508 windows->widget.width=(
unsigned int)
3509 MagickMax(event.xconfigure.width,(
int) windows->widget.min_width);
3510 windows->widget.height=(
unsigned int)
3511 MagickMax(event.xconfigure.height,(
int) windows->widget.min_height);
3512 state|=UpdateConfigurationState;
3517 if (event.xcrossing.window != windows->widget.id)
3519 state&=(
unsigned int) (~InactiveWidgetState);
3524 if (event.xexpose.window != windows->widget.id)
3526 if (event.xexpose.count != 0)
3528 state|=RedrawWidgetState;
3534 command[MagickPathExtent];
3542 if (event.xkey.window != windows->widget.id)
3544 (void) XLookupString((XKeyEvent *) &event.xkey,command,
3545 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
3546 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
3548 yes_info.raised=MagickFalse;
3549 XDrawBeveledButton(display,&windows->widget,&yes_info);
3558 if (event.xcrossing.window != windows->widget.id)
3560 state|=InactiveWidgetState;
3568 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
3569 if (state & InactiveWidgetState)
3571 if (cancel_info.raised == MatteIsActive(cancel_info,event.xmotion))
3576 cancel_info.raised=cancel_info.raised == MagickFalse ?
3577 MagickTrue : MagickFalse;
3578 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3581 if (dismiss_info.raised == MatteIsActive(dismiss_info,event.xmotion))
3586 dismiss_info.raised=dismiss_info.raised == MagickFalse ?
3587 MagickTrue : MagickFalse;
3588 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
3591 if (yes_info.raised == MatteIsActive(yes_info,event.xmotion))
3596 yes_info.raised=yes_info.raised == MagickFalse ?
3597 MagickTrue : MagickFalse;
3598 XDrawBeveledButton(display,&windows->widget,&yes_info);
3606 }
while ((state & ExitState) == 0);
3607 XSetCursorState(display,windows,MagickFalse);
3608 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
3609 XCheckRefreshWindows(display,windows);
3647MagickPrivate
int XDialogWidget(Display *display,XWindows *windows,
3648 const char *action,
const char *query,
char *reply)
3650#define CancelButtonText "Cancel"
3653 primary_selection[MagickPathExtent];
3661 static MagickBooleanType
3662 raised = MagickFalse;
3697 assert(display != (Display *) NULL);
3698 assert(windows != (XWindows *) NULL);
3699 assert(action != (
char *) NULL);
3700 assert(query != (
char *) NULL);
3701 assert(reply != (
char *) NULL);
3702 if (IsEventLogging() != MagickFalse)
3703 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",action);
3704 XCheckRefreshWindows(display,windows);
3705 font_info=windows->widget.font_info;
3706 width=WidgetTextWidth(font_info,(
char *) action);
3707 if (WidgetTextWidth(font_info,CancelButtonText) > width)
3708 width=WidgetTextWidth(font_info,CancelButtonText);
3709 width+=(
unsigned int) (3*QuantumMargin) >> 1;
3710 height=(
unsigned int) (font_info->ascent+font_info->descent);
3714 windows->widget.width=(
unsigned int) MagickMax((
int) (2*width),(
int)
3715 WidgetTextWidth(font_info,(
char *) query));
3716 if (windows->widget.width < WidgetTextWidth(font_info,reply))
3717 windows->widget.width=WidgetTextWidth(font_info,reply);
3718 windows->widget.width+=(
unsigned int) (6*QuantumMargin);
3719 windows->widget.min_width=(
unsigned int)
3720 ((
int) width+28*XTextWidth(font_info,
"#",1)+4*QuantumMargin);
3721 if (windows->widget.width < windows->widget.min_width)
3722 windows->widget.width=windows->widget.min_width;
3723 windows->widget.height=(
unsigned int) (7*(
int) height+(QuantumMargin << 1));
3724 windows->widget.min_height=windows->widget.height;
3725 if (windows->widget.height < windows->widget.min_height)
3726 windows->widget.height=windows->widget.min_height;
3727 XConstrainWindowPosition(display,&windows->widget);
3731 (void) CopyMagickString(windows->widget.name,
"Dialog",MagickPathExtent);
3732 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
3733 if (status != False)
3735 XSetWMName(display,windows->widget.id,&window_name);
3736 XSetWMIconName(display,windows->widget.id,&window_name);
3737 (void) XFree((
void *) window_name.value);
3739 window_changes.width=(int) windows->widget.width;
3740 window_changes.height=(int) windows->widget.height;
3741 window_changes.x=windows->widget.x;
3742 window_changes.y=windows->widget.y;
3743 (void) XReconfigureWMWindow(display,windows->widget.id,windows->widget.screen,
3744 (
unsigned int) (CWWidth | CWHeight | CWX | CWY),&window_changes);
3745 (void) XMapRaised(display,windows->widget.id);
3746 windows->widget.mapped=MagickFalse;
3750 anomaly=(LocaleCompare(action,
"Background") == 0) ||
3751 (LocaleCompare(action,
"New") == 0) ||
3752 (LocaleCompare(action,
"Quantize") == 0) ||
3753 (LocaleCompare(action,
"Resize") == 0) ||
3754 (LocaleCompare(action,
"Save") == 0) ||
3755 (LocaleCompare(action,
"Shade") == 0);
3756 state=UpdateConfigurationState;
3757 XSetCursorState(display,windows,MagickTrue);
3760 if (state & UpdateConfigurationState)
3765 XGetWidgetInfo(CancelButtonText,&cancel_info);
3766 cancel_info.width=width;
3767 cancel_info.height=(
unsigned int) ((3*height) >> 1);
3768 cancel_info.x=(int) windows->widget.width-(
int) cancel_info.width-
3769 ((3*QuantumMargin) >> 1);
3770 cancel_info.y=(int) windows->widget.height-(
int) cancel_info.height-
3771 ((3*QuantumMargin) >> 1);
3772 XGetWidgetInfo(action,&action_info);
3773 action_info.width=width;
3774 action_info.height=(
unsigned int) ((3*height) >> 1);
3775 action_info.x=cancel_info.x-((int) cancel_info.width+QuantumMargin+
3776 (int) (action_info.bevel_width << 1));
3777 action_info.y=cancel_info.y;
3781 XGetWidgetInfo(reply,&reply_info);
3782 reply_info.raised=MagickFalse;
3783 reply_info.bevel_width--;
3784 reply_info.width=(
unsigned int) ((
int) windows->widget.width-
3786 reply_info.height=height << 1;
3787 reply_info.x=(3*QuantumMargin) >> 1;
3788 reply_info.y=action_info.y-(int) reply_info.height-QuantumMargin;
3792 XGetWidgetInfo(
"Dither",&special_info);
3793 special_info.raised=raised;
3794 special_info.bevel_width--;
3795 special_info.width=(
unsigned int) QuantumMargin >> 1;
3796 special_info.height=(
unsigned int) QuantumMargin >> 1;
3797 special_info.x=reply_info.x;
3798 special_info.y=action_info.y+(int) action_info.height-(
int)
3799 special_info.height;
3800 if (LocaleCompare(action,
"Background") == 0)
3801 special_info.text=(
char *)
"Backdrop";
3802 if (LocaleCompare(action,
"New") == 0)
3803 special_info.text=(
char *)
"Gradation";
3804 if (LocaleCompare(action,
"Resize") == 0)
3805 special_info.text=(
char *)
"Constrain ratio";
3806 if (LocaleCompare(action,
"Save") == 0)
3807 special_info.text=(
char *)
"Non-progressive";
3808 if (LocaleCompare(action,
"Shade") == 0)
3809 special_info.text=(
char *)
"Color shading";
3813 XGetWidgetInfo(query,&text_info);
3814 text_info.width=reply_info.width;
3815 text_info.height=height;
3816 text_info.x=reply_info.x-(int) (QuantumMargin >> 1);
3817 text_info.y=QuantumMargin;
3818 text_info.center=MagickFalse;
3819 state&=(
unsigned int) (~UpdateConfigurationState);
3821 if (state & RedrawWidgetState)
3826 XDrawWidgetText(display,&windows->widget,&text_info);
3827 XDrawBeveledMatte(display,&windows->widget,&reply_info);
3828 XDrawMatteText(display,&windows->widget,&reply_info);
3830 XDrawBeveledButton(display,&windows->widget,&special_info);
3831 XDrawBeveledButton(display,&windows->widget,&action_info);
3832 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3833 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
3834 state&=(
unsigned int) (~RedrawWidgetState);
3839 (void) XIfEvent(display,&event,XScreenEvent,(
char *) windows);
3845 if (MatteIsActive(special_info,event.xbutton))
3850 special_info.raised=!special_info.raised;
3851 XDrawBeveledButton(display,&windows->widget,&special_info);
3854 if (MatteIsActive(action_info,event.xbutton))
3859 action_info.raised=MagickFalse;
3860 XDrawBeveledButton(display,&windows->widget,&action_info);
3863 if (MatteIsActive(cancel_info,event.xbutton))
3868 cancel_info.raised=MagickFalse;
3869 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3872 if (MatteIsActive(reply_info,event.xbutton) == MagickFalse)
3874 if (event.xbutton.button != Button2)
3882 x=
event.xbutton.x-reply_info.x-(int) (QuantumMargin >> 2);
3883 for (i=1; i <= Extent(reply_info.marker); i++)
3884 if (XTextWidth(font_info,reply_info.marker,i) > x)
3886 reply_info.cursor=reply_info.marker+i-1;
3887 if (event.xbutton.time > (click_time+(
unsigned long) DoubleClick))
3888 reply_info.highlight=MagickFalse;
3894 (void) CopyMagickString(primary_selection,reply_info.text,
3896 (void) XSetSelectionOwner(display,XA_PRIMARY,windows->widget.id,
3897 event.xbutton.time);
3898 reply_info.highlight=XGetSelectionOwner(display,XA_PRIMARY) ==
3899 windows->widget.id ? MagickTrue : MagickFalse;
3901 XDrawMatteText(display,&windows->widget,&reply_info);
3902 click_time=
event.xbutton.time;
3908 (void) XConvertSelection(display,XA_PRIMARY,XA_STRING,XA_STRING,
3909 windows->widget.id,event.xbutton.time);
3914 if (windows->widget.mapped == MagickFalse)
3916 if (action_info.raised == MagickFalse)
3918 if (event.xbutton.window == windows->widget.id)
3919 if (MatteIsActive(action_info,event.xbutton))
3921 action_info.raised=MagickTrue;
3922 XDrawBeveledButton(display,&windows->widget,&action_info);
3924 if (cancel_info.raised == MagickFalse)
3926 if (event.xbutton.window == windows->widget.id)
3927 if (MatteIsActive(cancel_info,event.xbutton))
3929 *reply_info.text=
'\0';
3932 cancel_info.raised=MagickTrue;
3933 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3942 if (event.xclient.message_type != windows->wm_protocols)
3944 if (*event.xclient.data.l == (
int) windows->wm_take_focus)
3946 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
3947 (Time) event.xclient.data.l[1]);
3950 if (*event.xclient.data.l != (
int) windows->wm_delete_window)
3952 if (event.xclient.window == windows->widget.id)
3954 *reply_info.text=
'\0';
3960 case ConfigureNotify:
3965 if (event.xconfigure.window != windows->widget.id)
3967 if ((event.xconfigure.width == (
int) windows->widget.width) &&
3968 (event.xconfigure.height == (
int) windows->widget.height))
3970 windows->widget.width=(
unsigned int)
3971 MagickMax(event.xconfigure.width,(
int) windows->widget.min_width);
3972 windows->widget.height=(
unsigned int)
3973 MagickMax(event.xconfigure.height,(
int) windows->widget.min_height);
3974 state|=UpdateConfigurationState;
3979 if (event.xcrossing.window != windows->widget.id)
3981 state&=(
unsigned int) (~InactiveWidgetState);
3986 if (event.xexpose.window != windows->widget.id)
3988 if (event.xexpose.count != 0)
3990 state|=RedrawWidgetState;
3996 command[MagickPathExtent];
4007 if (event.xkey.window != windows->widget.id)
4009 length=XLookupString((XKeyEvent *) &event.xkey,command,
4010 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
4011 *(command+length)=
'\0';
4012 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
4014 action_info.raised=MagickFalse;
4015 XDrawBeveledButton(display,&windows->widget,&action_info);
4019 if (key_symbol == XK_Control_L)
4021 state|=ControlState;
4024 if (state & ControlState)
4025 switch ((
int) key_symbol)
4033 *reply_info.text=
'\0';
4034 reply_info.cursor=reply_info.text;
4035 reply_info.marker=reply_info.text;
4036 reply_info.highlight=MagickFalse;
4042 XEditText(display,&reply_info,key_symbol,command,state);
4043 XDrawMatteText(display,&windows->widget,&reply_info);
4049 command[MagickPathExtent];
4057 if (event.xkey.window != windows->widget.id)
4059 (void) XLookupString((XKeyEvent *) &event.xkey,command,
4060 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
4061 if (key_symbol == XK_Control_L)
4062 state&=(
unsigned int) (~ControlState);
4067 if (event.xcrossing.window != windows->widget.id)
4069 state|=InactiveWidgetState;
4077 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
4078 if (state & InactiveWidgetState)
4080 if (action_info.raised == MatteIsActive(action_info,event.xmotion))
4085 action_info.raised=action_info.raised == MagickFalse ?
4086 MagickTrue : MagickFalse;
4087 XDrawBeveledButton(display,&windows->widget,&action_info);
4090 if (cancel_info.raised == MatteIsActive(cancel_info,event.xmotion))
4095 cancel_info.raised=cancel_info.raised == MagickFalse ?
4096 MagickTrue : MagickFalse;
4097 XDrawBeveledButton(display,&windows->widget,&cancel_info);
4102 case SelectionClear:
4104 reply_info.highlight=MagickFalse;
4105 XDrawMatteText(display,&windows->widget,&reply_info);
4108 case SelectionNotify:
4126 if (event.xselection.property == (Atom) None)
4128 status=XGetWindowProperty(display,event.xselection.requestor,
4129 event.xselection.property,0L,2047L,MagickTrue,XA_STRING,&type,
4130 &format,&length,&after,&data);
4131 if ((status != Success) || (type != XA_STRING) || (format == 32) ||
4134 if ((Extent(reply_info.text)+(
int) length) >= (MagickPathExtent-1))
4135 (void) XBell(display,0);
4141 *(data+length)=
'\0';
4142 XEditText(display,&reply_info,(KeySym) XK_Insert,(
char *) data,
4144 XDrawMatteText(display,&windows->widget,&reply_info);
4146 (void) XFree((
void *) data);
4149 case SelectionRequest:
4154 XSelectionRequestEvent
4157 if (reply_info.highlight == MagickFalse)
4162 request=(&(
event.xselectionrequest));
4163 (void) XChangeProperty(request->display,request->requestor,
4164 request->property,request->target,8,PropModeReplace,
4165 (
unsigned char *) primary_selection,Extent(primary_selection));
4166 notify.type=SelectionNotify;
4167 notify.display=request->display;
4168 notify.requestor=request->requestor;
4169 notify.selection=request->selection;
4170 notify.target=request->target;
4171 notify.time=request->time;
4172 if (request->property == None)
4173 notify.property=request->target;
4175 notify.property=request->property;
4176 (void) XSendEvent(request->display,request->requestor,False,0,
4177 (XEvent *) ¬ify);
4182 }
while ((state & ExitState) == 0);
4183 XSetCursorState(display,windows,MagickFalse);
4184 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
4185 XCheckRefreshWindows(display,windows);
4187 if (special_info.raised)
4190 return(raised == MagickFalse);
4225MagickPrivate
void XFileBrowserWidget(Display *display,XWindows *windows,
4226 const char *action,
char *reply)
4228#define CancelButtonText "Cancel"
4229#define DirectoryText "Directory:"
4230#define FilenameText "File name:"
4231#define GrabButtonText "Grab"
4232#define FormatButtonText "Format"
4233#define HomeButtonText "Home"
4234#define UpButtonText "Up"
4239 home_directory[MagickPathExtent],
4240 primary_selection[MagickPathExtent],
4241 text[MagickPathExtent],
4242 working_path[MagickPathExtent];
4249 glob_pattern[MagickPathExtent] =
"*",
4250 format[MagickPathExtent] =
"miff";
4252 static MagickStatusType
4253 mask = (MagickStatusType) (CWWidth | CWHeight | CWX | CWY);
4304 assert(display != (Display *) NULL);
4305 assert(windows != (XWindows *) NULL);
4306 assert(action != (
char *) NULL);
4307 assert(reply != (
char *) NULL);
4308 if (IsEventLogging() != MagickFalse)
4309 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",action);
4310 XSetCursorState(display,windows,MagickTrue);
4311 XCheckRefreshWindows(display,windows);
4312 directory=getcwd(home_directory,MagickPathExtent);
4314 (void) CopyMagickString(working_path,home_directory,MagickPathExtent);
4315 filelist=ListFiles(working_path,glob_pattern,&files);
4316 if (filelist == (
char **) NULL)
4321 XNoticeWidget(display,windows,
"Unable to read directory:",working_path);
4322 (void) XDialogWidget(display,windows,action,
"Enter filename:",reply);
4328 font_info=windows->widget.font_info;
4330 for (i=0; i < (ssize_t) files; i++)
4331 if (WidgetTextWidth(font_info,filelist[i]) > text_width)
4332 text_width=WidgetTextWidth(font_info,filelist[i]);
4333 width=WidgetTextWidth(font_info,(
char *) action);
4334 if (WidgetTextWidth(font_info,GrabButtonText) > width)
4335 width=WidgetTextWidth(font_info,GrabButtonText);
4336 if (WidgetTextWidth(font_info,FormatButtonText) > width)
4337 width=WidgetTextWidth(font_info,FormatButtonText);
4338 if (WidgetTextWidth(font_info,CancelButtonText) > width)
4339 width=WidgetTextWidth(font_info,CancelButtonText);
4340 if (WidgetTextWidth(font_info,HomeButtonText) > width)
4341 width=WidgetTextWidth(font_info,HomeButtonText);
4342 if (WidgetTextWidth(font_info,UpButtonText) > width)
4343 width=WidgetTextWidth(font_info,UpButtonText);
4344 width+=(
unsigned int) QuantumMargin;
4345 if (WidgetTextWidth(font_info,DirectoryText) > width)
4346 width=WidgetTextWidth(font_info,DirectoryText);
4347 if (WidgetTextWidth(font_info,FilenameText) > width)
4348 width=WidgetTextWidth(font_info,FilenameText);
4349 height=(
unsigned int) (font_info->ascent+font_info->descent);
4353 windows->widget.width=width+MagickMin(text_width,MaxTextWidth)+
4354 (
unsigned int) (6*QuantumMargin);
4355 windows->widget.min_width=width+MinTextWidth+(
unsigned int) (4*QuantumMargin);
4356 if (windows->widget.width < windows->widget.min_width)
4357 windows->widget.width=windows->widget.min_width;
4358 windows->widget.height=(
unsigned int)
4359 (((81*height) >> 2)+(
unsigned int) ((13*QuantumMargin) >> 1)+4);
4360 windows->widget.min_height=(
unsigned int)
4361 (((23*height) >> 1)+(
unsigned int) ((13*QuantumMargin) >> 1)+4);
4362 if (windows->widget.height < windows->widget.min_height)
4363 windows->widget.height=windows->widget.min_height;
4364 XConstrainWindowPosition(display,&windows->widget);
4368 (void) CopyMagickString(windows->widget.name,
"Browse and Select a File",
4370 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
4371 if (status != False)
4373 XSetWMName(display,windows->widget.id,&window_name);
4374 XSetWMIconName(display,windows->widget.id,&window_name);
4375 (void) XFree((
void *) window_name.value);
4377 window_changes.width=(int) windows->widget.width;
4378 window_changes.height=(int) windows->widget.height;
4379 window_changes.x=windows->widget.x;
4380 window_changes.y=windows->widget.y;
4381 (void) XReconfigureWMWindow(display,windows->widget.id,
4382 windows->widget.screen,mask,&window_changes);
4383 (void) XMapRaised(display,windows->widget.id);
4384 windows->widget.mapped=MagickFalse;
4388 XGetWidgetInfo((
char *) NULL,&slider_info);
4389 XGetWidgetInfo((
char *) NULL,&north_info);
4390 XGetWidgetInfo((
char *) NULL,&south_info);
4391 XGetWidgetInfo((
char *) NULL,&expose_info);
4393 anomaly=(LocaleCompare(action,
"Composite") == 0) ||
4394 (LocaleCompare(action,
"Open") == 0) || (LocaleCompare(action,
"Map") == 0);
4395 delay=SuspendTime << 2;
4396 state=UpdateConfigurationState;
4399 if (state & UpdateConfigurationState)
4407 XGetWidgetInfo(CancelButtonText,&cancel_info);
4408 cancel_info.width=width;
4409 cancel_info.height=(
unsigned int) ((3*height) >> 1);
4410 cancel_info.x=(int) windows->widget.width-(
int) cancel_info.width-
4412 cancel_info.y=(int) windows->widget.height-(
int) cancel_info.height-
4414 XGetWidgetInfo(action,&action_info);
4415 action_info.width=width;
4416 action_info.height=(
unsigned int) ((3*height) >> 1);
4417 action_info.x=cancel_info.x-((int) cancel_info.width+
4418 (QuantumMargin >> 1)+(int) (action_info.bevel_width << 1));
4419 action_info.y=cancel_info.y;
4420 XGetWidgetInfo(GrabButtonText,&special_info);
4421 special_info.width=width;
4422 special_info.height=(
unsigned int) ((3*height) >> 1);
4423 special_info.x=action_info.x-((int) action_info.width+
4424 (QuantumMargin >> 1)+(int) (special_info.bevel_width << 1));
4425 special_info.y=action_info.y;
4426 if (anomaly == MagickFalse)
4431 special_info.text=(
char *) FormatButtonText;
4432 p=reply+Extent(reply)-1;
4433 while ((p > (reply+1)) && (*(p-1) !=
'.'))
4435 if ((p > (reply+1)) && (*(p-1) ==
'.'))
4436 (void) CopyMagickString(format,p,MagickPathExtent);
4438 XGetWidgetInfo(UpButtonText,&up_info);
4439 up_info.width=width;
4440 up_info.height=(
unsigned int) ((3*height) >> 1);
4441 up_info.x=QuantumMargin;
4442 up_info.y=(int) ((5*QuantumMargin) >> 1)+(int) height;
4443 XGetWidgetInfo(HomeButtonText,&home_info);
4444 home_info.width=width;
4445 home_info.height=(
unsigned int) ((3*height) >> 1);
4446 home_info.x=QuantumMargin;
4447 home_info.y=up_info.y+(int) up_info.height+QuantumMargin;
4451 XGetWidgetInfo(reply,&reply_info);
4452 reply_info.raised=MagickFalse;
4453 reply_info.bevel_width--;
4454 reply_info.width=windows->widget.width-width-(
unsigned int)
4455 ((6*QuantumMargin) >> 1);
4456 reply_info.height=height << 1;
4457 reply_info.x=(int) width+(QuantumMargin << 1);
4458 reply_info.y=action_info.y-(int) reply_info.height-QuantumMargin;
4462 XGetWidgetInfo((
char *) NULL,&scroll_info);
4463 scroll_info.bevel_width--;
4464 scroll_info.width=height;
4465 scroll_info.height=(
unsigned int)
4466 (reply_info.y-up_info.y-(
int) (QuantumMargin >> 1));
4467 scroll_info.x=reply_info.x+(int) (reply_info.width-scroll_info.width);
4468 scroll_info.y=up_info.y-(int) reply_info.bevel_width;
4469 scroll_info.raised=MagickFalse;
4470 scroll_info.trough=MagickTrue;
4471 north_info=scroll_info;
4472 north_info.raised=MagickTrue;
4473 north_info.width-=(north_info.bevel_width << 1);
4474 north_info.height=north_info.width-1;
4475 north_info.x+=(int) north_info.bevel_width;
4476 north_info.y+=(int) north_info.bevel_width;
4477 south_info=north_info;
4478 south_info.y=scroll_info.y+(int) scroll_info.height-(
int)
4479 scroll_info.bevel_width-(int) south_info.height;
4481 slider_info=north_info;
4483 slider_info.width-=2;
4484 slider_info.min_y=north_info.y+(int) north_info.height+(
int)
4485 north_info.bevel_width+(int) slider_info.bevel_width+2;
4486 slider_info.height=(
unsigned int) ((
int) scroll_info.height-
4487 ((slider_info.min_y-scroll_info.y+1) << 1)+4);
4488 visible_files=(
unsigned int) (scroll_info.height*
4489 PerceptibleReciprocal((
double) height+(height >> 3)));
4490 if (files > visible_files)
4491 slider_info.height=(
unsigned int)
4492 ((visible_files*slider_info.height)/files);
4493 slider_info.max_y=south_info.y-(int) south_info.bevel_width-(
int)
4494 slider_info.bevel_width-2;
4495 slider_info.x=scroll_info.x+(int) slider_info.bevel_width+1;
4496 slider_info.y=slider_info.min_y;
4497 expose_info=scroll_info;
4498 expose_info.y=slider_info.y;
4502 XGetWidgetInfo((
char *) NULL,&list_info);
4503 list_info.raised=MagickFalse;
4504 list_info.bevel_width--;
4505 list_info.width=(
unsigned int)
4506 (scroll_info.x-reply_info.x-(
int) (QuantumMargin >> 1));
4507 list_info.height=scroll_info.height;
4508 list_info.x=reply_info.x;
4509 list_info.y=scroll_info.y;
4510 if (windows->widget.mapped == MagickFalse)
4511 state|=JumpListState;
4516 XGetWidgetInfo(text,&text_info);
4517 text_info.center=MagickFalse;
4518 text_info.width=reply_info.width;
4519 text_info.height=height;
4520 text_info.x=list_info.x-(int) (QuantumMargin >> 1);
4521 text_info.y=QuantumMargin;
4525 XGetWidgetInfo((
char *) NULL,&selection_info);
4526 selection_info.center=MagickFalse;
4527 selection_info.width=list_info.width;
4528 selection_info.height=(
unsigned int) ((9*height) >> 3);
4529 selection_info.x=list_info.x;
4530 state&=(
unsigned int) (~UpdateConfigurationState);
4532 if (state & RedrawWidgetState)
4538 y=text_info.y+(int) ((text_info.height-height) >> 1)+font_info->ascent;
4539 (void) XDrawString(display,windows->widget.id,
4540 windows->widget.annotate_context,x,y,DirectoryText,
4541 Extent(DirectoryText));
4542 (void) CopyMagickString(text_info.text,working_path,MagickPathExtent);
4543 (void) ConcatenateMagickString(text_info.text,DirectorySeparator,
4545 (void) ConcatenateMagickString(text_info.text,glob_pattern,
4547 XDrawWidgetText(display,&windows->widget,&text_info);
4548 XDrawBeveledButton(display,&windows->widget,&up_info);
4549 XDrawBeveledButton(display,&windows->widget,&home_info);
4550 XDrawBeveledMatte(display,&windows->widget,&list_info);
4551 XDrawBeveledMatte(display,&windows->widget,&scroll_info);
4552 XDrawTriangleNorth(display,&windows->widget,&north_info);
4553 XDrawBeveledButton(display,&windows->widget,&slider_info);
4554 XDrawTriangleSouth(display,&windows->widget,&south_info);
4556 y=reply_info.y+(int) ((reply_info.height-height) >> 1)+
4558 (void) XDrawString(display,windows->widget.id,
4559 windows->widget.annotate_context,x,y,FilenameText,
4560 Extent(FilenameText));
4561 XDrawBeveledMatte(display,&windows->widget,&reply_info);
4562 XDrawMatteText(display,&windows->widget,&reply_info);
4563 XDrawBeveledButton(display,&windows->widget,&special_info);
4564 XDrawBeveledButton(display,&windows->widget,&action_info);
4565 XDrawBeveledButton(display,&windows->widget,&cancel_info);
4566 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
4567 selection_info.id=(~0);
4568 state|=RedrawListState;
4569 state&=(
unsigned int) (~RedrawWidgetState);
4571 if (state & UpdateListState)
4582 checklist=ListFiles(working_path,glob_pattern,&number_files);
4583 if (checklist == (
char **) NULL)
4588 action_info.raised=MagickFalse;
4589 XDrawBeveledButton(display,&windows->widget,&action_info);
4592 for (i=0; i < (ssize_t) files; i++)
4593 filelist[i]=DestroyString(filelist[i]);
4594 if (filelist != (
char **) NULL)
4595 filelist=(
char **) RelinquishMagickMemory(filelist);
4601 slider_info.height=(
unsigned int) ((
int) scroll_info.height-
4602 ((slider_info.min_y-scroll_info.y+1) << 1)+1);
4603 if (files > visible_files)
4604 slider_info.height=(
unsigned int)
4605 ((visible_files*slider_info.height)/files);
4606 slider_info.max_y=south_info.y-(int) south_info.bevel_width-
4607 (
int) slider_info.bevel_width-2;
4609 slider_info.y=slider_info.min_y;
4610 expose_info.y=slider_info.y;
4611 selection_info.id=(~0);
4613 state|=RedrawListState;
4617 if (IsGlob(reply_info.text) == MagickFalse)
4619 *reply_info.text=
'\0';
4620 reply_info.cursor=reply_info.text;
4622 (void) CopyMagickString(text_info.text,working_path,MagickPathExtent);
4623 (void) ConcatenateMagickString(text_info.text,DirectorySeparator,
4625 (void) ConcatenateMagickString(text_info.text,glob_pattern,
4627 XDrawWidgetText(display,&windows->widget,&text_info);
4628 XDrawMatteText(display,&windows->widget,&reply_info);
4629 XDrawBeveledMatte(display,&windows->widget,&scroll_info);
4630 XDrawTriangleNorth(display,&windows->widget,&north_info);
4631 XDrawBeveledButton(display,&windows->widget,&slider_info);
4632 XDrawTriangleSouth(display,&windows->widget,&south_info);
4633 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
4634 state&=(
unsigned int) (~UpdateListState);
4636 if (state & JumpListState)
4642 for (i=0; i < (ssize_t) files; i++)
4643 if (LocaleCompare(filelist[i],reply) >= 0)
4646 (LocaleCompare(filelist[i],reply) == 0 ? i : ~0);
4649 if ((i < (ssize_t) slider_info.id) ||
4650 (i >= (slider_info.id+(ssize_t) visible_files)))
4651 slider_info.id=i-(int) (visible_files >> 1);
4652 selection_info.id=(~0);
4653 state|=RedrawListState;
4654 state&=(
unsigned int) (~JumpListState);
4656 if (state & RedrawListState)
4661 if (slider_info.id >= (
int) (files-visible_files))
4662 slider_info.id=(int) (files-visible_files);
4663 if ((slider_info.id < 0) || (files <= visible_files))
4665 slider_info.y=slider_info.min_y;
4667 slider_info.y+=((int) slider_info.id*(slider_info.max_y-
4668 slider_info.min_y+1)/(int) files);
4669 if (slider_info.id != selection_info.id)
4674 selection_info.id=slider_info.id;
4675 selection_info.y=list_info.y+(int) (height >> 3)+2;
4676 for (i=0; i < (ssize_t) visible_files; i++)
4678 selection_info.raised=(int) (slider_info.id+i) != list_info.id ?
4679 MagickTrue : MagickFalse;
4680 selection_info.text=(
char *) NULL;
4681 if ((slider_info.id+i) < (ssize_t) files)
4682 selection_info.text=filelist[slider_info.id+i];
4683 XDrawWidgetText(display,&windows->widget,&selection_info);
4684 selection_info.y+=(int) selection_info.height;
4689 if (slider_info.y > expose_info.y)
4691 expose_info.height=(
unsigned int) (slider_info.y-expose_info.y);
4692 expose_info.y=slider_info.y-(int) expose_info.height-(
int)
4693 slider_info.bevel_width-1;
4697 expose_info.height=(
unsigned int) (expose_info.y-slider_info.y);
4698 expose_info.y=slider_info.y+(int) slider_info.height+(
int)
4699 slider_info.bevel_width+1;
4701 XDrawTriangleNorth(display,&windows->widget,&north_info);
4702 XDrawMatte(display,&windows->widget,&expose_info);
4703 XDrawBeveledButton(display,&windows->widget,&slider_info);
4704 XDrawTriangleSouth(display,&windows->widget,&south_info);
4705 expose_info.y=slider_info.y;
4707 state&=(
unsigned int) (~RedrawListState);
4712 if (north_info.raised && south_info.raised)
4713 (void) XIfEvent(display,&event,XScreenEvent,(
char *) windows);
4719 XDelay(display,delay);
4721 (void) XCheckIfEvent(display,&event,XScreenEvent,(
char *) windows);
4722 if (north_info.raised == MagickFalse)
4723 if (slider_info.id > 0)
4729 state|=RedrawListState;
4731 if (south_info.raised == MagickFalse)
4732 if (slider_info.id < (
int) files)
4738 state|=RedrawListState;
4740 if (event.type != ButtonRelease)
4747 if (MatteIsActive(slider_info,event.xbutton))
4752 slider_info.active=MagickTrue;
4755 if (MatteIsActive(north_info,event.xbutton))
4756 if (slider_info.id > 0)
4761 north_info.raised=MagickFalse;
4763 state|=RedrawListState;
4766 if (MatteIsActive(south_info,event.xbutton))
4767 if (slider_info.id < (
int) files)
4772 south_info.raised=MagickFalse;
4774 state|=RedrawListState;
4777 if (MatteIsActive(scroll_info,event.xbutton))
4782 if (event.xbutton.y < slider_info.y)
4783 slider_info.id-=(int) (visible_files-1);
4785 slider_info.id+=(int) (visible_files-1);
4786 state|=RedrawListState;
4789 if (MatteIsActive(list_info,event.xbutton))
4797 id=slider_info.id+(
event.xbutton.y-(list_info.y+(int)
4798 (height >> 1))+1)/(
int) selection_info.height;
4799 if (
id >= (
int) files)
4801 (void) CopyMagickString(reply_info.text,filelist[
id],MagickPathExtent);
4802 reply_info.highlight=MagickFalse;
4803 reply_info.marker=reply_info.text;
4804 reply_info.cursor=reply_info.text+Extent(reply_info.text);
4805 XDrawMatteText(display,&windows->widget,&reply_info);
4806 if (
id == list_info.id)
4811 p=reply_info.text+strlen(reply_info.text)-1;
4812 if (*p == *DirectorySeparator)
4813 ChopPathComponents(reply_info.text,1);
4814 (void) ConcatenateMagickString(working_path,DirectorySeparator,
4816 (void) ConcatenateMagickString(working_path,reply_info.text,
4819 state|=UpdateListState;
4821 selection_info.id=(~0);
4823 state|=RedrawListState;
4826 if (MatteIsActive(up_info,event.xbutton))
4831 up_info.raised=MagickFalse;
4832 XDrawBeveledButton(display,&windows->widget,&up_info);
4835 if (MatteIsActive(home_info,event.xbutton))
4840 home_info.raised=MagickFalse;
4841 XDrawBeveledButton(display,&windows->widget,&home_info);
4844 if (MatteIsActive(special_info,event.xbutton))
4849 special_info.raised=MagickFalse;
4850 XDrawBeveledButton(display,&windows->widget,&special_info);
4853 if (MatteIsActive(action_info,event.xbutton))
4858 action_info.raised=MagickFalse;
4859 XDrawBeveledButton(display,&windows->widget,&action_info);
4862 if (MatteIsActive(cancel_info,event.xbutton))
4867 cancel_info.raised=MagickFalse;
4868 XDrawBeveledButton(display,&windows->widget,&cancel_info);
4871 if (MatteIsActive(reply_info,event.xbutton) == MagickFalse)
4873 if (event.xbutton.button != Button2)
4881 x=
event.xbutton.x-reply_info.x-(int) (QuantumMargin >> 2);
4882 for (i=1; i <= (ssize_t) Extent(reply_info.marker); i++)
4883 if (XTextWidth(font_info,reply_info.marker,(
int) i) > x)
4885 reply_info.cursor=reply_info.marker+i-1;
4886 if (event.xbutton.time > (click_time+(
unsigned long) DoubleClick))
4887 reply_info.highlight=MagickFalse;
4893 (void) CopyMagickString(primary_selection,reply_info.text,
4895 (void) XSetSelectionOwner(display,XA_PRIMARY,windows->widget.id,
4896 event.xbutton.time);
4897 reply_info.highlight=XGetSelectionOwner(display,XA_PRIMARY) ==
4898 windows->widget.id ? MagickTrue : MagickFalse;
4900 XDrawMatteText(display,&windows->widget,&reply_info);
4901 click_time=
event.xbutton.time;
4907 (void) XConvertSelection(display,XA_PRIMARY,XA_STRING,XA_STRING,
4908 windows->widget.id,event.xbutton.time);
4913 if (windows->widget.mapped == MagickFalse)
4915 if (north_info.raised == MagickFalse)
4920 delay=SuspendTime << 2;
4921 north_info.raised=MagickTrue;
4922 XDrawTriangleNorth(display,&windows->widget,&north_info);
4924 if (south_info.raised == MagickFalse)
4929 delay=SuspendTime << 2;
4930 south_info.raised=MagickTrue;
4931 XDrawTriangleSouth(display,&windows->widget,&south_info);
4933 if (slider_info.active)
4938 slider_info.active=MagickFalse;
4941 if (up_info.raised == MagickFalse)
4943 if (event.xbutton.window == windows->widget.id)
4944 if (MatteIsActive(up_info,event.xbutton))
4946 ChopPathComponents(working_path,1);
4947 if (*working_path ==
'\0')
4948 (void) CopyMagickString(working_path,DirectorySeparator,
4950 state|=UpdateListState;
4952 up_info.raised=MagickTrue;
4953 XDrawBeveledButton(display,&windows->widget,&up_info);
4955 if (home_info.raised == MagickFalse)
4957 if (event.xbutton.window == windows->widget.id)
4958 if (MatteIsActive(home_info,event.xbutton))
4960 (void) CopyMagickString(working_path,home_directory,
4962 state|=UpdateListState;
4964 home_info.raised=MagickTrue;
4965 XDrawBeveledButton(display,&windows->widget,&home_info);
4967 if (special_info.raised == MagickFalse)
4969 if (anomaly == MagickFalse)
4983 exception=AcquireExceptionInfo();
4984 formats=GetMagickList(
"*",&number_formats,exception);
4985 exception=DestroyExceptionInfo(exception);
4986 if (formats == (
char **) NULL)
4988 (void) XCheckDefineCursor(display,windows->widget.id,
4989 windows->widget.busy_cursor);
4990 windows->popup.x=windows->widget.x+60;
4991 windows->popup.y=windows->widget.y+60;
4992 XListBrowserWidget(display,windows,&windows->popup,
4993 (
const char **) formats,
"Select",
"Select image format type:",
4995 XSetCursorState(display,windows,MagickTrue);
4996 (void) XCheckDefineCursor(display,windows->widget.id,
4997 windows->widget.cursor);
4998 LocaleLower(format);
4999 AppendImageFormat(format,reply_info.text);
5000 reply_info.cursor=reply_info.text+Extent(reply_info.text);
5001 XDrawMatteText(display,&windows->widget,&reply_info);
5002 special_info.raised=MagickTrue;
5003 XDrawBeveledButton(display,&windows->widget,&special_info);
5004 for (i=0; i < (ssize_t) number_formats; i++)
5005 formats[i]=DestroyString(formats[i]);
5006 formats=(
char **) RelinquishMagickMemory(formats);
5009 if (event.xbutton.window == windows->widget.id)
5010 if (MatteIsActive(special_info,event.xbutton))
5012 (void) CopyMagickString(working_path,
"x:",MagickPathExtent);
5015 special_info.raised=MagickTrue;
5016 XDrawBeveledButton(display,&windows->widget,&special_info);
5018 if (action_info.raised == MagickFalse)
5020 if (event.xbutton.window == windows->widget.id)
5022 if (MatteIsActive(action_info,event.xbutton))
5024 if (*reply_info.text ==
'\0')
5025 (void) XBell(display,0);
5030 action_info.raised=MagickTrue;
5031 XDrawBeveledButton(display,&windows->widget,&action_info);
5033 if (cancel_info.raised == MagickFalse)
5035 if (event.xbutton.window == windows->widget.id)
5036 if (MatteIsActive(cancel_info,event.xbutton))
5038 *reply_info.text=
'\0';
5042 cancel_info.raised=MagickTrue;
5043 XDrawBeveledButton(display,&windows->widget,&cancel_info);
5052 if (event.xclient.message_type != windows->wm_protocols)
5054 if (*event.xclient.data.l == (
int) windows->wm_take_focus)
5056 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
5057 (Time) event.xclient.data.l[1]);
5060 if (*event.xclient.data.l != (
int) windows->wm_delete_window)
5062 if (event.xclient.window == windows->widget.id)
5064 *reply_info.text=
'\0';
5070 case ConfigureNotify:
5075 if (event.xconfigure.window != windows->widget.id)
5077 if ((event.xconfigure.width == (
int) windows->widget.width) &&
5078 (event.xconfigure.height == (
int) windows->widget.height))
5080 windows->widget.width=(
unsigned int)
5081 MagickMax(event.xconfigure.width,(
int) windows->widget.min_width);
5082 windows->widget.height=(
unsigned int)
5083 MagickMax(event.xconfigure.height,(
int) windows->widget.min_height);
5084 state|=UpdateConfigurationState;
5089 if (event.xcrossing.window != windows->widget.id)
5091 state&=(
unsigned int) (~InactiveWidgetState);
5096 if (event.xexpose.window != windows->widget.id)
5098 if (event.xexpose.count != 0)
5100 state|=RedrawWidgetState;
5106 command[MagickPathExtent];
5117 if (event.xkey.window != windows->widget.id)
5119 length=XLookupString((XKeyEvent *) &event.xkey,command,
5120 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
5121 *(command+length)=
'\0';
5122 if (AreaIsActive(scroll_info,event.xkey))
5127 switch ((
int) key_symbol)
5150 slider_info.id-=(int) visible_files;
5156 slider_info.id+=(int) visible_files;
5162 slider_info.id=(int) files;
5166 state|=RedrawListState;
5169 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
5174 if (*reply_info.text ==
'\0')
5176 if (IsGlob(reply_info.text))
5177 (void) CopyMagickString(glob_pattern,reply_info.text,
5181 (void) ConcatenateMagickString(working_path,DirectorySeparator,
5183 (void) ConcatenateMagickString(working_path,reply_info.text,
5185 if (*working_path ==
'~')
5186 ExpandFilename(working_path);
5189 state|=UpdateListState;
5192 if (key_symbol == XK_Control_L)
5194 state|=ControlState;
5197 if (state & ControlState)
5198 switch ((
int) key_symbol)
5206 *reply_info.text=
'\0';
5207 reply_info.cursor=reply_info.text;
5208 reply_info.marker=reply_info.text;
5209 reply_info.highlight=MagickFalse;
5215 XEditText(display,&reply_info,key_symbol,command,state);
5216 XDrawMatteText(display,&windows->widget,&reply_info);
5217 state|=JumpListState;
5223 command[MagickPathExtent];
5231 if (event.xkey.window != windows->widget.id)
5233 (void) XLookupString((XKeyEvent *) &event.xkey,command,
5234 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
5235 if (key_symbol == XK_Control_L)
5236 state&=(
unsigned int) (~ControlState);
5241 if (event.xcrossing.window != windows->widget.id)
5243 state|=InactiveWidgetState;
5248 mask&=(
unsigned int) (~CWX);
5249 mask&=(
unsigned int) (~CWY);
5257 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
5258 if (slider_info.active)
5263 slider_info.y=
event.xmotion.y-(int)
5264 ((slider_info.height+slider_info.bevel_width) >> 1)+1;
5265 if (slider_info.y < slider_info.min_y)
5266 slider_info.y=slider_info.min_y;
5267 if (slider_info.y > slider_info.max_y)
5268 slider_info.y=slider_info.max_y;
5270 if (slider_info.y != slider_info.min_y)
5271 slider_info.id=((int) files*(slider_info.y-slider_info.min_y+1))/
5272 (slider_info.max_y-slider_info.min_y+1);
5273 state|=RedrawListState;
5276 if (state & InactiveWidgetState)
5278 if (up_info.raised == MatteIsActive(up_info,event.xmotion))
5283 up_info.raised=!up_info.raised;
5284 XDrawBeveledButton(display,&windows->widget,&up_info);
5287 if (home_info.raised == MatteIsActive(home_info,event.xmotion))
5292 home_info.raised=!home_info.raised;
5293 XDrawBeveledButton(display,&windows->widget,&home_info);
5296 if (special_info.raised == MatteIsActive(special_info,event.xmotion))
5301 special_info.raised=!special_info.raised;
5302 XDrawBeveledButton(display,&windows->widget,&special_info);
5305 if (action_info.raised == MatteIsActive(action_info,event.xmotion))
5310 action_info.raised=action_info.raised == MagickFalse ?
5311 MagickTrue : MagickFalse;
5312 XDrawBeveledButton(display,&windows->widget,&action_info);
5315 if (cancel_info.raised == MatteIsActive(cancel_info,event.xmotion))
5320 cancel_info.raised=cancel_info.raised == MagickFalse ?
5321 MagickTrue : MagickFalse;
5322 XDrawBeveledButton(display,&windows->widget,&cancel_info);
5327 case SelectionClear:
5329 reply_info.highlight=MagickFalse;
5330 XDrawMatteText(display,&windows->widget,&reply_info);
5333 case SelectionNotify:
5351 if (event.xselection.property == (Atom) None)
5353 status=XGetWindowProperty(display,event.xselection.requestor,
5354 event.xselection.property,0L,2047L,MagickTrue,XA_STRING,&type,
5355 &format,&length,&after,&data);
5356 if ((status != Success) || (type != XA_STRING) || (format == 32) ||
5359 if ((Extent(reply_info.text)+(
int) length) >= (MagickPathExtent-1))
5360 (void) XBell(display,0);
5366 *(data+length)=
'\0';
5367 XEditText(display,&reply_info,(KeySym) XK_Insert,(
char *) data,
5369 XDrawMatteText(display,&windows->widget,&reply_info);
5370 state|=JumpListState;
5371 state|=RedrawActionState;
5373 (void) XFree((
void *) data);
5376 case SelectionRequest:
5381 XSelectionRequestEvent
5384 if (reply_info.highlight == MagickFalse)
5389 request=(&(
event.xselectionrequest));
5390 (void) XChangeProperty(request->display,request->requestor,
5391 request->property,request->target,8,PropModeReplace,
5392 (
unsigned char *) primary_selection,Extent(primary_selection));
5393 notify.type=SelectionNotify;
5394 notify.display=request->display;
5395 notify.requestor=request->requestor;
5396 notify.selection=request->selection;
5397 notify.target=request->target;
5398 notify.time=request->time;
5399 if (request->property == None)
5400 notify.property=request->target;
5402 notify.property=request->property;
5403 (void) XSendEvent(request->display,request->requestor,False,0,
5404 (XEvent *) ¬ify);
5409 }
while ((state & ExitState) == 0);
5410 XSetCursorState(display,windows,MagickFalse);
5411 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
5412 XCheckRefreshWindows(display,windows);
5416 for (i=0; i < (ssize_t) files; i++)
5417 filelist[i]=DestroyString(filelist[i]);
5418 if (filelist != (
char **) NULL)
5419 filelist=(
char **) RelinquishMagickMemory(filelist);
5422 (void) ConcatenateMagickString(working_path,DirectorySeparator,
5424 (void) ConcatenateMagickString(working_path,reply,MagickPathExtent);
5426 (void) CopyMagickString(reply,working_path,MagickPathExtent);
5428 ExpandFilename(reply);
5465#if defined(__cplusplus) || defined(c_plusplus)
5469static int FontCompare(
const void *x,
const void *y)
5475 p=(
char *) *((
char **) x);
5476 q=(
char *) *((
char **) y);
5477 while ((*p !=
'\0') && (*q !=
'\0') && (*p == *q))
5485#if defined(__cplusplus) || defined(c_plusplus)
5489MagickPrivate
void XFontBrowserWidget(Display *display,XWindows *windows,
5490 const char *action,
char *reply)
5492#define BackButtonText "Back"
5493#define CancelButtonText "Cancel"
5494#define FontnameText "Name:"
5495#define FontPatternText "Pattern:"
5496#define ResetButtonText "Reset"
5499 back_pattern[MagickPathExtent],
5502 primary_selection[MagickPathExtent] =
"",
5503 reset_pattern[MagickPathExtent],
5504 text[MagickPathExtent];
5515 glob_pattern[MagickPathExtent] =
"*";
5517 static MagickStatusType
5518 mask = (MagickStatusType) (CWWidth | CWHeight | CWX | CWY);
5564 assert(display != (Display *) NULL);
5565 assert(windows != (XWindows *) NULL);
5566 assert(action != (
char *) NULL);
5567 assert(reply != (
char *) NULL);
5568 if (IsEventLogging() != MagickFalse)
5569 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",action);
5570 XSetCursorState(display,windows,MagickTrue);
5571 XCheckRefreshWindows(display,windows);
5572 (void) CopyMagickString(back_pattern,glob_pattern,MagickPathExtent);
5573 (void) CopyMagickString(reset_pattern,
"*",MagickPathExtent);
5574 fontlist=XListFonts(display,glob_pattern,32767,&fonts);
5580 XNoticeWidget(display,windows,
"Unable to obtain fonts names:",
5582 (void) CopyMagickString(glob_pattern,
"*",MagickPathExtent);
5583 fontlist=XListFonts(display,glob_pattern,32767,&fonts);
5584 if (fontlist == (
char **) NULL)
5586 XNoticeWidget(display,windows,
"Unable to obtain fonts names:",
5595 fontlist=(
char **) AcquireQuantumMemory((
size_t) fonts,
sizeof(*fontlist));
5596 if (fontlist == (
char **) NULL)
5598 XNoticeWidget(display,windows,
"MemoryAllocationFailed",
5599 "UnableToViewFonts");
5602 for (i=0; i < fonts; i++)
5603 fontlist[i]=listhead[i];
5604 qsort((
void *) fontlist,(
size_t) fonts,
sizeof(*fontlist),FontCompare);
5608 font_info=windows->widget.font_info;
5610 for (i=0; i < fonts; i++)
5611 if (WidgetTextWidth(font_info,fontlist[i]) > text_width)
5612 text_width=WidgetTextWidth(font_info,fontlist[i]);
5613 width=WidgetTextWidth(font_info,(
char *) action);
5614 if (WidgetTextWidth(font_info,CancelButtonText) > width)
5615 width=WidgetTextWidth(font_info,CancelButtonText);
5616 if (WidgetTextWidth(font_info,ResetButtonText) > width)
5617 width=WidgetTextWidth(font_info,ResetButtonText);
5618 if (WidgetTextWidth(font_info,BackButtonText) > width)
5619 width=WidgetTextWidth(font_info,BackButtonText);
5620 width+=(
unsigned int) QuantumMargin;
5621 if (WidgetTextWidth(font_info,FontPatternText) > width)
5622 width=WidgetTextWidth(font_info,FontPatternText);
5623 if (WidgetTextWidth(font_info,FontnameText) > width)
5624 width=WidgetTextWidth(font_info,FontnameText);
5625 height=(
unsigned int) (font_info->ascent+font_info->descent);
5629 windows->widget.width=width+MagickMin(text_width,MaxTextWidth)+(
unsigned int)
5631 windows->widget.min_width=width+MinTextWidth+(
unsigned int) (4*QuantumMargin);
5632 if (windows->widget.width < windows->widget.min_width)
5633 windows->widget.width=windows->widget.min_width;
5634 windows->widget.height=(
unsigned int)
5635 (((85*(
int) height) >> 2)+((13*QuantumMargin) >> 1)+4);
5636 windows->widget.min_height=(
unsigned int)
5637 (((27*(
int) height) >> 1)+((13*QuantumMargin) >> 1)+4);
5638 if (windows->widget.height < windows->widget.min_height)
5639 windows->widget.height=windows->widget.min_height;
5640 XConstrainWindowPosition(display,&windows->widget);
5644 (void) CopyMagickString(windows->widget.name,
"Browse and Select a Font",
5646 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
5647 if (status != False)
5649 XSetWMName(display,windows->widget.id,&window_name);
5650 XSetWMIconName(display,windows->widget.id,&window_name);
5651 (void) XFree((
void *) window_name.value);
5653 window_changes.width=(int) windows->widget.width;
5654 window_changes.height=(int) windows->widget.height;
5655 window_changes.x=windows->widget.x;
5656 window_changes.y=windows->widget.y;
5657 (void) XReconfigureWMWindow(display,windows->widget.id,
5658 windows->widget.screen,mask,&window_changes);
5659 (void) XMapRaised(display,windows->widget.id);
5660 windows->widget.mapped=MagickFalse;
5664 XGetWidgetInfo((
char *) NULL,&slider_info);
5665 XGetWidgetInfo((
char *) NULL,&north_info);
5666 XGetWidgetInfo((
char *) NULL,&south_info);
5667 XGetWidgetInfo((
char *) NULL,&expose_info);
5668 XGetWidgetInfo((
char *) NULL,&selection_info);
5670 delay=SuspendTime << 2;
5671 state=UpdateConfigurationState;
5674 if (state & UpdateConfigurationState)
5682 XGetWidgetInfo(CancelButtonText,&cancel_info);
5683 cancel_info.width=width;
5684 cancel_info.height=(
unsigned int) ((3*height) >> 1);
5685 cancel_info.x=(int) windows->widget.width-(
int) cancel_info.width-
5687 cancel_info.y=(int) windows->widget.height-(
int) cancel_info.height-
5689 XGetWidgetInfo(action,&action_info);
5690 action_info.width=width;
5691 action_info.height=(
unsigned int) ((3*height) >> 1);
5692 action_info.x=(int) windows->widget.width-(
int) action_info.width-
5693 (int) cancel_info.width-2*QuantumMargin-2;
5694 action_info.y=cancel_info.y;
5695 XGetWidgetInfo(BackButtonText,&back_info);
5696 back_info.width=width;
5697 back_info.height=(
unsigned int) ((3*height) >> 1);
5698 back_info.x=QuantumMargin;
5699 back_info.y=((5*QuantumMargin) >> 1)+(
int) height;
5700 XGetWidgetInfo(ResetButtonText,&reset_info);
5701 reset_info.width=width;
5702 reset_info.height=(
unsigned int) ((3*height) >> 1);
5703 reset_info.x=QuantumMargin;
5704 reset_info.y=back_info.y+(int) back_info.height+QuantumMargin;
5708 XGetWidgetInfo(reply,&reply_info);
5709 reply_info.raised=MagickFalse;
5710 reply_info.bevel_width--;
5711 reply_info.width=(
unsigned int) ((
int) windows->widget.width-(
int)
5712 width-((6*QuantumMargin) >> 1));
5713 reply_info.height=height << 1;
5714 reply_info.x=(int) width+(QuantumMargin << 1);
5715 reply_info.y=action_info.y-(int) (action_info.height << 1)-
5720 XGetWidgetInfo(reply,&mode_info);
5721 mode_info.bevel_width=0;
5722 mode_info.width=(
unsigned int)
5723 (action_info.x-reply_info.x-QuantumMargin);
5724 mode_info.height=action_info.height << 1;
5725 mode_info.x=reply_info.x;
5726 mode_info.y=action_info.y-(int) action_info.height+(
int)
5727 action_info.bevel_width;
5731 XGetWidgetInfo((
char *) NULL,&scroll_info);
5732 scroll_info.bevel_width--;
5733 scroll_info.width=height;
5734 scroll_info.height=(
unsigned int)
5735 (reply_info.y-back_info.y-(
int) (QuantumMargin >> 1));
5736 scroll_info.x=reply_info.x+(int) (reply_info.width-scroll_info.width);
5737 scroll_info.y=back_info.y-(int) reply_info.bevel_width;
5738 scroll_info.raised=MagickFalse;
5739 scroll_info.trough=MagickTrue;
5740 north_info=scroll_info;
5741 north_info.raised=MagickTrue;
5742 north_info.width-=(north_info.bevel_width << 1);
5743 north_info.height=north_info.width-1;
5744 north_info.x+=(int) north_info.bevel_width;
5745 north_info.y+=(int) north_info.bevel_width;
5746 south_info=north_info;
5747 south_info.y=scroll_info.y+(int) scroll_info.height-(
int)
5748 scroll_info.bevel_width-(int) south_info.height;
5750 slider_info=north_info;
5752 slider_info.width-=2;
5753 slider_info.min_y=north_info.y+(int) north_info.height+(
int)
5754 north_info.bevel_width+(int) slider_info.bevel_width+2;
5755 slider_info.height=(
unsigned int) ((
int) scroll_info.height-
5756 ((slider_info.min_y-scroll_info.y+1) << 1)+4);
5757 visible_fonts=(
unsigned int) (scroll_info.height*
5758 PerceptibleReciprocal((
double) height+(height >> 3)));
5759 if (fonts > (
int) visible_fonts)
5760 slider_info.height=(visible_fonts*slider_info.height)/(
unsigned int)
5762 slider_info.max_y=south_info.y-(int) south_info.bevel_width-
5763 (
int) slider_info.bevel_width-2;
5764 slider_info.x=scroll_info.x+(int) slider_info.bevel_width+1;
5765 slider_info.y=slider_info.min_y;
5766 expose_info=scroll_info;
5767 expose_info.y=slider_info.y;
5771 XGetWidgetInfo((
char *) NULL,&list_info);
5772 list_info.raised=MagickFalse;
5773 list_info.bevel_width--;
5774 list_info.width=(
unsigned int) (scroll_info.x-reply_info.x-
5775 (QuantumMargin >> 1));
5776 list_info.height=scroll_info.height;
5777 list_info.x=reply_info.x;
5778 list_info.y=scroll_info.y;
5779 if (windows->widget.mapped == MagickFalse)
5780 state|=JumpListState;
5785 XGetWidgetInfo(text,&text_info);
5786 text_info.center=MagickFalse;
5787 text_info.width=reply_info.width;
5788 text_info.height=height;
5789 text_info.x=list_info.x-(QuantumMargin >> 1);
5790 text_info.y=QuantumMargin;
5794 XGetWidgetInfo((
char *) NULL,&selection_info);
5795 selection_info.center=MagickFalse;
5796 selection_info.width=list_info.width;
5797 selection_info.height=(
unsigned int) ((9*height) >> 3);
5798 selection_info.x=list_info.x;
5799 state&=(
unsigned int) (~UpdateConfigurationState);
5801 if (state & RedrawWidgetState)
5807 y=text_info.y+(int) ((text_info.height-height) >> 1)+font_info->ascent;
5808 (void) XDrawString(display,windows->widget.id,
5809 windows->widget.annotate_context,x,y,FontPatternText,
5810 Extent(FontPatternText));
5811 (void) CopyMagickString(text_info.text,glob_pattern,MagickPathExtent);
5812 XDrawWidgetText(display,&windows->widget,&text_info);
5813 XDrawBeveledButton(display,&windows->widget,&back_info);
5814 XDrawBeveledButton(display,&windows->widget,&reset_info);
5815 XDrawBeveledMatte(display,&windows->widget,&list_info);
5816 XDrawBeveledMatte(display,&windows->widget,&scroll_info);
5817 XDrawTriangleNorth(display,&windows->widget,&north_info);
5818 XDrawBeveledButton(display,&windows->widget,&slider_info);
5819 XDrawTriangleSouth(display,&windows->widget,&south_info);
5821 y=reply_info.y+(int) ((reply_info.height-height) >> 1)+
5823 (void) XDrawString(display,windows->widget.id,
5824 windows->widget.annotate_context,x,y,FontnameText,
5825 Extent(FontnameText));
5826 XDrawBeveledMatte(display,&windows->widget,&reply_info);
5827 XDrawMatteText(display,&windows->widget,&reply_info);
5828 XDrawBeveledButton(display,&windows->widget,&action_info);
5829 XDrawBeveledButton(display,&windows->widget,&cancel_info);
5830 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
5831 selection_info.id=(~0);
5832 state|=RedrawActionState;
5833 state|=RedrawListState;
5834 state&=(
unsigned int) (~RedrawWidgetState);
5836 if (state & UpdateListState)
5847 checklist=XListFonts(display,glob_pattern,32767,&number_fonts);
5848 if (checklist == (
char **) NULL)
5850 if ((strchr(glob_pattern,
'*') == (
char *) NULL) &&
5851 (strchr(glob_pattern,
'?') == (
char *) NULL))
5856 (void) CopyMagickString(reply,glob_pattern,MagickPathExtent);
5857 (void) CopyMagickString(glob_pattern,back_pattern,MagickPathExtent);
5858 action_info.raised=MagickFalse;
5859 XDrawBeveledButton(display,&windows->widget,&action_info);
5862 (void) CopyMagickString(glob_pattern,back_pattern,MagickPathExtent);
5863 (void) XBell(display,0);
5866 if (number_fonts == 1)
5871 (void) CopyMagickString(reply,checklist[0],MagickPathExtent);
5872 (void) CopyMagickString(glob_pattern,back_pattern,MagickPathExtent);
5873 (void) XFreeFontNames(checklist);
5874 action_info.raised=MagickFalse;
5875 XDrawBeveledButton(display,&windows->widget,&action_info);
5880 (void) XFreeFontNames(listhead);
5881 fontlist=(
char **) RelinquishMagickMemory(fontlist);
5889 fontlist=(
char **) AcquireQuantumMemory((
size_t) fonts,
5891 if (fontlist == (
char **) NULL)
5893 XNoticeWidget(display,windows,
"MemoryAllocationFailed",
5894 "UnableToViewFonts");
5897 for (i=0; i < fonts; i++)
5898 fontlist[i]=listhead[i];
5899 qsort((
void *) fontlist,(
size_t) fonts,
sizeof(*fontlist),FontCompare);
5900 slider_info.height=(
unsigned int) ((
int) scroll_info.height-
5901 ((slider_info.min_y-scroll_info.y+1) << 1)+1);
5902 if (fonts > (
int) visible_fonts)
5903 slider_info.height=(visible_fonts*slider_info.height)/(
unsigned int)
5905 slider_info.max_y=south_info.y-(int) south_info.bevel_width-(
int)
5906 slider_info.bevel_width-2;
5908 slider_info.y=slider_info.min_y;
5909 expose_info.y=slider_info.y;
5910 selection_info.id=(~0);
5912 state|=RedrawListState;
5916 *reply_info.text=
'\0';
5917 reply_info.cursor=reply_info.text;
5918 (void) CopyMagickString(text_info.text,glob_pattern,MagickPathExtent);
5919 XDrawWidgetText(display,&windows->widget,&text_info);
5920 XDrawMatteText(display,&windows->widget,&reply_info);
5921 XDrawBeveledMatte(display,&windows->widget,&scroll_info);
5922 XDrawTriangleNorth(display,&windows->widget,&north_info);
5923 XDrawBeveledButton(display,&windows->widget,&slider_info);
5924 XDrawTriangleSouth(display,&windows->widget,&south_info);
5925 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
5926 state&=(
unsigned int) (~UpdateListState);
5928 if (state & JumpListState)
5934 for (i=0; i < fonts; i++)
5935 if (LocaleCompare(fontlist[i],reply) >= 0)
5937 list_info.id=LocaleCompare(fontlist[i],reply) == 0 ? i : ~0;
5940 if ((i < slider_info.id) || (i >= (slider_info.id+(
int) visible_fonts)))
5941 slider_info.id=i-((int) visible_fonts >> 1);
5942 selection_info.id=(~0);
5943 state|=RedrawListState;
5944 state&=(
unsigned int) (~JumpListState);
5946 if (state & RedrawListState)
5951 if (slider_info.id >= (fonts-(
int) visible_fonts))
5952 slider_info.id=fonts-(int) visible_fonts;
5953 if ((slider_info.id < 0) || (fonts <= (
int) visible_fonts))
5955 slider_info.y=slider_info.min_y;
5958 slider_info.id*(slider_info.max_y-slider_info.min_y+1)/fonts;
5959 if (slider_info.id != selection_info.id)
5964 selection_info.id=slider_info.id;
5965 selection_info.y=list_info.y+(int) (height >> 3)+2;
5966 for (i=0; i < (int) visible_fonts; i++)
5968 selection_info.raised=(slider_info.id+i) != list_info.id ?
5969 MagickTrue : MagickFalse;
5970 selection_info.text=(
char *) NULL;
5971 if ((slider_info.id+i) < fonts)
5972 selection_info.text=fontlist[slider_info.id+i];
5973 XDrawWidgetText(display,&windows->widget,&selection_info);
5974 selection_info.y+=(int) selection_info.height;
5979 if (slider_info.y > expose_info.y)
5981 expose_info.height=(
unsigned int) (slider_info.y-expose_info.y);
5982 expose_info.y=slider_info.y-(int) expose_info.height-(
int)
5983 slider_info.bevel_width-1;
5987 expose_info.height=(
unsigned int) (expose_info.y-slider_info.y);
5988 expose_info.y=slider_info.y+(int) slider_info.height+(
int)
5989 slider_info.bevel_width+1;
5991 XDrawTriangleNorth(display,&windows->widget,&north_info);
5992 XDrawMatte(display,&windows->widget,&expose_info);
5993 XDrawBeveledButton(display,&windows->widget,&slider_info);
5994 XDrawTriangleSouth(display,&windows->widget,&south_info);
5995 expose_info.y=slider_info.y;
5997 state&=(
unsigned int) (~RedrawListState);
5999 if (state & RedrawActionState)
6007 save_info=windows->widget.font_info;
6008 font_info=XLoadQueryFont(display,reply_info.text);
6009 if (font_info != (XFontStruct *) NULL)
6011 windows->widget.font_info=font_info;
6012 (void) XSetFont(display,windows->widget.widget_context,
6015 XDrawBeveledButton(display,&windows->widget,&mode_info);
6016 windows->widget.font_info=save_info;
6017 if (font_info != (XFontStruct *) NULL)
6019 (void) XSetFont(display,windows->widget.widget_context,
6020 windows->widget.font_info->fid);
6021 (void) XFreeFont(display,font_info);
6023 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
6024 XDrawMatteText(display,&windows->widget,&reply_info);
6025 state&=(
unsigned int) (~RedrawActionState);
6030 if (north_info.raised && south_info.raised)
6031 (void) XIfEvent(display,&event,XScreenEvent,(
char *) windows);
6037 XDelay(display,delay);
6039 (void) XCheckIfEvent(display,&event,XScreenEvent,(
char *) windows);
6040 if (north_info.raised == MagickFalse)
6041 if (slider_info.id > 0)
6047 state|=RedrawListState;
6049 if (south_info.raised == MagickFalse)
6050 if (slider_info.id < fonts)
6056 state|=RedrawListState;
6058 if (event.type != ButtonRelease)
6065 if (MatteIsActive(slider_info,event.xbutton))
6070 slider_info.active=MagickTrue;
6073 if (MatteIsActive(north_info,event.xbutton))
6074 if (slider_info.id > 0)
6079 north_info.raised=MagickFalse;
6081 state|=RedrawListState;
6084 if (MatteIsActive(south_info,event.xbutton))
6085 if (slider_info.id < fonts)
6090 south_info.raised=MagickFalse;
6092 state|=RedrawListState;
6095 if (MatteIsActive(scroll_info,event.xbutton))
6100 if (event.xbutton.y < slider_info.y)
6101 slider_info.id-=((int) visible_fonts-1);
6103 slider_info.id+=((int) visible_fonts-1);
6104 state|=RedrawListState;
6107 if (MatteIsActive(list_info,event.xbutton))
6115 id=slider_info.id+(
event.xbutton.y-(list_info.y+(int)
6116 (height >> 1))+1)/(
int) selection_info.height;
6117 if (
id >= (
int) fonts)
6119 (void) CopyMagickString(reply_info.text,fontlist[
id],MagickPathExtent);
6120 reply_info.highlight=MagickFalse;
6121 reply_info.marker=reply_info.text;
6122 reply_info.cursor=reply_info.text+Extent(reply_info.text);
6123 XDrawMatteText(display,&windows->widget,&reply_info);
6124 state|=RedrawActionState;
6125 if (
id == list_info.id)
6127 (void) CopyMagickString(glob_pattern,reply_info.text,
6129 state|=UpdateListState;
6131 selection_info.id=(~0);
6133 state|=RedrawListState;
6136 if (MatteIsActive(back_info,event.xbutton))
6141 back_info.raised=MagickFalse;
6142 XDrawBeveledButton(display,&windows->widget,&back_info);
6145 if (MatteIsActive(reset_info,event.xbutton))
6150 reset_info.raised=MagickFalse;
6151 XDrawBeveledButton(display,&windows->widget,&reset_info);
6154 if (MatteIsActive(action_info,event.xbutton))
6159 action_info.raised=MagickFalse;
6160 XDrawBeveledButton(display,&windows->widget,&action_info);
6163 if (MatteIsActive(cancel_info,event.xbutton))
6168 cancel_info.raised=MagickFalse;
6169 XDrawBeveledButton(display,&windows->widget,&cancel_info);
6172 if (MatteIsActive(reply_info,event.xbutton) == MagickFalse)
6174 if (event.xbutton.button != Button2)
6182 x=
event.xbutton.x-reply_info.x-(int) (QuantumMargin >> 2);
6183 if (font_info != (XFontStruct *) NULL)
6184 for (i=1; i <= Extent(reply_info.marker); i++)
6185 if (XTextWidth(font_info,reply_info.marker,i) > x)
6187 reply_info.cursor=reply_info.marker+i-1;
6188 if (event.xbutton.time > (click_time+(
unsigned long) DoubleClick))
6189 reply_info.highlight=MagickFalse;
6195 (void) CopyMagickString(primary_selection,reply_info.text,
6197 (void) XSetSelectionOwner(display,XA_PRIMARY,windows->widget.id,
6198 event.xbutton.time);
6199 reply_info.highlight=XGetSelectionOwner(display,XA_PRIMARY) ==
6200 windows->widget.id ? MagickTrue : MagickFalse;
6202 XDrawMatteText(display,&windows->widget,&reply_info);
6203 click_time=
event.xbutton.time;
6209 (void) XConvertSelection(display,XA_PRIMARY,XA_STRING,XA_STRING,
6210 windows->widget.id,event.xbutton.time);
6215 if (windows->widget.mapped == MagickFalse)
6217 if (north_info.raised == MagickFalse)
6222 delay=SuspendTime << 2;
6223 north_info.raised=MagickTrue;
6224 XDrawTriangleNorth(display,&windows->widget,&north_info);
6226 if (south_info.raised == MagickFalse)
6231 delay=SuspendTime << 2;
6232 south_info.raised=MagickTrue;
6233 XDrawTriangleSouth(display,&windows->widget,&south_info);
6235 if (slider_info.active)
6240 slider_info.active=MagickFalse;
6243 if (back_info.raised == MagickFalse)
6245 if (event.xbutton.window == windows->widget.id)
6246 if (MatteIsActive(back_info,event.xbutton))
6248 (void) CopyMagickString(glob_pattern,back_pattern,
6250 state|=UpdateListState;
6252 back_info.raised=MagickTrue;
6253 XDrawBeveledButton(display,&windows->widget,&back_info);
6255 if (reset_info.raised == MagickFalse)
6257 if (event.xbutton.window == windows->widget.id)
6258 if (MatteIsActive(reset_info,event.xbutton))
6260 (void) CopyMagickString(back_pattern,glob_pattern,MagickPathExtent);
6261 (void) CopyMagickString(glob_pattern,reset_pattern,MagickPathExtent);
6262 state|=UpdateListState;
6264 reset_info.raised=MagickTrue;
6265 XDrawBeveledButton(display,&windows->widget,&reset_info);
6267 if (action_info.raised == MagickFalse)
6269 if (event.xbutton.window == windows->widget.id)
6271 if (MatteIsActive(action_info,event.xbutton))
6273 if (*reply_info.text ==
'\0')
6274 (void) XBell(display,0);
6279 action_info.raised=MagickTrue;
6280 XDrawBeveledButton(display,&windows->widget,&action_info);
6282 if (cancel_info.raised == MagickFalse)
6284 if (event.xbutton.window == windows->widget.id)
6285 if (MatteIsActive(cancel_info,event.xbutton))
6287 *reply_info.text=
'\0';
6290 cancel_info.raised=MagickTrue;
6291 XDrawBeveledButton(display,&windows->widget,&cancel_info);
6300 if (event.xclient.message_type != windows->wm_protocols)
6302 if (*event.xclient.data.l == (
int) windows->wm_take_focus)
6304 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
6305 (Time) event.xclient.data.l[1]);
6308 if (*event.xclient.data.l != (
int) windows->wm_delete_window)
6310 if (event.xclient.window == windows->widget.id)
6312 *reply_info.text=
'\0';
6318 case ConfigureNotify:
6323 if (event.xconfigure.window != windows->widget.id)
6325 if ((event.xconfigure.width == (
int) windows->widget.width) &&
6326 (event.xconfigure.height == (
int) windows->widget.height))
6328 windows->widget.width=(
unsigned int)
6329 MagickMax(event.xconfigure.width,(
int) windows->widget.min_width);
6330 windows->widget.height=(
unsigned int)
6331 MagickMax(event.xconfigure.height,(
int) windows->widget.min_height);
6332 state|=UpdateConfigurationState;
6337 if (event.xcrossing.window != windows->widget.id)
6339 state&=(
unsigned int) (~InactiveWidgetState);
6344 if (event.xexpose.window != windows->widget.id)
6346 if (event.xexpose.count != 0)
6348 state|=RedrawWidgetState;
6354 command[MagickPathExtent];
6365 if (event.xkey.window != windows->widget.id)
6367 length=XLookupString((XKeyEvent *) &event.xkey,command,
6368 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
6369 *(command+length)=
'\0';
6370 if (AreaIsActive(scroll_info,event.xkey))
6375 switch ((
int) key_symbol)
6398 slider_info.id-=(int) visible_fonts;
6404 slider_info.id+=(int) visible_fonts;
6410 slider_info.id=fonts;
6414 state|=RedrawListState;
6417 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
6422 if (*reply_info.text ==
'\0')
6424 (void) CopyMagickString(back_pattern,glob_pattern,MagickPathExtent);
6425 (void) CopyMagickString(glob_pattern,reply_info.text,MagickPathExtent);
6426 state|=UpdateListState;
6429 if (key_symbol == XK_Control_L)
6431 state|=ControlState;
6434 if (state & ControlState)
6435 switch ((
int) key_symbol)
6443 *reply_info.text=
'\0';
6444 reply_info.cursor=reply_info.text;
6445 reply_info.marker=reply_info.text;
6446 reply_info.highlight=MagickFalse;
6452 XEditText(display,&reply_info,key_symbol,command,state);
6453 XDrawMatteText(display,&windows->widget,&reply_info);
6454 state|=JumpListState;
6460 command[MagickPathExtent];
6468 if (event.xkey.window != windows->widget.id)
6470 (void) XLookupString((XKeyEvent *) &event.xkey,command,
6471 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
6472 if (key_symbol == XK_Control_L)
6473 state&=(
unsigned int) (~ControlState);
6478 if (event.xcrossing.window != windows->widget.id)
6480 state|=InactiveWidgetState;
6485 mask&=(
unsigned int) (~CWX);
6486 mask&=(
unsigned int) (~CWY);
6494 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
6495 if (slider_info.active)
6500 slider_info.y=
event.xmotion.y-(int)
6501 ((slider_info.height+slider_info.bevel_width) >> 1)+1;
6502 if (slider_info.y < slider_info.min_y)
6503 slider_info.y=slider_info.min_y;
6504 if (slider_info.y > slider_info.max_y)
6505 slider_info.y=slider_info.max_y;
6507 if (slider_info.y != slider_info.min_y)
6508 slider_info.id=(fonts*(slider_info.y-slider_info.min_y+1))/
6509 (slider_info.max_y-slider_info.min_y+1);
6510 state|=RedrawListState;
6513 if (state & InactiveWidgetState)
6515 if (back_info.raised == MatteIsActive(back_info,event.xmotion))
6520 back_info.raised=!back_info.raised;
6521 XDrawBeveledButton(display,&windows->widget,&back_info);
6524 if (reset_info.raised == MatteIsActive(reset_info,event.xmotion))
6529 reset_info.raised=!reset_info.raised;
6530 XDrawBeveledButton(display,&windows->widget,&reset_info);
6533 if (action_info.raised == MatteIsActive(action_info,event.xmotion))
6538 action_info.raised=action_info.raised == MagickFalse ?
6539 MagickTrue : MagickFalse;
6540 XDrawBeveledButton(display,&windows->widget,&action_info);
6543 if (cancel_info.raised == MatteIsActive(cancel_info,event.xmotion))
6548 cancel_info.raised=cancel_info.raised == MagickFalse ?
6549 MagickTrue : MagickFalse;
6550 XDrawBeveledButton(display,&windows->widget,&cancel_info);
6555 case SelectionClear:
6557 reply_info.highlight=MagickFalse;
6558 XDrawMatteText(display,&windows->widget,&reply_info);
6561 case SelectionNotify:
6579 if (event.xselection.property == (Atom) None)
6581 status=XGetWindowProperty(display,event.xselection.requestor,
6582 event.xselection.property,0L,2047L,MagickTrue,XA_STRING,&type,
6583 &format,&length,&after,&data);
6584 if ((status != Success) || (type != XA_STRING) || (format == 32) ||
6587 if ((Extent(reply_info.text)+(
int) length) >= (MagickPathExtent-1))
6588 (void) XBell(display,0);
6594 *(data+length)=
'\0';
6595 XEditText(display,&reply_info,(KeySym) XK_Insert,(
char *) data,
6597 XDrawMatteText(display,&windows->widget,&reply_info);
6598 state|=JumpListState;
6599 state|=RedrawActionState;
6601 (void) XFree((
void *) data);
6604 case SelectionRequest:
6609 XSelectionRequestEvent
6615 request=(&(
event.xselectionrequest));
6616 (void) XChangeProperty(request->display,request->requestor,
6617 request->property,request->target,8,PropModeReplace,
6618 (
unsigned char *) primary_selection,Extent(primary_selection));
6619 notify.type=SelectionNotify;
6620 notify.display=request->display;
6621 notify.requestor=request->requestor;
6622 notify.selection=request->selection;
6623 notify.target=request->target;
6624 notify.time=request->time;
6625 if (request->property == None)
6626 notify.property=request->target;
6628 notify.property=request->property;
6629 (void) XSendEvent(request->display,request->requestor,False,0,
6630 (XEvent *) ¬ify);
6635 }
while ((state & ExitState) == 0);
6636 XSetCursorState(display,windows,MagickFalse);
6637 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
6638 XCheckRefreshWindows(display,windows);
6642 (void) XFreeFontNames(listhead);
6643 fontlist=(
char **) RelinquishMagickMemory(fontlist);
6676MagickPrivate
void XInfoWidget(Display *display,XWindows *windows,
6677 const char *activity)
6693 if (IsEventLogging() != MagickFalse)
6694 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
6695 assert(display != (Display *) NULL);
6696 assert(windows != (XWindows *) NULL);
6697 assert(activity != (
char *) NULL);
6698 font_info=windows->info.font_info;
6699 width=WidgetTextWidth(font_info,(
char *) activity)+(
unsigned int)
6700 ((3*QuantumMargin) >> 1)+4;
6701 height=(
unsigned int) (((6*(font_info->ascent+font_info->descent)) >> 2)+4);
6702 if ((windows->info.width != width) || (windows->info.height != height))
6707 windows->info.width=width;
6708 windows->info.height=height;
6709 window_changes.width=(int) width;
6710 window_changes.height=(int) height;
6711 (void) XReconfigureWMWindow(display,windows->info.id,windows->info.screen,
6712 (
unsigned int) (CWWidth | CWHeight),&window_changes);
6714 if (windows->info.mapped == MagickFalse)
6716 (void) XMapRaised(display,windows->info.id);
6717 windows->info.mapped=MagickTrue;
6722 height=(
unsigned int) (font_info->ascent+font_info->descent);
6723 XGetWidgetInfo(activity,&monitor_info);
6724 monitor_info.bevel_width--;
6725 margin=monitor_info.bevel_width+((windows->info.height-height) >> 1)-2;
6726 monitor_info.center=MagickFalse;
6727 monitor_info.x=(int) margin;
6728 monitor_info.y=(int) margin;
6729 monitor_info.width=windows->info.width-(margin << 1);
6730 monitor_info.height=windows->info.height-(margin << 1)+1;
6734 monitor_info.raised=MagickFalse;
6735 XDrawBeveledMatte(display,&windows->info,&monitor_info);
6736 monitor_info.raised=MagickTrue;
6737 XDrawWidgetText(display,&windows->info,&monitor_info);
6779MagickPrivate
void XListBrowserWidget(Display *display,XWindows *windows,
6780 XWindowInfo *window_info,
const char *
const *list,
const char *action,
6781 const char *query,
char *reply)
6783#define CancelButtonText "Cancel"
6786 primary_selection[MagickPathExtent];
6794 static MagickStatusType
6795 mask = (MagickStatusType) (CWWidth | CWHeight | CWX | CWY);
6839 assert(display != (Display *) NULL);
6840 assert(windows != (XWindows *) NULL);
6841 assert(window_info != (XWindowInfo *) NULL);
6842 assert(list != (
const char **) NULL);
6843 assert(action != (
char *) NULL);
6844 assert(query != (
char *) NULL);
6845 assert(reply != (
char *) NULL);
6846 if (IsEventLogging() != MagickFalse)
6847 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",action);
6848 XSetCursorState(display,windows,MagickTrue);
6849 XCheckRefreshWindows(display,windows);
6850 if (list == (
const char **) NULL)
6852 XNoticeWidget(display,windows,
"No text to browse:",(
char *) NULL);
6855 for (entries=0; ; entries++)
6856 if (list[entries] == (
char *) NULL)
6861 font_info=window_info->font_info;
6862 text_width=WidgetTextWidth(font_info,(
char *) query);
6863 for (i=0; i < (int) entries; i++)
6864 if (WidgetTextWidth(font_info,(
char *) list[i]) > text_width)
6865 text_width=WidgetTextWidth(font_info,(
char *) list[i]);
6866 width=WidgetTextWidth(font_info,(
char *) action);
6867 if (WidgetTextWidth(font_info,CancelButtonText) > width)
6868 width=WidgetTextWidth(font_info,CancelButtonText);
6869 width+=(
unsigned int) QuantumMargin;
6870 height=(
unsigned int) (font_info->ascent+font_info->descent);
6874 window_info->width=MagickMin(text_width,MaxTextWidth)+(
unsigned int)
6875 ((9*QuantumMargin) >> 1);
6876 window_info->min_width=(MinTextWidth+4*(
unsigned int) QuantumMargin);
6877 if (window_info->width < window_info->min_width)
6878 window_info->width=window_info->min_width;
6879 window_info->height=(((81*height) >> 2)+(
unsigned int)
6880 ((13*QuantumMargin) >> 1)+4);
6881 window_info->min_height=(((23*height) >> 1)+(
unsigned int)
6882 ((13*QuantumMargin) >> 1)+4);
6883 if (window_info->height < window_info->min_height)
6884 window_info->height=window_info->min_height;
6885 XConstrainWindowPosition(display,window_info);
6889 (void) CopyMagickString(window_info->name,
"Browse",MagickPathExtent);
6890 status=XStringListToTextProperty(&window_info->name,1,&window_name);
6891 if (status != False)
6893 XSetWMName(display,window_info->id,&window_name);
6894 XSetWMIconName(display,windows->widget.id,&window_name);
6895 (void) XFree((
void *) window_name.value);
6897 window_changes.width=(int) window_info->width;
6898 window_changes.height=(int) window_info->height;
6899 window_changes.x=window_info->x;
6900 window_changes.y=window_info->y;
6901 (void) XReconfigureWMWindow(display,window_info->id,window_info->screen,mask,
6903 (void) XMapRaised(display,window_info->id);
6904 window_info->mapped=MagickFalse;
6908 XGetWidgetInfo((
char *) NULL,&slider_info);
6909 XGetWidgetInfo((
char *) NULL,&north_info);
6910 XGetWidgetInfo((
char *) NULL,&south_info);
6911 XGetWidgetInfo((
char *) NULL,&expose_info);
6912 XGetWidgetInfo((
char *) NULL,&selection_info);
6914 delay=SuspendTime << 2;
6915 state=UpdateConfigurationState;
6918 if (state & UpdateConfigurationState)
6926 XGetWidgetInfo(CancelButtonText,&cancel_info);
6927 cancel_info.width=width;
6928 cancel_info.height=(
unsigned int) ((3*height) >> 1);
6929 cancel_info.x=(int) window_info->width-(
int) cancel_info.width-
6931 cancel_info.y=(int) window_info->height-(
int) cancel_info.height-
6933 XGetWidgetInfo(action,&action_info);
6934 action_info.width=width;
6935 action_info.height=(
unsigned int) ((3*height) >> 1);
6936 action_info.x=cancel_info.x-((int) cancel_info.width+
6937 (QuantumMargin >> 1)+(int) (action_info.bevel_width << 1));
6938 action_info.y=cancel_info.y;
6942 XGetWidgetInfo(reply,&reply_info);
6943 reply_info.raised=MagickFalse;
6944 reply_info.bevel_width--;
6945 reply_info.width=(
unsigned int) ((
int) window_info->width-
6946 (((4*QuantumMargin) >> 1)));
6947 reply_info.height=height << 1;
6948 reply_info.x=QuantumMargin;
6949 reply_info.y=action_info.y-(int) reply_info.height-QuantumMargin;
6953 XGetWidgetInfo((
char *) NULL,&scroll_info);
6954 scroll_info.bevel_width--;
6955 scroll_info.width=height;
6956 scroll_info.height=(
unsigned int)
6957 (reply_info.y-((6*QuantumMargin) >> 1)-(
int) height);
6958 scroll_info.x=reply_info.x+(int) (reply_info.width-scroll_info.width);
6959 scroll_info.y=((5*QuantumMargin) >> 1)+(
int) height-(int)
6960 reply_info.bevel_width;
6961 scroll_info.raised=MagickFalse;
6962 scroll_info.trough=MagickTrue;
6963 north_info=scroll_info;
6964 north_info.raised=MagickTrue;
6965 north_info.width-=(north_info.bevel_width << 1);
6966 north_info.height=north_info.width-1;
6967 north_info.x+=(int) north_info.bevel_width;
6968 north_info.y+=(int) north_info.bevel_width;
6969 south_info=north_info;
6970 south_info.y=scroll_info.y+(int) scroll_info.height-(
int)
6971 scroll_info.bevel_width-(int) south_info.height;
6973 slider_info=north_info;
6975 slider_info.width-=2;
6976 slider_info.min_y=north_info.y+(int) north_info.height+(
int)
6977 north_info.bevel_width+(int) slider_info.bevel_width+2;
6978 slider_info.height=(
unsigned int) ((
int) scroll_info.height-
6979 ((slider_info.min_y-scroll_info.y+1) << 1)+4);
6980 visible_entries=(
unsigned int) (scroll_info.height*
6981 PerceptibleReciprocal((
double) height+(height >> 3)));
6982 if (entries > visible_entries)
6983 slider_info.height=(visible_entries*slider_info.height)/entries;
6984 slider_info.max_y=south_info.y-(int) south_info.bevel_width-(
int)
6985 slider_info.bevel_width-2;
6986 slider_info.x=scroll_info.x+(int) slider_info.bevel_width+1;
6987 slider_info.y=slider_info.min_y;
6988 expose_info=scroll_info;
6989 expose_info.y=slider_info.y;
6993 XGetWidgetInfo((
char *) NULL,&list_info);
6994 list_info.raised=MagickFalse;
6995 list_info.bevel_width--;
6996 list_info.width=(
unsigned int)
6997 (scroll_info.x-reply_info.x-(
int) (QuantumMargin >> 1));
6998 list_info.height=scroll_info.height;
6999 list_info.x=reply_info.x;
7000 list_info.y=scroll_info.y;
7001 if (window_info->mapped == MagickFalse)
7002 for (i=0; i < (int) entries; i++)
7003 if (LocaleCompare(list[i],reply) == 0)
7006 slider_info.id=i-(int) (visible_entries >> 1);
7007 if (slider_info.id < 0)
7013 XGetWidgetInfo(query,&text_info);
7014 text_info.width=reply_info.width;
7015 text_info.height=height;
7016 text_info.x=list_info.x-(int) (QuantumMargin >> 1);
7017 text_info.y=QuantumMargin;
7021 XGetWidgetInfo((
char *) NULL,&selection_info);
7022 selection_info.center=MagickFalse;
7023 selection_info.width=list_info.width;
7024 selection_info.height=(
unsigned int) ((9*height) >> 3);
7025 selection_info.x=list_info.x;
7026 state&=(
unsigned int) (~UpdateConfigurationState);
7028 if (state & RedrawWidgetState)
7033 XDrawWidgetText(display,window_info,&text_info);
7034 XDrawBeveledMatte(display,window_info,&list_info);
7035 XDrawBeveledMatte(display,window_info,&scroll_info);
7036 XDrawTriangleNorth(display,window_info,&north_info);
7037 XDrawBeveledButton(display,window_info,&slider_info);
7038 XDrawTriangleSouth(display,window_info,&south_info);
7039 XDrawBeveledMatte(display,window_info,&reply_info);
7040 XDrawMatteText(display,window_info,&reply_info);
7041 XDrawBeveledButton(display,window_info,&action_info);
7042 XDrawBeveledButton(display,window_info,&cancel_info);
7043 XHighlightWidget(display,window_info,BorderOffset,BorderOffset);
7044 selection_info.id=(~0);
7045 state|=RedrawActionState;
7046 state|=RedrawListState;
7047 state&=(
unsigned int) (~RedrawWidgetState);
7049 if (state & RedrawListState)
7054 if (slider_info.id >= (
int) (entries-visible_entries))
7055 slider_info.id=(int) (entries-visible_entries);
7056 if ((slider_info.id < 0) || (entries <= visible_entries))
7058 slider_info.y=slider_info.min_y;
7060 slider_info.y+=slider_info.id*(slider_info.max_y-
7061 slider_info.min_y+1)/(
int) entries;
7062 if (slider_info.id != selection_info.id)
7067 selection_info.id=slider_info.id;
7068 selection_info.y=list_info.y+(int) (height >> 3)+2;
7069 for (i=0; i < (int) visible_entries; i++)
7071 selection_info.raised=(slider_info.id+i) != list_info.id ?
7072 MagickTrue : MagickFalse;
7073 selection_info.text=(
char *) NULL;
7074 if ((slider_info.id+i) < (
int) entries)
7075 selection_info.text=(
char *) list[slider_info.id+i];
7076 XDrawWidgetText(display,window_info,&selection_info);
7077 selection_info.y+=(int) selection_info.height;
7082 if (slider_info.y > expose_info.y)
7084 expose_info.height=(
unsigned int) (slider_info.y-expose_info.y);
7085 expose_info.y=slider_info.y-(int) expose_info.height-(
int)
7086 slider_info.bevel_width-1;
7090 expose_info.height=(
unsigned int) (expose_info.y-slider_info.y);
7091 expose_info.y=slider_info.y+(int) slider_info.height+(
int)
7092 slider_info.bevel_width+1;
7094 XDrawTriangleNorth(display,window_info,&north_info);
7095 XDrawMatte(display,window_info,&expose_info);
7096 XDrawBeveledButton(display,window_info,&slider_info);
7097 XDrawTriangleSouth(display,window_info,&south_info);
7098 expose_info.y=slider_info.y;
7100 state&=(
unsigned int) (~RedrawListState);
7105 if (north_info.raised && south_info.raised)
7106 (void) XIfEvent(display,&event,XScreenEvent,(
char *) windows);
7112 XDelay(display,delay);
7114 (void) XCheckIfEvent(display,&event,XScreenEvent,(
char *) windows);
7115 if (north_info.raised == MagickFalse)
7116 if (slider_info.id > 0)
7122 state|=RedrawListState;
7124 if (south_info.raised == MagickFalse)
7125 if (slider_info.id < (
int) entries)
7131 state|=RedrawListState;
7133 if (event.type != ButtonRelease)
7140 if (MatteIsActive(slider_info,event.xbutton))
7145 slider_info.active=MagickTrue;
7148 if (MatteIsActive(north_info,event.xbutton))
7149 if (slider_info.id > 0)
7154 north_info.raised=MagickFalse;
7156 state|=RedrawListState;
7159 if (MatteIsActive(south_info,event.xbutton))
7160 if (slider_info.id < (
int) entries)
7165 south_info.raised=MagickFalse;
7167 state|=RedrawListState;
7170 if (MatteIsActive(scroll_info,event.xbutton))
7175 if (event.xbutton.y < slider_info.y)
7176 slider_info.id-=(int) (visible_entries-1);
7178 slider_info.id+=(int) (visible_entries-1);
7179 state|=RedrawListState;
7182 if (MatteIsActive(list_info,event.xbutton))
7190 id=slider_info.id+(
event.xbutton.y-(list_info.y+(int)
7191 (height >> 1))+1)/(
int) selection_info.height;
7192 if (
id >= (
int) entries)
7194 (void) CopyMagickString(reply_info.text,list[
id],MagickPathExtent);
7195 reply_info.highlight=MagickFalse;
7196 reply_info.marker=reply_info.text;
7197 reply_info.cursor=reply_info.text+Extent(reply_info.text);
7198 XDrawMatteText(display,window_info,&reply_info);
7199 selection_info.id=(~0);
7200 if (
id == list_info.id)
7202 action_info.raised=MagickFalse;
7203 XDrawBeveledButton(display,window_info,&action_info);
7207 state|=RedrawListState;
7210 if (MatteIsActive(action_info,event.xbutton))
7215 action_info.raised=MagickFalse;
7216 XDrawBeveledButton(display,window_info,&action_info);
7219 if (MatteIsActive(cancel_info,event.xbutton))
7224 cancel_info.raised=MagickFalse;
7225 XDrawBeveledButton(display,window_info,&cancel_info);
7228 if (MatteIsActive(reply_info,event.xbutton) == MagickFalse)
7230 if (event.xbutton.button != Button2)
7238 x=
event.xbutton.x-reply_info.x-(int) (QuantumMargin >> 2);
7239 for (i=1; i <= Extent(reply_info.marker); i++)
7240 if (XTextWidth(font_info,reply_info.marker,i) > x)
7242 reply_info.cursor=reply_info.marker+i-1;
7243 if (event.xbutton.time > (click_time+(
unsigned long) DoubleClick))
7244 reply_info.highlight=MagickFalse;
7250 (void) CopyMagickString(primary_selection,reply_info.text,
7252 (void) XSetSelectionOwner(display,XA_PRIMARY,window_info->id,
7253 event.xbutton.time);
7254 reply_info.highlight=XGetSelectionOwner(display,XA_PRIMARY) ==
7255 window_info->id ? MagickTrue : MagickFalse;
7257 XDrawMatteText(display,window_info,&reply_info);
7258 click_time=
event.xbutton.time;
7264 (void) XConvertSelection(display,XA_PRIMARY,XA_STRING,XA_STRING,
7265 window_info->id,event.xbutton.time);
7270 if (window_info->mapped == MagickFalse)
7272 if (north_info.raised == MagickFalse)
7277 delay=SuspendTime << 2;
7278 north_info.raised=MagickTrue;
7279 XDrawTriangleNorth(display,window_info,&north_info);
7281 if (south_info.raised == MagickFalse)
7286 delay=SuspendTime << 2;
7287 south_info.raised=MagickTrue;
7288 XDrawTriangleSouth(display,window_info,&south_info);
7290 if (slider_info.active)
7295 slider_info.active=MagickFalse;
7298 if (action_info.raised == MagickFalse)
7300 if (event.xbutton.window == window_info->id)
7302 if (MatteIsActive(action_info,event.xbutton))
7304 if (*reply_info.text ==
'\0')
7305 (void) XBell(display,0);
7310 action_info.raised=MagickTrue;
7311 XDrawBeveledButton(display,window_info,&action_info);
7313 if (cancel_info.raised == MagickFalse)
7315 if (event.xbutton.window == window_info->id)
7316 if (MatteIsActive(cancel_info,event.xbutton))
7318 *reply_info.text=
'\0';
7321 cancel_info.raised=MagickTrue;
7322 XDrawBeveledButton(display,window_info,&cancel_info);
7324 if (MatteIsActive(reply_info,event.xbutton) == MagickFalse)
7333 if (event.xclient.message_type != windows->wm_protocols)
7335 if (*event.xclient.data.l == (
int) windows->wm_take_focus)
7337 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
7338 (Time) event.xclient.data.l[1]);
7341 if (*event.xclient.data.l != (
int) windows->wm_delete_window)
7343 if (event.xclient.window == window_info->id)
7345 *reply_info.text=
'\0';
7351 case ConfigureNotify:
7356 if (event.xconfigure.window != window_info->id)
7358 if ((event.xconfigure.width == (
int) window_info->width) &&
7359 (event.xconfigure.height == (
int) window_info->height))
7361 window_info->width=(
unsigned int)
7362 MagickMax(event.xconfigure.width,(
int) window_info->min_width);
7363 window_info->height=(
unsigned int)
7364 MagickMax(event.xconfigure.height,(
int) window_info->min_height);
7365 state|=UpdateConfigurationState;
7370 if (event.xcrossing.window != window_info->id)
7372 state&=(
unsigned int) (~InactiveWidgetState);
7377 if (event.xexpose.window != window_info->id)
7379 if (event.xexpose.count != 0)
7381 state|=RedrawWidgetState;
7387 command[MagickPathExtent];
7398 if (event.xkey.window != window_info->id)
7400 length=XLookupString((XKeyEvent *) &event.xkey,command,
7401 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
7402 *(command+length)=
'\0';
7403 if (AreaIsActive(scroll_info,event.xkey))
7408 switch ((
int) key_symbol)
7431 slider_info.id-=(int) visible_entries;
7437 slider_info.id+=(int) visible_entries;
7443 slider_info.id=(int) entries;
7447 state|=RedrawListState;
7450 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
7455 if (*reply_info.text ==
'\0')
7457 action_info.raised=MagickFalse;
7458 XDrawBeveledButton(display,window_info,&action_info);
7462 if (key_symbol == XK_Control_L)
7464 state|=ControlState;
7467 if (state & ControlState)
7468 switch ((
int) key_symbol)
7476 *reply_info.text=
'\0';
7477 reply_info.cursor=reply_info.text;
7478 reply_info.marker=reply_info.text;
7479 reply_info.highlight=MagickFalse;
7485 XEditText(display,&reply_info,key_symbol,command,state);
7486 XDrawMatteText(display,window_info,&reply_info);
7492 command[MagickPathExtent];
7500 if (event.xkey.window != window_info->id)
7502 (void) XLookupString((XKeyEvent *) &event.xkey,command,
7503 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
7504 if (key_symbol == XK_Control_L)
7505 state&=(
unsigned int) (~ControlState);
7510 if (event.xcrossing.window != window_info->id)
7512 state|=InactiveWidgetState;
7517 mask&=(
unsigned int) (~CWX);
7518 mask&=(
unsigned int) (~CWY);
7526 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
7527 if (slider_info.active)
7532 slider_info.y=
event.xmotion.y-(int)
7533 ((slider_info.height+slider_info.bevel_width) >> 1)+1;
7534 if (slider_info.y < slider_info.min_y)
7535 slider_info.y=slider_info.min_y;
7536 if (slider_info.y > slider_info.max_y)
7537 slider_info.y=slider_info.max_y;
7539 if (slider_info.y != slider_info.min_y)
7540 slider_info.id=((int) entries*(slider_info.y-
7541 slider_info.min_y+1))/(slider_info.max_y-slider_info.min_y+1);
7542 state|=RedrawListState;
7545 if (state & InactiveWidgetState)
7547 if (action_info.raised == MatteIsActive(action_info,event.xmotion))
7552 action_info.raised=action_info.raised == MagickFalse ?
7553 MagickTrue : MagickFalse;
7554 XDrawBeveledButton(display,window_info,&action_info);
7557 if (cancel_info.raised == MatteIsActive(cancel_info,event.xmotion))
7562 cancel_info.raised=cancel_info.raised == MagickFalse ?
7563 MagickTrue : MagickFalse;
7564 XDrawBeveledButton(display,window_info,&cancel_info);
7569 case SelectionClear:
7571 reply_info.highlight=MagickFalse;
7572 XDrawMatteText(display,window_info,&reply_info);
7575 case SelectionNotify:
7593 if (event.xselection.property == (Atom) None)
7595 status=XGetWindowProperty(display,
7596 event.xselection.requestor,event.xselection.property,0L,2047L,
7597 MagickTrue,XA_STRING,&type,&format,&length,&after,&data);
7598 if ((status != Success) || (type != XA_STRING) || (format == 32) ||
7601 if ((Extent(reply_info.text)+(
int) length) >= (MagickPathExtent-1))
7602 (void) XBell(display,0);
7608 *(data+length)=
'\0';
7609 XEditText(display,&reply_info,(KeySym) XK_Insert,(
char *) data,
7611 XDrawMatteText(display,window_info,&reply_info);
7612 state|=RedrawActionState;
7614 (void) XFree((
void *) data);
7617 case SelectionRequest:
7622 XSelectionRequestEvent
7625 if (reply_info.highlight == MagickFalse)
7630 request=(&(
event.xselectionrequest));
7631 (void) XChangeProperty(request->display,request->requestor,
7632 request->property,request->target,8,PropModeReplace,
7633 (
unsigned char *) primary_selection,Extent(primary_selection));
7634 notify.type=SelectionNotify;
7635 notify.send_event=MagickTrue;
7636 notify.display=request->display;
7637 notify.requestor=request->requestor;
7638 notify.selection=request->selection;
7639 notify.target=request->target;
7640 notify.time=request->time;
7641 if (request->property == None)
7642 notify.property=request->target;
7644 notify.property=request->property;
7645 (void) XSendEvent(request->display,request->requestor,False,NoEventMask,
7646 (XEvent *) ¬ify);
7651 }
while ((state & ExitState) == 0);
7652 XSetCursorState(display,windows,MagickFalse);
7653 (void) XWithdrawWindow(display,window_info->id,window_info->screen);
7654 XCheckRefreshWindows(display,windows);
7695MagickPrivate
int XMenuWidget(Display *display,XWindows *windows,
7696 const char *title,
const char *
const *selections,
char *item)
7722 XSetWindowAttributes
7736 assert(display != (Display *) NULL);
7737 assert(windows != (XWindows *) NULL);
7738 assert(title != (
char *) NULL);
7739 assert(selections != (
const char **) NULL);
7740 assert(item != (
char *) NULL);
7741 if (IsEventLogging() != MagickFalse)
7742 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",title);
7743 font_info=windows->widget.font_info;
7744 windows->widget.width=submenu_info.active == 0 ?
7745 WidgetTextWidth(font_info,(
char *) title) : 0;
7746 for (
id=0; selections[id] != (
char *) NULL;
id++)
7748 width=WidgetTextWidth(font_info,(
char *) selections[
id]);
7749 if (width > windows->widget.width)
7750 windows->widget.width=width;
7752 number_selections=(
unsigned int)
id;
7753 XGetWidgetInfo((
char *) NULL,&menu_info);
7754 title_height=(
unsigned int) (submenu_info.active == 0 ?
7755 (3*(font_info->descent+font_info->ascent) >> 1)+5 : 2);
7756 width=WidgetTextWidth(font_info,(
char *) title);
7757 height=(
unsigned int) ((3*(font_info->ascent+font_info->descent)) >> 1);
7761 windows->widget.width+=(
unsigned int) QuantumMargin+
7762 (menu_info.bevel_width << 1);
7763 top_offset=title_height+menu_info.bevel_width-1;
7764 windows->widget.height=top_offset+number_selections*height+4;
7765 windows->widget.min_width=windows->widget.width;
7766 windows->widget.min_height=windows->widget.height;
7767 XQueryPosition(display,windows->widget.root,&x,&y);
7768 windows->widget.x=x-(int) (QuantumMargin >> 1);
7769 if (submenu_info.active != 0)
7771 windows->widget.x=windows->command.x+(int) windows->command.width-
7773 toggle_info.raised=MagickTrue;
7774 XDrawTriangleEast(display,&windows->command,&toggle_info);
7776 windows->widget.y=submenu_info.active == 0 ? y-(int)
7777 ((3*title_height) >> 2) : y;
7778 if (submenu_info.active != 0)
7779 windows->widget.y=windows->command.y+submenu_info.y;
7780 XConstrainWindowPosition(display,&windows->widget);
7784 window_attributes.override_redirect=MagickTrue;
7785 (void) XChangeWindowAttributes(display,windows->widget.id,
7786 (
size_t) CWOverrideRedirect,&window_attributes);
7787 window_changes.width=(int) windows->widget.width;
7788 window_changes.height=(int) windows->widget.height;
7789 window_changes.x=windows->widget.x;
7790 window_changes.y=windows->widget.y;
7791 (void) XReconfigureWMWindow(display,windows->widget.id,windows->widget.screen,
7792 (
unsigned int) (CWWidth | CWHeight | CWX | CWY),&window_changes);
7793 (void) XMapRaised(display,windows->widget.id);
7794 windows->widget.mapped=MagickFalse;
7798 selection_info.height=height;
7799 cursor=XCreateFontCursor(display,XC_right_ptr);
7800 (void) XCheckDefineCursor(display,windows->image.id,cursor);
7801 (void) XCheckDefineCursor(display,windows->command.id,cursor);
7802 (void) XCheckDefineCursor(display,windows->widget.id,cursor);
7803 state=UpdateConfigurationState;
7806 if (state & UpdateConfigurationState)
7811 XGetWidgetInfo((
char *) NULL,&menu_info);
7812 menu_info.bevel_width--;
7813 menu_info.width=windows->widget.width-((menu_info.bevel_width) << 1);
7814 menu_info.height=windows->widget.height-((menu_info.bevel_width) << 1);
7815 menu_info.x=(int) menu_info.bevel_width;
7816 menu_info.y=(int) menu_info.bevel_width;
7817 XGetWidgetInfo((
char *) NULL,&selection_info);
7818 selection_info.center=MagickFalse;
7819 selection_info.width=menu_info.width;
7820 selection_info.height=height;
7821 selection_info.x=menu_info.x;
7822 highlight_info=selection_info;
7823 highlight_info.bevel_width--;
7824 highlight_info.width-=(highlight_info.bevel_width << 1);
7825 highlight_info.height-=(highlight_info.bevel_width << 1);
7826 highlight_info.x+=(int) highlight_info.bevel_width;
7827 state&=(
unsigned int) (~UpdateConfigurationState);
7829 if (state & RedrawWidgetState)
7834 if (submenu_info.active == 0)
7836 y=(int) title_height;
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,
7851 selection_info.center=MagickTrue;
7852 selection_info.y=(int) menu_info.bevel_width;
7853 selection_info.text=(
char *) title;
7854 if (submenu_info.active == 0)
7855 XDrawWidgetText(display,&windows->widget,&selection_info);
7856 selection_info.center=MagickFalse;
7857 selection_info.y=(int) top_offset;
7858 for (
id=0;
id < (int) number_selections;
id++)
7860 selection_info.text=(
char *) selections[
id];
7861 XDrawWidgetText(display,&windows->widget,&selection_info);
7862 highlight_info.y=selection_info.y+(int) highlight_info.bevel_width;
7863 if (
id == selection_info.id)
7864 XDrawBevel(display,&windows->widget,&highlight_info);
7865 selection_info.y+=(int) selection_info.height;
7867 XDrawBevel(display,&windows->widget,&menu_info);
7868 state&=(
unsigned int) (~RedrawWidgetState);
7870 if (number_selections > 2)
7875 y=((int) top_offset+(int) selection_info.height*(int)
7876 (number_selections-1));
7877 XSetBevelColor(display,&windows->widget,MagickFalse);
7878 (void) XDrawLine(display,windows->widget.id,
7879 windows->widget.widget_context,selection_info.x,y-1,
7880 (
int) selection_info.width,y-1);
7881 XSetBevelColor(display,&windows->widget,MagickTrue);
7882 (void) XDrawLine(display,windows->widget.id,
7883 windows->widget.widget_context,selection_info.x,y,
7884 (
int) selection_info.width,y);
7885 (void) XSetFillStyle(display,windows->widget.widget_context,FillSolid);
7890 (void) XIfEvent(display,&event,XScreenEvent,(
char *) windows);
7895 if (event.xbutton.window != windows->widget.id)
7900 if (event.xbutton.window == windows->command.id)
7901 (void) XPutBackEvent(display,&event);
7902 selection_info.id=(~0);
7907 state&=(
unsigned int) (~InactiveWidgetState);
7908 if (selection_info.height == 0)
7910 id=(
event.xbutton.y-(int) top_offset)/(
int) selection_info.height;
7911 selection_info.id=id;
7912 if ((
id < 0) || (
id >= (
int) number_selections))
7917 selection_info.y=((int) top_offset+
id*(int) selection_info.height);
7918 selection_info.text=(
char *) selections[
id];
7919 XDrawWidgetText(display,&windows->widget,&selection_info);
7920 highlight_info.y=selection_info.y+(int) highlight_info.bevel_width;
7921 XDrawBevel(display,&windows->widget,&highlight_info);
7926 if (windows->widget.mapped == MagickFalse)
7928 if (event.xbutton.window == windows->command.id)
7929 if ((state & InactiveWidgetState) == 0)
7934 XSetCursorState(display,windows,MagickFalse);
7939 case ConfigureNotify:
7944 if (event.xconfigure.window != windows->widget.id)
7946 if ((event.xconfigure.width == (
int) windows->widget.width) &&
7947 (event.xconfigure.height == (
int) windows->widget.height))
7949 windows->widget.width=(
unsigned int)
7950 MagickMax(event.xconfigure.width,(
int) windows->widget.min_width);
7951 windows->widget.height=(
unsigned int)
7952 MagickMax(event.xconfigure.height,(
int) windows->widget.min_height);
7953 state|=UpdateConfigurationState;
7958 if (event.xcrossing.window != windows->widget.id)
7960 if (event.xcrossing.state == 0)
7962 state&=(
unsigned int) (~InactiveWidgetState);
7963 if (selection_info.height == 0)
7965 id=((
event.xcrossing.y-(int) top_offset)/(int) selection_info.height);
7966 if ((selection_info.id >= 0) &&
7967 (selection_info.id < (
int) number_selections))
7972 if (
id == selection_info.id)
7974 selection_info.y=((int) top_offset+selection_info.id*(int)
7975 selection_info.height);
7976 selection_info.text=(
char *) selections[selection_info.id];
7977 XDrawWidgetText(display,&windows->widget,&selection_info);
7979 if ((
id < 0) || (
id >= (
int) number_selections))
7984 selection_info.id=id;
7985 selection_info.y=((int) top_offset+selection_info.id*(int)
7986 selection_info.height);
7987 selection_info.text=(
char *) selections[selection_info.id];
7988 XDrawWidgetText(display,&windows->widget,&selection_info);
7989 highlight_info.y=selection_info.y+(int) highlight_info.bevel_width;
7990 XDrawBevel(display,&windows->widget,&highlight_info);
7995 if (event.xexpose.window != windows->widget.id)
7997 if (event.xexpose.count != 0)
7999 state|=RedrawWidgetState;
8004 if (event.xcrossing.window != windows->widget.id)
8006 state|=InactiveWidgetState;
8007 id=selection_info.id;
8008 if ((
id < 0) || (
id >= (
int) number_selections))
8013 selection_info.y=((int) top_offset+
id*(int) selection_info.height);
8014 selection_info.id=(~0);
8015 selection_info.text=(
char *) selections[
id];
8016 XDrawWidgetText(display,&windows->widget,&selection_info);
8024 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
8025 if (submenu_info.active != 0)
8026 if (event.xmotion.window == windows->command.id)
8028 if ((state & InactiveWidgetState) == 0)
8030 if (MatteIsActive(submenu_info,event.xmotion) == MagickFalse)
8032 selection_info.id=(~0);
8039 if (WindowIsActive(windows->command,event.xmotion))
8041 selection_info.id=(~0);
8047 if (event.xmotion.window != windows->widget.id)
8049 if (state & InactiveWidgetState)
8051 if (selection_info.height == 0)
8053 id=(
event.xmotion.y-(int) top_offset)/(
int) selection_info.height;
8054 if ((selection_info.id >= 0) &&
8055 (selection_info.id < (
int) number_selections))
8060 if (
id == selection_info.id)
8062 selection_info.y=((int) top_offset+selection_info.id*(int)
8063 selection_info.height);
8064 selection_info.text=(
char *) selections[selection_info.id];
8065 XDrawWidgetText(display,&windows->widget,&selection_info);
8067 selection_info.id=id;
8068 if ((
id < 0) || (
id >= (
int) number_selections))
8073 selection_info.y=((int) top_offset+
id*(int) selection_info.height);
8074 selection_info.text=(
char *) selections[
id];
8075 XDrawWidgetText(display,&windows->widget,&selection_info);
8076 highlight_info.y=selection_info.y+(int) highlight_info.bevel_width;
8077 XDrawBevel(display,&windows->widget,&highlight_info);
8083 }
while ((state & ExitState) == 0);
8084 (void) XFreeCursor(display,cursor);
8085 window_attributes.override_redirect=MagickFalse;
8086 (void) XChangeWindowAttributes(display,windows->widget.id,
8087 (
size_t) CWOverrideRedirect,&window_attributes);
8088 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
8089 XCheckRefreshWindows(display,windows);
8090 if (submenu_info.active != 0)
8092 submenu_info.active=MagickFalse;
8093 toggle_info.raised=MagickFalse;
8094 XDrawTriangleEast(display,&windows->command,&toggle_info);
8096 if ((selection_info.id < 0) || (selection_info.id >= (
int) number_selections))
8098 (void) CopyMagickString(item,selections[selection_info.id],MagickPathExtent);
8099 return(selection_info.id);
8134MagickPrivate
void XNoticeWidget(Display *display,XWindows *windows,
8135 const char *reason,
const char *description)
8137#define DismissButtonText "Dismiss"
8178 assert(display != (Display *) NULL);
8179 assert(windows != (XWindows *) NULL);
8180 assert(reason != (
char *) NULL);
8181 if (IsEventLogging() != MagickFalse)
8182 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",reason);
8183 XDelay(display,SuspendTime << 3);
8184 XSetCursorState(display,windows,MagickTrue);
8185 XCheckRefreshWindows(display,windows);
8186 font_info=windows->widget.font_info;
8187 width=WidgetTextWidth(font_info,DismissButtonText);
8188 text=GetLocaleExceptionMessage(XServerError,reason);
8189 if (text != (
char *) NULL)
8190 if (WidgetTextWidth(font_info,(
char *) text) > width)
8191 width=WidgetTextWidth(font_info,(
char *) text);
8192 if (description != (
char *) NULL)
8194 text=GetLocaleExceptionMessage(XServerError,description);
8195 if (text != (
char *) NULL)
8196 if (WidgetTextWidth(font_info,(
char *) text) > width)
8197 width=WidgetTextWidth(font_info,(
char *) text);
8199 height=(
unsigned int) (font_info->ascent+font_info->descent);
8203 windows->widget.width=width+(
unsigned int) (4*QuantumMargin);
8204 windows->widget.min_width=width+(
unsigned int) QuantumMargin;
8205 if (windows->widget.width < windows->widget.min_width)
8206 windows->widget.width=windows->widget.min_width;
8207 windows->widget.height=(
unsigned int) (12*height);
8208 windows->widget.min_height=(
unsigned int) (7*height);
8209 if (windows->widget.height < windows->widget.min_height)
8210 windows->widget.height=windows->widget.min_height;
8211 XConstrainWindowPosition(display,&windows->widget);
8215 (void) CopyMagickString(windows->widget.name,
"Notice",MagickPathExtent);
8216 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
8217 if (status != False)
8219 XSetWMName(display,windows->widget.id,&window_name);
8220 XSetWMIconName(display,windows->widget.id,&window_name);
8221 (void) XFree((
void *) window_name.value);
8223 window_changes.width=(int) windows->widget.width;
8224 window_changes.height=(int) windows->widget.height;
8225 window_changes.x=windows->widget.x;
8226 window_changes.y=windows->widget.y;
8227 (void) XReconfigureWMWindow(display,windows->widget.id,windows->widget.screen,
8228 (
unsigned int) (CWWidth | CWHeight | CWX | CWY),&window_changes);
8229 (void) XMapRaised(display,windows->widget.id);
8230 windows->widget.mapped=MagickFalse;
8231 (void) XBell(display,0);
8235 timer=GetMagickTime()+Timeout;
8236 state=UpdateConfigurationState;
8239 if (GetMagickTime() > timer)
8241 if (state & UpdateConfigurationState)
8246 XGetWidgetInfo(DismissButtonText,&dismiss_info);
8247 dismiss_info.width=(
unsigned int) QuantumMargin+
8248 WidgetTextWidth(font_info,DismissButtonText);
8249 dismiss_info.height=(
unsigned int) ((3*height) >> 1);
8250 dismiss_info.x=(int)
8251 ((windows->widget.width >> 1)-(dismiss_info.width >> 1));
8252 dismiss_info.y=(int)
8253 (windows->widget.height-(dismiss_info.height << 1));
8254 state&=(
unsigned int) (~UpdateConfigurationState);
8256 if (state & RedrawWidgetState)
8261 width=WidgetTextWidth(font_info,(
char *) reason);
8262 x=(int) ((windows->widget.width >> 1)-(width >> 1));
8263 y=(int) ((windows->widget.height >> 1)-(height << 1));
8264 (void) XDrawString(display,windows->widget.id,
8265 windows->widget.annotate_context,x,y,(
char *) reason,Extent(reason));
8266 if (description != (
char *) NULL)
8268 width=WidgetTextWidth(font_info,(
char *) description);
8269 x=(int) ((windows->widget.width >> 1)-(width >> 1));
8271 (void) XDrawString(display,windows->widget.id,
8272 windows->widget.annotate_context,x,y,(
char *) description,
8273 Extent(description));
8275 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
8276 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
8277 state&=(
unsigned int) (~RedrawWidgetState);
8282 if (XCheckIfEvent(display,&event,XScreenEvent,(
char *) windows) == MagickFalse)
8287 XDelay(display,SuspendTime << 2);
8294 if (MatteIsActive(dismiss_info,event.xbutton))
8299 dismiss_info.raised=MagickFalse;
8300 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
8307 if (windows->widget.mapped == MagickFalse)
8309 if (dismiss_info.raised == MagickFalse)
8311 if (event.xbutton.window == windows->widget.id)
8312 if (MatteIsActive(dismiss_info,event.xbutton))
8314 dismiss_info.raised=MagickTrue;
8315 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
8324 if (event.xclient.message_type != windows->wm_protocols)
8326 if (*event.xclient.data.l == (
int) windows->wm_take_focus)
8328 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
8329 (Time) event.xclient.data.l[1]);
8332 if (*event.xclient.data.l != (
int) windows->wm_delete_window)
8334 if (event.xclient.window == windows->widget.id)
8341 case ConfigureNotify:
8346 if (event.xconfigure.window != windows->widget.id)
8348 if ((event.xconfigure.width == (
int) windows->widget.width) &&
8349 (event.xconfigure.height == (
int) windows->widget.height))
8351 windows->widget.width=(
unsigned int)
8352 MagickMax(event.xconfigure.width,(
int) windows->widget.min_width);
8353 windows->widget.height=(
unsigned int)
8354 MagickMax(event.xconfigure.height,(
int) windows->widget.min_height);
8355 state|=UpdateConfigurationState;
8360 if (event.xcrossing.window != windows->widget.id)
8362 state&=(
unsigned int) (~InactiveWidgetState);
8367 if (event.xexpose.window != windows->widget.id)
8369 if (event.xexpose.count != 0)
8371 state|=RedrawWidgetState;
8377 command[MagickPathExtent];
8385 if (event.xkey.window != windows->widget.id)
8387 (void) XLookupString((XKeyEvent *) &event.xkey,command,
8388 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
8389 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
8391 dismiss_info.raised=MagickFalse;
8392 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
8400 if (event.xcrossing.window != windows->widget.id)
8402 state|=InactiveWidgetState;
8410 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
8411 if (state & InactiveWidgetState)
8413 if (dismiss_info.raised == MatteIsActive(dismiss_info,event.xmotion))
8418 dismiss_info.raised=
8419 dismiss_info.raised == MagickFalse ? MagickTrue : MagickFalse;
8420 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
8428 }
while ((state & ExitState) == 0);
8429 XSetCursorState(display,windows,MagickFalse);
8430 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
8431 XCheckRefreshWindows(display,windows);
8464MagickPrivate MagickBooleanType XPreferencesWidget(Display *display,
8465 XResourceInfo *resource_info,XWindows *windows)
8467#define ApplyButtonText "Apply"
8468#define CacheButtonText "%lu mega-bytes of memory in the undo edit cache "
8469#define CancelButtonText "Cancel"
8470#define NumberPreferences 8
8475 "display image centered on a backdrop",
8476 "confirm on program exit",
8477 "confirm on image edits",
8478 "correct image for display gamma",
8479 "display warning messages",
8480 "apply Floyd/Steinberg error diffusion to image",
8481 "use a shared colormap for colormapped X visuals",
8482 "display images as an X server pixmap"
8486 cache[MagickPathExtent];
8519 preferences_info[NumberPreferences];
8527 if (IsEventLogging() != MagickFalse)
8528 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
8529 assert(display != (Display *) NULL);
8530 assert(resource_info != (XResourceInfo *) NULL);
8531 assert(windows != (XWindows *) NULL);
8532 XCheckRefreshWindows(display,windows);
8533 font_info=windows->widget.font_info;
8534 text_width=WidgetTextWidth(font_info,CacheButtonText);
8535 for (i=0; i < NumberPreferences; i++)
8536 if (WidgetTextWidth(font_info,(
char *) Preferences[i]) > text_width)
8537 text_width=WidgetTextWidth(font_info,(
char *) Preferences[i]);
8538 width=WidgetTextWidth(font_info,ApplyButtonText);
8539 if (WidgetTextWidth(font_info,CancelButtonText) > width)
8540 width=WidgetTextWidth(font_info,CancelButtonText);
8541 width+=(
unsigned int) QuantumMargin;
8542 height=(
unsigned int) (font_info->ascent+font_info->descent);
8546 windows->widget.width=(
unsigned int) (MagickMax((
int) (width << 1),
8547 (
int) text_width)+6*QuantumMargin);
8548 windows->widget.min_width=(width << 1)+(
unsigned int) QuantumMargin;
8549 if (windows->widget.width < windows->widget.min_width)
8550 windows->widget.width=windows->widget.min_width;
8551 windows->widget.height=(
unsigned int) (7*(
int) height+NumberPreferences*
8552 ((
int) height+(QuantumMargin >> 1)));
8553 windows->widget.min_height=(
unsigned int) (7*(
int) height+NumberPreferences*
8554 ((
int) height+(QuantumMargin >> 1)));
8555 if (windows->widget.height < windows->widget.min_height)
8556 windows->widget.height=windows->widget.min_height;
8557 XConstrainWindowPosition(display,&windows->widget);
8561 (void) CopyMagickString(windows->widget.name,
"Preferences",MagickPathExtent);
8562 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
8563 if (status != False)
8565 XSetWMName(display,windows->widget.id,&window_name);
8566 XSetWMIconName(display,windows->widget.id,&window_name);
8567 (void) XFree((
void *) window_name.value);
8569 window_changes.width=(int) windows->widget.width;
8570 window_changes.height=(int) windows->widget.height;
8571 window_changes.x=windows->widget.x;
8572 window_changes.y=windows->widget.y;
8573 (void) XReconfigureWMWindow(display,windows->widget.id,windows->widget.screen,
8574 (
unsigned int) (CWWidth | CWHeight | CWX | CWY),&window_changes);
8575 (void) XMapRaised(display,windows->widget.id);
8576 windows->widget.mapped=MagickFalse;
8580 state=UpdateConfigurationState;
8581 XSetCursorState(display,windows,MagickTrue);
8584 if (state & UpdateConfigurationState)
8589 XGetWidgetInfo(CancelButtonText,&cancel_info);
8590 cancel_info.width=width;
8591 cancel_info.height=(
unsigned int) (3*height) >> 1;
8592 cancel_info.x=(int) windows->widget.width-(
int) cancel_info.width-
8593 (QuantumMargin << 1);
8594 cancel_info.y=(int) windows->widget.height-(
int) cancel_info.height-
8596 XGetWidgetInfo(ApplyButtonText,&apply_info);
8597 apply_info.width=width;
8598 apply_info.height=(
unsigned int) (3*height) >> 1;
8599 apply_info.x=QuantumMargin << 1;
8600 apply_info.y=cancel_info.y;
8601 y=(int) (height << 1);
8602 for (i=0; i < NumberPreferences; i++)
8604 XGetWidgetInfo(Preferences[i],&preferences_info[i]);
8605 preferences_info[i].bevel_width--;
8606 preferences_info[i].width=(
unsigned int) QuantumMargin >> 1;
8607 preferences_info[i].height=(
unsigned int) QuantumMargin >> 1;
8608 preferences_info[i].x=QuantumMargin << 1;
8609 preferences_info[i].y=y;
8610 y+=(int) height+(QuantumMargin >> 1);
8612 preferences_info[0].raised=resource_info->backdrop ==
8613 MagickFalse ? MagickTrue : MagickFalse;
8614 preferences_info[1].raised=resource_info->confirm_exit ==
8615 MagickFalse ? MagickTrue : MagickFalse;
8616 preferences_info[2].raised=resource_info->confirm_edit ==
8617 MagickFalse ? MagickTrue : MagickFalse;
8618 preferences_info[3].raised=resource_info->gamma_correct ==
8619 MagickFalse ? MagickTrue : MagickFalse;
8620 preferences_info[4].raised=resource_info->display_warnings ==
8621 MagickFalse ? MagickTrue : MagickFalse;
8622 preferences_info[5].raised=
8623 resource_info->quantize_info->dither_method == NoDitherMethod ?
8624 MagickTrue : MagickFalse;
8625 preferences_info[6].raised=resource_info->colormap !=
8626 SharedColormap ? MagickTrue : MagickFalse;
8627 preferences_info[7].raised=resource_info->use_pixmap ==
8628 MagickFalse ? MagickTrue : MagickFalse;
8629 (void) FormatLocaleString(cache,MagickPathExtent,CacheButtonText,
8630 (
unsigned long) resource_info->undo_cache);
8631 XGetWidgetInfo(cache,&cache_info);
8632 cache_info.bevel_width--;
8633 cache_info.width=(
unsigned int) QuantumMargin >> 1;
8634 cache_info.height=(
unsigned int) QuantumMargin >> 1;
8635 cache_info.x=QuantumMargin << 1;
8637 state&=(
unsigned int) (~UpdateConfigurationState);
8639 if (state & RedrawWidgetState)
8644 XDrawBeveledButton(display,&windows->widget,&apply_info);
8645 XDrawBeveledButton(display,&windows->widget,&cancel_info);
8646 for (i=0; i < NumberPreferences; i++)
8647 XDrawBeveledButton(display,&windows->widget,&preferences_info[i]);
8648 XDrawTriangleEast(display,&windows->widget,&cache_info);
8649 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
8650 state&=(
unsigned int) (~RedrawWidgetState);
8655 (void) XIfEvent(display,&event,XScreenEvent,(
char *) windows);
8660 if (MatteIsActive(apply_info,event.xbutton))
8665 apply_info.raised=MagickFalse;
8666 XDrawBeveledButton(display,&windows->widget,&apply_info);
8669 if (MatteIsActive(cancel_info,event.xbutton))
8674 cancel_info.raised=MagickFalse;
8675 XDrawBeveledButton(display,&windows->widget,&cancel_info);
8678 for (i=0; i < NumberPreferences; i++)
8679 if (MatteIsActive(preferences_info[i],event.xbutton))
8684 preferences_info[i].raised=preferences_info[i].raised ==
8685 MagickFalse ? MagickTrue : MagickFalse;
8686 XDrawBeveledButton(display,&windows->widget,&preferences_info[i]);
8689 if (MatteIsActive(cache_info,event.xbutton))
8694 x=cache_info.x+(int) cache_info.width+(
int) cache_info.bevel_width+
8695 (QuantumMargin >> 1);
8696 y=cache_info.y+(int) ((cache_info.height-height) >> 1);
8697 width=WidgetTextWidth(font_info,cache);
8698 (void) XClearArea(display,windows->widget.id,x,y,width,height,
8700 resource_info->undo_cache<<=1;
8701 if (resource_info->undo_cache > 256)
8702 resource_info->undo_cache=1;
8703 (void) FormatLocaleString(cache,MagickPathExtent,CacheButtonText,
8704 (
unsigned long) resource_info->undo_cache);
8705 cache_info.raised=MagickFalse;
8706 XDrawTriangleEast(display,&windows->widget,&cache_info);
8713 if (windows->widget.mapped == MagickFalse)
8715 if (apply_info.raised == MagickFalse)
8717 if (event.xbutton.window == windows->widget.id)
8718 if (MatteIsActive(apply_info,event.xbutton))
8720 apply_info.raised=MagickTrue;
8721 XDrawBeveledButton(display,&windows->widget,&apply_info);
8722 apply_info.raised=MagickFalse;
8724 if (cancel_info.raised == MagickFalse)
8726 if (event.xbutton.window == windows->widget.id)
8727 if (MatteIsActive(cancel_info,event.xbutton))
8729 cancel_info.raised=MagickTrue;
8730 XDrawBeveledButton(display,&windows->widget,&cancel_info);
8732 if (cache_info.raised == MagickFalse)
8734 cache_info.raised=MagickTrue;
8735 XDrawTriangleEast(display,&windows->widget,&cache_info);
8744 if (event.xclient.message_type != windows->wm_protocols)
8746 if (*event.xclient.data.l == (
int) windows->wm_take_focus)
8748 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
8749 (Time) event.xclient.data.l[1]);
8752 if (*event.xclient.data.l != (
int) windows->wm_delete_window)
8754 if (event.xclient.window == windows->widget.id)
8761 case ConfigureNotify:
8766 if (event.xconfigure.window != windows->widget.id)
8768 if ((event.xconfigure.width == (
int) windows->widget.width) &&
8769 (event.xconfigure.height == (
int) windows->widget.height))
8771 windows->widget.width=(
unsigned int)
8772 MagickMax(event.xconfigure.width,(
int) windows->widget.min_width);
8773 windows->widget.height=(
unsigned int)
8774 MagickMax(event.xconfigure.height,(
int) windows->widget.min_height);
8775 state|=UpdateConfigurationState;
8780 if (event.xcrossing.window != windows->widget.id)
8782 state&=(
unsigned int) (~InactiveWidgetState);
8787 if (event.xexpose.window != windows->widget.id)
8789 if (event.xexpose.count != 0)
8791 state|=RedrawWidgetState;
8797 command[MagickPathExtent];
8805 if (event.xkey.window != windows->widget.id)
8807 (void) XLookupString((XKeyEvent *) &event.xkey,command,
8808 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
8809 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
8811 apply_info.raised=MagickFalse;
8812 XDrawBeveledButton(display,&windows->widget,&apply_info);
8820 if (event.xcrossing.window != windows->widget.id)
8822 state|=InactiveWidgetState;
8830 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
8831 if (state & InactiveWidgetState)
8833 if (apply_info.raised == MatteIsActive(apply_info,event.xmotion))
8839 apply_info.raised == MagickFalse ? MagickTrue : MagickFalse;
8840 XDrawBeveledButton(display,&windows->widget,&apply_info);
8843 if (cancel_info.raised == MatteIsActive(cancel_info,event.xmotion))
8849 cancel_info.raised == MagickFalse ? MagickTrue : MagickFalse;
8850 XDrawBeveledButton(display,&windows->widget,&cancel_info);
8858 }
while ((state & ExitState) == 0);
8859 XSetCursorState(display,windows,MagickFalse);
8860 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
8861 XCheckRefreshWindows(display,windows);
8862 if (apply_info.raised)
8863 return(MagickFalse);
8867 resource_info->backdrop=
8868 preferences_info[0].raised == MagickFalse ? MagickTrue : MagickFalse;
8869 resource_info->confirm_exit=
8870 preferences_info[1].raised == MagickFalse ? MagickTrue : MagickFalse;
8871 resource_info->confirm_edit=
8872 preferences_info[2].raised == MagickFalse ? MagickTrue : MagickFalse;
8873 resource_info->gamma_correct=
8874 preferences_info[3].raised == MagickFalse ? MagickTrue : MagickFalse;
8875 resource_info->display_warnings=
8876 preferences_info[4].raised == MagickFalse ? MagickTrue : MagickFalse;
8877 resource_info->quantize_info->dither_method=
8878 preferences_info[5].raised == MagickFalse ?
8879 RiemersmaDitherMethod : NoDitherMethod;
8880 resource_info->colormap=SharedColormap;
8881 if (preferences_info[6].raised)
8882 resource_info->colormap=PrivateColormap;
8883 resource_info->use_pixmap=
8884 preferences_info[7].raised == MagickFalse ? MagickTrue : MagickFalse;
8885 XUserPreferences(resource_info);
8925MagickPrivate
void XProgressMonitorWidget(Display *display,XWindows *windows,
8926 const char *task,
const MagickOffsetType offset,
const MagickSizeType span)
8934 assert(display != (Display *) NULL);
8935 assert(windows != (XWindows *) NULL);
8936 assert(task != (
const char *) NULL);
8937 if (IsEventLogging() != MagickFalse)
8938 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",task);
8944 while (XCheckTypedWindowEvent(display,windows->command.id,Expose,&event))
8945 (void) XCommandWidget(display,windows,(
const char *
const *) NULL,&event);
8946 while (XCheckTypedWindowEvent(display,windows->image.id,Expose,&event))
8947 XRefreshWindow(display,&windows->image,&event);
8948 while (XCheckTypedWindowEvent(display,windows->info.id,Expose,&event))
8949 if (monitor_info.text != (
char *) NULL)
8950 XInfoWidget(display,windows,monitor_info.text);
8954 if ((windows->info.mapped == MagickFalse) || (task != monitor_info.text))
8955 XInfoWidget(display,windows,task);
8956 width=(
unsigned int) (((offset+1)*((
int) windows->info.width-
8957 (2*monitor_info.x)))/(
int) span);
8958 if (width < monitor_info.width)
8960 monitor_info.raised=MagickTrue;
8961 XDrawWidgetText(display,&windows->info,&monitor_info);
8962 monitor_info.raised=MagickFalse;
8964 monitor_info.width=width;
8965 XDrawWidgetText(display,&windows->info,&monitor_info);
8966 (void) XFlush(display);
9005MagickPrivate
void XTextViewWidget(Display *display,
9006 const XResourceInfo *resource_info,XWindows *windows,
9007 const MagickBooleanType mono,
const char *title,
const char **textlist)
9009#define DismissButtonText "Dismiss"
9012 primary_selection[MagickPathExtent];
9017 static MagickStatusType
9018 mask = (MagickStatusType) (CWWidth | CWHeight | CWX | CWY);
9060 assert(display != (Display *) NULL);
9061 assert(resource_info != (XResourceInfo *) NULL);
9062 assert(windows != (XWindows *) NULL);
9063 assert(title != (
const char *) NULL);
9064 assert(textlist != (
const char **) NULL);
9065 if (IsEventLogging() != MagickFalse)
9066 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",title);
9067 XSetCursorState(display,windows,MagickTrue);
9068 XCheckRefreshWindows(display,windows);
9069 if (textlist == (
const char **) NULL)
9071 XNoticeWidget(display,windows,
"No text to view:",(
char *) NULL);
9077 font_info=windows->widget.font_info;
9078 text_info=(XFontStruct *) NULL;
9079 if (mono != MagickFalse)
9080 text_info=XBestFont(display,resource_info,MagickTrue);
9081 if (text_info == (XFontStruct *) NULL)
9082 text_info=windows->widget.font_info;
9084 for (i=0; textlist[i] != (
char *) NULL; i++)
9085 if (WidgetTextWidth(text_info,(
char *) textlist[i]) > text_width)
9086 text_width=(
unsigned int) XTextWidth(text_info,(
char *) textlist[i],
9087 MagickMin(Extent(textlist[i]),160));
9088 lines=(
unsigned int) i;
9089 width=WidgetTextWidth(font_info,DismissButtonText);
9090 width+=(
unsigned int) QuantumMargin;
9091 height=(
unsigned int) (text_info->ascent+text_info->descent);
9095 windows->widget.width=(
unsigned int) (MagickMin((
int) text_width,
9096 (
int) MaxTextWidth)+5*QuantumMargin);
9097 windows->widget.min_width=(
unsigned int) ((
int) MinTextWidth+4*QuantumMargin);
9098 if (windows->widget.width < windows->widget.min_width)
9099 windows->widget.width=windows->widget.min_width;
9100 windows->widget.height=(
unsigned int) (MagickMin(MagickMax((
int) lines,3),32)*
9101 (
int) height+(
int) ((13*height) >> 1)+((9*QuantumMargin) >> 1));
9102 windows->widget.min_height=(3*height+((13*height) >> 1)+(
unsigned int) ((9*
9103 QuantumMargin) >> 1));
9104 if (windows->widget.height < windows->widget.min_height)
9105 windows->widget.height=windows->widget.min_height;
9106 XConstrainWindowPosition(display,&windows->widget);
9110 (void) CopyMagickString(windows->widget.name,title,MagickPathExtent);
9111 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
9112 if (status != False)
9114 XSetWMName(display,windows->widget.id,&window_name);
9115 XSetWMIconName(display,windows->widget.id,&window_name);
9116 (void) XFree((
void *) window_name.value);
9118 window_changes.width=(int) windows->widget.width;
9119 window_changes.height=(int) windows->widget.height;
9120 window_changes.x=windows->widget.x;
9121 window_changes.y=windows->widget.y;
9122 (void) XReconfigureWMWindow(display,windows->widget.id,
9123 windows->widget.screen,(
unsigned int) mask,&window_changes);
9124 (void) XMapRaised(display,windows->widget.id);
9125 windows->widget.mapped=MagickFalse;
9129 XGetWidgetInfo((
char *) NULL,&slider_info);
9130 XGetWidgetInfo((
char *) NULL,&north_info);
9131 XGetWidgetInfo((
char *) NULL,&south_info);
9132 XGetWidgetInfo((
char *) NULL,&expose_info);
9133 XGetWidgetInfo((
char *) NULL,&selection_info);
9135 delay=SuspendTime << 2;
9136 height=(
unsigned int) (font_info->ascent+font_info->descent);
9137 state=UpdateConfigurationState;
9140 if (state & UpdateConfigurationState)
9148 XGetWidgetInfo(DismissButtonText,&dismiss_info);
9149 dismiss_info.width=width;
9150 dismiss_info.height=(
unsigned int) ((3*height) >> 1);
9151 dismiss_info.x=(int) windows->widget.width-(
int) dismiss_info.width-
9153 dismiss_info.y=(int) windows->widget.height-(
int) dismiss_info.height-
9158 XGetWidgetInfo((
char *) NULL,&scroll_info);
9159 scroll_info.bevel_width--;
9160 scroll_info.width=height;
9161 scroll_info.height=(
unsigned int) (dismiss_info.y-((5*QuantumMargin) >>
9163 scroll_info.x=(int) windows->widget.width-QuantumMargin-(
int)
9165 scroll_info.y=(3*QuantumMargin) >> 1;
9166 scroll_info.raised=MagickFalse;
9167 scroll_info.trough=MagickTrue;
9168 north_info=scroll_info;
9169 north_info.raised=MagickTrue;
9170 north_info.width-=(north_info.bevel_width << 1);
9171 north_info.height=north_info.width-1;
9172 north_info.x+=(int) north_info.bevel_width;
9173 north_info.y+=(int) north_info.bevel_width;
9174 south_info=north_info;
9175 south_info.y=scroll_info.y+(int) scroll_info.height-(
int)
9176 scroll_info.bevel_width-(int) south_info.height;
9178 slider_info=north_info;
9180 slider_info.width-=2;
9181 slider_info.min_y=north_info.y+(int) north_info.height+(
int)
9182 north_info.bevel_width+(int) slider_info.bevel_width+2;
9183 slider_info.height=(
unsigned int) ((
int) scroll_info.height-
9184 ((slider_info.min_y-scroll_info.y+1) << 1)+4);
9185 visible_lines=(
unsigned int) (scroll_info.height*PerceptibleReciprocal(
9186 (
double) text_info->ascent+text_info->descent+((text_info->ascent+
9187 text_info->descent) >> 3)));
9188 if (lines > visible_lines)
9189 slider_info.height=(
unsigned int) (visible_lines*slider_info.height)/
9191 slider_info.max_y=south_info.y-(int) south_info.bevel_width-(
int)
9192 slider_info.bevel_width-2;
9193 slider_info.x=scroll_info.x+(int) slider_info.bevel_width+1;
9194 slider_info.y=slider_info.min_y;
9195 expose_info=scroll_info;
9196 expose_info.y=slider_info.y;
9200 XGetWidgetInfo((
char *) NULL,&list_info);
9201 list_info.raised=MagickFalse;
9202 list_info.bevel_width--;
9203 list_info.width=(
unsigned int) (scroll_info.x-((3*QuantumMargin) >> 1));
9204 list_info.height=scroll_info.height;
9205 list_info.x=QuantumMargin;
9206 list_info.y=scroll_info.y;
9210 XGetWidgetInfo((
char *) NULL,&selection_info);
9211 selection_info.center=MagickFalse;
9212 selection_info.width=list_info.width;
9213 selection_info.height=(
unsigned int)
9214 (9*(text_info->ascent+text_info->descent)) >> 3;
9215 selection_info.x=list_info.x;
9216 state&=(
unsigned int) (~UpdateConfigurationState);
9218 if (state & RedrawWidgetState)
9223 XDrawBeveledMatte(display,&windows->widget,&list_info);
9224 XDrawBeveledMatte(display,&windows->widget,&scroll_info);
9225 XDrawTriangleNorth(display,&windows->widget,&north_info);
9226 XDrawBeveledButton(display,&windows->widget,&slider_info);
9227 XDrawTriangleSouth(display,&windows->widget,&south_info);
9228 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
9229 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
9230 selection_info.id=(~0);
9231 state|=RedrawListState;
9232 state&=(
unsigned int) (~RedrawWidgetState);
9234 if (state & RedrawListState)
9239 if (slider_info.id >= (
int) (lines-visible_lines))
9240 slider_info.id=(int) (lines-visible_lines);
9241 if ((slider_info.id < 0) || (lines <= visible_lines))
9243 slider_info.y=slider_info.min_y;
9245 slider_info.y+=slider_info.id*(slider_info.max_y-
9246 slider_info.min_y+1)/(
int) lines;
9247 if (slider_info.id != selection_info.id)
9252 windows->widget.font_info=text_info;
9253 (void) XSetFont(display,windows->widget.annotate_context,
9255 (void) XSetFont(display,windows->widget.highlight_context,
9257 selection_info.id=slider_info.id;
9258 selection_info.y=list_info.y+(int) (height >> 3)+2;
9259 for (i=0; i < (int) visible_lines; i++)
9261 selection_info.raised=
9262 (slider_info.id+i) != list_info.id ? MagickTrue : MagickFalse;
9263 selection_info.text=(
char *) NULL;
9264 if ((slider_info.id+i) < (
int) lines)
9265 selection_info.text=(
char *) textlist[slider_info.id+i];
9266 XDrawWidgetText(display,&windows->widget,&selection_info);
9267 selection_info.y+=(int) selection_info.height;
9269 windows->widget.font_info=font_info;
9270 (void) XSetFont(display,windows->widget.annotate_context,
9272 (void) XSetFont(display,windows->widget.highlight_context,
9277 if (slider_info.y > expose_info.y)
9279 expose_info.height=(
unsigned int) (slider_info.y-expose_info.y);
9280 expose_info.y=slider_info.y-(int) expose_info.height-(
int)
9281 slider_info.bevel_width-1;
9285 expose_info.height=(
unsigned int) (expose_info.y-slider_info.y);
9286 expose_info.y=slider_info.y+(int) slider_info.height+(
int)
9287 slider_info.bevel_width+1;
9289 XDrawTriangleNorth(display,&windows->widget,&north_info);
9290 XDrawMatte(display,&windows->widget,&expose_info);
9291 XDrawBeveledButton(display,&windows->widget,&slider_info);
9292 XDrawTriangleSouth(display,&windows->widget,&south_info);
9293 expose_info.y=slider_info.y;
9295 state&=(
unsigned int) (~RedrawListState);
9300 if (north_info.raised && south_info.raised)
9301 (void) XIfEvent(display,&event,XScreenEvent,(
char *) windows);
9307 XDelay(display,delay);
9309 (void) XCheckIfEvent(display,&event,XScreenEvent,(
char *) windows);
9310 if (north_info.raised == MagickFalse)
9311 if (slider_info.id > 0)
9317 state|=RedrawListState;
9319 if (south_info.raised == MagickFalse)
9320 if (slider_info.id < (
int) lines)
9326 state|=RedrawListState;
9328 if (event.type != ButtonRelease)
9335 if (MatteIsActive(slider_info,event.xbutton))
9340 slider_info.active=MagickTrue;
9343 if (MatteIsActive(north_info,event.xbutton))
9344 if (slider_info.id > 0)
9349 north_info.raised=MagickFalse;
9351 state|=RedrawListState;
9354 if (MatteIsActive(south_info,event.xbutton))
9355 if (slider_info.id < (
int) lines)
9360 south_info.raised=MagickFalse;
9362 state|=RedrawListState;
9365 if (MatteIsActive(scroll_info,event.xbutton))
9370 if (event.xbutton.y < slider_info.y)
9371 slider_info.id-=(int) (visible_lines-1);
9373 slider_info.id+=(int) (visible_lines-1);
9374 state|=RedrawListState;
9377 if (MatteIsActive(dismiss_info,event.xbutton))
9382 dismiss_info.raised=MagickFalse;
9383 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
9386 if (MatteIsActive(list_info,event.xbutton))
9397 id=slider_info.id+(
event.xbutton.y-(list_info.y+(int)
9398 (height >> 1))+1)/(
int) selection_info.height;
9399 if (
id >= (
int) lines)
9401 if (
id != list_info.id)
9404 click_time=
event.xbutton.time;
9408 if (event.xbutton.time >= (click_time+(
unsigned long) DoubleClick))
9410 click_time=
event.xbutton.time;
9413 click_time=
event.xbutton.time;
9417 (void) CopyMagickString(primary_selection,textlist[list_info.id],
9419 (void) XSetSelectionOwner(display,XA_PRIMARY,windows->widget.id,
9420 event.xbutton.time);
9421 if (XGetSelectionOwner(display,XA_PRIMARY) != windows->widget.id)
9423 selection_info.id=(~0);
9425 state|=RedrawListState;
9432 if (windows->widget.mapped == MagickFalse)
9434 if (north_info.raised == MagickFalse)
9439 delay=SuspendTime << 2;
9440 north_info.raised=MagickTrue;
9441 XDrawTriangleNorth(display,&windows->widget,&north_info);
9443 if (south_info.raised == MagickFalse)
9448 delay=SuspendTime << 2;
9449 south_info.raised=MagickTrue;
9450 XDrawTriangleSouth(display,&windows->widget,&south_info);
9452 if (slider_info.active)
9457 slider_info.active=MagickFalse;
9460 if (dismiss_info.raised == MagickFalse)
9462 if (event.xbutton.window == windows->widget.id)
9463 if (MatteIsActive(dismiss_info,event.xbutton))
9465 dismiss_info.raised=MagickTrue;
9466 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
9475 if (event.xclient.message_type != windows->wm_protocols)
9477 if (*event.xclient.data.l == (
int) windows->wm_take_focus)
9479 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
9480 (Time) event.xclient.data.l[1]);
9483 if (*event.xclient.data.l != (
int) windows->wm_delete_window)
9485 if (event.xclient.window == windows->widget.id)
9492 case ConfigureNotify:
9497 if (event.xconfigure.window != windows->widget.id)
9499 if ((event.xconfigure.width == (
int) windows->widget.width) &&
9500 (event.xconfigure.height == (
int) windows->widget.height))
9502 windows->widget.width=(
unsigned int)
9503 MagickMax(event.xconfigure.width,(
int) windows->widget.min_width);
9504 windows->widget.height=(
unsigned int)
9505 MagickMax(event.xconfigure.height,(
int) windows->widget.min_height);
9506 state|=UpdateConfigurationState;
9511 if (event.xcrossing.window != windows->widget.id)
9513 state&=(
unsigned int) (~InactiveWidgetState);
9518 if (event.xexpose.window != windows->widget.id)
9520 if (event.xexpose.count != 0)
9522 state|=RedrawWidgetState;
9528 command[MagickPathExtent];
9539 if (event.xkey.window != windows->widget.id)
9541 length=XLookupString((XKeyEvent *) &event.xkey,command,
9542 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
9543 *(command+length)=
'\0';
9544 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
9546 dismiss_info.raised=MagickFalse;
9547 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
9551 if (AreaIsActive(scroll_info,event.xkey))
9556 switch ((
int) key_symbol)
9579 slider_info.id-=(int) visible_lines;
9585 slider_info.id+=(int) visible_lines;
9591 slider_info.id=(int) lines;
9595 state|=RedrawListState;
9604 if (event.xcrossing.window != windows->widget.id)
9606 state|=InactiveWidgetState;
9611 mask&=(
unsigned int) (~CWX);
9612 mask&=(
unsigned int) (~CWY);
9620 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
9621 if (slider_info.active)
9626 slider_info.y=
event.xmotion.y-(int)
9627 ((slider_info.height+slider_info.bevel_width) >> 1)+1;
9628 if (slider_info.y < slider_info.min_y)
9629 slider_info.y=slider_info.min_y;
9630 if (slider_info.y > slider_info.max_y)
9631 slider_info.y=slider_info.max_y;
9633 if (slider_info.y != slider_info.min_y)
9634 slider_info.id=((int) lines*(slider_info.y-slider_info.min_y+1))/
9635 (slider_info.max_y-slider_info.min_y+1);
9636 state|=RedrawListState;
9639 if (state & InactiveWidgetState)
9641 if (dismiss_info.raised == MatteIsActive(dismiss_info,event.xmotion))
9646 dismiss_info.raised=
9647 dismiss_info.raised == MagickFalse ? MagickTrue : MagickFalse;
9648 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
9653 case SelectionClear:
9656 selection_info.id=(~0);
9657 state|=RedrawListState;
9660 case SelectionRequest:
9665 XSelectionRequestEvent
9668 if (list_info.id == (~0))
9673 request=(&(
event.xselectionrequest));
9674 (void) XChangeProperty(request->display,request->requestor,
9675 request->property,request->target,8,PropModeReplace,
9676 (
unsigned char *) primary_selection,Extent(primary_selection));
9677 notify.type=SelectionNotify;
9678 notify.send_event=MagickTrue;
9679 notify.display=request->display;
9680 notify.requestor=request->requestor;
9681 notify.selection=request->selection;
9682 notify.target=request->target;
9683 notify.time=request->time;
9684 if (request->property == None)
9685 notify.property=request->target;
9687 notify.property=request->property;
9688 (void) XSendEvent(request->display,request->requestor,False,NoEventMask,
9689 (XEvent *) ¬ify);
9694 }
while ((state & ExitState) == 0);
9695 if (text_info != windows->widget.font_info)
9696 (void) XFreeFont(display,text_info);
9697 XSetCursorState(display,windows,MagickFalse);
9698 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
9699 XCheckRefreshWindows(display,windows);