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 *q=(*(q-Extent(text)));
1178 for (i=0; i < Extent(text); i++)
1179 *text_info->cursor++=(*p++);
1210static void XGetWidgetInfo(
const char *text,XWidgetInfo *widget_info)
1215 widget_info->id=(~0);
1216 widget_info->bevel_width=3;
1217 widget_info->width=1;
1218 widget_info->height=1;
1221 widget_info->min_y=0;
1222 widget_info->max_y=0;
1223 widget_info->raised=MagickTrue;
1224 widget_info->active=MagickFalse;
1225 widget_info->center=MagickTrue;
1226 widget_info->trough=MagickFalse;
1227 widget_info->highlight=MagickFalse;
1228 widget_info->text=(
char *) text;
1229 widget_info->cursor=(
char *) text;
1230 if (text != (
char *) NULL)
1231 widget_info->cursor+=Extent(text);
1232 widget_info->marker=(
char *) text;
1266static void XHighlightWidget(Display *display,
const XWindowInfo *window_info,
1267 const int x,
const int y)
1272 XSetBevelColor(display,window_info,MagickTrue);
1273 (void) XDrawRectangle(display,window_info->id,window_info->widget_context,x,y,
1274 (
unsigned int) ((
int) window_info->width-(x << 1)),(
unsigned int)
1275 ((
int) window_info->height-(y << 1)));
1276 (void) XDrawRectangle(display,window_info->id,window_info->widget_context,
1277 x-1,y-1,(
unsigned int) ((
int) window_info->width-(x << 1)+1),(
unsigned int)
1278 ((
int) window_info->height-(y << 1)+1));
1279 XSetBevelColor(display,window_info,MagickFalse);
1280 (void) XDrawRectangle(display,window_info->id,window_info->widget_context,
1281 x-1,y-1,(
unsigned int) ((
int) window_info->width-(x << 1)),(
unsigned int)
1282 ((
int) window_info->height-(y << 1)));
1283 (void) XSetFillStyle(display,window_info->widget_context,FillSolid);
1315#if defined(__cplusplus) || defined(c_plusplus)
1319static int XScreenEvent(Display *display,XEvent *event,
char *data)
1324 windows=(XWindows *) data;
1325 if (event->xany.window == windows->popup.id)
1327 if (event->type == MapNotify)
1328 windows->popup.mapped=MagickTrue;
1329 if (event->type == UnmapNotify)
1330 windows->popup.mapped=MagickFalse;
1333 if (event->xany.window == windows->widget.id)
1335 if (event->type == MapNotify)
1336 windows->widget.mapped=MagickTrue;
1337 if (event->type == UnmapNotify)
1338 windows->widget.mapped=MagickFalse;
1341 switch (event->type)
1345 if ((event->xbutton.button == Button3) &&
1346 (event->xbutton.state & Mod1Mask))
1351 event->xbutton.button=Button2;
1352 event->xbutton.state&=(
unsigned int) (~Mod1Mask);
1358 if (event->xexpose.window == windows->image.id)
1360 XRefreshWindow(display,&windows->image,event);
1363 if (event->xexpose.window == windows->magnify.id)
1364 if (event->xexpose.count == 0)
1365 if (windows->magnify.mapped)
1370 exception=AcquireExceptionInfo();
1371 XMakeMagnifyImage(display,windows,exception);
1372 exception=DestroyExceptionInfo(exception);
1375 if (event->xexpose.window == windows->command.id)
1376 if (event->xexpose.count == 0)
1378 (void) XCommandWidget(display,windows,(
const char *
const *) NULL,
1389 if (event->xfocus.window == windows->image.id)
1390 (void) XSetInputFocus(display,windows->image.id,RevertToNone,
1398 case SelectionNotify:
1403 return(MagickFalse);
1406#if defined(__cplusplus) || defined(c_plusplus)
1438static void XSetBevelColor(Display *display,
const XWindowInfo *window_info,
1439 const MagickStatusType raised)
1441 if (window_info->depth == 1)
1449 (void) XSetBackground(display,window_info->widget_context,
1450 XBlackPixel(display,window_info->screen));
1451 (void) XSetForeground(display,window_info->widget_context,
1452 XWhitePixel(display,window_info->screen));
1453 (void) XSetFillStyle(display,window_info->widget_context,
1454 FillOpaqueStippled);
1455 stipple=window_info->highlight_stipple;
1456 if (raised == MagickFalse)
1457 stipple=window_info->shadow_stipple;
1458 (void) XSetStipple(display,window_info->widget_context,stipple);
1462 (void) XSetForeground(display,window_info->widget_context,
1463 window_info->pixel_info->highlight_color.pixel);
1465 (
void) XSetForeground(display,window_info->widget_context,
1466 window_info->pixel_info->shadow_color.pixel);
1496static void XSetMatteColor(Display *display,
const XWindowInfo *window_info,
1497 const MagickStatusType raised)
1499 if (window_info->depth == 1)
1505 (void) XSetForeground(display,window_info->widget_context,
1506 XWhitePixel(display,window_info->screen));
1508 (
void) XSetForeground(display,window_info->widget_context,
1509 XBlackPixel(display,window_info->screen));
1513 (void) XSetForeground(display,window_info->widget_context,
1514 window_info->pixel_info->matte_color.pixel);
1516 (
void) XSetForeground(display,window_info->widget_context,
1517 window_info->pixel_info->depth_color.pixel);
1548static void XSetTextColor(Display *display,
const XWindowInfo *window_info,
1549 const MagickStatusType raised)
1555 if (window_info->depth == 1)
1561 (void) XSetForeground(display,window_info->widget_context,
1562 XBlackPixel(display,window_info->screen));
1564 (
void) XSetForeground(display,window_info->widget_context,
1565 XWhitePixel(display,window_info->screen));
1568 foreground=(ssize_t) XPixelIntensity(
1569 &window_info->pixel_info->foreground_color);
1570 matte=(ssize_t) XPixelIntensity(&window_info->pixel_info->matte_color);
1571 if (MagickAbsoluteValue((
int) (foreground-matte)) > (65535L >> 3))
1572 (void) XSetForeground(display,window_info->widget_context,
1573 window_info->pixel_info->foreground_color.pixel);
1575 (
void) XSetForeground(display,window_info->widget_context,
1576 window_info->pixel_info->background_color.pixel);
1611MagickPrivate
void XColorBrowserWidget(Display *display,XWindows *windows,
1612 const char *action,
char *reply)
1614#define CancelButtonText "Cancel"
1615#define ColornameText "Name:"
1616#define ColorPatternText "Pattern:"
1617#define GrabButtonText "Grab"
1618#define ResetButtonText "Reset"
1622 primary_selection[MagickPathExtent],
1623 reset_pattern[MagickPathExtent],
1624 text[MagickPathExtent];
1637 glob_pattern[MagickPathExtent] =
"*";
1639 static MagickStatusType
1640 mask = (MagickStatusType) (CWWidth | CWHeight | CWX | CWY);
1690 assert(display != (Display *) NULL);
1691 assert(windows != (XWindows *) NULL);
1692 assert(action != (
char *) NULL);
1693 assert(reply != (
char *) NULL);
1694 if (IsEventLogging() != MagickFalse)
1695 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",action);
1696 XSetCursorState(display,windows,MagickTrue);
1697 XCheckRefreshWindows(display,windows);
1698 (void) CopyMagickString(reset_pattern,
"*",MagickPathExtent);
1699 exception=AcquireExceptionInfo();
1700 colorlist=GetColorList(glob_pattern,&colors,exception);
1701 if (colorlist == (
char **) NULL)
1706 (void) CopyMagickString(glob_pattern,
"*",MagickPathExtent);
1707 colorlist=GetColorList(glob_pattern,&colors,exception);
1708 if (colorlist == (
char **) NULL)
1710 XNoticeWidget(display,windows,
"Unable to obtain colors names:",
1712 (void) XDialogWidget(display,windows,action,
"Enter color name:",
1720 font_info=windows->widget.font_info;
1722 for (i=0; i < (int) colors; i++)
1723 if (WidgetTextWidth(font_info,colorlist[i]) > text_width)
1724 text_width=WidgetTextWidth(font_info,colorlist[i]);
1725 width=WidgetTextWidth(font_info,(
char *) action);
1726 if (WidgetTextWidth(font_info,CancelButtonText) > width)
1727 width=WidgetTextWidth(font_info,CancelButtonText);
1728 if (WidgetTextWidth(font_info,ResetButtonText) > width)
1729 width=WidgetTextWidth(font_info,ResetButtonText);
1730 if (WidgetTextWidth(font_info,GrabButtonText) > width)
1731 width=WidgetTextWidth(font_info,GrabButtonText);
1732 width+=(
unsigned int) QuantumMargin;
1733 if (WidgetTextWidth(font_info,ColorPatternText) > width)
1734 width=WidgetTextWidth(font_info,ColorPatternText);
1735 if (WidgetTextWidth(font_info,ColornameText) > width)
1736 width=WidgetTextWidth(font_info,ColornameText);
1737 height=(
unsigned int) (font_info->ascent+font_info->descent);
1741 windows->widget.width=width+MagickMin(text_width,MaxTextWidth)+
1742 6*(
unsigned int) QuantumMargin;
1743 windows->widget.min_width=width+MinTextWidth+4*(
unsigned int) QuantumMargin;
1744 if (windows->widget.width < windows->widget.min_width)
1745 windows->widget.width=windows->widget.min_width;
1746 windows->widget.height=(
unsigned int)
1747 ((81*height) >> 2)+((13*(
unsigned int) QuantumMargin) >> 1)+4;
1748 windows->widget.min_height=(
unsigned int)
1749 (((23*height) >> 1)+((13*(
unsigned int) QuantumMargin) >> 1)+4);
1750 if (windows->widget.height < windows->widget.min_height)
1751 windows->widget.height=windows->widget.min_height;
1752 XConstrainWindowPosition(display,&windows->widget);
1756 (void) CopyMagickString(windows->widget.name,
"Browse and Select a Color",
1758 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
1759 if (status != False)
1761 XSetWMName(display,windows->widget.id,&window_name);
1762 XSetWMIconName(display,windows->widget.id,&window_name);
1763 (void) XFree((
void *) window_name.value);
1765 window_changes.width=(int) windows->widget.width;
1766 window_changes.height=(int) windows->widget.height;
1767 window_changes.x=windows->widget.x;
1768 window_changes.y=windows->widget.y;
1769 (void) XReconfigureWMWindow(display,windows->widget.id,windows->widget.screen,
1770 mask,&window_changes);
1771 (void) XMapRaised(display,windows->widget.id);
1772 windows->widget.mapped=MagickFalse;
1776 XGetWidgetInfo((
char *) NULL,&mode_info);
1777 XGetWidgetInfo((
char *) NULL,&slider_info);
1778 XGetWidgetInfo((
char *) NULL,&north_info);
1779 XGetWidgetInfo((
char *) NULL,&south_info);
1780 XGetWidgetInfo((
char *) NULL,&expose_info);
1781 XGetWidgetInfo((
char *) NULL,&selection_info);
1783 delay=SuspendTime << 2;
1784 state=UpdateConfigurationState;
1787 if (state & UpdateConfigurationState)
1795 XGetWidgetInfo(CancelButtonText,&cancel_info);
1796 cancel_info.width=width;
1797 cancel_info.height=(
unsigned int) ((3*height) >> 1);
1798 cancel_info.x=(int) windows->widget.width-(
int) cancel_info.width-
1800 cancel_info.y=(int) windows->widget.height-(
int) cancel_info.height-
1802 XGetWidgetInfo(action,&action_info);
1803 action_info.width=width;
1804 action_info.height=(
unsigned int) ((3*height) >> 1);
1805 action_info.x=(int) windows->widget.width-(
int) action_info.width-
1806 (int) cancel_info.width-2*QuantumMargin-2;
1807 action_info.y=cancel_info.y;
1808 XGetWidgetInfo(GrabButtonText,&grab_info);
1809 grab_info.width=width;
1810 grab_info.height=(
unsigned int) ((3*height) >> 1);
1811 grab_info.x=QuantumMargin;
1812 grab_info.y=((5*QuantumMargin) >> 1)+(
int) height;
1813 XGetWidgetInfo(ResetButtonText,&reset_info);
1814 reset_info.width=width;
1815 reset_info.height=(
unsigned int) ((3*height) >> 1);
1816 reset_info.x=QuantumMargin;
1817 reset_info.y=grab_info.y+(int) grab_info.height+QuantumMargin;
1821 XGetWidgetInfo(reply,&reply_info);
1822 reply_info.raised=MagickFalse;
1823 reply_info.bevel_width--;
1824 reply_info.width=windows->widget.width-width-(
unsigned int)
1825 ((6*QuantumMargin) >> 1);
1826 reply_info.height=height << 1;
1827 reply_info.x=(int) width+(QuantumMargin << 1);
1828 reply_info.y=action_info.y-(int) reply_info.height-QuantumMargin;
1832 XGetWidgetInfo((
char *) NULL,&mode_info);
1833 mode_info.active=MagickTrue;
1834 mode_info.bevel_width=0;
1835 mode_info.width=(
unsigned int) (action_info.x-(
int) (QuantumMargin << 1));
1836 mode_info.height=action_info.height;
1837 mode_info.x=QuantumMargin;
1838 mode_info.y=action_info.y;
1842 XGetWidgetInfo((
char *) NULL,&scroll_info);
1843 scroll_info.bevel_width--;
1844 scroll_info.width=height;
1845 scroll_info.height=(
unsigned int) (reply_info.y-grab_info.y-
1846 (QuantumMargin >> 1));
1847 scroll_info.x=reply_info.x+(int) (reply_info.width-scroll_info.width);
1848 scroll_info.y=grab_info.y-(int) reply_info.bevel_width;
1849 scroll_info.raised=MagickFalse;
1850 scroll_info.trough=MagickTrue;
1851 north_info=scroll_info;
1852 north_info.raised=MagickTrue;
1853 north_info.width-=(north_info.bevel_width << 1);
1854 north_info.height=north_info.width-1;
1855 north_info.x+=(int) north_info.bevel_width;
1856 north_info.y+=(int) north_info.bevel_width;
1857 south_info=north_info;
1858 south_info.y=scroll_info.y+(int) scroll_info.height-(
int)
1859 scroll_info.bevel_width-(int) south_info.height;
1861 slider_info=north_info;
1863 slider_info.width-=2;
1864 slider_info.min_y=north_info.y+(int) north_info.height+(
int)
1865 north_info.bevel_width+(int) slider_info.bevel_width+2;
1866 slider_info.height=(
unsigned int) ((
int) scroll_info.height-
1867 ((slider_info.min_y-scroll_info.y+1) << 1)+4);
1868 visible_colors=(
unsigned int) (scroll_info.height*
1869 PerceptibleReciprocal((
double) height+(height >> 3)));
1870 if (colors > visible_colors)
1871 slider_info.height=(
unsigned int) ((visible_colors*
1872 slider_info.height)/colors);
1873 slider_info.max_y=south_info.y-(int) south_info.bevel_width-
1874 (
int) slider_info.bevel_width-2;
1875 slider_info.x=scroll_info.x+(int) slider_info.bevel_width+1;
1876 slider_info.y=slider_info.min_y;
1877 expose_info=scroll_info;
1878 expose_info.y=slider_info.y;
1882 XGetWidgetInfo((
char *) NULL,&list_info);
1883 list_info.raised=MagickFalse;
1884 list_info.bevel_width--;
1885 list_info.width=(
unsigned int)
1886 (scroll_info.x-reply_info.x-(
int) (QuantumMargin >> 1));
1887 list_info.height=scroll_info.height;
1888 list_info.x=reply_info.x;
1889 list_info.y=scroll_info.y;
1890 if (windows->widget.mapped == MagickFalse)
1891 state|=JumpListState;
1896 XGetWidgetInfo(text,&text_info);
1897 text_info.center=MagickFalse;
1898 text_info.width=reply_info.width;
1899 text_info.height=height;
1900 text_info.x=list_info.x-(int) (QuantumMargin >> 1);
1901 text_info.y=QuantumMargin;
1905 XGetWidgetInfo((
char *) NULL,&selection_info);
1906 selection_info.center=MagickFalse;
1907 selection_info.width=list_info.width;
1908 selection_info.height=(
unsigned int) ((9*height) >> 3);
1909 selection_info.x=list_info.x;
1910 state&=(
unsigned int) (~UpdateConfigurationState);
1912 if (state & RedrawWidgetState)
1918 y=text_info.y+(int) ((text_info.height-height) >> 1)+font_info->ascent;
1919 (void) XDrawString(display,windows->widget.id,
1920 windows->widget.annotate_context,x,y,ColorPatternText,
1921 Extent(ColorPatternText));
1922 (void) CopyMagickString(text_info.text,glob_pattern,MagickPathExtent);
1923 XDrawWidgetText(display,&windows->widget,&text_info);
1924 XDrawBeveledButton(display,&windows->widget,&grab_info);
1925 XDrawBeveledButton(display,&windows->widget,&reset_info);
1926 XDrawBeveledMatte(display,&windows->widget,&list_info);
1927 XDrawBeveledMatte(display,&windows->widget,&scroll_info);
1928 XDrawTriangleNorth(display,&windows->widget,&north_info);
1929 XDrawBeveledButton(display,&windows->widget,&slider_info);
1930 XDrawTriangleSouth(display,&windows->widget,&south_info);
1932 y=reply_info.y+(int) ((reply_info.height-height) >> 1)+
1934 (void) XDrawString(display,windows->widget.id,
1935 windows->widget.annotate_context,x,y,ColornameText,
1936 Extent(ColornameText));
1937 XDrawBeveledMatte(display,&windows->widget,&reply_info);
1938 XDrawMatteText(display,&windows->widget,&reply_info);
1939 XDrawBeveledButton(display,&windows->widget,&action_info);
1940 XDrawBeveledButton(display,&windows->widget,&cancel_info);
1941 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
1942 selection_info.id=(~0);
1943 state|=RedrawActionState;
1944 state|=RedrawListState;
1945 state&=(
unsigned int) (~RedrawWidgetState);
1947 if (state & UpdateListState)
1955 status=XParseColor(display,windows->widget.map_info->colormap,
1956 glob_pattern,&color);
1957 if ((status != False) || (strchr(glob_pattern,
'-') != (
char *) NULL))
1962 (void) CopyMagickString(reply,glob_pattern,MagickPathExtent);
1963 (void) CopyMagickString(glob_pattern,reset_pattern,MagickPathExtent);
1964 action_info.raised=MagickFalse;
1965 XDrawBeveledButton(display,&windows->widget,&action_info);
1971 checklist=GetColorList(glob_pattern,&number_colors,exception);
1972 if (number_colors == 0)
1974 (void) CopyMagickString(glob_pattern,reset_pattern,MagickPathExtent);
1975 (void) XBell(display,0);
1979 for (i=0; i < (int) colors; i++)
1980 colorlist[i]=DestroyString(colorlist[i]);
1981 if (colorlist != (
char **) NULL)
1982 colorlist=(
char **) RelinquishMagickMemory(colorlist);
1983 colorlist=checklist;
1984 colors=number_colors;
1989 slider_info.height=(
unsigned int) ((
int) scroll_info.height-
1990 ((slider_info.min_y-scroll_info.y+1) << 1)+1);
1991 if (colors > visible_colors)
1992 slider_info.height=(
unsigned int) ((visible_colors*
1993 slider_info.height)/colors);
1994 slider_info.max_y=south_info.y-(int) south_info.bevel_width-
1995 (
int) slider_info.bevel_width-2;
1997 slider_info.y=slider_info.min_y;
1998 expose_info.y=slider_info.y;
1999 selection_info.id=(~0);
2001 state|=RedrawListState;
2005 *reply_info.text=
'\0';
2006 reply_info.cursor=reply_info.text;
2007 (void) CopyMagickString(text_info.text,glob_pattern,MagickPathExtent);
2008 XDrawWidgetText(display,&windows->widget,&text_info);
2009 XDrawMatteText(display,&windows->widget,&reply_info);
2010 XDrawBeveledMatte(display,&windows->widget,&scroll_info);
2011 XDrawTriangleNorth(display,&windows->widget,&north_info);
2012 XDrawBeveledButton(display,&windows->widget,&slider_info);
2013 XDrawTriangleSouth(display,&windows->widget,&south_info);
2014 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
2015 state&=(
unsigned int) (~UpdateListState);
2017 if (state & JumpListState)
2023 for (i=0; i < (int) colors; i++)
2024 if (LocaleCompare(colorlist[i],reply) >= 0)
2026 list_info.id=LocaleCompare(colorlist[i],reply) == 0 ? i : ~0;
2029 if ((i < slider_info.id) ||
2030 (i >= (
int) (slider_info.id+(
int) visible_colors)))
2031 slider_info.id=i-(int) (visible_colors >> 1);
2032 selection_info.id=(~0);
2033 state|=RedrawListState;
2034 state&=(
unsigned int) (~JumpListState);
2036 if (state & RedrawListState)
2041 if (slider_info.id >= (
int) (colors-visible_colors))
2042 slider_info.id=(int) (colors-visible_colors);
2043 if ((slider_info.id < 0) || (colors <= visible_colors))
2045 slider_info.y=slider_info.min_y;
2047 slider_info.y+=(int) slider_info.id*(slider_info.max_y-
2048 slider_info.min_y+1)/(int) colors;
2049 if (slider_info.id != selection_info.id)
2054 selection_info.id=slider_info.id;
2055 selection_info.y=list_info.y+(int) (height >> 3)+2;
2056 for (i=0; i < (int) visible_colors; i++)
2058 selection_info.raised=(slider_info.id+i) != list_info.id ?
2059 MagickTrue : MagickFalse;
2060 selection_info.text=(
char *) NULL;
2061 if ((slider_info.id+i) < (
int) colors)
2062 selection_info.text=colorlist[slider_info.id+i];
2063 XDrawWidgetText(display,&windows->widget,&selection_info);
2064 selection_info.y+=(int) selection_info.height;
2069 if (slider_info.y > expose_info.y)
2071 expose_info.height=(
unsigned int) (slider_info.y-expose_info.y);
2072 expose_info.y=slider_info.y-(int) expose_info.height-(
int)
2073 slider_info.bevel_width-1;
2077 expose_info.height=(
unsigned int) (expose_info.y-slider_info.y);
2078 expose_info.y=slider_info.y+(int) slider_info.height+(
int)
2079 slider_info.bevel_width+1;
2081 XDrawTriangleNorth(display,&windows->widget,&north_info);
2082 XDrawMatte(display,&windows->widget,&expose_info);
2083 XDrawBeveledButton(display,&windows->widget,&slider_info);
2084 XDrawTriangleSouth(display,&windows->widget,&south_info);
2085 expose_info.y=slider_info.y;
2087 state&=(
unsigned int) (~RedrawListState);
2089 if (state & RedrawActionState)
2092 colorname[MagickPathExtent];
2097 color=windows->widget.pixel_info->matte_color;
2098 (void) XParseColor(display,windows->widget.map_info->colormap,
2099 reply_info.text,&windows->widget.pixel_info->matte_color);
2100 XBestPixel(display,windows->widget.map_info->colormap,(XColor *) NULL,
2101 (
unsigned int) windows->widget.visual_info->colormap_size,
2102 &windows->widget.pixel_info->matte_color);
2103 mode_info.text=colorname;
2104 (void) FormatLocaleString(mode_info.text,MagickPathExtent,
2105 "#%02x%02x%02x",windows->widget.pixel_info->matte_color.red,
2106 windows->widget.pixel_info->matte_color.green,
2107 windows->widget.pixel_info->matte_color.blue);
2108 XDrawBeveledButton(display,&windows->widget,&mode_info);
2109 windows->widget.pixel_info->matte_color=color;
2110 state&=(
unsigned int) (~RedrawActionState);
2115 if (north_info.raised && south_info.raised)
2116 (void) XIfEvent(display,&event,XScreenEvent,(
char *) windows);
2122 XDelay(display,delay);
2124 (void) XCheckIfEvent(display,&event,XScreenEvent,(
char *) windows);
2125 if (north_info.raised == MagickFalse)
2126 if (slider_info.id > 0)
2132 state|=RedrawListState;
2134 if (south_info.raised == MagickFalse)
2135 if (slider_info.id < (
int) colors)
2141 state|=RedrawListState;
2143 if (event.type != ButtonRelease)
2150 if (MatteIsActive(slider_info,event.xbutton))
2155 slider_info.active=MagickTrue;
2158 if (MatteIsActive(north_info,event.xbutton))
2159 if (slider_info.id > 0)
2164 north_info.raised=MagickFalse;
2166 state|=RedrawListState;
2169 if (MatteIsActive(south_info,event.xbutton))
2170 if (slider_info.id < (
int) colors)
2175 south_info.raised=MagickFalse;
2177 state|=RedrawListState;
2180 if (MatteIsActive(scroll_info,event.xbutton))
2185 if (event.xbutton.y < slider_info.y)
2186 slider_info.id-=(int) (visible_colors-1);
2188 slider_info.id+=(int) (visible_colors-1);
2189 state|=RedrawListState;
2192 if (MatteIsActive(list_info,event.xbutton))
2200 id=slider_info.id+(
event.xbutton.y-(list_info.y+(int)
2201 (height >> 1))+1)/(
int) selection_info.height;
2202 if (
id >= (
int) colors)
2204 (void) CopyMagickString(reply_info.text,colorlist[
id],
2206 reply_info.highlight=MagickFalse;
2207 reply_info.marker=reply_info.text;
2208 reply_info.cursor=reply_info.text+Extent(reply_info.text);
2209 XDrawMatteText(display,&windows->widget,&reply_info);
2210 state|=RedrawActionState;
2211 if (
id == list_info.id)
2213 (void) CopyMagickString(glob_pattern,reply_info.text,
2215 state|=UpdateListState;
2217 selection_info.id=(~0);
2219 state|=RedrawListState;
2222 if (MatteIsActive(grab_info,event.xbutton))
2227 grab_info.raised=MagickFalse;
2228 XDrawBeveledButton(display,&windows->widget,&grab_info);
2231 if (MatteIsActive(reset_info,event.xbutton))
2236 reset_info.raised=MagickFalse;
2237 XDrawBeveledButton(display,&windows->widget,&reset_info);
2240 if (MatteIsActive(mode_info,event.xbutton))
2245 if (mode_info.text != (
char *) NULL)
2246 (void) CopyMagickString(reply_info.text,mode_info.text,
2248 (void) CopyMagickString(primary_selection,reply_info.text,
2250 (void) XSetSelectionOwner(display,XA_PRIMARY,windows->widget.id,
2251 event.xbutton.time);
2252 reply_info.highlight=XGetSelectionOwner(display,XA_PRIMARY) ==
2253 windows->widget.id ? MagickTrue : MagickFalse;
2254 reply_info.marker=reply_info.text;
2255 reply_info.cursor=reply_info.text+Extent(reply_info.text);
2256 XDrawMatteText(display,&windows->widget,&reply_info);
2259 if (MatteIsActive(action_info,event.xbutton))
2264 action_info.raised=MagickFalse;
2265 XDrawBeveledButton(display,&windows->widget,&action_info);
2268 if (MatteIsActive(cancel_info,event.xbutton))
2273 cancel_info.raised=MagickFalse;
2274 XDrawBeveledButton(display,&windows->widget,&cancel_info);
2277 if (MatteIsActive(reply_info,event.xbutton) == MagickFalse)
2279 if (event.xbutton.button != Button2)
2287 x=
event.xbutton.x-reply_info.x-(int) (QuantumMargin >> 2);
2288 for (i=1; i <= Extent(reply_info.marker); i++)
2289 if (XTextWidth(font_info,reply_info.marker,i) > x)
2291 reply_info.cursor=reply_info.marker+i-1;
2292 if (event.xbutton.time > (click_time+(
unsigned long) DoubleClick))
2293 reply_info.highlight=MagickFalse;
2299 (void) CopyMagickString(primary_selection,reply_info.text,
2301 (void) XSetSelectionOwner(display,XA_PRIMARY,windows->widget.id,
2302 event.xbutton.time);
2303 reply_info.highlight=XGetSelectionOwner(display,XA_PRIMARY) ==
2304 windows->widget.id ? MagickTrue : MagickFalse;
2306 XDrawMatteText(display,&windows->widget,&reply_info);
2307 click_time=
event.xbutton.time;
2313 (void) XConvertSelection(display,XA_PRIMARY,XA_STRING,XA_STRING,
2314 windows->widget.id,event.xbutton.time);
2319 if (windows->widget.mapped == MagickFalse)
2321 if (north_info.raised == MagickFalse)
2326 delay=SuspendTime << 2;
2327 north_info.raised=MagickTrue;
2328 XDrawTriangleNorth(display,&windows->widget,&north_info);
2330 if (south_info.raised == MagickFalse)
2335 delay=SuspendTime << 2;
2336 south_info.raised=MagickTrue;
2337 XDrawTriangleSouth(display,&windows->widget,&south_info);
2339 if (slider_info.active)
2344 slider_info.active=MagickFalse;
2347 if (grab_info.raised == MagickFalse)
2349 if (event.xbutton.window == windows->widget.id)
2350 if (MatteIsActive(grab_info,event.xbutton))
2355 (void) XGetWindowColor(display,windows,reply_info.text,
2357 reply_info.marker=reply_info.text;
2358 reply_info.cursor=reply_info.text+Extent(reply_info.text);
2359 XDrawMatteText(display,&windows->widget,&reply_info);
2360 state|=RedrawActionState;
2362 grab_info.raised=MagickTrue;
2363 XDrawBeveledButton(display,&windows->widget,&grab_info);
2365 if (reset_info.raised == MagickFalse)
2367 if (event.xbutton.window == windows->widget.id)
2368 if (MatteIsActive(reset_info,event.xbutton))
2370 (void) CopyMagickString(glob_pattern,reset_pattern,
2372 state|=UpdateListState;
2374 reset_info.raised=MagickTrue;
2375 XDrawBeveledButton(display,&windows->widget,&reset_info);
2377 if (action_info.raised == MagickFalse)
2379 if (event.xbutton.window == windows->widget.id)
2381 if (MatteIsActive(action_info,event.xbutton))
2383 if (*reply_info.text ==
'\0')
2384 (void) XBell(display,0);
2389 action_info.raised=MagickTrue;
2390 XDrawBeveledButton(display,&windows->widget,&action_info);
2392 if (cancel_info.raised == MagickFalse)
2394 if (event.xbutton.window == windows->widget.id)
2395 if (MatteIsActive(cancel_info,event.xbutton))
2397 *reply_info.text=
'\0';
2400 cancel_info.raised=MagickTrue;
2401 XDrawBeveledButton(display,&windows->widget,&cancel_info);
2403 if (MatteIsActive(reply_info,event.xbutton) == MagickFalse)
2412 if (event.xclient.message_type != windows->wm_protocols)
2414 if (*event.xclient.data.l == (
int) windows->wm_take_focus)
2416 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
2417 (Time) event.xclient.data.l[1]);
2420 if (*event.xclient.data.l != (
int) windows->wm_delete_window)
2422 if (event.xclient.window == windows->widget.id)
2424 *reply_info.text=
'\0';
2430 case ConfigureNotify:
2435 if (event.xconfigure.window != windows->widget.id)
2437 if ((event.xconfigure.width == (
int) windows->widget.width) &&
2438 (event.xconfigure.height == (
int) windows->widget.height))
2440 windows->widget.width=(
unsigned int)
2441 MagickMax(event.xconfigure.width,(
int) windows->widget.min_width);
2442 windows->widget.height=(
unsigned int)
2443 MagickMax(event.xconfigure.height,(
int) windows->widget.min_height);
2444 state|=UpdateConfigurationState;
2449 if (event.xcrossing.window != windows->widget.id)
2451 state&=(
unsigned int) (~InactiveWidgetState);
2456 if (event.xexpose.window != windows->widget.id)
2458 if (event.xexpose.count != 0)
2460 state|=RedrawWidgetState;
2466 command[MagickPathExtent];
2477 if (event.xkey.window != windows->widget.id)
2479 length=XLookupString((XKeyEvent *) &event.xkey,command,
2480 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
2481 *(command+length)=
'\0';
2482 if (AreaIsActive(scroll_info,event.xkey))
2487 switch ((
int) key_symbol)
2510 slider_info.id-=(int) visible_colors;
2516 slider_info.id+=(int) visible_colors;
2522 slider_info.id=(int) colors;
2526 state|=RedrawListState;
2529 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
2534 if (*reply_info.text ==
'\0')
2536 (void) CopyMagickString(glob_pattern,reply_info.text,MagickPathExtent);
2537 state|=UpdateListState;
2540 if (key_symbol == XK_Control_L)
2542 state|=ControlState;
2545 if (state & ControlState)
2546 switch ((
int) key_symbol)
2554 *reply_info.text=
'\0';
2555 reply_info.cursor=reply_info.text;
2556 reply_info.marker=reply_info.text;
2557 reply_info.highlight=MagickFalse;
2563 XEditText(display,&reply_info,key_symbol,command,state);
2564 XDrawMatteText(display,&windows->widget,&reply_info);
2565 state|=JumpListState;
2566 status=XParseColor(display,windows->widget.map_info->colormap,
2567 reply_info.text,&color);
2568 if (status != False)
2569 state|=RedrawActionState;
2575 command[MagickPathExtent];
2583 if (event.xkey.window != windows->widget.id)
2585 (void) XLookupString((XKeyEvent *) &event.xkey,command,
2586 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
2587 if (key_symbol == XK_Control_L)
2588 state&=(
unsigned int) (~ControlState);
2593 if (event.xcrossing.window != windows->widget.id)
2595 state|=InactiveWidgetState;
2600 mask&=(
unsigned int) (~CWX);
2601 mask&=(
unsigned int) (~CWY);
2609 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
2610 if (slider_info.active)
2615 slider_info.y=
event.xmotion.y-(int)
2616 ((slider_info.height+slider_info.bevel_width) >> 1)+1;
2617 if (slider_info.y < slider_info.min_y)
2618 slider_info.y=slider_info.min_y;
2619 if (slider_info.y > slider_info.max_y)
2620 slider_info.y=slider_info.max_y;
2622 if (slider_info.y != slider_info.min_y)
2623 slider_info.id=(int) (((
int) colors*(slider_info.y-
2624 slider_info.min_y+1))/(slider_info.max_y-slider_info.min_y+1));
2625 state|=RedrawListState;
2628 if (state & InactiveWidgetState)
2630 if (grab_info.raised == MatteIsActive(grab_info,event.xmotion))
2635 grab_info.raised=!grab_info.raised;
2636 XDrawBeveledButton(display,&windows->widget,&grab_info);
2639 if (reset_info.raised == MatteIsActive(reset_info,event.xmotion))
2644 reset_info.raised=!reset_info.raised;
2645 XDrawBeveledButton(display,&windows->widget,&reset_info);
2648 if (action_info.raised == MatteIsActive(action_info,event.xmotion))
2653 action_info.raised=action_info.raised == MagickFalse ?
2654 MagickTrue : MagickFalse;
2655 XDrawBeveledButton(display,&windows->widget,&action_info);
2658 if (cancel_info.raised == MatteIsActive(cancel_info,event.xmotion))
2663 cancel_info.raised=cancel_info.raised == MagickFalse ?
2664 MagickTrue : MagickFalse;
2665 XDrawBeveledButton(display,&windows->widget,&cancel_info);
2670 case SelectionClear:
2672 reply_info.highlight=MagickFalse;
2673 XDrawMatteText(display,&windows->widget,&reply_info);
2676 case SelectionNotify:
2694 if (event.xselection.property == (Atom) None)
2696 status=XGetWindowProperty(display,event.xselection.requestor,
2697 event.xselection.property,0L,2047L,MagickTrue,XA_STRING,&type,
2698 &format,&length,&after,&data);
2699 if ((status != Success) || (type != XA_STRING) || (format == 32) ||
2702 if ((Extent(reply_info.text)+(
int) length) >= (MagickPathExtent-1))
2703 (void) XBell(display,0);
2709 *(data+length)=
'\0';
2710 XEditText(display,&reply_info,(KeySym) XK_Insert,(
char *) data,
2712 XDrawMatteText(display,&windows->widget,&reply_info);
2713 state|=JumpListState;
2714 state|=RedrawActionState;
2716 (void) XFree((
void *) data);
2719 case SelectionRequest:
2724 XSelectionRequestEvent
2727 if (reply_info.highlight == MagickFalse)
2732 request=(&(
event.xselectionrequest));
2733 (void) XChangeProperty(request->display,request->requestor,
2734 request->property,request->target,8,PropModeReplace,
2735 (
unsigned char *) primary_selection,Extent(primary_selection));
2736 notify.type=SelectionNotify;
2737 notify.send_event=MagickTrue;
2738 notify.display=request->display;
2739 notify.requestor=request->requestor;
2740 notify.selection=request->selection;
2741 notify.target=request->target;
2742 notify.time=request->time;
2743 if (request->property == None)
2744 notify.property=request->target;
2746 notify.property=request->property;
2747 (void) XSendEvent(request->display,request->requestor,False,
2748 NoEventMask,(XEvent *) ¬ify);
2753 }
while ((state & ExitState) == 0);
2754 XSetCursorState(display,windows,MagickFalse);
2755 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
2756 XCheckRefreshWindows(display,windows);
2760 for (i=0; i < (int) colors; i++)
2761 colorlist[i]=DestroyString(colorlist[i]);
2762 if (colorlist != (
char **) NULL)
2763 colorlist=(
char **) RelinquishMagickMemory(colorlist);
2764 exception=DestroyExceptionInfo(exception);
2765 if ((*reply ==
'\0') || (strchr(reply,
'-') != (
char *) NULL))
2767 status=XParseColor(display,windows->widget.map_info->colormap,reply,&color);
2768 if (status != False)
2770 XNoticeWidget(display,windows,
"Color is unknown to X server:",reply);
2771 (void) CopyMagickString(reply,
"gray",MagickPathExtent);
2809MagickPrivate
int XCommandWidget(Display *display,XWindows *windows,
2810 const char *
const *selections,XEvent *event)
2812#define tile_width 112
2813#define tile_height 70
2815 static const unsigned char
2818 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2819 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2820 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2821 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
2822 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00,
2823 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00,
2824 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2825 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2826 0x00, 0x00, 0x1e, 0x38, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2827 0x00, 0x00, 0x00, 0x00, 0x1e, 0xbc, 0x9f, 0x03, 0x00, 0x3e, 0x00, 0xc0,
2828 0x1f, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x1e, 0xfc, 0xff, 0x0f, 0x80, 0x3f,
2829 0x00, 0xf0, 0x1f, 0xc0, 0x0f, 0x00, 0x00, 0x00, 0x1e, 0xfc, 0xff, 0x1f,
2830 0xe0, 0x3f, 0x00, 0xfc, 0x1f, 0xf0, 0x0f, 0x00, 0x00, 0x00, 0x1e, 0xfc,
2831 0xff, 0x1f, 0xf0, 0x3f, 0x00, 0xfe, 0x1f, 0xf8, 0x0f, 0x00, 0x00, 0x00,
2832 0x1e, 0xfc, 0xfc, 0x3f, 0xf8, 0x3f, 0x00, 0xff, 0x1e, 0xfc, 0x0f, 0x00,
2833 0x00, 0x00, 0x1e, 0x7c, 0xfc, 0x3e, 0xf8, 0x3c, 0x80, 0x1f, 0x1e, 0x7c,
2834 0x0f, 0x00, 0x00, 0x00, 0x1e, 0x78, 0x78, 0x3c, 0x7c, 0x3c, 0xc0, 0x0f,
2835 0x1e, 0x3e, 0x0f, 0x00, 0x00, 0x00, 0x1e, 0x78, 0x78, 0x3c, 0x7c, 0x3c,
2836 0xc0, 0x07, 0x1e, 0x3e, 0x0f, 0x00, 0x00, 0x00, 0x1e, 0x78, 0x78, 0x3c,
2837 0x7c, 0x7c, 0xc0, 0x0f, 0x1e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x78,
2838 0x78, 0x3c, 0xfc, 0x7c, 0x80, 0x7f, 0x1e, 0x7c, 0x00, 0x00, 0x00, 0x00,
2839 0x1e, 0xf8, 0x78, 0x7c, 0xf8, 0xff, 0x00, 0xff, 0x1f, 0xf8, 0xff, 0x00,
2840 0x00, 0x00, 0x1e, 0xf8, 0x78, 0x7c, 0xf0, 0xff, 0x07, 0xfe, 0x1f, 0xf8,
2841 0xff, 0x00, 0x00, 0x00, 0x1e, 0xf8, 0x78, 0x7c, 0xf0, 0xff, 0x07, 0xf8,
2842 0x1f, 0xf0, 0xff, 0x01, 0x00, 0x00, 0x1e, 0xf8, 0x78, 0x7c, 0xc0, 0xef,
2843 0x07, 0xe0, 0x1f, 0xc0, 0xff, 0x01, 0x00, 0x00, 0x1e, 0x70, 0x40, 0x78,
2844 0x00, 0xc7, 0x07, 0x00, 0x1e, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x1e, 0x00,
2845 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00,
2846 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00,
2847 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00,
2848 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
2849 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2850 0x00, 0xc0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2851 0x00, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2852 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
2853 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x01, 0x00, 0x00, 0x00,
2854 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00,
2855 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78,
2856 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2857 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x02, 0x00,
2858 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07,
2859 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2860 0xc0, 0x0f, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2861 0x60, 0x00, 0xc0, 0x0f, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2862 0x00, 0x00, 0x78, 0x00, 0xc0, 0x8f, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00,
2863 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0xc0, 0x8f, 0x3f, 0x00, 0x00, 0x00,
2864 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0xe0, 0x9f, 0x7f, 0x00,
2865 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0xe0, 0xdf,
2866 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x78, 0x00,
2867 0xe0, 0xdf, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x0c,
2868 0x78, 0x30, 0xf0, 0xff, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e,
2869 0x00, 0x0f, 0xf8, 0x70, 0xf0, 0xff, 0x7b, 0x00, 0x00, 0x1f, 0x00, 0xe0,
2870 0x0f, 0x1e, 0x80, 0x0f, 0xf8, 0x78, 0xf0, 0xfd, 0xf9, 0x00, 0xc0, 0x1f,
2871 0x00, 0xf8, 0x0f, 0x00, 0xe0, 0x1f, 0xf8, 0x7c, 0xf0, 0xfc, 0xf9, 0x00,
2872 0xf0, 0x1f, 0x00, 0xfe, 0x0f, 0x00, 0xf0, 0x07, 0xf8, 0x3e, 0xf8, 0xfc,
2873 0xf0, 0x01, 0xf8, 0x1f, 0x00, 0xff, 0x0f, 0x1e, 0xf0, 0x03, 0xf8, 0x3f,
2874 0xf8, 0xf8, 0xf0, 0x01, 0xfc, 0x1f, 0x80, 0x7f, 0x0f, 0x1e, 0xf8, 0x00,
2875 0xf8, 0x1f, 0x78, 0x18, 0xf0, 0x01, 0x7c, 0x1e, 0xc0, 0x0f, 0x0f, 0x1e,
2876 0x7c, 0x00, 0xf0, 0x0f, 0x78, 0x00, 0xf0, 0x01, 0x3e, 0x1e, 0xe0, 0x07,
2877 0x0f, 0x1e, 0x7c, 0x00, 0xf0, 0x07, 0x7c, 0x00, 0xe0, 0x01, 0x3e, 0x1e,
2878 0xe0, 0x03, 0x0f, 0x1e, 0x3e, 0x00, 0xf0, 0x0f, 0x7c, 0x00, 0xe0, 0x03,
2879 0x3e, 0x3e, 0xe0, 0x07, 0x0f, 0x1e, 0x1e, 0x00, 0xf0, 0x1f, 0x3c, 0x00,
2880 0xe0, 0x03, 0x7e, 0x3e, 0xc0, 0x3f, 0x0f, 0x1e, 0x3e, 0x00, 0xf0, 0x1f,
2881 0x3e, 0x00, 0xe0, 0x03, 0xfc, 0x7f, 0x80, 0xff, 0x0f, 0x1e, 0xfc, 0x00,
2882 0xf0, 0x3e, 0x3e, 0x00, 0xc0, 0x03, 0xf8, 0xff, 0x03, 0xff, 0x0f, 0x1e,
2883 0xfc, 0x07, 0xf0, 0x7c, 0x1e, 0x00, 0xc0, 0x03, 0xf8, 0xff, 0x03, 0xfc,
2884 0x0f, 0x1e, 0xf8, 0x1f, 0xf0, 0xf8, 0x1e, 0x00, 0xc0, 0x03, 0xe0, 0xf7,
2885 0x03, 0xf0, 0x0f, 0x1e, 0xe0, 0x3f, 0xf0, 0x78, 0x1c, 0x00, 0x80, 0x03,
2886 0x80, 0xe3, 0x03, 0x00, 0x0f, 0x1e, 0xc0, 0x3f, 0xf0, 0x30, 0x00, 0x00,
2887 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0e, 0x00, 0x3e, 0x00, 0x00,
2888 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x0f, 0x00, 0x00, 0x10,
2889 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x0f, 0x00,
2890 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
2891 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2892 0x00, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2893 0x00, 0x00, 0x00, 0xf0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2894 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
2895 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00,
2896 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00,
2897 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c,
2898 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2899 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2921 assert(display != (Display *) NULL);
2922 assert(windows != (XWindows *) NULL);
2923 if (IsEventLogging() != MagickFalse)
2924 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
2925 font_info=windows->command.font_info;
2926 height=(
unsigned int) (font_info->ascent+font_info->descent);
2929 if (event == (XEvent *) NULL)
2943 assert(selections != (
const char **) NULL);
2944 windows->command.width=0;
2945 for (i=0; selections[i] != (
char *) NULL; i++)
2947 width=WidgetTextWidth(font_info,(
char *) selections[i]);
2948 if (width > windows->command.width)
2949 windows->command.width=width;
2951 number_selections=(
unsigned int) i;
2952 windows->command.width+=(
unsigned int) (3*QuantumMargin+10);
2953 if ((
int) windows->command.width < (tile_width+QuantumMargin+10))
2954 windows->command.width=(
unsigned int) (tile_width+QuantumMargin+10);
2955 windows->command.height=(
unsigned int) (number_selections*
2956 (((3*height) >> 1)+10)+tile_height+20);
2957 windows->command.min_width=windows->command.width;
2958 windows->command.min_height=windows->command.height;
2959 XConstrainWindowPosition(display,&windows->command);
2960 if (windows->command.id != (Window) NULL)
2968 status=XStringListToTextProperty(&windows->command.name,1,
2970 if (status != False)
2972 XSetWMName(display,windows->command.id,&window_name);
2973 XSetWMIconName(display,windows->command.id,&window_name);
2974 (void) XFree((
void *) window_name.value);
2976 window_changes.width=(int) windows->command.width;
2977 window_changes.height=(int) windows->command.height;
2978 (void) XReconfigureWMWindow(display,windows->command.id,
2979 windows->command.screen,(
unsigned int) (CWWidth | CWHeight),
2985 if (selection_info != (XWidgetInfo *) NULL)
2986 selection_info=(XWidgetInfo *) RelinquishMagickMemory(selection_info);
2987 selection_info=(XWidgetInfo *) AcquireQuantumMemory(number_selections,
2988 sizeof(*selection_info));
2989 if (selection_info == (XWidgetInfo *) NULL)
2991 ThrowXWindowFatalException(ResourceLimitFatalError,
2992 "MemoryAllocationFailed",
"...");
2995 state|=UpdateConfigurationState | RedrawWidgetState;
3000 if (event != (XEvent *) NULL)
3001 switch (event->type)
3005 for (i=0; i < (int) number_selections; i++)
3007 if (MatteIsActive(selection_info[i],event->xbutton) == MagickFalse)
3009 if (i >= (
int) windows->command.data)
3011 selection_info[i].raised=MagickFalse;
3012 XDrawBeveledButton(display,&windows->command,&selection_info[i]);
3015 submenu_info=selection_info[i];
3016 submenu_info.active=MagickTrue;
3017 toggle_info.y=submenu_info.y+(int) (submenu_info.height >> 1)-
3018 (int) (toggle_info.height >> 1);
3020 (void) XCheckWindowEvent(display,windows->widget.id,LeaveWindowMask,
3028 for (i=0; i < (int) number_selections; i++)
3030 if (MatteIsActive(selection_info[i],event->xbutton) == MagickFalse)
3033 if (
id >= (
int) windows->command.data)
3035 selection_info[id].raised=MagickTrue;
3036 XDrawBeveledButton(display,&windows->command,&selection_info[
id]);
3048 if (event->xclient.message_type != windows->wm_protocols)
3050 if (*event->xclient.data.l != (
int) windows->wm_delete_window)
3052 (void) XWithdrawWindow(display,windows->command.id,
3053 windows->command.screen);
3056 case ConfigureNotify:
3061 if (event->xconfigure.window != windows->command.id)
3063 if (event->xconfigure.send_event != 0)
3065 windows->command.x=
event->xconfigure.x;
3066 windows->command.y=
event->xconfigure.y;
3068 if ((event->xconfigure.width == (
int) windows->command.width) &&
3069 (event->xconfigure.height == (
int) windows->command.height))
3071 windows->command.width=(
unsigned int)
3072 MagickMax(event->xconfigure.width,(
int) windows->command.min_width);
3073 windows->command.height=(
unsigned int)
3074 MagickMax(event->xconfigure.height,(
int) windows->command.min_height);
3075 state|=UpdateConfigurationState;
3080 if (event->xexpose.window != windows->command.id)
3082 if (event->xexpose.count != 0)
3084 state|=RedrawWidgetState;
3094 for (i=0; i < (int) number_selections; i++)
3096 if (i >= (
int) windows->command.data)
3098 if (selection_info[i].raised ==
3099 MatteIsActive(selection_info[i],event->xmotion))
3104 selection_info[i].raised=!selection_info[i].raised;
3105 XDrawBeveledButton(display,&windows->command,
3106 &selection_info[i]);
3110 if (MatteIsActive(selection_info[i],event->xmotion) == MagickFalse)
3112 submenu_info=selection_info[i];
3113 submenu_info.active=MagickTrue;
3114 toggle_info.raised=MagickTrue;
3115 toggle_info.y=submenu_info.y+(int) (submenu_info.height >> 1)-
3116 (int) (toggle_info.height >> 1);
3117 XDrawTriangleEast(display,&windows->command,&toggle_info);
3120 XDelay(display,SuspendTime);
3121 if (XCheckMaskEvent(display,ButtonMotionMask,event) == MagickFalse)
3123 while (XCheckMaskEvent(display,ButtonMotionMask,event)) ;
3124 toggle_info.raised=MagickFalse;
3125 if (windows->command.data != 0)
3126 XDrawTriangleEast(display,&windows->command,&toggle_info);
3132 windows->command.mapped=MagickTrue;
3137 windows->command.mapped=MagickFalse;
3143 if (state & UpdateConfigurationState)
3148 assert(selections != (
const char **) NULL);
3150 for (i=0; i < (int) number_selections; i++)
3152 XGetWidgetInfo(selections[i],&selection_info[i]);
3153 selection_info[i].center=MagickFalse;
3154 selection_info[i].bevel_width--;
3155 selection_info[i].height=(
unsigned int) ((3*height) >> 1);
3156 selection_info[i].x=(QuantumMargin >> 1)+4;
3157 selection_info[i].width=(
unsigned int) ((
int) windows->command.width-
3158 (selection_info[i].x << 1));
3159 selection_info[i].y=y;
3160 y+=(int) selection_info[i].height+(
int)
3161 (selection_info[i].bevel_width << 1)+6;
3163 XGetWidgetInfo((
char *) NULL,&toggle_info);
3164 toggle_info.bevel_width--;
3165 toggle_info.width=(
unsigned int) (((5*height) >> 3)-
3166 (toggle_info.bevel_width << 1));
3167 toggle_info.height=toggle_info.width;
3168 toggle_info.x=selection_info[0].x+(int) selection_info[0].width-
3169 (
int) toggle_info.width-(int) (QuantumMargin >> 1);
3170 if (windows->command.mapped)
3171 (void) XClearWindow(display,windows->command.id);
3173 if (state & RedrawWidgetState)
3181 tile_pixmap=XCreatePixmapFromBitmapData(display,windows->command.id,
3182 (
char *) tile_bits,tile_width,tile_height,1L,0L,1);
3183 if (tile_pixmap != (Pixmap) NULL)
3185 (void) XCopyPlane(display,tile_pixmap,windows->command.id,
3186 windows->command.annotate_context,0,0,tile_width,tile_height,
3187 (
int) ((windows->command.width-tile_width) >> 1),10,1L);
3188 (void) XFreePixmap(display,tile_pixmap);
3190 for (i=0; i < (int) number_selections; i++)
3192 XDrawBeveledButton(display,&windows->command,&selection_info[i]);
3193 if (i >= (
int) windows->command.data)
3195 toggle_info.raised=MagickFalse;
3196 toggle_info.y=selection_info[i].y+(int) (selection_info[i].height >> 1)-
3197 (int) (toggle_info.height >> 1);
3198 XDrawTriangleEast(display,&windows->command,&toggle_info);
3200 XHighlightWidget(display,&windows->command,BorderOffset,BorderOffset);
3237MagickPrivate
int XConfirmWidget(Display *display,XWindows *windows,
3238 const char *reason,
const char *description)
3240#define CancelButtonText "Cancel"
3241#define DismissButtonText "Dismiss"
3242#define YesButtonText "Yes"
3279 assert(display != (Display *) NULL);
3280 assert(windows != (XWindows *) NULL);
3281 assert(reason != (
char *) NULL);
3282 assert(description != (
char *) NULL);
3283 if (IsEventLogging() != MagickFalse)
3284 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",reason);
3285 XCheckRefreshWindows(display,windows);
3286 font_info=windows->widget.font_info;
3287 width=WidgetTextWidth(font_info,CancelButtonText);
3288 if (WidgetTextWidth(font_info,DismissButtonText) > width)
3289 width=WidgetTextWidth(font_info,DismissButtonText);
3290 if (WidgetTextWidth(font_info,YesButtonText) > width)
3291 width=WidgetTextWidth(font_info,YesButtonText);
3293 if (description != (
char *) NULL)
3294 if (WidgetTextWidth(font_info,(
char *) description) > width)
3295 width=WidgetTextWidth(font_info,(
char *) description);
3296 height=(
unsigned int) (font_info->ascent+font_info->descent);
3300 windows->widget.width=(
unsigned int) ((
int) width+9*QuantumMargin);
3301 windows->widget.min_width=9*(
unsigned int) QuantumMargin+
3302 WidgetTextWidth(font_info,CancelButtonText)+
3303 WidgetTextWidth(font_info,DismissButtonText)+
3304 WidgetTextWidth(font_info,YesButtonText);
3305 if (windows->widget.width < windows->widget.min_width)
3306 windows->widget.width=windows->widget.min_width;
3307 windows->widget.height=(
unsigned int) (12*height);
3308 windows->widget.min_height=(
unsigned int) (7*height);
3309 if (windows->widget.height < windows->widget.min_height)
3310 windows->widget.height=windows->widget.min_height;
3311 XConstrainWindowPosition(display,&windows->widget);
3315 (void) CopyMagickString(windows->widget.name,
"Confirm",MagickPathExtent);
3316 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
3317 if (status != False)
3319 XSetWMName(display,windows->widget.id,&window_name);
3320 XSetWMIconName(display,windows->widget.id,&window_name);
3321 (void) XFree((
void *) window_name.value);
3323 window_changes.width=(int) windows->widget.width;
3324 window_changes.height=(int) windows->widget.height;
3325 window_changes.x=windows->widget.x;
3326 window_changes.y=windows->widget.y;
3327 (void) XReconfigureWMWindow(display,windows->widget.id,windows->widget.screen,
3328 (
unsigned int) (CWWidth | CWHeight | CWX | CWY),&window_changes);
3329 (void) XMapRaised(display,windows->widget.id);
3330 windows->widget.mapped=MagickFalse;
3335 state=UpdateConfigurationState;
3336 XSetCursorState(display,windows,MagickTrue);
3339 if (state & UpdateConfigurationState)
3344 XGetWidgetInfo(CancelButtonText,&cancel_info);
3345 cancel_info.width=(
unsigned int) QuantumMargin+
3346 WidgetTextWidth(font_info,CancelButtonText);
3347 cancel_info.height=(
unsigned int) ((3*height) >> 1);
3348 cancel_info.x=(int) windows->widget.width-(
int) cancel_info.width-
3350 cancel_info.y=(int) (windows->widget.height-(cancel_info.height << 1));
3351 dismiss_info=cancel_info;
3352 dismiss_info.text=(
char *) DismissButtonText;
3353 if (LocaleCompare(description,
"Do you want to save it") == 0)
3354 dismiss_info.text=(
char *)
"Don't Save";
3355 dismiss_info.width=(
unsigned int) QuantumMargin+
3356 WidgetTextWidth(font_info,dismiss_info.text);
3357 dismiss_info.x=(int)
3358 ((windows->widget.width >> 1)-(dismiss_info.width >> 1));
3359 yes_info=cancel_info;
3360 yes_info.text=(
char *) YesButtonText;
3361 if (LocaleCompare(description,
"Do you want to save it") == 0)
3362 yes_info.text=(
char *)
"Save";
3363 yes_info.width=(
unsigned int) QuantumMargin+
3364 WidgetTextWidth(font_info,yes_info.text);
3365 if (yes_info.width < cancel_info.width)
3366 yes_info.width=cancel_info.width;
3367 yes_info.x=QuantumMargin;
3368 state&=(
unsigned int) (~UpdateConfigurationState);
3370 if (state & RedrawWidgetState)
3375 width=WidgetTextWidth(font_info,(
char *) reason);
3376 x=(int) ((windows->widget.width >> 1)-(width >> 1));
3377 y=(int) ((windows->widget.height >> 1)-(height << 1));
3378 (void) XDrawString(display,windows->widget.id,
3379 windows->widget.annotate_context,x,y,(
char *) reason,Extent(reason));
3380 if (description != (
char *) NULL)
3383 question[MagickPathExtent];
3385 (void) CopyMagickString(question,description,MagickPathExtent);
3386 (void) ConcatenateMagickString(question,
"?",MagickPathExtent);
3387 width=WidgetTextWidth(font_info,question);
3388 x=((int) (windows->widget.width >> 1)-(int) (width >> 1));
3390 (void) XDrawString(display,windows->widget.id,
3391 windows->widget.annotate_context,x,y,question,Extent(question));
3393 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3394 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
3395 XDrawBeveledButton(display,&windows->widget,&yes_info);
3396 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
3397 state&=(
unsigned int) (~RedrawWidgetState);
3402 (void) XIfEvent(display,&event,XScreenEvent,(
char *) windows);
3407 if (MatteIsActive(cancel_info,event.xbutton))
3412 cancel_info.raised=MagickFalse;
3413 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3416 if (MatteIsActive(dismiss_info,event.xbutton))
3421 dismiss_info.raised=MagickFalse;
3422 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
3425 if (MatteIsActive(yes_info,event.xbutton))
3430 yes_info.raised=MagickFalse;
3431 XDrawBeveledButton(display,&windows->widget,&yes_info);
3438 if (windows->widget.mapped == MagickFalse)
3440 if (cancel_info.raised == MagickFalse)
3442 if (event.xbutton.window == windows->widget.id)
3443 if (MatteIsActive(cancel_info,event.xbutton))
3448 cancel_info.raised=MagickTrue;
3449 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3451 if (dismiss_info.raised == MagickFalse)
3453 if (event.xbutton.window == windows->widget.id)
3454 if (MatteIsActive(dismiss_info,event.xbutton))
3459 dismiss_info.raised=MagickTrue;
3460 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
3462 if (yes_info.raised == MagickFalse)
3464 if (event.xbutton.window == windows->widget.id)
3465 if (MatteIsActive(yes_info,event.xbutton))
3470 yes_info.raised=MagickTrue;
3471 XDrawBeveledButton(display,&windows->widget,&yes_info);
3480 if (event.xclient.message_type != windows->wm_protocols)
3482 if (*event.xclient.data.l == (
int) windows->wm_take_focus)
3484 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
3485 (Time) event.xclient.data.l[1]);
3488 if (*event.xclient.data.l != (
int) windows->wm_delete_window)
3490 if (event.xclient.window == windows->widget.id)
3497 case ConfigureNotify:
3502 if (event.xconfigure.window != windows->widget.id)
3504 if ((event.xconfigure.width == (
int) windows->widget.width) &&
3505 (event.xconfigure.height == (
int) windows->widget.height))
3507 windows->widget.width=(
unsigned int)
3508 MagickMax(event.xconfigure.width,(
int) windows->widget.min_width);
3509 windows->widget.height=(
unsigned int)
3510 MagickMax(event.xconfigure.height,(
int) windows->widget.min_height);
3511 state|=UpdateConfigurationState;
3516 if (event.xcrossing.window != windows->widget.id)
3518 state&=(
unsigned int) (~InactiveWidgetState);
3523 if (event.xexpose.window != windows->widget.id)
3525 if (event.xexpose.count != 0)
3527 state|=RedrawWidgetState;
3533 command[MagickPathExtent];
3541 if (event.xkey.window != windows->widget.id)
3543 (void) XLookupString((XKeyEvent *) &event.xkey,command,
3544 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
3545 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
3547 yes_info.raised=MagickFalse;
3548 XDrawBeveledButton(display,&windows->widget,&yes_info);
3557 if (event.xcrossing.window != windows->widget.id)
3559 state|=InactiveWidgetState;
3567 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
3568 if (state & InactiveWidgetState)
3570 if (cancel_info.raised == MatteIsActive(cancel_info,event.xmotion))
3575 cancel_info.raised=cancel_info.raised == MagickFalse ?
3576 MagickTrue : MagickFalse;
3577 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3580 if (dismiss_info.raised == MatteIsActive(dismiss_info,event.xmotion))
3585 dismiss_info.raised=dismiss_info.raised == MagickFalse ?
3586 MagickTrue : MagickFalse;
3587 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
3590 if (yes_info.raised == MatteIsActive(yes_info,event.xmotion))
3595 yes_info.raised=yes_info.raised == MagickFalse ?
3596 MagickTrue : MagickFalse;
3597 XDrawBeveledButton(display,&windows->widget,&yes_info);
3605 }
while ((state & ExitState) == 0);
3606 XSetCursorState(display,windows,MagickFalse);
3607 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
3608 XCheckRefreshWindows(display,windows);
3646MagickPrivate
int XDialogWidget(Display *display,XWindows *windows,
3647 const char *action,
const char *query,
char *reply)
3649#define CancelButtonText "Cancel"
3652 primary_selection[MagickPathExtent];
3660 static MagickBooleanType
3661 raised = MagickFalse;
3696 assert(display != (Display *) NULL);
3697 assert(windows != (XWindows *) NULL);
3698 assert(action != (
char *) NULL);
3699 assert(query != (
char *) NULL);
3700 assert(reply != (
char *) NULL);
3701 if (IsEventLogging() != MagickFalse)
3702 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",action);
3703 XCheckRefreshWindows(display,windows);
3704 font_info=windows->widget.font_info;
3705 width=WidgetTextWidth(font_info,(
char *) action);
3706 if (WidgetTextWidth(font_info,CancelButtonText) > width)
3707 width=WidgetTextWidth(font_info,CancelButtonText);
3708 width+=(
unsigned int) (3*QuantumMargin) >> 1;
3709 height=(
unsigned int) (font_info->ascent+font_info->descent);
3713 windows->widget.width=(
unsigned int) MagickMax((
int) (2*width),(
int)
3714 WidgetTextWidth(font_info,(
char *) query));
3715 if (windows->widget.width < WidgetTextWidth(font_info,reply))
3716 windows->widget.width=WidgetTextWidth(font_info,reply);
3717 windows->widget.width+=(
unsigned int) (6*QuantumMargin);
3718 windows->widget.min_width=(
unsigned int)
3719 ((
int) width+28*XTextWidth(font_info,
"#",1)+4*QuantumMargin);
3720 if (windows->widget.width < windows->widget.min_width)
3721 windows->widget.width=windows->widget.min_width;
3722 windows->widget.height=(
unsigned int) (7*(
int) height+(QuantumMargin << 1));
3723 windows->widget.min_height=windows->widget.height;
3724 if (windows->widget.height < windows->widget.min_height)
3725 windows->widget.height=windows->widget.min_height;
3726 XConstrainWindowPosition(display,&windows->widget);
3730 (void) CopyMagickString(windows->widget.name,
"Dialog",MagickPathExtent);
3731 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
3732 if (status != False)
3734 XSetWMName(display,windows->widget.id,&window_name);
3735 XSetWMIconName(display,windows->widget.id,&window_name);
3736 (void) XFree((
void *) window_name.value);
3738 window_changes.width=(int) windows->widget.width;
3739 window_changes.height=(int) windows->widget.height;
3740 window_changes.x=windows->widget.x;
3741 window_changes.y=windows->widget.y;
3742 (void) XReconfigureWMWindow(display,windows->widget.id,windows->widget.screen,
3743 (
unsigned int) (CWWidth | CWHeight | CWX | CWY),&window_changes);
3744 (void) XMapRaised(display,windows->widget.id);
3745 windows->widget.mapped=MagickFalse;
3749 anomaly=(LocaleCompare(action,
"Background") == 0) ||
3750 (LocaleCompare(action,
"New") == 0) ||
3751 (LocaleCompare(action,
"Quantize") == 0) ||
3752 (LocaleCompare(action,
"Resize") == 0) ||
3753 (LocaleCompare(action,
"Save") == 0) ||
3754 (LocaleCompare(action,
"Shade") == 0);
3755 state=UpdateConfigurationState;
3756 XSetCursorState(display,windows,MagickTrue);
3759 if (state & UpdateConfigurationState)
3764 XGetWidgetInfo(CancelButtonText,&cancel_info);
3765 cancel_info.width=width;
3766 cancel_info.height=(
unsigned int) ((3*height) >> 1);
3767 cancel_info.x=(int) windows->widget.width-(
int) cancel_info.width-
3768 ((3*QuantumMargin) >> 1);
3769 cancel_info.y=(int) windows->widget.height-(
int) cancel_info.height-
3770 ((3*QuantumMargin) >> 1);
3771 XGetWidgetInfo(action,&action_info);
3772 action_info.width=width;
3773 action_info.height=(
unsigned int) ((3*height) >> 1);
3774 action_info.x=cancel_info.x-((int) cancel_info.width+QuantumMargin+
3775 (int) (action_info.bevel_width << 1));
3776 action_info.y=cancel_info.y;
3780 XGetWidgetInfo(reply,&reply_info);
3781 reply_info.raised=MagickFalse;
3782 reply_info.bevel_width--;
3783 reply_info.width=(
unsigned int) ((
int) windows->widget.width-
3785 reply_info.height=height << 1;
3786 reply_info.x=(3*QuantumMargin) >> 1;
3787 reply_info.y=action_info.y-(int) reply_info.height-QuantumMargin;
3791 XGetWidgetInfo(
"Dither",&special_info);
3792 special_info.raised=raised;
3793 special_info.bevel_width--;
3794 special_info.width=(
unsigned int) QuantumMargin >> 1;
3795 special_info.height=(
unsigned int) QuantumMargin >> 1;
3796 special_info.x=reply_info.x;
3797 special_info.y=action_info.y+(int) action_info.height-(
int)
3798 special_info.height;
3799 if (LocaleCompare(action,
"Background") == 0)
3800 special_info.text=(
char *)
"Backdrop";
3801 if (LocaleCompare(action,
"New") == 0)
3802 special_info.text=(
char *)
"Gradation";
3803 if (LocaleCompare(action,
"Resize") == 0)
3804 special_info.text=(
char *)
"Constrain ratio";
3805 if (LocaleCompare(action,
"Save") == 0)
3806 special_info.text=(
char *)
"Non-progressive";
3807 if (LocaleCompare(action,
"Shade") == 0)
3808 special_info.text=(
char *)
"Color shading";
3812 XGetWidgetInfo(query,&text_info);
3813 text_info.width=reply_info.width;
3814 text_info.height=height;
3815 text_info.x=reply_info.x-(int) (QuantumMargin >> 1);
3816 text_info.y=QuantumMargin;
3817 text_info.center=MagickFalse;
3818 state&=(
unsigned int) (~UpdateConfigurationState);
3820 if (state & RedrawWidgetState)
3825 XDrawWidgetText(display,&windows->widget,&text_info);
3826 XDrawBeveledMatte(display,&windows->widget,&reply_info);
3827 XDrawMatteText(display,&windows->widget,&reply_info);
3829 XDrawBeveledButton(display,&windows->widget,&special_info);
3830 XDrawBeveledButton(display,&windows->widget,&action_info);
3831 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3832 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
3833 state&=(
unsigned int) (~RedrawWidgetState);
3838 (void) XIfEvent(display,&event,XScreenEvent,(
char *) windows);
3844 if (MatteIsActive(special_info,event.xbutton))
3849 special_info.raised=!special_info.raised;
3850 XDrawBeveledButton(display,&windows->widget,&special_info);
3853 if (MatteIsActive(action_info,event.xbutton))
3858 action_info.raised=MagickFalse;
3859 XDrawBeveledButton(display,&windows->widget,&action_info);
3862 if (MatteIsActive(cancel_info,event.xbutton))
3867 cancel_info.raised=MagickFalse;
3868 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3871 if (MatteIsActive(reply_info,event.xbutton) == MagickFalse)
3873 if (event.xbutton.button != Button2)
3881 x=
event.xbutton.x-reply_info.x-(int) (QuantumMargin >> 2);
3882 for (i=1; i <= Extent(reply_info.marker); i++)
3883 if (XTextWidth(font_info,reply_info.marker,i) > x)
3885 reply_info.cursor=reply_info.marker+i-1;
3886 if (event.xbutton.time > (click_time+(
unsigned long) DoubleClick))
3887 reply_info.highlight=MagickFalse;
3893 (void) CopyMagickString(primary_selection,reply_info.text,
3895 (void) XSetSelectionOwner(display,XA_PRIMARY,windows->widget.id,
3896 event.xbutton.time);
3897 reply_info.highlight=XGetSelectionOwner(display,XA_PRIMARY) ==
3898 windows->widget.id ? MagickTrue : MagickFalse;
3900 XDrawMatteText(display,&windows->widget,&reply_info);
3901 click_time=
event.xbutton.time;
3907 (void) XConvertSelection(display,XA_PRIMARY,XA_STRING,XA_STRING,
3908 windows->widget.id,event.xbutton.time);
3913 if (windows->widget.mapped == MagickFalse)
3915 if (action_info.raised == MagickFalse)
3917 if (event.xbutton.window == windows->widget.id)
3918 if (MatteIsActive(action_info,event.xbutton))
3920 action_info.raised=MagickTrue;
3921 XDrawBeveledButton(display,&windows->widget,&action_info);
3923 if (cancel_info.raised == MagickFalse)
3925 if (event.xbutton.window == windows->widget.id)
3926 if (MatteIsActive(cancel_info,event.xbutton))
3928 *reply_info.text=
'\0';
3931 cancel_info.raised=MagickTrue;
3932 XDrawBeveledButton(display,&windows->widget,&cancel_info);
3941 if (event.xclient.message_type != windows->wm_protocols)
3943 if (*event.xclient.data.l == (
int) windows->wm_take_focus)
3945 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
3946 (Time) event.xclient.data.l[1]);
3949 if (*event.xclient.data.l != (
int) windows->wm_delete_window)
3951 if (event.xclient.window == windows->widget.id)
3953 *reply_info.text=
'\0';
3959 case ConfigureNotify:
3964 if (event.xconfigure.window != windows->widget.id)
3966 if ((event.xconfigure.width == (
int) windows->widget.width) &&
3967 (event.xconfigure.height == (
int) windows->widget.height))
3969 windows->widget.width=(
unsigned int)
3970 MagickMax(event.xconfigure.width,(
int) windows->widget.min_width);
3971 windows->widget.height=(
unsigned int)
3972 MagickMax(event.xconfigure.height,(
int) windows->widget.min_height);
3973 state|=UpdateConfigurationState;
3978 if (event.xcrossing.window != windows->widget.id)
3980 state&=(
unsigned int) (~InactiveWidgetState);
3985 if (event.xexpose.window != windows->widget.id)
3987 if (event.xexpose.count != 0)
3989 state|=RedrawWidgetState;
3995 command[MagickPathExtent];
4006 if (event.xkey.window != windows->widget.id)
4008 length=XLookupString((XKeyEvent *) &event.xkey,command,
4009 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
4010 *(command+length)=
'\0';
4011 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
4013 action_info.raised=MagickFalse;
4014 XDrawBeveledButton(display,&windows->widget,&action_info);
4018 if (key_symbol == XK_Control_L)
4020 state|=ControlState;
4023 if (state & ControlState)
4024 switch ((
int) key_symbol)
4032 *reply_info.text=
'\0';
4033 reply_info.cursor=reply_info.text;
4034 reply_info.marker=reply_info.text;
4035 reply_info.highlight=MagickFalse;
4041 XEditText(display,&reply_info,key_symbol,command,state);
4042 XDrawMatteText(display,&windows->widget,&reply_info);
4048 command[MagickPathExtent];
4056 if (event.xkey.window != windows->widget.id)
4058 (void) XLookupString((XKeyEvent *) &event.xkey,command,
4059 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
4060 if (key_symbol == XK_Control_L)
4061 state&=(
unsigned int) (~ControlState);
4066 if (event.xcrossing.window != windows->widget.id)
4068 state|=InactiveWidgetState;
4076 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
4077 if (state & InactiveWidgetState)
4079 if (action_info.raised == MatteIsActive(action_info,event.xmotion))
4084 action_info.raised=action_info.raised == MagickFalse ?
4085 MagickTrue : MagickFalse;
4086 XDrawBeveledButton(display,&windows->widget,&action_info);
4089 if (cancel_info.raised == MatteIsActive(cancel_info,event.xmotion))
4094 cancel_info.raised=cancel_info.raised == MagickFalse ?
4095 MagickTrue : MagickFalse;
4096 XDrawBeveledButton(display,&windows->widget,&cancel_info);
4101 case SelectionClear:
4103 reply_info.highlight=MagickFalse;
4104 XDrawMatteText(display,&windows->widget,&reply_info);
4107 case SelectionNotify:
4125 if (event.xselection.property == (Atom) None)
4127 status=XGetWindowProperty(display,event.xselection.requestor,
4128 event.xselection.property,0L,2047L,MagickTrue,XA_STRING,&type,
4129 &format,&length,&after,&data);
4130 if ((status != Success) || (type != XA_STRING) || (format == 32) ||
4133 if ((Extent(reply_info.text)+(
int) length) >= (MagickPathExtent-1))
4134 (void) XBell(display,0);
4140 *(data+length)=
'\0';
4141 XEditText(display,&reply_info,(KeySym) XK_Insert,(
char *) data,
4143 XDrawMatteText(display,&windows->widget,&reply_info);
4145 (void) XFree((
void *) data);
4148 case SelectionRequest:
4153 XSelectionRequestEvent
4156 if (reply_info.highlight == MagickFalse)
4161 request=(&(
event.xselectionrequest));
4162 (void) XChangeProperty(request->display,request->requestor,
4163 request->property,request->target,8,PropModeReplace,
4164 (
unsigned char *) primary_selection,Extent(primary_selection));
4165 notify.type=SelectionNotify;
4166 notify.display=request->display;
4167 notify.requestor=request->requestor;
4168 notify.selection=request->selection;
4169 notify.target=request->target;
4170 notify.time=request->time;
4171 if (request->property == None)
4172 notify.property=request->target;
4174 notify.property=request->property;
4175 (void) XSendEvent(request->display,request->requestor,False,0,
4176 (XEvent *) ¬ify);
4181 }
while ((state & ExitState) == 0);
4182 XSetCursorState(display,windows,MagickFalse);
4183 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
4184 XCheckRefreshWindows(display,windows);
4186 if (special_info.raised)
4189 return(raised == MagickFalse);
4224MagickPrivate
void XFileBrowserWidget(Display *display,XWindows *windows,
4225 const char *action,
char *reply)
4227#define CancelButtonText "Cancel"
4228#define DirectoryText "Directory:"
4229#define FilenameText "File name:"
4230#define GrabButtonText "Grab"
4231#define FormatButtonText "Format"
4232#define HomeButtonText "Home"
4233#define UpButtonText "Up"
4238 home_directory[MagickPathExtent],
4239 primary_selection[MagickPathExtent],
4240 text[MagickPathExtent],
4241 working_path[MagickPathExtent];
4248 glob_pattern[MagickPathExtent] =
"*",
4249 format[MagickPathExtent] =
"miff";
4251 static MagickStatusType
4252 mask = (MagickStatusType) (CWWidth | CWHeight | CWX | CWY);
4303 assert(display != (Display *) NULL);
4304 assert(windows != (XWindows *) NULL);
4305 assert(action != (
char *) NULL);
4306 assert(reply != (
char *) NULL);
4307 if (IsEventLogging() != MagickFalse)
4308 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",action);
4309 XSetCursorState(display,windows,MagickTrue);
4310 XCheckRefreshWindows(display,windows);
4311 directory=getcwd(home_directory,MagickPathExtent);
4313 (void) CopyMagickString(working_path,home_directory,MagickPathExtent);
4314 filelist=ListFiles(working_path,glob_pattern,&files);
4315 if (filelist == (
char **) NULL)
4320 XNoticeWidget(display,windows,
"Unable to read directory:",working_path);
4321 (void) XDialogWidget(display,windows,action,
"Enter filename:",reply);
4327 font_info=windows->widget.font_info;
4329 for (i=0; i < (ssize_t) files; i++)
4330 if (WidgetTextWidth(font_info,filelist[i]) > text_width)
4331 text_width=WidgetTextWidth(font_info,filelist[i]);
4332 width=WidgetTextWidth(font_info,(
char *) action);
4333 if (WidgetTextWidth(font_info,GrabButtonText) > width)
4334 width=WidgetTextWidth(font_info,GrabButtonText);
4335 if (WidgetTextWidth(font_info,FormatButtonText) > width)
4336 width=WidgetTextWidth(font_info,FormatButtonText);
4337 if (WidgetTextWidth(font_info,CancelButtonText) > width)
4338 width=WidgetTextWidth(font_info,CancelButtonText);
4339 if (WidgetTextWidth(font_info,HomeButtonText) > width)
4340 width=WidgetTextWidth(font_info,HomeButtonText);
4341 if (WidgetTextWidth(font_info,UpButtonText) > width)
4342 width=WidgetTextWidth(font_info,UpButtonText);
4343 width+=(
unsigned int) QuantumMargin;
4344 if (WidgetTextWidth(font_info,DirectoryText) > width)
4345 width=WidgetTextWidth(font_info,DirectoryText);
4346 if (WidgetTextWidth(font_info,FilenameText) > width)
4347 width=WidgetTextWidth(font_info,FilenameText);
4348 height=(
unsigned int) (font_info->ascent+font_info->descent);
4352 windows->widget.width=width+MagickMin(text_width,MaxTextWidth)+
4353 (
unsigned int) (6*QuantumMargin);
4354 windows->widget.min_width=width+MinTextWidth+(
unsigned int) (4*QuantumMargin);
4355 if (windows->widget.width < windows->widget.min_width)
4356 windows->widget.width=windows->widget.min_width;
4357 windows->widget.height=(
unsigned int)
4358 (((81*height) >> 2)+(
unsigned int) ((13*QuantumMargin) >> 1)+4);
4359 windows->widget.min_height=(
unsigned int)
4360 (((23*height) >> 1)+(
unsigned int) ((13*QuantumMargin) >> 1)+4);
4361 if (windows->widget.height < windows->widget.min_height)
4362 windows->widget.height=windows->widget.min_height;
4363 XConstrainWindowPosition(display,&windows->widget);
4367 (void) CopyMagickString(windows->widget.name,
"Browse and Select a File",
4369 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
4370 if (status != False)
4372 XSetWMName(display,windows->widget.id,&window_name);
4373 XSetWMIconName(display,windows->widget.id,&window_name);
4374 (void) XFree((
void *) window_name.value);
4376 window_changes.width=(int) windows->widget.width;
4377 window_changes.height=(int) windows->widget.height;
4378 window_changes.x=windows->widget.x;
4379 window_changes.y=windows->widget.y;
4380 (void) XReconfigureWMWindow(display,windows->widget.id,
4381 windows->widget.screen,mask,&window_changes);
4382 (void) XMapRaised(display,windows->widget.id);
4383 windows->widget.mapped=MagickFalse;
4387 XGetWidgetInfo((
char *) NULL,&slider_info);
4388 XGetWidgetInfo((
char *) NULL,&north_info);
4389 XGetWidgetInfo((
char *) NULL,&south_info);
4390 XGetWidgetInfo((
char *) NULL,&expose_info);
4392 anomaly=(LocaleCompare(action,
"Composite") == 0) ||
4393 (LocaleCompare(action,
"Open") == 0) || (LocaleCompare(action,
"Map") == 0);
4394 delay=SuspendTime << 2;
4395 state=UpdateConfigurationState;
4398 if (state & UpdateConfigurationState)
4406 XGetWidgetInfo(CancelButtonText,&cancel_info);
4407 cancel_info.width=width;
4408 cancel_info.height=(
unsigned int) ((3*height) >> 1);
4409 cancel_info.x=(int) windows->widget.width-(
int) cancel_info.width-
4411 cancel_info.y=(int) windows->widget.height-(
int) cancel_info.height-
4413 XGetWidgetInfo(action,&action_info);
4414 action_info.width=width;
4415 action_info.height=(
unsigned int) ((3*height) >> 1);
4416 action_info.x=cancel_info.x-((int) cancel_info.width+
4417 (QuantumMargin >> 1)+(int) (action_info.bevel_width << 1));
4418 action_info.y=cancel_info.y;
4419 XGetWidgetInfo(GrabButtonText,&special_info);
4420 special_info.width=width;
4421 special_info.height=(
unsigned int) ((3*height) >> 1);
4422 special_info.x=action_info.x-((int) action_info.width+
4423 (QuantumMargin >> 1)+(int) (special_info.bevel_width << 1));
4424 special_info.y=action_info.y;
4425 if (anomaly == MagickFalse)
4430 special_info.text=(
char *) FormatButtonText;
4431 p=reply+Extent(reply)-1;
4432 while ((p > (reply+1)) && (*(p-1) !=
'.'))
4434 if ((p > (reply+1)) && (*(p-1) ==
'.'))
4435 (void) CopyMagickString(format,p,MagickPathExtent);
4437 XGetWidgetInfo(UpButtonText,&up_info);
4438 up_info.width=width;
4439 up_info.height=(
unsigned int) ((3*height) >> 1);
4440 up_info.x=QuantumMargin;
4441 up_info.y=(int) ((5*QuantumMargin) >> 1)+(int) height;
4442 XGetWidgetInfo(HomeButtonText,&home_info);
4443 home_info.width=width;
4444 home_info.height=(
unsigned int) ((3*height) >> 1);
4445 home_info.x=QuantumMargin;
4446 home_info.y=up_info.y+(int) up_info.height+QuantumMargin;
4450 XGetWidgetInfo(reply,&reply_info);
4451 reply_info.raised=MagickFalse;
4452 reply_info.bevel_width--;
4453 reply_info.width=windows->widget.width-width-(
unsigned int)
4454 ((6*QuantumMargin) >> 1);
4455 reply_info.height=height << 1;
4456 reply_info.x=(int) width+(QuantumMargin << 1);
4457 reply_info.y=action_info.y-(int) reply_info.height-QuantumMargin;
4461 XGetWidgetInfo((
char *) NULL,&scroll_info);
4462 scroll_info.bevel_width--;
4463 scroll_info.width=height;
4464 scroll_info.height=(
unsigned int)
4465 (reply_info.y-up_info.y-(
int) (QuantumMargin >> 1));
4466 scroll_info.x=reply_info.x+(int) (reply_info.width-scroll_info.width);
4467 scroll_info.y=up_info.y-(int) reply_info.bevel_width;
4468 scroll_info.raised=MagickFalse;
4469 scroll_info.trough=MagickTrue;
4470 north_info=scroll_info;
4471 north_info.raised=MagickTrue;
4472 north_info.width-=(north_info.bevel_width << 1);
4473 north_info.height=north_info.width-1;
4474 north_info.x+=(int) north_info.bevel_width;
4475 north_info.y+=(int) north_info.bevel_width;
4476 south_info=north_info;
4477 south_info.y=scroll_info.y+(int) scroll_info.height-(
int)
4478 scroll_info.bevel_width-(int) south_info.height;
4480 slider_info=north_info;
4482 slider_info.width-=2;
4483 slider_info.min_y=north_info.y+(int) north_info.height+(
int)
4484 north_info.bevel_width+(int) slider_info.bevel_width+2;
4485 slider_info.height=(
unsigned int) ((
int) scroll_info.height-
4486 ((slider_info.min_y-scroll_info.y+1) << 1)+4);
4487 visible_files=(
unsigned int) (scroll_info.height*
4488 PerceptibleReciprocal((
double) height+(height >> 3)));
4489 if (files > visible_files)
4490 slider_info.height=(
unsigned int)
4491 ((visible_files*slider_info.height)/files);
4492 slider_info.max_y=south_info.y-(int) south_info.bevel_width-(
int)
4493 slider_info.bevel_width-2;
4494 slider_info.x=scroll_info.x+(int) slider_info.bevel_width+1;
4495 slider_info.y=slider_info.min_y;
4496 expose_info=scroll_info;
4497 expose_info.y=slider_info.y;
4501 XGetWidgetInfo((
char *) NULL,&list_info);
4502 list_info.raised=MagickFalse;
4503 list_info.bevel_width--;
4504 list_info.width=(
unsigned int)
4505 (scroll_info.x-reply_info.x-(
int) (QuantumMargin >> 1));
4506 list_info.height=scroll_info.height;
4507 list_info.x=reply_info.x;
4508 list_info.y=scroll_info.y;
4509 if (windows->widget.mapped == MagickFalse)
4510 state|=JumpListState;
4515 XGetWidgetInfo(text,&text_info);
4516 text_info.center=MagickFalse;
4517 text_info.width=reply_info.width;
4518 text_info.height=height;
4519 text_info.x=list_info.x-(int) (QuantumMargin >> 1);
4520 text_info.y=QuantumMargin;
4524 XGetWidgetInfo((
char *) NULL,&selection_info);
4525 selection_info.center=MagickFalse;
4526 selection_info.width=list_info.width;
4527 selection_info.height=(
unsigned int) ((9*height) >> 3);
4528 selection_info.x=list_info.x;
4529 state&=(
unsigned int) (~UpdateConfigurationState);
4531 if (state & RedrawWidgetState)
4537 y=text_info.y+(int) ((text_info.height-height) >> 1)+font_info->ascent;
4538 (void) XDrawString(display,windows->widget.id,
4539 windows->widget.annotate_context,x,y,DirectoryText,
4540 Extent(DirectoryText));
4541 (void) CopyMagickString(text_info.text,working_path,MagickPathExtent);
4542 (void) ConcatenateMagickString(text_info.text,DirectorySeparator,
4544 (void) ConcatenateMagickString(text_info.text,glob_pattern,
4546 XDrawWidgetText(display,&windows->widget,&text_info);
4547 XDrawBeveledButton(display,&windows->widget,&up_info);
4548 XDrawBeveledButton(display,&windows->widget,&home_info);
4549 XDrawBeveledMatte(display,&windows->widget,&list_info);
4550 XDrawBeveledMatte(display,&windows->widget,&scroll_info);
4551 XDrawTriangleNorth(display,&windows->widget,&north_info);
4552 XDrawBeveledButton(display,&windows->widget,&slider_info);
4553 XDrawTriangleSouth(display,&windows->widget,&south_info);
4555 y=reply_info.y+(int) ((reply_info.height-height) >> 1)+
4557 (void) XDrawString(display,windows->widget.id,
4558 windows->widget.annotate_context,x,y,FilenameText,
4559 Extent(FilenameText));
4560 XDrawBeveledMatte(display,&windows->widget,&reply_info);
4561 XDrawMatteText(display,&windows->widget,&reply_info);
4562 XDrawBeveledButton(display,&windows->widget,&special_info);
4563 XDrawBeveledButton(display,&windows->widget,&action_info);
4564 XDrawBeveledButton(display,&windows->widget,&cancel_info);
4565 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
4566 selection_info.id=(~0);
4567 state|=RedrawListState;
4568 state&=(
unsigned int) (~RedrawWidgetState);
4570 if (state & UpdateListState)
4581 checklist=ListFiles(working_path,glob_pattern,&number_files);
4582 if (checklist == (
char **) NULL)
4587 action_info.raised=MagickFalse;
4588 XDrawBeveledButton(display,&windows->widget,&action_info);
4591 for (i=0; i < (ssize_t) files; i++)
4592 filelist[i]=DestroyString(filelist[i]);
4593 if (filelist != (
char **) NULL)
4594 filelist=(
char **) RelinquishMagickMemory(filelist);
4600 slider_info.height=(
unsigned int) ((
int) scroll_info.height-
4601 ((slider_info.min_y-scroll_info.y+1) << 1)+1);
4602 if (files > visible_files)
4603 slider_info.height=(
unsigned int)
4604 ((visible_files*slider_info.height)/files);
4605 slider_info.max_y=south_info.y-(int) south_info.bevel_width-
4606 (
int) slider_info.bevel_width-2;
4608 slider_info.y=slider_info.min_y;
4609 expose_info.y=slider_info.y;
4610 selection_info.id=(~0);
4612 state|=RedrawListState;
4616 if (IsGlob(reply_info.text) == MagickFalse)
4618 *reply_info.text=
'\0';
4619 reply_info.cursor=reply_info.text;
4621 (void) CopyMagickString(text_info.text,working_path,MagickPathExtent);
4622 (void) ConcatenateMagickString(text_info.text,DirectorySeparator,
4624 (void) ConcatenateMagickString(text_info.text,glob_pattern,
4626 XDrawWidgetText(display,&windows->widget,&text_info);
4627 XDrawMatteText(display,&windows->widget,&reply_info);
4628 XDrawBeveledMatte(display,&windows->widget,&scroll_info);
4629 XDrawTriangleNorth(display,&windows->widget,&north_info);
4630 XDrawBeveledButton(display,&windows->widget,&slider_info);
4631 XDrawTriangleSouth(display,&windows->widget,&south_info);
4632 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
4633 state&=(
unsigned int) (~UpdateListState);
4635 if (state & JumpListState)
4641 for (i=0; i < (ssize_t) files; i++)
4642 if (LocaleCompare(filelist[i],reply) >= 0)
4645 (LocaleCompare(filelist[i],reply) == 0 ? i : ~0);
4648 if ((i < (ssize_t) slider_info.id) ||
4649 (i >= (slider_info.id+(ssize_t) visible_files)))
4650 slider_info.id=i-(int) (visible_files >> 1);
4651 selection_info.id=(~0);
4652 state|=RedrawListState;
4653 state&=(
unsigned int) (~JumpListState);
4655 if (state & RedrawListState)
4660 if (slider_info.id >= (
int) (files-visible_files))
4661 slider_info.id=(int) (files-visible_files);
4662 if ((slider_info.id < 0) || (files <= visible_files))
4664 slider_info.y=slider_info.min_y;
4666 slider_info.y+=((int) slider_info.id*(slider_info.max_y-
4667 slider_info.min_y+1)/(int) files);
4668 if (slider_info.id != selection_info.id)
4673 selection_info.id=slider_info.id;
4674 selection_info.y=list_info.y+(int) (height >> 3)+2;
4675 for (i=0; i < (ssize_t) visible_files; i++)
4677 selection_info.raised=(int) (slider_info.id+i) != list_info.id ?
4678 MagickTrue : MagickFalse;
4679 selection_info.text=(
char *) NULL;
4680 if ((slider_info.id+i) < (ssize_t) files)
4681 selection_info.text=filelist[slider_info.id+i];
4682 XDrawWidgetText(display,&windows->widget,&selection_info);
4683 selection_info.y+=(int) selection_info.height;
4688 if (slider_info.y > expose_info.y)
4690 expose_info.height=(
unsigned int) (slider_info.y-expose_info.y);
4691 expose_info.y=slider_info.y-(int) expose_info.height-(
int)
4692 slider_info.bevel_width-1;
4696 expose_info.height=(
unsigned int) (expose_info.y-slider_info.y);
4697 expose_info.y=slider_info.y+(int) slider_info.height+(
int)
4698 slider_info.bevel_width+1;
4700 XDrawTriangleNorth(display,&windows->widget,&north_info);
4701 XDrawMatte(display,&windows->widget,&expose_info);
4702 XDrawBeveledButton(display,&windows->widget,&slider_info);
4703 XDrawTriangleSouth(display,&windows->widget,&south_info);
4704 expose_info.y=slider_info.y;
4706 state&=(
unsigned int) (~RedrawListState);
4711 if (north_info.raised && south_info.raised)
4712 (void) XIfEvent(display,&event,XScreenEvent,(
char *) windows);
4718 XDelay(display,delay);
4720 (void) XCheckIfEvent(display,&event,XScreenEvent,(
char *) windows);
4721 if (north_info.raised == MagickFalse)
4722 if (slider_info.id > 0)
4728 state|=RedrawListState;
4730 if (south_info.raised == MagickFalse)
4731 if (slider_info.id < (
int) files)
4737 state|=RedrawListState;
4739 if (event.type != ButtonRelease)
4746 if (MatteIsActive(slider_info,event.xbutton))
4751 slider_info.active=MagickTrue;
4754 if (MatteIsActive(north_info,event.xbutton))
4755 if (slider_info.id > 0)
4760 north_info.raised=MagickFalse;
4762 state|=RedrawListState;
4765 if (MatteIsActive(south_info,event.xbutton))
4766 if (slider_info.id < (
int) files)
4771 south_info.raised=MagickFalse;
4773 state|=RedrawListState;
4776 if (MatteIsActive(scroll_info,event.xbutton))
4781 if (event.xbutton.y < slider_info.y)
4782 slider_info.id-=(int) (visible_files-1);
4784 slider_info.id+=(int) (visible_files-1);
4785 state|=RedrawListState;
4788 if (MatteIsActive(list_info,event.xbutton))
4796 id=slider_info.id+(
event.xbutton.y-(list_info.y+(int)
4797 (height >> 1))+1)/(
int) selection_info.height;
4798 if (
id >= (
int) files)
4800 (void) CopyMagickString(reply_info.text,filelist[
id],MagickPathExtent);
4801 reply_info.highlight=MagickFalse;
4802 reply_info.marker=reply_info.text;
4803 reply_info.cursor=reply_info.text+Extent(reply_info.text);
4804 XDrawMatteText(display,&windows->widget,&reply_info);
4805 if (
id == list_info.id)
4810 p=reply_info.text+strlen(reply_info.text)-1;
4811 if (*p == *DirectorySeparator)
4812 ChopPathComponents(reply_info.text,1);
4813 (void) ConcatenateMagickString(working_path,DirectorySeparator,
4815 (void) ConcatenateMagickString(working_path,reply_info.text,
4818 state|=UpdateListState;
4820 selection_info.id=(~0);
4822 state|=RedrawListState;
4825 if (MatteIsActive(up_info,event.xbutton))
4830 up_info.raised=MagickFalse;
4831 XDrawBeveledButton(display,&windows->widget,&up_info);
4834 if (MatteIsActive(home_info,event.xbutton))
4839 home_info.raised=MagickFalse;
4840 XDrawBeveledButton(display,&windows->widget,&home_info);
4843 if (MatteIsActive(special_info,event.xbutton))
4848 special_info.raised=MagickFalse;
4849 XDrawBeveledButton(display,&windows->widget,&special_info);
4852 if (MatteIsActive(action_info,event.xbutton))
4857 action_info.raised=MagickFalse;
4858 XDrawBeveledButton(display,&windows->widget,&action_info);
4861 if (MatteIsActive(cancel_info,event.xbutton))
4866 cancel_info.raised=MagickFalse;
4867 XDrawBeveledButton(display,&windows->widget,&cancel_info);
4870 if (MatteIsActive(reply_info,event.xbutton) == MagickFalse)
4872 if (event.xbutton.button != Button2)
4880 x=
event.xbutton.x-reply_info.x-(int) (QuantumMargin >> 2);
4881 for (i=1; i <= (ssize_t) Extent(reply_info.marker); i++)
4882 if (XTextWidth(font_info,reply_info.marker,(
int) i) > x)
4884 reply_info.cursor=reply_info.marker+i-1;
4885 if (event.xbutton.time > (click_time+(
unsigned long) DoubleClick))
4886 reply_info.highlight=MagickFalse;
4892 (void) CopyMagickString(primary_selection,reply_info.text,
4894 (void) XSetSelectionOwner(display,XA_PRIMARY,windows->widget.id,
4895 event.xbutton.time);
4896 reply_info.highlight=XGetSelectionOwner(display,XA_PRIMARY) ==
4897 windows->widget.id ? MagickTrue : MagickFalse;
4899 XDrawMatteText(display,&windows->widget,&reply_info);
4900 click_time=
event.xbutton.time;
4906 (void) XConvertSelection(display,XA_PRIMARY,XA_STRING,XA_STRING,
4907 windows->widget.id,event.xbutton.time);
4912 if (windows->widget.mapped == MagickFalse)
4914 if (north_info.raised == MagickFalse)
4919 delay=SuspendTime << 2;
4920 north_info.raised=MagickTrue;
4921 XDrawTriangleNorth(display,&windows->widget,&north_info);
4923 if (south_info.raised == MagickFalse)
4928 delay=SuspendTime << 2;
4929 south_info.raised=MagickTrue;
4930 XDrawTriangleSouth(display,&windows->widget,&south_info);
4932 if (slider_info.active)
4937 slider_info.active=MagickFalse;
4940 if (up_info.raised == MagickFalse)
4942 if (event.xbutton.window == windows->widget.id)
4943 if (MatteIsActive(up_info,event.xbutton))
4945 ChopPathComponents(working_path,1);
4946 if (*working_path ==
'\0')
4947 (void) CopyMagickString(working_path,DirectorySeparator,
4949 state|=UpdateListState;
4951 up_info.raised=MagickTrue;
4952 XDrawBeveledButton(display,&windows->widget,&up_info);
4954 if (home_info.raised == MagickFalse)
4956 if (event.xbutton.window == windows->widget.id)
4957 if (MatteIsActive(home_info,event.xbutton))
4959 (void) CopyMagickString(working_path,home_directory,
4961 state|=UpdateListState;
4963 home_info.raised=MagickTrue;
4964 XDrawBeveledButton(display,&windows->widget,&home_info);
4966 if (special_info.raised == MagickFalse)
4968 if (anomaly == MagickFalse)
4982 exception=AcquireExceptionInfo();
4983 formats=GetMagickList(
"*",&number_formats,exception);
4984 exception=DestroyExceptionInfo(exception);
4985 if (formats == (
char **) NULL)
4987 (void) XCheckDefineCursor(display,windows->widget.id,
4988 windows->widget.busy_cursor);
4989 windows->popup.x=windows->widget.x+60;
4990 windows->popup.y=windows->widget.y+60;
4991 XListBrowserWidget(display,windows,&windows->popup,
4992 (
const char **) formats,
"Select",
"Select image format type:",
4994 XSetCursorState(display,windows,MagickTrue);
4995 (void) XCheckDefineCursor(display,windows->widget.id,
4996 windows->widget.cursor);
4997 LocaleLower(format);
4998 AppendImageFormat(format,reply_info.text);
4999 reply_info.cursor=reply_info.text+Extent(reply_info.text);
5000 XDrawMatteText(display,&windows->widget,&reply_info);
5001 special_info.raised=MagickTrue;
5002 XDrawBeveledButton(display,&windows->widget,&special_info);
5003 for (i=0; i < (ssize_t) number_formats; i++)
5004 formats[i]=DestroyString(formats[i]);
5005 formats=(
char **) RelinquishMagickMemory(formats);
5008 if (event.xbutton.window == windows->widget.id)
5009 if (MatteIsActive(special_info,event.xbutton))
5011 (void) CopyMagickString(working_path,
"x:",MagickPathExtent);
5014 special_info.raised=MagickTrue;
5015 XDrawBeveledButton(display,&windows->widget,&special_info);
5017 if (action_info.raised == MagickFalse)
5019 if (event.xbutton.window == windows->widget.id)
5021 if (MatteIsActive(action_info,event.xbutton))
5023 if (*reply_info.text ==
'\0')
5024 (void) XBell(display,0);
5029 action_info.raised=MagickTrue;
5030 XDrawBeveledButton(display,&windows->widget,&action_info);
5032 if (cancel_info.raised == MagickFalse)
5034 if (event.xbutton.window == windows->widget.id)
5035 if (MatteIsActive(cancel_info,event.xbutton))
5037 *reply_info.text=
'\0';
5041 cancel_info.raised=MagickTrue;
5042 XDrawBeveledButton(display,&windows->widget,&cancel_info);
5051 if (event.xclient.message_type != windows->wm_protocols)
5053 if (*event.xclient.data.l == (
int) windows->wm_take_focus)
5055 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
5056 (Time) event.xclient.data.l[1]);
5059 if (*event.xclient.data.l != (
int) windows->wm_delete_window)
5061 if (event.xclient.window == windows->widget.id)
5063 *reply_info.text=
'\0';
5069 case ConfigureNotify:
5074 if (event.xconfigure.window != windows->widget.id)
5076 if ((event.xconfigure.width == (
int) windows->widget.width) &&
5077 (event.xconfigure.height == (
int) windows->widget.height))
5079 windows->widget.width=(
unsigned int)
5080 MagickMax(event.xconfigure.width,(
int) windows->widget.min_width);
5081 windows->widget.height=(
unsigned int)
5082 MagickMax(event.xconfigure.height,(
int) windows->widget.min_height);
5083 state|=UpdateConfigurationState;
5088 if (event.xcrossing.window != windows->widget.id)
5090 state&=(
unsigned int) (~InactiveWidgetState);
5095 if (event.xexpose.window != windows->widget.id)
5097 if (event.xexpose.count != 0)
5099 state|=RedrawWidgetState;
5105 command[MagickPathExtent];
5116 if (event.xkey.window != windows->widget.id)
5118 length=XLookupString((XKeyEvent *) &event.xkey,command,
5119 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
5120 *(command+length)=
'\0';
5121 if (AreaIsActive(scroll_info,event.xkey))
5126 switch ((
int) key_symbol)
5149 slider_info.id-=(int) visible_files;
5155 slider_info.id+=(int) visible_files;
5161 slider_info.id=(int) files;
5165 state|=RedrawListState;
5168 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
5173 if (*reply_info.text ==
'\0')
5175 if (IsGlob(reply_info.text))
5176 (void) CopyMagickString(glob_pattern,reply_info.text,
5180 (void) ConcatenateMagickString(working_path,DirectorySeparator,
5182 (void) ConcatenateMagickString(working_path,reply_info.text,
5184 if (*working_path ==
'~')
5185 ExpandFilename(working_path);
5188 state|=UpdateListState;
5191 if (key_symbol == XK_Control_L)
5193 state|=ControlState;
5196 if (state & ControlState)
5197 switch ((
int) key_symbol)
5205 *reply_info.text=
'\0';
5206 reply_info.cursor=reply_info.text;
5207 reply_info.marker=reply_info.text;
5208 reply_info.highlight=MagickFalse;
5214 XEditText(display,&reply_info,key_symbol,command,state);
5215 XDrawMatteText(display,&windows->widget,&reply_info);
5216 state|=JumpListState;
5222 command[MagickPathExtent];
5230 if (event.xkey.window != windows->widget.id)
5232 (void) XLookupString((XKeyEvent *) &event.xkey,command,
5233 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
5234 if (key_symbol == XK_Control_L)
5235 state&=(
unsigned int) (~ControlState);
5240 if (event.xcrossing.window != windows->widget.id)
5242 state|=InactiveWidgetState;
5247 mask&=(
unsigned int) (~CWX);
5248 mask&=(
unsigned int) (~CWY);
5256 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
5257 if (slider_info.active)
5262 slider_info.y=
event.xmotion.y-(int)
5263 ((slider_info.height+slider_info.bevel_width) >> 1)+1;
5264 if (slider_info.y < slider_info.min_y)
5265 slider_info.y=slider_info.min_y;
5266 if (slider_info.y > slider_info.max_y)
5267 slider_info.y=slider_info.max_y;
5269 if (slider_info.y != slider_info.min_y)
5270 slider_info.id=((int) files*(slider_info.y-slider_info.min_y+1))/
5271 (slider_info.max_y-slider_info.min_y+1);
5272 state|=RedrawListState;
5275 if (state & InactiveWidgetState)
5277 if (up_info.raised == MatteIsActive(up_info,event.xmotion))
5282 up_info.raised=!up_info.raised;
5283 XDrawBeveledButton(display,&windows->widget,&up_info);
5286 if (home_info.raised == MatteIsActive(home_info,event.xmotion))
5291 home_info.raised=!home_info.raised;
5292 XDrawBeveledButton(display,&windows->widget,&home_info);
5295 if (special_info.raised == MatteIsActive(special_info,event.xmotion))
5300 special_info.raised=!special_info.raised;
5301 XDrawBeveledButton(display,&windows->widget,&special_info);
5304 if (action_info.raised == MatteIsActive(action_info,event.xmotion))
5309 action_info.raised=action_info.raised == MagickFalse ?
5310 MagickTrue : MagickFalse;
5311 XDrawBeveledButton(display,&windows->widget,&action_info);
5314 if (cancel_info.raised == MatteIsActive(cancel_info,event.xmotion))
5319 cancel_info.raised=cancel_info.raised == MagickFalse ?
5320 MagickTrue : MagickFalse;
5321 XDrawBeveledButton(display,&windows->widget,&cancel_info);
5326 case SelectionClear:
5328 reply_info.highlight=MagickFalse;
5329 XDrawMatteText(display,&windows->widget,&reply_info);
5332 case SelectionNotify:
5350 if (event.xselection.property == (Atom) None)
5352 status=XGetWindowProperty(display,event.xselection.requestor,
5353 event.xselection.property,0L,2047L,MagickTrue,XA_STRING,&type,
5354 &format,&length,&after,&data);
5355 if ((status != Success) || (type != XA_STRING) || (format == 32) ||
5358 if ((Extent(reply_info.text)+(
int) length) >= (MagickPathExtent-1))
5359 (void) XBell(display,0);
5365 *(data+length)=
'\0';
5366 XEditText(display,&reply_info,(KeySym) XK_Insert,(
char *) data,
5368 XDrawMatteText(display,&windows->widget,&reply_info);
5369 state|=JumpListState;
5370 state|=RedrawActionState;
5372 (void) XFree((
void *) data);
5375 case SelectionRequest:
5380 XSelectionRequestEvent
5383 if (reply_info.highlight == MagickFalse)
5388 request=(&(
event.xselectionrequest));
5389 (void) XChangeProperty(request->display,request->requestor,
5390 request->property,request->target,8,PropModeReplace,
5391 (
unsigned char *) primary_selection,Extent(primary_selection));
5392 notify.type=SelectionNotify;
5393 notify.display=request->display;
5394 notify.requestor=request->requestor;
5395 notify.selection=request->selection;
5396 notify.target=request->target;
5397 notify.time=request->time;
5398 if (request->property == None)
5399 notify.property=request->target;
5401 notify.property=request->property;
5402 (void) XSendEvent(request->display,request->requestor,False,0,
5403 (XEvent *) ¬ify);
5408 }
while ((state & ExitState) == 0);
5409 XSetCursorState(display,windows,MagickFalse);
5410 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
5411 XCheckRefreshWindows(display,windows);
5415 for (i=0; i < (ssize_t) files; i++)
5416 filelist[i]=DestroyString(filelist[i]);
5417 if (filelist != (
char **) NULL)
5418 filelist=(
char **) RelinquishMagickMemory(filelist);
5421 (void) ConcatenateMagickString(working_path,DirectorySeparator,
5423 (void) ConcatenateMagickString(working_path,reply,MagickPathExtent);
5425 (void) CopyMagickString(reply,working_path,MagickPathExtent);
5427 ExpandFilename(reply);
5464#if defined(__cplusplus) || defined(c_plusplus)
5468static int FontCompare(
const void *x,
const void *y)
5474 p=(
char *) *((
char **) x);
5475 q=(
char *) *((
char **) y);
5476 while ((*p !=
'\0') && (*q !=
'\0') && (*p == *q))
5484#if defined(__cplusplus) || defined(c_plusplus)
5488MagickPrivate
void XFontBrowserWidget(Display *display,XWindows *windows,
5489 const char *action,
char *reply)
5491#define BackButtonText "Back"
5492#define CancelButtonText "Cancel"
5493#define FontnameText "Name:"
5494#define FontPatternText "Pattern:"
5495#define ResetButtonText "Reset"
5498 back_pattern[MagickPathExtent],
5501 primary_selection[MagickPathExtent] =
"",
5502 reset_pattern[MagickPathExtent],
5503 text[MagickPathExtent];
5514 glob_pattern[MagickPathExtent] =
"*";
5516 static MagickStatusType
5517 mask = (MagickStatusType) (CWWidth | CWHeight | CWX | CWY);
5563 assert(display != (Display *) NULL);
5564 assert(windows != (XWindows *) NULL);
5565 assert(action != (
char *) NULL);
5566 assert(reply != (
char *) NULL);
5567 if (IsEventLogging() != MagickFalse)
5568 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",action);
5569 XSetCursorState(display,windows,MagickTrue);
5570 XCheckRefreshWindows(display,windows);
5571 (void) CopyMagickString(back_pattern,glob_pattern,MagickPathExtent);
5572 (void) CopyMagickString(reset_pattern,
"*",MagickPathExtent);
5573 fontlist=XListFonts(display,glob_pattern,32767,&fonts);
5579 XNoticeWidget(display,windows,
"Unable to obtain fonts names:",
5581 (void) CopyMagickString(glob_pattern,
"*",MagickPathExtent);
5582 fontlist=XListFonts(display,glob_pattern,32767,&fonts);
5583 if (fontlist == (
char **) NULL)
5585 XNoticeWidget(display,windows,
"Unable to obtain fonts names:",
5594 fontlist=(
char **) AcquireQuantumMemory((
size_t) fonts,
sizeof(*fontlist));
5595 if (fontlist == (
char **) NULL)
5597 XNoticeWidget(display,windows,
"MemoryAllocationFailed",
5598 "UnableToViewFonts");
5601 for (i=0; i < fonts; i++)
5602 fontlist[i]=listhead[i];
5603 qsort((
void *) fontlist,(
size_t) fonts,
sizeof(*fontlist),FontCompare);
5607 font_info=windows->widget.font_info;
5609 for (i=0; i < fonts; i++)
5610 if (WidgetTextWidth(font_info,fontlist[i]) > text_width)
5611 text_width=WidgetTextWidth(font_info,fontlist[i]);
5612 width=WidgetTextWidth(font_info,(
char *) action);
5613 if (WidgetTextWidth(font_info,CancelButtonText) > width)
5614 width=WidgetTextWidth(font_info,CancelButtonText);
5615 if (WidgetTextWidth(font_info,ResetButtonText) > width)
5616 width=WidgetTextWidth(font_info,ResetButtonText);
5617 if (WidgetTextWidth(font_info,BackButtonText) > width)
5618 width=WidgetTextWidth(font_info,BackButtonText);
5619 width+=(
unsigned int) QuantumMargin;
5620 if (WidgetTextWidth(font_info,FontPatternText) > width)
5621 width=WidgetTextWidth(font_info,FontPatternText);
5622 if (WidgetTextWidth(font_info,FontnameText) > width)
5623 width=WidgetTextWidth(font_info,FontnameText);
5624 height=(
unsigned int) (font_info->ascent+font_info->descent);
5628 windows->widget.width=width+MagickMin(text_width,MaxTextWidth)+(
unsigned int)
5630 windows->widget.min_width=width+MinTextWidth+(
unsigned int) (4*QuantumMargin);
5631 if (windows->widget.width < windows->widget.min_width)
5632 windows->widget.width=windows->widget.min_width;
5633 windows->widget.height=(
unsigned int)
5634 (((85*(
int) height) >> 2)+((13*QuantumMargin) >> 1)+4);
5635 windows->widget.min_height=(
unsigned int)
5636 (((27*(
int) height) >> 1)+((13*QuantumMargin) >> 1)+4);
5637 if (windows->widget.height < windows->widget.min_height)
5638 windows->widget.height=windows->widget.min_height;
5639 XConstrainWindowPosition(display,&windows->widget);
5643 (void) CopyMagickString(windows->widget.name,
"Browse and Select a Font",
5645 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
5646 if (status != False)
5648 XSetWMName(display,windows->widget.id,&window_name);
5649 XSetWMIconName(display,windows->widget.id,&window_name);
5650 (void) XFree((
void *) window_name.value);
5652 window_changes.width=(int) windows->widget.width;
5653 window_changes.height=(int) windows->widget.height;
5654 window_changes.x=windows->widget.x;
5655 window_changes.y=windows->widget.y;
5656 (void) XReconfigureWMWindow(display,windows->widget.id,
5657 windows->widget.screen,mask,&window_changes);
5658 (void) XMapRaised(display,windows->widget.id);
5659 windows->widget.mapped=MagickFalse;
5663 XGetWidgetInfo((
char *) NULL,&slider_info);
5664 XGetWidgetInfo((
char *) NULL,&north_info);
5665 XGetWidgetInfo((
char *) NULL,&south_info);
5666 XGetWidgetInfo((
char *) NULL,&expose_info);
5667 XGetWidgetInfo((
char *) NULL,&selection_info);
5669 delay=SuspendTime << 2;
5670 state=UpdateConfigurationState;
5673 if (state & UpdateConfigurationState)
5681 XGetWidgetInfo(CancelButtonText,&cancel_info);
5682 cancel_info.width=width;
5683 cancel_info.height=(
unsigned int) ((3*height) >> 1);
5684 cancel_info.x=(int) windows->widget.width-(
int) cancel_info.width-
5686 cancel_info.y=(int) windows->widget.height-(
int) cancel_info.height-
5688 XGetWidgetInfo(action,&action_info);
5689 action_info.width=width;
5690 action_info.height=(
unsigned int) ((3*height) >> 1);
5691 action_info.x=(int) windows->widget.width-(
int) action_info.width-
5692 (int) cancel_info.width-2*QuantumMargin-2;
5693 action_info.y=cancel_info.y;
5694 XGetWidgetInfo(BackButtonText,&back_info);
5695 back_info.width=width;
5696 back_info.height=(
unsigned int) ((3*height) >> 1);
5697 back_info.x=QuantumMargin;
5698 back_info.y=((5*QuantumMargin) >> 1)+(
int) height;
5699 XGetWidgetInfo(ResetButtonText,&reset_info);
5700 reset_info.width=width;
5701 reset_info.height=(
unsigned int) ((3*height) >> 1);
5702 reset_info.x=QuantumMargin;
5703 reset_info.y=back_info.y+(int) back_info.height+QuantumMargin;
5707 XGetWidgetInfo(reply,&reply_info);
5708 reply_info.raised=MagickFalse;
5709 reply_info.bevel_width--;
5710 reply_info.width=(
unsigned int) ((
int) windows->widget.width-(
int)
5711 width-((6*QuantumMargin) >> 1));
5712 reply_info.height=height << 1;
5713 reply_info.x=(int) width+(QuantumMargin << 1);
5714 reply_info.y=action_info.y-(int) (action_info.height << 1)-
5719 XGetWidgetInfo(reply,&mode_info);
5720 mode_info.bevel_width=0;
5721 mode_info.width=(
unsigned int)
5722 (action_info.x-reply_info.x-QuantumMargin);
5723 mode_info.height=action_info.height << 1;
5724 mode_info.x=reply_info.x;
5725 mode_info.y=action_info.y-(int) action_info.height+(
int)
5726 action_info.bevel_width;
5730 XGetWidgetInfo((
char *) NULL,&scroll_info);
5731 scroll_info.bevel_width--;
5732 scroll_info.width=height;
5733 scroll_info.height=(
unsigned int)
5734 (reply_info.y-back_info.y-(
int) (QuantumMargin >> 1));
5735 scroll_info.x=reply_info.x+(int) (reply_info.width-scroll_info.width);
5736 scroll_info.y=back_info.y-(int) reply_info.bevel_width;
5737 scroll_info.raised=MagickFalse;
5738 scroll_info.trough=MagickTrue;
5739 north_info=scroll_info;
5740 north_info.raised=MagickTrue;
5741 north_info.width-=(north_info.bevel_width << 1);
5742 north_info.height=north_info.width-1;
5743 north_info.x+=(int) north_info.bevel_width;
5744 north_info.y+=(int) north_info.bevel_width;
5745 south_info=north_info;
5746 south_info.y=scroll_info.y+(int) scroll_info.height-(
int)
5747 scroll_info.bevel_width-(int) south_info.height;
5749 slider_info=north_info;
5751 slider_info.width-=2;
5752 slider_info.min_y=north_info.y+(int) north_info.height+(
int)
5753 north_info.bevel_width+(int) slider_info.bevel_width+2;
5754 slider_info.height=(
unsigned int) ((
int) scroll_info.height-
5755 ((slider_info.min_y-scroll_info.y+1) << 1)+4);
5756 visible_fonts=(
unsigned int) (scroll_info.height*
5757 PerceptibleReciprocal((
double) height+(height >> 3)));
5758 if (fonts > (
int) visible_fonts)
5759 slider_info.height=(visible_fonts*slider_info.height)/(
unsigned int)
5761 slider_info.max_y=south_info.y-(int) south_info.bevel_width-
5762 (
int) slider_info.bevel_width-2;
5763 slider_info.x=scroll_info.x+(int) slider_info.bevel_width+1;
5764 slider_info.y=slider_info.min_y;
5765 expose_info=scroll_info;
5766 expose_info.y=slider_info.y;
5770 XGetWidgetInfo((
char *) NULL,&list_info);
5771 list_info.raised=MagickFalse;
5772 list_info.bevel_width--;
5773 list_info.width=(
unsigned int) (scroll_info.x-reply_info.x-
5774 (QuantumMargin >> 1));
5775 list_info.height=scroll_info.height;
5776 list_info.x=reply_info.x;
5777 list_info.y=scroll_info.y;
5778 if (windows->widget.mapped == MagickFalse)
5779 state|=JumpListState;
5784 XGetWidgetInfo(text,&text_info);
5785 text_info.center=MagickFalse;
5786 text_info.width=reply_info.width;
5787 text_info.height=height;
5788 text_info.x=list_info.x-(QuantumMargin >> 1);
5789 text_info.y=QuantumMargin;
5793 XGetWidgetInfo((
char *) NULL,&selection_info);
5794 selection_info.center=MagickFalse;
5795 selection_info.width=list_info.width;
5796 selection_info.height=(
unsigned int) ((9*height) >> 3);
5797 selection_info.x=list_info.x;
5798 state&=(
unsigned int) (~UpdateConfigurationState);
5800 if (state & RedrawWidgetState)
5806 y=text_info.y+(int) ((text_info.height-height) >> 1)+font_info->ascent;
5807 (void) XDrawString(display,windows->widget.id,
5808 windows->widget.annotate_context,x,y,FontPatternText,
5809 Extent(FontPatternText));
5810 (void) CopyMagickString(text_info.text,glob_pattern,MagickPathExtent);
5811 XDrawWidgetText(display,&windows->widget,&text_info);
5812 XDrawBeveledButton(display,&windows->widget,&back_info);
5813 XDrawBeveledButton(display,&windows->widget,&reset_info);
5814 XDrawBeveledMatte(display,&windows->widget,&list_info);
5815 XDrawBeveledMatte(display,&windows->widget,&scroll_info);
5816 XDrawTriangleNorth(display,&windows->widget,&north_info);
5817 XDrawBeveledButton(display,&windows->widget,&slider_info);
5818 XDrawTriangleSouth(display,&windows->widget,&south_info);
5820 y=reply_info.y+(int) ((reply_info.height-height) >> 1)+
5822 (void) XDrawString(display,windows->widget.id,
5823 windows->widget.annotate_context,x,y,FontnameText,
5824 Extent(FontnameText));
5825 XDrawBeveledMatte(display,&windows->widget,&reply_info);
5826 XDrawMatteText(display,&windows->widget,&reply_info);
5827 XDrawBeveledButton(display,&windows->widget,&action_info);
5828 XDrawBeveledButton(display,&windows->widget,&cancel_info);
5829 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
5830 selection_info.id=(~0);
5831 state|=RedrawActionState;
5832 state|=RedrawListState;
5833 state&=(
unsigned int) (~RedrawWidgetState);
5835 if (state & UpdateListState)
5846 checklist=XListFonts(display,glob_pattern,32767,&number_fonts);
5847 if (checklist == (
char **) NULL)
5849 if ((strchr(glob_pattern,
'*') == (
char *) NULL) &&
5850 (strchr(glob_pattern,
'?') == (
char *) NULL))
5855 (void) CopyMagickString(reply,glob_pattern,MagickPathExtent);
5856 (void) CopyMagickString(glob_pattern,back_pattern,MagickPathExtent);
5857 action_info.raised=MagickFalse;
5858 XDrawBeveledButton(display,&windows->widget,&action_info);
5861 (void) CopyMagickString(glob_pattern,back_pattern,MagickPathExtent);
5862 (void) XBell(display,0);
5865 if (number_fonts == 1)
5870 (void) CopyMagickString(reply,checklist[0],MagickPathExtent);
5871 (void) CopyMagickString(glob_pattern,back_pattern,MagickPathExtent);
5872 (void) XFreeFontNames(checklist);
5873 action_info.raised=MagickFalse;
5874 XDrawBeveledButton(display,&windows->widget,&action_info);
5879 (void) XFreeFontNames(listhead);
5880 fontlist=(
char **) RelinquishMagickMemory(fontlist);
5888 fontlist=(
char **) AcquireQuantumMemory((
size_t) fonts,
5890 if (fontlist == (
char **) NULL)
5892 XNoticeWidget(display,windows,
"MemoryAllocationFailed",
5893 "UnableToViewFonts");
5896 for (i=0; i < fonts; i++)
5897 fontlist[i]=listhead[i];
5898 qsort((
void *) fontlist,(
size_t) fonts,
sizeof(*fontlist),FontCompare);
5899 slider_info.height=(
unsigned int) ((
int) scroll_info.height-
5900 ((slider_info.min_y-scroll_info.y+1) << 1)+1);
5901 if (fonts > (
int) visible_fonts)
5902 slider_info.height=(visible_fonts*slider_info.height)/(
unsigned int)
5904 slider_info.max_y=south_info.y-(int) south_info.bevel_width-(
int)
5905 slider_info.bevel_width-2;
5907 slider_info.y=slider_info.min_y;
5908 expose_info.y=slider_info.y;
5909 selection_info.id=(~0);
5911 state|=RedrawListState;
5915 *reply_info.text=
'\0';
5916 reply_info.cursor=reply_info.text;
5917 (void) CopyMagickString(text_info.text,glob_pattern,MagickPathExtent);
5918 XDrawWidgetText(display,&windows->widget,&text_info);
5919 XDrawMatteText(display,&windows->widget,&reply_info);
5920 XDrawBeveledMatte(display,&windows->widget,&scroll_info);
5921 XDrawTriangleNorth(display,&windows->widget,&north_info);
5922 XDrawBeveledButton(display,&windows->widget,&slider_info);
5923 XDrawTriangleSouth(display,&windows->widget,&south_info);
5924 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
5925 state&=(
unsigned int) (~UpdateListState);
5927 if (state & JumpListState)
5933 for (i=0; i < fonts; i++)
5934 if (LocaleCompare(fontlist[i],reply) >= 0)
5936 list_info.id=LocaleCompare(fontlist[i],reply) == 0 ? i : ~0;
5939 if ((i < slider_info.id) || (i >= (slider_info.id+(
int) visible_fonts)))
5940 slider_info.id=i-((int) visible_fonts >> 1);
5941 selection_info.id=(~0);
5942 state|=RedrawListState;
5943 state&=(
unsigned int) (~JumpListState);
5945 if (state & RedrawListState)
5950 if (slider_info.id >= (fonts-(
int) visible_fonts))
5951 slider_info.id=fonts-(int) visible_fonts;
5952 if ((slider_info.id < 0) || (fonts <= (
int) visible_fonts))
5954 slider_info.y=slider_info.min_y;
5957 slider_info.id*(slider_info.max_y-slider_info.min_y+1)/fonts;
5958 if (slider_info.id != selection_info.id)
5963 selection_info.id=slider_info.id;
5964 selection_info.y=list_info.y+(int) (height >> 3)+2;
5965 for (i=0; i < (int) visible_fonts; i++)
5967 selection_info.raised=(slider_info.id+i) != list_info.id ?
5968 MagickTrue : MagickFalse;
5969 selection_info.text=(
char *) NULL;
5970 if ((slider_info.id+i) < fonts)
5971 selection_info.text=fontlist[slider_info.id+i];
5972 XDrawWidgetText(display,&windows->widget,&selection_info);
5973 selection_info.y+=(int) selection_info.height;
5978 if (slider_info.y > expose_info.y)
5980 expose_info.height=(
unsigned int) (slider_info.y-expose_info.y);
5981 expose_info.y=slider_info.y-(int) expose_info.height-(
int)
5982 slider_info.bevel_width-1;
5986 expose_info.height=(
unsigned int) (expose_info.y-slider_info.y);
5987 expose_info.y=slider_info.y+(int) slider_info.height+(
int)
5988 slider_info.bevel_width+1;
5990 XDrawTriangleNorth(display,&windows->widget,&north_info);
5991 XDrawMatte(display,&windows->widget,&expose_info);
5992 XDrawBeveledButton(display,&windows->widget,&slider_info);
5993 XDrawTriangleSouth(display,&windows->widget,&south_info);
5994 expose_info.y=slider_info.y;
5996 state&=(
unsigned int) (~RedrawListState);
5998 if (state & RedrawActionState)
6006 save_info=windows->widget.font_info;
6007 font_info=XLoadQueryFont(display,reply_info.text);
6008 if (font_info != (XFontStruct *) NULL)
6010 windows->widget.font_info=font_info;
6011 (void) XSetFont(display,windows->widget.widget_context,
6014 XDrawBeveledButton(display,&windows->widget,&mode_info);
6015 windows->widget.font_info=save_info;
6016 if (font_info != (XFontStruct *) NULL)
6018 (void) XSetFont(display,windows->widget.widget_context,
6019 windows->widget.font_info->fid);
6020 (void) XFreeFont(display,font_info);
6022 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
6023 XDrawMatteText(display,&windows->widget,&reply_info);
6024 state&=(
unsigned int) (~RedrawActionState);
6029 if (north_info.raised && south_info.raised)
6030 (void) XIfEvent(display,&event,XScreenEvent,(
char *) windows);
6036 XDelay(display,delay);
6038 (void) XCheckIfEvent(display,&event,XScreenEvent,(
char *) windows);
6039 if (north_info.raised == MagickFalse)
6040 if (slider_info.id > 0)
6046 state|=RedrawListState;
6048 if (south_info.raised == MagickFalse)
6049 if (slider_info.id < fonts)
6055 state|=RedrawListState;
6057 if (event.type != ButtonRelease)
6064 if (MatteIsActive(slider_info,event.xbutton))
6069 slider_info.active=MagickTrue;
6072 if (MatteIsActive(north_info,event.xbutton))
6073 if (slider_info.id > 0)
6078 north_info.raised=MagickFalse;
6080 state|=RedrawListState;
6083 if (MatteIsActive(south_info,event.xbutton))
6084 if (slider_info.id < fonts)
6089 south_info.raised=MagickFalse;
6091 state|=RedrawListState;
6094 if (MatteIsActive(scroll_info,event.xbutton))
6099 if (event.xbutton.y < slider_info.y)
6100 slider_info.id-=((int) visible_fonts-1);
6102 slider_info.id+=((int) visible_fonts-1);
6103 state|=RedrawListState;
6106 if (MatteIsActive(list_info,event.xbutton))
6114 id=slider_info.id+(
event.xbutton.y-(list_info.y+(int)
6115 (height >> 1))+1)/(
int) selection_info.height;
6116 if (
id >= (
int) fonts)
6118 (void) CopyMagickString(reply_info.text,fontlist[
id],MagickPathExtent);
6119 reply_info.highlight=MagickFalse;
6120 reply_info.marker=reply_info.text;
6121 reply_info.cursor=reply_info.text+Extent(reply_info.text);
6122 XDrawMatteText(display,&windows->widget,&reply_info);
6123 state|=RedrawActionState;
6124 if (
id == list_info.id)
6126 (void) CopyMagickString(glob_pattern,reply_info.text,
6128 state|=UpdateListState;
6130 selection_info.id=(~0);
6132 state|=RedrawListState;
6135 if (MatteIsActive(back_info,event.xbutton))
6140 back_info.raised=MagickFalse;
6141 XDrawBeveledButton(display,&windows->widget,&back_info);
6144 if (MatteIsActive(reset_info,event.xbutton))
6149 reset_info.raised=MagickFalse;
6150 XDrawBeveledButton(display,&windows->widget,&reset_info);
6153 if (MatteIsActive(action_info,event.xbutton))
6158 action_info.raised=MagickFalse;
6159 XDrawBeveledButton(display,&windows->widget,&action_info);
6162 if (MatteIsActive(cancel_info,event.xbutton))
6167 cancel_info.raised=MagickFalse;
6168 XDrawBeveledButton(display,&windows->widget,&cancel_info);
6171 if (MatteIsActive(reply_info,event.xbutton) == MagickFalse)
6173 if (event.xbutton.button != Button2)
6181 x=
event.xbutton.x-reply_info.x-(int) (QuantumMargin >> 2);
6182 if (font_info != (XFontStruct *) NULL)
6183 for (i=1; i <= Extent(reply_info.marker); i++)
6184 if (XTextWidth(font_info,reply_info.marker,i) > x)
6186 reply_info.cursor=reply_info.marker+i-1;
6187 if (event.xbutton.time > (click_time+(
unsigned long) DoubleClick))
6188 reply_info.highlight=MagickFalse;
6194 (void) CopyMagickString(primary_selection,reply_info.text,
6196 (void) XSetSelectionOwner(display,XA_PRIMARY,windows->widget.id,
6197 event.xbutton.time);
6198 reply_info.highlight=XGetSelectionOwner(display,XA_PRIMARY) ==
6199 windows->widget.id ? MagickTrue : MagickFalse;
6201 XDrawMatteText(display,&windows->widget,&reply_info);
6202 click_time=
event.xbutton.time;
6208 (void) XConvertSelection(display,XA_PRIMARY,XA_STRING,XA_STRING,
6209 windows->widget.id,event.xbutton.time);
6214 if (windows->widget.mapped == MagickFalse)
6216 if (north_info.raised == MagickFalse)
6221 delay=SuspendTime << 2;
6222 north_info.raised=MagickTrue;
6223 XDrawTriangleNorth(display,&windows->widget,&north_info);
6225 if (south_info.raised == MagickFalse)
6230 delay=SuspendTime << 2;
6231 south_info.raised=MagickTrue;
6232 XDrawTriangleSouth(display,&windows->widget,&south_info);
6234 if (slider_info.active)
6239 slider_info.active=MagickFalse;
6242 if (back_info.raised == MagickFalse)
6244 if (event.xbutton.window == windows->widget.id)
6245 if (MatteIsActive(back_info,event.xbutton))
6247 (void) CopyMagickString(glob_pattern,back_pattern,
6249 state|=UpdateListState;
6251 back_info.raised=MagickTrue;
6252 XDrawBeveledButton(display,&windows->widget,&back_info);
6254 if (reset_info.raised == MagickFalse)
6256 if (event.xbutton.window == windows->widget.id)
6257 if (MatteIsActive(reset_info,event.xbutton))
6259 (void) CopyMagickString(back_pattern,glob_pattern,MagickPathExtent);
6260 (void) CopyMagickString(glob_pattern,reset_pattern,MagickPathExtent);
6261 state|=UpdateListState;
6263 reset_info.raised=MagickTrue;
6264 XDrawBeveledButton(display,&windows->widget,&reset_info);
6266 if (action_info.raised == MagickFalse)
6268 if (event.xbutton.window == windows->widget.id)
6270 if (MatteIsActive(action_info,event.xbutton))
6272 if (*reply_info.text ==
'\0')
6273 (void) XBell(display,0);
6278 action_info.raised=MagickTrue;
6279 XDrawBeveledButton(display,&windows->widget,&action_info);
6281 if (cancel_info.raised == MagickFalse)
6283 if (event.xbutton.window == windows->widget.id)
6284 if (MatteIsActive(cancel_info,event.xbutton))
6286 *reply_info.text=
'\0';
6289 cancel_info.raised=MagickTrue;
6290 XDrawBeveledButton(display,&windows->widget,&cancel_info);
6299 if (event.xclient.message_type != windows->wm_protocols)
6301 if (*event.xclient.data.l == (
int) windows->wm_take_focus)
6303 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
6304 (Time) event.xclient.data.l[1]);
6307 if (*event.xclient.data.l != (
int) windows->wm_delete_window)
6309 if (event.xclient.window == windows->widget.id)
6311 *reply_info.text=
'\0';
6317 case ConfigureNotify:
6322 if (event.xconfigure.window != windows->widget.id)
6324 if ((event.xconfigure.width == (
int) windows->widget.width) &&
6325 (event.xconfigure.height == (
int) windows->widget.height))
6327 windows->widget.width=(
unsigned int)
6328 MagickMax(event.xconfigure.width,(
int) windows->widget.min_width);
6329 windows->widget.height=(
unsigned int)
6330 MagickMax(event.xconfigure.height,(
int) windows->widget.min_height);
6331 state|=UpdateConfigurationState;
6336 if (event.xcrossing.window != windows->widget.id)
6338 state&=(
unsigned int) (~InactiveWidgetState);
6343 if (event.xexpose.window != windows->widget.id)
6345 if (event.xexpose.count != 0)
6347 state|=RedrawWidgetState;
6353 command[MagickPathExtent];
6364 if (event.xkey.window != windows->widget.id)
6366 length=XLookupString((XKeyEvent *) &event.xkey,command,
6367 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
6368 *(command+length)=
'\0';
6369 if (AreaIsActive(scroll_info,event.xkey))
6374 switch ((
int) key_symbol)
6397 slider_info.id-=(int) visible_fonts;
6403 slider_info.id+=(int) visible_fonts;
6409 slider_info.id=fonts;
6413 state|=RedrawListState;
6416 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
6421 if (*reply_info.text ==
'\0')
6423 (void) CopyMagickString(back_pattern,glob_pattern,MagickPathExtent);
6424 (void) CopyMagickString(glob_pattern,reply_info.text,MagickPathExtent);
6425 state|=UpdateListState;
6428 if (key_symbol == XK_Control_L)
6430 state|=ControlState;
6433 if (state & ControlState)
6434 switch ((
int) key_symbol)
6442 *reply_info.text=
'\0';
6443 reply_info.cursor=reply_info.text;
6444 reply_info.marker=reply_info.text;
6445 reply_info.highlight=MagickFalse;
6451 XEditText(display,&reply_info,key_symbol,command,state);
6452 XDrawMatteText(display,&windows->widget,&reply_info);
6453 state|=JumpListState;
6459 command[MagickPathExtent];
6467 if (event.xkey.window != windows->widget.id)
6469 (void) XLookupString((XKeyEvent *) &event.xkey,command,
6470 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
6471 if (key_symbol == XK_Control_L)
6472 state&=(
unsigned int) (~ControlState);
6477 if (event.xcrossing.window != windows->widget.id)
6479 state|=InactiveWidgetState;
6484 mask&=(
unsigned int) (~CWX);
6485 mask&=(
unsigned int) (~CWY);
6493 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
6494 if (slider_info.active)
6499 slider_info.y=
event.xmotion.y-(int)
6500 ((slider_info.height+slider_info.bevel_width) >> 1)+1;
6501 if (slider_info.y < slider_info.min_y)
6502 slider_info.y=slider_info.min_y;
6503 if (slider_info.y > slider_info.max_y)
6504 slider_info.y=slider_info.max_y;
6506 if (slider_info.y != slider_info.min_y)
6507 slider_info.id=(fonts*(slider_info.y-slider_info.min_y+1))/
6508 (slider_info.max_y-slider_info.min_y+1);
6509 state|=RedrawListState;
6512 if (state & InactiveWidgetState)
6514 if (back_info.raised == MatteIsActive(back_info,event.xmotion))
6519 back_info.raised=!back_info.raised;
6520 XDrawBeveledButton(display,&windows->widget,&back_info);
6523 if (reset_info.raised == MatteIsActive(reset_info,event.xmotion))
6528 reset_info.raised=!reset_info.raised;
6529 XDrawBeveledButton(display,&windows->widget,&reset_info);
6532 if (action_info.raised == MatteIsActive(action_info,event.xmotion))
6537 action_info.raised=action_info.raised == MagickFalse ?
6538 MagickTrue : MagickFalse;
6539 XDrawBeveledButton(display,&windows->widget,&action_info);
6542 if (cancel_info.raised == MatteIsActive(cancel_info,event.xmotion))
6547 cancel_info.raised=cancel_info.raised == MagickFalse ?
6548 MagickTrue : MagickFalse;
6549 XDrawBeveledButton(display,&windows->widget,&cancel_info);
6554 case SelectionClear:
6556 reply_info.highlight=MagickFalse;
6557 XDrawMatteText(display,&windows->widget,&reply_info);
6560 case SelectionNotify:
6578 if (event.xselection.property == (Atom) None)
6580 status=XGetWindowProperty(display,event.xselection.requestor,
6581 event.xselection.property,0L,2047L,MagickTrue,XA_STRING,&type,
6582 &format,&length,&after,&data);
6583 if ((status != Success) || (type != XA_STRING) || (format == 32) ||
6586 if ((Extent(reply_info.text)+(
int) length) >= (MagickPathExtent-1))
6587 (void) XBell(display,0);
6593 *(data+length)=
'\0';
6594 XEditText(display,&reply_info,(KeySym) XK_Insert,(
char *) data,
6596 XDrawMatteText(display,&windows->widget,&reply_info);
6597 state|=JumpListState;
6598 state|=RedrawActionState;
6600 (void) XFree((
void *) data);
6603 case SelectionRequest:
6608 XSelectionRequestEvent
6614 request=(&(
event.xselectionrequest));
6615 (void) XChangeProperty(request->display,request->requestor,
6616 request->property,request->target,8,PropModeReplace,
6617 (
unsigned char *) primary_selection,Extent(primary_selection));
6618 notify.type=SelectionNotify;
6619 notify.display=request->display;
6620 notify.requestor=request->requestor;
6621 notify.selection=request->selection;
6622 notify.target=request->target;
6623 notify.time=request->time;
6624 if (request->property == None)
6625 notify.property=request->target;
6627 notify.property=request->property;
6628 (void) XSendEvent(request->display,request->requestor,False,0,
6629 (XEvent *) ¬ify);
6634 }
while ((state & ExitState) == 0);
6635 XSetCursorState(display,windows,MagickFalse);
6636 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
6637 XCheckRefreshWindows(display,windows);
6641 (void) XFreeFontNames(listhead);
6642 fontlist=(
char **) RelinquishMagickMemory(fontlist);
6675MagickPrivate
void XInfoWidget(Display *display,XWindows *windows,
6676 const char *activity)
6692 if (IsEventLogging() != MagickFalse)
6693 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
6694 assert(display != (Display *) NULL);
6695 assert(windows != (XWindows *) NULL);
6696 assert(activity != (
char *) NULL);
6697 font_info=windows->info.font_info;
6698 width=WidgetTextWidth(font_info,(
char *) activity)+(
unsigned int)
6699 ((3*QuantumMargin) >> 1)+4;
6700 height=(
unsigned int) (((6*(font_info->ascent+font_info->descent)) >> 2)+4);
6701 if ((windows->info.width != width) || (windows->info.height != height))
6706 windows->info.width=width;
6707 windows->info.height=height;
6708 window_changes.width=(int) width;
6709 window_changes.height=(int) height;
6710 (void) XReconfigureWMWindow(display,windows->info.id,windows->info.screen,
6711 (
unsigned int) (CWWidth | CWHeight),&window_changes);
6713 if (windows->info.mapped == MagickFalse)
6715 (void) XMapRaised(display,windows->info.id);
6716 windows->info.mapped=MagickTrue;
6721 height=(
unsigned int) (font_info->ascent+font_info->descent);
6722 XGetWidgetInfo(activity,&monitor_info);
6723 monitor_info.bevel_width--;
6724 margin=monitor_info.bevel_width+((windows->info.height-height) >> 1)-2;
6725 monitor_info.center=MagickFalse;
6726 monitor_info.x=(int) margin;
6727 monitor_info.y=(int) margin;
6728 monitor_info.width=windows->info.width-(margin << 1);
6729 monitor_info.height=windows->info.height-(margin << 1)+1;
6733 monitor_info.raised=MagickFalse;
6734 XDrawBeveledMatte(display,&windows->info,&monitor_info);
6735 monitor_info.raised=MagickTrue;
6736 XDrawWidgetText(display,&windows->info,&monitor_info);
6778MagickPrivate
void XListBrowserWidget(Display *display,XWindows *windows,
6779 XWindowInfo *window_info,
const char *
const *list,
const char *action,
6780 const char *query,
char *reply)
6782#define CancelButtonText "Cancel"
6785 primary_selection[MagickPathExtent];
6793 static MagickStatusType
6794 mask = (MagickStatusType) (CWWidth | CWHeight | CWX | CWY);
6838 assert(display != (Display *) NULL);
6839 assert(windows != (XWindows *) NULL);
6840 assert(window_info != (XWindowInfo *) NULL);
6841 assert(list != (
const char **) NULL);
6842 assert(action != (
char *) NULL);
6843 assert(query != (
char *) NULL);
6844 assert(reply != (
char *) NULL);
6845 if (IsEventLogging() != MagickFalse)
6846 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",action);
6847 XSetCursorState(display,windows,MagickTrue);
6848 XCheckRefreshWindows(display,windows);
6849 if (list == (
const char **) NULL)
6851 XNoticeWidget(display,windows,
"No text to browse:",(
char *) NULL);
6854 for (entries=0; ; entries++)
6855 if (list[entries] == (
char *) NULL)
6860 font_info=window_info->font_info;
6861 text_width=WidgetTextWidth(font_info,(
char *) query);
6862 for (i=0; i < (int) entries; i++)
6863 if (WidgetTextWidth(font_info,(
char *) list[i]) > text_width)
6864 text_width=WidgetTextWidth(font_info,(
char *) list[i]);
6865 width=WidgetTextWidth(font_info,(
char *) action);
6866 if (WidgetTextWidth(font_info,CancelButtonText) > width)
6867 width=WidgetTextWidth(font_info,CancelButtonText);
6868 width+=(
unsigned int) QuantumMargin;
6869 height=(
unsigned int) (font_info->ascent+font_info->descent);
6873 window_info->width=MagickMin(text_width,MaxTextWidth)+(
unsigned int)
6874 ((9*QuantumMargin) >> 1);
6875 window_info->min_width=(MinTextWidth+4*(
unsigned int) QuantumMargin);
6876 if (window_info->width < window_info->min_width)
6877 window_info->width=window_info->min_width;
6878 window_info->height=(((81*height) >> 2)+(
unsigned int)
6879 ((13*QuantumMargin) >> 1)+4);
6880 window_info->min_height=(((23*height) >> 1)+(
unsigned int)
6881 ((13*QuantumMargin) >> 1)+4);
6882 if (window_info->height < window_info->min_height)
6883 window_info->height=window_info->min_height;
6884 XConstrainWindowPosition(display,window_info);
6888 (void) CopyMagickString(window_info->name,
"Browse",MagickPathExtent);
6889 status=XStringListToTextProperty(&window_info->name,1,&window_name);
6890 if (status != False)
6892 XSetWMName(display,window_info->id,&window_name);
6893 XSetWMIconName(display,windows->widget.id,&window_name);
6894 (void) XFree((
void *) window_name.value);
6896 window_changes.width=(int) window_info->width;
6897 window_changes.height=(int) window_info->height;
6898 window_changes.x=window_info->x;
6899 window_changes.y=window_info->y;
6900 (void) XReconfigureWMWindow(display,window_info->id,window_info->screen,mask,
6902 (void) XMapRaised(display,window_info->id);
6903 window_info->mapped=MagickFalse;
6907 XGetWidgetInfo((
char *) NULL,&slider_info);
6908 XGetWidgetInfo((
char *) NULL,&north_info);
6909 XGetWidgetInfo((
char *) NULL,&south_info);
6910 XGetWidgetInfo((
char *) NULL,&expose_info);
6911 XGetWidgetInfo((
char *) NULL,&selection_info);
6913 delay=SuspendTime << 2;
6914 state=UpdateConfigurationState;
6917 if (state & UpdateConfigurationState)
6925 XGetWidgetInfo(CancelButtonText,&cancel_info);
6926 cancel_info.width=width;
6927 cancel_info.height=(
unsigned int) ((3*height) >> 1);
6928 cancel_info.x=(int) window_info->width-(
int) cancel_info.width-
6930 cancel_info.y=(int) window_info->height-(
int) cancel_info.height-
6932 XGetWidgetInfo(action,&action_info);
6933 action_info.width=width;
6934 action_info.height=(
unsigned int) ((3*height) >> 1);
6935 action_info.x=cancel_info.x-((int) cancel_info.width+
6936 (QuantumMargin >> 1)+(int) (action_info.bevel_width << 1));
6937 action_info.y=cancel_info.y;
6941 XGetWidgetInfo(reply,&reply_info);
6942 reply_info.raised=MagickFalse;
6943 reply_info.bevel_width--;
6944 reply_info.width=(
unsigned int) ((
int) window_info->width-
6945 (((4*QuantumMargin) >> 1)));
6946 reply_info.height=height << 1;
6947 reply_info.x=QuantumMargin;
6948 reply_info.y=action_info.y-(int) reply_info.height-QuantumMargin;
6952 XGetWidgetInfo((
char *) NULL,&scroll_info);
6953 scroll_info.bevel_width--;
6954 scroll_info.width=height;
6955 scroll_info.height=(
unsigned int)
6956 (reply_info.y-((6*QuantumMargin) >> 1)-(
int) height);
6957 scroll_info.x=reply_info.x+(int) (reply_info.width-scroll_info.width);
6958 scroll_info.y=((5*QuantumMargin) >> 1)+(
int) height-(int)
6959 reply_info.bevel_width;
6960 scroll_info.raised=MagickFalse;
6961 scroll_info.trough=MagickTrue;
6962 north_info=scroll_info;
6963 north_info.raised=MagickTrue;
6964 north_info.width-=(north_info.bevel_width << 1);
6965 north_info.height=north_info.width-1;
6966 north_info.x+=(int) north_info.bevel_width;
6967 north_info.y+=(int) north_info.bevel_width;
6968 south_info=north_info;
6969 south_info.y=scroll_info.y+(int) scroll_info.height-(
int)
6970 scroll_info.bevel_width-(int) south_info.height;
6972 slider_info=north_info;
6974 slider_info.width-=2;
6975 slider_info.min_y=north_info.y+(int) north_info.height+(
int)
6976 north_info.bevel_width+(int) slider_info.bevel_width+2;
6977 slider_info.height=(
unsigned int) ((
int) scroll_info.height-
6978 ((slider_info.min_y-scroll_info.y+1) << 1)+4);
6979 visible_entries=(
unsigned int) (scroll_info.height*
6980 PerceptibleReciprocal((
double) height+(height >> 3)));
6981 if (entries > visible_entries)
6982 slider_info.height=(visible_entries*slider_info.height)/entries;
6983 slider_info.max_y=south_info.y-(int) south_info.bevel_width-(
int)
6984 slider_info.bevel_width-2;
6985 slider_info.x=scroll_info.x+(int) slider_info.bevel_width+1;
6986 slider_info.y=slider_info.min_y;
6987 expose_info=scroll_info;
6988 expose_info.y=slider_info.y;
6992 XGetWidgetInfo((
char *) NULL,&list_info);
6993 list_info.raised=MagickFalse;
6994 list_info.bevel_width--;
6995 list_info.width=(
unsigned int)
6996 (scroll_info.x-reply_info.x-(
int) (QuantumMargin >> 1));
6997 list_info.height=scroll_info.height;
6998 list_info.x=reply_info.x;
6999 list_info.y=scroll_info.y;
7000 if (window_info->mapped == MagickFalse)
7001 for (i=0; i < (int) entries; i++)
7002 if (LocaleCompare(list[i],reply) == 0)
7005 slider_info.id=i-(int) (visible_entries >> 1);
7006 if (slider_info.id < 0)
7012 XGetWidgetInfo(query,&text_info);
7013 text_info.width=reply_info.width;
7014 text_info.height=height;
7015 text_info.x=list_info.x-(int) (QuantumMargin >> 1);
7016 text_info.y=QuantumMargin;
7020 XGetWidgetInfo((
char *) NULL,&selection_info);
7021 selection_info.center=MagickFalse;
7022 selection_info.width=list_info.width;
7023 selection_info.height=(
unsigned int) ((9*height) >> 3);
7024 selection_info.x=list_info.x;
7025 state&=(
unsigned int) (~UpdateConfigurationState);
7027 if (state & RedrawWidgetState)
7032 XDrawWidgetText(display,window_info,&text_info);
7033 XDrawBeveledMatte(display,window_info,&list_info);
7034 XDrawBeveledMatte(display,window_info,&scroll_info);
7035 XDrawTriangleNorth(display,window_info,&north_info);
7036 XDrawBeveledButton(display,window_info,&slider_info);
7037 XDrawTriangleSouth(display,window_info,&south_info);
7038 XDrawBeveledMatte(display,window_info,&reply_info);
7039 XDrawMatteText(display,window_info,&reply_info);
7040 XDrawBeveledButton(display,window_info,&action_info);
7041 XDrawBeveledButton(display,window_info,&cancel_info);
7042 XHighlightWidget(display,window_info,BorderOffset,BorderOffset);
7043 selection_info.id=(~0);
7044 state|=RedrawActionState;
7045 state|=RedrawListState;
7046 state&=(
unsigned int) (~RedrawWidgetState);
7048 if (state & RedrawListState)
7053 if (slider_info.id >= (
int) (entries-visible_entries))
7054 slider_info.id=(int) (entries-visible_entries);
7055 if ((slider_info.id < 0) || (entries <= visible_entries))
7057 slider_info.y=slider_info.min_y;
7059 slider_info.y+=slider_info.id*(slider_info.max_y-
7060 slider_info.min_y+1)/(
int) entries;
7061 if (slider_info.id != selection_info.id)
7066 selection_info.id=slider_info.id;
7067 selection_info.y=list_info.y+(int) (height >> 3)+2;
7068 for (i=0; i < (int) visible_entries; i++)
7070 selection_info.raised=(slider_info.id+i) != list_info.id ?
7071 MagickTrue : MagickFalse;
7072 selection_info.text=(
char *) NULL;
7073 if ((slider_info.id+i) < (
int) entries)
7074 selection_info.text=(
char *) list[slider_info.id+i];
7075 XDrawWidgetText(display,window_info,&selection_info);
7076 selection_info.y+=(int) selection_info.height;
7081 if (slider_info.y > expose_info.y)
7083 expose_info.height=(
unsigned int) (slider_info.y-expose_info.y);
7084 expose_info.y=slider_info.y-(int) expose_info.height-(
int)
7085 slider_info.bevel_width-1;
7089 expose_info.height=(
unsigned int) (expose_info.y-slider_info.y);
7090 expose_info.y=slider_info.y+(int) slider_info.height+(
int)
7091 slider_info.bevel_width+1;
7093 XDrawTriangleNorth(display,window_info,&north_info);
7094 XDrawMatte(display,window_info,&expose_info);
7095 XDrawBeveledButton(display,window_info,&slider_info);
7096 XDrawTriangleSouth(display,window_info,&south_info);
7097 expose_info.y=slider_info.y;
7099 state&=(
unsigned int) (~RedrawListState);
7104 if (north_info.raised && south_info.raised)
7105 (void) XIfEvent(display,&event,XScreenEvent,(
char *) windows);
7111 XDelay(display,delay);
7113 (void) XCheckIfEvent(display,&event,XScreenEvent,(
char *) windows);
7114 if (north_info.raised == MagickFalse)
7115 if (slider_info.id > 0)
7121 state|=RedrawListState;
7123 if (south_info.raised == MagickFalse)
7124 if (slider_info.id < (
int) entries)
7130 state|=RedrawListState;
7132 if (event.type != ButtonRelease)
7139 if (MatteIsActive(slider_info,event.xbutton))
7144 slider_info.active=MagickTrue;
7147 if (MatteIsActive(north_info,event.xbutton))
7148 if (slider_info.id > 0)
7153 north_info.raised=MagickFalse;
7155 state|=RedrawListState;
7158 if (MatteIsActive(south_info,event.xbutton))
7159 if (slider_info.id < (
int) entries)
7164 south_info.raised=MagickFalse;
7166 state|=RedrawListState;
7169 if (MatteIsActive(scroll_info,event.xbutton))
7174 if (event.xbutton.y < slider_info.y)
7175 slider_info.id-=(int) (visible_entries-1);
7177 slider_info.id+=(int) (visible_entries-1);
7178 state|=RedrawListState;
7181 if (MatteIsActive(list_info,event.xbutton))
7189 id=slider_info.id+(
event.xbutton.y-(list_info.y+(int)
7190 (height >> 1))+1)/(
int) selection_info.height;
7191 if (
id >= (
int) entries)
7193 (void) CopyMagickString(reply_info.text,list[
id],MagickPathExtent);
7194 reply_info.highlight=MagickFalse;
7195 reply_info.marker=reply_info.text;
7196 reply_info.cursor=reply_info.text+Extent(reply_info.text);
7197 XDrawMatteText(display,window_info,&reply_info);
7198 selection_info.id=(~0);
7199 if (
id == list_info.id)
7201 action_info.raised=MagickFalse;
7202 XDrawBeveledButton(display,window_info,&action_info);
7206 state|=RedrawListState;
7209 if (MatteIsActive(action_info,event.xbutton))
7214 action_info.raised=MagickFalse;
7215 XDrawBeveledButton(display,window_info,&action_info);
7218 if (MatteIsActive(cancel_info,event.xbutton))
7223 cancel_info.raised=MagickFalse;
7224 XDrawBeveledButton(display,window_info,&cancel_info);
7227 if (MatteIsActive(reply_info,event.xbutton) == MagickFalse)
7229 if (event.xbutton.button != Button2)
7237 x=
event.xbutton.x-reply_info.x-(int) (QuantumMargin >> 2);
7238 for (i=1; i <= Extent(reply_info.marker); i++)
7239 if (XTextWidth(font_info,reply_info.marker,i) > x)
7241 reply_info.cursor=reply_info.marker+i-1;
7242 if (event.xbutton.time > (click_time+(
unsigned long) DoubleClick))
7243 reply_info.highlight=MagickFalse;
7249 (void) CopyMagickString(primary_selection,reply_info.text,
7251 (void) XSetSelectionOwner(display,XA_PRIMARY,window_info->id,
7252 event.xbutton.time);
7253 reply_info.highlight=XGetSelectionOwner(display,XA_PRIMARY) ==
7254 window_info->id ? MagickTrue : MagickFalse;
7256 XDrawMatteText(display,window_info,&reply_info);
7257 click_time=
event.xbutton.time;
7263 (void) XConvertSelection(display,XA_PRIMARY,XA_STRING,XA_STRING,
7264 window_info->id,event.xbutton.time);
7269 if (window_info->mapped == MagickFalse)
7271 if (north_info.raised == MagickFalse)
7276 delay=SuspendTime << 2;
7277 north_info.raised=MagickTrue;
7278 XDrawTriangleNorth(display,window_info,&north_info);
7280 if (south_info.raised == MagickFalse)
7285 delay=SuspendTime << 2;
7286 south_info.raised=MagickTrue;
7287 XDrawTriangleSouth(display,window_info,&south_info);
7289 if (slider_info.active)
7294 slider_info.active=MagickFalse;
7297 if (action_info.raised == MagickFalse)
7299 if (event.xbutton.window == window_info->id)
7301 if (MatteIsActive(action_info,event.xbutton))
7303 if (*reply_info.text ==
'\0')
7304 (void) XBell(display,0);
7309 action_info.raised=MagickTrue;
7310 XDrawBeveledButton(display,window_info,&action_info);
7312 if (cancel_info.raised == MagickFalse)
7314 if (event.xbutton.window == window_info->id)
7315 if (MatteIsActive(cancel_info,event.xbutton))
7317 *reply_info.text=
'\0';
7320 cancel_info.raised=MagickTrue;
7321 XDrawBeveledButton(display,window_info,&cancel_info);
7323 if (MatteIsActive(reply_info,event.xbutton) == MagickFalse)
7332 if (event.xclient.message_type != windows->wm_protocols)
7334 if (*event.xclient.data.l == (
int) windows->wm_take_focus)
7336 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
7337 (Time) event.xclient.data.l[1]);
7340 if (*event.xclient.data.l != (
int) windows->wm_delete_window)
7342 if (event.xclient.window == window_info->id)
7344 *reply_info.text=
'\0';
7350 case ConfigureNotify:
7355 if (event.xconfigure.window != window_info->id)
7357 if ((event.xconfigure.width == (
int) window_info->width) &&
7358 (event.xconfigure.height == (
int) window_info->height))
7360 window_info->width=(
unsigned int)
7361 MagickMax(event.xconfigure.width,(
int) window_info->min_width);
7362 window_info->height=(
unsigned int)
7363 MagickMax(event.xconfigure.height,(
int) window_info->min_height);
7364 state|=UpdateConfigurationState;
7369 if (event.xcrossing.window != window_info->id)
7371 state&=(
unsigned int) (~InactiveWidgetState);
7376 if (event.xexpose.window != window_info->id)
7378 if (event.xexpose.count != 0)
7380 state|=RedrawWidgetState;
7386 command[MagickPathExtent];
7397 if (event.xkey.window != window_info->id)
7399 length=XLookupString((XKeyEvent *) &event.xkey,command,
7400 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
7401 *(command+length)=
'\0';
7402 if (AreaIsActive(scroll_info,event.xkey))
7407 switch ((
int) key_symbol)
7430 slider_info.id-=(int) visible_entries;
7436 slider_info.id+=(int) visible_entries;
7442 slider_info.id=(int) entries;
7446 state|=RedrawListState;
7449 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
7454 if (*reply_info.text ==
'\0')
7456 action_info.raised=MagickFalse;
7457 XDrawBeveledButton(display,window_info,&action_info);
7461 if (key_symbol == XK_Control_L)
7463 state|=ControlState;
7466 if (state & ControlState)
7467 switch ((
int) key_symbol)
7475 *reply_info.text=
'\0';
7476 reply_info.cursor=reply_info.text;
7477 reply_info.marker=reply_info.text;
7478 reply_info.highlight=MagickFalse;
7484 XEditText(display,&reply_info,key_symbol,command,state);
7485 XDrawMatteText(display,window_info,&reply_info);
7491 command[MagickPathExtent];
7499 if (event.xkey.window != window_info->id)
7501 (void) XLookupString((XKeyEvent *) &event.xkey,command,
7502 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
7503 if (key_symbol == XK_Control_L)
7504 state&=(
unsigned int) (~ControlState);
7509 if (event.xcrossing.window != window_info->id)
7511 state|=InactiveWidgetState;
7516 mask&=(
unsigned int) (~CWX);
7517 mask&=(
unsigned int) (~CWY);
7525 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
7526 if (slider_info.active)
7531 slider_info.y=
event.xmotion.y-(int)
7532 ((slider_info.height+slider_info.bevel_width) >> 1)+1;
7533 if (slider_info.y < slider_info.min_y)
7534 slider_info.y=slider_info.min_y;
7535 if (slider_info.y > slider_info.max_y)
7536 slider_info.y=slider_info.max_y;
7538 if (slider_info.y != slider_info.min_y)
7539 slider_info.id=((int) entries*(slider_info.y-
7540 slider_info.min_y+1))/(slider_info.max_y-slider_info.min_y+1);
7541 state|=RedrawListState;
7544 if (state & InactiveWidgetState)
7546 if (action_info.raised == MatteIsActive(action_info,event.xmotion))
7551 action_info.raised=action_info.raised == MagickFalse ?
7552 MagickTrue : MagickFalse;
7553 XDrawBeveledButton(display,window_info,&action_info);
7556 if (cancel_info.raised == MatteIsActive(cancel_info,event.xmotion))
7561 cancel_info.raised=cancel_info.raised == MagickFalse ?
7562 MagickTrue : MagickFalse;
7563 XDrawBeveledButton(display,window_info,&cancel_info);
7568 case SelectionClear:
7570 reply_info.highlight=MagickFalse;
7571 XDrawMatteText(display,window_info,&reply_info);
7574 case SelectionNotify:
7592 if (event.xselection.property == (Atom) None)
7594 status=XGetWindowProperty(display,
7595 event.xselection.requestor,event.xselection.property,0L,2047L,
7596 MagickTrue,XA_STRING,&type,&format,&length,&after,&data);
7597 if ((status != Success) || (type != XA_STRING) || (format == 32) ||
7600 if ((Extent(reply_info.text)+(
int) length) >= (MagickPathExtent-1))
7601 (void) XBell(display,0);
7607 *(data+length)=
'\0';
7608 XEditText(display,&reply_info,(KeySym) XK_Insert,(
char *) data,
7610 XDrawMatteText(display,window_info,&reply_info);
7611 state|=RedrawActionState;
7613 (void) XFree((
void *) data);
7616 case SelectionRequest:
7621 XSelectionRequestEvent
7624 if (reply_info.highlight == MagickFalse)
7629 request=(&(
event.xselectionrequest));
7630 (void) XChangeProperty(request->display,request->requestor,
7631 request->property,request->target,8,PropModeReplace,
7632 (
unsigned char *) primary_selection,Extent(primary_selection));
7633 notify.type=SelectionNotify;
7634 notify.send_event=MagickTrue;
7635 notify.display=request->display;
7636 notify.requestor=request->requestor;
7637 notify.selection=request->selection;
7638 notify.target=request->target;
7639 notify.time=request->time;
7640 if (request->property == None)
7641 notify.property=request->target;
7643 notify.property=request->property;
7644 (void) XSendEvent(request->display,request->requestor,False,NoEventMask,
7645 (XEvent *) ¬ify);
7650 }
while ((state & ExitState) == 0);
7651 XSetCursorState(display,windows,MagickFalse);
7652 (void) XWithdrawWindow(display,window_info->id,window_info->screen);
7653 XCheckRefreshWindows(display,windows);
7694MagickPrivate
int XMenuWidget(Display *display,XWindows *windows,
7695 const char *title,
const char *
const *selections,
char *item)
7721 XSetWindowAttributes
7735 assert(display != (Display *) NULL);
7736 assert(windows != (XWindows *) NULL);
7737 assert(title != (
char *) NULL);
7738 assert(selections != (
const char **) NULL);
7739 assert(item != (
char *) NULL);
7740 if (IsEventLogging() != MagickFalse)
7741 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",title);
7742 font_info=windows->widget.font_info;
7743 windows->widget.width=submenu_info.active == 0 ?
7744 WidgetTextWidth(font_info,(
char *) title) : 0;
7745 for (
id=0; selections[id] != (
char *) NULL;
id++)
7747 width=WidgetTextWidth(font_info,(
char *) selections[
id]);
7748 if (width > windows->widget.width)
7749 windows->widget.width=width;
7751 number_selections=(
unsigned int)
id;
7752 XGetWidgetInfo((
char *) NULL,&menu_info);
7753 title_height=(
unsigned int) (submenu_info.active == 0 ?
7754 (3*(font_info->descent+font_info->ascent) >> 1)+5 : 2);
7755 width=WidgetTextWidth(font_info,(
char *) title);
7756 height=(
unsigned int) ((3*(font_info->ascent+font_info->descent)) >> 1);
7760 windows->widget.width+=(
unsigned int) QuantumMargin+
7761 (menu_info.bevel_width << 1);
7762 top_offset=title_height+menu_info.bevel_width-1;
7763 windows->widget.height=top_offset+number_selections*height+4;
7764 windows->widget.min_width=windows->widget.width;
7765 windows->widget.min_height=windows->widget.height;
7766 XQueryPosition(display,windows->widget.root,&x,&y);
7767 windows->widget.x=x-(int) (QuantumMargin >> 1);
7768 if (submenu_info.active != 0)
7770 windows->widget.x=windows->command.x+(int) windows->command.width-
7772 toggle_info.raised=MagickTrue;
7773 XDrawTriangleEast(display,&windows->command,&toggle_info);
7775 windows->widget.y=submenu_info.active == 0 ? y-(int)
7776 ((3*title_height) >> 2) : y;
7777 if (submenu_info.active != 0)
7778 windows->widget.y=windows->command.y+submenu_info.y;
7779 XConstrainWindowPosition(display,&windows->widget);
7783 window_attributes.override_redirect=MagickTrue;
7784 (void) XChangeWindowAttributes(display,windows->widget.id,
7785 (
size_t) CWOverrideRedirect,&window_attributes);
7786 window_changes.width=(int) windows->widget.width;
7787 window_changes.height=(int) windows->widget.height;
7788 window_changes.x=windows->widget.x;
7789 window_changes.y=windows->widget.y;
7790 (void) XReconfigureWMWindow(display,windows->widget.id,windows->widget.screen,
7791 (
unsigned int) (CWWidth | CWHeight | CWX | CWY),&window_changes);
7792 (void) XMapRaised(display,windows->widget.id);
7793 windows->widget.mapped=MagickFalse;
7797 selection_info.height=height;
7798 cursor=XCreateFontCursor(display,XC_right_ptr);
7799 (void) XCheckDefineCursor(display,windows->image.id,cursor);
7800 (void) XCheckDefineCursor(display,windows->command.id,cursor);
7801 (void) XCheckDefineCursor(display,windows->widget.id,cursor);
7802 state=UpdateConfigurationState;
7805 if (state & UpdateConfigurationState)
7810 XGetWidgetInfo((
char *) NULL,&menu_info);
7811 menu_info.bevel_width--;
7812 menu_info.width=windows->widget.width-((menu_info.bevel_width) << 1);
7813 menu_info.height=windows->widget.height-((menu_info.bevel_width) << 1);
7814 menu_info.x=(int) menu_info.bevel_width;
7815 menu_info.y=(int) menu_info.bevel_width;
7816 XGetWidgetInfo((
char *) NULL,&selection_info);
7817 selection_info.center=MagickFalse;
7818 selection_info.width=menu_info.width;
7819 selection_info.height=height;
7820 selection_info.x=menu_info.x;
7821 highlight_info=selection_info;
7822 highlight_info.bevel_width--;
7823 highlight_info.width-=(highlight_info.bevel_width << 1);
7824 highlight_info.height-=(highlight_info.bevel_width << 1);
7825 highlight_info.x+=(int) highlight_info.bevel_width;
7826 state&=(
unsigned int) (~UpdateConfigurationState);
7828 if (state & RedrawWidgetState)
7833 if (submenu_info.active == 0)
7835 y=(int) title_height;
7836 XSetBevelColor(display,&windows->widget,MagickFalse);
7837 (void) XDrawLine(display,windows->widget.id,
7838 windows->widget.widget_context,selection_info.x,y-1,
7839 (
int) selection_info.width,y-1);
7840 XSetBevelColor(display,&windows->widget,MagickTrue);
7841 (void) XDrawLine(display,windows->widget.id,
7842 windows->widget.widget_context,selection_info.x,y,
7843 (
int) selection_info.width,y);
7844 (void) XSetFillStyle(display,windows->widget.widget_context,
7850 selection_info.center=MagickTrue;
7851 selection_info.y=(int) menu_info.bevel_width;
7852 selection_info.text=(
char *) title;
7853 if (submenu_info.active == 0)
7854 XDrawWidgetText(display,&windows->widget,&selection_info);
7855 selection_info.center=MagickFalse;
7856 selection_info.y=(int) top_offset;
7857 for (
id=0;
id < (int) number_selections;
id++)
7859 selection_info.text=(
char *) selections[
id];
7860 XDrawWidgetText(display,&windows->widget,&selection_info);
7861 highlight_info.y=selection_info.y+(int) highlight_info.bevel_width;
7862 if (
id == selection_info.id)
7863 XDrawBevel(display,&windows->widget,&highlight_info);
7864 selection_info.y+=(int) selection_info.height;
7866 XDrawBevel(display,&windows->widget,&menu_info);
7867 state&=(
unsigned int) (~RedrawWidgetState);
7869 if (number_selections > 2)
7874 y=((int) top_offset+(int) selection_info.height*(int)
7875 (number_selections-1));
7876 XSetBevelColor(display,&windows->widget,MagickFalse);
7877 (void) XDrawLine(display,windows->widget.id,
7878 windows->widget.widget_context,selection_info.x,y-1,
7879 (
int) selection_info.width,y-1);
7880 XSetBevelColor(display,&windows->widget,MagickTrue);
7881 (void) XDrawLine(display,windows->widget.id,
7882 windows->widget.widget_context,selection_info.x,y,
7883 (
int) selection_info.width,y);
7884 (void) XSetFillStyle(display,windows->widget.widget_context,FillSolid);
7889 (void) XIfEvent(display,&event,XScreenEvent,(
char *) windows);
7894 if (event.xbutton.window != windows->widget.id)
7899 if (event.xbutton.window == windows->command.id)
7900 (void) XPutBackEvent(display,&event);
7901 selection_info.id=(~0);
7906 state&=(
unsigned int) (~InactiveWidgetState);
7907 if (selection_info.height == 0)
7909 id=(
event.xbutton.y-(int) top_offset)/(
int) selection_info.height;
7910 selection_info.id=id;
7911 if ((
id < 0) || (
id >= (
int) number_selections))
7916 selection_info.y=((int) top_offset+
id*(int) selection_info.height);
7917 selection_info.text=(
char *) selections[
id];
7918 XDrawWidgetText(display,&windows->widget,&selection_info);
7919 highlight_info.y=selection_info.y+(int) highlight_info.bevel_width;
7920 XDrawBevel(display,&windows->widget,&highlight_info);
7925 if (windows->widget.mapped == MagickFalse)
7927 if (event.xbutton.window == windows->command.id)
7928 if ((state & InactiveWidgetState) == 0)
7933 XSetCursorState(display,windows,MagickFalse);
7938 case ConfigureNotify:
7943 if (event.xconfigure.window != windows->widget.id)
7945 if ((event.xconfigure.width == (
int) windows->widget.width) &&
7946 (event.xconfigure.height == (
int) windows->widget.height))
7948 windows->widget.width=(
unsigned int)
7949 MagickMax(event.xconfigure.width,(
int) windows->widget.min_width);
7950 windows->widget.height=(
unsigned int)
7951 MagickMax(event.xconfigure.height,(
int) windows->widget.min_height);
7952 state|=UpdateConfigurationState;
7957 if (event.xcrossing.window != windows->widget.id)
7959 if (event.xcrossing.state == 0)
7961 state&=(
unsigned int) (~InactiveWidgetState);
7962 if (selection_info.height == 0)
7964 id=((
event.xcrossing.y-(int) top_offset)/(int) selection_info.height);
7965 if ((selection_info.id >= 0) &&
7966 (selection_info.id < (
int) number_selections))
7971 if (
id == selection_info.id)
7973 selection_info.y=((int) top_offset+selection_info.id*(int)
7974 selection_info.height);
7975 selection_info.text=(
char *) selections[selection_info.id];
7976 XDrawWidgetText(display,&windows->widget,&selection_info);
7978 if ((
id < 0) || (
id >= (
int) number_selections))
7983 selection_info.id=id;
7984 selection_info.y=((int) top_offset+selection_info.id*(int)
7985 selection_info.height);
7986 selection_info.text=(
char *) selections[selection_info.id];
7987 XDrawWidgetText(display,&windows->widget,&selection_info);
7988 highlight_info.y=selection_info.y+(int) highlight_info.bevel_width;
7989 XDrawBevel(display,&windows->widget,&highlight_info);
7994 if (event.xexpose.window != windows->widget.id)
7996 if (event.xexpose.count != 0)
7998 state|=RedrawWidgetState;
8003 if (event.xcrossing.window != windows->widget.id)
8005 state|=InactiveWidgetState;
8006 id=selection_info.id;
8007 if ((
id < 0) || (
id >= (
int) number_selections))
8012 selection_info.y=((int) top_offset+
id*(int) selection_info.height);
8013 selection_info.id=(~0);
8014 selection_info.text=(
char *) selections[
id];
8015 XDrawWidgetText(display,&windows->widget,&selection_info);
8023 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
8024 if (submenu_info.active != 0)
8025 if (event.xmotion.window == windows->command.id)
8027 if ((state & InactiveWidgetState) == 0)
8029 if (MatteIsActive(submenu_info,event.xmotion) == MagickFalse)
8031 selection_info.id=(~0);
8038 if (WindowIsActive(windows->command,event.xmotion))
8040 selection_info.id=(~0);
8046 if (event.xmotion.window != windows->widget.id)
8048 if (state & InactiveWidgetState)
8050 if (selection_info.height == 0)
8052 id=(
event.xmotion.y-(int) top_offset)/(
int) selection_info.height;
8053 if ((selection_info.id >= 0) &&
8054 (selection_info.id < (
int) number_selections))
8059 if (
id == selection_info.id)
8061 selection_info.y=((int) top_offset+selection_info.id*(int)
8062 selection_info.height);
8063 selection_info.text=(
char *) selections[selection_info.id];
8064 XDrawWidgetText(display,&windows->widget,&selection_info);
8066 selection_info.id=id;
8067 if ((
id < 0) || (
id >= (
int) number_selections))
8072 selection_info.y=((int) top_offset+
id*(int) selection_info.height);
8073 selection_info.text=(
char *) selections[
id];
8074 XDrawWidgetText(display,&windows->widget,&selection_info);
8075 highlight_info.y=selection_info.y+(int) highlight_info.bevel_width;
8076 XDrawBevel(display,&windows->widget,&highlight_info);
8082 }
while ((state & ExitState) == 0);
8083 (void) XFreeCursor(display,cursor);
8084 window_attributes.override_redirect=MagickFalse;
8085 (void) XChangeWindowAttributes(display,windows->widget.id,
8086 (
size_t) CWOverrideRedirect,&window_attributes);
8087 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
8088 XCheckRefreshWindows(display,windows);
8089 if (submenu_info.active != 0)
8091 submenu_info.active=MagickFalse;
8092 toggle_info.raised=MagickFalse;
8093 XDrawTriangleEast(display,&windows->command,&toggle_info);
8095 if ((selection_info.id < 0) || (selection_info.id >= (
int) number_selections))
8097 (void) CopyMagickString(item,selections[selection_info.id],MagickPathExtent);
8098 return(selection_info.id);
8133MagickPrivate
void XNoticeWidget(Display *display,XWindows *windows,
8134 const char *reason,
const char *description)
8136#define DismissButtonText "Dismiss"
8177 assert(display != (Display *) NULL);
8178 assert(windows != (XWindows *) NULL);
8179 assert(reason != (
char *) NULL);
8180 if (IsEventLogging() != MagickFalse)
8181 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",reason);
8182 XDelay(display,SuspendTime << 3);
8183 XSetCursorState(display,windows,MagickTrue);
8184 XCheckRefreshWindows(display,windows);
8185 font_info=windows->widget.font_info;
8186 width=WidgetTextWidth(font_info,DismissButtonText);
8187 text=GetLocaleExceptionMessage(XServerError,reason);
8188 if (text != (
char *) NULL)
8189 if (WidgetTextWidth(font_info,(
char *) text) > width)
8190 width=WidgetTextWidth(font_info,(
char *) text);
8191 if (description != (
char *) NULL)
8193 text=GetLocaleExceptionMessage(XServerError,description);
8194 if (text != (
char *) NULL)
8195 if (WidgetTextWidth(font_info,(
char *) text) > width)
8196 width=WidgetTextWidth(font_info,(
char *) text);
8198 height=(
unsigned int) (font_info->ascent+font_info->descent);
8202 windows->widget.width=width+(
unsigned int) (4*QuantumMargin);
8203 windows->widget.min_width=width+(
unsigned int) QuantumMargin;
8204 if (windows->widget.width < windows->widget.min_width)
8205 windows->widget.width=windows->widget.min_width;
8206 windows->widget.height=(
unsigned int) (12*height);
8207 windows->widget.min_height=(
unsigned int) (7*height);
8208 if (windows->widget.height < windows->widget.min_height)
8209 windows->widget.height=windows->widget.min_height;
8210 XConstrainWindowPosition(display,&windows->widget);
8214 (void) CopyMagickString(windows->widget.name,
"Notice",MagickPathExtent);
8215 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
8216 if (status != False)
8218 XSetWMName(display,windows->widget.id,&window_name);
8219 XSetWMIconName(display,windows->widget.id,&window_name);
8220 (void) XFree((
void *) window_name.value);
8222 window_changes.width=(int) windows->widget.width;
8223 window_changes.height=(int) windows->widget.height;
8224 window_changes.x=windows->widget.x;
8225 window_changes.y=windows->widget.y;
8226 (void) XReconfigureWMWindow(display,windows->widget.id,windows->widget.screen,
8227 (
unsigned int) (CWWidth | CWHeight | CWX | CWY),&window_changes);
8228 (void) XMapRaised(display,windows->widget.id);
8229 windows->widget.mapped=MagickFalse;
8230 (void) XBell(display,0);
8234 timer=GetMagickTime()+Timeout;
8235 state=UpdateConfigurationState;
8238 if (GetMagickTime() > timer)
8240 if (state & UpdateConfigurationState)
8245 XGetWidgetInfo(DismissButtonText,&dismiss_info);
8246 dismiss_info.width=(
unsigned int) QuantumMargin+
8247 WidgetTextWidth(font_info,DismissButtonText);
8248 dismiss_info.height=(
unsigned int) ((3*height) >> 1);
8249 dismiss_info.x=(int)
8250 ((windows->widget.width >> 1)-(dismiss_info.width >> 1));
8251 dismiss_info.y=(int)
8252 (windows->widget.height-(dismiss_info.height << 1));
8253 state&=(
unsigned int) (~UpdateConfigurationState);
8255 if (state & RedrawWidgetState)
8260 width=WidgetTextWidth(font_info,(
char *) reason);
8261 x=(int) ((windows->widget.width >> 1)-(width >> 1));
8262 y=(int) ((windows->widget.height >> 1)-(height << 1));
8263 (void) XDrawString(display,windows->widget.id,
8264 windows->widget.annotate_context,x,y,(
char *) reason,Extent(reason));
8265 if (description != (
char *) NULL)
8267 width=WidgetTextWidth(font_info,(
char *) description);
8268 x=(int) ((windows->widget.width >> 1)-(width >> 1));
8270 (void) XDrawString(display,windows->widget.id,
8271 windows->widget.annotate_context,x,y,(
char *) description,
8272 Extent(description));
8274 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
8275 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
8276 state&=(
unsigned int) (~RedrawWidgetState);
8281 if (XCheckIfEvent(display,&event,XScreenEvent,(
char *) windows) == MagickFalse)
8286 XDelay(display,SuspendTime << 2);
8293 if (MatteIsActive(dismiss_info,event.xbutton))
8298 dismiss_info.raised=MagickFalse;
8299 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
8306 if (windows->widget.mapped == MagickFalse)
8308 if (dismiss_info.raised == MagickFalse)
8310 if (event.xbutton.window == windows->widget.id)
8311 if (MatteIsActive(dismiss_info,event.xbutton))
8313 dismiss_info.raised=MagickTrue;
8314 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
8323 if (event.xclient.message_type != windows->wm_protocols)
8325 if (*event.xclient.data.l == (
int) windows->wm_take_focus)
8327 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
8328 (Time) event.xclient.data.l[1]);
8331 if (*event.xclient.data.l != (
int) windows->wm_delete_window)
8333 if (event.xclient.window == windows->widget.id)
8340 case ConfigureNotify:
8345 if (event.xconfigure.window != windows->widget.id)
8347 if ((event.xconfigure.width == (
int) windows->widget.width) &&
8348 (event.xconfigure.height == (
int) windows->widget.height))
8350 windows->widget.width=(
unsigned int)
8351 MagickMax(event.xconfigure.width,(
int) windows->widget.min_width);
8352 windows->widget.height=(
unsigned int)
8353 MagickMax(event.xconfigure.height,(
int) windows->widget.min_height);
8354 state|=UpdateConfigurationState;
8359 if (event.xcrossing.window != windows->widget.id)
8361 state&=(
unsigned int) (~InactiveWidgetState);
8366 if (event.xexpose.window != windows->widget.id)
8368 if (event.xexpose.count != 0)
8370 state|=RedrawWidgetState;
8376 command[MagickPathExtent];
8384 if (event.xkey.window != windows->widget.id)
8386 (void) XLookupString((XKeyEvent *) &event.xkey,command,
8387 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
8388 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
8390 dismiss_info.raised=MagickFalse;
8391 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
8399 if (event.xcrossing.window != windows->widget.id)
8401 state|=InactiveWidgetState;
8409 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
8410 if (state & InactiveWidgetState)
8412 if (dismiss_info.raised == MatteIsActive(dismiss_info,event.xmotion))
8417 dismiss_info.raised=
8418 dismiss_info.raised == MagickFalse ? MagickTrue : MagickFalse;
8419 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
8427 }
while ((state & ExitState) == 0);
8428 XSetCursorState(display,windows,MagickFalse);
8429 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
8430 XCheckRefreshWindows(display,windows);
8463MagickPrivate MagickBooleanType XPreferencesWidget(Display *display,
8464 XResourceInfo *resource_info,XWindows *windows)
8466#define ApplyButtonText "Apply"
8467#define CacheButtonText "%lu mega-bytes of memory in the undo edit cache "
8468#define CancelButtonText "Cancel"
8469#define NumberPreferences 8
8474 "display image centered on a backdrop",
8475 "confirm on program exit",
8476 "confirm on image edits",
8477 "correct image for display gamma",
8478 "display warning messages",
8479 "apply Floyd/Steinberg error diffusion to image",
8480 "use a shared colormap for colormapped X visuals",
8481 "display images as an X server pixmap"
8485 cache[MagickPathExtent];
8518 preferences_info[NumberPreferences];
8526 if (IsEventLogging() != MagickFalse)
8527 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
8528 assert(display != (Display *) NULL);
8529 assert(resource_info != (XResourceInfo *) NULL);
8530 assert(windows != (XWindows *) NULL);
8531 XCheckRefreshWindows(display,windows);
8532 font_info=windows->widget.font_info;
8533 text_width=WidgetTextWidth(font_info,CacheButtonText);
8534 for (i=0; i < NumberPreferences; i++)
8535 if (WidgetTextWidth(font_info,(
char *) Preferences[i]) > text_width)
8536 text_width=WidgetTextWidth(font_info,(
char *) Preferences[i]);
8537 width=WidgetTextWidth(font_info,ApplyButtonText);
8538 if (WidgetTextWidth(font_info,CancelButtonText) > width)
8539 width=WidgetTextWidth(font_info,CancelButtonText);
8540 width+=(
unsigned int) QuantumMargin;
8541 height=(
unsigned int) (font_info->ascent+font_info->descent);
8545 windows->widget.width=(
unsigned int) (MagickMax((
int) (width << 1),
8546 (
int) text_width)+6*QuantumMargin);
8547 windows->widget.min_width=(width << 1)+(
unsigned int) QuantumMargin;
8548 if (windows->widget.width < windows->widget.min_width)
8549 windows->widget.width=windows->widget.min_width;
8550 windows->widget.height=(
unsigned int) (7*(
int) height+NumberPreferences*
8551 ((
int) height+(QuantumMargin >> 1)));
8552 windows->widget.min_height=(
unsigned int) (7*(
int) height+NumberPreferences*
8553 ((
int) height+(QuantumMargin >> 1)));
8554 if (windows->widget.height < windows->widget.min_height)
8555 windows->widget.height=windows->widget.min_height;
8556 XConstrainWindowPosition(display,&windows->widget);
8560 (void) CopyMagickString(windows->widget.name,
"Preferences",MagickPathExtent);
8561 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
8562 if (status != False)
8564 XSetWMName(display,windows->widget.id,&window_name);
8565 XSetWMIconName(display,windows->widget.id,&window_name);
8566 (void) XFree((
void *) window_name.value);
8568 window_changes.width=(int) windows->widget.width;
8569 window_changes.height=(int) windows->widget.height;
8570 window_changes.x=windows->widget.x;
8571 window_changes.y=windows->widget.y;
8572 (void) XReconfigureWMWindow(display,windows->widget.id,windows->widget.screen,
8573 (
unsigned int) (CWWidth | CWHeight | CWX | CWY),&window_changes);
8574 (void) XMapRaised(display,windows->widget.id);
8575 windows->widget.mapped=MagickFalse;
8579 state=UpdateConfigurationState;
8580 XSetCursorState(display,windows,MagickTrue);
8583 if (state & UpdateConfigurationState)
8588 XGetWidgetInfo(CancelButtonText,&cancel_info);
8589 cancel_info.width=width;
8590 cancel_info.height=(
unsigned int) (3*height) >> 1;
8591 cancel_info.x=(int) windows->widget.width-(
int) cancel_info.width-
8592 (QuantumMargin << 1);
8593 cancel_info.y=(int) windows->widget.height-(
int) cancel_info.height-
8595 XGetWidgetInfo(ApplyButtonText,&apply_info);
8596 apply_info.width=width;
8597 apply_info.height=(
unsigned int) (3*height) >> 1;
8598 apply_info.x=QuantumMargin << 1;
8599 apply_info.y=cancel_info.y;
8600 y=(int) (height << 1);
8601 for (i=0; i < NumberPreferences; i++)
8603 XGetWidgetInfo(Preferences[i],&preferences_info[i]);
8604 preferences_info[i].bevel_width--;
8605 preferences_info[i].width=(
unsigned int) QuantumMargin >> 1;
8606 preferences_info[i].height=(
unsigned int) QuantumMargin >> 1;
8607 preferences_info[i].x=QuantumMargin << 1;
8608 preferences_info[i].y=y;
8609 y+=(int) height+(QuantumMargin >> 1);
8611 preferences_info[0].raised=resource_info->backdrop ==
8612 MagickFalse ? MagickTrue : MagickFalse;
8613 preferences_info[1].raised=resource_info->confirm_exit ==
8614 MagickFalse ? MagickTrue : MagickFalse;
8615 preferences_info[2].raised=resource_info->confirm_edit ==
8616 MagickFalse ? MagickTrue : MagickFalse;
8617 preferences_info[3].raised=resource_info->gamma_correct ==
8618 MagickFalse ? MagickTrue : MagickFalse;
8619 preferences_info[4].raised=resource_info->display_warnings ==
8620 MagickFalse ? MagickTrue : MagickFalse;
8621 preferences_info[5].raised=
8622 resource_info->quantize_info->dither_method == NoDitherMethod ?
8623 MagickTrue : MagickFalse;
8624 preferences_info[6].raised=resource_info->colormap !=
8625 SharedColormap ? MagickTrue : MagickFalse;
8626 preferences_info[7].raised=resource_info->use_pixmap ==
8627 MagickFalse ? MagickTrue : MagickFalse;
8628 (void) FormatLocaleString(cache,MagickPathExtent,CacheButtonText,
8629 (
unsigned long) resource_info->undo_cache);
8630 XGetWidgetInfo(cache,&cache_info);
8631 cache_info.bevel_width--;
8632 cache_info.width=(
unsigned int) QuantumMargin >> 1;
8633 cache_info.height=(
unsigned int) QuantumMargin >> 1;
8634 cache_info.x=QuantumMargin << 1;
8636 state&=(
unsigned int) (~UpdateConfigurationState);
8638 if (state & RedrawWidgetState)
8643 XDrawBeveledButton(display,&windows->widget,&apply_info);
8644 XDrawBeveledButton(display,&windows->widget,&cancel_info);
8645 for (i=0; i < NumberPreferences; i++)
8646 XDrawBeveledButton(display,&windows->widget,&preferences_info[i]);
8647 XDrawTriangleEast(display,&windows->widget,&cache_info);
8648 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
8649 state&=(
unsigned int) (~RedrawWidgetState);
8654 (void) XIfEvent(display,&event,XScreenEvent,(
char *) windows);
8659 if (MatteIsActive(apply_info,event.xbutton))
8664 apply_info.raised=MagickFalse;
8665 XDrawBeveledButton(display,&windows->widget,&apply_info);
8668 if (MatteIsActive(cancel_info,event.xbutton))
8673 cancel_info.raised=MagickFalse;
8674 XDrawBeveledButton(display,&windows->widget,&cancel_info);
8677 for (i=0; i < NumberPreferences; i++)
8678 if (MatteIsActive(preferences_info[i],event.xbutton))
8683 preferences_info[i].raised=preferences_info[i].raised ==
8684 MagickFalse ? MagickTrue : MagickFalse;
8685 XDrawBeveledButton(display,&windows->widget,&preferences_info[i]);
8688 if (MatteIsActive(cache_info,event.xbutton))
8693 x=cache_info.x+(int) cache_info.width+(
int) cache_info.bevel_width+
8694 (QuantumMargin >> 1);
8695 y=cache_info.y+(int) ((cache_info.height-height) >> 1);
8696 width=WidgetTextWidth(font_info,cache);
8697 (void) XClearArea(display,windows->widget.id,x,y,width,height,
8699 resource_info->undo_cache<<=1;
8700 if (resource_info->undo_cache > 256)
8701 resource_info->undo_cache=1;
8702 (void) FormatLocaleString(cache,MagickPathExtent,CacheButtonText,
8703 (
unsigned long) resource_info->undo_cache);
8704 cache_info.raised=MagickFalse;
8705 XDrawTriangleEast(display,&windows->widget,&cache_info);
8712 if (windows->widget.mapped == MagickFalse)
8714 if (apply_info.raised == MagickFalse)
8716 if (event.xbutton.window == windows->widget.id)
8717 if (MatteIsActive(apply_info,event.xbutton))
8719 apply_info.raised=MagickTrue;
8720 XDrawBeveledButton(display,&windows->widget,&apply_info);
8721 apply_info.raised=MagickFalse;
8723 if (cancel_info.raised == MagickFalse)
8725 if (event.xbutton.window == windows->widget.id)
8726 if (MatteIsActive(cancel_info,event.xbutton))
8728 cancel_info.raised=MagickTrue;
8729 XDrawBeveledButton(display,&windows->widget,&cancel_info);
8731 if (cache_info.raised == MagickFalse)
8733 cache_info.raised=MagickTrue;
8734 XDrawTriangleEast(display,&windows->widget,&cache_info);
8743 if (event.xclient.message_type != windows->wm_protocols)
8745 if (*event.xclient.data.l == (
int) windows->wm_take_focus)
8747 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
8748 (Time) event.xclient.data.l[1]);
8751 if (*event.xclient.data.l != (
int) windows->wm_delete_window)
8753 if (event.xclient.window == windows->widget.id)
8760 case ConfigureNotify:
8765 if (event.xconfigure.window != windows->widget.id)
8767 if ((event.xconfigure.width == (
int) windows->widget.width) &&
8768 (event.xconfigure.height == (
int) windows->widget.height))
8770 windows->widget.width=(
unsigned int)
8771 MagickMax(event.xconfigure.width,(
int) windows->widget.min_width);
8772 windows->widget.height=(
unsigned int)
8773 MagickMax(event.xconfigure.height,(
int) windows->widget.min_height);
8774 state|=UpdateConfigurationState;
8779 if (event.xcrossing.window != windows->widget.id)
8781 state&=(
unsigned int) (~InactiveWidgetState);
8786 if (event.xexpose.window != windows->widget.id)
8788 if (event.xexpose.count != 0)
8790 state|=RedrawWidgetState;
8796 command[MagickPathExtent];
8804 if (event.xkey.window != windows->widget.id)
8806 (void) XLookupString((XKeyEvent *) &event.xkey,command,
8807 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
8808 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
8810 apply_info.raised=MagickFalse;
8811 XDrawBeveledButton(display,&windows->widget,&apply_info);
8819 if (event.xcrossing.window != windows->widget.id)
8821 state|=InactiveWidgetState;
8829 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
8830 if (state & InactiveWidgetState)
8832 if (apply_info.raised == MatteIsActive(apply_info,event.xmotion))
8838 apply_info.raised == MagickFalse ? MagickTrue : MagickFalse;
8839 XDrawBeveledButton(display,&windows->widget,&apply_info);
8842 if (cancel_info.raised == MatteIsActive(cancel_info,event.xmotion))
8848 cancel_info.raised == MagickFalse ? MagickTrue : MagickFalse;
8849 XDrawBeveledButton(display,&windows->widget,&cancel_info);
8857 }
while ((state & ExitState) == 0);
8858 XSetCursorState(display,windows,MagickFalse);
8859 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
8860 XCheckRefreshWindows(display,windows);
8861 if (apply_info.raised)
8862 return(MagickFalse);
8866 resource_info->backdrop=
8867 preferences_info[0].raised == MagickFalse ? MagickTrue : MagickFalse;
8868 resource_info->confirm_exit=
8869 preferences_info[1].raised == MagickFalse ? MagickTrue : MagickFalse;
8870 resource_info->confirm_edit=
8871 preferences_info[2].raised == MagickFalse ? MagickTrue : MagickFalse;
8872 resource_info->gamma_correct=
8873 preferences_info[3].raised == MagickFalse ? MagickTrue : MagickFalse;
8874 resource_info->display_warnings=
8875 preferences_info[4].raised == MagickFalse ? MagickTrue : MagickFalse;
8876 resource_info->quantize_info->dither_method=
8877 preferences_info[5].raised == MagickFalse ?
8878 RiemersmaDitherMethod : NoDitherMethod;
8879 resource_info->colormap=SharedColormap;
8880 if (preferences_info[6].raised)
8881 resource_info->colormap=PrivateColormap;
8882 resource_info->use_pixmap=
8883 preferences_info[7].raised == MagickFalse ? MagickTrue : MagickFalse;
8884 XUserPreferences(resource_info);
8924MagickPrivate
void XProgressMonitorWidget(Display *display,XWindows *windows,
8925 const char *task,
const MagickOffsetType offset,
const MagickSizeType span)
8933 assert(display != (Display *) NULL);
8934 assert(windows != (XWindows *) NULL);
8935 assert(task != (
const char *) NULL);
8936 if (IsEventLogging() != MagickFalse)
8937 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",task);
8943 while (XCheckTypedWindowEvent(display,windows->command.id,Expose,&event))
8944 (void) XCommandWidget(display,windows,(
const char *
const *) NULL,&event);
8945 while (XCheckTypedWindowEvent(display,windows->image.id,Expose,&event))
8946 XRefreshWindow(display,&windows->image,&event);
8947 while (XCheckTypedWindowEvent(display,windows->info.id,Expose,&event))
8948 if (monitor_info.text != (
char *) NULL)
8949 XInfoWidget(display,windows,monitor_info.text);
8953 if ((windows->info.mapped == MagickFalse) || (task != monitor_info.text))
8954 XInfoWidget(display,windows,task);
8955 width=(
unsigned int) (((offset+1)*((
int) windows->info.width-
8956 (2*monitor_info.x)))/(
int) span);
8957 if (width < monitor_info.width)
8959 monitor_info.raised=MagickTrue;
8960 XDrawWidgetText(display,&windows->info,&monitor_info);
8961 monitor_info.raised=MagickFalse;
8963 monitor_info.width=width;
8964 XDrawWidgetText(display,&windows->info,&monitor_info);
8965 (void) XFlush(display);
9004MagickPrivate
void XTextViewWidget(Display *display,
9005 const XResourceInfo *resource_info,XWindows *windows,
9006 const MagickBooleanType mono,
const char *title,
const char **textlist)
9008#define DismissButtonText "Dismiss"
9011 primary_selection[MagickPathExtent];
9016 static MagickStatusType
9017 mask = (MagickStatusType) (CWWidth | CWHeight | CWX | CWY);
9059 assert(display != (Display *) NULL);
9060 assert(resource_info != (XResourceInfo *) NULL);
9061 assert(windows != (XWindows *) NULL);
9062 assert(title != (
const char *) NULL);
9063 assert(textlist != (
const char **) NULL);
9064 if (IsEventLogging() != MagickFalse)
9065 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",title);
9066 XSetCursorState(display,windows,MagickTrue);
9067 XCheckRefreshWindows(display,windows);
9068 if (textlist == (
const char **) NULL)
9070 XNoticeWidget(display,windows,
"No text to view:",(
char *) NULL);
9076 font_info=windows->widget.font_info;
9077 text_info=(XFontStruct *) NULL;
9078 if (mono != MagickFalse)
9079 text_info=XBestFont(display,resource_info,MagickTrue);
9080 if (text_info == (XFontStruct *) NULL)
9081 text_info=windows->widget.font_info;
9083 for (i=0; textlist[i] != (
char *) NULL; i++)
9084 if (WidgetTextWidth(text_info,(
char *) textlist[i]) > text_width)
9085 text_width=(
unsigned int) XTextWidth(text_info,(
char *) textlist[i],
9086 MagickMin(Extent(textlist[i]),160));
9087 lines=(
unsigned int) i;
9088 width=WidgetTextWidth(font_info,DismissButtonText);
9089 width+=(
unsigned int) QuantumMargin;
9090 height=(
unsigned int) (text_info->ascent+text_info->descent);
9094 windows->widget.width=(
unsigned int) (MagickMin((
int) text_width,
9095 (
int) MaxTextWidth)+5*QuantumMargin);
9096 windows->widget.min_width=(
unsigned int) ((
int) MinTextWidth+4*QuantumMargin);
9097 if (windows->widget.width < windows->widget.min_width)
9098 windows->widget.width=windows->widget.min_width;
9099 windows->widget.height=(
unsigned int) (MagickMin(MagickMax((
int) lines,3),32)*
9100 (
int) height+(
int) ((13*height) >> 1)+((9*QuantumMargin) >> 1));
9101 windows->widget.min_height=(3*height+((13*height) >> 1)+(
unsigned int) ((9*
9102 QuantumMargin) >> 1));
9103 if (windows->widget.height < windows->widget.min_height)
9104 windows->widget.height=windows->widget.min_height;
9105 XConstrainWindowPosition(display,&windows->widget);
9109 (void) CopyMagickString(windows->widget.name,title,MagickPathExtent);
9110 status=XStringListToTextProperty(&windows->widget.name,1,&window_name);
9111 if (status != False)
9113 XSetWMName(display,windows->widget.id,&window_name);
9114 XSetWMIconName(display,windows->widget.id,&window_name);
9115 (void) XFree((
void *) window_name.value);
9117 window_changes.width=(int) windows->widget.width;
9118 window_changes.height=(int) windows->widget.height;
9119 window_changes.x=windows->widget.x;
9120 window_changes.y=windows->widget.y;
9121 (void) XReconfigureWMWindow(display,windows->widget.id,
9122 windows->widget.screen,(
unsigned int) mask,&window_changes);
9123 (void) XMapRaised(display,windows->widget.id);
9124 windows->widget.mapped=MagickFalse;
9128 XGetWidgetInfo((
char *) NULL,&slider_info);
9129 XGetWidgetInfo((
char *) NULL,&north_info);
9130 XGetWidgetInfo((
char *) NULL,&south_info);
9131 XGetWidgetInfo((
char *) NULL,&expose_info);
9132 XGetWidgetInfo((
char *) NULL,&selection_info);
9134 delay=SuspendTime << 2;
9135 height=(
unsigned int) (font_info->ascent+font_info->descent);
9136 state=UpdateConfigurationState;
9139 if (state & UpdateConfigurationState)
9147 XGetWidgetInfo(DismissButtonText,&dismiss_info);
9148 dismiss_info.width=width;
9149 dismiss_info.height=(
unsigned int) ((3*height) >> 1);
9150 dismiss_info.x=(int) windows->widget.width-(
int) dismiss_info.width-
9152 dismiss_info.y=(int) windows->widget.height-(
int) dismiss_info.height-
9157 XGetWidgetInfo((
char *) NULL,&scroll_info);
9158 scroll_info.bevel_width--;
9159 scroll_info.width=height;
9160 scroll_info.height=(
unsigned int) (dismiss_info.y-((5*QuantumMargin) >>
9162 scroll_info.x=(int) windows->widget.width-QuantumMargin-(
int)
9164 scroll_info.y=(3*QuantumMargin) >> 1;
9165 scroll_info.raised=MagickFalse;
9166 scroll_info.trough=MagickTrue;
9167 north_info=scroll_info;
9168 north_info.raised=MagickTrue;
9169 north_info.width-=(north_info.bevel_width << 1);
9170 north_info.height=north_info.width-1;
9171 north_info.x+=(int) north_info.bevel_width;
9172 north_info.y+=(int) north_info.bevel_width;
9173 south_info=north_info;
9174 south_info.y=scroll_info.y+(int) scroll_info.height-(
int)
9175 scroll_info.bevel_width-(int) south_info.height;
9177 slider_info=north_info;
9179 slider_info.width-=2;
9180 slider_info.min_y=north_info.y+(int) north_info.height+(
int)
9181 north_info.bevel_width+(int) slider_info.bevel_width+2;
9182 slider_info.height=(
unsigned int) ((
int) scroll_info.height-
9183 ((slider_info.min_y-scroll_info.y+1) << 1)+4);
9184 visible_lines=(
unsigned int) (scroll_info.height*PerceptibleReciprocal(
9185 (
double) text_info->ascent+text_info->descent+((text_info->ascent+
9186 text_info->descent) >> 3)));
9187 if (lines > visible_lines)
9188 slider_info.height=(
unsigned int) (visible_lines*slider_info.height)/
9190 slider_info.max_y=south_info.y-(int) south_info.bevel_width-(
int)
9191 slider_info.bevel_width-2;
9192 slider_info.x=scroll_info.x+(int) slider_info.bevel_width+1;
9193 slider_info.y=slider_info.min_y;
9194 expose_info=scroll_info;
9195 expose_info.y=slider_info.y;
9199 XGetWidgetInfo((
char *) NULL,&list_info);
9200 list_info.raised=MagickFalse;
9201 list_info.bevel_width--;
9202 list_info.width=(
unsigned int) (scroll_info.x-((3*QuantumMargin) >> 1));
9203 list_info.height=scroll_info.height;
9204 list_info.x=QuantumMargin;
9205 list_info.y=scroll_info.y;
9209 XGetWidgetInfo((
char *) NULL,&selection_info);
9210 selection_info.center=MagickFalse;
9211 selection_info.width=list_info.width;
9212 selection_info.height=(
unsigned int)
9213 (9*(text_info->ascent+text_info->descent)) >> 3;
9214 selection_info.x=list_info.x;
9215 state&=(
unsigned int) (~UpdateConfigurationState);
9217 if (state & RedrawWidgetState)
9222 XDrawBeveledMatte(display,&windows->widget,&list_info);
9223 XDrawBeveledMatte(display,&windows->widget,&scroll_info);
9224 XDrawTriangleNorth(display,&windows->widget,&north_info);
9225 XDrawBeveledButton(display,&windows->widget,&slider_info);
9226 XDrawTriangleSouth(display,&windows->widget,&south_info);
9227 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
9228 XHighlightWidget(display,&windows->widget,BorderOffset,BorderOffset);
9229 selection_info.id=(~0);
9230 state|=RedrawListState;
9231 state&=(
unsigned int) (~RedrawWidgetState);
9233 if (state & RedrawListState)
9238 if (slider_info.id >= (
int) (lines-visible_lines))
9239 slider_info.id=(int) (lines-visible_lines);
9240 if ((slider_info.id < 0) || (lines <= visible_lines))
9242 slider_info.y=slider_info.min_y;
9244 slider_info.y+=slider_info.id*(slider_info.max_y-
9245 slider_info.min_y+1)/(
int) lines;
9246 if (slider_info.id != selection_info.id)
9251 windows->widget.font_info=text_info;
9252 (void) XSetFont(display,windows->widget.annotate_context,
9254 (void) XSetFont(display,windows->widget.highlight_context,
9256 selection_info.id=slider_info.id;
9257 selection_info.y=list_info.y+(int) (height >> 3)+2;
9258 for (i=0; i < (int) visible_lines; i++)
9260 selection_info.raised=
9261 (slider_info.id+i) != list_info.id ? MagickTrue : MagickFalse;
9262 selection_info.text=(
char *) NULL;
9263 if ((slider_info.id+i) < (
int) lines)
9264 selection_info.text=(
char *) textlist[slider_info.id+i];
9265 XDrawWidgetText(display,&windows->widget,&selection_info);
9266 selection_info.y+=(int) selection_info.height;
9268 windows->widget.font_info=font_info;
9269 (void) XSetFont(display,windows->widget.annotate_context,
9271 (void) XSetFont(display,windows->widget.highlight_context,
9276 if (slider_info.y > expose_info.y)
9278 expose_info.height=(
unsigned int) (slider_info.y-expose_info.y);
9279 expose_info.y=slider_info.y-(int) expose_info.height-(
int)
9280 slider_info.bevel_width-1;
9284 expose_info.height=(
unsigned int) (expose_info.y-slider_info.y);
9285 expose_info.y=slider_info.y+(int) slider_info.height+(
int)
9286 slider_info.bevel_width+1;
9288 XDrawTriangleNorth(display,&windows->widget,&north_info);
9289 XDrawMatte(display,&windows->widget,&expose_info);
9290 XDrawBeveledButton(display,&windows->widget,&slider_info);
9291 XDrawTriangleSouth(display,&windows->widget,&south_info);
9292 expose_info.y=slider_info.y;
9294 state&=(
unsigned int) (~RedrawListState);
9299 if (north_info.raised && south_info.raised)
9300 (void) XIfEvent(display,&event,XScreenEvent,(
char *) windows);
9306 XDelay(display,delay);
9308 (void) XCheckIfEvent(display,&event,XScreenEvent,(
char *) windows);
9309 if (north_info.raised == MagickFalse)
9310 if (slider_info.id > 0)
9316 state|=RedrawListState;
9318 if (south_info.raised == MagickFalse)
9319 if (slider_info.id < (
int) lines)
9325 state|=RedrawListState;
9327 if (event.type != ButtonRelease)
9334 if (MatteIsActive(slider_info,event.xbutton))
9339 slider_info.active=MagickTrue;
9342 if (MatteIsActive(north_info,event.xbutton))
9343 if (slider_info.id > 0)
9348 north_info.raised=MagickFalse;
9350 state|=RedrawListState;
9353 if (MatteIsActive(south_info,event.xbutton))
9354 if (slider_info.id < (
int) lines)
9359 south_info.raised=MagickFalse;
9361 state|=RedrawListState;
9364 if (MatteIsActive(scroll_info,event.xbutton))
9369 if (event.xbutton.y < slider_info.y)
9370 slider_info.id-=(int) (visible_lines-1);
9372 slider_info.id+=(int) (visible_lines-1);
9373 state|=RedrawListState;
9376 if (MatteIsActive(dismiss_info,event.xbutton))
9381 dismiss_info.raised=MagickFalse;
9382 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
9385 if (MatteIsActive(list_info,event.xbutton))
9396 id=slider_info.id+(
event.xbutton.y-(list_info.y+(int)
9397 (height >> 1))+1)/(
int) selection_info.height;
9398 if (
id >= (
int) lines)
9400 if (
id != list_info.id)
9403 click_time=
event.xbutton.time;
9407 if (event.xbutton.time >= (click_time+(
unsigned long) DoubleClick))
9409 click_time=
event.xbutton.time;
9412 click_time=
event.xbutton.time;
9416 (void) CopyMagickString(primary_selection,textlist[list_info.id],
9418 (void) XSetSelectionOwner(display,XA_PRIMARY,windows->widget.id,
9419 event.xbutton.time);
9420 if (XGetSelectionOwner(display,XA_PRIMARY) != windows->widget.id)
9422 selection_info.id=(~0);
9424 state|=RedrawListState;
9431 if (windows->widget.mapped == MagickFalse)
9433 if (north_info.raised == MagickFalse)
9438 delay=SuspendTime << 2;
9439 north_info.raised=MagickTrue;
9440 XDrawTriangleNorth(display,&windows->widget,&north_info);
9442 if (south_info.raised == MagickFalse)
9447 delay=SuspendTime << 2;
9448 south_info.raised=MagickTrue;
9449 XDrawTriangleSouth(display,&windows->widget,&south_info);
9451 if (slider_info.active)
9456 slider_info.active=MagickFalse;
9459 if (dismiss_info.raised == MagickFalse)
9461 if (event.xbutton.window == windows->widget.id)
9462 if (MatteIsActive(dismiss_info,event.xbutton))
9464 dismiss_info.raised=MagickTrue;
9465 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
9474 if (event.xclient.message_type != windows->wm_protocols)
9476 if (*event.xclient.data.l == (
int) windows->wm_take_focus)
9478 (void) XSetInputFocus(display,event.xclient.window,RevertToParent,
9479 (Time) event.xclient.data.l[1]);
9482 if (*event.xclient.data.l != (
int) windows->wm_delete_window)
9484 if (event.xclient.window == windows->widget.id)
9491 case ConfigureNotify:
9496 if (event.xconfigure.window != windows->widget.id)
9498 if ((event.xconfigure.width == (
int) windows->widget.width) &&
9499 (event.xconfigure.height == (
int) windows->widget.height))
9501 windows->widget.width=(
unsigned int)
9502 MagickMax(event.xconfigure.width,(
int) windows->widget.min_width);
9503 windows->widget.height=(
unsigned int)
9504 MagickMax(event.xconfigure.height,(
int) windows->widget.min_height);
9505 state|=UpdateConfigurationState;
9510 if (event.xcrossing.window != windows->widget.id)
9512 state&=(
unsigned int) (~InactiveWidgetState);
9517 if (event.xexpose.window != windows->widget.id)
9519 if (event.xexpose.count != 0)
9521 state|=RedrawWidgetState;
9527 command[MagickPathExtent];
9538 if (event.xkey.window != windows->widget.id)
9540 length=XLookupString((XKeyEvent *) &event.xkey,command,
9541 (
int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
9542 *(command+length)=
'\0';
9543 if ((key_symbol == XK_Return) || (key_symbol == XK_KP_Enter))
9545 dismiss_info.raised=MagickFalse;
9546 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
9550 if (AreaIsActive(scroll_info,event.xkey))
9555 switch ((
int) key_symbol)
9578 slider_info.id-=(int) visible_lines;
9584 slider_info.id+=(int) visible_lines;
9590 slider_info.id=(int) lines;
9594 state|=RedrawListState;
9603 if (event.xcrossing.window != windows->widget.id)
9605 state|=InactiveWidgetState;
9610 mask&=(
unsigned int) (~CWX);
9611 mask&=(
unsigned int) (~CWY);
9619 while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
9620 if (slider_info.active)
9625 slider_info.y=
event.xmotion.y-(int)
9626 ((slider_info.height+slider_info.bevel_width) >> 1)+1;
9627 if (slider_info.y < slider_info.min_y)
9628 slider_info.y=slider_info.min_y;
9629 if (slider_info.y > slider_info.max_y)
9630 slider_info.y=slider_info.max_y;
9632 if (slider_info.y != slider_info.min_y)
9633 slider_info.id=((int) lines*(slider_info.y-slider_info.min_y+1))/
9634 (slider_info.max_y-slider_info.min_y+1);
9635 state|=RedrawListState;
9638 if (state & InactiveWidgetState)
9640 if (dismiss_info.raised == MatteIsActive(dismiss_info,event.xmotion))
9645 dismiss_info.raised=
9646 dismiss_info.raised == MagickFalse ? MagickTrue : MagickFalse;
9647 XDrawBeveledButton(display,&windows->widget,&dismiss_info);
9652 case SelectionClear:
9655 selection_info.id=(~0);
9656 state|=RedrawListState;
9659 case SelectionRequest:
9664 XSelectionRequestEvent
9667 if (list_info.id == (~0))
9672 request=(&(
event.xselectionrequest));
9673 (void) XChangeProperty(request->display,request->requestor,
9674 request->property,request->target,8,PropModeReplace,
9675 (
unsigned char *) primary_selection,Extent(primary_selection));
9676 notify.type=SelectionNotify;
9677 notify.send_event=MagickTrue;
9678 notify.display=request->display;
9679 notify.requestor=request->requestor;
9680 notify.selection=request->selection;
9681 notify.target=request->target;
9682 notify.time=request->time;
9683 if (request->property == None)
9684 notify.property=request->target;
9686 notify.property=request->property;
9687 (void) XSendEvent(request->display,request->requestor,False,NoEventMask,
9688 (XEvent *) ¬ify);
9693 }
while ((state & ExitState) == 0);
9694 if (text_info != windows->widget.font_info)
9695 (void) XFreeFont(display,text_info);
9696 XSetCursorState(display,windows,MagickFalse);
9697 (void) XWithdrawWindow(display,windows->widget.id,windows->widget.screen);
9698 XCheckRefreshWindows(display,windows);