File: size.c

package info (click to toggle)
xpaint 2.5.1-4
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,448 kB
  • ctags: 2,478
  • sloc: ansic: 25,980; makefile: 36; sh: 23
file content (137 lines) | stat: -rw-r--r-- 3,835 bytes parent folder | download | duplicates (4)
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
/* +-------------------------------------------------------------------+ */
/* | 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.4 1996/05/31 06:25:37 torsten Exp $ */

#include <X11/StringDefs.h>
#include <X11/Intrinsic.h>
#include <X11/Shell.h>
#include <X11/Xaw/Dialog.h>
#include <X11/Xaw/Command.h>
#include <X11/Xaw/Toggle.h>
#include <X11/Xaw/Form.h>
#include <X11/Xaw/Label.h>
#include <X11/Xaw/AsciiText.h>
#include <X11/Xaw/Text.h>
#include <stdio.h>

#ifndef NOSTDHDRS
#include <stdlib.h>
#include <unistd.h>
#endif

#include "Paint.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;
    XtVaSetValues(arg->paint, XtNdrawWidth, arg->w, XtNdrawHeight, arg->h,
		  XtNdirty, True, NULL);
    FatbitsUpdate(arg->paint, -1);
    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, "Invalid width");
    } else if (arg->h <= 0) {
	Notice(w, "Invalid height");
    } else if (arg->paint == None) {
	arg->func(arg->widget, arg->w, arg->h, arg->z);
    } else if (arg->w != width || arg->h != height) {
	AlertBox(GetShell(arg->paint),
		 "Warning: this operation cannot be undone\nContinue?",
		 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 = "Enter the desired image size:";

    values[0].prompt = "Width:";
    values[0].str = bufA;
    values[0].len = 5;
    values[1].prompt = "Height:";
    values[1].str = bufB;
    values[1].len = 5;
    values[2].prompt = "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);
}