home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / ResEdit / ResEdit 1.2 / Examples / CExamples / Source / ICONLDEF.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-04  |  2.0 KB  |  74 lines  |  [TEXT/MPS ]

  1. /*
  2.  COPYRIGHT (C) 1984,1985,1986,1988,1989 Apple Computer,Inc.
  3.  All rights reserved
  4. */
  5.  
  6. #include    <types.h>
  7. #include    <memory.h>
  8. #include    <menus.h>
  9. #include    <resources.h>
  10. #include    <lists.h>
  11. #include    <ToolUtils.h>
  12.  
  13. #include    "ResEd.h"
  14.  
  15. #define IconSize 128
  16. #define cellInset 8
  17.  
  18. /* This routine simply looks up in the list at the given cell, extracts the ID and
  19.     gets the resource called for.  Returns NIL if not found.  Note, this assumes
  20.     the resfile is set up correctly */
  21. Handle IconFetch (Cell lCell, ListHandle lHandle)
  22. {
  23.     short        id;
  24.     short     len = 2;
  25.     Handle    tempH;
  26.         
  27.     LGetCell((Ptr)&id, &len, lCell, lHandle);            /* Get the ID from the list.    */
  28.     if (len == 2) {                                                                /* ID must be 2 bytes.                */
  29.         /* Load the resource since we want to draw it.                                                         */
  30.         tempH = Get1Res((ResType)'ICON', id );
  31.         
  32.         if (SizeResource(tempH) >= IconSize)
  33.             return tempH;
  34.         }
  35.     return NULL;
  36. }
  37.  
  38. /* This is the custom drawProc for the list (which contains the resource ID's).  It
  39.     simply draws the icon in the given rect and frames a selection rect around it (if
  40.     necessary). */
  41. pascal void  DrawCell(short message, Boolean lSelect, Rect *lRect, Point lCell,
  42.                            short lDataOffset, short lDataLen, ListHandle lHandle)
  43. {
  44.     Handle tempH;
  45.     
  46.     #pragma    unused (lDataOffset, lDataLen)    /* Not needed here.                                */
  47.  
  48.     if (message == lInitMsg) {
  49.             (*lHandle)->indent.h = 8;
  50.             (*lHandle)->indent.v = 8;
  51.             }
  52.  
  53.     if ((message == lDrawMsg) || (message == lHiliteMsg)) {
  54.         /* Always use the right sized rectangle. */
  55.         lRect->bottom = lRect->top + (*lHandle)->cellSize.v;
  56.         lRect->right = lRect->left + (*lHandle)->cellSize.h;
  57.         
  58.         tempH = IconFetch(lCell, lHandle);
  59.         EraseRect(lRect);
  60.         InsetRect(lRect, (*lHandle)->indent.h, (*lHandle)->indent.v);
  61.         
  62.         if (lSelect == true) {
  63.             FrameRect(lRect);                                /* Select the icon by framing it. */
  64.             }
  65.             
  66.         if (tempH != NULL) {
  67.             if (*tempH != NULL) {
  68.                 InsetRect(lRect, (*lHandle)->indent.h, (*lHandle)->indent.v);
  69.                 PlotIcon(lRect, tempH);
  70.                 }
  71.             }
  72.         }
  73. }
  74.