process.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995
  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. /* $TOG: process.c /main/7 1999/08/16 11:03:31 mgreess $ */
  24. /********************************************************************
  25. * (c) Copyright 1993, 1994 Hewlett-Packard Company
  26. * (c) Copyright 1993, 1994 International Business Machines Corp.
  27. * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  28. * (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
  29. * Novell, Inc.
  30. **********************************************************************/
  31. /******************************************************************************
  32. ** Program: dticon.c
  33. **
  34. ** Description: X11-based multi-color icon editor
  35. **
  36. ** File: process.c, which contains the following subroutines or
  37. ** functions:
  38. ** Process_New()
  39. ** Process_Open()
  40. ** Process_Save()
  41. ** Process_SaveAs()
  42. ** Process_Quit()
  43. ** Process_Query_OK()
  44. ** Process_Query_Cancel()
  45. ** Process_Size_OK()
  46. ** Eval_NewSize()
  47. ** Process_Size_Cancel()
  48. ** Process_StdErr_OK()
  49. ** Process_Undo()
  50. ** Process_Cut()
  51. ** Process_Copy()
  52. ** Process_Paste()
  53. ** Process_Scale()
  54. ** Process_Resize()
  55. ** Process_AddHotspot()
  56. ** Process_DeleteHotspot()
  57. ** Process_Clear()
  58. ** Process_RotateLeft()
  59. ** Process_RotateRight()
  60. ** Process_FlipV()
  61. ** Process_FlipH()
  62. ** Process_GridState()
  63. ** Process_DropCheckOp()
  64. ** Do_DropCheckOp()
  65. ** Process_DropOp()
  66. ** Do_Paste()
  67. ** Do_DropOp()
  68. **
  69. ******************************************************************************
  70. **
  71. ** Copyright Hewlett-Packard Company, 1990, 1991, 1992.
  72. ** All rights are reserved. Copying or reproduction of this program,
  73. ** except for archival purposes, is prohibited without prior written
  74. ** consent of Hewlett-Packard Company.
  75. **
  76. ** Hewlett-Packard makes no representations about the suitibility of this
  77. ** software for any purpose. It is provided "as is" without express or
  78. ** implied warranty.
  79. **
  80. *****************************************************************************
  81. */
  82. #include <Xm/Xm.h>
  83. #include <Xm/XmP.h>
  84. #include <Xm/TextF.h>
  85. #include <stdlib.h>
  86. #include "externals.h"
  87. #include <string.h>
  88. #include <unistd.h>
  89. #include <Xm/DragC.h>
  90. #include <Dt/Dnd.h>
  91. #include <Dt/Connect.h>
  92. #include <Dt/HelpDialog.h>
  93. #include "main.h"
  94. #include "utils.h"
  95. #include "process.h"
  96. #include "graphics.h"
  97. #include "image.h"
  98. #include "fileIO.h"
  99. #ifdef __TOOLTALK
  100. #include <Tt/tttk.h>
  101. extern void ReplyToMessage( );
  102. extern Tt_message replyMsg;
  103. int edit_notifier(char* fname, Tt_message msg, int clear);
  104. #endif
  105. static void Do_DropCheckOp(DtDndTransferCallback);
  106. static void Do_DropOp(void);
  107. extern Widget optionsMenu_grid;
  108. extern Widget editMenu_paste_pb;
  109. extern Widget editMenu_cut_pb;
  110. extern Widget editMenu_copy_pb;
  111. extern Widget editMenu_rotate_pb;
  112. extern Widget editMenu_flip_pb;
  113. extern Widget editMenu_scale_pb;
  114. extern Widget editMenu_undo_pb;
  115. extern Widget newWidthText, newHeightText;
  116. extern GC scratch_gc;
  117. extern char dummy[];
  118. Boolean Write_File( char * );
  119. Boolean Read_File( char * );
  120. extern void Process_SaveAs(void);
  121. extern void Eval_NewSize(int, int);
  122. extern void Process_Copy(XImage **, XImage **);
  123. extern void Process_Resize(void);
  124. /*-----------------------------------------------------------*/
  125. /* Insert application global declarations here */
  126. /*-----------------------------------------------------------*/
  127. static char undo_file[MAX_FNAME]; /* save the file name after new */
  128. char dropFileName[MAX_FNAME];
  129. int SaveMeNot = TRUE; /* used to flag a save as for existing file */
  130. int SavedOnce = False;
  131. int NewFlag = False; /* use for undo after new */
  132. /***************************************************************************
  133. * *
  134. * Routine: Process_New *
  135. * *
  136. * Purpose: Process the selection of the NEW button in the 'File' *
  137. * pulldown menu. If the 'Dirty' flag is set, changes have *
  138. * been made to the drawing tablet since the last save, which *
  139. * would be lost by quitting. Notify the user of this and *
  140. * allow them the chance to change their minds. If they do *
  141. * not, pop-up the NewIconDialog for the user to select new *
  142. * dimensions (if desired) for the new icon. *
  143. * *
  144. ***************************************************************************/
  145. void
  146. Process_New( void )
  147. {
  148. DialogFlag = NEW;
  149. if (Dirty)
  150. DoQueryDialog( GETSTR(16,16, "The current icon has not been saved.\n\nYour changes will be lost.") );
  151. else {
  152. Process_Resize();
  153. DialogFlag = NONE; }
  154. }
  155. /***************************************************************************
  156. * *
  157. * Routine: Process_Open *
  158. * *
  159. * Purpose: Process the selection of the OPEN button in the 'File' *
  160. * pulldown menu. If the 'Dirty' flag is set, changes have *
  161. * been made to the drawing tablet since the last save, which *
  162. * would be lost by quitting. Notify the user of this and *
  163. * allow them the chance to change their minds. If they do *
  164. * not, pop-up the FileSelectionDialog for the user to select *
  165. * the new file to be loaded. *
  166. * *
  167. ***************************************************************************/
  168. void
  169. Process_Open( void )
  170. {
  171. DialogFlag = OPEN;
  172. fileIOMode = FILE_READ;
  173. if (Dirty)
  174. DoQueryDialog( GETSTR(16,16, "The current icon has not been saved.\nYour changes will be lost.") );
  175. else
  176. {
  177. XtManageChild(fileIODialog);
  178. SetFileIODialogInfo();
  179. }
  180. }
  181. /***************************************************************************
  182. * *
  183. * Routine: Process_Save *
  184. * *
  185. * Purpose: Process the selection of the SAVE button in the 'File' *
  186. * pulldown menu. This automatically saves the current icon *
  187. * to the same file it was loaded from, or saved to the last *
  188. * time. If this file was created 'from scratch' and no *
  189. * previous save operation has taken place, selecting this *
  190. * operation behaves the same way that the SAVE_AS operation *
  191. * behaves. *
  192. * *
  193. ***************************************************************************/
  194. void
  195. Process_Save( void )
  196. {
  197. static char *untitledStr = NULL;
  198. static char newName[MAX_FNAME];
  199. char *tmp1 = NULL;
  200. char *tmp2 = NULL;
  201. int c;
  202. DialogFlag = SAVE;
  203. fileIOMode = FILE_WRITE;
  204. untitledStr = GETSTR(2,20, "UNTITLED");
  205. tmp1= strrchr(last_fname, '/');
  206. if (tmp1) {
  207. c = tmp1[1];
  208. tmp2 = strchr(tmp1, c);
  209. if(tmp2) {
  210. snprintf(newName, sizeof(newName), "%s", tmp2);
  211. }
  212. }
  213. if (strncmp(newName, untitledStr, 8) == 0 || last_fname[0] == '\0') Process_SaveAs();
  214. else
  215. {
  216. if (SavedOnce == True)
  217. {
  218. if (!Write_File(last_fname))
  219. DoErrorDialog( GETSTR(16,4, "Unable to write data to file") );
  220. else
  221. Dirty = False;
  222. }
  223. else
  224. Process_SaveAs();
  225. }
  226. }
  227. /***************************************************************************
  228. * *
  229. * Routine: Process_SaveAs *
  230. * *
  231. * Purpose: Process the selection of the SAVE_AS button in the 'File' *
  232. * pulldown menu. This pops-up the FileSelectionDialog which *
  233. * prompts the user to select the file in which to save the *
  234. * current icon. *
  235. * *
  236. ***************************************************************************/
  237. void
  238. Process_SaveAs( void )
  239. {
  240. DialogFlag = SAVE_AS;
  241. fileIOMode = FILE_WRITE;
  242. XtManageChild(fileIODialog);
  243. SetFileIODialogInfo();
  244. }
  245. /***************************************************************************
  246. * *
  247. * Routine: Process_Quit *
  248. * *
  249. * Purpose: Process the selection of the QUIT button in the 'File' *
  250. * pulldown menu. If the 'Dirty' flag is set, changes have *
  251. * been made to the drawing tablet since the last save, which *
  252. * would be lost by quitting. Notify the user of this and *
  253. * allow them the chance to change their minds. *
  254. * *
  255. ***************************************************************************/
  256. void
  257. Process_Quit( void )
  258. {
  259. extern int ttMark;
  260. extern int tt_tmpfile_fd;
  261. DialogFlag = QUIT;
  262. if (Dirty)
  263. DoQueryDialog( GETSTR(16,16, "The current icon has not been saved.\nYour changes will be lost.") );
  264. else {
  265. #ifdef __TOOLTALK
  266. edit_notifier(NULL, 0, 1);
  267. ttdt_session_quit( 0, 0, 1 );
  268. ttdt_close( 0, 0, 1 );
  269. tt_release( ttMark );
  270. if (tt_tmpfile_fd != -1) {
  271. unlink(last_fname);
  272. if (fileFormat != FORMAT_XPM ) {
  273. unlink(dummy);
  274. } /* if */
  275. } /* if */
  276. #endif
  277. exit(0);
  278. } /* else */
  279. }
  280. /*****************************************************************************/
  281. void
  282. Process_Query_OK( void )
  283. {
  284. extern int ttMark;
  285. extern int tt_tmpfile_fd;
  286. switch (DialogFlag) {
  287. case QUIT :
  288. #ifdef __TOOLTALK
  289. edit_notifier(NULL, 0, 1);
  290. ttdt_session_quit( 0, 0, 1 );
  291. ttdt_close( 0, 0, 1 );
  292. tt_release( ttMark );
  293. if (tt_tmpfile_fd != -1) {
  294. unlink(last_fname);
  295. if (fileFormat != FORMAT_XPM ) {
  296. unlink(dummy);}
  297. }
  298. #endif
  299. exit(0);
  300. break;
  301. case NEW : Process_Resize();
  302. DialogFlag= NONE;
  303. break;
  304. case OPEN : XtManageChild(fileIODialog);
  305. SetFileIODialogInfo();
  306. break;
  307. case SAVE_AS : SaveMeNot = False;
  308. Do_FileIO(NULL, NULL, NULL);
  309. break;
  310. case GRAB : Do_GrabOp();
  311. break;
  312. case DROP : Do_DropOp();
  313. break;
  314. } /* switch */
  315. XSync(dpy, 0);
  316. }
  317. void
  318. Process_Query_Cancel( void )
  319. {
  320. DialogFlag = NONE;
  321. }
  322. void
  323. Process_Size_OK( void )
  324. {
  325. char *widthStr, *heightStr;
  326. int new_width, new_height;
  327. XtUnmanageChild(newIconDialog);
  328. widthStr = XmTextFieldGetString(newWidthText);
  329. heightStr = XmTextFieldGetString(newHeightText);
  330. new_width = atoi(widthStr);
  331. new_height = atoi(heightStr);
  332. Eval_NewSize(new_width, new_height);
  333. DialogFlag = NONE;
  334. }
  335. void
  336. Eval_NewSize(
  337. int width,
  338. int height )
  339. {
  340. char old_width[10], old_height[10];
  341. int flag;
  342. if ((width < 1) || (width > xrdb.maxIconWidth) ||
  343. (height < 1) || (height > xrdb.maxIconHeight)) {
  344. sprintf(old_width, "%d", icon_width);
  345. XmTextFieldSetString(newWidthText, old_width);
  346. sprintf(old_height, "%d", icon_height);
  347. XmTextFieldSetString(newHeightText, old_height);
  348. DoErrorDialog(GETSTR(16,10,"Invalid width and/or\nheight specified"));
  349. }
  350. else {
  351. if (DialogFlag == NEW)
  352. flag = DO_NOT_SAVE;
  353. else
  354. flag = DO_SAVE;
  355. Backup_Icons(); /* for undo */
  356. Init_Icons(width, height, flag);
  357. }
  358. }
  359. void
  360. Process_Size_Cancel( void )
  361. {
  362. DialogFlag = NONE;
  363. XtUnmanageChild(newIconDialog);
  364. }
  365. void
  366. Process_StdErr_OK( void )
  367. {
  368. DialogFlag = NONE;
  369. XtUnmanageChild(stdErrDialog);
  370. }
  371. /***************************************************************************
  372. * *
  373. * Routine: Process_Undo *
  374. * *
  375. * Purpose: Process the selection of the 'Undo' button in the 'Edit' *
  376. * pulldown menu. If no previous icon state is available, *
  377. * notify the user via a pop-up error dialog. Otherwise, *
  378. * reverse the Backup_Icon() function behavior, update the *
  379. * tablet to reflect the change, and set the UndoFlag to *
  380. * False (indicating that no further undo ops. are possible). *
  381. * *
  382. ***************************************************************************/
  383. void
  384. Process_Undo( void )
  385. {
  386. if (UndoFlag) {
  387. if ((icon_width != backup_width) || (icon_height != backup_height))
  388. Init_Icons(backup_width, backup_height, DO_NOT_SAVE);
  389. XCopyArea(dpy, prev_color_icon, color_icon,
  390. Color_gc, 0, 0, icon_width, icon_height, 0, 0);
  391. XCopyArea(dpy, prev_mono_icon, mono_icon,
  392. Mono_gc, 0, 0, icon_width, icon_height, 0, 0);
  393. if (XtWindow(iconImage))
  394. XCopyArea(dpy, color_icon, XtWindow(iconImage), Color_gc,
  395. 0, 0, icon_width, icon_height, 0, 0);
  396. if (XtWindow(monoImage))
  397. XCopyArea(dpy, mono_icon, XtWindow(monoImage), Mono_gc,
  398. 0, 0, icon_width, icon_height, 0, 0);
  399. Repaint_Exposed_Tablet();
  400. UndoFlag = False;
  401. Dirty = True;
  402. XtSetSensitive( editMenu_undo_pb, False);
  403. if ( NewFlag == TRUE ){
  404. NewFlag = False;
  405. strcpy(last_fname, undo_file);
  406. last_fname[strlen(last_fname)] = '\0';
  407. ChangeTitle();}
  408. }
  409. else
  410. DoErrorDialog( GETSTR(16,8,"There is no previous\nimage available") );
  411. }
  412. void
  413. Process_Cut( void )
  414. {
  415. Process_Copy(&CutCopy, &CutCopy_mono);
  416. if (Selected) {
  417. Backup_Icons();
  418. XSetForeground(dpy, scratch_gc, Transparent);
  419. XFillRectangle(dpy, color_icon, scratch_gc, select_box.x, select_box.y,
  420. select_box.width, select_box.height);
  421. XFillRectangle(dpy, mono_icon, scratch_gc, select_box.x, select_box.y,
  422. select_box.width, select_box.height);
  423. XFillRectangle(dpy, XtWindow(iconImage), scratch_gc,
  424. select_box.x, select_box.y, select_box.width, select_box.height);
  425. XFillRectangle(dpy, XtWindow(monoImage), scratch_gc,
  426. select_box.x, select_box.y, select_box.width, select_box.height);
  427. Transfer_Back_Image(select_box.x, select_box.y,
  428. (select_box.x+select_box.width),
  429. (select_box.y+select_box.height), FILL);
  430. XtSetSensitive( editMenu_paste_pb, True);
  431. }
  432. }
  433. void
  434. Process_Copy(
  435. XImage **img,
  436. XImage **img_mono )
  437. {
  438. if (Selected) {
  439. *img = XGetImage(dpy, color_icon, select_box.x, select_box.y,
  440. select_box.width, select_box.height, AllPlanes, format);
  441. *img_mono = XGetImage(dpy, mono_icon, select_box.x, select_box.y,
  442. select_box.width, select_box.height, AllPlanes, format);
  443. XtSetSensitive( editMenu_paste_pb, True);
  444. }
  445. else
  446. DoErrorDialog( GETSTR(16,12, "No area has been selected") );
  447. }
  448. void
  449. Process_Paste( void )
  450. {
  451. if (CutCopy) {
  452. Backup_Icons();
  453. Backup_G_Op = GraphicsOp;
  454. GraphicsOp = S_PASTE;
  455. FirstRigid = True;
  456. /* grayout unusable stuff */
  457. XtSetSensitive( editMenu_cut_pb, False);
  458. XtSetSensitive( editMenu_copy_pb, False);
  459. XtSetSensitive(editMenu_rotate_pb, False);
  460. XtSetSensitive(editMenu_flip_pb, False);
  461. XtSetSensitive(editMenu_scale_pb, False);
  462. XSync(dpy, 0);
  463. }
  464. else
  465. DoErrorDialog(GETSTR(16,14, "No area was previously\ncut or copied"));
  466. }
  467. void
  468. Process_Scale( void )
  469. {
  470. if (Selected) {
  471. Backup_Icons();
  472. Backup_G_Op = GraphicsOp;
  473. GraphicsOp = S_SCALE_1;
  474. FirstRigid = True;
  475. }
  476. else
  477. DoErrorDialog( GETSTR(16,12, "No area has been selected") );
  478. }
  479. void
  480. Process_Resize( void )
  481. {
  482. int flag;
  483. char old_width[10], old_height[10];
  484. static char *untitledStr = NULL;
  485. if ( DialogFlag == NEW ) {
  486. strcpy(undo_file, last_fname);
  487. SavedOnce = False;
  488. Backup_Icons(); /* for undo */
  489. flag = DO_NOT_SAVE;
  490. Init_Icons(icon_width, icon_height, flag);
  491. if (!untitledStr)
  492. untitledStr = GETSTR(2,20, "UNTITLED");
  493. snprintf(last_fname, sizeof(last_fname), "%s.m.pm", untitledStr);
  494. ChangeTitle();
  495. Repaint_Exposed_Tablet();
  496. Dirty = False;
  497. NewFlag = TRUE;
  498. }
  499. else{
  500. sprintf(old_width, "%d", icon_width);
  501. XmTextFieldSetString(newWidthText, old_width);
  502. sprintf(old_height, "%d", icon_height);
  503. XmTextFieldSetString(newHeightText, old_height);
  504. XtManageChild(newIconDialog);
  505. XmProcessTraversal(newWidthText, XmTRAVERSE_CURRENT);
  506. XmTextFieldSetSelection(newWidthText, 0, 3, CurrentTime); }
  507. }
  508. /***************************************************************************
  509. * *
  510. * Routine: Process_Clear *
  511. * *
  512. * Purpose: Process the selection of the 'Clear' button in the 'Edit' *
  513. * pulldown menu. This should be undo'able, just like a normal *
  514. * graphics ops., so back up the icons before wiping out their *
  515. * contents. After painting them to transparent, copy the *
  516. * contents of the color icon back onto the tablet. *
  517. * *
  518. ***************************************************************************/
  519. void
  520. Process_Clear( void )
  521. {
  522. Backup_Icons();
  523. XSetForeground(dpy, scratch_gc, Transparent);
  524. XFillRectangle(dpy, color_icon, scratch_gc, 0, 0, icon_width, icon_height);
  525. XFillRectangle(dpy, mono_icon, scratch_gc, 0, 0, icon_width, icon_height);
  526. if (XtWindow(iconImage))
  527. XCopyArea(dpy, color_icon, XtWindow(iconImage), scratch_gc,
  528. 0, 0, icon_width, icon_height, 0, 0);
  529. if (XtWindow(monoImage))
  530. XCopyArea(dpy, mono_icon, XtWindow(monoImage), scratch_gc,
  531. 0, 0, icon_width, icon_height, 0, 0);
  532. Repaint_Exposed_Tablet();
  533. Dirty = False;
  534. }
  535. /***************************************************************************
  536. * *
  537. * Routine: Process_GrabImage *
  538. * *
  539. * Purpose: You're a computer programmer. *YOU* figure out what it does.*
  540. * *
  541. ***************************************************************************/
  542. void
  543. Process_GrabImage( void )
  544. {
  545. DialogFlag = GRAB;
  546. if (Dirty)
  547. DoQueryDialog( GETSTR(16,16, "The current icon has not been saved.\nYour changes will be lost.") );
  548. else
  549. Do_GrabOp();
  550. }
  551. /***************************************************************************
  552. * *
  553. * Routine: Process_AddHotspot *
  554. * *
  555. * Purpose: Process the selection of the 'Add Hotspot' button in the *
  556. * 'Edit' pulldown menu. Save the current graphics ops. flag *
  557. * and set the flag to S_HOTSPOT. The actual [x,y] location *
  558. * selection for the hotspot will occur in the event processing *
  559. * loop for the tablet. *
  560. * *
  561. ***************************************************************************/
  562. void
  563. Process_AddHotspot( void )
  564. {
  565. Backup_G_Op = GraphicsOp;
  566. GraphicsOp = S_HOTSPOT;
  567. }
  568. /***************************************************************************
  569. * *
  570. * Routine: Process_DeleteHotspot *
  571. * *
  572. * Purpose: Process the selection of the 'Delete Hotspot' button in the *
  573. * 'Edit' pulldown menu. Set the X and Y hot values to -1, set *
  574. * the hotSpot flag to FALSE, and repaint the exposed portion *
  575. * of the tablet (to remove the visible hotspot indicator). *
  576. * *
  577. ***************************************************************************/
  578. void
  579. Process_DeleteHotspot( void )
  580. {
  581. X_Hot = -1;
  582. Y_Hot = -1;
  583. hotSpot = False;
  584. Repaint_Exposed_Tablet();
  585. }
  586. void
  587. Process_RotateLeft( void )
  588. {
  589. XImage *color_img, *mono_img;
  590. Process_Copy(&color_img, &mono_img);
  591. /* Turn off Paste since no area is available to Paste */
  592. XtSetSensitive( editMenu_paste_pb, False);
  593. if (Selected) {
  594. Backup_Icons();
  595. Rotate = XGetImage(dpy, root, 0, 0, color_img->height, color_img->width,
  596. AllPlanes, format);
  597. Rotate_mono = XGetImage(dpy, root, 0, 0, mono_img->height, mono_img->width,
  598. AllPlanes, format);
  599. Block_Rotate(color_img, Rotate, ROTATE_L);
  600. Block_Rotate(mono_img, Rotate_mono, ROTATE_L);
  601. XDestroyImage(color_img);
  602. XDestroyImage(mono_img);
  603. Backup_G_Op = GraphicsOp;
  604. GraphicsOp = S_ROTATE;
  605. FirstRigid = True;
  606. }
  607. }
  608. void
  609. Process_RotateRight( void )
  610. {
  611. XImage *color_img, *mono_img;
  612. Process_Copy(&color_img, &mono_img);
  613. /* Turn off Paste since no area is available to Paste */
  614. XtSetSensitive( editMenu_paste_pb, False);
  615. if (Selected) {
  616. Backup_Icons();
  617. Rotate = XGetImage(dpy, root, 0, 0, color_img->height, color_img->width,
  618. AllPlanes, format);
  619. Rotate_mono = XGetImage(dpy, root, 0, 0, mono_img->height, mono_img->width,
  620. AllPlanes, format);
  621. Block_Rotate(color_img, Rotate, ROTATE_R);
  622. Block_Rotate(mono_img, Rotate_mono, ROTATE_R);
  623. XDestroyImage(color_img);
  624. XDestroyImage(mono_img);
  625. Backup_G_Op = GraphicsOp;
  626. GraphicsOp = S_ROTATE;
  627. FirstRigid = True;
  628. }
  629. }
  630. /***************************************************************************
  631. * *
  632. * Routine: Process_FlipV *
  633. * *
  634. * Purpose: Process the selection of the 'Vertical' button in the 'Edit' *
  635. * ->'Flip Area' pulldown menu. This should be undo'able, *
  636. * just like a normal graphics ops., so back up the icons *
  637. * first, then call Mirror_Image(), with the flag VERTICAL. *
  638. * If no area is SELECTED, map the error dialog with the *
  639. * appropriate message. *
  640. * *
  641. ***************************************************************************/
  642. void
  643. Process_FlipV( void )
  644. {
  645. if (Selected) {
  646. Backup_Icons();
  647. Mirror_Image(VERTICAL);
  648. }
  649. else
  650. DoErrorDialog( GETSTR(16,12, "No area has been selected") );
  651. }
  652. /***************************************************************************
  653. * *
  654. * Routine: Process_FlipH *
  655. * *
  656. * Purpose: Process the selection of the 'Horizontal' button in the *
  657. * 'Edit'->'Flip Area' pulldown menu. This should be undo'able,*
  658. * just like a normal graphics ops., so back up the icons *
  659. * first, then call Mirror_Image(), with the flag HORIZONTAL. *
  660. * If no area is SELECTED, map the error dialog with the *
  661. * appropriate message. *
  662. * *
  663. ***************************************************************************/
  664. void
  665. Process_FlipH( void )
  666. {
  667. if (Selected) {
  668. Backup_Icons();
  669. Mirror_Image(HORIZONTAL);
  670. }
  671. else
  672. DoErrorDialog( GETSTR(16,12, "No area has been selected") );
  673. }
  674. /***************************************************************************
  675. * *
  676. * Routine: Process_GridState *
  677. * *
  678. * Purpose: Process the selection of the 'Visible Grid' button in the *
  679. * 'Options' pulldown menu. Set the GridEnabled internal flag *
  680. * to reflect the current state of the toggle. If the value is *
  681. * different from the previous value, repaint the tablet. *
  682. * *
  683. ***************************************************************************/
  684. void
  685. Process_GridState( void )
  686. {
  687. Arg args[10];
  688. int i;
  689. Boolean new_val;
  690. i = 0;
  691. XtSetArg(args[i], XmNset, &new_val); i++;
  692. XtGetValues(optionsMenu_grid, args, i);
  693. #ifdef DEBUG
  694. if (debug) {
  695. stat_out("Toggling tablet grid ");
  696. switch (new_val) {
  697. case True : stat_out("ON\n");
  698. break;
  699. case False : stat_out("OFF\n");
  700. break;
  701. }
  702. }
  703. #endif
  704. if (new_val != GridEnabled) {
  705. GridEnabled = new_val;
  706. Repaint_Exposed_Tablet();
  707. }
  708. }
  709. /***************************************************************************
  710. * *
  711. * Routine: ConvertDropName *
  712. * *
  713. * Purpose: Convert the "object" received from bms to a full path name *
  714. * note: I am making BIG assumptions about the format of the *
  715. * file I am getting from dtfile. "<host> - <path>" *
  716. * *
  717. ***************************************************************************/
  718. static char *
  719. ConvertDropName( char *objects)
  720. {
  721. char *host;
  722. char *path;
  723. char *fullName;
  724. char *tmp;
  725. char *netfile;
  726. host = objects;
  727. tmp = strchr(objects,' ');
  728. if (tmp==NULL) /* shouldn't happen */
  729. return (strdup(strchr(objects, '/')));
  730. /* check if same host */
  731. tmp[0] = '\0';
  732. if (DtIsLocalHostP(host))
  733. {
  734. char *slash = NULL;
  735. tmp[0] = ' ';
  736. slash = strchr(objects, '/');
  737. if(slash) {
  738. return strdup(slash);
  739. } else {
  740. return NULL;
  741. }
  742. }
  743. /* different host... get full path name */
  744. path = tmp+3; /* skip past the " - " */
  745. /* Convert to a valid name on the local host. */
  746. netfile = tt_host_file_netfile(host, path);
  747. fullName = tt_netfile_file(netfile);
  748. tt_free(netfile);
  749. tmp[0] = ' '; /* put back the " " after host name */
  750. return (fullName);
  751. }
  752. /***************************************************************************
  753. * *
  754. * Routine: Process_DropCheckOp *
  755. * *
  756. * Purpose: Validate the drag-n-drop operation that just occurred on the *
  757. * tablet window. *
  758. * *
  759. ***************************************************************************/
  760. void
  761. Process_DropCheckOp(
  762. Widget w,
  763. XtPointer client_data,
  764. XtPointer call_data)
  765. {
  766. DtDndTransferCallback transferInfo = (DtDndTransferCallback) call_data;
  767. /* save name in global array for later (Do_DropOp function) */
  768. /*
  769. * REMIND: Need to address case of multiple file names - here and
  770. * elsewhere in the code. This continues with the assumption
  771. * that there is only one file name transfered.
  772. */
  773. if (transferInfo->dropData->numItems > 0)
  774. {
  775. snprintf(dropFileName, sizeof(dropFileName), "%s", transferInfo->dropData->data.files[0]);
  776. }
  777. else
  778. dropFileName[0] = '\0';
  779. Do_DropCheckOp(transferInfo);
  780. #ifdef DEBUG
  781. if (debug) {
  782. stat_out(" file-name = %s\n", dropFileName);
  783. }
  784. #endif
  785. }
  786. extern Widget formatMenu_xpm_tb, formatMenu_xbm_tb;
  787. extern int successFormat, x_hot, y_hot;
  788. extern unsigned int width_ret, height_ret;
  789. /***************************************************************************
  790. * *
  791. * Routine: Do_DropCheckOp *
  792. * *
  793. * Purpose: Verify the drag-n-drop operation that just occurred on the *
  794. * tablet window. *
  795. * *
  796. ***************************************************************************/
  797. static void
  798. Do_DropCheckOp(
  799. DtDndTransferCallback transferInfo)
  800. {
  801. #ifdef DEBUG
  802. if (debug) {
  803. stat_out(" Doing DROP OPERATION :\n");
  804. stat_out(" name is = %s\n", dropFileName);
  805. }
  806. #endif
  807. if (dropFileName[0] != '\0')
  808. {
  809. if (!Read_File(dropFileName))
  810. {
  811. DoErrorDialog( GETSTR(16,2,
  812. "The file cannot be accessed\nor contains invalid data") );
  813. transferInfo->status = DtDND_FAILURE;
  814. }
  815. else
  816. {
  817. transferInfo->status = DtDND_SUCCESS;
  818. } /* else */
  819. } /* if */
  820. }
  821. void
  822. Process_DropOp(
  823. Widget w,
  824. XtPointer client_data,
  825. XtPointer call_data)
  826. {
  827. DialogFlag = DROP;
  828. if (Dirty)
  829. DoQueryDialog( GETSTR(16,16, "The current icon has not been saved.\n\nYour changes will be lost.") );
  830. else {
  831. Do_DropOp();}
  832. }
  833. static void
  834. Do_DropOp(void)
  835. {
  836. if (successFormat == FORMAT_XPM)
  837. {
  838. X_Hot = xpm_ReadAttribs.x_hotspot;
  839. Y_Hot = xpm_ReadAttribs.y_hotspot;
  840. Display_XPMFile(xpm_ReadAttribs.width, xpm_ReadAttribs.height);
  841. }
  842. else if (successFormat == FORMAT_XBM)
  843. {
  844. X_Hot = x_hot;
  845. Y_Hot = y_hot;
  846. Display_XBMFile(width_ret, height_ret);
  847. }
  848. Dirty = False;
  849. }
  850. /***************************************************************************
  851. * *
  852. * Routine: Do_Paste *
  853. * *
  854. * Purpose: Paste the CutCopy image at the tablet location specified by *
  855. * the [x,y] parameters in the call. *
  856. * *
  857. ***************************************************************************/
  858. void
  859. Do_Paste(
  860. int x,
  861. int y )
  862. {
  863. XImage *color_img, *mono_img;
  864. if (GraphicsOp == S_PASTE) {
  865. color_img = CutCopy;
  866. mono_img = CutCopy_mono;
  867. }
  868. else if (GraphicsOp == S_ROTATE) {
  869. color_img = Rotate;
  870. mono_img = Rotate_mono;
  871. }
  872. else {
  873. color_img = Scale;
  874. mono_img = Scale_mono;
  875. }
  876. if (GraphicsOp == S_PASTE)
  877. {
  878. GraphicsOp = S_WAIT_RELEASE;
  879. }
  880. else
  881. {
  882. GraphicsOp = Backup_G_Op;
  883. if (Backup_G_Op == SELECT)
  884. Start_HotBox(CONTINUE);
  885. Backup_G_Op = 0;
  886. }
  887. XPutImage(dpy, color_icon, Color_gc, color_img, 0, 0, x, y,
  888. color_img->width, color_img->height);
  889. XPutImage(dpy, mono_icon, Mono_gc, mono_img, 0, 0, x, y,
  890. mono_img->width, mono_img->height);
  891. XCopyArea(dpy, color_icon, XtWindow(iconImage), Color_gc,
  892. x, y, color_img->width, color_img->height, x, y);
  893. XCopyArea(dpy, mono_icon, XtWindow(monoImage), Mono_gc,
  894. x, y, mono_img->width, mono_img->height, x, y);
  895. Transfer_Back_Image(x, y, x+color_img->width, y+color_img->height, FILL);
  896. }