home *** CD-ROM | disk | FTP | other *** search
/ World of A1200 / World_Of_A1200.iso / programs / develop / visualarts / docs / gadgets.readme < prev    next >
Text File  |  1995-02-27  |  5KB  |  200 lines

  1.  
  2. Getting information for a specific gadget.
  3. ------------------------------------------
  4.  
  5. The following #defines are taking from VisualArts.h file included with
  6. Visual Arts.
  7.  
  8. #define GetString(gad)            (((struct StringInfo *)gad->SpecialInfo)->Buffer)
  9. #define GetUndoString(gad)    (((struct StringInfo *)gad->SpecialInfo)->UndoBuffer)
  10. #define GetNumber(gad)            (((struct StringInfo *)gad->SpecialInfo)->LongInt)
  11.  
  12. gad - is the gadget structure name to pass to.
  13.  
  14. 1. GetString() function will return the string for the GadTool STRING_KIND
  15.  
  16.    eg: 
  17.    
  18.    #define ID_name                      1   //defined by Visual Arts
  19.    #define ID_age                       2   //defined by Visual Arts
  20.    struct Gadget *DemoGadgets[5];           //defined by Visual Arts
  21.    char myvar[80];
  22.    
  23.    strcpy(myvar, GetString(DemoGadgets[ID_name]));
  24.    
  25.    this will copy the string in DemoGadget into myvar.  Note that the
  26.    contants 'ID_name' and DemoGadgets[] is defined by Visual Arts.
  27.    
  28. 2. GetNumber() function will return the number for the GadTool INTEGER_KIND
  29.  
  30.    eg: 
  31.    
  32.    #define ID_name                     1   //defined by Visual Arts
  33.    #define ID_age                      2   //defined by Visual Arts
  34.    struct Gadget *DemoGadgets[5];          //defined by Visual Arts
  35.    int myinteger;
  36.    
  37.    myinteger = GetNumber(DemoGadgets[ID_age]);
  38.    
  39.    this will copy the string in DemoGadget into myvar.  Note that the
  40.    contants 'ID_age' and DemoGadgets[] is defined by Visual Arts.
  41.  
  42.  
  43. 3. GetUndoString() function will return the undo string for the GadTool 
  44.    STRING_KIND.  This is handy if the user types over the string gadget and
  45.    you want to undo because they have entered a invalid entry.
  46.  
  47.    char undo[255];
  48.    
  49.    //get the previous name
  50.    strcpy(undo, GetUndoString(DemoGadgets[ID_name]));
  51.    
  52.    //set the string gadget back to the previous name
  53.    GT_SetGadgetAttrs(DemoGadgets[ID_name], DemoWnd, NULL,
  54.      GTST_String, undo, TAG_END);
  55.  
  56. 4. Get the item selected from a ListView, Cycle, Popup and MX gadgets.
  57.  
  58. example:
  59.  
  60. //Visual Arts message object.  This structure gets passed to every active
  61. //GadTool
  62.  
  63. struct VAobject {
  64.   struct Window *va_Window;             //window the object originated
  65.   struct Gadget *va_Gadget;             //the gadget that sent this object
  66.   struct IntuiMessage *va_IntuiMsg;     //the IntuiMessage
  67.   ULONG va_Flags;                       //user flags 
  68.   APTR va_UserData;                     //user data, function pointer etc..
  69. };
  70.  
  71.  
  72. /*
  73.    for ListView, Cycle, Popup and MX gadgets the VAObject.va_IntuiMsg->Code
  74.    always contain the item the user selected, and you have always check
  75.    this field when the user selects the gadget.
  76. */
  77. int listviewObj(struct VAobject VAObject)
  78. {
  79.   int item;
  80.   
  81.   //get the item selected by the user
  82.   item = VAObject.va_IntuiMsg->Code;      //get the item here!!!!
  83.   printf("you selected item %d\n", item);
  84.   
  85.   return(1L);
  86. }
  87.  
  88. 5. Get from check boxes
  89.  
  90. int SmokerObj(struct VAobject VAObject)
  91. {
  92.   if (VAObject.va_Gadget->Flags & GFLG_SELECTED) //check if its checked
  93.     printf("this person is a smoker\n");
  94.   else
  95.     printf("this person does not smoke\n");
  96.   return(1L);
  97. }
  98. /*    Check Box  Cool!         */ 
  99.  
  100.  
  101. 6. Setting GadTools.  For GadTools always use the  GT_SetGadgetAttrs()
  102.    function and never use the anyother method.
  103.  
  104.    to disable any GadTool use.  Note you can't disable listview and mx
  105.      
  106.    //disable gadget
  107.    GT_SetGadgetAttrs(DemoGadgets[ID_save], DemoWnd, NULL,
  108.      GA_Disabled, TRUE, TAG_END);
  109.  
  110. a. string gadgets
  111.  
  112.    GT_SetGadgetAttrs(DemoGadgets[ID_name], DemoWnd, NULL,
  113.      GTST_String, "Joe Blow", TAG_END);
  114.  
  115.    GT_SetGadgetAttrs(DemoGadgets[ID_name], DemoWnd, NULL,
  116.      GTST_String, myname, TAG_END);
  117.  
  118. b. integer gadgets
  119.  
  120.    GT_SetGadgetAttrs(DemoGadgets[ID_age], DemoWnd, NULL,
  121.      GTIN_Number, "Joe Blow", TAG_END);
  122.  
  123.    GT_SetGadgetAttrs(DemoGadgets[ID_age], DemoWnd, NULL,
  124.      GTST_Number, yourage, TAG_END);
  125.  
  126. c. checkbox gadgets
  127.  
  128.    //no check mark
  129.    GT_SetGadgetAttrs(DemoGadgets[ID_smoker], DemoWnd, NULL,
  130.      GTCB_Checked, FALSE, TAG_END);
  131.  
  132.    //check mark
  133.    GT_SetGadgetAttrs(DemoGadgets[ID_smoker], DemoWnd, NULL,
  134.      GTCB_Checked, TRUE, TAG_END);
  135.  
  136. d. mx gadgets
  137.  
  138.    eg:  
  139.          0 - Male
  140.          1 - Female
  141.  
  142.    //set it to Female
  143.    GT_SetGadgetAttrs(DemoGadgets[ID_sex], DemoWnd, NULL,
  144.      GTMX_Active, 1 , TAG_END);
  145.  
  146.    //set it to Male
  147.    GT_SetGadgetAttrs(DemoGadgets[ID_sex], DemoWnd, NULL,
  148.      GTMX_Active, 0 , TAG_END);
  149.  
  150. e. cycle gadgets
  151.  
  152.    eg: 
  153.    
  154.       Canada    = 0
  155.       China     = 1
  156.       .
  157.       .
  158.       USA       = 5
  159.       
  160.    //set the cycle to be USA
  161.    GT_SetGadgetAttrs(DemoGadgets[ID_country], DemoWnd, NULL,
  162.      GTCY_Active, 5 , TAG_END);
  163.  
  164. f. slider
  165.  
  166.    min = 10000
  167.    max = 50000
  168.    
  169.    //set the level to 30000
  170.    GT_SetGadgetAttrs(DemoGadgets[ID_salary], DemoWnd, NULL,
  171.      GTSL_Level, 30000 , TAG_END);
  172.  
  173. g. scroller
  174.  
  175.    top = 1
  176.    total = 10
  177.       
  178.    //set the top to start displaying from 5
  179.    GT_SetGadgetAttrs(DemoGadgets[ID_salary], DemoWnd, NULL,
  180.      GTSC_Top, 5 , TAG_END);
  181.  
  182. h. listview
  183.  
  184. //defined by Visual Arts in your project header file .h
  185.  
  186. struct List *DemoLists[2];
  187.  
  188. //this will attach list 1 
  189.    GT_SetGadgetAttrs(DemoGadgets[ID_names], DemoWnd, NULL,
  190.      GTLV_Label, DemoLists[1] , TAG_END);
  191.  
  192.  
  193. To better understand GadTools you should read the RKM in the GadTool
  194. section.  It is very informative.
  195.  
  196.  
  197.  
  198.  
  199.  
  200.