1 /*
2 **
3 ** note.c
4 **
5 ** Copyright (C) 1995, 1996, 1997 Johannes Plass
6 ** Copyright (C) 2004 Jose E. Marchesi
7 **
8 ** This program is free software; you can redistribute it and/or modify
9 ** it under the terms of the GNU General Public License as published by
10 ** the Free Software Foundation; either version 3 of the License, or
11 ** (at your option) any later version.
12 **
13 ** This program is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ** GNU General Public License for more details.
17 **
18 ** You should have received a copy of the GNU General Public License
19 ** along with GNU gv; see the file COPYING.  If not, write to
20 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ** Boston, MA 02111-1307, USA.
22 **
23 ** Author:   Johannes Plass (plass@thep.physik.uni-mainz.de)
24 **           Department of Physics
25 **           Johannes Gutenberg-University
26 **           Mainz, Germany
27 **
28 **           Jose E. Marchesi (jemarch@gnu.org)
29 **           GNU Project
30 **
31 */
32 #include "ac_config.h"
33 
34 /*
35 #define MESSAGES
36 */
37 #include "message.h"
38 
39 #include "config.h"
40 
41 #include <stdio.h>
42 
43 #include "paths.h"
44 #include INC_X11(IntrinsicP.h)
45 #include INC_X11(StringDefs.h)
46 #include INC_XAW(Label.h)
47 #include INC_X11(Shell.h)
48 #include "Aaa.h"
49 #include "Button.h"
50 #include "popup.h"
51 
52 #ifndef max
53 #   define max(a, b)    ((a) > (b) ? (a) : (b))
54 #endif
55 
56 /*### Application dependencies ##############################################*/
57 
58 #define NOTE_TOPLEVEL	toplevel       			/* the Application Shell   */
59 #define NOTE_POPUP	notepopup
60 #define NOTE_POPUP_NAME	"notePopup"
61 
62 #include "types.h"
63 #include "main_resources.h"
64 #include "main_globals.h"
65 #include "note.h"
66 #include "widgets_misc.h"
67 
68 static Bool notePopupVisible = False;
69 static Bool notePopupCreated = False;
70 static Widget doneButton=NULL;
71 
72 /*###############################################################################
73    cb_popupNotePopup
74 ###############################################################################*/
75 
cb_popupNotePopup(Widget w _GL_UNUSED,XtPointer client_data _GL_UNUSED,XtPointer call_data _GL_UNUSED)76 void cb_popupNotePopup(Widget w _GL_UNUSED, XtPointer client_data _GL_UNUSED, XtPointer call_data _GL_UNUSED)
77 {
78    BEGINMESSAGE(cb_popupNotePopup)
79    if (!notePopupVisible) {
80       if (!notePopupCreated) makeNotePopup();
81       popup_positionPopup(NOTE_POPUP,NOTE_TOPLEVEL,POPUP_POSITION_CENTER,0,0);
82       widgets_preferButton(doneButton,1);
83       XtPopup(NOTE_POPUP, XtGrabNone);
84       notePopupVisible = True;
85    }
86    ENDMESSAGE(cb_popupNotePopup)
87 }
88 
89 /*###############################################################################
90    cb_popdownNotePopup
91 ###############################################################################*/
92 
cb_popdownNotePopup(Widget w _GL_UNUSED,XtPointer client_data _GL_UNUSED,XtPointer call_data _GL_UNUSED)93 void cb_popdownNotePopup(Widget w _GL_UNUSED, XtPointer client_data _GL_UNUSED, XtPointer call_data _GL_UNUSED)
94 {
95    BEGINMESSAGE(cb_popdownNotePopup)
96    if (notePopupVisible) {
97       XtPopdown(NOTE_POPUP);
98       notePopupVisible = False;
99    }
100    ENDMESSAGE(cb_popdownNotePopup)
101 }
102 
103 /*###############################################################################
104    makeNotePopup
105 ###############################################################################*/
106 
makeNotePopup(void)107 void makeNotePopup(void)
108 {
109    Arg          args[10];
110    Cardinal     n;
111    Widget   noteAaa;
112    Widget   messageLabel;
113 
114    BEGINMESSAGE(makeNotePopup)
115 
116 							n=0;
117         XtSetArg(args[n], XtNallowShellResize, True);	n++;
118    NOTE_POPUP = XtCreatePopupShell(NOTE_POPUP_NAME,transientShellWidgetClass,NOTE_TOPLEVEL, args, n);
119 
120 							n=0;
121    noteAaa = XtCreateManagedWidget("noteAaa",aaaWidgetClass,NOTE_POPUP,args,n);
122 
123 							n=0;
124          XtSetArg(args[n], XtNresize, True);		++n;
125    messageLabel = XtCreateManagedWidget("message", labelWidgetClass,noteAaa, args, n);
126 
127 							n=0;
128    doneButton = XtCreateManagedWidget("done", buttonWidgetClass,noteAaa, args, n);
129          XtAddCallback(doneButton, XtNcallback, cb_popdownNotePopup,(XtPointer)NULL);
130 
131    XtRealizeWidget(NOTE_POPUP);
132 
133 						n=0;
134    XtSetArg(args[n], XtNminWidth, 100);		++n;
135    XtSetArg(args[n], XtNminHeight, 50);		++n;
136    XtSetArg(args[n], XtNmaxWidth, XtUnspecifiedShellInt);  ++n;
137    XtSetArg(args[n], XtNmaxHeight, XtUnspecifiedShellInt); ++n;
138    XtSetValues(NOTE_POPUP, args, n);
139 
140    XtSetKeyboardFocus(noteAaa,doneButton);
141 
142    XSetWMProtocols(XtDisplay(NOTE_POPUP),XtWindow(NOTE_POPUP),&wm_delete_window,1);
143    notePopupCreated =True;
144 
145    ENDMESSAGE(makeNotePopup)
146 }
147 
148 /*###############################################################################
149     NotePopupShowMessage
150 ###############################################################################*/
151 
152 void
NotePopupShowMessage(String message)153 NotePopupShowMessage(String message)
154 {
155     Arg args[5];
156     Cardinal n;
157     Widget label;
158 
159     BEGINMESSAGE(NotePopupShowMessage)
160     if (!message) {INFMESSAGE(no message) ENDMESSAGE(NotePopupShowMessage) return;}
161     if (!notePopupCreated) makeNotePopup();
162     label = XtNameToWidget(NOTE_POPUP, "*message");
163     n=0;
164     XtSetArg(args[n], XtNlabel, message); n++;
165     XtSetValues(label, args, n);
166     cb_popupNotePopup((Widget)NULL,(XtPointer)NULL,(XtPointer)NULL);
167     ENDMESSAGE(NotePopupShowMessage)
168 }
169