home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / sviluppo / easygui_os12 / source / easyplugins / icongad_os12.e < prev    next >
Encoding:
Text File  |  2000-06-11  |  4.3 KB  |  170 lines

  1. /*
  2. **
  3. ** $VER: IconGad PLUGIN V1.10 (08-Feb-98) - By Fabio Rotondo
  4. **
  5. ** Name         : IconGad PLUGIN
  6. **
  7. ** Copyright    :
  8. ** EMail        : fsoft@intercom.it
  9. ** WWW          : http://www.intercom.it/~fsoft
  10. **
  11. ** ProgID       : $01
  12. ** ProgrammerID : $03
  13. **
  14. ** Version      : 1.10
  15. ** Date         : 01-Feb-98
  16. **
  17. ** Notes        : Fixed AND enhanced by:  Jason Hulance (jason@fsel.com)
  18. **                Comments between /* */ are mine (Fabio)
  19. **                Comments satrting with -> are from Jason
  20. **
  21. **
  22. ** History      : 1.00  - Inital Release
  23. **
  24. **                1.10  - Now it is (I hope) EasyPLUGINs StyleGuide Compliant :-)
  25. **
  26. **                      - Added ICONGAD constant TO use instead of PLUGIN one in your
  27. **                        interfaces.
  28. **
  29. **                      - Added the disabled() method.
  30. */
  31.  
  32.  
  33. OPT MODULE
  34. OPT EXPORT
  35. OPT PREPROCESS
  36.  
  37. -> RST: Added conditional EASY_OS12 support
  38. #define EASY_OS12
  39.  
  40. #ifdef EASY_OS12
  41.   MODULE 'tools/easygui_os12'
  42. #endif
  43. #ifndef EASY_OS12
  44.   OPT OSVERSION=37
  45.   MODULE 'tools/easygui'
  46. #endif
  47.  
  48. MODULE  'workbench/workbench',
  49.         'exec/ports',
  50.         'icon',
  51.         'intuition/screens', 'intuition/intuition',
  52.         'gadtools', 'libraries/gadtools',
  53.         'tools/Exceptions'
  54.  
  55.  
  56. CONST ICONGAD_BASE = $83010000
  57.  
  58. CONST ICONGAD      = PLUGIN
  59.  
  60.  
  61. /*
  62.    This is our new plugin.
  63.    Note the PRIVATE keyword:
  64.    we don't want the user to access these fields.
  65. */
  66.  
  67. OBJECT icongad_plugin OF plugin
  68.   PRIVATE
  69.   dobj:PTR TO diskobject
  70. -> Have our own gadget (don't use dobj's gadget)
  71.   gad:PTR TO gadget
  72.   disabled
  73. ENDOBJECT
  74.  
  75. /*
  76.     This is the init proc for the plugin.
  77.     You must provide a valid icon name (full path)
  78.     without the ".info" extension (it is added automagically
  79.     by GetDiskObject() call)
  80. */
  81. PROC init(fname) OF icongad_plugin
  82.   IF (iconbase:=OpenLibrary('icon.library', 0))=NIL THEN Raise("ilib")
  83.   self.dobj := GetDiskObject(fname)
  84.   IF self.dobj = NIL THEN Raise("icon")
  85.  
  86. -> Copy the relevant parts of dobj to our gadget
  87. -> The *vital* part is the initialisation of the "activation" field to
  88. -> a known value (GACT_RELVERIFY).  That way, we know what IDCMP messages
  89. -> the gadget will generate.
  90.  
  91.   self.gad:=NEW [NIL, 0, 0, self.dobj.gadget.width, self.dobj.gadget.height,
  92.                  self.dobj.gadget.flags, GACT_RELVERIFY,
  93.                  self.dobj.gadget.gadgettype,
  94.                  self.dobj.gadget.gadgetrender,
  95.                  self.dobj.gadget.selectrender,
  96.                  NIL, 0, NIL, 0, NIL]:gadget
  97. ENDPROC
  98.  
  99. /*
  100.    We free all Alloc()ed resources.
  101.    Remeber to always END your PLUGINs before program termination.
  102. */
  103. PROC end() OF icongad_plugin
  104.   IF self.dobj THEN FreeDiskObject(self.dobj)
  105.   IF iconbase THEN CloseLibrary(iconbase)
  106.   END self.gad
  107. ENDPROC
  108.  
  109. /* The icon cannot be stretched, so it cannot be resized... */
  110. PROC will_resize() OF icongad_plugin IS FALSE
  111.  
  112.  
  113. /* We provide, as min size, the Icon size */
  114. PROC min_size(ta, fh) OF icongad_plugin IS self.gad.width, self.gad.height
  115.  
  116.  
  117. /* This is the render proc */
  118. PROC render(ta, x,y, xs, ys, win:PTR TO window) OF icongad_plugin
  119.   IF self.gh    = NIL THEN RETURN
  120.   IF win        = NIL THEN RETURN
  121.  
  122.   IF self.gad
  123.     self.gad.leftedge:=x
  124.     self.gad.topedge :=y
  125.     AddGadget(win, self.gad, NIL)
  126. -> The final argument to RefreshGList() ought to be 1, not 0
  127.     RefreshGList(self.gad, win, NIL, 1)
  128.  
  129.     self.change_status(win)
  130.   ENDIF
  131. ENDPROC
  132.  
  133. PROC change_status(win) OF icongad_plugin
  134.   IF self.disabled
  135.     OffGadget(self.gad, win, NIL)
  136.   ELSE
  137.     OnGadget(self.gad, win, NIL)
  138.   ENDIF
  139. ENDPROC
  140.  
  141.  
  142. /*
  143.     And here there is the clear proc
  144.     Since we have created a standard gadget, we simply
  145.     remove it from the gadget list of the window.
  146. */
  147. PROC clear_render(win:PTR TO window) OF icongad_plugin
  148.   IF self.gad THEN IF win THEN RemoveGadget(win, self.gad)
  149. ENDPROC
  150.  
  151. PROC message_test(imsg:PTR TO intuimessage, win:PTR TO window) OF icongad_plugin
  152. -> Because we set the gadget's activation field we know we'll only get
  153. -> IDCMP_GADGETUP generated by our gadget.
  154.   IF (imsg.class=IDCMP_GADGETUP) THEN RETURN imsg.iaddress=self.gad
  155. ENDPROC FALSE
  156.  
  157. PROC message_action(a,b,c,d) OF icongad_plugin IS TRUE
  158.  
  159. PROC disabled(dis=TRUE) OF icongad_plugin
  160.   IF dis<>self.disabled
  161.     self.disabled:=dis
  162.  
  163.     IF self.gh     = NIL THEN RETURN
  164.     IF self.gh.wnd = NIL THEN RETURN
  165.  
  166.     self.change_status(self.gh.wnd)
  167.   ENDIF
  168. ENDPROC
  169.  
  170.