File: InfoDialog.c

package info (click to toggle)
xrn 9.01-1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 1,768 kB
  • ctags: 3,015
  • sloc: ansic: 24,433; makefile: 1,964; yacc: 888; sh: 278; lex: 92; perl: 35; awk: 31; csh: 13
file content (169 lines) | stat: -rw-r--r-- 3,946 bytes parent folder | download | duplicates (2)
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
/* InfoDialog.c */

#ifdef MOTIF
# include <Xm/Xm.h>
# include <Xm/PanedW.h>
# include <Xm/MessageB.h>
#else
# include <X11/Xos.h>
# include <X11/cursorfont.h>
# include <X11/StringDefs.h>
# include <X11/Intrinsic.h>
# include <X11/Shell.h>
# include <X11/Xaw/Paned.h>
# include <X11/Xaw/Command.h>
# include <X11/Xaw/Box.h>
#endif

#include "butdefs.h"
#include "ButtonBox.h"
#include "InfoLine.h"
#include "Text.h"
#include "InfoDialog.h"
#include "ngMode.h"

/* entire widget */
static Widget MesgTopLevel = (Widget) 0;
/* text window */
static Widget MesgText = (Widget) 0;
/* amount of text currently in the window */
static long current_length = 0;


long
MesgLength()
{
	return (current_length);
}

#ifdef MOTIF
static void mesgDismissXmCallback _ARGUMENTS((Widget,XtPointer,XtPointer));
static void mesgClearXmCallback _ARGUMENTS((Widget,XtPointer,XtPointer));
#else
static void mesgDismissFunction _ARGUMENTS((Widget,XEvent*,String*,Cardinal*));
static void mesgClearFunction _ARGUMENTS((Widget,XEvent*,String*,Cardinal*));
BUTTON(mesgDismiss,dismiss);
BUTTON(mesgClear,clear);
#endif

void
InfoDialogCreate(Widget parent)
{
	Widget pane, buttonBox, label, button;
	static Arg shellArgs[] = {
	{XtNinput, (XtArgVal) True},
	};

	if (MesgTopLevel)
		return;

#ifdef MOTIF
	MesgTopLevel = XmCreateTemplateDialog(parent, "Information", 
					  shellArgs, XtNumber(shellArgs));

	pane = XmCreatePanedWindow(MesgTopLevel, "pane", NULL, 0);
	label = InfoLineCreate("label", 0, pane);
	MesgText = TextCreate("text", True, pane);

        XtAddCallback(MesgTopLevel, XmNcancelCallback,
		      mesgDismissXmCallback, NULL);
        XtAddCallback(MesgTopLevel, XmNokCallback, mesgClearXmCallback, NULL);

	XtRealizeWidget(MesgTopLevel);
        XtManageChild(pane);
        XtManageChild(MesgTopLevel);
#else
	MesgTopLevel = XtCreatePopupShell("Information", topLevelShellWidgetClass,
					  parent, shellArgs, XtNumber(shellArgs));

	pane = XtVaCreateManagedWidget("pane", panedWidgetClass, MesgTopLevel,
				       NULL);

	label = InfoLineCreate("label", 0, pane);

	MesgText = TextCreate("text", True, pane);

	buttonBox = ButtonBoxCreate("box", pane);

	button = ButtonBoxAddButton("mesgDismiss", mesgDismissCallbacks,
				    buttonBox);
	makeDefaultButton(button);

	(void) ButtonBoxAddButton("mesgClear", mesgClearCallbacks,
				  buttonBox);

	ButtonBoxDoneAdding(buttonBox);

	XtRealizeWidget(MesgTopLevel);
	XtSetKeyboardFocus(MesgTopLevel, MesgText);
	XtInstallAccelerators(MesgText, button);

	XDefineCursor(XtDisplay(MesgTopLevel), XtWindow(MesgTopLevel),
		      XCreateFontCursor(XtDisplay(MesgTopLevel), XC_left_ptr));

	XtPopup(MesgTopLevel, XtGrabNone);
#endif
}


void displayMesgString(new_string)
    char *new_string;
{
    long newlen = strlen(new_string);

    if (! MesgText)
	return;

    TextReplace(MesgText, new_string, newlen, current_length, current_length);
    current_length += newlen;
    TextSetInsertionPoint(MesgText, current_length);
}

/*ARGSUSED*/
#ifdef MOTIF
static void mesgDismissXmCallback(widget, client, cbsp)
    Widget widget;
    XtPointer client;
    XtPointer cbsp;
{
    XtDestroyWidget(XtParent(MesgTopLevel));
    MesgTopLevel = (Widget) 0;
    MesgText = (Widget) 0;
    current_length = 0;
}

static void mesgClearXmCallback(widget, client, cbsp)
    Widget widget;
    XtPointer client;
    XtPointer cbsp;
{
    TextClear(MesgText);
    current_length = 0;
}

#else

static void mesgDismissFunction(widget, event, string, count)
    Widget widget;
    XEvent *event;
    String *string;
    Cardinal *count;
{
    XtPopdown(MesgTopLevel);
    TextDestroy(MesgText);
    XtDestroyWidget(MesgTopLevel);
    MesgTopLevel = (Widget) 0;
    MesgText = (Widget) 0;
    current_length = 0;
}

static void mesgClearFunction(widget, event, string, count)
    Widget widget;
    XEvent *event;
    String *string;
    Cardinal *count;
{
    TextClear(MesgText);
    current_length = 0;
}
#endif