log.c 3.8 KB

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