1 /*
2  * Copyright 1991 by David A. Curry
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that copyright
7  * notice and this permission notice appear in supporting documentation.  The
8  * author makes no representations about the suitability of this software for
9  * any purpose.  It is provided "as is" without express or implied warranty.
10  */
11 #ifndef lint
12 static char	*RCSid = "$Header: /home/harbor/davy/stuff/xpostit/RCS/title.c,v 1.6 1992/12/10 16:39:38 davy Exp $";
13 #endif
14 
15 /*
16  * title.c - handle getting a new title from the user.
17  *
18  * David A. Curry
19  * Purdue University
20  * Engineering Computer Network
21  * West Lafayette, IN 47907
22  * davy@ecn.purdue.edu
23  *
24  * $Log: title.c,v $
25  * Revision 1.6  1992/12/10  16:39:38  davy
26  * Added code for keyboard accelerators, tearoff notes, wm protocols, etc.
27  * from Joe English (joe@trystero.art.com).
28  *
29  * Revision 1.5  1992/12/09  20:02:33  davy
30  * Added changes to work properly under mwm from Brian Walker,
31  * brian@crl.labs.tek.com.
32  *
33  * Revision 1.4  1992/12/09  19:54:16  davy
34  * Added XI18N international Xaw support from Hiroshi Kuribayashi,
35  * kuri@omron.co.jp.
36  *
37  * Revision 1.3  1991/11/08  14:26:49  davy
38  * Fixed titles to stay with their own notes.
39  *
40  * Revision 1.2  91/09/06  18:29:29  davy
41  * Added copyright/permission notice for submission to MIT R5 contrib.
42  *
43  * Revision 1.1  91/09/06  17:14:43  davy
44  * Initial revision
45  *
46  */
47 #include <X11/StringDefs.h>
48 #include <X11/Intrinsic.h>
49 #include <X11/Xaw/Dialog.h>
50 #include <X11/Shell.h>
51 #include <stdio.h>
52 
53 #include "xpostit.h"
54 
55 Widget		dialog;
56 static int	notenum;
57 static Widget	titlewidget;
58 
59 /*
60  * GetNoteTitle - return the note's new title.
61  */
62 char *
GetNoteTitle(pn,okayCallback,cancelCallback)63 GetNoteTitle(pn, okayCallback, cancelCallback)
64 XtCallbackProc okayCallback, cancelCallback;
65 PostItNote *pn;
66 {
67 	Arg args[8];
68 	Widget value;
69 	Window root, child;
70 	unsigned int buttons;
71 	register int nargs, nwidgets;
72 	static Boolean inited = False;
73 	int root_x, root_y, child_x, child_y;
74 
75 	/*
76 	 * Find out where the mouse is, so we can put the confirmation
77 	 * box right there.
78 	 */
79 	XQueryPointer(display, XtWindow(toplevel), &root, &child,
80 		      &root_x, &root_y, &child_x, &child_y, &buttons);
81 
82 	root_x -= 5;
83 	root_y -= 5;
84 	notenum = pn->pn_index;
85 
86 	/*
87 	 * If we need to construct the confirmation box do that,
88 	 * otherwise just reset the position and callbacks and
89 	 * put it up again.
90 	 */
91 	if (!inited) {
92 		nargs = 0;
93 		SetArg(XtNx, root_x);
94 		SetArg(XtNy, root_y);
95 		SetArg(XtNallowShellResize, True);
96 
97 		/*
98 		 * The dialog box will be a pop-up widget.
99 		 */
100 		titlewidget = XtCreatePopupShell("Title",
101 #ifdef XI18N
102 						   topLevelShellWidgetClass,
103 #else
104 						   transientShellWidgetClass,
105 #endif
106 						   toplevel, args, nargs);
107 
108 		nargs = 0;
109 		SetArg(XtNlabel, "New Title:");
110 		SetArg(XtNvalue, pn->pn_title);
111 
112 		dialog = XtCreateWidget("Dialog", dialogWidgetClass,
113 					titlewidget, args, nargs);
114 
115 		nargs = 0;
116 		SetArg(XtNresizable, True);
117 		value = XtNameToWidget(dialog, "value");
118 		XtSetValues(value, args, nargs);
119 
120 		XawDialogAddButton(dialog, "Okay", okayCallback,
121 				   (caddr_t) &notenum);
122 		XawDialogAddButton(dialog, "Cancel", cancelCallback,
123 				   (caddr_t) &notenum);
124 
125 		XtInstallAllAccelerators(value, dialog);
126 
127 		/*
128 		 * Let the shell widget know we're here.
129 		 */
130 		XtManageChild(dialog);
131 
132 		XtRealizeWidget(titlewidget);
133 		inited = True;
134 	}
135 	else {
136 		/*
137 		 * Reset the title box position and value.
138 		 */
139 		nargs = 0;
140 		SetArg(XtNx, root_x);
141 		SetArg(XtNy, root_y);
142 		XtSetValues(titlewidget, args, nargs);
143 
144 		nargs = 0;
145 		SetArg(XtNvalue, pn->pn_title);
146 		XtSetValues(dialog, args, nargs);
147 	}
148 
149 	/*
150 	 * Pop up the dialog box.
151 	 */
152 	XtPopup(titlewidget, XtGrabExclusive);
153 }
154 
155 /*
156  * ClearTitle - get rid of the title box.
157  */
158 void
ClearTitle()159 ClearTitle()
160 {
161 	XtPopdown(titlewidget);
162 }
163 
164