fs@uwasa.fi (Filip Sawicki LAKE) (06/27/90)
Submitted-by: Filip Sawicki LAKE <fs@uwasa.fi> Posting-number: Volume 8, Issue 3 Archive-name: xpostme/part01 [ Moderator's note: this posting contains stuff from xpostit written by Dave Curry. He doesn't advocate this program, but he has OK'ed it to be posted. Future patches to xpostit or xpostme do not affect one another. --dan ] [from README by Filip Sawicki LAKE <fs@uwasa.fi> ] I wasn't very pleased with the "xpostit" space-waisting design, but I love this program; so here is my own version of it. The program is called "xpostme", to avoid any confusion, but is based on the original code, and thus reads/saves notes in the same format. Application class is also "Xpostit", for the resources inheritance. Major changes: 1. Separate notes, as well as the toplevel "Plaid" box can be hidden (unmapped) and recovered at once or individually. 2. Notes' command buttons are gone, as awfully space-consuming stuff. 3. Classes of all popup objects are changed, to conform to accepted standards (e.g. TransientShell instead of OverrideShell). /* a note for a group moderator: please send me info if you're going to post it -- in this case I'll write a note to "comp.windows.x" */ #!/bin/sh # This is a shell archive (shar 3.24) # made 06/20/1990 16:19 UTC by fs@chyde # Source directory /home2/cc/fs/xpostit # # existing files WILL be overwritten # # This shar contains: # length mode name # ------ ---------- ------------------------------------------ # 2368 -rw------- README # 551 -rw------- Imakefile # 5763 -rw------- Plaid.c # 1689 -rw------- Plaid.h # 1262 -rw------- PlaidP.h # 2982 -rw------- confirm.c # 3538 -rw------- menu.c # 18798 -rw------- note.c # 1819 -rw------- plaid.c # 2041 -rw------- util.c # 4588 -rw------- xpostme.c # 3231 -rw------- xpostme.h # if touch 2>&1 | fgrep '[-amc]' > /dev/null then TOUCH=touch else TOUCH=true fi # ============= README ============== echo "x - extracting README (Text)" sed 's/^X//' << 'SHAR_EOF' > README && XWHY? X X I wasn't very pleased with the "xpostit" space-waisting design, but XI love this program; so here is my own version of it. The program is Xcalled "xpostme", to avoid any confusion, but is based on the original Xcode, and thus reads/saves notes in the same format. Application Xclass is also "Xpostit", for the resources inheritance. X X Major changes: X X1. Separate notes, as well as the toplevel "Plaid" box, can be hidden X(unmapped) and recovered at once or individually. X X2. Notes' command buttons are gone, as awfully space-consuming stuff. X X3. Classes of all popup objects are changed, to conform to accepted Xstandards (e.g. TransientShell instead of OverrideShell). X XUSAGE X X1. In the top bar of the note press: X X BTN-1 - to open menu with actions previously in command buttons. X BTN-2 - to open menu showing hidden notes. X BTN-3 - to open main menu (as in "Plaid" box). X X2. Two new command line parameters: X X -hide - hide "Plaid" box whenever possible (default: don't). X -show - show it allways (don't hide). X X3. New top-level resource (see also above): X X Name Class Type Default Value X hidePlaid HidePlaid Boolean "false" X XRESOURCES X X Here's the complete program structure tree for resources lovers: X X "Xpostit" (ApplicationShell) X "Plaid" (Plaid) X X [Popup Children: menus] X "Menu" (SimpleMenu) X "Xpostit" (smeBSB) [menu label] X ".x. Note" (smeBSB) [different note sizes] X ... X "Line1" (smeLine) X "Raise Notes", "Lower Notes", "Save Notes" (smeBSB) X "Line2" (smeLine) X "Exit" (smeBSB) X "hiddenNotes" (SimpleMenu) X "Hidden Notes" (smeBSB) [menu label] X "Note at +%d+%d" (smeBSB) [variable number] X X [Popup Box] X "Confirm" (TransientShell) [confirmation box] X "Dialog" (Dialog) X "Confirm", "Cancel" (CommandButton) X X [Popup Children: Notes] X "Note" (TopLevelShell) X "Form" (Form) X "topBar" (Simple) [with added translations] X "noteText" (AsciiText) X [some children of AsciiText] X [Note's Popup Child: menu] X "privateMenu" (SimpleMenu) X "Note Actions" (smeBSB) [menu label] X "Save Text", "Erase Text" (smeBSB) X "Hide This Note" (smeBSB) X "Line" (smeLine) X "Remove This Note" (smeBSB) X XAUTHOR X X With any complains/suggestions e-mail to "fs@uwasa.fi". As for I/O Xtroubles, I'm in touch with the original "xpostit" author, so there Xshould be no problems. X Xfi. X(Piotr Filip Sawicki, IIUW, Warsaw, Poland) SHAR_EOF $TOUCH -am 0620191890 README && chmod 0600 README || echo "restore of README failed" set `wc -c README`;Wc_c=$1 if test "$Wc_c" != "2368"; then echo original size 2368, current size $Wc_c fi # ============= Imakefile ============== echo "x - extracting Imakefile (Text)" sed 's/^X//' << 'SHAR_EOF' > Imakefile && X# X# Imakefile for xpostme. X# X# original xpostit by: X# X# David A. Curry X# SRI International X# 333 Ravenswood Avenue X# Menlo Park, CA 94025 X# davy@itstd.sri.com X# X# $Log: Imakefile,v $ X# Revision 1.2 90/06/14 11:16:50 davy X# Ported to X11 Release 4. Added app-defaults file. X# X# XLOCAL_LIBRARIES = $(XAWLIB) $(XMULIB) $(XTOOLLIB) $(XLIB) X SRCS = Plaid.c confirm.c menu.c note.c plaid.c util.c xpostme.c X OBJS = Plaid.o confirm.o menu.o note.o plaid.o util.o xpostme.o X XComplexProgramTarget(xpostme) X XInstallAppDefaults(Xpostit) X SHAR_EOF $TOUCH -am 0620135290 Imakefile && chmod 0600 Imakefile || echo "restore of Imakefile failed" set `wc -c Imakefile`;Wc_c=$1 if test "$Wc_c" != "551"; then echo original size 551, current size $Wc_c fi # ============= Plaid.c ============== echo "x - extracting Plaid.c (Text)" sed 's/^X//' << 'SHAR_EOF' > Plaid.c && X#ifndef lint Xstatic char *RCSid = "$Header: /tmp_mnt/net/sparky.a/davy/progs/xpostit/RCS/Plaid.c,v 1.2 90/06/14 11:17:42 davy Exp $"; X#endif X X/* X * Plaid.c - code for the plaid widget. X * X * Based on the Template widget from the X11R4 distribution. X * X * David A. Curry X * SRI International X * 333 Ravenswood Avenue X * Menlo Park, CA 94025 X * davy@itstd.sri.com X * X * $Log: Plaid.c,v $ X * Revision 1.2 90/06/14 11:17:42 davy X * Ported to X11 Release 4. Added translations to invoke all actions from X * the plaid widget, instead of passing the event back to a single callback. X * X * Revision 1.1 90/06/13 09:48:39 davy X * Initial revision X * X */ X#include <X11/copyright.h> X X#include <X11/IntrinsicP.h> X#include <X11/StringDefs.h> X#include "PlaidP.h" X X#define plaid_width 22 X#define plaid_height 22 X X/* X * The bits representing the plaid background. X */ Xstatic char plaid_bits[] = { X 0x75, 0xfd, 0x3f, 0xaa, 0xfa, 0x3e, 0x75, 0xfd, 0x3f, 0xaa, 0xfa, 0x3e, X 0x75, 0xfd, 0x3f, 0xff, 0x57, 0x15, 0x75, 0xfd, 0x3f, 0xaa, 0xfa, 0x3e, X 0x75, 0xfd, 0x3f, 0xaa, 0xfa, 0x3e, 0x75, 0xfd, 0x3f, 0x20, 0xa8, 0x2b, X 0x20, 0x50, 0x15, 0x20, 0xa8, 0x2b, 0x20, 0x50, 0x15, 0x20, 0xa8, 0x2b, X 0xff, 0xff, 0x3f, 0x20, 0xa8, 0x2b, 0x20, 0x50, 0x15, 0x20, 0xa8, 0x2b, X 0x20, 0x50, 0x15, 0x20, 0xa8, 0x2b X}; X X/* X * The resources specific to the plaid widget. X */ Xstatic XtResource resources[] = { X#define offset(field) XtOffset(PlaidWidget,plaid.field) X { XtNlowerCallback, XtCCallback, XtRCallback, sizeof(XtCallbackList), X offset(lower_callback), XtRCallback, NULL }, X { XtNraiseCallback, XtCCallback, XtRCallback, sizeof(XtCallbackList), X offset(raise_callback), XtRCallback, NULL }, X { XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), X offset(foreground), XtRString, "XtDefaultForeground" } X#undef offset X}; X X/***************************************************************************** X * Plaid Widget Routines X *****************************************************************************/ X X/* X * RaiseAction - called when raise button is pressed. X */ Xstatic void XRaiseAction(w, event, params, num_params) XCardinal *num_params; /* unused */ XString *params; /* unused */ XXEvent *event; XWidget w; X{ X /* X * Just pass it off to the user's callback function. X */ X XtCallCallbacks(w, XtNraiseCallback, (caddr_t) event); X} X X/* X * LowerAction - called when lower button is pressed. X */ Xstatic void XLowerAction(w, event, params, num_params) XCardinal *num_params; /* unused */ XString *params; /* unused */ XXEvent *event; XWidget w; X{ X /* X * Just pass it off to the user's callback function. X */ X XtCallCallbacks(w, XtNlowerCallback, (caddr_t) event); X} X X/* X * RealizePlaid - realize the window by creating it, and by creating the X * plaid background pixmap. X */ Xstatic void XRealizePlaid(w, value_mask, attributes) XXSetWindowAttributes *attributes; XMask *value_mask; XWidget w; X{ X Pixmap p; X Window window; X Display *display; X PlaidWidget plaidw; X X plaidw = (PlaidWidget) w; X X /* X * Create the window. X */ X XtCreateWindow(w, (unsigned int) InputOutput, X (Visual *) CopyFromParent, *value_mask, attributes); X X display = XtDisplay(w); X window = XtWindow(w); X X /* X * Create the plaid pixmap. X */ X p = XCreatePixmapFromBitmapData(display, window, plaid_bits, X plaid_width, plaid_height, X plaidw->plaid.foreground, X w->core.background_pixel, X w->core.depth); X X /* X * Tile the window. X */ X XSetWindowBackgroundPixmap(display, window, p); X X /* X * Now save the pixmap in the core widget. X */ X w->core.background_pixmap = p; X} X X/* X * DestroyPlaid - free up server resources when widget is destroyed. X */ Xstatic void XDestroyPlaid(w) XWidget w; X{ X /* X * All we need to do is get rid of the pixmap we created. X */ X XFreePixmap(XtDisplay(w), w->core.background_pixmap); X} X X/***************************************************************************** X * Plaid Widget definitions X *****************************************************************************/ X X/* X * Action table. We're only interested in button presses. X */ Xstatic XtActionsRec actions[] = X{ X { "raise", RaiseAction }, X { "lower", LowerAction } X}; X X/* X * Translation table. We're only interested in button presses. X */ Xstatic char translations[] = X "<Btn1Down>: raise() \n\ X <Btn2Down>: lower() \n\ X <Btn3Down>: XawPositionSimpleMenu(Menu) MenuPopup(Menu) \n\ X"; X X/* X * The plaid widget class record. Initialization of values. X */ XPlaidClassRec plaidClassRec = { X { /* core fields */ X /* superclass */ (WidgetClass) &widgetClassRec, X /* class_name */ "Plaid", X /* widget_size */ sizeof(PlaidRec), X /* class_initialize */ NULL, X /* class_part_initialize */ NULL, X /* class_inited */ FALSE, X /* initialize */ NULL, X /* initialize_hook */ NULL, X /* realize */ RealizePlaid, X /* actions */ actions, X /* num_actions */ XtNumber(actions), X /* resources */ resources, X /* num_resources */ XtNumber(resources), X /* xrm_class */ NULLQUARK, X /* compress_motion */ TRUE, X /* compress_exposure */ TRUE, X /* compress_enterleave */ TRUE, X /* visible_interest */ FALSE, X /* destroy */ DestroyPlaid, X /* resize */ NULL, X /* expose */ NULL, X /* set_values */ NULL, X /* set_values_hook */ NULL, X /* set_values_almost */ XtInheritSetValuesAlmost, X /* get_values_hook */ NULL, X /* accept_focus */ NULL, X /* version */ XtVersion, X /* callback_private */ NULL, X /* tm_table */ translations, X /* query_geometry */ XtInheritQueryGeometry, X /* display_accelerator */ XtInheritDisplayAccelerator, X /* extension */ NULL X }, X { /* plaid fields */ X /* empty */ 0 X } X}; X X/* X * The class declaration. X */ XWidgetClass plaidWidgetClass = (WidgetClass)&plaidClassRec; SHAR_EOF $TOUCH -am 0620123790 Plaid.c && chmod 0600 Plaid.c || echo "restore of Plaid.c failed" set `wc -c Plaid.c`;Wc_c=$1 if test "$Wc_c" != "5763"; then echo original size 5763, current size $Wc_c fi # ============= Plaid.h ============== echo "x - extracting Plaid.h (Text)" sed 's/^X//' << 'SHAR_EOF' > Plaid.h && X/* X * $Header: /tmp_mnt/net/sparky.a/davy/progs/xpostit/RCS/Plaid.h,v 1.2 90/06/14 11:18:27 davy Exp $ X * X * Plaid.h - public definitions for the plaid widget. X * X * Based on the Template widget from the X11R4 distribution. X * X * David A. Curry X * SRI International X * 333 Ravenswood Avenue X * Menlo Park, CA 94025 X * davy@itstd.sri.com X * X * $Log: Plaid.h,v $ X * Revision 1.2 90/06/14 11:18:27 davy X * Ported to X11 Release 4. X * X * Revision 1.1 90/06/13 09:48:42 davy X * Initial revision X * X */ X#include <X11/copyright.h> X X#ifndef _Plaid_h X#define _Plaid_h X X/* X * Resources: X * X * Name Class RepType Default Value X * ---- ----- ------- ------------- X * background Background Pixel XtDefaultBackground X * border BorderColor Pixel XtDefaultForeground X * borderWidth BorderWidth Dimension 1 X * callback Callback Callback NULL X * destroyCallback Callback Pointer NULL X * foreground Foreground Pixel XtDefaultForeground X * height Height Dimension 0 X * lowerCallback Callback Pointer NULL X * raiseCallback Callback Pointer NULL X * mappedWhenManaged MappedWhenManaged Boolean True X * sensitive Sensitive Boolean True X * width Width Dimension 0 X * x Position Position 0 X * y Position Position 0 X */ X X/* X * Declare specific PlaidWidget class and instance datatypes. X */ Xtypedef struct _PlaidClassRec* PlaidWidgetClass; Xtypedef struct _PlaidRec* PlaidWidget; X X/* X * Declare the class constant. X */ Xextern WidgetClass plaidWidgetClass; X X/* X * Declare a couple of new resources. X */ X#define XtNlowerCallback "lowerCallback" X#define XtNraiseCallback "raiseCallback" X X#endif /* _Plaid_h */ SHAR_EOF $TOUCH -am 0620123790 Plaid.h && chmod 0600 Plaid.h || echo "restore of Plaid.h failed" set `wc -c Plaid.h`;Wc_c=$1 if test "$Wc_c" != "1689"; then echo original size 1689, current size $Wc_c fi # ============= PlaidP.h ============== echo "x - extracting PlaidP.h (Text)" sed 's/^X//' << 'SHAR_EOF' > PlaidP.h && X/* X * $Header: /tmp_mnt/net/sparky.a/davy/progs/xpostit/RCS/PlaidP.h,v 1.2 90/06/14 11:18:37 davy Exp $ X * X * PlaidP.h - private definitions for the plaid widget. X * X * Based on the Template widget from the X11R4 distribution. X * X * David A. Curry X * SRI International X * 333 Ravenswood Avenue X * Menlo Park, CA 94025 X * davy@itstd.sri.com X * X * $Log: PlaidP.h,v $ X * Revision 1.2 90/06/14 11:18:37 davy X * Ported to X11 Release 4. X * X * Revision 1.1 90/06/13 09:48:45 davy X * Initial revision X * X */ X#include <X11/copyright.h> X X#ifndef _PlaidP_h X#define _PlaidP_h X X#include <X11/CoreP.h> X#include "Plaid.h" X X/* X * The plaid part of the class record is not used. X */ Xtypedef struct { X int empty; X} PlaidClassPart; X X/* X * Declare the class record for the widget. X */ Xtypedef struct _PlaidClassRec { X CoreClassPart core_class; X PlaidClassPart plaid_class; X} PlaidClassRec; X X/* X * Declare the plaid class record type. X */ Xextern PlaidClassRec plaidClassRec; X X/* X * Resources specific to the plaid widget. X */ Xtypedef struct { X Pixel foreground; X XtCallbackList lower_callback; X XtCallbackList raise_callback; X} PlaidPart; X X/* X * Declare the widget type. X */ Xtypedef struct _PlaidRec { X CorePart core; X PlaidPart plaid; X} PlaidRec; X X#endif /* _PlaidP_h */ SHAR_EOF $TOUCH -am 0620123790 PlaidP.h && chmod 0600 PlaidP.h || echo "restore of PlaidP.h failed" set `wc -c PlaidP.h`;Wc_c=$1 if test "$Wc_c" != "1262"; then echo original size 1262, current size $Wc_c fi # ============= confirm.c ============== echo "x - extracting confirm.c (Text)" sed 's/^X//' << 'SHAR_EOF' > confirm.c && X#ifndef lint Xstatic char *RCSid = "$Header: /tmp_mnt/net/sparky.a/davy/progs/xpostit/RCS/confirm.c,v 1.2 90/06/14 11:18:52 davy Exp Changed PFS $"; X#endif X X/* X * confirm.c - handle confirming requests made by the user. X * X * David A. Curry X * SRI International X * 333 Ravenswood Avenue X * Menlo Park, CA 94025 X * davy@itstd.sri.com X * X * $Log: confirm.c,v $ X * Revision 1.2 90/06/14 11:18:52 davy X * Ported to X11 Release 4. X * X * Revision 1.1 90/06/13 09:47:27 davy X * Initial revision X * X */ X#include <X11/StringDefs.h> X#include <X11/Intrinsic.h> X#include <X11/Xaw/Command.h> X#include <X11/Xaw/Form.h> X/* #include <X11/Xaw/Label.h> */ X#include <X11/Shell.h> X#include <X11/Xaw/Dialog.h> X#include <stdio.h> X X#include "xpostme.h" X Xstatic Widget confirmwidget; X X/* X * ConfirmIt - put up a window asking for confirmation. X */ Xvoid XConfirmIt(text, confirm_callbacks, cancel_callbacks) XXtCallbackRec *confirm_callbacks, *cancel_callbacks; XString text; X{ X Arg args[4]; X Window root, child; X unsigned int buttons; X register int nargs, nwidgets; X static Boolean inited = False; X static Widget form, widgets[3]; X int root_x, root_y, child_x, child_y; X X /* X * Find out where the mouse is, so we can put the confirmation X * box right there. X */ X XQueryPointer(display, XtWindow(toplevel), &root, &child, X &root_x, &root_y, &child_x, &child_y, &buttons); X X /* X * If we need to construct the confirmation box do that, X * otherwise just reset the position and callbacks and X * put it up again. X */ X if (!inited) { X nargs = 0; X SetArg(XtNx, root_x); X SetArg(XtNy, root_y); X X /* X * The confirmation box will be a pop-up widget. X */ X confirmwidget = XtCreatePopupShell("Confirm", X transientShellWidgetClass, X toplevel, args, nargs); X X /* X * Make a form to put the buttons in. X */ X X nargs = 0; X SetArg(XtNlabel, text); X widgets[0] = form = XtCreateManagedWidget("Dialog", dialogWidgetClass, confirmwidget, X args, nargs); X X nargs = 0; X SetArg(XtNcallback, confirm_callbacks); X widgets[1] = XtCreateManagedWidget("Confirm", commandWidgetClass, form, args, nargs); X X nargs = 0; X SetArg(XtNcallback, cancel_callbacks); X widgets[2] = XtCreateManagedWidget("Cancel", commandWidgetClass, form, args, nargs); X X XtRealizeWidget(confirmwidget); X inited = True; X } X else { X /* X * Reset the confirmation box position. X */ X nargs = 0; X SetArg(XtNx, root_x); X SetArg(XtNy, root_y); X XtSetValues(confirmwidget, args, nargs); X X nargs = 0; X SetArg(XtNlabel, text); X XtSetValues(widgets[0], args, nargs); X /* X * Reset the callbacks. X */ X nargs = 0; X SetArg(XtNcallback, confirm_callbacks); X XtSetValues(widgets[1], args, nargs); X X nargs = 0; X SetArg(XtNcallback, cancel_callbacks); X XtSetValues(widgets[2], args, nargs); X } X X /* X * Pop up the confirmation box. X */ X XtPopup(confirmwidget, XtGrabExclusive); X} X X/* X * ClearConfirm - get rid of the confirmation box. X */ Xvoid XClearConfirm() X{ X XtPopdown(confirmwidget); X} SHAR_EOF $TOUCH -am 0620135490 confirm.c && chmod 0600 confirm.c || echo "restore of confirm.c failed" set `wc -c confirm.c`;Wc_c=$1 if test "$Wc_c" != "2982"; then echo original size 2982, current size $Wc_c fi # ============= menu.c ============== echo "x - extracting menu.c (Text)" sed 's/^X//' << 'SHAR_EOF' > menu.c && X#ifndef lint Xstatic char *RCSid = "$Header: /tmp_mnt/net/sparky.a/davy/progs/xpostit/RCS/menu.c,v 1.2 90/06/14 11:19:39 davy Exp Cnahged PFS $"; X#endif X X/* X * menu.c - routines to handle the menu. X * X * David A. Curry X * SRI International X * 333 Ravenswood Avenue X * Menlo Park, CA 94025 X * davy@itstd.sri.com X * X * $Log: menu.c,v $ X * Revision 1.2 90/06/14 11:19:39 davy X * Ported to X11 Release 4. Changed to use the SimpleMenu widget instead X * of a List widget for the menu. X * X * Revision 1.1 90/06/13 09:48:47 davy X * Initial revision X * X */ X#include <X11/StringDefs.h> X#include <X11/Intrinsic.h> X#include <X11/Xaw/SimpleMenu.h> X#include <X11/Xaw/SmeLine.h> X#include <X11/Xaw/SmeBSB.h> X#include <X11/Shell.h> X#include <stdio.h> X X#include "xpostme.h" X Xstatic String menu_1a_[] = { X#define MenuCreate_1p5x1 0 X "1.5x1 Note", X#define MenuCreate_1p5x2 1 X "1.5x2 Note", X#define MenuCreate_2x3 2 X "2x3 Note", X#define MenuCreate_3x3 3 X "3x3 Note", X#define MenuCreate_3x4 4 X "3x4 Note", X#define MenuCreate_3x5 5 X "3x5 Note", X#define MenuCreate_4x6 6 X "4x6 Note" X}; X Xstatic struct { X char *text; X void (*callback)(); X} menu_1b_[] = { X { "Line1", NULL }, X { "Raise Notes", RaiseAllNotes }, X { "Lower Notes", LowerAllNotes }, X { "Save Notes", SaveAllNotes }, X { "Line2", NULL }, X { "Exit", ByeBye } X}; X XWidget menuwidget; Xextern XtAppContext appcontext; Xstatic void HandleMenuSelection(); X X/* X * CreateMenuWidget - create the widget used for the menus. X */ Xvoid XCreateMenuWidget() X{ X Arg args[8]; X Widget entry; X register int i, nargs; X XtCallbackRec callbacks[2]; X X nargs = 0; X SetArg(XtNmenuOnScreen, True); X SetArg(XtNlabel, PostItNoteClass); X X menuwidget = XtCreatePopupShell(MAIN_MENU, simpleMenuWidgetClass, X toplevel, args, nargs); X X nargs = 0; X SetArg(XtNcallback, callbacks); X callbacks[0].callback = HandleMenuSelection; X callbacks[1].callback = NULL; X callbacks[1].closure = NULL; X X for (i=0; i<sizeof(menu_1a_)/sizeof(menu_1a_[0]); i++) { X callbacks[0].closure = (caddr_t) i; X (void) XtCreateManagedWidget(menu_1a_[i], X smeBSBObjectClass, menuwidget, X args, nargs); X } X X callbacks[0].closure = NULL; X for (i=0; i<sizeof(menu_1b_)/sizeof(menu_1b_[0]); i++) { X callbacks[0].callback = menu_1b_[i].callback; X if (i && i!=4) X (void) XtCreateManagedWidget(menu_1b_[i].text, smeBSBObjectClass, X menuwidget, args, nargs); X else X (void) XtCreateManagedWidget(menu_1b_[i].text, smeLineObjectClass, X menuwidget, args, nargs); X } X X XtRealizeWidget(menuwidget); X X nargs = 0; X SetArg(XtNmenuOnScreen, True); X SetArg(XtNlabel, "Hidden Notes"); X X menuwidget = XtCreatePopupShell(HIDDEN_MENU, simpleMenuWidgetClass, X toplevel, args, nargs); X X XtRealizeWidget(menuwidget); X /* from now on, this points to the hidden notes menu, which is often changed */ X} X X/* X * HandleMenuSelection - callback from menu widget to handle a selection. X */ Xstatic void XHandleMenuSelection(w, client_data, call_data) Xcaddr_t client_data, call_data; XWidget w; X{ X /* X * Dispatch the command. X */ X switch ((int) client_data) { X case MenuCreate_1p5x1: X CreateNewNote(PostItNote_1p5x1); X break; X case MenuCreate_1p5x2: X CreateNewNote(PostItNote_1p5x2); X break; X case MenuCreate_2x3: X CreateNewNote(PostItNote_2x3); X break; X case MenuCreate_3x3: X CreateNewNote(PostItNote_3x3); X break; X case MenuCreate_3x4: X CreateNewNote(PostItNote_3x4); X break; X case MenuCreate_3x5: X CreateNewNote(PostItNote_3x5); X break; X case MenuCreate_4x6: X CreateNewNote(PostItNote_4x6); X break; X } X} SHAR_EOF $TOUCH -am 0620135490 menu.c && chmod 0600 menu.c || echo "restore of menu.c failed" set `wc -c menu.c`;Wc_c=$1 if test "$Wc_c" != "3538"; then echo original size 3538, current size $Wc_c fi # ============= note.c ============== echo "x - extracting note.c (Text)" sed 's/^X//' << 'SHAR_EOF' > note.c && X#ifndef lint Xstatic char *RCSid = "$Header: /tmp_mnt/net/sparky.a/davy/progs/xpostit/RCS/note.c,v 1.4 90/06/14 11:20:09 davy Exp Changed PFS $"; X#endif X X/* X * note.c - routines for handling notes. X * X * David A. Curry X * SRI International X * 333 Ravenswood Avenue X * Menlo Park, CA 94025 X * davy@itstd.sri.com X * X * $Log: note.c,v $ X * Revision 1.4 90/06/14 11:20:09 davy X * Ported to X11 Release 4. Changed to get the note save position in an X * ICCCM compliant (although kludgy) way. X * X * Revision 1.3 89/01/10 09:57:24 davy X * Changed XGetNormalHints to XGetWindowAttributes for getting the size of X * the text window when saving. XGetNormalHints comes up with the wrong X * size, for some reason. X * X * Revision 1.2 89/01/10 09:13:13 davy X * Added XtChain... arguments to buttons and text window to prevent the X * buttons from getting screwed up on a resize. X * X * Revision 1.1 89/01/10 09:00:21 davy X * Initial revision X * X */ X#include <X11/StringDefs.h> X#include <X11/Intrinsic.h> X#include <X11/Xaw/AsciiText.h> X#include <X11/Xaw/Command.h> X#include <X11/Xaw/Form.h> X#include <X11/Xaw/Simple.h> X#include <X11/Shell.h> X#include <sys/param.h> X#include <sys/dir.h> X#include <stdio.h> X#include <X11/Xaw/SimpleMenu.h> X#include <X11/Xaw/SmeLine.h> X#include <X11/Xaw/SmeBSB.h> X X#include "xpostme.h" X Xstatic PostItNote *notes = NULL; X Xstatic PostItNote *FindNote(); Xstatic PostItNote *AllocNote(); X Xstatic void SaveNote(); Xstatic void EraseNote(); Xstatic void HideNote(); Xstatic void DestroyNote(); Xstatic void CancelErase(); Xstatic void ConfirmErase(); Xstatic void CancelDestroy(); Xstatic void ConfirmDestroy(); Xstatic void MakeNoteWidget(); X Xstatic void GoMenu(); X Xstatic struct { X char *text; X void (*callback)(); X} menu_2_[] = { X { "Save Text", SaveNote }, X { "Erase Text", EraseNote }, X { "Hide This Note", HideNote }, X { "Line", NULL }, X { "Remove This Note", DestroyNote } X}; X X/* X * CreateNewNote - create a new note of the specified size. X */ Xvoid XCreateNewNote(size) Xint size; X{ X static int hpi = 0; X static int wpi = 0; X register PostItNote *pn; X register int hmm, wmm, hpixel, wpixel; X X /* X * Find out the number of pixels per inch on the screen. We X * can get the number of pixels, and the size in millimeters. X * Then we convert to pixels/inch using the formula X * X * 2.54 cm 10 mm pixels pixels X * --------- x ------- x -------- = -------- X * inch cm mm inch X * X * The only problem with this is that some servers (like Xsun) X * lie about what these numbers really are. X */ X if ((hpi == 0) || (wpi == 0)) { X hpixel = DisplayHeight(display, DefaultScreen(display)); X wpixel = DisplayWidth(display, DefaultScreen(display)); X X hmm = DisplayHeightMM(display, DefaultScreen(display)); X wmm = DisplayWidthMM(display, DefaultScreen(display)); X X hpi = (int) ((25.4 * hpixel) / (float) hmm + 0.5); X wpi = (int) ((25.4 * wpixel) / (float) wmm + 0.5); X } X X /* X * Calculate sizes for the note. X */ X switch (size) { X case PostItNote_1p5x1: X hpixel = 1.5 * hpi; X wpixel = 1.425 * wpi - 1; X break; X case PostItNote_1p5x2: X hpixel = 1.5 * hpi; X wpixel = 2 * wpi; X break; X case PostItNote_2x3: X hpixel = 2 * hpi; X wpixel = 3 * wpi; X break; X case PostItNote_3x3: X hpixel = 3 * hpi; X wpixel = 3 * wpi; X break; X case PostItNote_3x4: X hpixel = 3 * hpi; X wpixel = 4 * wpi; X break; X case PostItNote_3x5: X hpixel = 3 * hpi; X wpixel = 5 * wpi; X break; X case PostItNote_4x6: X hpixel = 4 * hpi; X wpixel = 6 * wpi; X break; X } X X /* X * Allocate a new note structure. X */ X pn = AllocNote(NewIndex); X X /* X * Set the text window size. X */ X pn->pn_textwidth = wpixel; X pn->pn_textheight = hpixel; X X /* X * Make the widget for the note. X */ X MakeNoteWidget(pn); X} X X/* X * LoadSavedNotes - load in the notes the user has saved. X */ Xvoid XLoadSavedNotes() X{ X DIR *dp; X FILE *fp; X char *realloc(); X register PostItNote *pn; X register struct direct *d; X char buf[BUFSIZ], fname[MAXPATHLEN]; X int n, len, nlen, shellx, shelly, texth, textw; X X /* X * Try to open the directory. X */ X if ((dp = opendir(app_res.note_dir)) == NULL) X /* return; */ X goto skipped; X X nlen = strlen(PostItNoteFname); X X /* X * For each entry... X */ X while ((d = readdir(dp)) != NULL) { X /* X * Skip over anything which doesn't match our X * file naming scheme. X */ X if (strncmp(d->d_name, PostItNoteFname, nlen) != 0) X continue; X X /* X * Make the full path name. X */ X sprintf(fname, "%s/%s", app_res.note_dir, d->d_name); X X /* X * Open the file. X */ X if ((fp = fopen(fname, "r")) == NULL) X continue; X X /* X * Look for the magic cookie identifying this as X * a Post-It note. X */ X if ((fscanf(fp, "%s", buf) == EOF) || X (strcmp(buf, PostItNoteMagic) != 0)) { X fclose(fp); X continue; X } X X /* X * Get the note position and size information. X */ X fgets(buf, sizeof(buf), fp); X X n = sscanf(buf, "%d %d %d %d %d", &shellx, &shelly, &texth, X &textw, &len); X X /* X * Bad format; skip it. X */ X if (n != 5) { X fclose(fp); X continue; X } X X /* X * Get the index number of this note. X */ X n = atoi(&(d->d_name[nlen])); X X /* X * Get a note structure. X */ X pn = AllocNote(n); X X /* X * Set the information. X */ X pn->pn_shellx = shellx; X pn->pn_shelly = shelly; X pn->pn_textwidth = textw; X pn->pn_textheight = texth; X pn->pn_positionit = True; X X /* X * Save the file name. X */ X pn->pn_file = SafeAlloc(strlen(fname) + 1); X strcpy(pn->pn_file, fname); X X /* X * If we need a bigger buffer than the default, X * get one. X */ X if (len >= pn->pn_textsize) { X n = (len + app_res.buf_size - 1) / app_res.buf_size; X n = n * app_res.buf_size; X X if ((pn->pn_text = realloc(pn->pn_text, n)) == NULL) { X fprintf(stderr, "xpostme: out of memory.\n"); X ByeBye(); X } X X pn->pn_textsize = n; X } X X /* X * Read in the text. X */ X fread(pn->pn_text, sizeof(char), len, fp); X fclose(fp); X X /* X * Make a widget for this note. X */ X MakeNoteWidget(pn); X } X X closedir(dp); X Xskipped: X if (!notes || !app_res.hide_plaid) X XtMapWidget(toplevel); X} X Xstatic void RaiseNote(w, c, garbage) XWidget w; Xcaddr_t c, garbage; X{ X PostItNote *pn = (PostItNote *) c; X if (pn->pn_unmapped) { X pn->pn_unmapped = FALSE; X XtMapWidget(pn->pn_shellwidget); X XtUnmanageChild(w); X } X XRaiseWindow(display, XtWindow(pn->pn_shellwidget)); X} X X/* X * RaiseAllNotes - raise all the notes by raising their shell windows. X */ Xvoid XRaiseAllNotes() X{ X register PostItNote *pn; X X for (pn = notes; pn != NULL; pn = pn->pn_next) X RaiseNote(pn->pn_menuentry, (caddr_t) pn, (caddr_t) NULL); X X if (app_res.hide_plaid && pn != notes) X XtUnmapWidget(toplevel); X} X X/* X * LowerAllNotes - lower all the notes by lowering their shell windows. X */ Xvoid XLowerAllNotes() X{ X register PostItNote *pn; X X for (pn = notes; pn != NULL; pn = pn->pn_next) X XLowerWindow(display, XtWindow(pn->pn_shellwidget)); X} X X/* X * SaveAllNotes - save all the notes. X */ Xvoid XSaveAllNotes() X{ X register PostItNote *pn; X X for (pn = notes; pn != NULL; pn = pn->pn_next) X SaveNote(pn->pn_shellwidget, (caddr_t) pn, 0); X} X X/* X * MakeNoteWidget - make a widget for a Post-It note. X */ Xstatic void XMakeNoteWidget(pn) XPostItNote *pn; X{ X Arg args[16]; X char geometry[64]; X Widget form, menu, simple; X XtCallbackRec callbacks[2]; X register int nargs; X int i; X static char *formtrans = "<Btn3Down>: XawPositionSimpleMenu(Menu) MenuPopup(Menu) \n\ X<Btn1Down>: XawPositionSimpleMenu(privateMenu) MenuPopup(privateMenu) \n\ X<Btn2Down>: XawPositionSimpleMenu(hiddenNotes) MenuPopup(hiddenNotes)"; X XtTranslations tt; X X nargs = 0; X X /* X * If the shell window coordinates are valid, use them. X */ X if (pn->pn_positionit) { X sprintf(geometry, "+%d+%d", pn->pn_shellx, pn->pn_shelly); X SetArg(XtNgeometry, geometry); X SetArg(XtNx, pn->pn_shellx); X SetArg(XtNy, pn->pn_shelly); X } X X /* X * Make the shell widget for this note. We just use X * a pop-up shell for this. X */ X pn->pn_shellwidget = XtCreatePopupShell("Note", X topLevelShellWidgetClass, toplevel, X args, nargs); X X pn->pn_menuentry = NULL; X X /* X * Make a form widget. X */ X nargs = 0; X SetArg(XtNdefaultDistance, 0); X form = XtCreateManagedWidget("Form", formWidgetClass, pn->pn_shellwidget, X args, nargs); X X /* X * Create simple to popup menus X */ X nargs = 0; X SetArg(XtNtop, XtChainTop); X SetArg(XtNleft, XtChainLeft); X SetArg(XtNright, XtChainRight); X SetArg(XtNbottom, XtChainTop); /* keep the constant height */ X SetArg(XtNheight, 8); X SetArg(XtNwidth, pn->pn_textwidth); X SetArg(XtNtranslations, XtParseTranslationTable(formtrans)); X SetArg(XtNbackground, foreground); X simple = XtCreateManagedWidget("topBar", simpleWidgetClass, form, X args, nargs); X X /* X * Create the text window. X */ X nargs = 0; X SetArg(XtNtop, XtChainTop); X SetArg(XtNfromVert, simple); X SetArg(XtNleft, XtChainLeft); X SetArg(XtNright, XtChainRight); X SetArg(XtNstring, pn->pn_text); X SetArg(XtNeditType, XawtextEdit); X SetArg(XtNbottom, XtChainBottom); X SetArg(XtNuseStringInPlace, True); X SetArg(XtNlength, pn->pn_textsize); X SetArg(XtNwidth, pn->pn_textwidth); X SetArg(XtNheight, pn->pn_textheight); X SetArg(XtNresize, XawtextResizeNever); X X if (app_res.scroll_bar) { X SetArg(XtNscrollVertical, XawtextScrollAlways); X } X else { X SetArg(XtNscrollVertical, XawtextScrollWhenNeeded); X } X X pn->pn_textwidget = XtCreateManagedWidget("noteText", asciiTextWidgetClass, X form, args, nargs); X X /* X * add needed stuff X */ X X nargs = 0; X SetArg(XtNlabel, "Note Actions"); X menu = XtCreatePopupShell(PRIVATE_MENU, simpleMenuWidgetClass, form, args, nargs); X nargs = 0; X SetArg(XtNcallback, callbacks); X callbacks[0].closure = (caddr_t) pn; X callbacks[1].callback = NULL; X callbacks[1].closure = NULL; X X for (i=0; i<sizeof(menu_2_)/sizeof(menu_2_[0]); i++) { X callbacks[0].callback = menu_2_[i].callback; X if (i != 3) X (void) XtCreateManagedWidget(menu_2_[i].text, smeBSBObjectClass, menu, args, nargs); X else X (void) XtCreateManagedWidget(menu_2_[i].text, smeLineObjectClass, menu, args, nargs); X } X X /* X * Realize the note and pop it up. X */ X X XtRealizeWidget(pn->pn_shellwidget); X if (app_res.hide_plaid) X XtUnmapWidget(toplevel); X pn->pn_unmapped = FALSE; /* visible */ X XtPopup(pn->pn_shellwidget, XtGrabNone); X} X X/* X * SaveNote - save a note to a file. X */ Xstatic void XSaveNote(w, client_data, call_data) Xcaddr_t client_data, call_data; XWidget w; X{ X FILE *fp; X Window junk; X char *MakeFname(); X PostItNote *pn = (PostItNote *) client_data; X XWindowAttributes win_attributes; X int len, shellx, shelly, texth, textw; X X /* X * If it doesn't have a file name, make one. X */ X if (pn->pn_file == NULL) X pn->pn_file = MakeFname(pn->pn_index); X X /* X * Create the file. X */ X if ((fp = fopen(pn->pn_file, "w")) == NULL) { X fprintf(stderr, "xpostit: "); X perror(pn->pn_file); X return; X } X X /* X * Get the position of the shell window. X */ X GetNotePosition(pn->pn_shellwidget, &shellx, &shelly); X X /* X * Get the size of the text window. X */ X XGetWindowAttributes(display, XtWindow(pn->pn_textwidget), X &win_attributes); X texth = win_attributes.height; X textw = win_attributes.width; X X /* X * Get the length of the text in the window. X */ X len = strlen(pn->pn_text); X X /* X * Print out the information needed to recreate the note. X */ X fprintf(fp, "%s %d %d %d %d %d\n", PostItNoteMagic, shellx, shelly, X texth, textw, len); X X /* X * Write out the text of the note. X */ X if (len) X fwrite(pn->pn_text, sizeof(char), len, fp); X X fclose(fp); X} X X/* X * EraseNote - erase all the text in a note. X */ Xstatic void XEraseNote(w, client_data, call_data) Xcaddr_t client_data, call_data; XWidget w; X{ X PostItNote *pn = (PostItNote *) client_data; X XtCallbackRec cancel[2], confirm[2]; X X bzero(confirm, sizeof(confirm)); X bzero(cancel, sizeof(cancel)); X X /* X * If there's nothing in the window, then there's X * no need to erase it. X */ X if (strlen(pn->pn_text) == 0) X return; X X confirm[0].callback = ConfirmErase; X confirm[0].closure = (caddr_t) pn; X cancel[0].callback = CancelErase; X cancel[0].closure = (caddr_t) pn; X X /* X * Get confirmation of what they want to do. X */ X ConfirmIt("Erase This Note: ", confirm, cancel); X} X X/* X * DestroyNote - destroy a note. X */ Xstatic void XDestroyNote(w, client_data, call_data) Xcaddr_t client_data, call_data; XWidget w; X{ X PostItNote *pn = (PostItNote *) client_data; X XtCallbackRec cancel[2], confirm[2]; X X bzero(confirm, sizeof(confirm)); X bzero(cancel, sizeof(cancel)); X X confirm[0].callback = ConfirmDestroy; X confirm[0].closure = (caddr_t) pn; X cancel[0].callback = CancelDestroy; X cancel[0].closure = (caddr_t) pn; X X /* X * Get confirmation of what they want to do. X */ X ConfirmIt("Destroy This Note:", confirm, cancel); X} X X/* X * ConfirmErase - callback for erase confirmation. X */ Xstatic void XConfirmErase(w, client_data, call_data) Xcaddr_t client_data, call_data; XWidget w; X{ X Arg args[4]; X register int nargs; X PostItNote *pn = (PostItNote *) client_data; X XawTextPosition pos = 0; X X /* X * Get rid of the confirmation box. X */ X ClearConfirm(); X X /* X * This is a kludge. They should have provided X * an XtTextErase function. X */ X bzero(pn->pn_text, pn->pn_textsize); X X nargs = 0; X SetArg(XtNstring, pn->pn_text); X XtSetValues(pn->pn_textwidget, args, nargs); X} X X/* X * CancelErase - callback for erase cancellation. X */ Xstatic void XCancelErase(w, client_data, call_data) Xcaddr_t client_data, call_data; XWidget w; X{ X /* X * Get rid of the confirmation box. X */ X ClearConfirm(); X} X X/* X * ConfirmDestroy - callback for destroy confirmation. X */ Xstatic void XConfirmDestroy(w, client_data, call_data) Xcaddr_t client_data, call_data; XWidget w; X{ X PostItNote *pn = (PostItNote *) client_data, *prev; X X /* X * Get rid of the confirmation box. X */ X ClearConfirm(); X X /* X * Get rid of the widgets for this note. X */ X XtDestroyWidget(pn->pn_shellwidget); /* but it still will hang around */ X if (pn->pn_menuentry) X XtDestroyWidget(pn->pn_menuentry); X X /* X * Get rid of the note structure. X */ X if (pn != notes) { X for (prev = notes; prev->pn_next; prev = prev->pn_next) { X if (prev->pn_next == pn) X break; X } X X prev->pn_next = pn->pn_next; X } X else { X notes = pn->pn_next; X } X X /* X * Get rid of the file. X */ X if (pn->pn_file) { X unlink(pn->pn_file); X free(pn->pn_file); X } X X /* X * Free the memory we used. X */ X free(pn->pn_text); X free(pn); X X for (pn = notes; pn; pn = pn->pn_next) X if (!pn->pn_unmapped) X break; X X if (app_res.hide_plaid && !pn) { /* no note is visible */ X XtMapWidget(toplevel); X XLowerWindow(XtDisplay(toplevel), XtWindow(toplevel)); X } X} X X/* X * CancelDestroy - callback for destroy cancellation. X */ Xstatic void XCancelDestroy(w, client_data, call_data) Xcaddr_t client_data, call_data; XWidget w; X{ X /* X * Get rid of the confirmation box. X */ X ClearConfirm(); X} X X/* X * AllocNote - allocate a new note structure and insert in into the X * list of notes. X */ Xstatic PostItNote * XAllocNote(index) Xint index; X{ X register PostItNote *pn; X X /* X * Allocate a structure. X */ X if (notes == NULL) { X notes = (PostItNote *) SafeAlloc(sizeof(PostItNote)); X pn = notes; X } X else { X for (pn = notes; pn->pn_next != NULL; pn = pn->pn_next) X ; X X pn->pn_next = (PostItNote *) SafeAlloc(sizeof(PostItNote)); X pn = pn->pn_next; X } X X /* X * Initialize the note. X */ X pn->pn_positionit = False; X pn->pn_textsize = app_res.buf_size; X pn->pn_text = SafeAlloc(pn->pn_textsize); X X /* X * If the index number was given, use it. Otherwise, X * get a new index number. X */ X pn->pn_index = (index == NewIndex ? NoteIndex() : index); X X return(pn); X} X X/* X * FindNote - find the note structure with the given index number. X */ Xstatic PostItNote * XFindNote(index) Xregister int index; X{ X register PostItNote *pn; X X for (pn = notes; pn != NULL; pn = pn->pn_next) { X if (pn->pn_index == index) X return(pn); X } X X return(NULL); X} X X/* X * NoteIndex - find the lowest free index number. X */ Xstatic int XNoteIndex() X{ X register int index; X register PostItNote *pn; X X /* X * This is O(n**2), but the list should be small. X */ X for (index = 1; ; index++) { X if ((pn = FindNote(index)) == NULL) X return(index); X } X} X X/* X * GetNotePosition - find the position of the widget window, taking into X * account any borders stuck on by reparenting window X * managers. X * X * This is a KLUDGE. The ICCCM does not specify a way X * for a client to find out what kind of border stuff X * the window manager has added. X * X * Thanks to Stewart Levin for the original code. X */ XGetNotePosition(w, x, y) Xint *x, *y; XWidget w; X{ X Window *children; X int status, nchildren; X Window here, parent, root; X XWindowAttributes win_attributes; X X parent = XtWindow(w); X X /* X * Walk up the tree looking for a parent of this window whose X * parent is the root. That'll either be this window (if there X * is no window manager window) or the window added by the X * window manager. X */ X do { X here = parent; X X status = XQueryTree(display, here, &root, &parent, &children, X &nchildren); X X if (!status) X break; X X if (children) X XFree(children); X } while (parent != root); X X /* X * Get the attributes of this window we just found. X */ X XGetWindowAttributes(display, here, &win_attributes); X X /* X * Now deduct the border from the position of the window. X * We know the coordinates don't need translating, since X * this window's parent is the root. X */ X *x = win_attributes.x - win_attributes.border_width; X *y = win_attributes.y - win_attributes.border_width; X} X X/* unused event handler */ Xstatic void GoMenu(w, c, event) XWidget w; Xcaddr_t c; XXEvent *event; X{ X char *m = MAIN_MENU; X XtCallActionProc(w, "XawPositionSimpleMenu", event, &m, 1); X XtCallActionProc(w, "MenuPopup", event, &m, 1); X} X Xstatic void HideNote(w, client_data, garbage) XWidget w; Xcaddr_t client_data, garbage; X{ X PostItNote *pn = (PostItNote *) client_data; X int nargs = 0; X Arg args[2]; X Widget entry; X char buf[40]; X X GetNotePosition(pn->pn_shellwidget, &pn->pn_shellx, &pn->pn_shelly); X XtUnmapWidget(pn->pn_shellwidget); X SetArg(XtNx, pn->pn_shellx); X SetArg(XtNy, pn->pn_shelly); X XtSetValues(pn->pn_shellwidget, args, nargs); X pn->pn_unmapped = TRUE; X X /* add this note to the menu */ X sprintf(buf, "Note at +%d+%d", pn->pn_shellx, pn->pn_shelly); X nargs = 0; X SetArg(XtNlabel, buf); X if (!pn->pn_menuentry) { X pn->pn_menuentry = XtCreateWidget("hidden", smeBSBObjectClass, X menuwidget, args, nargs); X XtAddCallback(pn->pn_menuentry, XtNcallback, RaiseNote, (caddr_t) pn); X } X else X XtSetValues(pn->pn_menuentry, args, nargs); X X XtManageChild(pn->pn_menuentry); X X for (pn = notes; pn; pn = pn->pn_next) X if (!pn->pn_unmapped) X break; X X if (app_res.hide_plaid && !pn) /* all notes are unmapped */ X XtMapWidget(toplevel); X} X X X X SHAR_EOF $TOUCH -am 0620190290 note.c && chmod 0600 note.c || echo "restore of note.c failed" set `wc -c note.c`;Wc_c=$1 if test "$Wc_c" != "18798"; then echo original size 18798, current size $Wc_c fi # ============= plaid.c ============== echo "x - extracting plaid.c (Text)" sed 's/^X//' << 'SHAR_EOF' > plaid.c && X#ifndef lint Xstatic char *RCSid = "$Header: /tmp_mnt/net/sparky.a/davy/progs/xpostit/RCS/plaid.c,v 1.3 90/06/14 11:20:42 davy Exp Changed PFS $"; X#endif X X/* X * plaid.c - routines for manipulating the plaid widget. X * X * David A. Curry X * SRI International X * 333 Ravenswood Avenue X * Menlo Park, CA 94025 X * davy@itstd.sri.com X * X * $Log: plaid.c,v $ X * Revision 1.3 90/06/14 11:20:42 davy X * Ported to X11 Release 4. Got rid of button callback from the Plaid widget, X * since it handles its own actions now. X * X * Revision 1.2 89/01/10 09:30:30 davy X * Fixed menu call-up so that the menu is always on the screen. X * X * Revision 1.1 89/01/10 09:13:59 davy X * Initial revision X * X */ X#include <X11/StringDefs.h> X#include <X11/Intrinsic.h> X#include <stdio.h> X X#include "xpostme.h" X#include "Plaid.h" X XWidget plaidwidget; X X/* X * CreatePlaidWidget - create the plaid widget. X */ XWidget XCreatePlaidWidget() X{ X Arg args[4]; X register int nargs; X X /* X * Create the plaid widget. X */ X plaidwidget = XtCreateWidget("Plaid", plaidWidgetClass, toplevel, X NULL, 0); X X XtAddCallback(plaidwidget, XtNlowerCallback, LowerAllNotes, 0); X XtAddCallback(plaidwidget, XtNraiseCallback, RaiseAllNotes, 0); X X /* X * Get the width and height of the widget. X */ X nargs = 0; X SetArg(XtNwidth, NULL); X SetArg(XtNheight, NULL); X XtGetValues(plaidwidget, args, nargs); X X /* X * If the user didn't set them, then we X * should set them to the defaults. X */ X if ((args[0].value == 0) || (args[1].value == 0)) { X if (args[0].value == 0) X XtSetArg(args[0], XtNwidth, DefaultPlaidWidth); X X if (args[1].value == 0) X XtSetArg(args[1], XtNheight, DefaultPlaidHeight); X X XtSetValues(plaidwidget, args, nargs); X } X X /* X * Inform the application shell we're here. X */ X XtManageChild(plaidwidget); X return(plaidwidget); X} SHAR_EOF $TOUCH -am 0620135490 plaid.c && chmod 0600 plaid.c || echo "restore of plaid.c failed" set `wc -c plaid.c`;Wc_c=$1 if test "$Wc_c" != "1819"; then echo original size 1819, current size $Wc_c fi # ============= util.c ============== echo "x - extracting util.c (Text)" sed 's/^X//' << 'SHAR_EOF' > util.c && X#ifndef lint Xstatic char *RCSid = "$Header: /tmp_mnt/net/sparky.a/davy/progs/xpostit/RCS/util.c,v 1.2 90/06/14 11:21:14 davy Exp Changed PFS $"; X#endif X X/* X * util.c - utility routines. X * X * David A. Curry X * SRI International X * 333 Ravenswood Avenue X * Menlo Park, CA 94025 X * davy@itstd.sri.com X * X * $Log: util.c,v $ X * Revision 1.2 90/06/14 11:21:14 davy X * Ported to X11 Release 4. X * X * Revision 1.1 90/06/13 09:48:49 davy X * Initial revision X * X */ X#include <X11/StringDefs.h> X#include <X11/Intrinsic.h> X#include <sys/param.h> X#include <stdio.h> X#include <pwd.h> X X#include "xpostme.h" X X/* X * ByeBye - clean up and exit. X */ Xvoid XByeBye() X{ X /* X * If saving notes is on, save all notes. X */ X if (app_res.save_notes) X SaveAllNotes(); X X XtDestroyWidget(toplevel); X XCloseDisplay(display); X exit(0); X} X X/* X * SetNoteDir - determine the path to the note directory. X */ Xvoid XSetNoteDir() X{ X char *getenv(); X char *home, *s; X struct passwd *pwd; X char fname[MAXPATHLEN]; X X /* X * If it's an absolute path name, X * we're done. X */ X if (app_res.note_dir[0] == '/') X return; X X /* X * Find the user's home directory. X */ X if ((home = getenv("HOME")) == NULL) { X if ((pwd = getpwuid(getuid())) == NULL) { X fprintf(stderr, "xpostme: who are you?\n"); X exit(1); X } X X home = pwd->pw_dir; X } X X /* X * Save the path. X */ X sprintf(fname, "%s/%s", home, app_res.note_dir); X X s = SafeAlloc(strlen(fname) + 1); X app_res.note_dir = s; X strcpy(s, fname); X} X X/* X * MakeFname - make a file name from a note index number. X */ Xchar * XMakeFname(index) Xregister int index; X{ X char *s; X char fname[MAXPATHLEN]; X X sprintf(fname, "%s/%s%d", app_res.note_dir, PostItNoteFname, index); X s = SafeAlloc(strlen(fname) + 1); X strcpy(s, fname); X return(s); X} X X/* X * SafeAlloc - allocate n bytes of memory, exit if we run out. X */ Xchar * XSafeAlloc(nbytes) Xregister int nbytes; X{ X char *malloc(); X register char *s; X X if ((s = malloc(nbytes)) == NULL) { X fprintf(stderr, "xpostme: out of memory.\n"); X exit(1); X } X X bzero(s, nbytes); X return(s); X} SHAR_EOF $TOUCH -am 0620135490 util.c && chmod 0600 util.c || echo "restore of util.c failed" set `wc -c util.c`;Wc_c=$1 if test "$Wc_c" != "2041"; then echo original size 2041, current size $Wc_c fi # ============= xpostme.c ============== echo "x - extracting xpostme.c (Text)" sed 's/^X//' << 'SHAR_EOF' > xpostme.c && X#ifndef lint Xstatic char *RCSid = "$Header: /tmp_mnt/net/sparky.a/davy/progs/xpostit/RCS/xpostit.c,v 1.2 90/06/14 11:21:24 davy Exp Changed PFS $"; X#endif X X/* X * xpostme.c - Post-It Notes for the X Window System, with a new user interface. X * X * Based on an X10R4 application. This one is for X11R4 and uses the X * Xt toolkit and the Athena widgets. X * X * David A. Curry X * SRI International X * 333 Ravenswood Avenue X * Menlo Park, CA 94025 X * davy@itstd.sri.com X * X * $Log: xpostit.c,v $ X * Revision 1.2 90/06/14 11:21:24 davy X * Ported to X11 Release 4. X * X * Revision 1.1 90/06/13 09:48:51 davy X * Initial revision X * X */ X#include <X11/StringDefs.h> X#include <X11/Intrinsic.h> X#include <X11/Shell.h> X#include <signal.h> X#include <stdio.h> X X#include "xpostme.h" X X/* X * Command line options and the resources they set. X */ Xstatic XrmOptionDescRec options[] = { X { "-bs", ".bufSize", XrmoptionSepArg, NULL }, X { "-dir", ".noteDir", XrmoptionSepArg, NULL }, X { "-sb", ".scrollBar", XrmoptionNoArg, "true" }, X { "-sv", ".saveNotes", XrmoptionNoArg, "true" }, X { "-hide", ".hidePlaid", XrmoptionNoArg, "true" }, X { "-show", ".hidePlaid", XrmoptionNoArg, "false" }, X}; X X/* X * Fallback resources. X */ Xstatic String fallback_resources[] = { X "*Command*font: -adobe-helvetica-bold-r-normal--*-120-*-*-*-*-*-*", X "*SimpleMenu*font: -adobe-helvetica-medium-r-normal--*-120-*-*-*-*-*-*", X "*Text*font: -b&h-lucidatypewriter-medium-r-normal-*-*-120-*-*-*-*-*-*", X "*Text*wrap: word", X "*Command*shapeStyle: oval", X X NULL X}; X X/* X * Resources we maintain besides those maintained by the toolkit. X */ Xstatic XtResource resources[] = { X#define offset(field) XtOffset(AppResPtr,field) X { "bufSize", "BufSize", XtRInt, sizeof(int), X offset(buf_size), XtRImmediate, (caddr_t) DefaultBufSize }, X { "noteDir", "NoteDir", XtRString, sizeof(String), X offset(note_dir), XtRString, DefaultNoteDir }, X { "saveNotes", "SaveNotes", XtRBoolean, sizeof(Boolean), X offset(save_notes), XtRImmediate, (caddr_t) False }, X { "scrollBar", "Scroll", XtRBoolean, sizeof(Boolean), X offset(scroll_bar), XtRImmediate, (caddr_t) False }, X { "hidePlaid", "HidePlaid", XtRBoolean, sizeof(Boolean), X offset(hide_plaid), XtRImmediate, (caddr_t) False }, X#undef offset X}; X XAppRes app_res; /* xpostme application resources */ XWidget toplevel; /* top level application shell widget */ XScreen *screen; /* pointer to the screen of the display */ XDisplay *display; /* pointer to the display we're on */ XXtAppContext appcontext; /* application context */ XPixel foreground; X Xvoid Xmain(argc, argv) Xchar **argv; Xint argc; X{ X Arg args[4]; X char *appname; X char *rindex(); X register int nargs; X Boolean setsigs = False; X Widget plaid; X X /* X * Ignore signals for now, but record whether they were X * already ignored or not so we can catch them later if X * need be. X */ X if ((signal(SIGQUIT, SIG_IGN) != SIG_IGN) && X (signal(SIGINT, SIG_IGN) != SIG_IGN)) X setsigs = True; X X /* X * Get application name. X */ X if ((appname = rindex(*argv, '/')) == NULL) X appname = *argv; X else X appname++; X X /* X * Initialize the toolkit and create an application shell. X */ X toplevel = XtAppInitialize(&appcontext, PostItNoteClass, options, X XtNumber(options), &argc, argv, fallback_resources, X NULL, 0); X X display = XtDisplay(toplevel); X screen = DefaultScreenOfDisplay(display); X X /* X * If we need to handle keyboard signals, do it now. X */ X if (setsigs) { X signal(SIGQUIT, ByeBye); X signal(SIGINT, ByeBye); X } X X /* X * Always handle these. X */ X signal(SIGTERM, ByeBye); X signal(SIGHUP, ByeBye); X X /* X * Send X errors to the exit routine. X */ X XSetErrorHandler((XErrorHandler) ByeBye); X X /* X * Now get any resources we're interested in. X */ X XtGetApplicationResources(toplevel, &app_res, resources, X XtNumber(resources), argv, argc); X X plaid = CreatePlaidWidget(); X CreateMenuWidget(); /* create main menu */ X X XtSetArg(args[0], XtNmappedWhenManaged, (XtArgVal) False); X XtSetValues(toplevel, args, (Cardinal) 1); X XtRealizeWidget(toplevel); X X XtSetArg(args[0], XtNforeground, (XtArgVal) &foreground); X XtGetValues(plaid, args, (Cardinal) 1); X X /* X * Construct the path to the directory notes are X * stored in. X */ X SetNoteDir(); X X /* X * Realize the top level and flush the server, which will X * let the user position the plaid window and map it. X */ X X XFlush(display); X X /* X * Load the notes the user has saved, and create widgets X * for them. X */ X LoadSavedNotes(); X X /* X * Never returns. X */ X XtAppMainLoop(appcontext); X} X X X SHAR_EOF $TOUCH -am 0620141490 xpostme.c && chmod 0600 xpostme.c || echo "restore of xpostme.c failed" set `wc -c xpostme.c`;Wc_c=$1 if test "$Wc_c" != "4588"; then echo original size 4588, current size $Wc_c fi # ============= xpostme.h ============== echo "x - extracting xpostme.h (Text)" sed 's/^X//' << 'SHAR_EOF' > xpostme.h && X/* X * $Header: /tmp_mnt/net/sparky.a/davy/progs/xpostit/RCS/xpostit.h,v 1.2 90/06/14 11:21:33 davy Exp Changed PFS $ X * X * xpostme.h - declarations for xpostit. X * X * David A. Curry X * SRI International X * 333 Ravenswood Avenue X * Menlo Park, CA 94025 X * davy@itstd.sri.com X * X * $Log: xpostit.h,v $ X * Revision 1.2 90/06/14 11:21:33 davy X * Ported to X11 Release 4. X * X * Revision 1.1 90/06/13 09:48:52 davy X * Initial revision X * X */ X X/* X * Default values. X */ X#define DefaultBufSize 2048 X#define DefaultNoteDir ".postitnotes" X#define DefaultPlaidWidth 113 X#define DefaultPlaidHeight 17 X X/* X * Post-It Note sizes. X */ X#define PostItNote_1p5x1 0 X#define PostItNote_1p5x2 1 X#define PostItNote_2x3 2 X#define PostItNote_3x3 3 X#define PostItNote_3x4 4 X#define PostItNote_3x5 5 X#define PostItNote_4x6 6 X X/* X * Post-It Note file information. X */ X#define PostItNoteMagic "%!<postitnote>" X#define PostItNoteFname "note" X X/* X * Application class. X */ X#define PostItNoteClass "Xpostit" X X/* X * Request for a new note index number. X */ X#define NewIndex -1 X X/* X * Just in case. X */ X#ifndef MAXPATHLEN X#define MAXPATHLEN 1024 X#endif X X/* X * Useful macros. X */ X#define SetArg(which, val) XtSetArg(args[nargs], (which),\ X (XtArgVal) (val)); nargs++ X#define SetCallback(which, val) callbacks[0].callback = (which); \ X callbacks[0].closure = (caddr_t) (val) X X/* X * The Post-It Note record. One of these is allocated X * for each note created. X */ Xtypedef struct _PostItNote { X Widget pn_shellwidget; /* shell widget holding it all */ X Widget pn_textwidget; /* text widget of the note */ X Widget pn_menuentry; /* associated menu entry if hidden */ X X char *pn_file; /* file note will be saved in */ X char *pn_text; /* buffer holding text of note */ X X int pn_index; /* index number of note */ X int pn_shellx; /* x coord of shell widget */ X int pn_shelly; /* y coord of shell widget */ X int pn_textsize; /* size of pn_text in chars */ X int pn_textwidth; /* width of text widget window */ X int pn_textheight; /* height of text widget window */ X X Boolean pn_positionit; /* true if shellx/shelly valid */ X Boolean pn_unmapped; X X struct _PostItNote *pn_next; /* pointer to next note record */ X} PostItNote; X X/* X * The resource record, for holding resources specific to xpostme. X */ Xtypedef struct { X int buf_size; /* size of pn_text to be used */ X String note_dir; /* path to note directory */ X Boolean scroll_ovf; /* set scroll on overflow */ X Boolean scroll_bar; /* turn on scroll bars */ X Boolean save_notes; /* save notes on exit */ X Boolean hide_plaid; /* hide plaid when notes are active ? */ X} AppRes, *AppResPtr; X X/* X * External variable declarations. X */ Xextern AppRes app_res; X Xextern Screen *screen; Xextern Display *display; X Xextern Widget toplevel; Xextern Widget listwidget; Xextern Widget menuwidget; Xextern Widget plaidwidget; X Xextern Pixel foreground; X X/* X * Function declarations. X */ Xchar *SafeAlloc(); X Xvoid ByeBye(); Xvoid ConfirmIt(); Xvoid ClearConfirm(); Xvoid SaveAllNotes(); Xvoid RaiseAllNotes(); Xvoid LowerAllNotes(); Xvoid CreateNewNote(); Xvoid CreateMenuWidget(); XWidget CreatePlaidWidget(); X X#define MAIN_MENU "Menu" X#define PRIVATE_MENU "privateMenu" X#define HIDDEN_MENU "hiddenNotes" SHAR_EOF $TOUCH -am 0620135490 xpostme.h && chmod 0600 xpostme.h || echo "restore of xpostme.h failed" set `wc -c xpostme.h`;Wc_c=$1 if test "$Wc_c" != "3231"; then echo original size 3231, current size $Wc_c fi exit 0 dan ---------------------------------------------------- O'Reilly && Associates argv@sun.com / argv@ora.com Opinions expressed reflect those of the author only.