home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / gui / x / xfig.lha / src / x11 / w_msgpanel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-26  |  5.7 KB  |  212 lines

  1. /*
  2.  * FIG : Facility for Interactive Generation of figures
  3.  * Copyright (c) 1985 by Supoj Sutanthavibul
  4.  *
  5.  * "Permission to use, copy, modify, distribute, and sell this software and its
  6.  * documentation for any purpose is hereby granted without fee, provided that
  7.  * the above copyright notice appear in all copies and that both the copyright
  8.  * notice and this permission notice appear in supporting documentation. 
  9.  * No representations are made about the suitability of this software for 
  10.  * any purpose.  It is provided "as is" without express or implied warranty."
  11.  */
  12.  
  13. #include "fig.h"
  14. #include "figx.h"
  15. #include "resources.h"
  16. #include "object.h"
  17. #include "mode.h"
  18. #include "paintop.h"
  19. #include "u_elastic.h"
  20. #include "w_canvas.h"
  21. #include "w_drawprim.h"
  22. #include "w_util.h"
  23. #include "w_setup.h"
  24. #include <varargs.h>
  25.  
  26. /********************* EXPORTS *******************/
  27.  
  28. int        put_msg();
  29. int        init_msgreceiving();
  30.  
  31. /************************  LOCAL ******************/
  32.  
  33. #define        BUF_SIZE        128
  34. static char    prompt[BUF_SIZE];
  35.  
  36. DeclareStaticArgs(12);
  37.  
  38. int
  39. init_msg(tool, filename)
  40.     TOOL        tool;
  41.     char       *filename;
  42. {
  43.     /* first make a form to put the two widgets in */
  44.     FirstArg(XtNwidth, MSGFORM_WD);
  45.     NextArg(XtNheight, MSGFORM_HT);
  46.     NextArg(XtNfromVert, cmd_panel);
  47.     NextArg(XtNvertDistance, -INTERNAL_BW);
  48.     NextArg(XtNdefaultDistance, 0);
  49.     NextArg(XtNborderWidth, 0);
  50.     msg_form = XtCreateManagedWidget("msg_form", formWidgetClass, tool,
  51.                       Args, ArgCount);
  52.     /* setup the file name widget first */
  53.     FirstArg(XtNresizable, True);
  54.     NextArg(XtNfont, bold_font);
  55.     NextArg(XtNlabel, (filename!=NULL? filename: DEF_NAME));
  56.     NextArg(XtNtop, XtChainTop);
  57.     NextArg(XtNbottom, XtChainTop);
  58.     NextArg(XtNborderWidth, INTERNAL_BW);
  59.     name_panel = XtCreateManagedWidget("file_name", labelWidgetClass, msg_form,
  60.                       Args, ArgCount);
  61.     /* now the message panel */
  62.     FirstArg(XtNfont, roman_font);
  63.     NextArg(XtNstring, "\0");
  64.     NextArg(XtNfromHoriz, name_panel);
  65.     NextArg(XtNhorizDistance, -INTERNAL_BW);
  66.     NextArg(XtNtop, XtChainTop);
  67.     NextArg(XtNbottom, XtChainTop);
  68.     NextArg(XtNborderWidth, INTERNAL_BW);
  69.     NextArg(XtNdisplayCaret, False);
  70.     msg_panel = XtCreateManagedWidget("message", asciiTextWidgetClass, msg_form,
  71.                       Args, ArgCount);
  72. }
  73.  
  74. setup_msg()
  75. {
  76.     Dimension ht;
  77.  
  78.     /* set the height of the message panel to the height of the file name panel */
  79.     XtUnmanageChild(msg_panel);
  80.     FirstArg(XtNheight, &ht);
  81.     GetValues(name_panel);
  82.     FirstArg(XtNheight, ht);
  83.     SetValues(msg_panel);
  84.     /* set the MSGFORM_HT variable so the mouse panel can be resized to fit */
  85.     MSGFORM_HT = ht;
  86.     XtManageChild(msg_panel);
  87.     if (msg_win == 0)
  88.     msg_win = XtWindow(msg_panel);
  89.     XDefineCursor(tool_d, msg_win, null_cursor);
  90. }
  91.  
  92. /*
  93.  * Update the current filename in the name_panel widget (it will resize
  94.  * automatically) and resize the msg_panel widget to fit in the remaining 
  95.  * space, by getting the width of the command panel and subtract the new 
  96.  * width of the name_panel to get the new width of the message panel
  97.  */
  98. update_cur_filename(newname)
  99.     char    *newname;
  100. {
  101.     Dimension namwid;
  102.  
  103.     XtUnmanageChild(msg_form);
  104.     XtUnmanageChild(msg_panel);
  105.     XtUnmanageChild(name_panel);
  106.     strcpy(cur_filename,newname);
  107.  
  108.  
  109.     FirstArg(XtNlabel, newname);
  110.     SetValues(name_panel);
  111.     /* get the new size of the name_panel */
  112.     FirstArg(XtNwidth, &namwid);
  113.     GetValues(name_panel);
  114.     MSGPANEL_WD = MSGFORM_WD-namwid;
  115.     /* resize the message panel to fit with the new width of the name panel */
  116.     FirstArg(XtNwidth, MSGPANEL_WD);
  117.     SetValues(msg_panel);
  118.     XtManageChild(msg_panel);
  119.     XtManageChild(name_panel);
  120.  
  121.     /* now resize the whole form */
  122.     FirstArg(XtNwidth, MSGFORM_WD);
  123.     SetValues(msg_form);
  124.     XtManageChild(msg_form);
  125. }
  126.  
  127. /* VARARGS1 */
  128. int put_msg(va_alist) va_dcl
  129. {
  130.     va_list ap;
  131.     char *format;
  132.  
  133.     va_start(ap);
  134.     format = va_arg(ap, char *);
  135.     vsprintf(prompt, format, ap );
  136.     va_end(ap);
  137.     FirstArg(XtNstring, prompt);
  138.     SetValues(msg_panel);
  139. }
  140.  
  141. clear_message()
  142. {
  143.     FirstArg(XtNstring, "\0");
  144.     SetValues(msg_panel);
  145. }
  146.  
  147. boxsize_msg()
  148. {
  149.     float dx, dy;
  150.  
  151.     dx = (float) abs(cur_x - fix_x) /
  152.         (float)(appres.INCHES? PIX_PER_INCH: PIX_PER_CM);
  153.     dy = (float) abs(cur_y - fix_y) /
  154.         (float)(appres.INCHES? PIX_PER_INCH: PIX_PER_CM);
  155.     put_msg("Width = %.2f, Length = %.2f %s",
  156.         dx*appres.user_scale, dy*appres.user_scale, cur_fig_units);
  157. }
  158.  
  159. length_msg(type)
  160. int type;
  161. {
  162.     altlength_msg(type, fix_x, fix_y);
  163. }
  164.  
  165. /*
  166. ** In typical usage, point fx,fy is the fixed point.
  167. ** Distance will be measured from it to cur_x,cur_y.
  168. */
  169.  
  170. altlength_msg(type, fx, fy)
  171. int type;
  172. {
  173.     float len,dx,dy;
  174.  
  175.     dx = cur_x - fx;
  176.     dy = cur_y - fy;
  177.     len = (float)(sqrt((double)dx*(double)dx + (double)dy*(double)dy)/
  178.         (double)(appres.INCHES? PIX_PER_INCH: PIX_PER_CM));
  179.     put_msg("%s = %.2f %s", (type==MSG_RADIUS? "Radius":
  180.                 (type==MSG_DIAM? "Diameter": "Length")),
  181.         len*appres.user_scale, cur_fig_units);
  182. }
  183.  
  184. /*
  185. ** In typical usage, point x3,y3 is the one that is moving,
  186. ** the other two are fixed.  Distances will be measured from
  187. ** points 1 -> 3 and 2 -> 3.
  188. */
  189.  
  190. length_msg2(x1,y1,x2,y2,x3,y3)
  191. int x1,y1,x2,y2,x3,y3;
  192. {
  193.     float len1,len2,dx1,dy1,dx2,dy2;
  194.  
  195.     len1=len2=0.0;
  196.     if (x1 != -999) {
  197.         dx1 = x3 - x1;
  198.         dy1 = y3 - y1;
  199.         len1 = (float)(sqrt((double)dx1*(double)dx1 + (double)dy1*(double)dy1)/
  200.         (double)(appres.INCHES? PIX_PER_INCH: PIX_PER_CM));
  201.     }
  202.     if (x2 != -999) {
  203.         dx2 = x3 - x2;
  204.         dy2 = y3 - y2;
  205.         len2 = (float)(sqrt((double)dx2*(double)dx2 + (double)dy2*(double)dy2)/
  206.         (double)(appres.INCHES? PIX_PER_INCH: PIX_PER_CM));
  207.     }
  208.     put_msg("Length 1 = %.2f, Length 2 = %.2f %s",
  209.         len1*appres.user_scale, len2*appres.user_scale, cur_fig_units);
  210. }
  211.  
  212.