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

  1. /* $Header: /home/neeri/MacCVS/MacPerl/perl/ext/Mac/Controls/Controls.xs,v 1.2 1997/11/18 00:52:12 neeri Exp $
  2.  *
  3.  *    Copyright (c) 1997 Matthias Neeracher
  4.  *
  5.  *    You may distribute under the terms of the Perl Artistic License,
  6.  *    as specified in the README file.
  7.  *
  8.  * $Log: Controls.xs,v $
  9.  * Revision 1.2  1997/11/18 00:52:12  neeri
  10.  * MacPerl 5.1.5
  11.  *
  12.  * Revision 1.1  1997/04/07 20:49:19  neeri
  13.  * Synchronized with MacPerl 5.1.4a1
  14.  *
  15.  */
  16.  
  17. #define MAC_CONTEXT
  18.  
  19. #include "EXTERN.h"
  20. #include "perl.h"
  21. #include "XSUB.h"
  22. #include <Types.h>
  23. #include <Controls.h>
  24. #include <CodeFragments.h>
  25.  
  26. static SV * sActionProc;
  27.  
  28. static pascal void ActionProc(ControlHandle cntl, short part)
  29. {
  30.     dSP ;
  31.  
  32.     PUSHMARK(sp) ;
  33.     XPUSHs(sv_setref_pv(sv_newmortal(), "ControlHandle", (void*)cntl));
  34.     XPUSHs(sv_2mortal(newSViv(part)));
  35.     PUTBACK ;
  36.  
  37.     perl_call_sv(sActionProc, G_DISCARD);
  38. }
  39.  
  40. static pascal void IndicatorActionProc()
  41. {
  42.     dSP ;
  43.  
  44.     PUSHMARK(sp) ;
  45.  
  46.     perl_call_sv(sActionProc, G_DISCARD|G_NOARGS);
  47. }
  48.  
  49. #if TARGET_RT_MAC_CFM
  50. static RoutineDescriptor    uActionProc = 
  51.         BUILD_ROUTINE_DESCRIPTOR(uppControlActionProcInfo, ActionProc);
  52. static RoutineDescriptor    uIndicatorActionProc = 
  53.         BUILD_ROUTINE_DESCRIPTOR(kPascalStackBased, IndicatorActionProc);
  54. #else
  55. #define uActionProc *(ControlActionUPP)&ActionProc
  56. #define uIndicatorActionProc *(ControlActionUPP)&IndicatorActionProc
  57. #endif
  58.  
  59. MODULE = Mac::Controls  PACKAGE = Mac::Controls
  60.  
  61. =head2 Structures
  62.  
  63. =over 4
  64.  
  65. =item ControlHandle
  66.  
  67. A Control structure. Fields are:
  68.  
  69.     ControlHandle       nextControl;
  70.     GrafPtr             contrlOwner;
  71.     Rect                contrlRect;
  72.     UInt8               contrlVis;
  73.     UInt8               contrlHilite;
  74.     SInt16              contrlValue;
  75.     SInt16              contrlMin;
  76.     SInt16              contrlMax;
  77.     SInt32              contrlRfCon;
  78.     Str255              contrlTitle;
  79.  
  80. =back
  81.  
  82. =cut
  83.  
  84. STRUCT ** ControlHandle
  85.     ControlHandle       nextControl;
  86.         READ_ONLY
  87.     GrafPtr             contrlOwner;
  88.         READ_ONLY
  89.     Rect                contrlRect;
  90.         READ_ONLY
  91.     U8                  contrlVis;
  92.         READ_ONLY
  93.     U8                  contrlHilite;
  94.         READ_ONLY
  95.     short               contrlValue;
  96.         READ_ONLY
  97.     short               contrlMin;
  98.         READ_ONLY
  99.     short               contrlMax;
  100.         READ_ONLY
  101.     long                contrlRfCon;
  102.     Str255              contrlTitle;
  103.         READ_ONLY
  104.  
  105. =head2 Functions
  106.  
  107. =over 4
  108.  
  109. =item NewControl THEWINDOW, BOUNDSRECT, TITLE, VISIBLE, VALUE, MIN, MAX, PROC [, REFCON ]
  110.  
  111. Create a new control and return it..
  112.  
  113. =cut
  114. ControlHandle
  115. NewControl(theWindow, boundsRect, title, visible, value, min, max, proc, refCon=0)
  116.     GrafPtr theWindow
  117.     Rect    &boundsRect
  118.     Str255  title
  119.     Boolean visible
  120.     short   value
  121.     short   min
  122.     short   max
  123.     short   proc
  124.     long    refCon
  125.  
  126. =item GetNewControl CONTROLID, OWNER 
  127.  
  128. Create a new control from resource description.
  129.  
  130. =cut
  131. ControlHandle
  132. GetNewControl(controlID, owner)
  133.     short   controlID
  134.     GrafPtr owner
  135.  
  136. =item DisposeControl CONTROL
  137.  
  138. Destroy a control.
  139.  
  140. =cut
  141. void
  142. DisposeControl(theControl)
  143.     ControlHandle   theControl
  144.  
  145. =item KillControls WINDOW
  146.  
  147. Destroy all controls in a window.
  148.  
  149. =cut
  150. void
  151. KillControls(theWindow)
  152.     GrafPtr theWindow
  153.  
  154. =item ShowControl CONTROL
  155.  
  156. Make a control visible.
  157.  
  158. =cut
  159. void
  160. ShowControl(theControl)
  161.     ControlHandle   theControl
  162.  
  163. =item HideControl CONTROL
  164.  
  165. Make a control invisible.
  166.  
  167. =cut
  168. void
  169. HideControl(theControl)
  170.     ControlHandle   theControl
  171.  
  172. =item DrawControls WINDOW
  173.  
  174. Draw all controls in the window.
  175.  
  176. =cut
  177. void
  178. DrawControls(theWindow)
  179.     GrafPtr theWindow
  180.  
  181. =item Draw1Control CONTROL
  182.  
  183. Draw a single control.
  184.  
  185. =cut
  186. void
  187. Draw1Control(theControl)
  188.     ControlHandle   theControl
  189.  
  190. =item UpdateControls WINDOW [, UPDATEREGION]
  191.  
  192. Update the controls intersecting with the given region.
  193.  
  194. =cut
  195. void
  196. UpdateControls(theWindow, updateRegion=theWindow->visRgn)
  197.     GrafPtr theWindow
  198.     RgnHandle   updateRegion
  199.  
  200. =item HiliteControl CONTROL, HILITE
  201.  
  202. Hilite a control.
  203.  
  204. =cut
  205. void
  206. HiliteControl(theControl, hiliteState)
  207.     ControlHandle   theControl
  208.     short           hiliteState
  209.  
  210. =item TrackControl CONTROL, PT [, ACTIONPROC]
  211.  
  212. Track a mouse click on a control.
  213.  
  214. =cut
  215. short
  216. TrackControl(theControl, pt, actionProc=nil)
  217.     ControlHandle   theControl
  218.     Point           pt
  219.     SV *            actionProc
  220.     CODE:
  221.     {
  222.         ControlActionUPP    upp;
  223.         short               part;
  224.         
  225.         if (!actionProc)
  226.             upp = nil;
  227.         else if (SvNIOK(actionProc) || looks_like_number(actionProc)) {
  228.             upp = (ControlActionUPP) SvIV(actionProc);
  229.             if (upp && upp != (ControlActionUPP)-1)
  230.                 croak("Mac::Controls::TrackControl: Last argument must be procedure, 0, or -1");
  231.         } else {
  232.             sActionProc = actionProc;
  233.             /* Heuristic here */
  234.             part = TestControl(theControl, pt);
  235.             if (part > 127 || part < 250)
  236.                 upp = &uIndicatorActionProc;
  237.             else
  238.                 upp = &uActionProc;
  239.         }
  240.         RETVAL = TrackControl(theControl, pt, upp); 
  241.     }
  242.     OUTPUT:
  243.     RETVAL
  244.  
  245. =item DragControl CONTROL, PT, LIMITRECT, SLOPRECT, AXIS
  246.  
  247. Drag a control to a new position.
  248.  
  249. =cut
  250. void
  251. DragControl(theControl, pt, limitRect, slopRect, axis)
  252.     ControlHandle   theControl
  253.     Point           pt
  254.     Rect           &limitRect
  255.     Rect           &slopRect
  256.     short           axis
  257.  
  258. =item PART = TestControl CONTROL, PT
  259.  
  260. Test which part of a control, if any, has been hit.
  261.  
  262. =cut
  263. short
  264. TestControl(theControl, pt)
  265.     ControlHandle   theControl
  266.     Point           pt
  267.  
  268. =item FindControl PT, WINDOW
  269.  
  270. Find which control in a window, if any, has been hit and where.
  271.  
  272.     ($part,$ctrl) = FindWindow($pt, $win);
  273.  
  274. =cut
  275. void
  276. FindControl(pt, theWindow)
  277.     Point   pt
  278.     GrafPtr theWindow
  279.     PPCODE:
  280.     {
  281.         ControlHandle   cntl;
  282.         short           part;
  283.         
  284.         if (part = FindControl(pt, theWindow, &cntl)) {
  285.             EXTEND(sp, 2);
  286.             PUSHs(sv_2mortal(newSViv(part)));
  287.             PUSHs(sv_setref_pv(sv_newmortal(), "ControlHandle", (void*)cntl));
  288.         } else {
  289.             XSRETURN_EMPTY;
  290.         }
  291.     }
  292.  
  293. =item MoveControl CONTROL, H, V
  294.  
  295. Move a control to a new position.
  296.  
  297. =cut
  298. void
  299. MoveControl(theControl, h, v)
  300.     ControlHandle   theControl
  301.     short   h
  302.     short   v
  303.  
  304. =item SizeControl CONTROL, W, H
  305.  
  306. Resize a control.
  307.  
  308. =cut
  309. void
  310. SizeControl(theControl, w, h)
  311.     ControlHandle   theControl
  312.     short   w
  313.     short   h
  314.  
  315. =item SetControlTitle CONTROL, TITLE
  316.  
  317. Change the title of a control.
  318.  
  319. =cut
  320. void
  321. SetControlTitle(theControl, title)
  322.     ControlHandle   theControl
  323.     Str255  title
  324.  
  325. =item GetControlTitle THECONTROL 
  326.  
  327. Returns the title of a control.
  328.  
  329. =cut
  330. Str255
  331. GetControlTitle(theControl)
  332.     ControlHandle   theControl
  333.     CODE:
  334.     GetControlTitle(theControl, RETVAL);
  335.     OUTPUT:
  336.     RETVAL
  337.  
  338. =item GetControlValue CONTROL
  339.  
  340. Returns the value of a control.
  341.  
  342. =cut
  343. short
  344. GetControlValue(theControl)
  345.     ControlHandle   theControl
  346.  
  347. =item SetControlValue CONTROL, VAL
  348.  
  349. Set the value of a control.
  350.  
  351. =cut
  352. void
  353. SetControlValue(theControl, newValue)
  354.     ControlHandle   theControl
  355.     short   newValue
  356.  
  357. =item GetControlMinimum CONTROL 
  358.  
  359. Get the minimum value of a control.
  360.  
  361. =cut
  362. short
  363. GetControlMinimum(theControl)
  364.     ControlHandle   theControl
  365.  
  366. =item SetControlMinimum CONTROL, MIN
  367.  
  368. Set the minimum value of a control.
  369.  
  370. =cut
  371. void
  372. SetControlMinimum(theControl, newMinimum)
  373.     ControlHandle   theControl
  374.     short   newMinimum
  375.  
  376. =item GetControlMaximum CONTROL
  377.  
  378. Get the maximum value of a control.
  379.  
  380. =cut
  381. short
  382. GetControlMaximum(theControl)
  383.     ControlHandle   theControl
  384.  
  385. =item SetControlMaximum CONTROL, MAX
  386.  
  387. Set the maximum value of a control.
  388.  
  389. =cut
  390. void
  391. SetControlMaximum(theControl, newMaximum)
  392.     ControlHandle   theControl
  393.     short   newMaximum
  394.  
  395. =item GetControlVariant CONTROL
  396.  
  397. Get the control variant of a control.
  398.  
  399. =cut
  400. short
  401. GetControlVariant(theControl)
  402.     ControlHandle   theControl
  403.  
  404. =item SetControlReference CONTROL, REF
  405.  
  406. Set the reference value of a control.
  407.  
  408. =cut
  409. void
  410. SetControlReference(theControl, data)
  411.     ControlHandle   theControl
  412.     long    data
  413.  
  414. =item GetControlReference CONTROL
  415.  
  416. Get the reference value of a control.
  417.  
  418. =cut
  419. long
  420. GetControlReference(theControl)
  421.     ControlHandle   theControl
  422.  
  423.