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

  1. /*
  2.  * MUI Test
  3.  *
  4.  * MUITest is a small example that shows how one would read
  5.  * the text from the Textfield gadget used in a MUI interface.
  6.  */
  7.  
  8. #include <stdio.h>
  9.  
  10. #include <exec/types.h>
  11. #include <libraries/mui.h>
  12. #include <intuition/classes.h>
  13. #include <gadgets/textfield.h>
  14.  
  15. #include <proto/muimaster.h>
  16. #include <proto/dos.h>
  17. #include <proto/exec.h>
  18. #include <proto/intuition.h>
  19.  
  20. #include <clib/alib_protos.h>
  21.  
  22. #include "muitest.h"
  23.  
  24. static BOOL init(void);
  25. static void clean(void);
  26.  
  27. struct Library *MUIMasterBase;
  28.  
  29. main()
  30. {
  31.     BOOL running = TRUE;
  32.     ULONG signal;
  33.     struct ObjApp *obj_app;
  34.  
  35.     if (init()) {
  36.         obj_app = CreateApp();
  37.         if (obj_app) {
  38.             DoMethod(obj_app->window, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, obj_app->App, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
  39.             set(obj_app->window, MUIA_Window_Open, TRUE);
  40.  
  41.             while (running) {
  42.                 switch (DoMethod(obj_app->App, MUIM_Application_Input, &signal)) {
  43.                     case MUIV_Application_ReturnID_Quit:
  44.                         running = FALSE;
  45.                         break;
  46.                 }
  47.                 if (running && signal) {
  48.                     Wait(signal);
  49.                 }
  50.             }
  51.  
  52.             {
  53.                 struct Window *window;
  54.                 struct Gadget *gadget;
  55.                 char *text;
  56.                 ULONG size, i;
  57.  
  58.                 GetAttr(MUIA_Window_Window, obj_app->window, (ULONG *)&window);
  59.                 GetAttr(MUIA_Boopsi_Object, obj_app->text, (ULONG *)&gadget);
  60.                 if (window) {
  61.                     SetGadgetAttrs(gadget, window, NULL, TEXTFIELD_ReadOnly, TRUE, TAG_DONE);
  62.                     GetAttr(TEXTFIELD_Size, gadget, &size);
  63.                     GetAttr(TEXTFIELD_Text, gadget, (ULONG *)&text);
  64.                     if (text && size) {
  65.                         for (i = 0; i < size; i++) {
  66.                             putchar(text[i]);
  67.                         }
  68.                     }
  69.                     SetGadgetAttrs(gadget, window, NULL, TEXTFIELD_ReadOnly, FALSE, TAG_DONE);
  70.                 } else {
  71.                     printf("No window\n");
  72.                 }
  73.             }
  74.  
  75.             DisposeApp(obj_app);
  76.         }
  77.     }
  78. }
  79.  
  80. static BOOL init(void)
  81. {
  82.     MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN);
  83.     if (MUIMasterBase) {
  84.         return TRUE;
  85.     } else {
  86.         return FALSE;
  87.     }
  88. }
  89.  
  90. static void clean(void)
  91. {
  92.     CloseLibrary(MUIMasterBase);
  93. }
  94.