home *** CD-ROM | disk | FTP | other *** search
/ CLIX - Fazer Clix Custa Nix / CLIX-CD.cdr / mac / lib / Mac / Lists.xs < prev    next >
Text File  |  1998-04-05  |  9KB  |  484 lines

  1. /* $Header: /home/neeri/MacCVS/MacPerl/perl/ext/Mac/ExtUtils/MakeToolboxModule,v 1.1 1997/04/07 20:49:35 neeri Exp 
  2.  *    Copyright (c) 1997 Matthias Neeracher
  3.  *
  4.  *    You may distribute under the terms of the Perl Artistic License,
  5.  *    as specified in the README file.
  6.  *
  7.  * $Log: MakeToolboxModule,v  Revision 1.1  1997/04/07 20:49:35  neeri
  8.  * Synchronized with MacPerl 5.1.4a1
  9.  * 
  10.  */
  11.  
  12. #define MAC_CONTEXT
  13.  
  14. #include "EXTERN.h"
  15. #include "perl.h"
  16. #include "XSUB.h"
  17. #include <Types.h>
  18. #include <Lists.h>
  19. #include <OSUtils.h>
  20.  
  21. static pascal void
  22. CallLDEF(
  23.         short message, Boolean selected, const Rect * r, Point cell,
  24.         short dataoffset, short datalen, ListHandle lHandle)
  25. {
  26.     SV *    ldef;
  27.     Handle  cells;
  28.     
  29.     dSP;
  30.     
  31.     ldef = (SV *) lHandle[0]->userHandle;
  32.     
  33.     PUSHMARK(sp);
  34.     XS_XPUSH(short, message);
  35.     XS_XPUSH(Boolean, selected);
  36.     XS_XPUSH(Rect, *r);
  37.     XS_XPUSH(Point, cell);
  38.     HLock(cells = lHandle[0]->cells);
  39.     XPUSHs(sv_2mortal(newSVpv(datalen ? *cells+dataoffset : "", datalen)));
  40.     HUnlock(cells);
  41.     XS_XPUSH(ListHandle, lHandle);
  42.     PUTBACK;
  43.     
  44.     perl_call_sv(ldef, G_DISCARD);
  45. }
  46.  
  47. #if GENERATINGCFM
  48. RoutineDescriptor sCallLDEF = 
  49.     BUILD_ROUTINE_DESCRIPTOR(uppListDefProcInfo, CallLDEF);
  50. #else
  51. struct {
  52.     short   jmp;
  53.     void *  addr;
  54. } sCallLDEF = {0x4EF9, CallLDEF};
  55. #endif
  56. static Handle   sLDEF;
  57. static int      sLDEFRefCount;
  58.  
  59. MODULE = Mac::Lists PACKAGE = Mac::Lists
  60.  
  61. =head2 Functions
  62.  
  63. =over 4
  64.  
  65. =cut
  66.  
  67. STRUCT ** ListHandle
  68.     Rect            rView;
  69.     Rect            bounds;
  70.         READ_ONLY;
  71.         OUTPUT:
  72.         {
  73.             Rect bounds = STRUCT[0]->rView;
  74.             if (STRUCT[0]->vScroll)
  75.                 bounds.right += 15;
  76.             if (STRUCT[0]->hScroll)
  77.                 bounds.bottom += 15;
  78.             XS_OUTPUT(Rect, bounds, $arg);
  79.         }
  80.     GrafPtr         port;
  81.     Point           indent;
  82.     Point           cellSize;
  83.     Rect            visible;
  84.     ControlHandle   vScroll;
  85.     ControlHandle   hScroll;
  86.     I8              selFlags;
  87.     Boolean         lActive;
  88.     I8              lReserved;
  89.     I8              listFlags;
  90.     long            clikTime;
  91.     Point           clikLoc;
  92.     Point           mouseLoc;
  93.     Point           lastClick;
  94.     long            refCon;
  95.     SV *            listDefProc;
  96.         INPUT:
  97.         if (STRUCT[0]->listDefProc == sLDEF) 
  98.             SvREFCNT_dec((SV *)STRUCT[0]->userHandle);
  99.         else
  100.             STRUCT[0]->listDefProc = sLDEF;
  101.         STRUCT[0]->userHandle = (Handle)newSVsv($arg);
  102.         OUTPUT:
  103.         if (STRUCT[0]->listDefProc == sLDEF) 
  104.             XS_OUTPUT(SV *, (SV *)STRUCT[0]->userHandle, $arg);
  105.         else
  106.             XS_OUTPUT(SV *, &sv_undef, $arg);
  107.     Rect            dataBounds;
  108.     Handle          cells;
  109.     short           maxIndex;
  110.  
  111. =item LIST = LNew rView, dataBounds, cSize, theProc, theWindow [, drawIt [, hasGrow [, scrollHoriz [, scrollVert]]]]
  112.  
  113. Creates a list.
  114.  
  115. =cut
  116.  
  117. ListHandle
  118. LNew(rView, dataBounds, cSize, theProc, theWindow, drawIt=true, hasGrow=false, scrollHoriz=false, scrollVert=true)
  119.     Rect    &rView
  120.     Rect    &dataBounds
  121.     Point   cSize
  122.     SV *    theProc
  123.     GrafPtr theWindow
  124.     Boolean drawIt
  125.     Boolean hasGrow
  126.     Boolean scrollHoriz
  127.     Boolean scrollVert
  128.     CODE:
  129.     {
  130.         short   proc = 0;
  131.         if (!SvROK(theProc) && looks_like_number(theProc))
  132.             proc = SvIV(theProc);
  133.         RETVAL = LNew(
  134.             &rView, &dataBounds, cSize, proc, theWindow, drawIt, 
  135.             hasGrow, scrollHoriz, scrollVert);
  136.         if (!proc && SvTRUE(theProc)) {
  137.             if (!sLDEFRefCount++) {
  138.                 PtrToHand((Ptr)&sCallLDEF, &sLDEF, sizeof(sCallLDEF));
  139. #if !GENERATINGCFM
  140.                 FlushInstructionCache();
  141.                 FlushDataCache();
  142. #endif
  143.             }
  144.             RETVAL[0]->listDefProc  = sLDEF;
  145.             RETVAL[0]->userHandle   = (Handle) newSVsv(theProc);
  146.             CallLDEF(lInitMsg, false, &rView, cSize, 0, 0, RETVAL);
  147.         }
  148.     }
  149.     OUTPUT:
  150.     RETVAL
  151.  
  152. =item LDispose LIST
  153.  
  154. Deletes a list.
  155.  
  156. =cut
  157.  
  158. void
  159. LDispose(lHandle)
  160.     ListHandle  lHandle
  161.     CODE:
  162.     if (lHandle[0]->listDefProc == sLDEF) {
  163.         SV * proc = (SV *)lHandle[0]->userHandle;
  164.         LDispose(lHandle);
  165.         if (!--sLDEFRefCount)
  166.             DisposeHandle(sLDEF);
  167.         SvREFCNT_dec(proc);
  168.     } else {
  169.         LDispose(lHandle);
  170.     }
  171.  
  172. =item LAddColumn count, colNum, list
  173.  
  174. Adds a number of columns to the list.
  175.  
  176. =cut
  177.  
  178. short
  179. LAddColumn(count, colNum, lHandle)
  180.     short   count
  181.     short   colNum
  182.     ListHandle  lHandle
  183.  
  184. =item LAddRow count, rowNum, list
  185.  
  186. Adds a number of rows to the list.
  187.  
  188. =cut
  189.  
  190. short
  191. LAddRow(count, rowNum, lHandle)
  192.     short   count
  193.     short   rowNum
  194.     ListHandle  lHandle
  195.  
  196. =item LDelColumn count, colNum, list
  197.  
  198. Delete a number of columns from the list.
  199.  
  200. =cut
  201.  
  202. void
  203. LDelColumn(count, colNum, lHandle)
  204.     short   count
  205.     short   colNum
  206.     ListHandle  lHandle
  207.  
  208. =item LDelRow count, colNum, list
  209.  
  210. Delete a number of rows from the list.
  211.  
  212. =cut
  213.  
  214. void
  215. LDelRow(count, rowNum, lHandle)
  216.     short   count
  217.     short   rowNum
  218.     ListHandle  lHandle
  219.  
  220.  
  221. =item CELL = LGetSelect NEXT, STARTCELL, LIST
  222.  
  223. If C<NEXT> is false, returns STARTCELL if it is selected, else undef. If
  224. C<NEXT> is true, returns next selected cell if one exists, else undef.
  225.  
  226. =cut
  227. Point
  228. LGetSelect(next, theCell, lHandle)
  229.     Boolean next
  230.     Point &theCell
  231.     ListHandle  lHandle
  232.     CODE:
  233.     if (!LGetSelect(next, &theCell, lHandle)) {
  234.         XSRETURN_UNDEF;
  235.     }
  236.     RETVAL = theCell;
  237.     OUTPUT:
  238.     RETVAL
  239.  
  240. =item CELL = LLastClick LIST
  241.  
  242. Returns last cell clicked.
  243.  
  244. =cut
  245.  
  246. Point
  247. LLastClick(lHandle)
  248.     ListHandle  lHandle
  249.  
  250. =item CELL = LNextCell HNEXT, VNEXT, CELL, LIST
  251.  
  252. Returns next cell in indiacted direction or false.
  253.  
  254. =cut
  255.  
  256. Point
  257. LNextCell(hNext, vNext, theCell, lHandle)
  258.     Boolean hNext
  259.     Boolean vNext
  260.     Point &theCell
  261.     ListHandle  lHandle
  262.     CODE:
  263.     if (!LNextCell(hNext, vNext, &theCell, lHandle)) {
  264.         XSRETURN_UNDEF;
  265.     }
  266.     RETVAL = theCell;
  267.     OUTPUT:
  268.     RETVAL
  269.  
  270. =begin ignore
  271.  
  272. Boolean
  273. LSearch(dataPtr, dataLen, searchProc, theCell, lHandle)
  274.     const void *    dataPtr
  275.     short   dataLen
  276.     ListSearchUPP   searchProc
  277.     Point * theCell
  278.     ListHandle  lHandle
  279.  
  280. =end ignore
  281.  
  282. =cut
  283.  
  284. =item LSize WIDTH, HEIGHT, LIST
  285.  
  286. Set the size of the list's visible rectangle.
  287.  
  288. =cut
  289.  
  290. void
  291. LSize(listWidth, listHeight, lHandle)
  292.     short   listWidth
  293.     short   listHeight
  294.     ListHandle  lHandle
  295.  
  296. =item LSetDrawingMode DRAWIT, LIST
  297.  
  298. Set flag to draw or not draw changes to the list.
  299.  
  300. =cut
  301.  
  302. void
  303. LSetDrawingMode(drawIt, lHandle)
  304.     Boolean drawIt
  305.     ListHandle  lHandle
  306.  
  307. =item LScroll COLS, ROWS, LIST
  308.  
  309. Scroll the list.
  310.  
  311. =cut
  312.  
  313. void
  314. LScroll(dCols, dRows, lHandle)
  315.     short   dCols
  316.     short   dRows
  317.     ListHandle  lHandle
  318.  
  319. =item LAutoScroll LIST
  320.  
  321. Scroll selection into view.
  322.  
  323. =cut
  324.  
  325. void
  326. LAutoScroll(lHandle)
  327.     ListHandle  lHandle
  328.  
  329. =item LUpdate REGION, LIST
  330.  
  331. Update list.
  332.  
  333. =cut
  334.  
  335. void
  336. LUpdate(theRgn, lHandle)
  337.     RgnHandle   theRgn
  338.     ListHandle  lHandle
  339.  
  340. =item LActivate ACTIVE, LIST
  341.  
  342. Activate list.
  343.  
  344. =cut
  345.  
  346. void
  347. LActivate(act, lHandle)
  348.     Boolean act
  349.     ListHandle  lHandle
  350.  
  351. =item LCellSize SIZE, LIST
  352.  
  353. Set the list cell size.
  354.  
  355. =cut
  356. void
  357. LCellSize(cSize, lHandle)
  358.     Point   cSize
  359.     ListHandle  lHandle
  360.  
  361. =item DOUBLE = LClick PT, MODIFIERS, LIST
  362.  
  363. Handle a click in the list.
  364.  
  365. =cut
  366.  
  367. Boolean
  368. LClick(pt, modifiers, lHandle)
  369.     Point   pt
  370.     short   modifiers
  371.     ListHandle  lHandle
  372.  
  373. =item LAddToCell DATA, CELL, LIST
  374.  
  375. Add data to a cell.
  376.  
  377. =cut
  378.  
  379. void
  380. LAddToCell(data, theCell, lHandle)
  381.     SV *        data
  382.     Point       theCell
  383.     ListHandle  lHandle
  384.     CODE:
  385.     {
  386.         STRLEN  len;
  387.         char *  ptr = SvPV(data, len);
  388.         
  389.         LAddToCell(ptr, (short) len, theCell, lHandle);
  390.     }
  391.  
  392. =item LClrCell CELL, LIST
  393.  
  394. Delete data for a cell.
  395.  
  396. =cut
  397.  
  398. void
  399. LClrCell(theCell, lHandle)
  400.     Point   theCell
  401.     ListHandle  lHandle
  402.  
  403. =item DATA = LGetCell CELL, LIST
  404.  
  405. Get the data for a cell.
  406.  
  407. =cut
  408.  
  409. SV *
  410. LGetCell(theCell, lHandle)
  411.     Point       theCell
  412.     ListHandle  lHandle
  413.     CODE:
  414.     {
  415.         short   offset;
  416.         short   len;
  417.         Handle  cells;
  418.         
  419.         LGetCellDataLocation(&offset, &len, theCell, lHandle);
  420.         HLock(cells = lHandle[0]->cells);
  421.         RETVAL = len ? newSVpv(*cells+offset, len) : newSVpv("", 0);
  422.         HUnlock(cells);
  423.     }
  424.     OUTPUT:
  425.     RETVAL
  426.  
  427. =item RECT = LRect CELL, LIST
  428.  
  429. Get the rectangle of a cell.
  430.  
  431. =cut
  432. Rect
  433. LRect(theCell, lHandle)
  434.     Point   theCell
  435.     ListHandle  lHandle
  436.     CODE:
  437.     LRect(&RETVAL, theCell, lHandle);
  438.     OUTPUT:
  439.     RETVAL
  440.  
  441. =item LSetCell DATA, CELL, LIST
  442.  
  443. Set data for a cell.
  444.  
  445. =cut
  446. void
  447. LSetCell(data, theCell, lHandle)
  448.     SV *        data
  449.     Point       theCell
  450.     ListHandle  lHandle
  451.     CODE:
  452.     {
  453.         STRLEN  len;
  454.         char *  ptr = SvPV(data, len);
  455.         
  456.         LSetCell(ptr, (short) len, theCell, lHandle);
  457.     }
  458.  
  459. =item LSetSelect SETIT, CELL, LIST
  460.  
  461. Set selection status of a cell.
  462.  
  463. =cut
  464.  
  465. void
  466. LSetSelect(setIt, theCell, lHandle)
  467.     Boolean setIt
  468.     Point   theCell
  469.     ListHandle  lHandle
  470.  
  471. =item LDraw CELL, LIST
  472.  
  473. Draw a cell.
  474.  
  475. =cut
  476. void
  477. LDraw(theCell, lHandle)
  478.     Point   theCell
  479.     ListHandle  lHandle
  480.  
  481. =back
  482.  
  483. =cut
  484.