home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 2265 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.9 KB

  1. Path: sunsite.doc.ic.ac.uk!ukc!news
  2. From: bec1@ukc.ac.uk (Ben Clifton)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Removing and Adding Gadgets
  5. Date: 29 Jan 1996 16:56:07 GMT
  6. Organization: Computing Lab, University of Kent at Canterbury, UK.
  7. Message-ID: <3568.6602T1016T654@ukc.ac.uk>
  8. NNTP-Posting-Host: merlin.ukc.ac.uk
  9. X-Newsreader: THOR 2.22 (Amiga;TCP/IP) *UNREGISTERED*
  10.  
  11.  
  12. I`m in need of help.
  13.  
  14. I currently have a set of gadgets on a window that I would like to change
  15. the gadget text on.  There is no function I can find in the RKMs to change
  16. this for me and changing the GadetText field of the gadgets result in non
  17. centred gadget texts and memory over write.  The follow function does not work
  18. correctly - first time it is called it works fine.  Second time it crashes all
  19. systems.   No enforcer hits are generated.  No mungwall reports generated.
  20.  
  21. Can anyone suggest what I`m doing wrong or missing, or explain a better way of
  22. doing this.
  23.  
  24. Thanks in advance.
  25.  
  26. Ben
  27.  
  28. ------
  29.  
  30. void ChangeUserGadgets( int ListNo )
  31. {
  32.   struct FM_UserGadget *ptr;
  33.   UWORD offx, offy;
  34.   UWORD loop;
  35.   struct NewGadget newgad;
  36.   struct Gadget *Gad = NULL;
  37.   struct Gadget *Gad2;
  38.   APTR Cla;
  39.   int StartGad, n1;
  40.  
  41.   offx = Scr->WBorLeft;
  42.   offy = Scr->WBorTop + Scr->Font->ta_YSize+1;
  43.  
  44.   RemoveGList( MainWindow, MainWindowGList, ~0 );
  45.  
  46.   FreeGadgets( MainWindowGList );
  47.  
  48.   if( ListNo == 0 )
  49.     StartGad = MainWindow_UserGad1;
  50.   else
  51.     StartGad = MainWindow_UserGad18;
  52.  
  53.  
  54.   if( SideInfo.NUserGads[0] < USERGAD_MAX/2 )
  55.     n1 = SideInfo.NUserGads[0];
  56.   else
  57.     n1 = USERGAD_MAX/2;
  58.  
  59.   for( loop=SideInfo.NUserGadsStart[ListNo]-1; loop<n1; loop++ )
  60.   {
  61.     ptr = GetUserGadsNode( ListNo, loop );
  62.     FreeVec( MainWindowNewGadgets[StartGad+loop].ng_GadgetText );
  63.     if( MainWindowNewGadgets[StartGad+loop].ng_GadgetText = AllocVec( 10 ,
  64. MEMF_PUBLIC|MEMF_CLEAR ))
  65.       strcpy( MainWindowNewGadgets[StartGad+loop].ng_GadgetText, ptr->
  66. gadgetname );     else
  67.       return;
  68.   }
  69.  
  70.   MainWindowVisualInfo = GetVisualInfoA( Scr, NULL);
  71.   MainWindowDrawInfo = GetScreenDrawInfo( Scr);
  72.  
  73.   MainWindowGList = NULL;
  74.   Gad = CreateContext( &MainWindowGList );
  75.   if( Gad )
  76.   {
  77.     DoRTRequest( "Create New Gadgets", "Okay", "Debug Req" );
  78.     for ( loop=0 ; loop<67 ; loop++ )
  79.     {
  80.       if (MainWindowGadgetTypes[loop] != 198)
  81.       {
  82.         CopyMem((char * )&MainWindowNewGadgets[loop], ( char * )&newgad,
  83. (long)sizeof( struct NewGadget ));
  84.         newgad.ng_VisualInfo = MainWindowVisualInfo;
  85.         newgad.ng_LeftEdge += offx;
  86.         newgad.ng_TopEdge += offy;
  87.         MainWindowGadgets[ loop ] = NULL;
  88.         MainWindowGadgets[ newgad.ng_GadgetID - MainWindowFirstID ] = Gad =
  89. CreateGadgetA( MainWindowGadgetTypes[loop], Gad, &newgad, newgad.ng_UserData
  90. );
  91.       }
  92.     }
  93.     for ( loop=0 ; loop<67 ; loop++ )
  94.     {
  95.       if (MainWindowGadgetTypes[loop] == 198)
  96.       {
  97.         MainWindowGadgets[ loop ] = NULL;
  98.         Cla = NULL;
  99.         if (Gad)
  100.           MainWindowGadgets[ loop ] = Gad2 = (struct Gadget *) NewObjectA(
  101. (struct IClass *)Cla, MainWindowNewGadgets[ loop ].ng_GadgetText,
  102. MainWindowNewGadgets[ loop ].ng_UserData );
  103.       }
  104.     }
  105.  
  106.     AddGList( MainWindow, MainWindowGadgets[0], 0, ~0, NULL );
  107.  
  108.     RefreshGList( MainWindowGList, MainWindow, NULL, ~0);
  109.     GT_RefreshWindow( MainWindow, NULL);
  110.  
  111.     SetSliderGadgets();
  112.   }
  113.   else
  114.   {
  115.     DoRTRequest( "Error Recreating Gadgets (Context)", "Okay", "Error from
  116. FileMan" );
  117.   }
  118.  
  119. }
  120.  
  121.  
  122. +--------------------------------------------------------------+
  123. | The Ephebians made wine out of anything they could put in a  |
  124. | bucket, and ate anything that couldn't climb out of one.     |
  125. |     -- (Terry Pratchett, Pyramids)                           |
  126. +-------------+----------------+-------------------------------+
  127. | Ben Clifton | bec1@ukc.ac.uk | Talk to me in #AmigaCafe      |
  128. +-------------+----------------+-------------------------------+
  129.  
  130. Join the TAGLINE CHAIN !!, adopt and add 1. This one is copy #5
  131.  
  132.