process.c 34 KB

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