home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / text / tex / pastex / source / driver / show / amiga / pgscroll.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-14  |  7.4 KB  |  315 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #include <exec/types.h>
  5. #include <utility/tagitem.h>
  6. #include <intuition/intuition.h>
  7.  
  8. #include <intuition/classusr.h>
  9. #include <intuition/imageclass.h>
  10. #include <intuition/gadgetclass.h>
  11. #include <intuition/cghooks.h>
  12. #include <intuition/icclass.h>
  13. #include <intuition/classes.h>
  14.  
  15. #include <clib/intuition_protos.h>
  16. #include <clib/exec_protos.h>
  17. #include <clib/utility_protos.h>
  18. #include <clib/alib_protos.h>
  19. #include <pragmas/intuition_pragmas.h>
  20. #include <pragmas/exec_pragmas.h>
  21. #include <pragmas/utility_pragmas.h>
  22.  
  23. #include "globals.h"
  24. #include "pgmodel.h"
  25. #include "pgscroll.i"
  26.  
  27.  
  28.  
  29. extern struct  ExecBase           *SysBase;
  30. extern struct  IntuitionBase   *IntuitionBase;
  31. extern struct  GfxBase         *GfxBase;
  32. extern struct  Library         *UtilityBase;
  33.  
  34.  
  35. static Object        * mymodel     = NULL;    /* the repository of the "Current Value" */
  36. static void        * MyModClass    = NULL;
  37.  
  38.  
  39. static struct Gadget    * propg        = NULL;
  40. static struct Gadget    * stringg    = NULL;
  41. static struct Gadget    * rightarrowg    = NULL;
  42. static struct Gadget    * leftarrowg    = NULL;
  43. static struct Gadget    * mygadgets    = NULL;        /* linked list    */
  44.  
  45. /* pictures for arrows    */
  46. static struct Image    * rightimage    = NULL;
  47. static struct Image    * leftimage    = NULL;
  48.  
  49.  
  50. /* some static layout and setup constants, for now    */
  51. #define SWIDTH        (3*8)
  52. #define INITVAL        (0)    /* initial value of string and slider    */
  53. #define PWIDTH        (200)    /* width of horizontal propslider    */
  54.  
  55.  
  56. enum gadgetids {
  57.     gUp = 50,
  58.     gDown,
  59.     gSlider,
  60.     gString,
  61. };
  62.  
  63.  
  64. /****************************************************************/
  65. /*  mapping tag lists                        */
  66. /****************************************************************/
  67.  
  68. /* for IDCMPUPDATE    */
  69. struct TagItem    model2me[] = {
  70.     {MYMODA_CURRVAL, ICSPECIAL_CODE },    /* put (16 bits of) currval into IntuiMessage.Code */
  71.     {TAG_END, }
  72. };
  73.  
  74. struct TagItem    slider2model[] = {
  75.     {PGA_TOP, MYMODA_CURRVAL},
  76.     {TAG_END, }
  77. };
  78.  
  79. struct TagItem    model2slider[] = {
  80.     {MYMODA_CURRVAL, PGA_TOP},
  81.     {MYMODA_RANGE,   PGA_TOTAL },
  82.     {TAG_END, }
  83. };
  84.  
  85. struct TagItem    string2model[] = {
  86.     {STRINGA_LongVal, MYMODA_CURRVAL},
  87.     {TAG_END, }
  88. };
  89.  
  90. struct TagItem    model2string[] = {
  91.     {MYMODA_CURRVAL, STRINGA_LongVal},
  92.     {TAG_END, }
  93. };
  94.  
  95. struct TagItem    uparrow2model[] = {
  96.     {GA_ID, MYMODA_INCRSTROBE},
  97.     {TAG_END, }
  98. };
  99.  
  100. struct TagItem    downarrow2model[] = {
  101.     {GA_ID, MYMODA_DECRSTROBE},
  102.     {TAG_END, }
  103. };
  104.  
  105.  
  106. /* a macro for the "adjacent" position to the right of a gadget,
  107.  * but safe, if the reference gadget is NULL
  108.  */
  109. #define RIGHTBY( g )    ( ((g)==NULL)? 20: ((g)->LeftEdge + (g)->Width ) )
  110.  
  111.  
  112.  
  113.  
  114. int InitPGScrollGad(struct Window * w, struct DrawInfo * drinfo)
  115. {
  116.     struct Gadget    * tmpgad;
  117.     Object        * ic;
  118.  
  119.  
  120.     /* get images for the up and down arrows, sensitive
  121.      * to depth and pen specs for current screen (we'll be
  122.      * adding resolution/size selection later).
  123.      */
  124.     rightimage = (struct Image *) NewObject( NULL, "sysiclass",
  125.             SYSIA_Size,    0,        /* normal "medium-res" for now */
  126.             SYSIA_DrawInfo, drinfo,
  127.             SYSIA_Which,    RIGHTIMAGE,
  128.                 TAG_END );
  129.  
  130.     leftimage = (struct Image *) NewObject( NULL, "sysiclass",
  131.             SYSIA_Size,    0,        /* normal "medium-res" for now */
  132.             SYSIA_Which,    LEFTIMAGE,
  133.             SYSIA_DrawInfo, drinfo,
  134.                 TAG_END );
  135.  
  136.  
  137.     /* get "model" object which is the repository of our "current
  138.      * value" and is the hub of object interconnection.
  139.      * This thing also is used to free icclass objects,
  140.      * so we'd better make sure it got allocated.
  141.      */
  142.     MyModClass = initMyModClass();    /* private class    */
  143.  
  144.     mymodel = (Object *) NewObject( MyModClass, NULL, 
  145.             ICA_TARGET,    ICTARGET_IDCMP,    /* talk to me    */
  146.             ICA_MAP,    model2me,
  147.             TAG_END );
  148.  
  149.     if ( ! mymodel ) {
  150.       DispPGScrollGad( w );
  151.       return FALSE;
  152.     }
  153.  
  154.     /* make gadgets, link into list (easier starting with Beta 4) */
  155.     tmpgad = (struct Gadget *) &mygadgets;
  156.  
  157.  
  158.     stringg  = (struct Gadget *) NewObject(NULL, "strgclass",
  159.             GA_ID,            gString,
  160.             GA_Width,        SWIDTH,
  161.             GA_Height,        8,        /* fix this    */
  162.             GA_Left,        w->BorderLeft+5,
  163.             GA_RelBottom,        -w->BorderBottom+2,
  164.             GA_BottomBorder,    TRUE,
  165.             GA_Previous,        tmpgad,
  166.  
  167.             STRINGA_MaxChars,    5,
  168.             STRINGA_LongVal,    INITVAL,
  169.             STRINGA_Justification,    STRINGRIGHT,
  170.  
  171.             ICA_TARGET,        mymodel,
  172.             ICA_MAP,        string2model,
  173.             TAG_END );
  174.  
  175.     propg = (struct Gadget *) NewObject( NULL, "propgclass",
  176.             GA_ID,            gSlider,
  177.             GA_Left,        RIGHTBY(stringg)+2,
  178.             GA_RelBottom,        -w->BorderBottom+1+2,
  179.             GA_BottomBorder,    TRUE,
  180.             GA_Height,        6,    /* normale border bottom mit size gadg */
  181.             GA_Width,        PWIDTH,    /* height to be specified    */
  182.             GA_Previous,        tmpgad,
  183.  
  184.             PGA_Freedom,        FREEHORIZ,
  185.             PGA_NewLook,        TRUE,
  186.             PGA_Borderless,        TRUE,
  187.             PGA_Top,        INITVAL,
  188.             PGA_Total,        1,
  189.             PGA_Visible,        1,        /* want an integer value slider    */
  190.  
  191.             ICA_TARGET,        mymodel,
  192.             ICA_MAP,        slider2model,
  193.             TAG_END );
  194.  
  195.  
  196.     leftarrowg = (struct Gadget *) NewObject( NULL, "buttongclass",
  197.             GA_ID,            gDown,
  198.             GA_Left,        RIGHTBY(propg) + 2,
  199.             GA_RelBottom,        -w->BorderBottom+1,
  200.             GA_BottomBorder,    TRUE,
  201.             GA_Image,        leftimage,
  202.             GA_Previous,        tmpgad,
  203.  
  204.             ICA_TARGET,        mymodel,
  205.             ICA_MAP,        downarrow2model,
  206.             TAG_END );
  207.  
  208.     /* get up/down arrow button gadgets    */
  209.     rightarrowg = (struct Gadget *) NewObject( NULL, "buttongclass",
  210.             GA_ID,            gUp,
  211.             GA_Left,        RIGHTBY(leftarrowg),
  212.             GA_RelBottom,        -w->BorderBottom+1,
  213.             GA_BottomBorder,    TRUE,
  214.             GA_Image,         rightimage,
  215.             GA_Previous,        tmpgad,
  216.  
  217.             ICA_TARGET,        mymodel,
  218.             ICA_MAP,        uparrow2model,
  219.             TAG_END );
  220.  
  221.     /*
  222.      * We now have all the gadgets talking to the model,
  223.      * but we need to create some little IC nodes for
  224.      * the model to update the string and propotional gadgets
  225.      */
  226.     ic = NewObject( NULL, ICCLASS,
  227.             ICA_TARGET,        stringg,
  228.             ICA_MAP,        model2string,
  229.             TAG_END );
  230.     DoMethod( mymodel, OM_ADDMEMBER, ic );
  231.  
  232.     ic = NewObject( NULL, ICCLASS,
  233.             ICA_TARGET,        propg,
  234.             ICA_MAP,        model2slider,
  235.             TAG_END );
  236.     DoMethod( mymodel, OM_ADDMEMBER, ic );
  237.  
  238.  
  239.     AddGList( w, mygadgets, -1, 4, NULL );
  240.     RefreshGList( mygadgets, w, NULL, 4 );
  241.  
  242.  
  243.     return TRUE;    // alle ok!
  244. }
  245.  
  246.  
  247.  
  248. void ChangePGScrollGad(struct Window * w, int range, int curval)
  249. {
  250.     /* although we're changing the attributes of
  251.      * the model, if we want the gadgets attached 
  252.      * to it to be able to refresh, we have to 
  253.      * use SetGadgetAttr()s rather than SetAttrs()
  254.      */
  255.  
  256.     SetAttrs( mymodel, 
  257.         MYMODA_RANGE, range,
  258.         MYMODA_CURRVAL, curval,
  259.         MYMODA_LOWERB, 1,
  260.         TAG_END );
  261.     //RefreshGList( mygadgets, w, NULL, 4 );
  262.     RefreshGList( rightarrowg, w, NULL, 4 );
  263.     RefreshGList( stringg, w, NULL, 1 );
  264.  
  265.     /*
  266.     SetGadgetAttrsA( (struct Gadget *)mymodel, w, NULL, setrangevaltags);
  267.     SetGadgetAttrs( (struct Gadget *)mymodel, w, NULL,
  268.                 MYMODA_RANGE, PROPRANGE,
  269.             MYMODA_CURRVAL, PROPRANGE/2,
  270.             TAG_END );
  271.     */
  272. }
  273.  
  274.  
  275. void DispPGScrollGad(struct Window * w)
  276. {
  277.     RemoveGList( w, mygadgets, 4 );
  278.  
  279.     DisposeObject( mymodel );
  280.  
  281.     DisposeObject( propg );
  282.     DisposeObject( stringg );
  283.     DisposeObject( rightarrowg );
  284.     DisposeObject( leftarrowg );
  285.  
  286.     mymodel   = NULL;
  287.     mygadgets = NULL;
  288.     
  289.     propg = NULL;
  290.     stringg = NULL;
  291.     rightarrowg = NULL;
  292.     leftarrowg = NULL;
  293.  
  294.     DisposeObject(rightimage);
  295.     DisposeObject(leftimage);
  296.     
  297.     rightimage = NULL;
  298.     leftimage  = NULL;
  299.  
  300.     if ( MyModClass ) {
  301.     freeMyModClass( MyModClass );
  302.     MyModClass = NULL;
  303.     }
  304. }
  305.  
  306.  
  307. long GetValPgScrollGad(void)
  308. {
  309.   ULONG currval;
  310.  
  311.   GetAttr( MYMODA_CURRVAL, mymodel, &currval );
  312.   
  313.   return (long)currval;
  314. }
  315.