1/* $Xorg: log.c,v 1.4 2001/02/09 02:06:01 xorgcvs Exp $ */
2/******************************************************************************
3
4Copyright 1994, 1998  The Open Group
5
6Permission to use, copy, modify, distribute, and sell this software and its
7documentation for any purpose is hereby granted without fee, provided that
8the above copyright notice appear in all copies and that both that
9copyright notice and this permission notice appear in supporting
10documentation.
11
12The above copyright notice and this permission notice shall be included in
13all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
18OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22Except as contained in this notice, the name of The Open Group shall not be
23used in advertising or otherwise to promote the sale, use or other dealings
24in this Software without prior written authorization from The Open Group.
25******************************************************************************/
26/* $XFree86: xc/programs/xsm/log.c,v 1.4 2001/01/17 23:46:29 dawes Exp $ */
27
28#include "xsm.h"
29#include "save.h"
30#include "popup.h"
31#include "log.h"
32
33#include <X11/Shell.h>
34#include <X11/Xaw/Form.h>
35#include <X11/Xaw/Command.h>
36#include <X11/Xaw/AsciiText.h>
37
38static Widget logPopup;
39static Widget   logForm;
40static Widget	   logText;
41static Widget	   logOkButton;
42
43
44
45void
46DisplayLogXtProc(Widget w, XtPointer client_data, XtPointer callData)
47{
48    static int first_time = 1;
49
50    if (client_log_visible)
51    {
52	/* Make sure it is visible */
53
54	XMapRaised (XtDisplay (topLevel), XtWindow (logPopup));
55    }
56    else
57    {
58	PopupPopup (mainWindow, logPopup,
59	    False, first_time, 50, 50, "DelLogWinAction()");
60
61	client_log_visible = 1;
62
63	if (first_time)
64	    first_time = 0;
65    }
66}
67
68
69
70static void
71logOkXtProc(Widget w, XtPointer client_data, XtPointer callData)
72{
73    XtPopdown (logPopup);
74    client_log_visible = 0;
75}
76
77
78
79void
80add_log_text(char *str)
81{
82    XawTextPosition pos = XawTextGetInsertionPoint (logText);
83    XawTextBlock text;
84
85    text.firstPos = 0;
86    text.length = strlen (str);
87    text.ptr = str;
88    text.format = XawFmt8Bit;
89
90    XawTextReplace (logText, pos, pos, &text);
91}
92
93
94
95static void
96DelLogWinAction(Widget w, XEvent *event, String *params, Cardinal *num_params)
97{
98    XtCallCallbacks (logOkButton, XtNcallback, NULL);
99}
100
101
102
103void
104create_log_popup(void)
105
106{
107    /*
108     * Pop up for session log
109     */
110
111    static XtActionsRec actions[] = {
112        {"DelLogWinAction", DelLogWinAction}
113    };
114
115    XtAppAddActions (appContext, actions, XtNumber (actions));
116
117    logPopup = XtVaCreatePopupShell ("logPopup",
118	topLevelShellWidgetClass, topLevel,
119	XtNallowShellResize, True,
120	NULL);
121
122    logForm = XtVaCreateManagedWidget (
123	"logForm", formWidgetClass, logPopup,
124	NULL);
125
126    logText = XtVaCreateManagedWidget (
127	"logText", asciiTextWidgetClass, logForm,
128        XtNfromHoriz, NULL,
129        XtNfromVert, NULL,
130	XtNeditType, XawtextAppend,
131        XtNdisplayCaret, False,
132	XtNscrollVertical, XawtextScrollAlways,
133	XtNscrollHorizontal, XawtextScrollWhenNeeded,
134	XtNresizable, True,
135	XtNtop, XawChainTop,
136	XtNbottom, XawChainBottom,
137	NULL);
138
139    logOkButton = XtVaCreateManagedWidget (
140	"logOkButton", commandWidgetClass, logForm,
141        XtNfromHoriz, NULL,
142        XtNfromVert, logText,
143	XtNtop, XawChainBottom,
144	XtNbottom, XawChainBottom,
145	XtNleft, XawChainLeft,
146	XtNright, XawChainLeft,
147        NULL);
148
149    XtAddCallback (logOkButton, XtNcallback, logOkXtProc, NULL);
150}
151