home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sys / amiga / programm / 15514 < prev    next >
Encoding:
Text File  |  1992-11-08  |  8.9 KB  |  284 lines

  1. Newsgroups: comp.sys.amiga.programmer
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!torn!nott!cu23.crl.aecl.ca!wl.aecl.ca!taylorm
  3. From: taylorm@wl.aecl.ca
  4. Subject: Listview slider problem (Code included)
  5. Message-ID: <7NOV92.13340477@wl.aecl.ca>
  6. Sender: news@cu23.crl.aecl.ca (USENET News System)
  7. Nntp-Posting-Host: wc4.wl.aecl.ca
  8. Organization: AECL RESEARCH
  9. Date: Sat, 7 Nov 1992 19:34:04 GMT
  10. Lines: 272
  11.  
  12. Here is the source code for a program that opens a window with a Listview
  13. gadget in it.  The problem is that the slider on the listview does not
  14. render properly.  The slider does, however, function properly in all other
  15. respects.  The slider appears in blue and always seems to be full height.
  16.  
  17. This code is part of a much larger program with other gadgets that function
  18. and look proper.  I removed the rest of the code to make the bug easier to
  19. find.
  20.  
  21. I am only posting this as a final resort.  I have agonized over it for long
  22. hours with no luck.  I have also poured through the examples in the RKMs.
  23. I have also checked it against the program "Demo" by Miller in the August
  24. 1991 Amigaworld Tech Journal which does compile and run properly.
  25. Anyone who could find the bug would receive my enternal gratitude and 
  26. preserve my sanity.
  27.  
  28. This should compile effortlessly under SAS/C 6.0. 
  29.  
  30. /*****************/
  31. /* Include Files */
  32. /*****************/
  33.  
  34. #include <exec/types.h>
  35. #include <exec/memory.h>    
  36. #include <exec/lists.h>     
  37. #include <intuition/intuition.h> 
  38. #include <intuition/imageclass.h>         
  39. #include <intuition/gadgetclass.h>       
  40. #include <libraries/gadtools.h>
  41. #include <clib/alib_protos.h> 
  42. #include <clib/exec_protos.h>   
  43. #include <clib/graphics_protos.h>  
  44. #include <clib/intuition_protos.h>
  45. #include <clib/gadtools_protos.h> 
  46. #include <stdio.h>
  47.  
  48.  
  49.  
  50. struct List stack;               /* Exec list structure for stack       */
  51.  
  52. long win_width  = 221;           /* Window width                        */
  53. long win_innerheight = 179;      /* Inner height of window              */
  54. long x_coord = 0;                /* Coordinates for window to open at   */
  55. long y_coord = 0;
  56.  
  57. struct TextAttr Topaz80 = { "topaz.font", 8, 0, 0, };
  58.                                  /* Font definition                     */
  59.  
  60. struct Library *IntuitionBase;   /* Pointers to libraries               */
  61. struct Library *GfxBase;
  62. struct Library *GadToolsBase;
  63.  
  64. struct Screen  *calcsc  = NULL;  /* Screen pointer                      */
  65. struct Window  *calcwin = NULL;  /* Window pointer                      */
  66.  
  67. struct Gadget   *glist  = NULL; 
  68. void *vi;                 /* VisualInfo pointer                  */
  69.  
  70. struct Remember *rmem = NULL;
  71.  
  72. char *month_labels[] = {                                          
  73.            "January", "February", "March", "April", "May", "June", "July",
  74.            "August", "September", "October", "November", "December", NULL 
  75.            };
  76.  
  77.  
  78. /***************/
  79. /* Subprograms */
  80. /***************/
  81.  
  82.  
  83. VOID errorMessage(char *message)
  84. {
  85.    printf("%s\n",message);
  86.  
  87.  
  88. /* Set up Gadgets */
  89. struct Gadget *createGadgets(UWORD topborder)
  90. {  
  91.    struct NewGadget ng;
  92.    struct Gadget *gad;
  93.    struct Node *node;
  94.    int index;
  95.  
  96.    gad = CreateContext(&glist);
  97.  
  98.    NewList(&stack);                  /* Initialize Global Variables */
  99.  
  100.    index = 0;                                                        
  101.    while (month_labels[index])                                       
  102.       {                                                                 
  103.       node = (struct Node *)AllocRemember(&rmem, sizeof(struct Node), 
  104.                                           MEMF_CLEAR);               
  105.       /* if (!node)                                                     
  106.          abort("Couldn't allocate LISTVIEW List."); */
  107.  
  108.       node->ln_Name = month_labels[index++];                         
  109.       AddTail(&stack, node);                                          
  110.       }
  111.  
  112.    ng.ng_LeftEdge   = 10;                             
  113.    ng.ng_Width      = 201;
  114.    ng.ng_GadgetText = NULL;
  115.    ng.ng_TextAttr   = &Topaz80;   
  116.    ng.ng_VisualInfo = vi;                               
  117.    ng.ng_TopEdge    = 7+topborder;
  118.    ng.ng_Height     = 80;
  119.    ng.ng_GadgetID   = 0;
  120.    ng.ng_Flags      = 0;
  121.  
  122.    gad = CreateGadget (LISTVIEW_KIND, gad, &ng,
  123.                                 GTLV_Labels, &stack,
  124.                                 GTLV_ReadOnly, TRUE,
  125.                                 GTLV_ScrollWidth, 18,
  126.                                 GTLV_Top, 1,
  127.                                 LAYOUTA_Spacing, 1,
  128.                                 TAG_END);
  129.  
  130.    return(gad);
  131. }
  132.  
  133.  
  134. VOID process_window_events(VOID)
  135. {
  136.    struct IntuiMessage *imsg;
  137.    ULONG imsgClass;
  138.    UWORD imsgCode;
  139.    struct Gadget *gad;
  140.    BOOL terminated = FALSE;
  141.  
  142.    while (!terminated)
  143.       {
  144.       Wait (1 << calcwin->UserPort->mp_SigBit);
  145.  
  146.       while ((!terminated) &&
  147.              (imsg = GT_GetIMsg(calcwin->UserPort)))
  148.          {
  149.          gad = (struct Gadget *)imsg->IAddress;
  150.  
  151.          imsgClass = imsg->Class;
  152.          imsgCode  = imsg->Code;
  153.  
  154.          GT_ReplyIMsg(imsg);
  155.  
  156.          switch (imsgClass)
  157.             {
  158.             case IDCMP_GADGETDOWN:
  159.                break;
  160.             case IDCMP_GADGETUP:
  161.                break;
  162.             case IDCMP_CLOSEWINDOW:
  163.                terminated = TRUE;
  164.                break;
  165.             case IDCMP_REFRESHWINDOW:
  166.                GT_BeginRefresh(calcwin);
  167.                GT_EndRefresh(calcwin, TRUE);
  168.                break;
  169.             }
  170.          }
  171.       }
  172. }
  173.  
  174.  
  175. VOID gadtoolsWindow(int argc, char **argv)
  176.    struct TextFont *font;
  177.    UWORD  topborder;
  178.  
  179.  
  180.    if (NULL == (font = OpenFont(&Topaz80)))
  181.       errorMessage( "Failed to open Topaz 80");
  182.    else
  183.       {
  184.       if (NULL == (calcsc = LockPubScreen("Workbench")))
  185.          errorMessage( "Couldn't lock default public screen");
  186.       else
  187.          {       
  188.          if (NULL ==(vi = GetVisualInfo(calcsc, TAG_END)))
  189.             errorMessage( "GetVisualInfo() failed");
  190.          else
  191.             {
  192.             topborder = calcsc->WBorTop + (calcsc->Font->ta_YSize + 1);
  193.  
  194.             if (NULL == createGadgets(topborder))
  195.                errorMessage ( "createAllGadgets() failed");
  196.             else
  197.                {
  198.                if (NULL == (calcwin = OpenWindowTags(NULL,
  199.                        WA_Left,          x_coord,
  200.                        WA_Top,           y_coord,
  201.                        WA_Title,         "Listview test",
  202.                        WA_Gadgets,       glist,
  203.                        WA_AutoAdjust,    FALSE,
  204.                        WA_Width,         win_width,
  205.                        WA_InnerHeight,   win_innerheight,
  206.                        WA_DragBar,       TRUE,
  207.                        WA_DepthGadget,   TRUE,
  208.                        WA_Activate,      TRUE,
  209.                        WA_CloseGadget,   TRUE,
  210.                        WA_SizeGadget,    FALSE,
  211.                        WA_SimpleRefresh, TRUE,
  212.                        WA_DetailPen,     -1,
  213.                        WA_BlockPen,      -1, 
  214.                        WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW |
  215.                                         LISTVIEWIDCMP,
  216.                        WA_PubScreen,     calcsc,
  217.                        TAG_END)))
  218.                   errorMessage( "OpenWindow() failed");
  219.                else
  220.                   {
  221.                   /*AddGList(calcwin, glist, (UWORD)-1, (UWORD)-1, NULL); */
  222.  
  223.                   /* AddGList(calcwin, &CUST_SQRT, ~0, 6L, NULL); */
  224.                   RefreshGList(glist, calcwin, NULL, (UWORD)-1);
  225.  
  226.                   GT_RefreshWindow(calcwin, NULL);
  227.  
  228.                   process_window_events(); 
  229.  
  230.                   /* clear_stack(); */
  231.  
  232.                   CloseWindow(calcwin);
  233.                   }
  234.               }
  235.             FreeGadgets(glist);
  236.             FreeVisualInfo(vi);            
  237.             }
  238.          UnlockPubScreen(NULL, calcsc);
  239.          } 
  240.       CloseFont(font);
  241.       }
  242. }      
  243.  
  244.  
  245. /* Open Libraries and run main code */
  246. VOID main(int argc, char **argv)
  247. {      
  248.    if (NULL == (IntuitionBase = OpenLibrary("intuition.library", 37)))
  249.       errorMessage( "Requires V37 intuition.library");
  250.    else
  251.       {
  252.       if (NULL == (GfxBase = OpenLibrary("graphics.library", 37)))
  253.          errorMessage ("Requires V37 graphics.library");
  254.       else
  255.          {
  256.          if (NULL ==(GadToolsBase = OpenLibrary("gadtools.library", 37)))
  257.             errorMessage( "Requires V37 gadtools.library");
  258.          else
  259.             {
  260.             gadtoolsWindow(argc, argv);
  261.  
  262.                if (rmem) FreeRemember(&rmem, TRUE);
  263.  
  264.             CloseLibrary(GadToolsBase);
  265.             }
  266.          CloseLibrary(GfxBase);
  267.          }
  268.       CloseLibrary(IntuitionBase); 
  269.       }
  270.  
  271.  
  272.  
  273. -------Cut-------
  274.  
  275. *****************************************************************************
  276.   In search of the virtual world       *             /\/\ike Taylor
  277.                                        * mataylor@undergrad.math.uwaterloo.ca
  278.     Sometimes real is too real         *          taylorm@wl.aecl.ca
  279. *****************************************************************************
  280.  
  281.