File: name.c

package info (click to toggle)
xpostitplus 2.3.1-10
  • links: PTS
  • area: non-free
  • in suites: potato
  • size: 464 kB
  • ctags: 661
  • sloc: ansic: 4,831; makefile: 527; sh: 70
file content (189 lines) | stat: -rw-r--r-- 3,928 bytes parent folder | download | duplicates (3)
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#ifndef lint
static char	*RCSid = "$Id: name.c,v 2.0 1995/03/27 18:56:22 mjhammel Exp $";
#endif

/*
 * name.c - handle note naming requests made by the user.
 *
 * Michael J. Hammel
 * Contractor
 * 1150 Inca St. TH 70
 * Denver, CO 80204
 * mjhammel@csn.org
 *
 * $Log: name.c,v $
 * Revision 2.0  1995/03/27  18:56:22  mjhammel
 * Initial update to 2.0
 *
 */

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

#include "xpostit.h"

Widget				dialogwidget;
Widget				namewidget;

/*
 * NameIt - put up a window prompt for the notes name
 */
void
NameIt(pn, confirm_callbacks, cancel_callbacks)
PostItNote *pn;
XtCallbackRec *confirm_callbacks, *cancel_callbacks;
{
	Arg 			args[10];
	Window 			root, child;
	unsigned int 		buttons;
	register int 		nargs, nwidgets;
	static Boolean 		inited = False;
	static Widget 		widgets[3];
	int 			root_x, root_y, child_x, child_y;

	/*
	 * Find out where the mouse is, so we can put the confirmation
	 * box right there.
	 */
	XQueryPointer(display, XtWindow(toplevel), &root, &child,
		      &root_x, &root_y, &child_x, &child_y, &buttons);

	/*
	 * If we need to construct the confirmation box do that,
	 * otherwise just reset the position and callbacks and
	 * put it up again.
	 */
	if (!inited) {

		nargs = 0;
		SetArg(XtNx, root_x);
		SetArg(XtNy, root_y);

		/*
		 * The confirmation box will be a pop-up widget.
		 */
		namewidget = XtCreatePopupShell("Name",
				transientShellWidgetClass,
				toplevel, args, nargs);

		/*
		 * Make a dialog to put the buttons in.
		 */
		nargs = 0;
		SetArg(XtNlabel, PostItNoteDialog);
		if ( pn->pn_name == NULL )
		{
			SetArg(XtNvalue, "");
		}
		else
		{
			SetArg(XtNvalue, pn->pn_name);
		}
		SetArg(XtNresize, XawtextResizeWidth);
		SetArg(XtNresizable, TRUE);
		dialogwidget = XtCreateManagedWidget("Dialog", dialogWidgetClass,
				      namewidget, args, nargs);

		nwidgets = -1;

		/*
		 * Confirmation button.
		 */
		nargs = 0;
		SetArg(XtNcallback, confirm_callbacks);
		widgets[++nwidgets] = XtCreateWidget("Confirm",
					commandWidgetClass,
					dialogwidget, args, nargs);

		/*
		 * Cancellation button.
		 */
		nargs = 0;
		SetArg(XtNcallback, cancel_callbacks);
		SetArg(XtNfromHoriz, widgets[nwidgets]);
		widgets[++nwidgets] = XtCreateWidget("Cancel",
					commandWidgetClass,
					dialogwidget, args, nargs);

		/*
		 * Let the shell widget know we're here.
		 */
		XtManageChildren(widgets, nwidgets+1);

		inited = True;
	}
	else {
		/*
		 * Reset the confirmation box position.
		 */
		nargs = 0;
		SetArg(XtNx, root_x);
		SetArg(XtNy, root_y);
		XtSetValues(namewidget, args, nargs);

		/* clear the dialog text */
		nargs = 0;
		if ( pn->pn_name == NULL )
		{
			SetArg(XtNvalue, "");
		}
		else
		{
			SetArg(XtNvalue, pn->pn_name);
		}
		XtSetValues(dialogwidget, args, nargs);

		/*
		 * Reset the callbacks.
		 */
		nargs = 0;
		SetArg(XtNcallback, confirm_callbacks);
		XtSetValues(widgets[0], args, nargs);

		nargs = 0;
		SetArg(XtNcallback, cancel_callbacks);
		XtSetValues(widgets[1], args, nargs);

	}

	/*
	 * Pop up the confirmation box.
	 */
	XtPopup(namewidget, XtGrabNonexclusive);

	/*
	 * Reset the width of the dialog box - this sucks, since I can't tell
	 * the width, in pixels, of the font being used for the text field.
	 * The hack is to allow the user to specify a width via a resource.
	 * The problem is a limitation in the Athena Widget set.
	 */

	if ( pn->pn_name == NULL )
	{
		nargs = 0;
		SetArg(XtNwidth, (app_res.name_width*30)); 
		XtSetValues(namewidget, args, nargs);
	}
	else
	{
		nargs = 0;
		SetArg(XtNwidth, (app_res.name_width*(strlen((char *)pn->pn_name)+10)));
		XtSetValues(namewidget, args, nargs);
	}

}

/*
 * ClearName - get rid of the confirmation box.
 */
void
ClearName()
{
	XtPopdown(namewidget);
}