home *** CD-ROM | disk | FTP | other *** search
/ World of A1200 / World_Of_A1200.iso / programs / monitors / rsys / rsyssrc.lha / RSysTextFormatter.c < prev    next >
C/C++ Source or Header  |  1993-09-23  |  8KB  |  363 lines

  1. /*
  2. ***************************************************************************
  3. *
  4. * Datei:
  5. *      RSysTextFormatter.c
  6. *
  7. * Inhalt:
  8. *
  9. *      --- Globale Routinen ---
  10. *
  11. *    int RSysFormatOutput ( struct Window *wind , char *format );
  12. *
  13. *      --- Lokale  Routinen ---
  14. *
  15. *    static int BlankLeftCGadClicked ( void );
  16. *    static int HandleFormatterIDCMP ( void );
  17. *    static int NoFormatGadClicked ( void );
  18. *    static int NoHeaderCGadClicked ( void );
  19. *    static int OpenFormatterWindow ( void );
  20. *    static int PostFixSGadClicked ( void );
  21. *    static int PrefixSGadClicked ( void );
  22. *    static int QuoteCGadClicked ( void );
  23. *    static int UseGadClicked ( void );
  24. *    static void preview ( void );
  25. *
  26. * Bemerkungen:
  27. *      Formatierung der Ausgabelisten von RSys.
  28. *
  29. * Erstellungsdatum:
  30. *      07-Jul-93     Rolf Böhme
  31. *
  32. * Änderungen:
  33. *      07-Jul-93     Rolf Böhme      Erstellung
  34. *
  35. ***************************************************************************
  36. */
  37.  
  38. #include "RSys.h"
  39.  
  40. static struct _fmt {
  41.     int    f_blanks,
  42.             f_quote;
  43.     int    f_noheader;
  44.     int    f_noformat;
  45.     char    f_prefix[100],
  46.             f_postfix[100];
  47.     char    f_format[MAXWRITESIZE];
  48. } TFormat, TFormatDef = {
  49.     FALSE, FALSE, FALSE, TRUE,"","","%s"
  50. };
  51.  
  52. static struct Window *FormatterWnd = NULL;
  53. static struct Gadget *FormatterGList = NULL;
  54. static struct IntuiMessage FormatterMsg;
  55. static struct Gadget *FormatterGadgets[Formatter_CNT];
  56. static UWORD FormatterLeft = 47;
  57. static UWORD FormatterTop = 52;
  58. static UWORD FormatterWidth = 610;
  59. static UWORD FormatterHeight = 74;
  60. static UBYTE *FormatterWdt = (UBYTE *) NAME " " VERSION " - Output Formatter";
  61.  
  62. static UWORD FormatterGTypes[]=
  63. {
  64.     STRING_KIND,
  65.     STRING_KIND,
  66.     CHECKBOX_KIND,
  67.     CHECKBOX_KIND,
  68.     CHECKBOX_KIND,
  69.     TEXT_KIND,
  70.     BUTTON_KIND,
  71.     BUTTON_KIND
  72. };
  73.  
  74. int PrefixSGadClicked( void );
  75. int PostFixSGadClicked( void );
  76. int BlankLeftCGadClicked( void );
  77. int QuoteCGadClicked( void );
  78. int NoHeaderCGadClicked( void );
  79. int UseGadClicked( void );
  80. int NoFormatGadClicked( void );
  81.  
  82. static struct NewGadget FormatterNGad[]=
  83. {
  84.     14, 17, 211, 13, (UBYTE *)"Prefix", NULL, GD_PrefixSGad, PLACETEXT_ABOVE, NULL, (APTR)PrefixSGadClicked,
  85.     384, 17, 211, 13, (UBYTE *)"Postfix", NULL, GD_PostFixSGad, PLACETEXT_ABOVE, NULL, (APTR)PostFixSGadClicked,
  86.     14, 33, 26, 11, (UBYTE *)"Blanks between texts", NULL, GD_BlankLeftCGad, PLACETEXT_RIGHT, NULL, (APTR)BlankLeftCGadClicked,
  87.     234, 33, 26, 11, (UBYTE *)"Quote-in text", NULL, GD_QuoteCGad, PLACETEXT_RIGHT, NULL, (APTR)QuoteCGadClicked,
  88.     419, 33, 26, 11, (UBYTE *)"No header in file", NULL, GD_NoHeaderCGad, PLACETEXT_RIGHT, NULL, (APTR)NoHeaderCGadClicked,
  89.     233, 17, 143, 13, (UBYTE *)"Text to save", NULL, GD_TextTGad, PLACETEXT_ABOVE, NULL, NULL,
  90.     119, 53, 147, 13, (UBYTE *)"Use Format", NULL, GD_UseGad, PLACETEXT_IN, NULL, (APTR)UseGadClicked,
  91.     343, 53, 147, 13, (UBYTE *)"No Format", NULL, GD_NoFormatGad, PLACETEXT_IN, NULL, (APTR)NoFormatGadClicked
  92. };
  93.  
  94. static ULONG *FormatterGTags[]=
  95. {
  96.     (ULONG *) (GTST_MaxChars), (ULONG *) 100, (ULONG *) (TAG_DONE),
  97.     (ULONG *) (GTST_MaxChars), (ULONG *) 100, (ULONG *) (TAG_DONE),
  98.     (ULONG *) (TAG_DONE),
  99.     (ULONG *) (TAG_DONE),
  100.     (ULONG *) (TAG_DONE),
  101.     (ULONG *) (GTTX_Text), (ULONG *) "This is text", (ULONG *) (GTTX_Border), (ULONG *) TRUE, (ULONG *) (TAG_DONE),
  102.     (ULONG *) (TAG_DONE),
  103.     (ULONG *) (TAG_DONE)
  104. };
  105.  
  106. static int
  107. UseGadClicked(void)
  108. {
  109.     TFormat.f_noformat = FALSE;
  110.  
  111.     strncpy(TFormat.f_prefix,gadgetbuff(FormatterGadgets[GD_PrefixSGad - GD_PrefixSGad]),100);
  112.     strncpy(TFormat.f_postfix,gadgetbuff(FormatterGadgets[GD_PostFixSGad - GD_PrefixSGad]),100);
  113.  
  114.     sprintf(TFormat.f_format,"%s%s%s%s%s%s%s",
  115.               TFormat.f_prefix,
  116.               TFormat.f_blanks ? " " : "",
  117.               TFormat.f_quote  ? "\"" : "",
  118.               "\%s",
  119.               TFormat.f_quote  ? "\"" : "",
  120.               TFormat.f_blanks ? " " : "",
  121.               TFormat.f_postfix
  122.               );
  123.  
  124.     return(FALSE);
  125. }
  126.  
  127. static void
  128. preview(void)
  129. {
  130.     char text[MAXWRITESIZE];
  131.  
  132.     DPOS;
  133.  
  134.     sprintf(text,"%s%s%s%s%s",
  135.               TFormat.f_blanks ? " " : "",
  136.               TFormat.f_quote  ? "\"" : "",
  137.               "This is text",
  138.               TFormat.f_quote  ? "\"" : "",
  139.               TFormat.f_blanks ? " " : "");
  140.  
  141.     GT_SetGadgetAttrs(FormatterGadgets[GD_TextTGad - GD_PrefixSGad], FormatterWnd,
  142.                             NULL,
  143.                             GTTX_Text, text,
  144.                             TAG_DONE);
  145.  
  146.     (void)UseGadClicked();
  147.  
  148.     return;
  149. }
  150.  
  151. static int
  152. PrefixSGadClicked(void)
  153. {
  154.     DPOS;
  155.  
  156.     strncpy(TFormat.f_prefix,gadgetbuff(FormatterGadgets[GD_PrefixSGad - GD_PrefixSGad]),100);
  157.  
  158.     preview();
  159.  
  160.     return TRUE;
  161. }
  162.  
  163. static int
  164. PostFixSGadClicked(void)
  165. {
  166.     DPOS;
  167.  
  168.     strncpy(TFormat.f_postfix,gadgetbuff(FormatterGadgets[GD_PostFixSGad - GD_PrefixSGad]),100);
  169.  
  170.     preview();
  171.  
  172.     return TRUE;
  173. }
  174.  
  175. static int
  176. BlankLeftCGadClicked(void)
  177. {
  178.     DPOS;
  179.  
  180.     TFormat.f_blanks = (TFormat.f_blanks ? FALSE : TRUE);
  181.  
  182.     preview();
  183.  
  184.     return TRUE;
  185. }
  186.  
  187. static int
  188. QuoteCGadClicked(void)
  189. {
  190.     DPOS;
  191.  
  192.     TFormat.f_quote = (TFormat.f_quote ? FALSE : TRUE);
  193.  
  194.     preview();
  195.  
  196.     return TRUE;
  197. }
  198.  
  199. static int
  200. NoHeaderCGadClicked(void)
  201. {
  202.     DPOS;
  203.  
  204.     TFormat.f_noheader = (TFormat.f_noheader ? FALSE : TRUE);
  205.  
  206.     return TRUE;
  207. }
  208.  
  209. static int
  210. NoFormatGadClicked(void)
  211. {
  212.     DPOS;
  213.  
  214.     TFormat.f_noformat = TRUE;
  215.     TFormat.f_noheader = FALSE;
  216.  
  217.     return FALSE;
  218. }
  219.  
  220. static int
  221. OpenFormatterWindow(void)
  222. {
  223.     struct NewGadget ng;
  224.     struct Gadget *g;
  225.     UWORD lc,
  226.             tc;
  227.     UWORD wleft = FormatterLeft,
  228.             wtop = FormatterTop,
  229.             ww,
  230.             wh;
  231.     int gl[] = { GD_PrefixSGad - GD_PrefixSGad,
  232.                 GD_PostFixSGad - GD_PrefixSGad,
  233.                 GD_TextTGad - GD_PrefixSGad };
  234.  
  235.     DPOS;
  236.  
  237.    AdjustWindowDimensions(Scr, FormatterLeft, FormatterTop, FormatterWidth, FormatterHeight,
  238.                                &wleft, &wtop, &ww, &wh);
  239.  
  240.     if (!(g = CreateContext(&FormatterGList))) return 1L;
  241.  
  242.     for (lc = 0, tc = 0; lc < Formatter_CNT; lc++)
  243.     {
  244.         CopyMem((char *)&FormatterNGad[lc], (char *)&ng, (long)sizeof(struct NewGadget));
  245.  
  246.         ng.ng_VisualInfo = VisualInfo;
  247.         ng.ng_TextAttr = Font;
  248.         ng.ng_LeftEdge = OffX + ComputeX(ng.ng_LeftEdge);
  249.         ng.ng_TopEdge = OffY + ComputeY(ng.ng_TopEdge);
  250.         ng.ng_Width = ComputeX(ng.ng_Width);
  251.         ng.ng_Height = ComputeY(ng.ng_Height);
  252.  
  253.         FormatterGadgets[lc] = g = CreateGadgetA((ULONG) FormatterGTypes[lc], g, &ng, (struct TagItem *) & FormatterGTags[tc]);
  254.  
  255.         makelabelvisible(FormatterGadgets[lc]);
  256.  
  257.         while (FormatterGTags[tc]) tc += 2;
  258.         tc++;
  259.  
  260.         if (NOT g) return 2L;
  261.     }
  262.  
  263.     if (!(FormatterWnd = OpenWindowTags(NULL,
  264.                                                     WA_Left, wleft,
  265.                                                     WA_Top, wtop,
  266.                                                     WA_Width, ww,
  267.                                                     WA_Height, wh,
  268.                                                     WA_IDCMP, STRINGIDCMP | CHECKBOXIDCMP |
  269.                                                     TEXTIDCMP | BUTTONIDCMP | IDCMP_CLOSEWINDOW |
  270.                                                     IDCMP_REFRESHWINDOW | IDCMP_VANILLAKEY,
  271.                                                     WA_Flags, WFLG_DRAGBAR | WFLG_DEPTHGADGET |
  272.                                                     WFLG_CLOSEGADGET | WFLG_SMART_REFRESH |
  273.                                                     WFLG_ACTIVATE | WFLG_RMBTRAP,
  274.                                                     WA_Title, FormatterWdt,
  275.                                                     WA_PubScreenFallBack,TRUE,
  276.                                                     WA_PubScreen, Scr,
  277.                                                     TAG_DONE)))
  278.         return 4L;
  279.  
  280.     RefreshRastPort(FormatterWnd,FormatterGadgets,gl, 3, FALSE, FormatterGList);
  281.  
  282.     return NULL;
  283. }
  284.  
  285. static int
  286. HandleFormatterIDCMP(void)
  287. {
  288.     struct IntuiMessage *m;
  289.     int    (*func) (void), ID;
  290.     BOOL    running = TRUE;
  291.  
  292.     DPOS;
  293.  
  294.     while (m = GT_GetIMsg(FormatterWnd->UserPort))
  295.     {
  296.         CopyMem((char *)m, (char *)&FormatterMsg, (long)sizeof(struct IntuiMessage));
  297.  
  298.         GT_ReplyIMsg(m);
  299.  
  300.         switch (FormatterMsg.Class)
  301.         {
  302.             case IDCMP_REFRESHWINDOW:
  303.                 GT_BeginRefresh(FormatterWnd);
  304.                 GT_EndRefresh(FormatterWnd, TRUE);
  305.                 break;
  306.  
  307.             case IDCMP_VANILLAKEY:
  308.                 if ((char)FormatterMsg.Code == ESC) running = FALSE;
  309.                 break;
  310.  
  311.             case IDCMP_CLOSEWINDOW:
  312.                 running = NoFormatGadClicked();
  313.                 break;
  314.  
  315.             case IDCMP_GADGETUP:
  316.             ID = ((struct Gadget *) FormatterMsg.IAddress)->GadgetID;
  317.  
  318.             HandleHelp((enum RSysNumbers)ID);
  319.  
  320.                 func = (void *)((struct Gadget *) FormatterMsg.IAddress)->UserData;
  321.                 running = func();
  322.                 break;
  323.         }
  324.     }
  325.  
  326.     return running;
  327. }
  328.  
  329. int
  330. RSysFormatOutput(struct Window *wind, char *format)
  331. {
  332.    APTR req = NULL;
  333.  
  334.     DPOS;
  335.  
  336.    if(!Flags.textformat)
  337.    {
  338.       strcpy(format, "%s");
  339.       return TFormat.f_noheader;
  340.    }
  341.  
  342.     CopyMem(&TFormatDef, &TFormat, sizeof(struct _fmt));
  343.  
  344.     if (OpenASysWindow(OpenFormatterWindow, NO_KILL))
  345.     {
  346.         PrintInfo("Format output strings", SPEAK, 0);
  347.  
  348.         if(wind) req = LockWindow(wind);
  349.  
  350.         while(HandleFormatterIDCMP()) ;
  351.  
  352.         CloseASysWindow(&FormatterWnd, &FormatterGList, NULL);
  353.  
  354.         if(TFormat.f_noformat == FALSE) strcpy(format,TFormat.f_format);
  355.         else
  356.             strcpy(format,"%s");
  357.  
  358.       UnlockWindow(req);
  359.     }
  360.  
  361.     return TFormat.f_noheader;
  362. }
  363.