/* +-------------------------------------------------------------------+ */ /* | Copyright 1992, 1993, David Koblas (koblas@netcom.com) | */ /* | | */ /* | Permission to use, copy, modify, and to distribute this software | */ /* | and its documentation for any purpose is hereby granted without | */ /* | fee, provided that the above copyright notice appear in all | */ /* | copies and that both that copyright notice and this permission | */ /* | notice appear in supporting documentation. There is no | */ /* | representations about the suitability of this software for | */ /* | any purpose. this software is provided "as is" without express | */ /* | or implied warranty. | */ /* | | */ /* +-------------------------------------------------------------------+ */ /* $Id: size.c,v 1.17 2005/03/20 20:15:32 demailly Exp $ */ #include #ifndef NOSTDHDRS #include #include #endif #include #include #include #include "xaw_incdir/Dialog.h" #include "xaw_incdir/Command.h" #include "xaw_incdir/Toggle.h" #include "xaw_incdir/Form.h" #include "xaw_incdir/Label.h" #include "xaw_incdir/AsciiText.h" #include "xaw_incdir/Text.h" #include "Paint.h" #include "messages.h" #include "misc.h" #include "text.h" typedef struct { Widget widget, paint; int w, h; int z; void (*func) (Widget, int, int, int); } arg_t; static void cancelSizeCallback(Widget w, XtPointer arg, XtPointer junk) { XtFree((XtPointer) arg); } static void sureCallback(Widget w, XtPointer argArg, XtPointer junk) { arg_t *arg = (arg_t *) argArg; Dimension u, v; int z; XtUnmanageChild(arg->paint); XtVaGetValues(arg->paint, XtNzoom, &z, NULL); XtVaSetValues(arg->paint, XtNdrawWidth, arg->w, XtNdrawHeight, arg->h, XtNwidth, arg->w * z, XtNheight, arg->h * z, XtNdirty, True, NULL); w = XtParent(XtParent(arg->paint)); XtVaGetValues(w, XtNwidth, &u, XtNheight, &v, NULL); #ifdef XAW95 if (u >= z*arg->w+14 && v >= z*arg->h+14) #else if (u >= z*arg->w+10 && v >= z*arg->h+10) #endif XtVaSetValues(w, XtNallowVert, False, XtNallowHoriz, False, NULL); else XtVaSetValues(w, XtNallowVert, True, XtNallowHoriz, True, NULL); FatbitsUpdate(arg->paint, -1); XtManageChild(arg->paint); XtFree((XtPointer) arg); } static void okSizeCallback(Widget w, XtPointer argArg, XtPointer infoArg) { arg_t *arg = (arg_t *) argArg; TextPromptInfo *info = (TextPromptInfo *) infoArg; int width, height; arg->w = atoi(info->prompts[0].rstr); arg->h = atoi(info->prompts[1].rstr); if (arg->paint == None) arg->z = atoi(info->prompts[2].rstr); if (arg->paint != None) XtVaGetValues(arg->paint, XtNdrawWidth, &width, XtNdrawHeight, &height, NULL); if (arg->w <= 0) { Notice(w, msgText[INVALID_WIDTH]); } else if (arg->h <= 0) { Notice(w, msgText[INVALID_HEIGHT]); } else if (arg->paint == None) { if (arg->func) arg->func(arg->widget, arg->w, arg->h, arg->z); else { SetDefaultWHZ(arg->w, arg->h, arg->z); } } else if (arg->w != width || arg->h != height) { AlertBox(GetShell(arg->paint), msgText[RESIZING_WARNING_CANNOT_BE_UNDONE], sureCallback, cancelSizeCallback, arg); /* don't free */ return; } XtFree((XtPointer) arg); } void SizeSelect(Widget w, Widget paint, void (*func) (Widget, int, int, int)) { static TextPromptInfo info; static struct textPromptInfo values[4]; int width, height, zoom; arg_t *arg = XtNew(arg_t); char bufA[16], bufB[16], bufC[16]; info.prompts = values; info.nprompt = (paint == None) ? 3 : 2; info.title = msgText[ENTER_DESIRED_IMAGE_SIZE]; values[0].prompt = msgText[SIZE_WIDTH]; values[0].str = bufA; values[0].len = 5; values[1].prompt = msgText[SIZE_HEIGHT]; values[1].str = bufB; values[1].len = 5; values[2].prompt = msgText[SIZE_ZOOM]; values[2].str = bufC; values[2].len = 5; if (paint != None) { XtVaGetValues(paint, XtNdrawWidth, &width, XtNdrawHeight, &height, XtNzoom, &zoom, NULL); } else { GetDefaultWH(&width, &height); zoom = 1; } sprintf(bufA, "%d", (int) width); sprintf(bufB, "%d", (int) height); sprintf(bufC, "%d", (int) zoom); arg->widget = w; arg->paint = paint; arg->func = func; TextPrompt(w, "sizeselect", &info, okSizeCallback, cancelSizeCallback, arg); }