home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume8 / xfig2.8 / part07 / global.c < prev    next >
C/C++ Source or Header  |  1990-07-02  |  7KB  |  312 lines

  1. /* 
  2.  *    FIG : Facility for Interactive Generation of figures
  3.  *
  4.  *    Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU)
  5.  *    January 1985.
  6.  *    1st revision : Aug 1985.
  7.  *
  8.  *    %W%    %G%
  9. */
  10. #include "fig.h"
  11. #define    GLOBAL        /* force resources and font to allocate space */
  12. #include "resources.h"
  13. #include "font.h"
  14. #undef    GLOBAL
  15. #include "const.h"
  16. #include "func.h"
  17. #include "object.h"
  18. #include "paintop.h"
  19.  
  20. /**********************  canvas variables  ************************/
  21.  
  22. int            (*canvas_kbd_proc)();
  23. int            (*canvas_locmove_proc)();
  24. int            (*canvas_leftbut_proc)();
  25. int            (*canvas_middlebut_proc)();
  26. int            (*canvas_rightbut_proc)();
  27. int            (*return_proc)();
  28. int            fix_x, fix_y;
  29. int            cur_x, cur_y;
  30.  
  31. int            action_on = 0;
  32. int            pointmarker_shown = 0;
  33. int            compoundbox_shown = 0;
  34.  
  35. int            ICON_COLUMN;
  36. int            CANVAS_HEIGHT, CANVAS_WIDTH;
  37. int            PANEL_WID, PANEL2_WID;
  38. int            SIDERULER_WIDTH, SIDERULER_HEIGHT;
  39. int            TOPRULER_WIDTH, TOPRULER_HEIGHT;
  40.  
  41. int            num_point;
  42. F_point            *first_point, *cur_point;
  43.  
  44. /************************  Objects  **********************/
  45.  
  46. /*
  47. Object_tails (not always) point to the last objects in each linked list
  48. in objects.  It is used to speed up an undo-read action.  When a file
  49. is read, the lists of the objects read are stored in saved_objects
  50. and the pointers to tails of the lists in objects would kept in object_tails
  51. the "next" members of the tail objects point to the lists in saved_objects.
  52. To undo, one would only set all the "next" of tail object to NULL;
  53.  
  54. Object_tails is also used for speeding up the undo of compound breaking
  55. action in similar fashion.
  56. */
  57. F_compound        object_tails = {NULL,NULL,NULL,NULL,NULL,NULL,NULL};
  58. F_compound        objects = {NULL,NULL,NULL,NULL,NULL,NULL,NULL};
  59. F_compound        saved_objects = {NULL,NULL,NULL,NULL,NULL,NULL,NULL};
  60. F_compound        *saved_compound = NULL;    /* Saved the broken compound */
  61.  
  62. /*************************  Undo  variables  **********************/
  63.  
  64. int            last_action = F_NULL;
  65. int            last_object;
  66. int            last_axis;
  67. int            last_rotateangle;
  68. struct {int x, y;}    last_position, new_position;
  69. F_point            *moved_point;
  70. F_point            *deleted_point;
  71. F_point            *added_point;
  72. F_point            *left_point;
  73. F_point            *right_point;
  74. int            movedpoint_num;
  75.  
  76. /***************************  Modes  ****************************/
  77.  
  78. int            manhattan_mode        = 0;
  79. int            mountain_mode        = 0;
  80. int            autoforwardarrow_mode    = 0;
  81. int            autobackwardarrow_mode    = 0;
  82. int            latexline_mode        = 0;
  83. int            latexarrow_mode        = 0;
  84. int            magnet_mode        = 0;
  85. int            line_thickness        = 1;
  86. int            line_style        = SOLID_LINE;
  87. int            cur_radius        = 7;
  88. int            pen_size        = 0;
  89. int            pen_type        = 0;
  90. int            flip_axis        = -1;
  91. int            rotate_angle        = 0;
  92. int            fill_mode        = 0;
  93. int            print_landscape        = 0;    /* def. orientation for printer */
  94. int            size_button;            /* font size button value */
  95. int            font_button        = 0;    /* font button value */
  96. int            type_button        = T_LEFT_JUSTIFIED;    /* text type button value */
  97. int            cur_font;            /* font of current text object */
  98. int            cur_fontsize;            /* size of current text object font */
  99. int            cur_areafill        = 1;
  100. float            cur_dashlength        = 4;
  101. float            cur_dotgap        = 3;
  102. float            cur_styleval        = 0.0;
  103. float            cur_angle        = 0.0;
  104. int            cur_color        = BLACK;
  105. int            cur_textstyle        = PLAIN;
  106. int            cur_textjust        = T_LEFT_JUSTIFIED;
  107.         /* line thicknesses for each gc */
  108. int            gc_thickness[NUMOPS]    = {-1,-1,-1,-1};
  109. int            gc_line_style[NUMOPS]    = {-1,-1,-1,-1};
  110.  
  111. /*************************  Flags/Resources  *******************************/
  112.  
  113. int            cur_command = -1;
  114.  
  115. /* Resources */
  116.  
  117. appresStruct appres;
  118.  
  119. /************************  Status  ****************************/
  120.  
  121. char            directory[1024];
  122. char            current_file[200] = "";
  123. int            cur_printer=0;
  124. char            *printer="";
  125. char            *printer_list[MAXPRINTERS]={"Specify","Default","File"};
  126. int            figure_modified = 0;
  127.  
  128. /************************  Error messages  ****************************/
  129.  
  130. char        Err_incomp[] = "Incomplete %s object at line %d.";
  131. char        Err_mem[] = "Running out of memory.";
  132.  
  133. /************************  Routines  ****************************/
  134.  
  135. null_proc()
  136. {
  137.     }
  138.  
  139. set_modifiedflag()
  140. {
  141.     figure_modified = 1;
  142.     }
  143.  
  144. set_action_on()
  145. {
  146.     action_on = 1;
  147.     }
  148.  
  149. reset_action_on()
  150. {
  151.     action_on = 0;
  152.     }
  153.  
  154. reset_cursor()
  155. {
  156.     XDefineCursor(tool_d, canvas_win, (Cursor)cur_cursor->bitmap);
  157.     }
  158.  
  159. set_temp_cursor(cursor)
  160. CURSOR    cursor;
  161. {
  162.     XDefineCursor(tool_d, canvas_win, (Cursor)cursor->bitmap);
  163.     }
  164.  
  165. set_cursor(cursor)
  166. CURSOR    cursor;
  167. {
  168.     cur_cursor = cursor;
  169.     XDefineCursor(tool_d, canvas_win, (Cursor)cursor->bitmap);
  170.     }
  171.  
  172. set_lastaxis(a)
  173. int    a;
  174. {
  175.     last_axis = a;
  176.     }
  177.  
  178. set_lastangle(a)
  179. int    a;
  180. {
  181.     last_rotateangle = a;
  182.     }
  183.  
  184. set_lastposition(x, y)
  185. int    x, y;
  186. {
  187.     last_position.x = x;
  188.     last_position.y = y;
  189.     }
  190.  
  191. set_action(action)
  192. int     action;
  193. {
  194.     last_action = action;
  195.     }
  196.  
  197. set_action_object(action, object)
  198. int     action, object;
  199. {
  200.     last_action = action;
  201.     last_object = object;
  202.     }
  203.  
  204. /*
  205. Clean_up should be called before committing a user's request.
  206. Clean_up will attempt to free all the allocated memories which
  207. resulted from delete/remove action.  It will set the last_action
  208. to F_NULL.  Thus this routine should be before set_action_object().
  209. if they are to be called in the same routine.
  210. */
  211. clean_up()
  212. {
  213.     if (last_action == F_REMOVE) {
  214.         switch (last_object) {
  215.         case O_ARC :
  216.             free_arc(&saved_objects.arcs);
  217.             break;
  218.         case O_COMPOUND :
  219.             free_compound(&saved_objects.compounds);
  220.             break;
  221.         case O_ELLIPSE :
  222.             free_ellipse(&saved_objects.ellipses);
  223.             break;
  224.         case O_POLYLINE :
  225.             free_line(&saved_objects.lines);
  226.             break;
  227.         case O_SPLINE :
  228.             free_spline(&saved_objects.splines);
  229.             break;
  230.         case O_TEXT :
  231.             free_text(&saved_objects.texts);
  232.             break;
  233.         case O_ALL_OBJECT :
  234.             free_arc(&saved_objects.arcs);
  235.             free_compound(&saved_objects.compounds);
  236.             free_ellipse(&saved_objects.ellipses);
  237.             free_line(&saved_objects.lines);
  238.             free_spline(&saved_objects.splines);
  239.             free_text(&saved_objects.texts);
  240.             break;
  241.         }
  242.         }
  243.     else if (last_action == F_DELETE_POINT) {
  244.         free((char*)deleted_point);
  245.         deleted_point = NULL;
  246.         }
  247.     else if (last_action == F_REMOVE_ALL || last_action == F_EDIT) {
  248.         free_arc(&saved_objects.arcs);
  249.         free_compound(&saved_objects.compounds);
  250.         free_ellipse(&saved_objects.ellipses);
  251.         free_line(&saved_objects.lines);
  252.         free_spline(&saved_objects.splines);
  253.         free_text(&saved_objects.texts);
  254.         }
  255.     else if (last_action == F_BREAK) {
  256.         free_compound(&saved_compound);
  257.         }
  258.     else if (last_action == F_CREATE) {
  259.         saved_objects.arcs = NULL;
  260.         saved_objects.compounds = NULL;
  261.         saved_objects.ellipses = NULL;
  262.         saved_objects.lines = NULL;
  263.         saved_objects.splines = NULL;
  264.         saved_objects.texts = NULL;
  265.         }
  266.     else if (last_action == F_TURN) {
  267.         if (last_object == O_POLYLINE) {
  268.         free_line(&saved_objects.lines);
  269.         }
  270.         else {    /* last_object == O_SPLINE */
  271.         free_spline(&saved_objects.splines);
  272.         }
  273.         }
  274.     last_action = F_NULL;
  275.     }
  276.  
  277. set_latestarc(arc)
  278. F_arc    *arc;
  279. {
  280.     saved_objects.arcs = arc;
  281.     }
  282.  
  283. set_latestcompound(compound)
  284. F_compound    *compound;
  285. {
  286.     saved_objects.compounds = compound;
  287.     }
  288.  
  289. set_latestellipse(ellipse)
  290. F_ellipse    *ellipse;
  291. {
  292.     saved_objects.ellipses = ellipse;
  293.     }
  294.  
  295. set_latestline(line)
  296. F_line    *line;
  297. {
  298.     saved_objects.lines = line;
  299.     }
  300.  
  301. set_latestspline(spline)
  302. F_spline    *spline;
  303. {
  304.     saved_objects.splines = spline;
  305.     }
  306.  
  307. set_latesttext(text)
  308. F_text    *text;
  309. {
  310.     saved_objects.texts = text;
  311.     }
  312.