home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / alt / sources / 2562 < prev    next >
Encoding:
Text File  |  1992-11-18  |  50.1 KB  |  1,934 lines

  1. Newsgroups: alt.sources
  2. Path: sparky!uunet!sun-barr!cs.utexas.edu!zaphod.mps.ohio-state.edu!darwin.sura.net!sgiblab!munnari.oz.au!manuel.anu.edu.au!csc.canberra.edu.au!pandonia!jan
  3. From: jan@pandonia.canberra.edu.au (Jan Newmarch)
  4. Subject: X11/Motif file manager - part 07 of 17
  5. Message-ID: <1992Nov19.052315.25782@csc.canberra.edu.au>
  6. Sender: news@csc.canberra.edu.au
  7. Organization: University of Canberra
  8. Date: Thu, 19 Nov 92 05:23:15 GMT
  9. Lines: 1923
  10.  
  11.  
  12.  
  13. #!/bin/sh
  14. # this is part.07 (part 7 of a multipart archive)
  15. # do not concatenate these parts, unpack them in order with /bin/sh
  16. # file xmfm/main.c continued
  17. #
  18. if test ! -r _shar_seq_.tmp; then
  19.     echo 'Please unpack part 1 first!'
  20.     exit 1
  21. fi
  22. (read Scheck
  23.  if test "$Scheck" != 7; then
  24.     echo Please unpack part "$Scheck" next!
  25.     exit 1
  26.  else
  27.     exit 0
  28.  fi
  29. ) < _shar_seq_.tmp || exit 1
  30. if test ! -f _shar_wnt_.tmp; then
  31.     echo 'x - still skipping xmfm/main.c'
  32. else
  33. echo 'x - continuing file xmfm/main.c'
  34. sed 's/^X//' << 'SHAR_EOF' >> 'xmfm/main.c' &&
  35. X * drag-n-drop procedure.
  36. X */
  37. X    String myTranslations =
  38. X        "#override\n\
  39. X        <Btn1Down>:    Arm() rddStartAction()\n\
  40. X        <Btn1Up>:    Activate() Disarm() myDropAction()\n\
  41. X        <Btn1Motion>:    rddDragAction()\n";
  42. #endif /* RDD */
  43. X
  44. X
  45. X
  46. X    /*    Initialize toolkit and open the display. 
  47. X        Use XtInitialize and XtWidgetToAppContext cos
  48. X        I can't get XtAppCreateShell to work
  49. X        in builtin_opendir()
  50. X    */ 
  51. X     app_shell = XtInitialize(
  52. X             NULL,         /* application name */    
  53. X               Class_name,     /* class name */    
  54. X               NULL,         /* options */    
  55. X               0,        /* number of options */    
  56. X               &argc, argv);
  57. X    app_context = XtWidgetToApplicationContext (app_shell);
  58. X      
  59. #    ifdef DEBUG_MAIN
  60. X        fprintf(stderr, "Initialised toolkit\n");
  61. #    endif
  62. #ifdef RDD
  63. X    /* RDD add action myAction */
  64. X    {
  65. X        XtActionsRec actions;
  66. X        actions.string    = "myDropAction";
  67. X        actions.proc    = myDropAction;
  68. X        XtAppAddActions (app_context, &actions, 1);
  69. X    }
  70. X
  71. X    /* RDD  initialize the rdd package */
  72. X    rddInit (app_shell, app_context);
  73. X
  74. X    /* RDD parse translations table */
  75. X    trans_table = XtParseTranslationTable (myTranslations);
  76. #endif /* RDD */
  77. X
  78. #ifdef MOTIF_DD
  79. X        InitMotifDD (app_shell, app_context);
  80. #endif /* MOTIF_DD */
  81. X
  82. X    applic_widget = CreateApplication (app_shell);
  83. X    XtManageChild (applic_widget);
  84. X
  85. #    ifdef DEBUG_MAIN
  86. X        fprintf(stderr, "Created application\n");
  87. #    endif
  88. X
  89. X    /*    Create and realize main application window. 
  90. X    */ 
  91. X    XtRealizeWidget (app_shell); 
  92. X
  93. #    ifdef DEBUG_MAIN
  94. X        fprintf(stderr, "Realised windows\n");
  95. #    endif
  96. X
  97. X    create_gcs (app_shell);
  98. X
  99. X
  100. X    /* set files in panes */
  101. X    XtVaGetValues (applic_widget,
  102. X            XmNuserData, (XtArgVal) &dpi,
  103. X            NULL);
  104. X
  105. X    actions = LoadFileActions (dpi);
  106. X
  107. X    ResetFilesInPanes (dpi);
  108. X
  109. X    SetActionsInDirsToolbar (dpi);
  110. X
  111. X        SetFiltersInLabels (dpi);
  112. X
  113. X    /* set up a signal handler for children dying
  114. X       typically actions performed on files that may
  115. X       change directories
  116. X    */
  117. X    signal (SIGCHLD, child_died);
  118. X
  119. X    /*    Get and dispatch events. 
  120. X    */ 
  121. #    ifdef DEBUG_MAIN
  122. X        fprintf(stderr, "Main looping...\n");
  123. #    endif
  124. X
  125. #ifdef RDD
  126. X    rddAppMainLoop (app_context);
  127. #else
  128. X    XtAppMainLoop (app_context); 
  129. #endif /* RDD */
  130. X
  131. /*************************************************************************
  132. X * Function: DestroyDialogCB ()
  133. X * Purpose: destroy a dialog
  134. X * In parameters: w, c1, c2
  135. X * Out parameters:
  136. X * Precondition: w is a child of a popup shell
  137. X * Postcondition: parent on down all destroyed
  138. X ************************************************************************/ 
  139. /* ARGSUSED */
  140. void
  141. DestroyDialogCB
  142. #ifdef UseFunctionPrototypes
  143. X    (Widget w, XtPointer c1, XtPointer c2)
  144. #else
  145. X    (w, c1, c2)
  146. X    Widget w;
  147. X    XtPointer c1, c2;
  148. X
  149. #endif
  150. {
  151. X    XtUnmanageChild(w);
  152. X    XtDestroyWidget(XtParent(w));
  153. }
  154. X
  155. /*-------------------------------------------------------------
  156. **    Show Error Message Dialog when a system error has occurred
  157. */
  158. X
  159. /*************************************************************************
  160. X * Function: ErrorDialog ()
  161. X * Purpose: show an error dialog
  162. X * In parameters: str
  163. X * Out parameters:
  164. X * Precondition: an error of some kind has occurred
  165. X * Postcondition: user has registered error
  166. X ************************************************************************/ 
  167. void ErrorDialog
  168. #ifdef UseFunctionPrototypes
  169. X    (char *str)
  170. #else
  171. X    (str)
  172. char * str;
  173. X
  174. #endif
  175. {    int n;
  176. X    Arg    args[MAX_ARGS];
  177. X    Widget cancel, help, dialog;
  178. X    XmString xmstr;
  179. X
  180. X    n = 0;
  181. X    xmstr = XmStringCreateSimple (str);
  182. X    XtSetArg (args[n], XmNmessageString, xmstr); n++;
  183. X    dialog = XmCreateErrorDialog(app_shell, "", args, n);
  184. X    XmStringFree(xmstr);
  185. X    XtAddCallback(dialog, XmNokCallback, DestroyDialogCB, NULL);
  186. X
  187. X    help = XmMessageBoxGetChild(dialog, 
  188. X            XmDIALOG_HELP_BUTTON);
  189. X    XtUnmanageChild(help);
  190. X
  191. X    cancel = XmMessageBoxGetChild(dialog, 
  192. X            XmDIALOG_CANCEL_BUTTON);
  193. X    XtUnmanageChild(cancel);
  194. X
  195. X    XtManageChild(dialog);
  196. }
  197. SHAR_EOF
  198. echo 'File xmfm/main.c is complete' &&
  199. chmod 0644 xmfm/main.c ||
  200. echo 'restore of xmfm/main.c failed'
  201. Wc_c="`wc -c < 'xmfm/main.c'`"
  202. test 12462 -eq "$Wc_c" ||
  203.     echo 'xmfm/main.c: original size 12462, current size' "$Wc_c"
  204. rm -f _shar_wnt_.tmp
  205. fi
  206. # ============= xmfm/menu.c ==============
  207. if test -f 'xmfm/menu.c' -a X"$1" != X"-c"; then
  208.     echo 'x - skipping xmfm/menu.c (File already exists)'
  209.     rm -f _shar_wnt_.tmp
  210. else
  211. > _shar_wnt_.tmp
  212. echo 'x - extracting xmfm/menu.c (Text)'
  213. sed 's/^X//' << 'SHAR_EOF' > 'xmfm/menu.c' &&
  214. /*------------------------------------------------------------- 
  215. X * File: $Source: /usr/usrs/xsource/xmfm/RCS/menu.c,v $
  216. X * Author: Jan Newmarch
  217. X * Last modified: $Date: 1992/11/10 05:12:37 $
  218. X * Version: $Revision: 1.7 $
  219. X * Purpose:
  220. X *   This file sets up the menu structure.
  221. X *   The appearance is (approximately)
  222. X *
  223. X *    ~File    ~Goto      ~Help
  224. X *    ~New file Goto Home ~Application
  225. X *    ~New dir  Goto dir   Men~u
  226. X *    ~Close    Open Home ~Keyboard
  227. X *    ~Exit     Open dir   Mous~e
  228. X *
  229. X *   where the ~ gives some clue about the mnemonic
  230. X *
  231. X * Revision history:
  232. X *    4 Aug 92    filter menu added
  233. X *      25 Aug 92       fixed menonmics clash in Goto menu
  234. X *    16 Oct 92    caddr_t changed to XtPointer
  235. X *       3 Nov 92       lint-ed
  236. X ************************************************************************/ 
  237. X
  238. #include "copyright.h"
  239. X
  240. /*************************************************************************
  241. X * System includes
  242. X ************************************************************************/ 
  243. #include <stdio.h> 
  244. #include <string.h> 
  245. #include <Xm/CascadeB.h> 
  246. #include <Xm/PushB.h> 
  247. #include <Xm/RowColumn.h> 
  248. X
  249. /*************************************************************************
  250. X * Local includes
  251. X ************************************************************************/ 
  252. X
  253. /*************************************************************************
  254. X * Functions exported
  255. X ************************************************************************/ 
  256. extern    Widget CreateMenu (
  257. #ifdef UseFunctionPrototypes
  258. X    Widget parent, XtPointer user_data
  259. #endif
  260. );
  261. X
  262. /*************************************************************************
  263. X * Variables exported
  264. X ************************************************************************/ 
  265. X
  266. /*************************************************************************
  267. X * Extern variables
  268. X ************************************************************************/ 
  269. extern    char  help_applic_text[];
  270. extern    char  help_menu_text[];
  271. extern    char  help_mouse_text[];
  272. extern    char  help_keyboard_text[];
  273. extern  char  help_filter_text[];
  274. extern  char  help_bugs_text[];
  275. extern    char  help_about_text[];
  276. X
  277. /*************************************************************************
  278. X * Extern functions
  279. X ************************************************************************/ 
  280. /* File menu callbacks */
  281. extern void FileNewFileCB (
  282. #ifdef UseFunctionPrototypes
  283. X    Widget w, XtPointer client_data, XtPointer call_data
  284. #endif
  285. );
  286. extern void FileNewDirCB (
  287. #ifdef UseFunctionPrototypes
  288. X    Widget w, XtPointer client_data, XtPointer call_data
  289. #endif
  290. );
  291. extern void FileCopyCB (
  292. #ifdef UseFunctionPrototypes
  293. X    Widget w, XtPointer client_data, XtPointer call_data
  294. #endif
  295. );
  296. extern void FileMoveCB (
  297. #ifdef UseFunctionPrototypes
  298. X    Widget w, XtPointer client_data, XtPointer call_data
  299. #endif
  300. );
  301. extern void FileCloseCB (
  302. #ifdef UseFunctionPrototypes
  303. X    Widget w, XtPointer client_data, XtPointer call_data
  304. #endif
  305. );
  306. extern void FileExitCB (
  307. #ifdef UseFunctionPrototypes
  308. X    Widget w, XtPointer client_data, XtPointer call_data
  309. #endif
  310. );
  311. X
  312. /* help menu callbacks */
  313. extern void HelpCB (
  314. #ifdef UseFunctionPrototypes
  315. X    Widget w, XtPointer client_data, XtPointer call_data
  316. #endif
  317. );
  318. X
  319. /* goto menu callbacks */
  320. extern void GotoHomeCB (
  321. #ifdef UseFunctionPrototypes
  322. X    Widget w, XtPointer client_data, XtPointer call_data
  323. #endif
  324. );
  325. extern void GotoDirCB (
  326. #ifdef UseFunctionPrototypes
  327. X    Widget w, XtPointer client_data, XtPointer call_data
  328. #endif
  329. );
  330. extern void GotoOpenHomeCB (
  331. #ifdef UseFunctionPrototypes
  332. X    Widget w, XtPointer client_data, XtPointer call_data
  333. #endif
  334. );
  335. extern void GotoOpenDirCB (
  336. #ifdef UseFunctionPrototypes
  337. X    Widget w, XtPointer client_data, XtPointer call_data
  338. #endif
  339. );
  340. X
  341. /* run menu callbacks */
  342. extern void RunCommandCB (
  343. #ifdef UseFunctionPrototypes
  344. X    Widget w, XtPointer client_data, XtPointer call_data
  345. #endif
  346. );
  347. extern void RunXtermCB (
  348. #ifdef UseFunctionPrototypes
  349. X    Widget w, XtPointer client_data, XtPointer call_data
  350. #endif
  351. );
  352. X
  353. /* filter menu callbacks */
  354. extern void FilterFileCB (
  355. #ifdef UseFunctionPrototypes
  356. X    Widget w, XtPointer client_data, XtPointer call_data
  357. #endif
  358. );
  359. extern void FilterDirCB (
  360. #ifdef UseFunctionPrototypes
  361. X    Widget w, XtPointer client_data, XtPointer call_data
  362. #endif
  363. );
  364. extern void FilterExecutableCB (
  365. #ifdef UseFunctionPrototypes
  366. X    Widget w, XtPointer client_data, XtPointer call_data
  367. #endif
  368. );
  369. X
  370. /*************************************************************************
  371. X * Forward functions
  372. X ************************************************************************/ 
  373. static void    CreateFileSubMenu (
  374. #ifdef UseFunctionPrototypes
  375. X    Widget menu_bar, XtPointer user_data
  376. #endif
  377. );
  378. static void    CreateRunSubMenu (
  379. #ifdef UseFunctionPrototypes
  380. X    Widget menu_bar, XtPointer user_data
  381. #endif
  382. );
  383. static void    CreateHelpSubMenu (
  384. #ifdef UseFunctionPrototypes
  385. X    Widget parent, XtPointer user_data
  386. #endif
  387. );
  388. static void    CreateGotoSubMenu (
  389. #ifdef UseFunctionPrototypes
  390. X    Widget menu_bar, XtPointer user_data
  391. #endif
  392. );
  393. static void    CreateFilterSubMenu (
  394. #ifdef UseFunctionPrototypes
  395. X    Widget menu_bar, XtPointer user_data
  396. #endif
  397. );
  398. X
  399. /*************************************************************************
  400. X * Local variables
  401. X ************************************************************************/ 
  402. #define MAX_ARGS    128
  403. X
  404. /*************************************************************************
  405. X * Function:  CreatePulldownMenuButton ()
  406. X * Purpose:
  407. X *     creates a single button in a pulldown 
  408. X *     menu system
  409. X * In parameters: parent, name, label, accel_text, accelerator,
  410. X                  mnemonic, callback_func, client_data
  411. X * Function return: button in menu
  412. X * Precondition: parent is non-null, other fields null or valid args
  413. X * Postcondition: button created with fileds set if non-null
  414. X ************************************************************************/ 
  415. static Widget
  416. CreatePulldownMenuButton 
  417. #ifdef UseFunctionPrototypes
  418. X    (Widget parent, String name, String label, String accel_text, String accelerator, char mnemonic, void (*callback_func) (/* ??? */), XtPointer client_data, XtPointer user_data)
  419. #else
  420. X    (parent, name, label,
  421. X        accel_text, accelerator, mnemonic,
  422. X        callback_func, client_data,
  423. X        user_data)
  424. X    Widget    parent;
  425. X    String    name;
  426. X    String    label;
  427. X    String    accel_text;
  428. X    String    accelerator;
  429. X    char    mnemonic;
  430. X    void    (*callback_func) ();
  431. X    XtPointer    client_data;
  432. X    XtPointer user_data;
  433. X
  434. #endif
  435. {
  436. X    Arg    args[MAX_ARGS];
  437. X    int    n;
  438. X    XmString    xm_accel_text = NULL;
  439. X    XmString    xm_label = NULL;
  440. X    Widget    button;
  441. X
  442. X    n = 0; 
  443. X    if (label != NULL)
  444. X    {
  445. X        xm_label = XmStringCreateLtoR(label, XmSTRING_DEFAULT_CHARSET);
  446. X        XtSetArg (args[n], XmNlabelString, xm_label); n++;
  447. X    }
  448. X    button = XmCreatePushButton (parent, name, args, n); 
  449. X    XtManageChild (button); 
  450. X    XtAddCallback (button, XmNactivateCallback, 
  451. X            callback_func, client_data); 
  452. X
  453. X    /* if accelerator non-NULL and resource db hasn't set it, set it */
  454. X    if (accel_text != NULL)
  455. X    {
  456. X        n = 0;
  457. X        XtSetArg (args[n], XmNacceleratorText, &xm_accel_text); n++;
  458. X        XtGetValues (button, args, n);
  459. X        if (xm_accel_text == NULL)
  460. X        {
  461. X            xm_accel_text = XmStringCreateLtoR(accel_text, 
  462. X                        XmSTRING_DEFAULT_CHARSET);
  463. X            n = 0;
  464. X            XtSetArg (args[n], XmNacceleratorText, 
  465. X                        xm_accel_text); n++;
  466. X            XtSetArg (args[n], XmNaccelerator, accelerator); n++;
  467. X            XtSetValues (button, args, n);
  468. X        }
  469. X    }
  470. X    /* if mnemonic non-NULL and resource db hasn't set it, set it */
  471. X    if (mnemonic != 0)
  472. X    {    KeySym    mnemonic_sym;
  473. X
  474. X        n = 0;
  475. X        XtSetArg (args[n], XmNmnemonic, &mnemonic_sym); n++;
  476. X        XtGetValues (button, args, n);
  477. X        if (mnemonic_sym == 0)
  478. X        {
  479. X            n = 0;
  480. X            XtSetArg (args[n], XmNmnemonic, mnemonic); n++;
  481. X            XtSetValues (button, args, n);
  482. X        }
  483. X    }
  484. X
  485. X    if (user_data != NULL)
  486. X        XtVaSetValues (button,
  487. X                XmNuserData, (XtArgVal) user_data,
  488. X                NULL);
  489. X
  490. X    /* reclaim used string space */
  491. X    if (xm_accel_text != NULL)
  492. X        XmStringFree (xm_accel_text);
  493. X    if (xm_label != NULL)
  494. X        XmStringFree (xm_label);
  495. X
  496. X    return (button);
  497. }
  498. X
  499. /*------------------------------------------------------------- 
  500. **    CreateMenu    - create menu structure
  501. **
  502. **    Return the menu bar
  503. **
  504. **    What this lot creates is the following menu:
  505. **
  506. */ 
  507. X
  508. /*************************************************************************
  509. X * Function: CreateMenu ()
  510. X * Purpose: create the menu bar
  511. X * In parameters: parent
  512. X * Function return: menu bar widget unmanaged
  513. X * Precondition: parent non-null widget
  514. X * Postcondition: menu bar creted in unmanaged state, with all submenus
  515. X *                with associated callbacks created
  516. X ************************************************************************/ 
  517. Widget
  518. CreateMenu 
  519. #ifdef UseFunctionPrototypes
  520. X    (Widget parent, XtPointer user_data)
  521. #else
  522. X    (parent, user_data)  
  523. X    Widget    parent;        /*  parent widget    */ 
  524. X    XtPointer user_data;
  525. X
  526. #endif
  527. X    Widget        menu_bar;    /*  MenuBar        */ 
  528. X    Arg    args[MAX_ARGS];
  529. X    register int    n;        /*  arg count        */ 
  530. X    /*    Create MenuBar in MainWindow. 
  531. X    */ 
  532. X    n = 0; 
  533. X    menu_bar = XmCreateMenuBar (parent, "menu_bar", args, n);  
  534. X    XtManageChild (menu_bar); 
  535. #       ifdef DEBUG_MENU
  536. X                fprintf(stderr, "Created menu bar\n");
  537. #       endif
  538. X
  539. X
  540. X    /*    Create "File" PulldownMenu. 
  541. X    */ 
  542. X    CreateFileSubMenu(menu_bar, user_data);
  543. X
  544. #       ifdef DEBUG_MENU
  545. X                fprintf(stderr, "Created file menu\n");
  546. #       endif
  547. X
  548. X    /*    Create "Goto" menu. 
  549. X    */ 
  550. X    CreateGotoSubMenu(menu_bar, user_data);
  551. #       ifdef DEBUG_MENU
  552. X                fprintf(stderr, "Created goto menu\n");
  553. #       endif
  554. X
  555. X    /*    Create "Run" menu. 
  556. X    */ 
  557. X    CreateRunSubMenu(menu_bar, user_data);
  558. X
  559. X    /*    Create "Filter" menu. 
  560. X    */ 
  561. X    CreateFilterSubMenu(menu_bar, user_data);
  562. #       ifdef DEBUG_MENU
  563. X                fprintf(stderr, "Created run menu\n");
  564. #       endif
  565. X
  566. X    /*    Create "Help" menu. 
  567. X    */ 
  568. X    CreateHelpSubMenu(menu_bar, user_data);
  569. X
  570. #       ifdef DEBUG_MENU
  571. X                fprintf(stderr, "Created help menu\n");
  572. #       endif
  573. X
  574. X    return (menu_bar);
  575. X
  576. X
  577. /*************************************************************************
  578. X * Function: CreateFileSubMenu ()
  579. X * Purpose:
  580. X *    Create SubMenu to handle File Actions
  581. X * In parameters: menu_bar, user_data
  582. X * Out parameters:
  583. X * Precondition: menu_bar is non-null widget
  584. X * Postcondition: file menu added to menu_bar
  585. X ************************************************************************/ 
  586. static void
  587. CreateFileSubMenu 
  588. #ifdef UseFunctionPrototypes
  589. X    (Widget menu_bar, XtPointer user_data)
  590. #else
  591. X    (menu_bar, user_data)  
  592. X    Widget    menu_bar;        /*  parent widget    */ 
  593. X    XtPointer user_data;
  594. X
  595. #endif
  596. X    Widget        menu_pane;    /*  MenuPane        */ 
  597. X    Widget        cascade;    /*  CascadeButton    */ 
  598. X    Arg    args[MAX_ARGS];
  599. X    int    n;        /*  arg count        */ 
  600. X    /*    Create "File" PulldownMenu. 
  601. X    **    Names, accelerators and mnemonics are all set
  602. X    **    in the resource database before we get here.
  603. X    */ 
  604. X    n = 0; 
  605. X    menu_pane = XmCreatePulldownMenu (menu_bar, "menu_pane", args, n); 
  606. #    ifdef DEBUG_FILE
  607. X        fprintf (stderr, "Created file menu bar\n");
  608. #    endif
  609. X
  610. X    CreatePulldownMenuButton (menu_pane, "New file...", NULL,
  611. X            NULL, NULL, 'f',
  612. X            FileNewFileCB, NULL, user_data);
  613. X
  614. X    CreatePulldownMenuButton (menu_pane, "New dir", NULL,
  615. X            NULL, NULL, 'd',
  616. X            FileNewDirCB, NULL, user_data);
  617. X
  618. X    CreatePulldownMenuButton (menu_pane, "Copy...", NULL,
  619. X            NULL, NULL, 'C',
  620. X            FileCopyCB, NULL, user_data);
  621. X
  622. X    CreatePulldownMenuButton (menu_pane, "Move...", NULL,
  623. X            NULL, NULL, 'M',
  624. X            FileMoveCB, NULL, user_data);
  625. X
  626. X    CreatePulldownMenuButton (menu_pane, "Close", NULL,
  627. X            "Ctrl+F4", "Ctrl<Key>F4", 'l',
  628. X            FileCloseCB, NULL, user_data);
  629. X
  630. X    CreatePulldownMenuButton (menu_pane, "Exit", NULL,
  631. X            "Meta+F4", "Meta<Key>F4", 'x',
  632. X            FileExitCB, NULL, user_data);
  633. X    n = 0; 
  634. X    XtSetArg (args[n], XmNsubMenuId, menu_pane);  n++; 
  635. X        XtSetArg (args[n], XmNmnemonic, 'F'); n++;
  636. X    cascade = XmCreateCascadeButton (menu_bar, "File", args, n); 
  637. X    XtManageChild (cascade); 
  638. }
  639. X
  640. /*************************************************************************
  641. X * Function: CreateGotoSubMenu ()
  642. X * Purpose:
  643. X *    Create SubMenu to handle Goto Actions
  644. X * In parameters: menu_bar
  645. X * Out parameters:
  646. X * Precondition: menu_bar is non-null widget
  647. X * Postcondition: file menu added to menu_bar
  648. X ************************************************************************/ 
  649. static void
  650. CreateGotoSubMenu 
  651. #ifdef UseFunctionPrototypes
  652. X    (Widget menu_bar, XtPointer user_data)
  653. #else
  654. X    (menu_bar, user_data)  
  655. X    Widget    menu_bar;        /*  parent widget    */ 
  656. X    XtPointer user_data;
  657. X
  658. #endif
  659. X    Widget        menu_pane;    /*  MenuPane        */ 
  660. X    Widget        cascade;    /*  CascadeButton    */ 
  661. X    Arg    args[MAX_ARGS];
  662. X    int    n;        /*  arg count        */ 
  663. X    /*    Create "Goto" PulldownMenu. 
  664. X    **    Names, accelerators and mnemonics are all set
  665. X    **    in the resource database before we get here.
  666. X    */ 
  667. X    n = 0; 
  668. X    menu_pane = XmCreatePulldownMenu (menu_bar, "menu_pane", args, n); 
  669. #    ifdef DEBUG_FILE
  670. X        fprintf (stderr, "Created Goto menu bar\n");
  671. #    endif
  672. X
  673. X    CreatePulldownMenuButton (menu_pane, "Chdir Home", NULL,
  674. X            "Meta+H", "Meta<Key>H", 'H',
  675. X            GotoHomeCB, NULL, user_data);
  676. X
  677. X    CreatePulldownMenuButton (menu_pane, "Chdir Directory...", NULL,
  678. X            "Meta+D", "Meta<Key>D", 'D',
  679. X            GotoDirCB, NULL, user_data);
  680. X
  681. X    CreatePulldownMenuButton (menu_pane, "Open Home", NULL,
  682. X            "Ctrl+H", "Ctrl<Key>H", 'o',
  683. X            GotoOpenHomeCB, NULL, user_data);
  684. X
  685. X    CreatePulldownMenuButton (menu_pane, "Open Directory...", NULL,
  686. X            "Ctrl+D", "Ctrl<Key>D", 'i',
  687. X            GotoOpenDirCB, NULL, user_data);
  688. X    n = 0; 
  689. X    XtSetArg (args[n], XmNsubMenuId, menu_pane);  n++; 
  690. X        XtSetArg (args[n], XmNmnemonic, 'G'); n++;
  691. X    cascade = XmCreateCascadeButton (menu_bar, "Goto", args, n); 
  692. X    XtManageChild (cascade); 
  693. }
  694. X
  695. X
  696. /*************************************************************************
  697. X * Function: CreateFilterSubMenu ()
  698. X * Purpose:
  699. X *    Create SubMenu to handle Filter Actions
  700. X * In parameters: menu_bar
  701. X * Out parameters:
  702. X * Precondition: menu_bar is non-null widget
  703. X * Postcondition: filter menu added to menu_bar
  704. X ************************************************************************/ 
  705. static void
  706. CreateFilterSubMenu 
  707. #ifdef UseFunctionPrototypes
  708. X    (Widget menu_bar, XtPointer user_data)
  709. #else
  710. X    (menu_bar, user_data)  
  711. X    Widget    menu_bar;        /*  parent widget    */ 
  712. X    XtPointer user_data;
  713. X
  714. #endif
  715. X    Widget        menu_pane;    /*  MenuPane        */ 
  716. X    Widget        cascade;    /*  CascadeButton    */ 
  717. X    Arg    args[MAX_ARGS];
  718. X    int    n;        /*  arg count        */ 
  719. X    /*    Create "Filter" PulldownMenu. 
  720. X    **    Names, accelerators and mnemonics are all set
  721. X    **    in the resource database before we get here.
  722. X    */ 
  723. X    n = 0; 
  724. X    menu_pane = XmCreatePulldownMenu (menu_bar, "menu_pane", args, n); 
  725. #    ifdef DEBUG_FILE
  726. X        fprintf (stderr, "Created Filter menu bar\n");
  727. #    endif
  728. X
  729. X    CreatePulldownMenuButton (menu_pane, "Files", NULL,
  730. X            NULL, NULL, 'F',
  731. X            FilterFileCB, NULL, user_data);
  732. X
  733. X    CreatePulldownMenuButton (menu_pane, "Executables", NULL,
  734. X            NULL, NULL, 'E',
  735. X            FilterExecutableCB, NULL, user_data);
  736. X
  737. X    CreatePulldownMenuButton (menu_pane, "Directories", NULL,
  738. X            NULL, NULL, 'D',
  739. X            FilterDirCB, NULL, user_data);
  740. X    n = 0; 
  741. X    XtSetArg (args[n], XmNsubMenuId, menu_pane);  n++; 
  742. X        XtSetArg (args[n], XmNmnemonic, 'i'); n++;
  743. X    cascade = XmCreateCascadeButton (menu_bar, "Filter", args, n); 
  744. X    XtManageChild (cascade); 
  745. }
  746. X
  747. X
  748. /*************************************************************************
  749. X * Function: CreateRunSubMenu ()
  750. X * Purpose:
  751. X *    Create SubMenu to handle Run Actions
  752. X * In parameters: menu_bar
  753. X * Out parameters:
  754. X * Precondition: menu_bar is non-null widget
  755. X * Postcondition: run menu added to menu_bar
  756. X ************************************************************************/ 
  757. static void
  758. CreateRunSubMenu 
  759. #ifdef UseFunctionPrototypes
  760. X    (Widget menu_bar, XtPointer user_data)
  761. #else
  762. X    (menu_bar, user_data)  
  763. X    Widget    menu_bar;        /*  parent widget    */ 
  764. X    XtPointer user_data;
  765. X
  766. #endif
  767. X    Widget        menu_pane;    /*  MenuPane        */ 
  768. X    Widget        cascade;    /*  CascadeButton    */ 
  769. X    Arg    args[MAX_ARGS];
  770. X    int    n;        /*  arg count        */ 
  771. X    /*    Create "Goto" PulldownMenu. 
  772. X    **    Names, accelerators and mnemonics are all set
  773. X    **    in the resource database before we get here.
  774. X    */ 
  775. X    n = 0; 
  776. X    menu_pane = XmCreatePulldownMenu (menu_bar, "menu_pane", args, n); 
  777. #    ifdef DEBUG_FILE
  778. X        fprintf (stderr, "Created Run menu bar\n");
  779. #    endif
  780. X
  781. X    CreatePulldownMenuButton (menu_pane, "Command...", NULL,
  782. X            "Meta+C", "Meta<Key>C", 'C',
  783. X            RunCommandCB, NULL, user_data);
  784. X
  785. X    CreatePulldownMenuButton (menu_pane, "Xterm", NULL,
  786. X            "Meta+X", "Meta<Key>X", 'X',
  787. X            RunXtermCB, NULL, user_data);
  788. X    n = 0; 
  789. X    XtSetArg (args[n], XmNsubMenuId, menu_pane);  n++; 
  790. X        XtSetArg (args[n], XmNmnemonic, 'R'); n++;
  791. X    cascade = XmCreateCascadeButton (menu_bar, "Run", args, n); 
  792. X    XtManageChild (cascade); 
  793. }
  794. X
  795. /*************************************************************************
  796. X * Function: CreateHelpSubMenu ()
  797. X * Purpose: create the help pulldown menu
  798. X * In parameters: parent
  799. X * Out parameters:
  800. X * Precondition: parent is non-null widget
  801. X * Postcondition: help pulldown menu added to parent,
  802. X *                with all callbacks in place
  803. X ************************************************************************/ 
  804. static void
  805. CreateHelpSubMenu 
  806. #ifdef UseFunctionPrototypes
  807. X    (Widget parent, XtPointer user_data)
  808. #else
  809. X    (parent, user_data)
  810. X    Widget    parent;
  811. X    XtPointer user_data;
  812. X
  813. #endif
  814. {
  815. X    Widget    menu_pane;
  816. X    Widget    cascade;
  817. X    Arg    args[MAX_ARGS];
  818. X    int    n;
  819. X    
  820. X    n = 0;
  821. X    menu_pane = XmCreatePulldownMenu (parent, "menu_pane", args, n); 
  822. X    CreatePulldownMenuButton (menu_pane, "XmFm", NULL,
  823. X            NULL, NULL, 'X',
  824. X            HelpCB, help_applic_text, user_data);
  825. X
  826. X    CreatePulldownMenuButton (menu_pane, "Mouse", NULL,
  827. X            NULL, NULL, 'M',
  828. X            HelpCB, help_mouse_text, user_data);
  829. X
  830. X    CreatePulldownMenuButton (menu_pane, "Keyboard", NULL,
  831. X            NULL, NULL, 'K',
  832. X            HelpCB, help_keyboard_text, user_data);
  833. X
  834. X    CreatePulldownMenuButton (menu_pane, "Filters", NULL,
  835. X            NULL, NULL, 'F',
  836. X            HelpCB, help_filter_text, user_data);
  837. X
  838. X    CreatePulldownMenuButton (menu_pane, "Bugs", NULL,
  839. X            NULL, NULL, 'B',
  840. X            HelpCB, help_bugs_text, user_data);
  841. X
  842. X    CreatePulldownMenuButton (menu_pane, "About", NULL,
  843. X            NULL, NULL, 'A',
  844. X            HelpCB, help_about_text, user_data);
  845. X    n = 0; 
  846. X    XtSetArg (args[n], XmNsubMenuId, menu_pane);  n++; 
  847. X    XtSetArg (args[n], XmNmnemonic, 'p'); n++;
  848. X    cascade = XmCreateCascadeButton (parent, "Help", args, n); 
  849. X    XtManageChild (cascade); 
  850. X    n = 0; 
  851. X    XtSetArg (args[n], XmNmenuHelpWidget, cascade);  n++; 
  852. X    XtSetValues (parent, args, n); 
  853. }
  854. SHAR_EOF
  855. chmod 0644 xmfm/menu.c ||
  856. echo 'restore of xmfm/menu.c failed'
  857. Wc_c="`wc -c < 'xmfm/menu.c'`"
  858. test 18186 -eq "$Wc_c" ||
  859.     echo 'xmfm/menu.c: original size 18186, current size' "$Wc_c"
  860. rm -f _shar_wnt_.tmp
  861. fi
  862. # ============= xmfm/prompt.c ==============
  863. if test -f 'xmfm/prompt.c' -a X"$1" != X"-c"; then
  864.     echo 'x - skipping xmfm/prompt.c (File already exists)'
  865.     rm -f _shar_wnt_.tmp
  866. else
  867. > _shar_wnt_.tmp
  868. echo 'x - extracting xmfm/prompt.c (Text)'
  869. sed 's/^X//' << 'SHAR_EOF' > 'xmfm/prompt.c' &&
  870. /*************************************************************************
  871. X * File: $Source: /usr/usrs/xsource/xmfm/RCS/prompt.c,v $
  872. X * Author: Jan Newmarch
  873. X * Last modified: $Date: 1992/11/17 00:35:51 $
  874. X * Version: $Revision: 1.6 $
  875. X * Purpose:
  876. X *          and calls the Xt main loop.
  877. X *
  878. X * Revision history:
  879. X *    16 Oct 92    caddr_t changed to XtPointer
  880. X ************************************************************************/ 
  881. X
  882. #include "copyright.h"
  883. X
  884. /*************************************************************************
  885. X * System includes
  886. X ************************************************************************/ 
  887. #include <stdio.h> 
  888. #include <string.h> 
  889. #include <sys/types.h> 
  890. #include <sys/stat.h> 
  891. #include <Xm/MainW.h> 
  892. #include <Xm/MessageB.h> 
  893. #include <Xm/SelectioB.h>
  894. X
  895. /*************************************************************************
  896. X * Local includes
  897. X ************************************************************************/ 
  898. #include "const.h"
  899. #include "types.h"
  900. X
  901. /*************************************************************************
  902. X * Functions exported
  903. X ************************************************************************/ 
  904. extern void PromptDialog (
  905. #ifdef UseFunctionPrototypes
  906. X    Widget parent, char *prompt, int modal, char **answer
  907. #endif
  908. );
  909. X
  910. /*************************************************************************
  911. X * Variables exported
  912. X ************************************************************************/ 
  913. X
  914. /*************************************************************************
  915. X * Extern variables
  916. X ************************************************************************/ 
  917. extern XtAppContext app_context;
  918. X
  919. /*************************************************************************
  920. X * Extern functions
  921. X ************************************************************************/ 
  922. X
  923. /*************************************************************************
  924. X * Forward functions
  925. X ************************************************************************/ 
  926. X
  927. /*************************************************************************
  928. X * Local variables
  929. X ************************************************************************/ 
  930. static Bool dialog_over;
  931. X
  932. /*************************************************************************
  933. X * Function: modal_dialog_loop ()
  934. X * Purpose: 
  935. X * In parameters:
  936. X * Out parameters:
  937. X * Side effects: modifies dialog_over
  938. X * Precondition: 
  939. X * Postcondition:
  940. X ************************************************************************/ 
  941. static void
  942. modal_dialog_loop 
  943. #ifdef UseFunctionPrototypes
  944. X    (Widget w)
  945. #else
  946. X    (w)
  947. X    Widget w;
  948. X
  949. #endif
  950. {
  951. X    dialog_over = False;
  952. X    XtVaSetValues (w,
  953. X            XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
  954. X            NULL);
  955. X    XtManageChild (w);
  956. X    while (dialog_over == False)
  957. X        XtAppProcessEvent (app_context, XtIMAll);
  958. }
  959. X
  960. /*************************************************************************
  961. X * Function: OkDialogCB ()
  962. X * Purpose: handle the dialog OK button
  963. X * In parameters: w, c2
  964. X * Out parameters: answer
  965. X * Precondition: w is a child of a popup shell
  966. X * Postcondition: parent on down all destroyed, text field first copied
  967. X ************************************************************************/ 
  968. X
  969. /* ARGSUSED */
  970. static void
  971. OkDialogCB
  972. #ifdef UseFunctionPrototypes
  973. X    (Widget w, XtPointer client_data, XtPointer c2)
  974. #else
  975. X    (w, client_data, c2)
  976. X    Widget w;
  977. X    XtPointer client_data;
  978. X    XtPointer  c2;
  979. X
  980. #endif
  981. {
  982. X    char ** answer = (char **) client_data;
  983. X    XmString xmstr;
  984. X
  985. X    XtVaGetValues (w, XmNtextString, &xmstr, NULL);
  986. X    /* decode the xmstr */
  987. X    /* this should be replaced by code that does not use obsoleted
  988. X       XmSTRING_DEFAULT_CHARSET */
  989. X    XmStringGetLtoR (xmstr, XmSTRING_DEFAULT_CHARSET, answer);
  990. X    XmStringFree (xmstr);
  991. X
  992. X    dialog_over = True;
  993. X
  994. X    XtUnmanageChild (w);
  995. X    XtDestroyWidget (XtParent (w));
  996. }
  997. X
  998. /*************************************************************************
  999. X * Function: CancelDialogCB ()
  1000. X * Purpose: handle the dialog Cancel button
  1001. X * In parameters: w, c2
  1002. X * Out parameters: answer
  1003. X * Precondition: w is a child of a popup shell
  1004. X * Postcondition: parent on down all destroyed, anser set to NULL
  1005. X ************************************************************************/ 
  1006. X
  1007. /* ARGSUSED */
  1008. static void
  1009. CancelDialogCB
  1010. #ifdef UseFunctionPrototypes
  1011. X    (Widget w, XtPointer client_data, XtPointer c2)
  1012. #else
  1013. X    (w, client_data, c2)
  1014. X    Widget w;
  1015. X    XtPointer client_data;
  1016. X    XtPointer  c2;
  1017. X
  1018. #endif
  1019. {
  1020. X    char ** answer = (char **) client_data;
  1021. X
  1022. X    *answer = NULL;
  1023. X
  1024. X    dialog_over = True;
  1025. X
  1026. X    XtUnmanageChild (w);
  1027. X    XtDestroyWidget (XtParent (w));
  1028. }
  1029. X
  1030. /*************************************************************************
  1031. X * Function: PromptDialog ()
  1032. X * Purpose: show a prompt dialog, and find the prompted string
  1033. X * In parameters: parent, prompt, modal
  1034. X * Out parameters: answer 
  1035. X * Precondition: 
  1036. X * Postcondition: 
  1037. X ************************************************************************/ 
  1038. void
  1039. PromptDialog
  1040. #ifdef UseFunctionPrototypes
  1041. X    (Widget parent, char *prompt, int modal, char **answer)
  1042. #else
  1043. X    (parent, prompt, modal, answer)
  1044. X    Widget parent;
  1045. X    char * prompt;
  1046. X    Bool modal;
  1047. X    char ** answer;
  1048. X
  1049. #endif
  1050. {    int n;
  1051. X    Arg    args[MAX_ARGS];
  1052. X    Widget help, dialog;
  1053. X    XmString xmstr;
  1054. X
  1055. X    n = 0;
  1056. X    xmstr = XmStringCreateSimple (prompt);
  1057. X    XtSetArg (args[n], XmNselectionLabelString, xmstr); n++;
  1058. X    dialog = XmCreatePromptDialog(parent, prompt, args, n);
  1059. X    XmStringFree(xmstr);
  1060. X
  1061. X    XtAddCallback(dialog, XmNokCallback, OkDialogCB, (XtPointer) answer);
  1062. X    XtAddCallback(dialog, XmNcancelCallback, CancelDialogCB, (XtPointer) answer);
  1063. X
  1064. X    help = XmSelectionBoxGetChild(dialog, 
  1065. X            XmDIALOG_HELP_BUTTON);
  1066. X    XtUnmanageChild(help);
  1067. X
  1068. X    /* set keyboard focus to text field */
  1069. X    XmProcessTraversal (XmSelectionBoxGetChild (dialog,
  1070. X                        XmDIALOG_TEXT),
  1071. X                XmTRAVERSE_CURRENT);
  1072. X    XmProcessTraversal (XmSelectionBoxGetChild (dialog,
  1073. X                        XmDIALOG_TEXT),
  1074. X                XmTRAVERSE_CURRENT);
  1075. X    XmProcessTraversal (XmSelectionBoxGetChild (dialog,
  1076. X                        XmDIALOG_TEXT),
  1077. X                XmTRAVERSE_CURRENT);
  1078. X
  1079. X    if (modal)
  1080. X        modal_dialog_loop(dialog);
  1081. }
  1082. SHAR_EOF
  1083. chmod 0644 xmfm/prompt.c ||
  1084. echo 'restore of xmfm/prompt.c failed'
  1085. Wc_c="`wc -c < 'xmfm/prompt.c'`"
  1086. test 5990 -eq "$Wc_c" ||
  1087.     echo 'xmfm/prompt.c: original size 5990, current size' "$Wc_c"
  1088. rm -f _shar_wnt_.tmp
  1089. fi
  1090. # ============= xmfm/rdd.c ==============
  1091. if test -f 'xmfm/rdd.c' -a X"$1" != X"-c"; then
  1092.     echo 'x - skipping xmfm/rdd.c (File already exists)'
  1093.     rm -f _shar_wnt_.tmp
  1094. else
  1095. > _shar_wnt_.tmp
  1096. echo 'x - extracting xmfm/rdd.c (Text)'
  1097. sed 's/^X//' << 'SHAR_EOF' > 'xmfm/rdd.c' &&
  1098. /*                               -*- Mode: C -*- 
  1099. X * rdd.c
  1100. X * 
  1101. X * Description     :  Roger's Drag 'n Drop Library.
  1102. X *                       A drag-n-drop library for Xt programs.
  1103. X * 
  1104. X * Author          : Roger Reynolds     -     rogerr@netcom.com
  1105. X * Created On      : Sun Apr 26 14:14:01 1992
  1106. X * 
  1107. X * Configuration Management
  1108. X * 
  1109. X * @(#)rdd.c    1.10    10/5/92
  1110. X * 
  1111. X * VERSION   SPR   MODIFIER   DATE AND TIME
  1112. X * 1.10      0     rogerr     Mon Oct  5 14:34:36 1992
  1113. X *           more gcc stuff. 
  1114. X * 1.9       0     rogerr     Tue Sep 29 11:41:27 1992
  1115. X *           GCC2.2.2 clean up. Can now be cleanly compiled without 
  1116. X *           -traditional. 
  1117. X * 1.8       0     rogerr     Wed Sep 23 14:10:56 1992
  1118. X *           use debug.h which defines DEBUGRDD TRACE and XtFree macros 
  1119. X * 1.7       0     rogerr     Thu Aug 27 15:06:39 1992
  1120. X *           added rddDragButton 
  1121. X * 1.6       0     rogerr     Mon Aug 17 15:51:33 1992
  1122. X *           additional example functionality 
  1123. X * 1.5       0     rogerr     Tue Jul 28 16:11:38 1992
  1124. X *           more ansi mumbo jumbo 
  1125. X * 1.4       0     rogerr     Wed Jul 15 14:49:27 1992
  1126. X *           send keymask in RddCallbackStruct so dropee knows what was 
  1127. X *           going on 
  1128. X * 1.3       0     rogerr     Fri Jun 26 16:16:58 1992
  1129. X *           deleteDropHandler as widget destroy callback 
  1130. X * 1.2       0     rogerr     Tue Jun 23 17:08:58 1992
  1131. X *           now dragging pixmaps around 
  1132. X * 
  1133. X */
  1134. X
  1135. #include <stdio.h>
  1136. #include <X11/Xatom.h>
  1137. #include <X11/Intrinsic.h>
  1138. #include <X11/cursorfont.h>
  1139. #include <X11/StringDefs.h>
  1140. X
  1141. #include <rdd.h>
  1142. X
  1143. /*
  1144. X *  Private variables containing bits of current state 
  1145. X */
  1146. static Widget topLevel;
  1147. static XtAppContext appContext;
  1148. static Display *display;
  1149. static Atom rddProtocolMsg;
  1150. static Atom rddSelnAtom;
  1151. static Cursor dragCursor;
  1152. static Pixmap dragPixmap, savePixmap;
  1153. static int    pixmapwid, pixmaphgt, xcursoff, ycursoff;
  1154. static Window getPointerWindow();
  1155. static int rddDataType;
  1156. static GC  dragGC;
  1157. /*
  1158. X *  Is this event an rdd drop message? 
  1159. X */
  1160. #define rddIsRddMessageEvent(ev)\
  1161. X    ((ev).type == ClientMessage && (ev).xclient.message_type == rddProtocolMsg)
  1162. X
  1163. X
  1164. /*
  1165. X * Data structure describing a "drop event handler" 
  1166. X */
  1167. typedef struct 
  1168. {
  1169. X    XtCallbackProc proc;
  1170. X    char *data;
  1171. X    Widget w;
  1172. X    Boolean active;
  1173. } HandlerData;
  1174. X
  1175. /*
  1176. X * Internal list of all drop handlers 
  1177. X */
  1178. static HandlerData *handlerList;
  1179. static int handlerListCnt, handlerListAllocCnt;
  1180. X
  1181. /*
  1182. X * Action routines which changes the cursor when appropriate and begin
  1183. X * the drag-n-drop process.
  1184. X * They could be bound directly to btndown, btnmotion, and btnup events,
  1185. X * but to do anything useful, rddSetDropData must be called someplace.
  1186. X */
  1187. static int bx, by, dragflag;
  1188. X
  1189. void
  1190. rddStartAction (w, event, args, nargs)
  1191. X    Widget w;
  1192. X    XButtonEvent *event;
  1193. X    String *args;
  1194. X    int *nargs;
  1195. {
  1196. X    dragflag = 0;
  1197. X    bx = event->x;
  1198. X    by = event->y;
  1199. X    xcursoff = 0;
  1200. X    ycursoff = 0;
  1201. X    DEBUGRDD (fprintf(stderr, "rddStartAction at %d,%d\n", bx, by););
  1202. }
  1203. X
  1204. void
  1205. rddDragAction (w, event, args, nargs)
  1206. X    Widget w;
  1207. X    XButtonEvent *event;
  1208. X    String *args;
  1209. X    int *nargs;
  1210. {
  1211. X    DEBUGRDD (fprintf(stderr, "rddDragAction\n"););
  1212. X    if (dragflag == 0 && ((abs(bx - event->x)) > 10 ||
  1213. X                          (abs(by - event->y)) > 10))
  1214. X    {
  1215. X        DEBUGRDD (fprintf(stderr, "using drag cursor %d\n", dragCursor););
  1216. X        dragflag = 1;
  1217. X        if (dragCursor)
  1218. X            XDefineCursor (XtDisplay(w), XtWindow(w), dragCursor);
  1219. X
  1220. X        if (dragPixmap&&savePixmap)
  1221. X            XCopyArea (display, RootWindow(display,0), savePixmap, dragGC,
  1222. X                       bx=event->x_root-xcursoff, by=event->y_root-ycursoff,
  1223. X                       pixmapwid, pixmaphgt,
  1224. X                       0, 0);
  1225. X    }
  1226. X
  1227. X    if (0)
  1228. X    {
  1229. X        u_int state;
  1230. X        Window child, root;
  1231. X        int x, y;
  1232. X        XQueryPointer (display, RootWindow(display,0), &root, &child,
  1233. X                       &x, &y, &x, &y, &state);
  1234. X        DEBUGRDD (fprintf (stderr, "pointer root = 0x%x win 0x%x, state = 0x%x\n",
  1235. X                        root, child, state););
  1236. X    }
  1237. X
  1238. X    if (dragflag && dragPixmap && savePixmap)
  1239. X    {
  1240. X        XCopyArea (display, savePixmap, RootWindow(display,0), dragGC,
  1241. X                   0, 0, pixmapwid, pixmaphgt, bx, by);
  1242. X
  1243. X        XCopyArea (display, RootWindow(display,0), savePixmap, dragGC,
  1244. X                   bx=event->x_root-xcursoff, by=event->y_root-ycursoff,
  1245. X                   pixmapwid, pixmaphgt,
  1246. X                   0, 0);
  1247. X
  1248. X        XCopyArea (display, dragPixmap, RootWindow(display,0), dragGC,
  1249. X                   0, 0, pixmapwid, pixmaphgt, bx, by);
  1250. X    }
  1251. }
  1252. X    
  1253. void
  1254. rddDropAction (w, event, args, nargs)
  1255. X    Widget w;
  1256. X    XButtonEvent *event;
  1257. X    String *args;
  1258. X    int *nargs;
  1259. {
  1260. X    DEBUGRDD (fprintf(stderr, "rddDropAction\n"););
  1261. X    if (dragflag == 1)
  1262. X    {
  1263. X        XUndefineCursor (display, XtWindow(w));
  1264. X        rddSendDropEvent(w, (XEvent*)event);
  1265. X
  1266. X        if (savePixmap)
  1267. X        {
  1268. X            XCopyArea (display, savePixmap, RootWindow(display,0), dragGC,
  1269. X                       0, 0, pixmapwid, pixmaphgt, bx, by);
  1270. X        }
  1271. X    }
  1272. }
  1273. X
  1274. X
  1275. /*
  1276. X * Install this as a callback on something like a push button, and
  1277. X * you get a button which starts a drag, with the next click sending
  1278. X * the drop event.  You might want to get in first and install a
  1279. X * drag pixmap...
  1280. X * NOTE: This is the only routine in rdd which assumes Motif.
  1281. X * If you aren't using motif, then you may need to remove or edit this
  1282. X * function...
  1283. X */
  1284. void
  1285. rddDragCallback(w, client_data, cbs)
  1286. X    Widget w;
  1287. X    XtPointer client_data;
  1288. X    XmAnyCallbackStruct *cbs;
  1289. {
  1290. X    XEvent event;
  1291. X    XtAppContext app = XtWidgetToApplicationContext(w);
  1292. X    int x, y;
  1293. X    DEBUGRDD (fprintf(stderr, "rddDragCallback: w = 0x%x\n",
  1294. X                   cbs->event->xany.window););
  1295. X
  1296. X    /* Make the pointer look like it moved some */
  1297. X    x = cbs->event->xbutton.x;
  1298. X    cbs->event->xbutton.x += 100;
  1299. X    y = cbs->event->xbutton.y;
  1300. X    cbs->event->xbutton.y += 100;
  1301. X    rddStartAction(w, (XButtonEvent*)cbs->event, NULL, 0);
  1302. X
  1303. X    /* Then back again */
  1304. X    cbs->event->xbutton.x = x;
  1305. X    cbs->event->xbutton.y = y;
  1306. X    rddDragAction(w, (XButtonEvent*)cbs->event, NULL, 0);
  1307. X
  1308. X
  1309. X    /* Grab the pointer and start an event loop */
  1310. X    XGrabPointer (XtDisplay(w), cbs->event->xbutton.window, True,
  1311. X                  PointerMotionMask | ButtonReleaseMask,
  1312. X                  GrabModeAsync, GrabModeAsync, None, None, 
  1313. X                  cbs->event->xbutton.time);
  1314. X    for (;;)
  1315. X    {
  1316. X        XtAppNextEvent(app, &event);
  1317. X
  1318. X        XtDispatchEvent(&event);
  1319. X        if (event.type == ButtonRelease)
  1320. X        {
  1321. X            /* Done, release pointer and send drop event */
  1322. X            XUngrabPointer (XtDisplay(w), event.xbutton.time);
  1323. X            rddDropAction (w, (XButtonEvent*)&event, NULL, 0);
  1324. X            break;
  1325. X        }
  1326. X        else if (event.type == MotionNotify)
  1327. X        {
  1328. X            /* drag me */
  1329. X            rddDragAction (w, (XButtonEvent*)&event, NULL, 0);
  1330. X        }
  1331. X    }
  1332. X    DEBUGRDD (fprintf (stderr, "out of rddDragCallback\n"););
  1333. }
  1334. X
  1335. /*
  1336. X *  rddInit - 
  1337. X *         Initialize the rdd package.    This routine must be called before
  1338. X *         any other rdd routines.
  1339. X *             Initialize static data,
  1340. X *             Create rdd protocol atoms.
  1341. X *             Create default cursor used for drag operations.
  1342. X *             Register rdd actions.
  1343. X */
  1344. void
  1345. rddInit(shell, context)
  1346. X    Widget shell;
  1347. X    XtAppContext context;
  1348. {
  1349. X    /* Should NOT need to CAST here!*/
  1350. X    static XtActionsRec actions[3] = {
  1351. X            "rddStartAction",   (XtActionProc)rddStartAction,
  1352. X            "rddDragAction",    (XtActionProc)rddDragAction,
  1353. X            "rddDropAction",    (XtActionProc)rddDropAction,
  1354. X    };
  1355. X
  1356. X    DEBUGRDD (fprintf(stderr, "rddInit entered\n"););
  1357. X
  1358. X    topLevel        = shell;
  1359. X    appContext        = context;
  1360. X    display            = XtDisplay(topLevel);
  1361. X    rddProtocolMsg    = XInternAtom (display, "RDD_MESSAGE", FALSE);
  1362. X    rddSelnAtom        = XInternAtom (display, "RDD_SELECTION", FALSE);
  1363. X    dragCursor         = XCreateFontCursor (display, XC_cross);
  1364. X
  1365. X    {
  1366. X        XGCValues gcv;
  1367. X        XtGCMask  mask;
  1368. X        
  1369. X        mask =GCSubwindowMode;
  1370. X        gcv.subwindow_mode = IncludeInferiors;
  1371. X        dragGC    = XCreateGC (display, RootWindow(display,0), mask, &gcv);
  1372. X    }
  1373. X    
  1374. X    XtAppAddActions (context, actions, XtNumber(actions));
  1375. X
  1376. X    DEBUGRDD (fprintf (stderr,"rddInit: topLevel=%d display=%d\n",
  1377. X                    topLevel, display););
  1378. }
  1379. X
  1380. /*
  1381. X * rddSetDragCursor - 
  1382. X *         Set the cursor that will be used for drag-n-drop operations.
  1383. X */
  1384. void
  1385. rddSetDragCursor (cursor)
  1386. X    Cursor cursor;
  1387. X
  1388. {
  1389. X    dragCursor = cursor;
  1390. }
  1391. X
  1392. /*
  1393. X * rddSetDragPixmap - 
  1394. X *         Set the cursor that will be used for drag-n-drop operations.
  1395. X */
  1396. void
  1397. rddSetDragPixmap (pixmap, wid, hgt)
  1398. X    Pixmap pixmap;
  1399. X    int wid, hgt;
  1400. {
  1401. X    if (savePixmap && (pixmapwid != wid || pixmaphgt != hgt))
  1402. X    {
  1403. X        XFreePixmap(display, savePixmap);
  1404. X        savePixmap = 0;
  1405. X    }
  1406. X    if (!savePixmap)
  1407. X    {
  1408. X        savePixmap = XCreatePixmap (display, RootWindow(display,0), 
  1409. X                                    pixmapwid = wid, pixmaphgt = hgt,
  1410. X                                    XDefaultDepth(display,0));
  1411. X    }
  1412. X    DEBUGRDD (fprintf (stderr, "savePixmap = %d wid=%d hgt=%d\n",
  1413. X                    savePixmap, pixmapwid, pixmaphgt););
  1414. X    dragPixmap = pixmap;
  1415. }
  1416. X
  1417. void rddSetDragCursorOffset(x,y)
  1418. X    int x,y;
  1419. {
  1420. X    xcursoff = x;
  1421. X    ycursoff = y;
  1422. }
  1423. X
  1424. /*
  1425. X *  rddInitCheck - 
  1426. X *         Ensure that rdd has been initialized.
  1427. X */
  1428. static void
  1429. rddInitCheck()
  1430. {
  1431. X    if (!topLevel)
  1432. X    {
  1433. X        fprintf (stderr, "rdd not initialized\n");
  1434. X        exit(-1);
  1435. X    }
  1436. }
  1437. X
  1438. /*
  1439. X *  These routines coordinate access to the rddSelection 
  1440. X */
  1441. X
  1442. static unsigned char *rddSelnData;
  1443. static unsigned long rddSelnLen;
  1444. X
  1445. X
  1446. static int 
  1447. rddSetSelection(data, nbytes)
  1448. X    caddr_t data;
  1449. X    int nbytes;
  1450. {
  1451. X    int stat;
  1452. X    Window window;
  1453. X
  1454. X    rddInitCheck();
  1455. X
  1456. X    window = XtWindow(topLevel);
  1457. X
  1458. X    XSetSelectionOwner (display, rddSelnAtom, window, CurrentTime);
  1459. X
  1460. X    if (XGetSelectionOwner (display, rddSelnAtom) != window)
  1461. X    {
  1462. X        fprintf (stderr, "XSetSelectionOwner failed\n");
  1463. X    }
  1464. X
  1465. X    if (rddSelnLen)
  1466. X    {
  1467. X        XtFree((char*)rddSelnData);
  1468. X        rddSelnLen = 0;
  1469. X    }
  1470. X
  1471. X    rddSelnData = (u_char *)XtMalloc(rddSelnLen=nbytes);
  1472. X    bcopy (data, rddSelnData, rddSelnLen);
  1473. X
  1474. X    stat = XChangeProperty (display, RootWindow(display,0), rddSelnAtom,
  1475. X                            XA_STRING,
  1476. X                            8,
  1477. X                            PropModeReplace,
  1478. X                            rddSelnData, (int)rddSelnLen);
  1479. X    return(stat);
  1480. }
  1481. X
  1482. static int
  1483. rddGetSelection (data)
  1484. X    u_char **data;
  1485. {
  1486. X    int n;
  1487. X    Atom type;
  1488. X    int format, count;
  1489. X    u_long leftover;
  1490. X
  1491. X    DEBUGRDD (fprintf (stderr, "rddGetSelection entered\n"););
  1492. X
  1493. X    rddInitCheck();
  1494. X
  1495. X    n =XGetWindowProperty (display, RootWindow(display,0), rddSelnAtom,
  1496. X                           0L, 100000L,
  1497. X                           FALSE,
  1498. X                           AnyPropertyType,
  1499. X                           &type, &format,
  1500. X                           &rddSelnLen,
  1501. X                           &leftover,
  1502. X                           &rddSelnData);
  1503. X
  1504. X    *data = rddSelnData;
  1505. X    return(rddSelnLen);    
  1506. }
  1507. X
  1508. /*
  1509. X *  getPointerWindow - 
  1510. X *         return the first subwindow of top which the pointer is in that
  1511. X *         has a drop handler installed on it.
  1512. X */
  1513. static Window
  1514. getPointerWindow ()
  1515. {
  1516. X    int i;
  1517. X    for (i=0; i < handlerListCnt; i++)
  1518. X    {
  1519. X        if (handlerList[i].active)
  1520. X        {
  1521. X            DEBUGRDD (fprintf(stderr, "returning handler %d %s window = 0x%x\n",
  1522. X                           i, XtName(handlerList[i].w),
  1523. X                           XtWindow(handlerList[i].w)););
  1524. X            return (XtWindow(handlerList[i].w));
  1525. X        }
  1526. X    }
  1527. X    DEBUGRDD (fprintf (stderr, "getPointerWindow returned 0\n"););
  1528. X    return (0);
  1529. }
  1530. X
  1531. /*
  1532. X *  rddSendDropEvent - 
  1533. X *         Send an rdd drop message to the window which contains the pointer.
  1534. X *         The window parameter is filled in with the window id  of the widget
  1535. X *         passed in, or with the window id of the topLevel shell if w is NULL
  1536. X *         This is to facilitate a possible conversation between the
  1537. X *         dropping window and its target.  Such a conversation could be 
  1538. X *         needed to negotiate the details of a complex drop operation,
  1539. X *         none is required to send simple messages.
  1540. X */
  1541. void 
  1542. rddSendDropEvent (w, event)
  1543. X    Widget w;
  1544. X    XEvent *event;
  1545. {
  1546. X    static XClientMessageEvent ev;
  1547. X    XButtonEvent *bv = (XButtonEvent*)event;
  1548. X
  1549. X    if (!ev.type)
  1550. X    {
  1551. X        rddInitCheck();
  1552. X        ev.type            = ClientMessage;
  1553. X        ev.display        = display;
  1554. X        ev.message_type = rddProtocolMsg;
  1555. X        ev.format        = 32;
  1556. X        ev.data.l[0]    = rddDataType;
  1557. X    }
  1558. X
  1559. X
  1560. X    ev.window    = XtWindow(topLevel);
  1561. X    ev.data.l[1]    = w ? XtWindow(w) : XtWindow(topLevel);
  1562. X
  1563. X    if (bv && (bv->type == ButtonPress || bv->type == ButtonRelease))
  1564. X        ev.data.l[2]    = bv->state;
  1565. X    else
  1566. X        ev.data.l[2]    = 0;
  1567. X
  1568. X    ++ev.serial;
  1569. X
  1570. X    DEBUGRDD (fprintf(stderr, "rddSendDropEvent to win 0x%x\n", ev.window););
  1571. X
  1572. X    XSendEvent (display, PointerWindow, TRUE, NoEventMask, (XEvent*)&ev);
  1573. }
  1574. X
  1575. /*
  1576. X *  rddDropEventHandler - 
  1577. X *         This procedure is installed to handel rdd drop events on all windows.
  1578. X *         It dispatches to the user specified procedure after retrieving data
  1579. X *         from the rdd selection buffer.
  1580. X */
  1581. static void
  1582. rddDropEventHandler(w, hd, ev)
  1583. X    Widget w;
  1584. X    HandlerData *hd;
  1585. X    XClientMessageEvent *ev;
  1586. {
  1587. X    int nbytes;
  1588. X    u_char *sdata;
  1589. X    RddCallbackStruct cbs;
  1590. X
  1591. X    if (ev->type != ClientMessage || ev->message_type != rddProtocolMsg)
  1592. X        return;
  1593. X    
  1594. X    nbytes = rddGetSelection (&sdata);
  1595. X
  1596. X    DEBUGRDD (fprintf (stderr,"GOT DROP MESSAGE %d bytes\n", nbytes););
  1597. X
  1598. X    if (hd && hd->proc)
  1599. X    {
  1600. X        cbs.data    = (caddr_t)sdata;
  1601. X        cbs.len        = nbytes;
  1602. X        cbs.type    = ev->data.l[0];
  1603. X        cbs.from    = ev->data.l[1];
  1604. X        cbs.keymask    = ev->data.l[2];
  1605. X        cbs.event    = ev;
  1606. X        (hd->proc)(hd->w, hd->data, &cbs);
  1607. X    }
  1608. }
  1609. X
  1610. static void
  1611. enterLeaveProc(w, hd, ev)
  1612. X    Widget w;
  1613. X    HandlerData *hd;
  1614. X    XCrossingEvent *ev;
  1615. {
  1616. X    hd->active    = (ev->type == EnterNotify);
  1617. X    DEBUGRDD (fprintf(stderr, "window %s active = %d\n",
  1618. X                   XtName(hd->w), hd->active););
  1619. }
  1620. X
  1621. static void
  1622. deleteDropHandler (w, h, cbs)
  1623. X    Widget w;
  1624. X    HandlerData *h;
  1625. X    XtPointer *cbs;
  1626. {
  1627. X    int i;
  1628. X
  1629. X    DEBUGRDD (fprintf (stderr, "deleted handler for widget 0x%x\n", w););
  1630. X    for (i=0; i < handlerListCnt; i++)
  1631. X    {
  1632. X        if (handlerList[i].w == w)    
  1633. X        {
  1634. X            bzero(&handlerList[i], sizeof(handlerList[i]));
  1635. X            return;
  1636. X        }
  1637. X    }
  1638. }
  1639. X
  1640. /*
  1641. X *  rddAddDropHandler - 
  1642. X *         Add a callback routine to a widget for rdd drop events.
  1643. X *         Call scemantics for proc:
  1644. X *             void proc (Widget w; XtPointer data; RddCallbackStruct *cbs)
  1645. X *         where w     is the widget for which the handler is being called
  1646. X *               data  is user specified data passed through to proc
  1647. X *               cbs    is an RddCallbackStruct filled in.
  1648. X */
  1649. void
  1650. rddAddDropHandler(w, proc, data)
  1651. X    Widget w;
  1652. X    XtCallbackProc proc;
  1653. X    caddr_t data;
  1654. {
  1655. X    int i;
  1656. X    HandlerData *newHandler;
  1657. X
  1658. X    rddInitCheck();
  1659. X
  1660. X    if (handlerListCnt >= handlerListAllocCnt)
  1661. X    {
  1662. X
  1663. X        for (i=0; i < handlerListCnt; i++)
  1664. X        {
  1665. X            if (handlerList[i].w == 0)    /* was deleted */
  1666. X                continue;
  1667. X             XtRemoveEventHandler(handlerList[i].w, 0, TRUE, 
  1668. X                                  rddDropEventHandler, 
  1669. X                                  handlerList+i);
  1670. X            XtRemoveEventHandler (handlerList[i].w,
  1671. X                                  EnterWindowMask|LeaveWindowMask, FALSE, 
  1672. X                                  enterLeaveProc, 
  1673. X                                  handlerList+i);
  1674. X        }
  1675. X
  1676. X        handlerListAllocCnt += 10;
  1677. X        handlerList =
  1678. X            (HandlerData*) XtRealloc((char*)handlerList,
  1679. X                                 sizeof(HandlerData) * handlerListAllocCnt);
  1680. X        DEBUGRDD(fprintf(stderr,"handlerList = 0x%x\n", handlerList););
  1681. X
  1682. X        for (i=0; i < handlerListCnt; i++)
  1683. X        {
  1684. X            if (handlerList[i].w == 0)    /* was deleted */
  1685. X                continue;
  1686. X            XtAddEventHandler (handlerList[i].w, 0, TRUE, 
  1687. X                               rddDropEventHandler, 
  1688. X                               handlerList+i);
  1689. X            XtAddEventHandler (handlerList[i].w,
  1690. X                               EnterWindowMask|LeaveWindowMask,
  1691. X                               FALSE, enterLeaveProc, 
  1692. X                               handlerList+i);
  1693. X        }
  1694. X    }
  1695. X
  1696. X    newHandler = handlerList + handlerListCnt++;
  1697. X    
  1698. X    DEBUGRDD (fprintf(stderr, "rddAddDropHandler: for widget %s window=0x%x\n",
  1699. X                  XtName(w), XtWindow(w)););
  1700. X
  1701. X    newHandler->proc    =    proc;
  1702. X    newHandler->data    =    data;
  1703. X    newHandler->w        =   w;
  1704. X    newHandler->active    =   FALSE;
  1705. X    XtAddEventHandler (w, 0, TRUE, 
  1706. X                       rddDropEventHandler, newHandler);
  1707. X    XtAddEventHandler (w, EnterWindowMask|LeaveWindowMask, FALSE, 
  1708. X                       enterLeaveProc, newHandler);
  1709. X    XtAddCallback (w, XtNdestroyCallback, deleteDropHandler, newHandler);
  1710. }
  1711. X
  1712. /*
  1713. X *  rddSetDropData - 
  1714. X *         Public function to set data into the rdd selection buffer.
  1715. X */
  1716. void
  1717. rddSetDropData (data, len)
  1718. X    caddr_t data;
  1719. X    int len;
  1720. {
  1721. X    rddDataType = RDD_NO_DATA_TYPE;
  1722. X    rddSetSelection (data, len);
  1723. }
  1724. X
  1725. void
  1726. rddSetDropDataType (data, len, type)
  1727. X    caddr_t data;
  1728. X    int len, type;
  1729. {
  1730. X    rddDataType = type;
  1731. X    rddSetSelection (data, len);
  1732. }
  1733. X
  1734. X
  1735. X
  1736. /*
  1737. X *  rddAppMainLoop - 
  1738. X *         Replacement for XtAppMainLoop. This routine knows more than it
  1739. X *         should, but seems to be needed to make rdd work for "all" cases.
  1740. X */
  1741. void rddAppMainLoop(app)
  1742. X    XtAppContext app;
  1743. {
  1744. X    XEvent event;
  1745. X    Widget w;
  1746. X
  1747. X    for (;;)
  1748. X    {
  1749. X        XtAppNextEvent(app, &event);
  1750. X
  1751. X        /*
  1752. X         * If it is an rdd message, try to dispatch it to the
  1753. X         * currently active drop window. 
  1754. X         */
  1755. X        if (rddIsRddMessageEvent(event))
  1756. X        {
  1757. X            DEBUGRDD (fprintf(stderr, "clientMessage received window 0x%x\n",
  1758. X                           event.xclient.window););
  1759. X            if (!(event.xclient.window = getPointerWindow()))
  1760. X            {
  1761. X                DEBUGRDD (fprintf (stderr, "no window to dispatch to\n"););
  1762. X                continue;
  1763. X            }
  1764. X        }
  1765. X        if (!XtDispatchEvent(&event))
  1766. X        {
  1767. X            /*DEBUGRDD (fprintf (stderr, "rddAppMainLoop dispatch failed type %d\n",
  1768. X                            event.type););*/
  1769. X        }
  1770. X    }
  1771. }
  1772. X
  1773. /*
  1774. X * When called, initiate and dispatch an RDD operation.
  1775. X * This can be used to, for example, to start an RDD thing by pressing 
  1776. X * a button.  The next click will be reported to this window, and
  1777. X * the user supplied function will be called, presumably to do
  1778. X * rddSetDataType and rddDropActions.
  1779. X */
  1780. void 
  1781. rddDragButton (w, ev, fptr)
  1782. X    Widget w;
  1783. X    XButtonEvent *ev;
  1784. X    void (*fptr)();
  1785. {
  1786. X    XEvent event;
  1787. X    Window win = XtWindow(w);
  1788. X    XtAppContext app = XtWidgetToApplicationContext(w);
  1789. X
  1790. X    DEBUGRDD (fprintf(stderr, "rddDragButton: w = 0x%x app = 0x%x\n",
  1791. X                   win, app););
  1792. X
  1793. X    rddStartAction(w, ev, NULL, 0);
  1794. X
  1795. X    ev->x += 100;
  1796. X    ev->y += 100;
  1797. X
  1798. X    rddDragAction(w, ev, NULL, 0);
  1799. X
  1800. X    XGrabPointer (XtDisplay(w), win, FALSE,
  1801. X                  PointerMotionMask | ButtonReleaseMask,
  1802. X                  GrabModeAsync, GrabModeAsync, None, None, 
  1803. X                  ev->time);
  1804. X    for (;;)
  1805. X    {
  1806. X        XtAppNextEvent(app, &event);
  1807. X
  1808. X        XtDispatchEvent(&event);
  1809. X        if (event.type == ButtonRelease)
  1810. X        {
  1811. X            XUngrabPointer (XtDisplay(w), event.xbutton.time);
  1812. X            (*fptr)(w, &event);
  1813. X            break;
  1814. X        }
  1815. X        else if (event.type == MotionNotify)
  1816. X        {
  1817. X            rddDragAction (w, (XButtonEvent*)&event, NULL, 0);
  1818. X        }
  1819. X    }
  1820. X    DEBUGRDD (fprintf (stderr, "out of rddDragButton\n"););
  1821. }
  1822. X
  1823. #ifdef MAIN
  1824. X
  1825. /* As an example of how to add drag-n-drop to an existimg program,
  1826. X * here is the hello program from chapter 2 of Dan Heller's book,
  1827. X * modified so that the button can both initiate a drag-n-drop
  1828. X * operation, and respond to something being dropped on it.
  1829. X * 
  1830. X * RDD comments denote rdd additions and changes.
  1831. X */
  1832. X
  1833. X
  1834. /* Written by Dan Heller.  Copyright 1991, O'Reilly && Associates.
  1835. X * This program is freely distributable without licensing fees and
  1836. X * is provided without guarantee or warrantee expressed or implied.
  1837. X * This program is -not- in the public domain.
  1838. X */
  1839. X
  1840. /* hello.c --
  1841. X * Initialize the toolkit using an application context and a toplevel
  1842. X * shell widget, then create a pushbutton that says Hello using
  1843. X * the R4 varargs interface.
  1844. X */
  1845. #include <Xm/Xm.h>
  1846. #include <Xm/PushB.h>
  1847. X
  1848. X
  1849. /*
  1850. X * RDD
  1851. X * The normal translations for a button, plus those needed to do a 
  1852. X * drag-n-drop procedure.
  1853. X */
  1854. String myTranslations =
  1855. X        "<Btn1Down>:    Arm() myStartAction()        \n\
  1856. X        <Btn1Up>:        Activate() Disarm() myDropAction() \n\
  1857. X        <Btn1Motion>:    rddDragAction() \n\
  1858. ";
  1859. X
  1860. XXtAppContext  app;
  1861. X
  1862. /* RDD myStartAction */
  1863. void myStartAction (w, event, args, nargs)
  1864. X    Widget w;
  1865. X    XButtonEvent *event;
  1866. X    String *args;
  1867. X    int *nargs;
  1868. {
  1869. X    static Pixmap pixmap;
  1870. X    Display *dpy = XtDisplay(w);
  1871. X    int wid=40, hgt=40;
  1872. X    static GC gc;
  1873. X
  1874. X    if (!pixmap)
  1875. X    {
  1876. X        XGCValues gcv;
  1877. X
  1878. X        gcv.subwindow_mode = IncludeInferiors;
  1879. X        gc = XCreateGC (dpy, XtWindow(w), GCSubwindowMode, &gcv);
  1880. X        
  1881. X        pixmap = XCreatePixmap (dpy, RootWindow(dpy,0), 
  1882. X                                wid, hgt, XDefaultDepth(dpy,0));
  1883. X    }
  1884. X
  1885. X    /* Create a pixmap of the screen near the cursor */
  1886. X    XCopyArea (dpy, RootWindow(dpy,0), pixmap, gc,
  1887. X               event->x_root-wid/2, event->y_root-hgt/2,
  1888. X               wid, hgt, 0, 0);
  1889. X    rddSetDragPixmap (pixmap, wid, hgt);
  1890. X    rddSetDragCursorOffset(wid/2, hgt/2);
  1891. SHAR_EOF
  1892. true || echo 'restore of xmfm/rdd.c failed'
  1893. fi
  1894. echo 'End of  part 7'
  1895. echo 'File xmfm/rdd.c is continued in part 8'
  1896. echo 8 > _shar_seq_.tmp
  1897. exit 0
  1898. --
  1899. +----------------------+---+
  1900.   Jan Newmarch, Information Science and Engineering,
  1901.   University of Canberra, PO Box 1, Belconnen, Act 2616
  1902.   Australia. Tel: (Aust) 6-2012422. Fax: (Aust) 6-2015041
  1903.