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

  1. /* $Header: /home/neeri/MacCVS/MacPerl/perl/ext/Mac/Dialogs/Dialogs.xs,v 1.4 1998/04/07 01:02:47 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: Dialogs.xs,v $
  9.  * Revision 1.4  1998/04/07 01:02:47  neeri
  10.  * MacPerl 5.2.0r4b1
  11.  *
  12.  * Revision 1.3  1997/11/18 00:52:14  neeri
  13.  * MacPerl 5.1.5
  14.  *
  15.  * Revision 1.2  1997/06/04 22:55:44  neeri
  16.  * Compiles fine.
  17.  *
  18.  * Revision 1.1  1997/04/07 20:49:23  neeri
  19.  * Synchronized with MacPerl 5.1.4a1
  20.  *
  21.  */
  22.  
  23. #define MAC_CONTEXT
  24.  
  25. #include "EXTERN.h"
  26. #include "perl.h"
  27. #include "XSUB.h"
  28. #include <Types.h>
  29. #include <Dialogs.h>
  30.  
  31. typedef EventRecord *   ToolboxEvent;
  32.  
  33. static SV *     sModalFilter;
  34.  
  35. static pascal Boolean ModalFilter(DialogPtr theDialog, EventRecord *theEvent, short *itemHit)
  36. {
  37.     dSP ;
  38.  
  39.     ENTER ;
  40.     SAVETMPS;
  41.  
  42.     PUSHMARK(sp) ;
  43.     XPUSHs(sv_mortalcopy(sModalFilter));
  44.     XPUSHs(sv_setref_pv(sv_newmortal(), "GrafPtr", (void*)theDialog));
  45.     XPUSHs(sv_setref_pv(sv_newmortal(), "ToolboxEvent", (void*)theEvent));
  46.     PUTBACK ;
  47.  
  48.     perl_call_pv("Mac::Dialogs::_ModalFilter", G_SCALAR);
  49.  
  50.     SPAGAIN ;
  51.  
  52.     *itemHit = (short)POPi;
  53.  
  54.     PUTBACK ;
  55.     FREETMPS ;
  56.     LEAVE ;
  57.     
  58.     return *itemHit != 0;
  59. }
  60.  
  61. static pascal Boolean DefaultModalFilter(DialogPtr theDialog, EventRecord *theEvent, short *itemHit)
  62. {
  63.     dSP ;
  64.  
  65.     ENTER ;
  66.     SAVETMPS;
  67.  
  68.     PUSHMARK(sp) ;
  69.     XPUSHs(sv_2mortal(newSVpv("Mac::Dialogs::_DefaultModalFilter", 0)));
  70.     XPUSHs(sv_setref_pv(sv_newmortal(), "GrafPtr", (void*)theDialog));
  71.     XPUSHs(sv_setref_pv(sv_newmortal(), "ToolboxEvent", (void*)theEvent));
  72.     PUTBACK ;
  73.  
  74.     perl_call_pv("Mac::Dialogs::_ModalFilter", G_SCALAR);
  75.  
  76.     SPAGAIN ;
  77.  
  78.     *itemHit = (short)POPi;
  79.  
  80.     PUTBACK ;
  81.     FREETMPS ;
  82.     LEAVE ;
  83.     
  84.     return *itemHit != 0;
  85. }
  86.  
  87. static pascal void ItemProc(DialogPtr theDialog, short item)
  88. {
  89.     dSP ;
  90.  
  91.     PUSHMARK(sp) ;
  92.     XPUSHs(sv_setref_pv(sv_newmortal(), "GrafPtr", (void*)theDialog));
  93.     XPUSHs(sv_2mortal(newSViv(item)));
  94.     PUTBACK ;
  95.  
  96.     perl_call_pv("Mac::Dialogs::_UserItem", G_DISCARD);
  97. }
  98.  
  99. #if TARGET_RT_MAC_CFM
  100. static RoutineDescriptor    uModalFilter = 
  101.         BUILD_ROUTINE_DESCRIPTOR(uppModalFilterProcInfo, ModalFilter);
  102. static RoutineDescriptor    uDefaultModalFilter = 
  103.         BUILD_ROUTINE_DESCRIPTOR(uppModalFilterProcInfo, DefaultModalFilter);
  104. static RoutineDescriptor    uItemProc = 
  105.         BUILD_ROUTINE_DESCRIPTOR(uppUserItemProcInfo, ItemProc);
  106. #else
  107. #define uModalFilter *(ModalFilterUPP)&ModalFilter
  108. #define uDefaultModalFilter *(ModalFilterUPP)&DefaultModalFilter
  109. #define uItemProc *(UserItemUPP)&ItemProc
  110. #endif
  111.  
  112. MODULE = Mac::Dialogs   PACKAGE = Mac::Dialogs
  113.  
  114. =head2 Structures
  115.  
  116. =over 4
  117.  
  118. =item GrafPtr
  119.  
  120. A dialog window has the following additional fields over an ordinary window, all
  121. of them read only:
  122.  
  123. =over 4
  124.  
  125. =item items
  126.  
  127. The dialog item list.
  128.  
  129. =item textH
  130.  
  131. A C<TextEdit> record for the active edit field.
  132.  
  133. =item editField
  134.  
  135. The currently active edit field - 1.
  136.  
  137. =item aDefItem
  138.  
  139. Default item number.
  140.  
  141. =back
  142.  
  143. =back
  144.  
  145. =cut
  146. STRUCT * GrafPtr
  147.     DialogPeek      STRUCT;
  148.         INPUT:
  149.         XS_INPUT(GrafPtr, *(GrafPtr *)&STRUCT, ST(0));
  150.         OUTPUT:
  151.         XS_PUSH(GrafPtr, STRUCT);
  152.     Handle          items;
  153.     TEHandle        textH;
  154.     short           editField;
  155.     short           aDefItem;
  156.  
  157. =head2 Functions
  158.  
  159. =over 4
  160.  
  161. =item _NewDialog BOUNDS, TITLE, VISIBLE, PROC, GOAWAY, ITEMS [, REFCON [, BEHIND]]
  162.  
  163. Create a new dialog and return it.
  164.  
  165. =cut
  166. GrafPtr
  167. _NewDialog(boundsRect, title, visible, theProc, goAwayFlag, ditems, refCon=0, behind=(GrafPtr)-1)
  168.     Rect       &boundsRect
  169.     Str255      title
  170.     Boolean     visible
  171.     short       theProc
  172.     Boolean     goAwayFlag
  173.     Handle      ditems
  174.     long        refCon
  175.     GrafPtr     behind
  176.     CODE:
  177.     RETVAL = 
  178.         NewDialog(
  179.             nil, &boundsRect, title, visible, theProc, behind, goAwayFlag, refCon, ditems);
  180.     OUTPUT:
  181.     RETVAL
  182.  
  183. =item PORT = GetNewDialog ID [, BEHIND]
  184.  
  185. Create a new dialog from a resource.
  186.  
  187. =cut
  188. GrafPtr
  189. GetNewDialog(dialogID, behind=(GrafPtr)-1)
  190.     short   dialogID
  191.     GrafPtr behind
  192.     CODE:
  193.     RETVAL = GetNewDialog(dialogID, nil, behind);
  194.     OUTPUT:
  195.     RETVAL
  196.  
  197. void
  198. _DisposeDialog(theDialog)
  199.     GrafPtr theDialog
  200.     CODE:
  201.     DisposeDialog(theDialog);
  202.  
  203. =item ParamText PARAM0, PARAM1, PARAM2, PARAM3 
  204.  
  205. Set text values for ^0 ^1 ^2 ^3.
  206.  
  207. =cut
  208. void
  209. ParamText(param0, param1, param2, param3)
  210.     Str255  param0
  211.     Str255  param1
  212.     Str255  param2
  213.     Str255  param3
  214.  
  215. =item ITEM = ModalDialog [ FILTERPROC ]
  216.  
  217. Run a modal dialog until an item is hit.
  218.  
  219. =cut
  220. short
  221. ModalDialog(modalFilter=0)
  222.     SV *    modalFilter
  223.     CODE:
  224.     {
  225.         Boolean saveInModalDialog = gInModalDialog;
  226.         gInModalDialog  = true;
  227.         if (modalFilter) {
  228.             SV * saveModalFilter = sModalFilter;
  229.             sModalFilter = modalFilter;
  230.             ModalDialog(&uModalFilter, &RETVAL);
  231.             sModalFilter = saveModalFilter;
  232.         } else
  233.             ModalDialog(&uDefaultModalFilter, &RETVAL);
  234.         gInModalDialog  = saveInModalDialog;
  235.     }
  236.     OUTPUT:
  237.     RETVAL
  238.  
  239. =item IsDialogEvent EVENT
  240.  
  241. Check if an event belongs to a dialog.
  242.  
  243. =cut
  244. Boolean
  245. IsDialogEvent(theEvent)
  246.     ToolboxEvent    theEvent
  247.  
  248. =item DialogSelect EVENT
  249.  
  250. Returns the dialog and item that were affected by an event, if any.
  251.  
  252.     ($dlg, $item) = DialogSelect($event);
  253.  
  254. =cut
  255. void
  256. DialogSelect(theEvent)
  257.     ToolboxEvent    theEvent
  258.     PPCODE:
  259.     {
  260.         DialogPtr   theDialog;
  261.         short       itemHit;
  262.         
  263.         if (DialogSelect(theEvent, &theDialog, &itemHit)) {
  264.             EXTEND(sp, 2);
  265.             PUSHs(sv_setref_pv(sv_newmortal(), "GrafPtr", (void*)theDialog));
  266.             PUSHs(sv_2mortal(newSViv(itemHit)));
  267.         } else {
  268.             XSRETURN_EMPTY;
  269.         }
  270.     }
  271.  
  272. =item DrawDialog DIALOG
  273.  
  274. Draw a dialog.
  275.  
  276. =cut
  277. void
  278. DrawDialog(theDialog)
  279.     GrafPtr theDialog
  280.  
  281. =item UpdateDialog DIALOG [, UPDATERGN ]
  282.  
  283. Draw the update region in a dialog.
  284.  
  285. =cut
  286. void
  287. UpdateDialog(theDialog, updateRgn=theDialog->visRgn)
  288.     GrafPtr theDialog
  289.     RgnHandle   updateRgn
  290.  
  291. =item ITEM = Alert ALERTID [, FILTER]
  292.  
  293. Run an alert.
  294.  
  295. =cut
  296. short
  297. Alert(alertID, modalFilter=nil)
  298.     short   alertID
  299.     SV *    modalFilter
  300.     CODE:
  301.     if (modalFilter) {
  302.         SV * saveModalFilter = sModalFilter;
  303.         sModalFilter = modalFilter;
  304.         RETVAL = Alert(alertID, &uModalFilter);
  305.         sModalFilter = saveModalFilter;
  306.     } else
  307.         RETVAL = Alert(alertID, &uDefaultModalFilter);
  308.     OUTPUT:
  309.     RETVAL
  310.  
  311. =item ITEM = StopAlert ALERTID [, FILTER]
  312.  
  313. Run a an alert with the stop icon.
  314.  
  315. =cut
  316. short
  317. StopAlert(alertID, modalFilter=nil)
  318.     short   alertID
  319.     SV *    modalFilter
  320.     CODE:
  321.     if (modalFilter) {
  322.         SV * saveModalFilter = sModalFilter;
  323.         sModalFilter = modalFilter;
  324.         RETVAL = StopAlert(alertID, &uModalFilter);
  325.         sModalFilter = saveModalFilter;
  326.     } else
  327.         RETVAL = StopAlert(alertID, &uDefaultModalFilter);
  328.     OUTPUT:
  329.     RETVAL
  330.  
  331. =item ITEM = NoteAlert ALERTID [, FILTER]
  332.  
  333. Run a an alert with the note icon.
  334.  
  335. =cut
  336. short
  337. NoteAlert(alertID, modalFilter=nil)
  338.     short   alertID
  339.     SV *    modalFilter
  340.     CODE:
  341.     if (modalFilter) {
  342.         SV * saveModalFilter = sModalFilter;
  343.         sModalFilter = modalFilter;
  344.         RETVAL = NoteAlert(alertID, &uModalFilter);
  345.         sModalFilter = saveModalFilter;
  346.     } else
  347.         RETVAL = NoteAlert(alertID, &uDefaultModalFilter);
  348.     OUTPUT:
  349.     RETVAL
  350.  
  351. =item ITEM = CautionAlert ALERTID [, FILTER]
  352.  
  353. Run a an alert with the caution icon.
  354.  
  355. =cut
  356. short
  357. CautionAlert(alertID, modalFilter=nil)
  358.     short   alertID
  359.     SV *    modalFilter
  360.     CODE:
  361.     if (modalFilter) {
  362.         SV * saveModalFilter = sModalFilter;
  363.         sModalFilter = modalFilter;
  364.         RETVAL = CautionAlert(alertID, &uModalFilter);
  365.         sModalFilter = saveModalFilter;
  366.     } else
  367.         RETVAL = CautionAlert(alertID, &uDefaultModalFilter);
  368.     OUTPUT:
  369.     RETVAL
  370.  
  371. =item GetDialogItem DIALOG, ITEM
  372.  
  373. Get a dialog item's type, contents, and area.
  374.  
  375.     ($type, $handle, $box) = GetDialogItem($dlg, $item);
  376.  
  377. =cut
  378. void
  379. GetDialogItem(theDialog, itemNo)
  380.     GrafPtr theDialog
  381.     short   itemNo
  382.     PPCODE:
  383.     {
  384.         short   itemType;
  385.         Handle  item;
  386.         Rect    box;
  387.         
  388.         GetDialogItem(theDialog, itemNo, &itemType, &item, &box);
  389.         EXTEND(sp, 3);
  390.         PUSHs(sv_2mortal(newSViv(itemType)));
  391.         PUSHs(sv_setref_pv(sv_newmortal(), "Handle", (void*)item));
  392.         PUSHs(sv_setref_pvn(sv_newmortal(), "Rect", (void*)&box, sizeof(Rect)));
  393.     }
  394.  
  395. =item GetDialogItemControl DIALOG, ITEM
  396.  
  397. Get the control handle for a dialog item.
  398.  
  399.     $control = GetDialogItemControl($dlg, $item);
  400.  
  401. =cut
  402. ControlHandle
  403. GetDialogItemControl(theDialog, itemNo)
  404.     GrafPtr theDialog
  405.     short   itemNo
  406.     CODE:
  407.     {
  408.         short   itemType;
  409.         Handle  item;
  410.         Rect    box;
  411.         
  412.         GetDialogItem(theDialog, itemNo, &itemType, &item, &box);
  413.         if (!(itemType & kControlDialogItem)) {
  414.             XSRETURN_UNDEF;
  415.         }
  416.         RETVAL = (ControlHandle)item;
  417.     }
  418.     OUTPUT:
  419.     RETVAL
  420.  
  421. =item SetDialogItem DIALOG, ITEM, TYPE, ITEMHANDLE, BOX
  422.  
  423. Don't use this for setting an user item procedure. 
  424.  
  425. =cut
  426. void
  427. SetDialogItem(theDialog, itemNo, itemType, item, box)
  428.     GrafPtr theDialog
  429.     short   itemNo
  430.     short   itemType
  431.     Handle  item
  432.     Rect   &box
  433.  
  434.  
  435. void
  436. _SetDialogItemProc(theDialog, itemNo)
  437.     GrafPtr theDialog
  438.     short   itemNo
  439.     CODE:
  440.     {
  441.         short   itemType;
  442.         Handle  item;
  443.         Rect    box;
  444.         
  445.         GetDialogItem(theDialog, itemNo, &itemType, &item, &box);
  446.         SetDialogItem(theDialog, itemNo, kUserDialogItem, (Handle)&uItemProc, &box);
  447.     }
  448.     
  449. =item HideDialogItem DIALOG, ITEM
  450.  
  451. =cut
  452. void
  453. HideDialogItem(theDialog, itemNo)
  454.     GrafPtr theDialog
  455.     short   itemNo
  456.  
  457. =item ShowDialogItem DIALOG, ITEM
  458.  
  459. =cut
  460. void
  461. ShowDialogItem(theDialog, itemNo)
  462.     GrafPtr theDialog
  463.     short   itemNo
  464.  
  465. =item SelectDialogItemText DIALOG, ITEM [, START, END]
  466.  
  467. Select text in one of the edit items of a dialog.
  468.  
  469. =cut
  470. void
  471. SelectDialogItemText(theDialog, itemNo, strtSel=0, endSel=32767)
  472.     GrafPtr theDialog
  473.     short   itemNo
  474.     short   strtSel
  475.     short   endSel
  476.  
  477. Str255
  478. _GetDialogItemText(item)
  479.     Handle  item
  480.     CODE:
  481.     GetDialogItemText(item, RETVAL);
  482.     OUTPUT:
  483.     RETVAL
  484.  
  485. void
  486. _SetDialogItemText(item, text)
  487.     Handle  item
  488.     Str255  text
  489.     CODE:
  490.     SetDialogItemText(item, text);
  491.  
  492. =item FindDialogItem DIALOG, POINT
  493.  
  494. Find the topmost dialog item containing the point.
  495.  
  496. =cut
  497. short
  498. FindDialogItem(theDialog, thePt)
  499.     GrafPtr theDialog
  500.     Point   thePt
  501.  
  502. =item NewColorDialog BOUNDS, TITLE, VISIBLE, PROC, GOAWAY, ITEMS [, REFCON [, BEHIND]]
  503.  
  504. Create and return a color dialog.
  505.  
  506. =cut
  507. GrafPtr
  508. _NewColorDialog(boundsRect, title, visible, theProc, goAwayFlag, ditems, refCon=0, behind=(GrafPtr)-1)
  509.     Rect       &boundsRect
  510.     Str255      title
  511.     Boolean     visible
  512.     short       theProc
  513.     Boolean     goAwayFlag
  514.     Handle      ditems
  515.     long        refCon
  516.     GrafPtr     behind
  517.     CODE:
  518.     RETVAL = 
  519.         NewColorDialog(
  520.             nil, &boundsRect, title, visible, theProc, behind, goAwayFlag, refCon, ditems);
  521.     OUTPUT:
  522.     RETVAL
  523.  
  524. =item GetAlertStage 
  525.  
  526. Get the dialog alert stage. Lower stages will just beep, while higher stages
  527. will put up a dialog.
  528.  
  529. =cut
  530. short
  531. GetAlertStage()
  532.  
  533. =item ResetAlertStage 
  534.  
  535. Set the alert stage back to 0.
  536.  
  537. =cut
  538. void
  539. ResetAlertStage()
  540.  
  541. =item DialogCut DIALOG
  542.  
  543. =item DialogCopy DIALOG
  544.  
  545. =item DialogPaste DIALOG
  546.  
  547. =item DialogDelete DIALOG
  548.  
  549. Perform edit menu functions on a dialog.
  550.  
  551. =cut
  552. void
  553. DialogCut(theDialog)
  554.     GrafPtr theDialog
  555.  
  556. void
  557. DialogPaste(theDialog)
  558.     GrafPtr theDialog
  559.  
  560. void
  561. DialogCopy(theDialog)
  562.     GrafPtr theDialog
  563.  
  564. void
  565. DialogDelete(theDialog)
  566.     GrafPtr theDialog
  567.  
  568. =item SetDialogFont FONTNUM
  569.  
  570. Set the font to be used in a dialog's edit items.
  571.  
  572. =cut
  573. void
  574. SetDialogFont(value)
  575.     short   value
  576.  
  577. =item AppendDITL DIALOG, DITLHANDLE, METHOD
  578.  
  579. Append further items to a dialog.
  580.  
  581. =cut
  582. void
  583. AppendDITL(theDialog, theHandle, method)
  584.     GrafPtr theDialog
  585.     Handle  theHandle
  586.     short   method
  587.  
  588. =item CountDITL DIALOG
  589.  
  590. Count the number of items in a dialog.
  591.  
  592. =cut
  593. short
  594. CountDITL(theDialog)
  595.     GrafPtr theDialog
  596.  
  597. =item ShortenDITL DIALOG, ITEMS
  598.  
  599. Removes the specified number of the items from the end of the item list.
  600.  
  601. =cut
  602. void
  603. ShortenDITL(theDialog, numberItems)
  604.     GrafPtr theDialog
  605.     short   numberItems
  606.  
  607. =item ITEM = StdFilterProc DIALOG, EVENT
  608.  
  609. Call the standard filter procedure and return the item hit or 0.
  610.  
  611. =cut
  612. short
  613. StdFilterProc(theDialog, event)
  614.     GrafPtr         theDialog
  615.     ToolboxEvent    event
  616.     CODE:
  617.     if (!StdFilterProc(theDialog, event, &RETVAL))
  618.         RETVAL = 0;
  619.     OUTPUT:
  620.     RETVAL
  621.  
  622. =item SetDialogDefaultItem DIALOG, ITEM
  623.  
  624. Set the item to be highlighted as the OK button.
  625.  
  626. =cut
  627. MacOSRet
  628. SetDialogDefaultItem(theDialog, newItem)
  629.     GrafPtr theDialog
  630.     short   newItem
  631.  
  632. =item SetDialogCancelItem DIALOG, ITEM
  633.  
  634. Set the item to be highlighted as the Cancel button.
  635.  
  636. =cut
  637. MacOSRet
  638. SetDialogCancelItem(theDialog, newItem)
  639.     GrafPtr theDialog
  640.     short   newItem
  641.  
  642. =item SetDialogTracksCursor DIALOG, TRACK
  643.  
  644. Tell the dialog to automatically change the cursor over edit items.
  645.  
  646. =cut
  647. MacOSRet
  648. SetDialogTracksCursor(theDialog, tracks)
  649.     GrafPtr theDialog
  650.     Boolean tracks
  651.  
  652.