home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / wp_dtp / xdme1821.lha / XDME / prefs.c < prev    next >
C/C++ Source or Header  |  1993-03-30  |  11KB  |  572 lines

  1. /******************************************************************************
  2.  
  3.     MODUL
  4.     prefs.c
  5.  
  6.     DESCRIPTION
  7.     Everything to set, edit, get, load and save settings !
  8.  
  9.     NOTES
  10.  
  11.     BUGS
  12.  
  13.     TODO
  14.  
  15.     EXAMPLES
  16.  
  17.     SEE ALSO
  18.  
  19.     INDEX
  20.  
  21.     HISTORY
  22.     14. Nov 1992    ada created
  23.  
  24. ******************************************************************************/
  25.  
  26. /**************************************
  27.         Includes
  28. **************************************/
  29. #include "defs.h"
  30.  
  31.  
  32. /**************************************
  33.         Globale Variable
  34. **************************************/
  35. Prototype void do_margin      (void);
  36. Prototype void do_wordwrap      (void);
  37. Prototype void do_global      (void);
  38. Prototype void do_setparcol      (void);
  39. Prototype void do_tabstop      (void);
  40. Prototype void do_chfilename      (void);
  41. Prototype void do_savetabs      (void);
  42. Prototype void do_setfont      (void);
  43. Prototype void do_ignorecase      (void);
  44. Prototype void loadconfig      (ED *);
  45. Prototype void do_saveconfig      (void);
  46. Prototype void do_fgpen       (void);
  47. Prototype void do_bgpen       (void);
  48. Prototype void do_hgpen       (void);
  49. Prototype void do_bbpen       (void);
  50. Prototype void do_tpen          (void);
  51. Prototype void do_modified      (void);
  52. Prototype void do_autoindent      (void);
  53. Prototype void do_sizewindow      (void);
  54. Prototype void do_autosplit      (void);
  55. Prototype void do_taskpri      (void);
  56. Prototype void do_debug       (void);
  57. Prototype void do_autounblock      (void);
  58. Prototype void do_followcursor      (void);
  59. Prototype void do_setlinedistance (void);
  60.  
  61.  
  62. /**************************************
  63.       Interne Defines & Strukturen
  64. **************************************/
  65.  
  66.  
  67. /**************************************
  68.         Interne Variable
  69. **************************************/
  70.  
  71.  
  72. /**************************************
  73.        Interne Prototypes
  74. **************************************/
  75.  
  76.  
  77. void do_margin (void)
  78. {
  79.     Ep->config.margin = atoi((char *)av[1]);
  80. } /* do_margin */
  81.  
  82.  
  83. void do_wordwrap (void)
  84. {
  85.     if (Ep->config.wordwrap = test_arg (av[1], Ep->config.wordwrap))
  86.     title("Wordwrap ON");
  87.     else
  88.     title("Wordwrap OFF");
  89. } /* do_wordwrap() */
  90.  
  91.  
  92. void do_global (void)
  93. {
  94.     if (globalflags.global_search = test_arg (av[1], globalflags.global_search))
  95.     title ("Global search ON");
  96.     else
  97.     title ("Global search OFF");
  98. } /* global_search */
  99.  
  100.  
  101. void do_setparcol (void)
  102. {
  103.     Ep->config.wwcol = atoi ((char *)av[1]);
  104. } /* do_setparcol() */
  105.  
  106.  
  107. void do_tabstop (void)
  108. {
  109.     Ep->config.tabstop = atoi ((char *)av[1]);
  110. } /* do_tabstop() */
  111.  
  112.  
  113. void do_insertmode (void)
  114. {
  115.     Ep->config.insertmode = test_arg (av[1], Ep->config.insertmode);
  116.  
  117.     window_title ();
  118. } /* do_insertmode() */
  119.  
  120.  
  121. void do_chfilename (void)
  122. {
  123.     BPTR   new_lock;
  124.     char * ptr;
  125.  
  126.     text_sync ();
  127.  
  128.     getpathto (Ep->dirlock, av[1], tmp_buffer);
  129.  
  130.     ptr = FilePart (tmp_buffer);
  131.     if (ptr != tmp_buffer)
  132.     {
  133.     char c = *ptr;
  134.     *ptr = 0;
  135.  
  136.     if (new_lock = Lock (tmp_buffer, SHARED_LOCK))
  137.     {
  138.         UnLock (Ep->dirlock);
  139.  
  140.         Ep->dirlock = new_lock;
  141.     } else
  142.     {
  143.         error ("%s:\nCannot get lock for\n`%s'.", av[0], tmp_buffer);
  144.  
  145.         return;
  146.     }
  147.  
  148.     *ptr = c;
  149.     }
  150.  
  151.     strncpy ((char *)Ep->name, ptr, 63);
  152.     Ep->name[63] = 0;
  153.  
  154.     globalflags.MForceTitle = 1;
  155. } /* do_chfilename */
  156.  
  157.  
  158. void do_savetabs (void)
  159. {
  160.     globalflags.Savetabs = test_arg (av[1], globalflags.Savetabs);
  161. } /* do_savetabs() */
  162.  
  163.  
  164. /*
  165.  *  SETFONT font size
  166.  */
  167.  
  168. void do_setfont (void)
  169. {
  170.     FONT * font;
  171.     ED     * ep    = Ep;
  172.     ULONG  size;
  173.  
  174.     size = atoi ((char *)av[2]);
  175.  
  176.     if (size > MAX_FONT_SIZE)
  177.     {
  178.     error ("setfont:\nSize %ld too large !", size);
  179.     return;
  180.     }
  181.  
  182.     font = (FONT *)GetFont ((char *)av[1], size);
  183.  
  184.     if (font)
  185.     {
  186.     if (ep->font)
  187.         CloseFont (ep->font);
  188.  
  189.     ep->font = font;
  190.  
  191.     SetFont (ep->win->RPort, font);
  192.     SetRast (ep->win->RPort, 0);
  193.     RefreshWindowFrame (ep->win);
  194.     set_window_params ();
  195.     text_adjust (TRUE);
  196.     } else
  197.     {
  198.     error ("setfont:\nUnable to find font\n%s/%ld", av[1], size);
  199.     }
  200. } /* do_setfont */
  201.  
  202.  
  203. void do_ignorecase (void)
  204. {
  205.     ED *ep = Ep;
  206.  
  207.     ep->config.ignorecase = test_arg (av[1], ep->config.ignorecase);
  208.  
  209.     if (ep->config.ignorecase)
  210.     title ("Case Insensitive");
  211.     else
  212.     title ("Case Sensitive");
  213. } /* do_ignorecase */
  214.  
  215.  
  216. void do_saveconfig (void)
  217. {
  218.     ED     * ep = Ep;
  219.     FILE * fi;
  220.     WIN  * win = ep->win;
  221.  
  222.    if (ep->iconmode)
  223.    {
  224.     ep->config.iwinx = win->LeftEdge;
  225.     ep->config.iwiny = win->TopEdge;
  226.    } else
  227.    {
  228.     ep->config.winx      = win->LeftEdge;
  229.     ep->config.winy      = win->TopEdge;
  230.     ep->config.winwidth  = win->Width;
  231.     ep->config.winheight = win->Height;
  232.    }
  233.  
  234.     if (fi = fopen (XDME_CONFIG, "w"))
  235.     {
  236.     fwrite (CONFIG_VERSION, sizeof(CONFIG_VERSION), 1, fi);
  237.     fwrite (&ep->beginconfig, CONFIG_SIZE, 1, fi);
  238.     fclose (fi);
  239.     }
  240. } /* do_saveconfig */
  241.  
  242.  
  243. void loadconfig (ED * ep)
  244. {
  245.     FILE * fi;
  246.  
  247.     /* Always init the fields */
  248.     movmem (&default_config, &ep->beginconfig, CONFIG_SIZE);
  249.  
  250.     if (fi = fopen (XDME_CONFIG, "r"))
  251.     {
  252.     fread (tmp_buffer, sizeof(CONFIG_VERSION), 1, fi);
  253.  
  254.     if (strncmp (CONFIG_VERSION, tmp_buffer, sizeof(CONFIG_VERSION)) )
  255.     {
  256.         error ("loadconfig:\nWrong version for\nconfiguration file !\nUsing defaults");
  257.     } else
  258.         fread (&ep->beginconfig, CONFIG_SIZE, 1, fi);
  259.  
  260.     fclose (fi);
  261.     }
  262. } /* loadconfig */
  263.  
  264.  
  265. void do_fgpen (void)
  266. {
  267.     int pen;
  268.  
  269.     pen = atoi((char *)av[1]);
  270.  
  271.     if (pen != TEXT_BPEN)
  272.     {
  273.     TEXT_FPEN = pen;
  274.     text_redisplay ();
  275.     } else
  276.     error ("fgpen:\n"
  277.            "Cannot choose same color\n"
  278.            "for both back- and fore-\n"
  279.            "ground");
  280. } /* do_fgpen */
  281.  
  282.  
  283. void do_tpen (void)
  284. {
  285.     int pen;
  286.  
  287.     pen = atoi((char *)av[1]);
  288.  
  289.     if (pen != TEXT_FPEN)
  290.     {
  291.     TITLE_BPEN = pen;
  292.     text_redisplay ();
  293.     } else
  294.     error ("tpen:\n"
  295.            "Cannot choose same color\n"
  296.            "for both back- and fore-\n"
  297.            "ground");
  298. } /* do_tpen */
  299.  
  300.  
  301. void do_bgpen (void)
  302. {
  303.     int pen;
  304.  
  305.     pen = atoi((char *)av[1]);
  306.  
  307.     if (pen != TEXT_FPEN)
  308.     {
  309.     TEXT_BPEN = pen;
  310.     text_redisplay ();
  311.     } else
  312.     error ("bgpen:\n"
  313.            "Cannot choose same color\n"
  314.            "for both back- and fore-\n"
  315.            "ground");
  316. } /* do_bgpen */
  317.  
  318.  
  319. void do_hgpen (void)
  320. {
  321.     int pen;
  322.  
  323.     pen = atoi((char *)av[1]);
  324.  
  325.     if (pen != BLOCK_BPEN)
  326.     {
  327.     BLOCK_FPEN = pen;
  328.  
  329.     if (block_ok ())
  330.         text_redisplay ();
  331.     } else
  332.     error ("hgpen:\n"
  333.            "Cannot choose same color\n"
  334.            "for both back- and fore-\n"
  335.            "ground");
  336. } /* do_hgpen */
  337.  
  338.  
  339. void do_bbpen (void)
  340. {
  341.     int pen;
  342.  
  343.     pen = atoi((char *)av[1]);
  344.  
  345.     if (pen != BLOCK_FPEN)
  346.     {
  347.     BLOCK_BPEN = pen;
  348.  
  349.     if (block_ok ())
  350.         text_redisplay ();
  351.     } else
  352.     error ("bbpen:\n"
  353.            "Cannot choose same color\n"
  354.            "for both back- and fore-\n"
  355.            "ground");
  356. } /* do_hgpen */
  357.  
  358.  
  359. void do_modified (void)
  360. {
  361.     register ED *ep = Ep;
  362.  
  363.     if (av[1][0])
  364.     {
  365.     switch(av[1][1] & 0x1F)
  366.     {
  367.     case 'n' & 0x1F:
  368.         ep->modified = 1;
  369.         break;
  370.     case 'f' & 0x1F:
  371.         ep->modified = 0;
  372.         break;
  373.     case 'o' & 0x1F:
  374.         ep->modified = ep->modified ? 0 : 1;
  375.         break;
  376.     }
  377.     }
  378. } /* do_modified */
  379.  
  380.  
  381. void do_autoindent (void)
  382. {
  383.     Ep->config.autoindent = test_arg ((char *)av[1], Ep->config.autoindent);
  384.  
  385.     if (Ep->config.autoindent)
  386.     title ("Autoindent ON");
  387.     else
  388.     title ("Autoindent OFF");
  389. } /* do_autoindent */
  390.  
  391.  
  392. void do_sizewindow (void)
  393. {
  394.     WIN * win = Ep->win;
  395.     struct NewWindow nw;
  396.     int mdx, mdy;
  397.  
  398.     GeometryToNW (av[1], &nw);
  399.  
  400.     if (nw.LeftEdge + nw.Width <= win->WScreen->Width &&
  401.         nw.TopEdge + nw.Height <= win->WScreen->Height &&
  402.         nw.Width >= win->MinWidth &&
  403.         nw.Height >= win->MinHeight)
  404.         {
  405.  
  406.     mdx = nw.LeftEdge - win->LeftEdge;
  407.     mdy = nw.TopEdge - win->TopEdge;
  408.  
  409.     if (mdx > 0)
  410.         mdx = 0;
  411.  
  412.     if (mdy > 0)
  413.         mdy = 0;
  414.  
  415.     MoveWindow (win, mdx, mdy);
  416.     SizeWindow (win, nw.Width - win->Width, nw.Height - win->Height);
  417.     MoveWindow (win, nw.LeftEdge - win->LeftEdge, nw.TopEdge - win->TopEdge);
  418.     }
  419. }
  420.  
  421.  
  422. void do_autosplit (void)
  423. {
  424.     Ep->config.autosplit = test_arg (av[1], Ep->config.autosplit);
  425.  
  426.     if (Ep->config.autosplit)
  427.     title ("AutoSplit is now ON");
  428.     else
  429.     title ("AutoSplit is now OFF");
  430. } /* do_autosplit */
  431.  
  432.  
  433. void do_taskpri (void)
  434. {
  435.     LONG pri;
  436.  
  437.     pri = atoi (av[1]);
  438.  
  439.     if (pri > 5 || pri < -5)
  440.     {
  441.     error ("taskpri:\nWrong TaskPri %ld. Taskpri must\nbe between -5 and 5 !", pri);
  442.     return ;
  443.     }
  444.  
  445.     SetTaskPri (FindTask(NULL), pri);
  446. } /* do_taskpri */
  447.  
  448.  
  449. void do_debug (void)
  450. {
  451.     if (globalflags.debug = test_arg (av[1], globalflags.debug))
  452.     title ("DEBUG is now ON");
  453.     else
  454.     title ("DEBUG is now OFF");
  455. } /* do_debug */
  456.  
  457.  
  458. /*****************************************************************************
  459.  
  460.     NAME
  461.  
  462.     PARAMETER
  463.  
  464.     RETURN
  465.  
  466.     DESCRIPTION
  467.  
  468. ******************************************************************************/
  469.  
  470. void do_autounblock (void)
  471. {
  472.     Ep->config.autounblock = test_arg (av[1], Ep->config.autounblock);
  473. } /* do_autounblock */
  474.  
  475.  
  476. /*****************************************************************************
  477.  
  478.     NAME
  479.  
  480.     PARAMETER
  481.  
  482.     RETURN
  483.  
  484.     DESCRIPTION
  485.  
  486. ******************************************************************************/
  487.  
  488. void do_followcursor (void)
  489. {
  490.     globalflags.FollowCursor = test_arg (av[1], globalflags.FollowCursor);
  491. } /* do_followcursor */
  492.  
  493.  
  494. /*****************************************************************************
  495.  
  496.     NAME
  497.     do_setlinedistance
  498.  
  499.     PARAMETER
  500.     av[1] : integer offset (>= 0)
  501.  
  502.     DESCRIPTION
  503.     Sets the LineDistance. The offset must be positive.
  504.  
  505. ******************************************************************************/
  506.  
  507. void do_setlinedistance (void)
  508. {
  509.     int offset = strtol (av[1], NULL, 0);
  510.  
  511.     if (offset < 0)
  512.     error ("%s:\nYou cannot set a negative\nspace between the lines", av[0]);
  513.     else
  514.     {
  515.     ED   * ep     = Ep;
  516.     RP   * rp     = ep->win->RPort;
  517.     USHORT old_Xpixs = Xpixs;
  518.     USHORT old_Ypixs = Ypixs;
  519.  
  520.     LineDistance = offset;
  521.  
  522.     set_window_params ();       /* recalc new offsets */
  523.  
  524.     if (old_Xpixs != Xpixs || old_Ypixs != Ypixs)
  525.     {
  526.         USHORT x1, x2, y1, y2;
  527.  
  528.         /* Prepare for clear */
  529.  
  530.         SetAPen (rp, TEXT_BPEN);
  531.         SetWrMsk (rp, BLOCK_MASK);
  532.  
  533.         /* #1 is lower, #2 is higher coordinate */
  534.  
  535.         if (old_Xpixs < Xpixs)
  536.         {
  537.         x1 = old_Xpixs;
  538.         x2 = Xpixs;
  539.         } else
  540.         {
  541.         x2 = old_Xpixs;
  542.         x1 = Xpixs;
  543.         }
  544.  
  545.         if (old_Ypixs < Ypixs)
  546.         {
  547.         y1 = old_Ypixs;
  548.         y2 = Ypixs;
  549.         } else
  550.         {
  551.         y2 = old_Ypixs;
  552.         y1 = Ypixs;
  553.         }
  554.  
  555.         /* clear obsolete areas */
  556.  
  557.         if (x1 != x2)
  558.         RectFill (rp, x1, Ybase, x2, y2);
  559.  
  560.         if (y1 != y2)
  561.         RectFill (rp, Xbase, y1, x2, y2);
  562.     }
  563.  
  564.     text_adjust (TRUE);
  565.     }
  566. } /* do_setlinedistance */
  567.  
  568.  
  569. /******************************************************************************
  570. *****  ENDE prefs.c
  571. ******************************************************************************/
  572.