cntl.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
  24. /*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
  25. /*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
  26. /*%% (c) Copyright 1993, 1994 Novell, Inc. */
  27. /*%% $TOG: cntl.c /main/4 1998/05/18 16:55:06 rafi $ */
  28. /*
  29. * cntl.c
  30. *
  31. * Copyright (c) 1993 by Sun Microsystems, Inc.
  32. */
  33. /*
  34. * An example controller for the remote-control editor defined in edit.c.
  35. * Puts up a simple panel with a text field to enter the filename to
  36. * operate on and sends out ToolTalk messages to start up an editor to
  37. * carry out the operations. Also allows browsing any sub-file specs
  38. * defined in the file.
  39. */
  40. #include <stdio.h>
  41. #include <sys/param.h>
  42. #include <sys/types.h>
  43. #include <sys/stat.h>
  44. #include <Xm/Xm.h>
  45. #include <Xm/MainW.h>
  46. #include <Xm/CascadeB.h>
  47. #include <Xm/DialogS.h>
  48. #include <Xm/Form.h>
  49. #include <Xm/Label.h>
  50. #include <Xm/List.h>
  51. #include <Xm/PushB.h>
  52. #include <Xm/Text.h>
  53. #include <Xm/Protocols.h>
  54. #include <desktop/tt_c.h>
  55. #define TITLE_LINE_HEIGHT 25
  56. Display *dpy;
  57. XtAppContext app;
  58. Widget cntl_ui_base_window;
  59. Widget cntl_ui_base_controls;
  60. Widget cntl_ui_file_button;
  61. Widget cntl_ui_file_label;
  62. Widget cntl_ui_file_field;
  63. Widget cntl_ui_message;
  64. Widget cntl_ui_file_menu;
  65. Widget cntl_ui_saveas_popup;
  66. Widget cntl_ui_saveas_controls;
  67. Widget cntl_ui_save_as_dlabel;
  68. Widget cntl_ui_save_as_directory;
  69. Widget cntl_ui_new_flabel;
  70. Widget cntl_ui_new_filename;
  71. Widget cntl_ui_save_as_button;
  72. Widget cntl_ui_obj_popup;
  73. Widget cntl_ui_obj_controls;
  74. Widget cntl_ui_olist_label;
  75. Widget cntl_ui_olist;
  76. Widget cntl_ui_hilite_button;
  77. Widget cntl_ui_obj_field;
  78. char *cntl_objid = (char *)0;
  79. Tt_scope msg_scope = TT_FILE_IN_SESSION;
  80. void
  81. main(argc, argv)
  82. int argc;
  83. char **argv;
  84. {
  85. void cntl_ui_initialize();
  86. /*
  87. * Initialize Motif.
  88. */
  89. XtToolkitInitialize();
  90. app = XtCreateApplicationContext();
  91. dpy = XtOpenDisplay(app, 0, 0, "cntl", 0, 0, &argc, argv);
  92. /*
  93. * Initialize user interface components.
  94. */
  95. cntl_ui_initialize();
  96. if (! cntl_init_tt()) {
  97. fprintf(stderr,"%s: Can't initialize ToolTalk\n", argv[0]);
  98. exit(1);
  99. }
  100. /*
  101. * Turn control over to Motif.
  102. */
  103. XtAppMainLoop(app);
  104. tt_close();
  105. exit(0);
  106. }
  107. int
  108. is_window_showing(widget)
  109. Widget widget;
  110. {
  111. return(XtIsManaged(widget)) ;
  112. }
  113. void
  114. get_screen_size(widget, width, height)
  115. Widget widget;
  116. int *width, *height;
  117. {
  118. Display *dpy = XtDisplay(widget);
  119. int screen = DefaultScreen(dpy);
  120. *width = DisplayWidth(dpy, screen);
  121. *height = DisplayHeight(dpy, screen);
  122. }
  123. void
  124. force_popup_on_screen(popup, px, py)
  125. Widget popup;
  126. int *px, *py;
  127. {
  128. Dimension popup_width, popup_height;
  129. Position left, top;
  130. int n, x, y, screen_width, screen_height;
  131. x = *px;
  132. y = *py;
  133. /* Get the screen size. */
  134. get_screen_size(popup, &screen_width, &screen_height);
  135. XtVaGetValues(popup,
  136. XmNwidth, &popup_width,
  137. XmNheight, &popup_height,
  138. 0);
  139. /* Make sure frame does not go off side of screen. */
  140. n = x + (int) popup_width;
  141. if (n > screen_width) x -= (n - screen_width);
  142. else if (x < 0) x = 0;
  143. /* Make sure frame doen't go off top or bottom. */
  144. n = y + (int) popup_height;
  145. if (n > screen_height) y -= n - screen_height;
  146. else if (y < 0) y = 0;
  147. /* Set location and return. */
  148. left = (Position) x;
  149. top = (Position) y;
  150. XtVaSetValues(popup,
  151. XmNx, left,
  152. XmNy, top,
  153. 0);
  154. *px = x;
  155. *py = y;
  156. }
  157. void
  158. position_popup(base, popup)
  159. Widget base, popup;
  160. {
  161. int bw, bx, by, px, py;
  162. int screen_width, screen_height;
  163. Position base_x, base_y, popup_x, popup_y;
  164. Dimension base_width, base_height, popup_width, popup_height;
  165. XtVaGetValues(base,
  166. XmNx, &base_x,
  167. XmNy, &base_y,
  168. XmNwidth, &base_width,
  169. XmNheight, &base_height,
  170. 0);
  171. bx = (int) base_x;
  172. by = (int) base_y;
  173. bw = (int) base_width;
  174. XtVaGetValues(popup,
  175. XmNx, &popup_x,
  176. XmNy, &popup_y,
  177. XmNwidth, &popup_width,
  178. XmNheight, &popup_height,
  179. 0);
  180. px = (int) popup_x;
  181. py = (int) popup_y;
  182. get_screen_size(popup, &screen_width, &screen_height);
  183. px = bx + bw + 5;
  184. py = by - TITLE_LINE_HEIGHT;
  185. force_popup_on_screen(popup, &px, &py);
  186. }
  187. void
  188. show_popup(widget)
  189. Widget widget;
  190. {
  191. if (!is_window_showing(widget))
  192. position_popup(cntl_ui_base_window, widget) ;
  193. XtMapWidget(widget);
  194. XtManageChild(widget);
  195. XtPopup(XtParent(widget), XtGrabNone);
  196. }
  197. void
  198. dismiss_popup(widget, client_data, cbs)
  199. Widget widget;
  200. XtPointer client_data;
  201. XmAnyCallbackStruct *cbs;
  202. {
  203. XtUnmapWidget(widget);
  204. XtUnmanageChild(widget);
  205. }
  206. void
  207. add_delete_callback(widget)
  208. Widget widget;
  209. {
  210. Atom WM_DELETE_WINDOW;
  211. WM_DELETE_WINDOW = XmInternAtom(XtDisplay(widget),
  212. "WM_DELETE_WINDOW", False);
  213. XmAddWMProtocolCallback(widget, WM_DELETE_WINDOW,
  214. (XtCallbackProc) dismiss_popup, NULL);
  215. }
  216. void
  217. write_footer(message)
  218. char *message;
  219. {
  220. XmString label;
  221. label = XmStringCreateSimple(message);
  222. XtVaSetValues(cntl_ui_message, XmNlabelString, label, 0);
  223. XmStringFree(label);
  224. }
  225. /*
  226. * Initialize our ToolTalk environment.
  227. */
  228. int
  229. cntl_init_tt()
  230. {
  231. char *procid = tt_open();
  232. int ttfd;
  233. void cntl_receive_tt_message();
  234. Tt_pattern pat;
  235. Tt_callback_action cntl_update_obj_panel_callback();
  236. if (tt_pointer_error(procid) != TT_OK) {
  237. return 0;
  238. }
  239. ttfd = tt_fd();
  240. /* register a dynamic pattern to catch whenever the remote */
  241. /* editor creates a sub-file object so that we can update our */
  242. /* object query panel. */
  243. pat = tt_pattern_create();
  244. tt_pattern_op_add(pat, "Sun_EditDemo_new_object");
  245. tt_pattern_scope_add(pat, msg_scope);
  246. tt_pattern_category_set(pat, TT_OBSERVE);
  247. tt_pattern_callback_add(pat, cntl_update_obj_panel_callback);
  248. if (tt_pattern_register(pat) != TT_OK) {
  249. return 0;
  250. }
  251. XtAppAddInput(app, ttfd, (XtPointer) XtInputReadMask,
  252. cntl_receive_tt_message, 0);
  253. tt_session_join(tt_default_session());
  254. tt_free(procid);
  255. return 1;
  256. }
  257. /*
  258. * Handle any incoming ToolTalk messages. Since all the messages we send
  259. * out have callback functions, no further action is required after doing
  260. * a tt_message_receive.
  261. */
  262. void
  263. cntl_receive_tt_message(client_data, fid, id)
  264. XtPointer client_data;
  265. int *fid;
  266. XtInputId *id;
  267. {
  268. Tt_message msg;
  269. msg = tt_message_receive();
  270. if (msg != NULL && tt_pointer_error(msg) == TT_ERR_NOMP) {
  271. fprintf(stderr,"ToolTalk server down.\n");
  272. exit(0);
  273. }
  274. }
  275. /*
  276. * Callback for our dynamic pattern informing us when an object has
  277. * been added to a file. We use this information to update the file
  278. * objects panel if it is up.
  279. */
  280. Tt_callback_action
  281. cntl_update_obj_panel_callback(m, p)
  282. Tt_message m;
  283. Tt_pattern p;
  284. {
  285. int mark;
  286. mark = tt_mark();
  287. if (cntl_is_same_file(tt_message_file(m),
  288. XmTextGetString(cntl_ui_file_field))) {
  289. /* update the objects panel if it's showing */
  290. /* objects for the same file as the one in the */
  291. /* message. */
  292. cntl_update_obj_panel();
  293. }
  294. /*
  295. * no further action required for this message. Destroy it
  296. * and return TT_CALLBACK_PROCESSED so no other callbacks will
  297. * be run for the message.
  298. */
  299. tt_message_destroy(m);
  300. tt_release(mark);
  301. return TT_CALLBACK_PROCESSED;
  302. }
  303. /*
  304. * Default callback for all the ToolTalk messages we send.
  305. */
  306. Tt_callback_action
  307. cntl_msg_callback(m, p)
  308. Tt_message m;
  309. Tt_pattern p;
  310. {
  311. int mark;
  312. char msg[255];
  313. char *errstr;
  314. mark = tt_mark();
  315. switch (tt_message_state(m)) {
  316. case TT_STARTED:
  317. write_footer("Starting editor...");
  318. break;
  319. case TT_HANDLED:
  320. write_footer("");
  321. break;
  322. case TT_FAILED:
  323. errstr = tt_message_status_string(m);
  324. if (tt_pointer_error(errstr) == TT_OK && errstr) {
  325. sprintf(msg,"%s failed: %s", tt_message_op(m), errstr);
  326. } else if (tt_message_status(m) == TT_ERR_NO_MATCH) {
  327. sprintf(msg,"%s failed: Couldn't contact editor",
  328. tt_message_op(m),
  329. tt_status_message(tt_message_status(m)));
  330. } else {
  331. sprintf(msg,"%s failed: %s",
  332. tt_message_op(m),
  333. tt_status_message(tt_message_status(m)));
  334. }
  335. write_footer(msg);
  336. break;
  337. default:
  338. break;
  339. }
  340. /*
  341. * no further action required for this message. Destroy it
  342. * and return TT_CALLBACK_PROCESSED so no other callbacks will
  343. * be run for the message.
  344. */
  345. tt_message_destroy(m);
  346. tt_release(mark);
  347. return TT_CALLBACK_PROCESSED;
  348. }
  349. /*
  350. * Handle the edit actions by sending out a message to Sun_EditDemo to
  351. * start an editing session.
  352. */
  353. void
  354. cntl_edit(file)
  355. char *file;
  356. {
  357. Tt_message msg;
  358. write_footer("");
  359. msg = tt_prequest_create(msg_scope, "Sun_EditDemo_edit");
  360. tt_message_file_set(msg, file);
  361. tt_message_callback_add(msg, cntl_msg_callback);
  362. tt_message_send(msg);
  363. }
  364. /*
  365. * Handle the save actions by sending out a message to the Sun_EditDemo
  366. * editing this file to save the file.
  367. */
  368. void
  369. cntl_save(file)
  370. char *file;
  371. {
  372. Tt_message msg;
  373. write_footer("");
  374. msg = tt_prequest_create(msg_scope, "Sun_EditDemo_save");
  375. tt_message_file_set(msg, file);
  376. tt_message_callback_add(msg, cntl_msg_callback);
  377. tt_message_send(msg);
  378. }
  379. /*
  380. * Shut down the Sun_EditDemo that is editing this file.
  381. */
  382. void
  383. cntl_close(file)
  384. char *file;
  385. {
  386. Tt_message msg;
  387. write_footer("");
  388. msg = tt_prequest_create(msg_scope, "Sun_EditDemo_close");
  389. tt_message_file_set(msg, file);
  390. tt_message_callback_add(msg, cntl_msg_callback);
  391. tt_message_send(msg);
  392. }
  393. /*
  394. * Instruct the Sun_EditDemo that is editing this file to save the file
  395. * under a new name.
  396. */
  397. void
  398. cntl_save_as(file, dir, newfile)
  399. char *file;
  400. char *dir;
  401. char *newfile;
  402. {
  403. Tt_message msg;
  404. char buf[255];
  405. int dirlen;
  406. msg = tt_prequest_create(msg_scope, "Sun_EditDemo_save_as");
  407. /* construct new filename out of directory and new file */
  408. /* fields. */
  409. dirlen = strlen(dir);
  410. if (dirlen > 0 && dir[dirlen - 1] == '/') {
  411. sprintf(buf,"%s%s", dir, newfile);
  412. } else {
  413. sprintf(buf,"%s/%s", dir, newfile);
  414. }
  415. tt_message_arg_add(msg, TT_IN, "string", buf);
  416. tt_message_file_set(msg, file);
  417. tt_message_callback_add(msg, cntl_msg_callback);
  418. tt_message_send(msg);
  419. }
  420. /*
  421. * Handler for `file_menu (Edit)'.
  422. */
  423. void
  424. cntl_ui_edit(widget, client_data, call_data)
  425. Widget widget;
  426. XtPointer client_data, call_data;
  427. {
  428. write_footer("");
  429. cntl_edit(XmTextGetString(cntl_ui_file_field));
  430. }
  431. /*
  432. * Handler for `file_menu (Save)'.
  433. */
  434. void
  435. cntl_ui_save(widget, client_data, call_data)
  436. Widget widget;
  437. XtPointer client_data, call_data;
  438. {
  439. write_footer("");
  440. cntl_save(XmTextGetString(cntl_ui_file_field));
  441. }
  442. /*
  443. * Handler for `file_menu (Save as...)'.
  444. */
  445. cntl_ui_save_as(widget, client_data, call_data)
  446. Widget widget;
  447. XtPointer client_data, call_data;
  448. {
  449. write_footer("");
  450. show_popup(cntl_ui_saveas_popup);
  451. }
  452. /*
  453. * Handler for `file_menu (Close)'.
  454. */
  455. cntl_ui_close(widget, client_data, call_data)
  456. Widget widget;
  457. XtPointer client_data, call_data;
  458. {
  459. write_footer("");
  460. cntl_close(XmTextGetString(cntl_ui_file_field));
  461. }
  462. /*
  463. * Callback function for `save_as_button'.
  464. */
  465. void
  466. cntl_ui_save_as_button_handler(widget, client_data, call_data)
  467. Widget widget;
  468. XtPointer client_data, call_data;
  469. {
  470. write_footer("");
  471. cntl_save_as(XmTextGetString(cntl_ui_file_field),
  472. XmTextGetString(cntl_ui_save_as_directory),
  473. XmTextGetString(cntl_ui_new_filename));
  474. }
  475. /*
  476. * Function to insert the objid given into the scrolling lists of objects
  477. * for a file. Used inside tt_file_objects_query as it iterates through
  478. * all the ToolTalk objects in a file.
  479. */
  480. Tt_filter_action
  481. cntl_gather_specs(objid, list_count, acc)
  482. char *objid;
  483. void *list_count;
  484. void *acc;
  485. {
  486. int *i = (int *)list_count;
  487. XmString label;
  488. label = XmStringCreateSimple(objid);
  489. XmListAddItem(cntl_ui_olist, label, *i);
  490. XmStringFree(label);
  491. *i = (*i + 1);
  492. /* continue processing */
  493. return TT_FILTER_CONTINUE;
  494. }
  495. /*
  496. * Called to update the scrolling list of objects for a file. Uses
  497. * tt_file_objects_query to find all the ToolTalk objects.
  498. */
  499. int
  500. cntl_update_obj_panel()
  501. {
  502. static int list_item = 0;
  503. char *file;
  504. int i;
  505. cntl_objid = (char *)0;
  506. for (i = list_item; i >= 0; i--) {
  507. XmListDeletePos(cntl_ui_olist, i);
  508. }
  509. list_item = 0;
  510. file = XmTextGetString(cntl_ui_file_field);
  511. if (tt_file_objects_query(file,
  512. (Tt_filter_function)cntl_gather_specs,
  513. &list_item, NULL) != TT_OK) {
  514. write_footer("Couldn't query objects for file");
  515. return 0;
  516. }
  517. return 1;
  518. }
  519. /*
  520. * Callback function for "File objects..." menu item.
  521. */
  522. void
  523. cntl_ui_file_objects(widget, client_data, call_data)
  524. Widget widget;
  525. XtPointer client_data, call_data;
  526. {
  527. char *string;
  528. write_footer("");
  529. string = XmTextGetString(cntl_ui_file_field);
  530. if (cntl_update_obj_panel()) {
  531. (void) tt_file_join(XmTextGetString(cntl_ui_file_field));
  532. show_popup(cntl_ui_obj_popup);
  533. }
  534. }
  535. /*
  536. * Notify callback function for `cntl_ui_olist'.
  537. */
  538. void
  539. cntl_ui_olist_handler(widget, client_data, cbs)
  540. Widget widget;
  541. XtPointer client_data;
  542. XmListCallbackStruct *cbs;
  543. {
  544. char *string;
  545. string = XmStringUnparse(cbs->item, NULL, XmCHARSET_TEXT, XmCHARSET_TEXT,
  546. NULL, 0, XmOUTPUT_ALL);
  547. cntl_objid = strdup(string);
  548. XtFree (string);
  549. }
  550. /*
  551. * Notify callback function for `cntl_ui_hilite_button'.
  552. */
  553. void
  554. cntl_ui_hilite_button_handler(widget, client_data, call_data)
  555. Widget widget;
  556. XtPointer client_data, call_data;
  557. {
  558. Tt_message msg;
  559. if (cntl_objid == (char *)0) {
  560. write_footer("No object id selected");
  561. return;
  562. }
  563. msg = tt_orequest_create(cntl_objid, "hilite_obj");
  564. tt_message_arg_add(msg, TT_IN, "string", cntl_objid);
  565. tt_message_callback_add(msg, cntl_msg_callback);
  566. tt_message_send(msg);
  567. }
  568. /*
  569. * Initialize ui environment.
  570. */
  571. void
  572. cntl_ui_initialize()
  573. {
  574. Arg args[20];
  575. int n;
  576. Widget but;
  577. XmString label;
  578. void cntl_ui_saveas_popup_initialize();
  579. void cntl_ui_obj_popup_initialize();
  580. cntl_ui_base_window = XtAppCreateShell(0, "base_frame",
  581. applicationShellWidgetClass, dpy, 0, 0 );
  582. XtVaSetValues(cntl_ui_base_window,
  583. XmNwidth, 339,
  584. XmNheight, 100,
  585. XmNtitle, "Sun_EditDemo_cntl",
  586. 0);
  587. cntl_ui_base_controls = XtVaCreateManagedWidget("controls",
  588. xmFormWidgetClass, cntl_ui_base_window, 0 );
  589. n = 0;
  590. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  591. XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  592. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  593. XtSetArg(args[n], XmNleftOffset, 5); n++;
  594. XtSetArg(args[n], XmNrightOffset, 5); n++;
  595. XtSetArg(args[n], XmNtopOffset, 5); n++;
  596. cntl_ui_file_menu = (Widget) XmCreateMenuBar(cntl_ui_base_controls,
  597. "menubar", args, n);
  598. cntl_ui_file_button = (Widget) XmCreatePulldownMenu(cntl_ui_file_menu,
  599. "File", NULL, 0);
  600. label = XmStringCreateSimple("File");
  601. XtVaCreateManagedWidget("File",
  602. xmCascadeButtonWidgetClass, cntl_ui_file_menu,
  603. XmNlabelString, label,
  604. XmNmnemonic, 'F',
  605. XmNsubMenuId, cntl_ui_file_button,
  606. 0);
  607. XmStringFree(label);
  608. but = XtVaCreateManagedWidget("Edit",
  609. xmPushButtonWidgetClass, cntl_ui_file_button, 0);
  610. XtAddCallback(but, XmNactivateCallback,
  611. (XtCallbackProc) cntl_ui_edit, 0);
  612. but = XtVaCreateManagedWidget("Save",
  613. xmPushButtonWidgetClass, cntl_ui_file_button, 0);
  614. XtAddCallback(but, XmNactivateCallback,
  615. (XtCallbackProc) cntl_ui_save, 0);
  616. but = XtVaCreateManagedWidget("Save as...",
  617. xmPushButtonWidgetClass, cntl_ui_file_button, 0);
  618. XtAddCallback(but, XmNactivateCallback,
  619. (XtCallbackProc) cntl_ui_save_as, 0);
  620. but = XtVaCreateManagedWidget("File Objects...",
  621. xmPushButtonWidgetClass, cntl_ui_file_button, 0);
  622. XtAddCallback(but, XmNactivateCallback,
  623. (XtCallbackProc) cntl_ui_file_objects, 0);
  624. but = XtVaCreateManagedWidget("Close",
  625. xmPushButtonWidgetClass, cntl_ui_file_button, 0);
  626. XtAddCallback(but, XmNactivateCallback,
  627. (XtCallbackProc) cntl_ui_close, 0);
  628. XtManageChild(cntl_ui_file_menu);
  629. cntl_ui_file_label = XtVaCreateManagedWidget("File:",
  630. xmLabelWidgetClass, cntl_ui_base_controls,
  631. XmNtopAttachment, XmATTACH_WIDGET,
  632. XmNtopWidget, cntl_ui_file_menu,
  633. XmNtopOffset, 5,
  634. XmNleftAttachment, XmATTACH_FORM,
  635. XmNleftOffset, 5,
  636. 0);
  637. label = XmStringCreateSimple("File:");
  638. XtVaSetValues(cntl_ui_file_label, XmNlabelString, label, 0);
  639. XmStringFree(label);
  640. cntl_ui_file_field = XtVaCreateManagedWidget("text",
  641. xmTextWidgetClass, cntl_ui_base_controls,
  642. XmNtopAttachment, XmATTACH_WIDGET,
  643. XmNtopWidget, cntl_ui_file_menu,
  644. XmNtopOffset, 5,
  645. XmNleftAttachment, XmATTACH_WIDGET,
  646. XmNleftWidget, cntl_ui_file_label,
  647. XmNleftOffset, 5,
  648. XmNrightAttachment, XmATTACH_FORM,
  649. XmNrightOffset, 5,
  650. 0);
  651. label = XmStringCreateSimple("");
  652. XtVaSetValues(cntl_ui_file_field, XmNlabelString, label, 0);
  653. XmStringFree(label);
  654. cntl_ui_message = XtVaCreateManagedWidget("message",
  655. xmLabelWidgetClass, cntl_ui_base_controls,
  656. XmNtopAttachment, XmATTACH_WIDGET,
  657. XmNtopWidget, cntl_ui_file_field,
  658. XmNtopOffset, 10,
  659. XmNleftAttachment, XmATTACH_FORM,
  660. XmNleftOffset, 5,
  661. XmNrightAttachment, XmATTACH_FORM,
  662. XmNrightOffset, 5,
  663. XmNbottomAttachment, XmATTACH_FORM,
  664. XmNbottomOffset, 5,
  665. 0);
  666. label = XmStringCreateSimple("");
  667. XtVaSetValues(cntl_ui_message, XmNlabelString, label, 0);
  668. XmStringFree(label);
  669. XtRealizeWidget(cntl_ui_base_window);
  670. cntl_ui_saveas_popup_initialize();
  671. cntl_ui_obj_popup_initialize();
  672. }
  673. void
  674. cntl_ui_saveas_popup_initialize()
  675. {
  676. Arg args[10];
  677. int n;
  678. XmString label;
  679. n = 0;
  680. XtSetArg(args[n], XmNtitle, "Sun_EditMenu_cntl: Save As"); n++;
  681. XtSetArg(args[n], XmNmappedWhenManaged, False); n++;
  682. XtSetArg(args[n], XmNdeleteResponse, XmDO_NOTHING); n++;
  683. cntl_ui_saveas_popup = XmCreateDialogShell(cntl_ui_base_window,
  684. "saveas", args, n);
  685. cntl_ui_saveas_controls = XtVaCreateManagedWidget("controls",
  686. xmFormWidgetClass, cntl_ui_saveas_popup,
  687. XmNrubberPositioning, False,
  688. XmNresizePolicy, XmRESIZE_ANY,
  689. XmNautoUnmanage, False,
  690. XmNwidth, 350,
  691. XmNheight, 120,
  692. 0);
  693. label = XmStringCreateSimple("Directory:");
  694. cntl_ui_save_as_dlabel = XtVaCreateManagedWidget("dlabel",
  695. xmLabelWidgetClass, cntl_ui_saveas_controls,
  696. XmNtopAttachment, XmATTACH_FORM,
  697. XmNtopOffset, 5,
  698. XmNleftAttachment, XmATTACH_FORM,
  699. XmNleftOffset, 5,
  700. XmNlabelString, label,
  701. 0);
  702. XmStringFree(label);
  703. cntl_ui_save_as_directory = XtVaCreateManagedWidget("text",
  704. xmTextWidgetClass, cntl_ui_saveas_controls,
  705. XmNcolumns, 35,
  706. XmNtopAttachment, XmATTACH_FORM,
  707. XmNtopOffset, 5,
  708. XmNleftAttachment, XmATTACH_WIDGET,
  709. XmNleftWidget, cntl_ui_save_as_dlabel,
  710. XmNleftOffset, 5,
  711. XmNrightAttachment, XmATTACH_FORM,
  712. XmNrightOffset, 5,
  713. 0);
  714. label = XmStringCreateSimple("Filename:");
  715. cntl_ui_new_flabel = XtVaCreateManagedWidget("flabel",
  716. xmLabelWidgetClass, cntl_ui_saveas_controls,
  717. XmNtopAttachment, XmATTACH_WIDGET,
  718. XmNtopWidget, cntl_ui_save_as_directory,
  719. XmNtopOffset, 5,
  720. XmNleftAttachment, XmATTACH_FORM,
  721. XmNleftOffset, 5,
  722. XmNlabelString, label,
  723. 0);
  724. XmStringFree(label);
  725. label = XmStringCreateSimple("");
  726. cntl_ui_new_filename = XtVaCreateManagedWidget("text",
  727. xmTextWidgetClass, cntl_ui_saveas_controls,
  728. XmNcolumns, 35,
  729. XmNlabelString, label,
  730. XmNtopAttachment, XmATTACH_WIDGET,
  731. XmNtopWidget, cntl_ui_save_as_directory,
  732. XmNtopOffset, 5,
  733. XmNleftAttachment, XmATTACH_WIDGET,
  734. XmNleftWidget, cntl_ui_save_as_dlabel,
  735. XmNleftOffset, 5,
  736. XmNrightAttachment, XmATTACH_FORM,
  737. XmNrightOffset, 5,
  738. 0);
  739. XmStringFree(label);
  740. label = XmStringCreateSimple("Save");
  741. cntl_ui_save_as_button = XtVaCreateManagedWidget("button",
  742. xmPushButtonWidgetClass, cntl_ui_saveas_controls,
  743. XmNleftAttachment, XmATTACH_FORM,
  744. XmNleftOffset, 5,
  745. XmNtopAttachment, XmATTACH_WIDGET,
  746. XmNtopWidget, cntl_ui_new_filename,
  747. XmNtopOffset, 5,
  748. XmNbottomAttachment, XmATTACH_FORM,
  749. XmNbottomOffset, 5,
  750. XmNlabelString, label,
  751. 0);
  752. XmStringFree(label);
  753. XtAddCallback(cntl_ui_save_as_button,
  754. XmNactivateCallback, cntl_ui_save_as_button_handler, 0);
  755. XtManageChild(cntl_ui_saveas_controls);
  756. add_delete_callback(cntl_ui_saveas_popup);
  757. }
  758. void
  759. cntl_ui_obj_popup_initialize()
  760. {
  761. int n;
  762. Arg args[20];
  763. XmString label;
  764. n = 0;
  765. XtSetArg(args[n], XmNtitle, "Sun_EditMenu_cntl: File Objects"); n++;
  766. XtSetArg(args[n], XmNmappedWhenManaged, False); n++;
  767. XtSetArg(args[n], XmNdeleteResponse, XmDO_NOTHING); n++;
  768. cntl_ui_obj_popup = XmCreateDialogShell(cntl_ui_base_window,
  769. "object", args, n);
  770. cntl_ui_obj_controls = XtVaCreateManagedWidget("controls",
  771. xmFormWidgetClass, cntl_ui_obj_popup,
  772. XmNrubberPositioning, False,
  773. XmNresizePolicy, XmRESIZE_ANY,
  774. XmNautoUnmanage, False,
  775. XmNwidth, 350,
  776. XmNheight, 120,
  777. 0);
  778. n = 0;
  779. label = XmStringCreateSimple("File Objects:");
  780. XtSetArg(args[n], XmNlabelString, label); n++;
  781. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  782. XtSetArg(args[n], XmNleftOffset, 5); n++;
  783. XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  784. XtSetArg(args[n], XmNtopOffset, 5); n++;
  785. cntl_ui_olist_label =
  786. XmCreateLabel(cntl_ui_obj_controls, "label", args, n);
  787. XmStringFree(label);
  788. XtManageChild(cntl_ui_olist_label);
  789. n = 0;
  790. XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  791. XtSetArg(args[n], XmNtopOffset, 5); n++;
  792. XtSetArg(args[n], XmNvisibleItemCount, 4); n++;
  793. XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  794. XtSetArg(args[n], XmNleftWidget, cntl_ui_olist_label); n++;
  795. XtSetArg(args[n], XmNleftOffset, 5); n++;
  796. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  797. XtSetArg(args[n], XmNrightOffset, 5); n++;
  798. XtSetArg(args[n], XmNresizable, True); n++;
  799. cntl_ui_olist =
  800. XmCreateScrolledList(cntl_ui_obj_controls, "olist", args, n);
  801. XtAddCallback(cntl_ui_olist,
  802. XmNsingleSelectionCallback, cntl_ui_olist_handler, 0);
  803. XtManageChild(cntl_ui_olist);
  804. label = XmStringCreateSimple("Display");
  805. cntl_ui_hilite_button = XtVaCreateManagedWidget("button",
  806. xmPushButtonWidgetClass, cntl_ui_obj_controls,
  807. XmNtopAttachment, XmATTACH_WIDGET,
  808. XmNtopWidget, cntl_ui_olist,
  809. XmNtopOffset, 5,
  810. XmNbottomAttachment, XmATTACH_FORM,
  811. XmNbottomOffset, 5,
  812. XmNlabelString, label,
  813. 0);
  814. XmStringFree(label);
  815. XtAddCallback(cntl_ui_hilite_button,
  816. XmNactivateCallback, cntl_ui_hilite_button_handler, 0);
  817. XtManageChild(cntl_ui_obj_controls);
  818. add_delete_callback(cntl_ui_obj_popup);
  819. }
  820. int
  821. cntl_is_same_file(f1, f2)
  822. char *f1;
  823. char *f2;
  824. {
  825. struct stat f1_stat;
  826. struct stat f2_stat;
  827. if (!strcmp(f1,f2)) {
  828. return(1);
  829. }
  830. return((0 == stat(f1, &f1_stat)) &&
  831. (0 == stat(f2, &f2_stat)) &&
  832. (f1_stat.st_ino == f2_stat.st_ino) &&
  833. (f1_stat.st_dev == f2_stat.st_dev));
  834. }