home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / fish / disks / d1031.lha / Programs / Textfield / TestClass / TestClass.c < prev    next >
C/C++ Source or Header  |  1994-11-12  |  17KB  |  580 lines

  1. /*
  2.  * TestClass.c
  3.  *
  4.  * This is a sample program that uses the TextField BOOPSI class.
  5.  * It is modeled after an example in the RKRM Libraries book on
  6.  * the RKMButClass.  It is provided to show how to use a TextField.gadget
  7.  * BOOPSI object and shows general techniques and functionality.
  8.  *
  9.  * Opening the textfield.gadget library is done by TextFieldAuto.c.
  10.  * The variable TextFieldBase has the library base, and the variable
  11.  * TextFieldClass has the class pointer.
  12.  *
  13.  * See the autodoc if you do not use the SAS/C auto-open feature or
  14.  * if you have another compiler.
  15.  *
  16.  * This code compiles with SAS/C 6.51.
  17.  */
  18.  
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22.  
  23. #include <exec/types.h>
  24. #include <intuition/intuition.h>
  25. #include <intuition/classes.h>
  26. #include <intuition/classusr.h>
  27. #include <intuition/imageclass.h>
  28. #include <intuition/gadgetclass.h>
  29. #include <intuition/cghooks.h>
  30. #include <intuition/icclass.h>
  31. #include <graphics/gfxmacros.h>
  32. #include <graphics/text.h>
  33. #include <utility/tagitem.h>
  34. #include <gadgets/textfield.h>
  35. #include <libraries/gadtools.h>
  36.  
  37. #include <clib/alib_protos.h>
  38.  
  39. #include <proto/exec.h>
  40. #include <proto/iffparse.h>
  41. #include <proto/intuition.h>
  42. #include <proto/graphics.h>
  43. #include <proto/utility.h>
  44. #include <proto/textfield.h>
  45. #include <proto/gadtools.h>
  46.  
  47. /*
  48.  * External prototypes
  49.  */
  50.  
  51. extern int SetupScreen( void );
  52. extern void CloseDownScreen( void );
  53. extern int HandleTextFieldPrefsIDCMP( void );
  54. extern int OpenTextFieldPrefsWindow( void );
  55. extern void CloseTextFieldPrefsWindow( void );
  56. extern struct Window *TextFieldPrefsWnd;
  57.  
  58. /*
  59.  * Local prototypes
  60.  */
  61.  
  62. static void MainLoop(void);
  63. static BOOL SetupPrefsWindow(void);
  64. static void ShutdownPrefsWindow(void);
  65. static void GetGadgetRect(struct Window *window, struct Gadget *gadget, struct Rectangle *rect);
  66. static void ActivateTabGadget(struct Window *window);
  67. static void DoMenu(UWORD item);
  68.  
  69. /*
  70.  * Local variables
  71.  */
  72.  
  73. //static const char vers[] = "\0$VER: TestTextfield 2.0 " __AMIGADATE__;
  74. static const char vers[] = "\0$VER: TestTextfield 2.0 (12.11.94)";
  75. static struct IntuiText text1_title;
  76. static struct DrawInfo *draw_info;
  77. static struct ClipboardHandle *clip_handle, *undo_handle;
  78. static struct Image *up_image, *down_image;
  79. static struct IntuiMessage *msg;
  80. static struct Menu *menu_strip;
  81. static APTR *visual_info;
  82. static unsigned char *text_buffer, *my_buffer;
  83. static UWORD gap_w, gap_h;
  84.  
  85. static char initial_text[] = "Sample text placed immediately into the gadget.\nType into the object.\nOr try AMIGA-[, AMIGA-=, AMIGA-], or AMIGA-\\.\n",
  86.             more_text[] = "I think the gadget looks best with the double-bevel border and a medium cursor speed.";
  87.  
  88. static struct TagItem prop2text[] = {
  89.     { PGA_Top, TEXTFIELD_Top },
  90.     { TAG_DONE }
  91. };
  92. static struct TagItem text2prop[] = {
  93.     { TEXTFIELD_Top, PGA_Top },
  94.     { TEXTFIELD_Visible, PGA_Visible },
  95.     { TEXTFIELD_Lines, PGA_Total },
  96.     { TAG_DONE }
  97. };
  98. static struct TagItem up2text[] = {
  99.     { GA_ID, TEXTFIELD_Up },
  100.     { TAG_DONE }
  101. };
  102. static struct TagItem down2text[] = {
  103.     { GA_ID, TEXTFIELD_Down },
  104.     { TAG_DONE }
  105. };
  106.  
  107. enum {
  108.     CUT_ITEM,
  109.     COPY_ITEM,
  110.     COPYALL_ITEM,
  111.     PASTE_ITEM,
  112.     UNDO_ITEM = 5,
  113.     ERASE_ITEM = 7
  114. };
  115.  
  116. static struct NewMenu menus[] = {
  117.     { NM_TITLE, "Edit",              0, 0, 0, 0 },
  118.     {  NM_ITEM, "Cut",            "X", 0, 0, 0 },
  119.     {  NM_ITEM, "Copy",            "C", 0, 0, 0 },
  120.     {  NM_ITEM, "Copy All",        "K", 0, 0, 0 },
  121.     {  NM_ITEM, "Paste",        "V", 0, 0, 0 },
  122.     {  NM_ITEM, NM_BARLABEL,      0, 0, 0, 0 },
  123.     {  NM_ITEM, "Undo",            "U", 0, 0, 0 },
  124.     {  NM_ITEM, NM_BARLABEL,      0, 0, 0, 0 },
  125.     {  NM_ITEM, "Erase",        "E", 0, 0, 0 },
  126.     {   NM_END, NULL,              0, 0, 0, 0 }
  127. };
  128.  
  129. /*
  130.  * Global variables
  131.  */
  132.  
  133. struct Window *window;
  134. struct Gadget *text1_object, *prop_object, *up_object, *down_object;
  135. ULONG length, window_sig, prefs_sig, sigs, style;
  136. UWORD *pens;
  137.  
  138. /*
  139.  * Functions
  140.  */
  141.  
  142. void main(void)
  143. {
  144.     if (!SetupPrefsWindow()) {
  145.         printf("Cannot setup prefs window.\n");
  146.         return;
  147.     }
  148.     prefs_sig = 1L << TextFieldPrefsWnd->UserPort->mp_SigBit;
  149.  
  150.     /* Open the window */
  151.     window = OpenWindowTags(NULL,    WA_Flags,            WFLG_DEPTHGADGET|WFLG_DRAGBAR|WFLG_CLOSEGADGET|WFLG_SIZEGADGET
  152.                                                         |WFLG_SIZEBBOTTOM|WFLG_SIZEBRIGHT,
  153.                                     WA_Activate,        TRUE,
  154.                                     WA_IDCMP,            IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY|IDCMP_MENUPICK,
  155.                                     WA_Width,            320,
  156.                                     WA_Height,            200,
  157.                                     WA_NoCareRefresh,    TRUE,
  158.                                     WA_NewLookMenus,    TRUE,
  159.                                     WA_ScreenTitle,        "Testing textfield.gadget",
  160.                                     TAG_END);
  161.  
  162.     if (window) {
  163.         window_sig = 1L << window->UserPort->mp_SigBit;
  164.         sigs = prefs_sig | window_sig;
  165.         /* Get the DrawInfo since sysiclass needs it */
  166.         draw_info = GetScreenDrawInfo(window->WScreen);
  167.  
  168.         if (draw_info) {
  169.             pens = draw_info->dri_Pens;
  170.  
  171.             /* Make a title for the gadget */
  172.             text1_title.FrontPen = pens[TEXTPEN];
  173.             text1_title.BackPen = pens[BACKGROUNDPEN];  /* don't really need to set for JAM1 */
  174.             text1_title.DrawMode = JAM1;
  175.             text1_title.LeftEdge = 0;
  176.             text1_title.TopEdge = -(window->WScreen->RastPort.TxHeight + 1);
  177.             text1_title.ITextFont = NULL;
  178.             text1_title.IText = "Gadget label:";
  179.             text1_title.NextText = NULL;
  180.  
  181.             /* Setup the gaps */
  182.             gap_w = 20;
  183.             gap_h = window->RPort->TxHeight;
  184.  
  185.             /* Make some changes in the window limits */
  186.             WindowLimits(window, 160, window->BorderTop + window->BorderBottom + window->WScreen->RastPort.TxHeight + 46, -1, -1);
  187.  
  188.             /* Create the gadgets/images with interconnection */
  189.             prop_object = NewObject(NULL, "propgclass",
  190.                                     GA_ID,            2,
  191.                                     GA_Top,            window->BorderTop,
  192.                                     GA_RelRight,    -(window->BorderRight - 5),
  193.                                     GA_Width,        window->BorderRight - 8,
  194.                                     GA_RelHeight,    -(window->BorderTop + (3 * window->BorderBottom)) - 2,
  195.                                     GA_RightBorder,    TRUE,
  196.                                     ICA_MAP,        prop2text,
  197.                                     PGA_NewLook,    TRUE,
  198.                                     PGA_Borderless,    TRUE,
  199.                                     PGA_Visible,    50,        /* will get set later */
  200.                                     PGA_Total,        50,        /* will get set later */
  201.                                     TAG_END);
  202.  
  203.             up_image = NewObject(NULL, "sysiclass",
  204.                                     SYSIA_DrawInfo,    draw_info,
  205.                                     SYSIA_Which,    UPIMAGE,
  206.                                     IA_Width,        window->BorderRight,
  207.                                     IA_Height,        window->BorderBottom,
  208.                                     TAG_END);
  209.  
  210.             down_image = NewObject(NULL, "sysiclass",
  211.                                     SYSIA_DrawInfo,    draw_info,
  212.                                     SYSIA_Which,    DOWNIMAGE,
  213.                                     IA_Width,        window->BorderRight,
  214.                                     IA_Height,        window->BorderBottom,
  215.                                     TAG_END);
  216.  
  217.             up_object = NewObject(NULL, "buttongclass",
  218.                                     GA_RelBottom,    -(3 * window->BorderBottom) - 1,
  219.                                     GA_RelRight,    -(window->BorderRight - 1),
  220.                                     GA_Height,        window->BorderBottom,
  221.                                     GA_Width,        window->BorderRight,
  222.                                     GA_Image,        up_image,
  223.                                     GA_RightBorder,    TRUE,
  224.                                     //GA_RelVerify,    TRUE,
  225.                                     GA_Previous,    prop_object,
  226.                                     ICA_MAP,        up2text,
  227.                                     TAG_END);
  228.  
  229.             down_object = NewObject(NULL, "buttongclass",
  230.                                     GA_RelBottom,    -(2 * window->BorderBottom),
  231.                                     GA_RelRight,    -(window->BorderRight - 1),
  232.                                     GA_Height,        window->BorderBottom,
  233.                                     GA_Width,        window->BorderRight,
  234.                                     GA_Image,        down_image,
  235.                                     GA_RightBorder,    TRUE,
  236.                                     //GA_RelVerify,    TRUE,
  237.                                     GA_Previous,    up_object,
  238.                                     ICA_MAP,        down2text,
  239.                                     TAG_END);
  240.  
  241.             /* Open the clipboard; no need to verify */
  242.             clip_handle = OpenClipboard(0);
  243.             undo_handle = OpenClipboard(42);
  244.  
  245.             text1_object = NewObject(TextFieldClass, NULL,
  246.                                     GA_ID,                    1,
  247.                                     GA_Top,                    window->BorderTop + gap_h,
  248.                                     GA_Left,                window->BorderLeft + gap_w,
  249.                                     GA_RelWidth,            -(window->BorderLeft + window->BorderRight + 2 * gap_w),
  250.                                     GA_RelHeight,            -(window->BorderTop + window->BorderBottom + 2 * gap_h),
  251.                                     GA_Previous,            down_object,
  252.                                     GA_TabCycle,            TRUE,
  253.                                     GA_IntuiText,            &text1_title,
  254.  
  255.                                     ICA_MAP,                text2prop,
  256.                                     ICA_TARGET,                prop_object,
  257.  
  258.                                     TEXTFIELD_Text,            (ULONG)initial_text,
  259.                                     TEXTFIELD_UserAlign,    TRUE,
  260.                                     TEXTFIELD_ClipStream,    clip_handle,
  261.                                     TEXTFIELD_UndoStream,    undo_handle,
  262.                                     TEXTFIELD_Border,        TEXTFIELD_BORDER_DOUBLEBEVEL,
  263.                                     TEXTFIELD_BlinkRate,    500000,
  264.  
  265.                                     /*TEXTFIELD_VCenter,        TRUE,
  266.                                     TEXTFIELD_CursorPos,    10,
  267.                                     TEXTFIELD_Partial,        TRUE,
  268.                                     TEXTFIELD_MaxSize,        1000,
  269.                                     TEXTFIELD_AcceptChars,    "+-1234567890\n",
  270.                                     TEXTFIELD_Alignment,    TEXTFIELD_ALIGN_CENTER,
  271.                                     TEXTFIELD_TextAttr,        (ULONG)&font,
  272.                                     TEXTFIELD_Spacing,        10,
  273.                                     TEXTFIELD_FontStyle,    style,*/
  274.                                     TAG_END);
  275.  
  276.             /* Check if they were all created okay */
  277.             if (text1_object && prop_object && up_image && down_image && up_object && down_object) {
  278.                 ULONG cur;
  279.  
  280.                 /* Do menu stuff */
  281.                 visual_info = GetVisualInfo(window->WScreen, TAG_END);
  282.                 if (visual_info) {
  283.                     menu_strip = CreateMenus(menus, TAG_END);
  284.                     if (menu_strip) {
  285.                         if (LayoutMenus(menu_strip, visual_info, GTMN_NewLookMenus, TRUE, TAG_END)) {
  286.                             if (!SetMenuStrip(window, menu_strip)) {
  287.                                 printf("Can't set menu strip; no menus.\n");
  288.                             }
  289.                         } else {
  290.                             printf("Can't layout menus; no menus.\n");
  291.                         }
  292.                     } else {
  293.                         printf("Can't create menus; no menus.\n");
  294.                     }
  295.                 } else {
  296.                     printf("Can't get visual info; no menus.\n");
  297.                 }
  298.  
  299.                 /* Adjust some of the interconnections */
  300.                 SetGadgetAttrs(prop_object, window, NULL, ICA_TARGET, text1_object, TAG_END);
  301.                 SetGadgetAttrs(up_object, window, NULL, ICA_TARGET, text1_object, TAG_END);
  302.                 SetGadgetAttrs(down_object, window, NULL, ICA_TARGET, text1_object, TAG_END);
  303.  
  304.                 AddGList(window, prop_object, -1, -1, NULL);
  305.                 RefreshGList(prop_object, window, NULL, -1);
  306.  
  307.                 ActivateGadget(text1_object, window, NULL);
  308.                 SetWindowTitles(window, "<-- Scroll to bottom; click to go to top", (UBYTE *)-1);
  309.                 MainLoop();
  310.                 SetGadgetAttrs(text1_object, window, NULL, TEXTFIELD_CursorPos, 0, TAG_DONE);
  311.  
  312.                 ActivateGadget(text1_object, window, NULL);
  313.                 SetWindowTitles(window, "<-- Move cursor; click to remember", (UBYTE *)-1);
  314.                 MainLoop();
  315.                 GetAttr(TEXTFIELD_CursorPos, text1_object, &cur);
  316.  
  317.                 SetWindowTitles(window, "<-- Click to reset cursor", (UBYTE *)-1);
  318.                 MainLoop();
  319.                 SetGadgetAttrs(text1_object, window, NULL, TEXTFIELD_CursorPos, cur, TAG_DONE);
  320.                 ActivateGadget(text1_object, window, NULL);
  321.  
  322.                 SetWindowTitles(window, "<-- Click to move gadget position", (UBYTE *)-1);
  323.                 MainLoop();
  324.                 { // Shows how to change the size on the fly
  325.                   // Also shows the special case of handling size change with GA_Rel#?
  326.                     struct Rectangle rect;
  327.  
  328.                     GetGadgetRect(window, text1_object, &rect);
  329.                     SetAPen(window->RPort, pens[BACKGROUNDPEN]);
  330.                     RectFill(window->RPort, rect.MinX, rect.MinY, rect.MaxX, rect.MaxY);
  331.                     SetGadgetAttrs(text1_object, window, NULL,
  332.                                     GA_Left,        window->BorderLeft,
  333.                                     GA_Top,            window->BorderTop,
  334.                                     GA_RelWidth,    -(window->BorderLeft + window->BorderRight),
  335.                                     GA_RelHeight,    -(window->BorderTop + window->BorderBottom),
  336.                                     GA_IntuiText,    NULL,
  337.                                     TAG_DONE);
  338.                     RefreshGList(text1_object, window, NULL, 1);
  339.                 }
  340.                 //ActivateGadget(text1_object, window, NULL);
  341.  
  342.                 SetWindowTitles(window, "<-- Click to replace text", (UBYTE *)-1);
  343.                 MainLoop();
  344.                 SetGadgetAttrs(text1_object, window, NULL, TEXTFIELD_Text, more_text, TAG_DONE);
  345.                 //ActivateGadget(text1_object, window, NULL);
  346.  
  347.                 SetWindowTitles(window, "<-- Click to select 10 chars", (UBYTE *)-1);
  348.                 MainLoop();
  349.                 SetGadgetAttrs(text1_object, window, NULL, TEXTFIELD_SelectSize, 10, TAG_DONE);
  350.                 ActivateGadget(text1_object, window, NULL);
  351.  
  352.                 SetWindowTitles(window, "<-- Click to print text and info", (UBYTE *)-1);
  353.                 MainLoop();
  354.                 SetGadgetAttrs(text1_object, window, NULL, TEXTFIELD_ReadOnly, TRUE, TAG_DONE);
  355.                 if (GetAttr(TEXTFIELD_Size, text1_object, &length)) {
  356.                     my_buffer = malloc(length + 1);
  357.                     if (my_buffer) {
  358.                         my_buffer[length] = 0;
  359.                         if (GetAttr(TEXTFIELD_Text, text1_object, (ULONG *)&text_buffer)) {
  360.                             if (text_buffer) {
  361.                                 memcpy(my_buffer, text_buffer, length);
  362.                                 printf("%s", my_buffer);
  363.                                 printf("\n");
  364.                             }
  365.                         }
  366.                         free(my_buffer);
  367.                     }
  368.                 }
  369.                 SetGadgetAttrs(text1_object, window, NULL, TEXTFIELD_ReadOnly, FALSE, TAG_DONE);
  370.                 if (GetAttr(TEXTFIELD_Visible, text1_object, &length)) {
  371.                     printf("Visible lines: %d\n", length);
  372.                 }
  373.                 if (GetAttr(TEXTFIELD_Lines, text1_object, &length)) {
  374.                     printf("  Total lines: %d\n", length);
  375.                 }
  376.                 if (GetAttr(TEXTFIELD_Size, text1_object, &length)) {
  377.                     printf("         Size: %d\n", length);
  378.                 }
  379.                 if (GetAttr(TEXTFIELD_Top, text1_object, &length)) {
  380.                     printf("     Top line: %d\n", length);
  381.                 }
  382.  
  383.                 SetWindowTitles(window, "<-- Click to quit", (UBYTE *)-1);
  384.                 MainLoop();
  385.  
  386.                 RemoveGList(window, prop_object, -1);
  387.  
  388.                 /* Clean menu stuff */
  389.                 if (window->MenuStrip) {
  390.                     ClearMenuStrip(window);
  391.                 }
  392.                 if (menu_strip) {
  393.                     FreeMenus(menu_strip);
  394.                 }
  395.                 if (visual_info) {
  396.                     FreeVisualInfo(visual_info);
  397.                 }
  398.             } else {
  399.                 printf("Couldn't get objects.\n");
  400.             }
  401.  
  402.             /* Clean up any objects */
  403.             DisposeObject(text1_object);
  404.             DisposeObject(down_object);
  405.             DisposeObject(up_object);
  406.             DisposeObject(down_image);
  407.             DisposeObject(up_image);
  408.             DisposeObject(prop_object);
  409.  
  410.             /* Close the clipboard */
  411.             if (undo_handle) {
  412.                 CloseClipboard(undo_handle);
  413.             }
  414.             if (clip_handle) {
  415.                 CloseClipboard(clip_handle);
  416.             }
  417.  
  418.             FreeScreenDrawInfo(window->WScreen, draw_info);
  419.         } else {
  420.             printf("Couldn't get draw info.\n");
  421.         }
  422.         CloseWindow(window);
  423.     } else {
  424.         printf("Couldn't open window.\n");
  425.     }
  426.  
  427.     ShutdownPrefsWindow();
  428. }
  429.  
  430. /*
  431.  * GetGadgetRect()
  432.  *
  433.  * This function gets the actual Rectangle where a gadget exists
  434.  * in a window.  The special cases it handles are all the REL#?
  435.  * (relative positioning flags).
  436.  *
  437.  * You need the actual position if you want to RectFill() to clear
  438.  * the space a gadget covers or something like that.
  439.  *
  440.  * The function takes a struct Window pointer, a struct Gadget
  441.  * pointer, and a struct Rectangle pointer.  It uses the window and
  442.  * gadget to fill in the rectangle.
  443.  */
  444.  
  445. static void GetGadgetRect(struct Window *window, struct Gadget *gadget, struct Rectangle *rect)
  446. {
  447.     rect->MinX = rect->MaxX = gadget->LeftEdge;
  448.     if (gadget->Flags & GFLG_RELRIGHT) rect->MinX += window->Width - 1;
  449.     rect->MinY = rect->MaxY = gadget->TopEdge;
  450.     if (gadget->Flags & GFLG_RELBOTTOM) rect->MinY += window->Height - 1;
  451.     rect->MaxX += gadget->Width;
  452.     if (gadget->Flags & GFLG_RELWIDTH) rect->MaxX += window->Width - 1;
  453.     rect->MaxY += gadget->Height;
  454.     if (gadget->Flags & GFLG_RELHEIGHT) rect->MaxY += window->Height - 1;
  455. }
  456.  
  457. /*
  458.  * MainLoop()
  459.  *
  460.  * Handles all window IDCMP messages
  461.  */
  462.  
  463. static void MainLoop(void)
  464. {
  465.     ULONG done = FALSE;
  466.     UWORD menu_num;
  467.  
  468.     while (!done) {
  469.         HandleTextFieldPrefsIDCMP();
  470.         while (msg = (struct IntuiMessage *)GetMsg((struct MsgPort *)window->UserPort)) {
  471.             if (msg->Class == IDCMP_CLOSEWINDOW) {
  472.                 done = TRUE;
  473.             } else if ((msg->Class == IDCMP_VANILLAKEY) && (msg->Code == 0x09)) {
  474.                 // Activate first gadget that supports tab cycling if TAB is pressed
  475.                 ActivateTabGadget(window);
  476.             } else if (msg->Class == IDCMP_MENUPICK) {
  477.                 menu_num = msg->Code;
  478.                 while (menu_num != MENUNULL) {
  479.                     DoMenu(ITEMNUM(menu_num));
  480.                     menu_num = ItemAddress(menu_strip, menu_num)->NextSelect;
  481.                 }
  482.                 ActivateGadget(text1_object, window, NULL);
  483.             }
  484.             ReplyMsg((struct Message *)msg);
  485.         }
  486.         if (!done) {
  487.             Wait(sigs);
  488.         }
  489.     }
  490. }
  491.  
  492. /*
  493.  * ActivateTabGadget()
  494.  *
  495.  * This function scans a window's gadget list and activates the
  496.  * first gadget that supports tab cycling.
  497.  *
  498.  * It should be called when your window gets a VANILLAKEY message
  499.  * with a TAB code (0x09).  This gives the user a way to start
  500.  * tab cycling through gadgets.
  501.  */
  502.  
  503. static void ActivateTabGadget(struct Window *window)
  504. {
  505.     struct Gadget *gad;
  506.  
  507.     for (gad = window->FirstGadget; gad != NULL; gad = gad->NextGadget) {
  508.         if ((gad->Flags & GFLG_TABCYCLE) && !(gad->Flags & GFLG_DISABLED)) {
  509.             ActivateGadget(gad, window, NULL);
  510.             break;
  511.         }
  512.     }
  513. }
  514.  
  515. /*
  516.  * DoMenu()
  517.  *
  518.  * Handle the Edit menu items
  519.  */
  520.  
  521. static void DoMenu(UWORD item)
  522. {
  523.     ULONG tag = 0;
  524.  
  525.     switch (item) {
  526.         case CUT_ITEM:
  527.             tag = TEXTFIELD_Cut;
  528.             break;
  529.         case COPY_ITEM:
  530.             tag = TEXTFIELD_Copy;
  531.             break;
  532.         case COPYALL_ITEM:
  533.             tag = TEXTFIELD_CopyAll;
  534.             break;
  535.         case PASTE_ITEM:
  536.             tag = TEXTFIELD_Paste;
  537.             break;
  538.         case UNDO_ITEM:
  539.             tag = TEXTFIELD_Undo;
  540.             break;
  541.         case ERASE_ITEM:
  542.             tag = TEXTFIELD_Erase;
  543.             break;
  544.     }
  545.     if (tag > 0) {
  546.         SetGadgetAttrs(text1_object, window, NULL, tag, 0, TAG_DONE);
  547.     }
  548. }
  549.  
  550. /*
  551.  * SetupPrefsWindow()
  552.  *
  553.  * Opens the preferences window generated by GadToolsBox
  554.  */
  555.  
  556. static BOOL SetupPrefsWindow(void)
  557. {
  558.     if (SetupScreen() == 0) {
  559.         if (OpenTextFieldPrefsWindow() == 0) {
  560.             return TRUE;
  561.         } else {
  562.             CloseDownScreen();
  563.         }
  564.     }
  565.  
  566.     return FALSE;
  567. }
  568.  
  569. /*
  570.  * ShutdownPrefsWindow()
  571.  *
  572.  * Closes the preferences window generated by GadToolsBox
  573.  */
  574.  
  575. static void ShutdownPrefsWindow(void)
  576. {
  577.     CloseTextFieldPrefsWindow();
  578.     CloseDownScreen();
  579. }
  580.