1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
/* +-------------------------------------------------------------------+ */
/* | 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 <stdio.h>
#ifndef NOSTDHDRS
#include <stdlib.h>
#include <unistd.h>
#endif
#include <X11/StringDefs.h>
#include <X11/Intrinsic.h>
#include <X11/Shell.h>
#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);
}
|