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