home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume8 / xpostme / part01 next >
Internet Message Format  |  1990-06-26  |  57KB

  1. Path: uunet!snorkelwacker!tut.cis.ohio-state.edu!cs.utexas.edu!sun-barr!newstop!sun!uwasa.fi
  2. From: fs@uwasa.fi (Filip Sawicki LAKE)
  3. Newsgroups: comp.sources.x
  4. Subject: v08i003: xpostme (xpostit-2), Part01/01
  5. Message-ID: <137917@sun.Eng.Sun.COM>
  6. Date: 27 Jun 90 06:36:59 GMT
  7. Sender: news@sun.Eng.Sun.COM
  8. Lines: 2357
  9. Approved: argv@sun.com
  10.  
  11. Submitted-by: Filip Sawicki LAKE <fs@uwasa.fi>
  12. Posting-number: Volume 8, Issue 3
  13. Archive-name: xpostme/part01
  14.  
  15. [ Moderator's note:
  16.     this posting contains stuff from xpostit written by Dave Curry.
  17.     He doesn't advocate this program, but he has OK'ed it to be
  18.     posted.  Future patches to xpostit or xpostme do not affect
  19.     one another.  --dan
  20. ]
  21.  
  22. [from README by Filip Sawicki LAKE <fs@uwasa.fi> ]
  23.  
  24.   I wasn't very pleased with the "xpostit" space-waisting design, but
  25. I love this program; so here is my own version of it. The program is
  26. called "xpostme", to avoid any confusion, but is based on the original
  27. code, and thus reads/saves notes in the same format.  Application
  28. class is also "Xpostit", for the resources inheritance.
  29.  
  30.   Major changes:
  31.  
  32. 1. Separate notes, as well as the toplevel "Plaid" box can be hidden
  33. (unmapped) and recovered at once or individually.
  34.  
  35. 2. Notes' command buttons are gone, as awfully space-consuming stuff.
  36.  
  37. 3. Classes of all popup objects are changed, to conform to accepted
  38. standards (e.g. TransientShell instead of OverrideShell).
  39.  
  40. /* a note for a group moderator: please send me info if you're going
  41. to post it -- in this case I'll write a note to "comp.windows.x" */
  42.  
  43. #!/bin/sh
  44. # This is a shell archive (shar 3.24)
  45. # made 06/20/1990 16:19 UTC by fs@chyde
  46. # Source directory /home2/cc/fs/xpostit
  47. #
  48. # existing files WILL be overwritten
  49. #
  50. # This shar contains:
  51. # length  mode       name
  52. # ------ ---------- ------------------------------------------
  53. #   2368 -rw------- README
  54. #    551 -rw------- Imakefile
  55. #   5763 -rw------- Plaid.c
  56. #   1689 -rw------- Plaid.h
  57. #   1262 -rw------- PlaidP.h
  58. #   2982 -rw------- confirm.c
  59. #   3538 -rw------- menu.c
  60. #  18798 -rw------- note.c
  61. #   1819 -rw------- plaid.c
  62. #   2041 -rw------- util.c
  63. #   4588 -rw------- xpostme.c
  64. #   3231 -rw------- xpostme.h
  65. #
  66. if touch 2>&1 | fgrep '[-amc]' > /dev/null
  67.  then TOUCH=touch
  68.  else TOUCH=true
  69. fi
  70. # ============= README ==============
  71. echo "x - extracting README (Text)"
  72. sed 's/^X//' << 'SHAR_EOF' > README &&
  73. XWHY?
  74. X
  75. X  I wasn't very pleased with the "xpostit" space-waisting design, but
  76. XI love this program; so here is my own version of it. The program is
  77. Xcalled "xpostme", to avoid any confusion, but is based on the original
  78. Xcode, and thus reads/saves notes in the same format.  Application
  79. Xclass is also "Xpostit", for the resources inheritance.
  80. X
  81. X  Major changes:
  82. X
  83. X1. Separate notes, as well as the toplevel "Plaid" box, can be hidden
  84. X(unmapped) and recovered at once or individually.
  85. X
  86. X2. Notes' command buttons are gone, as awfully space-consuming stuff.
  87. X
  88. X3. Classes of all popup objects are changed, to conform to accepted
  89. Xstandards (e.g. TransientShell instead of OverrideShell).
  90. X
  91. XUSAGE
  92. X
  93. X1. In the top bar of the note press:
  94. X
  95. X    BTN-1 - to open menu with actions previously in command buttons.
  96. X    BTN-2 - to open menu showing hidden notes.
  97. X    BTN-3 - to open main menu (as in "Plaid" box).
  98. X
  99. X2. Two new command line parameters:
  100. X
  101. X    -hide - hide "Plaid" box whenever possible (default: don't).
  102. X    -show - show it allways (don't hide).
  103. X
  104. X3. New top-level resource (see also above):
  105. X
  106. X    Name        Class        Type        Default Value
  107. X    hidePlaid    HidePlaid    Boolean        "false"
  108. X
  109. XRESOURCES
  110. X
  111. X  Here's the complete program structure tree for resources lovers:
  112. X
  113. X    "Xpostit" (ApplicationShell)
  114. X        "Plaid" (Plaid)
  115. X
  116. X    [Popup Children: menus]
  117. X        "Menu" (SimpleMenu)
  118. X            "Xpostit" (smeBSB) [menu label]
  119. X            ".x. Note" (smeBSB) [different note sizes]
  120. X            ...
  121. X            "Line1" (smeLine)
  122. X            "Raise Notes", "Lower Notes", "Save Notes" (smeBSB)
  123. X            "Line2" (smeLine)
  124. X            "Exit" (smeBSB)
  125. X        "hiddenNotes" (SimpleMenu)
  126. X            "Hidden Notes" (smeBSB) [menu label]
  127. X            "Note at +%d+%d" (smeBSB) [variable number]
  128. X
  129. X    [Popup Box]
  130. X    "Confirm" (TransientShell) [confirmation box]
  131. X        "Dialog" (Dialog)
  132. X        "Confirm", "Cancel" (CommandButton)
  133. X
  134. X    [Popup Children: Notes]
  135. X        "Note" (TopLevelShell)
  136. X            "Form" (Form)
  137. X                "topBar" (Simple) [with added translations]
  138. X                "noteText" (AsciiText)
  139. X                    [some children of AsciiText]
  140. X        [Note's Popup Child: menu]
  141. X            "privateMenu" (SimpleMenu)
  142. X                "Note Actions" (smeBSB) [menu label]
  143. X                "Save Text", "Erase Text" (smeBSB)
  144. X                "Hide This Note" (smeBSB)
  145. X                "Line" (smeLine)
  146. X                "Remove This Note" (smeBSB)
  147. X
  148. XAUTHOR
  149. X
  150. X  With any complains/suggestions e-mail to "fs@uwasa.fi". As for I/O
  151. Xtroubles, I'm in touch with the original "xpostit" author, so there
  152. Xshould be no problems.
  153. X
  154. Xfi.
  155. X(Piotr Filip Sawicki, IIUW, Warsaw, Poland)
  156. SHAR_EOF
  157. $TOUCH -am 0620191890 README &&
  158. chmod 0600 README ||
  159. echo "restore of README failed"
  160. set `wc -c README`;Wc_c=$1
  161. if test "$Wc_c" != "2368"; then
  162.     echo original size 2368, current size $Wc_c
  163. fi
  164. # ============= Imakefile ==============
  165. echo "x - extracting Imakefile (Text)"
  166. sed 's/^X//' << 'SHAR_EOF' > Imakefile &&
  167. X#
  168. X# Imakefile for xpostme.
  169. X#
  170. X# original xpostit by:
  171. X#
  172. X# David A. Curry
  173. X# SRI International
  174. X# 333 Ravenswood Avenue
  175. X# Menlo Park, CA 94025
  176. X# davy@itstd.sri.com
  177. X#
  178. X# $Log:    Imakefile,v $
  179. X# Revision 1.2  90/06/14  11:16:50  davy
  180. X# Ported to X11 Release 4.  Added app-defaults file.
  181. X# 
  182. X#
  183. XLOCAL_LIBRARIES = $(XAWLIB) $(XMULIB) $(XTOOLLIB) $(XLIB)
  184. X           SRCS = Plaid.c confirm.c menu.c note.c plaid.c util.c xpostme.c
  185. X           OBJS = Plaid.o confirm.o menu.o note.o plaid.o util.o xpostme.o
  186. X
  187. XComplexProgramTarget(xpostme)
  188. X
  189. XInstallAppDefaults(Xpostit)
  190. X
  191. SHAR_EOF
  192. $TOUCH -am 0620135290 Imakefile &&
  193. chmod 0600 Imakefile ||
  194. echo "restore of Imakefile failed"
  195. set `wc -c Imakefile`;Wc_c=$1
  196. if test "$Wc_c" != "551"; then
  197.     echo original size 551, current size $Wc_c
  198. fi
  199. # ============= Plaid.c ==============
  200. echo "x - extracting Plaid.c (Text)"
  201. sed 's/^X//' << 'SHAR_EOF' > Plaid.c &&
  202. X#ifndef lint
  203. 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 $";
  204. X#endif
  205. X
  206. X/*
  207. X * Plaid.c - code for the plaid widget.
  208. X *
  209. X * Based on the Template widget from the X11R4 distribution.
  210. X *
  211. X * David A. Curry
  212. X * SRI International
  213. X * 333 Ravenswood Avenue
  214. X * Menlo Park, CA 94025
  215. X * davy@itstd.sri.com
  216. X *
  217. X * $Log:    Plaid.c,v $
  218. X * Revision 1.2  90/06/14  11:17:42  davy
  219. X * Ported to X11 Release 4.  Added translations to invoke all actions from
  220. X * the plaid widget, instead of passing the event back to a single callback.
  221. X * 
  222. X * Revision 1.1  90/06/13  09:48:39  davy
  223. X * Initial revision
  224. X * 
  225. X */
  226. X#include <X11/copyright.h>
  227. X
  228. X#include <X11/IntrinsicP.h>
  229. X#include <X11/StringDefs.h>
  230. X#include "PlaidP.h"
  231. X
  232. X#define plaid_width    22
  233. X#define plaid_height    22
  234. X
  235. X/*
  236. X * The bits representing the plaid background.
  237. X */
  238. Xstatic char plaid_bits[] = {
  239. X    0x75, 0xfd, 0x3f, 0xaa, 0xfa, 0x3e, 0x75, 0xfd, 0x3f, 0xaa, 0xfa, 0x3e,
  240. X    0x75, 0xfd, 0x3f, 0xff, 0x57, 0x15, 0x75, 0xfd, 0x3f, 0xaa, 0xfa, 0x3e,
  241. X    0x75, 0xfd, 0x3f, 0xaa, 0xfa, 0x3e, 0x75, 0xfd, 0x3f, 0x20, 0xa8, 0x2b,
  242. X    0x20, 0x50, 0x15, 0x20, 0xa8, 0x2b, 0x20, 0x50, 0x15, 0x20, 0xa8, 0x2b,
  243. X    0xff, 0xff, 0x3f, 0x20, 0xa8, 0x2b, 0x20, 0x50, 0x15, 0x20, 0xa8, 0x2b,
  244. X    0x20, 0x50, 0x15, 0x20, 0xa8, 0x2b
  245. X};
  246. X
  247. X/*
  248. X * The resources specific to the plaid widget.
  249. X */
  250. Xstatic XtResource resources[] = {
  251. X#define offset(field)    XtOffset(PlaidWidget,plaid.field)
  252. X    { XtNlowerCallback, XtCCallback, XtRCallback, sizeof(XtCallbackList),
  253. X        offset(lower_callback), XtRCallback, NULL },
  254. X    { XtNraiseCallback, XtCCallback, XtRCallback, sizeof(XtCallbackList),
  255. X        offset(raise_callback), XtRCallback, NULL },
  256. X    { XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
  257. X        offset(foreground), XtRString, "XtDefaultForeground" }
  258. X#undef offset
  259. X};
  260. X
  261. X/*****************************************************************************
  262. X * Plaid Widget Routines
  263. X *****************************************************************************/
  264. X
  265. X/*
  266. X * RaiseAction - called when raise button is pressed.
  267. X */
  268. Xstatic void
  269. XRaiseAction(w, event, params, num_params)
  270. XCardinal *num_params;    /* unused */
  271. XString *params;        /* unused */
  272. XXEvent *event;
  273. XWidget w;
  274. X{
  275. X    /*
  276. X     * Just pass it off to the user's callback function.
  277. X     */
  278. X    XtCallCallbacks(w, XtNraiseCallback, (caddr_t) event);
  279. X}
  280. X
  281. X/*
  282. X * LowerAction - called when lower button is pressed.
  283. X */
  284. Xstatic void
  285. XLowerAction(w, event, params, num_params)
  286. XCardinal *num_params;    /* unused */
  287. XString *params;        /* unused */
  288. XXEvent *event;
  289. XWidget w;
  290. X{
  291. X    /*
  292. X     * Just pass it off to the user's callback function.
  293. X     */
  294. X    XtCallCallbacks(w, XtNlowerCallback, (caddr_t) event);
  295. X}
  296. X
  297. X/*
  298. X * RealizePlaid - realize the window by creating it, and by creating the
  299. X *          plaid background pixmap.
  300. X */
  301. Xstatic void
  302. XRealizePlaid(w, value_mask, attributes)
  303. XXSetWindowAttributes *attributes;
  304. XMask *value_mask;
  305. XWidget w;
  306. X{
  307. X    Pixmap p;
  308. X    Window window;
  309. X    Display *display;
  310. X    PlaidWidget plaidw;
  311. X
  312. X    plaidw = (PlaidWidget) w;
  313. X
  314. X    /*
  315. X     * Create the window.
  316. X     */
  317. X    XtCreateWindow(w, (unsigned int) InputOutput,
  318. X               (Visual *) CopyFromParent, *value_mask, attributes);
  319. X
  320. X    display = XtDisplay(w);
  321. X    window = XtWindow(w);
  322. X
  323. X    /*
  324. X     * Create the plaid pixmap.
  325. X     */
  326. X    p = XCreatePixmapFromBitmapData(display, window, plaid_bits,
  327. X                    plaid_width, plaid_height,
  328. X                    plaidw->plaid.foreground,
  329. X                    w->core.background_pixel,
  330. X                    w->core.depth);
  331. X
  332. X    /*
  333. X     * Tile the window.
  334. X     */
  335. X    XSetWindowBackgroundPixmap(display, window, p);
  336. X
  337. X    /*
  338. X     * Now save the pixmap in the core widget.
  339. X     */
  340. X    w->core.background_pixmap = p;
  341. X}
  342. X
  343. X/*
  344. X * DestroyPlaid - free up server resources when widget is destroyed.
  345. X */
  346. Xstatic void
  347. XDestroyPlaid(w)
  348. XWidget w;
  349. X{
  350. X    /*
  351. X     * All we need to do is get rid of the pixmap we created.
  352. X     */
  353. X    XFreePixmap(XtDisplay(w), w->core.background_pixmap);
  354. X}
  355. X
  356. X/*****************************************************************************
  357. X * Plaid Widget definitions
  358. X *****************************************************************************/
  359. X
  360. X/*
  361. X * Action table.  We're only interested in button presses.
  362. X */
  363. Xstatic XtActionsRec actions[] =
  364. X{
  365. X    { "raise",    RaiseAction },
  366. X    { "lower",    LowerAction }
  367. X};
  368. X
  369. X/*
  370. X * Translation table.  We're only interested in button presses.
  371. X */
  372. Xstatic char translations[] =
  373. X    "<Btn1Down>:    raise()    \n\
  374. X    <Btn2Down>:    lower()    \n\
  375. X    <Btn3Down>:    XawPositionSimpleMenu(Menu) MenuPopup(Menu) \n\
  376. X";
  377. X
  378. X/*
  379. X * The plaid widget class record.   Initialization of values.
  380. X */
  381. XPlaidClassRec plaidClassRec = {
  382. X  { /* core fields */
  383. X    /* superclass        */    (WidgetClass) &widgetClassRec,
  384. X    /* class_name        */    "Plaid",
  385. X    /* widget_size        */    sizeof(PlaidRec),
  386. X    /* class_initialize        */    NULL,
  387. X    /* class_part_initialize    */    NULL,
  388. X    /* class_inited        */    FALSE,
  389. X    /* initialize        */    NULL,
  390. X    /* initialize_hook        */    NULL,
  391. X    /* realize            */    RealizePlaid,
  392. X    /* actions            */    actions,
  393. X    /* num_actions        */    XtNumber(actions),
  394. X    /* resources        */    resources,
  395. X    /* num_resources        */    XtNumber(resources),
  396. X    /* xrm_class        */    NULLQUARK,
  397. X    /* compress_motion        */    TRUE,
  398. X    /* compress_exposure    */    TRUE,
  399. X    /* compress_enterleave    */    TRUE,
  400. X    /* visible_interest        */    FALSE,
  401. X    /* destroy            */    DestroyPlaid,
  402. X    /* resize            */    NULL,
  403. X    /* expose            */    NULL,
  404. X    /* set_values        */    NULL,
  405. X    /* set_values_hook        */    NULL,
  406. X    /* set_values_almost    */    XtInheritSetValuesAlmost,
  407. X    /* get_values_hook        */    NULL,
  408. X    /* accept_focus        */    NULL,
  409. X    /* version            */    XtVersion,
  410. X    /* callback_private        */    NULL,
  411. X    /* tm_table            */    translations,
  412. X    /* query_geometry        */    XtInheritQueryGeometry,
  413. X    /* display_accelerator    */    XtInheritDisplayAccelerator,
  414. X    /* extension        */    NULL
  415. X  },
  416. X  { /* plaid fields */
  417. X    /* empty            */    0
  418. X  }
  419. X};
  420. X
  421. X/*
  422. X * The class declaration.
  423. X */
  424. XWidgetClass plaidWidgetClass = (WidgetClass)&plaidClassRec;
  425. SHAR_EOF
  426. $TOUCH -am 0620123790 Plaid.c &&
  427. chmod 0600 Plaid.c ||
  428. echo "restore of Plaid.c failed"
  429. set `wc -c Plaid.c`;Wc_c=$1
  430. if test "$Wc_c" != "5763"; then
  431.     echo original size 5763, current size $Wc_c
  432. fi
  433. # ============= Plaid.h ==============
  434. echo "x - extracting Plaid.h (Text)"
  435. sed 's/^X//' << 'SHAR_EOF' > Plaid.h &&
  436. X/*
  437. X * $Header: /tmp_mnt/net/sparky.a/davy/progs/xpostit/RCS/Plaid.h,v 1.2 90/06/14 11:18:27 davy Exp $
  438. X *
  439. X * Plaid.h - public definitions for the plaid widget.
  440. X *
  441. X * Based on the Template widget from the X11R4 distribution.
  442. X *
  443. X * David A. Curry
  444. X * SRI International
  445. X * 333 Ravenswood Avenue
  446. X * Menlo Park, CA 94025
  447. X * davy@itstd.sri.com
  448. X *
  449. X * $Log:    Plaid.h,v $
  450. X * Revision 1.2  90/06/14  11:18:27  davy
  451. X * Ported to X11 Release 4.
  452. X * 
  453. X * Revision 1.1  90/06/13  09:48:42  davy
  454. X * Initial revision
  455. X * 
  456. X */
  457. X#include <X11/copyright.h>
  458. X
  459. X#ifndef _Plaid_h
  460. X#define _Plaid_h
  461. X
  462. X/*
  463. X * Resources:
  464. X *
  465. X * Name             Class        RepType        Default Value
  466. X * ----             -----        -------        -------------
  467. X * background         Background        Pixel        XtDefaultBackground
  468. X * border         BorderColor    Pixel        XtDefaultForeground
  469. X * borderWidth         BorderWidth    Dimension    1
  470. X * callback         Callback        Callback    NULL
  471. X * destroyCallback   Callback        Pointer        NULL
  472. X * foreground         Foreground        Pixel        XtDefaultForeground
  473. X * height         Height        Dimension    0
  474. X * lowerCallback     Callback        Pointer        NULL
  475. X * raiseCallback     Callback        Pointer        NULL
  476. X * mappedWhenManaged MappedWhenManaged    Boolean        True
  477. X * sensitive         Sensitive        Boolean        True
  478. X * width         Width        Dimension    0
  479. X * x             Position        Position    0
  480. X * y             Position        Position    0
  481. X */
  482. X
  483. X/*
  484. X * Declare specific PlaidWidget class and instance datatypes.
  485. X */
  486. Xtypedef struct _PlaidClassRec*        PlaidWidgetClass;
  487. Xtypedef struct _PlaidRec*        PlaidWidget;
  488. X
  489. X/*
  490. X * Declare the class constant.
  491. X */
  492. Xextern WidgetClass            plaidWidgetClass;
  493. X
  494. X/*
  495. X * Declare a couple of new resources.
  496. X */
  497. X#define XtNlowerCallback        "lowerCallback"
  498. X#define XtNraiseCallback        "raiseCallback"
  499. X
  500. X#endif /* _Plaid_h */
  501. SHAR_EOF
  502. $TOUCH -am 0620123790 Plaid.h &&
  503. chmod 0600 Plaid.h ||
  504. echo "restore of Plaid.h failed"
  505. set `wc -c Plaid.h`;Wc_c=$1
  506. if test "$Wc_c" != "1689"; then
  507.     echo original size 1689, current size $Wc_c
  508. fi
  509. # ============= PlaidP.h ==============
  510. echo "x - extracting PlaidP.h (Text)"
  511. sed 's/^X//' << 'SHAR_EOF' > PlaidP.h &&
  512. X/*
  513. X * $Header: /tmp_mnt/net/sparky.a/davy/progs/xpostit/RCS/PlaidP.h,v 1.2 90/06/14 11:18:37 davy Exp $
  514. X *
  515. X * PlaidP.h - private definitions for the plaid widget.
  516. X *
  517. X * Based on the Template widget from the X11R4 distribution.
  518. X *
  519. X * David A. Curry
  520. X * SRI International
  521. X * 333 Ravenswood Avenue
  522. X * Menlo Park, CA 94025
  523. X * davy@itstd.sri.com
  524. X *
  525. X * $Log:    PlaidP.h,v $
  526. X * Revision 1.2  90/06/14  11:18:37  davy
  527. X * Ported to X11 Release 4.
  528. X * 
  529. X * Revision 1.1  90/06/13  09:48:45  davy
  530. X * Initial revision
  531. X * 
  532. X */
  533. X#include <X11/copyright.h>
  534. X
  535. X#ifndef _PlaidP_h
  536. X#define _PlaidP_h
  537. X
  538. X#include <X11/CoreP.h>
  539. X#include "Plaid.h"
  540. X
  541. X/*
  542. X * The plaid part of the class record is not used.
  543. X */
  544. Xtypedef struct {
  545. X    int        empty;
  546. X} PlaidClassPart;
  547. X
  548. X/*
  549. X * Declare the class record for the widget.
  550. X */
  551. Xtypedef struct _PlaidClassRec {
  552. X    CoreClassPart    core_class;
  553. X    PlaidClassPart    plaid_class;
  554. X} PlaidClassRec;
  555. X
  556. X/*
  557. X * Declare the plaid class record type.
  558. X */
  559. Xextern PlaidClassRec    plaidClassRec;
  560. X
  561. X/*
  562. X * Resources specific to the plaid widget.
  563. X */
  564. Xtypedef struct {
  565. X    Pixel        foreground;
  566. X    XtCallbackList    lower_callback;
  567. X    XtCallbackList    raise_callback;
  568. X} PlaidPart;
  569. X
  570. X/*
  571. X * Declare the widget type.
  572. X */
  573. Xtypedef struct _PlaidRec {
  574. X    CorePart    core;
  575. X    PlaidPart    plaid;
  576. X} PlaidRec;
  577. X
  578. X#endif /* _PlaidP_h */
  579. SHAR_EOF
  580. $TOUCH -am 0620123790 PlaidP.h &&
  581. chmod 0600 PlaidP.h ||
  582. echo "restore of PlaidP.h failed"
  583. set `wc -c PlaidP.h`;Wc_c=$1
  584. if test "$Wc_c" != "1262"; then
  585.     echo original size 1262, current size $Wc_c
  586. fi
  587. # ============= confirm.c ==============
  588. echo "x - extracting confirm.c (Text)"
  589. sed 's/^X//' << 'SHAR_EOF' > confirm.c &&
  590. X#ifndef lint
  591. 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 $";
  592. X#endif
  593. X
  594. X/*
  595. X * confirm.c - handle confirming requests made by the user.
  596. X *
  597. X * David A. Curry
  598. X * SRI International
  599. X * 333 Ravenswood Avenue
  600. X * Menlo Park, CA 94025
  601. X * davy@itstd.sri.com
  602. X *
  603. X * $Log:    confirm.c,v $
  604. X * Revision 1.2  90/06/14  11:18:52  davy
  605. X * Ported to X11 Release 4.
  606. X * 
  607. X * Revision 1.1  90/06/13  09:47:27  davy
  608. X * Initial revision
  609. X * 
  610. X */
  611. X#include <X11/StringDefs.h>
  612. X#include <X11/Intrinsic.h>
  613. X#include <X11/Xaw/Command.h>
  614. X#include <X11/Xaw/Form.h>
  615. X/* #include <X11/Xaw/Label.h> */
  616. X#include <X11/Shell.h>
  617. X#include <X11/Xaw/Dialog.h>
  618. X#include <stdio.h>
  619. X
  620. X#include "xpostme.h"
  621. X
  622. Xstatic Widget    confirmwidget;
  623. X
  624. X/*
  625. X * ConfirmIt - put up a window asking for confirmation.
  626. X */
  627. Xvoid
  628. XConfirmIt(text, confirm_callbacks, cancel_callbacks)
  629. XXtCallbackRec *confirm_callbacks, *cancel_callbacks;
  630. XString text;
  631. X{
  632. X    Arg args[4];
  633. X    Window root, child;
  634. X    unsigned int buttons;
  635. X    register int nargs, nwidgets;
  636. X    static Boolean inited = False;
  637. X    static Widget form, widgets[3];
  638. X    int root_x, root_y, child_x, child_y;
  639. X
  640. X    /*
  641. X     * Find out where the mouse is, so we can put the confirmation
  642. X     * box right there.
  643. X     */
  644. X    XQueryPointer(display, XtWindow(toplevel), &root, &child,
  645. X              &root_x, &root_y, &child_x, &child_y, &buttons);
  646. X
  647. X    /*
  648. X     * If we need to construct the confirmation box do that,
  649. X     * otherwise just reset the position and callbacks and
  650. X     * put it up again.
  651. X     */
  652. X    if (!inited) {
  653. X        nargs = 0;
  654. X        SetArg(XtNx, root_x);
  655. X        SetArg(XtNy, root_y);
  656. X
  657. X        /*
  658. X         * The confirmation box will be a pop-up widget.
  659. X         */
  660. X        confirmwidget = XtCreatePopupShell("Confirm",
  661. X                           transientShellWidgetClass,
  662. X                           toplevel, args, nargs);
  663. X
  664. X        /*
  665. X         * Make a form to put the buttons in.
  666. X         */
  667. X        
  668. X        nargs = 0;
  669. X        SetArg(XtNlabel, text);
  670. X        widgets[0] = form = XtCreateManagedWidget("Dialog", dialogWidgetClass, confirmwidget,
  671. X                                     args, nargs);
  672. X
  673. X        nargs = 0;
  674. X        SetArg(XtNcallback, confirm_callbacks);
  675. X        widgets[1] = XtCreateManagedWidget("Confirm", commandWidgetClass, form, args, nargs);
  676. X
  677. X        nargs = 0;
  678. X        SetArg(XtNcallback, cancel_callbacks);
  679. X        widgets[2] = XtCreateManagedWidget("Cancel", commandWidgetClass, form, args, nargs);
  680. X
  681. X        XtRealizeWidget(confirmwidget);
  682. X        inited = True;
  683. X    }
  684. X    else {
  685. X        /*
  686. X         * Reset the confirmation box position.
  687. X         */
  688. X        nargs = 0;
  689. X        SetArg(XtNx, root_x);
  690. X        SetArg(XtNy, root_y);
  691. X        XtSetValues(confirmwidget, args, nargs);
  692. X
  693. X        nargs = 0;
  694. X        SetArg(XtNlabel, text);
  695. X        XtSetValues(widgets[0], args, nargs);
  696. X        /*
  697. X         * Reset the callbacks.
  698. X         */
  699. X        nargs = 0;
  700. X        SetArg(XtNcallback, confirm_callbacks);
  701. X        XtSetValues(widgets[1], args, nargs);
  702. X
  703. X        nargs = 0;
  704. X        SetArg(XtNcallback, cancel_callbacks);
  705. X        XtSetValues(widgets[2], args, nargs);
  706. X    }
  707. X
  708. X    /*
  709. X     * Pop up the confirmation box.
  710. X     */
  711. X    XtPopup(confirmwidget, XtGrabExclusive);
  712. X}
  713. X
  714. X/*
  715. X * ClearConfirm - get rid of the confirmation box.
  716. X */
  717. Xvoid
  718. XClearConfirm()
  719. X{
  720. X    XtPopdown(confirmwidget);
  721. X}
  722. SHAR_EOF
  723. $TOUCH -am 0620135490 confirm.c &&
  724. chmod 0600 confirm.c ||
  725. echo "restore of confirm.c failed"
  726. set `wc -c confirm.c`;Wc_c=$1
  727. if test "$Wc_c" != "2982"; then
  728.     echo original size 2982, current size $Wc_c
  729. fi
  730. # ============= menu.c ==============
  731. echo "x - extracting menu.c (Text)"
  732. sed 's/^X//' << 'SHAR_EOF' > menu.c &&
  733. X#ifndef lint
  734. 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 $";
  735. X#endif
  736. X
  737. X/*
  738. X * menu.c - routines to handle the menu.
  739. X *
  740. X * David A. Curry
  741. X * SRI International
  742. X * 333 Ravenswood Avenue
  743. X * Menlo Park, CA 94025
  744. X * davy@itstd.sri.com
  745. X *
  746. X * $Log:    menu.c,v $
  747. X * Revision 1.2  90/06/14  11:19:39  davy
  748. X * Ported to X11 Release 4.  Changed to use the SimpleMenu widget instead
  749. X * of a List widget for the menu.
  750. X * 
  751. X * Revision 1.1  90/06/13  09:48:47  davy
  752. X * Initial revision
  753. X * 
  754. X */
  755. X#include <X11/StringDefs.h>
  756. X#include <X11/Intrinsic.h>
  757. X#include <X11/Xaw/SimpleMenu.h>
  758. X#include <X11/Xaw/SmeLine.h>
  759. X#include <X11/Xaw/SmeBSB.h>
  760. X#include <X11/Shell.h>
  761. X#include <stdio.h>
  762. X
  763. X#include "xpostme.h"
  764. X
  765. Xstatic String menu_1a_[] = {
  766. X#define MenuCreate_1p5x1    0
  767. X    "1.5x1 Note",
  768. X#define MenuCreate_1p5x2    1
  769. X    "1.5x2 Note",
  770. X#define MenuCreate_2x3        2
  771. X    "2x3 Note",
  772. X#define MenuCreate_3x3        3
  773. X    "3x3 Note",
  774. X#define MenuCreate_3x4        4
  775. X    "3x4 Note",
  776. X#define MenuCreate_3x5        5
  777. X    "3x5 Note",
  778. X#define MenuCreate_4x6        6
  779. X    "4x6 Note"
  780. X};
  781. X
  782. Xstatic struct {
  783. X    char *text;
  784. X    void (*callback)();
  785. X} menu_1b_[] = {
  786. X    { "Line1", NULL },
  787. X    { "Raise Notes", RaiseAllNotes },
  788. X    { "Lower Notes", LowerAllNotes },
  789. X    { "Save Notes", SaveAllNotes },
  790. X    { "Line2", NULL },
  791. X    { "Exit", ByeBye }
  792. X};
  793. X
  794. XWidget            menuwidget;
  795. Xextern XtAppContext    appcontext;
  796. Xstatic void        HandleMenuSelection();
  797. X
  798. X/*
  799. X * CreateMenuWidget - create the widget used for the menus.
  800. X */
  801. Xvoid
  802. XCreateMenuWidget()
  803. X{
  804. X    Arg args[8];
  805. X    Widget entry;
  806. X    register int i, nargs;
  807. X    XtCallbackRec callbacks[2];
  808. X
  809. X    nargs = 0;
  810. X    SetArg(XtNmenuOnScreen, True);
  811. X    SetArg(XtNlabel, PostItNoteClass);
  812. X
  813. X    menuwidget = XtCreatePopupShell(MAIN_MENU, simpleMenuWidgetClass,
  814. X                                    toplevel, args, nargs);
  815. X
  816. X    nargs = 0;
  817. X    SetArg(XtNcallback, callbacks);
  818. X    callbacks[0].callback = HandleMenuSelection;
  819. X    callbacks[1].callback = NULL;
  820. X    callbacks[1].closure = NULL;
  821. X    
  822. X    for (i=0; i<sizeof(menu_1a_)/sizeof(menu_1a_[0]); i++) {
  823. X        callbacks[0].closure = (caddr_t) i;
  824. X        (void) XtCreateManagedWidget(menu_1a_[i],
  825. X                                     smeBSBObjectClass, menuwidget,
  826. X                                     args, nargs);
  827. X    }
  828. X
  829. X    callbacks[0].closure = NULL;
  830. X    for (i=0; i<sizeof(menu_1b_)/sizeof(menu_1b_[0]); i++) {
  831. X        callbacks[0].callback = menu_1b_[i].callback;
  832. X        if (i && i!=4)
  833. X            (void) XtCreateManagedWidget(menu_1b_[i].text, smeBSBObjectClass,
  834. X                                         menuwidget, args, nargs);
  835. X        else
  836. X            (void) XtCreateManagedWidget(menu_1b_[i].text, smeLineObjectClass,
  837. X                                         menuwidget, args, nargs);
  838. X    }
  839. X
  840. X    XtRealizeWidget(menuwidget);
  841. X
  842. X    nargs = 0;
  843. X    SetArg(XtNmenuOnScreen, True);
  844. X    SetArg(XtNlabel, "Hidden Notes");
  845. X    
  846. X    menuwidget = XtCreatePopupShell(HIDDEN_MENU, simpleMenuWidgetClass,
  847. X                                    toplevel, args, nargs);
  848. X
  849. X    XtRealizeWidget(menuwidget);
  850. X    /* from now on, this points to the hidden notes menu, which is often changed */
  851. X}
  852. X
  853. X/*
  854. X * HandleMenuSelection - callback from menu widget to handle a selection.
  855. X */
  856. Xstatic void
  857. XHandleMenuSelection(w, client_data, call_data)
  858. Xcaddr_t client_data, call_data;
  859. XWidget w;
  860. X{
  861. X    /*
  862. X     * Dispatch the command.
  863. X     */
  864. X    switch ((int) client_data) {
  865. X    case MenuCreate_1p5x1:
  866. X        CreateNewNote(PostItNote_1p5x1);
  867. X        break;
  868. X    case MenuCreate_1p5x2:
  869. X        CreateNewNote(PostItNote_1p5x2);
  870. X        break;
  871. X    case MenuCreate_2x3:
  872. X        CreateNewNote(PostItNote_2x3);
  873. X        break;
  874. X    case MenuCreate_3x3:
  875. X        CreateNewNote(PostItNote_3x3);
  876. X        break;
  877. X    case MenuCreate_3x4:
  878. X        CreateNewNote(PostItNote_3x4);
  879. X        break;
  880. X    case MenuCreate_3x5:
  881. X        CreateNewNote(PostItNote_3x5);
  882. X        break;
  883. X    case MenuCreate_4x6:
  884. X        CreateNewNote(PostItNote_4x6);
  885. X        break;
  886. X    }
  887. X}
  888. SHAR_EOF
  889. $TOUCH -am 0620135490 menu.c &&
  890. chmod 0600 menu.c ||
  891. echo "restore of menu.c failed"
  892. set `wc -c menu.c`;Wc_c=$1
  893. if test "$Wc_c" != "3538"; then
  894.     echo original size 3538, current size $Wc_c
  895. fi
  896. # ============= note.c ==============
  897. echo "x - extracting note.c (Text)"
  898. sed 's/^X//' << 'SHAR_EOF' > note.c &&
  899. X#ifndef lint
  900. 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 $";
  901. X#endif
  902. X
  903. X/*
  904. X * note.c - routines for handling notes.
  905. X *
  906. X * David A. Curry
  907. X * SRI International
  908. X * 333 Ravenswood Avenue
  909. X * Menlo Park, CA 94025
  910. X * davy@itstd.sri.com
  911. X *
  912. X * $Log:    note.c,v $
  913. X * Revision 1.4  90/06/14  11:20:09  davy
  914. X * Ported to X11 Release 4.  Changed to get the note save position in an
  915. X * ICCCM compliant (although kludgy) way.
  916. X * 
  917. X * Revision 1.3  89/01/10  09:57:24  davy
  918. X * Changed XGetNormalHints to XGetWindowAttributes for getting the size of
  919. X * the text window when saving.  XGetNormalHints comes up with the wrong
  920. X * size, for some reason.
  921. X * 
  922. X * Revision 1.2  89/01/10  09:13:13  davy
  923. X * Added XtChain... arguments to buttons and text window to prevent the
  924. X * buttons from getting screwed up on a resize.
  925. X * 
  926. X * Revision 1.1  89/01/10  09:00:21  davy
  927. X * Initial revision
  928. X * 
  929. X */
  930. X#include <X11/StringDefs.h>
  931. X#include <X11/Intrinsic.h>
  932. X#include <X11/Xaw/AsciiText.h>
  933. X#include <X11/Xaw/Command.h>
  934. X#include <X11/Xaw/Form.h>
  935. X#include <X11/Xaw/Simple.h>
  936. X#include <X11/Shell.h>
  937. X#include <sys/param.h>
  938. X#include <sys/dir.h>
  939. X#include <stdio.h>
  940. X#include <X11/Xaw/SimpleMenu.h>
  941. X#include <X11/Xaw/SmeLine.h>
  942. X#include <X11/Xaw/SmeBSB.h>
  943. X
  944. X#include "xpostme.h"
  945. X
  946. Xstatic PostItNote    *notes = NULL;
  947. X
  948. Xstatic PostItNote    *FindNote();
  949. Xstatic PostItNote    *AllocNote();
  950. X
  951. Xstatic void        SaveNote();
  952. Xstatic void        EraseNote();
  953. Xstatic void        HideNote();
  954. Xstatic void        DestroyNote();
  955. Xstatic void        CancelErase();
  956. Xstatic void        ConfirmErase();
  957. Xstatic void        CancelDestroy();
  958. Xstatic void        ConfirmDestroy();
  959. Xstatic void        MakeNoteWidget();
  960. X
  961. Xstatic void        GoMenu();
  962. X
  963. Xstatic struct {
  964. X    char *text;
  965. X    void (*callback)();
  966. X} menu_2_[] = {
  967. X    { "Save Text", SaveNote },
  968. X    { "Erase Text", EraseNote },
  969. X    { "Hide This Note", HideNote },
  970. X    { "Line", NULL },
  971. X    { "Remove This Note", DestroyNote }
  972. X};
  973. X
  974. X/*
  975. X * CreateNewNote - create a new note of the specified size.
  976. X */
  977. Xvoid
  978. XCreateNewNote(size)
  979. Xint size;
  980. X{
  981. X    static int hpi = 0;
  982. X    static int wpi = 0;
  983. X    register PostItNote *pn;
  984. X    register int hmm, wmm, hpixel, wpixel;
  985. X
  986. X    /*
  987. X     * Find out the number of pixels per inch on the screen.  We
  988. X     * can get the number of pixels, and the size in millimeters.
  989. X     * Then we convert to pixels/inch using the formula
  990. X     *
  991. X     *       2.54 cm     10 mm     pixels     pixels
  992. X     *    --------- x ------- x -------- = --------
  993. X     *      inch        cm         mm        inch
  994. X     *
  995. X     * The only problem with this is that some servers (like Xsun)
  996. X     * lie about what these numbers really are.
  997. X     */
  998. X    if ((hpi == 0) || (wpi == 0)) {
  999. X        hpixel = DisplayHeight(display, DefaultScreen(display));
  1000. X        wpixel = DisplayWidth(display, DefaultScreen(display));
  1001. X
  1002. X        hmm = DisplayHeightMM(display, DefaultScreen(display));
  1003. X        wmm = DisplayWidthMM(display, DefaultScreen(display));
  1004. X
  1005. X        hpi = (int) ((25.4 * hpixel) / (float) hmm + 0.5);
  1006. X        wpi = (int) ((25.4 * wpixel) / (float) wmm + 0.5);
  1007. X    }
  1008. X
  1009. X    /*
  1010. X     * Calculate sizes for the note.
  1011. X     */
  1012. X    switch (size) {
  1013. X    case PostItNote_1p5x1:
  1014. X        hpixel = 1.5 * hpi;
  1015. X        wpixel = 1.425 * wpi - 1;
  1016. X        break;
  1017. X    case PostItNote_1p5x2:
  1018. X        hpixel = 1.5 * hpi;
  1019. X        wpixel = 2 * wpi;
  1020. X        break;
  1021. X    case PostItNote_2x3:
  1022. X        hpixel = 2 * hpi;
  1023. X        wpixel = 3 * wpi;
  1024. X        break;
  1025. X    case PostItNote_3x3:
  1026. X        hpixel = 3 * hpi;
  1027. X        wpixel = 3 * wpi;
  1028. X        break;
  1029. X    case PostItNote_3x4:
  1030. X        hpixel = 3 * hpi;
  1031. X        wpixel = 4 * wpi;
  1032. X        break;
  1033. X    case PostItNote_3x5:
  1034. X        hpixel = 3 * hpi;
  1035. X        wpixel = 5 * wpi;
  1036. X        break;
  1037. X    case PostItNote_4x6:
  1038. X        hpixel = 4 * hpi;
  1039. X        wpixel = 6 * wpi;
  1040. X        break;
  1041. X    }
  1042. X
  1043. X    /*
  1044. X     * Allocate a new note structure.
  1045. X     */
  1046. X    pn = AllocNote(NewIndex);
  1047. X
  1048. X    /*
  1049. X     * Set the text window size.
  1050. X     */
  1051. X    pn->pn_textwidth = wpixel;
  1052. X    pn->pn_textheight = hpixel;
  1053. X
  1054. X    /*
  1055. X     * Make the widget for the note.
  1056. X     */
  1057. X    MakeNoteWidget(pn);
  1058. X}
  1059. X
  1060. X/*
  1061. X * LoadSavedNotes - load in the notes the user has saved.
  1062. X */
  1063. Xvoid
  1064. XLoadSavedNotes()
  1065. X{
  1066. X    DIR *dp;
  1067. X    FILE *fp;
  1068. X    char *realloc();
  1069. X    register PostItNote *pn;
  1070. X    register struct direct *d;
  1071. X    char buf[BUFSIZ], fname[MAXPATHLEN];
  1072. X    int n, len, nlen, shellx, shelly, texth, textw;
  1073. X
  1074. X    /*
  1075. X     * Try to open the directory.
  1076. X     */
  1077. X    if ((dp = opendir(app_res.note_dir)) == NULL)
  1078. X        /*        return; */
  1079. X        goto skipped;
  1080. X
  1081. X    nlen = strlen(PostItNoteFname);
  1082. X
  1083. X    /*
  1084. X     * For each entry...
  1085. X     */
  1086. X    while ((d = readdir(dp)) != NULL) {
  1087. X        /*
  1088. X         * Skip over anything which doesn't match our
  1089. X         * file naming scheme.
  1090. X         */
  1091. X        if (strncmp(d->d_name, PostItNoteFname, nlen) != 0)
  1092. X            continue;
  1093. X
  1094. X        /*
  1095. X         * Make the full path name.
  1096. X         */
  1097. X        sprintf(fname, "%s/%s", app_res.note_dir, d->d_name);
  1098. X
  1099. X        /*
  1100. X         * Open the file.
  1101. X         */
  1102. X        if ((fp = fopen(fname, "r")) == NULL)
  1103. X            continue;
  1104. X
  1105. X        /*
  1106. X         * Look for the magic cookie identifying this as
  1107. X         * a Post-It note.
  1108. X         */
  1109. X        if ((fscanf(fp, "%s", buf) == EOF) ||
  1110. X            (strcmp(buf, PostItNoteMagic) != 0)) {
  1111. X            fclose(fp);
  1112. X            continue;
  1113. X        }
  1114. X
  1115. X        /*
  1116. X         * Get the note position and size information.
  1117. X         */
  1118. X        fgets(buf, sizeof(buf), fp);
  1119. X
  1120. X        n = sscanf(buf, "%d %d %d %d %d", &shellx, &shelly, &texth,
  1121. X               &textw, &len);
  1122. X
  1123. X        /*
  1124. X         * Bad format; skip it.
  1125. X         */
  1126. X        if (n != 5) {
  1127. X            fclose(fp);
  1128. X            continue;
  1129. X        }
  1130. X
  1131. X        /*
  1132. X         * Get the index number of this note.
  1133. X         */
  1134. X        n = atoi(&(d->d_name[nlen]));
  1135. X
  1136. X        /*
  1137. X         * Get a note structure.
  1138. X         */
  1139. X        pn = AllocNote(n);
  1140. X
  1141. X        /*
  1142. X         * Set the information.
  1143. X         */
  1144. X        pn->pn_shellx = shellx;
  1145. X        pn->pn_shelly = shelly;
  1146. X        pn->pn_textwidth = textw;
  1147. X        pn->pn_textheight = texth;
  1148. X        pn->pn_positionit = True;
  1149. X
  1150. X        /*
  1151. X         * Save the file name.
  1152. X         */
  1153. X        pn->pn_file = SafeAlloc(strlen(fname) + 1);
  1154. X        strcpy(pn->pn_file, fname);
  1155. X
  1156. X        /*
  1157. X         * If we need a bigger buffer than the default,
  1158. X         * get one.
  1159. X         */
  1160. X        if (len >= pn->pn_textsize) {
  1161. X            n = (len + app_res.buf_size - 1) / app_res.buf_size;
  1162. X            n = n * app_res.buf_size;
  1163. X
  1164. X            if ((pn->pn_text = realloc(pn->pn_text, n)) == NULL) {
  1165. X                fprintf(stderr, "xpostme: out of memory.\n");
  1166. X                ByeBye();
  1167. X            }
  1168. X
  1169. X            pn->pn_textsize = n;
  1170. X        }
  1171. X
  1172. X        /*
  1173. X         * Read in the text.
  1174. X         */
  1175. X        fread(pn->pn_text, sizeof(char), len, fp);
  1176. X        fclose(fp);
  1177. X
  1178. X        /*
  1179. X         * Make a widget for this note.
  1180. X         */
  1181. X        MakeNoteWidget(pn);
  1182. X    }
  1183. X
  1184. X    closedir(dp);
  1185. X
  1186. Xskipped:
  1187. X    if (!notes || !app_res.hide_plaid)
  1188. X        XtMapWidget(toplevel);
  1189. X}
  1190. X
  1191. Xstatic void RaiseNote(w, c, garbage)
  1192. XWidget w;
  1193. Xcaddr_t c, garbage;
  1194. X{
  1195. X    PostItNote *pn = (PostItNote *) c;
  1196. X    if (pn->pn_unmapped) {
  1197. X        pn->pn_unmapped = FALSE;
  1198. X        XtMapWidget(pn->pn_shellwidget);
  1199. X        XtUnmanageChild(w);
  1200. X    }
  1201. X    XRaiseWindow(display, XtWindow(pn->pn_shellwidget));
  1202. X}
  1203. X
  1204. X/*
  1205. X * RaiseAllNotes - raise all the notes by raising their shell windows.
  1206. X */
  1207. Xvoid
  1208. XRaiseAllNotes()
  1209. X{
  1210. X    register PostItNote *pn;
  1211. X
  1212. X    for (pn = notes; pn != NULL; pn = pn->pn_next) 
  1213. X        RaiseNote(pn->pn_menuentry, (caddr_t) pn, (caddr_t) NULL);
  1214. X
  1215. X    if (app_res.hide_plaid && pn != notes)
  1216. X        XtUnmapWidget(toplevel);
  1217. X}
  1218. X
  1219. X/*
  1220. X * LowerAllNotes - lower all the notes by lowering their shell windows.
  1221. X */
  1222. Xvoid
  1223. XLowerAllNotes()
  1224. X{
  1225. X    register PostItNote *pn;
  1226. X
  1227. X    for (pn = notes; pn != NULL; pn = pn->pn_next)
  1228. X        XLowerWindow(display, XtWindow(pn->pn_shellwidget));
  1229. X}
  1230. X
  1231. X/*
  1232. X * SaveAllNotes - save all the notes.
  1233. X */
  1234. Xvoid
  1235. XSaveAllNotes()
  1236. X{
  1237. X    register PostItNote *pn;
  1238. X
  1239. X    for (pn = notes; pn != NULL; pn = pn->pn_next)
  1240. X        SaveNote(pn->pn_shellwidget, (caddr_t) pn, 0);
  1241. X}
  1242. X
  1243. X/*
  1244. X * MakeNoteWidget - make a widget for a Post-It note.
  1245. X */
  1246. Xstatic void
  1247. XMakeNoteWidget(pn)
  1248. XPostItNote *pn;
  1249. X{
  1250. X    Arg args[16];
  1251. X    char geometry[64];
  1252. X    Widget form, menu, simple;
  1253. X    XtCallbackRec callbacks[2];
  1254. X    register int nargs;
  1255. X    int i;
  1256. X    static char *formtrans = "<Btn3Down>: XawPositionSimpleMenu(Menu) MenuPopup(Menu) \n\
  1257. X<Btn1Down>: XawPositionSimpleMenu(privateMenu) MenuPopup(privateMenu) \n\
  1258. X<Btn2Down>: XawPositionSimpleMenu(hiddenNotes) MenuPopup(hiddenNotes)";
  1259. X    XtTranslations tt;
  1260. X
  1261. X    nargs = 0;
  1262. X    
  1263. X    /*
  1264. X     * If the shell window coordinates are valid, use them.
  1265. X     */
  1266. X    if (pn->pn_positionit) {
  1267. X        sprintf(geometry, "+%d+%d", pn->pn_shellx, pn->pn_shelly);
  1268. X        SetArg(XtNgeometry, geometry);
  1269. X        SetArg(XtNx, pn->pn_shellx);
  1270. X        SetArg(XtNy, pn->pn_shelly);
  1271. X    }
  1272. X
  1273. X    /*
  1274. X     * Make the shell widget for this note.  We just use
  1275. X     * a pop-up shell for this.
  1276. X     */
  1277. X    pn->pn_shellwidget = XtCreatePopupShell("Note",
  1278. X                        topLevelShellWidgetClass, toplevel,
  1279. X                        args, nargs);
  1280. X
  1281. X    pn->pn_menuentry = NULL;
  1282. X    
  1283. X    /*
  1284. X     * Make a form widget.
  1285. X     */
  1286. X    nargs = 0;
  1287. X    SetArg(XtNdefaultDistance, 0);
  1288. X    form = XtCreateManagedWidget("Form", formWidgetClass, pn->pn_shellwidget,
  1289. X                                 args, nargs);
  1290. X
  1291. X    /*
  1292. X     * Create simple to popup menus
  1293. X     */
  1294. X    nargs = 0;
  1295. X    SetArg(XtNtop, XtChainTop);
  1296. X    SetArg(XtNleft, XtChainLeft);
  1297. X    SetArg(XtNright, XtChainRight);
  1298. X    SetArg(XtNbottom, XtChainTop);        /* keep the constant height */
  1299. X    SetArg(XtNheight, 8);
  1300. X    SetArg(XtNwidth, pn->pn_textwidth);
  1301. X    SetArg(XtNtranslations, XtParseTranslationTable(formtrans));
  1302. X    SetArg(XtNbackground, foreground);
  1303. X    simple = XtCreateManagedWidget("topBar", simpleWidgetClass, form,
  1304. X                                   args, nargs);
  1305. X       
  1306. X    /*
  1307. X     * Create the text window.
  1308. X     */
  1309. X    nargs = 0;
  1310. X    SetArg(XtNtop, XtChainTop);
  1311. X    SetArg(XtNfromVert, simple);
  1312. X    SetArg(XtNleft, XtChainLeft);
  1313. X    SetArg(XtNright, XtChainRight);
  1314. X    SetArg(XtNstring, pn->pn_text);
  1315. X    SetArg(XtNeditType, XawtextEdit);
  1316. X    SetArg(XtNbottom, XtChainBottom);
  1317. X    SetArg(XtNuseStringInPlace, True);
  1318. X    SetArg(XtNlength, pn->pn_textsize);
  1319. X    SetArg(XtNwidth, pn->pn_textwidth);
  1320. X    SetArg(XtNheight, pn->pn_textheight);
  1321. X    SetArg(XtNresize, XawtextResizeNever);
  1322. X
  1323. X    if (app_res.scroll_bar) {
  1324. X        SetArg(XtNscrollVertical, XawtextScrollAlways);
  1325. X    }
  1326. X    else {
  1327. X        SetArg(XtNscrollVertical, XawtextScrollWhenNeeded);
  1328. X    }
  1329. X
  1330. X    pn->pn_textwidget = XtCreateManagedWidget("noteText", asciiTextWidgetClass,
  1331. X                                              form, args, nargs);
  1332. X
  1333. X    /*
  1334. X     * add needed stuff
  1335. X     */
  1336. X
  1337. X    nargs = 0;
  1338. X    SetArg(XtNlabel, "Note Actions");
  1339. X    menu = XtCreatePopupShell(PRIVATE_MENU, simpleMenuWidgetClass, form, args, nargs);
  1340. X    nargs = 0;
  1341. X    SetArg(XtNcallback, callbacks);
  1342. X    callbacks[0].closure = (caddr_t) pn;
  1343. X    callbacks[1].callback = NULL;
  1344. X    callbacks[1].closure = NULL;
  1345. X
  1346. X    for (i=0; i<sizeof(menu_2_)/sizeof(menu_2_[0]); i++) {
  1347. X        callbacks[0].callback = menu_2_[i].callback;
  1348. X        if (i != 3)
  1349. X            (void) XtCreateManagedWidget(menu_2_[i].text, smeBSBObjectClass, menu, args, nargs);
  1350. X        else
  1351. X            (void) XtCreateManagedWidget(menu_2_[i].text, smeLineObjectClass, menu, args, nargs);
  1352. X    }
  1353. X    
  1354. X    /*
  1355. X     * Realize the note and pop it up.
  1356. X     */
  1357. X
  1358. X    XtRealizeWidget(pn->pn_shellwidget);
  1359. X    if (app_res.hide_plaid)
  1360. X        XtUnmapWidget(toplevel);
  1361. X    pn->pn_unmapped = FALSE;                    /* visible */
  1362. X    XtPopup(pn->pn_shellwidget, XtGrabNone);
  1363. X}
  1364. X
  1365. X/*
  1366. X * SaveNote - save a note to a file.
  1367. X */
  1368. Xstatic void
  1369. XSaveNote(w, client_data, call_data)
  1370. Xcaddr_t client_data, call_data;
  1371. XWidget w;
  1372. X{
  1373. X    FILE *fp;
  1374. X    Window junk;
  1375. X    char *MakeFname();
  1376. X    PostItNote *pn = (PostItNote *) client_data;
  1377. X    XWindowAttributes win_attributes;
  1378. X    int len, shellx, shelly, texth, textw;
  1379. X
  1380. X    /*
  1381. X     * If it doesn't have a file name, make one.
  1382. X     */
  1383. X    if (pn->pn_file == NULL)
  1384. X        pn->pn_file = MakeFname(pn->pn_index);
  1385. X
  1386. X    /*
  1387. X     * Create the file.
  1388. X     */
  1389. X    if ((fp = fopen(pn->pn_file, "w")) == NULL) {
  1390. X        fprintf(stderr, "xpostit: ");
  1391. X        perror(pn->pn_file);
  1392. X        return;
  1393. X    }
  1394. X
  1395. X    /*
  1396. X     * Get the position of the shell window.
  1397. X     */
  1398. X    GetNotePosition(pn->pn_shellwidget, &shellx, &shelly);
  1399. X
  1400. X    /*
  1401. X     * Get the size of the text window.
  1402. X     */
  1403. X    XGetWindowAttributes(display, XtWindow(pn->pn_textwidget),
  1404. X                 &win_attributes);
  1405. X    texth = win_attributes.height;
  1406. X    textw = win_attributes.width;
  1407. X
  1408. X    /*
  1409. X     * Get the length of the text in the window.
  1410. X     */
  1411. X    len = strlen(pn->pn_text);
  1412. X
  1413. X    /*
  1414. X     * Print out the information needed to recreate the note.
  1415. X     */
  1416. X    fprintf(fp, "%s %d %d %d %d %d\n", PostItNoteMagic, shellx, shelly,
  1417. X        texth, textw, len);
  1418. X
  1419. X    /*
  1420. X     * Write out the text of the note.
  1421. X     */
  1422. X    if (len)
  1423. X        fwrite(pn->pn_text, sizeof(char), len, fp);
  1424. X
  1425. X    fclose(fp);
  1426. X}
  1427. X
  1428. X/*
  1429. X * EraseNote - erase all the text in a note.
  1430. X */
  1431. Xstatic void
  1432. XEraseNote(w, client_data, call_data)
  1433. Xcaddr_t client_data, call_data;
  1434. XWidget w;
  1435. X{
  1436. X    PostItNote *pn = (PostItNote *) client_data;
  1437. X    XtCallbackRec cancel[2], confirm[2];
  1438. X
  1439. X    bzero(confirm, sizeof(confirm));
  1440. X    bzero(cancel, sizeof(cancel));
  1441. X
  1442. X    /*
  1443. X     * If there's nothing in the window, then there's
  1444. X     * no need to erase it.
  1445. X     */
  1446. X    if (strlen(pn->pn_text) == 0)
  1447. X        return;
  1448. X
  1449. X    confirm[0].callback = ConfirmErase;
  1450. X    confirm[0].closure = (caddr_t) pn;
  1451. X    cancel[0].callback = CancelErase;
  1452. X    cancel[0].closure = (caddr_t) pn;
  1453. X
  1454. X    /*
  1455. X     * Get confirmation of what they want to do.
  1456. X     */
  1457. X    ConfirmIt("Erase This Note:  ", confirm, cancel);
  1458. X}
  1459. X
  1460. X/*
  1461. X * DestroyNote - destroy a note.
  1462. X */
  1463. Xstatic void
  1464. XDestroyNote(w, client_data, call_data)
  1465. Xcaddr_t client_data, call_data;
  1466. XWidget w;
  1467. X{
  1468. X    PostItNote *pn = (PostItNote *) client_data;
  1469. X    XtCallbackRec cancel[2], confirm[2];
  1470. X
  1471. X    bzero(confirm, sizeof(confirm));
  1472. X    bzero(cancel, sizeof(cancel));
  1473. X
  1474. X    confirm[0].callback = ConfirmDestroy;
  1475. X    confirm[0].closure = (caddr_t) pn;
  1476. X    cancel[0].callback = CancelDestroy;
  1477. X    cancel[0].closure = (caddr_t) pn;
  1478. X
  1479. X    /*
  1480. X     * Get confirmation of what they want to do.
  1481. X     */
  1482. X    ConfirmIt("Destroy This Note:", confirm, cancel);
  1483. X}
  1484. X
  1485. X/*
  1486. X * ConfirmErase - callback for erase confirmation.
  1487. X */
  1488. Xstatic void
  1489. XConfirmErase(w, client_data, call_data)
  1490. Xcaddr_t client_data, call_data;
  1491. XWidget w;
  1492. X{
  1493. X    Arg args[4];
  1494. X    register int nargs;
  1495. X    PostItNote *pn = (PostItNote *) client_data;
  1496. X    XawTextPosition pos = 0;
  1497. X
  1498. X    /*
  1499. X     * Get rid of the confirmation box.
  1500. X     */
  1501. X    ClearConfirm();
  1502. X
  1503. X    /*
  1504. X     * This is a kludge.  They should have provided
  1505. X     * an XtTextErase function.
  1506. X     */
  1507. X    bzero(pn->pn_text, pn->pn_textsize);
  1508. X
  1509. X    nargs = 0;
  1510. X    SetArg(XtNstring, pn->pn_text);
  1511. X    XtSetValues(pn->pn_textwidget, args, nargs);
  1512. X}
  1513. X
  1514. X/*
  1515. X * CancelErase - callback for erase cancellation.
  1516. X */
  1517. Xstatic void
  1518. XCancelErase(w, client_data, call_data)
  1519. Xcaddr_t client_data, call_data;
  1520. XWidget w;
  1521. X{
  1522. X    /*
  1523. X     * Get rid of the confirmation box.
  1524. X     */
  1525. X    ClearConfirm();
  1526. X}
  1527. X
  1528. X/*
  1529. X * ConfirmDestroy - callback for destroy confirmation.
  1530. X */
  1531. Xstatic void
  1532. XConfirmDestroy(w, client_data, call_data)
  1533. Xcaddr_t client_data, call_data;
  1534. XWidget w;
  1535. X{
  1536. X    PostItNote *pn = (PostItNote *) client_data, *prev;
  1537. X
  1538. X    /*
  1539. X     * Get rid of the confirmation box.
  1540. X     */
  1541. X    ClearConfirm();
  1542. X
  1543. X    /*
  1544. X     * Get rid of the widgets for this note.
  1545. X     */
  1546. X    XtDestroyWidget(pn->pn_shellwidget);        /* but it still will hang around */
  1547. X    if (pn->pn_menuentry)
  1548. X        XtDestroyWidget(pn->pn_menuentry);
  1549. X
  1550. X    /*
  1551. X     * Get rid of the note structure.
  1552. X     */
  1553. X    if (pn != notes) {
  1554. X        for (prev = notes; prev->pn_next; prev = prev->pn_next) {
  1555. X            if (prev->pn_next == pn)
  1556. X                break;
  1557. X        }
  1558. X
  1559. X        prev->pn_next = pn->pn_next;
  1560. X    }
  1561. X    else {
  1562. X        notes = pn->pn_next;
  1563. X    }
  1564. X
  1565. X    /*
  1566. X     * Get rid of the file.
  1567. X     */
  1568. X    if (pn->pn_file) {
  1569. X        unlink(pn->pn_file);
  1570. X        free(pn->pn_file);
  1571. X    }
  1572. X
  1573. X    /*
  1574. X     * Free the memory we used.
  1575. X     */
  1576. X    free(pn->pn_text);
  1577. X    free(pn);
  1578. X
  1579. X    for (pn = notes; pn; pn = pn->pn_next)
  1580. X        if (!pn->pn_unmapped)
  1581. X            break;
  1582. X
  1583. X    if (app_res.hide_plaid && !pn) {                                /* no note is visible */
  1584. X        XtMapWidget(toplevel);
  1585. X        XLowerWindow(XtDisplay(toplevel), XtWindow(toplevel));
  1586. X    }
  1587. X}
  1588. X
  1589. X/*
  1590. X * CancelDestroy - callback for destroy cancellation.
  1591. X */
  1592. Xstatic void
  1593. XCancelDestroy(w, client_data, call_data)
  1594. Xcaddr_t client_data, call_data;
  1595. XWidget w;
  1596. X{
  1597. X    /*
  1598. X     * Get rid of the confirmation box.
  1599. X     */
  1600. X    ClearConfirm();
  1601. X}
  1602. X
  1603. X/*
  1604. X * AllocNote - allocate a new note structure and insert in into the
  1605. X *           list of notes.
  1606. X */
  1607. Xstatic PostItNote *
  1608. XAllocNote(index)
  1609. Xint index;
  1610. X{
  1611. X    register PostItNote *pn;
  1612. X
  1613. X    /*
  1614. X     * Allocate a structure.
  1615. X     */
  1616. X    if (notes == NULL) {
  1617. X        notes = (PostItNote *) SafeAlloc(sizeof(PostItNote));
  1618. X        pn = notes;
  1619. X    }
  1620. X    else {
  1621. X        for (pn = notes; pn->pn_next != NULL; pn = pn->pn_next)
  1622. X            ;
  1623. X
  1624. X        pn->pn_next = (PostItNote *) SafeAlloc(sizeof(PostItNote));
  1625. X        pn = pn->pn_next;
  1626. X    }
  1627. X
  1628. X    /*
  1629. X     * Initialize the note.
  1630. X     */
  1631. X    pn->pn_positionit = False;
  1632. X    pn->pn_textsize = app_res.buf_size;
  1633. X    pn->pn_text = SafeAlloc(pn->pn_textsize);
  1634. X
  1635. X    /*
  1636. X     * If the index number was given, use it.  Otherwise,
  1637. X     * get a new index number.
  1638. X     */
  1639. X    pn->pn_index = (index == NewIndex ? NoteIndex() : index);
  1640. X
  1641. X    return(pn);
  1642. X}
  1643. X
  1644. X/*
  1645. X * FindNote - find the note structure with the given index number.
  1646. X */
  1647. Xstatic PostItNote *
  1648. XFindNote(index)
  1649. Xregister int index;
  1650. X{
  1651. X    register PostItNote *pn;
  1652. X
  1653. X    for (pn = notes; pn != NULL; pn = pn->pn_next) {
  1654. X        if (pn->pn_index == index)
  1655. X            return(pn);
  1656. X    }
  1657. X
  1658. X    return(NULL);
  1659. X}
  1660. X
  1661. X/*
  1662. X * NoteIndex - find the lowest free index number.
  1663. X */
  1664. Xstatic int
  1665. XNoteIndex()
  1666. X{
  1667. X    register int index;
  1668. X    register PostItNote *pn;
  1669. X
  1670. X    /*
  1671. X     * This is O(n**2), but the list should be small.
  1672. X     */
  1673. X    for (index = 1; ; index++) {
  1674. X        if ((pn = FindNote(index)) == NULL)
  1675. X            return(index);
  1676. X    }
  1677. X}
  1678. X
  1679. X/*
  1680. X * GetNotePosition - find the position of the widget window, taking into
  1681. X *             account any borders stuck on by reparenting window
  1682. X *             managers.
  1683. X *
  1684. X *             This is a KLUDGE.  The ICCCM does not specify a way
  1685. X *             for a client to find out what kind of border stuff
  1686. X *             the window manager has added.
  1687. X *
  1688. X *             Thanks to Stewart Levin for the original code.
  1689. X */
  1690. XGetNotePosition(w, x, y)
  1691. Xint *x, *y;
  1692. XWidget w;
  1693. X{
  1694. X    Window *children;
  1695. X    int status, nchildren;
  1696. X    Window here, parent, root;
  1697. X    XWindowAttributes win_attributes;
  1698. X
  1699. X    parent = XtWindow(w);
  1700. X
  1701. X    /*
  1702. X     * Walk up the tree looking for a parent of this window whose
  1703. X     * parent is the root.  That'll either be this window (if there
  1704. X     * is no window manager window) or the window added by the
  1705. X     * window manager.
  1706. X     */
  1707. X    do {
  1708. X        here = parent;
  1709. X
  1710. X        status = XQueryTree(display, here, &root, &parent, &children,
  1711. X                    &nchildren);
  1712. X
  1713. X        if (!status)
  1714. X            break;
  1715. X
  1716. X        if (children)
  1717. X            XFree(children);
  1718. X    } while (parent != root);
  1719. X
  1720. X    /*
  1721. X     * Get the attributes of this window we just found.
  1722. X     */
  1723. X    XGetWindowAttributes(display, here, &win_attributes);
  1724. X
  1725. X    /*
  1726. X     * Now deduct the border from the position of the window.
  1727. X     * We know the coordinates don't need translating, since
  1728. X     * this window's parent is the root.
  1729. X     */
  1730. X    *x = win_attributes.x - win_attributes.border_width;
  1731. X    *y = win_attributes.y - win_attributes.border_width;
  1732. X}
  1733. X
  1734. X/* unused event handler */            
  1735. Xstatic void GoMenu(w, c, event)
  1736. XWidget w;
  1737. Xcaddr_t c;
  1738. XXEvent *event;
  1739. X{
  1740. X    char *m = MAIN_MENU;
  1741. X    XtCallActionProc(w, "XawPositionSimpleMenu", event, &m, 1);
  1742. X    XtCallActionProc(w, "MenuPopup", event, &m, 1);
  1743. X}
  1744. X
  1745. Xstatic void HideNote(w, client_data, garbage)
  1746. XWidget w;
  1747. Xcaddr_t client_data, garbage;
  1748. X{
  1749. X    PostItNote *pn = (PostItNote *) client_data;
  1750. X    int nargs = 0;
  1751. X    Arg args[2];
  1752. X    Widget entry;
  1753. X    char buf[40];
  1754. X    
  1755. X    GetNotePosition(pn->pn_shellwidget, &pn->pn_shellx, &pn->pn_shelly);
  1756. X    XtUnmapWidget(pn->pn_shellwidget);
  1757. X    SetArg(XtNx, pn->pn_shellx);
  1758. X    SetArg(XtNy, pn->pn_shelly);
  1759. X    XtSetValues(pn->pn_shellwidget, args, nargs);
  1760. X    pn->pn_unmapped = TRUE;
  1761. X
  1762. X    /* add this note to the menu */
  1763. X    sprintf(buf, "Note at +%d+%d", pn->pn_shellx, pn->pn_shelly);
  1764. X    nargs = 0;
  1765. X    SetArg(XtNlabel, buf);
  1766. X    if (!pn->pn_menuentry) {
  1767. X        pn->pn_menuentry = XtCreateWidget("hidden", smeBSBObjectClass,
  1768. X                                          menuwidget, args, nargs);
  1769. X        XtAddCallback(pn->pn_menuentry, XtNcallback, RaiseNote, (caddr_t) pn);
  1770. X    }
  1771. X    else
  1772. X        XtSetValues(pn->pn_menuentry, args, nargs);
  1773. X    
  1774. X    XtManageChild(pn->pn_menuentry);
  1775. X
  1776. X    for (pn = notes; pn; pn = pn->pn_next)
  1777. X        if (!pn->pn_unmapped)
  1778. X            break;
  1779. X
  1780. X    if (app_res.hide_plaid && !pn)        /* all notes are unmapped */
  1781. X        XtMapWidget(toplevel);
  1782. X}
  1783. X
  1784. X
  1785. X
  1786. X
  1787. SHAR_EOF
  1788. $TOUCH -am 0620190290 note.c &&
  1789. chmod 0600 note.c ||
  1790. echo "restore of note.c failed"
  1791. set `wc -c note.c`;Wc_c=$1
  1792. if test "$Wc_c" != "18798"; then
  1793.     echo original size 18798, current size $Wc_c
  1794. fi
  1795. # ============= plaid.c ==============
  1796. echo "x - extracting plaid.c (Text)"
  1797. sed 's/^X//' << 'SHAR_EOF' > plaid.c &&
  1798. X#ifndef lint
  1799. 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 $";
  1800. X#endif
  1801. X
  1802. X/*
  1803. X * plaid.c - routines for manipulating the plaid widget.
  1804. X *
  1805. X * David A. Curry
  1806. X * SRI International
  1807. X * 333 Ravenswood Avenue
  1808. X * Menlo Park, CA 94025
  1809. X * davy@itstd.sri.com
  1810. X *
  1811. X * $Log:    plaid.c,v $
  1812. X * Revision 1.3  90/06/14  11:20:42  davy
  1813. X * Ported to X11 Release 4.  Got rid of button callback from the Plaid widget,
  1814. X * since it handles its own actions now.
  1815. X * 
  1816. X * Revision 1.2  89/01/10  09:30:30  davy
  1817. X * Fixed menu call-up so that the menu is always on the screen.
  1818. X * 
  1819. X * Revision 1.1  89/01/10  09:13:59  davy
  1820. X * Initial revision
  1821. X * 
  1822. X */
  1823. X#include <X11/StringDefs.h>
  1824. X#include <X11/Intrinsic.h>
  1825. X#include <stdio.h>
  1826. X
  1827. X#include "xpostme.h"
  1828. X#include "Plaid.h"
  1829. X
  1830. XWidget        plaidwidget;
  1831. X
  1832. X/*
  1833. X * CreatePlaidWidget - create the plaid widget.
  1834. X */
  1835. XWidget
  1836. XCreatePlaidWidget()
  1837. X{
  1838. X    Arg args[4];
  1839. X    register int nargs;
  1840. X
  1841. X    /*
  1842. X     * Create the plaid widget.
  1843. X     */
  1844. X    plaidwidget = XtCreateWidget("Plaid", plaidWidgetClass, toplevel,
  1845. X                     NULL, 0);
  1846. X
  1847. X    XtAddCallback(plaidwidget, XtNlowerCallback, LowerAllNotes, 0);
  1848. X    XtAddCallback(plaidwidget, XtNraiseCallback, RaiseAllNotes, 0);
  1849. X    
  1850. X    /*
  1851. X     * Get the width and height of the widget.
  1852. X     */
  1853. X    nargs = 0;
  1854. X    SetArg(XtNwidth, NULL);
  1855. X    SetArg(XtNheight, NULL);
  1856. X    XtGetValues(plaidwidget, args, nargs);
  1857. X
  1858. X    /*
  1859. X     * If the user didn't set them, then we
  1860. X     * should set them to the defaults.
  1861. X     */
  1862. X    if ((args[0].value == 0) || (args[1].value == 0)) {
  1863. X        if (args[0].value == 0)
  1864. X            XtSetArg(args[0], XtNwidth, DefaultPlaidWidth);
  1865. X
  1866. X        if (args[1].value == 0)
  1867. X            XtSetArg(args[1], XtNheight, DefaultPlaidHeight);
  1868. X
  1869. X        XtSetValues(plaidwidget, args, nargs);
  1870. X    }
  1871. X
  1872. X    /*
  1873. X     * Inform the application shell we're here.
  1874. X     */
  1875. X    XtManageChild(plaidwidget);
  1876. X    return(plaidwidget);
  1877. X}
  1878. SHAR_EOF
  1879. $TOUCH -am 0620135490 plaid.c &&
  1880. chmod 0600 plaid.c ||
  1881. echo "restore of plaid.c failed"
  1882. set `wc -c plaid.c`;Wc_c=$1
  1883. if test "$Wc_c" != "1819"; then
  1884.     echo original size 1819, current size $Wc_c
  1885. fi
  1886. # ============= util.c ==============
  1887. echo "x - extracting util.c (Text)"
  1888. sed 's/^X//' << 'SHAR_EOF' > util.c &&
  1889. X#ifndef lint
  1890. 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 $";
  1891. X#endif
  1892. X
  1893. X/*
  1894. X * util.c - utility routines.
  1895. X *
  1896. X * David A. Curry
  1897. X * SRI International
  1898. X * 333 Ravenswood Avenue
  1899. X * Menlo Park, CA 94025
  1900. X * davy@itstd.sri.com
  1901. X *
  1902. X * $Log:    util.c,v $
  1903. X * Revision 1.2  90/06/14  11:21:14  davy
  1904. X * Ported to X11 Release 4.
  1905. X * 
  1906. X * Revision 1.1  90/06/13  09:48:49  davy
  1907. X * Initial revision
  1908. X * 
  1909. X */
  1910. X#include <X11/StringDefs.h>
  1911. X#include <X11/Intrinsic.h>
  1912. X#include <sys/param.h>
  1913. X#include <stdio.h>
  1914. X#include <pwd.h>
  1915. X
  1916. X#include "xpostme.h"
  1917. X
  1918. X/*
  1919. X * ByeBye - clean up and exit.
  1920. X */
  1921. Xvoid
  1922. XByeBye()
  1923. X{
  1924. X    /*
  1925. X     * If saving notes is on, save all notes.
  1926. X     */
  1927. X    if (app_res.save_notes)
  1928. X        SaveAllNotes();
  1929. X
  1930. X    XtDestroyWidget(toplevel);
  1931. X    XCloseDisplay(display);
  1932. X    exit(0);
  1933. X}
  1934. X
  1935. X/*
  1936. X * SetNoteDir - determine the path to the note directory.
  1937. X */
  1938. Xvoid
  1939. XSetNoteDir()
  1940. X{
  1941. X    char *getenv();
  1942. X    char *home, *s;
  1943. X    struct passwd *pwd;
  1944. X    char fname[MAXPATHLEN];
  1945. X
  1946. X    /*
  1947. X     * If it's an absolute path name,
  1948. X     * we're done.
  1949. X     */
  1950. X    if (app_res.note_dir[0] == '/')
  1951. X        return;
  1952. X
  1953. X    /*
  1954. X     * Find the user's home directory.
  1955. X     */
  1956. X    if ((home = getenv("HOME")) == NULL) {
  1957. X        if ((pwd = getpwuid(getuid())) == NULL) {
  1958. X            fprintf(stderr, "xpostme: who are you?\n");
  1959. X            exit(1);
  1960. X        }
  1961. X
  1962. X        home = pwd->pw_dir;
  1963. X    }
  1964. X
  1965. X    /*
  1966. X     * Save the path.
  1967. X     */
  1968. X    sprintf(fname, "%s/%s", home, app_res.note_dir);
  1969. X
  1970. X    s = SafeAlloc(strlen(fname) + 1);
  1971. X    app_res.note_dir = s;
  1972. X    strcpy(s, fname);
  1973. X}
  1974. X
  1975. X/*
  1976. X * MakeFname - make a file name from a note index number.
  1977. X */
  1978. Xchar *
  1979. XMakeFname(index)
  1980. Xregister int index;
  1981. X{
  1982. X    char *s;
  1983. X    char fname[MAXPATHLEN];
  1984. X
  1985. X    sprintf(fname, "%s/%s%d", app_res.note_dir, PostItNoteFname, index);
  1986. X    s = SafeAlloc(strlen(fname) + 1);
  1987. X    strcpy(s, fname);
  1988. X    return(s);
  1989. X}
  1990. X
  1991. X/*
  1992. X * SafeAlloc - allocate n bytes of memory, exit if we run out.
  1993. X */
  1994. Xchar *
  1995. XSafeAlloc(nbytes)
  1996. Xregister int nbytes;
  1997. X{
  1998. X    char *malloc();
  1999. X    register char *s;
  2000. X
  2001. X    if ((s = malloc(nbytes)) == NULL) {
  2002. X        fprintf(stderr, "xpostme: out of memory.\n");
  2003. X        exit(1);
  2004. X    }
  2005. X
  2006. X    bzero(s, nbytes);
  2007. X    return(s);
  2008. X}
  2009. SHAR_EOF
  2010. $TOUCH -am 0620135490 util.c &&
  2011. chmod 0600 util.c ||
  2012. echo "restore of util.c failed"
  2013. set `wc -c util.c`;Wc_c=$1
  2014. if test "$Wc_c" != "2041"; then
  2015.     echo original size 2041, current size $Wc_c
  2016. fi
  2017. # ============= xpostme.c ==============
  2018. echo "x - extracting xpostme.c (Text)"
  2019. sed 's/^X//' << 'SHAR_EOF' > xpostme.c &&
  2020. X#ifndef lint
  2021. 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 $";
  2022. X#endif
  2023. X
  2024. X/*
  2025. X * xpostme.c - Post-It Notes for the X Window System, with a new user interface.
  2026. X *
  2027. X * Based on an X10R4 application.  This one is for X11R4 and uses the
  2028. X * Xt toolkit and the Athena widgets.
  2029. X *
  2030. X * David A. Curry
  2031. X * SRI International
  2032. X * 333 Ravenswood Avenue
  2033. X * Menlo Park, CA 94025
  2034. X * davy@itstd.sri.com
  2035. X *
  2036. X * $Log:    xpostit.c,v $
  2037. X * Revision 1.2  90/06/14  11:21:24  davy
  2038. X * Ported to X11 Release 4.
  2039. X * 
  2040. X * Revision 1.1  90/06/13  09:48:51  davy
  2041. X * Initial revision
  2042. X * 
  2043. X */
  2044. X#include <X11/StringDefs.h>
  2045. X#include <X11/Intrinsic.h>
  2046. X#include <X11/Shell.h>
  2047. X#include <signal.h>
  2048. X#include <stdio.h>
  2049. X
  2050. X#include "xpostme.h"
  2051. X
  2052. X/*
  2053. X * Command line options and the resources they set.
  2054. X */
  2055. Xstatic XrmOptionDescRec options[] = {
  2056. X    { "-bs",    ".bufSize",        XrmoptionSepArg,    NULL },
  2057. X    { "-dir",    ".noteDir",        XrmoptionSepArg,    NULL },
  2058. X    { "-sb",    ".scrollBar",    XrmoptionNoArg,        "true" },
  2059. X    { "-sv",    ".saveNotes",    XrmoptionNoArg,        "true" },
  2060. X    { "-hide",    ".hidePlaid",    XrmoptionNoArg,        "true" },
  2061. X    { "-show",    ".hidePlaid",    XrmoptionNoArg,        "false" },
  2062. X};
  2063. X
  2064. X/*
  2065. X * Fallback resources.
  2066. X */
  2067. Xstatic String fallback_resources[] = {
  2068. X    "*Command*font: -adobe-helvetica-bold-r-normal--*-120-*-*-*-*-*-*",
  2069. X    "*SimpleMenu*font:    -adobe-helvetica-medium-r-normal--*-120-*-*-*-*-*-*",
  2070. X    "*Text*font:    -b&h-lucidatypewriter-medium-r-normal-*-*-120-*-*-*-*-*-*",
  2071. X    "*Text*wrap:        word",
  2072. X    "*Command*shapeStyle:    oval",
  2073. X
  2074. X    NULL
  2075. X};
  2076. X    
  2077. X/*
  2078. X * Resources we maintain besides those maintained by the toolkit.
  2079. X */
  2080. Xstatic XtResource resources[] = {
  2081. X#define offset(field)    XtOffset(AppResPtr,field)
  2082. X    { "bufSize", "BufSize", XtRInt, sizeof(int),
  2083. X      offset(buf_size), XtRImmediate, (caddr_t) DefaultBufSize },
  2084. X    { "noteDir", "NoteDir", XtRString, sizeof(String),
  2085. X      offset(note_dir), XtRString, DefaultNoteDir },
  2086. X    { "saveNotes", "SaveNotes", XtRBoolean, sizeof(Boolean),
  2087. X      offset(save_notes), XtRImmediate, (caddr_t) False },
  2088. X    { "scrollBar", "Scroll", XtRBoolean, sizeof(Boolean),
  2089. X      offset(scroll_bar), XtRImmediate, (caddr_t) False },
  2090. X    { "hidePlaid", "HidePlaid", XtRBoolean, sizeof(Boolean),
  2091. X      offset(hide_plaid), XtRImmediate, (caddr_t) False },
  2092. X#undef offset
  2093. X};
  2094. X
  2095. XAppRes    app_res;        /* xpostme application resources    */
  2096. XWidget    toplevel;        /* top level application shell widget    */
  2097. XScreen    *screen;        /* pointer to the screen of the display    */
  2098. XDisplay    *display;        /* pointer to the display we're on    */
  2099. XXtAppContext appcontext;    /* application context            */
  2100. XPixel foreground;
  2101. X
  2102. Xvoid
  2103. Xmain(argc, argv)
  2104. Xchar **argv;
  2105. Xint argc;
  2106. X{
  2107. X    Arg args[4];
  2108. X    char *appname;
  2109. X    char *rindex();
  2110. X    register int nargs;
  2111. X    Boolean setsigs = False;
  2112. X    Widget plaid;
  2113. X
  2114. X    /*
  2115. X     * Ignore signals for now, but record whether they were
  2116. X     * already ignored or not so we can catch them later if
  2117. X     * need be.
  2118. X     */
  2119. X    if ((signal(SIGQUIT, SIG_IGN) != SIG_IGN) &&
  2120. X        (signal(SIGINT, SIG_IGN) != SIG_IGN))
  2121. X        setsigs = True;
  2122. X
  2123. X    /*
  2124. X     * Get application name.
  2125. X     */
  2126. X    if ((appname = rindex(*argv, '/')) == NULL)
  2127. X        appname = *argv;
  2128. X    else
  2129. X        appname++;
  2130. X
  2131. X    /*
  2132. X     * Initialize the toolkit and create an application shell.
  2133. X     */
  2134. X    toplevel = XtAppInitialize(&appcontext, PostItNoteClass, options,
  2135. X            XtNumber(options), &argc, argv, fallback_resources,
  2136. X            NULL, 0);
  2137. X
  2138. X    display = XtDisplay(toplevel);
  2139. X    screen = DefaultScreenOfDisplay(display);
  2140. X
  2141. X    /*
  2142. X     * If we need to handle keyboard signals, do it now.
  2143. X     */
  2144. X    if (setsigs) {
  2145. X        signal(SIGQUIT, ByeBye);
  2146. X        signal(SIGINT, ByeBye);
  2147. X    }
  2148. X
  2149. X    /*
  2150. X     * Always handle these.
  2151. X     */
  2152. X    signal(SIGTERM, ByeBye);
  2153. X    signal(SIGHUP, ByeBye);
  2154. X
  2155. X    /*
  2156. X     * Send X errors to the exit routine.
  2157. X     */
  2158. X    XSetErrorHandler((XErrorHandler) ByeBye);
  2159. X
  2160. X    /*
  2161. X     * Now get any resources we're interested in.
  2162. X     */
  2163. X    XtGetApplicationResources(toplevel, &app_res, resources,
  2164. X                  XtNumber(resources), argv, argc);
  2165. X
  2166. X    plaid = CreatePlaidWidget();
  2167. X    CreateMenuWidget();        /* create main menu */
  2168. X
  2169. X    XtSetArg(args[0], XtNmappedWhenManaged, (XtArgVal) False);
  2170. X    XtSetValues(toplevel, args, (Cardinal) 1);
  2171. X    XtRealizeWidget(toplevel);
  2172. X
  2173. X    XtSetArg(args[0], XtNforeground, (XtArgVal) &foreground);
  2174. X    XtGetValues(plaid, args, (Cardinal) 1);
  2175. X    
  2176. X    /*
  2177. X     * Construct the path to the directory notes are
  2178. X     * stored in.
  2179. X     */
  2180. X    SetNoteDir();
  2181. X
  2182. X    /*
  2183. X     * Realize the top level and flush the server, which will
  2184. X     * let the user position the plaid window and map it.
  2185. X     */
  2186. X
  2187. X    XFlush(display);
  2188. X
  2189. X    /*
  2190. X     * Load the notes the user has saved, and create widgets
  2191. X     * for them.
  2192. X     */
  2193. X    LoadSavedNotes();
  2194. X
  2195. X    /*
  2196. X     * Never returns.
  2197. X     */
  2198. X    XtAppMainLoop(appcontext);
  2199. X}
  2200. X
  2201. X
  2202. X
  2203. SHAR_EOF
  2204. $TOUCH -am 0620141490 xpostme.c &&
  2205. chmod 0600 xpostme.c ||
  2206. echo "restore of xpostme.c failed"
  2207. set `wc -c xpostme.c`;Wc_c=$1
  2208. if test "$Wc_c" != "4588"; then
  2209.     echo original size 4588, current size $Wc_c
  2210. fi
  2211. # ============= xpostme.h ==============
  2212. echo "x - extracting xpostme.h (Text)"
  2213. sed 's/^X//' << 'SHAR_EOF' > xpostme.h &&
  2214. X/*
  2215. 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 $
  2216. X *
  2217. X * xpostme.h - declarations for xpostit.
  2218. X *
  2219. X * David A. Curry
  2220. X * SRI International
  2221. X * 333 Ravenswood Avenue
  2222. X * Menlo Park, CA 94025
  2223. X * davy@itstd.sri.com
  2224. X *
  2225. X * $Log:    xpostit.h,v $
  2226. X * Revision 1.2  90/06/14  11:21:33  davy
  2227. X * Ported to X11 Release 4.
  2228. X * 
  2229. X * Revision 1.1  90/06/13  09:48:52  davy
  2230. X * Initial revision
  2231. X * 
  2232. X */
  2233. X
  2234. X/*
  2235. X * Default values.
  2236. X */
  2237. X#define DefaultBufSize        2048
  2238. X#define DefaultNoteDir        ".postitnotes"
  2239. X#define DefaultPlaidWidth    113
  2240. X#define DefaultPlaidHeight    17
  2241. X
  2242. X/*
  2243. X * Post-It Note sizes.
  2244. X */
  2245. X#define PostItNote_1p5x1    0
  2246. X#define PostItNote_1p5x2    1
  2247. X#define PostItNote_2x3        2
  2248. X#define PostItNote_3x3        3
  2249. X#define PostItNote_3x4        4
  2250. X#define PostItNote_3x5        5
  2251. X#define PostItNote_4x6        6
  2252. X
  2253. X/*
  2254. X * Post-It Note file information.
  2255. X */
  2256. X#define PostItNoteMagic        "%!<postitnote>"
  2257. X#define PostItNoteFname        "note"
  2258. X
  2259. X/*
  2260. X * Application class.
  2261. X */
  2262. X#define PostItNoteClass        "Xpostit"
  2263. X
  2264. X/*
  2265. X * Request for a new note index number.
  2266. X */
  2267. X#define NewIndex        -1
  2268. X
  2269. X/*
  2270. X * Just in case.
  2271. X */
  2272. X#ifndef MAXPATHLEN
  2273. X#define MAXPATHLEN    1024
  2274. X#endif
  2275. X
  2276. X/*
  2277. X * Useful macros.
  2278. X */
  2279. X#define SetArg(which, val)    XtSetArg(args[nargs], (which),\
  2280. X                     (XtArgVal) (val)); nargs++
  2281. X#define SetCallback(which, val)    callbacks[0].callback = (which); \
  2282. X                callbacks[0].closure = (caddr_t) (val)
  2283. X
  2284. X/*
  2285. X * The Post-It Note record.  One of these is allocated
  2286. X * for each note created.
  2287. X */
  2288. Xtypedef struct _PostItNote {
  2289. X    Widget    pn_shellwidget;        /* shell widget holding it all    */
  2290. X    Widget    pn_textwidget;        /* text widget of the note    */
  2291. X    Widget    pn_menuentry;        /* associated menu entry if hidden */
  2292. X
  2293. X    char    *pn_file;        /* file note will be saved in    */
  2294. X    char    *pn_text;        /* buffer holding text of note    */
  2295. X
  2296. X    int    pn_index;        /* index number of note        */
  2297. X    int    pn_shellx;        /* x coord of shell widget    */
  2298. X    int    pn_shelly;        /* y coord of shell widget    */
  2299. X    int    pn_textsize;        /* size of pn_text in chars    */
  2300. X    int    pn_textwidth;        /* width of text widget window    */
  2301. X    int    pn_textheight;        /* height of text widget window    */
  2302. X
  2303. X    Boolean    pn_positionit;        /* true if shellx/shelly valid    */
  2304. X    Boolean pn_unmapped;
  2305. X
  2306. X    struct    _PostItNote *pn_next;    /* pointer to next note record    */
  2307. X} PostItNote;
  2308. X
  2309. X/*
  2310. X * The resource record, for holding resources specific to xpostme.
  2311. X */
  2312. Xtypedef struct {
  2313. X    int    buf_size;        /* size of pn_text to be used    */
  2314. X    String    note_dir;        /* path to note directory    */
  2315. X    Boolean    scroll_ovf;        /* set scroll on overflow    */
  2316. X    Boolean    scroll_bar;        /* turn on scroll bars        */
  2317. X    Boolean save_notes;        /* save notes on exit        */
  2318. X    Boolean hide_plaid;        /* hide plaid when notes are active ? */
  2319. X} AppRes, *AppResPtr;
  2320. X
  2321. X/*
  2322. X * External variable declarations.
  2323. X */
  2324. Xextern    AppRes app_res;
  2325. X
  2326. Xextern    Screen *screen;
  2327. Xextern    Display *display;
  2328. X
  2329. Xextern    Widget toplevel;
  2330. Xextern    Widget listwidget;
  2331. Xextern    Widget menuwidget;
  2332. Xextern    Widget plaidwidget;
  2333. X
  2334. Xextern Pixel foreground;
  2335. X
  2336. X/*
  2337. X * Function declarations.
  2338. X */
  2339. Xchar    *SafeAlloc();
  2340. X
  2341. Xvoid    ByeBye();
  2342. Xvoid    ConfirmIt();
  2343. Xvoid    ClearConfirm();
  2344. Xvoid    SaveAllNotes();
  2345. Xvoid    RaiseAllNotes();
  2346. Xvoid    LowerAllNotes();
  2347. Xvoid    CreateNewNote();
  2348. Xvoid    CreateMenuWidget();
  2349. XWidget    CreatePlaidWidget();
  2350. X
  2351. X#define MAIN_MENU "Menu"
  2352. X#define PRIVATE_MENU "privateMenu"
  2353. X#define HIDDEN_MENU "hiddenNotes"
  2354. SHAR_EOF
  2355. $TOUCH -am 0620135490 xpostme.h &&
  2356. chmod 0600 xpostme.h ||
  2357. echo "restore of xpostme.h failed"
  2358. set `wc -c xpostme.h`;Wc_c=$1
  2359. if test "$Wc_c" != "3231"; then
  2360.     echo original size 3231, current size $Wc_c
  2361. fi
  2362. exit 0
  2363.  
  2364. dan
  2365. ----------------------------------------------------
  2366. O'Reilly && Associates   argv@sun.com / argv@ora.com
  2367. Opinions expressed reflect those of the author only.
  2368.