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

  1. Newsgroups: alt.sources
  2. Path: sparky!uunet!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 04 of 17
  5. Message-ID: <1992Nov19.052231.25622@csc.canberra.edu.au>
  6. Sender: news@csc.canberra.edu.au
  7. Organization: University of Canberra
  8. Date: Thu, 19 Nov 92 05:22:31 GMT
  9. Lines: 1768
  10.  
  11.  
  12.  
  13. #!/bin/sh
  14. # this is part.04 (part 4 of a multipart archive)
  15. # do not concatenate these parts, unpack them in order with /bin/sh
  16. # file xmfm/applicat.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" != 4; 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/applicat.c'
  32. else
  33. echo 'x - continuing file xmfm/applicat.c'
  34. sed 's/^X//' << 'SHAR_EOF' >> 'xmfm/applicat.c' &&
  35. X    }
  36. X
  37. X    /* turn visibility back on for panes */
  38. X    XtMapWidget (XtParent (dpi -> files_pane));
  39. X    XtMapWidget (XtParent (dpi -> executables_pane));
  40. X    XtMapWidget (XtParent (dpi -> dirs_pane));
  41. }
  42. SHAR_EOF
  43. echo 'File xmfm/applicat.c is complete' &&
  44. chmod 0644 xmfm/applicat.c ||
  45. echo 'restore of xmfm/applicat.c failed'
  46. Wc_c="`wc -c < 'xmfm/applicat.c'`"
  47. test 39204 -eq "$Wc_c" ||
  48.     echo 'xmfm/applicat.c: original size 39204, current size' "$Wc_c"
  49. rm -f _shar_wnt_.tmp
  50. fi
  51. # ============= xmfm/builtin.c ==============
  52. if test -f 'xmfm/builtin.c' -a X"$1" != X"-c"; then
  53.     echo 'x - skipping xmfm/builtin.c (File already exists)'
  54.     rm -f _shar_wnt_.tmp
  55. else
  56. > _shar_wnt_.tmp
  57. echo 'x - extracting xmfm/builtin.c (Text)'
  58. sed 's/^X//' << 'SHAR_EOF' > 'xmfm/builtin.c' &&
  59. /*************************************************************************
  60. X * File: builtin.c
  61. X * Author: Jan Newmarch
  62. X * Last modified: $Date: 1992/11/17 00:35:36 $
  63. X * Version: $Revision: 1.7 $
  64. X * Purpose: Handle builtin calls to the file manager. These are calls that
  65. X *    must be done internally (eg change directory) or for efficiency
  66. X *    (none yet)
  67. X * Revision history:
  68. X *    4 Aug 92    filter part added to open dir
  69. X *    6 Aug 92    busy cursor when changing/opening dir
  70. X ************************************************************************/ 
  71. X
  72. #include "copyright.h"
  73. X
  74. /*************************************************************************
  75. X * System includes
  76. X ************************************************************************/ 
  77. #include <stdio.h>
  78. X
  79. /*************************************************************************
  80. X * Local includes
  81. X ************************************************************************/ 
  82. #include "types.h"
  83. #include "const.h"
  84. #include "xmvararg.h"
  85. X
  86. /*************************************************************************
  87. X * Extern variables
  88. X ************************************************************************/ 
  89. extern XmString empty_string;
  90. extern int pane_count;
  91. X
  92. /*************************************************************************
  93. X * Extern functions
  94. X ************************************************************************/ 
  95. extern DirectoryMgr *GetFilesInDir (
  96. #ifdef UseFunctionPrototypes
  97. X    void
  98. #endif
  99. );
  100. extern void invert_colours (
  101. #ifdef UseFunctionPrototypes
  102. X    Widget w
  103. #endif
  104. );
  105. extern Widget CreateApplication (
  106. #ifdef UseFunctionPrototypes
  107. X    Widget parent
  108. #endif
  109. );
  110. extern Bool XtChdir (
  111. #ifdef UseFunctionPrototypes
  112. X    char *dir
  113. #endif
  114. );
  115. extern void BusyCursor (
  116. #ifdef UseFunctionPrototypes
  117. X    Widget toplevel
  118. #endif
  119. );
  120. extern void UnBusyCursor (
  121. #ifdef UseFunctionPrototypes
  122. X    Widget toplevel
  123. #endif
  124. );
  125. extern void builtin_info (
  126. #ifdef UseFunctionPrototypes
  127. X    dir_pane_info *dpi
  128. #endif
  129. );
  130. extern void ResetFilesInPanes (
  131. #ifdef UseFunctionPrototypes
  132. X    dir_pane_info *dpi
  133. #endif
  134. );
  135. X
  136. /*************************************************************************
  137. X * Functions exported
  138. X ************************************************************************/ 
  139. void builtin_command (
  140. #ifdef UseFunctionPrototypes
  141. X    char *command, dir_pane_info *dpi
  142. #endif
  143. );
  144. void builtin_chdir (
  145. #ifdef UseFunctionPrototypes
  146. X    char *dir, dir_pane_info *dpi
  147. #endif
  148. );
  149. void builtin_opendir (
  150. #ifdef UseFunctionPrototypes
  151. X    char *dir, dir_pane_info *dpi
  152. #endif
  153. );
  154. X
  155. /*************************************************************************
  156. X * Variables exported
  157. X ************************************************************************/ 
  158. X
  159. /*************************************************************************
  160. X * Forward functions
  161. X ************************************************************************/ 
  162. X
  163. /*************************************************************************
  164. X * Local variables
  165. X ************************************************************************/ 
  166. X
  167. X
  168. /*************************************************************************
  169. X * Function: SetWMTitle()
  170. X * Purpose: set the title of window and icon.
  171. X * In parameters: dir, toplevel
  172. X * Precondition:
  173. X * Postcondition: title and icon title set to dir
  174. X ************************************************************************/ 
  175. static void
  176. SetWMTitle 
  177. #ifdef UseFunctionPrototypes
  178. X    (char *dir, Widget toplevel)
  179. #else
  180. X    (dir, toplevel)
  181. X    char * dir;
  182. X    Widget toplevel;
  183. X
  184. #endif
  185. {    char *p;
  186. X    int len;
  187. X
  188. X    /* set the new window manager title
  189. X       the icon will only show a small amount, so use end of path
  190. X    */
  191. X    len = strlen (dir);
  192. X    if (strlen (dir) <= 1)
  193. X        /* root */
  194. X        p = dir;
  195. X    else
  196. X    {    /* backup over trailing / in dir */
  197. X        p = dir + len - 2;
  198. X        while (p > dir && *(p - 1) != '/' )
  199. X            p--;
  200. X    }
  201. X
  202. X    XtVaSetValues (toplevel,
  203. X        XmNtitle, dir,
  204. X        XmNiconName, p,
  205. X        NULL);
  206. }
  207. X
  208. /*************************************************************************
  209. X * Function: builtin_chdir ()
  210. X * Purpose: handle a change of directory request
  211. X * In parameters: dir, dpi
  212. X * Precondition: dir is an existing directory relative to current one
  213. X * Postcondition: panes are repainted to show the new directory, and
  214. X *                values are set in dpi for this.
  215. X ************************************************************************/ 
  216. void
  217. builtin_chdir 
  218. #ifdef UseFunctionPrototypes
  219. X    (char *dir, dir_pane_info *dpi)
  220. #else
  221. X    (dir, dpi)
  222. X    char * dir;
  223. X    dir_pane_info *dpi;
  224. X
  225. #endif
  226. {
  227. X    DirectoryMgr *dm;
  228. X    Widget *files_toolbar;
  229. X    int i;
  230. X
  231. #ifdef DEBUG
  232. X    fprintf (stderr, "built in: chdir %s\n", dir);
  233. #endif
  234. X    if (XtChdir (dir) == False)
  235. X        /* chdir failed, no changes */
  236. X        return;
  237. X
  238. X    /* turn off the highlighted dir */
  239. X    if (dpi -> file_selected != NULL)
  240. X        invert_colours (dpi -> file_button_selected);
  241. X    dpi -> file_button_selected = NULL;
  242. X    dpi -> file_selected = NULL;
  243. X
  244. X    /* void the file toolbar */
  245. X    files_toolbar = dpi -> files_toolbar;
  246. X    for (i = 0; i < FILES_TOOLBAR_SIZE; i++)
  247. X    {    XtVaSetValues (files_toolbar[i],
  248. X                XmNlabelString, (XtArgVal) empty_string,
  249. X                NULL);
  250. X        XtSetSensitive (files_toolbar[i], False);
  251. X    }
  252. X
  253. X    BusyCursor (dpi -> toplevel);
  254. X    DirectoryMgrClose (dpi -> directory_manager);
  255. X    dm = GetFilesInDir ();
  256. X    dpi -> directory_manager = dm;
  257. X    ResetFilesInPanes (dpi);
  258. X    UnBusyCursor (dpi -> toplevel);
  259. X    SetWMTitle (
  260. X        DirectoryPath (DirectoryMgrDir (dpi -> directory_manager)),
  261. X        dpi -> toplevel);
  262. }
  263. X
  264. X
  265. /*************************************************************************
  266. X * Function: builtin_opendir ()
  267. X * Purpose: handle a change of directory request
  268. X * In parameters: dir, dpi
  269. X * Precondition: dir is an existing directory relative to current one
  270. X * Postcondition: panes are repainted to show the new directory, and
  271. X *                values are set in dpi for this.
  272. X ************************************************************************/ 
  273. void
  274. builtin_opendir 
  275. #ifdef UseFunctionPrototypes
  276. X    (char *dir, dir_pane_info *dpi)
  277. #else
  278. X    (dir, dpi)
  279. X    char * dir;
  280. X    dir_pane_info *dpi;
  281. X
  282. #endif
  283. {
  284. X    Widget shell, dir_pane;
  285. X    dir_pane_info *new_dpi;
  286. X
  287. #ifdef DEBUG
  288. X    fprintf (stderr, "built in: opendir %s\n", dir);
  289. #endif
  290. X    if (XtChdir (dir) == False)
  291. X        /* chdir failed, no changes */
  292. X        return;
  293. X    
  294. X    pane_count++;
  295. X
  296. X    shell = XtCreateApplicationShell ("shell",
  297. X                vendorShellWidgetClass,
  298. X                NULL, 0);
  299. /*
  300. X    shell = XtAppCreateShell ("shell",
  301. X                vendorShellWidgetClass,
  302. X                NULL, 0);
  303. */
  304. X
  305. X    dir_pane = CreateApplication (shell);
  306. X    XtManageChild (dir_pane);
  307. X
  308. X    XtPopup (shell, XtGrabNone);
  309. X
  310. X        /* set files in panes */
  311. X        XtVaGetValues (dir_pane,
  312. X                        XmNuserData, (XtArgVal) &new_dpi,
  313. X                        NULL);
  314. X
  315. X    /* copy over filters */
  316. X    new_dpi -> file_filter = XtMalloc (strlen (dpi -> file_filter) + 1);    
  317. X    strcpy (new_dpi -> file_filter, dpi -> file_filter);
  318. X
  319. X    /* a compiled regexp is an opaque string, that I suspect may
  320. X       contain NULL bytes. To stop strcpy stopping on them, use
  321. X       bcopy instead
  322. X    */
  323. X    bcopy (dpi -> file_filter_regexp, new_dpi -> file_filter_regexp,
  324. X        FSM_LENGTH);
  325. X
  326. X    new_dpi -> dir_filter = XtMalloc (strlen (dpi -> dir_filter) + 1);    
  327. X    strcpy (new_dpi -> dir_filter, dpi -> dir_filter);
  328. X
  329. X    bcopy (dpi -> dir_filter_regexp, new_dpi -> dir_filter_regexp,
  330. X        FSM_LENGTH);
  331. X
  332. X    new_dpi -> executable_filter = 
  333. X        XtMalloc (strlen (dpi -> executable_filter) + 1);    
  334. X    strcpy (new_dpi -> executable_filter, dpi -> executable_filter);
  335. X
  336. X    bcopy (dpi -> executable_filter_regexp, 
  337. X        new_dpi -> executable_filter_regexp,
  338. X        FSM_LENGTH);
  339. X
  340. X        SetFiltersInLabels (new_dpi);
  341. X
  342. X    /* and now set the files in the panes */
  343. X    BusyCursor (new_dpi -> toplevel);
  344. X        ResetFilesInPanes (new_dpi);
  345. X    SetActionsInDirsToolbar (new_dpi);
  346. X    UnBusyCursor (new_dpi -> toplevel);
  347. X
  348. X    SetWMTitle (
  349. X        DirectoryPath (DirectoryMgrDir (dpi -> directory_manager)),
  350. X        dpi -> toplevel);
  351. X
  352. }
  353. X
  354. X
  355. X
  356. /*************************************************************************
  357. X * Function: builtin_command ()
  358. X * Purpose: handle any of the builtin commands
  359. X * In parameters: command
  360. X * Out parameters:
  361. X * Precondition:command is a non-null builtin command
  362. X * Postcondition: builtin command has been executed
  363. X ************************************************************************/ 
  364. void
  365. builtin_command 
  366. #ifdef UseFunctionPrototypes
  367. X    (char *command, dir_pane_info *dpi)
  368. #else
  369. X    (command, dpi)
  370. X    char *command;
  371. X    dir_pane_info *dpi;
  372. X
  373. #endif
  374. {
  375. X    /* these start with a $ - lose that, and then look */
  376. X    command++;
  377. X    
  378. X    if (strncmp (command, CHDIR_COMMAND, LEN_CHDIR_COMMAND) == 0)
  379. X    {
  380. X        /* lose the builtin part */
  381. X        command += LEN_CHDIR_COMMAND + 1;
  382. X        builtin_chdir (command, dpi);
  383. X        return;
  384. X    }
  385. X    
  386. X    if (strncmp (command, OPENDIR_COMMAND, LEN_OPENDIR_COMMAND) == 0)
  387. X    {
  388. X        /* lose the builtin part */
  389. X        command += LEN_OPENDIR_COMMAND + 1;
  390. X        builtin_opendir (command, dpi);
  391. X        return;
  392. X    }
  393. X    if (strncmp (command, INFO_COMMAND, LEN_INFO_COMMAND) == 0)
  394. X    {
  395. X        builtin_info (dpi);
  396. X        return;
  397. X    }
  398. }
  399. SHAR_EOF
  400. chmod 0644 xmfm/builtin.c ||
  401. echo 'restore of xmfm/builtin.c failed'
  402. Wc_c="`wc -c < 'xmfm/builtin.c'`"
  403. test 8841 -eq "$Wc_c" ||
  404.     echo 'xmfm/builtin.c: original size 8841, current size' "$Wc_c"
  405. rm -f _shar_wnt_.tmp
  406. fi
  407. # ============= xmfm/buttoncb.c ==============
  408. if test -f 'xmfm/buttoncb.c' -a X"$1" != X"-c"; then
  409.     echo 'x - skipping xmfm/buttoncb.c (File already exists)'
  410.     rm -f _shar_wnt_.tmp
  411. else
  412. > _shar_wnt_.tmp
  413. echo 'x - extracting xmfm/buttoncb.c (Text)'
  414. sed 's/^X//' << 'SHAR_EOF' > 'xmfm/buttoncb.c' &&
  415. /*************************************************************************
  416. X * File: $Source: /usr/usrs/xsource/xmfm/RCS/buttoncb.c,v $
  417. X * Author: Jan Newmarch
  418. X * Last modified: $Date: 1992/11/17 00:35:37 $
  419. X * Version: $Revision: 1.9 $
  420. X * Purpose: handle the callback events from various buttons being pressed
  421. X *
  422. X * Revision history:
  423. X *    7 Aug 92    stdin of no-xterm do_commands set to /dev/null
  424. X *    16 Oct 92    caddr_t changed to XtPointer
  425. X *       3 Nov 92       lint-ed
  426. X ************************************************************************/ 
  427. X
  428. #include "copyright.h"
  429. X
  430. /*************************************************************************
  431. X * System includes
  432. X ************************************************************************/ 
  433. #include <Xm/Xm.h>
  434. #include <X11/cursorfont.h>
  435. #include <string.h>
  436. X
  437. /*************************************************************************
  438. X * Local includes
  439. X ************************************************************************/ 
  440. #include "const.h"
  441. #include "types.h"
  442. #ifdef RDD
  443. #include "rdd.h"
  444. #endif
  445. X
  446. /*************************************************************************
  447. X * Functions exported
  448. X ************************************************************************/ 
  449. extern void FileButtonPressedCB (
  450. #ifdef UseFunctionPrototypes
  451. X    Widget w, XtPointer client_data, XtPointer call_data
  452. #endif
  453. );
  454. extern void FileButtonReleasedCB (
  455. #ifdef UseFunctionPrototypes
  456. X    Widget w, XtPointer client_data, XtPointer call_data
  457. #endif
  458. );
  459. extern void FileToolButtonPressedCB (
  460. #ifdef UseFunctionPrototypes
  461. X    Widget w, XtPointer client_data, XtPointer call_data
  462. #endif
  463. );
  464. extern void do_command (
  465. #ifdef UseFunctionPrototypes
  466. X    char *command, int run_in_xterm, int pause_after_exec, dir_pane_info *dpi
  467. #endif
  468. );
  469. X
  470. /*************************************************************************
  471. X * Variables exported
  472. X ************************************************************************/ 
  473. X
  474. /*************************************************************************
  475. X * Extern functions
  476. X ************************************************************************/ 
  477. extern void builtin_command (
  478. #ifdef UseFunctionPrototypes
  479. X    char *command, dir_pane_info *dpi
  480. #endif
  481. );
  482. extern void BusyCursor (
  483. #ifdef UseFunctionPrototypes
  484. X    Widget toplevel
  485. #endif
  486. );
  487. extern void UnBusyCursor (
  488. #ifdef UseFunctionPrototypes
  489. X    Widget toplevel
  490. #endif
  491. );
  492. extern void PromptDialog (
  493. #ifdef UseFunctionPrototypes
  494. X    Widget parent, char *prompt, int modal, char **answer
  495. #endif
  496. );
  497. extern Bool XtChdir (
  498. #ifdef UseFunctionPrototypes
  499. X    char *dir
  500. #endif
  501. );
  502. X
  503. /*************************************************************************
  504. X * Extern variables
  505. X ************************************************************************/ 
  506. extern file_action *actions;
  507. extern XmString empty_string;
  508. X
  509. /*************************************************************************
  510. X * Forward functions
  511. X ************************************************************************/ 
  512. static void expand_command (
  513. #ifdef UseFunctionPrototypes
  514. X    char **command, char **argv, int argc, char *action
  515. #endif
  516. );
  517. void do_command (
  518. #ifdef UseFunctionPrototypes
  519. X    char *command, int run_in_xterm, int pause_after_exec, dir_pane_info *dpi
  520. #endif
  521. );
  522. void expand_prompt ();
  523. X
  524. /*************************************************************************
  525. X * Local variables
  526. X ************************************************************************/ 
  527. X
  528. #define XTERM_STR "xterm -title '"
  529. #define PAUSEME_STR "' -exec pauseme '"
  530. #define EXEC_STR "' -exec sh -c '"
  531. X
  532. #define COMM_SIZE        4096
  533. #define IS_WHITE_SPACE(c)    ((c) == ' ' || (c) == '\t' || (c) == '\n')
  534. #define STRING_LEN_CHECK(size)    if ((int)(new_str + (size) - *command) > COMM_SIZE)\
  535. X                {    fprintf (stderr, "action too long\n");\
  536. X                    *new_str = '\0';\
  537. X                    return;}
  538. X
  539. /*************************************************************************
  540. X * Function: invert_colours ()
  541. X * Purpose: swap  the fg and bg of the label and pixmap
  542. X * In parameters: w
  543. X * Out parameters:
  544. X * Side effects: pne_button_info of button has label, pixmap swapped
  545. X *    with inverted versions
  546. X * Precondition:
  547. X * Postcondition: label shows inverted.
  548. X ************************************************************************/ 
  549. void
  550. invert_colours 
  551. #ifdef UseFunctionPrototypes
  552. X    (Widget w)
  553. #else
  554. X    (w)
  555. X    Widget w;
  556. X
  557. #endif
  558. {    
  559. X    pane_button_info *pbi;
  560. X    Pixmap tmp_pixmap;
  561. X    GC tmp_gc;
  562. X
  563. X    if (w == NULL)
  564. X        return;
  565. X    XtVaGetValues (w,
  566. X        XmNuserData, (XtArgVal) &pbi,
  567. X        NULL);
  568. X    
  569. X    /* swap the gc and pixmap with reversed forms */
  570. X    tmp_pixmap = pbi -> pixmap;
  571. X    pbi -> pixmap = pbi -> pixmap_reversed;
  572. X    pbi -> pixmap_reversed = tmp_pixmap;
  573. X
  574. X    tmp_gc = pbi -> gc;
  575. X    pbi -> gc = pbi -> gc_reversed;
  576. X    pbi -> gc_reversed = tmp_gc;
  577. X
  578. X    /* set the reversed pixmap in the button */
  579. X    XtVaSetValues (w,
  580. X        XmNlabelPixmap, (XtArgVal) pbi -> pixmap,
  581. X        NULL);
  582. X    
  583. X    /* and force a redisplay to redraw name */
  584. X    XClearArea (XtDisplay (w), XtWindow (w),
  585. X            0, 0, 0, 0, True);
  586. }
  587. /*************************************************************************
  588. X * Function: FileButtonPressedCB ()
  589. X * Purpose: handle a button press in any of the panes i.e. a file has
  590. X *          been selected
  591. X * In parameters: w, client_data, call_data
  592. X * Out parameters:
  593. X * Precondition: a button for a file, executable, or 
  594. X *               directory has been pressed
  595. X * Postcondition: toolbar buttons set up to reflect actions for this 
  596. X *               selected file
  597. X * Warning: this function is called by others that set last 2 params
  598. X *    to NULL
  599. X ************************************************************************/ 
  600. X
  601. /* ARGSUSED */
  602. void
  603. FileButtonPressedCB 
  604. #ifdef UseFunctionPrototypes
  605. X    (Widget w, XtPointer client_data, XtPointer call_data)
  606. #else
  607. X    (w, client_data, call_data)
  608. X    Widget w;
  609. X    XtPointer client_data;
  610. X    XtPointer call_data;
  611. X
  612. #endif
  613. {    
  614. X    pane_button_info *pbi;
  615. X    tool_button_info *tbi;
  616. X    file_action *pfa;
  617. X    action_pair *pap;
  618. X    XmString xmstr;
  619. X    int button;
  620. X    Widget tool_button;
  621. X
  622. #ifdef DEBUG
  623. X    fprintf (stderr, "button pressed\n");
  624. #endif
  625. X    /* get the user data */
  626. X    XtVaGetValues (w,
  627. X            XmNuserData, (XtArgVal) &pbi,
  628. X            NULL);
  629. X
  630. X    /* set the last selected back to normal and invert this one */
  631. X    if (pbi -> dpi -> file_selected != NULL)
  632. X        invert_colours (pbi -> dpi -> file_button_selected);
  633. X    invert_colours (w);
  634. X    
  635. X    /* set the file selected */
  636. X    pbi -> dpi -> file_selected = pbi -> name;
  637. X    pbi -> dpi -> file_button_selected = w;
  638. X    pbi -> dpi -> executable_selected = NULL;
  639. X    pbi -> dpi -> dir_selected = NULL;
  640. X
  641. X    /* find file pattern matching this name */
  642. X    pfa = actions;
  643. X    while (pfa != NULL)
  644. X        if (pfa -> file_type == pbi -> file_type &&
  645. X            RegExpMatch (pbi -> name, pfa -> fsm_ptr))
  646. X            break;
  647. X        else    pfa = pfa -> next;
  648. X
  649. X    /* description of this file type */
  650. X    if (pfa != NULL)
  651. X        pbi -> dpi -> description =  pfa -> description; 
  652. X    else    pbi -> dpi -> description =  NULL;
  653. X    
  654. X    button = 0;
  655. X    /* set actions in toolbar */
  656. X    if (pfa != NULL)
  657. X    {
  658. X        pap = pfa -> actions;
  659. X        while (button < FILES_TOOLBAR_SIZE && pap != NULL)
  660. X        {
  661. X            tool_button = (pbi -> dpi -> files_toolbar) [button];
  662. X
  663. X            /* set the action label in the button */
  664. X            xmstr = XmStringCreateLtoR (pap -> action_label,
  665. X                    XmSTRING_DEFAULT_CHARSET);
  666. X            XtVaSetValues (tool_button,
  667. X                    XmNlabelString, (XtArgVal) xmstr,
  668. X                    NULL);
  669. X            XmStringFree (xmstr);
  670. X
  671. X            /* set the action in the buttons user data */
  672. X            XtVaGetValues (tool_button,
  673. X                    XmNuserData, (XtArgVal) &tbi,
  674. X                    NULL);
  675. X            tbi -> action = pap -> action;
  676. X            tbi -> prompt = pap -> prompt;
  677. X            tbi -> run_in_xterm = pap -> run_in_xterm;
  678. X            tbi -> pause_after_exec = pap -> pause_after_exec;
  679. X            tbi -> has_prompt = pap -> has_prompt;
  680. X
  681. X            XtSetSensitive (tool_button, True);
  682. X            button++;
  683. X            pap = pap -> next;
  684. X        }
  685. X    }
  686. X    /* empty out the remaining buttons */
  687. X    for ( ; button < FILES_TOOLBAR_SIZE; button++)
  688. X    {
  689. X        tool_button = (pbi -> dpi -> files_toolbar) [button];
  690. X        /* break out as soon as we hit an already insensitive button */
  691. X        if (XtIsSensitive (tool_button) == False)
  692. X            break;
  693. X        XtVaSetValues (tool_button,
  694. X                XmNlabelString, (XtArgVal) empty_string,
  695. X                NULL);
  696. X        XtSetSensitive (tool_button, False);
  697. X    }
  698. X
  699. #ifdef RDD
  700. X    /* set the drag cursor */
  701. X    {    Window root;
  702. X        int x, y;
  703. X        unsigned int width, height;
  704. X        unsigned int border_width, depth;
  705. X
  706. X        XGetGeometry (XtDisplay (pbi -> dpi -> toplevel),
  707. X                pbi -> pixmap,
  708. X                &root,
  709. X                &x, &y, &width, &height,
  710. X                &border_width, &depth);
  711. X        rddSetDragPixmap (pbi -> pixmap, width, height);
  712. X    }
  713. #endif
  714. }
  715. X
  716. X
  717. /*************************************************************************
  718. X * Function: FileButtonReleasedCB ()
  719. X * Purpose: handle a button release in any of the panes i.e. a file has
  720. X *          been selected. Check if it is a multiclick, and if so
  721. X *        execute default action.
  722. X * In parameters: w, client_data, call_data
  723. X * Out parameters:
  724. X * Precondition: a button for a file, executable, or 
  725. X                 directory has been released
  726. X ************************************************************************/ 
  727. X
  728. /* ARGSUSED */
  729. void
  730. FileButtonReleasedCB 
  731. #ifdef UseFunctionPrototypes
  732. X    (Widget w, XtPointer client_data, XtPointer call_data)
  733. #else
  734. X    (w, client_data, call_data)
  735. X    Widget w;
  736. X    XtPointer client_data;
  737. X    XtPointer call_data;
  738. X
  739. #endif
  740. {    pane_button_info *pbi;
  741. X    XmDrawnButtonCallbackStruct *c_data= (XmDrawnButtonCallbackStruct *) call_data;
  742. X
  743. #ifdef DEBUG
  744. X    fprintf (stderr, "button released\n");
  745. #endif
  746. X    /* get the user data */
  747. X    XtVaGetValues (w,
  748. X            XmNuserData, (XtArgVal) &pbi, NULL);
  749. X    /* if it was a double click, execute
  750. X       the default action. default action is in
  751. X       the first toolbar button, if sensitive */
  752. X    if ((c_data -> click_count) > 1 &&
  753. X        XtIsSensitive ((pbi -> dpi -> files_toolbar) [0]))
  754. X    {    /* set the busy cursor as a signal that something happens */
  755. X        BusyCursor (pbi -> dpi -> toplevel);
  756. X
  757. X        /* fake default action on button */
  758. X        FileToolButtonPressedCB ( (pbi -> dpi -> files_toolbar) [0],
  759. X                    NULL, NULL);
  760. X            UnBusyCursor (pbi -> dpi -> toplevel);
  761. X    }
  762. }
  763. X
  764. /*************************************************************************
  765. X * Function: FileToolbarButtonPressed ()
  766. X * Purpose: handle a button press in the file toolbar
  767. X * In parameters: w, client_data, call_data
  768. X * Out parameters:
  769. X * Precondition: button in toolbar pressed
  770. X * Postcondition: action for that button on selected file executed
  771. X ************************************************************************/ 
  772. void
  773. FileToolButtonPressedCB 
  774. #ifdef UseFunctionPrototypes
  775. X    (Widget w, XtPointer client_data, XtPointer call_data)
  776. #else
  777. X    (w, client_data, call_data)
  778. X    Widget w;
  779. X    XtPointer client_data, call_data;
  780. X
  781. #endif
  782. {
  783. X    tool_button_info *tbi;
  784. X    char *command;
  785. X    char *argv[10];
  786. X    int argc;
  787. X    char *prompt_answer;
  788. X    int len_arg;
  789. X
  790. X    XtVaGetValues (w,
  791. X            XmNuserData, (XtArgVal) &tbi,
  792. X            NULL);
  793. X
  794. X    argv[0] = tbi -> dpi -> file_selected;
  795. X    if (argv[0] != NULL)
  796. X        argc = 1;
  797. X    else    argc = 0;
  798. X    if (tbi -> has_prompt)
  799. X    {    PromptDialog (w, tbi -> prompt, True, &prompt_answer);
  800. X        if (prompt_answer == NULL)
  801. X            return;
  802. X        /* set answer into args array */
  803. X        while (*prompt_answer != '\0' && argc < 10)
  804. X        {    while (IS_WHITE_SPACE (*prompt_answer))
  805. X                prompt_answer++;
  806. X            argv[argc] = prompt_answer;
  807. X            argc++;
  808. X            len_arg = strcspn (prompt_answer, " \t\n");
  809. X            if (prompt_answer[len_arg] == '\0')
  810. X                break;
  811. X            else
  812. X            {    prompt_answer[len_arg] = '\0';
  813. X                prompt_answer += len_arg + 1;
  814. X            }
  815. X        }
  816. X    }
  817. #ifdef DEBUG
  818. X    for (len_arg = 0; len_arg < argc; len_arg++)
  819. X        fprintf (stderr, "Arg %d is %s\n", len_arg, argv[len_arg]);
  820. #endif
  821. X
  822. #ifdef OLD_PATTERN
  823. X    /* next step: replace 2nd arg by argv */
  824. X    expand_command (&command, tbi -> dpi -> file_selected, tbi -> action);
  825. #else
  826. X    expand_command (&command, argv, argc, tbi -> action);
  827. #endif
  828. X
  829. #ifdef DEBUG
  830. X    fprintf (stderr, "action %s\n", tbi -> action);
  831. X    fprintf (stderr, "on file %s\n", tbi -> dpi -> file_selected);
  832. X    fprintf (stderr, "new command: %s\n", command);
  833. #endif
  834. X
  835. X    /* make sure we are in the right directory for this pane */
  836. X    XtChdir (DirectoryPath (DirectoryMgrDir (tbi -> dpi -> directory_manager)));
  837. X
  838. #ifdef DEBUG
  839. X    {    char path[MAXPATHLEN];
  840. X        fprintf (stderr, "changing to directory %s\n",
  841. X            DirectoryPath (DirectoryMgrDir (tbi -> dpi -> directory_manager)));
  842. X
  843. X            getcwd (path, MAXPATHLEN);
  844. X        fprintf (stderr, "now in directory %s\n", path);
  845. X    }
  846. #endif
  847. X
  848. X    if (*command == '$')
  849. X        builtin_command (command, tbi -> dpi);
  850. X    else
  851. X        do_command (command, tbi -> run_in_xterm, 
  852. X                     tbi -> pause_after_exec,
  853. X                                     tbi -> dpi);
  854. X    XtFree (command);
  855. }
  856. X
  857. X
  858. #ifdef OLD_PATTERN
  859. /*************************************************************************
  860. X * Function: expand_command ()
  861. X * Purpose: this expands out the action into a command
  862. X *         it uses the Make patterns of
  863. X *        $$ = $
  864. X *        $* = stem of file name
  865. X *        $@ = file name
  866. X * In parameters: file, action
  867. X * Out parameters: command
  868. X * Precondition: action is a string that can be applied to the file
  869. X * Postcondition: command is the action with filename replaced
  870. X *                according to patterns above
  871. X ************************************************************************/ 
  872. static void
  873. expand_command (command, file, action)
  874. X    char **command;
  875. X    char *file;
  876. X    char *action;
  877. {
  878. X    int old_len, new_len;
  879. X    int file_len, stem_len;
  880. X    char *p;
  881. X    char *new_str;
  882. X    char *stem;
  883. X
  884. X    /* find some constant lengths */
  885. X    old_len = strlen (action);
  886. X    file_len = strlen (file);
  887. X    for (stem_len = file_len; stem_len > 0; stem_len--)
  888. X        if (file[stem_len - 1] == '.')
  889. X            break;
  890. X    stem_len--;
  891. X
  892. X    /* create the stem string */
  893. X    stem = XtMalloc (stem_len + 1);
  894. X    strncpy (stem, file, stem_len);
  895. X    stem[stem_len + 1] = '\0';
  896. X
  897. X    /* find the length of the new string */
  898. X    new_len = 0;
  899. X    p = action;
  900. X    while (*p != '\0')
  901. X    {    if (*p == '$')
  902. X        switch ( *(p+1) )
  903. X        {    case '$':    new_len++;
  904. X                    p += 2;
  905. X                    break;
  906. X            case '@':    new_len += file_len;
  907. X                    p += 2;
  908. X                    break;
  909. X            case '*':    new_len += stem_len;
  910. X                    p += 2;
  911. X                    break;
  912. X            default:    new_len++;
  913. X                    p++;
  914. X        } else {
  915. X            new_len++;
  916. X            p++;
  917. X        }
  918. X    }
  919. X
  920. X    /* create the new string */
  921. X    *command = new_str = (char *) XtMalloc (new_len + 1);
  922. X
  923. X    /* and populate it */
  924. X    p = action; 
  925. X    while (*p != '\0')
  926. X    {    if (*p == '$')
  927. X        switch ( *(p+1) )
  928. X        {    case '$':    *new_str = '$';
  929. X                    new_str++;
  930. X                    p += 2;
  931. X                    break;
  932. X            case '@':    strcpy (new_str, file);
  933. X                    new_str += file_len;
  934. X                    p += 2;
  935. X                    break;
  936. X            case '*':    strcpy (new_str, stem);
  937. X                    new_str += stem_len;
  938. X                    p += 2;
  939. X                    break;
  940. X            default:    *new_str++ = *p++;
  941. X                    
  942. X        } else {
  943. X            new_len++;
  944. X            *new_str++ = *p++;
  945. X        }
  946. X    }
  947. X    *new_str = '\0';
  948. }
  949. #else /* OLD_PATTERN */
  950. /*************************************************************************
  951. X * Function: expand_command ()
  952. X * Purpose: this expands out the action into a command
  953. X *         it uses the ksh patterns of
  954. X *        \c = c
  955. X *        $0 = selected file
  956. X *        $d = n-th parameter in prompt
  957. X *        $* = string of entire prompt 
  958. X *        ${d#p} = d-th param less pattern p from front
  959. X *        ${d%p} = d-th param less pattern p from end
  960. X * In parameters: argv, argc, action
  961. X * Out parameters: command
  962. X * Precondition: action is a string that can be applied to the file
  963. X * Postcondition: command is the action with patterns replaced
  964. X *                according to params in argv
  965. X ************************************************************************/ 
  966. static void
  967. expand_command 
  968. #ifdef UseFunctionPrototypes
  969. X    (char **command, char **argv, int argc, char *action)
  970. #else
  971. X    (command, argv, argc, action)
  972. X    char **command;
  973. X    char **argv;
  974. X    int argc;
  975. X    char *action;
  976. X
  977. #endif
  978. {
  979. X    char *p;
  980. X    char *new_str;
  981. X    int digit;
  982. X    char *end_brace_pos;
  983. X    int arg_len, pat_len;
  984. X
  985. X    /* create the new string, hopefully too big */
  986. X    *command = new_str = (char *) XtMalloc (4096);
  987. X
  988. X    /* and populate it */
  989. X    p = action; 
  990. X    while (*p != '\0')
  991. X    {    if (*p == '\\')
  992. X        {    /* escape sequence */
  993. X            STRING_LEN_CHECK (2);
  994. X            p++;
  995. X            *new_str++ = *p++;
  996. X            continue;
  997. X        }
  998. X        if (*p == '$')
  999. X        {     p++;
  1000. X            if (isdigit (*p))
  1001. X            {    /* $d param subst */
  1002. X                digit = *p++ - '0';
  1003. X                if (digit >= argc)
  1004. X                    /* off the end of the argv array */
  1005. X                    continue;
  1006. X                arg_len = strlen (argv[digit]);
  1007. X                STRING_LEN_CHECK (arg_len);
  1008. X                strcpy (new_str, argv[digit]);
  1009. X                new_str += arg_len;
  1010. X                continue;
  1011. X            }
  1012. X            if (*p == '*')
  1013. X            {    /* $* all params subst */
  1014. X                int i;
  1015. X
  1016. X                for (i = 1; i < argc; i++)
  1017. X                {    arg_len = strlen (argv[i]);
  1018. X                    STRING_LEN_CHECK (arg_len);
  1019. X                    strcpy (new_str, argv[i]);
  1020. X                    new_str += arg_len;
  1021. X                    if (i < argc - 1)
  1022. X                        /* change \0 to ' ' */
  1023. X                        *new_str++ = ' ';
  1024. X                }
  1025. X                p++;
  1026. X                continue;
  1027. X            }
  1028. X            if (*p != '{')
  1029. X            {    /* pass $ through - not one of our patterns */
  1030. X                STRING_LEN_CHECK (2);
  1031. X                *new_str++ = '$';
  1032. X                *new_str++ = *p++;
  1033. X                continue;
  1034. X            }
  1035. X            /* it's '${' so should end in '}' */
  1036. X            end_brace_pos = strchr (p, '}');
  1037. X            if (end_brace_pos == NULL)
  1038. X            {    /* dunno what to do - no closing brace */
  1039. X                fprintf (stderr, "no closing } in action!\n");
  1040. X                continue;
  1041. X            }
  1042. X            p++;
  1043. X            if (!isdigit (*p))
  1044. X            {    /* pass it through - not a positional param */
  1045. X                STRING_LEN_CHECK ((int)(end_brace_pos - p) + 2);
  1046. X                *new_str++ = '$';
  1047. X                *new_str++ = '{';
  1048. X                while (p != end_brace_pos + 1)
  1049. X                    *new_str++ = *p++;
  1050. X            }
  1051. X            /* its ${d...}. Is ... NULL, %, #? */
  1052. X            digit = *p - '0';
  1053. X            STRING_LEN_CHECK (1);
  1054. X            p++;
  1055. X            if (p == end_brace_pos)
  1056. X            {    /* ${d} param subst */
  1057. X                arg_len = strlen (argv[digit]);
  1058. X                STRING_LEN_CHECK (arg_len);
  1059. X                strcpy (new_str, argv[digit]);     
  1060. X                new_str += arg_len;
  1061. X                p++;    /* skip past '}' */
  1062. X                continue;
  1063. X            }
  1064. X            if (*p == '#')
  1065. X            {    /* ${d#pat} take pattern off the front */
  1066. X                p++;
  1067. X                pat_len = (int) (end_brace_pos - p);
  1068. X                if (strncmp (argv[digit],p,
  1069. X                    pat_len) != 0)
  1070. X                {     /* no match, copy whole arg */
  1071. X                    strcpy (new_str, argv[digit]);
  1072. X                    new_str += strlen (argv[digit]);
  1073. X                    p += pat_len + 1;
  1074. X                    continue;
  1075. X                }
  1076. X                /* copy part after match */
  1077. X                strcpy (new_str, argv[digit] + pat_len);
  1078. X                new_str +=strlen (argv[digit]) - pat_len;
  1079. X                p += pat_len + 1;
  1080. X                continue;
  1081. X            }
  1082. X            if (*p == '%')
  1083. X            {    /* ${d%pat} take pattern off the end */
  1084. X                int stem_len, arg_len;
  1085. X                char *tail;
  1086. X
  1087. X                p++;
  1088. X                pat_len = (int) (end_brace_pos - p);
  1089. X                arg_len = strlen (argv[digit]);
  1090. X                stem_len = arg_len - pat_len;
  1091. X
  1092. X                /* pattern should start at tail */
  1093. X                tail = argv[digit] + stem_len;
  1094. X                if (strncmp (tail, p, pat_len) != 0)
  1095. X                {    /* no match, copy all */
  1096. X                    strcpy (new_str, argv[digit]);
  1097. X                    new_str += arg_len;
  1098. X                    p += pat_len + 1;
  1099. X                    continue;
  1100. X                }
  1101. X                /* copy first part only, upto pattern */
  1102. X                strncpy (new_str, argv[digit], stem_len);
  1103. X                new_str += stem_len;
  1104. X                p += pat_len + 1;
  1105. X                continue;
  1106. X            }
  1107. X            /* dunno what it is */
  1108. X            fprintf (stderr, "unknown pattern %s in action\n",
  1109. X                    p);
  1110. X            continue;
  1111. X        }
  1112. X        /* copy any other char */
  1113. X        *new_str++ = *p++;
  1114. X    }
  1115. X    *new_str = '\0';
  1116. }
  1117. #endif /* OLD_PATTERN */
  1118. X
  1119. X
  1120. /*************************************************************************
  1121. X * Function: do_comand ()
  1122. X * Purpose: execute the selected command
  1123. X * In parameters: command, run_in_xterm, pause_after_exec
  1124. X * Out parameters:
  1125. X * Precondition: command is a valid Unix command
  1126. X * Postcondition: action specified by command running asynchronously
  1127. X ************************************************************************/ 
  1128. void 
  1129. do_command 
  1130. #ifdef UseFunctionPrototypes
  1131. X    (char *command, int run_in_xterm, int pause_after_exec, dir_pane_info *dpi)
  1132. #else
  1133. X    (command, run_in_xterm, pause_after_exec, dpi)
  1134. X    char *command;
  1135. X    Bool run_in_xterm;
  1136. X    Bool pause_after_exec;
  1137. X        dir_pane_info *dpi;
  1138. X
  1139. #endif
  1140. {
  1141. X    int len_new_command;
  1142. X    char *new_command;
  1143. X        int pid;
  1144. X
  1145. X    if (run_in_xterm && pause_after_exec)
  1146. X    {
  1147. X        len_new_command = 2 * strlen (command) + 
  1148. X                    strlen (XTERM_STR) +
  1149. X                    strlen (PAUSEME_STR) + 4;
  1150. X        /* leave space for \0 terminator */
  1151. X        new_command = XtMalloc (len_new_command + 1);
  1152. X        strcpy (new_command, XTERM_STR);
  1153. X        strcat (new_command, command);
  1154. X        strcat (new_command, PAUSEME_STR);
  1155. X        strcat (new_command, command);
  1156. X                strcat (new_command, "' ");
  1157. X        }
  1158. X    else if (run_in_xterm)
  1159. X    {
  1160. X        len_new_command = 2 * strlen (command) + 
  1161. X                    strlen (XTERM_STR) + 
  1162. X                    strlen (EXEC_STR) + 4;
  1163. X        new_command = XtMalloc (len_new_command + 1);
  1164. X        strcpy (new_command, XTERM_STR);
  1165. X        strcat (new_command, command);
  1166. X        strcat (new_command, EXEC_STR);
  1167. X        strcat (new_command, command);
  1168. X                strcat (new_command, "' ");
  1169. X
  1170. X    }
  1171. X    else    /* run as an X application, or into existing xterm */
  1172. X    {
  1173. X        len_new_command =  strlen (command) + 13;
  1174. X        new_command = XtMalloc (len_new_command + 1);
  1175. X        strcpy (new_command, command);
  1176. X        /* make sure that if it attempts to read from stdin,
  1177. X           it fails (eg. an interactive shell not run in an xterm) */
  1178. X        strcat (new_command, " < /dev/null ");
  1179. X    }
  1180. X
  1181. /*    system (new_command);
  1182. X    XtFree (new_command);
  1183. X */
  1184. X        if ((pid = fork ()) > 0)
  1185. X        {        /* parent */
  1186. X                 add_pid (pid, dpi);
  1187. X        }
  1188. X        else     /* child */
  1189. X        {
  1190. X                system (new_command);
  1191. X                XtFree (new_command); 
  1192. X        exit (0);
  1193. X        }                
  1194. }
  1195. X
  1196. SHAR_EOF
  1197. chmod 0644 xmfm/buttoncb.c ||
  1198. echo 'restore of xmfm/buttoncb.c failed'
  1199. Wc_c="`wc -c < 'xmfm/buttoncb.c'`"
  1200. test 20831 -eq "$Wc_c" ||
  1201.     echo 'xmfm/buttoncb.c: original size 20831, current size' "$Wc_c"
  1202. rm -f _shar_wnt_.tmp
  1203. fi
  1204. # ============= xmfm/drag.c ==============
  1205. if test -f 'xmfm/drag.c' -a X"$1" != X"-c"; then
  1206.     echo 'x - skipping xmfm/drag.c (File already exists)'
  1207.     rm -f _shar_wnt_.tmp
  1208. else
  1209. > _shar_wnt_.tmp
  1210. echo 'x - extracting xmfm/drag.c (Text)'
  1211. sed 's/^X//' << 'SHAR_EOF' > 'xmfm/drag.c' &&
  1212. /*************************************************************************
  1213. X * File: $Source: /usr/usrs/xsource/xmfm/RCS/drag.c,v $
  1214. X * Author: Jan Newmarch
  1215. X * Last modified: $Date: 1992/11/17 00:35:40 $
  1216. X * Version: $Revision: 1.2 $
  1217. X * Purpose:
  1218. X *
  1219. X * Revision history:
  1220. X *         3 Nov 92        lint-ed
  1221. X *      11 Nov 92       moved Rogers drag'n drop to here
  1222. X ************************************************************************/ 
  1223. X
  1224. #include "copyright.h"
  1225. X
  1226. /*************************************************************************
  1227. X * System includes
  1228. X ************************************************************************/ 
  1229. #include <sys/param.h>
  1230. X
  1231. #ifdef MOTIF_DD
  1232. #include <Xm/DragIcon.h>
  1233. #include <Xm/DragDrop.h>
  1234. #include <Xm/AtomMgr.h>
  1235. #include <X11/Xatom.h>
  1236. #endif
  1237. X
  1238. #ifdef RDD
  1239. #include "rdd.h"
  1240. #endif
  1241. X
  1242. /*************************************************************************
  1243. X * Local includes
  1244. X ************************************************************************/ 
  1245. #include "types.h"
  1246. X
  1247. /*************************************************************************
  1248. X * Functions exported
  1249. X ************************************************************************/ 
  1250. X
  1251. /*************************************************************************
  1252. X * Variables exported
  1253. X ************************************************************************/ 
  1254. X
  1255. /*************************************************************************
  1256. X * Extern variables
  1257. X ************************************************************************/ 
  1258. X
  1259. /*************************************************************************
  1260. X * Extern functions
  1261. X ************************************************************************/ 
  1262. extern void FileToolButtonPressed ();
  1263. extern void FileButtonPressed ();
  1264. X
  1265. /*************************************************************************
  1266. X * Forward functions
  1267. X ************************************************************************/ 
  1268. X
  1269. #ifdef MOTIF_DD
  1270. extern void MotifDDStartAction (
  1271. #ifdef UseFunctionPrototypes
  1272. X    Widget w, XButtonEvent *event
  1273. #endif
  1274. );
  1275. #endif
  1276. X
  1277. /*************************************************************************
  1278. X * Local variables
  1279. X ************************************************************************/ 
  1280. #ifdef MOTIF_DD
  1281. XXtTranslations trans_table;
  1282. Atom TEXT;
  1283. static pane_button_info *pbi;
  1284. static Widget drag_icon = NULL;
  1285. X
  1286. String myTranslations =
  1287. X        "#override\n\
  1288. X        <Btn2Down>:    Arm() MotifDDStartAction()\n\
  1289. X        <Btn2Up>:    Activate() Disarm()";
  1290. XXtActionsRec dragActions [] =
  1291. X                 { {"MotifDDStartAction", (XtActionProc) MotifDDStartAction} };
  1292. #endif /* MOTIF_DD */
  1293. X
  1294. X
  1295. #ifdef RDD
  1296. /*************************************************************************
  1297. X * Function: DirDrop ()
  1298. X * Purpose: handler for when a widget is dropped on a directory button
  1299. X * In parameters: w, call, cbs
  1300. X * Function result:
  1301. X * Precondition: drop message to widget w (a directory button) has occurred
  1302. X * Postcondition: 
  1303. X ************************************************************************/ 
  1304. void
  1305. DirDrop 
  1306. #ifdef UseFunctionPrototypes
  1307. X    (Widget w, XtPointer call, XtPointer client_data)
  1308. #else
  1309. X    (w, call, client_data)
  1310. X    Widget w;
  1311. X    XtPointer call;
  1312. X    XtPointer client_data;
  1313. X
  1314. #endif
  1315. {    pane_button_info *pbi;
  1316. X    RddCallbackStruct *cbs = (RddCallbackStruct *) client_data;
  1317. X
  1318. X    XtVaGetValues (w,
  1319. X        XmNuserData, &pbi, NULL);
  1320. #ifdef DEBUG
  1321. X    fprintf (stderr, "drop on directory %s of file %s", 
  1322. X            pbi -> name, cbs -> data);
  1323. #endif
  1324. }
  1325. X
  1326. /*************************************************************************
  1327. X * Function: ExecutableDrop ()
  1328. X * Purpose: handler for when a widget is dropped on an executable button
  1329. X * In parameters: w, call, cbs
  1330. X * Function result:
  1331. X * Precondition: drop message to widget w (an executable button) has occurred
  1332. X * Postcondition: 
  1333. X ************************************************************************/ 
  1334. void
  1335. ExecutableDrop 
  1336. #ifdef UseFunctionPrototypes
  1337. X    (Widget w, XtPointer call, XtPointer client_data)
  1338. #else
  1339. X    (w, call, client_data)
  1340. X    Widget w;
  1341. X    XtPointer call;
  1342. X    XtPointer client_data;
  1343. X
  1344. #endif
  1345. {    pane_button_info *pbi;
  1346. X    RddCallbackStruct *cbs = (RddCallbackStruct *) client_data;
  1347. X
  1348. X    XtVaGetValues (w,
  1349. X        XmNuserData, &pbi, NULL);
  1350. #ifdef DEBUG
  1351. X    fprintf (stderr, "drop on executable %s of file %s", 
  1352. X            pbi -> name, cbs -> data);
  1353. #endif
  1354. }
  1355. X
  1356. /*************************************************************************
  1357. X * Function: MainWindowDrop ()
  1358. X * Purpose: handler for when a widget is dropped on an executable button
  1359. X * In parameters: w, call, cbs
  1360. X * Function result:
  1361. X * Precondition: drop message to widget w (an executable button) has occurred
  1362. X * Postcondition: 
  1363. X ************************************************************************/ 
  1364. void
  1365. MainWindowDrop 
  1366. #ifdef UseFunctionPrototypes
  1367. X    (Widget w, XtPointer call, XtPointer client_data)
  1368. #else
  1369. X    (w, call, client_data)
  1370. X    Widget w;
  1371. X    XtPointer call;
  1372. X    XtPointer client_data;
  1373. X
  1374. #endif
  1375. {    pane_button_info *pbi;
  1376. X    RddCallbackStruct *cbs = (RddCallbackStruct *) client_data;
  1377. X
  1378. X    XtVaGetValues (w,
  1379. X        XmNuserData, &pbi, NULL);
  1380. #ifdef DEBUG
  1381. X    fprintf (stderr, "drop on main window of file %s", 
  1382. X             cbs -> data);
  1383. #endif
  1384. }
  1385. X
  1386. /*************************************************************************
  1387. X * Function: ToolbarDrop ()
  1388. X * Purpose: handler for when a widget is dropped on a toobar button
  1389. X * In parameters: w, call, cbs
  1390. X * Function result:
  1391. X * Precondition: drop message to widget w (a toolbar button) has occurred
  1392. X * Postcondition: action corresponding to toolbar button has been done
  1393. X ************************************************************************/ 
  1394. void
  1395. ToolbarDrop 
  1396. #ifdef UseFunctionPrototypes
  1397. X    (Widget w, XtPointer call, XtPointer client_data)
  1398. #else
  1399. X    (w, call, client_data)
  1400. X    Widget w;
  1401. X    XtPointer call;
  1402. X    XtPointer client_data;
  1403. X
  1404. #endif
  1405. {
  1406. X    RddCallbackStruct *cbs = (RddCallbackStruct *) client_data;
  1407. #ifdef DEBUG
  1408. X    fprintf (stderr, "File dropped: %s", cbs -> data);
  1409. #endif
  1410. X    FileToolButtonPressedCB (w, NULL, NULL);
  1411. }
  1412. #endif /* RDD */
  1413. X
  1414. #ifdef MOTIF_DD
  1415. /*************************************************************************
  1416. X *
  1417. X * DRAG SIDE OF MOTIF DRAG AND DROP
  1418. X *
  1419. X *************************************************************************/
  1420. X
  1421. /*************************************************************************
  1422. X * Function: MotifDragConvertProc ()
  1423. X * Purpose: convert data into form suitable to send to drop client
  1424. X * In parameters: w, selection, target, client_data
  1425. X * Out parameters: typeRtn, valueRtn, formatRtn, max_lengthRtn
  1426. X * Precondition: 
  1427. X * Postcondition: full path name of selected file set as data
  1428. X ************************************************************************/ 
  1429. X
  1430. /* ARGSUSED */
  1431. Boolean
  1432. MotifDragConvertProc 
  1433. #ifdef UseFunctionPrototypes
  1434. X    (Widget w, Atom *selection, Atom *target, Atom *typeRtn, XtPointer *valueRtn, long unsigned int *lengthRtn, int *formatRtn, long unsigned int *max_lengthRtn, XtPointer client_data, XtRequestId *request_id)
  1435. #else
  1436. X    (w, selection, target,
  1437. X    typeRtn, valueRtn, lengthRtn, formatRtn,
  1438. X    max_lengthRtn, client_data,
  1439. X    request_id)
  1440. X    Widget        w;
  1441. X    Atom        *selection;
  1442. X    Atom        *target;
  1443. X    Atom        *typeRtn;
  1444. X    XtPointer    *valueRtn;
  1445. X    unsigned long    *lengthRtn;
  1446. X    int        *formatRtn;
  1447. X    unsigned long    *max_lengthRtn;
  1448. X    XtPointer    client_data;
  1449. X    XtRequestId    *request_id;
  1450. X
  1451. #endif
  1452. {
  1453. X    char *path;
  1454. X
  1455. X    if (*target != XA_STRING)
  1456. X        return False;
  1457. X    /* build up full path name for file */
  1458. X    path = (char *) XtMalloc (MAXPATHLEN);
  1459. X    strcpy (path, DirectoryPath (DirectoryMgrDir (pbi -> dpi -> directory_manager)));
  1460. X    strcat (path, pbi -> name);
  1461. X    *lengthRtn = strlen (path);
  1462. X    *typeRtn = XA_STRING;
  1463. X    *valueRtn = path;
  1464. X    *formatRtn = 8;        /* dont know what 8 means */
  1465. #ifdef DEBUG_DD
  1466. X    fprintf (stderr, "starting drop for %s\n", path);
  1467. #endif
  1468. X    return True;
  1469. }
  1470. X
  1471. /*************************************************************************
  1472. X * Function: MotifDDStartAction ()
  1473. X * Purpose: what to do when a drag begins
  1474. X * In parameters: w, event
  1475. X * Out parameters:
  1476. X * Precondition: 
  1477. X * Postcondition:  icon set to image, drag started
  1478. X ************************************************************************/ 
  1479. void MotifDDStartAction 
  1480. #ifdef UseFunctionPrototypes
  1481. X    (Widget w, XButtonEvent *event)
  1482. #else
  1483. X    (w, event)
  1484. X    Widget w;
  1485. X    XButtonEvent *event;
  1486. X
  1487. #endif
  1488. {    Atom    exportList[1];
  1489. X    Arg    args[10];
  1490. X        int n;
  1491. X
  1492. X        /* store in a global variable the user data for this button
  1493. X           till I figure out which widgets take part in what 
  1494. X           The widget in the ConvertProc doesn't seem to be this one
  1495. X         */
  1496. X        XtVaGetValues (w, XmNuserData, &pbi, NULL);
  1497. X
  1498. X    if (drag_icon == NULL)
  1499. X    {    n = 0;
  1500. X        /* set the pixmap to be the icon of the file
  1501. X           used reverse icon cos it has been selected by now */
  1502. X        XtSetArg (args[n], XmNpixmap, pbi -> pixmap_reversed); n++;
  1503. X        drag_icon = XmCreateDragIcon (w, "drag_icon", args, n);
  1504. X    }
  1505. X    else
  1506. X    XtVaSetValues (w,
  1507. X            XmNpixmap, pbi -> pixmap_reversed,
  1508. X            NULL);
  1509. X    
  1510. X    exportList[0] = XA_STRING;
  1511. X        n = 0;
  1512. X    XtSetArg (args[n], XmNexportTargets,    (XtArgVal) exportList); n++;
  1513. X        XtSetArg (args[n], XmNnumExportTargets,    (XtArgVal) 1); n++;
  1514. X    XtSetArg (args[n], XmNdragOperations,    (XtArgVal) XmDROP_COPY); n++;
  1515. X    XtSetArg (args[n], XmNconvertProc,    (XtArgVal) MotifDragConvertProc); n++;
  1516. X    XtSetArg (args[n], XmNsourcePixmapIcon,    (XtArgVal) drag_icon); n++;
  1517. X
  1518. #ifdef DEBUG_DD
  1519. X        fprintf (stderr, "starting drag\n");
  1520. #endif  /* DEBUG_DD */
  1521. X
  1522. X    XmDragStart (w, (XEvent *) event, args, n);
  1523. }
  1524. X
  1525. /*************************************************************************
  1526. X * Function: InitMotifDD
  1527. X * Purpose         : set up global values for Motif DD
  1528. X * In parameters   : app_shell, app_context
  1529. X * Out parameters  :
  1530. X * Side effects    :
  1531. X * Function returns:
  1532. X * Precondition    :
  1533. X * Postcondition   : soem vbls set
  1534. X ************************************************************************/
  1535. void InitMotifDD 
  1536. #ifdef UseFunctionPrototypes
  1537. X    (Widget app_shell, XtAppContext app_context)
  1538. #else
  1539. X    (app_shell, app_context)
  1540. X        Widget app_shell;
  1541. X        XtAppContext app_context;
  1542. X
  1543. #endif
  1544. {
  1545. X
  1546. X    /* MOTIF_DD add action MotifDDStartAction */
  1547. X    {
  1548. X        XtActionsRec actions;
  1549. X        actions.string    = "MotifDDStartAction";
  1550. X        actions.proc    = MotifDDStartAction;
  1551. X        XtAppAddActions (app_context, &actions, 1);
  1552. X    }
  1553. X    trans_table = XtParseTranslationTable (myTranslations);
  1554. X    
  1555. X    /* set the atom to allow communication with other widgets */
  1556. X    TEXT = XmInternAtom (XtDisplay (app_shell),
  1557. X                "TEXT", False);
  1558. #ifdef DEBUG_DD
  1559. X        fprintf (stderr, "initialised Motif drag n' drop\n");
  1560. #endif /* DEBUG_DD */
  1561. X
  1562. }
  1563. /*************************************************************************
  1564. X *
  1565. X * DROP SIDE OF MOTIF DRAG AND DROP
  1566. X *
  1567. X *************************************************************************/
  1568. X
  1569. /*************************************************************************
  1570. X * Function: ToolbarTransferProc
  1571. X * Purpose         : execute the action on the dropped file
  1572. X * In parameters   : all of them
  1573. X * Out parameters  :
  1574. X * Side effects    :
  1575. X * Function returns:
  1576. X * Precondition    :
  1577. X * Postcondition   : legal drop site -> action executed on drop file
  1578. X ************************************************************************/
  1579. X
  1580. /* ARGSUSED */
  1581. static void
  1582. ToolbarTransferProc 
  1583. #ifdef UseFunctionPrototypes
  1584. X    (Widget w, XtPointer closure, Atom *seltype, Atom *type, XtPointer value, long unsigned int *length, int format)
  1585. #else
  1586. X    (w, closure, seltype,
  1587. X              type, value, length, format)
  1588. X       Widget w;
  1589. X       XtPointer closure;
  1590. X       Atom *seltype;
  1591. X       Atom *type;
  1592. X       XtPointer value;
  1593. X       unsigned long *length;
  1594. X       int format;
  1595. X
  1596. #endif
  1597. {
  1598. X      tool_button_info *tbi;
  1599. X       char selected_file[MAXPATHLEN];
  1600. X      
  1601. X       if (*type == XA_STRING)
  1602. X       {
  1603. #              ifdef DEBUG_DD
  1604. X                     fprintf (stderr, "drop data received okay: %s %s\n",
  1605. X                              (char *) value);
  1606. #              endif
  1607. X               /* closure has the button we just dropped on.
  1608. X                  Suppose a user has dropped from a *different*
  1609. X                  pane - probably an error. We must check that the
  1610. X                  file already selected in this pane is the same as
  1611. X                  the file we have just dropped here!
  1612. X               */
  1613. X               XtVaGetValues (closure, XmNuserData, &tbi, NULL);
  1614. X               strcpy (selected_file,
  1615. X                       DirectoryPath (DirectoryMgrDir (tbi -> dpi -> directory_manager)));
  1616. X
  1617. X               strcat (selected_file, tbi -> dpi -> file_selected);
  1618. #              ifdef DEBUG_DD
  1619. X                     fprintf (stderr, "current selected file in this pane %s\n",
  1620. X                            selected_file);
  1621. #              endif
  1622. X               if (strcmp (value, selected_file) == 0)
  1623. X                      FileToolButtonPressedCB (closure, NULL, NULL);
  1624. X       }
  1625. #      ifdef DEBUG_DD
  1626. X       else
  1627. X                     fprintf (stderr, "drop data not ok\n");
  1628. #      endif
  1629. }
  1630. /*************************************************************************
  1631. X * Function: HandleToolbarDrop
  1632. X * Purpose         : start drop on toolbar button
  1633. X * In parameters   : w, client_data, call_data
  1634. X * Out parameters  :
  1635. X * Side effects    :
  1636. X * Function returns:
  1637. X * Precondition    :
  1638. X * Postcondition   :
  1639. X ************************************************************************/
  1640. X
  1641. /* ARGSUSED */
  1642. static void
  1643. HandleToolbarDrop 
  1644. #ifdef UseFunctionPrototypes
  1645. X    (Widget w, XtPointer client_data, XmDropProcCallback DropData)
  1646. #else
  1647. X    (w, client_data, DropData)
  1648. X       Widget w;
  1649. X       XtPointer client_data;
  1650. X       XmDropProcCallback DropData;
  1651. X
  1652. #endif
  1653. {
  1654. X       
  1655. X       XmDropTransferEntryRec transferEntries[2];
  1656. X       Arg args[10];
  1657. X       int n;
  1658. X
  1659. X       n = 0;
  1660. X       if (DropData -> dropAction != (unsigned char) XmDROP ||
  1661. X              DropData -> operation != (unsigned char) XmDROP_COPY)
  1662. X       {      XtSetArg (args[n], XmNtransferStatus, XmTRANSFER_FAILURE); n++;
  1663. #             ifdef DEBUG_DD
  1664. X              fprintf (stderr, "drop: receive type failed\n");
  1665. #              endif
  1666. X       }
  1667. X       else
  1668. X       {      transferEntries[0].target = XA_STRING;
  1669. X              transferEntries[0].client_data = (XtPointer) w;
  1670. X              XtSetArg (args[n], XmNdropTransfers, transferEntries); n++;
  1671. X              XtSetArg (args[n], XmNnumDropTransfers, 1); n++;
  1672. X              XtSetArg (args[n], XmNtransferProc, ToolbarTransferProc); n++;
  1673. #             ifdef DEBUG_DD
  1674. X              fprintf (stderr, "drop: receive type okay\n");
  1675. #              endif
  1676. X       }
  1677. X       
  1678. X       XmDropTransferStart (DropData -> dragContext, args, n);
  1679. }
  1680. X
  1681. /*************************************************************************
  1682. X * Function: MotifDDRegisterToolbar
  1683. X * Purpose         : let the Motif DD system know about this toolbar button
  1684. X * In parameters   : button
  1685. X * Out parameters  :
  1686. X * Side effects    :
  1687. X * Function returns:
  1688. X * Precondition    :
  1689. X * Postcondition   : button registered in DD
  1690. X ************************************************************************/
  1691. void 
  1692. MotifDDRegisterToolbar 
  1693. #ifdef UseFunctionPrototypes
  1694. X    (Widget button)
  1695. #else
  1696. X    (button)
  1697. X       Widget button;
  1698. X
  1699. #endif
  1700. {
  1701. X       Atom importList[1];
  1702. X       Arg args[10];
  1703. X       int n;
  1704. X
  1705. X       importList[0] = XA_STRING;
  1706. X       n = 0;
  1707. X       XtSetArg (args[n], XmNimportTargets, (XtArgVal) importList); n++;
  1708. X       XtSetArg (args[n], XmNnumImportTargets, (XtArgVal) 1); n++;
  1709. X       XtSetArg (args[n], XmNdropSiteOperations, (XtArgVal) XmDROP_COPY); n++;
  1710. X       XtSetArg (args[n], XmNdropProc, (XtArgVal) HandleToolbarDrop); n++;
  1711. X       XmDropSiteRegister (button, args, n);
  1712. }
  1713. #endif /* MOTIF_DD */
  1714. SHAR_EOF
  1715. chmod 0644 xmfm/drag.c ||
  1716. echo 'restore of xmfm/drag.c failed'
  1717. Wc_c="`wc -c < 'xmfm/drag.c'`"
  1718. test 15392 -eq "$Wc_c" ||
  1719.     echo 'xmfm/drag.c: original size 15392, current size' "$Wc_c"
  1720. rm -f _shar_wnt_.tmp
  1721. fi
  1722. # ============= xmfm/file_act.c ==============
  1723. if test -f 'xmfm/file_act.c' -a X"$1" != X"-c"; then
  1724.     echo 'x - skipping xmfm/file_act.c (File already exists)'
  1725.     rm -f _shar_wnt_.tmp
  1726. else
  1727. > _shar_wnt_.tmp
  1728. echo 'x - extracting xmfm/file_act.c (Text)'
  1729. sed 's/^X//' << 'SHAR_EOF' > 'xmfm/file_act.c' &&
  1730. /*************************************************************************
  1731. X * File: file_act.c
  1732. X * Author: Jan Newmarch
  1733. X * Last modified: $Date: 1992/11/17 00:35:42 $
  1734. X * Version: $Revision: 1.6 $
  1735. X * Purpose: read in the set of actions for files, directories 
  1736. X *          and executables. See the user manual for the syntax used.
  1737. X *          The file for these actions is $HOME/.xmfmrc
  1738. X * Revision history:
  1739. X *    4 Aug 92    added filter actions as preamble
  1740. X *    7 Aug 92    looks in XAPPRESDIR for xmfmrc
  1741. X *    11 Aug 92    added description field to xmfmrc
  1742. X *       Oct        input file format revised
  1743. X *       3 Nov 92       lint-ed
  1744. X ************************************************************************/ 
  1745. X
  1746. #include "copyright.h"
  1747. X
  1748. /*************************************************************************
  1749. X * System includes
  1750. X ************************************************************************/ 
  1751. #include <stdlib.h>
  1752. #include <stdio.h>
  1753. #include <string.h>
  1754. #include <Xm/Xm.h>
  1755. #include <X11/Intrinsic.h>
  1756. X
  1757. /*************************************************************************
  1758. X * Local includes
  1759. X ************************************************************************/ 
  1760. #include "RegExp.h"
  1761. #include "types.h"
  1762. X
  1763. /*************************************************************************
  1764. X * Functions exported
  1765. SHAR_EOF
  1766. true || echo 'restore of xmfm/file_act.c failed'
  1767. fi
  1768. echo 'End of  part 4'
  1769. echo 'File xmfm/file_act.c is continued in part 5'
  1770. echo 5 > _shar_seq_.tmp
  1771. exit 0
  1772. --
  1773. +----------------------+---+
  1774.   Jan Newmarch, Information Science and Engineering,
  1775.   University of Canberra, PO Box 1, Belconnen, Act 2616
  1776.   Australia. Tel: (Aust) 6-2012422. Fax: (Aust) 6-2015041
  1777.