Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!newstop!sun!uwasa.fi From: fs@uwasa.fi (Filip Sawicki LAKE) Newsgroups: comp.sources.x Subject: v08i003: xpostme (xpostit-2), Part01/01 Message-ID: <137917@sun.Eng.Sun.COM> Date: 27 Jun 90 06:36:59 GMT Sender: news@sun.Eng.Sun.COM Lines: 2357 Approved: argv@sun.com Submitted-by: Filip Sawicki LAKE 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 ] 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 X X#include X#include 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 ": raise() \n\ X : lower() \n\ X : 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 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 X X#ifndef _PlaidP_h X#define _PlaidP_h X X#include 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 X#include X#include X#include X/* #include */ X#include X#include X#include 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 X#include X#include X#include X#include X#include X#include 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